@vkontakte/videoplayer-interactive 1.0.34-dev.740b6a98.0 → 1.0.34-dev.870071a7.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.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.34-dev.740b6a98.0
3
- * Mon, 24 Mar 2025 07:50:15 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.34-dev.870071a7.0
3
+ * Thu, 27 Mar 2025 13:20:20 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-34/doc/
5
5
  */
6
- var Po=Object.create;var an=Object.defineProperty;var ko=Object.getOwnPropertyDescriptor;var Vo=Object.getOwnPropertyNames;var Mo=Object.getPrototypeOf,No=Object.prototype.hasOwnProperty;var on=r=>{throw TypeError(r)};var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Lo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Vo(e))!No.call(r,i)&&i!==t&&an(r,i,{get:()=>e[i],enumerable:!(n=ko(e,i))||n.enumerable});return r};var J=(r,e,t)=>(t=r!=null?Po(Mo(r)):{},Lo(e||!r||!r.__esModule?an(t,"default",{value:r,enumerable:!0}):t,r));var cn=(r,e,t)=>e.has(r)||on("Cannot "+t);var S=(r,e,t)=>(cn(r,e,"read from private field"),t?t.call(r):e.get(r)),F=(r,e,t)=>e.has(r)?on("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),N=(r,e,t,n)=>(cn(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t);var ln=(r,e,t,n)=>({set _(i){N(r,e,i,t)},get _(){return S(r,e,n)}});var Q=p((Yt,bn)=>{"use strict";var Re=function(r){return r&&r.Math===Math&&r};bn.exports=Re(typeof globalThis=="object"&&globalThis)||Re(typeof window=="object"&&window)||Re(typeof self=="object"&&self)||Re(typeof global=="object"&&global)||Re(typeof Yt=="object"&&Yt)||function(){return this}()||Function("return this")()});var B=p((ed,Cn)=>{"use strict";Cn.exports=function(r){try{return!!r()}catch(e){return!0}}});var Oe=p((td,gn)=>{"use strict";var jo=B();gn.exports=!jo(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Sn=p((rd,xn)=>{"use strict";var $o=Oe(),Tn=Function.prototype,En=Tn.apply,In=Tn.call;xn.exports=typeof Reflect=="object"&&Reflect.apply||($o?In.bind(En):function(){return In.apply(En,arguments)})});var W=p((nd,Rn)=>{"use strict";var wn=Oe(),An=Function.prototype,Zt=An.call,_o=wn&&An.bind.bind(Zt,Zt);Rn.exports=wn?_o:function(r){return function(){return Zt.apply(r,arguments)}}});var Pe=p((id,Pn)=>{"use strict";var On=W(),Fo=On({}.toString),qo=On("".slice);Pn.exports=function(r){return qo(Fo(r),8,-1)}});var Jt=p((sd,kn)=>{"use strict";var Bo=Pe(),Do=W();kn.exports=function(r){if(Bo(r)==="Function")return Do(r)}});var D=p((ad,Vn)=>{"use strict";var er=typeof document=="object"&&document.all;Vn.exports=typeof er=="undefined"&&er!==void 0?function(r){return typeof r=="function"||r===er}:function(r){return typeof r=="function"}});var se=p((od,Mn)=>{"use strict";var Ho=B();Mn.exports=!Ho(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var ut=p((cd,Nn)=>{"use strict";var Uo=Oe(),lt=Function.prototype.call;Nn.exports=Uo?lt.bind(lt):function(){return lt.apply(lt,arguments)}});var tr=p($n=>{"use strict";var Ln={}.propertyIsEnumerable,jn=Object.getOwnPropertyDescriptor,Go=jn&&!Ln.call({1:2},1);$n.f=Go?function(e){var t=jn(this,e);return!!t&&t.enumerable}:Ln});var rr=p((ud,_n)=>{"use strict";_n.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var qn=p((pd,Fn)=>{"use strict";var zo=W(),Wo=B(),Ko=Pe(),nr=Object,Qo=zo("".split);Fn.exports=Wo(function(){return!nr("z").propertyIsEnumerable(0)})?function(r){return Ko(r)==="String"?Qo(r,""):nr(r)}:nr});var ir=p((hd,Bn)=>{"use strict";Bn.exports=function(r){return r==null}});var sr=p((dd,Dn)=>{"use strict";var Xo=ir(),Yo=TypeError;Dn.exports=function(r){if(Xo(r))throw new Yo("Can't call method on "+r);return r}});var ke=p((md,Hn)=>{"use strict";var Zo=qn(),Jo=sr();Hn.exports=function(r){return Zo(Jo(r))}});var ye=p((fd,Un)=>{"use strict";var ec=D();Un.exports=function(r){return typeof r=="object"?r!==null:ec(r)}});var pt=p((vd,Gn)=>{"use strict";Gn.exports={}});var ht=p((yd,Wn)=>{"use strict";var ar=pt(),or=Q(),tc=D(),zn=function(r){return tc(r)?r:void 0};Wn.exports=function(r,e){return arguments.length<2?zn(ar[r])||zn(or[r]):ar[r]&&ar[r][e]||or[r]&&or[r][e]}});var Qn=p((bd,Kn)=>{"use strict";var rc=W();Kn.exports=rc({}.isPrototypeOf)});var Jn=p((Cd,Zn)=>{"use strict";var nc=Q(),Xn=nc.navigator,Yn=Xn&&Xn.userAgent;Zn.exports=Yn?String(Yn):""});var ai=p((gd,si)=>{"use strict";var ii=Q(),cr=Jn(),ei=ii.process,ti=ii.Deno,ri=ei&&ei.versions||ti&&ti.version,ni=ri&&ri.v8,K,dt;ni&&(K=ni.split("."),dt=K[0]>0&&K[0]<4?1:+(K[0]+K[1]));!dt&&cr&&(K=cr.match(/Edge\/(\d+)/),(!K||K[1]>=74)&&(K=cr.match(/Chrome\/(\d+)/),K&&(dt=+K[1])));si.exports=dt});var lr=p((Ed,ci)=>{"use strict";var oi=ai(),ic=B(),sc=Q(),ac=sc.String;ci.exports=!!Object.getOwnPropertySymbols&&!ic(function(){var r=Symbol("symbol detection");return!ac(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&oi&&oi<41})});var ur=p((Id,li)=>{"use strict";var oc=lr();li.exports=oc&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var pr=p((Td,ui)=>{"use strict";var cc=ht(),lc=D(),uc=Qn(),pc=ur(),hc=Object;ui.exports=pc?function(r){return typeof r=="symbol"}:function(r){var e=cc("Symbol");return lc(e)&&uc(e.prototype,hc(r))}});var hi=p((xd,pi)=>{"use strict";var dc=String;pi.exports=function(r){try{return dc(r)}catch(e){return"Object"}}});var hr=p((Sd,di)=>{"use strict";var mc=D(),fc=hi(),vc=TypeError;di.exports=function(r){if(mc(r))return r;throw new vc(fc(r)+" is not a function")}});var fi=p((wd,mi)=>{"use strict";var yc=hr(),bc=ir();mi.exports=function(r,e){var t=r[e];return bc(t)?void 0:yc(t)}});var yi=p((Ad,vi)=>{"use strict";var dr=ut(),mr=D(),fr=ye(),Cc=TypeError;vi.exports=function(r,e){var t,n;if(e==="string"&&mr(t=r.toString)&&!fr(n=dr(t,r))||mr(t=r.valueOf)&&!fr(n=dr(t,r))||e!=="string"&&mr(t=r.toString)&&!fr(n=dr(t,r)))return n;throw new Cc("Can't convert object to primitive value")}});var Ci=p((Rd,bi)=>{"use strict";bi.exports=!0});var Ii=p((Od,Ei)=>{"use strict";var gi=Q(),gc=Object.defineProperty;Ei.exports=function(r,e){try{gc(gi,r,{value:e,configurable:!0,writable:!0})}catch(t){gi[r]=e}return e}});var mt=p((Pd,Si)=>{"use strict";var Ec=Ci(),Ic=Q(),Tc=Ii(),Ti="__core-js_shared__",xi=Si.exports=Ic[Ti]||Tc(Ti,{});(xi.versions||(xi.versions=[])).push({version:"3.38.0",mode:Ec?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var vr=p((kd,Ai)=>{"use strict";var wi=mt();Ai.exports=function(r,e){return wi[r]||(wi[r]=e||{})}});var Ve=p((Vd,Ri)=>{"use strict";var xc=sr(),Sc=Object;Ri.exports=function(r){return Sc(xc(r))}});var be=p((Md,Oi)=>{"use strict";var wc=W(),Ac=Ve(),Rc=wc({}.hasOwnProperty);Oi.exports=Object.hasOwn||function(e,t){return Rc(Ac(e),t)}});var yr=p((Nd,Pi)=>{"use strict";var Oc=W(),Pc=0,kc=Math.random(),Vc=Oc(1 .toString);Pi.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Vc(++Pc+kc,36)}});var Me=p((Ld,Vi)=>{"use strict";var Mc=Q(),Nc=vr(),ki=be(),Lc=yr(),jc=lr(),$c=ur(),Ce=Mc.Symbol,br=Nc("wks"),_c=$c?Ce.for||Ce:Ce&&Ce.withoutSetter||Lc;Vi.exports=function(r){return ki(br,r)||(br[r]=jc&&ki(Ce,r)?Ce[r]:_c("Symbol."+r)),br[r]}});var ji=p((jd,Li)=>{"use strict";var Fc=ut(),Mi=ye(),Ni=pr(),qc=fi(),Bc=yi(),Dc=Me(),Hc=TypeError,Uc=Dc("toPrimitive");Li.exports=function(r,e){if(!Mi(r)||Ni(r))return r;var t=qc(r,Uc),n;if(t){if(e===void 0&&(e="default"),n=Fc(t,r,e),!Mi(n)||Ni(n))return n;throw new Hc("Can't convert object to primitive value")}return e===void 0&&(e="number"),Bc(r,e)}});var Cr=p(($d,$i)=>{"use strict";var Gc=ji(),zc=pr();$i.exports=function(r){var e=Gc(r,"string");return zc(e)?e:e+""}});var qi=p((_d,Fi)=>{"use strict";var Wc=Q(),_i=ye(),gr=Wc.document,Kc=_i(gr)&&_i(gr.createElement);Fi.exports=function(r){return Kc?gr.createElement(r):{}}});var Er=p((Fd,Bi)=>{"use strict";var Qc=se(),Xc=B(),Yc=qi();Bi.exports=!Qc&&!Xc(function(){return Object.defineProperty(Yc("div"),"a",{get:function(){return 7}}).a!==7})});var Ui=p(Hi=>{"use strict";var Zc=se(),Jc=ut(),el=tr(),tl=rr(),rl=ke(),nl=Cr(),il=be(),sl=Er(),Di=Object.getOwnPropertyDescriptor;Hi.f=Zc?Di:function(e,t){if(e=rl(e),t=nl(t),sl)try{return Di(e,t)}catch(n){}if(il(e,t))return tl(!Jc(el.f,e,t),e[t])}});var zi=p((Bd,Gi)=>{"use strict";var al=B(),ol=D(),cl=/#|\.prototype\./,Ne=function(r,e){var t=ul[ll(r)];return t===hl?!0:t===pl?!1:ol(e)?al(e):!!e},ll=Ne.normalize=function(r){return String(r).replace(cl,".").toLowerCase()},ul=Ne.data={},pl=Ne.NATIVE="N",hl=Ne.POLYFILL="P";Gi.exports=Ne});var Ir=p((Dd,Ki)=>{"use strict";var Wi=Jt(),dl=hr(),ml=Oe(),fl=Wi(Wi.bind);Ki.exports=function(r,e){return dl(r),e===void 0?r:ml?fl(r,e):function(){return r.apply(e,arguments)}}});var Xi=p((Hd,Qi)=>{"use strict";var vl=se(),yl=B();Qi.exports=vl&&yl(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Zi=p((Ud,Yi)=>{"use strict";var bl=ye(),Cl=String,gl=TypeError;Yi.exports=function(r){if(bl(r))return r;throw new gl(Cl(r)+" is not an object")}});var ts=p(es=>{"use strict";var El=se(),Il=Er(),Tl=Xi(),ft=Zi(),Ji=Cr(),xl=TypeError,Tr=Object.defineProperty,Sl=Object.getOwnPropertyDescriptor,xr="enumerable",Sr="configurable",wr="writable";es.f=El?Tl?function(e,t,n){if(ft(e),t=Ji(t),ft(n),typeof e=="function"&&t==="prototype"&&"value"in n&&wr in n&&!n[wr]){var i=Sl(e,t);i&&i[wr]&&(e[t]=n.value,n={configurable:Sr in n?n[Sr]:i[Sr],enumerable:xr in n?n[xr]:i[xr],writable:!1})}return Tr(e,t,n)}:Tr:function(e,t,n){if(ft(e),t=Ji(t),ft(n),Il)try{return Tr(e,t,n)}catch(i){}if("get"in n||"set"in n)throw new xl("Accessors not supported");return"value"in n&&(e[t]=n.value),e}});var ns=p((zd,rs)=>{"use strict";var wl=se(),Al=ts(),Rl=rr();rs.exports=wl?function(r,e,t){return Al.f(r,e,Rl(1,t))}:function(r,e,t){return r[e]=t,r}});var je=p((Wd,ss)=>{"use strict";var Le=Q(),Ol=Sn(),Pl=Jt(),kl=D(),Vl=Ui().f,Ml=zi(),ge=pt(),Nl=Ir(),Ee=ns(),is=be();mt();var Ll=function(r){var e=function(t,n,i){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,n)}return new r(t,n,i)}return Ol(r,this,arguments)};return e.prototype=r.prototype,e};ss.exports=function(r,e){var t=r.target,n=r.global,i=r.stat,s=r.proto,o=n?Le:i?Le[t]:Le[t]&&Le[t].prototype,c=n?ge:ge[t]||Ee(ge,t,{})[t],a=c.prototype,l,y,f,v,C,w,g,m,A;for(v in e)l=Ml(n?v:t+(i?".":"#")+v,r.forced),y=!l&&o&&is(o,v),w=c[v],y&&(r.dontCallGetSet?(A=Vl(o,v),g=A&&A.value):g=o[v]),C=y&&g?g:e[v],!(!l&&!s&&typeof w==typeof C)&&(r.bind&&y?m=Nl(C,Le):r.wrap&&y?m=Ll(C):s&&kl(C)?m=Pl(C):m=C,(r.sham||C&&C.sham||w&&w.sham)&&Ee(m,"sham",!0),Ee(c,v,m),s&&(f=t+"Prototype",is(ge,f)||Ee(ge,f,{}),Ee(ge[f],v,C),r.real&&a&&(l||!a[v])&&Ee(a,v,C)))}});var os=p((Kd,as)=>{"use strict";var jl=Math.ceil,$l=Math.floor;as.exports=Math.trunc||function(e){var t=+e;return(t>0?$l:jl)(t)}});var $e=p((Qd,cs)=>{"use strict";var _l=os();cs.exports=function(r){var e=+r;return e!==e||e===0?0:_l(e)}});var us=p((Xd,ls)=>{"use strict";var Fl=$e(),ql=Math.min;ls.exports=function(r){var e=Fl(r);return e>0?ql(e,9007199254740991):0}});var _e=p((Yd,ps)=>{"use strict";var Bl=us();ps.exports=function(r){return Bl(r.length)}});var vt=p((Zd,hs)=>{"use strict";hs.exports=function(){}});var ds=p(()=>{"use strict";var Dl=je(),Hl=Ve(),Ul=_e(),Gl=$e(),zl=vt();Dl({target:"Array",proto:!0},{at:function(e){var t=Hl(this),n=Ul(t),i=Gl(e),s=i>=0?i:n+i;return s<0||s>=n?void 0:t[s]}});zl("at")});var yt=p((tm,ms)=>{"use strict";var Wl=ht();ms.exports=Wl});var vs=p((rm,fs)=>{"use strict";ds();var Kl=yt();fs.exports=Kl("Array","at")});var bs=p((nm,ys)=>{"use strict";var Ql=vs();ys.exports=Ql});var Ar=p((im,Cs)=>{"use strict";var Xl=bs();Cs.exports=Xl});var Ls=p((vf,Ns)=>{"use strict";var au=vr(),ou=yr(),Ms=au("keys");Ns.exports=function(r){return Ms[r]||(Ms[r]=ou(r))}});var $s=p((yf,js)=>{"use strict";var cu=B();js.exports=!cu(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var qs=p((bf,Fs)=>{"use strict";var lu=be(),uu=D(),pu=Ve(),hu=Ls(),du=$s(),_s=hu("IE_PROTO"),$r=Object,mu=$r.prototype;Fs.exports=du?$r.getPrototypeOf:function(r){var e=pu(r);if(lu(e,_s))return e[_s];var t=e.constructor;return uu(t)&&e instanceof t?t.prototype:e instanceof $r?mu:null}});var Ds=p((Cf,Bs)=>{"use strict";var fu=$e(),vu=Math.max,yu=Math.min;Bs.exports=function(r,e){var t=fu(r);return t<0?vu(t+e,0):yu(t,e)}});var _r=p((gf,Us)=>{"use strict";var bu=ke(),Cu=Ds(),gu=_e(),Hs=function(r){return function(e,t,n){var i=bu(e),s=gu(i);if(s===0)return!r&&-1;var o=Cu(n,s),c;if(r&&t!==t){for(;s>o;)if(c=i[o++],c!==c)return!0}else for(;s>o;o++)if((r||o in i)&&i[o]===t)return r||o||0;return!r&&-1}};Us.exports={includes:Hs(!0),indexOf:Hs(!1)}});var zs=p((Ef,Gs)=>{"use strict";Gs.exports={}});var Qs=p((If,Ks)=>{"use strict";var Eu=W(),Fr=be(),Iu=ke(),Tu=_r().indexOf,xu=zs(),Ws=Eu([].push);Ks.exports=function(r,e){var t=Iu(r),n=0,i=[],s;for(s in t)!Fr(xu,s)&&Fr(t,s)&&Ws(i,s);for(;e.length>n;)Fr(t,s=e[n++])&&(~Tu(i,s)||Ws(i,s));return i}});var Ys=p((Tf,Xs)=>{"use strict";Xs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var Js=p((xf,Zs)=>{"use strict";var Su=Qs(),wu=Ys();Zs.exports=Object.keys||function(e){return Su(e,wu)}});var sa=p((Sf,ia)=>{"use strict";var ta=se(),Au=B(),ra=W(),Ru=qs(),Ou=Js(),Pu=ke(),ku=tr().f,na=ra(ku),Vu=ra([].push),Mu=ta&&Au(function(){var r=Object.create(null);return r[2]=2,!na(r,2)}),ea=function(r){return function(e){for(var t=Pu(e),n=Ou(t),i=Mu&&Ru(t)===null,s=n.length,o=0,c=[],a;s>o;)a=n[o++],(!ta||(i?a in t:na(t,a)))&&Vu(c,r?[a,t[a]]:t[a]);return c}};ia.exports={entries:ea(!0),values:ea(!1)}});var aa=p(()=>{"use strict";var Nu=je(),Lu=sa().values;Nu({target:"Object",stat:!0},{values:function(e){return Lu(e)}})});var ca=p((Rf,oa)=>{"use strict";aa();var ju=pt();oa.exports=ju.Object.values});var ua=p((Of,la)=>{"use strict";var $u=ca();la.exports=$u});var Mt=p((Pf,pa)=>{"use strict";var _u=ua();pa.exports=_u});var ma=p(()=>{"use strict";var Fu=je(),qu=_r().includes,Bu=B(),Du=vt(),Hu=Bu(function(){return!Array(1).includes()});Fu({target:"Array",proto:!0,forced:Hu},{includes:function(e){return qu(this,e,arguments.length>1?arguments[1]:void 0)}});Du("includes")});var va=p((Lf,fa)=>{"use strict";ma();var Uu=yt();fa.exports=Uu("Array","includes")});var ba=p((jf,ya)=>{"use strict";var Gu=va();ya.exports=Gu});var Nt=p(($f,Ca)=>{"use strict";var zu=ba();Ca.exports=zu});var Ur=p((tv,xa)=>{"use strict";var Zu=Pe();xa.exports=Array.isArray||function(e){return Zu(e)==="Array"}});var wa=p((rv,Sa)=>{"use strict";var Ju=TypeError,ep=9007199254740991;Sa.exports=function(r){if(r>ep)throw Ju("Maximum allowed index exceeded");return r}});var Oa=p((nv,Ra)=>{"use strict";var tp=Ur(),rp=_e(),np=wa(),ip=Ir(),Aa=function(r,e,t,n,i,s,o,c){for(var a=i,l=0,y=o?ip(o,c):!1,f,v;l<n;)l in t&&(f=y?y(t[l],l,e):t[l],s>0&&tp(f)?(v=rp(f),a=Aa(r,e,f,v,a,s-1)-1):(np(a+1),r[a]=f),a++),l++;return a};Ra.exports=Aa});var Va=p((iv,ka)=>{"use strict";var sp=Me(),ap=sp("toStringTag"),Pa={};Pa[ap]="z";ka.exports=String(Pa)==="[object z]"});var Na=p((sv,Ma)=>{"use strict";var op=Va(),cp=D(),jt=Pe(),lp=Me(),up=lp("toStringTag"),pp=Object,hp=jt(function(){return arguments}())==="Arguments",dp=function(r,e){try{return r[e]}catch(t){}};Ma.exports=op?jt:function(r){var e,t,n;return r===void 0?"Undefined":r===null?"Null":typeof(t=dp(e=pp(r),up))=="string"?t:hp?jt(e):(n=jt(e))==="Object"&&cp(e.callee)?"Arguments":n}});var ja=p((av,La)=>{"use strict";var mp=W(),fp=D(),Gr=mt(),vp=mp(Function.toString);fp(Gr.inspectSource)||(Gr.inspectSource=function(r){return vp(r)});La.exports=Gr.inspectSource});var Da=p((ov,Ba)=>{"use strict";var yp=W(),bp=B(),$a=D(),Cp=Na(),gp=ht(),Ep=ja(),_a=function(){},Fa=gp("Reflect","construct"),zr=/^\s*(?:class|function)\b/,Ip=yp(zr.exec),Tp=!zr.test(_a),Qe=function(e){if(!$a(e))return!1;try{return Fa(_a,[],e),!0}catch(t){return!1}},qa=function(e){if(!$a(e))return!1;switch(Cp(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Tp||!!Ip(zr,Ep(e))}catch(t){return!0}};qa.sham=!0;Ba.exports=!Fa||bp(function(){var r;return Qe(Qe.call)||!Qe(Object)||!Qe(function(){r=!0})||r})?qa:Qe});var za=p((cv,Ga)=>{"use strict";var Ha=Ur(),xp=Da(),Sp=ye(),wp=Me(),Ap=wp("species"),Ua=Array;Ga.exports=function(r){var e;return Ha(r)&&(e=r.constructor,xp(e)&&(e===Ua||Ha(e.prototype))?e=void 0:Sp(e)&&(e=e[Ap],e===null&&(e=void 0))),e===void 0?Ua:e}});var Ka=p((lv,Wa)=>{"use strict";var Rp=za();Wa.exports=function(r,e){return new(Rp(r))(e===0?0:e)}});var Qa=p(()=>{"use strict";var Op=je(),Pp=Oa(),kp=Ve(),Vp=_e(),Mp=$e(),Np=Ka();Op({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=kp(this),n=Vp(t),i=Np(t,0);return i.length=Pp(i,t,t,n,0,e===void 0?1:Mp(e)),i}})});var Xa=p(()=>{"use strict";var Lp=vt();Lp("flat")});var Za=p((mv,Ya)=>{"use strict";Qa();Xa();var jp=yt();Ya.exports=jp("Array","flat")});var eo=p((fv,Ja)=>{"use strict";var $p=Za();Ja.exports=$p});var ro=p((vv,to)=>{"use strict";var _p=eo();to.exports=_p});var un="1.0.34-dev.740b6a98.0";var Ht=class{constructor(e){this.layout=e}},et=class extends Ht{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};function pn(r){return"features"in r}var me=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&pn(this.options)&&this.options.features[e]}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){var e;return((e=this.container.controls)==null?void 0:e.reduce((t,n)=>{let i=n.type.trim().toLowerCase(),s=this.factories.get(i);if(s){let o=s(n,this.options);if(o)return[...t,o]}return[...t]},[]))||[]}};function Ut(r,e=1){let t="0",n="0",i="0";return r.length===4?(t="0x"+r[1]+r[1],n="0x"+r[2]+r[2],i="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],n="0x"+r[3]+r[4],i="0x"+r[5]+r[6]),`rgba(${+t},${+n},${+i},${e})`}var hn="interactive",j={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},dn=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(dn||{}),mn=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(mn||{}),fn=(n=>(n.start="left",n.end="right",n.center="center",n))(fn||{}),tt=({target:r,props:e})=>{var t,n,i;r.style.alignItems=(t=(e==null?void 0:e.gravityVertical)&&dn[e.gravityVertical])!=null?t:"center",r.style.justifyContent=(n=(e==null?void 0:e.gravityHorizontal)&&mn[e.gravityHorizontal])!=null?n:"center",r.style.textAlign=(i=(e==null?void 0:e.alignment)&&fn[e.alignment])!=null?i:"center"},rt=({target:r,props:e,fallback:t,dependsOn:n})=>{var i,s,o,c,a,l;r.style.color=(s=(i=e==null?void 0:e.text)==null?void 0:i.color)!=null?s:t.textColor,r.style.fontSize=`calc(${n.height} * ${(c=(o=e==null?void 0:e.text)==null?void 0:o.size)!=null?c:t.textSize})`,r.textContent=(l=(a=e==null?void 0:e.text)==null?void 0:a.value)!=null?l:t.textContent},nt=({target:r,props:e,fallback:t})=>{var n,i,s,o;r.style.backgroundColor=Ut((i=(n=e==null?void 0:e.background)==null?void 0:n.color)!=null?i:t.backgroundColor,(o=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?o:t.backgroundAlpha)},it=({target:r,props:e,fallback:t,dependsOn:n})=>{var i,s,o,c,a,l,y,f,v,C,w;r.style.border=`calc(${n.height} * ${(o=(s=(i=e==null?void 0:e.shape)==null?void 0:i.border)==null?void 0:s.width)!=null?o:t.borderWidth}) solid ${Ut((l=(a=(c=e==null?void 0:e.shape)==null?void 0:c.border)==null?void 0:a.color)!=null?l:t.borderColor,(v=(f=(y=e==null?void 0:e.shape)==null?void 0:y.border)==null?void 0:f.alpha)!=null?v:t.borderAlpha)}`,r.style.borderRadius=`calc(${n.height} * ${(w=(C=e==null?void 0:e.shape)==null?void 0:C.roundCorners)!=null?w:t.roundCorners})`},fe=({target:r,layoutParams:e,fallback:t})=>{var i;let n=(i=e.angle)!=null?i:t.angle;n=n&&n*-1,r.style.transform=`rotate(${n}rad)`};var Gt="int",ie=(n=>(n.AREA=`${Gt}_area`,n.TEXT=`${Gt}_text`,n.BUTTON=`${Gt}_bttn`,n))(ie||{});function vn(r){return"features"in r}var ve="interactive-control",V={common:ve,wrapper:`${ve}-wrapper`,disabled:`${ve}-disabled`,button:`${ve}-button`,area:`${ve}-area`,text:`${ve}-text`};var ne=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){var i;let t=document.createElement("div");t.classList.add(V.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=((i=this.control.layoutParams.innerSizesDependOn)!=null?i:j.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:t,dimensions:n}}createClickListener(e){return t=>{t.stopPropagation(),e()}}featureIsEnabled(e){return this.options&&vn(this.options)&&this.options.features[e]}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{var i;switch(t.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),(i=this.container)==null||i.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){var e,t;(e=this.container)!=null&&e.element&&this.clickListener&&((t=this.container)==null||t.element.removeEventListener("click",this.clickListener))}};var st=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new zt(r,e)},zt=class extends ne{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(V.common,V.area),n.setAttribute("data-testid",ie.AREA),nt({target:n,props:this.control.props,fallback:{...j,backgroundColor:"transparent"}}),it({target:n,props:this.control.props,fallback:{...j,borderAlpha:0},dependsOn:this.container.dimensions}),fe({target:n,layoutParams:this.control.layoutParams,fallback:j}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(V.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(V.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var at=r=>{let e=document.createElement("span");switch(r){case"Button":case"button":{let t=document.createElement("div"),n={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(t.style,n),t.append(e);let i={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,i),t}default:{let t={display:"inline-block",whiteSpace:"break-spaces",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",maxHeight:"100%",wordBreak:"break-all"};return Object.assign(e.style,t),e}}};var ot=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Wt(r,e)},Wt=class extends ne{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var o;if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(V.common,V.button),n.setAttribute("data-testid",ie.BUTTON),fe({target:n,layoutParams:this.control.layoutParams,fallback:j}),nt({target:n,props:this.control.props,fallback:j}),it({target:n,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=at(this.control.type.trim().toLowerCase()),s=(o=i.firstElementChild)!=null?o:i;rt({target:s,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(V.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(V.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var yn=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Kt(r,e)},Kt=class extends ne{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var o;if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(V.common,V.text),n.setAttribute("data-testid",ie.TEXT),fe({target:n,layoutParams:this.control.layoutParams,fallback:j}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=at(this.control.type.trim().toLowerCase()),s=(o=i.firstElementChild)!=null?o:i;rt({target:s,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}};var Qt="interactive-container",q={common:Qt,hidden:`${Qt}-hidden`,disabled:`${Qt}-disabled`};var ct=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new Xt(r,e,t)},Xt=class extends me{constructor(t,n,i){super(t,i);this.containerElement=null;this.rootElement=n,this.layout=new et(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ot),this.addControlFactory("text",yn),this.addControlFactory("area",st)}createView({eventCallback:t}){let n=document.createElement("div");return n.classList.add(q.common,q.disabled),requestAnimationFrame(()=>{n.classList.remove(q.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout}}),i.setEvents(t)}),this.rootElement.append(n),this.isRemoved=!1,this.containerElement=n,n}hide(){let t=this.getElement();t&&t.classList.add(q.hidden)}show(){let t=this.getElement();t&&t.classList.remove(q.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(q.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(q.disabled),this.controls.forEach(n=>n.disable()),this.isDisabled=!0)}removeView(){let t=this.getElement();t&&(this.controls.forEach(n=>n.removeListeners()),t.remove(),this.isRemoved=!0,this.containerElement=null)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(t,n){n&&this.controls.forEach(i=>{i.onProgress(t)})}onResize(t){t&&this.controls.forEach(n=>{n.onResize()})}};var Ro=J(Ar(),1);import{combine as Yp,InterfaceLanguage as Zp,Observable as So,once as Jp,Subject as $,Subscription as Zr,ValueSubject as _,fromEvent as wo}from"@vkontakte/videoplayer-shared/es2018";import{InteractiveInterfaceClick as Ze}from"@vkontakte/videoplayer-statistics/es2018";import{loadVKLangPack as Yl}from"@vkontakte/videoplayer-shared/es2018";function Fe(r,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>r(...n),e)}}var ae=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,qe=r=>ae(r,"Object"),bt=r=>ae(r,"String"),Ct=r=>ae(r,"Array"),gt=r=>ae(r,"Number"),gs=r=>ae(r,"Function");var Rr=r=>gt(r)&&!isNaN(r);var oe=r=>qe(r)&&Object.keys(r).length===0,Or=r=>Ct(r)&&!r.length;var Be=(r,e)=>bt(r)&&(e?r.trim():r).length;var Es="video_interactive",Is="videoint";var Ts=250,De=class{constructor(e){this.handleZoomChange=Fe(e=>{this.lastZoomInfo=e},Ts);this.onResize=e=>{var n;if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&((n=this.ngEditor)==null||n.zoomTo(t)),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{var t,n,i;if(this.manifest){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.call(this,"Chapter id is not found");return}this.visitedChapterIds.add(e.id),(n=this.ngEditor)==null||n.selectChapter(e.id),(i=this.ngEditor)==null||i.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{var n;if(this.isReady=!1,!gt(e.graph.edit.chapters[0].x)){(n=this.onError)==null||n.call(this,"Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:i,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=i!=null?i:"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Zl(e),this.resizeObserver=new ResizeObserver(Fe(this.onResize,Ts)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){var t;this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),(t=this.ngEditor)==null||t.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){var t;(t=this.ngEditor)==null||t.updateVideosInfo(e)}async show(){var e;this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&((e=this.ngEditor)==null||e.focusChapter(this.currentChapterId)),this.isHidden=!1)}async initNgEditor(){var n;if(!this.manifest)return;let e;try{e=await Yl(this.lang,Es,Is)}catch(i){(n=this.onError)==null||n.call(this,"Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:i,...s})=>{var o;i==="openPreview"&&"chapterId"in s&&((o=this.onOpenPreviewClick)==null||o.call(this,s.chapterId))}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.manifest=null,this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Zl(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var He=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,n=!1,i=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let o=s.startTime-e;if(o<=i&&(s.endTime&&i<=s.endTime||s.endTime===null)){n=!0;break}i<o&&(t=t===-1?o:Math.min(t,o))}return!n&&t!==-1?t:null}}};import{isSupportedManifest as It,ContainerTypes as Om,ControlTypes as Tt,EventActionTypes as O,EventTypes as Pm,migrateManifestToLatestVersion as As,compareVersions as km}from"@interactiveplatform/movika-manifest";var xs={metadata:"Object",chapters:"Array"},Ss=r=>{if(!qe(r))return!1;for(let e in xs)if(!r[e]||!ae(r[e],xs[e]))return!1;return It(r.metadata.version)},Et=r=>r.type===Tt.Text,Em=r=>r.type===Tt.Button,Im=r=>r.type===Tt.Area,Tm={Choice:"Choice",TextInput:"TextInput"},xm={Button:"Button",Area:"Area",Text:"Text"},Sm={onClick:"onClick",onSuspense:"onSuspense"},ws={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var L=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var xt=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let n=this.listeners[e]||[];for(let i=n.length;i>0;i--)if(n[i]===t){n.splice(i,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(i=>{i(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var St=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{gs(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as su}from"@vkontakte/videoplayer-shared/es2018";var wt=class{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!=null?n:[]}}async exec(e,t){return Jl(...this.loaders[e])(t)}};function Jl(...r){return async function(t){let n=[...r];for(;n.length>0;)t=await n.shift()(t);return t}}function Ue(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function At({actions:r,errors:e,chapterId:t,...n}){if(t){let i=r.getManifest();if(i){let s=r.getChapter(i.chapters,t);if(s){let o=r.getMedia(i.media,s.videoId),c=r.getGraph(i.graph,s.id);return o?{...n,actions:r,errors:e,result:{chapter:s,media:o,graph:c}}:{...n,errors:Ue(e,At.name,"Could not find media"),actions:r}}}}return{...n,errors:Ue(e,At.name,"Could not find chapter"),actions:r}}var Rt=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;let n=this.listeners[e];for(let i=0,s=n.length;i<s;i++)if(n[i].callback===t){n.splice(i,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let n=this.listeners[e.type].slice();for(let i=0,s=n.length;i<s;i++){let o=n[i];try{o.callback.call(this,e)}catch(c){Promise.resolve().then(()=>{throw c})}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}},Ie=class extends Rt{constructor(){super(),this.listeners||Rt.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Ge=class{constructor(){Object.defineProperty(this,"signal",{value:new Ie,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(i){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=e;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(i){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(Ge.prototype[Symbol.toStringTag]="AbortController",Ie.prototype[Symbol.toStringTag]="AbortSignal");function Ot(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function Pr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=r;if(!Ot({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||i)&&(s=function(l,y){let f;y&&y.signal&&(f=y.signal,delete y.signal);let v=new t(l,y);return f&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),v},s.prototype=t.prototype);let o=e;return{fetch:(a,l)=>{let y=s&&s.prototype.isPrototypeOf(a)?a.signal:l?l.signal:void 0;if(y){let f;try{f=new DOMException("Aborted","AbortError")}catch(C){f=new Error("Aborted"),f.name="AbortError"}if(y.aborted)return Promise.reject(f);let v=new Promise((C,w)=>{y.addEventListener("abort",()=>w(f),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([v,o(a,l)])}return o(a,l)},Request:s}}var ze=Ot({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Rs=ze?Pr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,kr=ze?Rs.fetch:window.fetch,Qm=ze?Rs.Request:window.Request,Xm=ze?Ge:window.AbortController,Ym=ze?Ie:window.AbortSignal;var Vr=(r="",e="")=>{let t=r.split("."),n=e.split("."),i=0;for(let s=0;s<Math.max(t.length,n.length)&&!i;s++)t[s]>n[s]?i=1:t[s]<n[s]?i=-1:i=0;return i};var eu=async r=>{try{let e={},t;if(bt(r)){t=new URL(r).href;let i=await kr(t);if(!i.ok)return{};e=await i.json()}else if(qe(r))e=r;else return{};if(!Ss(e))return{};let n=e.metadata.media;if(bt(n)&&!("media"in e))try{let i;t?i=new URL(n,t).href:(i=new URL(n).href,t=i);let s=await kr(i);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch(i){return nu(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Os(r){let{manifest:e,manifestURL:t}=await eu(r);if(!e)throw new Error("Failed on fetch");let n=As(e);return n.media=tu(n.media,t),delete n.metadata.media,n}function Pt(r,e){if(e)return r.find(t=>t.id===e)}function Mr(r,e){var t,n;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(i=>i.id===e):(n=r.view)!=null&&n.chapters?r.view.chapters.find(i=>i.id===e):void 0}function Nr(r,e){return r.videos.find(t=>t.id===e)}function tu(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(n=>{let i="url"in n?n.url:"",s=ru(i,e);return{...n,url:s||i}})}))}}function ru(r="",e){try{return new URL(r,e).href}catch(t){return""}}function nu(r){return Vr(r,"3.2.0")>=0}var kt=r=>Ct(r)&&!Or(r),X=r=>r.order==="end",Vt=r=>Ct(r.containers)&&!Or(r.containers)&&X(r),Ps=(r,e)=>{var n;let t=r*1e3;return kt(e.controls)&&t<((n=e.startTime)!=null?n:0)},Lr=(r,e)=>{var n,i;let t=r*1e3;return kt(e.controls)&&t>=((n=e.startTime)!=null?n:0)&&t<=((i=e.endTime)!=null?i:1/0)};var ce=(r=[])=>r.some(e=>e.action.type==="expect"),jr=(r=[])=>r.find(e=>e.action.type==="expect"),iu=r=>(r==null?void 0:r.length)===1,Te=r=>iu(r)&&Et(r[0]);function ks(r,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?r({...e[0],...t}):r(...e,...t)}var Vs=(r,e)=>{let t=g=>{let m=e.find(({container:A})=>A.container.id===g);return m==null?void 0:m.container.isRemoved},n=ce(r.events)&&!t(r.id),i=(g,m=!1,A=!1)=>{let h=A?"every":"some";return g.controls[h](u=>{var E;let d=m?g.endTime===r.endTime:!0;return((E=u.events)==null?void 0:E[h](I=>{var b;return((b=I.action)==null?void 0:b.type)===ws.openURI}))&&d})},s=g=>g.some(({container:m})=>i(m.container,!0,!1)&&!m.isRemoved),o=g=>g.every(({container:m})=>m.isRemoved?!0:i(m.container,!0,!0)),c=e.filter(({container:g})=>g.container.id!==r.id&&ce(g.container.events)&&g.container.endTime===r.endTime&&!g.isRemoved).length,a=g=>g.controls.some(m=>{var A;return(A=m.events)==null?void 0:A.some(h=>{var u,d;return(d=(u=h.action)==null?void 0:u.args)==null?void 0:d.shouldOpenNow})}),l=n||c>0,y=s(e),f=i(r),v=o(e),C=n?!1:c>0,w=a(r);return{isExpectTime:l,hasOtherExpect:c>0,hasOpenURIEvent:y,hasOpenURIEventInCurrentContainer:f,isAllOpenURIEventsValid:v,isExpectEventForCurrentContainer:C,hasShouldOpenNowEvent:w}};var xe=class extends wt{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new su(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var i;this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ue},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await Os((i=n.result)!=null?i:t),this}async setInitial(){return this.setNext()}async setNext(t=(n=>(n=this.manifest)==null?void 0:n.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",At({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Mr,getChapter:Pt,getMedia:Nr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ue},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),i.result&&(this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){var n;return this.getByChapterId((n=this.manifest)==null?void 0:n.metadata.initChapterId)||null}getByChapterId(t=(n=>(n=this.manifest)==null?void 0:n.metadata.initChapterId)()){if(!t||!this.manifest)return null;let i=Pt(this.manifest.chapters,t);if(i){let s=Nr(this.manifest.media,i.videoId),o=Mr(this.manifest.graph,i.id);if(s)return{chapter:i,media:s,graph:o}}return null}getBranches(t=(n=>(n=this.chapter)==null?void 0:n.id)()){var i,s,o;if(t===((i=this.chapter)==null?void 0:i.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let c=Pt(((o=this.manifest)==null?void 0:o.chapters)||[],t);return this.getByBranches(c==null?void 0:c.branches)}}getByBranches(t=[]){return t.reduce((n,i)=>{let s=this.getByChapterId(i.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){var t,n;return((t=this.chapter)==null?void 0:t.id)===((n=this.manifest)==null?void 0:n.metadata.initChapterId)}isEndChapter(){return this.chapter?X(this.chapter):!1}};var ga=J(Mt(),1);import{Player as Wu}from"@vkontakte/videoplayer-core/es2018";import{Subscription as Dr,Tracer as Ku,ValueSubject as Qu}from"@vkontakte/videoplayer-shared/es2018";var ha=r=>{let e=r.variants.find(t=>{var n;return((n=t.payload)==null?void 0:n.type)==="vk"});if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};var da=J(Mt(),1);function qr(){let r=new Map;function e({listId:s=Math.random().toString(),itemId:o=Math.random().toString(),...c}){let a=r.get(s),l={...c};return a?a[o]=l:r.set(s,{[o]:l}),{listId:s,itemId:o,...c}}function t(s){var o,c;s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),(o=s.statistics)==null||o.oneStat.destroy(),(c=s.statistics)==null||c.statSubscription.unsubscribe()}function n(s,o){let c=r.get(s);if(!c)throw Error("Can't remove. Not find.");if(o){let a=c[o];a&&t(a),delete c[o],Object.keys(c).length||r.delete(s)}else{for(let a of(0,da.default)(c))t(a);r.delete(s)}}function i(){for(let s of r)n(s[0])}return{createPlayer:e,removePlayer:n,map:r,removeAll:i}}var Se=J(Nt(),1);function Br(r,e=[]){var s,o,c;let t={},n,i=!e.length;for(let a of r.variants)if(!n&&"cover"in a&&(n=a.cover),"url"in a)switch(a.type.toLowerCase()){case"mp4":(i||(0,Se.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[(s=a.standard)!=null?s:"Invariant quality"]:a.url});break;case"mpeg":(i||(0,Se.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[(o=a.standard)!=null?o:"Invariant quality"]:a.url});break;case"hls":(i||(0,Se.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:a.url}});break;case"dash":(i||(0,Se.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:a.url}});break;default:break}return{sources:t,thumbUrl:n,title:(c=r.title)!=null?c:""}}var We=(r,e)=>{let t=r.info.currentQuality$.getValue(),n=r.info.availableQualities$.getValue();t!==e&&(0,Se.default)(n,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Xu=2;function Hr(r){let e=qr(),t=new Dr,n={},i=null,s=!1,o,c=new Qu(null);r&&a(r);function a(m){i=m}function l(m,A,h){var E;if(!i)throw Error("need to set interactive controller");if(!i.options)return;let d=((E=e.map.get(m))!=null?E:{})[A];if(d){n={chapterId:h,listId:m,itemId:A,...d};let I=n.player;n.subscription.add(I.info.currentQuality$.subscribe(b=>{let T=I.info.position$.getValue(),P=I.info.isAutoQualityEnabled$.getValue();if(!(!b||!T||P))for(let x of e.map)(0,ga.default)(x[1]).forEach(({player:M})=>{We(M,b)})})).add(I.events.started$.subscribe(()=>{y(A)})),d.container.remove(),i.setPlayer(d.player),s||(i.init(),s=!0),c.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function y(m){if(!i)throw Error("need to set interactive controller");if(oe(n)||m!==n.itemId)return;let A=i.getChapterBranches(),h=new Set;for(let u of A)h.has(u.media.id)||(await v({media:u.media,chapterId:u.chapter.id,setAsActive:!1,title:u.chapter.label}),h.add(u.media.id))}async function f({chapter:{id:m},manifestVideo:A}){if(oe(n)||!i)return;let h=n.player.info.muted$.getValue(),u=n.player.info.currentQuality$.getValue(),d=n.player.info.isAutoQualityEnabled$.getValue(),E=n.player.info.volume$.getValue(),I=n.player.info.currentPlaybackRate$.getValue(),b=!d,T=!1;for(let P of e.map)if(P[0]===A.id&&!i.state.isReplay$.getValue()){let x=Object.keys(P[1]);for(let M of x)M===n.itemId?(x.length<Xu||(T=!0),e.removePlayer(P[0],M)):(T=!0,l(P[0],M,m),b?We(n.player,u):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h),n.player.setPlaybackRate(I))}else e.removePlayer(P[0]);T||(await v({media:A,chapterId:m,setAsActive:!0,playbackRate:I}),b?We(n.player,u):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h))}async function v({media:m,chapterId:A,prefetch:h=!0,setAsActive:u=!0,autoplay:d=!1,preferredExt:E,title:I,playbackRate:b}){var Jr,en,tn,rn,nn;let T=Math.random().toString(),P=document.createElement("div");o.append(P);let x;if((Jr=i==null?void 0:i.options)!=null&&Jr.vkVideoLoader){let Je=ha(m);Je.length&&(x=await i.options.vkVideoLoader(...Je))}let M=((en=i==null?void 0:i.options)==null?void 0:en.coreConfig)||void 0,U={...M,configName:[...(tn=M==null?void 0:M.configName)!=null?tn:[],"interactive"]},G={container:P,...((rn=x==null?void 0:x.videos)==null?void 0:rn[0])||{sources:Br(m,E).sources},title:I,failoverHosts:(x==null?void 0:x.failoverHosts)||[]},z=new Wu(U,Ku.createRootTracer());z.initVideo(G);let Z=null;if(x!=null&&x.videos&&(i!=null&&i.options.createOneStat)){let Je=x.videos[0],Dt=i.options.createOneStat(Je),sn=new Dr;Dt&&(sn.add(Dt.attachTo(z)),Z={oneStat:Dt,statSubscription:sn})}let he=new Dr,Oo=(nn=n==null?void 0:n.player)==null?void 0:nn.info.isAutoQualityEnabled$.getValue();he.add(z.events.canplay$.subscribe(function(){Oo||We(z,n.player.info.currentQuality$.getValue()),b&&z.setPlaybackRate(b)}));let de=e.createPlayer({listId:m.id,itemId:T,player:z,container:P,sources:Br(m,E).sources,config:G,subscription:he,statistics:Z});return u&&l(m.id,de.itemId,A),d&&de.player.play(),h&&!d&&de.player.prepare(),{player:de.player,config:de.config,statistics:de.statistics}}function C(){w(),i=null,o.remove()}function w(){t.unsubscribe(),e.removeAll(),n={},s=!1}async function g(){if(!i)throw Error("need to set interactive controller");w(),o=document.createElement("div");let{media:m,chapter:A}=i.getCurrentChapter();m&&A?(t.add(i.events.chapterChanged$.subscribe(f)),await v({media:m,chapterId:A.id,title:A.label})):console.error("not found")}return{...e,init:g,setInteractiveController:a,createPlayer:v,removeAll:C,getActivePlayer:function(){return n},activePlayerChanged:c}}var R={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ke={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},k={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var Ia=J(Nt(),1);import{Subscription as Yu}from"@vkontakte/videoplayer-shared/es2018";var Lt=class{constructor({player:e,container:t,branches:n,selectBranches:i,interactiveEvents:s,globalEvents:o,globalEventEmitter:c,getContainerEventState:a,permanentTextControls:l,interactiveTimeOpenUri:y,disabledControls$:f,onRemove:v}){this.hide=()=>{setTimeout(()=>{var e,t;this.gameState!==4&&(ce(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&((t=(e=this.container).hide)==null||t.call(e)),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{var t,n,i,s;if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:o}=this.getContainerEventState();if((n=(t=this.container).show)==null||n.call(t),this.interactiveTimeOpenUri&&o)return;this.emitContainerVisibilityEvent(!0,!1)}else{let o={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(a,l)=>{let{isExpectTime:y,hasOtherExpect:f,hasOpenURIEvent:v,hasOpenURIEventInCurrentContainer:C,isAllOpenURIEventsValid:w,hasShouldOpenNowEvent:g}=this.getContainerEventState(),m=this.interactiveTimeOpenUri&&!C,A=this.interactiveTimeOpenUri&&C;if((!this.interactiveTimeOpenUri||m)&&(this.isSelectedControlEvent=!0),a!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||m)){if(this.interactiveTimeOpenUri){let h=!f&&!w&&C;h&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:h})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&v&&this.gameState!==5){if(A){let u=((d,E,I,b)=>!d&&!E&&I||d&&!E&&I&&!b||d&&!E&&I&&b)(y,f,w,this.isSelectedContainerEvent);this.fakeRemoveView(u)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!y||!f||!g)&&(this.selectBranches.stopExpect(),l())}},isEOV:()=>this.gameState===4},c=ks(this.selectBranches.onControlEvent,o);this.container.createView({eventCallback:c}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&((s=(i=this.container).disable)==null||s.call(i))}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{var l,y,f;let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,Ia.default)(i,this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(Ps(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Lr(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let v=this.gameState;this.gameState=3,v===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:v}=this.getContainerEventState(),C=this.selectBranches.state.isExpect,w=this.interactiveTimeOpenUri&&v;if(w&&!C){let g=this.container.getElement();g&&(g.style.visibility!=="hidden"&&((y=(l=this.container).hide)==null||y.call(l)),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!w&&this.removeView()}let o=Lr(s,this.container.container),c=this.container.container.startTime?[this.container.container.startTime,(f=this.container.container.endTime)!=null?f:1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:c,currentTime:s,isInteractiveTime:o};this.container.onProgress(s*1e3,o),this.globalEventEmitter.emit(R.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=n,this.selectBranches=i,this.subscription=new Yu,this.player=e,this.interactiveEvents=s,this.getContainerEventState=a,this.isPermanentText=l&&Te(t.container.controls),this.interactiveTimeOpenUri=y,this.disabledControls$=f,this.onRemove=v,this.globalEventEmitter=c,this.gameState=0,this.globalEvents=o,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(R.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.visibility,visibility:e,isFirst:t}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e,isFirst:t})):(this.globalEventEmitter.emit(R.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,n,i,s;e?(n=(t=this.container).disable)==null||n.call(t):(s=(i=this.container).enable)==null||s.call(i)}))}selectContainerEvent(e=!1){var n,i;let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:(n=this.container.container.endTime)!=null?n:1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec((i=this.container.container.endTime)!=null?i:1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:ce(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(R.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,(e=this.onRemove)==null||e.call(this)}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}destroy(){var e;this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var Ta=(r=[])=>r.reduce((e,t,n)=>{var s,o,c;let i=((s=t==null?void 0:t.controls)!=null?s:[]).filter(a=>!Et(a));if(kt(i)){let a=[(o=t.startTime)!=null?o:0,(c=t.endTime)!=null?c:1/0],l={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[l],range:a});else{let y=[],f=-1/0,v=1/0,C=[],w=[];for(let g=0;g<e.length;g++){let m=e[g];if(w.push(...m.subjects),m.range[0]<v&&(v=m.range[0]),m.range[1]>f&&(f=m.range[1]),a[0]>=m.range[0]&&a[1]<=m.range[1])return e[g].subjects.push(l),e;a[0]<m.range[0]&&a[1]>m.range[0]&&(y.push(g),C=C.concat(m.subjects)),a[0]>=m.range[0]&&a[0]<=m.range[1]&&(y.push(g),C=C.concat(m.subjects),a[0]=m.range[0]),a[1]>=m.range[0]&&a[1]<=m.range[1]&&(y.push(g),C=C.concat(m.subjects),a[1]=m.range[1])}if(w.push(l),a[0]<=v&&a[1]>=f)return[{subjects:w,range:a}];y.length&&y.reverse().forEach(g=>{e.splice(g,1)}),e.push({subjects:C.concat([l]),range:a})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var io=J(Nt(),1),Wr=J(Mt(),1),so=J(ro(),1);function no(){let r={};function e(){for(let c in r)Object.prototype.hasOwnProperty.call(r,c)&&delete r[c]}function t(c){let a={};for(let l in r)+l<=c&&(a[l]=r[l]);return a}function n(c){let a={};for(let l in r)+l>=c&&(a[l]=r[l]);return a}function i({timestamp:c,priority:a,initiator:l}){var y;if(Rr(c)){let f=(y=r[c])!=null?y:null;if(f&&a&&Be(a,!0)){let v={},C=f[a];if(C&&(v={...v,...C}),v=oe(v)?null:v,v&&Be(l,!0)){let w=v[l];return w!=null?w:null}return v}return f}return null}function s({timestamp:c,priority:a,initiator:l}){if(Rr(c))if(r[c]){if(a&&Be(a,!0))if(r[c][a]){if(l&&Be(l,!0))if(r[c][a][l]){if(delete r[c][a][l],!oe(r[c][a]))return!0}else return!1;if(delete r[c][a],!oe(r[c]))return!0}else return!1;return delete r[c]}else return!1;return!1}function o({timestamp:c,priority:a,initiator:l,...y}){var f,v,C;(v=(f=r[c])==null?void 0:f[a])!=null&&v[l]?r[c][a][l].push({...y}):(C=r[c])!=null&&C[a]?r[c][a]={...r[c][a],[l]:[{...y}]}:r[c]?r[c]={...r[c],[a]:{[l]:[{...y}]}}:r[c]={[a]:{[l]:[{...y}]}}}return{map:r,remove:s,add:o,removeAll:e,get:i,getLte:t,getGte:n}}var Fp=[O.expect,O.setNextBranch],qp=1/0;function ao(r,e){let t=r,n,i=Bp(e),s=no(),o,c=()=>{C(),h()},a=u=>{s.add.call(void 0,u),g()},l=(u=[])=>{for(let d of u)if(d.action(),(0,io.default)(Fp,d.actionType))break},y=(u=1/0)=>{var b,T,P;let d=$t((b=s.get({timestamp:u,priority:"control"}))!=null?b:{}),E=$t((T=s.get({timestamp:u,priority:"container"}))!=null?T:{}),I=$t((P=s.get({timestamp:u,priority:"chapter"}))!=null?P:{});return[...d,...E,...I]},f=u=>{i.isReady(u)&&l(y(u))},v=()=>{var u;l([...$t((u=s.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},C=()=>{n&&(o==null||o.unsubscribe(),n=void 0)},w=u=>{},g=()=>{n||(n=()=>setTimeout(()=>{f(1/0)}),o=t.events.ended$.subscribe(n))},m=u=>{C(),t=u},A=u=>{u.priority==="container"&&i.resetCalled(u.timestamp),s.remove(u)},h=()=>{i.release(),s.removeAll()};return{setPlayer:m,add:a,remove:A,exec:f,execEndOfVideo:v,listen:g,unlisten:C,release:c,containersEventsCallState:i,getPreparedToExecActions:y}}function Bp(r){let e=new Map;return{setCalled:({timestamp:c,id:a})=>{let l=e.get(c);l&&l[a]!==void 0&&(l[a]=!0)},setData:(c=[])=>{var a;for(let l of c){let y=(a=l.endTime)!=null?a:qp,f=e.get(y);e.set(y,{...f,[l.id]:!1})}},resetCalled:c=>{let a=e.get(c);if(a)for(let l in a)a[l]=!1},isReady:c=>{let a=e.get(c);if(!a)return!0;let l=(0,Wr.default)(a);return r?l.some(f=>f):!l.some(f=>!f)},release:()=>e.clear()}}function $t(r){return(0,so.default)((0,Wr.default)(r)).sort(e=>e.actionType===O.expect?-1:1)}var oo={videoContentHeight:0,videoContentWidth:0},co=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return oo;let{clientHeight:n,clientWidth:i}=r.experimental.element$.getValue()||{};if(!(n&&i))return oo;let s=e/t,o=n/i,c,a;return o>s?(a=i,c=i*s):o<s?(a=n/s,c=n):(a=i,c=n),{videoContentWidth:a,videoContentHeight:c}};var Dp=250;function lo(r){let e,t=new ResizeObserver(c=>{s(c),e=s.bind(null,c)});function n(c){let{parentElement:a,player:l}=r();if(a&&l){let{videoContentWidth:y,videoContentHeight:f}=co(l);a.style.setProperty("--interactive-content-width",`${y}px`),a.style.setProperty("--interactive-content-height",`${f}px`),a.style.setProperty("--interactive-width",`${c[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${c[0].contentRect.height}px`)}}function i(){let{parentElement:c}=r();c.removeAttribute("style")}let s=Fe(c=>{let{fns:a=[]}=r();n(c);for(let l of a)l()},Dp);function o(){e=void 0,t.disconnect(),i()}return{resizeObserver:t,calc:()=>{e==null||e()},release:o}}var Hp=r=>Math.floor(Math.random()*r),po=r=>{var i;let e=r.length,t=1/0,n=null;for(;e--;){let s=r[e],o=(i=s.weight)!=null?i:1;o<t&&(t=o,n=s)}return n},ho=r=>{var i;let e=r.length,t=-1/0,n=null;for(;e--;){let s=r[e],o=(i=s.weight)!=null?i:0;o>t&&(t=o,n=s)}return n};var mo=r=>{let e=r.length,t=Hp(e);return r[t]},uo=1,fo=r=>{var n,i;let e=0;for(let s=0;s<r.length;++s)e+=(n=r[s].weight)!=null?n:uo;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(i=r[s].weight)!=null?i:uo,e>=t)return r[s];return r[r.length-1]};var vo={shouldOpenNow:!0,isDetachContainer:!0},yo="after-expect";var Kr=(r,e=!1)=>({...r,args:e?{...r.args,...vo}:{...vo,...r.args}}),go=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:n})=>{let i={isExpect:!1},s=()=>{i.isExpect&&(i.isExpect=!1)},o=({action:h,controlType:u,controlId:d,containerId:E,branches:I=[],onEvent:b,isEOV:T=()=>!1,isDisabled:P=()=>!1})=>{let x=Kr(h,T()),M={timestamp:1/0,priority:"control",initiator:d,actionType:x.type},U=P(),G=r.emit.bind(r,R.interactives,{subjectId:d,subjectType:u,subjectName:"control",type:U?k.actionChoiceCanceled:k.actionChoice,actionType:h.type,payload:{invokeImmediately:x.args.shouldOpenNow,containerId:E,...x.args}}),z=()=>{e.interactiveActionChoice$.next({subjectId:d,subjectType:u,subjectName:"control",type:U?"action-choice-canceled":"action-choice",actionType:h.type,payload:{invokeImmediately:x.args.shouldOpenNow,containerId:E,...x.args}})};if(U){G(),z();return}switch(x.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{let Z=I.find(he=>he.id===x.args.branchId);if(!Z)return;b(x.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),z(),x.args.shouldOpenNow?g({subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{chapterId:Z.chapterId,autoSelect:!1}}):n.add({...M,action:g.bind(null,{subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{chapterId:Z.chapterId,autoSelect:!1}})});return}case O.continuePlayback.trim().toLowerCase():{b(x.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),z(),x.args.shouldOpenNow?w({subjectId:d,subjectName:"control",subjectType:u,action:h}):n.add({...M,action:w.bind(null,{subjectId:d,subjectName:"control",subjectType:u,action:h})});return}case O.openURI.trim().toLowerCase():{b(x.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),z(),x.args.shouldOpenNow?A({subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{URI:h.args.uri}}):n.add({...M,action:A.bind(null,{subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{URI:h.args.uri}})});return}default:{let Z="Unexpected control event",he=new L(1,1,{message:Z});y(he,Z);return}}},c=({action:h,container:{id:u,endTime:d},branches:E=[],isEOV:I=!1,autoSelected:b=!1})=>{let T=Kr(h,I),P={timestamp:!T.args.shouldOpenNow||I?1/0:d!=null?d:1/0,priority:"container",initiator:u,actionType:T.type},x=r.emit.bind(r,R.interactives,{subjectId:u,subjectName:"container",type:k.actionChoice,actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),M=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"container",type:"action-choice",actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}})};switch(T.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{let U=E.find(G=>G.id===T.args.branchId);if(!U)return;x(),M(),n.add({...P,action:g.bind(null,{subjectId:u,subjectName:"container",action:T,payload:{chapterId:U.chapterId,autoSelect:b}})});return}case O.setMaxWeightBranch.trim().toLowerCase():return;case O.setMinWeightBranch.trim().toLowerCase():return;case O.setRandomBranch.trim().toLowerCase():return;case O.setWeightlessRandomBranch.trim().toLowerCase():return;case O.continuePlayback.trim().toLowerCase():{x(),M(),n.add({...P,action:w.bind(null,{subjectId:u,subjectName:"container",action:T})});return}case O.openURI.trim().toLowerCase():{x(),M(),n.add({...P,action:A.bind(null,{subjectId:u,subjectName:"container",action:T,payload:{URI:h.args.uri}})});return}default:{let U="Unexpected container event",G=new L(1,1,{message:U});y(G,U);return}}};function a({container:h,branches:u,isEOV:d=!1}){var I,b;let E=jr(h.events);if(E){let T=Kr(E.action,d);r.emit(R.interactives,{subjectId:h.id,subjectName:"container",type:k.actionChoice,actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"container",type:"action-choice",actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),n.add({timestamp:d?1/0:(I=h.endTime)!=null?I:1/0,priority:"container",initiator:h.id,actionType:O.expect,action:v.bind(null,{subjectId:h.id,subjectName:"container"})}),i.isExpect=!0}else for(let T of(b=h.events)!=null?b:[])c({action:T.action,container:h,branches:u,isEOV:d})}let l=({chapterId:h,action:u,branches:d=[]})=>{let E=r.emit.bind(r,R.interactives,{subjectId:h,subjectName:"chapter",type:k.actionChoice,actionType:u.type,payload:u.args}),I=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"chapter",type:"action-choice",actionType:u.type,payload:u.args})};switch(u.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{let b=d.find(T=>T.id===u.args.branchId);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setWeightlessRandomBranch.trim().toLowerCase():{let b=mo(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setRandomBranch.trim().toLowerCase():{let b=fo(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMaxWeightBranch.trim().toLowerCase():{let b=ho(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMinWeightBranch.trim().toLowerCase():{let b=po(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.continuePlayback.trim().toLowerCase():return E(),I(),w.bind(null,{subjectId:h,subjectName:"chapter",action:u});case O.openURI.trim().toLowerCase():return E(),I(),A.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:{let b="Unexpected chapter event",T=new L(1,1,{message:b});y(T,b);return}}};function y(h,u){console.error(u),e.error$.next(h),r.emit(R.errors,h)}function f(h){var d;let u=jr(h.events);if(u){if(X(h))return;r.emit(R.interactives,{subjectId:h.id,subjectName:"chapter",type:k.actionChoice,actionType:u.action.type,payload:u.action.args}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"chapter",type:"action-choice",actionType:u.action.type,payload:u.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:O.expect,action:v.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else(d=h.events)==null||d.forEach(E=>{let I=l({chapterId:h.id,action:E.action,branches:h.branches});I&&n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:E.action.type,action:I})})}let v=({subjectId:h,subjectName:u})=>{t.pause(),r.emit(R.interactives,{subjectId:h,subjectName:u,type:k.actionExecution,actionType:O.expect}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,type:"action-execution",actionType:O.expect})},C=({subjectId:h,subjectName:u})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),r.emit(R.interactives,{subjectId:h,subjectName:u,type:k.actionExecution,actionType:yo}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,type:"action-execution",actionType:yo})},w=({subjectId:h,subjectName:u,subjectType:d,action:E})=>{r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type})},g=({subjectId:h,subjectName:u,subjectType:d,action:E,payload:I})=>{I.behaviour="change-chapter",r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type,payload:I}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type,payload:I})},m=({subjectId:h,subjectName:u,subjectType:d,action:E,payload:I})=>{I.behaviour="change-manifest",r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type,payload:I}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type,payload:I})},A=({subjectId:h,subjectName:u,subjectType:d,action:E,payload:I})=>{if(!I.URI)return;let b=window.open(I.URI,"_blank","noopener,noreferrer");b&&(b.opener=null),r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type})};return{onControlEvent:o,onContainerEvent:c,onChapterEvent:l,onExpectEvent:v,expectEventHandler:C,setManifestChapterEvents:f,setManifestContainerEvents:a,stopExpect:s,state:i}};var Yr=J(Ar(),1);import{Subscription as Kp,Subject as Xr,ValueSubject as Xe}from"@vkontakte/videoplayer-shared/es2018";var Qr=(r,e)=>{let t={};return r.map(n=>{if(!t[n]){let i=e.chapters.find(o=>o.id===n);if(!i)return null;let s=e.media.videos.find(o=>i.videoId===o.id);if(!s)return null;t[n]=Eo(s)}return t[n]}).filter(Boolean)},Gp=r=>{for(let e of r.variants)if(zp(e)&&e.payload)return e.payload.id},zp=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Eo=r=>{let e=Gp(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},Wp=(r,e)=>{for(let t of r.media.videos)if(e===Eo(t)){for(let n of r.chapters)if(n.videoId===t.id)return n.id;return}},Io=(r,e)=>r.reduce((t,n)=>{let i=Wp(e,n);return i?[...t,i]:t},[]);var ee,le,ue,H,_t,te,re,Y,pe,we,Ae,Ye=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:i,settings:s}){this.state={history$:new Xe([]),hasPrevChapter$:new Xe(!1),prevChapter$:new Xe(null),isInitialChapter$:new Xe(!1),isGoBackLimited$:new Xe(!1)};F(this,ee,null);F(this,le);F(this,ue,!1);F(this,H,null);F(this,_t,null);this.events={inited$:new Xr,destroyed$:new Xr,error$:new Xr};F(this,te,null);F(this,re,null);F(this,Y,null);F(this,pe,new Kp);F(this,we,!1);F(this,Ae,0);var o;N(this,te,t),N(this,Y,e),N(this,re,n),N(this,ee,i),N(this,le,s),this.state.history$&&S(this,pe)&&((o=S(this,pe))==null||o.add(this.state.history$.subscribe(c=>{var a,l;this.state.prevChapter$.next((0,Yr.default)(c,-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((l=(a=S(this,H))==null?void 0:a.metadata)==null?void 0:l.initChapterId)),this.state.isGoBackLimited$.next(S(this,Ae)===S(this,le).maxLength-1)})))}async setManifest(e){if(!S(this,re)||!S(this,Y))return;N(this,H,e),await this.getProjectHistory();let t=this.getInitialChapterId();await S(this,re).setChapter({chapterId:t,pushToHistory:!1}),S(this,ue)||(N(this,ue,!0),this.events.inited$.next({initChapterId:t}))}get inited(){return S(this,ue)}async updateHistory(e,t=!0){var c;if(!S(this,H))return;S(this,we)?(N(this,we,!1),ln(this,Ae)._++):N(this,Ae,0);let n=S(this,H),i=e.length-S(this,le).maxLength,s=i>0?e.slice(i):e,o=Qr(s,n);if(N(this,_t,o),this.state.history$.next(s),!(!t||!S(this,ee)||!S(this,te)))try{await S(this,ee).save(S(this,te),o)}catch(a){let l=new L(1,5,"Unable to save interactive history");this.events.error$.next(l),(c=S(this,Y))==null||c.emit(R.errors,l)}}async goBack(){var n;if(!this.state||!S(this,re)){let i=new L(1,5,"Unable to save interactive history");return this.events.error$.next(i),(n=S(this,Y))==null?void 0:n.emit(R.errors,i)}N(this,we,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await S(this,re).setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){var i;if(!S(this,H)||!S(this,te))return;let e=S(this,H),t=[this.getInitialVideoId()];if(S(this,ee))try{let s=await S(this,ee).get(S(this,te));s.length&&(t=s)}catch(s){let o=new L(1,5,"Error while trying to fetch data");this.events.error$.next(o),(i=S(this,Y))==null||i.emit(R.errors,o)}let n=Io(t,e);this.state.history$.next(n)}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,Yr.default)(e,-1)||S(this,le).initChapterId||((t=S(this,H))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(S(this,H)){let e=this.getInitialChapterId();return Qr([e],S(this,H)).pop()}return null}destroy(){var e,t;N(this,te,null),N(this,ee,null),N(this,re,null),(e=S(this,pe))==null||e.unsubscribe(),N(this,pe,null),N(this,ue,!1),(t=S(this,Y))==null||t.emit(R.historyDestroyed),this.events.destroyed$.next(),N(this,Y,null)}};ee=new WeakMap,le=new WeakMap,ue=new WeakMap,H=new WeakMap,_t=new WeakMap,te=new WeakMap,re=new WeakMap,Y=new WeakMap,pe=new WeakMap,we=new WeakMap,Ae=new WeakMap;var Ft=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var i;let e=(i=this.rootElement.getContext("2d"))==null?void 0:i.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let s=3;s<n;s+=40)if(t[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let i;t&&(i=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&i&&this.restore(i),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var qt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
6
+ var Po=Object.create;var an=Object.defineProperty;var ko=Object.getOwnPropertyDescriptor;var Vo=Object.getOwnPropertyNames;var Mo=Object.getPrototypeOf,No=Object.prototype.hasOwnProperty;var on=r=>{throw TypeError(r)};var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Lo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Vo(e))!No.call(r,i)&&i!==t&&an(r,i,{get:()=>e[i],enumerable:!(n=ko(e,i))||n.enumerable});return r};var J=(r,e,t)=>(t=r!=null?Po(Mo(r)):{},Lo(e||!r||!r.__esModule?an(t,"default",{value:r,enumerable:!0}):t,r));var cn=(r,e,t)=>e.has(r)||on("Cannot "+t);var S=(r,e,t)=>(cn(r,e,"read from private field"),t?t.call(r):e.get(r)),F=(r,e,t)=>e.has(r)?on("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),N=(r,e,t,n)=>(cn(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t);var ln=(r,e,t,n)=>({set _(i){N(r,e,i,t)},get _(){return S(r,e,n)}});var Q=p((Yt,bn)=>{"use strict";var Re=function(r){return r&&r.Math===Math&&r};bn.exports=Re(typeof globalThis=="object"&&globalThis)||Re(typeof window=="object"&&window)||Re(typeof self=="object"&&self)||Re(typeof global=="object"&&global)||Re(typeof Yt=="object"&&Yt)||function(){return this}()||Function("return this")()});var B=p((Jh,Cn)=>{"use strict";Cn.exports=function(r){try{return!!r()}catch(e){return!0}}});var Oe=p((ed,gn)=>{"use strict";var jo=B();gn.exports=!jo(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Sn=p((td,xn)=>{"use strict";var $o=Oe(),Tn=Function.prototype,En=Tn.apply,In=Tn.call;xn.exports=typeof Reflect=="object"&&Reflect.apply||($o?In.bind(En):function(){return In.apply(En,arguments)})});var W=p((rd,Rn)=>{"use strict";var wn=Oe(),An=Function.prototype,Zt=An.call,_o=wn&&An.bind.bind(Zt,Zt);Rn.exports=wn?_o:function(r){return function(){return Zt.apply(r,arguments)}}});var Pe=p((nd,Pn)=>{"use strict";var On=W(),Fo=On({}.toString),qo=On("".slice);Pn.exports=function(r){return qo(Fo(r),8,-1)}});var Jt=p((id,kn)=>{"use strict";var Bo=Pe(),Do=W();kn.exports=function(r){if(Bo(r)==="Function")return Do(r)}});var D=p((sd,Vn)=>{"use strict";var er=typeof document=="object"&&document.all;Vn.exports=typeof er=="undefined"&&er!==void 0?function(r){return typeof r=="function"||r===er}:function(r){return typeof r=="function"}});var se=p((ad,Mn)=>{"use strict";var Ho=B();Mn.exports=!Ho(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var ut=p((od,Nn)=>{"use strict";var Uo=Oe(),lt=Function.prototype.call;Nn.exports=Uo?lt.bind(lt):function(){return lt.apply(lt,arguments)}});var tr=p($n=>{"use strict";var Ln={}.propertyIsEnumerable,jn=Object.getOwnPropertyDescriptor,Go=jn&&!Ln.call({1:2},1);$n.f=Go?function(e){var t=jn(this,e);return!!t&&t.enumerable}:Ln});var rr=p((ld,_n)=>{"use strict";_n.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var qn=p((ud,Fn)=>{"use strict";var zo=W(),Wo=B(),Ko=Pe(),nr=Object,Qo=zo("".split);Fn.exports=Wo(function(){return!nr("z").propertyIsEnumerable(0)})?function(r){return Ko(r)==="String"?Qo(r,""):nr(r)}:nr});var ir=p((pd,Bn)=>{"use strict";Bn.exports=function(r){return r==null}});var sr=p((hd,Dn)=>{"use strict";var Xo=ir(),Yo=TypeError;Dn.exports=function(r){if(Xo(r))throw new Yo("Can't call method on "+r);return r}});var ke=p((dd,Hn)=>{"use strict";var Zo=qn(),Jo=sr();Hn.exports=function(r){return Zo(Jo(r))}});var ye=p((md,Un)=>{"use strict";var ec=D();Un.exports=function(r){return typeof r=="object"?r!==null:ec(r)}});var pt=p((fd,Gn)=>{"use strict";Gn.exports={}});var ht=p((vd,Wn)=>{"use strict";var ar=pt(),or=Q(),tc=D(),zn=function(r){return tc(r)?r:void 0};Wn.exports=function(r,e){return arguments.length<2?zn(ar[r])||zn(or[r]):ar[r]&&ar[r][e]||or[r]&&or[r][e]}});var Qn=p((yd,Kn)=>{"use strict";var rc=W();Kn.exports=rc({}.isPrototypeOf)});var Jn=p((bd,Zn)=>{"use strict";var nc=Q(),Xn=nc.navigator,Yn=Xn&&Xn.userAgent;Zn.exports=Yn?String(Yn):""});var ai=p((Cd,si)=>{"use strict";var ii=Q(),cr=Jn(),ei=ii.process,ti=ii.Deno,ri=ei&&ei.versions||ti&&ti.version,ni=ri&&ri.v8,K,dt;ni&&(K=ni.split("."),dt=K[0]>0&&K[0]<4?1:+(K[0]+K[1]));!dt&&cr&&(K=cr.match(/Edge\/(\d+)/),(!K||K[1]>=74)&&(K=cr.match(/Chrome\/(\d+)/),K&&(dt=+K[1])));si.exports=dt});var lr=p((gd,ci)=>{"use strict";var oi=ai(),ic=B(),sc=Q(),ac=sc.String;ci.exports=!!Object.getOwnPropertySymbols&&!ic(function(){var r=Symbol("symbol detection");return!ac(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&oi&&oi<41})});var ur=p((Ed,li)=>{"use strict";var oc=lr();li.exports=oc&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var pr=p((Id,ui)=>{"use strict";var cc=ht(),lc=D(),uc=Qn(),pc=ur(),hc=Object;ui.exports=pc?function(r){return typeof r=="symbol"}:function(r){var e=cc("Symbol");return lc(e)&&uc(e.prototype,hc(r))}});var hi=p((Td,pi)=>{"use strict";var dc=String;pi.exports=function(r){try{return dc(r)}catch(e){return"Object"}}});var hr=p((xd,di)=>{"use strict";var mc=D(),fc=hi(),vc=TypeError;di.exports=function(r){if(mc(r))return r;throw new vc(fc(r)+" is not a function")}});var fi=p((Sd,mi)=>{"use strict";var yc=hr(),bc=ir();mi.exports=function(r,e){var t=r[e];return bc(t)?void 0:yc(t)}});var yi=p((wd,vi)=>{"use strict";var dr=ut(),mr=D(),fr=ye(),Cc=TypeError;vi.exports=function(r,e){var t,n;if(e==="string"&&mr(t=r.toString)&&!fr(n=dr(t,r))||mr(t=r.valueOf)&&!fr(n=dr(t,r))||e!=="string"&&mr(t=r.toString)&&!fr(n=dr(t,r)))return n;throw new Cc("Can't convert object to primitive value")}});var Ci=p((Ad,bi)=>{"use strict";bi.exports=!0});var Ii=p((Rd,Ei)=>{"use strict";var gi=Q(),gc=Object.defineProperty;Ei.exports=function(r,e){try{gc(gi,r,{value:e,configurable:!0,writable:!0})}catch(t){gi[r]=e}return e}});var mt=p((Od,Si)=>{"use strict";var Ec=Ci(),Ic=Q(),Tc=Ii(),Ti="__core-js_shared__",xi=Si.exports=Ic[Ti]||Tc(Ti,{});(xi.versions||(xi.versions=[])).push({version:"3.38.0",mode:Ec?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var vr=p((Pd,Ai)=>{"use strict";var wi=mt();Ai.exports=function(r,e){return wi[r]||(wi[r]=e||{})}});var Ve=p((kd,Ri)=>{"use strict";var xc=sr(),Sc=Object;Ri.exports=function(r){return Sc(xc(r))}});var be=p((Vd,Oi)=>{"use strict";var wc=W(),Ac=Ve(),Rc=wc({}.hasOwnProperty);Oi.exports=Object.hasOwn||function(e,t){return Rc(Ac(e),t)}});var yr=p((Md,Pi)=>{"use strict";var Oc=W(),Pc=0,kc=Math.random(),Vc=Oc(1 .toString);Pi.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Vc(++Pc+kc,36)}});var Me=p((Nd,Vi)=>{"use strict";var Mc=Q(),Nc=vr(),ki=be(),Lc=yr(),jc=lr(),$c=ur(),Ce=Mc.Symbol,br=Nc("wks"),_c=$c?Ce.for||Ce:Ce&&Ce.withoutSetter||Lc;Vi.exports=function(r){return ki(br,r)||(br[r]=jc&&ki(Ce,r)?Ce[r]:_c("Symbol."+r)),br[r]}});var ji=p((Ld,Li)=>{"use strict";var Fc=ut(),Mi=ye(),Ni=pr(),qc=fi(),Bc=yi(),Dc=Me(),Hc=TypeError,Uc=Dc("toPrimitive");Li.exports=function(r,e){if(!Mi(r)||Ni(r))return r;var t=qc(r,Uc),n;if(t){if(e===void 0&&(e="default"),n=Fc(t,r,e),!Mi(n)||Ni(n))return n;throw new Hc("Can't convert object to primitive value")}return e===void 0&&(e="number"),Bc(r,e)}});var Cr=p((jd,$i)=>{"use strict";var Gc=ji(),zc=pr();$i.exports=function(r){var e=Gc(r,"string");return zc(e)?e:e+""}});var qi=p(($d,Fi)=>{"use strict";var Wc=Q(),_i=ye(),gr=Wc.document,Kc=_i(gr)&&_i(gr.createElement);Fi.exports=function(r){return Kc?gr.createElement(r):{}}});var Er=p((_d,Bi)=>{"use strict";var Qc=se(),Xc=B(),Yc=qi();Bi.exports=!Qc&&!Xc(function(){return Object.defineProperty(Yc("div"),"a",{get:function(){return 7}}).a!==7})});var Ui=p(Hi=>{"use strict";var Zc=se(),Jc=ut(),el=tr(),tl=rr(),rl=ke(),nl=Cr(),il=be(),sl=Er(),Di=Object.getOwnPropertyDescriptor;Hi.f=Zc?Di:function(e,t){if(e=rl(e),t=nl(t),sl)try{return Di(e,t)}catch(n){}if(il(e,t))return tl(!Jc(el.f,e,t),e[t])}});var zi=p((qd,Gi)=>{"use strict";var al=B(),ol=D(),cl=/#|\.prototype\./,Ne=function(r,e){var t=ul[ll(r)];return t===hl?!0:t===pl?!1:ol(e)?al(e):!!e},ll=Ne.normalize=function(r){return String(r).replace(cl,".").toLowerCase()},ul=Ne.data={},pl=Ne.NATIVE="N",hl=Ne.POLYFILL="P";Gi.exports=Ne});var Ir=p((Bd,Ki)=>{"use strict";var Wi=Jt(),dl=hr(),ml=Oe(),fl=Wi(Wi.bind);Ki.exports=function(r,e){return dl(r),e===void 0?r:ml?fl(r,e):function(){return r.apply(e,arguments)}}});var Xi=p((Dd,Qi)=>{"use strict";var vl=se(),yl=B();Qi.exports=vl&&yl(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Zi=p((Hd,Yi)=>{"use strict";var bl=ye(),Cl=String,gl=TypeError;Yi.exports=function(r){if(bl(r))return r;throw new gl(Cl(r)+" is not an object")}});var ts=p(es=>{"use strict";var El=se(),Il=Er(),Tl=Xi(),ft=Zi(),Ji=Cr(),xl=TypeError,Tr=Object.defineProperty,Sl=Object.getOwnPropertyDescriptor,xr="enumerable",Sr="configurable",wr="writable";es.f=El?Tl?function(e,t,n){if(ft(e),t=Ji(t),ft(n),typeof e=="function"&&t==="prototype"&&"value"in n&&wr in n&&!n[wr]){var i=Sl(e,t);i&&i[wr]&&(e[t]=n.value,n={configurable:Sr in n?n[Sr]:i[Sr],enumerable:xr in n?n[xr]:i[xr],writable:!1})}return Tr(e,t,n)}:Tr:function(e,t,n){if(ft(e),t=Ji(t),ft(n),Il)try{return Tr(e,t,n)}catch(i){}if("get"in n||"set"in n)throw new xl("Accessors not supported");return"value"in n&&(e[t]=n.value),e}});var ns=p((Gd,rs)=>{"use strict";var wl=se(),Al=ts(),Rl=rr();rs.exports=wl?function(r,e,t){return Al.f(r,e,Rl(1,t))}:function(r,e,t){return r[e]=t,r}});var je=p((zd,ss)=>{"use strict";var Le=Q(),Ol=Sn(),Pl=Jt(),kl=D(),Vl=Ui().f,Ml=zi(),ge=pt(),Nl=Ir(),Ee=ns(),is=be();mt();var Ll=function(r){var e=function(t,n,i){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,n)}return new r(t,n,i)}return Ol(r,this,arguments)};return e.prototype=r.prototype,e};ss.exports=function(r,e){var t=r.target,n=r.global,i=r.stat,s=r.proto,o=n?Le:i?Le[t]:Le[t]&&Le[t].prototype,c=n?ge:ge[t]||Ee(ge,t,{})[t],a=c.prototype,l,y,f,v,C,w,g,m,A;for(v in e)l=Ml(n?v:t+(i?".":"#")+v,r.forced),y=!l&&o&&is(o,v),w=c[v],y&&(r.dontCallGetSet?(A=Vl(o,v),g=A&&A.value):g=o[v]),C=y&&g?g:e[v],!(!l&&!s&&typeof w==typeof C)&&(r.bind&&y?m=Nl(C,Le):r.wrap&&y?m=Ll(C):s&&kl(C)?m=Pl(C):m=C,(r.sham||C&&C.sham||w&&w.sham)&&Ee(m,"sham",!0),Ee(c,v,m),s&&(f=t+"Prototype",is(ge,f)||Ee(ge,f,{}),Ee(ge[f],v,C),r.real&&a&&(l||!a[v])&&Ee(a,v,C)))}});var os=p((Wd,as)=>{"use strict";var jl=Math.ceil,$l=Math.floor;as.exports=Math.trunc||function(e){var t=+e;return(t>0?$l:jl)(t)}});var $e=p((Kd,cs)=>{"use strict";var _l=os();cs.exports=function(r){var e=+r;return e!==e||e===0?0:_l(e)}});var us=p((Qd,ls)=>{"use strict";var Fl=$e(),ql=Math.min;ls.exports=function(r){var e=Fl(r);return e>0?ql(e,9007199254740991):0}});var _e=p((Xd,ps)=>{"use strict";var Bl=us();ps.exports=function(r){return Bl(r.length)}});var vt=p((Yd,hs)=>{"use strict";hs.exports=function(){}});var ds=p(()=>{"use strict";var Dl=je(),Hl=Ve(),Ul=_e(),Gl=$e(),zl=vt();Dl({target:"Array",proto:!0},{at:function(e){var t=Hl(this),n=Ul(t),i=Gl(e),s=i>=0?i:n+i;return s<0||s>=n?void 0:t[s]}});zl("at")});var yt=p((em,ms)=>{"use strict";var Wl=ht();ms.exports=Wl});var vs=p((tm,fs)=>{"use strict";ds();var Kl=yt();fs.exports=Kl("Array","at")});var bs=p((rm,ys)=>{"use strict";var Ql=vs();ys.exports=Ql});var Ar=p((nm,Cs)=>{"use strict";var Xl=bs();Cs.exports=Xl});var Ls=p((ff,Ns)=>{"use strict";var au=vr(),ou=yr(),Ms=au("keys");Ns.exports=function(r){return Ms[r]||(Ms[r]=ou(r))}});var $s=p((vf,js)=>{"use strict";var cu=B();js.exports=!cu(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var qs=p((yf,Fs)=>{"use strict";var lu=be(),uu=D(),pu=Ve(),hu=Ls(),du=$s(),_s=hu("IE_PROTO"),$r=Object,mu=$r.prototype;Fs.exports=du?$r.getPrototypeOf:function(r){var e=pu(r);if(lu(e,_s))return e[_s];var t=e.constructor;return uu(t)&&e instanceof t?t.prototype:e instanceof $r?mu:null}});var Ds=p((bf,Bs)=>{"use strict";var fu=$e(),vu=Math.max,yu=Math.min;Bs.exports=function(r,e){var t=fu(r);return t<0?vu(t+e,0):yu(t,e)}});var _r=p((Cf,Us)=>{"use strict";var bu=ke(),Cu=Ds(),gu=_e(),Hs=function(r){return function(e,t,n){var i=bu(e),s=gu(i);if(s===0)return!r&&-1;var o=Cu(n,s),c;if(r&&t!==t){for(;s>o;)if(c=i[o++],c!==c)return!0}else for(;s>o;o++)if((r||o in i)&&i[o]===t)return r||o||0;return!r&&-1}};Us.exports={includes:Hs(!0),indexOf:Hs(!1)}});var zs=p((gf,Gs)=>{"use strict";Gs.exports={}});var Qs=p((Ef,Ks)=>{"use strict";var Eu=W(),Fr=be(),Iu=ke(),Tu=_r().indexOf,xu=zs(),Ws=Eu([].push);Ks.exports=function(r,e){var t=Iu(r),n=0,i=[],s;for(s in t)!Fr(xu,s)&&Fr(t,s)&&Ws(i,s);for(;e.length>n;)Fr(t,s=e[n++])&&(~Tu(i,s)||Ws(i,s));return i}});var Ys=p((If,Xs)=>{"use strict";Xs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var Js=p((Tf,Zs)=>{"use strict";var Su=Qs(),wu=Ys();Zs.exports=Object.keys||function(e){return Su(e,wu)}});var sa=p((xf,ia)=>{"use strict";var ta=se(),Au=B(),ra=W(),Ru=qs(),Ou=Js(),Pu=ke(),ku=tr().f,na=ra(ku),Vu=ra([].push),Mu=ta&&Au(function(){var r=Object.create(null);return r[2]=2,!na(r,2)}),ea=function(r){return function(e){for(var t=Pu(e),n=Ou(t),i=Mu&&Ru(t)===null,s=n.length,o=0,c=[],a;s>o;)a=n[o++],(!ta||(i?a in t:na(t,a)))&&Vu(c,r?[a,t[a]]:t[a]);return c}};ia.exports={entries:ea(!0),values:ea(!1)}});var aa=p(()=>{"use strict";var Nu=je(),Lu=sa().values;Nu({target:"Object",stat:!0},{values:function(e){return Lu(e)}})});var ca=p((Af,oa)=>{"use strict";aa();var ju=pt();oa.exports=ju.Object.values});var ua=p((Rf,la)=>{"use strict";var $u=ca();la.exports=$u});var Mt=p((Of,pa)=>{"use strict";var _u=ua();pa.exports=_u});var ma=p(()=>{"use strict";var Fu=je(),qu=_r().includes,Bu=B(),Du=vt(),Hu=Bu(function(){return!Array(1).includes()});Fu({target:"Array",proto:!0,forced:Hu},{includes:function(e){return qu(this,e,arguments.length>1?arguments[1]:void 0)}});Du("includes")});var va=p((Nf,fa)=>{"use strict";ma();var Uu=yt();fa.exports=Uu("Array","includes")});var ba=p((Lf,ya)=>{"use strict";var Gu=va();ya.exports=Gu});var Nt=p((jf,Ca)=>{"use strict";var zu=ba();Ca.exports=zu});var Ur=p((tv,xa)=>{"use strict";var Yu=Pe();xa.exports=Array.isArray||function(e){return Yu(e)==="Array"}});var wa=p((rv,Sa)=>{"use strict";var Zu=TypeError,Ju=9007199254740991;Sa.exports=function(r){if(r>Ju)throw Zu("Maximum allowed index exceeded");return r}});var Oa=p((nv,Ra)=>{"use strict";var ep=Ur(),tp=_e(),rp=wa(),np=Ir(),Aa=function(r,e,t,n,i,s,o,c){for(var a=i,l=0,y=o?np(o,c):!1,f,v;l<n;)l in t&&(f=y?y(t[l],l,e):t[l],s>0&&ep(f)?(v=tp(f),a=Aa(r,e,f,v,a,s-1)-1):(rp(a+1),r[a]=f),a++),l++;return a};Ra.exports=Aa});var Va=p((iv,ka)=>{"use strict";var ip=Me(),sp=ip("toStringTag"),Pa={};Pa[sp]="z";ka.exports=String(Pa)==="[object z]"});var Na=p((sv,Ma)=>{"use strict";var ap=Va(),op=D(),jt=Pe(),cp=Me(),lp=cp("toStringTag"),up=Object,pp=jt(function(){return arguments}())==="Arguments",hp=function(r,e){try{return r[e]}catch(t){}};Ma.exports=ap?jt:function(r){var e,t,n;return r===void 0?"Undefined":r===null?"Null":typeof(t=hp(e=up(r),lp))=="string"?t:pp?jt(e):(n=jt(e))==="Object"&&op(e.callee)?"Arguments":n}});var ja=p((av,La)=>{"use strict";var dp=W(),mp=D(),Gr=mt(),fp=dp(Function.toString);mp(Gr.inspectSource)||(Gr.inspectSource=function(r){return fp(r)});La.exports=Gr.inspectSource});var Da=p((ov,Ba)=>{"use strict";var vp=W(),yp=B(),$a=D(),bp=Na(),Cp=ht(),gp=ja(),_a=function(){},Fa=Cp("Reflect","construct"),zr=/^\s*(?:class|function)\b/,Ep=vp(zr.exec),Ip=!zr.test(_a),Qe=function(e){if(!$a(e))return!1;try{return Fa(_a,[],e),!0}catch(t){return!1}},qa=function(e){if(!$a(e))return!1;switch(bp(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Ip||!!Ep(zr,gp(e))}catch(t){return!0}};qa.sham=!0;Ba.exports=!Fa||yp(function(){var r;return Qe(Qe.call)||!Qe(Object)||!Qe(function(){r=!0})||r})?qa:Qe});var za=p((cv,Ga)=>{"use strict";var Ha=Ur(),Tp=Da(),xp=ye(),Sp=Me(),wp=Sp("species"),Ua=Array;Ga.exports=function(r){var e;return Ha(r)&&(e=r.constructor,Tp(e)&&(e===Ua||Ha(e.prototype))?e=void 0:xp(e)&&(e=e[wp],e===null&&(e=void 0))),e===void 0?Ua:e}});var Ka=p((lv,Wa)=>{"use strict";var Ap=za();Wa.exports=function(r,e){return new(Ap(r))(e===0?0:e)}});var Qa=p(()=>{"use strict";var Rp=je(),Op=Oa(),Pp=Ve(),kp=_e(),Vp=$e(),Mp=Ka();Rp({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=Pp(this),n=kp(t),i=Mp(t,0);return i.length=Op(i,t,t,n,0,e===void 0?1:Vp(e)),i}})});var Xa=p(()=>{"use strict";var Np=vt();Np("flat")});var Za=p((mv,Ya)=>{"use strict";Qa();Xa();var Lp=yt();Ya.exports=Lp("Array","flat")});var eo=p((fv,Ja)=>{"use strict";var jp=Za();Ja.exports=jp});var ro=p((vv,to)=>{"use strict";var $p=eo();to.exports=$p});var un="1.0.34-dev.870071a7.0";var Ht=class{constructor(e){this.layout=e}},et=class extends Ht{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};function pn(r){return"features"in r}var me=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&pn(this.options)&&this.options.features[e]}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){var e;return((e=this.container.controls)==null?void 0:e.reduce((t,n)=>{let i=n.type.trim().toLowerCase(),s=this.factories.get(i);if(s){let o=s(n,this.options);if(o)return[...t,o]}return[...t]},[]))||[]}};function Ut(r,e=1){let t="0",n="0",i="0";return r.length===4?(t="0x"+r[1]+r[1],n="0x"+r[2]+r[2],i="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],n="0x"+r[3]+r[4],i="0x"+r[5]+r[6]),`rgba(${+t},${+n},${+i},${e})`}var hn="interactive",j={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},dn=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(dn||{}),mn=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(mn||{}),fn=(n=>(n.start="left",n.end="right",n.center="center",n))(fn||{}),tt=({target:r,props:e})=>{var t,n,i;r.style.alignItems=(t=(e==null?void 0:e.gravityVertical)&&dn[e.gravityVertical])!=null?t:"center",r.style.justifyContent=(n=(e==null?void 0:e.gravityHorizontal)&&mn[e.gravityHorizontal])!=null?n:"center",r.style.textAlign=(i=(e==null?void 0:e.alignment)&&fn[e.alignment])!=null?i:"center"},rt=({target:r,props:e,fallback:t,dependsOn:n})=>{var i,s,o,c,a,l;r.style.color=(s=(i=e==null?void 0:e.text)==null?void 0:i.color)!=null?s:t.textColor,r.style.fontSize=`calc(${n.height} * ${(c=(o=e==null?void 0:e.text)==null?void 0:o.size)!=null?c:t.textSize})`,r.textContent=(l=(a=e==null?void 0:e.text)==null?void 0:a.value)!=null?l:t.textContent},nt=({target:r,props:e,fallback:t})=>{var n,i,s,o;r.style.backgroundColor=Ut((i=(n=e==null?void 0:e.background)==null?void 0:n.color)!=null?i:t.backgroundColor,(o=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?o:t.backgroundAlpha)},it=({target:r,props:e,fallback:t,dependsOn:n})=>{var i,s,o,c,a,l,y,f,v,C,w;r.style.border=`calc(${n.height} * ${(o=(s=(i=e==null?void 0:e.shape)==null?void 0:i.border)==null?void 0:s.width)!=null?o:t.borderWidth}) solid ${Ut((l=(a=(c=e==null?void 0:e.shape)==null?void 0:c.border)==null?void 0:a.color)!=null?l:t.borderColor,(v=(f=(y=e==null?void 0:e.shape)==null?void 0:y.border)==null?void 0:f.alpha)!=null?v:t.borderAlpha)}`,r.style.borderRadius=`calc(${n.height} * ${(w=(C=e==null?void 0:e.shape)==null?void 0:C.roundCorners)!=null?w:t.roundCorners})`},fe=({target:r,layoutParams:e,fallback:t})=>{var i;let n=(i=e.angle)!=null?i:t.angle;n=n&&n*-1,r.style.transform=`rotate(${n}rad)`};var Gt="int",ie=(n=>(n.AREA=`${Gt}_area`,n.TEXT=`${Gt}_text`,n.BUTTON=`${Gt}_bttn`,n))(ie||{});function vn(r){return"features"in r}var ve="interactive-control",V={common:ve,wrapper:`${ve}-wrapper`,disabled:`${ve}-disabled`,button:`${ve}-button`,area:`${ve}-area`,text:`${ve}-text`};var ne=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){var i;let t=document.createElement("div");t.classList.add(V.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=((i=this.control.layoutParams.innerSizesDependOn)!=null?i:j.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:t,dimensions:n}}createClickListener(e){return t=>{t.stopPropagation(),e()}}featureIsEnabled(e){return this.options&&vn(this.options)&&this.options.features[e]}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{var i;switch(t.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),(i=this.container)==null||i.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){var e,t;(e=this.container)!=null&&e.element&&this.clickListener&&((t=this.container)==null||t.element.removeEventListener("click",this.clickListener))}};var st=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new zt(r,e)},zt=class extends ne{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(V.common,V.area),n.setAttribute("data-testid",ie.AREA),nt({target:n,props:this.control.props,fallback:{...j,backgroundColor:"transparent"}}),it({target:n,props:this.control.props,fallback:{...j,borderAlpha:0},dependsOn:this.container.dimensions}),fe({target:n,layoutParams:this.control.layoutParams,fallback:j}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(V.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(V.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var at=r=>{let e=document.createElement("span");switch(r){case"Button":case"button":{let t=document.createElement("div"),n={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(t.style,n),t.append(e);let i={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,i),t}default:{let t={display:"inline-block",whiteSpace:"break-spaces",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",maxHeight:"100%",wordBreak:"break-all"};return Object.assign(e.style,t),e}}};var ot=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Wt(r,e)},Wt=class extends ne{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var o;if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(V.common,V.button),n.setAttribute("data-testid",ie.BUTTON),fe({target:n,layoutParams:this.control.layoutParams,fallback:j}),nt({target:n,props:this.control.props,fallback:j}),it({target:n,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=at(this.control.type.trim().toLowerCase()),s=(o=i.firstElementChild)!=null?o:i;rt({target:s,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(V.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(V.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var yn=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Kt(r,e)},Kt=class extends ne{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var o;if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(V.common,V.text),n.setAttribute("data-testid",ie.TEXT),fe({target:n,layoutParams:this.control.layoutParams,fallback:j}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=at(this.control.type.trim().toLowerCase()),s=(o=i.firstElementChild)!=null?o:i;rt({target:s,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}};var Qt="interactive-container",q={common:Qt,hidden:`${Qt}-hidden`,disabled:`${Qt}-disabled`};var ct=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new Xt(r,e,t)},Xt=class extends me{constructor(t,n,i){super(t,i);this.containerElement=null;this.rootElement=n,this.layout=new et(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ot),this.addControlFactory("text",yn),this.addControlFactory("area",st)}createView({eventCallback:t}){let n=document.createElement("div");return n.classList.add(q.common,q.disabled),requestAnimationFrame(()=>{n.classList.remove(q.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout}}),i.setEvents(t)}),this.rootElement.append(n),this.isRemoved=!1,this.containerElement=n,n}hide(){let t=this.getElement();t&&t.classList.add(q.hidden)}show(){let t=this.getElement();t&&t.classList.remove(q.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(q.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(q.disabled),this.controls.forEach(n=>n.disable()),this.isDisabled=!0)}removeView(){let t=this.getElement();t&&(this.controls.forEach(n=>n.removeListeners()),t.remove(),this.isRemoved=!0,this.containerElement=null)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(t,n){n&&this.controls.forEach(i=>{i.onProgress(t)})}onResize(t){t&&this.controls.forEach(n=>{n.onResize()})}};var Ro=J(Ar(),1);import{combine as Xp,InterfaceLanguage as Yp,Observable as So,once as Zp,Subject as $,Subscription as Zr,ValueSubject as _,fromEvent as wo}from"@vkontakte/videoplayer-shared/es2018";import{InteractiveInterfaceClick as Ze}from"@vkontakte/videoplayer-statistics/es2018";import{loadVKLangPack as Yl}from"@vkontakte/videoplayer-shared/es2018";function Fe(r,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>r(...n),e)}}var ae=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,qe=r=>ae(r,"Object"),bt=r=>ae(r,"String"),Ct=r=>ae(r,"Array"),gt=r=>ae(r,"Number"),gs=r=>ae(r,"Function");var Rr=r=>gt(r)&&!isNaN(r);var oe=r=>qe(r)&&Object.keys(r).length===0,Or=r=>Ct(r)&&!r.length;var Be=(r,e)=>bt(r)&&(e?r.trim():r).length;var Es="video_interactive",Is="videoint";var Ts=250,De=class{constructor(e){this.handleZoomChange=Fe(e=>{this.lastZoomInfo=e},Ts);this.onResize=e=>{var n;if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&((n=this.ngEditor)==null||n.zoomTo(t)),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{var t,n,i;if(this.manifest){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.call(this,"Chapter id is not found");return}this.visitedChapterIds.add(e.id),(n=this.ngEditor)==null||n.selectChapter(e.id),(i=this.ngEditor)==null||i.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{var n;if(this.isReady=!1,!gt(e.graph.edit.chapters[0].x)){(n=this.onError)==null||n.call(this,"Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:i,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=i!=null?i:"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Zl(e),this.resizeObserver=new ResizeObserver(Fe(this.onResize,Ts)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){var t;this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),(t=this.ngEditor)==null||t.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){var t;(t=this.ngEditor)==null||t.updateVideosInfo(e)}async show(){var e;this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&((e=this.ngEditor)==null||e.focusChapter(this.currentChapterId)),this.isHidden=!1)}async initNgEditor(){var n;if(!this.manifest)return;let e;try{e=await Yl(this.lang,Es,Is)}catch(i){(n=this.onError)==null||n.call(this,"Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:i,...s})=>{var o;i==="openPreview"&&"chapterId"in s&&((o=this.onOpenPreviewClick)==null||o.call(this,s.chapterId))}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.manifest=null,this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Zl(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var He=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,n=!1,i=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let o=s.startTime-e;if(o<=i&&(s.endTime&&i<=s.endTime||s.endTime===null)){n=!0;break}i<o&&(t=t===-1?o:Math.min(t,o))}return!n&&t!==-1?t:null}}};import{isSupportedManifest as It,ContainerTypes as Rm,ControlTypes as Tt,EventActionTypes as O,EventTypes as Om,migrateManifestToLatestVersion as As,compareVersions as Pm}from"@interactiveplatform/movika-manifest";var xs={metadata:"Object",chapters:"Array"},Ss=r=>{if(!qe(r))return!1;for(let e in xs)if(!r[e]||!ae(r[e],xs[e]))return!1;return It(r.metadata.version)},Et=r=>r.type===Tt.Text,gm=r=>r.type===Tt.Button,Em=r=>r.type===Tt.Area,Im={Choice:"Choice",TextInput:"TextInput"},Tm={Button:"Button",Area:"Area",Text:"Text"},xm={onClick:"onClick",onSuspense:"onSuspense"},ws={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var L=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var xt=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let n=this.listeners[e]||[];for(let i=n.length;i>0;i--)if(n[i]===t){n.splice(i,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(i=>{i(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var St=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{gs(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as su}from"@vkontakte/videoplayer-shared/es2018";var wt=class{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!=null?n:[]}}async exec(e,t){return Jl(...this.loaders[e])(t)}};function Jl(...r){return async function(t){let n=[...r];for(;n.length>0;)t=await n.shift()(t);return t}}function Ue(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function At({actions:r,errors:e,chapterId:t,...n}){if(t){let i=r.getManifest();if(i){let s=r.getChapter(i.chapters,t);if(s){let o=r.getMedia(i.media,s.videoId),c=r.getGraph(i.graph,s.id);return o?{...n,actions:r,errors:e,result:{chapter:s,media:o,graph:c}}:{...n,errors:Ue(e,At.name,"Could not find media"),actions:r}}}}return{...n,errors:Ue(e,At.name,"Could not find chapter"),actions:r}}var Rt=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;let n=this.listeners[e];for(let i=0,s=n.length;i<s;i++)if(n[i].callback===t){n.splice(i,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let n=this.listeners[e.type].slice();for(let i=0,s=n.length;i<s;i++){let o=n[i];try{o.callback.call(this,e)}catch(c){Promise.resolve().then(()=>{throw c})}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}},Ie=class extends Rt{constructor(){super(),this.listeners||Rt.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Ge=class{constructor(){Object.defineProperty(this,"signal",{value:new Ie,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(i){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=e;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(i){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(Ge.prototype[Symbol.toStringTag]="AbortController",Ie.prototype[Symbol.toStringTag]="AbortSignal");function Ot(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function Pr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=r;if(!Ot({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||i)&&(s=function(l,y){let f;y&&y.signal&&(f=y.signal,delete y.signal);let v=new t(l,y);return f&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),v},s.prototype=t.prototype);let o=e;return{fetch:(a,l)=>{let y=s&&s.prototype.isPrototypeOf(a)?a.signal:l?l.signal:void 0;if(y){let f;try{f=new DOMException("Aborted","AbortError")}catch(C){f=new Error("Aborted"),f.name="AbortError"}if(y.aborted)return Promise.reject(f);let v=new Promise((C,w)=>{y.addEventListener("abort",()=>w(f),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([v,o(a,l)])}return o(a,l)},Request:s}}var ze=Ot({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Rs=ze?Pr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,kr=ze?Rs.fetch:window.fetch,Km=ze?Rs.Request:window.Request,Qm=ze?Ge:window.AbortController,Xm=ze?Ie:window.AbortSignal;var Vr=(r="",e="")=>{let t=r.split("."),n=e.split("."),i=0;for(let s=0;s<Math.max(t.length,n.length)&&!i;s++)t[s]>n[s]?i=1:t[s]<n[s]?i=-1:i=0;return i};var eu=async r=>{try{let e={},t;if(bt(r)){t=new URL(r).href;let i=await kr(t);if(!i.ok)return{};e=await i.json()}else if(qe(r))e=r;else return{};if(!Ss(e))return{};let n=e.metadata.media;if(bt(n)&&!("media"in e))try{let i;t?i=new URL(n,t).href:(i=new URL(n).href,t=i);let s=await kr(i);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch(i){return nu(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Os(r){let{manifest:e,manifestURL:t}=await eu(r);if(!e)throw new Error("Failed on fetch");let n=As(e);return n.media=tu(n.media,t),delete n.metadata.media,n}function Pt(r,e){if(e)return r.find(t=>t.id===e)}function Mr(r,e){var t,n;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(i=>i.id===e):(n=r.view)!=null&&n.chapters?r.view.chapters.find(i=>i.id===e):void 0}function Nr(r,e){return r.videos.find(t=>t.id===e)}function tu(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(n=>{let i="url"in n?n.url:"",s=ru(i,e);return{...n,url:s||i}})}))}}function ru(r="",e){try{return new URL(r,e).href}catch(t){return""}}function nu(r){return Vr(r,"3.2.0")>=0}var kt=r=>Ct(r)&&!Or(r),X=r=>r.order==="end",Vt=r=>Ct(r.containers)&&!Or(r.containers)&&X(r),Ps=(r,e)=>{var n;let t=r*1e3;return kt(e.controls)&&t<((n=e.startTime)!=null?n:0)},Lr=(r,e)=>{var n,i;let t=r*1e3;return kt(e.controls)&&t>=((n=e.startTime)!=null?n:0)&&t<=((i=e.endTime)!=null?i:1/0)};var ce=(r=[])=>r.some(e=>e.action.type==="expect"),jr=(r=[])=>r.find(e=>e.action.type==="expect"),iu=r=>(r==null?void 0:r.length)===1,Te=r=>iu(r)&&Et(r[0]);function ks(r,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?r({...e[0],...t}):r(...e,...t)}var Vs=(r,e)=>{let t=g=>{let m=e.find(({container:A})=>A.container.id===g);return m==null?void 0:m.container.isRemoved},n=ce(r.events)&&!t(r.id),i=(g,m=!1,A=!1)=>{let h=A?"every":"some";return g.controls[h](u=>{var E;let d=m?g.endTime===r.endTime:!0;return((E=u.events)==null?void 0:E[h](I=>{var b;return((b=I.action)==null?void 0:b.type)===ws.openURI}))&&d})},s=g=>g.some(({container:m})=>i(m.container,!0,!1)&&!m.isRemoved),o=g=>g.every(({container:m})=>m.isRemoved?!0:i(m.container,!0,!0)),c=e.filter(({container:g})=>g.container.id!==r.id&&ce(g.container.events)&&g.container.endTime===r.endTime&&!g.isRemoved).length,a=g=>g.controls.some(m=>{var A;return(A=m.events)==null?void 0:A.some(h=>{var u,d;return(d=(u=h.action)==null?void 0:u.args)==null?void 0:d.shouldOpenNow})}),l=n||c>0,y=s(e),f=i(r),v=o(e),C=n?!1:c>0,w=a(r);return{isExpectTime:l,hasOtherExpect:c>0,hasOpenURIEvent:y,hasOpenURIEventInCurrentContainer:f,isAllOpenURIEventsValid:v,isExpectEventForCurrentContainer:C,hasShouldOpenNowEvent:w}};var xe=class extends wt{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new su(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var i;this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ue},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await Os((i=n.result)!=null?i:t),this}async setInitial(){return this.setNext()}async setNext(t=(n=>(n=this.manifest)==null?void 0:n.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",At({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Mr,getChapter:Pt,getMedia:Nr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ue},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),i.result&&(this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){var n;return this.getByChapterId((n=this.manifest)==null?void 0:n.metadata.initChapterId)||null}getByChapterId(t=(n=>(n=this.manifest)==null?void 0:n.metadata.initChapterId)()){if(!t||!this.manifest)return null;let i=Pt(this.manifest.chapters,t);if(i){let s=Nr(this.manifest.media,i.videoId),o=Mr(this.manifest.graph,i.id);if(s)return{chapter:i,media:s,graph:o}}return null}getBranches(t=(n=>(n=this.chapter)==null?void 0:n.id)()){var i,s,o;if(t===((i=this.chapter)==null?void 0:i.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let c=Pt(((o=this.manifest)==null?void 0:o.chapters)||[],t);return this.getByBranches(c==null?void 0:c.branches)}}getByBranches(t=[]){return t.reduce((n,i)=>{let s=this.getByChapterId(i.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){var t,n;return((t=this.chapter)==null?void 0:t.id)===((n=this.manifest)==null?void 0:n.metadata.initChapterId)}isEndChapter(){return this.chapter?X(this.chapter):!1}};var ga=J(Mt(),1);import{Player as Wu}from"@vkontakte/videoplayer-core/es2018";import{Subscription as Dr,ValueSubject as Ku}from"@vkontakte/videoplayer-shared/es2018";var ha=r=>{let e=r.variants.find(t=>{var n;return((n=t.payload)==null?void 0:n.type)==="vk"});if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};var da=J(Mt(),1);function qr(){let r=new Map;function e({listId:s=Math.random().toString(),itemId:o=Math.random().toString(),...c}){let a=r.get(s),l={...c};return a?a[o]=l:r.set(s,{[o]:l}),{listId:s,itemId:o,...c}}function t(s){var o,c;s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),(o=s.statistics)==null||o.oneStat.destroy(),(c=s.statistics)==null||c.statSubscription.unsubscribe()}function n(s,o){let c=r.get(s);if(!c)throw Error("Can't remove. Not find.");if(o){let a=c[o];a&&t(a),delete c[o],Object.keys(c).length||r.delete(s)}else{for(let a of(0,da.default)(c))t(a);r.delete(s)}}function i(){for(let s of r)n(s[0])}return{createPlayer:e,removePlayer:n,map:r,removeAll:i}}var Se=J(Nt(),1);function Br(r,e=[]){var s,o,c;let t={},n,i=!e.length;for(let a of r.variants)if(!n&&"cover"in a&&(n=a.cover),"url"in a)switch(a.type.toLowerCase()){case"mp4":(i||(0,Se.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[(s=a.standard)!=null?s:"Invariant quality"]:a.url});break;case"mpeg":(i||(0,Se.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[(o=a.standard)!=null?o:"Invariant quality"]:a.url});break;case"hls":(i||(0,Se.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:a.url}});break;case"dash":(i||(0,Se.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:a.url}});break;default:break}return{sources:t,thumbUrl:n,title:(c=r.title)!=null?c:""}}var We=(r,e)=>{let t=r.info.currentQuality$.getValue(),n=r.info.availableQualities$.getValue();t!==e&&(0,Se.default)(n,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Qu=2;function Hr(r){let e=qr(),t=new Dr,n={},i=null,s=!1,o,c=new Ku(null);r&&a(r);function a(m){i=m}function l(m,A,h){var E;if(!i)throw Error("need to set interactive controller");if(!i.options)return;let d=((E=e.map.get(m))!=null?E:{})[A];if(d){n={chapterId:h,listId:m,itemId:A,...d};let I=n.player;n.subscription.add(I.info.currentQuality$.subscribe(b=>{let T=I.info.position$.getValue(),P=I.info.isAutoQualityEnabled$.getValue();if(!(!b||!T||P))for(let x of e.map)(0,ga.default)(x[1]).forEach(({player:M})=>{We(M,b)})})).add(I.events.started$.subscribe(()=>{y(A)})),d.container.remove(),i.setPlayer(d.player),s||(i.init(),s=!0),c.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function y(m){if(!i)throw Error("need to set interactive controller");if(oe(n)||m!==n.itemId)return;let A=i.getChapterBranches(),h=new Set;for(let u of A)h.has(u.media.id)||(await v({media:u.media,chapterId:u.chapter.id,setAsActive:!1,title:u.chapter.label}),h.add(u.media.id))}async function f({chapter:{id:m},manifestVideo:A}){if(oe(n)||!i)return;let h=n.player.info.muted$.getValue(),u=n.player.info.currentQuality$.getValue(),d=n.player.info.isAutoQualityEnabled$.getValue(),E=n.player.info.volume$.getValue(),I=n.player.info.currentPlaybackRate$.getValue(),b=!d,T=!1;for(let P of e.map)if(P[0]===A.id&&!i.state.isReplay$.getValue()){let x=Object.keys(P[1]);for(let M of x)M===n.itemId?(x.length<Qu||(T=!0),e.removePlayer(P[0],M)):(T=!0,l(P[0],M,m),b?We(n.player,u):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h),n.player.setPlaybackRate(I))}else e.removePlayer(P[0]);T||(await v({media:A,chapterId:m,setAsActive:!0,playbackRate:I}),b?We(n.player,u):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h))}async function v({media:m,chapterId:A,prefetch:h=!0,setAsActive:u=!0,autoplay:d=!1,preferredExt:E,title:I,playbackRate:b}){var Jr,en,tn,rn,nn;let T=Math.random().toString(),P=document.createElement("div");o.append(P);let x;if((Jr=i==null?void 0:i.options)!=null&&Jr.vkVideoLoader){let Je=ha(m);Je.length&&(x=await i.options.vkVideoLoader(...Je))}let M=((en=i==null?void 0:i.options)==null?void 0:en.coreConfig)||void 0,U={...M,configName:[...(tn=M==null?void 0:M.configName)!=null?tn:[],"interactive"]},G={container:P,...((rn=x==null?void 0:x.videos)==null?void 0:rn[0])||{sources:Br(m,E).sources},title:I,failoverHosts:(x==null?void 0:x.failoverHosts)||[]},z=new Wu(U);z.initVideo(G);let Z=null;if(x!=null&&x.videos&&(i!=null&&i.options.createOneStat)){let Je=x.videos[0],Dt=i.options.createOneStat(Je),sn=new Dr;Dt&&(sn.add(Dt.attachTo(z)),Z={oneStat:Dt,statSubscription:sn})}let he=new Dr,Oo=(nn=n==null?void 0:n.player)==null?void 0:nn.info.isAutoQualityEnabled$.getValue();he.add(z.events.canplay$.subscribe(function(){Oo||We(z,n.player.info.currentQuality$.getValue()),b&&z.setPlaybackRate(b)}));let de=e.createPlayer({listId:m.id,itemId:T,player:z,container:P,sources:Br(m,E).sources,config:G,subscription:he,statistics:Z});return u&&l(m.id,de.itemId,A),d&&de.player.play(),h&&!d&&de.player.prepare(),{player:de.player,config:de.config,statistics:de.statistics}}function C(){w(),i=null,o.remove()}function w(){t.unsubscribe(),e.removeAll(),n={},s=!1}async function g(){if(!i)throw Error("need to set interactive controller");w(),o=document.createElement("div");let{media:m,chapter:A}=i.getCurrentChapter();m&&A?(t.add(i.events.chapterChanged$.subscribe(f)),await v({media:m,chapterId:A.id,title:A.label})):console.error("not found")}return{...e,init:g,setInteractiveController:a,createPlayer:v,removeAll:C,getActivePlayer:function(){return n},activePlayerChanged:c}}var R={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ke={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},k={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var Ia=J(Nt(),1);import{Subscription as Xu}from"@vkontakte/videoplayer-shared/es2018";var Lt=class{constructor({player:e,container:t,branches:n,selectBranches:i,interactiveEvents:s,globalEvents:o,globalEventEmitter:c,getContainerEventState:a,permanentTextControls:l,interactiveTimeOpenUri:y,disabledControls$:f,onRemove:v}){this.hide=()=>{setTimeout(()=>{var e,t;this.gameState!==4&&(ce(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&((t=(e=this.container).hide)==null||t.call(e)),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{var t,n,i,s;if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:o}=this.getContainerEventState();if((n=(t=this.container).show)==null||n.call(t),this.interactiveTimeOpenUri&&o)return;this.emitContainerVisibilityEvent(!0,!1)}else{let o={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(a,l)=>{let{isExpectTime:y,hasOtherExpect:f,hasOpenURIEvent:v,hasOpenURIEventInCurrentContainer:C,isAllOpenURIEventsValid:w,hasShouldOpenNowEvent:g}=this.getContainerEventState(),m=this.interactiveTimeOpenUri&&!C,A=this.interactiveTimeOpenUri&&C;if((!this.interactiveTimeOpenUri||m)&&(this.isSelectedControlEvent=!0),a!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||m)){if(this.interactiveTimeOpenUri){let h=!f&&!w&&C;h&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:h})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&v&&this.gameState!==5){if(A){let u=((d,E,I,b)=>!d&&!E&&I||d&&!E&&I&&!b||d&&!E&&I&&b)(y,f,w,this.isSelectedContainerEvent);this.fakeRemoveView(u)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!y||!f||!g)&&(this.selectBranches.stopExpect(),l())}},isEOV:()=>this.gameState===4},c=ks(this.selectBranches.onControlEvent,o);this.container.createView({eventCallback:c}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&((s=(i=this.container).disable)==null||s.call(i))}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{var l,y,f;let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,Ia.default)(i,this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(Ps(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Lr(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let v=this.gameState;this.gameState=3,v===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:v}=this.getContainerEventState(),C=this.selectBranches.state.isExpect,w=this.interactiveTimeOpenUri&&v;if(w&&!C){let g=this.container.getElement();g&&(g.style.visibility!=="hidden"&&((y=(l=this.container).hide)==null||y.call(l)),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!w&&this.removeView()}let o=Lr(s,this.container.container),c=this.container.container.startTime?[this.container.container.startTime,(f=this.container.container.endTime)!=null?f:1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:c,currentTime:s,isInteractiveTime:o};this.container.onProgress(s*1e3,o),this.globalEventEmitter.emit(R.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=n,this.selectBranches=i,this.subscription=new Xu,this.player=e,this.interactiveEvents=s,this.getContainerEventState=a,this.isPermanentText=l&&Te(t.container.controls),this.interactiveTimeOpenUri=y,this.disabledControls$=f,this.onRemove=v,this.globalEventEmitter=c,this.gameState=0,this.globalEvents=o,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(R.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.visibility,visibility:e,isFirst:t}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e,isFirst:t})):(this.globalEventEmitter.emit(R.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,n,i,s;e?(n=(t=this.container).disable)==null||n.call(t):(s=(i=this.container).enable)==null||s.call(i)}))}selectContainerEvent(e=!1){var n,i;let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:(n=this.container.container.endTime)!=null?n:1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec((i=this.container.container.endTime)!=null?i:1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:ce(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(R.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,(e=this.onRemove)==null||e.call(this)}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}destroy(){var e;this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var Ta=(r=[])=>r.reduce((e,t,n)=>{var s,o,c;let i=((s=t==null?void 0:t.controls)!=null?s:[]).filter(a=>!Et(a));if(kt(i)){let a=[(o=t.startTime)!=null?o:0,(c=t.endTime)!=null?c:1/0],l={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[l],range:a});else{let y=[],f=-1/0,v=1/0,C=[],w=[];for(let g=0;g<e.length;g++){let m=e[g];if(w.push(...m.subjects),m.range[0]<v&&(v=m.range[0]),m.range[1]>f&&(f=m.range[1]),a[0]>=m.range[0]&&a[1]<=m.range[1])return e[g].subjects.push(l),e;a[0]<m.range[0]&&a[1]>m.range[0]&&(y.push(g),C=C.concat(m.subjects)),a[0]>=m.range[0]&&a[0]<=m.range[1]&&(y.push(g),C=C.concat(m.subjects),a[0]=m.range[0]),a[1]>=m.range[0]&&a[1]<=m.range[1]&&(y.push(g),C=C.concat(m.subjects),a[1]=m.range[1])}if(w.push(l),a[0]<=v&&a[1]>=f)return[{subjects:w,range:a}];y.length&&y.reverse().forEach(g=>{e.splice(g,1)}),e.push({subjects:C.concat([l]),range:a})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var io=J(Nt(),1),Wr=J(Mt(),1),so=J(ro(),1);function no(){let r={};function e(){for(let c in r)Object.prototype.hasOwnProperty.call(r,c)&&delete r[c]}function t(c){let a={};for(let l in r)+l<=c&&(a[l]=r[l]);return a}function n(c){let a={};for(let l in r)+l>=c&&(a[l]=r[l]);return a}function i({timestamp:c,priority:a,initiator:l}){var y;if(Rr(c)){let f=(y=r[c])!=null?y:null;if(f&&a&&Be(a,!0)){let v={},C=f[a];if(C&&(v={...v,...C}),v=oe(v)?null:v,v&&Be(l,!0)){let w=v[l];return w!=null?w:null}return v}return f}return null}function s({timestamp:c,priority:a,initiator:l}){if(Rr(c))if(r[c]){if(a&&Be(a,!0))if(r[c][a]){if(l&&Be(l,!0))if(r[c][a][l]){if(delete r[c][a][l],!oe(r[c][a]))return!0}else return!1;if(delete r[c][a],!oe(r[c]))return!0}else return!1;return delete r[c]}else return!1;return!1}function o({timestamp:c,priority:a,initiator:l,...y}){var f,v,C;(v=(f=r[c])==null?void 0:f[a])!=null&&v[l]?r[c][a][l].push({...y}):(C=r[c])!=null&&C[a]?r[c][a]={...r[c][a],[l]:[{...y}]}:r[c]?r[c]={...r[c],[a]:{[l]:[{...y}]}}:r[c]={[a]:{[l]:[{...y}]}}}return{map:r,remove:s,add:o,removeAll:e,get:i,getLte:t,getGte:n}}var _p=[O.expect,O.setNextBranch],Fp=1/0;function ao(r,e){let t=r,n,i=qp(e),s=no(),o,c=()=>{C(),h()},a=u=>{s.add.call(void 0,u),g()},l=(u=[])=>{for(let d of u)if(d.action(),(0,io.default)(_p,d.actionType))break},y=(u=1/0)=>{var b,T,P;let d=$t((b=s.get({timestamp:u,priority:"control"}))!=null?b:{}),E=$t((T=s.get({timestamp:u,priority:"container"}))!=null?T:{}),I=$t((P=s.get({timestamp:u,priority:"chapter"}))!=null?P:{});return[...d,...E,...I]},f=u=>{i.isReady(u)&&l(y(u))},v=()=>{var u;l([...$t((u=s.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},C=()=>{n&&(o==null||o.unsubscribe(),n=void 0)},w=u=>{},g=()=>{n||(n=()=>setTimeout(()=>{f(1/0)}),o=t.events.ended$.subscribe(n))},m=u=>{C(),t=u},A=u=>{u.priority==="container"&&i.resetCalled(u.timestamp),s.remove(u)},h=()=>{i.release(),s.removeAll()};return{setPlayer:m,add:a,remove:A,exec:f,execEndOfVideo:v,listen:g,unlisten:C,release:c,containersEventsCallState:i,getPreparedToExecActions:y}}function qp(r){let e=new Map;return{setCalled:({timestamp:c,id:a})=>{let l=e.get(c);l&&l[a]!==void 0&&(l[a]=!0)},setData:(c=[])=>{var a;for(let l of c){let y=(a=l.endTime)!=null?a:Fp,f=e.get(y);e.set(y,{...f,[l.id]:!1})}},resetCalled:c=>{let a=e.get(c);if(a)for(let l in a)a[l]=!1},isReady:c=>{let a=e.get(c);if(!a)return!0;let l=(0,Wr.default)(a);return r?l.some(f=>f):!l.some(f=>!f)},release:()=>e.clear()}}function $t(r){return(0,so.default)((0,Wr.default)(r)).sort(e=>e.actionType===O.expect?-1:1)}var oo={videoContentHeight:0,videoContentWidth:0},co=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return oo;let{clientHeight:n,clientWidth:i}=r.experimental.element$.getValue()||{};if(!(n&&i))return oo;let s=e/t,o=n/i,c,a;return o>s?(a=i,c=i*s):o<s?(a=n/s,c=n):(a=i,c=n),{videoContentWidth:a,videoContentHeight:c}};var Bp=250;function lo(r){let e,t=new ResizeObserver(c=>{s(c),e=s.bind(null,c)});function n(c){let{parentElement:a,player:l}=r();if(a&&l){let{videoContentWidth:y,videoContentHeight:f}=co(l);a.style.setProperty("--interactive-content-width",`${y}px`),a.style.setProperty("--interactive-content-height",`${f}px`),a.style.setProperty("--interactive-width",`${c[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${c[0].contentRect.height}px`)}}function i(){let{parentElement:c}=r();c.removeAttribute("style")}let s=Fe(c=>{let{fns:a=[]}=r();n(c);for(let l of a)l()},Bp);function o(){e=void 0,t.disconnect(),i()}return{resizeObserver:t,calc:()=>{e==null||e()},release:o}}var Dp=r=>Math.floor(Math.random()*r),po=r=>{var i;let e=r.length,t=1/0,n=null;for(;e--;){let s=r[e],o=(i=s.weight)!=null?i:1;o<t&&(t=o,n=s)}return n},ho=r=>{var i;let e=r.length,t=-1/0,n=null;for(;e--;){let s=r[e],o=(i=s.weight)!=null?i:0;o>t&&(t=o,n=s)}return n};var mo=r=>{let e=r.length,t=Dp(e);return r[t]},uo=1,fo=r=>{var n,i;let e=0;for(let s=0;s<r.length;++s)e+=(n=r[s].weight)!=null?n:uo;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(i=r[s].weight)!=null?i:uo,e>=t)return r[s];return r[r.length-1]};var vo={shouldOpenNow:!0,isDetachContainer:!0},yo="after-expect";var Kr=(r,e=!1)=>({...r,args:e?{...r.args,...vo}:{...vo,...r.args}}),go=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:n})=>{let i={isExpect:!1},s=()=>{i.isExpect&&(i.isExpect=!1)},o=({action:h,controlType:u,controlId:d,containerId:E,branches:I=[],onEvent:b,isEOV:T=()=>!1,isDisabled:P=()=>!1})=>{let x=Kr(h,T()),M={timestamp:1/0,priority:"control",initiator:d,actionType:x.type},U=P(),G=r.emit.bind(r,R.interactives,{subjectId:d,subjectType:u,subjectName:"control",type:U?k.actionChoiceCanceled:k.actionChoice,actionType:h.type,payload:{invokeImmediately:x.args.shouldOpenNow,containerId:E,...x.args}}),z=()=>{e.interactiveActionChoice$.next({subjectId:d,subjectType:u,subjectName:"control",type:U?"action-choice-canceled":"action-choice",actionType:h.type,payload:{invokeImmediately:x.args.shouldOpenNow,containerId:E,...x.args}})};if(U){G(),z();return}switch(x.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{let Z=I.find(he=>he.id===x.args.branchId);if(!Z)return;b(x.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),z(),x.args.shouldOpenNow?g({subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{chapterId:Z.chapterId,autoSelect:!1}}):n.add({...M,action:g.bind(null,{subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{chapterId:Z.chapterId,autoSelect:!1}})});return}case O.continuePlayback.trim().toLowerCase():{b(x.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),z(),x.args.shouldOpenNow?w({subjectId:d,subjectName:"control",subjectType:u,action:h}):n.add({...M,action:w.bind(null,{subjectId:d,subjectName:"control",subjectType:u,action:h})});return}case O.openURI.trim().toLowerCase():{b(x.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),z(),x.args.shouldOpenNow?A({subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{URI:h.args.uri}}):n.add({...M,action:A.bind(null,{subjectId:d,subjectName:"control",subjectType:u,action:x,payload:{URI:h.args.uri}})});return}default:{let Z="Unexpected control event",he=new L(1,1,{message:Z});y(he,Z);return}}},c=({action:h,container:{id:u,endTime:d},branches:E=[],isEOV:I=!1,autoSelected:b=!1})=>{let T=Kr(h,I),P={timestamp:!T.args.shouldOpenNow||I?1/0:d!=null?d:1/0,priority:"container",initiator:u,actionType:T.type},x=r.emit.bind(r,R.interactives,{subjectId:u,subjectName:"container",type:k.actionChoice,actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),M=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"container",type:"action-choice",actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}})};switch(T.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{let U=E.find(G=>G.id===T.args.branchId);if(!U)return;x(),M(),n.add({...P,action:g.bind(null,{subjectId:u,subjectName:"container",action:T,payload:{chapterId:U.chapterId,autoSelect:b}})});return}case O.setMaxWeightBranch.trim().toLowerCase():return;case O.setMinWeightBranch.trim().toLowerCase():return;case O.setRandomBranch.trim().toLowerCase():return;case O.setWeightlessRandomBranch.trim().toLowerCase():return;case O.continuePlayback.trim().toLowerCase():{x(),M(),n.add({...P,action:w.bind(null,{subjectId:u,subjectName:"container",action:T})});return}case O.openURI.trim().toLowerCase():{x(),M(),n.add({...P,action:A.bind(null,{subjectId:u,subjectName:"container",action:T,payload:{URI:h.args.uri}})});return}default:{let U="Unexpected container event",G=new L(1,1,{message:U});y(G,U);return}}};function a({container:h,branches:u,isEOV:d=!1}){var I,b;let E=jr(h.events);if(E){let T=Kr(E.action,d);r.emit(R.interactives,{subjectId:h.id,subjectName:"container",type:k.actionChoice,actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"container",type:"action-choice",actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),n.add({timestamp:d?1/0:(I=h.endTime)!=null?I:1/0,priority:"container",initiator:h.id,actionType:O.expect,action:v.bind(null,{subjectId:h.id,subjectName:"container"})}),i.isExpect=!0}else for(let T of(b=h.events)!=null?b:[])c({action:T.action,container:h,branches:u,isEOV:d})}let l=({chapterId:h,action:u,branches:d=[]})=>{let E=r.emit.bind(r,R.interactives,{subjectId:h,subjectName:"chapter",type:k.actionChoice,actionType:u.type,payload:u.args}),I=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"chapter",type:"action-choice",actionType:u.type,payload:u.args})};switch(u.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{let b=d.find(T=>T.id===u.args.branchId);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setWeightlessRandomBranch.trim().toLowerCase():{let b=mo(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setRandomBranch.trim().toLowerCase():{let b=fo(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMaxWeightBranch.trim().toLowerCase():{let b=ho(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMinWeightBranch.trim().toLowerCase():{let b=po(d);return b!=null&&b.chapterId?(E(),I(),g.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.continuePlayback.trim().toLowerCase():return E(),I(),w.bind(null,{subjectId:h,subjectName:"chapter",action:u});case O.openURI.trim().toLowerCase():return E(),I(),A.bind(null,{subjectId:h,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:{let b="Unexpected chapter event",T=new L(1,1,{message:b});y(T,b);return}}};function y(h,u){console.error(u),e.error$.next(h),r.emit(R.errors,h)}function f(h){var d;let u=jr(h.events);if(u){if(X(h))return;r.emit(R.interactives,{subjectId:h.id,subjectName:"chapter",type:k.actionChoice,actionType:u.action.type,payload:u.action.args}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"chapter",type:"action-choice",actionType:u.action.type,payload:u.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:O.expect,action:v.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else(d=h.events)==null||d.forEach(E=>{let I=l({chapterId:h.id,action:E.action,branches:h.branches});I&&n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:E.action.type,action:I})})}let v=({subjectId:h,subjectName:u})=>{t.pause(),r.emit(R.interactives,{subjectId:h,subjectName:u,type:k.actionExecution,actionType:O.expect}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,type:"action-execution",actionType:O.expect})},C=({subjectId:h,subjectName:u})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),r.emit(R.interactives,{subjectId:h,subjectName:u,type:k.actionExecution,actionType:yo}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,type:"action-execution",actionType:yo})},w=({subjectId:h,subjectName:u,subjectType:d,action:E})=>{r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type})},g=({subjectId:h,subjectName:u,subjectType:d,action:E,payload:I})=>{I.behaviour="change-chapter",r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type,payload:I}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type,payload:I})},m=({subjectId:h,subjectName:u,subjectType:d,action:E,payload:I})=>{I.behaviour="change-manifest",r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type,payload:I}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type,payload:I})},A=({subjectId:h,subjectName:u,subjectType:d,action:E,payload:I})=>{if(!I.URI)return;let b=window.open(I.URI,"_blank","noopener,noreferrer");b&&(b.opener=null),r.emit(R.interactives,{subjectId:h,subjectName:u,subjectType:d,type:k.actionExecution,actionType:E.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:u,subjectType:d,type:"action-execution",actionType:E.type})};return{onControlEvent:o,onContainerEvent:c,onChapterEvent:l,onExpectEvent:v,expectEventHandler:C,setManifestChapterEvents:f,setManifestContainerEvents:a,stopExpect:s,state:i}};var Yr=J(Ar(),1);import{Subscription as Wp,Subject as Xr,ValueSubject as Xe}from"@vkontakte/videoplayer-shared/es2018";var Qr=(r,e)=>{let t={};return r.map(n=>{if(!t[n]){let i=e.chapters.find(o=>o.id===n);if(!i)return null;let s=e.media.videos.find(o=>i.videoId===o.id);if(!s)return null;t[n]=Eo(s)}return t[n]}).filter(Boolean)},Up=r=>{for(let e of r.variants)if(Gp(e)&&e.payload)return e.payload.id},Gp=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Eo=r=>{let e=Up(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},zp=(r,e)=>{for(let t of r.media.videos)if(e===Eo(t)){for(let n of r.chapters)if(n.videoId===t.id)return n.id;return}},Io=(r,e)=>r.reduce((t,n)=>{let i=zp(e,n);return i?[...t,i]:t},[]);var ee,le,ue,H,_t,te,re,Y,pe,we,Ae,Ye=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:i,settings:s}){this.state={history$:new Xe([]),hasPrevChapter$:new Xe(!1),prevChapter$:new Xe(null),isInitialChapter$:new Xe(!1),isGoBackLimited$:new Xe(!1)};F(this,ee,null);F(this,le);F(this,ue,!1);F(this,H,null);F(this,_t,null);this.events={inited$:new Xr,destroyed$:new Xr,error$:new Xr};F(this,te,null);F(this,re,null);F(this,Y,null);F(this,pe,new Wp);F(this,we,!1);F(this,Ae,0);var o;N(this,te,t),N(this,Y,e),N(this,re,n),N(this,ee,i),N(this,le,s),this.state.history$&&S(this,pe)&&((o=S(this,pe))==null||o.add(this.state.history$.subscribe(c=>{var a,l;this.state.prevChapter$.next((0,Yr.default)(c,-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((l=(a=S(this,H))==null?void 0:a.metadata)==null?void 0:l.initChapterId)),this.state.isGoBackLimited$.next(S(this,Ae)===S(this,le).maxLength-1)})))}async setManifest(e){if(!S(this,re)||!S(this,Y))return;N(this,H,e),await this.getProjectHistory();let t=this.getInitialChapterId();await S(this,re).setChapter({chapterId:t,pushToHistory:!1}),S(this,ue)||(N(this,ue,!0),this.events.inited$.next({initChapterId:t}))}get inited(){return S(this,ue)}async updateHistory(e,t=!0){var c;if(!S(this,H))return;S(this,we)?(N(this,we,!1),ln(this,Ae)._++):N(this,Ae,0);let n=S(this,H),i=e.length-S(this,le).maxLength,s=i>0?e.slice(i):e,o=Qr(s,n);if(N(this,_t,o),this.state.history$.next(s),!(!t||!S(this,ee)||!S(this,te)))try{await S(this,ee).save(S(this,te),o)}catch(a){let l=new L(1,5,"Unable to save interactive history");this.events.error$.next(l),(c=S(this,Y))==null||c.emit(R.errors,l)}}async goBack(){var n;if(!this.state||!S(this,re)){let i=new L(1,5,"Unable to save interactive history");return this.events.error$.next(i),(n=S(this,Y))==null?void 0:n.emit(R.errors,i)}N(this,we,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await S(this,re).setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){var i;if(!S(this,H)||!S(this,te))return;let e=S(this,H),t=[this.getInitialVideoId()];if(S(this,ee))try{let s=await S(this,ee).get(S(this,te));s.length&&(t=s)}catch(s){let o=new L(1,5,"Error while trying to fetch data");this.events.error$.next(o),(i=S(this,Y))==null||i.emit(R.errors,o)}let n=Io(t,e);this.state.history$.next(n)}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,Yr.default)(e,-1)||S(this,le).initChapterId||((t=S(this,H))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(S(this,H)){let e=this.getInitialChapterId();return Qr([e],S(this,H)).pop()}return null}destroy(){var e,t;N(this,te,null),N(this,ee,null),N(this,re,null),(e=S(this,pe))==null||e.unsubscribe(),N(this,pe,null),N(this,ue,!1),(t=S(this,Y))==null||t.emit(R.historyDestroyed),this.events.destroyed$.next(),N(this,Y,null)}};ee=new WeakMap,le=new WeakMap,ue=new WeakMap,H=new WeakMap,_t=new WeakMap,te=new WeakMap,re=new WeakMap,Y=new WeakMap,pe=new WeakMap,we=new WeakMap,Ae=new WeakMap;var Ft=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var i;let e=(i=this.rootElement.getContext("2d"))==null?void 0:i.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let s=3;s<n;s+=40)if(t[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let i;t&&(i=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&i&&this.restore(i),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var qt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
7
7
  position: absolute;
8
8
  top: 0;
9
9
  left: 0;
@@ -16,7 +16,7 @@ var Po=Object.create;var an=Object.defineProperty;var ko=Object.getOwnPropertyDe
16
16
  top: 50%;
17
17
  left: 50%;
18
18
  transform: translate(-50%, -50%);
19
- `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),n={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(i){this._onError(i)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var n,i,s;return((n=t.controls)==null?void 0:n.length)&&e>=((i=t.startTime)!=null?i:0)&&e<=Math.min((s=t.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,n;(n=(t=this._callbacks)==null?void 0:t.onError)==null||n.call(t,e)}};function To(r=0){return new Promise(e=>{setTimeout(()=>{e(0)},r)})}var Qp=`
19
+ `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),n={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(i){this._onError(i)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var n,i,s;return((n=t.controls)==null?void 0:n.length)&&e>=((i=t.startTime)!=null?i:0)&&e<=Math.min((s=t.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,n;(n=(t=this._callbacks)==null?void 0:t.onError)==null||n.call(t,e)}};function To(r=0){return new Promise(e=>{setTimeout(()=>{e(0)},r)})}var Kp=`
20
20
  .${q.common} {
21
21
  opacity: 1;
22
22
  visibility: visible;
@@ -30,7 +30,7 @@ var Po=Object.create;var an=Object.defineProperty;var ko=Object.getOwnPropertyDe
30
30
  .${q.hidden} {
31
31
  visibility: hidden;
32
32
  }
33
- `,Xp=`
33
+ `,Qp=`
34
34
  .interactive-chapter {
35
35
  position: absolute;
36
36
  top: 0;
@@ -40,7 +40,7 @@ var Po=Object.create;var an=Object.defineProperty;var ko=Object.getOwnPropertyDe
40
40
  --interactive-transition-1: 100ms ease-in-out;
41
41
  }
42
42
 
43
- ${Qp}
43
+ ${Kp}
44
44
 
45
45
  .${V.common} {
46
46
  display: flex;
@@ -57,4 +57,4 @@ var Po=Object.create;var an=Object.defineProperty;var ko=Object.getOwnPropertyDe
57
57
  .${V.area} {
58
58
  cursor: pointer;
59
59
  }
60
- `,xo=r=>{let e=document.createElement("style");e.textContent=Xp,r.prepend(e)};import{clientChecker as eh}from"@vkontakte/videoplayer-core/es2018";var Ao=Object.freeze({lang:Zp.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}});function th(){let r=document.createElement("div");return r.classList.add("interactive-chapter"),r}var Bt=class{constructor(e){this.playerSubscriptions=new Zr;this.subscriptions=new Zr;this.globalEventEmitter=new xt;this.animation=new St;this.seekToInteractiveController=new He;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=th();this.factories=new Map([["choice",ct]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new Zr;this.graph=null;this.lastFrame=null;this.appState=0;this.state={prevChapter$:new _(null),isInitialChapter$:new _(!1),isFirstChapter$:new _(!0),isEndChapter$:new _(!1),isInteractiveExpectation$:new _(!1),isReplay$:new _(!1),calledByInteractive$:new _(!1),lastChapterChangeWasInitiatedByInteractive$:new _(!1),disabledControls$:new _(!1),interactiveRanges$:new _([]),isInteractiveTime$:new _(!1),statistics$:new _(null),isSeekable$:new _(!1)};this.events={noInteraction$:new $,graphVisibilityChanged$:new $,watchAgainIsClicked$:new $,chapterChanged$:new $,playerChanged$:new $,error$:new $,eachTick$:new $,manifestChanged$:new $,interactiveRangeEnded$:new $,interactiveContainerRemoved$:new $,interactiveContainerFakeRemoved$:new $,interactiveActionExecution$:new $,interactiveActionChoice$:new $,interactiveVisibilityChanged$:new $};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(R.errors,e)};this.clearHistoryIfEnded=()=>{var i;let e=(i=this.player)==null?void 0:i.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&X(n)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...n}=e;if(t){let{statSubscription:i,oneStat:s}=t;i.add(s.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(R.playerChanged,n)};this.onPlaybackStarted=()=>{var e;(e=this.resizeManager)==null||e.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(t=>{!e&&t.isPermanentText||(this.animation.removeFn(t.whilePlaying),t.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,i=t.getValue().map(s=>({...s,subjects:s.subjects.filter(o=>o.id!==e)}));t.next(i)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};var n;this._options={...Ao,...e,config:{...Ao.config,...e.config}},this._options.parentElement.append(this.rootElement),this.historyController=new Ye({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:(n=this._options.projectInfo)==null?void 0:n.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new qt({parentElement:this._options.parentElement,onError:i=>{let s=new L(1,6,i);this.emitErrorEvent(s)}})),xo(this._options.parentElement),this.subscriptions.add(wo(this.rootElement,"mousedown").subscribe(i=>i.stopPropagation())).add(wo(this.rootElement,"mouseup").subscribe(i=>i.stopPropagation())),this.manifestController=new xe(this._options.loaders,i=>{let s=new L(1,3,i);this.emitErrorEvent(s)});let t=[];this._options.lastFrame&&t.push(()=>{var i;(i=this.lastFrame)==null||i.updateCanvasDimensions(!0)}),t.push(()=>{let i=this.state.isInteractiveTime$.getValue();for(let s of this.gameControllers)s.onResize(i)}),this.resizeManager=lo(()=>({player:this.player,parentElement:this._options.parentElement,fns:t})),this._options.graph&&(this.graph=new De({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:i=>{this.setChapter({chapterId:i}),this.globalEventEmitter.emit(R.graph,{type:Ke.watchAgainClicked,chapterId:i}),this.events.watchAgainIsClicked$.next(i)},onError:i=>{let s=new L(1,2,{message:i});this.emitErrorEvent(s)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{var t,n;if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((t=e.payload)==null?void 0:t.behaviour)==="change-chapter"){let{chapterId:i}=e.payload;this.setChapter({chapterId:i}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(((n=e.payload)==null?void 0:n.behaviour)==="change-manifest"){let{manifestURL:i}=e.payload;i&&this.setManifest(i)}e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:n})=>{e!=="action-choice"||t==="chapter"||"invokeImmediately"in n&&n.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=Hr(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,i=this.getInteractiveRanges().reverse().find(({range:s})=>t>=s[1]);if(i){let s=i.range.join("-");this.endedRanges.has(s)||(this.endedRanges.add(s),this.globalEventEmitter.emit(R.interactives,{type:k.rangeEnded,payload:i,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:i}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Jp()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Yp({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:n})=>{var a;let i;if(n)i=!0;else{let l=e*1e3;i=!!t.find(({range:[f,v],subjects:C})=>f<l&&l<v&&C.some(w=>!w.isRemoved)&&C.length)}i!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(i);let s=!!this.noInteractionTimeout,c=((a=this.player)==null?void 0:a.info.playbackState$.getValue())==="playing"||n;i&&!s&&c?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):s&&!c&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{var t;(t=this.lastFrame)==null||t.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{var t;e&&((t=this.lastFrame)==null||t.setVideoElement(e))})).add(this.player.events.firstFrame$.subscribe(()=>{var e;(e=this.lastFrame)==null||e.reset(),setTimeout(()=>{var t,n;(t=this.lastFrame)==null||t.hide(),(n=this.lastFrame)==null||n.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){var t,n;let e=this.manifestController.chapter;e&&this.appState===1&&((t=this.selectBranches)==null||t.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),(n=this.interactiveEvents)==null||n.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(i=>i.container.container).filter(i=>!Te(i.controls))),this._options.lastFrame&&this.animation.addFn(()=>{var i;this.player&&((i=this.lastFrame)==null||i.onEachTick(this.player.info.position$.getValue()*1e3))},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(n=>{let i=n.type.trim().toLowerCase(),s=this.factories.get(i),o=s==null?void 0:s(n,this.rootElement);if(o&&this.selectBranches&&this.interactiveEvents&&this.player){let c=new Lt({player:this.player,container:o,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>Vs(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)}});this.animation.addFn(c.whilePlaying,!0),t.push(c)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!t||!n&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){var c,a;if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),i=(c=n&&X(n)&&Vt(n))!=null?c:!1,s=((a=this.manifestController.manifest)==null?void 0:a.metadata.initChapterId)===e,o=this.historyController.state.history$.getValue();if(s||i&&t){this.historyController.updateHistory([e]);return}(0,Ro.default)(o,-1)!==e&&this.historyController.updateHistory([...o,e])}handleFakeRemoval(e,t){let{interactiveRanges$:n}=this.state,s=n.getValue().map(o=>{let c=o.subjects.some(l=>l.id===e),a=o.subjects.map(l=>t&&c||l.id===e?{...l,isRemoved:!0}:l);return{...o,subjects:a}});n.next(s)}reset(){var e;this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),(e=this.interactiveEvents)==null||e.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}get options(){return this._options}init(){var e;this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&((e=this.resizeManager)==null||e.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.events.manifestChanged$.next(t.manifest),this.globalEventEmitter.emit(R.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=ao(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=go({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:n=!1}={}){var a,l;this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&eh.browser.isSafari&&await To(35);let i=!n&&this.state.isEndChapter$.getValue()&&((a=this.getCurrentManifest())==null?void 0:a.metadata.initChapterId)===e;this.state.isReplay$.next(i);let{chapter:s,media:o,graph:c}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||i)&&this.state.isFirstChapter$.next(!0),!(!s||!o)&&(t&&this.pushChapterToHistory(s.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(s),(l=this.lastFrame)==null||l.setCurrentChapter(s),this.events.chapterChanged$.next({chapter:s,manifestVideo:o}),this.globalEventEmitter.emit(R.chapterChanged,{chapter:s,media:o,graph:c}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new So(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?Ze.GRAPH_SHOW:Ze.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(Ze.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:n,subjectType:i})=>{t!=="action-choice"||n!=="control"||(i==="Button"&&e.next(Ze.NEXT_BUTTON),i==="Area"&&e.next(Ze.NEXT_AREA))}))}),nextMovie$:new So(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t!=null&&t.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(R.graph,{type:Ke.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.updateVideosInfo(e))}deadEndCheck(){var n;return!(((n=this.interactiveEvents)==null?void 0:n.getPreparedToExecActions())||[]).some(i=>i.actionType===O.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(t=>!t.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(n=>{let i=n.container.container;return!n.container.isRemoved&&i.endTime===null&&ce(i.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&It(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){var e;return Ta((e=this.manifestController.chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){var e,t,n,i,s;this.clearHistoryIfEnded(),this.destroyGameControllers(),this.gameControllers=[],(e=this.graph)==null||e.destroy(),this.seamlessControllerSubs.unsubscribe(),(t=this.seamlessController)==null||t.removeAll(),(n=this.resizeManager)==null||n.release(),this.animation.release(),(i=this.interactiveEvents)==null||i.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),(s=this.lastFrame)==null||s.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var rh={Container:me,createChoiceContainer:ct,createAreaControl:st,createButtonControl:ot,classnamesPrefix:hn};var Py={version:un};export{Om as ContainerTypes,Tt as ControlTypes,L as CustomError,R as EVENT_NAMES,O as EventActionTypes,Pm as EventTypes,Bt as Interactives,xe as ManifestController,Py as SDKInfo,Qr as chapterIdsToVKVideoIds,Vr as compareVersions,Tm as containerTypes,xm as controlTypes,ws as eventActionTypes,Sm as eventTypes,Wp as getChapterIdByVkVideoId,Eo as getVKVideoIdByMedia,Gp as getVideoRawIdByMedia,Ke as graphEventTypes,Vt as hasEndTemplate,k as interactivesEventTypes,Im as isAreaControl,Em as isButtonControl,X as isLastChapter,Te as isOneTextCtrlContainer,It as isSupportedManifest,Et as isTextControl,zp as isVKVariantItem,Ss as isValidManifest,As as migrateManifestToLatestVersion,rh as utils,Io as vkVideoIdsToChapterIds};
60
+ `,xo=r=>{let e=document.createElement("style");e.textContent=Qp,r.prepend(e)};import{clientChecker as Jp}from"@vkontakte/videoplayer-core/es2018";var Ao=Object.freeze({lang:Yp.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}});function eh(){let r=document.createElement("div");return r.classList.add("interactive-chapter"),r}var Bt=class{constructor(e){this.playerSubscriptions=new Zr;this.subscriptions=new Zr;this.globalEventEmitter=new xt;this.animation=new St;this.seekToInteractiveController=new He;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=eh();this.factories=new Map([["choice",ct]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new Zr;this.graph=null;this.lastFrame=null;this.appState=0;this.state={prevChapter$:new _(null),isInitialChapter$:new _(!1),isFirstChapter$:new _(!0),isEndChapter$:new _(!1),isInteractiveExpectation$:new _(!1),isReplay$:new _(!1),calledByInteractive$:new _(!1),lastChapterChangeWasInitiatedByInteractive$:new _(!1),disabledControls$:new _(!1),interactiveRanges$:new _([]),isInteractiveTime$:new _(!1),statistics$:new _(null),isSeekable$:new _(!1)};this.events={noInteraction$:new $,graphVisibilityChanged$:new $,watchAgainIsClicked$:new $,chapterChanged$:new $,playerChanged$:new $,error$:new $,eachTick$:new $,manifestChanged$:new $,interactiveRangeEnded$:new $,interactiveContainerRemoved$:new $,interactiveContainerFakeRemoved$:new $,interactiveActionExecution$:new $,interactiveActionChoice$:new $,interactiveVisibilityChanged$:new $};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(R.errors,e)};this.clearHistoryIfEnded=()=>{var i;let e=(i=this.player)==null?void 0:i.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&X(n)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...n}=e;if(t){let{statSubscription:i,oneStat:s}=t;i.add(s.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(R.playerChanged,n)};this.onPlaybackStarted=()=>{var e;(e=this.resizeManager)==null||e.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(t=>{!e&&t.isPermanentText||(this.animation.removeFn(t.whilePlaying),t.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,i=t.getValue().map(s=>({...s,subjects:s.subjects.filter(o=>o.id!==e)}));t.next(i)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};var n;this._options={...Ao,...e,config:{...Ao.config,...e.config}},this._options.parentElement.append(this.rootElement),this.historyController=new Ye({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:(n=this._options.projectInfo)==null?void 0:n.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new qt({parentElement:this._options.parentElement,onError:i=>{let s=new L(1,6,i);this.emitErrorEvent(s)}})),xo(this._options.parentElement),this.subscriptions.add(wo(this.rootElement,"mousedown").subscribe(i=>i.stopPropagation())).add(wo(this.rootElement,"mouseup").subscribe(i=>i.stopPropagation())),this.manifestController=new xe(this._options.loaders,i=>{let s=new L(1,3,i);this.emitErrorEvent(s)});let t=[];this._options.lastFrame&&t.push(()=>{var i;(i=this.lastFrame)==null||i.updateCanvasDimensions(!0)}),t.push(()=>{let i=this.state.isInteractiveTime$.getValue();for(let s of this.gameControllers)s.onResize(i)}),this.resizeManager=lo(()=>({player:this.player,parentElement:this._options.parentElement,fns:t})),this._options.graph&&(this.graph=new De({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:i=>{this.setChapter({chapterId:i}),this.globalEventEmitter.emit(R.graph,{type:Ke.watchAgainClicked,chapterId:i}),this.events.watchAgainIsClicked$.next(i)},onError:i=>{let s=new L(1,2,{message:i});this.emitErrorEvent(s)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{var t,n;if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((t=e.payload)==null?void 0:t.behaviour)==="change-chapter"){let{chapterId:i}=e.payload;this.setChapter({chapterId:i}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(((n=e.payload)==null?void 0:n.behaviour)==="change-manifest"){let{manifestURL:i}=e.payload;i&&this.setManifest(i)}e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:n})=>{e!=="action-choice"||t==="chapter"||"invokeImmediately"in n&&n.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=Hr(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,i=this.getInteractiveRanges().reverse().find(({range:s})=>t>=s[1]);if(i){let s=i.range.join("-");this.endedRanges.has(s)||(this.endedRanges.add(s),this.globalEventEmitter.emit(R.interactives,{type:k.rangeEnded,payload:i,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:i}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Zp()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Xp({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:n})=>{var a;let i;if(n)i=!0;else{let l=e*1e3;i=!!t.find(({range:[f,v],subjects:C})=>f<l&&l<v&&C.some(w=>!w.isRemoved)&&C.length)}i!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(i);let s=!!this.noInteractionTimeout,c=((a=this.player)==null?void 0:a.info.playbackState$.getValue())==="playing"||n;i&&!s&&c?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):s&&!c&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{var t;(t=this.lastFrame)==null||t.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{var t;e&&((t=this.lastFrame)==null||t.setVideoElement(e))})).add(this.player.events.firstFrame$.subscribe(()=>{var e;(e=this.lastFrame)==null||e.reset(),setTimeout(()=>{var t,n;(t=this.lastFrame)==null||t.hide(),(n=this.lastFrame)==null||n.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){var t,n;let e=this.manifestController.chapter;e&&this.appState===1&&((t=this.selectBranches)==null||t.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),(n=this.interactiveEvents)==null||n.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(i=>i.container.container).filter(i=>!Te(i.controls))),this._options.lastFrame&&this.animation.addFn(()=>{var i;this.player&&((i=this.lastFrame)==null||i.onEachTick(this.player.info.position$.getValue()*1e3))},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(n=>{let i=n.type.trim().toLowerCase(),s=this.factories.get(i),o=s==null?void 0:s(n,this.rootElement);if(o&&this.selectBranches&&this.interactiveEvents&&this.player){let c=new Lt({player:this.player,container:o,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>Vs(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)}});this.animation.addFn(c.whilePlaying,!0),t.push(c)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!t||!n&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){var c,a;if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),i=(c=n&&X(n)&&Vt(n))!=null?c:!1,s=((a=this.manifestController.manifest)==null?void 0:a.metadata.initChapterId)===e,o=this.historyController.state.history$.getValue();if(s||i&&t){this.historyController.updateHistory([e]);return}(0,Ro.default)(o,-1)!==e&&this.historyController.updateHistory([...o,e])}handleFakeRemoval(e,t){let{interactiveRanges$:n}=this.state,s=n.getValue().map(o=>{let c=o.subjects.some(l=>l.id===e),a=o.subjects.map(l=>t&&c||l.id===e?{...l,isRemoved:!0}:l);return{...o,subjects:a}});n.next(s)}reset(){var e;this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),(e=this.interactiveEvents)==null||e.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}get options(){return this._options}init(){var e;this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&((e=this.resizeManager)==null||e.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.events.manifestChanged$.next(t.manifest),this.globalEventEmitter.emit(R.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=ao(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=go({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:n=!1}={}){var a,l;this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&Jp.browser.isSafari&&await To(35);let i=!n&&this.state.isEndChapter$.getValue()&&((a=this.getCurrentManifest())==null?void 0:a.metadata.initChapterId)===e;this.state.isReplay$.next(i);let{chapter:s,media:o,graph:c}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||i)&&this.state.isFirstChapter$.next(!0),!(!s||!o)&&(t&&this.pushChapterToHistory(s.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(s),(l=this.lastFrame)==null||l.setCurrentChapter(s),this.events.chapterChanged$.next({chapter:s,manifestVideo:o}),this.globalEventEmitter.emit(R.chapterChanged,{chapter:s,media:o,graph:c}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new So(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?Ze.GRAPH_SHOW:Ze.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(Ze.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:n,subjectType:i})=>{t!=="action-choice"||n!=="control"||(i==="Button"&&e.next(Ze.NEXT_BUTTON),i==="Area"&&e.next(Ze.NEXT_AREA))}))}),nextMovie$:new So(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t!=null&&t.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(R.graph,{type:Ke.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.updateVideosInfo(e))}deadEndCheck(){var n;return!(((n=this.interactiveEvents)==null?void 0:n.getPreparedToExecActions())||[]).some(i=>i.actionType===O.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(t=>!t.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(n=>{let i=n.container.container;return!n.container.isRemoved&&i.endTime===null&&ce(i.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&It(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){var e;return Ta((e=this.manifestController.chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){var e,t,n,i,s;this.clearHistoryIfEnded(),this.destroyGameControllers(),this.gameControllers=[],(e=this.graph)==null||e.destroy(),this.seamlessControllerSubs.unsubscribe(),(t=this.seamlessController)==null||t.removeAll(),(n=this.resizeManager)==null||n.release(),this.animation.release(),(i=this.interactiveEvents)==null||i.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),(s=this.lastFrame)==null||s.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var th={Container:me,createChoiceContainer:ct,createAreaControl:st,createButtonControl:ot,classnamesPrefix:hn};var Py={version:un};export{Rm as ContainerTypes,Tt as ControlTypes,L as CustomError,R as EVENT_NAMES,O as EventActionTypes,Om as EventTypes,Bt as Interactives,xe as ManifestController,Py as SDKInfo,Qr as chapterIdsToVKVideoIds,Vr as compareVersions,Im as containerTypes,Tm as controlTypes,ws as eventActionTypes,xm as eventTypes,zp as getChapterIdByVkVideoId,Eo as getVKVideoIdByMedia,Up as getVideoRawIdByMedia,Ke as graphEventTypes,Vt as hasEndTemplate,k as interactivesEventTypes,Em as isAreaControl,gm as isButtonControl,X as isLastChapter,Te as isOneTextCtrlContainer,It as isSupportedManifest,Et as isTextControl,Gp as isVKVariantItem,Ss as isValidManifest,As as migrateManifestToLatestVersion,th as utils,Io as vkVideoIdsToChapterIds};