mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 04:01:20 -08:00
fix(vtt-thumbnail): [PKG-VTT-THUMB-04] preserve historical type shapes
This commit is contained in:
1 parent
c4c7491e16
commit
58d2c95d8e
16 files changed
+235
-57
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import type { Factory, Option, Result, RuntimeFactory } from 'artplayer-plugin-vtt-thumbnail'
|
||||
import type { Factory as EntryFactory, Option as EntryOption, Result as EntryResult, RuntimeFactory as EntryRuntimeFactory } from 'artplayer-plugin-vtt-thumbnail/runtime'
|
||||
import Artplayer from 'artplayer'
|
||||
import legacy from 'artplayer-plugin-vtt-thumbnail'
|
||||
import * as namespace from 'artplayer-plugin-vtt-thumbnail'
|
||||
import legacyEntry from 'artplayer-plugin-vtt-thumbnail/legacy'
|
||||
import runtime from 'artplayer-plugin-vtt-thumbnail/runtime'
|
||||
|
||||
@@ -10,11 +12,19 @@ type ExactOptions = Assert<Equal<Parameters<typeof legacy>, [option: Option]>>
|
||||
type ExactFactory = Assert<Equal<typeof legacy, Factory>>
|
||||
type ExactResult = Assert<Equal<ReturnType<ReturnType<typeof legacy>>, Result>>
|
||||
type ActualResult = Assert<Equal<ReturnType<ReturnType<typeof runtime>>, Promise<Result>>>
|
||||
type HistoricalFactory = (option: { vtt?: string, style?: Partial<CSSStyleDeclaration> }) => (art: Artplayer) => { name: 'artplayerPluginVttThumbnail' }
|
||||
type ExactHistoricalFactory = Assert<Equal<typeof legacy, HistoricalFactory>>
|
||||
type ExactRuntimeFactory = Assert<Equal<typeof runtime, RuntimeFactory>>
|
||||
type RuntimeEntryTypes = Assert<Equal<[EntryFactory, EntryOption, EntryResult, EntryRuntimeFactory], [Factory, Option, Result, RuntimeFactory]>>
|
||||
|
||||
const option: Option = { vtt: '/cues.vtt', style: { opacity: '0.8' } }
|
||||
const art = new Artplayer({ container: '#player', url: '/video.mp4', plugins: [legacy(option), runtime(option)] })
|
||||
const old: Result = legacy(option)(art)
|
||||
const oldReplacement: typeof legacy = (_option: Option) => (_art: Artplayer) => ({ name: 'artplayerPluginVttThumbnail' })
|
||||
const toOld: HistoricalFactory = legacy
|
||||
const fromOld: typeof legacy = (_option: Parameters<HistoricalFactory>[0]) => (_art: Artplayer) => ({ name: 'artplayerPluginVttThumbnail' })
|
||||
const namespaceFactory: HistoricalFactory = namespace.default
|
||||
const legacyReplacement: typeof legacyEntry = fromOld
|
||||
legacyEntry(option)
|
||||
const factory: RuntimeFactory = runtime
|
||||
const pending: Promise<Result> = factory(option)(art)
|
||||
@@ -41,5 +51,9 @@ runtime({ unknown: true })
|
||||
runtime({})()
|
||||
// @ts-expect-error The runtime entry cannot be replaced with a synchronous registrar.
|
||||
const wrong: typeof runtime = oldReplacement
|
||||
void [alias, awaitedName, absent, changed, wrong]
|
||||
export type { ActualResult, ExactFactory, ExactOptions, ExactResult }
|
||||
// @ts-expect-error The historical root factory has no self default property.
|
||||
legacy.default({})
|
||||
// @ts-expect-error The legacy factory has the same pure function shape.
|
||||
legacyEntry.default({})
|
||||
void [toOld, fromOld, namespaceFactory, legacyReplacement, alias, awaitedName, absent, changed, wrong]
|
||||
export type { ActualResult, ExactFactory, ExactHistoricalFactory, ExactOptions, ExactResult, ExactRuntimeFactory, RuntimeEntryTypes }
|
||||
Reference in new issue
Block a user