@vkontakte/videoplayer-interactive 1.0.37-dev.6c00e4da.0 → 1.0.37-dev.8109bc71.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/esnext.cjs.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.37-dev.6c00e4da.0
3
- * Tue, 27 May 2025 09:24:09 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.37-dev.8109bc71.0
3
+ * Wed, 04 Jun 2025 09:45:19 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-37/doc/
5
5
  */
6
- "use strict";var Ta=Object.create;var Je=Object.defineProperty;var Sa=Object.getOwnPropertyDescriptor;var wa=Object.getOwnPropertyNames;var Aa=Object.getPrototypeOf,Ra=Object.prototype.hasOwnProperty;var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ka=(r,e)=>{for(var t in e)Je(r,t,{get:e[t],enumerable:!0})},Zr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of wa(e))!Ra.call(r,i)&&i!==t&&Je(r,i,{get:()=>e[i],enumerable:!(n=Sa(e,i))||n.enumerable});return r};var D=(r,e,t)=>(t=r!=null?Ta(Aa(r)):{},Zr(e||!r||!r.__esModule?Je(t,"default",{value:r,enumerable:!0}):t,r)),Oa=r=>Zr(Je({},"__esModule",{value:!0}),r);var K=p((Xt,un)=>{"use strict";var Ae=function(r){return r&&r.Math===Math&&r};un.exports=Ae(typeof globalThis=="object"&&globalThis)||Ae(typeof window=="object"&&window)||Ae(typeof self=="object"&&self)||Ae(typeof global=="object"&&global)||Ae(typeof Xt=="object"&&Xt)||function(){return this}()||Function("return this")()});var _=p((od,hn)=>{"use strict";hn.exports=function(r){try{return!!r()}catch{return!0}}});var Re=p((sd,dn)=>{"use strict";var Pa=_();dn.exports=!Pa(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var bn=p((ad,yn)=>{"use strict";var Va=Re(),vn=Function.prototype,mn=vn.apply,fn=vn.call;yn.exports=typeof Reflect=="object"&&Reflect.apply||(Va?fn.bind(mn):function(){return fn.apply(mn,arguments)})});var H=p((ld,En)=>{"use strict";var Cn=Re(),gn=Function.prototype,Yt=gn.call,Ma=Cn&&gn.bind.bind(Yt,Yt);En.exports=Cn?Ma:function(r){return function(){return Yt.apply(r,arguments)}}});var ke=p((cd,xn)=>{"use strict";var In=H(),Na=In({}.toString),La=In("".slice);xn.exports=function(r){return La(Na(r),8,-1)}});var Zt=p((pd,Tn)=>{"use strict";var ja=ke(),$a=H();Tn.exports=function(r){if(ja(r)==="Function")return $a(r)}});var B=p((ud,Sn)=>{"use strict";var Jt=typeof document=="object"&&document.all;Sn.exports=typeof Jt>"u"&&Jt!==void 0?function(r){return typeof r=="function"||r===Jt}:function(r){return typeof r=="function"}});var ie=p((hd,wn)=>{"use strict";var Fa=_();wn.exports=!Fa(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var mt=p((dd,An)=>{"use strict";var _a=Re(),dt=Function.prototype.call;An.exports=_a?dt.bind(dt):function(){return dt.apply(dt,arguments)}});var er=p(On=>{"use strict";var Rn={}.propertyIsEnumerable,kn=Object.getOwnPropertyDescriptor,Ba=kn&&!Rn.call({1:2},1);On.f=Ba?function(e){var t=kn(this,e);return!!t&&t.enumerable}:Rn});var tr=p((fd,Pn)=>{"use strict";Pn.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Mn=p((vd,Vn)=>{"use strict";var qa=H(),Da=_(),Ha=ke(),rr=Object,Ua=qa("".split);Vn.exports=Da(function(){return!rr("z").propertyIsEnumerable(0)})?function(r){return Ha(r)==="String"?Ua(r,""):rr(r)}:rr});var nr=p((yd,Nn)=>{"use strict";Nn.exports=function(r){return r==null}});var ir=p((bd,Ln)=>{"use strict";var Ga=nr(),za=TypeError;Ln.exports=function(r){if(Ga(r))throw new za("Can't call method on "+r);return r}});var Oe=p((Cd,jn)=>{"use strict";var Wa=Mn(),Ka=ir();jn.exports=function(r){return Wa(Ka(r))}});var de=p((gd,$n)=>{"use strict";var Qa=B();$n.exports=function(r){return typeof r=="object"?r!==null:Qa(r)}});var ft=p((Ed,Fn)=>{"use strict";Fn.exports={}});var vt=p((Id,Bn)=>{"use strict";var or=ft(),sr=K(),Xa=B(),_n=function(r){return Xa(r)?r:void 0};Bn.exports=function(r,e){return arguments.length<2?_n(or[r])||_n(sr[r]):or[r]&&or[r][e]||sr[r]&&sr[r][e]}});var Dn=p((xd,qn)=>{"use strict";var Ya=H();qn.exports=Ya({}.isPrototypeOf)});var zn=p((Td,Gn)=>{"use strict";var Za=K(),Hn=Za.navigator,Un=Hn&&Hn.userAgent;Gn.exports=Un?String(Un):""});var Jn=p((Sd,Zn)=>{"use strict";var Yn=K(),ar=zn(),Wn=Yn.process,Kn=Yn.Deno,Qn=Wn&&Wn.versions||Kn&&Kn.version,Xn=Qn&&Qn.v8,U,yt;Xn&&(U=Xn.split("."),yt=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!yt&&ar&&(U=ar.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=ar.match(/Chrome\/(\d+)/),U&&(yt=+U[1])));Zn.exports=yt});var lr=p((wd,ti)=>{"use strict";var ei=Jn(),Ja=_(),el=K(),tl=el.String;ti.exports=!!Object.getOwnPropertySymbols&&!Ja(function(){var r=Symbol("symbol detection");return!tl(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&ei&&ei<41})});var cr=p((Ad,ri)=>{"use strict";var rl=lr();ri.exports=rl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var pr=p((Rd,ni)=>{"use strict";var nl=vt(),il=B(),ol=Dn(),sl=cr(),al=Object;ni.exports=sl?function(r){return typeof r=="symbol"}:function(r){var e=nl("Symbol");return il(e)&&ol(e.prototype,al(r))}});var oi=p((kd,ii)=>{"use strict";var ll=String;ii.exports=function(r){try{return ll(r)}catch{return"Object"}}});var ur=p((Od,si)=>{"use strict";var cl=B(),pl=oi(),ul=TypeError;si.exports=function(r){if(cl(r))return r;throw new ul(pl(r)+" is not a function")}});var li=p((Pd,ai)=>{"use strict";var hl=ur(),dl=nr();ai.exports=function(r,e){var t=r[e];return dl(t)?void 0:hl(t)}});var pi=p((Vd,ci)=>{"use strict";var hr=mt(),dr=B(),mr=de(),ml=TypeError;ci.exports=function(r,e){var t,n;if(e==="string"&&dr(t=r.toString)&&!mr(n=hr(t,r))||dr(t=r.valueOf)&&!mr(n=hr(t,r))||e!=="string"&&dr(t=r.toString)&&!mr(n=hr(t,r)))return n;throw new ml("Can't convert object to primitive value")}});var hi=p((Md,ui)=>{"use strict";ui.exports=!0});var fi=p((Nd,mi)=>{"use strict";var di=K(),fl=Object.defineProperty;mi.exports=function(r,e){try{fl(di,r,{value:e,configurable:!0,writable:!0})}catch{di[r]=e}return e}});var bt=p((Ld,bi)=>{"use strict";var vl=hi(),yl=K(),bl=fi(),vi="__core-js_shared__",yi=bi.exports=yl[vi]||bl(vi,{});(yi.versions||(yi.versions=[])).push({version:"3.38.0",mode:vl?"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 fr=p((jd,gi)=>{"use strict";var Ci=bt();gi.exports=function(r,e){return Ci[r]||(Ci[r]=e||{})}});var Pe=p(($d,Ei)=>{"use strict";var Cl=ir(),gl=Object;Ei.exports=function(r){return gl(Cl(r))}});var me=p((Fd,Ii)=>{"use strict";var El=H(),Il=Pe(),xl=El({}.hasOwnProperty);Ii.exports=Object.hasOwn||function(e,t){return xl(Il(e),t)}});var vr=p((_d,xi)=>{"use strict";var Tl=H(),Sl=0,wl=Math.random(),Al=Tl(1 .toString);xi.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Al(++Sl+wl,36)}});var Ve=p((Bd,Si)=>{"use strict";var Rl=K(),kl=fr(),Ti=me(),Ol=vr(),Pl=lr(),Vl=cr(),fe=Rl.Symbol,yr=kl("wks"),Ml=Vl?fe.for||fe:fe&&fe.withoutSetter||Ol;Si.exports=function(r){return Ti(yr,r)||(yr[r]=Pl&&Ti(fe,r)?fe[r]:Ml("Symbol."+r)),yr[r]}});var ki=p((qd,Ri)=>{"use strict";var Nl=mt(),wi=de(),Ai=pr(),Ll=li(),jl=pi(),$l=Ve(),Fl=TypeError,_l=$l("toPrimitive");Ri.exports=function(r,e){if(!wi(r)||Ai(r))return r;var t=Ll(r,_l),n;if(t){if(e===void 0&&(e="default"),n=Nl(t,r,e),!wi(n)||Ai(n))return n;throw new Fl("Can't convert object to primitive value")}return e===void 0&&(e="number"),jl(r,e)}});var br=p((Dd,Oi)=>{"use strict";var Bl=ki(),ql=pr();Oi.exports=function(r){var e=Bl(r,"string");return ql(e)?e:e+""}});var Mi=p((Hd,Vi)=>{"use strict";var Dl=K(),Pi=de(),Cr=Dl.document,Hl=Pi(Cr)&&Pi(Cr.createElement);Vi.exports=function(r){return Hl?Cr.createElement(r):{}}});var gr=p((Ud,Ni)=>{"use strict";var Ul=ie(),Gl=_(),zl=Mi();Ni.exports=!Ul&&!Gl(function(){return Object.defineProperty(zl("div"),"a",{get:function(){return 7}}).a!==7})});var $i=p(ji=>{"use strict";var Wl=ie(),Kl=mt(),Ql=er(),Xl=tr(),Yl=Oe(),Zl=br(),Jl=me(),ec=gr(),Li=Object.getOwnPropertyDescriptor;ji.f=Wl?Li:function(e,t){if(e=Yl(e),t=Zl(t),ec)try{return Li(e,t)}catch{}if(Jl(e,t))return Xl(!Kl(Ql.f,e,t),e[t])}});var _i=p((zd,Fi)=>{"use strict";var tc=_(),rc=B(),nc=/#|\.prototype\./,Me=function(r,e){var t=oc[ic(r)];return t===ac?!0:t===sc?!1:rc(e)?tc(e):!!e},ic=Me.normalize=function(r){return String(r).replace(nc,".").toLowerCase()},oc=Me.data={},sc=Me.NATIVE="N",ac=Me.POLYFILL="P";Fi.exports=Me});var Er=p((Wd,qi)=>{"use strict";var Bi=Zt(),lc=ur(),cc=Re(),pc=Bi(Bi.bind);qi.exports=function(r,e){return lc(r),e===void 0?r:cc?pc(r,e):function(){return r.apply(e,arguments)}}});var Hi=p((Kd,Di)=>{"use strict";var uc=ie(),hc=_();Di.exports=uc&&hc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Gi=p((Qd,Ui)=>{"use strict";var dc=de(),mc=String,fc=TypeError;Ui.exports=function(r){if(dc(r))return r;throw new fc(mc(r)+" is not an object")}});var Ki=p(Wi=>{"use strict";var vc=ie(),yc=gr(),bc=Hi(),Ct=Gi(),zi=br(),Cc=TypeError,Ir=Object.defineProperty,gc=Object.getOwnPropertyDescriptor,xr="enumerable",Tr="configurable",Sr="writable";Wi.f=vc?bc?function(e,t,n){if(Ct(e),t=zi(t),Ct(n),typeof e=="function"&&t==="prototype"&&"value"in n&&Sr in n&&!n[Sr]){var i=gc(e,t);i&&i[Sr]&&(e[t]=n.value,n={configurable:Tr in n?n[Tr]:i[Tr],enumerable:xr in n?n[xr]:i[xr],writable:!1})}return Ir(e,t,n)}:Ir:function(e,t,n){if(Ct(e),t=zi(t),Ct(n),yc)try{return Ir(e,t,n)}catch{}if("get"in n||"set"in n)throw new Cc("Accessors not supported");return"value"in n&&(e[t]=n.value),e}});var Xi=p((Yd,Qi)=>{"use strict";var Ec=ie(),Ic=Ki(),xc=tr();Qi.exports=Ec?function(r,e,t){return Ic.f(r,e,xc(1,t))}:function(r,e,t){return r[e]=t,r}});var Le=p((Zd,Zi)=>{"use strict";var Ne=K(),Tc=bn(),Sc=Zt(),wc=B(),Ac=$i().f,Rc=_i(),ve=ft(),kc=Er(),ye=Xi(),Yi=me();bt();var Oc=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 Tc(r,this,arguments)};return e.prototype=r.prototype,e};Zi.exports=function(r,e){var t=r.target,n=r.global,i=r.stat,o=r.proto,l=n?Ne:i?Ne[t]:Ne[t]&&Ne[t].prototype,s=n?ve:ve[t]||ye(ve,t,{})[t],a=s.prototype,c,d,f,v,y,k,w,C,u;for(v in e)c=Rc(n?v:t+(i?".":"#")+v,r.forced),d=!c&&l&&Yi(l,v),k=s[v],d&&(r.dontCallGetSet?(u=Ac(l,v),w=u&&u.value):w=l[v]),y=d&&w?w:e[v],!(!c&&!o&&typeof k==typeof y)&&(r.bind&&d?C=kc(y,Ne):r.wrap&&d?C=Oc(y):o&&wc(y)?C=Sc(y):C=y,(r.sham||y&&y.sham||k&&k.sham)&&ye(C,"sham",!0),ye(s,v,C),o&&(f=t+"Prototype",Yi(ve,f)||ye(ve,f,{}),ye(ve[f],v,y),r.real&&a&&(c||!a[v])&&ye(a,v,y)))}});var eo=p((Jd,Ji)=>{"use strict";var Pc=Math.ceil,Vc=Math.floor;Ji.exports=Math.trunc||function(e){var t=+e;return(t>0?Vc:Pc)(t)}});var je=p((em,to)=>{"use strict";var Mc=eo();to.exports=function(r){var e=+r;return e!==e||e===0?0:Mc(e)}});var no=p((tm,ro)=>{"use strict";var Nc=je(),Lc=Math.min;ro.exports=function(r){var e=Nc(r);return e>0?Lc(e,9007199254740991):0}});var $e=p((rm,io)=>{"use strict";var jc=no();io.exports=function(r){return jc(r.length)}});var gt=p((nm,oo)=>{"use strict";oo.exports=function(){}});var so=p(()=>{"use strict";var $c=Le(),Fc=Pe(),_c=$e(),Bc=je(),qc=gt();$c({target:"Array",proto:!0},{at:function(e){var t=Fc(this),n=_c(t),i=Bc(e),o=i>=0?i:n+i;return o<0||o>=n?void 0:t[o]}});qc("at")});var Et=p((sm,ao)=>{"use strict";var Dc=vt();ao.exports=Dc});var co=p((am,lo)=>{"use strict";so();var Hc=Et();lo.exports=Hc("Array","at")});var uo=p((lm,po)=>{"use strict";var Uc=co();po.exports=Uc});var wr=p((cm,ho)=>{"use strict";var Gc=uo();ho.exports=Gc});var Io=p((Qm,Eo)=>{"use strict";var ip=je(),op=Math.max,sp=Math.min;Eo.exports=function(r,e){var t=ip(r);return t<0?op(t+e,0):sp(t,e)}});var Mr=p((Xm,To)=>{"use strict";var ap=Oe(),lp=Io(),cp=$e(),xo=function(r){return function(e,t,n){var i=ap(e),o=cp(i);if(o===0)return!r&&-1;var l=lp(n,o),s;if(r&&t!==t){for(;o>l;)if(s=i[l++],s!==s)return!0}else for(;o>l;l++)if((r||l in i)&&i[l]===t)return r||l||0;return!r&&-1}};To.exports={includes:xo(!0),indexOf:xo(!1)}});var So=p(()=>{"use strict";var pp=Le(),up=Mr().includes,hp=_(),dp=gt(),mp=hp(function(){return!Array(1).includes()});pp({target:"Array",proto:!0,forced:mp},{includes:function(e){return up(this,e,arguments.length>1?arguments[1]:void 0)}});dp("includes")});var Ao=p((Jm,wo)=>{"use strict";So();var fp=Et();wo.exports=fp("Array","includes")});var ko=p((ef,Ro)=>{"use strict";var vp=Ao();Ro.exports=vp});var Ge=p((tf,Oo)=>{"use strict";var yp=ko();Oo.exports=yp});var Fo=p((hf,$o)=>{"use strict";var Cp=fr(),gp=vr(),jo=Cp("keys");$o.exports=function(r){return jo[r]||(jo[r]=gp(r))}});var Bo=p((df,_o)=>{"use strict";var Ep=_();_o.exports=!Ep(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var Ho=p((mf,Do)=>{"use strict";var Ip=me(),xp=B(),Tp=Pe(),Sp=Fo(),wp=Bo(),qo=Sp("IE_PROTO"),jr=Object,Ap=jr.prototype;Do.exports=wp?jr.getPrototypeOf:function(r){var e=Tp(r);if(Ip(e,qo))return e[qo];var t=e.constructor;return xp(t)&&e instanceof t?t.prototype:e instanceof jr?Ap:null}});var Go=p((ff,Uo)=>{"use strict";Uo.exports={}});var Ko=p((vf,Wo)=>{"use strict";var Rp=H(),$r=me(),kp=Oe(),Op=Mr().indexOf,Pp=Go(),zo=Rp([].push);Wo.exports=function(r,e){var t=kp(r),n=0,i=[],o;for(o in t)!$r(Pp,o)&&$r(t,o)&&zo(i,o);for(;e.length>n;)$r(t,o=e[n++])&&(~Op(i,o)||zo(i,o));return i}});var Xo=p((yf,Qo)=>{"use strict";Qo.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var Zo=p((bf,Yo)=>{"use strict";var Vp=Ko(),Mp=Xo();Yo.exports=Object.keys||function(e){return Vp(e,Mp)}});var is=p((Cf,ns)=>{"use strict";var es=ie(),Np=_(),ts=H(),Lp=Ho(),jp=Zo(),$p=Oe(),Fp=er().f,rs=ts(Fp),_p=ts([].push),Bp=es&&Np(function(){var r=Object.create(null);return r[2]=2,!rs(r,2)}),Jo=function(r){return function(e){for(var t=$p(e),n=jp(t),i=Bp&&Lp(t)===null,o=n.length,l=0,s=[],a;o>l;)a=n[l++],(!es||(i?a in t:rs(t,a)))&&_p(s,r?[a,t[a]]:t[a]);return s}};ns.exports={entries:Jo(!0),values:Jo(!1)}});var os=p(()=>{"use strict";var qp=Le(),Dp=is().values;qp({target:"Object",stat:!0},{values:function(e){return Dp(e)}})});var as=p((If,ss)=>{"use strict";os();var Hp=ft();ss.exports=Hp.Object.values});var cs=p((xf,ls)=>{"use strict";var Up=as();ls.exports=Up});var Vt=p((Tf,ps)=>{"use strict";var Gp=cs();ps.exports=Gp});var Dr=p((Gf,Cs)=>{"use strict";var Wp=ke();Cs.exports=Array.isArray||function(e){return Wp(e)==="Array"}});var Es=p((zf,gs)=>{"use strict";var Kp=TypeError,Qp=9007199254740991;gs.exports=function(r){if(r>Qp)throw Kp("Maximum allowed index exceeded");return r}});var Ts=p((Wf,xs)=>{"use strict";var Xp=Dr(),Yp=$e(),Zp=Es(),Jp=Er(),Is=function(r,e,t,n,i,o,l,s){for(var a=i,c=0,d=l?Jp(l,s):!1,f,v;c<n;)c in t&&(f=d?d(t[c],c,e):t[c],o>0&&Xp(f)?(v=Yp(f),a=Is(r,e,f,v,a,o-1)-1):(Zp(a+1),r[a]=f),a++),c++;return a};xs.exports=Is});var As=p((Kf,ws)=>{"use strict";var eu=Ve(),tu=eu("toStringTag"),Ss={};Ss[tu]="z";ws.exports=String(Ss)==="[object z]"});var ks=p((Qf,Rs)=>{"use strict";var ru=As(),nu=B(),Nt=ke(),iu=Ve(),ou=iu("toStringTag"),su=Object,au=Nt(function(){return arguments}())==="Arguments",lu=function(r,e){try{return r[e]}catch{}};Rs.exports=ru?Nt:function(r){var e,t,n;return r===void 0?"Undefined":r===null?"Null":typeof(t=lu(e=su(r),ou))=="string"?t:au?Nt(e):(n=Nt(e))==="Object"&&nu(e.callee)?"Arguments":n}});var Ps=p((Xf,Os)=>{"use strict";var cu=H(),pu=B(),Hr=bt(),uu=cu(Function.toString);pu(Hr.inspectSource)||(Hr.inspectSource=function(r){return uu(r)});Os.exports=Hr.inspectSource});var $s=p((Yf,js)=>{"use strict";var hu=H(),du=_(),Vs=B(),mu=ks(),fu=vt(),vu=Ps(),Ms=function(){},Ns=fu("Reflect","construct"),Ur=/^\s*(?:class|function)\b/,yu=hu(Ur.exec),bu=!Ur.test(Ms),Qe=function(e){if(!Vs(e))return!1;try{return Ns(Ms,[],e),!0}catch{return!1}},Ls=function(e){if(!Vs(e))return!1;switch(mu(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return bu||!!yu(Ur,vu(e))}catch{return!0}};Ls.sham=!0;js.exports=!Ns||du(function(){var r;return Qe(Qe.call)||!Qe(Object)||!Qe(function(){r=!0})||r})?Ls:Qe});var qs=p((Zf,Bs)=>{"use strict";var Fs=Dr(),Cu=$s(),gu=de(),Eu=Ve(),Iu=Eu("species"),_s=Array;Bs.exports=function(r){var e;return Fs(r)&&(e=r.constructor,Cu(e)&&(e===_s||Fs(e.prototype))?e=void 0:gu(e)&&(e=e[Iu],e===null&&(e=void 0))),e===void 0?_s:e}});var Hs=p((Jf,Ds)=>{"use strict";var xu=qs();Ds.exports=function(r,e){return new(xu(r))(e===0?0:e)}});var Us=p(()=>{"use strict";var Tu=Le(),Su=Ts(),wu=Pe(),Au=$e(),Ru=je(),ku=Hs();Tu({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=wu(this),n=Au(t),i=ku(t,0);return i.length=Su(i,t,t,n,0,e===void 0?1:Ru(e)),i}})});var Gs=p(()=>{"use strict";var Ou=gt();Ou("flat")});var Ws=p((iv,zs)=>{"use strict";Us();Gs();var Pu=Et();zs.exports=Pu("Array","flat")});var Qs=p((ov,Ks)=>{"use strict";var Vu=Ws();Ks.exports=Vu});var Ys=p((sv,Xs)=>{"use strict";var Mu=Qs();Xs.exports=Mu});var Hu={};ka(Hu,{ContainerTypes:()=>b.ContainerTypes,ControlTypes:()=>b.ControlTypes,CustomError:()=>O,EVENT_NAMES:()=>S,EventActionTypes:()=>b.EventActionTypes,EventTypes:()=>b.EventTypes,Interactives:()=>Ye,ManifestController:()=>ae,SDKInfo:()=>Du,chapterIdsToVKVideoIds:()=>jt,compareVersions:()=>Rt,containerTypes:()=>Qc,controlTypes:()=>Xc,eventActionTypes:()=>Rr,eventTypes:()=>Yc,getChapterIdByVkVideoId:()=>fa,getVKVideoIdByMedia:()=>Wr,getVideoRawIdByMedia:()=>da,graphEventTypes:()=>ge,hasEndTemplate:()=>ze,interactivesEventTypes:()=>P,isAreaControl:()=>Kc,isButtonControl:()=>Wc,isLastChapter:()=>G,isOneTextCtrlContainer:()=>se,isSupportedManifest:()=>b.isSupportedManifest,isTextControl:()=>qe,isVKVariantItem:()=>ma,isValidManifest:()=>Ar,migrateManifestToLatestVersion:()=>b.migrateManifestToLatestVersion,utils:()=>Ia,vkVideoIdsToChapterIds:()=>Kr});module.exports=Oa(Hu);var Jr="1.0.37-dev.6c00e4da.0";var ut=require("@vkontakte/videoplayer-shared");var Bt=class{constructor(e){this.layout=e}},et=class extends Bt{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 en(r){return"features"in r}var pe=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&en(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(){return this.container.controls?.reduce((e,t)=>{let n=t.type.trim().toLowerCase(),i=this.factories.get(n);if(i){let o=i(t,this.options);if(o)return[...e,o]}return[...e]},[])||[]}};var re=require("@vkontakte/videoplayer-shared");function Ie(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 tn="interactive",V={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderWidthRawValue:"1px",roundCornersRawValue:"0",borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0,shadowColorLight:"#fff",shadowColorDark:"#000",shadowColorAlpha:.24},rn=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(rn||{}),nn=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(nn||{}),on=(n=>(n.start="left",n.end="right",n.center="center",n))(on||{}),tt=({target:r,props:e})=>{r.style.alignItems=(e?.gravityVertical&&rn[e.gravityVertical])??"center",r.style.justifyContent=(e?.gravityHorizontal&&nn[e.gravityHorizontal])??"center",r.style.textAlign=(e?.alignment&&on[e.alignment])??"center"},rt=({target:r,props:e,fallback:t,dependsOn:n})=>{r.style.color=e?.text?.color??t.textColor,r.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,r.textContent=e?.text?.value??t.textContent},nt=({target:r,props:e,fallback:t})=>{r.style.backgroundColor=Ie(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},xe=({target:r,props:e,fallback:t,dependsOn:n,useRawValues:i=!1})=>{let o=i?t.borderWidthRawValue:`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth})`,l=i?t.roundCornersRawValue:`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Ie(i?t.borderColor:e?.shape?.border?.color??t.borderColor,i?t.borderAlpha:e?.shape?.border?.alpha??t.borderAlpha),r.style.borderRadius=l},sn=({target:r,isDark:e,baseDimension:t,fallback:n})=>{let l=Ie(n.shadowColorLight,n.shadowColorAlpha),s=Ie(n.shadowColorDark,n.shadowColorAlpha),a=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,d=`0px 0px ${a} ${c} ${e?s:l}`;r.style.boxShadow=d},ue=({target:r,layoutParams:e,fallback:t})=>{let n=e.angle??t.angle;n=n&&n*-1,r.style.transform=`rotate(${n}rad)`};var he=require("@vkontakte/videoplayer-shared");var qt="int",ee=(n=>(n.AREA=`${qt}_area`,n.TEXT=`${qt}_text`,n.BUTTON=`${qt}_bttn`,n))(ee||{});function an(r){return"features"in r}var W="interactive-control",R={common:W,selected:`${W}-selected`,wrapper:`${W}-wrapper`,disabled:`${W}-disabled`,button:`${W}-button`,area:`${W}-area`,text:`${W}-text`,blinkAnim:`${W}-blink-anim`,blinkAnimButton:`${W}-blink-anim-button`,blinkAnimArea:`${W}-blink-anim-area`};var O=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Q=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new he.Subscription;this.error$=new he.Subject}createContainerElement(e){let t=document.createElement("div");t.classList.add(R.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??V.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&&an(this.options)&&this.options.features[e]}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":{if(!this.container)break;this.subscriptions.add((0,he.fromEvent)(this.container.element,"click").subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),i=>{let o=new O(1,1,{message:"Error happened on control interaction",error:i});this.error$.next(o)}));break}default:break}})}removeListeners(){this.subscriptions.unsubscribe()}};var X=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Y=r=>X(r,"Object"),it=r=>X(r,"String"),ot=r=>X(r,"Array"),st=r=>X(r,"Number"),ln=r=>X(r,"Function"),cn=r=>X(r,"Boolean"),Dt=r=>st(r)&&!isNaN(r);var te=r=>Y(r)&&Object.keys(r).length===0,Ht=r=>ot(r)&&!r.length;var we=(r,e)=>it(r)&&(e?r.trim():r).length;var Ut="interactive-blink-anim-reference",L={common:Ut,animation:`${Ut}-animation`,disabled:`${Ut}-disabled`},at=class{constructor(){this._RAFId=0;this._element=void 0}get element(){return this._element}create(){if(this._element)return;let e=document.createElement("div");e.classList.add(L.common,L.animation),this._element=e}restart(){this._element&&(this._element.classList.add(L.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(L.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var Gt="interactive-container",j={common:Gt,hidden:`${Gt}-hidden`,disabled:`${Gt}-disabled`};var lt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new zt(r,e)},zt=class extends Q{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(R.common,R.area),n.setAttribute("data-testid",ee.AREA),nt({target:n,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),ue({target:n,layoutParams:this.control.layoutParams,fallback:V}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.updateShadowStyles(),this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add((0,re.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(j.disabled))return;let t=e.parentElement;if(t){let n=t.querySelector(`.${L.common}`);n&&this.syncBlinkAnimation(n)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add((0,re.fromEvent)(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(j.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add((0,re.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(R.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(R.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(cn(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";sn({target:this.controlElement,props:this.control.props,fallback:V,isDark:e,baseDimension:t}),xe({target:this.controlElement,props:this.control.props,fallback:{...V,borderColor:e?V.shadowColorDark:V.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??V.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else xe({target:this.controlElement,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(R.blinkAnim,e),this.controlElement?.classList.toggle(R.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${R.blinkAnimArea}`)||this.controlElement.classList.contains(R.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add((0,re.fromEvent)(e,"animationiteration").pipe((0,re.once)()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${R.blinkAnimArea}`)||this.controlElement.classList.contains(R.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-area-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}onError(e="",t){let n=new O(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(n)}onProgress(){}onResize(){}};var ne=require("@vkontakte/videoplayer-shared");var ct=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 pt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Wt(r,e)},Wt=class extends Q{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(R.common,R.button),n.setAttribute("data-testid",ee.BUTTON),ue({target:n,layoutParams:this.control.layoutParams,fallback:V}),nt({target:n,props:this.control.props,fallback:V}),xe({target:n,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=ct(this.control.type.trim().toLowerCase()),o=i.firstElementChild??i;rt({target:o,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add((0,ne.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(j.disabled))return;let t=e.parentElement;if(t){let n=t.querySelector(`.${L.common}`);n&&this.syncBlinkAnimation(n)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add((0,ne.fromEvent)(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(j.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add((0,ne.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(R.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(R.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(R.blinkAnim,e),this.controlElement?.classList.toggle(R.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${R.blinkAnimButton}`)||this.controlElement.classList.contains(R.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add((0,ne.fromEvent)(e,"animationiteration").pipe((0,ne.once)()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${R.blinkAnimButton}`)||this.controlElement.classList.contains(R.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-button-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}onError(e="",t){let n=new O(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(n)}onProgress(){}onResize(){}updateShadowStyles(){}};var pn=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Kt(r,e)},Kt=class extends Q{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(R.common,R.text),n.setAttribute("data-testid",ee.TEXT),ue({target:n,layoutParams:this.control.layoutParams,fallback:V}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=ct(this.control.type.trim().toLowerCase()),o=i.firstElementChild??i;rt({target:o,props:this.control.props,fallback:V,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(){}updateShadowStyles(){}toggleBlinkAnimation(){}onError(){}};var ht=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new Qt(r,e,t)},Qt=class extends pe{constructor(t,n,i){super(t,i);this.containerElement=null;this.controlSubscriptions=new ut.Subscription;this.error$=new ut.Subject;this.rootElement=n,this.layout=new et(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pt),this.addControlFactory("text",pn),this.addControlFactory("area",lt)}createView({eventCallback:t}){let n=document.createElement("div");return n.classList.add(j.common,j.disabled),requestAnimationFrame(()=>{n.classList.remove(j.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout}}),i.setEvents(t),this.controlSubscriptions.add(i.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.containerElement=n,n}hide(){let t=this.getElement();t&&t.classList.add(j.hidden)}show(){let t=this.getElement();t&&t.classList.remove(j.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(j.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(j.disabled),this.controls.forEach(n=>n.disable()),this.isDisabled=!0)}removeView(){let t=this.getElement();t&&(this.controlSubscriptions.unsubscribe(),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()})}updateControlsShadowStyles(t){this.controls.forEach(n=>n.updateShadowStyles(t))}toggleBlinkAnimation(t){this.controls.forEach(n=>n.toggleBlinkAnimation(t))}};var ga=D(wr(),1),g=require("@vkontakte/videoplayer-shared"),Ee=require("@vkontakte/videoplayer-statistics");var yo=require("@vkontakte/videoplayer-shared");function Fe(r,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>r(...n),e)}}var mo="video_interactive",fo="videoint";var vo=250,_e=class{constructor(e){this.handleZoomChange=Fe(e=>{this.lastZoomInfo=e},vo);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Chapter id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!st(e.graph.edit.chapters[0].x)){this.onError?.("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:o=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(o),this.onOpenPreviewClick=t,this.onError=n,this.lang=i??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=zc(e),this.resizeObserver=new ResizeObserver(Fe(this.onResize,vo)),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){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await(0,yo.loadVKLangPack)(this.lang,mo,fo)}catch{this.onError?.("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"view",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:n,...i})=>{n==="openPreview"&&"chapterId"in i&&this.onOpenPreviewClick?.(i.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function zc(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 Be=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 o of this._containers){let l=o.startTime-e;if(l<=i&&(o.endTime&&i<=o.endTime||o.endTime===null)){n=!0;break}i<l&&(t=t===-1?l:Math.min(t,l))}return!n&&t!==-1?t:null}}};var b=require("@interactiveplatform/movika-manifest");var bo={metadata:"Object",chapters:"Array"},Ar=r=>{if(!Y(r))return!1;for(let e in bo)if(!r[e]||!X(r[e],bo[e]))return!1;return(0,b.isSupportedManifest)(r.metadata.version)},qe=r=>r.type===b.ControlTypes.Text,Wc=r=>r.type===b.ControlTypes.Button,Kc=r=>r.type===b.ControlTypes.Area,Qc={Choice:"Choice",TextInput:"TextInput"},Xc={Button:"Button",Area:"Area",Text:"Text"},Yc={onClick:"onClick",onSuspense:"onSuspense"},Rr={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var It=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 xt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{ln(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=[]}};var Lo=require("@vkontakte/videoplayer-shared");var Tt=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return Zc(...this.loaders[e])(t)}};function Zc(...r){return async function(t){let n=[...r];for(;n.length>0;)t=await n.shift()(t);return t}}function De(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function St({actions:r,errors:e,chapterId:t,...n}){if(t){let i=r.getManifest();if(i){let o=r.getChapter(i.chapters,t);if(o){let l=r.getMedia(i.media,o.videoId),s=r.getGraph(i.graph,o.id);return l?{...n,actions:r,errors:e,result:{chapter:o,media:l,graph:s}}:{...n,errors:De(e,St.name,"Could not find media"),actions:r}}}}return{...n,errors:De(e,St.name,"Could not find chapter"),actions:r}}var wt=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,o=n.length;i<o;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,o=n.length;i<o;i++){let l=n[i];try{l.callback.call(this,e)}catch(s){Promise.resolve().then(()=>{throw s})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},be=class extends wt{constructor(){super(),this.listeners||wt.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)}},He=class{constructor(){Object.defineProperty(this,"signal",{value:new be,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?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>"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(He.prototype[Symbol.toStringTag]="AbortController",be.prototype[Symbol.toStringTag]="AbortSignal");function At(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 kr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=r;if(!At({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:o};let o=t;(o&&!o.prototype.hasOwnProperty("signal")||i)&&(o=function(c,d){let f;d&&d.signal&&(f=d.signal,delete d.signal);let v=new t(c,d);return f&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),v},o.prototype=t.prototype);let l=e;return{fetch:(a,c)=>{let d=o&&o.prototype.isPrototypeOf(a)?a.signal:c?c.signal:void 0;if(d){let f;try{f=new DOMException("Aborted","AbortError")}catch{f=new Error("Aborted"),f.name="AbortError"}if(d.aborted)return Promise.reject(f);let v=new Promise((y,k)=>{d.addEventListener("abort",()=>k(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([v,l(a,c)])}return l(a,c)},Request:o}}var Jc=()=>"fetch"in window,Ue=Jc()&&At({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Co=Ue?kr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Or=Ue?Co.fetch:window.fetch,_m=Ue?Co.Request:window.Request,Bm=Ue?He:window.AbortController,qm=Ue?be:window.AbortSignal;var Rt=(r="",e="")=>{let t=r.split("."),n=e.split("."),i=0;for(let o=0;o<Math.max(t.length,n.length)&&!i;o++)t[o]>n[o]?i=1:t[o]<n[o]?i=-1:i=0;return i};var ep=async r=>{try{let e={},t;if(it(r)){t=new URL(r).href;let i=await Or(t);if(!i.ok)return{};e=await i.json()}else if(Y(r))e=r;else return{};if(!Ar(e))return{};let n=e.metadata.media;if(it(n)&&!("media"in e))try{let i;t?i=new URL(n,t).href:(i=new URL(n).href,t=i);let o=await Or(i);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch{return np(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function go(r){let{manifest:e,manifestURL:t}=await ep(r);if(!e)throw new Error("Failed on fetch");let n=(0,b.migrateManifestToLatestVersion)(e);return n.media=tp(n.media,t),delete n.metadata.media,n}function kt(r,e){if(e)return r.find(t=>t.id===e)}function Pr(r,e){return r.edit?.chapters?r.edit.chapters.find(t=>t.id===e):r.view?.chapters?r.view.chapters.find(t=>t.id===e):void 0}function Vr(r,e){return r.videos.find(t=>t.id===e)}function tp(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(n=>{let i="url"in n?n.url:"",o=rp(i,e);return{...n,url:o||i}})}))}}function rp(r="",e){try{return new URL(r,e).href}catch{return""}}function np(r){return Rt(r,"3.2.0")>=0}var Po=D(Ge(),1);var Ot=r=>ot(r)&&!Ht(r),G=r=>r.order==="end",ze=r=>ot(r.containers)&&!Ht(r.containers)&&G(r),Vo=(r,e)=>{let t=r*1e3;return Ot(e.controls)&&t<(e.startTime??0)},Nr=(r,e)=>{let t=r*1e3;return Ot(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var oe=(r=[])=>r.some(e=>e.action.type==="expect"),Lr=(r=[])=>r.find(e=>e.action.type==="expect"),bp=r=>r?.length===1,se=r=>bp(r)&&qe(r[0]);function Mo(r=[],e=1/0,t=[]){return r.filter(({container:n})=>!(0,Po.default)(t,n.container.id)&&oe(n.container.events)&&n.container.endTime===e&&!n.isRemoved)}function Pt({gameControllers:r=[],subjectName:e,subjectId:t,execFn:n}){for(let i of r)if(e==="container"&&i.container.container.id===t){n(i),Mo(r,i.container.container.endTime,[i.container.container.id]).forEach(l=>{n(l)});break}}var No=(r,e)=>{let t=w=>e.find(({container:u})=>u.container.id===w)?.container.isRemoved,n=oe(r.events)&&!t(r.id),i=(w,C=!1,u=!1)=>{let h=u?"every":"some";return w.controls[h](m=>{let I=C?w.endTime===r.endTime:!0;return m.events?.[h](E=>E.action?.type===Rr.openURI)&&I})},o=w=>w.some(({container:C})=>i(C.container,!0,!1)&&!C.isRemoved),l=w=>w.every(({container:C})=>C.isRemoved?!0:i(C.container,!0,!0)),s=Mo(e,r.endTime,[r.id]).length,a=w=>w.controls.some(C=>C.events?.some(u=>u.action?.args?.shouldOpenNow)),c=n||s>0,d=o(e),f=i(r),v=l(e),y=n?!1:s>0,k=a(r);return{isExpectTime:c,hasOtherExpect:s>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:f,isAllOpenURIEventsValid:v,isExpectEventForCurrentContainer:y,hasShouldOpenNowEvent:k}};var ae=class extends Tt{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Lo.ValueSubject(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){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:De},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await go(n.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",St({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Pr,getChapter:kt,getMedia:Vr,getByBranches:this.getByBranches.bind(this),addErrorMessage:De},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),n.result&&(this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let n=kt(this.manifest.chapters,t);if(n){let i=Vr(this.manifest.media,n.videoId),o=Pr(this.manifest.graph,n.id);if(i)return{chapter:n,media:i,graph:o}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=kt(this.manifest?.chapters||[],t);return this.getByBranches(n?.branches)}}getByBranches(t=[]){return t.reduce((n,i)=>{let o=this.getByChapterId(i.chapterId);return o&&n.push(o),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?G(this.chapter):!1}};var ds=D(Vt(),1),ms=require("@vkontakte/videoplayer-core"),Z=require("@vkontakte/videoplayer-shared");var us=r=>{let e=r.variants.find(t=>t.payload?.type==="vk");if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};var hs=D(Vt(),1);function Fr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:l=Math.random().toString(),...s}){let a=r.get(o),c={...s};return a?a[l]=c:r.set(o,{[l]:c}),{listId:o,itemId:l,...s}}function t(o){o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),o.statistics?.oneStat.destroy(),o.statistics?.statSubscription.unsubscribe()}function n(o,l){let s=r.get(o);if(!s)throw Error("Can't remove. Not find.");if(l){let a=s[l];a&&t(a),delete s[l],Object.keys(s).length||r.delete(o)}else{for(let a of(0,hs.default)(s))t(a);r.delete(o)}}function i(){for(let o of r)n(o[0])}return{createPlayer:e,removePlayer:n,map:r,removeAll:i}}var Ce=D(Ge(),1);function _r(r,e=[]){let t={},n,i=!e.length;for(let o of r.variants)if(!n&&"cover"in o&&(n=o.cover),"url"in o)switch(o.type.toLowerCase()){case"mp4":(i||(0,Ce.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"mpeg":(i||(0,Ce.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"hls":(i||(0,Ce.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:o.url}});break;case"dash":(i||(0,Ce.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:o.url}});break;default:break}return{sources:t,thumbUrl:n,title:r.title??""}}var We=(r,e)=>{let t=r.info.currentQuality$.getValue(),n=r.info.availableQualities$.getValue();t!==e&&(0,Ce.default)(n,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var zp=2;function Br(r){let e=Fr(),t=new Z.Subscription,n={},i=null,o=!1,l,s=new Z.ValueSubject(null);r&&a(r);function a(C){i=C}function c(C,u,h){if(!i)throw Error("need to set interactive controller");if(!i.options)return;let I=(e.map.get(C)??{})[u];if(I){n={chapterId:h,listId:C,itemId:u,...I};let E=n.player;n.subscription.add(E.info.currentQuality$.subscribe(x=>{let A=E.info.position$.getValue(),$=E.info.isAutoQualityEnabled$.getValue();if(!(!x||!A||$))for(let T of e.map)(0,ds.default)(T[1]).forEach(({player:M})=>{We(M,x)})})).add(E.events.started$.subscribe(()=>{d(u)})),I.container.remove(),i.setPlayer(I.player),o||(i.init(),o=!0),s.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function d(C){if(!i)throw Error("need to set interactive controller");if(te(n)||C!==n.itemId)return;let u=i.getChapterBranches(),h=new Set;for(let m of u)h.has(m.media.id)||(await v({media:m.media,chapterId:m.chapter.id,setAsActive:!1,title:m.chapter.label}),h.add(m.media.id))}async function f({chapter:{id:C},manifestVideo:u}){if(te(n)||!i)return;let h=n.player.info.muted$.getValue(),m=n.player.info.currentQuality$.getValue(),I=n.player.info.isAutoQualityEnabled$.getValue(),E=n.player.info.volume$.getValue(),x=n.player.info.currentPlaybackRate$.getValue(),A=!I,$=!1;for(let T of e.map)if(T[0]===u.id&&!i.state.isReplay$.getValue()){let M=Object.keys(T[1]);for(let N of M)N===n.itemId?(M.length<zp||($=!0),e.removePlayer(T[0],N)):($=!0,c(T[0],N,C),A?We(n.player,m):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h),n.player.setPlaybackRate(x))}else e.removePlayer(T[0]);$||(await v({media:u,chapterId:C,setAsActive:!0,playbackRate:x}),A?We(n.player,m):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h))}async function v({media:C,chapterId:u,prefetch:h=!0,setAsActive:m=!0,autoplay:I=!1,preferredExt:E,title:x,playbackRate:A}){let $=Math.random().toString(),T=document.createElement("div");l.append(T);let M;if(i?.options?.vkVideoLoader){let Ze=us(C);Ze.length&&(M=await i.options.vkVideoLoader(...Ze))}let N=i?.options?.coreConfig||void 0,z={...N,configName:[...N?.configName??[],"interactive"]},J={container:T,...M?.videos?.[0]||{sources:_r(C,E).sources},title:x,failoverHosts:M?.failoverHosts||[]},F=new ms.Player(z,Z.Tracer.createRootTracer());F.initVideo(J);let le=null;if(M?.videos&&i?.options.createOneStat){let Ze=M.videos[0],_t=i.options.createOneStat(Ze),Yr=new Z.Subscription;_t&&(Yr.add(_t.attachTo(F)),le={oneStat:_t,statSubscription:Yr})}let Xr=new Z.Subscription,xa=n?.player?.info.isAutoQualityEnabled$.getValue();Xr.add(F.events.canplay$.subscribe(function(){xa||We(F,n.player.info.currentQuality$.getValue()),A&&F.setPlaybackRate(A)}));let ce=e.createPlayer({listId:C.id,itemId:$,player:F,container:T,sources:_r(C,E).sources,config:J,subscription:Xr,statistics:le});return m&&c(C.id,ce.itemId,u),I&&ce.player.play(),h&&!I&&ce.player.prepare(),{player:ce.player,config:ce.config,statistics:ce.statistics}}function y(){k(),i=null,l.remove()}function k(){t.unsubscribe(),e.removeAll(),n={},o=!1}async function w(){if(!i)throw Error("need to set interactive controller");k(),l=document.createElement("div");let{media:C,chapter:u}=i.getCurrentChapter();C&&u?(t.add(i.events.chapterChanged$.subscribe(f)),await v({media:C,chapterId:u.id,title:u.label})):console.error("not found")}return{...e,init:w,setInteractiveController:a,createPlayer:v,removeAll:y,getActivePlayer:function(){return n},activePlayerChanged:s}}var S={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ge={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},P={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var vs=D(Ge(),1),ys=require("@vkontakte/videoplayer-shared");function qr(r){return function(...t){return r(...t.reverse())}}function Ke(r,...e){return(...t)=>Y(e[0])&&Y(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var Mt=class{constructor({player:e,container:t,branches:n,selectBranches:i,interactiveEvents:o,globalEvents:l,globalEventEmitter:s,getContainerEventState:a,permanentTextControls:c,interactiveTimeOpenUri:d,disabledControls$:f,onRemove:v,onError:y}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(oe(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&t)return;this.emitContainerVisibilityEvent(!0,!1)}else{let t={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(i,o)=>{let{isExpectTime:l,hasOtherExpect:s,hasOpenURIEvent:a,hasOpenURIEventInCurrentContainer:c,isAllOpenURIEventsValid:d,hasShouldOpenNowEvent:f}=this.getContainerEventState(),v=this.interactiveTimeOpenUri&&!c,y=this.interactiveTimeOpenUri&&c;if((!this.interactiveTimeOpenUri||v)&&(this.isSelectedControlEvent=!0),i!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||v)){if(this.interactiveTimeOpenUri){let k=!s&&!d&&c;k&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:k})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&a&&this.gameState!==5){if(y){let w=((C,u,h,m)=>!C&&!u&&h||C&&!u&&h&&!m||C&&!u&&h&&m)(l,s,d,this.isSelectedContainerEvent);this.fakeRemoveView(w)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!l||!s||!f)&&(this.selectBranches.stopExpect(),o())}},isEOV:()=>this.gameState===4},n=Ke(this.selectBranches.onControlEvent,t);this.container.createView({eventCallback:n}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,vs.default)(i,this.gameState)&&!this.isPermanentText)return;let o=this.player.getExactTime();if(Vo(o,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Nr(o,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let c=this.gameState;this.gameState=3,c===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:c}=this.getContainerEventState(),d=this.selectBranches.state.isExpect,f=this.interactiveTimeOpenUri&&c;if(f&&!d){let v=this.container.getElement();v&&(v.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!f&&this.removeView()}let l=Nr(o,this.container.container),s=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:s,currentTime:o,isInteractiveTime:l};this.container.onProgress(o*1e3,l),this.globalEventEmitter.emit(S.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=n,this.selectBranches=i,this.subscription=new ys.Subscription,this.player=e,this.interactiveEvents=o,this.getContainerEventState=a,this.isPermanentText=c&&se(t.container.controls),this.interactiveTimeOpenUri=d,this.disabledControls$=f,this.onRemove=v,this.globalEventEmitter=s,this.gameState=0,this.globalEvents=l,this.onError=y,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:P.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(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:P.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=>{e?this.container.disable?.():this.container.enable?.()})),this.subscription.add(this.container.error$.subscribe(this.onError))}selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??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(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:oe(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:P.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}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()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var bs=(r=[])=>r.reduce((e,t,n)=>{let i=(t?.controls??[]).filter(o=>!qe(o));if(Ot(i)){let o=[t.startTime??0,t.endTime??1/0],l={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[l],range:o});else{let s=[],a=-1/0,c=1/0,d=[],f=[];for(let v=0;v<e.length;v++){let y=e[v];if(f.push(...y.subjects),y.range[0]<c&&(c=y.range[0]),y.range[1]>a&&(a=y.range[1]),o[0]>=y.range[0]&&o[1]<=y.range[1])return e[v].subjects.push(l),e;o[0]<y.range[0]&&o[1]>y.range[0]&&(s.push(v),d=d.concat(y.subjects)),o[0]>=y.range[0]&&o[0]<=y.range[1]&&(s.push(v),d=d.concat(y.subjects),o[0]=y.range[0]),o[1]>=y.range[0]&&o[1]<=y.range[1]&&(s.push(v),d=d.concat(y.subjects),o[1]=y.range[1])}if(f.push(l),o[0]<=c&&o[1]>=a)return[{subjects:f,range:o}];s.length&&s.reverse().forEach(v=>{e.splice(v,1)}),e.push({subjects:d.concat([l]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var Js=D(Ge(),1),Gr=D(Vt(),1),ea=D(Ys(),1);function Zs(){let r={};function e(){for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&delete r[s]}function t(s){let a={};for(let c in r)+c<=s&&(a[c]=r[c]);return a}function n(s){let a={};for(let c in r)+c>=s&&(a[c]=r[c]);return a}function i({timestamp:s,priority:a,initiator:c}){if(Dt(s)){let d=r[s]??null;if(d&&a&&we(a,!0)){let f={},v=d[a];return v&&(f={...f,...v}),f=te(f)?null:f,f&&we(c,!0)?f[c]??null:f}return d}return null}function o({timestamp:s,priority:a,initiator:c}){if(Dt(s))if(r[s]){if(a&&we(a,!0))if(r[s][a]){if(c&&we(c,!0))if(r[s][a][c]){if(delete r[s][a][c],!te(r[s][a]))return!0}else return!1;if(delete r[s][a],!te(r[s]))return!0}else return!1;return delete r[s]}else return!1;return!1}function l({timestamp:s,priority:a,initiator:c,...d}){r[s]?.[a]?.[c]?r[s][a][c].push({...d}):r[s]?.[a]?r[s][a]={...r[s][a],[c]:[{...d}]}:r[s]?r[s]={...r[s],[a]:{[c]:[{...d}]}}:r[s]={[a]:{[c]:[{...d}]}}}return{map:r,remove:o,add:l,removeAll:e,get:i,getLte:t,getGte:n}}var Nu=[b.EventActionTypes.expect,b.EventActionTypes.setNextBranch],Lu=1/0;function ta(r,e){let t=r,n,i=ju(e),o=Zs(),l,s=()=>{y(),u()},a=h=>{o.add.call(void 0,h),k()},c=(h=[])=>{for(let m of h)if(m.action(),(0,Js.default)(Nu,m.actionType))break},d=(h=1/0)=>{let m=Lt(o.get({timestamp:h,priority:"control"})??{}),I=Lt(o.get({timestamp:h,priority:"container"})??{}),E=Lt(o.get({timestamp:h,priority:"chapter"})??{});return[...m,...I,...E]},f=h=>{i.isReady(h)&&c(d(h))},v=()=>{c([...Lt(o.get({timestamp:1/0,priority:"chapter"})??{})])},y=()=>{n&&(l?.unsubscribe(),n=void 0)},k=()=>{n||(n=()=>setTimeout(()=>{f(1/0)}),l=t.events.ended$.subscribe(n))},w=h=>{y(),t=h},C=h=>{h.priority==="container"&&i.resetCalled(h.timestamp),o.remove(h)},u=()=>{i.release(),o.removeAll()};return{setPlayer:w,add:a,remove:C,exec:f,execEndOfVideo:v,listen:k,unlisten:y,release:s,containersEventsCallState:i,getPreparedToExecActions:d}}function ju(r){let e=new Map;return{setCalled:({timestamp:s,id:a})=>{let c=e.get(s);c&&c[a]!==void 0&&(c[a]=!0)},setData:(s=[])=>{for(let a of s){let c=a.endTime??Lu,d=e.get(c);e.set(c,{...d,[a.id]:!1})}},resetCalled:s=>{let a=e.get(s);if(a)for(let c in a)a[c]=!1},isReady:s=>{let a=e.get(s);if(!a)return!0;let c=(0,Gr.default)(a);return r?c.some(f=>f):!c.some(f=>!f)},release:()=>e.clear()}}function Lt(r){return(0,ea.default)((0,Gr.default)(r)).sort(e=>e.actionType===b.EventActionTypes.expect?-1:1)}var ra={videoContentHeight:0,videoContentWidth:0},na=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return ra;let{clientHeight:n,clientWidth:i}=r.experimental.element$.getValue()||{};if(!(n&&i))return ra;let o=e/t,l=n/i,s,a;return l>o?(a=i,s=i*o):l<o?(a=n/o,s=n):(a=i,s=n),{videoContentWidth:a,videoContentHeight:s}};var $u=250;function ia(r){let e,t=new ResizeObserver(s=>{o(s),e=o.bind(null,s)});function n(s){let{parentElement:a,player:c}=r();if(a&&c){let{videoContentWidth:d,videoContentHeight:f}=na(c);a.style.setProperty("--interactive-content-width",`${d}px`),a.style.setProperty("--interactive-content-height",`${f}px`),a.style.setProperty("--interactive-width",`${s[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${s[0].contentRect.height}px`)}}function i(){let{parentElement:s}=r();s.removeAttribute("style")}let o=Fe(s=>{let{fns:a=[]}=r();n(s);for(let c of a)c()},$u);function l(){e=void 0,t.disconnect(),i()}return{resizeObserver:t,calc:()=>{e?.()},release:l}}var Fu=r=>Math.floor(Math.random()*r),sa=r=>{let e=r.length,t=1/0,n=null;for(;e--;){let i=r[e],o=i.weight??1;o<t&&(t=o,n=i)}return n},aa=r=>{let e=r.length,t=-1/0,n=null;for(;e--;){let i=r[e],o=i.weight??0;o>t&&(t=o,n=i)}return n};var la=r=>{let e=r.length,t=Fu(e);return r[t]},oa=1,ca=r=>{let e=0;for(let n=0;n<r.length;++n)e+=r[n].weight??oa;let t=Math.random()*e;e=0;for(let n=0;n<r.length-1;++n)if(e+=r[n].weight??oa,e>=t)return r[n];return r[r.length-1]};var pa={shouldOpenNow:!0,isDetachContainer:!0},ua="after-expect",zr=(r,e=!1)=>({...r,args:e?{...r.args,...pa}:{...pa,...r.args}}),ha=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:n})=>{let i={isExpect:!1},o=()=>{i.isExpect&&(i.isExpect=!1)},l=({action:u,controlType:h,controlId:m,containerId:I,branches:E=[],onEvent:x,isEOV:A=()=>!1,isDisabled:$=()=>!1})=>{let T=zr(u,A()),M={timestamp:1/0,priority:"control",initiator:m,actionType:T.type},N=$(),z=r.emit.bind(r,S.interactives,{subjectId:m,subjectType:h,subjectName:"control",type:N?P.actionChoiceCanceled:P.actionChoice,actionType:u.type,payload:{invokeImmediately:T.args.shouldOpenNow,containerId:I,...T.args}}),J=()=>{e.interactiveActionChoice$.next({subjectId:m,subjectType:h,subjectName:"control",type:N?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:T.args.shouldOpenNow,containerId:I,...T.args}})};if(N){z(),J();return}switch(T.type.trim().toLowerCase()){case b.EventActionTypes.setNextBranch.trim().toLowerCase():{let F=E.find(le=>le.id===T.args.branchId);if(!F)return;x(T.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),z(),J(),T.args.shouldOpenNow?w({subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{chapterId:F.chapterId,autoSelect:!1}}):n.add({...M,action:w.bind(null,{subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{chapterId:F.chapterId,autoSelect:!1}})});return}case b.EventActionTypes.continuePlayback.trim().toLowerCase():{x(T.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),z(),J(),T.args.shouldOpenNow?k({subjectId:m,subjectName:"control",subjectType:h,action:u}):n.add({...M,action:k.bind(null,{subjectId:m,subjectName:"control",subjectType:h,action:u})});return}case b.EventActionTypes.openURI.trim().toLowerCase():{x(T.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),z(),J(),T.args.shouldOpenNow?C({subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{URI:u.args.uri}}):n.add({...M,action:C.bind(null,{subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{URI:u.args.uri}})});return}default:{let F="Unexpected control event",le=new O(1,1,{message:F});d(le,F);return}}},s=({action:u,container:{id:h,endTime:m},branches:I=[],isEOV:E=!1,autoSelected:x=!1})=>{let A=zr(u,E),$={timestamp:!A.args.shouldOpenNow||E?1/0:m??1/0,priority:"container",initiator:h,actionType:A.type},T=r.emit.bind(r,S.interactives,{subjectId:h,subjectName:"container",type:P.actionChoice,actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}}),M=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"container",type:"action-choice",actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}})};switch(A.type.trim().toLowerCase()){case b.EventActionTypes.setNextBranch.trim().toLowerCase():{let N=I.find(z=>z.id===A.args.branchId);if(!N)return;T(),M(),n.add({...$,action:w.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{chapterId:N.chapterId,autoSelect:x}})});return}case b.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():return;case b.EventActionTypes.setMinWeightBranch.trim().toLowerCase():return;case b.EventActionTypes.setRandomBranch.trim().toLowerCase():return;case b.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():return;case b.EventActionTypes.continuePlayback.trim().toLowerCase():{T(),M(),n.add({...$,action:k.bind(null,{subjectId:h,subjectName:"container",action:A})});return}case b.EventActionTypes.openURI.trim().toLowerCase():{T(),M(),n.add({...$,action:C.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{URI:u.args.uri}})});return}default:{let N="Unexpected container event",z=new O(1,1,{message:N});d(z,N);return}}};function a({container:u,branches:h,isEOV:m=!1}){let I=Lr(u.events);if(I){let E=zr(I.action,m);r.emit(S.interactives,{subjectId:u.id,subjectName:"container",type:P.actionChoice,actionType:E.type,payload:{invokeImmediately:E.args.shouldOpenNow,...E.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:E.type,payload:{invokeImmediately:E.args.shouldOpenNow,...E.args}}),n.add({timestamp:m?1/0:u.endTime??1/0,priority:"container",initiator:u.id,actionType:b.EventActionTypes.expect,action:v.bind(null,{subjectId:u.id,subjectName:"container"})}),i.isExpect=!0}else for(let E of u.events??[])s({action:E.action,container:u,branches:h,isEOV:m})}let c=({chapterId:u,action:h,branches:m=[]})=>{let I=r.emit.bind(r,S.interactives,{subjectId:u,subjectName:"chapter",type:P.actionChoice,actionType:h.type,payload:h.args}),E=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:h.type,payload:h.args})};switch(h.type.trim().toLowerCase()){case b.EventActionTypes.setNextBranch.trim().toLowerCase():{let x=m.find(A=>A.id===h.args.branchId);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():{let x=la(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setRandomBranch.trim().toLowerCase():{let x=ca(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():{let x=aa(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setMinWeightBranch.trim().toLowerCase():{let x=sa(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.continuePlayback.trim().toLowerCase():return I(),E(),k.bind(null,{subjectId:u,subjectName:"chapter",action:h});case b.EventActionTypes.openURI.trim().toLowerCase():return I(),E(),C.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:{let x="Unexpected chapter event",A=new O(1,1,{message:x});d(A,x);return}}};function d(u,h){console.error(h),e.error$.next(u),r.emit(S.errors,u)}function f(u){let h=Lr(u.events);if(h){if(G(u))return;r.emit(S.interactives,{subjectId:u.id,subjectName:"chapter",type:P.actionChoice,actionType:h.action.type,payload:h.action.args}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"chapter",type:"action-choice",actionType:h.action.type,payload:h.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:b.EventActionTypes.expect,action:v.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else u.events?.forEach(m=>{let I=c({chapterId:u.id,action:m.action,branches:u.branches});I&&n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:m.action.type,action:I})})}let v=({subjectId:u,subjectName:h})=>{t.pause(),r.emit(S.interactives,{subjectId:u,subjectName:h,type:P.actionExecution,actionType:b.EventActionTypes.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:b.EventActionTypes.expect})},y=({subjectId:u,subjectName:h})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),r.emit(S.interactives,{subjectId:u,subjectName:h,type:P.actionExecution,actionType:ua}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:ua})},k=({subjectId:u,subjectName:h,subjectType:m,action:I})=>{r.emit(S.interactives,{subjectId:u,subjectName:h,subjectType:m,type:P.actionExecution,actionType:I.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:m,type:"action-execution",actionType:I.type})},w=({subjectId:u,subjectName:h,subjectType:m,action:I,payload:E})=>{E.behaviour="change-chapter",r.emit(S.interactives,{subjectId:u,subjectName:h,subjectType:m,type:P.actionExecution,actionType:I.type,payload:E}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:m,type:"action-execution",actionType:I.type,payload:E})},C=({subjectId:u,subjectName:h,subjectType:m,action:I,payload:E})=>{if(!E.URI)return;let x=window.open(E.URI,"_blank","noopener,noreferrer");x&&(x.opener=null),r.emit(S.interactives,{subjectId:u,subjectName:h,subjectType:m,type:P.actionExecution,actionType:I.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:m,type:"action-execution",actionType:I.type})};return{onControlEvent:l,onContainerEvent:s,onChapterEvent:c,onExpectEvent:v,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:a,stopExpect:o,state:i}};var Qr=D(wr(),1),q=require("@vkontakte/videoplayer-shared");var jt=(r,e)=>{let t={};return r.map(n=>{if(!t[n]){let i=e.chapters.find(l=>l.id===n);if(!i)return null;let o=e.media.videos.find(l=>i.videoId===l.id);if(!o)return null;t[n]=Wr(o)}return t[n]}).filter(Boolean)},da=r=>{for(let e of r.variants)if(ma(e)&&e.payload)return e.payload.id},ma=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Wr=r=>{let e=da(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},fa=(r,e)=>{for(let t of r.media.videos)if(e===Wr(t)){for(let n of r.chapters)if(n.videoId===t.id)return n.id;return}},Kr=(r,e)=>r.reduce((t,n)=>{let i=fa(e,n);return i?[...t,i]:t},[]);var Xe=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:i,settings:o}){this.state={history$:new q.ValueSubject([]),hasPrevChapter$:new q.ValueSubject(!1),prevChapter$:new q.ValueSubject(null),isInitialChapter$:new q.ValueSubject(!1),isGoBackLimited$:new q.ValueSubject(!1)};this.#r=null;this.#s=!1;this.#e=null;this.#p=null;this.events={inited$:new q.Subject,destroyed$:new q.Subject,error$:new q.Subject};this.#n=null;this.#i=null;this.#t=null;this.#a=new q.Subscription;this.#l=!1;this.#c=0;this.#n=t,this.#t=e,this.#i=n,this.#r=i,this.#o=o,this.state.history$&&this.#a&&this.#a?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,Qr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#o.maxLength-1)}))}#r;#o;#s;#e;#p;#n;#i;#t;#a;#l;#c;async setManifest(e){if(!this.#i||!this.#t)return;this.#e=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#i.setChapter({chapterId:t,pushToHistory:!1}),this.#s||(this.#s=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#s}async updateHistory(e,t=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,i=e.length-this.#o.maxLength,o=i>0?e.slice(i):e,l=jt(o,n);if(this.#p=l,this.state.history$.next(o),!(!t||!this.#r||!this.#n))try{await this.#r.save(this.#n,l)}catch{let a=new O(1,5,"Unable to save interactive history");this.events.error$.next(a),this.#t?.emit(S.errors,a)}}async goBack(){if(!this.state||!this.#i){let n=new O(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#t?.emit(S.errors,n)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#i.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#n)return;let e=this.#e,t=[this.getInitialVideoId()];if(this.#r)try{let i=await this.#r.get(this.#n);i.length&&(t=i)}catch{let o=new O(1,5,"Error while trying to fetch data");this.events.error$.next(o),this.#t?.emit(S.errors,o)}let n=Kr(t,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,Qr.default)(e,-1)||this.#o.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return jt([e],this.#e).pop()}return null}destroy(){this.#n=null,this.#r=null,this.#i=null,this.#a?.unsubscribe(),this.#a=null,this.#s=!1,this.#t?.emit(S.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var $t=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let i=3;i<n;i+=40)if(t[i]!==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(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.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){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var Ft=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??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
+ "use strict";var Ta=Object.create;var Je=Object.defineProperty;var Sa=Object.getOwnPropertyDescriptor;var wa=Object.getOwnPropertyNames;var Aa=Object.getPrototypeOf,Ra=Object.prototype.hasOwnProperty;var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ka=(r,e)=>{for(var t in e)Je(r,t,{get:e[t],enumerable:!0})},Zr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of wa(e))!Ra.call(r,i)&&i!==t&&Je(r,i,{get:()=>e[i],enumerable:!(n=Sa(e,i))||n.enumerable});return r};var D=(r,e,t)=>(t=r!=null?Ta(Aa(r)):{},Zr(e||!r||!r.__esModule?Je(t,"default",{value:r,enumerable:!0}):t,r)),Oa=r=>Zr(Je({},"__esModule",{value:!0}),r);var K=p((Xt,un)=>{"use strict";var Ae=function(r){return r&&r.Math===Math&&r};un.exports=Ae(typeof globalThis=="object"&&globalThis)||Ae(typeof window=="object"&&window)||Ae(typeof self=="object"&&self)||Ae(typeof global=="object"&&global)||Ae(typeof Xt=="object"&&Xt)||function(){return this}()||Function("return this")()});var _=p((od,hn)=>{"use strict";hn.exports=function(r){try{return!!r()}catch{return!0}}});var Re=p((sd,dn)=>{"use strict";var Pa=_();dn.exports=!Pa(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var bn=p((ad,yn)=>{"use strict";var Va=Re(),vn=Function.prototype,mn=vn.apply,fn=vn.call;yn.exports=typeof Reflect=="object"&&Reflect.apply||(Va?fn.bind(mn):function(){return fn.apply(mn,arguments)})});var H=p((ld,En)=>{"use strict";var Cn=Re(),gn=Function.prototype,Yt=gn.call,Ma=Cn&&gn.bind.bind(Yt,Yt);En.exports=Cn?Ma:function(r){return function(){return Yt.apply(r,arguments)}}});var ke=p((cd,xn)=>{"use strict";var In=H(),Na=In({}.toString),La=In("".slice);xn.exports=function(r){return La(Na(r),8,-1)}});var Zt=p((pd,Tn)=>{"use strict";var ja=ke(),$a=H();Tn.exports=function(r){if(ja(r)==="Function")return $a(r)}});var B=p((ud,Sn)=>{"use strict";var Jt=typeof document=="object"&&document.all;Sn.exports=typeof Jt>"u"&&Jt!==void 0?function(r){return typeof r=="function"||r===Jt}:function(r){return typeof r=="function"}});var ie=p((hd,wn)=>{"use strict";var Fa=_();wn.exports=!Fa(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var mt=p((dd,An)=>{"use strict";var _a=Re(),dt=Function.prototype.call;An.exports=_a?dt.bind(dt):function(){return dt.apply(dt,arguments)}});var er=p(On=>{"use strict";var Rn={}.propertyIsEnumerable,kn=Object.getOwnPropertyDescriptor,Ba=kn&&!Rn.call({1:2},1);On.f=Ba?function(e){var t=kn(this,e);return!!t&&t.enumerable}:Rn});var tr=p((fd,Pn)=>{"use strict";Pn.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Mn=p((vd,Vn)=>{"use strict";var qa=H(),Da=_(),Ha=ke(),rr=Object,Ua=qa("".split);Vn.exports=Da(function(){return!rr("z").propertyIsEnumerable(0)})?function(r){return Ha(r)==="String"?Ua(r,""):rr(r)}:rr});var nr=p((yd,Nn)=>{"use strict";Nn.exports=function(r){return r==null}});var ir=p((bd,Ln)=>{"use strict";var Ga=nr(),za=TypeError;Ln.exports=function(r){if(Ga(r))throw new za("Can't call method on "+r);return r}});var Oe=p((Cd,jn)=>{"use strict";var Wa=Mn(),Ka=ir();jn.exports=function(r){return Wa(Ka(r))}});var de=p((gd,$n)=>{"use strict";var Qa=B();$n.exports=function(r){return typeof r=="object"?r!==null:Qa(r)}});var ft=p((Ed,Fn)=>{"use strict";Fn.exports={}});var vt=p((Id,Bn)=>{"use strict";var or=ft(),sr=K(),Xa=B(),_n=function(r){return Xa(r)?r:void 0};Bn.exports=function(r,e){return arguments.length<2?_n(or[r])||_n(sr[r]):or[r]&&or[r][e]||sr[r]&&sr[r][e]}});var Dn=p((xd,qn)=>{"use strict";var Ya=H();qn.exports=Ya({}.isPrototypeOf)});var zn=p((Td,Gn)=>{"use strict";var Za=K(),Hn=Za.navigator,Un=Hn&&Hn.userAgent;Gn.exports=Un?String(Un):""});var Jn=p((Sd,Zn)=>{"use strict";var Yn=K(),ar=zn(),Wn=Yn.process,Kn=Yn.Deno,Qn=Wn&&Wn.versions||Kn&&Kn.version,Xn=Qn&&Qn.v8,U,yt;Xn&&(U=Xn.split("."),yt=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!yt&&ar&&(U=ar.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=ar.match(/Chrome\/(\d+)/),U&&(yt=+U[1])));Zn.exports=yt});var lr=p((wd,ti)=>{"use strict";var ei=Jn(),Ja=_(),el=K(),tl=el.String;ti.exports=!!Object.getOwnPropertySymbols&&!Ja(function(){var r=Symbol("symbol detection");return!tl(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&ei&&ei<41})});var cr=p((Ad,ri)=>{"use strict";var rl=lr();ri.exports=rl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var pr=p((Rd,ni)=>{"use strict";var nl=vt(),il=B(),ol=Dn(),sl=cr(),al=Object;ni.exports=sl?function(r){return typeof r=="symbol"}:function(r){var e=nl("Symbol");return il(e)&&ol(e.prototype,al(r))}});var oi=p((kd,ii)=>{"use strict";var ll=String;ii.exports=function(r){try{return ll(r)}catch{return"Object"}}});var ur=p((Od,si)=>{"use strict";var cl=B(),pl=oi(),ul=TypeError;si.exports=function(r){if(cl(r))return r;throw new ul(pl(r)+" is not a function")}});var li=p((Pd,ai)=>{"use strict";var hl=ur(),dl=nr();ai.exports=function(r,e){var t=r[e];return dl(t)?void 0:hl(t)}});var pi=p((Vd,ci)=>{"use strict";var hr=mt(),dr=B(),mr=de(),ml=TypeError;ci.exports=function(r,e){var t,n;if(e==="string"&&dr(t=r.toString)&&!mr(n=hr(t,r))||dr(t=r.valueOf)&&!mr(n=hr(t,r))||e!=="string"&&dr(t=r.toString)&&!mr(n=hr(t,r)))return n;throw new ml("Can't convert object to primitive value")}});var hi=p((Md,ui)=>{"use strict";ui.exports=!0});var fi=p((Nd,mi)=>{"use strict";var di=K(),fl=Object.defineProperty;mi.exports=function(r,e){try{fl(di,r,{value:e,configurable:!0,writable:!0})}catch{di[r]=e}return e}});var bt=p((Ld,bi)=>{"use strict";var vl=hi(),yl=K(),bl=fi(),vi="__core-js_shared__",yi=bi.exports=yl[vi]||bl(vi,{});(yi.versions||(yi.versions=[])).push({version:"3.38.0",mode:vl?"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 fr=p((jd,gi)=>{"use strict";var Ci=bt();gi.exports=function(r,e){return Ci[r]||(Ci[r]=e||{})}});var Pe=p(($d,Ei)=>{"use strict";var Cl=ir(),gl=Object;Ei.exports=function(r){return gl(Cl(r))}});var me=p((Fd,Ii)=>{"use strict";var El=H(),Il=Pe(),xl=El({}.hasOwnProperty);Ii.exports=Object.hasOwn||function(e,t){return xl(Il(e),t)}});var vr=p((_d,xi)=>{"use strict";var Tl=H(),Sl=0,wl=Math.random(),Al=Tl(1 .toString);xi.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Al(++Sl+wl,36)}});var Ve=p((Bd,Si)=>{"use strict";var Rl=K(),kl=fr(),Ti=me(),Ol=vr(),Pl=lr(),Vl=cr(),fe=Rl.Symbol,yr=kl("wks"),Ml=Vl?fe.for||fe:fe&&fe.withoutSetter||Ol;Si.exports=function(r){return Ti(yr,r)||(yr[r]=Pl&&Ti(fe,r)?fe[r]:Ml("Symbol."+r)),yr[r]}});var ki=p((qd,Ri)=>{"use strict";var Nl=mt(),wi=de(),Ai=pr(),Ll=li(),jl=pi(),$l=Ve(),Fl=TypeError,_l=$l("toPrimitive");Ri.exports=function(r,e){if(!wi(r)||Ai(r))return r;var t=Ll(r,_l),n;if(t){if(e===void 0&&(e="default"),n=Nl(t,r,e),!wi(n)||Ai(n))return n;throw new Fl("Can't convert object to primitive value")}return e===void 0&&(e="number"),jl(r,e)}});var br=p((Dd,Oi)=>{"use strict";var Bl=ki(),ql=pr();Oi.exports=function(r){var e=Bl(r,"string");return ql(e)?e:e+""}});var Mi=p((Hd,Vi)=>{"use strict";var Dl=K(),Pi=de(),Cr=Dl.document,Hl=Pi(Cr)&&Pi(Cr.createElement);Vi.exports=function(r){return Hl?Cr.createElement(r):{}}});var gr=p((Ud,Ni)=>{"use strict";var Ul=ie(),Gl=_(),zl=Mi();Ni.exports=!Ul&&!Gl(function(){return Object.defineProperty(zl("div"),"a",{get:function(){return 7}}).a!==7})});var $i=p(ji=>{"use strict";var Wl=ie(),Kl=mt(),Ql=er(),Xl=tr(),Yl=Oe(),Zl=br(),Jl=me(),ec=gr(),Li=Object.getOwnPropertyDescriptor;ji.f=Wl?Li:function(e,t){if(e=Yl(e),t=Zl(t),ec)try{return Li(e,t)}catch{}if(Jl(e,t))return Xl(!Kl(Ql.f,e,t),e[t])}});var _i=p((zd,Fi)=>{"use strict";var tc=_(),rc=B(),nc=/#|\.prototype\./,Me=function(r,e){var t=oc[ic(r)];return t===ac?!0:t===sc?!1:rc(e)?tc(e):!!e},ic=Me.normalize=function(r){return String(r).replace(nc,".").toLowerCase()},oc=Me.data={},sc=Me.NATIVE="N",ac=Me.POLYFILL="P";Fi.exports=Me});var Er=p((Wd,qi)=>{"use strict";var Bi=Zt(),lc=ur(),cc=Re(),pc=Bi(Bi.bind);qi.exports=function(r,e){return lc(r),e===void 0?r:cc?pc(r,e):function(){return r.apply(e,arguments)}}});var Hi=p((Kd,Di)=>{"use strict";var uc=ie(),hc=_();Di.exports=uc&&hc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Gi=p((Qd,Ui)=>{"use strict";var dc=de(),mc=String,fc=TypeError;Ui.exports=function(r){if(dc(r))return r;throw new fc(mc(r)+" is not an object")}});var Ki=p(Wi=>{"use strict";var vc=ie(),yc=gr(),bc=Hi(),Ct=Gi(),zi=br(),Cc=TypeError,Ir=Object.defineProperty,gc=Object.getOwnPropertyDescriptor,xr="enumerable",Tr="configurable",Sr="writable";Wi.f=vc?bc?function(e,t,n){if(Ct(e),t=zi(t),Ct(n),typeof e=="function"&&t==="prototype"&&"value"in n&&Sr in n&&!n[Sr]){var i=gc(e,t);i&&i[Sr]&&(e[t]=n.value,n={configurable:Tr in n?n[Tr]:i[Tr],enumerable:xr in n?n[xr]:i[xr],writable:!1})}return Ir(e,t,n)}:Ir:function(e,t,n){if(Ct(e),t=zi(t),Ct(n),yc)try{return Ir(e,t,n)}catch{}if("get"in n||"set"in n)throw new Cc("Accessors not supported");return"value"in n&&(e[t]=n.value),e}});var Xi=p((Yd,Qi)=>{"use strict";var Ec=ie(),Ic=Ki(),xc=tr();Qi.exports=Ec?function(r,e,t){return Ic.f(r,e,xc(1,t))}:function(r,e,t){return r[e]=t,r}});var Le=p((Zd,Zi)=>{"use strict";var Ne=K(),Tc=bn(),Sc=Zt(),wc=B(),Ac=$i().f,Rc=_i(),ve=ft(),kc=Er(),ye=Xi(),Yi=me();bt();var Oc=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 Tc(r,this,arguments)};return e.prototype=r.prototype,e};Zi.exports=function(r,e){var t=r.target,n=r.global,i=r.stat,o=r.proto,l=n?Ne:i?Ne[t]:Ne[t]&&Ne[t].prototype,s=n?ve:ve[t]||ye(ve,t,{})[t],a=s.prototype,c,d,f,v,y,k,w,C,u;for(v in e)c=Rc(n?v:t+(i?".":"#")+v,r.forced),d=!c&&l&&Yi(l,v),k=s[v],d&&(r.dontCallGetSet?(u=Ac(l,v),w=u&&u.value):w=l[v]),y=d&&w?w:e[v],!(!c&&!o&&typeof k==typeof y)&&(r.bind&&d?C=kc(y,Ne):r.wrap&&d?C=Oc(y):o&&wc(y)?C=Sc(y):C=y,(r.sham||y&&y.sham||k&&k.sham)&&ye(C,"sham",!0),ye(s,v,C),o&&(f=t+"Prototype",Yi(ve,f)||ye(ve,f,{}),ye(ve[f],v,y),r.real&&a&&(c||!a[v])&&ye(a,v,y)))}});var eo=p((Jd,Ji)=>{"use strict";var Pc=Math.ceil,Vc=Math.floor;Ji.exports=Math.trunc||function(e){var t=+e;return(t>0?Vc:Pc)(t)}});var je=p((em,to)=>{"use strict";var Mc=eo();to.exports=function(r){var e=+r;return e!==e||e===0?0:Mc(e)}});var no=p((tm,ro)=>{"use strict";var Nc=je(),Lc=Math.min;ro.exports=function(r){var e=Nc(r);return e>0?Lc(e,9007199254740991):0}});var $e=p((rm,io)=>{"use strict";var jc=no();io.exports=function(r){return jc(r.length)}});var gt=p((nm,oo)=>{"use strict";oo.exports=function(){}});var so=p(()=>{"use strict";var $c=Le(),Fc=Pe(),_c=$e(),Bc=je(),qc=gt();$c({target:"Array",proto:!0},{at:function(e){var t=Fc(this),n=_c(t),i=Bc(e),o=i>=0?i:n+i;return o<0||o>=n?void 0:t[o]}});qc("at")});var Et=p((sm,ao)=>{"use strict";var Dc=vt();ao.exports=Dc});var co=p((am,lo)=>{"use strict";so();var Hc=Et();lo.exports=Hc("Array","at")});var uo=p((lm,po)=>{"use strict";var Uc=co();po.exports=Uc});var wr=p((cm,ho)=>{"use strict";var Gc=uo();ho.exports=Gc});var Io=p((Qm,Eo)=>{"use strict";var ip=je(),op=Math.max,sp=Math.min;Eo.exports=function(r,e){var t=ip(r);return t<0?op(t+e,0):sp(t,e)}});var Mr=p((Xm,To)=>{"use strict";var ap=Oe(),lp=Io(),cp=$e(),xo=function(r){return function(e,t,n){var i=ap(e),o=cp(i);if(o===0)return!r&&-1;var l=lp(n,o),s;if(r&&t!==t){for(;o>l;)if(s=i[l++],s!==s)return!0}else for(;o>l;l++)if((r||l in i)&&i[l]===t)return r||l||0;return!r&&-1}};To.exports={includes:xo(!0),indexOf:xo(!1)}});var So=p(()=>{"use strict";var pp=Le(),up=Mr().includes,hp=_(),dp=gt(),mp=hp(function(){return!Array(1).includes()});pp({target:"Array",proto:!0,forced:mp},{includes:function(e){return up(this,e,arguments.length>1?arguments[1]:void 0)}});dp("includes")});var Ao=p((Jm,wo)=>{"use strict";So();var fp=Et();wo.exports=fp("Array","includes")});var ko=p((ef,Ro)=>{"use strict";var vp=Ao();Ro.exports=vp});var Ge=p((tf,Oo)=>{"use strict";var yp=ko();Oo.exports=yp});var Fo=p((hf,$o)=>{"use strict";var Cp=fr(),gp=vr(),jo=Cp("keys");$o.exports=function(r){return jo[r]||(jo[r]=gp(r))}});var Bo=p((df,_o)=>{"use strict";var Ep=_();_o.exports=!Ep(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var Ho=p((mf,Do)=>{"use strict";var Ip=me(),xp=B(),Tp=Pe(),Sp=Fo(),wp=Bo(),qo=Sp("IE_PROTO"),jr=Object,Ap=jr.prototype;Do.exports=wp?jr.getPrototypeOf:function(r){var e=Tp(r);if(Ip(e,qo))return e[qo];var t=e.constructor;return xp(t)&&e instanceof t?t.prototype:e instanceof jr?Ap:null}});var Go=p((ff,Uo)=>{"use strict";Uo.exports={}});var Ko=p((vf,Wo)=>{"use strict";var Rp=H(),$r=me(),kp=Oe(),Op=Mr().indexOf,Pp=Go(),zo=Rp([].push);Wo.exports=function(r,e){var t=kp(r),n=0,i=[],o;for(o in t)!$r(Pp,o)&&$r(t,o)&&zo(i,o);for(;e.length>n;)$r(t,o=e[n++])&&(~Op(i,o)||zo(i,o));return i}});var Xo=p((yf,Qo)=>{"use strict";Qo.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var Zo=p((bf,Yo)=>{"use strict";var Vp=Ko(),Mp=Xo();Yo.exports=Object.keys||function(e){return Vp(e,Mp)}});var is=p((Cf,ns)=>{"use strict";var es=ie(),Np=_(),ts=H(),Lp=Ho(),jp=Zo(),$p=Oe(),Fp=er().f,rs=ts(Fp),_p=ts([].push),Bp=es&&Np(function(){var r=Object.create(null);return r[2]=2,!rs(r,2)}),Jo=function(r){return function(e){for(var t=$p(e),n=jp(t),i=Bp&&Lp(t)===null,o=n.length,l=0,s=[],a;o>l;)a=n[l++],(!es||(i?a in t:rs(t,a)))&&_p(s,r?[a,t[a]]:t[a]);return s}};ns.exports={entries:Jo(!0),values:Jo(!1)}});var os=p(()=>{"use strict";var qp=Le(),Dp=is().values;qp({target:"Object",stat:!0},{values:function(e){return Dp(e)}})});var as=p((If,ss)=>{"use strict";os();var Hp=ft();ss.exports=Hp.Object.values});var cs=p((xf,ls)=>{"use strict";var Up=as();ls.exports=Up});var Vt=p((Tf,ps)=>{"use strict";var Gp=cs();ps.exports=Gp});var Dr=p((Gf,Cs)=>{"use strict";var Wp=ke();Cs.exports=Array.isArray||function(e){return Wp(e)==="Array"}});var Es=p((zf,gs)=>{"use strict";var Kp=TypeError,Qp=9007199254740991;gs.exports=function(r){if(r>Qp)throw Kp("Maximum allowed index exceeded");return r}});var Ts=p((Wf,xs)=>{"use strict";var Xp=Dr(),Yp=$e(),Zp=Es(),Jp=Er(),Is=function(r,e,t,n,i,o,l,s){for(var a=i,c=0,d=l?Jp(l,s):!1,f,v;c<n;)c in t&&(f=d?d(t[c],c,e):t[c],o>0&&Xp(f)?(v=Yp(f),a=Is(r,e,f,v,a,o-1)-1):(Zp(a+1),r[a]=f),a++),c++;return a};xs.exports=Is});var As=p((Kf,ws)=>{"use strict";var eu=Ve(),tu=eu("toStringTag"),Ss={};Ss[tu]="z";ws.exports=String(Ss)==="[object z]"});var ks=p((Qf,Rs)=>{"use strict";var ru=As(),nu=B(),Nt=ke(),iu=Ve(),ou=iu("toStringTag"),su=Object,au=Nt(function(){return arguments}())==="Arguments",lu=function(r,e){try{return r[e]}catch{}};Rs.exports=ru?Nt:function(r){var e,t,n;return r===void 0?"Undefined":r===null?"Null":typeof(t=lu(e=su(r),ou))=="string"?t:au?Nt(e):(n=Nt(e))==="Object"&&nu(e.callee)?"Arguments":n}});var Ps=p((Xf,Os)=>{"use strict";var cu=H(),pu=B(),Hr=bt(),uu=cu(Function.toString);pu(Hr.inspectSource)||(Hr.inspectSource=function(r){return uu(r)});Os.exports=Hr.inspectSource});var $s=p((Yf,js)=>{"use strict";var hu=H(),du=_(),Vs=B(),mu=ks(),fu=vt(),vu=Ps(),Ms=function(){},Ns=fu("Reflect","construct"),Ur=/^\s*(?:class|function)\b/,yu=hu(Ur.exec),bu=!Ur.test(Ms),Qe=function(e){if(!Vs(e))return!1;try{return Ns(Ms,[],e),!0}catch{return!1}},Ls=function(e){if(!Vs(e))return!1;switch(mu(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return bu||!!yu(Ur,vu(e))}catch{return!0}};Ls.sham=!0;js.exports=!Ns||du(function(){var r;return Qe(Qe.call)||!Qe(Object)||!Qe(function(){r=!0})||r})?Ls:Qe});var qs=p((Zf,Bs)=>{"use strict";var Fs=Dr(),Cu=$s(),gu=de(),Eu=Ve(),Iu=Eu("species"),_s=Array;Bs.exports=function(r){var e;return Fs(r)&&(e=r.constructor,Cu(e)&&(e===_s||Fs(e.prototype))?e=void 0:gu(e)&&(e=e[Iu],e===null&&(e=void 0))),e===void 0?_s:e}});var Hs=p((Jf,Ds)=>{"use strict";var xu=qs();Ds.exports=function(r,e){return new(xu(r))(e===0?0:e)}});var Us=p(()=>{"use strict";var Tu=Le(),Su=Ts(),wu=Pe(),Au=$e(),Ru=je(),ku=Hs();Tu({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=wu(this),n=Au(t),i=ku(t,0);return i.length=Su(i,t,t,n,0,e===void 0?1:Ru(e)),i}})});var Gs=p(()=>{"use strict";var Ou=gt();Ou("flat")});var Ws=p((iv,zs)=>{"use strict";Us();Gs();var Pu=Et();zs.exports=Pu("Array","flat")});var Qs=p((ov,Ks)=>{"use strict";var Vu=Ws();Ks.exports=Vu});var Ys=p((sv,Xs)=>{"use strict";var Mu=Qs();Xs.exports=Mu});var Hu={};ka(Hu,{ContainerTypes:()=>b.ContainerTypes,ControlTypes:()=>b.ControlTypes,CustomError:()=>O,EVENT_NAMES:()=>S,EventActionTypes:()=>b.EventActionTypes,EventTypes:()=>b.EventTypes,Interactives:()=>Ye,ManifestController:()=>ae,SDKInfo:()=>Du,chapterIdsToVKVideoIds:()=>jt,compareVersions:()=>Rt,containerTypes:()=>Qc,controlTypes:()=>Xc,eventActionTypes:()=>Rr,eventTypes:()=>Yc,getChapterIdByVkVideoId:()=>fa,getVKVideoIdByMedia:()=>Wr,getVideoRawIdByMedia:()=>da,graphEventTypes:()=>ge,hasEndTemplate:()=>ze,interactivesEventTypes:()=>P,isAreaControl:()=>Kc,isButtonControl:()=>Wc,isLastChapter:()=>G,isOneTextCtrlContainer:()=>se,isSupportedManifest:()=>b.isSupportedManifest,isTextControl:()=>qe,isVKVariantItem:()=>ma,isValidManifest:()=>Ar,migrateManifestToLatestVersion:()=>b.migrateManifestToLatestVersion,utils:()=>Ia,vkVideoIdsToChapterIds:()=>Kr});module.exports=Oa(Hu);var Jr="1.0.37-dev.8109bc71.0";var ut=require("@vkontakte/videoplayer-shared");var Bt=class{constructor(e){this.layout=e}},et=class extends Bt{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 en(r){return"features"in r}var pe=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&en(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(){return this.container.controls?.reduce((e,t)=>{let n=t.type.trim().toLowerCase(),i=this.factories.get(n);if(i){let o=i(t,this.options);if(o)return[...e,o]}return[...e]},[])||[]}};var re=require("@vkontakte/videoplayer-shared");function Ie(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 tn="interactive",V={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderWidthRawValue:"1px",roundCornersRawValue:"0",borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0,shadowColorLight:"#fff",shadowColorDark:"#000",shadowColorAlpha:.24},rn=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(rn||{}),nn=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(nn||{}),on=(n=>(n.start="left",n.end="right",n.center="center",n))(on||{}),tt=({target:r,props:e})=>{r.style.alignItems=(e?.gravityVertical&&rn[e.gravityVertical])??"center",r.style.justifyContent=(e?.gravityHorizontal&&nn[e.gravityHorizontal])??"center",r.style.textAlign=(e?.alignment&&on[e.alignment])??"center"},rt=({target:r,props:e,fallback:t,dependsOn:n})=>{r.style.color=e?.text?.color??t.textColor,r.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,r.textContent=e?.text?.value??t.textContent},nt=({target:r,props:e,fallback:t})=>{r.style.backgroundColor=Ie(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},xe=({target:r,props:e,fallback:t,dependsOn:n,useRawValues:i=!1})=>{let o=i?t.borderWidthRawValue:`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth})`,l=i?t.roundCornersRawValue:`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Ie(i?t.borderColor:e?.shape?.border?.color??t.borderColor,i?t.borderAlpha:e?.shape?.border?.alpha??t.borderAlpha),r.style.borderRadius=l},sn=({target:r,isDark:e,baseDimension:t,fallback:n})=>{let l=Ie(n.shadowColorLight,n.shadowColorAlpha),s=Ie(n.shadowColorDark,n.shadowColorAlpha),a=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,d=`0px 0px ${a} ${c} ${e?s:l}`;r.style.boxShadow=d},ue=({target:r,layoutParams:e,fallback:t})=>{let n=e.angle??t.angle;n=n&&n*-1,r.style.transform=`rotate(${n}rad)`};var he=require("@vkontakte/videoplayer-shared");var qt="int",ee=(n=>(n.AREA=`${qt}_area`,n.TEXT=`${qt}_text`,n.BUTTON=`${qt}_bttn`,n))(ee||{});function an(r){return"features"in r}var W="interactive-control",R={common:W,selected:`${W}-selected`,wrapper:`${W}-wrapper`,disabled:`${W}-disabled`,button:`${W}-button`,area:`${W}-area`,text:`${W}-text`,blinkAnim:`${W}-blink-anim`,blinkAnimButton:`${W}-blink-anim-button`,blinkAnimArea:`${W}-blink-anim-area`};var O=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Q=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new he.Subscription;this.error$=new he.Subject}createContainerElement(e){let t=document.createElement("div");t.classList.add(R.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??V.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&&an(this.options)&&this.options.features[e]}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":{if(!this.container)break;this.subscriptions.add((0,he.fromEvent)(this.container.element,"click").subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),i=>{let o=new O(1,1,{message:"Error happened on control interaction",error:i});this.error$.next(o)}));break}default:break}})}removeListeners(){this.subscriptions.unsubscribe()}};var X=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Y=r=>X(r,"Object"),it=r=>X(r,"String"),ot=r=>X(r,"Array"),st=r=>X(r,"Number"),ln=r=>X(r,"Function"),cn=r=>X(r,"Boolean"),Dt=r=>st(r)&&!isNaN(r);var te=r=>Y(r)&&Object.keys(r).length===0,Ht=r=>ot(r)&&!r.length;var we=(r,e)=>it(r)&&(e?r.trim():r).length;var Ut="interactive-blink-anim-reference",L={common:Ut,animation:`${Ut}-animation`,disabled:`${Ut}-disabled`},at=class{constructor(){this._RAFId=0;this._element=void 0}get element(){return this._element}create(){if(this._element)return;let e=document.createElement("div");e.classList.add(L.common,L.animation),this._element=e}restart(){this._element&&(this._element.classList.add(L.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(L.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var Gt="interactive-container",j={common:Gt,hidden:`${Gt}-hidden`,disabled:`${Gt}-disabled`};var lt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new zt(r,e)},zt=class extends Q{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(R.common,R.area),n.setAttribute("data-testid",ee.AREA),nt({target:n,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),ue({target:n,layoutParams:this.control.layoutParams,fallback:V}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.updateShadowStyles(),this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add((0,re.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(j.disabled))return;let t=e.parentElement;if(t){let n=t.querySelector(`.${L.common}`);n&&this.syncBlinkAnimation(n)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add((0,re.fromEvent)(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(j.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add((0,re.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(R.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(R.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(cn(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";sn({target:this.controlElement,props:this.control.props,fallback:V,isDark:e,baseDimension:t}),xe({target:this.controlElement,props:this.control.props,fallback:{...V,borderColor:e?V.shadowColorDark:V.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??V.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else xe({target:this.controlElement,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(R.blinkAnim,e),this.controlElement?.classList.toggle(R.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${R.blinkAnimArea}`)||this.controlElement.classList.contains(R.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add((0,re.fromEvent)(e,"animationiteration").pipe((0,re.once)()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${R.blinkAnimArea}`)||this.controlElement.classList.contains(R.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-area-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}onError(e="",t){let n=new O(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(n)}onProgress(){}onResize(){}};var ne=require("@vkontakte/videoplayer-shared");var ct=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 pt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Wt(r,e)},Wt=class extends Q{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(R.common,R.button),n.setAttribute("data-testid",ee.BUTTON),ue({target:n,layoutParams:this.control.layoutParams,fallback:V}),nt({target:n,props:this.control.props,fallback:V}),xe({target:n,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=ct(this.control.type.trim().toLowerCase()),o=i.firstElementChild??i;rt({target:o,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add((0,ne.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(j.disabled))return;let t=e.parentElement;if(t){let n=t.querySelector(`.${L.common}`);n&&this.syncBlinkAnimation(n)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add((0,ne.fromEvent)(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(j.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add((0,ne.fromEvent)(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(R.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(R.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(R.blinkAnim,e),this.controlElement?.classList.toggle(R.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${R.blinkAnimButton}`)||this.controlElement.classList.contains(R.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add((0,ne.fromEvent)(e,"animationiteration").pipe((0,ne.once)()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${R.blinkAnimButton}`)||this.controlElement.classList.contains(R.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-button-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}onError(e="",t){let n=new O(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(n)}onProgress(){}onResize(){}updateShadowStyles(){}};var pn=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Kt(r,e)},Kt=class extends Q{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(R.common,R.text),n.setAttribute("data-testid",ee.TEXT),ue({target:n,layoutParams:this.control.layoutParams,fallback:V}),tt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=ct(this.control.type.trim().toLowerCase()),o=i.firstElementChild??i;rt({target:o,props:this.control.props,fallback:V,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(){}updateShadowStyles(){}toggleBlinkAnimation(){}onError(){}};var ht=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new Qt(r,e,t)},Qt=class extends pe{constructor(t,n,i){super(t,i);this.containerElement=null;this.controlSubscriptions=new ut.Subscription;this.error$=new ut.Subject;this.rootElement=n,this.layout=new et(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pt),this.addControlFactory("text",pn),this.addControlFactory("area",lt)}createView({eventCallback:t}){let n=document.createElement("div");return n.classList.add(j.common,j.disabled),requestAnimationFrame(()=>{n.classList.remove(j.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout}}),i.setEvents(t),this.controlSubscriptions.add(i.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.containerElement=n,n}hide(){let t=this.getElement();t&&t.classList.add(j.hidden)}show(){let t=this.getElement();t&&t.classList.remove(j.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(j.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(j.disabled),this.controls.forEach(n=>n.disable()),this.isDisabled=!0)}removeView(){let t=this.getElement();t&&(this.controlSubscriptions.unsubscribe(),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()})}updateControlsShadowStyles(t){this.controls.forEach(n=>n.updateShadowStyles(t))}toggleBlinkAnimation(t){this.controls.forEach(n=>n.toggleBlinkAnimation(t))}};var ga=D(wr(),1),g=require("@vkontakte/videoplayer-shared"),Ee=require("@vkontakte/videoplayer-statistics");var yo=require("@vkontakte/videoplayer-shared");function Fe(r,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>r(...n),e)}}var mo="video_interactive",fo="videoint";var vo=250,_e=class{constructor(e){this.handleZoomChange=Fe(e=>{this.lastZoomInfo=e},vo);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Chapter id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!st(e.graph.edit.chapters[0].x)){this.onError?.("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:o=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(o),this.onOpenPreviewClick=t,this.onError=n,this.lang=i??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=zc(e),this.resizeObserver=new ResizeObserver(Fe(this.onResize,vo)),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){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await(0,yo.loadVKLangPack)(this.lang,mo,fo)}catch{this.onError?.("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"view",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:n,...i})=>{n==="openPreview"&&"chapterId"in i&&this.onOpenPreviewClick?.(i.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function zc(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 Be=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 o of this._containers){let l=o.startTime-e;if(l<=i&&(o.endTime&&i<=o.endTime||o.endTime===null)){n=!0;break}i<l&&(t=t===-1?l:Math.min(t,l))}return!n&&t!==-1?t:null}}};var b=require("@interactiveplatform/movika-manifest");var bo={metadata:"Object",chapters:"Array"},Ar=r=>{if(!Y(r))return!1;for(let e in bo)if(!r[e]||!X(r[e],bo[e]))return!1;return(0,b.isSupportedManifest)(r.metadata.version)},qe=r=>r.type===b.ControlTypes.Text,Wc=r=>r.type===b.ControlTypes.Button,Kc=r=>r.type===b.ControlTypes.Area,Qc={Choice:"Choice",TextInput:"TextInput"},Xc={Button:"Button",Area:"Area",Text:"Text"},Yc={onClick:"onClick",onSuspense:"onSuspense"},Rr={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var It=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 xt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{ln(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=[]}};var Lo=require("@vkontakte/videoplayer-shared");var Tt=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return Zc(...this.loaders[e])(t)}};function Zc(...r){return async function(t){let n=[...r];for(;n.length>0;)t=await n.shift()(t);return t}}function De(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function St({actions:r,errors:e,chapterId:t,...n}){if(t){let i=r.getManifest();if(i){let o=r.getChapter(i.chapters,t);if(o){let l=r.getMedia(i.media,o.videoId),s=r.getGraph(i.graph,o.id);return l?{...n,actions:r,errors:e,result:{chapter:o,media:l,graph:s}}:{...n,errors:De(e,St.name,"Could not find media"),actions:r}}}}return{...n,errors:De(e,St.name,"Could not find chapter"),actions:r}}var wt=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,o=n.length;i<o;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,o=n.length;i<o;i++){let l=n[i];try{l.callback.call(this,e)}catch(s){Promise.resolve().then(()=>{throw s})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},be=class extends wt{constructor(){super(),this.listeners||wt.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)}},He=class{constructor(){Object.defineProperty(this,"signal",{value:new be,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?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>"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(He.prototype[Symbol.toStringTag]="AbortController",be.prototype[Symbol.toStringTag]="AbortSignal");function At(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 kr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=r;if(!At({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:o};let o=t;(o&&!o.prototype.hasOwnProperty("signal")||i)&&(o=function(c,d){let f;d&&d.signal&&(f=d.signal,delete d.signal);let v=new t(c,d);return f&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),v},o.prototype=t.prototype);let l=e;return{fetch:(a,c)=>{let d=o&&o.prototype.isPrototypeOf(a)?a.signal:c?c.signal:void 0;if(d){let f;try{f=new DOMException("Aborted","AbortError")}catch{f=new Error("Aborted"),f.name="AbortError"}if(d.aborted)return Promise.reject(f);let v=new Promise((y,k)=>{d.addEventListener("abort",()=>k(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([v,l(a,c)])}return l(a,c)},Request:o}}var Jc=()=>"fetch"in window,Ue=Jc()&&At({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Co=Ue?kr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Or=Ue?Co.fetch:window.fetch,_m=Ue?Co.Request:window.Request,Bm=Ue?He:window.AbortController,qm=Ue?be:window.AbortSignal;var Rt=(r="",e="")=>{let t=r.split("."),n=e.split("."),i=0;for(let o=0;o<Math.max(t.length,n.length)&&!i;o++)t[o]>n[o]?i=1:t[o]<n[o]?i=-1:i=0;return i};var ep=async r=>{try{let e={},t;if(it(r)){t=new URL(r).href;let i=await Or(t);if(!i.ok)return{};e=await i.json()}else if(Y(r))e=r;else return{};if(!Ar(e))return{};let n=e.metadata.media;if(it(n)&&!("media"in e))try{let i;t?i=new URL(n,t).href:(i=new URL(n).href,t=i);let o=await Or(i);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch{return np(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function go(r){let{manifest:e,manifestURL:t}=await ep(r);if(!e)throw new Error("Failed on fetch");let n=(0,b.migrateManifestToLatestVersion)(e);return n.media=tp(n.media,t),delete n.metadata.media,n}function kt(r,e){if(e)return r.find(t=>t.id===e)}function Pr(r,e){return r.edit?.chapters?r.edit.chapters.find(t=>t.id===e):r.view?.chapters?r.view.chapters.find(t=>t.id===e):void 0}function Vr(r,e){return r.videos.find(t=>t.id===e)}function tp(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(n=>{let i="url"in n?n.url:"",o=rp(i,e);return{...n,url:o||i}})}))}}function rp(r="",e){try{return new URL(r,e).href}catch{return""}}function np(r){return Rt(r,"3.2.0")>=0}var Po=D(Ge(),1);var Ot=r=>ot(r)&&!Ht(r),G=r=>r.order==="end",ze=r=>ot(r.containers)&&!Ht(r.containers)&&G(r),Vo=(r,e)=>{let t=r*1e3;return Ot(e.controls)&&t<(e.startTime??0)},Nr=(r,e)=>{let t=r*1e3;return Ot(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var oe=(r=[])=>r.some(e=>e.action.type==="expect"),Lr=(r=[])=>r.find(e=>e.action.type==="expect"),bp=r=>r?.length===1,se=r=>bp(r)&&qe(r[0]);function Mo(r=[],e=1/0,t=[]){return r.filter(({container:n})=>!(0,Po.default)(t,n.container.id)&&oe(n.container.events)&&n.container.endTime===e&&!n.isRemoved)}function Pt({gameControllers:r=[],subjectName:e,subjectId:t,execFn:n}){for(let i of r)if(e==="container"&&i.container.container.id===t){n(i),Mo(r,i.container.container.endTime,[i.container.container.id]).forEach(l=>{n(l)});break}}var No=(r,e)=>{let t=w=>e.find(({container:u})=>u.container.id===w)?.container.isRemoved,n=oe(r.events)&&!t(r.id),i=(w,C=!1,u=!1)=>{let h=u?"every":"some";return w.controls[h](m=>{let I=C?w.endTime===r.endTime:!0;return m.events?.[h](E=>E.action?.type===Rr.openURI)&&I})},o=w=>w.some(({container:C})=>i(C.container,!0,!1)&&!C.isRemoved),l=w=>w.every(({container:C})=>C.isRemoved?!0:i(C.container,!0,!0)),s=Mo(e,r.endTime,[r.id]).length,a=w=>w.controls.some(C=>C.events?.some(u=>u.action?.args?.shouldOpenNow)),c=n||s>0,d=o(e),f=i(r),v=l(e),y=n?!1:s>0,k=a(r);return{isExpectTime:c,hasOtherExpect:s>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:f,isAllOpenURIEventsValid:v,isExpectEventForCurrentContainer:y,hasShouldOpenNowEvent:k}};var ae=class extends Tt{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Lo.ValueSubject(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){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:De},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await go(n.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",St({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Pr,getChapter:kt,getMedia:Vr,getByBranches:this.getByBranches.bind(this),addErrorMessage:De},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),n.result&&(this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let n=kt(this.manifest.chapters,t);if(n){let i=Vr(this.manifest.media,n.videoId),o=Pr(this.manifest.graph,n.id);if(i)return{chapter:n,media:i,graph:o}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=kt(this.manifest?.chapters||[],t);return this.getByBranches(n?.branches)}}getByBranches(t=[]){return t.reduce((n,i)=>{let o=this.getByChapterId(i.chapterId);return o&&n.push(o),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?G(this.chapter):!1}};var ds=D(Vt(),1),ms=require("@vkontakte/videoplayer-core"),Z=require("@vkontakte/videoplayer-shared");var us=r=>{let e=r.variants.find(t=>t.payload?.type==="vk");if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};var hs=D(Vt(),1);function Fr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:l=Math.random().toString(),...s}){let a=r.get(o),c={...s};return a?a[l]=c:r.set(o,{[l]:c}),{listId:o,itemId:l,...s}}function t(o){o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),o.statistics?.oneStat.destroy(),o.statistics?.statSubscription.unsubscribe()}function n(o,l){let s=r.get(o);if(!s)throw Error("Can't remove. Not find.");if(l){let a=s[l];a&&t(a),delete s[l],Object.keys(s).length||r.delete(o)}else{for(let a of(0,hs.default)(s))t(a);r.delete(o)}}function i(){for(let o of r)n(o[0])}return{createPlayer:e,removePlayer:n,map:r,removeAll:i}}var Ce=D(Ge(),1);function _r(r,e=[]){let t={},n,i=!e.length;for(let o of r.variants)if(!n&&"cover"in o&&(n=o.cover),"url"in o)switch(o.type.toLowerCase()){case"mp4":(i||(0,Ce.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"mpeg":(i||(0,Ce.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"hls":(i||(0,Ce.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:o.url}});break;case"dash":(i||(0,Ce.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:o.url}});break;default:break}return{sources:t,thumbUrl:n,title:r.title??""}}var We=(r,e)=>{let t=r.info.currentQuality$.getValue(),n=r.info.availableQualities$.getValue();t!==e&&(0,Ce.default)(n,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var zp=2;function Br(r){let e=Fr(),t=new Z.Subscription,n={},i=null,o=!1,l,s=new Z.ValueSubject(null);r&&a(r);function a(C){i=C}function c(C,u,h){if(!i)throw Error("need to set interactive controller");if(!i.options)return;let I=(e.map.get(C)??{})[u];if(I){n={chapterId:h,listId:C,itemId:u,...I};let E=n.player;n.subscription.add(E.info.currentQuality$.subscribe(x=>{let A=E.info.position$.getValue(),$=E.info.isAutoQualityEnabled$.getValue();if(!(!x||!A||$))for(let T of e.map)(0,ds.default)(T[1]).forEach(({player:M})=>{We(M,x)})})).add(E.events.started$.subscribe(()=>{d(u)})),I.container.remove(),i.setPlayer(I.player),o||(i.init(),o=!0),s.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function d(C){if(!i)throw Error("need to set interactive controller");if(te(n)||C!==n.itemId)return;let u=i.getChapterBranches(),h=new Set;for(let m of u)h.has(m.media.id)||(await v({media:m.media,chapterId:m.chapter.id,setAsActive:!1,title:m.chapter.label}),h.add(m.media.id))}async function f({chapter:{id:C},manifestVideo:u}){if(te(n)||!i)return;let h=n.player.info.muted$.getValue(),m=n.player.info.currentQuality$.getValue(),I=n.player.info.isAutoQualityEnabled$.getValue(),E=n.player.info.volume$.getValue(),x=n.player.info.currentPlaybackRate$.getValue(),A=!I,$=!1;for(let T of e.map)if(T[0]===u.id&&!i.state.isReplay$.getValue()){let M=Object.keys(T[1]);for(let N of M)N===n.itemId?(M.length<zp||($=!0),e.removePlayer(T[0],N)):($=!0,c(T[0],N,C),A?We(n.player,m):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h),n.player.setPlaybackRate(x))}else e.removePlayer(T[0]);$||(await v({media:u,chapterId:C,setAsActive:!0,playbackRate:x}),A?We(n.player,m):n.player.setAutoQuality(!0),n.player.setVolume(E),n.player.setMuted(h))}async function v({media:C,chapterId:u,prefetch:h=!0,setAsActive:m=!0,autoplay:I=!1,preferredExt:E,title:x,playbackRate:A}){let $=Math.random().toString(),T=document.createElement("div");l.append(T);let M;if(i?.options?.vkVideoLoader){let Ze=us(C);Ze.length&&(M=await i.options.vkVideoLoader(...Ze))}let N=i?.options?.coreConfig||void 0,z={...N,configName:[...N?.configName??[],"interactive"]},J={container:T,...M?.videos?.[0]||{sources:_r(C,E).sources},title:x,failoverHosts:M?.failoverHosts||[]},F=new ms.Player(z,Z.Tracer.createRootTracer());F.initVideo(J);let le=null;if(M?.videos&&i?.options.createOneStat){let Ze=M.videos[0],_t=i.options.createOneStat(Ze),Yr=new Z.Subscription;_t&&(Yr.add(_t.attachTo(F)),le={oneStat:_t,statSubscription:Yr})}let Xr=new Z.Subscription,xa=n?.player?.info.isAutoQualityEnabled$.getValue();Xr.add(F.events.canplay$.subscribe(function(){xa||We(F,n.player.info.currentQuality$.getValue()),A&&F.setPlaybackRate(A)}));let ce=e.createPlayer({listId:C.id,itemId:$,player:F,container:T,sources:_r(C,E).sources,config:J,subscription:Xr,statistics:le});return m&&c(C.id,ce.itemId,u),I&&ce.player.play(),h&&!I&&ce.player.prepare(),{player:ce.player,config:ce.config,statistics:ce.statistics}}function y(){k(),i=null,l.remove()}function k(){t.unsubscribe(),e.removeAll(),n={},o=!1}async function w(){if(!i)throw Error("need to set interactive controller");k(),l=document.createElement("div");let{media:C,chapter:u}=i.getCurrentChapter();C&&u?(t.add(i.events.chapterChanged$.subscribe(f)),await v({media:C,chapterId:u.id,title:u.label})):console.error("not found")}return{...e,init:w,setInteractiveController:a,createPlayer:v,removeAll:y,getActivePlayer:function(){return n},activePlayerChanged:s}}var S={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ge={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},P={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var vs=D(Ge(),1),ys=require("@vkontakte/videoplayer-shared");function qr(r){return function(...t){return r(...t.reverse())}}function Ke(r,...e){return(...t)=>Y(e[0])&&Y(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var Mt=class{constructor({player:e,container:t,branches:n,selectBranches:i,interactiveEvents:o,globalEvents:l,globalEventEmitter:s,getContainerEventState:a,permanentTextControls:c,interactiveTimeOpenUri:d,disabledControls$:f,onRemove:v,onError:y}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(oe(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&t)return;this.emitContainerVisibilityEvent(!0,!1)}else{let t={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(i,o)=>{let{isExpectTime:l,hasOtherExpect:s,hasOpenURIEvent:a,hasOpenURIEventInCurrentContainer:c,isAllOpenURIEventsValid:d,hasShouldOpenNowEvent:f}=this.getContainerEventState(),v=this.interactiveTimeOpenUri&&!c,y=this.interactiveTimeOpenUri&&c;if((!this.interactiveTimeOpenUri||v)&&(this.isSelectedControlEvent=!0),i!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||v)){if(this.interactiveTimeOpenUri){let k=!s&&!d&&c;k&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:k})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&a&&this.gameState!==5){if(y){let w=((C,u,h,m)=>!C&&!u&&h||C&&!u&&h&&!m||C&&!u&&h&&m)(l,s,d,this.isSelectedContainerEvent);this.fakeRemoveView(w)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!l||!s||!f)&&(this.selectBranches.stopExpect(),o())}},isEOV:()=>this.gameState===4},n=Ke(this.selectBranches.onControlEvent,t);this.container.createView({eventCallback:n}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,vs.default)(i,this.gameState)&&!this.isPermanentText)return;let o=this.player.getExactTime();if(Vo(o,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Nr(o,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let c=this.gameState;this.gameState=3,c===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:c}=this.getContainerEventState(),d=this.selectBranches.state.isExpect,f=this.interactiveTimeOpenUri&&c;if(f&&!d){let v=this.container.getElement();v&&(v.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!f&&this.removeView()}let l=Nr(o,this.container.container),s=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:s,currentTime:o,isInteractiveTime:l};this.container.onProgress(o*1e3,l),this.globalEventEmitter.emit(S.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=n,this.selectBranches=i,this.subscription=new ys.Subscription,this.player=e,this.interactiveEvents=o,this.getContainerEventState=a,this.isPermanentText=c&&se(t.container.controls),this.interactiveTimeOpenUri=d,this.disabledControls$=f,this.onRemove=v,this.globalEventEmitter=s,this.gameState=0,this.globalEvents=l,this.onError=y,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:P.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(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:P.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=>{e?this.container.disable?.():this.container.enable?.()})),this.subscription.add(this.container.error$.subscribe(this.onError))}selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??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(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:oe(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:P.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}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()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var bs=(r=[])=>r.reduce((e,t,n)=>{let i=(t?.controls??[]).filter(o=>!qe(o));if(Ot(i)){let o=[t.startTime??0,t.endTime??1/0],l={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[l],range:o});else{let s=[],a=-1/0,c=1/0,d=[],f=[];for(let v=0;v<e.length;v++){let y=e[v];if(f.push(...y.subjects),y.range[0]<c&&(c=y.range[0]),y.range[1]>a&&(a=y.range[1]),o[0]>=y.range[0]&&o[1]<=y.range[1])return e[v].subjects.push(l),e;o[0]<y.range[0]&&o[1]>y.range[0]&&(s.push(v),d=d.concat(y.subjects)),o[0]>=y.range[0]&&o[0]<=y.range[1]&&(s.push(v),d=d.concat(y.subjects),o[0]=y.range[0]),o[1]>=y.range[0]&&o[1]<=y.range[1]&&(s.push(v),d=d.concat(y.subjects),o[1]=y.range[1])}if(f.push(l),o[0]<=c&&o[1]>=a)return[{subjects:f,range:o}];s.length&&s.reverse().forEach(v=>{e.splice(v,1)}),e.push({subjects:d.concat([l]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var Js=D(Ge(),1),Gr=D(Vt(),1),ea=D(Ys(),1);function Zs(){let r={};function e(){for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&delete r[s]}function t(s){let a={};for(let c in r)+c<=s&&(a[c]=r[c]);return a}function n(s){let a={};for(let c in r)+c>=s&&(a[c]=r[c]);return a}function i({timestamp:s,priority:a,initiator:c}){if(Dt(s)){let d=r[s]??null;if(d&&a&&we(a,!0)){let f={},v=d[a];return v&&(f={...f,...v}),f=te(f)?null:f,f&&we(c,!0)?f[c]??null:f}return d}return null}function o({timestamp:s,priority:a,initiator:c}){if(Dt(s))if(r[s]){if(a&&we(a,!0))if(r[s][a]){if(c&&we(c,!0))if(r[s][a][c]){if(delete r[s][a][c],!te(r[s][a]))return!0}else return!1;if(delete r[s][a],!te(r[s]))return!0}else return!1;return delete r[s]}else return!1;return!1}function l({timestamp:s,priority:a,initiator:c,...d}){r[s]?.[a]?.[c]?r[s][a][c].push({...d}):r[s]?.[a]?r[s][a]={...r[s][a],[c]:[{...d}]}:r[s]?r[s]={...r[s],[a]:{[c]:[{...d}]}}:r[s]={[a]:{[c]:[{...d}]}}}return{map:r,remove:o,add:l,removeAll:e,get:i,getLte:t,getGte:n}}var Nu=[b.EventActionTypes.expect,b.EventActionTypes.setNextBranch],Lu=1/0;function ta(r,e){let t=r,n,i=ju(e),o=Zs(),l,s=()=>{y(),u()},a=h=>{o.add.call(void 0,h),k()},c=(h=[])=>{for(let m of h)if(m.action(),(0,Js.default)(Nu,m.actionType))break},d=(h=1/0)=>{let m=Lt(o.get({timestamp:h,priority:"control"})??{}),I=Lt(o.get({timestamp:h,priority:"container"})??{}),E=Lt(o.get({timestamp:h,priority:"chapter"})??{});return[...m,...I,...E]},f=h=>{i.isReady(h)&&c(d(h))},v=()=>{c([...Lt(o.get({timestamp:1/0,priority:"chapter"})??{})])},y=()=>{n&&(l?.unsubscribe(),n=void 0)},k=()=>{n||(n=()=>setTimeout(()=>{f(1/0)}),l=t.events.ended$.subscribe(n))},w=h=>{y(),t=h},C=h=>{h.priority==="container"&&i.resetCalled(h.timestamp),o.remove(h)},u=()=>{i.release(),o.removeAll()};return{setPlayer:w,add:a,remove:C,exec:f,execEndOfVideo:v,listen:k,unlisten:y,release:s,containersEventsCallState:i,getPreparedToExecActions:d}}function ju(r){let e=new Map;return{setCalled:({timestamp:s,id:a})=>{let c=e.get(s);c&&c[a]!==void 0&&(c[a]=!0)},setData:(s=[])=>{for(let a of s){let c=a.endTime??Lu,d=e.get(c);e.set(c,{...d,[a.id]:!1})}},resetCalled:s=>{let a=e.get(s);if(a)for(let c in a)a[c]=!1},isReady:s=>{let a=e.get(s);if(!a)return!0;let c=(0,Gr.default)(a);return r?c.some(f=>f):!c.some(f=>!f)},release:()=>e.clear()}}function Lt(r){return(0,ea.default)((0,Gr.default)(r)).sort(e=>e.actionType===b.EventActionTypes.expect?-1:1)}var ra={videoContentHeight:0,videoContentWidth:0},na=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return ra;let{clientHeight:n,clientWidth:i}=r.experimental.element$.getValue()||{};if(!(n&&i))return ra;let o=e/t,l=n/i,s,a;return l>o?(a=i,s=i*o):l<o?(a=n/o,s=n):(a=i,s=n),{videoContentWidth:a,videoContentHeight:s}};var $u=250;function ia(r){let e,t=new ResizeObserver(s=>{o(s),e=o.bind(null,s)});function n(s){let{parentElement:a,player:c}=r();if(a&&c){let{videoContentWidth:d,videoContentHeight:f}=na(c);a.style.setProperty("--interactive-content-width",`${d}px`),a.style.setProperty("--interactive-content-height",`${f}px`),a.style.setProperty("--interactive-width",`${s[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${s[0].contentRect.height}px`)}}function i(){let{parentElement:s}=r();s.removeAttribute("style")}let o=Fe(s=>{let{fns:a=[]}=r();n(s);for(let c of a)c()},$u);function l(){e=void 0,t.disconnect(),i()}return{resizeObserver:t,calc:()=>{e?.()},release:l}}var Fu=r=>Math.floor(Math.random()*r),sa=r=>{let e=r.length,t=1/0,n=null;for(;e--;){let i=r[e],o=i.weight??1;o<t&&(t=o,n=i)}return n},aa=r=>{let e=r.length,t=-1/0,n=null;for(;e--;){let i=r[e],o=i.weight??0;o>t&&(t=o,n=i)}return n};var la=r=>{let e=r.length,t=Fu(e);return r[t]},oa=1,ca=r=>{let e=0;for(let n=0;n<r.length;++n)e+=r[n].weight??oa;let t=Math.random()*e;e=0;for(let n=0;n<r.length-1;++n)if(e+=r[n].weight??oa,e>=t)return r[n];return r[r.length-1]};var pa={shouldOpenNow:!0,isDetachContainer:!0},ua="after-expect",zr=(r,e=!1)=>({...r,args:e?{...r.args,...pa}:{...pa,...r.args}}),ha=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:n})=>{let i={isExpect:!1},o=()=>{i.isExpect&&(i.isExpect=!1)},l=({action:u,controlType:h,controlId:m,containerId:I,branches:E=[],onEvent:x,isEOV:A=()=>!1,isDisabled:$=()=>!1})=>{let T=zr(u,A()),M={timestamp:1/0,priority:"control",initiator:m,actionType:T.type},N=$(),z=r.emit.bind(r,S.interactives,{subjectId:m,subjectType:h,subjectName:"control",type:N?P.actionChoiceCanceled:P.actionChoice,actionType:u.type,payload:{invokeImmediately:T.args.shouldOpenNow,containerId:I,...T.args}}),J=()=>{e.interactiveActionChoice$.next({subjectId:m,subjectType:h,subjectName:"control",type:N?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:T.args.shouldOpenNow,containerId:I,...T.args}})};if(N){z(),J();return}switch(T.type.trim().toLowerCase()){case b.EventActionTypes.setNextBranch.trim().toLowerCase():{let F=E.find(le=>le.id===T.args.branchId);if(!F)return;x(T.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),z(),J(),T.args.shouldOpenNow?w({subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{chapterId:F.chapterId,autoSelect:!1}}):n.add({...M,action:w.bind(null,{subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{chapterId:F.chapterId,autoSelect:!1}})});return}case b.EventActionTypes.continuePlayback.trim().toLowerCase():{x(T.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),z(),J(),T.args.shouldOpenNow?k({subjectId:m,subjectName:"control",subjectType:h,action:u}):n.add({...M,action:k.bind(null,{subjectId:m,subjectName:"control",subjectType:h,action:u})});return}case b.EventActionTypes.openURI.trim().toLowerCase():{x(T.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),z(),J(),T.args.shouldOpenNow?C({subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{URI:u.args.uri}}):n.add({...M,action:C.bind(null,{subjectId:m,subjectName:"control",subjectType:h,action:T,payload:{URI:u.args.uri}})});return}default:{let F="Unexpected control event",le=new O(1,1,{message:F});d(le,F);return}}},s=({action:u,container:{id:h,endTime:m},branches:I=[],isEOV:E=!1,autoSelected:x=!1})=>{let A=zr(u,E),$={timestamp:!A.args.shouldOpenNow||E?1/0:m??1/0,priority:"container",initiator:h,actionType:A.type},T=r.emit.bind(r,S.interactives,{subjectId:h,subjectName:"container",type:P.actionChoice,actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}}),M=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"container",type:"action-choice",actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}})};switch(A.type.trim().toLowerCase()){case b.EventActionTypes.setNextBranch.trim().toLowerCase():{let N=I.find(z=>z.id===A.args.branchId);if(!N)return;T(),M(),n.add({...$,action:w.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{chapterId:N.chapterId,autoSelect:x}})});return}case b.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():return;case b.EventActionTypes.setMinWeightBranch.trim().toLowerCase():return;case b.EventActionTypes.setRandomBranch.trim().toLowerCase():return;case b.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():return;case b.EventActionTypes.continuePlayback.trim().toLowerCase():{T(),M(),n.add({...$,action:k.bind(null,{subjectId:h,subjectName:"container",action:A})});return}case b.EventActionTypes.openURI.trim().toLowerCase():{T(),M(),n.add({...$,action:C.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{URI:u.args.uri}})});return}default:{let N="Unexpected container event",z=new O(1,1,{message:N});d(z,N);return}}};function a({container:u,branches:h,isEOV:m=!1}){let I=Lr(u.events);if(I){let E=zr(I.action,m);r.emit(S.interactives,{subjectId:u.id,subjectName:"container",type:P.actionChoice,actionType:E.type,payload:{invokeImmediately:E.args.shouldOpenNow,...E.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:E.type,payload:{invokeImmediately:E.args.shouldOpenNow,...E.args}}),n.add({timestamp:m?1/0:u.endTime??1/0,priority:"container",initiator:u.id,actionType:b.EventActionTypes.expect,action:v.bind(null,{subjectId:u.id,subjectName:"container"})}),i.isExpect=!0}else for(let E of u.events??[])s({action:E.action,container:u,branches:h,isEOV:m})}let c=({chapterId:u,action:h,branches:m=[]})=>{let I=r.emit.bind(r,S.interactives,{subjectId:u,subjectName:"chapter",type:P.actionChoice,actionType:h.type,payload:h.args}),E=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:h.type,payload:h.args})};switch(h.type.trim().toLowerCase()){case b.EventActionTypes.setNextBranch.trim().toLowerCase():{let x=m.find(A=>A.id===h.args.branchId);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():{let x=la(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setRandomBranch.trim().toLowerCase():{let x=ca(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():{let x=aa(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.setMinWeightBranch.trim().toLowerCase():{let x=sa(m);return x?.chapterId?(I(),E(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:x.chapterId,autoSelect:!0}})):void 0}case b.EventActionTypes.continuePlayback.trim().toLowerCase():return I(),E(),k.bind(null,{subjectId:u,subjectName:"chapter",action:h});case b.EventActionTypes.openURI.trim().toLowerCase():return I(),E(),C.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:{let x="Unexpected chapter event",A=new O(1,1,{message:x});d(A,x);return}}};function d(u,h){console.error(h),e.error$.next(u),r.emit(S.errors,u)}function f(u){let h=Lr(u.events);if(h){if(G(u))return;r.emit(S.interactives,{subjectId:u.id,subjectName:"chapter",type:P.actionChoice,actionType:h.action.type,payload:h.action.args}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"chapter",type:"action-choice",actionType:h.action.type,payload:h.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:b.EventActionTypes.expect,action:v.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else u.events?.forEach(m=>{let I=c({chapterId:u.id,action:m.action,branches:u.branches});I&&n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:m.action.type,action:I})})}let v=({subjectId:u,subjectName:h})=>{t.pause(),r.emit(S.interactives,{subjectId:u,subjectName:h,type:P.actionExecution,actionType:b.EventActionTypes.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:b.EventActionTypes.expect})},y=({subjectId:u,subjectName:h})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),r.emit(S.interactives,{subjectId:u,subjectName:h,type:P.actionExecution,actionType:ua}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:ua})},k=({subjectId:u,subjectName:h,subjectType:m,action:I})=>{r.emit(S.interactives,{subjectId:u,subjectName:h,subjectType:m,type:P.actionExecution,actionType:I.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:m,type:"action-execution",actionType:I.type})},w=({subjectId:u,subjectName:h,subjectType:m,action:I,payload:E})=>{E.behaviour="change-chapter",r.emit(S.interactives,{subjectId:u,subjectName:h,subjectType:m,type:P.actionExecution,actionType:I.type,payload:E}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:m,type:"action-execution",actionType:I.type,payload:E})},C=({subjectId:u,subjectName:h,subjectType:m,action:I,payload:E})=>{if(!E.URI)return;let x=window.open(E.URI,"_blank","noopener,noreferrer");x&&(x.opener=null),r.emit(S.interactives,{subjectId:u,subjectName:h,subjectType:m,type:P.actionExecution,actionType:I.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:m,type:"action-execution",actionType:I.type})};return{onControlEvent:l,onContainerEvent:s,onChapterEvent:c,onExpectEvent:v,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:a,stopExpect:o,state:i}};var Qr=D(wr(),1),q=require("@vkontakte/videoplayer-shared");var jt=(r,e)=>{let t={};return r.map(n=>{if(!t[n]){let i=e.chapters.find(l=>l.id===n);if(!i)return null;let o=e.media.videos.find(l=>i.videoId===l.id);if(!o)return null;t[n]=Wr(o)}return t[n]}).filter(Boolean)},da=r=>{for(let e of r.variants)if(ma(e)&&e.payload)return e.payload.id},ma=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Wr=r=>{let e=da(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},fa=(r,e)=>{for(let t of r.media.videos)if(e===Wr(t)){for(let n of r.chapters)if(n.videoId===t.id)return n.id;return}},Kr=(r,e)=>r.reduce((t,n)=>{let i=fa(e,n);return i?[...t,i]:t},[]);var Xe=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:i,settings:o}){this.state={history$:new q.ValueSubject([]),hasPrevChapter$:new q.ValueSubject(!1),prevChapter$:new q.ValueSubject(null),isInitialChapter$:new q.ValueSubject(!1),isGoBackLimited$:new q.ValueSubject(!1)};this.#r=null;this.#s=!1;this.#e=null;this.#p=null;this.events={inited$:new q.Subject,destroyed$:new q.Subject,error$:new q.Subject};this.#n=null;this.#i=null;this.#t=null;this.#a=new q.Subscription;this.#l=!1;this.#c=0;this.#n=t,this.#t=e,this.#i=n,this.#r=i,this.#o=o,this.state.history$&&this.#a&&this.#a?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,Qr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#o.maxLength-1)}))}#r;#o;#s;#e;#p;#n;#i;#t;#a;#l;#c;async setManifest(e){if(!this.#i||!this.#t)return;this.#e=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#i.setChapter({chapterId:t,pushToHistory:!1}),this.#s||(this.#s=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#s}async updateHistory(e,t=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,i=e.length-this.#o.maxLength,o=i>0?e.slice(i):e,l=jt(o,n);if(this.#p=l,this.state.history$.next(o),!(!t||!this.#r||!this.#n))try{await this.#r.save(this.#n,l)}catch{let a=new O(1,5,"Unable to save interactive history");this.events.error$.next(a),this.#t?.emit(S.errors,a)}}async goBack(){if(!this.state||!this.#i){let n=new O(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#t?.emit(S.errors,n)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#i.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#n)return;let e=this.#e,t=[this.getInitialVideoId()];if(this.#r)try{let i=await this.#r.get(this.#n);i.length&&(t=i)}catch{let o=new O(1,5,"Error while trying to fetch data");this.events.error$.next(o),this.#t?.emit(S.errors,o)}let n=Kr(t,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,Qr.default)(e,-1)||this.#o.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return jt([e],this.#e).pop()}return null}destroy(){this.#n=null,this.#r=null,this.#i=null,this.#a?.unsubscribe(),this.#a=null,this.#s=!1,this.#t?.emit(S.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var $t=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let i=3;i<n;i+=40)if(t[i]!==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(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.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){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var Ft=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??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;