(function(){var g={}; var _ = _ || {}
var f=function(window){var iU="CLPP Subtitle Styles",jU="Unsupported unit",kU="clpp-text-plain",lU="clpp-text-ttml",mU="clpp.htmlcue.HtmlTextDisplayer",nU="initial",oU=function(a){return _.Ki(a,{Ih:function(b,c){return b.pa(c)}})},pU=function(a,b){if(0===b.length)return a;var c=a,d=a.findIndex(function(e){return e.startTime>=b[0].startTime});0<=d&&(c=c.slice(0,d));return c.concat(b)},qU=function(a,b){for(var c=0,d=a.length-1;c<=d;){var e=c+d>>1,f=b(a[e]);if(0===f)return e;0<f?c=e+1:d=e-1}return-1},rU=function(){},sU=function(a){if(!a.input)return null;
var b=a.input.match(/^([^<]*)(<[^>]+>?)?/);b=b[1]?b[1]:b[2];a.input=a.input.substr(b.length);return b},uU=function(a){for(var b=null;b=a.match(/&(amp|lt|gt|lrm|rlm|nbsp);/);)a=a.replace(b[0],function(c){return tU[c]});return a},wU=function(a,b){vU(a,b);Array.from(b.getElementsByTagName("*")).forEach(function(c){vU(a,c)})},vU=function(a,b){for(var c in a)null!=a[c]&&(b.style[c]=a[c])},xU=function(a,b){return 0===a?"0":a+b},yU=function(a,b){return 1>Math.abs(a-b)||a<b},zU=function(a,b){return a<b&&
1<Math.abs(a-b)},AU=function(a,b){return a>b&&1<Math.abs(a-b)},BU=function(a,b){return 1>Math.abs(a-b)||a>b},CU=function(a,b,c,d,e,f){this.left=a;this.f=b;this.top=c;this.a=d;this.height=e;this.width=f},DU=function(a){return new CU(a.left,a.f,a.top,a.a,a.height,a.width)},EU=function(a){var b=a.getBoundingClientRect(),c=getComputedStyle(a,null),d=parseFloat(c.getPropertyValue("border-left-width"))||0,e=parseFloat(c.getPropertyValue("border-right-width"))||0,f=parseFloat(c.getPropertyValue("border-top-width"))||
0;c=parseFloat(c.getPropertyValue("border-bottom-width"))||0;var g=(b.top||a.offsetTop)+f;f=(b.height||a.offsetHeight)-f-c;return new CU(b.left+d,b.right+e,g,(b.bottom||g+f)+c,f,(b.width||a.offsetWidth)-d-e)},FU=function(a,b){return b.some(function(c){return zU(a.left,c.f)&&AU(a.f,c.left)&&zU(a.top,c.a)&&AU(a.a,c.top)})},GU=function(a,b){return BU(a.top,b.top)&&yU(a.a,b.a)&&BU(a.left,b.left)&&yU(a.f,b.f)},HU=function(a,b,c){switch(c){case "+x":return zU(a.left,b.left);case "-x":return AU(a.f,b.f);
case "+y":return zU(a.top,b.top);case "-y":return AU(a.a,b.a);default:throw Error("Unknown axis");}},IU=function(a,b,c){this.id=a;this.w=b;this.B=c;this.a=this.o();this.j=!1},JU=function(a,b,c){IU.call(this,a.id,"clpp-text-cue",{});this.l=b;this.f=a;this.h=!!this.f.backgroundImage;this.C=c},LU=function(a){var b=a.a.childNodes[0],c=a.a.getBoundingClientRect(),d=b.getClientRects();b=c.height/d.length;c=c.width/d.length;return KU(a)?b:c},OU=function(a,b,c){return KU(a)&&_.L.wa(c)?xU(c,_.Hf):(MU(a)||
NU(a))&&_.L.wa(b)?xU(b,"%"):nU},MU=function(a){return a.f.writingMode===_.Gg},NU=function(a){return a.f.writingMode===_.Hg},KU=function(a){return a.f.writingMode===_.Oi},PU=function(a,b,c){return(MU(a)||NU(a))&&_.L.wa(c)?xU(c,_.Hf):MU(a)&&_.L.R(c)?xU(0,_.Hf):KU(a)&&_.L.wa(b)?xU(b,"%"):nU},QU=function(a,b){if(typeof a.f.position===_.k&&typeof a.f.size===_.k)switch(b){case _.ye:return a.f.position;case "auto":case _.id:return a.f.position-a.f.size/2;case _.ze:return a.f.position-a.f.size}return 0},
RU=function(a){switch(a.f.positionAlign){case _.ye:return _.ve;case "auto":case _.id:return _.Ni;case _.ze:return _.Of}return a.f.textAlign},SU=function(a){if(!a.f.positionAlign)switch(a.f.textAlign){case _.ag:case _.ve:return _.ye;case _.Ni:return _.id;case _.ge:case _.Of:return _.ze}return a.f.positionAlign},TU=function(a){switch(a.f.writingMode){case _.Oi:return"horizontal-tb";case _.Gg:return _.Gg;case _.Hg:return _.Hg;default:throw Error("Unknown writing mode");}},UU=function(a,b){this.l=a;this.f=
a.a;this.j=void 0===b?!1:b;this.a=EU(a.a);this.h=[]},VU=function(a,b){if(a.j)switch(b.writingMode){case _.Oi:return["-y"];case _.Gg:return["+x"];case _.Hg:return["-x"]}var c=[];switch(b.writingMode){case _.Oi:c=["+y","-y"];break;case _.Gg:c=["+x","-x"];break;case _.Hg:c=["-x","+x"]}0>b.line&&(c=c.reverse());return c},WU=function(a){for(a.h=[];0<a.f.childNodes.length;)a.f.removeChild(a.f.childNodes[0]);a.a=EU(a.l.a)},XU=function(a,b,c){IU.call(this,a,b,c);this.h=null;this.l=[]},YU=function(a,b){XU.call(this,
a.id,"clpp-text-cue-region",b);this.f=a},ZU=function(a,b,c){a=a.f;var d=a.viewportAnchorUnits;if(d===_.Ti)return a.viewportAnchorY/100*c-a.regionAnchorY/100*b;if(0===d)return a.viewportAnchorY-a.regionAnchorY;throw Error(jU);},aV=function(a){this.g=new _.J("clpp.htmlcue.StyleManager");this.j=[];this.h=a;this.l=[];this.a=$U(this,this.h);this.f=$U(this,this.h,!0);this.f.disabled=!0;this.g.debug("Stylesheet CLPP Subtitle Styles has been created.")},bV=function(a,b){var c=!1;try{a.f.insertRule(b,0);var d=
a.f.cssRules[0];d instanceof CSSStyleRule&&(c=d.selectorText.split(",").every(function(e){return 0===e.trim().indexOf("."+a.h+" ")}))}catch(e){}0<a.f.cssRules.length&&a.f.deleteRule(0);return c},cV=function(a,b){var c="."+a.h+" .clpp-text-container",d=c+" .clpp-text-cue";return b=b.replace(/::cue\((#[^)]+)\)/g,c+" $1").replace(/::cue\(([^)]+)\)/g,d+" $1").replace(/::cue-region\(([^)]+)\)/g,c+" $1 .clpp-text-cue").replace(/::cue/g,d).replace(/::cue-region/g,c+" .clpp-text-cue-region .clpp-text-cue").replace(/::ttml/g,
c)},$U=function(a,b,c){var d=document.createElement(_.gg),e=d.dataset;e.name=iU;e["for"]=b;c&&(e.name="CLPP Subtitle Styles (sandbox)",e.sandbox=!0);b=document.head;b.appendChild(d);dV(a,b);a.g.debug("Created HTML style element #CLPP Subtitle Styles.");return d.sheet},dV=function(a,b){var c=new MutationObserver(function(d){d.forEach(function(e){e.removedNodes.forEach(function(f){f.id===iU&&a.g.error("PRESTOplay HTML style element #CLPP Subtitle Styles has been unexpectedly removed! Some styles will not work!")})})});
c.observe(b,{subtree:!1,childList:!0});a.j.push(function(){return c.disconnect()})},gV=function(a){_.Dv.call(this,a);var b=this;this.g=new _.J(mU);this.m=a;this.L=eV(a.getConfiguration());this.j=!1;this.f=[];this.C=a.getSurface().getContainer();this.h=new aV(a.getSurface().getUniqueCssClass());this.a=new XU(null,"clpp-text-container",{});this.w=new _.Vu(a.getSurface(),this.Ak.bind(this));this.J=null;this.C?(this.C.appendChild(this.a.a),this.a.init(null)):this.g.warn("No container element! Subtitles will not appear. Please check your player surface configuration or switch to NativeTextDisplayer.");
this.G=new _.Xh(function(){fV(b)});this.A=new Map;this.l=null},eV=function(a){a=_.L.kb(a.htmlcue||{});_.L.R(a.stretchSmpteImage)&&(a.stretchSmpteImage=!1);_.L.R(a.enableResizeObserver)&&(a.enableResizeObserver=!0);return a},hV=function(a,b){return a.startTime<=b&&a.endTime>b},fV=function(a,b){if((b||a.j)&&a.C){var c=a.m.getPosition();if(b||a.J!==c&&a.m.getState()===_.Hq){a.J=c;var d=iV(a,c);(c=b)||(c=a.l,c=!(null===c&&null===d||null!==c&&null!==d&&c.start===d.start&&c.end===d.end));if(c&&(a.l=d,jV(a),
d)){c={color:a.getFontColor()||void 0,backgroundColor:a.getBackgroundColor()||void 0,fontFamily:a.getFontFamily()||void 0,textShadow:_.Xv(a)||void 0};d=a.f.slice(d.start,d.end+1);d=_.u(d);for(var e=d.next();!e.done;e=d.next()){var f=a;e=e.value;var g=f.a.a,h=null;switch(e.payloadType){case _.Qg:h="clpp-text-vtt";break;case _.ug:h=lU;break;case _.Mi:h=kU}h&&!g.classList.contains(h)&&_.fr(g,h);g=EU(f.a.a);if(0===g.width||0===g.height)f.g.warn("The height or width of the `.clpp-text-container` element is zero. Captions will not be displayed. Please check if the `clpp.styles.css` file has been included.");
else{vU({fontSize:kV(f,e.containerRows)},f.a.a);g=null;h=e.payloadType===_.Qg;var l=e.payloadType===_.ug;e.region&&(h||l||e.backgroundImage)&&(f.A.has(e.region.id)?g=f.A.get(e.region.id):(g=new YU(e.region,{}),f.A.set(e.region.id,g),f.a.appendChild(g)));e=new JU(e,f.L,c);g?g.appendChild(e):f.a.appendChild(e)}}}}}},iV=function(a,b){var c=qU(a.f,function(e){return hV(e,b)?0:b!==e.startTime?b-e.startTime:b-e.endTime});if(-1===c)return null;for(var d=c;0<=d-1&&hV(a.f[d-1],b);)d--;for(;c+1<a.f.length&&
hV(a.f[c+1],b);)c++;return{start:d,end:c}},lV=function(a){jV(a);a.J=null;a.l=null;a.f=[]},jV=function(a){a.A.clear();if(a.a){var b=a.a.a;b.classList.remove("clpp-text-vtt");b.classList.remove(lU);b.classList.remove(kU);a=a.a;WU(a.h);a.l=[]}},kV=function(a,b){var c=EU(a.a.a).height;if(null!==a.I)return a.getFontSize();if(null!==a.B){var d=a.getFontSizePercent();return Math.round(c*d)+_.Hf}if(typeof b===_.k&&0<b)return Math.round(c/b)+_.Hf;d=a.getFontSizePercent();return Math.round(c*d)+_.Hf},mV=function(){},
nV=function(){};
rU.prototype.parse=function(a){a={input:a};for(var b=_.hr(_.Qd),c=[],d=b,e;null!==(e=sU(a));)if("\x3c"===e[0])if("/"===e[1])c.length&&c[c.length-1]===e.substr(2).replace("\x3e","")&&(c.pop(),d=d.parentNode);else{if(e=e.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/)){var f=e[1];var g=e[3];var h=oV[f];h?(h=_.hr(h),(f=pV[f])&&g&&h.setAttribute(f,g.trim()),g=h):g=null;!g||qV[g.localName]&&qV[g.localName]!==d.localName||(e[2]&&(g.className=e[2].substr(1).replace(/\./g," ")),c.push(e[1]),d.appendChild(g),
d=g)}}else d.appendChild(document.createTextNode(uU(e)));return b};var oV={c:"c",i:"i",b:"b",u:"u",ruby:"ruby",rt:"rt",v:"v",lang:"lang"},pV={v:"voice",lang:"lang"},qV={rt:"ruby"},tU={"\x26amp;":"\x26","\x26lt;":"\x3c","\x26gt;":"\x3e","\x26lrm;":"\u200e","\x26rlm;":"\u200f","\x26nbsp;":"\u00a0"};IU.prototype.init=function(){this.j=!0};IU.prototype.A=function(){return!1};_.w(JU,IU);JU.prototype.A=function(){return!this.h&&!(this.f.region&&this.f.region.displayAlign)};
JU.prototype.init=function(a){IU.prototype.init.call(this,a);if(this.h)_.fr(this.a,"clpp-text-cue-image"),this.a.style.backgroundImage='url("'+this.f.backgroundImage+'")',this.l.stretchSmpteImage&&(this.a.style.backgroundSize="contain");else if(a){var b=this.f;if(b.payloadType===_.ug){var c=_.hr(_.Qd);c.innerHTML=b.payload;b=c}else b.payloadType===_.Qg?b=(new rU).parse(b.payload):(c=_.hr(_.Qd),c.textContent=b.payload,b=c);_.fr(b,this.w);this.id&&(b.id=this.id);c=_.u(this.f.cssClassList);for(var d=
c.next();!d.done;d=c.next())_.fr(b,d.value);vU({writingMode:TU(this)},b);this.a.appendChild(b);_.fr(this.a,"clpp-text-wrapper");c=_.u(this.f.cssClassList);for(d=c.next();!d.done;d=c.next())_.fr(this.a,"clpp-text-wrapper__"+d.value);_.L.R(this.f.line)&&(this.f.lineInterpretation=_.Pi,this.f.line=KU(this)?-1:0);c=TU(this);vU({writingMode:c,webkitWritingMode:c,direction:nU,textAlign:RU(this)},this.a);if(!this.f.region||!this.f.region.displayAlign){c=QU(this,SU(this));d=PU(this,c,null);var e=OU(this,
c,null),f=NU(this)&&_.L.R(null)?xU(0,_.Hf):nU;vU({position:"absolute",left:d,right:f,top:e,width:KU(this)?xU(this.f.size,"%"):nU,height:MU(this)||NU(this)?xU(this.f.size,"%"):nU},this.a);d=this.f;a=KU(this)?a.height:a.width;e=LU(this);if(d.lineInterpretation===_.Pi)f=e*Math.round(d.line),Math.abs(f)>a&&(f=e*(0>d.line?0:-1)),0>f&&(f+=a);else{f=e/a*100;var g=d.line;switch(d.lineAlign){case _.id:g-=f/2;break;case _.ge:g-=f}f=Math.round(g/100*a)}NU(this)&&(f=a-f-e);a=f;d=PU(this,c,a);e=NU(this)&&_.L.R(a)?
xU(0,_.Hf):nU;vU({left:d,right:e,top:OU(this,c,a)},this.a)}wU(this.C,b)}};JU.prototype.o=function(){return _.hr(_.Qd)};UU.prototype.append=function(a){var b=a.a;b.style.visibility=_.qe;this.f.appendChild(b);a.j||a.init(this.a);if(a.A()){a:{var c=EU(a.a);var d=VU(this,a.f),e=LU(a),f=DU(c),g=null,h=0;d=_.u(d);for(var l=d.next();!l.done;l=d.next()){for(l=l.value;HU(c,this.a,l)||GU(c,this.a)&&FU(c,this.h);){var m=c,n=e;switch(l){case "+x":m.left+=n;m.f+=n;break;case "-x":m.left-=n;m.f-=n;break;case "+y":m.top+=n;m.a+=n;break;case "-y":m.top-=n,m.a-=n}}if(this.j||GU(c,this.a))break a;l=this.a;l=Math.max(0,Math.min(c.f,
l.f)-Math.max(c.left,l.left))*Math.max(0,Math.min(c.a,l.a)-Math.max(c.top,l.top))/(c.height*c.width);l>h&&(g=DU(c),h=l);c=DU(f)}c=g||f}vU({top:xU(c.top-this.a.top,_.Hf),bottom:xU(this.a.a-c.a,_.Hf),left:xU(c.left-this.a.left,_.Hf),right:xU(this.a.f-c.f,_.Hf),height:xU(c.height,_.Hf),width:xU(c.width,_.Hf)},a.a)}b.style.visibility="visible";this.h.push(EU(a.a))};_.w(XU,IU);XU.prototype.init=function(){this.h=new UU(this);this.j=!0};XU.prototype.o=function(){var a=_.hr(_.Qd);_.fr(a,this.w);this.id&&(a.id=this.id);return a};XU.prototype.appendChild=function(a){WU(this.h);this.l.unshift(a);a=_.u(this.l);for(var b=a.next();!b.done;b=a.next())this.h.append(b.value)};_.w(YU,XU);
YU.prototype.init=function(a){a:{var b=this.f;switch(b.widthUnits){case 0:b=b.width;break a;case _.Ti:b=b.width/100*a.width;break a;default:throw Error(jU);}}var c=this.f;var d=c.viewportAnchorUnits;if(d===_.Ti)c=c.viewportAnchorX/100*a.width-c.regionAnchorX/100*b;else if(0===d)c=c.viewportAnchorX-c.regionAnchorX;else throw Error(jU);d=a.height;var e=ZU(this,d,a.height);vU(this.B,this.a);vU({left:xU(c,_.Hf),top:xU(e,_.Hf),width:xU(b,_.Hf),height:xU(d,_.Hf)},this.a);this.f.writingMode&&vU({display:"flex",
"flex-direction":this.f.writingMode},this.a);this.f.displayAlign&&vU({"justify-content":this.f.displayAlign},this.a);b=_.u(this.f.cssClassList);for(c=b.next();!c.done;c=b.next())_.fr(this.a,c.value);a:switch(b=this.f,b.heightUnits){case 0:b=b.height;break a;case _.Ti:b=b.height/100*a.height;break a;case 2:b=b.height;d=new JU(new _.Si(0,1,"Lorem ipsum",_.Mi),{},{});c=d.a;this.a.appendChild(c);d.init(EU(this.a));d=c.getBoundingClientRect().height;this.a.removeChild(c);b*=d;break a;default:throw Error(jU);
}a=ZU(this,b,a.height);vU({top:xU(a,_.Hf),height:xU(b,_.Hf)},this.a);this.h=new UU(this,!0);this.j=!0};YU.prototype.getId=function(){return this.f.id};aV.prototype.appendRule=function(a){if(null!=this.a&&!this.l.some(function(c){return c===a})){var b=cV(this,a);if(bV(this,b)){try{this.a.insertRule(b,this.a.cssRules.length),this.g.debug("Added CSS rule "+b)}catch(c){this.g.error("An error occurred when adding a CSS rule: "+b)}this.l.push(a)}else this.g.warn("Stylesheet CLPP Subtitle Styles ignoring the CSS rule because it's not safe: "+b)}};
aV.prototype.destroy=function(){var a=this;return _.H(function(b){if(null==a.a)return b["return"]();a.j.forEach(function(c){return c()});a.j=[];if(null!=a.a){for(;0<a.a.cssRules.length;)a.a.deleteRule(0);a.l=[]}document.head.removeChild(a.a.ownerNode);document.head.removeChild(a.f.ownerNode);a.a=null;a.f=null;a.g.debug("Stylesheet CLPP Subtitle Styles has been destroyed.");_.y(b)})};_.w(gV,_.Dv);_.r=gV.prototype;_.r.append=function(a,b){if(null!=this.h&&0!==a.length){for(var c=_.u(b),d=c.next();!d.done;d=c.next())this.h.appendRule(d.value);a.sort(function(e,f){return e.startTime!==f.startTime?e.startTime-f.startTime:e.endTime-f.endTime});this.f=pU(this.f,oU(a));this.l=null;fV(this,!1)}};_.r.Wb=function(){null==this.h||fV(this,!0)};
_.r.destroy=function(){var a=this;return _.H(function(b){if(1==b.a){if(null==a.h)return b["return"]();lV(a);a.G.stop();return _.x(b,a.h.destroy(),2)}a.h=null;a.C.removeChild(a.a.a);a.a=null;a.w.stop();a.w=null;a.j=!1;_.y(b)})};_.r.remove=function(a,b){if(null==this.h)return!1;this.f=this.f.filter(function(c){return c.startTime<a||c.endTime>=b});this.l=null;fV(this,!0);return!0};_.r.isTextVisible=function(){return this.j};
_.r.setTextVisibility=function(a){null!=this.h&&this.j!==a&&((this.j=a)?(this.G.Jb(.25),this.L.enableResizeObserver&&this.w.start(),fV(this,!0)):(this.G.stop(),this.w.stop(),lV(this)))};_.r.Ak=function(){fV(this,!0)};_.I(mU,gV);gV.prototype.setTextVisibility=gV.prototype.setTextVisibility;gV.prototype.isTextVisible=gV.prototype.isTextVisible;gV.prototype.remove=gV.prototype.remove;gV.prototype.destroy=gV.prototype.destroy;gV.prototype.append=gV.prototype.append;mV.prototype.a=function(a){return!!a.enableHtmlCue&&!_.zl()};mV.prototype.create=function(a){return new gV(a)};_.w(nV,_.Bu);nV.prototype.f=function(){_.jq(_.re,new mV)};nV.prototype.a=function(){_.hq.has(_.re)&&(_.hq["delete"](_.re),_.iq.info("Removed factory: 'html'"))};nV.prototype.id=function(){return _.ig};_.I("clpp.htmlcue.HtmlCueComponent",nV);};
if(typeof(module)!="undefined"&&module.exports){var x=require("./cl.core.js");_ = x._;(f.call(g,this));module.exports=g;}
else if (typeof(define)!="undefined"&&define.amd) {define(["./cl.core"], function(c){_=c._;(f.call(g,this));return g;});}
else{_=this.clpp._;(f.call(g,this));}
})();