mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 21:31:20 -08:00
Danmuku (#759)
* chore: Bump artplayer-plugin-danmuku version to 5.1.0 * chore: Update danmuku plugin with new mount option * chore: Update danmuku plugin with new mount option * chore: Update danmuku plugin with new mount option * chore: Update danmuku plugin with new mount option * chore: Update danmuku plugin with new mount option * chore: Update danmuku plugin with new mount option * chore: Refactor getDanmuTop function to handle additional cases * chore: Refactor getDanmuTop function to handle additional cases * chore: Update danmuku plugin with new mount option * chore: Update danmuku plugin with new mount option * chore: Refactor danmuku plugin to always create a new Setting instance * Refactor danmuku plugin to always create a new Setting instance * Refactor danmuku plugin to always create a new Setting instance * Update danmuku.js * Update danmuku.js * Refactor danmuku plugin to include a new Setting instance * Refactor danmuku plugin to include a new Setting instance * Refactor danmuku plugin styles for better alignment and spacing * Refactor danmuku plugin styles for better alignment and spacing * Refactor danmuku plugin styles for better alignment and spacing * Refactor danmuku plugin styles for better alignment and spacing * Refactor danmuku plugin styles for better alignment and spacing * chore: Update package.json files * Refactor danmuku plugin to remove unnecessary whitespace in the setting template * chore: Remove ESLint configuration files and update npm dependencies * chore: Update ESLint configuration to disable console warnings and fix unused variable warnings * chore: Update ESLint configuration to fix quotes rule * Update package.json * Update package.json * Update setting.js * chore: Compress CSS code in build script * chore: Update build script to compress JavaScript code * chore: Update build script to compress JavaScript code * chore: Refactor setting.js to improve code organization and remove unused variables * chore: Add isHover flag to Control component for better control hiding behavior * chore: Update Control component to use $bottom instead of $controls for better control hiding behavior * Update package.json * Update package.json * Update package.json * chore: Update lerna.json to use independent versioning and yarn as npm client * refactor: Update Danmuku class to support configurable modes and visibility * refactor: Update Danmuku styles for better visibility and configurability * feat: Update font weight in Danmuku styles for better readability * refactor: Update Danmuku class to support configurable modes and visibility * refactor: Add opacity, area, font, and speed sliders to Danmuku settings * refactor: Initialize sliders for opacity, area, font, and speed in Danmuku settings * feat: Add slider UI for opacity, area, and speed in Danmuku settings * feat: Update slider styles in Danmuku settings for better visibility and configurability * refactor: Improve Danmuku settings UI for better visibility and configurability * refactor: Improve Danmuku settings UI for better visibility and configurability * refactor: Update slider styles in Danmuku settings for better visibility and configurability * refactor: Update margin slider initialization in Danmuku settings * refactor: Update slider styles and initialization in Danmuku settings * refactor: Update Danmuku class to support configurable visibility * refactor: Update Danmuku class to support configurable visibility * refactor: Update Danmuku class to support configurable visibility * refactor: Update Danmuku class to support configurable visibility * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Improve Danmuku settings UI for better visibility and configurability * add lock * refactor: Add lock and unlock methods to Danmuku settings * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * Update artplayer-plugin-danmuku.d.ts * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings event listeners * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability * refactor: Update Danmuku settings UI for better visibility and configurability
This commit is contained in:
1 parent
dfd1cf968d
commit
699135afcf
402 files changed
+20804
-17005
No files matched your search
@@ -4,4 +4,4 @@
|
||||
* (c) 2017-2024 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=>{const 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,"undefined"!=typeof window&&(window.artplayerPluginLibass=i)},{"./adapter":"cjgNP","@parcel/transformer-js/src/esmodule-helpers.js":"6N8qz"}],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":"hidden"}#r(e){return this.#o(e)?e:new URL(e,document.baseURI).toString()}#o(e){return/^https?:\/\//.test(e)}#i({workerUrl:e,wasmUrl:t}){return new Promise((s=>{fetch(e).then((e=>e.text())).then((r=>{let n=r;n=n.replace(/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,((s,r)=>`wasmBinaryFile = "${t=t?thLine truncated
|
||||
!function(e,t,r,s,n){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},i="function"==typeof a[s]&&a[s],o=i.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function c(t,r){if(!o[t]){if(!e[t]){var n="function"==typeof a[s]&&a[s];if(!r&&n)return n(t,!0);if(i)return i(t,!0);if(l&&"string"==typeof t)return l(t);var d=Error("Cannot find module '"+t+"'");throw d.code="MODULE_NOT_FOUND",d}v.resolve=function(r){var s=e[t][1][r];return null!=s?s:r},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,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(c,"root",{get:function(){return a[s]}}),a[s]=c;for(var d=0;d<t.length;d++)c(t[d]);if(r){var u=c(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=u:"function"==typeof define&&define.amd&&define(function(){return u})}}({abjMI:[function(e,t,r){var s=e("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"default",()=>i);var n=e("./adapter"),a=s.interopDefault(n);function i(e){return t=>{let r=new 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=i)},{"./adapter":"cjgNP","@parcel/transformer-js/src/esmodule-helpers.js":"guZOB"}],cjgNP:[function(e,t,r){var s=e("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r);var n=e("libass-wasm"),a=s.interopDefault(n);let i=`[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.#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,r])=>(e[t]=this.#s(r),e),{})),this.libass=new a.default({subContent:i,video:this.$video,...e,workerUrl:await this.#i(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))}#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":"hidden"}#s(e){return this.#o(e)?e:new URL(e,document.baseURI).toString()}#o(e){return/^https?:\/\//.test(e)}#i({workerUrl:e,wasmUrl:t}){return new Promise(r=>{fetch(e).then(e=>e.text()).then(s=>{let n=s,a=new Blob([n=n.replace(/wasmBinaryFile\s*=\s*"(subtitles-octopus-worker\.wasm)"/g,(r,s)=>(t=t?this.#s(t):new URL(s,e).toString(),`wasmBinaryFile = "${t}"`))],{type:"text/javascript"});r(URL.createObjectURL(a))})})}#e(){let e=!1;Line truncated
|
||||
@@ -4,4 +4,4 @@
|
||||
* (c) 2017-2024 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,n,o){var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a="function"==typeof s[n]&&s[n],i=a.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function c(t,r){if(!i[t]){if(!e[t]){var o="function"==typeof s[n]&&s[n];if(!r&&o)return o(t,!0);if(a)return a(t,!0);if(l&&"string"==typeof t)return l(t);var u=new Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}d.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},d.cache={};var f=i[t]=new c.Module(t);e[t][0].call(f.exports,d,f,f.exports,this)}return i[t].exports;function d(e){var t=d.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=i,c.parent=a,c.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(c,"root",{get:function(){return s[n]}}),s[n]=c;for(var u=0;u<t.length;u++)c(t[u]);if(r){var f=c(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 o=e("./adapter"),s=n.interopDefault(o);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)}}}r.default=a,"undefined"!=typeof window&&(window.artplayerPluginLibass=a)},{"./adapter":"9NihZ","@parcel/transformer-js/src/esmodule-helpers.js":"8MTyn"}],"9NihZ":[function(e,t,r){var n=e("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(r),n.export(r,"default",(function(){return S}));var o=e("@swc/helpers/src/_async_to_generator.mjs"),s=n.interopDefault(o),a=e("@swc/helpers/src/_class_call_check.mjs"),i=n.interopDefault(a),l=e("@swc/helpers/src/_class_private_method_get.mjs"),c=n.interopDefault(l),u=e("@swc/helpers/src/_class_private_method_init.mjs"),f=n.interopDefault(u),d=e("@swc/helpers/src/_create_class.mjs"),p=n.interopDefault(d),h=e("@swc/helpers/src/_object_spread.mjs"),v=n.interopDefault(h),m=e("@swc/helpers/src/_object_spread_props.mjs"),y=n.interopDefault(m),b=e("@swc/helpers/src/_sliced_to_array.mjs"),w=n.interopDefault(b),g=e("@swc/helpers/src/_ts_generator.mjs"),j=n.interopDefault(g),_=e("libass-wasm"),k=n.interopDefault(_),x="[Script Info]\nScriptType: v4.00+",O=new WeakSet,E=new WeakSet,T=new WeakSet,M=new WeakSet,P=new WeakSet,L=new WeakSet,F=new WeakSet,C=new WeakSet,S=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,T),(0,f.default)(this,M),(0,f.default)(this,P),(0,f.default)(this,L),(0,f.default)(this,F),(0,f.default)(this,C);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,p.default)(e,[{key:"init",value:function(e){var t=this;return(0,s.default)((function(){var r,n,o,s;return(0,j.default)(this,(function(a){switch(a.label){case 0:return(0,c.default)(t,C,B).call(t),[4,(0,c.default)(t,O,A).call(t,e)];case 1:return a.sent(),(0,c.default)(t,E,R).call(t),t.art.emit("artplayerPluginLibass:init",t),(s=null===(r=t.art)||void 0===r||null===(n=r.option)||void 0===n||null===(o=n.subtitle)||void 0===o?void 0:o.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,c.default)(this,P,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,c.default)(this,M,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:function(){this.visible=!1}},{key:"destroy",value:function(){this.art.emit("artplayerPluginLibass:destroy"),(0,c.default)(this,T,W).call(this),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}}]),e}();function A(){return I.apply(this,arguments)}function I(){return I=(0,s.default)((function(){var eLine truncated
|
||||
!function(e,t,r,n,o){var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a="function"==typeof s[n]&&s[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 o="function"==typeof s[n]&&s[n];if(!r&&o)return o(t,!0);if(a)return a(t,!0);if(c&&"string"==typeof t)return c(t);var u=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 s[n]}}),s[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),n.export(r,"default",function(){return a});var o=e("./adapter"),s=n.interopDefault(o);function a(e){return function(t){var r=new 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":"9NihZ","@parcel/transformer-js/src/esmodule-helpers.js":"hTt7M"}],"9NihZ":[function(e,t,r){var n=e("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(r),n.export(r,"default",function(){return k});var o=e("@swc/helpers/_/_async_to_generator"),s=e("@swc/helpers/_/_class_call_check"),a=e("@swc/helpers/_/_class_private_method_get"),i=e("@swc/helpers/_/_class_private_method_init"),c=e("@swc/helpers/_/_create_class"),l=e("@swc/helpers/_/_object_spread"),u=e("@swc/helpers/_/_object_spread_props"),f=e("@swc/helpers/_/_sliced_to_array"),p=e("@swc/helpers/_/_ts_generator"),d=e("libass-wasm"),h=n.interopDefault(d),v=new WeakSet,m=new WeakSet,y=new WeakSet,_=new WeakSet,b=new WeakSet,g=new WeakSet,w=new WeakSet,j=new WeakSet,k=function(){function e(t,r){(0,s._)(this,e),(0,i._)(this,v),(0,i._)(this,m),(0,i._)(this,y),(0,i._)(this,_),(0,i._)(this,b),(0,i._)(this,g),(0,i._)(this,w),(0,i._)(this,j);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,c._)(e,[{key:"init",value:function(e){var t=this;return(0,o._)(function(){var r,n,o,s;return(0,p._)(this,function(i){switch(i.label){case 0:return(0,a._)(t,j,F).call(t),[4,(0,a._)(t,v,x).call(t,e)];case 1:return i.sent(),(0,a._)(t,m,E).call(t),t.art.emit("artplayerPluginLibass:init",t),(s=null===(o=t.art)||void 0===o?void 0:null===(n=o.option)||void 0===n?void 0:null===(r=n.subtitle)||void 0===r?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,b,P).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,_,M).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,y,T).call(this),this.libass.dispose(),URL.revokeObjectURL(this.workerScriptUrl),this.libass=null}}]),e}();function x(){return O.apply(this,arguments)}function O(){return(O=(0,o._)(function(){var e,t,r,n,o,s,i,c=arguments;return(0,p._)(this,function(p){switch(p.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")];return t.workerUrl||(t.workerUrl="https://cdnjs.cloudflare.com/ajax/libs/libass-wasm/4.1.0/js/subtitles-octopus-worker.js"),t.availableFonts&&(t.availaLine truncated
|
||||
@@ -1,127 +1,125 @@
|
||||
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
|
||||
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()
|
||||
this.#checkWebAssemblySupport();
|
||||
|
||||
await this.#createLibass(option)
|
||||
await this.#createLibass(option);
|
||||
|
||||
this.#addEventListeners()
|
||||
this.#addEventListeners();
|
||||
|
||||
this.art.emit("artplayerPluginLibass:init", this)
|
||||
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)
|
||||
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)
|
||||
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))
|
||||
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
|
||||
this.visible = this.art.subtitle.show;
|
||||
} else {
|
||||
this.currentType = "webvtt"
|
||||
this.hide()
|
||||
this.libass.freeTrack()
|
||||
this.currentType = 'webvtt';
|
||||
this.hide();
|
||||
this.libass.freeTrack();
|
||||
}
|
||||
}
|
||||
|
||||
setVisibility(visible) {
|
||||
this.visible = visible
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
setOffset(offset) {
|
||||
this.timeOffset = offset
|
||||
this.timeOffset = offset;
|
||||
}
|
||||
|
||||
get active() {
|
||||
return this.currentType === 'ass'
|
||||
return this.currentType === 'ass';
|
||||
}
|
||||
|
||||
get visible() {
|
||||
if (!this.libass)
|
||||
return false
|
||||
if (!this.libass) return false;
|
||||
|
||||
return this.libass.canvasParent.style.display !== "none"
|
||||
return this.libass.canvasParent.style.display !== 'none';
|
||||
}
|
||||
|
||||
set visible(visible) {
|
||||
this.art.emit("artplayerPluginLibass:visible", visible)
|
||||
this.art.emit('artplayerPluginLibass:visible', visible);
|
||||
|
||||
this.#setVttVisible(!this.active)
|
||||
this.#setVttVisible(!this.active);
|
||||
|
||||
if (this.libass.canvasParent) {
|
||||
this.libass.canvasParent.style.display = visible ? "block" : "none"
|
||||
this.libass.canvasParent.style.display = visible ? 'block' : 'none';
|
||||
|
||||
if (visible) this.libass.resize()
|
||||
if (visible) this.libass.resize();
|
||||
}
|
||||
}
|
||||
|
||||
get timeOffset() {
|
||||
return this.libass.timeOffset
|
||||
return this.libass.timeOffset;
|
||||
}
|
||||
|
||||
set timeOffset(offset) {
|
||||
this.art.emit("artplayerPluginLibass:timeOffset", offset)
|
||||
this.libass.timeOffset = offset
|
||||
this.art.emit('artplayerPluginLibass:timeOffset', offset);
|
||||
this.libass.timeOffset = offset;
|
||||
}
|
||||
|
||||
show() {
|
||||
this.visible = true
|
||||
this.visible = true;
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.visible = false
|
||||
this.visible = false;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.art.emit("artplayerPluginLibass:destroy")
|
||||
this.art.emit('artplayerPluginLibass:destroy');
|
||||
|
||||
this.#removeEventListeners()
|
||||
this.#removeEventListeners();
|
||||
|
||||
this.libass.dispose()
|
||||
URL.revokeObjectURL(this.workerScriptUrl)
|
||||
this.libass = null
|
||||
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')
|
||||
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'
|
||||
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
|
||||
}, {})
|
||||
option.availableFonts = Object.entries(option.availableFonts).reduce((acc, [key, value]) => {
|
||||
acc[key] = this.#toAbsoluteUrl(value);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
this.libass = new SubtitlesOctopus({
|
||||
@@ -131,9 +129,9 @@ export default class LibassAdapter {
|
||||
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.className = 'artplayer-plugin-libass';
|
||||
this.libass.canvasParent.style.cssText = `
|
||||
position: absolute;
|
||||
top: 0;
|
||||
@@ -142,81 +140,80 @@ 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.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.on('subtitle', this.visibleHandler);
|
||||
this.art.on('subtitleLoad', this.switchHandler);
|
||||
this.art.on('subtitleOffset', this.offsetHandler);
|
||||
|
||||
this.art.once("destroy", this.destroy.bind(this))
|
||||
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)
|
||||
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'
|
||||
this.$webvtt.style.visibility = visible ? 'visible' : 'hidden';
|
||||
}
|
||||
|
||||
#toAbsoluteUrl(url) {
|
||||
if (this.#isAbsoluteUrl(url))
|
||||
return 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()
|
||||
return new URL(url, document.baseURI).toString();
|
||||
}
|
||||
|
||||
#isAbsoluteUrl(url) {
|
||||
return /^https?:\/\//.test(url)
|
||||
return /^https?:\/\//.test(url);
|
||||
}
|
||||
|
||||
#loadWorker({ workerUrl, wasmUrl }) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(workerUrl)
|
||||
.then(res => res.text())
|
||||
.then(text => {
|
||||
let workerScriptContent = text
|
||||
.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()
|
||||
wasmUrl = new URL(wasm, workerUrl).toString();
|
||||
} else {
|
||||
wasmUrl = this.#toAbsoluteUrl(wasmUrl)
|
||||
wasmUrl = this.#toAbsoluteUrl(wasmUrl);
|
||||
}
|
||||
|
||||
return `wasmBinaryFile = "${wasmUrl}"`
|
||||
}
|
||||
)
|
||||
return `wasmBinaryFile = "${wasmUrl}"`;
|
||||
},
|
||||
);
|
||||
|
||||
const workerBlob = new Blob([workerScriptContent], { type: "text/javascript" })
|
||||
resolve(URL.createObjectURL(workerBlob))
|
||||
})
|
||||
})
|
||||
const workerBlob = new Blob([workerScriptContent], { type: 'text/javascript' });
|
||||
resolve(URL.createObjectURL(workerBlob));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#checkWebAssemblySupport() {
|
||||
let supportsWebAssembly = false
|
||||
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 (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)
|
||||
supportsWebAssembly = new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
|
||||
}
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
|
||||
this.utils.errorHandle(supportsWebAssembly, "Browser does not support WebAssembly")
|
||||
this.utils.errorHandle(supportsWebAssembly, 'Browser does not support WebAssembly');
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
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 Options } from 'libass-wasm';
|
||||
|
||||
export = artplayerPluginAss
|
||||
export as namespace artplayerPluginAss
|
||||
export = artplayerPluginAss;
|
||||
export as namespace artplayerPluginAss;
|
||||
|
||||
declare const artplayerPluginAss: (options: Options) => (art: Artplayer) => {
|
||||
name: 'artplayerPluginLibass';
|
||||
|
||||
Reference in new issue
Block a user