import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var Ax='application/mp4; codecs\x3d"stpp.ttml"',Bx='application/mp4; codecs\x3d"stpp.ttml.im1i"',Cx='application/mp4; codecs\x3d"stpp.ttml.im1t"',Dx="backgroundColor",Ex="direction",Fx="displayAlign",Gx="region",Hx="textAlign",Ix="textDecoration",Jx="writingMode",Kx=function(a,b,c){a=a.f;for(let d=a.length-1;0<=d;d--){const e=b.get(a[d]);if(e.hasAttribute(c))return e.getAttribute(c)}return null},Sx=function(a,b){var c=null;if(Lx.test(a)){{a=Lx.exec(a);c=Number(a[1]);const d=Number(a[2]);
let e=Number(a[3]),f=Number(a[4]);f+=(Number(a[5])||0)/b.f;e+=f/b.frameRate;c=e+60*d+3600*c}}else Mx.test(a)?c=Nx(Mx,a):Ox.test(a)?c=Nx(Ox,a):Px.test(a)?(a=Px.exec(a),c=Number(a[1])/b.frameRate):Qx.test(a)?(a=Qx.exec(a),c=Number(a[1])/b.a):Rx.test(a)&&(c=Nx(Rx,a));return c},Nx=function(a,b){a=a.exec(b);return null==a||""===a[0]?null:(Number(a[4])||0)/1E3+(Number(a[3])||0)+60*(Number(a[2])||0)+3600*(Number(a[1])||0)},Tx=function(a){return a.split(":").pop()},Ux=function(a){return a.replace(/(\d*\.?\d+)c/g,
"$1em")},Wx=function(a,b){for(;Vx.test(a);){const c=Vx.exec(a)[0];a=a.replace(c,`${parseInt(c,10)/b}em`)}return a},Xx=function(a){return a?a.replace(/(\d*\.?\d+)%/g,(b,c)=>`${c/100}em`):""},Yx=function(a,b,c){a=Kx(a,b,Hx);if(!a&&c&&(a=Kx(c,b,Hx),!a&&"rltb"===Kx(c,b,Jx)))return _.Rd;switch(a){case _.Uc:return _.Qt;case _.wf:case _.Rd:return _.Rd;default:return _.Jf}},Zx=function(a,b,c){if(_.cj(a.w))return document.createTextNode(_.gj(a.w||""));if(a.A)return _.op("br");const d=_.op("span");for(const e of a.f)_.pp(d,
e);for(const e of a.j)d.appendChild(Zx(c.get(e),b,c));return d},by=function(a,b,c,d){const e=$x.exec(a);a=ay.exec(a);return typeof b===_.t&&0<b&&a?100*Number(a[c])/b:e?Number(e[c]):a?Number(a[c]):d},cy=function(a,b){return typeof b===_.t&&0<b?_.Yt:ay.test(a)?0:_.Yt},dy=function(a,b,c){return typeof a===_.t?a:typeof b===_.t?b:c},ey=function(a,b){a=a.getAttribute("extent");return(a=ay.exec(a))?Number(a[b]):null},gy=function(a){a=a.getAttribute("cellResolution");return(a=fy.exec(a))?Number(a[2]):null},
iy=function(){return`${"inline-"}${hy++}`},ky=function(a){return jy.some(b=>b in a.attributes)},ly=function(a,b){if(0===b.length)return[];const c=[];for(const d of b)a.a.has(d)&&c.push(...ly(a,a.a.get(d).f),d);return c},my=function(a){return a.o.map(b=>b.build(a.l,a.w,a.A,a.h,a.a,a.j,a.f)).filter(b=>null!=b)},ny=function(a){return Tx(a.h.nodeName)},qy=function(a,b){if(a.a.has(b))return a.a.get(b);var c=null,d=null;let e=[],f=[],g={};const h=b.parentNode;if(h&&a.a.has(h)){const k=a.a.get(h);e=[...k.l];
-1===[_.da,"span","br"].indexOf(b.nodeName)&&(c=k.a,d=k.j,f=[...k.f],g={},oy.forEach(l=>{l in k.attributes&&(g[l]=k.attributes[l])}))}if(b.nodeType===b.ELEMENT_NODE){b.hasAttribute(Gx)&&(c=b.getAttribute(Gx));b.hasAttribute(_.Pf)&&f.push(...b.getAttribute(_.Pf).split(" "));d=Array.from(b.attributes).map(k=>k.name);for(const k of d)d=Tx(k),g[d]=b.getAttribute(k);d=g.backgroundImage}c=new py(b,c,d,e,f,g);a.a.set(b,c);return c},ry=function(a){return`${String(Math.floor(a/3600)).padStart(2,"0")}:${String(Math.floor(a/
60%60)).padStart(2,"0")}:${String(Math.floor(a%60)).padStart(2,"0")}.${String(Math.floor(1E3*a%1E3)).padStart(3,"0")}`},sy=class{constructor(a,b,c){this.h=a;this.f=b;this.a=c}getId(){return this.h}hasAttribute(a){return a in this.a}getAttribute(a){return this.a[a]}};var ty=class extends sy{constructor(a,b,c){super(a,[],c);this.j=b||""}};var uy=class extends sy{constructor(a,b,c){super(a,b,c)}};var Lx=/^(\d{2,}):(\d{2}):(\d{2}):(\d{2})\.?(\d+)?$/,Mx=/^(?:(\d{2,}):)?(\d{2}):(\d{2})$/,Ox=/^(?:(\d{2,}):)?(\d{2}):(\d{2}\.\d+)$/,Px=/^(\d*(?:\.\d*)?)f$/,Qx=/^(\d*(?:\.\d*)?)t$/,Rx=/^(?:(\d*(?:\.\d*)?)h)?(?:(\d*(?:\.\d*)?)m)?(?:(\d*(?:\.\d*)?)s)?(?:(\d*(?:\.\d*)?)ms)?$/,$x=/^(\d{1,2}(?:\.\d+)?|100(?:\.0+)?)% (\d{1,2}(?:\.\d+)?|100(?:\.0+)?)%$/,ay=/^(\d+)px (\d+)px$/,fy=/^(\d+) (\d+)$/,Vx=/(\d+)px/,vy=/^(\d+px|\d+em|\d*\.?\d+c)$/,jy=[Dx,"color",Ex,Fx,"fontFamily","fontSize","fontStyle","fontWeight",
"lineHeight","opacity","padding",Hx,Ix,"textOutline",Jx,"zIndex"],oy=["begin",_.Rd];var wy=class extends uy{constructor(a,b,c,d,e,f,g){super(a,f,g);this.w=b;this.A=c;this.o=d;this.l=e;this.j=[]}build(a,b,c,d,e,f,g){let h=Sx(this.a.begin,b);b=Sx(this.a.end,b);if(null===h||null===b)return null;h+=c;b+=c;c=_.op(_.Cd);for(const k of this.j)c.appendChild(Zx(g.get(k),e,g));g=new _.Vt(h,b,c.innerHTML.trim(),_.bg);g.cssClassList=[...this.f];g.textAlign=Yx(this,e,null);g.writingMode=_.Rt;g.line=-1;g.lineInterpretation=_.St;g.lineAlign=_.Tt;g.containerRows=dy(null,gy(a),15);if(this.o&&(f=
f.get(this.o))){g.region=f.build(a,e);g.textAlign=Yx(this,e,f);a:switch(Kx(f,e,Jx)){case "tb":case "tblr":a=_.mg;break a;case "tbrl":a=_.ng;break a;default:a=_.Rt}g.writingMode=a;a:switch(Kx(f,e,Fx)){case _.Uc:a=50;break a;case "after":a=-1;break a;default:a=0}g.line=a;a:switch(Kx(f,e,Fx)){case _.Uc:a=1;break a;default:a=_.St}g.lineInterpretation=a;a:switch(Kx(f,e,Fx)){case _.Uc:e=_.Uc;break a;default:e=_.Tt}g.lineAlign=e}this.l&&(d=d.get(this.l))&&(a=d,d=a.getAttribute("encoding"),e=a.getAttribute("imageType")||
a.getAttribute("imagetype"),a=a.j.trim(),d="PNG"===e&&"Base64"===d&&0<a.length?`data:image/png;base64,${a}`:null,g.backgroundImage=d||"");return g}};var xy=class{constructor(a,b,c,d){this.frameRate=Number(a)||30;this.f=Number(b)||1;this.a=Number(d);0===this.a&&(this.a=a?this.frameRate*this.f:1);c&&(a=/^(\d+) (\d+)$/g.exec(c))&&(this.frameRate*=Number(a[1])/Number(a[2]))}};var yy=class extends uy{constructor(a,b,c){super(a,b,c)}build(a,b){const c=new _.$t;c.id=this.getId();const d=dy(a.j.containerWidth,ey(a,1),720);a=dy(a.j.containerHeight,ey(a,2),480);a:switch(Kx(this,b,Fx)){case "after":var e="flex-start";break a;case _.Uc:e=_.Uc;break a;default:e="flex-end"}c.displayAlign=e;a:switch(Kx(this,b,Jx)){case "tb":case "tblr":e="row-reverse";break a;case "tbrl":e="row";break a;default:e=_.nd}c.writingMode=e;e=this.getAttribute("extent")||Kx(this,b,"extent");c.width=by(e,
d,1,100);c.widthUnits=cy(e,d);c.height=by(e,a,2,100);c.heightUnits=cy(e,a);b=this.getAttribute("origin")||Kx(this,b,"origin");c.viewportAnchorX=by(b,d,1,0);c.viewportAnchorY=by(b,a,2,0);c.viewportAnchorUnits=cy(b,d);c.cssClassList=[...this.f];return c}};var zy=class extends sy{constructor(a,b){super("root-container",[],b);this.j=a}};var By=class extends sy{constructor(a,b,c){super(a,b,c)}build(a){var b=null;var c=gy(a);c&&(b=dy(a.j.containerHeight,ey(a,2),480)/c);b=dy(a.j.fontSizeRadix,b,16);a=[];c=`::ttml .${this.h}, ::ttml .${this.h} * {`;for(const [g,h]of Ay.entries())g in this.a&&(c+=`${h}:${Ux(this.a[g])};`);a:{if("unicodeBidi"in this.a){var d=this.a.unicodeBidi;var e="";switch(d){case "normal":case "embed":e=d;break;case "bidiOverride":e="bidi-override"}if(0<e.length){d=`unicode-bidi:${e};`;break a}}d=""}c+=d;a:{if("textOutline"in
this.a){d=this.a.textOutline.split(" ");e="black";let g=".4em";const h=d[0]&&d[0].trim(),k=d[1]&&d[1].trim(),l=d[2]&&d[2].trim();3===d.length&&!vy.test(h)&&vy.test(k)&&vy.test(l)?(e=h,g=k):2===d.length&&!vy.test(h)&&vy.test(k)?(e=h,g=k):2===d.length&&vy.test(h)&&vy.test(k)&&(g=h);if(""!==g){g=Ux(g);d="text-shadow:"+`0 0 ${g} ${e},`+`0 0 ${g} ${e},`+`0 0 ${g} ${e};`;break a}}d=""}c+=d;"textShadow"in this.a?(d=Xx(this.a.textShadow),d=Ux(d),d=`text-shadow:${d};`):d="";c=c+d+("fontFamily"in this.a?`font-family:${this.a.fontFamily.replace("monospaceSansSerif",
"monospace").replace("monospaceSerif","monospace").replace("proportionalSansSerif","sans-serif").replace("proportionalSerif","sans-serif").replace("sansSerif","sans-serif").replace("default","sans-serif")};`:"");a:{if(Ix in this.a){d=this.a.textDecoration.split(" ");e=[];for(f of d)switch(f){case "underline":case "overline":e.push(f);break;case "lineThrough":e.push("line-through")}if(0<e.length){var f=`text-decoration:${e.join(" ")};`;break a}}f=""}"padding"in this.a?(d="border: solid transparent;border-width:"+
Ux(this.a.padding),d+=";"):d="";f=c=c+f+d;"lineHeight"in this.a?(c="",d=this.a.lineHeight,d=Ux(d),d=Wx(d,b),c+="line-height:",c+=d,c+=";"):c="";a.push(f+c+"}");a:{if("fontSize"in this.a&&(f=this.a.fontSize.split(" "),c=null,1===f.length&&(c=f[0]),2===f.length&&(c=f[1]),c)){c=c.trim();c=Ux(c);c=Wx(c,b);b=`font-size:${c};`;break a}b=null}b&&(f=`::ttml .${this.h} .clpp-text-wrapper {`,f+=b,f+="}",a.push(f),f=`::ttml .clpp-text-wrapper__${this.h} {`,f+=b,f+="}",a.push(f));return a}},Ay=new Map([[Dx,"background-color"],
["color","color"],[Ex,Ex],["fontStyle","font-style"],["fontWeight","font-weight"],["opacity","opacity"],["zIndex","z-index"]]);var Cy=class{constructor(a){this.B=a;this.w=this.l=null;this.A=0;this.h=new Map;this.a=new Map;this.j=new Map;this.f=new Map;this.o=[]}},hy=0;var Fy=class{constructor(a){this.a=a.firstChild;this.f=new Set}nd(){return!!this.a}next(){if(!this.a)return null;let a=this.a;do this.f.add(a),a.nodeType!==Node.TEXT_NODE&&!Dy.has(Tx(a.nodeName))||Ey.has(Tx(a.nodeName))||!a.firstChild||this.f.has(a.firstChild)?a.nextSibling?a=a.nextSibling:a=a.parentNode:a=a.firstChild;while(a&&(this.f.has(a)||a.nodeType!==Node.TEXT_NODE&&!Dy.has(Tx(a.nodeName))));const b=this.a;this.a=a;return b}},Dy=new Set(["tt","head","layout",_.se,_.be,Gx,"styling",_.Pf,"body",
_.Cd,"p","span","br"]),Ey=new Set([_.Pf,_.be]);var py=class{constructor(a,b,c,d,e,f){this.h=a;this.a=b;this.j=c;this.l=d;this.f=e;this.attributes=f}getId(){return this.attributes.id}};var Gy=class{constructor(){this.a=new Map}};var Hy=class{constructor(a){this.a=a;this.f=new DOMParser}parseInit(){}parseMedia(a,b,c){c&&c.length||(c=[a.byteLength]);var d=_.Xg(this.a.ttml||{}),e=_.K(a,0,c[0]);e=_.Ui(e);if(""===e)return{cues:[],styles:[]};var f=null;try{f=this.f.parseFromString(e,_.Tf)}catch(m){throw new _.I(_.G,2,2005,"Failed to parse TTML.");}d=new Cy(d);e=new Gy;f=new Fy(f);b=b.periodStart;typeof b===_.t&&(d.A=b);b=c[0];for(var g=1;g<c.length;++g){var h=c[g],k=_.K(a,b,h);k=_.Hl(k);const m=`urn:mpeg:14496-30:subs:${g}`;d.h.set(m,
new ty(m,k,{imageType:"PNG",encoding:"Base64"}));b+=h}for(;f.nd();)a=f.next(),a=qy(e,a),c=d,b=a,"tt"===ny(b)&&(c.l=new zy(c.B,Object.assign({},b.attributes))),c=d,b=a,"tt"===ny(b)&&(c.w=new xy(b.attributes.frameRate,b.attributes.subFrameRate,b.attributes.frameRateMultiplier,b.attributes.tickRate)),c=d,b=a,ny(b)!==_.be||b.attributes.begin||b.attributes.end||(g=`#${b.getId()}`,c.h.set(g,new ty(g,b.h.textContent,b.attributes))),c=d,g=a,ny(g)===_.be&&g.attributes.begin&&g.attributes.end?(b=`#${iy()}`,
g=new ty(b,g.h.textContent,g.attributes),c.h.set(b,g),c=g):c=null,c&&(a.j=c.getId()),c=d,b=a,ny(b)===_.Pf&&(g=b.getId()||iy(),h=new By(g,b.f,Object.assign({},b.attributes)),c.a.set(g,h),b.a&&c.j.get(b.a).f.push(g)),c=d,g=a,ny(g)!==_.Pf&&ky(g)?(b=iy(),g=new By(b,[],Object.assign({},g.attributes)),c.a.set(b,g),c=g):c=null,c&&a.f.push(c.getId()),c=d,g=a,ny(g)!==_.Cd||!g.attributes.extent&&!g.attributes.origin?c=null:(b=iy(),g=new yy(b,ly(c,g.f),Object.assign({},g.attributes)),c.j.set(b,g),c=g),c&&(a.a=
c.getId()),c=d,g=a,ny(g)!==Gx?c=null:(b=g.getId(),g=new yy(b,ly(c,g.f),Object.assign({},g.attributes)),c.j.set(b,g),c=g),c&&(a.a=c.getId()),c=d,g=a,b=g.l,-1===[_.da,"span","br"].indexOf(ny(g))||0===b.length?c=null:(h=b[b.length-1],c.f.has(h)?(b=iy(),g=new wy(b,g.h.nodeName===_.da?g.h.textContent:null,"br"===ny(g),g.a,g.j,ly(c,g.f),g.attributes),c.f.set(b,g),(c=c.f.get(h))&&c.j.push(b),c=g):c=null),c&&a.l.push(c.getId()),c=d,g=a,"p"===ny(g)||g.j?(b=iy(),g=new wy(b,null,!1,g.a,g.j,ly(c,g.f),g.attributes),
c.f.set(b,g),c.o.push(g),c=g):c=null,c&&a.l.push(c.getId());e=my(d);f=[];for(l of d.a.values())f.push(...l.build(d.l));var l=f;return{cues:e,styles:l}}};var Iy=class{constructor(a){this.f=a}a(a){var b=new Hy(this.f);({cues:a}=b.parseMedia(a,{periodStart:0,segmentStart:null,segmentEnd:0}));b="WEBVTT\n\n";for(const d of a){a=b;b=ry(d.startTime)+" --\x3e "+ry(d.endTime);{var c=d;const e=[];switch(c.textAlign){case _.ee:e.push("align:left");break;case _.wf:e.push("align:right");break;case _.Qt:e.push("align:middle");break;case _.Jf:e.push("align:start");break;case _.Rd:e.push("align:end")}switch(c.writingMode){case _.mg:e.push("vertical:lr");break;case _.ng:e.push("vertical:rl")}c=
e.length?" "+e.join(" "):""}b=a+(b+c+"\n");b+=d.payload+"\n\n"}return _.Yi(b)}},Jy=class{probe(a,b){return a===_.xc&&b===_.Sf}create(a){return new Iy(a)}};var Ky=class{constructor(a){this.a=new Hy(a);this.g=new _.S("clpp.ttml.Mp4TtmlParser")}parseInit(a){let b=!1;(new _.om).N(_.ye,_.hm).N(_.ag,_.hm).N(_.qe,_.hm).N(_.xe,_.hm).N(_.Mf,_.hm).ea(_.Of,_.im).N("stpp",c=>{b=!0;c.parser.stop()}).parse(a);if(!b)throw new _.I(_.G,2,2007);}parseMedia(a,b){let c=!1,d=[],e=[];const f=[];(new _.om).N("moof",_.hm).N("traf",_.hm).ea("subs",g=>{const h=_.P(g.reader);for(let k=0;k<h;++k){g.reader.skip(4);const l=_.am(g.reader);for(let m=0;m<l;++m){const n=1===g.version?
_.P(g.reader):_.am(g.reader);f.push(n);g.reader.skip(6)}}}).N(_.pe,_.jm(g=>{c=!0;g=this.a.parseMedia(g,b,f);d=d.concat(g.cues);e=e.concat(g.styles)})).parse(a);c||this.g.warn("Couldn't find the mdat box");return{cues:d,styles:e}}};_.z("clpp.ttml.TtmlComponent",class extends _.Av{constructor(){super();this.j=new Jy}f(){_.yt(_.xc,Hy);_.yt(_.vc,Ky);_.yt(Ax,Ky);_.yt(Cx,Ky);_.yt(Bx,Ky);_.ck.push(this.j)}a(){_.At(_.xc);_.At(_.vc);_.At(Ax);_.At(Cx);_.At(Bx);_.ek(this.j)}id(){return"subtitles-ttml"}});};f.call(g, window);