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