mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
fix(types): [PKG-FACTORY-01] preserve published factory compatibility
This commit is contained in:
1 parent
1117107032
commit
c4c7491e16
35 files changed
+670
-229
No files matched your search
+28
-7
@@ -1,12 +1,26 @@
|
||||
import type { Factory, MediaCanvas, Option, Result } from 'artplayer-proxy-canvas'
|
||||
import type { Factory, Option, Result, RuntimeFactory } from 'artplayer-proxy-canvas'
|
||||
import type { MediaCanvas, RuntimeFactory as RuntimeEntry, Factory as RuntimeEntryFactory, Option as RuntimeOption, Result as RuntimeResult } from 'artplayer-proxy-canvas/runtime'
|
||||
import Artplayer from 'artplayer'
|
||||
import canvas from 'artplayer-proxy-canvas'
|
||||
import * as namespace from 'artplayer-proxy-canvas'
|
||||
import legacy from 'artplayer-proxy-canvas/legacy'
|
||||
import runtime from 'artplayer-proxy-canvas/runtime'
|
||||
|
||||
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 OptionalInput = Assert<Equal<Parameters<typeof canvas>, [option?: Option]>>
|
||||
type ExactResult = Assert<Equal<ReturnType<ReturnType<typeof canvas>>, HTMLCanvasElement>>
|
||||
type HistoricalFactory = (option?: (ctx: CanvasRenderingContext2D, video: HTMLVideoElement) => void) => (art: Artplayer) => HTMLCanvasElement
|
||||
type ExactFactory = Assert<Equal<typeof canvas, HistoricalFactory>>
|
||||
type RuntimeEntries = Assert<Equal<[RuntimeEntryFactory, RuntimeOption, RuntimeResult, RuntimeEntry], [Factory, Option, Result, RuntimeFactory]>>
|
||||
type ExactRuntime = Assert<Equal<typeof runtime, RuntimeFactory>>
|
||||
|
||||
const replacement: HistoricalFactory = (_option?: Option) => (_art: Artplayer) => document.createElement('canvas')
|
||||
const toOld: HistoricalFactory = canvas
|
||||
const fromOld: typeof canvas = replacement
|
||||
const namedFactory: Factory = replacement
|
||||
const namespaceFactory: HistoricalFactory = namespace.default
|
||||
const legacyFactory: typeof legacy = replacement
|
||||
|
||||
const option: Option = (context, video) => {
|
||||
context.drawImage(video, 0, 0)
|
||||
@@ -17,8 +31,9 @@ const option: Option = (context, video) => {
|
||||
const art = new Artplayer({ container: '#player', url: 'video.mp4', proxy: canvas(option) })
|
||||
canvas()
|
||||
canvas(undefined)
|
||||
canvas.default(option)
|
||||
legacy.default()
|
||||
runtime.default(option)
|
||||
runtime.default.default()
|
||||
legacy()
|
||||
declare const optional: Option | undefined
|
||||
canvas(optional)
|
||||
const missing: Parameters<typeof canvas>[0] = undefined
|
||||
@@ -51,9 +66,15 @@ const promise: Promise<HTMLCanvasElement> = canvas()(art)
|
||||
media.getContext('2d')?.play()
|
||||
// @ts-expect-error Native Canvas dimensions remain numeric.
|
||||
media.width = '320'
|
||||
// @ts-expect-error Self default identity is readonly in declarations.
|
||||
canvas.default = legacy
|
||||
// @ts-expect-error Historical root factory has no required or exposed self default member.
|
||||
canvas.default()
|
||||
// @ts-expect-error Legacy factory retains the same plain factory shape.
|
||||
legacy.default()
|
||||
// @ts-expect-error A precise runtime replacement must provide its self identity.
|
||||
const missingAlias: RuntimeFactory = replacement
|
||||
// @ts-expect-error Self default identity is readonly in precise declarations.
|
||||
runtime.default = runtime
|
||||
// @ts-expect-error Registration requires a host.
|
||||
canvas()()
|
||||
void [missing, originalResult, play, context, listen, width, video, promise]
|
||||
export type { ExactResult, OptionalInput }
|
||||
void [toOld, fromOld, namedFactory, namespaceFactory, legacyFactory, missing, originalResult, play, context, listen, width, video, promise, missingAlias]
|
||||
export type { ExactFactory, ExactResult, ExactRuntime, OptionalInput, RuntimeEntries }
|
||||
Reference in new issue
Block a user