@vkontakte/videoplayer-interactive 1.0.12-dev.3f0b6cc2.0 → 1.0.13-beta.0

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