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