UNPKG

imsc

Version:

Renders IMSC documents to HTML5 fragments

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