UNPKG

imsc

Version:

Renders IMSC documents to HTML5 fragments

100 lines 55.5 kB
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(f,v,l){f!=Array.prototype&&f!=Object.prototype&&(f[v]=l.value)};$jscomp.getGlobal=function(f){return"undefined"!=typeof window&&window===f?f:"undefined"!=typeof global&&null!=global?global:f};$jscomp.global=$jscomp.getGlobal(this); $jscomp.polyfill=function(f,v,l,w){if(v){l=$jscomp.global;f=f.split(".");for(w=0;w<f.length-1;w++){var A=f[w];A in l||(l[A]={});l=l[A]}f=f[f.length-1];w=l[f];v=v(w);v!=w&&null!=v&&$jscomp.defineProperty(l,f,{configurable:!0,writable:!0,value:v})}};$jscomp.polyfill("Object.is",function(f){return f?f:function(f,l){return f===l?0!==f||1/f===1/l:f!==f&&l!==l}},"es6","es3"); $jscomp.polyfill("Array.prototype.includes",function(f){return f?f:function(f,l){var w=this;w instanceof String&&(w=String(w));var A=w.length;l=l||0;for(0>l&&(l=Math.max(l+A,0));l<A;l++){var m=w[l];if(m===f||Object.is(m,f))return!0}return!1}},"es7","es3"); $jscomp.checkStringArgs=function(f,v,l){if(null==f)throw new TypeError("The 'this' value for String.prototype."+l+" must not be null or undefined");if(v instanceof RegExp)throw new TypeError("First argument to String.prototype."+l+" must not be a regular expression");return f+""};$jscomp.polyfill("String.prototype.includes",function(f){return f?f:function(f,l){return-1!==$jscomp.checkStringArgs(this,f,"includes").indexOf(f,l||0)}},"es6","es3"); $jscomp.polyfill("Math.sign",function(f){return f?f:function(f){f=Number(f);return 0===f||isNaN(f)?f:0<f?1:-1}},"es6","es3"); (function(f){"object"===typeof exports&&"undefined"!==typeof module?module.exports=f():"function"===typeof define&&define.amd?define([],f):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).imsc=f()})(function(){return function(){function f(v,l,w){function A(n,J){if(!l[n]){if(!v[n]){var a="function"==typeof require&&require;if(!J&&a)return a(n,!0);if(m)return m(n,!0);J=Error("Cannot find module '"+n+"'");throw J.code="MODULE_NOT_FOUND",J;}J= l[n]={exports:{}};v[n][0].call(J.exports,function(a){return A(v[n][1][a]||a)},J,J.exports,f,v,l,w)}return l[n].exports}for(var m="function"==typeof require&&require,n=0;n<w.length;n++)A(w[n]);return A}return f}()({1:[function(f,v,l){(function(f,l,m,n,v){function w(b){if("contents"in b){var c="styleAttrs"in b?b.styleAttrs[n.byName.ruby.qname]:null;c="span"===b.kind&&("container"===c||"textContainer"===c||"baseContainer"===c);for(var a=b.contents.length-1;0<=a;a--)!c||"styleAttrs"in b.contents[a]&& n.byName.ruby.qname in b.contents[a].styleAttrs?w(b.contents[a]):delete b.contents[a]}}function a(b,c,d,e){var z=e&&"seq"===e.timeContainer,g=0;e&&(g=z&&d?d.end:e.begin);c.begin=c.explicit_begin?c.explicit_begin+g:g;d=c.begin;e=null;if("sets"in c)for(var k=0;k<c.sets.length;k++)a(b,c.sets[k],e,c),d="seq"===c.timeContainer?c.sets[k].end:Math.max(d,c.sets[k].end),e=c.sets[k];if(!("contents"in c))d=z?c.begin:Number.POSITIVE_INFINITY;else if("contents"in c)for(z=0;z<c.contents.length;z++)a(b,c.contents[z], e,c),d="seq"===c.timeContainer?c.contents[z].end:Math.max(d,c.contents[z].end),e=c.contents[z];c.end=null!==c.explicit_end&&null!==c.explicit_dur?Math.min(c.begin+c.explicit_dur,g+c.explicit_end):null===c.explicit_end&&null!==c.explicit_dur?c.begin+c.explicit_dur:null!==c.explicit_end&&null===c.explicit_dur?g+c.explicit_end:d;delete c.explicit_begin;delete c.explicit_dur;delete c.explicit_end;b._registerEvent(c)}function e(b){this.node=b}function p(){this.events=[];this.head=new g;this.body=null} function g(){this.styling=new G;this.layout=new L}function G(){this.styles={};this.initials={}}function y(){this.styleRefs=this.styleAttrs=this.id=null}function A(){this.styleAttrs=null}function L(){this.regions={}}function E(b,c){this.kind="image";this.src=b;this.type=c}function b(b){this.id=b}function k(b){this.regionID=b}function c(b){this.styleAttrs=b}function d(b){this.sets=b}function D(b){this.contents=b}function h(b,c,a){this.explicit_begin=b;this.explicit_end=c;this.explicit_dur=a}function O(){this.kind= "body"}function t(){this.kind="div"}function q(){this.kind="p"}function r(){this.kind="span"}function M(){this.kind="span"}function H(){this.kind="br"}function x(){}function T(){}function U(b){return b&&"xml:id"in b.attributes?b.attributes["xml:id"].value||null:null}function Q(b){return b&&"style"in b.attributes?b.attributes.style.value.split(" "):[]}function P(b,c){var a={};if(null!==b)for(var d in b.attributes){var e=b.attributes[d].uri+" "+b.attributes[d].local,g=n.byQName[e];if(void 0!==g){var k= g.parse(b.attributes[d].value);null!==k?(a[e]=k,g===n.byName.zIndex&&I(c,"zIndex attribute present but not used by IMSC1 since regions do not overlap")):F(c,"Cannot parse styling attribute "+e+" --\x3e "+b.attributes[d].value)}}return a}function K(b,c,a){for(var d in b.attributes)if(b.attributes[d].uri===c&&b.attributes[d].local===a)return b.attributes[d].value;return null}function Y(b,c){b=K(b,m.ns_tts,"extent");if(null===b)return null;var a=b.split(" ");if(2!==a.length)return I(c,"Malformed extent (ignoring)"), null;b=v.parseLength(a[0]);a=v.parseLength(a[1]);return a&&b?{h:a,w:b}:(I(c,"Malformed extent values (ignoring)"),null)}function R(b,c,a){var d=/^(\d{2,}):(\d\d):(\d\d(?:\.\d+)?)$/,e=/^(\d{2,}):(\d\d):(\d\d):(\d{2,})$/,g=/^(\d+(?:\.\d+)?)t$/,k=/^(\d+(?:\.\d+)?)ms$/,h=/^(\d+(?:\.\d+)?)s$/,z=/^(\d+(?:\.\d+)?)h$/,m=/^(\d+(?:\.\d+)?)m$/,u,p=null;null!==(u=/^(\d+(?:\.\d+)?)f$/.exec(a))?null!==c&&(p=parseFloat(u[1])/c):null!==(u=g.exec(a))?null!==b&&(p=parseFloat(u[1])/b):null!==(u=k.exec(a))?p=parseFloat(u[1])/ 1E3:null!==(u=h.exec(a))?p=parseFloat(u[1]):null!==(u=z.exec(a))?p=3600*parseFloat(u[1]):null!==(u=m.exec(a))?p=60*parseFloat(u[1]):null!==(u=d.exec(a))?p=3600*parseInt(u[1])+60*parseInt(u[2])+parseFloat(u[3]):null!==(u=e.exec(a))&&null!==c&&(p=3600*parseInt(u[1])+60*parseInt(u[2])+parseInt(u[3])+(null===u[4]?0:parseInt(u[4])/c));return p}function V(b,c,a){for(;0<c.styleRefs.length;){var d=c.styleRefs.pop();d in b.styles?(V(b,b.styles[d],a),S(b.styles[d].styleAttrs,c.styleAttrs)):F(a,"Non-existant style id referenced")}} function W(b,c,a,d){for(var e=c.length-1;0<=e;e--){var g=c[e];g in b.styles?S(b.styles[g].styleAttrs,a):F(d,"Non-existant style id referenced")}}function S(b,c){for(var a in b)b.hasOwnProperty(a)&&(a in c||(c[a]=b[a]))}function I(b,c){if(b&&b.warn&&b.warn(c))throw c;}function F(b,c){if(b&&b.error&&b.error(c))throw c;}function C(b,c){b&&b.fatal&&b.fatal(c);throw c;}function X(b,c){for(var a=0,d=b.length-1,e;a<=d;){e=Math.floor((a+d)/2);var g=b[e];if(g<c)a=e+1;else if(g>c)d=e-1;else return{found:!0, index:e}}return{found:!1,index:a}}f.fromXML=function(b,c,d){var k=l.parser(!0,{xmlns:!0}),h=[],z=[],D=[],f=0,u=null;k.onclosetag=function(b){if(h[0]instanceof x)null!==u.head&&null!==u.head.styling&&W(u.head.styling,h[0].styleRefs,h[0].styleAttrs,c),delete h[0].styleRefs;else if(h[0]instanceof G)for(var a in h[0].styles)h[0].styles.hasOwnProperty(a)&&V(h[0],h[0].styles[a],c);else if(h[0]instanceof q||h[0]instanceof r){if(1<h[0].contents.length){b=[h[0].contents[0]];for(a=1;a<h[0].contents.length;a++)h[0].contents[a]instanceof M&&b[b.length-1]instanceof M?b[b.length-1].text+=h[0].contents[a].text:b.push(h[0].contents[a]);h[0].contents=b}h[0]instanceof r&&1===h[0].contents.length&&h[0].contents[0]instanceof M&&(h[0].text=h[0].contents[0].text,delete h[0].contents)}else if(h[0]instanceof e)if(h[0].node.uri===m.ns_tt&&"metadata"===h[0].node.local)f--;else if(0<f&&d&&"onCloseTag"in d)d.onCloseTag();D.shift();z.shift();h.shift()};k.ontext=function(b){if(void 0!==h[0])if(h[0]instanceof r||h[0]instanceof q){if(h[0]instanceof r){var a= h[0].styleAttrs[n.byName.ruby.qname];if("container"===a||"textContainer"===a||"baseContainer"===a)return}a=new M;a.initFromText(u,h[0],b,z[0],D[0],c);h[0].contents.push(a)}else if(h[0]instanceof e&&0<f&&d&&"onText"in d)d.onText(b)};k.onopentag=function(b){var a=b.attributes["xml:space"];a?D.unshift(a.value):0===D.length?D.unshift("default"):D.unshift(D[0]);(a=b.attributes["xml:lang"])?z.unshift(a.value):0===z.length?z.unshift(""):z.unshift(z[0]);if(b.uri===m.ns_tt)if("tt"===b.local)null!==u&&C(c, "Two <tt> elements at ("+this.line+","+this.column+")"),u=new p,u.initFromNode(b,z[0],c),h.unshift(u);else if("head"===b.local)h[0]instanceof p||C(c,"Parent of <head> element is not <tt> at ("+this.line+","+this.column+")"),h.unshift(u.head);else if("styling"===b.local)h[0]instanceof g||C(c,"Parent of <styling> element is not <head> at ("+this.line+","+this.column+")"),h.unshift(u.head.styling);else if("style"===b.local)if(h[0]instanceof G){var k=new y;k.initFromNode(b,c);k.id?u.head.styling.styles[k.id]= k:F(c,"<style> element missing @id attribute");h.unshift(k)}else h[0]instanceof x?(k=new y,k.initFromNode(b,c),S(k.styleAttrs,h[0].styleAttrs),h.unshift(k)):C(c,"Parent of <style> element is not <styling> or <region> at ("+this.line+","+this.column+")");else if("initial"===b.local)if(h[0]instanceof G){a=new A;a.initFromNode(b,c);for(k in a.styleAttrs)a.styleAttrs.hasOwnProperty(k)&&(u.head.styling.initials[k]=a.styleAttrs[k]);h.unshift(a)}else C(c,"Parent of <initial> element is not <styling> at ("+ this.line+","+this.column+")");else if("layout"===b.local)h[0]instanceof g||C(c,"Parent of <layout> element is not <head> at "+this.line+","+this.column+")"),h.unshift(u.head.layout);else if("region"===b.local)h[0]instanceof L||C(c,"Parent of <region> element is not <layout> at "+this.line+","+this.column+")"),k=new x,k.initFromNode(u,b,z[0],c),!k.id||k.id in u.head.layout.regions?F(c,"Ignoring <region> with duplicate or missing @id at "+this.line+","+this.column+")"):u.head.layout.regions[k.id]= k,h.unshift(k);else if("body"===b.local)h[0]instanceof p||C(c,"Parent of <body> element is not <tt> at "+this.line+","+this.column+")"),null!==u.body&&C(c,"Second <body> element at "+this.line+","+this.column+")"),k=new O,k.initFromNode(u,b,z[0],c),u.body=k,h.unshift(k);else if("div"===b.local){h[0]instanceof t||h[0]instanceof O||C(c,"Parent of <div> element is not <body> or <div> at "+this.line+","+this.column+")");k=new t;k.initFromNode(u,h[0],b,z[0],c);if(a=k.styleAttrs[n.byName.backgroundImage.qname])k.contents.push(new E(a)), delete k.styleAttrs[n.byName.backgroundImage.qname];h[0].contents.push(k);h.unshift(k)}else"image"===b.local?(h[0]instanceof t||C(c,"Parent of <image> element is not <div> at "+this.line+","+this.column+")"),k=new E,k.initFromNode(u,h[0],b,z[0],c),h[0].contents.push(k),h.unshift(k)):"p"===b.local?(h[0]instanceof t||C(c,"Parent of <p> element is not <div> at "+this.line+","+this.column+")"),k=new q,k.initFromNode(u,h[0],b,z[0],c),h[0].contents.push(k),h.unshift(k)):"span"===b.local?(h[0]instanceof r||h[0]instanceof q||C(c,"Parent of <span> element is not <span> or <p> at "+this.line+","+this.column+")"),k=new r,k.initFromNode(u,h[0],b,z[0],D[0],c),h[0].contents.push(k),h.unshift(k)):"br"===b.local?(h[0]instanceof r||h[0]instanceof q||C(c,"Parent of <br> element is not <span> or <p> at "+this.line+","+this.column+")"),k=new H,k.initFromNode(u,h[0],b,z[0],c),h[0].contents.push(k),h.unshift(k)):"set"===b.local?(h[0]instanceof r||h[0]instanceof q||h[0]instanceof t||h[0]instanceof O||h[0]instanceof x||h[0]instanceof H||C(c,"Parent of <set> element is not a content element or a region at "+this.line+","+this.column+")"),k=new T,k.initFromNode(u,h[0],b,c),h[0].sets.push(k),h.unshift(k)):h.unshift(new e(b));else h.unshift(new e(b));if(h[0]instanceof e)if(b.uri===m.ns_tt&&"metadata"===b.local)f++;else if(0<f&&d&&"onOpenTag"in d){k=[];for(var w in b.attributes)k[b.attributes[w].uri+" "+b.attributes[w].local]={uri:b.attributes[w].uri,local:b.attributes[w].local,value:b.attributes[w].value};d.onOpenTag(b.uri, b.local,k)}};k.write(b).close();delete u.head.styling.styles;b=!1;for(var N in u.head.layout.regions)if(u.head.layout.regions.hasOwnProperty(N)){b=!0;break}b||(N=x.prototype.createDefaultRegion(u.lang),u.head.layout.regions[N.id]=N);for(var B in u.head.layout.regions)u.head.layout.regions.hasOwnProperty(B)&&a(u,u.head.layout.regions[B],null,null);u.body&&a(u,u.body,null,null);u.body&&w(u.body);return u};p.prototype.initFromNode=function(b,c,a){var d=K(b,m.ns_ttp,"cellResolution"),h=15;var k=32;null!== d&&(d=/(\d+) (\d+)/.exec(d),null!==d?(k=parseInt(d[1]),h=parseInt(d[2])):I(a,"Malformed cellResolution value (using initial value instead)"));this.cellLength={h:new v.ComputedLength(0,1/h),w:new v.ComputedLength(1/k,0)};h=K(b,m.ns_ttp,"frameRate");d=30;null!==h&&(k=/(\d+)/.exec(h),null!==k?d=parseInt(k[1]):I(a,"Malformed frame rate attribute (using initial value instead)"));k=K(b,m.ns_ttp,"frameRateMultiplier");var e=1;null!==k&&(k=/(\d+) (\d+)/.exec(k),null!==k?e=parseInt(k[1])/parseInt(k[2]):I(a, "Malformed frame rate multiplier attribute (using initial value instead)"));d*=e;e=1;k=K(b,m.ns_ttp,"tickRate");null===k?null!==h&&(e=d):(k=/(\d+)/.exec(k),null!==k?e=parseInt(k[1]):I(a,"Malformed tick rate attribute (using initial value instead)"));this.effectiveFrameRate=d;this.tickRate=e;k=K(b,m.ns_ittp,"aspectRatio");null===k&&(k=K(b,m.ns_ttp,"displayAspectRatio"));h=null;null!==k&&(d=/(\d+)\s+(\d+)/.exec(k),null!==d?(k=parseInt(d[1]),d=parseInt(d[2]),0!==k&&0!==d?h=k/d:F(a,"Illegal aspectRatio values (ignoring)")): F(a,"Malformed aspectRatio attribute (ignoring)"));this.aspectRatio=h;h=K(b,m.ns_ttp,"timeBase");null!==h&&"media"!==h&&C(a,"Unsupported time base");b=Y(b,a);null===b?this.pxLength={h:null,w:null}:("px"===b.h.unit&&"px"===b.w.unit||C(a,"Extent on TT must be in px or absent"),this.pxLength={h:new v.ComputedLength(0,1/b.h.value),w:new v.ComputedLength(1/b.w.value,0)});this.dimensions={h:new v.ComputedLength(0,1),w:new v.ComputedLength(1,0)};this.lang=c};p.prototype._registerEvent=function(b){if(!(b.end<= b.begin)){var c=X(this.events,b.begin);c.found||this.events.splice(c.index,0,b.begin);b.end!==Number.POSITIVE_INFINITY&&(c=X(this.events,b.end),c.found||this.events.splice(c.index,0,b.end))}};p.prototype.getMediaTimeRange=function(){return[this.events[0],this.events[this.events.length-1]]};p.prototype.getMediaTimeEvents=function(){return this.events};y.prototype.initFromNode=function(b,c){this.id=U(b);this.styleAttrs=P(b,c);this.styleRefs=Q(b)};A.prototype.initFromNode=function(b,c){this.styleAttrs= {};for(var a in b.attributes)if(b.attributes[a].uri===m.ns_itts||b.attributes[a].uri===m.ns_ebutts||b.attributes[a].uri===m.ns_tts)this.styleAttrs[b.attributes[a].uri+" "+b.attributes[a].local]=b.attributes[a].value};E.prototype.initFromNode=function(b,a,e,g,p){(this.src="src"in e.attributes?e.attributes.src.value:null)||F(p,"Invalid image@src attribute");(this.type="type"in e.attributes?e.attributes.type.value:null)||F(p,"Invalid image@type attribute");c.prototype.initFromNode.call(this,b,a,e,p); h.prototype.initFromNode.call(this,b,a,e,p);d.prototype.initFromNode.call(this,b,a,e,p);k.prototype.initFromNode.call(this,b,a,e,p);this.lang=g};b.prototype.initFromNode=function(b,c,a,d){this.id=U(a)};k.prototype.initFromNode=function(b,c,a,d){this.regionID=a&&"region"in a.attributes?a.attributes.region.value:""};c.prototype.initFromNode=function(b,c,a,d){this.styleAttrs=P(a,d);null!==b.head&&null!==b.head.styling&&W(b.head.styling,Q(a),this.styleAttrs,d)};d.prototype.initFromNode=function(b,c,a, d){this.sets=[]};D.prototype.initFromNode=function(b,c,a,d){this.contents=[]};h.prototype.initFromNode=function(b,c,a,d){c=null;a&&"begin"in a.attributes&&(c=R(b.tickRate,b.effectiveFrameRate,a.attributes.begin.value),null===c&&I(d,"Malformed begin value "+a.attributes.begin.value+" (using 0)"));var k=null;a&&"dur"in a.attributes&&(k=R(b.tickRate,b.effectiveFrameRate,a.attributes.dur.value),null===k&&I(d,"Malformed dur value "+a.attributes.dur.value+" (ignoring)"));var h=null;a&&"end"in a.attributes&& (h=R(b.tickRate,b.effectiveFrameRate,a.attributes.end.value),null===h&&I(d,"Malformed end value (ignoring)"));this.explicit_begin=c;this.explicit_end=h;this.explicit_dur=k;(b=a&&"timeContainer"in a.attributes?a.attributes.timeContainer.value:null)&&"par"!==b?"seq"===b?d="seq":(F(d,"Illegal value of timeContainer (assuming 'par')"),d="par"):d="par";this.timeContainer=d};O.prototype.initFromNode=function(b,a,e,g){c.prototype.initFromNode.call(this,b,null,a,g);h.prototype.initFromNode.call(this,b,null, a,g);d.prototype.initFromNode.call(this,b,null,a,g);k.prototype.initFromNode.call(this,b,null,a,g);D.prototype.initFromNode.call(this,b,null,a,g);this.lang=e};t.prototype.initFromNode=function(b,a,e,g,p){c.prototype.initFromNode.call(this,b,a,e,p);h.prototype.initFromNode.call(this,b,a,e,p);d.prototype.initFromNode.call(this,b,a,e,p);k.prototype.initFromNode.call(this,b,a,e,p);D.prototype.initFromNode.call(this,b,a,e,p);this.lang=g};q.prototype.initFromNode=function(b,a,e,g,p){c.prototype.initFromNode.call(this, b,a,e,p);h.prototype.initFromNode.call(this,b,a,e,p);d.prototype.initFromNode.call(this,b,a,e,p);k.prototype.initFromNode.call(this,b,a,e,p);D.prototype.initFromNode.call(this,b,a,e,p);this.lang=g};r.prototype.initFromNode=function(b,a,e,g,p,m){c.prototype.initFromNode.call(this,b,a,e,m);h.prototype.initFromNode.call(this,b,a,e,m);d.prototype.initFromNode.call(this,b,a,e,m);k.prototype.initFromNode.call(this,b,a,e,m);D.prototype.initFromNode.call(this,b,a,e,m);this.space=p;this.lang=g};M.prototype.initFromText= function(b,a,c,d,k,e){h.prototype.initFromNode.call(this,b,a,null,e);this.text=c;this.space=k;this.lang=d};H.prototype.initFromNode=function(b,a,c,d,e){k.prototype.initFromNode.call(this,b,a,c,e);h.prototype.initFromNode.call(this,b,a,c,e);this.lang=d};x.prototype.createDefaultRegion=function(b){var a=new x;a.id="";a.styleAttrs={};a.sets=[];h.call(a,0,Number.POSITIVE_INFINITY,null);this.lang=b;return a};x.prototype.initFromNode=function(a,c,k,e){b.prototype.initFromNode.call(this,a,null,c,e);h.prototype.initFromNode.call(this, a,null,c,e);d.prototype.initFromNode.call(this,a,null,c,e);this.styleAttrs=P(c,e);this.styleRefs=Q(c);this.lang=k};T.prototype.initFromNode=function(b,a,c,d){h.prototype.initFromNode.call(this,b,a,c,d);b=P(c,d);this.value=this.qname=null;for(var k in b)if(b.hasOwnProperty(k)){if(this.qname){F(d,"More than one style specified on set");break}this.qname=k;this.value=b[k]}}})("undefined"===typeof l?this.imscDoc={}:l,"undefined"===typeof sax?f("sax"):sax,"undefined"===typeof imscNames?f("./names"):imscNames, "undefined"===typeof imscStyles?f("./styles"):imscStyles,"undefined"===typeof imscUtils?f("./utils"):imscUtils)},{"./names":5,"./styles":6,"./utils":7,sax:void 0}],2:[function(f,v,l){(function(f,l,m){function w(b,k,c,d){if("region"===c.kind){var g=document.createElement("div");g.style.position="absolute"}else if("body"===c.kind)g=document.createElement("div");else if("div"===c.kind)g=document.createElement("div");else if("image"===c.kind){if(g=document.createElement("img"),null!==b.imgResolver&&null!== c.src){var h=b.imgResolver(c.src,g);h&&(g.src=h);g.height=b.regionH;g.width=b.regionW}}else if("p"===c.kind)g=document.createElement("p");else if("span"===c.kind)if("container"===c.styleAttrs[m.byName.ruby.qname])g=document.createElement("ruby"),b.ruby=!0;else if("base"===c.styleAttrs[m.byName.ruby.qname])g=document.createElement("rb");else if("text"===c.styleAttrs[m.byName.ruby.qname])g=document.createElement("rt");else if("baseContainer"===c.styleAttrs[m.byName.ruby.qname])g=document.createElement("rbc"); else if("textContainer"===c.styleAttrs[m.byName.ruby.qname])g=document.createElement("rtc");else{if("delimiter"===c.styleAttrs[m.byName.ruby.qname])return;g=document.createElement("span")}else"br"===c.kind&&(g=document.createElement("br"));if(g){!c.lang||"region"!==c.kind&&c.lang===d.lang||(g.lang=c.lang);k.appendChild(g);g.style.margin="0";if("region"===c.kind)if(k=c.styleAttrs[m.byName.writingMode.qname],"lrtb"===k||"lr"===k)b.ipd="lr",b.bpd="tb";else if("rltb"===k||"rl"===k)b.ipd="rl",b.bpd="tb"; else if("tblr"===k)b.ipd="tb",b.bpd="lr";else{if("tbrl"===k||"tb"===k)b.ipd="tb",b.bpd="rl"}else"p"===c.kind&&"tb"===b.bpd&&(b.ipd="ltr"===c.styleAttrs[m.byName.direction.qname]?"lr":"rl");for(k=0;k<G.length;k++)d=G[k],h=c.styleAttrs[d.qname],void 0!==h&&null!==d.map&&d.map(b,g,c,h);k=g;(d=c.styleAttrs[m.byName.linePadding.qname])&&!d.isZero()&&(h=d.toUsedLength(b.w,b.h),0<h&&(h=Math.ceil(h)+"px","tb"===b.bpd?(k.style.paddingLeft=h,k.style.paddingRight=h):(k.style.paddingTop=h,k.style.paddingBottom= h),b.lp=d));(d=c.styleAttrs[m.byName.multiRowAlign.qname])&&"auto"!==d&&(k=document.createElement("span"),k.style.display="inline-block",k.style.textAlign=d,g.appendChild(k),b.mra=d);(d=c.styleAttrs[m.byName.rubyReserve.qname])&&"none"!==d[0]&&(b.rubyReserve=d);c.styleAttrs[m.byName.fillLineGap.qname]&&(b.flg=!0);if("span"===c.kind&&c.text)if((d=c.styleAttrs[m.byName.textEmphasis.qname])&&"none"!==d.style&&(b.textEmphasis=!0),m.byName.textCombine.qname in c.styleAttrs&&"all"===c.styleAttrs[m.byName.textCombine.qname])g.textContent= c.text,d&&p(b,g,c,d);else{h="";for(var f=0;f<c.text.length;f++){h+=c.text.charAt(f);var t=c.text.charCodeAt(f);if(55296>t||56319<t||f===c.text.length-1)t=document.createElement("span"),t.textContent=h,d&&p(b,t,c,d),g.appendChild(t),h="",t._isd_element=c}}if("contents"in c)for(d=0;d<c.contents.length;d++)w(b,k,c.contents[d],c);d=[];if("p"===c.kind){e(b,k,d,null);if(b.rubyReserve){for(h=0;h<d.length;h++){f=document.createElement("ruby");t=document.createElement("rb");t.textContent="\u200b";f.appendChild(t); var q=b.rubyReserve[1].toUsedLength(b.w,b.h)+"px";if("both"===b.rubyReserve[0]||"outside"===b.rubyReserve[0]&&1==d.length){t=document.createElement("rtc");t.style[B]=y?"after":"under";t.textContent="\u200b";t.style.fontSize=q;var r=document.createElement("rtc");r.style[B]=y?"before":"over";r.textContent="\u200b";r.style.fontSize=q;f.appendChild(t);f.appendChild(r)}else t=document.createElement("rtc"),t.textContent="\u200b",t.style.fontSize=q,t.style[B]="after"===b.rubyReserve[0]||"outside"===b.rubyReserve[0]&& 0<h?y?"after":"tb"===b.bpd||"rl"===b.bpd?"under":"over":y?"before":"tb"===b.bpd||"rl"===b.bpd?"over":"under",f.appendChild(t);t=null;for(r=0;r<d[h].rbc.length;r++)if("ruby"===d[h].rbc[r].localName){t=d[h].rbc[r];for(r=0;r<t.style.length;r++)f.style.setProperty(t.style.item(r),t.style.getPropertyValue(t.style.item(r)));break}t=t||d[h].elements[0].node;t.parentElement.insertBefore(f,t)}b.rubyReserve=null}if(b.ruby||b.rubyReserve){for(h=0;h<d.length;h++)for(f=0;f<d[h].rbc.length;f++)d[h].rbc[f].style[B]|| (d[h].rbc[f].style[B]=y?0===h?"before":"after":"tb"===b.bpd?0===h?"over":"under":"rl"===b.bpd?0===h?"over":"under":0===h?"under":"over");b.ruby=null}if(b.textEmphasis){for(h=0;h<d.length;h++)for(f=0;f<d[h].te.length;f++)d[h].te[f].style[E]&&"none"!==d[h].te[f].style[E]||(d[h].te[f].style[E]="tb"===b.bpd?0===h?"left over":"left under":"rl"===b.bpd?0===h?"right under":"left under":0===h?"left under":"right under");b.textEmphasis=null}if(b.mra){for(h=0;h<d.length-1;h++)t=d[h].elements.length,0!==t&& !1===d[h].br&&(f=document.createElement("br"),t=d[h].elements[t-1].node,t.parentElement.insertBefore(f,t.nextSibling));b.mra=null}if(b.lp){h=b.lp.toUsedLength(b.w,b.h);if(null!==d)for(f=0;f<d.length;f++)if(t=Math.ceil(h)+"px",r="-"+Math.ceil(h)+"px",0!==d[f].elements.length){q=d[f].elements[d[f].start_elem];var n=d[f].elements[d[f].end_elem];if(q===n&&(elementBoundingRect=q.node.getBoundingClientRect(),0==elementBoundingRect.width||0==elementBoundingRect.height))continue;"lr"===b.ipd?(q.node.style.marginLeft= r,q.node.style.paddingLeft=t):"rl"===b.ipd?(q.node.style.paddingRight=t,q.node.style.marginRight=r):"tb"===b.ipd&&(q.node.style.paddingTop=t,q.node.style.marginTop=r);"lr"===b.ipd?(n.node.style.marginRight=r,n.node.style.paddingRight=t):"rl"===b.ipd?(n.node.style.paddingLeft=t,n.node.style.marginLeft=r):"tb"===b.ipd&&(n.node.style.paddingBottom=t,n.node.style.marginBottom=r)}b.lp=null}for(h=0;h<d.length;h++)for(f=d[h],t=1;t<f.elements.length;){r=f.elements[t-1].node;q=f.elements[t].node;if("SPAN"=== r.tagName&&"SPAN"===q.tagName&&r._isd_element===q._isd_element){r.textContent+=q.textContent;for(n=0;n<q.style.length;n++){var l=q.style[n];if(0<=l.indexOf("border")||0<=l.indexOf("padding")||0<=l.indexOf("margin"))r.style[l]=q.style[l]}q.parentElement.removeChild(q);r=!0}else r=!1;r?f.elements.splice(t,1):t++}h=[];for(r=0;r<d.length;r++)for(q=0;q<d[r].elements.length;q++)if(f=d[r].elements[q].node,t=A(f,h,!1))f.style.backgroundColor=t;for(f=0;f<h.length;f++)h[f].style.backgroundColor="";if(b.flg){f= a(k.getBoundingClientRect(),b);h=f.before;f=f.after;t=Math.sign(f-h);for(r=0;r<=d.length;r++){q=0===r?Math.round(h):r===d.length?Math.round(f):Math.round((d[r-1].after+d[r].before)/2);if(0<r&&d[r-1])for(l=0;l<d[r-1].elements.length;l++){var x=d[r-1].elements[l];n=t*(q-x.after)+"px";"lr"===b.bpd?x.node.style.paddingRight=n:"rl"===b.bpd?x.node.style.paddingLeft=n:"tb"===b.bpd&&(x.node.style.paddingBottom=n)}if(r<d.length)for(l=0;l<d[r].elements.length;l++)x=d[r].elements[l],n=t*(x.before-q)+"px","lr"=== b.bpd?x.node.style.paddingLeft=n:"rl"===b.bpd?x.node.style.paddingRight=n:"tb"===b.bpd&&(x.node.style.paddingTop=n)}b.flg=null}}"region"===c.kind&&"tb"===b.bpd&&b.enableRollUp&&0<c.contents.length&&"after"===c.styleAttrs[m.byName.displayAlign.qname]&&(e(b,k,d,null),c=new v(""===c.id?"_":c.id,d),b.currentISDState[c.id]=c,b.previousISDState&&c.id in b.previousISDState&&0<b.previousISDState[c.id].plist.length&&1<c.plist.length&&c.plist[c.plist.length-2].text===b.previousISDState[c.id].plist[b.previousISDState[c.id].plist.length- 1].text&&(b=g.firstElementChild,c=c.plist[c.plist.length-1].after-c.plist[c.plist.length-1].before,b.style.bottom="-"+c+"px",b.style.transition="transform 0.4s",b.style.position="relative",b.style.transform="translateY(-"+c+"px)"))}else if(b=b.errorHandler,c="Error processing ISD element kind: "+c.kind,b&&b.error&&b.error(c))throw c;}function A(b,a,c){if(b.style.backgroundColor)return c&&!a.includes(b)&&a.push(b),b.style.backgroundColor;if("SPAN"===b.parentElement.nodeName)return A(b.parentElement, a,!0)}function v(b,a){this.id=b;this.plist=a}function a(b,a){var c={before:null,after:null,start:null,end:null};"tb"===a.bpd?(c.before=b.top,c.after=b.bottom,"lr"===a.ipd?(c.start=b.left,c.end=b.right):(c.start=b.right,c.end=b.left)):"lr"===a.bpd?(c.before=b.left,c.after=b.right,c.start=b.top,c.end=b.bottom):"rl"===a.bpd&&(c.before=b.right,c.after=b.left,c.start=b.top,c.end=b.bottom);return c}function e(b,k,c,d){if("rt"!==k.localName&&"rtc"!==k.localName)if(d=k.style.backgroundColor||d,0===k.childElementCount)if("span"=== k.localName||"rb"===k.localName){var g=k.getBoundingClientRect();b=a(g,b);if(!(g=0===c.length)){g=b.before;var h=b.after,f=c[c.length-1].before,p=c[c.length-1].after;g=!(h<p&&g>f||p<=h&&f>=g)}g?c.push({before:b.before,after:b.after,start:b.start,end:b.end,start_elem:0,end_elem:0,elements:[],rbc:[],te:[],text:"",br:!1}):(g=Math.sign(b.after-b.before),h=Math.sign(b.end-b.start),0>g*(b.before-c[c.length-1].before)&&(c[c.length-1].before=b.before),0<g*(b.after-c[c.length-1].after)&&(c[c.length-1].after= b.after),0>h*(b.start-c[c.length-1].start)&&(c[c.length-1].start=b.start,c[c.length-1].start_elem=c[c.length-1].elements.length),0<h*(b.end-c[c.length-1].end)&&(c[c.length-1].end=b.end,c[c.length-1].end_elem=c[c.length-1].elements.length));c[c.length-1].text+=k.textContent;c[c.length-1].elements.push({node:k,bgcolor:d,before:b.before,after:b.after})}else"br"===k.localName&&0!==c.length&&(c[c.length-1].br=!0);else for(k=k.firstChild;k;)k.nodeType===Node.ELEMENT_NODE&&(e(b,k,c,d),"ruby"===k.localName|| "rtc"===k.localName?0<c.length&&c[c.length-1].rbc.push(k):"span"===k.localName&&k.style[L]&&"none"!==k.style[L]&&0<c.length&&c[c.length-1].te.push(k)),k=k.nextSibling}function p(b,a,c,d){"none"!==d.style&&(a.style[L]="auto"===d.style?"filled":d.style+" "+d.symbol,"before"===d.position||"after"===d.position)&&(a.style[E]="tb"===b.bpd?"before"===d.position?"left over":"left under":"rl"===b.bpd?"before"===d.position?"right under":"left under":"before"===d.position?"left under":"right under")}function g(b, a){this.qname=b;this.map=a}f.render=function(b,a,c,d,e,h,g,f,p){d=d||a.clientHeight;var k=e||a.clientWidth;null!==b.aspectRatio&&(e=d*b.aspectRatio,e>k?d=Math.round(k/b.aspectRatio):k=e);e=document.createElement("div");e.style.position="relative";e.style.width=k+"px";e.style.height=d+"px";e.style.margin="auto";e.style.top=0;e.style.bottom=0;e.style.left=0;e.style.right=0;e.style.zIndex=0;c={h:d,w:k,regionH:null,regionW:null,imgResolver:c,displayForcedOnlyMode:h||!1,isd:b,errorHandler:g,previousISDState:f, enableRollUp:p||!1,currentISDState:{},flg:null,lp:null,mra:null,ipd:null,bpd:null,ruby:null,textEmphasis:null,rubyReserve:null};a.appendChild(e);if("contents"in b)for(a=0;a<b.contents.length;a++)w(c,e,b.contents[a],b);return c.currentISDState};var G=[new g("http://www.w3.org/ns/ttml#styling backgroundColor",function(b,a,c,d){0!==d[3]&&(a.style.backgroundColor="rgba("+d[0].toString()+","+d[1].toString()+","+d[2].toString()+","+(d[3]/255).toString()+")")}),new g("http://www.w3.org/ns/ttml#styling color", function(b,a,c,d){a.style.color="rgba("+d[0].toString()+","+d[1].toString()+","+d[2].toString()+","+(d[3]/255).toString()+")"}),new g("http://www.w3.org/ns/ttml#styling direction",function(b,a,c,d){a.style.direction=d}),new g("http://www.w3.org/ns/ttml#styling display",function(b,a,c,d){}),new g("http://www.w3.org/ns/ttml#styling displayAlign",function(b,a,c,d){a.style.display="flex";a.style.flexDirection="column";"before"===d?a.style.justifyContent="flex-start":"center"===d?a.style.justifyContent= "center":"after"===d&&(a.style.justifyContent="flex-end")}),new g("http://www.w3.org/ns/ttml#styling extent",function(b,a,c,d){b.regionH=d.h.toUsedLength(b.w,b.h);b.regionW=d.w.toUsedLength(b.w,b.h);var e=d=0;if(c=c.styleAttrs["http://www.w3.org/ns/ttml#styling padding"])d=c[0].toUsedLength(b.w,b.h)+c[2].toUsedLength(b.w,b.h),e=c[1].toUsedLength(b.w,b.h)+c[3].toUsedLength(b.w,b.h);a.style.height=b.regionH-d+"px";a.style.width=b.regionW-e+"px"}),new g("http://www.w3.org/ns/ttml#styling fontFamily", function(b,a,c,d){b=[];for(c=0;c<d.length;c++)"monospaceSerif"===d[c]?(b.push("Courier New"),b.push('"Liberation Mono"'),b.push("Courier"),b.push("monospace")):"proportionalSansSerif"===d[c]?(b.push("Arial"),b.push("Helvetica"),b.push('"Liberation Sans"'),b.push("sans-serif")):"monospace"===d[c]?b.push("monospace"):"sansSerif"===d[c]?b.push("sans-serif"):"serif"===d[c]?b.push("serif"):"monospaceSansSerif"===d[c]?(b.push("Consolas"),b.push("monospace")):"proportionalSerif"===d[c]?b.push("serif"):b.push(d[c]); if(0<b.length){d=[b[0]];for(c=1;c<b.length;c++)-1==d.indexOf(b[c])&&d.push(b[c]);b=d}a.style.fontFamily=b.join(",")}),new g("http://www.w3.org/ns/ttml#styling shear",function(b,a,c,d){0!==d&&(c=-.9*d,a.style.transform="tb"===b.bpd?"skewX("+c+"deg)":"skewY("+c+"deg)")}),new g("http://www.w3.org/ns/ttml#styling fontSize",function(b,a,c,d){a.style.fontSize=d.toUsedLength(b.w,b.h)+"px"}),new g("http://www.w3.org/ns/ttml#styling fontStyle",function(b,a,c,d){a.style.fontStyle=d}),new g("http://www.w3.org/ns/ttml#styling fontWeight", function(b,a,c,d){a.style.fontWeight=d}),new g("http://www.w3.org/ns/ttml#styling lineHeight",function(b,a,c,d){a.style.lineHeight="normal"===d?"normal":d.toUsedLength(b.w,b.h)+"px"}),new g("http://www.w3.org/ns/ttml#styling opacity",function(b,a,c,d){a.style.opacity=d}),new g("http://www.w3.org/ns/ttml#styling origin",function(b,a,c,d){a.style.top=d.h.toUsedLength(b.w,b.h)+"px";a.style.left=d.w.toUsedLength(b.w,b.h)+"px"}),new g("http://www.w3.org/ns/ttml#styling overflow",function(b,a,c,d){a.style.overflow= d}),new g("http://www.w3.org/ns/ttml#styling padding",function(b,a,c,d){c=[];c[0]=d[0].toUsedLength(b.w,b.h)+"px";c[1]=d[3].toUsedLength(b.w,b.h)+"px";c[2]=d[2].toUsedLength(b.w,b.h)+"px";c[3]=d[1].toUsedLength(b.w,b.h)+"px";a.style.padding=c.join(" ")}),new g("http://www.w3.org/ns/ttml#styling position",function(b,a,c,d){a.style.top=d.h.toUsedLength(b.w,b.h)+"px";a.style.left=d.w.toUsedLength(b.w,b.h)+"px"}),new g("http://www.w3.org/ns/ttml#styling rubyAlign",function(b,a,c,d){a.style.rubyAlign= "spaceAround"===d?"space-around":"center"}),new g("http://www.w3.org/ns/ttml#styling rubyPosition",function(b,a,c,d){if("before"===d||"after"===d)a.parentElement.style[B]=y?d:"tb"===b.bpd?"before"===d?"over":"under":"rl"===b.bpd?"before"===d?"over":"under":"before"===d?"under":"over"}),new g("http://www.w3.org/ns/ttml#styling showBackground",null),new g("http://www.w3.org/ns/ttml#styling textAlign",function(b,a,c,d){a.style.textAlign="start"===d?"rl"===b.ipd?"right":"left":"end"===d?"rl"===b.ipd? "left":"right":d}),new g("http://www.w3.org/ns/ttml#styling textDecoration",function(b,a,c,d){a.style.textDecoration=d.join(" ").replace("lineThrough","line-through")}),new g("http://www.w3.org/ns/ttml#styling textOutline",function(b,a,c,d){}),new g("http://www.w3.org/ns/ttml#styling textShadow",function(b,a,c,d){var e=c.styleAttrs[m.byName.textOutline.qname];if("none"===d&&"none"===e)a.style.textShadow="";else{c=[];"none"!==e&&(e="rgba("+e.color[0].toString()+","+e.color[1].toString()+","+e.color[2].toString()+ ","+(e.color[3]/255).toString()+")",c.push("1px 1px 1px "+e),c.push("-1px 1px 1px "+e),c.push("1px -1px 1px "+e),c.push("-1px -1px 1px "+e));if("none"!==d)for(e=0;e<d.length;e++)c.push(d[e].x_off.toUsedLength(b.w,b.h)+"px "+d[e].y_off.toUsedLength(b.w,b.h)+"px "+d[e].b_radius.toUsedLength(b.w,b.h)+"px rgba("+d[e].color[0].toString()+","+d[e].color[1].toString()+","+d[e].color[2].toString()+","+(d[e].color[3]/255).toString()+")");a.style.textShadow=c.join(",")}}),new g("http://www.w3.org/ns/ttml#styling textCombine", function(b,a,c,d){a.style.textCombineUpright=d}),new g("http://www.w3.org/ns/ttml#styling textEmphasis",function(b,a,c,d){}),new g("http://www.w3.org/ns/ttml#styling unicodeBidi",function(b,a,c,d){a.style.unicodeBidi="bidiOverride"===d?"bidi-override":d}),new g("http://www.w3.org/ns/ttml#styling visibility",function(b,a,c,d){a.style.visibility=d}),new g("http://www.w3.org/ns/ttml#styling wrapOption",function(b,a,c,d){a.style.whiteSpace="wrap"===d?"preserve"===c.space?"pre-wrap":"normal":"preserve"=== c.space?"pre":"noWrap"}),new g("http://www.w3.org/ns/ttml#styling writingMode",function(b,a,c,d){if("lrtb"===d||"lr"===d)a.style.writingMode="horizontal-tb";else if("rltb"===d||"rl"===d)a.style.writingMode="horizontal-tb";else if("tblr"===d)a.style.writingMode="vertical-lr";else if("tbrl"===d||"tb"===d)a.style.writingMode="vertical-rl"}),new g("http://www.w3.org/ns/ttml#styling zIndex",function(b,a,c,d){a.style.zIndex=d}),new g("http://www.w3.org/ns/ttml/profile/imsc1#styling forcedDisplay",function(b, a,c,d){b.displayForcedOnlyMode&&!1===d&&(a.style.visibility="hidden")})];for(f=0;f<G.length;f++);var y="webkitRubyPosition"in window.getComputedStyle(document.documentElement),B=y?"webkitRubyPosition":"rubyPosition",L="webkitTextEmphasisStyle"in window.getComputedStyle(document.documentElement)?"webkitTextEmphasisStyle":"textEmphasisStyle",E="webkitTextEmphasisPosition"in window.getComputedStyle(document.documentElement)?"webkitTextEmphasisPosition":"textEmphasisPosition"})("undefined"===typeof l? this.imscHTML={}:l,"undefined"===typeof imscNames?f("./names"):imscNames,"undefined"===typeof imscStyles?f("./styles"):imscStyles,"undefined"===typeof imscUtils?f("./utils"):imscUtils)},{"./names":5,"./styles":6,"./utils":7}],3:[function(f,v,l){(function(f,l,m,n){function w(f,p,l,E,b,k,c,d,v){if(p<c.begin||p>=c.end)return null;k="regionID"in c&&""!==c.regionID?c.regionID:k;if(null!==b&&k!==l.id&&(!("contents"in c)||"contents"in c&&0===c.contents.length||""!==k))return null;var h=new g(c);if("sets"in c)for(var y=0;y<c.sets.length;y++)p<c.sets[y].begin||p>=c.sets[y].end||(h.styleAttrs[c.sets[y].qname]=c.sets[y].value);y={};for(var t in h.styleAttrs)if(h.styleAttrs.hasOwnProperty(t)&&(y[t]=!0,"region"===h.kind&&t===m.byName.writingMode.qname&&!(m.byName.direction.qname in h.styleAttrs))){var q=h.styleAttrs[t];if("lrtb"===q||"lr"===q)h.styleAttrs[m.byName.direction.qname]="ltr";else if("rltb"===q||"rl"===q)h.styleAttrs[m.byName.direction.qname]="rtl"}if(null!==b)for(t=0;t<m.all.length;t++)if(q=m.all[t], q.qname===m.byName.textDecoration.qname){var r=b.styleAttrs[q.qname],B=h.styleAttrs[q.qname],H=[];void 0===B?H=r:-1===B.indexOf("none")?((-1===B.indexOf("noUnderline")&&-1!==r.indexOf("underline")||-1!==B.indexOf("underline"))&&H.push("underline"),(-1===B.indexOf("noLineThrough")&&-1!==r.indexOf("lineThrough")||-1!==B.indexOf("lineThrough"))&&H.push("lineThrough"),(-1===B.indexOf("noOverline")&&-1!==r.indexOf("overline")||-1!==B.indexOf("overline"))&&H.push("overline")):H.push("none");h.styleAttrs[q.qname]= H}else q.qname!==m.byName.fontSize.qname||q.qname in h.styleAttrs||"span"!==h.kind||"textContainer"!==h.styleAttrs[m.byName.ruby.qname]?q.qname!==m.byName.fontSize.qname||q.qname in h.styleAttrs||"span"!==h.kind||"text"!==h.styleAttrs[m.byName.ruby.qname]?q.inherit&&q.qname in b.styleAttrs&&!(q.qname in h.styleAttrs)&&(h.styleAttrs[q.qname]=b.styleAttrs[q.qname]):(r=b.styleAttrs[m.byName.fontSize.qname],h.styleAttrs[q.qname]="textContainer"===b.styleAttrs[m.byName.ruby.qname]?r:new n.ComputedLength(.5* r.rw,.5*r.rh)):(r=b.styleAttrs[m.byName.fontSize.qname],h.styleAttrs[q.qname]=new n.ComputedLength(.5*r.rw,.5*r.rh));for(t=0;t<m.all.length;t++)if(q=m.all[t],!(q.qname in h.styleAttrs||q.qname===m.byName.position.qname&&m.byName.origin.qname in h.styleAttrs||q.qname===m.byName.origin.qname&&m.byName.position.qname in h.styleAttrs)&&(r=f.head.styling.initials[q.qname]||q.initial,null!==r&&("region"===h.kind||!1===q.inherit&&null!==r)))if(r=q.parse(r),null!==r)h.styleAttrs[q.qname]=r,y[q.qname]=!0; else if(q="Invalid initial value for '"+q.qname+"' on element '"+h.kind,d&&d.error&&d.error(q))throw q;for(t=0;t<m.all.length;t++)if(q=m.all[t],q.qname in y&&null!==q.compute)if(r=q.compute(f,b,h,h.styleAttrs[q.qname],v),null!==r)h.styleAttrs[q.qname]=r;else if(h.styleAttrs[q.qname]=q.compute(f,b,h,q.parse(q.initial),v),q="Style '"+q.qname+"' on element '"+h.kind+"' cannot be computed",d&&d.error&&d.error(q))throw q;if("none"===h.styleAttrs[m.byName.display.qname])return null;y=null;null===b?y=null=== E?[]:[E]:"contents"in c&&(y=c.contents);for(b=0;null!==y&&b<y.length;b++)c=w(f,p,l,E,h,k,y[b],d,v),null!==c&&h.contents.push(c.element);for(var x in h.styleAttrs)h.styleAttrs.hasOwnProperty(x)&&(f=!1,"span"===h.kind&&(p=h.styleAttrs[m.byName.ruby.qname],(f=("container"===p||"textContainer"===p||"baseContainer"===p)&&-1!==G.indexOf(x))||(f="container"!==p&&x===m.byName.rubyAlign.qname),f||(f=!("textContainer"===p||"text"===p)&&x===m.byName.rubyPosition.qname)),f||(p=m.byQName[x],"applies"in p&&(f= -1===p.applies.indexOf(h.kind))),f&&delete h.styleAttrs[x]);x=h.styleAttrs[m.byName.ruby.qname];if("p"===h.kind||"span"===h.kind&&("textContainer"===x||"text"===x))x=[],a(h,x),A(x),e(h);return"div"===h.kind&&m.byName.backgroundImage.qname in h.styleAttrs||"br"===h.kind||"image"===h.kind||"contents"in h&&0<h.contents.length||"span"===h.kind&&null!==h.text||"region"===h.kind&&"always"===h.styleAttrs[m.byName.showBackground.qname]?{region_id:k,element:h}:null}function A(a){function e(b){return"br"=== b.kind||/[\r\n\t ]$/.test(b.text)}function g(b){return"br"===b.kind||"preserve"===b.space&&/^[\r\n]/.test(b.text)}for(var f,b=0;b<a.length;)if(f=a[b],"br"===f.kind||"preserve"===f.space)b++;else{var k=f.text.replace(/[\t\r\n ]+/g," ");/^[ ]/.test(k)&&(0===b||e(a[b-1]))&&(k=k.substring(1));f.text=k;0===k.length?a.splice(b,1):b++}for(b=0;b<a.length;b++)f=a[b],"br"===f.kind||"preserve"===f.space?b++:/[ ]$/.test(f.text)&&(b===a.length-1||g(a[b+1]))&&(f.text=f.text.slice(0,-1))}function a(e,g){if("contents"in e)for(var f=0;f<e.contents.length;f++){var p=e.contents[f],b=p.styleAttrs[m.byName.ruby.qname];if("span"!==p.kind||"textContainer"!==b&&"text"!==b)"contents"in p?a(p,g):("span"===p.kind&&0!==p.text.length||"br"===p.kind)&&g.push(p)}}function e(a){if("br"===a.kind)return!1;if("text"in a)return 0===a.text.length;if("contents"in a){for(var g=a.contents.length;g--;)e(a.contents[g])&&a.contents.splice(g,1);return 0===a.contents.length}}function p(a){this.contents=[];this.aspectRatio=a.aspectRatio;this.lang= a.lang}function g(a){this.kind=a.kind||"region";this.lang=a.lang;a.id&&(this.id=a.id);this.styleAttrs={};for(var e in a.styleAttrs)a.styleAttrs.hasOwnProperty(e)&&(this.styleAttrs[e]=a.styleAttrs[e]);"src"in a&&(this.src=a.src);"type"in a&&(this.type=a.type);if("text"in a)this.text=a.text;else if("region"===this.kind||"contents"in a)this.contents=[];"space"in a&&(this.space=a.space)}f.generateISD=function(a,e,g){function f(a,b){function c(b){return!(a<b.begin||a>=b.end)}if(b.contents){var e={},g; for(g in b)b.hasOwnProperty(g)&&(e[g]=b[g]);e.contents=[];b.contents.filter(c).forEach(function(b){b=f(a,b);b.regionID&&(d[b.regionID]=!0);null!==b&&e.contents.push(b)});return e}return b}var b=new p(a),k={},c={},d={};c=a.head.styling.initials[m.byName.showBackground.qname];var n=a.head.styling.initials[m.byName.backgroundColor.qname];for(r in a.head.layout.regions)if(a.head.layout.regions.hasOwnProperty(r)){var h=a.head.layout.regions[r],l=h.styleAttrs[m.byName.showBackground.qname]||c,t=h.styleAttrs[m.byName.backgroundColor.qname]|| n;d[h.id]=("always"===l||void 0===l)&&void 0!==t&&!(e<h.begin||e>=h.end)}a.body&&a.body.regionID&&(d[a.body.regionID]=!0);c=null!==a.body?f(e,a.body):null;void 0!==d[""]&&(d[""]=!0);for(var q in d)if(d[q]){var r=w(a,e,a.head.layout.regions[q],c,null,"",a.head.layout.regions[q],g,k);null!==r&&b.contents.push(r.element)}return b};var G=[m.byName.color.qname,m.byName.textCombine.qname,m.byName.textDecoration.qname,m.byName.textEmphasis.qname,m.byName.textOutline.qname,m.byName.textShadow.qname]})("undefined"=== typeof l?this.imscISD={}:l,"undefined"===typeof imscNames?f("./names"):imscNames,"undefined"===typeof imscStyles?f("./styles"):imscStyles,"undefined"===typeof imscUtils?f("./utils"):imscUtils)},{"./names":5,"./styles":6,"./utils":7}],4:[function(f,v,l){l.generateISD=f("./isd").generateISD;l.fromXML=f("./doc").fromXML;l.renderHTML=f("./html").render},{"./doc":1,"./html":2,"./isd":3}],5:[function(f,v,l){f="undefined"===typeof l?this.imscNames={}:l;f.ns_tt="http://www.w3.org/ns/ttml";f.ns_tts="http://www.w3.org/ns/ttml#styling"; f.ns_ttp="http://www.w3.org/ns/ttml#parameter";f.ns_xml="http://www.w3.org/XML/1998/namespace";f.ns_itts="http://www.w3.org/ns/ttml/profile/imsc1#styling";f.ns_ittp="http://www.w3.org/ns/ttml/profile/imsc1#parameter";f.ns_smpte="http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt";f.ns_ebutts="urn:ebu:tt:style"},{}],6:[function(f,v,l){(function(f,l,m){function n(a,e,f,g,m,l,n,w){this.name=e;this.ns=a;this.qname=a+" "+e;this.inherit=m;this.animatable=l;this.initial=f;this.applies=g;this.parse=n;this.compute= w}f.all=[new n(l.ns_tts,"backgroundColor","transparent",["body","div","p","region","span"],!1,!0,m.parseColor,null),new n(l.ns_tts,"color","white",["span"],!0,!0,m.parseColor,null),new n(l.ns_tts,"direction","ltr",["p","span"],!0,!0,function(a){return a},null),new n(l.ns_tts,"display","auto",["body","div","p","region","span"],!1,!0,function(a){return a},null),new n(l.ns_tts,"displayAlign","before",["region"],!1,!0,function(a){return a},null),new n(l.ns_tts,"extent","auto",["tt","region"],!1,!0,function(a){if("auto"=== a)return a;var e=a.split(" ");if(2!==e.length)return null;a=m.parseLength(e[0]);return(e=m.parseLength(e[1]))&&a?{h:e,w:a}:null},function(a,e,f,g,l){if("auto"===g)e=new m.ComputedLength(0,1);else if(e=m.toComputedLength(g.h.value,g.h.unit,null,a.dimensions.h,null,a.pxLength.h),null===e)return null;if("auto"===g)a=new m.ComputedLength(1,0);else if(a=m.toComputedLength(g.w.value,g.w.unit,null,a.dimensions.w,null,a.pxLength.w),null===a)return null;return{h:e,w:a}}),new n(l.ns_tts,"fontFamily","default", ["span","p"],!0,!0,function(a){a=a.split(",");for(var e=[],f=0;f<a.length;f++)"'"!==a[f].charAt(0)&&'"'!==a[f].charAt(0)?"default"===a[f]?e.push("monospaceSerif"):e.push(a[f]):e.push(a[f]);return e},null),new n(l.ns_tts,"shear","0%",["p"],!0,!0,m.parseLength,function(a,e,f,g){if("%"===g.unit)a=100<Math.abs(g.value)?100*Math.sign(g.value):g.value;else return null;return a}),new n(l.ns_tts,"fontSize","1c",["span","p"],!0,!0,m.parseLength,function(a,e,p,g,l){return m.toComputedLength(g.value,g.unit, null!==e?e.styleAttrs[f.byName.fontSize.qname]:a.cellLength.h,null!==e?e.styleAttrs[f.byName.fontSize.qname]:a.cellLength.h,a.cellLength.h,a.pxLength.h)}),new n(l.ns_tts,"fontStyle","normal",["span","p"],!0,!0,function(a){return a},null),new n(l.ns_tts,"fontWeight","normal",["span","p"],!0,!0,function(a){return a},null),new n(l.ns_tts,"lineHeight","normal",["p"],!0,!0,function(a){return"normal"===a?a:m.parseLength(a)},function(a,e,p,g,l){if("normal"===g)a=g;else if(a=m.toComputedLength(g.value,g.unit, p.styleAttrs[f.byName.fontSize.qname],p.styleAttrs[f.byName.fontSize.qname],a.cellLength.h,a.pxLength.h),null===a)return null;return a}),new n(l.ns_tts,"opacity",1,["region"],!1,!0,parseFloat,null),new n(l.ns_tts,"origin","auto",["region"],!1,!0,function(a){if("auto"===a)return a;var e=a.split(" ");if(2!==e.length)return null;a=m.parseLength(e[0]);return(e=m.parseLength(e[1]))&&a?{h:e,w:a}:null},function(a,e,f,g,l){if("auto"===g)e=new m.ComputedLength(0,0);else if(e=m.toComputedLength(g.h.value,g.h.unit, null,a.dimensions.h,null,a.pxLength.h),null===e)return null;if("auto"===g)a=new m.ComputedLength(0,0);else if(a=m.toComputedLength(g.w.value,g.w.unit,null,a.dimensions.w,null,a.pxLength.w),null===a)return null;return{h:e,w:a}}),new n(l.ns_tts,"overflow","hidden",["region"],!1,!0,function(a){return a},null),new n(l.ns_tts,"padding","0px",["region"],!1,!0,function(a){a=a.split(" ");if(4<a.length)return null;for(var e=[],f=0;f<a.length;f++){var g=m.parseLength(a[f]);if(!g)return null;e.push(g)}return e}, function(a,e,p,g,l){if(1===g.length)e=[g[0],g[0],g[0],g[0]];else if(2===g.length)e=[g[0],g[1],g[0],g[1]];else if(3===g.length)e=[g[0],g[1],g[2],g[1]];else if(4===g.length)e=[g[0],g[1],g[2],g[3]];else return null;g=p.styleAttrs[f.byName.writingMode.qname];if("lrtb"===g||"lr"===g)e=[e[0],e[3],e[2],e[1]];else if("rltb"===g||"rl"===g)e=[e[0],e[1],e[2],e[3]];else if("tblr"===g)e=[e[3],e[0],e[1],e[2]];else if("tbrl"===g||"tb"===g)e=[e[3],e[2],e[1],e[0]];else return null;g=[];for(l=0;l<e.length;l++)if(0=== e[l].value)g[l]=new m.ComputedLength(0,0);else if(g[l]=m.toComputedLength(e[l].value,e[l].unit,p.styleAttrs[f.byName.fontSize.qname],0===l||2===l?p.styleAttrs[f.byName.extent.qname].h:p.styleAttrs[f.byName.extent.qname].w,0===l||2===l?a.cellLength.h:a.cellLength.w,0===l||2===l?a.pxLength.h:a.pxLength.w),null===g[l])return null;return g}),new n(l.ns_tts,"position","top left",["region"],!1,!0,function(a){return m.parsePosition(a)},function(a,e,p,g){e=m.toComputedLength(g.v.offset.value,g.v.offset.unit, null,new m.ComputedLength(-p.styleAttrs[f.byName.extent.qname].h.rw,a.dimensions.h.rh-p.styleAttrs[f.byName.extent.qname].h.rh),null,a.pxLength.h);if(null===e)return null;"bottom"===g.v.edge&&(e=new m.ComputedLength(-e.rw-p.styleAttrs[f.byName.extent.qname].h.rw,a.dimensions.h.rh-e.rh-p.styleAttrs[f.byName.extent.qname].h.rh));var l=m.toComputedLength(g.h.offset.value,g.h.offset.unit,null,new m.ComputedLength(a.dimensions.w.rw-p.styleAttrs[f.byName.extent.qname].w.rw,-p.styleAttrs[f.byName.extent.qname].w.rh), null,a.pxLength.w);if(null===e)return null;"right"===g.h.edge&&(l=new m.ComputedLength(a.dimensions.w.rw-l.rw-p.styleAttrs[f.byName.extent.qname].w.rw,-l.rh-p.styleAttrs[f.byName.extent.qname].w.rh));return{h:e,w:l}}),new n(l.ns_tts,"ruby","none",["span"],!1,!0,function(a){return a},null),new n(l.ns_tts,"rubyAlign","center",["span"],!0,!0,function(a){return"center"!==a&&"spaceAround"!==a?null:a},null),new n(l.ns_tts,"rubyPosition","outside",["span"],!0,!0,function(a){return a},null),new n(l.ns_tts, "rubyReserve","none",["p"],!0,!0,function(a){var e=a.split(" ");a=[null,null];if(0===e.length||2<e.length||"none"!==e[0]&&"both"!==e[0]&&"after"!==e[0]&&"before"!==e[0]&&"outside"!==e[0])return null;a[0]=e[0];if(2===e.length&&"none"!==e[0])if(e=m.parseLength(e[1]))a[1]=e;else return null;return a},function(a,e,p,g,l){if("none"===g[0])return g;a=null===g[1]?new m.ComputedLength(.5*p.styleAttrs[f.byName.fontSize.qname].rw,.5*p.styleAttrs[f.byName.fontSize.qname].rh):m.toComputedLength(g[1].value,g[1].unit, p.styleAttrs[f.byName.fontSize.qname],p.styleAttrs[f.byName.fontSize.qname],a.cellLength.h,a.pxLength.h);return null===a?null:[g[0],a]}),new n(l.ns_tts,"showBackground","always",["region"],!1,!0,function(a){return a},null),new n(l.ns_tts,"textAlign","start",["p"],!0,!0,function(a){return a},function(a,e,f,g,l){return"left"===g?"start":"right"===g?"end":g}),new n(l.ns_tts,"textCombine","none",["span"],!0,!0,function(a){return"none"===a||"all"===a?a:null},null),new n(l.ns_tts,"textDecoration","none", ["span"],!0,!0,function(a){return a.split(" ")},null),new n(l.ns_tts,"textEmphasis","none",["span"],!0,!0,function(a){a=a.split(" ");for(var e={style:null,symbol:null,color:null,position:null},f=0;f<a.length;f++)if("none"===a[f]||"auto"===a[f])e.style=a[f];else if("filled"===a[f]||"open"===a[f])e.style=a[f];else if("circle"===a[f]||"dot"===a[f]||"sesame"===a[f])e.symbol=a[f];else if("current"===a[f])e.color=a[f];else if("outside"===a[f]||"before"===a[f]||"after"===a[f])e.position=a[f];else if(e.color= m.parseColor(a[f]),null===e.color)return null;null==e.style&&null==e.symbol?e.style="auto":(e.symbol=e.symbol||"circle",e.style=e.style||"filled");e.position=e.position||"outside";e.color=e.color||"current";return e},null),new n(l.ns_tts,"textOutline","none",["span"],!0,!0,function(a){if("none"===a)re