refactor(danmuku): [PKG-DANMUKU-06] migrate runtime and preserve public types

This commit is contained in:
Harvey Zhao committed 2026-09-13 22:06:00 +08:00
1 parent abc8008da7
commit 24b883d862
64 files changed
+14020 -633

No files matched your search

@@ -0,0 +1,27 @@
import type Artplayer from 'artplayer'
import type { Danmu, Option, Result } from 'artplayer-plugin-danmuku'
import danmuku from 'artplayer-plugin-danmuku'
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false
type Assert<T extends true> = T
type Factory = (option: Option) => (art: Artplayer) => Result
type SameArguments = Assert<Equal<Parameters<typeof danmuku>, [option: Option]>>
type SameResult = Assert<Equal<ReturnType<ReturnType<typeof danmuku>>, Result>>
type SameEmit = Assert<Equal<ReturnType<Result['emit']>, Result>>
type SameLoad = Assert<Equal<ReturnType<Result['load']>, Promise<Result>>>
type SamePoints = Assert<Equal<Option['points'], { time: number, value: number }[] | undefined>>
type SameDanmuKeys = Assert<Equal<keyof Danmu, 'text' | 'mode' | 'color' | 'time' | 'border' | 'style'>>
declare const art: Artplayer
declare const result: Result
const replacement: Factory = (_option: Option) => (_art: Artplayer) => result
const toOld: Factory = danmuku
const fromOld: typeof danmuku = replacement
const option: Option = { danmuku: [], points: [{ time: 1, value: 2 }], margin: [0, '25%'], beforeEmit: async () => true }
const plugin: Result = danmuku(option)(art)
const synchronousOldEmit: Result = plugin.emit({ text: 'old declaration', mode: 1 })
const loaded: Promise<Result> = plugin.load(Promise.resolve([{ text: 'reload' }]))
const configured: Result = plugin.config(option)
const mounted: void = plugin.mount('#external')
void [toOld, fromOld, synchronousOldEmit, loaded, configured, mounted]
export type { SameArguments, SameDanmuKeys, SameEmit, SameLoad, SamePoints, SameResult }
@@ -0,0 +1,6 @@
import type { RuntimeFactory } from 'artplayer-plugin-danmuku/runtime'
import factory from '../../../packages/artplayer-plugin-danmuku/src'
// Compile with the package configuration: the implementation imports Worker assets.
const implementation: RuntimeFactory = factory
export { implementation }