mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 17:51:20 -08:00
refactor(jassub): [PKG-JASSUB-04] migrate owned TypeScript and preserve public types
This commit is contained in:
1 parent
38e7b37878
commit
5e445b1af6
33 files changed
+3636
-61
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import type { RuntimeOption, RuntimeResult } from '../types/runtime-api.js'
|
||||
import JASSUB from './jassub.es.js'
|
||||
|
||||
export interface JassubHost {
|
||||
video: HTMLVideoElement
|
||||
on: (name: 'destroy', callback: () => void) => unknown
|
||||
off: (name: 'destroy', callback: () => void) => unknown
|
||||
}
|
||||
|
||||
export function registerJassub(art: JassubHost, option?: RuntimeOption): RuntimeResult {
|
||||
const instance = new JASSUB({ video: art.video, ...option })
|
||||
let disposed = false
|
||||
const dispose = () => {
|
||||
if (disposed || instance._destroyed)
|
||||
return
|
||||
disposed = true
|
||||
try {
|
||||
instance.destroy()
|
||||
}
|
||||
catch (error) {
|
||||
disposed = false
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (instance._canvasParent)
|
||||
instance._canvasParent.style.zIndex = 20
|
||||
art.on('destroy', dispose)
|
||||
}
|
||||
catch (error) {
|
||||
// Registration may throw after attaching its listener. Keep the original
|
||||
// error while independently attempting listener and instance rollback.
|
||||
try {
|
||||
art.off('destroy', dispose)
|
||||
}
|
||||
catch {}
|
||||
try {
|
||||
dispose()
|
||||
}
|
||||
catch {}
|
||||
throw error
|
||||
}
|
||||
|
||||
return { name: 'artplayerPluginJassub', instance }
|
||||
}
|
||||
Reference in new issue
Block a user