@byomakase/omakase-player 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@
7
7
  * https://github.com/MikeMcl/decimal.js
8
8
  * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
9
9
  * MIT Licence
10
- */var ei=9e15,Dt=1e9,Ns="0123456789abcdef",$r="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Vr="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Gs={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ei,maxE:ei,crypto:!1},qo,ht,q=!0,Kr="[DecimalError] ",Lt=Kr+"Invalid argument: ",Yo=Kr+"Precision limit exceeded",Ko=Kr+"crypto unavailable",Jo="[object Decimal]",Me=Math.floor,Se=Math.pow,Wc=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Uc=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Zc=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Qo=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,je=1e7,j=7,jc=9007199254740991,Xc=$r.length-1,Ds=Vr.length-1,C={toStringTag:Jo};C.absoluteValue=C.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),z(r)};C.ceil=function(){return z(new this.constructor(this),this.e+1,2)};C.clampedTo=C.clamp=function(r,e){var t,i=this,s=i.constructor;if(r=new s(r),e=new s(e),!r.s||!e.s)return new s(NaN);if(r.gt(e))throw Error(Lt+e);return t=i.cmp(r),t<0?r:i.cmp(e)>0?e:new s(i)};C.comparedTo=C.cmp=function(r){var e,t,i,s,n=this,a=n.d,o=(r=new n.constructor(r)).d,h=n.s,l=r.s;if(!a||!o)return!h||!l?NaN:h!==l?h:a===o?0:!a^h<0?1:-1;if(!a[0]||!o[0])return a[0]?h:o[0]?-l:0;if(h!==l)return h;if(n.e!==r.e)return n.e>r.e^h<0?1:-1;for(i=a.length,s=o.length,e=0,t=i<s?i:s;e<t;++e)if(a[e]!==o[e])return a[e]>o[e]^h<0?1:-1;return i===s?0:i>s^h<0?1:-1};C.cosine=C.cos=function(){var r,e,t=this,i=t.constructor;return t.d?t.d[0]?(r=i.precision,e=i.rounding,i.precision=r+Math.max(t.e,t.sd())+j,i.rounding=1,t=qc(i,sl(i,t)),i.precision=r,i.rounding=e,z(ht==2||ht==3?t.neg():t,r,e,!0)):new i(1):new i(NaN)};C.cubeRoot=C.cbrt=function(){var r,e,t,i,s,n,a,o,h,l,d=this,u=d.constructor;if(!d.isFinite()||d.isZero())return new u(d);for(q=!1,n=d.s*Se(d.s*d,1/3),!n||Math.abs(n)==1/0?(t=xe(d.d),r=d.e,(n=(r-t.length+1)%3)&&(t+=n==1||n==-2?"0":"00"),n=Se(t,1/3),r=Me((r+1)/3)-(r%3==(r<0?-1:2)),n==1/0?t="5e"+r:(t=n.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),i=new u(t),i.s=d.s):i=new u(n.toString()),a=(r=u.precision)+3;;)if(o=i,h=o.times(o).times(o),l=h.plus(d),i=ue(l.plus(d).times(o),l.plus(h),a+2,1),xe(o.d).slice(0,a)===(t=xe(i.d)).slice(0,a))if(t=t.slice(a-3,a+1),t=="9999"||!s&&t=="4999"){if(!s&&(z(o,r+1,0),o.times(o).times(o).eq(d))){i=o;break}a+=4,s=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(z(i,r+1,1),e=!i.times(i).times(i).eq(d));break}return q=!0,z(i,r,u.rounding,e)};C.decimalPlaces=C.dp=function(){var r,e=this.d,t=NaN;if(e){if(r=e.length-1,t=(r-Me(this.e/j))*j,r=e[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};C.dividedBy=C.div=function(r){return ue(this,new this.constructor(r))};C.dividedToIntegerBy=C.divToInt=function(r){var e=this,t=e.constructor;return z(ue(e,new t(r),0,1,1),t.precision,t.rounding)};C.equals=C.eq=function(r){return this.cmp(r)===0};C.floor=function(){return z(new this.constructor(this),this.e+1,3)};C.greaterThan=C.gt=function(r){return this.cmp(r)>0};C.greaterThanOrEqualTo=C.gte=function(r){var e=this.cmp(r);return e==1||e===0};C.hyperbolicCosine=C.cosh=function(){var r,e,t,i,s,n=this,a=n.constructor,o=new a(1);if(!n.isFinite())return new a(n.s?1/0:NaN);if(n.isZero())return o;t=a.precision,i=a.rounding,a.precision=t+Math.max(n.e,n.sd())+4,a.rounding=1,s=n.d.length,s<32?(r=Math.ceil(s/3),e=(1/Qr(4,r)).toString()):(r=16,e="2.3283064365386962890625e-10"),n=ci(a,1,n.times(e),new a(1),!0);for(var h,l=r,d=new a(8);l--;)h=n.times(n),n=o.minus(h.times(d.minus(h.times(d))));return z(n,a.precision=t,a.rounding=i,!0)};C.hyperbolicSine=C.sinh=function(){var r,e,t,i,s=this,n=s.constructor;if(!s.isFinite()||s.isZero())return new n(s);if(e=n.precision,t=n.rounding,n.precision=e+Math.max(s.e,s.sd())+4,n.rounding=1,i=s.d.length,i<3)s=ci(n,2,s,s,!0);else{r=1.4*Math.sqrt(i),r=r>16?16:r|0,s=s.times(1/Qr(5,r)),s=ci(n,2,s,s,!0);for(var a,o=new n(5),h=new n(16),l=new n(20);r--;)a=s.times(s),s=s.times(o.plus(a.times(h.times(a).plus(l))))}return n.precision=e,n.rounding=t,z(s,e,t,!0)};C.hyperbolicTangent=C.tanh=function(){var r,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+7,i.rounding=1,ue(t.sinh(),t.cosh(),i.precision=r,i.rounding=e)):new i(t.s)};C.inverseCosine=C.acos=function(){var r,e=this,t=e.constructor,i=e.abs().cmp(1),s=t.precision,n=t.rounding;return i!==-1?i===0?e.isNeg()?Ue(t,s,n):new t(0):new t(NaN):e.isZero()?Ue(t,s+4,n).times(.5):(t.precision=s+6,t.rounding=1,e=e.asin(),r=Ue(t,s+4,n).times(.5),t.precision=s,t.rounding=n,r.minus(e))};C.inverseHyperbolicCosine=C.acosh=function(){var r,e,t=this,i=t.constructor;return t.lte(1)?new i(t.eq(1)?0:NaN):t.isFinite()?(r=i.precision,e=i.rounding,i.precision=r+Math.max(Math.abs(t.e),t.sd())+4,i.rounding=1,q=!1,t=t.times(t).minus(1).sqrt().plus(t),q=!0,i.precision=r,i.rounding=e,t.ln()):new i(t)};C.inverseHyperbolicSine=C.asinh=function(){var r,e,t=this,i=t.constructor;return!t.isFinite()||t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+2*Math.max(Math.abs(t.e),t.sd())+6,i.rounding=1,q=!1,t=t.times(t).plus(1).sqrt().plus(t),q=!0,i.precision=r,i.rounding=e,t.ln())};C.inverseHyperbolicTangent=C.atanh=function(){var r,e,t,i,s=this,n=s.constructor;return s.isFinite()?s.e>=0?new n(s.abs().eq(1)?s.s/0:s.isZero()?s:NaN):(r=n.precision,e=n.rounding,i=s.sd(),Math.max(i,r)<2*-s.e-1?z(new n(s),r,e,!0):(n.precision=t=i-s.e,s=ue(s.plus(1),new n(1).minus(s),t+r,1),n.precision=r+4,n.rounding=1,s=s.ln(),n.precision=r,n.rounding=e,s.times(.5))):new n(NaN)};C.inverseSine=C.asin=function(){var r,e,t,i,s=this,n=s.constructor;return s.isZero()?new n(s):(e=s.abs().cmp(1),t=n.precision,i=n.rounding,e!==-1?e===0?(r=Ue(n,t+4,i).times(.5),r.s=s.s,r):new n(NaN):(n.precision=t+6,n.rounding=1,s=s.div(new n(1).minus(s.times(s)).sqrt().plus(1)).atan(),n.precision=t,n.rounding=i,s.times(2)))};C.inverseTangent=C.atan=function(){var r,e,t,i,s,n,a,o,h,l=this,d=l.constructor,u=d.precision,c=d.rounding;if(l.isFinite()){if(l.isZero())return new d(l);if(l.abs().eq(1)&&u+4<=Ds)return a=Ue(d,u+4,c).times(.25),a.s=l.s,a}else{if(!l.s)return new d(NaN);if(u+4<=Ds)return a=Ue(d,u+4,c).times(.5),a.s=l.s,a}for(d.precision=o=u+10,d.rounding=1,t=Math.min(28,o/j+2|0),r=t;r;--r)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(q=!1,e=Math.ceil(o/j),i=1,h=l.times(l),a=new d(l),s=l;r!==-1;)if(s=s.times(h),n=a.minus(s.div(i+=2)),s=s.times(h),a=n.plus(s.div(i+=2)),a.d[e]!==void 0)for(r=e;a.d[r]===n.d[r]&&r--;);return t&&(a=a.times(2<<t-1)),q=!0,z(a,d.precision=u,d.rounding=c,!0)};C.isFinite=function(){return!!this.d};C.isInteger=C.isInt=function(){return!!this.d&&Me(this.e/j)>this.d.length-2};C.isNaN=function(){return!this.s};C.isNegative=C.isNeg=function(){return this.s<0};C.isPositive=C.isPos=function(){return this.s>0};C.isZero=function(){return!!this.d&&this.d[0]===0};C.lessThan=C.lt=function(r){return this.cmp(r)<0};C.lessThanOrEqualTo=C.lte=function(r){return this.cmp(r)<1};C.logarithm=C.log=function(r){var e,t,i,s,n,a,o,h,l=this,d=l.constructor,u=d.precision,c=d.rounding,p=5;if(r==null)r=new d(10),e=!0;else{if(r=new d(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new d(NaN);e=r.eq(10)}if(t=l.d,l.s<0||!t||!t[0]||l.eq(1))return new d(t&&!t[0]?-1/0:l.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)n=!0;else{for(s=t[0];s%10===0;)s/=10;n=s!==1}if(q=!1,o=u+p,a=Pt(l,o),i=e?zr(d,o+10):Pt(r,o),h=ue(a,i,o,1),Zi(h.d,s=u,c))do if(o+=10,a=Pt(l,o),i=e?zr(d,o+10):Pt(r,o),h=ue(a,i,o,1),!n){+xe(h.d).slice(s+1,s+15)+1==1e14&&(h=z(h,u+1,0));break}while(Zi(h.d,s+=10,c));return q=!0,z(h,u,c)};C.minus=C.sub=function(r){var e,t,i,s,n,a,o,h,l,d,u,c,p=this,f=p.constructor;if(r=new f(r),!p.d||!r.d)return!p.s||!r.s?r=new f(NaN):p.d?r.s=-r.s:r=new f(r.d||p.s!==r.s?p:NaN),r;if(p.s!=r.s)return r.s=-r.s,p.plus(r);if(l=p.d,c=r.d,o=f.precision,h=f.rounding,!l[0]||!c[0]){if(c[0])r.s=-r.s;else if(l[0])r=new f(p);else return new f(h===3?-0:0);return q?z(r,o,h):r}if(t=Me(r.e/j),d=Me(p.e/j),l=l.slice(),n=d-t,n){for(u=n<0,u?(e=l,n=-n,a=c.length):(e=c,t=d,a=l.length),i=Math.max(Math.ceil(o/j),a)+2,n>i&&(n=i,e.length=1),e.reverse(),i=n;i--;)e.push(0);e.reverse()}else{for(i=l.length,a=c.length,u=i<a,u&&(a=i),i=0;i<a;i++)if(l[i]!=c[i]){u=l[i]<c[i];break}n=0}for(u&&(e=l,l=c,c=e,r.s=-r.s),a=l.length,i=c.length-a;i>0;--i)l[a++]=0;for(i=c.length;i>n;){if(l[--i]<c[i]){for(s=i;s&&l[--s]===0;)l[s]=je-1;--l[s],l[i]+=je}l[i]-=c[i]}for(;l[--a]===0;)l.pop();for(;l[0]===0;l.shift())--t;return l[0]?(r.d=l,r.e=Jr(l,t),q?z(r,o,h):r):new f(h===3?-0:0)};C.modulo=C.mod=function(r){var e,t=this,i=t.constructor;return r=new i(r),!t.d||!r.s||r.d&&!r.d[0]?new i(NaN):!r.d||t.d&&!t.d[0]?z(new i(t),i.precision,i.rounding):(q=!1,i.modulo==9?(e=ue(t,r.abs(),0,3,1),e.s*=r.s):e=ue(t,r,0,i.modulo,1),e=e.times(r),q=!0,t.minus(e))};C.naturalExponential=C.exp=function(){return Fs(this)};C.naturalLogarithm=C.ln=function(){return Pt(this)};C.negated=C.neg=function(){var r=new this.constructor(this);return r.s=-r.s,z(r)};C.plus=C.add=function(r){var e,t,i,s,n,a,o,h,l,d,u=this,c=u.constructor;if(r=new c(r),!u.d||!r.d)return!u.s||!r.s?r=new c(NaN):u.d||(r=new c(r.d||u.s===r.s?u:NaN)),r;if(u.s!=r.s)return r.s=-r.s,u.minus(r);if(l=u.d,d=r.d,o=c.precision,h=c.rounding,!l[0]||!d[0])return d[0]||(r=new c(u)),q?z(r,o,h):r;if(n=Me(u.e/j),i=Me(r.e/j),l=l.slice(),s=n-i,s){for(s<0?(t=l,s=-s,a=d.length):(t=d,i=n,a=l.length),n=Math.ceil(o/j),a=n>a?n+1:a+1,s>a&&(s=a,t.length=1),t.reverse();s--;)t.push(0);t.reverse()}for(a=l.length,s=d.length,a-s<0&&(s=a,t=d,d=l,l=t),e=0;s;)e=(l[--s]=l[s]+d[s]+e)/je|0,l[s]%=je;for(e&&(l.unshift(e),++i),a=l.length;l[--a]==0;)l.pop();return r.d=l,r.e=Jr(l,i),q?z(r,o,h):r};C.precision=C.sd=function(r){var e,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(Lt+r);return t.d?(e=el(t.d),r&&t.e+1>e&&(e=t.e+1)):e=NaN,e};C.round=function(){var r=this,e=r.constructor;return z(new e(r),r.e+1,e.rounding)};C.sine=C.sin=function(){var r,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+Math.max(t.e,t.sd())+j,i.rounding=1,t=Kc(i,sl(i,t)),i.precision=r,i.rounding=e,z(ht>2?t.neg():t,r,e,!0)):new i(NaN)};C.squareRoot=C.sqrt=function(){var r,e,t,i,s,n,a=this,o=a.d,h=a.e,l=a.s,d=a.constructor;if(l!==1||!o||!o[0])return new d(!l||l<0&&(!o||o[0])?NaN:o?a:1/0);for(q=!1,l=Math.sqrt(+a),l==0||l==1/0?(e=xe(o),(e.length+h)%2==0&&(e+="0"),l=Math.sqrt(e),h=Me((h+1)/2)-(h<0||h%2),l==1/0?e="5e"+h:(e=l.toExponential(),e=e.slice(0,e.indexOf("e")+1)+h),i=new d(e)):i=new d(l.toString()),t=(h=d.precision)+3;;)if(n=i,i=n.plus(ue(a,n,t+2,1)).times(.5),xe(n.d).slice(0,t)===(e=xe(i.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!s&&e=="4999"){if(!s&&(z(n,h+1,0),n.times(n).eq(a))){i=n;break}t+=4,s=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(z(i,h+1,1),r=!i.times(i).eq(a));break}return q=!0,z(i,h,d.rounding,r)};C.tangent=C.tan=function(){var r,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+10,i.rounding=1,t=t.sin(),t.s=1,t=ue(t,new i(1).minus(t.times(t)).sqrt(),r+10,0),i.precision=r,i.rounding=e,z(ht==2||ht==4?t.neg():t,r,e,!0)):new i(NaN)};C.times=C.mul=function(r){var e,t,i,s,n,a,o,h,l,d=this,u=d.constructor,c=d.d,p=(r=new u(r)).d;if(r.s*=d.s,!c||!c[0]||!p||!p[0])return new u(!r.s||c&&!c[0]&&!p||p&&!p[0]&&!c?NaN:!c||!p?r.s/0:r.s*0);for(t=Me(d.e/j)+Me(r.e/j),h=c.length,l=p.length,h<l&&(n=c,c=p,p=n,a=h,h=l,l=a),n=[],a=h+l,i=a;i--;)n.push(0);for(i=l;--i>=0;){for(e=0,s=h+i;s>i;)o=n[s]+p[i]*c[s-i-1]+e,n[s--]=o%je|0,e=o/je|0;n[s]=(n[s]+e)%je|0}for(;!n[--a];)n.pop();return e?++t:n.shift(),r.d=n,r.e=Jr(n,t),q?z(r,u.precision,u.rounding):r};C.toBinary=function(r,e){return dn(this,2,r,e)};C.toDecimalPlaces=C.toDP=function(r,e){var t=this,i=t.constructor;return t=new i(t),r===void 0?t:(Ne(r,0,Dt),e===void 0?e=i.rounding:Ne(e,0,8),z(t,r+t.e+1,e))};C.toExponential=function(r,e){var t,i=this,s=i.constructor;return r===void 0?t=nt(i,!0):(Ne(r,0,Dt),e===void 0?e=s.rounding:Ne(e,0,8),i=z(new s(i),r+1,e),t=nt(i,!0,r+1)),i.isNeg()&&!i.isZero()?"-"+t:t};C.toFixed=function(r,e){var t,i,s=this,n=s.constructor;return r===void 0?t=nt(s):(Ne(r,0,Dt),e===void 0?e=n.rounding:Ne(e,0,8),i=z(new n(s),r+s.e+1,e),t=nt(i,!1,r+i.e+1)),s.isNeg()&&!s.isZero()?"-"+t:t};C.toFraction=function(r){var e,t,i,s,n,a,o,h,l,d,u,c,p=this,f=p.d,m=p.constructor;if(!f)return new m(p);if(l=t=new m(1),i=h=new m(0),e=new m(i),n=e.e=el(f)-p.e-1,a=n%j,e.d[0]=Se(10,a<0?j+a:a),r==null)r=n>0?e:l;else{if(o=new m(r),!o.isInt()||o.lt(l))throw Error(Lt+o);r=o.gt(e)?n>0?e:l:o}for(q=!1,o=new m(xe(f)),d=m.precision,m.precision=n=f.length*j*2;u=ue(o,e,0,1,1),s=t.plus(u.times(i)),s.cmp(r)!=1;)t=i,i=s,s=l,l=h.plus(u.times(s)),h=s,s=e,e=o.minus(u.times(s)),o=s;return s=ue(r.minus(t),i,0,1,1),h=h.plus(s.times(l)),t=t.plus(s.times(i)),h.s=l.s=p.s,c=ue(l,i,n,1).minus(p).abs().cmp(ue(h,t,n,1).minus(p).abs())<1?[l,i]:[h,t],m.precision=d,q=!0,c};C.toHexadecimal=C.toHex=function(r,e){return dn(this,16,r,e)};C.toNearest=function(r,e){var t=this,i=t.constructor;if(t=new i(t),r==null){if(!t.d)return t;r=new i(1),e=i.rounding}else{if(r=new i(r),e===void 0?e=i.rounding:Ne(e,0,8),!t.d)return r.s?t:r;if(!r.d)return r.s&&(r.s=t.s),r}return r.d[0]?(q=!1,t=ue(t,r,0,e,1).times(r),q=!0,z(t)):(r.s=t.s,t=r),t};C.toNumber=function(){return+this};C.toOctal=function(r,e){return dn(this,8,r,e)};C.toPower=C.pow=function(r){var e,t,i,s,n,a,o=this,h=o.constructor,l=+(r=new h(r));if(!o.d||!r.d||!o.d[0]||!r.d[0])return new h(Se(+o,l));if(o=new h(o),o.eq(1))return o;if(i=h.precision,n=h.rounding,r.eq(1))return z(o,i,n);if(e=Me(r.e/j),e>=r.d.length-1&&(t=l<0?-l:l)<=jc)return s=tl(h,o,t,i),r.s<0?new h(1).div(s):z(s,i,n);if(a=o.s,a<0){if(e<r.d.length-1)return new h(NaN);if(r.d[e]&1||(a=1),o.e==0&&o.d[0]==1&&o.d.length==1)return o.s=a,o}return t=Se(+o,l),e=t==0||!isFinite(t)?Me(l*(Math.log("0."+xe(o.d))/Math.LN10+o.e+1)):new h(t+"").e,e>h.maxE+1||e<h.minE-1?new h(e>0?a/0:0):(q=!1,h.rounding=o.s=1,t=Math.min(12,(e+"").length),s=Fs(r.times(Pt(o,i+t)),i),s.d&&(s=z(s,i+5,1),Zi(s.d,i,n)&&(e=i+10,s=z(Fs(r.times(Pt(o,e+t)),e),e+5,1),+xe(s.d).slice(i+1,i+15)+1==1e14&&(s=z(s,i+1,0)))),s.s=a,q=!0,h.rounding=n,z(s,i,n))};C.toPrecision=function(r,e){var t,i=this,s=i.constructor;return r===void 0?t=nt(i,i.e<=s.toExpNeg||i.e>=s.toExpPos):(Ne(r,1,Dt),e===void 0?e=s.rounding:Ne(e,0,8),i=z(new s(i),r,e),t=nt(i,r<=i.e||i.e<=s.toExpNeg,r)),i.isNeg()&&!i.isZero()?"-"+t:t};C.toSignificantDigits=C.toSD=function(r,e){var t=this,i=t.constructor;return r===void 0?(r=i.precision,e=i.rounding):(Ne(r,1,Dt),e===void 0?e=i.rounding:Ne(e,0,8)),z(new i(t),r,e)};C.toString=function(){var r=this,e=r.constructor,t=nt(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};C.truncated=C.trunc=function(){return z(new this.constructor(this),this.e+1,1)};C.valueOf=C.toJSON=function(){var r=this,e=r.constructor,t=nt(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()?"-"+t:t};function xe(r){var e,t,i,s=r.length-1,n="",a=r[0];if(s>0){for(n+=a,e=1;e<s;e++)i=r[e]+"",t=j-i.length,t&&(n+=kt(t)),n+=i;a=r[e],i=a+"",t=j-i.length,t&&(n+=kt(t))}else if(a===0)return"0";for(;a%10===0;)a/=10;return n+a}function Ne(r,e,t){if(r!==~~r||r<e||r>t)throw Error(Lt+r)}function Zi(r,e,t,i){var s,n,a,o;for(n=r[0];n>=10;n/=10)--e;return--e<0?(e+=j,s=0):(s=Math.ceil((e+1)/j),e%=j),n=Se(10,j-e),o=r[s]%n|0,i==null?e<3?(e==0?o=o/100|0:e==1&&(o=o/10|0),a=t<4&&o==99999||t>3&&o==49999||o==5e4||o==0):a=(t<4&&o+1==n||t>3&&o+1==n/2)&&(r[s+1]/n/100|0)==Se(10,e-2)-1||(o==n/2||o==0)&&(r[s+1]/n/100|0)==0:e<4?(e==0?o=o/1e3|0:e==1?o=o/100|0:e==2&&(o=o/10|0),a=(i||t<4)&&o==9999||!i&&t>3&&o==4999):a=((i||t<4)&&o+1==n||!i&&t>3&&o+1==n/2)&&(r[s+1]/n/1e3|0)==Se(10,e-3)-1,a}function Sr(r,e,t){for(var i,s=[0],n,a=0,o=r.length;a<o;){for(n=s.length;n--;)s[n]*=e;for(s[0]+=Ns.indexOf(r.charAt(a++)),i=0;i<s.length;i++)s[i]>t-1&&(s[i+1]===void 0&&(s[i+1]=0),s[i+1]+=s[i]/t|0,s[i]%=t)}return s.reverse()}function qc(r,e){var t,i,s;if(e.isZero())return e;i=e.d.length,i<32?(t=Math.ceil(i/3),s=(1/Qr(4,t)).toString()):(t=16,s="2.3283064365386962890625e-10"),r.precision+=t,e=ci(r,1,e.times(s),new r(1));for(var n=t;n--;){var a=e.times(e);e=a.times(a).minus(a).times(8).plus(1)}return r.precision-=t,e}var ue=function(){function r(i,s,n){var a,o=0,h=i.length;for(i=i.slice();h--;)a=i[h]*s+o,i[h]=a%n|0,o=a/n|0;return o&&i.unshift(o),i}function e(i,s,n,a){var o,h;if(n!=a)h=n>a?1:-1;else for(o=h=0;o<n;o++)if(i[o]!=s[o]){h=i[o]>s[o]?1:-1;break}return h}function t(i,s,n,a){for(var o=0;n--;)i[n]-=o,o=i[n]<s[n]?1:0,i[n]=o*a+i[n]-s[n];for(;!i[0]&&i.length>1;)i.shift()}return function(i,s,n,a,o,h){var l,d,u,c,p,f,m,v,_,w,b,T,L,A,G,R,H,$,I,K,W=i.constructor,le=i.s==s.s?1:-1,ne=i.d,U=s.d;if(!ne||!ne[0]||!U||!U[0])return new W(!i.s||!s.s||(ne?U&&ne[0]==U[0]:!U)?NaN:ne&&ne[0]==0||!U?le*0:le/0);for(h?(p=1,d=i.e-s.e):(h=je,p=j,d=Me(i.e/p)-Me(s.e/p)),I=U.length,H=ne.length,_=new W(le),w=_.d=[],u=0;U[u]==(ne[u]||0);u++);if(U[u]>(ne[u]||0)&&d--,n==null?(A=n=W.precision,a=W.rounding):o?A=n+(i.e-s.e)+1:A=n,A<0)w.push(1),f=!0;else{if(A=A/p+2|0,u=0,I==1){for(c=0,U=U[0],A++;(u<H||c)&&A--;u++)G=c*h+(ne[u]||0),w[u]=G/U|0,c=G%U|0;f=c||u<H}else{for(c=h/(U[0]+1)|0,c>1&&(U=r(U,c,h),ne=r(ne,c,h),I=U.length,H=ne.length),R=I,b=ne.slice(0,I),T=b.length;T<I;)b[T++]=0;K=U.slice(),K.unshift(0),$=U[0],U[1]>=h/2&&++$;do c=0,l=e(U,b,I,T),l<0?(L=b[0],I!=T&&(L=L*h+(b[1]||0)),c=L/$|0,c>1?(c>=h&&(c=h-1),m=r(U,c,h),v=m.length,T=b.length,l=e(m,b,v,T),l==1&&(c--,t(m,I<v?K:U,v,h))):(c==0&&(l=c=1),m=U.slice()),v=m.length,v<T&&m.unshift(0),t(b,m,T,h),l==-1&&(T=b.length,l=e(U,b,I,T),l<1&&(c++,t(b,I<T?K:U,T,h))),T=b.length):l===0&&(c++,b=[0]),w[u++]=c,l&&b[0]?b[T++]=ne[R]||0:(b=[ne[R]],T=1);while((R++<H||b[0]!==void 0)&&A--);f=b[0]!==void 0}w[0]||w.shift()}if(p==1)_.e=d,qo=f;else{for(u=1,c=w[0];c>=10;c/=10)u++;_.e=u+d*p-1,z(_,o?n+_.e+1:n,a,f)}return _}}();function z(r,e,t,i){var s,n,a,o,h,l,d,u,c,p=r.constructor;e:if(e!=null){if(u=r.d,!u)return r;for(s=1,o=u[0];o>=10;o/=10)s++;if(n=e-s,n<0)n+=j,a=e,d=u[c=0],h=d/Se(10,s-a-1)%10|0;else if(c=Math.ceil((n+1)/j),o=u.length,c>=o)if(i){for(;o++<=c;)u.push(0);d=h=0,s=1,n%=j,a=n-j+1}else break e;else{for(d=o=u[c],s=1;o>=10;o/=10)s++;n%=j,a=n-j+s,h=a<0?0:d/Se(10,s-a-1)%10|0}if(i=i||e<0||u[c+1]!==void 0||(a<0?d:d%Se(10,s-a-1)),l=t<4?(h||i)&&(t==0||t==(r.s<0?3:2)):h>5||h==5&&(t==4||i||t==6&&(n>0?a>0?d/Se(10,s-a):0:u[c-1])%10&1||t==(r.s<0?8:7)),e<1||!u[0])return u.length=0,l?(e-=r.e+1,u[0]=Se(10,(j-e%j)%j),r.e=-e||0):u[0]=r.e=0,r;if(n==0?(u.length=c,o=1,c--):(u.length=c+1,o=Se(10,j-n),u[c]=a>0?(d/Se(10,s-a)%Se(10,a)|0)*o:0),l)for(;;)if(c==0){for(n=1,a=u[0];a>=10;a/=10)n++;for(a=u[0]+=o,o=1;a>=10;a/=10)o++;n!=o&&(r.e++,u[0]==je&&(u[0]=1));break}else{if(u[c]+=o,u[c]!=je)break;u[c--]=0,o=1}for(n=u.length;u[--n]===0;)u.pop()}return q&&(r.e>p.maxE?(r.d=null,r.e=NaN):r.e<p.minE&&(r.e=0,r.d=[0])),r}function nt(r,e,t){if(!r.isFinite())return rl(r);var i,s=r.e,n=xe(r.d),a=n.length;return e?(t&&(i=t-a)>0?n=n.charAt(0)+"."+n.slice(1)+kt(i):a>1&&(n=n.charAt(0)+"."+n.slice(1)),n=n+(r.e<0?"e":"e+")+r.e):s<0?(n="0."+kt(-s-1)+n,t&&(i=t-a)>0&&(n+=kt(i))):s>=a?(n+=kt(s+1-a),t&&(i=t-s-1)>0&&(n=n+"."+kt(i))):((i=s+1)<a&&(n=n.slice(0,i)+"."+n.slice(i)),t&&(i=t-a)>0&&(s+1===a&&(n+="."),n+=kt(i))),n}function Jr(r,e){var t=r[0];for(e*=j;t>=10;t/=10)e++;return e}function zr(r,e,t){if(e>Xc)throw q=!0,t&&(r.precision=t),Error(Yo);return z(new r($r),e,1,!0)}function Ue(r,e,t){if(e>Ds)throw Error(Yo);return z(new r(Vr),e,t,!0)}function el(r){var e=r.length-1,t=e*j+1;if(e=r[e],e){for(;e%10==0;e/=10)t--;for(e=r[0];e>=10;e/=10)t++}return t}function kt(r){for(var e="";r--;)e+="0";return e}function tl(r,e,t,i){var s,n=new r(1),a=Math.ceil(i/j+4);for(q=!1;;){if(t%2&&(n=n.times(e),ra(n.d,a)&&(s=!0)),t=Me(t/2),t===0){t=n.d.length-1,s&&n.d[t]===0&&++n.d[t];break}e=e.times(e),ra(e.d,a)}return q=!0,n}function ia(r){return r.d[r.d.length-1]&1}function il(r,e,t){for(var i,s=new r(e[0]),n=0;++n<e.length;)if(i=new r(e[n]),i.s)s[t](i)&&(s=i);else{s=i;break}return s}function Fs(r,e){var t,i,s,n,a,o,h,l=0,d=0,u=0,c=r.constructor,p=c.rounding,f=c.precision;if(!r.d||!r.d[0]||r.e>17)return new c(r.d?r.d[0]?r.s<0?0:1/0:1:r.s?r.s<0?0:r:0/0);for(e==null?(q=!1,h=f):h=e,o=new c(.03125);r.e>-2;)r=r.times(o),u+=5;for(i=Math.log(Se(2,u))/Math.LN10*2+5|0,h+=i,t=n=a=new c(1),c.precision=h;;){if(n=z(n.times(r),h,1),t=t.times(++d),o=a.plus(ue(n,t,h,1)),xe(o.d).slice(0,h)===xe(a.d).slice(0,h)){for(s=u;s--;)a=z(a.times(a),h,1);if(e==null)if(l<3&&Zi(a.d,h-i,p,l))c.precision=h+=10,t=n=o=new c(1),d=0,l++;else return z(a,c.precision=f,p,q=!0);else return c.precision=f,a}a=o}}function Pt(r,e){var t,i,s,n,a,o,h,l,d,u,c,p=1,f=10,m=r,v=m.d,_=m.constructor,w=_.rounding,b=_.precision;if(m.s<0||!v||!v[0]||!m.e&&v[0]==1&&v.length==1)return new _(v&&!v[0]?-1/0:m.s!=1?NaN:v?0:m);if(e==null?(q=!1,d=b):d=e,_.precision=d+=f,t=xe(v),i=t.charAt(0),Math.abs(n=m.e)<15e14){for(;i<7&&i!=1||i==1&&t.charAt(1)>3;)m=m.times(r),t=xe(m.d),i=t.charAt(0),p++;n=m.e,i>1?(m=new _("0."+t),n++):m=new _(i+"."+t.slice(1))}else return l=zr(_,d+2,b).times(n+""),m=Pt(new _(i+"."+t.slice(1)),d-f).plus(l),_.precision=b,e==null?z(m,b,w,q=!0):m;for(u=m,h=a=m=ue(m.minus(1),m.plus(1),d,1),c=z(m.times(m),d,1),s=3;;){if(a=z(a.times(c),d,1),l=h.plus(ue(a,new _(s),d,1)),xe(l.d).slice(0,d)===xe(h.d).slice(0,d))if(h=h.times(2),n!==0&&(h=h.plus(zr(_,d+2,b).times(n+""))),h=ue(h,new _(p),d,1),e==null)if(Zi(h.d,d-f,w,o))_.precision=d+=f,l=a=m=ue(u.minus(1),u.plus(1),d,1),c=z(m.times(m),d,1),s=o=1;else return z(h,_.precision=b,w,q=!0);else return _.precision=b,h;h=l,s+=2}}function rl(r){return String(r.s*r.s/0)}function Hs(r,e){var t,i,s;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(t<0&&(t=i),t+=+e.slice(i+1),e=e.substring(0,i)):t<0&&(t=e.length),i=0;e.charCodeAt(i)===48;i++);for(s=e.length;e.charCodeAt(s-1)===48;--s);if(e=e.slice(i,s),e){if(s-=i,r.e=t=t-i-1,r.d=[],i=(t+1)%j,t<0&&(i+=j),i<s){for(i&&r.d.push(+e.slice(0,i)),s-=j;i<s;)r.d.push(+e.slice(i,i+=j));e=e.slice(i),i=j-e.length}else i-=s;for(;i--;)e+="0";r.d.push(+e),q&&(r.e>r.constructor.maxE?(r.d=null,r.e=NaN):r.e<r.constructor.minE&&(r.e=0,r.d=[0]))}else r.e=0,r.d=[0];return r}function Yc(r,e){var t,i,s,n,a,o,h,l,d;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Qo.test(e))return Hs(r,e)}else if(e==="Infinity"||e==="NaN")return+e||(r.s=NaN),r.e=NaN,r.d=null,r;if(Uc.test(e))t=16,e=e.toLowerCase();else if(Wc.test(e))t=2;else if(Zc.test(e))t=8;else throw Error(Lt+e);for(n=e.search(/p/i),n>0?(h=+e.slice(n+1),e=e.substring(2,n)):e=e.slice(2),n=e.indexOf("."),a=n>=0,i=r.constructor,a&&(e=e.replace(".",""),o=e.length,n=o-n,s=tl(i,new i(t),n,n*2)),l=Sr(e,t,je),d=l.length-1,n=d;l[n]===0;--n)l.pop();return n<0?new i(r.s*0):(r.e=Jr(l,d),r.d=l,q=!1,a&&(r=ue(r,s,o*4)),h&&(r=r.times(Math.abs(h)<54?Se(2,h):Z.pow(2,h))),q=!0,r)}function Kc(r,e){var t,i=e.d.length;if(i<3)return e.isZero()?e:ci(r,2,e,e);t=1.4*Math.sqrt(i),t=t>16?16:t|0,e=e.times(1/Qr(5,t)),e=ci(r,2,e,e);for(var s,n=new r(5),a=new r(16),o=new r(20);t--;)s=e.times(e),e=e.times(n.plus(s.times(a.times(s).minus(o))));return e}function ci(r,e,t,i,s){var n,a,o,h,l=r.precision,d=Math.ceil(l/j);for(q=!1,h=t.times(t),o=new r(i);;){if(a=ue(o.times(h),new r(e++*e++),l,1),o=s?i.plus(a):i.minus(a),i=ue(a.times(h),new r(e++*e++),l,1),a=o.plus(i),a.d[d]!==void 0){for(n=d;a.d[n]===o.d[n]&&n--;);if(n==-1)break}n=o,o=i,i=a,a=n}return q=!0,a.d.length=d+1,a}function Qr(r,e){for(var t=r;--e;)t*=r;return t}function sl(r,e){var t,i=e.s<0,s=Ue(r,r.precision,1),n=s.times(.5);if(e=e.abs(),e.lte(n))return ht=i?4:1,e;if(t=e.divToInt(s),t.isZero())ht=i?3:2;else{if(e=e.minus(t.times(s)),e.lte(n))return ht=ia(t)?i?2:3:i?4:1,e;ht=ia(t)?i?1:4:i?3:2}return e.minus(s).abs()}function dn(r,e,t,i){var s,n,a,o,h,l,d,u,c,p=r.constructor,f=t!==void 0;if(f?(Ne(t,1,Dt),i===void 0?i=p.rounding:Ne(i,0,8)):(t=p.precision,i=p.rounding),!r.isFinite())d=rl(r);else{for(d=nt(r),a=d.indexOf("."),f?(s=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):s=e,a>=0&&(d=d.replace(".",""),c=new p(1),c.e=d.length-a,c.d=Sr(nt(c),10,s),c.e=c.d.length),u=Sr(d,10,s),n=h=u.length;u[--h]==0;)u.pop();if(!u[0])d=f?"0p+0":"0";else{if(a<0?n--:(r=new p(r),r.d=u,r.e=n,r=ue(r,c,t,i,0,s),u=r.d,n=r.e,l=qo),a=u[t],o=s/2,l=l||u[t+1]!==void 0,l=i<4?(a!==void 0||l)&&(i===0||i===(r.s<0?3:2)):a>o||a===o&&(i===4||l||i===6&&u[t-1]&1||i===(r.s<0?8:7)),u.length=t,l)for(;++u[--t]>s-1;)u[t]=0,t||(++n,u.unshift(1));for(h=u.length;!u[h-1];--h);for(a=0,d="";a<h;a++)d+=Ns.charAt(u[a]);if(f){if(h>1)if(e==16||e==8){for(a=e==16?4:3,--h;h%a;h++)d+="0";for(u=Sr(d,s,e),h=u.length;!u[h-1];--h);for(a=1,d="1.";a<h;a++)d+=Ns.charAt(u[a])}else d=d.charAt(0)+"."+d.slice(1);d=d+(n<0?"p":"p+")+n}else if(n<0){for(;++n;)d="0"+d;d="0."+d}else if(++n>h)for(n-=h;n--;)d+="0";else n<h&&(d=d.slice(0,n)+"."+d.slice(n))}d=(e==16?"0x":e==2?"0b":e==8?"0o":"")+d}return r.s<0?"-"+d:d}function ra(r,e){if(r.length>e)return r.length=e,!0}function Jc(r){return new this(r).abs()}function Qc(r){return new this(r).acos()}function ef(r){return new this(r).acosh()}function tf(r,e){return new this(r).plus(e)}function rf(r){return new this(r).asin()}function sf(r){return new this(r).asinh()}function nf(r){return new this(r).atan()}function af(r){return new this(r).atanh()}function of(r,e){r=new this(r),e=new this(e);var t,i=this.precision,s=this.rounding,n=i+4;return!r.s||!e.s?t=new this(NaN):!r.d&&!e.d?(t=Ue(this,n,1).times(e.s>0?.25:.75),t.s=r.s):!e.d||r.isZero()?(t=e.s<0?Ue(this,i,s):new this(0),t.s=r.s):!r.d||e.isZero()?(t=Ue(this,n,1).times(.5),t.s=r.s):e.s<0?(this.precision=n,this.rounding=1,t=this.atan(ue(r,e,n,1)),e=Ue(this,n,1),this.precision=i,this.rounding=s,t=r.s<0?t.minus(e):t.plus(e)):t=this.atan(ue(r,e,n,1)),t}function lf(r){return new this(r).cbrt()}function hf(r){return z(r=new this(r),r.e+1,2)}function df(r,e,t){return new this(r).clamp(e,t)}function uf(r){if(!r||typeof r!="object")throw Error(Kr+"Object expected");var e,t,i,s=r.defaults===!0,n=["precision",1,Dt,"rounding",0,8,"toExpNeg",-ei,0,"toExpPos",0,ei,"maxE",0,ei,"minE",-ei,0,"modulo",0,9];for(e=0;e<n.length;e+=3)if(t=n[e],s&&(this[t]=Gs[t]),(i=r[t])!==void 0)if(Me(i)===i&&i>=n[e+1]&&i<=n[e+2])this[t]=i;else throw Error(Lt+t+": "+i);if(t="crypto",s&&(this[t]=Gs[t]),(i=r[t])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Ko);else this[t]=!1;else throw Error(Lt+t+": "+i);return this}function cf(r){return new this(r).cos()}function ff(r){return new this(r).cosh()}function nl(r){var e,t,i;function s(n){var a,o,h,l=this;if(!(l instanceof s))return new s(n);if(l.constructor=s,sa(n)){l.s=n.s,q?!n.d||n.e>s.maxE?(l.e=NaN,l.d=null):n.e<s.minE?(l.e=0,l.d=[0]):(l.e=n.e,l.d=n.d.slice()):(l.e=n.e,l.d=n.d?n.d.slice():n.d);return}if(h=typeof n,h==="number"){if(n===0){l.s=1/n<0?-1:1,l.e=0,l.d=[0];return}if(n<0?(n=-n,l.s=-1):l.s=1,n===~~n&&n<1e7){for(a=0,o=n;o>=10;o/=10)a++;q?a>s.maxE?(l.e=NaN,l.d=null):a<s.minE?(l.e=0,l.d=[0]):(l.e=a,l.d=[n]):(l.e=a,l.d=[n]);return}else if(n*0!==0){n||(l.s=NaN),l.e=NaN,l.d=null;return}return Hs(l,n.toString())}else if(h!=="string")throw Error(Lt+n);return(o=n.charCodeAt(0))===45?(n=n.slice(1),l.s=-1):(o===43&&(n=n.slice(1)),l.s=1),Qo.test(n)?Hs(l,n):Yc(l,n)}if(s.prototype=C,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=uf,s.clone=nl,s.isDecimal=sa,s.abs=Jc,s.acos=Qc,s.acosh=ef,s.add=tf,s.asin=rf,s.asinh=sf,s.atan=nf,s.atanh=af,s.atan2=of,s.cbrt=lf,s.ceil=hf,s.clamp=df,s.cos=cf,s.cosh=ff,s.div=pf,s.exp=mf,s.floor=gf,s.hypot=vf,s.ln=yf,s.log=bf,s.log10=wf,s.log2=_f,s.max=Sf,s.min=Tf,s.mod=Cf,s.mul=Ef,s.pow=kf,s.random=xf,s.round=Pf,s.sign=Af,s.sin=Of,s.sinh=Mf,s.sqrt=Lf,s.sub=Rf,s.sum=If,s.tan=Nf,s.tanh=Gf,s.trunc=Df,r===void 0&&(r={}),r&&r.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)r.hasOwnProperty(t=i[e++])||(r[t]=this[t]);return s.config(r),s}function pf(r,e){return new this(r).div(e)}function mf(r){return new this(r).exp()}function gf(r){return z(r=new this(r),r.e+1,3)}function vf(){var r,e,t=new this(0);for(q=!1,r=0;r<arguments.length;)if(e=new this(arguments[r++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return q=!0,new this(1/0);t=e}return q=!0,t.sqrt()}function sa(r){return r instanceof Z||r&&r.toStringTag===Jo||!1}function yf(r){return new this(r).ln()}function bf(r,e){return new this(r).log(e)}function _f(r){return new this(r).log(2)}function wf(r){return new this(r).log(10)}function Sf(){return il(this,arguments,"lt")}function Tf(){return il(this,arguments,"gt")}function Cf(r,e){return new this(r).mod(e)}function Ef(r,e){return new this(r).mul(e)}function kf(r,e){return new this(r).pow(e)}function xf(r){var e,t,i,s,n=0,a=new this(1),o=[];if(r===void 0?r=this.precision:Ne(r,1,Dt),i=Math.ceil(r/j),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));n<i;)s=e[n],s>=429e7?e[n]=crypto.getRandomValues(new Uint32Array(1))[0]:o[n++]=s%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(i*=4);n<i;)s=e[n]+(e[n+1]<<8)+(e[n+2]<<16)+((e[n+3]&127)<<24),s>=214e7?crypto.randomBytes(4).copy(e,n):(o.push(s%1e7),n+=4);n=i/4}else throw Error(Ko);else for(;n<i;)o[n++]=Math.random()*1e7|0;for(i=o[--n],r%=j,i&&r&&(s=Se(10,j-r),o[n]=(i/s|0)*s);o[n]===0;n--)o.pop();if(n<0)t=0,o=[0];else{for(t=-1;o[0]===0;t-=j)o.shift();for(i=1,s=o[0];s>=10;s/=10)i++;i<j&&(t-=j-i)}return a.e=t,a.d=o,a}function Pf(r){return z(r=new this(r),r.e+1,this.rounding)}function Af(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function Of(r){return new this(r).sin()}function Mf(r){return new this(r).sinh()}function Lf(r){return new this(r).sqrt()}function Rf(r,e){return new this(r).sub(e)}function If(){var r=0,e=arguments,t=new this(e[r]);for(q=!1;t.s&&++r<e.length;)t=t.plus(e[r]);return q=!0,z(t,this.precision,this.rounding)}function Nf(r){return new this(r).tan()}function Gf(r){return new this(r).tanh()}function Df(r){return z(r=new this(r),r.e+1,1)}C[Symbol.for("nodejs.util.inspect.custom")]=C.toString;C[Symbol.toStringTag]="Decimal";var Z=C.constructor=nl(Gs);$r=new Z($r);Vr=new Z(Vr);const na={editable:!0,style:{...jo,markerSymbolSize:20,periodMarkerHandleType:"start"}};class aa extends Xo{constructor(e,t,i){super({...na,...e,style:{...na.style,...e.style}},t,i)}createSymbol(){switch(this.style.markerSymbolType){case"triangle":let t=Z.sqrt(2).mul(this.style.markerSymbolSize).toNumber()/2;return new O.Line({points:this.style.periodMarkerHandleType==="start"?[-t,0,0,0,0,t]:[0,0,t,0,0,t],fill:this.style.color,closed:!0,offsetY:t/2});case"circle":return new O.Arc({fill:this.style.color,innerRadius:0,outerRadius:this.style.markerSymbolSize/2,angle:180,rotation:this.style.periodMarkerHandleType==="start"?90:-90});case"square":return new O.Line({points:[0,0,this.style.markerSymbolSize,0,this.style.markerSymbolSize,this.style.markerSymbolSize],fill:this.style.color,closed:!0,rotation:this.style.periodMarkerHandleType==="start"?225:45,offsetX:this.style.markerSymbolSize/2,offsetY:this.style.markerSymbolSize/2});default:throw Error("Unknown type")}}}const oa={editable:!0,style:{...Uo,selectedAreaOpacity:.2,markerHandleAreaOpacity:.7}};class al extends Zo{constructor(e){super({...oa,...e,style:{...oa.style,...e.style}}),this.observation.start=_e.coerce.number().min(0).optional().nullable().parse(this.observation.start),this.observation.end=_e.coerce.number().min(0).optional().nullable().parse(this.observation.end),this.observation.end!=null&&this.observation.start!=null&&(this.observation.start=_e.coerce.number().lte(this.observation.end).parse(this.observation.start))}createCanvasNode(){return super.createCanvasNode(),this.initStartMarkerHandle(),this.initEndMarkerHandle(),this.initSelectedAreaRect(),this.group}onChange(){this.settlePosition();let e={timeObservation:this.observation};this.onChange$.next(e)}onMeasurementsChange(){super.onMeasurementsChange();let e=this.startMarkerHandle.getVerticalMeasurement();this.selectedAreaRect.setAttrs({y:e.y,height:e.height});let t={y:this.startMarkerHandle.getHandleGroup().y(),height:this.startMarkerHandle.getHandleGroup().getClientRect().height};this.markerHandleRect.setAttrs({y:e.y+t.y-t.height/2,height:t.height}),this.settlePosition()}initSelectedAreaRect(){if(this.selectedAreaRect&&this.selectedAreaRect.destroy(),this.markerHandleRect&&this.markerHandleRect.destroy(),!this.hasStart()||!this.hasEnd())return;let e=this.startMarkerHandle.getVerticalMeasurement(),t=this.timeline.timeToTimelinePosition(this.observation.start),i=this.timeline.timeToTimelinePosition(this.observation.end);this.selectedAreaRect=new O.Rect({x:t,y:e.y,width:i-t,height:e.height,listening:!1,fill:this.style.color,opacity:this.style.selectedAreaOpacity});let s={y:this.startMarkerHandle.getHandleGroup().y(),height:this.startMarkerHandle.getHandleGroup().getClientRect().height};this.markerHandleRect=new O.Rect({x:t,y:e.y+s.y-s.height/2,width:i-t,height:s.height,listening:!1,fill:this.style.color,opacity:this.style.markerHandleAreaOpacity}),this.group.add(this.selectedAreaRect),this.group.add(this.markerHandleRect)}initStartMarkerHandle(){if(this.startMarkerHandle&&(this.startMarkerHandle.destroy(),this.startMarkerHandle=void 0),!this.hasStart())return;let e=this.timeline.timeToTimelinePosition(this.observation.start);this.startMarkerHandle=new aa({x:e,editable:this.editable,style:{color:this.style.color,markerRenderType:this.style.renderType,markerSymbolType:this.style.symbolType,periodMarkerHandleType:"start"}},this.markerLane,this.timeline),this.startMarkerHandle.onDrag=t=>{this.editable&&(this.hasEnd()&&t.x()>this.endMarkerHandle.getPosition().x&&t.x(this.endMarkerHandle.getPosition().x),this.settleMeasurements(),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(1))},this.startMarkerHandle.onDragEnd=t=>{if(this.editable){let i=this.timeline.timelinePositionToTime(t.x());this.setTimeObservation({...this.observation,start:i}),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(this.style.markerHandleAreaOpacity)}},this.group.add(this.startMarkerHandle.initCanvasNode())}initEndMarkerHandle(){if(this.endMarkerHandle&&(this.endMarkerHandle.destroy(),this.endMarkerHandle=void 0),!this.hasEnd())return;let e=this.hasEnd()?this.timeline.timeToTimelinePosition(this.observation.end):void 0;this.endMarkerHandle=new aa({x:e,editable:this.editable,style:{periodMarkerHandleType:"end",color:this.style.color,markerRenderType:this.style.renderType,markerSymbolType:this.style.symbolType}},this.markerLane,this.timeline),this.endMarkerHandle.onDrag=t=>{this.editable&&(this.hasStart()&&t.x()<this.startMarkerHandle.getPosition().x&&t.x(this.startMarkerHandle.getPosition().x),this.settleMeasurements(),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(1))},this.endMarkerHandle.onDragEnd=t=>{if(this.editable){let i=this.timeline.timelinePositionToTime(t.x());this.setTimeObservation({...this.observation,end:i}),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(this.style.markerHandleAreaOpacity)}},this.group.add(this.endMarkerHandle.initCanvasNode())}settlePosition(){this.hasStart()&&this.startMarkerHandle.setPosition({...this.startMarkerHandle.getPosition(),x:this.timeline.timeToTimelinePosition(this.observation.start)}),this.hasEnd()&&this.endMarkerHandle.setPosition({...this.endMarkerHandle.getPosition(),x:this.timeline.timeToTimelinePosition(this.observation.end)}),this.settleMeasurements()}settleMeasurements(){this.hasStart()&&this.hasEnd()&&(this.selectedAreaRect.setAttrs({x:this.startMarkerHandle.getPosition().x,width:this.endMarkerHandle.getPosition().x-this.startMarkerHandle.getPosition().x}),this.markerHandleRect.setAttrs({x:this.startMarkerHandle.getPosition().x,width:this.endMarkerHandle.getPosition().x-this.startMarkerHandle.getPosition().x}))}setTimeObservation(e){this.editable&&(this.observation=e,this.initStartMarkerHandle(),this.initEndMarkerHandle(),this.initSelectedAreaRect(),this.onChange())}setEditable(e){super.setEditable(e)}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.styleAdapter.onChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.hasStart()&&this.initStartMarkerHandle(),this.hasEnd()&&this.initEndMarkerHandle(),this.hasStart()&&this.hasEnd()&&this.initSelectedAreaRect()})}hasStart(){return this.observation&&this.observation.start!==null&&this.observation.start!==void 0}hasEnd(){return this.observation&&this.observation.end!==null&&this.observation.end!==void 0}}const la={editable:!0,style:{...jo,markerSymbolSize:20}};class Ff extends Xo{constructor(e,t,i){super({...la,...e,style:{...la.style,...e.style}},t,i)}createSymbol(){switch(this.style.markerSymbolType){case"triangle":let t=Z.sqrt(2).mul(this.style.markerSymbolSize).toNumber()/2;return new O.Line({points:[-t,0,t,0,0,t],fill:this.style.color,closed:!0,offsetY:t/2});case"circle":return new O.Circle({fill:this.style.color,radius:this.style.markerSymbolSize/2});case"square":return new O.Rect({fill:this.style.color,width:this.style.markerSymbolSize,height:this.style.markerSymbolSize,rotation:45,offsetX:this.style.markerSymbolSize/2,offsetY:this.style.markerSymbolSize/2});default:throw Error("Unknown type")}}}const ha={description:"",editable:!0,style:{...Uo}};class ol extends Zo{constructor(e){super({...ha,...e,style:{...ha.style,...e.style}}),this.observation.time=_e.coerce.number().min(0).parse(this.observation.time)}createCanvasNode(){return super.createCanvasNode(),this.initMarkerHandle(),this.group}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.styleAdapter.onChange$.subscribe(e=>{this.initMarkerHandle()})}initMarkerHandle(){this.markerHandle&&(this.markerHandle.destroy(),this.markerHandle=void 0);let e=this.timeline.timeToTimelinePosition(this.observation.time);this.markerHandle=new Ff({x:e,editable:this.editable,style:{color:this.style.color,markerRenderType:this.style.renderType,markerSymbolType:this.style.symbolType}},this.markerLane,this.timeline),this.markerHandle.onDragEnd=t=>{if(this.editable){let i=this.timeline.timelinePositionToTime(t.x());this.setTimeObservation({...this.observation,time:i})}},this.group.add(this.markerHandle.initCanvasNode())}onChange(){this.settlePosition();let e={timeObservation:this.observation};this.onChange$.next(e)}onMeasurementsChange(){super.onMeasurementsChange(),this.markerHandle.onMeasurementsChange(),this.settlePosition()}settlePosition(){this.markerHandle.setPosition({...this.markerHandle.getPosition(),x:this.timeline.timeToTimelinePosition(this.observation.time)})}setEditable(e){super.setEditable(e)}}const Hf={...Qi};class Bs extends er{constructor(e){super({...e,style:{...Hf,...e.style}}),this.onMarkerFocus$=new V,this.markers=[],this.markersMap=new Map}createCanvasNode(){return super.createCanvasNode(),this.markersGroup=new O.Group({...F.POSITION_TOP_LEFT,...this.timeline.getTimecodedGroupDimension()}),this.timeline.addToTimecodedMarkersGroup(this.markersGroup),this.bodyGroup}settleLayout(){super.settleLayout();let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.markersGroup].forEach(t=>{t.width(e.width)}),this.markers&&this.markers.forEach(t=>{t.onMeasurementsChange()})}destroy(){super.destroy(),this.markersGroup.destroy()}clearContent(){this.removeAllMarkers(),this.markers=[],this.markersMap=new Map,this.markersGroup.destroyChildren()}createMomentMarker(e){return this.addMarker(new ol(e))}createPeriodMarker(e){return this.addMarker(new al(e))}addMarker(e){if(!this.isInitialized())throw new Error("MarkerLane not initalized. Maybe you forgot to add MarkerLane to Timeline?");if(this.markersMap.has(e.getId()))throw new Error(`Marker with id=${e.getId()} already exists`);return e.setMarkerLane(this),e.setTimeline(this.timeline),e.onClick$.pipe(k(this.onDestroy$)).subscribe(t=>{this.focusMarker(e.getId())}),e.onMouseEnter$.pipe(k(this.onDestroy$)).subscribe(t=>{this.focusMarker(e.getId())}),this.markers.push(e),this.markersMap.set(e.getId(),e),this.markersGroup.add(e.initCanvasNode()),e}removeAllMarkers(){this.markers&&this.markers.forEach(e=>{this.removeMarker(e.getId())})}removeMarker(e){let t=this.getMarker(e);t&&(this.markers.splice(this.markers.findIndex(i=>i.getId()===t.getId()),1),this.markersMap.delete(t.getId()),t.destroy())}getMarker(e){return this.markersMap.get(e)}getMarkers(){return this.markers}focusMarker(e){let t=this.getMarker(e);t&&(this.moveToTop(t),this.markerInFocus=t,this.onMarkerFocus$.next({marker:t}))}getMarkerInFocus(){return this.markerInFocus}moveToTop(e){e&&(this.markersGroup.moveToTop(),e.getCanvasNode().moveToTop())}}class Bf{static randomHexColor(){return`#${Math.floor(Math.random()*16777215).toString(16)}`}}class yi{static createGoldenRatioWedge(e){let t=new Z(e.height).div(F.GOLDEN_RATIO+1).toDecimalPlaces(2).toNumber(),i=e.height-t,s=i/2;return new O.Line({points:[e.x-s,e.y,e.x+s,e.y,e.x+s,e.y+i,e.x,e.y+i+t,e.x-s,e.y+i],fill:e.color,stroke:e.color,closed:!0,listening:!1})}static createTriangle(e){let t=e.height/2;return new O.Line({points:[e.x-t,e.y,e.x+t,e.y,e.x,e.y+e.height],fill:e.color,closed:!0,listening:!1})}static createEventCatcher(e={}){return new O.Rect({...F.POSITION_TOP_LEFT,opacity:0,listening:!0,...e})}static createDebugRect(){return new O.Rect({...F.POSITION_TOP_LEFT,width:100,height:100,fill:Bf.randomHexColor(),opacity:1})}}function ll(r,e){return function(){return r.apply(e,arguments)}}const{toString:hl}=Object.prototype,{getPrototypeOf:un}=Object,cn=(r=>e=>{const t=hl.call(e);return r[t]||(r[t]=t.slice(8,-1).toLowerCase())})(Object.create(null)),wt=r=>(r=r.toLowerCase(),e=>cn(e)===r),es=r=>e=>typeof e===r,{isArray:bi}=Array,ji=es("undefined");function $f(r){return r!==null&&!ji(r)&&r.constructor!==null&&!ji(r.constructor)&&Rt(r.constructor.isBuffer)&&r.constructor.isBuffer(r)}const dl=wt("ArrayBuffer");function Vf(r){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(r):e=r&&r.buffer&&dl(r.buffer),e}const zf=es("string"),Rt=es("function"),ul=es("number"),fn=r=>r!==null&&typeof r=="object",Wf=r=>r===!0||r===!1,Tr=r=>{if(cn(r)!=="object")return!1;const e=un(r);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in r)&&!(Symbol.iterator in r)},Uf=wt("Date"),Zf=wt("File"),jf=wt("Blob"),Xf=wt("FileList"),qf=r=>fn(r)&&Rt(r.pipe),Yf=r=>{const e="[object FormData]";return r&&(typeof FormData=="function"&&r instanceof FormData||hl.call(r)===e||Rt(r.toString)&&r.toString()===e)},Kf=wt("URLSearchParams"),Jf=r=>r.trim?r.trim():r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function tr(r,e,{allOwnKeys:t=!1}={}){if(r===null||typeof r>"u")return;let i,s;if(typeof r!="object"&&(r=[r]),bi(r))for(i=0,s=r.length;i<s;i++)e.call(null,r[i],i,r);else{const n=t?Object.getOwnPropertyNames(r):Object.keys(r),a=n.length;let o;for(i=0;i<a;i++)o=n[i],e.call(null,r[o],o,r)}}function cl(r,e){e=e.toLowerCase();const t=Object.keys(r);let i=t.length,s;for(;i-- >0;)if(s=t[i],e===s.toLowerCase())return s;return null}const fl=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),pl=r=>!ji(r)&&r!==fl;function $s(){const{caseless:r}=pl(this)&&this||{},e={},t=(i,s)=>{const n=r&&cl(e,s)||s;Tr(e[n])&&Tr(i)?e[n]=$s(e[n],i):Tr(i)?e[n]=$s({},i):bi(i)?e[n]=i.slice():e[n]=i};for(let i=0,s=arguments.length;i<s;i++)arguments[i]&&tr(arguments[i],t);return e}const Qf=(r,e,t,{allOwnKeys:i}={})=>(tr(e,(s,n)=>{t&&Rt(s)?r[n]=ll(s,t):r[n]=s},{allOwnKeys:i}),r),ep=r=>(r.charCodeAt(0)===65279&&(r=r.slice(1)),r),tp=(r,e,t,i)=>{r.prototype=Object.create(e.prototype,i),r.prototype.constructor=r,Object.defineProperty(r,"super",{value:e.prototype}),t&&Object.assign(r.prototype,t)},ip=(r,e,t,i)=>{let s,n,a;const o={};if(e=e||{},r==null)return e;do{for(s=Object.getOwnPropertyNames(r),n=s.length;n-- >0;)a=s[n],(!i||i(a,r,e))&&!o[a]&&(e[a]=r[a],o[a]=!0);r=t!==!1&&un(r)}while(r&&(!t||t(r,e))&&r!==Object.prototype);return e},rp=(r,e,t)=>{r=String(r),(t===void 0||t>r.length)&&(t=r.length),t-=e.length;const i=r.indexOf(e,t);return i!==-1&&i===t},sp=r=>{if(!r)return null;if(bi(r))return r;let e=r.length;if(!ul(e))return null;const t=new Array(e);for(;e-- >0;)t[e]=r[e];return t},np=(r=>e=>r&&e instanceof r)(typeof Uint8Array<"u"&&un(Uint8Array)),ap=(r,e)=>{const i=(r&&r[Symbol.iterator]).call(r);let s;for(;(s=i.next())&&!s.done;){const n=s.value;e.call(r,n[0],n[1])}},op=(r,e)=>{let t;const i=[];for(;(t=r.exec(e))!==null;)i.push(t);return i},lp=wt("HTMLFormElement"),hp=r=>r.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(t,i,s){return i.toUpperCase()+s}),da=(({hasOwnProperty:r})=>(e,t)=>r.call(e,t))(Object.prototype),dp=wt("RegExp"),ml=(r,e)=>{const t=Object.getOwnPropertyDescriptors(r),i={};tr(t,(s,n)=>{e(s,n,r)!==!1&&(i[n]=s)}),Object.defineProperties(r,i)},up=r=>{ml(r,(e,t)=>{if(Rt(r)&&["arguments","caller","callee"].indexOf(t)!==-1)return!1;const i=r[t];if(Rt(i)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+t+"'")})}})},cp=(r,e)=>{const t={},i=s=>{s.forEach(n=>{t[n]=!0})};return bi(r)?i(r):i(String(r).split(e)),t},fp=()=>{},pp=(r,e)=>(r=+r,Number.isFinite(r)?r:e),gs="abcdefghijklmnopqrstuvwxyz",ua="0123456789",gl={DIGIT:ua,ALPHA:gs,ALPHA_DIGIT:gs+gs.toUpperCase()+ua},mp=(r=16,e=gl.ALPHA_DIGIT)=>{let t="";const{length:i}=e;for(;r--;)t+=e[Math.random()*i|0];return t};function gp(r){return!!(r&&Rt(r.append)&&r[Symbol.toStringTag]==="FormData"&&r[Symbol.iterator])}const vp=r=>{const e=new Array(10),t=(i,s)=>{if(fn(i)){if(e.indexOf(i)>=0)return;if(!("toJSON"in i)){e[s]=i;const n=bi(i)?[]:{};return tr(i,(a,o)=>{const h=t(a,s+1);!ji(h)&&(n[o]=h)}),e[s]=void 0,n}}return i};return t(r,0)},S={isArray:bi,isArrayBuffer:dl,isBuffer:$f,isFormData:Yf,isArrayBufferView:Vf,isString:zf,isNumber:ul,isBoolean:Wf,isObject:fn,isPlainObject:Tr,isUndefined:ji,isDate:Uf,isFile:Zf,isBlob:jf,isRegExp:dp,isFunction:Rt,isStream:qf,isURLSearchParams:Kf,isTypedArray:np,isFileList:Xf,forEach:tr,merge:$s,extend:Qf,trim:Jf,stripBOM:ep,inherits:tp,toFlatObject:ip,kindOf:cn,kindOfTest:wt,endsWith:rp,toArray:sp,forEachEntry:ap,matchAll:op,isHTMLForm:lp,hasOwnProperty:da,hasOwnProp:da,reduceDescriptors:ml,freezeMethods:up,toObjectSet:cp,toCamelCase:hp,noop:fp,toFiniteNumber:pp,findKey:cl,global:fl,isContextDefined:pl,ALPHABET:gl,generateString:mp,isSpecCompliantForm:gp,toJSONObject:vp};function ie(r,e,t,i,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=r,this.name="AxiosError",e&&(this.code=e),t&&(this.config=t),i&&(this.request=i),s&&(this.response=s)}S.inherits(ie,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:S.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const vl=ie.prototype,yl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(r=>{yl[r]={value:r}});Object.defineProperties(ie,yl);Object.defineProperty(vl,"isAxiosError",{value:!0});ie.from=(r,e,t,i,s,n)=>{const a=Object.create(vl);return S.toFlatObject(r,a,function(h){return h!==Error.prototype},o=>o!=="isAxiosError"),ie.call(a,r.message,e,t,i,s),a.cause=r,a.name=r.name,n&&Object.assign(a,n),a};const yp=null;function Vs(r){return S.isPlainObject(r)||S.isArray(r)}function bl(r){return S.endsWith(r,"[]")?r.slice(0,-2):r}function ca(r,e,t){return r?r.concat(e).map(function(s,n){return s=bl(s),!t&&n?"["+s+"]":s}).join(t?".":""):e}function bp(r){return S.isArray(r)&&!r.some(Vs)}const _p=S.toFlatObject(S,{},null,function(e){return/^is[A-Z]/.test(e)});function ts(r,e,t){if(!S.isObject(r))throw new TypeError("target must be an object");e=e||new FormData,t=S.toFlatObject(t,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,v){return!S.isUndefined(v[m])});const i=t.metaTokens,s=t.visitor||d,n=t.dots,a=t.indexes,h=(t.Blob||typeof Blob<"u"&&Blob)&&S.isSpecCompliantForm(e);if(!S.isFunction(s))throw new TypeError("visitor must be a function");function l(f){if(f===null)return"";if(S.isDate(f))return f.toISOString();if(!h&&S.isBlob(f))throw new ie("Blob is not supported. Use a Buffer instead.");return S.isArrayBuffer(f)||S.isTypedArray(f)?h&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function d(f,m,v){let _=f;if(f&&!v&&typeof f=="object"){if(S.endsWith(m,"{}"))m=i?m:m.slice(0,-2),f=JSON.stringify(f);else if(S.isArray(f)&&bp(f)||(S.isFileList(f)||S.endsWith(m,"[]"))&&(_=S.toArray(f)))return m=bl(m),_.forEach(function(b,T){!(S.isUndefined(b)||b===null)&&e.append(a===!0?ca([m],T,n):a===null?m:m+"[]",l(b))}),!1}return Vs(f)?!0:(e.append(ca(v,m,n),l(f)),!1)}const u=[],c=Object.assign(_p,{defaultVisitor:d,convertValue:l,isVisitable:Vs});function p(f,m){if(!S.isUndefined(f)){if(u.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));u.push(f),S.forEach(f,function(_,w){(!(S.isUndefined(_)||_===null)&&s.call(e,_,S.isString(w)?w.trim():w,m,c))===!0&&p(_,m?m.concat(w):[w])}),u.pop()}}if(!S.isObject(r))throw new TypeError("data must be an object");return p(r),e}function fa(r){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(r).replace(/[!'()~]|%20|%00/g,function(i){return e[i]})}function pn(r,e){this._pairs=[],r&&ts(r,this,e)}const _l=pn.prototype;_l.append=function(e,t){this._pairs.push([e,t])};_l.toString=function(e){const t=e?function(i){return e.call(this,i,fa)}:fa;return this._pairs.map(function(s){return t(s[0])+"="+t(s[1])},"").join("&")};function wp(r){return encodeURIComponent(r).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function wl(r,e,t){if(!e)return r;const i=t&&t.encode||wp,s=t&&t.serialize;let n;if(s?n=s(e,t):n=S.isURLSearchParams(e)?e.toString():new pn(e,t).toString(i),n){const a=r.indexOf("#");a!==-1&&(r=r.slice(0,a)),r+=(r.indexOf("?")===-1?"?":"&")+n}return r}class Sp{constructor(){this.handlers=[]}use(e,t,i){return this.handlers.push({fulfilled:e,rejected:t,synchronous:i?i.synchronous:!1,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){S.forEach(this.handlers,function(i){i!==null&&e(i)})}}const pa=Sp,Sl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Tp=typeof URLSearchParams<"u"?URLSearchParams:pn,Cp=typeof FormData<"u"?FormData:null,Ep=(()=>{let r;return typeof navigator<"u"&&((r=navigator.product)==="ReactNative"||r==="NativeScript"||r==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),kp=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),tt={isBrowser:!0,classes:{URLSearchParams:Tp,FormData:Cp,Blob},isStandardBrowserEnv:Ep,isStandardBrowserWebWorkerEnv:kp,protocols:["http","https","file","blob","url","data"]};function xp(r,e){return ts(r,new tt.classes.URLSearchParams,Object.assign({visitor:function(t,i,s,n){return tt.isNode&&S.isBuffer(t)?(this.append(i,t.toString("base64")),!1):n.defaultVisitor.apply(this,arguments)}},e))}function Pp(r){return S.matchAll(/\w+|\[(\w*)]/g,r).map(e=>e[0]==="[]"?"":e[1]||e[0])}function Ap(r){const e={},t=Object.keys(r);let i;const s=t.length;let n;for(i=0;i<s;i++)n=t[i],e[n]=r[n];return e}function Tl(r){function e(t,i,s,n){let a=t[n++];const o=Number.isFinite(+a),h=n>=t.length;return a=!a&&S.isArray(s)?s.length:a,h?(S.hasOwnProp(s,a)?s[a]=[s[a],i]:s[a]=i,!o):((!s[a]||!S.isObject(s[a]))&&(s[a]=[]),e(t,i,s[a],n)&&S.isArray(s[a])&&(s[a]=Ap(s[a])),!o)}if(S.isFormData(r)&&S.isFunction(r.entries)){const t={};return S.forEachEntry(r,(i,s)=>{e(Pp(i),s,t,0)}),t}return null}const Op={"Content-Type":void 0};function Mp(r,e,t){if(S.isString(r))try{return(e||JSON.parse)(r),S.trim(r)}catch(i){if(i.name!=="SyntaxError")throw i}return(t||JSON.stringify)(r)}const is={transitional:Sl,adapter:["xhr","http"],transformRequest:[function(e,t){const i=t.getContentType()||"",s=i.indexOf("application/json")>-1,n=S.isObject(e);if(n&&S.isHTMLForm(e)&&(e=new FormData(e)),S.isFormData(e))return s&&s?JSON.stringify(Tl(e)):e;if(S.isArrayBuffer(e)||S.isBuffer(e)||S.isStream(e)||S.isFile(e)||S.isBlob(e))return e;if(S.isArrayBufferView(e))return e.buffer;if(S.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let o;if(n){if(i.indexOf("application/x-www-form-urlencoded")>-1)return xp(e,this.formSerializer).toString();if((o=S.isFileList(e))||i.indexOf("multipart/form-data")>-1){const h=this.env&&this.env.FormData;return ts(o?{"files[]":e}:e,h&&new h,this.formSerializer)}}return n||s?(t.setContentType("application/json",!1),Mp(e)):e}],transformResponse:[function(e){const t=this.transitional||is.transitional,i=t&&t.forcedJSONParsing,s=this.responseType==="json";if(e&&S.isString(e)&&(i&&!this.responseType||s)){const a=!(t&&t.silentJSONParsing)&&s;try{return JSON.parse(e)}catch(o){if(a)throw o.name==="SyntaxError"?ie.from(o,ie.ERR_BAD_RESPONSE,this,null,this.response):o}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:tt.classes.FormData,Blob:tt.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};S.forEach(["delete","get","head"],function(e){is.headers[e]={}});S.forEach(["post","put","patch"],function(e){is.headers[e]=S.merge(Op)});const mn=is,Lp=S.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Rp=r=>{const e={};let t,i,s;return r&&r.split(`
10
+ */var ei=9e15,Dt=1e9,Ns="0123456789abcdef",$r="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Vr="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Gs={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ei,maxE:ei,crypto:!1},qo,ht,q=!0,Kr="[DecimalError] ",Lt=Kr+"Invalid argument: ",Yo=Kr+"Precision limit exceeded",Ko=Kr+"crypto unavailable",Jo="[object Decimal]",Me=Math.floor,Se=Math.pow,Wc=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Uc=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Zc=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Qo=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,je=1e7,j=7,jc=9007199254740991,Xc=$r.length-1,Ds=Vr.length-1,C={toStringTag:Jo};C.absoluteValue=C.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),z(r)};C.ceil=function(){return z(new this.constructor(this),this.e+1,2)};C.clampedTo=C.clamp=function(r,e){var t,i=this,s=i.constructor;if(r=new s(r),e=new s(e),!r.s||!e.s)return new s(NaN);if(r.gt(e))throw Error(Lt+e);return t=i.cmp(r),t<0?r:i.cmp(e)>0?e:new s(i)};C.comparedTo=C.cmp=function(r){var e,t,i,s,n=this,a=n.d,o=(r=new n.constructor(r)).d,h=n.s,l=r.s;if(!a||!o)return!h||!l?NaN:h!==l?h:a===o?0:!a^h<0?1:-1;if(!a[0]||!o[0])return a[0]?h:o[0]?-l:0;if(h!==l)return h;if(n.e!==r.e)return n.e>r.e^h<0?1:-1;for(i=a.length,s=o.length,e=0,t=i<s?i:s;e<t;++e)if(a[e]!==o[e])return a[e]>o[e]^h<0?1:-1;return i===s?0:i>s^h<0?1:-1};C.cosine=C.cos=function(){var r,e,t=this,i=t.constructor;return t.d?t.d[0]?(r=i.precision,e=i.rounding,i.precision=r+Math.max(t.e,t.sd())+j,i.rounding=1,t=qc(i,sl(i,t)),i.precision=r,i.rounding=e,z(ht==2||ht==3?t.neg():t,r,e,!0)):new i(1):new i(NaN)};C.cubeRoot=C.cbrt=function(){var r,e,t,i,s,n,a,o,h,l,d=this,u=d.constructor;if(!d.isFinite()||d.isZero())return new u(d);for(q=!1,n=d.s*Se(d.s*d,1/3),!n||Math.abs(n)==1/0?(t=xe(d.d),r=d.e,(n=(r-t.length+1)%3)&&(t+=n==1||n==-2?"0":"00"),n=Se(t,1/3),r=Me((r+1)/3)-(r%3==(r<0?-1:2)),n==1/0?t="5e"+r:(t=n.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),i=new u(t),i.s=d.s):i=new u(n.toString()),a=(r=u.precision)+3;;)if(o=i,h=o.times(o).times(o),l=h.plus(d),i=ue(l.plus(d).times(o),l.plus(h),a+2,1),xe(o.d).slice(0,a)===(t=xe(i.d)).slice(0,a))if(t=t.slice(a-3,a+1),t=="9999"||!s&&t=="4999"){if(!s&&(z(o,r+1,0),o.times(o).times(o).eq(d))){i=o;break}a+=4,s=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(z(i,r+1,1),e=!i.times(i).times(i).eq(d));break}return q=!0,z(i,r,u.rounding,e)};C.decimalPlaces=C.dp=function(){var r,e=this.d,t=NaN;if(e){if(r=e.length-1,t=(r-Me(this.e/j))*j,r=e[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};C.dividedBy=C.div=function(r){return ue(this,new this.constructor(r))};C.dividedToIntegerBy=C.divToInt=function(r){var e=this,t=e.constructor;return z(ue(e,new t(r),0,1,1),t.precision,t.rounding)};C.equals=C.eq=function(r){return this.cmp(r)===0};C.floor=function(){return z(new this.constructor(this),this.e+1,3)};C.greaterThan=C.gt=function(r){return this.cmp(r)>0};C.greaterThanOrEqualTo=C.gte=function(r){var e=this.cmp(r);return e==1||e===0};C.hyperbolicCosine=C.cosh=function(){var r,e,t,i,s,n=this,a=n.constructor,o=new a(1);if(!n.isFinite())return new a(n.s?1/0:NaN);if(n.isZero())return o;t=a.precision,i=a.rounding,a.precision=t+Math.max(n.e,n.sd())+4,a.rounding=1,s=n.d.length,s<32?(r=Math.ceil(s/3),e=(1/Qr(4,r)).toString()):(r=16,e="2.3283064365386962890625e-10"),n=ci(a,1,n.times(e),new a(1),!0);for(var h,l=r,d=new a(8);l--;)h=n.times(n),n=o.minus(h.times(d.minus(h.times(d))));return z(n,a.precision=t,a.rounding=i,!0)};C.hyperbolicSine=C.sinh=function(){var r,e,t,i,s=this,n=s.constructor;if(!s.isFinite()||s.isZero())return new n(s);if(e=n.precision,t=n.rounding,n.precision=e+Math.max(s.e,s.sd())+4,n.rounding=1,i=s.d.length,i<3)s=ci(n,2,s,s,!0);else{r=1.4*Math.sqrt(i),r=r>16?16:r|0,s=s.times(1/Qr(5,r)),s=ci(n,2,s,s,!0);for(var a,o=new n(5),h=new n(16),l=new n(20);r--;)a=s.times(s),s=s.times(o.plus(a.times(h.times(a).plus(l))))}return n.precision=e,n.rounding=t,z(s,e,t,!0)};C.hyperbolicTangent=C.tanh=function(){var r,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+7,i.rounding=1,ue(t.sinh(),t.cosh(),i.precision=r,i.rounding=e)):new i(t.s)};C.inverseCosine=C.acos=function(){var r,e=this,t=e.constructor,i=e.abs().cmp(1),s=t.precision,n=t.rounding;return i!==-1?i===0?e.isNeg()?Ue(t,s,n):new t(0):new t(NaN):e.isZero()?Ue(t,s+4,n).times(.5):(t.precision=s+6,t.rounding=1,e=e.asin(),r=Ue(t,s+4,n).times(.5),t.precision=s,t.rounding=n,r.minus(e))};C.inverseHyperbolicCosine=C.acosh=function(){var r,e,t=this,i=t.constructor;return t.lte(1)?new i(t.eq(1)?0:NaN):t.isFinite()?(r=i.precision,e=i.rounding,i.precision=r+Math.max(Math.abs(t.e),t.sd())+4,i.rounding=1,q=!1,t=t.times(t).minus(1).sqrt().plus(t),q=!0,i.precision=r,i.rounding=e,t.ln()):new i(t)};C.inverseHyperbolicSine=C.asinh=function(){var r,e,t=this,i=t.constructor;return!t.isFinite()||t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+2*Math.max(Math.abs(t.e),t.sd())+6,i.rounding=1,q=!1,t=t.times(t).plus(1).sqrt().plus(t),q=!0,i.precision=r,i.rounding=e,t.ln())};C.inverseHyperbolicTangent=C.atanh=function(){var r,e,t,i,s=this,n=s.constructor;return s.isFinite()?s.e>=0?new n(s.abs().eq(1)?s.s/0:s.isZero()?s:NaN):(r=n.precision,e=n.rounding,i=s.sd(),Math.max(i,r)<2*-s.e-1?z(new n(s),r,e,!0):(n.precision=t=i-s.e,s=ue(s.plus(1),new n(1).minus(s),t+r,1),n.precision=r+4,n.rounding=1,s=s.ln(),n.precision=r,n.rounding=e,s.times(.5))):new n(NaN)};C.inverseSine=C.asin=function(){var r,e,t,i,s=this,n=s.constructor;return s.isZero()?new n(s):(e=s.abs().cmp(1),t=n.precision,i=n.rounding,e!==-1?e===0?(r=Ue(n,t+4,i).times(.5),r.s=s.s,r):new n(NaN):(n.precision=t+6,n.rounding=1,s=s.div(new n(1).minus(s.times(s)).sqrt().plus(1)).atan(),n.precision=t,n.rounding=i,s.times(2)))};C.inverseTangent=C.atan=function(){var r,e,t,i,s,n,a,o,h,l=this,d=l.constructor,u=d.precision,c=d.rounding;if(l.isFinite()){if(l.isZero())return new d(l);if(l.abs().eq(1)&&u+4<=Ds)return a=Ue(d,u+4,c).times(.25),a.s=l.s,a}else{if(!l.s)return new d(NaN);if(u+4<=Ds)return a=Ue(d,u+4,c).times(.5),a.s=l.s,a}for(d.precision=o=u+10,d.rounding=1,t=Math.min(28,o/j+2|0),r=t;r;--r)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(q=!1,e=Math.ceil(o/j),i=1,h=l.times(l),a=new d(l),s=l;r!==-1;)if(s=s.times(h),n=a.minus(s.div(i+=2)),s=s.times(h),a=n.plus(s.div(i+=2)),a.d[e]!==void 0)for(r=e;a.d[r]===n.d[r]&&r--;);return t&&(a=a.times(2<<t-1)),q=!0,z(a,d.precision=u,d.rounding=c,!0)};C.isFinite=function(){return!!this.d};C.isInteger=C.isInt=function(){return!!this.d&&Me(this.e/j)>this.d.length-2};C.isNaN=function(){return!this.s};C.isNegative=C.isNeg=function(){return this.s<0};C.isPositive=C.isPos=function(){return this.s>0};C.isZero=function(){return!!this.d&&this.d[0]===0};C.lessThan=C.lt=function(r){return this.cmp(r)<0};C.lessThanOrEqualTo=C.lte=function(r){return this.cmp(r)<1};C.logarithm=C.log=function(r){var e,t,i,s,n,a,o,h,l=this,d=l.constructor,u=d.precision,c=d.rounding,p=5;if(r==null)r=new d(10),e=!0;else{if(r=new d(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new d(NaN);e=r.eq(10)}if(t=l.d,l.s<0||!t||!t[0]||l.eq(1))return new d(t&&!t[0]?-1/0:l.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)n=!0;else{for(s=t[0];s%10===0;)s/=10;n=s!==1}if(q=!1,o=u+p,a=Pt(l,o),i=e?zr(d,o+10):Pt(r,o),h=ue(a,i,o,1),Zi(h.d,s=u,c))do if(o+=10,a=Pt(l,o),i=e?zr(d,o+10):Pt(r,o),h=ue(a,i,o,1),!n){+xe(h.d).slice(s+1,s+15)+1==1e14&&(h=z(h,u+1,0));break}while(Zi(h.d,s+=10,c));return q=!0,z(h,u,c)};C.minus=C.sub=function(r){var e,t,i,s,n,a,o,h,l,d,u,c,p=this,f=p.constructor;if(r=new f(r),!p.d||!r.d)return!p.s||!r.s?r=new f(NaN):p.d?r.s=-r.s:r=new f(r.d||p.s!==r.s?p:NaN),r;if(p.s!=r.s)return r.s=-r.s,p.plus(r);if(l=p.d,c=r.d,o=f.precision,h=f.rounding,!l[0]||!c[0]){if(c[0])r.s=-r.s;else if(l[0])r=new f(p);else return new f(h===3?-0:0);return q?z(r,o,h):r}if(t=Me(r.e/j),d=Me(p.e/j),l=l.slice(),n=d-t,n){for(u=n<0,u?(e=l,n=-n,a=c.length):(e=c,t=d,a=l.length),i=Math.max(Math.ceil(o/j),a)+2,n>i&&(n=i,e.length=1),e.reverse(),i=n;i--;)e.push(0);e.reverse()}else{for(i=l.length,a=c.length,u=i<a,u&&(a=i),i=0;i<a;i++)if(l[i]!=c[i]){u=l[i]<c[i];break}n=0}for(u&&(e=l,l=c,c=e,r.s=-r.s),a=l.length,i=c.length-a;i>0;--i)l[a++]=0;for(i=c.length;i>n;){if(l[--i]<c[i]){for(s=i;s&&l[--s]===0;)l[s]=je-1;--l[s],l[i]+=je}l[i]-=c[i]}for(;l[--a]===0;)l.pop();for(;l[0]===0;l.shift())--t;return l[0]?(r.d=l,r.e=Jr(l,t),q?z(r,o,h):r):new f(h===3?-0:0)};C.modulo=C.mod=function(r){var e,t=this,i=t.constructor;return r=new i(r),!t.d||!r.s||r.d&&!r.d[0]?new i(NaN):!r.d||t.d&&!t.d[0]?z(new i(t),i.precision,i.rounding):(q=!1,i.modulo==9?(e=ue(t,r.abs(),0,3,1),e.s*=r.s):e=ue(t,r,0,i.modulo,1),e=e.times(r),q=!0,t.minus(e))};C.naturalExponential=C.exp=function(){return Fs(this)};C.naturalLogarithm=C.ln=function(){return Pt(this)};C.negated=C.neg=function(){var r=new this.constructor(this);return r.s=-r.s,z(r)};C.plus=C.add=function(r){var e,t,i,s,n,a,o,h,l,d,u=this,c=u.constructor;if(r=new c(r),!u.d||!r.d)return!u.s||!r.s?r=new c(NaN):u.d||(r=new c(r.d||u.s===r.s?u:NaN)),r;if(u.s!=r.s)return r.s=-r.s,u.minus(r);if(l=u.d,d=r.d,o=c.precision,h=c.rounding,!l[0]||!d[0])return d[0]||(r=new c(u)),q?z(r,o,h):r;if(n=Me(u.e/j),i=Me(r.e/j),l=l.slice(),s=n-i,s){for(s<0?(t=l,s=-s,a=d.length):(t=d,i=n,a=l.length),n=Math.ceil(o/j),a=n>a?n+1:a+1,s>a&&(s=a,t.length=1),t.reverse();s--;)t.push(0);t.reverse()}for(a=l.length,s=d.length,a-s<0&&(s=a,t=d,d=l,l=t),e=0;s;)e=(l[--s]=l[s]+d[s]+e)/je|0,l[s]%=je;for(e&&(l.unshift(e),++i),a=l.length;l[--a]==0;)l.pop();return r.d=l,r.e=Jr(l,i),q?z(r,o,h):r};C.precision=C.sd=function(r){var e,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(Lt+r);return t.d?(e=el(t.d),r&&t.e+1>e&&(e=t.e+1)):e=NaN,e};C.round=function(){var r=this,e=r.constructor;return z(new e(r),r.e+1,e.rounding)};C.sine=C.sin=function(){var r,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+Math.max(t.e,t.sd())+j,i.rounding=1,t=Kc(i,sl(i,t)),i.precision=r,i.rounding=e,z(ht>2?t.neg():t,r,e,!0)):new i(NaN)};C.squareRoot=C.sqrt=function(){var r,e,t,i,s,n,a=this,o=a.d,h=a.e,l=a.s,d=a.constructor;if(l!==1||!o||!o[0])return new d(!l||l<0&&(!o||o[0])?NaN:o?a:1/0);for(q=!1,l=Math.sqrt(+a),l==0||l==1/0?(e=xe(o),(e.length+h)%2==0&&(e+="0"),l=Math.sqrt(e),h=Me((h+1)/2)-(h<0||h%2),l==1/0?e="5e"+h:(e=l.toExponential(),e=e.slice(0,e.indexOf("e")+1)+h),i=new d(e)):i=new d(l.toString()),t=(h=d.precision)+3;;)if(n=i,i=n.plus(ue(a,n,t+2,1)).times(.5),xe(n.d).slice(0,t)===(e=xe(i.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!s&&e=="4999"){if(!s&&(z(n,h+1,0),n.times(n).eq(a))){i=n;break}t+=4,s=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(z(i,h+1,1),r=!i.times(i).eq(a));break}return q=!0,z(i,h,d.rounding,r)};C.tangent=C.tan=function(){var r,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(r=i.precision,e=i.rounding,i.precision=r+10,i.rounding=1,t=t.sin(),t.s=1,t=ue(t,new i(1).minus(t.times(t)).sqrt(),r+10,0),i.precision=r,i.rounding=e,z(ht==2||ht==4?t.neg():t,r,e,!0)):new i(NaN)};C.times=C.mul=function(r){var e,t,i,s,n,a,o,h,l,d=this,u=d.constructor,c=d.d,p=(r=new u(r)).d;if(r.s*=d.s,!c||!c[0]||!p||!p[0])return new u(!r.s||c&&!c[0]&&!p||p&&!p[0]&&!c?NaN:!c||!p?r.s/0:r.s*0);for(t=Me(d.e/j)+Me(r.e/j),h=c.length,l=p.length,h<l&&(n=c,c=p,p=n,a=h,h=l,l=a),n=[],a=h+l,i=a;i--;)n.push(0);for(i=l;--i>=0;){for(e=0,s=h+i;s>i;)o=n[s]+p[i]*c[s-i-1]+e,n[s--]=o%je|0,e=o/je|0;n[s]=(n[s]+e)%je|0}for(;!n[--a];)n.pop();return e?++t:n.shift(),r.d=n,r.e=Jr(n,t),q?z(r,u.precision,u.rounding):r};C.toBinary=function(r,e){return dn(this,2,r,e)};C.toDecimalPlaces=C.toDP=function(r,e){var t=this,i=t.constructor;return t=new i(t),r===void 0?t:(Ne(r,0,Dt),e===void 0?e=i.rounding:Ne(e,0,8),z(t,r+t.e+1,e))};C.toExponential=function(r,e){var t,i=this,s=i.constructor;return r===void 0?t=nt(i,!0):(Ne(r,0,Dt),e===void 0?e=s.rounding:Ne(e,0,8),i=z(new s(i),r+1,e),t=nt(i,!0,r+1)),i.isNeg()&&!i.isZero()?"-"+t:t};C.toFixed=function(r,e){var t,i,s=this,n=s.constructor;return r===void 0?t=nt(s):(Ne(r,0,Dt),e===void 0?e=n.rounding:Ne(e,0,8),i=z(new n(s),r+s.e+1,e),t=nt(i,!1,r+i.e+1)),s.isNeg()&&!s.isZero()?"-"+t:t};C.toFraction=function(r){var e,t,i,s,n,a,o,h,l,d,u,c,p=this,f=p.d,m=p.constructor;if(!f)return new m(p);if(l=t=new m(1),i=h=new m(0),e=new m(i),n=e.e=el(f)-p.e-1,a=n%j,e.d[0]=Se(10,a<0?j+a:a),r==null)r=n>0?e:l;else{if(o=new m(r),!o.isInt()||o.lt(l))throw Error(Lt+o);r=o.gt(e)?n>0?e:l:o}for(q=!1,o=new m(xe(f)),d=m.precision,m.precision=n=f.length*j*2;u=ue(o,e,0,1,1),s=t.plus(u.times(i)),s.cmp(r)!=1;)t=i,i=s,s=l,l=h.plus(u.times(s)),h=s,s=e,e=o.minus(u.times(s)),o=s;return s=ue(r.minus(t),i,0,1,1),h=h.plus(s.times(l)),t=t.plus(s.times(i)),h.s=l.s=p.s,c=ue(l,i,n,1).minus(p).abs().cmp(ue(h,t,n,1).minus(p).abs())<1?[l,i]:[h,t],m.precision=d,q=!0,c};C.toHexadecimal=C.toHex=function(r,e){return dn(this,16,r,e)};C.toNearest=function(r,e){var t=this,i=t.constructor;if(t=new i(t),r==null){if(!t.d)return t;r=new i(1),e=i.rounding}else{if(r=new i(r),e===void 0?e=i.rounding:Ne(e,0,8),!t.d)return r.s?t:r;if(!r.d)return r.s&&(r.s=t.s),r}return r.d[0]?(q=!1,t=ue(t,r,0,e,1).times(r),q=!0,z(t)):(r.s=t.s,t=r),t};C.toNumber=function(){return+this};C.toOctal=function(r,e){return dn(this,8,r,e)};C.toPower=C.pow=function(r){var e,t,i,s,n,a,o=this,h=o.constructor,l=+(r=new h(r));if(!o.d||!r.d||!o.d[0]||!r.d[0])return new h(Se(+o,l));if(o=new h(o),o.eq(1))return o;if(i=h.precision,n=h.rounding,r.eq(1))return z(o,i,n);if(e=Me(r.e/j),e>=r.d.length-1&&(t=l<0?-l:l)<=jc)return s=tl(h,o,t,i),r.s<0?new h(1).div(s):z(s,i,n);if(a=o.s,a<0){if(e<r.d.length-1)return new h(NaN);if(r.d[e]&1||(a=1),o.e==0&&o.d[0]==1&&o.d.length==1)return o.s=a,o}return t=Se(+o,l),e=t==0||!isFinite(t)?Me(l*(Math.log("0."+xe(o.d))/Math.LN10+o.e+1)):new h(t+"").e,e>h.maxE+1||e<h.minE-1?new h(e>0?a/0:0):(q=!1,h.rounding=o.s=1,t=Math.min(12,(e+"").length),s=Fs(r.times(Pt(o,i+t)),i),s.d&&(s=z(s,i+5,1),Zi(s.d,i,n)&&(e=i+10,s=z(Fs(r.times(Pt(o,e+t)),e),e+5,1),+xe(s.d).slice(i+1,i+15)+1==1e14&&(s=z(s,i+1,0)))),s.s=a,q=!0,h.rounding=n,z(s,i,n))};C.toPrecision=function(r,e){var t,i=this,s=i.constructor;return r===void 0?t=nt(i,i.e<=s.toExpNeg||i.e>=s.toExpPos):(Ne(r,1,Dt),e===void 0?e=s.rounding:Ne(e,0,8),i=z(new s(i),r,e),t=nt(i,r<=i.e||i.e<=s.toExpNeg,r)),i.isNeg()&&!i.isZero()?"-"+t:t};C.toSignificantDigits=C.toSD=function(r,e){var t=this,i=t.constructor;return r===void 0?(r=i.precision,e=i.rounding):(Ne(r,1,Dt),e===void 0?e=i.rounding:Ne(e,0,8)),z(new i(t),r,e)};C.toString=function(){var r=this,e=r.constructor,t=nt(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};C.truncated=C.trunc=function(){return z(new this.constructor(this),this.e+1,1)};C.valueOf=C.toJSON=function(){var r=this,e=r.constructor,t=nt(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()?"-"+t:t};function xe(r){var e,t,i,s=r.length-1,n="",a=r[0];if(s>0){for(n+=a,e=1;e<s;e++)i=r[e]+"",t=j-i.length,t&&(n+=kt(t)),n+=i;a=r[e],i=a+"",t=j-i.length,t&&(n+=kt(t))}else if(a===0)return"0";for(;a%10===0;)a/=10;return n+a}function Ne(r,e,t){if(r!==~~r||r<e||r>t)throw Error(Lt+r)}function Zi(r,e,t,i){var s,n,a,o;for(n=r[0];n>=10;n/=10)--e;return--e<0?(e+=j,s=0):(s=Math.ceil((e+1)/j),e%=j),n=Se(10,j-e),o=r[s]%n|0,i==null?e<3?(e==0?o=o/100|0:e==1&&(o=o/10|0),a=t<4&&o==99999||t>3&&o==49999||o==5e4||o==0):a=(t<4&&o+1==n||t>3&&o+1==n/2)&&(r[s+1]/n/100|0)==Se(10,e-2)-1||(o==n/2||o==0)&&(r[s+1]/n/100|0)==0:e<4?(e==0?o=o/1e3|0:e==1?o=o/100|0:e==2&&(o=o/10|0),a=(i||t<4)&&o==9999||!i&&t>3&&o==4999):a=((i||t<4)&&o+1==n||!i&&t>3&&o+1==n/2)&&(r[s+1]/n/1e3|0)==Se(10,e-3)-1,a}function Sr(r,e,t){for(var i,s=[0],n,a=0,o=r.length;a<o;){for(n=s.length;n--;)s[n]*=e;for(s[0]+=Ns.indexOf(r.charAt(a++)),i=0;i<s.length;i++)s[i]>t-1&&(s[i+1]===void 0&&(s[i+1]=0),s[i+1]+=s[i]/t|0,s[i]%=t)}return s.reverse()}function qc(r,e){var t,i,s;if(e.isZero())return e;i=e.d.length,i<32?(t=Math.ceil(i/3),s=(1/Qr(4,t)).toString()):(t=16,s="2.3283064365386962890625e-10"),r.precision+=t,e=ci(r,1,e.times(s),new r(1));for(var n=t;n--;){var a=e.times(e);e=a.times(a).minus(a).times(8).plus(1)}return r.precision-=t,e}var ue=function(){function r(i,s,n){var a,o=0,h=i.length;for(i=i.slice();h--;)a=i[h]*s+o,i[h]=a%n|0,o=a/n|0;return o&&i.unshift(o),i}function e(i,s,n,a){var o,h;if(n!=a)h=n>a?1:-1;else for(o=h=0;o<n;o++)if(i[o]!=s[o]){h=i[o]>s[o]?1:-1;break}return h}function t(i,s,n,a){for(var o=0;n--;)i[n]-=o,o=i[n]<s[n]?1:0,i[n]=o*a+i[n]-s[n];for(;!i[0]&&i.length>1;)i.shift()}return function(i,s,n,a,o,h){var l,d,u,c,p,f,m,v,_,w,b,T,L,A,G,R,H,$,I,K,W=i.constructor,le=i.s==s.s?1:-1,ne=i.d,U=s.d;if(!ne||!ne[0]||!U||!U[0])return new W(!i.s||!s.s||(ne?U&&ne[0]==U[0]:!U)?NaN:ne&&ne[0]==0||!U?le*0:le/0);for(h?(p=1,d=i.e-s.e):(h=je,p=j,d=Me(i.e/p)-Me(s.e/p)),I=U.length,H=ne.length,_=new W(le),w=_.d=[],u=0;U[u]==(ne[u]||0);u++);if(U[u]>(ne[u]||0)&&d--,n==null?(A=n=W.precision,a=W.rounding):o?A=n+(i.e-s.e)+1:A=n,A<0)w.push(1),f=!0;else{if(A=A/p+2|0,u=0,I==1){for(c=0,U=U[0],A++;(u<H||c)&&A--;u++)G=c*h+(ne[u]||0),w[u]=G/U|0,c=G%U|0;f=c||u<H}else{for(c=h/(U[0]+1)|0,c>1&&(U=r(U,c,h),ne=r(ne,c,h),I=U.length,H=ne.length),R=I,b=ne.slice(0,I),T=b.length;T<I;)b[T++]=0;K=U.slice(),K.unshift(0),$=U[0],U[1]>=h/2&&++$;do c=0,l=e(U,b,I,T),l<0?(L=b[0],I!=T&&(L=L*h+(b[1]||0)),c=L/$|0,c>1?(c>=h&&(c=h-1),m=r(U,c,h),v=m.length,T=b.length,l=e(m,b,v,T),l==1&&(c--,t(m,I<v?K:U,v,h))):(c==0&&(l=c=1),m=U.slice()),v=m.length,v<T&&m.unshift(0),t(b,m,T,h),l==-1&&(T=b.length,l=e(U,b,I,T),l<1&&(c++,t(b,I<T?K:U,T,h))),T=b.length):l===0&&(c++,b=[0]),w[u++]=c,l&&b[0]?b[T++]=ne[R]||0:(b=[ne[R]],T=1);while((R++<H||b[0]!==void 0)&&A--);f=b[0]!==void 0}w[0]||w.shift()}if(p==1)_.e=d,qo=f;else{for(u=1,c=w[0];c>=10;c/=10)u++;_.e=u+d*p-1,z(_,o?n+_.e+1:n,a,f)}return _}}();function z(r,e,t,i){var s,n,a,o,h,l,d,u,c,p=r.constructor;e:if(e!=null){if(u=r.d,!u)return r;for(s=1,o=u[0];o>=10;o/=10)s++;if(n=e-s,n<0)n+=j,a=e,d=u[c=0],h=d/Se(10,s-a-1)%10|0;else if(c=Math.ceil((n+1)/j),o=u.length,c>=o)if(i){for(;o++<=c;)u.push(0);d=h=0,s=1,n%=j,a=n-j+1}else break e;else{for(d=o=u[c],s=1;o>=10;o/=10)s++;n%=j,a=n-j+s,h=a<0?0:d/Se(10,s-a-1)%10|0}if(i=i||e<0||u[c+1]!==void 0||(a<0?d:d%Se(10,s-a-1)),l=t<4?(h||i)&&(t==0||t==(r.s<0?3:2)):h>5||h==5&&(t==4||i||t==6&&(n>0?a>0?d/Se(10,s-a):0:u[c-1])%10&1||t==(r.s<0?8:7)),e<1||!u[0])return u.length=0,l?(e-=r.e+1,u[0]=Se(10,(j-e%j)%j),r.e=-e||0):u[0]=r.e=0,r;if(n==0?(u.length=c,o=1,c--):(u.length=c+1,o=Se(10,j-n),u[c]=a>0?(d/Se(10,s-a)%Se(10,a)|0)*o:0),l)for(;;)if(c==0){for(n=1,a=u[0];a>=10;a/=10)n++;for(a=u[0]+=o,o=1;a>=10;a/=10)o++;n!=o&&(r.e++,u[0]==je&&(u[0]=1));break}else{if(u[c]+=o,u[c]!=je)break;u[c--]=0,o=1}for(n=u.length;u[--n]===0;)u.pop()}return q&&(r.e>p.maxE?(r.d=null,r.e=NaN):r.e<p.minE&&(r.e=0,r.d=[0])),r}function nt(r,e,t){if(!r.isFinite())return rl(r);var i,s=r.e,n=xe(r.d),a=n.length;return e?(t&&(i=t-a)>0?n=n.charAt(0)+"."+n.slice(1)+kt(i):a>1&&(n=n.charAt(0)+"."+n.slice(1)),n=n+(r.e<0?"e":"e+")+r.e):s<0?(n="0."+kt(-s-1)+n,t&&(i=t-a)>0&&(n+=kt(i))):s>=a?(n+=kt(s+1-a),t&&(i=t-s-1)>0&&(n=n+"."+kt(i))):((i=s+1)<a&&(n=n.slice(0,i)+"."+n.slice(i)),t&&(i=t-a)>0&&(s+1===a&&(n+="."),n+=kt(i))),n}function Jr(r,e){var t=r[0];for(e*=j;t>=10;t/=10)e++;return e}function zr(r,e,t){if(e>Xc)throw q=!0,t&&(r.precision=t),Error(Yo);return z(new r($r),e,1,!0)}function Ue(r,e,t){if(e>Ds)throw Error(Yo);return z(new r(Vr),e,t,!0)}function el(r){var e=r.length-1,t=e*j+1;if(e=r[e],e){for(;e%10==0;e/=10)t--;for(e=r[0];e>=10;e/=10)t++}return t}function kt(r){for(var e="";r--;)e+="0";return e}function tl(r,e,t,i){var s,n=new r(1),a=Math.ceil(i/j+4);for(q=!1;;){if(t%2&&(n=n.times(e),ra(n.d,a)&&(s=!0)),t=Me(t/2),t===0){t=n.d.length-1,s&&n.d[t]===0&&++n.d[t];break}e=e.times(e),ra(e.d,a)}return q=!0,n}function ia(r){return r.d[r.d.length-1]&1}function il(r,e,t){for(var i,s=new r(e[0]),n=0;++n<e.length;)if(i=new r(e[n]),i.s)s[t](i)&&(s=i);else{s=i;break}return s}function Fs(r,e){var t,i,s,n,a,o,h,l=0,d=0,u=0,c=r.constructor,p=c.rounding,f=c.precision;if(!r.d||!r.d[0]||r.e>17)return new c(r.d?r.d[0]?r.s<0?0:1/0:1:r.s?r.s<0?0:r:0/0);for(e==null?(q=!1,h=f):h=e,o=new c(.03125);r.e>-2;)r=r.times(o),u+=5;for(i=Math.log(Se(2,u))/Math.LN10*2+5|0,h+=i,t=n=a=new c(1),c.precision=h;;){if(n=z(n.times(r),h,1),t=t.times(++d),o=a.plus(ue(n,t,h,1)),xe(o.d).slice(0,h)===xe(a.d).slice(0,h)){for(s=u;s--;)a=z(a.times(a),h,1);if(e==null)if(l<3&&Zi(a.d,h-i,p,l))c.precision=h+=10,t=n=o=new c(1),d=0,l++;else return z(a,c.precision=f,p,q=!0);else return c.precision=f,a}a=o}}function Pt(r,e){var t,i,s,n,a,o,h,l,d,u,c,p=1,f=10,m=r,v=m.d,_=m.constructor,w=_.rounding,b=_.precision;if(m.s<0||!v||!v[0]||!m.e&&v[0]==1&&v.length==1)return new _(v&&!v[0]?-1/0:m.s!=1?NaN:v?0:m);if(e==null?(q=!1,d=b):d=e,_.precision=d+=f,t=xe(v),i=t.charAt(0),Math.abs(n=m.e)<15e14){for(;i<7&&i!=1||i==1&&t.charAt(1)>3;)m=m.times(r),t=xe(m.d),i=t.charAt(0),p++;n=m.e,i>1?(m=new _("0."+t),n++):m=new _(i+"."+t.slice(1))}else return l=zr(_,d+2,b).times(n+""),m=Pt(new _(i+"."+t.slice(1)),d-f).plus(l),_.precision=b,e==null?z(m,b,w,q=!0):m;for(u=m,h=a=m=ue(m.minus(1),m.plus(1),d,1),c=z(m.times(m),d,1),s=3;;){if(a=z(a.times(c),d,1),l=h.plus(ue(a,new _(s),d,1)),xe(l.d).slice(0,d)===xe(h.d).slice(0,d))if(h=h.times(2),n!==0&&(h=h.plus(zr(_,d+2,b).times(n+""))),h=ue(h,new _(p),d,1),e==null)if(Zi(h.d,d-f,w,o))_.precision=d+=f,l=a=m=ue(u.minus(1),u.plus(1),d,1),c=z(m.times(m),d,1),s=o=1;else return z(h,_.precision=b,w,q=!0);else return _.precision=b,h;h=l,s+=2}}function rl(r){return String(r.s*r.s/0)}function Hs(r,e){var t,i,s;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(t<0&&(t=i),t+=+e.slice(i+1),e=e.substring(0,i)):t<0&&(t=e.length),i=0;e.charCodeAt(i)===48;i++);for(s=e.length;e.charCodeAt(s-1)===48;--s);if(e=e.slice(i,s),e){if(s-=i,r.e=t=t-i-1,r.d=[],i=(t+1)%j,t<0&&(i+=j),i<s){for(i&&r.d.push(+e.slice(0,i)),s-=j;i<s;)r.d.push(+e.slice(i,i+=j));e=e.slice(i),i=j-e.length}else i-=s;for(;i--;)e+="0";r.d.push(+e),q&&(r.e>r.constructor.maxE?(r.d=null,r.e=NaN):r.e<r.constructor.minE&&(r.e=0,r.d=[0]))}else r.e=0,r.d=[0];return r}function Yc(r,e){var t,i,s,n,a,o,h,l,d;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Qo.test(e))return Hs(r,e)}else if(e==="Infinity"||e==="NaN")return+e||(r.s=NaN),r.e=NaN,r.d=null,r;if(Uc.test(e))t=16,e=e.toLowerCase();else if(Wc.test(e))t=2;else if(Zc.test(e))t=8;else throw Error(Lt+e);for(n=e.search(/p/i),n>0?(h=+e.slice(n+1),e=e.substring(2,n)):e=e.slice(2),n=e.indexOf("."),a=n>=0,i=r.constructor,a&&(e=e.replace(".",""),o=e.length,n=o-n,s=tl(i,new i(t),n,n*2)),l=Sr(e,t,je),d=l.length-1,n=d;l[n]===0;--n)l.pop();return n<0?new i(r.s*0):(r.e=Jr(l,d),r.d=l,q=!1,a&&(r=ue(r,s,o*4)),h&&(r=r.times(Math.abs(h)<54?Se(2,h):Z.pow(2,h))),q=!0,r)}function Kc(r,e){var t,i=e.d.length;if(i<3)return e.isZero()?e:ci(r,2,e,e);t=1.4*Math.sqrt(i),t=t>16?16:t|0,e=e.times(1/Qr(5,t)),e=ci(r,2,e,e);for(var s,n=new r(5),a=new r(16),o=new r(20);t--;)s=e.times(e),e=e.times(n.plus(s.times(a.times(s).minus(o))));return e}function ci(r,e,t,i,s){var n,a,o,h,l=r.precision,d=Math.ceil(l/j);for(q=!1,h=t.times(t),o=new r(i);;){if(a=ue(o.times(h),new r(e++*e++),l,1),o=s?i.plus(a):i.minus(a),i=ue(a.times(h),new r(e++*e++),l,1),a=o.plus(i),a.d[d]!==void 0){for(n=d;a.d[n]===o.d[n]&&n--;);if(n==-1)break}n=o,o=i,i=a,a=n}return q=!0,a.d.length=d+1,a}function Qr(r,e){for(var t=r;--e;)t*=r;return t}function sl(r,e){var t,i=e.s<0,s=Ue(r,r.precision,1),n=s.times(.5);if(e=e.abs(),e.lte(n))return ht=i?4:1,e;if(t=e.divToInt(s),t.isZero())ht=i?3:2;else{if(e=e.minus(t.times(s)),e.lte(n))return ht=ia(t)?i?2:3:i?4:1,e;ht=ia(t)?i?1:4:i?3:2}return e.minus(s).abs()}function dn(r,e,t,i){var s,n,a,o,h,l,d,u,c,p=r.constructor,f=t!==void 0;if(f?(Ne(t,1,Dt),i===void 0?i=p.rounding:Ne(i,0,8)):(t=p.precision,i=p.rounding),!r.isFinite())d=rl(r);else{for(d=nt(r),a=d.indexOf("."),f?(s=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):s=e,a>=0&&(d=d.replace(".",""),c=new p(1),c.e=d.length-a,c.d=Sr(nt(c),10,s),c.e=c.d.length),u=Sr(d,10,s),n=h=u.length;u[--h]==0;)u.pop();if(!u[0])d=f?"0p+0":"0";else{if(a<0?n--:(r=new p(r),r.d=u,r.e=n,r=ue(r,c,t,i,0,s),u=r.d,n=r.e,l=qo),a=u[t],o=s/2,l=l||u[t+1]!==void 0,l=i<4?(a!==void 0||l)&&(i===0||i===(r.s<0?3:2)):a>o||a===o&&(i===4||l||i===6&&u[t-1]&1||i===(r.s<0?8:7)),u.length=t,l)for(;++u[--t]>s-1;)u[t]=0,t||(++n,u.unshift(1));for(h=u.length;!u[h-1];--h);for(a=0,d="";a<h;a++)d+=Ns.charAt(u[a]);if(f){if(h>1)if(e==16||e==8){for(a=e==16?4:3,--h;h%a;h++)d+="0";for(u=Sr(d,s,e),h=u.length;!u[h-1];--h);for(a=1,d="1.";a<h;a++)d+=Ns.charAt(u[a])}else d=d.charAt(0)+"."+d.slice(1);d=d+(n<0?"p":"p+")+n}else if(n<0){for(;++n;)d="0"+d;d="0."+d}else if(++n>h)for(n-=h;n--;)d+="0";else n<h&&(d=d.slice(0,n)+"."+d.slice(n))}d=(e==16?"0x":e==2?"0b":e==8?"0o":"")+d}return r.s<0?"-"+d:d}function ra(r,e){if(r.length>e)return r.length=e,!0}function Jc(r){return new this(r).abs()}function Qc(r){return new this(r).acos()}function ef(r){return new this(r).acosh()}function tf(r,e){return new this(r).plus(e)}function rf(r){return new this(r).asin()}function sf(r){return new this(r).asinh()}function nf(r){return new this(r).atan()}function af(r){return new this(r).atanh()}function of(r,e){r=new this(r),e=new this(e);var t,i=this.precision,s=this.rounding,n=i+4;return!r.s||!e.s?t=new this(NaN):!r.d&&!e.d?(t=Ue(this,n,1).times(e.s>0?.25:.75),t.s=r.s):!e.d||r.isZero()?(t=e.s<0?Ue(this,i,s):new this(0),t.s=r.s):!r.d||e.isZero()?(t=Ue(this,n,1).times(.5),t.s=r.s):e.s<0?(this.precision=n,this.rounding=1,t=this.atan(ue(r,e,n,1)),e=Ue(this,n,1),this.precision=i,this.rounding=s,t=r.s<0?t.minus(e):t.plus(e)):t=this.atan(ue(r,e,n,1)),t}function lf(r){return new this(r).cbrt()}function hf(r){return z(r=new this(r),r.e+1,2)}function df(r,e,t){return new this(r).clamp(e,t)}function uf(r){if(!r||typeof r!="object")throw Error(Kr+"Object expected");var e,t,i,s=r.defaults===!0,n=["precision",1,Dt,"rounding",0,8,"toExpNeg",-ei,0,"toExpPos",0,ei,"maxE",0,ei,"minE",-ei,0,"modulo",0,9];for(e=0;e<n.length;e+=3)if(t=n[e],s&&(this[t]=Gs[t]),(i=r[t])!==void 0)if(Me(i)===i&&i>=n[e+1]&&i<=n[e+2])this[t]=i;else throw Error(Lt+t+": "+i);if(t="crypto",s&&(this[t]=Gs[t]),(i=r[t])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Ko);else this[t]=!1;else throw Error(Lt+t+": "+i);return this}function cf(r){return new this(r).cos()}function ff(r){return new this(r).cosh()}function nl(r){var e,t,i;function s(n){var a,o,h,l=this;if(!(l instanceof s))return new s(n);if(l.constructor=s,sa(n)){l.s=n.s,q?!n.d||n.e>s.maxE?(l.e=NaN,l.d=null):n.e<s.minE?(l.e=0,l.d=[0]):(l.e=n.e,l.d=n.d.slice()):(l.e=n.e,l.d=n.d?n.d.slice():n.d);return}if(h=typeof n,h==="number"){if(n===0){l.s=1/n<0?-1:1,l.e=0,l.d=[0];return}if(n<0?(n=-n,l.s=-1):l.s=1,n===~~n&&n<1e7){for(a=0,o=n;o>=10;o/=10)a++;q?a>s.maxE?(l.e=NaN,l.d=null):a<s.minE?(l.e=0,l.d=[0]):(l.e=a,l.d=[n]):(l.e=a,l.d=[n]);return}else if(n*0!==0){n||(l.s=NaN),l.e=NaN,l.d=null;return}return Hs(l,n.toString())}else if(h!=="string")throw Error(Lt+n);return(o=n.charCodeAt(0))===45?(n=n.slice(1),l.s=-1):(o===43&&(n=n.slice(1)),l.s=1),Qo.test(n)?Hs(l,n):Yc(l,n)}if(s.prototype=C,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=uf,s.clone=nl,s.isDecimal=sa,s.abs=Jc,s.acos=Qc,s.acosh=ef,s.add=tf,s.asin=rf,s.asinh=sf,s.atan=nf,s.atanh=af,s.atan2=of,s.cbrt=lf,s.ceil=hf,s.clamp=df,s.cos=cf,s.cosh=ff,s.div=pf,s.exp=mf,s.floor=gf,s.hypot=vf,s.ln=yf,s.log=bf,s.log10=wf,s.log2=_f,s.max=Sf,s.min=Tf,s.mod=Cf,s.mul=Ef,s.pow=kf,s.random=xf,s.round=Pf,s.sign=Af,s.sin=Of,s.sinh=Mf,s.sqrt=Lf,s.sub=Rf,s.sum=If,s.tan=Nf,s.tanh=Gf,s.trunc=Df,r===void 0&&(r={}),r&&r.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)r.hasOwnProperty(t=i[e++])||(r[t]=this[t]);return s.config(r),s}function pf(r,e){return new this(r).div(e)}function mf(r){return new this(r).exp()}function gf(r){return z(r=new this(r),r.e+1,3)}function vf(){var r,e,t=new this(0);for(q=!1,r=0;r<arguments.length;)if(e=new this(arguments[r++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return q=!0,new this(1/0);t=e}return q=!0,t.sqrt()}function sa(r){return r instanceof Z||r&&r.toStringTag===Jo||!1}function yf(r){return new this(r).ln()}function bf(r,e){return new this(r).log(e)}function _f(r){return new this(r).log(2)}function wf(r){return new this(r).log(10)}function Sf(){return il(this,arguments,"lt")}function Tf(){return il(this,arguments,"gt")}function Cf(r,e){return new this(r).mod(e)}function Ef(r,e){return new this(r).mul(e)}function kf(r,e){return new this(r).pow(e)}function xf(r){var e,t,i,s,n=0,a=new this(1),o=[];if(r===void 0?r=this.precision:Ne(r,1,Dt),i=Math.ceil(r/j),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));n<i;)s=e[n],s>=429e7?e[n]=crypto.getRandomValues(new Uint32Array(1))[0]:o[n++]=s%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(i*=4);n<i;)s=e[n]+(e[n+1]<<8)+(e[n+2]<<16)+((e[n+3]&127)<<24),s>=214e7?crypto.randomBytes(4).copy(e,n):(o.push(s%1e7),n+=4);n=i/4}else throw Error(Ko);else for(;n<i;)o[n++]=Math.random()*1e7|0;for(i=o[--n],r%=j,i&&r&&(s=Se(10,j-r),o[n]=(i/s|0)*s);o[n]===0;n--)o.pop();if(n<0)t=0,o=[0];else{for(t=-1;o[0]===0;t-=j)o.shift();for(i=1,s=o[0];s>=10;s/=10)i++;i<j&&(t-=j-i)}return a.e=t,a.d=o,a}function Pf(r){return z(r=new this(r),r.e+1,this.rounding)}function Af(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function Of(r){return new this(r).sin()}function Mf(r){return new this(r).sinh()}function Lf(r){return new this(r).sqrt()}function Rf(r,e){return new this(r).sub(e)}function If(){var r=0,e=arguments,t=new this(e[r]);for(q=!1;t.s&&++r<e.length;)t=t.plus(e[r]);return q=!0,z(t,this.precision,this.rounding)}function Nf(r){return new this(r).tan()}function Gf(r){return new this(r).tanh()}function Df(r){return z(r=new this(r),r.e+1,1)}C[Symbol.for("nodejs.util.inspect.custom")]=C.toString;C[Symbol.toStringTag]="Decimal";var Z=C.constructor=nl(Gs);$r=new Z($r);Vr=new Z(Vr);const na={editable:!0,style:{...jo,markerSymbolSize:20,periodMarkerHandleType:"start"}};class aa extends Xo{constructor(e,t,i){super({...na,...e,style:{...na.style,...e.style}},t,i)}createSymbol(){switch(this.style.markerSymbolType){case"triangle":let t=Z.sqrt(2).mul(this.style.markerSymbolSize).toNumber()/2;return new O.Line({points:this.style.periodMarkerHandleType==="start"?[-t,0,0,0,0,t]:[0,0,t,0,0,t],fill:this.style.color,closed:!0,offsetY:t/2});case"circle":return new O.Arc({fill:this.style.color,innerRadius:0,outerRadius:this.style.markerSymbolSize/2,angle:180,rotation:this.style.periodMarkerHandleType==="start"?90:-90});case"square":return new O.Line({points:[0,0,this.style.markerSymbolSize,0,this.style.markerSymbolSize,this.style.markerSymbolSize],fill:this.style.color,closed:!0,rotation:this.style.periodMarkerHandleType==="start"?225:45,offsetX:this.style.markerSymbolSize/2,offsetY:this.style.markerSymbolSize/2});default:throw Error("Unknown type")}}}const oa={editable:!0,style:{...Uo,selectedAreaOpacity:.2,markerHandleAreaOpacity:.7}};class al extends Zo{constructor(e){super({...oa,...e,style:{...oa.style,...e.style}}),this.observation.start=_e.coerce.number().min(0).optional().nullable().parse(this.observation.start),this.observation.end=_e.coerce.number().min(0).optional().nullable().parse(this.observation.end),this.observation.end!=null&&this.observation.start!=null&&(this.observation.start=_e.coerce.number().lte(this.observation.end).parse(this.observation.start))}createCanvasNode(){return super.createCanvasNode(),this.initStartMarkerHandle(),this.initEndMarkerHandle(),this.initSelectedAreaRect(),this.group}onChange(){this.settlePosition();let e={timeObservation:this.observation};this.onChange$.next(e)}onMeasurementsChange(){super.onMeasurementsChange();let e=this.startMarkerHandle.getVerticalMeasurement();this.selectedAreaRect&&this.selectedAreaRect.setAttrs({y:e.y,height:e.height});let t={y:this.startMarkerHandle.getHandleGroup().y(),height:this.startMarkerHandle.getHandleGroup().getClientRect().height};this.markerHandleRect.setAttrs({y:e.y+t.y-t.height/2,height:t.height}),this.settlePosition()}initSelectedAreaRect(){if(this.selectedAreaRect&&this.selectedAreaRect.destroy(),this.markerHandleRect&&this.markerHandleRect.destroy(),!this.hasStart()||!this.hasEnd())return;let e=this.startMarkerHandle.getVerticalMeasurement(),t=this.timeline.timeToTimelinePosition(this.observation.start),i=this.timeline.timeToTimelinePosition(this.observation.end);this.selectedAreaRect=new O.Rect({x:t,y:e.y,width:i-t,height:e.height,listening:!1,fill:this.style.color,opacity:this.style.selectedAreaOpacity});let s={y:this.startMarkerHandle.getHandleGroup().y(),height:this.startMarkerHandle.getHandleGroup().getClientRect().height};this.markerHandleRect=new O.Rect({x:t,y:e.y+s.y-s.height/2,width:i-t,height:s.height,listening:!1,fill:this.style.color,opacity:this.style.markerHandleAreaOpacity}),this.group.add(this.selectedAreaRect),this.group.add(this.markerHandleRect)}initStartMarkerHandle(){if(this.startMarkerHandle&&(this.startMarkerHandle.destroy(),this.startMarkerHandle=void 0),!this.hasStart())return;let e=this.timeline.timeToTimelinePosition(this.observation.start);this.startMarkerHandle=new aa({x:e,editable:this.editable,style:{color:this.style.color,markerRenderType:this.style.renderType,markerSymbolType:this.style.symbolType,periodMarkerHandleType:"start"}},this.markerLane,this.timeline),this.startMarkerHandle.onDrag=t=>{this.editable&&(this.hasEnd()&&t.x()>this.endMarkerHandle.getPosition().x&&t.x(this.endMarkerHandle.getPosition().x),this.settleMeasurements(),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(1))},this.startMarkerHandle.onDragEnd=t=>{if(this.editable){let i=this.timeline.timelinePositionToTime(t.x());this.setTimeObservation({...this.observation,start:i}),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(this.style.markerHandleAreaOpacity)}},this.group.add(this.startMarkerHandle.initCanvasNode())}initEndMarkerHandle(){if(this.endMarkerHandle&&(this.endMarkerHandle.destroy(),this.endMarkerHandle=void 0),!this.hasEnd())return;let e=this.hasEnd()?this.timeline.timeToTimelinePosition(this.observation.end):void 0;this.endMarkerHandle=new aa({x:e,editable:this.editable,style:{periodMarkerHandleType:"end",color:this.style.color,markerRenderType:this.style.renderType,markerSymbolType:this.style.symbolType}},this.markerLane,this.timeline),this.endMarkerHandle.onDrag=t=>{this.editable&&(this.hasStart()&&t.x()<this.startMarkerHandle.getPosition().x&&t.x(this.startMarkerHandle.getPosition().x),this.settleMeasurements(),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(1))},this.endMarkerHandle.onDragEnd=t=>{if(this.editable){let i=this.timeline.timelinePositionToTime(t.x());this.setTimeObservation({...this.observation,end:i}),this.hasStart()&&this.hasEnd()&&this.markerHandleRect.opacity(this.style.markerHandleAreaOpacity)}},this.group.add(this.endMarkerHandle.initCanvasNode())}settlePosition(){this.hasStart()&&this.startMarkerHandle.setPosition({...this.startMarkerHandle.getPosition(),x:this.timeline.timeToTimelinePosition(this.observation.start)}),this.hasEnd()&&this.endMarkerHandle.setPosition({...this.endMarkerHandle.getPosition(),x:this.timeline.timeToTimelinePosition(this.observation.end)}),this.settleMeasurements()}settleMeasurements(){this.hasStart()&&this.hasEnd()&&(this.selectedAreaRect.setAttrs({x:this.startMarkerHandle.getPosition().x,width:this.endMarkerHandle.getPosition().x-this.startMarkerHandle.getPosition().x}),this.markerHandleRect.setAttrs({x:this.startMarkerHandle.getPosition().x,width:this.endMarkerHandle.getPosition().x-this.startMarkerHandle.getPosition().x}))}setTimeObservation(e){this.editable&&(this.observation=e,this.initStartMarkerHandle(),this.initEndMarkerHandle(),this.initSelectedAreaRect(),this.onChange())}setEditable(e){super.setEditable(e)}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.styleAdapter.onChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.hasStart()&&this.initStartMarkerHandle(),this.hasEnd()&&this.initEndMarkerHandle(),this.hasStart()&&this.hasEnd()&&this.initSelectedAreaRect()})}hasStart(){return this.observation&&this.observation.start!==null&&this.observation.start!==void 0}hasEnd(){return this.observation&&this.observation.end!==null&&this.observation.end!==void 0}}const la={editable:!0,style:{...jo,markerSymbolSize:20}};class Ff extends Xo{constructor(e,t,i){super({...la,...e,style:{...la.style,...e.style}},t,i)}createSymbol(){switch(this.style.markerSymbolType){case"triangle":let t=Z.sqrt(2).mul(this.style.markerSymbolSize).toNumber()/2;return new O.Line({points:[-t,0,t,0,0,t],fill:this.style.color,closed:!0,offsetY:t/2});case"circle":return new O.Circle({fill:this.style.color,radius:this.style.markerSymbolSize/2});case"square":return new O.Rect({fill:this.style.color,width:this.style.markerSymbolSize,height:this.style.markerSymbolSize,rotation:45,offsetX:this.style.markerSymbolSize/2,offsetY:this.style.markerSymbolSize/2});default:throw Error("Unknown type")}}}const ha={description:"",editable:!0,style:{...Uo}};class ol extends Zo{constructor(e){super({...ha,...e,style:{...ha.style,...e.style}}),this.observation.time=_e.coerce.number().min(0).parse(this.observation.time)}createCanvasNode(){return super.createCanvasNode(),this.initMarkerHandle(),this.group}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.styleAdapter.onChange$.subscribe(e=>{this.initMarkerHandle()})}initMarkerHandle(){this.markerHandle&&(this.markerHandle.destroy(),this.markerHandle=void 0);let e=this.timeline.timeToTimelinePosition(this.observation.time);this.markerHandle=new Ff({x:e,editable:this.editable,style:{color:this.style.color,markerRenderType:this.style.renderType,markerSymbolType:this.style.symbolType}},this.markerLane,this.timeline),this.markerHandle.onDragEnd=t=>{if(this.editable){let i=this.timeline.timelinePositionToTime(t.x());this.setTimeObservation({...this.observation,time:i})}},this.group.add(this.markerHandle.initCanvasNode())}onChange(){this.settlePosition();let e={timeObservation:this.observation};this.onChange$.next(e)}onMeasurementsChange(){super.onMeasurementsChange(),this.markerHandle.onMeasurementsChange(),this.settlePosition()}settlePosition(){this.markerHandle.setPosition({...this.markerHandle.getPosition(),x:this.timeline.timeToTimelinePosition(this.observation.time)})}setEditable(e){super.setEditable(e)}}const Hf={...Qi};class Bs extends er{constructor(e){super({...e,style:{...Hf,...e.style}}),this.onMarkerFocus$=new V,this.markers=[],this.markersMap=new Map}createCanvasNode(){return super.createCanvasNode(),this.markersGroup=new O.Group({...F.POSITION_TOP_LEFT,...this.timeline.getTimecodedGroupDimension()}),this.timeline.addToTimecodedMarkersGroup(this.markersGroup),this.bodyGroup}settleLayout(){super.settleLayout();let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.markersGroup].forEach(t=>{t.width(e.width)}),this.markers&&this.markers.forEach(t=>{t.onMeasurementsChange()})}destroy(){super.destroy(),this.markersGroup.destroy()}clearContent(){this.removeAllMarkers(),this.markers=[],this.markersMap=new Map,this.markersGroup.destroyChildren()}createMomentMarker(e){return this.addMarker(new ol(e))}createPeriodMarker(e){return this.addMarker(new al(e))}addMarker(e){if(!this.isInitialized())throw new Error("MarkerLane not initalized. Maybe you forgot to add MarkerLane to Timeline?");if(this.markersMap.has(e.getId()))throw new Error(`Marker with id=${e.getId()} already exists`);return e.setMarkerLane(this),e.setTimeline(this.timeline),e.onClick$.pipe(k(this.onDestroy$)).subscribe(t=>{this.focusMarker(e.getId())}),e.onMouseEnter$.pipe(k(this.onDestroy$)).subscribe(t=>{this.focusMarker(e.getId())}),this.markers.push(e),this.markersMap.set(e.getId(),e),this.markersGroup.add(e.initCanvasNode()),e}removeAllMarkers(){this.markers&&this.markers.forEach(e=>{this.removeMarker(e.getId())})}removeMarker(e){let t=this.getMarker(e);t&&(this.markers.splice(this.markers.findIndex(i=>i.getId()===t.getId()),1),this.markersMap.delete(t.getId()),t.destroy())}getMarker(e){return this.markersMap.get(e)}getMarkers(){return this.markers}focusMarker(e){let t=this.getMarker(e);t&&(this.moveToTop(t),this.markerInFocus=t,this.onMarkerFocus$.next({marker:t}))}getMarkerInFocus(){return this.markerInFocus}moveToTop(e){e&&(this.markersGroup.moveToTop(),e.getCanvasNode().moveToTop())}}class Bf{static randomHexColor(){return`#${Math.floor(Math.random()*16777215).toString(16)}`}}class yi{static createGoldenRatioWedge(e){let t=new Z(e.height).div(F.GOLDEN_RATIO+1).toDecimalPlaces(2).toNumber(),i=e.height-t,s=i/2;return new O.Line({points:[e.x-s,e.y,e.x+s,e.y,e.x+s,e.y+i,e.x,e.y+i+t,e.x-s,e.y+i],fill:e.color,stroke:e.color,closed:!0,listening:!1})}static createTriangle(e){let t=e.height/2;return new O.Line({points:[e.x-t,e.y,e.x+t,e.y,e.x,e.y+e.height],fill:e.color,closed:!0,listening:!1})}static createEventCatcher(e={}){return new O.Rect({...F.POSITION_TOP_LEFT,opacity:0,listening:!0,...e})}static createDebugRect(){return new O.Rect({...F.POSITION_TOP_LEFT,width:100,height:100,fill:Bf.randomHexColor(),opacity:1})}}function ll(r,e){return function(){return r.apply(e,arguments)}}const{toString:hl}=Object.prototype,{getPrototypeOf:un}=Object,cn=(r=>e=>{const t=hl.call(e);return r[t]||(r[t]=t.slice(8,-1).toLowerCase())})(Object.create(null)),wt=r=>(r=r.toLowerCase(),e=>cn(e)===r),es=r=>e=>typeof e===r,{isArray:bi}=Array,ji=es("undefined");function $f(r){return r!==null&&!ji(r)&&r.constructor!==null&&!ji(r.constructor)&&Rt(r.constructor.isBuffer)&&r.constructor.isBuffer(r)}const dl=wt("ArrayBuffer");function Vf(r){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(r):e=r&&r.buffer&&dl(r.buffer),e}const zf=es("string"),Rt=es("function"),ul=es("number"),fn=r=>r!==null&&typeof r=="object",Wf=r=>r===!0||r===!1,Tr=r=>{if(cn(r)!=="object")return!1;const e=un(r);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in r)&&!(Symbol.iterator in r)},Uf=wt("Date"),Zf=wt("File"),jf=wt("Blob"),Xf=wt("FileList"),qf=r=>fn(r)&&Rt(r.pipe),Yf=r=>{const e="[object FormData]";return r&&(typeof FormData=="function"&&r instanceof FormData||hl.call(r)===e||Rt(r.toString)&&r.toString()===e)},Kf=wt("URLSearchParams"),Jf=r=>r.trim?r.trim():r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function tr(r,e,{allOwnKeys:t=!1}={}){if(r===null||typeof r>"u")return;let i,s;if(typeof r!="object"&&(r=[r]),bi(r))for(i=0,s=r.length;i<s;i++)e.call(null,r[i],i,r);else{const n=t?Object.getOwnPropertyNames(r):Object.keys(r),a=n.length;let o;for(i=0;i<a;i++)o=n[i],e.call(null,r[o],o,r)}}function cl(r,e){e=e.toLowerCase();const t=Object.keys(r);let i=t.length,s;for(;i-- >0;)if(s=t[i],e===s.toLowerCase())return s;return null}const fl=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),pl=r=>!ji(r)&&r!==fl;function $s(){const{caseless:r}=pl(this)&&this||{},e={},t=(i,s)=>{const n=r&&cl(e,s)||s;Tr(e[n])&&Tr(i)?e[n]=$s(e[n],i):Tr(i)?e[n]=$s({},i):bi(i)?e[n]=i.slice():e[n]=i};for(let i=0,s=arguments.length;i<s;i++)arguments[i]&&tr(arguments[i],t);return e}const Qf=(r,e,t,{allOwnKeys:i}={})=>(tr(e,(s,n)=>{t&&Rt(s)?r[n]=ll(s,t):r[n]=s},{allOwnKeys:i}),r),ep=r=>(r.charCodeAt(0)===65279&&(r=r.slice(1)),r),tp=(r,e,t,i)=>{r.prototype=Object.create(e.prototype,i),r.prototype.constructor=r,Object.defineProperty(r,"super",{value:e.prototype}),t&&Object.assign(r.prototype,t)},ip=(r,e,t,i)=>{let s,n,a;const o={};if(e=e||{},r==null)return e;do{for(s=Object.getOwnPropertyNames(r),n=s.length;n-- >0;)a=s[n],(!i||i(a,r,e))&&!o[a]&&(e[a]=r[a],o[a]=!0);r=t!==!1&&un(r)}while(r&&(!t||t(r,e))&&r!==Object.prototype);return e},rp=(r,e,t)=>{r=String(r),(t===void 0||t>r.length)&&(t=r.length),t-=e.length;const i=r.indexOf(e,t);return i!==-1&&i===t},sp=r=>{if(!r)return null;if(bi(r))return r;let e=r.length;if(!ul(e))return null;const t=new Array(e);for(;e-- >0;)t[e]=r[e];return t},np=(r=>e=>r&&e instanceof r)(typeof Uint8Array<"u"&&un(Uint8Array)),ap=(r,e)=>{const i=(r&&r[Symbol.iterator]).call(r);let s;for(;(s=i.next())&&!s.done;){const n=s.value;e.call(r,n[0],n[1])}},op=(r,e)=>{let t;const i=[];for(;(t=r.exec(e))!==null;)i.push(t);return i},lp=wt("HTMLFormElement"),hp=r=>r.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(t,i,s){return i.toUpperCase()+s}),da=(({hasOwnProperty:r})=>(e,t)=>r.call(e,t))(Object.prototype),dp=wt("RegExp"),ml=(r,e)=>{const t=Object.getOwnPropertyDescriptors(r),i={};tr(t,(s,n)=>{e(s,n,r)!==!1&&(i[n]=s)}),Object.defineProperties(r,i)},up=r=>{ml(r,(e,t)=>{if(Rt(r)&&["arguments","caller","callee"].indexOf(t)!==-1)return!1;const i=r[t];if(Rt(i)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+t+"'")})}})},cp=(r,e)=>{const t={},i=s=>{s.forEach(n=>{t[n]=!0})};return bi(r)?i(r):i(String(r).split(e)),t},fp=()=>{},pp=(r,e)=>(r=+r,Number.isFinite(r)?r:e),gs="abcdefghijklmnopqrstuvwxyz",ua="0123456789",gl={DIGIT:ua,ALPHA:gs,ALPHA_DIGIT:gs+gs.toUpperCase()+ua},mp=(r=16,e=gl.ALPHA_DIGIT)=>{let t="";const{length:i}=e;for(;r--;)t+=e[Math.random()*i|0];return t};function gp(r){return!!(r&&Rt(r.append)&&r[Symbol.toStringTag]==="FormData"&&r[Symbol.iterator])}const vp=r=>{const e=new Array(10),t=(i,s)=>{if(fn(i)){if(e.indexOf(i)>=0)return;if(!("toJSON"in i)){e[s]=i;const n=bi(i)?[]:{};return tr(i,(a,o)=>{const h=t(a,s+1);!ji(h)&&(n[o]=h)}),e[s]=void 0,n}}return i};return t(r,0)},S={isArray:bi,isArrayBuffer:dl,isBuffer:$f,isFormData:Yf,isArrayBufferView:Vf,isString:zf,isNumber:ul,isBoolean:Wf,isObject:fn,isPlainObject:Tr,isUndefined:ji,isDate:Uf,isFile:Zf,isBlob:jf,isRegExp:dp,isFunction:Rt,isStream:qf,isURLSearchParams:Kf,isTypedArray:np,isFileList:Xf,forEach:tr,merge:$s,extend:Qf,trim:Jf,stripBOM:ep,inherits:tp,toFlatObject:ip,kindOf:cn,kindOfTest:wt,endsWith:rp,toArray:sp,forEachEntry:ap,matchAll:op,isHTMLForm:lp,hasOwnProperty:da,hasOwnProp:da,reduceDescriptors:ml,freezeMethods:up,toObjectSet:cp,toCamelCase:hp,noop:fp,toFiniteNumber:pp,findKey:cl,global:fl,isContextDefined:pl,ALPHABET:gl,generateString:mp,isSpecCompliantForm:gp,toJSONObject:vp};function ie(r,e,t,i,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=r,this.name="AxiosError",e&&(this.code=e),t&&(this.config=t),i&&(this.request=i),s&&(this.response=s)}S.inherits(ie,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:S.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const vl=ie.prototype,yl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(r=>{yl[r]={value:r}});Object.defineProperties(ie,yl);Object.defineProperty(vl,"isAxiosError",{value:!0});ie.from=(r,e,t,i,s,n)=>{const a=Object.create(vl);return S.toFlatObject(r,a,function(h){return h!==Error.prototype},o=>o!=="isAxiosError"),ie.call(a,r.message,e,t,i,s),a.cause=r,a.name=r.name,n&&Object.assign(a,n),a};const yp=null;function Vs(r){return S.isPlainObject(r)||S.isArray(r)}function bl(r){return S.endsWith(r,"[]")?r.slice(0,-2):r}function ca(r,e,t){return r?r.concat(e).map(function(s,n){return s=bl(s),!t&&n?"["+s+"]":s}).join(t?".":""):e}function bp(r){return S.isArray(r)&&!r.some(Vs)}const _p=S.toFlatObject(S,{},null,function(e){return/^is[A-Z]/.test(e)});function ts(r,e,t){if(!S.isObject(r))throw new TypeError("target must be an object");e=e||new FormData,t=S.toFlatObject(t,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,v){return!S.isUndefined(v[m])});const i=t.metaTokens,s=t.visitor||d,n=t.dots,a=t.indexes,h=(t.Blob||typeof Blob<"u"&&Blob)&&S.isSpecCompliantForm(e);if(!S.isFunction(s))throw new TypeError("visitor must be a function");function l(f){if(f===null)return"";if(S.isDate(f))return f.toISOString();if(!h&&S.isBlob(f))throw new ie("Blob is not supported. Use a Buffer instead.");return S.isArrayBuffer(f)||S.isTypedArray(f)?h&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function d(f,m,v){let _=f;if(f&&!v&&typeof f=="object"){if(S.endsWith(m,"{}"))m=i?m:m.slice(0,-2),f=JSON.stringify(f);else if(S.isArray(f)&&bp(f)||(S.isFileList(f)||S.endsWith(m,"[]"))&&(_=S.toArray(f)))return m=bl(m),_.forEach(function(b,T){!(S.isUndefined(b)||b===null)&&e.append(a===!0?ca([m],T,n):a===null?m:m+"[]",l(b))}),!1}return Vs(f)?!0:(e.append(ca(v,m,n),l(f)),!1)}const u=[],c=Object.assign(_p,{defaultVisitor:d,convertValue:l,isVisitable:Vs});function p(f,m){if(!S.isUndefined(f)){if(u.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));u.push(f),S.forEach(f,function(_,w){(!(S.isUndefined(_)||_===null)&&s.call(e,_,S.isString(w)?w.trim():w,m,c))===!0&&p(_,m?m.concat(w):[w])}),u.pop()}}if(!S.isObject(r))throw new TypeError("data must be an object");return p(r),e}function fa(r){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(r).replace(/[!'()~]|%20|%00/g,function(i){return e[i]})}function pn(r,e){this._pairs=[],r&&ts(r,this,e)}const _l=pn.prototype;_l.append=function(e,t){this._pairs.push([e,t])};_l.toString=function(e){const t=e?function(i){return e.call(this,i,fa)}:fa;return this._pairs.map(function(s){return t(s[0])+"="+t(s[1])},"").join("&")};function wp(r){return encodeURIComponent(r).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function wl(r,e,t){if(!e)return r;const i=t&&t.encode||wp,s=t&&t.serialize;let n;if(s?n=s(e,t):n=S.isURLSearchParams(e)?e.toString():new pn(e,t).toString(i),n){const a=r.indexOf("#");a!==-1&&(r=r.slice(0,a)),r+=(r.indexOf("?")===-1?"?":"&")+n}return r}class Sp{constructor(){this.handlers=[]}use(e,t,i){return this.handlers.push({fulfilled:e,rejected:t,synchronous:i?i.synchronous:!1,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){S.forEach(this.handlers,function(i){i!==null&&e(i)})}}const pa=Sp,Sl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Tp=typeof URLSearchParams<"u"?URLSearchParams:pn,Cp=typeof FormData<"u"?FormData:null,Ep=(()=>{let r;return typeof navigator<"u"&&((r=navigator.product)==="ReactNative"||r==="NativeScript"||r==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),kp=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),tt={isBrowser:!0,classes:{URLSearchParams:Tp,FormData:Cp,Blob},isStandardBrowserEnv:Ep,isStandardBrowserWebWorkerEnv:kp,protocols:["http","https","file","blob","url","data"]};function xp(r,e){return ts(r,new tt.classes.URLSearchParams,Object.assign({visitor:function(t,i,s,n){return tt.isNode&&S.isBuffer(t)?(this.append(i,t.toString("base64")),!1):n.defaultVisitor.apply(this,arguments)}},e))}function Pp(r){return S.matchAll(/\w+|\[(\w*)]/g,r).map(e=>e[0]==="[]"?"":e[1]||e[0])}function Ap(r){const e={},t=Object.keys(r);let i;const s=t.length;let n;for(i=0;i<s;i++)n=t[i],e[n]=r[n];return e}function Tl(r){function e(t,i,s,n){let a=t[n++];const o=Number.isFinite(+a),h=n>=t.length;return a=!a&&S.isArray(s)?s.length:a,h?(S.hasOwnProp(s,a)?s[a]=[s[a],i]:s[a]=i,!o):((!s[a]||!S.isObject(s[a]))&&(s[a]=[]),e(t,i,s[a],n)&&S.isArray(s[a])&&(s[a]=Ap(s[a])),!o)}if(S.isFormData(r)&&S.isFunction(r.entries)){const t={};return S.forEachEntry(r,(i,s)=>{e(Pp(i),s,t,0)}),t}return null}const Op={"Content-Type":void 0};function Mp(r,e,t){if(S.isString(r))try{return(e||JSON.parse)(r),S.trim(r)}catch(i){if(i.name!=="SyntaxError")throw i}return(t||JSON.stringify)(r)}const is={transitional:Sl,adapter:["xhr","http"],transformRequest:[function(e,t){const i=t.getContentType()||"",s=i.indexOf("application/json")>-1,n=S.isObject(e);if(n&&S.isHTMLForm(e)&&(e=new FormData(e)),S.isFormData(e))return s&&s?JSON.stringify(Tl(e)):e;if(S.isArrayBuffer(e)||S.isBuffer(e)||S.isStream(e)||S.isFile(e)||S.isBlob(e))return e;if(S.isArrayBufferView(e))return e.buffer;if(S.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let o;if(n){if(i.indexOf("application/x-www-form-urlencoded")>-1)return xp(e,this.formSerializer).toString();if((o=S.isFileList(e))||i.indexOf("multipart/form-data")>-1){const h=this.env&&this.env.FormData;return ts(o?{"files[]":e}:e,h&&new h,this.formSerializer)}}return n||s?(t.setContentType("application/json",!1),Mp(e)):e}],transformResponse:[function(e){const t=this.transitional||is.transitional,i=t&&t.forcedJSONParsing,s=this.responseType==="json";if(e&&S.isString(e)&&(i&&!this.responseType||s)){const a=!(t&&t.silentJSONParsing)&&s;try{return JSON.parse(e)}catch(o){if(a)throw o.name==="SyntaxError"?ie.from(o,ie.ERR_BAD_RESPONSE,this,null,this.response):o}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:tt.classes.FormData,Blob:tt.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};S.forEach(["delete","get","head"],function(e){is.headers[e]={}});S.forEach(["post","put","patch"],function(e){is.headers[e]=S.merge(Op)});const mn=is,Lp=S.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Rp=r=>{const e={};let t,i,s;return r&&r.split(`
11
11
  `).forEach(function(a){s=a.indexOf(":"),t=a.substring(0,s).trim().toLowerCase(),i=a.substring(s+1).trim(),!(!t||e[t]&&Lp[t])&&(t==="set-cookie"?e[t]?e[t].push(i):e[t]=[i]:e[t]=e[t]?e[t]+", "+i:i)}),e},ma=Symbol("internals");function Ci(r){return r&&String(r).trim().toLowerCase()}function Cr(r){return r===!1||r==null?r:S.isArray(r)?r.map(Cr):String(r)}function Ip(r){const e=Object.create(null),t=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let i;for(;i=t.exec(r);)e[i[1]]=i[2];return e}function Np(r){return/^[-_a-zA-Z]+$/.test(r.trim())}function vs(r,e,t,i,s){if(S.isFunction(i))return i.call(this,e,t);if(s&&(e=t),!!S.isString(e)){if(S.isString(i))return e.indexOf(i)!==-1;if(S.isRegExp(i))return i.test(e)}}function Gp(r){return r.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,t,i)=>t.toUpperCase()+i)}function Dp(r,e){const t=S.toCamelCase(" "+e);["get","set","has"].forEach(i=>{Object.defineProperty(r,i+t,{value:function(s,n,a){return this[i].call(this,e,s,n,a)},configurable:!0})})}class rs{constructor(e){e&&this.set(e)}set(e,t,i){const s=this;function n(o,h,l){const d=Ci(h);if(!d)throw new Error("header name must be a non-empty string");const u=S.findKey(s,d);(!u||s[u]===void 0||l===!0||l===void 0&&s[u]!==!1)&&(s[u||h]=Cr(o))}const a=(o,h)=>S.forEach(o,(l,d)=>n(l,d,h));return S.isPlainObject(e)||e instanceof this.constructor?a(e,t):S.isString(e)&&(e=e.trim())&&!Np(e)?a(Rp(e),t):e!=null&&n(t,e,i),this}get(e,t){if(e=Ci(e),e){const i=S.findKey(this,e);if(i){const s=this[i];if(!t)return s;if(t===!0)return Ip(s);if(S.isFunction(t))return t.call(this,s,i);if(S.isRegExp(t))return t.exec(s);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=Ci(e),e){const i=S.findKey(this,e);return!!(i&&this[i]!==void 0&&(!t||vs(this,this[i],i,t)))}return!1}delete(e,t){const i=this;let s=!1;function n(a){if(a=Ci(a),a){const o=S.findKey(i,a);o&&(!t||vs(i,i[o],o,t))&&(delete i[o],s=!0)}}return S.isArray(e)?e.forEach(n):n(e),s}clear(e){const t=Object.keys(this);let i=t.length,s=!1;for(;i--;){const n=t[i];(!e||vs(this,this[n],n,e,!0))&&(delete this[n],s=!0)}return s}normalize(e){const t=this,i={};return S.forEach(this,(s,n)=>{const a=S.findKey(i,n);if(a){t[a]=Cr(s),delete t[n];return}const o=e?Gp(n):String(n).trim();o!==n&&delete t[n],t[o]=Cr(s),i[o]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return S.forEach(this,(i,s)=>{i!=null&&i!==!1&&(t[s]=e&&S.isArray(i)?i.join(", "):i)}),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,t])=>e+": "+t).join(`
12
12
  `)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const i=new this(e);return t.forEach(s=>i.set(s)),i}static accessor(e){const i=(this[ma]=this[ma]={accessors:{}}).accessors,s=this.prototype;function n(a){const o=Ci(a);i[o]||(Dp(s,a),i[o]=!0)}return S.isArray(e)?e.forEach(n):n(e),this}}rs.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);S.freezeMethods(rs.prototype);S.freezeMethods(rs);const pt=rs;function ys(r,e){const t=this||mn,i=e||t,s=pt.from(i.headers);let n=i.data;return S.forEach(r,function(o){n=o.call(t,n,s.normalize(),e?e.status:void 0)}),s.normalize(),n}function Cl(r){return!!(r&&r.__CANCEL__)}function ir(r,e,t){ie.call(this,r??"canceled",ie.ERR_CANCELED,e,t),this.name="CanceledError"}S.inherits(ir,ie,{__CANCEL__:!0});function Fp(r,e,t){const i=t.config.validateStatus;!t.status||!i||i(t.status)?r(t):e(new ie("Request failed with status code "+t.status,[ie.ERR_BAD_REQUEST,ie.ERR_BAD_RESPONSE][Math.floor(t.status/100)-4],t.config,t.request,t))}const Hp=tt.isStandardBrowserEnv?function(){return{write:function(t,i,s,n,a,o){const h=[];h.push(t+"="+encodeURIComponent(i)),S.isNumber(s)&&h.push("expires="+new Date(s).toGMTString()),S.isString(n)&&h.push("path="+n),S.isString(a)&&h.push("domain="+a),o===!0&&h.push("secure"),document.cookie=h.join("; ")},read:function(t){const i=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return i?decodeURIComponent(i[3]):null},remove:function(t){this.write(t,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}();function Bp(r){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(r)}function $p(r,e){return e?r.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):r}function El(r,e){return r&&!Bp(e)?$p(r,e):e}const Vp=tt.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let i;function s(n){let a=n;return e&&(t.setAttribute("href",a),a=t.href),t.setAttribute("href",a),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:t.pathname.charAt(0)==="/"?t.pathname:"/"+t.pathname}}return i=s(window.location.href),function(a){const o=S.isString(a)?s(a):a;return o.protocol===i.protocol&&o.host===i.host}}():function(){return function(){return!0}}();function zp(r){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(r);return e&&e[1]||""}function Wp(r,e){r=r||10;const t=new Array(r),i=new Array(r);let s=0,n=0,a;return e=e!==void 0?e:1e3,function(h){const l=Date.now(),d=i[n];a||(a=l),t[s]=h,i[s]=l;let u=n,c=0;for(;u!==s;)c+=t[u++],u=u%r;if(s=(s+1)%r,s===n&&(n=(n+1)%r),l-a<e)return;const p=d&&l-d;return p?Math.round(c*1e3/p):void 0}}function ga(r,e){let t=0;const i=Wp(50,250);return s=>{const n=s.loaded,a=s.lengthComputable?s.total:void 0,o=n-t,h=i(o),l=n<=a;t=n;const d={loaded:n,total:a,progress:a?n/a:void 0,bytes:o,rate:h||void 0,estimated:h&&a&&l?(a-n)/h:void 0,event:s};d[e?"download":"upload"]=!0,r(d)}}const Up=typeof XMLHttpRequest<"u",Zp=Up&&function(r){return new Promise(function(t,i){let s=r.data;const n=pt.from(r.headers).normalize(),a=r.responseType;let o;function h(){r.cancelToken&&r.cancelToken.unsubscribe(o),r.signal&&r.signal.removeEventListener("abort",o)}S.isFormData(s)&&(tt.isStandardBrowserEnv||tt.isStandardBrowserWebWorkerEnv)&&n.setContentType(!1);let l=new XMLHttpRequest;if(r.auth){const p=r.auth.username||"",f=r.auth.password?unescape(encodeURIComponent(r.auth.password)):"";n.set("Authorization","Basic "+btoa(p+":"+f))}const d=El(r.baseURL,r.url);l.open(r.method.toUpperCase(),wl(d,r.params,r.paramsSerializer),!0),l.timeout=r.timeout;function u(){if(!l)return;const p=pt.from("getAllResponseHeaders"in l&&l.getAllResponseHeaders()),m={data:!a||a==="text"||a==="json"?l.responseText:l.response,status:l.status,statusText:l.statusText,headers:p,config:r,request:l};Fp(function(_){t(_),h()},function(_){i(_),h()},m),l=null}if("onloadend"in l?l.onloadend=u:l.onreadystatechange=function(){!l||l.readyState!==4||l.status===0&&!(l.responseURL&&l.responseURL.indexOf("file:")===0)||setTimeout(u)},l.onabort=function(){l&&(i(new ie("Request aborted",ie.ECONNABORTED,r,l)),l=null)},l.onerror=function(){i(new ie("Network Error",ie.ERR_NETWORK,r,l)),l=null},l.ontimeout=function(){let f=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const m=r.transitional||Sl;r.timeoutErrorMessage&&(f=r.timeoutErrorMessage),i(new ie(f,m.clarifyTimeoutError?ie.ETIMEDOUT:ie.ECONNABORTED,r,l)),l=null},tt.isStandardBrowserEnv){const p=(r.withCredentials||Vp(d))&&r.xsrfCookieName&&Hp.read(r.xsrfCookieName);p&&n.set(r.xsrfHeaderName,p)}s===void 0&&n.setContentType(null),"setRequestHeader"in l&&S.forEach(n.toJSON(),function(f,m){l.setRequestHeader(m,f)}),S.isUndefined(r.withCredentials)||(l.withCredentials=!!r.withCredentials),a&&a!=="json"&&(l.responseType=r.responseType),typeof r.onDownloadProgress=="function"&&l.addEventListener("progress",ga(r.onDownloadProgress,!0)),typeof r.onUploadProgress=="function"&&l.upload&&l.upload.addEventListener("progress",ga(r.onUploadProgress)),(r.cancelToken||r.signal)&&(o=p=>{l&&(i(!p||p.type?new ir(null,r,l):p),l.abort(),l=null)},r.cancelToken&&r.cancelToken.subscribe(o),r.signal&&(r.signal.aborted?o():r.signal.addEventListener("abort",o)));const c=zp(d);if(c&&tt.protocols.indexOf(c)===-1){i(new ie("Unsupported protocol "+c+":",ie.ERR_BAD_REQUEST,r));return}l.send(s||null)})},Er={http:yp,xhr:Zp};S.forEach(Er,(r,e)=>{if(r){try{Object.defineProperty(r,"name",{value:e})}catch{}Object.defineProperty(r,"adapterName",{value:e})}});const jp={getAdapter:r=>{r=S.isArray(r)?r:[r];const{length:e}=r;let t,i;for(let s=0;s<e&&(t=r[s],!(i=S.isString(t)?Er[t.toLowerCase()]:t));s++);if(!i)throw i===!1?new ie(`Adapter ${t} is not supported by the environment`,"ERR_NOT_SUPPORT"):new Error(S.hasOwnProp(Er,t)?`Adapter '${t}' is not available in the build`:`Unknown adapter '${t}'`);if(!S.isFunction(i))throw new TypeError("adapter is not a function");return i},adapters:Er};function bs(r){if(r.cancelToken&&r.cancelToken.throwIfRequested(),r.signal&&r.signal.aborted)throw new ir(null,r)}function va(r){return bs(r),r.headers=pt.from(r.headers),r.data=ys.call(r,r.transformRequest),["post","put","patch"].indexOf(r.method)!==-1&&r.headers.setContentType("application/x-www-form-urlencoded",!1),jp.getAdapter(r.adapter||mn.adapter)(r).then(function(i){return bs(r),i.data=ys.call(r,r.transformResponse,i),i.headers=pt.from(i.headers),i},function(i){return Cl(i)||(bs(r),i&&i.response&&(i.response.data=ys.call(r,r.transformResponse,i.response),i.response.headers=pt.from(i.response.headers))),Promise.reject(i)})}const ya=r=>r instanceof pt?r.toJSON():r;function fi(r,e){e=e||{};const t={};function i(l,d,u){return S.isPlainObject(l)&&S.isPlainObject(d)?S.merge.call({caseless:u},l,d):S.isPlainObject(d)?S.merge({},d):S.isArray(d)?d.slice():d}function s(l,d,u){if(S.isUndefined(d)){if(!S.isUndefined(l))return i(void 0,l,u)}else return i(l,d,u)}function n(l,d){if(!S.isUndefined(d))return i(void 0,d)}function a(l,d){if(S.isUndefined(d)){if(!S.isUndefined(l))return i(void 0,l)}else return i(void 0,d)}function o(l,d,u){if(u in e)return i(l,d);if(u in r)return i(void 0,l)}const h={url:n,method:n,data:n,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:o,headers:(l,d)=>s(ya(l),ya(d),!0)};return S.forEach(Object.keys(r).concat(Object.keys(e)),function(d){const u=h[d]||s,c=u(r[d],e[d],d);S.isUndefined(c)&&u!==o||(t[d]=c)}),t}const kl="1.3.3",gn={};["object","boolean","number","function","string","symbol"].forEach((r,e)=>{gn[r]=function(i){return typeof i===r||"a"+(e<1?"n ":" ")+r}});const ba={};gn.transitional=function(e,t,i){function s(n,a){return"[Axios v"+kl+"] Transitional option '"+n+"'"+a+(i?". "+i:"")}return(n,a,o)=>{if(e===!1)throw new ie(s(a," has been removed"+(t?" in "+t:"")),ie.ERR_DEPRECATED);return t&&!ba[a]&&(ba[a]=!0,console.warn(s(a," has been deprecated since v"+t+" and will be removed in the near future"))),e?e(n,a,o):!0}};function Xp(r,e,t){if(typeof r!="object")throw new ie("options must be an object",ie.ERR_BAD_OPTION_VALUE);const i=Object.keys(r);let s=i.length;for(;s-- >0;){const n=i[s],a=e[n];if(a){const o=r[n],h=o===void 0||a(o,n,r);if(h!==!0)throw new ie("option "+n+" must be "+h,ie.ERR_BAD_OPTION_VALUE);continue}if(t!==!0)throw new ie("Unknown option "+n,ie.ERR_BAD_OPTION)}}const zs={assertOptions:Xp,validators:gn},Ct=zs.validators;class Wr{constructor(e){this.defaults=e,this.interceptors={request:new pa,response:new pa}}request(e,t){typeof e=="string"?(t=t||{},t.url=e):t=e||{},t=fi(this.defaults,t);const{transitional:i,paramsSerializer:s,headers:n}=t;i!==void 0&&zs.assertOptions(i,{silentJSONParsing:Ct.transitional(Ct.boolean),forcedJSONParsing:Ct.transitional(Ct.boolean),clarifyTimeoutError:Ct.transitional(Ct.boolean)},!1),s!==void 0&&zs.assertOptions(s,{encode:Ct.function,serialize:Ct.function},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let a;a=n&&S.merge(n.common,n[t.method]),a&&S.forEach(["delete","get","head","post","put","patch","common"],f=>{delete n[f]}),t.headers=pt.concat(a,n);const o=[];let h=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(t)===!1||(h=h&&m.synchronous,o.unshift(m.fulfilled,m.rejected))});const l=[];this.interceptors.response.forEach(function(m){l.push(m.fulfilled,m.rejected)});let d,u=0,c;if(!h){const f=[va.bind(this),void 0];for(f.unshift.apply(f,o),f.push.apply(f,l),c=f.length,d=Promise.resolve(t);u<c;)d=d.then(f[u++],f[u++]);return d}c=o.length;let p=t;for(u=0;u<c;){const f=o[u++],m=o[u++];try{p=f(p)}catch(v){m.call(this,v);break}}try{d=va.call(this,p)}catch(f){return Promise.reject(f)}for(u=0,c=l.length;u<c;)d=d.then(l[u++],l[u++]);return d}getUri(e){e=fi(this.defaults,e);const t=El(e.baseURL,e.url);return wl(t,e.params,e.paramsSerializer)}}S.forEach(["delete","get","head","options"],function(e){Wr.prototype[e]=function(t,i){return this.request(fi(i||{},{method:e,url:t,data:(i||{}).data}))}});S.forEach(["post","put","patch"],function(e){function t(i){return function(n,a,o){return this.request(fi(o||{},{method:e,headers:i?{"Content-Type":"multipart/form-data"}:{},url:n,data:a}))}}Wr.prototype[e]=t(),Wr.prototype[e+"Form"]=t(!0)});const kr=Wr;class vn{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let t;this.promise=new Promise(function(n){t=n});const i=this;this.promise.then(s=>{if(!i._listeners)return;let n=i._listeners.length;for(;n-- >0;)i._listeners[n](s);i._listeners=null}),this.promise.then=s=>{let n;const a=new Promise(o=>{i.subscribe(o),n=o}).then(s);return a.cancel=function(){i.unsubscribe(n)},a},e(function(n,a,o){i.reason||(i.reason=new ir(n,a,o),t(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);t!==-1&&this._listeners.splice(t,1)}static source(){let e;return{token:new vn(function(s){e=s}),cancel:e}}}const qp=vn;function Yp(r){return function(t){return r.apply(null,t)}}function Kp(r){return S.isObject(r)&&r.isAxiosError===!0}const Ws={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ws).forEach(([r,e])=>{Ws[e]=r});const Jp=Ws;function xl(r){const e=new kr(r),t=ll(kr.prototype.request,e);return S.extend(t,kr.prototype,e,{allOwnKeys:!0}),S.extend(t,e,null,{allOwnKeys:!0}),t.create=function(s){return xl(fi(r,s))},t}const Te=xl(mn);Te.Axios=kr;Te.CanceledError=ir;Te.CancelToken=qp;Te.isCancel=Cl;Te.VERSION=kl;Te.toFormData=ts;Te.AxiosError=ie;Te.Cancel=Te.CanceledError;Te.all=function(e){return Promise.all(e)};Te.spread=Yp;Te.isAxiosError=Kp;Te.mergeConfig=fi;Te.AxiosHeaders=pt;Te.formToJSON=r=>Tl(S.isHTMLForm(r)?new FormData(r):r);Te.HttpStatusCode=Jp;Te.default=Te;const _a=Te;function Qp(r,e){return e!=null?_a.get(r,e):_a.get(r)}function He(r,e){this.message=r,this.error=e}He.prototype=Object.create(Error.prototype);const yn=/([0-9]+)?:?([0-9]{2}):([0-9]{2}\.[0-9]{2,3})/;function em(r,e){e||(e={});const{meta:t=!1,strict:i=!0}=e;if(typeof r!="string")throw new He("Input must be a string");r=r.trim(),r=r.replace(/\r\n/g,`
13
13
  `),r=r.replace(/\r/g,`
@@ -44,7 +44,7 @@ ${Ll(i)}`)}),e.join(`
44
44
  `)}function ym(r){let e=0;return r.forEach(t=>{t.duration>e&&(e=t.duration)}),e}function bm(r){const e=[];return r.forEach(t=>{e.push(_m(t))}),e.join(`
45
45
 
46
46
  `)}function _m(r){const e=[];r.identifier&&e.push(r.identifier);const t=Ca(r.start),i=Ca(r.end),s=r.styles?`${r.styles}`:"";return e.push(`${t} --> ${i} ${s}`),e.push(r.text),e.join(`
47
- `)}function Ca(r){const e=(r%1).toFixed(3);r=Math.round(r-e);const t=Math.floor(r/3600),i=Math.floor((r-t*3600)/60),s=r-t*3600-i*60;return`${`${gr(t,2)}:`}${gr(i,2)}:${gr(s,2)}.${gr(e*1e3,3)}`}var wm={hlsSegment:mm,hlsSegmentPlaylist:gm};const Sm=Pl.parse,Tm=dm.compile,Cm=Ol.segment,Em=wm;var km={parse:Sm,compile:Tm,segment:Cm,hls:Em};class bn{constructor(e,t){this.cues=new Map,this.cuesKeysSorted=[],this.url=e,this.axiosConfig=t}fetch(){return Ki(Qp(this.getUrl(),this.axiosConfig)).pipe(ke(e=>{let t=e.data;try{return km.parse(t,{strict:!0,meta:!0}).cues.forEach(s=>{let n=this.mapCue(s);this.cues.set(n.startTime,n),this.cuesKeysSorted.push(n.startTime)}),this.cuesKeysSorted.sort((s,n)=>s-n),!0}catch(i){return console.error(i),!1}}))}getUrl(){return this.url}hasCues(){return this.cues&&this.cues.size>0}findCue(e){let t=this.findCues(e,e);if(t&&t.length===1)return t[0]}findCues(e,t){let i=this.findCueIndex(e),s=this.findCueIndex(t);return s===-1?[]:this.cuesKeysSorted.slice(i,s+1).map(n=>this.cues.get(n))}getCues(){return[...this.cues.values()]}findCueIndex(e){let t=0,i=this.cuesKeysSorted.length-1;for(;t<=i;){const s=Math.floor((t+i)/2);if(this.cuesKeysSorted[s]===e)return s;this.cuesKeysSorted[s]<e?t=s+1:i=s-1}return i===-1&&(i=0),i}}class _n extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new _n(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text}}}const Ea={listening:!0,style:{height:20,fill:"rgba(255,73,145)",opacity:1,visible:!0}};class xm extends Je{constructor(e,t){super({...Ea,...e,style:{...Ea.style,...e.style}}),this.textTrackCue=this.config.textTrackCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening,this.subtitlesLane=t,this.subtitlesLane.onSettleLayout$.pipe(k(this.onDestroy$)).subscribe(()=>{let i=this.subtitlesLane.resolveItemHorizontalMeasurement(this.getTextTrackCue());this.setHorizontalMeasurement(i)})}createCanvasNode(){return this.group=new O.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new O.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),fill:this.style.fill,opacity:this.style.opacity,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.backgroundRect),this.group}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getHorizontalMeasurement(){return{x:this.x,width:this.width}}setHorizontalMeasurement(e){this.x=e.x,this.width=e.width,this.isInitialized()&&this.group.setAttrs({x:this.x,width:this.width}),this.onMeasurementsChange()}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}getTextTrackCue(){return this.textTrackCue}setTextTrackCue(e){this.textTrackCue=e}compareTo(e){return this.textTrackCue&&e&&this.getTextTrackCue().id===e.getTextTrackCue().id&&this.getTextTrackCue().startTime===e.getTextTrackCue().startTime&&this.getTextTrackCue().endTime===e.getTextTrackCue().endTime?0:-1}}const Pm={...Qi,height:40,paddingTop:0,paddingBottom:0,subtitlesLaneItemOpacity:.9,subtitlesLaneItemFill:"rgba(255,73,145)"};class Us extends er{constructor(e){super({...e,style:{...Pm,...e.style}}),this.subtitlesLaneItemsMap=new Map,this.onSettleLayout$=new V,this._subtitlesVttUrl=this.config.subtitlesVttUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.subtitlesLaneItemsGroup=new O.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.subtitlesLaneItemsGroup),this.timeline.addToTimecodedSubtitlesGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.subtitlesLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateSubtitles()}clearContent(){this.subtitlesVttFile=void 0,this.clearItems()}clearItems(){this.subtitlesLaneItemsMap.forEach(e=>e.destroy()),this.subtitlesLaneItemsMap.clear(),this.subtitlesLaneItemsGroup.destroyChildren()}createEntities(){if(!this.isVttLoaded())return;this.clearItems(),this.subtitlesVttFile.getCues().forEach(t=>{let i=this.resolveItemHorizontalMeasurement(t),s=new xm({...i,textTrackCue:t,style:{height:this.subtitlesLaneItemsGroup.height(),fill:this.style.subtitlesLaneItemFill,opacity:this.style.subtitlesLaneItemOpacity}},this);this.subtitlesLaneItemsMap.set(t.startTime,s),this.subtitlesLaneItemsGroup.add(s.initCanvasNode())})}resolveItemHorizontalMeasurement(e){let t=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.startTime)),i=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.endTime));return{x:t,width:i-t}}fetchAndCreateSubtitles(){this.fetchSubtitlesVttFile(this._subtitlesVttUrl).pipe(ct(1)).subscribe(e=>{this.subtitlesVttFile=e,this.createEntities()})}fetchSubtitlesVttFile(e){return e?_n.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.subtitlesVttFile}get subtitlesVttUrl(){return this._subtitlesVttUrl}set subtitlesVttUrl(e){this._subtitlesVttUrl=e,this.clearContent(),this.fetchAndCreateSubtitles()}}const Am={listening:!1,style:{...F.POSITION_TOP_LEFT,...F.DIMENSION_ZERO,stroke:"rgba(255,73,145)",strokeWidth:5,visible:!1}};class Zs extends Je{constructor(e){super(vi(e,Am)),this.onClick$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.listening=this.config.listening}createCanvasNode(){return this.group=new O.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new O.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),strokeWidth:this.style.strokeWidth,stroke:this.style.stroke}),this.group.add(this.backgroundRect),this.group}afterCanvasNodeInit(){this.group.on("click",e=>{this.onClick$.next({thumbnail:this})}),this.group.on("mouseover",e=>{this.onMouseOver$.next({thumbnail:this})}),this.group.on("mousemove",e=>{this.onMouseMove$.next({thumbnail:this})}),this.group.on("mouseout",e=>{this.onMouseOut$.next({thumbnail:this})}),this.group.on("mouseleave",e=>{this.onMouseLeave$.next({thumbnail:this})})}destroy(){super.destroy()}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setImage(e){this.image&&this.image.destroy(),this.image=e,this.style={width:e.width(),height:e.height()},this.group.setAttrs({...this.image.getSize()}),this.backgroundRect.setAttrs({...this.image.getSize()}),this.group.add(this.image)}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.isInitialized()&&this.group.position(e)}setVisibleAndX(e,t){this.style={visible:e,x:t},this.isInitialized()&&this.group.setAttrs({visible:e,x:t})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}setDimension(e){this.style={...e},this.isInitialized()&&this.group.size(e),this.onMeasurementsChange()}getRect(){return{...this.getPosition(),...this.getDimension()}}getThumbnailVttCue(){return this.thumbnailVttCue}setThumbnailVttCue(e){this.thumbnailVttCue=e}getImage(){return this.image}compareTo(e){return this.thumbnailVttCue&&e&&this.thumbnailVttCue.url===e.thumbnailVttCue.url?0:-1}}class ss extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new ss(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,url:this.resolveThumbnailUrl(e)}}resolveThumbnailUrl(e){return this.isUrlAbsolute(e.text)?e.text:this.createThumbnailUrlFromRelativeUrl(e.text)}createThumbnailUrlFromRelativeUrl(e){return this.url.lastIndexOf("/")>2?`${this.url.substring(0,this.url.lastIndexOf("/"))}/${e}`:e}isUrlAbsolute(e){return/^(http(s):\/\/.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(e)}}class dt{static createKonvaImage(e){return new se(t=>{O.Image.fromURL(e,i=>{t.next(i),t.complete()},i=>{console.error(i),t.error(i)})})}static createKonvaImageSizedByWidth(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:t,height:dt.calculateProportionalHeight(t,i)}),i)))}static createKonvaImageSizedByHeight(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:dt.calculateProportionalWidth(t,i),height:t}),i)))}static calculateProportionalHeight(e,t){return e*t.getAttrs().image.naturalHeight/t.getAttrs().image.naturalWidth}static calculateProportionalWidth(e,t){return e*t.getAttrs().image.naturalWidth/t.getAttrs().image.naturalHeight}}const Om={...Qi,thumbnailHeight:40,thumbnailStroke:"rgba(121,0,255,0.9)",thumbnailStrokeWidth:0,thumbnailHoverScale:1.5,thumbnailHoverStroke:"rgba(0,255,188,0.9)",thumbnailHoverStrokeWidth:5};class js extends er{constructor(e){super({...e,style:{...Om,...e.style}}),this.thumbnailsMap=new Map,this.thumbnailsVisibleSet=new Set,this.onSettleLayout$=new V,this.eventStreamBreaker$=new V,this.onClick$=new V,this._thumbnailVttUrl=this.config.thumbnailVttUrl,this._axiosConfig=this.config.axiosConfig}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.thumbnailsGroup=new O.Group({x:0,y:this.style.height/2-this.style.thumbnailHeight/2,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.thumbnailsGroup),this.timeline.addToTimecodedThumbnailsGroup(this.timecodedGroup),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.timeline.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.thumbnailsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateThumbnails(),this.onSettleLayout$.pipe(k(this.onDestroy$)).subscribe(()=>{this.hideThumbnailHover(),this.adjustThumbnails()}),this.onSettleLayout$.pipe(k(this.onDestroy$)).pipe(Io(100)).subscribe(()=>{this.createAndAdjustThumbnails()}),this.timecodedGroup.on("mouseout mouseleave",e=>{this.hideThumbnailHover()})}onMeasurementsChange(){super.onMeasurementsChange(),this.hideThumbnailHover(),this.createAndAdjustThumbnails()}destroy(){super.destroy(),this.timecodedGroup.destroy(),this.thumbnailHover.destroy(),this.fireEventStreamBreaker()}clearContent(){this.fireEventStreamBreaker(),this.thumbnailVttFile=void 0,this.clearItems()}clearItems(){this.thumbnailsMap.forEach(e=>e.destroy()),this.thumbnailsMap.clear(),this.thumbnailsVisibleSet.clear(),this.thumbnailsGroup.destroyChildren()}fireEventStreamBreaker(){this.eventStreamBreaker$&&(this.eventStreamBreaker$.next(),this.eventStreamBreaker$.complete()),this.eventStreamBreaker$=new V}createAndAdjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailVttFile.getCues().forEach(e=>{let t=this.timeline.timeToTimelinePosition(e.startTime),i=this.thumbnailsVisibleSet.has(e.startTime);if(this.timeline.constrainTimelinePosition(t)===t)if(this.thumbnailsMap.has(e.startTime)){let s=this.thumbnailsMap.get(e.startTime);s&&s.setVisibleAndX(i,t)}else i&&(this.thumbnailsMap.set(e.startTime,null),dt.createKonvaImageSizedByHeight(e.url,this.style.thumbnailHeight).subscribe(s=>{let n=this.thumbnailsVisibleSet.has(e.startTime),a=this.createThumbnail(e,s,n);this.thumbnailsMap.set(e.startTime,a),this.thumbnailsGroup.add(a.getCanvasNode())}))}))}adjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailsMap.forEach(e=>{if(e){let t=this.timeline.timeToTimelinePosition(e.getThumbnailVttCue().startTime),i=this.thumbnailsVisibleSet.has(e.getThumbnailVttCue().startTime);e.setVisibleAndX(i,t)}}))}resolveVisibleTimestamps(){let e;this.thumbnailVttFile.getCues().forEach(i=>{let s=this.timeline.timeToTimelinePosition(i.startTime);this.timeline.constrainTimelinePosition(s)===s&&((e?s>=e:!0)?(e=s+this.thumbnailWidth,this.thumbnailsVisibleSet.add(i.startTime)):this.thumbnailsVisibleSet.delete(i.startTime))})}createThumbnail(e,t,i){let s=this.timeline.timeToTimelinePosition(e.startTime),n=new Zs({listening:!0,style:{x:s,y:0,visible:i,stroke:this.style.thumbnailStroke,strokeWidth:this.style.thumbnailStrokeWidth}});return n.setThumbnailVttCue(e),n.initCanvasNode(),n.setImage(t),n.onClick$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.onClick$.next(a)}),n.onMouseOver$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseMove$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseOut$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n.onMouseLeave$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n}showThumbnailHover(e){if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.compareTo(e)===0){let t=this.resolveThumbnailHoverPosition(e);this.thumbnailHover.setPosition(t),this.thumbnailHover.setVisible(!0)}else dt.createKonvaImageSizedByWidth(e.getThumbnailVttCue().url,e.getImage().width()*this.style.thumbnailHoverScale).subscribe(t=>{this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailHoverPosition(e)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.style.visible&&this.thumbnailHover.setVisible(!1)}resolveThumbnailHoverPosition(e){let t=this.timeline.getTimecodedGroupRect(),i=this.thumbnailHover.getImage().getSize(),s=e.getPosition().x+e.getDimension().width/2-i.width/2,n=e.style.strokeWidth>0?e.style.strokeWidth/2:0;s=s-n<0?n:s+i.width+n>t.width?t.width-i.width-n:s;let h=this.getRect().y+this.thumbnailsGroup.y()+e.getDimension().height/2-this.thumbnailHover.getDimension().height/2;return{x:s,y:h}}fetchAndCreateThumbnails(){this.fetchThumbnailVttFile(this._thumbnailVttUrl,this._axiosConfig,this.style.thumbnailHeight).pipe(ct(1)).subscribe(e=>{e&&(this.thumbnailVttFile=e.thumbnailVttFile,this.thumbnailWidth=e.thumbnailWidth,this.createAndAdjustThumbnails())})}fetchThumbnailVttFile(e,t,i){return e?ss.create(e,t).pipe(Yu(s=>{let n=s.getCues()[0];return dt.createKonvaImageSizedByHeight(n.url,i).pipe(ke(a=>{let o=a.getSize().width;return{thumbnailVttFile:s,thumbnailWidth:o}}))}),gi((s,n)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.thumbnailVttFile&&!!this.thumbnailWidth}getThumbnailVttFile(){return this.thumbnailVttFile}get thumbnailVttUrl(){return this._thumbnailVttUrl}set thumbnailVttUrl(e){this._thumbnailVttUrl=e,this.clearContent(),this.fetchAndCreateThumbnails()}}class wn extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new wn(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){let t=e.text.split(","),i=_e.coerce.number().min(-1).max(0).parse(t[0]),s=_e.coerce.number().min(0).max(1).parse(t[1]);return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,minSample:i,maxSample:s}}}const ka={listening:!1,style:{height:20,cornerRadius:20,opacity:1,visible:!0,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]}};class Mm extends Je{constructor(e){super({...ka,...e,style:{...ka.style,...e.style}}),this.audioVttCue=this.config.audioVttCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening}createCanvasNode(){this.group=new O.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening});let e=this.style.height/2,t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();return this.maxSampleBar=new O.Rect({x:0,width:this.group.width(),y:e-t,height:t,opacity:this.style.opacity,cornerRadius:[this.style.cornerRadius,this.style.cornerRadius,0,0],fillLinearGradientStartPoint:{x:0,y:-(e-t)},fillLinearGradientEndPoint:{x:0,y:t},fillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.minSampleBar=new O.Rect({x:0,width:this.group.width(),y:e,height:i,opacity:this.style.opacity,cornerRadius:[0,0,this.style.cornerRadius,this.style.cornerRadius],fillLinearGradientStartPoint:{x:0,y:0},fillLinearGradientEndPoint:{x:0,y:e},fillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.maxSampleBar),this.group.add(this.minSampleBar),this.group}resolveMaxSampleBarHeight(){return new Z(this.audioVttCue.maxSample).mul(this.style.height/2).toDecimalPlaces(2).toNumber()}resolveMinSampleBarHeight(){return new Z(this.audioVttCue.minSample).abs().mul(this.style.height/2).toDecimalPlaces(2).toNumber()}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getAudioVttCue(){return this.audioVttCue}setAudioVttCue(e){this.audioVttCue=e;let t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();this.minSampleBar.setAttrs({height:i}),this.maxSampleBar.setAttrs({y:this.style.height/2-t,height:t,fillLinearGradientStartPoint:{x:0,y:-(this.style.height/2-t)},fillLinearGradientEndPoint:{x:0,y:t}})}}const Lm={...Qi,height:40,paddingTop:0,paddingBottom:0,itemWidth:5,itemMinPadding:2,itemCornerRadius:5,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]};class Rl extends er{constructor(e){super({...e,style:{...Lm,...e.style}}),this.audioTrackLaneItemsMap=new Map,this.onSettleLayout$=new V,this._audioVttFileUrl=this.config.audioVttFileUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.audioTrackLaneItemsGroup=new O.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.audioTrackLaneItemsGroup),this.timeline.addToTimecodedAudioGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.audioTrackLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateAudioTrack(),this.onSettleLayout$.pipe(k(this.onDestroy$)).subscribe(()=>{this.settlePosition()}),Ou([this.onSettleLayout$,this.timeline.onScroll$]).pipe(k(this.onDestroy$),Io(100)).subscribe(()=>{this.settleAll()})}clearContent(){this.audioVttFile=void 0,this.clearItems()}clearItems(){this.audioTrackLaneItemsMap.forEach(e=>e.destroy()),this.audioTrackLaneItemsMap.clear(),this.audioTrackLaneItemsGroup.destroyChildren()}getVisibleCues(){let e=this.timeline.getVisibleTimeRange();return this.audioVttFile.findCues(e.start,e.end)}createEntities(){if(!this.isVttLoaded())return;this.clearItems();let e=this.getVisibleCues(),t=this.timeline.getTimecodedContainerDimension().width;this.numOfInterpolations=new Z(t+this.style.itemMinPadding).div(this.style.itemWidth+this.style.itemMinPadding).floor().toNumber(),this.itemPadding=new Z(t-this.numOfInterpolations*this.style.itemWidth).div(this.numOfInterpolations-1).toNumber();let i=this.resolveNumOfCuesPerInterpolation(e.length),s=this.resolveCuesInterpolations(e,i);for(let n=0;n<this.numOfInterpolations;n++){let a=s.get(n),o=this.resolveInterpolatedItemPosition(n),h=new Mm({x:o,width:this.style.itemWidth,audioVttCue:a,style:{cornerRadius:this.style.itemCornerRadius,height:this.audioTrackLaneItemsGroup.height(),visible:!0,maxSampleFillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,minSampleFillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops}});this.audioTrackLaneItemsMap.set(n,h),this.audioTrackLaneItemsGroup.add(h.initCanvasNode())}}resolveNumOfCuesPerInterpolation(e){return new Z(e).div(this.numOfInterpolations).floor().toNumber()}resolveCuesInterpolations(e,t){let i=e.length-t*this.numOfInterpolations,s=new Map,n=0;for(let a=0;a<this.numOfInterpolations;a++){let o=t+(a<i?1:0),h=n;n=h+o;let l=e.slice(h,n),d=e[h],u=e[n-1],c=0,p=0;l.forEach(m=>{c+=m.minSample,p+=m.maxSample});let f={id:`${a}`,text:"",minSample:new Z(c).div(o).toDecimalPlaces(3).toNumber(),maxSample:new Z(p).div(o).toDecimalPlaces(3).toNumber(),startTime:d.startTime,endTime:u.endTime};s.set(a,f)}return s}settleAll(){if(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1)return;let e=this.getVisibleCues(),t=this.resolveNumOfCuesPerInterpolation(e.length),i=this.resolveCuesInterpolations(e,t);for(let s=0;s<this.numOfInterpolations;s++){let n=i.get(s),a=this.audioTrackLaneItemsMap.get(s);a.setAudioVttCue(n),a.setPosition({x:this.resolveInterpolatedItemPosition(s)})}}resolveInterpolatedItemPosition(e){return Math.abs(this.timeline.getTimecodedGroupHorizontalMeasurement().x)+e*this.style.itemWidth+e*this.itemPadding}settlePosition(){if(!(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1))for(let e=0;e<this.numOfInterpolations;e++){let t=this.audioTrackLaneItemsMap.get(e),i=this.timeline.timeToTimelinePosition(t.getAudioVttCue().startTime);t.setPosition({x:i})}}fetchAndCreateAudioTrack(){this.fetchAudioTrackVttFile(this._audioVttFileUrl).pipe(ct(1)).subscribe(e=>{this.audioVttFile=e,this.createEntities()})}fetchAudioTrackVttFile(e){return e?wn.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.audioVttFile}get audioVttFileUrl(){return this._audioVttFileUrl}set audioVttFileUrl(e){this._audioVttFileUrl=e,this.clearContent(),this.fetchAndCreateAudioTrack()}}function Xs(r){if(r.from===r.to)return;let e=r.from<r.to,t=e?r.to-r.from:r.from-r.to,i=new O.Animation(s=>{let n=O.Easings.StrongEaseInOut(s.time,0,t,r.duration);if(n>=t)r.onUpdateHandler(s,r.to),i.stop(),r.onCompleteHandler&&(r.onCompleteHandler(s,r.to),i=null);else{let a=r.from+n*(e?1:-1);r.onUpdateHandler(s,a)}},r.layer);i.start()}const Rm={...F.POSITION_TOP_LEFT,width:0,zoomMax:1500,scrollStepNumberOfDivisions:10,style:{height:20,backgroundFill:"#000000",backgroundFillOpacity:.3,handleBarFill:"#01a6f0",handleBarOpacity:1,handleOpacity:1}};class Im extends Je{constructor(e){super(vi(e,Rm)),this.onScroll$=new V,this.onZoom$=new V,this.x=this.config.x,this.y=this.config.y,this.width=this.config.width,this.zoomMax=this.config.zoomMax,this.scrollStepNumberOfDivisions=this.config.scrollStepNumberOfDivisions}createCanvasNode(){return this.group=new O.Group({x:this.x,y:this.y,width:this.width,height:this.style.height}),this.background=new O.Rect({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup=new O.Group({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height}),this.handleBar=new O.Rect({...F.POSITION_TOP_LEFT,width:this.handleGroup.width(),height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity,draggable:!0}),this.leftZoomHandle=new O.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.rightZoomHandle=new O.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.handleGroup.add(this.background),this.handleGroup.add(this.handleBar),this.group.add(this.background),this.group.add(this.handleGroup),this.handleGroup.add(this.leftZoomHandle),this.handleGroup.add(this.rightZoomHandle),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(k(this.onDestroy$),$e(n=>!!n)).subscribe(n=>{this.onStyleChange()}),this.group.on("click",n=>{this.clickScrollTo(this.group.getRelativePointerPosition().x)}),this.handleBar.on("dragstart dragmove dragend",n=>{let a=this.handleBar.getPosition(),o=this.getConstrainedHandleBarX(a.x);this.handleBar.setAttrs({x:o,y:0}),this.syncLeftRightHandles(),this.handleBar.getRelativePointerPosition().x>=0&&this.handleBar.getRelativePointerPosition().x<=this.handleBar.width()&&this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})});let e={scaleX:1.5,scaleY:1.5,duration:.1},t={scaleX:1,scaleY:1,duration:.1};this.leftZoomHandle.on("mouseover",n=>{this.leftZoomHandle.to({...e}),et.cursor("ew-resize")}),this.leftZoomHandle.on("mouseout",n=>{this.leftZoomHandle.to({...t}),et.cursor("default")}),this.rightZoomHandle.on("mouseover",n=>{this.rightZoomHandle.to({...e}),et.cursor("ew-resize")}),this.rightZoomHandle.on("mouseout",n=>{this.rightZoomHandle.to({...t}),et.cursor("default")});let i=n=>{let a=n;return a<0?a=0:this.rightZoomHandle.x()-n<=this.minHandleBarWidth&&(a=this.rightZoomHandle.x()-this.minHandleBarWidth),a};this.leftZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.leftZoomHandle.getPosition(),o=i(a.x);this.leftZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({x:o,width:this.rightZoomHandle.x()-o}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})});let s=n=>{let a=n,o=this.group.width();return a>o?a=o:n-this.leftZoomHandle.x()<=this.minHandleBarWidth&&(a=this.leftZoomHandle.x()+this.minHandleBarWidth),a};this.rightZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.rightZoomHandle.getPosition(),o=s(a.x);this.rightZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({width:o-this.leftZoomHandle.x()}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})})}onMeasurementsChange(){this.group.width(this.width),this.background.width(this.group.width()),this.handleGroup.width(this.group.width()),this.minHandleBarWidth=this.calculateHandleBarWidthFromZoomRatioPercent(this.zoomMax)}onStyleChange(){this.group.setAttrs({height:this.style.height}),this.background.setAttrs({height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup.setAttrs({height:this.style.height}),this.handleBar.setAttrs({height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity}),this.leftZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity}),this.rightZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity})}getScrollHandleMaxX(){return this.group.width()-this.handleBar.width()}getConstrainedHandleBarX(e){let t=e;return t<0?t=0:t+this.handleBar.width()>this.group.width()&&(t=this.getScrollHandleMaxX()),t}clickScrollTo(e){let t=this.group.width()/this.scrollStepNumberOfDivisions;if(!(e>=this.handleBar.x()&&e<=this.handleBar.x()+this.handleBar.width())){let i=this.handleBar.x()>e,s=this.handleBar.x()+t*(i?-1:1);i?s=s<e?e:s:s=s+this.handleBar.width()>e?e-this.handleBar.width():s,this.scrollToEased(s)}}scrollTo(e){this.handleBar.x(this.getConstrainedHandleBarX(e)),this.syncLeftRightHandles(),this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})}scrollToEased(e){let t=this.handleBar.x(),i=this.getConstrainedHandleBarX(e);Xs({layer:this.handleGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:t,to:i,onUpdateHandler:(s,n)=>{this.scrollTo(n)}})}calculateHandleBarWidthFromZoomRatioPercent(e){return new Z(this.group.width()).mul(100).div(e).toNumber()}getZoomPercent(){return this.group.width()===this.handleBar.width()?100:new Z(this.group.width()).mul(100).div(this.handleBar.width()).toNumber()}getScrollHandlePercent(){return this.handleBar.x()===0?0:new Z(this.handleBar.x()).div(this.group.width()-this.handleBar.width()).mul(100).toNumber()}updateScrollHandle(e){let t=e.getScrollHandleHorizontalMeasurement(this.group.width());this.handleBar.setAttrs({...t}),this.syncLeftRightHandles()}syncLeftRightHandles(){this.leftZoomHandle.x(this.handleBar.x()),this.rightZoomHandle.x(this.handleBar.x()+this.handleBar.width())}setWidth(e){this.width=e,this.onMeasurementsChange()}setPosition(e){this.x=e.x,this.y=e.y,this.group.setAttrs({...e})}getPosition(){return this.group.getPosition()}getRect(){return{...this.group.getPosition(),...this.group.getSize()}}}const Nm={style:{...F.POSITION_TOP_LEFT,height:100,fill:"#737373",fillSnapped:"#ffd500",lineWidth:2,symbolY:0,symbolHeight:15,textFontSize:12,textFill:"#0d0f05",textSnappedFill:"#f43530",visible:!1}};class Gm extends Je{constructor(e,t){super(vi(e,Nm)),this.stylesProvider=lt.instance(),this.timeline=t}createCanvasNode(){return this.group=new O.Group({x:this.style.x,y:this.style.y,visible:this.style.visible,listening:!1}),this.line=new O.Line({points:[this.style.x,0,this.style.x,this.style.height],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.symbol=new O.Circle({y:this.style.symbolY,fill:this.style.fill,radius:this.style.symbolHeight/2,offsetY:-this.style.symbolHeight/2}),this.group.add(this.symbol),this.group.add(this.line),this.label=new O.Label({...F.POSITION_TOP_LEFT,listening:!1}),this.text=new O.Text({fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,...F.POSITION_TOP_LEFT,text:"",listening:!1}),this.label.y(-this.text.getSelfRect().height),this.label.add(this.text),this.group.add(this.label),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.onMeasurementsChange()}),this.stylesProvider.onChange$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})})}onMeasurementsChange(){this.line.points([this.line.x(),0,this.line.x(),this.style.height])}sync(e,t=!1){this.style.visible||this.toggleVisible(!0);let i=this.timeline.timelinePositionToTimeFormatted(e),s=this.text.getSelfRect(),n=s.width/2,a=-n,o=this.timeline.getTimecodedGroupHorizontalMeasurement();o.width-e<n?a=-s.width+(o.width-e):e<n&&(a=-n+(n-e)),this.group.x(e),this.text.text(i),this.label.x(a),t?(this.line.stroke(this.style.fillSnapped),this.text.fill(this.style.fillSnapped),this.symbol.visible(!1)):(this.line.stroke(this.style.fill),this.text.fill(this.style.fill),this.symbol.visible(!0))}toggleVisible(e){this.style={visible:e},this.group.visible(e)}}const Dm={style:{visible:!0,fill:"#f43530",lineWidth:2,symbolHeight:15,scrubberHeight:15,backgroundFill:"#ffffff",backgroundOpacity:0,playProgressFill:"#008cbc",playProgressOpacity:.5,bufferedFill:"#a2a2a2",bufferedOpacity:1}};class Fm extends Je{constructor(e,t,i){super(vi(e,Dm)),this.timeline=t,this.videoController=i}createCanvasNode(){return this.group=new O.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.background=new O.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.backgroundFill,opacity:this.style.backgroundOpacity,listening:!1}),this.playProgressBackground=new O.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.playProgressFill,opacity:this.style.playProgressOpacity,listening:!1}),this.playheadGroup=new O.Group({...F.POSITION_TOP_LEFT,visible:this.style.visible,listening:!1}),this.playheadLine=new O.Line({points:[0,0,0,0],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.playheadSymbol=yi.createTriangle({...F.POSITION_TOP_LEFT,height:this.style.symbolHeight,color:this.style.fill}),this.bufferedGroup=new O.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.group.add(this.background),this.group.add(this.bufferedGroup),this.group.add(this.playProgressBackground),this.playheadGroup.add(this.playheadLine),this.playheadGroup.add(this.playheadSymbol),this.group.add(this.playheadGroup),this.group}afterCanvasNodeInit(){this.settleLayout(),this.timeline.onZoom$.pipe(k(this.onDestroy$)).subscribe(e=>{this.settleLayout()}),this.videoController.onVideoLoading$.pipe(k(this.onDestroy$)).subscribe(e=>{this.group.visible(!1)}),this.videoController.onVideoLoaded$.pipe(k(this.onDestroy$)).subscribe(e=>{this.group.visible(!0),this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onVideoTimeChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.doPlayProgress()}),this.videoController.onSeeking$.pipe(k(this.onDestroy$)).subscribe(e=>{this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onBuffering$.pipe(k(this.onDestroy$)).subscribe(e=>{this.doBufferingProgress()})}onMeasurementsChange(){this.settleLayout()}getPlayheadPosition(){return this.playheadGroup.x()}settleLayout(){let e=this.timeline.getTimecodedGroupDimension();[this.group,this.bufferedGroup,this.playheadGroup].forEach(t=>{t.setAttrs({...e})}),[this.background].forEach(t=>{t.setAttrs({width:e.width})}),this.playheadLine.setAttrs({points:[0,0,0,e.height]}),this.doPlayProgress(),this.doBufferingProgress()}doPlayProgress(){let e=this.timeline.timeToTimelinePosition(this.videoController.getCurrentTime());this.playProgressBackground.width(e),this.playheadGroup.x(e)}doBufferingProgress(){let e=this.videoController.getBufferedTimespans();if(e&&e.length>0)if(this.bufferedGroup.hasChildren()){let t=e.length,i=this.bufferedGroup.getChildren().length;t===i?this.bufferedGroup.getChildren().forEach((s,n)=>{let a=e[n],o=this.timeline.timeToTimelinePosition(a.start),h=this.timeline.timeToTimelinePosition(a.end);s.setAttrs({x:o,width:h-o})}):(this.bufferedGroup.getChildren().forEach(s=>s.destroy()),this.createBuffers(e))}else this.createBuffers(e)}createBuffers(e){e.forEach(t=>{let i=this.timeline.timeToTimelinePosition(t.start),s=this.timeline.timeToTimelinePosition(t.end),n=new O.Rect({x:i,y:0,width:s-i,height:this.style.scrubberHeight,fill:this.style.bufferedFill,opacity:this.style.bufferedOpacity,listening:!1});this.bufferedGroup.add(n)})}}const Hm={style:{...F.POSITION_TOP_LEFT,width:150,height:20,textFontSize:20,textFill:"#0d0f05",visible:!0}};class Il extends Je{constructor(e,t){super(vi(e,Hm)),this.stylesProvider=lt.instance(),this.videoEventStreamBreaker$=new V,this.videoController=t}createCanvasNode(){return this.group=new O.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,listening:!1,visible:this.style.visible}),this.text=new O.Text({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.group.height(),text:"",fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,visible:!0,align:"left",verticalAlign:"middle"}),this.group.add(this.text),this.group}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.stylesProvider.onChange$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)})}onMeasurementsChange(){this.group.width(this.style.width)}fireVideoEventStreamBreaker(){this.videoEventStreamBreaker$&&(this.videoEventStreamBreaker$.next(),this.videoEventStreamBreaker$.complete()),this.videoEventStreamBreaker$=new V}onVideoLoadedEvent(e){this.fireVideoEventStreamBreaker(),this.text.text(this.videoController.formatTimestamp(0)),this.videoController.onVideoTimeChange$.pipe(k(this.videoEventStreamBreaker$)).subscribe(t=>{this.text.text(this.videoController.formatTimestamp(t.currentTime))})}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.group.setAttrs({...e}),this.onMeasurementsChange()}getRect(){return this.group.getClientRect()}}const Bm={...Qi,height:60,tickDivisor:5,tickDivisionMinWidth:18,tickFill:"#0d0f05",tickHeight:12,divisionTickFill:"#000000",divisionTickHeight:12*F.GOLDEN_RATIO,timecodeShowFirst:!0,timecodeFontSize:11,timecodeFill:"#0d0f05"};class $m extends er{constructor(e,t){super({...e,style:{...Bm,...e.style}}),this.onClick$=new V,this.onMouseEnter$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.videoController=t}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.ticksGroup=new O.Group({...F.POSITION_TOP_LEFT,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.ticksGroup),this.timeline.addToTimecodedBaseGroup(this.timecodedGroup),this.timecodeDisplay=new Il({style:{x:10,y:0,width:this.leftGroup.width(),height:this.getRect().height}},this.videoController),this.leftGroup.add(this.timecodeDisplay.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout();let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.ticksGroup].forEach(t=>{t.width(e.width)}),this.refreshTimeDivisions()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.timecodedEventCatcher.on("mousemove",e=>{this.onMouseMove$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseenter",e=>{this.onMouseEnter$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseout",e=>{this.onMouseOut$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseleave",e=>{this.onMouseLeave$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("click",e=>{this.onClick$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.videoController.onVideoLoading$.pipe(k(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe(k(this.onDestroy$)).subscribe(e=>{this.settleLayout()})}onStyleChange(){super.onStyleChange(),this.refreshTimeDivisions(!0)}destroy(){super.destroy(),this.timecodedGroup.destroy()}clearContent(){this.ticksGroup.destroyChildren()}refreshTimeDivisions(e=!1){if(!this.isTimelineReady())return;let t=this.style.tickDivisor,i=this.style.tickDivisionMinWidth,s=this.timeline.getTimecodedGroupRect().width,n=this.resolveTimeDivisionWidth(s,i,t,t),a=new Z(s).div(n).round().toNumber(),o=!e&&this.tickTotalDivisions===a&&!(this.ticksGroup.getChildren().length<1);o||this.clearContent(),this.tickDivisionWidth=n,this.tickTotalDivisions=a;let h=0,l=2,d=2,u=5;for(let c=0;c<this.tickTotalDivisions+1;c++){let p=c===0,f=c===this.tickTotalDivisions,m=c%t===0,v=c*this.tickDivisionWidth,_=m?this.style.divisionTickHeight:this.style.tickHeight,w=this.ticksGroup.height()-_,b=this.ticksGroup.height()-this.style.divisionTickHeight-u;if(o)this.ticksGroup.getChildren()[c].x(v);else{let T=new O.Group({x:v,y:h}),L=0,A=new O.Line({points:[L,w,L,w+_],stroke:this.style.tickFill,strokeWidth:1,listening:!1});T.add(A);let G=new O.Text({fontSize:this.style.timecodeFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.timecodeFill,text:`${this.timeline.timelinePositionToTimeFormatted(v)}`,listening:!1}),R=G.getSelfRect(),H=p?L+l:f?L-R.width-d:L-R.width/2,$=b-R.height;G.setAttrs({x:H,y:$});let I=m;I=p?this.style.timecodeShowFirst:I,I&&(T.add(G),T.x()+(G.x()>0?0:G.x()),T.y(),G.width()),this.ticksGroup.add(T)}}}resolveTimeDivisionWidth(e,t,i,s){return new Z(e).div(s).floor().greaterThan(t)?this.resolveTimeDivisionWidth(e,t,i,s*i):new Z(e).div(s/i).toNumber()}}const Vm={timelineHTMLElementId:"omakase-timeline",playheadHoverSnapArea:5,zoomScale:1.02,zoomBaseline:100,zoomMax:1500,style:{stageMinWidth:700,backgroundFill:"#f5f5f5",headerBackgroundFill:"#f5f5f5",footerBackgroundFill:"#f5f5f5",scrollbarHeight:15,thumbnailHoverWidth:200,thumbnailHoverStroke:"rgba(255,73,145,0.9)",thumbnailHoverStrokeWidth:5,thumbnailHoverYOffset:0,headerHeight:50,footerHeight:50,leftPanelWidth:200,rightPanelLeftGutterWidth:30,rightPanelRightGutterWidth:30,timecodedContainerClipPadding:20,playheadVisible:!0,playheadFill:"#f43530",playheadLineWidth:2,playheadSymbolHeight:15,playheadScrubberHeight:15,playheadBackgroundFill:"#ffffff",playheadBackgroundOpacity:0,playheadPlayProgressFill:"#008cbc",playheadPlayProgressOpacity:.5,playheadBufferedFill:"#a2a2a2",playheadBufferedOpacity:1}},xa="omakase_scrubber_lane";class zm extends Je{constructor(e,t){super(vi(e,Vm)),this.scrollWithPlayhead=!0,this.syncTimelineWithPlayheadInProgress=!1,this.mouseWheelEnabled=!1,this.leftPanelVisible=!0,this.videoEventBreaker$=new V,this.onScroll$=new V,this.onZoom$=new V,this.timelineHTMLElementId=this.config.timelineHTMLElementId,this.thumbnailVttUrl=this.config.thumbnailVttUrl,this.axiosConfig=this.config.axiosConfig,this.playheadHoverSnapArea=this.config.playheadHoverSnapArea,this.zoomScale=this.config.zoomScale,this.zoomBaseline=this.config.zoomBaseline,this.zoomMax=this.config.zoomMax,this.timecodedGroupNodes=[],this.timelaneLanes=[],this.timelaneLanesMap=new Map,this.timelineHTMLElement=document.getElementById(this.timelineHTMLElementId),this.videoController=t}createCanvasNode(){let e=this.resolveStageDimension();return this.width=e.width,this.stage=new O.Stage({container:this.timelineHTMLElementId,...e}),this.layer=new O.Layer,this.stage.add(this.layer),this.layoutGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.layer.add(this.layoutGroup),this.layoutBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:this.style.backgroundFill}),this.headerGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.headerBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:this.style.headerBackgroundFill}),this.footerGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.footerBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:this.style.footerBackgroundFill}),this.bodyGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.bodyContentGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.leftPanel=new O.Group({...F.POSITION_TOP_LEFT}),this.rightPanel=new O.Group({...F.POSITION_TOP_LEFT}),this.timecodedContainer=new O.Group({...F.POSITION_TOP_LEFT}),this.timecodedGroup=new O.Group({...F.POSITION_TOP_LEFT,draggable:!0}),this.timecodedBaseGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedBaseGroup"}),this.timecodedThumbnailsGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedThumbnailsGroup"}),this.timecodedSubtitlesGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedSubtitlesGroup"}),this.timecodedAudioGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedAudioGroup"}),this.timecodedMarkersGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedMarkersGroup"}),this.timecodedSurfaceGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedSurfaceGroup"}),this.timecodedBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:"yellow",opacity:0,listening:!1}),this.timecodedEventCatcher=yi.createEventCatcher(),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.layoutGroup.add(this.layoutBackground),this.layoutGroup.add(this.headerGroup),this.layoutGroup.add(this.footerGroup),this.layoutGroup.add(this.bodyGroup),this.headerGroup.add(this.headerBackground),this.footerGroup.add(this.footerBackground),this.bodyGroup.add(this.bodyContentGroup),this.bodyGroup.add(this.leftPanel),this.bodyGroup.add(this.rightPanel),this.rightPanel.add(this.timecodedContainer),this.timecodedContainer.add(this.timecodedGroup),[this.timecodedBackground,this.timecodedEventCatcher,this.timecodedBaseGroup,this.timecodedThumbnailsGroup,this.timecodedSubtitlesGroup,this.timecodedAudioGroup,this.timecodedMarkersGroup,this.timecodedSurfaceGroup].forEach(t=>{this.timecodedGroupNodes.push(t),this.timecodedGroup.add(t)}),this.scrollbar=new Im({style:{height:this.style.scrollbarHeight}}),this.rightPanel.add(this.scrollbar.initCanvasNode()),this.playhead=new Fm({style:{visible:this.style.playheadVisible,fill:this.style.playheadFill,lineWidth:this.style.playheadLineWidth,symbolHeight:this.style.playheadSymbolHeight,backgroundFill:this.style.playheadBackgroundFill,backgroundOpacity:this.style.playheadBackgroundOpacity,scrubberHeight:this.style.playheadScrubberHeight,playProgressFill:this.style.playheadPlayProgressFill,playProgressOpacity:this.style.playheadPlayProgressOpacity,bufferedFill:this.style.playheadBufferedFill,bufferedOpacity:this.style.playheadBufferedOpacity}},this,this.videoController),this.playheadHover=new Gm({},this),[this.playhead,this.playheadHover].forEach(t=>{this.addToTimecodedSurfaceGroup(t.initCanvasNode())}),this.headerTimecodeDisplay=new Il({style:{x:10,y:10,visible:!1}},this.videoController),this.headerGroup.add(this.headerTimecodeDisplay.initCanvasNode()),this.settleLayout(),this.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.scrubberLane=new $m({id:xa,description:""},this.videoController),this.addLanes([this.scrubberLane]),this.stage}afterCanvasNodeInit(){this.videoController.onVideoLoading$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)}),be(window,"resize").pipe(k(this.onDestroy$)).subscribe(e=>{setTimeout(()=>{this.onWindowResize(e)},200)}),this.timecodedGroup.on("mouseenter",e=>{this.playheadHover.toggleVisible(this.videoController.isVideoLoaded())}),this.timecodedGroup.on("mouseleave",e=>{this.playheadHover.toggleVisible(!1)}),this.timecodedGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedMarkersGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("wheel",e=>{if(!this.videoController.isVideoLoaded())return;if(this.mouseWheelEnabled){let i=e.evt;i.preventDefault();let s=i.deltaY>0?"IN":"OUT";i.ctrlKey&&(s=s==="IN"?"OUT":"IN"),this.zoomStep(s,this.timecodedGroup.getRelativePointerPosition().x),this.updateScrollWithPlayhead()}let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("dragstart dragmove dragend",e=>{if(!this.videoController.isVideoLoaded()){this.timecodedGroup.setAttrs({...F.POSITION_TOP_LEFT});return}if(e.target===this.timecodedGroup){let t=this.timecodedGroup.getPosition();this.timecodedGroup.setAttrs({x:this.getConstrainedTimelineX(t.x),y:0}),this.onScroll$.next(this.createScrollEvent()),this.scrollbar.updateScrollHandle(this)}this.updateScrollWithPlayhead()}),this.timecodedGroup.on("dragmove",e=>{et.cursor("grabbing")}),this.timecodedGroup.on("dragend",e=>{et.cursor("default")}),this.scrubberLane.onMouseMove$.pipe(k(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.mouseWheelEnabled=!0;let t=this.timecodedGroup.getRelativePointerPosition().x,i=this.timelinePositionToTime(t);if(this.thumbnailVttFile){let s=this.thumbnailVttFile.findCue(i);this.showThumbnailHover(s)}}),this.scrubberLane.onMouseEnter$.pipe(k(this.onDestroy$)).subscribe(e=>{this.mouseWheelEnabled=!0}),this.scrubberLane.onMouseLeave$.pipe(k(this.onDestroy$)).subscribe(e=>{this.hideThumbnailHover(),this.mouseWheelEnabled=!1}),this.scrubberLane.onClick$.pipe(k(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.updateScrollWithPlayhead();let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t),this.videoController.isVideoLoaded()&&this.videoController.seekToTimestamp(this.timelinePositionToTime(t)).subscribe(()=>{})}),this.scrollbar.onScroll$.pipe(k(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.updateScrollWithPlayhead(),this.onScroll$.next(this.createScrollEvent()))}),this.scrollbar.onZoom$.pipe(k(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.zoomByPercent(e.zoomPercent,!1),this.updateScrollWithPlayhead())}),this.thumbnailVttUrl&&this.fetchThumbnailVttFile().subscribe()}settleLayout(){this.stage.setAttrs({...this.resolveStageDimension()});let e=this.calculateHeights();this.headerGroup.setAttrs({width:this.width,height:this.style.headerHeight}),this.bodyGroup.setAttrs({y:this.headerGroup.y()+this.headerGroup.height(),width:this.layoutGroup.width(),height:e.bodyHeight}),this.footerGroup.setAttrs({y:this.bodyGroup.y()+this.bodyGroup.height(),width:this.width,height:this.style.footerHeight}),this.layoutGroup.setAttrs({width:this.width,height:e.layoutHeight}),this.layoutBackground.setAttrs({...this.layoutGroup.getSize()}),this.headerBackground.setAttrs({...this.headerGroup.getSize()}),this.footerBackground.setAttrs({...this.footerGroup.getSize()}),[this.bodyContentGroup].forEach(t=>{t.setAttrs({...this.bodyGroup.getSize()})}),[this.leftPanel,this.rightPanel].forEach(t=>{t.setAttrs({height:this.bodyGroup.getSize().height})}),this.leftPanel.setAttrs({width:this.leftPanelVisible?this.style.leftPanelWidth:0,visible:this.leftPanelVisible}),this.rightPanel.setAttrs({x:this.leftPanel.x()+this.leftPanel.width()+this.style.rightPanelLeftGutterWidth,width:this.layoutGroup.width()-(this.leftPanel.width()+this.style.rightPanelLeftGutterWidth+this.style.rightPanelRightGutterWidth)}),[this.timecodedContainer,this.timecodedGroup,...this.timecodedGroupNodes].forEach(t=>{t.setAttrs({...this.rightPanel.getSize()})}),this.timecodedContainer.clipFunc(t=>{t.rect(-this.style.timecodedContainerClipPadding,-500,this.timecodedContainer.width()+2*this.style.timecodedContainerClipPadding,this.timecodedContainer.height()+500)}),this.timecodedThumbnailsGroup.clipFunc(t=>{t.rect(0,0,this.timecodedThumbnailsGroup.width(),this.timecodedThumbnailsGroup.height())}),this.scrollbar.setPosition({...this.scrollbar.getPosition(),y:this.leftPanel.getSize().height}),this.scrollbar.setWidth(this.timecodedContainer.width()),this.scrollbar.updateScrollHandle(this),this.maxTimecodedGroupWidth=this.calculateWidthFromZoomRatioPercent(this.zoomMax),this.playheadHover.style={height:this.timecodedContainer.height()},this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.playhead.onMeasurementsChange()}onMeasurementsChange(){this.settleLayout();let e=this.getTimecodedGroupDimension();this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.zoomByWidth(e.width,this.resolveZoomFocus()),this.scrollbar.updateScrollHandle(this)}onWindowResize(e){let t=this.resolveStageDimension();this.width=t.width,this.onMeasurementsChange()}calculateHeights(){let t=this.getLanes().map(i=>i.getDimension().height).reduce((i,s)=>i+s,0);return{bodyHeight:t,layoutHeight:this.style.headerHeight+t+this.style.footerHeight}}resolveStageDimension(){let e=this.getTimelineHTMLElementRect(),t=this.calculateHeights();return{width:e.width>=this.style.stageMinWidth?e.width:this.style.stageMinWidth,height:t.layoutHeight}}getTimelineHTMLElementRect(){return{x:this.timelineHTMLElement.offsetLeft,y:this.timelineHTMLElement.offsetTop,width:this.timelineHTMLElement.offsetWidth,height:this.timelineHTMLElement.offsetHeight}}showThumbnailHover(e){if(e)if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.getThumbnailVttCue()===e){this.thumbnailHover.setThumbnailVttCue(e);let t=this.resolveThumbnailPosition(this.thumbnailHover);this.thumbnailHover.setPosition(t),this.thumbnailHover.getCanvasNode().moveToTop()}else dt.createKonvaImageSizedByWidth(e.url,this.style.thumbnailHoverWidth).subscribe(t=>{this.thumbnailHover.setThumbnailVttCue(e),this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailPosition(this.thumbnailHover)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.setVisible(!1)}resolveThumbnailPosition(e){let t=this.timecodedGroup.getRelativePointerPosition(),i=this.getTimecodedGroupDimension(),s=e.getImage().getSize(),n=t.x-s.width/2,a=e.style.strokeWidth>0?e.style.strokeWidth/2:0;n=n-a<0?a:n+s.width+a>i.width?i.width-s.width-a:n;let h=this.scrubberLane.getRect();return{x:n,y:h.y+h.height+e.style.strokeWidth/2+this.style.thumbnailHoverYOffset}}createScrollEvent(){return{scrollPercent:this.getHorizontalScrollPercent()}}createZoomEvent(){return{zoomPercent:this.getZoomPercent()}}getHorizontalScrollPercent(){if(this.isSnappedStart())return 0;if(this.isSnappedEnd())return 100;{let e=new Z(this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width).abs();return new Z(this.getTimecodedGroupPosition().x).abs().mul(100).div(e).toNumber()}}setHorizontalScrollPercent(e){this.setTimelinePosition(this.calculateTimelineXFromScrollPercent(e))}getScrollHandleHorizontalMeasurement(e){let t=this.getTimecodedGroupDimension().width,i=this.getTimecodedGroupPosition().x,s;return t<=e?s={width:e,x:0}:s={width:new Z(e).mul(e).div(t).round().toNumber(),x:new Z(i).abs().mul(e).div(t).toNumber()},s}scrollTo(e){return e=_e.coerce.number().min(0).max(100).parse(e),this.scrollToPercentEased(e)}scrollToPlayhead(){let e=-this.playhead.getPlayheadPosition()+this.getTimecodedContainerDimension().width/2;return this.scrollToEased(e)}scrollToPercent(e){let t=this.calculateTimelineXFromScrollPercent(e);this.scrollTimeline(t)}scrollToPercentEased(e){let t=this.calculateTimelineXFromScrollPercent(e);return this.scrollToEased(t)}scrollToEased(e){return new se(t=>{let i=this.getTimecodedGroupPosition().x;Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:i,to:e,onUpdateHandler:(s,n)=>{this.scrollTimeline(n)},onCompleteHandler:(s,n)=>{t.next(this.getHorizontalScrollPercent()),t.complete()}})})}isPlayheadInTimecodedView(){return this.isInVisiblePositionRange(this.playhead.getPlayheadPosition())}updateScrollWithPlayhead(){let e=this.playhead.getPlayheadPosition(),t=e<this.getVisiblePositionRange().start,i=this.isInVisiblePositionRange(e);this.scrollWithPlayhead=i&&!t}syncTimelineWithPlayhead(){return new se(e=>{this.scrollToEased(-this.playhead.getPlayheadPosition()).pipe(ke(t=>{e.next(this.getHorizontalScrollPercent()),e.complete()})).subscribe()})}setTimelinePosition(e){let t=this.getConstrainedTimelineX(e);this.timecodedGroup.x(t)}scrollTimeline(e){let t=this.getTimecodedGroupPosition().x;this.setTimelinePosition(e),this.getTimecodedGroupPosition().x!==t&&(this.scrollbar.updateScrollHandle(this),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onScroll$.next(this.createScrollEvent()))}calculateTimelineXFromScrollPercent(e){e=this.getConstrainedScrollPercent(e);let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width>i.width){let s=new Z(i.width-t.width);return new Z(e).mul(s).div(100).toDecimalPlaces(2).toNumber()}else return 0}getZoomPercent(){let e=this.getTimecodedGroupDimension(),t=this.getTimecodedContainerDimension();return e.width>t.width?new Z(e.width).mul(100).div(t.width).round().toNumber():this.zoomBaseline}zoomTo(e){return e=_e.coerce.number().min(this.getZoomBaseline()).max(this.getZoomMax()).parse(e),this.zoomToEased(e)}zoomIn(){return new se(e=>{this.zoomStep("IN",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomOut(){return new se(e=>{this.zoomStep("OUT",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomToEased(e){return new se(t=>{e=this.getConstrainedZoomPercent(e);let i=this.getTimecodedGroupDimension().width,s=this.calculateWidthFromZoomRatioPercent(e);Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_ZOOM_EASED_DURATION_MS,from:i,to:s,onUpdateHandler:(n,a)=>{this.zoomByWidth(a,this.resolveZoomFocus())},onCompleteHandler:(n,a)=>{t.next(this.getZoomPercent()),t.complete()}})})}zoomStep(e,t){let i=new Z(this.getTimecodedGroupDimension().width),s=(e==="IN"?i.mul(this.zoomScale):i.div(this.zoomScale)).round().toNumber();this.zoomByWidth(s,t)}zoomByPercent(e,t=!0){e=this.getConstrainedZoomPercent(e);let i=this.calculateWidthFromZoomRatioPercent(e);return this.zoomByWidth(i,this.resolveZoomFocus(),t),this.getZoomPercent()}zoomByWidth(e,t,i=!0){let s=this.getTimecodedGroupPosition().x,n=this.getTimecodedGroupDimension().width;e=this.getConstrainedWidth(e);let a=this.calculateNewPosition(e,t);this.hideThumbnailHover(),this.timecodedGroup.setAttrs({width:e,x:a}),this.timecodedGroupNodes.forEach(h=>{h.width(e)}),(this.getTimecodedGroupDimension().width!==n||this.getTimecodedGroupPosition().x!==s)&&(i?this.scrollbar.updateScrollHandle(this):this.playheadHover.toggleVisible(!1),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onZoom$.next(this.createZoomEvent()),this.onScroll$.next(this.createScrollEvent()))}calculateNewPosition(e,t=0){let i=this.getTimecodedGroupPosition().x,s=this.getTimecodedGroupDimension().width,n=this.getTimecodedContainerRect(),a=e>s?"IN":"OUT",o=i;if(e===n.width)o=0;else if(e>n.width){if(t>0){let h=new Z(t).div(s);if(h.greaterThanOrEqualTo(0)&&h.lessThanOrEqualTo(1)){let l=e-s,d=h.mul(l).abs().round().toNumber(),u=i+d*(a==="IN"?-1:1);o=u<0?u:0}}if(e>n.width){let h=n.x+n.width;o+e<=h&&(o=n.width-e)}}return o}resolveZoomFocus(){return this.videoController.isVideoLoaded()?this.resolvePlayheadSyncPosition():this.isSnappedStart()?0:this.isSnappedEnd()?this.getTimecodedGroupDimension().width:this.getTimecodedGroupDimension().width/2}calculateWidthFromZoomRatioPercent(e){return new Z(this.getTimecodedContainerDimension().width).mul(e).div(100).round().toNumber()}getConstrainedWidth(e){let t=this.getTimecodedContainerDimension();return e>=t.width?e<=this.maxTimecodedGroupWidth?e:this.maxTimecodedGroupWidth:t.width}getConstrainedZoomPercent(e){return e<this.zoomBaseline?this.zoomBaseline:e>this.zoomMax?this.zoomMax:e}getConstrainedScrollPercent(e){return e<0?0:e>100?100:e}playheadHoverMove(e){if(this.videoController.isVideoLoaded()&&this.playheadHover){let t=!1;if(!this.videoController.isPlaying()){let i=this.resolvePlayheadSyncPosition();e>i-this.playheadHoverSnapArea&&e<i+this.playheadHoverSnapArea&&(e=i,t=!0)}this.playheadHover.sync(e,t)}}resolvePlayheadSyncPosition(){return this.timeToTimelinePosition(this.videoController.getCurrentTime())}onVideoLoadedEvent(e){this.fireVideoEventBreaker(),this.clearContent(),this.syncVideoMetadata(),this.videoController.onVideoTimeChange$.pipe(k(this.videoEventBreaker$)).subscribe(t=>{this.syncVideoMetadata()}),this.videoController.onPlay$.pipe(k(this.videoEventBreaker$)).subscribe(t=>{this.updateScrollWithPlayhead()})}fireVideoEventBreaker(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V}setThumbnailVttFile(e){this.thumbnailVttFile=e}syncVideoMetadata(){this.scrollWithPlayhead&&!this.isPlayheadInTimecodedView()&&!this.syncTimelineWithPlayheadInProgress&&(this.syncTimelineWithPlayheadInProgress=!0,this.syncTimelineWithPlayhead().subscribe(e=>{this.syncTimelineWithPlayheadInProgress=!1}))}addLane(e){if(this.timelaneLanesMap.has(e.getId()))throw new Error(`TimelineLane with id=${e.getId()} already exist`);let t=this.timelaneLanes.length<1,i={...F.POSITION_TOP_LEFT};t||(i.y=this.timelaneLanes.map(s=>s.getRect().height).reduce((s,n)=>s+n,0)),e.setTimeline(this),e.setVideoController(this.videoController),e.setTimelinePosition(i),e.initCanvasNode(),this.timelaneLanes.push(e),this.timelaneLanesMap.set(e.getId(),e),this.bodyContentGroup.add(e.getCanvasNode()),this.settleLayout()}removeLane(e){if(!this.timelaneLanesMap.has(e))throw new Error(`TimelineLane with id=${e} doesn't exist`);let t=this.timelaneLanesMap.get(e);this.timelaneLanes.splice(this.timelaneLanes.findIndex(s=>s.getId()===e),1),this.timelaneLanesMap.delete(e),t.clearContent(),t.destroy();let i={...F.POSITION_TOP_LEFT};this.timelaneLanes.forEach(s=>{s.setTimelinePosition({...i}),i.y=i.y+s.getRect().height}),this.timelaneLanes.forEach(s=>{s.onMeasurementsChange()}),this.settleLayout()}getScrollbar(){return this.scrollbar}addLanes(e){e.forEach(t=>this.addLane(t))}getLanes(){return[...this.timelaneLanesMap.values()]}getLane(e){return this.timelaneLanesMap.get(e)}getScrubberLane(){return this.getLane(xa)}getMarkerLane(e){let t=this.getLane(e);return t instanceof Bs?t:void 0}getThumbnailLane(e){let t=this.getLane(e);return t instanceof js?t:void 0}getSubtitlesLane(e){let t=this.getLane(e);return t instanceof Us?t:void 0}getAudioTrackLane(e){let t=this.getLane(e);return t instanceof Rl?t:void 0}createMarkerLane(e){let t=new Bs(e);return this.addLane(t),t}createThumbnailLane(e){let t=new js(e);return this.addLane(t),t}createSubtitlesLane(e){let t=new Us(e);return this.addLane(t),t}isTimelineReady(){return this.videoController.isVideoLoaded()}addToTimecodedBaseGroup(e){this.timecodedBaseGroup.add(e)}addToTimecodedSurfaceGroup(e){this.timecodedSurfaceGroup.add(e)}addToTimecodedMarkersGroup(e){this.timecodedMarkersGroup.add(e)}addToTimecodedThumbnailsGroup(e){this.timecodedThumbnailsGroup.add(e)}addToTimecodedSubtitlesGroup(e){this.timecodedSubtitlesGroup.add(e)}addToTimecodedAudioGroup(e){this.timecodedAudioGroup.add(e)}constrainTimelinePosition(e){let t=this.getTimecodedGroupDimension();return e<0?0:e>t.width?t.width:e}timelinePositionToTime(e){let t=this.constrainTimelinePosition(e);return this.videoController.isVideoLoaded()?new Z(t).mul(this.videoController.getDuration()).div(this.getTimecodedGroupDimension().width).toNumber():0}timelinePositionToTimeFormatted(e){return this.videoController.isVideoLoaded()?this.videoController.formatTimestamp(this.timelinePositionToTime(e)):""}timelinePositionToFrame(e){return this.videoController.isVideoLoaded()?this.videoController.calculateTimeToFrame(this.timelinePositionToTime(e)):0}timeToTimelinePosition(e){return new Z(e).mul(this.getTimecodedGroupDimension().width).div(this.videoController.getDuration()).toNumber()}getConstrainedTimelineX(e){let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width<=i.width)return 0;{let s=i.width-t.width;return e<s?s:e>0?0:e}}getBodyGroupRect(){return{...this.bodyGroup.getPosition(),...this.bodyGroup.getSize()}}getLeftPanelRect(){return{...this.leftPanel.getPosition(),...this.leftPanel.getSize()}}getLeftPanelVisible(){return this.leftPanelVisible}getRightPanelRect(){return{...this.rightPanel.getSize(),...this.rightPanel.getPosition()}}getTimecodedContainerDimension(){return this.timecodedContainer.getSize()}getTimecodedContainerPosition(){return this.timecodedContainer.getPosition()}getTimecodedContainerRect(){return{...this.getTimecodedContainerDimension(),...this.getTimecodedContainerPosition()}}getTimecodedGroupDimension(){return this.timecodedGroup.getSize()}getTimecodedGroupPosition(){return this.timecodedGroup.getPosition()}getTimecodedGroupRect(){return{...this.timecodedGroup.getPosition(),...this.timecodedGroup.getSize()}}getTimecodedGroupHorizontalMeasurement(){return{x:this.timecodedGroup.x(),width:this.timecodedGroup.width()}}getRelativePointerPosition(){return this.timecodedGroup.getRelativePointerPosition()}getLayoutGroupDimension(){return this.layoutGroup.getSize()}getLayoutGroupPosition(){return this.layoutGroup.getPosition()}getRect(){return{...this.getLayoutGroupDimension(),...this.getLayoutGroupPosition()}}getVisiblePositionRange(){let e=Math.abs(this.timecodedGroup.x()),t=e+this.timecodedContainer.width();return{start:e,end:t}}isInVisiblePositionRange(e){let t=this.getVisiblePositionRange();return e>=t.start&&e<=t.end}isSnappedStart(){return this.getTimecodedGroupPosition().x===0}isSnappedEnd(){return this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width===this.getTimecodedGroupPosition().x}getVisibleTimeRange(){let e=this.getVisiblePositionRange(),t=this.timelinePositionToTime(e.start),i=this.timelinePositionToTime(e.end);return{start:t,end:i}}getZoomBaseline(){return this.zoomBaseline}getZoomMax(){return this.zoomMax}fetchThumbnailVttFile(){return this.thumbnailVttUrl?ss.create(this.thumbnailVttUrl,this.axiosConfig).pipe(ke(e=>(this.thumbnailVttFile=e,e)),gi((e,t)=>Ee(void 0))):Ee(void 0)}toggleLeftPanelVisible(e){this.leftPanelVisible=e,this.leftPanel.visible(e),this.settleLayout(),this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.headerTimecodeDisplay.setVisible(!e)}clearContent(){this.setThumbnailVttFile(void 0),this.timelaneLanes.forEach(e=>{e.clearContent()}),this.zoomByPercent(this.zoomBaseline)}}class qs{static timeToFrame(e,t){return t.mul(e).floor().toNumber()}static frameToTime(e,t){return new Z(e).dividedBy(t).toNumber()}}function Wm(r){r.next(),r.complete()}class ti{constructor(){this.resolveUserAgent()}static instance(){return ti._instance||(ti._instance=new ti),ti._instance}resolveUserAgent(){this._userAgent=window.navigator&&window.navigator.userAgent||"",this._isAndroid=/Android/i.test(this._userAgent),this._isFirefox=/Firefox/i.test(this._userAgent),this._isEdge=/Edg/i.test(this._userAgent),this._isChromium=/Chrome/i.test(this._userAgent)||/CriOS/i.test(this._userAgent),this._isChrome=!this.isEdge&&this.isChromium,this._isSafari=/Safari/i.test(this._userAgent)&&!this.isChrome&&!this.isAndroid&&!this.isEdge}get isSafari(){return this._isSafari}get isFirefox(){return this._isFirefox}get isEdge(){return this._isEdge}get isChromium(){return this._isChromium}get isChrome(){return this._isChrome}get isAndroid(){return this._isAndroid}}const Qe=class{static formatVideoTimestamp(r,e){if(r<=0)return Qe.VIDEO_ZERO_TIMESTAMP;const t=Math.floor(r/3600),i=Math.floor(r%3600/60),s=Math.floor(r%60);let n=new Z(qs.timeToFrame(r,e)).mod(e).toNumber();return`${Qe.padZero(t)}:${Qe.padZero(i)}:${Qe.padZero(s)}:${Qe.padZero(n)}`}static padZero(r,e=2){return r.toString().padStart(e,"0")}};let Ys=Qe;Ys.VIDEO_ZERO_TIMESTAMP=`${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}`;class Um{constructor(){this._state={playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1},this.onChange$=new Qt(this._state)}updateState(e){let t={...this._state,...e},i=this.compare(this._state,t)===0;this._state=t,i||this.onChange$.next(this._state)}compare(e,t){return e.playing===t.playing&&e.paused===t.paused&&e.waiting===t.waiting&&e.seeking===t.seeking&&e.buffering===t.buffering&&e.ended===t.ended?0:-1}get state(){return this._state}setPlaying(){this.updateState({playing:!0,paused:!1,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setPaused(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setEnded(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!0})}set waiting(e){this.updateState({waiting:e})}set seeking(e){this.updateState({seeking:e})}set buffering(e){this.updateState({buffering:e})}}function Pa(r){let e;return typeof r=="string"?e=r:r instanceof it?(console.log(r),e=r.errors.map(t=>t.message).join(". ")):r instanceof Error?e=r.message:e="Unexpected error",e}function Zm(r){return{errorMap:(e,t)=>({message:r})}}const We={PAUSE:"pause",WAITING:"waiting",PLAYING:"playing",TIMEUPDATE:"timeupdate",SEEKING:"seeking",SEEKED:"seeked",LOADEDDATA:"loadeddata",LOADEDMETEDATA:"loadedmetadata",ENDED:"ended",PROGRESS:"progress"};class jm{constructor(e,t){if(this.browserProvider=ti.instance(),this.helpMenuGroups=[],this._isVideoLoaded=!1,this.frameDurationSpillOverCorrection=1e-6,this.syncLoopMaxIterations=20,this.seekInProgress=!1,this.videoStalledCheckIntervalMs=700,this.videoFrameCallback$=new Qt(null),this.videoEventBreaker$=new V,this.onDestroy$=new V,this.seekBreaker$=new V,this.onVideoLoaded$=new Qt(void 0),this.onVideoLoading$=new V,this.onPlay$=new V,this.onPause$=new V,this.onVideoTimeChange$=new V,this.onSeeking$=new V,this.onSeeked$=new V,this.onBuffering$=new V,this.onEnded$=new V,this.onAudioSwitched$=new V,this.onPlaybackState$=new V,this.onHelpMenuChange$=new Qt(void 0),this.onVideoError$=new V,this.domController=e,this.crossorigin=t,this.videoElement=this.domController.videoElement,this.videoElement.crossOrigin=this.crossorigin,!this.videoElement)throw new Error("VideoController element not set");this.videoFrameCallback$.pipe(k(this.onDestroy$)).subscribe(i=>{i&&(this.seekInProgress||(this.isPlaying()?this.videoTimeChangeHandlerExecutor():this.isPaused()))})}loadVideo(e,t,i){try{return e=ai.url()(e),t=_e.coerce.number().min(0).max(100).parse(t,Zm("Invalid frameRate")),this.onVideoLoading$.next({sourceUrl:e,frameRate:t}),this._isVideoLoaded=!1,this.video=void 0,this.detachVideoEventListeners(),this.videoLoad(e,t,i).pipe(ke(s=>(this.video=s,this.frameRateDecimal=new Z(this.video.frameRate),this.syncStepCurrentTimeMediaTime=new Z(this.video.frameDuration).div(10).toNumber(),this.playbackStateMachine=new Um,this.initEventHandlers(),this.startVideoFrameCallback(),this._isVideoLoaded=!0,this.onVideoLoaded$.next({video:this.video}),s)),gi((s,n)=>{let a=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:a}),Kn(()=>new Error(a))}))}catch(s){let n=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:n}),Kn(()=>new Error(n))}}initEventHandlers(){be(this.videoElement,We.PAUSE).pipe(k(this.videoEventBreaker$)).subscribe(e=>{if(this.browserProvider.isSafari){let t=this.getCurrentTime()+this.video.frameDuration;this._seekTimeAndSyncNoEmitEvents(t).subscribe(i=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}else this.syncVideoFrames({}).subscribe(t=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}),be(this.videoElement,We.WAITING).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.waiting=!0}),be(this.videoElement,We.PLAYING).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.PAUSE).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.TIMEUPDATE).pipe(k(this.videoEventBreaker$)).subscribe(e=>{}),be(this.videoElement,We.PROGRESS).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.onBuffering$.next({bufferedTimespans:this.getBufferedTimespans()})}),be(this.videoElement,We.ENDED).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.onEnded$.next({})}),this.playbackStateMachine.onChange$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.onPlaybackState$.next(e)}),this.onPlay$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),this.onPause$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),this.onSeeking$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!0}),this.onSeeked$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!1}),this.onEnded$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setEnded(),this.videoStalledCheckLastCurrentTime=void 0}),zu(this.videoStalledCheckIntervalMs).pipe(k(this.videoEventBreaker$)).subscribe(e=>{let t=this.getCurrentTime();if(!this.videoStalledCheckLastCurrentTime){this.videoStalledCheckLastCurrentTime=t;return}if(this.playbackStateMachine.state.playing){let i=this.videoStalledCheckIntervalMs*.8/1e3*this.getPlaybackRate(),s=this.videoStalledCheckLastCurrentTime+i,n=t<s;this.playbackStateMachine.waiting=n,this.videoStalledCheckLastCurrentTime=t}})}getBufferedTimespans(){if(!this.isVideoLoaded())return[];let e=[],t=this.videoElement.buffered;for(let i=0;i<t.length;i++)e.push({start:t.start(i),end:t.end(i)});return e}startVideoFrameCallback(){let e=()=>{this.videoFrameCallbackHandle=this.videoElement.requestVideoFrameCallback((i,s)=>{t({now:i,metadata:s})})},t=i=>{this.videoFrameCallback$.next(i),e()};e()}detachVideoEventListeners(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V,this.videoElement&&this.videoFrameCallbackHandle&&this.videoElement.cancelVideoFrameCallback(this.videoFrameCallbackHandle)}syncVideoFrames(e){return console.debug("syncFrames - START",e),new se(t=>{let i=new Qt(!1),s=new V,n=this.syncLoopMaxIterations;this.seekBreaker$.pipe(k(s)).subscribe(()=>{console.debug("%csyncFrames - seek breaker triggered","color: gray"),i.next(!0),a()});let a=()=>{Wm(s),t.next(),t.complete(),console.debug("%csyncFrames - END","color: gray")},o=h=>{i.pipe(ct(1)).subscribe(l=>{l?console.debug("%csyncFrames - seek skipped, breaker already triggered","color: gray"):this._seekTimeFireAndForget(h)})};if(this.isPlaying())console.debug("%csyncFrames - SKIPPED: video is playing","color: gray"),a();else{let h=u=>{let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(this.isPlaying())return console.debug("%csyncFrames - UNKNOWN: video is playing","color: gray"),!0;if(p===0)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === 0`,"color: green"),!0;if(e.seekToFrame){if(e.seekToFrame===p&&(p===m||!m))return console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),!0}else if(p===m||!m)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),!0;return!1},l,d=u=>{if(console.debug(`syncFrames.syncLoop - START (${this.syncLoopMaxIterations-n})`,{syncConditions:e,videoFrameCallbackData:u,dropped:this.videoElement.getVideoPlaybackQuality()}),this.isPlaying()){a();return}if(h(u)){a();return}let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(n--<=0){console.debug(`%csyncFrames - TOO MANY SYNCs, EXITING.. : currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}]`,"color: red"),a();return}if(console.debug(`syncFrames - currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}], `),e.seekToFrame)if(l||(l=c),e.seekToFrame===p)if(p===m||!m)console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),a();else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red");let v=Math.abs(p-m);console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange");let _=this.syncStepCurrentTimeMediaTime*(p>m?1:-1);o(Z.add(c,_).toNumber())}else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; syncConditions.seekToFrame[${e.seekToFrame}] !== currentTimeFrame[${p}] | seekToFrameTimeBaseline=${l}`,"color: red");let v=Math.abs(e.seekToFrame-p),_=v*this.video.frameDuration,b=(e.seekToFrame>=p?Z.add(l,_):Z.sub(l,_)).toNumber();l=b,console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange"),console.debug(`%csyncFrames - frameCorrectionTime: ${_}`,"color: orange"),console.debug(`%csyncFrames - seekTo: ${b}`,"color: orange"),o(b)}else p===m||!m?(console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),a()):(console.debug(`%csyncFrames - CORRECTION; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red"),p>m?o(Z.add(c,this.syncStepCurrentTimeMediaTime).toNumber()):o(f+this.syncStepCurrentTimeMediaTime));console.debug("syncFrames.syncLoop - END")};this.videoFrameCallback$.pipe(ju((e.seekToFrame,0)),k(s)).subscribe(u=>{console.debug("syncFrames.syncLoop - videoFrameCallback$ trigger",u),d(u)})}})}seekTimeAndSync(e,t={}){return new se(i=>{this.seekInProgress&&(this.seekBreaker$.next(),this.seekBreaker$.complete(),this.seekBreaker$=new V),this.seekInProgress=!0,isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKING).pipe(k(this.seekBreaker$),ct(1)).subscribe(s=>{this.onSeeking$.next({newTime:e,currentTime:this.getCurrentTime()})}),be(this.videoElement,We.SEEKED).pipe(k(this.seekBreaker$),ct(1)).subscribe(s=>{this.syncVideoFrames(t).subscribe(n=>{this.onSeeked$.next({currentTime:this.getCurrentTime()}),this.seekInProgress=!1,i.next(!0),i.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking to timestamp: ${e}`),this.setCurrentTime(e))})}_seekTimeFireAndForget(e){if(!isNaN(e)){let t=this.getCurrentTime();e=e<0?0:e>this.getDuration()?this.getDuration():e;let i=e>t?"FORWARD":"BACKWARD",s=Z.sub(t,e).abs();console.debug(`Seeking from currentTime[${t}] to newTime[${e}], direction: ${i} ${s.toNumber()}`),this.setCurrentTime(e)}}_seekTimeAndSyncNoEmitEvents(e){return this.isPlaying()?Ee(!1):new se(t=>{isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKED).pipe(hi()).subscribe(i=>{this.syncVideoFrames({}).subscribe(s=>{t.next(!0),t.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking ${e}`),this.setCurrentTime(e))})}seekFromCurrentTimeAndSync(e,t={}){let i=this.getCurrentTime(),s=Z.add(i,e).toNumber(),n=s>i?"FORWARD":"BACKWARD",a=Z.sub(i,s).abs().toNumber();return console.debug(`Seeking from currentTime ${i} to ${s}, direction: ${n} ${a}`),this.seekTimeAndSync(s,t)}setCurrentTime(e){this.videoElement.currentTime=e}getFrameRateDecimal(){return this.frameRateDecimal}_seekToFrame(e){if(!this.isPlaying()&&!isNaN(e)){if(console.debug(`Seeking to frame: ${e}`),e<=0)return this.seekTimeAndSync(0,{});{let t=this.calculateFrameToTime(e)+new Z(this.frameDurationSpillOverCorrection).toNumber(),i=this.calculateTimeToFrame(t);return i!==e?(console.error(`Frame numbers don't match. Wanted: ${e}, calculated: ${i}`),Ee(!1)):this.seekTimeAndSync(t,{seekToFrame:e,seekToTimestamp:t,currentTime:this.getCurrentTime()}).pipe(ke(s=>s))}}}_seekFromCurrentFrame(e){let t=this.getCurrentFrame(),i=t+e;if(console.debug(`seekFromCurrentFrame - Current frame: ${t}, wanted frame: ${i}`),t!==i){if(i<=0)return this._seekToFrame(0);if(i>=this.getTotalFrames())return this._seekToFrame(this.getTotalFrames());{let s=this.calculateFrameToTime(e);return this.seekFromCurrentTimeAndSync(s,{seekToFrame:i,currentTime:this.getCurrentTime()}).pipe(ke(n=>n))}}else return Ee(!0)}videoTimeChangeHandlerExecutor(){let e=this.getCurrentTime(),t=this.getCurrentFrame();this.onVideoTimeChange$.next({currentTime:e,frame:t})}getPlaybackState(){return this.playbackStateMachine.state}getVideo(){return this.isVideoLoaded()?this.video:void 0}getHTMLVideoElement(){return this.videoElement}calculateTimeToFrame(e){return qs.timeToFrame(e,this.getFrameRateDecimal())}calculateFrameToTime(e){return qs.frameToTime(e,this.getFrameRateDecimal())}play(){this.isVideoLoaded()&&!this.isPlaying()&&this.videoElement.play().then(()=>{this.onPlay$.next({})})}pause(){this.isVideoLoaded()&&this.isPlaying()&&this.videoElement.pause()}togglePlayPause(){this.isPlaying()?this.pause():this.play()}isPlaying(){return this.isVideoLoaded()&&this.videoElement.currentTime>0&&this.videoElement.currentTime<this.getDuration()&&!this.videoElement.paused&&!this.videoElement.ended&&this.videoElement.readyState>this.videoElement.HAVE_CURRENT_DATA}isPaused(){return!this.isPlaying()}isSeeking(){return this.seekInProgress}getCurrentTime(){return this.isVideoLoaded()?this.videoElement.currentTime:0}getPlaybackRate(){return this.isVideoLoaded()?this.videoElement.playbackRate:0}setPlaybackRate(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(.1).max(16).default(1).parse(e)}catch{e=1}this.videoElement.playbackRate=e}}getVolume(){return this.isVideoLoaded()?this.videoElement.volume:0}setVolume(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(0).max(1).default(1).parse(e)}catch{e=1}this.videoElement.volume=e}}getDuration(){return this.isVideoLoaded()?this.video.duration:0}getFrameRate(){return this.isVideoLoaded()?this.video.frameRate:0}getTotalFrames(){return this.isVideoLoaded()?this.video.totalFrames:0}getCurrentFrame(){return this.isVideoLoaded()?this.calculateTimeToFrame(this.getCurrentTime()):0}seekToFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getTotalFrames()).parse(e),this._seekToFrame(e)):Ee(!1)}seekFromCurrentFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this._seekFromCurrentFrame(e)):Ee(!1)}seekPreviousFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(-1):Ee(!1)}seekNextFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(1):Ee(!1)}seekToTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this.seekTimeAndSync(e)):Ee(!1)}formatTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getDuration()).parse(e),Ys.formatVideoTimestamp(e,this.getFrameRateDecimal())):Ys.VIDEO_ZERO_TIMESTAMP}mute(){this.isVideoLoaded()&&(this.videoElement.muted=!0)}unmute(){this.isVideoLoaded()&&(this.videoElement.muted=!1)}isFullscreen(){return this.isVideoLoaded()?this.domController.isFullscreen():!1}toggleFullscreen(){this.isVideoLoaded()&&this.domController.toggleFullscreen(this.videoElement)}getAudioTracks(){throw new Error("unsupported")}getCurrentAudioTrack(){throw new Error("unsupported")}setAudioTrack(e){throw new Error("unsupported")}isVideoLoaded(){return this._isVideoLoaded}getHls(){throw new Error("Unsupported or video not loaded with Hls.js")}addHelpMenuGroup(e){this.helpMenuGroups.push(e),this.onHelpMenuChange$.next()}getHelpMenuGroups(){return this.helpMenuGroups}destroy(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.onDestroy$&&(this.onDestroy$.next(),this.onDestroy$.complete()),this.videoElement=null,this.domController=null,this._isVideoLoaded=!1}}class Xm{constructor(e,t,i,s){this._element=e,this._sourceUrl=t,this._frameRate=i,this._duration=s,this._totalFrames=new Z(this._duration).mul(this._frameRate).toNumber(),this._frameDuration=new Z(1).div(this._frameRate).toNumber()}get element(){return this._element}get sourceUrl(){return this._sourceUrl}get frameRate(){return this._frameRate}get duration(){return this._duration}get totalFrames(){return this._totalFrames}get frameDuration(){return this._frameDuration}}class qm extends jm{constructor(e,t){super(e,t),ze.isSupported()?console.debug("video load with hls.js"):console.error("hls is not supported through MediaSource extensions");let i={...ze.DefaultConfig,enableWorker:!1};this.hls=new ze(i)}videoLoad(e,t,i){return new se(s=>{this.hls.on(ze.Events.ERROR,function(h,l){l.type;let d=l.details;l.fatal,d.includes("audioTrackLoadError")||(s.error(`Error loading video. Hls error details: ${d}`),s.complete())});let n=new se(h=>{this.hls.once(ze.Events.MEDIA_ATTACHED,function(l,d){console.debug("video element and hls.js are now bound together"),h.next(!0),h.complete()})}),a=new se(h=>{this.hls.once(ze.Events.MANIFEST_PARSED,function(l,d){console.debug("manifest loaded, found "+d.levels.length+" quality level"),h.next(!0),h.complete()})}),o=be(this.videoElement,We.LOADEDDATA).pipe(hi());Gu([n,a,o]).pipe(hi()).subscribe(h=>{i=i&&_e.coerce.number().parse(i),i=i||this.videoElement.duration;let l=new Xm(this.videoElement,e,t,i);s.next(l),s.complete()}),this.hls.loadSource(e),this.hls.attachMedia(this.videoElement)})}initEventHandlers(){super.initEventHandlers(),this.hls.on(ze.Events.ERROR,function(e,t){t.type,t.details,t.fatal,console.error(e,t),(t.details===ze.ErrorDetails.BUFFER_STALLED_ERROR||t.details===ze.ErrorDetails.BUFFER_APPEND_ERROR||t.details===ze.ErrorDetails.BUFFER_APPENDING_ERROR)&&(this.videoPlaybackStateHolder.buffering=!0)})}getAudioTracks(){return this.isVideoLoaded?this.hls.audioTracks:null}getCurrentAudioTrack(){return this.getAudioTracks()[this.hls.audioTrack]}setAudioTrack(e){if(!this.isVideoLoaded)return null;let t=this.hls.audioTrack;this.hls.audioTrack=e;let i=this.hls.audioTrack;i>=0&&t!==i&&this.onAudioSwitched$.next({audioTrack:this.getCurrentAudioTrack()})}getHls(){return this.hls}}class Ym{constructor(e){this.hidden=!0,this.id=e.id,this.src=e.src,this.default=e.default,this.label=e.label,this.language=e.language,this.cues=[]}}class Km extends Ym{constructor(e){super(e)}}class Sn{constructor(e){this.subtitlesTracks=new Map,this.onCreate$=new V,this.onRemove$=new V,this.onShow$=new V,this.onHide$=new V,this.videoController=e,this.videoController.onVideoLoaded$.pipe($e(t=>!!t)).subscribe(t=>{this.removeAllTracks()})}getDomTextTrack(e){let t=this.videoController.getHTMLVideoElement().textTracks.getTrackById(e.id);if(t.kind==="subtitles")return t}removeDomTextTrack(e){return this.getDomTextTrack(e)?(this.videoController.getHTMLVideoElement().querySelectorAll("track").forEach(i=>{i.getAttribute("id")===e.id&&i.parentElement.removeChild(i)}),!0):!1}static createHTMLTrackElement(e){let t=document.createElement("track");return t.kind="subtitles",t.id=e.id,t.label=e.label,t.srclang=e.language,t.src=e.src,t.default=e.default,t}createVttTrack(e){return this.videoController.isVideoLoaded?new se(t=>{let i=new Km({...e});this.subtitlesTracks.has(i.id)&&this.removeTrack(i.id),i.element=Sn.createHTMLTrackElement(i),be(i.element,"load").pipe(hi()).subscribe(n=>{this.subtitlesTracks.set(i.id,i),t.next(i),t.complete(),this.onCreate$.next({textTrack:i})}),this.videoController.getHTMLVideoElement().appendChild(i.element);let s=this.getDomTextTrack(i);s.mode="hidden"}):Ee(void 0)}getTracks(){if(this.videoController.isVideoLoaded)return[...this.subtitlesTracks.values()]}removeAllTracks(){this.videoController.isVideoLoaded&&this.subtitlesTracks.forEach((e,t)=>{this.removeTrack(e.id)})}removeTrack(e){if(!this.videoController.isVideoLoaded)return;let t=this.subtitlesTracks.get(e);t&&(this.subtitlesTracks.delete(e),this.removeDomTextTrack(t),this.onRemove$.next({}))}getCurrentTrack(){return this.currentTrack}showTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);if(i){for(let s=0;s<this.videoController.getHTMLVideoElement().textTracks.length;s++){let n=this.videoController.getHTMLVideoElement().textTracks[s];n.mode="hidden"}i.mode="showing",t.hidden=!1,this.currentTrack=t,this.onShow$.next({})}}}hideTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);i&&(i.mode="hidden",t.hidden=!0,this.onHide$.next({}))}}destroy(){this.removeAllTracks(),this.videoController=null,this.videoController=void 0}}var Ks={},Jm={get exports(){return Ks},set exports(r){Ks=r}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,l,d){this.fn=h,this.context=l,this.once=d||!1}function n(h,l,d,u,c){if(typeof d!="function")throw new TypeError("The listener must be a function");var p=new s(d,u||h,c),f=t?t+l:l;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],p]:h._events[f].push(p):(h._events[f]=p,h._eventsCount++),h}function a(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function o(){this._events=new i,this._eventsCount=0}o.prototype.eventNames=function(){var l=[],d,u;if(this._eventsCount===0)return l;for(u in d=this._events)e.call(d,u)&&l.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(d)):l},o.prototype.listeners=function(l){var d=t?t+l:l,u=this._events[d];if(!u)return[];if(u.fn)return[u.fn];for(var c=0,p=u.length,f=new Array(p);c<p;c++)f[c]=u[c].fn;return f},o.prototype.listenerCount=function(l){var d=t?t+l:l,u=this._events[d];return u?u.fn?1:u.length:0},o.prototype.emit=function(l,d,u,c,p,f){var m=t?t+l:l;if(!this._events[m])return!1;var v=this._events[m],_=arguments.length,w,b;if(v.fn){switch(v.once&&this.removeListener(l,v.fn,void 0,!0),_){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,d),!0;case 3:return v.fn.call(v.context,d,u),!0;case 4:return v.fn.call(v.context,d,u,c),!0;case 5:return v.fn.call(v.context,d,u,c,p),!0;case 6:return v.fn.call(v.context,d,u,c,p,f),!0}for(b=1,w=new Array(_-1);b<_;b++)w[b-1]=arguments[b];v.fn.apply(v.context,w)}else{var T=v.length,L;for(b=0;b<T;b++)switch(v[b].once&&this.removeListener(l,v[b].fn,void 0,!0),_){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,d);break;case 3:v[b].fn.call(v[b].context,d,u);break;case 4:v[b].fn.call(v[b].context,d,u,c);break;default:if(!w)for(L=1,w=new Array(_-1);L<_;L++)w[L-1]=arguments[L];v[b].fn.apply(v[b].context,w)}}return!0},o.prototype.on=function(l,d,u){return n(this,l,d,u,!1)},o.prototype.once=function(l,d,u){return n(this,l,d,u,!0)},o.prototype.removeListener=function(l,d,u,c){var p=t?t+l:l;if(!this._events[p])return this;if(!d)return a(this,p),this;var f=this._events[p];if(f.fn)f.fn===d&&(!c||f.once)&&(!u||f.context===u)&&a(this,p);else{for(var m=0,v=[],_=f.length;m<_;m++)(f[m].fn!==d||c&&!f[m].once||u&&f[m].context!==u)&&v.push(f[m]);v.length?this._events[p]=v.length===1?v[0]:v:a(this,p)}return this},o.prototype.removeAllListeners=function(l){var d;return l?(d=t?t+l:l,this._events[d]&&a(this,d)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=t,o.EventEmitter=o,r.exports=o})(Jm);const Qm={OMAKASE_SUBTITLES_HIDE:"omakaseSubtitlesHide",OMAKASE_TIMELINE_ZOOM:"omakaseTimelineZoom",OMAKASE_VIDEO_LOADED:"omakaseVideoLoaded",OMAKASE_VIDEO_PAUSE:"omakaseVideoPause",OMAKASE_VIDEO_PLAY:"omakaseVideoPlay",OMAKASE_VIDEO_SEEKED:"omakaseVideoSeeked",OMAKASE_VIDEO_SEEKING:"omakaseVideoSeeking",OMAKASE_VIDEO_BUFFERING:"omakaseVideoBuffering",OMAKASE_VIDEO_ENDED:"omakaseVideoEnded",OMAKASE_VIDEO_TIME_CHANGE:"omakaseVideoTimeChange",OMAKASE_VIDEO_AUDIO_SWITCHED:"omakaseVideoAudioSwitched",OMAKASE_AUDIO_SWITCHED:"omakaseAudioSwitched",OMAKASE_SUBTITLES_CREATE:"omakaseSubtitlesCreate",OMAKASE_SUBTITLES_REMOVE:"omakaseSubtitlesRemove",OMAKASE_SUBTITLES_SHOW:"omakaseSubtitlesShow",OMAKASE_TIMELINE_SCROLL:"omakaseTimelineScroll"};class eg{constructor(e){this.onAudioSwitched$=new V,this.videoController=e}getAudioTracks(){return this.videoController.getAudioTracks()}getCurrentAudioTrack(){return this.videoController.getCurrentAudioTrack()}setAudioTrack(e){let t=this.getCurrentAudioTrack();this.videoController.setAudioTrack(e);let i=this.getCurrentAudioTrack();t!==i&&this.onAudioSwitched$.next({audioTrack:i})}}class Ei{static isFullscreenEnabled(){const e=document;return e.fullscreenEnabled||e.webkitFullscreenEnabled||!!e.webkitCancelFullScreen||e.mozFullScreenEnabled||e.msFullscreenEnabled||!1}static isFullscreen(){const e=document;return!!(e.fullscreenElement||e.webkitFullscreenElement||e.webkitCurrentFullScreenElement||e.mozFullScreenElement||e.msFullscreenElement)}static requestFullscreen(e,t){const i=e??document.documentElement,s=i.requestFullscreen||i.webkitRequestFullscreen||i.webkitRequestFullScreen||i.mozRequestFullScreen||i.msRequestFullscreen;if(!s)throw new Error("Unsupported");return s.call(i,t)}static exitFullscreen(){const e=document,t=e.exitFullscreen||e.webkitExitFullscreen||e.webkitCancelFullScreen||e.mozCancelFullScreen||e.msExitFullscreen;if(!t)throw new Error("Unsupported");return t.call(e)}}const fe={player:"omakase-player",playerWrapper:"omakase-player-wrapper",video:"omakase-video",videoControls:"omakase-video-controls",buttonPlay:"omakase-button-play",buttonPause:"omakase-button-pause",buttonLoading:"omakase-button-loading",buttonError:"omakase-button-error",buttonReplay:"omakase-button-replay",buttonHelp:"omakase-help-button",help:"omakase-help",helpMenu:"omakase-help-menu",errorMessage:"omakase-error-message"};class tg{constructor(e){this._playerHTMLElementId=e,this.divPlayer=this.getElementById(this._playerHTMLElementId),this.createDom()}createDom(){this.divPlayer.classList.add(`${fe.player}`),this.divPlayer.innerHTML=`<div class="${fe.playerWrapper}">
47
+ `)}function Ca(r){const e=(r%1).toFixed(3);r=Math.round(r-e);const t=Math.floor(r/3600),i=Math.floor((r-t*3600)/60),s=r-t*3600-i*60;return`${`${gr(t,2)}:`}${gr(i,2)}:${gr(s,2)}.${gr(e*1e3,3)}`}var wm={hlsSegment:mm,hlsSegmentPlaylist:gm};const Sm=Pl.parse,Tm=dm.compile,Cm=Ol.segment,Em=wm;var km={parse:Sm,compile:Tm,segment:Cm,hls:Em};class bn{constructor(e,t){this.cues=new Map,this.cuesKeysSorted=[],this.url=e,this.axiosConfig=t}fetch(){return Ki(Qp(this.getUrl(),this.axiosConfig)).pipe(ke(e=>{let t=e.data;try{return km.parse(t,{strict:!0,meta:!0}).cues.forEach(s=>{let n=this.mapCue(s);this.cues.set(n.startTime,n),this.cuesKeysSorted.push(n.startTime)}),this.cuesKeysSorted.sort((s,n)=>s-n),!0}catch(i){return console.error(i),!1}}))}getUrl(){return this.url}hasCues(){return this.cues&&this.cues.size>0}findCue(e){let t=this.findCues(e,e);if(t&&t.length===1)return t[0]}findCues(e,t){let i=this.findCueIndex(e),s=this.findCueIndex(t);return s===-1?[]:this.cuesKeysSorted.slice(i,s+1).map(n=>this.cues.get(n))}getCues(){return[...this.cues.values()]}findCueIndex(e){let t=0,i=this.cuesKeysSorted.length-1;for(;t<=i;){const s=Math.floor((t+i)/2);if(this.cuesKeysSorted[s]===e)return s;this.cuesKeysSorted[s]<e?t=s+1:i=s-1}return i===-1&&(i=0),i}}class _n extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new _n(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text}}}const Ea={listening:!0,style:{height:20,fill:"rgba(255,73,145)",opacity:1,visible:!0}};class xm extends Je{constructor(e,t){super({...Ea,...e,style:{...Ea.style,...e.style}}),this.textTrackCue=this.config.textTrackCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening,this.subtitlesLane=t,this.subtitlesLane.onSettleLayout$.pipe(k(this.onDestroy$)).subscribe(()=>{let i=this.subtitlesLane.resolveItemHorizontalMeasurement(this.getTextTrackCue());this.setHorizontalMeasurement(i)})}createCanvasNode(){return this.group=new O.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new O.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),fill:this.style.fill,opacity:this.style.opacity,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.backgroundRect),this.group}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getHorizontalMeasurement(){return{x:this.x,width:this.width}}setHorizontalMeasurement(e){this.x=e.x,this.width=e.width,this.isInitialized()&&this.group.setAttrs({x:this.x,width:this.width}),this.onMeasurementsChange()}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}getTextTrackCue(){return this.textTrackCue}setTextTrackCue(e){this.textTrackCue=e}compareTo(e){return this.textTrackCue&&e&&this.getTextTrackCue().id===e.getTextTrackCue().id&&this.getTextTrackCue().startTime===e.getTextTrackCue().startTime&&this.getTextTrackCue().endTime===e.getTextTrackCue().endTime?0:-1}}const Pm={...Qi,height:40,paddingTop:0,paddingBottom:0,subtitlesLaneItemOpacity:.9,subtitlesLaneItemFill:"rgba(255,73,145)"};class Us extends er{constructor(e){super({...e,style:{...Pm,...e.style}}),this.subtitlesLaneItemsMap=new Map,this.onSettleLayout$=new V,this._subtitlesVttUrl=this.config.subtitlesVttUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.subtitlesLaneItemsGroup=new O.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.subtitlesLaneItemsGroup),this.timeline.addToTimecodedSubtitlesGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.subtitlesLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateSubtitles()}clearContent(){this.subtitlesVttFile=void 0,this.clearItems()}clearItems(){this.subtitlesLaneItemsMap.forEach(e=>e.destroy()),this.subtitlesLaneItemsMap.clear(),this.subtitlesLaneItemsGroup.destroyChildren()}createEntities(){if(!this.isVttLoaded())return;this.clearItems(),this.subtitlesVttFile.getCues().forEach(t=>{let i=this.resolveItemHorizontalMeasurement(t),s=new xm({...i,textTrackCue:t,style:{height:this.subtitlesLaneItemsGroup.height(),fill:this.style.subtitlesLaneItemFill,opacity:this.style.subtitlesLaneItemOpacity}},this);this.subtitlesLaneItemsMap.set(t.startTime,s),this.subtitlesLaneItemsGroup.add(s.initCanvasNode())})}resolveItemHorizontalMeasurement(e){let t=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.startTime)),i=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.endTime));return{x:t,width:i-t}}fetchAndCreateSubtitles(){this.fetchSubtitlesVttFile(this._subtitlesVttUrl).pipe(ct(1)).subscribe(e=>{this.subtitlesVttFile=e,this.createEntities()})}fetchSubtitlesVttFile(e){return e?_n.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.subtitlesVttFile}get subtitlesVttUrl(){return this._subtitlesVttUrl}set subtitlesVttUrl(e){this._subtitlesVttUrl=e,this.clearContent(),this.fetchAndCreateSubtitles()}}const Am={listening:!1,style:{...F.POSITION_TOP_LEFT,...F.DIMENSION_ZERO,stroke:"rgba(255,73,145)",strokeWidth:5,visible:!1}};class Zs extends Je{constructor(e){super(vi(e,Am)),this.onClick$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.listening=this.config.listening}createCanvasNode(){return this.group=new O.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new O.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),strokeWidth:this.style.strokeWidth,stroke:this.style.stroke}),this.group.add(this.backgroundRect),this.group}afterCanvasNodeInit(){this.group.on("click",e=>{this.onClick$.next({thumbnail:this})}),this.group.on("mouseover",e=>{this.onMouseOver$.next({thumbnail:this})}),this.group.on("mousemove",e=>{this.onMouseMove$.next({thumbnail:this})}),this.group.on("mouseout",e=>{this.onMouseOut$.next({thumbnail:this})}),this.group.on("mouseleave",e=>{this.onMouseLeave$.next({thumbnail:this})})}destroy(){super.destroy()}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setImage(e){this.image&&this.image.destroy(),this.image=e,this.style={width:e.width(),height:e.height()},this.group.setAttrs({...this.image.getSize()}),this.backgroundRect.setAttrs({...this.image.getSize()}),this.group.add(this.image)}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.isInitialized()&&this.group.position(e)}setVisibleAndX(e,t){this.style={visible:e,x:t},this.isInitialized()&&this.group.setAttrs({visible:e,x:t})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}setDimension(e){this.style={...e},this.isInitialized()&&this.group.size(e),this.onMeasurementsChange()}getRect(){return{...this.getPosition(),...this.getDimension()}}getThumbnailVttCue(){return this.thumbnailVttCue}setThumbnailVttCue(e){this.thumbnailVttCue=e}getImage(){return this.image}compareTo(e){return this.thumbnailVttCue&&e&&this.thumbnailVttCue.url===e.thumbnailVttCue.url?0:-1}}class ss extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new ss(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,url:this.resolveThumbnailUrl(e)}}resolveThumbnailUrl(e){return this.isUrlAbsolute(e.text)?e.text:this.createThumbnailUrlFromRelativeUrl(e.text)}createThumbnailUrlFromRelativeUrl(e){return this.url.lastIndexOf("/")>2?`${this.url.substring(0,this.url.lastIndexOf("/"))}/${e}`:e}isUrlAbsolute(e){return/^(http(s):\/\/.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(e)}}class dt{static createKonvaImage(e){return new se(t=>{O.Image.fromURL(e,i=>{t.next(i),t.complete()},i=>{console.error(i),t.error(i)})})}static createKonvaImageSizedByWidth(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:t,height:dt.calculateProportionalHeight(t,i)}),i)))}static createKonvaImageSizedByHeight(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:dt.calculateProportionalWidth(t,i),height:t}),i)))}static calculateProportionalHeight(e,t){return e*t.getAttrs().image.naturalHeight/t.getAttrs().image.naturalWidth}static calculateProportionalWidth(e,t){return e*t.getAttrs().image.naturalWidth/t.getAttrs().image.naturalHeight}}const Om={...Qi,thumbnailHeight:40,thumbnailStroke:"rgba(121,0,255,0.9)",thumbnailStrokeWidth:0,thumbnailHoverScale:1.5,thumbnailHoverStroke:"rgba(0,255,188,0.9)",thumbnailHoverStrokeWidth:5};class js extends er{constructor(e){super({...e,style:{...Om,...e.style}}),this.thumbnailsMap=new Map,this.thumbnailsVisibleSet=new Set,this.onSettleLayout$=new V,this.eventStreamBreaker$=new V,this.onClick$=new V,this._thumbnailVttUrl=this.config.thumbnailVttUrl,this._axiosConfig=this.config.axiosConfig}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.thumbnailsGroup=new O.Group({x:0,y:this.style.height/2-this.style.thumbnailHeight/2,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.thumbnailsGroup),this.timeline.addToTimecodedThumbnailsGroup(this.timecodedGroup),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.timeline.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.thumbnailsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateThumbnails(),this.onSettleLayout$.pipe(k(this.onDestroy$)).subscribe(()=>{this.hideThumbnailHover(),this.adjustThumbnails()}),this.onSettleLayout$.pipe(k(this.onDestroy$)).pipe(Io(100)).subscribe(()=>{this.createAndAdjustThumbnails()}),this.timecodedGroup.on("mouseout mouseleave",e=>{this.hideThumbnailHover()})}onMeasurementsChange(){super.onMeasurementsChange(),this.hideThumbnailHover(),this.createAndAdjustThumbnails()}destroy(){super.destroy(),this.timecodedGroup.destroy(),this.thumbnailHover.destroy(),this.fireEventStreamBreaker()}clearContent(){this.fireEventStreamBreaker(),this.thumbnailVttFile=void 0,this.clearItems()}clearItems(){this.thumbnailsMap.forEach(e=>e.destroy()),this.thumbnailsMap.clear(),this.thumbnailsVisibleSet.clear(),this.thumbnailsGroup.destroyChildren()}fireEventStreamBreaker(){this.eventStreamBreaker$&&(this.eventStreamBreaker$.next(),this.eventStreamBreaker$.complete()),this.eventStreamBreaker$=new V}createAndAdjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailVttFile.getCues().forEach(e=>{let t=this.timeline.timeToTimelinePosition(e.startTime),i=this.thumbnailsVisibleSet.has(e.startTime);if(this.timeline.constrainTimelinePosition(t)===t)if(this.thumbnailsMap.has(e.startTime)){let s=this.thumbnailsMap.get(e.startTime);s&&s.setVisibleAndX(i,t)}else i&&(this.thumbnailsMap.set(e.startTime,null),dt.createKonvaImageSizedByHeight(e.url,this.style.thumbnailHeight).subscribe(s=>{let n=this.thumbnailsVisibleSet.has(e.startTime),a=this.createThumbnail(e,s,n);this.thumbnailsMap.set(e.startTime,a),this.thumbnailsGroup.add(a.getCanvasNode())}))}))}adjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailsMap.forEach(e=>{if(e){let t=this.timeline.timeToTimelinePosition(e.getThumbnailVttCue().startTime),i=this.thumbnailsVisibleSet.has(e.getThumbnailVttCue().startTime);e.setVisibleAndX(i,t)}}))}resolveVisibleTimestamps(){let e;this.thumbnailVttFile.getCues().forEach(i=>{let s=this.timeline.timeToTimelinePosition(i.startTime);this.timeline.constrainTimelinePosition(s)===s&&((e?s>=e:!0)?(e=s+this.thumbnailWidth,this.thumbnailsVisibleSet.add(i.startTime)):this.thumbnailsVisibleSet.delete(i.startTime))})}createThumbnail(e,t,i){let s=this.timeline.timeToTimelinePosition(e.startTime),n=new Zs({listening:!0,style:{x:s,y:0,visible:i,stroke:this.style.thumbnailStroke,strokeWidth:this.style.thumbnailStrokeWidth}});return n.setThumbnailVttCue(e),n.initCanvasNode(),n.setImage(t),n.onClick$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.onClick$.next(a)}),n.onMouseOver$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseMove$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseOut$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n.onMouseLeave$.pipe(k(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n}showThumbnailHover(e){if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.compareTo(e)===0){let t=this.resolveThumbnailHoverPosition(e);this.thumbnailHover.setPosition(t),this.thumbnailHover.setVisible(!0)}else dt.createKonvaImageSizedByWidth(e.getThumbnailVttCue().url,e.getImage().width()*this.style.thumbnailHoverScale).subscribe(t=>{this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailHoverPosition(e)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.style.visible&&this.thumbnailHover.setVisible(!1)}resolveThumbnailHoverPosition(e){let t=this.timeline.getTimecodedGroupRect(),i=this.thumbnailHover.getImage().getSize(),s=e.getPosition().x+e.getDimension().width/2-i.width/2,n=e.style.strokeWidth>0?e.style.strokeWidth/2:0;s=s-n<0?n:s+i.width+n>t.width?t.width-i.width-n:s;let h=this.getRect().y+this.thumbnailsGroup.y()+e.getDimension().height/2-this.thumbnailHover.getDimension().height/2;return{x:s,y:h}}fetchAndCreateThumbnails(){this.fetchThumbnailVttFile(this._thumbnailVttUrl,this._axiosConfig,this.style.thumbnailHeight).pipe(ct(1)).subscribe(e=>{e&&(this.thumbnailVttFile=e.thumbnailVttFile,this.thumbnailWidth=e.thumbnailWidth,this.createAndAdjustThumbnails())})}fetchThumbnailVttFile(e,t,i){return e?ss.create(e,t).pipe(Yu(s=>{let n=s.getCues()[0];return dt.createKonvaImageSizedByHeight(n.url,i).pipe(ke(a=>{let o=a.getSize().width;return{thumbnailVttFile:s,thumbnailWidth:o}}))}),gi((s,n)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.thumbnailVttFile&&!!this.thumbnailWidth}getThumbnailVttFile(){return this.thumbnailVttFile}get thumbnailVttUrl(){return this._thumbnailVttUrl}set thumbnailVttUrl(e){this._thumbnailVttUrl=e,this.clearContent(),this.fetchAndCreateThumbnails()}}class wn extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new wn(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){let t=e.text.split(","),i=_e.coerce.number().min(-1).max(0).parse(t[0]),s=_e.coerce.number().min(0).max(1).parse(t[1]);return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,minSample:i,maxSample:s}}}const ka={listening:!1,style:{height:20,cornerRadius:20,opacity:1,visible:!0,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]}};class Mm extends Je{constructor(e){super({...ka,...e,style:{...ka.style,...e.style}}),this.audioVttCue=this.config.audioVttCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening}createCanvasNode(){this.group=new O.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening});let e=this.style.height/2,t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();return this.maxSampleBar=new O.Rect({x:0,width:this.group.width(),y:e-t,height:t,opacity:this.style.opacity,cornerRadius:[this.style.cornerRadius,this.style.cornerRadius,0,0],fillLinearGradientStartPoint:{x:0,y:-(e-t)},fillLinearGradientEndPoint:{x:0,y:t},fillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.minSampleBar=new O.Rect({x:0,width:this.group.width(),y:e,height:i,opacity:this.style.opacity,cornerRadius:[0,0,this.style.cornerRadius,this.style.cornerRadius],fillLinearGradientStartPoint:{x:0,y:0},fillLinearGradientEndPoint:{x:0,y:e},fillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.maxSampleBar),this.group.add(this.minSampleBar),this.group}resolveMaxSampleBarHeight(){return new Z(this.audioVttCue.maxSample).mul(this.style.height/2).toDecimalPlaces(2).toNumber()}resolveMinSampleBarHeight(){return new Z(this.audioVttCue.minSample).abs().mul(this.style.height/2).toDecimalPlaces(2).toNumber()}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getAudioVttCue(){return this.audioVttCue}setAudioVttCue(e){this.audioVttCue=e;let t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();this.minSampleBar.setAttrs({height:i}),this.maxSampleBar.setAttrs({y:this.style.height/2-t,height:t,fillLinearGradientStartPoint:{x:0,y:-(this.style.height/2-t)},fillLinearGradientEndPoint:{x:0,y:t}})}}const Lm={...Qi,height:40,paddingTop:0,paddingBottom:0,itemWidth:5,itemMinPadding:2,itemCornerRadius:5,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]};class Rl extends er{constructor(e){super({...e,style:{...Lm,...e.style}}),this.audioTrackLaneItemsMap=new Map,this.onSettleLayout$=new V,this._audioVttFileUrl=this.config.audioVttFileUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.audioTrackLaneItemsGroup=new O.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.audioTrackLaneItemsGroup),this.timeline.addToTimecodedAudioGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.audioTrackLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateAudioTrack(),this.onSettleLayout$.pipe(k(this.onDestroy$)).subscribe(()=>{this.settlePosition()}),Ou([this.onSettleLayout$,this.timeline.onScroll$]).pipe(k(this.onDestroy$),Io(100)).subscribe(()=>{this.settleAll()})}clearContent(){this.audioVttFile=void 0,this.clearItems()}clearItems(){this.audioTrackLaneItemsMap.forEach(e=>e.destroy()),this.audioTrackLaneItemsMap.clear(),this.audioTrackLaneItemsGroup.destroyChildren()}getVisibleCues(){let e=this.timeline.getVisibleTimeRange();return this.audioVttFile.findCues(e.start,e.end)}createEntities(){if(!this.isVttLoaded())return;this.clearItems();let e=this.getVisibleCues(),t=this.timeline.getTimecodedContainerDimension().width;this.numOfInterpolations=new Z(t+this.style.itemMinPadding).div(this.style.itemWidth+this.style.itemMinPadding).floor().toNumber(),this.itemPadding=new Z(t-this.numOfInterpolations*this.style.itemWidth).div(this.numOfInterpolations-1).toNumber();let i=this.resolveNumOfCuesPerInterpolation(e.length),s=this.resolveCuesInterpolations(e,i);for(let n=0;n<this.numOfInterpolations;n++){let a=s.get(n),o=this.resolveInterpolatedItemPosition(n),h=new Mm({x:o,width:this.style.itemWidth,audioVttCue:a,style:{cornerRadius:this.style.itemCornerRadius,height:this.audioTrackLaneItemsGroup.height(),visible:!0,maxSampleFillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,minSampleFillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops}});this.audioTrackLaneItemsMap.set(n,h),this.audioTrackLaneItemsGroup.add(h.initCanvasNode())}}resolveNumOfCuesPerInterpolation(e){return new Z(e).div(this.numOfInterpolations).floor().toNumber()}resolveCuesInterpolations(e,t){let i=e.length-t*this.numOfInterpolations,s=new Map,n=0;for(let a=0;a<this.numOfInterpolations;a++){let o=t+(a<i?1:0),h=n;n=h+o;let l=e.slice(h,n),d=e[h],u=e[n-1],c=0,p=0;l.forEach(m=>{c+=m.minSample,p+=m.maxSample});let f={id:`${a}`,text:"",minSample:new Z(c).div(o).toDecimalPlaces(3).toNumber(),maxSample:new Z(p).div(o).toDecimalPlaces(3).toNumber(),startTime:d.startTime,endTime:u.endTime};s.set(a,f)}return s}settleAll(){if(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1)return;let e=this.getVisibleCues(),t=this.resolveNumOfCuesPerInterpolation(e.length),i=this.resolveCuesInterpolations(e,t);for(let s=0;s<this.numOfInterpolations;s++){let n=i.get(s),a=this.audioTrackLaneItemsMap.get(s);a.setAudioVttCue(n),a.setPosition({x:this.resolveInterpolatedItemPosition(s)})}}resolveInterpolatedItemPosition(e){return Math.abs(this.timeline.getTimecodedGroupHorizontalMeasurement().x)+e*this.style.itemWidth+e*this.itemPadding}settlePosition(){if(!(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1))for(let e=0;e<this.numOfInterpolations;e++){let t=this.audioTrackLaneItemsMap.get(e),i=this.timeline.timeToTimelinePosition(t.getAudioVttCue().startTime);t.setPosition({x:i})}}fetchAndCreateAudioTrack(){this.fetchAudioTrackVttFile(this._audioVttFileUrl).pipe(ct(1)).subscribe(e=>{this.audioVttFile=e,this.createEntities()})}fetchAudioTrackVttFile(e){return e?wn.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.audioVttFile}get audioVttFileUrl(){return this._audioVttFileUrl}set audioVttFileUrl(e){this._audioVttFileUrl=e,this.clearContent(),this.fetchAndCreateAudioTrack()}}function Xs(r){if(r.from===r.to)return;let e=r.from<r.to,t=e?r.to-r.from:r.from-r.to,i=new O.Animation(s=>{let n=O.Easings.StrongEaseInOut(s.time,0,t,r.duration);if(n>=t)r.onUpdateHandler(s,r.to),i.stop(),r.onCompleteHandler&&(r.onCompleteHandler(s,r.to),i=null);else{let a=r.from+n*(e?1:-1);r.onUpdateHandler(s,a)}},r.layer);i.start()}const Rm={...F.POSITION_TOP_LEFT,width:0,zoomMax:1500,scrollStepNumberOfDivisions:10,style:{height:20,backgroundFill:"#000000",backgroundFillOpacity:.3,handleBarFill:"#01a6f0",handleBarOpacity:1,handleOpacity:1}};class Im extends Je{constructor(e){super(vi(e,Rm)),this.onScroll$=new V,this.onZoom$=new V,this.x=this.config.x,this.y=this.config.y,this.width=this.config.width,this.zoomMax=this.config.zoomMax,this.scrollStepNumberOfDivisions=this.config.scrollStepNumberOfDivisions}createCanvasNode(){return this.group=new O.Group({x:this.x,y:this.y,width:this.width,height:this.style.height}),this.background=new O.Rect({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup=new O.Group({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height}),this.handleBar=new O.Rect({...F.POSITION_TOP_LEFT,width:this.handleGroup.width(),height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity,draggable:!0}),this.leftZoomHandle=new O.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.rightZoomHandle=new O.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.handleGroup.add(this.background),this.handleGroup.add(this.handleBar),this.group.add(this.background),this.group.add(this.handleGroup),this.handleGroup.add(this.leftZoomHandle),this.handleGroup.add(this.rightZoomHandle),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(k(this.onDestroy$),$e(n=>!!n)).subscribe(n=>{this.onStyleChange()}),this.group.on("click",n=>{this.clickScrollTo(this.group.getRelativePointerPosition().x)}),this.handleBar.on("dragstart dragmove dragend",n=>{let a=this.handleBar.getPosition(),o=this.getConstrainedHandleBarX(a.x);this.handleBar.setAttrs({x:o,y:0}),this.syncLeftRightHandles(),this.handleBar.getRelativePointerPosition().x>=0&&this.handleBar.getRelativePointerPosition().x<=this.handleBar.width()&&this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})});let e={scaleX:1.5,scaleY:1.5,duration:.1},t={scaleX:1,scaleY:1,duration:.1};this.leftZoomHandle.on("mouseover",n=>{this.leftZoomHandle.to({...e}),et.cursor("ew-resize")}),this.leftZoomHandle.on("mouseout",n=>{this.leftZoomHandle.to({...t}),et.cursor("default")}),this.rightZoomHandle.on("mouseover",n=>{this.rightZoomHandle.to({...e}),et.cursor("ew-resize")}),this.rightZoomHandle.on("mouseout",n=>{this.rightZoomHandle.to({...t}),et.cursor("default")});let i=n=>{let a=n;return a<0?a=0:this.rightZoomHandle.x()-n<=this.minHandleBarWidth&&(a=this.rightZoomHandle.x()-this.minHandleBarWidth),a};this.leftZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.leftZoomHandle.getPosition(),o=i(a.x);this.leftZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({x:o,width:this.rightZoomHandle.x()-o}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})});let s=n=>{let a=n,o=this.group.width();return a>o?a=o:n-this.leftZoomHandle.x()<=this.minHandleBarWidth&&(a=this.leftZoomHandle.x()+this.minHandleBarWidth),a};this.rightZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.rightZoomHandle.getPosition(),o=s(a.x);this.rightZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({width:o-this.leftZoomHandle.x()}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})})}onMeasurementsChange(){this.group.width(this.width),this.background.width(this.group.width()),this.handleGroup.width(this.group.width()),this.minHandleBarWidth=this.calculateHandleBarWidthFromZoomRatioPercent(this.zoomMax)}onStyleChange(){this.group.setAttrs({height:this.style.height}),this.background.setAttrs({height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup.setAttrs({height:this.style.height}),this.handleBar.setAttrs({height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity}),this.leftZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity}),this.rightZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity})}getScrollHandleMaxX(){return this.group.width()-this.handleBar.width()}getConstrainedHandleBarX(e){let t=e;return t<0?t=0:t+this.handleBar.width()>this.group.width()&&(t=this.getScrollHandleMaxX()),t}clickScrollTo(e){let t=this.group.width()/this.scrollStepNumberOfDivisions;if(!(e>=this.handleBar.x()&&e<=this.handleBar.x()+this.handleBar.width())){let i=this.handleBar.x()>e,s=this.handleBar.x()+t*(i?-1:1);i?s=s<e?e:s:s=s+this.handleBar.width()>e?e-this.handleBar.width():s,this.scrollToEased(s)}}scrollTo(e){this.handleBar.x(this.getConstrainedHandleBarX(e)),this.syncLeftRightHandles(),this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})}scrollToEased(e){let t=this.handleBar.x(),i=this.getConstrainedHandleBarX(e);Xs({layer:this.handleGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:t,to:i,onUpdateHandler:(s,n)=>{this.scrollTo(n)}})}calculateHandleBarWidthFromZoomRatioPercent(e){return new Z(this.group.width()).mul(100).div(e).toNumber()}getZoomPercent(){return this.group.width()===this.handleBar.width()?100:new Z(this.group.width()).mul(100).div(this.handleBar.width()).toNumber()}getScrollHandlePercent(){return this.handleBar.x()===0?0:new Z(this.handleBar.x()).div(this.group.width()-this.handleBar.width()).mul(100).toNumber()}updateScrollHandle(e){let t=e.getScrollHandleHorizontalMeasurement(this.group.width());this.handleBar.setAttrs({...t}),this.syncLeftRightHandles()}syncLeftRightHandles(){this.leftZoomHandle.x(this.handleBar.x()),this.rightZoomHandle.x(this.handleBar.x()+this.handleBar.width())}setWidth(e){this.width=e,this.onMeasurementsChange()}setPosition(e){this.x=e.x,this.y=e.y,this.group.setAttrs({...e})}getPosition(){return this.group.getPosition()}getRect(){return{...this.group.getPosition(),...this.group.getSize()}}}const Nm={style:{...F.POSITION_TOP_LEFT,height:100,fill:"#737373",fillSnapped:"#ffd500",lineWidth:2,symbolY:0,symbolHeight:15,textFontSize:12,textFill:"#0d0f05",textSnappedFill:"#f43530",visible:!1}};class Gm extends Je{constructor(e,t){super(vi(e,Nm)),this.stylesProvider=lt.instance(),this.timeline=t}createCanvasNode(){return this.group=new O.Group({x:this.style.x,y:this.style.y,visible:this.style.visible,listening:!1}),this.line=new O.Line({points:[this.style.x,0,this.style.x,this.style.height],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.symbol=new O.Circle({y:this.style.symbolY,fill:this.style.fill,radius:this.style.symbolHeight/2,offsetY:-this.style.symbolHeight/2}),this.group.add(this.symbol),this.group.add(this.line),this.label=new O.Label({...F.POSITION_TOP_LEFT,listening:!1}),this.text=new O.Text({fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,...F.POSITION_TOP_LEFT,text:"",listening:!1}),this.label.y(-this.text.getSelfRect().height),this.label.add(this.text),this.group.add(this.label),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.onMeasurementsChange()}),this.stylesProvider.onChange$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})})}onMeasurementsChange(){this.line.points([this.line.x(),0,this.line.x(),this.style.height])}sync(e,t=!1){this.style.visible||this.toggleVisible(!0);let i=this.timeline.timelinePositionToTimeFormatted(e),s=this.text.getSelfRect(),n=s.width/2,a=-n,o=this.timeline.getTimecodedGroupHorizontalMeasurement();o.width-e<n?a=-s.width+(o.width-e):e<n&&(a=-n+(n-e)),this.group.x(e),this.text.text(i),this.label.x(a),t?(this.line.stroke(this.style.fillSnapped),this.text.fill(this.style.fillSnapped),this.symbol.visible(!1)):(this.line.stroke(this.style.fill),this.text.fill(this.style.fill),this.symbol.visible(!0))}toggleVisible(e){this.style={visible:e},this.group.visible(e)}}const Dm={style:{visible:!0,fill:"#f43530",lineWidth:2,symbolHeight:15,scrubberHeight:15,backgroundFill:"#ffffff",backgroundOpacity:0,playProgressFill:"#008cbc",playProgressOpacity:.5,bufferedFill:"#a2a2a2",bufferedOpacity:1}};class Fm extends Je{constructor(e,t,i){super(vi(e,Dm)),this.timeline=t,this.videoController=i}createCanvasNode(){return this.group=new O.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.background=new O.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.backgroundFill,opacity:this.style.backgroundOpacity,listening:!1}),this.playProgressBackground=new O.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.playProgressFill,opacity:this.style.playProgressOpacity,listening:!1}),this.playheadGroup=new O.Group({...F.POSITION_TOP_LEFT,visible:this.style.visible,listening:!1}),this.playheadLine=new O.Line({points:[0,0,0,0],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.playheadSymbol=yi.createTriangle({...F.POSITION_TOP_LEFT,height:this.style.symbolHeight,color:this.style.fill}),this.bufferedGroup=new O.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.group.add(this.background),this.group.add(this.bufferedGroup),this.group.add(this.playProgressBackground),this.playheadGroup.add(this.playheadLine),this.playheadGroup.add(this.playheadSymbol),this.group.add(this.playheadGroup),this.group}afterCanvasNodeInit(){this.settleLayout(),this.timeline.onZoom$.pipe(k(this.onDestroy$)).subscribe(e=>{this.settleLayout()}),this.videoController.onVideoLoading$.pipe(k(this.onDestroy$)).subscribe(e=>{this.group.visible(!1)}),this.videoController.onVideoLoaded$.pipe(k(this.onDestroy$)).subscribe(e=>{this.group.visible(!0),this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onVideoTimeChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.doPlayProgress()}),this.videoController.onSeeking$.pipe(k(this.onDestroy$)).subscribe(e=>{this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onBuffering$.pipe(k(this.onDestroy$)).subscribe(e=>{this.doBufferingProgress()})}onMeasurementsChange(){this.settleLayout()}getPlayheadPosition(){return this.playheadGroup.x()}settleLayout(){let e=this.timeline.getTimecodedGroupDimension();[this.group,this.bufferedGroup,this.playheadGroup].forEach(t=>{t.setAttrs({...e})}),[this.background].forEach(t=>{t.setAttrs({width:e.width})}),this.playheadLine.setAttrs({points:[0,0,0,e.height]}),this.doPlayProgress(),this.doBufferingProgress()}doPlayProgress(){let e=this.timeline.timeToTimelinePosition(this.videoController.getCurrentTime());this.playProgressBackground.width(e),this.playheadGroup.x(e)}doBufferingProgress(){let e=this.videoController.getBufferedTimespans();if(e&&e.length>0)if(this.bufferedGroup.hasChildren()){let t=e.length,i=this.bufferedGroup.getChildren().length;t===i?this.bufferedGroup.getChildren().forEach((s,n)=>{let a=e[n],o=this.timeline.timeToTimelinePosition(a.start),h=this.timeline.timeToTimelinePosition(a.end);s.setAttrs({x:o,width:h-o})}):(this.bufferedGroup.getChildren().forEach(s=>s.destroy()),this.createBuffers(e))}else this.createBuffers(e)}createBuffers(e){e.forEach(t=>{let i=this.timeline.timeToTimelinePosition(t.start),s=this.timeline.timeToTimelinePosition(t.end),n=new O.Rect({x:i,y:0,width:s-i,height:this.style.scrubberHeight,fill:this.style.bufferedFill,opacity:this.style.bufferedOpacity,listening:!1});this.bufferedGroup.add(n)})}}const Hm={style:{...F.POSITION_TOP_LEFT,width:150,height:20,textFontSize:20,textFill:"#0d0f05",visible:!0}};class Il extends Je{constructor(e,t){super(vi(e,Hm)),this.stylesProvider=lt.instance(),this.videoEventStreamBreaker$=new V,this.videoController=t}createCanvasNode(){return this.group=new O.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,listening:!1,visible:this.style.visible}),this.text=new O.Text({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.group.height(),text:"",fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,visible:!0,align:"left",verticalAlign:"middle"}),this.group.add(this.text),this.group}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.stylesProvider.onChange$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)})}onMeasurementsChange(){this.group.width(this.style.width)}fireVideoEventStreamBreaker(){this.videoEventStreamBreaker$&&(this.videoEventStreamBreaker$.next(),this.videoEventStreamBreaker$.complete()),this.videoEventStreamBreaker$=new V}onVideoLoadedEvent(e){this.fireVideoEventStreamBreaker(),this.text.text(this.videoController.formatTimestamp(0)),this.videoController.onVideoTimeChange$.pipe(k(this.videoEventStreamBreaker$)).subscribe(t=>{this.text.text(this.videoController.formatTimestamp(t.currentTime))})}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.group.setAttrs({...e}),this.onMeasurementsChange()}getRect(){return this.group.getClientRect()}}const Bm={...Qi,height:60,tickDivisor:5,tickDivisionMinWidth:18,tickFill:"#0d0f05",tickHeight:12,divisionTickFill:"#000000",divisionTickHeight:12*F.GOLDEN_RATIO,timecodeShowFirst:!0,timecodeFontSize:11,timecodeFill:"#0d0f05"};class $m extends er{constructor(e,t){super({...e,style:{...Bm,...e.style}}),this.onClick$=new V,this.onMouseEnter$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.videoController=t}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new O.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.ticksGroup=new O.Group({...F.POSITION_TOP_LEFT,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.ticksGroup),this.timeline.addToTimecodedBaseGroup(this.timecodedGroup),this.timecodeDisplay=new Il({style:{x:10,y:0,width:this.leftGroup.width(),height:this.getRect().height}},this.videoController),this.leftGroup.add(this.timecodeDisplay.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout();let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.ticksGroup].forEach(t=>{t.width(e.width)}),this.refreshTimeDivisions()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.timecodedEventCatcher.on("mousemove",e=>{this.onMouseMove$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseenter",e=>{this.onMouseEnter$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseout",e=>{this.onMouseOut$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseleave",e=>{this.onMouseLeave$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("click",e=>{this.onClick$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.videoController.onVideoLoading$.pipe(k(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe(k(this.onDestroy$)).subscribe(e=>{this.settleLayout()})}onStyleChange(){super.onStyleChange(),this.refreshTimeDivisions(!0)}destroy(){super.destroy(),this.timecodedGroup.destroy()}clearContent(){this.ticksGroup.destroyChildren()}refreshTimeDivisions(e=!1){if(!this.isTimelineReady())return;let t=this.style.tickDivisor,i=this.style.tickDivisionMinWidth,s=this.timeline.getTimecodedGroupRect().width,n=this.resolveTimeDivisionWidth(s,i,t,t),a=new Z(s).div(n).round().toNumber(),o=!e&&this.tickTotalDivisions===a&&!(this.ticksGroup.getChildren().length<1);o||this.clearContent(),this.tickDivisionWidth=n,this.tickTotalDivisions=a;let h=0,l=2,d=2,u=5;for(let c=0;c<this.tickTotalDivisions+1;c++){let p=c===0,f=c===this.tickTotalDivisions,m=c%t===0,v=c*this.tickDivisionWidth,_=m?this.style.divisionTickHeight:this.style.tickHeight,w=this.ticksGroup.height()-_,b=this.ticksGroup.height()-this.style.divisionTickHeight-u;if(o)this.ticksGroup.getChildren()[c].x(v);else{let T=new O.Group({x:v,y:h}),L=0,A=new O.Line({points:[L,w,L,w+_],stroke:this.style.tickFill,strokeWidth:1,listening:!1});T.add(A);let G=new O.Text({fontSize:this.style.timecodeFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.timecodeFill,text:`${this.timeline.timelinePositionToTimeFormatted(v)}`,listening:!1}),R=G.getSelfRect(),H=p?L+l:f?L-R.width-d:L-R.width/2,$=b-R.height;G.setAttrs({x:H,y:$});let I=m;I=p?this.style.timecodeShowFirst:I,I&&(T.add(G),T.x()+(G.x()>0?0:G.x()),T.y(),G.width()),this.ticksGroup.add(T)}}}resolveTimeDivisionWidth(e,t,i,s){return new Z(e).div(s).floor().greaterThan(t)?this.resolveTimeDivisionWidth(e,t,i,s*i):new Z(e).div(s/i).toNumber()}}const Vm={timelineHTMLElementId:"omakase-timeline",playheadHoverSnapArea:5,zoomScale:1.02,zoomBaseline:100,zoomMax:1500,style:{stageMinWidth:700,backgroundFill:"#f5f5f5",headerBackgroundFill:"#f5f5f5",footerBackgroundFill:"#f5f5f5",scrollbarHeight:15,thumbnailHoverWidth:200,thumbnailHoverStroke:"rgba(255,73,145,0.9)",thumbnailHoverStrokeWidth:5,thumbnailHoverYOffset:0,headerHeight:50,footerHeight:50,leftPanelWidth:200,rightPanelLeftGutterWidth:30,rightPanelRightGutterWidth:30,timecodedContainerClipPadding:20,playheadVisible:!0,playheadFill:"#f43530",playheadLineWidth:2,playheadSymbolHeight:15,playheadScrubberHeight:15,playheadBackgroundFill:"#ffffff",playheadBackgroundOpacity:0,playheadPlayProgressFill:"#008cbc",playheadPlayProgressOpacity:.5,playheadBufferedFill:"#a2a2a2",playheadBufferedOpacity:1}},xa="omakase_scrubber_lane";class zm extends Je{constructor(e,t){super(vi(e,Vm)),this.scrollWithPlayhead=!0,this.syncTimelineWithPlayheadInProgress=!1,this.mouseWheelEnabled=!1,this.leftPanelVisible=!0,this.videoEventBreaker$=new V,this.onScroll$=new V,this.onZoom$=new V,this.timelineHTMLElementId=this.config.timelineHTMLElementId,this.thumbnailVttUrl=this.config.thumbnailVttUrl,this.axiosConfig=this.config.axiosConfig,this.playheadHoverSnapArea=this.config.playheadHoverSnapArea,this.zoomScale=this.config.zoomScale,this.zoomBaseline=this.config.zoomBaseline,this.zoomMax=this.config.zoomMax,this.timecodedGroupNodes=[],this.timelaneLanes=[],this.timelaneLanesMap=new Map,this.timelineHTMLElement=document.getElementById(this.timelineHTMLElementId),this.videoController=t}createCanvasNode(){let e=this.resolveStageDimension();return this.width=e.width,this.stage=new O.Stage({container:this.timelineHTMLElementId,...e}),this.layer=new O.Layer,this.stage.add(this.layer),this.layoutGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.layer.add(this.layoutGroup),this.layoutBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:this.style.backgroundFill}),this.headerGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.headerBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:this.style.headerBackgroundFill}),this.footerGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.footerBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:this.style.footerBackgroundFill}),this.bodyGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.bodyContentGroup=new O.Group({...F.POSITION_TOP_LEFT}),this.leftPanel=new O.Group({...F.POSITION_TOP_LEFT}),this.rightPanel=new O.Group({...F.POSITION_TOP_LEFT}),this.timecodedContainer=new O.Group({...F.POSITION_TOP_LEFT}),this.timecodedGroup=new O.Group({...F.POSITION_TOP_LEFT,draggable:!0}),this.timecodedBaseGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedBaseGroup"}),this.timecodedThumbnailsGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedThumbnailsGroup"}),this.timecodedSubtitlesGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedSubtitlesGroup"}),this.timecodedAudioGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedAudioGroup"}),this.timecodedMarkersGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedMarkersGroup"}),this.timecodedSurfaceGroup=new O.Group({...F.POSITION_TOP_LEFT,name:"timecodedSurfaceGroup"}),this.timecodedBackground=new O.Rect({...F.POSITION_TOP_LEFT,fill:"yellow",opacity:0,listening:!1}),this.timecodedEventCatcher=yi.createEventCatcher(),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.layoutGroup.add(this.layoutBackground),this.layoutGroup.add(this.headerGroup),this.layoutGroup.add(this.footerGroup),this.layoutGroup.add(this.bodyGroup),this.headerGroup.add(this.headerBackground),this.footerGroup.add(this.footerBackground),this.bodyGroup.add(this.bodyContentGroup),this.bodyGroup.add(this.leftPanel),this.bodyGroup.add(this.rightPanel),this.rightPanel.add(this.timecodedContainer),this.timecodedContainer.add(this.timecodedGroup),[this.timecodedBackground,this.timecodedEventCatcher,this.timecodedBaseGroup,this.timecodedThumbnailsGroup,this.timecodedSubtitlesGroup,this.timecodedAudioGroup,this.timecodedMarkersGroup,this.timecodedSurfaceGroup].forEach(t=>{this.timecodedGroupNodes.push(t),this.timecodedGroup.add(t)}),this.scrollbar=new Im({style:{height:this.style.scrollbarHeight}}),this.rightPanel.add(this.scrollbar.initCanvasNode()),this.playhead=new Fm({style:{visible:this.style.playheadVisible,fill:this.style.playheadFill,lineWidth:this.style.playheadLineWidth,symbolHeight:this.style.playheadSymbolHeight,backgroundFill:this.style.playheadBackgroundFill,backgroundOpacity:this.style.playheadBackgroundOpacity,scrubberHeight:this.style.playheadScrubberHeight,playProgressFill:this.style.playheadPlayProgressFill,playProgressOpacity:this.style.playheadPlayProgressOpacity,bufferedFill:this.style.playheadBufferedFill,bufferedOpacity:this.style.playheadBufferedOpacity}},this,this.videoController),this.playheadHover=new Gm({},this),[this.playhead,this.playheadHover].forEach(t=>{this.addToTimecodedSurfaceGroup(t.initCanvasNode())}),this.headerTimecodeDisplay=new Il({style:{x:10,y:10,visible:!1}},this.videoController),this.headerGroup.add(this.headerTimecodeDisplay.initCanvasNode()),this.settleLayout(),this.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.scrubberLane=new $m({id:xa,description:""},this.videoController),this.addLanes([this.scrubberLane]),this.stage}afterCanvasNodeInit(){this.videoController.onVideoLoading$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),k(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)}),be(window,"resize").pipe(k(this.onDestroy$)).subscribe(e=>{setTimeout(()=>{this.onWindowResize(e)},200)}),this.timecodedGroup.on("mouseenter",e=>{this.playheadHover.toggleVisible(this.videoController.isVideoLoaded())}),this.timecodedGroup.on("mouseleave",e=>{this.playheadHover.toggleVisible(!1)}),this.timecodedGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedMarkersGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("wheel",e=>{if(!this.videoController.isVideoLoaded())return;if(this.mouseWheelEnabled){let i=e.evt;i.preventDefault();let s=i.deltaY>0?"IN":"OUT";i.ctrlKey&&(s=s==="IN"?"OUT":"IN"),this.zoomStep(s,this.timecodedGroup.getRelativePointerPosition().x),this.updateScrollWithPlayhead()}let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("dragstart dragmove dragend",e=>{if(!this.videoController.isVideoLoaded()){this.timecodedGroup.setAttrs({...F.POSITION_TOP_LEFT});return}if(e.target===this.timecodedGroup){let t=this.timecodedGroup.getPosition();this.timecodedGroup.setAttrs({x:this.getConstrainedTimelineX(t.x),y:0}),this.onScroll$.next(this.createScrollEvent()),this.scrollbar.updateScrollHandle(this)}this.updateScrollWithPlayhead()}),this.timecodedGroup.on("dragmove",e=>{et.cursor("grabbing")}),this.timecodedGroup.on("dragend",e=>{et.cursor("default")}),this.scrubberLane.onMouseMove$.pipe(k(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.mouseWheelEnabled=!0;let t=this.timecodedGroup.getRelativePointerPosition().x,i=this.timelinePositionToTime(t);if(this.thumbnailVttFile){let s=this.thumbnailVttFile.findCue(i);this.showThumbnailHover(s)}}),this.scrubberLane.onMouseEnter$.pipe(k(this.onDestroy$)).subscribe(e=>{this.mouseWheelEnabled=!0}),this.scrubberLane.onMouseLeave$.pipe(k(this.onDestroy$)).subscribe(e=>{this.hideThumbnailHover(),this.mouseWheelEnabled=!1}),this.scrubberLane.onClick$.pipe(k(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.updateScrollWithPlayhead();let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t),this.videoController.isVideoLoaded()&&this.videoController.seekToTimestamp(this.timelinePositionToTime(t)).subscribe(()=>{})}),this.scrollbar.onScroll$.pipe(k(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.updateScrollWithPlayhead(),this.onScroll$.next(this.createScrollEvent()))}),this.scrollbar.onZoom$.pipe(k(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.zoomByPercent(e.zoomPercent,!1),this.updateScrollWithPlayhead())}),this.thumbnailVttUrl&&this.fetchThumbnailVttFile().subscribe()}settleLayout(){this.stage.setAttrs({...this.resolveStageDimension()});let e=this.calculateHeights();this.headerGroup.setAttrs({width:this.width,height:this.style.headerHeight}),this.bodyGroup.setAttrs({y:this.headerGroup.y()+this.headerGroup.height(),width:this.layoutGroup.width(),height:e.bodyHeight}),this.footerGroup.setAttrs({y:this.bodyGroup.y()+this.bodyGroup.height(),width:this.width,height:this.style.footerHeight}),this.layoutGroup.setAttrs({width:this.width,height:e.layoutHeight}),this.layoutBackground.setAttrs({...this.layoutGroup.getSize()}),this.headerBackground.setAttrs({...this.headerGroup.getSize()}),this.footerBackground.setAttrs({...this.footerGroup.getSize()}),[this.bodyContentGroup].forEach(t=>{t.setAttrs({...this.bodyGroup.getSize()})}),[this.leftPanel,this.rightPanel].forEach(t=>{t.setAttrs({height:this.bodyGroup.getSize().height})}),this.leftPanel.setAttrs({width:this.leftPanelVisible?this.style.leftPanelWidth:0,visible:this.leftPanelVisible}),this.rightPanel.setAttrs({x:this.leftPanel.x()+this.leftPanel.width()+this.style.rightPanelLeftGutterWidth,width:this.layoutGroup.width()-(this.leftPanel.width()+this.style.rightPanelLeftGutterWidth+this.style.rightPanelRightGutterWidth)}),[this.timecodedContainer,this.timecodedGroup,...this.timecodedGroupNodes].forEach(t=>{t.setAttrs({...this.rightPanel.getSize()})}),this.timecodedContainer.clipFunc(t=>{t.rect(-this.style.timecodedContainerClipPadding,-500,this.timecodedContainer.width()+2*this.style.timecodedContainerClipPadding,this.timecodedContainer.height()+500)}),this.timecodedThumbnailsGroup.clipFunc(t=>{t.rect(0,0,this.timecodedThumbnailsGroup.width(),this.timecodedThumbnailsGroup.height())}),this.scrollbar.setPosition({...this.scrollbar.getPosition(),y:this.leftPanel.getSize().height}),this.scrollbar.setWidth(this.timecodedContainer.width()),this.scrollbar.updateScrollHandle(this),this.maxTimecodedGroupWidth=this.calculateWidthFromZoomRatioPercent(this.zoomMax),this.playheadHover.style={height:this.timecodedContainer.height()},this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.playhead.onMeasurementsChange()}onMeasurementsChange(){this.settleLayout();let e=this.getTimecodedGroupDimension();this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.zoomByWidth(e.width,this.resolveZoomFocus()),this.scrollbar.updateScrollHandle(this)}onWindowResize(e){let t=this.resolveStageDimension();this.width=t.width,this.onMeasurementsChange()}calculateHeights(){let t=this.getLanes().map(i=>i.getDimension().height).reduce((i,s)=>i+s,0);return{bodyHeight:t,layoutHeight:this.style.headerHeight+t+this.style.footerHeight}}resolveStageDimension(){let e=this.getTimelineHTMLElementRect(),t=this.calculateHeights();return{width:e.width>=this.style.stageMinWidth?e.width:this.style.stageMinWidth,height:t.layoutHeight}}getTimelineHTMLElementRect(){return{x:this.timelineHTMLElement.offsetLeft,y:this.timelineHTMLElement.offsetTop,width:this.timelineHTMLElement.offsetWidth,height:this.timelineHTMLElement.offsetHeight}}showThumbnailHover(e){if(e)if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.getThumbnailVttCue()===e){this.thumbnailHover.setThumbnailVttCue(e);let t=this.resolveThumbnailPosition(this.thumbnailHover);this.thumbnailHover.setPosition(t),this.thumbnailHover.getCanvasNode().moveToTop()}else dt.createKonvaImageSizedByWidth(e.url,this.style.thumbnailHoverWidth).subscribe(t=>{this.thumbnailHover.setThumbnailVttCue(e),this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailPosition(this.thumbnailHover)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.setVisible(!1)}resolveThumbnailPosition(e){let t=this.timecodedGroup.getRelativePointerPosition(),i=this.getTimecodedGroupDimension(),s=e.getImage().getSize(),n=t.x-s.width/2,a=e.style.strokeWidth>0?e.style.strokeWidth/2:0;n=n-a<0?a:n+s.width+a>i.width?i.width-s.width-a:n;let h=this.scrubberLane.getRect();return{x:n,y:h.y+h.height+e.style.strokeWidth/2+this.style.thumbnailHoverYOffset}}createScrollEvent(){return{scrollPercent:this.getHorizontalScrollPercent()}}createZoomEvent(){return{zoomPercent:this.getZoomPercent()}}getHorizontalScrollPercent(){if(this.isSnappedStart())return 0;if(this.isSnappedEnd())return 100;{let e=new Z(this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width).abs();return new Z(this.getTimecodedGroupPosition().x).abs().mul(100).div(e).toNumber()}}setHorizontalScrollPercent(e){this.setTimelinePosition(this.calculateTimelineXFromScrollPercent(e))}getScrollHandleHorizontalMeasurement(e){let t=this.getTimecodedGroupDimension().width,i=this.getTimecodedGroupPosition().x,s;return t<=e?s={width:e,x:0}:s={width:new Z(e).mul(e).div(t).round().toNumber(),x:new Z(i).abs().mul(e).div(t).toNumber()},s}scrollTo(e){return e=_e.coerce.number().min(0).max(100).parse(e),this.scrollToPercentEased(e)}scrollToPlayhead(){let e=-this.playhead.getPlayheadPosition()+this.getTimecodedContainerDimension().width/2;return this.scrollToEased(e)}scrollToPercent(e){let t=this.calculateTimelineXFromScrollPercent(e);this.scrollTimeline(t)}scrollToPercentEased(e){let t=this.calculateTimelineXFromScrollPercent(e);return this.scrollToEased(t)}scrollToEased(e){return new se(t=>{let i=this.getTimecodedGroupPosition().x;Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:i,to:e,onUpdateHandler:(s,n)=>{this.scrollTimeline(n)},onCompleteHandler:(s,n)=>{t.next(this.getHorizontalScrollPercent()),t.complete()}})})}isPlayheadInTimecodedView(){return this.isInVisiblePositionRange(this.playhead.getPlayheadPosition())}updateScrollWithPlayhead(){let e=this.playhead.getPlayheadPosition(),t=e<this.getVisiblePositionRange().start,i=this.isInVisiblePositionRange(e);this.scrollWithPlayhead=i&&!t}syncTimelineWithPlayhead(){return new se(e=>{this.scrollToEased(-this.playhead.getPlayheadPosition()).pipe(ke(t=>{e.next(this.getHorizontalScrollPercent()),e.complete()})).subscribe()})}setTimelinePosition(e){let t=this.getConstrainedTimelineX(e);this.timecodedGroup.x(t)}scrollTimeline(e){let t=this.getTimecodedGroupPosition().x;this.setTimelinePosition(e),this.getTimecodedGroupPosition().x!==t&&(this.scrollbar.updateScrollHandle(this),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onScroll$.next(this.createScrollEvent()))}calculateTimelineXFromScrollPercent(e){e=this.getConstrainedScrollPercent(e);let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width>i.width){let s=new Z(i.width-t.width);return new Z(e).mul(s).div(100).toDecimalPlaces(2).toNumber()}else return 0}getZoomPercent(){let e=this.getTimecodedGroupDimension(),t=this.getTimecodedContainerDimension();return e.width>t.width?new Z(e.width).mul(100).div(t.width).round().toNumber():this.zoomBaseline}zoomTo(e){return e=_e.coerce.number().min(this.getZoomBaseline()).max(this.getZoomMax()).parse(e),this.zoomToEased(e)}zoomIn(){return new se(e=>{this.zoomStep("IN",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomOut(){return new se(e=>{this.zoomStep("OUT",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomToEased(e){return new se(t=>{e=this.getConstrainedZoomPercent(e);let i=this.getTimecodedGroupDimension().width,s=this.calculateWidthFromZoomRatioPercent(e);Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_ZOOM_EASED_DURATION_MS,from:i,to:s,onUpdateHandler:(n,a)=>{this.zoomByWidth(a,this.resolveZoomFocus())},onCompleteHandler:(n,a)=>{t.next(this.getZoomPercent()),t.complete()}})})}zoomStep(e,t){let i=new Z(this.getTimecodedGroupDimension().width),s=(e==="IN"?i.mul(this.zoomScale):i.div(this.zoomScale)).round().toNumber();this.zoomByWidth(s,t)}zoomByPercent(e,t=!0){e=this.getConstrainedZoomPercent(e);let i=this.calculateWidthFromZoomRatioPercent(e);return this.zoomByWidth(i,this.resolveZoomFocus(),t),this.getZoomPercent()}zoomByWidth(e,t,i=!0){let s=this.getTimecodedGroupPosition().x,n=this.getTimecodedGroupDimension().width;e=this.getConstrainedWidth(e);let a=this.calculateNewPosition(e,t);this.hideThumbnailHover(),this.timecodedGroup.setAttrs({width:e,x:a}),this.timecodedGroupNodes.forEach(h=>{h.width(e)}),(this.getTimecodedGroupDimension().width!==n||this.getTimecodedGroupPosition().x!==s)&&(i?this.scrollbar.updateScrollHandle(this):this.playheadHover.toggleVisible(!1),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onZoom$.next(this.createZoomEvent()),this.onScroll$.next(this.createScrollEvent()))}calculateNewPosition(e,t=0){let i=this.getTimecodedGroupPosition().x,s=this.getTimecodedGroupDimension().width,n=this.getTimecodedContainerRect(),a=e>s?"IN":"OUT",o=i;if(e===n.width)o=0;else if(e>n.width){if(t>0){let h=new Z(t).div(s);if(h.greaterThanOrEqualTo(0)&&h.lessThanOrEqualTo(1)){let l=e-s,d=h.mul(l).abs().round().toNumber(),u=i+d*(a==="IN"?-1:1);o=u<0?u:0}}if(e>n.width){let h=n.x+n.width;o+e<=h&&(o=n.width-e)}}return o}resolveZoomFocus(){return this.videoController.isVideoLoaded()?this.resolvePlayheadSyncPosition():this.isSnappedStart()?0:this.isSnappedEnd()?this.getTimecodedGroupDimension().width:this.getTimecodedGroupDimension().width/2}calculateWidthFromZoomRatioPercent(e){return new Z(this.getTimecodedContainerDimension().width).mul(e).div(100).round().toNumber()}getConstrainedWidth(e){let t=this.getTimecodedContainerDimension();return e>=t.width?e<=this.maxTimecodedGroupWidth?e:this.maxTimecodedGroupWidth:t.width}getConstrainedZoomPercent(e){return e<this.zoomBaseline?this.zoomBaseline:e>this.zoomMax?this.zoomMax:e}getConstrainedScrollPercent(e){return e<0?0:e>100?100:e}playheadHoverMove(e){if(this.videoController.isVideoLoaded()&&this.playheadHover){let t=!1;if(!this.videoController.isPlaying()){let i=this.resolvePlayheadSyncPosition();e>i-this.playheadHoverSnapArea&&e<i+this.playheadHoverSnapArea&&(e=i,t=!0)}this.playheadHover.sync(e,t)}}resolvePlayheadSyncPosition(){return this.timeToTimelinePosition(this.videoController.getCurrentTime())}onVideoLoadedEvent(e){this.fireVideoEventBreaker(),this.clearContent(),this.syncVideoMetadata(),this.videoController.onVideoTimeChange$.pipe(k(this.videoEventBreaker$)).subscribe(t=>{this.syncVideoMetadata()}),this.videoController.onPlay$.pipe(k(this.videoEventBreaker$)).subscribe(t=>{this.updateScrollWithPlayhead()})}fireVideoEventBreaker(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V}setThumbnailVttFile(e){this.thumbnailVttFile=e}syncVideoMetadata(){this.scrollWithPlayhead&&!this.isPlayheadInTimecodedView()&&!this.syncTimelineWithPlayheadInProgress&&(this.syncTimelineWithPlayheadInProgress=!0,this.syncTimelineWithPlayhead().subscribe(e=>{this.syncTimelineWithPlayheadInProgress=!1}))}addLane(e){if(this.timelaneLanesMap.has(e.getId()))throw new Error(`TimelineLane with id=${e.getId()} already exist`);let t=this.timelaneLanes.length<1,i={...F.POSITION_TOP_LEFT};t||(i.y=this.timelaneLanes.map(s=>s.getRect().height).reduce((s,n)=>s+n,0)),e.setTimeline(this),e.setVideoController(this.videoController),e.setTimelinePosition(i),e.initCanvasNode(),this.timelaneLanes.push(e),this.timelaneLanesMap.set(e.getId(),e),this.bodyContentGroup.add(e.getCanvasNode()),this.settleLayout()}removeLane(e){if(!this.timelaneLanesMap.has(e))throw new Error(`TimelineLane with id=${e} doesn't exist`);let t=this.timelaneLanesMap.get(e);this.timelaneLanes.splice(this.timelaneLanes.findIndex(s=>s.getId()===e),1),this.timelaneLanesMap.delete(e),t.clearContent(),t.destroy();let i={...F.POSITION_TOP_LEFT};this.timelaneLanes.forEach(s=>{s.setTimelinePosition({...i}),i.y=i.y+s.getRect().height}),this.timelaneLanes.forEach(s=>{s.onMeasurementsChange()}),this.settleLayout()}getScrollbar(){return this.scrollbar}addLanes(e){e.forEach(t=>this.addLane(t))}getLanes(){return[...this.timelaneLanesMap.values()]}getLane(e){return this.timelaneLanesMap.get(e)}getScrubberLane(){return this.getLane(xa)}getMarkerLane(e){let t=this.getLane(e);return t instanceof Bs?t:void 0}getThumbnailLane(e){let t=this.getLane(e);return t instanceof js?t:void 0}getSubtitlesLane(e){let t=this.getLane(e);return t instanceof Us?t:void 0}getAudioTrackLane(e){let t=this.getLane(e);return t instanceof Rl?t:void 0}createMarkerLane(e){let t=new Bs(e);return this.addLane(t),t}createThumbnailLane(e){let t=new js(e);return this.addLane(t),t}createSubtitlesLane(e){let t=new Us(e);return this.addLane(t),t}isTimelineReady(){return this.videoController.isVideoLoaded()}addToTimecodedBaseGroup(e){this.timecodedBaseGroup.add(e)}addToTimecodedSurfaceGroup(e){this.timecodedSurfaceGroup.add(e)}addToTimecodedMarkersGroup(e){this.timecodedMarkersGroup.add(e)}addToTimecodedThumbnailsGroup(e){this.timecodedThumbnailsGroup.add(e)}addToTimecodedSubtitlesGroup(e){this.timecodedSubtitlesGroup.add(e)}addToTimecodedAudioGroup(e){this.timecodedAudioGroup.add(e)}constrainTimelinePosition(e){let t=this.getTimecodedGroupDimension();return e<0?0:e>t.width?t.width:e}timelinePositionToTime(e){let t=this.constrainTimelinePosition(e);return this.videoController.isVideoLoaded()?new Z(t).mul(this.videoController.getDuration()).div(this.getTimecodedGroupDimension().width).toNumber():0}timelinePositionToTimeFormatted(e){return this.videoController.isVideoLoaded()?this.videoController.formatTimestamp(this.timelinePositionToTime(e)):""}timelinePositionToFrame(e){return this.videoController.isVideoLoaded()?this.videoController.calculateTimeToFrame(this.timelinePositionToTime(e)):0}timeToTimelinePosition(e){return new Z(e).mul(this.getTimecodedGroupDimension().width).div(this.videoController.getDuration()).toNumber()}getConstrainedTimelineX(e){let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width<=i.width)return 0;{let s=i.width-t.width;return e<s?s:e>0?0:e}}getBodyGroupRect(){return{...this.bodyGroup.getPosition(),...this.bodyGroup.getSize()}}getLeftPanelRect(){return{...this.leftPanel.getPosition(),...this.leftPanel.getSize()}}getLeftPanelVisible(){return this.leftPanelVisible}getRightPanelRect(){return{...this.rightPanel.getSize(),...this.rightPanel.getPosition()}}getTimecodedContainerDimension(){return this.timecodedContainer.getSize()}getTimecodedContainerPosition(){return this.timecodedContainer.getPosition()}getTimecodedContainerRect(){return{...this.getTimecodedContainerDimension(),...this.getTimecodedContainerPosition()}}getTimecodedGroupDimension(){return this.timecodedGroup.getSize()}getTimecodedGroupPosition(){return this.timecodedGroup.getPosition()}getTimecodedGroupRect(){return{...this.timecodedGroup.getPosition(),...this.timecodedGroup.getSize()}}getTimecodedGroupHorizontalMeasurement(){return{x:this.timecodedGroup.x(),width:this.timecodedGroup.width()}}getRelativePointerPosition(){return this.timecodedGroup.getRelativePointerPosition()}getLayoutGroupDimension(){return this.layoutGroup.getSize()}getLayoutGroupPosition(){return this.layoutGroup.getPosition()}getRect(){return{...this.getLayoutGroupDimension(),...this.getLayoutGroupPosition()}}getVisiblePositionRange(){let e=Math.abs(this.timecodedGroup.x()),t=e+this.timecodedContainer.width();return{start:e,end:t}}isInVisiblePositionRange(e){let t=this.getVisiblePositionRange();return e>=t.start&&e<=t.end}isSnappedStart(){return this.getTimecodedGroupPosition().x===0}isSnappedEnd(){return this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width===this.getTimecodedGroupPosition().x}getVisibleTimeRange(){let e=this.getVisiblePositionRange(),t=this.timelinePositionToTime(e.start),i=this.timelinePositionToTime(e.end);return{start:t,end:i}}getZoomBaseline(){return this.zoomBaseline}getZoomMax(){return this.zoomMax}fetchThumbnailVttFile(){return this.thumbnailVttUrl?ss.create(this.thumbnailVttUrl,this.axiosConfig).pipe(ke(e=>(this.thumbnailVttFile=e,e)),gi((e,t)=>Ee(void 0))):Ee(void 0)}toggleLeftPanelVisible(e){this.leftPanelVisible=e,this.leftPanel.visible(e),this.settleLayout(),this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.headerTimecodeDisplay.setVisible(!e)}clearContent(){this.setThumbnailVttFile(void 0),this.timelaneLanes.forEach(e=>{e.clearContent()}),this.zoomByPercent(this.zoomBaseline)}}class qs{static timeToFrame(e,t){return t.mul(e).floor().toNumber()}static frameToTime(e,t){return new Z(e).dividedBy(t).toNumber()}}function Wm(r){r.next(),r.complete()}class ti{constructor(){this.resolveUserAgent()}static instance(){return ti._instance||(ti._instance=new ti),ti._instance}resolveUserAgent(){this._userAgent=window.navigator&&window.navigator.userAgent||"",this._isAndroid=/Android/i.test(this._userAgent),this._isFirefox=/Firefox/i.test(this._userAgent),this._isEdge=/Edg/i.test(this._userAgent),this._isChromium=/Chrome/i.test(this._userAgent)||/CriOS/i.test(this._userAgent),this._isChrome=!this.isEdge&&this.isChromium,this._isSafari=/Safari/i.test(this._userAgent)&&!this.isChrome&&!this.isAndroid&&!this.isEdge}get isSafari(){return this._isSafari}get isFirefox(){return this._isFirefox}get isEdge(){return this._isEdge}get isChromium(){return this._isChromium}get isChrome(){return this._isChrome}get isAndroid(){return this._isAndroid}}const Qe=class{static formatVideoTimestamp(r,e){if(r<=0)return Qe.VIDEO_ZERO_TIMESTAMP;const t=Math.floor(r/3600),i=Math.floor(r%3600/60),s=Math.floor(r%60);let n=new Z(qs.timeToFrame(r,e)).mod(e).toNumber();return`${Qe.padZero(t)}:${Qe.padZero(i)}:${Qe.padZero(s)}:${Qe.padZero(n)}`}static padZero(r,e=2){return r.toString().padStart(e,"0")}};let Ys=Qe;Ys.VIDEO_ZERO_TIMESTAMP=`${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}`;class Um{constructor(){this._state={playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1},this.onChange$=new Qt(this._state)}updateState(e){let t={...this._state,...e},i=this.compare(this._state,t)===0;this._state=t,i||this.onChange$.next(this._state)}compare(e,t){return e.playing===t.playing&&e.paused===t.paused&&e.waiting===t.waiting&&e.seeking===t.seeking&&e.buffering===t.buffering&&e.ended===t.ended?0:-1}get state(){return this._state}setPlaying(){this.updateState({playing:!0,paused:!1,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setPaused(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setEnded(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!0})}set waiting(e){this.updateState({waiting:e})}set seeking(e){this.updateState({seeking:e})}set buffering(e){this.updateState({buffering:e})}}function Pa(r){let e;return typeof r=="string"?e=r:r instanceof it?(console.log(r),e=r.errors.map(t=>t.message).join(". ")):r instanceof Error?e=r.message:e="Unexpected error",e}function Zm(r){return{errorMap:(e,t)=>({message:r})}}const We={PAUSE:"pause",WAITING:"waiting",PLAYING:"playing",TIMEUPDATE:"timeupdate",SEEKING:"seeking",SEEKED:"seeked",LOADEDDATA:"loadeddata",LOADEDMETEDATA:"loadedmetadata",ENDED:"ended",PROGRESS:"progress"};class jm{constructor(e,t){if(this.browserProvider=ti.instance(),this.helpMenuGroups=[],this._isVideoLoaded=!1,this.frameDurationSpillOverCorrection=1e-6,this.syncLoopMaxIterations=20,this.seekInProgress=!1,this.videoStalledCheckIntervalMs=700,this.videoFrameCallback$=new Qt(null),this.videoEventBreaker$=new V,this.onDestroy$=new V,this.seekBreaker$=new V,this.onVideoLoaded$=new Qt(void 0),this.onVideoLoading$=new V,this.onPlay$=new V,this.onPause$=new V,this.onVideoTimeChange$=new V,this.onSeeking$=new V,this.onSeeked$=new V,this.onBuffering$=new V,this.onEnded$=new V,this.onAudioSwitched$=new V,this.onPlaybackState$=new V,this.onHelpMenuChange$=new Qt(void 0),this.onVideoError$=new V,this.domController=e,this.crossorigin=t,this.videoElement=this.domController.videoElement,this.videoElement.crossOrigin=this.crossorigin,!this.videoElement)throw new Error("VideoController element not set");this.videoFrameCallback$.pipe(k(this.onDestroy$)).subscribe(i=>{i&&(this.seekInProgress||(this.isPlaying()?this.videoTimeChangeHandlerExecutor():this.isPaused()))})}loadVideo(e,t,i){try{return e=ai.url()(e),t=_e.coerce.number().min(0).max(100).parse(t,Zm("Invalid frameRate")),this.onVideoLoading$.next({sourceUrl:e,frameRate:t}),this._isVideoLoaded=!1,this.video=void 0,this.detachVideoEventListeners(),this.videoLoad(e,t,i).pipe(ke(s=>(this.video=s,this.frameRateDecimal=new Z(this.video.frameRate),this.syncStepCurrentTimeMediaTime=new Z(this.video.frameDuration).div(10).toNumber(),this.playbackStateMachine=new Um,this.initEventHandlers(),this.startVideoFrameCallback(),this._isVideoLoaded=!0,this.onVideoLoaded$.next({video:this.video}),s)),gi((s,n)=>{let a=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:a}),Kn(()=>new Error(a))}))}catch(s){let n=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:n}),Kn(()=>new Error(n))}}initEventHandlers(){be(this.videoElement,We.PAUSE).pipe(k(this.videoEventBreaker$)).subscribe(e=>{if(this.browserProvider.isSafari){let t=this.getCurrentTime()+this.video.frameDuration;this._seekTimeAndSyncNoEmitEvents(t).subscribe(i=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}else this.syncVideoFrames({}).subscribe(t=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}),be(this.videoElement,We.WAITING).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.waiting=!0}),be(this.videoElement,We.PLAYING).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.PAUSE).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.TIMEUPDATE).pipe(k(this.videoEventBreaker$)).subscribe(e=>{}),be(this.videoElement,We.PROGRESS).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.onBuffering$.next({bufferedTimespans:this.getBufferedTimespans()})}),be(this.videoElement,We.ENDED).pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.onEnded$.next({})}),this.playbackStateMachine.onChange$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.onPlaybackState$.next(e)}),this.onPlay$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),this.onPause$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),this.onSeeking$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!0}),this.onSeeked$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!1}),this.onEnded$.pipe(k(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setEnded(),this.videoStalledCheckLastCurrentTime=void 0}),zu(this.videoStalledCheckIntervalMs).pipe(k(this.videoEventBreaker$)).subscribe(e=>{let t=this.getCurrentTime();if(!this.videoStalledCheckLastCurrentTime){this.videoStalledCheckLastCurrentTime=t;return}if(this.playbackStateMachine.state.playing){let i=this.videoStalledCheckIntervalMs*.8/1e3*this.getPlaybackRate(),s=this.videoStalledCheckLastCurrentTime+i,n=t<s;this.playbackStateMachine.waiting=n,this.videoStalledCheckLastCurrentTime=t}})}getBufferedTimespans(){if(!this.isVideoLoaded())return[];let e=[],t=this.videoElement.buffered;for(let i=0;i<t.length;i++)e.push({start:t.start(i),end:t.end(i)});return e}startVideoFrameCallback(){let e=()=>{this.videoFrameCallbackHandle=this.videoElement.requestVideoFrameCallback((i,s)=>{t({now:i,metadata:s})})},t=i=>{this.videoFrameCallback$.next(i),e()};e()}detachVideoEventListeners(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V,this.videoElement&&this.videoFrameCallbackHandle&&this.videoElement.cancelVideoFrameCallback(this.videoFrameCallbackHandle)}syncVideoFrames(e){return console.debug("syncFrames - START",e),new se(t=>{let i=new Qt(!1),s=new V,n=this.syncLoopMaxIterations;this.seekBreaker$.pipe(k(s)).subscribe(()=>{console.debug("%csyncFrames - seek breaker triggered","color: gray"),i.next(!0),a()});let a=()=>{Wm(s),t.next(),t.complete(),console.debug("%csyncFrames - END","color: gray")},o=h=>{i.pipe(ct(1)).subscribe(l=>{l?console.debug("%csyncFrames - seek skipped, breaker already triggered","color: gray"):this._seekTimeFireAndForget(h)})};if(this.isPlaying())console.debug("%csyncFrames - SKIPPED: video is playing","color: gray"),a();else{let h=u=>{let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(this.isPlaying())return console.debug("%csyncFrames - UNKNOWN: video is playing","color: gray"),!0;if(p===0)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === 0`,"color: green"),!0;if(e.seekToFrame){if(e.seekToFrame===p&&(p===m||!m))return console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),!0}else if(p===m||!m)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),!0;return!1},l,d=u=>{if(console.debug(`syncFrames.syncLoop - START (${this.syncLoopMaxIterations-n})`,{syncConditions:e,videoFrameCallbackData:u,dropped:this.videoElement.getVideoPlaybackQuality()}),this.isPlaying()){a();return}if(h(u)){a();return}let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(n--<=0){console.debug(`%csyncFrames - TOO MANY SYNCs, EXITING.. : currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}]`,"color: red"),a();return}if(console.debug(`syncFrames - currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}], `),e.seekToFrame)if(l||(l=c),e.seekToFrame===p)if(p===m||!m)console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),a();else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red");let v=Math.abs(p-m);console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange");let _=this.syncStepCurrentTimeMediaTime*(p>m?1:-1);o(Z.add(c,_).toNumber())}else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; syncConditions.seekToFrame[${e.seekToFrame}] !== currentTimeFrame[${p}] | seekToFrameTimeBaseline=${l}`,"color: red");let v=Math.abs(e.seekToFrame-p),_=v*this.video.frameDuration,b=(e.seekToFrame>=p?Z.add(l,_):Z.sub(l,_)).toNumber();l=b,console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange"),console.debug(`%csyncFrames - frameCorrectionTime: ${_}`,"color: orange"),console.debug(`%csyncFrames - seekTo: ${b}`,"color: orange"),o(b)}else p===m||!m?(console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),a()):(console.debug(`%csyncFrames - CORRECTION; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red"),p>m?o(Z.add(c,this.syncStepCurrentTimeMediaTime).toNumber()):o(f+this.syncStepCurrentTimeMediaTime));console.debug("syncFrames.syncLoop - END")};this.videoFrameCallback$.pipe(ju((e.seekToFrame,0)),k(s)).subscribe(u=>{console.debug("syncFrames.syncLoop - videoFrameCallback$ trigger",u),d(u)})}})}seekTimeAndSync(e,t={}){return new se(i=>{this.seekInProgress&&(this.seekBreaker$.next(),this.seekBreaker$.complete(),this.seekBreaker$=new V),this.seekInProgress=!0,isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKING).pipe(k(this.seekBreaker$),ct(1)).subscribe(s=>{this.onSeeking$.next({newTime:e,currentTime:this.getCurrentTime()})}),be(this.videoElement,We.SEEKED).pipe(k(this.seekBreaker$),ct(1)).subscribe(s=>{this.syncVideoFrames(t).subscribe(n=>{this.onSeeked$.next({currentTime:this.getCurrentTime()}),this.seekInProgress=!1,i.next(!0),i.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking to timestamp: ${e}`),this.setCurrentTime(e))})}_seekTimeFireAndForget(e){if(!isNaN(e)){let t=this.getCurrentTime();e=e<0?0:e>this.getDuration()?this.getDuration():e;let i=e>t?"FORWARD":"BACKWARD",s=Z.sub(t,e).abs();console.debug(`Seeking from currentTime[${t}] to newTime[${e}], direction: ${i} ${s.toNumber()}`),this.setCurrentTime(e)}}_seekTimeAndSyncNoEmitEvents(e){return this.isPlaying()?Ee(!1):new se(t=>{isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKED).pipe(hi()).subscribe(i=>{this.syncVideoFrames({}).subscribe(s=>{t.next(!0),t.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking ${e}`),this.setCurrentTime(e))})}seekFromCurrentTimeAndSync(e,t={}){let i=this.getCurrentTime(),s=Z.add(i,e).toNumber(),n=s>i?"FORWARD":"BACKWARD",a=Z.sub(i,s).abs().toNumber();return console.debug(`Seeking from currentTime ${i} to ${s}, direction: ${n} ${a}`),this.seekTimeAndSync(s,t)}setCurrentTime(e){this.videoElement.currentTime=e}getFrameRateDecimal(){return this.frameRateDecimal}_seekToFrame(e){if(!this.isPlaying()&&!isNaN(e)){if(console.debug(`Seeking to frame: ${e}`),e<=0)return this.seekTimeAndSync(0,{});{let t=this.calculateFrameToTime(e)+new Z(this.frameDurationSpillOverCorrection).toNumber(),i=this.calculateTimeToFrame(t);return i!==e?(console.error(`Frame numbers don't match. Wanted: ${e}, calculated: ${i}`),Ee(!1)):this.seekTimeAndSync(t,{seekToFrame:e,seekToTimestamp:t,currentTime:this.getCurrentTime()}).pipe(ke(s=>s))}}}_seekFromCurrentFrame(e){let t=this.getCurrentFrame(),i=t+e;if(console.debug(`seekFromCurrentFrame - Current frame: ${t}, wanted frame: ${i}`),t!==i){if(i<=0)return this._seekToFrame(0);if(i>=this.getTotalFrames())return this._seekToFrame(this.getTotalFrames());{let s=this.calculateFrameToTime(e);return this.seekFromCurrentTimeAndSync(s,{seekToFrame:i,currentTime:this.getCurrentTime()}).pipe(ke(n=>n))}}else return Ee(!0)}videoTimeChangeHandlerExecutor(){let e=this.getCurrentTime(),t=this.getCurrentFrame();this.onVideoTimeChange$.next({currentTime:e,frame:t})}getPlaybackState(){return this.playbackStateMachine.state}getVideo(){return this.isVideoLoaded()?this.video:void 0}getHTMLVideoElement(){return this.videoElement}calculateTimeToFrame(e){return qs.timeToFrame(e,this.getFrameRateDecimal())}calculateFrameToTime(e){return qs.frameToTime(e,this.getFrameRateDecimal())}play(){this.isVideoLoaded()&&!this.isPlaying()&&this.videoElement.play().then(()=>{this.onPlay$.next({})})}pause(){this.isVideoLoaded()&&this.isPlaying()&&this.videoElement.pause()}togglePlayPause(){this.isPlaying()?this.pause():this.play()}isPlaying(){return this.isVideoLoaded()&&this.videoElement.currentTime>0&&this.videoElement.currentTime<this.getDuration()&&!this.videoElement.paused&&!this.videoElement.ended&&this.videoElement.readyState>this.videoElement.HAVE_CURRENT_DATA}isPaused(){return!this.isPlaying()}isSeeking(){return this.seekInProgress}getCurrentTime(){return this.isVideoLoaded()?this.videoElement.currentTime:0}getPlaybackRate(){return this.isVideoLoaded()?this.videoElement.playbackRate:0}setPlaybackRate(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(.1).max(16).default(1).parse(e)}catch{e=1}this.videoElement.playbackRate=e}}getVolume(){return this.isVideoLoaded()?this.videoElement.volume:0}setVolume(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(0).max(1).default(1).parse(e)}catch{e=1}this.videoElement.volume=e}}getDuration(){return this.isVideoLoaded()?this.video.duration:0}getFrameRate(){return this.isVideoLoaded()?this.video.frameRate:0}getTotalFrames(){return this.isVideoLoaded()?this.video.totalFrames:0}getCurrentFrame(){return this.isVideoLoaded()?this.calculateTimeToFrame(this.getCurrentTime()):0}seekToFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getTotalFrames()).parse(e),this._seekToFrame(e)):Ee(!1)}seekFromCurrentFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this._seekFromCurrentFrame(e)):Ee(!1)}seekPreviousFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(-1):Ee(!1)}seekNextFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(1):Ee(!1)}seekToTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this.seekTimeAndSync(e)):Ee(!1)}formatTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getDuration()).parse(e),Ys.formatVideoTimestamp(e,this.getFrameRateDecimal())):Ys.VIDEO_ZERO_TIMESTAMP}mute(){this.isVideoLoaded()&&(this.videoElement.muted=!0)}unmute(){this.isVideoLoaded()&&(this.videoElement.muted=!1)}isFullscreen(){return this.isVideoLoaded()?this.domController.isFullscreen():!1}toggleFullscreen(){this.isVideoLoaded()&&this.domController.toggleFullscreen(this.videoElement)}getAudioTracks(){throw new Error("unsupported")}getCurrentAudioTrack(){throw new Error("unsupported")}setAudioTrack(e){throw new Error("unsupported")}isVideoLoaded(){return this._isVideoLoaded}getHls(){throw new Error("Unsupported or video not loaded with Hls.js")}addHelpMenuGroup(e){this.helpMenuGroups.push(e),this.onHelpMenuChange$.next()}getHelpMenuGroups(){return this.helpMenuGroups}destroy(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.onDestroy$&&(this.onDestroy$.next(),this.onDestroy$.complete()),this.videoElement=null,this.domController=null,this._isVideoLoaded=!1}}class Xm{constructor(e,t,i,s){this._element=e,this._sourceUrl=t,this._frameRate=i,this._duration=s,this._totalFrames=new Z(this._duration).mul(this._frameRate).toNumber(),this._frameDuration=new Z(1).div(this._frameRate).toNumber()}get element(){return this._element}get sourceUrl(){return this._sourceUrl}get frameRate(){return this._frameRate}get duration(){return this._duration}get totalFrames(){return this._totalFrames}get frameDuration(){return this._frameDuration}}class qm extends jm{constructor(e,t){super(e,t),ze.isSupported()?console.debug("video load with hls.js"):console.error("hls is not supported through MediaSource extensions");let i={...ze.DefaultConfig,enableWorker:!1};this.hls=new ze(i)}videoLoad(e,t,i){return new se(s=>{this.hls.on(ze.Events.ERROR,function(h,l){l.type;let d=l.details;l.fatal,d.includes("audioTrackLoadError")||(s.error(`Error loading video. Hls error details: ${d}`),s.complete())});let n=new se(h=>{this.hls.once(ze.Events.MEDIA_ATTACHED,function(l,d){console.debug("video element and hls.js are now bound together"),h.next(!0),h.complete()})}),a=new se(h=>{this.hls.once(ze.Events.MANIFEST_PARSED,function(l,d){console.debug("manifest loaded, found "+d.levels.length+" quality level"),h.next(!0),h.complete()})}),o=be(this.videoElement,We.LOADEDDATA).pipe(hi());Gu([n,a,o]).pipe(hi()).subscribe(h=>{i=i&&_e.coerce.number().parse(i),i=i||this.videoElement.duration;let l=new Xm(this.videoElement,e,t,i);s.next(l),s.complete()}),this.hls.loadSource(e),this.hls.attachMedia(this.videoElement)})}initEventHandlers(){super.initEventHandlers(),this.hls.on(ze.Events.ERROR,function(e,t){t.type,t.details,t.fatal,console.error(e,t),t.details===ze.ErrorDetails.BUFFER_STALLED_ERROR||t.details===ze.ErrorDetails.BUFFER_APPEND_ERROR||(t.details,ze.ErrorDetails.BUFFER_APPENDING_ERROR)})}getAudioTracks(){return this.isVideoLoaded?this.hls.audioTracks:null}getCurrentAudioTrack(){return this.getAudioTracks()[this.hls.audioTrack]}setAudioTrack(e){if(!this.isVideoLoaded)return null;let t=this.hls.audioTrack;this.hls.audioTrack=e;let i=this.hls.audioTrack;i>=0&&t!==i&&this.onAudioSwitched$.next({audioTrack:this.getCurrentAudioTrack()})}getHls(){return this.hls}}class Ym{constructor(e){this.hidden=!0,this.id=e.id,this.src=e.src,this.default=e.default,this.label=e.label,this.language=e.language,this.cues=[]}}class Km extends Ym{constructor(e){super(e)}}class Sn{constructor(e){this.subtitlesTracks=new Map,this.onCreate$=new V,this.onRemove$=new V,this.onShow$=new V,this.onHide$=new V,this.videoController=e,this.videoController.onVideoLoaded$.pipe($e(t=>!!t)).subscribe(t=>{this.removeAllTracks()})}getDomTextTrack(e){let t=this.videoController.getHTMLVideoElement().textTracks.getTrackById(e.id);if(t.kind==="subtitles")return t}removeDomTextTrack(e){return this.getDomTextTrack(e)?(this.videoController.getHTMLVideoElement().querySelectorAll("track").forEach(i=>{i.getAttribute("id")===e.id&&i.parentElement.removeChild(i)}),!0):!1}static createHTMLTrackElement(e){let t=document.createElement("track");return t.kind="subtitles",t.id=e.id,t.label=e.label,t.srclang=e.language,t.src=e.src,t.default=e.default,t}createVttTrack(e){return this.videoController.isVideoLoaded?new se(t=>{let i=new Km({...e});this.subtitlesTracks.has(i.id)&&this.removeTrack(i.id),i.element=Sn.createHTMLTrackElement(i),be(i.element,"load").pipe(hi()).subscribe(n=>{this.subtitlesTracks.set(i.id,i),t.next(i),t.complete(),this.onCreate$.next({textTrack:i})}),this.videoController.getHTMLVideoElement().appendChild(i.element);let s=this.getDomTextTrack(i);s.mode="hidden"}):Ee(void 0)}getTracks(){if(this.videoController.isVideoLoaded)return[...this.subtitlesTracks.values()]}removeAllTracks(){this.videoController.isVideoLoaded&&this.subtitlesTracks.forEach((e,t)=>{this.removeTrack(e.id)})}removeTrack(e){if(!this.videoController.isVideoLoaded)return;let t=this.subtitlesTracks.get(e);t&&(this.subtitlesTracks.delete(e),this.removeDomTextTrack(t),this.onRemove$.next({}))}getCurrentTrack(){return this.currentTrack}showTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);if(i){for(let s=0;s<this.videoController.getHTMLVideoElement().textTracks.length;s++){let n=this.videoController.getHTMLVideoElement().textTracks[s];n.mode="hidden"}i.mode="showing",t.hidden=!1,this.currentTrack=t,this.onShow$.next({})}}}hideTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);i&&(i.mode="hidden",t.hidden=!0,this.onHide$.next({}))}}destroy(){this.removeAllTracks(),this.videoController=null,this.videoController=void 0}}var Ks={},Jm={get exports(){return Ks},set exports(r){Ks=r}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,l,d){this.fn=h,this.context=l,this.once=d||!1}function n(h,l,d,u,c){if(typeof d!="function")throw new TypeError("The listener must be a function");var p=new s(d,u||h,c),f=t?t+l:l;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],p]:h._events[f].push(p):(h._events[f]=p,h._eventsCount++),h}function a(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function o(){this._events=new i,this._eventsCount=0}o.prototype.eventNames=function(){var l=[],d,u;if(this._eventsCount===0)return l;for(u in d=this._events)e.call(d,u)&&l.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(d)):l},o.prototype.listeners=function(l){var d=t?t+l:l,u=this._events[d];if(!u)return[];if(u.fn)return[u.fn];for(var c=0,p=u.length,f=new Array(p);c<p;c++)f[c]=u[c].fn;return f},o.prototype.listenerCount=function(l){var d=t?t+l:l,u=this._events[d];return u?u.fn?1:u.length:0},o.prototype.emit=function(l,d,u,c,p,f){var m=t?t+l:l;if(!this._events[m])return!1;var v=this._events[m],_=arguments.length,w,b;if(v.fn){switch(v.once&&this.removeListener(l,v.fn,void 0,!0),_){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,d),!0;case 3:return v.fn.call(v.context,d,u),!0;case 4:return v.fn.call(v.context,d,u,c),!0;case 5:return v.fn.call(v.context,d,u,c,p),!0;case 6:return v.fn.call(v.context,d,u,c,p,f),!0}for(b=1,w=new Array(_-1);b<_;b++)w[b-1]=arguments[b];v.fn.apply(v.context,w)}else{var T=v.length,L;for(b=0;b<T;b++)switch(v[b].once&&this.removeListener(l,v[b].fn,void 0,!0),_){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,d);break;case 3:v[b].fn.call(v[b].context,d,u);break;case 4:v[b].fn.call(v[b].context,d,u,c);break;default:if(!w)for(L=1,w=new Array(_-1);L<_;L++)w[L-1]=arguments[L];v[b].fn.apply(v[b].context,w)}}return!0},o.prototype.on=function(l,d,u){return n(this,l,d,u,!1)},o.prototype.once=function(l,d,u){return n(this,l,d,u,!0)},o.prototype.removeListener=function(l,d,u,c){var p=t?t+l:l;if(!this._events[p])return this;if(!d)return a(this,p),this;var f=this._events[p];if(f.fn)f.fn===d&&(!c||f.once)&&(!u||f.context===u)&&a(this,p);else{for(var m=0,v=[],_=f.length;m<_;m++)(f[m].fn!==d||c&&!f[m].once||u&&f[m].context!==u)&&v.push(f[m]);v.length?this._events[p]=v.length===1?v[0]:v:a(this,p)}return this},o.prototype.removeAllListeners=function(l){var d;return l?(d=t?t+l:l,this._events[d]&&a(this,d)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=t,o.EventEmitter=o,r.exports=o})(Jm);const Qm={OMAKASE_SUBTITLES_HIDE:"omakaseSubtitlesHide",OMAKASE_TIMELINE_ZOOM:"omakaseTimelineZoom",OMAKASE_VIDEO_LOADED:"omakaseVideoLoaded",OMAKASE_VIDEO_PAUSE:"omakaseVideoPause",OMAKASE_VIDEO_PLAY:"omakaseVideoPlay",OMAKASE_VIDEO_SEEKED:"omakaseVideoSeeked",OMAKASE_VIDEO_SEEKING:"omakaseVideoSeeking",OMAKASE_VIDEO_BUFFERING:"omakaseVideoBuffering",OMAKASE_VIDEO_ENDED:"omakaseVideoEnded",OMAKASE_VIDEO_TIME_CHANGE:"omakaseVideoTimeChange",OMAKASE_VIDEO_AUDIO_SWITCHED:"omakaseVideoAudioSwitched",OMAKASE_AUDIO_SWITCHED:"omakaseAudioSwitched",OMAKASE_SUBTITLES_CREATE:"omakaseSubtitlesCreate",OMAKASE_SUBTITLES_REMOVE:"omakaseSubtitlesRemove",OMAKASE_SUBTITLES_SHOW:"omakaseSubtitlesShow",OMAKASE_TIMELINE_SCROLL:"omakaseTimelineScroll"};class eg{constructor(e){this.onAudioSwitched$=new V,this.videoController=e}getAudioTracks(){return this.videoController.getAudioTracks()}getCurrentAudioTrack(){return this.videoController.getCurrentAudioTrack()}setAudioTrack(e){let t=this.getCurrentAudioTrack();this.videoController.setAudioTrack(e);let i=this.getCurrentAudioTrack();t!==i&&this.onAudioSwitched$.next({audioTrack:i})}}class Ei{static isFullscreenEnabled(){const e=document;return e.fullscreenEnabled||e.webkitFullscreenEnabled||!!e.webkitCancelFullScreen||e.mozFullScreenEnabled||e.msFullscreenEnabled||!1}static isFullscreen(){const e=document;return!!(e.fullscreenElement||e.webkitFullscreenElement||e.webkitCurrentFullScreenElement||e.mozFullScreenElement||e.msFullscreenElement)}static requestFullscreen(e,t){const i=e??document.documentElement,s=i.requestFullscreen||i.webkitRequestFullscreen||i.webkitRequestFullScreen||i.mozRequestFullScreen||i.msRequestFullscreen;if(!s)throw new Error("Unsupported");return s.call(i,t)}static exitFullscreen(){const e=document,t=e.exitFullscreen||e.webkitExitFullscreen||e.webkitCancelFullScreen||e.mozCancelFullScreen||e.msExitFullscreen;if(!t)throw new Error("Unsupported");return t.call(e)}}const fe={player:"omakase-player",playerWrapper:"omakase-player-wrapper",video:"omakase-video",videoControls:"omakase-video-controls",buttonPlay:"omakase-button-play",buttonPause:"omakase-button-pause",buttonLoading:"omakase-button-loading",buttonError:"omakase-button-error",buttonReplay:"omakase-button-replay",buttonHelp:"omakase-help-button",help:"omakase-help",helpMenu:"omakase-help-menu",errorMessage:"omakase-error-message"};class tg{constructor(e){this._playerHTMLElementId=e,this.divPlayer=this.getElementById(this._playerHTMLElementId),this.createDom()}createDom(){this.divPlayer.classList.add(`${fe.player}`),this.divPlayer.innerHTML=`<div class="${fe.playerWrapper}">
48
48
  <video class="${fe.video}"></video>
49
49
 
50
50
  <div class="${fe.help} d-none">
@@ -71,5 +71,5 @@ ${Ll(i)}`)}),e.join(`
71
71
  <span class="omakase-help-group-title">${t.name}</span>
72
72
  ${i}
73
73
  </div>
74
- `}).join("")):this.hideElements(this.divHelp)}isFullscreen(){return Ei.isFullscreenEnabled()?Ei.isFullscreen():!1}toggleFullscreen(e){try{Ei.isFullscreenEnabled()&&(this.isFullscreen()?Ei.exitFullscreen().then(()=>{}):Ei.requestFullscreen(e).then(()=>{}))}catch(t){console.trace(t)}}set videoController(e){this._videoController=e,this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V;let t=[this.divButtonPlay,this.divButtonPause,this.divButtonLoading,this.divButtonReplay,this.divButtonError],i=()=>{this.showTemporaryOnMouseMoveTimeoutId&&clearTimeout(this.showTemporaryOnMouseMoveTimeoutId)};be(this.divPlayerWrapper,"mousemove").pipe(k(this.videoEventBreaker$)).subscribe(s=>{if(this._videoController.isVideoLoaded()&&!(this._videoController.getPlaybackState().ended||this._videoController.getPlaybackState().waiting||this._videoController.getPlaybackState().seeking)){let n=this._videoController.isPlaying()?this.divButtonPause:this.divButtonPlay;i(),this.hideElements(this.divButtonPause,this.divButtonPlay).showElements(n,this.divButtonHelp),this.showTemporaryOnMouseMoveTimeoutId=setTimeout(()=>{this.hideElements(n),this.isShown(this.divHelpMenu)||this.hideElements(this.divButtonHelp,this.divHelpMenu)},1e3)}}),be(this.divPlayerWrapper,"mouseleave").pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(this.divButtonPlay,this.divButtonPause),this.hideElements(this.divButtonHelp,this.divHelpMenu)}),be(this.divPlayerWrapper,"click").pipe(k(this.videoEventBreaker$)).subscribe(s=>{(s.target===this._videoElement||s.target===this.divButtonPlay||s.target===this.divButtonPause||s.target===this.divButtonReplay||s.target===this.divButtonLoading)&&this._videoController.togglePlayPause()}),be(this._videoElement,"contextmenu").pipe(k(this.videoEventBreaker$)).subscribe(s=>{s.preventDefault()}),this._videoElement.controls=!1,this._videoController.onVideoLoading$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(...t).hideElements(this.divErrorMessage).showElements(this.divButtonLoading)}),this._videoController.onVideoLoaded$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(...t).hideElements(this.divErrorMessage),s||this.showElements(this.divButtonLoading)}),this._videoController.onPlaybackState$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{i(),s.waiting&&s.playing?this.hideElements(...t).hideElements(this.divErrorMessage).showElements(this.divButtonLoading):s.playing?(this.hideElements(...t).hideElements(this.divErrorMessage),s.seeking&&s.waiting&&this.showElements(this.divButtonLoading)):s.paused?(this.hideElements(...t).hideElements(this.divErrorMessage),s.seeking&&s.waiting?this.showElements(this.divButtonLoading):s.ended&&this.showElements(this.divButtonReplay)):s.seeking&&s.waiting&&this.hideElements(...t).hideElements(this.divErrorMessage).showElements(this.divButtonLoading)}),this._videoController.onVideoError$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(...t).showElements(this.divErrorMessage,this.divButtonError),this.divErrorMessage.innerHTML=s.message}),be(this.divButtonHelp,"click").pipe(k(this.videoEventBreaker$)).subscribe(s=>{s.target===this.divButtonHelp&&(this.isShown(this.divHelpMenu)?this.hideElements(this.divHelpMenu):this.showElements(this.divHelpMenu))}),this._videoController.onHelpMenuChange$.pipe(k(this.videoEventBreaker$)).subscribe(()=>{this.helpChangeHandler()})}set timeline(e){this._timeline=e}get videoElement(){return this._videoElement}destroy(){this._videoController=null,this._videoElement=null,this._timeline=null,this._timelineElement=null}}const Tn={fontFamily:"Arial"},Aa={playerHTMLElementId:"omakase-player",crossorigin:"anonymous",style:{...Tn}};class ig{constructor(e){this.stylesProvider=lt.instance(),this.eventEmitter=new Ks,this.onDestroy$=new V,this.config={...Aa,...e,style:{...Aa.style,...e.style}},this.styleAdapter=new Go({...Tn,...this.config.style}),this.stylesProvider.styles={omakasePlayerStyle:this.style},this.styleAdapter.onChange$.pipe(k(this.onDestroy$)).subscribe(t=>{this.stylesProvider.styles={omakasePlayerStyle:this.style}}),this.playerHTMLElementId=this.config.playerHTMLElementId,this.domController=new tg(this.playerHTMLElementId),this.videoController=new qm(this.domController,this.config.crossorigin),this.audioController=new eg(this.videoController),this.subtitlesController=new Sn(this.videoController),this.domController.videoController=this.videoController,this.bindEventHandlers()}loadVideo(e,t,i){return new se(s=>{this.videoController.loadVideo(e,t,i).pipe(hi()).subscribe({next:n=>{s.next(n),s.complete()},error:n=>{s.error(n),s.complete()}})})}createTimeline(e){return new se(t=>{let i=()=>{console.debug("Creating timeline"),this._timeline=new zm(e,this.videoController),this.domController.timeline=this.timeline,this._timeline.initCanvasNode(),this._timeline.onScroll$.pipe(k(this.onDestroy$)).subscribe(s=>{this.emit("omakaseTimelineScroll",s)}),this._timeline.onZoom$.pipe(k(this.onDestroy$)).subscribe(s=>{this.emit("omakaseTimelineZoom",s)})};this.timeline?(t.next(this._timeline),t.complete()):(console.debug("Timeline creation in progress, checking video load status.."),this.videoController.isVideoLoaded()?(console.debug("Video is already loaded"),i(),t.next(this._timeline),t.complete()):(console.debug("Waiting video to load.."),this.videoController.onVideoLoaded$.pipe($e(s=>!!s),hi()).subscribe(s=>{console.debug("Video just loaded"),i(),t.next(this._timeline),t.complete()})))})}bindEventHandlers(){this.videoController.onPlay$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoPlay",e)}),this.videoController.onPause$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoPause",e)}),this.videoController.onVideoLoaded$.pipe(k(this.onDestroy$),$e(e=>!!e)).subscribe(e=>{this.emit("omakaseVideoLoaded",e)}),this.videoController.onVideoTimeChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoTimeChange",e)}),this.videoController.onSeeking$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoSeeking",e)}),this.videoController.onSeeked$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoSeeked",e)}),this.videoController.onBuffering$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoBuffering",e)}),this.videoController.onEnded$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoEnded",e)}),this.videoController.onAudioSwitched$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoAudioSwitched",e)}),this.audioController.onAudioSwitched$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseAudioSwitched",e)}),this.subtitlesController.onCreate$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesCreate",e)}),this.subtitlesController.onRemove$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesRemove",e)}),this.subtitlesController.onShow$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesShow",e)}),this.subtitlesController.onHide$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesHide",e)})}emit(e,t){this.eventEmitter.emit(e,t)}off(e,t){this.eventEmitter.off(e,t)}on(e,t){this.eventEmitter.on(e,t)}listenerCount(e){this.eventEmitter.listenerCount(e)}listeners(e){return this.eventEmitter.listeners(e)}once(e,t){this.eventEmitter.once(e,t)}removeAllListeners(e){this.eventEmitter.removeAllListeners(e)}get style(){return this.styleAdapter.style}set style(e){this.styleAdapter.style=e}get timeline(){return this._timeline}get video(){return this.videoController}get audio(){return this.audioController}get subtitles(){return this.subtitlesController}get EVENTS(){return Qm}destroy(){this.onDestroy$&&(this.onDestroy$.next(),this.onDestroy$.complete()),this.timeline.getLanes().forEach(e=>{e!=null&&(e.clearContent(),e.destroy())}),this.timeline.destroy(),this.video.getHls().off(ze.Events.ERROR),this.video.getHls().destroy(),this.subtitlesController.destroy(),this.domController.destroy(),this.videoController.destroy()}}exports.AudioTrackLane=Rl;exports.MarkerLane=Bs;exports.MomentMarker=ol;exports.OMAKASE_PLAYER_STYLE_DEFAULT=Tn;exports.OmakasePlayer=ig;exports.PeriodMarker=al;exports.SubtitlesLane=Us;exports.ThumbnailLane=js;
74
+ `}).join("")):this.hideElements(this.divHelp)}isFullscreen(){return Ei.isFullscreenEnabled()?Ei.isFullscreen():!1}toggleFullscreen(e){try{Ei.isFullscreenEnabled()&&(this.isFullscreen()?Ei.exitFullscreen().then(()=>{}):Ei.requestFullscreen(e).then(()=>{}))}catch(t){console.trace(t)}}set videoController(e){this._videoController=e,this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V;let t=[this.divButtonPlay,this.divButtonPause,this.divButtonLoading,this.divButtonReplay,this.divButtonError],i=()=>{this.showTemporaryOnMouseMoveTimeoutId&&clearTimeout(this.showTemporaryOnMouseMoveTimeoutId)};be(this.divPlayerWrapper,"mousemove").pipe(k(this.videoEventBreaker$)).subscribe(s=>{if(this._videoController.isVideoLoaded()&&!(this._videoController.getPlaybackState().ended||this._videoController.getPlaybackState().waiting||this._videoController.getPlaybackState().seeking)){let n=this._videoController.isPlaying()?this.divButtonPause:this.divButtonPlay;i(),this.hideElements(this.divButtonPause,this.divButtonPlay).showElements(n,this.divButtonHelp),this.showTemporaryOnMouseMoveTimeoutId=setTimeout(()=>{this.hideElements(n),this.isShown(this.divHelpMenu)||this.hideElements(this.divButtonHelp,this.divHelpMenu)},1e3)}}),be(this.divPlayerWrapper,"mouseleave").pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(this.divButtonPlay,this.divButtonPause),this.hideElements(this.divButtonHelp,this.divHelpMenu)}),be(this.divPlayerWrapper,"click").pipe(k(this.videoEventBreaker$)).subscribe(s=>{(s.target===this._videoElement||s.target===this.divButtonPlay||s.target===this.divButtonPause||s.target===this.divButtonReplay||s.target===this.divButtonLoading)&&this._videoController.togglePlayPause()}),be(this._videoElement,"contextmenu").pipe(k(this.videoEventBreaker$)).subscribe(s=>{s.preventDefault()}),this._videoElement.controls=!1,this._videoController.onVideoLoading$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(...t).hideElements(this.divErrorMessage).showElements(this.divButtonLoading)}),this._videoController.onVideoLoaded$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(...t).hideElements(this.divErrorMessage),s||this.showElements(this.divButtonLoading)}),this._videoController.onPlaybackState$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{i(),s.waiting&&s.playing?this.hideElements(...t).hideElements(this.divErrorMessage).showElements(this.divButtonLoading):s.playing?(this.hideElements(...t).hideElements(this.divErrorMessage),s.seeking&&s.waiting&&this.showElements(this.divButtonLoading)):s.paused?(this.hideElements(...t).hideElements(this.divErrorMessage),s.seeking&&s.waiting?this.showElements(this.divButtonLoading):s.ended&&this.showElements(this.divButtonReplay)):s.seeking&&s.waiting&&this.hideElements(...t).hideElements(this.divErrorMessage).showElements(this.divButtonLoading)}),this._videoController.onVideoError$.pipe(k(this.videoEventBreaker$)).subscribe(s=>{this.hideElements(...t).showElements(this.divErrorMessage,this.divButtonError),this.divErrorMessage.innerHTML=s.message}),be(this.divButtonHelp,"click").pipe(k(this.videoEventBreaker$)).subscribe(s=>{s.target===this.divButtonHelp&&(this.isShown(this.divHelpMenu)?this.hideElements(this.divHelpMenu):this.showElements(this.divHelpMenu))}),this._videoController.onHelpMenuChange$.pipe(k(this.videoEventBreaker$)).subscribe(()=>{this.helpChangeHandler()})}set timeline(e){this._timeline=e}get videoElement(){return this._videoElement}destroy(){this._videoController=null,this._videoElement=null,this._timeline=null,this._timelineElement=null}}const Tn={fontFamily:"Arial"},Aa={playerHTMLElementId:"omakase-player",crossorigin:"anonymous",style:{...Tn}};class ig{constructor(e){this.stylesProvider=lt.instance(),this.eventEmitter=new Ks,this.onDestroy$=new V,this.config={...Aa,...e,style:{...Aa.style,...e.style}},this.styleAdapter=new Go({...Tn,...this.config.style}),this.stylesProvider.styles={omakasePlayerStyle:this.style},this.styleAdapter.onChange$.pipe(k(this.onDestroy$)).subscribe(t=>{this.stylesProvider.styles={omakasePlayerStyle:this.style}}),this.playerHTMLElementId=this.config.playerHTMLElementId,this.domController=new tg(this.playerHTMLElementId),this.videoController=new qm(this.domController,this.config.crossorigin),this.audioController=new eg(this.videoController),this.subtitlesController=new Sn(this.videoController),this.domController.videoController=this.videoController,this.bindEventHandlers()}loadVideo(e,t,i){return new se(s=>{this.videoController.loadVideo(e,t,i).pipe(hi()).subscribe({next:n=>{s.next(n),s.complete()},error:n=>{s.error(n),s.complete()}})})}createTimeline(e){return new se(t=>{let i=()=>{console.debug("Creating timeline"),this._timeline=new zm(e,this.videoController),this.domController.timeline=this.timeline,this._timeline.initCanvasNode(),this._timeline.onScroll$.pipe(k(this.onDestroy$)).subscribe(s=>{this.emit("omakaseTimelineScroll",s)}),this._timeline.onZoom$.pipe(k(this.onDestroy$)).subscribe(s=>{this.emit("omakaseTimelineZoom",s)})};this.timeline?(t.next(this._timeline),t.complete()):(console.debug("Timeline creation in progress, checking video load status.."),this.videoController.isVideoLoaded()?(console.debug("Video is already loaded"),i(),t.next(this._timeline),t.complete()):(console.debug("Waiting video to load.."),this.videoController.onVideoLoaded$.pipe($e(s=>!!s),hi()).subscribe(s=>{console.debug("Video just loaded"),i(),t.next(this._timeline),t.complete()})))})}bindEventHandlers(){this.videoController.onPlay$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoPlay",e)}),this.videoController.onPause$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoPause",e)}),this.videoController.onVideoLoaded$.pipe(k(this.onDestroy$),$e(e=>!!e)).subscribe(e=>{this.emit("omakaseVideoLoaded",e)}),this.videoController.onVideoTimeChange$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoTimeChange",e)}),this.videoController.onSeeking$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoSeeking",e)}),this.videoController.onSeeked$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoSeeked",e)}),this.videoController.onBuffering$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoBuffering",e)}),this.videoController.onEnded$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoEnded",e)}),this.videoController.onAudioSwitched$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseVideoAudioSwitched",e)}),this.audioController.onAudioSwitched$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseAudioSwitched",e)}),this.subtitlesController.onCreate$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesCreate",e)}),this.subtitlesController.onRemove$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesRemove",e)}),this.subtitlesController.onShow$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesShow",e)}),this.subtitlesController.onHide$.pipe(k(this.onDestroy$)).subscribe(e=>{this.emit("omakaseSubtitlesHide",e)})}emit(e,t){this.eventEmitter.emit(e,t)}off(e,t){this.eventEmitter.off(e,t)}on(e,t){this.eventEmitter.on(e,t)}listenerCount(e){this.eventEmitter.listenerCount(e)}listeners(e){return this.eventEmitter.listeners(e)}once(e,t){this.eventEmitter.once(e,t)}removeAllListeners(e){this.eventEmitter.removeAllListeners(e)}get style(){return this.styleAdapter.style}set style(e){this.styleAdapter.style=e}get timeline(){return this._timeline}get video(){return this.videoController}get audio(){return this.audioController}get subtitles(){return this.subtitlesController}get EVENTS(){return Qm}destroy(){var e,t;this.onDestroy$&&(this.onDestroy$.next(),this.onDestroy$.complete()),(e=this.timeline)!=null&&e.getLanes()&&this.timeline.getLanes().forEach(i=>{i!=null&&(i.clearContent(),i.destroy())}),this.timeline&&this.timeline.destroy(),(t=this.video)!=null&&t.getHls()&&(this.video.getHls().off(ze.Events.ERROR),this.video.getHls().destroy()),this.subtitlesController&&this.subtitlesController.destroy(),this.domController&&this.domController.destroy(),this.videoController&&this.videoController.destroy()}}exports.AudioTrackLane=Rl;exports.MarkerLane=Bs;exports.MomentMarker=ol;exports.OMAKASE_PLAYER_STYLE_DEFAULT=Tn;exports.OmakasePlayer=ig;exports.PeriodMarker=al;exports.SubtitlesLane=Us;exports.ThumbnailLane=js;
75
75
  //# sourceMappingURL=omakase-player.cjs.js.map