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