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