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