mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-19 03:11:20 -08:00
fix(multiple-subtitles): [PKG-MULTI-SUB-04] preserve historical type shapes
This commit is contained in:
1 parent
58d2c95d8e
commit
87cfcf5a6c
17 files changed
+223
-63
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { Factory, LegacyResult, Option, Result, RuntimeFactory, TrackOption } from 'artplayer-plugin-multiple-subtitles'
|
||||
import type { RuntimeFactory as EntryFactory, RuntimeOption as EntryOption, Result as EntryResult, TrackOption as EntryTrack } from 'artplayer-plugin-multiple-subtitles/runtime'
|
||||
import Artplayer from 'artplayer'
|
||||
import legacy from 'artplayer-plugin-multiple-subtitles'
|
||||
import legacyEntry from 'artplayer-plugin-multiple-subtitles/legacy'
|
||||
@@ -12,10 +13,16 @@ type ExactResult = Assert<Equal<ReturnType<ReturnType<typeof legacy>>, LegacyRes
|
||||
type ActualResult = Assert<Equal<ReturnType<ReturnType<typeof runtime>>, Promise<Result>>>
|
||||
type OldTrack = Assert<Equal<TrackOption, { url?: string, name?: string, type?: 'vtt' | 'srt' | 'ass', encoding?: string, onParser?: (...args: object[]) => object }>>
|
||||
|
||||
type PublishedFactory = (option: { subtitles: TrackOption[] }) => (art: Artplayer) => { name: 'multipleSubtitles' }
|
||||
type PublishedShape = Assert<Equal<typeof legacy, PublishedFactory>>
|
||||
type RuntimeEntry = Assert<Equal<[EntryFactory, EntryOption, EntryResult, EntryTrack], [RuntimeFactory, { subtitles?: TrackOption[] }, Result, TrackOption]>>
|
||||
|
||||
const option: Option = { subtitles: [{ url: '/en.vtt', name: 'en', onParser: (...args) => args }] }
|
||||
const art = new Artplayer({ container: '#player', url: '/video.mp4', plugins: [legacy(option), runtime(option)] })
|
||||
const old: LegacyResult = legacy(option)(art)
|
||||
const replacement: typeof legacy = (_option: Option) => (_art: Artplayer) => ({ name: 'multipleSubtitles' })
|
||||
const assignToOld: PublishedFactory = legacy
|
||||
const assignFromOld: typeof legacy = (_option: { subtitles: TrackOption[] }) => (_art: Artplayer) => ({ name: 'multipleSubtitles' })
|
||||
legacyEntry(option)
|
||||
const factory: RuntimeFactory = runtime
|
||||
const pending: Promise<Result> = factory({})(art)
|
||||
@@ -25,9 +32,11 @@ pending.then((result) => {
|
||||
const returned: void = result.tracks(['en'])
|
||||
result.tracks()
|
||||
result.reset()
|
||||
// @ts-expect-error Selection methods stay synchronous after awaited registration.
|
||||
const selectionPromise: Promise<void> = result.reset()
|
||||
// @ts-expect-error Selection names are strings.
|
||||
result.tracks([1])
|
||||
void returned
|
||||
void [returned, selectionPromise]
|
||||
})
|
||||
// @ts-expect-error Historical subtitles field remains required.
|
||||
legacy({})
|
||||
@@ -51,5 +60,11 @@ runtime({ unknown: true })
|
||||
runtime({})()
|
||||
// @ts-expect-error Accurate runtime types cannot accept a synchronous registrar.
|
||||
const wrong: typeof runtime = replacement
|
||||
void [alias, absent, changed, wrong]
|
||||
export type { ActualResult, ExactFactory, ExactOptions, ExactResult, OldTrack }
|
||||
// @ts-expect-error Root replacement factories must not expose a required self alias.
|
||||
legacy.default(option)
|
||||
// @ts-expect-error Historical root result has only its name.
|
||||
old.tracks()
|
||||
// @ts-expect-error Historical root result has only its name.
|
||||
old.reset()
|
||||
void [alias, absent, changed, wrong, assignToOld, assignFromOld]
|
||||
export type { ActualResult, ExactFactory, ExactOptions, ExactResult, OldTrack, PublishedShape, RuntimeEntry }
|
||||
Reference in new issue
Block a user