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