imsc
Version:
Renders IMSC documents to HTML5 fragments
4 lines • 53.9 kB
JavaScript
/*! DEPRECATED: this bundle is subject to removal in a future release; use imsc.debug.js or imsc.min.js instead. */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).imsc={})}(this,function(t){"use strict";var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}function i(t,e){if(t&&t.warn&&t.warn(e))throw e}function r(t,e){if(t&&t.error&&t.error(e))throw e}function l(t,e){throw t&&t.fatal&&t.fatal(e),e}"function"==typeof SuppressedError&&SuppressedError;var o="http://www.w3.org/ns/ttml",s="http://www.w3.org/ns/ttml#styling",a="http://www.w3.org/ns/ttml#parameter",u="http://www.w3.org/ns/ttml/profile/imsc1#styling",f="http://www.w3.org/ns/ttml/profile/imsc1#parameter",h="urn:ebu:tt:style",c=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?/,d=/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/,p=/rgba\(\s*(\d+),\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/,g={transparent:[0,0,0,0],black:[0,0,0,255],silver:[192,192,192,255],gray:[128,128,128,255],white:[255,255,255,255],maroon:[128,0,0,255],red:[255,0,0,255],purple:[128,0,128,255],fuchsia:[255,0,255,255],magenta:[255,0,255,255],green:[0,128,0,255],lime:[0,255,0,255],olive:[128,128,0,255],yellow:[255,255,0,255],navy:[0,0,128,255],blue:[0,0,255,255],teal:[0,128,128,255],aqua:[0,255,255,255],cyan:[0,255,255,255]};function m(t){var e,n=null,i=g[t.toLowerCase()];return void 0!==i?n=i:null!==(e=c.exec(t))?n=[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16),void 0!==e[4]?parseInt(e[4],16):255]:null!==(e=d.exec(t))?n=[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),255]:null!==(e=p.exec(t))&&(n=[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),parseInt(e[4])]),n}var y=/^((?:\+|-)?\d*(?:\.\d+)?)(px|em|c|%|rh|rw)$/;function v(t){var e,n=null;return null!==(e=y.exec(t))&&(n={value:parseFloat(e[1]),unit:e[2]}),n}var w=function(){function t(t,e){this.rw=t,this.rh=e}return t.prototype.toUsedLength=function(t,e){return t*this.rw+e*this.rh},t.prototype.isZero=function(){return 0===this.rw&&0===this.rh},t}();function b(t,e,n,i,r,l){return"%"===e&&i?new w(i.rw*t/100,i.rh*t/100):"em"===e&&n?new w(n.rw*t,n.rh*t):"c"===e&&r?new w(t*r.rw,t*r.rh):"px"===e&&l?new w(t*l.rw,t*l.rh):"rh"===e?new w(0,t/100):"rw"===e?new w(t/100,0):null}function x(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var q=function(t,e,n,i,r,l,o,s){this.name=e,this.ns=t,this.qname=t+" "+e,this.inherit=r,this.animatable=l,this.initial=n,this.applies=i,this.parse=o,this.compute=s},A=[new q(s,"backgroundColor","transparent",["body","div","p","region","span"],!1,!0,m,null),new q(s,"color","white",["span"],!0,!0,m,null),new q(s,"direction","ltr",["p","span"],!0,!0,function(t){return t},null),new q(s,"display","auto",["body","div","p","region","span"],!1,!0,function(t){return t},null),new q(s,"displayAlign","before",["region"],!1,!0,function(t){return t},null),new q(s,"extent","auto",["tt","region"],!1,!0,function(t){if("auto"===t)return t;var e=t.split(" ");if(2!==e.length)return null;var n=v(e[0]),i=v(e[1]);return i&&n?{h:i,w:n}:null},function(t,e,n,i){var r,l;if("auto"===i)r=new w(0,1);else if(null===(r=b(i.h.value,i.h.unit,null,t.dimensions.h,null,t.pxLength.h)))return null;if("auto"===i)l=new w(1,0);else if(null===(l=b(i.w.value,i.w.unit,null,t.dimensions.w,null,t.pxLength.w)))return null;return{h:r,w:l}}),new q(s,"fontFamily","default",["span","p"],!0,!0,function(t){for(var e=t.split(","),n=[],i=0;i<e.length;i++)e[i]=e[i].trim(),"'"!==e[i].charAt(0)&&'"'!==e[i].charAt(0)&&"default"===e[i]?n.push("monospaceSerif"):n.push(e[i]);return n},null),new q(s,"shear","0%",["p"],!0,!0,v,function(t,e,n,i){return"%"!==i.unit?null:Math.abs(i.value)>100?100*Math.sign(i.value):i.value}),new q(s,"fontSize","1c",["span","p"],!0,!0,v,function(t,e,n,i){return b(i.value,i.unit,null!==e?e.styleAttrs[F.fontSize.qname]:t.cellLength.h,null!==e?e.styleAttrs[F.fontSize.qname]:t.cellLength.h,t.cellLength.h,t.pxLength.h)}),new q(s,"fontStyle","normal",["span","p"],!0,!0,function(t){return t},null),new q(s,"fontVariant","normal",["span"],!0,!0,function(t){return"normal"===t||"sub"===t||"super"===t?t:null},null),new q(s,"fontWeight","normal",["span","p"],!0,!0,function(t){return t},null),new q(s,"lineHeight","normal",["p"],!0,!0,function(t){return"normal"===t?t:v(t)},function(t,e,n,i){var r;if("normal"===i)r=i;else if(null===(r=b(i.value,i.unit,n.styleAttrs[F.fontSize.qname],n.styleAttrs[F.fontSize.qname],t.cellLength.h,t.pxLength.h)))return null;return r}),new q(s,"opacity",1,["region"],!1,!0,parseFloat,null),new q(s,"origin","auto",["region"],!1,!0,function(t){if("auto"===t)return t;var e=t.split(" ");if(2!==e.length)return null;var n=v(e[0]),i=v(e[1]);return i&&n?{h:i,w:n}:null},function(t,e,n,i){var r,l;if("auto"===i)r=new w(0,0);else if(null===(r=b(i.h.value,i.h.unit,null,t.dimensions.h,null,t.pxLength.h)))return null;if("auto"===i)l=new w(0,0);else if(null===(l=b(i.w.value,i.w.unit,null,t.dimensions.w,null,t.pxLength.w)))return null;return{h:r,w:l}}),new q(s,"overflow","hidden",["region"],!1,!0,function(t){return t},null),new q(s,"padding","0px",["region"],!1,!0,function(t){var e=t.split(" ");if(e.length>4)return null;for(var n=[],i=0;i<e.length;i++){var r=v(e[i]);if(!r)return null;n.push(r)}return n},function(t,e,n,i){var r;if(1===i.length)r=[i[0],i[0],i[0],i[0]];else if(2===i.length)r=[i[0],i[1],i[0],i[1]];else if(3===i.length)r=[i[0],i[1],i[2],i[1]];else{if(4!==i.length)return null;r=[i[0],i[1],i[2],i[3]]}var l=n.styleAttrs[F.writingMode.qname];if("lrtb"===l||"lr"===l)r=[r[0],r[3],r[2],r[1]];else if("rltb"===l||"rl"===l)r=[r[0],r[1],r[2],r[3]];else if("tblr"===l)r=[r[3],r[0],r[1],r[2]];else{if("tbrl"!==l&&"tb"!==l)return null;r=[r[3],r[2],r[1],r[0]]}for(var o=[],s=0;s<r.length;s++)if(0===r[s].value)o[s]=new w(0,0);else if(o[s]=b(r[s].value,r[s].unit,n.styleAttrs[F.fontSize.qname],0===s||2===s?n.styleAttrs[F.extent.qname].h:n.styleAttrs[F.extent.qname].w,0===s||2===s?t.cellLength.h:t.cellLength.w,0===s||2===s?t.pxLength.h:t.pxLength.w),null===o[s])return null;return o}),new q(s,"position","top left",["region"],!1,!0,function(t){return function(t){var e=t.split(" "),n=function(t){return"center"===t||"left"===t||"top"===t||"bottom"===t||"right"===t};if(e.length>4)return null;for(var i=0;i<e.length;i++)if(!n(e[i])){var r=v(e[i]);if(null===r)return null;e[i]=r}for(var l={h:{edge:"left",offset:{value:50,unit:"%"}},v:{edge:"top",offset:{value:50,unit:"%"}}},o=0;o<e.length;){var s=e[o++];if(n(s)){var a={value:0,unit:"%"};2!==e.length&&o<e.length&&!n(e[o])&&(a=e[o++]),"right"===s?(l.h.edge=s,l.h.offset=a):"bottom"===s?(l.v.edge=s,l.v.offset=a):"left"===s?l.h.offset=a:"top"===s&&(l.v.offset=a)}else{if(1!==e.length&&2!==e.length)return null;1===o?l.h.offset=s:l.v.offset=s}}return l}(t)},function(t,e,n,i){var r,l;return null===(r=b(i.v.offset.value,i.v.offset.unit,null,new w(-n.styleAttrs[F.extent.qname].h.rw,t.dimensions.h.rh-n.styleAttrs[F.extent.qname].h.rh),null,t.pxLength.h))?null:("bottom"===i.v.edge&&(r=new w(-r.rw-n.styleAttrs[F.extent.qname].h.rw,t.dimensions.h.rh-r.rh-n.styleAttrs[F.extent.qname].h.rh)),l=b(i.h.offset.value,i.h.offset.unit,null,new w(t.dimensions.w.rw-n.styleAttrs[F.extent.qname].w.rw,-n.styleAttrs[F.extent.qname].w.rh),null,t.pxLength.w),null===r?null:("right"===i.h.edge&&(l=new w(t.dimensions.w.rw-l.rw-n.styleAttrs[F.extent.qname].w.rw,-l.rh-n.styleAttrs[F.extent.qname].w.rh)),{h:r,w:l}))}),new q(s,"ruby","none",["span"],!1,!0,function(t){return t},null),new q(s,"rubyAlign","center",["span"],!0,!0,function(t){return"center"!==t&&"spaceAround"!==t?null:t},null),new q(s,"rubyPosition","outside",["span"],!0,!0,function(t){return t},null),new q(s,"rubyReserve","none",["p"],!0,!0,function(t){var e=t.split(" "),n=[null,null];if(0===e.length||e.length>2)return null;if("none"!==e[0]&&"both"!==e[0]&&"after"!==e[0]&&"before"!==e[0]&&"outside"!==e[0])return null;if(n[0]=e[0],2===e.length&&"none"!==e[0]){var i=v(e[1]);if(!i)return null;n[1]=i}return n},function(t,e,n,i){if("none"===i[0])return i;var r=null;return null===(r=null===i[1]?new w(.5*n.styleAttrs[F.fontSize.qname].rw,.5*n.styleAttrs[F.fontSize.qname].rh):b(i[1].value,i[1].unit,n.styleAttrs[F.fontSize.qname],n.styleAttrs[F.fontSize.qname],t.cellLength.h,t.pxLength.h))?null:[i[0],r]}),new q(s,"showBackground","always",["region"],!1,!0,function(t){return t},null),new q(s,"textAlign","start",["p"],!0,!0,function(t){return t},function(t,e,n,i){return"left"===i?"start":"right"===i?"end":i}),new q(s,"textCombine","none",["span"],!0,!0,function(t){return"none"===t||"all"===t?t:null},null),new q(s,"textDecoration","none",["span"],!0,!0,function(t){return t.split(" ")},null),new q(s,"textEmphasis","none",["span"],!0,!0,function(t){for(var e=t.split(" "),n={style:null,symbol:null,color:null,position:null},i=0;i<e.length;i++)if("none"===e[i]||"auto"===e[i])n.style=e[i];else if("filled"===e[i]||"open"===e[i])n.style=e[i];else if("circle"===e[i]||"dot"===e[i]||"sesame"===e[i])n.symbol=e[i];else if("current"===e[i])n.color=e[i];else if("outside"===e[i]||"before"===e[i]||"after"===e[i])n.position=e[i];else if(n.color=m(e[i]),null===n.color)return null;return null==n.style&&null==n.symbol?n.style="auto":(n.symbol=n.symbol||"circle",n.style=n.style||"filled"),n.position=n.position||"outside",n.color=n.color||"current",n},null),new q(s,"textOutline","none",["span"],!0,!0,function(t){if("none"===t)return t;var e={},n=t.split(" ");if(0===n.length||n.length>2)return null;var i=m(n[0]);if(e.color=i,null!==i&&n.shift(),1!==n.length)return null;var r=v(n[0]);return r?(e.thickness=r,e):null},function(t,e,n,i){if("none"===i)return i;var r={};return null===i.color?r.color=n.styleAttrs[F.color.qname]:r.color=i.color,r.thickness=b(i.thickness.value,i.thickness.unit,n.styleAttrs[F.fontSize.qname],n.styleAttrs[F.fontSize.qname],t.cellLength.h,t.pxLength.h),null===r.thickness?null:r}),new q(s,"textShadow","none",["span"],!0,!0,function(t){for(var e=t.match(/([^(,)]|\([^)]+\))+/g),n=[],i=0;i<e.length;i++){var r=e[i].split(" ");if(1===r.length&&"none"===r[0])return"none";if(r.length>1&&r.length<5){var l=[null,null,null,null],o=v(r.shift());if(null===o)return null;if(l[0]=o,null===(o=v(r.shift())))return null;if(l[1]=o,0===r.length){n.push(l);continue}if(null!==(o=v(r[0]))&&(l[2]=o,r.shift()),0===r.length){n.push(l);continue}var s=m(r[0]);if(null===s)return null;l[3]=s,n.push(l)}}return n},function(t,e,n,i){if("none"===i)return i;for(var r=[],l=0;l<i.length;l++){var o={};if(o.x_off=b(i[l][0].value,i[l][0].unit,null,n.styleAttrs[F.fontSize.qname],null,t.pxLength.w),null===o.x_off)return null;if(o.y_off=b(i[l][1].value,i[l][1].unit,null,n.styleAttrs[F.fontSize.qname],null,t.pxLength.h),null===o.y_off)return null;if(null===i[l][2])o.b_radius=0;else if(o.b_radius=b(i[l][2].value,i[l][2].unit,null,n.styleAttrs[F.fontSize.qname],null,t.pxLength.h),null===o.b_radius)return null;null===i[l][3]?o.color=n.styleAttrs[F.color.qname]:o.color=i[l][3],r.push(o)}return r}),new q(s,"unicodeBidi","normal",["span","p"],!1,!0,function(t){return t},null),new q(s,"visibility","visible",["body","div","p","region","span"],!0,!0,function(t){return t},null),new q(s,"wrapOption","wrap",["span"],!0,!0,function(t){return t},null),new q(s,"writingMode","lrtb",["region"],!1,!0,function(t){return t},null),new q(s,"zIndex","auto",["region"],!1,!0,function(t){var e;return"auto"===t?e=t:(e=parseInt(t),isNaN(e)&&(e=null)),e},null),new q(h,"linePadding","0c",["p"],!0,!1,v,function(t,e,n,i){return b(i.value,i.unit,null,null,t.cellLength.w,null)}),new q(h,"multiRowAlign","auto",["p"],!0,!1,function(t){return t},null),new q("http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt","backgroundImage",null,["div"],!1,!1,function(t){return t},null),new q(u,"forcedDisplay","false",["body","div","p","region","span"],!0,!0,function(t){return"true"===t},null),new q(u,"fillLineGap","false",["p"],!0,!0,function(t){return"true"===t},null)],N={};for(var S in A)N[A[S].qname]=A[S];var F={};for(var k in A)F[A[k].name]=A[k];function I(t,e,n,i){i||l(e,"No parser provided");var s=[],a=[],u=[],f=0,h=null;i.onclosetag=function(){if(s[0]instanceof K)null!==h.head&&null!==h.head.styling&&ot(h.head.styling,s[0].styleRefs,s[0].styleAttrs,e),delete s[0].styleRefs;else if(s[0]instanceof M)for(var t in s[0].styles)x(s[0].styles,t)&<(s[0],s[0].styles[t],e);else if(s[0]instanceof X||s[0]instanceof G){if(s[0].contents.length>1){var i=[s[0].contents[0]],r=void 0;for(r=1;r<s[0].contents.length;r++)s[0].contents[r]instanceof Z&&i[i.length-1]instanceof Z?i[i.length-1].text+=s[0].contents[r].text:i.push(s[0].contents[r]);s[0].contents=i}s[0]instanceof G&&1===s[0].contents.length&&s[0].contents[0]instanceof Z&&(s[0].text=s[0].contents[0].text,delete s[0].contents)}else s[0]instanceof R&&(s[0].node.uri===o&&"metadata"===s[0].node.local?f--:f>0&&n&&"onCloseTag"in n&&n.onCloseTag());u.shift(),a.shift(),s.shift()},i.ontext=function(t){if(void 0===s[0]);else if(s[0]instanceof G||s[0]instanceof X){if(s[0]instanceof G){var i=s[0].styleAttrs[F.ruby.qname];if("container"===i||"textContainer"===i||"baseContainer"===i)return}var r=new Z;r.initFromText(h,s[0],t,a[0],u[0],e),s[0].contents.push(r)}else s[0]instanceof R&&f>0&&n&&"onText"in n&&n.onText(t)},i.onopentag=function(t){var i=t.attributes["xml:space"];i?u.unshift(i.value):0===u.length?u.unshift("default"):u.unshift(u[0]);var c=t.attributes["xml:lang"];if(c?a.unshift(c.value):0===a.length?a.unshift(""):a.unshift(a[0]),t.uri===o)if("tt"===t.local)null!==h&&l(e,"Two <tt> elements at ("+this.line+","+this.column+")"),(h=new L).initFromNode(t,a[0],e),s.unshift(h);else if("head"===t.local)s[0]instanceof L||l(e,"Parent of <head> element is not <tt> at ("+this.line+","+this.column+")"),s.unshift(h.head);else if("styling"===t.local)s[0]instanceof E||l(e,"Parent of <styling> element is not <head> at ("+this.line+","+this.column+")"),s.unshift(h.head.styling);else if("style"===t.local){var d=void 0;s[0]instanceof M?((d=new T).initFromNode(t,e),d.id?h.head.styling.styles[d.id]=d:r(e,"<style> element missing @id attribute"),s.unshift(d)):s[0]instanceof K?((d=new T).initFromNode(t,e),st(d.styleAttrs,s[0].styleAttrs),s.unshift(d)):l(e,"Parent of <style> element is not <styling> or <region> at ("+this.line+","+this.column+")")}else if("initial"===t.local){var p=void 0;if(s[0]instanceof M){for(var g in(p=new O).initFromNode(t,e),p.styleAttrs)x(p.styleAttrs,g)&&(h.head.styling.initials[g]=p.styleAttrs[g]);s.unshift(p)}else l(e,"Parent of <initial> element is not <styling> at ("+this.line+","+this.column+")")}else if("layout"===t.local)s[0]instanceof E||l(e,"Parent of <layout> element is not <head> at "+this.line+","+this.column+")"),s.unshift(h.head.layout);else if("region"===t.local){s[0]instanceof P||l(e,"Parent of <region> element is not <layout> at "+this.line+","+this.column+")");var m=new K;m.initFromNode(h,t,a[0],e),!m.id||m.id in h.head.layout.regions?r(e,"Ignoring <region> with duplicate or missing @id at "+this.line+","+this.column+")"):h.head.layout.regions[m.id]=m,s.unshift(m)}else if("body"===t.local){s[0]instanceof L||l(e,"Parent of <body> element is not <tt> at "+this.line+","+this.column+")"),null!==h.body&&l(e,"Second <body> element at "+this.line+","+this.column+")");var y=new V;y.initFromNode(h,t,a[0],e),h.body=y,s.unshift(y)}else if("div"===t.local){s[0]instanceof Y||s[0]instanceof V||l(e,"Parent of <div> element is not <body> or <div> at "+this.line+","+this.column+")");var v=new Y;v.initFromNode(h,s[0],t,a[0],e);var w=v.styleAttrs[F.backgroundImage.qname];w&&(v.contents.push(new z(w)),delete v.styleAttrs[F.backgroundImage.qname]),s[0].contents.push(v),s.unshift(v)}else if("image"===t.local){s[0]instanceof Y||l(e,"Parent of <image> element is not <div> at "+this.line+","+this.column+")");var b=new z;b.initFromNode(h,s[0],t,a[0],e),s[0].contents.push(b),s.unshift(b)}else if("p"===t.local){s[0]instanceof Y||l(e,"Parent of <p> element is not <div> at "+this.line+","+this.column+")");var q=new X;q.initFromNode(h,s[0],t,a[0],e),s[0].contents.push(q),s.unshift(q)}else if("span"===t.local){s[0]instanceof G||s[0]instanceof X||l(e,"Parent of <span> element is not <span> or <p> at "+this.line+","+this.column+")");var A=new G;A.initFromNode(h,s[0],t,a[0],u[0],e),s[0].contents.push(A),s.unshift(A)}else if("br"===t.local){s[0]instanceof G||s[0]instanceof X||l(e,"Parent of <br> element is not <span> or <p> at "+this.line+","+this.column+")");var N=new J;N.initFromNode(h,s[0],t,a[0],e),s[0].contents.push(N),s.unshift(N)}else if("set"===t.local){s[0]instanceof G||s[0]instanceof X||s[0]instanceof Y||s[0]instanceof V||s[0]instanceof K||s[0]instanceof J||l(e,"Parent of <set> element is not a content element or a region at "+this.line+","+this.column+")");var S=new Q;S.initFromNode(h,s[0],t,e),s[0].sets.push(S),s.unshift(S)}else s.unshift(new R(t));else s.unshift(new R(t));if(s[0]instanceof R)if(t.uri===o&&"metadata"===t.local)f++;else if(f>0&&n&&"onOpenTag"in n){var k=[];for(var I in t.attributes)k[t.attributes[I].uri+" "+t.attributes[I].local]={uri:t.attributes[I].uri,local:t.attributes[I].local,value:t.attributes[I].value};n.onOpenTag(t.uri,t.local,k)}},i.write(t).close(),delete h.head.styling.styles;var c=h.head.layout.regions,d=!1;for(var p in c)if(x(c,p)){d=!0;break}if(!d){var g=K.prototype.createDefaultRegion(h.lang);c[g.id]=g}for(var m in c)x(c,m)&&_(h,c[m],null,null);return h.body&&_(h,h.body,null,null),h.body&&C(h.body),h}function C(t){if("contents"in t)for(var e=("styleAttrs"in t?t.styleAttrs[F.ruby.qname]:null),n="span"===t.kind&&("container"===e||"textContainer"===e||"baseContainer"===e),i=t.contents.length-1;i>=0;i--)!n||"styleAttrs"in t.contents[i]&&F.ruby.qname in t.contents[i].styleAttrs?C(t.contents[i]):delete t.contents[i]}function _(t,e,n,i){var r=i&&"seq"===i.timeContainer,l=0;i&&(l=r&&n?n.end:i.begin),e.begin=e.explicit_begin?e.explicit_begin+l:l;var o=e.begin,s=null;if("sets"in e)for(var a=0;a<e.sets.length;a++)_(t,e.sets[a],s,e),o="seq"===e.timeContainer?e.sets[a].end:Math.max(o,e.sets[a].end),s=e.sets[a];if("contents"in e){if("contents"in e)for(var u=0;u<e.contents.length;u++)_(t,e.contents[u],s,e),o="seq"===e.timeContainer?e.contents[u].end:Math.max(o,e.contents[u].end),s=e.contents[u]}else o=r?e.begin:Number.POSITIVE_INFINITY;null!==e.explicit_end&&null!==e.explicit_dur?e.end=Math.min(e.begin+e.explicit_dur,l+e.explicit_end):null===e.explicit_end&&null!==e.explicit_dur?e.end=e.begin+e.explicit_dur:null!==e.explicit_end&&null===e.explicit_dur?e.end=l+e.explicit_end:e.end=o,delete e.explicit_begin,delete e.explicit_dur,delete e.explicit_end,t._registerEvent(e)}var R=function(t){this.node=t},L=function(){function t(){this.events=[],this.head=new E,this.body=null}return t.prototype.initFromNode=function(t,e,n){var o=function(t,e){var n=it(t,a,"cellResolution"),r=15,l=32;if(null!==n){var o=/(\d+) (\d+)/.exec(n);null!==o?(l=parseInt(o[1]),r=parseInt(o[2])):i(e,"Malformed cellResolution value (using initial value instead)")}return{w:l,h:r}}(t,n);this.cellLength={h:new w(0,1/o.h),w:new w(1/o.w,0)};var u=function(t,e){var n,r=it(t,a,"frameRate"),l=30;if(null!==r){null!==(n=/(\d+)/.exec(r))?l=parseInt(n[1]):i(e,"Malformed frame rate attribute (using initial value instead)")}var o=it(t,a,"frameRateMultiplier"),s=1;if(null!==o){null!==(n=/(\d+) (\d+)/.exec(o))?s=parseInt(n[1])/parseInt(n[2]):i(e,"Malformed frame rate multiplier attribute (using initial value instead)")}var u=s*l,f=1,h=it(t,a,"tickRate");if(null===h)null!==r&&(f=u);else{null!==(n=/(\d+)/.exec(h))?f=parseInt(n[1]):i(e,"Malformed tick rate attribute (using initial value instead)")}return{effectiveFrameRate:u,tickRate:f}}(t,n);this.effectiveFrameRate=u.effectiveFrameRate,this.tickRate=u.tickRate,this.aspectRatio=function(t,e){var n=it(t,f,"aspectRatio");null===n&&(n=it(t,a,"displayAspectRatio"));var i=null;if(null!==n){var l=/(\d+)\s+(\d+)/.exec(n);if(null!==l){var o=parseInt(l[1]),s=parseInt(l[2]);0!==o&&0!==s?i=o/s:r(e,"Illegal aspectRatio values (ignoring)")}else r(e,"Malformed aspectRatio attribute (ignoring)")}return i}(t,n);var h=it(t,a,"timeBase");null!==h&&"media"!==h&&l(n,"Unsupported time base");var c=function(t,e){var n=it(t,s,"extent");if(null===n)return null;var r=n.split(" ");if(2!==r.length)return i(e,"Malformed extent (ignoring)"),null;var l=v(r[0]),o=v(r[1]);if(!o||!l)return i(e,"Malformed extent values (ignoring)"),null;return{h:o,w:l}}(t,n);null===c?this.pxLength={h:null,w:null}:("px"===c.h.unit&&"px"===c.w.unit||l(n,"Extent on TT must be in px or absent"),this.pxLength={h:new w(0,1/c.h.value),w:new w(1/c.w.value,0)}),this.dimensions={h:new w(0,1),w:new w(1,0)},this.lang=e},t.prototype._registerEvent=function(t){if(!(t.end<=t.begin)){var e=at(this.events,t.begin);if(e.found||this.events.splice(e.index,0,t.begin),t.end!==Number.POSITIVE_INFINITY){var n=at(this.events,t.end);n.found||this.events.splice(n.index,0,t.end)}}},t.prototype.getMediaTimeRange=function(){return[this.events[0],this.events[this.events.length-1]]},t.prototype.getMediaTimeEvents=function(){return this.events},t}(),E=function(){this.styling=new M,this.layout=new P},M=function(){this.styles={},this.initials={}},T=function(){function t(){this.id=null,this.styleAttrs=null,this.styleRefs=null}return t.prototype.initFromNode=function(t,e){this.id=tt(t),this.styleAttrs=nt(t,e),this.styleRefs=et(t)},t}(),O=function(){function t(){this.styleAttrs=null}return t.prototype.initFromNode=function(t){for(var e in this.styleAttrs={},t.attributes)if(t.attributes[e].uri===u||t.attributes[e].uri===h||t.attributes[e].uri===s){var n=t.attributes[e].uri+" "+t.attributes[e].local;this.styleAttrs[n]=t.attributes[e].value}},t}(),P=function(){this.regions={}},D=function(t){this.kind=t},z=function(t){function e(e,n){var i=t.call(this,"image")||this;return i.src=e,i.type=n,i}return n(e,t),e.prototype.initFromNode=function(t,e,n,i,l){this.src="src"in n.attributes?n.attributes.src.value:null,this.src||r(l,"Invalid image@src attribute"),this.type="type"in n.attributes?n.attributes.type.value:null,this.type||r(l,"Invalid image@type attribute"),H.prototype.initFromNode.call(this,t,e,n,l),W.prototype.initFromNode.call(this,t,e,n,l),j.prototype.initFromNode.call(this,t,e,n,l),B.prototype.initFromNode.call(this,t,e,n,l),this.lang=i},e}(D),U=function(){function t(t){this.id=t}return t.prototype.initFromNode=function(t,e,n){this.id=tt(n)},t}(),B=function(){function t(t){this.regionID=t}return t.prototype.initFromNode=function(t,e,n){this.regionID=function(t){return t&&"region"in t.attributes?t.attributes.region.value:""}(n)},t}(),H=function(){function t(t){this.styleAttrs=t}return t.prototype.initFromNode=function(t,e,n,i){this.styleAttrs=nt(n,i),null!==t.head&&null!==t.head.styling&&ot(t.head.styling,et(n),this.styleAttrs,i)},t}(),j=function(){function t(t){this.sets=t}return t.prototype.initFromNode=function(){this.sets=[]},t}(),$=function(){function t(t){this.contents=t}return t.prototype.initFromNode=function(){this.contents=[]},t}(),W=function(){function t(t,e,n){this.explicit_begin=t,this.explicit_end=e,this.explicit_dur=n}return t.prototype.initFromNode=function(t,e,n,l){var o=function(t,e,n,r){var l=null;n&&"begin"in n.attributes&&null===(l=rt(t.tickRate,t.effectiveFrameRate,n.attributes.begin.value))&&i(r,"Malformed begin value (using 0)");var o=null;n&&"dur"in n.attributes&&null===(o=rt(t.tickRate,t.effectiveFrameRate,n.attributes.dur.value))&&i(r,"Malformed dur value (ignoring)");var s=null;n&&"end"in n.attributes&&null===(s=rt(t.tickRate,t.effectiveFrameRate,n.attributes.end.value))&&i(r,"Malformed end value (ignoring)");return{explicit_begin:l,explicit_end:s,explicit_dur:o}}(t,0,n,l);this.explicit_begin=o.explicit_begin,this.explicit_end=o.explicit_end,this.explicit_dur=o.explicit_dur,this.timeContainer=function(t,e){var n=t&&"timeContainer"in t.attributes?t.attributes.timeContainer.value:null;return n&&"par"!==n?"seq"===n?"seq":(r(e,"Illegal value of timeContainer (assuming 'par')"),"par"):"par"}(n,l)},t}(),V=function(t){function e(){return t.call(this,"body")||this}return n(e,t),e.prototype.initFromNode=function(t,e,n,i){H.prototype.initFromNode.call(this,t,null,e,i),W.prototype.initFromNode.call(this,t,null,e,i),j.prototype.initFromNode.call(this,t,null,e,i),B.prototype.initFromNode.call(this,t,null,e,i),$.prototype.initFromNode.call(this,t,null,e,i),this.lang=n},e}(D),Y=function(t){function e(){return t.call(this,"div")||this}return n(e,t),e.prototype.initFromNode=function(t,e,n,i,r){H.prototype.initFromNode.call(this,t,e,n,r),W.prototype.initFromNode.call(this,t,e,n,r),j.prototype.initFromNode.call(this,t,e,n,r),B.prototype.initFromNode.call(this,t,e,n,r),$.prototype.initFromNode.call(this,t,e,n,r),this.lang=i},e}(D),X=function(t){function e(){return t.call(this,"p")||this}return n(e,t),e.prototype.initFromNode=function(t,e,n,i,r){H.prototype.initFromNode.call(this,t,e,n,r),W.prototype.initFromNode.call(this,t,e,n,r),j.prototype.initFromNode.call(this,t,e,n,r),B.prototype.initFromNode.call(this,t,e,n,r),$.prototype.initFromNode.call(this,t,e,n,r),this.lang=i},e}(D),G=function(t){function e(){return t.call(this,"span")||this}return n(e,t),e.prototype.initFromNode=function(t,e,n,i,r,l){H.prototype.initFromNode.call(this,t,e,n,l),W.prototype.initFromNode.call(this,t,e,n,l),j.prototype.initFromNode.call(this,t,e,n,l),B.prototype.initFromNode.call(this,t,e,n,l),$.prototype.initFromNode.call(this,t,e,n,l),this.space=r,this.lang=i},e}(D),Z=function(t){function e(){return t.call(this,"span")||this}return n(e,t),e.prototype.initFromText=function(t,e,n,i,r,l){W.prototype.initFromNode.call(this,t,e,null,l),this.text=n,this.space=r,this.lang=i},e}(D),J=function(t){function e(){return t.call(this,"br")||this}return n(e,t),e.prototype.initFromNode=function(t,e,n,i,r){B.prototype.initFromNode.call(this,t,e,n,r),W.prototype.initFromNode.call(this,t,e,n,r),this.lang=i},e}(D),K=function(){function t(){}return t.prototype.createDefaultRegion=function(e){var n=new t;return n.id="",n.styleAttrs={},n.sets=[],n.explicit_begin=0,n.explicit_end=Number.POSITIVE_INFINITY,n.explicit_dur=null,this.lang=e,n},t.prototype.initFromNode=function(t,e,n,i){U.prototype.initFromNode.call(this,t,null,e,i),W.prototype.initFromNode.call(this,t,null,e,i),j.prototype.initFromNode.call(this,t,null,e,i),this.styleAttrs=nt(e,i),this.styleRefs=et(e),this.lang=n},t}(),Q=function(){function t(){}return t.prototype.initFromNode=function(t,e,n,i){W.prototype.initFromNode.call(this,t,e,n,i),this.styles=nt(n,i)},t}();function tt(t){return t&&"xml:id"in t.attributes&&t.attributes["xml:id"].value||null}function et(t){return t&&"style"in t.attributes?t.attributes.style.value.split(" "):[]}function nt(t,e){var n={};if(null!==t)for(var l in t.attributes){var o=t.attributes[l].uri+" "+t.attributes[l].local,s=N[o];if(void 0!==s){var a=s.parse(t.attributes[l].value);null!==a?(o in n&&i(e,"More than one style attribute for "+o),n[o]=a,s===F.zIndex&&i(e,"zIndex attribute present but not used by IMSC1 since regions do not overlap")):r(e,"Cannot parse styling attribute "+o)}}return n}function it(t,e,n){for(var i in t.attributes)if(t.attributes[i].uri===e&&t.attributes[i].local===n)return t.attributes[i].value;return null}function rt(t,e,n){var i,r=null;return null!==(i=/^(\d+(?:\.\d+)?)f$/.exec(n))?null!==e&&(r=parseFloat(i[1])/e):null!==(i=/^(\d+(?:\.\d+)?)t$/.exec(n))?null!==t&&(r=parseFloat(i[1])/t):null!==(i=/^(\d+(?:\.\d+)?)ms$/.exec(n))?r=parseFloat(i[1])/1e3:null!==(i=/^(\d+(?:\.\d+)?)s$/.exec(n))?r=parseFloat(i[1]):null!==(i=/^(\d+(?:\.\d+)?)h$/.exec(n))?r=3600*parseFloat(i[1]):null!==(i=/^(\d+(?:\.\d+)?)m$/.exec(n))?r=60*parseFloat(i[1]):null!==(i=/^(\d{2,}):(\d\d):(\d\d(?:\.\d+)?)$/.exec(n))?r=3600*parseInt(i[1])+60*parseInt(i[2])+parseFloat(i[3]):null!==(i=/^(\d{2,}):(\d\d):(\d\d):(\d{2,})$/.exec(n))&&null!==e&&(r=3600*parseInt(i[1])+60*parseInt(i[2])+parseInt(i[3])+(null===i[4]?0:parseInt(i[4])/e)),r}function lt(t,e,n){for(;e.styleRefs.length>0;){var i=e.styleRefs.pop();i in t.styles?(lt(t,t.styles[i],n),st(t.styles[i].styleAttrs,e.styleAttrs)):r(n,"Non-existant style id referenced")}}function ot(t,e,n,i){for(var l=e.length-1;l>=0;l--){var o=e[l];o in t.styles?st(t.styles[o].styleAttrs,n):r(i,"Non-existant style id referenced")}}function st(t,e){for(var n in t)x(t,n)&&(n in e||(e[n]=t[n]))}function at(t,e){for(var n,i=0,r=t.length-1;i<=r;){var l=t[n=Math.floor((i+r)/2)];if(l<e)i=n+1;else{if(!(l>e))return{found:!0,index:n};r=n-1}}return{found:!1,index:i}}var ut=function(){function t(){this.onopentag=function(t){console.log(t)},this.ontext=function(t){console.log(t)},this.onclosetag=function(){}}return t.toNode=function(e){var n=e.attributes,i=t.toNS(e);i.attributes={};for(var r=0,l=n.length;r<l;r++){var o=n[r];i.attributes[o.name]=t.toNS(o)}return i},t.toNS=function(t){return{name:t.nodeName,prefix:t.prefix,local:t.localName,uri:t.namespaceURI,value:t.value}},t.prototype.write=function(t){var e=(new DOMParser).parseFromString(t,"application/xml"),n=e.querySelector("parsererror");if(n)throw new Error("XML parsing error: "+n.textContent);return this.process(e.documentElement),this},t.prototype.process=function(e){var n=t.toNode(e);this.onopentag(n);for(var i=e.childNodes,r=0,l=i.length;r<l;r++){var o=i[r];o.nodeType===Node.TEXT_NODE?this.ontext(o.textContent):o.nodeType===Node.ELEMENT_NODE&&this.process(o)}this.onclosetag()},t.prototype.close=function(){return this},t}();function ft(){return new ut}var ht=/firefox/i.test(navigator.userAgent);function ct(t,e,n,l){var o;if("region"===n.kind)(o=document.createElement("div")).style.position="absolute";else if("body"===n.kind)o=document.createElement("div");else if("div"===n.kind)o=document.createElement("div");else if("image"===n.kind){if(o=document.createElement("img"),null!==t.imgResolver&&null!==n.src){var s=t.imgResolver(n.src,o);s&&(o.src=s),o.height=t.regionH,o.width=t.regionW}}else if("p"===n.kind)o=document.createElement("p");else if("span"===n.kind)if("container"===n.styleAttrs[F.ruby.qname])o=document.createElement("ruby"),t.ruby=!0;else if("base"===n.styleAttrs[F.ruby.qname])o=document.createElement("span");else if("text"===n.styleAttrs[F.ruby.qname])o=document.createElement("rt");else{if("delimiter"===n.styleAttrs[F.ruby.qname])return;o=document.createElement("span")}else"br"===n.kind&&(o=document.createElement("br"));if(o){if(n.lang&&("region"!==n.kind&&n.lang===l.lang||(o.lang=n.lang)),e.appendChild(o),o.style.margin="0","region"===n.kind){var a=n.styleAttrs[F.writingMode.qname];"lrtb"===a||"lr"===a?(t.ipd="lr",t.bpd="tb"):"rltb"===a||"rl"===a?(t.ipd="rl",t.bpd="tb"):"tblr"===a?(t.ipd="tb",t.bpd="lr"):"tbrl"!==a&&"tb"!==a||(t.ipd="tb",t.bpd="rl")}else if("p"===n.kind&&"tb"===t.bpd){var u=n.styleAttrs[F.direction.qname];t.ipd="ltr"===u?"lr":"rl"}for(var f=0;f<bt.length;f++){var h=bt[f],c=n.styleAttrs[h.qname];void 0!==c&&null!==h.map&&h.map(t,o,n,c)}var d=o,p=n.styleAttrs[F.linePadding.qname];if(p&&!p.isZero()){var g=p.toUsedLength(t.w,t.h);if(g>0){var m=Math.ceil(g)+"px";"tb"===t.bpd?(d.style.paddingLeft=m,d.style.paddingRight=m):(d.style.paddingTop=m,d.style.paddingBottom=m),t.lp=p}}var y=n.styleAttrs[F.multiRowAlign.qname];if(y&&"auto"!==y){var v=document.createElement("span");v.style.display="inline-block",v.style.textAlign=y,o.appendChild(v),d=v,t.mra=y}var w=n.styleAttrs[F.rubyReserve.qname];if(w&&"none"!==w[0]&&(t.rubyReserve=w),n.styleAttrs[F.fillLineGap.qname]&&(t.flg=!0),"span"===n.kind&&n.text){var b=n.styleAttrs[F.textEmphasis.qname];if(b&&"none"!==b.style&&(t.textEmphasis=!0),F.textCombine.qname in n.styleAttrs&&"all"===n.styleAttrs[F.textCombine.qname]||null!==o.closest("rt"))o.textContent=n.text,o._isd_element=n,b&&vt(t,o,n,b);else for(var x="",q=0;q<n.text.length;q++){x+=n.text.charAt(q);var A=n.text.charCodeAt(q);if(A<55296||A>56319||q===n.text.length-1){var N=document.createElement("span");N.textContent=x,b&&vt(t,N,n,b),o.appendChild(N),x="",N._isd_element=n}}}if("contents"in n)if("span"===n.kind&&"container"===n.styleAttrs[F.ruby.qname]&&n.contents.some(function(t){return"baseContainer"===t.styleAttrs[F.ruby.qname]}))!function(t,e,n){for(var r=[],l=[],o=0,s=n.contents;o<s.length;o++){var a=s[o];"baseContainer"===a.styleAttrs[F.ruby.qname]?r=a.contents.filter(function(t){return"base"===t.styleAttrs[F.ruby.qname]}):"textContainer"===a.styleAttrs[F.ruby.qname]&&l.push(a.contents.filter(function(t){return"text"===t.styleAttrs[F.ruby.qname]}))}for(var u=r.length,f=0;f<l.length&&f<2;f++)u=Math.max(u,l[f].length);u>r.length&&i(t.errorHandler,"Ruby text container has more ruby text than the ruby base container has ruby bases.");for(var h=e.cloneNode(!1),c=e,d=0;d<u;d++){if(d>0){var p=h.cloneNode(!1);c.parentElement.insertBefore(p,c.nextSibling),c=p}var g=c;l.length>1&&(g=h.cloneNode(!1),c.appendChild(g)),d<r.length&&ct(t,g,r[d],n),l.length>1&&d<l[1].length&&ct(t,g,l[1][d],n),l.length>0&&d<l[0].length&&ct(t,c,l[0][d],n)}}(t,o,n);else for(var S=0;S<n.contents.length;S++)ct(t,d,n.contents[S],n);var k=[];if("p"===n.kind&&(yt(t,d,k,null),t.rubyReserve&&(!function(t,e){for(var n=0;n<t.length;n++){var i=e.rubyReserve[1].toUsedLength(e.w,e.h)+"px",r=[];"both"===e.rubyReserve[0]||"outside"===e.rubyReserve[0]&&1==t.length?(r.push(At?"after":"under"),r.push(At?"before":"over")):"after"===e.rubyReserve[0]||"outside"===e.rubyReserve[0]&&n>0?r.push(At?"after":"tb"===e.bpd||"rl"===e.bpd?"under":"over"):r.push(At?"before":"tb"===e.bpd||"rl"===e.bpd?"over":"under");for(var l=null,o=0;o<t[n].rbc.length;o++)if("ruby"===t[n].rbc[o].localName){l=t[n].rbc[o];break}var s=document.createElement("span");s.textContent="";for(var a=0,u=r;a<u.length;a++){var f=u[a],h=document.createElement("ruby");h.appendChild(s);var c=document.createElement("rt");if(c.style[Nt]=f,c.textContent="",c.style.fontSize=i,h.appendChild(c),null!==l)for(var d=0;d<l.style.length;d++)h.style.setProperty(l.style.item(d),l.style.getPropertyValue(l.style.item(d)));h.style[Nt]=f,s=h}var p=l||t[n].elements[0].node;p.parentElement.insertBefore(s,p)}}(k,t),t.rubyReserve=null),(t.ruby||t.rubyReserve)&&(!function(t,e){for(var n=0;n<t.length;n++)for(var i=0;i<t[n].rbc.length;i++)if(!t[n].rbc[i].style[Nt]){var r=void 0;r=At?0===n?"before":"after":"tb"===e.bpd||"rl"===e.bpd?0===n?"over":"under":0===n?"under":"over",t[n].rbc[i].style[Nt]=r}}(k,t),t.ruby=null),t.textEmphasis&&(!function(t,e){for(var n=0;n<t.length;n++)for(var i=0;i<t[n].te.length;i++)if(!t[n].te[i].style[Ft]||"none"===t[n].te[i].style[Ft]){var r=void 0;r="tb"===e.bpd?0===n?"left over":"left under":"rl"===e.bpd?0===n?"right under":"left under":0===n?"left under":"right under",t[n].te[i].style[Ft]=r}}(k,t),t.textEmphasis=null),t.mra&&(!function(t){for(var e=0;e<t.length-1;e++){var n=t[e].elements.length;if(0!==n&&!1===t[e].br){var i=document.createElement("br"),r=t[e].elements[n-1].node;r.parentElement.insertBefore(i,r.nextSibling)}}}(k),t.mra=null),t.lp&&(!function(t,e,n){if(null===t)return;for(var i=0;i<t.length;i++){var r=t[i].elements.length,l=Math.ceil(e)+"px",o="-"+Math.ceil(e)+"px";if(0!==r){var s=t[i].elements[t[i].start_elem],a=t[i].elements[t[i].end_elem];if(s===a){var u=s.node.getBoundingClientRect();if(0==u.width||0==u.height)continue}"lr"===n.ipd?(s.node.style.marginLeft=o,s.node.style.paddingLeft=l):"rl"===n.ipd?(s.node.style.paddingRight=l,s.node.style.marginRight=o):"tb"===n.ipd&&(s.node.style.paddingTop=l,s.node.style.marginTop=o),"lr"===n.ipd?(ht||(a.node.style.marginRight=o),a.node.style.paddingRight=l):"rl"===n.ipd?(a.node.style.paddingLeft=l,ht||(a.node.style.marginLeft=o)):"tb"===n.ipd&&(a.node.style.paddingBottom=l,a.node.style.marginBottom=o)}}}(k,t.lp.toUsedLength(t.w,t.h),t),t.lp=null),function(t,e){for(var n=0;n<t.length;n++)for(var i=t[n],r=1;r<i.elements.length;){var l=i.elements[r-1],o=i.elements[r];pt(l.node,o.node,e)?i.elements.splice(r,1):r++}for(var s,a,u=[],f=0;f<t.length;f++)for(var h=0;h<t[f].elements.length;h++)(a=dt(s=t[f].elements[h].node,u,!1))&&(s.style.backgroundColor=a);for(var c=0;c<u.length;c++)u[c].style.backgroundColor=""}(k,t),t.flg)){var I=mt(d.getBoundingClientRect(),t);!function(t,e,n,i){for(var r=Math.sign(n-e),l=0;l<=t.length;l++){var o=void 0;o=0===l?Math.round(e):l===t.length?Math.round(n):Math.round((t[l-1].after+t[l].before)/2);var s=void 0,a=void 0,u=void 0;if(l>0&&t[l-1])for(a=0;a<t[l-1].elements.length;a++)s=r*(o-(u=t[l-1].elements[a]).after)+"px","lr"===i.bpd?u.node.style.paddingRight=s:"rl"===i.bpd?u.node.style.paddingLeft=s:"tb"===i.bpd&&(u.node.style.paddingBottom=s);if(l<t.length)for(a=0;a<t[l].elements.length;a++)s=r*((u=t[l].elements[a]).before-o)+"px","lr"===i.bpd?u.node.style.paddingLeft=s:"rl"===i.bpd?u.node.style.paddingRight=s:"tb"===i.bpd&&(u.node.style.paddingTop=s)}}(k,I.before,I.after,t),t.flg=null}if("region"===n.kind&&"tb"===t.bpd&&t.enableRollUp&&n.contents.length>0&&"after"===n.styleAttrs[F.displayAlign.qname]){yt(t,d,k,null);var C=""===n.id?"_":n.id,_=new gt(C,k);if(t.currentISDState[_.id]=_,t.previousISDState&&_.id in t.previousISDState&&t.previousISDState[_.id].plist.length>0&&_.plist.length>1&&_.plist[_.plist.length-2].text===t.previousISDState[_.id].plist[t.previousISDState[_.id].plist.length-1].text){var R=o.firstElementChild,L=_.plist[_.plist.length-1].after-_.plist[_.plist.length-1].before;R.style.bottom="-"+L+"px",R.style.transition="transform 0.4s",R.style.position="relative",R.style.transform="translateY(-"+L+"px)"}}}else r(t.errorHandler,"Error processing ISD element kind: "+n.kind)}function dt(t,e,n){return t.style.backgroundColor?(n&&!e.includes(t)&&e.push(t),t.style.backgroundColor):"SPAN"===t.parentElement.nodeName||"RUBY"===t.parentElement.nodeName||"RT"===t.parentElement.nodeName?dt(t.parentElement,e,!0):void 0}function pt(t,e,n){if("SPAN"===t.tagName&&"SPAN"===e.tagName&&t._isd_element===e._isd_element){if(!t._isd_element)return r(n.errorHandler,"Internal error: HTML span is not linked to a source element; cannot merge spans."),!1;t.textContent+=e.textContent;for(var i=0;i<e.style.length;i++){var l=e.style[i];(l.indexOf("border")>=0||l.indexOf("padding")>=0||l.indexOf("margin")>=0)&&(t.style[l]=e.style[l])}return e.parentElement.removeChild(e),!0}return!1}var gt=function(t,e){this.id=t,this.plist=e};function mt(t,e){var n={before:null,after:null,start:null,end:null};return"tb"===e.bpd?(n.before=t.top,n.after=t.bottom,"lr"===e.ipd?(n.start=t.left,n.end=t.right):(n.start=t.right,n.end=t.left)):"lr"===e.bpd?(n.before=t.left,n.after=t.right,n.start=t.top,n.end=t.bottom):"rl"===e.bpd&&(n.before=t.right,n.after=t.left,n.start=t.top,n.end=t.bottom),n}function yt(t,e,n,i){if("rt"!==e.localName){var r,l,o,s,a=e.style.backgroundColor||i;if(0===e.childElementCount)if("span"===e.localName){var u=mt(e.getBoundingClientRect(),t);if(0!==n.length&&(r=u.before,l=u.after,o=n[n.length-1].before,s=n[n.length-1].after,l<s&&r>o||s<=l&&o>=r)){var f=Math.sign(u.after-u.before),h=Math.sign(u.end-u.start);f*(u.before-n[n.length-1].before)<0&&(n[n.length-1].before=u.before),f*(u.after-n[n.length-1].after)>0&&(n[n.length-1].after=u.after),h*(u.start-n[n.length-1].start)<0&&(n[n.length-1].start=u.start,n[n.length-1].start_elem=n[n.length-1].elements.length),h*(u.end-n[n.length-1].end)>0&&(n[n.length-1].end=u.end,n[n.length-1].end_elem=n[n.length-1].elements.length)}else n.push({before:u.before,after:u.after,start:u.start,end:u.end,start_elem:0,end_elem:0,elements:[],rbc:[],te:[],text:"",br:!1});n[n.length-1].text+=e.textContent,n[n.length-1].elements.push({node:e,bgcolor:a,before:u.before,after:u.after})}else"br"===e.localName&&0!==n.length&&(n[n.length-1].br=!0);else for(var c=e.firstChild;c;)c.nodeType===Node.ELEMENT_NODE&&(yt(t,c,n,a),"ruby"===c.localName?n.length>0&&n[n.length-1].rbc.push(c):"span"===c.localName&&c.style[St]&&"none"!==c.style[St]&&n.length>0&&n[n.length-1].te.push(c)),c=c.nextSibling}}function vt(t,e,n,i){if("none"!==i.style&&("auto"===i.style?e.style[St]="filled":e.style[St]=i.style+" "+i.symbol,"before"===i.position||"after"===i.position)){var r=void 0;r="tb"===t.bpd?"before"===i.position?"left over":"left under":"rl"===t.bpd?"before"===i.position?"right under":"left under":"before"===i.position?"left under":"right under",e.style[Ft]=r}}for(var wt=function(t,e){this.qname=t,this.map=e},bt=[new wt("http://www.w3.org/ns/ttml#styling backgroundColor",function(t,e,n,i){0!==i[3]&&(e.style.backgroundColor="rgba("+i[0].toString()+","+i[1].toString()+","+i[2].toString()+","+(i[3]/255).toString()+")")}),new wt("http://www.w3.org/ns/ttml#styling color",function(t,e,n,i){e.style.color="rgba("+i[0].toString()+","+i[1].toString()+","+i[2].toString()+","+(i[3]/255).toString()+")"}),new wt("http://www.w3.org/ns/ttml#styling direction",function(t,e,n,i){e.style.direction=i}),new wt("http://www.w3.org/ns/ttml#styling display",function(){}),new wt("http://www.w3.org/ns/ttml#styling displayAlign",function(t,e,n,i){e.style.display="flex",e.style.flexDirection="column","before"===i?e.style.justifyContent="flex-start":"center"===i?e.style.justifyContent="center":"after"===i&&(e.style.justifyContent="flex-end")}),new wt("http://www.w3.org/ns/ttml#styling extent",function(t,e,n,i){t.regionH=i.h.toUsedLength(t.w,t.h),t.regionW=i.w.toUsedLength(t.w,t.h);var r=0,l=0,o=n.styleAttrs["http://www.w3.org/ns/ttml#styling padding"];o&&(r=o[0].toUsedLength(t.w,t.h)+o[2].toUsedLength(t.w,t.h),l=o[1].toUsedLength(t.w,t.h)+o[3].toUsedLength(t.w,t.h)),e.style.height=t.regionH-r+"px",e.style.width=t.regionW-l+"px"}),new wt("http://www.w3.org/ns/ttml#styling fontFamily",function(t,e,n,i){for(var r=[],l=0;l<i.length;l++)i[l]=i[l].trim(),"monospaceSerif"===i[l]?(r.push("Courier New"),r.push('"Liberation Mono"'),r.push("Courier"),r.push("monospace")):"proportionalSansSerif"===i[l]?(r.push("Arial"),r.push("Helvetica"),r.push('"Liberation Sans"'),r.push("sans-serif")):"monospace"===i[l]?r.push("monospace"):"sansSerif"===i[l]?r.push("sans-serif"):"serif"===i[l]?r.push("serif"):"monospaceSansSerif"===i[l]?(r.push("Consolas"),r.push("monospace")):"proportionalSerif"===i[l]?r.push("serif"):r.push(i[l]);if(r.length>0){for(var o=[r[0]],s=1;s<r.length;s++)-1==o.indexOf(r[s])&&o.push(r[s]);r=o}e.style.fontFamily=r.join(",")}),new wt("http://www.w3.org/ns/ttml#styling shear",function(t,e,n,i){if(0!==i){var r=-.9*i;"tb"===t.bpd?e.style.transform="skewX("+r+"deg)":e.style.transform="skewY("+r+"deg)"}}),new wt("http://www.w3.org/ns/ttml#styling fontSize",function(t,e,n,i){e.style.fontSize=i.toUsedLength(t.w,t.h)+"px"}),new wt("http://www.w3.org/ns/ttml#styling fontStyle",function(t,e,n,i){e.style.fontStyle=i}),new wt("http://www.w3.org/ns/ttml#styling fontVariant",function(t,e,n,i){if(n.text&&"normal"!==i){e.style.verticalAlign=i;var r=n.styleAttrs[F.fontSize.qname];e.style.fontSize=.7*r.toUsedLength(t.w,t.h)+"px"}}),new wt("http://www.w3.org/ns/ttml#styling fontWeight",function(t,e,n,i){e.style.fontWeight=i}),new wt("http://www.w3.org/ns/ttml#styling lineHeight",function(t,e,n,i){e.style.lineHeight="normal"===i?"normal":i.toUsedLength(t.w,t.h)+"px"}),new wt("http://www.w3.org/ns/ttml#styling opacity",function(t,e,n,i){e.style.opacity=i}),new wt("http://www.w3.org/ns/ttml#styling origin",function(t,e,n,i){e.style.top=i.h.toUsedLength(t.w,t.h)+"px",e.style.left=i.w.toUsedLength(t.w,t.h)+"px"}),new wt("http://www.w3.org/ns/ttml#styling overflow",function(t,e,n,i){e.style.overflow=i}),new wt("http://www.w3.org/ns/ttml#styling padding",function(t,e,n,i){var r=[];r[0]=i[0].toUsedLength(t.w,t.h)+"px",r[1]=i[3].toUsedLength(t.w,t.h)+"px",r[2]=i[2].toUsedLength(t.w,t.h)+"px",r[3]=i[1].toUsedLength(t.w,t.h)+"px",e.style.padding=r.join(" ")}),new wt("http://www.w3.org/ns/ttml#styling position",function(t,e,n,i){e.style.top=i.h.toUsedLength(t.w,t.h)+"px",e.style.left=i.w.toUsedLength(t.w,t.h)+"px"}),new wt("http://www.w3.org/ns/ttml#styling rubyAlign",function(t,e,n,i){e.style.rubyAlign="spaceAround"===i?"space-around":"center"}),new wt("http://www.w3.org/ns/ttml#styling rubyPosition",function(t,e,n,i){if("before"===i||"after"===i){var r=void 0;r=At?i:"tb"===t.bpd||"rl"===t.bpd?"before"===i?"over":"under":"before"===i?"under":"over",e.parentElement.style[Nt]=r}}),new wt("http://www.w3.org/ns/ttml#styling showBackground",null),new wt("http://www.w3.org/ns/ttml#styling textAlign",function(t,e,n,i){var r;r="start"===i?"rl"===t.ipd?"right":"left":"end"===i?"rl"===t.ipd?"left":"right":i,e.style.textAlign=r}),new wt("http://www.w3.org/ns/ttml#styling textDecoration",function(t,e,n,i){e.style.textDecoration=i.join(" ").replace("lineThrough","line-through")}),new wt("http://www.w3.org/ns/ttml#styling textOutline",function(){}),new wt("http://www.w3.org/ns/ttml#styling textShadow",function(t,e,n,i){var r=n.styleAttrs[F.textOutline.qname];if("none"===i&&"none"===r)e.style.textShadow="";else{var l=[];if("none"!==r){var o="rgba("+r.color[0].toString()+","+r.color[1].toString()+","+r.color[2].toString()+","+(r.color[3]/255).toString()+")";l.push("1px 1px 1px "+o),l.push("-1px 1px 1px "+o),l.push("1px -1px 1px "+o),l.push("-1px -1px 1px "+o)}if("none"!==i)for(var s=0;s<i.length;s++)l.push(i[s].x_off.toUsedLength(t.w,t.h)+"px "+i[s].y_off.toUsedLength(t.w,t.h)+"px "+i[s].b_radius.toUsedLength(t.w,t.h)+"px rgba("+i[s].color[0].toString()+","+i[s].color[1].toString()+","+i[s].color[2].toString()+","+(i[s].color[3]/255).toString()+")");e.style.textShadow=l.join(",")}}),new wt("http://www.w3.org/ns/ttml#styling textCombine",function(t,e,n,i){e.style.textCombineUpright=i}),new wt("http://www.w3.org/ns/ttml#styling textEmphasis",function(){}),new wt("http://www.w3.org/ns/ttml#styling unicodeBidi",function(t,e,n,i){var r;r="bidiOverride"===i?"bidi-override":i,e.style.unicodeBidi=r}),new wt("http://www.w3.org/ns/ttml#styling visibility",function(t,e,n,i){e.style.visibility=i}),new wt("http://www.w3.org/ns/ttml#styling wrapOption",function(t,e,n,i){"wrap"===i?"preserve"===n.space?e.style.whiteSpace="pre-wrap":e.style.whiteSpace="normal":"preserve"===n.space?e.style.whiteSpace="pre":e.style.whiteSpace="noWrap"}),new wt("http://www.w3.org/ns/ttml#styling writingMode",function(t,e,n,i){"lrtb"===i||"lr"===i||"rltb"===i||"rl"===i?e.style.writingMode="horizontal-tb":"tblr"===i?e.style.writingMode="vertical-lr":"tbrl"!==i&&"tb"!==i||(e.style.writingMode="vertical-rl")}),new wt("http://www.w3.org/ns/ttml#styling zIndex",function(t,e,n,i){e.style.zIndex=i}),new wt("http://www.w3.org/ns/ttml/profile/imsc1#styling forcedDisplay",function(t,e,n,i){t.displayForcedOnlyMode&&!1===i&&(e.style.visibility="hidden")})],xt={},qt=0;qt<bt.length;qt++)xt[bt[qt].qname]=bt[qt];var At="webkitRubyPosition"in window.getComputedStyle(document.documentElement),Nt=At?"webkitRubyPosition":"rubyPosition",St="webkitTextEmphasisStyle"in window.getComputedStyle(document.documentElement)?"webkitTextEmphasisStyle":"textEmphasisStyle",Ft="webkitTextEmphasisPosition"in window.getComputedStyle(document.documentElement)?"webkitTextEmphasisPosition":"textEmphasisPosition";var kt=[F.color.qname,F.textCombine.qname,F.textDecoration.qname,F.textEmphasis.qname,F.textOutline.qname,F.textShadow.qname];function It(t,e,n,i,l,o,s,a,u){if(e<s.begin||e>=s.end)return null;var f="regionID"in s&&""!==s.regionID?s.regionID:o;if(null!==l&&f!==n.id&&(!("contents"in s)||"contents"in s&&0===s.contents.length||""!==f))return null;var h=new Lt(s),c=h.styleAttrs;if("sets"in s)for(var d=0;d<s.sets.length;d++)if(!(e<s.sets[d].begin||e>=s.sets[d].end))for(var p in s.sets[d].styles)x(s.sets[d].styles,p)&&(c[p]=s.sets[d].styles[p]);var g={};for(var p in c)if(x(c,p)&&(g[p]=!0,"region"===h.kind&&p===F.writingMode.qname&&!(F.direction.qname in c))){var m=c[p];"lrtb"===m||"lr"===m?c[F.direction.qname]="ltr":"rltb"!==m&&"rl"!==m||(c[F.direction.qname]="rtl")}if(null!==l)for(var y=0;y<A.length;y++){var v=A[y];if(v.qname===F.textDecoration.qname){var b=l.styleAttrs[v.qname],q=c[v.qname],S=[];void 0===q?S=b:-1===q.indexOf("none")?((-1===q.indexOf("noUnderline")&&-1!==b.indexOf("underline")||-1!==q.indexOf("underline"))&&S.push("underline"),(-1===q.indexOf("noLineThrough")&&-1!==b.indexOf("lineThrough")||-1!==q.indexOf("lineThrough"))&&S.push("lineThrough"),(-1===q.indexOf("noOverline")&&-1!==b.indexOf("overline")||-1!==q.indexOf("overline"))&&S.push("overline")):S.push("none"),c[v.qname]=S}else if(v.qname!==F.fontSize.qname||v.qname in c||"span"!==h.kind||"textContainer"!==c[F.ruby.qname])if(v.qname!==F.fontSize.qname||v.qname in c||"span"!==h.kind||"text"!==c[F.ruby.qname])v.inherit&&v.qname in l.styleAttrs&&!(v.qname in c)&&(c[v.qname]=l.styleAttrs[v.qname]);else{var k=l.styleAttrs[F.fontSize.qname];"textContainer"===l.styleAttrs[F.ruby.qname]?c[v.qname]=k:c[v.qname]=new w(.5*k.rw,.5*k.rh)}else{var I=l.styleAttrs[F.fontSize.qname];c[v.qname]=new w(.5*I.rw,.5*I.rh)}}for(var C=0;C<A.length;C++){var _=A[C];if(!(_.qname in c)&&!(_.qname===F.position.qname&&F.origin.qname in c||_.qname===F.origin.qname&&F.position.qname in c)){var R=t.head.styling.initials[_.qname]||_.initial;if(null!==R&&("region"===h.kind||!1===_.inherit&&null!==R)){var L=_.parse(R);null!==L?(c[_.qname]=L,g[_.qname]=!0):r(a,"Invalid initial value for '"+_.qname+"' on element '"+h.kind)}}}for(var E=0;E<A.length;E++){var M=A[E];if(M.qname in g&&null!==M.compute){var T=M.compute(t,l,h,c[M.qname],u);null!==T?c[M.qname]=T:(c[M.qname]=M.compute(t,l,h,M.parse(M.initial),u),r(a,"Style '"+M.qname+"' on element '"+h.kind+"' cannot be computed"))}}if("none"===c[F.display.qname])return null;var O=null;null===l?O=null===i?[]:[i]:"contents"in s&&(O=s.contents);for(var P=0;null!==O&&P<O.length;P++){var D=It(t,e,n,i,h,f,O[P],a,u);null!==D&&h.contents.push(D.element)}for(var z in c)if(x(c,z)){var U=!1;if("span"===h.kind){var B=c[F.ruby.qname];(U=("container"===B||"textContainer"===B||"baseContainer"===B)&&-1!==kt.indexOf(z))||(U="container"!==B&&z===F.rubyAlign.qname),U||(U=!("textContainer"===B||"text"===B)&&z===F.rubyPosition.qname)}if(!U){var H=N[z];"applies"in H&&(U=-1===H.applies.indexOf(h.kind))}U&&delete c[z]}var j=c[F.ruby.qname];if("p"===h.kind||"span"===h.kind&&("textContainer"===j||"text"===j)){var $=[];Ct(h,$),function(t){function e(t){return"br"===t.kind||/[\r\n\t ]$/.test(t.text)}function n(t){return"br"===t.kind||"preserve"===t.space&&/^[\r\n]/.test(t.text)}for(var i,r=0;r<t.length;)if("br"!==(i=t[r]).kind&&"preserve"!==i.space){var l=i.text.replace(/[\t\r\n ]+/g," ");/^[ ]/.test(l)&&(0===r||e(t[r-1]))&&(l=l.substring(1)),i.text=l,0===l.length?t.splice(r,1):r++}else r++;for(r=0;r<t.length;r++)"br"!==(i=t[r]).kind&&"preserve"!==i.space?/[ ]$/.test(i.text)&&(r===t.length-1||n(t[r+1]))&&(i.text=i.text.slice(0,-1)):r++}($),_t(h)}return"div"===h.kind&&F.backgroundImage.qname in c||"br"===h.kind||"image"===h.kind||"contents"in h&&h.contents.length>0||"span"===h.kind&&null!==h.text||"region"===h.kind&&"always"===c[F.showBackground.qname]?{region_id:f,element:h}:null}function Ct(t,e){if("contents"in t)for(var n=0;n<t.contents.length;n++){var i=t.contents[n],r=i.styleAttrs[F.ruby.qname];("span"!==i.kind||"textContainer"!==r&&"text"!==r)&&("contents"in i?Ct(i,e):("span"===i.kind&&0!==i.text.length||"br"===i.kind)&&e.push(i))}}function _t(t){if("br"===t.kind)return!1;if("text"in t)return 0===t.text.length;if("contents"in t){for(var e=t.contents.length;e--;)_t(t.contents[e])&&t.contents.splice(e,1);return 0===t.contents.length}}var Rt=function(t){this.contents=[],this.aspectRatio=t.aspectRatio,this.lang=t.lang},Lt=function(t){for(var e in this.kind=t.kind||"region",this.lang=t.lang,t.id&&(this.id=t.id),this.styleAttrs={},t.styleAttrs)x(t.styleAttrs,e)&&(this.styleAttrs[e]=t.styleAttrs[e]);"src"in t&&(this.src=t.src),"type"in t&&(this.type=t.type),"text"in t?this.text=t.text:("region"===this.kind||"contents"in t)&&(this.contents=[]),"space"in t&&(this.space=t.space)};t.createSAXParserFromDOMParser=ft,t.fromXML=function(t,e,n,i){return void 0===i&&(i=ft()),I(t,e,n,i)},t.generateISD=function(t,e,n){var i=new Rt(t),r={},l={},o={},s=t.head.styling.initials[F.showBackground.qname],a=t.head.styling.initials[F.backgroundColor.qname],u=t.head.layout.regions;for(var f in u)if(x(u,f)){var h=u[f],c=h.styleAttrs[F.showBackground.qname]||s,d=h.styleAttrs[F.backgroundColor.qname]||a;o[h.id]=("always"===c||void 0===c)&&void 0!==d&&!(e<h.begin||e>=h.end)}for(var p in t.body&&t.body.regionID&&(o[t.body.regionID]=!0),l=null!==t.body?function t(e,n){if(n.contents){var i={};for(var r in n)x(n,r)&&(i[r]=n[r]);return i.contents=[],n.contents.filter(function(t){return!(e<t.begin||e>=t.end)}).forEach(function(n){var r=t(e,n);r.regionID&&(o[r.regionID]=!0),null!==r&&i.contents.push(r)}),i}return n}(e,t.body):null,void 0!==o[""]&&(o[""]=!0),o)if(o[p]){var g=It(t,e,t.head.layout.regions[p],l,null,"",t.head.layout.regions[p],n,r);null!==g&&i.contents.push(g.element)}return i},t.renderHTML=function(t,e,n,i,r,l,o,s,a){var u=i||e.clientHeight,f=r||e.clientWidth;if(null!==t.aspectRatio){var h=u*t.aspectRatio;h>f?u=Math.round(f/t.aspectRatio):f=h}var c=document.createElement("div");c.style.position="relative",c.style.width=f+"px",c.style.height=u+"px",c.style.margin="auto",c.style.top=0,c.style.bottom=0,c.style.left=0,c.style.right=0,c.style.zIndex=0;var d={h:u,w:f,regionH:null,regionW:null,imgResolver:n,displayForcedOnlyMode:l||!1,isd:t,errorHandler:o,previousISDState:s,enableRollUp:a||!1,currentISDState:{},flg:null,lp:null,mra:null,ipd:null,bpd:null,ruby:null,textEmphasis:null,rubyReserve:null};if(e.appendChild(c),"contents"in t)for(var p=0;p<t.contents.length;p++)ct(d,c,t.contents[p],t);return d.currentISDState}});
//# sourceMappingURL=imsc.all.min.js.map