mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 21:01:20 -08:00
refactor(core): CORE-15 type subtitles and own request and track lifetimes
This commit is contained in:
1 parent
64d1939daa
commit
1b83081e8f
28 files changed
+11286
-405
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import type Subtitle from '../../packages/artplayer/src/subtitle'
|
||||
import type { SubtitleCue, SubtitleHost, SubtitleOption } from '../../packages/artplayer/src/subtitle/types'
|
||||
|
||||
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false
|
||||
type Expect<T extends true> = T
|
||||
|
||||
declare const subtitle: Subtitle
|
||||
declare const host: SubtitleHost
|
||||
declare const options: SubtitleOption
|
||||
|
||||
subtitle.init(options)
|
||||
subtitle.switch('/subtitle.vtt', { onVttLoad: vtt => vtt })
|
||||
subtitle.style({ color: 'red' })
|
||||
subtitle.style('fontSize', '22px')
|
||||
subtitle.url = '/subtitle.srt'
|
||||
host.emit('subtitleBeforeUpdate', subtitle.activeCues)
|
||||
|
||||
type Cues = Expect<Equal<typeof subtitle.cues, SubtitleCue[]>>
|
||||
type Switch = Expect<Equal<ReturnType<Subtitle['switch']>, Promise<string | null | undefined>>>
|
||||
type Update = Expect<Equal<ReturnType<Subtitle['update']>, void>>
|
||||
type Style = Expect<Equal<ReturnType<Subtitle['style']>, HTMLDivElement>>
|
||||
export type Assertions = [Cues, Switch, Update, Style]
|
||||
|
||||
// @ts-expect-error Subtitle update does not accept registry entries.
|
||||
subtitle.update({ name: 'entry' })
|
||||
// @ts-expect-error Conversion callbacks produce text synchronously.
|
||||
subtitle.switch('/subtitle.vtt', { onVttLoad: async vtt => vtt })
|
||||
Reference in new issue
Block a user