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