@vkontakte/videoplayer-interactive 1.0.7-beta.0 → 1.0.7-dev.6643328a.0

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