@vkontakte/videoplayer-interactive 1.0.39-dev.e16aeacb.0 → 1.0.39-dev.f4da114d.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.
Files changed (28) hide show
  1. package/es2015.cjs.js +111 -10
  2. package/es2015.esm.js +111 -10
  3. package/es2018.cjs.js +111 -10
  4. package/es2018.esm.js +111 -10
  5. package/es2024.cjs.js +111 -10
  6. package/es2024.esm.js +111 -10
  7. package/esnext.cjs.js +111 -10
  8. package/esnext.esm.js +111 -10
  9. package/evergreen.esm.js +111 -10
  10. package/package.json +4 -4
  11. package/types/modules/Interactives/Interactives.d.ts +8 -4
  12. package/types/modules/Interactives/containers/ChoiceContainer.d.ts +9 -6
  13. package/types/modules/Interactives/containers/Container.d.ts +4 -0
  14. package/types/modules/Interactives/containers/types.d.ts +2 -1
  15. package/types/modules/Interactives/controls/AreaControl.d.ts +3 -1
  16. package/types/modules/Interactives/controls/ButtonControl.d.ts +8 -2
  17. package/types/modules/Interactives/controls/Control.d.ts +9 -4
  18. package/types/modules/Interactives/controls/TextControl.d.ts +2 -1
  19. package/types/modules/Interactives/controls/types.d.ts +1 -1
  20. package/types/modules/Interactives/index.d.ts +20 -5
  21. package/types/modules/Interactives/types.d.ts +3 -0
  22. package/types/modules/Interactives/utils/ControlFillAnimation/ControlFillAnimation.d.ts +34 -0
  23. package/types/modules/Interactives/utils/ControlFillAnimation/index.d.ts +1 -0
  24. package/types/modules/Interactives/utils/ControlFillAnimation/utils.d.ts +12 -0
  25. package/types/modules/Interactives/utils/GameController.d.ts +11 -4
  26. package/types/modules/Interactives/utils/angleUtils.d.ts +23 -0
  27. package/types/modules/Interactives/utils/emitOnError.d.ts +13 -0
  28. package/types/modules/Interactives/utils/gameUtils.d.ts +1 -0
package/es2018.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.39-dev.e16aeacb.0
3
- * Thu, 05 Jun 2025 13:19:16 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.39-dev.f4da114d.0
3
+ * Mon, 23 Jun 2025 13:02:02 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-39/doc/
5
5
  */
6
- var Ws=Object.create;var En=Object.defineProperty;var Ks=Object.getOwnPropertyDescriptor;var Qs=Object.getOwnPropertyNames;var Xs=Object.getPrototypeOf,Ys=Object.prototype.hasOwnProperty;var In=r=>{throw TypeError(r)};var h=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Zs=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Qs(e))!Ys.call(r,i)&&i!==t&&En(r,i,{get:()=>e[i],enumerable:!(n=Ks(e,i))||n.enumerable});return r};var Q=(r,e,t)=>(t=r!=null?Ws(Xs(r)):{},Zs(e||!r||!r.__esModule?En(t,"default",{value:r,enumerable:!0}):t,r));var xn=(r,e,t)=>e.has(r)||In("Cannot "+t);var S=(r,e,t)=>(xn(r,e,"read from private field"),t?t.call(r):e.get(r)),D=(r,e,t)=>e.has(r)?In("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),L=(r,e,t,n)=>(xn(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t);var Tn=(r,e,t,n)=>({set _(i){L(r,e,i,t)},get _(){return S(r,e,n)}});var Y=h((hr,jn)=>{"use strict";var Me=function(r){return r&&r.Math===Math&&r};jn.exports=Me(typeof globalThis=="object"&&globalThis)||Me(typeof window=="object"&&window)||Me(typeof self=="object"&&self)||Me(typeof global=="object"&&global)||Me(typeof hr=="object"&&hr)||function(){return this}()||Function("return this")()});var H=h((Xd,_n)=>{"use strict";_n.exports=function(r){try{return!!r()}catch(e){return!0}}});var Le=h((Yd,$n)=>{"use strict";var ll=H();$n.exports=!ll(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Hn=h((Zd,Dn)=>{"use strict";var cl=Le(),qn=Function.prototype,Fn=qn.apply,Bn=qn.call;Dn.exports=typeof Reflect=="object"&&Reflect.apply||(cl?Bn.bind(Fn):function(){return Bn.apply(Fn,arguments)})});var z=h((Jd,zn)=>{"use strict";var Un=Le(),Gn=Function.prototype,dr=Gn.call,ul=Un&&Gn.bind.bind(dr,dr);zn.exports=Un?ul:function(r){return function(){return dr.apply(r,arguments)}}});var Ne=h((em,Kn)=>{"use strict";var Wn=z(),pl=Wn({}.toString),hl=Wn("".slice);Kn.exports=function(r){return hl(pl(r),8,-1)}});var mr=h((tm,Qn)=>{"use strict";var dl=Ne(),ml=z();Qn.exports=function(r){if(dl(r)==="Function")return ml(r)}});var U=h((rm,Xn)=>{"use strict";var fr=typeof document=="object"&&document.all;Xn.exports=typeof fr=="undefined"&&fr!==void 0?function(r){return typeof r=="function"||r===fr}:function(r){return typeof r=="function"}});var ce=h((nm,Yn)=>{"use strict";var fl=H();Yn.exports=!fl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Et=h((im,Zn)=>{"use strict";var vl=Le(),gt=Function.prototype.call;Zn.exports=vl?gt.bind(gt):function(){return gt.apply(gt,arguments)}});var vr=h(ti=>{"use strict";var Jn={}.propertyIsEnumerable,ei=Object.getOwnPropertyDescriptor,yl=ei&&!Jn.call({1:2},1);ti.f=yl?function(e){var t=ei(this,e);return!!t&&t.enumerable}:Jn});var yr=h((am,ri)=>{"use strict";ri.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var ii=h((sm,ni)=>{"use strict";var bl=z(),Cl=H(),gl=Ne(),br=Object,El=bl("".split);ni.exports=Cl(function(){return!br("z").propertyIsEnumerable(0)})?function(r){return gl(r)==="String"?El(r,""):br(r)}:br});var Cr=h((lm,oi)=>{"use strict";oi.exports=function(r){return r==null}});var gr=h((cm,ai)=>{"use strict";var Il=Cr(),xl=TypeError;ai.exports=function(r){if(Il(r))throw new xl("Can't call method on "+r);return r}});var je=h((um,si)=>{"use strict";var Tl=ii(),Sl=gr();si.exports=function(r){return Tl(Sl(r))}});var Ce=h((pm,li)=>{"use strict";var wl=U();li.exports=function(r){return typeof r=="object"?r!==null:wl(r)}});var It=h((hm,ci)=>{"use strict";ci.exports={}});var xt=h((dm,pi)=>{"use strict";var Er=It(),Ir=Y(),Al=U(),ui=function(r){return Al(r)?r:void 0};pi.exports=function(r,e){return arguments.length<2?ui(Er[r])||ui(Ir[r]):Er[r]&&Er[r][e]||Ir[r]&&Ir[r][e]}});var di=h((mm,hi)=>{"use strict";var Rl=z();hi.exports=Rl({}.isPrototypeOf)});var yi=h((fm,vi)=>{"use strict";var kl=Y(),mi=kl.navigator,fi=mi&&mi.userAgent;vi.exports=fi?String(fi):""});var Ti=h((vm,xi)=>{"use strict";var Ii=Y(),xr=yi(),bi=Ii.process,Ci=Ii.Deno,gi=bi&&bi.versions||Ci&&Ci.version,Ei=gi&&gi.v8,W,Tt;Ei&&(W=Ei.split("."),Tt=W[0]>0&&W[0]<4?1:+(W[0]+W[1]));!Tt&&xr&&(W=xr.match(/Edge\/(\d+)/),(!W||W[1]>=74)&&(W=xr.match(/Chrome\/(\d+)/),W&&(Tt=+W[1])));xi.exports=Tt});var Tr=h((ym,wi)=>{"use strict";var Si=Ti(),Ol=H(),Pl=Y(),Vl=Pl.String;wi.exports=!!Object.getOwnPropertySymbols&&!Ol(function(){var r=Symbol("symbol detection");return!Vl(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Si&&Si<41})});var Sr=h((bm,Ai)=>{"use strict";var Ml=Tr();Ai.exports=Ml&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var wr=h((Cm,Ri)=>{"use strict";var Ll=xt(),Nl=U(),jl=di(),_l=Sr(),$l=Object;Ri.exports=_l?function(r){return typeof r=="symbol"}:function(r){var e=Ll("Symbol");return Nl(e)&&jl(e.prototype,$l(r))}});var Oi=h((gm,ki)=>{"use strict";var Fl=String;ki.exports=function(r){try{return Fl(r)}catch(e){return"Object"}}});var Ar=h((Em,Pi)=>{"use strict";var Bl=U(),ql=Oi(),Dl=TypeError;Pi.exports=function(r){if(Bl(r))return r;throw new Dl(ql(r)+" is not a function")}});var Mi=h((Im,Vi)=>{"use strict";var Hl=Ar(),Ul=Cr();Vi.exports=function(r,e){var t=r[e];return Ul(t)?void 0:Hl(t)}});var Ni=h((xm,Li)=>{"use strict";var Rr=Et(),kr=U(),Or=Ce(),Gl=TypeError;Li.exports=function(r,e){var t,n;if(e==="string"&&kr(t=r.toString)&&!Or(n=Rr(t,r))||kr(t=r.valueOf)&&!Or(n=Rr(t,r))||e!=="string"&&kr(t=r.toString)&&!Or(n=Rr(t,r)))return n;throw new Gl("Can't convert object to primitive value")}});var _i=h((Tm,ji)=>{"use strict";ji.exports=!0});var Bi=h((Sm,Fi)=>{"use strict";var $i=Y(),zl=Object.defineProperty;Fi.exports=function(r,e){try{zl($i,r,{value:e,configurable:!0,writable:!0})}catch(t){$i[r]=e}return e}});var St=h((wm,Hi)=>{"use strict";var Wl=_i(),Kl=Y(),Ql=Bi(),qi="__core-js_shared__",Di=Hi.exports=Kl[qi]||Ql(qi,{});(Di.versions||(Di.versions=[])).push({version:"3.38.0",mode:Wl?"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 Pr=h((Am,Gi)=>{"use strict";var Ui=St();Gi.exports=function(r,e){return Ui[r]||(Ui[r]=e||{})}});var _e=h((Rm,zi)=>{"use strict";var Xl=gr(),Yl=Object;zi.exports=function(r){return Yl(Xl(r))}});var ge=h((km,Wi)=>{"use strict";var Zl=z(),Jl=_e(),ec=Zl({}.hasOwnProperty);Wi.exports=Object.hasOwn||function(e,t){return ec(Jl(e),t)}});var Vr=h((Om,Ki)=>{"use strict";var tc=z(),rc=0,nc=Math.random(),ic=tc(1 .toString);Ki.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+ic(++rc+nc,36)}});var $e=h((Pm,Xi)=>{"use strict";var oc=Y(),ac=Pr(),Qi=ge(),sc=Vr(),lc=Tr(),cc=Sr(),Ee=oc.Symbol,Mr=ac("wks"),uc=cc?Ee.for||Ee:Ee&&Ee.withoutSetter||sc;Xi.exports=function(r){return Qi(Mr,r)||(Mr[r]=lc&&Qi(Ee,r)?Ee[r]:uc("Symbol."+r)),Mr[r]}});var eo=h((Vm,Ji)=>{"use strict";var pc=Et(),Yi=Ce(),Zi=wr(),hc=Mi(),dc=Ni(),mc=$e(),fc=TypeError,vc=mc("toPrimitive");Ji.exports=function(r,e){if(!Yi(r)||Zi(r))return r;var t=hc(r,vc),n;if(t){if(e===void 0&&(e="default"),n=pc(t,r,e),!Yi(n)||Zi(n))return n;throw new fc("Can't convert object to primitive value")}return e===void 0&&(e="number"),dc(r,e)}});var Lr=h((Mm,to)=>{"use strict";var yc=eo(),bc=wr();to.exports=function(r){var e=yc(r,"string");return bc(e)?e:e+""}});var io=h((Lm,no)=>{"use strict";var Cc=Y(),ro=Ce(),Nr=Cc.document,gc=ro(Nr)&&ro(Nr.createElement);no.exports=function(r){return gc?Nr.createElement(r):{}}});var jr=h((Nm,oo)=>{"use strict";var Ec=ce(),Ic=H(),xc=io();oo.exports=!Ec&&!Ic(function(){return Object.defineProperty(xc("div"),"a",{get:function(){return 7}}).a!==7})});var lo=h(so=>{"use strict";var Tc=ce(),Sc=Et(),wc=vr(),Ac=yr(),Rc=je(),kc=Lr(),Oc=ge(),Pc=jr(),ao=Object.getOwnPropertyDescriptor;so.f=Tc?ao:function(e,t){if(e=Rc(e),t=kc(t),Pc)try{return ao(e,t)}catch(n){}if(Oc(e,t))return Ac(!Sc(wc.f,e,t),e[t])}});var uo=h((_m,co)=>{"use strict";var Vc=H(),Mc=U(),Lc=/#|\.prototype\./,Fe=function(r,e){var t=jc[Nc(r)];return t===$c?!0:t===_c?!1:Mc(e)?Vc(e):!!e},Nc=Fe.normalize=function(r){return String(r).replace(Lc,".").toLowerCase()},jc=Fe.data={},_c=Fe.NATIVE="N",$c=Fe.POLYFILL="P";co.exports=Fe});var _r=h(($m,ho)=>{"use strict";var po=mr(),Fc=Ar(),Bc=Le(),qc=po(po.bind);ho.exports=function(r,e){return Fc(r),e===void 0?r:Bc?qc(r,e):function(){return r.apply(e,arguments)}}});var fo=h((Fm,mo)=>{"use strict";var Dc=ce(),Hc=H();mo.exports=Dc&&Hc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var yo=h((Bm,vo)=>{"use strict";var Uc=Ce(),Gc=String,zc=TypeError;vo.exports=function(r){if(Uc(r))return r;throw new zc(Gc(r)+" is not an object")}});var go=h(Co=>{"use strict";var Wc=ce(),Kc=jr(),Qc=fo(),wt=yo(),bo=Lr(),Xc=TypeError,$r=Object.defineProperty,Yc=Object.getOwnPropertyDescriptor,Fr="enumerable",Br="configurable",qr="writable";Co.f=Wc?Qc?function(e,t,n){if(wt(e),t=bo(t),wt(n),typeof e=="function"&&t==="prototype"&&"value"in n&&qr in n&&!n[qr]){var i=Yc(e,t);i&&i[qr]&&(e[t]=n.value,n={configurable:Br in n?n[Br]:i[Br],enumerable:Fr in n?n[Fr]:i[Fr],writable:!1})}return $r(e,t,n)}:$r:function(e,t,n){if(wt(e),t=bo(t),wt(n),Kc)try{return $r(e,t,n)}catch(i){}if("get"in n||"set"in n)throw new Xc("Accessors not supported");return"value"in n&&(e[t]=n.value),e}});var Io=h((Dm,Eo)=>{"use strict";var Zc=ce(),Jc=go(),eu=yr();Eo.exports=Zc?function(r,e,t){return Jc.f(r,e,eu(1,t))}:function(r,e,t){return r[e]=t,r}});var qe=h((Hm,To)=>{"use strict";var Be=Y(),tu=Hn(),ru=mr(),nu=U(),iu=lo().f,ou=uo(),Ie=It(),au=_r(),xe=Io(),xo=ge();St();var su=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 tu(r,this,arguments)};return e.prototype=r.prototype,e};To.exports=function(r,e){var t=r.target,n=r.global,i=r.stat,o=r.proto,a=n?Be:i?Be[t]:Be[t]&&Be[t].prototype,l=n?Ie:Ie[t]||xe(Ie,t,{})[t],s=l.prototype,c,m,f,v,C,T,E,d,p;for(v in e)c=ou(n?v:t+(i?".":"#")+v,r.forced),m=!c&&a&&xo(a,v),T=l[v],m&&(r.dontCallGetSet?(p=iu(a,v),E=p&&p.value):E=a[v]),C=m&&E?E:e[v],!(!c&&!o&&typeof T==typeof C)&&(r.bind&&m?d=au(C,Be):r.wrap&&m?d=su(C):o&&nu(C)?d=ru(C):d=C,(r.sham||C&&C.sham||T&&T.sham)&&xe(d,"sham",!0),xe(l,v,d),o&&(f=t+"Prototype",xo(Ie,f)||xe(Ie,f,{}),xe(Ie[f],v,C),r.real&&s&&(c||!s[v])&&xe(s,v,C)))}});var wo=h((Um,So)=>{"use strict";var lu=Math.ceil,cu=Math.floor;So.exports=Math.trunc||function(e){var t=+e;return(t>0?cu:lu)(t)}});var De=h((Gm,Ao)=>{"use strict";var uu=wo();Ao.exports=function(r){var e=+r;return e!==e||e===0?0:uu(e)}});var ko=h((zm,Ro)=>{"use strict";var pu=De(),hu=Math.min;Ro.exports=function(r){var e=pu(r);return e>0?hu(e,9007199254740991):0}});var He=h((Wm,Oo)=>{"use strict";var du=ko();Oo.exports=function(r){return du(r.length)}});var At=h((Km,Po)=>{"use strict";Po.exports=function(){}});var Vo=h(()=>{"use strict";var mu=qe(),fu=_e(),vu=He(),yu=De(),bu=At();mu({target:"Array",proto:!0},{at:function(e){var t=fu(this),n=vu(t),i=yu(e),o=i>=0?i:n+i;return o<0||o>=n?void 0:t[o]}});bu("at")});var Rt=h((Ym,Mo)=>{"use strict";var Cu=xt();Mo.exports=Cu});var No=h((Zm,Lo)=>{"use strict";Vo();var gu=Rt();Lo.exports=gu("Array","at")});var _o=h((Jm,jo)=>{"use strict";var Eu=No();jo.exports=Eu});var Dr=h((ef,$o)=>{"use strict";var Iu=_o();$o.exports=Iu});var Qo=h((Yf,Ko)=>{"use strict";var Pu=De(),Vu=Math.max,Mu=Math.min;Ko.exports=function(r,e){var t=Pu(r);return t<0?Vu(t+e,0):Mu(t,e)}});var Kr=h((Zf,Yo)=>{"use strict";var Lu=je(),Nu=Qo(),ju=He(),Xo=function(r){return function(e,t,n){var i=Lu(e),o=ju(i);if(o===0)return!r&&-1;var a=Nu(n,o),l;if(r&&t!==t){for(;o>a;)if(l=i[a++],l!==l)return!0}else for(;o>a;a++)if((r||a in i)&&i[a]===t)return r||a||0;return!r&&-1}};Yo.exports={includes:Xo(!0),indexOf:Xo(!1)}});var Zo=h(()=>{"use strict";var _u=qe(),$u=Kr().includes,Fu=H(),Bu=At(),qu=Fu(function(){return!Array(1).includes()});_u({target:"Array",proto:!0,forced:qu},{includes:function(e){return $u(this,e,arguments.length>1?arguments[1]:void 0)}});Bu("includes")});var ea=h((tv,Jo)=>{"use strict";Zo();var Du=Rt();Jo.exports=Du("Array","includes")});var ra=h((rv,ta)=>{"use strict";var Hu=ea();ta.exports=Hu});var Xe=h((nv,na)=>{"use strict";var Uu=ra();na.exports=Uu});var ua=h((mv,ca)=>{"use strict";var Wu=Pr(),Ku=Vr(),la=Wu("keys");ca.exports=function(r){return la[r]||(la[r]=Ku(r))}});var ha=h((fv,pa)=>{"use strict";var Qu=H();pa.exports=!Qu(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var fa=h((vv,ma)=>{"use strict";var Xu=ge(),Yu=U(),Zu=_e(),Ju=ua(),ep=ha(),da=Ju("IE_PROTO"),Yr=Object,tp=Yr.prototype;ma.exports=ep?Yr.getPrototypeOf:function(r){var e=Zu(r);if(Xu(e,da))return e[da];var t=e.constructor;return Yu(t)&&e instanceof t?t.prototype:e instanceof Yr?tp:null}});var ya=h((yv,va)=>{"use strict";va.exports={}});var ga=h((bv,Ca)=>{"use strict";var rp=z(),Zr=ge(),np=je(),ip=Kr().indexOf,op=ya(),ba=rp([].push);Ca.exports=function(r,e){var t=np(r),n=0,i=[],o;for(o in t)!Zr(op,o)&&Zr(t,o)&&ba(i,o);for(;e.length>n;)Zr(t,o=e[n++])&&(~ip(i,o)||ba(i,o));return i}});var Ia=h((Cv,Ea)=>{"use strict";Ea.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var Ta=h((gv,xa)=>{"use strict";var ap=ga(),sp=Ia();xa.exports=Object.keys||function(e){return ap(e,sp)}});var Oa=h((Ev,ka)=>{"use strict";var wa=ce(),lp=H(),Aa=z(),cp=fa(),up=Ta(),pp=je(),hp=vr().f,Ra=Aa(hp),dp=Aa([].push),mp=wa&&lp(function(){var r=Object.create(null);return r[2]=2,!Ra(r,2)}),Sa=function(r){return function(e){for(var t=pp(e),n=up(t),i=mp&&cp(t)===null,o=n.length,a=0,l=[],s;o>a;)s=n[a++],(!wa||(i?s in t:Ra(t,s)))&&dp(l,r?[s,t[s]]:t[s]);return l}};ka.exports={entries:Sa(!0),values:Sa(!1)}});var Pa=h(()=>{"use strict";var fp=qe(),vp=Oa().values;fp({target:"Object",stat:!0},{values:function(e){return vp(e)}})});var Ma=h((Tv,Va)=>{"use strict";Pa();var yp=It();Va.exports=yp.Object.values});var Na=h((Sv,La)=>{"use strict";var bp=Ma();La.exports=bp});var Dt=h((wv,ja)=>{"use strict";var Cp=Na();ja.exports=Cp});var on=h((Xv,Ha)=>{"use strict";var Sp=Ne();Ha.exports=Array.isArray||function(e){return Sp(e)==="Array"}});var Ga=h((Yv,Ua)=>{"use strict";var wp=TypeError,Ap=9007199254740991;Ua.exports=function(r){if(r>Ap)throw wp("Maximum allowed index exceeded");return r}});var Ka=h((Zv,Wa)=>{"use strict";var Rp=on(),kp=He(),Op=Ga(),Pp=_r(),za=function(r,e,t,n,i,o,a,l){for(var s=i,c=0,m=a?Pp(a,l):!1,f,v;c<n;)c in t&&(f=m?m(t[c],c,e):t[c],o>0&&Rp(f)?(v=kp(f),s=za(r,e,f,v,s,o-1)-1):(Op(s+1),r[s]=f),s++),c++;return s};Wa.exports=za});var Ya=h((Jv,Xa)=>{"use strict";var Vp=$e(),Mp=Vp("toStringTag"),Qa={};Qa[Mp]="z";Xa.exports=String(Qa)==="[object z]"});var Ja=h((ey,Za)=>{"use strict";var Lp=Ya(),Np=U(),Ut=Ne(),jp=$e(),_p=jp("toStringTag"),$p=Object,Fp=Ut(function(){return arguments}())==="Arguments",Bp=function(r,e){try{return r[e]}catch(t){}};Za.exports=Lp?Ut:function(r){var e,t,n;return r===void 0?"Undefined":r===null?"Null":typeof(t=Bp(e=$p(r),_p))=="string"?t:Fp?Ut(e):(n=Ut(e))==="Object"&&Np(e.callee)?"Arguments":n}});var ts=h((ty,es)=>{"use strict";var qp=z(),Dp=U(),an=St(),Hp=qp(Function.toString);Dp(an.inspectSource)||(an.inspectSource=function(r){return Hp(r)});es.exports=an.inspectSource});var ss=h((ry,as)=>{"use strict";var Up=z(),Gp=H(),rs=U(),zp=Ja(),Wp=xt(),Kp=ts(),ns=function(){},is=Wp("Reflect","construct"),sn=/^\s*(?:class|function)\b/,Qp=Up(sn.exec),Xp=!sn.test(ns),et=function(e){if(!rs(e))return!1;try{return is(ns,[],e),!0}catch(t){return!1}},os=function(e){if(!rs(e))return!1;switch(zp(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Xp||!!Qp(sn,Kp(e))}catch(t){return!0}};os.sham=!0;as.exports=!is||Gp(function(){var r;return et(et.call)||!et(Object)||!et(function(){r=!0})||r})?os:et});var ps=h((ny,us)=>{"use strict";var ls=on(),Yp=ss(),Zp=Ce(),Jp=$e(),eh=Jp("species"),cs=Array;us.exports=function(r){var e;return ls(r)&&(e=r.constructor,Yp(e)&&(e===cs||ls(e.prototype))?e=void 0:Zp(e)&&(e=e[eh],e===null&&(e=void 0))),e===void 0?cs:e}});var ds=h((iy,hs)=>{"use strict";var th=ps();hs.exports=function(r,e){return new(th(r))(e===0?0:e)}});var ms=h(()=>{"use strict";var rh=qe(),nh=Ka(),ih=_e(),oh=He(),ah=De(),sh=ds();rh({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=ih(this),n=oh(t),i=sh(t,0);return i.length=nh(i,t,t,n,0,e===void 0?1:ah(e)),i}})});var fs=h(()=>{"use strict";var lh=At();lh("flat")});var ys=h((cy,vs)=>{"use strict";ms();fs();var ch=Rt();vs.exports=ch("Array","flat")});var Cs=h((uy,bs)=>{"use strict";var uh=ys();bs.exports=uh});var Es=h((py,gs)=>{"use strict";var ph=Cs();gs.exports=ph});var Sn="1.0.39-dev.e16aeacb.0";import{Subject as al,Subscription as sl}from"@vkontakte/videoplayer-shared/es2018";var Yt=class{constructor(e){this.layout=e}},ot=class extends Yt{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} + ${2e-4}))`,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 wn(r){return"features"in r}var ve=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&wn(this.options)&&this.options.features[e]}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){var e;return((e=this.container.controls)==null?void 0:e.reduce((t,n)=>{let i=n.type.trim().toLowerCase(),o=this.factories.get(i);if(o){let a=o(n,this.options);if(a)return[...t,a]}return[...t]},[]))||[]}};import{fromEvent as mt,once as il}from"@vkontakte/videoplayer-shared/es2018";var ne=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,ie=r=>ne(r,"Object"),at=r=>ne(r,"String"),st=r=>ne(r,"Array"),lt=r=>ne(r,"Number"),An=r=>ne(r,"Function"),Rn=r=>ne(r,"Boolean"),Zt=r=>lt(r)&&!isNaN(r);var se=r=>ie(r)&&Object.keys(r).length===0,Jt=r=>st(r)&&!r.length;var Oe=(r,e)=>at(r)&&(e?r.trim():r).length;function Pe(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 kn="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},On=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(On||{}),Pn=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(Pn||{}),Vn=(n=>(n.start="left",n.end="right",n.center="center",n))(Vn||{}),ct=({target:r,props:e})=>{var t,n,i;r.style.alignItems=(t=(e==null?void 0:e.gravityVertical)&&On[e.gravityVertical])!=null?t:"center",r.style.justifyContent=(n=(e==null?void 0:e.gravityHorizontal)&&Pn[e.gravityHorizontal])!=null?n:"center",r.style.textAlign=(i=(e==null?void 0:e.alignment)&&Vn[e.alignment])!=null?i:"center"},ut=({target:r,props:e,fallback:t,dependsOn:n})=>{var i,o,a,l,s,c;r.style.color=(o=(i=e==null?void 0:e.text)==null?void 0:i.color)!=null?o:t.textColor,r.style.fontSize=`calc(${n.height} * ${(l=(a=e==null?void 0:e.text)==null?void 0:a.size)!=null?l:t.textSize})`,r.textContent=(c=(s=e==null?void 0:e.text)==null?void 0:s.value)!=null?c:t.textContent},pt=({target:r,props:e,fallback:t})=>{var n,i,o,a;r.style.backgroundColor=Pe((i=(n=e==null?void 0:e.background)==null?void 0:n.color)!=null?i:t.backgroundColor,(a=(o=e==null?void 0:e.background)==null?void 0:o.alpha)!=null?a:t.backgroundAlpha)},Ve=({target:r,props:e,fallback:t,dependsOn:n,useRawValues:i=!1})=>{var l,s,c,m,f,v,C,T,E,d,p;let o=i?t.borderWidthRawValue:`calc(${n.height} * ${(c=(s=(l=e==null?void 0:e.shape)==null?void 0:l.border)==null?void 0:s.width)!=null?c:t.borderWidth})`,a=i?t.roundCornersRawValue:`calc(${n.height} * ${(f=(m=e==null?void 0:e.shape)==null?void 0:m.roundCorners)!=null?f:t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Pe(i?t.borderColor:(T=(C=(v=e==null?void 0:e.shape)==null?void 0:v.border)==null?void 0:C.color)!=null?T:t.borderColor,i?t.borderAlpha:(p=(d=(E=e==null?void 0:e.shape)==null?void 0:E.border)==null?void 0:d.alpha)!=null?p:t.borderAlpha),r.style.borderRadius=a},Mn=({target:r,isDark:e,baseDimension:t,fallback:n})=>{let a=Pe(n.shadowColorLight,n.shadowColorAlpha),l=Pe(n.shadowColorDark,n.shadowColorAlpha),s=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,m=`0px 0px ${s} ${c} ${e?l:a}`;r.style.boxShadow=m},ye=({target:r,layoutParams:e,fallback:t})=>{var i;let n=(i=e.angle)!=null?i:t.angle;n=n&&n*-1,r.style.transform=`rotate(${n}rad)`};import{fromEvent as nr,Subject as tl,Subscription as rl,ValueSubject as nl}from"@vkontakte/videoplayer-shared/es2018";var er="interactive-control-tap",be={common:er,animation:`${er}-animation`,visible:`${er}-visible`};var Js=60,ht=class{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=Js,useDimensionsBasedSize:i=!1}){this.onElementClick=e=>{if(!e.target||!e.currentTarget||this.clickCancelCondition())return;let t=e.currentTarget.parentElement;if(!t)return;let n=t.getBoundingClientRect(),i={width:this.useDimensionsBasedSize?t.offsetWidth:this.circleDiameterPx,height:this.useDimensionsBasedSize?t.offsetHeight:this.circleDiameterPx},o=Math.min(i.width,i.height),a=n.left+n.width/2,l=n.top+n.height/2,s=e.clientX-a,c=e.clientY-l,m=el(s,c,this.controlRotateAngleRad);this.element.style.width=o+"px",this.element.style.left=m.x+n.width/2-o/2+"px",this.element.style.top=m.y+n.height/2-o/2+"px",this.element.classList.add(be.visible,be.animation)};this.onAnimationEnd=e=>{!e.target||!e.currentTarget||e.target===e.currentTarget&&this.element.classList.remove(be.visible,be.animation)};let o=document.createElement("div");o.classList.add(be.common),this.controlRotateAngleRad=e,this.element=o,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=i}};function el(r,e,t){return{x:r*Math.cos(t)-e*Math.sin(t),y:r*Math.sin(t)+e*Math.cos(t)}}var tr="int",le=(n=>(n.AREA=`${tr}_area`,n.TEXT=`${tr}_text`,n.BUTTON=`${tr}_bttn`,n))(le||{});function rr(r){return"features"in r}var X="interactive-control",k={common:X,selected:`${X}-selected`,wrapper:`${X}-wrapper`,disabled:`${X}-disabled`,button:`${X}-button`,area:`${X}-area`,text:`${X}-text`,blinkAnim:`${X}-blink-anim`,blinkAnimButton:`${X}-blink-anim-button`,blinkAnimArea:`${X}-blink-anim-area`},Ln=40;var N=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var oe=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new rl;this.error$=new tl;this.isInteracted$=new nl(!1)}onError(e="",t){let n=new N(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(n)}addControlTap(e){var t;if(this.featureIsEnabled("controlsTapPlace")&&this.container){let n=(t=this.control.layoutParams.angle)!=null?t:V.angle;this.controlTap=new ht({controlRotateAngleRad:n,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?Ln:void 0}),this.subscriptions.add(nr(e,"click").subscribe(this.controlTap.onElementClick,i=>this.onError("Control click tap animation error",i))).add(nr(this.controlTap.element,"animationend").subscribe(this.controlTap.onAnimationEnd,i=>this.onError("Tap animationend error",i))),this.container.element.append(this.controlTap.element)}}createContainerElement(e){var o;let t=document.createElement("div");t.classList.add(k.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=((o=this.control.layoutParams.innerSizesDependOn)!=null?o:V.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"},i=()=>{var a,l;return(l=(a=e.isContainerDisabled)==null?void 0:a.call(e))!=null?l:!1};this.container={element:t,dimensions:n,isManifestContainerDisabled:i}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted$.next(!0),e()}}featureIsEnabled(e){return this.options&&rr(this.options)&&this.options.features[e]}isTouch(){return this.options&&rr(this.options)&&this.options.isTouch}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(nr(this.container.element,"click").subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),i=>this.onError("Error happened on control interaction",i)));break}default:break}})}removeListeners(){this.subscriptions.unsubscribe()}};var ar="interactive-blink-anim-reference",_={common:ar,animation:`${ar}-animation`,disabled:`${ar}-disabled`},dt=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(_.common,_.animation),this._element=e}restart(){this._element&&(this._element.classList.add(_.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(_.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var sr="interactive-container",$={common:sr,hidden:`${sr}-hidden`,disabled:`${sr}-disabled`};var ft=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new lr(r,e)},lr=class extends oe{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(k.common,k.area),n.setAttribute("data-testid",le.AREA),pt({target:n,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),ye({target:n,layoutParams:this.control.layoutParams,fallback:V}),this.addControlTap(n),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.updateShadowStyles(),this.registerEvents()}registerEvents(){var t;if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=(t=this.container)==null?void 0:t.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(mt(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains($.disabled))return;let n=e.parentElement;if(n){let i=n.querySelector(`.${_.common}`);i&&this.syncBlinkAnimation(i)}},n=>this.onError("Error happened in mouseleave callback",n))),this.subscriptions.add(mt(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains($.disabled)||this.onBlinkHovering()},n=>this.onError("Error happened in mouseenter callback",n))).add(mt(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},n=>this.onError("Error happened in mouseleave callback",n))))}disable(){this.controlElement&&this.controlElement.classList.add(k.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(k.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){var t,n,i;if(!(!this.container||!this.controlElement))if(Rn(e)){let o=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";Mn({target:this.controlElement,props:this.control.props,fallback:V,isDark:e,baseDimension:o}),Ve({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} * ${(i=(n=(t=this.control.props)==null?void 0:t.shape)==null?void 0:n.roundCorners)!=null?i:V.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Ve({target:this.controlElement,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){var t,n;(t=this.controlElement)==null||t.classList.toggle(k.blinkAnim,e),(n=this.controlElement)==null||n.classList.toggle(k.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${k.blinkAnimArea}`)||this.controlElement.classList.contains(k.selected)||this.controlElement.classList.contains(_.disabled)||(this.controlElement.classList.add(_.disabled),this.subscriptions.add(mt(e,"animationiteration").pipe(il()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(_.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${k.blinkAnimArea}`)||this.controlElement.classList.contains(k.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)})}onProgress(){}onResize(){}};import{fromEvent as yt,once as ol}from"@vkontakte/videoplayer-shared/es2018";var vt=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 bt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new cr(r,e)},cr=class extends oe{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var a;if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(k.common,k.button),n.setAttribute("data-testid",le.BUTTON),ye({target:n,layoutParams:this.control.layoutParams,fallback:V}),pt({target:n,props:this.control.props,fallback:V}),Ve({target:n,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),ct({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=vt(this.control.type.trim().toLowerCase()),o=(a=i.firstElementChild)!=null?a:i;ut({target:o,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),this.addControlTap(n),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.registerEvents()}registerEvents(){var t;if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=(t=this.container)==null?void 0:t.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(yt(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains($.disabled))return;let n=e.parentElement;if(n){let i=n.querySelector(`.${_.common}`);i&&this.syncBlinkAnimation(i)}},n=>this.onError("Error happened in mouseleave callback",n))),this.subscriptions.add(yt(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains($.disabled)||this.onBlinkHovering()},n=>this.onError("Error happened in mouseenter callback",n))).add(yt(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},n=>this.onError("Error happened in mouseleave callback",n))))}disable(){this.controlElement&&this.controlElement.classList.add(k.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(k.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){var t,n;(t=this.controlElement)==null||t.classList.toggle(k.blinkAnim,e),(n=this.controlElement)==null||n.classList.toggle(k.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${k.blinkAnimButton}`)||this.controlElement.classList.contains(k.selected)||this.controlElement.classList.contains(_.disabled)||(this.controlElement.classList.add(_.disabled),this.subscriptions.add(yt(e,"animationiteration").pipe(ol()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(_.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${k.blinkAnimButton}`)||this.controlElement.classList.contains(k.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)})}onProgress(){}onResize(){}updateShadowStyles(){}};var Nn=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new ur(r,e)},ur=class extends oe{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var a;if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(k.common,k.text),n.setAttribute("data-testid",le.TEXT),ye({target:n,layoutParams:this.control.layoutParams,fallback:V}),ct({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=vt(this.control.type.trim().toLowerCase()),o=(a=i.firstElementChild)!=null?a:i;ut({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 Ct=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new pr(r,e,t)},pr=class extends ve{constructor(t,n,i){super(t,i);this.containerElement=null;this.controlSubscriptions=new sl;this.error$=new al;this.rootElement=n,this.layout=new ot(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",bt),this.addControlFactory("text",Nn),this.addControlFactory("area",ft)}createView({eventCallback:t}){let n=document.createElement("div");return n.classList.add($.common,$.disabled),requestAnimationFrame(()=>{n.classList.remove($.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout,isContainerDisabled:()=>this.isDisabled}}),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($.hidden)}show(){let t=this.getElement();t&&t.classList.remove($.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove($.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add($.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 Gs=Q(Dr(),1);import{combine as xh,InterfaceLanguage as Th,Observable as Ds,once as Sh,Subject as F,Subscription as dn,ValueSubject as q,fromEvent as Hs}from"@vkontakte/videoplayer-shared/es2018";import{InteractiveInterfaceClick as nt}from"@vkontakte/videoplayer-statistics/es2018";import{loadVKLangPack as xu}from"@vkontakte/videoplayer-shared/es2018";function Ue(r,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>r(...n),e)}}var Fo="video_interactive",Bo="videoint";var qo=250,Ge=class{constructor(e){this.handleZoomChange=Ue(e=>{this.lastZoomInfo=e},qo);this.onResize=e=>{var n;if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&((n=this.ngEditor)==null||n.zoomTo(t,void 0,{isFromCenter:!0})),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{var t,n,i;if(this.manifest){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.call(this,"Chapter id is not found");return}this.visitedChapterIds.add(e.id),(n=this.ngEditor)==null||n.selectChapter(e.id),(i=this.ngEditor)==null||i.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{var n;if(this.isReady=!1,!lt(e.graph.edit.chapters[0].x)){(n=this.onError)==null||n.call(this,"Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:i,visitedChapters:o=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(o),this.onOpenPreviewClick=t,this.onError=n,this.lang=i!=null?i:"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Tu(e),this.resizeObserver=new ResizeObserver(Ue(this.onResize,qo)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){var t;this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),(t=this.ngEditor)==null||t.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){var t;(t=this.ngEditor)==null||t.updateVideosInfo(e)}async show(){var e;this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&((e=this.ngEditor)==null||e.focusChapter(this.currentChapterId)),this.isHidden=!1)}async initNgEditor(){var n;if(!this.manifest)return;let e;try{e=await xu(this.lang,Fo,Bo)}catch(i){(n=this.onError)==null||n.call(this,"Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"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:i,...o})=>{var a;i==="openPreview"&&"chapterId"in o&&((a=this.onOpenPreviewClick)==null||a.call(this,o.chapterId))}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.manifest=null,this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Tu(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 ze=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 a=o.startTime-e;if(a<=i&&(o.endTime&&i<=o.endTime||o.endTime===null)){n=!0;break}i<a&&(t=t===-1?a:Math.min(t,a))}return!n&&t!==-1?t:null}}};import{isSupportedManifest as Ot,ContainerTypes as wf,ControlTypes as Pt,EventActionTypes as R,EventTypes as Af,migrateManifestToLatestVersion as Go,compareVersions as Rf}from"@interactiveplatform/movika-manifest";var Do={metadata:"Object",chapters:"Array"},Ho=r=>{if(!ie(r))return!1;for(let e in Do)if(!r[e]||!ne(r[e],Do[e]))return!1;return Ot(r.metadata.version)},kt=r=>r.type===Pt.Text,bf=r=>r.type===Pt.Button,Cf=r=>r.type===Pt.Area,gf={Choice:"Choice",TextInput:"TextInput"},Ef={Button:"Button",Area:"Area",Text:"Text"},If={onClick:"onClick",onSuspense:"onSuspense"},Uo={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var Vt=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 Mt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{An(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as zu}from"@vkontakte/videoplayer-shared/es2018";var Lt=class{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!=null?n:[]}}async exec(e,t){return Su(...this.loaders[e])(t)}};function Su(...r){return async function(t){let n=[...r];for(;n.length>0;)t=await n.shift()(t);return t}}function We(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function Nt({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 a=r.getMedia(i.media,o.videoId),l=r.getGraph(i.graph,o.id);return a?{...n,actions:r,errors:e,result:{chapter:o,media:a,graph:l}}:{...n,errors:We(e,Nt.name,"Could not find media"),actions:r}}}}return{...n,errors:We(e,Nt.name,"Could not find chapter"),actions:r}}var jt=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 a=n[i];try{a.callback.call(this,e)}catch(l){Promise.resolve().then(()=>{throw l})}a.options&&a.options.once&&this.removeEventListener(e.type,a.callback)}return!e.defaultPrevented}},Te=class extends jt{constructor(){super(),this.listeners||jt.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)}},Ke=class{constructor(){Object.defineProperty(this,"signal",{value:new Te,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(i){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=e;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(i){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(Ke.prototype[Symbol.toStringTag]="AbortController",Te.prototype[Symbol.toStringTag]="AbortSignal");function _t(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 Hr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=r;if(!_t({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,m){let f;m&&m.signal&&(f=m.signal,delete m.signal);let v=new t(c,m);return f&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),v},o.prototype=t.prototype);let a=e;return{fetch:(s,c)=>{let m=o&&o.prototype.isPrototypeOf(s)?s.signal:c?c.signal:void 0;if(m){let f;try{f=new DOMException("Aborted","AbortError")}catch(C){f=new Error("Aborted"),f.name="AbortError"}if(m.aborted)return Promise.reject(f);let v=new Promise((C,T)=>{m.addEventListener("abort",()=>T(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([v,a(s,c)])}return a(s,c)},Request:o}}var wu=()=>"fetch"in window,Qe=wu()&&_t({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),zo=Qe?Hr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ur=Qe?zo.fetch:window.fetch,qf=Qe?zo.Request:window.Request,Df=Qe?Ke:window.AbortController,Hf=Qe?Te:window.AbortSignal;var Gr=(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 Au=async r=>{try{let e={},t;if(at(r)){t=new URL(r).href;let i=await Ur(t);if(!i.ok)return{};e=await i.json()}else if(ie(r))e=r;else return{};if(!Ho(e))return{};let n=e.metadata.media;if(at(n)&&!("media"in e))try{let i;t?i=new URL(n,t).href:(i=new URL(n).href,t=i);let o=await Ur(i);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch(i){return Ou(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Wo(r){let{manifest:e,manifestURL:t}=await Au(r);if(!e)throw new Error("Failed on fetch");let n=Go(e);return n.media=Ru(n.media,t),delete n.metadata.media,n}function $t(r,e){if(e)return r.find(t=>t.id===e)}function zr(r,e){var t,n;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(i=>i.id===e):(n=r.view)!=null&&n.chapters?r.view.chapters.find(i=>i.id===e):void 0}function Wr(r,e){return r.videos.find(t=>t.id===e)}function Ru(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(n=>{let i="url"in n?n.url:"",o=ku(i,e);return{...n,url:o||i}})}))}}function ku(r="",e){try{return new URL(r,e).href}catch(t){return""}}function Ou(r){return Gr(r,"3.2.0")>=0}var ia=Q(Xe(),1);var Ft=r=>st(r)&&!Jt(r),Z=r=>r.order==="end",Bt=r=>st(r.containers)&&!Jt(r.containers)&&Z(r),oa=(r,e)=>{var n;let t=r*1e3;return Ft(e.controls)&&t<((n=e.startTime)!=null?n:0)},Qr=(r,e)=>{var n,i;let t=r*1e3;return Ft(e.controls)&&t>=((n=e.startTime)!=null?n:0)&&t<=((i=e.endTime)!=null?i:1/0)};var ue=(r=[])=>r.some(e=>e.action.type==="expect"),Xr=(r=[])=>r.find(e=>e.action.type==="expect"),Gu=r=>(r==null?void 0:r.length)===1,Se=r=>Gu(r)&&kt(r[0]);function aa(r=[],e=1/0,t=[]){return r.filter(({container:n})=>!(0,ia.default)(t,n.container.id)&&ue(n.container.events)&&n.container.endTime===e&&!n.isRemoved)}function qt({gameControllers:r=[],subjectName:e,subjectId:t,execFn:n}){for(let i of r)if(e==="container"&&i.container.container.id===t){n(i),aa(r,i.container.container.endTime,[i.container.container.id]).forEach(a=>{n(a)});break}}var sa=(r,e)=>{let t=E=>{let d=e.find(({container:p})=>p.container.id===E);return d==null?void 0:d.container.isRemoved},n=ue(r.events)&&!t(r.id),i=(E,d=!1,p=!1)=>{let u=p?"every":"some";return E.controls[u](y=>{var x;let g=d?E.endTime===r.endTime:!0;return((x=y.events)==null?void 0:x[u](b=>{var I;return((I=b.action)==null?void 0:I.type)===Uo.openURI}))&&g})},o=E=>E.some(({container:d})=>i(d.container,!0,!1)&&!d.isRemoved),a=E=>E.every(({container:d})=>d.isRemoved?!0:i(d.container,!0,!0)),l=aa(e,r.endTime,[r.id]).length,s=E=>E.controls.some(d=>{var p;return(p=d.events)==null?void 0:p.some(u=>{var y,g;return(g=(y=u.action)==null?void 0:y.args)==null?void 0:g.shouldOpenNow})}),c=n||l>0,m=o(e),f=i(r),v=a(e),C=n?!1:l>0,T=s(r);return{isExpectTime:c,hasOtherExpect:l>0,hasOpenURIEvent:m,hasOpenURIEventInCurrentContainer:f,isAllOpenURIEventsValid:v,isExpectEventForCurrentContainer:C,hasShouldOpenNowEvent:T}};var we=class extends Lt{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new zu(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var i;this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:We},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await Wo((i=n.result)!=null?i:t),this}async setInitial(){return this.setNext()}async setNext(t=(n=>(n=this.manifest)==null?void 0:n.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",Nt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:zr,getChapter:$t,getMedia:Wr,getByBranches:this.getByBranches.bind(this),addErrorMessage:We},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),i.result&&(this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){var n;return this.getByChapterId((n=this.manifest)==null?void 0:n.metadata.initChapterId)||null}getByChapterId(t=(n=>(n=this.manifest)==null?void 0:n.metadata.initChapterId)()){if(!t||!this.manifest)return null;let i=$t(this.manifest.chapters,t);if(i){let o=Wr(this.manifest.media,i.videoId),a=zr(this.manifest.graph,i.id);if(o)return{chapter:i,media:o,graph:a}}return null}getBranches(t=(n=>(n=this.chapter)==null?void 0:n.id)()){var i,o,a;if(t===((i=this.chapter)==null?void 0:i.id))return this.getByBranches((o=this.chapter)==null?void 0:o.branches);{let l=$t(((a=this.manifest)==null?void 0:a.chapters)||[],t);return this.getByBranches(l==null?void 0:l.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(){var t,n;return((t=this.chapter)==null?void 0:t.id)===((n=this.manifest)==null?void 0:n.metadata.initChapterId)}isEndChapter(){return this.chapter?Z(this.chapter):!1}};var Fa=Q(Dt(),1);import{Player as gp}from"@vkontakte/videoplayer-core/es2018";import{Subscription as tn,Tracer as Ep,ValueSubject as Ip}from"@vkontakte/videoplayer-shared/es2018";var _a=r=>{let e=r.variants.find(t=>{var n;return((n=t.payload)==null?void 0:n.type)==="vk"});if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};var $a=Q(Dt(),1);function Jr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:a=Math.random().toString(),...l}){let s=r.get(o),c={...l};return s?s[a]=c:r.set(o,{[a]:c}),{listId:o,itemId:a,...l}}function t(o){var a,l;o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),(a=o.statistics)==null||a.oneStat.destroy(),(l=o.statistics)==null||l.statSubscription.unsubscribe()}function n(o,a){let l=r.get(o);if(!l)throw Error("Can't remove. Not find.");if(a){let s=l[a];s&&t(s),delete l[a],Object.keys(l).length||r.delete(o)}else{for(let s of(0,$a.default)(l))t(s);r.delete(o)}}function i(){for(let o of r)n(o[0])}return{createPlayer:e,removePlayer:n,map:r,removeAll:i}}var Ae=Q(Xe(),1);function en(r,e=[]){var o,a,l;let t={},n,i=!e.length;for(let s of r.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(i||(0,Ae.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[(o=s.standard)!=null?o:"Invariant quality"]:s.url});break;case"mpeg":(i||(0,Ae.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[(a=s.standard)!=null?a:"Invariant quality"]:s.url});break;case"hls":(i||(0,Ae.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(i||(0,Ae.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:t,thumbUrl:n,title:(l=r.title)!=null?l:""}}var Ye=(r,e)=>{let t=r.info.currentQuality$.getValue(),n=r.info.availableQualities$.getValue();t!==e&&(0,Ae.default)(n,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var xp=2;function rn(r){let e=Jr(),t=new tn,n={},i=null,o=!1,a,l=new Ip(null);r&&s(r);function s(d){i=d}function c(d,p,u){var x;if(!i)throw Error("need to set interactive controller");if(!i.options)return;let g=((x=e.map.get(d))!=null?x:{})[p];if(g){n={chapterId:u,listId:d,itemId:p,...g};let b=n.player;n.subscription.add(b.info.currentQuality$.subscribe(I=>{let j=b.info.position$.getValue(),w=b.info.isAutoQualityEnabled$.getValue();if(!(!I||!j||w))for(let O of e.map)(0,Fa.default)(O[1]).forEach(({player:P})=>{Ye(P,I)})})).add(b.events.started$.subscribe(()=>{m(p)})),g.container.remove(),i.setPlayer(g.player),o||(i.init(),o=!0),l.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function m(d){if(!i)throw Error("need to set interactive controller");if(se(n)||d!==n.itemId)return;let p=i.getChapterBranches(),u=new Set;for(let y of p)u.has(y.media.id)||(await v({media:y.media,chapterId:y.chapter.id,setAsActive:!1,title:y.chapter.label}),u.add(y.media.id))}async function f({chapter:{id:d},manifestVideo:p}){if(se(n)||!i)return;let u=n.player.info.muted$.getValue(),y=n.player.info.currentQuality$.getValue(),g=n.player.info.isAutoQualityEnabled$.getValue(),x=n.player.info.volume$.getValue(),b=n.player.info.currentPlaybackRate$.getValue(),I=!g,j=!1;for(let w of e.map)if(w[0]===p.id&&!i.state.isReplay$.getValue()){let O=Object.keys(w[1]);for(let P of O)P===n.itemId?(O.length<xp||(j=!0),e.removePlayer(w[0],P)):(j=!0,c(w[0],P,d),I?Ye(n.player,y):n.player.setAutoQuality(!0),n.player.setVolume(x),n.player.setMuted(u),n.player.setPlaybackRate(b))}else e.removePlayer(w[0]);j||(await v({media:p,chapterId:d,setAsActive:!0,playbackRate:b}),I?Ye(n.player,y):n.player.setAutoQuality(!0),n.player.setVolume(x),n.player.setMuted(u))}async function v({media:d,chapterId:p,prefetch:u=!0,setAsActive:y=!0,autoplay:g=!1,preferredExt:x,title:b,playbackRate:I}){var fn,vn,yn,bn,Cn;let j=Math.random().toString(),w=document.createElement("div");a.append(w);let O;if((fn=i==null?void 0:i.options)!=null&&fn.vkVideoLoader){let it=_a(d);it.length&&(O=await i.options.vkVideoLoader(...it))}let P=((vn=i==null?void 0:i.options)==null?void 0:vn.coreConfig)||void 0,K={...P,configName:[...(yn=P==null?void 0:P.configName)!=null?yn:[],"interactive"]},ae={container:w,...((bn=O==null?void 0:O.videos)==null?void 0:bn[0])||{sources:en(d,x).sources},title:b,failoverHosts:(O==null?void 0:O.failoverHosts)||[]},B=new gp(K,Ep.createRootTracer());B.initVideo(ae);let me=null;if(O!=null&&O.videos&&(i!=null&&i.options.createOneStat)){let it=O.videos[0],Xt=i.options.createOneStat(it),gn=new tn;Xt&&(gn.add(Xt.attachTo(B)),me={oneStat:Xt,statSubscription:gn})}let mn=new tn,zs=(Cn=n==null?void 0:n.player)==null?void 0:Cn.info.isAutoQualityEnabled$.getValue();mn.add(B.events.canplay$.subscribe(function(){zs||Ye(B,n.player.info.currentQuality$.getValue()),I&&B.setPlaybackRate(I)}));let fe=e.createPlayer({listId:d.id,itemId:j,player:B,container:w,sources:en(d,x).sources,config:ae,subscription:mn,statistics:me});return y&&c(d.id,fe.itemId,p),g&&fe.player.play(),u&&!g&&fe.player.prepare(),{player:fe.player,config:fe.config,statistics:fe.statistics}}function C(){T(),i=null,a.remove()}function T(){t.unsubscribe(),e.removeAll(),n={},o=!1}async function E(){if(!i)throw Error("need to set interactive controller");T(),a=document.createElement("div");let{media:d,chapter:p}=i.getCurrentChapter();d&&p?(t.add(i.events.chapterChanged$.subscribe(f)),await v({media:d,chapterId:p.id,title:p.label})):console.error("not found")}return{...e,init:E,setInteractiveController:s,createPlayer:v,removeAll:C,getActivePlayer:function(){return n},activePlayerChanged:l}}var A={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ze={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},M={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var qa=Q(Xe(),1);import{Subscription as Tp}from"@vkontakte/videoplayer-shared/es2018";function nn(r){return function(...t){return r(...t.reverse())}}function Je(r,...e){return(...t)=>ie(e[0])&&ie(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var Ht=class{constructor({player:e,container:t,branches:n,selectBranches:i,interactiveEvents:o,globalEvents:a,globalEventEmitter:l,getContainerEventState:s,permanentTextControls:c,interactiveTimeOpenUri:m,disabledControls$:f,onRemove:v,onError:C}){this.hide=()=>{setTimeout(()=>{var e,t;this.gameState!==4&&(ue(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&((t=(e=this.container).hide)==null||t.call(e)),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{var t,n,i,o;if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:a}=this.getContainerEventState();if((n=(t=this.container).show)==null||n.call(t),this.interactiveTimeOpenUri&&a)return;this.emitContainerVisibilityEvent(!0,!1)}else{let a={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(s,c)=>{let{isExpectTime:m,hasOtherExpect:f,hasOpenURIEvent:v,hasOpenURIEventInCurrentContainer:C,isAllOpenURIEventsValid:T,hasShouldOpenNowEvent:E}=this.getContainerEventState(),d=this.interactiveTimeOpenUri&&!C,p=this.interactiveTimeOpenUri&&C;if((!this.interactiveTimeOpenUri||d)&&(this.isSelectedControlEvent=!0),s!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||d)){if(this.interactiveTimeOpenUri){let u=!f&&!T&&C;u&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:u})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&v&&this.gameState!==5){if(p){let y=((g,x,b,I)=>!g&&!x&&b||g&&!x&&b&&!I||g&&!x&&b&&I)(m,f,T,this.isSelectedContainerEvent);this.fakeRemoveView(y)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!m||!f||!E)&&(this.selectBranches.stopExpect(),c())}},isEOV:()=>this.gameState===4},l=Je(this.selectBranches.onControlEvent,a);this.container.createView({eventCallback:l}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&((o=(i=this.container).disable)==null||o.call(i))}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{var c,m,f;let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,qa.default)(i,this.gameState)&&!this.isPermanentText)return;let o=this.player.getExactTime();if(oa(o,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Qr(o,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let v=this.gameState;this.gameState=3,v===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:v}=this.getContainerEventState(),C=this.selectBranches.state.isExpect,T=this.interactiveTimeOpenUri&&v;if(T&&!C){let E=this.container.getElement();E&&(E.style.visibility!=="hidden"&&((m=(c=this.container).hide)==null||m.call(c)),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!T&&this.removeView()}let a=Qr(o,this.container.container),l=this.container.container.startTime?[this.container.container.startTime,(f=this.container.container.endTime)!=null?f:1/0]:[],s={subjectId:this.container.container.id,subjectName:"container",range:l,currentTime:o,isInteractiveTime:a};this.container.onProgress(o*1e3,a),this.globalEventEmitter.emit(A.eachTick,s),this.globalEvents.eachTick$.next(s)};this.container=t,this.branches=n,this.selectBranches=i,this.subscription=new Tp,this.player=e,this.interactiveEvents=o,this.getContainerEventState=s,this.isPermanentText=c&&Se(t.container.controls),this.interactiveTimeOpenUri=m,this.disabledControls$=f,this.onRemove=v,this.globalEventEmitter=l,this.gameState=0,this.globalEvents=a,this.onError=C,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(A.interactives,{subjectId:this.container.container.id,subjectName:"container",type:M.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(A.interactives,{subjectId:this.container.container.id,subjectName:"container",type:M.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,n,i,o;e?(n=(t=this.container).disable)==null||n.call(t):(o=(i=this.container).enable)==null||o.call(i)})),this.subscription.add(this.container.error$.subscribe(this.onError))}selectContainerEvent(e=!1){var n,i;let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:(n=this.container.container.endTime)!=null?n:1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec((i=this.container.container.endTime)!=null?i:1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:ue(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(A.interactives,{subjectId:this.container.container.id,subjectName:"container",type:M.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,(e=this.onRemove)==null||e.call(this)}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}destroy(){var e;this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var Da=(r=[])=>r.reduce((e,t,n)=>{var o,a,l;let i=((o=t==null?void 0:t.controls)!=null?o:[]).filter(s=>!kt(s));if(Ft(i)){let s=[(a=t.startTime)!=null?a:0,(l=t.endTime)!=null?l:1/0],c={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[c],range:s});else{let m=[],f=-1/0,v=1/0,C=[],T=[];for(let E=0;E<e.length;E++){let d=e[E];if(T.push(...d.subjects),d.range[0]<v&&(v=d.range[0]),d.range[1]>f&&(f=d.range[1]),s[0]>=d.range[0]&&s[1]<=d.range[1])return e[E].subjects.push(c),e;s[0]<d.range[0]&&s[1]>d.range[0]&&(m.push(E),C=C.concat(d.subjects)),s[0]>=d.range[0]&&s[0]<=d.range[1]&&(m.push(E),C=C.concat(d.subjects),s[0]=d.range[0]),s[1]>=d.range[0]&&s[1]<=d.range[1]&&(m.push(E),C=C.concat(d.subjects),s[1]=d.range[1])}if(T.push(c),s[0]<=v&&s[1]>=f)return[{subjects:T,range:s}];m.length&&m.reverse().forEach(E=>{e.splice(E,1)}),e.push({subjects:C.concat([c]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var xs=Q(Xe(),1),ln=Q(Dt(),1),Ts=Q(Es(),1);function Is(){let r={};function e(){for(let l in r)Object.prototype.hasOwnProperty.call(r,l)&&delete r[l]}function t(l){let s={};for(let c in r)+c<=l&&(s[c]=r[c]);return s}function n(l){let s={};for(let c in r)+c>=l&&(s[c]=r[c]);return s}function i({timestamp:l,priority:s,initiator:c}){var m;if(Zt(l)){let f=(m=r[l])!=null?m:null;if(f&&s&&Oe(s,!0)){let v={},C=f[s];if(C&&(v={...v,...C}),v=se(v)?null:v,v&&Oe(c,!0)){let T=v[c];return T!=null?T:null}return v}return f}return null}function o({timestamp:l,priority:s,initiator:c}){if(Zt(l))if(r[l]){if(s&&Oe(s,!0))if(r[l][s]){if(c&&Oe(c,!0))if(r[l][s][c]){if(delete r[l][s][c],!se(r[l][s]))return!0}else return!1;if(delete r[l][s],!se(r[l]))return!0}else return!1;return delete r[l]}else return!1;return!1}function a({timestamp:l,priority:s,initiator:c,...m}){var f,v,C;(v=(f=r[l])==null?void 0:f[s])!=null&&v[c]?r[l][s][c].push({...m}):(C=r[l])!=null&&C[s]?r[l][s]={...r[l][s],[c]:[{...m}]}:r[l]?r[l]={...r[l],[s]:{[c]:[{...m}]}}:r[l]={[s]:{[c]:[{...m}]}}}return{map:r,remove:o,add:a,removeAll:e,get:i,getLte:t,getGte:n}}var hh=[R.expect,R.setNextBranch],dh=1/0;function Ss(r,e){let t=r,n,i=mh(e),o=Is(),a,l=()=>{C(),p()},s=u=>{o.add.call(void 0,u),T()},c=(u=[])=>{for(let y of u)if(y.action(),(0,xs.default)(hh,y.actionType))break},m=(u=1/0)=>{var b,I,j;let y=Gt((b=o.get({timestamp:u,priority:"control"}))!=null?b:{}),g=Gt((I=o.get({timestamp:u,priority:"container"}))!=null?I:{}),x=Gt((j=o.get({timestamp:u,priority:"chapter"}))!=null?j:{});return[...y,...g,...x]},f=u=>{i.isReady(u)&&c(m(u))},v=()=>{var u;c([...Gt((u=o.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},C=()=>{n&&(a==null||a.unsubscribe(),n=void 0)},T=()=>{n||(n=()=>setTimeout(()=>{f(1/0)}),a=t.events.ended$.subscribe(n))},E=u=>{C(),t=u},d=u=>{u.priority==="container"&&i.resetCalled(u.timestamp),o.remove(u)},p=()=>{i.release(),o.removeAll()};return{setPlayer:E,add:s,remove:d,exec:f,execEndOfVideo:v,listen:T,unlisten:C,release:l,containersEventsCallState:i,getPreparedToExecActions:m}}function mh(r){let e=new Map;return{setCalled:({timestamp:l,id:s})=>{let c=e.get(l);c&&c[s]!==void 0&&(c[s]=!0)},setData:(l=[])=>{var s;for(let c of l){let m=(s=c.endTime)!=null?s:dh,f=e.get(m);e.set(m,{...f,[c.id]:!1})}},resetCalled:l=>{let s=e.get(l);if(s)for(let c in s)s[c]=!1},isReady:l=>{let s=e.get(l);if(!s)return!0;let c=(0,ln.default)(s);return r?c.some(f=>f):!c.some(f=>!f)},release:()=>e.clear()}}function Gt(r){return(0,Ts.default)((0,ln.default)(r)).sort(e=>e.actionType===R.expect?-1:1)}var ws={videoContentHeight:0,videoContentWidth:0},As=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return ws;let{clientHeight:n,clientWidth:i}=r.experimental.element$.getValue()||{};if(!(n&&i))return ws;let o=e/t,a=n/i,l,s;return a>o?(s=i,l=i*o):a<o?(s=n/o,l=n):(s=i,l=n),{videoContentWidth:s,videoContentHeight:l}};var fh=250;function Rs(r){let e,t=new ResizeObserver(l=>{o(l),e=o.bind(null,l)});function n(l){let{parentElement:s,player:c}=r();if(s&&c){let{videoContentWidth:m,videoContentHeight:f}=As(c);s.style.setProperty("--interactive-content-width",`${m}px`),s.style.setProperty("--interactive-content-height",`${f}px`),s.style.setProperty("--interactive-width",`${l[0].contentRect.width}px`),s.style.setProperty("--interactive-height",`${l[0].contentRect.height}px`)}}function i(){let{parentElement:l}=r();l.removeAttribute("style")}let o=Ue(l=>{let{fns:s=[]}=r();n(l);for(let c of s)c()},fh);function a(){e=void 0,t.disconnect(),i()}return{resizeObserver:t,calc:()=>{e==null||e()},release:a}}var vh=r=>Math.floor(Math.random()*r),Os=r=>{var i;let e=r.length,t=1/0,n=null;for(;e--;){let o=r[e],a=(i=o.weight)!=null?i:1;a<t&&(t=a,n=o)}return n},Ps=r=>{var i;let e=r.length,t=-1/0,n=null;for(;e--;){let o=r[e],a=(i=o.weight)!=null?i:0;a>t&&(t=a,n=o)}return n};var Vs=r=>{let e=r.length,t=vh(e);return r[t]},ks=1,Ms=r=>{var n,i;let e=0;for(let o=0;o<r.length;++o)e+=(n=r[o].weight)!=null?n:ks;let t=Math.random()*e;e=0;for(let o=0;o<r.length-1;++o)if(e+=(i=r[o].weight)!=null?i:ks,e>=t)return r[o];return r[r.length-1]};var Ls={shouldOpenNow:!0,isDetachContainer:!0},Ns="after-expect",cn=(r,e=!1)=>({...r,args:e?{...r.args,...Ls}:{...Ls,...r.args}}),js=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:n})=>{let i={isExpect:!1},o=()=>{i.isExpect&&(i.isExpect=!1)},a=({action:p,controlType:u,controlId:y,containerId:g,branches:x=[],onEvent:b,isEOV:I=()=>!1,isDisabled:j=()=>!1})=>{let w=cn(p,I()),O={timestamp:1/0,priority:"control",initiator:y,actionType:w.type},P=j(),K=r.emit.bind(r,A.interactives,{subjectId:y,subjectType:u,subjectName:"control",type:P?M.actionChoiceCanceled:M.actionChoice,actionType:p.type,payload:{invokeImmediately:w.args.shouldOpenNow,containerId:g,...w.args}}),ae=()=>{e.interactiveActionChoice$.next({subjectId:y,subjectType:u,subjectName:"control",type:P?"action-choice-canceled":"action-choice",actionType:p.type,payload:{invokeImmediately:w.args.shouldOpenNow,containerId:g,...w.args}})};if(P){K(),ae();return}switch(w.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{let B=x.find(me=>me.id===w.args.branchId);if(!B)return;b(w.args.isDetachContainer,C.bind(null,{subjectId:y,subjectName:"control"})),K(),ae(),w.args.shouldOpenNow?E({subjectId:y,subjectName:"control",subjectType:u,action:w,payload:{chapterId:B.chapterId,autoSelect:!1}}):n.add({...O,action:E.bind(null,{subjectId:y,subjectName:"control",subjectType:u,action:w,payload:{chapterId:B.chapterId,autoSelect:!1}})});return}case R.continuePlayback.trim().toLowerCase():{b(w.args.isDetachContainer,C.bind(null,{subjectId:y,subjectName:"control"})),K(),ae(),w.args.shouldOpenNow?T({subjectId:y,subjectName:"control",subjectType:u,action:p}):n.add({...O,action:T.bind(null,{subjectId:y,subjectName:"control",subjectType:u,action:p})});return}case R.openURI.trim().toLowerCase():{b(w.args.isDetachContainer,C.bind(null,{subjectId:y,subjectName:"control"})),K(),ae(),w.args.shouldOpenNow?d({subjectId:y,subjectName:"control",subjectType:u,action:w,payload:{URI:p.args.uri}}):n.add({...O,action:d.bind(null,{subjectId:y,subjectName:"control",subjectType:u,action:w,payload:{URI:p.args.uri}})});return}default:{let B="Unexpected control event",me=new N(1,1,{message:B});m(me,B);return}}},l=({action:p,container:{id:u,endTime:y},branches:g=[],isEOV:x=!1,autoSelected:b=!1})=>{let I=cn(p,x),j={timestamp:!I.args.shouldOpenNow||x?1/0:y!=null?y:1/0,priority:"container",initiator:u,actionType:I.type},w=r.emit.bind(r,A.interactives,{subjectId:u,subjectName:"container",type:M.actionChoice,actionType:I.type,payload:{invokeImmediately:I.args.shouldOpenNow,...I.args}}),O=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"container",type:"action-choice",actionType:I.type,payload:{invokeImmediately:I.args.shouldOpenNow,...I.args}})};switch(I.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{let P=g.find(K=>K.id===I.args.branchId);if(!P)return;w(),O(),n.add({...j,action:E.bind(null,{subjectId:u,subjectName:"container",action:I,payload:{chapterId:P.chapterId,autoSelect:b}})});return}case R.setMaxWeightBranch.trim().toLowerCase():return;case R.setMinWeightBranch.trim().toLowerCase():return;case R.setRandomBranch.trim().toLowerCase():return;case R.setWeightlessRandomBranch.trim().toLowerCase():return;case R.continuePlayback.trim().toLowerCase():{w(),O(),n.add({...j,action:T.bind(null,{subjectId:u,subjectName:"container",action:I})});return}case R.openURI.trim().toLowerCase():{w(),O(),n.add({...j,action:d.bind(null,{subjectId:u,subjectName:"container",action:I,payload:{URI:p.args.uri}})});return}default:{let P="Unexpected container event",K=new N(1,1,{message:P});m(K,P);return}}};function s({container:p,branches:u,isEOV:y=!1}){var x,b;let g=Xr(p.events);if(g){let I=cn(g.action,y);r.emit(A.interactives,{subjectId:p.id,subjectName:"container",type:M.actionChoice,actionType:I.type,payload:{invokeImmediately:I.args.shouldOpenNow,...I.args}}),e.interactiveActionChoice$.next({subjectId:p.id,subjectName:"container",type:"action-choice",actionType:I.type,payload:{invokeImmediately:I.args.shouldOpenNow,...I.args}}),n.add({timestamp:y?1/0:(x=p.endTime)!=null?x:1/0,priority:"container",initiator:p.id,actionType:R.expect,action:v.bind(null,{subjectId:p.id,subjectName:"container"})}),i.isExpect=!0}else for(let I of(b=p.events)!=null?b:[])l({action:I.action,container:p,branches:u,isEOV:y})}let c=({chapterId:p,action:u,branches:y=[]})=>{let g=r.emit.bind(r,A.interactives,{subjectId:p,subjectName:"chapter",type:M.actionChoice,actionType:u.type,payload:u.args}),x=()=>{e.interactiveActionChoice$.next({subjectId:p,subjectName:"chapter",type:"action-choice",actionType:u.type,payload:u.args})};switch(u.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{let b=y.find(I=>I.id===u.args.branchId);return b!=null&&b.chapterId?(g(),x(),E.bind(null,{subjectId:p,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case R.setWeightlessRandomBranch.trim().toLowerCase():{let b=Vs(y);return b!=null&&b.chapterId?(g(),x(),E.bind(null,{subjectId:p,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case R.setRandomBranch.trim().toLowerCase():{let b=Ms(y);return b!=null&&b.chapterId?(g(),x(),E.bind(null,{subjectId:p,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case R.setMaxWeightBranch.trim().toLowerCase():{let b=Ps(y);return b!=null&&b.chapterId?(g(),x(),E.bind(null,{subjectId:p,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case R.setMinWeightBranch.trim().toLowerCase():{let b=Os(y);return b!=null&&b.chapterId?(g(),x(),E.bind(null,{subjectId:p,subjectName:"chapter",action:u,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case R.continuePlayback.trim().toLowerCase():return g(),x(),T.bind(null,{subjectId:p,subjectName:"chapter",action:u});case R.openURI.trim().toLowerCase():return g(),x(),d.bind(null,{subjectId:p,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:{let b="Unexpected chapter event",I=new N(1,1,{message:b});m(I,b);return}}};function m(p,u){console.error(u),e.error$.next(p),r.emit(A.errors,p)}function f(p){var y;let u=Xr(p.events);if(u){if(Z(p))return;r.emit(A.interactives,{subjectId:p.id,subjectName:"chapter",type:M.actionChoice,actionType:u.action.type,payload:u.action.args}),e.interactiveActionChoice$.next({subjectId:p.id,subjectName:"chapter",type:"action-choice",actionType:u.action.type,payload:u.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:R.expect,action:v.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else(y=p.events)==null||y.forEach(g=>{let x=c({chapterId:p.id,action:g.action,branches:p.branches});x&&n.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:g.action.type,action:x})})}let v=({subjectId:p,subjectName:u})=>{t.pause(),r.emit(A.interactives,{subjectId:p,subjectName:u,type:M.actionExecution,actionType:R.expect}),e.interactiveActionExecution$.next({subjectId:p,subjectName:u,type:"action-execution",actionType:R.expect})},C=({subjectId:p,subjectName:u})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),r.emit(A.interactives,{subjectId:p,subjectName:u,type:M.actionExecution,actionType:Ns}),e.interactiveActionExecution$.next({subjectId:p,subjectName:u,type:"action-execution",actionType:Ns})},T=({subjectId:p,subjectName:u,subjectType:y,action:g})=>{r.emit(A.interactives,{subjectId:p,subjectName:u,subjectType:y,type:M.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:p,subjectName:u,subjectType:y,type:"action-execution",actionType:g.type})},E=({subjectId:p,subjectName:u,subjectType:y,action:g,payload:x})=>{x.behaviour="change-chapter",r.emit(A.interactives,{subjectId:p,subjectName:u,subjectType:y,type:M.actionExecution,actionType:g.type,payload:x}),e.interactiveActionExecution$.next({subjectId:p,subjectName:u,subjectType:y,type:"action-execution",actionType:g.type,payload:x})},d=({subjectId:p,subjectName:u,subjectType:y,action:g,payload:x})=>{if(!x.URI)return;let b=window.open(x.URI,"_blank","noopener,noreferrer");b&&(b.opener=null),r.emit(A.interactives,{subjectId:p,subjectName:u,subjectType:y,type:M.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:p,subjectName:u,subjectType:y,type:"action-execution",actionType:g.type})};return{onControlEvent:a,onContainerEvent:l,onChapterEvent:c,onExpectEvent:v,expectEventHandler:C,setManifestChapterEvents:f,setManifestContainerEvents:s,stopExpect:o,state:i}};var hn=Q(Dr(),1);import{Subscription as Eh,Subject as pn,ValueSubject as tt}from"@vkontakte/videoplayer-shared/es2018";var un=(r,e)=>{let t={};return r.map(n=>{if(!t[n]){let i=e.chapters.find(a=>a.id===n);if(!i)return null;let o=e.media.videos.find(a=>i.videoId===a.id);if(!o)return null;t[n]=_s(o)}return t[n]}).filter(Boolean)},bh=r=>{for(let e of r.variants)if(Ch(e)&&e.payload)return e.payload.id},Ch=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),_s=r=>{let e=bh(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},gh=(r,e)=>{for(let t of r.media.videos)if(e===_s(t)){for(let n of r.chapters)if(n.videoId===t.id)return n.id;return}},$s=(r,e)=>r.reduce((t,n)=>{let i=gh(e,n);return i?[...t,i]:t},[]);var ee,pe,he,G,zt,te,re,J,de,Re,ke,rt=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:i,settings:o}){this.state={history$:new tt([]),hasPrevChapter$:new tt(!1),prevChapter$:new tt(null),isInitialChapter$:new tt(!1),isGoBackLimited$:new tt(!1)};D(this,ee,null);D(this,pe);D(this,he,!1);D(this,G,null);D(this,zt,null);this.events={inited$:new pn,destroyed$:new pn,error$:new pn};D(this,te,null);D(this,re,null);D(this,J,null);D(this,de,new Eh);D(this,Re,!1);D(this,ke,0);var a;L(this,te,t),L(this,J,e),L(this,re,n),L(this,ee,i),L(this,pe,o),this.state.history$&&S(this,de)&&((a=S(this,de))==null||a.add(this.state.history$.subscribe(l=>{var s,c;this.state.prevChapter$.next((0,hn.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((c=(s=S(this,G))==null?void 0:s.metadata)==null?void 0:c.initChapterId)),this.state.isGoBackLimited$.next(S(this,ke)===S(this,pe).maxLength-1)})))}async setManifest(e){if(!S(this,re)||!S(this,J))return;L(this,G,e),await this.getProjectHistory();let t=this.getInitialChapterId();await S(this,re).setChapter({chapterId:t,pushToHistory:!1}),S(this,he)||(L(this,he,!0),this.events.inited$.next({initChapterId:t}))}get inited(){return S(this,he)}async updateHistory(e,t=!0){var l;if(!S(this,G))return;S(this,Re)?(L(this,Re,!1),Tn(this,ke)._++):L(this,ke,0);let n=S(this,G),i=e.length-S(this,pe).maxLength,o=i>0?e.slice(i):e,a=un(o,n);if(L(this,zt,a),this.state.history$.next(o),!(!t||!S(this,ee)||!S(this,te)))try{await S(this,ee).save(S(this,te),a)}catch(s){let c=new N(1,5,"Unable to save interactive history");this.events.error$.next(c),(l=S(this,J))==null||l.emit(A.errors,c)}}async goBack(){var n;if(!this.state||!S(this,re)){let i=new N(1,5,"Unable to save interactive history");return this.events.error$.next(i),(n=S(this,J))==null?void 0:n.emit(A.errors,i)}L(this,Re,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await S(this,re).setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){var i;if(!S(this,G)||!S(this,te))return;let e=S(this,G),t=[this.getInitialVideoId()];if(S(this,ee))try{let o=await S(this,ee).get(S(this,te));o.length&&(t=o)}catch(o){let a=new N(1,5,"Error while trying to fetch data");this.events.error$.next(a),(i=S(this,J))==null||i.emit(A.errors,a)}let n=$s(t,e);this.state.history$.next(n)}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,hn.default)(e,-1)||S(this,pe).initChapterId||((t=S(this,G))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(S(this,G)){let e=this.getInitialChapterId();return un([e],S(this,G)).pop()}return null}destroy(){var e,t;L(this,te,null),L(this,ee,null),L(this,re,null),(e=S(this,de))==null||e.unsubscribe(),L(this,de,null),L(this,he,!1),(t=S(this,J))==null||t.emit(A.historyDestroyed),this.events.destroyed$.next(),L(this,J,null)}};ee=new WeakMap,pe=new WeakMap,he=new WeakMap,G=new WeakMap,zt=new WeakMap,te=new WeakMap,re=new WeakMap,J=new WeakMap,de=new WeakMap,Re=new WeakMap,ke=new WeakMap;var Wt=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var i;let e=(i=this.rootElement.getContext("2d"))==null?void 0:i.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let o=3;o<n;o+=40)if(t[o]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let i;t&&(i=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&i&&this.restore(i),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var Kt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
6
+ var pl=Object.create;var Si=Object.defineProperty;var hl=Object.getOwnPropertyDescriptor;var dl=Object.getOwnPropertyNames;var ml=Object.getPrototypeOf,fl=Object.prototype.hasOwnProperty;var Ri=r=>{throw TypeError(r)};var h=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var vl=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of dl(e))!fl.call(r,n)&&n!==t&&Si(r,n,{get:()=>e[n],enumerable:!(i=hl(e,n))||i.enumerable});return r};var ee=(r,e,t)=>(t=r!=null?pl(ml(r)):{},vl(e||!r||!r.__esModule?Si(t,"default",{value:r,enumerable:!0}):t,r));var Oi=(r,e,t)=>e.has(r)||Ri("Cannot "+t);var w=(r,e,t)=>(Oi(r,e,"read from private field"),t?t.call(r):e.get(r)),H=(r,e,t)=>e.has(r)?Ri("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),V=(r,e,t,i)=>(Oi(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var ki=(r,e,t,i)=>({set _(n){V(r,e,n,t)},get _(){return w(r,e,i)}});var Y=h((hr,qi)=>{"use strict";var Me=function(r){return r&&r.Math===Math&&r};qi.exports=Me(typeof globalThis=="object"&&globalThis)||Me(typeof window=="object"&&window)||Me(typeof self=="object"&&self)||Me(typeof global=="object"&&global)||Me(typeof hr=="object"&&hr)||function(){return this}()||Function("return this")()});var U=h((Cd,Di)=>{"use strict";Di.exports=function(r){try{return!!r()}catch(e){return!0}}});var Ne=h((Ed,Hi)=>{"use strict";var Cl=U();Hi.exports=!Cl(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Ki=h((Td,Wi)=>{"use strict";var El=Ne(),zi=Function.prototype,Ui=zi.apply,Gi=zi.call;Wi.exports=typeof Reflect=="object"&&Reflect.apply||(El?Gi.bind(Ui):function(){return Gi.apply(Ui,arguments)})});var W=h((Id,Yi)=>{"use strict";var Qi=Ne(),Xi=Function.prototype,dr=Xi.call,Tl=Qi&&Xi.bind.bind(dr,dr);Yi.exports=Qi?Tl:function(r){return function(){return dr.apply(r,arguments)}}});var $e=h((xd,Ji)=>{"use strict";var Zi=W(),Il=Zi({}.toString),xl=Zi("".slice);Ji.exports=function(r){return xl(Il(r),8,-1)}});var mr=h((Ad,en)=>{"use strict";var Al=$e(),wl=W();en.exports=function(r){if(Al(r)==="Function")return wl(r)}});var G=h((wd,tn)=>{"use strict";var fr=typeof document=="object"&&document.all;tn.exports=typeof fr=="undefined"&&fr!==void 0?function(r){return typeof r=="function"||r===fr}:function(r){return typeof r=="function"}});var pe=h((Sd,rn)=>{"use strict";var Sl=U();rn.exports=!Sl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var gt=h((Rd,nn)=>{"use strict";var Rl=Ne(),yt=Function.prototype.call;nn.exports=Rl?yt.bind(yt):function(){return yt.apply(yt,arguments)}});var vr=h(sn=>{"use strict";var on={}.propertyIsEnumerable,an=Object.getOwnPropertyDescriptor,Ol=an&&!on.call({1:2},1);sn.f=Ol?function(e){var t=an(this,e);return!!t&&t.enumerable}:on});var br=h((kd,ln)=>{"use strict";ln.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var un=h((Pd,cn)=>{"use strict";var kl=W(),Pl=U(),_l=$e(),yr=Object,Ll=kl("".split);cn.exports=Pl(function(){return!yr("z").propertyIsEnumerable(0)})?function(r){return _l(r)==="String"?Ll(r,""):yr(r)}:yr});var gr=h((_d,pn)=>{"use strict";pn.exports=function(r){return r==null}});var Cr=h((Ld,hn)=>{"use strict";var Fl=gr(),Vl=TypeError;hn.exports=function(r){if(Fl(r))throw new Vl("Can't call method on "+r);return r}});var je=h((Fd,dn)=>{"use strict";var Ml=un(),Nl=Cr();dn.exports=function(r){return Ml(Nl(r))}});var Te=h((Vd,mn)=>{"use strict";var $l=G();mn.exports=function(r){return typeof r=="object"?r!==null:$l(r)}});var Ct=h((Md,fn)=>{"use strict";fn.exports={}});var Et=h((Nd,bn)=>{"use strict";var Er=Ct(),Tr=Y(),jl=G(),vn=function(r){return jl(r)?r:void 0};bn.exports=function(r,e){return arguments.length<2?vn(Er[r])||vn(Tr[r]):Er[r]&&Er[r][e]||Tr[r]&&Tr[r][e]}});var gn=h(($d,yn)=>{"use strict";var Bl=W();yn.exports=Bl({}.isPrototypeOf)});var In=h((jd,Tn)=>{"use strict";var ql=Y(),Cn=ql.navigator,En=Cn&&Cn.userAgent;Tn.exports=En?String(En):""});var kn=h((Bd,On)=>{"use strict";var Rn=Y(),Ir=In(),xn=Rn.process,An=Rn.Deno,wn=xn&&xn.versions||An&&An.version,Sn=wn&&wn.v8,K,Tt;Sn&&(K=Sn.split("."),Tt=K[0]>0&&K[0]<4?1:+(K[0]+K[1]));!Tt&&Ir&&(K=Ir.match(/Edge\/(\d+)/),(!K||K[1]>=74)&&(K=Ir.match(/Chrome\/(\d+)/),K&&(Tt=+K[1])));On.exports=Tt});var xr=h((qd,_n)=>{"use strict";var Pn=kn(),Dl=U(),Hl=Y(),Ul=Hl.String;_n.exports=!!Object.getOwnPropertySymbols&&!Dl(function(){var r=Symbol("symbol detection");return!Ul(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Pn&&Pn<41})});var Ar=h((Dd,Ln)=>{"use strict";var Gl=xr();Ln.exports=Gl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var wr=h((Hd,Fn)=>{"use strict";var zl=Et(),Wl=G(),Kl=gn(),Ql=Ar(),Xl=Object;Fn.exports=Ql?function(r){return typeof r=="symbol"}:function(r){var e=zl("Symbol");return Wl(e)&&Kl(e.prototype,Xl(r))}});var Mn=h((Ud,Vn)=>{"use strict";var Yl=String;Vn.exports=function(r){try{return Yl(r)}catch(e){return"Object"}}});var Sr=h((Gd,Nn)=>{"use strict";var Zl=G(),Jl=Mn(),ec=TypeError;Nn.exports=function(r){if(Zl(r))return r;throw new ec(Jl(r)+" is not a function")}});var jn=h((zd,$n)=>{"use strict";var tc=Sr(),rc=gr();$n.exports=function(r,e){var t=r[e];return rc(t)?void 0:tc(t)}});var qn=h((Wd,Bn)=>{"use strict";var Rr=gt(),Or=G(),kr=Te(),ic=TypeError;Bn.exports=function(r,e){var t,i;if(e==="string"&&Or(t=r.toString)&&!kr(i=Rr(t,r))||Or(t=r.valueOf)&&!kr(i=Rr(t,r))||e!=="string"&&Or(t=r.toString)&&!kr(i=Rr(t,r)))return i;throw new ic("Can't convert object to primitive value")}});var Hn=h((Kd,Dn)=>{"use strict";Dn.exports=!0});var zn=h((Qd,Gn)=>{"use strict";var Un=Y(),nc=Object.defineProperty;Gn.exports=function(r,e){try{nc(Un,r,{value:e,configurable:!0,writable:!0})}catch(t){Un[r]=e}return e}});var It=h((Xd,Qn)=>{"use strict";var oc=Hn(),ac=Y(),sc=zn(),Wn="__core-js_shared__",Kn=Qn.exports=ac[Wn]||sc(Wn,{});(Kn.versions||(Kn.versions=[])).push({version:"3.43.0",mode:oc?"pure":"global",copyright:"\xA9 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var Pr=h((Yd,Yn)=>{"use strict";var Xn=It();Yn.exports=function(r,e){return Xn[r]||(Xn[r]=e||{})}});var Be=h((Zd,Zn)=>{"use strict";var lc=Cr(),cc=Object;Zn.exports=function(r){return cc(lc(r))}});var Ie=h((Jd,Jn)=>{"use strict";var uc=W(),pc=Be(),hc=uc({}.hasOwnProperty);Jn.exports=Object.hasOwn||function(e,t){return hc(pc(e),t)}});var _r=h((em,eo)=>{"use strict";var dc=W(),mc=0,fc=Math.random(),vc=dc(1.1.toString);eo.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+vc(++mc+fc,36)}});var qe=h((tm,ro)=>{"use strict";var bc=Y(),yc=Pr(),to=Ie(),gc=_r(),Cc=xr(),Ec=Ar(),xe=bc.Symbol,Lr=yc("wks"),Tc=Ec?xe.for||xe:xe&&xe.withoutSetter||gc;ro.exports=function(r){return to(Lr,r)||(Lr[r]=Cc&&to(xe,r)?xe[r]:Tc("Symbol."+r)),Lr[r]}});var ao=h((rm,oo)=>{"use strict";var Ic=gt(),io=Te(),no=wr(),xc=jn(),Ac=qn(),wc=qe(),Sc=TypeError,Rc=wc("toPrimitive");oo.exports=function(r,e){if(!io(r)||no(r))return r;var t=xc(r,Rc),i;if(t){if(e===void 0&&(e="default"),i=Ic(t,r,e),!io(i)||no(i))return i;throw new Sc("Can't convert object to primitive value")}return e===void 0&&(e="number"),Ac(r,e)}});var Fr=h((im,so)=>{"use strict";var Oc=ao(),kc=wr();so.exports=function(r){var e=Oc(r,"string");return kc(e)?e:e+""}});var uo=h((nm,co)=>{"use strict";var Pc=Y(),lo=Te(),Vr=Pc.document,_c=lo(Vr)&&lo(Vr.createElement);co.exports=function(r){return _c?Vr.createElement(r):{}}});var Mr=h((om,po)=>{"use strict";var Lc=pe(),Fc=U(),Vc=uo();po.exports=!Lc&&!Fc(function(){return Object.defineProperty(Vc("div"),"a",{get:function(){return 7}}).a!==7})});var fo=h(mo=>{"use strict";var Mc=pe(),Nc=gt(),$c=vr(),jc=br(),Bc=je(),qc=Fr(),Dc=Ie(),Hc=Mr(),ho=Object.getOwnPropertyDescriptor;mo.f=Mc?ho:function(e,t){if(e=Bc(e),t=qc(t),Hc)try{return ho(e,t)}catch(i){}if(Dc(e,t))return jc(!Nc($c.f,e,t),e[t])}});var bo=h((sm,vo)=>{"use strict";var Uc=U(),Gc=G(),zc=/#|\.prototype\./,De=function(r,e){var t=Kc[Wc(r)];return t===Xc?!0:t===Qc?!1:Gc(e)?Uc(e):!!e},Wc=De.normalize=function(r){return String(r).replace(zc,".").toLowerCase()},Kc=De.data={},Qc=De.NATIVE="N",Xc=De.POLYFILL="P";vo.exports=De});var Nr=h((lm,go)=>{"use strict";var yo=mr(),Yc=Sr(),Zc=Ne(),Jc=yo(yo.bind);go.exports=function(r,e){return Yc(r),e===void 0?r:Zc?Jc(r,e):function(){return r.apply(e,arguments)}}});var Eo=h((cm,Co)=>{"use strict";var eu=pe(),tu=U();Co.exports=eu&&tu(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Io=h((um,To)=>{"use strict";var ru=Te(),iu=String,nu=TypeError;To.exports=function(r){if(ru(r))return r;throw new nu(iu(r)+" is not an object")}});var wo=h(Ao=>{"use strict";var ou=pe(),au=Mr(),su=Eo(),xt=Io(),xo=Fr(),lu=TypeError,$r=Object.defineProperty,cu=Object.getOwnPropertyDescriptor,jr="enumerable",Br="configurable",qr="writable";Ao.f=ou?su?function(e,t,i){if(xt(e),t=xo(t),xt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&qr in i&&!i[qr]){var n=cu(e,t);n&&n[qr]&&(e[t]=i.value,i={configurable:Br in i?i[Br]:n[Br],enumerable:jr in i?i[jr]:n[jr],writable:!1})}return $r(e,t,i)}:$r:function(e,t,i){if(xt(e),t=xo(t),xt(i),au)try{return $r(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new lu("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Ro=h((hm,So)=>{"use strict";var uu=pe(),pu=wo(),hu=br();So.exports=uu?function(r,e,t){return pu.f(r,e,hu(1,t))}:function(r,e,t){return r[e]=t,r}});var Ue=h((dm,ko)=>{"use strict";var He=Y(),du=Ki(),mu=mr(),fu=G(),vu=fo().f,bu=bo(),Ae=Ct(),yu=Nr(),we=Ro(),Oo=Ie();It();var gu=function(r){var e=function(t,i,n){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,i)}return new r(t,i,n)}return du(r,this,arguments)};return e.prototype=r.prototype,e};ko.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,o=r.proto,a=i?He:n?He[t]:He[t]&&He[t].prototype,l=i?Ae:Ae[t]||we(Ae,t,{})[t],s=l.prototype,c,m,f,v,y,C,E,d,u;for(v in e)c=bu(i?v:t+(n?".":"#")+v,r.forced),m=!c&&a&&Oo(a,v),C=l[v],m&&(r.dontCallGetSet?(u=vu(a,v),E=u&&u.value):E=a[v]),y=m&&E?E:e[v],!(!c&&!o&&typeof C==typeof y)&&(r.bind&&m?d=yu(y,He):r.wrap&&m?d=gu(y):o&&fu(y)?d=mu(y):d=y,(r.sham||y&&y.sham||C&&C.sham)&&we(d,"sham",!0),we(l,v,d),o&&(f=t+"Prototype",Oo(Ae,f)||we(Ae,f,{}),we(Ae[f],v,y),r.real&&s&&(c||!s[v])&&we(s,v,y)))}});var _o=h((mm,Po)=>{"use strict";var Cu=Math.ceil,Eu=Math.floor;Po.exports=Math.trunc||function(e){var t=+e;return(t>0?Eu:Cu)(t)}});var Ge=h((fm,Lo)=>{"use strict";var Tu=_o();Lo.exports=function(r){var e=+r;return e!==e||e===0?0:Tu(e)}});var Vo=h((vm,Fo)=>{"use strict";var Iu=Ge(),xu=Math.max,Au=Math.min;Fo.exports=function(r,e){var t=Iu(r);return t<0?xu(t+e,0):Au(t,e)}});var No=h((bm,Mo)=>{"use strict";var wu=Ge(),Su=Math.min;Mo.exports=function(r){var e=wu(r);return e>0?Su(e,9007199254740991):0}});var ze=h((ym,$o)=>{"use strict";var Ru=No();$o.exports=function(r){return Ru(r.length)}});var Dr=h((gm,Bo)=>{"use strict";var Ou=je(),ku=Vo(),Pu=ze(),jo=function(r){return function(e,t,i){var n=Ou(e),o=Pu(n);if(o===0)return!r&&-1;var a=ku(i,o),l;if(r&&t!==t){for(;o>a;)if(l=n[a++],l!==l)return!0}else for(;o>a;a++)if((r||a in n)&&n[a]===t)return r||a||0;return!r&&-1}};Bo.exports={includes:jo(!0),indexOf:jo(!1)}});var At=h((Cm,qo)=>{"use strict";qo.exports=function(){}});var Do=h(()=>{"use strict";var _u=Ue(),Lu=Dr().includes,Fu=U(),Vu=At(),Mu=Fu(function(){return!Array(1).includes()});_u({target:"Array",proto:!0,forced:Mu},{includes:function(e){return Lu(this,e,arguments.length>1?arguments[1]:void 0)}});Vu("includes")});var wt=h((Im,Ho)=>{"use strict";var Nu=Et();Ho.exports=Nu});var Go=h((xm,Uo)=>{"use strict";Do();var $u=wt();Uo.exports=$u("Array","includes")});var Wo=h((Am,zo)=>{"use strict";var ju=Go();zo.exports=ju});var St=h((wm,Ko)=>{"use strict";var Bu=Wo();Ko.exports=Bu});var ma=h(()=>{"use strict";var Ku=Ue(),Qu=Be(),Xu=ze(),Yu=Ge(),Zu=At();Ku({target:"Array",proto:!0},{at:function(e){var t=Qu(this),i=Xu(t),n=Yu(e),o=n>=0?n:i+n;return o<0||o>=i?void 0:t[o]}});Zu("at")});var va=h((iv,fa)=>{"use strict";ma();var Ju=wt();fa.exports=Ju("Array","at")});var ya=h((nv,ba)=>{"use strict";var ep=va();ba.exports=ep});var Zr=h((ov,ga)=>{"use strict";var tp=ya();ga.exports=tp});var Oa=h((Yv,Ra)=>{"use strict";var pp=Pr(),hp=_r(),Sa=pp("keys");Ra.exports=function(r){return Sa[r]||(Sa[r]=hp(r))}});var Pa=h((Zv,ka)=>{"use strict";var dp=U();ka.exports=!dp(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var Fa=h((Jv,La)=>{"use strict";var mp=Ie(),fp=G(),vp=Be(),bp=Oa(),yp=Pa(),_a=bp("IE_PROTO"),ni=Object,gp=ni.prototype;La.exports=yp?ni.getPrototypeOf:function(r){var e=vp(r);if(mp(e,_a))return e[_a];var t=e.constructor;return fp(t)&&e instanceof t?t.prototype:e instanceof ni?gp:null}});var Ma=h((eb,Va)=>{"use strict";Va.exports={}});var ja=h((tb,$a)=>{"use strict";var Cp=W(),oi=Ie(),Ep=je(),Tp=Dr().indexOf,Ip=Ma(),Na=Cp([].push);$a.exports=function(r,e){var t=Ep(r),i=0,n=[],o;for(o in t)!oi(Ip,o)&&oi(t,o)&&Na(n,o);for(;e.length>i;)oi(t,o=e[i++])&&(~Tp(n,o)||Na(n,o));return n}});var qa=h((rb,Ba)=>{"use strict";Ba.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var Ha=h((ib,Da)=>{"use strict";var xp=ja(),Ap=qa();Da.exports=Object.keys||function(e){return xp(e,Ap)}});var Qa=h((nb,Ka)=>{"use strict";var Ga=pe(),wp=U(),za=W(),Sp=Fa(),Rp=Ha(),Op=je(),kp=vr().f,Wa=za(kp),Pp=za([].push),_p=Ga&&wp(function(){var r=Object.create(null);return r[2]=2,!Wa(r,2)}),Ua=function(r){return function(e){for(var t=Op(e),i=Rp(t),n=_p&&Sp(t)===null,o=i.length,a=0,l=[],s;o>a;)s=i[a++],(!Ga||(n?s in t:Wa(t,s)))&&Pp(l,r?[s,t[s]]:t[s]);return l}};Ka.exports={entries:Ua(!0),values:Ua(!1)}});var Xa=h(()=>{"use strict";var Lp=Ue(),Fp=Qa().values;Lp({target:"Object",stat:!0},{values:function(e){return Fp(e)}})});var Za=h((sb,Ya)=>{"use strict";Xa();var Vp=Ct();Ya.exports=Vp.Object.values});var es=h((lb,Ja)=>{"use strict";var Mp=Za();Ja.exports=Mp});var Qt=h((cb,ts)=>{"use strict";var Np=es();ts.exports=Np});var pi=h((Lb,ss)=>{"use strict";var Hp=$e();ss.exports=Array.isArray||function(e){return Hp(e)==="Array"}});var cs=h((Fb,ls)=>{"use strict";var Up=TypeError,Gp=9007199254740991;ls.exports=function(r){if(r>Gp)throw Up("Maximum allowed index exceeded");return r}});var hs=h((Vb,ps)=>{"use strict";var zp=pi(),Wp=ze(),Kp=cs(),Qp=Nr(),us=function(r,e,t,i,n,o,a,l){for(var s=n,c=0,m=a?Qp(a,l):!1,f,v;c<i;)c in t&&(f=m?m(t[c],c,e):t[c],o>0&&zp(f)?(v=Wp(f),s=us(r,e,f,v,s,o-1)-1):(Kp(s+1),r[s]=f),s++),c++;return s};ps.exports=us});var fs=h((Mb,ms)=>{"use strict";var Xp=qe(),Yp=Xp("toStringTag"),ds={};ds[Yp]="z";ms.exports=String(ds)==="[object z]"});var bs=h((Nb,vs)=>{"use strict";var Zp=fs(),Jp=G(),Yt=$e(),eh=qe(),th=eh("toStringTag"),rh=Object,ih=Yt(function(){return arguments}())==="Arguments",nh=function(r,e){try{return r[e]}catch(t){}};vs.exports=Zp?Yt:function(r){var e,t,i;return r===void 0?"Undefined":r===null?"Null":typeof(t=nh(e=rh(r),th))=="string"?t:ih?Yt(e):(i=Yt(e))==="Object"&&Jp(e.callee)?"Arguments":i}});var gs=h(($b,ys)=>{"use strict";var oh=W(),ah=G(),hi=It(),sh=oh(Function.toString);ah(hi.inspectSource)||(hi.inspectSource=function(r){return sh(r)});ys.exports=hi.inspectSource});var As=h((jb,xs)=>{"use strict";var lh=W(),ch=U(),Cs=G(),uh=bs(),ph=Et(),hh=gs(),Es=function(){},Ts=ph("Reflect","construct"),di=/^\s*(?:class|function)\b/,dh=lh(di.exec),mh=!di.test(Es),nt=function(e){if(!Cs(e))return!1;try{return Ts(Es,[],e),!0}catch(t){return!1}},Is=function(e){if(!Cs(e))return!1;switch(uh(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return mh||!!dh(di,hh(e))}catch(t){return!0}};Is.sham=!0;xs.exports=!Ts||ch(function(){var r;return nt(nt.call)||!nt(Object)||!nt(function(){r=!0})||r})?Is:nt});var Os=h((Bb,Rs)=>{"use strict";var ws=pi(),fh=As(),vh=Te(),bh=qe(),yh=bh("species"),Ss=Array;Rs.exports=function(r){var e;return ws(r)&&(e=r.constructor,fh(e)&&(e===Ss||ws(e.prototype))?e=void 0:vh(e)&&(e=e[yh],e===null&&(e=void 0))),e===void 0?Ss:e}});var Ps=h((qb,ks)=>{"use strict";var gh=Os();ks.exports=function(r,e){return new(gh(r))(e===0?0:e)}});var _s=h(()=>{"use strict";var Ch=Ue(),Eh=hs(),Th=Be(),Ih=ze(),xh=Ge(),Ah=Ps();Ch({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=Th(this),i=Ih(t),n=Ah(t,0);return n.length=Eh(n,t,t,i,0,e===void 0?1:xh(e)),n}})});var Ls=h(()=>{"use strict";var wh=At();wh("flat")});var Vs=h((zb,Fs)=>{"use strict";_s();Ls();var Sh=wt();Fs.exports=Sh("Array","flat")});var Ns=h((Wb,Ms)=>{"use strict";var Rh=Vs();Ms.exports=Rh});var js=h((Kb,$s)=>{"use strict";var Oh=Ns();$s.exports=Oh});var Pi="1.0.39-dev.f4da114d.0";import{fromEvent as da,Subscription as Wu}from"@vkontakte/videoplayer-shared/es2018";var nr=class{constructor(e){this.layout=e}},ct=class extends nr{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} + ${2e-4}))`,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))`}};import{Subject as bl}from"@vkontakte/videoplayer-shared/es2018";function _i(r){return"features"in r}var M=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};function ut({emitter$:r,error:e,subjectId:t,message:i="",severity:n=1,category:o=1}){let a=new M(n,o,{message:i,error:e,details:{id:t}});r.next(a)}var ge=class{constructor(e,t){this.error$=new bl;this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&_i(this.options)&&this.options.features[e]}onError(e="",t){ut({emitter$:this.error$,error:t,message:e,subjectId:this.container.id})}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){var e;return((e=this.container.controls)==null?void 0:e.reduce((t,i)=>{let n=i.type.trim().toLowerCase(),o=this.factories.get(n);if(o){let a=o(i,this.options);if(a)return[...t,a]}return[...t]},[]))||[]}};import{fromEvent as Ke,once as ia}from"@vkontakte/videoplayer-shared/es2018";var oe=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,ae=r=>oe(r,"Object"),pt=r=>oe(r,"String"),ht=r=>oe(r,"Array"),dt=r=>oe(r,"Number"),Li=r=>oe(r,"Function"),Fi=r=>oe(r,"Boolean"),sr=r=>dt(r)&&!isNaN(r);var ce=r=>ae(r)&&Object.keys(r).length===0,lr=r=>ht(r)&&!r.length;var Le=(r,e)=>pt(r)&&(e?r.trim():r).length;function Fe(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var Vi="interactive",_={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},Mi=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Mi||{}),Ni=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(Ni||{}),$i=(i=>(i.start="left",i.end="right",i.center="center",i))($i||{}),mt=({target:r,props:e})=>{var t,i,n;r.style.alignItems=(t=(e==null?void 0:e.gravityVertical)&&Mi[e.gravityVertical])!=null?t:"center",r.style.justifyContent=(i=(e==null?void 0:e.gravityHorizontal)&&Ni[e.gravityHorizontal])!=null?i:"center",r.style.textAlign=(n=(e==null?void 0:e.alignment)&&$i[e.alignment])!=null?n:"center"},ft=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,o,a,l,s,c;r.style.color=(o=(n=e==null?void 0:e.text)==null?void 0:n.color)!=null?o:t.textColor,r.style.fontSize=`calc(${i.height} * ${(l=(a=e==null?void 0:e.text)==null?void 0:a.size)!=null?l:t.textSize})`,r.textContent=(c=(s=e==null?void 0:e.text)==null?void 0:s.value)!=null?c:t.textContent},vt=({target:r,props:e,fallback:t})=>{var i,n,o,a;r.style.backgroundColor=Fe((n=(i=e==null?void 0:e.background)==null?void 0:i.color)!=null?n:t.backgroundColor,(a=(o=e==null?void 0:e.background)==null?void 0:o.alpha)!=null?a:t.backgroundAlpha)},Ve=({target:r,props:e,fallback:t,dependsOn:i,useRawValues:n=!1})=>{var l,s,c,m,f,v,y,C,E,d,u;let o=n?t.borderWidthRawValue:`calc(${i.height} * ${(c=(s=(l=e==null?void 0:e.shape)==null?void 0:l.border)==null?void 0:s.width)!=null?c:t.borderWidth})`,a=n?t.roundCornersRawValue:`calc(${i.height} * ${(f=(m=e==null?void 0:e.shape)==null?void 0:m.roundCorners)!=null?f:t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Fe(n?t.borderColor:(C=(y=(v=e==null?void 0:e.shape)==null?void 0:v.border)==null?void 0:y.color)!=null?C:t.borderColor,n?t.borderAlpha:(u=(d=(E=e==null?void 0:e.shape)==null?void 0:E.border)==null?void 0:d.alpha)!=null?u:t.borderAlpha),r.style.borderRadius=a},ji=({target:r,isDark:e,baseDimension:t,fallback:i})=>{let a=Fe(i.shadowColorLight,i.shadowColorAlpha),l=Fe(i.shadowColorDark,i.shadowColorAlpha),s=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,m=`0px 0px ${s} ${c} ${e?l:a}`;r.style.boxShadow=m},Ce=({target:r,layoutParams:e,fallback:t})=>{var n;let i=(n=e.angle)!=null?n:t.angle;i=i&&i*-1,r.style.transform=`rotate(${i}rad)`};import{fromEvent as We,Subject as Du,Subscription as Hu}from"@vkontakte/videoplayer-shared/es2018";var cr="interactive-control-tap",Ee={common:cr,animation:`${cr}-animation`,visible:`${cr}-visible`};var yl=60,bt=class{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:i=yl,useDimensionsBasedSize:n=!1}){this.onElementClick=e=>{if(!e.target||!e.currentTarget||this.clickCancelCondition())return;let t=e.currentTarget.parentElement;if(!t)return;let i=t.getBoundingClientRect(),n={width:this.useDimensionsBasedSize?t.offsetWidth:this.circleDiameterPx,height:this.useDimensionsBasedSize?t.offsetHeight:this.circleDiameterPx},o=Math.min(n.width,n.height),a=i.left+i.width/2,l=i.top+i.height/2,s=e.clientX-a,c=e.clientY-l,m=gl(s,c,this.controlRotateAngleRad);this.element.style.width=o+"px",this.element.style.left=m.x+i.width/2-o/2+"px",this.element.style.top=m.y+i.height/2-o/2+"px",this.element.classList.add(Ee.visible,Ee.animation)};this.onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(Ee.visible,Ee.animation)};let o=document.createElement("div");o.classList.add(Ee.common),this.controlRotateAngleRad=e,this.element=o,this.clickCancelCondition=t,this.circleDiameterPx=i,this.useDimensionsBasedSize=n}};function gl(r,e,t){return{x:r*Math.cos(t)-e*Math.sin(t),y:r*Math.sin(t)+e*Math.cos(t)}}var ur="int",ue=(i=>(i.AREA=`${ur}_area`,i.TEXT=`${ur}_text`,i.BUTTON=`${ur}_bttn`,i))(ue||{});function pr(r){return"features"in r}var X="interactive-control",k={common:X,selected:`${X}-selected`,wrapper:`${X}-wrapper`,disabled:`${X}-disabled`,button:`${X}-button`,area:`${X}-area`,text:`${X}-text`,blinkAnim:`${X}-blink-anim`,blinkAnimButton:`${X}-blink-anim-button`,blinkAnimArea:`${X}-blink-anim-area`},Bi=40;var Zo=ee(St(),1);import{isSupportedManifest as Ot,ContainerTypes as jm,ControlTypes as kt,EventActionTypes as R,EventTypes as Bm,migrateManifestToLatestVersion as Yo,compareVersions as qm}from"@interactiveplatform/movika-manifest";var Qo={metadata:"Object",chapters:"Array"},Xo=r=>{if(!ae(r))return!1;for(let e in Qo)if(!r[e]||!oe(r[e],Qo[e]))return!1;return Ot(r.metadata.version)},Rt=r=>r.type===kt.Text,km=r=>r.type===kt.Button,Pm=r=>r.type===kt.Area,_m={Choice:"Choice",TextInput:"TextInput"},Lm={Button:"Button",Area:"Area",Text:"Text"},Fm={onClick:"onClick",onSuspense:"onSuspense"},Vm={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var Pt=r=>ht(r)&&!lr(r),Z=r=>r.order==="end",_t=r=>ht(r.containers)&&!lr(r.containers)&&Z(r),Jo=(r,e)=>{var i;let t=r*1e3;return Pt(e.controls)&&t<((i=e.startTime)!=null?i:0)},Hr=(r,e)=>{var i,n;let t=r*1e3;return Pt(e.controls)&&t>=((i=e.startTime)!=null?i:0)&&t<=((n=e.endTime)!=null?n:1/0)};var he=(r=[])=>r.some(e=>e.action.type==="expect"),Ur=(r=[])=>r.find(e=>e.action.type==="expect"),qu=r=>(r==null?void 0:r.length)===1,Se=r=>qu(r)&&Rt(r[0]);function ea(r=[],e=1/0,t=[]){return r.filter(({container:i})=>!(0,Zo.default)(t,i.container.id)&&he(i.container.events)&&i.container.endTime===e&&!i.isRemoved&&!i.willRemoved)}function Lt({gameControllers:r=[],subjectName:e,subjectId:t,execFn:i}){for(let n of r)if(e==="container"&&n.container.container.id===t){i(n),ea(r,n.container.container.endTime,[n.container.container.id]).forEach(a=>{i(a)});break}}function ta(r){for(let e of r.events)if(e.action.type==="openURI")return!0;return!1}var ra=(r,e)=>{let t=E=>{let d=e.find(({container:u})=>u.container.id===E);return d==null?void 0:d.container.isRemoved},i=he(r.events)&&!t(r.id),n=(E,d=!1,u=!1)=>{let p=u?"every":"some";return E.controls[p](b=>{var x;let I=d?E.endTime===r.endTime:!0;return((x=b.events)==null?void 0:x[p](g=>{var T;return((T=g.action)==null?void 0:T.type)===R.openURI}))&&I})},o=E=>E.some(({container:d})=>n(d.container,!0,!1)&&!d.isRemoved),a=E=>E.every(({container:d})=>d.isRemoved||d.willRemoved?!0:n(d.container,!0,!0)),l=ea(e,r.endTime,[r.id]).length,s=E=>E.controls.some(d=>{var u;return(u=d.events)==null?void 0:u.some(p=>{var b,I;return(I=(b=p.action)==null?void 0:b.args)==null?void 0:I.shouldOpenNow})}),c=i||l>0,m=o(e),f=n(r),v=a(e),y=i?!1:l>0,C=s(r);return{isExpectTime:c,hasOtherExpect:l>0,hasOpenURIEvent:m,hasOpenURIEventInCurrentContainer:f,isAllOpenURIEventsValid:v,isExpectEventForCurrentContainer:y,hasShouldOpenNowEvent:C}};var se=class r{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new Hu;this.error$=new Du;this.isInteracted=!1;this.isRemoved=!1;this.onControlSelect=()=>{var e,t,i;(e=this.container)!=null&&e.isManifestContainerDisabled()||ta(this.control)||(i=(t=this.container)==null?void 0:t.element)==null||i.classList.add("interactive-control-wrapper-selected")};this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()}}removeView(e=!1){let t=this.getElement();if(t){if(e){if(t.classList.contains("interactive-control-before-remove"))return;t.classList.add("interactive-control-before-remove"),this.subscriptions.add(We(t,"transitionend").subscribe(this.onTransitionEnd,n=>this.onError(`${r.name} remove view transition error`,n))).add(We(t,"transitioncancel").subscribe(this.onTransitionEnd,n=>this.onError(`${r.name} remove view transition error`,n)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e="",t){ut({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){var t;if(this.featureIsEnabled("controlsTapPlace")&&this.container){let i=(t=this.control.layoutParams.angle)!=null?t:_.angle;this.controlTap=new bt({controlRotateAngleRad:i,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?Bi:void 0}),this.subscriptions.add(We(e,"click").subscribe(this.controlTap.onElementClick,n=>this.onError("Control click tap animation error",n))).add(We(this.controlTap.element,"animationend").subscribe(this.controlTap.onAnimationEnd,n=>this.onError("Tap animationend error",n))),this.container.element.append(this.controlTap.element)}}createContainerElement(e){var o;let t=document.createElement("div");t.classList.add(k.wrapper),e.setControlLayout(t,this.control.layoutParams);let i=((o=this.control.layoutParams.innerSizesDependOn)!=null?o:_.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"},n=()=>{var a,l;return(l=(a=e.isContainerDisabled)==null?void 0:a.call(e))!=null?l:!1};this.container={element:t,dimensions:i,isManifestContainerDisabled:n}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return this.options&&pr(this.options)&&this.options.features[e]}isTouch(){return this.options&&pr(this.options)&&this.options.isTouch}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(We(this.container.element,"click").subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),n=>this.onError("Error happened on control interaction",n)));break}default:break}})}removeListeners(){this.subscriptions.unsubscribe()}};var Gr="interactive-blink-anim-reference",N={common:Gr,animation:`${Gr}-animation`,disabled:`${Gr}-disabled`},Ft=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(N.common,N.animation),this._element=e}restart(){this._element&&(this._element.classList.add(N.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(N.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var zr="interactive-container",$={common:zr,hidden:`${zr}-hidden`,disabled:`${zr}-disabled`};var Vt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new Wr(r,e)},Wr=class extends se{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("button");i.type="button",i.classList.add(k.common,k.area),i.setAttribute("data-testid",ue.AREA),vt({target:i,props:this.control.props,fallback:{..._,backgroundColor:"transparent"}}),Ce({target:i,layoutParams:this.control.layoutParams,fallback:_}),this.addControlTap(i),this.subscriptions.add(Ke(this.container.element,"click").pipe(ia()).subscribe(this.onControlSelect,n=>this.onError("Control click handler error",n))),this.container.element.append(i),e.append(this.container.element),this.controlElement=i,this.updateShadowStyles(),this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){var t;if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=(t=this.container)==null?void 0:t.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(Ke(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains($.disabled))return;let i=e.parentElement;if(i){let n=i.querySelector(`.${N.common}`);n&&this.syncBlinkAnimation(n)}},i=>this.onError("Error happened in mouseleave callback",i))),this.subscriptions.add(Ke(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains($.disabled)||this.onBlinkHovering()},i=>this.onError("Error happened in mouseenter callback",i))).add(Ke(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},i=>this.onError("Error happened in mouseleave callback",i))))}disable(){this.controlElement&&this.controlElement.classList.add(k.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(k.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){var t,i,n;if(!(!this.container||!this.controlElement))if(Fi(e)){let o=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";ji({target:this.controlElement,props:this.control.props,fallback:_,isDark:e,baseDimension:o}),Ve({target:this.controlElement,props:this.control.props,fallback:{..._,borderColor:e?_.shadowColorDark:_.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${(n=(i=(t=this.control.props)==null?void 0:t.shape)==null?void 0:i.roundCorners)!=null?n:_.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Ve({target:this.controlElement,props:this.control.props,fallback:{..._,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){var t,i;(t=this.controlElement)==null||t.classList.toggle(k.blinkAnim,e),(i=this.controlElement)==null||i.classList.toggle(k.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${k.blinkAnimArea}`)||this.controlElement.classList.contains(k.selected)||this.controlElement.classList.contains(N.disabled)||(this.controlElement.classList.add(N.disabled),this.subscriptions.add(Ke(e,"animationiteration").pipe(ia()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(N.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${k.blinkAnimArea}`)||this.controlElement.classList.contains(k.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)})}setShowTimeRange(){}updateFillAnimationDimensions(){}onProgress(){}onResize(){}};import{fromEvent as Qe,once as pa}from"@vkontakte/videoplayer-shared/es2018";var Mt=r=>{let e=document.createElement("span");switch(r){case"Button":case"button":{let t=document.createElement("div"),i={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(t.style,i),t.append(e);let n={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,n),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 Nt=Math.PI,Kr=2*Nt,$t=Nt/2,na=3*$t,Uu=0,Gu=[Uu,$t,Nt,na];function oa(r){return r===$t}function aa(r){return r===Nt}function sa(r){return r===na}function la(r){return(r%Kr+Kr)%Kr}function zu(r){for(let e of Gu)if(r===e)return e}function ca(r){if(zu(r))return null;let t=Math.floor(r/$t)+1;return[1,2,3,4][t-1]}function ua(r){return r*180/Math.PI}var te="interactive-control-fill-animation",j={common:te,fillerWrapper:`${te}-filler-wrapper`,filler:`${te}-filler`,fillHeight:`${te}-fill-height`,fillWidth:`${te}-fill-width`,fromTop:`${te}-from-top`,fromBottom:`${te}-from-bottom`,fromLeft:`${te}-from-left`,fromRight:`${te}-from-right`};var jt=class r{constructor(e){this.widthExpansionCoef=0;var d;let t=document.createElement("div");t.classList.add(j.common);let i=document.createElement("div");i.classList.add(j.fillerWrapper);let n=document.createElement("div");n.classList.add(j.filler),i.append(n),t.append(i);let o=la(e.rotateAngle),a=ca(o),l=a!==null,c=a===2||!l&&aa(o)||a===3,m=!l&&oa(o),f=!l&&sa(o),v=!c&&!m&&!f,y=m||f,C=l&&!y,E=C?o:0;t.style.borderRadius=e.borderRadius,i.style.transform=`skew(${E*-1}rad)`,y?(n.classList.add(j.fillHeight,m?j.fromTop:j.fromBottom),i.classList.add(j.fillHeight,m?j.fromTop:j.fromBottom)):(n.classList.add(j.fillWidth,v?j.fromLeft:j.fromRight),i.classList.add(j.fillWidth)),e.debug&&console.log(`[interactive ${r.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:y,rotateAngleRad:o,rotateAngelDeg:ua(o),rotateAngleRaw:e.rotateAngle,fromRight:c,fromTop:m,fromBottom:f,fromLeft:v}),this.useSkew=C,this.fromLeft=v,this.rotateAngle=o,this.fillAnimationElement=t,this.fillAnimationFillerElement=n,this.fillAnimationFillerWrapperElement=i,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=y,this.isDebug=(d=e.debug)!=null?d:!1}updateDimension(e){this.fillAnimationElement.style.top=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.left=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.width=`${e.width}px`,this.fillAnimationElement.style.height=`${e.height}px`;let t=this.calcWidthExpansionCoef({rotateAngle:this.rotateAngle,isSkewed:this.useSkew,initWidth:e.width,initHeight:e.height});!this.shouldFillHeight&&(this.fillAnimationFillerWrapperElement.style.width=100*t+100+"%",this.fillAnimationFillerWrapperElement.style[`${this.fromLeft?"left":"right"}`]=`calc((${t} * 100%) / 2 * -1)`),this.widthExpansionCoef=t}updateAnimation(e){if((o=>o<this.startTime||o>this.endTime)(e))return;let i=this.endTime-this.startTime,n=Math.min(Math.max((e-this.startTime)/i,0),1);this.shouldFillHeight?this.fillAnimationFillerElement.style.transform=`scaleY(${n})`:this.fillAnimationFillerElement.style.transform=`scaleX(${n})`}calcWidthExpansionCoef({rotateAngle:e,isSkewed:t=!1,initWidth:i,initHeight:n}){return t?(i+n*Math.abs(Math.tan(e)))/i-1:0}};var Bt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Qr(r,e)},Qr=class extends se{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var a,l,s,c,m,f;if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("button");i.type="button",i.classList.add(k.common,k.button),i.setAttribute("data-testid",ue.BUTTON),Ce({target:i,layoutParams:this.control.layoutParams,fallback:_}),vt({target:i,props:this.control.props,fallback:_}),Ve({target:i,props:this.control.props,fallback:_,dependsOn:this.container.dimensions}),mt({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=Mt(this.control.type.trim().toLowerCase()),o=(a=n.firstElementChild)!=null?a:n;ft({target:o,props:this.control.props,fallback:_,dependsOn:this.container.dimensions}),this.addControlTap(i),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled("controlsFillAnimation")&&(this.controlFillAnimation=new jt({startTime:this.startTime,endTime:this.endTime,rotateAngle:(l=this.control.layoutParams.angle)!=null?l:_.angle,borderRadius:i.style.borderRadius})),this.subscriptions.add(Qe(i,"click").pipe(pa()).subscribe(this.onControlSelect,v=>this.onError("Control click handler error",v))),i.append(n,(c=(s=this.controlFillAnimation)==null?void 0:s.fillAnimationElement)!=null?c:""),this.container.element.append((f=(m=this.controlTap)==null?void 0:m.element)!=null?f:"",i),e.append(this.container.element),this.controlElement=i,this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){var t;if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=(t=this.container)==null?void 0:t.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(Qe(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains($.disabled))return;let i=e.parentElement;if(i){let n=i.querySelector(`.${N.common}`);n&&this.syncBlinkAnimation(n)}},i=>this.onError("Error happened in mouseleave callback",i))),this.subscriptions.add(Qe(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains($.disabled)||this.onBlinkHovering()},i=>this.onError("Error happened in mouseenter callback",i))).add(Qe(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},i=>this.onError("Error happened in mouseleave callback",i))))}disable(){this.controlElement&&this.controlElement.classList.add(k.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(k.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){var t,i;(t=this.controlElement)==null||t.classList.toggle(k.blinkAnim,e),(i=this.controlElement)==null||i.classList.toggle(k.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${k.blinkAnimButton}`)||this.controlElement.classList.contains(k.selected)||this.controlElement.classList.contains(N.disabled)||(this.controlElement.classList.add(N.disabled),this.subscriptions.add(Qe(e,"animationiteration").pipe(pa()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(N.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${k.blinkAnimButton}`)||this.controlElement.classList.contains(k.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)})}updateFillAnimationDimensions(){if(!this.container||!this.controlElement||!this.controlFillAnimation)return;let e=getComputedStyle(this.controlElement),t={width:parseFloat(e.width),height:parseFloat(e.height),borderWidth:parseFloat(e.borderWidth)||0};this.controlFillAnimation.updateDimension(t)}setShowTimeRange(e,t){this.startTime=e,this.endTime=t}onProgress(e){var t;(t=this.controlFillAnimation)==null||t.updateAnimation(e)}onResize(){this.updateFillAnimationDimensions()}updateShadowStyles(){}};var ha=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Xr(r,e)},Xr=class extends se{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){var a;if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("div");i.classList.add(k.common,k.text),i.setAttribute("data-testid",ue.TEXT),Ce({target:i,layoutParams:this.control.layoutParams,fallback:_}),mt({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=Mt(this.control.type.trim().toLowerCase()),o=(a=n.firstElementChild)!=null?a:n;ft({target:o,props:this.control.props,fallback:_,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}updateShadowStyles(){}toggleBlinkAnimation(){}setShowTimeRange(){}updateFillAnimationDimensions(){}};var qt=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new Yr(r,e,t)},Yr=class r extends ge{constructor(t,i,n){super(t,n);this.containerElement=null;this.subscriptions=new Wu;this.onTransitionEnd=t=>{t.stopPropagation(),!(!t.target||!t.currentTarget)&&t.target===t.currentTarget&&this.removeView()};this.rootElement=i,this.layout=new ct(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Bt),this.addControlFactory("text",ha),this.addControlFactory("area",Vt)}createView({eventCallback:t,videoDurationMs:i}){let n=document.createElement("div");return n.classList.add($.common,$.disabled),requestAnimationFrame(()=>{n.classList.remove($.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(o=>{var a;o.setShowTimeRange(this.container.startTime,(a=this.container.endTime)!=null?a:i),o.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout,isContainerDisabled:()=>this.isDisabled}}),o.setEvents(t),this.subscriptions.add(o.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.willRemoved=!1,this.containerElement=n,this.updateControlsFillAnimationDimensions(),n}updateControlsFillAnimationDimensions(){for(let t of this.controls)t.updateFillAnimationDimensions()}hide(){let t=this.getElement();t&&t.classList.add($.hidden)}show(){let t=this.getElement();t&&t.classList.remove($.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove($.disabled),this.controls.forEach(i=>i.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add($.disabled),this.controls.forEach(i=>i.disable()),this.isDisabled=!0)}removeView(t=!1,i=!1){let n=this.getElement();if(n){if(t){if(this.willRemoved)return;this.willRemoved=!0,i&&n.classList.add("interactive-container-before-remove-delay"),n.classList.add("interactive-container-before-remove"),this.subscriptions.add(da(n,"transitionend").subscribe(this.onTransitionEnd,a=>this.onError(`${r.name} remove view transition error`,a))).add(da(n,"transitioncancel").subscribe(this.onTransitionEnd,a=>this.onError(`${r.name} remove view transition error`,a)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}removeAllControls(t=!1){this.controls.forEach(i=>i.removeView(t))}removeNonInteractedControls(t=!1){this.controls.forEach(i=>{i.isInteracted||i.removeView(t)})}isInteracted(){return this.controls.some(t=>t.isInteracted)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(t,i){i&&this.controls.forEach(n=>{n.onProgress(t)})}onResize(t){t&&this.controls.forEach(i=>{i.onResize()})}updateControlsShadowStyles(t){this.controls.forEach(i=>i.updateShadowStyles(t))}toggleBlinkAnimation(t){this.controls.forEach(i=>i.toggleBlinkAnimation(t))}};var cl=ee(Zr(),1);import{combine as qh,InterfaceLanguage as Dh,Observable as al,once as Hh,Subject as B,Subscription as gi,ValueSubject as D,fromEvent as sl}from"@vkontakte/videoplayer-shared/es2018";import{InteractiveInterfaceClick as st}from"@vkontakte/videoplayer-statistics/es2018";import{loadVKLangPack as rp}from"@vkontakte/videoplayer-shared/es2018";function Xe(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var Ca="video_interactive",Ea="videoint";var Ta=250,Ye=class{constructor(e){this.handleZoomChange=Xe(e=>{this.lastZoomInfo=e},Ta);this.onResize=e=>{var i;if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&((i=this.ngEditor)==null||i.zoomTo(t,void 0,{isFromCenter:!0})),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{var t,i,n;if(this.manifest){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.call(this,"Chapter id is not found");return}this.visitedChapterIds.add(e.id),(i=this.ngEditor)==null||i.selectChapter(e.id),(n=this.ngEditor)==null||n.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{var i;if(this.isReady=!1,!dt(e.graph.edit.chapters[0].x)){(i=this.onError)==null||i.call(this,"Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:i,lang:n,visitedChapters:o=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(o),this.onOpenPreviewClick=t,this.onError=i,this.lang=n!=null?n:"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=ip(e),this.resizeObserver=new ResizeObserver(Xe(this.onResize,Ta)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){var t;this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),(t=this.ngEditor)==null||t.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){var t;(t=this.ngEditor)==null||t.updateVideosInfo(e)}async show(){var e;this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&((e=this.ngEditor)==null||e.focusChapter(this.currentChapterId)),this.isHidden=!1)}async initNgEditor(){var i;if(!this.manifest)return;let e;try{e=await rp(this.lang,Ca,Ea)}catch(n){(i=this.onError)==null||i.call(this,"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,...o})=>{var a;n==="openPreview"&&"chapterId"in o&&((a=this.onOpenPreviewClick)==null||a.call(this,o.chapterId))}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.manifest=null,this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function ip(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 Ze=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,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let o of this._containers){let a=o.startTime-e;if(a<=n&&(o.endTime&&n<=o.endTime||o.endTime===null)){i=!0;break}n<a&&(t=t===-1?a:Math.min(t,a))}return!i&&t!==-1?t:null}}};var Dt=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 i=()=>{t(),this.off(e,i)};return this.listeners[e].push(i),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let i=this.listeners[e]||[];for(let n=i.length;n>0;n--)if(i[n]===t){i.splice(n,1);break}return this}emit(e,...t){let i=this.listeners[e];return i?(i.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Ht=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{Li(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(i=>i!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as up}from"@vkontakte/videoplayer-shared/es2018";var Ut=class{constructor(e){var t,i;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(i=e==null?void 0:e.manifestLoaders)!=null?i:[]}}async exec(e,t){return np(...this.loaders[e])(t)}};function np(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function Je(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function Gt({actions:r,errors:e,chapterId:t,...i}){if(t){let n=r.getManifest();if(n){let o=r.getChapter(n.chapters,t);if(o){let a=r.getMedia(n.media,o.videoId),l=r.getGraph(n.graph,o.id);return a?{...i,actions:r,errors:e,result:{chapter:o,media:a,graph:l}}:{...i,errors:Je(e,Gt.name,"Could not find media"),actions:r}}}}return{...i,errors:Je(e,Gt.name,"Could not find chapter"),actions:r}}var{NativeAbortSignal:Iv,NativeAbortController:xv}=function(r){return{NativeAbortSignal:r.AbortSignal,NativeAbortController:r.AbortController}}(typeof self!="undefined"?self:global);function Ia(r){let e;try{e=new Event("abort")}catch(t){typeof document!="undefined"?document.createEvent?(e=document.createEvent("Event"),e.initEvent("abort",!1,!1)):(e=document.createEventObject(),e.type="abort"):e={type:"abort",bubbles:!1,cancelable:!1}}return e.reason=r,e}function xa(r){if(r===void 0)if(typeof document=="undefined")r=new Error("This operation was aborted"),r.name="AbortError";else try{r=new DOMException("signal is aborted without reason"),Object.defineProperty(r,"name",{value:"AbortError"})}catch(e){r=new Error("This operation was aborted"),r.name="AbortError"}return r}var zt=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,o=i.length;n<o;n++)if(i[n].callback===t){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,o=i.length;n<o;n++){let a=i[n];try{a.callback.call(this,e)}catch(l){Promise.resolve().then(()=>{throw l})}a.options&&a.options.once&&this.removeEventListener(e.type,a.callback)}return!e.defaultPrevented}},Re=class extends zt{constructor(){super(),this.listeners||zt.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)}throwIfAborted(){let{aborted:e,reason:t="Aborted"}=this;if(e)throw t}static timeout(e){let t=new de;return setTimeout(()=>t.abort(new DOMException(`This signal is timeout in ${e}ms`,"TimeoutError")),e),t.signal}static any(e){let t=new de;function i(){t.abort(this.reason),n()}function n(){for(let o of e)o.removeEventListener("abort",i)}for(let o of e)if(o.aborted){t.abort(o.reason);break}else o.addEventListener("abort",i);return t.signal}},de=class{constructor(){Object.defineProperty(this,"signal",{value:new Re,writable:!0,configurable:!0})}abort(e){let t=xa(e),i=Ia(t);this.signal.reason=t,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(de.prototype[Symbol.toStringTag]="AbortController",Re.prototype[Symbol.toStringTag]="AbortSignal");function Wt(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 Jr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!Wt({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:o};let o=t;(o&&!o.prototype.hasOwnProperty("signal")||n)&&(o=function(c,m){let f;m&&m.signal&&(f=m.signal,delete m.signal);let v=new t(c,m);return f&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),v},o.prototype=t.prototype);let a=e;return{fetch:(s,c)=>{let m=o&&o.prototype.isPrototypeOf(s)?s.signal:c?c.signal:void 0;if(m){let f;try{f=new DOMException("Aborted","AbortError")}catch(y){f=new Error("Aborted"),f.name="AbortError"}if(m.aborted)return Promise.reject(f);let v=new Promise((y,C)=>{m.addEventListener("abort",()=>C(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([v,a(s,c)])}return a(s,c)},Request:o}}var op=()=>"fetch"in window,et=op()&&Wt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Aa=et?Jr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,ei=et?Aa.fetch:window.fetch,Fv=et?Aa.Request:window.Request,Vv=et?de:window.AbortController,Mv=et?Re:window.AbortSignal;var ti=(r="",e="")=>{let t=r.split("."),i=e.split("."),n=0;for(let o=0;o<Math.max(t.length,i.length)&&!n;o++)t[o]>i[o]?n=1:t[o]<i[o]?n=-1:n=0;return n};var ap=async r=>{try{let e={},t;if(pt(r)){t=new URL(r).href;let n=await ei(t);if(!n.ok)return{};e=await n.json()}else if(ae(r))e=r;else return{};if(!Xo(e))return{};let i=e.metadata.media;if(pt(i)&&!("media"in e))try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let o=await ei(n);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch(n){return cp(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function wa(r){let{manifest:e,manifestURL:t}=await ap(r);if(!e)throw new Error("Failed on fetch");let i=Yo(e);return i.media=sp(i.media,t),delete i.metadata.media,i}function Kt(r,e){if(e)return r.find(t=>t.id===e)}function ri(r,e){var t,i;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(n=>n.id===e):(i=r.view)!=null&&i.chapters?r.view.chapters.find(n=>n.id===e):void 0}function ii(r,e){return r.videos.find(t=>t.id===e)}function sp(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",o=lp(n,e);return{...i,url:o||n}})}))}}function lp(r="",e){try{return new URL(r,e).href}catch(t){return""}}function cp(r){return ti(r,"3.2.0")>=0}var Oe=class extends Ut{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new up(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var n;this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:Je},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await wa((n=i.result)!=null?n:t),this}async setInitial(){return this.setNext()}async setNext(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",Gt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ri,getChapter:Kt,getMedia:ii,getByBranches:this.getByBranches.bind(this),addErrorMessage:Je},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(){var i;return this.getByChapterId((i=this.manifest)==null?void 0:i.metadata.initChapterId)||null}getByChapterId(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t||!this.manifest)return null;let n=Kt(this.manifest.chapters,t);if(n){let o=ii(this.manifest.media,n.videoId),a=ri(this.manifest.graph,n.id);if(o)return{chapter:n,media:o,graph:a}}return null}getBranches(t=(i=>(i=this.chapter)==null?void 0:i.id)()){var n,o,a;if(t===((n=this.chapter)==null?void 0:n.id))return this.getByBranches((o=this.chapter)==null?void 0:o.branches);{let l=Kt(((a=this.manifest)==null?void 0:a.chapters)||[],t);return this.getByBranches(l==null?void 0:l.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{let o=this.getByChapterId(n.chapterId);return o&&i.push(o),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){var t,i;return((t=this.chapter)==null?void 0:t.id)===((i=this.manifest)==null?void 0:i.metadata.initChapterId)}isEndChapter(){return this.chapter?Z(this.chapter):!1}};var ns=ee(Qt(),1);import{Player as $p}from"@vkontakte/videoplayer-core/es2018";import{Subscription as li,TracerFactory as jp,ValueSubject as Bp}from"@vkontakte/videoplayer-shared/es2018";var rs=r=>{let e=r.variants.find(t=>{var i;return((i=t.payload)==null?void 0:i.type)==="vk"});if(e&&e.payload){let[t,i]=e.payload.id.split("_");return[t,i]}return[]};var is=ee(Qt(),1);function ai(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:a=Math.random().toString(),...l}){let s=r.get(o),c={...l};return s?s[a]=c:r.set(o,{[a]:c}),{listId:o,itemId:a,...l}}function t(o){var a,l;o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),(a=o.statistics)==null||a.oneStat.destroy(),(l=o.statistics)==null||l.statSubscription.unsubscribe()}function i(o,a){let l=r.get(o);if(!l)throw Error("Can't remove. Not find.");if(a){let s=l[a];s&&t(s),delete l[a],Object.keys(l).length||r.delete(o)}else{for(let s of(0,is.default)(l))t(s);r.delete(o)}}function n(){for(let o of r)i(o[0])}return{createPlayer:e,removePlayer:i,map:r,removeAll:n}}var ke=ee(St(),1);function si(r,e=[]){var o,a,l;let t={},i,n=!e.length;for(let s of r.variants)if(!i&&"cover"in s&&(i=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(n||(0,ke.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[(o=s.standard)!=null?o:"Invariant quality"]:s.url});break;case"mpeg":(n||(0,ke.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[(a=s.standard)!=null?a:"Invariant quality"]:s.url});break;case"hls":(n||(0,ke.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(n||(0,ke.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:t,thumbUrl:i,title:(l=r.title)!=null?l:""}}var tt=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&(0,ke.default)(i,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var qp=2;function ci(r){let e=ai(),t=new li,i={},n=null,o=!1,a,l=new Bp(null);r&&s(r);function s(d){n=d}function c(d,u,p){var x;if(!n)throw Error("need to set interactive controller");if(!n.options)return;let I=((x=e.map.get(d))!=null?x:{})[u];if(I){i={chapterId:p,listId:d,itemId:u,...I};let g=i.player;i.subscription.add(g.info.currentQuality$.subscribe(T=>{let L=g.info.position$.getValue(),A=g.info.isAutoQualityEnabled$.getValue();if(!(!T||!L||A))for(let O of e.map)(0,ns.default)(O[1]).forEach(({player:P})=>{tt(P,T)})})).add(g.events.started$.subscribe(()=>{m(u)})),I.container.remove(),n.setPlayer(I.player),o||(n.init(),o=!0),l.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}async function m(d){if(!n)throw Error("need to set interactive controller");if(ce(i)||d!==i.itemId)return;let u=n.getChapterBranches(),p=new Set;for(let b of u)p.has(b.media.id)||(await v({media:b.media,chapterId:b.chapter.id,setAsActive:!1,title:b.chapter.label}),p.add(b.media.id))}async function f({chapter:{id:d},manifestVideo:u}){if(ce(i)||!n)return;let p=i.player.info.muted$.getValue(),b=i.player.info.currentQuality$.getValue(),I=i.player.info.isAutoQualityEnabled$.getValue(),x=i.player.info.volume$.getValue(),g=i.player.info.currentPlaybackRate$.getValue(),T=!I,L=!1;for(let A of e.map)if(A[0]===u.id&&!n.state.isReplay$.getValue()){let O=Object.keys(A[1]);for(let P of O)P===i.itemId?(O.length<qp||(L=!0),e.removePlayer(A[0],P)):(L=!0,c(A[0],P,d),T?tt(i.player,b):i.player.setAutoQuality(!0),i.player.setVolume(x),i.player.setMuted(p),i.player.setPlaybackRate(g))}else e.removePlayer(A[0]);L||(await v({media:u,chapterId:d,setAsActive:!0,playbackRate:g}),T?tt(i.player,b):i.player.setAutoQuality(!0),i.player.setVolume(x),i.player.setMuted(p))}async function v({media:d,chapterId:u,prefetch:p=!0,setAsActive:b=!0,autoplay:I=!1,preferredExt:x,title:g,playbackRate:T}){var Ei,Ti,Ii,xi,Ai;let L=Math.random().toString(),A=document.createElement("div");a.append(A);let O;if((Ei=n==null?void 0:n.options)!=null&&Ei.vkVideoLoader){let lt=rs(d);lt.length&&(O=await n.options.vkVideoLoader(...lt))}let P=((Ti=n==null?void 0:n.options)==null?void 0:Ti.coreConfig)||void 0,Q={...P,configName:[...(Ii=P==null?void 0:P.configName)!=null?Ii:[],"interactive"]},le={container:A,...((xi=O==null?void 0:O.videos)==null?void 0:xi[0])||{sources:si(d,x).sources},title:g,failoverHosts:(O==null?void 0:O.failoverHosts)||[]},q=new $p(Q,jp.createRootTracer());q.initVideo(le);let be=null;if(O!=null&&O.videos&&(n!=null&&n.options.createOneStat)){let lt=O.videos[0],ir=n.options.createOneStat(lt),wi=new li;ir&&(wi.add(ir.attachTo(q)),be={oneStat:ir,statSubscription:wi})}let Ci=new li,ul=(Ai=i==null?void 0:i.player)==null?void 0:Ai.info.isAutoQualityEnabled$.getValue();Ci.add(q.events.canplay$.subscribe(function(){ul||tt(q,i.player.info.currentQuality$.getValue()),T&&q.setPlaybackRate(T)}));let ye=e.createPlayer({listId:d.id,itemId:L,player:q,container:A,sources:si(d,x).sources,config:le,subscription:Ci,statistics:be});return b&&c(d.id,ye.itemId,u),I&&ye.player.play(),p&&!I&&ye.player.prepare(),{player:ye.player,config:ye.config,statistics:ye.statistics}}function y(){C(),n=null,a.remove()}function C(){t.unsubscribe(),e.removeAll(),i={},o=!1}async function E(){if(!n)throw Error("need to set interactive controller");C(),a=document.createElement("div");let{media:d,chapter:u}=n.getCurrentChapter();d&&u?(t.add(n.events.chapterChanged$.subscribe(f)),await v({media:d,chapterId:u.id,title:u.label})):console.error("not found")}return{...e,init:E,setInteractiveController:s,createPlayer:v,removeAll:y,getActivePlayer:function(){return i},activePlayerChanged:l}}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"},rt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},F={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as Dp}from"@vkontakte/videoplayer-shared/es2018";function ui(r){return function(...t){return r(...t.reverse())}}function it(r,...e){return(...t)=>ae(e[0])&&ae(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var Xt=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:o,globalEvents:a,globalEventEmitter:l,getContainerEventState:s,permanentTextControls:c,interactiveTimeOpenUri:m,disabledControls$:f,onRemove:v,onError:y,disableTextControlContainerVisibilityEvents:C=!1,features:E}){this.hide=()=>{setTimeout(()=>{var e,t;this.gameState!==4&&(he(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&((t=(e=this.container).hide)==null||t.call(e)),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{var t,i,n,o,a,l;if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:s}=this.getContainerEventState();if((i=(t=this.container).show)==null||i.call(t),this.interactiveTimeOpenUri&&s||this.disableTextControlContainerVisibilityEvents)return;this.emitContainerVisibilityEvent(!0,!1)}else{let s={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(f,v)=>{let{isExpectTime:y,hasOtherExpect:C,hasOpenURIEvent:E,hasOpenURIEventInCurrentContainer:d,isAllOpenURIEventsValid:u,hasShouldOpenNowEvent:p}=this.getContainerEventState(),b=this.interactiveTimeOpenUri&&!d,I=this.interactiveTimeOpenUri&&d;if((!this.interactiveTimeOpenUri||b)&&(this.isSelectedControlEvent=!0),f!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||b)){if(this.interactiveTimeOpenUri){let x=!C&&!u&&d;x&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:x})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&E&&this.gameState!==5){if(I){let g=((T,L,A,O)=>!T&&!L&&A||T&&!L&&A&&!O||T&&!L&&A&&O)(y,C,u,this.isSelectedContainerEvent);this.fakeRemoveView(g)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!y||!C||!p)&&(this.selectBranches.stopExpect(),v())}},isEOV:()=>this.gameState===4},c=it(this.selectBranches.onControlEvent,s),m=((o=(n=this.player)==null?void 0:n.info.duration$.getValue())!=null?o:1/0)*1e3;this.container.createView({eventCallback:c,videoDurationMs:m}),this.disableTextControlContainerVisibilityEvents||this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&((l=(a=this.container).disable)==null||l.call(a))}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{var s,c,m;let e=this.player.experimental.element$.getValue();if(!(e instanceof HTMLVideoElement?e.readyState:void 0)||this.isRemovedOrDestroyed()&&!this.isPermanentText)return;let n=this.player.getExactTime();if(Jo(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Hr(n,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let f=this.gameState;this.gameState=3,f===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:f}=this.getContainerEventState(),v=this.selectBranches.state.isExpect,y=this.interactiveTimeOpenUri&&f;if(y&&!v){let C=this.container.getElement();C&&(C.style.visibility!=="hidden"&&((c=(s=this.container).hide)==null||c.call(s)),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!y&&this.removeView()}let o=Hr(n,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,(m=this.container.container.endTime)!=null?m:1/0]:[],l={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:n,isInteractiveTime:o};this.container.onProgress(n*1e3,o),this.globalEventEmitter.emit(S.eachTick,l),this.globalEvents.eachTick$.next(l)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new Dp,this.player=e,this.interactiveEvents=o,this.getContainerEventState=s;let d=Se(t.container.controls);this.isPermanentText=c&&d,this.disableTextControlContainerVisibilityEvents=C&&d,this.interactiveTimeOpenUri=m,this.disabledControls$=f,this.onRemove=v,this.globalEventEmitter=l,this.gameState=0,this.globalEvents=a,this.onError=y,this.features=E,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:F.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:F.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,i,n,o;e?(i=(t=this.container).disable)==null||i.call(t):(o=(n=this.container).enable)==null||o.call(n)})),this.subscription.add(this.container.error$.subscribe(this.onError))}selectContainerEvent(e=!1){var i,n;let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:(i=this.container.container.endTime)!=null?i: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((n=this.container.container.endTime)!=null?n:1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),i=this.interactiveTimeOpenUri?e||t:he(this.container.container.events)||e;(this.isSelectedControlEvent||!i)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(e=this.features.controlsHideAnimation){var t;if(e){if(this.isRemovedOrDestroyed())return;this.container.removeNonInteractedControls(!0),this.container.removeView(!0,!0)}else this.container.removeView();this.globalEventEmitter.emit(S.interactives,{subjectId:this.container.container.id,subjectName:"container",type:F.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,(t=this.onRemove)==null||t.call(this)}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}isInteracted(){return this.container.isInteracted()}isRemovedOrDestroyed(e=!0){let t=e?this.container.willRemoved:!1;return this.gameState===5||t||this.gameState===6}destroy(e=!1){var t;this.reset(),this.removeView(e),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!=null?t:1/0,id:this.container.container.id})}};var as=(r=[])=>r.reduce((e,t,i)=>{var o,a,l;let n=((o=t==null?void 0:t.controls)!=null?o:[]).filter(s=>!Rt(s));if(Pt(n)){let s=[(a=t.startTime)!=null?a:0,(l=t.endTime)!=null?l:1/0],c={id:t.id,isRemoved:!1};if(!i)e.push({subjects:[c],range:s});else{let m=[],f=-1/0,v=1/0,y=[],C=[];for(let E=0;E<e.length;E++){let d=e[E];if(C.push(...d.subjects),d.range[0]<v&&(v=d.range[0]),d.range[1]>f&&(f=d.range[1]),s[0]>=d.range[0]&&s[1]<=d.range[1])return e[E].subjects.push(c),e;s[0]<d.range[0]&&s[1]>d.range[0]&&(m.push(E),y=y.concat(d.subjects)),s[0]>=d.range[0]&&s[0]<=d.range[1]&&(m.push(E),y=y.concat(d.subjects),s[0]=d.range[0]),s[1]>=d.range[0]&&s[1]<=d.range[1]&&(m.push(E),y=y.concat(d.subjects),s[1]=d.range[1])}if(C.push(c),s[0]<=v&&s[1]>=f)return[{subjects:C,range:s}];m.length&&m.reverse().forEach(E=>{e.splice(E,1)}),e.push({subjects:y.concat([c]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var qs=ee(St(),1),mi=ee(Qt(),1),Ds=ee(js(),1);function Bs(){let r={};function e(){for(let l in r)Object.prototype.hasOwnProperty.call(r,l)&&delete r[l]}function t(l){let s={};for(let c in r)+c<=l&&(s[c]=r[c]);return s}function i(l){let s={};for(let c in r)+c>=l&&(s[c]=r[c]);return s}function n({timestamp:l,priority:s,initiator:c}){var m;if(sr(l)){let f=(m=r[l])!=null?m:null;if(f&&s&&Le(s,!0)){let v={},y=f[s];if(y&&(v={...v,...y}),v=ce(v)?null:v,v&&Le(c,!0)){let C=v[c];return C!=null?C:null}return v}return f}return null}function o({timestamp:l,priority:s,initiator:c}){if(sr(l))if(r[l]){if(s&&Le(s,!0))if(r[l][s]){if(c&&Le(c,!0))if(r[l][s][c]){if(delete r[l][s][c],!ce(r[l][s]))return!0}else return!1;if(delete r[l][s],!ce(r[l]))return!0}else return!1;return delete r[l]}else return!1;return!1}function a({timestamp:l,priority:s,initiator:c,...m}){var f,v,y;(v=(f=r[l])==null?void 0:f[s])!=null&&v[c]?r[l][s][c].push({...m}):(y=r[l])!=null&&y[s]?r[l][s]={...r[l][s],[c]:[{...m}]}:r[l]?r[l]={...r[l],[s]:{[c]:[{...m}]}}:r[l]={[s]:{[c]:[{...m}]}}}return{map:r,remove:o,add:a,removeAll:e,get:n,getLte:t,getGte:i}}var kh=[R.expect,R.setNextBranch],Ph=1/0;function Hs(r,e){let t=r,i,n=_h(e),o=Bs(),a,l=()=>{y(),u()},s=p=>{o.add.call(void 0,p),C()},c=(p=[])=>{for(let b of p)if(b.action(),(0,qs.default)(kh,b.actionType))break},m=(p=1/0)=>{var g,T,L;let b=Zt((g=o.get({timestamp:p,priority:"control"}))!=null?g:{}),I=Zt((T=o.get({timestamp:p,priority:"container"}))!=null?T:{}),x=Zt((L=o.get({timestamp:p,priority:"chapter"}))!=null?L:{});return[...b,...I,...x]},f=p=>{n.isReady(p)&&c(m(p))},v=()=>{var p;c([...Zt((p=o.get({timestamp:1/0,priority:"chapter"}))!=null?p:{})])},y=()=>{i&&(a==null||a.unsubscribe(),i=void 0)},C=()=>{i||(i=()=>setTimeout(()=>{f(1/0)}),a=t.events.ended$.subscribe(i))},E=p=>{y(),t=p},d=p=>{p.priority==="container"&&n.resetCalled(p.timestamp),o.remove(p)},u=()=>{n.release(),o.removeAll()};return{setPlayer:E,add:s,remove:d,exec:f,execEndOfVideo:v,listen:C,unlisten:y,release:l,containersEventsCallState:n,getPreparedToExecActions:m}}function _h(r){let e=new Map;return{setCalled:({timestamp:l,id:s})=>{let c=e.get(l);c&&c[s]!==void 0&&(c[s]=!0)},setData:(l=[])=>{var s;for(let c of l){let m=(s=c.endTime)!=null?s:Ph,f=e.get(m);e.set(m,{...f,[c.id]:!1})}},resetCalled:l=>{let s=e.get(l);if(s)for(let c in s)s[c]=!1},isReady:l=>{let s=e.get(l);if(!s)return!0;let c=(0,mi.default)(s);return r?c.some(f=>f):!c.some(f=>!f)},release:()=>e.clear()}}function Zt(r){return(0,Ds.default)((0,mi.default)(r)).sort(e=>e.actionType===R.expect?-1:1)}var Us={videoContentHeight:0,videoContentWidth:0},Gs=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return Us;let{clientHeight:i,clientWidth:n}=r.experimental.element$.getValue()||{};if(!(i&&n))return Us;let o=e/t,a=i/n,l,s;return a>o?(s=n,l=n*o):a<o?(s=i/o,l=i):(s=n,l=i),{videoContentWidth:s,videoContentHeight:l}};var Lh=250;function zs(r){let e,t=new ResizeObserver(l=>{o(l),e=o.bind(null,l)});function i(l){let{parentElement:s,player:c}=r();if(s&&c){let{videoContentWidth:m,videoContentHeight:f}=Gs(c);s.style.setProperty("--interactive-content-width",`${m}px`),s.style.setProperty("--interactive-content-height",`${f}px`),s.style.setProperty("--interactive-width",`${l[0].contentRect.width}px`),s.style.setProperty("--interactive-height",`${l[0].contentRect.height}px`)}}function n(){let{parentElement:l}=r();l.removeAttribute("style")}let o=Xe(l=>{let{fns:s=[]}=r();i(l);for(let c of s)c()},Lh);function a(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e==null||e()},release:a}}var Fh=r=>Math.floor(Math.random()*r),Ks=r=>{var n;let e=r.length,t=1/0,i=null;for(;e--;){let o=r[e],a=(n=o.weight)!=null?n:1;a<t&&(t=a,i=o)}return i},Qs=r=>{var n;let e=r.length,t=-1/0,i=null;for(;e--;){let o=r[e],a=(n=o.weight)!=null?n:0;a>t&&(t=a,i=o)}return i};var Xs=r=>{let e=r.length,t=Fh(e);return r[t]},Ws=1,Ys=r=>{var i,n;let e=0;for(let o=0;o<r.length;++o)e+=(i=r[o].weight)!=null?i:Ws;let t=Math.random()*e;e=0;for(let o=0;o<r.length-1;++o)if(e+=(n=r[o].weight)!=null?n:Ws,e>=t)return r[o];return r[r.length-1]};var Zs={shouldOpenNow:!0,isDetachContainer:!0},Js="after-expect",fi=(r,e=!1)=>({...r,args:e?{...r.args,...Zs}:{...Zs,...r.args}}),el=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:i})=>{let n={isExpect:!1},o=()=>{n.isExpect&&(n.isExpect=!1)},a=({action:u,controlType:p,controlId:b,containerId:I,branches:x=[],onEvent:g,isEOV:T=()=>!1,isDisabled:L=()=>!1})=>{let A=fi(u,T()),O={timestamp:1/0,priority:"control",initiator:b,actionType:A.type},P=L(),Q=r.emit.bind(r,S.interactives,{subjectId:b,subjectType:p,subjectName:"control",type:P?F.actionChoiceCanceled:F.actionChoice,actionType:u.type,payload:{invokeImmediately:A.args.shouldOpenNow,containerId:I,...A.args}}),le=()=>{e.interactiveActionChoice$.next({subjectId:b,subjectType:p,subjectName:"control",type:P?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:A.args.shouldOpenNow,containerId:I,...A.args}})};if(P){Q(),le();return}switch(A.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{let q=x.find(be=>be.id===A.args.branchId);if(!q)return;g(A.args.isDetachContainer,y.bind(null,{subjectId:b,subjectName:"control"})),Q(),le(),A.args.shouldOpenNow?E({subjectId:b,subjectName:"control",subjectType:p,action:A,payload:{chapterId:q.chapterId,autoSelect:!1}}):i.add({...O,action:E.bind(null,{subjectId:b,subjectName:"control",subjectType:p,action:A,payload:{chapterId:q.chapterId,autoSelect:!1}})});return}case R.continuePlayback.trim().toLowerCase():{g(A.args.isDetachContainer,y.bind(null,{subjectId:b,subjectName:"control"})),Q(),le(),A.args.shouldOpenNow?C({subjectId:b,subjectName:"control",subjectType:p,action:u}):i.add({...O,action:C.bind(null,{subjectId:b,subjectName:"control",subjectType:p,action:u})});return}case R.openURI.trim().toLowerCase():{g(A.args.isDetachContainer,y.bind(null,{subjectId:b,subjectName:"control"})),Q(),le(),A.args.shouldOpenNow?d({subjectId:b,subjectName:"control",subjectType:p,action:A,payload:{URI:u.args.uri}}):i.add({...O,action:d.bind(null,{subjectId:b,subjectName:"control",subjectType:p,action:A,payload:{URI:u.args.uri}})});return}default:{let q="Unexpected control event",be=new M(1,1,{message:q});m(be,q);return}}},l=({action:u,container:{id:p,endTime:b},branches:I=[],isEOV:x=!1,autoSelected:g=!1})=>{let T=fi(u,x),L={timestamp:!T.args.shouldOpenNow||x?1/0:b!=null?b:1/0,priority:"container",initiator:p,actionType:T.type},A=r.emit.bind(r,S.interactives,{subjectId:p,subjectName:"container",type:F.actionChoice,actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),O=()=>{e.interactiveActionChoice$.next({subjectId:p,subjectName:"container",type:"action-choice",actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}})};switch(T.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{let P=I.find(Q=>Q.id===T.args.branchId);if(!P)return;A(),O(),i.add({...L,action:E.bind(null,{subjectId:p,subjectName:"container",action:T,payload:{chapterId:P.chapterId,autoSelect:g}})});return}case R.setMaxWeightBranch.trim().toLowerCase():return;case R.setMinWeightBranch.trim().toLowerCase():return;case R.setRandomBranch.trim().toLowerCase():return;case R.setWeightlessRandomBranch.trim().toLowerCase():return;case R.continuePlayback.trim().toLowerCase():{A(),O(),i.add({...L,action:C.bind(null,{subjectId:p,subjectName:"container",action:T})});return}case R.openURI.trim().toLowerCase():{A(),O(),i.add({...L,action:d.bind(null,{subjectId:p,subjectName:"container",action:T,payload:{URI:u.args.uri}})});return}default:{let P="Unexpected container event",Q=new M(1,1,{message:P});m(Q,P);return}}};function s({container:u,branches:p,isEOV:b=!1}){var x,g;let I=Ur(u.events);if(I){let T=fi(I.action,b);r.emit(S.interactives,{subjectId:u.id,subjectName:"container",type:F.actionChoice,actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:T.type,payload:{invokeImmediately:T.args.shouldOpenNow,...T.args}}),i.add({timestamp:b?1/0:(x=u.endTime)!=null?x:1/0,priority:"container",initiator:u.id,actionType:R.expect,action:v.bind(null,{subjectId:u.id,subjectName:"container"})}),n.isExpect=!0}else for(let T of(g=u.events)!=null?g:[])l({action:T.action,container:u,branches:p,isEOV:b})}let c=({chapterId:u,action:p,branches:b=[]})=>{let I=r.emit.bind(r,S.interactives,{subjectId:u,subjectName:"chapter",type:F.actionChoice,actionType:p.type,payload:p.args}),x=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:p.type,payload:p.args})};switch(p.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{let g=b.find(T=>T.id===p.args.branchId);return g!=null&&g.chapterId?(I(),x(),E.bind(null,{subjectId:u,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case R.setWeightlessRandomBranch.trim().toLowerCase():{let g=Xs(b);return g!=null&&g.chapterId?(I(),x(),E.bind(null,{subjectId:u,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case R.setRandomBranch.trim().toLowerCase():{let g=Ys(b);return g!=null&&g.chapterId?(I(),x(),E.bind(null,{subjectId:u,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case R.setMaxWeightBranch.trim().toLowerCase():{let g=Qs(b);return g!=null&&g.chapterId?(I(),x(),E.bind(null,{subjectId:u,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case R.setMinWeightBranch.trim().toLowerCase():{let g=Ks(b);return g!=null&&g.chapterId?(I(),x(),E.bind(null,{subjectId:u,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case R.continuePlayback.trim().toLowerCase():return I(),x(),C.bind(null,{subjectId:u,subjectName:"chapter",action:p});case R.openURI.trim().toLowerCase():return I(),x(),d.bind(null,{subjectId:u,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:{let g="Unexpected chapter event",T=new M(1,1,{message:g});m(T,g);return}}};function m(u,p){console.error(p),e.error$.next(u),r.emit(S.errors,u)}function f(u){var b;let p=Ur(u.events);if(p){if(Z(u))return;r.emit(S.interactives,{subjectId:u.id,subjectName:"chapter",type:F.actionChoice,actionType:p.action.type,payload:p.action.args}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"chapter",type:"action-choice",actionType:p.action.type,payload:p.action.args}),i.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:R.expect,action:v.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else(b=u.events)==null||b.forEach(I=>{let x=c({chapterId:u.id,action:I.action,branches:u.branches});x&&i.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:I.action.type,action:x})})}let v=({subjectId:u,subjectName:p})=>{t.pause(),r.emit(S.interactives,{subjectId:u,subjectName:p,type:F.actionExecution,actionType:R.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:p,type:"action-execution",actionType:R.expect})},y=({subjectId:u,subjectName:p})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),r.emit(S.interactives,{subjectId:u,subjectName:p,type:F.actionExecution,actionType:Js}),e.interactiveActionExecution$.next({subjectId:u,subjectName:p,type:"action-execution",actionType:Js})},C=({subjectId:u,subjectName:p,subjectType:b,action:I})=>{r.emit(S.interactives,{subjectId:u,subjectName:p,subjectType:b,type:F.actionExecution,actionType:I.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:p,subjectType:b,type:"action-execution",actionType:I.type})},E=({subjectId:u,subjectName:p,subjectType:b,action:I,payload:x})=>{x.behaviour="change-chapter",r.emit(S.interactives,{subjectId:u,subjectName:p,subjectType:b,type:F.actionExecution,actionType:I.type,payload:x}),e.interactiveActionExecution$.next({subjectId:u,subjectName:p,subjectType:b,type:"action-execution",actionType:I.type,payload:x})},d=({subjectId:u,subjectName:p,subjectType:b,action:I,payload:x})=>{if(!x.URI)return;let g=window.open(x.URI,"_blank","noopener,noreferrer");g&&(g.opener=null),r.emit(S.interactives,{subjectId:u,subjectName:p,subjectType:b,type:F.actionExecution,actionType:I.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:p,subjectType:b,type:"action-execution",actionType:I.type})};return{onControlEvent:a,onContainerEvent:l,onChapterEvent:c,onExpectEvent:v,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:s,stopExpect:o,state:n}};var yi=ee(Zr(),1);import{Subscription as jh,Subject as bi,ValueSubject as ot}from"@vkontakte/videoplayer-shared/es2018";var vi=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(a=>a.id===i);if(!n)return null;let o=e.media.videos.find(a=>n.videoId===a.id);if(!o)return null;t[i]=tl(o)}return t[i]}).filter(Boolean)},Mh=r=>{for(let e of r.variants)if(Nh(e)&&e.payload)return e.payload.id},Nh=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),tl=r=>{let e=Mh(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},$h=(r,e)=>{for(let t of r.media.videos)if(e===tl(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},rl=(r,e)=>r.reduce((t,i)=>{let n=$h(e,i);return n?[...t,n]:t},[]);var re,me,fe,z,Jt,ie,ne,J,ve,Pe,_e,at=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:o}){this.state={history$:new ot([]),hasPrevChapter$:new ot(!1),prevChapter$:new ot(null),isInitialChapter$:new ot(!1),isGoBackLimited$:new ot(!1)};H(this,re,null);H(this,me);H(this,fe,!1);H(this,z,null);H(this,Jt,null);this.events={inited$:new bi,destroyed$:new bi,error$:new bi};H(this,ie,null);H(this,ne,null);H(this,J,null);H(this,ve,new jh);H(this,Pe,!1);H(this,_e,0);var a;V(this,ie,t),V(this,J,e),V(this,ne,i),V(this,re,n),V(this,me,o),this.state.history$&&w(this,ve)&&((a=w(this,ve))==null||a.add(this.state.history$.subscribe(l=>{var s,c;this.state.prevChapter$.next((0,yi.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((c=(s=w(this,z))==null?void 0:s.metadata)==null?void 0:c.initChapterId)),this.state.isGoBackLimited$.next(w(this,_e)===w(this,me).maxLength-1)})))}async setManifest(e){if(!w(this,ne)||!w(this,J))return;V(this,z,e),await this.getProjectHistory();let t=this.getInitialChapterId();await w(this,ne).setChapter({chapterId:t,pushToHistory:!1}),w(this,fe)||(V(this,fe,!0),this.events.inited$.next({initChapterId:t}))}get inited(){return w(this,fe)}async updateHistory(e,t=!0){var l;if(!w(this,z))return;w(this,Pe)?(V(this,Pe,!1),ki(this,_e)._++):V(this,_e,0);let i=w(this,z),n=e.length-w(this,me).maxLength,o=n>0?e.slice(n):e,a=vi(o,i);if(V(this,Jt,a),this.state.history$.next(o),!(!t||!w(this,re)||!w(this,ie)))try{await w(this,re).save(w(this,ie),a)}catch(s){let c=new M(1,5,"Unable to save interactive history");this.events.error$.next(c),(l=w(this,J))==null||l.emit(S.errors,c)}}async goBack(){var i;if(!this.state||!w(this,ne)){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),(i=w(this,J))==null?void 0:i.emit(S.errors,n)}V(this,Pe,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await w(this,ne).setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){var n;if(!w(this,z)||!w(this,ie))return;let e=w(this,z),t=[this.getInitialVideoId()];if(w(this,re))try{let o=await w(this,re).get(w(this,ie));o.length&&(t=o)}catch(o){let a=new M(1,5,"Error while trying to fetch data");this.events.error$.next(a),(n=w(this,J))==null||n.emit(S.errors,a)}let i=rl(t,e);this.state.history$.next(i)}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,yi.default)(e,-1)||w(this,me).initChapterId||((t=w(this,z))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(w(this,z)){let e=this.getInitialChapterId();return vi([e],w(this,z)).pop()}return null}destroy(){var e,t;V(this,ie,null),V(this,re,null),V(this,ne,null),(e=w(this,ve))==null||e.unsubscribe(),V(this,ve,null),V(this,fe,!1),(t=w(this,J))==null||t.emit(S.historyDestroyed),this.events.destroyed$.next(),V(this,J,null)}};re=new WeakMap,me=new WeakMap,fe=new WeakMap,z=new WeakMap,Jt=new WeakMap,ie=new WeakMap,ne=new WeakMap,J=new WeakMap,ve=new WeakMap,Pe=new WeakMap,_e=new WeakMap;var er=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var n;let e=(n=this.rootElement.getContext("2d"))==null?void 0:n.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,i=t.length;for(let o=3;o<i;o+=40)if(t[o]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(e,t=!1){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var tr=class{constructor({parentElement:e,endOffsetMs:t=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)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;
@@ -11,12 +11,12 @@ var Ws=Object.create;var En=Object.defineProperty;var Ks=Object.getOwnPropertyDe
11
11
  height: var(--interactive-height);
12
12
  background-color: var(--black);
13
13
  visibility: hidden;
14
- `,this.lastFrameCanvas=new Wt,this.endOffsetMs=t,this._callbacks={onError:n},this.lastFrameCanvas.rootElement.style.cssText=`
14
+ `,this.lastFrameCanvas=new er,this.endOffsetMs=t,this._callbacks={onError:i},this.lastFrameCanvas.rootElement.style.cssText=`
15
15
  position: absolute;
16
16
  top: 50%;
17
17
  left: 50%;
18
18
  transform: translate(-50%, -50%);
19
- `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),n={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(i){this._onError(i)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var n,i,o;return((n=t.controls)==null?void 0:n.length)&&e>=((i=t.startTime)!=null?i:0)&&e<=Math.min((o=t.endTime)!=null?o:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,n;(n=(t=this._callbacks)==null?void 0:t.onError)==null||n.call(t,e)}};function Fs(r=0){return new Promise(e=>{setTimeout(()=>{e(0)},r)})}var Bs=`/* interactive-container */
19
+ `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),i={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(i,e)}catch(n){this._onError(n)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var i,n,o;return((i=t.controls)==null?void 0:i.length)&&e>=((n=t.startTime)!=null?n:0)&&e<=Math.min((o=t.endTime)!=null?o:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,i;(i=(t=this._callbacks)==null?void 0:t.onError)==null||i.call(t,e)}};function il(r=0){return new Promise(e=>{setTimeout(()=>{e(0)},r)})}var nl=`/* interactive-container */
20
20
  .interactive-container {
21
21
  opacity: 1;
22
22
  visibility: visible;
@@ -31,6 +31,16 @@ var Ws=Object.create;var En=Object.defineProperty;var Ks=Object.getOwnPropertyDe
31
31
  visibility: hidden;
32
32
  }
33
33
 
34
+ .interactive-container.interactive-container-before-remove.interactive-container-before-remove-delay {
35
+ transition-delay: var(--interactive-remove-delay);
36
+ }
37
+
38
+ .interactive-container.interactive-container-before-remove {
39
+ transition: opacity var(--interactive-transition-1);
40
+ opacity: 0;
41
+ pointer-events: none;
42
+ }
43
+
34
44
  /* blink-anim */
35
45
  .interactive-control-blink-anim {
36
46
  animation-duration: 2001ms;
@@ -131,9 +141,14 @@ var Ws=Object.create;var En=Object.defineProperty;var Ks=Object.getOwnPropertyDe
131
141
  --interactive-bg-color-1: rgba(255, 255, 255, 0.08);
132
142
  --interactive-button-hover-opacity: 0.8;
133
143
  --interactive-area-hover-opacity: 0;
144
+ --interactive-remove-delay: 300ms;
134
145
  }
135
146
 
136
147
  /* interactive-control */
148
+ .interactive-control-wrapper-selected {
149
+ pointer-events: none;
150
+ }
151
+
137
152
  .interactive-control {
138
153
  display: flex;
139
154
  width: 100%;
@@ -165,20 +180,106 @@ var Ws=Object.create;var En=Object.defineProperty;var Ks=Object.getOwnPropertyDe
165
180
  transition: border-color var(--interactive-transition-1), box-shadow var(--interactive-transition-1), opacity var(--interactive-transition-2);
166
181
  }
167
182
 
183
+ .interactive-control-wrapper-selected > .interactive-control-button {
184
+ transition: opacity var(--interactive-transition-1);
185
+ opacity: 0.5;
186
+ }
187
+
188
+ .interactive-control-wrapper-selected > .interactive-control-area {
189
+ transition: opacity var(--interactive-transition-1);
190
+ opacity: 0;
191
+ }
192
+
193
+
194
+ .interactive-control.interactive-control-before-remove {
195
+ transition: opacity var(--interactive-transition-1);
196
+ opacity: 0;
197
+ pointer-events: none;
198
+ }
199
+
168
200
  .interactive-container.interactive-container-disabled .interactive-control-button,
169
201
  .interactive-container.interactive-container-disabled .interactive-control-area {
170
202
  animation: none;
171
203
  }
172
204
 
173
- .interactive-container:not(.interactive-container-disabled) .interactive-control-button:not(.interactive-control-selected):not(.interactive-control-blink-anim):hover,
174
- .interactive-container:not(.interactive-container-disabled) .interactive-control-button:not(.interactive-control-selected):not(.interactive-control-blink-anim):focus-visible {
205
+ .interactive-container:not(.interactive-container-disabled) .interactive-control-wrapper:not(.interactive-control-wrapper-selected) > .interactive-control-button:not(.interactive-control-blink-anim):hover,
206
+ .interactive-container:not(.interactive-container-disabled) .interactive-control-wrapper:not(.interactive-control-wrapper-selected) > .interactive-control-button:not(.interactive-control-blink-anim):focus-visible {
175
207
  opacity: var(--interactive-button-hover-opacity);
176
208
  animation: none;
177
209
  }
178
210
 
179
- .interactive-container:not(.interactive-container-disabled) .interactive-control-area:not(.interactive-control-selected):not(.interactive-control-blink-anim):hover,
180
- .interactive-container:not(.interactive-container-disabled) .interactive-control-area:not(.interactive-control-selected):not(.interactive-control-blink-anim):focus-visible {
211
+ .interactive-container:not(.interactive-container-disabled) .interactive-control-wrapper:not(.interactive-control-wrapper-selected) > .interactive-control-area:not(.interactive-control-blink-anim):hover,
212
+ .interactive-container:not(.interactive-container-disabled) .interactive-control-wrapper:not(.interactive-control-wrapper-selected) > .interactive-control-area:not(.interactive-control-blink-anim):focus-visible {
181
213
  opacity: var(--interactive-area-hover-opacity);
182
214
  animation: none;
183
215
  }
184
- `;var qs=r=>{let e=document.createElement("style");e.textContent=Bs,r.prepend(e)};import{clientChecker as wh}from"@vkontakte/videoplayer-core/es2018";var Us=Object.freeze({lang:Th.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4},isTouch:!1,animationsFeatureToggles:{areaControlShadow:!1,controlsExpectTimeBlinkAnimation:!1,controlsTapPlace:!1}});function Ah(){let r=document.createElement("div");return r.classList.add("interactive-chapter"),r}var Qt=class{constructor(e){this.playerSubscriptions=new dn;this.subscriptions=new dn;this.globalEventEmitter=new Vt;this.animation=new Mt;this.seekToInteractiveController=new ze;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Ah();this.factories=new Map([["choice",Ct]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new dn;this.graph=null;this.lastFrame=null;this.blinkAnimationRef=null;this.appState=0;this.state={prevChapter$:new q(null),isInitialChapter$:new q(!1),isFirstChapter$:new q(!0),isEndChapter$:new q(!1),isInteractiveExpectation$:new q(!1),isReplay$:new q(!1),calledByInteractive$:new q(!1),lastChapterChangeWasInitiatedByInteractive$:new q(!1),disabledControls$:new q(!1),interactiveRanges$:new q([]),isInteractiveTime$:new q(!1),statistics$:new q(null),isSeekable$:new q(!1)};this.events={noInteraction$:new F,graphVisibilityChanged$:new F,watchAgainIsClicked$:new F,chapterChanged$:new F,playerChanged$:new F,error$:new F,eachTick$:new F,manifestChanged$:new F,interactiveRangeEnded$:new F,interactiveContainerRemoved$:new F,interactiveContainerFakeRemoved$:new F,interactiveActionExecution$:new F,interactiveActionChoice$:new F,interactiveVisibilityChanged$:new F};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(A.errors,e)};this.clearHistoryIfEnded=()=>{var i;let e=(i=this.player)==null?void 0:i.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&Z(n)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...n}=e;if(t){let{statSubscription:i,oneStat:o}=t;i.add(o.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(A.playerChanged,n)};this.onPlaybackStarted=()=>{var e;(e=this.resizeManager)==null||e.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(t=>{!e&&t.isPermanentText||(this.animation.removeFn(t.whilePlaying),t.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,i=t.getValue().map(o=>({...o,subjects:o.subjects.filter(a=>a.id!==e)}));t.next(i)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};var i,o;if(this._options={...Us,...e,config:{...Us.config,...e.config}},(i=this._options.animationsFeatureToggles)==null?void 0:i.controlsExpectTimeBlinkAnimation){this.blinkAnimationRef=new dt,this.blinkAnimationRef.create();let a=this.blinkAnimationRef.element;a&&this.rootElement.append(a)}this._options.parentElement.append(this.rootElement),this.historyController=new rt({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:(o=this._options.projectInfo)==null?void 0:o.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new Kt({parentElement:this._options.parentElement,onError:a=>{let l=new N(1,6,a);this.emitErrorEvent(l)}})),qs(this._options.parentElement),this.subscriptions.add(Hs(this.rootElement,"mousedown").subscribe(a=>a.stopPropagation())).add(Hs(this.rootElement,"mouseup").subscribe(a=>a.stopPropagation())),this.manifestController=new we(this._options.loaders,a=>{let l=new N(1,3,a);this.emitErrorEvent(l)});let n=[];this._options.lastFrame&&n.push(()=>{var a;(a=this.lastFrame)==null||a.updateCanvasDimensions(!0)}),n.push(()=>{let a=this.state.isInteractiveTime$.getValue();for(let l of this.gameControllers)l.onResize(a)}),this.resizeManager=Rs(()=>({player:this.player,parentElement:this._options.parentElement,fns:n})),this._options.graph&&(this.graph=new Ge({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:a=>{this.setChapter({chapterId:a}),this.globalEventEmitter.emit(A.graph,{type:Ze.watchAgainClicked,chapterId:a}),this.events.watchAgainIsClicked$.next(a)},onError:a=>{let l=new N(1,2,{message:a});this.emitErrorEvent(l)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{var t,n;if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((t=e.payload)==null?void 0:t.behaviour)==="change-chapter"){let{chapterId:i}=e.payload;this.setChapter({chapterId:i}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(((n=e.payload)==null?void 0:n.behaviour)==="change-manifest"){let{manifestURL:i}=e.payload;i&&this.setManifest(i)}e.actionType==="expect"?(this.state.isInteractiveExpectation$.next(!0),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0})):e.actionType==="after-expect"&&(this.state.isInteractiveExpectation$.next(!1),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}))})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:n})=>{e!=="action-choice"||t==="chapter"||"invokeImmediately"in n&&n.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=rn(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,i=this.getInteractiveRanges().reverse().find(({range:o})=>t>=o[1]);if(i){let o=i.range.join("-");this.endedRanges.has(o)||(this.endedRanges.add(o),this.globalEventEmitter.emit(A.interactives,{type:M.rangeEnded,payload:i,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:i}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Sh()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(xh({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:n})=>{var s;let i;if(n)i=!0;else{let c=e*1e3;i=!!t.find(({range:[f,v],subjects:C})=>f<c&&c<v&&C.some(T=>!T.isRemoved)&&C.length)}i!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(i);let o=!!this.noInteractionTimeout,l=((s=this.player)==null?void 0:s.info.playbackState$.getValue())==="playing"||n;i&&!o&&l?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):o&&!l&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{var t;(t=this.lastFrame)==null||t.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{var t;e&&((t=this.lastFrame)==null||t.setVideoElement(e))})).add(this.player.events.firstFrame$.subscribe(()=>{var e;(e=this.lastFrame)==null||e.reset(),setTimeout(()=>{var t,n;(t=this.lastFrame)==null||t.hide(),(n=this.lastFrame)==null||n.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){var t,n;let e=this.manifestController.chapter;e&&this.appState===1&&((t=this.selectBranches)==null||t.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),(n=this.interactiveEvents)==null||n.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(i=>i.container.container).filter(i=>!Se(i.controls))),this._options.lastFrame&&this.animation.addFn(()=>{var i;this.player&&((i=this.lastFrame)==null||i.onEachTick(this.player.info.position$.getValue()*1e3))},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(n=>{var l,s,c,m;let i=n.type.trim().toLowerCase(),o=this.factories.get(i),a=o==null?void 0:o(n,this.rootElement,{isTouch:(s=(l=this._options)==null?void 0:l.isTouch)!=null?s:!1,features:{controlsExpectTimeBlinkAnimation:(c=this._options.animationsFeatureToggles)==null?void 0:c.controlsExpectTimeBlinkAnimation,controlsTapPlace:(m=this._options.animationsFeatureToggles)==null?void 0:m.controlsTapPlace}});if(a&&this.selectBranches&&this.interactiveEvents&&this.player){let f=new Ht({player:this.player,container:a,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>sa(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)},onError:this.emitErrorEvent});this.animation.addFn(f.whilePlaying,!0),t.push(f)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!t||!n&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){var l,s;if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),i=(l=n&&Z(n)&&Bt(n))!=null?l:!1,o=((s=this.manifestController.manifest)==null?void 0:s.metadata.initChapterId)===e,a=this.historyController.state.history$.getValue();if(o||i&&t){this.historyController.updateHistory([e]);return}(0,Gs.default)(a,-1)!==e&&this.historyController.updateHistory([...a,e])}handleFakeRemoval(e,t){let{interactiveRanges$:n}=this.state,o=n.getValue().map(a=>{let l=a.subjects.some(c=>c.id===e),s=a.subjects.map(c=>t&&l||c.id===e?{...c,isRemoved:!0}:c);return{...a,subjects:s}});n.next(o)}reset(){var e;this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),(e=this.interactiveEvents)==null||e.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}toggleBlinkAnimation(e){var n,i;if(!((n=this._options.animationsFeatureToggles)!=null&&n.controlsExpectTimeBlinkAnimation))return;let t=(o,a)=>{o.toggleBlinkAnimation(a)};qt({...e,gameControllers:this.gameControllers,execFn:Je(nn(t),e.isExpect)}),e.isExpect&&((i=this.blinkAnimationRef)==null||i.restart())}updateControlsShadowStyles(e){var n;if(!((n=this._options.animationsFeatureToggles)!=null&&n.areaControlShadow))return;let t=(i,o)=>{i.updateControlsShadowStyles(o)};e.isExpect?qt({...e,gameControllers:this.gameControllers,execFn:Je(nn(t),!1)}):qt({...e,gameControllers:this.gameControllers,execFn:t})}get options(){return this._options}init(){var e;this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&((e=this.resizeManager)==null||e.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.events.manifestChanged$.next(t.manifest),this.globalEventEmitter.emit(A.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Ss(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=js({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:n=!1}={}){var s,c;this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&wh.browser.isSafari&&await Fs(35);let i=!n&&this.state.isEndChapter$.getValue()&&((s=this.getCurrentManifest())==null?void 0:s.metadata.initChapterId)===e;this.state.isReplay$.next(i);let{chapter:o,media:a,graph:l}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||i)&&this.state.isFirstChapter$.next(!0),!(!o||!a)&&(t&&this.pushChapterToHistory(o.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(o),(c=this.lastFrame)==null||c.setCurrentChapter(o),this.events.chapterChanged$.next({chapter:o,manifestVideo:a}),this.globalEventEmitter.emit(A.chapterChanged,{chapter:o,media:a,graph:l}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new Ds(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?nt.GRAPH_SHOW:nt.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(nt.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:n,subjectType:i})=>{t!=="action-choice"||n!=="control"||(i==="Button"&&e.next(nt.NEXT_BUTTON),i==="Area"&&e.next(nt.NEXT_AREA))}))}),nextMovie$:new Ds(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t!=null&&t.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(A.graph,{type:Ze.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.updateVideosInfo(e))}deadEndCheck(){var n;return!(((n=this.interactiveEvents)==null?void 0:n.getPreparedToExecActions())||[]).some(i=>i.actionType===R.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(t=>!t.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(n=>{let i=n.container.container;return!n.container.isRemoved&&i.endTime===null&&ue(i.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&Ot(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){var e;return Da((e=this.manifestController.chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){var e,t,n,i,o,a;this.clearHistoryIfEnded(),(e=this.blinkAnimationRef)==null||e.destroy(),this.destroyGameControllers(),this.gameControllers=[],(t=this.graph)==null||t.destroy(),this.seamlessControllerSubs.unsubscribe(),(n=this.seamlessController)==null||n.removeAll(),(i=this.resizeManager)==null||i.release(),this.animation.release(),(o=this.interactiveEvents)==null||o.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),(a=this.lastFrame)==null||a.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Rh={Container:ve,createChoiceContainer:Ct,createAreaControl:ft,createButtonControl:bt,classnamesPrefix:kn};var Ab={version:Sn};export{wf as ContainerTypes,Pt as ControlTypes,N as CustomError,A as EVENT_NAMES,R as EventActionTypes,Af as EventTypes,Qt as Interactives,we as ManifestController,Ab as SDKInfo,un as chapterIdsToVKVideoIds,Gr as compareVersions,gf as containerTypes,Ef as controlTypes,Uo as eventActionTypes,If as eventTypes,gh as getChapterIdByVkVideoId,_s as getVKVideoIdByMedia,bh as getVideoRawIdByMedia,Ze as graphEventTypes,Bt as hasEndTemplate,M as interactivesEventTypes,Cf as isAreaControl,bf as isButtonControl,Z as isLastChapter,Se as isOneTextCtrlContainer,Ot as isSupportedManifest,kt as isTextControl,Ch as isVKVariantItem,Ho as isValidManifest,Go as migrateManifestToLatestVersion,Rh as utils,$s as vkVideoIdsToChapterIds};
216
+
217
+ /* fill animation */
218
+ .interactive-control-fill-animation {
219
+ position: absolute;
220
+ overflow: hidden;
221
+ z-index: -1;
222
+ pointer-events: none;
223
+ }
224
+
225
+ .interactive-control-fill-animation-filler-wrapper {
226
+ position: absolute;
227
+ width: 100%;
228
+ height: 100%;
229
+ transform-origin: center;
230
+ }
231
+
232
+ .interactive-control-fill-animation-filler-wrapper.interactive-control-fill-animation-fill-width {
233
+ top: 0;
234
+ }
235
+
236
+ .interactive-control-fill-animation-filler-wrapper.interactive-control-fill-animation-fill-height {
237
+ left: 0;
238
+ }
239
+
240
+ .interactive-control-fill-animation-filler-wrapper.interactive-control-fill-animation-from-right {
241
+ right: 0;
242
+ }
243
+
244
+ .interactive-control-fill-animation-filler-wrapper.interactive-control-fill-animation-from-left {
245
+ left: 0;
246
+ }
247
+
248
+ .interactive-control-fill-animation-filler-wrapper.interactive-control-fill-animation-from-top {
249
+ top: 0;
250
+ }
251
+
252
+ .interactive-control-fill-animation-filler-wrapper.interactive-control-fill-animation-from-bottom {
253
+ bottom: 0;
254
+ }
255
+
256
+ .interactive-control-fill-animation-filler {
257
+ width: 100%;
258
+ height: 100%;
259
+ background-color: rgba(173, 211, 255, 0.32);
260
+ }
261
+
262
+ .interactive-control-fill-animation-filler.interactive-control-fill-animation-fill-width {
263
+ transform: scaleX(0);
264
+ }
265
+
266
+ .interactive-control-fill-animation-filler.interactive-control-fill-animation-fill-height {
267
+ transform: scaleY(0);
268
+ }
269
+
270
+ .interactive-control-fill-animation-filler.interactive-control-fill-animation-from-right {
271
+ transform-origin: right;
272
+ }
273
+
274
+ .interactive-control-fill-animation-filler.interactive-control-fill-animation-from-left {
275
+ transform-origin: left;
276
+ }
277
+
278
+ .interactive-control-fill-animation-filler.interactive-control-fill-animation-from-top {
279
+ transform-origin: top;
280
+ }
281
+
282
+ .interactive-control-fill-animation-filler.interactive-control-fill-animation-from-bottom {
283
+ transform-origin: bottom;
284
+ }
285
+ `;var ol=r=>{let e=document.createElement("style");e.textContent=nl,r.prepend(e)};import{clientChecker as Uh}from"@vkontakte/videoplayer-core/es2018";var ll=Object.freeze({lang:Dh.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4},isTouch:!1,disableTextControlContainerVisibilityEvents:!1,animationsFeatureToggles:{areaControlShadow:!1,controlsExpectTimeBlinkAnimation:!1,controlsTapPlace:!1,controlsFillAnimation:!1,controlsHideAnimation:!1}});function Gh(){let r=document.createElement("div");return r.classList.add("interactive-chapter"),r}var rr=class{constructor(e){this.playerSubscriptions=new gi;this.subscriptions=new gi;this.globalEventEmitter=new Dt;this.animation=new Ht;this.seekToInteractiveController=new Ze;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Gh();this.factories=new Map([["choice",qt]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new gi;this.graph=null;this.lastFrame=null;this.blinkAnimationRef=null;this.appState=0;this.state={prevChapter$:new D(null),isInitialChapter$:new D(!1),isFirstChapter$:new D(!0),isEndChapter$:new D(!1),isInteractiveExpectation$:new D(!1),isReplay$:new D(!1),calledByInteractive$:new D(!1),lastChapterChangeWasInitiatedByInteractive$:new D(!1),disabledControls$:new D(!1),interactiveRanges$:new D([]),isInteractiveTime$:new D(!1),statistics$:new D(null),isSeekable$:new D(!1)};this.events={noInteraction$:new B,graphVisibilityChanged$:new B,watchAgainIsClicked$:new B,chapterChanged$:new B,playerChanged$:new B,error$:new B,eachTick$:new B,manifestChanged$:new B,interactiveRangeEnded$:new B,interactiveContainerRemoved$:new B,interactiveContainerFakeRemoved$:new B,interactiveActionExecution$:new B,interactiveActionChoice$:new B,interactiveVisibilityChanged$:new B};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(S.errors,e)};this.clearHistoryIfEnded=()=>{var n;let e=(n=this.player)==null?void 0:n.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:i}=this.getCurrentChapter();e&&i&&Z(i)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...i}=e;if(t){let{statSubscription:n,oneStat:o}=t;n.add(o.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(i),this.globalEventEmitter.emit(S.playerChanged,i)};this.onPlaybackStarted=()=>{var e;(e=this.resizeManager)==null||e.calc(),this.animation.requestAnimation()};this.destroyGameControllers=({removeTextControls:e=!0,withTransition:t=!1}={})=>{for(let i of this.gameControllers)!e&&i.isPermanentText||(this.animation.removeFn(i.whilePlaying),i.destroy(t))};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(o=>({...o,subjects:o.subjects.filter(a=>a.id!==e)}));t.next(n)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};var n,o;if(this._options={...ll,...e,config:{...ll.config,...e.config}},(n=this._options.animationsFeatureToggles)==null?void 0:n.controlsExpectTimeBlinkAnimation){this.blinkAnimationRef=new Ft,this.blinkAnimationRef.create();let a=this.blinkAnimationRef.element;a&&this.rootElement.append(a)}this._options.parentElement.append(this.rootElement),this.historyController=new at({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:(o=this._options.projectInfo)==null?void 0:o.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new tr({parentElement:this._options.parentElement,onError:a=>{let l=new M(1,6,a);this.emitErrorEvent(l)}})),ol(this._options.parentElement),this.subscriptions.add(sl(this.rootElement,"mousedown").subscribe(a=>a.stopPropagation())).add(sl(this.rootElement,"mouseup").subscribe(a=>a.stopPropagation())),this.manifestController=new Oe(this._options.loaders,a=>{let l=new M(1,3,a);this.emitErrorEvent(l)});let i=[];this._options.lastFrame&&i.push(()=>{var a;(a=this.lastFrame)==null||a.updateCanvasDimensions(!0)}),i.push(()=>{let a=this.state.isInteractiveTime$.getValue();for(let l of this.gameControllers)l.onResize(a)}),this.resizeManager=zs(()=>({player:this.player,parentElement:this._options.parentElement,fns:i})),this._options.graph&&(this.graph=new Ye({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:a=>{this.setChapter({chapterId:a}),this.globalEventEmitter.emit(S.graph,{type:rt.watchAgainClicked,chapterId:a}),this.events.watchAgainIsClicked$.next(a)},onError:a=>{let l=new M(1,2,{message:a});this.emitErrorEvent(l)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{var t,i;if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((t=e.payload)==null?void 0:t.behaviour)==="change-chapter"){let{chapterId:n}=e.payload;this.setChapter({chapterId:n}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(((i=e.payload)==null?void 0:i.behaviour)==="change-manifest"){let{manifestURL:n}=e.payload;n&&this.setManifest(n)}e.actionType==="expect"?(this.state.isInteractiveExpectation$.next(!0),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0})):e.actionType==="after-expect"&&(this.state.isInteractiveExpectation$.next(!1),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}))})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:i})=>{var n;e!=="action-choice"||t==="chapter"||"invokeImmediately"in i&&i.invokeImmediately||this.destroyGameControllers({removeTextControls:!1,withTransition:(n=this._options.animationsFeatureToggles)==null?void 0:n.controlsHideAnimation})}))}async initSeamless(){this.seamlessController=ci(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,n=this.getInteractiveRanges().reverse().find(({range:o})=>t>=o[1]);if(n){let o=n.range.join("-");this.endedRanges.has(o)||(this.endedRanges.add(o),this.globalEventEmitter.emit(S.interactives,{type:F.rangeEnded,payload:n,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:n}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Hh()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(qh({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:i})=>{var s;let n;if(i)n=!0;else{let c=e*1e3;n=!!t.find(({range:[f,v],subjects:y})=>f<c&&c<v&&y.some(C=>!C.isRemoved)&&y.length)}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let o=!!this.noInteractionTimeout,l=((s=this.player)==null?void 0:s.info.playbackState$.getValue())==="playing"||i;n&&!o&&l?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):o&&!l&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{var t;(t=this.lastFrame)==null||t.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{var t;e&&((t=this.lastFrame)==null||t.setVideoElement(e))})).add(this.player.events.firstFrame$.subscribe(()=>{var e;(e=this.lastFrame)==null||e.reset(),setTimeout(()=>{var t,i;(t=this.lastFrame)==null||t.hide(),(i=this.lastFrame)==null||i.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){var t,i;let e=this.manifestController.chapter;e&&this.appState===1&&((t=this.selectBranches)==null||t.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),(i=this.interactiveEvents)==null||i.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(n=>n.container.container).filter(n=>!Se(n.controls))),this._options.lastFrame&&this.animation.addFn(()=>{var n;this.player&&((n=this.lastFrame)==null||n.onEachTick(this.player.info.position$.getValue()*1e3))},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(i=>{var l,s,c,m,f,v,y;let n=i.type.trim().toLowerCase(),o=this.factories.get(n),a=o==null?void 0:o(i,this.rootElement,{isTouch:(s=(l=this._options)==null?void 0:l.isTouch)!=null?s:!1,features:{controlsExpectTimeBlinkAnimation:(c=this._options.animationsFeatureToggles)==null?void 0:c.controlsExpectTimeBlinkAnimation,controlsTapPlace:(m=this._options.animationsFeatureToggles)==null?void 0:m.controlsTapPlace,controlsFillAnimation:(f=this._options.animationsFeatureToggles)==null?void 0:f.controlsFillAnimation}});if(a&&this.selectBranches&&this.interactiveEvents&&this.player){let C=new Xt({player:this.player,container:a,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>ra(i,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(i.id)},onError:this.emitErrorEvent,disableTextControlContainerVisibilityEvents:(v=this.options.disableTextControlContainerVisibilityEvents)!=null?v:!1,features:{controlsHideAnimation:(y=this._options.animationsFeatureToggles)==null?void 0:y.controlsHideAnimation}});this.animation.addFn(C.whilePlaying,!0),t.push(C)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),i=!!this.seekToInteractiveController.getNextInteractiveTime();(i&&!t||!i&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){var l,s;if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),i=this.state.prevChapter$.getValue(),n=(l=i&&Z(i)&&_t(i))!=null?l:!1,o=((s=this.manifestController.manifest)==null?void 0:s.metadata.initChapterId)===e,a=this.historyController.state.history$.getValue();if(o||n&&t){this.historyController.updateHistory([e]);return}(0,cl.default)(a,-1)!==e&&this.historyController.updateHistory([...a,e])}handleFakeRemoval(e,t){let{interactiveRanges$:i}=this.state,o=i.getValue().map(a=>{let l=a.subjects.some(c=>c.id===e),s=a.subjects.map(c=>t&&l||c.id===e?{...c,isRemoved:!0}:c);return{...a,subjects:s}});i.next(o)}reset(){var e;this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),(e=this.interactiveEvents)==null||e.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}toggleBlinkAnimation(e){var i,n;if(!((i=this._options.animationsFeatureToggles)!=null&&i.controlsExpectTimeBlinkAnimation))return;let t=(o,a)=>{o.toggleBlinkAnimation(a)};Lt({...e,gameControllers:this.gameControllers,execFn:it(ui(t),e.isExpect)}),e.isExpect&&((n=this.blinkAnimationRef)==null||n.restart())}updateControlsShadowStyles(e){var i;if(!((i=this._options.animationsFeatureToggles)!=null&&i.areaControlShadow))return;let t=(n,o)=>{n.updateControlsShadowStyles(o)};e.isExpect?Lt({...e,gameControllers:this.gameControllers,execFn:it(ui(t),!1)}):Lt({...e,gameControllers:this.gameControllers,execFn:t})}get options(){return this._options}init(){var e;this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&((e=this.resizeManager)==null||e.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.events.manifestChanged$.next(t.manifest),this.globalEventEmitter.emit(S.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Hs(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=el({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:i=!1}={}){var s,c;this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&Uh.browser.isSafari&&await il(35);let n=!i&&this.state.isEndChapter$.getValue()&&((s=this.getCurrentManifest())==null?void 0:s.metadata.initChapterId)===e;this.state.isReplay$.next(n);let{chapter:o,media:a,graph:l}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||n)&&this.state.isFirstChapter$.next(!0),!(!o||!a)&&(t&&this.pushChapterToHistory(o.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(o),(c=this.lastFrame)==null||c.setCurrentChapter(o),this.events.chapterChanged$.next({chapter:o,manifestVideo:a}),this.globalEventEmitter.emit(S.chapterChanged,{chapter:o,media:a,graph:l}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new al(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?st.GRAPH_SHOW:st.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(st.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:i,subjectType:n})=>{t!=="action-choice"||i!=="control"||(n==="Button"&&e.next(st.NEXT_BUTTON),n==="Area"&&e.next(st.NEXT_AREA))}))}),nextMovie$:new al(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t!=null&&t.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(S.graph,{type:rt.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=this.graph)==null||t.updateVideosInfo(e))}deadEndCheck(){var i;return!(((i=this.interactiveEvents)==null?void 0:i.getPreparedToExecActions())||[]).some(n=>n.actionType===R.setNextBranch)}allControlsAreRemoved(e=!0){return!this.gameControllers.some(i=>{var o;let n=e&&((o=this._options.animationsFeatureToggles)!=null&&o.controlsHideAnimation)?i.container.willRemoved:!0;return!i.container.isRemoved||!n})}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(i=>{let n=i.container.container;return!i.container.isRemoved&&!i.container.willRemoved&&n.endTime===null&&he(n.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&Ot(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){var e;return as((e=this.manifestController.chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){var e,t,i,n,o,a;this.clearHistoryIfEnded(),(e=this.blinkAnimationRef)==null||e.destroy(),this.destroyGameControllers(),this.gameControllers=[],(t=this.graph)==null||t.destroy(),this.seamlessControllerSubs.unsubscribe(),(i=this.seamlessController)==null||i.removeAll(),(n=this.resizeManager)==null||n.release(),this.animation.release(),(o=this.interactiveEvents)==null||o.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),(a=this.lastFrame)==null||a.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var zh={Container:ge,createChoiceContainer:qt,createAreaControl:Vt,createButtonControl:Bt,classnamesPrefix:Vi};var ug={version:Pi};export{jm as ContainerTypes,kt as ControlTypes,M as CustomError,S as EVENT_NAMES,R as EventActionTypes,Bm as EventTypes,rr as Interactives,Oe as ManifestController,ug as SDKInfo,vi as chapterIdsToVKVideoIds,ti as compareVersions,_m as containerTypes,Lm as controlTypes,Vm as eventActionTypes,Fm as eventTypes,$h as getChapterIdByVkVideoId,tl as getVKVideoIdByMedia,Mh as getVideoRawIdByMedia,rt as graphEventTypes,_t as hasEndTemplate,F as interactivesEventTypes,Pm as isAreaControl,km as isButtonControl,Z as isLastChapter,Se as isOneTextCtrlContainer,Ot as isSupportedManifest,Rt as isTextControl,Nh as isVKVariantItem,Xo as isValidManifest,Yo as migrateManifestToLatestVersion,zh as utils,rl as vkVideoIdsToChapterIds};