mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 04:31:20 -08:00
refactor(mask): [PKG-MASK-04] migrate strict types and preserve public consumers
This commit is contained in:
1 parent
aba125262a
commit
aca4bc1cd2
30 files changed
+1848
-72
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import Artplayer from 'artplayer'
|
||||
import mask from 'artplayer-plugin-danmuku-mask'
|
||||
import legacy from 'artplayer-plugin-danmuku-mask/legacy'
|
||||
|
||||
interface Option {
|
||||
solutionPath?: string
|
||||
modelSelection?: number
|
||||
smoothSegmentation?: boolean
|
||||
minDetectionConfidence?: number
|
||||
minTrackingConfidence?: number
|
||||
selfieMode?: boolean
|
||||
drawContour?: boolean
|
||||
foregroundThreshold?: number
|
||||
opacity?: number
|
||||
maskBlurAmount?: number
|
||||
}
|
||||
interface Result { name: 'artplayerPluginDanmukuMask', start: () => Promise<void>, stop: () => void }
|
||||
type Factory = (option?: Option) => (art: Artplayer) => Result
|
||||
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 Arguments = Assert<Equal<Parameters<typeof mask>, [option?: Option]>>
|
||||
type Registration = Assert<Equal<ReturnType<ReturnType<typeof mask>>, Result>>
|
||||
const replacement: Factory = () => () => ({ name: 'artplayerPluginDanmukuMask', async start() {}, stop() {} })
|
||||
const toOld: Factory = mask
|
||||
const fromOld: typeof mask = replacement
|
||||
const legacyReplacement: typeof legacy = replacement
|
||||
const option: Option = { solutionPath: '/models', modelSelection: 0, smoothSegmentation: false, minDetectionConfidence: 0, minTrackingConfidence: 0, selfieMode: false, drawContour: false, foregroundThreshold: 0, opacity: 0, maskBlurAmount: 0 }
|
||||
const art = new Artplayer({ container: '#player', url: '/video.mp4', plugins: [mask(), mask(option), legacy(undefined)] })
|
||||
const result = mask(option)(art)
|
||||
const name: 'artplayerPluginDanmukuMask' = result.name
|
||||
const starting: Promise<void> = result.start()
|
||||
const stopped: void = result.stop()
|
||||
void [toOld, fromOld, legacyReplacement, name, starting, stopped]
|
||||
export type { Arguments, Registration }
|
||||
Reference in new issue
Block a user