Files
ArtPlayer/docs/compiled/artplayer-plugin-multiple-subtitles.esm.js
T
Harvey Zack 35ad9883af 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.
2025-08-03 13:17:33 +08:00

9 lines
15 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*!
* artplayer-plugin-multiple-subtitles.js v1.1.0
* Github: https://github.com/zhw2590582/ArtPlayer
* (c) 2017-2025 Harvey Zack
* Released under the MIT License.
*/
!function(e,t,n,i,r,a,o,s){var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},u="function"==typeof l[i]&&l[i],f=u.i||{},d=u.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,n){if(!d[t]){if(!e[t]){if(r[t])return r[t];var a="function"==typeof l[i]&&l[i];if(!n&&a)return a(t,!0);if(u)return u(t,!0);if(c&&"string"==typeof t)return c(t);var o=Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}f.resolve=function(n){var i=e[t][1][n];return null!=i?i:n},f.cache={};var s=d[t]=new p.Module(t);e[t][0].call(s.exports,f,s,s.exports,l)}return d[t].exports;function f(e){var t=f.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=c,this.exports={}},p.modules=e,p.cache=d,p.parent=u,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=f,p.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(p,"root",{get:function(){return l[i]}}),l[i]=p;for(var m=0;m<t.length;m++)p(t[m]);if(n){var g=p(n);"object"==typeof exports&&"undefined"!=typeof module?module.exports=g:"function"==typeof define&&define.amd&&define(function(){return g})}}({"3MgS1":[function(e,t,n,i){var r=e("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(n),r.export(n,"default",()=>s);var a=e("./parser");async function o(e,{getExt:t,srtToVtt:n,assToVtt:i}){let r=await fetch(e.url),a=await r.arrayBuffer(),o=new TextDecoder(e.encoding||"utf-8").decode(a);switch(e.type||t(e.url)){case"srt":return n(o);case"ass":return i(o);case"vtt":return o;default:return""}}function s({subtitles:e=[]}){return async t=>{let{unescape:n,getExt:i,srtToVtt:r,assToVtt:s}=t.constructor.utils,l=new(0,a.WebVTTParser),u=new(0,a.WebVTTSerializer),f=(await Promise.all(e.map(e=>o(e,{getExt:i,srtToVtt:r,assToVtt:s})))).map((t,n)=>{let i=l.parse(t,"metadata");return i.url=e[n].url,i.name=e[n].name,i}),d="";function c(e=[]){let i=function(e){let t=new(0,a.WebVTTParser)().parse("","metadata");for(let n=0;n<e.length;n++){let i=e[n];if(!i.updated){i.updated=!0;for(let e=0;e<i.cues.length;e++){let t=i.cues[e];for(let e=0;e<t.tree.children.length;e++){let n=t.tree.children[e];n.value=`<div class="art-subtitle-${i.name}">${n.value}</div>`}}}t.cues.push(...i.cues)}return t}(e),r=u.serialize(i.cues);URL.revokeObjectURL(d);let o=URL.createObjectURL(new Blob([r],{type:"text/vtt"}));d=o,t.option.subtitle.escape=!1,t.subtitle.init({...t.option.subtitle,url:o,type:"vtt",onVttLoad:n})}return c(f),{name:"multipleSubtitles",tracks:(e=[])=>c(e.map(e=>f.find(t=>t.name===e))),reset:()=>c(f)}}}"undefined"!=typeof window&&(window.artplayerPluginMultipleSubtitles=s)},{"./parser":"01rPS","@parcel/transformer-js/src/esmodule-helpers.js":"5lQoW"}],"01rPS":[function(e,t,n,i){!function(){var e={direction:"horizontal",snapToLines:!0,linePosition:"auto",lineAlign:"start",textPosition:"auto",positionAlign:"auto",size:100,alignment:"center"},t=function(t){t||(t={"&amp":"&","&lt":"<","&gt":">","&lrm":"‎","&rlm":"‏","&nbsp":" "}),this.entities=t,this.parse=function(n,a){n=n.replace(/\0/g,"�");var o=Date.now(),s=0,l=n.split(/\r\n|\r|\n/),u=!1,f=[],d=[],c=[];function p(e,t){c.push({message:e,line:s+1,col:t})}var m=l[s],g=m.length,v="WEBVTT",h=0,b=v.length;for("\uFEFF"===m[0]&&(h=1,b+=1),(g<b||m.indexOf(v)!==0+h||g>b&&" "!==m[b]&&" "!==m[b])&&p('No valid signature. (File needs to start with "WEBVTT".)'),s++;""!=l[s]&&void 0!=l[s];){if(p("No blank line after the signature."),-1!=l[s].indexOf("--\x3e")){u=!0;break}s++}for(;void 0!=l[s];){for(;!u&&""==l[s];)s++;if(!u&&void 0==l[s])break;var T=Object.assign({},e,{id:"",startTime:0,endTime:0,pauseOnExit:!1,direction:"horizontal",snapToLines:!0,linePosition:"auto",lineAlign:"start",textPosition:"auto",positionAlign:"auto",size:100,alignment:"center",text:"",tree:null}),x=!0;if(-1==l[s].indexOf("--\x3e")){if(T.id=l[s],/^NOTE($|[ \t])/.test(T.id)){for(s++;""!=l[s]&&void 0!=l[s];)-1!=l[s].indexOf("--\x3e")&&p("Cannot have timestamp in a comment."),s++;continue}if(/^STYLE($|[ \t])/.test(T.id)){var y=[],w=!1;for(s++;""!=l[s]&&void 0!=l[s];)-1!=l[s].indexOf("--\x3e")&&(p("Cannot have timestamp in a style block."),w=!0),y.push(l[s]),s++;if(d.length){p("Style blocks cannot appear after the first cue.");continue}w||f.push(y.join("\n"));continue}if(""==l[++s]||void 0==l[s]){p("Cue identifier cannot be standalone.");continue}if(-1==l[s].indexOf("--\x3e")){x=!1,p("Cue identifier needs to be followed by timestamp.");continue}}u=!1;var O=new i(l[s],p),S=0;if(d.length>0&&(S=d[d.length-1].startTime),x&&!O.parse(T,S)){for(T=null,s++;""!=l[s]&&void 0!=l[s];){if(-1!=l[s].indexOf("--\x3e")){u=!0;break}s++}continue}for(s++;""!=l[s]&&void 0!=l[s];){if(-1!=l[s].indexOf("--\x3e")){p("Blank line missing before cue."),u=!0;break}""!=T.text&&(T.text+="\n"),T.text+=l[s],s++}var P=new r(T.text,p,a,t);T.tree=P.parse(T.startTime,T.endTime),d.push(T)}return d.sort(function(e,t){return e.startTime<t.startTime?-1:e.startTime>t.startTime?1:e.endTime>t.endTime?-1:+(e.endTime<t.endTime)}),{cues:d,errors:c,time:Date.now()-o,styles:f}}},i=function(e,t){var n=/[\u0020\t\f]/,i=/[^\u0020\t\f]/,e=e,r=0,a=function(e){t(e,r+1)};function o(t){for(;void 0!=e[r]&&t.test(e[r]);)r++}function s(t){for(var n="";void 0!=e[r]&&t.test(e[r]);)n+=e[r],r++;return n}function l(){var t,n,i,o,l="minutes";if(void 0==e[r])return void a("No timestamp found.");if(!/\d/.test(e[r]))return void a("Timestamp must start with a character in the range 0-9.");if(((t=s(/\d/)).length>2||parseInt(t,10)>59)&&(l="hours"),":"!=e[r])return void a("No time unit separator found.");if(r++,2!=(n=s(/\d/)).length)return void a("Must be exactly two digits.");if("hours"==l||":"==e[r]){if(":"!=e[r])return void a("No seconds found or minutes is greater than 59.");if(r++,2!=(i=s(/\d/)).length)return void a("Must be exactly two digits.")}else{if(2!=t.length)return void a("Must be exactly two digits.");i=n,n=t,t="0"}return"."!=e[r]?void a('No decimal separator (".") found.'):(r++,3!=(o=s(/\d/)).length)?void a("Milliseconds must be given in three digits."):parseInt(n,10)>59?void a("You cannot have more than 59 minutes."):parseInt(i,10)>59?void a("You cannot have more than 59 seconds."):3600*parseInt(t,10)+60*parseInt(n,10)+parseInt(i,10)+parseInt(o,10)/1e3}this.parse=function(t,s){return(o(n),t.startTime=l(),void 0==t.startTime)?void 0:(t.startTime<s&&a("Start timestamp is not greater than or equal to start timestamp of previous cue."),i.test(e[r])&&a("Timestamp not separated from '--\x3e' by whitespace."),o(n),"-"!=e[r]||"-"!=e[++r]||">"!=e[++r])?void a("No valid timestamp separator found."):(r++,i.test(e[r])&&a("'--\x3e' not separated from timestamp by whitespace."),o(n),t.endTime=l(),void 0!=t.endTime)?(t.endTime<=t.startTime&&a("End timestamp is not greater than start timestamp."),i.test(e[r]),o(n),!function(e,t){for(var i=e.split(n),r=[],o=0;o<i.length;o++)if(""!=i[o]){var s=i[o].indexOf(":"),l=i[o].slice(0,s),u=i[o].slice(s+1);if(-1!=r.indexOf(l)&&a("Duplicate setting."),r.push(l),""==u)return void a("No value for setting defined.");if("vertical"==l){if("rl"!=u&&"lr"!=u){a("Writing direction can only be set to 'rl' or 'rl'.");continue}t.direction=u}else if("line"==l){if(/,/.test(u)){var f=u.split(",");u=f[0];var d=f[1]}if(!/^[-\d](\d*)(\.\d+)?%?$/.test(u)){a("Line position takes a number or percentage.");continue}if(-1!=u.indexOf("-",1)){a("Line position can only have '-' at the start.");continue}if(-1!=u.indexOf("%")&&u.indexOf("%")!=u.length-1){a("Line position can only have '%' at the end.");continue}if("-"==u[0]&&"%"==u[u.length-1]){a("Line position cannot be a negative percentage.");continue}var c=u,p=!1;if("%"==u[u.length-1]&&(p=!0,c=u.slice(0,u.length-1),parseInt(u,10)>100)){a("Line position cannot be >100%.");continue}if(""===c||isNaN(c)||!isFinite(c)){a("Line position needs to be a number");continue}if(void 0!==d){if(!["start","center","end"].includes(d)){a("Line alignment needs to be one of start, center or end");continue}t.lineAlign=d}t.snapToLines=!p,t.linePosition=parseFloat(c),parseFloat(c).toString()!==c&&(t.nonSerializable=!0)}else if("position"==l){if(/,/.test(u)){var f=u.split(",");u=f[0];var m=f[1]}if("%"!=u[u.length-1]){a("Text position must be a percentage.");continue}if(parseInt(u,10)>100||0>parseInt(u,10)){a("Text position needs to be between 0 and 100%.");continue}if(""===(c=u.slice(0,u.length-1))||isNaN(c)||!isFinite(c)){a("Line position needs to be a number");continue}if(void 0!==m){if(!["line-left","center","line-right"].includes(m)){a("Position alignment needs to be one of line-left, center or line-right");continue}t.positionAlign=m}t.textPosition=parseFloat(c)}else if("size"==l){if("%"!=u[u.length-1]){a("Size must be a percentage.");continue}if(parseInt(u,10)>100){a("Size cannot be >100%.");continue}var g=u.slice(0,u.length-1);if(void 0===g||""===g||isNaN(g)){a("Size needs to be a number"),g=100;continue}if((g=parseFloat(g))<0||g>100){a("Size needs to be between 0 and 100%.");continue}t.size=g}else if("align"==l){var v=["start","center","end","left","right"];if(-1==v.indexOf(u)){a("Alignment can only be set to one of "+v.join(", ")+".");continue}t.alignment=u}else a("Invalid setting.")}}(e.substring(r),t),!0):void 0},this.parseTimestamp=function(){var t=l();return void 0!=e[r]?void a("Timestamp must not have trailing characters."):t}},r=function(e,t,n,r){this.entities=r;var a=this,e=e,o=0,s=function(e){"metadata"!=n&&t(e,o+1)};this.parse=function(t,l){var u={children:[]},f=u,d=[];function c(e){f.children.push({type:"object",name:e[1],classes:e[2],children:[],parent:f}),f=f.children[f.children.length-1]}for(;void 0!=e[o];){var p=function(){for(var t="data",n="",i="",l=[];void 0!=e[o-1]||0==o;){var u=e[o];if("data"==t)if("&"==u)i=u,t="escape";else if("<"==u&&""==n)t="tag";else{if("<"==u||void 0==u)return["text",n];n+=u}else if("escape"==t)if("<"==u||void 0==u){let e;return s("Incorrect escape."),(e=i.match(/^&#([0-9]+)$/))?n+=String.fromCharCode(e[1]):a.entities[i]?n+=a.entities[i]:n+=i,["text",n]}else if("&"==u)s("Incorrect escape."),n+=i,i=u;else if(/[a-z#0-9]/i.test(u))i+=u;else if(";"==u){let e;(e=i.match(/^&#(x?[0-9]+)$/))?n+=String.fromCharCode("0"+e[1]):a.entities[i+u]?n+=a.entities[i+u]:(e=Object.keys(r).find(e=>i.startsWith(e)))?n+=a.entities[e]+i.slice(e.length)+u:(s("Incorrect escape."),n+=i+";"),t="data"}else s("Incorrect escape."),n+=i+u,t="data";else if("tag"==t)if(" "==u||"\n"==u||"\f"==u||" "==u)t="start tag annotation";else if("."==u)t="start tag class";else if("/"==u)t="end tag";else if(/\d/.test(u))n=u,t="timestamp tag";else{if(">"==u||void 0==u)return">"==u&&o++,["start tag","",[],""];n=u,t="start tag"}else if("start tag"==t)if(" "==u||"\f"==u||" "==u)t="start tag annotation";else if("\n"==u)i=u,t="start tag annotation";else if("."==u)t="start tag class";else{if(">"==u||void 0==u)return">"==u&&o++,["start tag",n,[],""];n+=u}else if("start tag class"==t)if(" "==u||"\f"==u||" "==u)i&&l.push(i),i="",t="start tag annotation";else if("\n"==u)i&&l.push(i),i=u,t="start tag annotation";else if("."==u)i&&l.push(i),i="";else{if(">"==u||void 0==u)return">"==u&&o++,i&&l.push(i),["start tag",n,l,""];i+=u}else if("start tag annotation"==t)if(">"==u||void 0==u)return">"==u&&o++,["start tag",n,l,i=i.split(/[\u0020\t\f\r\n]+/).filter(function(e){if(e)return!0}).join(" ")];else i+=u;else if("end tag"==t)if(">"==u||void 0==u)return">"==u&&o++,["end tag",n];else n+=u;else if("timestamp tag"==t)if(">"==u||void 0==u)return">"==u&&o++,["timestamp",n];else n+=u;else s("Never happens.");o++}}();if("text"==p[0])f.children.push({type:"text",value:p[1],parent:f});else if("start tag"==p[0]){"chapters"==n&&s("Start tags not allowed in chapter title text.");var m=p[1];"v"!=m&&"lang"!=m&&""!=p[3]&&s("Only<v>and<lang>can have an annotation."),"c"==m||"i"==m||"b"==m||"u"==m||"ruby"==m||"rt"==m&&"ruby"==f.name?c(p):"v"==m?(function(e){for(var t=f;t;){if("v"==t.name)return!0;t=t.parent}}(0)&&s("<v>cannot be nested inside itself."),c(p),f.value=p[3],p[3]||s("<v>requires an annotation.")):"lang"==m?(c(p),f.value=p[3]):s("Incorrect start tag.")}else if("end tag"==p[0])"chapters"==n&&s("End tags not allowed in chapter title text."),p[1]==f.name?f=f.parent:"ruby"==p[1]&&"rt"==f.name?f=f.parent.parent:s("Incorrect end tag.");else if("timestamp"==p[0]){"chapters"==n&&s("Timestamp not allowed in chapter title text.");var g=new i(p[1],s).parseTimestamp();void 0!=g&&((g<=t||g>=l)&&s("Timestamp must be between start timestamp and end timestamp."),d.length>0&&d[d.length-1]>=g&&s("Timestamp must be greater than any previous timestamp."),f.children.push({type:"timestamp",value:g,parent:f}),d.push(g))}}for(;f.parent;)"v"!=f.name&&s("Required end tag missing."),f=f.parent;return function e(t){let n={...t};return t.children&&(n.children=t.children.map(e)),n.parent&&delete n.parent,n}(u)}},a=function(){function t(e){let t=("00"+1e3*(e-Math.floor(e)).toFixed(3)).slice(-3),n=0,i=0,r=0;return e>=3600&&(n=Math.floor(e/3600)),i=Math.floor((e-3600*n)/60),r=Math.floor(e-3600*n-60*i),(n?n+":":"")+(""+i).padStart(2,"0")+":"+(""+r).padStart(2,"0")+"."+t}this.serialize=function(n,i){var r,a="WEBVTT\n\n";if(i)for(var o=0;o<i.length;o++)a+="STYLE\n"+i[o]+"\n\n";for(var o=0;o<n.length;o++)a+=(void 0!==(r=n[o]).id?r.id+"\n":"")+t(r.startTime)+" --\x3e "+t(r.endTime)+function(t){var n="";let i=Object.keys(e).filter(n=>t[n]!==e[n]);return i.includes("direction")&&(n+=" vertical:"+t.direction),i.includes("alignment")&&(n+=" align:"+t.alignment),i.includes("size")&&(n+=" size:"+t.size+"%"),(i.includes("lineAlign")||i.includes("linePosition"))&&(n+=" line:"+t.linePosition+(t.snapToLines?"":"%")+(t.lineAlign&&t.lineAlign!=e.lineAlign?","+t.lineAlign:"")),(i.includes("textPosition")||i.includes("positionAlign"))&&(n+=" position:"+t.textPosition+"%"+(t.positionAlign&&t.positionAlign!==e.positionAlign?","+t.positionAlign:"")),n}(r)+"\n"+function e(n){for(var i="",r=0;r<n.length;r++){var a=n[r];if("text"==a.type)i+=a.value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");else if("object"==a.type){if(i+="<"+a.name,a.classes)for(var o=0;o<a.classes.length;o++)i+="."+a.classes[o];a.value&&(i+=" "+a.value),i+=">",a.children&&(i+=e(a.children)),i+="</"+a.name+">"}else"timestamp"==a.type?i+="<"+t(a.value)+">":i+="<"+a.value+">"}return i}(r.tree.children)+"\n\n";return a}};function o(e){e.WebVTTParser=t,e.WebVTTCueTimingsAndSettingsParser=i,e.WebVTTCueTextParser=r,e.WebVTTSerializer=a}"undefined"!=typeof window&&o(window),o(n)}()},{}],"5lQoW":[function(e,t,n,i){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach(function(n){"default"===n||"__esModule"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}]},["3MgS1"],"3MgS1","parcelRequire4dc0",{});let{default:e}=parcelRequire4dc0("3MgS1");export{e as default};
//# sourceMappingURL=artplayer-plugin-multiple-subtitles.esm.js.map