@vkontakte/videoplayer-core 2.0.139 → 2.0.140-dev.26e4b860.0

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.
package/es2018.cjs.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @vkontakte/videoplayer-core v2.0.139
3
- * Fri, 22 Aug 2025 14:38:31 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/2-0-139/doc/
2
+ * @vkontakte/videoplayer-core v2.0.140-dev.26e4b860.0
3
+ * Mon, 25 Aug 2025 17:43:24 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/2-0-140/doc/
5
5
  */
6
- "use strict";var Oy=Object.create;var Ra=Object.defineProperty;var Fy=Object.getOwnPropertyDescriptor;var Ny=Object.getOwnPropertyNames;var qy=Object.getPrototypeOf,Uy=Object.prototype.hasOwnProperty;var v=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Hy=(s,e)=>{for(var t in e)Ra(s,t,{get:e[t],enumerable:!0})},nd=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ny(e))!Uy.call(s,r)&&r!==t&&Ra(s,r,{get:()=>e[r],enumerable:!(i=Fy(e,r))||i.enumerable});return s};var G=(s,e,t)=>(t=s!=null?Oy(qy(s)):{},nd(e||!s||!s.__esModule?Ra(t,"default",{value:s,enumerable:!0}):t,s)),jy=s=>nd(Ra({},"__esModule",{value:!0}),s);var Ie=v((xo,od)=>{"use strict";var Ur=function(s){return s&&s.Math===Math&&s};od.exports=Ur(typeof globalThis=="object"&&globalThis)||Ur(typeof window=="object"&&window)||Ur(typeof self=="object"&&self)||Ur(typeof global=="object"&&global)||Ur(typeof xo=="object"&&xo)||function(){return this}()||Function("return this")()});var Re=v((B$,ud)=>{"use strict";ud.exports=function(s){try{return!!s()}catch(e){return!0}}});var Hr=v((V$,ld)=>{"use strict";var Qy=Re();ld.exports=!Qy(function(){var s=function(){}.bind();return typeof s!="function"||s.hasOwnProperty("prototype")})});var wo=v((_$,hd)=>{"use strict";var Wy=Hr(),pd=Function.prototype,cd=pd.apply,dd=pd.call;hd.exports=typeof Reflect=="object"&&Reflect.apply||(Wy?dd.bind(cd):function(){return dd.apply(cd,arguments)})});var ke=v((O$,bd)=>{"use strict";var fd=Hr(),md=Function.prototype,Ao=md.call,Gy=fd&&md.bind.bind(Ao,Ao);bd.exports=fd?Gy:function(s){return function(){return Ao.apply(s,arguments)}}});var Ii=v((F$,vd)=>{"use strict";var gd=ke(),zy=gd({}.toString),Yy=gd("".slice);vd.exports=function(s){return Yy(zy(s),8,-1)}});var Po=v((N$,Sd)=>{"use strict";var Ky=Ii(),Xy=ke();Sd.exports=function(s){if(Ky(s)==="Function")return Xy(s)}});var Ee=v((q$,yd)=>{"use strict";var Ro=typeof document=="object"&&document.all;yd.exports=typeof Ro=="undefined"&&Ro!==void 0?function(s){return typeof s=="function"||s===Ro}:function(s){return typeof s=="function"}});var Ze=v((U$,Td)=>{"use strict";var Jy=Re();Td.exports=!Jy(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var et=v((H$,Id)=>{"use strict";var Zy=Hr(),$a=Function.prototype.call;Id.exports=Zy?$a.bind($a):function(){return $a.apply($a,arguments)}});var ko=v(wd=>{"use strict";var Ed={}.propertyIsEnumerable,xd=Object.getOwnPropertyDescriptor,eT=xd&&!Ed.call({1:2},1);wd.f=eT?function(e){var t=xd(this,e);return!!t&&t.enumerable}:Ed});var jr=v((Q$,Ad)=>{"use strict";Ad.exports=function(s,e){return{enumerable:!(s&1),configurable:!(s&2),writable:!(s&4),value:e}}});var Rd=v((W$,Pd)=>{"use strict";var tT=ke(),iT=Re(),rT=Ii(),Lo=Object,sT=tT("".split);Pd.exports=iT(function(){return!Lo("z").propertyIsEnumerable(0)})?function(s){return rT(s)==="String"?sT(s,""):Lo(s)}:Lo});var Qr=v((G$,kd)=>{"use strict";kd.exports=function(s){return s==null}});var ri=v((z$,Ld)=>{"use strict";var aT=Qr(),nT=TypeError;Ld.exports=function(s){if(aT(s))throw new nT("Can't call method on "+s);return s}});var Ei=v((Y$,$d)=>{"use strict";var oT=Rd(),uT=ri();$d.exports=function(s){return oT(uT(s))}});var He=v((K$,Md)=>{"use strict";var lT=Ee();Md.exports=function(s){return typeof s=="object"?s!==null:lT(s)}});var xi=v((X$,Dd)=>{"use strict";Dd.exports={}});var Ot=v((J$,Bd)=>{"use strict";var $o=xi(),Mo=Ie(),cT=Ee(),Cd=function(s){return cT(s)?s:void 0};Bd.exports=function(s,e){return arguments.length<2?Cd($o[s])||Cd(Mo[s]):$o[s]&&$o[s][e]||Mo[s]&&Mo[s][e]}});var Wr=v((Z$,Vd)=>{"use strict";var dT=ke();Vd.exports=dT({}.isPrototypeOf)});var wi=v((eM,Fd)=>{"use strict";var pT=Ie(),_d=pT.navigator,Od=_d&&_d.userAgent;Fd.exports=Od?String(Od):""});var Co=v((tM,Qd)=>{"use strict";var jd=Ie(),Do=wi(),Nd=jd.process,qd=jd.Deno,Ud=Nd&&Nd.versions||qd&&qd.version,Hd=Ud&&Ud.v8,bt,Ma;Hd&&(bt=Hd.split("."),Ma=bt[0]>0&&bt[0]<4?1:+(bt[0]+bt[1]));!Ma&&Do&&(bt=Do.match(/Edge\/(\d+)/),(!bt||bt[1]>=74)&&(bt=Do.match(/Chrome\/(\d+)/),bt&&(Ma=+bt[1])));Qd.exports=Ma});var Bo=v((iM,Gd)=>{"use strict";var Wd=Co(),hT=Re(),fT=Ie(),mT=fT.String;Gd.exports=!!Object.getOwnPropertySymbols&&!hT(function(){var s=Symbol("symbol detection");return!mT(s)||!(Object(s)instanceof Symbol)||!Symbol.sham&&Wd&&Wd<41})});var Vo=v((rM,zd)=>{"use strict";var bT=Bo();zd.exports=bT&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var _o=v((sM,Yd)=>{"use strict";var gT=Ot(),vT=Ee(),ST=Wr(),yT=Vo(),TT=Object;Yd.exports=yT?function(s){return typeof s=="symbol"}:function(s){var e=gT("Symbol");return vT(e)&&ST(e.prototype,TT(s))}});var Gr=v((aM,Kd)=>{"use strict";var IT=String;Kd.exports=function(s){try{return IT(s)}catch(e){return"Object"}}});var At=v((nM,Xd)=>{"use strict";var ET=Ee(),xT=Gr(),wT=TypeError;Xd.exports=function(s){if(ET(s))return s;throw new wT(xT(s)+" is not a function")}});var zr=v((oM,Jd)=>{"use strict";var AT=At(),PT=Qr();Jd.exports=function(s,e){var t=s[e];return PT(t)?void 0:AT(t)}});var ep=v((uM,Zd)=>{"use strict";var Oo=et(),Fo=Ee(),No=He(),RT=TypeError;Zd.exports=function(s,e){var t,i;if(e==="string"&&Fo(t=s.toString)&&!No(i=Oo(t,s))||Fo(t=s.valueOf)&&!No(i=Oo(t,s))||e!=="string"&&Fo(t=s.toString)&&!No(i=Oo(t,s)))return i;throw new RT("Can't convert object to primitive value")}});var gt=v((lM,tp)=>{"use strict";tp.exports=!0});var sp=v((cM,rp)=>{"use strict";var ip=Ie(),kT=Object.defineProperty;rp.exports=function(s,e){try{kT(ip,s,{value:e,configurable:!0,writable:!0})}catch(t){ip[s]=e}return e}});var Yr=v((dM,op)=>{"use strict";var LT=gt(),$T=Ie(),MT=sp(),ap="__core-js_shared__",np=op.exports=$T[ap]||MT(ap,{});(np.versions||(np.versions=[])).push({version:"3.43.0",mode:LT?"pure":"global",copyright:"\xA9 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var qo=v((pM,lp)=>{"use strict";var up=Yr();lp.exports=function(s,e){return up[s]||(up[s]=e||{})}});var Xi=v((hM,cp)=>{"use strict";var DT=ri(),CT=Object;cp.exports=function(s){return CT(DT(s))}});var vt=v((fM,dp)=>{"use strict";var BT=ke(),VT=Xi(),_T=BT({}.hasOwnProperty);dp.exports=Object.hasOwn||function(e,t){return _T(VT(e),t)}});var Uo=v((mM,pp)=>{"use strict";var OT=ke(),FT=0,NT=Math.random(),qT=OT(1.1.toString);pp.exports=function(s){return"Symbol("+(s===void 0?"":s)+")_"+qT(++FT+NT,36)}});var Be=v((bM,fp)=>{"use strict";var UT=Ie(),HT=qo(),hp=vt(),jT=Uo(),QT=Bo(),WT=Vo(),Ji=UT.Symbol,Ho=HT("wks"),GT=WT?Ji.for||Ji:Ji&&Ji.withoutSetter||jT;fp.exports=function(s){return hp(Ho,s)||(Ho[s]=QT&&hp(Ji,s)?Ji[s]:GT("Symbol."+s)),Ho[s]}});var vp=v((gM,gp)=>{"use strict";var zT=et(),mp=He(),bp=_o(),YT=zr(),KT=ep(),XT=Be(),JT=TypeError,ZT=XT("toPrimitive");gp.exports=function(s,e){if(!mp(s)||bp(s))return s;var t=YT(s,ZT),i;if(t){if(e===void 0&&(e="default"),i=zT(t,s,e),!mp(i)||bp(i))return i;throw new JT("Can't convert object to primitive value")}return e===void 0&&(e="number"),KT(s,e)}});var jo=v((vM,Sp)=>{"use strict";var eI=vp(),tI=_o();Sp.exports=function(s){var e=eI(s,"string");return tI(e)?e:e+""}});var Da=v((SM,Tp)=>{"use strict";var iI=Ie(),yp=He(),Qo=iI.document,rI=yp(Qo)&&yp(Qo.createElement);Tp.exports=function(s){return rI?Qo.createElement(s):{}}});var Wo=v((yM,Ip)=>{"use strict";var sI=Ze(),aI=Re(),nI=Da();Ip.exports=!sI&&!aI(function(){return Object.defineProperty(nI("div"),"a",{get:function(){return 7}}).a!==7})});var wp=v(xp=>{"use strict";var oI=Ze(),uI=et(),lI=ko(),cI=jr(),dI=Ei(),pI=jo(),hI=vt(),fI=Wo(),Ep=Object.getOwnPropertyDescriptor;xp.f=oI?Ep:function(e,t){if(e=dI(e),t=pI(t),fI)try{return Ep(e,t)}catch(i){}if(hI(e,t))return cI(!uI(lI.f,e,t),e[t])}});var Go=v((IM,Ap)=>{"use strict";var mI=Re(),bI=Ee(),gI=/#|\.prototype\./,Kr=function(s,e){var t=SI[vI(s)];return t===TI?!0:t===yI?!1:bI(e)?mI(e):!!e},vI=Kr.normalize=function(s){return String(s).replace(gI,".").toLowerCase()},SI=Kr.data={},yI=Kr.NATIVE="N",TI=Kr.POLYFILL="P";Ap.exports=Kr});var Zi=v((EM,Rp)=>{"use strict";var Pp=Po(),II=At(),EI=Hr(),xI=Pp(Pp.bind);Rp.exports=function(s,e){return II(s),e===void 0?s:EI?xI(s,e):function(){return s.apply(e,arguments)}}});var zo=v((xM,kp)=>{"use strict";var wI=Ze(),AI=Re();kp.exports=wI&&AI(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Pt=v((wM,Lp)=>{"use strict";var PI=He(),RI=String,kI=TypeError;Lp.exports=function(s){if(PI(s))return s;throw new kI(RI(s)+" is not an object")}});var Ai=v(Mp=>{"use strict";var LI=Ze(),$I=Wo(),MI=zo(),Ca=Pt(),$p=jo(),DI=TypeError,Yo=Object.defineProperty,CI=Object.getOwnPropertyDescriptor,Ko="enumerable",Xo="configurable",Jo="writable";Mp.f=LI?MI?function(e,t,i){if(Ca(e),t=$p(t),Ca(i),typeof e=="function"&&t==="prototype"&&"value"in i&&Jo in i&&!i[Jo]){var r=CI(e,t);r&&r[Jo]&&(e[t]=i.value,i={configurable:Xo in i?i[Xo]:r[Xo],enumerable:Ko in i?i[Ko]:r[Ko],writable:!1})}return Yo(e,t,i)}:Yo:function(e,t,i){if(Ca(e),t=$p(t),Ca(i),$I)try{return Yo(e,t,i)}catch(r){}if("get"in i||"set"in i)throw new DI("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var er=v((PM,Dp)=>{"use strict";var BI=Ze(),VI=Ai(),_I=jr();Dp.exports=BI?function(s,e,t){return VI.f(s,e,_I(1,t))}:function(s,e,t){return s[e]=t,s}});var Ae=v((RM,Bp)=>{"use strict";var Xr=Ie(),OI=wo(),FI=Po(),NI=Ee(),qI=wp().f,UI=Go(),tr=xi(),HI=Zi(),ir=er(),Cp=vt();Yr();var jI=function(s){var e=function(t,i,r){if(this instanceof e){switch(arguments.length){case 0:return new s;case 1:return new s(t);case 2:return new s(t,i)}return new s(t,i,r)}return OI(s,this,arguments)};return e.prototype=s.prototype,e};Bp.exports=function(s,e){var t=s.target,i=s.global,r=s.stat,a=s.proto,n=i?Xr:r?Xr[t]:Xr[t]&&Xr[t].prototype,o=i?tr:tr[t]||ir(tr,t,{})[t],u=o.prototype,l,c,d,f,p,h,b,S,g;for(f in e)l=UI(i?f:t+(r?".":"#")+f,s.forced),c=!l&&n&&Cp(n,f),h=o[f],c&&(s.dontCallGetSet?(g=qI(n,f),b=g&&g.value):b=n[f]),p=c&&b?b:e[f],!(!l&&!a&&typeof h==typeof p)&&(s.bind&&c?S=HI(p,Xr):s.wrap&&c?S=jI(p):a&&NI(p)?S=FI(p):S=p,(s.sham||p&&p.sham||h&&h.sham)&&ir(S,"sham",!0),ir(o,f,S),a&&(d=t+"Prototype",Cp(tr,d)||ir(tr,d,{}),ir(tr[d],f,p),s.real&&u&&(l||!u[f])&&ir(u,f,p)))}});var Ba=v((kM,_p)=>{"use strict";var QI=qo(),WI=Uo(),Vp=QI("keys");_p.exports=function(s){return Vp[s]||(Vp[s]=WI(s))}});var Fp=v((LM,Op)=>{"use strict";var GI=Re();Op.exports=!GI(function(){function s(){}return s.prototype.constructor=null,Object.getPrototypeOf(new s)!==s.prototype})});var Va=v(($M,qp)=>{"use strict";var zI=vt(),YI=Ee(),KI=Xi(),XI=Ba(),JI=Fp(),Np=XI("IE_PROTO"),Zo=Object,ZI=Zo.prototype;qp.exports=JI?Zo.getPrototypeOf:function(s){var e=KI(s);if(zI(e,Np))return e[Np];var t=e.constructor;return YI(t)&&e instanceof t?t.prototype:e instanceof Zo?ZI:null}});var Hp=v((MM,Up)=>{"use strict";var eE=Math.ceil,tE=Math.floor;Up.exports=Math.trunc||function(e){var t=+e;return(t>0?tE:eE)(t)}});var Jr=v((DM,jp)=>{"use strict";var iE=Hp();jp.exports=function(s){var e=+s;return e!==e||e===0?0:iE(e)}});var Wp=v((CM,Qp)=>{"use strict";var rE=Jr(),sE=Math.max,aE=Math.min;Qp.exports=function(s,e){var t=rE(s);return t<0?sE(t+e,0):aE(t,e)}});var eu=v((BM,Gp)=>{"use strict";var nE=Jr(),oE=Math.min;Gp.exports=function(s){var e=nE(s);return e>0?oE(e,9007199254740991):0}});var rr=v((VM,zp)=>{"use strict";var uE=eu();zp.exports=function(s){return uE(s.length)}});var tu=v((_M,Kp)=>{"use strict";var lE=Ei(),cE=Wp(),dE=rr(),Yp=function(s){return function(e,t,i){var r=lE(e),a=dE(r);if(a===0)return!s&&-1;var n=cE(i,a),o;if(s&&t!==t){for(;a>n;)if(o=r[n++],o!==o)return!0}else for(;a>n;n++)if((s||n in r)&&r[n]===t)return s||n||0;return!s&&-1}};Kp.exports={includes:Yp(!0),indexOf:Yp(!1)}});var _a=v((OM,Xp)=>{"use strict";Xp.exports={}});var eh=v((FM,Zp)=>{"use strict";var pE=ke(),iu=vt(),hE=Ei(),fE=tu().indexOf,mE=_a(),Jp=pE([].push);Zp.exports=function(s,e){var t=hE(s),i=0,r=[],a;for(a in t)!iu(mE,a)&&iu(t,a)&&Jp(r,a);for(;e.length>i;)iu(t,a=e[i++])&&(~fE(r,a)||Jp(r,a));return r}});var ru=v((NM,th)=>{"use strict";th.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var su=v((qM,ih)=>{"use strict";var bE=eh(),gE=ru();ih.exports=Object.keys||function(e){return bE(e,gE)}});var au=v((UM,oh)=>{"use strict";var sh=Ze(),vE=Re(),ah=ke(),SE=Va(),yE=su(),TE=Ei(),IE=ko().f,nh=ah(IE),EE=ah([].push),xE=sh&&vE(function(){var s=Object.create(null);return s[2]=2,!nh(s,2)}),rh=function(s){return function(e){for(var t=TE(e),i=yE(t),r=xE&&SE(t)===null,a=i.length,n=0,o=[],u;a>n;)u=i[n++],(!sh||(r?u in t:nh(t,u)))&&EE(o,s?[u,t[u]]:t[u]);return o}};oh.exports={entries:rh(!0),values:rh(!1)}});var uh=v(()=>{"use strict";var wE=Ae(),AE=au().values;wE({target:"Object",stat:!0},{values:function(e){return AE(e)}})});var ch=v((QM,lh)=>{"use strict";uh();var PE=xi();lh.exports=PE.Object.values});var ph=v((WM,dh)=>{"use strict";var RE=ch();dh.exports=RE});var Pi=v((GM,hh)=>{"use strict";var kE=ph();hh.exports=kE});var Zr=v((zM,fh)=>{"use strict";fh.exports=function(){}});var mh=v(()=>{"use strict";var LE=Ae(),$E=tu().includes,ME=Re(),DE=Zr(),CE=ME(function(){return!Array(1).includes()});LE({target:"Array",proto:!0,forced:CE},{includes:function(e){return $E(this,e,arguments.length>1?arguments[1]:void 0)}});DE("includes")});var si=v((XM,bh)=>{"use strict";var BE=Ot();bh.exports=BE});var vh=v((JM,gh)=>{"use strict";mh();var VE=si();gh.exports=VE("Array","includes")});var yh=v((ZM,Sh)=>{"use strict";var _E=vh();Sh.exports=_E});var Ne=v((eD,Th)=>{"use strict";var OE=yh();Th.exports=OE});var Eh=v(()=>{"use strict";var NE=Ae(),qE=au().entries;NE({target:"Object",stat:!0},{entries:function(e){return qE(e)}})});var wh=v((hD,xh)=>{"use strict";Eh();var UE=xi();xh.exports=UE.Object.entries});var Ph=v((fD,Ah)=>{"use strict";var HE=wh();Ah.exports=HE});var sr=v((mD,Rh)=>{"use strict";var jE=Ph();Rh.exports=jE});var Ri=v((bD,kh)=>{"use strict";kh.exports={}});var Mh=v((gD,$h)=>{"use strict";var QE=Ie(),WE=Ee(),Lh=QE.WeakMap;$h.exports=WE(Lh)&&/native code/.test(String(Lh))});var lu=v((vD,Bh)=>{"use strict";var GE=Mh(),Ch=Ie(),zE=He(),YE=er(),nu=vt(),ou=Yr(),KE=Ba(),XE=_a(),Dh="Object already initialized",uu=Ch.TypeError,JE=Ch.WeakMap,Fa,es,Na,ZE=function(s){return Na(s)?es(s):Fa(s,{})},ex=function(s){return function(e){var t;if(!zE(e)||(t=es(e)).type!==s)throw new uu("Incompatible receiver, "+s+" required");return t}};GE||ou.state?(St=ou.state||(ou.state=new JE),St.get=St.get,St.has=St.has,St.set=St.set,Fa=function(s,e){if(St.has(s))throw new uu(Dh);return e.facade=s,St.set(s,e),e},es=function(s){return St.get(s)||{}},Na=function(s){return St.has(s)}):(ki=KE("state"),XE[ki]=!0,Fa=function(s,e){if(nu(s,ki))throw new uu(Dh);return e.facade=s,YE(s,ki,e),e},es=function(s){return nu(s,ki)?s[ki]:{}},Na=function(s){return nu(s,ki)});var St,ki;Bh.exports={set:Fa,get:es,has:Na,enforce:ZE,getterFor:ex}});var pu=v((SD,_h)=>{"use strict";var cu=Ze(),tx=vt(),Vh=Function.prototype,ix=cu&&Object.getOwnPropertyDescriptor,du=tx(Vh,"name"),rx=du&&function(){}.name==="something",sx=du&&(!cu||cu&&ix(Vh,"name").configurable);_h.exports={EXISTS:du,PROPER:rx,CONFIGURABLE:sx}});var Fh=v(Oh=>{"use strict";var ax=Ze(),nx=zo(),ox=Ai(),ux=Pt(),lx=Ei(),cx=su();Oh.f=ax&&!nx?Object.defineProperties:function(e,t){ux(e);for(var i=lx(t),r=cx(t),a=r.length,n=0,o;a>n;)ox.f(e,o=r[n++],i[o]);return e}});var hu=v((TD,Nh)=>{"use strict";var dx=Ot();Nh.exports=dx("document","documentElement")});var gu=v((ID,Gh)=>{"use strict";var px=Pt(),hx=Fh(),qh=ru(),fx=_a(),mx=hu(),bx=Da(),gx=Ba(),Uh=">",Hh="<",mu="prototype",bu="script",Qh=gx("IE_PROTO"),fu=function(){},Wh=function(s){return Hh+bu+Uh+s+Hh+"/"+bu+Uh},jh=function(s){s.write(Wh("")),s.close();var e=s.parentWindow.Object;return s=null,e},vx=function(){var s=bx("iframe"),e="java"+bu+":",t;return s.style.display="none",mx.appendChild(s),s.src=String(e),t=s.contentWindow.document,t.open(),t.write(Wh("document.F=Object")),t.close(),t.F},qa,Ua=function(){try{qa=new ActiveXObject("htmlfile")}catch(e){}Ua=typeof document!="undefined"?document.domain&&qa?jh(qa):vx():jh(qa);for(var s=qh.length;s--;)delete Ua[mu][qh[s]];return Ua()};fx[Qh]=!0;Gh.exports=Object.create||function(e,t){var i;return e!==null?(fu[mu]=px(e),i=new fu,fu[mu]=null,i[Qh]=e):i=Ua(),t===void 0?i:hx.f(i,t)}});var ar=v((ED,zh)=>{"use strict";var Sx=er();zh.exports=function(s,e,t,i){return i&&i.enumerable?s[e]=t:Sx(s,e,t),s}});var Tu=v((xD,Xh)=>{"use strict";var yx=Re(),Tx=Ee(),Ix=He(),Ex=gu(),Yh=Va(),xx=ar(),wx=Be(),Ax=gt(),yu=wx("iterator"),Kh=!1,Ft,vu,Su;[].keys&&(Su=[].keys(),"next"in Su?(vu=Yh(Yh(Su)),vu!==Object.prototype&&(Ft=vu)):Kh=!0);var Px=!Ix(Ft)||yx(function(){var s={};return Ft[yu].call(s)!==s});Px?Ft={}:Ax&&(Ft=Ex(Ft));Tx(Ft[yu])||xx(Ft,yu,function(){return this});Xh.exports={IteratorPrototype:Ft,BUGGY_SAFARI_ITERATORS:Kh}});var Ha=v((wD,Zh)=>{"use strict";var Rx=Be(),kx=Rx("toStringTag"),Jh={};Jh[kx]="z";Zh.exports=String(Jh)==="[object z]"});var ts=v((AD,ef)=>{"use strict";var Lx=Ha(),$x=Ee(),ja=Ii(),Mx=Be(),Dx=Mx("toStringTag"),Cx=Object,Bx=ja(function(){return arguments}())==="Arguments",Vx=function(s,e){try{return s[e]}catch(t){}};ef.exports=Lx?ja:function(s){var e,t,i;return s===void 0?"Undefined":s===null?"Null":typeof(t=Vx(e=Cx(s),Dx))=="string"?t:Bx?ja(e):(i=ja(e))==="Object"&&$x(e.callee)?"Arguments":i}});var rf=v((PD,tf)=>{"use strict";var _x=Ha(),Ox=ts();tf.exports=_x?{}.toString:function(){return"[object "+Ox(this)+"]"}});var is=v((RD,af)=>{"use strict";var Fx=Ha(),Nx=Ai().f,qx=er(),Ux=vt(),Hx=rf(),jx=Be(),sf=jx("toStringTag");af.exports=function(s,e,t,i){var r=t?s:s&&s.prototype;r&&(Ux(r,sf)||Nx(r,sf,{configurable:!0,value:e}),i&&!Fx&&qx(r,"toString",Hx))}});var of=v((kD,nf)=>{"use strict";var Qx=Tu().IteratorPrototype,Wx=gu(),Gx=jr(),zx=is(),Yx=Ri(),Kx=function(){return this};nf.exports=function(s,e,t,i){var r=e+" Iterator";return s.prototype=Wx(Qx,{next:Gx(+!i,t)}),zx(s,r,!1,!0),Yx[r]=Kx,s}});var lf=v((LD,uf)=>{"use strict";var Xx=ke(),Jx=At();uf.exports=function(s,e,t){try{return Xx(Jx(Object.getOwnPropertyDescriptor(s,e)[t]))}catch(i){}}});var df=v(($D,cf)=>{"use strict";var Zx=He();cf.exports=function(s){return Zx(s)||s===null}});var hf=v((MD,pf)=>{"use strict";var ew=df(),tw=String,iw=TypeError;pf.exports=function(s){if(ew(s))return s;throw new iw("Can't set "+tw(s)+" as a prototype")}});var Iu=v((DD,ff)=>{"use strict";var rw=lf(),sw=He(),aw=ri(),nw=hf();ff.exports=Object.setPrototypeOf||("__proto__"in{}?function(){var s=!1,e={},t;try{t=rw(Object.prototype,"__proto__","set"),t(e,[]),s=e instanceof Array}catch(i){}return function(r,a){return aw(r),nw(a),sw(r)&&(s?t(r,a):r.__proto__=a),r}}():void 0)});var wf=v((CD,xf)=>{"use strict";var ow=Ae(),uw=et(),Qa=gt(),If=pu(),lw=Ee(),cw=of(),mf=Va(),bf=Iu(),dw=is(),pw=er(),Eu=ar(),hw=Be(),gf=Ri(),Ef=Tu(),fw=If.PROPER,mw=If.CONFIGURABLE,vf=Ef.IteratorPrototype,Wa=Ef.BUGGY_SAFARI_ITERATORS,rs=hw("iterator"),Sf="keys",ss="values",yf="entries",Tf=function(){return this};xf.exports=function(s,e,t,i,r,a,n){cw(t,e,i);var o=function(g){if(g===r&&f)return f;if(!Wa&&g&&g in c)return c[g];switch(g){case Sf:return function(){return new t(this,g)};case ss:return function(){return new t(this,g)};case yf:return function(){return new t(this,g)}}return function(){return new t(this)}},u=e+" Iterator",l=!1,c=s.prototype,d=c[rs]||c["@@iterator"]||r&&c[r],f=!Wa&&d||o(r),p=e==="Array"&&c.entries||d,h,b,S;if(p&&(h=mf(p.call(new s)),h!==Object.prototype&&h.next&&(!Qa&&mf(h)!==vf&&(bf?bf(h,vf):lw(h[rs])||Eu(h,rs,Tf)),dw(h,u,!0,!0),Qa&&(gf[u]=Tf))),fw&&r===ss&&d&&d.name!==ss&&(!Qa&&mw?pw(c,"name",ss):(l=!0,f=function(){return uw(d,this)})),r)if(b={values:o(ss),keys:a?f:o(Sf),entries:o(yf)},n)for(S in b)(Wa||l||!(S in c))&&Eu(c,S,b[S]);else ow({target:e,proto:!0,forced:Wa||l},b);return(!Qa||n)&&c[rs]!==f&&Eu(c,rs,f,{name:r}),gf[e]=f,b}});var Pf=v((BD,Af)=>{"use strict";Af.exports=function(s,e){return{value:s,done:e}}});var wu=v((VD,Mf)=>{"use strict";var bw=Ei(),xu=Zr(),Rf=Ri(),Lf=lu(),gw=Ai().f,vw=wf(),Ga=Pf(),Sw=gt(),yw=Ze(),$f="Array Iterator",Tw=Lf.set,Iw=Lf.getterFor($f);Mf.exports=vw(Array,"Array",function(s,e){Tw(this,{type:$f,target:bw(s),index:0,kind:e})},function(){var s=Iw(this),e=s.target,t=s.index++;if(!e||t>=e.length)return s.target=null,Ga(void 0,!0);switch(s.kind){case"keys":return Ga(t,!1);case"values":return Ga(e[t],!1)}return Ga([t,e[t]],!1)},"values");var kf=Rf.Arguments=Rf.Array;xu("keys");xu("values");xu("entries");if(!Sw&&yw&&kf.name!=="values")try{gw(kf,"name",{value:"values"})}catch(s){}});var Cf=v((_D,Df)=>{"use strict";var Ew=Be(),xw=Ri(),ww=Ew("iterator"),Aw=Array.prototype;Df.exports=function(s){return s!==void 0&&(xw.Array===s||Aw[ww]===s)}});var Au=v((OD,Vf)=>{"use strict";var Pw=ts(),Bf=zr(),Rw=Qr(),kw=Ri(),Lw=Be(),$w=Lw("iterator");Vf.exports=function(s){if(!Rw(s))return Bf(s,$w)||Bf(s,"@@iterator")||kw[Pw(s)]}});var Of=v((FD,_f)=>{"use strict";var Mw=et(),Dw=At(),Cw=Pt(),Bw=Gr(),Vw=Au(),_w=TypeError;_f.exports=function(s,e){var t=arguments.length<2?Vw(s):e;if(Dw(t))return Cw(Mw(t,s));throw new _w(Bw(s)+" is not iterable")}});var qf=v((ND,Nf)=>{"use strict";var Ow=et(),Ff=Pt(),Fw=zr();Nf.exports=function(s,e,t){var i,r;Ff(s);try{if(i=Fw(s,"return"),!i){if(e==="throw")throw t;return t}i=Ow(i,s)}catch(a){r=!0,i=a}if(e==="throw")throw t;if(r)throw i;return Ff(i),t}});var Ya=v((qD,Qf)=>{"use strict";var Nw=Zi(),qw=et(),Uw=Pt(),Hw=Gr(),jw=Cf(),Qw=rr(),Uf=Wr(),Ww=Of(),Gw=Au(),Hf=qf(),zw=TypeError,za=function(s,e){this.stopped=s,this.result=e},jf=za.prototype;Qf.exports=function(s,e,t){var i=t&&t.that,r=!!(t&&t.AS_ENTRIES),a=!!(t&&t.IS_RECORD),n=!!(t&&t.IS_ITERATOR),o=!!(t&&t.INTERRUPTED),u=Nw(e,i),l,c,d,f,p,h,b,S=function(I){return l&&Hf(l,"normal"),new za(!0,I)},g=function(I){return r?(Uw(I),o?u(I[0],I[1],S):u(I[0],I[1])):o?u(I,S):u(I)};if(a)l=s.iterator;else if(n)l=s;else{if(c=Gw(s),!c)throw new zw(Hw(s)+" is not iterable");if(jw(c)){for(d=0,f=Qw(s);f>d;d++)if(p=g(s[d]),p&&Uf(jf,p))return p;return new za(!1)}l=Ww(s,c)}for(h=a?s.next:l.next;!(b=qw(h,l)).done;){try{p=g(b.value)}catch(I){Hf(l,"throw",I)}if(typeof p=="object"&&p&&Uf(jf,p))return p}return new za(!1)}});var Gf=v((UD,Wf)=>{"use strict";var Yw=Ze(),Kw=Ai(),Xw=jr();Wf.exports=function(s,e,t){Yw?Kw.f(s,e,Xw(0,t)):s[e]=t}});var zf=v(()=>{"use strict";var Jw=Ae(),Zw=Ya(),eA=Gf();Jw({target:"Object",stat:!0},{fromEntries:function(e){var t={};return Zw(e,function(i,r){eA(t,i,r)},{AS_ENTRIES:!0}),t}})});var Kf=v((QD,Yf)=>{"use strict";wu();zf();var tA=xi();Yf.exports=tA.Object.fromEntries});var Jf=v((WD,Xf)=>{"use strict";Xf.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}});var em=v(()=>{"use strict";wu();var iA=Jf(),rA=Ie(),sA=is(),Zf=Ri();for(Ka in iA)sA(rA[Ka],Ka),Zf[Ka]=Zf.Array;var Ka});var im=v((YD,tm)=>{"use strict";var aA=Kf();em();tm.exports=aA});var Pu=v((KD,rm)=>{"use strict";var nA=im();rm.exports=nA});var sm=v(()=>{"use strict"});var Ru=v((ZD,am)=>{"use strict";var as=Ie(),oA=wi(),uA=Ii(),Xa=function(s){return oA.slice(0,s.length)===s};am.exports=function(){return Xa("Bun/")?"BUN":Xa("Cloudflare-Workers")?"CLOUDFLARE":Xa("Deno/")?"DENO":Xa("Node.js/")?"NODE":as.Bun&&typeof Bun.version=="string"?"BUN":as.Deno&&typeof Deno.version=="object"?"DENO":uA(as.process)==="process"?"NODE":as.window&&as.document?"BROWSER":"REST"}()});var Ja=v((eC,nm)=>{"use strict";var lA=Ru();nm.exports=lA==="NODE"});var um=v((tC,om)=>{"use strict";var cA=Ai();om.exports=function(s,e,t){return cA.f(s,e,t)}});var dm=v((iC,cm)=>{"use strict";var dA=Ot(),pA=um(),hA=Be(),fA=Ze(),lm=hA("species");cm.exports=function(s){var e=dA(s);fA&&e&&!e[lm]&&pA(e,lm,{configurable:!0,get:function(){return this}})}});var hm=v((rC,pm)=>{"use strict";var mA=Wr(),bA=TypeError;pm.exports=function(s,e){if(mA(e,s))return s;throw new bA("Incorrect invocation")}});var Lu=v((sC,fm)=>{"use strict";var gA=ke(),vA=Ee(),ku=Yr(),SA=gA(Function.toString);vA(ku.inspectSource)||(ku.inspectSource=function(s){return SA(s)});fm.exports=ku.inspectSource});var Mu=v((aC,Sm)=>{"use strict";var yA=ke(),TA=Re(),mm=Ee(),IA=ts(),EA=Ot(),xA=Lu(),bm=function(){},gm=EA("Reflect","construct"),$u=/^\s*(?:class|function)\b/,wA=yA($u.exec),AA=!$u.test(bm),ns=function(e){if(!mm(e))return!1;try{return gm(bm,[],e),!0}catch(t){return!1}},vm=function(e){if(!mm(e))return!1;switch(IA(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return AA||!!wA($u,xA(e))}catch(t){return!0}};vm.sham=!0;Sm.exports=!gm||TA(function(){var s;return ns(ns.call)||!ns(Object)||!ns(function(){s=!0})||s})?vm:ns});var Tm=v((nC,ym)=>{"use strict";var PA=Mu(),RA=Gr(),kA=TypeError;ym.exports=function(s){if(PA(s))return s;throw new kA(RA(s)+" is not a constructor")}});var Du=v((oC,Em)=>{"use strict";var Im=Pt(),LA=Tm(),$A=Qr(),MA=Be(),DA=MA("species");Em.exports=function(s,e){var t=Im(s).constructor,i;return t===void 0||$A(i=Im(t)[DA])?e:LA(i)}});var wm=v((uC,xm)=>{"use strict";var CA=ke();xm.exports=CA([].slice)});var Pm=v((lC,Am)=>{"use strict";var BA=TypeError;Am.exports=function(s,e){if(s<e)throw new BA("Not enough arguments");return s}});var Cu=v((cC,Rm)=>{"use strict";var VA=wi();Rm.exports=/(?:ipad|iphone|ipod).*applewebkit/i.test(VA)});var Hu=v((dC,_m)=>{"use strict";var tt=Ie(),_A=wo(),OA=Zi(),km=Ee(),FA=vt(),Vm=Re(),Lm=hu(),NA=wm(),$m=Da(),qA=Pm(),UA=Cu(),HA=Ja(),Nu=tt.setImmediate,qu=tt.clearImmediate,jA=tt.process,Bu=tt.Dispatch,QA=tt.Function,Mm=tt.MessageChannel,WA=tt.String,Vu=0,os={},Dm="onreadystatechange",us,Li,_u,Ou;Vm(function(){us=tt.location});var Uu=function(s){if(FA(os,s)){var e=os[s];delete os[s],e()}},Fu=function(s){return function(){Uu(s)}},Cm=function(s){Uu(s.data)},Bm=function(s){tt.postMessage(WA(s),us.protocol+"//"+us.host)};(!Nu||!qu)&&(Nu=function(e){qA(arguments.length,1);var t=km(e)?e:QA(e),i=NA(arguments,1);return os[++Vu]=function(){_A(t,void 0,i)},Li(Vu),Vu},qu=function(e){delete os[e]},HA?Li=function(s){jA.nextTick(Fu(s))}:Bu&&Bu.now?Li=function(s){Bu.now(Fu(s))}:Mm&&!UA?(_u=new Mm,Ou=_u.port2,_u.port1.onmessage=Cm,Li=OA(Ou.postMessage,Ou)):tt.addEventListener&&km(tt.postMessage)&&!tt.importScripts&&us&&us.protocol!=="file:"&&!Vm(Bm)?(Li=Bm,tt.addEventListener("message",Cm,!1)):Dm in $m("script")?Li=function(s){Lm.appendChild($m("script"))[Dm]=function(){Lm.removeChild(this),Uu(s)}}:Li=function(s){setTimeout(Fu(s),0)});_m.exports={set:Nu,clear:qu}});var Nm=v((pC,Fm)=>{"use strict";var Om=Ie(),GA=Ze(),zA=Object.getOwnPropertyDescriptor;Fm.exports=function(s){if(!GA)return Om[s];var e=zA(Om,s);return e&&e.value}});var ju=v((hC,Um)=>{"use strict";var qm=function(){this.head=null,this.tail=null};qm.prototype={add:function(s){var e={item:s,next:null},t=this.tail;t?t.next=e:this.head=e,this.tail=e},get:function(){var s=this.head;if(s){var e=this.head=s.next;return e===null&&(this.tail=null),s.item}}};Um.exports=qm});var jm=v((fC,Hm)=>{"use strict";var YA=wi();Hm.exports=/ipad|iphone|ipod/i.test(YA)&&typeof Pebble!="undefined"});var Wm=v((mC,Qm)=>{"use strict";var KA=wi();Qm.exports=/web0s(?!.*chrome)/i.test(KA)});var Zm=v((bC,Jm)=>{"use strict";var or=Ie(),XA=Nm(),Gm=Zi(),Qu=Hu().set,JA=ju(),ZA=Cu(),eP=jm(),tP=Wm(),Wu=Ja(),zm=or.MutationObserver||or.WebKitMutationObserver,Ym=or.document,Km=or.process,Za=or.Promise,Yu=XA("queueMicrotask"),nr,Gu,zu,en,Xm;Yu||(ls=new JA,cs=function(){var s,e;for(Wu&&(s=Km.domain)&&s.exit();e=ls.get();)try{e()}catch(t){throw ls.head&&nr(),t}s&&s.enter()},!ZA&&!Wu&&!tP&&zm&&Ym?(Gu=!0,zu=Ym.createTextNode(""),new zm(cs).observe(zu,{characterData:!0}),nr=function(){zu.data=Gu=!Gu}):!eP&&Za&&Za.resolve?(en=Za.resolve(void 0),en.constructor=Za,Xm=Gm(en.then,en),nr=function(){Xm(cs)}):Wu?nr=function(){Km.nextTick(cs)}:(Qu=Gm(Qu,or),nr=function(){Qu(cs)}),Yu=function(s){ls.head||nr(),ls.add(s)});var ls,cs;Jm.exports=Yu});var tb=v((gC,eb)=>{"use strict";eb.exports=function(s,e){try{arguments.length===1?console.error(s):console.error(s,e)}catch(t){}}});var tn=v((vC,ib)=>{"use strict";ib.exports=function(s){try{return{error:!1,value:s()}}catch(e){return{error:!0,value:e}}}});var $i=v((SC,rb)=>{"use strict";var iP=Ie();rb.exports=iP.Promise});var ur=v((yC,ob)=>{"use strict";var rP=Ie(),ds=$i(),sP=Ee(),aP=Go(),nP=Lu(),oP=Be(),sb=Ru(),uP=gt(),Ku=Co(),ab=ds&&ds.prototype,lP=oP("species"),Xu=!1,nb=sP(rP.PromiseRejectionEvent),cP=aP("Promise",function(){var s=nP(ds),e=s!==String(ds);if(!e&&Ku===66||uP&&!(ab.catch&&ab.finally))return!0;if(!Ku||Ku<51||!/native code/.test(s)){var t=new ds(function(a){a(1)}),i=function(a){a(function(){},function(){})},r=t.constructor={};if(r[lP]=i,Xu=t.then(function(){})instanceof i,!Xu)return!0}return!e&&(sb==="BROWSER"||sb==="DENO")&&!nb});ob.exports={CONSTRUCTOR:cP,REJECTION_EVENT:nb,SUBCLASSING:Xu}});var lr=v((TC,lb)=>{"use strict";var ub=At(),dP=TypeError,pP=function(s){var e,t;this.promise=new s(function(i,r){if(e!==void 0||t!==void 0)throw new dP("Bad Promise constructor");e=i,t=r}),this.resolve=ub(e),this.reject=ub(t)};lb.exports.f=function(s){return new pP(s)}});var kb=v(()=>{"use strict";var hP=Ae(),fP=gt(),nn=Ja(),ai=Ie(),mP=xi(),hr=et(),cb=ar(),db=Iu(),bP=is(),gP=dm(),vP=At(),an=Ee(),SP=He(),yP=hm(),TP=Du(),bb=Hu().set,il=Zm(),IP=tb(),EP=tn(),xP=ju(),gb=lu(),on=$i(),rl=ur(),vb=lr(),un="Promise",Sb=rl.CONSTRUCTOR,wP=rl.REJECTION_EVENT,AP=rl.SUBCLASSING,Ju=gb.getterFor(un),PP=gb.set,cr=on&&on.prototype,Mi=on,rn=cr,yb=ai.TypeError,Zu=ai.document,sl=ai.process,el=vb.f,RP=el,kP=!!(Zu&&Zu.createEvent&&ai.dispatchEvent),Tb="unhandledrejection",LP="rejectionhandled",pb=0,Ib=1,$P=2,al=1,Eb=2,sn,hb,xb,fb,wb=function(s){var e;return SP(s)&&an(e=s.then)?e:!1},Ab=function(s,e){var t=e.value,i=e.state===Ib,r=i?s.ok:s.fail,a=s.resolve,n=s.reject,o=s.domain,u,l,c;try{r?(i||(e.rejection===Eb&&DP(e),e.rejection=al),r===!0?u=t:(o&&o.enter(),u=r(t),o&&(o.exit(),c=!0)),u===s.promise?n(new yb("Promise-chain cycle")):(l=wb(u))?hr(l,u,a,n):a(u)):n(t)}catch(d){o&&!c&&o.exit(),n(d)}},Pb=function(s,e){s.notified||(s.notified=!0,il(function(){for(var t=s.reactions,i;i=t.get();)Ab(i,s);s.notified=!1,e&&!s.rejection&&MP(s)}))},Rb=function(s,e,t){var i,r;kP?(i=Zu.createEvent("Event"),i.promise=e,i.reason=t,i.initEvent(s,!1,!0),ai.dispatchEvent(i)):i={promise:e,reason:t},!wP&&(r=ai["on"+s])?r(i):s===Tb&&IP("Unhandled promise rejection",t)},MP=function(s){hr(bb,ai,function(){var e=s.facade,t=s.value,i=mb(s),r;if(i&&(r=EP(function(){nn?sl.emit("unhandledRejection",t,e):Rb(Tb,e,t)}),s.rejection=nn||mb(s)?Eb:al,r.error))throw r.value})},mb=function(s){return s.rejection!==al&&!s.parent},DP=function(s){hr(bb,ai,function(){var e=s.facade;nn?sl.emit("rejectionHandled",e):Rb(LP,e,s.value)})},dr=function(s,e,t){return function(i){s(e,i,t)}},pr=function(s,e,t){s.done||(s.done=!0,t&&(s=t),s.value=e,s.state=$P,Pb(s,!0))},tl=function(s,e,t){if(!s.done){s.done=!0,t&&(s=t);try{if(s.facade===e)throw new yb("Promise can't be resolved itself");var i=wb(e);i?il(function(){var r={done:!1};try{hr(i,e,dr(tl,r,s),dr(pr,r,s))}catch(a){pr(r,a,s)}}):(s.value=e,s.state=Ib,Pb(s,!1))}catch(r){pr({done:!1},r,s)}}};if(Sb&&(Mi=function(e){yP(this,rn),vP(e),hr(sn,this);var t=Ju(this);try{e(dr(tl,t),dr(pr,t))}catch(i){pr(t,i)}},rn=Mi.prototype,sn=function(e){PP(this,{type:un,done:!1,notified:!1,parent:!1,reactions:new xP,rejection:!1,state:pb,value:null})},sn.prototype=cb(rn,"then",function(e,t){var i=Ju(this),r=el(TP(this,Mi));return i.parent=!0,r.ok=an(e)?e:!0,r.fail=an(t)&&t,r.domain=nn?sl.domain:void 0,i.state===pb?i.reactions.add(r):il(function(){Ab(r,i)}),r.promise}),hb=function(){var s=new sn,e=Ju(s);this.promise=s,this.resolve=dr(tl,e),this.reject=dr(pr,e)},vb.f=el=function(s){return s===Mi||s===xb?new hb(s):RP(s)},!fP&&an(on)&&cr!==Object.prototype)){fb=cr.then,AP||cb(cr,"then",function(e,t){var i=this;return new Mi(function(r,a){hr(fb,i,r,a)}).then(e,t)},{unsafe:!0});try{delete cr.constructor}catch(s){}db&&db(cr,rn)}hP({global:!0,constructor:!0,wrap:!0,forced:Sb},{Promise:Mi});xb=mP.Promise;bP(Mi,un,!1,!0);gP(un)});var Cb=v((xC,Db)=>{"use strict";var CP=Be(),$b=CP("iterator"),Mb=!1;try{Lb=0,nl={next:function(){return{done:!!Lb++}},return:function(){Mb=!0}},nl[$b]=function(){return this},Array.from(nl,function(){throw 2})}catch(s){}var Lb,nl;Db.exports=function(s,e){try{if(!e&&!Mb)return!1}catch(r){return!1}var t=!1;try{var i={};i[$b]=function(){return{next:function(){return{done:t=!0}}}},s(i)}catch(r){}return t}});var ol=v((wC,Bb)=>{"use strict";var BP=$i(),VP=Cb(),_P=ur().CONSTRUCTOR;Bb.exports=_P||!VP(function(s){BP.all(s).then(void 0,function(){})})});var Vb=v(()=>{"use strict";var OP=Ae(),FP=et(),NP=At(),qP=lr(),UP=tn(),HP=Ya(),jP=ol();OP({target:"Promise",stat:!0,forced:jP},{all:function(e){var t=this,i=qP.f(t),r=i.resolve,a=i.reject,n=UP(function(){var o=NP(t.resolve),u=[],l=0,c=1;HP(e,function(d){var f=l++,p=!1;c++,FP(o,t,d).then(function(h){p||(p=!0,u[f]=h,--c||r(u))},a)}),--c||r(u)});return n.error&&a(n.value),i.promise}})});var Ob=v(()=>{"use strict";var QP=Ae(),WP=gt(),GP=ur().CONSTRUCTOR,ll=$i(),zP=Ot(),YP=Ee(),KP=ar(),_b=ll&&ll.prototype;QP({target:"Promise",proto:!0,forced:GP,real:!0},{catch:function(s){return this.then(void 0,s)}});!WP&&YP(ll)&&(ul=zP("Promise").prototype.catch,_b.catch!==ul&&KP(_b,"catch",ul,{unsafe:!0}));var ul});var Fb=v(()=>{"use strict";var XP=Ae(),JP=et(),ZP=At(),eR=lr(),tR=tn(),iR=Ya(),rR=ol();XP({target:"Promise",stat:!0,forced:rR},{race:function(e){var t=this,i=eR.f(t),r=i.reject,a=tR(function(){var n=ZP(t.resolve);iR(e,function(o){JP(n,t,o).then(i.resolve,r)})});return a.error&&r(a.value),i.promise}})});var Nb=v(()=>{"use strict";var sR=Ae(),aR=lr(),nR=ur().CONSTRUCTOR;sR({target:"Promise",stat:!0,forced:nR},{reject:function(e){var t=aR.f(this),i=t.reject;return i(e),t.promise}})});var cl=v((CC,qb)=>{"use strict";var oR=Pt(),uR=He(),lR=lr();qb.exports=function(s,e){if(oR(s),uR(e)&&e.constructor===s)return e;var t=lR.f(s),i=t.resolve;return i(e),t.promise}});var jb=v(()=>{"use strict";var cR=Ae(),dR=Ot(),Ub=gt(),pR=$i(),Hb=ur().CONSTRUCTOR,hR=cl(),fR=dR("Promise"),mR=Ub&&!Hb;cR({target:"Promise",stat:!0,forced:Ub||Hb},{resolve:function(e){return hR(mR&&this===fR?pR:this,e)}})});var Qb=v(()=>{"use strict";kb();Vb();Ob();Fb();Nb();jb()});var Yb=v(()=>{"use strict";var bR=Ae(),gR=gt(),ln=$i(),vR=Re(),Gb=Ot(),zb=Ee(),SR=Du(),Wb=cl(),yR=ar(),pl=ln&&ln.prototype,TR=!!ln&&vR(function(){pl.finally.call({then:function(){}},function(){})});bR({target:"Promise",proto:!0,real:!0,forced:TR},{finally:function(s){var e=SR(this,Gb("Promise")),t=zb(s);return this.then(t?function(i){return Wb(e,s()).then(function(){return i})}:s,t?function(i){return Wb(e,s()).then(function(){throw i})}:s)}});!gR&&zb(ln)&&(dl=Gb("Promise").prototype.finally,pl.finally!==dl&&yR(pl,"finally",dl,{unsafe:!0}));var dl});var Xb=v((qC,Kb)=>{"use strict";sm();Qb();Yb();var IR=si();Kb.exports=IR("Promise","finally")});var Zb=v((UC,Jb)=>{"use strict";var ER=Xb();Jb.exports=ER});var cn=v((HC,eg)=>{"use strict";var xR=Zb();eg.exports=xR});var bg=v(()=>{"use strict";var OR=Ae(),FR=Xi(),NR=rr(),qR=Jr(),UR=Zr();OR({target:"Array",proto:!0},{at:function(e){var t=FR(this),i=NR(t),r=qR(e),a=r>=0?r:i+r;return a<0||a>=i?void 0:t[a]}});UR("at")});var vg=v((IB,gg)=>{"use strict";bg();var HR=si();gg.exports=HR("Array","at")});var yg=v((EB,Sg)=>{"use strict";var jR=vg();Sg.exports=jR});var yt=v((xB,Tg)=>{"use strict";var QR=yg();Tg.exports=QR});var Cl=v((s_,Qg)=>{"use strict";var ik=Ii();Qg.exports=Array.isArray||function(e){return ik(e)==="Array"}});var Gg=v((a_,Wg)=>{"use strict";var rk=TypeError,sk=9007199254740991;Wg.exports=function(s){if(s>sk)throw rk("Maximum allowed index exceeded");return s}});var Kg=v((n_,Yg)=>{"use strict";var ak=Cl(),nk=rr(),ok=Gg(),uk=Zi(),zg=function(s,e,t,i,r,a,n,o){for(var u=r,l=0,c=n?uk(n,o):!1,d,f;l<i;)l in t&&(d=c?c(t[l],l,e):t[l],a>0&&ak(d)?(f=nk(d),u=zg(s,e,d,f,u,a-1)-1):(ok(u+1),s[u]=d),u++),l++;return u};Yg.exports=zg});var ev=v((o_,Zg)=>{"use strict";var Xg=Cl(),lk=Mu(),ck=He(),dk=Be(),pk=dk("species"),Jg=Array;Zg.exports=function(s){var e;return Xg(s)&&(e=s.constructor,lk(e)&&(e===Jg||Xg(e.prototype))?e=void 0:ck(e)&&(e=e[pk],e===null&&(e=void 0))),e===void 0?Jg:e}});var iv=v((u_,tv)=>{"use strict";var hk=ev();tv.exports=function(s,e){return new(hk(s))(e===0?0:e)}});var rv=v(()=>{"use strict";var fk=Ae(),mk=Kg(),bk=At(),gk=Xi(),vk=rr(),Sk=iv();fk({target:"Array",proto:!0},{flatMap:function(e){var t=gk(this),i=vk(t),r;return bk(e),r=Sk(t,0),r.length=mk(r,t,t,i,0,1,e,arguments.length>1?arguments[1]:void 0),r}})});var sv=v(()=>{"use strict";var yk=Zr();yk("flatMap")});var nv=v((h_,av)=>{"use strict";rv();sv();var Tk=si();av.exports=Tk("Array","flatMap")});var uv=v((f_,ov)=>{"use strict";var Ik=nv();ov.exports=Ik});var Es=v((m_,lv)=>{"use strict";var Ek=uv();lv.exports=Ek});var xs=v((b_,cv)=>{"use strict";var xk=ts(),wk=String;cv.exports=function(s){if(xk(s)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return wk(s)}});var Bl=v((g_,dv)=>{"use strict";dv.exports=`
7
- \v\f\r \xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF`});var fv=v((v_,hv)=>{"use strict";var Ak=ke(),Pk=ri(),Rk=xs(),_l=Bl(),pv=Ak("".replace),kk=RegExp("^["+_l+"]+"),Lk=RegExp("(^|[^"+_l+"])["+_l+"]+$"),Vl=function(s){return function(e){var t=Rk(Pk(e));return s&1&&(t=pv(t,kk,"")),s&2&&(t=pv(t,Lk,"$1")),t}};hv.exports={start:Vl(1),end:Vl(2),trim:Vl(3)}});var vv=v((S_,gv)=>{"use strict";var $k=pu().PROPER,Mk=Re(),mv=Bl(),bv="\u200B\x85\u180E";gv.exports=function(s){return Mk(function(){return!!mv[s]()||bv[s]()!==bv||$k&&mv[s].name!==s})}});var Ol=v((y_,Sv)=>{"use strict";var Dk=fv().start,Ck=vv();Sv.exports=Ck("trimStart")?function(){return Dk(this)}:"".trimStart});var Tv=v(()=>{"use strict";var Bk=Ae(),yv=Ol();Bk({target:"String",proto:!0,name:"trimStart",forced:"".trimLeft!==yv},{trimLeft:yv})});var Ev=v(()=>{"use strict";Tv();var Vk=Ae(),Iv=Ol();Vk({target:"String",proto:!0,name:"trimStart",forced:"".trimStart!==Iv},{trimStart:Iv})});var wv=v((w_,xv)=>{"use strict";Ev();var _k=si();xv.exports=_k("String","trimLeft")});var Pv=v((A_,Av)=>{"use strict";var Ok=wv();Av.exports=Ok});var kv=v((P_,Rv)=>{"use strict";var Fk=Pv();Rv.exports=Fk});var jv=v(()=>{"use strict"});var Qv=v(()=>{"use strict"});var Gv=v((uN,Wv)=>{"use strict";var aL=He(),nL=Ii(),oL=Be(),uL=oL("match");Wv.exports=function(s){var e;return aL(s)&&((e=s[uL])!==void 0?!!e:nL(s)==="RegExp")}});var Kv=v((lN,Yv)=>{"use strict";var lL=Ie(),cL=Re(),zv=lL.RegExp,dL=!cL(function(){var s=!0;try{zv(".","d")}catch(u){s=!1}var e={},t="",i=s?"dgimsy":"gimsy",r=function(u,l){Object.defineProperty(e,u,{get:function(){return t+=l,!0}})},a={dotAll:"s",global:"g",ignoreCase:"i",multiline:"m",sticky:"y"};s&&(a.hasIndices="d");for(var n in a)r(n,a[n]);var o=Object.getOwnPropertyDescriptor(zv.prototype,"flags").get.call(e);return o!==i||t!==i});Yv.exports={correct:dL}});var Jv=v((cN,Xv)=>{"use strict";var pL=Pt();Xv.exports=function(){var s=pL(this),e="";return s.hasIndices&&(e+="d"),s.global&&(e+="g"),s.ignoreCase&&(e+="i"),s.multiline&&(e+="m"),s.dotAll&&(e+="s"),s.unicode&&(e+="u"),s.unicodeSets&&(e+="v"),s.sticky&&(e+="y"),e}});var tS=v((dN,eS)=>{"use strict";var hL=et(),fL=vt(),mL=Wr(),Zv=Kv(),bL=Jv(),gL=RegExp.prototype;eS.exports=Zv.correct?function(s){return s.flags}:function(s){return!Zv.correct&&mL(gL,s)&&!fL(s,"flags")?hL(bL,s):s.flags}});var rS=v((pN,iS)=>{"use strict";var Ul=ke(),vL=Xi(),SL=Math.floor,Nl=Ul("".charAt),yL=Ul("".replace),ql=Ul("".slice),TL=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,IL=/\$([$&'`]|\d{1,2})/g;iS.exports=function(s,e,t,i,r,a){var n=t+s.length,o=i.length,u=IL;return r!==void 0&&(r=vL(r),u=TL),yL(a,u,function(l,c){var d;switch(Nl(c,0)){case"$":return"$";case"&":return s;case"`":return ql(e,0,t);case"'":return ql(e,n);case"<":d=r[ql(c,1,-1)];break;default:var f=+c;if(f===0)return l;if(f>o){var p=SL(f/10);return p===0?l:p<=o?i[p-1]===void 0?Nl(c,1):i[p-1]+Nl(c,1):l}d=i[f-1]}return d===void 0?"":d})}});var nS=v(()=>{"use strict";var EL=Ae(),xL=et(),jl=ke(),sS=ri(),wL=Ee(),AL=He(),PL=Gv(),wr=xs(),RL=zr(),kL=tS(),LL=rS(),$L=Be(),ML=gt(),DL=$L("replace"),CL=TypeError,Hl=jl("".indexOf),BL=jl("".replace),aS=jl("".slice),VL=Math.max;EL({target:"String",proto:!0},{replaceAll:function(e,t){var i=sS(this),r,a,n,o,u,l,c,d,f,p,h=0,b="";if(AL(e)){if(r=PL(e),r&&(a=wr(sS(kL(e))),!~Hl(a,"g")))throw new CL("`.replaceAll` does not allow non-global regexes");if(n=RL(e,DL),n)return xL(n,e,i,t);if(ML&&r)return BL(wr(i),e,t)}for(o=wr(i),u=wr(e),l=wL(t),l||(t=wr(t)),c=u.length,d=VL(1,c),f=Hl(o,u);f!==-1;)p=l?wr(t(u,f,o)):LL(u,o,f,[],void 0,t),b+=aS(o,h,f)+p,h=f+c,f=f+d>o.length?-1:Hl(o,u,f+d);return h<o.length&&(b+=aS(o,h)),b}})});var uS=v((mN,oS)=>{"use strict";jv();Qv();nS();var _L=si();oS.exports=_L("String","replaceAll")});var cS=v((bN,lS)=>{"use strict";var OL=uS();lS.exports=OL});var pS=v((gN,dS)=>{"use strict";var FL=cS();dS.exports=FL});var fS=v((vN,hS)=>{"use strict";var NL=Jr(),qL=xs(),UL=ri(),HL=RangeError;hS.exports=function(e){var t=qL(UL(this)),i="",r=NL(e);if(r<0||r===1/0)throw new HL("Wrong number of repetitions");for(;r>0;(r>>>=1)&&(t+=t))r&1&&(i+=t);return i}});var SS=v((SN,vS)=>{"use strict";var gS=ke(),jL=eu(),mS=xs(),QL=fS(),WL=ri(),GL=gS(QL),zL=gS("".slice),YL=Math.ceil,bS=function(s){return function(e,t,i){var r=mS(WL(e)),a=jL(t),n=r.length,o=i===void 0?" ":mS(i),u,l;return a<=n||o===""?r:(u=a-n,l=GL(o,YL(u/o.length)),l.length>u&&(l=zL(l,0,u)),s?r+l:l+r)}};vS.exports={start:bS(!1),end:bS(!0)}});var TS=v((yN,yS)=>{"use strict";var KL=wi();yS.exports=/Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(KL)});var IS=v(()=>{"use strict";var XL=Ae(),JL=SS().start,ZL=TS();XL({target:"String",proto:!0,forced:ZL},{padStart:function(e){return JL(this,e,arguments.length>1?arguments[1]:void 0)}})});var xS=v((EN,ES)=>{"use strict";IS();var e$=si();ES.exports=e$("String","padStart")});var AS=v((xN,wS)=>{"use strict";var t$=xS();wS.exports=t$});var RS=v((wN,PS)=>{"use strict";var i$=AS();PS.exports=i$});var $$={};Hy($$,{ChromecastState:()=>Nr,HttpConnectionType:()=>ka,Observable:()=>Bt.Observable,PlaybackState:()=>Fe,Player:()=>fa,PredefinedQualityLimits:()=>qr,SDK_VERSION:()=>L$,Subject:()=>Bt.Subject,Subscription:()=>Bt.Subscription,Surface:()=>La,VERSION:()=>Eo,ValueSubject:()=>Bt.ValueSubject,VideoFormat:()=>wt,VideoQuality:()=>Bt.VideoQuality,areValidLiveRecordSources:()=>ug,clientChecker:()=>z,isMobile:()=>fr});module.exports=jy($$);var Eo="2.0.139";var Fe=(r=>(r.STOPPED="stopped",r.READY="ready",r.PLAYING="playing",r.PAUSED="paused",r))(Fe||{}),wt=(E=>(E.MPEG="MPEG",E.DASH="DASH",E.DASH_SEP="DASH_SEP",E.DASH_SEP_VK="DASH_SEP",E.DASH_WEBM="DASH_WEBM",E.DASH_WEBM_AV1="DASH_WEBM_AV1",E.DASH_STREAMS="DASH_STREAMS",E.DASH_WEBM_VK="DASH_WEBM",E.DASH_ONDEMAND="DASH_ONDEMAND",E.DASH_ONDEMAND_VK="DASH_ONDEMAND",E.DASH_LIVE="DASH_LIVE",E.DASH_LIVE_CMAF="DASH_LIVE_CMAF",E.DASH_LIVE_WEBM="DASH_LIVE_WEBM",E.HLS="HLS",E.HLS_ONDEMAND="HLS_ONDEMAND",E.HLS_JS="HLS",E.HLS_FMP4="HLS_FMP4",E.HLS_LIVE="HLS_LIVE",E.HLS_LIVE_CMAF="HLS_LIVE_CMAF",E.WEB_RTC_LIVE="WEB_RTC_LIVE",E))(wt||{});var Nr=(r=>(r.NOT_AVAILABLE="NOT_AVAILABLE",r.AVAILABLE="AVAILABLE",r.CONNECTING="CONNECTING",r.CONNECTED="CONNECTED",r))(Nr||{}),ka=(i=>(i.HTTP1="http1",i.HTTP2="http2",i.QUIC="quic",i))(ka||{});var La=(n=>(n.NONE="none",n.INLINE="inline",n.FULLSCREEN="fullscreen",n.SECOND_SCREEN="second_screen",n.PIP="pip",n.INVISIBLE="invisible",n))(La||{}),qr=(i=>(i.TRAFFIC_SAVING="traffic_saving",i.HIGH_QUALITY="high_quality",i.UNKNOWN="unknown",i))(qr||{});var Tc=G(Pi(),1),Ly=G(Ne(),1);var ie=require("@vkontakte/videoplayer-shared/es2018");var Ih=s=>new Promise((e,t)=>{let i=document.createElement("script");i.setAttribute("src",s),i.onload=()=>e(),i.onerror=r=>t(r),document.body.appendChild(i)});var Oa=class{constructor(e){this.connection$=new ie.ValueSubject(void 0);this.castState$=new ie.ValueSubject("NOT_AVAILABLE");this.errorEvent$=new ie.Subject;this.realCastState$=new ie.ValueSubject("NOT_AVAILABLE");this.subscription=new ie.Subscription;this.isDestroyed=!1;var a;this.params=e,this.log=this.params.dependencies.logger.createComponentLog("ChromecastInitializer");let t="chrome"in window;if(this.log({message:`[constructor] receiverApplicationId: ${this.params.receiverApplicationId}, isDisabled: ${this.params.isDisabled}, isSupported: ${t}`}),e.isDisabled||!t)return;let i=(0,ie.isNonNullable)((a=window.chrome)==null?void 0:a.cast),r=!!window.__onGCastApiAvailable;i?this.initializeCastApi():(window.__onGCastApiAvailable=n=>{delete window.__onGCastApiAvailable,n&&!this.isDestroyed&&this.initializeCastApi()},r||Ih("https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1").catch(()=>this.errorEvent$.next({id:"ChromecastLoading",category:ie.ErrorCategory.NETWORK,message:"Script loading failed!"})))}connect(){var e;(e=cast.framework.CastContext.getInstance())==null||e.requestSession()}disconnect(){var e,t;(t=(e=cast.framework.CastContext.getInstance())==null?void 0:e.getCurrentSession())==null||t.endSession(!0)}stopMedia(){return new Promise((e,t)=>{var i,r,a;(a=(r=(i=cast.framework.CastContext.getInstance())==null?void 0:i.getCurrentSession())==null?void 0:r.getMediaSession())==null||a.stop(new chrome.cast.media.StopRequest,e,t)})}toggleConnection(){(0,ie.isNonNullable)(this.connection$.getValue())?this.disconnect():this.connect()}setVolume(e){let t=this.connection$.getValue();(0,ie.isNullable)(t)||(t.remotePlayer.volumeLevel=e,t.remotePlayerController.setVolumeLevel())}setMuted(e){let t=this.connection$.getValue();(0,ie.isNullable)(t)||e!==t.remotePlayer.isMuted&&t.remotePlayerController.muteOrUnmute()}destroy(){this.isDestroyed=!0,this.subscription.unsubscribe()}initListeners(){let e=new cast.framework.RemotePlayer,t=new cast.framework.RemotePlayerController(e),i=cast.framework.CastContext.getInstance();this.subscription.add((0,ie.fromEvent)(i,cast.framework.CastContextEventType.SESSION_STATE_CHANGED).subscribe(r=>{var a,n,o;switch(r.sessionState){case cast.framework.SessionState.SESSION_STARTED:case cast.framework.SessionState.SESSION_STARTING:case cast.framework.SessionState.SESSION_RESUMED:this.contentId=(o=(n=(a=i.getCurrentSession())==null?void 0:a.getMediaSession())==null?void 0:n.media)==null?void 0:o.contentId;break;case cast.framework.SessionState.NO_SESSION:case cast.framework.SessionState.SESSION_ENDING:case cast.framework.SessionState.SESSION_ENDED:case cast.framework.SessionState.SESSION_START_FAILED:this.contentId=void 0;break;default:return(0,ie.assertNever)(r.sessionState)}})).add((0,ie.merge)((0,ie.fromEvent)(i,cast.framework.CastContextEventType.CAST_STATE_CHANGED).pipe((0,ie.tap)(r=>{this.log({message:`[cast.framework.RemotePlayerEventType.CAST_STATE_CHANGED]: ${JSON.stringify(r)}`})}),(0,ie.map)(r=>r.castState)),(0,ie.observableFrom)([i.getCastState()])).pipe((0,ie.filterChanged)(),(0,ie.map)(FE),(0,ie.tap)(r=>{this.log({message:`realCastState$: ${r}`})})).subscribe(this.realCastState$)).add(this.realCastState$.subscribe(r=>{var o,u;let a=r==="CONNECTED",n=(0,ie.isNonNullable)(this.connection$.getValue());if(a&&!n){let l=i.getCurrentSession();(0,ie.assertNonNullable)(l);let c=l.getCastDevice(),d=(u=(o=l.getMediaSession())==null?void 0:o.media)==null?void 0:u.contentId;((0,ie.isNullable)(d)||d===this.contentId)&&(this.log({message:"connection created"}),this.connection$.next({remotePlayer:e,remotePlayerController:t,session:l,castDevice:c}))}else!a&&n&&(this.log({message:"connection destroyed"}),this.connection$.next(void 0));this.castState$.next(r==="CONNECTED"?(0,ie.isNonNullable)(this.connection$.getValue())?"CONNECTED":"AVAILABLE":r)}))}initializeCastApi(){var r;let e,t,i;try{e=cast.framework.CastContext.getInstance(),t=chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,i=chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}catch(a){return}try{e.setOptions({receiverApplicationId:(r=this.params.receiverApplicationId)!=null?r:t,autoJoinPolicy:i}),this.initListeners()}catch(a){this.errorEvent$.next({id:"ChromecastInitializer",category:ie.ErrorCategory.EXTERNAL_API,message:"[initializeCastApi] failed",thrown:a})}}},FE=s=>{switch(s){case cast.framework.CastState.NO_DEVICES_AVAILABLE:return"NOT_AVAILABLE";case cast.framework.CastState.NOT_CONNECTED:return"AVAILABLE";case cast.framework.CastState.CONNECTING:return"CONNECTING";case cast.framework.CastState.CONNECTED:return"CONNECTED";default:return(0,ie.assertNever)(s)}};var vc=G(Ne(),1),gy=G(sr(),1),vy=G(Pu(),1);var cg=G(cn(),1);var hl=require("@vkontakte/videoplayer-shared/es2018");var xe=(s,e=0,t=0)=>{switch(t){case 0:return s.replace("_offset_p",e===0?"":"_"+e.toFixed(0));case 1:{if(e===0)return s;let i=new URL(s);return i.searchParams.append("playback_shift",e.toFixed(0)),i.toString()}case 2:{let i=new URL(s);return!i.searchParams.get("offset_p")&&e===0?s:(i.searchParams.set("offset_p",e.toFixed(0)),i.toString())}default:(0,hl.assertNever)(t)}return s},ni=(s,e)=>{var t;switch(e){case 0:return NaN;case 1:{let i=new URL(s);return Number(i.searchParams.get("playback_shift"))}case 2:{let i=new URL(s);return Number((t=i.searchParams.get("offset_p"))!=null?t:0)}default:(0,hl.assertNever)(e)}};var O=(s,e,t=!1)=>{let i=s.getTransition();(t||!i||i.to===e)&&s.setState(e)};var Rt=require("@vkontakte/videoplayer-shared/es2018"),re=class{constructor(e){this.transitionStarted$=new Rt.Subject;this.transitionEnded$=new Rt.Subject;this.transitionUpdated$=new Rt.Subject;this.forceChanged$=new Rt.Subject;this.stateChangeStarted$=(0,Rt.merge)(this.transitionStarted$,this.transitionUpdated$);this.stateChangeEnded$=(0,Rt.merge)(this.transitionEnded$,this.forceChanged$);this.state=e,this.prevState=void 0}setState(e){let t=this.transition,i=this.state;this.transition=void 0,this.prevState=i,this.state=e,t?t.to===e?this.transitionEnded$.next(t):this.forceChanged$.next({from:t.from,to:e,canceledTransition:t}):this.forceChanged$.next({from:i,to:e,canceledTransition:t})}startTransitionTo(e){let t=this.transition,i=this.state;i===e||(0,Rt.isNonNullable)(t)&&t.to===e||(this.prevState=i,this.state=e,t?(this.transition={from:t.from,to:e,canceledTransition:t},this.transitionUpdated$.next(this.transition)):(this.transition={from:i,to:e},this.transitionStarted$.next(this.transition)))}getTransition(){return this.transition}getState(){return this.state}getPrevState(){return this.prevState}};var ml=require("@vkontakte/videoplayer-shared/es2018");var dn=class{constructor(){this._isMiuiBrowser=!1}get current(){return this._current}get isChrome(){return this.current==="Chrome"}get isFirefox(){return this.current==="Firefox"}get isSafari(){return this.current==="Safari"}get isOpera(){return this.current==="Opera"}get isEdge(){return this.current==="Edge"}get isYandex(){return this.current==="Yandex"}get isSamsungBrowser(){return this.current==="SamsungBrowser"}get currentVersion(){return this._current_version}get chromeVersion(){return this._chromeVersion}get firefoxVersion(){return this._firefoxVersion}get safariVersion(){return this._safariVersion}get operaVersion(){return this._operaVersion}get edgeVersion(){return this._edgeVersion}get yandexVersion(){return this._yandexVersion}get isMiuiBrowser(){return this._isMiuiBrowser}detect(){let{userAgent:e}=navigator;try{let t=/yabrowser/i.test(e)?"Yandex":void 0,i=/samsungbrowser/i.test(e)?"SamsungBrowser":void 0,r=/chrome|crios/i.test(e)?"Chrome":void 0,a=/chromium/i.test(e)?"Chromium":void 0,n=/firefox|fxios/i.test(e)?"Firefox":void 0,o=/webkit|safari|khtml/i.test(e)?"Safari":void 0,u=/opr\//i.test(e)?"Opera":void 0,l=/edg/i.test(e)?"Edge":void 0;this._isMiuiBrowser=/(XiaoMi)|(MiuiBrowser)/i.test(e),this._current=t||i||n||u||l||r||a||o||"Rest"}catch(t){console.error(t)}this.isChrome&&this.detectChromeVersion(),this.isFirefox&&this.detectFirefoxVersion(),this.isSafari&&this.detectSafariVersion(),this.isOpera&&this.detectOperaVersion(),this.isEdge&&this.detectEdgeVersion(),this.isYandex&&this.detectYandexVersion()}detectVersion(e){try{let{userAgent:t}=window.navigator,i=t.match(e);if(!i)return;let r=i[1],a=parseInt(r,10);if(!isNaN(a))return this._current_version=a,a}catch(t){console.error(t)}}detectChromeVersion(){this._chromeVersion=this.detectVersion(/Chrome\/(\d+\.\d+)/)}detectFirefoxVersion(){this._firefoxVersion=this.detectVersion(/Firefox\/(\d+\.\d+)/)}detectSafariVersion(){this._safariVersion=this.detectVersion(/Version\/(\d+)/)}detectOperaVersion(){this._operaVersion=this.detectVersion(/OPR\/(\d+\.\d+)/)}detectEdgeVersion(){this._edgeVersion=this.detectVersion(/Edg\/(\d+\.\d+)/)}detectYandexVersion(){this._yandexVersion=this.detectVersion(/YaBrowser\/(\d+\.\d+\.\d+)/)}};var tg=G(Ne(),1);var fr=()=>{var s,e;return/Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test((s=navigator.appVersion)!=null?s:navigator.userAgent)||((e=navigator==null?void 0:navigator.userAgentData)==null?void 0:e.mobile)};var pn=class{constructor(e){this._highEntropyValues={};this._displayChecker=e}get current(){return this._current}get isIOS(){let e=["iPhone","iPad","iPod"];return this._highEntropyValues.platform==="iOS"||(0,tg.default)(e,this.current)}get isMac(){return this._highEntropyValues.platform==="macOS"||this.current==="Mac"}get isApple(){return this.isIOS||this.isMac}get isIphoneOrOldIpad(){if(!this.isApple||!this._displayChecker.isTouch)return!1;let e=this.current==="iPad"||this._displayChecker.width>700,t=this._iosVersion;return!e||e&&!!t&&t<16}get isAndroid(){return this._highEntropyValues.platform==="Android"||this.current==="Android"}get isMobile(){return this._highEntropyValues.mobile||this._isMobile}get iOSVersion(){return this._iosVersion}detect(){let{userAgent:e}=navigator;try{this._isMobile=fr()}catch(t){console.error(t)}this.detectDevice(e),this.detectHighEntropyValues(),this.isIOS&&this.detectIOSVersion()}async detectHighEntropyValues(){let{userAgentData:e}=navigator;if(e!=null&&e.getHighEntropyValues){let t=await e.getHighEntropyValues(["architecture","bitness","brands","mobile","platform","formFactor","model","platformVersion","wow64"]);this._highEntropyValues=t}}detectDevice(e){try{let t=/android/i.test(e)?"Android":void 0,i=/iphone/i.test(e)?"iPhone":void 0,r=/ipad/i.test(e)?"iPad":void 0,a=/ipod/i.test(e)?"iPod":void 0,n=/mac/i.test(e)?"Mac":void 0,o=/webOS|BlackBerry|IEMobile|Opera Mini/i.test(e)?"RestMobile":void 0;this._current=t||i||r||a||o||n||"Desktop"}catch(t){console.error(t)}}detectIOSVersion(){try{if(this._highEntropyValues.platformVersion){let a=this._highEntropyValues.platformVersion.split(".").slice(0,2).join("."),n=parseFloat(a);this._iosVersion=n;return}let{userAgent:e}=window.navigator,t=e.match(/OS (\d+(_\d+)?)/i);if(!t)return;let i=t[1].replace(/_/g,".");if(!i)return;let r=parseFloat(i);if(isNaN(r))return;this._iosVersion=r}catch(e){console.error(e)}}};var hn=class{get isTouch(){return typeof this._maxTouchPoints=="number"?this._maxTouchPoints>1:"ontouchstart"in window}get maxTouchPoints(){return this._maxTouchPoints}get height(){return this._height}get width(){return this._width}get screenHeight(){return this._screenHeight}get screenWidth(){return this._screenWidth}get pixelRatio(){return this._pixelRatio}get isHDR(){return this._isHdr}get colorDepth(){return this._colorDepth}detect(){var t;let{maxTouchPoints:e}=navigator;try{this._maxTouchPoints=e!=null?e:0,this._isHdr=!!((t=matchMedia("(dynamic-range: high)"))!=null&&t.matches),this._colorDepth=screen.colorDepth}catch(i){console.error(i)}try{this._pixelRatio=window.devicePixelRatio||1,this._height=screen.height,this._width=screen.width,this._height=screen.height,this._screenHeight=this._height*this._pixelRatio,this._screenWidth=this._width*this._pixelRatio}catch(i){console.error(i)}}};var it=()=>window.ManagedMediaSource||window.MediaSource,mr=()=>{var s,e;return!!(window.ManagedMediaSource&&((e=(s=window.ManagedSourceBuffer)==null?void 0:s.prototype)!=null&&e.appendBuffer))},ig=()=>{var s,e;return!!(window.MediaSource&&((e=(s=window.SourceBuffer)==null?void 0:s.prototype)!=null&&e.appendBuffer))},fn=()=>window.ManagedMediaSource?new ManagedMediaSource:new MediaSource;var wR=document.createElement("video"),AR='video/mp4; codecs="avc1.42000a,mp4a.40.2"',PR='video/mp4; codecs="hev1.1.6.L93.B0"',rg='video/webm; codecs="vp09.00.10.08"',sg='video/webm; codecs="av01.0.00M.08"',RR='audio/mp4; codecs="mp4a.40.2"',kR='audio/webm; codecs="opus"',ag,LR=async()=>{if(!window.navigator.mediaCapabilities)return;let s={type:"media-source",video:{contentType:"video/webm",width:1280,height:720,bitrate:1e6,framerate:30}},[e,t]=await Promise.all([window.navigator.mediaCapabilities.decodingInfo({...s,video:{...s.video,contentType:sg}}),window.navigator.mediaCapabilities.decodingInfo({...s,video:{...s.video,contentType:rg}})]);ag={DASH_WEBM_AV1:e,DASH_WEBM:t}};LR().catch(s=>{console.log(wR),console.error(s)});var mn=class{constructor(e,t){this._deviceChecker=e,this._browserChecker=t}get protocols(){return this._protocols}get containers(){return this._containers}get codecs(){return this._codecs}get webmDecodingInfo(){return ag}get supportedCodecs(){return Object.keys(this._codecs).filter(e=>this._codecs[e])}get nativeHlsSupported(){return this._nativeHlsSupported}detect(){var e,t,i,r,a,n,o,u,l,c,d,f,p,h,b,S,g,I,w,E;this._video=document.createElement("video");try{this._protocols={mms:mr(),mse:ig(),hls:!!((t=(e=this._video).canPlayType)!=null&&t.call(e,"application/x-mpegurl")||(r=(i=this._video).canPlayType)!=null&&r.call(i,"vnd.apple.mpegURL")),webrtc:!!window.RTCPeerConnection,ws:!!window.WebSocket},this._containers={mp4:!!((n=(a=this._video).canPlayType)!=null&&n.call(a,"video/mp4")),webm:!!((u=(o=this._video).canPlayType)!=null&&u.call(o,"video/webm")),cmaf:!0};let P=!!((c=(l=it())==null?void 0:l.isTypeSupported)!=null&&c.call(l,AR)),_=!!((f=(d=it())==null?void 0:d.isTypeSupported)!=null&&f.call(d,PR)),N=!!((h=(p=it())==null?void 0:p.isTypeSupported)!=null&&h.call(p,RR));this._codecs={h264:P,h265:_,vp9:!!((S=(b=it())==null?void 0:b.isTypeSupported)!=null&&S.call(b,rg)),av1:!!((I=(g=it())==null?void 0:g.isTypeSupported)!=null&&I.call(g,sg)),aac:N,opus:!!((E=(w=it())==null?void 0:w.isTypeSupported)!=null&&E.call(w,kR)),mpeg:(P||_)&&N},this._nativeHlsSupported=this._protocols.hls&&this._containers.mp4}catch(P){console.error(P)}try{this.destroyVideoElement()}catch(P){console.error("Error destroying video element:",P)}}destroyVideoElement(){var t;if(!this._video)return;if(this._video.pause(),this._video.currentTime=0,this._video.removeAttribute("src"),this._video.src="",this._video.load(),this._video.remove){this._video.remove(),this._video=null;return}this._video.parentNode&&this._video.parentNode.removeChild(this._video);let e=this._video.cloneNode(!1);(t=this._video.parentNode)==null||t.replaceChild(e,this._video),this._video=null}};var ng="audio/mpeg",bn=class{supportMp3(){return this._codecs.mp3&&this._containers.mpeg}detect(){var e,t,i,r;this._audio=document.createElement("audio");try{this._containers={mpeg:!!((t=(e=this._audio).canPlayType)!=null&&t.call(e,ng))},this._codecs={mp3:!!((r=(i=it())==null?void 0:i.isTypeSupported)!=null&&r.call(i,ng))}}catch(a){console.error(a)}try{this.destroyAudioElement()}catch(a){console.error("Error destroying audio element:",a)}}destroyAudioElement(){var t;if(!this._audio)return;if(this._audio.pause(),this._audio.currentTime=0,this._audio.removeAttribute("src"),this._audio.src="",this._audio.load(),this._audio.remove){this._audio.remove(),this._audio=null;return}this._audio.parentNode&&this._audio.parentNode.removeChild(this._audio);let e=this._audio.cloneNode(!1);(t=this._audio.parentNode)==null||t.replaceChild(e,this._audio),this._audio=null}};var og=require("@vkontakte/videoplayer-shared/es2018"),fl=class{constructor(){this.isInited$=new og.ValueSubject(!1);this._displayChecker=new hn,this._deviceChecker=new pn(this._displayChecker),this._browserChecker=new dn,this._videoChecker=new mn(this._deviceChecker,this._browserChecker),this._audioChecker=new bn,this.detect()}get display(){return this._displayChecker}get device(){return this._deviceChecker}get browser(){return this._browserChecker}get video(){return this._videoChecker}get audio(){return this._audioChecker}async detect(){this._displayChecker.detect(),this._deviceChecker.detect(),this._browserChecker.detect(),this._videoChecker.detect(),this._audioChecker.detect(),this.isInited$.next(!0)}},z=new fl;var bl=s=>{let{containers:e,protocols:t,codecs:i,nativeHlsSupported:r}=z.video,a=(i.h264||i.h265)&&i.aac,n=t.mse||t.mms;return s.filter(o=>{switch(o){case"DASH_SEP":return n&&e.mp4&&a;case"DASH_WEBM":return n&&e.webm&&i.vp9&&i.opus;case"DASH_WEBM_AV1":return n&&e.webm&&i.av1&&i.opus;case"DASH_STREAMS":return n&&(e.mp4&&a||e.webm&&(i.vp9||i.av1)&&(i.opus||i.aac));case"DASH_LIVE":return n&&e.mp4&&a;case"DASH_LIVE_CMAF":return n&&e.mp4&&a&&e.cmaf;case"DASH_ONDEMAND":return n&&e.mp4&&a;case"HLS":case"HLS_ONDEMAND":case"HLS_FMP4":case"HLS_LIVE":case"HLS_LIVE_CMAF":return r;case"MPEG":return e.mp4;case"DASH":case"DASH_LIVE_WEBM":return!1;case"WEB_RTC_LIVE":return t.webrtc&&t.ws&&i.h264&&(e.mp4||e.webm);default:return(0,ml.assertNever)(o)}})},gl=s=>{switch(s){case"MPEG":case"DASH":case"DASH_SEP":case"DASH_ONDEMAND":case"DASH_WEBM":case"DASH_WEBM_AV1":case"DASH_STREAMS":case"HLS":case"HLS_FMP4":case"HLS_ONDEMAND":return!1;case"DASH_LIVE":case"DASH_LIVE_CMAF":case"HLS_LIVE":case"HLS_LIVE_CMAF":case"DASH_LIVE_WEBM":case"WEB_RTC_LIVE":return!0;default:return(0,ml.assertNever)(s)}},ug=s=>{let t=Object.keys(s).filter(i=>!gl(i));return bl(t).length>0};var j=require("@vkontakte/videoplayer-shared/es2018");var $R=5,MR=5,DR=500,lg=7e3,ps=class{constructor(e){this.subscription=new j.Subscription;this.loadMediaTimeoutSubscription=new j.Subscription;this.videoState=new re("stopped");this.syncPlayback=()=>{let e=this.videoState.getState(),t=this.videoState.getTransition(),i=this.params.desiredState.playbackState.getState(),r=this.params.desiredState.playbackState.getTransition(),a=this.params.desiredState.seekState.getState();if(this.log({message:`[syncPlayback] videoState: ${e}; videoTransition: ${JSON.stringify(t)}; desiredPlaybackState: ${i}; desiredPlaybackStateTransition: ${this.params.desiredState.playbackState.getTransition()}; seekState: ${JSON.stringify(a)};`}),i==="stopped"){e!=="stopped"&&(this.videoState.startTransitionTo("stopped"),this.stop());return}if(!t){if((r==null?void 0:r.to)!=="paused"&&a.state==="requested"&&e!=="stopped"){this.seek(a.position/1e3);return}switch(i){case"ready":{switch(e){case"playing":case"paused":case"ready":break;case"stopped":this.videoState.startTransitionTo("ready"),this.prepare();break;default:(0,j.assertNever)(e)}break}case"playing":{switch(e){case"playing":break;case"paused":this.videoState.startTransitionTo("playing"),this.params.connection.remotePlayerController.playOrPause();break;case"ready":this.videoState.startTransitionTo("playing"),this.params.connection.remotePlayerController.playOrPause();break;case"stopped":this.videoState.startTransitionTo("ready"),this.prepare();break;default:(0,j.assertNever)(e)}break}case"paused":{switch(e){case"playing":this.videoState.startTransitionTo("paused"),this.params.connection.remotePlayerController.playOrPause();break;case"paused":break;case"ready":this.videoState.startTransitionTo("paused"),this.videoState.setState("paused");break;case"stopped":this.videoState.startTransitionTo("ready"),this.prepare();break;default:(0,j.assertNever)(e)}break}default:(0,j.assertNever)(i)}}};this.params=e,this.log=this.params.dependencies.logger.createComponentLog("ChromecastProvider"),this.log({message:`constructor, format: ${e.format}`}),this.params.output.isLive$.next(gl(e.format)),this.params.output.isAudioAvailable$.next(!0),this.handleRemoteVolumeChange({volume:this.params.connection.remotePlayer.volumeLevel,muted:this.params.connection.remotePlayer.isMuted});let t=this.params.connection.session.getMediaSession();t&&this.restoreSession(t),this.subscribe()}destroy(){this.log({message:"[destroy]"}),this.subscription.unsubscribe()}subscribe(){this.subscription.add(this.loadMediaTimeoutSubscription);let e=new j.Subscription;this.subscription.add(e),this.subscription.add((0,j.merge)(this.videoState.stateChangeStarted$.pipe((0,j.map)(r=>`stateChangeStarted$ ${JSON.stringify(r)}`)),this.videoState.stateChangeEnded$.pipe((0,j.map)(r=>`stateChangeEnded$ ${JSON.stringify(r)}`))).subscribe(r=>this.log({message:`[videoState] ${r}`})));let t=(r,a)=>this.subscription.add(r.subscribe(a));if(this.params.output.isLive$.getValue())this.params.output.position$.next(0),this.params.output.duration$.next(0);else{let r=new j.Subject;e.add(r.pipe((0,j.debounce)(DR)).subscribe(()=>{this.params.output.seekedEvent$.next()}));let a=NaN;e.add((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.CURRENT_TIME_CHANGED).subscribe(n=>{this.logRemoteEvent(n);let o=n.value;this.params.output.position$.next(o),(this.params.desiredState.seekState.getState().state==="applying"||Math.abs(o-a)>$R)&&r.next(o),a=o})),e.add((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.DURATION_CHANGED).subscribe(n=>{this.logRemoteEvent(n),this.params.output.duration$.next(n.value)}))}t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MEDIA_LOADED_CHANGED),r=>{this.logRemoteEvent(r),r.value?this.handleRemoteReady():(this.handleRemoteStop(),e.unsubscribe())}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_PAUSED_CHANGED),r=>{this.logRemoteEvent(r),r.value?this.handleRemotePause():this.handleRemotePlay()}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.PLAYER_STATE_CHANGED),r=>{this.logRemoteEvent(r);let{remotePlayer:a}=this.params.connection,n=r.value,o=this.params.output.isBuffering$.getValue(),u=n===chrome.cast.media.PlayerState.BUFFERING;switch(o!==u&&this.params.output.isBuffering$.next(u),n){case chrome.cast.media.PlayerState.IDLE:!this.params.output.isLive$.getValue()&&a.duration-a.currentTime<MR&&this.params.output.endedEvent$.next(),this.handleRemoteStop(),O(this.params.desiredState.playbackState,"stopped");break;case chrome.cast.media.PlayerState.PAUSED:{this.handleRemotePause();break}case chrome.cast.media.PlayerState.PLAYING:this.handleRemotePlay();break;case chrome.cast.media.PlayerState.BUFFERING:break;default:(0,j.assertNever)(n)}}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.VOLUME_LEVEL_CHANGED),r=>{this.logRemoteEvent(r),this.handleRemoteVolumeChange({volume:r.value})}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MUTED_CHANGED),r=>{this.logRemoteEvent(r),this.handleRemoteVolumeChange({muted:r.value})});let i=(0,j.merge)(this.params.desiredState.playbackState.stateChangeStarted$,this.params.desiredState.seekState.stateChangeEnded$,this.videoState.stateChangeEnded$,(0,j.observableFrom)(["init"])).pipe((0,j.debounce)(0));t(i,this.syncPlayback)}restoreSession(e){this.log({message:"restoreSession"});let{remotePlayer:t}=this.params.connection;if(e.playerState!==chrome.cast.media.PlayerState.IDLE){t.isPaused?(this.videoState.setState("paused"),O(this.params.desiredState.playbackState,"paused")):(this.videoState.setState("playing"),O(this.params.desiredState.playbackState,"playing"));let i=this.params.output.isLive$.getValue();this.params.output.duration$.next(i?0:t.duration),this.params.output.position$.next(i?0:t.currentTime),this.params.desiredState.seekState.setState({state:"none"})}}prepare(){let e=this.params.format;this.log({message:`[prepare] format: ${e}`});let t=this.createMediaInfo(e),i=this.createLoadRequest(t);this.loadMedia(i)}handleRemotePause(){let e=this.videoState.getState(),t=this.videoState.getTransition();((t==null?void 0:t.to)==="paused"||e==="playing")&&(this.videoState.setState("paused"),O(this.params.desiredState.playbackState,"paused"))}handleRemotePlay(){let e=this.videoState.getState(),t=this.videoState.getTransition();((t==null?void 0:t.to)==="playing"||e==="paused")&&(this.videoState.setState("playing"),O(this.params.desiredState.playbackState,"playing"))}handleRemoteReady(){var t;let e=this.videoState.getTransition();(e==null?void 0:e.to)==="ready"&&this.videoState.setState("ready"),((t=this.params.desiredState.playbackState.getTransition())==null?void 0:t.to)==="ready"&&O(this.params.desiredState.playbackState,"ready")}handleRemoteStop(){this.videoState.getState()!=="stopped"&&this.videoState.setState("stopped")}handleRemoteVolumeChange(e){var r,a;let t=this.params.output.volume$.getValue(),i={volume:(r=e.volume)!=null?r:t.volume,muted:(a=e.muted)!=null?a:t.muted};(i.volume!==t.volume||i.muted!==i.muted)&&this.params.output.volume$.next(i)}seek(e){this.params.output.willSeekEvent$.next();let{remotePlayer:t,remotePlayerController:i}=this.params.connection;t.currentTime=e,i.seek()}stop(){let{remotePlayerController:e}=this.params.connection;e.stop()}createMediaInfo(e){var l;let t=this.params.source,i,r,a;switch(e){case"MPEG":{let c=t[e];(0,j.assertNonNullable)(c);let d=(0,j.getHighestQuality)(Object.keys(c));(0,j.assertNonNullable)(d);let f=c[d];(0,j.assertNonNullable)(f),i=f,r="video/mp4",a=chrome.cast.media.StreamType.BUFFERED;break}case"HLS":case"HLS_FMP4":case"HLS_ONDEMAND":{let c=t[e];(0,j.assertNonNullable)(c),i=c.url,r="application/x-mpegurl",a=chrome.cast.media.StreamType.BUFFERED;break}case"DASH_SEP":case"DASH_ONDEMAND":case"DASH_WEBM":case"DASH_WEBM_AV1":case"DASH_STREAMS":{let c=t[e];(0,j.assertNonNullable)(c),i=c.url,r="application/dash+xml",a=chrome.cast.media.StreamType.BUFFERED;break}case"DASH_LIVE_CMAF":{let c=t[e];(0,j.assertNonNullable)(c),i=c.url,r="application/dash+xml",a=chrome.cast.media.StreamType.LIVE;break}case"HLS_LIVE":case"HLS_LIVE_CMAF":{let c=t[e];(0,j.assertNonNullable)(c),i=xe(c.url),r="application/x-mpegurl",a=chrome.cast.media.StreamType.LIVE;break}case"DASH_LIVE":case"WEB_RTC_LIVE":{let c="Unsupported format for Chromecast",d=new Error(c);throw this.params.output.error$.next({id:"ChromecastProvider.createMediaInfo()",category:j.ErrorCategory.VIDEO_PIPELINE,message:c,thrown:d}),d}case"DASH":case"DASH_LIVE_WEBM":throw new Error(`${e} is no longer supported`);default:return(0,j.assertNever)(e)}let n=new chrome.cast.media.MediaInfo((l=this.params.meta.videoId)!=null?l:i,r);n.contentUrl=i,n.streamType=a,n.metadata=new chrome.cast.media.GenericMediaMetadata;let{title:o,subtitle:u}=this.params.meta;return(0,j.isNonNullable)(o)&&(n.metadata.title=o),(0,j.isNonNullable)(u)&&(n.metadata.subtitle=u),n}createLoadRequest(e){let t=new chrome.cast.media.LoadRequest(e);t.autoplay=!1;let i=this.params.desiredState.seekState.getState();return i.state==="applying"||i.state==="requested"?t.currentTime=this.params.output.isLive$.getValue()?0:i.position/1e3:t.currentTime=0,t}loadMedia(e){let t=this.params.connection.session.loadMedia(e),i=new Promise((r,a)=>{this.loadMediaTimeoutSubscription.add((0,j.timeout)(lg).subscribe(()=>a(`timeout(${lg})`)))});(0,cg.default)(Promise.race([t,i]).then(()=>{this.log({message:`[loadMedia] completed, format: ${this.params.format}`}),this.params.desiredState.seekState.getState().state==="applying"&&this.params.output.seekedEvent$.next(),this.handleRemoteReady()},r=>{let a=`[prepare] loadMedia failed, format: ${this.params.format}, reason: ${r}`;this.log({message:a}),this.params.output.error$.next({id:"ChromecastProvider.loadMedia",category:j.ErrorCategory.VIDEO_PIPELINE,message:a,thrown:r})}),()=>{this.loadMediaTimeoutSubscription.unsubscribe()})}logRemoteEvent(e){this.log({message:`[remoteEvent] ${JSON.stringify(e)}`})}};var Ml=G(Ne(),1);var Tl=require("@vkontakte/videoplayer-shared/es2018");var dg=require("@vkontakte/videoplayer-shared/es2018"),pg=s=>{try{s.pause(),s.playbackRate=0,(0,dg.clearVideoElement)(s),s.remove()}catch(e){console.error(e)}};var gn=require("@vkontakte/videoplayer-shared/es2018"),vl=class{constructor(){this.attribute="data-pool-reused"}get(e){return e.hasAttribute(this.attribute)}set(e,t){e.toggleAttribute(this.attribute,t)}delete(e){e.removeAttribute(this.attribute)}},Sl=window.WeakMap?new WeakMap:new vl,yl=window.WeakMap?new WeakMap:new Map,CR=(s,e=20)=>{let t=0;return(0,gn.fromEvent)(s,"ratechange").subscribe(i=>{t++,t>=e&&(s.currentTime=s.currentTime,t=0)})},je=(s,{audioVideoSyncRate:e,disableYandexPiP:t})=>{let i=s.querySelector("video"),r=!!i;i?(0,Tl.clearVideoElement)(i):(i=document.createElement("video"),s.appendChild(i)),Sl.set(i,r);let a=new gn.Subscription;return a.add(CR(i,e)),yl.set(i,a),i.setAttribute("crossorigin","anonymous"),i.setAttribute("playsinline","playsinline"),t&&i.setAttribute("x-yandex-pip","false"),i.controls=!1,i.setAttribute("poster","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="),i},Qe=s=>{let e=yl.get(s);e==null||e.unsubscribe(),yl.delete(s);let t=Sl.get(s);Sl.delete(s),t?(0,Tl.clearVideoElement)(s):pg(s)};var Il=G(Pi(),1),Q=require("@vkontakte/videoplayer-shared/es2018");var oi=require("@vkontakte/videoplayer-shared/es2018"),vn=(s,e,t,{equal:i=(n,o)=>n===o,changed$:r,onError:a}={})=>{let n=s.getState(),o=e(),u=(0,oi.isNullable)(r),l=new oi.Subscription;return r&&l.add(r.subscribe(c=>{let d=s.getState();i(c,d)&&s.setState(c)},a)),i(o,n)||(t(n),u&&s.setState(n)),l.add(s.stateChangeStarted$.subscribe(c=>{t(c.to),u&&s.setState(c.to)},a)),l},kt=(s,e,t)=>vn(e,()=>s.loop,i=>{(0,oi.isNonNullable)(i)&&(s.loop=i)},{onError:t}),We=(s,e,t,i)=>vn(e,()=>({muted:s.muted,volume:s.volume}),r=>{(0,oi.isNonNullable)(r)&&(s.muted=r.muted,s.volume=r.volume)},{equal:(r,a)=>r===a||(r==null?void 0:r.muted)===(a==null?void 0:a.muted)&&(r==null?void 0:r.volume)===(a==null?void 0:a.volume),changed$:t,onError:i}),ut=(s,e,t,i)=>vn(e,()=>s.playbackRate,r=>{(0,oi.isNonNullable)(r)&&(s.playbackRate=r)},{changed$:t,onError:i}),hs=vn;var BR=s=>["__",s.language,s.label].join("|"),VR=(s,e)=>{if(s.id===e)return!0;let[t,i,r]=e.split("|");return s.language===i&&s.label===r},El=class s{constructor(e){this.available$=new Q.Subject;this.current$=new Q.ValueSubject(void 0);this.error$=new Q.Subject;this.subscription=new Q.Subscription;this.externalTracks=new Map;this.internalTracks=new Map;this.baseURL=e}connect(e,t,i){this.video=e,this.cueSettings=t.textTrackCuesSettings,this.subscribe();let r=a=>{this.error$.next({id:"TextTracksManager",category:Q.ErrorCategory.WTF,message:"Generic HtmlVideoTextTrackManager error",thrown:a})};this.subscription.add(this.available$.subscribe(i.availableTextTracks$)),this.subscription.add(this.current$.subscribe(i.currentTextTrack$)),this.subscription.add(this.error$.subscribe(i.error$)),this.subscription.add(hs(t.internalTextTracks,()=>(0,Il.default)(this.internalTracks),a=>{(0,Q.isNonNullable)(a)&&this.setInternal(a)},{equal:(a,n)=>(0,Q.isNonNullable)(a)&&(0,Q.isNonNullable)(n)&&a.length===n.length&&a.every(({id:o},u)=>o===n[u].id),changed$:this.available$.pipe((0,Q.map)(a=>a.filter(({type:n})=>n==="internal"))),onError:r})),this.subscription.add(hs(t.externalTextTracks,()=>(0,Il.default)(this.externalTracks),a=>{(0,Q.isNonNullable)(a)&&this.setExternal(a)},{equal:(a,n)=>(0,Q.isNonNullable)(a)&&(0,Q.isNonNullable)(n)&&a.length===n.length&&a.every(({id:o},u)=>o===n[u].id),changed$:this.available$.pipe((0,Q.map)(a=>a.filter(({type:n})=>n==="external"))),onError:r})),this.subscription.add(hs(t.currentTextTrack,()=>{if(this.video)return;let a=this.htmlTextTracksAsArray().find(({mode:n})=>n==="showing");return a&&this.htmlTextTrackToITextTrack(a).id},a=>this.select(a),{changed$:this.current$,onError:r})),this.subscription.add(hs(t.textTrackCuesSettings,()=>({}),()=>{if(this.video)for(let a of this.htmlTextTracksAsArray())this.applyCueSettings(a.cues),this.applyCueSettings(a.activeCues)}))}subscribe(){(0,Q.assertNonNullable)(this.video);let{textTracks:e}=this.video;this.subscription.add((0,Q.fromEvent)(e,"addtrack").subscribe(()=>{let i=this.current$.getValue();i&&this.select(i)})),this.subscription.add((0,Q.merge)((0,Q.fromEvent)(e,"addtrack"),(0,Q.fromEvent)(e,"removetrack"),(0,Q.observableFrom)(["init"])).pipe((0,Q.map)(()=>this.htmlTextTracksAsArray().map(i=>this.htmlTextTrackToITextTrack(i))),(0,Q.filterChanged)((i,r)=>i.length===r.length&&i.every(({id:a},n)=>a===r[n].id))).subscribe(this.available$)),this.subscription.add((0,Q.merge)((0,Q.fromEvent)(e,"change"),(0,Q.observableFrom)(["init"])).pipe((0,Q.map)(()=>this.htmlTextTracksAsArray().find(({mode:i})=>i==="showing")),(0,Q.map)(i=>i&&this.htmlTextTrackToITextTrack(i).id),(0,Q.filterChanged)()).subscribe(this.current$));let t=i=>{var r,a;return this.applyCueSettings((a=(r=i.target)==null?void 0:r.activeCues)!=null?a:null)};this.subscription.add((0,Q.fromEvent)(e,"addtrack").subscribe(i=>{var a,n;(a=i.track)==null||a.addEventListener("cuechange",t);let r=o=>{var l,c,d,f,p;let u=(c=(l=o.target)==null?void 0:l.cues)!=null?c:null;u&&u.length&&(this.applyCueSettings((f=(d=o.target)==null?void 0:d.cues)!=null?f:null),(p=o.target)==null||p.removeEventListener("cuechange",r))};(n=i.track)==null||n.addEventListener("cuechange",r)})),this.subscription.add((0,Q.fromEvent)(e,"removetrack").subscribe(i=>{var r;(r=i.track)==null||r.removeEventListener("cuechange",t)}))}applyCueSettings(e){if(!e||!e.length)return;let t=this.cueSettings.getState();for(let i of Array.from(e)){let r=i;(0,Q.isNonNullable)(t.align)&&(r.align=t.align),(0,Q.isNonNullable)(t.position)&&(r.position=t.position),(0,Q.isNonNullable)(t.size)&&(r.size=t.size),(0,Q.isNonNullable)(t.line)&&(r.line=t.line)}}htmlTextTracksAsArray(e=!1){(0,Q.assertNonNullable)(this.video);let t=[...this.video.textTracks];return e?t:t.filter(s.isHealthyTrack)}htmlTextTrackToITextTrack(e){var o,u,l,c,d;let{language:t,label:i}=e,r=e.id?e.id:BR(e),a=this.externalTracks.has(r),n=(l=a?(o=this.externalTracks.get(r))==null?void 0:o.isAuto:(u=this.internalTracks.get(r))==null?void 0:u.isAuto)!=null?l:r.includes("auto");return a?{id:r,type:"external",isAuto:n,language:t,label:i,url:(c=this.externalTracks.get(r))==null?void 0:c.url}:{id:r,type:"internal",isAuto:n,language:t,label:i,url:(d=this.internalTracks.get(r))==null?void 0:d.url}}static isHealthyTrack(e){return!(e.kind==="metadata"||e.groupId||e.id===""&&e.label===""&&e.language==="")}setExternal(e){this.internalTracks.size>0&&Array.from(this.internalTracks).forEach(([,t])=>this.detach(t)),e.filter(({id:t})=>!this.externalTracks.has(t)).forEach(t=>this.attach(t)),Array.from(this.externalTracks).filter(([t])=>!e.find(i=>i.id===t)).forEach(([,t])=>this.detach(t))}setInternal(e){let t=[...this.externalTracks];e.filter(({id:i,language:r,isAuto:a})=>!this.internalTracks.has(i)&&!t.some(([,n])=>n.language===r&&n.isAuto===a)).forEach(i=>this.attach(i)),Array.from(this.internalTracks).filter(([i])=>!e.find(r=>r.id===i)).forEach(([,i])=>this.detach(i))}select(e){(0,Q.assertNonNullable)(this.video);for(let t of this.htmlTextTracksAsArray(!0))t.mode="showing";for(let t of this.htmlTextTracksAsArray(!0))((0,Q.isNullable)(e)||!VR(t,e))&&(t.mode="disabled")}destroy(){if(this.subscription.unsubscribe(),this.video)for(let e of Array.from(this.video.getElementsByTagName("track"))){let t=e.getAttribute("id");t&&this.externalTracks.has(t)&&this.video.removeChild(e)}this.externalTracks.clear()}attach(e){(0,Q.assertNonNullable)(this.video);let t=document.createElement("track");this.baseURL?t.setAttribute("src",new URL(e.url,this.baseURL).toString()):t.setAttribute("src",e.url),t.setAttribute("id",e.id),e.label&&t.setAttribute("label",e.label),e.language&&t.setAttribute("srclang",e.language),e.type==="external"?this.externalTracks.set(e.id,e):e.type==="internal"&&this.internalTracks.set(e.id,e),this.video.appendChild(t)}detach(e){(0,Q.assertNonNullable)(this.video);let t=Array.prototype.find.call(this.video.getElementsByTagName("track"),i=>i.getAttribute("id")===e.id);t&&this.video.removeChild(t),e.type==="external"?this.externalTracks.delete(e.id):e.type==="internal"&&this.internalTracks.delete(e.id)}},lt=El;var Di=class{constructor(){this.pausedTime=0;this.streamOffset=0;this.pauseTimestamp=0}getTotalPausedTime(){return this.pausedTime+this.getCurrentPausedTime()}getCurrentPausedTime(){return this.pauseTimestamp>0?Date.now()-this.pauseTimestamp:0}getStreamOffset(){return this.streamOffset}getTotalOffset(){return this.getTotalPausedTime()+this.streamOffset}pause(){this.pauseTimestamp===0&&(this.pauseTimestamp=Date.now())}resume(){this.pauseTimestamp>0&&(this.pausedTime+=this.getCurrentPausedTime(),this.pauseTimestamp=0)}resetTo(e,t=!1){this.streamOffset=e,this.pauseTimestamp=0,this.pausedTime=0,t&&this.pause()}};var hg=s=>{let e=s;for(;!(e instanceof Document)&&!(e instanceof ShadowRoot)&&e!==null;)e=e==null?void 0:e.parentNode;return e!=null?e:void 0},xl=s=>{let e=hg(s);return!!(e&&e.fullscreenElement&&e.fullscreenElement===s)},fg=s=>{let e=hg(s);return!!(e&&e.pictureInPictureElement&&e.pictureInPictureElement===s)};var L=require("@vkontakte/videoplayer-shared/es2018");var _R=3,mg=(s,e,t=_R)=>{let i=0,r=0;for(let a=0;a<s.length;a++){let n=s.start(a),o=s.end(a);if(n<=e&&e<=o){if(i=n,r=o,!t)return{from:i,to:r};for(let u=a-1;u>=0;u--)s.end(u)+t>=i&&(i=s.start(u));for(let u=a+1;u<s.length;u++)s.start(u)-t<=r&&(r=s.end(u))}}return{from:i,to:r}};var Ge=s=>{let e=B=>(0,L.fromEvent)(s,B).pipe((0,L.mapTo)(void 0),(0,L.shareReplay)(1)),t=new L.Subscription,i=()=>t.unsubscribe(),r=(0,L.merge)((0,L.fromEvent)(s,"progress"),(0,L.fromEvent)(s,"timeupdate")).pipe((0,L.map)(()=>mg(s.buffered,s.currentTime)),(0,L.shareReplay)(1)),a=z.browser.isSafari?(0,L.combine)({play:e("play").pipe((0,L.once)()),playing:e("playing")}).pipe((0,L.mapTo)(void 0),(0,L.shareReplay)(1)):e("playing"),n=(0,L.fromEvent)(s,"volumechange").pipe((0,L.map)(()=>({muted:s.muted,volume:s.volume})),(0,L.shareReplay)(1)),o=(0,L.fromEvent)(s,"ratechange").pipe((0,L.map)(()=>s.playbackRate),(0,L.shareReplay)(1)),u=(0,L.fromEvent)(s,"error").pipe((0,L.filter)(()=>!!(s.error||s.played.length)),(0,L.map)(()=>{var H;let B=s.error;return{id:B?`MediaError#${B.code}`:"HtmlVideoError",category:L.ErrorCategory.VIDEO_PIPELINE,message:B?B.message:"Error event from HTML video element",thrown:(H=s.error)!=null?H:void 0}}),(0,L.shareReplay)(1)),l=(0,L.fromEvent)(s,"timeupdate").pipe((0,L.map)(()=>s.currentTime),(0,L.shareReplay)(1)),c=["waiting","seeking","seeked","timeupdate"],d=new L.Subject,f=.3,p;t.add((0,L.merge)(...c.map(B=>(0,L.fromEvent)(s,B))).subscribe(B=>{let H=s.currentTime;s.loop&&(0,L.isNonNullable)(p)&&(0,L.isNonNullable)(H)&&p>=s.duration-f&&H<=f&&d.next(p),p=H}));let h=e("pause").pipe((0,L.filter)(()=>!s.error&&p!==s.duration),(0,L.shareReplay)(1)),b=(0,L.fromEvent)(s,"enterpictureinpicture").pipe((0,L.shareReplay)(1)),S=(0,L.fromEvent)(s,"leavepictureinpicture").pipe((0,L.shareReplay)(1)),g=new L.ValueSubject(fg(s));t.add(b.subscribe(()=>g.next(!0))),t.add(S.subscribe(()=>g.next(!1)));let I=new L.ValueSubject(xl(s)),w=(0,L.fromEvent)(s,"fullscreenchange").pipe((0,L.shareReplay)(1));t.add(w.pipe((0,L.map)(()=>xl(s))).subscribe(I));let E=.1,P=1e3,_=(0,L.fromEvent)(s,"timeupdate").pipe((0,L.map)(B=>s.duration-s.currentTime<E),(0,L.filterChanged)(),(0,L.shareReplay)(1)),N=(0,L.merge)(_.pipe((0,L.filter)(B=>!s.loop&&B)),(0,L.fromEvent)(s,"ended")).pipe((0,L.throttle)(P),(0,L.mapTo)(void 0),(0,L.shareReplay)(1)),C=(0,L.merge)(...["waiting","pause","canplay","play","canplaythrough","playing","seeking","seeked","ended"].map(B=>(0,L.fromEvent)(s,B)),_.pipe((0,L.map)(B=>({type:B?"ended":"unknown"})))).pipe((0,L.map)(B=>z.browser.isFirefox&&B.type==="ended"?s.readyState<2:s.readyState<3),(0,L.filterChanged)(),(0,L.shareReplay)(1));return{playing$:a,pause$:h,canplay$:e("canplay"),ended$:N,looped$:d,error$:u,seeked$:e("seeked"),seeking$:e("seeking"),progress$:e("progress"),loadStart$:e("loadstart"),loadedMetadata$:e("loadedmetadata"),loadedData$:e("loadeddata"),timeUpdate$:l,durationChange$:(0,L.fromEvent)(s,"durationchange").pipe((0,L.map)(()=>s.duration),(0,L.shareReplay)(1)),isBuffering$:C,currentBuffer$:r,volumeState$:n,playbackRateState$:o,inPiP$:g,inFullscreen$:I,enterPip$:b,leavePip$:S,destroy:i}};var qt=require("@vkontakte/videoplayer-shared/es2018"),ui=s=>{switch(s){case"mobile":return qt.VideoQuality.Q_144P;case"lowest":return qt.VideoQuality.Q_240P;case"low":return qt.VideoQuality.Q_360P;case"sd":case"medium":return qt.VideoQuality.Q_480P;case"hd":case"high":return qt.VideoQuality.Q_720P;case"fullhd":case"full":return qt.VideoQuality.Q_1080P;case"quadhd":case"quad":return qt.VideoQuality.Q_1440P;case"ultrahd":case"ultra":return qt.VideoQuality.Q_2160P}};var Ue=G(yt(),1),Pl=G(Ne(),1),Ci=G(sr(),1),D=require("@vkontakte/videoplayer-shared/es2018");var wl=!1,Ut={},Ig=s=>{wl=s},Eg=()=>{Ut={}},xg=s=>{s(Ut)},fs=(s,e)=>{var t;wl&&(Ut.meta=(t=Ut.meta)!=null?t:{},Ut.meta[s]=e)},qe=class{constructor(e){this.name=e}next(e){var i,r;if(!wl)return;Ut.series=(i=Ut.series)!=null?i:{};let t=(r=Ut.series[this.name])!=null?r:[];t.push([Date.now(),e]),Ut.series[this.name]=t}};var Pe=require("@vkontakte/videoplayer-shared/es2018");function Al(s,e,t){return!s.max&&s.min===e?"high_quality":!s.min&&s.max===t?"traffic_saving":"unknown"}function Sn(s,e,t){return!!s&&Al(s,e,t)==="high_quality"}function br(s,e,t){return(0,Pe.isNullable)(s)||(0,Pe.isNonNullable)(s.min)&&(0,Pe.isNonNullable)(s.max)&&(0,Pe.isLower)(s.max,s.min)||(0,Pe.isNonNullable)(s.min)&&e&&(0,Pe.isHigher)(s.min,e)||(0,Pe.isNonNullable)(s.max)&&t&&(0,Pe.isLower)(s.max,t)}function wg({limits:s,highestAvailableHeight:e,lowestAvailableHeight:t}){return br({max:s!=null&&s.max?(0,Pe.videoHeightToQuality)(s.max):void 0,min:s!=null&&s.min?(0,Pe.videoHeightToQuality)(s.min):void 0},e?(0,Pe.videoHeightToQuality)(e):void 0,t?(0,Pe.videoHeightToQuality)(t):void 0)}var Lg=new qe("best_bitrate"),Tn=(s,e,t)=>(e-t)*Math.pow(2,-10*s)+t;var gr=s=>(e,t)=>s*(Number(e.bitrate)-Number(t.bitrate)),li=class{constructor(){this.history={}}recordSelection(e){this.history[e.id]=(0,D.now)()}recordSwitch(e){this.last=e}clear(){this.last=void 0,this.history={}}},In='Assertion "ABR Tracks is empty array" failed',yn=new WeakMap,Ag=new WeakMap,Pg=new WeakMap,ms=(s,e,t,i)=>{var u;let r=[...e].sort(gr(1)),a=[...t].sort(gr(1)),n=a.filter(l=>(0,D.isNonNullable)(l.bitrate)&&(0,D.isNonNullable)(s.bitrate)?s.bitrate/l.bitrate>i:!0),o=(u=(0,Ue.default)(a,Math.round(a.length*r.indexOf(s)/(r.length+1))))!=null?u:(0,Ue.default)(a,-1);return o&&(0,Pl.default)(n,o)?o:n.length?(0,Ue.default)(n,-1):(0,Ue.default)(a,0)},bs=(s,e,t,i)=>{var u;let r=yn.get(e);r||(r=[...e].sort(gr(1)),yn.set(e,r));let a=yn.get(t);a||(a=[...t].sort(gr(1)),yn.set(t,a));let n=Pg.get(s);n||(n=a.filter(l=>(0,D.isNonNullable)(l.bitrate)&&(0,D.isNonNullable)(s.bitrate)?s.bitrate/l.bitrate>i:!0),Pg.set(s,n));let o=(u=(0,Ue.default)(a,Math.round(a.length*r.indexOf(s)/(r.length+1))))!=null?u:(0,Ue.default)(a,-1);return o&&(0,Pl.default)(n,o)?o:n.length?(0,Ue.default)(n,-1):(0,Ue.default)(a,0)},Rg=s=>"quality"in s,En=(s,e,t,i)=>{var n;let r=(0,D.isNonNullable)((n=i==null?void 0:i.last)==null?void 0:n.bitrate)&&(0,D.isNonNullable)(t==null?void 0:t.bitrate)&&i.last.bitrate<t.bitrate?s.trackCooldownIncreaseQuality:s.trackCooldownDecreaseQuality,a=t&&i&&i.history[t.id]&&(0,D.now)()-i.history[t.id]<=r&&(!i.last||t.id!==i.last.id);if(t!=null&&t.id&&i&&!a&&i.recordSelection(t),a&&(i!=null&&i.last)){let o=i.last;i==null||i.recordSwitch(o);let u=Rg(o)?"video":"audio",l=Rg(o)?o.quality:o.bitrate;return e({message:`
6
+ "use strict";var Oy=Object.create;var Ra=Object.defineProperty;var Fy=Object.getOwnPropertyDescriptor;var Ny=Object.getOwnPropertyNames;var qy=Object.getPrototypeOf,Uy=Object.prototype.hasOwnProperty;var v=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Hy=(s,e)=>{for(var t in e)Ra(s,t,{get:e[t],enumerable:!0})},nd=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ny(e))!Uy.call(s,r)&&r!==t&&Ra(s,r,{get:()=>e[r],enumerable:!(i=Fy(e,r))||i.enumerable});return s};var G=(s,e,t)=>(t=s!=null?Oy(qy(s)):{},nd(e||!s||!s.__esModule?Ra(t,"default",{value:s,enumerable:!0}):t,s)),jy=s=>nd(Ra({},"__esModule",{value:!0}),s);var Ie=v((xo,od)=>{"use strict";var Ur=function(s){return s&&s.Math===Math&&s};od.exports=Ur(typeof globalThis=="object"&&globalThis)||Ur(typeof window=="object"&&window)||Ur(typeof self=="object"&&self)||Ur(typeof global=="object"&&global)||Ur(typeof xo=="object"&&xo)||function(){return this}()||Function("return this")()});var Re=v((B$,ud)=>{"use strict";ud.exports=function(s){try{return!!s()}catch(e){return!0}}});var Hr=v((V$,ld)=>{"use strict";var Qy=Re();ld.exports=!Qy(function(){var s=function(){}.bind();return typeof s!="function"||s.hasOwnProperty("prototype")})});var wo=v((_$,hd)=>{"use strict";var Wy=Hr(),pd=Function.prototype,cd=pd.apply,dd=pd.call;hd.exports=typeof Reflect=="object"&&Reflect.apply||(Wy?dd.bind(cd):function(){return dd.apply(cd,arguments)})});var ke=v((O$,bd)=>{"use strict";var fd=Hr(),md=Function.prototype,Ao=md.call,Gy=fd&&md.bind.bind(Ao,Ao);bd.exports=fd?Gy:function(s){return function(){return Ao.apply(s,arguments)}}});var Ii=v((F$,vd)=>{"use strict";var gd=ke(),zy=gd({}.toString),Yy=gd("".slice);vd.exports=function(s){return Yy(zy(s),8,-1)}});var Po=v((N$,Sd)=>{"use strict";var Ky=Ii(),Xy=ke();Sd.exports=function(s){if(Ky(s)==="Function")return Xy(s)}});var Ee=v((q$,yd)=>{"use strict";var Ro=typeof document=="object"&&document.all;yd.exports=typeof Ro=="undefined"&&Ro!==void 0?function(s){return typeof s=="function"||s===Ro}:function(s){return typeof s=="function"}});var Ze=v((U$,Td)=>{"use strict";var Jy=Re();Td.exports=!Jy(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var et=v((H$,Id)=>{"use strict";var Zy=Hr(),$a=Function.prototype.call;Id.exports=Zy?$a.bind($a):function(){return $a.apply($a,arguments)}});var ko=v(wd=>{"use strict";var Ed={}.propertyIsEnumerable,xd=Object.getOwnPropertyDescriptor,eT=xd&&!Ed.call({1:2},1);wd.f=eT?function(e){var t=xd(this,e);return!!t&&t.enumerable}:Ed});var jr=v((Q$,Ad)=>{"use strict";Ad.exports=function(s,e){return{enumerable:!(s&1),configurable:!(s&2),writable:!(s&4),value:e}}});var Rd=v((W$,Pd)=>{"use strict";var tT=ke(),iT=Re(),rT=Ii(),Lo=Object,sT=tT("".split);Pd.exports=iT(function(){return!Lo("z").propertyIsEnumerable(0)})?function(s){return rT(s)==="String"?sT(s,""):Lo(s)}:Lo});var Qr=v((G$,kd)=>{"use strict";kd.exports=function(s){return s==null}});var ri=v((z$,Ld)=>{"use strict";var aT=Qr(),nT=TypeError;Ld.exports=function(s){if(aT(s))throw new nT("Can't call method on "+s);return s}});var Ei=v((Y$,$d)=>{"use strict";var oT=Rd(),uT=ri();$d.exports=function(s){return oT(uT(s))}});var He=v((K$,Md)=>{"use strict";var lT=Ee();Md.exports=function(s){return typeof s=="object"?s!==null:lT(s)}});var xi=v((X$,Dd)=>{"use strict";Dd.exports={}});var Ot=v((J$,Bd)=>{"use strict";var $o=xi(),Mo=Ie(),cT=Ee(),Cd=function(s){return cT(s)?s:void 0};Bd.exports=function(s,e){return arguments.length<2?Cd($o[s])||Cd(Mo[s]):$o[s]&&$o[s][e]||Mo[s]&&Mo[s][e]}});var Wr=v((Z$,Vd)=>{"use strict";var dT=ke();Vd.exports=dT({}.isPrototypeOf)});var wi=v((eM,Fd)=>{"use strict";var pT=Ie(),_d=pT.navigator,Od=_d&&_d.userAgent;Fd.exports=Od?String(Od):""});var Co=v((tM,Qd)=>{"use strict";var jd=Ie(),Do=wi(),Nd=jd.process,qd=jd.Deno,Ud=Nd&&Nd.versions||qd&&qd.version,Hd=Ud&&Ud.v8,bt,Ma;Hd&&(bt=Hd.split("."),Ma=bt[0]>0&&bt[0]<4?1:+(bt[0]+bt[1]));!Ma&&Do&&(bt=Do.match(/Edge\/(\d+)/),(!bt||bt[1]>=74)&&(bt=Do.match(/Chrome\/(\d+)/),bt&&(Ma=+bt[1])));Qd.exports=Ma});var Bo=v((iM,Gd)=>{"use strict";var Wd=Co(),hT=Re(),fT=Ie(),mT=fT.String;Gd.exports=!!Object.getOwnPropertySymbols&&!hT(function(){var s=Symbol("symbol detection");return!mT(s)||!(Object(s)instanceof Symbol)||!Symbol.sham&&Wd&&Wd<41})});var Vo=v((rM,zd)=>{"use strict";var bT=Bo();zd.exports=bT&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var _o=v((sM,Yd)=>{"use strict";var gT=Ot(),vT=Ee(),ST=Wr(),yT=Vo(),TT=Object;Yd.exports=yT?function(s){return typeof s=="symbol"}:function(s){var e=gT("Symbol");return vT(e)&&ST(e.prototype,TT(s))}});var Gr=v((aM,Kd)=>{"use strict";var IT=String;Kd.exports=function(s){try{return IT(s)}catch(e){return"Object"}}});var At=v((nM,Xd)=>{"use strict";var ET=Ee(),xT=Gr(),wT=TypeError;Xd.exports=function(s){if(ET(s))return s;throw new wT(xT(s)+" is not a function")}});var zr=v((oM,Jd)=>{"use strict";var AT=At(),PT=Qr();Jd.exports=function(s,e){var t=s[e];return PT(t)?void 0:AT(t)}});var ep=v((uM,Zd)=>{"use strict";var Oo=et(),Fo=Ee(),No=He(),RT=TypeError;Zd.exports=function(s,e){var t,i;if(e==="string"&&Fo(t=s.toString)&&!No(i=Oo(t,s))||Fo(t=s.valueOf)&&!No(i=Oo(t,s))||e!=="string"&&Fo(t=s.toString)&&!No(i=Oo(t,s)))return i;throw new RT("Can't convert object to primitive value")}});var gt=v((lM,tp)=>{"use strict";tp.exports=!0});var sp=v((cM,rp)=>{"use strict";var ip=Ie(),kT=Object.defineProperty;rp.exports=function(s,e){try{kT(ip,s,{value:e,configurable:!0,writable:!0})}catch(t){ip[s]=e}return e}});var Yr=v((dM,op)=>{"use strict";var LT=gt(),$T=Ie(),MT=sp(),ap="__core-js_shared__",np=op.exports=$T[ap]||MT(ap,{});(np.versions||(np.versions=[])).push({version:"3.43.0",mode:LT?"pure":"global",copyright:"\xA9 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var qo=v((pM,lp)=>{"use strict";var up=Yr();lp.exports=function(s,e){return up[s]||(up[s]=e||{})}});var Xi=v((hM,cp)=>{"use strict";var DT=ri(),CT=Object;cp.exports=function(s){return CT(DT(s))}});var vt=v((fM,dp)=>{"use strict";var BT=ke(),VT=Xi(),_T=BT({}.hasOwnProperty);dp.exports=Object.hasOwn||function(e,t){return _T(VT(e),t)}});var Uo=v((mM,pp)=>{"use strict";var OT=ke(),FT=0,NT=Math.random(),qT=OT(1.1.toString);pp.exports=function(s){return"Symbol("+(s===void 0?"":s)+")_"+qT(++FT+NT,36)}});var Be=v((bM,fp)=>{"use strict";var UT=Ie(),HT=qo(),hp=vt(),jT=Uo(),QT=Bo(),WT=Vo(),Ji=UT.Symbol,Ho=HT("wks"),GT=WT?Ji.for||Ji:Ji&&Ji.withoutSetter||jT;fp.exports=function(s){return hp(Ho,s)||(Ho[s]=QT&&hp(Ji,s)?Ji[s]:GT("Symbol."+s)),Ho[s]}});var vp=v((gM,gp)=>{"use strict";var zT=et(),mp=He(),bp=_o(),YT=zr(),KT=ep(),XT=Be(),JT=TypeError,ZT=XT("toPrimitive");gp.exports=function(s,e){if(!mp(s)||bp(s))return s;var t=YT(s,ZT),i;if(t){if(e===void 0&&(e="default"),i=zT(t,s,e),!mp(i)||bp(i))return i;throw new JT("Can't convert object to primitive value")}return e===void 0&&(e="number"),KT(s,e)}});var jo=v((vM,Sp)=>{"use strict";var eI=vp(),tI=_o();Sp.exports=function(s){var e=eI(s,"string");return tI(e)?e:e+""}});var Da=v((SM,Tp)=>{"use strict";var iI=Ie(),yp=He(),Qo=iI.document,rI=yp(Qo)&&yp(Qo.createElement);Tp.exports=function(s){return rI?Qo.createElement(s):{}}});var Wo=v((yM,Ip)=>{"use strict";var sI=Ze(),aI=Re(),nI=Da();Ip.exports=!sI&&!aI(function(){return Object.defineProperty(nI("div"),"a",{get:function(){return 7}}).a!==7})});var wp=v(xp=>{"use strict";var oI=Ze(),uI=et(),lI=ko(),cI=jr(),dI=Ei(),pI=jo(),hI=vt(),fI=Wo(),Ep=Object.getOwnPropertyDescriptor;xp.f=oI?Ep:function(e,t){if(e=dI(e),t=pI(t),fI)try{return Ep(e,t)}catch(i){}if(hI(e,t))return cI(!uI(lI.f,e,t),e[t])}});var Go=v((IM,Ap)=>{"use strict";var mI=Re(),bI=Ee(),gI=/#|\.prototype\./,Kr=function(s,e){var t=SI[vI(s)];return t===TI?!0:t===yI?!1:bI(e)?mI(e):!!e},vI=Kr.normalize=function(s){return String(s).replace(gI,".").toLowerCase()},SI=Kr.data={},yI=Kr.NATIVE="N",TI=Kr.POLYFILL="P";Ap.exports=Kr});var Zi=v((EM,Rp)=>{"use strict";var Pp=Po(),II=At(),EI=Hr(),xI=Pp(Pp.bind);Rp.exports=function(s,e){return II(s),e===void 0?s:EI?xI(s,e):function(){return s.apply(e,arguments)}}});var zo=v((xM,kp)=>{"use strict";var wI=Ze(),AI=Re();kp.exports=wI&&AI(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Pt=v((wM,Lp)=>{"use strict";var PI=He(),RI=String,kI=TypeError;Lp.exports=function(s){if(PI(s))return s;throw new kI(RI(s)+" is not an object")}});var Ai=v(Mp=>{"use strict";var LI=Ze(),$I=Wo(),MI=zo(),Ca=Pt(),$p=jo(),DI=TypeError,Yo=Object.defineProperty,CI=Object.getOwnPropertyDescriptor,Ko="enumerable",Xo="configurable",Jo="writable";Mp.f=LI?MI?function(e,t,i){if(Ca(e),t=$p(t),Ca(i),typeof e=="function"&&t==="prototype"&&"value"in i&&Jo in i&&!i[Jo]){var r=CI(e,t);r&&r[Jo]&&(e[t]=i.value,i={configurable:Xo in i?i[Xo]:r[Xo],enumerable:Ko in i?i[Ko]:r[Ko],writable:!1})}return Yo(e,t,i)}:Yo:function(e,t,i){if(Ca(e),t=$p(t),Ca(i),$I)try{return Yo(e,t,i)}catch(r){}if("get"in i||"set"in i)throw new DI("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var er=v((PM,Dp)=>{"use strict";var BI=Ze(),VI=Ai(),_I=jr();Dp.exports=BI?function(s,e,t){return VI.f(s,e,_I(1,t))}:function(s,e,t){return s[e]=t,s}});var Ae=v((RM,Bp)=>{"use strict";var Xr=Ie(),OI=wo(),FI=Po(),NI=Ee(),qI=wp().f,UI=Go(),tr=xi(),HI=Zi(),ir=er(),Cp=vt();Yr();var jI=function(s){var e=function(t,i,r){if(this instanceof e){switch(arguments.length){case 0:return new s;case 1:return new s(t);case 2:return new s(t,i)}return new s(t,i,r)}return OI(s,this,arguments)};return e.prototype=s.prototype,e};Bp.exports=function(s,e){var t=s.target,i=s.global,r=s.stat,a=s.proto,n=i?Xr:r?Xr[t]:Xr[t]&&Xr[t].prototype,o=i?tr:tr[t]||ir(tr,t,{})[t],u=o.prototype,l,c,d,f,p,h,b,S,g;for(f in e)l=UI(i?f:t+(r?".":"#")+f,s.forced),c=!l&&n&&Cp(n,f),h=o[f],c&&(s.dontCallGetSet?(g=qI(n,f),b=g&&g.value):b=n[f]),p=c&&b?b:e[f],!(!l&&!a&&typeof h==typeof p)&&(s.bind&&c?S=HI(p,Xr):s.wrap&&c?S=jI(p):a&&NI(p)?S=FI(p):S=p,(s.sham||p&&p.sham||h&&h.sham)&&ir(S,"sham",!0),ir(o,f,S),a&&(d=t+"Prototype",Cp(tr,d)||ir(tr,d,{}),ir(tr[d],f,p),s.real&&u&&(l||!u[f])&&ir(u,f,p)))}});var Ba=v((kM,_p)=>{"use strict";var QI=qo(),WI=Uo(),Vp=QI("keys");_p.exports=function(s){return Vp[s]||(Vp[s]=WI(s))}});var Fp=v((LM,Op)=>{"use strict";var GI=Re();Op.exports=!GI(function(){function s(){}return s.prototype.constructor=null,Object.getPrototypeOf(new s)!==s.prototype})});var Va=v(($M,qp)=>{"use strict";var zI=vt(),YI=Ee(),KI=Xi(),XI=Ba(),JI=Fp(),Np=XI("IE_PROTO"),Zo=Object,ZI=Zo.prototype;qp.exports=JI?Zo.getPrototypeOf:function(s){var e=KI(s);if(zI(e,Np))return e[Np];var t=e.constructor;return YI(t)&&e instanceof t?t.prototype:e instanceof Zo?ZI:null}});var Hp=v((MM,Up)=>{"use strict";var eE=Math.ceil,tE=Math.floor;Up.exports=Math.trunc||function(e){var t=+e;return(t>0?tE:eE)(t)}});var Jr=v((DM,jp)=>{"use strict";var iE=Hp();jp.exports=function(s){var e=+s;return e!==e||e===0?0:iE(e)}});var Wp=v((CM,Qp)=>{"use strict";var rE=Jr(),sE=Math.max,aE=Math.min;Qp.exports=function(s,e){var t=rE(s);return t<0?sE(t+e,0):aE(t,e)}});var eu=v((BM,Gp)=>{"use strict";var nE=Jr(),oE=Math.min;Gp.exports=function(s){var e=nE(s);return e>0?oE(e,9007199254740991):0}});var rr=v((VM,zp)=>{"use strict";var uE=eu();zp.exports=function(s){return uE(s.length)}});var tu=v((_M,Kp)=>{"use strict";var lE=Ei(),cE=Wp(),dE=rr(),Yp=function(s){return function(e,t,i){var r=lE(e),a=dE(r);if(a===0)return!s&&-1;var n=cE(i,a),o;if(s&&t!==t){for(;a>n;)if(o=r[n++],o!==o)return!0}else for(;a>n;n++)if((s||n in r)&&r[n]===t)return s||n||0;return!s&&-1}};Kp.exports={includes:Yp(!0),indexOf:Yp(!1)}});var _a=v((OM,Xp)=>{"use strict";Xp.exports={}});var eh=v((FM,Zp)=>{"use strict";var pE=ke(),iu=vt(),hE=Ei(),fE=tu().indexOf,mE=_a(),Jp=pE([].push);Zp.exports=function(s,e){var t=hE(s),i=0,r=[],a;for(a in t)!iu(mE,a)&&iu(t,a)&&Jp(r,a);for(;e.length>i;)iu(t,a=e[i++])&&(~fE(r,a)||Jp(r,a));return r}});var ru=v((NM,th)=>{"use strict";th.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var su=v((qM,ih)=>{"use strict";var bE=eh(),gE=ru();ih.exports=Object.keys||function(e){return bE(e,gE)}});var au=v((UM,oh)=>{"use strict";var sh=Ze(),vE=Re(),ah=ke(),SE=Va(),yE=su(),TE=Ei(),IE=ko().f,nh=ah(IE),EE=ah([].push),xE=sh&&vE(function(){var s=Object.create(null);return s[2]=2,!nh(s,2)}),rh=function(s){return function(e){for(var t=TE(e),i=yE(t),r=xE&&SE(t)===null,a=i.length,n=0,o=[],u;a>n;)u=i[n++],(!sh||(r?u in t:nh(t,u)))&&EE(o,s?[u,t[u]]:t[u]);return o}};oh.exports={entries:rh(!0),values:rh(!1)}});var uh=v(()=>{"use strict";var wE=Ae(),AE=au().values;wE({target:"Object",stat:!0},{values:function(e){return AE(e)}})});var ch=v((QM,lh)=>{"use strict";uh();var PE=xi();lh.exports=PE.Object.values});var ph=v((WM,dh)=>{"use strict";var RE=ch();dh.exports=RE});var Pi=v((GM,hh)=>{"use strict";var kE=ph();hh.exports=kE});var Zr=v((zM,fh)=>{"use strict";fh.exports=function(){}});var mh=v(()=>{"use strict";var LE=Ae(),$E=tu().includes,ME=Re(),DE=Zr(),CE=ME(function(){return!Array(1).includes()});LE({target:"Array",proto:!0,forced:CE},{includes:function(e){return $E(this,e,arguments.length>1?arguments[1]:void 0)}});DE("includes")});var si=v((XM,bh)=>{"use strict";var BE=Ot();bh.exports=BE});var vh=v((JM,gh)=>{"use strict";mh();var VE=si();gh.exports=VE("Array","includes")});var yh=v((ZM,Sh)=>{"use strict";var _E=vh();Sh.exports=_E});var Ne=v((eD,Th)=>{"use strict";var OE=yh();Th.exports=OE});var Eh=v(()=>{"use strict";var NE=Ae(),qE=au().entries;NE({target:"Object",stat:!0},{entries:function(e){return qE(e)}})});var wh=v((hD,xh)=>{"use strict";Eh();var UE=xi();xh.exports=UE.Object.entries});var Ph=v((fD,Ah)=>{"use strict";var HE=wh();Ah.exports=HE});var sr=v((mD,Rh)=>{"use strict";var jE=Ph();Rh.exports=jE});var Ri=v((bD,kh)=>{"use strict";kh.exports={}});var Mh=v((gD,$h)=>{"use strict";var QE=Ie(),WE=Ee(),Lh=QE.WeakMap;$h.exports=WE(Lh)&&/native code/.test(String(Lh))});var lu=v((vD,Bh)=>{"use strict";var GE=Mh(),Ch=Ie(),zE=He(),YE=er(),nu=vt(),ou=Yr(),KE=Ba(),XE=_a(),Dh="Object already initialized",uu=Ch.TypeError,JE=Ch.WeakMap,Fa,es,Na,ZE=function(s){return Na(s)?es(s):Fa(s,{})},ex=function(s){return function(e){var t;if(!zE(e)||(t=es(e)).type!==s)throw new uu("Incompatible receiver, "+s+" required");return t}};GE||ou.state?(St=ou.state||(ou.state=new JE),St.get=St.get,St.has=St.has,St.set=St.set,Fa=function(s,e){if(St.has(s))throw new uu(Dh);return e.facade=s,St.set(s,e),e},es=function(s){return St.get(s)||{}},Na=function(s){return St.has(s)}):(ki=KE("state"),XE[ki]=!0,Fa=function(s,e){if(nu(s,ki))throw new uu(Dh);return e.facade=s,YE(s,ki,e),e},es=function(s){return nu(s,ki)?s[ki]:{}},Na=function(s){return nu(s,ki)});var St,ki;Bh.exports={set:Fa,get:es,has:Na,enforce:ZE,getterFor:ex}});var pu=v((SD,_h)=>{"use strict";var cu=Ze(),tx=vt(),Vh=Function.prototype,ix=cu&&Object.getOwnPropertyDescriptor,du=tx(Vh,"name"),rx=du&&function(){}.name==="something",sx=du&&(!cu||cu&&ix(Vh,"name").configurable);_h.exports={EXISTS:du,PROPER:rx,CONFIGURABLE:sx}});var Fh=v(Oh=>{"use strict";var ax=Ze(),nx=zo(),ox=Ai(),ux=Pt(),lx=Ei(),cx=su();Oh.f=ax&&!nx?Object.defineProperties:function(e,t){ux(e);for(var i=lx(t),r=cx(t),a=r.length,n=0,o;a>n;)ox.f(e,o=r[n++],i[o]);return e}});var hu=v((TD,Nh)=>{"use strict";var dx=Ot();Nh.exports=dx("document","documentElement")});var gu=v((ID,Gh)=>{"use strict";var px=Pt(),hx=Fh(),qh=ru(),fx=_a(),mx=hu(),bx=Da(),gx=Ba(),Uh=">",Hh="<",mu="prototype",bu="script",Qh=gx("IE_PROTO"),fu=function(){},Wh=function(s){return Hh+bu+Uh+s+Hh+"/"+bu+Uh},jh=function(s){s.write(Wh("")),s.close();var e=s.parentWindow.Object;return s=null,e},vx=function(){var s=bx("iframe"),e="java"+bu+":",t;return s.style.display="none",mx.appendChild(s),s.src=String(e),t=s.contentWindow.document,t.open(),t.write(Wh("document.F=Object")),t.close(),t.F},qa,Ua=function(){try{qa=new ActiveXObject("htmlfile")}catch(e){}Ua=typeof document!="undefined"?document.domain&&qa?jh(qa):vx():jh(qa);for(var s=qh.length;s--;)delete Ua[mu][qh[s]];return Ua()};fx[Qh]=!0;Gh.exports=Object.create||function(e,t){var i;return e!==null?(fu[mu]=px(e),i=new fu,fu[mu]=null,i[Qh]=e):i=Ua(),t===void 0?i:hx.f(i,t)}});var ar=v((ED,zh)=>{"use strict";var Sx=er();zh.exports=function(s,e,t,i){return i&&i.enumerable?s[e]=t:Sx(s,e,t),s}});var Tu=v((xD,Xh)=>{"use strict";var yx=Re(),Tx=Ee(),Ix=He(),Ex=gu(),Yh=Va(),xx=ar(),wx=Be(),Ax=gt(),yu=wx("iterator"),Kh=!1,Ft,vu,Su;[].keys&&(Su=[].keys(),"next"in Su?(vu=Yh(Yh(Su)),vu!==Object.prototype&&(Ft=vu)):Kh=!0);var Px=!Ix(Ft)||yx(function(){var s={};return Ft[yu].call(s)!==s});Px?Ft={}:Ax&&(Ft=Ex(Ft));Tx(Ft[yu])||xx(Ft,yu,function(){return this});Xh.exports={IteratorPrototype:Ft,BUGGY_SAFARI_ITERATORS:Kh}});var Ha=v((wD,Zh)=>{"use strict";var Rx=Be(),kx=Rx("toStringTag"),Jh={};Jh[kx]="z";Zh.exports=String(Jh)==="[object z]"});var ts=v((AD,ef)=>{"use strict";var Lx=Ha(),$x=Ee(),ja=Ii(),Mx=Be(),Dx=Mx("toStringTag"),Cx=Object,Bx=ja(function(){return arguments}())==="Arguments",Vx=function(s,e){try{return s[e]}catch(t){}};ef.exports=Lx?ja:function(s){var e,t,i;return s===void 0?"Undefined":s===null?"Null":typeof(t=Vx(e=Cx(s),Dx))=="string"?t:Bx?ja(e):(i=ja(e))==="Object"&&$x(e.callee)?"Arguments":i}});var rf=v((PD,tf)=>{"use strict";var _x=Ha(),Ox=ts();tf.exports=_x?{}.toString:function(){return"[object "+Ox(this)+"]"}});var is=v((RD,af)=>{"use strict";var Fx=Ha(),Nx=Ai().f,qx=er(),Ux=vt(),Hx=rf(),jx=Be(),sf=jx("toStringTag");af.exports=function(s,e,t,i){var r=t?s:s&&s.prototype;r&&(Ux(r,sf)||Nx(r,sf,{configurable:!0,value:e}),i&&!Fx&&qx(r,"toString",Hx))}});var of=v((kD,nf)=>{"use strict";var Qx=Tu().IteratorPrototype,Wx=gu(),Gx=jr(),zx=is(),Yx=Ri(),Kx=function(){return this};nf.exports=function(s,e,t,i){var r=e+" Iterator";return s.prototype=Wx(Qx,{next:Gx(+!i,t)}),zx(s,r,!1,!0),Yx[r]=Kx,s}});var lf=v((LD,uf)=>{"use strict";var Xx=ke(),Jx=At();uf.exports=function(s,e,t){try{return Xx(Jx(Object.getOwnPropertyDescriptor(s,e)[t]))}catch(i){}}});var df=v(($D,cf)=>{"use strict";var Zx=He();cf.exports=function(s){return Zx(s)||s===null}});var hf=v((MD,pf)=>{"use strict";var ew=df(),tw=String,iw=TypeError;pf.exports=function(s){if(ew(s))return s;throw new iw("Can't set "+tw(s)+" as a prototype")}});var Iu=v((DD,ff)=>{"use strict";var rw=lf(),sw=He(),aw=ri(),nw=hf();ff.exports=Object.setPrototypeOf||("__proto__"in{}?function(){var s=!1,e={},t;try{t=rw(Object.prototype,"__proto__","set"),t(e,[]),s=e instanceof Array}catch(i){}return function(r,a){return aw(r),nw(a),sw(r)&&(s?t(r,a):r.__proto__=a),r}}():void 0)});var wf=v((CD,xf)=>{"use strict";var ow=Ae(),uw=et(),Qa=gt(),If=pu(),lw=Ee(),cw=of(),mf=Va(),bf=Iu(),dw=is(),pw=er(),Eu=ar(),hw=Be(),gf=Ri(),Ef=Tu(),fw=If.PROPER,mw=If.CONFIGURABLE,vf=Ef.IteratorPrototype,Wa=Ef.BUGGY_SAFARI_ITERATORS,rs=hw("iterator"),Sf="keys",ss="values",yf="entries",Tf=function(){return this};xf.exports=function(s,e,t,i,r,a,n){cw(t,e,i);var o=function(g){if(g===r&&f)return f;if(!Wa&&g&&g in c)return c[g];switch(g){case Sf:return function(){return new t(this,g)};case ss:return function(){return new t(this,g)};case yf:return function(){return new t(this,g)}}return function(){return new t(this)}},u=e+" Iterator",l=!1,c=s.prototype,d=c[rs]||c["@@iterator"]||r&&c[r],f=!Wa&&d||o(r),p=e==="Array"&&c.entries||d,h,b,S;if(p&&(h=mf(p.call(new s)),h!==Object.prototype&&h.next&&(!Qa&&mf(h)!==vf&&(bf?bf(h,vf):lw(h[rs])||Eu(h,rs,Tf)),dw(h,u,!0,!0),Qa&&(gf[u]=Tf))),fw&&r===ss&&d&&d.name!==ss&&(!Qa&&mw?pw(c,"name",ss):(l=!0,f=function(){return uw(d,this)})),r)if(b={values:o(ss),keys:a?f:o(Sf),entries:o(yf)},n)for(S in b)(Wa||l||!(S in c))&&Eu(c,S,b[S]);else ow({target:e,proto:!0,forced:Wa||l},b);return(!Qa||n)&&c[rs]!==f&&Eu(c,rs,f,{name:r}),gf[e]=f,b}});var Pf=v((BD,Af)=>{"use strict";Af.exports=function(s,e){return{value:s,done:e}}});var wu=v((VD,Mf)=>{"use strict";var bw=Ei(),xu=Zr(),Rf=Ri(),Lf=lu(),gw=Ai().f,vw=wf(),Ga=Pf(),Sw=gt(),yw=Ze(),$f="Array Iterator",Tw=Lf.set,Iw=Lf.getterFor($f);Mf.exports=vw(Array,"Array",function(s,e){Tw(this,{type:$f,target:bw(s),index:0,kind:e})},function(){var s=Iw(this),e=s.target,t=s.index++;if(!e||t>=e.length)return s.target=null,Ga(void 0,!0);switch(s.kind){case"keys":return Ga(t,!1);case"values":return Ga(e[t],!1)}return Ga([t,e[t]],!1)},"values");var kf=Rf.Arguments=Rf.Array;xu("keys");xu("values");xu("entries");if(!Sw&&yw&&kf.name!=="values")try{gw(kf,"name",{value:"values"})}catch(s){}});var Cf=v((_D,Df)=>{"use strict";var Ew=Be(),xw=Ri(),ww=Ew("iterator"),Aw=Array.prototype;Df.exports=function(s){return s!==void 0&&(xw.Array===s||Aw[ww]===s)}});var Au=v((OD,Vf)=>{"use strict";var Pw=ts(),Bf=zr(),Rw=Qr(),kw=Ri(),Lw=Be(),$w=Lw("iterator");Vf.exports=function(s){if(!Rw(s))return Bf(s,$w)||Bf(s,"@@iterator")||kw[Pw(s)]}});var Of=v((FD,_f)=>{"use strict";var Mw=et(),Dw=At(),Cw=Pt(),Bw=Gr(),Vw=Au(),_w=TypeError;_f.exports=function(s,e){var t=arguments.length<2?Vw(s):e;if(Dw(t))return Cw(Mw(t,s));throw new _w(Bw(s)+" is not iterable")}});var qf=v((ND,Nf)=>{"use strict";var Ow=et(),Ff=Pt(),Fw=zr();Nf.exports=function(s,e,t){var i,r;Ff(s);try{if(i=Fw(s,"return"),!i){if(e==="throw")throw t;return t}i=Ow(i,s)}catch(a){r=!0,i=a}if(e==="throw")throw t;if(r)throw i;return Ff(i),t}});var Ya=v((qD,Qf)=>{"use strict";var Nw=Zi(),qw=et(),Uw=Pt(),Hw=Gr(),jw=Cf(),Qw=rr(),Uf=Wr(),Ww=Of(),Gw=Au(),Hf=qf(),zw=TypeError,za=function(s,e){this.stopped=s,this.result=e},jf=za.prototype;Qf.exports=function(s,e,t){var i=t&&t.that,r=!!(t&&t.AS_ENTRIES),a=!!(t&&t.IS_RECORD),n=!!(t&&t.IS_ITERATOR),o=!!(t&&t.INTERRUPTED),u=Nw(e,i),l,c,d,f,p,h,b,S=function(I){return l&&Hf(l,"normal"),new za(!0,I)},g=function(I){return r?(Uw(I),o?u(I[0],I[1],S):u(I[0],I[1])):o?u(I,S):u(I)};if(a)l=s.iterator;else if(n)l=s;else{if(c=Gw(s),!c)throw new zw(Hw(s)+" is not iterable");if(jw(c)){for(d=0,f=Qw(s);f>d;d++)if(p=g(s[d]),p&&Uf(jf,p))return p;return new za(!1)}l=Ww(s,c)}for(h=a?s.next:l.next;!(b=qw(h,l)).done;){try{p=g(b.value)}catch(I){Hf(l,"throw",I)}if(typeof p=="object"&&p&&Uf(jf,p))return p}return new za(!1)}});var Gf=v((UD,Wf)=>{"use strict";var Yw=Ze(),Kw=Ai(),Xw=jr();Wf.exports=function(s,e,t){Yw?Kw.f(s,e,Xw(0,t)):s[e]=t}});var zf=v(()=>{"use strict";var Jw=Ae(),Zw=Ya(),eA=Gf();Jw({target:"Object",stat:!0},{fromEntries:function(e){var t={};return Zw(e,function(i,r){eA(t,i,r)},{AS_ENTRIES:!0}),t}})});var Kf=v((QD,Yf)=>{"use strict";wu();zf();var tA=xi();Yf.exports=tA.Object.fromEntries});var Jf=v((WD,Xf)=>{"use strict";Xf.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}});var em=v(()=>{"use strict";wu();var iA=Jf(),rA=Ie(),sA=is(),Zf=Ri();for(Ka in iA)sA(rA[Ka],Ka),Zf[Ka]=Zf.Array;var Ka});var im=v((YD,tm)=>{"use strict";var aA=Kf();em();tm.exports=aA});var Pu=v((KD,rm)=>{"use strict";var nA=im();rm.exports=nA});var sm=v(()=>{"use strict"});var Ru=v((ZD,am)=>{"use strict";var as=Ie(),oA=wi(),uA=Ii(),Xa=function(s){return oA.slice(0,s.length)===s};am.exports=function(){return Xa("Bun/")?"BUN":Xa("Cloudflare-Workers")?"CLOUDFLARE":Xa("Deno/")?"DENO":Xa("Node.js/")?"NODE":as.Bun&&typeof Bun.version=="string"?"BUN":as.Deno&&typeof Deno.version=="object"?"DENO":uA(as.process)==="process"?"NODE":as.window&&as.document?"BROWSER":"REST"}()});var Ja=v((eC,nm)=>{"use strict";var lA=Ru();nm.exports=lA==="NODE"});var um=v((tC,om)=>{"use strict";var cA=Ai();om.exports=function(s,e,t){return cA.f(s,e,t)}});var dm=v((iC,cm)=>{"use strict";var dA=Ot(),pA=um(),hA=Be(),fA=Ze(),lm=hA("species");cm.exports=function(s){var e=dA(s);fA&&e&&!e[lm]&&pA(e,lm,{configurable:!0,get:function(){return this}})}});var hm=v((rC,pm)=>{"use strict";var mA=Wr(),bA=TypeError;pm.exports=function(s,e){if(mA(e,s))return s;throw new bA("Incorrect invocation")}});var Lu=v((sC,fm)=>{"use strict";var gA=ke(),vA=Ee(),ku=Yr(),SA=gA(Function.toString);vA(ku.inspectSource)||(ku.inspectSource=function(s){return SA(s)});fm.exports=ku.inspectSource});var Mu=v((aC,Sm)=>{"use strict";var yA=ke(),TA=Re(),mm=Ee(),IA=ts(),EA=Ot(),xA=Lu(),bm=function(){},gm=EA("Reflect","construct"),$u=/^\s*(?:class|function)\b/,wA=yA($u.exec),AA=!$u.test(bm),ns=function(e){if(!mm(e))return!1;try{return gm(bm,[],e),!0}catch(t){return!1}},vm=function(e){if(!mm(e))return!1;switch(IA(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return AA||!!wA($u,xA(e))}catch(t){return!0}};vm.sham=!0;Sm.exports=!gm||TA(function(){var s;return ns(ns.call)||!ns(Object)||!ns(function(){s=!0})||s})?vm:ns});var Tm=v((nC,ym)=>{"use strict";var PA=Mu(),RA=Gr(),kA=TypeError;ym.exports=function(s){if(PA(s))return s;throw new kA(RA(s)+" is not a constructor")}});var Du=v((oC,Em)=>{"use strict";var Im=Pt(),LA=Tm(),$A=Qr(),MA=Be(),DA=MA("species");Em.exports=function(s,e){var t=Im(s).constructor,i;return t===void 0||$A(i=Im(t)[DA])?e:LA(i)}});var wm=v((uC,xm)=>{"use strict";var CA=ke();xm.exports=CA([].slice)});var Pm=v((lC,Am)=>{"use strict";var BA=TypeError;Am.exports=function(s,e){if(s<e)throw new BA("Not enough arguments");return s}});var Cu=v((cC,Rm)=>{"use strict";var VA=wi();Rm.exports=/(?:ipad|iphone|ipod).*applewebkit/i.test(VA)});var Hu=v((dC,_m)=>{"use strict";var tt=Ie(),_A=wo(),OA=Zi(),km=Ee(),FA=vt(),Vm=Re(),Lm=hu(),NA=wm(),$m=Da(),qA=Pm(),UA=Cu(),HA=Ja(),Nu=tt.setImmediate,qu=tt.clearImmediate,jA=tt.process,Bu=tt.Dispatch,QA=tt.Function,Mm=tt.MessageChannel,WA=tt.String,Vu=0,os={},Dm="onreadystatechange",us,Li,_u,Ou;Vm(function(){us=tt.location});var Uu=function(s){if(FA(os,s)){var e=os[s];delete os[s],e()}},Fu=function(s){return function(){Uu(s)}},Cm=function(s){Uu(s.data)},Bm=function(s){tt.postMessage(WA(s),us.protocol+"//"+us.host)};(!Nu||!qu)&&(Nu=function(e){qA(arguments.length,1);var t=km(e)?e:QA(e),i=NA(arguments,1);return os[++Vu]=function(){_A(t,void 0,i)},Li(Vu),Vu},qu=function(e){delete os[e]},HA?Li=function(s){jA.nextTick(Fu(s))}:Bu&&Bu.now?Li=function(s){Bu.now(Fu(s))}:Mm&&!UA?(_u=new Mm,Ou=_u.port2,_u.port1.onmessage=Cm,Li=OA(Ou.postMessage,Ou)):tt.addEventListener&&km(tt.postMessage)&&!tt.importScripts&&us&&us.protocol!=="file:"&&!Vm(Bm)?(Li=Bm,tt.addEventListener("message",Cm,!1)):Dm in $m("script")?Li=function(s){Lm.appendChild($m("script"))[Dm]=function(){Lm.removeChild(this),Uu(s)}}:Li=function(s){setTimeout(Fu(s),0)});_m.exports={set:Nu,clear:qu}});var Nm=v((pC,Fm)=>{"use strict";var Om=Ie(),GA=Ze(),zA=Object.getOwnPropertyDescriptor;Fm.exports=function(s){if(!GA)return Om[s];var e=zA(Om,s);return e&&e.value}});var ju=v((hC,Um)=>{"use strict";var qm=function(){this.head=null,this.tail=null};qm.prototype={add:function(s){var e={item:s,next:null},t=this.tail;t?t.next=e:this.head=e,this.tail=e},get:function(){var s=this.head;if(s){var e=this.head=s.next;return e===null&&(this.tail=null),s.item}}};Um.exports=qm});var jm=v((fC,Hm)=>{"use strict";var YA=wi();Hm.exports=/ipad|iphone|ipod/i.test(YA)&&typeof Pebble!="undefined"});var Wm=v((mC,Qm)=>{"use strict";var KA=wi();Qm.exports=/web0s(?!.*chrome)/i.test(KA)});var Zm=v((bC,Jm)=>{"use strict";var or=Ie(),XA=Nm(),Gm=Zi(),Qu=Hu().set,JA=ju(),ZA=Cu(),eP=jm(),tP=Wm(),Wu=Ja(),zm=or.MutationObserver||or.WebKitMutationObserver,Ym=or.document,Km=or.process,Za=or.Promise,Yu=XA("queueMicrotask"),nr,Gu,zu,en,Xm;Yu||(ls=new JA,cs=function(){var s,e;for(Wu&&(s=Km.domain)&&s.exit();e=ls.get();)try{e()}catch(t){throw ls.head&&nr(),t}s&&s.enter()},!ZA&&!Wu&&!tP&&zm&&Ym?(Gu=!0,zu=Ym.createTextNode(""),new zm(cs).observe(zu,{characterData:!0}),nr=function(){zu.data=Gu=!Gu}):!eP&&Za&&Za.resolve?(en=Za.resolve(void 0),en.constructor=Za,Xm=Gm(en.then,en),nr=function(){Xm(cs)}):Wu?nr=function(){Km.nextTick(cs)}:(Qu=Gm(Qu,or),nr=function(){Qu(cs)}),Yu=function(s){ls.head||nr(),ls.add(s)});var ls,cs;Jm.exports=Yu});var tb=v((gC,eb)=>{"use strict";eb.exports=function(s,e){try{arguments.length===1?console.error(s):console.error(s,e)}catch(t){}}});var tn=v((vC,ib)=>{"use strict";ib.exports=function(s){try{return{error:!1,value:s()}}catch(e){return{error:!0,value:e}}}});var $i=v((SC,rb)=>{"use strict";var iP=Ie();rb.exports=iP.Promise});var ur=v((yC,ob)=>{"use strict";var rP=Ie(),ds=$i(),sP=Ee(),aP=Go(),nP=Lu(),oP=Be(),sb=Ru(),uP=gt(),Ku=Co(),ab=ds&&ds.prototype,lP=oP("species"),Xu=!1,nb=sP(rP.PromiseRejectionEvent),cP=aP("Promise",function(){var s=nP(ds),e=s!==String(ds);if(!e&&Ku===66||uP&&!(ab.catch&&ab.finally))return!0;if(!Ku||Ku<51||!/native code/.test(s)){var t=new ds(function(a){a(1)}),i=function(a){a(function(){},function(){})},r=t.constructor={};if(r[lP]=i,Xu=t.then(function(){})instanceof i,!Xu)return!0}return!e&&(sb==="BROWSER"||sb==="DENO")&&!nb});ob.exports={CONSTRUCTOR:cP,REJECTION_EVENT:nb,SUBCLASSING:Xu}});var lr=v((TC,lb)=>{"use strict";var ub=At(),dP=TypeError,pP=function(s){var e,t;this.promise=new s(function(i,r){if(e!==void 0||t!==void 0)throw new dP("Bad Promise constructor");e=i,t=r}),this.resolve=ub(e),this.reject=ub(t)};lb.exports.f=function(s){return new pP(s)}});var kb=v(()=>{"use strict";var hP=Ae(),fP=gt(),nn=Ja(),ai=Ie(),mP=xi(),hr=et(),cb=ar(),db=Iu(),bP=is(),gP=dm(),vP=At(),an=Ee(),SP=He(),yP=hm(),TP=Du(),bb=Hu().set,il=Zm(),IP=tb(),EP=tn(),xP=ju(),gb=lu(),on=$i(),rl=ur(),vb=lr(),un="Promise",Sb=rl.CONSTRUCTOR,wP=rl.REJECTION_EVENT,AP=rl.SUBCLASSING,Ju=gb.getterFor(un),PP=gb.set,cr=on&&on.prototype,Mi=on,rn=cr,yb=ai.TypeError,Zu=ai.document,sl=ai.process,el=vb.f,RP=el,kP=!!(Zu&&Zu.createEvent&&ai.dispatchEvent),Tb="unhandledrejection",LP="rejectionhandled",pb=0,Ib=1,$P=2,al=1,Eb=2,sn,hb,xb,fb,wb=function(s){var e;return SP(s)&&an(e=s.then)?e:!1},Ab=function(s,e){var t=e.value,i=e.state===Ib,r=i?s.ok:s.fail,a=s.resolve,n=s.reject,o=s.domain,u,l,c;try{r?(i||(e.rejection===Eb&&DP(e),e.rejection=al),r===!0?u=t:(o&&o.enter(),u=r(t),o&&(o.exit(),c=!0)),u===s.promise?n(new yb("Promise-chain cycle")):(l=wb(u))?hr(l,u,a,n):a(u)):n(t)}catch(d){o&&!c&&o.exit(),n(d)}},Pb=function(s,e){s.notified||(s.notified=!0,il(function(){for(var t=s.reactions,i;i=t.get();)Ab(i,s);s.notified=!1,e&&!s.rejection&&MP(s)}))},Rb=function(s,e,t){var i,r;kP?(i=Zu.createEvent("Event"),i.promise=e,i.reason=t,i.initEvent(s,!1,!0),ai.dispatchEvent(i)):i={promise:e,reason:t},!wP&&(r=ai["on"+s])?r(i):s===Tb&&IP("Unhandled promise rejection",t)},MP=function(s){hr(bb,ai,function(){var e=s.facade,t=s.value,i=mb(s),r;if(i&&(r=EP(function(){nn?sl.emit("unhandledRejection",t,e):Rb(Tb,e,t)}),s.rejection=nn||mb(s)?Eb:al,r.error))throw r.value})},mb=function(s){return s.rejection!==al&&!s.parent},DP=function(s){hr(bb,ai,function(){var e=s.facade;nn?sl.emit("rejectionHandled",e):Rb(LP,e,s.value)})},dr=function(s,e,t){return function(i){s(e,i,t)}},pr=function(s,e,t){s.done||(s.done=!0,t&&(s=t),s.value=e,s.state=$P,Pb(s,!0))},tl=function(s,e,t){if(!s.done){s.done=!0,t&&(s=t);try{if(s.facade===e)throw new yb("Promise can't be resolved itself");var i=wb(e);i?il(function(){var r={done:!1};try{hr(i,e,dr(tl,r,s),dr(pr,r,s))}catch(a){pr(r,a,s)}}):(s.value=e,s.state=Ib,Pb(s,!1))}catch(r){pr({done:!1},r,s)}}};if(Sb&&(Mi=function(e){yP(this,rn),vP(e),hr(sn,this);var t=Ju(this);try{e(dr(tl,t),dr(pr,t))}catch(i){pr(t,i)}},rn=Mi.prototype,sn=function(e){PP(this,{type:un,done:!1,notified:!1,parent:!1,reactions:new xP,rejection:!1,state:pb,value:null})},sn.prototype=cb(rn,"then",function(e,t){var i=Ju(this),r=el(TP(this,Mi));return i.parent=!0,r.ok=an(e)?e:!0,r.fail=an(t)&&t,r.domain=nn?sl.domain:void 0,i.state===pb?i.reactions.add(r):il(function(){Ab(r,i)}),r.promise}),hb=function(){var s=new sn,e=Ju(s);this.promise=s,this.resolve=dr(tl,e),this.reject=dr(pr,e)},vb.f=el=function(s){return s===Mi||s===xb?new hb(s):RP(s)},!fP&&an(on)&&cr!==Object.prototype)){fb=cr.then,AP||cb(cr,"then",function(e,t){var i=this;return new Mi(function(r,a){hr(fb,i,r,a)}).then(e,t)},{unsafe:!0});try{delete cr.constructor}catch(s){}db&&db(cr,rn)}hP({global:!0,constructor:!0,wrap:!0,forced:Sb},{Promise:Mi});xb=mP.Promise;bP(Mi,un,!1,!0);gP(un)});var Cb=v((xC,Db)=>{"use strict";var CP=Be(),$b=CP("iterator"),Mb=!1;try{Lb=0,nl={next:function(){return{done:!!Lb++}},return:function(){Mb=!0}},nl[$b]=function(){return this},Array.from(nl,function(){throw 2})}catch(s){}var Lb,nl;Db.exports=function(s,e){try{if(!e&&!Mb)return!1}catch(r){return!1}var t=!1;try{var i={};i[$b]=function(){return{next:function(){return{done:t=!0}}}},s(i)}catch(r){}return t}});var ol=v((wC,Bb)=>{"use strict";var BP=$i(),VP=Cb(),_P=ur().CONSTRUCTOR;Bb.exports=_P||!VP(function(s){BP.all(s).then(void 0,function(){})})});var Vb=v(()=>{"use strict";var OP=Ae(),FP=et(),NP=At(),qP=lr(),UP=tn(),HP=Ya(),jP=ol();OP({target:"Promise",stat:!0,forced:jP},{all:function(e){var t=this,i=qP.f(t),r=i.resolve,a=i.reject,n=UP(function(){var o=NP(t.resolve),u=[],l=0,c=1;HP(e,function(d){var f=l++,p=!1;c++,FP(o,t,d).then(function(h){p||(p=!0,u[f]=h,--c||r(u))},a)}),--c||r(u)});return n.error&&a(n.value),i.promise}})});var Ob=v(()=>{"use strict";var QP=Ae(),WP=gt(),GP=ur().CONSTRUCTOR,ll=$i(),zP=Ot(),YP=Ee(),KP=ar(),_b=ll&&ll.prototype;QP({target:"Promise",proto:!0,forced:GP,real:!0},{catch:function(s){return this.then(void 0,s)}});!WP&&YP(ll)&&(ul=zP("Promise").prototype.catch,_b.catch!==ul&&KP(_b,"catch",ul,{unsafe:!0}));var ul});var Fb=v(()=>{"use strict";var XP=Ae(),JP=et(),ZP=At(),eR=lr(),tR=tn(),iR=Ya(),rR=ol();XP({target:"Promise",stat:!0,forced:rR},{race:function(e){var t=this,i=eR.f(t),r=i.reject,a=tR(function(){var n=ZP(t.resolve);iR(e,function(o){JP(n,t,o).then(i.resolve,r)})});return a.error&&r(a.value),i.promise}})});var Nb=v(()=>{"use strict";var sR=Ae(),aR=lr(),nR=ur().CONSTRUCTOR;sR({target:"Promise",stat:!0,forced:nR},{reject:function(e){var t=aR.f(this),i=t.reject;return i(e),t.promise}})});var cl=v((CC,qb)=>{"use strict";var oR=Pt(),uR=He(),lR=lr();qb.exports=function(s,e){if(oR(s),uR(e)&&e.constructor===s)return e;var t=lR.f(s),i=t.resolve;return i(e),t.promise}});var jb=v(()=>{"use strict";var cR=Ae(),dR=Ot(),Ub=gt(),pR=$i(),Hb=ur().CONSTRUCTOR,hR=cl(),fR=dR("Promise"),mR=Ub&&!Hb;cR({target:"Promise",stat:!0,forced:Ub||Hb},{resolve:function(e){return hR(mR&&this===fR?pR:this,e)}})});var Qb=v(()=>{"use strict";kb();Vb();Ob();Fb();Nb();jb()});var Yb=v(()=>{"use strict";var bR=Ae(),gR=gt(),ln=$i(),vR=Re(),Gb=Ot(),zb=Ee(),SR=Du(),Wb=cl(),yR=ar(),pl=ln&&ln.prototype,TR=!!ln&&vR(function(){pl.finally.call({then:function(){}},function(){})});bR({target:"Promise",proto:!0,real:!0,forced:TR},{finally:function(s){var e=SR(this,Gb("Promise")),t=zb(s);return this.then(t?function(i){return Wb(e,s()).then(function(){return i})}:s,t?function(i){return Wb(e,s()).then(function(){throw i})}:s)}});!gR&&zb(ln)&&(dl=Gb("Promise").prototype.finally,pl.finally!==dl&&yR(pl,"finally",dl,{unsafe:!0}));var dl});var Xb=v((qC,Kb)=>{"use strict";sm();Qb();Yb();var IR=si();Kb.exports=IR("Promise","finally")});var Zb=v((UC,Jb)=>{"use strict";var ER=Xb();Jb.exports=ER});var cn=v((HC,eg)=>{"use strict";var xR=Zb();eg.exports=xR});var bg=v(()=>{"use strict";var OR=Ae(),FR=Xi(),NR=rr(),qR=Jr(),UR=Zr();OR({target:"Array",proto:!0},{at:function(e){var t=FR(this),i=NR(t),r=qR(e),a=r>=0?r:i+r;return a<0||a>=i?void 0:t[a]}});UR("at")});var vg=v((I0,gg)=>{"use strict";bg();var HR=si();gg.exports=HR("Array","at")});var yg=v((E0,Sg)=>{"use strict";var jR=vg();Sg.exports=jR});var yt=v((x0,Tg)=>{"use strict";var QR=yg();Tg.exports=QR});var Cl=v((s_,Qg)=>{"use strict";var ik=Ii();Qg.exports=Array.isArray||function(e){return ik(e)==="Array"}});var Gg=v((a_,Wg)=>{"use strict";var rk=TypeError,sk=9007199254740991;Wg.exports=function(s){if(s>sk)throw rk("Maximum allowed index exceeded");return s}});var Kg=v((n_,Yg)=>{"use strict";var ak=Cl(),nk=rr(),ok=Gg(),uk=Zi(),zg=function(s,e,t,i,r,a,n,o){for(var u=r,l=0,c=n?uk(n,o):!1,d,f;l<i;)l in t&&(d=c?c(t[l],l,e):t[l],a>0&&ak(d)?(f=nk(d),u=zg(s,e,d,f,u,a-1)-1):(ok(u+1),s[u]=d),u++),l++;return u};Yg.exports=zg});var ev=v((o_,Zg)=>{"use strict";var Xg=Cl(),lk=Mu(),ck=He(),dk=Be(),pk=dk("species"),Jg=Array;Zg.exports=function(s){var e;return Xg(s)&&(e=s.constructor,lk(e)&&(e===Jg||Xg(e.prototype))?e=void 0:ck(e)&&(e=e[pk],e===null&&(e=void 0))),e===void 0?Jg:e}});var iv=v((u_,tv)=>{"use strict";var hk=ev();tv.exports=function(s,e){return new(hk(s))(e===0?0:e)}});var rv=v(()=>{"use strict";var fk=Ae(),mk=Kg(),bk=At(),gk=Xi(),vk=rr(),Sk=iv();fk({target:"Array",proto:!0},{flatMap:function(e){var t=gk(this),i=vk(t),r;return bk(e),r=Sk(t,0),r.length=mk(r,t,t,i,0,1,e,arguments.length>1?arguments[1]:void 0),r}})});var sv=v(()=>{"use strict";var yk=Zr();yk("flatMap")});var nv=v((h_,av)=>{"use strict";rv();sv();var Tk=si();av.exports=Tk("Array","flatMap")});var uv=v((f_,ov)=>{"use strict";var Ik=nv();ov.exports=Ik});var Es=v((m_,lv)=>{"use strict";var Ek=uv();lv.exports=Ek});var xs=v((b_,cv)=>{"use strict";var xk=ts(),wk=String;cv.exports=function(s){if(xk(s)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return wk(s)}});var Bl=v((g_,dv)=>{"use strict";dv.exports=`
7
+ \v\f\r \xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF`});var fv=v((v_,hv)=>{"use strict";var Ak=ke(),Pk=ri(),Rk=xs(),_l=Bl(),pv=Ak("".replace),kk=RegExp("^["+_l+"]+"),Lk=RegExp("(^|[^"+_l+"])["+_l+"]+$"),Vl=function(s){return function(e){var t=Rk(Pk(e));return s&1&&(t=pv(t,kk,"")),s&2&&(t=pv(t,Lk,"$1")),t}};hv.exports={start:Vl(1),end:Vl(2),trim:Vl(3)}});var vv=v((S_,gv)=>{"use strict";var $k=pu().PROPER,Mk=Re(),mv=Bl(),bv="\u200B\x85\u180E";gv.exports=function(s){return Mk(function(){return!!mv[s]()||bv[s]()!==bv||$k&&mv[s].name!==s})}});var Ol=v((y_,Sv)=>{"use strict";var Dk=fv().start,Ck=vv();Sv.exports=Ck("trimStart")?function(){return Dk(this)}:"".trimStart});var Tv=v(()=>{"use strict";var Bk=Ae(),yv=Ol();Bk({target:"String",proto:!0,name:"trimStart",forced:"".trimLeft!==yv},{trimLeft:yv})});var Ev=v(()=>{"use strict";Tv();var Vk=Ae(),Iv=Ol();Vk({target:"String",proto:!0,name:"trimStart",forced:"".trimStart!==Iv},{trimStart:Iv})});var wv=v((w_,xv)=>{"use strict";Ev();var _k=si();xv.exports=_k("String","trimLeft")});var Pv=v((A_,Av)=>{"use strict";var Ok=wv();Av.exports=Ok});var kv=v((P_,Rv)=>{"use strict";var Fk=Pv();Rv.exports=Fk});var jv=v(()=>{"use strict"});var Qv=v(()=>{"use strict"});var Gv=v((uN,Wv)=>{"use strict";var aL=He(),nL=Ii(),oL=Be(),uL=oL("match");Wv.exports=function(s){var e;return aL(s)&&((e=s[uL])!==void 0?!!e:nL(s)==="RegExp")}});var Kv=v((lN,Yv)=>{"use strict";var lL=Ie(),cL=Re(),zv=lL.RegExp,dL=!cL(function(){var s=!0;try{zv(".","d")}catch(u){s=!1}var e={},t="",i=s?"dgimsy":"gimsy",r=function(u,l){Object.defineProperty(e,u,{get:function(){return t+=l,!0}})},a={dotAll:"s",global:"g",ignoreCase:"i",multiline:"m",sticky:"y"};s&&(a.hasIndices="d");for(var n in a)r(n,a[n]);var o=Object.getOwnPropertyDescriptor(zv.prototype,"flags").get.call(e);return o!==i||t!==i});Yv.exports={correct:dL}});var Jv=v((cN,Xv)=>{"use strict";var pL=Pt();Xv.exports=function(){var s=pL(this),e="";return s.hasIndices&&(e+="d"),s.global&&(e+="g"),s.ignoreCase&&(e+="i"),s.multiline&&(e+="m"),s.dotAll&&(e+="s"),s.unicode&&(e+="u"),s.unicodeSets&&(e+="v"),s.sticky&&(e+="y"),e}});var tS=v((dN,eS)=>{"use strict";var hL=et(),fL=vt(),mL=Wr(),Zv=Kv(),bL=Jv(),gL=RegExp.prototype;eS.exports=Zv.correct?function(s){return s.flags}:function(s){return!Zv.correct&&mL(gL,s)&&!fL(s,"flags")?hL(bL,s):s.flags}});var rS=v((pN,iS)=>{"use strict";var Ul=ke(),vL=Xi(),SL=Math.floor,Nl=Ul("".charAt),yL=Ul("".replace),ql=Ul("".slice),TL=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,IL=/\$([$&'`]|\d{1,2})/g;iS.exports=function(s,e,t,i,r,a){var n=t+s.length,o=i.length,u=IL;return r!==void 0&&(r=vL(r),u=TL),yL(a,u,function(l,c){var d;switch(Nl(c,0)){case"$":return"$";case"&":return s;case"`":return ql(e,0,t);case"'":return ql(e,n);case"<":d=r[ql(c,1,-1)];break;default:var f=+c;if(f===0)return l;if(f>o){var p=SL(f/10);return p===0?l:p<=o?i[p-1]===void 0?Nl(c,1):i[p-1]+Nl(c,1):l}d=i[f-1]}return d===void 0?"":d})}});var nS=v(()=>{"use strict";var EL=Ae(),xL=et(),jl=ke(),sS=ri(),wL=Ee(),AL=He(),PL=Gv(),wr=xs(),RL=zr(),kL=tS(),LL=rS(),$L=Be(),ML=gt(),DL=$L("replace"),CL=TypeError,Hl=jl("".indexOf),BL=jl("".replace),aS=jl("".slice),VL=Math.max;EL({target:"String",proto:!0},{replaceAll:function(e,t){var i=sS(this),r,a,n,o,u,l,c,d,f,p,h=0,b="";if(AL(e)){if(r=PL(e),r&&(a=wr(sS(kL(e))),!~Hl(a,"g")))throw new CL("`.replaceAll` does not allow non-global regexes");if(n=RL(e,DL),n)return xL(n,e,i,t);if(ML&&r)return BL(wr(i),e,t)}for(o=wr(i),u=wr(e),l=wL(t),l||(t=wr(t)),c=u.length,d=VL(1,c),f=Hl(o,u);f!==-1;)p=l?wr(t(u,f,o)):LL(u,o,f,[],void 0,t),b+=aS(o,h,f)+p,h=f+c,f=f+d>o.length?-1:Hl(o,u,f+d);return h<o.length&&(b+=aS(o,h)),b}})});var uS=v((mN,oS)=>{"use strict";jv();Qv();nS();var _L=si();oS.exports=_L("String","replaceAll")});var cS=v((bN,lS)=>{"use strict";var OL=uS();lS.exports=OL});var pS=v((gN,dS)=>{"use strict";var FL=cS();dS.exports=FL});var fS=v((vN,hS)=>{"use strict";var NL=Jr(),qL=xs(),UL=ri(),HL=RangeError;hS.exports=function(e){var t=qL(UL(this)),i="",r=NL(e);if(r<0||r===1/0)throw new HL("Wrong number of repetitions");for(;r>0;(r>>>=1)&&(t+=t))r&1&&(i+=t);return i}});var SS=v((SN,vS)=>{"use strict";var gS=ke(),jL=eu(),mS=xs(),QL=fS(),WL=ri(),GL=gS(QL),zL=gS("".slice),YL=Math.ceil,bS=function(s){return function(e,t,i){var r=mS(WL(e)),a=jL(t),n=r.length,o=i===void 0?" ":mS(i),u,l;return a<=n||o===""?r:(u=a-n,l=GL(o,YL(u/o.length)),l.length>u&&(l=zL(l,0,u)),s?r+l:l+r)}};vS.exports={start:bS(!1),end:bS(!0)}});var TS=v((yN,yS)=>{"use strict";var KL=wi();yS.exports=/Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(KL)});var IS=v(()=>{"use strict";var XL=Ae(),JL=SS().start,ZL=TS();XL({target:"String",proto:!0,forced:ZL},{padStart:function(e){return JL(this,e,arguments.length>1?arguments[1]:void 0)}})});var xS=v((EN,ES)=>{"use strict";IS();var e$=si();ES.exports=e$("String","padStart")});var AS=v((xN,wS)=>{"use strict";var t$=xS();wS.exports=t$});var RS=v((wN,PS)=>{"use strict";var i$=AS();PS.exports=i$});var $$={};Hy($$,{ChromecastState:()=>Nr,HttpConnectionType:()=>ka,Observable:()=>Bt.Observable,PlaybackState:()=>Fe,Player:()=>fa,PredefinedQualityLimits:()=>qr,SDK_VERSION:()=>L$,Subject:()=>Bt.Subject,Subscription:()=>Bt.Subscription,Surface:()=>La,VERSION:()=>Eo,ValueSubject:()=>Bt.ValueSubject,VideoFormat:()=>wt,VideoQuality:()=>Bt.VideoQuality,areValidLiveRecordSources:()=>ug,clientChecker:()=>z,isMobile:()=>fr});module.exports=jy($$);var Eo="2.0.140-dev.26e4b860.0";var Fe=(r=>(r.STOPPED="stopped",r.READY="ready",r.PLAYING="playing",r.PAUSED="paused",r))(Fe||{}),wt=(E=>(E.MPEG="MPEG",E.DASH="DASH",E.DASH_SEP="DASH_SEP",E.DASH_SEP_VK="DASH_SEP",E.DASH_WEBM="DASH_WEBM",E.DASH_WEBM_AV1="DASH_WEBM_AV1",E.DASH_STREAMS="DASH_STREAMS",E.DASH_WEBM_VK="DASH_WEBM",E.DASH_ONDEMAND="DASH_ONDEMAND",E.DASH_ONDEMAND_VK="DASH_ONDEMAND",E.DASH_LIVE="DASH_LIVE",E.DASH_LIVE_CMAF="DASH_LIVE_CMAF",E.DASH_LIVE_WEBM="DASH_LIVE_WEBM",E.HLS="HLS",E.HLS_ONDEMAND="HLS_ONDEMAND",E.HLS_JS="HLS",E.HLS_FMP4="HLS_FMP4",E.HLS_LIVE="HLS_LIVE",E.HLS_LIVE_CMAF="HLS_LIVE_CMAF",E.WEB_RTC_LIVE="WEB_RTC_LIVE",E))(wt||{});var Nr=(r=>(r.NOT_AVAILABLE="NOT_AVAILABLE",r.AVAILABLE="AVAILABLE",r.CONNECTING="CONNECTING",r.CONNECTED="CONNECTED",r))(Nr||{}),ka=(i=>(i.HTTP1="http1",i.HTTP2="http2",i.QUIC="quic",i))(ka||{});var La=(n=>(n.NONE="none",n.INLINE="inline",n.FULLSCREEN="fullscreen",n.SECOND_SCREEN="second_screen",n.PIP="pip",n.INVISIBLE="invisible",n))(La||{}),qr=(i=>(i.TRAFFIC_SAVING="traffic_saving",i.HIGH_QUALITY="high_quality",i.UNKNOWN="unknown",i))(qr||{});var Tc=G(Pi(),1),Ly=G(Ne(),1);var ie=require("@vkontakte/videoplayer-shared/es2018");var Ih=s=>new Promise((e,t)=>{let i=document.createElement("script");i.setAttribute("src",s),i.onload=()=>e(),i.onerror=r=>t(r),document.body.appendChild(i)});var Oa=class{constructor(e){this.connection$=new ie.ValueSubject(void 0);this.castState$=new ie.ValueSubject("NOT_AVAILABLE");this.errorEvent$=new ie.Subject;this.realCastState$=new ie.ValueSubject("NOT_AVAILABLE");this.subscription=new ie.Subscription;this.isDestroyed=!1;var a;this.params=e,this.log=this.params.dependencies.logger.createComponentLog("ChromecastInitializer");let t="chrome"in window;if(this.log({message:`[constructor] receiverApplicationId: ${this.params.receiverApplicationId}, isDisabled: ${this.params.isDisabled}, isSupported: ${t}`}),e.isDisabled||!t)return;let i=(0,ie.isNonNullable)((a=window.chrome)==null?void 0:a.cast),r=!!window.__onGCastApiAvailable;i?this.initializeCastApi():(window.__onGCastApiAvailable=n=>{delete window.__onGCastApiAvailable,n&&!this.isDestroyed&&this.initializeCastApi()},r||Ih("https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1").catch(()=>this.errorEvent$.next({id:"ChromecastLoading",category:ie.ErrorCategory.NETWORK,message:"Script loading failed!"})))}connect(){var e;(e=cast.framework.CastContext.getInstance())==null||e.requestSession()}disconnect(){var e,t;(t=(e=cast.framework.CastContext.getInstance())==null?void 0:e.getCurrentSession())==null||t.endSession(!0)}stopMedia(){return new Promise((e,t)=>{var i,r,a;(a=(r=(i=cast.framework.CastContext.getInstance())==null?void 0:i.getCurrentSession())==null?void 0:r.getMediaSession())==null||a.stop(new chrome.cast.media.StopRequest,e,t)})}toggleConnection(){(0,ie.isNonNullable)(this.connection$.getValue())?this.disconnect():this.connect()}setVolume(e){let t=this.connection$.getValue();(0,ie.isNullable)(t)||(t.remotePlayer.volumeLevel=e,t.remotePlayerController.setVolumeLevel())}setMuted(e){let t=this.connection$.getValue();(0,ie.isNullable)(t)||e!==t.remotePlayer.isMuted&&t.remotePlayerController.muteOrUnmute()}destroy(){this.isDestroyed=!0,this.subscription.unsubscribe()}initListeners(){let e=new cast.framework.RemotePlayer,t=new cast.framework.RemotePlayerController(e),i=cast.framework.CastContext.getInstance();this.subscription.add((0,ie.fromEvent)(i,cast.framework.CastContextEventType.SESSION_STATE_CHANGED).subscribe(r=>{var a,n,o;switch(r.sessionState){case cast.framework.SessionState.SESSION_STARTED:case cast.framework.SessionState.SESSION_STARTING:case cast.framework.SessionState.SESSION_RESUMED:this.contentId=(o=(n=(a=i.getCurrentSession())==null?void 0:a.getMediaSession())==null?void 0:n.media)==null?void 0:o.contentId;break;case cast.framework.SessionState.NO_SESSION:case cast.framework.SessionState.SESSION_ENDING:case cast.framework.SessionState.SESSION_ENDED:case cast.framework.SessionState.SESSION_START_FAILED:this.contentId=void 0;break;default:return(0,ie.assertNever)(r.sessionState)}})).add((0,ie.merge)((0,ie.fromEvent)(i,cast.framework.CastContextEventType.CAST_STATE_CHANGED).pipe((0,ie.tap)(r=>{this.log({message:`[cast.framework.RemotePlayerEventType.CAST_STATE_CHANGED]: ${JSON.stringify(r)}`})}),(0,ie.map)(r=>r.castState)),(0,ie.observableFrom)([i.getCastState()])).pipe((0,ie.filterChanged)(),(0,ie.map)(FE),(0,ie.tap)(r=>{this.log({message:`realCastState$: ${r}`})})).subscribe(this.realCastState$)).add(this.realCastState$.subscribe(r=>{var o,u;let a=r==="CONNECTED",n=(0,ie.isNonNullable)(this.connection$.getValue());if(a&&!n){let l=i.getCurrentSession();(0,ie.assertNonNullable)(l);let c=l.getCastDevice(),d=(u=(o=l.getMediaSession())==null?void 0:o.media)==null?void 0:u.contentId;((0,ie.isNullable)(d)||d===this.contentId)&&(this.log({message:"connection created"}),this.connection$.next({remotePlayer:e,remotePlayerController:t,session:l,castDevice:c}))}else!a&&n&&(this.log({message:"connection destroyed"}),this.connection$.next(void 0));this.castState$.next(r==="CONNECTED"?(0,ie.isNonNullable)(this.connection$.getValue())?"CONNECTED":"AVAILABLE":r)}))}initializeCastApi(){var r;let e,t,i;try{e=cast.framework.CastContext.getInstance(),t=chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,i=chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}catch(a){return}try{e.setOptions({receiverApplicationId:(r=this.params.receiverApplicationId)!=null?r:t,autoJoinPolicy:i}),this.initListeners()}catch(a){this.errorEvent$.next({id:"ChromecastInitializer",category:ie.ErrorCategory.EXTERNAL_API,message:"[initializeCastApi] failed",thrown:a})}}},FE=s=>{switch(s){case cast.framework.CastState.NO_DEVICES_AVAILABLE:return"NOT_AVAILABLE";case cast.framework.CastState.NOT_CONNECTED:return"AVAILABLE";case cast.framework.CastState.CONNECTING:return"CONNECTING";case cast.framework.CastState.CONNECTED:return"CONNECTED";default:return(0,ie.assertNever)(s)}};var vc=G(Ne(),1),gy=G(sr(),1),vy=G(Pu(),1);var cg=G(cn(),1);var hl=require("@vkontakte/videoplayer-shared/es2018");var xe=(s,e=0,t=0)=>{switch(t){case 0:return s.replace("_offset_p",e===0?"":"_"+e.toFixed(0));case 1:{if(e===0)return s;let i=new URL(s);return i.searchParams.append("playback_shift",e.toFixed(0)),i.toString()}case 2:{let i=new URL(s);return!i.searchParams.get("offset_p")&&e===0?s:(i.searchParams.set("offset_p",e.toFixed(0)),i.toString())}default:(0,hl.assertNever)(t)}return s},ni=(s,e)=>{var t;switch(e){case 0:return NaN;case 1:{let i=new URL(s);return Number(i.searchParams.get("playback_shift"))}case 2:{let i=new URL(s);return Number((t=i.searchParams.get("offset_p"))!=null?t:0)}default:(0,hl.assertNever)(e)}};var O=(s,e,t=!1)=>{let i=s.getTransition();(t||!i||i.to===e)&&s.setState(e)};var Rt=require("@vkontakte/videoplayer-shared/es2018"),re=class{constructor(e){this.transitionStarted$=new Rt.Subject;this.transitionEnded$=new Rt.Subject;this.transitionUpdated$=new Rt.Subject;this.forceChanged$=new Rt.Subject;this.stateChangeStarted$=(0,Rt.merge)(this.transitionStarted$,this.transitionUpdated$);this.stateChangeEnded$=(0,Rt.merge)(this.transitionEnded$,this.forceChanged$);this.state=e,this.prevState=void 0}setState(e){let t=this.transition,i=this.state;this.transition=void 0,this.prevState=i,this.state=e,t?t.to===e?this.transitionEnded$.next(t):this.forceChanged$.next({from:t.from,to:e,canceledTransition:t}):this.forceChanged$.next({from:i,to:e,canceledTransition:t})}startTransitionTo(e){let t=this.transition,i=this.state;i===e||(0,Rt.isNonNullable)(t)&&t.to===e||(this.prevState=i,this.state=e,t?(this.transition={from:t.from,to:e,canceledTransition:t},this.transitionUpdated$.next(this.transition)):(this.transition={from:i,to:e},this.transitionStarted$.next(this.transition)))}getTransition(){return this.transition}getState(){return this.state}getPrevState(){return this.prevState}};var ml=require("@vkontakte/videoplayer-shared/es2018");var dn=class{constructor(){this._isMiuiBrowser=!1}get current(){return this._current}get isChrome(){return this.current==="Chrome"}get isFirefox(){return this.current==="Firefox"}get isSafari(){return this.current==="Safari"}get isOpera(){return this.current==="Opera"}get isEdge(){return this.current==="Edge"}get isYandex(){return this.current==="Yandex"}get isSamsungBrowser(){return this.current==="SamsungBrowser"}get currentVersion(){return this._current_version}get chromeVersion(){return this._chromeVersion}get firefoxVersion(){return this._firefoxVersion}get safariVersion(){return this._safariVersion}get operaVersion(){return this._operaVersion}get edgeVersion(){return this._edgeVersion}get yandexVersion(){return this._yandexVersion}get isMiuiBrowser(){return this._isMiuiBrowser}detect(){let{userAgent:e}=navigator;try{let t=/yabrowser/i.test(e)?"Yandex":void 0,i=/samsungbrowser/i.test(e)?"SamsungBrowser":void 0,r=/chrome|crios/i.test(e)?"Chrome":void 0,a=/chromium/i.test(e)?"Chromium":void 0,n=/firefox|fxios/i.test(e)?"Firefox":void 0,o=/webkit|safari|khtml/i.test(e)?"Safari":void 0,u=/opr\//i.test(e)?"Opera":void 0,l=/edg/i.test(e)?"Edge":void 0;this._isMiuiBrowser=/(XiaoMi)|(MiuiBrowser)/i.test(e),this._current=t||i||n||u||l||r||a||o||"Rest"}catch(t){console.error(t)}this.isChrome&&this.detectChromeVersion(),this.isFirefox&&this.detectFirefoxVersion(),this.isSafari&&this.detectSafariVersion(),this.isOpera&&this.detectOperaVersion(),this.isEdge&&this.detectEdgeVersion(),this.isYandex&&this.detectYandexVersion()}detectVersion(e){try{let{userAgent:t}=window.navigator,i=t.match(e);if(!i)return;let r=i[1],a=parseInt(r,10);if(!isNaN(a))return this._current_version=a,a}catch(t){console.error(t)}}detectChromeVersion(){this._chromeVersion=this.detectVersion(/Chrome\/(\d+\.\d+)/)}detectFirefoxVersion(){this._firefoxVersion=this.detectVersion(/Firefox\/(\d+\.\d+)/)}detectSafariVersion(){this._safariVersion=this.detectVersion(/Version\/(\d+)/)}detectOperaVersion(){this._operaVersion=this.detectVersion(/OPR\/(\d+\.\d+)/)}detectEdgeVersion(){this._edgeVersion=this.detectVersion(/Edg\/(\d+\.\d+)/)}detectYandexVersion(){this._yandexVersion=this.detectVersion(/YaBrowser\/(\d+\.\d+\.\d+)/)}};var tg=G(Ne(),1);var fr=()=>{var s,e;return/Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test((s=navigator.appVersion)!=null?s:navigator.userAgent)||((e=navigator==null?void 0:navigator.userAgentData)==null?void 0:e.mobile)};var pn=class{constructor(e){this._highEntropyValues={};this._displayChecker=e}get current(){return this._current}get isIOS(){let e=["iPhone","iPad","iPod"];return this._highEntropyValues.platform==="iOS"||(0,tg.default)(e,this.current)}get isMac(){return this._highEntropyValues.platform==="macOS"||this.current==="Mac"}get isApple(){return this.isIOS||this.isMac}get isIphoneOrOldIpad(){if(!this.isApple||!this._displayChecker.isTouch)return!1;let e=this.current==="iPad"||this._displayChecker.width>700,t=this._iosVersion;return!e||e&&!!t&&t<16}get isAndroid(){return this._highEntropyValues.platform==="Android"||this.current==="Android"}get isMobile(){return this._highEntropyValues.mobile||this._isMobile}get iOSVersion(){return this._iosVersion}detect(){let{userAgent:e}=navigator;try{this._isMobile=fr()}catch(t){console.error(t)}this.detectDevice(e),this.detectHighEntropyValues(),this.isIOS&&this.detectIOSVersion()}async detectHighEntropyValues(){let{userAgentData:e}=navigator;if(e!=null&&e.getHighEntropyValues){let t=await e.getHighEntropyValues(["architecture","bitness","brands","mobile","platform","formFactor","model","platformVersion","wow64"]);this._highEntropyValues=t}}detectDevice(e){try{let t=/android/i.test(e)?"Android":void 0,i=/iphone/i.test(e)?"iPhone":void 0,r=/ipad/i.test(e)?"iPad":void 0,a=/ipod/i.test(e)?"iPod":void 0,n=/mac/i.test(e)?"Mac":void 0,o=/webOS|BlackBerry|IEMobile|Opera Mini/i.test(e)?"RestMobile":void 0;this._current=t||i||r||a||o||n||"Desktop"}catch(t){console.error(t)}}detectIOSVersion(){try{if(this._highEntropyValues.platformVersion){let a=this._highEntropyValues.platformVersion.split(".").slice(0,2).join("."),n=parseFloat(a);this._iosVersion=n;return}let{userAgent:e}=window.navigator,t=e.match(/OS (\d+(_\d+)?)/i);if(!t)return;let i=t[1].replace(/_/g,".");if(!i)return;let r=parseFloat(i);if(isNaN(r))return;this._iosVersion=r}catch(e){console.error(e)}}};var hn=class{get isTouch(){return typeof this._maxTouchPoints=="number"?this._maxTouchPoints>1:"ontouchstart"in window}get maxTouchPoints(){return this._maxTouchPoints}get height(){return this._height}get width(){return this._width}get screenHeight(){return this._screenHeight}get screenWidth(){return this._screenWidth}get pixelRatio(){return this._pixelRatio}get isHDR(){return this._isHdr}get colorDepth(){return this._colorDepth}detect(){var t;let{maxTouchPoints:e}=navigator;try{this._maxTouchPoints=e!=null?e:0,this._isHdr=!!((t=matchMedia("(dynamic-range: high)"))!=null&&t.matches),this._colorDepth=screen.colorDepth}catch(i){console.error(i)}try{this._pixelRatio=window.devicePixelRatio||1,this._height=screen.height,this._width=screen.width,this._height=screen.height,this._screenHeight=this._height*this._pixelRatio,this._screenWidth=this._width*this._pixelRatio}catch(i){console.error(i)}}};var it=()=>window.ManagedMediaSource||window.MediaSource,mr=()=>{var s,e;return!!(window.ManagedMediaSource&&((e=(s=window.ManagedSourceBuffer)==null?void 0:s.prototype)!=null&&e.appendBuffer))},ig=()=>{var s,e;return!!(window.MediaSource&&((e=(s=window.SourceBuffer)==null?void 0:s.prototype)!=null&&e.appendBuffer))},fn=()=>window.ManagedMediaSource?new ManagedMediaSource:new MediaSource;var wR=document.createElement("video"),AR='video/mp4; codecs="avc1.42000a,mp4a.40.2"',PR='video/mp4; codecs="hev1.1.6.L93.B0"',rg='video/webm; codecs="vp09.00.10.08"',sg='video/webm; codecs="av01.0.00M.08"',RR='audio/mp4; codecs="mp4a.40.2"',kR='audio/webm; codecs="opus"',ag,LR=async()=>{if(!window.navigator.mediaCapabilities)return;let s={type:"media-source",video:{contentType:"video/webm",width:1280,height:720,bitrate:1e6,framerate:30}},[e,t]=await Promise.all([window.navigator.mediaCapabilities.decodingInfo({...s,video:{...s.video,contentType:sg}}),window.navigator.mediaCapabilities.decodingInfo({...s,video:{...s.video,contentType:rg}})]);ag={DASH_WEBM_AV1:e,DASH_WEBM:t}};LR().catch(s=>{console.log(wR),console.error(s)});var mn=class{constructor(e,t){this._deviceChecker=e,this._browserChecker=t}get protocols(){return this._protocols}get containers(){return this._containers}get codecs(){return this._codecs}get webmDecodingInfo(){return ag}get supportedCodecs(){return Object.keys(this._codecs).filter(e=>this._codecs[e])}get nativeHlsSupported(){return this._nativeHlsSupported}detect(){var e,t,i,r,a,n,o,u,l,c,d,f,p,h,b,S,g,I,w,E;this._video=document.createElement("video");try{this._protocols={mms:mr(),mse:ig(),hls:!!((t=(e=this._video).canPlayType)!=null&&t.call(e,"application/x-mpegurl")||(r=(i=this._video).canPlayType)!=null&&r.call(i,"vnd.apple.mpegURL")),webrtc:!!window.RTCPeerConnection,ws:!!window.WebSocket},this._containers={mp4:!!((n=(a=this._video).canPlayType)!=null&&n.call(a,"video/mp4")),webm:!!((u=(o=this._video).canPlayType)!=null&&u.call(o,"video/webm")),cmaf:!0};let P=!!((c=(l=it())==null?void 0:l.isTypeSupported)!=null&&c.call(l,AR)),_=!!((f=(d=it())==null?void 0:d.isTypeSupported)!=null&&f.call(d,PR)),N=!!((h=(p=it())==null?void 0:p.isTypeSupported)!=null&&h.call(p,RR));this._codecs={h264:P,h265:_,vp9:!!((S=(b=it())==null?void 0:b.isTypeSupported)!=null&&S.call(b,rg)),av1:!!((I=(g=it())==null?void 0:g.isTypeSupported)!=null&&I.call(g,sg)),aac:N,opus:!!((E=(w=it())==null?void 0:w.isTypeSupported)!=null&&E.call(w,kR)),mpeg:(P||_)&&N},this._nativeHlsSupported=this._protocols.hls&&this._containers.mp4}catch(P){console.error(P)}try{this.destroyVideoElement()}catch(P){console.error("Error destroying video element:",P)}}destroyVideoElement(){var t;if(!this._video)return;if(this._video.pause(),this._video.currentTime=0,this._video.removeAttribute("src"),this._video.src="",this._video.load(),this._video.remove){this._video.remove(),this._video=null;return}this._video.parentNode&&this._video.parentNode.removeChild(this._video);let e=this._video.cloneNode(!1);(t=this._video.parentNode)==null||t.replaceChild(e,this._video),this._video=null}};var ng="audio/mpeg",bn=class{supportMp3(){return this._codecs.mp3&&this._containers.mpeg}detect(){var e,t,i,r;this._audio=document.createElement("audio");try{this._containers={mpeg:!!((t=(e=this._audio).canPlayType)!=null&&t.call(e,ng))},this._codecs={mp3:!!((r=(i=it())==null?void 0:i.isTypeSupported)!=null&&r.call(i,ng))}}catch(a){console.error(a)}try{this.destroyAudioElement()}catch(a){console.error("Error destroying audio element:",a)}}destroyAudioElement(){var t;if(!this._audio)return;if(this._audio.pause(),this._audio.currentTime=0,this._audio.removeAttribute("src"),this._audio.src="",this._audio.load(),this._audio.remove){this._audio.remove(),this._audio=null;return}this._audio.parentNode&&this._audio.parentNode.removeChild(this._audio);let e=this._audio.cloneNode(!1);(t=this._audio.parentNode)==null||t.replaceChild(e,this._audio),this._audio=null}};var og=require("@vkontakte/videoplayer-shared/es2018"),fl=class{constructor(){this.isInited$=new og.ValueSubject(!1);this._displayChecker=new hn,this._deviceChecker=new pn(this._displayChecker),this._browserChecker=new dn,this._videoChecker=new mn(this._deviceChecker,this._browserChecker),this._audioChecker=new bn,this.detect()}get display(){return this._displayChecker}get device(){return this._deviceChecker}get browser(){return this._browserChecker}get video(){return this._videoChecker}get audio(){return this._audioChecker}async detect(){this._displayChecker.detect(),this._deviceChecker.detect(),this._browserChecker.detect(),this._videoChecker.detect(),this._audioChecker.detect(),this.isInited$.next(!0)}},z=new fl;var bl=s=>{let{containers:e,protocols:t,codecs:i,nativeHlsSupported:r}=z.video,a=(i.h264||i.h265)&&i.aac,n=t.mse||t.mms;return s.filter(o=>{switch(o){case"DASH_SEP":return n&&e.mp4&&a;case"DASH_WEBM":return n&&e.webm&&i.vp9&&i.opus;case"DASH_WEBM_AV1":return n&&e.webm&&i.av1&&i.opus;case"DASH_STREAMS":return n&&(e.mp4&&a||e.webm&&(i.vp9||i.av1)&&(i.opus||i.aac));case"DASH_LIVE":return n&&e.mp4&&a;case"DASH_LIVE_CMAF":return n&&e.mp4&&a&&e.cmaf;case"DASH_ONDEMAND":return n&&e.mp4&&a;case"HLS":case"HLS_ONDEMAND":case"HLS_FMP4":case"HLS_LIVE":case"HLS_LIVE_CMAF":return r;case"MPEG":return e.mp4;case"DASH":case"DASH_LIVE_WEBM":return!1;case"WEB_RTC_LIVE":return t.webrtc&&t.ws&&i.h264&&(e.mp4||e.webm);default:return(0,ml.assertNever)(o)}})},gl=s=>{switch(s){case"MPEG":case"DASH":case"DASH_SEP":case"DASH_ONDEMAND":case"DASH_WEBM":case"DASH_WEBM_AV1":case"DASH_STREAMS":case"HLS":case"HLS_FMP4":case"HLS_ONDEMAND":return!1;case"DASH_LIVE":case"DASH_LIVE_CMAF":case"HLS_LIVE":case"HLS_LIVE_CMAF":case"DASH_LIVE_WEBM":case"WEB_RTC_LIVE":return!0;default:return(0,ml.assertNever)(s)}},ug=s=>{let t=Object.keys(s).filter(i=>!gl(i));return bl(t).length>0};var j=require("@vkontakte/videoplayer-shared/es2018");var $R=5,MR=5,DR=500,lg=7e3,ps=class{constructor(e){this.subscription=new j.Subscription;this.loadMediaTimeoutSubscription=new j.Subscription;this.videoState=new re("stopped");this.syncPlayback=()=>{let e=this.videoState.getState(),t=this.videoState.getTransition(),i=this.params.desiredState.playbackState.getState(),r=this.params.desiredState.playbackState.getTransition(),a=this.params.desiredState.seekState.getState();if(this.log({message:`[syncPlayback] videoState: ${e}; videoTransition: ${JSON.stringify(t)}; desiredPlaybackState: ${i}; desiredPlaybackStateTransition: ${this.params.desiredState.playbackState.getTransition()}; seekState: ${JSON.stringify(a)};`}),i==="stopped"){e!=="stopped"&&(this.videoState.startTransitionTo("stopped"),this.stop());return}if(!t){if((r==null?void 0:r.to)!=="paused"&&a.state==="requested"&&e!=="stopped"){this.seek(a.position/1e3);return}switch(i){case"ready":{switch(e){case"playing":case"paused":case"ready":break;case"stopped":this.videoState.startTransitionTo("ready"),this.prepare();break;default:(0,j.assertNever)(e)}break}case"playing":{switch(e){case"playing":break;case"paused":this.videoState.startTransitionTo("playing"),this.params.connection.remotePlayerController.playOrPause();break;case"ready":this.videoState.startTransitionTo("playing"),this.params.connection.remotePlayerController.playOrPause();break;case"stopped":this.videoState.startTransitionTo("ready"),this.prepare();break;default:(0,j.assertNever)(e)}break}case"paused":{switch(e){case"playing":this.videoState.startTransitionTo("paused"),this.params.connection.remotePlayerController.playOrPause();break;case"paused":break;case"ready":this.videoState.startTransitionTo("paused"),this.videoState.setState("paused");break;case"stopped":this.videoState.startTransitionTo("ready"),this.prepare();break;default:(0,j.assertNever)(e)}break}default:(0,j.assertNever)(i)}}};this.params=e,this.log=this.params.dependencies.logger.createComponentLog("ChromecastProvider"),this.log({message:`constructor, format: ${e.format}`}),this.params.output.isLive$.next(gl(e.format)),this.params.output.isAudioAvailable$.next(!0),this.handleRemoteVolumeChange({volume:this.params.connection.remotePlayer.volumeLevel,muted:this.params.connection.remotePlayer.isMuted});let t=this.params.connection.session.getMediaSession();t&&this.restoreSession(t),this.subscribe()}destroy(){this.log({message:"[destroy]"}),this.subscription.unsubscribe()}subscribe(){this.subscription.add(this.loadMediaTimeoutSubscription);let e=new j.Subscription;this.subscription.add(e),this.subscription.add((0,j.merge)(this.videoState.stateChangeStarted$.pipe((0,j.map)(r=>`stateChangeStarted$ ${JSON.stringify(r)}`)),this.videoState.stateChangeEnded$.pipe((0,j.map)(r=>`stateChangeEnded$ ${JSON.stringify(r)}`))).subscribe(r=>this.log({message:`[videoState] ${r}`})));let t=(r,a)=>this.subscription.add(r.subscribe(a));if(this.params.output.isLive$.getValue())this.params.output.position$.next(0),this.params.output.duration$.next(0);else{let r=new j.Subject;e.add(r.pipe((0,j.debounce)(DR)).subscribe(()=>{this.params.output.seekedEvent$.next()}));let a=NaN;e.add((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.CURRENT_TIME_CHANGED).subscribe(n=>{this.logRemoteEvent(n);let o=n.value;this.params.output.position$.next(o),(this.params.desiredState.seekState.getState().state==="applying"||Math.abs(o-a)>$R)&&r.next(o),a=o})),e.add((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.DURATION_CHANGED).subscribe(n=>{this.logRemoteEvent(n),this.params.output.duration$.next(n.value)}))}t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MEDIA_LOADED_CHANGED),r=>{this.logRemoteEvent(r),r.value?this.handleRemoteReady():(this.handleRemoteStop(),e.unsubscribe())}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_PAUSED_CHANGED),r=>{this.logRemoteEvent(r),r.value?this.handleRemotePause():this.handleRemotePlay()}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.PLAYER_STATE_CHANGED),r=>{this.logRemoteEvent(r);let{remotePlayer:a}=this.params.connection,n=r.value,o=this.params.output.isBuffering$.getValue(),u=n===chrome.cast.media.PlayerState.BUFFERING;switch(o!==u&&this.params.output.isBuffering$.next(u),n){case chrome.cast.media.PlayerState.IDLE:!this.params.output.isLive$.getValue()&&a.duration-a.currentTime<MR&&this.params.output.endedEvent$.next(),this.handleRemoteStop(),O(this.params.desiredState.playbackState,"stopped");break;case chrome.cast.media.PlayerState.PAUSED:{this.handleRemotePause();break}case chrome.cast.media.PlayerState.PLAYING:this.handleRemotePlay();break;case chrome.cast.media.PlayerState.BUFFERING:break;default:(0,j.assertNever)(n)}}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.VOLUME_LEVEL_CHANGED),r=>{this.logRemoteEvent(r),this.handleRemoteVolumeChange({volume:r.value})}),t((0,j.fromEvent)(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MUTED_CHANGED),r=>{this.logRemoteEvent(r),this.handleRemoteVolumeChange({muted:r.value})});let i=(0,j.merge)(this.params.desiredState.playbackState.stateChangeStarted$,this.params.desiredState.seekState.stateChangeEnded$,this.videoState.stateChangeEnded$,(0,j.observableFrom)(["init"])).pipe((0,j.debounce)(0));t(i,this.syncPlayback)}restoreSession(e){this.log({message:"restoreSession"});let{remotePlayer:t}=this.params.connection;if(e.playerState!==chrome.cast.media.PlayerState.IDLE){t.isPaused?(this.videoState.setState("paused"),O(this.params.desiredState.playbackState,"paused")):(this.videoState.setState("playing"),O(this.params.desiredState.playbackState,"playing"));let i=this.params.output.isLive$.getValue();this.params.output.duration$.next(i?0:t.duration),this.params.output.position$.next(i?0:t.currentTime),this.params.desiredState.seekState.setState({state:"none"})}}prepare(){let e=this.params.format;this.log({message:`[prepare] format: ${e}`});let t=this.createMediaInfo(e),i=this.createLoadRequest(t);this.loadMedia(i)}handleRemotePause(){let e=this.videoState.getState(),t=this.videoState.getTransition();((t==null?void 0:t.to)==="paused"||e==="playing")&&(this.videoState.setState("paused"),O(this.params.desiredState.playbackState,"paused"))}handleRemotePlay(){let e=this.videoState.getState(),t=this.videoState.getTransition();((t==null?void 0:t.to)==="playing"||e==="paused")&&(this.videoState.setState("playing"),O(this.params.desiredState.playbackState,"playing"))}handleRemoteReady(){var t;let e=this.videoState.getTransition();(e==null?void 0:e.to)==="ready"&&this.videoState.setState("ready"),((t=this.params.desiredState.playbackState.getTransition())==null?void 0:t.to)==="ready"&&O(this.params.desiredState.playbackState,"ready")}handleRemoteStop(){this.videoState.getState()!=="stopped"&&this.videoState.setState("stopped")}handleRemoteVolumeChange(e){var r,a;let t=this.params.output.volume$.getValue(),i={volume:(r=e.volume)!=null?r:t.volume,muted:(a=e.muted)!=null?a:t.muted};(i.volume!==t.volume||i.muted!==i.muted)&&this.params.output.volume$.next(i)}seek(e){this.params.output.willSeekEvent$.next();let{remotePlayer:t,remotePlayerController:i}=this.params.connection;t.currentTime=e,i.seek()}stop(){let{remotePlayerController:e}=this.params.connection;e.stop()}createMediaInfo(e){var l;let t=this.params.source,i,r,a;switch(e){case"MPEG":{let c=t[e];(0,j.assertNonNullable)(c);let d=(0,j.getHighestQuality)(Object.keys(c));(0,j.assertNonNullable)(d);let f=c[d];(0,j.assertNonNullable)(f),i=f,r="video/mp4",a=chrome.cast.media.StreamType.BUFFERED;break}case"HLS":case"HLS_FMP4":case"HLS_ONDEMAND":{let c=t[e];(0,j.assertNonNullable)(c),i=c.url,r="application/x-mpegurl",a=chrome.cast.media.StreamType.BUFFERED;break}case"DASH_SEP":case"DASH_ONDEMAND":case"DASH_WEBM":case"DASH_WEBM_AV1":case"DASH_STREAMS":{let c=t[e];(0,j.assertNonNullable)(c),i=c.url,r="application/dash+xml",a=chrome.cast.media.StreamType.BUFFERED;break}case"DASH_LIVE_CMAF":{let c=t[e];(0,j.assertNonNullable)(c),i=c.url,r="application/dash+xml",a=chrome.cast.media.StreamType.LIVE;break}case"HLS_LIVE":case"HLS_LIVE_CMAF":{let c=t[e];(0,j.assertNonNullable)(c),i=xe(c.url),r="application/x-mpegurl",a=chrome.cast.media.StreamType.LIVE;break}case"DASH_LIVE":case"WEB_RTC_LIVE":{let c="Unsupported format for Chromecast",d=new Error(c);throw this.params.output.error$.next({id:"ChromecastProvider.createMediaInfo()",category:j.ErrorCategory.VIDEO_PIPELINE,message:c,thrown:d}),d}case"DASH":case"DASH_LIVE_WEBM":throw new Error(`${e} is no longer supported`);default:return(0,j.assertNever)(e)}let n=new chrome.cast.media.MediaInfo((l=this.params.meta.videoId)!=null?l:i,r);n.contentUrl=i,n.streamType=a,n.metadata=new chrome.cast.media.GenericMediaMetadata;let{title:o,subtitle:u}=this.params.meta;return(0,j.isNonNullable)(o)&&(n.metadata.title=o),(0,j.isNonNullable)(u)&&(n.metadata.subtitle=u),n}createLoadRequest(e){let t=new chrome.cast.media.LoadRequest(e);t.autoplay=!1;let i=this.params.desiredState.seekState.getState();return i.state==="applying"||i.state==="requested"?t.currentTime=this.params.output.isLive$.getValue()?0:i.position/1e3:t.currentTime=0,t}loadMedia(e){let t=this.params.connection.session.loadMedia(e),i=new Promise((r,a)=>{this.loadMediaTimeoutSubscription.add((0,j.timeout)(lg).subscribe(()=>a(`timeout(${lg})`)))});(0,cg.default)(Promise.race([t,i]).then(()=>{this.log({message:`[loadMedia] completed, format: ${this.params.format}`}),this.params.desiredState.seekState.getState().state==="applying"&&this.params.output.seekedEvent$.next(),this.handleRemoteReady()},r=>{let a=`[prepare] loadMedia failed, format: ${this.params.format}, reason: ${r}`;this.log({message:a}),this.params.output.error$.next({id:"ChromecastProvider.loadMedia",category:j.ErrorCategory.VIDEO_PIPELINE,message:a,thrown:r})}),()=>{this.loadMediaTimeoutSubscription.unsubscribe()})}logRemoteEvent(e){this.log({message:`[remoteEvent] ${JSON.stringify(e)}`})}};var Ml=G(Ne(),1);var Tl=require("@vkontakte/videoplayer-shared/es2018");var dg=require("@vkontakte/videoplayer-shared/es2018"),pg=s=>{try{s.pause(),s.playbackRate=0,(0,dg.clearVideoElement)(s),s.remove()}catch(e){console.error(e)}};var gn=require("@vkontakte/videoplayer-shared/es2018"),vl=class{constructor(){this.attribute="data-pool-reused"}get(e){return e.hasAttribute(this.attribute)}set(e,t){e.toggleAttribute(this.attribute,t)}delete(e){e.removeAttribute(this.attribute)}},Sl=window.WeakMap?new WeakMap:new vl,yl=window.WeakMap?new WeakMap:new Map,CR=(s,e=20)=>{let t=0;return(0,gn.fromEvent)(s,"ratechange").subscribe(i=>{t++,t>=e&&(s.currentTime=s.currentTime,t=0)})},je=(s,{audioVideoSyncRate:e,disableYandexPiP:t})=>{let i=s.querySelector("video"),r=!!i;i?(0,Tl.clearVideoElement)(i):(i=document.createElement("video"),s.appendChild(i)),Sl.set(i,r);let a=new gn.Subscription;return a.add(CR(i,e)),yl.set(i,a),i.setAttribute("crossorigin","anonymous"),i.setAttribute("playsinline","playsinline"),t&&i.setAttribute("x-yandex-pip","false"),i.controls=!1,i.setAttribute("poster","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="),i},Qe=s=>{let e=yl.get(s);e==null||e.unsubscribe(),yl.delete(s);let t=Sl.get(s);Sl.delete(s),t?(0,Tl.clearVideoElement)(s):pg(s)};var Il=G(Pi(),1),Q=require("@vkontakte/videoplayer-shared/es2018");var oi=require("@vkontakte/videoplayer-shared/es2018"),vn=(s,e,t,{equal:i=(n,o)=>n===o,changed$:r,onError:a}={})=>{let n=s.getState(),o=e(),u=(0,oi.isNullable)(r),l=new oi.Subscription;return r&&l.add(r.subscribe(c=>{let d=s.getState();i(c,d)&&s.setState(c)},a)),i(o,n)||(t(n),u&&s.setState(n)),l.add(s.stateChangeStarted$.subscribe(c=>{t(c.to),u&&s.setState(c.to)},a)),l},kt=(s,e,t)=>vn(e,()=>s.loop,i=>{(0,oi.isNonNullable)(i)&&(s.loop=i)},{onError:t}),We=(s,e,t,i)=>vn(e,()=>({muted:s.muted,volume:s.volume}),r=>{(0,oi.isNonNullable)(r)&&(s.muted=r.muted,s.volume=r.volume)},{equal:(r,a)=>r===a||(r==null?void 0:r.muted)===(a==null?void 0:a.muted)&&(r==null?void 0:r.volume)===(a==null?void 0:a.volume),changed$:t,onError:i}),ut=(s,e,t,i)=>vn(e,()=>s.playbackRate,r=>{(0,oi.isNonNullable)(r)&&(s.playbackRate=r)},{changed$:t,onError:i}),hs=vn;var BR=s=>["__",s.language,s.label].join("|"),VR=(s,e)=>{if(s.id===e)return!0;let[t,i,r]=e.split("|");return s.language===i&&s.label===r},El=class s{constructor(e){this.available$=new Q.Subject;this.current$=new Q.ValueSubject(void 0);this.error$=new Q.Subject;this.subscription=new Q.Subscription;this.externalTracks=new Map;this.internalTracks=new Map;this.baseURL=e}connect(e,t,i){this.video=e,this.cueSettings=t.textTrackCuesSettings,this.subscribe();let r=a=>{this.error$.next({id:"TextTracksManager",category:Q.ErrorCategory.WTF,message:"Generic HtmlVideoTextTrackManager error",thrown:a})};this.subscription.add(this.available$.subscribe(i.availableTextTracks$)),this.subscription.add(this.current$.subscribe(i.currentTextTrack$)),this.subscription.add(this.error$.subscribe(i.error$)),this.subscription.add(hs(t.internalTextTracks,()=>(0,Il.default)(this.internalTracks),a=>{(0,Q.isNonNullable)(a)&&this.setInternal(a)},{equal:(a,n)=>(0,Q.isNonNullable)(a)&&(0,Q.isNonNullable)(n)&&a.length===n.length&&a.every(({id:o},u)=>o===n[u].id),changed$:this.available$.pipe((0,Q.map)(a=>a.filter(({type:n})=>n==="internal"))),onError:r})),this.subscription.add(hs(t.externalTextTracks,()=>(0,Il.default)(this.externalTracks),a=>{(0,Q.isNonNullable)(a)&&this.setExternal(a)},{equal:(a,n)=>(0,Q.isNonNullable)(a)&&(0,Q.isNonNullable)(n)&&a.length===n.length&&a.every(({id:o},u)=>o===n[u].id),changed$:this.available$.pipe((0,Q.map)(a=>a.filter(({type:n})=>n==="external"))),onError:r})),this.subscription.add(hs(t.currentTextTrack,()=>{if(this.video)return;let a=this.htmlTextTracksAsArray().find(({mode:n})=>n==="showing");return a&&this.htmlTextTrackToITextTrack(a).id},a=>this.select(a),{changed$:this.current$,onError:r})),this.subscription.add(hs(t.textTrackCuesSettings,()=>({}),()=>{if(this.video)for(let a of this.htmlTextTracksAsArray())this.applyCueSettings(a.cues),this.applyCueSettings(a.activeCues)}))}subscribe(){(0,Q.assertNonNullable)(this.video);let{textTracks:e}=this.video;this.subscription.add((0,Q.fromEvent)(e,"addtrack").subscribe(()=>{let i=this.current$.getValue();i&&this.select(i)})),this.subscription.add((0,Q.merge)((0,Q.fromEvent)(e,"addtrack"),(0,Q.fromEvent)(e,"removetrack"),(0,Q.observableFrom)(["init"])).pipe((0,Q.map)(()=>this.htmlTextTracksAsArray().map(i=>this.htmlTextTrackToITextTrack(i))),(0,Q.filterChanged)((i,r)=>i.length===r.length&&i.every(({id:a},n)=>a===r[n].id))).subscribe(this.available$)),this.subscription.add((0,Q.merge)((0,Q.fromEvent)(e,"change"),(0,Q.observableFrom)(["init"])).pipe((0,Q.map)(()=>this.htmlTextTracksAsArray().find(({mode:i})=>i==="showing")),(0,Q.map)(i=>i&&this.htmlTextTrackToITextTrack(i).id),(0,Q.filterChanged)()).subscribe(this.current$));let t=i=>{var r,a;return this.applyCueSettings((a=(r=i.target)==null?void 0:r.activeCues)!=null?a:null)};this.subscription.add((0,Q.fromEvent)(e,"addtrack").subscribe(i=>{var a,n;(a=i.track)==null||a.addEventListener("cuechange",t);let r=o=>{var l,c,d,f,p;let u=(c=(l=o.target)==null?void 0:l.cues)!=null?c:null;u&&u.length&&(this.applyCueSettings((f=(d=o.target)==null?void 0:d.cues)!=null?f:null),(p=o.target)==null||p.removeEventListener("cuechange",r))};(n=i.track)==null||n.addEventListener("cuechange",r)})),this.subscription.add((0,Q.fromEvent)(e,"removetrack").subscribe(i=>{var r;(r=i.track)==null||r.removeEventListener("cuechange",t)}))}applyCueSettings(e){if(!e||!e.length)return;let t=this.cueSettings.getState();for(let i of Array.from(e)){let r=i;(0,Q.isNonNullable)(t.align)&&(r.align=t.align),(0,Q.isNonNullable)(t.position)&&(r.position=t.position),(0,Q.isNonNullable)(t.size)&&(r.size=t.size),(0,Q.isNonNullable)(t.line)&&(r.line=t.line)}}htmlTextTracksAsArray(e=!1){(0,Q.assertNonNullable)(this.video);let t=[...this.video.textTracks];return e?t:t.filter(s.isHealthyTrack)}htmlTextTrackToITextTrack(e){var o,u,l,c,d;let{language:t,label:i}=e,r=e.id?e.id:BR(e),a=this.externalTracks.has(r),n=(l=a?(o=this.externalTracks.get(r))==null?void 0:o.isAuto:(u=this.internalTracks.get(r))==null?void 0:u.isAuto)!=null?l:r.includes("auto");return a?{id:r,type:"external",isAuto:n,language:t,label:i,url:(c=this.externalTracks.get(r))==null?void 0:c.url}:{id:r,type:"internal",isAuto:n,language:t,label:i,url:(d=this.internalTracks.get(r))==null?void 0:d.url}}static isHealthyTrack(e){return!(e.kind==="metadata"||e.groupId||e.id===""&&e.label===""&&e.language==="")}setExternal(e){this.internalTracks.size>0&&Array.from(this.internalTracks).forEach(([,t])=>this.detach(t)),e.filter(({id:t})=>!this.externalTracks.has(t)).forEach(t=>this.attach(t)),Array.from(this.externalTracks).filter(([t])=>!e.find(i=>i.id===t)).forEach(([,t])=>this.detach(t))}setInternal(e){let t=[...this.externalTracks];e.filter(({id:i,language:r,isAuto:a})=>!this.internalTracks.has(i)&&!t.some(([,n])=>n.language===r&&n.isAuto===a)).forEach(i=>this.attach(i)),Array.from(this.internalTracks).filter(([i])=>!e.find(r=>r.id===i)).forEach(([,i])=>this.detach(i))}select(e){(0,Q.assertNonNullable)(this.video);for(let t of this.htmlTextTracksAsArray(!0))t.mode="showing";for(let t of this.htmlTextTracksAsArray(!0))((0,Q.isNullable)(e)||!VR(t,e))&&(t.mode="disabled")}destroy(){if(this.subscription.unsubscribe(),this.video)for(let e of Array.from(this.video.getElementsByTagName("track"))){let t=e.getAttribute("id");t&&this.externalTracks.has(t)&&this.video.removeChild(e)}this.externalTracks.clear()}attach(e){(0,Q.assertNonNullable)(this.video);let t=document.createElement("track");this.baseURL?t.setAttribute("src",new URL(e.url,this.baseURL).toString()):t.setAttribute("src",e.url),t.setAttribute("id",e.id),e.label&&t.setAttribute("label",e.label),e.language&&t.setAttribute("srclang",e.language),e.type==="external"?this.externalTracks.set(e.id,e):e.type==="internal"&&this.internalTracks.set(e.id,e),this.video.appendChild(t)}detach(e){(0,Q.assertNonNullable)(this.video);let t=Array.prototype.find.call(this.video.getElementsByTagName("track"),i=>i.getAttribute("id")===e.id);t&&this.video.removeChild(t),e.type==="external"?this.externalTracks.delete(e.id):e.type==="internal"&&this.internalTracks.delete(e.id)}},lt=El;var Di=class{constructor(){this.pausedTime=0;this.streamOffset=0;this.pauseTimestamp=0}getTotalPausedTime(){return this.pausedTime+this.getCurrentPausedTime()}getCurrentPausedTime(){return this.pauseTimestamp>0?Date.now()-this.pauseTimestamp:0}getStreamOffset(){return this.streamOffset}getTotalOffset(){return this.getTotalPausedTime()+this.streamOffset}pause(){this.pauseTimestamp===0&&(this.pauseTimestamp=Date.now())}resume(){this.pauseTimestamp>0&&(this.pausedTime+=this.getCurrentPausedTime(),this.pauseTimestamp=0)}resetTo(e,t=!1){this.streamOffset=e,this.pauseTimestamp=0,this.pausedTime=0,t&&this.pause()}};var hg=s=>{let e=s;for(;!(e instanceof Document)&&!(e instanceof ShadowRoot)&&e!==null;)e=e==null?void 0:e.parentNode;return e!=null?e:void 0},xl=s=>{let e=hg(s);return!!(e&&e.fullscreenElement&&e.fullscreenElement===s)},fg=s=>{let e=hg(s);return!!(e&&e.pictureInPictureElement&&e.pictureInPictureElement===s)};var L=require("@vkontakte/videoplayer-shared/es2018");var _R=3,mg=(s,e,t=_R)=>{let i=0,r=0;for(let a=0;a<s.length;a++){let n=s.start(a),o=s.end(a);if(n<=e&&e<=o){if(i=n,r=o,!t)return{from:i,to:r};for(let u=a-1;u>=0;u--)s.end(u)+t>=i&&(i=s.start(u));for(let u=a+1;u<s.length;u++)s.start(u)-t<=r&&(r=s.end(u))}}return{from:i,to:r}};var Ge=s=>{let e=B=>(0,L.fromEvent)(s,B).pipe((0,L.mapTo)(void 0),(0,L.shareReplay)(1)),t=new L.Subscription,i=()=>t.unsubscribe(),r=(0,L.merge)((0,L.fromEvent)(s,"progress"),(0,L.fromEvent)(s,"timeupdate")).pipe((0,L.map)(()=>mg(s.buffered,s.currentTime)),(0,L.shareReplay)(1)),a=z.browser.isSafari?(0,L.combine)({play:e("play").pipe((0,L.once)()),playing:e("playing")}).pipe((0,L.mapTo)(void 0),(0,L.shareReplay)(1)):e("playing"),n=(0,L.fromEvent)(s,"volumechange").pipe((0,L.map)(()=>({muted:s.muted,volume:s.volume})),(0,L.shareReplay)(1)),o=(0,L.fromEvent)(s,"ratechange").pipe((0,L.map)(()=>s.playbackRate),(0,L.shareReplay)(1)),u=(0,L.fromEvent)(s,"error").pipe((0,L.filter)(()=>!!(s.error||s.played.length)),(0,L.map)(()=>{var H;let B=s.error;return{id:B?`MediaError#${B.code}`:"HtmlVideoError",category:L.ErrorCategory.VIDEO_PIPELINE,message:B?B.message:"Error event from HTML video element",thrown:(H=s.error)!=null?H:void 0}}),(0,L.shareReplay)(1)),l=(0,L.fromEvent)(s,"timeupdate").pipe((0,L.map)(()=>s.currentTime),(0,L.shareReplay)(1)),c=["waiting","seeking","seeked","timeupdate"],d=new L.Subject,f=.3,p;t.add((0,L.merge)(...c.map(B=>(0,L.fromEvent)(s,B))).subscribe(B=>{let H=s.currentTime;s.loop&&(0,L.isNonNullable)(p)&&(0,L.isNonNullable)(H)&&p>=s.duration-f&&H<=f&&d.next(p),p=H}));let h=e("pause").pipe((0,L.filter)(()=>!s.error&&p!==s.duration),(0,L.shareReplay)(1)),b=(0,L.fromEvent)(s,"enterpictureinpicture").pipe((0,L.shareReplay)(1)),S=(0,L.fromEvent)(s,"leavepictureinpicture").pipe((0,L.shareReplay)(1)),g=new L.ValueSubject(fg(s));t.add(b.subscribe(()=>g.next(!0))),t.add(S.subscribe(()=>g.next(!1)));let I=new L.ValueSubject(xl(s)),w=(0,L.fromEvent)(s,"fullscreenchange").pipe((0,L.shareReplay)(1));t.add(w.pipe((0,L.map)(()=>xl(s))).subscribe(I));let E=.1,P=1e3,_=(0,L.fromEvent)(s,"timeupdate").pipe((0,L.map)(B=>s.duration-s.currentTime<E),(0,L.filterChanged)(),(0,L.shareReplay)(1)),N=(0,L.merge)(_.pipe((0,L.filter)(B=>!s.loop&&B)),(0,L.fromEvent)(s,"ended")).pipe((0,L.throttle)(P),(0,L.mapTo)(void 0),(0,L.shareReplay)(1)),C=(0,L.merge)(...["waiting","pause","canplay","play","canplaythrough","playing","seeking","seeked","ended"].map(B=>(0,L.fromEvent)(s,B)),_.pipe((0,L.map)(B=>({type:B?"ended":"unknown"})))).pipe((0,L.map)(B=>z.browser.isFirefox&&B.type==="ended"?s.readyState<2:s.readyState<3),(0,L.filterChanged)(),(0,L.shareReplay)(1));return{playing$:a,pause$:h,canplay$:e("canplay"),ended$:N,looped$:d,error$:u,seeked$:e("seeked"),seeking$:e("seeking"),progress$:e("progress"),loadStart$:e("loadstart"),loadedMetadata$:e("loadedmetadata"),loadedData$:e("loadeddata"),timeUpdate$:l,durationChange$:(0,L.fromEvent)(s,"durationchange").pipe((0,L.map)(()=>s.duration),(0,L.shareReplay)(1)),isBuffering$:C,currentBuffer$:r,volumeState$:n,playbackRateState$:o,inPiP$:g,inFullscreen$:I,enterPip$:b,leavePip$:S,destroy:i}};var qt=require("@vkontakte/videoplayer-shared/es2018"),ui=s=>{switch(s){case"mobile":return qt.VideoQuality.Q_144P;case"lowest":return qt.VideoQuality.Q_240P;case"low":return qt.VideoQuality.Q_360P;case"sd":case"medium":return qt.VideoQuality.Q_480P;case"hd":case"high":return qt.VideoQuality.Q_720P;case"fullhd":case"full":return qt.VideoQuality.Q_1080P;case"quadhd":case"quad":return qt.VideoQuality.Q_1440P;case"ultrahd":case"ultra":return qt.VideoQuality.Q_2160P}};var Ue=G(yt(),1),Pl=G(Ne(),1),Ci=G(sr(),1),D=require("@vkontakte/videoplayer-shared/es2018");var wl=!1,Ut={},Ig=s=>{wl=s},Eg=()=>{Ut={}},xg=s=>{s(Ut)},fs=(s,e)=>{var t;wl&&(Ut.meta=(t=Ut.meta)!=null?t:{},Ut.meta[s]=e)},qe=class{constructor(e){this.name=e}next(e){var i,r;if(!wl)return;Ut.series=(i=Ut.series)!=null?i:{};let t=(r=Ut.series[this.name])!=null?r:[];t.push([Date.now(),e]),Ut.series[this.name]=t}};var Pe=require("@vkontakte/videoplayer-shared/es2018");function Al(s,e,t){return!s.max&&s.min===e?"high_quality":!s.min&&s.max===t?"traffic_saving":"unknown"}function Sn(s,e,t){return!!s&&Al(s,e,t)==="high_quality"}function br(s,e,t){return(0,Pe.isNullable)(s)||(0,Pe.isNonNullable)(s.min)&&(0,Pe.isNonNullable)(s.max)&&(0,Pe.isLower)(s.max,s.min)||(0,Pe.isNonNullable)(s.min)&&e&&(0,Pe.isHigher)(s.min,e)||(0,Pe.isNonNullable)(s.max)&&t&&(0,Pe.isLower)(s.max,t)}function wg({limits:s,highestAvailableHeight:e,lowestAvailableHeight:t}){return br({max:s!=null&&s.max?(0,Pe.videoHeightToQuality)(s.max):void 0,min:s!=null&&s.min?(0,Pe.videoHeightToQuality)(s.min):void 0},e?(0,Pe.videoHeightToQuality)(e):void 0,t?(0,Pe.videoHeightToQuality)(t):void 0)}var Lg=new qe("best_bitrate"),Tn=(s,e,t)=>(e-t)*Math.pow(2,-10*s)+t;var gr=s=>(e,t)=>s*(Number(e.bitrate)-Number(t.bitrate)),li=class{constructor(){this.history={}}recordSelection(e){this.history[e.id]=(0,D.now)()}recordSwitch(e){this.last=e}clear(){this.last=void 0,this.history={}}},In='Assertion "ABR Tracks is empty array" failed',yn=new WeakMap,Ag=new WeakMap,Pg=new WeakMap,ms=(s,e,t,i)=>{var u;let r=[...e].sort(gr(1)),a=[...t].sort(gr(1)),n=a.filter(l=>(0,D.isNonNullable)(l.bitrate)&&(0,D.isNonNullable)(s.bitrate)?s.bitrate/l.bitrate>i:!0),o=(u=(0,Ue.default)(a,Math.round(a.length*r.indexOf(s)/(r.length+1))))!=null?u:(0,Ue.default)(a,-1);return o&&(0,Pl.default)(n,o)?o:n.length?(0,Ue.default)(n,-1):(0,Ue.default)(a,0)},bs=(s,e,t,i)=>{var u;let r=yn.get(e);r||(r=[...e].sort(gr(1)),yn.set(e,r));let a=yn.get(t);a||(a=[...t].sort(gr(1)),yn.set(t,a));let n=Pg.get(s);n||(n=a.filter(l=>(0,D.isNonNullable)(l.bitrate)&&(0,D.isNonNullable)(s.bitrate)?s.bitrate/l.bitrate>i:!0),Pg.set(s,n));let o=(u=(0,Ue.default)(a,Math.round(a.length*r.indexOf(s)/(r.length+1))))!=null?u:(0,Ue.default)(a,-1);return o&&(0,Pl.default)(n,o)?o:n.length?(0,Ue.default)(n,-1):(0,Ue.default)(a,0)},Rg=s=>"quality"in s,En=(s,e,t,i)=>{var n;let r=(0,D.isNonNullable)((n=i==null?void 0:i.last)==null?void 0:n.bitrate)&&(0,D.isNonNullable)(t==null?void 0:t.bitrate)&&i.last.bitrate<t.bitrate?s.trackCooldownIncreaseQuality:s.trackCooldownDecreaseQuality,a=t&&i&&i.history[t.id]&&(0,D.now)()-i.history[t.id]<=r&&(!i.last||t.id!==i.last.id);if(t!=null&&t.id&&i&&!a&&i.recordSelection(t),a&&(i!=null&&i.last)){let o=i.last;i==null||i.recordSwitch(o);let u=Rg(o)?"video":"audio",l=Rg(o)?o.quality:o.bitrate;return e({message:`
8
8
  [last ${u} selected] ${l}
9
9
  `}),o}return i==null||i.recordSwitch(t),t},WR=(s,e)=>Math.log(e)/Math.log(s),$g=({tuning:s,container:e,limits:t,panelSize:i})=>{let r=s.containerSizeFactor;if(i)return{containerSizeLimit:i,containerSizeFactor:r};if(s.usePixelRatio&&z.display.pixelRatio){let a=z.display.pixelRatio;if(s.pixelRatioMultiplier)r*=s.pixelRatioMultiplier*(a-1)+1;else{let n=s.pixelRatioLogBase,[o=0,u=0,l=0]=s.pixelRatioLogCoefficients,c=WR(n,o*a+u)+l;Number.isFinite(c)&&(r*=c)}}return Sn(t,s.highQualityLimit,s.trafficSavingLimit)&&(r*=2),{containerSizeLimit:s.limitByContainer&&e&&e.width>0&&e.height>0?{width:e.width*r,height:e.height*r}:void 0,containerSizeFactor:r}},kg=new WeakMap,Lt=(s,{container:e,estimatedThroughput:t,tuning:i,limits:r,reserve:a=0,forwardBufferHealth:n,playbackRate:o,current:u,history:l,visible:c,droppedVideoMaxQualityLimit:d,stallsVideoMaxQualityLimit:f,stallsPredictedThroughput:p,abrLogger:h,panelSize:b})=>{var W,ue,le,A,V;(0,D.assertNotEmptyArray)(s,In);let{containerSizeFactor:S,containerSizeLimit:g}=$g({container:e,tuning:i,limits:r,panelSize:b}),I=i.considerPlaybackRate&&(0,D.isNonNullable)(o)?o:1,w=kg.get(s);w||(w=s.filter($=>!(0,D.isInvariantQuality)($.quality)).sort(($,M)=>(0,D.isHigher)($.quality,M.quality)?-1:1),kg.set(s,w));let E=(W=(0,Ue.default)(w,-1))==null?void 0:W.quality,P=(ue=(0,Ue.default)(w,0))==null?void 0:ue.quality,_=br(r,P,E),N=I*Tn(n!=null?n:.5,i.bitrateFactorAtEmptyBuffer,i.bitrateFactorAtFullBuffer),F={},C=null;for(let $ of w){let M=!0;if(g)if($.size)M=$.size.width<=g.width&&$.size.height<=g.height;else{let Je=g&&(0,D.videoSizeToQuality)(g);M=Je?(0,D.isLowerOrEqual)($.quality,Je):!0}if(!M){F[$.quality]="FitsContainer";continue}let U=p||t,Te=(0,D.isNonNullable)(U)&&isFinite(U)&&(0,D.isNonNullable)($.bitrate)?U-a>=$.bitrate*N:!0,Xe=Sn(r,i.highQualityLimit,i.trafficSavingLimit)&&(r==null?void 0:r.min)===$.quality;if(!Te&&!Xe){F[$.quality]="FitsThroughput";continue}if(i.lazyQualitySwitch&&(0,D.isNonNullable)(i.minBufferToSwitchUp)&&u&&!(0,D.isInvariantQuality)(u.quality)&&(n!=null?n:0)<i.minBufferToSwitchUp&&(0,D.isHigher)($.quality,u.quality)){F[$.quality]="Buffer";continue}if(!!d&&(0,D.isHigherOrEqual)($.quality,d)&&!Xe){F[$.quality]="DroppedFramesLimit";continue}if(!!f&&(0,D.isHigherOrEqual)($.quality,f)&&!Xe){F[$.quality]="StallsLimit";continue}let De=_||((0,D.isNullable)(r==null?void 0:r.max)||(0,D.isLowerOrEqual)($.quality,r.max))&&((0,D.isNullable)(r==null?void 0:r.min)||(0,D.isHigherOrEqual)($.quality,r.min)),Ce=(0,D.isNonNullable)(c)&&!c?(0,D.isLowerOrEqual)($.quality,i.backgroundVideoQualityLimit):!0;if(!De||!Ce){F[$.quality]="FitsQualityLimits";continue}C||(C=$)}C&&C.bitrate&&Lg.next(C.bitrate);let B=(le=C!=null?C:(0,Ue.default)(w,-1))!=null?le:s[0],H=l==null?void 0:l.last,q=En(i,h,B,l);return(0,D.isNonNullable)(l)&&q.quality!==(H==null?void 0:H.quality)&&h({message:`
10
10
  [VIDEO TRACKS ABR]
@@ -121,7 +121,7 @@
121
121
  (?<variants>(?:-(?:[a-z0-9]{5,8}|[0-9][a-z0-9]{3}))*)
122
122
  (?<extensions>(?:-[0-9a-wy-z](?:-[a-z0-9]{2,8})+)*)
123
123
  (?:-(?<privateuse>(?:${e})))?
124
- `})|(?<privateuse2>${e}))$`.replace(/[\s\t\n]/g,"");return new RegExp(c,"i")}var MS=s=>{if(!(s!=null&&s.startsWith("P")))return;let e=(n,o)=>{let u=n?parseFloat(n.replace(",",".")):NaN;return(isNaN(u)?0:u)*o},i=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/.exec(s),r=(i==null?void 0:i[1])==="-"?-1:1,a={days:e(i==null?void 0:i[5],r),hours:e(i==null?void 0:i[6],r),minutes:e(i==null?void 0:i[7],r),seconds:e(i==null?void 0:i[8],r)};return a.days*24*60*60*1e3+a.hours*60*60*1e3+a.minutes*60*1e3+a.seconds*1e3},It=(s,e)=>{let t=s;t=(0,Wl.default)(t,"$$","$");let i={RepresentationID:e.representationId,Number:e.segmentNumber,Bandwidth:e.bandwidth,Time:e.segmentTime};for(let[r,a]of(0,DS.default)(i)){let n=new RegExp(`\\$${r}(?:%0(\\d+)d)?\\$`,"g");t=(0,Wl.default)(t,n,(o,u)=>(0,Xs.isNullable)(a)?o:(0,Xs.isNullable)(u)?a:(0,CS.default)(a,parseInt(u,10),"0"))}return t},Dn=(s,e)=>{var C,B,H,q,W,ue,le,A,V,$,M,U,Te,Xe,me,ne,Me,De,Ce,Je,Vt,Kt,mi,ji,Dr,Ic,Ec,xc,wc,Ac,Pc,Rc,kc,Lc,$c,Mc,Dc,Cc,Bc,Vc,_c,Oc,Fc,Nc,qc,Uc,Hc,jc,Qc,Wc,Gc,zc,Yc,Kc,Xc,Jc,Zc,ed,td,id,rd;let i=new DOMParser().parseFromString(s,"application/xml"),r={video:[],audio:[],text:[]},a=i.children[0],n=Array.from(a.querySelectorAll("MPD > BaseURL").values()).map(ht=>{var fe,bi;return(bi=(fe=ht.textContent)==null?void 0:fe.trim())!=null?bi:""}),o=(C=(0,BS.default)(n,0))!=null?C:"",u=a.getAttribute("type")==="dynamic",l=a.getAttribute("availabilityStartTime"),c=a.getAttribute("publishTime"),d=a.getElementsByTagName("vk:Attrs")[0],f=d==null?void 0:d.getElementsByTagName("vk:XLatestSegmentPublishTime")[0].textContent,p=d==null?void 0:d.getElementsByTagName("vk:XStreamIsLive")[0].textContent,h=d==null?void 0:d.getElementsByTagName("vk:XStreamIsUnpublished")[0].textContent,b=d==null?void 0:d.getElementsByTagName("vk:XPlaybackDuration")[0].textContent,S;u&&(S={availabilityStartTime:l?new Date(l).getTime():0,publishTime:c?new Date(c).getTime():0,latestSegmentPublishTime:f?new Date(f).getTime():0,streamIsAlive:p==="yes",streamIsUnpublished:h==="yes"});let g,I=a.getAttribute("mediaPresentationDuration"),w=[...a.getElementsByTagName("Period")],E=w.reduce((ht,fe)=>({...ht,[fe.id]:fe.children}),{}),P=w.reduce((ht,fe)=>({...ht,[fe.id]:fe.getAttribute("duration")}),{});I?g=MS(I):(0,Gl.default)(P).filter(ht=>ht).length&&!u?g=(0,Gl.default)(P).reduce((ht,fe)=>{var bi;return ht+((bi=MS(fe))!=null?bi:0)},0):b&&(g=parseInt(b,10));let _=0,N=(H=(B=a.getAttribute("profiles"))==null?void 0:B.split(","))!=null?H:[];for(let ht of w.map(fe=>fe.id))for(let fe of E[ht]){let bi=(q=fe.getAttribute("id"))!=null?q:"id"+(_++).toString(10),Cr=(W=fe.getAttribute("mimeType"))!=null?W:"",vo=(ue=fe.getAttribute("codecs"))!=null?ue:"",So=(le=fe.getAttribute("contentType"))!=null?le:Cr==null?void 0:Cr.split("/")[0],$y=(V=(A=fe.getAttribute("profiles"))==null?void 0:A.split(","))!=null?V:[],sd=(M=$S(($=fe.getAttribute("lang"))!=null?$:""))!=null?M:{},ma=(Xe=(Te=(U=fe.querySelector("Label"))==null?void 0:U.textContent)==null?void 0:Te.trim())!=null?Xe:void 0,My=fe.querySelectorAll("Representation"),Dy=fe.querySelector("SegmentTemplate"),Cy=(ne=(me=fe.querySelector("Role"))==null?void 0:me.getAttribute("value"))!=null?ne:void 0,Qi=So,we={id:bi,language:sd.language,isDefault:Cy==="main",label:ma,codecs:vo,hdr:Qi==="video"&&Ql(vo),mime:Cr,representations:[]};for(let de of My){let Xt=(Me=de.getAttribute("lang"))!=null?Me:void 0,Br=(Ce=(De=ma!=null?ma:fe.getAttribute("label"))!=null?De:de.getAttribute("label"))!=null?Ce:void 0,ba=(Kt=(Vt=(Je=de.querySelector("BaseURL"))==null?void 0:Je.textContent)==null?void 0:Vt.trim())!=null?Kt:"",gi=new URL(ba||o,e).toString(),Jt=(mi=de.getAttribute("mimeType"))!=null?mi:Cr,ga=(Dr=(ji=de.getAttribute("codecs"))!=null?ji:vo)!=null?Dr:"",va;if(So==="text"){let Zt=de.getAttribute("id")||"",Sa=((Ic=sd.privateuse)==null?void 0:Ic.includes("x-auto"))||Zt.includes("_auto"),vi=de.querySelector("SegmentTemplate");if(vi){let Vr={representationId:(Ec=de.getAttribute("id"))!=null?Ec:void 0,bandwidth:(xc=de.getAttribute("bandwidth"))!=null?xc:void 0},ya=parseInt((wc=de.getAttribute("bandwidth"))!=null?wc:"",10)/1e3,Ta=(Pc=parseInt((Ac=vi.getAttribute("startNumber"))!=null?Ac:"",10))!=null?Pc:1,Wi=parseInt((Rc=vi.getAttribute("timescale"))!=null?Rc:"",10),yo=(kc=vi.querySelectorAll("SegmentTimeline S"))!=null?kc:[],Gi=vi.getAttribute("media");if(!Gi)continue;let Ia=[],Ea=0,xa="",zi=0,_r=Ta,Oe=0;for(let ft of yo){let Si=parseInt((Lc=ft.getAttribute("d"))!=null?Lc:"",10),ot=parseInt(($c=ft.getAttribute("r"))!=null?$c:"",10)||0,ei=parseInt((Mc=ft.getAttribute("t"))!=null?Mc:"",10);Oe=Number.isFinite(ei)?ei:Oe;let yi=Si/Wi*1e3,ti=Oe/Wi*1e3;for(let Et=0;Et<ot+1;Et++){let ii=It(Gi,{...Vr,segmentNumber:_r.toString(10),segmentTime:(Oe+Et*Si).toString(10)}),Yi=(ti!=null?ti:0)+Et*yi,Fr=Yi+yi;_r++,Ia.push({time:{from:Yi,to:Fr},url:ii})}Oe+=(ot+1)*Si,Ea+=(ot+1)*yi}zi=Oe/Wi*1e3,xa=It(Gi,{...Vr,segmentNumber:_r.toString(10),segmentTime:Oe.toString(10)});let Or={time:{from:zi,to:1/0},url:xa},_t={type:"template",baseUrl:gi,segmentTemplateUrl:Gi,initUrl:"",totalSegmentsDurationMs:Ea,segments:Ia,nextSegmentBeyondManifest:Or,timescale:Wi};va={id:Zt,kind:"text",segmentReference:_t,profiles:[],duration:g,bitrate:ya,mime:"",codecs:"",width:0,height:0,isAuto:Sa}}else va={id:Zt,isAuto:Sa,kind:"text",url:gi}}else{let Zt=(Cc=(Dc=de.getAttribute("contentType"))!=null?Dc:Jt==null?void 0:Jt.split("/")[0])!=null?Cc:So,Sa=(Vc=(Bc=fe.getAttribute("profiles"))==null?void 0:Bc.split(","))!=null?Vc:[],vi=parseInt((_c=de.getAttribute("width"))!=null?_c:"",10),Vr=parseInt((Oc=de.getAttribute("height"))!=null?Oc:"",10),ya=parseInt((Fc=de.getAttribute("bandwidth"))!=null?Fc:"",10)/1e3,Ta=(Nc=de.getAttribute("frameRate"))!=null?Nc:"",Wi=(qc=de.getAttribute("quality"))!=null?qc:void 0,yo=Ta?LS(Ta):void 0,Gi=(Uc=de.getAttribute("id"))!=null?Uc:"id"+(_++).toString(10),Ia=Zt==="video"?`${Vr}p`:Zt==="audio"?`${ya}Kbps`:ga,Ea=`${Gi}@${Ia}`,xa=[...N,...$y,...Sa],zi,_r=de.querySelector("SegmentBase"),Oe=(Hc=de.querySelector("SegmentTemplate"))!=null?Hc:Dy;if(_r){let _t=(Qc=(jc=de.querySelector("SegmentBase Initialization"))==null?void 0:jc.getAttribute("range"))!=null?Qc:"",[ft,Si]=_t.split("-").map(ii=>parseInt(ii,10)),ot={from:ft,to:Si},ei=(Wc=de.querySelector("SegmentBase"))==null?void 0:Wc.getAttribute("indexRange"),[yi,ti]=ei?ei.split("-").map(ii=>parseInt(ii,10)):[],Et=ei?{from:yi,to:ti}:void 0;zi={type:"byteRange",url:gi,initRange:ot,indexRange:Et}}else if(Oe){let _t={representationId:(Gc=de.getAttribute("id"))!=null?Gc:void 0,bandwidth:(zc=de.getAttribute("bandwidth"))!=null?zc:void 0},ft=parseInt((Yc=Oe.getAttribute("timescale"))!=null?Yc:"",10),Si=(Kc=Oe.getAttribute("initialization"))!=null?Kc:"",ot=Oe.getAttribute("media"),ei=(Jc=parseInt((Xc=Oe.getAttribute("startNumber"))!=null?Xc:"",10))!=null?Jc:1,yi=It(Si,_t);if(!ot)throw new ReferenceError("No media attribute in SegmentTemplate");let ti=(Zc=Oe.querySelectorAll("SegmentTimeline S"))!=null?Zc:[],Et=[],ii=0,Yi="",Fr=0;if(ti.length){let wa=ei,mt=0;for(let Ki of ti){let xt=parseInt((ed=Ki.getAttribute("d"))!=null?ed:"",10),Ti=parseInt((td=Ki.getAttribute("r"))!=null?td:"",10)||0,Aa=parseInt((id=Ki.getAttribute("t"))!=null?id:"",10);mt=Number.isFinite(Aa)?Aa:mt;let To=xt/ft*1e3,Io=mt/ft*1e3;for(let Pa=0;Pa<Ti+1;Pa++){let Vy=It(ot,{..._t,segmentNumber:wa.toString(10),segmentTime:(mt+Pa*xt).toString(10)}),ad=(Io!=null?Io:0)+Pa*To,_y=ad+To;wa++,Et.push({time:{from:ad,to:_y},url:Vy})}mt+=(Ti+1)*xt,ii+=(Ti+1)*To}Fr=mt/ft*1e3,Yi=It(ot,{..._t,segmentNumber:wa.toString(10),segmentTime:mt.toString(10)})}else if((0,Xs.isNonNullable)(g)){let mt=parseInt((rd=Oe.getAttribute("duration"))!=null?rd:"",10)/ft*1e3,Ki=Math.ceil(g/mt),xt=0;for(let Ti=1;Ti<Ki;Ti++){let Aa=It(ot,{..._t,segmentNumber:Ti.toString(10),segmentTime:xt.toString(10)});Et.push({time:{from:xt,to:xt+mt},url:Aa}),xt+=mt}Fr=xt,Yi=It(ot,{..._t,segmentNumber:Ki.toString(10),segmentTime:xt.toString(10)})}let By={time:{from:Fr,to:1/0},url:Yi};zi={type:"template",baseUrl:gi,segmentTemplateUrl:ot,initUrl:yi,totalSegmentsDurationMs:ii,segments:Et,nextSegmentBeyondManifest:By,timescale:ft}}else throw new ReferenceError("Unknown MPD segment referencing type");if(!Zt||!Jt)continue;let Or={video:"video",audio:"audio",text:"text"}[Zt];if(!Or)continue;Qi||(Qi=Or),va={id:Ea,kind:Or,segmentReference:zi,profiles:xa,duration:g,bitrate:ya,mime:Jt,codecs:ga,width:vi,height:Vr,fps:yo,quality:Wi}}we.language||(we.language=Xt),we.label||(we.label=Br),we.mime||(we.mime=Jt),we.codecs||(we.codecs=ga),we.hdr||(we.hdr=Qi==="video"&&Ql(ga)),we.representations.push(va)}if(Qi){let de=r[Qi].find(Xt=>Xt.id===we.id);if(de&&we.representations.every(Xt=>Xt.segmentReference.type==="template"))for(let Xt of de.representations){let Br=we.representations.find(Jt=>Jt.id===Xt.id),ba=Br==null?void 0:Br.segmentReference,gi=Xt.segmentReference;gi.segments.push(...ba.segments),gi.nextSegmentBeyondManifest=ba.nextSegmentBeyondManifest}else r[Qi].push(we)}}return{duration:g,streams:r,baseUrls:n,live:S}};var zl=G(yt(),1);var VS=require("@vkontakte/videoplayer-shared/es2018"),_S=({id:s,width:e,height:t,bitrate:i,fps:r,quality:a,streamId:n})=>{var u;let o=(u=a?ui(a):void 0)!=null?u:(0,VS.videoSizeToQuality)({width:e,height:t});return o&&{id:s,quality:o,bitrate:i,size:{width:e,height:t},fps:r,streamId:n}},OS=({id:s,bitrate:e})=>({id:s,bitrate:e}),FS=({language:s,label:e},{id:t,url:i,isAuto:r})=>({id:t,url:i,isAuto:r,type:"internal",language:s,label:e}),NS=({language:s,label:e,id:t,url:i,isAuto:r})=>({id:t,url:i,isAuto:r,type:"internal",language:s,label:e}),Yl=({id:s,language:e,label:t,codecs:i,isDefault:r})=>({id:s,language:e,label:t,codec:(0,zl.default)(i.split("."),0),isDefault:r}),Kl=({id:s,language:e,label:t,hdr:i,codecs:r})=>({id:s,language:e,hdr:i,label:t,codec:(0,zl.default)(r.split("."),0)}),Xl=s=>"url"in s,st=s=>s.type==="template";var Jl=require("@vkontakte/videoplayer-shared/es2018"),J=(s,e)=>(0,Jl.isNonNullable)(s)&&(0,Jl.isNonNullable)(e)&&s.readyState==="open"&&s$(s,e);function s$(s,e){for(let t=0;t<s.activeSourceBuffers.length;++t)if(s.activeSourceBuffers[t]===e)return!0;return!1}var Js=class{constructor(e,t,i,{fetcher:r,tuning:a,getCurrentPosition:n,isActiveLowLatency:o,compatibilityMode:u=!1,manifest:l}){this.currentLiveSegmentServerLatency$=new R.ValueSubject(0);this.currentLowLatencySegmentLength$=new R.ValueSubject(0);this.currentSegmentLength$=new R.ValueSubject(0);this.onLastSegment$=new R.ValueSubject(!1);this.fullyBuffered$=new R.ValueSubject(!1);this.playingRepresentation$=new R.ValueSubject(void 0);this.playingRepresentationInit$=new R.ValueSubject(void 0);this.error$=new R.Subject;this.gaps=[];this.subscription=new R.Subscription;this.allInitsLoaded=!1;this.activeSegments=new Set;this.downloadAbortController=new ce;this.switchAbortController=new ce;this.destroyAbortController=new ce;this.bufferLimit=1/0;this.failedDownloads=0;this.baseUrls=[];this.baseUrlsIndex=0;this.isLive=!1;this.liveUpdateSegmentIndex=0;this.liveInitialAdditionalOffset=0;this.isSeekingLive=!1;this.index=0;this.lastDataObtainedTimestampMs=0;this.loadByteRangeSegmentsTimeoutId=0;this.startWith=(0,R.abortable)(this.destroyAbortController.signal,async function*(e){let t=this.representations.get(e);(0,R.assertNonNullable)(t,`Cannot find representation ${e}`),this.playingRepresentationId=e,this.downloadingRepresentationId=e,this.sourceBuffer=this.mediaSource.addSourceBuffer(`${t.mime}; codecs="${t.codecs}"`),this.sourceBufferTaskQueue=new Cv(this.sourceBuffer),this.subscription.add((0,R.fromEvent)(this.sourceBuffer,"updateend").subscribe(()=>{this.checkEjectedSegments(),this.maintain()},n=>{let o,u=this.mediaSource.readyState;u!=="open"&&(o={id:`SegmentEjection_source_${u}`,category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when trying to clear segments ejected by browser",thrown:n}),o!=null||(o={id:"SegmentEjection",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when trying to clear segments ejected by browser",thrown:n}),this.error$.next(o)})),this.subscription.add((0,R.fromEvent)(this.sourceBuffer,"error").subscribe(()=>this.error$.next({id:"SourceBuffer",category:R.ErrorCategory.VIDEO_PIPELINE,message:"SourceBuffer Error event fired"}))),this.subscription.add(this.sourceBufferTaskQueue.bufferFull$.subscribe(n=>{let o=this.getCurrentPosition();if(!this.sourceBuffer||!o||!J(this.mediaSource,this.sourceBuffer))return;let u=Math.min(this.bufferLimit,Er(this.sourceBuffer.buffered)*.8);this.bufferLimit=u;let l=this.getForwardBufferDuration(o),c=Math.min(this.forwardBufferTarget,this.bufferLimit)*this.tuning.dash.minSafeBufferThreshold;this.pruneBuffer(o,n*2,l<c).catch(d=>{this.handleAsyncError(d,"pruneBuffer")})})),this.subscription.add(this.sourceBufferTaskQueue.error$.subscribe(n=>this.error$.next(n))),yield this.loadInit(t,"high",!0);let i=this.initData.get(t.id),r=this.segments.get(t.id),a=this.parsedInitData.get(t.id);(0,R.assertNonNullable)(i,"No init buffer for starting representation"),(0,R.assertNonNullable)(r,"No segments for starting representation"),i instanceof ArrayBuffer&&(this.searchGaps(r,t),yield this.sourceBufferTaskQueue.append(i,this.destroyAbortController.signal),this.playingRepresentation$.next(this.playingRepresentationId),this.playingRepresentationInit$.next(a))}.bind(this));this.switchTo=(0,R.abortable)(this.destroyAbortController.signal,async function*(e,t=!1){if(!J(this.mediaSource,this.sourceBuffer)||e===this.downloadingRepresentationId||e===this.switchingToRepresentationId)return;this.switchingToRepresentationId=e;let i=this.representations.get(e);(0,R.assertNonNullable)(i,`No such representation ${e}`);let r=this.segments.get(e),a=this.initData.get(e);if((0,R.isNullable)(a)||(0,R.isNullable)(r)?yield this.loadInit(i,"high",!1):a instanceof Promise&&(yield a),r=this.segments.get(e),(0,R.assertNonNullable)(r,"No segments for starting representation"),a=this.initData.get(e),!(!a||!(a instanceof ArrayBuffer)||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(yield this.abort(),yield this.sourceBufferTaskQueue.append(a,this.downloadAbortController.signal),t)this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e,yield this.dropBuffer();else{let n=this.getCurrentPosition();(0,R.isNonNullable)(n)&&!this.isLive&&(this.bufferLimit=1/0,await this.pruneBuffer(n,1/0,!0)),this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e}this.maintain()}}.bind(this));this.switchToOld=(0,R.abortable)(this.destroyAbortController.signal,async function*(e,t=!1){if(!J(this.mediaSource,this.sourceBuffer)||e===this.downloadingRepresentationId||e===this.switchingToRepresentationId)return;this.switchingToRepresentationId=e;let i=this.representations.get(e);(0,R.assertNonNullable)(i,`No such representation ${e}`);let r=this.segments.get(e),a=this.initData.get(e);if((0,R.isNullable)(a)||(0,R.isNullable)(r)?yield this.loadInit(i,"high",!1):a instanceof Promise&&(yield a),r=this.segments.get(e),(0,R.assertNonNullable)(r,"No segments for starting representation"),a=this.initData.get(e),!(!a||!(a instanceof ArrayBuffer)||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)))if(yield this.abort(),yield this.sourceBufferTaskQueue.append(a,this.downloadAbortController.signal),t)this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e,yield this.dropBuffer(),this.maintain();else{let n=this.getCurrentPosition();(0,R.isNonNullable)(n)&&(this.isLive||(this.bufferLimit=1/0,await this.pruneBuffer(n,1/0,!0)),this.maintain(n)),this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e}}.bind(this));this.seekLive=(0,R.abortable)(this.destroyAbortController.signal,async function*(e){var u,l;let t=(u=(0,Bn.default)(e,c=>c.representations))!=null?u:[];if(this.isSeekingLive=!0,!this.downloadingRepresentationId||!t)return;for(let c of this.representations.keys()){let d=t.find(h=>h.id===c);d&&this.representations.set(c,d);let f=this.representations.get(c);if(!f||!st(f.segmentReference))return;let p=this.getActualLiveStartingSegments(f.segmentReference);this.segments.set(f.id,p)}let i=(l=this.switchingToRepresentationId)!=null?l:this.downloadingRepresentationId,r=this.representations.get(i);(0,R.assertNonNullable)(r);let a=this.segments.get(i);(0,R.assertNonNullable)(a,"No segments for starting representation");let n=this.initData.get(i);if((0,R.assertNonNullable)(n,"No init buffer for starting representation"),!(n instanceof ArrayBuffer))return;let o=this.getDebugBufferState();this.liveUpdateSegmentIndex=0,yield this.abort(),o&&(yield this.sourceBufferTaskQueue.remove(o.from*1e3,o.to*1e3,this.destroyAbortController.signal)),this.searchGaps(a,r),yield this.sourceBufferTaskQueue.append(n,this.destroyAbortController.signal),this.isSeekingLive=!1}.bind(this));var c;this.fetcher=r,this.tuning=a,this.compatibilityMode=u,this.forwardBufferTarget=a.dash.forwardBufferTargetAuto,this.getCurrentPosition=n,this.isActiveLowLatency=o,this.isLive=!!(l!=null&&l.live),this.baseUrls=(c=l==null?void 0:l.baseUrls)!=null?c:[],this.initData=new Map(i.map(d=>[d.id,null])),this.segments=new Map,this.parsedInitData=new Map,this.representations=new Map(i.map(d=>[d.id,d])),this.kind=e,this.mediaSource=t,this.sourceBuffer=null}switchToWithPreviousAbort(e,t=!1){!J(this.mediaSource,this.sourceBuffer)||e===this.downloadingRepresentationId||e===this.switchingToRepresentationId||(this.switchAbortController.abort(),this.switchAbortController=new ce,(0,R.abortable)(this.switchAbortController.signal,async function*(i,r=!1){this.switchingToRepresentationId=i;let a=this.representations.get(i);(0,R.assertNonNullable)(a,`No such representation ${i}`);let n=this.segments.get(i),o=this.initData.get(i);if((0,R.isNullable)(o)||(0,R.isNullable)(n)?yield this.loadInit(a,"high",!1):o instanceof Promise&&(yield o),n=this.segments.get(i),(0,R.assertNonNullable)(n,"No segments for starting representation"),o=this.initData.get(i),!(!(o instanceof ArrayBuffer)||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(yield this.abort(),yield this.sourceBufferTaskQueue.append(o,this.downloadAbortController.signal),r)this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=i,yield this.dropBuffer();else{let u=this.getCurrentPosition();(0,R.isNonNullable)(u)&&!this.isLive&&(this.bufferLimit=this.forwardBufferTarget,yield this.pruneBuffer(u,1/0,!0)),this.downloadingRepresentationId=i,this.switchingToRepresentationId=void 0}this.maintain()}}.bind(this))(e,t))}warmUpMediaSource(){!(0,R.isNullable)(this.sourceBuffer)&&!this.sourceBuffer.updating&&(this.sourceBuffer.mode="segments")}async abort(){for(let e of this.activeSegments)this.abortSegment(e.segment);return this.activeSegments.clear(),this.downloadAbortController.abort(),this.downloadAbortController=new ce,this.abortBuffer()}maintain(e=this.getCurrentPosition()){if((0,R.isNullable)(e)||(0,R.isNullable)(this.downloadingRepresentationId)||(0,R.isNullable)(this.playingRepresentationId)||(0,R.isNullable)(this.sourceBuffer)||!J(this.mediaSource,this.sourceBuffer)||(0,R.isNonNullable)(this.switchingToRepresentationId)||this.isSeekingLive)return;let t=this.representations.get(this.downloadingRepresentationId),i=this.segments.get(this.downloadingRepresentationId);if((0,R.assertNonNullable)(t,`No such representation ${this.downloadingRepresentationId}`),!i)return;let r=i.find(c=>e>=c.time.from&&e<c.time.to);(0,R.isNonNullable)(r)&&isFinite(r.time.from)&&isFinite(r.time.to)&&this.currentSegmentLength$.next((r==null?void 0:r.time.to)-r.time.from);let a=e,n=100;if(this.playingRepresentationId!==this.downloadingRepresentationId){let c=this.getForwardBufferDuration(e),d=r?r.time.to+n:-1/0;r&&r.time.to-e<this.tuning.dash.maxSegmentDurationLeftToSelectNextSegment&&c>=r.time.to-e+n&&(a=d)}if(isFinite(this.bufferLimit)&&Er(this.sourceBuffer.buffered)>=this.bufferLimit){let c=this.getForwardBufferDuration(e),d=Math.min(this.forwardBufferTarget,this.bufferLimit)*this.tuning.dash.minSafeBufferThreshold;this.pruneBuffer(e,1/0,c<d).catch(f=>{this.handleAsyncError(f,"pruneBuffer")});return}let u=[];if(!this.activeSegments.size&&(u=this.selectForwardBufferSegments(i,t.segmentReference.type,a),u.length)){let c="auto";if(this.tuning.dash.useFetchPriorityHints&&r)if((0,Cn.default)(u,r))c="high";else{let d=(0,Oi.default)(u,0);d&&d.time.from-r.time.to>=this.forwardBufferTarget/2&&(c="low")}this.loadSegments(u,t,c).catch(d=>{this.handleAsyncError(d,"loadSegments")})}(!this.preloadOnly&&!this.allInitsLoaded&&r&&r.status==="fed"&&!u.length&&this.getForwardBufferDuration(e)>3e3||this.isActiveLowLatency())&&this.loadNextInit();let l=(0,Oi.default)(i,-1);!this.isLive&&l&&(this.fullyBuffered$.next(l.time.to-e-this.getForwardBufferDuration(e)<n),this.onLastSegment$.next(e-l.time.from>0))}get lastDataObtainedTimestamp(){return this.lastDataObtainedTimestampMs}searchGaps(e,t){this.gaps=[];let i=0,r=this.isLive?this.liveInitialAdditionalOffset:0;for(let a of e)Math.trunc(a.time.from-i)>0&&this.gaps.push({representation:t.id,from:i,to:a.time.from+r}),i=a.time.to;(0,R.isNonNullable)(t.duration)&&t.duration-i>0&&!this.isLive&&this.gaps.push({representation:t.id,from:i,to:t.duration})}getActualLiveStartingSegments(e){let t=e.segments,i=this.isActiveLowLatency()?this.tuning.dashCmafLive.lowLatency.maxTargetOffset:this.tuning.dashCmafLive.maxActiveLiveOffset,r=[],a=0,n=t.length-1;do r.unshift(t[n]),a+=t[n].time.to-t[n].time.from,n--;while(a<i&&n>=0);return this.liveInitialAdditionalOffset=a-i,this.isActiveLowLatency()?[r[0]]:r}getLiveSegmentsToLoadState(e){let t=(0,Bn.default)(e==null?void 0:e.streams[this.kind],r=>r.representations).find(r=>r.id===this.downloadingRepresentationId);if(!t)return;let i=this.segments.get(t.id);if(i!=null&&i.length)return{from:i[0].time.from,to:i[i.length-1].time.to}}updateLive(e){var i,r,a,n;let t=(i=(0,Bn.default)(e==null?void 0:e.streams[this.kind],o=>o.representations))!=null?i:[];if(![...this.segments.values()].every(o=>!o.length))for(let o of t){if(!o||!st(o.segmentReference))return;let u=o.segmentReference.segments.map(p=>({...p,status:"none",size:void 0})),l=100,c=(r=this.segments.get(o.id))!=null?r:[],d=(n=(a=(0,Oi.default)(c,-1))==null?void 0:a.time.to)!=null?n:0,f=u==null?void 0:u.findIndex(p=>d>=p.time.from+l&&d<=p.time.to+l);if(f===-1){this.liveUpdateSegmentIndex=0;let p=this.getActualLiveStartingSegments(o.segmentReference);this.segments.set(o.id,p)}else{let p=u.slice(f+1);this.segments.set(o.id,[...c,...p])}}}proceedLowLatencyLive(){let e=this.downloadingRepresentationId;(0,R.assertNonNullable)(e);let t=this.segments.get(e);if(t!=null&&t.length){let i=t[t.length-1];this.updateLowLatencyLiveIfNeeded(i)}}calculateDurationFromSegments(){var t;if(!this.playingRepresentationId)return 0;let e=this.segments.get(this.playingRepresentationId);return(e?(t=(0,Oi.default)(e,-1))==null?void 0:t.time.to:0)||0}updateLowLatencyLiveIfNeeded(e){var i;let t=0;for(let r of this.representations.values()){let a=r.segmentReference;if(!st(a))return;let n=(i=this.segments.get(r.id))!=null?i:[],o=n.find(l=>Math.floor(l.time.from)===Math.floor(e.time.from));if(o&&!isFinite(o.time.to)&&(o.time.to=e.time.to,t=o.time.to-o.time.from),!!!n.find(l=>Math.floor(l.time.from)===Math.floor(e.time.to))&&this.isActiveLowLatency()){let l=Math.round(e.time.to*a.timescale/1e3).toString(10),c=It(a.segmentTemplateUrl,{segmentTime:l});n.push({status:"none",time:{from:e.time.to,to:1/0},url:c})}}this.currentLowLatencySegmentLength$.next(t)}findSegmentStartTime(e){var a,n,o;let t=(n=(a=this.switchingToRepresentationId)!=null?a:this.downloadingRepresentationId)!=null?n:this.playingRepresentationId;if(!t)return;let i=this.segments.get(t);if(!i)return;let r=i.find(u=>u.time.from<=e&&u.time.to>=e);return(o=r==null?void 0:r.time.from)!=null?o:void 0}setTarget(e){this.forwardBufferTarget=e}setPreloadOnly(e){this.preloadOnly=e}destroy(){var e;if(this.initData.clear(),this.segments.clear(),this.parsedInitData.clear(),this.representations.clear(),(e=this.sourceBufferTaskQueue)==null||e.destroy(),this.gapDetectionIdleCallback&&Mt&&Mt(this.gapDetectionIdleCallback),this.initLoadIdleCallback&&Mt&&Mt(this.initLoadIdleCallback),this.subscription.unsubscribe(),this.sourceBuffer)try{this.mediaSource.removeSourceBuffer(this.sourceBuffer)}catch(t){if(!(t instanceof DOMException&&t.name==="NotFoundError"))throw t}this.sourceBuffer=null,this.downloadAbortController.abort(),this.switchAbortController.abort(),this.destroyAbortController.abort(),window.clearTimeout(this.loadByteRangeSegmentsTimeoutId)}selectForwardBufferSegments(e,t,i){return this.isLive?this.selectForwardBufferSegmentsLive(e,i):this.selectForwardBufferSegmentsRecord(e,t,i)}selectForwardBufferSegmentsLive(e,t){let i=e.findIndex(r=>t>=r.time.from&&t<r.time.to);return this.playingRepresentationId!==this.downloadingRepresentationId&&(this.liveUpdateSegmentIndex=i),this.liveUpdateSegmentIndex<e.length?e.slice(this.liveUpdateSegmentIndex++):[]}selectForwardBufferSegmentsRecord(e,t,i){let r=this.getForwardBufferDuration(i),a=e.findIndex(({status:f,time:{from:p,to:h}},b)=>{let S=p<=i&&h>=i,g=p>i||S||b===0&&i===0,I=Math.min(this.forwardBufferTarget,this.bufferLimit),w=this.preloadOnly&&p<=i+I||r<I&&h-p>=I||h<=i+I;return(f==="none"||f==="partially_ejected"&&g&&w&&this.sourceBuffer&&J(this.mediaSource,this.sourceBuffer)&&!(_e(this.sourceBuffer.buffered,p)&&_e(this.sourceBuffer.buffered,h)))&&g&&w});if(a===-1)return[];if(t!=="byteRange")return e.slice(a,a+1);let n=e,o=0,u=0,l=[],c=this.preloadOnly?0:this.tuning.dash.segmentRequestSize,d=this.preloadOnly?this.forwardBufferTarget:0;for(let f=a;f<n.length&&(o<=c||u<=d);f++){let p=n[f];if(o+=p.byte.to+1-p.byte.from,u+=p.time.to+1-p.time.from,p.status==="none"||p.status==="partially_ejected")l.push(p);else break}return l}async loadSegments(e,t,i="auto"){st(t.segmentReference)?await this.loadTemplateSegment(e[0],t,i):await this.loadByteRangeSegments(e,t,i)}async loadTemplateSegment(e,t,i="auto"){e.status="downloading";let r={segment:e,loadedBytes:0,feedingBytes:0,fedBytes:0,representationId:t.id};this.activeSegments.add(r);let{range:a,url:n,signal:o,onProgress:u,onProgressTasks:l}=this.prepareTemplateFetchSegmentParams(e,t);this.failedDownloads&&o&&(await(0,R.abortable)(o,async function*(){let c=(0,R.getExponentialDelay)(this.failedDownloads,this.tuning.downloadBackoff);yield new Promise(d=>setTimeout(d,c))}.bind(this))(),o.aborted&&this.abortActiveSegments([e]));try{let c=await this.fetcher.fetch(n,{range:a,signal:o,onProgress:u,priority:i,isLowLatency:this.isActiveLowLatency(),bufferOptimisation:this.tuning.dash.fetcherBufferOptimisation});if(this.lastDataObtainedTimestampMs=(0,R.now)(),!c)return;let d=new DataView(c),f=Dt(t.mime);if(!isFinite(r.segment.time.to)){let b=t.segmentReference.timescale;r.segment.time.to=f.getChunkEndTime(d,b)}u&&r.feedingBytes&&l?await Promise.all(l):await this.sourceBufferTaskQueue.append(d,o);let{serverDataReceivedTimestamp:p,serverDataPreparedTime:h}=f.getServerLatencyTimestamps(d);p&&h&&this.currentLiveSegmentServerLatency$.next(h-p),r.segment.status="downloaded",this.onSegmentFullyAppended(r,t.id),this.failedDownloads=0}catch(c){this.abortActiveSegments([e]),Ct(c)||(this.failedDownloads++,this.updateRepresentationsBaseUrlIfNeeded())}}updateRepresentationsBaseUrlIfNeeded(){if(!this.tuning.dash.enableBaseUrlSupport||!this.baseUrls.length||this.failedDownloads<=this.tuning.dash.maxSegmentRetryCount)return;this.baseUrlsIndex=(this.baseUrlsIndex+1)%this.baseUrls.length;let e=this.baseUrls[this.baseUrlsIndex];for(let t of this.representations.values())st(t.segmentReference)?t.segmentReference.baseUrl=e:t.segmentReference.url=e}async loadByteRangeSegments(e,t,i="auto"){if(!e.length)return;for(let u of e)u.status="downloading",this.activeSegments.add({segment:u,loadedBytes:0,feedingBytes:0,fedBytes:0,representationId:t.id});let{range:r,url:a,signal:n,onProgress:o}=this.prepareByteRangeFetchSegmentParams(e,t);this.failedDownloads&&n&&(await(0,R.abortable)(n,async function*(){let u=(0,R.getExponentialDelay)(this.failedDownloads,this.tuning.downloadBackoff);yield new Promise(l=>{this.loadByteRangeSegmentsTimeoutId=window.setTimeout(l,u),(0,R.fromEvent)(window,"online").pipe((0,R.once)()).subscribe(()=>{l(),window.clearTimeout(this.loadByteRangeSegmentsTimeoutId)})})}.bind(this))(),n.aborted&&this.abortActiveSegments(e));try{await this.fetcher.fetch(a,{range:r,onProgress:o,signal:n,priority:i,bufferOptimisation:this.tuning.dash.fetcherBufferOptimisation}),this.lastDataObtainedTimestampMs=(0,R.now)(),this.failedDownloads=0}catch(u){this.abortActiveSegments(e),Ct(u)||(this.failedDownloads++,this.updateRepresentationsBaseUrlIfNeeded())}}prepareByteRangeFetchSegmentParams(e,t){if(st(t.segmentReference))throw new Error("Representation is not byte range type");let i=t.segmentReference.url,r={from:(0,Oi.default)(e,0).byte.from,to:(0,Oi.default)(e,-1).byte.to},{signal:a}=this.downloadAbortController;return{url:i,range:r,signal:a,onProgress:async(o,u)=>{if(!a.aborted)try{this.lastDataObtainedTimestampMs=(0,R.now)(),await this.onSomeByteRangesDataLoaded({dataView:o,loaded:u,signal:a,onSegmentAppendFailed:()=>this.abort(),globalFrom:r?r.from:0,representationId:t.id})}catch(l){this.error$.next({id:"SegmentFeeding",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when feeding segments",thrown:l})}}}}prepareTemplateFetchSegmentParams(e,t){if(!st(t.segmentReference))throw new Error("Representation is not template type");let i=new URL(e.url,t.segmentReference.baseUrl);this.isActiveLowLatency()&&i.searchParams.set("low-latency","yes");let r=i.toString(),{signal:a}=this.downloadAbortController,n=[],u=this.isActiveLowLatency()||this.tuning.dash.enableSubSegmentBufferFeeding&&this.liveUpdateSegmentIndex<3?(l,c)=>{if(!a.aborted)try{this.lastDataObtainedTimestampMs=(0,R.now)();let d=this.onSomeTemplateDataLoaded({dataView:l,loaded:c,signal:a,onSegmentAppendFailed:()=>this.abort(),representationId:t.id});n.push(d)}catch(d){this.error$.next({id:"SegmentFeeding",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when feeding segments",thrown:d})}}:void 0;return{url:r,signal:a,onProgress:u,onProgressTasks:n}}abortActiveSegments(e){for(let t of this.activeSegments)(0,Cn.default)(e,t.segment)&&this.abortSegment(t.segment)}async onSomeTemplateDataLoaded({dataView:e,representationId:t,loaded:i,onSegmentAppendFailed:r,signal:a}){if(!this.activeSegments.size||!J(this.mediaSource,this.sourceBuffer))return;let n=this.representations.get(t);if(n)for(let o of this.activeSegments){let{segment:u}=o;if(o.representationId===t){if(a.aborted){r();continue}if(o.loadedBytes=i,o.loadedBytes>o.feedingBytes){let l=new DataView(e.buffer,e.byteOffset+o.feedingBytes,o.loadedBytes-o.feedingBytes),c=Dt(n.mime).parseFeedableSegmentChunk(l,this.isLive);c!=null&&c.byteLength&&(u.status="partially_fed",o.feedingBytes+=c.byteLength,await this.sourceBufferTaskQueue.append(c),o.fedBytes+=c.byteLength)}}}}async onSomeByteRangesDataLoaded({dataView:e,representationId:t,globalFrom:i,loaded:r,signal:a,onSegmentAppendFailed:n}){if(!this.activeSegments.size||!J(this.mediaSource,this.sourceBuffer))return;let o=this.representations.get(t);if(o)for(let u of this.activeSegments){let{segment:l}=u;if(u.representationId!==t)continue;if(a.aborted){await n();continue}let c=l.byte.from-i,d=l.byte.to-i,f=d-c+1,p=c<r,h=d<=r;if(!p)continue;let b=Dt(o.mime);if(l.status==="downloading"&&h){l.status="downloaded";let S=new DataView(e.buffer,e.byteOffset+c,f);await this.sourceBufferTaskQueue.append(S,a)&&!a.aborted?this.onSegmentFullyAppended(u,t):await n()}else if(this.tuning.dash.enableSubSegmentBufferFeeding&&(l.status==="downloading"||l.status==="partially_fed")&&(u.loadedBytes=Math.min(f,r-c),u.loadedBytes>u.feedingBytes)){let S=new DataView(e.buffer,e.byteOffset+c+u.feedingBytes,u.loadedBytes-u.feedingBytes),g=u.loadedBytes===f?S:b.parseFeedableSegmentChunk(S);g!=null&&g.byteLength&&(l.status="partially_fed",u.feedingBytes+=g.byteLength,await this.sourceBufferTaskQueue.append(g,a)&&!a.aborted?(u.fedBytes+=g.byteLength,u.fedBytes===f&&this.onSegmentFullyAppended(u,t)):await n())}}}onSegmentFullyAppended(e,t){var i;if(!((0,R.isNullable)(this.sourceBuffer)||!J(this.mediaSource,this.sourceBuffer))){!this.isLive&&z.browser.isSafari&&this.tuning.useSafariEndlessRequestBugfix&&(_e(this.sourceBuffer.buffered,e.segment.time.from,100)&&_e(this.sourceBuffer.buffered,e.segment.time.to,100)||this.error$.next({id:"EmptyAppendBuffer",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Browser stuck on empty result of adding segment to source buffer"})),this.playingRepresentationId=t,this.playingRepresentation$.next(this.playingRepresentationId),this.playingRepresentationInit$.next(this.parsedInitData.get(this.playingRepresentationId)),e.segment.status="fed",Xl(e.segment)&&(e.segment.size=e.fedBytes);for(let r of this.representations.values())if(r.id!==t)for(let a of(i=this.segments.get(r.id))!=null?i:[])a.status==="fed"&&Math.round(a.time.from)===Math.round(e.segment.time.from)&&Math.round(a.time.to)===Math.round(e.segment.time.to)&&(a.status="none");this.updateLowLatencyLiveIfNeeded(e.segment),this.activeSegments.delete(e),this.detectGapsWhenIdle(t,[e.segment])}}abortSegment(e){e.status==="partially_fed"?e.status="partially_ejected":e.status!=="partially_ejected"&&(e.status="none");for(let t of this.activeSegments.values())if(t.segment===e){this.activeSegments.delete(t);break}}loadNextInit(){if(this.allInitsLoaded||this.initLoadIdleCallback)return;let e=null,t=!1;for(let[r,a]of this.initData.entries()){let n=a instanceof Promise;t||(t=n),a===null&&(e=r)}if(!e){this.allInitsLoaded=!0;return}if(t)return;let i=this.representations.get(e);i&&(this.initLoadIdleCallback=Ir(()=>(0,qS.default)(this.loadInit(i,"low",!1),()=>this.initLoadIdleCallback=null)))}async loadInit(e,t="auto",i=!1){let r=this.tuning.dash.useFetchPriorityHints?t:"auto",n=(!i&&this.failedDownloads>0?(0,R.abortable)(this.destroyAbortController.signal,async function*(){let o=(0,R.getExponentialDelay)(this.failedDownloads,this.tuning.downloadBackoff);yield new Promise(u=>setTimeout(u,o))}.bind(this))():Promise.resolve()).then(()=>this.fetcher.fetchRepresentation(e.segmentReference,Dt(e.mime),r)).then(async o=>{if(!o)return;let{init:u,dataView:l,segments:c}=o,d=l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength);this.initData.set(e.id,d);let f=c;this.isLive&&st(e.segmentReference)&&(f=this.getActualLiveStartingSegments(e.segmentReference)),(!this.isLive||!this.segments.has(e.id))&&this.segments.set(e.id,f),u&&this.parsedInitData.set(e.id,u)}).then(()=>this.failedDownloads=0,o=>{this.initData.set(e.id,null),i&&this.error$.next({id:"LoadInits",category:R.ErrorCategory.WTF,message:"loadInit threw",thrown:o})});return this.initData.set(e.id,n),n}async dropBuffer(){for(let e of this.segments.values())for(let t of e)t.status="none";await this.pruneBuffer(0,1/0,!0)}async pruneBuffer(e,t,i=!1){if(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)||!this.playingRepresentationId||(0,R.isNullable)(e))return!1;let r=[],a=0,n=u=>{u.sort((c,d)=>c.from-d.from);let l=[u[0]];for(let c=1;c<u.length;c++){let{from:d,to:f}=u[c],p=l[l.length-1];p.to>=d?p.to=Math.max(p.to,f):l.push(u[c])}return l},o=u=>{var c;if(a>=t)return r;r.push({...u.time}),r=n(r);let l=Xl(u)?(c=u.size)!=null?c:0:u.byte.to-u.byte.from;a+=l};for(let u of this.segments.values())for(let l of u){let c=l.time.to<=e-this.tuning.dash.bufferPruningSafeZone,d=l.time.from>=e+Math.min(this.forwardBufferTarget,this.bufferLimit);(c||d)&&l.status==="fed"&&o(l)}for(let u=0;u<this.sourceBuffer.buffered.length;u++){let l=this.sourceBuffer.buffered.start(u)*1e3,c=this.sourceBuffer.buffered.end(u)*1e3,d=0;for(let f of this.segments.values())for(let p of f)(0,Cn.default)(["none","partially_ejected"],p.status)&&Math.round(p.time.from)<=Math.round(l)&&Math.round(p.time.to)>=Math.round(c)&&d++;if(d===this.segments.size){let f={time:{from:l,to:c},url:"",status:"none"};o(f)}}if(r.length&&i){let u=Math.min(this.forwardBufferTarget,this.bufferLimit)*this.tuning.dash.minSafeBufferThreshold;for(let l of this.segments.values())for(let c of l)c.time.from>=e+u&&c.status==="fed"&&o(c)}return r.length?(await Promise.all(r.map(l=>this.sourceBufferTaskQueue.remove(l.from,l.to)))).reduce((l,c)=>l||c,!1):!1}async abortBuffer(){if(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))return!1;let e=this.playingRepresentationId&&this.initData.get(this.playingRepresentationId),t=e instanceof ArrayBuffer?e:void 0;return this.sourceBufferTaskQueue.abort(t)}getDebugBufferState(){if(!(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)||!this.sourceBuffer.buffered.length))return{from:this.sourceBuffer.buffered.start(0),to:this.sourceBuffer.buffered.end(this.sourceBuffer.buffered.length-1)}}getForwardBufferDuration(e=this.getCurrentPosition()){return!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)||!this.sourceBuffer.buffered.length||(0,R.isNullable)(e)?0:$e(this.sourceBuffer.buffered,e)}detectGaps(e,t){if(!(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(this.tuning.useRefactoredSearchGap)for(let i=0;i<this.sourceBuffer.buffered.length;i++)this.gaps=this.gaps.filter(r=>this.sourceBuffer&&(Math.round(r.from)<Math.round(this.sourceBuffer.buffered.start(i)*1e3)||Math.round(r.to)>Math.round(this.sourceBuffer.buffered.end(i)*1e3)));for(let i of t){let r={representation:e,from:i.time.from,to:i.time.to};for(let a=0;a<this.sourceBuffer.buffered.length;a++){let n=this.sourceBuffer.buffered.start(a)*1e3,o=this.sourceBuffer.buffered.end(a)*1e3;if(!(o<=i.time.from||n>=i.time.to)){if(n<=i.time.from&&o>=i.time.to){r=void 0;break}o>i.time.from&&o<i.time.to&&(r.from=o),n<i.time.to&&n>i.time.from&&(r.to=n)}}r&&r.to-r.from>1&&!this.gaps.some(a=>r&&a.from===r.from&&a.to===r.to)&&this.gaps.push(r)}}}detectGapsWhenIdle(e,t){if(!(this.gapDetectionIdleCallback||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(!this.tuning.useRefactoredSearchGap)for(let i=0;i<this.sourceBuffer.buffered.length;i++)this.gaps=this.gaps.filter(r=>this.sourceBuffer&&(Math.round(r.from)<Math.round(this.sourceBuffer.buffered.start(i)*1e3)||Math.round(r.to)>Math.round(this.sourceBuffer.buffered.end(i)*1e3)));this.gapDetectionIdleCallback=Ir(()=>{try{this.detectGaps(e,t)}catch(i){this.error$.next({id:"GapDetection",category:R.ErrorCategory.WTF,message:"detectGaps threw",thrown:i})}finally{this.gapDetectionIdleCallback=null}})}}checkEjectedSegments(){if((0,R.isNullable)(this.sourceBuffer)||!J(this.mediaSource,this.sourceBuffer)||(0,R.isNullable)(this.playingRepresentationId))return;let e=[];for(let i=0;i<this.sourceBuffer.buffered.length;i++){let r=Math.floor(this.sourceBuffer.buffered.start(i)*1e3),a=Math.ceil(this.sourceBuffer.buffered.end(i)*1e3);e.push({from:r,to:a})}let t=100;for(let i of this.segments.values())for(let r of i){let{status:a}=r;if(a!=="fed"&&a!=="partially_ejected")continue;let n=Math.floor(r.time.from),o=Math.ceil(r.time.to),u=e.some(c=>c.from-t<=n&&c.to+t>=o),l=e.filter(c=>n>=c.from&&n<c.to-t||o>c.from+t&&o<=c.to);u||(l.length===1?r.status="partially_ejected":this.gaps.some(c=>c.from===r.time.from||c.to===r.time.to)?r.status="partially_ejected":r.status="none")}}handleAsyncError(e,t){this.error$.next({id:t,category:R.ErrorCategory.VIDEO_PIPELINE,thrown:e,message:"Something went wrong"})}};var pi=s=>{let e=new URL(s);return e.searchParams.set("quic","1"),e.toString()};var Vn=s=>{var a;let e=s.get("X-Delivery-Type"),t=s.get("X-Reused"),i=e===null?"http1":e!=null?e:void 0,r=t===null?void 0:(a={1:!0,0:!1}[t])!=null?a:void 0;return{type:i,reused:r}};var Y=require("@vkontakte/videoplayer-shared/es2018");var _n=s=>{let e=new URL(s);return e.searchParams.set("enable-subtitles","yes"),e.toString()};var Fn=class{constructor({throughputEstimator:e,requestQuic:t,tracer:i,compatibilityMode:r=!1,useEnableSubtitlesParam:a=!1}){this.manifestRequested=new Y.Subject;this.manifestReceived=new Y.Subject;this.firstBytesRequested=new Y.Subject;this.firstBytesReceived=new Y.Subject;this.lastConnectionType$=new Y.ValueSubject(void 0);this.lastConnectionReused$=new Y.ValueSubject(void 0);this.lastRequestFirstBytes$=new Y.ValueSubject(void 0);this.recoverableError$=new Y.Subject;this.error$=new Y.Subject;this.abortAllController=new ce;this.subscription=new Y.Subscription;this.fetchManifest=(0,Y.abortable)(this.abortAllController.signal,async function*(e){let t=this.tracer.createComponentTracer("FetchManifest"),i=e;this.requestQuic&&(i=pi(i)),!this.compatibilityMode&&this.useEnableSubtitlesParam&&(i=_n(i)),this.manifestRequested.next();let r=yield this.doFetch(i,{signal:this.abortAllController.signal}).catch(On);return r?(t.log("success",(0,Y.flattenObject)({url:i,message:"Request successfully executed"})),t.end(),this.manifestReceived.next(),this.onHeadersReceived(r.headers),r.text()):(t.error("error",(0,Y.flattenObject)({url:i,message:"No data in request manifest"})),t.end(),null)}.bind(this));this.fetch=(0,Y.abortable)(this.abortAllController.signal,async function*(e,{rangeMethod:t=this.compatibilityMode?0:1,range:i,onProgress:r,priority:a="auto",signal:n,measureThroughput:o=!0,isLowLatency:u=!1,bufferOptimisation:l=!1}={}){var W,ue,le;let c=e,d=new Headers,f=this.tracer.createComponentTracer("Fetch");if(i)switch(t){case 0:{d.append("Range",`bytes=${i.from}-${i.to}`);break}case 1:{let A=new URL(c,location.href);A.searchParams.append("bytes",`${i.from}-${i.to}`),c=A.toString();break}default:(0,Y.assertNever)(t)}this.requestQuic&&(c=pi(c));let p=this.abortAllController.signal,h;if(n){let A=new ce;if(h=(0,Y.merge)((0,Y.fromEvent)(this.abortAllController.signal,"abort"),(0,Y.fromEvent)(n,"abort")).subscribe(()=>{try{A.abort()}catch(V){On(V)}}),this.subscription.add(h),this.abortAllController.signal.aborted||n.aborted)try{A.abort()}catch(V){On(V)}p=A.signal}let b=0,S=(0,Y.now)();f.log("startRequest",(0,Y.flattenObject)({url:c,priority:a,rangeMethod:t,range:i,isLowLatency:u,requestStartedAt:S})),this.firstBytesRequested.next();let g=yield this.doFetch(c,{priority:a,headers:d,signal:p}),I=(0,Y.now)();if(!g)return f.error("error",{message:"No response in request"}),f.end(),h==null||h.unsubscribe(),null;if((W=this.throughputEstimator)==null||W.addRawRtt(I-S),!g.ok||!g.body){h==null||h.unsubscribe();let A=`Fetch error ${g.status}: ${g.statusText}`;return f.error("error",{message:A}),f.end(),Promise.reject(new Error(`Fetch error ${g.status}: ${g.statusText}`))}if(this.onHeadersReceived(g.headers),!r&&!o){h==null||h.unsubscribe();let A=(0,Y.now)(),V={requestStartedAt:S,requestEndedAt:A,duration:A-S};return f.log("endRequest",(0,Y.flattenObject)(V)),f.end(),g.arrayBuffer()}let w=g.body;if(o){let A;[w,A]=g.body.tee(),(ue=this.throughputEstimator)==null||ue.trackStream(A,u)}let E=w.getReader(),P,_=parseInt((le=g.headers.get("content-length"))!=null?le:"",10);Number.isFinite(_)&&(P=_),!P&&i&&(P=i.to-i.from+1);let N=P?new Uint8Array(P):new Uint8Array(0),F=!1,C=A=>{h==null||h.unsubscribe(),F=!0,On(A)},B=(0,Y.abortable)(p,async function*({done:A,value:V}){if(b===0&&(this.lastRequestFirstBytes$.next((0,Y.now)()-S),this.firstBytesReceived.next()),p.aborted){h==null||h.unsubscribe();return}if(!A&&V){if(l&&P)N.set(V,b),b+=V.byteLength;else{let $=new Uint8Array(N.length+V.length);$.set(N),$.set(V,N.length),N=$,b+=V.byteLength}r==null||r(new DataView(N.buffer),b),yield E==null?void 0:E.read().then(B,C)}}.bind(this));yield E==null?void 0:E.read().then(B,C),h==null||h.unsubscribe();let H=(0,Y.now)(),q={failed:F,requestStartedAt:S,requestEndedAt:H,duration:H-S};return F?(f.error("endRequest",(0,Y.flattenObject)(q)),f.end(),null):(f.log("endRequest",(0,Y.flattenObject)(q)),f.end(),N.buffer)}.bind(this));this.fetchByteRangeRepresentation=(0,Y.abortable)(this.abortAllController.signal,async function*(e,t,i){var g;if(e.type!=="byteRange")return null;let{from:r,to:a}=e.initRange,n=r,o=a,u=!1,l,c;e.indexRange&&(l=e.indexRange.from,c=e.indexRange.to,u=a+1===l,u&&(n=Math.min(l,r),o=Math.max(c,a))),n=Math.min(n,0);let d=yield this.fetch(e.url,{range:{from:n,to:o},priority:i,measureThroughput:!1});if(!d)return null;let f=new DataView(d,r-n,a-n+1);if(!t.validateData(f))throw new Error("Invalid media file");let p=t.parseInit(f),h=(g=e.indexRange)!=null?g:t.getIndexRange(p);if(!h)throw new ReferenceError("No way to load representation index");let b;if(u)b=new DataView(d,h.from-n,h.to-h.from+1);else{let I=yield this.fetch(e.url,{range:h,priority:i,measureThroughput:!1});if(!I)return null;b=new DataView(I)}let S=t.parseSegments(b,p,h);return{init:p,dataView:new DataView(d),segments:S}}.bind(this));this.fetchTemplateRepresentation=(0,Y.abortable)(this.abortAllController.signal,async function*(e,t){if(e.type!=="template")return null;let i=new URL(e.initUrl,e.baseUrl).toString(),r=yield this.fetch(i,{priority:t,measureThroughput:!1});return r?{init:null,segments:e.segments.map(n=>({...n,status:"none",size:void 0})),dataView:new DataView(r)}:null}.bind(this));this.throughputEstimator=e,this.requestQuic=t,this.compatibilityMode=r,this.tracer=i.createComponentTracer("Fetcher"),this.useEnableSubtitlesParam=a}onHeadersReceived(e){let{type:t,reused:i}=Vn(e);this.lastConnectionType$.next(t),this.lastConnectionReused$.next(i)}async fetchRepresentation(e,t,i="auto"){var a,n;let{type:r}=e;switch(r){case"byteRange":return(a=await this.fetchByteRangeRepresentation(e,t,i))!=null?a:null;case"template":return(n=await this.fetchTemplateRepresentation(e,i))!=null?n:null;default:(0,Y.assertNever)(r)}}destroy(){this.abortAllController.abort(),this.subscription.unsubscribe(),this.tracer.end()}async doFetch(e,t){let i=await dt(e,t);if(i.ok)return i;let r=await i.text(),a=parseInt(r);if(!isNaN(a))switch(a){case 1:this.recoverableError$.next({id:"VideoDataLinkExpiredError",message:"Video data links have expired",category:Y.ErrorCategory.FATAL});break;case 8:this.recoverableError$.next({id:"VideoDataLinkBlockedForFloodError",message:"Url blocked for flood",category:Y.ErrorCategory.FATAL});break;case 18:this.recoverableError$.next({id:"VideoDataLinkIllegalIpChangeError",message:"Client IP has changed",category:Y.ErrorCategory.FATAL});break;case 21:this.recoverableError$.next({id:"VideoDataLinkIllegalHostChangeError",message:"Request HOST has changed",category:Y.ErrorCategory.FATAL});break;default:this.error$.next({id:"GeneralVideoDataFetchError",message:`Generic video data fetch error (${a})`,category:Y.ErrorCategory.FATAL})}}},On=s=>{if(!Ct(s))throw s};var Qt=(s,e,t)=>t*e+(1-t)*s,Zl=(s,e)=>s.reduce((t,i)=>t+i,0)/e,US=(s,e,t,i)=>{let r=0,a=t,n=Zl(s,e),o=e<i?e:i;for(let u=0;u<o;u++)s[a]>n?r++:r--,a=(s.length+a-1)%s.length;return Math.abs(r)===o};var Zs=require("@vkontakte/videoplayer-shared/es2018"),hi=class{constructor(e){this.prevReported=void 0;this.pastMeasures=[];this.takenMeasures=0;this.measuresCursor=0;var i;this.params=e,this.pastMeasures=Array(e.deviationDepth),this.smoothed=this.prevReported=e.initial,this.smoothed$=new Zs.ValueSubject(e.initial),this.debounced$=new Zs.ValueSubject(e.initial);let t=(i=e.label)!=null?i:"value"+Math.random().toString(16).substring(2,6);this.rawSeries$=new qe(`raw_${t}`),this.smoothedSeries$=new qe(`smoothed_${t}`),this.reportedSeries$=new qe(`reported_${t}`),this.rawSeries$.next(e.initial),this.smoothedSeries$.next(e.initial),this.reportedSeries$.next(e.initial)}next(e){let t=0,i=0;for(let o=0;o<this.pastMeasures.length;o++)this.pastMeasures[o]!==void 0&&(t+=(this.pastMeasures[o]-this.smoothed)**2,i++);this.takenMeasures=i,t/=i;let r=Math.sqrt(t),a=this.smoothed+this.params.deviationFactor*r,n=this.smoothed-this.params.deviationFactor*r;this.pastMeasures[this.measuresCursor]=e,this.measuresCursor=(this.measuresCursor+1)%this.pastMeasures.length,this.rawSeries$.next(e),this.updateSmoothedValue(e),this.smoothed$.next(this.smoothed),this.smoothedSeries$.next(this.smoothed),!(this.smoothed>a||this.smoothed<n)&&((0,Zs.isNullable)(this.prevReported)||Math.abs(this.smoothed-this.prevReported)/this.prevReported>=this.params.changeThreshold)&&(this.prevReported=this.smoothed,this.debounced$.next(this.smoothed),this.reportedSeries$.next(this.smoothed))}};var Nn=class extends hi{constructor(e){super(e),this.slow=this.fast=e.initial}updateSmoothedValue(e){this.slow=Qt(this.slow,e,this.params.emaAlphaSlow),this.fast=Qt(this.fast,e,this.params.emaAlphaFast);let t=this.params.fastDirection>0?Math.max:Math.min;this.smoothed=t(this.slow,this.fast)}};var qn=class extends hi{constructor(e){super(e),this.emaSmoothed=e.initial}updateSmoothedValue(e){let t=Zl(this.pastMeasures,this.takenMeasures);this.emaSmoothed=Qt(this.emaSmoothed,e,this.params.emaAlpha);let i=US(this.pastMeasures,this.takenMeasures,this.measuresCursor-1,this.params.basisTrendChangeCount);this.smoothed=i?this.emaSmoothed:t}};var Un=class extends hi{constructor(t){super(t);this.furtherValues=[];this.currentTopExtremumValue=0;this.extremumInterval=t.extremumInterval}next(t){this.currentTopExtremumValue<=t?(this.currentTopExtremumValue=t,this.furtherValues=[]):this.furtherValues.length===this.extremumInterval?(super.next(this.currentTopExtremumValue),this.currentTopExtremumValue=t,this.furtherValues=[]):this.furtherValues.push(t)}updateSmoothedValue(t){this.smoothed=this.smoothed?Qt(this.smoothed,t,this.params.emaAlpha):t}};var Wt=class{static getSmoothedValue(e,t,i){return i.type==="TwoEma"?new Nn({initial:e,emaAlphaSlow:i.emaAlphaSlow,emaAlphaFast:i.emaAlphaFast,changeThreshold:i.changeThreshold,fastDirection:t,deviationDepth:i.deviationDepth,deviationFactor:i.deviationFactor,label:"throughput"}):new qn({initial:e,emaAlpha:i.emaAlpha,basisTrendChangeCount:i.basisTrendChangeCount,changeThreshold:i.changeThreshold,deviationDepth:i.deviationDepth,deviationFactor:i.deviationFactor,label:"throughput"})}static getLiveBufferSmoothedValue(e,t){return new Un({initial:e,label:"liveEdgeDelay",...t})}};var Rr=(s,e)=>{s&&s.playbackRate!==e&&(s.playbackRate=e)};var Hn=require("@vkontakte/videoplayer-shared/es2018");var ea=class s{constructor(e,t){this.currentRepresentation$=new Hn.ValueSubject(null);this.maxRepresentations=4;this.representationsCursor=0;this.representations=[];this.currentSegment=null;this.getCurrentPosition=t.getCurrentPosition,this.processStreams(e)}updateLive(e){this.processStreams(e==null?void 0:e.streams.text)}seekLive(e){this.processStreams(e)}maintain(e=this.getCurrentPosition()){var t;if(!(0,Hn.isNullable)(e))for(let i of this.representations)for(let r of i){let a=r.segmentReference,n=a.segments.length,o=a.segments[0].time.from,u=a.segments[n-1].time.to;if(e<o||e>u)continue;let l=a.segments.find(c=>c.time.from<=e&&c.time.to>=e);!l||((t=this.currentSegment)==null?void 0:t.time.from)===l.time.from&&this.currentSegment.time.to===l.time.to||(this.currentSegment=l,this.currentRepresentation$.next({...r,label:"Live Text",language:"ru",isAuto:!0,url:new URL(l.url,a.baseUrl).toString()}))}}destroy(){this.currentRepresentation$.next(null),this.currentSegment=null,this.representations=[]}processStreams(e){for(let t of e!=null?e:[]){let i=s.filterRepresentations(t.representations);if(i){this.representations[this.representationsCursor]=i,this.representationsCursor=(this.representationsCursor+1)%this.maxRepresentations;break}}}static isSupported(e){return!!(e!=null&&e.some(t=>s.filterRepresentations(t.representations)))}static filterRepresentations(e){return e==null?void 0:e.filter(t=>t.kind==="text"&&"segmentReference"in t&&st(t.segmentReference))}};var Qn=G(yt(),1),ec=G(Ne(),1),ta=require("@vkontakte/videoplayer-shared/es2018");var jn=s=>{let{webmDecodingInfo:e}=z.video,t="DASH_WEBM",i="DASH_WEBM_AV1";switch(s){case"vp9":return[t,i];case"av1":return[i,t];case"none":return[];case"smooth":return e?e[i].smooth?[i,t]:e[t].smooth?[t,i]:[i,t]:[t,i];case"power_efficient":return e?e[i].powerEfficient?[i,t]:e[t].powerEfficient?[t,i]:[i,t]:[t,i];default:(0,ta.assertNever)(s)}return[t,i]},HS=({webmCodec:s,androidPreferredFormat:e,iosPreferredFormat:t,preferMultiStream:i})=>{let r=[...i?["DASH_STREAMS"]:[],...jn(s),"DASH_SEP","DASH_ONDEMAND",...i?[]:["DASH_STREAMS"]],a=[...i?["DASH_STREAMS"]:[],"DASH_SEP","DASH_ONDEMAND",...i?[]:["DASH_STREAMS"]];if(z.device.isAndroid)switch(e){case"mpeg":return["MPEG",...r,"HLS","HLS_ONDEMAND"];case"hls":return["HLS","HLS_ONDEMAND",...r,"MPEG"];case"dash":return[...r,"HLS","HLS_ONDEMAND","MPEG"];case"dash_any_mpeg":return[...a,"MPEG",...jn(s),"HLS","HLS_ONDEMAND"];case"dash_any_webm":return[...jn(s),"MPEG",...a,"HLS","HLS_ONDEMAND"];case"dash_sep":return["DASH_SEP","MPEG",...jn(s),...a,"HLS","HLS_ONDEMAND"];default:(0,ta.assertNever)(e)}if(z.video.nativeHlsSupported)switch(t){case"hls":return[...r,"HLS","HLS_FMP4","HLS_ONDEMAND","MPEG"];case"hls_fmp4":return[...r,"HLS_FMP4","HLS","HLS_ONDEMAND","MPEG"];default:(0,ta.assertNever)(t)}return[...r,"HLS","HLS_ONDEMAND","MPEG"]},jS=({androidPreferredFormat:s,preferCMAF:e,preferWebRTC:t})=>{let i=e?["DASH_LIVE_CMAF","DASH_LIVE"]:["DASH_LIVE","DASH_LIVE_CMAF"],r=e?["HLS_LIVE_CMAF","HLS_LIVE"]:["HLS_LIVE","HLS_LIVE_CMAF"],a=[...i,...r],n=[...r,...i],o,u=z.device.isMac&&z.browser.isSafari;if(z.device.isAndroid)switch(s){case"dash":case"dash_any_mpeg":case"dash_any_webm":case"dash_sep":{o=a;break}case"hls":case"mpeg":{o=n;break}default:(0,ta.assertNever)(s)}else z.video.nativeHlsSupported&&!u?o=n:u?o=e?["DASH_LIVE_CMAF","HLS_LIVE_CMAF","HLS_LIVE","DASH_LIVE"]:["HLS_LIVE","DASH_LIVE","DASH_LIVE_CMAF","HLS_LIVE_CMAF"]:o=a;return t?["WEB_RTC_LIVE",...o]:[...o,"WEB_RTC_LIVE"]},tc=s=>s?["HLS_LIVE","HLS_LIVE_CMAF","DASH_LIVE_CMAF"]:["DASH_WEBM","DASH_WEBM_AV1","DASH_SEP","DASH_ONDEMAND","HLS","HLS_ONDEMAND","MPEG"],Wn=s=>{if(s.size===0)return;if(s.size===1){let t=s.values().next();return(0,Qn.default)(t.value.split("."),0)}for(let t of s){let i=(0,Qn.default)(t.split("."),0);if(i==="opus"||i==="vp09"||i==="av01")return i}let e=s.values().next();return(0,Qn.default)(e.value.split("."),0)},Gn=s=>{let e=s.map(i=>kr(i)),{codecs:t}=z.video;return u$().filter(i=>{if((0,ec.default)(e,i))switch(i){case"av1":return t.av1;case"vp9":return t.vp9;case"avc1":return t.h264;case"hev1":return t.h265;default:return!1}else return!1})},zn=s=>{let e=s.map(i=>kr(i)),{codecs:t}=z.video;return l$().filter(i=>{if((0,ec.default)(e,i))switch(i){case"opus":return t.opus;case"mp4a":return t.aac;default:return!1}else return!1})},kr=s=>s.split(".")[0].replace("0",""),u$=()=>["av1","vp9","hev1","avc1"],l$=()=>["opus","mp4a"];var p$=["timeupdate","progress","play","seeked","stalled","waiting"],h$=["timeupdate","progress","loadeddata","playing","seeked"];var Yn=class{constructor(e){this.element=null;this.manifestUrlString="";this.source=null;this.manifest=null;this.bufferManagers=[];this.subscription=new T.Subscription;this.representationSubscription=new T.Subscription;this.state$=new re("none");this.currentVideoRepresentation$=new T.ValueSubject(void 0);this.currentVideoRepresentationInit$=new T.ValueSubject(void 0);this.currentAudioRepresentation$=new T.ValueSubject(void 0);this.currentVideoSegmentLength$=new T.ValueSubject(0);this.currentAudioSegmentLength$=new T.ValueSubject(0);this.error$=new T.Subject;this.manifestRequested=new T.Subject;this.manifestReceived=new T.Subject;this.firstBytesRequested=new T.Subject;this.firstBytesReceived=new T.Subject;this.lastConnectionType$=new T.ValueSubject(void 0);this.lastConnectionReused$=new T.ValueSubject(void 0);this.lastRequestFirstBytes$=new T.ValueSubject(void 0);this.currentLiveTextRepresentation$=new T.ValueSubject(null);this.isLive$=new T.ValueSubject(!1);this.isActiveLive$=new T.ValueSubject(!1);this.isLowLatency$=new T.ValueSubject(!1);this.liveDuration$=new T.ValueSubject(0);this.liveSeekableDuration$=new T.ValueSubject(0);this.liveAvailabilityStartTime$=new T.ValueSubject(0);this.liveStreamStatus$=new T.ValueSubject(void 0);this.bufferLength$=new T.ValueSubject(0);this.liveLatency$=new T.ValueSubject(void 0);this.liveLoadBufferLength$=new T.ValueSubject(0);this.livePositionFromPlayer$=new T.ValueSubject(0);this.currentStallDuration$=new T.ValueSubject(0);this.videoLastDataObtainedTimestamp$=new T.ValueSubject(0);this.fetcherRecoverableError$=new T.Subject;this.fetcherError$=new T.Subject;this.liveStreamEndTimestamp=0;this.isUpdatingLive=!1;this.isJumpGapAfterSeekLive=!1;this.forceEnded$=new T.Subject;this.gapWatchdogActive=!1;this.destroyController=new ce;this.initManifest=(0,T.abortable)(this.destroyController.signal,async function*(e,t,i){var r;this.tracer.log("initManifest"),this.element=e,this.manifestUrlString=xe(t,i,2),this.state$.startTransitionTo("manifest_ready"),this.manifest=yield this.updateManifest(),(r=this.manifest)!=null&&r.streams.video.length?this.state$.setState("manifest_ready"):this.error$.next({id:"NoRepresentations",category:T.ErrorCategory.PARSER,message:"No playable video representations"})}.bind(this));this.updateManifest=(0,T.abortable)(this.destroyController.signal,async function*(){var u,l;this.tracer.log("updateManifestStart",{manifestUrl:this.manifestUrlString});let e=yield this.fetcher.fetchManifest(this.manifestUrlString).catch(c=>{!this.manifest&&!this.bufferLength$.getValue()&&this.error$.next({id:"LoadManifest",category:T.ErrorCategory.NETWORK,message:"Failed to load manifest",thrown:c})});if(!e)return null;let t=null;try{t=Dn(e!=null?e:"",this.manifestUrlString)}catch(c){let d=(u=$n(e))!=null?u:{id:"ManifestParsing",category:T.ErrorCategory.PARSER,message:"Failed to parse MPD manifest",thrown:c};this.error$.next(d)}if(!t)return null;let i=(c,d,f)=>{var p,h,b,S;return!!((h=(p=this.element)==null?void 0:p.canPlayType)!=null&&h.call(p,d)&&((S=(b=it())==null?void 0:b.isTypeSupported)!=null&&S.call(b,`${d}; codecs="${f}"`))||c==="text")};if(t.live){this.isLive$.next(!!t.live);let{availabilityStartTime:c,latestSegmentPublishTime:d,streamIsUnpublished:f,streamIsAlive:p}=t.live,h=((l=t.duration)!=null?l:0)/1e3;this.liveSeekableDuration$.next(-1*h),this.liveDuration$.next((d-c)/1e3),this.liveAvailabilityStartTime$.next(t.live.availabilityStartTime);let b="active";p||(b=f?"unpublished":"unexpectedly_down"),this.liveStreamStatus$.next(b)}let r={text:t.streams.text,video:[],audio:[]},a,n;for(let c of["video","audio"]){let f=t.streams[c].filter(({mime:h,codecs:b})=>i(c,h,b));r[c]=f;let p;if(this.tuning.dash.codecsPrioritizeEnabled){let h=f.map(({codecs:b})=>b);c==="audio"&&(n=zn(h),p=n[0]),c==="video"&&(a=Gn(h),this.forceVideoCodec&&(0,GS.default)(a,this.forceVideoCodec)?p=this.forceVideoCodec:p=a[0]),p&&(r[c]=f.filter(({codecs:b})=>kr(b)===p))}else{let h=new Set(f.map(({codecs:b})=>b));p=Wn(h),p&&(r[c]=f.filter(({codecs:b})=>b.startsWith(p)))}if(c==="video"){let h=this.tuning.preferHDR,b=r.video.some(g=>g.hdr),S=r.video.some(g=>!g.hdr);z.display.isHDR&&h&&b?r.video=r.video.filter(g=>g.hdr):S&&(r.video=r.video.filter(g=>!g.hdr))}}let o={...t,streams:r};return this.tuning.dash.codecsPrioritizeEnabled&&(o.codecs={video:a,audio:n}),this.tracer.log("updateManifestEnd",(0,T.flattenObject)(o)),o}.bind(this));this.initRepresentations=(0,T.abortable)(this.destroyController.signal,async function*(e,t,i){var f;this.tracer.log("initRepresentationsStart",(0,T.flattenObject)({initialVideo:e,initialAudio:t,sourceHls:i})),(0,T.assertNonNullable)(this.manifest),(0,T.assertNonNullable)(this.element),this.representationSubscription.unsubscribe(),this.state$.startTransitionTo("representations_ready");let r=p=>{this.representationSubscription.add((0,T.fromEvent)(p,"error").pipe((0,T.filter)(h=>{var b;return!!((b=this.element)!=null&&b.played.length)})).subscribe(h=>{this.error$.next({id:"VideoSource",category:T.ErrorCategory.VIDEO_PIPELINE,message:"Unexpected video source error",thrown:h})}))};this.source=fn();let a=document.createElement("source");if(r(a),a.src=URL.createObjectURL(this.source),this.element.appendChild(a),mr())if(i){let p=document.createElement("source");r(p),p.type="application/x-mpegurl",p.src=i.url,this.element.appendChild(p)}else this.element.disableRemotePlayback=!0;this.isActiveLive$.next(this.isLive$.getValue());let n={fetcher:this.fetcher,tuning:this.tuning,getCurrentPosition:()=>this.element?this.element.currentTime*1e3:void 0,isActiveLowLatency:()=>this.isActiveLive$.getValue()&&this.isLowLatency$.getValue(),manifest:this.manifest},o=this.manifest.streams.video.reduce((p,h)=>[...p,...h.representations],[]);if(this.videoBufferManager=new Js("video",this.source,o,n),this.bufferManagers=[this.videoBufferManager],(0,T.isNonNullable)(t)){let p=this.manifest.streams.audio.reduce((h,b)=>[...h,...b.representations],[]);this.audioBufferManager=new Js("audio",this.source,p,n),this.bufferManagers.push(this.audioBufferManager)}ea.isSupported(this.manifest.streams.text)&&!this.isLowLatency$.getValue()&&(this.liveTextManager=new ea(this.manifest.streams.text,n)),this.representationSubscription.add(this.fetcher.manifestRequested.subscribe(this.manifestRequested)),this.representationSubscription.add(this.fetcher.manifestReceived.subscribe(this.manifestReceived)),this.representationSubscription.add(this.fetcher.firstBytesRequested.subscribe(this.firstBytesRequested)),this.representationSubscription.add(this.fetcher.firstBytesReceived.subscribe(this.firstBytesReceived)),this.representationSubscription.add(this.fetcher.lastConnectionType$.subscribe(this.lastConnectionType$)),this.representationSubscription.add(this.fetcher.lastConnectionReused$.subscribe(this.lastConnectionReused$)),this.representationSubscription.add(this.fetcher.lastRequestFirstBytes$.subscribe(this.lastRequestFirstBytes$));let u=()=>{var p;(p=this.stallWatchdogSubscription)==null||p.unsubscribe(),this.currentStallDuration$.next(0)};if(this.representationSubscription.add((0,T.merge)(...h$.map(p=>(0,T.fromEvent)(this.element,p))).pipe((0,T.map)(p=>this.element?$e(this.element.buffered,this.element.currentTime*1e3):0),(0,T.filterChanged)(),(0,T.tap)(p=>{p>this.tuning.dash.bufferEmptinessTolerance&&u()})).subscribe(this.bufferLength$)),this.representationSubscription.add((0,T.merge)((0,T.fromEvent)(this.element,"ended"),this.forceEnded$).subscribe(()=>{u()})),this.isLive$.getValue()){this.subscription.add(this.liveDuration$.pipe((0,T.filterChanged)()).subscribe(h=>this.liveStreamEndTimestamp=(0,T.now)())),this.subscription.add((0,T.fromEvent)(this.element,"pause").subscribe(()=>{this.livePauseWatchdogSubscription=(0,T.interval)(1e3).subscribe(h=>{let b=ni(this.manifestUrlString,2);this.manifestUrlString=xe(this.manifestUrlString,b+1e3,2),this.liveStreamStatus$.getValue()==="active"&&this.updateManifest()}),this.subscription.add(this.livePauseWatchdogSubscription)})).add((0,T.fromEvent)(this.element,"play").subscribe(h=>{var b;return(b=this.livePauseWatchdogSubscription)==null?void 0:b.unsubscribe()})),this.representationSubscription.add((0,T.combine)({isActiveLive:this.isActiveLive$,isLowLatency:this.isLowLatency$}).pipe((0,T.map)(({isActiveLive:h,isLowLatency:b})=>h&&b),(0,T.filterChanged)()).subscribe(h=>{this.isManualDecreasePlaybackInLive()||Rr(this.element,1)})),this.representationSubscription.add((0,T.combine)({bufferLength:this.bufferLength$,isActiveLive:this.isActiveLive$,isLowLatency:this.isLowLatency$}).pipe((0,T.filter)(({bufferLength:h,isActiveLive:b,isLowLatency:S})=>b&&S&&!!h)).subscribe(({bufferLength:h})=>this.liveBuffer.next(h))),this.representationSubscription.add(this.videoBufferManager.currentLowLatencySegmentLength$.subscribe(h=>{if(!this.isActiveLive$.getValue()&&!this.isLowLatency$.getValue()&&!h)return;let b=this.liveSeekableDuration$.getValue()-h/1e3;this.liveSeekableDuration$.next(Math.max(b,-1*this.tuning.dashCmafLive.maxLiveDuration)),this.liveDuration$.next(this.liveDuration$.getValue()+h/1e3)})),this.representationSubscription.add((0,T.combine)({isLive:this.isLive$,rtt:this.throughputEstimator.rtt$,bufferLength:this.bufferLength$,segmentServerLatency:this.videoBufferManager.currentLiveSegmentServerLatency$}).pipe((0,T.filter)(({isLive:h})=>h),(0,T.filterChanged)((h,b)=>b.bufferLength<h.bufferLength),(0,T.map)(({rtt:h,bufferLength:b,segmentServerLatency:S})=>{let g=ni(this.manifestUrlString,2);return(h/2+b+S+g)/1e3})).subscribe(this.liveLatency$)),this.representationSubscription.add((0,T.combine)({liveBuffer:this.liveBuffer.smoothed$,isActiveLive:this.isActiveLive$,isLowLatency:this.isLowLatency$}).subscribe(({liveBuffer:h,isActiveLive:b,isLowLatency:S})=>{if(!S||!b)return;let g=this.tuning.dashCmafLive.lowLatency.maxTargetOffset,I=this.tuning.dashCmafLive.lowLatency.maxTargetOffsetDeviation,w=this.tuning.dashCmafLive.lowLatency.playbackCatchupSpeedup,E=h-g;if(this.isManualDecreasePlaybackInLive())return;let P=1;Math.abs(E)>I&&(P=1+Math.sign(E)*w),Rr(this.element,P)})),this.representationSubscription.add(this.bufferLength$.subscribe(h=>{var S,g;let b=0;if(h){let I=((g=(S=this.element)==null?void 0:S.currentTime)!=null?g:0)*1e3;b=Math.min(...this.bufferManagers.map(E=>{var P,_;return(_=(P=E.getLiveSegmentsToLoadState(this.manifest))==null?void 0:P.to)!=null?_:I}))-I}this.liveLoadBufferLength$.getValue()!==b&&this.liveLoadBufferLength$.next(b)}));let p=0;this.representationSubscription.add((0,T.combine)({liveLoadBufferLength:this.liveLoadBufferLength$,bufferLength:this.bufferLength$}).pipe((0,T.throttle)(1e3)).subscribe(async({liveLoadBufferLength:h,bufferLength:b})=>{if(!this.element||this.isUpdatingLive)return;let S=this.element.playbackRate,g=ni(this.manifestUrlString,2),I=Math.abs(this.livePositionFromPlayer$.getValue())*1e3,w=Math.min(I,this.tuning.dashCmafLive.normalizedTargetMinBufferSize*S),E=this.tuning.dashCmafLive.normalizedActualBufferOffset*S,P=this.tuning.dashCmafLive.normalizedLiveMinBufferSize*S,_=isFinite(h)?h:b,N=this.isActiveLive$.getValue()&&this.isLowLatency$.getValue(),F=I<=this.tuning.live.activeLiveDelay;this.isActiveLive$.next(F);let C="none";if(N?C="active_low_latency":this.isLowLatency$.getValue()&&F?(this.bufferManagers.forEach(B=>B.proceedLowLatencyLive()),C="active_low_latency"):g!==0&&_<w?C="live_forward_buffering":_<w+P&&(C="live_with_target_offset"),isFinite(h)&&(p=h>p?h:p),C==="live_forward_buffering"||C==="live_with_target_offset"){let B=p-(w+E),H=this.normolizeLiveOffset(Math.trunc(g+B/S)),q=Math.abs(H-g),W=0;!h||q<=this.tuning.dashCmafLive.offsetCalculationError?W=g:H>0&&q>this.tuning.dashCmafLive.offsetCalculationError&&(W=H),this.manifestUrlString=xe(this.manifestUrlString,W,2)}(C==="live_with_target_offset"||C==="live_forward_buffering")&&(p=0,await this.updateLive())},h=>{this.error$.next({id:"updateLive",category:T.ErrorCategory.VIDEO_PIPELINE,thrown:h,message:"Failed to update live with subscription"})}))}let l=(0,T.merge)(...this.bufferManagers.map(p=>p.fullyBuffered$)).pipe((0,T.map)(()=>this.bufferManagers.every(p=>p.fullyBuffered$.getValue()))),c=(0,T.merge)(...this.bufferManagers.map(p=>p.onLastSegment$)).pipe((0,T.map)(()=>this.bufferManagers.some(p=>p.onLastSegment$.getValue()))),d=(0,T.combine)({allBuffersFull:l,someBufferEnded:c}).pipe((0,T.filterChanged)(),(0,T.map)(({allBuffersFull:p,someBufferEnded:h})=>p&&h),(0,T.filter)(p=>p));if(this.representationSubscription.add((0,T.merge)(this.forceEnded$,d).subscribe(()=>{var p;if(this.source&&this.source.readyState==="open"&&Array.from(this.source.sourceBuffers).every(h=>!h.updating))try{(p=this.source)==null||p.endOfStream()}catch(h){this.error$.next({id:"EndOfStream",category:T.ErrorCategory.VIDEO_PIPELINE,message:"Failed to end MediaSource stream",thrown:h})}})),this.representationSubscription.add((0,T.merge)(...this.bufferManagers.map(p=>p.error$)).subscribe(this.error$)),this.representationSubscription.add(this.videoBufferManager.playingRepresentation$.subscribe(this.currentVideoRepresentation$)),this.representationSubscription.add(this.videoBufferManager.playingRepresentationInit$.subscribe(this.currentVideoRepresentationInit$)),this.representationSubscription.add(this.videoBufferManager.currentSegmentLength$.subscribe(this.currentVideoSegmentLength$)),this.audioBufferManager&&(this.representationSubscription.add(this.audioBufferManager.playingRepresentation$.subscribe(this.currentAudioRepresentation$)),this.representationSubscription.add(this.audioBufferManager.currentSegmentLength$.subscribe(this.currentAudioSegmentLength$))),this.liveTextManager&&this.representationSubscription.add(this.liveTextManager.currentRepresentation$.subscribe(this.currentLiveTextRepresentation$)),this.source.readyState!=="open"){let p=this.tuning.dash.sourceOpenTimeout>=0;yield new Promise(h=>{var b;p&&(this.timeoutSourceOpenId=setTimeout(()=>{var S;if(((S=this.source)==null?void 0:S.readyState)==="open"){h();return}this.error$.next({id:"OpenOfStream",category:T.ErrorCategory.VIDEO_PIPELINE,message:"Failed to open MediaSource",thrown:new Error("Timeout reject when wait sourceopen event"),traceAsLog:!0})},this.tuning.dash.sourceOpenTimeout)),(b=this.source)==null||b.addEventListener("sourceopen",()=>{this.timeoutSourceOpenId&&clearTimeout(this.timeoutSourceOpenId),h()},{once:!0})})}if(!this.isLive$.getValue()){let p=[(f=this.manifest.duration)!=null?f:0,...(0,rc.default)((0,rc.default)([...this.manifest.streams.audio,...this.manifest.streams.video],h=>h.representations),h=>{let b=[];return h.duration&&b.push(h.duration),st(h.segmentReference)&&h.segmentReference.totalSegmentsDurationMs&&b.push(h.segmentReference.totalSegmentsDurationMs),b})];this.source.duration=Math.max(...p)/1e3}this.audioBufferManager&&(0,T.isNonNullable)(t)?yield Promise.all([this.videoBufferManager.startWith(e),this.audioBufferManager.startWith(t)]):yield this.videoBufferManager.startWith(e),this.state$.setState("representations_ready"),this.tracer.log("initRepresentationsEnd")}.bind(this));this.tick=()=>{var t,i,r,a;if(!this.element||!this.videoBufferManager||((t=this.source)==null?void 0:t.readyState)!=="open")return;let e=this.element.currentTime*1e3;this.videoBufferManager.maintain(e),(i=this.audioBufferManager)==null||i.maintain(e),(r=this.liveTextManager)==null||r.maintain(e),(this.videoBufferManager.gaps.length||(a=this.audioBufferManager)!=null&&a.gaps.length)&&!this.gapWatchdogActive&&(this.gapWatchdogActive=!0,this.gapWatchdogSubscription=(0,T.interval)(this.tuning.gapWatchdogInterval).subscribe(()=>this.jumpGap(),n=>{this.error$.next({id:"GapWatchdog",category:T.ErrorCategory.WTF,message:"Error handling gaps",thrown:n})}),this.subscription.add(this.gapWatchdogSubscription))};this.throughputEstimator=e.throughputEstimator,this.tuning=e.tuning,this.tracer=e.tracer.createComponentTracer(this.constructor.name),this.forceVideoCodec=e.forceVideoCodec,this.fetcher=new Fn({throughputEstimator:this.throughputEstimator,requestQuic:this.tuning.requestQuick,compatibilityMode:e.compatibilityMode,tracer:this.tracer,useEnableSubtitlesParam:e.tuning.useEnableSubtitlesParam}),this.subscription.add(this.fetcher.recoverableError$.subscribe(this.fetcherRecoverableError$)),this.subscription.add(this.fetcher.error$.subscribe(this.fetcherError$)),this.liveBuffer=Wt.getLiveBufferSmoothedValue(this.tuning.dashCmafLive.lowLatency.maxTargetOffset,{...e.tuning.dashCmafLive.lowLatency.bufferEstimator}),this.initTracerSubscription()}async seekLive(e){var r,a,n;(0,T.assertNonNullable)(this.element);let t=this.liveStreamStatus$.getValue()!=="active"?(0,T.now)()-this.liveStreamEndTimestamp:0,i=this.normolizeLiveOffset(e+t);this.isActiveLive$.next(i===0),this.manifestUrlString=xe(this.manifestUrlString,i,2),this.manifest=await this.updateManifest(),this.manifest&&(this.isJumpGapAfterSeekLive=!0,await((r=this.videoBufferManager)==null?void 0:r.seekLive(this.manifest.streams.video)),await((a=this.audioBufferManager)==null?void 0:a.seekLive(this.manifest.streams.audio)),(n=this.liveTextManager)==null||n.seekLive(this.manifest.streams.text))}initBuffer(){(0,T.assertNonNullable)(this.element),this.state$.setState("running"),this.subscription.add((0,T.merge)(...p$.map(e=>(0,T.fromEvent)(this.element,e)),(0,T.fromEvent)(window,"online")).subscribe(()=>this.tick(),e=>{this.error$.next({id:"DashVKPlayer",category:T.ErrorCategory.WTF,message:"Internal logic error",thrown:e})})),this.subscription.add((0,T.fromEvent)(this.element,"progress").subscribe(()=>{this.element&&this.element.readyState===2&&!this.element.seeking&&(this.element.currentTime=this.element.currentTime)})),this.subscription.add((0,T.fromEvent)(this.element,"waiting").subscribe(()=>{var t;this.element&&this.element.readyState===2&&!this.element.seeking&&_e(this.element.buffered,this.element.currentTime*1e3)&&(this.element.currentTime=this.element.currentTime);let e=()=>{var p,h,b,S,g,I,w,E,P,_,N;if(!this.element||((p=this.source)==null?void 0:p.readyState)!=="open")return;let i=this.currentStallDuration$.getValue();i+=50,this.currentStallDuration$.next(i);let r={timeInWaiting:i},a=(0,T.now)(),n=100,o=(b=(h=this.videoBufferManager)==null?void 0:h.lastDataObtainedTimestamp)!=null?b:0;this.videoLastDataObtainedTimestamp$.next(o);let u=(g=(S=this.audioBufferManager)==null?void 0:S.lastDataObtainedTimestamp)!=null?g:0,l=(w=(I=this.videoBufferManager)==null?void 0:I.getForwardBufferDuration())!=null?w:0,c=(P=(E=this.audioBufferManager)==null?void 0:E.getForwardBufferDuration())!=null?P:0,d=l<n&&a-o>this.tuning.dash.crashOnStallTWithoutDataTimeout,f=this.audioBufferManager&&c<n&&a-u>this.tuning.dash.crashOnStallTWithoutDataTimeout;if((d||f)&&i>this.tuning.dash.crashOnStallTWithoutDataTimeout||i>=this.tuning.dash.crashOnStallTimeout)throw new Error(`Stall timeout exceeded: ${i} ms`);if(this.isLive$.getValue()&&i%2e3===0){let F=this.normolizeLiveOffset(-1*this.livePositionFromPlayer$.getValue()*1e3);this.seekLive(F).catch(C=>{this.error$.next({id:"stallIntervalCallback",category:T.ErrorCategory.VIDEO_PIPELINE,message:"stallIntervalCallback failed",thrown:C})}),r.liveLastOffset=F}else{let F=this.element.currentTime*1e3;(_=this.videoBufferManager)==null||_.maintain(F),(N=this.audioBufferManager)==null||N.maintain(F),r.position=F}this.tracer.log("stallIntervalCallback",(0,T.flattenObject)(r))};(t=this.stallWatchdogSubscription)==null||t.unsubscribe(),this.stallWatchdogSubscription=(0,T.interval)(50).subscribe(e,i=>{this.error$.next({id:"StallWatchdogCallback",category:T.ErrorCategory.NETWORK,message:"Can't restore DASH after stall.",thrown:i})}),this.subscription.add(this.stallWatchdogSubscription)})),this.tick()}async switchRepresentation(e,t,i=!1){let r={video:this.videoBufferManager,audio:this.audioBufferManager,text:null}[e];return this.tuning.useNewSwitchTo?this.currentStallDuration$.getValue()>0?r==null?void 0:r.switchToWithPreviousAbort(t,i):r==null?void 0:r.switchTo(t,i):r==null?void 0:r.switchToOld(t,i)}async seek(e,t){var r,a,n,o,u;(0,T.assertNonNullable)(this.element),(0,T.assertNonNullable)(this.videoBufferManager);let i;t||this.element.duration*1e3<=this.tuning.dashSeekInSegmentDurationThreshold||Math.abs(this.element.currentTime*1e3-e)<=this.tuning.dashSeekInSegmentAlwaysSeekDelta?i=e:i=Math.max((r=this.videoBufferManager.findSegmentStartTime(e))!=null?r:e,(n=(a=this.audioBufferManager)==null?void 0:a.findSegmentStartTime(e))!=null?n:e),this.warmUpMediaSourceIfNeeded(i),_e(this.element.buffered,i)||await Promise.all([this.videoBufferManager.abort(),(o=this.audioBufferManager)==null?void 0:o.abort()]),!((0,T.isNullable)(this.element)||(0,T.isNullable)(this.videoBufferManager))&&(this.videoBufferManager.maintain(i),(u=this.audioBufferManager)==null||u.maintain(i),this.element.currentTime=i/1e3,this.tracer.log("seek",(0,T.flattenObject)({requestedPosition:e,forcePrecise:t,position:i})))}warmUpMediaSourceIfNeeded(e=(t=>(t=this.element)==null?void 0:t.currentTime)()){var i;(0,T.isNonNullable)(this.element)&&(0,T.isNonNullable)(this.source)&&(0,T.isNonNullable)(e)&&((i=this.source)==null?void 0:i.readyState)==="ended"&&this.element.duration*1e3-e>this.tuning.dash.seekBiasInTheEnd&&this.bufferManagers.forEach(r=>r.warmUpMediaSource())}get isStreamEnded(){var e;return((e=this.source)==null?void 0:e.readyState)==="ended"}stop(){var e,t,i;this.tracer.log("stop"),(e=this.element)==null||e.querySelectorAll("source").forEach(r=>{URL.revokeObjectURL(r.src),r.remove()}),this.element=null,this.source=null,this.manifest=null,this.currentVideoRepresentation$.next(void 0),(t=this.videoBufferManager)==null||t.destroy(),this.videoBufferManager=null,(i=this.audioBufferManager)==null||i.destroy(),this.audioBufferManager=null,this.bufferManagers=[],this.state$.setState("none")}setBufferTarget(e){for(let t of this.bufferManagers)t.setTarget(e)}getStreams(){var e;return(e=this.manifest)==null?void 0:e.streams}getCodecs(){var e;return(e=this.manifest)==null?void 0:e.codecs}setPreloadOnly(e){for(let t of this.bufferManagers)t.setPreloadOnly(e)}destroy(){var e;this.subscription.unsubscribe(),this.representationSubscription.unsubscribe(),this.timeoutSourceOpenId&&clearTimeout(this.timeoutSourceOpenId),this.destroyController.abort(),this.fetcher.destroy(),this.stop(),((e=this.source)==null?void 0:e.readyState)==="open"&&Array.from(this.source.sourceBuffers).every(t=>!t.updating)&&this.source.endOfStream(),this.source=null,this.tracer.end()}initTracerSubscription(){let e=(0,T.getTraceSubscriptionMethod)(this.tracer.error.bind(this.tracer));this.subscription.add(this.error$.subscribe(e("error")))}isManualDecreasePlaybackInLive(){if(!this.element||!this.isLive$.getValue())return!1;let e=1-this.element.playbackRate;return Number(e.toFixed(2))>Number(this.tuning.dashCmafLive.lowLatency.playbackCatchupSpeedup.toFixed(2))}normolizeLiveOffset(e){return Math.trunc(e/1e3)*1e3}async updateLive(){var e;this.isUpdatingLive=!0,this.manifest=await this.updateManifest(),this.manifest&&(this.bufferManagers.forEach(t=>t.updateLive(this.manifest)),(e=this.liveTextManager)==null||e.updateLive(this.manifest)),this.isUpdatingLive=!1}jumpGap(){if(!this.element||!this.videoBufferManager)return;let e=this.videoBufferManager.getDebugBufferState();if(!e)return;let t=this.isActiveLive$.getValue()&&this.isLowLatency$.getValue(),i={isJumpGapAfterSeekLive:this.isJumpGapAfterSeekLive,isActiveLowLatency:t,initialCurrentTime:this.element.currentTime};this.isJumpGapAfterSeekLive&&!t&&this.element.currentTime>e.to&&(this.isJumpGapAfterSeekLive=!1,this.element.currentTime=0);let r=this.element.currentTime*1e3,a=[],n=this.element.readyState===1?this.tuning.endGapTolerance:0;for(let o of this.bufferManagers)for(let u of o.gaps)o.playingRepresentation$.getValue()===u.representation&&u.from-n<=r&&u.to+n>r&&(this.element.duration*1e3-u.to<this.tuning.endGapTolerance?a.push(1/0):a.push(u.to));if(a.length){let o=Math.max(...a)+10;this.gapWatchdogSubscription.unsubscribe(),this.gapWatchdogActive=!1,o===1/0?this.forceEnded$.next():(this.element.currentTime=o/1e3,i={...i,gapEnds:a,jumpTo:o,resultCurrentTime:this.element.currentTime},this.tracer.log("jumpGap",(0,T.flattenObject)(i)))}}calculateDurationFromSegments(){var e,t;return Math.max(((e=this.videoBufferManager)==null?void 0:e.calculateDurationFromSegments())||0,((t=this.audioBufferManager)==null?void 0:t.calculateDurationFromSegments())||0)}};var Kn=class{constructor(e,t){this.fov=e,this.orientation=t}};var Xn=class{constructor(e,t){this.rotating=!1;this.fading=!1;this.lastTickTS=0;this.lastCameraTurnTS=0;this.fadeStartSpeed=null;this.fadeTime=0;this.camera=e,this.options=t,this.rotationSpeed={x:0,y:0,z:0},this.fadeCorrection=1/(this.options.speedFadeTime/1e3)**2}turnCamera(e=0,t=0,i=0){this.pointCameraTo(this.camera.orientation.x+e,this.camera.orientation.y+t,this.camera.orientation.z+i)}pointCameraTo(e=0,t=0,i=0){t=this.limitCameraRotationY(t);let r=e-this.camera.orientation.x,a=t-this.camera.orientation.y,n=i-this.camera.orientation.z;this.camera.orientation.x=e,this.camera.orientation.y=t,this.camera.orientation.z=i,this.lastCameraTurn={x:r,y:a,z:n},this.lastCameraTurnTS=Date.now()}setRotationSpeed(e,t,i){this.rotationSpeed.x=e!=null?e:this.rotationSpeed.x,this.rotationSpeed.y=t!=null?t:this.rotationSpeed.y,this.rotationSpeed.z=i!=null?i:this.rotationSpeed.z}startRotation(){this.rotating=!0}stopRotation(e=!1){e?(this.setRotationSpeed(0,0,0),this.fadeStartSpeed=null):this.startFading(this.rotationSpeed.x,this.rotationSpeed.y,this.rotationSpeed.z),this.rotating=!1}onCameraRelease(){if(this.lastCameraTurn&&this.lastCameraTurnTS){let e=Date.now()-this.lastCameraTurnTS;if(e<this.options.speedFadeThreshold){let t=(1-e/this.options.speedFadeThreshold)*this.options.rotationSpeedCorrection;this.startFading(this.lastCameraTurn.x*t,this.lastCameraTurn.y*t,this.lastCameraTurn.z*t)}}}startFading(e,t,i){this.setRotationSpeed(e,t,i),this.fadeStartSpeed={...this.rotationSpeed},this.fading=!0}stopFading(){this.fadeStartSpeed=null,this.fading=!0,this.fadeTime=0}limitCameraRotationY(e){return Math.max(-this.options.maxYawAngle,Math.min(e,this.options.maxYawAngle))}tick(e){if(!this.lastTickTS){this.lastTickTS=e,this.lastCameraTurnTS=Date.now();return}let t=e-this.lastTickTS,i=t/1e3;if(this.rotating)this.turnCamera(this.rotationSpeed.x*this.options.rotationSpeedCorrection*i,this.rotationSpeed.y*this.options.rotationSpeedCorrection*i,this.rotationSpeed.z*this.options.rotationSpeedCorrection*i);else if(this.fading&&this.fadeStartSpeed){let r=-this.fadeCorrection*(this.fadeTime/1e3)**2+1;this.setRotationSpeed(this.fadeStartSpeed.x*r,this.fadeStartSpeed.y*r,this.fadeStartSpeed.z*r),r>0?this.turnCamera(this.rotationSpeed.x*this.options.rotationSpeedCorrection*i,this.rotationSpeed.y*this.options.rotationSpeedCorrection*i,this.rotationSpeed.z*this.options.rotationSpeedCorrection*i):(this.stopRotation(!0),this.stopFading()),this.fadeTime=Math.min(this.fadeTime+t,this.options.speedFadeTime)}this.lastTickTS=e}};var zS=`attribute vec2 a_vertex;
124
+ `})|(?<privateuse2>${e}))$`.replace(/[\s\t\n]/g,"");return new RegExp(c,"i")}var MS=s=>{if(!(s!=null&&s.startsWith("P")))return;let e=(n,o)=>{let u=n?parseFloat(n.replace(",",".")):NaN;return(isNaN(u)?0:u)*o},i=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/.exec(s),r=(i==null?void 0:i[1])==="-"?-1:1,a={days:e(i==null?void 0:i[5],r),hours:e(i==null?void 0:i[6],r),minutes:e(i==null?void 0:i[7],r),seconds:e(i==null?void 0:i[8],r)};return a.days*24*60*60*1e3+a.hours*60*60*1e3+a.minutes*60*1e3+a.seconds*1e3},It=(s,e)=>{let t=s;t=(0,Wl.default)(t,"$$","$");let i={RepresentationID:e.representationId,Number:e.segmentNumber,Bandwidth:e.bandwidth,Time:e.segmentTime};for(let[r,a]of(0,DS.default)(i)){let n=new RegExp(`\\$${r}(?:%0(\\d+)d)?\\$`,"g");t=(0,Wl.default)(t,n,(o,u)=>(0,Xs.isNullable)(a)?o:(0,Xs.isNullable)(u)?a:(0,CS.default)(a,parseInt(u,10),"0"))}return t},Dn=(s,e)=>{var C,B,H,q,W,ue,le,A,V,$,M,U,Te,Xe,me,ne,Me,De,Ce,Je,Vt,Kt,mi,ji,Dr,Ic,Ec,xc,wc,Ac,Pc,Rc,kc,Lc,$c,Mc,Dc,Cc,Bc,Vc,_c,Oc,Fc,Nc,qc,Uc,Hc,jc,Qc,Wc,Gc,zc,Yc,Kc,Xc,Jc,Zc,ed,td,id,rd;let i=new DOMParser().parseFromString(s,"application/xml"),r={video:[],audio:[],text:[]},a=i.children[0],n=Array.from(a.querySelectorAll("MPD > BaseURL").values()).map(ht=>{var fe,bi;return(bi=(fe=ht.textContent)==null?void 0:fe.trim())!=null?bi:""}),o=(C=(0,BS.default)(n,0))!=null?C:"",u=a.getAttribute("type")==="dynamic",l=a.getAttribute("availabilityStartTime"),c=a.getAttribute("publishTime"),d=a.getElementsByTagName("vk:Attrs")[0],f=d==null?void 0:d.getElementsByTagName("vk:XLatestSegmentPublishTime")[0].textContent,p=d==null?void 0:d.getElementsByTagName("vk:XStreamIsLive")[0].textContent,h=d==null?void 0:d.getElementsByTagName("vk:XStreamIsUnpublished")[0].textContent,b=d==null?void 0:d.getElementsByTagName("vk:XPlaybackDuration")[0].textContent,S;u&&(S={availabilityStartTime:l?new Date(l).getTime():0,publishTime:c?new Date(c).getTime():0,latestSegmentPublishTime:f?new Date(f).getTime():0,streamIsAlive:p==="yes",streamIsUnpublished:h==="yes"});let g,I=a.getAttribute("mediaPresentationDuration"),w=[...a.getElementsByTagName("Period")],E=w.reduce((ht,fe)=>({...ht,[fe.id]:fe.children}),{}),P=w.reduce((ht,fe)=>({...ht,[fe.id]:fe.getAttribute("duration")}),{});I?g=MS(I):(0,Gl.default)(P).filter(ht=>ht).length&&!u?g=(0,Gl.default)(P).reduce((ht,fe)=>{var bi;return ht+((bi=MS(fe))!=null?bi:0)},0):b&&(g=parseInt(b,10));let _=0,N=(H=(B=a.getAttribute("profiles"))==null?void 0:B.split(","))!=null?H:[];for(let ht of w.map(fe=>fe.id))for(let fe of E[ht]){let bi=(q=fe.getAttribute("id"))!=null?q:"id"+(_++).toString(10),Cr=(W=fe.getAttribute("mimeType"))!=null?W:"",vo=(ue=fe.getAttribute("codecs"))!=null?ue:"",So=(le=fe.getAttribute("contentType"))!=null?le:Cr==null?void 0:Cr.split("/")[0],$y=(V=(A=fe.getAttribute("profiles"))==null?void 0:A.split(","))!=null?V:[],sd=(M=$S(($=fe.getAttribute("lang"))!=null?$:""))!=null?M:{},ma=(Xe=(Te=(U=fe.querySelector("Label"))==null?void 0:U.textContent)==null?void 0:Te.trim())!=null?Xe:void 0,My=fe.querySelectorAll("Representation"),Dy=fe.querySelector("SegmentTemplate"),Cy=(ne=(me=fe.querySelector("Role"))==null?void 0:me.getAttribute("value"))!=null?ne:void 0,Qi=So,we={id:bi,language:sd.language,isDefault:Cy==="main",label:ma,codecs:vo,hdr:Qi==="video"&&Ql(vo),mime:Cr,representations:[]};for(let de of My){let Xt=(Me=de.getAttribute("lang"))!=null?Me:void 0,Br=(Ce=(De=ma!=null?ma:fe.getAttribute("label"))!=null?De:de.getAttribute("label"))!=null?Ce:void 0,ba=(Kt=(Vt=(Je=de.querySelector("BaseURL"))==null?void 0:Je.textContent)==null?void 0:Vt.trim())!=null?Kt:"",gi=new URL(ba||o,e).toString(),Jt=(mi=de.getAttribute("mimeType"))!=null?mi:Cr,ga=(Dr=(ji=de.getAttribute("codecs"))!=null?ji:vo)!=null?Dr:"",va;if(So==="text"){let Zt=de.getAttribute("id")||"",Sa=((Ic=sd.privateuse)==null?void 0:Ic.includes("x-auto"))||Zt.includes("_auto"),vi=de.querySelector("SegmentTemplate");if(vi){let Vr={representationId:(Ec=de.getAttribute("id"))!=null?Ec:void 0,bandwidth:(xc=de.getAttribute("bandwidth"))!=null?xc:void 0},ya=parseInt((wc=de.getAttribute("bandwidth"))!=null?wc:"",10)/1e3,Ta=(Pc=parseInt((Ac=vi.getAttribute("startNumber"))!=null?Ac:"",10))!=null?Pc:1,Wi=parseInt((Rc=vi.getAttribute("timescale"))!=null?Rc:"",10),yo=(kc=vi.querySelectorAll("SegmentTimeline S"))!=null?kc:[],Gi=vi.getAttribute("media");if(!Gi)continue;let Ia=[],Ea=0,xa="",zi=0,_r=Ta,Oe=0;for(let ft of yo){let Si=parseInt((Lc=ft.getAttribute("d"))!=null?Lc:"",10),ot=parseInt(($c=ft.getAttribute("r"))!=null?$c:"",10)||0,ei=parseInt((Mc=ft.getAttribute("t"))!=null?Mc:"",10);Oe=Number.isFinite(ei)?ei:Oe;let yi=Si/Wi*1e3,ti=Oe/Wi*1e3;for(let Et=0;Et<ot+1;Et++){let ii=It(Gi,{...Vr,segmentNumber:_r.toString(10),segmentTime:(Oe+Et*Si).toString(10)}),Yi=(ti!=null?ti:0)+Et*yi,Fr=Yi+yi;_r++,Ia.push({time:{from:Yi,to:Fr},url:ii})}Oe+=(ot+1)*Si,Ea+=(ot+1)*yi}zi=Oe/Wi*1e3,xa=It(Gi,{...Vr,segmentNumber:_r.toString(10),segmentTime:Oe.toString(10)});let Or={time:{from:zi,to:1/0},url:xa},_t={type:"template",baseUrl:gi,segmentTemplateUrl:Gi,initUrl:"",totalSegmentsDurationMs:Ea,segments:Ia,nextSegmentBeyondManifest:Or,timescale:Wi};va={id:Zt,kind:"text",segmentReference:_t,profiles:[],duration:g,bitrate:ya,mime:"",codecs:"",width:0,height:0,isAuto:Sa}}else va={id:Zt,isAuto:Sa,kind:"text",url:gi}}else{let Zt=(Cc=(Dc=de.getAttribute("contentType"))!=null?Dc:Jt==null?void 0:Jt.split("/")[0])!=null?Cc:So,Sa=(Vc=(Bc=fe.getAttribute("profiles"))==null?void 0:Bc.split(","))!=null?Vc:[],vi=parseInt((_c=de.getAttribute("width"))!=null?_c:"",10),Vr=parseInt((Oc=de.getAttribute("height"))!=null?Oc:"",10),ya=parseInt((Fc=de.getAttribute("bandwidth"))!=null?Fc:"",10)/1e3,Ta=(Nc=de.getAttribute("frameRate"))!=null?Nc:"",Wi=(qc=de.getAttribute("quality"))!=null?qc:void 0,yo=Ta?LS(Ta):void 0,Gi=(Uc=de.getAttribute("id"))!=null?Uc:"id"+(_++).toString(10),Ia=Zt==="video"?`${Vr}p`:Zt==="audio"?`${ya}Kbps`:ga,Ea=`${Gi}@${Ia}`,xa=[...N,...$y,...Sa],zi,_r=de.querySelector("SegmentBase"),Oe=(Hc=de.querySelector("SegmentTemplate"))!=null?Hc:Dy;if(_r){let _t=(Qc=(jc=de.querySelector("SegmentBase Initialization"))==null?void 0:jc.getAttribute("range"))!=null?Qc:"",[ft,Si]=_t.split("-").map(ii=>parseInt(ii,10)),ot={from:ft,to:Si},ei=(Wc=de.querySelector("SegmentBase"))==null?void 0:Wc.getAttribute("indexRange"),[yi,ti]=ei?ei.split("-").map(ii=>parseInt(ii,10)):[],Et=ei?{from:yi,to:ti}:void 0;zi={type:"byteRange",url:gi,initRange:ot,indexRange:Et}}else if(Oe){let _t={representationId:(Gc=de.getAttribute("id"))!=null?Gc:void 0,bandwidth:(zc=de.getAttribute("bandwidth"))!=null?zc:void 0},ft=parseInt((Yc=Oe.getAttribute("timescale"))!=null?Yc:"",10),Si=(Kc=Oe.getAttribute("initialization"))!=null?Kc:"",ot=Oe.getAttribute("media"),ei=(Jc=parseInt((Xc=Oe.getAttribute("startNumber"))!=null?Xc:"",10))!=null?Jc:1,yi=It(Si,_t);if(!ot)throw new ReferenceError("No media attribute in SegmentTemplate");let ti=(Zc=Oe.querySelectorAll("SegmentTimeline S"))!=null?Zc:[],Et=[],ii=0,Yi="",Fr=0;if(ti.length){let wa=ei,mt=0;for(let Ki of ti){let xt=parseInt((ed=Ki.getAttribute("d"))!=null?ed:"",10),Ti=parseInt((td=Ki.getAttribute("r"))!=null?td:"",10)||0,Aa=parseInt((id=Ki.getAttribute("t"))!=null?id:"",10);mt=Number.isFinite(Aa)?Aa:mt;let To=xt/ft*1e3,Io=mt/ft*1e3;for(let Pa=0;Pa<Ti+1;Pa++){let Vy=It(ot,{..._t,segmentNumber:wa.toString(10),segmentTime:(mt+Pa*xt).toString(10)}),ad=(Io!=null?Io:0)+Pa*To,_y=ad+To;wa++,Et.push({time:{from:ad,to:_y},url:Vy})}mt+=(Ti+1)*xt,ii+=(Ti+1)*To}Fr=mt/ft*1e3,Yi=It(ot,{..._t,segmentNumber:wa.toString(10),segmentTime:mt.toString(10)})}else if((0,Xs.isNonNullable)(g)){let mt=parseInt((rd=Oe.getAttribute("duration"))!=null?rd:"",10)/ft*1e3,Ki=Math.ceil(g/mt),xt=0;for(let Ti=1;Ti<Ki;Ti++){let Aa=It(ot,{..._t,segmentNumber:Ti.toString(10),segmentTime:xt.toString(10)});Et.push({time:{from:xt,to:xt+mt},url:Aa}),xt+=mt}Fr=xt,Yi=It(ot,{..._t,segmentNumber:Ki.toString(10),segmentTime:xt.toString(10)})}let By={time:{from:Fr,to:1/0},url:Yi};zi={type:"template",baseUrl:gi,segmentTemplateUrl:ot,initUrl:yi,totalSegmentsDurationMs:ii,segments:Et,nextSegmentBeyondManifest:By,timescale:ft}}else throw new ReferenceError("Unknown MPD segment referencing type");if(!Zt||!Jt)continue;let Or={video:"video",audio:"audio",text:"text"}[Zt];if(!Or)continue;Qi||(Qi=Or),va={id:Ea,kind:Or,segmentReference:zi,profiles:xa,duration:g,bitrate:ya,mime:Jt,codecs:ga,width:vi,height:Vr,fps:yo,quality:Wi}}we.language||(we.language=Xt),we.label||(we.label=Br),we.mime||(we.mime=Jt),we.codecs||(we.codecs=ga),we.hdr||(we.hdr=Qi==="video"&&Ql(ga)),we.representations.push(va)}if(Qi){let de=r[Qi].find(Xt=>Xt.id===we.id);if(de&&we.representations.every(Xt=>Xt.segmentReference.type==="template"))for(let Xt of de.representations){let Br=we.representations.find(Jt=>Jt.id===Xt.id),ba=Br==null?void 0:Br.segmentReference,gi=Xt.segmentReference;gi.segments.push(...ba.segments),gi.nextSegmentBeyondManifest=ba.nextSegmentBeyondManifest}else r[Qi].push(we)}}return{duration:g,streams:r,baseUrls:n,live:S}};var zl=G(yt(),1);var VS=require("@vkontakte/videoplayer-shared/es2018"),_S=({id:s,width:e,height:t,bitrate:i,fps:r,quality:a,streamId:n})=>{var u;let o=(u=a?ui(a):void 0)!=null?u:(0,VS.videoSizeToQuality)({width:e,height:t});return o&&{id:s,quality:o,bitrate:i,size:{width:e,height:t},fps:r,streamId:n}},OS=({id:s,bitrate:e})=>({id:s,bitrate:e}),FS=({language:s,label:e},{id:t,url:i,isAuto:r})=>({id:t,url:i,isAuto:r,type:"internal",language:s,label:e}),NS=({language:s,label:e,id:t,url:i,isAuto:r})=>({id:t,url:i,isAuto:r,type:"internal",language:s,label:e}),Yl=({id:s,language:e,label:t,codecs:i,isDefault:r})=>({id:s,language:e,label:t,codec:(0,zl.default)(i.split("."),0),isDefault:r}),Kl=({id:s,language:e,label:t,hdr:i,codecs:r})=>({id:s,language:e,hdr:i,label:t,codec:(0,zl.default)(r.split("."),0)}),Xl=s=>"url"in s,st=s=>s.type==="template";var Jl=require("@vkontakte/videoplayer-shared/es2018"),J=(s,e)=>(0,Jl.isNonNullable)(s)&&(0,Jl.isNonNullable)(e)&&s.readyState==="open"&&s$(s,e);function s$(s,e){for(let t=0;t<s.activeSourceBuffers.length;++t)if(s.activeSourceBuffers[t]===e)return!0;return!1}var Js=class{constructor(e,t,i,{fetcher:r,tuning:a,getCurrentPosition:n,isActiveLowLatency:o,compatibilityMode:u=!1,manifest:l}){this.currentLiveSegmentServerLatency$=new R.ValueSubject(0);this.currentLowLatencySegmentLength$=new R.ValueSubject(0);this.currentSegmentLength$=new R.ValueSubject(0);this.onLastSegment$=new R.ValueSubject(!1);this.fullyBuffered$=new R.ValueSubject(!1);this.playingRepresentation$=new R.ValueSubject(void 0);this.playingRepresentationInit$=new R.ValueSubject(void 0);this.error$=new R.Subject;this.gaps=[];this.subscription=new R.Subscription;this.allInitsLoaded=!1;this.activeSegments=new Set;this.downloadAbortController=new ce;this.switchAbortController=new ce;this.destroyAbortController=new ce;this.bufferLimit=1/0;this.failedDownloads=0;this.baseUrls=[];this.baseUrlsIndex=0;this.isLive=!1;this.liveUpdateSegmentIndex=0;this.liveInitialAdditionalOffset=0;this.isSeekingLive=!1;this.index=0;this.lastDataObtainedTimestampMs=0;this.loadByteRangeSegmentsTimeoutId=0;this.startWith=(0,R.abortable)(this.destroyAbortController.signal,async function*(e){let t=this.representations.get(e);(0,R.assertNonNullable)(t,`Cannot find representation ${e}`),this.playingRepresentationId=e,this.downloadingRepresentationId=e,this.sourceBuffer=this.mediaSource.addSourceBuffer(`${t.mime}; codecs="${t.codecs}"`),this.sourceBufferTaskQueue=new Cv(this.sourceBuffer),this.subscription.add((0,R.fromEvent)(this.sourceBuffer,"updateend").subscribe(()=>{this.checkEjectedSegments(),this.maintain()},n=>{let o,u=this.mediaSource.readyState;u!=="open"&&(o={id:`SegmentEjection_source_${u}`,category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when trying to clear segments ejected by browser",thrown:n}),o!=null||(o={id:"SegmentEjection",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when trying to clear segments ejected by browser",thrown:n}),this.error$.next(o)})),this.subscription.add((0,R.fromEvent)(this.sourceBuffer,"error").subscribe(()=>this.error$.next({id:"SourceBuffer",category:R.ErrorCategory.VIDEO_PIPELINE,message:"SourceBuffer Error event fired"}))),this.subscription.add(this.sourceBufferTaskQueue.bufferFull$.subscribe(n=>{let o=this.getCurrentPosition();if(!this.sourceBuffer||!o||!J(this.mediaSource,this.sourceBuffer))return;let u=Math.min(this.bufferLimit,Er(this.sourceBuffer.buffered)*.8);this.bufferLimit=u;let l=this.getForwardBufferDuration(o),c=Math.min(this.forwardBufferTarget,this.bufferLimit)*this.tuning.dash.minSafeBufferThreshold;this.pruneBuffer(o,n*2,l<c).catch(d=>{this.handleAsyncError(d,"pruneBuffer")})})),this.subscription.add(this.sourceBufferTaskQueue.error$.subscribe(n=>this.error$.next(n))),yield this.loadInit(t,"high",!0);let i=this.initData.get(t.id),r=this.segments.get(t.id),a=this.parsedInitData.get(t.id);(0,R.assertNonNullable)(i,"No init buffer for starting representation"),(0,R.assertNonNullable)(r,"No segments for starting representation"),i instanceof ArrayBuffer&&(this.searchGaps(r,t),yield this.sourceBufferTaskQueue.append(i,this.destroyAbortController.signal),this.playingRepresentation$.next(this.playingRepresentationId),this.playingRepresentationInit$.next(a))}.bind(this));this.switchTo=(0,R.abortable)(this.destroyAbortController.signal,async function*(e,t=!1){if(!J(this.mediaSource,this.sourceBuffer)||e===this.downloadingRepresentationId||e===this.switchingToRepresentationId)return;this.switchingToRepresentationId=e;let i=this.representations.get(e);(0,R.assertNonNullable)(i,`No such representation ${e}`);let r=this.segments.get(e),a=this.initData.get(e);if((0,R.isNullable)(a)||(0,R.isNullable)(r)?yield this.loadInit(i,"high",!1):a instanceof Promise&&(yield a),r=this.segments.get(e),(0,R.assertNonNullable)(r,"No segments for starting representation"),a=this.initData.get(e),!(!a||!(a instanceof ArrayBuffer)||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(yield this.abort(),yield this.sourceBufferTaskQueue.append(a,this.downloadAbortController.signal),t)this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e,yield this.dropBuffer();else{let n=this.getCurrentPosition();(0,R.isNonNullable)(n)&&!this.isLive&&(this.bufferLimit=1/0,await this.pruneBuffer(n,1/0,!0)),this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e}this.maintain()}}.bind(this));this.switchToOld=(0,R.abortable)(this.destroyAbortController.signal,async function*(e,t=!1){if(!J(this.mediaSource,this.sourceBuffer)||e===this.downloadingRepresentationId||e===this.switchingToRepresentationId)return;this.switchingToRepresentationId=e;let i=this.representations.get(e);(0,R.assertNonNullable)(i,`No such representation ${e}`);let r=this.segments.get(e),a=this.initData.get(e);if((0,R.isNullable)(a)||(0,R.isNullable)(r)?yield this.loadInit(i,"high",!1):a instanceof Promise&&(yield a),r=this.segments.get(e),(0,R.assertNonNullable)(r,"No segments for starting representation"),a=this.initData.get(e),!(!a||!(a instanceof ArrayBuffer)||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)))if(yield this.abort(),yield this.sourceBufferTaskQueue.append(a,this.downloadAbortController.signal),t)this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e,yield this.dropBuffer(),this.maintain();else{let n=this.getCurrentPosition();(0,R.isNonNullable)(n)&&(this.isLive||(this.bufferLimit=1/0,await this.pruneBuffer(n,1/0,!0)),this.maintain(n)),this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=e}}.bind(this));this.seekLive=(0,R.abortable)(this.destroyAbortController.signal,async function*(e){var u,l;let t=(u=(0,Bn.default)(e,c=>c.representations))!=null?u:[];if(this.isSeekingLive=!0,!this.downloadingRepresentationId||!t)return;for(let c of this.representations.keys()){let d=t.find(h=>h.id===c);d&&this.representations.set(c,d);let f=this.representations.get(c);if(!f||!st(f.segmentReference))return;let p=this.getActualLiveStartingSegments(f.segmentReference);this.segments.set(f.id,p)}let i=(l=this.switchingToRepresentationId)!=null?l:this.downloadingRepresentationId,r=this.representations.get(i);(0,R.assertNonNullable)(r);let a=this.segments.get(i);(0,R.assertNonNullable)(a,"No segments for starting representation");let n=this.initData.get(i);if((0,R.assertNonNullable)(n,"No init buffer for starting representation"),!(n instanceof ArrayBuffer))return;let o=this.getDebugBufferState();this.liveUpdateSegmentIndex=0,yield this.abort(),o&&(yield this.sourceBufferTaskQueue.remove(o.from*1e3,o.to*1e3,this.destroyAbortController.signal)),this.searchGaps(a,r),yield this.sourceBufferTaskQueue.append(n,this.destroyAbortController.signal),this.isSeekingLive=!1}.bind(this));var c;this.fetcher=r,this.tuning=a,this.compatibilityMode=u,this.forwardBufferTarget=a.dash.forwardBufferTargetAuto,this.getCurrentPosition=n,this.isActiveLowLatency=o,this.isLive=!!(l!=null&&l.live),this.baseUrls=(c=l==null?void 0:l.baseUrls)!=null?c:[],this.initData=new Map(i.map(d=>[d.id,null])),this.segments=new Map,this.parsedInitData=new Map,this.representations=new Map(i.map(d=>[d.id,d])),this.kind=e,this.mediaSource=t,this.sourceBuffer=null}switchToWithPreviousAbort(e,t=!1){!J(this.mediaSource,this.sourceBuffer)||e===this.downloadingRepresentationId||e===this.switchingToRepresentationId||(this.switchAbortController.abort(),this.switchAbortController=new ce,(0,R.abortable)(this.switchAbortController.signal,async function*(i,r=!1){this.switchingToRepresentationId=i;let a=this.representations.get(i);(0,R.assertNonNullable)(a,`No such representation ${i}`);let n=this.segments.get(i),o=this.initData.get(i);if((0,R.isNullable)(o)||(0,R.isNullable)(n)?yield this.loadInit(a,"high",!1):o instanceof Promise&&(yield o),n=this.segments.get(i),(0,R.assertNonNullable)(n,"No segments for starting representation"),o=this.initData.get(i),!(!(o instanceof ArrayBuffer)||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(yield this.abort(),yield this.sourceBufferTaskQueue.append(o,this.downloadAbortController.signal),r)this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=i,yield this.dropBuffer();else{let u=this.getCurrentPosition();(0,R.isNonNullable)(u)&&!this.isLive&&(this.bufferLimit=this.forwardBufferTarget,yield this.pruneBuffer(u,1/0,!0)),this.downloadingRepresentationId=i,this.switchingToRepresentationId=void 0}this.maintain()}}.bind(this))(e,t))}warmUpMediaSource(){!(0,R.isNullable)(this.sourceBuffer)&&!this.sourceBuffer.updating&&(this.sourceBuffer.mode="segments")}async abort(){for(let e of this.activeSegments)this.abortSegment(e.segment);return this.activeSegments.clear(),this.downloadAbortController.abort(),this.downloadAbortController=new ce,this.abortBuffer()}maintain(e=this.getCurrentPosition()){if((0,R.isNullable)(e)||(0,R.isNullable)(this.downloadingRepresentationId)||(0,R.isNullable)(this.playingRepresentationId)||(0,R.isNullable)(this.sourceBuffer)||!J(this.mediaSource,this.sourceBuffer)||(0,R.isNonNullable)(this.switchingToRepresentationId)||this.isSeekingLive)return;let t=this.representations.get(this.downloadingRepresentationId),i=this.segments.get(this.downloadingRepresentationId);if((0,R.assertNonNullable)(t,`No such representation ${this.downloadingRepresentationId}`),!i)return;let r=i.find(c=>e>=c.time.from&&e<c.time.to);(0,R.isNonNullable)(r)&&isFinite(r.time.from)&&isFinite(r.time.to)&&this.currentSegmentLength$.next((r==null?void 0:r.time.to)-r.time.from);let a=e,n=100;if(this.playingRepresentationId!==this.downloadingRepresentationId){let c=this.getForwardBufferDuration(e),d=r?r.time.to+n:-1/0;r&&r.time.to-e<this.tuning.dash.maxSegmentDurationLeftToSelectNextSegment&&c>=r.time.to-e+n&&(a=d)}if(isFinite(this.bufferLimit)&&Er(this.sourceBuffer.buffered)>=this.bufferLimit){let c=this.getForwardBufferDuration(e),d=Math.min(this.forwardBufferTarget,this.bufferLimit)*this.tuning.dash.minSafeBufferThreshold;this.pruneBuffer(e,1/0,c<d).catch(f=>{this.handleAsyncError(f,"pruneBuffer")});return}let u=[];if(!this.activeSegments.size&&(u=this.selectForwardBufferSegments(i,t.segmentReference.type,a),u.length)){let c="auto";if(this.tuning.dash.useFetchPriorityHints&&r)if((0,Cn.default)(u,r))c="high";else{let d=(0,Oi.default)(u,0);d&&d.time.from-r.time.to>=this.forwardBufferTarget/2&&(c="low")}this.loadSegments(u,t,c).catch(d=>{this.handleAsyncError(d,"loadSegments")})}(!this.preloadOnly&&!this.allInitsLoaded&&r&&r.status==="fed"&&!u.length&&this.getForwardBufferDuration(e)>3e3||this.isActiveLowLatency())&&this.loadNextInit();let l=(0,Oi.default)(i,-1);!this.isLive&&l&&(this.fullyBuffered$.next(l.time.to-e-this.getForwardBufferDuration(e)<n),this.onLastSegment$.next(e-l.time.from>0))}get lastDataObtainedTimestamp(){return this.lastDataObtainedTimestampMs}searchGaps(e,t){this.gaps=[];let i=0,r=this.isLive?this.liveInitialAdditionalOffset:0;for(let a of e)Math.trunc(a.time.from-i)>0&&this.gaps.push({representation:t.id,from:i,to:a.time.from+r}),i=a.time.to;(0,R.isNonNullable)(t.duration)&&t.duration-i>0&&!this.isLive&&this.gaps.push({representation:t.id,from:i,to:t.duration})}getActualLiveStartingSegments(e){let t=e.segments,i=this.isActiveLowLatency()?this.tuning.dashCmafLive.lowLatency.maxTargetOffset:this.tuning.dashCmafLive.maxActiveLiveOffset,r=[],a=0,n=t.length-1;do r.unshift(t[n]),a+=t[n].time.to-t[n].time.from,n--;while(a<i&&n>=0);return this.liveInitialAdditionalOffset=a-i,this.isActiveLowLatency()?[r[0]]:r}getLiveSegmentsToLoadState(e){let t=(0,Bn.default)(e==null?void 0:e.streams[this.kind],r=>r.representations).find(r=>r.id===this.downloadingRepresentationId);if(!t)return;let i=this.segments.get(t.id);if(i!=null&&i.length)return{from:i[0].time.from,to:i[i.length-1].time.to}}updateLive(e){var i,r,a,n;let t=(i=(0,Bn.default)(e==null?void 0:e.streams[this.kind],o=>o.representations))!=null?i:[];if(![...this.segments.values()].every(o=>!o.length))for(let o of t){if(!o||!st(o.segmentReference))return;let u=o.segmentReference.segments.map(p=>({...p,status:"none",size:void 0})),l=100,c=(r=this.segments.get(o.id))!=null?r:[],d=(n=(a=(0,Oi.default)(c,-1))==null?void 0:a.time.to)!=null?n:0,f=u==null?void 0:u.findIndex(p=>d>=p.time.from+l&&d<=p.time.to+l);if(f===-1){this.liveUpdateSegmentIndex=0;let p=this.getActualLiveStartingSegments(o.segmentReference);this.segments.set(o.id,p)}else{let p=u.slice(f+1);this.segments.set(o.id,[...c,...p])}}}proceedLowLatencyLive(){let e=this.downloadingRepresentationId;(0,R.assertNonNullable)(e);let t=this.segments.get(e);if(t!=null&&t.length){let i=t[t.length-1];this.updateLowLatencyLiveIfNeeded(i)}}calculateDurationFromSegments(){var t;if(!this.playingRepresentationId)return 0;let e=this.segments.get(this.playingRepresentationId);return(e?(t=(0,Oi.default)(e,-1))==null?void 0:t.time.to:0)||0}updateLowLatencyLiveIfNeeded(e){var i;let t=0;for(let r of this.representations.values()){let a=r.segmentReference;if(!st(a))return;let n=(i=this.segments.get(r.id))!=null?i:[],o=n.find(l=>Math.floor(l.time.from)===Math.floor(e.time.from));if(o&&!isFinite(o.time.to)&&(o.time.to=e.time.to,t=o.time.to-o.time.from),!!!n.find(l=>Math.floor(l.time.from)===Math.floor(e.time.to))&&this.isActiveLowLatency()){let l=Math.round(e.time.to*a.timescale/1e3).toString(10),c=It(a.segmentTemplateUrl,{segmentTime:l});n.push({status:"none",time:{from:e.time.to,to:1/0},url:c})}}this.currentLowLatencySegmentLength$.next(t)}findSegmentStartTime(e){var a,n,o;let t=(n=(a=this.switchingToRepresentationId)!=null?a:this.downloadingRepresentationId)!=null?n:this.playingRepresentationId;if(!t)return;let i=this.segments.get(t);if(!i)return;let r=i.find(u=>u.time.from<=e&&u.time.to>=e);return(o=r==null?void 0:r.time.from)!=null?o:void 0}setTarget(e){this.forwardBufferTarget=e}setPreloadOnly(e){this.preloadOnly=e}destroy(){var e;if(this.initData.clear(),this.segments.clear(),this.parsedInitData.clear(),this.representations.clear(),(e=this.sourceBufferTaskQueue)==null||e.destroy(),this.gapDetectionIdleCallback&&Mt&&Mt(this.gapDetectionIdleCallback),this.initLoadIdleCallback&&Mt&&Mt(this.initLoadIdleCallback),this.subscription.unsubscribe(),this.sourceBuffer)try{this.mediaSource.removeSourceBuffer(this.sourceBuffer)}catch(t){if(!(t instanceof DOMException&&t.name==="NotFoundError"))throw t}this.sourceBuffer=null,this.downloadAbortController.abort(),this.switchAbortController.abort(),this.destroyAbortController.abort(),window.clearTimeout(this.loadByteRangeSegmentsTimeoutId)}selectForwardBufferSegments(e,t,i){return this.isLive?this.selectForwardBufferSegmentsLive(e,i):this.selectForwardBufferSegmentsRecord(e,t,i)}selectForwardBufferSegmentsLive(e,t){let i=e.findIndex(r=>t>=r.time.from&&t<r.time.to);return this.playingRepresentationId!==this.downloadingRepresentationId&&(this.liveUpdateSegmentIndex=i),this.liveUpdateSegmentIndex<e.length?e.slice(this.liveUpdateSegmentIndex++):[]}selectForwardBufferSegmentsRecord(e,t,i){let r=this.getForwardBufferDuration(i),a=e.findIndex(({status:f,time:{from:p,to:h}},b)=>{let S=p<=i&&h>=i,g=p>i||S||b===0&&i===0,I=Math.min(this.forwardBufferTarget,this.bufferLimit),w=this.preloadOnly&&p<=i+I||r<I&&h-p>=I||h<=i+I;return(f==="none"||f==="partially_ejected"&&g&&w&&this.sourceBuffer&&J(this.mediaSource,this.sourceBuffer)&&!(_e(this.sourceBuffer.buffered,p)&&_e(this.sourceBuffer.buffered,h)))&&g&&w});if(a===-1)return[];if(t!=="byteRange")return e.slice(a,a+1);let n=e,o=0,u=0,l=[],c=this.preloadOnly?0:this.tuning.dash.segmentRequestSize,d=this.preloadOnly?this.forwardBufferTarget:0;for(let f=a;f<n.length&&(o<=c||u<=d);f++){let p=n[f];if(o+=p.byte.to+1-p.byte.from,u+=p.time.to+1-p.time.from,p.status==="none"||p.status==="partially_ejected")l.push(p);else break}return l}async loadSegments(e,t,i="auto"){st(t.segmentReference)?await this.loadTemplateSegment(e[0],t,i):await this.loadByteRangeSegments(e,t,i)}async loadTemplateSegment(e,t,i="auto"){e.status="downloading";let r={segment:e,loadedBytes:0,feedingBytes:0,fedBytes:0,representationId:t.id};this.activeSegments.add(r);let{range:a,url:n,signal:o,onProgress:u,onProgressTasks:l}=this.prepareTemplateFetchSegmentParams(e,t);this.failedDownloads&&o&&(await(0,R.abortable)(o,async function*(){let c=(0,R.getExponentialDelay)(this.failedDownloads,this.tuning.downloadBackoff);yield new Promise(d=>setTimeout(d,c))}.bind(this))(),o.aborted&&this.abortActiveSegments([e]));try{let c=await this.fetcher.fetch(n,{range:a,signal:o,onProgress:u,priority:i,isLowLatency:this.isActiveLowLatency(),bufferOptimisation:this.tuning.dash.fetcherBufferOptimisation});if(this.lastDataObtainedTimestampMs=(0,R.now)(),!c)return;let d=new DataView(c),f=Dt(t.mime);if(!isFinite(r.segment.time.to)){let b=t.segmentReference.timescale;r.segment.time.to=f.getChunkEndTime(d,b)}u&&r.feedingBytes&&l?await Promise.all(l):await this.sourceBufferTaskQueue.append(d,o);let{serverDataReceivedTimestamp:p,serverDataPreparedTime:h}=f.getServerLatencyTimestamps(d);p&&h&&this.currentLiveSegmentServerLatency$.next(h-p),r.segment.status="downloaded",this.onSegmentFullyAppended(r,t.id),this.failedDownloads=0}catch(c){this.abortActiveSegments([e]),Ct(c)||(this.failedDownloads++,this.updateRepresentationsBaseUrlIfNeeded())}}updateRepresentationsBaseUrlIfNeeded(){if(!this.tuning.dash.enableBaseUrlSupport||!this.baseUrls.length||this.failedDownloads<=this.tuning.dash.maxSegmentRetryCount)return;this.baseUrlsIndex=(this.baseUrlsIndex+1)%this.baseUrls.length;let e=this.baseUrls[this.baseUrlsIndex];for(let t of this.representations.values())st(t.segmentReference)?t.segmentReference.baseUrl=e:t.segmentReference.url=e}async loadByteRangeSegments(e,t,i="auto"){if(!e.length)return;for(let u of e)u.status="downloading",this.activeSegments.add({segment:u,loadedBytes:0,feedingBytes:0,fedBytes:0,representationId:t.id});let{range:r,url:a,signal:n,onProgress:o}=this.prepareByteRangeFetchSegmentParams(e,t);this.failedDownloads&&n&&(await(0,R.abortable)(n,async function*(){let u=(0,R.getExponentialDelay)(this.failedDownloads,this.tuning.downloadBackoff);yield new Promise(l=>{this.loadByteRangeSegmentsTimeoutId=window.setTimeout(l,u),(0,R.fromEvent)(window,"online").pipe((0,R.once)()).subscribe(()=>{l(),window.clearTimeout(this.loadByteRangeSegmentsTimeoutId)})})}.bind(this))(),n.aborted&&this.abortActiveSegments(e));try{await this.fetcher.fetch(a,{range:r,onProgress:o,signal:n,priority:i,bufferOptimisation:this.tuning.dash.fetcherBufferOptimisation}),this.lastDataObtainedTimestampMs=(0,R.now)(),this.failedDownloads=0}catch(u){this.abortActiveSegments(e),Ct(u)||(this.failedDownloads++,this.updateRepresentationsBaseUrlIfNeeded())}}prepareByteRangeFetchSegmentParams(e,t){if(st(t.segmentReference))throw new Error("Representation is not byte range type");let i=t.segmentReference.url,r={from:(0,Oi.default)(e,0).byte.from,to:(0,Oi.default)(e,-1).byte.to},{signal:a}=this.downloadAbortController;return{url:i,range:r,signal:a,onProgress:async(o,u)=>{if(!a.aborted)try{this.lastDataObtainedTimestampMs=(0,R.now)(),await this.onSomeByteRangesDataLoaded({dataView:o,loaded:u,signal:a,onSegmentAppendFailed:()=>this.abort(),globalFrom:r?r.from:0,representationId:t.id})}catch(l){this.error$.next({id:"SegmentFeeding",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when feeding segments",thrown:l})}}}}prepareTemplateFetchSegmentParams(e,t){if(!st(t.segmentReference))throw new Error("Representation is not template type");let i=new URL(e.url,t.segmentReference.baseUrl);this.isActiveLowLatency()&&i.searchParams.set("low-latency","yes");let r=i.toString(),{signal:a}=this.downloadAbortController,n=[],u=this.isActiveLowLatency()||this.tuning.dash.enableSubSegmentBufferFeeding&&this.liveUpdateSegmentIndex<3?(l,c)=>{if(!a.aborted)try{this.lastDataObtainedTimestampMs=(0,R.now)();let d=this.onSomeTemplateDataLoaded({dataView:l,loaded:c,signal:a,onSegmentAppendFailed:()=>this.abort(),representationId:t.id});n.push(d)}catch(d){this.error$.next({id:"SegmentFeeding",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Error when feeding segments",thrown:d})}}:void 0;return{url:r,signal:a,onProgress:u,onProgressTasks:n}}abortActiveSegments(e){for(let t of this.activeSegments)(0,Cn.default)(e,t.segment)&&this.abortSegment(t.segment)}async onSomeTemplateDataLoaded({dataView:e,representationId:t,loaded:i,onSegmentAppendFailed:r,signal:a}){if(!this.activeSegments.size||!J(this.mediaSource,this.sourceBuffer))return;let n=this.representations.get(t);if(n)for(let o of this.activeSegments){let{segment:u}=o;if(o.representationId===t){if(a.aborted){r();continue}if(o.loadedBytes=i,o.loadedBytes>o.feedingBytes){let l=new DataView(e.buffer,e.byteOffset+o.feedingBytes,o.loadedBytes-o.feedingBytes),c=Dt(n.mime).parseFeedableSegmentChunk(l,this.isLive);c!=null&&c.byteLength&&(u.status="partially_fed",o.feedingBytes+=c.byteLength,await this.sourceBufferTaskQueue.append(c),o.fedBytes+=c.byteLength)}}}}async onSomeByteRangesDataLoaded({dataView:e,representationId:t,globalFrom:i,loaded:r,signal:a,onSegmentAppendFailed:n}){if(!this.activeSegments.size||!J(this.mediaSource,this.sourceBuffer))return;let o=this.representations.get(t);if(o)for(let u of this.activeSegments){let{segment:l}=u;if(u.representationId!==t)continue;if(a.aborted){await n();continue}let c=l.byte.from-i,d=l.byte.to-i,f=d-c+1,p=c<r,h=d<=r;if(!p)continue;let b=Dt(o.mime);if(l.status==="downloading"&&h){l.status="downloaded";let S=new DataView(e.buffer,e.byteOffset+c,f);await this.sourceBufferTaskQueue.append(S,a)&&!a.aborted?this.onSegmentFullyAppended(u,t):await n()}else if(this.tuning.dash.enableSubSegmentBufferFeeding&&(l.status==="downloading"||l.status==="partially_fed")&&(u.loadedBytes=Math.min(f,r-c),u.loadedBytes>u.feedingBytes)){let S=new DataView(e.buffer,e.byteOffset+c+u.feedingBytes,u.loadedBytes-u.feedingBytes),g=u.loadedBytes===f?S:b.parseFeedableSegmentChunk(S);g!=null&&g.byteLength&&(l.status="partially_fed",u.feedingBytes+=g.byteLength,await this.sourceBufferTaskQueue.append(g,a)&&!a.aborted?(u.fedBytes+=g.byteLength,u.fedBytes===f&&this.onSegmentFullyAppended(u,t)):await n())}}}onSegmentFullyAppended(e,t){var i;if(!((0,R.isNullable)(this.sourceBuffer)||!J(this.mediaSource,this.sourceBuffer))){!this.isLive&&z.browser.isSafari&&this.tuning.useSafariEndlessRequestBugfix&&(_e(this.sourceBuffer.buffered,e.segment.time.from,100)&&_e(this.sourceBuffer.buffered,e.segment.time.to,100)||this.error$.next({id:"EmptyAppendBuffer",category:R.ErrorCategory.VIDEO_PIPELINE,message:"Browser stuck on empty result of adding segment to source buffer"})),this.playingRepresentationId=t,this.playingRepresentation$.next(this.playingRepresentationId),this.playingRepresentationInit$.next(this.parsedInitData.get(this.playingRepresentationId)),e.segment.status="fed",Xl(e.segment)&&(e.segment.size=e.fedBytes);for(let r of this.representations.values())if(r.id!==t)for(let a of(i=this.segments.get(r.id))!=null?i:[])a.status==="fed"&&Math.round(a.time.from)===Math.round(e.segment.time.from)&&Math.round(a.time.to)===Math.round(e.segment.time.to)&&(a.status="none");this.updateLowLatencyLiveIfNeeded(e.segment),this.activeSegments.delete(e),this.detectGapsWhenIdle(t,[e.segment])}}abortSegment(e){e.status==="partially_fed"?e.status="partially_ejected":e.status!=="partially_ejected"&&(e.status="none");for(let t of this.activeSegments.values())if(t.segment===e){this.activeSegments.delete(t);break}}loadNextInit(){if(this.allInitsLoaded||this.initLoadIdleCallback)return;let e=null,t=!1;for(let[r,a]of this.initData.entries()){let n=a instanceof Promise;t||(t=n),a===null&&(e=r)}if(!e){this.allInitsLoaded=!0;return}if(t)return;let i=this.representations.get(e);i&&(this.initLoadIdleCallback=Ir(()=>(0,qS.default)(this.loadInit(i,"low",!1),()=>this.initLoadIdleCallback=null)))}async loadInit(e,t="auto",i=!1){let r=this.tuning.dash.useFetchPriorityHints?t:"auto",n=(!i&&this.failedDownloads>0?(0,R.abortable)(this.destroyAbortController.signal,async function*(){let o=(0,R.getExponentialDelay)(this.failedDownloads,this.tuning.downloadBackoff);yield new Promise(u=>setTimeout(u,o))}.bind(this))():Promise.resolve()).then(()=>this.fetcher.fetchRepresentation(e.segmentReference,Dt(e.mime),r)).then(async o=>{if(!o)return;let{init:u,dataView:l,segments:c}=o,d=l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength);this.initData.set(e.id,d);let f=c;this.isLive&&st(e.segmentReference)&&(f=this.getActualLiveStartingSegments(e.segmentReference)),(!this.isLive||!this.segments.has(e.id))&&this.segments.set(e.id,f),u&&this.parsedInitData.set(e.id,u)}).then(()=>this.failedDownloads=0,o=>{this.initData.set(e.id,null),i&&this.error$.next({id:"LoadInits",category:R.ErrorCategory.WTF,message:"loadInit threw",thrown:o})});return this.initData.set(e.id,n),n}async dropBuffer(){for(let e of this.segments.values())for(let t of e)t.status="none";await this.pruneBuffer(0,1/0,!0)}async pruneBuffer(e,t,i=!1){if(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)||!this.playingRepresentationId||(0,R.isNullable)(e))return!1;let r=[],a=0,n=u=>{u.sort((c,d)=>c.from-d.from);let l=[u[0]];for(let c=1;c<u.length;c++){let{from:d,to:f}=u[c],p=l[l.length-1];p.to>=d?p.to=Math.max(p.to,f):l.push(u[c])}return l},o=u=>{var c;if(a>=t)return r;r.push({...u.time}),r=n(r);let l=Xl(u)?(c=u.size)!=null?c:0:u.byte.to-u.byte.from;a+=l};for(let u of this.segments.values())for(let l of u){let c=l.time.to<=e-this.tuning.dash.bufferPruningSafeZone,d=l.time.from>=e+Math.min(this.forwardBufferTarget,this.bufferLimit);(c||d)&&l.status==="fed"&&o(l)}for(let u=0;u<this.sourceBuffer.buffered.length;u++){let l=this.sourceBuffer.buffered.start(u)*1e3,c=this.sourceBuffer.buffered.end(u)*1e3,d=0;for(let f of this.segments.values())for(let p of f)(0,Cn.default)(["none","partially_ejected"],p.status)&&Math.round(p.time.from)<=Math.round(l)&&Math.round(p.time.to)>=Math.round(c)&&d++;if(d===this.segments.size){let f={time:{from:l,to:c},url:"",status:"none"};o(f)}}if(r.length&&i){let u=Math.min(this.forwardBufferTarget,this.bufferLimit)*this.tuning.dash.minSafeBufferThreshold;for(let l of this.segments.values())for(let c of l)c.time.from>=e+u&&c.status==="fed"&&o(c)}return r.length?(await Promise.all(r.map(l=>this.sourceBufferTaskQueue.remove(l.from,l.to)))).reduce((l,c)=>l||c,!1):!1}async abortBuffer(){if(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))return!1;let e=this.playingRepresentationId&&this.initData.get(this.playingRepresentationId),t=e instanceof ArrayBuffer?e:void 0;return this.sourceBufferTaskQueue.abort(t)}getDebugBufferState(){if(!(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)||!this.sourceBuffer.buffered.length))return{from:this.sourceBuffer.buffered.start(0),to:this.sourceBuffer.buffered.end(this.sourceBuffer.buffered.length-1)}}getForwardBufferDuration(e=this.getCurrentPosition()){return!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer)||!this.sourceBuffer.buffered.length||(0,R.isNullable)(e)?0:$e(this.sourceBuffer.buffered,e)}detectGaps(e,t){if(!(!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(this.tuning.useRefactoredSearchGap)for(let i=0;i<this.sourceBuffer.buffered.length;i++)this.gaps=this.gaps.filter(r=>this.sourceBuffer&&(Math.round(r.from)<Math.round(this.sourceBuffer.buffered.start(i)*1e3)||Math.round(r.to)>Math.round(this.sourceBuffer.buffered.end(i)*1e3)));for(let i of t){let r={representation:e,from:i.time.from,to:i.time.to};for(let a=0;a<this.sourceBuffer.buffered.length;a++){let n=this.sourceBuffer.buffered.start(a)*1e3,o=this.sourceBuffer.buffered.end(a)*1e3;if(!(o<=i.time.from||n>=i.time.to)){if(n<=i.time.from&&o>=i.time.to){r=void 0;break}o>i.time.from&&o<i.time.to&&(r.from=o),n<i.time.to&&n>i.time.from&&(r.to=n)}}r&&r.to-r.from>1&&!this.gaps.some(a=>r&&a.from===r.from&&a.to===r.to)&&this.gaps.push(r)}}}detectGapsWhenIdle(e,t){if(!(this.gapDetectionIdleCallback||!this.sourceBuffer||!J(this.mediaSource,this.sourceBuffer))){if(!this.tuning.useRefactoredSearchGap)for(let i=0;i<this.sourceBuffer.buffered.length;i++)this.gaps=this.gaps.filter(r=>this.sourceBuffer&&(Math.round(r.from)<Math.round(this.sourceBuffer.buffered.start(i)*1e3)||Math.round(r.to)>Math.round(this.sourceBuffer.buffered.end(i)*1e3)));this.gapDetectionIdleCallback=Ir(()=>{try{this.detectGaps(e,t)}catch(i){this.error$.next({id:"GapDetection",category:R.ErrorCategory.WTF,message:"detectGaps threw",thrown:i})}finally{this.gapDetectionIdleCallback=null}})}}checkEjectedSegments(){if((0,R.isNullable)(this.sourceBuffer)||!J(this.mediaSource,this.sourceBuffer)||(0,R.isNullable)(this.playingRepresentationId))return;let e=[];for(let i=0;i<this.sourceBuffer.buffered.length;i++){let r=Math.floor(this.sourceBuffer.buffered.start(i)*1e3),a=Math.ceil(this.sourceBuffer.buffered.end(i)*1e3);e.push({from:r,to:a})}let t=100;for(let i of this.segments.values())for(let r of i){let{status:a}=r;if(a!=="fed"&&a!=="partially_ejected")continue;let n=Math.floor(r.time.from),o=Math.ceil(r.time.to),u=e.some(c=>c.from-t<=n&&c.to+t>=o),l=e.filter(c=>n>=c.from&&n<c.to-t||o>c.from+t&&o<=c.to);u||(l.length===1?r.status="partially_ejected":this.gaps.some(c=>c.from===r.time.from||c.to===r.time.to)?r.status="partially_ejected":r.status="none")}}handleAsyncError(e,t){this.error$.next({id:t,category:R.ErrorCategory.VIDEO_PIPELINE,thrown:e,message:"Something went wrong"})}};var pi=s=>{let e=new URL(s);return e.searchParams.set("quic","1"),e.toString()};var Vn=s=>{var a;let e=s.get("X-Delivery-Type"),t=s.get("X-Reused"),i=e===null?"http1":e!=null?e:void 0,r=t===null?void 0:(a={1:!0,0:!1}[t])!=null?a:void 0;return{type:i,reused:r}};var Y=require("@vkontakte/videoplayer-shared/es2018");var _n=s=>{let e=new URL(s);return e.searchParams.set("enable-subtitles","yes"),e.toString()};var Fn=class{constructor({throughputEstimator:e,requestQuic:t,tracer:i,compatibilityMode:r=!1,useEnableSubtitlesParam:a=!1}){this.manifestRequested=new Y.Subject;this.manifestReceived=new Y.Subject;this.firstBytesRequested=new Y.Subject;this.firstBytesReceived=new Y.Subject;this.lastConnectionType$=new Y.ValueSubject(void 0);this.lastConnectionReused$=new Y.ValueSubject(void 0);this.lastRequestFirstBytes$=new Y.ValueSubject(void 0);this.recoverableError$=new Y.Subject;this.error$=new Y.Subject;this.abortAllController=new ce;this.subscription=new Y.SubscriptionRemovable;this.fetchManifest=(0,Y.abortable)(this.abortAllController.signal,async function*(e){let t=this.tracer.createComponentTracer("FetchManifest"),i=e;this.requestQuic&&(i=pi(i)),!this.compatibilityMode&&this.useEnableSubtitlesParam&&(i=_n(i)),this.manifestRequested.next();let r=yield this.doFetch(i,{signal:this.abortAllController.signal}).catch(On);return r?(t.log("success",(0,Y.flattenObject)({url:i,message:"Request successfully executed"})),t.end(),this.manifestReceived.next(),this.onHeadersReceived(r.headers),r.text()):(t.error("error",(0,Y.flattenObject)({url:i,message:"No data in request manifest"})),t.end(),null)}.bind(this));this.fetch=(0,Y.abortable)(this.abortAllController.signal,async function*(e,{rangeMethod:t=this.compatibilityMode?0:1,range:i,onProgress:r,priority:a="auto",signal:n,measureThroughput:o=!0,isLowLatency:u=!1,bufferOptimisation:l=!1}={}){var W,ue,le;let c=e,d=new Headers,f=this.tracer.createComponentTracer("Fetch");if(i)switch(t){case 0:{d.append("Range",`bytes=${i.from}-${i.to}`);break}case 1:{let A=new URL(c,location.href);A.searchParams.append("bytes",`${i.from}-${i.to}`),c=A.toString();break}default:(0,Y.assertNever)(t)}this.requestQuic&&(c=pi(c));let p=this.abortAllController.signal,h;if(n){let A=new ce;if(h=(0,Y.merge)((0,Y.fromEvent)(this.abortAllController.signal,"abort"),(0,Y.fromEvent)(n,"abort")).subscribe(()=>{try{A.abort()}catch(V){On(V)}}),this.subscription.add(h),this.abortAllController.signal.aborted||n.aborted)try{A.abort()}catch(V){On(V)}p=A.signal}let b=0,S=(0,Y.now)();f.log("startRequest",(0,Y.flattenObject)({url:c,priority:a,rangeMethod:t,range:i,isLowLatency:u,requestStartedAt:S})),this.firstBytesRequested.next();let g=yield this.doFetch(c,{priority:a,headers:d,signal:p}),I=(0,Y.now)();if(!g)return f.error("error",{message:"No response in request"}),f.end(),this.unsubscribeAbortSubscription(h),null;if((W=this.throughputEstimator)==null||W.addRawRtt(I-S),!g.ok||!g.body){this.unsubscribeAbortSubscription(h);let A=`Fetch error ${g.status}: ${g.statusText}`;return f.error("error",{message:A}),f.end(),Promise.reject(new Error(`Fetch error ${g.status}: ${g.statusText}`))}if(this.onHeadersReceived(g.headers),!r&&!o){this.unsubscribeAbortSubscription(h);let A=(0,Y.now)(),V={requestStartedAt:S,requestEndedAt:A,duration:A-S};return f.log("endRequest",(0,Y.flattenObject)(V)),f.end(),g.arrayBuffer()}let w=g.body;if(o){let A;[w,A]=g.body.tee(),(ue=this.throughputEstimator)==null||ue.trackStream(A,u)}let E=w.getReader(),P,_=parseInt((le=g.headers.get("content-length"))!=null?le:"",10);Number.isFinite(_)&&(P=_),!P&&i&&(P=i.to-i.from+1);let N=P?new Uint8Array(P):new Uint8Array(0),F=!1,C=A=>{this.unsubscribeAbortSubscription(h),F=!0,On(A)},B=(0,Y.abortable)(p,async function*({done:A,value:V}){if(b===0&&(this.lastRequestFirstBytes$.next((0,Y.now)()-S),this.firstBytesReceived.next()),p.aborted){this.unsubscribeAbortSubscription(h);return}if(!A&&V){if(l&&P)N.set(V,b),b+=V.byteLength;else{let $=new Uint8Array(N.length+V.length);$.set(N),$.set(V,N.length),N=$,b+=V.byteLength}r==null||r(new DataView(N.buffer),b),yield E==null?void 0:E.read().then(B,C)}}.bind(this));yield E==null?void 0:E.read().then(B,C),this.unsubscribeAbortSubscription(h);let H=(0,Y.now)(),q={failed:F,requestStartedAt:S,requestEndedAt:H,duration:H-S};return F?(f.error("endRequest",(0,Y.flattenObject)(q)),f.end(),null):(f.log("endRequest",(0,Y.flattenObject)(q)),f.end(),N.buffer)}.bind(this));this.fetchByteRangeRepresentation=(0,Y.abortable)(this.abortAllController.signal,async function*(e,t,i){var g;if(e.type!=="byteRange")return null;let{from:r,to:a}=e.initRange,n=r,o=a,u=!1,l,c;e.indexRange&&(l=e.indexRange.from,c=e.indexRange.to,u=a+1===l,u&&(n=Math.min(l,r),o=Math.max(c,a))),n=Math.min(n,0);let d=yield this.fetch(e.url,{range:{from:n,to:o},priority:i,measureThroughput:!1});if(!d)return null;let f=new DataView(d,r-n,a-n+1);if(!t.validateData(f))throw new Error("Invalid media file");let p=t.parseInit(f),h=(g=e.indexRange)!=null?g:t.getIndexRange(p);if(!h)throw new ReferenceError("No way to load representation index");let b;if(u)b=new DataView(d,h.from-n,h.to-h.from+1);else{let I=yield this.fetch(e.url,{range:h,priority:i,measureThroughput:!1});if(!I)return null;b=new DataView(I)}let S=t.parseSegments(b,p,h);return{init:p,dataView:new DataView(d),segments:S}}.bind(this));this.fetchTemplateRepresentation=(0,Y.abortable)(this.abortAllController.signal,async function*(e,t){if(e.type!=="template")return null;let i=new URL(e.initUrl,e.baseUrl).toString(),r=yield this.fetch(i,{priority:t,measureThroughput:!1});return r?{init:null,segments:e.segments.map(n=>({...n,status:"none",size:void 0})),dataView:new DataView(r)}:null}.bind(this));this.throughputEstimator=e,this.requestQuic=t,this.compatibilityMode=r,this.tracer=i.createComponentTracer("Fetcher"),this.useEnableSubtitlesParam=a}onHeadersReceived(e){let{type:t,reused:i}=Vn(e);this.lastConnectionType$.next(t),this.lastConnectionReused$.next(i)}async fetchRepresentation(e,t,i="auto"){var a,n;let{type:r}=e;switch(r){case"byteRange":return(a=await this.fetchByteRangeRepresentation(e,t,i))!=null?a:null;case"template":return(n=await this.fetchTemplateRepresentation(e,i))!=null?n:null;default:(0,Y.assertNever)(r)}}destroy(){this.abortAllController.abort(),this.subscription.unsubscribe(),this.tracer.end()}async doFetch(e,t){let i=await dt(e,t);if(i.ok)return i;let r=await i.text(),a=parseInt(r);if(!isNaN(a))switch(a){case 1:this.recoverableError$.next({id:"VideoDataLinkExpiredError",message:"Video data links have expired",category:Y.ErrorCategory.FATAL});break;case 8:this.recoverableError$.next({id:"VideoDataLinkBlockedForFloodError",message:"Url blocked for flood",category:Y.ErrorCategory.FATAL});break;case 18:this.recoverableError$.next({id:"VideoDataLinkIllegalIpChangeError",message:"Client IP has changed",category:Y.ErrorCategory.FATAL});break;case 21:this.recoverableError$.next({id:"VideoDataLinkIllegalHostChangeError",message:"Request HOST has changed",category:Y.ErrorCategory.FATAL});break;default:this.error$.next({id:"GeneralVideoDataFetchError",message:`Generic video data fetch error (${a})`,category:Y.ErrorCategory.FATAL})}}unsubscribeAbortSubscription(e){e&&(e.unsubscribe(),this.subscription.remove(e))}},On=s=>{if(!Ct(s))throw s};var Qt=(s,e,t)=>t*e+(1-t)*s,Zl=(s,e)=>s.reduce((t,i)=>t+i,0)/e,US=(s,e,t,i)=>{let r=0,a=t,n=Zl(s,e),o=e<i?e:i;for(let u=0;u<o;u++)s[a]>n?r++:r--,a=(s.length+a-1)%s.length;return Math.abs(r)===o};var Zs=require("@vkontakte/videoplayer-shared/es2018"),hi=class{constructor(e){this.prevReported=void 0;this.pastMeasures=[];this.takenMeasures=0;this.measuresCursor=0;var i;this.params=e,this.pastMeasures=Array(e.deviationDepth),this.smoothed=this.prevReported=e.initial,this.smoothed$=new Zs.ValueSubject(e.initial),this.debounced$=new Zs.ValueSubject(e.initial);let t=(i=e.label)!=null?i:"value"+Math.random().toString(16).substring(2,6);this.rawSeries$=new qe(`raw_${t}`),this.smoothedSeries$=new qe(`smoothed_${t}`),this.reportedSeries$=new qe(`reported_${t}`),this.rawSeries$.next(e.initial),this.smoothedSeries$.next(e.initial),this.reportedSeries$.next(e.initial)}next(e){let t=0,i=0;for(let o=0;o<this.pastMeasures.length;o++)this.pastMeasures[o]!==void 0&&(t+=(this.pastMeasures[o]-this.smoothed)**2,i++);this.takenMeasures=i,t/=i;let r=Math.sqrt(t),a=this.smoothed+this.params.deviationFactor*r,n=this.smoothed-this.params.deviationFactor*r;this.pastMeasures[this.measuresCursor]=e,this.measuresCursor=(this.measuresCursor+1)%this.pastMeasures.length,this.rawSeries$.next(e),this.updateSmoothedValue(e),this.smoothed$.next(this.smoothed),this.smoothedSeries$.next(this.smoothed),!(this.smoothed>a||this.smoothed<n)&&((0,Zs.isNullable)(this.prevReported)||Math.abs(this.smoothed-this.prevReported)/this.prevReported>=this.params.changeThreshold)&&(this.prevReported=this.smoothed,this.debounced$.next(this.smoothed),this.reportedSeries$.next(this.smoothed))}};var Nn=class extends hi{constructor(e){super(e),this.slow=this.fast=e.initial}updateSmoothedValue(e){this.slow=Qt(this.slow,e,this.params.emaAlphaSlow),this.fast=Qt(this.fast,e,this.params.emaAlphaFast);let t=this.params.fastDirection>0?Math.max:Math.min;this.smoothed=t(this.slow,this.fast)}};var qn=class extends hi{constructor(e){super(e),this.emaSmoothed=e.initial}updateSmoothedValue(e){let t=Zl(this.pastMeasures,this.takenMeasures);this.emaSmoothed=Qt(this.emaSmoothed,e,this.params.emaAlpha);let i=US(this.pastMeasures,this.takenMeasures,this.measuresCursor-1,this.params.basisTrendChangeCount);this.smoothed=i?this.emaSmoothed:t}};var Un=class extends hi{constructor(t){super(t);this.furtherValues=[];this.currentTopExtremumValue=0;this.extremumInterval=t.extremumInterval}next(t){this.currentTopExtremumValue<=t?(this.currentTopExtremumValue=t,this.furtherValues=[]):this.furtherValues.length===this.extremumInterval?(super.next(this.currentTopExtremumValue),this.currentTopExtremumValue=t,this.furtherValues=[]):this.furtherValues.push(t)}updateSmoothedValue(t){this.smoothed=this.smoothed?Qt(this.smoothed,t,this.params.emaAlpha):t}};var Wt=class{static getSmoothedValue(e,t,i){return i.type==="TwoEma"?new Nn({initial:e,emaAlphaSlow:i.emaAlphaSlow,emaAlphaFast:i.emaAlphaFast,changeThreshold:i.changeThreshold,fastDirection:t,deviationDepth:i.deviationDepth,deviationFactor:i.deviationFactor,label:"throughput"}):new qn({initial:e,emaAlpha:i.emaAlpha,basisTrendChangeCount:i.basisTrendChangeCount,changeThreshold:i.changeThreshold,deviationDepth:i.deviationDepth,deviationFactor:i.deviationFactor,label:"throughput"})}static getLiveBufferSmoothedValue(e,t){return new Un({initial:e,label:"liveEdgeDelay",...t})}};var Rr=(s,e)=>{s&&s.playbackRate!==e&&(s.playbackRate=e)};var Hn=require("@vkontakte/videoplayer-shared/es2018");var ea=class s{constructor(e,t){this.currentRepresentation$=new Hn.ValueSubject(null);this.maxRepresentations=4;this.representationsCursor=0;this.representations=[];this.currentSegment=null;this.getCurrentPosition=t.getCurrentPosition,this.processStreams(e)}updateLive(e){this.processStreams(e==null?void 0:e.streams.text)}seekLive(e){this.processStreams(e)}maintain(e=this.getCurrentPosition()){var t;if(!(0,Hn.isNullable)(e))for(let i of this.representations)for(let r of i){let a=r.segmentReference,n=a.segments.length,o=a.segments[0].time.from,u=a.segments[n-1].time.to;if(e<o||e>u)continue;let l=a.segments.find(c=>c.time.from<=e&&c.time.to>=e);!l||((t=this.currentSegment)==null?void 0:t.time.from)===l.time.from&&this.currentSegment.time.to===l.time.to||(this.currentSegment=l,this.currentRepresentation$.next({...r,label:"Live Text",language:"ru",isAuto:!0,url:new URL(l.url,a.baseUrl).toString()}))}}destroy(){this.currentRepresentation$.next(null),this.currentSegment=null,this.representations=[]}processStreams(e){for(let t of e!=null?e:[]){let i=s.filterRepresentations(t.representations);if(i){this.representations[this.representationsCursor]=i,this.representationsCursor=(this.representationsCursor+1)%this.maxRepresentations;break}}}static isSupported(e){return!!(e!=null&&e.some(t=>s.filterRepresentations(t.representations)))}static filterRepresentations(e){return e==null?void 0:e.filter(t=>t.kind==="text"&&"segmentReference"in t&&st(t.segmentReference))}};var Qn=G(yt(),1),ec=G(Ne(),1),ta=require("@vkontakte/videoplayer-shared/es2018");var jn=s=>{let{webmDecodingInfo:e}=z.video,t="DASH_WEBM",i="DASH_WEBM_AV1";switch(s){case"vp9":return[t,i];case"av1":return[i,t];case"none":return[];case"smooth":return e?e[i].smooth?[i,t]:e[t].smooth?[t,i]:[i,t]:[t,i];case"power_efficient":return e?e[i].powerEfficient?[i,t]:e[t].powerEfficient?[t,i]:[i,t]:[t,i];default:(0,ta.assertNever)(s)}return[t,i]},HS=({webmCodec:s,androidPreferredFormat:e,iosPreferredFormat:t,preferMultiStream:i})=>{let r=[...i?["DASH_STREAMS"]:[],...jn(s),"DASH_SEP","DASH_ONDEMAND",...i?[]:["DASH_STREAMS"]],a=[...i?["DASH_STREAMS"]:[],"DASH_SEP","DASH_ONDEMAND",...i?[]:["DASH_STREAMS"]];if(z.device.isAndroid)switch(e){case"mpeg":return["MPEG",...r,"HLS","HLS_ONDEMAND"];case"hls":return["HLS","HLS_ONDEMAND",...r,"MPEG"];case"dash":return[...r,"HLS","HLS_ONDEMAND","MPEG"];case"dash_any_mpeg":return[...a,"MPEG",...jn(s),"HLS","HLS_ONDEMAND"];case"dash_any_webm":return[...jn(s),"MPEG",...a,"HLS","HLS_ONDEMAND"];case"dash_sep":return["DASH_SEP","MPEG",...jn(s),...a,"HLS","HLS_ONDEMAND"];default:(0,ta.assertNever)(e)}if(z.video.nativeHlsSupported)switch(t){case"hls":return[...r,"HLS","HLS_FMP4","HLS_ONDEMAND","MPEG"];case"hls_fmp4":return[...r,"HLS_FMP4","HLS","HLS_ONDEMAND","MPEG"];default:(0,ta.assertNever)(t)}return[...r,"HLS","HLS_ONDEMAND","MPEG"]},jS=({androidPreferredFormat:s,preferCMAF:e,preferWebRTC:t})=>{let i=e?["DASH_LIVE_CMAF","DASH_LIVE"]:["DASH_LIVE","DASH_LIVE_CMAF"],r=e?["HLS_LIVE_CMAF","HLS_LIVE"]:["HLS_LIVE","HLS_LIVE_CMAF"],a=[...i,...r],n=[...r,...i],o,u=z.device.isMac&&z.browser.isSafari;if(z.device.isAndroid)switch(s){case"dash":case"dash_any_mpeg":case"dash_any_webm":case"dash_sep":{o=a;break}case"hls":case"mpeg":{o=n;break}default:(0,ta.assertNever)(s)}else z.video.nativeHlsSupported&&!u?o=n:u?o=e?["DASH_LIVE_CMAF","HLS_LIVE_CMAF","HLS_LIVE","DASH_LIVE"]:["HLS_LIVE","DASH_LIVE","DASH_LIVE_CMAF","HLS_LIVE_CMAF"]:o=a;return t?["WEB_RTC_LIVE",...o]:[...o,"WEB_RTC_LIVE"]},tc=s=>s?["HLS_LIVE","HLS_LIVE_CMAF","DASH_LIVE_CMAF"]:["DASH_WEBM","DASH_WEBM_AV1","DASH_SEP","DASH_ONDEMAND","HLS","HLS_ONDEMAND","MPEG"],Wn=s=>{if(s.size===0)return;if(s.size===1){let t=s.values().next();return(0,Qn.default)(t.value.split("."),0)}for(let t of s){let i=(0,Qn.default)(t.split("."),0);if(i==="opus"||i==="vp09"||i==="av01")return i}let e=s.values().next();return(0,Qn.default)(e.value.split("."),0)},Gn=s=>{let e=s.map(i=>kr(i)),{codecs:t}=z.video;return u$().filter(i=>{if((0,ec.default)(e,i))switch(i){case"av1":return t.av1;case"vp9":return t.vp9;case"avc1":return t.h264;case"hev1":return t.h265;default:return!1}else return!1})},zn=s=>{let e=s.map(i=>kr(i)),{codecs:t}=z.video;return l$().filter(i=>{if((0,ec.default)(e,i))switch(i){case"opus":return t.opus;case"mp4a":return t.aac;default:return!1}else return!1})},kr=s=>s.split(".")[0].replace("0",""),u$=()=>["av1","vp9","hev1","avc1"],l$=()=>["opus","mp4a"];var p$=["timeupdate","progress","play","seeked","stalled","waiting"],h$=["timeupdate","progress","loadeddata","playing","seeked"];var Yn=class{constructor(e){this.element=null;this.manifestUrlString="";this.source=null;this.manifest=null;this.bufferManagers=[];this.subscription=new T.Subscription;this.representationSubscription=new T.Subscription;this.state$=new re("none");this.currentVideoRepresentation$=new T.ValueSubject(void 0);this.currentVideoRepresentationInit$=new T.ValueSubject(void 0);this.currentAudioRepresentation$=new T.ValueSubject(void 0);this.currentVideoSegmentLength$=new T.ValueSubject(0);this.currentAudioSegmentLength$=new T.ValueSubject(0);this.error$=new T.Subject;this.manifestRequested=new T.Subject;this.manifestReceived=new T.Subject;this.firstBytesRequested=new T.Subject;this.firstBytesReceived=new T.Subject;this.lastConnectionType$=new T.ValueSubject(void 0);this.lastConnectionReused$=new T.ValueSubject(void 0);this.lastRequestFirstBytes$=new T.ValueSubject(void 0);this.currentLiveTextRepresentation$=new T.ValueSubject(null);this.isLive$=new T.ValueSubject(!1);this.isActiveLive$=new T.ValueSubject(!1);this.isLowLatency$=new T.ValueSubject(!1);this.liveDuration$=new T.ValueSubject(0);this.liveSeekableDuration$=new T.ValueSubject(0);this.liveAvailabilityStartTime$=new T.ValueSubject(0);this.liveStreamStatus$=new T.ValueSubject(void 0);this.bufferLength$=new T.ValueSubject(0);this.liveLatency$=new T.ValueSubject(void 0);this.liveLoadBufferLength$=new T.ValueSubject(0);this.livePositionFromPlayer$=new T.ValueSubject(0);this.currentStallDuration$=new T.ValueSubject(0);this.videoLastDataObtainedTimestamp$=new T.ValueSubject(0);this.fetcherRecoverableError$=new T.Subject;this.fetcherError$=new T.Subject;this.liveStreamEndTimestamp=0;this.isUpdatingLive=!1;this.isJumpGapAfterSeekLive=!1;this.forceEnded$=new T.Subject;this.gapWatchdogActive=!1;this.destroyController=new ce;this.initManifest=(0,T.abortable)(this.destroyController.signal,async function*(e,t,i){var r;this.tracer.log("initManifest"),this.element=e,this.manifestUrlString=xe(t,i,2),this.state$.startTransitionTo("manifest_ready"),this.manifest=yield this.updateManifest(),(r=this.manifest)!=null&&r.streams.video.length?this.state$.setState("manifest_ready"):this.error$.next({id:"NoRepresentations",category:T.ErrorCategory.PARSER,message:"No playable video representations"})}.bind(this));this.updateManifest=(0,T.abortable)(this.destroyController.signal,async function*(){var u,l;this.tracer.log("updateManifestStart",{manifestUrl:this.manifestUrlString});let e=yield this.fetcher.fetchManifest(this.manifestUrlString).catch(c=>{!this.manifest&&!this.bufferLength$.getValue()&&this.error$.next({id:"LoadManifest",category:T.ErrorCategory.NETWORK,message:"Failed to load manifest",thrown:c})});if(!e)return null;let t=null;try{t=Dn(e!=null?e:"",this.manifestUrlString)}catch(c){let d=(u=$n(e))!=null?u:{id:"ManifestParsing",category:T.ErrorCategory.PARSER,message:"Failed to parse MPD manifest",thrown:c};this.error$.next(d)}if(!t)return null;let i=(c,d,f)=>{var p,h,b,S;return!!((h=(p=this.element)==null?void 0:p.canPlayType)!=null&&h.call(p,d)&&((S=(b=it())==null?void 0:b.isTypeSupported)!=null&&S.call(b,`${d}; codecs="${f}"`))||c==="text")};if(t.live){this.isLive$.next(!!t.live);let{availabilityStartTime:c,latestSegmentPublishTime:d,streamIsUnpublished:f,streamIsAlive:p}=t.live,h=((l=t.duration)!=null?l:0)/1e3;this.liveSeekableDuration$.next(-1*h),this.liveDuration$.next((d-c)/1e3),this.liveAvailabilityStartTime$.next(t.live.availabilityStartTime);let b="active";p||(b=f?"unpublished":"unexpectedly_down"),this.liveStreamStatus$.next(b)}let r={text:t.streams.text,video:[],audio:[]},a,n;for(let c of["video","audio"]){let f=t.streams[c].filter(({mime:h,codecs:b})=>i(c,h,b));r[c]=f;let p;if(this.tuning.dash.codecsPrioritizeEnabled){let h=f.map(({codecs:b})=>b);c==="audio"&&(n=zn(h),p=n[0]),c==="video"&&(a=Gn(h),this.forceVideoCodec&&(0,GS.default)(a,this.forceVideoCodec)?p=this.forceVideoCodec:p=a[0]),p&&(r[c]=f.filter(({codecs:b})=>kr(b)===p))}else{let h=new Set(f.map(({codecs:b})=>b));p=Wn(h),p&&(r[c]=f.filter(({codecs:b})=>b.startsWith(p)))}if(c==="video"){let h=this.tuning.preferHDR,b=r.video.some(g=>g.hdr),S=r.video.some(g=>!g.hdr);z.display.isHDR&&h&&b?r.video=r.video.filter(g=>g.hdr):S&&(r.video=r.video.filter(g=>!g.hdr))}}let o={...t,streams:r};return this.tuning.dash.codecsPrioritizeEnabled&&(o.codecs={video:a,audio:n}),this.tracer.log("updateManifestEnd",(0,T.flattenObject)(o)),o}.bind(this));this.initRepresentations=(0,T.abortable)(this.destroyController.signal,async function*(e,t,i){var f;this.tracer.log("initRepresentationsStart",(0,T.flattenObject)({initialVideo:e,initialAudio:t,sourceHls:i})),(0,T.assertNonNullable)(this.manifest),(0,T.assertNonNullable)(this.element),this.representationSubscription.unsubscribe(),this.state$.startTransitionTo("representations_ready");let r=p=>{this.representationSubscription.add((0,T.fromEvent)(p,"error").pipe((0,T.filter)(h=>{var b;return!!((b=this.element)!=null&&b.played.length)})).subscribe(h=>{this.error$.next({id:"VideoSource",category:T.ErrorCategory.VIDEO_PIPELINE,message:"Unexpected video source error",thrown:h})}))};this.source=fn();let a=document.createElement("source");if(r(a),a.src=URL.createObjectURL(this.source),this.element.appendChild(a),mr())if(i){let p=document.createElement("source");r(p),p.type="application/x-mpegurl",p.src=i.url,this.element.appendChild(p)}else this.element.disableRemotePlayback=!0;this.isActiveLive$.next(this.isLive$.getValue());let n={fetcher:this.fetcher,tuning:this.tuning,getCurrentPosition:()=>this.element?this.element.currentTime*1e3:void 0,isActiveLowLatency:()=>this.isActiveLive$.getValue()&&this.isLowLatency$.getValue(),manifest:this.manifest},o=this.manifest.streams.video.reduce((p,h)=>[...p,...h.representations],[]);if(this.videoBufferManager=new Js("video",this.source,o,n),this.bufferManagers=[this.videoBufferManager],(0,T.isNonNullable)(t)){let p=this.manifest.streams.audio.reduce((h,b)=>[...h,...b.representations],[]);this.audioBufferManager=new Js("audio",this.source,p,n),this.bufferManagers.push(this.audioBufferManager)}ea.isSupported(this.manifest.streams.text)&&!this.isLowLatency$.getValue()&&(this.liveTextManager=new ea(this.manifest.streams.text,n)),this.representationSubscription.add(this.fetcher.manifestRequested.subscribe(this.manifestRequested)),this.representationSubscription.add(this.fetcher.manifestReceived.subscribe(this.manifestReceived)),this.representationSubscription.add(this.fetcher.firstBytesRequested.subscribe(this.firstBytesRequested)),this.representationSubscription.add(this.fetcher.firstBytesReceived.subscribe(this.firstBytesReceived)),this.representationSubscription.add(this.fetcher.lastConnectionType$.subscribe(this.lastConnectionType$)),this.representationSubscription.add(this.fetcher.lastConnectionReused$.subscribe(this.lastConnectionReused$)),this.representationSubscription.add(this.fetcher.lastRequestFirstBytes$.subscribe(this.lastRequestFirstBytes$));let u=()=>{var p;(p=this.stallWatchdogSubscription)==null||p.unsubscribe(),this.currentStallDuration$.next(0)};if(this.representationSubscription.add((0,T.merge)(...h$.map(p=>(0,T.fromEvent)(this.element,p))).pipe((0,T.map)(p=>this.element?$e(this.element.buffered,this.element.currentTime*1e3):0),(0,T.filterChanged)(),(0,T.tap)(p=>{p>this.tuning.dash.bufferEmptinessTolerance&&u()})).subscribe(this.bufferLength$)),this.representationSubscription.add((0,T.merge)((0,T.fromEvent)(this.element,"ended"),this.forceEnded$).subscribe(()=>{u()})),this.isLive$.getValue()){this.subscription.add(this.liveDuration$.pipe((0,T.filterChanged)()).subscribe(h=>this.liveStreamEndTimestamp=(0,T.now)())),this.subscription.add((0,T.fromEvent)(this.element,"pause").subscribe(()=>{this.livePauseWatchdogSubscription=(0,T.interval)(1e3).subscribe(h=>{let b=ni(this.manifestUrlString,2);this.manifestUrlString=xe(this.manifestUrlString,b+1e3,2),this.liveStreamStatus$.getValue()==="active"&&this.updateManifest()}),this.subscription.add(this.livePauseWatchdogSubscription)})).add((0,T.fromEvent)(this.element,"play").subscribe(h=>{var b;return(b=this.livePauseWatchdogSubscription)==null?void 0:b.unsubscribe()})),this.representationSubscription.add((0,T.combine)({isActiveLive:this.isActiveLive$,isLowLatency:this.isLowLatency$}).pipe((0,T.map)(({isActiveLive:h,isLowLatency:b})=>h&&b),(0,T.filterChanged)()).subscribe(h=>{this.isManualDecreasePlaybackInLive()||Rr(this.element,1)})),this.representationSubscription.add((0,T.combine)({bufferLength:this.bufferLength$,isActiveLive:this.isActiveLive$,isLowLatency:this.isLowLatency$}).pipe((0,T.filter)(({bufferLength:h,isActiveLive:b,isLowLatency:S})=>b&&S&&!!h)).subscribe(({bufferLength:h})=>this.liveBuffer.next(h))),this.representationSubscription.add(this.videoBufferManager.currentLowLatencySegmentLength$.subscribe(h=>{if(!this.isActiveLive$.getValue()&&!this.isLowLatency$.getValue()&&!h)return;let b=this.liveSeekableDuration$.getValue()-h/1e3;this.liveSeekableDuration$.next(Math.max(b,-1*this.tuning.dashCmafLive.maxLiveDuration)),this.liveDuration$.next(this.liveDuration$.getValue()+h/1e3)})),this.representationSubscription.add((0,T.combine)({isLive:this.isLive$,rtt:this.throughputEstimator.rtt$,bufferLength:this.bufferLength$,segmentServerLatency:this.videoBufferManager.currentLiveSegmentServerLatency$}).pipe((0,T.filter)(({isLive:h})=>h),(0,T.filterChanged)((h,b)=>b.bufferLength<h.bufferLength),(0,T.map)(({rtt:h,bufferLength:b,segmentServerLatency:S})=>{let g=ni(this.manifestUrlString,2);return(h/2+b+S+g)/1e3})).subscribe(this.liveLatency$)),this.representationSubscription.add((0,T.combine)({liveBuffer:this.liveBuffer.smoothed$,isActiveLive:this.isActiveLive$,isLowLatency:this.isLowLatency$}).subscribe(({liveBuffer:h,isActiveLive:b,isLowLatency:S})=>{if(!S||!b)return;let g=this.tuning.dashCmafLive.lowLatency.maxTargetOffset,I=this.tuning.dashCmafLive.lowLatency.maxTargetOffsetDeviation,w=this.tuning.dashCmafLive.lowLatency.playbackCatchupSpeedup,E=h-g;if(this.isManualDecreasePlaybackInLive())return;let P=1;Math.abs(E)>I&&(P=1+Math.sign(E)*w),Rr(this.element,P)})),this.representationSubscription.add(this.bufferLength$.subscribe(h=>{var S,g;let b=0;if(h){let I=((g=(S=this.element)==null?void 0:S.currentTime)!=null?g:0)*1e3;b=Math.min(...this.bufferManagers.map(E=>{var P,_;return(_=(P=E.getLiveSegmentsToLoadState(this.manifest))==null?void 0:P.to)!=null?_:I}))-I}this.liveLoadBufferLength$.getValue()!==b&&this.liveLoadBufferLength$.next(b)}));let p=0;this.representationSubscription.add((0,T.combine)({liveLoadBufferLength:this.liveLoadBufferLength$,bufferLength:this.bufferLength$}).pipe((0,T.throttle)(1e3)).subscribe(async({liveLoadBufferLength:h,bufferLength:b})=>{if(!this.element||this.isUpdatingLive)return;let S=this.element.playbackRate,g=ni(this.manifestUrlString,2),I=Math.abs(this.livePositionFromPlayer$.getValue())*1e3,w=Math.min(I,this.tuning.dashCmafLive.normalizedTargetMinBufferSize*S),E=this.tuning.dashCmafLive.normalizedActualBufferOffset*S,P=this.tuning.dashCmafLive.normalizedLiveMinBufferSize*S,_=isFinite(h)?h:b,N=this.isActiveLive$.getValue()&&this.isLowLatency$.getValue(),F=I<=this.tuning.live.activeLiveDelay;this.isActiveLive$.next(F);let C="none";if(N?C="active_low_latency":this.isLowLatency$.getValue()&&F?(this.bufferManagers.forEach(B=>B.proceedLowLatencyLive()),C="active_low_latency"):g!==0&&_<w?C="live_forward_buffering":_<w+P&&(C="live_with_target_offset"),isFinite(h)&&(p=h>p?h:p),C==="live_forward_buffering"||C==="live_with_target_offset"){let B=p-(w+E),H=this.normolizeLiveOffset(Math.trunc(g+B/S)),q=Math.abs(H-g),W=0;!h||q<=this.tuning.dashCmafLive.offsetCalculationError?W=g:H>0&&q>this.tuning.dashCmafLive.offsetCalculationError&&(W=H),this.manifestUrlString=xe(this.manifestUrlString,W,2)}(C==="live_with_target_offset"||C==="live_forward_buffering")&&(p=0,await this.updateLive())},h=>{this.error$.next({id:"updateLive",category:T.ErrorCategory.VIDEO_PIPELINE,thrown:h,message:"Failed to update live with subscription"})}))}let l=(0,T.merge)(...this.bufferManagers.map(p=>p.fullyBuffered$)).pipe((0,T.map)(()=>this.bufferManagers.every(p=>p.fullyBuffered$.getValue()))),c=(0,T.merge)(...this.bufferManagers.map(p=>p.onLastSegment$)).pipe((0,T.map)(()=>this.bufferManagers.some(p=>p.onLastSegment$.getValue()))),d=(0,T.combine)({allBuffersFull:l,someBufferEnded:c}).pipe((0,T.filterChanged)(),(0,T.map)(({allBuffersFull:p,someBufferEnded:h})=>p&&h),(0,T.filter)(p=>p));if(this.representationSubscription.add((0,T.merge)(this.forceEnded$,d).subscribe(()=>{var p;if(this.source&&this.source.readyState==="open"&&Array.from(this.source.sourceBuffers).every(h=>!h.updating))try{(p=this.source)==null||p.endOfStream()}catch(h){this.error$.next({id:"EndOfStream",category:T.ErrorCategory.VIDEO_PIPELINE,message:"Failed to end MediaSource stream",thrown:h})}})),this.representationSubscription.add((0,T.merge)(...this.bufferManagers.map(p=>p.error$)).subscribe(this.error$)),this.representationSubscription.add(this.videoBufferManager.playingRepresentation$.subscribe(this.currentVideoRepresentation$)),this.representationSubscription.add(this.videoBufferManager.playingRepresentationInit$.subscribe(this.currentVideoRepresentationInit$)),this.representationSubscription.add(this.videoBufferManager.currentSegmentLength$.subscribe(this.currentVideoSegmentLength$)),this.audioBufferManager&&(this.representationSubscription.add(this.audioBufferManager.playingRepresentation$.subscribe(this.currentAudioRepresentation$)),this.representationSubscription.add(this.audioBufferManager.currentSegmentLength$.subscribe(this.currentAudioSegmentLength$))),this.liveTextManager&&this.representationSubscription.add(this.liveTextManager.currentRepresentation$.subscribe(this.currentLiveTextRepresentation$)),this.source.readyState!=="open"){let p=this.tuning.dash.sourceOpenTimeout>=0;yield new Promise(h=>{var b;p&&(this.timeoutSourceOpenId=setTimeout(()=>{var S;if(((S=this.source)==null?void 0:S.readyState)==="open"){h();return}this.error$.next({id:"OpenOfStream",category:T.ErrorCategory.VIDEO_PIPELINE,message:"Failed to open MediaSource",thrown:new Error("Timeout reject when wait sourceopen event"),traceAsLog:!0})},this.tuning.dash.sourceOpenTimeout)),(b=this.source)==null||b.addEventListener("sourceopen",()=>{this.timeoutSourceOpenId&&clearTimeout(this.timeoutSourceOpenId),h()},{once:!0})})}if(!this.isLive$.getValue()){let p=[(f=this.manifest.duration)!=null?f:0,...(0,rc.default)((0,rc.default)([...this.manifest.streams.audio,...this.manifest.streams.video],h=>h.representations),h=>{let b=[];return h.duration&&b.push(h.duration),st(h.segmentReference)&&h.segmentReference.totalSegmentsDurationMs&&b.push(h.segmentReference.totalSegmentsDurationMs),b})];this.source.duration=Math.max(...p)/1e3}this.audioBufferManager&&(0,T.isNonNullable)(t)?yield Promise.all([this.videoBufferManager.startWith(e),this.audioBufferManager.startWith(t)]):yield this.videoBufferManager.startWith(e),this.state$.setState("representations_ready"),this.tracer.log("initRepresentationsEnd")}.bind(this));this.tick=()=>{var t,i,r,a;if(!this.element||!this.videoBufferManager||((t=this.source)==null?void 0:t.readyState)!=="open")return;let e=this.element.currentTime*1e3;this.videoBufferManager.maintain(e),(i=this.audioBufferManager)==null||i.maintain(e),(r=this.liveTextManager)==null||r.maintain(e),(this.videoBufferManager.gaps.length||(a=this.audioBufferManager)!=null&&a.gaps.length)&&!this.gapWatchdogActive&&(this.gapWatchdogActive=!0,this.gapWatchdogSubscription=(0,T.interval)(this.tuning.gapWatchdogInterval).subscribe(()=>this.jumpGap(),n=>{this.error$.next({id:"GapWatchdog",category:T.ErrorCategory.WTF,message:"Error handling gaps",thrown:n})}),this.subscription.add(this.gapWatchdogSubscription))};this.throughputEstimator=e.throughputEstimator,this.tuning=e.tuning,this.tracer=e.tracer.createComponentTracer(this.constructor.name),this.forceVideoCodec=e.forceVideoCodec,this.fetcher=new Fn({throughputEstimator:this.throughputEstimator,requestQuic:this.tuning.requestQuick,compatibilityMode:e.compatibilityMode,tracer:this.tracer,useEnableSubtitlesParam:e.tuning.useEnableSubtitlesParam}),this.subscription.add(this.fetcher.recoverableError$.subscribe(this.fetcherRecoverableError$)),this.subscription.add(this.fetcher.error$.subscribe(this.fetcherError$)),this.liveBuffer=Wt.getLiveBufferSmoothedValue(this.tuning.dashCmafLive.lowLatency.maxTargetOffset,{...e.tuning.dashCmafLive.lowLatency.bufferEstimator}),this.initTracerSubscription()}async seekLive(e){var r,a,n;(0,T.assertNonNullable)(this.element);let t=this.liveStreamStatus$.getValue()!=="active"?(0,T.now)()-this.liveStreamEndTimestamp:0,i=this.normolizeLiveOffset(e+t);this.isActiveLive$.next(i===0),this.manifestUrlString=xe(this.manifestUrlString,i,2),this.manifest=await this.updateManifest(),this.manifest&&(this.isJumpGapAfterSeekLive=!0,await((r=this.videoBufferManager)==null?void 0:r.seekLive(this.manifest.streams.video)),await((a=this.audioBufferManager)==null?void 0:a.seekLive(this.manifest.streams.audio)),(n=this.liveTextManager)==null||n.seekLive(this.manifest.streams.text))}initBuffer(){(0,T.assertNonNullable)(this.element),this.state$.setState("running"),this.subscription.add((0,T.merge)(...p$.map(e=>(0,T.fromEvent)(this.element,e)),(0,T.fromEvent)(window,"online")).subscribe(()=>this.tick(),e=>{this.error$.next({id:"DashVKPlayer",category:T.ErrorCategory.WTF,message:"Internal logic error",thrown:e})})),this.subscription.add((0,T.fromEvent)(this.element,"progress").subscribe(()=>{this.element&&this.element.readyState===2&&!this.element.seeking&&(this.element.currentTime=this.element.currentTime)})),this.subscription.add((0,T.fromEvent)(this.element,"waiting").subscribe(()=>{var t;this.element&&this.element.readyState===2&&!this.element.seeking&&_e(this.element.buffered,this.element.currentTime*1e3)&&(this.element.currentTime=this.element.currentTime);let e=()=>{var p,h,b,S,g,I,w,E,P,_,N;if(!this.element||((p=this.source)==null?void 0:p.readyState)!=="open")return;let i=this.currentStallDuration$.getValue();i+=50,this.currentStallDuration$.next(i);let r={timeInWaiting:i},a=(0,T.now)(),n=100,o=(b=(h=this.videoBufferManager)==null?void 0:h.lastDataObtainedTimestamp)!=null?b:0;this.videoLastDataObtainedTimestamp$.next(o);let u=(g=(S=this.audioBufferManager)==null?void 0:S.lastDataObtainedTimestamp)!=null?g:0,l=(w=(I=this.videoBufferManager)==null?void 0:I.getForwardBufferDuration())!=null?w:0,c=(P=(E=this.audioBufferManager)==null?void 0:E.getForwardBufferDuration())!=null?P:0,d=l<n&&a-o>this.tuning.dash.crashOnStallTWithoutDataTimeout,f=this.audioBufferManager&&c<n&&a-u>this.tuning.dash.crashOnStallTWithoutDataTimeout;if((d||f)&&i>this.tuning.dash.crashOnStallTWithoutDataTimeout||i>=this.tuning.dash.crashOnStallTimeout)throw new Error(`Stall timeout exceeded: ${i} ms`);if(this.isLive$.getValue()&&i%2e3===0){let F=this.normolizeLiveOffset(-1*this.livePositionFromPlayer$.getValue()*1e3);this.seekLive(F).catch(C=>{this.error$.next({id:"stallIntervalCallback",category:T.ErrorCategory.VIDEO_PIPELINE,message:"stallIntervalCallback failed",thrown:C})}),r.liveLastOffset=F}else{let F=this.element.currentTime*1e3;(_=this.videoBufferManager)==null||_.maintain(F),(N=this.audioBufferManager)==null||N.maintain(F),r.position=F}this.tracer.log("stallIntervalCallback",(0,T.flattenObject)(r))};(t=this.stallWatchdogSubscription)==null||t.unsubscribe(),this.stallWatchdogSubscription=(0,T.interval)(50).subscribe(e,i=>{this.error$.next({id:"StallWatchdogCallback",category:T.ErrorCategory.NETWORK,message:"Can't restore DASH after stall.",thrown:i})}),this.subscription.add(this.stallWatchdogSubscription)})),this.tick()}async switchRepresentation(e,t,i=!1){let r={video:this.videoBufferManager,audio:this.audioBufferManager,text:null}[e];return this.tuning.useNewSwitchTo?this.currentStallDuration$.getValue()>0?r==null?void 0:r.switchToWithPreviousAbort(t,i):r==null?void 0:r.switchTo(t,i):r==null?void 0:r.switchToOld(t,i)}async seek(e,t){var r,a,n,o,u;(0,T.assertNonNullable)(this.element),(0,T.assertNonNullable)(this.videoBufferManager);let i;t||this.element.duration*1e3<=this.tuning.dashSeekInSegmentDurationThreshold||Math.abs(this.element.currentTime*1e3-e)<=this.tuning.dashSeekInSegmentAlwaysSeekDelta?i=e:i=Math.max((r=this.videoBufferManager.findSegmentStartTime(e))!=null?r:e,(n=(a=this.audioBufferManager)==null?void 0:a.findSegmentStartTime(e))!=null?n:e),this.warmUpMediaSourceIfNeeded(i),_e(this.element.buffered,i)||await Promise.all([this.videoBufferManager.abort(),(o=this.audioBufferManager)==null?void 0:o.abort()]),!((0,T.isNullable)(this.element)||(0,T.isNullable)(this.videoBufferManager))&&(this.videoBufferManager.maintain(i),(u=this.audioBufferManager)==null||u.maintain(i),this.element.currentTime=i/1e3,this.tracer.log("seek",(0,T.flattenObject)({requestedPosition:e,forcePrecise:t,position:i})))}warmUpMediaSourceIfNeeded(e=(t=>(t=this.element)==null?void 0:t.currentTime)()){var i;(0,T.isNonNullable)(this.element)&&(0,T.isNonNullable)(this.source)&&(0,T.isNonNullable)(e)&&((i=this.source)==null?void 0:i.readyState)==="ended"&&this.element.duration*1e3-e>this.tuning.dash.seekBiasInTheEnd&&this.bufferManagers.forEach(r=>r.warmUpMediaSource())}get isStreamEnded(){var e;return((e=this.source)==null?void 0:e.readyState)==="ended"}stop(){var e,t,i;this.tracer.log("stop"),(e=this.element)==null||e.querySelectorAll("source").forEach(r=>{URL.revokeObjectURL(r.src),r.remove()}),this.element=null,this.source=null,this.manifest=null,this.currentVideoRepresentation$.next(void 0),(t=this.videoBufferManager)==null||t.destroy(),this.videoBufferManager=null,(i=this.audioBufferManager)==null||i.destroy(),this.audioBufferManager=null,this.bufferManagers=[],this.state$.setState("none")}setBufferTarget(e){for(let t of this.bufferManagers)t.setTarget(e)}getStreams(){var e;return(e=this.manifest)==null?void 0:e.streams}getCodecs(){var e;return(e=this.manifest)==null?void 0:e.codecs}setPreloadOnly(e){for(let t of this.bufferManagers)t.setPreloadOnly(e)}destroy(){var e;this.subscription.unsubscribe(),this.representationSubscription.unsubscribe(),this.timeoutSourceOpenId&&clearTimeout(this.timeoutSourceOpenId),this.destroyController.abort(),this.fetcher.destroy(),this.stop(),((e=this.source)==null?void 0:e.readyState)==="open"&&Array.from(this.source.sourceBuffers).every(t=>!t.updating)&&this.source.endOfStream(),this.source=null,this.tracer.end()}initTracerSubscription(){let e=(0,T.getTraceSubscriptionMethod)(this.tracer.error.bind(this.tracer));this.subscription.add(this.error$.subscribe(e("error")))}isManualDecreasePlaybackInLive(){if(!this.element||!this.isLive$.getValue())return!1;let e=1-this.element.playbackRate;return Number(e.toFixed(2))>Number(this.tuning.dashCmafLive.lowLatency.playbackCatchupSpeedup.toFixed(2))}normolizeLiveOffset(e){return Math.trunc(e/1e3)*1e3}async updateLive(){var e;this.isUpdatingLive=!0,this.manifest=await this.updateManifest(),this.manifest&&(this.bufferManagers.forEach(t=>t.updateLive(this.manifest)),(e=this.liveTextManager)==null||e.updateLive(this.manifest)),this.isUpdatingLive=!1}jumpGap(){if(!this.element||!this.videoBufferManager)return;let e=this.videoBufferManager.getDebugBufferState();if(!e)return;let t=this.isActiveLive$.getValue()&&this.isLowLatency$.getValue(),i={isJumpGapAfterSeekLive:this.isJumpGapAfterSeekLive,isActiveLowLatency:t,initialCurrentTime:this.element.currentTime};this.isJumpGapAfterSeekLive&&!t&&this.element.currentTime>e.to&&(this.isJumpGapAfterSeekLive=!1,this.element.currentTime=0);let r=this.element.currentTime*1e3,a=[],n=this.element.readyState===1?this.tuning.endGapTolerance:0;for(let o of this.bufferManagers)for(let u of o.gaps)o.playingRepresentation$.getValue()===u.representation&&u.from-n<=r&&u.to+n>r&&(this.element.duration*1e3-u.to<this.tuning.endGapTolerance?a.push(1/0):a.push(u.to));if(a.length){let o=Math.max(...a)+10;this.gapWatchdogSubscription.unsubscribe(),this.gapWatchdogActive=!1,o===1/0?this.forceEnded$.next():(this.element.currentTime=o/1e3,i={...i,gapEnds:a,jumpTo:o,resultCurrentTime:this.element.currentTime},this.tracer.log("jumpGap",(0,T.flattenObject)(i)))}}calculateDurationFromSegments(){var e,t;return Math.max(((e=this.videoBufferManager)==null?void 0:e.calculateDurationFromSegments())||0,((t=this.audioBufferManager)==null?void 0:t.calculateDurationFromSegments())||0)}};var Kn=class{constructor(e,t){this.fov=e,this.orientation=t}};var Xn=class{constructor(e,t){this.rotating=!1;this.fading=!1;this.lastTickTS=0;this.lastCameraTurnTS=0;this.fadeStartSpeed=null;this.fadeTime=0;this.camera=e,this.options=t,this.rotationSpeed={x:0,y:0,z:0},this.fadeCorrection=1/(this.options.speedFadeTime/1e3)**2}turnCamera(e=0,t=0,i=0){this.pointCameraTo(this.camera.orientation.x+e,this.camera.orientation.y+t,this.camera.orientation.z+i)}pointCameraTo(e=0,t=0,i=0){t=this.limitCameraRotationY(t);let r=e-this.camera.orientation.x,a=t-this.camera.orientation.y,n=i-this.camera.orientation.z;this.camera.orientation.x=e,this.camera.orientation.y=t,this.camera.orientation.z=i,this.lastCameraTurn={x:r,y:a,z:n},this.lastCameraTurnTS=Date.now()}setRotationSpeed(e,t,i){this.rotationSpeed.x=e!=null?e:this.rotationSpeed.x,this.rotationSpeed.y=t!=null?t:this.rotationSpeed.y,this.rotationSpeed.z=i!=null?i:this.rotationSpeed.z}startRotation(){this.rotating=!0}stopRotation(e=!1){e?(this.setRotationSpeed(0,0,0),this.fadeStartSpeed=null):this.startFading(this.rotationSpeed.x,this.rotationSpeed.y,this.rotationSpeed.z),this.rotating=!1}onCameraRelease(){if(this.lastCameraTurn&&this.lastCameraTurnTS){let e=Date.now()-this.lastCameraTurnTS;if(e<this.options.speedFadeThreshold){let t=(1-e/this.options.speedFadeThreshold)*this.options.rotationSpeedCorrection;this.startFading(this.lastCameraTurn.x*t,this.lastCameraTurn.y*t,this.lastCameraTurn.z*t)}}}startFading(e,t,i){this.setRotationSpeed(e,t,i),this.fadeStartSpeed={...this.rotationSpeed},this.fading=!0}stopFading(){this.fadeStartSpeed=null,this.fading=!0,this.fadeTime=0}limitCameraRotationY(e){return Math.max(-this.options.maxYawAngle,Math.min(e,this.options.maxYawAngle))}tick(e){if(!this.lastTickTS){this.lastTickTS=e,this.lastCameraTurnTS=Date.now();return}let t=e-this.lastTickTS,i=t/1e3;if(this.rotating)this.turnCamera(this.rotationSpeed.x*this.options.rotationSpeedCorrection*i,this.rotationSpeed.y*this.options.rotationSpeedCorrection*i,this.rotationSpeed.z*this.options.rotationSpeedCorrection*i);else if(this.fading&&this.fadeStartSpeed){let r=-this.fadeCorrection*(this.fadeTime/1e3)**2+1;this.setRotationSpeed(this.fadeStartSpeed.x*r,this.fadeStartSpeed.y*r,this.fadeStartSpeed.z*r),r>0?this.turnCamera(this.rotationSpeed.x*this.options.rotationSpeedCorrection*i,this.rotationSpeed.y*this.options.rotationSpeedCorrection*i,this.rotationSpeed.z*this.options.rotationSpeedCorrection*i):(this.stopRotation(!0),this.stopFading()),this.fadeTime=Math.min(this.fadeTime+t,this.options.speedFadeTime)}this.lastTickTS=e}};var zS=`attribute vec2 a_vertex;
125
125
  attribute vec2 a_texel;
126
126
 
127
127
  varying vec2 v_texel;