@vkontakte/videoplayer-interactive 1.0.9-dev.fb906f6e.0 → 1.0.10-beta.0

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