feat(subtitle): add artplayer-plugin-libass

This commit is contained in:
journey-ad committed 2023-11-14 12:36:35 +08:00
1 parent cf8cea8283
commit 08ec5716f9
17 files changed
+2450

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
/*!
* artplayer-plugin-libass.js v1.0.0
* Github: https://github.com/zhw2590582/ArtPlayer
* (c) 2017-2023 Harvey Zack
* Released under the MIT License.
*/
!function(e,t,s,r,n){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},i="function"==typeof a[r]&&a[r],o=i.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function c(t,s){if(!o[t]){if(!e[t]){var n="function"==typeof a[r]&&a[r];if(!s&&n)return n(t,!0);if(i)return i(t,!0);if(l&&"string"==typeof t)return l(t);var d=new Error("Cannot find module '"+t+"'");throw d.code="MODULE_NOT_FOUND",d}v.resolve=function(s){var r=e[t][1][s];return null!=r?r:s},v.cache={};var u=o[t]=new c.Module(t);e[t][0].call(u.exports,v,u,u.exports,this)}return o[t].exports;function v(e){var t=v.resolve(e);return!1===t?{}:c(t)}}c.isParcelRequire=!0,c.Module=function(e){this.id=e,this.bundle=c,this.exports={}},c.modules=e,c.cache=o,c.parent=i,c.register=function(t,s){e[t]=[function(e,t){t.exports=s},{}]},Object.defineProperty(c,"root",{get:function(){return a[r]}}),a[r]=c;for(var d=0;d<t.length;d++)c(t[d]);if(s){var u=c(s);"object"==typeof exports&&"undefined"!=typeof module?module.exports=u:"function"==typeof define&&define.amd&&define((function(){return u}))}}({abjMI:[function(e,t,s){var r=e("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(s);var n=e("./adapter"),a=r.interopDefault(n);function i(e){return t=>{!function(e){const{version:t,utils:{errorHandle:s}}=e.constructor,r=t.split(".").map(Number);s(r[0]+r[1]/100>=5,`Artplayer.js@${t} is not compatible the artplayerPluginLibass@${i.version}. Please update it to version Artplayer.js@5.x.x`)}(t);let s=new(0,a.default)(t,e);return{name:"artplayerPluginLibass",libass:s.libass,visible:s.visible,init:s.init.bind(s),switch:s.switch.bind(s),show:s.show.bind(s),hide:s.hide.bind(s),destroy:s.destroy.bind(s)}}}s.default=i,i.env="production",i.version="1.0.0",i.build="2023-11-14 12:36:09","undefined"!=typeof window&&(window.artplayerPluginLibass=i)},{"./adapter":"cjgNP","@parcel/transformer-js/src/esmodule-helpers.js":"4ajKp"}],cjgNP:[function(e,t,s){var r=e("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(s);var n=e("libass-wasm"),a=r.interopDefault(n);s.default=class{constructor(e,t){const{constructor:s,template:r}=e;this.art=e,this.$video=r.$video,this.$webvtt=r.$subtitle,this.utils=s.utils,this.libass=null,e.once("ready",this.init.bind(this,t))}async init(e){this.#e(),await this.#t(e),this.#s(),this.art.emit("artplayerPluginLibass:init",this);const 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.#r(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.#n(!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.#a(),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,s])=>(e[t]=this.#r(s),e)),{})),this.libass=new(0,a.default)({subContent:"[Script Info]\nScriptType: v4.00+",video:this.$video,...e,workerUrl:await this.#i(e),fallbackFont:this.#r(e.fallbackFont),fonts:e.fonts?.map((e=>this.#r(e)))}),this.libass.canvasParent.className="artplayer-plugin-libass",this.libass.canvasParent.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n user-select: none;\n pointer-events: none;\n z-index: 20;"}#s(){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))}#a(){this.art.off("subtitle",this.visibleHandler),this.art.off("subtitleLoad",this.switchHandler),this.art.off("subtitleOffset",this.offsetHandler)}#n(e){this.$webvtt.style.visibility=e?"visible":"hiddenLine truncated
@@ -0,0 +1,7 @@
/*!
* artplayer-plugin-libass.js v1.0.0
* Github: https://github.com/zhw2590582/ArtPlayer
* (c) 2017-2023 Harvey Zack
* Released under the MIT License.
*/
!function(e,t,r,n,s){var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a="function"==typeof o[n]&&o[n],i=a.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function l(t,r){if(!i[t]){if(!e[t]){var s="function"==typeof o[n]&&o[n];if(!r&&s)return s(t,!0);if(a)return a(t,!0);if(c&&"string"==typeof t)return c(t);var u=new Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}p.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},p.cache={};var f=i[t]=new l.Module(t);e[t][0].call(f.exports,p,f,f.exports,this)}return i[t].exports;function p(e){var t=p.resolve(e);return!1===t?{}:l(t)}}l.isParcelRequire=!0,l.Module=function(e){this.id=e,this.bundle=l,this.exports={}},l.modules=e,l.cache=i,l.parent=a,l.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(l,"root",{get:function(){return o[n]}}),o[n]=l;for(var u=0;u<t.length;u++)l(t[u]);if(r){var f=l(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=f:"function"==typeof define&&define.amd&&define((function(){return f}))}}({"7Csdv":[function(e,t,r){var n=e("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(r);var s=e("./adapter"),o=n.interopDefault(s);function a(e){return function(t){!function(e){var t=e.constructor,r=t.version,n=t.utils.errorHandle,s=r.split(".").map(Number);n(s[0]+s[1]/100>=5,"Artplayer.js@".concat(r," is not compatible the artplayerPluginLibass@").concat(a.version,". Please update it to version Artplayer.js@5.x.x"))}(t);var r=new(0,o.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)}}}r.default=a,a.env="production",a.version="1.0.0",a.build="2023-11-14 12:36:10","undefined"!=typeof window&&(window.artplayerPluginLibass=a)},{"./adapter":"9NihZ","@parcel/transformer-js/src/esmodule-helpers.js":"38Wbh"}],"9NihZ":[function(e,t,r){var n=e("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(r),n.export(r,"default",(function(){return I}));var s=e("@swc/helpers/src/_async_to_generator.mjs"),o=n.interopDefault(s),a=e("@swc/helpers/src/_class_call_check.mjs"),i=n.interopDefault(a),c=e("@swc/helpers/src/_class_private_method_get.mjs"),l=n.interopDefault(c),u=e("@swc/helpers/src/_class_private_method_init.mjs"),f=n.interopDefault(u),p=e("@swc/helpers/src/_create_class.mjs"),d=n.interopDefault(p),h=e("@swc/helpers/src/_object_spread.mjs"),m=n.interopDefault(h),v=e("@swc/helpers/src/_object_spread_props.mjs"),b=n.interopDefault(v),y=e("@swc/helpers/src/_sliced_to_array.mjs"),_=n.interopDefault(y),g=e("@swc/helpers/src/_ts_generator.mjs"),w=n.interopDefault(g),j=e("libass-wasm"),k=n.interopDefault(j),x="[Script Info]\nScriptType: v4.00+",O=new WeakSet,E=new WeakSet,P=new WeakSet,T=new WeakSet,F=new WeakSet,L=new WeakSet,W=new WeakSet,S=new WeakSet,I=function(){"use strict";function e(t,r){(0,i.default)(this,e),(0,f.default)(this,O),(0,f.default)(this,E),(0,f.default)(this,P),(0,f.default)(this,T),(0,f.default)(this,F),(0,f.default)(this,L),(0,f.default)(this,W),(0,f.default)(this,S);var n=t.constructor,s=t.template;this.art=t,this.$video=s.$video,this.$webvtt=s.$subtitle,this.utils=n.utils,this.libass=null,t.once("ready",this.init.bind(this,r))}return(0,d.default)(e,[{key:"init",value:function(e){var t=this;return(0,o.default)((function(){var r,n,s,o;return(0,w.default)(this,(function(a){switch(a.label){case 0:return(0,l.default)(t,S,B).call(t),[4,(0,l.default)(t,O,C).call(t,e)];case 1:return a.sent(),(0,l.default)(t,E,R).call(t),t.art.emit("artplayerPluginLibass:init",t),(o=null===(r=t.art)||void 0===r||null===(n=r.option)||void 0===n||null===(s=n.subtitle)||void 0===s?void 0:s.url)&&"ass"===t.utils.getExt(o)&&t.switch(o),[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,l.default)(this,F,U).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,l.default)(this,T,D).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:fuLine truncated