mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
refactor(asr): [PKG-ASR-04] preserve old declarations and add precise runtime types
This commit is contained in:
1 parent
0cf2af4840
commit
93208e59e1
24 files changed
+1224
-19
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import type Artplayer from 'artplayer'
|
||||
import asr from 'artplayer-plugin-asr'
|
||||
import * as namespace from 'artplayer-plugin-asr'
|
||||
|
||||
// Compile this fixture as .mts with NodeNext: published declarations expose
|
||||
// a CommonJS declaration namespace even though the runtime import is ESM.
|
||||
interface HistoricalOption {
|
||||
length?: number
|
||||
interval?: number
|
||||
sampleRate?: number
|
||||
autoHideTimeout?: number
|
||||
onAudioChunk?: (chunk: { pcm: ArrayBuffer, wav: ArrayBuffer }) => void | Promise<void>
|
||||
}
|
||||
|
||||
interface HistoricalResult {
|
||||
name: 'artplayerPluginAsr'
|
||||
stop: () => void
|
||||
hide: () => void
|
||||
append: (subtitle: string) => void
|
||||
}
|
||||
|
||||
type HistoricalFactory = (option?: HistoricalOption) => (art: Artplayer) => HistoricalResult
|
||||
interface HistoricalModule { default: HistoricalFactory }
|
||||
const result: ReturnType<ReturnType<typeof asr.default>> = {
|
||||
name: 'artplayerPluginAsr',
|
||||
stop() {},
|
||||
hide() {},
|
||||
append(_subtitle: string) {},
|
||||
}
|
||||
const replacementFactory: HistoricalFactory = (_option?: HistoricalOption) => (_art: Artplayer) => result
|
||||
const replacementModule: typeof asr = { default: replacementFactory }
|
||||
const assignToOld: HistoricalModule = asr
|
||||
const assignFromOld: typeof asr = assignToOld
|
||||
const namespaceModule: typeof namespace.default = replacementModule
|
||||
const factoryToOld: HistoricalFactory = asr.default
|
||||
const factoryFromOld: typeof asr.default = replacementFactory
|
||||
const option: Parameters<typeof asr.default>[0] = {
|
||||
onAudioChunk: async (_chunk): Promise<void> => {},
|
||||
}
|
||||
const absent: Parameters<typeof namespace.default.default>[0] = undefined
|
||||
declare const art: Artplayer
|
||||
const installed: HistoricalResult = asr.default(option)(art)
|
||||
const namespaceResult: HistoricalResult = namespace.default.default(absent)(art)
|
||||
const stop: void = installed.stop()
|
||||
const append: void = namespaceResult.append('Old namespace import.')
|
||||
void [assignFromOld, namespaceModule, factoryToOld, factoryFromOld, stop, append]
|
||||
@@ -0,0 +1,55 @@
|
||||
import Artplayer from 'artplayer'
|
||||
import asr from 'artplayer-plugin-asr'
|
||||
import * as namespace from 'artplayer-plugin-asr'
|
||||
|
||||
interface PublishedChunk {
|
||||
pcm: ArrayBuffer
|
||||
wav: ArrayBuffer
|
||||
}
|
||||
|
||||
interface PublishedOption {
|
||||
length?: number
|
||||
interval?: number
|
||||
sampleRate?: number
|
||||
autoHideTimeout?: number
|
||||
onAudioChunk?: (chunk: PublishedChunk) => void | Promise<void>
|
||||
}
|
||||
|
||||
interface PublishedResult {
|
||||
name: 'artplayerPluginAsr'
|
||||
stop: () => void
|
||||
hide: () => void
|
||||
append: (subtitle: string) => void
|
||||
}
|
||||
|
||||
type PublishedFactory = (option?: PublishedOption) => (art: Artplayer) => PublishedResult
|
||||
const option: Parameters<typeof asr>[0] = {
|
||||
length: 3,
|
||||
interval: 100,
|
||||
sampleRate: 16000,
|
||||
autoHideTimeout: 10000,
|
||||
onAudioChunk(chunk) {
|
||||
const pcm: ArrayBuffer = chunk.pcm
|
||||
const wav: ArrayBuffer = chunk.wav
|
||||
void [pcm, wav]
|
||||
},
|
||||
}
|
||||
const empty: Parameters<typeof asr>[0] = undefined
|
||||
const asyncOption: PublishedOption = { onAudioChunk: async (_chunk: PublishedChunk): Promise<void> => {} }
|
||||
const result: ReturnType<ReturnType<typeof asr>> = {
|
||||
name: 'artplayerPluginAsr',
|
||||
stop() {},
|
||||
hide() {},
|
||||
append(_subtitle: string) {},
|
||||
}
|
||||
const replacement: PublishedFactory = (_option?: PublishedOption) => (_art: Artplayer) => result
|
||||
const assignToOld: PublishedFactory = asr
|
||||
const assignFromOld: typeof asr = replacement
|
||||
const namespaceFactory: PublishedFactory = namespace.default
|
||||
const art = new Artplayer({ container: '#player', url: '/video.mp4', plugins: [asr(option), asr(asyncOption), asr(), namespace.default(empty)] })
|
||||
const installed: PublishedResult = asr(option)(art)
|
||||
const stop: void = installed.stop()
|
||||
const hide: void = installed.hide()
|
||||
const append: void = installed.append('Historical subtitle.')
|
||||
const callback: ((chunk: PublishedChunk) => void | Promise<void>) | undefined = option.onAudioChunk
|
||||
void [assignToOld, assignFromOld, namespaceFactory, stop, hide, append, callback]
|
||||
Reference in new issue
Block a user