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