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