require(["css!modules/webvtt/vtt.css"]);let MaxVerticalLinePositionPercent=100;function ParsingError(errorData,message){this.name="ParsingError",this.code=errorData.code,this.message=message||errorData.message}function parseTimeStamp(input){function computeSeconds(h,m,s,f){return 3600*(0|h)+60*(0|m)+(0|s)+(0|f)/1e3}input=input.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);return input?input[3]?computeSeconds(input[1],input[2],input[3].replace(":",""),input[4]):59{let settings=new Settings;parseOptions(input,function(k,v){switch(k){case"region":for(let i=regionList.length-1;0<=i;i--)if(regionList[i].id===v){settings.set(k,regionList[i].region);break}break;case"vertical":settings.alt(k,v,["rl","lr"]);break;case"line":var vals=v.split(","),vals0=vals[0];settings.integer(k,vals0),settings.percent(k,vals0)&&settings.set("snapToLines",!1),settings.alt(k,vals0,["auto"]),2===vals.length&&settings.alt("lineAlign",vals[1],["start","center","end"]);break;case"position":{let vals=v.split(",");settings.percent(k,vals[0]),2===vals.length&&settings.alt("positionAlign",vals[1],["start","center","end"])}break;case"size":settings.percent(k,v);break;case"align":settings.alt(k,v,["start","center","end","left","right"])}},/:/,/\s/),cue.region=settings.get("region",null),cue.vertical=settings.get("vertical",""),cue.line=settings.get("line","auto"),cue.lineAlign=settings.get("lineAlign","start"),cue.snapToLines=settings.get("snapToLines",!0),cue.size=settings.get("size",100);try{cue.align=settings.get("align","center")}catch(e){cue.align=settings.get("align","middle")}cue.position=settings.get("position","auto"),cue.positionAlign=settings.get("positionAlign",{start:"start",left:"start",middle:"center",center:"center",end:"end",right:"end"},cue.align)})(input,cue)}ParsingError.prototype=Object.create(Error.prototype),(ParsingError.prototype.constructor=ParsingError).Errors={BadSignature:{code:0,message:"Malformed WebVTT signature."},BadTimeStamp:{code:1,message:"Malformed time stamp."}},Settings.prototype={set:function(k,v){this.get(k)||""===v||(this.values[k]=v)},get:function(k,dflt,defaultKey){return defaultKey?this.has(k)?this.values[k]:dflt[defaultKey]:this.has(k)?this.values[k]:dflt},has:function(k){return k in this.values},alt:function(k,v,a){for(let n=0;n","":"","":""," ":" "},TAG_NAME={c:"span",i:"i",b:"b",u:"u",ruby:"ruby",rt:"rt",v:"span",lang:"span"},TAG_ANNOTATION={v:"title",lang:"lang"},NEEDS_PARENT={rt:"ruby"};function parseContent(window,input){function unescape1(e){return ESCAPE[e]}var rootDiv=window.document.createElement("div");let current=rootDiv,t;for(var annotation,tagName,m,tagStack=[];null!==(m=void 0,t=input?(m=(m=input.match(/^([^<]*)(<[^>]*>?)?/))[1]||m[2],input=input.substr(m.length),m):null);)if("<"===t[0]){if("/"===t[1]){tagStack.length&&tagStack[tagStack.length-1]===t.substr(2).replace(">","")&&(tagStack.pop(),current=current.parentNode);continue}var ts=parseTimeStamp(t.substr(1,t.length-2));let node;if(ts){node=window.document.createProcessingInstruction("timestamp",ts),current.appendChild(node);continue}let m=t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/);if(!m)continue;if(!(node=(ts=m[1],annotation=m[3],tagName=void 0,(tagName=TAG_NAME[ts])?(tagName=window.document.createElement(tagName),(ts=TAG_ANNOTATION[ts])&&annotation&&(tagName[ts]=annotation.trim()),tagName):null)))continue;if(!((current,element)=>!NEEDS_PARENT[element.localName]||NEEDS_PARENT[element.localName]===current.localName)(current,node))continue;m[2]&&(node.className=m[2].substr(1).replace("."," ")),tagStack.push(m[1]),current.appendChild(node),current=node}else current.appendChild(window.document.createTextNode((s=>{for(var sMatch;sMatch=s.match(/&(amp|quot|lt|gt|lrm|rlm|nbsp);/);)s=s.replace(sMatch[0],unescape1);return s})(t)));return rootDiv}let strongRTLRanges=[[1470,1470],[1472,1472],[1475,1475],[1478,1478],[1488,1514],[1520,1524],[1544,1544],[1547,1547],[1549,1549],[1563,1563],[1566,1610],[1645,1647],[1649,1749],[1765,1766],[1774,1775],[1786,1805],[1807,1808],[1810,1839],[1869,1957],[1969,1969],[1984,2026],[2036,2037],[2042,2042],[2048,2069],[2074,2074],[2084,2084],[2088,2088],[2096,2110],[2112,2136],[2142,2142],[2208,2208],[2210,2220],[8207,8207],[64285,64285],[64287,64296],[64298,64310],[64312,64316],[64318,64318],[64320,64321],[64323,64324],[64326,64449],[64467,64829],[64848,64911],[64914,64967],[65008,65020],[65136,65140],[65142,65276],[67584,67589],[67592,67592],[67594,67637],[67639,67640],[67644,67644],[67647,67669],[67671,67679],[67840,67867],[67872,67897],[67903,67903],[67968,68023],[68030,68031],[68096,68096],[68112,68115],[68117,68119],[68121,68147],[68160,68167],[68176,68184],[68192,68223],[68352,68405],[68416,68437],[68440,68466],[68472,68479],[68608,68680],[126464,126467],[126469,126495],[126497,126498],[126500,126500],[126503,126503],[126505,126514],[126516,126519],[126521,126521],[126523,126523],[126530,126530],[126535,126535],[126537,126537],[126539,126539],[126541,126543],[126545,126546],[126548,126548],[126551,126551],[126553,126553],[126555,126555],[126557,126557],[126559,126559],[126561,126562],[126564,126564],[126567,126570],[126572,126578],[126580,126583],[126585,126588],[126590,126590],[126592,126601],[126603,126619],[126625,126627],[126629,126633],[126635,126651],[1114109,1114109]];function isStrongRTLChar(charCode){for(let i=0;i=currentRange[0]&&charCode<=currentRange[1])return!0}return!1}function pushNodes(nodeStack,node){for(let i=node.childNodes.length-1;0<=i;i--)nodeStack.push(node.childNodes[i])}function nextTextNode(nodeStack,options){if(!nodeStack||!nodeStack.length)return null;var node=nodeStack.pop(),text=node.textContent||node.innerText;if(text){if(!options.forceLTR)if(text.match(/(^| )[\?\!\.\,]/m))return options.forceLTR=!0,null;var m=text.match(/^.*(\n|\r)/);return m?m[nodeStack.length=0]:text}return"ruby"===node.tagName?nextTextNode(nodeStack,options):node.childNodes?(pushNodes(nodeStack,node),nextTextNode(nodeStack,options)):void 0}function determineBidi(cueDiv,options){var nodeStack=[],text="";if(cueDiv&&cueDiv.childNodes&&!options.forceLTR)for(pushNodes(nodeStack,cueDiv);text=nextTextNode(nodeStack,options);)for(let i=0;imaxPosition&&(position=position<0?-1:1,position*=Math.ceil(maxPosition/step)*step),linePos<0&&(position+=cue.vertical?containerBox.width:Math.floor(containerBox.height*(MaxVerticalLinePositionPercent/100)),axis=axis.reverse()),boxPosition.move(initialAxis,position)}else{var calculatedPercentage=boxPosition.lineHeight/containerBox.height*100;switch(cue.lineAlign){case"center":linePos-=calculatedPercentage/2;break;case"end":relativeToEnd=!0,linePos-=calculatedPercentage,linePos=Math.max(linePos,MaxVerticalLinePositionPercent)}switch(cue.vertical||""){case"":styleBox.applyStyles({top:styleBox.formatStyle(linePos,"%")});break;case"rl":styleBox.applyStyles({left:styleBox.formatStyle(linePos,"%")});break;case"lr":styleBox.applyStyles({right:styleBox.formatStyle(linePos,"%")})}axis=["+y","-x","+x","-y"],boxPosition=new BoxPosition(styleBox)}maxPosition=((b,axis)=>{let bestPosition;var specifiedPosition=new BoxPosition(b);let percentage=1;for(let i=0;ip&&(bestPosition=new BoxPosition(b),percentage=p),b=new BoxPosition(specifiedPosition)}return bestPosition||specifiedPosition})(boxPosition,axis),step={top:maxPosition.top-containerBox.top,bottom:containerBox.bottom-maxPosition.bottom,left:maxPosition.left-containerBox.left,right:containerBox.right-maxPosition.right};""===(cue.vertical||"")?relativeToEnd?styleBox.applyStyles({bottom:styleBox.formatStyle(step.bottom,"px")}):styleBox.applyStyles({top:styleBox.formatStyle(step.top,"px")}):relativeToEnd?styleBox.applyStyles({right:styleBox.formatStyle(step.right,"px")}):styleBox.applyStyles({left:styleBox.formatStyle(step.left,"px")})}function WebVTT(){}CueStyleBox.prototype=Object.create(StyleBox.prototype),CueStyleBox.prototype.constructor=CueStyleBox,BoxPosition.prototype.move=function(axis,toMove){switch(toMove=void 0!==toMove?toMove:this.lineHeight,axis){case"+x":this.left+=toMove,this.right+=toMove;break;case"-x":this.left-=toMove,this.right-=toMove;break;case"+y":this.top+=toMove,this.bottom+=toMove;break;case"-y":this.top-=toMove,this.bottom-=toMove}},BoxPosition.prototype.overlaps=function(b2){return this.leftb2.left&&this.topb2.top},BoxPosition.prototype.overlapsAny=function(boxes){for(let i=0;i=container.top&&this.bottom<=container.bottom&&this.left>=container.left&&this.right<=container.right},BoxPosition.prototype.overlapsOppositeAxis=function(container,axis){switch(axis){case"+x":return this.leftcontainer.right;case"+y":return this.topcontainer.bottom}},BoxPosition.prototype.intersectPercentage=function(b2){return Math.max(0,Math.min(this.right,b2.right)-Math.max(this.left,b2.left))*Math.max(0,Math.min(this.bottom,b2.bottom)-Math.max(this.top,b2.top))/(this.height*this.width)},BoxPosition.getSimpleBoxPosition=function(obj){var height=obj.div?obj.div.offsetHeight:obj.tagName?obj.offsetHeight:0,width=obj.div?obj.div.offsetWidth:obj.tagName?obj.offsetWidth:0,top=obj.div?obj.div.offsetTop:obj.tagName?obj.offsetTop:0;return{left:(obj=obj.div?obj.div.getBoundingClientRect():obj.tagName?obj.getBoundingClientRect():obj).left,right:obj.right,top:obj.top||top,height:obj.height||height,bottom:obj.bottom||top+(obj.height||height),width:obj.width||width}},WebVTT.StringDecoder=function(){return{decode:function(data){if(!data)return"";if("string"!=typeof data)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(data))}}},WebVTT.convertCueToDOMTree=function(window,cuetext){return window&&cuetext?parseContent(window,cuetext):null},WebVTT.processCues=function(window,cues,overlay,options){if(!window||!cues||!overlay)return null;for(;overlay.firstChild;)overlay.removeChild(overlay.firstChild);if((cues=>{for(let i=0;i