mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
build all
Refactor utility functions for improved readability and consistency - Updated compatibility.js to use consistent line endings and formatting. - Refactored component.js for better readability and structure, including consistent use of arrow functions and binding. - Simplified dom.js functions with consistent formatting and improved readability. - Enhanced emitter.js with consistent formatting and arrow function usage. - Streamlined error.js for improved readability and consistency. - Refactored file.js to use consistent formatting and improved readability. - Improved format.js functions for better readability and consistency. - Updated index.js to maintain consistent export formatting. - Refactored property.js for improved readability and consistency. - Enhanced subtitle.js with consistent formatting and improved readability. - Refactored time.js for better readability and consistent formatting. fix: update lint script to target only source files for consistency Revert "fix: restore export statements for various plugins and update type definitions for better clarity" This reverts commit b5e969d81ec765cd8a34b06e6ef4f232ef25087f. fix: restore export statements for various plugins and update type definitions for better clarity Refactor type definitions to use interfaces instead of type aliases for better extensibility and clarity across i18n, icons, option, player, quality, setting, subtitle, template, and utils modules.
This commit is contained in:
1 parent
532dd67cfd
commit
35ad9883af
447 files changed
+18248
-17946
No files matched your search
@@ -5,5 +5,5 @@
|
||||
* (c) 2017-2025 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,s,i,n,a,o){var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},c="function"==typeof l[s]&&l[s],d=c.i||{},u=c.cache||{},v="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!u[t]){if(!e[t]){if(i[t])return i[t];var n="function"==typeof l[s]&&l[s];if(!r&&n)return n(t,!0);if(c)return c(t,!0);if(v&&"string"==typeof t)return v(t);var a=Error("Cannot find module '"+t+"'");throw a.code="MODULE_NOT_FOUND",a}d.resolve=function(r){var s=e[t][1][r];return null!=s?s:r},d.cache={};var o=u[t]=new f.Module(t);e[t][0].call(o.exports,d,o,o.exports,l)}return u[t].exports;function d(e){var t=d.resolve(e);return!1===t?{}:f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=v,this.exports={}},f.modules=e,f.cache=u,f.parent=c,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=d,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return l[s]}}),l[s]=f;for(var h=0;h<t.length;h++)f(t[h]);if(r){var m=f(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"4omrA":[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r),i.export(r,"default",()=>o);var n=e("./adapter"),a=i.interopDefault(n);function o(e){return t=>{let r=new(0,a.default)(t,e);return{name:"artplayerPluginLibass",libass:r.libass,visible:r.visible,init:r.init.bind(r),switch:r.switch.bind(r),show:r.show.bind(r),hide:r.hide.bind(r),destroy:r.destroy.bind(r)}}}"undefined"!=typeof window&&(window.artplayerPluginLibass=o)},{"./adapter":"i5CMM","@parcel/transformer-js/src/esmodule-helpers.js":"w4pLy"}],i5CMM:[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r);var n=e("libass-wasm"),a=i.interopDefault(n);let o=`[Script Info] ScriptType: v4.00+`;r.default=class{constructor(e,t){let{constructor:r,template:s}=e;this.art=e,this.$video=s.$video,this.$webvtt=s.$subtitle,this.utils=r.utils,this.libass=null,e.once("ready",this.init.bind(this,t))}async init(e){this.#e(),await this.#t(e),this.#r(),this.art.emit("artplayerPluginLibass:init",this);let t=this.art?.option?.subtitle?.url;t&&"ass"===this.utils.getExt(t)&&this.switch(t)}switch(e){this.art.emit("artplayerPluginLibass:switch",e),e&&"ass"===this.utils.getExt(e)?(this.currentType="ass",this.libass.freeTrack(),this.libass.setTrackByUrl(this.#s(e)),this.visible=this.art.subtitle.show):(this.currentType="webvtt",this.hide(),this.libass.freeTrack())}setVisibility(e){this.visible=e}setOffset(e){this.timeOffset=e}get active(){return"ass"===this.currentType}get visible(){return!!this.libass&&"none"!==this.libass.canvasParent.style.display}set visible(e){this.art.emit("artplayerPluginLibass:visible",e),this.#i(!this.active),this.libass.canvasParent&&(this.libass.canvasParent.style.display=e?"block":"none",e&&this.libass.resize())}get timeOffset(){return this.libass.timeOffset}set timeOffset(e){this.art.emit("artplayerPluginLibass:timeOffset",e),this.libass.timeOffset=e}show(){this.visible=!0}hide(){this.visible=!1}destroy(){this.art.emit("artplayerPluginLibass:destroy"),this.#n(),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}async #t(e={}){if(!e.fallbackFont)return this.utils.errorHandle(e.fallbackFont,"artplayerPluginLibass: fallbackFont is required");e.workerUrl||(e.workerUrl="https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js"),e.availableFonts&&(e.availableFonts=Object.entries(e.availableFonts).reduce((e,[t,r])=>(e[t]=this.#s(r),e),{})),this.libass=new(0,a.default)({subContent:o,video:this.$video,...e,workerUrl:await this.#a(e),fallbackFont:this.#s(e.fallbackFont),fonts:e.fonts?.map(e=>this.#s(e))}),this.libass.canvasParent.className="artplayer-plugin-libass",this.libass.canvasParent.style.cssText=` position: absolute; top: 0; left: 0; width: 100%; height: 100%; user-select: none; pointer-events: none; z-index: 20;`}#r(){this.switchHandler=this.switch.bind(this),this.visibleHandler=this.setVisibility.bind(this),this.offsetHandler=this.setOffset.bind(this),this.art.on("subtitle",this.visibleHandler),this.art.on("subtitleLoad",this.switchHandler),this.art.on("subtitleOffset",this.offsetHandler),this.art.once("destroy",this.destroy.bind(this))}#n(){this.art.off("subtitle",this.visibleHandler),this.art.off("subtitleLoad",this.switchHandler),this.art.off("subtitleOffset",this.offsetHandler)}#i(e){this.$webvtt.style.visibility=e?"visible":"hidden"}#s(e){return this.#o(e)?e:new URL(e,document.baseURI).toString()}#o(e){return/^https?:\/\//.test(e)}#a({workerUrl:e,wasmUrl:t}){return new Promise(r=>{fetch(e).then(e=>e.text()).then(s=>{let i=s,n=new Blob([i=i.replace(/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,(r,s)=>(Line truncated
|
||||
!function(e,t,r,s,i,n,a,o){var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},c="function"==typeof l[s]&&l[s],d=c.i||{},u=c.cache||{},v="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!u[t]){if(!e[t]){if(i[t])return i[t];var n="function"==typeof l[s]&&l[s];if(!r&&n)return n(t,!0);if(c)return c(t,!0);if(v&&"string"==typeof t)return v(t);var a=Error("Cannot find module '"+t+"'");throw a.code="MODULE_NOT_FOUND",a}d.resolve=function(r){var s=e[t][1][r];return null!=s?s:r},d.cache={};var o=u[t]=new f.Module(t);e[t][0].call(o.exports,d,o,o.exports,l)}return u[t].exports;function d(e){var t=d.resolve(e);return!1===t?{}:f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=v,this.exports={}},f.modules=e,f.cache=u,f.parent=c,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=d,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return l[s]}}),l[s]=f;for(var h=0;h<t.length;h++)f(t[h]);if(r){var m=f(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"4083l":[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r),i.export(r,"default",()=>o);var n=e("./adapter"),a=i.interopDefault(n);function o(e){return t=>{let r=new(0,a.default)(t,e);return{name:"artplayerPluginLibass",libass:r.libass,visible:r.visible,init:r.init.bind(r),switch:r.switch.bind(r),show:r.show.bind(r),hide:r.hide.bind(r),destroy:r.destroy.bind(r)}}}"undefined"!=typeof window&&(window.artplayerPluginLibass=o)},{"./adapter":"uLby7","@parcel/transformer-js/src/esmodule-helpers.js":"5lQoW"}],uLby7:[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r);var n=e("libass-wasm"),a=i.interopDefault(n);let o=`[Script Info] ScriptType: v4.00+`;r.default=class{constructor(e,t){let{constructor:r,template:s}=e;this.art=e,this.$video=s.$video,this.$webvtt=s.$subtitle,this.utils=r.utils,this.libass=null,e.once("ready",this.init.bind(this,t))}async init(e){this.#e(),await this.#t(e),this.#r(),this.art.emit("artplayerPluginLibass:init",this);let t=this.art?.option?.subtitle?.url;t&&"ass"===this.utils.getExt(t)&&this.switch(t)}switch(e){this.art.emit("artplayerPluginLibass:switch",e),e&&"ass"===this.utils.getExt(e)?(this.currentType="ass",this.libass.freeTrack(),this.libass.setTrackByUrl(this.#s(e)),this.visible=this.art.subtitle.show):(this.currentType="webvtt",this.hide(),this.libass.freeTrack())}setVisibility(e){this.visible=e}setOffset(e){this.timeOffset=e}get active(){return"ass"===this.currentType}get visible(){return!!this.libass&&"none"!==this.libass.canvasParent.style.display}set visible(e){this.art.emit("artplayerPluginLibass:visible",e),this.#i(!this.active),this.libass.canvasParent&&(this.libass.canvasParent.style.display=e?"block":"none",e&&this.libass.resize())}get timeOffset(){return this.libass.timeOffset}set timeOffset(e){this.art.emit("artplayerPluginLibass:timeOffset",e),this.libass.timeOffset=e}show(){this.visible=!0}hide(){this.visible=!1}destroy(){this.art.emit("artplayerPluginLibass:destroy"),this.#n(),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}async #t(e={}){if(!e.fallbackFont)return this.utils.errorHandle(e.fallbackFont,"artplayerPluginLibass: fallbackFont is required");e.workerUrl||(e.workerUrl="https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js"),e.availableFonts&&(e.availableFonts=Object.entries(e.availableFonts).reduce((e,[t,r])=>(e[t]=this.#s(r),e),{})),this.libass=new(0,a.default)({subContent:o,video:this.$video,...e,workerUrl:await this.#a(e),fallbackFont:this.#s(e.fallbackFont),fonts:e.fonts?.map(e=>this.#s(e))}),this.libass.canvasParent.className="artplayer-plugin-libass",this.libass.canvasParent.style.cssText=` position: absolute; top: 0; left: 0; width: 100%; height: 100%; user-select: none; pointer-events: none; z-index: 20;`}#r(){this.switchHandler=this.switch.bind(this),this.visibleHandler=this.setVisibility.bind(this),this.offsetHandler=this.setOffset.bind(this),this.art.on("subtitle",this.visibleHandler),this.art.on("subtitleLoad",this.switchHandler),this.art.on("subtitleOffset",this.offsetHandler),this.art.once("destroy",this.destroy.bind(this))}#n(){this.art.off("subtitle",this.visibleHandler),this.art.off("subtitleLoad",this.switchHandler),this.art.off("subtitleOffset",this.offsetHandler)}#i(e){this.$webvtt.style.visibility=e?"visible":"hidden"}#s(e){return this.#o(e)?e:new URL(e,document.baseURI).toString()}#o(e){return/^https?:\/\//.test(e)}#a({workerUrl:e,wasmUrl:t}){return new Promise(r=>{fetch(e).then(e=>e.text()).then(s=>{let i=s,n=new Blob([i=i.replace(/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,(r,s)=>(Line truncated
|
||||
//# sourceMappingURL=artplayer-plugin-libass.esm.js.map
|
||||
@@ -1 +1 @@
|
||||
{"mappings":"C,A,S,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,E,I,E,A,a,O,W,W,A,a,O,K,K,A,a,O,O,O,A,a,O,O,O,C,E,E,A,Y,O,C,C,E,E,C,C,E,C,E,E,C,E,C,E,E,E,K,E,C,E,E,A,a,O,Q,A,Y,O,O,O,E,O,O,C,I,C,Q,S,E,C,C,C,E,G,C,C,C,E,C,C,G,C,C,C,E,C,C,G,C,C,E,C,O,C,C,E,C,I,E,A,Y,O,C,C,E,E,C,C,E,C,G,C,G,E,O,E,E,C,G,G,E,O,E,E,C,G,G,G,A,U,O,E,O,E,G,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,O,C,S,C,E,I,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,CAAC,IAAI,EACjD,CAEA,CAAA,CAAqB,GACnB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAY,IAAI,CAAC,cAAc,EAC5C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,eAAgB,IAAI,CAAC,aAAa,EAC/C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAkB,IAAI,CAAC,aAAa,CACnD,CAEA,CAAA,CAAc,CAAC,CAAO,EACpB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAG,EAAU,UAAY,QACxD,CAEA,CAAA,CAAc,CAAC,CAAG,SAChB,AAAI,IAAILine truncated
|
||||
@@ -5,4 +5,4 @@
|
||||
* (c) 2017-2025 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,s,i,n,a,o){var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},c="function"==typeof l[s]&&l[s],d=c.i||{},u=c.cache||{},v="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!u[t]){if(!e[t]){if(i[t])return i[t];var n="function"==typeof l[s]&&l[s];if(!r&&n)return n(t,!0);if(c)return c(t,!0);if(v&&"string"==typeof t)return v(t);var a=Error("Cannot find module '"+t+"'");throw a.code="MODULE_NOT_FOUND",a}d.resolve=function(r){var s=e[t][1][r];return null!=s?s:r},d.cache={};var o=u[t]=new f.Module(t);e[t][0].call(o.exports,d,o,o.exports,l)}return u[t].exports;function d(e){var t=d.resolve(e);return!1===t?{}:f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=v,this.exports={}},f.modules=e,f.cache=u,f.parent=c,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=d,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return l[s]}}),l[s]=f;for(var h=0;h<t.length;h++)f(t[h]);if(r){var m=f(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({jz4E5:[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r),i.export(r,"default",()=>o);var n=e("./adapter"),a=i.interopDefault(n);function o(e){return t=>{let r=new(0,a.default)(t,e);return{name:"artplayerPluginLibass",libass:r.libass,visible:r.visible,init:r.init.bind(r),switch:r.switch.bind(r),show:r.show.bind(r),hide:r.hide.bind(r),destroy:r.destroy.bind(r)}}}"undefined"!=typeof window&&(window.artplayerPluginLibass=o)},{"./adapter":"b8yho","@parcel/transformer-js/src/esmodule-helpers.js":"7o2zS"}],b8yho:[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r);var n=e("libass-wasm"),a=i.interopDefault(n);let o=`[Script Info] ScriptType: v4.00+`;r.default=class{constructor(e,t){let{constructor:r,template:s}=e;this.art=e,this.$video=s.$video,this.$webvtt=s.$subtitle,this.utils=r.utils,this.libass=null,e.once("ready",this.init.bind(this,t))}async init(e){this.#e(),await this.#t(e),this.#r(),this.art.emit("artplayerPluginLibass:init",this);let t=this.art?.option?.subtitle?.url;t&&"ass"===this.utils.getExt(t)&&this.switch(t)}switch(e){this.art.emit("artplayerPluginLibass:switch",e),e&&"ass"===this.utils.getExt(e)?(this.currentType="ass",this.libass.freeTrack(),this.libass.setTrackByUrl(this.#s(e)),this.visible=this.art.subtitle.show):(this.currentType="webvtt",this.hide(),this.libass.freeTrack())}setVisibility(e){this.visible=e}setOffset(e){this.timeOffset=e}get active(){return"ass"===this.currentType}get visible(){return!!this.libass&&"none"!==this.libass.canvasParent.style.display}set visible(e){this.art.emit("artplayerPluginLibass:visible",e),this.#i(!this.active),this.libass.canvasParent&&(this.libass.canvasParent.style.display=e?"block":"none",e&&this.libass.resize())}get timeOffset(){return this.libass.timeOffset}set timeOffset(e){this.art.emit("artplayerPluginLibass:timeOffset",e),this.libass.timeOffset=e}show(){this.visible=!0}hide(){this.visible=!1}destroy(){this.art.emit("artplayerPluginLibass:destroy"),this.#n(),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}async #t(e={}){if(!e.fallbackFont)return this.utils.errorHandle(e.fallbackFont,"artplayerPluginLibass: fallbackFont is required");e.workerUrl||(e.workerUrl="https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js"),e.availableFonts&&(e.availableFonts=Object.entries(e.availableFonts).reduce((e,[t,r])=>(e[t]=this.#s(r),e),{})),this.libass=new(0,a.default)({subContent:o,video:this.$video,...e,workerUrl:await this.#a(e),fallbackFont:this.#s(e.fallbackFont),fonts:e.fonts?.map(e=>this.#s(e))}),this.libass.canvasParent.className="artplayer-plugin-libass",this.libass.canvasParent.style.cssText=` position: absolute; top: 0; left: 0; width: 100%; height: 100%; user-select: none; pointer-events: none; z-index: 20;`}#r(){this.switchHandler=this.switch.bind(this),this.visibleHandler=this.setVisibility.bind(this),this.offsetHandler=this.setOffset.bind(this),this.art.on("subtitle",this.visibleHandler),this.art.on("subtitleLoad",this.switchHandler),this.art.on("subtitleOffset",this.offsetHandler),this.art.once("destroy",this.destroy.bind(this))}#n(){this.art.off("subtitle",this.visibleHandler),this.art.off("subtitleLoad",this.switchHandler),this.art.off("subtitleOffset",this.offsetHandler)}#i(e){this.$webvtt.style.visibility=e?"visible":"hidden"}#s(e){return this.#o(e)?e:new URL(e,document.baseURI).toString()}#o(e){return/^https?:\/\//.test(e)}#a({workerUrl:e,wasmUrl:t}){return new Promise(r=>{fetch(e).then(e=>e.text()).then(s=>{let i=s,n=new Blob([i=i.replace(/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,(r,s)=>(t=Line truncated
|
||||
!function(e,t,r,s,i,n,a,o){var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},c="function"==typeof l[s]&&l[s],d=c.i||{},u=c.cache||{},v="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!u[t]){if(!e[t]){if(i[t])return i[t];var n="function"==typeof l[s]&&l[s];if(!r&&n)return n(t,!0);if(c)return c(t,!0);if(v&&"string"==typeof t)return v(t);var a=Error("Cannot find module '"+t+"'");throw a.code="MODULE_NOT_FOUND",a}d.resolve=function(r){var s=e[t][1][r];return null!=s?s:r},d.cache={};var o=u[t]=new f.Module(t);e[t][0].call(o.exports,d,o,o.exports,l)}return u[t].exports;function d(e){var t=d.resolve(e);return!1===t?{}:f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=v,this.exports={}},f.modules=e,f.cache=u,f.parent=c,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=d,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return l[s]}}),l[s]=f;for(var h=0;h<t.length;h++)f(t[h]);if(r){var m=f(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"9G2Gn":[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r),i.export(r,"default",()=>o);var n=e("./adapter"),a=i.interopDefault(n);function o(e){return t=>{let r=new(0,a.default)(t,e);return{name:"artplayerPluginLibass",libass:r.libass,visible:r.visible,init:r.init.bind(r),switch:r.switch.bind(r),show:r.show.bind(r),hide:r.hide.bind(r),destroy:r.destroy.bind(r)}}}"undefined"!=typeof window&&(window.artplayerPluginLibass=o)},{"./adapter":"aO4ju","@parcel/transformer-js/src/esmodule-helpers.js":"6ykb1"}],aO4ju:[function(e,t,r,s){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(r);var n=e("libass-wasm"),a=i.interopDefault(n);let o=`[Script Info] ScriptType: v4.00+`;r.default=class{constructor(e,t){let{constructor:r,template:s}=e;this.art=e,this.$video=s.$video,this.$webvtt=s.$subtitle,this.utils=r.utils,this.libass=null,e.once("ready",this.init.bind(this,t))}async init(e){this.#e(),await this.#t(e),this.#r(),this.art.emit("artplayerPluginLibass:init",this);let t=this.art?.option?.subtitle?.url;t&&"ass"===this.utils.getExt(t)&&this.switch(t)}switch(e){this.art.emit("artplayerPluginLibass:switch",e),e&&"ass"===this.utils.getExt(e)?(this.currentType="ass",this.libass.freeTrack(),this.libass.setTrackByUrl(this.#s(e)),this.visible=this.art.subtitle.show):(this.currentType="webvtt",this.hide(),this.libass.freeTrack())}setVisibility(e){this.visible=e}setOffset(e){this.timeOffset=e}get active(){return"ass"===this.currentType}get visible(){return!!this.libass&&"none"!==this.libass.canvasParent.style.display}set visible(e){this.art.emit("artplayerPluginLibass:visible",e),this.#i(!this.active),this.libass.canvasParent&&(this.libass.canvasParent.style.display=e?"block":"none",e&&this.libass.resize())}get timeOffset(){return this.libass.timeOffset}set timeOffset(e){this.art.emit("artplayerPluginLibass:timeOffset",e),this.libass.timeOffset=e}show(){this.visible=!0}hide(){this.visible=!1}destroy(){this.art.emit("artplayerPluginLibass:destroy"),this.#n(),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}async #t(e={}){if(!e.fallbackFont)return this.utils.errorHandle(e.fallbackFont,"artplayerPluginLibass: fallbackFont is required");e.workerUrl||(e.workerUrl="https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js"),e.availableFonts&&(e.availableFonts=Object.entries(e.availableFonts).reduce((e,[t,r])=>(e[t]=this.#s(r),e),{})),this.libass=new(0,a.default)({subContent:o,video:this.$video,...e,workerUrl:await this.#a(e),fallbackFont:this.#s(e.fallbackFont),fonts:e.fonts?.map(e=>this.#s(e))}),this.libass.canvasParent.className="artplayer-plugin-libass",this.libass.canvasParent.style.cssText=` position: absolute; top: 0; left: 0; width: 100%; height: 100%; user-select: none; pointer-events: none; z-index: 20;`}#r(){this.switchHandler=this.switch.bind(this),this.visibleHandler=this.setVisibility.bind(this),this.offsetHandler=this.setOffset.bind(this),this.art.on("subtitle",this.visibleHandler),this.art.on("subtitleLoad",this.switchHandler),this.art.on("subtitleOffset",this.offsetHandler),this.art.once("destroy",this.destroy.bind(this))}#n(){this.art.off("subtitle",this.visibleHandler),this.art.off("subtitleLoad",this.switchHandler),this.art.off("subtitleOffset",this.offsetHandler)}#i(e){this.$webvtt.style.visibility=e?"visible":"hidden"}#s(e){return this.#o(e)?e:new URL(e,document.baseURI).toString()}#o(e){return/^https?:\/\//.test(e)}#a({workerUrl:e,wasmUrl:t}){return new Promise(r=>{fetch(e).then(e=>e.text()).then(s=>{let i=s,n=new Blob([i=i.replace(/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,(r,s)=>(Line truncated
|
||||
@@ -5,4 +5,4 @@
|
||||
* (c) 2017-2025 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,n,o,s,i,a){var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},u="function"==typeof c[n]&&c[n],l=u.i||{},f=u.cache||{},d="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,r){if(!f[t]){if(!e[t]){if(o[t])return o[t];var s="function"==typeof c[n]&&c[n];if(!r&&s)return s(t,!0);if(u)return u(t,!0);if(d&&"string"==typeof t)return d(t);var i=Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}l.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},l.cache={};var a=f[t]=new p.Module(t);e[t][0].call(a.exports,l,a,a.exports,c)}return f[t].exports;function l(e){var t=l.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=d,this.exports={}},p.modules=e,p.cache=f,p.parent=u,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=l,p.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(p,"root",{get:function(){return c[n]}}),c[n]=p;for(var v=0;v<t.length;v++)p(t[v]);if(r){var h=p(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=h:"function"==typeof define&&define.amd&&define(function(){return h})}}({bzF6W:[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return a});var s=e("./adapter"),i=o.interopDefault(s);function a(e){return function(t){var r=new(0,i.default)(t,e);return{name:"artplayerPluginLibass",libass:r.libass,visible:r.visible,init:r.init.bind(r),switch:r.switch.bind(r),show:r.show.bind(r),hide:r.hide.bind(r),destroy:r.destroy.bind(r)}}}"undefined"!=typeof window&&(window.artplayerPluginLibass=a)},{"./adapter":"kvT3o","@parcel/transformer-js/src/esmodule-helpers.js":"ihnSZ"}],kvT3o:[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return O});var s=e("@swc/helpers/cjs/_async_to_generator.cjs"),i=e("@swc/helpers/cjs/_class_call_check.cjs"),a=e("@swc/helpers/cjs/_class_private_method_get.cjs"),c=e("@swc/helpers/cjs/_class_private_method_init.cjs"),u=e("@swc/helpers/cjs/_create_class.cjs"),l=e("@swc/helpers/cjs/_object_spread.cjs"),f=e("@swc/helpers/cjs/_object_spread_props.cjs"),d=e("@swc/helpers/cjs/_sliced_to_array.cjs"),p=e("@swc/helpers/cjs/_type_of.cjs"),v=e("@swc/helpers/cjs/_ts_generator.cjs"),h=e("libass-wasm"),b=o.interopDefault(h),y=new WeakSet,m=new WeakSet,w=new WeakSet,g=new WeakSet,_=new WeakSet,k=new WeakSet,j=new WeakSet,x=new WeakSet,O=function(){"use strict";function e(t,r){(0,i._)(this,e),(0,c._)(this,y),(0,c._)(this,m),(0,c._)(this,w),(0,c._)(this,g),(0,c._)(this,_),(0,c._)(this,k),(0,c._)(this,j),(0,c._)(this,x);var n=t.constructor,o=t.template;this.art=t,this.$video=o.$video,this.$webvtt=o.$subtitle,this.utils=n.utils,this.libass=null,t.once("ready",this.init.bind(this,r))}return(0,u._)(e,[{key:"init",value:function(e){var t=this;return(0,s._)(function(){var r,n,o,s;return(0,v._)(this,function(i){switch(i.label){case 0:return(0,a._)(t,x,F).call(t),[4,(0,a._)(t,y,E).call(t,e)];case 1:return i.sent(),(0,a._)(t,m,L).call(t),t.art.emit("artplayerPluginLibass:init",t),(s=null==(o=t.art)||null==(n=o.option)||null==(r=n.subtitle)?void 0:r.url)&&"ass"===t.utils.getExt(s)&&t.switch(s),[2]}})})()}},{key:"switch",value:function(e){this.art.emit("artplayerPluginLibass:switch",e),e&&"ass"===this.utils.getExt(e)?(this.currentType="ass",this.libass.freeTrack(),this.libass.setTrackByUrl((0,a._)(this,_,M).call(this,e)),this.visible=this.art.subtitle.show):(this.currentType="webvtt",this.hide(),this.libass.freeTrack())}},{key:"setVisibility",value:function(e){this.visible=e}},{key:"setOffset",value:function(e){this.timeOffset=e}},{key:"active",get:function(){return"ass"===this.currentType}},{key:"visible",get:function(){return!!this.libass&&"none"!==this.libass.canvasParent.style.display},set:function(e){this.art.emit("artplayerPluginLibass:visible",e),(0,a._)(this,g,S).call(this,!this.active),this.libass.canvasParent&&(this.libass.canvasParent.style.display=e?"block":"none",e&&this.libass.resize())}},{key:"timeOffset",get:function(){return this.libass.timeOffset},set:function(e){this.art.emit("artplayerPluginLibass:timeOffset",e),this.libass.timeOffset=e}},{key:"show",value:function(){this.visible=!0}},{key:"hide",value:function(){this.visible=!1}},{key:"destroy",value:function(){this.art.emit("artplayerPluginLibass:destroy"),(0,a._)(this,w,T).call(this),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}}]),e}();function E(){return P.apply(this,arguments)}function P(){return(P=(0,s._)(function(){var e,t,r,n,o,s,i,c=arguments;return(0,v._)(this,function(u){switch(u.label){case 0:if(e=this,!(t=c.length>0&&void 0!==c[0]?c[0]:{}).fallbackFont)return[2,this.utils.errorHandle(t.fallbackFont,"artplayerPluginLibass: fallbackFont
Line truncated
|
||||
!function(e,t,r,n,o,i,s,a){var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},l="function"==typeof c[n]&&c[n],u=l.i||{},f=l.cache||{},d="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,r){if(!f[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof c[n]&&c[n];if(!r&&i)return i(t,!0);if(l)return l(t,!0);if(d&&"string"==typeof t)return d(t);var s=Error("Cannot find module '"+t+"'");throw s.code="MODULE_NOT_FOUND",s}u.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},u.cache={};var a=f[t]=new p.Module(t);e[t][0].call(a.exports,u,a,a.exports,c)}return f[t].exports;function u(e){var t=u.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=d,this.exports={}},p.modules=e,p.cache=f,p.parent=l,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=u,p.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(p,"root",{get:function(){return c[n]}}),c[n]=p;for(var h=0;h<t.length;h++)p(t[h]);if(r){var v=p(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=v:"function"==typeof define&&define.amd&&define(function(){return v})}}({"4kqKD":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return a});var i=e("./adapter"),s=o.interopDefault(i);function a(e){return function(t){var r=new(0,s.default)(t,e);return{name:"artplayerPluginLibass",libass:r.libass,visible:r.visible,init:r.init.bind(r),switch:r.switch.bind(r),show:r.show.bind(r),hide:r.hide.bind(r),destroy:r.destroy.bind(r)}}}"undefined"!=typeof window&&(window.artplayerPluginLibass=a)},{"./adapter":"jEGLL","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],jEGLL:[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return O});var i=e("@swc/helpers/cjs/_async_to_generator.cjs"),s=e("@swc/helpers/cjs/_class_call_check.cjs"),a=e("@swc/helpers/cjs/_class_private_method_get.cjs"),c=e("@swc/helpers/cjs/_class_private_method_init.cjs"),l=e("@swc/helpers/cjs/_create_class.cjs"),u=e("@swc/helpers/cjs/_object_spread.cjs"),f=e("@swc/helpers/cjs/_object_spread_props.cjs"),d=e("@swc/helpers/cjs/_sliced_to_array.cjs"),p=e("@swc/helpers/cjs/_type_of.cjs"),h=e("@swc/helpers/cjs/_ts_generator.cjs"),v=e("libass-wasm"),b=o.interopDefault(v),y=new WeakSet,m=new WeakSet,w=new WeakSet,g=new WeakSet,_=new WeakSet,k=new WeakSet,j=new WeakSet,x=new WeakSet,O=function(){"use strict";function e(t,r){(0,s._)(this,e),(0,c._)(this,y),(0,c._)(this,m),(0,c._)(this,w),(0,c._)(this,g),(0,c._)(this,_),(0,c._)(this,k),(0,c._)(this,j),(0,c._)(this,x);var n=t.constructor,o=t.template;this.art=t,this.$video=o.$video,this.$webvtt=o.$subtitle,this.utils=n.utils,this.libass=null,t.once("ready",this.init.bind(this,r))}return(0,l._)(e,[{key:"init",value:function(e){return(0,i._)(function(){var t,r,n,o;return(0,h._)(this,function(i){switch(i.label){case 0:return(0,a._)(this,x,R).call(this),[4,(0,a._)(this,y,E).call(this,e)];case 1:return i.sent(),(0,a._)(this,m,P).call(this),this.art.emit("artplayerPluginLibass:init",this),(o=null==(n=this.art)||null==(r=n.option)||null==(t=r.subtitle)?void 0:t.url)&&"ass"===this.utils.getExt(o)&&this.switch(o),[2]}})}).call(this)}},{key:"switch",value:function(e){this.art.emit("artplayerPluginLibass:switch",e),e&&"ass"===this.utils.getExt(e)?(this.currentType="ass",this.libass.freeTrack(),this.libass.setTrackByUrl((0,a._)(this,_,T).call(this,e)),this.visible=this.art.subtitle.show):(this.currentType="webvtt",this.hide(),this.libass.freeTrack())}},{key:"setVisibility",value:function(e){this.visible=e}},{key:"setOffset",value:function(e){this.timeOffset=e}},{key:"active",get:function(){return"ass"===this.currentType}},{key:"visible",get:function(){return!!this.libass&&"none"!==this.libass.canvasParent.style.display},set:function(e){this.art.emit("artplayerPluginLibass:visible",e),(0,a._)(this,g,S).call(this,!this.active),this.libass.canvasParent&&(this.libass.canvasParent.style.display=e?"block":"none",e&&this.libass.resize())}},{key:"timeOffset",get:function(){return this.libass.timeOffset},set:function(e){this.art.emit("artplayerPluginLibass:timeOffset",e),this.libass.timeOffset=e}},{key:"show",value:function(){this.visible=!0}},{key:"hide",value:function(){this.visible=!1}},{key:"destroy",value:function(){this.art.emit("artplayerPluginLibass:destroy"),(0,a._)(this,w,L).call(this),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}}]),e}();function E(){return(0,i._)(function(){var e,t,r,n,o,i,s,c=arguments;return(0,h._)(this,function(l){switch(l.label){case 0:if(e=this,!(t=c.length>0&&void 0!==c[0]?c[0]:{}).fallbackFont)return[2,this.utils.errorHandle(t.fallbackFont,"artplayerPluginLibass: fallbackFont is required")]Line truncated
|
||||
@@ -1,36 +1,36 @@
|
||||
{
|
||||
"license": "MIT",
|
||||
"version": "1.0.0",
|
||||
"name": "artplayer-plugin-libass",
|
||||
"description": "A powerful ass subtitle renderer `libass-wasm` for ArtPlayer",
|
||||
"main": "dist/artplayer-plugin-libass.js",
|
||||
"legacy": "dist/artplayer-plugin-libass.legacy.js",
|
||||
"module": "dist/artplayer-plugin-libass.esm.js",
|
||||
"types": "types/artplayer-plugin-libass.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/artplayer-plugin-libass.esm.js",
|
||||
"require": "./dist/artplayer-plugin-libass.js",
|
||||
"default": "./dist/artplayer-plugin-libass.js"
|
||||
},
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"browserslist": "last 1 Chrome version",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
],
|
||||
"dependencies": {
|
||||
"libass-wasm": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hrgui/libass-wasm-ts": "^1.0.3"
|
||||
}
|
||||
"name": "artplayer-plugin-libass",
|
||||
"version": "1.0.0",
|
||||
"description": "A powerful ass subtitle renderer `libass-wasm` for ArtPlayer",
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
],
|
||||
"exports": {
|
||||
"import": "./dist/artplayer-plugin-libass.esm.js",
|
||||
"require": "./dist/artplayer-plugin-libass.js",
|
||||
"default": "./dist/artplayer-plugin-libass.js"
|
||||
},
|
||||
"main": "dist/artplayer-plugin-libass.js",
|
||||
"legacy": "dist/artplayer-plugin-libass.legacy.js",
|
||||
"module": "dist/artplayer-plugin-libass.esm.js",
|
||||
"types": "types/artplayer-plugin-libass.d.ts",
|
||||
"browserslist": "last 1 Chrome version",
|
||||
"dependencies": {
|
||||
"libass-wasm": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hrgui/libass-wasm-ts": "^1.0.3"
|
||||
}
|
||||
}
|
||||
@@ -1,138 +1,141 @@
|
||||
import SubtitlesOctopus from 'libass-wasm';
|
||||
import SubtitlesOctopus from 'libass-wasm'
|
||||
|
||||
const defaultAssSubtitle = `[Script Info]\nScriptType: v4.00+`;
|
||||
const defaultAssSubtitle = `[Script Info]\nScriptType: v4.00+`
|
||||
|
||||
export default class LibassAdapter {
|
||||
constructor(art, option) {
|
||||
const { constructor, template } = art;
|
||||
constructor(art, option) {
|
||||
const { constructor, template } = art
|
||||
|
||||
this.art = art;
|
||||
this.$video = template.$video;
|
||||
this.$webvtt = template.$subtitle;
|
||||
this.utils = constructor.utils;
|
||||
this.art = art
|
||||
this.$video = template.$video
|
||||
this.$webvtt = template.$subtitle
|
||||
this.utils = constructor.utils
|
||||
|
||||
this.libass = null;
|
||||
this.libass = null
|
||||
|
||||
art.once('ready', this.init.bind(this, option));
|
||||
art.once('ready', this.init.bind(this, option))
|
||||
}
|
||||
|
||||
async init(option) {
|
||||
this.#checkWebAssemblySupport()
|
||||
|
||||
await this.#createLibass(option)
|
||||
|
||||
this.#addEventListeners()
|
||||
|
||||
this.art.emit('artplayerPluginLibass:init', this)
|
||||
|
||||
// set initial subtitle
|
||||
const initialSubtitle = this.art?.option?.subtitle?.url
|
||||
if (initialSubtitle && this.utils.getExt(initialSubtitle) === 'ass') {
|
||||
this.switch(initialSubtitle)
|
||||
}
|
||||
}
|
||||
|
||||
switch(url) {
|
||||
this.art.emit('artplayerPluginLibass:switch', url)
|
||||
|
||||
if (url && this.utils.getExt(url) === 'ass') {
|
||||
this.currentType = 'ass'
|
||||
this.libass.freeTrack()
|
||||
this.libass.setTrackByUrl(this.#toAbsoluteUrl(url))
|
||||
|
||||
this.visible = this.art.subtitle.show
|
||||
}
|
||||
else {
|
||||
this.currentType = 'webvtt'
|
||||
this.hide()
|
||||
this.libass.freeTrack()
|
||||
}
|
||||
}
|
||||
|
||||
setVisibility(visible) {
|
||||
this.visible = visible
|
||||
}
|
||||
|
||||
setOffset(offset) {
|
||||
this.timeOffset = offset
|
||||
}
|
||||
|
||||
get active() {
|
||||
return this.currentType === 'ass'
|
||||
}
|
||||
|
||||
get visible() {
|
||||
if (!this.libass)
|
||||
return false
|
||||
|
||||
return this.libass.canvasParent.style.display !== 'none'
|
||||
}
|
||||
|
||||
set visible(visible) {
|
||||
this.art.emit('artplayerPluginLibass:visible', visible)
|
||||
|
||||
this.#setVttVisible(!this.active)
|
||||
|
||||
if (this.libass.canvasParent) {
|
||||
this.libass.canvasParent.style.display = visible ? 'block' : 'none'
|
||||
|
||||
if (visible)
|
||||
this.libass.resize()
|
||||
}
|
||||
}
|
||||
|
||||
get timeOffset() {
|
||||
return this.libass.timeOffset
|
||||
}
|
||||
|
||||
set timeOffset(offset) {
|
||||
this.art.emit('artplayerPluginLibass:timeOffset', offset)
|
||||
this.libass.timeOffset = offset
|
||||
}
|
||||
|
||||
show() {
|
||||
this.visible = true
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.visible = false
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.art.emit('artplayerPluginLibass:destroy')
|
||||
|
||||
this.#removeEventListeners()
|
||||
|
||||
this.libass.dispose()
|
||||
URL.revokeObjectURL(this.workerScriptUrl)
|
||||
this.libass = null
|
||||
}
|
||||
|
||||
async #createLibass(option = {}) {
|
||||
if (!option.fallbackFont) {
|
||||
return this.utils.errorHandle(option.fallbackFont, 'artplayerPluginLibass: fallbackFont is required')
|
||||
}
|
||||
|
||||
async init(option) {
|
||||
this.#checkWebAssemblySupport();
|
||||
|
||||
await this.#createLibass(option);
|
||||
|
||||
this.#addEventListeners();
|
||||
|
||||
this.art.emit('artplayerPluginLibass:init', this);
|
||||
|
||||
// set initial subtitle
|
||||
const initialSubtitle = this.art?.option?.subtitle?.url;
|
||||
if (initialSubtitle && this.utils.getExt(initialSubtitle) === 'ass') {
|
||||
this.switch(initialSubtitle);
|
||||
}
|
||||
if (!option.workerUrl) {
|
||||
option.workerUrl
|
||||
= 'https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js'
|
||||
}
|
||||
|
||||
switch(url) {
|
||||
this.art.emit('artplayerPluginLibass:switch', url);
|
||||
|
||||
if (url && this.utils.getExt(url) === 'ass') {
|
||||
this.currentType = 'ass';
|
||||
this.libass.freeTrack();
|
||||
this.libass.setTrackByUrl(this.#toAbsoluteUrl(url));
|
||||
|
||||
this.visible = this.art.subtitle.show;
|
||||
} else {
|
||||
this.currentType = 'webvtt';
|
||||
this.hide();
|
||||
this.libass.freeTrack();
|
||||
}
|
||||
if (option.availableFonts) {
|
||||
option.availableFonts = Object.entries(option.availableFonts).reduce((acc, [key, value]) => {
|
||||
acc[key] = this.#toAbsoluteUrl(value)
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
|
||||
setVisibility(visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
this.libass = new SubtitlesOctopus({
|
||||
subContent: defaultAssSubtitle,
|
||||
video: this.$video,
|
||||
...option,
|
||||
workerUrl: await this.#loadWorker(option),
|
||||
fallbackFont: this.#toAbsoluteUrl(option.fallbackFont),
|
||||
fonts: option.fonts?.map(font => this.#toAbsoluteUrl(font)),
|
||||
})
|
||||
|
||||
setOffset(offset) {
|
||||
this.timeOffset = offset;
|
||||
}
|
||||
|
||||
get active() {
|
||||
return this.currentType === 'ass';
|
||||
}
|
||||
|
||||
get visible() {
|
||||
if (!this.libass) return false;
|
||||
|
||||
return this.libass.canvasParent.style.display !== 'none';
|
||||
}
|
||||
|
||||
set visible(visible) {
|
||||
this.art.emit('artplayerPluginLibass:visible', visible);
|
||||
|
||||
this.#setVttVisible(!this.active);
|
||||
|
||||
if (this.libass.canvasParent) {
|
||||
this.libass.canvasParent.style.display = visible ? 'block' : 'none';
|
||||
|
||||
if (visible) this.libass.resize();
|
||||
}
|
||||
}
|
||||
|
||||
get timeOffset() {
|
||||
return this.libass.timeOffset;
|
||||
}
|
||||
|
||||
set timeOffset(offset) {
|
||||
this.art.emit('artplayerPluginLibass:timeOffset', offset);
|
||||
this.libass.timeOffset = offset;
|
||||
}
|
||||
|
||||
show() {
|
||||
this.visible = true;
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.visible = false;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.art.emit('artplayerPluginLibass:destroy');
|
||||
|
||||
this.#removeEventListeners();
|
||||
|
||||
this.libass.dispose();
|
||||
URL.revokeObjectURL(this.workerScriptUrl);
|
||||
this.libass = null;
|
||||
}
|
||||
|
||||
async #createLibass(option = {}) {
|
||||
if (!option.fallbackFont) {
|
||||
return this.utils.errorHandle(option.fallbackFont, 'artplayerPluginLibass: fallbackFont is required');
|
||||
}
|
||||
|
||||
if (!option.workerUrl) {
|
||||
option.workerUrl =
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js';
|
||||
}
|
||||
|
||||
if (option.availableFonts) {
|
||||
option.availableFonts = Object.entries(option.availableFonts).reduce((acc, [key, value]) => {
|
||||
acc[key] = this.#toAbsoluteUrl(value);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
this.libass = new SubtitlesOctopus({
|
||||
subContent: defaultAssSubtitle,
|
||||
video: this.$video,
|
||||
...option,
|
||||
workerUrl: await this.#loadWorker(option),
|
||||
fallbackFont: this.#toAbsoluteUrl(option.fallbackFont),
|
||||
fonts: option.fonts?.map((font) => this.#toAbsoluteUrl(font)),
|
||||
});
|
||||
|
||||
this.libass.canvasParent.className = 'artplayer-plugin-libass';
|
||||
this.libass.canvasParent.style.cssText = `
|
||||
this.libass.canvasParent.className = 'artplayer-plugin-libass'
|
||||
this.libass.canvasParent.style.cssText = `
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
@@ -140,82 +143,84 @@ export default class LibassAdapter {
|
||||
height: 100%;
|
||||
user-select: none;
|
||||
pointer-events: none;
|
||||
z-index: 20;`;
|
||||
z-index: 20;`
|
||||
}
|
||||
|
||||
#addEventListeners() {
|
||||
this.switchHandler = this.switch.bind(this)
|
||||
this.visibleHandler = this.setVisibility.bind(this)
|
||||
this.offsetHandler = this.setOffset.bind(this)
|
||||
|
||||
this.art.on('subtitle', this.visibleHandler)
|
||||
this.art.on('subtitleLoad', this.switchHandler)
|
||||
this.art.on('subtitleOffset', this.offsetHandler)
|
||||
|
||||
this.art.once('destroy', this.destroy.bind(this))
|
||||
}
|
||||
|
||||
#removeEventListeners() {
|
||||
this.art.off('subtitle', this.visibleHandler)
|
||||
this.art.off('subtitleLoad', this.switchHandler)
|
||||
this.art.off('subtitleOffset', this.offsetHandler)
|
||||
}
|
||||
|
||||
#setVttVisible(visible) {
|
||||
this.$webvtt.style.visibility = visible ? 'visible' : 'hidden'
|
||||
}
|
||||
|
||||
#toAbsoluteUrl(url) {
|
||||
if (this.#isAbsoluteUrl(url))
|
||||
return url
|
||||
|
||||
// handle absolute URL when the `Worker` of `BLOB` type loading network resources
|
||||
return new URL(url, document.baseURI).toString()
|
||||
}
|
||||
|
||||
#isAbsoluteUrl(url) {
|
||||
return /^https?:\/\//.test(url)
|
||||
}
|
||||
|
||||
#loadWorker({ workerUrl, wasmUrl }) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(workerUrl)
|
||||
.then(res => res.text())
|
||||
.then((text) => {
|
||||
let workerScriptContent = text
|
||||
|
||||
workerScriptContent = workerScriptContent.replace(
|
||||
/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,
|
||||
(_match, wasm) => {
|
||||
if (!wasmUrl) {
|
||||
wasmUrl = new URL(wasm, workerUrl).toString()
|
||||
}
|
||||
else {
|
||||
wasmUrl = this.#toAbsoluteUrl(wasmUrl)
|
||||
}
|
||||
|
||||
return `wasmBinaryFile = "${wasmUrl}"`
|
||||
},
|
||||
)
|
||||
|
||||
const workerBlob = new Blob([workerScriptContent], { type: 'text/javascript' })
|
||||
resolve(URL.createObjectURL(workerBlob))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#checkWebAssemblySupport() {
|
||||
let supportsWebAssembly = false
|
||||
try {
|
||||
if (typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function') {
|
||||
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00))
|
||||
if (module instanceof WebAssembly.Module)
|
||||
supportsWebAssembly = new WebAssembly.Instance(module) instanceof WebAssembly.Instance
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('WebAssembly is not supported in this browser.', error)
|
||||
supportsWebAssembly = false
|
||||
}
|
||||
|
||||
#addEventListeners() {
|
||||
this.switchHandler = this.switch.bind(this);
|
||||
this.visibleHandler = this.setVisibility.bind(this);
|
||||
this.offsetHandler = this.setOffset.bind(this);
|
||||
|
||||
this.art.on('subtitle', this.visibleHandler);
|
||||
this.art.on('subtitleLoad', this.switchHandler);
|
||||
this.art.on('subtitleOffset', this.offsetHandler);
|
||||
|
||||
this.art.once('destroy', this.destroy.bind(this));
|
||||
}
|
||||
|
||||
#removeEventListeners() {
|
||||
this.art.off('subtitle', this.visibleHandler);
|
||||
this.art.off('subtitleLoad', this.switchHandler);
|
||||
this.art.off('subtitleOffset', this.offsetHandler);
|
||||
}
|
||||
|
||||
#setVttVisible(visible) {
|
||||
this.$webvtt.style.visibility = visible ? 'visible' : 'hidden';
|
||||
}
|
||||
|
||||
#toAbsoluteUrl(url) {
|
||||
if (this.#isAbsoluteUrl(url)) return url;
|
||||
|
||||
// handle absolute URL when the `Worker` of `BLOB` type loading network resources
|
||||
return new URL(url, document.baseURI).toString();
|
||||
}
|
||||
|
||||
#isAbsoluteUrl(url) {
|
||||
return /^https?:\/\//.test(url);
|
||||
}
|
||||
|
||||
#loadWorker({ workerUrl, wasmUrl }) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(workerUrl)
|
||||
.then((res) => res.text())
|
||||
.then((text) => {
|
||||
let workerScriptContent = text;
|
||||
|
||||
workerScriptContent = workerScriptContent.replace(
|
||||
/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,
|
||||
(_match, wasm) => {
|
||||
if (!wasmUrl) {
|
||||
wasmUrl = new URL(wasm, workerUrl).toString();
|
||||
} else {
|
||||
wasmUrl = this.#toAbsoluteUrl(wasmUrl);
|
||||
}
|
||||
|
||||
return `wasmBinaryFile = "${wasmUrl}"`;
|
||||
},
|
||||
);
|
||||
|
||||
const workerBlob = new Blob([workerScriptContent], { type: 'text/javascript' });
|
||||
resolve(URL.createObjectURL(workerBlob));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#checkWebAssemblySupport() {
|
||||
let supportsWebAssembly = false;
|
||||
try {
|
||||
if (typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function') {
|
||||
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
|
||||
if (module instanceof WebAssembly.Module)
|
||||
supportsWebAssembly = new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
|
||||
this.utils.errorHandle(supportsWebAssembly, 'Browser does not support WebAssembly');
|
||||
}
|
||||
this.utils.errorHandle(supportsWebAssembly, 'Browser does not support WebAssembly')
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import LibassAdapter from './adapter';
|
||||
import LibassAdapter from './adapter'
|
||||
|
||||
export default function artplayerPluginLibass(option) {
|
||||
return (art) => {
|
||||
const adapter = new LibassAdapter(art, option);
|
||||
return {
|
||||
name: 'artplayerPluginLibass',
|
||||
libass: adapter.libass,
|
||||
visible: adapter.visible,
|
||||
init: adapter.init.bind(adapter),
|
||||
switch: adapter.switch.bind(adapter),
|
||||
show: adapter.show.bind(adapter),
|
||||
hide: adapter.hide.bind(adapter),
|
||||
destroy: adapter.destroy.bind(adapter),
|
||||
};
|
||||
};
|
||||
return (art) => {
|
||||
const adapter = new LibassAdapter(art, option)
|
||||
return {
|
||||
name: 'artplayerPluginLibass',
|
||||
libass: adapter.libass,
|
||||
visible: adapter.visible,
|
||||
init: adapter.init.bind(adapter),
|
||||
switch: adapter.switch.bind(adapter),
|
||||
show: adapter.show.bind(adapter),
|
||||
hide: adapter.hide.bind(adapter),
|
||||
destroy: adapter.destroy.bind(adapter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window['artplayerPluginLibass'] = artplayerPluginLibass;
|
||||
window.artplayerPluginLibass = artplayerPluginLibass
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
import type Artplayer from 'artplayer';
|
||||
import type SubtitlesOctopus from '@hrgui/libass-wasm-ts';
|
||||
import { type Options } from 'libass-wasm';
|
||||
import type SubtitlesOctopus from '@hrgui/libass-wasm-ts'
|
||||
import type Artplayer from 'artplayer'
|
||||
import type { Options } from 'libass-wasm'
|
||||
|
||||
export = artplayerPluginAss;
|
||||
export = artplayerPluginAss
|
||||
export as namespace artplayerPluginAss;
|
||||
|
||||
declare const artplayerPluginAss: (options: Options) => (art: Artplayer) => {
|
||||
name: 'artplayerPluginLibass';
|
||||
libass: SubtitlesOctopus;
|
||||
visible: boolean;
|
||||
init: () => void;
|
||||
switch: (url: string) => void;
|
||||
show: () => void;
|
||||
hide: () => void;
|
||||
destroy: () => void;
|
||||
};
|
||||
name: 'artplayerPluginLibass'
|
||||
libass: SubtitlesOctopus
|
||||
visible: boolean
|
||||
init: () => void
|
||||
switch: (url: string) => void
|
||||
show: () => void
|
||||
hide: () => void
|
||||
destroy: () => void
|
||||
}
|
||||
Reference in new issue
Block a user