/** * libjass * * https://github.com/Arnavion/libjass * * Copyright 2013 Arnav Singh * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ !function(e,t){var r=this;"function"==typeof define&&define.amd?define([],function(){return t(r)}):"object"==typeof exports&&"object"==typeof module?module.exports=t(r):"object"==typeof exports?exports.libjass=t(r):e.libjass=t(r)}(this,function(e){"use strict";return function(e){function t(n){if(r[n])return r[n];var i=r[n]=Object.create(null);return e[n](i,t),i}var r=Object.create(null);return t(0)}([function(e,t){var r=t(23),n=t(23);e.debugMode=n.debugMode,e.verboseMode=n.verboseMode;var i=t(33),o=t(33);e.Set=o.Set;var a=t(30),l=t(30);e.Map=l.Map;var s=t(32),u=t(32);e.Promise=u.Promise,e.DeferredPromise=u.DeferredPromise;var p=t(37);e.webworker=p;var c=t(8);e.parts=c;var h=t(1);e.parser=h;var f=t(14);e.renderers=f;var d=t(24);e.ASS=d.ASS;var _=t(25);e.Attachment=_.Attachment,e.AttachmentType=_.AttachmentType;var g=t(26);e.Dialogue=g.Dialogue;var v=t(28);e.ScriptProperties=v.ScriptProperties;var y=t(29);e.Style=y.Style;var m=t(27);e.BorderStyle=m.BorderStyle,e.Format=m.Format,e.WrappingStyle=m.WrappingStyle,Object.defineProperties(e,{debugMode:{get:function(){return r.debugMode},set:r.setDebugMode},verboseMode:{get:function(){return r.verboseMode},set:r.setVerboseMode},Set:{get:function(){return i.Set},set:i.setImplementation},Map:{get:function(){return a.Map},set:a.setImplementation},Promise:{get:function(){return s.Promise},set:s.setImplementation}})},function(e,t){var r=t(3);e.parse=r.parse;var n=t(5);e.BrowserReadableStream=n.BrowserReadableStream,e.StringStream=n.StringStream,e.XhrStream=n.XhrStream;var i=t(4);e.StreamParser=i.StreamParser,e.SrtStreamParser=i.SrtStreamParser},function(e,t){function r(e){var t=e.indexOf(":");if(-1===t)return null;var r=e.substr(0,t),n=e.substr(t+1).replace(/^\s+/,"");return{name:r,value:n}}function n(e,t){var n=r(e);if(null===n)return null;var o=n.value.split(",");o.length>t.length&&(o[t.length-1]=o.slice(t.length-1).join(","));var a=new i.Map;return t.forEach(function(e,t){a.set(e,o[t])}),{type:n.name,template:a}}var i=t(30);e.parseLineIntoProperty=r,e.parseLineIntoTypedTemplate=n},function(e,t){function r(e,t){var r=new s(e,t);if(null===r.result||r.result.end!==e.length)throw o.debugMode&&console.error("Parse failed. %s %s %o",t,e,r.result),new Error("Parse failed.");return r.result.value}function n(e,t,r,n){s.prototype["parse_tag_"+e]=function(i){var o=this,a=new h(i);if(null===o.read(a,e))return i.pop(),null;var l=r.call(o,a);if(null!==l)a.value=new t(l.value);else{if(n)return i.pop(),null;a.value=new t(null)}return a}}var i=t(8),o=t(23),a=t(30),l=new a.Map;e.parse=r;var s=function(){function e(e,t){this.e=e,this.t=new h(null),this.r=l.get(t).call(this,this.t)}return Object.defineProperty(e.prototype,"result",{get:function(){return this.r},enumerable:!0,configurable:!0}),e.prototype.parse_dialogueParts=function(e){var t,n=new h(e);for(n.value=[];this.n();){var o=this.parse_enclosedTags(n);if(null!==o)(t=n.value).push.apply(t,o.value);else{var a=this.parse_newline(n)||this.parse_hardspace(n)||this.parse_text(n);if(null===a)return e.pop(),null;if(a.value instanceof i.Text&&n.value[n.value.length-1]instanceof i.Text){var l=n.value[n.value.length-1];n.value[n.value.length-1]=new i.Text(l.value+a.value.value)}else n.value.push(a.value)}}var s=!1;return n.value.forEach(function(e,t){e instanceof i.DrawingMode?s=0!==e.scale:e instanceof i.Text&&s&&(n.value[t]=new i.DrawingInstructions(r(e.value,"drawingInstructions")))}),n},e.prototype.parse_enclosedTags=function(e){var t=new h(e);if(t.value=[],null===this.read(t,"{"))return e.pop(),null;for(var r=this.i();this.n()&&"}"!==r;r=this.i()){var n=null;if(null!==this.read(t,"\\")&&(n=this.parse_tag_alpha(t)||this.parse_tag_iclip(t)||this.parse_tag_xbord(t)||this.parse_tag_ybord(t)||this.parse_tag_xshad(t)||this.parse_tag_yshad(t)||this.parse_tag_blur(t)||this.parse_tag_bord(t)||this.parse_tag_clip(t)||this.parse_tag_fade(t)||this.parse_tag_fscx(t)||this.parse_tag_fscy(t)||this.parse_tag_move(t)||this.parse_tag_shad(t)||this.parse_tag_fad(t)||this.parse_tag_fax(t)||this.parse_tag_fay(t)||this.parse_tag_frx(t)||this.parse_tag_fry(t)||this.parse_tag_frz(t)||this.parse_tag_fsp(t)||this.parse_tag_fsplus(t)||this.parse_tag_fsminus(t)||this.parse_tag_org(t)||this.parse_tag_pbo(t)||this.parse_tag_pos(t)||this.parse_tag_an(t)||this.parse_tag_be(t)||this.parse_tag_fn(t)||this.parse_tag_fr(t)||this.parse_tag_fs(t)||this.parse_tag_kf(t)||this.parse_tag_ko(t)||this.parse_tag_1a(t)||this.parse_tag_1c(t)||this.parse_tag_2a(t)||this.parse_tag_2c(t)||this.parse_tag_3a(t)||this.parse_tag_3c(t)||this.parse_tag_4a(t)||this.parse_tag_4c(t)||this.parse_tag_a(t)||this.parse_tag_b(t)||this.parse_tag_c(t)||this.parse_tag_i(t)||this.parse_tag_k(t)||this.parse_tag_K(t)||this.parse_tag_p(t)||this.parse_tag_q(t)||this.parse_tag_r(t)||this.parse_tag_s(t)||this.parse_tag_t(t)||this.parse_tag_u(t),null===n&&t.pop()),null===n&&(n=this.parse_comment(t)),null===n)return e.pop(),null;n.value instanceof i.Comment&&t.value[t.value.length-1]instanceof i.Comment?t.value[t.value.length-1]=new i.Comment(t.value[t.value.length-1].value+n.value.value):t.value.push(n.value)}return null===this.read(t,"}")?(e.pop(),null):t},e.prototype.parse_newline=function(e){var t=new h(e);return null===this.read(t,"\\N")?(e.pop(),null):(t.value=new i.NewLine,t)},e.prototype.parse_hardspace=function(e){var t=new h(e);return null===this.read(t,"\\h")?(e.pop(),null):(t.value=new i.Text(" "),t)},e.prototype.parse_text=function(e){var t=this.i(),r=new h(e),n=new h(r,t);return r.value=new i.Text(n.value),r},e.prototype.parse_comment=function(e){var t=this.i(),r=new h(e),n=new h(r,t);return r.value=new i.Comment(n.value),r},e.prototype.parse_tag_a=function(e){var t=new h(e);if(null===this.read(t,"a"))return e.pop(),null;var r=this.i();switch(r){case"1":var n=this.i(2);switch(n){case"10":case"11":r=n}break;case"2":case"3":case"5":case"6":case"7":case"9":break;default:return e.pop(),null}var o=new h(t,r),a=null;switch(o.value){case"1":a=1;break;case"2":a=2;break;case"3":a=3;break;case"5":a=7;break;case"6":a=8;break;case"7":a=9;break;case"9":a=4;break;case"10":a=5;break;case"11":a=6}return t.value=new i.Alignment(a),t},e.prototype.parse_tag_alpha=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_an=function(e){var t=new h(e);if(null===this.read(t,"an"))return e.pop(),null;var r=this.i();if("1">r||r>"9")return e.pop(),null;var n=new h(t,r);return t.value=new i.Alignment(parseInt(n.value)),t},e.prototype.parse_tag_b=function(e){var t=new h(e);if(null===this.read(t,"b"))return e.pop(),null;var r=null,n=this.i();return n>="1"&&"9">=n&&(n=this.i(3),"00"===n.substr(1)&&(r=new h(t,n),r.value=parseInt(r.value))),null===r&&(r=this.parse_enableDisable(t)),null!==r?t.value=new i.Bold(r.value):t.value=new i.Bold(null),t},e.prototype.parse_tag_be=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_blur=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_bord=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_c=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_clip=function(e){return this.o("clip",e)},e.prototype.parse_tag_fad=function(e){var t=new h(e);if(null===this.read(t,"fad"))return e.pop(),null;if(null===this.read(t,"("))return e.pop(),null;var r=this.parse_decimal(t);if(null===r)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var n=this.parse_decimal(t);return null===n?(e.pop(),null):null===this.read(t,")")?(e.pop(),null):(t.value=new i.Fade(r.value/1e3,n.value/1e3),t)},e.prototype.parse_tag_fade=function(e){var t=new h(e);if(null===this.read(t,"fade"))return e.pop(),null;if(null===this.read(t,"("))return e.pop(),null;var r=this.parse_decimal(t);if(null===r)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var n=this.parse_decimal(t);if(null===n)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var o=this.parse_decimal(t);if(null===o)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var a=this.parse_decimal(t);if(null===a)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var l=this.parse_decimal(t);if(null===l)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var s=this.parse_decimal(t);if(null===s)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var u=this.parse_decimal(t);return null===u?(e.pop(),null):null===this.read(t,")")?(e.pop(),null):(t.value=new i.ComplexFade(1-r.value/255,1-n.value/255,1-o.value/255,a.value/1e3,l.value/1e3,s.value/1e3,u.value/1e3),t)},e.prototype.parse_tag_fax=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_fay=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_fn=function(e){var t=new h(e);if(null===this.read(t,"fn"))return e.pop(),null;for(var r=new h(t,""),n=this.i();this.n()&&"\\"!==n&&"}"!==n;n=this.i())r.value+=n;return r.value.length>0?t.value=new i.FontName(r.value):t.value=new i.FontName(null),t},e.prototype.parse_tag_fr=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_frx=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_fry=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_frz=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_fs=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_fsplus=function(e){var t=new h(e);if(null===this.read(t,"fs+"))return e.pop(),null;var r=this.parse_decimal(t);return null===r?(e.pop(),null):(t.value=new i.FontSizePlus(r.value),t)},e.prototype.parse_tag_fsminus=function(e){var t=new h(e);if(null===this.read(t,"fs-"))return e.pop(),null;var r=this.parse_decimal(t);return null===r?(e.pop(),null):(t.value=new i.FontSizeMinus(r.value),t)},e.prototype.parse_tag_fscx=function(e){var t=new h(e);if(null===this.read(t,"fscx"))return e.pop(),null;var r=this.parse_decimal(t);return null!==r?t.value=new i.FontScaleX(r.value/100):t.value=new i.FontScaleX(null),t},e.prototype.parse_tag_fscy=function(e){var t=new h(e);if(null===this.read(t,"fscy"))return e.pop(),null;var r=this.parse_decimal(t);return null!==r?t.value=new i.FontScaleY(r.value/100):t.value=new i.FontScaleY(null),t},e.prototype.parse_tag_fsp=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_i=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_iclip=function(e){return this.o("iclip",e)},e.prototype.parse_tag_k=function(e){var t=new h(e);if(null===this.read(t,"k"))return e.pop(),null;var r=this.parse_decimal(t);return null===r?(e.pop(),null):(t.value=new i.ColorKaraoke(r.value/100),t)},e.prototype.parse_tag_K=function(e){var t=new h(e);if(null===this.read(t,"K"))return e.pop(),null;var r=this.parse_decimal(t);return null===r?(e.pop(),null):(t.value=new i.SweepingColorKaraoke(r.value/100),t)},e.prototype.parse_tag_kf=function(e){var t=new h(e);if(null===this.read(t,"kf"))return e.pop(),null;var r=this.parse_decimal(t);return null===r?(e.pop(),null):(t.value=new i.SweepingColorKaraoke(r.value/100),t)},e.prototype.parse_tag_ko=function(e){var t=new h(e);if(null===this.read(t,"ko"))return e.pop(),null;var r=this.parse_decimal(t);return null===r?(e.pop(),null):(t.value=new i.OutlineKaraoke(r.value/100),t)},e.prototype.parse_tag_move=function(e){var t=new h(e);if(null===this.read(t,"move"))return e.pop(),null;if(null===this.read(t,"("))return e.pop(),null;var r=this.parse_decimal(t);if(null===r)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var n=this.parse_decimal(t);if(null===n)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var o=this.parse_decimal(t);if(null===o)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var a=this.parse_decimal(t);if(null===a)return e.pop(),null;var l=null,s=null;if(null!==this.read(t,",")){if(l=this.parse_decimal(t),null===l)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;if(s=this.parse_decimal(t),null===s)return e.pop(),null}return null===this.read(t,")")?(e.pop(),null):(t.value=new i.Move(r.value,n.value,o.value,a.value,null!==l?l.value/1e3:null,null!==s?s.value/1e3:null),t)},e.prototype.parse_tag_org=function(e){var t=new h(e);if(null===this.read(t,"org"))return e.pop(),null;if(null===this.read(t,"("))return e.pop(),null;var r=this.parse_decimal(t);if(null===r)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var n=this.parse_decimal(t);return null===n?(e.pop(),null):null===this.read(t,")")?(e.pop(),null):(t.value=new i.RotationOrigin(r.value,n.value),t)},e.prototype.parse_tag_p=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_pbo=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_pos=function(e){var t=new h(e);if(null===this.read(t,"pos"))return e.pop(),null;if(null===this.read(t,"("))return e.pop(),null;var r=this.parse_decimal(t);if(null===r)return e.pop(),null;if(null===this.read(t,","))return e.pop(),null;var n=this.parse_decimal(t);return null===n?(e.pop(),null):null===this.read(t,")")?(e.pop(),null):(t.value=new i.Position(r.value,n.value),t)},e.prototype.parse_tag_q=function(e){var t=new h(e);if(null===this.read(t,"q"))return e.pop(),null;var r=this.i();if("0">r||r>"3")return e.pop(),null;var n=new h(t,r);return t.value=new i.WrappingStyle(parseInt(n.value)),t},e.prototype.parse_tag_r=function(e){var t=new h(e);if(null===this.read(t,"r"))return e.pop(),null;for(var r=new h(t,""),n=this.i();this.n()&&"\\"!==n&&"}"!==n;n=this.i())r.value+=n;return r.value.length>0?t.value=new i.Reset(r.value):t.value=new i.Reset(null),t},e.prototype.parse_tag_s=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_shad=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_t=function(e){var t=new h(e);if(null===this.read(t,"t"))return e.pop(),null;if(null===this.read(t,"("))return e.pop(),null;var r=null,n=null,o=null,a=this.parse_decimal(t);if(null!==a){if(null===this.read(t,","))return e.pop(),null;var l=this.parse_decimal(t);if(null!==l){if(r=a,n=l,null===this.read(t,","))return e.pop(),null;var s=this.parse_decimal(t);if(null!==s&&(o=s,null===this.read(t,",")))return e.pop(),null}else if(o=a,null===this.read(t,","))return e.pop(),null}for(var u=[],p=this.i();this.n()&&")"!==p&&"}"!==p;p=this.i()){var c=null;if(null!==this.read(t,"\\")&&(c=this.parse_tag_alpha(t)||this.parse_tag_iclip(t)||this.parse_tag_xbord(t)||this.parse_tag_ybord(t)||this.parse_tag_xshad(t)||this.parse_tag_yshad(t)||this.parse_tag_blur(t)||this.parse_tag_bord(t)||this.parse_tag_clip(t)||this.parse_tag_fscx(t)||this.parse_tag_fscy(t)||this.parse_tag_shad(t)||this.parse_tag_fax(t)||this.parse_tag_fay(t)||this.parse_tag_frx(t)||this.parse_tag_fry(t)||this.parse_tag_frz(t)||this.parse_tag_fsp(t)||this.parse_tag_fsplus(t)||this.parse_tag_fsminus(t)||this.parse_tag_be(t)||this.parse_tag_fr(t)||this.parse_tag_fs(t)||this.parse_tag_1a(t)||this.parse_tag_1c(t)||this.parse_tag_2a(t)||this.parse_tag_2c(t)||this.parse_tag_3a(t)||this.parse_tag_3c(t)||this.parse_tag_4a(t)||this.parse_tag_4c(t)||this.parse_tag_c(t),null===c&&t.pop()),null===c&&(c=this.parse_comment(t)),null===c)return e.pop(),null;c.value instanceof i.Comment&&u[u.length-1]instanceof i.Comment?u[u.length-1]=new i.Comment(u[u.length-1].value+c.value.value):u.push(c.value)}return this.read(t,")"),t.value=new i.Transform(null!==r?r.value/1e3:null,null!==n?n.value/1e3:null,null!==o?o.value/1e3:null,u),t},e.prototype.parse_tag_u=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_xbord=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_xshad=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_ybord=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_yshad=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_1a=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_1c=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_2a=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_2c=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_3a=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_3c=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_4a=function(){throw new Error("Method not implemented.")},e.prototype.parse_tag_4c=function(){throw new Error("Method not implemented.")},e.prototype.parse_drawingInstructions=function(e){var t=new h(e),r=null,n=[];for(t.value=[];this.n();){for(;null!==this.read(t," "););if(!this.n())break;if(null!==r){var o=this.parse_decimal(t);if(null!==o){n.push(o),"m"===r&&2===n.length?(t.value.push(new i.drawing.MoveInstruction(n[0].value,n[1].value)),n.splice(0,n.length)):"l"===r&&2===n.length?(t.value.push(new i.drawing.LineInstruction(n[0].value,n[1].value)),n.splice(0,n.length)):"b"===r&&6===n.length&&(t.value.push(new i.drawing.CubicBezierCurveInstruction(n[0].value,n[1].value,n[2].value,n[3].value,n[4].value,n[5].value)),n.splice(0,n.length));continue}}var a=this.parse_text(t);if(null===a)break;var l=a.value.value;switch(l){case"m":case"l":case"b":r=l,n.splice(0,n.length)}}for(;null!==this.read(t," "););return t},e.prototype.parse_decimalInt32=function(e){for(var t=new h(e),r=null!==this.read(t,"-"),n=new h(t,""),i=this.i();this.n()&&i>="0"&&"9">=i;i=this.i())n.value+=i;if(0===n.value.length)return e.pop(),null;var o=parseInt(n.value);return o>=4294967295?o=4294967295:r&&(o=-o),t.value=o,t},e.prototype.parse_hexInt32=function(e){for(var t=new h(e),r=null!==this.read(t,"-"),n=new h(t,""),i=this.i();this.n()&&(i>="0"&&"9">=i||i>="a"&&"f">=i||i>="A"&&"F">=i);i=this.i())n.value+=i;if(0===n.value.length)return e.pop(),null;var o=parseInt(n.value,16);return o>=4294967295?o=4294967295:r&&(o=-o),t.value=o,t},e.prototype.parse_decimalOrHexInt32=function(e){var t=new h(e),r=null!==this.read(t,"&H")||null!==this.read(t,"&h")?this.parse_hexInt32(t):this.parse_decimalInt32(t);return null===r?(e.pop(),null):(t.value=r.value,t)},e.prototype.parse_decimal=function(e){var t=new h(e),r=null!==this.read(t,"-"),n=this.parse_unsignedDecimal(t);return null===n?(e.pop(),null):(t.value=n.value,r&&(t.value=-t.value),t)},e.prototype.parse_unsignedDecimal=function(e){for(var t=new h(e),r=new h(t,""),n=null,i=this.i();this.n()&&i>="0"&&"9">=i;i=this.i())r.value+=i;if(0===r.value.length)return e.pop(),null;if(null!==this.read(t,".")){n=new h(t,"");for(var i=this.i();this.n()&&i>="0"&&"9">=i;i=this.i())n.value+=i;if(0===n.value.length)return e.pop(),null}return t.value=parseFloat(r.value+(null!==n?"."+n.value:"")),t},e.prototype.parse_enableDisable=function(e){var t=this.i();if("0"===t||"1"===t){var r=new h(e,t);return r.value="1"===r.value,r}return null},e.prototype.parse_color=function(e){for(var t=new h(e);null!==this.read(t,"&")||null!==this.read(t,"H"););var r=this.parse_hexInt32(t);if(null===r)return e.pop(),null;var n=r.value;for(t.value=new i.Color(255&n,n>>8&255,n>>16&255);null!==this.read(t,"&")||null!==this.read(t,"H"););return t},e.prototype.parse_alpha=function(e){for(var t=new h(e);null!==this.read(t,"&")||null!==this.read(t,"H"););var r=this.parse_hexInt32(t);if(null===r)return e.pop(),null;var n=r.value;for(t.value=1-(255&n)/255;null!==this.read(t,"&")||null!==this.read(t,"H"););return t},e.prototype.parse_colorWithAlpha=function(e){var t=new h(e),r=this.parse_decimalOrHexInt32(t);if(null===r)return e.pop(),null;var n=r.value;return t.value=new i.Color(255&n,n>>8&255,n>>16&255,1-(n>>24&255)/255),t},e.prototype.read=function(e,t){return this.i(t.length)!==t?null:new h(e,t)},e.prototype.i=function(e){return void 0===e&&(e=1),1===e?this.e[this.t.end]:this.e.substr(this.t.end,e)},e.prototype.n=function(){return this.t.end0?this.c(this.l[this.l.length-1].end):this.c(this.start)},e.prototype.c=function(e){this.u=e,null!==this.a&&this.a.end!==this.u&&this.a.c(this.u)},e}(),f=t(32),d=t(36),_=t(38);_.registerWorkerCommand(d.WorkerCommands.Parse,function(e){return new f.Promise(function(t){t(r(e.input,e.rule))})})},function(e,t){function r(e){for(var t="",r=0;rn||n>63)throw new Error("Out-of-range character code "+n+" at index "+r+" in string "+e);t+=26>n?String.fromCharCode("A".charCodeAt(0)+n):52>n?String.fromCharCode("a".charCodeAt(0)+n-26):62>n?String.fromCharCode("0".charCodeAt(0)+n-52):62===n?"+":"/"}return t}var n,i=t(23),o=t(24),a=t(29),l=t(26),s=t(25),u=t(30),p=t(32),c=t(2);!function(e){e[e.ScriptInfo=0]="ScriptInfo",e[e.Styles=1]="Styles",e[e.Events=2]="Events",e[e.Fonts=3]="Fonts",e[e.Graphics=4]="Graphics",e[e.Other=5]="Other",e[e.EOF=6]="EOF"}(n||(n={}));var h=function(){function e(e){var t=this;this.h=e,this.f=new o.ASS,this.d=new p.DeferredPromise,this._=new p.DeferredPromise,this.g=!0,this.v=n.ScriptInfo,this.y=null,this.h.nextLine().then(function(e){return t.m(e)},function(e){t.d.reject(e),t._.reject(e)})}return Object.defineProperty(e.prototype,"minimalASS",{get:function(){return this.d.promise},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ass",{get:function(){return this._.promise},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"currentSection",{get:function(){return this.v},set:function(e){if(null!==this.y&&(this.f.addAttachment(this.y),this.y=null),this.v===n.ScriptInfo&&e!==n.ScriptInfo&&this.d.resolve(this.f),e===n.EOF){var t=this.f.properties;void 0===t.resolutionX||void 0===t.resolutionY?(this.d.reject("Malformed ASS script."),this._.reject("Malformed ASS script.")):(this.d.resolve(this.f),this._.resolve(this.f))}this.v=e},enumerable:!0,configurable:!0}),e.prototype.m=function(e){var t=this;if(null===e)return void(this.currentSection=n.EOF);if("\r"===e[e.length-1]&&(e=e.substr(0,e.length-1)),65279===e.charCodeAt(0)&&this.g&&(e=e.substr(1)),this.g=!1,""===e);else if(";"===e[0]&&null===this.y);else if("[Script Info]"===e)this.currentSection=n.ScriptInfo;else if("[V4+ Styles]"===e||"[V4 Styles]"===e)this.currentSection=n.Styles;else if("[Events]"===e)this.currentSection=n.Events;else if("[Fonts]"===e)this.currentSection=n.Fonts;else if("[Graphics]"===e)this.currentSection=n.Graphics;else switch(null===this.y&&"["===e[0]&&"]"===e[e.length-1]&&(this.currentSection=n.Other),this.currentSection){case n.ScriptInfo:var o=c.parseLineIntoProperty(e);if(null!==o)switch(o.name){case"PlayResX":this.f.properties.resolutionX=parseInt(o.value);break;case"PlayResY":this.f.properties.resolutionY=parseInt(o.value);break;case"WrapStyle":this.f.properties.wrappingStyle=parseInt(o.value);break;case"ScaledBorderAndShadow":this.f.properties.scaleBorderAndShadow="yes"===o.value}break;case n.Styles:if(null===this.f.stylesFormatSpecifier){var a=c.parseLineIntoProperty(e);null!==a&&"Format"===a.name&&(this.f.stylesFormatSpecifier=a.value.split(",").map(function(e){return e.trim()}))}else try{this.f.addStyle(e)}catch(t){i.debugMode&&console.error("Could not parse style from line "+e+" - "+(t.stack||t))}break;case n.Events:if(null===this.f.dialoguesFormatSpecifier){var l=c.parseLineIntoProperty(e);null!==l&&"Format"===l.name&&(this.f.dialoguesFormatSpecifier=l.value.split(",").map(function(e){return e.trim()}))}else try{this.f.addEvent(e)}catch(t){i.debugMode&&console.error("Could not parse event from line "+e+" - "+(t.stack||t))}break;case n.Fonts:case n.Graphics:var u=this.currentSection===n.Fonts?/^fontname:(.+)/:/^filename:(.+)/,p=u.exec(e);if(null!==p)null!==this.y&&(this.f.addAttachment(this.y),this.y=null),this.y=new s.Attachment(p[1].trim(),this.currentSection===n.Fonts?s.AttachmentType.Font:s.AttachmentType.Graphic);else if(null!==this.y)try{this.y.contents+=r(e)}catch(e){i.debugMode&&console.error("Encountered error while reading font "+this.y.filename+": %o",e),this.y=null}break;case n.Other:break;default:throw new Error("Unhandled state "+this.currentSection)}this.h.nextLine().then(function(e){return t.m(e)},function(e){t.d.reject(e),t._.reject(e)})},e}();e.StreamParser=h;var f=function(){function e(e){var t=this;this.h=e,this.f=new o.ASS,this._=new p.DeferredPromise,this.g=!0,this.b=null,this.w=null,this.S=null,this.O=null,this.h.nextLine().then(function(e){return t.m(e)},function(e){t._.reject(e)}),this.f.properties.resolutionX=1280,this.f.properties.resolutionY=720,this.f.properties.wrappingStyle=1,this.f.properties.scaleBorderAndShadow=!0;var r=new a.Style(new u.Map([["Name","Default"],["FontSize","36"]]));this.f.styles.set(r.name,r)}return Object.defineProperty(e.prototype,"ass",{get:function(){return this._.promise},enumerable:!0,configurable:!0}),e.prototype.m=function(e){var t=this;if(null===e)return null!==this.b&&null!==this.w&&null!==this.S&&null!==this.O&&this.f.dialogues.push(new l.Dialogue(new u.Map([["Style","Default"],["Start",this.w],["End",this.S],["Text",this.O]]),this.f)),void this._.resolve(this.f);if("\r"===e[e.length-1]&&(e=e.substr(0,e.length-1)),65279===e.charCodeAt(0)&&this.g&&(e=e.substr(1)),this.g=!1,""===e)null!==this.b&&null!==this.w&&null!==this.S&&null!==this.O&&this.f.dialogues.push(new l.Dialogue(new u.Map([["Style","Default"],["Start",this.w],["End",this.S],["Text",this.O]]),this.f)),this.b=this.w=this.S=this.O=null;else if(null===this.b)/^\d+$/.test(e)&&(this.b=e);else if(null===this.w&&null===this.S){var r=/^(\d\d:\d\d:\d\d,\d\d\d) --> (\d\d:\d\d:\d\d,\d\d\d)/.exec(e);null!==r&&(this.w=r[1].replace(",","."),this.S=r[2].replace(",","."))}else e=e.replace(//g,"{\\b1}").replace(/\{b\}/g,"{\\b1}").replace(/<\/b>/g,"{\\b0}").replace(/\{\/b\}/g,"{\\b0}").replace(//g,"{\\i1}").replace(/\{i\}/g,"{\\i1}").replace(/<\/i>/g,"{\\i0}").replace(/\{\/i\}/g,"{\\i0}").replace(//g,"{\\u1}").replace(/\{u\}/g,"{\\u1}").replace(/<\/u>/g,"{\\u0}").replace(/\{\/u\}/g,"{\\u0}").replace(//g,function(e,t,r,n){return"{c&H"+n+r+t+"&}"}).replace(/<\/font>/g,"{\\c}"),null!==this.O?this.O+="\\N"+e:this.O=e;this.h.nextLine().then(function(e){return t.m(e)},function(e){t._.reject(e)})},e}();e.SrtStreamParser=f},function(t,r){var n=r(32),i=function(){function e(e){this.P=e,this.C=0}return e.prototype.nextLine=function(){var e=null;if(this.C0?" ":"")+"}"}}},ie=t(38),oe=0,ae=Object.keys(e);oethis.ce?(this._e=null,this.he.pause()):this.he.tick((e-this._e)/1e3*this.he.rate+this.de):(this.de=i,this._e=e,this.he.tick(i)),this.fe=requestAnimationFrame(function(e){return t.ye(e)})},e.prototype.ge=function(){var e=this;null===this.fe&&(this.fe=requestAnimationFrame(function(t){return e.ye(t)}))},e.prototype.ve=function(){null!==this.fe&&(cancelAnimationFrame(this.fe),this.fe=null)},e}();e.AutoClock=i},function(e){var t=function(){function e(){}return e.prototype.addEventListener=function(e,t){var r=this.me.get(e);void 0===r&&this.me.set(e,r=[]),r.push(t)},e.prototype.be=function(e,t){var r=this.me.get(e);if(void 0!==r)for(var n=0;na)return null;var u=document.createElement("div");u.style.marginLeft=(this.ot*e.style.marginLeft).toFixed(3)+"px",u.style.marginRight=(this.ot*e.style.marginRight).toFixed(3)+"px",u.style.marginTop=u.style.marginBottom=(this.at*e.style.marginVertical).toFixed(3)+"px",u.style.minWidth=(this.it-this.ot*(e.style.marginLeft+e.style.marginRight)).toFixed(3)+"px";var p=document.createElement("style");p.id="libjass-animation-styles-"+this.id+"-"+e.id,p.type="text/css";var c=new i.AnimationCollection(this,p),d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("version","1.1"),d.setAttribute("class","libjass-filters"),d.width.baseVal.valueAsString="0",d.height.baseVal.valueAsString="0";var g=document.createElementNS("http://www.w3.org/2000/svg","defs");d.appendChild(g);var y=null,m=new s.SpanStyles(this,e,this.ot,this.at,this.settings,this.tt,g,this.Je),b=null,w=!1,S=function(e){null!==y&&y.hasChildNodes()&&u.appendChild(m.setStylesOnSpan(y,b)),null!==b&&b.animationDelays.forEach(function(e,t){return c.animationDelays.set(t,e)}),e&&(w?u.appendChild(m.makeNewLine()):u.appendChild(document.createElement("br"))),y=document.createElement("span"),b=new i.AnimationCollection(t,p),w=e};S(!1);for(var O=new o.DrawingStyles(this.ot,this.at),P=this.ass.properties.wrappingStyle,C=0,k=0,E=e.parts;k=x.end?1:Math.pow((a-x.start)/(x.end-x.start),x.accel),A=0,T=x.tags;Ar||n.end0||r>0){var l=0,s=!this.De.preciseOutlines&&this.It>0?this.It:1;!function(e){if(r>=t)if(t>0){var n;for(n=0;t>=n;n+=s)e(n,r/t*Math.sqrt(t*t-n*n));n!==t+s&&e(t,0)}else e(0,r);else if(r>0){var i;for(i=0;r>=i;i+=s)e(t/r*Math.sqrt(r*r-i*i),i);i!==r+s&&e(0,r)}else e(t,0)}(function(e,t){var r=document.createElementNS("http://www.w3.org/2000/svg","feMorphology");a.appendChild(r),r.in1.baseVal="source",r.operator.baseVal=SVGFEMorphologyElement.SVG_MORPHOLOGY_OPERATOR_DILATE,r.radiusX.baseVal=e,r.radiusY.baseVal=t,r.result.baseVal="outline"+l,l++});var u=document.createElementNS("http://www.w3.org/2000/svg","feComponentTransfer");a.insertBefore(u,a.firstElementChild),u.in1.baseVal="SourceAlpha",u.result.baseVal="source";var p=document.createElementNS("http://www.w3.org/2000/svg","feFuncA");u.appendChild(p),p.type.baseVal=SVGComponentTransferFunctionElement.SVG_FECOMPONENTTRANSFER_TYPE_LINEAR,p.slope.baseVal=0===i?1:1/i,p.intercept.baseVal=0;var c=document.createElementNS("http://www.w3.org/2000/svg","feMerge");a.appendChild(c);for(var h=0;l>h;h++){var f=document.createElementNS("http://www.w3.org/2000/svg","feMergeNode");c.appendChild(f),f.in1.baseVal="outline"+h}var d=document.createElementNS("http://www.w3.org/2000/svg","feComponentTransfer");a.appendChild(d),d.setAttribute("color-interpolation-filters","sRGB");var _=document.createElementNS("http://www.w3.org/2000/svg","feFuncR");d.appendChild(_),_.type.baseVal=SVGComponentTransferFunctionElement.SVG_FECOMPONENTTRANSFER_TYPE_LINEAR,_.slope.baseVal=0,_.intercept.baseVal=n.red/255*n.alpha;var g=document.createElementNS("http://www.w3.org/2000/svg","feFuncG");d.appendChild(g),g.type.baseVal=SVGComponentTransferFunctionElement.SVG_FECOMPONENTTRANSFER_TYPE_LINEAR,g.slope.baseVal=0,g.intercept.baseVal=n.green/255*n.alpha;var v=document.createElementNS("http://www.w3.org/2000/svg","feFuncB");d.appendChild(v),v.type.baseVal=SVGComponentTransferFunctionElement.SVG_FECOMPONENTTRANSFER_TYPE_LINEAR,v.slope.baseVal=0,v.intercept.baseVal=n.blue/255*n.alpha;var y=document.createElementNS("http://www.w3.org/2000/svg","feFuncA");if(d.appendChild(y),y.type.baseVal=SVGComponentTransferFunctionElement.SVG_FECOMPONENTTRANSFER_TYPE_LINEAR,y.slope.baseVal=n.alpha,y.intercept.baseVal=0,this.It>0){var m=document.createElementNS("http://www.w3.org/2000/svg","feGaussianBlur");a.appendChild(m),m.stdDeviationX.baseVal=this.It,m.stdDeviationY.baseVal=this.It}for(var h=0;h0){var m=document.createElementNS("http://www.w3.org/2000/svg","feGaussianBlur");a.appendChild(m),m.stdDeviationX.baseVal=this.It,m.stdDeviationY.baseVal=this.It}for(var h=0;h0&&(this.ut.appendChild(a),e.style.webkitFilter='url("#'+o+'")',e.style.filter='url("#'+o+'")')},e.prototype.Lt=function(e,t,r,n){var i=this;if(t>0||r>0){var o="";!function(e){for(var n=0;t>=n;n++)for(var i=0===t?r:r*Math.sqrt(1-n*n/(t*t)),o=0;i>=o;o++)e(n,o),0!==n&&e(-n,o),0!==o&&e(n,-o),0!==n&&0!==o&&e(-n,-o)}(function(e,t){o+=", "+n.toString()+" "+e+"px "+t+"px "+i.It.toFixed(3)+"px"}),e.style.textShadow=o.substr(", ".length)}},e.prototype.makeNewLine=function(){var e=document.createElement("br");return e.style.lineHeight=(this.at*this.bt).toFixed(3)+"px",e},Object.defineProperty(e.prototype,"italic",{set:function(t){this.vt=e.Ct(t,this.ct.italic)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bold",{set:function(t){this.yt=e.Ct(t,this.ct.bold)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"underline",{set:function(t){this.St=e.Ct(t,this.ct.underline)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"strikeThrough",{set:function(t){this.Ot=e.Ct(t,this.ct.strikeThrough)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outlineWidth",{get:function(){return this.Et},set:function(t){this.Et=e.Ct(t,this.ct.outlineThickness)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outlineHeight",{get:function(){return this.Et},set:function(t){this.xt=e.Ct(t,this.ct.outlineThickness)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowDepthX",{get:function(){return this.Rt},set:function(t){this.Rt=e.Ct(t,this.ct.shadowDepth)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowDepthY",{get:function(){return this.Nt},set:function(t){this.Nt=e.Ct(t,this.ct.shadowDepth)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blur",{get:function(){return this.Xt},set:function(t){this.Xt=e.Ct(t,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"gaussianBlur",{get:function(){return this.It},set:function(t){this.It=e.Ct(t,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontName",{set:function(t){this.mt=e.Ct(t,this.ct.fontName)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontSize",{get:function(){return this.bt},set:function(t){this.bt=e.Ct(t,this.ct.fontSize)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontScaleX",{get:function(){return this.wt},set:function(t){this.wt=e.Ct(t,this.ct.fontScaleX)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontScaleY",{get:function(){return this.Pt},set:function(t){this.Pt=e.Ct(t,this.ct.fontScaleY)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"letterSpacing",{get:function(){return this.kt},set:function(t){this.kt=e.Ct(t,this.ct.letterSpacing)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationX",{get:function(){return this.ht},set:function(e){this.ht=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationY",{get:function(){return this.ft},set:function(e){this.ft=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationZ",{get:function(){return this.dt},set:function(t){this.dt=e.Ct(t,this.ct.rotationZ)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"skewX",{get:function(){return this._t},set:function(e){this._t=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"skewY",{get:function(){return this.gt},set:function(e){this.gt=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"primaryColor",{get:function(){return this.jt},set:function(t){this.jt=e.Ct(t,this.ct.primaryColor)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondaryColor",{get:function(){return this.Yt},set:function(t){this.Yt=e.Ct(t,this.ct.secondaryColor)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outlineColor",{get:function(){return this.Tt},set:function(t){this.Tt=e.Ct(t,this.ct.outlineColor)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowColor",{get:function(){return this.Ft},set:function(t){this.Ft=e.Ct(t,this.ct.shadowColor)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"primaryAlpha",{get:function(){return this.At},set:function(t){this.At=e.Ct(t,this.ct.primaryColor.alpha)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondaryAlpha",{get:function(){return this.Vt},set:function(t){this.Vt=e.Ct(t,this.ct.secondaryColor.alpha)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outlineAlpha",{get:function(){return this.Dt},set:function(t){this.Dt=e.Ct(t,this.ct.outlineColor.alpha)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowAlpha",{get:function(){return this.Mt},set:function(t){this.Mt=e.Ct(t,this.ct.shadowColor.alpha)},enumerable:!0,configurable:!0}),e.Ct=function(e,t){return null!==e?e:t},e}();e.SpanStyles=n},function(e){function t(t){e.debugMode=t}function r(t){e.verboseMode=t}e.debugMode=!1,e.verboseMode=!1,e.setDebugMode=t,e.setVerboseMode=r},function(t,r){var n=r(26),i=r(29),o=r(28),a=r(27),l=r(23),s=r(1),u=r(2),p=r(30),c=r(32),h=function(){function t(){if(this.Ue=new o.ScriptProperties,this.Bt=new p.Map,this.zt=[],this.Gt=[],this.qt=null,this.Ut=null,1===arguments.length)throw new Error("Constructor `new ASS(rawASS)` has been deprecated. Use `ASS.fromString(rawASS)` instead.");this.Bt.set("Default",new i.Style(new p.Map([["Name","Default"]])))}return Object.defineProperty(t.prototype,"properties",{get:function(){return this.Ue},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"styles",{get:function(){return this.Bt},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dialogues",{get:function(){return this.zt},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"attachments",{get:function(){return this.Gt},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stylesFormatSpecifier",{get:function(){return this.qt},set:function(e){this.qt=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dialoguesFormatSpecifier",{get:function(){return this.Ut},set:function(e){this.Ut=e},enumerable:!0,configurable:!0}),t.prototype.addStyle=function(e){var t=u.parseLineIntoTypedTemplate(e,this.qt);if(null!==t&&"Style"===t.type){var r=t.template;if(l.verboseMode){var n="";r.forEach(function(e,t){return n+=t+" = "+e+", "}),console.log("Read style: "+n)}var o=new i.Style(r);this.Bt.set(o.name,o)}},t.prototype.addEvent=function(e){var t=u.parseLineIntoTypedTemplate(e,this.Ut);if(null!==t&&"Dialogue"===t.type){var r=t.template;if(l.verboseMode){var i="";r.forEach(function(e,t){return i+=t+" = "+e+", "}),console.log("Read dialogue: "+i)}this.dialogues.push(new n.Dialogue(r,this))}},t.prototype.addAttachment=function(e){this.Gt.push(e)},t.fromString=function(e,r){return void 0===r&&(r=a.Format.ASS),t.fromStream(new s.StringStream(e),r)},t.fromStream=function(e,t){switch(void 0===t&&(t=a.Format.ASS),t){case a.Format.ASS:return new s.StreamParser(e).ass;case a.Format.SRT:return new s.SrtStreamParser(e).ass;default:throw new Error("Illegal value of type: "+t)}},t.fromUrl=function(r,n){void 0===n&&(n=a.Format.ASS);var i;return i="function"==typeof e.fetch&&"function"==typeof e.ReadableStream&&"function"==typeof e.ReadableStream.prototype.getReader&&"function"==typeof e.TextDecoder?e.fetch(r).then(function(e){if(e.ok===!1||void 0===e.ok&&(e.status<200||e.status>299))throw new Error("HTTP request for "+r+" failed with status code "+e.status);return t.fromReadableStream(e.body,"utf-8",n)}):c.Promise.reject(new Error("Not supported.")),i.catch(function(e){console.warn("fetch() failed, falling back to XHR: %o",e);var i=new XMLHttpRequest,o=t.fromStream(new s.XhrStream(i),n);return i.open("GET",r,!0),i.send(),o})},t.fromReadableStream=function(e,r,n){return void 0===r&&(r="utf-8"),void 0===n&&(n=a.Format.ASS),t.fromStream(new s.BrowserReadableStream(e,r),n)},t}();t.ASS=h},function(e){!function(e){e[e.Font=0]="Font",e[e.Graphic=1]="Graphic"}(e.AttachmentType||(e.AttachmentType={}));var t=function(){function e(e,t){this.Ht=e,this.Kt=t,this.Zt=""}return Object.defineProperty(e.prototype,"filename",{get:function(){return this.Ht},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this.Kt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"contents",{get:function(){return this.Zt},set:function(e){this.Zt=e},enumerable:!0,configurable:!0}),e}();e.Attachment=t},function(e,t){var r=t(27),n=t(3),i=t(8),o=t(23),a=t(30),l=function(){function e(t,n){this.Jt=null,this.$t=!1;var i=new a.Map;t.forEach(function(e,t){i.set(t.toLowerCase(),e)}),t=i,this.Ae=++e.Qt;var l=t.get("style");if(void 0!==l&&null!==l&&l.constructor===String&&(l=l.replace(/^\*+/,""),null!==l.match(/^Default$/i)&&(l="Default")),this.Le=n.styles.get(l),void 0===this.Le&&(o.debugMode&&console.warn("Unrecognized style "+l+'. Falling back to "Default"'),this.Le=n.styles.get("Default")),void 0===this.Le)throw new Error("Unrecognized style "+l);if(this.s=e.er(t.get("start")),this.u=e.er(t.get("end")),this.tr=Math.max(r.valueOrDefault(t,"layer",parseInt,function(e){return!isNaN(e)},"0"),0),this.rr=t.get("text"),void 0===this.rr||null===this.rr||this.rr.constructor!==String)throw new Error("Dialogue doesn't have any text.")}return Object.defineProperty(e.prototype,"id",{get:function(){return this.Ae},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"start",{get:function(){return this.s},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"end",{get:function(){return this.u},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"style",{get:function(){return this.Le},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alignment",{get:function(){return null===this.Jt&&this.nr(),this.ir},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"layer",{get:function(){return this.tr},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parts",{get:function(){return null===this.Jt&&this.nr(),this.Jt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"containsTransformTag",{get:function(){return null===this.Jt&&this.nr(),this.$t},enumerable:!0,configurable:!0}),e.prototype.toString=function(){return"#"+this.Ae+" ["+this.s.toFixed(3)+"-"+this.u.toFixed(3)+"] "+(null!==this.Jt?this.Jt.join(", "):this.rr)},e.prototype.nr=function(){var e=this;if(this.Jt=n.parse(this.rr,"dialogueParts"),this.ir=this.Le.alignment,this.Jt.forEach(function(t,r){t instanceof i.Alignment?e.ir=t.value:t instanceof i.Move?(null===t.t1||null===t.t2)&&(e.Jt[r]=new i.Move(t.x1,t.y1,t.x2,t.y2,0,e.u-e.s)):t instanceof i.Transform&&((null===t.start||null===t.end||null===t.accel)&&(e.Jt[r]=new i.Transform(null===t.start?0:t.start,null===t.end?e.u-e.s:t.end,null===t.accel?1:t.accel,t.tags)),e.$t=!0)}),o.debugMode){var t=this.Jt.filter(function(e){return e instanceof i.Comment&&-1!==e.value.indexOf("\\")});t.length>0&&console.warn("Possible incorrect parse:\n"+this.rr+"\nwas parsed as\n"+this.toString()+"\nThe possibly incorrect parses are:\n"+t.join("\n"))}},e.er=function(e){return e.split(":").reduce(function(e,t){return 60*e+parseFloat(t)},0)},e.Qt=-1,e}();e.Dialogue=l},function(e){function t(e,t,r,n,i){var o=e.get(t);if(void 0===o)return r(i);try{var a=r(o);if(null!==n&&!n(a))throw new Error("Validation failed.");return a}catch(e){throw new Error("Property "+t+" has invalid value "+o+" - "+e.stack)}}!function(e){e[e.ASS=0]="ASS",e[e.SRT=1]="SRT"}(e.Format||(e.Format={})),function(e){e[e.SmartWrappingWithWiderTopLine=0]="SmartWrappingWithWiderTopLine",e[e.SmartWrappingWithWiderBottomLine=3]="SmartWrappingWithWiderBottomLine",e[e.EndOfLineWrapping=1]="EndOfLineWrapping",e[e.NoLineWrapping=2]="NoLineWrapping"}(e.WrappingStyle||(e.WrappingStyle={})),function(e){e[e.Outline=1]="Outline",e[e.OpaqueBox=3]="OpaqueBox"}(e.BorderStyle||(e.BorderStyle={})),e.valueOrDefault=t},function(e){var t=function(){function e(){}return Object.defineProperty(e.prototype,"resolutionX",{get:function(){return this.or},set:function(e){this.or=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"resolutionY",{get:function(){return this.ar},set:function(e){this.ar=e},enumerable:!0, configurable:!0}),Object.defineProperty(e.prototype,"wrappingStyle",{get:function(){return this.lr},set:function(e){this.lr=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scaleBorderAndShadow",{get:function(){return this.sr},set:function(e){this.sr=e},enumerable:!0,configurable:!0}),e}();e.ScriptProperties=t},function(e,t){var r=t(27),n=t(3),i=t(30),o=function(){function e(e){var t=new i.Map;if(e.forEach(function(e,r){t.set(r.toLowerCase(),e)}),e=t,this.ur=e.get("name"),void 0===this.ur||null===this.ur||this.ur.constructor!==String)throw new Error("Style doesn't have a name.");this.ur=this.ur.replace(/^\*+/,""),this.vt=!!r.valueOrDefault(e,"italic",parseFloat,function(e){return!isNaN(e)},"0"),this.yt=!!r.valueOrDefault(e,"bold",parseFloat,function(e){return!isNaN(e)},"0"),this.St=!!r.valueOrDefault(e,"underline",parseFloat,function(e){return!isNaN(e)},"0"),this.Ot=!!r.valueOrDefault(e,"strikeout",parseFloat,function(e){return!isNaN(e)},"0"),this.mt=r.valueOrDefault(e,"fontname",function(e){return e},function(e){return e.constructor===String},"sans-serif"),this.bt=r.valueOrDefault(e,"fontsize",parseFloat,function(e){return!isNaN(e)},"18"),this.wt=r.valueOrDefault(e,"scalex",parseFloat,function(e){return e>=0},"100")/100,this.Pt=r.valueOrDefault(e,"scaley",parseFloat,function(e){return e>=0},"100")/100,this.kt=r.valueOrDefault(e,"spacing",parseFloat,function(e){return e>=0},"0"),this.dt=r.valueOrDefault(e,"angle",parseFloat,function(e){return!isNaN(e)},"0"),this.jt=r.valueOrDefault(e,"primarycolour",function(e){return n.parse(e,"colorWithAlpha")},null,"&H00FFFFFF"),this.Yt=r.valueOrDefault(e,"secondarycolour",function(e){return n.parse(e,"colorWithAlpha")},null,"&H00FFFF00"),this.Tt=r.valueOrDefault(e,"outlinecolour",function(e){return n.parse(e,"colorWithAlpha")},null,"&H00000000"),this.Ft=r.valueOrDefault(e,"backcolour",function(e){return n.parse(e,"colorWithAlpha")},null,"&H80000000"),this.pr=r.valueOrDefault(e,"outline",parseFloat,function(e){return e>=0},"2"),this.cr=r.valueOrDefault(e,"borderstyle",parseInt,function(e){return r.BorderStyle[r.BorderStyle[e]]===e},"1"),this.hr=r.valueOrDefault(e,"shadow",parseFloat,function(e){return e>=0},"3"),this.ir=r.valueOrDefault(e,"alignment",parseInt,function(e){return e>=1&&9>=e},"2"),this.fr=r.valueOrDefault(e,"marginl",parseFloat,function(e){return!isNaN(e)},"20"),this.dr=r.valueOrDefault(e,"marginr",parseFloat,function(e){return!isNaN(e)},"20"),this._r=r.valueOrDefault(e,"marginv",parseFloat,function(e){return!isNaN(e)},"20")}return Object.defineProperty(e.prototype,"name",{get:function(){return this.ur},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"italic",{get:function(){return this.vt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bold",{get:function(){return this.yt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"underline",{get:function(){return this.St},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"strikeThrough",{get:function(){return this.Ot},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontName",{get:function(){return this.mt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontSize",{get:function(){return this.bt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontScaleX",{get:function(){return this.wt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontScaleY",{get:function(){return this.Pt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"letterSpacing",{get:function(){return this.kt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationZ",{get:function(){return this.dt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"primaryColor",{get:function(){return this.jt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondaryColor",{get:function(){return this.Yt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outlineColor",{get:function(){return this.Tt},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowColor",{get:function(){return this.Ft},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outlineThickness",{get:function(){return this.pr},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"borderStyle",{get:function(){return this.cr},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowDepth",{get:function(){return this.hr},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alignment",{get:function(){return this.ir},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"marginLeft",{get:function(){return this.fr},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"marginRight",{get:function(){return this.dr},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"marginVertical",{get:function(){return this._r},enumerable:!0,configurable:!0}),e}();e.Style=o},function(t){function r(e){null!==e?t.Map=e:t.Map=n}t.Map=e.Map;var n=function(){function e(e){if(this.clear(),void 0!==e){if(!Array.isArray(e))throw new Error("Non-array iterables are not supported by the SimpleMap constructor.");for(var t=0;t0&&(i.classList.toggle("foo"),n=!0)});return o.observe(i,{attributes:!0}),function(e){r.push(e),n||(i.classList.toggle("foo"),n=!0)}}return function(e){return setTimeout(e,0)}}(),s=function(){function e(e){if(this.br=u.PENDING,this.wr=[],this.Sr=[],this.Or=null,this.Pr=null,"function"!=typeof e)throw new TypeError('typeof executor !== "function"');var t=this.Cr(),r=t.resolve,n=t.reject;try{e(r,n)}catch(e){n(e)}}return e.prototype.then=function(e,t){var r=new p;"function"!=typeof e&&(e=function(e){return e}),"function"!=typeof t&&(t=function(e){throw e});var n={capabilities:r,handler:e},i={capabilities:r,handler:t};switch(this.br){case u.PENDING:this.wr.push(n),this.Sr.push(i);break;case u.FULFILLED:this.kr(n,this.Or);break;case u.REJECTED:this.Er(i,this.Pr)}return r.promise},e.prototype.catch=function(e){return this.then(null,e)},e.resolve=function(r){return r instanceof e?r:new t.Promise(function(e){return e(r)})},e.reject=function(e){return new t.Promise(function(t,r){return r(e)})},e.all=function(e){return new t.Promise(function(r,n){var i=[],o=e.length;return 0===o?void r(i):void e.forEach(function(e,a){return t.Promise.resolve(e).then(function(e){i[a]=e,o--,0===o&&r(i)},n)})})},e.race=function(e){return new t.Promise(function(r,n){for(var i=0;i