refactor(jassub): [PKG-JASSUB-03] isolate registration and fix adapter cleanup

This commit is contained in:
Harvey Zhao committed 2026-09-14 01:12:03 +08:00
1 parent 944e2cc9d0
commit 38e7b37878
21 files changed
+6553 -70

No files matched your search

+2 -18
View File
@@ -1,21 +1,5 @@
import JASSUB from './jassub.es.js'
import { registerJassub } from './registration.js'
export default function artplayerPluginJassub(option) {
return (art) => {
const instance = new JASSUB({
video: art.video,
...option,
})
instance._canvasParent.style.zIndex = 20
art.on('destroy', () => {
instance.destroy()
})
return {
name: 'artplayerPluginJassub',
instance,
}
}
return art => registerJassub(art, option)
}
@@ -0,0 +1,39 @@
import JASSUB from './jassub.es.js'
export function registerJassub(art, option) {
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 }
}