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