refactor(asr): [PKG-ASR-04] preserve old declarations and add precise runtime types

This commit is contained in:
Harvey Zhao committed 2026-09-13 15:07:04 +08:00
1 parent 0cf2af4840
commit 93208e59e1
24 files changed
+1224 -19

No files matched your search

@@ -1,11 +1,11 @@
import type Artplayer from 'artplayer'
interface AudioChunk {
export interface AudioChunk {
pcm: ArrayBuffer
wav: ArrayBuffer
}
interface AsrPluginOption {
export interface AsrPluginOption {
length?: number
interval?: number
sampleRate?: number
@@ -13,13 +13,30 @@ interface AsrPluginOption {
onAudioChunk?: (chunk: AudioChunk) => void | Promise<void>
}
interface AsrPluginInstance {
export interface AsrPluginInstance {
name: 'artplayerPluginAsr'
stop: () => void
hide: () => void
append: (subtitle: string) => void
}
/** Historical factory shape, including void stop and callback results. */
export type Factory = (option?: AsrPluginOption) => (art: Artplayer) => AsrPluginInstance
/** Accurate asynchronous view available through the /runtime entry. */
export interface RuntimeOption extends Omit<AsrPluginOption, 'onAudioChunk'> {
onAudioChunk?: (chunk: AudioChunk) => string | void | null | Promise<string | void | null>
}
export interface RuntimeResult extends Omit<AsrPluginInstance, 'stop'> {
stop: () => Promise<void>
}
export interface RuntimeFactory {
(option?: RuntimeOption): (art: Artplayer) => RuntimeResult
readonly default: RuntimeFactory
}
declare function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer) => AsrPluginInstance
export default artplayerPluginAsr
@@ -0,0 +1,11 @@
import type { RuntimeFactory } from './artplayer-plugin-asr.js'
declare const artplayerPluginAsr: RuntimeFactory
// eslint-disable-next-line ts/no-redeclare -- Ambient merge exposes types on the CommonJS factory.
declare namespace artplayerPluginAsr {
type AudioChunk = import('./artplayer-plugin-asr.js').AudioChunk
type RuntimeFactory = import('./artplayer-plugin-asr.js').RuntimeFactory
type RuntimeOption = import('./artplayer-plugin-asr.js').RuntimeOption
type RuntimeResult = import('./artplayer-plugin-asr.js').RuntimeResult
}
export = artplayerPluginAsr
@@ -0,0 +1,5 @@
import type { RuntimeFactory } from './artplayer-plugin-asr.js'
declare const artplayerPluginAsr: RuntimeFactory
export default artplayerPluginAsr
export type { AudioChunk, RuntimeFactory, RuntimeOption, RuntimeResult } from './artplayer-plugin-asr.js'
+11
View File
@@ -0,0 +1,11 @@
import type { RuntimeFactory } from './artplayer-plugin-asr.js'
declare const artplayerPluginAsr: RuntimeFactory
// eslint-disable-next-line ts/no-redeclare -- Ambient merge exposes types on the CommonJS factory.
declare namespace artplayerPluginAsr {
type AudioChunk = import('./artplayer-plugin-asr.js').AudioChunk
type RuntimeFactory = import('./artplayer-plugin-asr.js').RuntimeFactory
type RuntimeOption = import('./artplayer-plugin-asr.js').RuntimeOption
type RuntimeResult = import('./artplayer-plugin-asr.js').RuntimeResult
}
export = artplayerPluginAsr