@vkontakte/videoplayer-interactive 1.0.8-beta.0 → 1.0.8-beta.1
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/es2015.cjs.js +6 -6
- package/es2015.esm.js +6 -6
- package/es2018.cjs.js +6 -6
- package/es2018.esm.js +6 -6
- package/esnext.cjs.js +6 -6
- package/esnext.esm.js +6 -6
- package/evergreen.esm.js +6 -6
- package/index.d.ts +13 -1
- package/package.json +1 -1
package/es2015.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.8-beta.
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.8-beta.1
|
|
3
|
+
* Thu, 21 Mar 2024 12:42:55 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-8/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{loadVKLangPack as Rs,ValueSubject as H,Subscription as we,Observable as Gi,getCurrentBrowser as As,CurrentClientBrowser as Ps,once as xs}from"@vkontakte/videoplayer-shared/es2015.esm.js";import{v4 as Ls}from"uuid";import{Player as Ms}from"@vkontakte/videoplayer-core/es2015.esm.js";const Ns="1.0.8-beta.0";function ln(e,t=1){let i="0",r="0",n="0";return e.length===4?(i="0x"+e[1]+e[1],r="0x"+e[2]+e[2],n="0x"+e[3]+e[3]):e.length===7&&(i="0x"+e[1]+e[2],r="0x"+e[3]+e[4],n="0x"+e[5]+e[6]),`rgba(${+i},${+r},${+n},${t})`}const q="SDK_NAME",ks="SDK_NAME-controls-container",cn=()=>document.querySelector(`.${ks}`),Fs=.4,tt={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Wi={top:"flex-start",bottom:"flex-end",center:"center"},Hi={start:"flex-start",end:"flex-end",center:"center"},Ui={start:"left",end:"right",center:"center"},dn=({target:e,props:t})=>{var i,r,n,s,l,o;e.style.alignItems=(r=Wi[(i=t==null?void 0:t.text)===null||i===void 0?void 0:i.gravityVertical])!==null&&r!==void 0?r:Wi.center,e.style.justifyContent=(s=Hi[(n=t==null?void 0:t.text)===null||n===void 0?void 0:n.gravityHorizontal])!==null&&s!==void 0?s:Hi.center,e.style.textAlign=(o=Ui[(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.alignment])!==null&&o!==void 0?o:Ui.start},hn=({target:e,props:t,fallback:i,dependsOn:r})=>{var n,s,l,o,c,d;e.style.color=(s=(n=t==null?void 0:t.text)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:i.textColor,e.style.fontSize=`calc(${r.height} * ${(o=(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.size)!==null&&o!==void 0?o:i.textSize})`,e.textContent=(d=(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.value)!==null&&d!==void 0?d:i.textContent},un=({target:e,props:t,fallback:i})=>{var r,n,s,l;e.style.backgroundColor=ln((n=(r=t==null?void 0:t.background)===null||r===void 0?void 0:r.color)!==null&&n!==void 0?n:i.backgroundColor,(l=(s=t==null?void 0:t.background)===null||s===void 0?void 0:s.alpha)!==null&&l!==void 0?l:i.backgroundAlpha)},fn=({target:e,props:t,fallback:i,dependsOn:r})=>{var n,s,l,o,c,d,h,u,f,m,g;e.style.border=`calc(${r.height} * ${(l=(s=(n=t==null?void 0:t.shape)===null||n===void 0?void 0:n.border)===null||s===void 0?void 0:s.width)!==null&&l!==void 0?l:i.borderWidth}) solid ${ln((d=(c=(o=t==null?void 0:t.shape)===null||o===void 0?void 0:o.border)===null||c===void 0?void 0:c.color)!==null&&d!==void 0?d:i.borderColor,(f=(u=(h=t==null?void 0:t.shape)===null||h===void 0?void 0:h.border)===null||u===void 0?void 0:u.alpha)!==null&&f!==void 0?f:i.borderAlpha)}`,e.style.borderRadius=`calc(${r.height} * ${(g=(m=t==null?void 0:t.shape)===null||m===void 0?void 0:m.roundCorners)!==null&&g!==void 0?g:i.roundCorners})`},yi=({target:e,layoutParams:t,fallback:i})=>{var r;e.style.transform=`rotate(${(r=-t.angle)!==null&&r!==void 0?r:i.angle}rad)`},$e="int",mi={AREA:`${$e}_area`,TEXT:`${$e}_text`,BUTTON:`${$e}_bttn`};class gi{constructor(t){this.control=t}createView(t){var i;const r=document.createElement("div");r.classList.add(`${q}-control-container-${this.control.id}`),t(r,this.control.layoutParams);const n=((i=this.control.layoutParams.innerSizesDependOn)!==null&&i!==void 0?i:tt.innerSizesDependOn)==="self"?{height:r.style.height,width:r.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:r,dependsOn:n}}setEvents(t,i){t&&this.control.events.forEach(r=>{switch(r.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",s=>{s.stopPropagation(),i&&i({action:r.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${q}-control-container-${this.control.id}`)}}const vn=e=>{if(e.type.trim().toLowerCase()==="area")return new Vs(e)};class Vs extends gi{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:r,controlContainerEl:n}=super.createView(i),s=document.createElement("button");return s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",mi.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",un({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},tt),{backgroundColor:"transparent"})}),fn({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},tt),{borderAlpha:0}),dependsOn:r}),yi({target:s,layoutParams:this.control.layoutParams,fallback:tt}),n.append(s),t.append(n),this.controlEl=s,n}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const pn=e=>{if(e.type.trim().toLowerCase()==="button")return new Bs(e)};class Bs extends gi{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:r,controlContainerEl:n}=super.createView(i),s=document.createElement("button");s.type="button",s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",mi.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";const l=document.createElement("span");return l.style.display="inline-block",l.style.whiteSpace="pre",l.style.overflow="hidden",l.style.textOverflow="ellipsis",yi({target:s,layoutParams:this.control.layoutParams,fallback:tt}),un({target:s,props:this.control.props,fallback:tt}),fn({target:s,props:this.control.props,fallback:tt,dependsOn:r}),dn({target:s,props:this.control.props}),hn({target:l,props:this.control.props,fallback:tt,dependsOn:r}),s.append(l),n.append(s),t.append(n),this.controlEl=s,n}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const Ds=e=>{if(e.type.trim().toLowerCase()==="text")return new Gs(e)};class Gs extends gi{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:r,controlContainerEl:n}=super.createView(i),s=document.createElement("div");s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",mi.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";const l=document.createElement("span");return l.style.whiteSpace="pre",yi({target:s,layoutParams:this.control.layoutParams,fallback:tt}),dn({target:s,props:this.control.props}),hn({target:l,props:this.control.props,fallback:tt,dependsOn:r}),s.append(l),n.append(s),t.append(n),this.controlEl=s,n}disable(){}enable(){}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}class Ws{constructor(t){this.layout=t}}const Hs=e=>{if(e.type.trim().toLowerCase()==="relative")return new yn(e)};class yn extends Ws{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,i){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${i.width})`,t.style.height=`calc(var(--interactive-content-height) * ${i.height})`,t.style.left=`calc(var(--interactive-content-width) * ${i.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${i.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function ft(e,t){var i={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(i[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(i[r[n]]=e[r[n]]);return i}function A(e,t,i,r){function n(s){return s instanceof i?s:new i(function(l){l(s)})}return new(i||(i=Promise))(function(s,l){function o(h){try{d(r.next(h))}catch(u){l(u)}}function c(h){try{d(r.throw(h))}catch(u){l(u)}}function d(h){h.done?s(h.value):n(h.value).then(o,c)}d((r=r.apply(e,t||[])).next())})}function a(e,t,i,r){if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?r:i==="a"?r.call(e):r?r.value:t.get(e)}function E(e,t,i,r,n){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?n.call(e,i):n?n.value=i:t.set(e,i),i}var jt,de,zi;class mn{constructor(t){jt.add(this),this.container=t,this.factories=new Map,a(this,jt,"m",de).call(this)}addControlFactory(t,i){this.factories.set(t.trim().toLowerCase(),i),a(this,jt,"m",de).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,jt,"m",de).call(this)}}jt=new WeakSet,de=function(){this.controls=a(this,jt,"m",zi).call(this)},zi=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((i,r)=>{const n=r.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...i,s(r)]:[...i]},[])};const gn=(e,t)=>{if(e.type.trim().toLowerCase()==="choice")return new Us(e,t)};class Us extends mn{constructor(t,i){super(t),this.rootElement=i!=null?i:cn(),this.layout=new yn(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pn),this.addControlFactory("text",Ds),this.addControlFactory("area",vn)}createView(t){const i=document.createElement("div");return i.classList.add(`${q}-${this.container.id}`),this.layout.setContainerLayout(i),this.controls.forEach(r=>{const n=r.createView({parent:i,layoutFn:this.layout.setControlLayout});r.setEvents(n,t)}),this.rootElement.append(i),this.isRemoved=!1,i}hide(){const t=this.getElement();t&&(t.style.visibility="hidden")}show(){const t=this.getElement();t&&(t.style.visibility="visible")}enable(){const t=this.getElement();t&&(this.controls.forEach(i=>i.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){const t=this.getElement();t&&(this.controls.forEach(i=>i.disable()),t.style.opacity=Fs,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${q}-${this.container.id}`)}}var je=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function bn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Jt=function(e){return e&&e.Math==Math&&e},Y=Jt(typeof globalThis=="object"&&globalThis)||Jt(typeof window=="object"&&window)||Jt(typeof self=="object"&&self)||Jt(typeof je=="object"&&je)||function(){return this}()||je||Function("return this")(),lt=function(e){try{return!!e()}catch(t){return!0}},zs=lt,Oe=!zs(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),Ks=Oe,En=Function.prototype,Ki=En.apply,qi=En.call,qs=typeof Reflect=="object"&&Reflect.apply||(Ks?qi.bind(Ki):function(){return qi.apply(Ki,arguments)}),Cn=Oe,_n=Function.prototype,Je=_n.call,Ys=Cn&&_n.bind.bind(Je,Je),Ct=Cn?Ys:function(e){return function(){return Je.apply(e,arguments)}},In=Ct,Qs=In({}.toString),Xs=In("".slice),bi=function(e){return Xs(Qs(e),8,-1)},Zs=bi,Js=Ct,wn=function(e){if(Zs(e)==="Function")return Js(e)},ti=typeof document=="object"&&document.all,ta=typeof ti=="undefined"&&ti!==void 0,On={all:ti,IS_HTMLDDA:ta},Sn=On,ea=Sn.all,Q=Sn.IS_HTMLDDA?function(e){return typeof e=="function"||e===ea}:function(e){return typeof e=="function"},Tn={},ia=lt,_t=!ia(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),ra=Oe,te=Function.prototype.call,It=ra?te.bind(te):function(){return te.apply(te,arguments)},$n={},jn={}.propertyIsEnumerable,Rn=Object.getOwnPropertyDescriptor,na=Rn&&!jn.call({1:2},1);$n.f=na?function(t){var i=Rn(this,t);return!!i&&i.enumerable}:jn;var Se=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},sa=Ct,aa=lt,oa=bi,Re=Object,la=sa("".split),ca=aa(function(){return!Re("z").propertyIsEnumerable(0)})?function(e){return oa(e)=="String"?la(e,""):Re(e)}:Re,Ei=function(e){return e==null},da=Ei,ha=TypeError,An=function(e){if(da(e))throw ha("Can't call method on "+e);return e},ua=ca,fa=An,Kt=function(e){return ua(fa(e))},Yi=Q,Pn=On,va=Pn.all,Mt=Pn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:Yi(e)||e===va}:function(e){return typeof e=="object"?e!==null:Yi(e)},Ci={},Ae=Ci,Pe=Y,pa=Q,Qi=function(e){return pa(e)?e:void 0},_i=function(e,t){return arguments.length<2?Qi(Ae[e])||Qi(Pe[e]):Ae[e]&&Ae[e][t]||Pe[e]&&Pe[e][t]},ya=Ct,xn=ya({}.isPrototypeOf),ma=typeof navigator!="undefined"&&String(navigator.userAgent)||"",Ln=Y,xe=ma,Xi=Ln.process,Zi=Ln.Deno,Ji=Xi&&Xi.versions||Zi&&Zi.version,tr=Ji&&Ji.v8,z,ye;tr&&(z=tr.split("."),ye=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!ye&&xe&&(z=xe.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=xe.match(/Chrome\/(\d+)/),z&&(ye=+z[1])));var ga=ye,er=ga,ba=lt,Ea=Y,Ca=Ea.String,Mn=!!Object.getOwnPropertySymbols&&!ba(function(){var e=Symbol();return!Ca(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&er&&er<41}),_a=Mn,Nn=_a&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Ia=_i,wa=Q,Oa=xn,Sa=Nn,Ta=Object,kn=Sa?function(e){return typeof e=="symbol"}:function(e){var t=Ia("Symbol");return wa(t)&&Oa(t.prototype,Ta(e))},$a=String,Ii=function(e){try{return $a(e)}catch(t){return"Object"}},ja=Q,Ra=Ii,Aa=TypeError,wi=function(e){if(ja(e))return e;throw Aa(Ra(e)+" is not a function")},Pa=wi,xa=Ei,Oi=function(e,t){var i=e[t];return xa(i)?void 0:Pa(i)},Le=It,Me=Q,Ne=Mt,La=TypeError,Ma=function(e,t){var i,r;if(t==="string"&&Me(i=e.toString)&&!Ne(r=Le(i,e))||Me(i=e.valueOf)&&!Ne(r=Le(i,e))||t!=="string"&&Me(i=e.toString)&&!Ne(r=Le(i,e)))return r;throw La("Can't convert object to primitive value")},Fn={exports:{}},ir=Y,Na=Object.defineProperty,ka=function(e,t){try{Na(ir,e,{value:t,configurable:!0,writable:!0})}catch(i){ir[e]=t}return t},Fa=Y,Va=ka,rr="__core-js_shared__",Ba=Fa[rr]||Va(rr,{}),Vn=Ba,nr=Vn;(Fn.exports=function(e,t){return nr[e]||(nr[e]=t!==void 0?t:{})})("versions",[]).push({version:"3.31.0",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"});var Bn=Fn.exports,Da=An,Ga=Object,Si=function(e){return Ga(Da(e))},Wa=Ct,Ha=Si,Ua=Wa({}.hasOwnProperty),vt=Object.hasOwn||function(t,i){return Ua(Ha(t),i)},za=Ct,Ka=0,qa=Math.random(),Ya=za(1 .toString),Dn=function(e){return"Symbol("+(e===void 0?"":e)+")_"+Ya(++Ka+qa,36)},Qa=Y,Xa=Bn,sr=vt,Za=Dn,Ja=Mn,to=Nn,Rt=Qa.Symbol,ke=Xa("wks"),eo=to?Rt.for||Rt:Rt&&Rt.withoutSetter||Za,ct=function(e){return sr(ke,e)||(ke[e]=Ja&&sr(Rt,e)?Rt[e]:eo("Symbol."+e)),ke[e]},io=It,ar=Mt,or=kn,ro=Oi,no=Ma,so=ct,ao=TypeError,oo=so("toPrimitive"),lo=function(e,t){if(!ar(e)||or(e))return e;var i=ro(e,oo),r;if(i){if(t===void 0&&(t="default"),r=io(i,e,t),!ar(r)||or(r))return r;throw ao("Can't convert object to primitive value")}return t===void 0&&(t="number"),no(e,t)},co=lo,ho=kn,Ti=function(e){var t=co(e,"string");return ho(t)?t:t+""},uo=Y,lr=Mt,ei=uo.document,fo=lr(ei)&&lr(ei.createElement),Gn=function(e){return fo?ei.createElement(e):{}},vo=_t,po=lt,yo=Gn,Wn=!vo&&!po(function(){return Object.defineProperty(yo("div"),"a",{get:function(){return 7}}).a!=7}),mo=_t,go=It,bo=$n,Eo=Se,Co=Kt,_o=Ti,Io=vt,wo=Wn,cr=Object.getOwnPropertyDescriptor;Tn.f=mo?cr:function(t,i){if(t=Co(t),i=_o(i),wo)try{return cr(t,i)}catch(r){}if(Io(t,i))return Eo(!go(bo.f,t,i),t[i])};var Oo=lt,So=Q,To=/#|\.prototype\./,qt=function(e,t){var i=jo[$o(e)];return i==Ao?!0:i==Ro?!1:So(t)?Oo(t):!!t},$o=qt.normalize=function(e){return String(e).replace(To,".").toLowerCase()},jo=qt.data={},Ro=qt.NATIVE="N",Ao=qt.POLYFILL="P",Po=qt,dr=wn,xo=wi,Lo=Oe,Mo=dr(dr.bind),Hn=function(e,t){return xo(e),t===void 0?e:Lo?Mo(e,t):function(){return e.apply(t,arguments)}},Nt={},No=_t,ko=lt,Un=No&&ko(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),Fo=Mt,Vo=String,Bo=TypeError,kt=function(e){if(Fo(e))return e;throw Bo(Vo(e)+" is not an object")},Do=_t,Go=Wn,Wo=Un,ee=kt,hr=Ti,Ho=TypeError,Fe=Object.defineProperty,Uo=Object.getOwnPropertyDescriptor,Ve="enumerable",Be="configurable",De="writable";Nt.f=Do?Wo?function(t,i,r){if(ee(t),i=hr(i),ee(r),typeof t=="function"&&i==="prototype"&&"value"in r&&De in r&&!r[De]){var n=Uo(t,i);n&&n[De]&&(t[i]=r.value,r={configurable:Be in r?r[Be]:n[Be],enumerable:Ve in r?r[Ve]:n[Ve],writable:!1})}return Fe(t,i,r)}:Fe:function(t,i,r){if(ee(t),i=hr(i),ee(r),Go)try{return Fe(t,i,r)}catch(n){}if("get"in r||"set"in r)throw Ho("Accessors not supported");return"value"in r&&(t[i]=r.value),t};var zo=_t,Ko=Nt,qo=Se,Yt=zo?function(e,t,i){return Ko.f(e,t,qo(1,i))}:function(e,t,i){return e[t]=i,e},ie=Y,Yo=qs,Qo=wn,Xo=Q,Zo=Tn.f,Jo=Po,St=Ci,tl=Hn,Tt=Yt,ur=vt,el=function(e){var t=function(i,r,n){if(this instanceof t){switch(arguments.length){case 0:return new e;case 1:return new e(i);case 2:return new e(i,r)}return new e(i,r,n)}return Yo(e,this,arguments)};return t.prototype=e.prototype,t},$i=function(e,t){var i=e.target,r=e.global,n=e.stat,s=e.proto,l=r?ie:n?ie[i]:(ie[i]||{}).prototype,o=r?St:St[i]||Tt(St,i,{})[i],c=o.prototype,d,h,u,f,m,g,_,v,p;for(f in t)d=Jo(r?f:i+(n?".":"#")+f,e.forced),h=!d&&l&&ur(l,f),g=o[f],h&&(e.dontCallGetSet?(p=Zo(l,f),_=p&&p.value):_=l[f]),m=h&&_?_:t[f],!(h&&typeof g==typeof m)&&(e.bind&&h?v=tl(m,ie):e.wrap&&h?v=el(m):s&&Xo(m)?v=Qo(m):v=m,(e.sham||m&&m.sham||g&&g.sham)&&Tt(v,"sham",!0),Tt(o,f,v),s&&(u=i+"Prototype",ur(St,u)||Tt(St,u,{}),Tt(St[u],f,m),e.real&&c&&(d||!c[f])&&Tt(c,f,m)))},il=Math.ceil,rl=Math.floor,nl=Math.trunc||function(t){var i=+t;return(i>0?rl:il)(i)},sl=nl,ji=function(e){var t=+e;return t!==t||t===0?0:sl(t)},al=ji,ol=Math.min,ll=function(e){return e>0?ol(al(e),9007199254740991):0},cl=ll,Ri=function(e){return cl(e.length)},dl=$i,hl=Si,ul=Ri,fl=ji;dl({target:"Array",proto:!0},{at:function(t){var i=hl(this),r=ul(i),n=fl(t),s=n>=0?n:r+n;return s<0||s>=r?void 0:i[s]}});var vl=_i,pl=vl,yl=pl,ml=yl("Array","at"),gl=ml,bl=gl,El=bl,Cl=El,ii=bn(Cl);function zn(e,t){let i;return(...r)=>{clearTimeout(i),i=setTimeout(()=>e(...r),t)}}const Qt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},Ft=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,Ai=e=>Ft(e,Qt.Object),ri=e=>Ft(e,Qt.String),Pi=e=>Ft(e,Qt.Array),Kn=e=>Ft(e,Qt.Number),_l=e=>Ft(e,Qt.Function),fr=e=>Kn(e)&&!isNaN(e),Ht=e=>Ai(e)&&Object.keys(e).length===0,qn=e=>Pi(e)&&!e.length,re=(e,t)=>ri(e)&&(t?e.trim():e).length,Yn=window.navigator.userAgent.toLowerCase(),Il=/mobi/i.test(Yn);Yn.indexOf("android")>-1;const wl="video_interactive",Ol="videoint",Sl=250;class Tl{constructor(t){this.onResize=i=>{this.isReady&&(!i[0].contentRect.width||!i[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:i[0].contentRect.width,height:i[0].contentRect.height}))},this.handleChapterChange=i=>{var r;if(this.isReady){if(this.isHidden||this.hide(),!(i!=null&&i.id)){(r=this.onError)===null||r===void 0||r.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=(i,r=[])=>A(this,void 0,void 0,function*(){var n;if(!Kn(i.graph.edit.chapters[0].x)){this.isReady=!1,(n=this.onError)===null||n===void 0||n.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let s;try{s=yield Rs(this.lang,wl,Ol)}catch(o){console.log("Unable to load graph language pack")}const{GraphEditor:l}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new l(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:s}),this.ngEditor.on("control",({name:o,chapterId:c})=>{o==="openPreview"&&this.onOpenPreviewClick(c)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo=Object.assign({},o)})}this.visitedChapterIds=new Set(r),i.metadata.id!==this.currentManifestId?(this.ngEditor.update(i),this.currentManifestId=i.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0}),this.init(t)}init({root:t,onOpenPreviewClick:i,onError:r,lang:n,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=i,this.onError=r,this.lang=n!=null?n:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=$l(t),this.resizeObserver=new ResizeObserver(zn(this.onResize,Sl)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var t,i;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)===null||t===void 0||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(i=this.ngEditor)===null||i===void 0||i.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function $l(e){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height="100%",t.style.width="100%",t.style.display="none",e.append(t),t}const me=(e="",t="")=>{e=e.split("."),t=t.split(".");let i=0;for(let r=0;r<Math.max(e.length,t.length)&&!i;r++)e[r]>t[r]?i=1:e[r]<t[r]?i=-1:i=0;return i},jl="3.1",vr={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Rl={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Al=e=>{const t=[];for(const i of e.chapters){let r;const n=[];for(let o of i.branches){const{isDefault:c}=o,d=ft(o,["isDefault"]);c&&(r=d.id),n.push(d)}let s=[];const l=[];for(let o of i.containers){const{fallbackStrategy:c}=o,d=ft(o,["fallbackStrategy"]),h=!!d.endTime;let u=[Rl];switch(c){case"await":h?u=[]:s=[];break;case"default":{const f={type:"onSuspense",action:{type:vr.default,args:{branchId:r,shouldOpenNow:!h,isDetachContainer:!0}}};h?u=[f]:s=[f];break}case"random":case"weightlessRandom":case"max":case"min":{const f={type:"onSuspense",action:{type:vr[c],args:{}}};h?u=[f]:s=[f];break}}for(const f of d.controls)l.push(Object.assign(Object.assign({},d),{controls:[Object.assign({},f)],id:Ls(),events:u}))}t.push(Object.assign(Object.assign({},i),{containers:l,events:s,branches:n}))}return e.metadata.version=jl,e.metadata.updated=new Date().toISOString(),Object.assign(Object.assign({},e),{chapters:t})},Pl="3.2",xl=e=>{if(!e.media){const t=e.metadata,{media:i}=t,r=ft(t,["media"]);return Object.assign(Object.assign({},e),{metadata:Object.assign(Object.assign({},r),{version:Pl}),media:i})}return e},Ll="3.3",Ml=(e=[])=>({edit:{chapters:e},view:{}}),pr={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Nl=e=>{var t;const i=[],r=[];for(const n of e.chapters){const{id:s,x:l,y:o}=n,c=ft(n,["id","x","y"]),d=c.containers.map(h=>{var u;return Object.assign(Object.assign({},h),{controls:h.controls.map(f=>{var{subtype:m,type:g}=f,_=ft(f,["subtype","type"]);return Object.assign(Object.assign({},_),{type:m!=null?m:g})}),events:!((u=h.events)===null||u===void 0)&&u.length?h.events:[pr]})});i.push(Object.assign(Object.assign({id:s},c),{containers:d,events:!((t=c.events)===null||t===void 0)&&t.length?c.events:[pr]})),r.push({id:s,x:l,y:o})}return Object.assign(Object.assign({},e),{chapters:i,graph:Ml(r),metadata:Object.assign(Object.assign({},e.metadata),{version:Ll})})},kl=[{version:"3.0",migrate:Al},{version:"3.1",migrate:xl},{version:"3.2",migrate:Nl}],Fl=e=>kl.reduce((t,i)=>me(t.metadata.version,i.version)?t:i.migrate(t),e),Vl=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),T=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var gt;(function(e){e.GO_NEXT_BUTTON="GO_NEXT_BUTTON",e.GO_NEXT_AREA="GO_NEXT_AREA",e.WATCH_AGAIN="WATCH_AGAIN",e.OPEN_GRAPH="OPEN_GRAPH",e.CLOSE_GRAPH="CLOSE_GRAPH"})(gt||(gt={}));const yr={metadata:"Object",chapters:"Array"},Bl="3.0.0",Dl="3.3.0",Qn=e=>{const t=me(e,Bl);return t===-1?!1:t===0?!0:me(e,Dl)!==1},Gl=e=>{if(!Ai(e))return!1;for(const t in yr)if(!e[t]||!Ft(e[t],yr[t]))return!1;return Qn(e.metadata.version)},Xn=e=>e.type===Vl.Text;class R{constructor(t,i,...r){this.severity=t,this.category=i,this.data=r}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}R.Severity={RECOVERABLE:1,CRITICAL:2};R.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Zn{constructor(){this.listeners={}}addListener(t,i){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(i),this}on(t,i){return this.addListener(t,i)}once(t,i){this.listeners[t]=this.listeners[t]||[];const r=()=>{i(),this.off(t,r)};return this.listeners[t].push(r),this}off(t,i){return this.removeListener(t,i)}reset(){this.listeners={}}removeListener(t,i){const r=this.listeners[t];if(!r)return this;for(let n=r.length;n>0;n--)if(r[n]===i){r.splice(n,1);break}return this}emit(t,...i){const r=this.listeners[t];return r?(r.forEach(n=>{n(...i)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}}class Wl{constructor(t){this.addFn=(i,r=!1)=>{_l(i)&&(this.fns.push(i),r&&this.updateFn())},this.removeFn=(i,r=!1)=>{this.fns=this.fns.filter(n=>n!==i),r&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(i=>i()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Hl{constructor(t){var i,r;this.loaders={chapterLoaders:(i=t==null?void 0:t.chapterLoaders)!==null&&i!==void 0?i:[],manifestLoaders:(r=t==null?void 0:t.manifestLoaders)!==null&&r!==void 0?r:[]}}exec(t,i){return A(this,void 0,void 0,function*(){return Ul(...this.loaders[t])(i)})}}function Ul(...e){return function(i){return A(this,void 0,void 0,function*(){const r=[...e];for(;r.length>0;)i=yield r.shift()(i);return i})}}function ge(e,t,i){return e?Object.assign(Object.assign({},e),{[t]:e[t]?[i,...e[t]]:[i]}):{[t]:[i]}}function ni(e){var{actions:t,errors:i,chapterId:r}=e,n=ft(e,["actions","errors","chapterId"]);if(r){const s=t.getManifest(),l=t.getChapter(s.chapters,r);if(l){const o=t.getMedia(s.media,l.videoId),c=t.getGraph(s.graph,l.id);return o?Object.assign(Object.assign({},n),{actions:t,errors:i,result:{chapter:l,media:o,graph:c}}):Object.assign(Object.assign({},n),{errors:ge(i,ni.name,"Could not find media"),actions:t})}}return Object.assign(Object.assign({},n),{errors:ge(i,ni.name,"Could not find chapter"),actions:t})}class mr{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,i,r){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:i,options:r})}removeEventListener(t,i){if(!(t in this.listeners))return;const r=this.listeners[t];for(let n=0,s=r.length;n<s;n++)if(r[n].callback===i){r.splice(n,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const r=this.listeners[t.type].slice();for(let n=0,s=r.length;n<s;n++){const l=r[n];try{l.callback.call(this,t)}catch(o){Promise.resolve().then(()=>{throw o})}l.options&&l.options.once&&this.removeEventListener(t.type,l.callback)}return!t.defaultPrevented}}class Jn extends mr{constructor(){super(),this.listeners||mr.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class zl{constructor(){Object.defineProperty(this,"signal",{value:new Jn,writable:!0,configurable:!0})}abort(t){let i;try{i=new Event("abort")}catch(n){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 r=t;if(r===void 0)if(typeof document=="undefined")r=new Error("This operation was aborted"),r.name="AbortError";else try{r=new DOMException("signal is aborted without reason")}catch(n){r=new Error("This operation was aborted"),r.name="AbortError"}this.signal.reason=r,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(zl.prototype[Symbol.toStringTag]="AbortController",Jn.prototype[Symbol.toStringTag]="AbortSignal");function ts(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function Kl(e){typeof e=="function"&&(e={fetch:e});const{fetch:t,Request:i=t.Request,AbortController:r,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=e;if(!ts({fetch:t,Request:i,AbortController:r,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:t,Request:s};let s=i;(s&&!s.prototype.hasOwnProperty("signal")||n)&&(s=function(d,h){let u;h&&h.signal&&(u=h.signal,delete h.signal);const f=new i(d,h);return u&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),f},s.prototype=i.prototype);const l=t;return{fetch:(c,d)=>{const h=s&&s.prototype.isPrototypeOf(c)?c.signal:d?d.signal:void 0;if(h){let u;try{u=new DOMException("Aborted","AbortError")}catch(m){u=new Error("Aborted"),u.name="AbortError"}if(h.aborted)return Promise.reject(u);const f=new Promise((m,g)=>{h.addEventListener("abort",()=>g(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([f,l(c,d)])}return l(c,d)},Request:s}}const xi=ts({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),es=xi?Kl({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,gr=xi?es.fetch:window.fetch;xi?es.Request:window.Request;const ql=e=>A(void 0,void 0,void 0,function*(){try{let t,i;if(Ai(e))t=e;else if(ri(e)){i=new URL(e).href;const n=yield gr(i);if(!n.ok)return{};t=yield n.json()}else return{};if(!Gl(t))return{};const r=t.metadata.media;if(ri(r)&&!t.media)try{let n;i?n=new URL(r,i).href:(n=new URL(r).href,i=n);const s=yield gr(n);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(n){return Zl(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:i}}catch(t){return{}}});function Yl(e){return A(this,void 0,void 0,function*(){const{manifest:t,manifestURL:i}=yield ql(e),r=Fl(t);return r.media=Ql(r.media,i),delete r.metadata.media,r})}function Ge(e,t){return e.find(i=>i.id===t)}function br(e,t){var i,r;return!((i=e.edit)===null||i===void 0)&&i.chapters?e.edit.chapters.find(n=>n.id===t):!((r=e.view)===null||r===void 0)&&r.chapters?e.view.chapters.find(n=>n.id===t):void 0}function Er(e,t){return e.videos.find(i=>i.id===t)}function Ql(e,t){return Object.assign(Object.assign({},e),{videos:e.videos.map(i=>Object.assign(Object.assign({},i),{variants:i.variants.map(r=>{const n=Xl(r.url,t);return Object.assign(Object.assign({},r),{url:n||r.url})})}))})}function Xl(e,t){try{return new URL(e,t).href}catch(i){return""}}function Zl(e){return me(e,"3.2.0")>=0}const P=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Li=e=>Pi(e)&&!qn(e),Te=e=>e.order==="end",Jl=e=>Pi(e.containers)&&!qn(e.containers)&&Te(e),tc=(e,t)=>{var i;const r=e*1e3;return Li(t.controls)&&r<((i=t.startTime)!==null&&i!==void 0?i:0)},Cr=(e,t)=>{var i,r;const n=e*1e3;return Li(t.controls)&&n>=((i=t.startTime)!==null&&i!==void 0?i:0)&&n<=((r=t.endTime)!==null&&r!==void 0?r:1/0)},be=e=>e.some(t=>t.action.type==="expect"),_r=e=>e.find(t=>t.action.type==="expect"),ec=e=>(e==null?void 0:e.length)===1,is=e=>ec(e)&&Xn(e[0]),ic=({fn:e,type:t=1},...i)=>(...r)=>t?e(...r,...i):e(Object.assign(Object.assign({},r[t]),i[t])),rc=(e=[])=>e.reduce((t,i,r)=>{var n,s,l;const o=((n=i==null?void 0:i.controls)!==null&&n!==void 0?n:[]).filter(c=>!Xn(c));if(Li(o)){const c=[(s=i.startTime)!==null&&s!==void 0?s:0,(l=i.endTime)!==null&&l!==void 0?l:1/0],d=i.id;if(!r)t.push({subjects:[d],range:c});else{const h=[];let u=-1/0,f=1/0,m=[];const g=[];for(let _=0;_<t.length;_++){const v=t[_];if(g.push(...v.subjects),v.range[0]<f&&(f=v.range[0]),v.range[1]>u&&(u=v.range[1]),v.range[0]<=c[0]&&v.range[1]>=c[1])return t[_].subjects.push(d),t;c[0]>=v.range[0]&&c[0]<=v.range[1]&&(h.push(_),m=m.concat(v.subjects),c[0]=v.range[0]),c[1]>=v.range[0]&&c[1]<=v.range[1]&&(h.push(_),m=m.concat(v.subjects),c[1]=v.range[1])}if(g.push(d),c[0]<=f&&c[1]>=u)return[{subjects:g,range:c}];h.length&&h.reverse().forEach(_=>{t.splice(_,1)}),t.push({subjects:m.concat([d]),range:c})}}return t},[]).sort((t,i)=>t.range[0]-i.range[0]),nc=(e,t)=>be(e.events)?!1:t.some(({container:i})=>i.container.id!==e.id&&be(i.container.events)&&i.container.endTime===e.endTime&&!i.isRemoved);class sc extends Hl{constructor(t,i){super(t),this.onError=i,this.prevChapter$=new H(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){var i;return A(this,void 0,void 0,function*(){this.release();const r=yield this.exec("manifestLoaders",{actions:{addErrorMessage:ge},result:null,errors:null,source:t});r.errors&&this.errorHandler(r.errors);const n=yield Yl((i=r.result)!==null&&i!==void 0?i:t);return this.manifest=n,this})}setInitial(){return A(this,void 0,void 0,function*(){return this.setNext()})}setNext(t=this.manifest.metadata.initChapterId){return A(this,void 0,void 0,function*(){this.prevChapter$.next(this.chapter);const i=yield this.exec("chapterLoaders",ni({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:br,getChapter:Ge,getMedia:Er,getByBranches:this.getByBranches.bind(this),addErrorMessage:ge},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph,this})}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest.metadata.initChapterId)||null}getByChapterId(t=this.manifest.metadata.initChapterId){const i=Ge(this.manifest.chapters,t);if(i){const r=Er(this.manifest.media,i.videoId),n=br(this.manifest.graph,i.id);if(r)return{chapter:i,media:r,graph:n}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{const i=Ge(this.manifest.chapters,t);return this.getByBranches(i==null?void 0:i.branches)}}getByBranches(t=[]){return t.reduce((i,r)=>{const n=this.getByChapterId(r.chapterId);return n&&i.push(n),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return Te(this.chapter)}}const ac=e=>{const t=e.variants.find(i=>{var r;return((r=i.payload)===null||r===void 0?void 0:r.type)==="vk"});if(t&&"payload"in t){const[i,r]=t.payload.id.split("_");return[i,r]}return[]},I={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ir={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function oc(){const e=new Map;function t(n){var{listId:s=Math.random().toString(),itemId:l=Math.random().toString()}=n,o=ft(n,["listId","itemId"]);const c=e.get(s),d=Object.assign({},o);return c?c[l]=d:e.set(s,{[l]:d}),Object.assign({listId:s,itemId:l},o)}function i(n,s){var l,o,c;const d=e.get(n);if(d){if(s)return(l=d[s])===null||l===void 0||l.player.destroy(),(o=d[s])===null||o===void 0||o.container.remove(),(c=d[s])===null||c===void 0||c.subscription.unsubscribe(),delete d[s],Object.keys(d).length||e.delete(n),!0;for(const h of Object.values(d))h.player.destroy(),h.container.remove();return e.delete(n),!0}else throw Error("Can't remove. Not find.")}function r(){for(const n of e)i(n[0])}return{createPlayer:t,removePlayer:i,map:e,removeAll:r}}function wr(e,t=[]){var i,r,n;let s={},l;const o=!t.length;for(const c of e.variants)if(!l&&"cover"in c&&(l=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(o||t.includes("mp4"))&&(s.MPEG=Object.assign(Object.assign({},s.MPEG),{[(i=c.standard)!==null&&i!==void 0?i:"Invariant quality"]:c.url}));break;case"mpeg":(o||t.includes("mpeg"))&&(s.MPEG=Object.assign(Object.assign({},s.MPEG),{[(r=c.standard)!==null&&r!==void 0?r:"Invariant quality"]:c.url}));break;case"hls":(o||t.includes("hls"))&&(s=Object.assign(Object.assign({},s),{HLS:{type:"url",url:c.url}}));break;case"dash":(o||t.includes("dash"))&&(s=Object.assign(Object.assign({},s),{DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}}));break}return{sources:s,thumbUrl:l,title:(n=e.title)!==null&&n!==void 0?n:""}}const ne=(e,t)=>{const i=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();i!==t&&r.includes(t)&&(e.setQuality(t),e.setAutoQuality(!1))},he={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},lc=2;function cc(e){const t=oc();let i,r;const n=new Zn;let s={},l=!1,o=null,c=!1,d;e&&h(e);function h(y){o=y}function u(y,C,b){var S;if(!o)throw Error("need to set interactive controller");const x=((S=t.map.get(y))!==null&&S!==void 0?S:{})[C];if(x){s=Object.assign({chapterId:b,listId:y,itemId:C},x);const w=s.player;r=w.info.currentQuality$.subscribe(F=>{if(!(!F||!w.info.position$.getValue())){i=F;for(const D of t.map)Object.values(D[1]).forEach(({player:N})=>{w.info.isAutoQualityEnabled$.getValue()||ne(N,F)})}}),x.container.remove(),l=!1,o.setPlayer(x.player),c||(o.init(),c=!0),n.emit(he.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function f(y,C,b){return A(this,void 0,void 0,function*(){if(!o)throw Error("need to set interactive controller");if(Ht(s)||y!==s.itemId)return;if(b>=0&&!l){const j=o.getChapterBranches();l=!0;const x=new Set;for(const w of j)x.has(w.media.id)||(yield g({media:w.media,chapterId:w.chapter.id,setAsActive:!1,title:w.chapter.label}),x.add(w.media.id))}})}function m({chapter:{id:y},media:C}){return A(this,void 0,void 0,function*(){if(Ht(s))return;r==null||r.unsubscribe();const b=s.player.info.muted$.getValue(),S=s.player.info.currentQuality$.getValue(),j=s.player.info.isAutoQualityEnabled$.getValue(),x=s.player.info.volume$.getValue(),w=s.player.info.currentPlaybackRate$.getValue(),F=!j;let D=!1;for(const N of t.map)if(N[0]===C.id){const X=Object.keys(N[1]);for(const et of X)et===s.itemId?(X.length<lc||(D=!0),t.removePlayer(N[0],et)):(D=!0,u(N[0],et,y),F?ne(s.player,S):s.player.setAutoQuality(!0),s.player.setVolume(x),s.player.setMuted(b),s.player.setPlaybackRate(w))}else t.removePlayer(N[0]);D||(yield g({media:C,chapterId:y,setAsActive:!0,playbackRate:w}),F?ne(s.player,S):s.player.setAutoQuality(!0),s.player.setVolume(x),s.player.setMuted(b))})}function g({media:y,chapterId:C,prefetch:b=!0,setAsActive:S=!0,autoplay:j=!1,preferredExt:x,title:w,playbackRate:F}){var D,N,X;return A(this,void 0,void 0,function*(){const et=Math.random().toString(),wt=document.createElement("div");d.append(wt);const $s=(D=s==null?void 0:s.player)===null||D===void 0?void 0:D.info.isAutoQualityEnabled$.getValue();let Xt;if(!((N=o==null?void 0:o.options)===null||N===void 0)&&N.vkVideoLoader){const Zt=ac(y);Zt.length&&(Xt=yield o.options.vkVideoLoader(...Zt))}const Bi=Object.assign(Object.assign({container:wt},((X=Xt==null?void 0:Xt.videos)===null||X===void 0?void 0:X[0])||{sources:wr(y,x).sources}),{title:w}),pt=new Ms;pt.initVideo(Bi);const js=wt.lastChild,Di=new we;Di.add(pt.info.position$.subscribe(function(Zt){f(et,pt.info.duration$.getValue(),Zt)})).add(pt.events.canplay$.subscribe(function(){$s||ne(pt,i),F&&pt.setPlaybackRate(F)})),js&&(wt.style.display="none",wt.classList.add(C));const Ot=t.createPlayer({listId:y.id,itemId:et,player:pt,container:wt,sources:wr(y,x).sources,config:Bi,subscription:Di});return S&&u(y.id,Ot.itemId,C),j&&Ot.player.play(),b&&!j&&Ot.player.prepare(),n.emit(he.playerCreated,Ot.player),{player:Ot.player,config:Ot.config}})}function _(){v(),o=null}function v(){o==null||o.off(I.chapterChanged,m),t.removeAll(),s={},c=!1,l=!1}function p({container:y}){return A(this,void 0,void 0,function*(){if(!o)throw Error("need to set interactive controller");v(),d=y;const{media:C,chapter:b}=o.getCurrentChapter();if(C){o.on(I.chapterChanged,m);const{player:S,config:j}=yield g({media:C,chapterId:b.id,title:b.label});return n.emit(he.initiated,{container:y,media:C,chapterId:b.id}),{player:S,config:j}}else console.error("not found")})}return Object.assign(Object.assign({},t),{on:n.on.bind(n),off:n.off.bind(n),init:p,setInteractiveController:h,createPlayer:g,removeAll:_,getActivePlayer:function(){return s}})}const dc=3e3,hc=()=>{let e=[],t=null;return{setPlayer:l=>{t=l},setContainers:l=>{e=l},deleteContainer:l=>{e=e.filter(o=>o.id!==l)},getNextInteractiveTime:(l=dc)=>{if(!e.length||t===null)return null;let o=-1,c=!1;const d=Math.round(t.info.position$.getValue()*1e3);for(const h of e){const u=h.startTime-l;if(u<=d&&(d<=h.endTime||h.endTime===null)){c=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!c&&o!==-1?o:null}}},Lt=hc();class uc{constructor({player:t,container:i,branches:r,selectBranches:n,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d}){this.hide=()=>{setTimeout(()=>{var h,u,f,m;this.gameState!==P.end&&(be(this.container.container.events)&&this.gameState===P.afterInteractive||this.selectBranches.state.isExpect||(this.gameState===P.interactive?this.disabledControls$||(u=(h=this.container).disable)===null||u===void 0||u.call(h):(m=(f=this.container).hide)===null||m===void 0||m.call(f),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var h,u,f,m,g;if(this.gameState===P.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(f=(u=this.container).show)===null||f===void 0||f.call(u),this.disabledControls$||(g=(m=this.container).enable)===null||g===void 0||g.call(m),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const v=ic({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(p,y)=>{this.isSelectedControlEvent=!0,p!==!1&&(this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===P.end||this.gameState===P.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),Lt.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===P.end});this.container.createView(v),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0}),!((h=this.disabledControls$)===null||h===void 0)&&h.getValue()&&this.container.disable()}},this.onEndOfVideo=()=>{this.gameState=P.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var h,u,f,m;if(((h=this.player.experimental.element$.getValue())===null||h===void 0?void 0:h.readyState)<1||[P.destroyed,P.removed].includes(this.gameState)&&!this.isPermanentText)return;const _=this.player.getExactTime();if(tc(_,this.container.container))this.gameState!==P.beforeInteractive&&(this.gameState=P.beforeInteractive,this.onBeforeStartTime());else if(Cr(_,this.container.container))this.gameState!==P.interactive&&(this.gameState=P.interactive,this.onStartTime());else if(this.gameState!==P.afterInteractive){const y=this.gameState;this.gameState=P.afterInteractive,y===P.interactive&&this.onEndTime()}else this.gameState!==P.destroyed&&this.removeView();const v=Cr(_,this.container.container),p=this.container.container.startTime?[this.container.container.startTime,(u=this.container.container.endTime)!==null&&u!==void 0?u:1/0]:[];(m=(f=this.container).onProgress)===null||m===void 0||m.call(f,_,v),this.globalEventEmitter.emit(I.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:p,currentTime:_,isInteractiveTime:v})},this.container=i,this.branches=r,this.selectBranches=n,this.subscription=new we,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&is(i.container.controls),this.disabledControls$=d,this.globalEventEmitter=l,this.gameState=P.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)),this.disabledControls$&&this.subscription.add(this.disabledControls$.subscribe(t=>{var i,r,n,s;t?(r=(i=this.container).disable)===null||r===void 0||r.call(i):(s=(n=this.container).enable)===null||s===void 0||s.call(n)}))}selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);const t=be(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,i;(i=(t=this.container).hide)===null||i===void 0||i.call(t),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=P.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=P.removed}destroy(){var t;this.reset(),this.removeView(),this.gameState=P.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!==null&&t!==void 0?t:1/0,id:this.container.container.id}),Lt.deleteContainer(this.container.container.id)}}function fc(){const e={};function t(){for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&delete e[o];return!0}function i(o){const c={};for(const d in e)+d<=o&&(c[d]=e[d]);return c}function r(o){const c={};for(const d in e)+d>=o&&(c[d]=e[d]);return c}function n({timestamp:o,priority:c,initiator:d}){var h;if(fr(o)){const u=(h=e[o])!==null&&h!==void 0?h:null;if(u&&re(c,!0)){let f={};const m=u[c];if(m&&(f=Object.assign(Object.assign({},f),m)),f=Ht(f)?null:f,f&&re(d,!0)){const g=f[d];return g!=null?g:null}return f}return u}return null}function s({timestamp:o,priority:c,initiator:d}){if(fr(o))if(e[o]){if(re(c,!0))if(e[o][c]){if(re(d,!0))if(e[o][c][d]){if(delete e[o][c][d],!Ht(e[o][c]))return!0}else return!1;if(delete e[o][c],!Ht(e[o]))return!0}else return!1;return delete e[o]}else return!1}function l(o){var c,d,h,{timestamp:u,priority:f,initiator:m}=o,g=ft(o,["timestamp","priority","initiator"]);!((d=(c=e[u])===null||c===void 0?void 0:c[f])===null||d===void 0)&&d[m]?e[u][f][m].push(Object.assign({},g)):!((h=e[u])===null||h===void 0)&&h[f]?e[u][f]=Object.assign(Object.assign({},e[u][f]),{[m]:[Object.assign({},g)]}):e[u]?e[u]=Object.assign(Object.assign({},e[u]),{[f]:{[m]:[Object.assign({},g)]}}):e[u]={[f]:{[m]:[Object.assign({},g)]}}}return{map:e,remove:s,add:l,removeAll:t,get:n,getLte:i,getGte:r}}const vc=[T.expect,T.setNextBranch],pc=1/0;function Or(e){let t=e,i;const r=yc(),n=new fc;let s;const l=()=>{f(),v()},o=p=>{n.add.call(void 0,p),m()},c=(p=[])=>{for(const y of p)if(y.action(),vc.includes(y.actionType))break},d=(p=1/0)=>{var y,C,b;const S=se((y=n.get({timestamp:p,priority:"control"}))!==null&&y!==void 0?y:{}),j=se((C=n.get({timestamp:p,priority:"container"}))!==null&&C!==void 0?C:{}),x=se((b=n.get({timestamp:p,priority:"chapter"}))!==null&&b!==void 0?b:{});return[...S,...j,...x]},h=p=>{r.isReady(p)&&c(d(p))},u=()=>{var p;c([...se((p=n.get({timestamp:1/0,priority:"chapter"}))!==null&&p!==void 0?p:{})])},f=()=>{i&&(s==null||s.unsubscribe(),i=void 0)},m=()=>{i||(i=()=>setTimeout(()=>{h(1/0)}),s=t.events.ended$.subscribe(i))},g=p=>{f(),t=p},_=p=>{p.priority==="container"&&r.resetCalled(p.timestamp),n.remove(p)},v=()=>{r.release(),n.removeAll()};return{setPlayer:g,add:o,remove:_,exec:h,execEndOfVideo:u,listen:m,unlisten:f,release:l,containersEventsCallState:r,getPreparedToExecActions:d}}function yc(){const e=new Map;return{setCalled:({timestamp:l,id:o})=>{const c=e.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(const d of l){const h=(o=d.endTime)!==null&&o!==void 0?o:pc,u=(c=e.get(h))!==null&&c!==void 0?c:{};e.set(h,Object.assign(Object.assign({},u),{[d.id]:!1}))}},resetCalled:l=>{const o=e.get(l);if(o)for(const c in o)o[c]=!1},isReady:l=>{const o=e.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>e.clear()}}function se(e){return Object.values(e).flat().sort(t=>t.actionType===T.expect?-1:1)}const mc=(e,t)=>{const{height:i,width:r}=t.info.intrinsicVideoSize$.getValue()||{};if(!(i&&r))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:n,clientWidth:s}=t.experimental.element$.value||{};if(!(n&&s))return{videoContentHeight:0,videoContentWidth:0};const l=i/r,o=n/s;let c,d;return o>l?(d=s,c=s*l):o<l?(d=n/l,c=n):(d=s,c=n),{videoContentWidth:d,videoContentHeight:c}},gc=250;function bc(e){let t=()=>{};const i=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function r(o){const{parentElement:c,player:d}=e();if(c&&d){const{videoContentWidth:h,videoContentHeight:u}=mc(c,d);c.style.setProperty("--interactive-content-width",`${h}px`),c.style.setProperty("--interactive-content-height",`${u}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function n(){const{parentElement:o}=e();o.removeAttribute("style")}const s=zn(o=>{const{fns:c=[]}=e();r(o);for(const d of c)d()},gc);function l(){t=void 0,i.disconnect(),n()}return{resizeObserver:i,calc:()=>{t()},release:l}}class Ec{constructor(){this.map={}}push(t,i){t in this.map?this.map[t].push(i):this.map[t]=[i]}get(t){const i=this.map[t];return i?i.slice():null}getAll(){const t=[];for(const i in this.map)t.push(...this.map[i]);return t}remove(t,i){t in this.map&&(this.map[t]=this.map[t].filter(r=>r!==i),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}size(){return Object.keys(this.map).length}keys(){return Object.keys(this.map)}}const Cc=e=>Math.floor(Math.random()*e),_c=e=>{let t=e.length,i=1/0,r=null;for(;t--;)e[t].weight<i&&(i=e[t].weight,r=e[t]);return r},Ic=e=>{let t=e.length,i=-1/0,r=null;for(;t--;)e[t].weight>i&&(i=e[t].weight,r=e[t]);return r},wc=e=>{const t=e.length,i=Cc(t);return e[i]},Sr=1,Oc=e=>{var t,i;let r=0;for(let s=0;s<e.length;++s)r+=(t=e[s].weight)!==null&&t!==void 0?t:Sr;const n=Math.random()*r;r=0;for(let s=0;s<e.length-1;++s)if(r+=(i=e[s].weight)!==null&&i!==void 0?i:Sr,r>=n)return e[s];return e[e.length-1]},Tr=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),We=(e,t=!1)=>Object.assign(Object.assign({},e),{args:t?Object.assign(Object.assign({},e.args),Tr):Object.assign(Object.assign({},Tr),e.args)}),$r=({globalEventEmitter:e,player:t,interactiveEvents:i,removeControllers:r})=>{const n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:v,controlType:p,controlId:y,containerId:C,branches:b=[],onEvent:S,isEOV:j=()=>!1,isDisabled:x=()=>!1})=>{const w=We(v,j()),F={timestamp:1/0,priority:"control",initiator:y,actionType:w.type},D=x(),N=e.emit.bind(e,I.interactives,{subjectId:y,subjectType:p,subjectName:"control",type:D?L.actionChoiceCanceled:L.actionChoice,actionType:v.type,payload:Object.assign({containerId:C},w.args)});if(D){N();return}switch(w.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{const X=b.find(et=>et.id===w.args.branchId);if(!X)return;S(w.args.isDetachContainer,f.bind(null,{subjectId:y,subjectName:"control"})),N(),w.args.shouldOpenNow?g({subjectId:y,subjectName:"control",subjectType:p,action:w,payload:{chapterId:X.chapterId,autoSelect:!1}}):(i.add(Object.assign(Object.assign({},F),{action:g.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:w,payload:{chapterId:X.chapterId,autoSelect:!1}})})),r==null||r());return}case T.continuePlayback.trim().toLowerCase():{S(w.args.isDetachContainer,f.bind(null,{subjectId:y,subjectName:"control"})),N(),w.args.shouldOpenNow?m({subjectId:y,subjectName:"control",subjectType:p,action:v}):i.add(Object.assign(Object.assign({},F),{action:m.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:v})}));return}case T.openURI.trim().toLowerCase():{S(w.args.isDetachContainer,f.bind(null,{subjectId:y,subjectName:"control"})),N(),w.args.shouldOpenNow?_({subjectId:y,subjectName:"control",subjectType:p,action:w,payload:{URI:v.args.uri}}):(i.add(Object.assign(Object.assign({},F),{action:_.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:w,payload:{URI:v.args.uri}})})),r==null||r());return}default:console.error("Unexpected control event"),e.emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:v,container:{id:p,endTime:y},branches:C=[],isEOV:b=!1,autoSelected:S=!1})=>{const j=We(v,b),x={timestamp:!j.args.shouldOpenNow||b?1/0:y,priority:"container",initiator:p,actionType:j.type},w=e.emit.bind(e,I.interactives,{subjectId:p,subjectName:"container",type:L.actionChoice,actionType:j.type,payload:j.args});switch(j.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{const F=C.find(D=>D.id===j.args.branchId);if(!F)return;w(),i.add(Object.assign(Object.assign({},x),{action:g.bind(null,{subjectId:p,subjectName:"container",action:j,payload:{chapterId:F.chapterId,autoSelect:S}})})),r==null||r();return}case T.setMaxWeightBranch.trim().toLowerCase():return;case T.setMinWeightBranch.trim().toLowerCase():return;case T.setRandomBranch.trim().toLowerCase():return;case T.setWeightlessRandomBranch.trim().toLowerCase():return;case T.continuePlayback.trim().toLowerCase():{w(),i.add(Object.assign(Object.assign({},x),{action:m.bind(null,{subjectId:p,subjectName:"container",action:j})}));return}case T.openURI.trim().toLowerCase():{w(),i.add(Object.assign(Object.assign({},x),{action:_.bind(null,{subjectId:p,subjectName:"container",action:j,payload:{URI:v.args.uri}})})),r==null||r();return}default:console.error("Unexpected container event"),e.emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:v,branches:p,isEOV:y=!1}){const C=_r(v.events);if(C){const b=We(C.action,y);e.emit(I.interactives,{subjectId:v.id,subjectName:"container",type:L.actionChoice,actionType:b.type,payload:b.args}),i.add({timestamp:y?1/0:v.endTime,priority:"container",initiator:v.id,actionType:T.expect,action:u.bind(null,{subjectId:v.id,subjectName:"container"})}),n.isExpect=!0}else for(const b of v.events)o({action:b.action,container:v,branches:p,isEOV:y})}const d=({chapterId:v,action:p,branches:y=[]})=>{const C=e.emit.bind(e,I.interactives,{subjectId:v,subjectName:"chapter",type:L.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{const b=y.find(S=>S.id===p.args.branchId);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:v,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case T.setWeightlessRandomBranch.trim().toLowerCase():{const b=wc(y);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:v,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case T.setRandomBranch.trim().toLowerCase():{const b=Oc(y);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:v,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case T.setMaxWeightBranch.trim().toLowerCase():{const b=Ic(y);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:v,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case T.setMinWeightBranch.trim().toLowerCase():{const b=_c(y);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:v,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case T.continuePlayback.trim().toLowerCase():return C(),m.bind(null,{subjectId:v,subjectName:"chapter",action:p});case T.openURI.trim().toLowerCase():return C(),_.bind(null,{subjectId:v,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),e.emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function h(v){const p=_r(v.events);if(p){if(Te(v))return;e.emit(I.interactives,{subjectId:v.id,subjectName:"chapter",type:L.actionChoice,actionType:p.action.type,payload:p.action.args}),i.add({timestamp:1/0,priority:"chapter",initiator:v.id,actionType:T.expect,action:u.bind(null,{subjectId:v.id,subjectName:"chapter"})})}else v.events.forEach(y=>{const C=d({chapterId:v.id,action:y.action,branches:v.branches});C&&i.add({timestamp:1/0,priority:"chapter",initiator:v.id,actionType:y.action.type,action:C})})}const u=({subjectId:v,subjectName:p,action:y})=>{var C;t.pause(),e.emit(I.interactives,{subjectId:v,subjectName:p,type:L.actionExecution,actionType:(C=y==null?void 0:y.type)!==null&&C!==void 0?C:T.expect})},f=({subjectId:v,subjectName:p})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),e.emit(I.interactives,{subjectId:v,subjectName:p,type:L.actionExecution,actionType:"after-expect"})},m=({subjectId:v,subjectName:p,subjectType:y,action:C})=>{e.emit(I.interactives,{subjectId:v,subjectName:p,subjectType:y,type:L.actionExecution,actionType:C.type})},g=({subjectId:v,subjectName:p,subjectType:y,action:C,payload:b})=>{b.behaviour="change-chapter",e.emit(I.interactives,{subjectId:v,subjectName:p,subjectType:y,type:L.actionExecution,actionType:C.type,payload:b})},_=({subjectId:v,subjectName:p,subjectType:y,action:C,payload:b})=>{if(!b.URI)return;const S=window.open(b.URI,"_blank","noopener,noreferrer");S&&(S.opener=null),e.emit(I.interactives,{subjectId:v,subjectName:p,subjectType:y,type:L.actionExecution,actionType:C.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:f,setManifestChapterEvents:h,setManifestContainerEvents:c,stopExpect:s,state:n}};var Vt={},Sc=Y,Tc=Q,jr=Sc.WeakMap,$c=Tc(jr)&&/native code/.test(String(jr)),jc=Bn,Rc=Dn,Rr=jc("keys"),Mi=function(e){return Rr[e]||(Rr[e]=Rc(e))},Ni={},Ac=$c,rs=Y,Pc=Mt,xc=Yt,He=vt,Ue=Vn,Lc=Mi,Mc=Ni,Ar="Object already initialized",si=rs.TypeError,Nc=rs.WeakMap,Ee,zt,Ce,kc=function(e){return Ce(e)?zt(e):Ee(e,{})},Fc=function(e){return function(t){var i;if(!Pc(t)||(i=zt(t)).type!==e)throw si("Incompatible receiver, "+e+" required");return i}};if(Ac||Ue.state){var Z=Ue.state||(Ue.state=new Nc);Z.get=Z.get,Z.has=Z.has,Z.set=Z.set,Ee=function(e,t){if(Z.has(e))throw si(Ar);return t.facade=e,Z.set(e,t),t},zt=function(e){return Z.get(e)||{}},Ce=function(e){return Z.has(e)}}else{var $t=Lc("state");Mc[$t]=!0,Ee=function(e,t){if(He(e,$t))throw si(Ar);return t.facade=e,xc(e,$t,t),t},zt=function(e){return He(e,$t)?e[$t]:{}},Ce=function(e){return He(e,$t)}}var Vc={set:Ee,get:zt,has:Ce,enforce:kc,getterFor:Fc},ai=_t,Bc=vt,ns=Function.prototype,Dc=ai&&Object.getOwnPropertyDescriptor,ki=Bc(ns,"name"),Gc=ki&&function(){}.name==="something",Wc=ki&&(!ai||ai&&Dc(ns,"name").configurable),Hc={EXISTS:ki,PROPER:Gc,CONFIGURABLE:Wc},ss={},Uc=ji,zc=Math.max,Kc=Math.min,qc=function(e,t){var i=Uc(e);return i<0?zc(i+t,0):Kc(i,t)},Yc=Kt,Qc=qc,Xc=Ri,Pr=function(e){return function(t,i,r){var n=Yc(t),s=Xc(n),l=Qc(r,s),o;if(e&&i!=i){for(;s>l;)if(o=n[l++],o!=o)return!0}else for(;s>l;l++)if((e||l in n)&&n[l]===i)return e||l||0;return!e&&-1}},Zc={includes:Pr(!0),indexOf:Pr(!1)},Jc=Ct,ze=vt,td=Kt,ed=Zc.indexOf,id=Ni,xr=Jc([].push),rd=function(e,t){var i=td(e),r=0,n=[],s;for(s in i)!ze(id,s)&&ze(i,s)&&xr(n,s);for(;t.length>r;)ze(i,s=t[r++])&&(~ed(n,s)||xr(n,s));return n},as=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],nd=rd,sd=as,ad=Object.keys||function(t){return nd(t,sd)},od=_t,ld=Un,cd=Nt,dd=kt,hd=Kt,ud=ad;ss.f=od&&!ld?Object.defineProperties:function(t,i){dd(t);for(var r=hd(i),n=ud(i),s=n.length,l=0,o;s>l;)cd.f(t,o=n[l++],r[o]);return t};var fd=_i,vd=fd("document","documentElement"),pd=kt,yd=ss,Lr=as,md=Ni,gd=vd,bd=Gn,Ed=Mi,Mr=">",Nr="<",oi="prototype",li="script",os=Ed("IE_PROTO"),Ke=function(){},ls=function(e){return Nr+li+Mr+e+Nr+"/"+li+Mr},kr=function(e){e.write(ls("")),e.close();var t=e.parentWindow.Object;return e=null,t},Cd=function(){var e=bd("iframe"),t="java"+li+":",i;return e.style.display="none",gd.appendChild(e),e.src=String(t),i=e.contentWindow.document,i.open(),i.write(ls("document.F=Object")),i.close(),i.F},ae,ue=function(){try{ae=new ActiveXObject("htmlfile")}catch(t){}ue=typeof document!="undefined"?document.domain&&ae?kr(ae):Cd():kr(ae);for(var e=Lr.length;e--;)delete ue[oi][Lr[e]];return ue()};md[os]=!0;var cs=Object.create||function(t,i){var r;return t!==null?(Ke[oi]=pd(t),r=new Ke,Ke[oi]=null,r[os]=t):r=ue(),i===void 0?r:yd.f(r,i)},_d=lt,Id=!_d(function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype}),wd=vt,Od=Q,Sd=Si,Td=Mi,$d=Id,Fr=Td("IE_PROTO"),ci=Object,jd=ci.prototype,ds=$d?ci.getPrototypeOf:function(e){var t=Sd(e);if(wd(t,Fr))return t[Fr];var i=t.constructor;return Od(i)&&t instanceof i?i.prototype:t instanceof ci?jd:null},Rd=Yt,hs=function(e,t,i,r){return r&&r.enumerable?e[t]=i:Rd(e,t,i),e},Ad=lt,Pd=Q,xd=Mt,Ld=cs,Vr=ds,Md=hs,Nd=ct,di=Nd("iterator"),us=!1,ot,qe,Ye;[].keys&&(Ye=[].keys(),"next"in Ye?(qe=Vr(Vr(Ye)),qe!==Object.prototype&&(ot=qe)):us=!0);var kd=!xd(ot)||Ad(function(){var e={};return ot[di].call(e)!==e});kd?ot={}:ot=Ld(ot);Pd(ot[di])||Md(ot,di,function(){return this});var fs={IteratorPrototype:ot,BUGGY_SAFARI_ITERATORS:us},Fd=ct,Vd=Fd("toStringTag"),vs={};vs[Vd]="z";var Fi=String(vs)==="[object z]",Bd=Fi,Dd=Q,fe=bi,Gd=ct,Wd=Gd("toStringTag"),Hd=Object,Ud=fe(function(){return arguments}())=="Arguments",zd=function(e,t){try{return e[t]}catch(i){}},Vi=Bd?fe:function(e){var t,i,r;return e===void 0?"Undefined":e===null?"Null":typeof(i=zd(t=Hd(e),Wd))=="string"?i:Ud?fe(t):(r=fe(t))=="Object"&&Dd(t.callee)?"Arguments":r},Kd=Fi,qd=Vi,Yd=Kd?{}.toString:function(){return"[object "+qd(this)+"]"},Qd=Fi,Xd=Nt.f,Zd=Yt,Jd=vt,th=Yd,eh=ct,Br=eh("toStringTag"),ps=function(e,t,i,r){if(e){var n=i?e:e.prototype;Jd(n,Br)||Xd(n,Br,{configurable:!0,value:t}),r&&!Qd&&Zd(n,"toString",th)}},ih=fs.IteratorPrototype,rh=cs,nh=Se,sh=ps,ah=Vt,oh=function(){return this},lh=function(e,t,i,r){var n=t+" Iterator";return e.prototype=rh(ih,{next:nh(+!r,i)}),sh(e,n,!1,!0),ah[n]=oh,e},ch=$i,dh=It,ys=Hc,hh=lh,uh=ds,fh=ps,Dr=hs,vh=ct,Gr=Vt,ms=fs,ph=ys.PROPER;ys.CONFIGURABLE;ms.IteratorPrototype;var oe=ms.BUGGY_SAFARI_ITERATORS,Qe=vh("iterator"),Wr="keys",le="values",Hr="entries",yh=function(){return this},mh=function(e,t,i,r,n,s,l){hh(i,t,r);var o=function(p){if(p===n&&f)return f;if(!oe&&p in h)return h[p];switch(p){case Wr:return function(){return new i(this,p)};case le:return function(){return new i(this,p)};case Hr:return function(){return new i(this,p)}}return function(){return new i(this)}},c=t+" Iterator",d=!1,h=e.prototype,u=h[Qe]||h["@@iterator"]||n&&h[n],f=!oe&&u||o(n),m=t=="Array"&&h.entries||u,g,_,v;if(m&&(g=uh(m.call(new e)),g!==Object.prototype&&g.next&&(fh(g,c,!0,!0),Gr[c]=yh)),ph&&n==le&&u&&u.name!==le&&(d=!0,f=function(){return dh(u,this)}),n)if(_={values:o(le),keys:s?f:o(Wr),entries:o(Hr)},l)for(v in _)(oe||d||!(v in h))&&Dr(h,v,_[v]);else ch({target:t,proto:!0,forced:oe||d},_);return l&&h[Qe]!==f&&Dr(h,Qe,f,{name:n}),Gr[t]=f,_},gh=function(e,t){return{value:e,done:t}},bh=Kt,Ur=Vt,gs=Vc;Nt.f;var Eh=mh,ce=gh,bs="Array Iterator",Ch=gs.set,_h=gs.getterFor(bs);Eh(Array,"Array",function(e,t){Ch(this,{type:bs,target:bh(e),index:0,kind:t})},function(){var e=_h(this),t=e.target,i=e.kind,r=e.index++;return!t||r>=t.length?(e.target=void 0,ce(void 0,!0)):i=="keys"?ce(r,!1):i=="values"?ce(t[r],!1):ce([r,t[r]],!1)},"values");Ur.Arguments=Ur.Array;var Ih=ct,wh=Vt,Oh=Ih("iterator"),Sh=Array.prototype,Th=function(e){return e!==void 0&&(wh.Array===e||Sh[Oh]===e)},$h=Vi,zr=Oi,jh=Ei,Rh=Vt,Ah=ct,Ph=Ah("iterator"),Es=function(e){if(!jh(e))return zr(e,Ph)||zr(e,"@@iterator")||Rh[$h(e)]},xh=It,Lh=wi,Mh=kt,Nh=Ii,kh=Es,Fh=TypeError,Vh=function(e,t){var i=arguments.length<2?kh(e):t;if(Lh(i))return Mh(xh(i,e));throw Fh(Nh(e)+" is not iterable")},Bh=It,Kr=kt,Dh=Oi,Gh=function(e,t,i){var r,n;Kr(e);try{if(r=Dh(e,"return"),!r){if(t==="throw")throw i;return i}r=Bh(r,e)}catch(s){n=!0,r=s}if(t==="throw")throw i;if(n)throw r;return Kr(r),i},Wh=Hn,Hh=It,Uh=kt,zh=Ii,Kh=Th,qh=Ri,qr=xn,Yh=Vh,Qh=Es,Yr=Gh,Xh=TypeError,ve=function(e,t){this.stopped=e,this.result=t},Qr=ve.prototype,Zh=function(e,t,i){var r=i&&i.that,n=!!(i&&i.AS_ENTRIES),s=!!(i&&i.IS_RECORD),l=!!(i&&i.IS_ITERATOR),o=!!(i&&i.INTERRUPTED),c=Wh(t,r),d,h,u,f,m,g,_,v=function(y){return d&&Yr(d,"normal",y),new ve(!0,y)},p=function(y){return n?(Uh(y),o?c(y[0],y[1],v):c(y[0],y[1])):o?c(y,v):c(y)};if(s)d=e.iterator;else if(l)d=e;else{if(h=Qh(e),!h)throw Xh(zh(e)+" is not iterable");if(Kh(h)){for(u=0,f=qh(e);f>u;u++)if(m=p(e[u]),m&&qr(Qr,m))return m;return new ve(!1)}d=Yh(e,h)}for(g=s?e.next:d.next;!(_=Hh(g,d)).done;){try{m=p(_.value)}catch(y){Yr(d,"throw",y)}if(typeof m=="object"&&m&&qr(Qr,m))return m}return new ve(!1)},Jh=Ti,tu=Nt,eu=Se,iu=function(e,t,i){var r=Jh(t);r in e?tu.f(e,r,eu(0,i)):e[r]=i},ru=$i,nu=Zh,su=iu;ru({target:"Object",stat:!0},{fromEntries:function(t){var i={};return nu(t,function(r,n){su(i,r,n)},{AS_ENTRIES:!0}),i}});var au=Ci,ou=au.Object.fromEntries,lu={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},cu=lu,du=Y,hu=Vi,uu=Yt,Xr=Vt,fu=ct,Zr=fu("toStringTag");for(var Xe in cu){var Jr=du[Xe],Ze=Jr&&Jr.prototype;Ze&&hu(Ze)!==Zr&&uu(Ze,Zr,Xe),Xr[Xe]=Xr.Array}var vu=ou,pu=vu,yu=pu,mu=yu,gu=bn(mu);const tn=(e,t)=>{const i={};return e.map(r=>{if(!i[r]){const n=t.chapters.find(l=>l.id===r);if(!n)return null;const s=t.media.videos.find(l=>n.videoId===l.id);if(!s)return null;i[r]=Cs(s)}return i[r]}).filter(Boolean)},bu=e=>{for(const t of e.variants)if(Eu(t)&&"payload"in t)return t.payload.id},Eu=e=>e.type==="custom"&&"payload"in e&&e.payload.type==="vk",Cs=e=>{const t=bu(e);if(!t)return null;const i=t.split("_").pop();return i?parseInt(i,10):null},Cu=(e,t)=>{for(const i of e.media.videos)if(t===Cs(i)){for(const r of e.chapters)if(r.videoId===i.id)return r.id;return}},_u=(e,t)=>e.reduce((i,r)=>{const n=Cu(t,r);return n?[...i,n]:i},[]);var bt,rt,_e,Pt,it,Ie,U,dt,nt,xt,J,Bt,_s,en,hi,Is;const Iu=864e5,wu=90*Iu,Ou=50,Su=100;class Tu{constructor({interactiveController:t,globalEventEmitter:i,videoId:r,apiController:n,historySettings:s,localStorageController:l}){var o,c,d;bt.add(this),this.state={history$:new H([]),hasPrevChapter$:new H(!1),prevChapter$:new H(null),isInitialChapter$:new H(!1)},rt.set(this,null),_e.set(this,[]),Pt.set(this,!1),it.set(this,null),Ie.set(this,null),U.set(this,null),dt.set(this,null),nt.set(this,null),xt.set(this,null),J.set(this,null),Bt.set(this,new we),E(this,rt,{expiryLimitInDays:(s==null?void 0:s.expiryLimitInDays)||wu,maxChaptersLength:(s==null?void 0:s.maxChaptersLength)||Su,maxProjectsLength:(s==null?void 0:s.maxProjectsLength)||Ou},"f"),E(this,dt,n,"f"),E(this,nt,l,"f"),E(this,U,r,"f"),E(this,J,i,"f"),E(this,xt,t,"f"),!((o=this===null||this===void 0?void 0:this.state)===null||o===void 0)&&o.history$&&((c=a(this,Bt,"f"))===null||c===void 0||c.add((d=this===null||this===void 0?void 0:this.state)===null||d===void 0?void 0:d.history$.subscribe(h=>{var u,f,m,g,_;(u=this.state)===null||u===void 0||u.prevChapter$.next(ii(h,-2)||null),(f=this.state)===null||f===void 0||f.hasPrevChapter$.next(h.length>1),(m=this.state)===null||m===void 0||m.isInitialChapter$.next(this.getInitialChapter()===((_=(g=a(this,it,"f"))===null||g===void 0?void 0:g.metadata)===null||_===void 0?void 0:_.initChapterId))}))),a(this,bt,"m",_s).call(this)}get inited(){return a(this,Pt,"f")}updateHistory(t,i=!0){var r;return A(this,void 0,void 0,function*(){if(!a(this,it,"f")||!a(this,U,"f")||!a(this,rt,"f"))return;const n=a(this,it,"f"),s=t.length-a(this,rt,"f").maxChaptersLength,l=s>0?t.slice(s):t,o=tn(l,n);E(this,Ie,o,"f"),(r=this===null||this===void 0?void 0:this.state)===null||r===void 0||r.history$.next(l),i&&(a(this,dt,"f")?yield a(this,dt,"f").save(a(this,U,"f"),o):a(this,nt,"f")&&a(this,bt,"m",Is).call(this))})}getProjectHistory(){var t,i;return A(this,void 0,void 0,function*(){if(!a(this,it,"f")||!a(this,U,"f"))return;const r=a(this,it,"f");let n=tn([this.getInitialChapter()],r);if(a(this,dt,"f")&&(n=yield a(this,dt,"f").fetch(a(this,U,"f"))),a(this,nt,"f")){const o=(t=a(this,bt,"m",hi).call(this)[a(this,U,"f")])===null||t===void 0?void 0:t.value;o!=null&&o.length&&(n=o)}const s=_u(n,r);(i=this===null||this===void 0?void 0:this.state)===null||i===void 0||i.history$.next(s)})}getInitialChapter(){var t,i;const r=(t=this.state)===null||t===void 0?void 0:t.history$.getValue();return ii(r,-1)||((i=a(this,it,"f"))===null||i===void 0?void 0:i.metadata.initChapterId)}destroy(){var t,i;this.state=null,E(this,U,null,"f"),E(this,dt,null,"f"),E(this,nt,null,"f"),E(this,xt,null,"f"),(t=a(this,Bt,"f"))===null||t===void 0||t.unsubscribe(),E(this,Bt,null,"f"),E(this,Pt,!1,"f"),E(this,rt,null,"f"),a(this,_e,"f").forEach(r=>{var n;return(n=a(this,J,"f"))===null||n===void 0?void 0:n.off(...r)}),(i=a(this,J,"f"))===null||i===void 0||i.emit(I.historyDestroyed),E(this,J,null,"f")}}rt=new WeakMap,_e=new WeakMap,Pt=new WeakMap,it=new WeakMap,Ie=new WeakMap,U=new WeakMap,dt=new WeakMap,nt=new WeakMap,xt=new WeakMap,J=new WeakMap,Bt=new WeakMap,bt=new WeakSet,_s=function(){if(!a(this,J,"f"))return;const t=[I.manifestChanged,a(this,bt,"m",en).bind(this)];a(this,J,"f").on(...t),a(this,_e,"f").push(t)},en=function({manifest:t}){return A(this,void 0,void 0,function*(){!a(this,xt,"f")||!a(this,J,"f")||(E(this,it,t,"f"),yield this.getProjectHistory(),yield a(this,xt,"f").setChapter({chapterId:this.getInitialChapter(),pushToHistory:!1}),a(this,Pt,"f")||(E(this,Pt,!0,"f"),a(this,J,"f").emit(I.historyInited,{initChapterId:this.getInitialChapter()})))})},hi=function(){var t;return((t=a(this,nt,"f"))===null||t===void 0?void 0:t.read())||{}},Is=function(){if(!a(this,nt,"f")||!a(this,U,"f")||!a(this,rt,"f"))return;const t=a(this,Ie,"f"),i=new Date().getTime(),r=Object.entries(Object.assign(Object.assign({},a(this,bt,"m",hi).call(this)),{[a(this,U,"f")]:{value:t,expiry:new Date().getTime()+a(this,rt,"f").expiryLimitInDays}})).filter(([,{expiry:n}])=>n>=i).sort(([,{expiry:n}],[,{expiry:s}])=>s-n);r.length>a(this,rt,"f").maxProjectsLength&&r.pop(),a(this,nt,"f").save(gu(r))};var Dt,ws,ui,rn;class st{constructor(t,i,r,n){this.target=t,this.type=i,this.listener=r,this.options=a(st,Dt,"m",ws).call(st,t,n),this.target.addEventListener(i,r,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}Dt=st,ws=function(t,i){if(i===void 0)return!1;if(typeof i=="boolean")return i;{const r=new Set(["passive","capture"]),n=Object.keys(i).filter(l=>!r.has(l));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),a(st,Dt,"m",rn).call(st,t)?i:i.capture||!1}},rn=function(t){let i=a(st,Dt,"f",ui);if(i===void 0){i=!1;try{const r={},n={get:()=>(i=!0,!1)};Object.defineProperty(r,"passive",n),Object.defineProperty(r,"capture",n);const s=()=>{};t.addEventListener("test",s,r),t.removeEventListener("test",s,r)}catch(r){i=!1}E(st,Dt,i,"f",ui)}return i||!1};ui={value:void 0};class $u{constructor(){this.bindingMap=new Ec}release(){this.removeAll(),this.bindingMap=null}listen(t,i,r,n){if(!this.bindingMap)return;const s=new st(t,i,r,n);this.bindingMap.push(i,s)}listenOnce(t,i,r,n){const s=l=>{this.unlisten(t,i,s),r(l)};this.listen(t,i,s,n)}unlisten(t,i,r){if(!this.bindingMap)return;const n=this.bindingMap.get(i)||[];for(const s of n)s.target===t&&(r===s.listener||!r)&&(s.unlisten(),this.bindingMap.remove(i,s))}removeAll(){if(!this.bindingMap)return;const t=this.bindingMap.getAll();for(const i of t)i.unlisten();this.bindingMap.clear()}}class ju{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const i=(t=this.rootElement.getContext("2d"))===null||t===void 0?void 0:t.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!i)return!1;const r=i.data,n=r.length;for(let s=3;s<n;s+=40)if(r[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){var t;this.canvasImgSrc&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}updateCanvasDimensions(t,i=!1){return A(this,void 0,void 0,function*(){const r=t.width+t.height;if(this._prevSizeId===r)return;let n;i&&(n=yield this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,i&&n&&this.restore(n),this._prevSizeId=r})}save(){return A(this,void 0,void 0,function*(){const t=this.rootElement.toDataURL("image/jpeg",1),i=new Image;return i.crossOrigin="anonymous",i.src=t,yield i.decode(),i})}restore(t){var i;this.rootElement&&((i=this.rootElement.getContext("2d"))===null||i===void 0||i.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}}class Ru{constructor({parentElement:t,endOffsetMs:i=250,onError:r}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=n=>{const s=n!=null?n:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,l=this.isChapterEndTime(s);if(this.isContainerTime(s))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(l)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
import{loadVKLangPack as Vn,ValueSubject as H,Subscription as Xt,Observable as Fe,getCurrentBrowser as kn,CurrentClientBrowser as Fn,once as Bn}from"@vkontakte/videoplayer-shared/es2015.esm.js";import{v4 as Dn}from"uuid";import{Player as Wn}from"@vkontakte/videoplayer-core/es2015.esm.js";const Un="1.0.8-beta.1";function xi(i,t=1){let e="0",n="0",r="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+r},${t})`}const Q="SDK_NAME",Hn="SDK_NAME-controls-container",Pi=()=>document.querySelector(`.${Hn}`),Gn=.4,Y={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Be={top:"flex-start",bottom:"flex-end",center:"center"},De={start:"flex-start",end:"flex-end",center:"center"},We={start:"left",end:"right",center:"center"},Li=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=Be[(e=t==null?void 0:t.text)===null||e===void 0?void 0:e.gravityVertical])!==null&&n!==void 0?n:Be.center,i.style.justifyContent=(s=De[(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.gravityHorizontal])!==null&&s!==void 0?s:De.center,i.style.textAlign=(o=We[(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.alignment])!==null&&o!==void 0?o:We.start},Mi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d;i.style.color=(s=(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.color)!==null&&s!==void 0?s:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.size)!==null&&o!==void 0?o:e.textSize})`,i.textContent=(d=(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.value)!==null&&d!==void 0?d:e.textContent},Ni=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=xi((r=(n=t==null?void 0:t.background)===null||n===void 0?void 0:n.color)!==null&&r!==void 0?r:e.backgroundColor,(l=(s=t==null?void 0:t.background)===null||s===void 0?void 0:s.alpha)!==null&&l!==void 0?l:e.backgroundAlpha)},Vi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d,h,u,v,m,g;i.style.border=`calc(${n.height} * ${(l=(s=(r=t==null?void 0:t.shape)===null||r===void 0?void 0:r.border)===null||s===void 0?void 0:s.width)!==null&&l!==void 0?l:e.borderWidth}) solid ${xi((d=(c=(o=t==null?void 0:t.shape)===null||o===void 0?void 0:o.border)===null||c===void 0?void 0:c.color)!==null&&d!==void 0?d:e.borderColor,(v=(u=(h=t==null?void 0:t.shape)===null||h===void 0?void 0:h.border)===null||u===void 0?void 0:u.alpha)!==null&&v!==void 0?v:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(g=(m=t==null?void 0:t.shape)===null||m===void 0?void 0:m.roundCorners)!==null&&g!==void 0?g:e.roundCorners})`},je=({target:i,layoutParams:t,fallback:e})=>{var n;i.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:e.angle}rad)`},ee="int",$e={AREA:`${ee}_area`,TEXT:`${ee}_text`,BUTTON:`${ee}_bttn`};class Re{constructor(t){this.control=t}createView(t){var e;const n=document.createElement("div");n.classList.add(`${Q}-control-container-${this.control.id}`),t(n,this.control.layoutParams);const r=((e=this.control.layoutParams.innerSizesDependOn)!==null&&e!==void 0?e:Y.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:r}}setEvents(t,e){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",s=>{s.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${Q}-control-container-${this.control.id}`)}}const ki=i=>{if(i.type.trim().toLowerCase()==="area")return new zn(i)};class zn extends Re{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");return s.classList.add(`${Q}-${this.control.id}`),s.setAttribute("data-testid",$e.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",Ni({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},Y),{backgroundColor:"transparent"})}),Vi({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},Y),{borderAlpha:0}),dependsOn:n}),je({target:s,layoutParams:this.control.layoutParams,fallback:Y}),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${Q}-${this.control.id}`)}}const Fi=i=>{if(i.type.trim().toLowerCase()==="button")return new qn(i)};class qn extends Re{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");s.type="button",s.classList.add(`${Q}-${this.control.id}`),s.setAttribute("data-testid",$e.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";const l=document.createElement("span");return l.style.display="inline-block",l.style.whiteSpace="pre",l.style.overflow="hidden",l.style.textOverflow="ellipsis",je({target:s,layoutParams:this.control.layoutParams,fallback:Y}),Ni({target:s,props:this.control.props,fallback:Y}),Vi({target:s,props:this.control.props,fallback:Y,dependsOn:n}),Li({target:s,props:this.control.props}),Mi({target:l,props:this.control.props,fallback:Y,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${Q}-${this.control.id}`)}}const Qn=i=>{if(i.type.trim().toLowerCase()==="text")return new Kn(i)};class Kn extends Re{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${Q}-${this.control.id}`),s.setAttribute("data-testid",$e.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";const l=document.createElement("span");return l.style.whiteSpace="pre",je({target:s,layoutParams:this.control.layoutParams,fallback:Y}),Li({target:s,props:this.control.props}),Mi({target:l,props:this.control.props,fallback:Y,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${Q}-${this.control.id}`)}}class Yn{constructor(t){this.layout=t}}const Xn=i=>{if(i.type.trim().toLowerCase()==="relative")return new Bi(i)};class Bi extends Yn{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,e){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${e.width})`,t.style.height=`calc(var(--interactive-content-height) * ${e.height})`,t.style.left=`calc(var(--interactive-content-width) * ${e.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${e.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function st(i,t){var e={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(i);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(i,n[r])&&(e[n[r]]=i[n[r]]);return e}function A(i,t,e,n){function r(s){return s instanceof e?s:new e(function(l){l(s)})}return new(e||(e=Promise))(function(s,l){function o(h){try{d(n.next(h))}catch(u){l(u)}}function c(h){try{d(n.throw(h))}catch(u){l(u)}}function d(h){h.done?s(h.value):r(h.value).then(o,c)}d((n=n.apply(i,t||[])).next())})}function a(i,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?i!==t||!n:!t.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(i):n?n.value:t.get(i)}function C(i,t,e,n,r){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?i!==t||!r:!t.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?r.call(i,e):r?r.value=e:t.set(i,e),e}var Ct,Ht,Ue;class Di{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",Ht).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),a(this,Ct,"m",Ht).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",Ht).call(this)}}Ct=new WeakSet,Ht=function(){this.controls=a(this,Ct,"m",Ue).call(this)},Ue=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((e,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};const Wi=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Zn(i,t)};class Zn extends Di{constructor(t,e){super(t),this.rootElement=e!=null?e:Pi(),this.layout=new Bi(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Fi),this.addControlFactory("text",Qn),this.addControlFactory("area",ki)}createView(t){const e=document.createElement("div");return e.classList.add(`${Q}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{const r=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(r,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){const t=this.getElement();t&&(t.style.visibility="hidden")}show(){const t=this.getElement();t&&(t.style.visibility="visible")}enable(){const t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){const t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=Gn,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${Q}-${this.container.id}`)}}var ie=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function Jn(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Vt=function(i){return i&&i.Math==Math&&i},at=Vt(typeof globalThis=="object"&&globalThis)||Vt(typeof window=="object"&&window)||Vt(typeof self=="object"&&self)||Vt(typeof ie=="object"&&ie)||function(){return this}()||ie||Function("return this")(),ut=function(i){try{return!!i()}catch(t){return!0}},tr=ut,Zt=!tr(function(){var i=function(){}.bind();return typeof i!="function"||i.hasOwnProperty("prototype")}),er=Zt,Ui=Function.prototype,He=Ui.apply,Ge=Ui.call,ir=typeof Reflect=="object"&&Reflect.apply||(er?Ge.bind(He):function(){return Ge.apply(He,arguments)}),Hi=Zt,Gi=Function.prototype,me=Gi.call,nr=Hi&&Gi.bind.bind(me,me),St=Hi?nr:function(i){return function(){return me.apply(i,arguments)}},zi=St,rr=zi({}.toString),sr=zi("".slice),qi=function(i){return sr(rr(i),8,-1)},ar=qi,or=St,Qi=function(i){if(ar(i)==="Function")return or(i)},be=typeof document=="object"&&document.all,lr=typeof be=="undefined"&&be!==void 0,Ki={all:be,IS_HTMLDDA:lr},Yi=Ki,cr=Yi.all,ft=Yi.IS_HTMLDDA?function(i){return typeof i=="function"||i===cr}:function(i){return typeof i=="function"},Xi={},dr=ut,xt=!dr(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),hr=Zt,kt=Function.prototype.call,Ae=hr?kt.bind(kt):function(){return kt.apply(kt,arguments)},Zi={},Ji={}.propertyIsEnumerable,tn=Object.getOwnPropertyDescriptor,ur=tn&&!Ji.call({1:2},1);Zi.f=ur?function(t){var e=tn(this,t);return!!e&&e.enumerable}:Ji;var en=function(i,t){return{enumerable:!(i&1),configurable:!(i&2),writable:!(i&4),value:t}},fr=St,vr=ut,pr=qi,ne=Object,yr=fr("".split),mr=vr(function(){return!ne("z").propertyIsEnumerable(0)})?function(i){return pr(i)=="String"?yr(i,""):ne(i)}:ne,nn=function(i){return i==null},br=nn,gr=TypeError,rn=function(i){if(br(i))throw gr("Can't call method on "+i);return i},Er=mr,Cr=rn,_r=function(i){return Er(Cr(i))},ze=ft,sn=Ki,Ir=sn.all,Jt=sn.IS_HTMLDDA?function(i){return typeof i=="object"?i!==null:ze(i)||i===Ir}:function(i){return typeof i=="object"?i!==null:ze(i)},an={},re=an,se=at,wr=ft,qe=function(i){return wr(i)?i:void 0},on=function(i,t){return arguments.length<2?qe(re[i])||qe(se[i]):re[i]&&re[i][t]||se[i]&&se[i][t]},Sr=St,Or=Sr({}.isPrototypeOf),Tr=typeof navigator!="undefined"&&String(navigator.userAgent)||"",ln=at,ae=Tr,Qe=ln.process,Ke=ln.Deno,Ye=Qe&&Qe.versions||Ke&&Ke.version,Xe=Ye&&Ye.v8,z,qt;Xe&&(z=Xe.split("."),qt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!qt&&ae&&(z=ae.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=ae.match(/Chrome\/(\d+)/),z&&(qt=+z[1])));var jr=qt,Ze=jr,$r=ut,Rr=at,Ar=Rr.String,cn=!!Object.getOwnPropertySymbols&&!$r(function(){var i=Symbol();return!Ar(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&Ze&&Ze<41}),xr=cn,dn=xr&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Pr=on,Lr=ft,Mr=Or,Nr=dn,Vr=Object,hn=Nr?function(i){return typeof i=="symbol"}:function(i){var t=Pr("Symbol");return Lr(t)&&Mr(t.prototype,Vr(i))},kr=String,Fr=function(i){try{return kr(i)}catch(t){return"Object"}},Br=ft,Dr=Fr,Wr=TypeError,un=function(i){if(Br(i))return i;throw Wr(Dr(i)+" is not a function")},Ur=un,Hr=nn,Gr=function(i,t){var e=i[t];return Hr(e)?void 0:Ur(e)},oe=Ae,le=ft,ce=Jt,zr=TypeError,qr=function(i,t){var e,n;if(t==="string"&&le(e=i.toString)&&!ce(n=oe(e,i))||le(e=i.valueOf)&&!ce(n=oe(e,i))||t!=="string"&&le(e=i.toString)&&!ce(n=oe(e,i)))return n;throw zr("Can't convert object to primitive value")},fn={exports:{}},Je=at,Qr=Object.defineProperty,Kr=function(i,t){try{Qr(Je,i,{value:t,configurable:!0,writable:!0})}catch(e){Je[i]=t}return t},Yr=at,Xr=Kr,ti="__core-js_shared__",Zr=Yr[ti]||Xr(ti,{}),Jr=Zr,ei=Jr;(fn.exports=function(i,t){return ei[i]||(ei[i]=t!==void 0?t:{})})("versions",[]).push({version:"3.31.0",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"});var ts=fn.exports,es=rn,is=Object,vn=function(i){return is(es(i))},ns=St,rs=vn,ss=ns({}.hasOwnProperty),xe=Object.hasOwn||function(t,e){return ss(rs(t),e)},as=St,os=0,ls=Math.random(),cs=as(1 .toString),ds=function(i){return"Symbol("+(i===void 0?"":i)+")_"+cs(++os+ls,36)},hs=at,us=ts,ii=xe,fs=ds,vs=cn,ps=dn,_t=hs.Symbol,de=us("wks"),ys=ps?_t.for||_t:_t&&_t.withoutSetter||fs,ms=function(i){return ii(de,i)||(de[i]=vs&&ii(_t,i)?_t[i]:ys("Symbol."+i)),de[i]},bs=Ae,ni=Jt,ri=hn,gs=Gr,Es=qr,Cs=ms,_s=TypeError,Is=Cs("toPrimitive"),ws=function(i,t){if(!ni(i)||ri(i))return i;var e=gs(i,Is),n;if(e){if(t===void 0&&(t="default"),n=bs(e,i,t),!ni(n)||ri(n))return n;throw _s("Can't convert object to primitive value")}return t===void 0&&(t="number"),Es(i,t)},Ss=ws,Os=hn,pn=function(i){var t=Ss(i,"string");return Os(t)?t:t+""},Ts=at,si=Jt,ge=Ts.document,js=si(ge)&&si(ge.createElement),$s=function(i){return js?ge.createElement(i):{}},Rs=xt,As=ut,xs=$s,yn=!Rs&&!As(function(){return Object.defineProperty(xs("div"),"a",{get:function(){return 7}}).a!=7}),Ps=xt,Ls=Ae,Ms=Zi,Ns=en,Vs=_r,ks=pn,Fs=xe,Bs=yn,ai=Object.getOwnPropertyDescriptor;Xi.f=Ps?ai:function(t,e){if(t=Vs(t),e=ks(e),Bs)try{return ai(t,e)}catch(n){}if(Fs(t,e))return Ns(!Ls(Ms.f,t,e),t[e])};var Ds=ut,Ws=ft,Us=/#|\.prototype\./,Pt=function(i,t){var e=Gs[Hs(i)];return e==qs?!0:e==zs?!1:Ws(t)?Ds(t):!!t},Hs=Pt.normalize=function(i){return String(i).replace(Us,".").toLowerCase()},Gs=Pt.data={},zs=Pt.NATIVE="N",qs=Pt.POLYFILL="P",Qs=Pt,oi=Qi,Ks=un,Ys=Zt,Xs=oi(oi.bind),Zs=function(i,t){return Ks(i),t===void 0?i:Ys?Xs(i,t):function(){return i.apply(t,arguments)}},mn={},Js=xt,ta=ut,ea=Js&&ta(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),ia=Jt,na=String,ra=TypeError,sa=function(i){if(ia(i))return i;throw ra(na(i)+" is not an object")},aa=xt,oa=yn,la=ea,Ft=sa,li=pn,ca=TypeError,he=Object.defineProperty,da=Object.getOwnPropertyDescriptor,ue="enumerable",fe="configurable",ve="writable";mn.f=aa?la?function(t,e,n){if(Ft(t),e=li(e),Ft(n),typeof t=="function"&&e==="prototype"&&"value"in n&&ve in n&&!n[ve]){var r=da(t,e);r&&r[ve]&&(t[e]=n.value,n={configurable:fe in n?n[fe]:r[fe],enumerable:ue in n?n[ue]:r[ue],writable:!1})}return he(t,e,n)}:he:function(t,e,n){if(Ft(t),e=li(e),Ft(n),oa)try{return he(t,e,n)}catch(r){}if("get"in n||"set"in n)throw ca("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var ha=xt,ua=mn,fa=en,va=ha?function(i,t,e){return ua.f(i,t,fa(1,e))}:function(i,t,e){return i[t]=e,i},Bt=at,pa=ir,ya=Qi,ma=ft,ba=Xi.f,ga=Qs,yt=an,Ea=Zs,mt=va,ci=xe,Ca=function(i){var t=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new i;case 1:return new i(e);case 2:return new i(e,n)}return new i(e,n,r)}return pa(i,this,arguments)};return t.prototype=i.prototype,t},_a=function(i,t){var e=i.target,n=i.global,r=i.stat,s=i.proto,l=n?Bt:r?Bt[e]:(Bt[e]||{}).prototype,o=n?yt:yt[e]||mt(yt,e,{})[e],c=o.prototype,d,h,u,v,m,g,w,f,p;for(v in t)d=ga(n?v:e+(r?".":"#")+v,i.forced),h=!d&&l&&ci(l,v),g=o[v],h&&(i.dontCallGetSet?(p=ba(l,v),w=p&&p.value):w=l[v]),m=h&&w?w:t[v],!(h&&typeof g==typeof m)&&(i.bind&&h?f=Ea(m,Bt):i.wrap&&h?f=Ca(m):s&&ma(m)?f=ya(m):f=m,(i.sham||m&&m.sham||g&&g.sham)&&mt(f,"sham",!0),mt(o,v,f),s&&(u=e+"Prototype",ci(yt,u)||mt(yt,u,{}),mt(yt[u],v,m),i.real&&c&&(d||!c[v])&&mt(c,v,m)))},Ia=Math.ceil,wa=Math.floor,Sa=Math.trunc||function(t){var e=+t;return(e>0?wa:Ia)(e)},Oa=Sa,bn=function(i){var t=+i;return t!==t||t===0?0:Oa(t)},Ta=bn,ja=Math.min,$a=function(i){return i>0?ja(Ta(i),9007199254740991):0},Ra=$a,Aa=function(i){return Ra(i.length)},xa=_a,Pa=vn,La=Aa,Ma=bn;xa({target:"Array",proto:!0},{at:function(t){var e=Pa(this),n=La(e),r=Ma(t),s=r>=0?r:n+r;return s<0||s>=n?void 0:e[s]}});var Na=on,Va=Na,ka=Va,Fa=ka("Array","at"),Ba=Fa,Da=Ba,Wa=Da,Ua=Wa,Ee=Jn(Ua);function gn(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const Lt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},Ot=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Pe=i=>Ot(i,Lt.Object),Ce=i=>Ot(i,Lt.String),Le=i=>Ot(i,Lt.Array),En=i=>Ot(i,Lt.Number),Ha=i=>Ot(i,Lt.Function),di=i=>En(i)&&!isNaN(i),Rt=i=>Pe(i)&&Object.keys(i).length===0,Cn=i=>Le(i)&&!i.length,Dt=(i,t)=>Ce(i)&&(t?i.trim():i).length,_n=window.navigator.userAgent.toLowerCase(),Ga=/mobi/i.test(_n);_n.indexOf("android")>-1;const za="video_interactive",qa="videoint",Qa=250;class Ka{constructor(t){this.onResize=e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))},this.handleChapterChange=e=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(n=this.onError)===null||n===void 0||n.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}},this.handleManifestChange=(e,n=[])=>A(this,void 0,void 0,function*(){var r;if(!En(e.graph.edit.chapters[0].x)){this.isReady=!1,(r=this.onError)===null||r===void 0||r.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let s;try{s=yield Vn(this.lang,za,qa)}catch(o){console.log("Unable to load graph language pack")}const{GraphEditor:l}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new l(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:s}),this.ngEditor.on("control",({name:o,chapterId:c})=>{o==="openPreview"&&this.onOpenPreviewClick(c)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo=Object.assign({},o)})}this.visitedChapterIds=new Set(n),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0}),this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:r,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=e,this.onError=n,this.lang=r!=null?r:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=Ya(t),this.resizeObserver=new ResizeObserver(gn(this.onResize,Qa)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var t,e;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)===null||t===void 0||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)===null||e===void 0||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function Ya(i){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height="100%",t.style.width="100%",t.style.display="none",i.append(t),t}const Qt=(i="",t="")=>{i=i.split("."),t=t.split(".");let e=0;for(let n=0;n<Math.max(i.length,t.length)&&!e;n++)i[n]>t[n]?e=1:i[n]<t[n]?e=-1:e=0;return e},Xa="3.1",hi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Za={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ja=i=>{const t=[];for(const e of i.chapters){let n;const r=[];for(let o of e.branches){const{isDefault:c}=o,d=st(o,["isDefault"]);c&&(n=d.id),r.push(d)}let s=[];const l=[];for(let o of e.containers){const{fallbackStrategy:c}=o,d=st(o,["fallbackStrategy"]),h=!!d.endTime;let u=[Za];switch(c){case"await":h?u=[]:s=[];break;case"default":{const v={type:"onSuspense",action:{type:hi.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?u=[v]:s=[v];break}case"random":case"weightlessRandom":case"max":case"min":{const v={type:"onSuspense",action:{type:hi[c],args:{}}};h?u=[v]:s=[v];break}}for(const v of d.controls)l.push(Object.assign(Object.assign({},d),{controls:[Object.assign({},v)],id:Dn(),events:u}))}t.push(Object.assign(Object.assign({},e),{containers:l,events:s,branches:r}))}return i.metadata.version=Xa,i.metadata.updated=new Date().toISOString(),Object.assign(Object.assign({},i),{chapters:t})},to="3.2",eo=i=>{if(!i.media){const t=i.metadata,{media:e}=t,n=st(t,["media"]);return Object.assign(Object.assign({},i),{metadata:Object.assign(Object.assign({},n),{version:to}),media:e})}return i},io="3.3",no=(i=[])=>({edit:{chapters:i},view:{}}),ui={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},ro=i=>{var t;const e=[],n=[];for(const r of i.chapters){const{id:s,x:l,y:o}=r,c=st(r,["id","x","y"]),d=c.containers.map(h=>{var u;return Object.assign(Object.assign({},h),{controls:h.controls.map(v=>{var{subtype:m,type:g}=v,w=st(v,["subtype","type"]);return Object.assign(Object.assign({},w),{type:m!=null?m:g})}),events:!((u=h.events)===null||u===void 0)&&u.length?h.events:[ui]})});e.push(Object.assign(Object.assign({id:s},c),{containers:d,events:!((t=c.events)===null||t===void 0)&&t.length?c.events:[ui]})),n.push({id:s,x:l,y:o})}return Object.assign(Object.assign({},i),{chapters:e,graph:no(n),metadata:Object.assign(Object.assign({},i.metadata),{version:io})})},so=[{version:"3.0",migrate:Ja},{version:"3.1",migrate:eo},{version:"3.2",migrate:ro}],ao=i=>so.reduce((t,e)=>Qt(t.metadata.version,e.version)?t:e.migrate(t),i),oo=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),j=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var dt;(function(i){i.GO_NEXT_BUTTON="GO_NEXT_BUTTON",i.GO_NEXT_AREA="GO_NEXT_AREA",i.WATCH_AGAIN="WATCH_AGAIN",i.OPEN_GRAPH="OPEN_GRAPH",i.CLOSE_GRAPH="CLOSE_GRAPH"})(dt||(dt={}));const fi={metadata:"Object",chapters:"Array"},lo="3.0.0",co="3.3.0",In=i=>{const t=Qt(i,lo);return t===-1?!1:t===0?!0:Qt(i,co)!==1},ho=i=>{if(!Pe(i))return!1;for(const t in fi)if(!i[t]||!Ot(i[t],fi[t]))return!1;return In(i.metadata.version)},wn=i=>i.type===oo.Text;class S{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}S.Severity={RECOVERABLE:1,CRITICAL:2};S.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Sn{constructor(){this.listeners={}}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];const n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){const n=this.listeners[t];if(!n)return this;for(let r=n.length;r>0;r--)if(n[r]===e){n.splice(r,1);break}return this}emit(t,...e){const n=this.listeners[t];return n?(n.forEach(r=>{r(...e)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}}class uo{constructor(t){this.addFn=(e,n=!1)=>{Ha(e)&&(this.fns.push(e),n&&this.updateFn())},this.removeFn=(e,n=!1)=>{this.fns=this.fns.filter(r=>r!==e),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class fo{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!==null&&e!==void 0?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!==null&&n!==void 0?n:[]}}exec(t,e){return A(this,void 0,void 0,function*(){return vo(...this.loaders[t])(e)})}}function vo(...i){return function(e){return A(this,void 0,void 0,function*(){const n=[...i];for(;n.length>0;)e=yield n.shift()(e);return e})}}function Kt(i,t,e){return i?Object.assign(Object.assign({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function _e(i){var{actions:t,errors:e,chapterId:n}=i,r=st(i,["actions","errors","chapterId"]);if(n){const s=t.getManifest(),l=t.getChapter(s.chapters,n);if(l){const o=t.getMedia(s.media,l.videoId),c=t.getGraph(s.graph,l.id);return o?Object.assign(Object.assign({},r),{actions:t,errors:e,result:{chapter:l,media:o,graph:c}}):Object.assign(Object.assign({},r),{errors:Kt(e,_e.name,"Could not find media"),actions:t})}}return Object.assign(Object.assign({},r),{errors:Kt(e,_e.name,"Could not find chapter"),actions:t})}class vi{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}removeEventListener(t,e){if(!(t in this.listeners))return;const n=this.listeners[t];for(let r=0,s=n.length;r<s;r++)if(n[r].callback===e){n.splice(r,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const n=this.listeners[t.type].slice();for(let r=0,s=n.length;r<s;r++){const l=n[r];try{l.callback.call(this,t)}catch(o){Promise.resolve().then(()=>{throw o})}l.options&&l.options.once&&this.removeEventListener(t.type,l.callback)}return!t.defaultPrevented}}class On extends vi{constructor(){super(),this.listeners||vi.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class po{constructor(){Object.defineProperty(this,"signal",{value:new On,writable:!0,configurable:!0})}abort(t){let e;try{e=new Event("abort")}catch(r){typeof document!="undefined"?document.createEvent?(e=document.createEvent("Event"),e.initEvent("abort",!1,!1)):(e=document.createEventObject(),e.type="abort"):e={type:"abort",bubbles:!1,cancelable:!1}}let n=t;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(r){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(po.prototype[Symbol.toStringTag]="AbortController",On.prototype[Symbol.toStringTag]="AbortSignal");function Tn(i){return i.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof i.Request=="function"&&!i.Request.prototype.hasOwnProperty("signal")||!i.AbortController}function yo(i){typeof i=="function"&&(i={fetch:i});const{fetch:t,Request:e=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!Tn({fetch:t,Request:e,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:t,Request:s};let s=e;(s&&!s.prototype.hasOwnProperty("signal")||r)&&(s=function(d,h){let u;h&&h.signal&&(u=h.signal,delete h.signal);const v=new e(d,h);return u&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),v},s.prototype=e.prototype);const l=t;return{fetch:(c,d)=>{const h=s&&s.prototype.isPrototypeOf(c)?c.signal:d?d.signal:void 0;if(h){let u;try{u=new DOMException("Aborted","AbortError")}catch(m){u=new Error("Aborted"),u.name="AbortError"}if(h.aborted)return Promise.reject(u);const v=new Promise((m,g)=>{h.addEventListener("abort",()=>g(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([v,l(c,d)])}return l(c,d)},Request:s}}const Me=Tn({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),jn=Me?yo({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,pi=Me?jn.fetch:window.fetch;Me?jn.Request:window.Request;const mo=i=>A(void 0,void 0,void 0,function*(){try{let t,e;if(Pe(i))t=i;else if(Ce(i)){e=new URL(i).href;const r=yield pi(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!ho(t))return{};const n=t.metadata.media;if(Ce(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);const s=yield pi(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return Co(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function bo(i){return A(this,void 0,void 0,function*(){const{manifest:t,manifestURL:e}=yield mo(i),n=ao(t);return n.media=go(n.media,e),delete n.metadata.media,n})}function pe(i,t){return i.find(e=>e.id===t)}function yi(i,t){var e,n;return!((e=i.edit)===null||e===void 0)&&e.chapters?i.edit.chapters.find(r=>r.id===t):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(r=>r.id===t):void 0}function mi(i,t){return i.videos.find(e=>e.id===t)}function go(i,t){return Object.assign(Object.assign({},i),{videos:i.videos.map(e=>Object.assign(Object.assign({},e),{variants:e.variants.map(n=>{const r=Eo(n.url,t);return Object.assign(Object.assign({},n),{url:r||n.url})})}))})}function Eo(i,t){try{return new URL(i,t).href}catch(e){return""}}function Co(i){return Qt(i,"3.2.0")>=0}const x=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ne=i=>Le(i)&&!Cn(i),te=i=>i.order==="end",_o=i=>Le(i.containers)&&!Cn(i.containers)&&te(i),Io=(i,t)=>{var e;const n=i*1e3;return Ne(t.controls)&&n<((e=t.startTime)!==null&&e!==void 0?e:0)},bi=(i,t)=>{var e,n;const r=i*1e3;return Ne(t.controls)&&r>=((e=t.startTime)!==null&&e!==void 0?e:0)&&r<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Yt=i=>i.some(t=>t.action.type==="expect"),gi=i=>i.find(t=>t.action.type==="expect"),wo=i=>(i==null?void 0:i.length)===1,$n=i=>wo(i)&&wn(i[0]),So=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(Object.assign(Object.assign({},n[t]),e[t])),Oo=(i=[])=>i.reduce((t,e,n)=>{var r,s,l;const o=((r=e==null?void 0:e.controls)!==null&&r!==void 0?r:[]).filter(c=>!wn(c));if(Ne(o)){const c=[(s=e.startTime)!==null&&s!==void 0?s:0,(l=e.endTime)!==null&&l!==void 0?l:1/0],d=e.id;if(!n)t.push({subjects:[d],range:c});else{const h=[];let u=-1/0,v=1/0,m=[];const g=[];for(let w=0;w<t.length;w++){const f=t[w];if(g.push(...f.subjects),f.range[0]<v&&(v=f.range[0]),f.range[1]>u&&(u=f.range[1]),f.range[0]<=c[0]&&f.range[1]>=c[1])return t[w].subjects.push(d),t;c[0]>=f.range[0]&&c[0]<=f.range[1]&&(h.push(w),m=m.concat(f.subjects),c[0]=f.range[0]),c[1]>=f.range[0]&&c[1]<=f.range[1]&&(h.push(w),m=m.concat(f.subjects),c[1]=f.range[1])}if(g.push(d),c[0]<=v&&c[1]>=u)return[{subjects:g,range:c}];h.length&&h.reverse().forEach(w=>{t.splice(w,1)}),t.push({subjects:m.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),To=(i,t)=>Yt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Yt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);class jo extends fo{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new H(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){var e;return A(this,void 0,void 0,function*(){this.release();const n=yield this.exec("manifestLoaders",{actions:{addErrorMessage:Kt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const r=yield bo((e=n.result)!==null&&e!==void 0?e:t);return this.manifest=r,this})}setInitial(){return A(this,void 0,void 0,function*(){return this.setNext()})}setNext(t=this.manifest.metadata.initChapterId){return A(this,void 0,void 0,function*(){this.prevChapter$.next(this.chapter);const e=yield this.exec("chapterLoaders",_e({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:yi,getChapter:pe,getMedia:mi,getByBranches:this.getByBranches.bind(this),addErrorMessage:Kt},result:null,errors:null,chapterId:t}));return e.errors&&this.errorHandler(e.errors),this.chapter=e.result.chapter,this.media=e.result.media,this.graph=e.result.graph,this})}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest.metadata.initChapterId)||null}getByChapterId(t=this.manifest.metadata.initChapterId){const e=pe(this.manifest.chapters,t);if(e){const n=mi(this.manifest.media,e.videoId),r=yi(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:r}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{const e=pe(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{const r=this.getByChapterId(n.chapterId);return r&&e.push(r),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return te(this.chapter)}}const $o=i=>{const t=i.variants.find(e=>{var n;return((n=e.payload)===null||n===void 0?void 0:n.type)==="vk"});if(t&&"payload"in t){const[e,n]=t.payload.id.split("_");return[e,n]}return[]},_={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ei={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Ro(){const i=new Map;function t(r){var{listId:s=Math.random().toString(),itemId:l=Math.random().toString()}=r,o=st(r,["listId","itemId"]);const c=i.get(s),d=Object.assign({},o);return c?c[l]=d:i.set(s,{[l]:d}),Object.assign({listId:s,itemId:l},o)}function e(r,s){var l,o,c;const d=i.get(r);if(d){if(s)return(l=d[s])===null||l===void 0||l.player.destroy(),(o=d[s])===null||o===void 0||o.container.remove(),(c=d[s])===null||c===void 0||c.subscription.unsubscribe(),delete d[s],Object.keys(d).length||i.delete(r),!0;for(const h of Object.values(d))h.player.destroy(),h.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(const r of i)e(r[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function Ci(i,t=[]){var e,n,r;let s={},l;const o=!t.length;for(const c of i.variants)if(!l&&"cover"in c&&(l=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(o||t.includes("mp4"))&&(s.MPEG=Object.assign(Object.assign({},s.MPEG),{[(e=c.standard)!==null&&e!==void 0?e:"Invariant quality"]:c.url}));break;case"mpeg":(o||t.includes("mpeg"))&&(s.MPEG=Object.assign(Object.assign({},s.MPEG),{[(n=c.standard)!==null&&n!==void 0?n:"Invariant quality"]:c.url}));break;case"hls":(o||t.includes("hls"))&&(s=Object.assign(Object.assign({},s),{HLS:{type:"url",url:c.url}}));break;case"dash":(o||t.includes("dash"))&&(s=Object.assign(Object.assign({},s),{DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}}));break}return{sources:s,thumbUrl:l,title:(r=i.title)!==null&&r!==void 0?r:""}}const Wt=(i,t)=>{const e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))},Gt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Ao=2;function xo(i){const t=Ro();let e,n;const r=new Sn;let s={},l=!1,o=null,c=!1,d;i&&h(i);function h(y){o=y}function u(y,E,b){var T;if(!o)throw Error("need to set interactive controller");const P=((T=t.map.get(y))!==null&&T!==void 0?T:{})[E];if(P){s=Object.assign({chapterId:b,listId:y,itemId:E},P);const I=s.player;n=I.info.currentQuality$.subscribe(k=>{if(!(!k||!I.info.position$.getValue())){e=k;for(const W of t.map)Object.values(W[1]).forEach(({player:N})=>{I.info.isAutoQualityEnabled$.getValue()||Wt(N,k)})}}),P.container.remove(),l=!1,o.setPlayer(P.player),c||(o.init(),c=!0),r.emit(Gt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function v(y,E,b){return A(this,void 0,void 0,function*(){if(!o)throw Error("need to set interactive controller");if(Rt(s)||y!==s.itemId)return;if(b>=0&&!l){const R=o.getChapterBranches();l=!0;const P=new Set;for(const I of R)P.has(I.media.id)||(yield g({media:I.media,chapterId:I.chapter.id,setAsActive:!1,title:I.chapter.label}),P.add(I.media.id))}})}function m({chapter:{id:y},media:E}){return A(this,void 0,void 0,function*(){if(Rt(s))return;n==null||n.unsubscribe();const b=s.player.info.muted$.getValue(),T=s.player.info.currentQuality$.getValue(),R=s.player.info.isAutoQualityEnabled$.getValue(),P=s.player.info.volume$.getValue(),I=s.player.info.currentPlaybackRate$.getValue(),k=!R;let W=!1;for(const N of t.map)if(N[0]===E.id){const K=Object.keys(N[1]);for(const X of K)X===s.itemId?(K.length<Ao||(W=!0),t.removePlayer(N[0],X)):(W=!0,u(N[0],X,y),k?Wt(s.player,T):s.player.setAutoQuality(!0),s.player.setVolume(P),s.player.setMuted(b),s.player.setPlaybackRate(I))}else t.removePlayer(N[0]);W||(yield g({media:E,chapterId:y,setAsActive:!0,playbackRate:I}),k?Wt(s.player,T):s.player.setAutoQuality(!0),s.player.setVolume(P),s.player.setMuted(b))})}function g({media:y,chapterId:E,prefetch:b=!0,setAsActive:T=!0,autoplay:R=!1,preferredExt:P,title:I,playbackRate:k}){var W,N,K;return A(this,void 0,void 0,function*(){const X=Math.random().toString(),vt=document.createElement("div");d.append(vt);const Mn=(W=s==null?void 0:s.player)===null||W===void 0?void 0:W.info.isAutoQualityEnabled$.getValue();let Mt;if(!((N=o==null?void 0:o.options)===null||N===void 0)&&N.vkVideoLoader){const Nt=$o(y);Nt.length&&(Mt=yield o.options.vkVideoLoader(...Nt))}const Ve=Object.assign(Object.assign({container:vt},((K=Mt==null?void 0:Mt.videos)===null||K===void 0?void 0:K[0])||{sources:Ci(y,P).sources}),{title:I}),ot=new Wn;ot.initVideo(Ve);const Nn=vt.lastChild,ke=new Xt;ke.add(ot.info.position$.subscribe(function(Nt){v(X,ot.info.duration$.getValue(),Nt)})).add(ot.events.canplay$.subscribe(function(){Mn||Wt(ot,e),k&&ot.setPlaybackRate(k)})),Nn&&(vt.style.display="none",vt.classList.add(E));const pt=t.createPlayer({listId:y.id,itemId:X,player:ot,container:vt,sources:Ci(y,P).sources,config:Ve,subscription:ke});return T&&u(y.id,pt.itemId,E),R&&pt.player.play(),b&&!R&&pt.player.prepare(),r.emit(Gt.playerCreated,pt.player),{player:pt.player,config:pt.config}})}function w(){f(),o=null}function f(){o==null||o.off(_.chapterChanged,m),t.removeAll(),s={},c=!1,l=!1}function p({container:y}){return A(this,void 0,void 0,function*(){if(!o)throw Error("need to set interactive controller");f(),d=y;const{media:E,chapter:b}=o.getCurrentChapter();if(E){o.on(_.chapterChanged,m);const{player:T,config:R}=yield g({media:E,chapterId:b.id,title:b.label});return r.emit(Gt.initiated,{container:y,media:E,chapterId:b.id}),{player:T,config:R}}else console.error("not found")})}return Object.assign(Object.assign({},t),{on:r.on.bind(r),off:r.off.bind(r),init:p,setInteractiveController:h,createPlayer:g,removeAll:w,getActivePlayer:function(){return s}})}const Po=3e3,Lo=()=>{let i=[],t=null;return{setPlayer:l=>{t=l},setContainers:l=>{i=l},deleteContainer:l=>{i=i.filter(o=>o.id!==l)},getNextInteractiveTime:(l=Po)=>{if(!i.length||t===null)return null;let o=-1,c=!1;const d=Math.round(t.info.position$.getValue()*1e3);for(const h of i){const u=h.startTime-l;if(u<=d&&(d<=h.endTime||h.endTime===null)){c=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!c&&o!==-1?o:null}}},wt=Lo();class Mo{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d}){this.hide=()=>{setTimeout(()=>{var h,u,v,m;this.gameState!==x.end&&(Yt(this.container.container.events)&&this.gameState===x.afterInteractive||this.selectBranches.state.isExpect||(this.gameState===x.interactive?this.disabledControls$||(u=(h=this.container).disable)===null||u===void 0||u.call(h):(m=(v=this.container).hide)===null||m===void 0||m.call(v),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var h,u,v,m,g;if(this.gameState===x.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(v=(u=this.container).show)===null||v===void 0||v.call(u),this.disabledControls$||(g=(m=this.container).enable)===null||g===void 0||g.call(m),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const f=So({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(p,y)=>{this.isSelectedControlEvent=!0,p!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===x.end||this.gameState===x.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),wt.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===x.end});this.container.createView(f),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0}),!((h=this.disabledControls$)===null||h===void 0)&&h.getValue()&&this.container.disable()}},this.onEndOfVideo=()=>{this.gameState=x.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var h,u,v,m;if(((h=this.player.experimental.element$.getValue())===null||h===void 0?void 0:h.readyState)<1||[x.destroyed,x.removed].includes(this.gameState)&&!this.isPermanentText)return;const w=this.player.getExactTime();if(Io(w,this.container.container))this.gameState!==x.beforeInteractive&&(this.gameState=x.beforeInteractive,this.onBeforeStartTime());else if(bi(w,this.container.container))this.gameState!==x.interactive&&(this.gameState=x.interactive,this.onStartTime());else if(this.gameState!==x.afterInteractive){const y=this.gameState;this.gameState=x.afterInteractive,y===x.interactive&&this.onEndTime()}else this.gameState!==x.destroyed&&this.removeView();const f=bi(w,this.container.container),p=this.container.container.startTime?[this.container.container.startTime,(u=this.container.container.endTime)!==null&&u!==void 0?u:1/0]:[];(m=(v=this.container).onProgress)===null||m===void 0||m.call(v,w,f),this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:p,currentTime:w,isInteractiveTime:f})},this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Xt,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&$n(e.container.controls),this.disabledControls$=d,this.globalEventEmitter=l,this.gameState=x.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)),this.disabledControls$&&this.subscription.add(this.disabledControls$.subscribe(t=>{var e,n,r,s;t?(n=(e=this.container).disable)===null||n===void 0||n.call(e):(s=(r=this.container).enable)===null||s===void 0||s.call(r)}))}selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);const t=Yt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)===null||e===void 0||e.call(t),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=x.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=x.removed}destroy(){var t;this.reset(),this.removeView(),this.gameState=x.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!==null&&t!==void 0?t:1/0,id:this.container.container.id}),wt.deleteContainer(this.container.container.id)}}function No(){const i={};function t(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){const c={};for(const d in i)+d<=o&&(c[d]=i[d]);return c}function n(o){const c={};for(const d in i)+d>=o&&(c[d]=i[d]);return c}function r({timestamp:o,priority:c,initiator:d}){var h;if(di(o)){const u=(h=i[o])!==null&&h!==void 0?h:null;if(u&&Dt(c,!0)){let v={};const m=u[c];if(m&&(v=Object.assign(Object.assign({},v),m)),v=Rt(v)?null:v,v&&Dt(d,!0)){const g=v[d];return g!=null?g:null}return v}return u}return null}function s({timestamp:o,priority:c,initiator:d}){if(di(o))if(i[o]){if(Dt(c,!0))if(i[o][c]){if(Dt(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!Rt(i[o][c]))return!0}else return!1;if(delete i[o][c],!Rt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(o){var c,d,h,{timestamp:u,priority:v,initiator:m}=o,g=st(o,["timestamp","priority","initiator"]);!((d=(c=i[u])===null||c===void 0?void 0:c[v])===null||d===void 0)&&d[m]?i[u][v][m].push(Object.assign({},g)):!((h=i[u])===null||h===void 0)&&h[v]?i[u][v]=Object.assign(Object.assign({},i[u][v]),{[m]:[Object.assign({},g)]}):i[u]?i[u]=Object.assign(Object.assign({},i[u]),{[v]:{[m]:[Object.assign({},g)]}}):i[u]={[v]:{[m]:[Object.assign({},g)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}const Vo=[j.expect,j.setNextBranch],ko=1/0;function _i(i){let t=i,e;const n=Fo(),r=new No;let s;const l=()=>{v(),f()},o=p=>{r.add.call(void 0,p),m()},c=(p=[])=>{for(const y of p)if(y.action(),Vo.includes(y.actionType))break},d=(p=1/0)=>{var y,E,b;const T=Ut((y=r.get({timestamp:p,priority:"control"}))!==null&&y!==void 0?y:{}),R=Ut((E=r.get({timestamp:p,priority:"container"}))!==null&&E!==void 0?E:{}),P=Ut((b=r.get({timestamp:p,priority:"chapter"}))!==null&&b!==void 0?b:{});return[...T,...R,...P]},h=p=>{n.isReady(p)&&c(d(p))},u=()=>{var p;c([...Ut((p=r.get({timestamp:1/0,priority:"chapter"}))!==null&&p!==void 0?p:{})])},v=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},m=()=>{e||(e=()=>setTimeout(()=>{h(1/0)}),s=t.events.ended$.subscribe(e))},g=p=>{v(),t=p},w=p=>{p.priority==="container"&&n.resetCalled(p.timestamp),r.remove(p)},f=()=>{n.release(),r.removeAll()};return{setPlayer:g,add:o,remove:w,exec:h,execEndOfVideo:u,listen:m,unlisten:v,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function Fo(){const i=new Map;return{setCalled:({timestamp:l,id:o})=>{const c=i.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(const d of l){const h=(o=d.endTime)!==null&&o!==void 0?o:ko,u=(c=i.get(h))!==null&&c!==void 0?c:{};i.set(h,Object.assign(Object.assign({},u),{[d.id]:!1}))}},resetCalled:l=>{const o=i.get(l);if(o)for(const c in o)o[c]=!1},isReady:l=>{const o=i.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>i.clear()}}function Ut(i){return Object.values(i).flat().sort(t=>t.actionType===j.expect?-1:1)}const Bo=(i,t)=>{const{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:r,clientWidth:s}=t.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};const l=e/n,o=r/s;let c,d;return o>l?(d=s,c=s*l):o<l?(d=r/l,c=r):(d=s,c=r),{videoContentWidth:d,videoContentHeight:c}},Do=250;function Wo(i){let t=()=>{};const e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){const{parentElement:c,player:d}=i();if(c&&d){const{videoContentWidth:h,videoContentHeight:u}=Bo(c,d);c.style.setProperty("--interactive-content-width",`${h}px`),c.style.setProperty("--interactive-content-height",`${u}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function r(){const{parentElement:o}=i();o.removeAttribute("style")}const s=gn(o=>{const{fns:c=[]}=i();n(o);for(const d of c)d()},Do);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}class Uo{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){const e=this.map[t];return e?e.slice():null}getAll(){const t=[];for(const e in this.map)t.push(...this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}size(){return Object.keys(this.map).length}keys(){return Object.keys(this.map)}}const Ho=i=>Math.floor(Math.random()*i),Go=i=>{let t=i.length,e=1/0,n=null;for(;t--;)i[t].weight<e&&(e=i[t].weight,n=i[t]);return n},zo=i=>{let t=i.length,e=-1/0,n=null;for(;t--;)i[t].weight>e&&(e=i[t].weight,n=i[t]);return n},qo=i=>{const t=i.length,e=Ho(t);return i[e]},Ii=1,Qo=i=>{var t,e;let n=0;for(let s=0;s<i.length;++s)n+=(t=i[s].weight)!==null&&t!==void 0?t:Ii;const r=Math.random()*n;n=0;for(let s=0;s<i.length-1;++s)if(n+=(e=i[s].weight)!==null&&e!==void 0?e:Ii,n>=r)return i[s];return i[i.length-1]},wi=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),ye=(i,t=!1)=>Object.assign(Object.assign({},i),{args:t?Object.assign(Object.assign({},i.args),wi):Object.assign(Object.assign({},wi),i.args)}),Si=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:p,controlId:y,containerId:E,branches:b=[],onEvent:T,isEOV:R=()=>!1,isDisabled:P=()=>!1})=>{const I=ye(f,R()),k={timestamp:1/0,priority:"control",initiator:y,actionType:I.type},W=P(),N=i.emit.bind(i,_.interactives,{subjectId:y,subjectType:p,subjectName:"control",type:W?L.actionChoiceCanceled:L.actionChoice,actionType:f.type,payload:Object.assign({containerId:E},I.args)});if(W){N();return}switch(I.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const K=b.find(X=>X.id===I.args.branchId);if(!K)return;T(I.args.isDetachContainer,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?g({subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{chapterId:K.chapterId,autoSelect:!1}}):(e.add(Object.assign(Object.assign({},k),{action:g.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{chapterId:K.chapterId,autoSelect:!1}})})),n==null||n());return}case j.continuePlayback.trim().toLowerCase():{T(I.args.isDetachContainer,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?m({subjectId:y,subjectName:"control",subjectType:p,action:f}):e.add(Object.assign(Object.assign({},k),{action:m.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:f})}));return}case j.openURI.trim().toLowerCase():{T(I.args.isDetachContainer,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?w({subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{URI:f.args.uri}}):(e.add(Object.assign(Object.assign({},k),{action:w.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:p,endTime:y},branches:E=[],isEOV:b=!1,autoSelected:T=!1})=>{const R=ye(f,b),P={timestamp:!R.args.shouldOpenNow||b?1/0:y,priority:"container",initiator:p,actionType:R.type},I=i.emit.bind(i,_.interactives,{subjectId:p,subjectName:"container",type:L.actionChoice,actionType:R.type,payload:R.args});switch(R.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const k=E.find(W=>W.id===R.args.branchId);if(!k)return;I(),e.add(Object.assign(Object.assign({},P),{action:g.bind(null,{subjectId:p,subjectName:"container",action:R,payload:{chapterId:k.chapterId,autoSelect:T}})})),n==null||n();return}case j.setMaxWeightBranch.trim().toLowerCase():return;case j.setMinWeightBranch.trim().toLowerCase():return;case j.setRandomBranch.trim().toLowerCase():return;case j.setWeightlessRandomBranch.trim().toLowerCase():return;case j.continuePlayback.trim().toLowerCase():{I(),e.add(Object.assign(Object.assign({},P),{action:m.bind(null,{subjectId:p,subjectName:"container",action:R})}));return}case j.openURI.trim().toLowerCase():{I(),e.add(Object.assign(Object.assign({},P),{action:w.bind(null,{subjectId:p,subjectName:"container",action:R,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:f,branches:p,isEOV:y=!1}){const E=gi(f.events);if(E){const b=ye(E.action,y);i.emit(_.interactives,{subjectId:f.id,subjectName:"container",type:L.actionChoice,actionType:b.type,payload:b.args}),e.add({timestamp:y?1/0:f.endTime,priority:"container",initiator:f.id,actionType:j.expect,action:u.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(const b of f.events)o({action:b.action,container:f,branches:p,isEOV:y})}const d=({chapterId:f,action:p,branches:y=[]})=>{const E=i.emit.bind(i,_.interactives,{subjectId:f,subjectName:"chapter",type:L.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const b=y.find(T=>T.id===p.args.branchId);return b!=null&&b.chapterId?(E(),g.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case j.setWeightlessRandomBranch.trim().toLowerCase():{const b=qo(y);return b!=null&&b.chapterId?(E(),g.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case j.setRandomBranch.trim().toLowerCase():{const b=Qo(y);return b!=null&&b.chapterId?(E(),g.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case j.setMaxWeightBranch.trim().toLowerCase():{const b=zo(y);return b!=null&&b.chapterId?(E(),g.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case j.setMinWeightBranch.trim().toLowerCase():{const b=Go(y);return b!=null&&b.chapterId?(E(),g.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case j.continuePlayback.trim().toLowerCase():return E(),m.bind(null,{subjectId:f,subjectName:"chapter",action:p});case j.openURI.trim().toLowerCase():return E(),w.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function h(f){const p=gi(f.events);if(p){if(te(f))return;i.emit(_.interactives,{subjectId:f.id,subjectName:"chapter",type:L.actionChoice,actionType:p.action.type,payload:p.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:j.expect,action:u.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(y=>{const E=d({chapterId:f.id,action:y.action,branches:f.branches});E&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:y.action.type,action:E})})}const u=({subjectId:f,subjectName:p,action:y})=>{var E;t.pause(),i.emit(_.interactives,{subjectId:f,subjectName:p,type:L.actionExecution,actionType:(E=y==null?void 0:y.type)!==null&&E!==void 0?E:j.expect})},v=({subjectId:f,subjectName:p})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(_.interactives,{subjectId:f,subjectName:p,type:L.actionExecution,actionType:"after-expect"})},m=({subjectId:f,subjectName:p,subjectType:y,action:E})=>{i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type})},g=({subjectId:f,subjectName:p,subjectType:y,action:E,payload:b})=>{b.behaviour="change-chapter",i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type,payload:b})},w=({subjectId:f,subjectName:p,subjectType:y,action:E,payload:b})=>{if(!b.URI)return;const T=window.open(b.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:v,setManifestChapterEvents:h,setManifestContainerEvents:c,stopExpect:s,state:r}},Oi=(i,t)=>{const e={};return i.map(n=>{if(!e[n]){const r=t.chapters.find(l=>l.id===n);if(!r)return null;const s=t.media.videos.find(l=>r.videoId===l.id);if(!s)return null;e[n]=Rn(s)}return e[n]}).filter(Boolean)},Ko=i=>{for(const t of i.variants)if(Yo(t)&&"payload"in t)return t.payload.id},Yo=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Rn=i=>{const t=Ko(i);if(!t)return null;const e=t.split("_").pop();return e?parseInt(e,10):null},Xo=(i,t)=>{for(const e of i.media.videos)if(t===Rn(e)){for(const n of i.chapters)if(n.videoId===e.id)return n.id;return}},Zo=(i,t)=>i.reduce((e,n)=>{const r=Xo(t,n);return r?[...e,r]:e},[]);var et,bt,G,Ie,it,gt,Z,Et;class Jo{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r}){var s,l,o;this.state={history$:new H([]),hasPrevChapter$:new H(!1),prevChapter$:new H(null),isInitialChapter$:new H(!1)},et.set(this,null),bt.set(this,!1),G.set(this,null),Ie.set(this,null),it.set(this,null),gt.set(this,null),Z.set(this,null),Et.set(this,new Xt),C(this,it,e,"f"),C(this,Z,t,"f"),C(this,gt,n,"f"),C(this,et,r,"f"),!((s=this.state)===null||s===void 0)&&s.history$&&a(this,Et,"f")&&((l=a(this,Et,"f"))===null||l===void 0||l.add((o=this.state)===null||o===void 0?void 0:o.history$.subscribe(c=>{var d,h,u,v,m;(d=this.state)===null||d===void 0||d.prevChapter$.next(Ee(c,-2)||null),(h=this.state)===null||h===void 0||h.hasPrevChapter$.next(c.length>1),(u=this.state)===null||u===void 0||u.isInitialChapter$.next(this.getInitialChapterId()===((m=(v=a(this,G,"f"))===null||v===void 0?void 0:v.metadata)===null||m===void 0?void 0:m.initChapterId))})))}setManifest(t){return A(this,void 0,void 0,function*(){!a(this,gt,"f")||!a(this,Z,"f")||(C(this,G,t,"f"),yield this.getProjectHistory(),yield a(this,gt,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,bt,"f")||(C(this,bt,!0,"f"),a(this,Z,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,bt,"f")}updateHistory(t,e=!0){var n,r;return A(this,void 0,void 0,function*(){if(!a(this,G,"f")||!a(this,it,"f"))return;const s=a(this,G,"f"),l=Oi(t,s);if(C(this,Ie,l,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(t),!(!e||!a(this,et,"f")))try{yield a(this,et,"f").save(a(this,it,"f"),l)}catch(o){(r=a(this,Z,"f"))===null||r===void 0||r.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}})}getProjectHistory(){var t,e;return A(this,void 0,void 0,function*(){if(!a(this,G,"f")||!a(this,it,"f"))return;const n=a(this,G,"f");let r=[this.getInitialVideoId()];if(a(this,et,"f"))try{const l=yield a(this,et,"f").get(a(this,it,"f"));l.length&&(r=l)}catch(l){(t=a(this,Z,"f"))===null||t===void 0||t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}const s=Zo(r,n);(e=this===null||this===void 0?void 0:this.state)===null||e===void 0||e.history$.next(s)})}getInitialChapterId(){var t,e;const n=(t=this.state)===null||t===void 0?void 0:t.history$.getValue();return Ee(n,-1)||((e=a(this,G,"f"))===null||e===void 0?void 0:e.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return Oi([t],a(this,G,"f")).pop()}return null}destroy(){var t,e;this.state=null,C(this,it,null,"f"),C(this,et,null,"f"),C(this,gt,null,"f"),(t=a(this,Et,"f"))===null||t===void 0||t.unsubscribe(),C(this,Et,null,"f"),C(this,bt,!1,"f"),(e=a(this,Z,"f"))===null||e===void 0||e.emit(_.historyDestroyed),C(this,Z,null,"f")}}et=new WeakMap,bt=new WeakMap,G=new WeakMap,Ie=new WeakMap,it=new WeakMap,gt=new WeakMap,Z=new WeakMap,Et=new WeakMap;var Tt,An,we,Ti;class J{constructor(t,e,n,r){this.target=t,this.type=e,this.listener=n,this.options=a(J,Tt,"m",An).call(J,t,r),this.target.addEventListener(e,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}Tt=J,An=function(t,e){if(e===void 0)return!1;if(typeof e=="boolean")return e;{const n=new Set(["passive","capture"]),r=Object.keys(e).filter(l=>!n.has(l));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),a(J,Tt,"m",Ti).call(J,t)?e:e.capture||!1}},Ti=function(t){let e=a(J,Tt,"f",we);if(e===void 0){e=!1;try{const n={},r={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);const s=()=>{};t.addEventListener("test",s,n),t.removeEventListener("test",s,n)}catch(n){e=!1}C(J,Tt,e,"f",we)}return e||!1};we={value:void 0};class tl{constructor(){this.bindingMap=new Uo}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;const s=new J(t,e,n,r);this.bindingMap.push(e,s)}listenOnce(t,e,n,r){const s=l=>{this.unlisten(t,e,s),n(l)};this.listen(t,e,s,r)}unlisten(t,e,n){if(!this.bindingMap)return;const r=this.bindingMap.get(e)||[];for(const s of r)s.target===t&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(e,s))}removeAll(){if(!this.bindingMap)return;const t=this.bindingMap.getAll();for(const e of t)e.unlisten();this.bindingMap.clear()}}class el{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const e=(t=this.rootElement.getContext("2d"))===null||t===void 0?void 0:t.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;const n=e.data,r=n.length;for(let s=3;s<r;s+=40)if(n[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){var t;this.canvasImgSrc&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}updateCanvasDimensions(t,e=!1){return A(this,void 0,void 0,function*(){const n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=yield this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n})}save(){return A(this,void 0,void 0,function*(){const t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,yield e.decode(),e})}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))===null||e===void 0||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}}class il{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=r=>{const s=r!=null?r:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,l=this.isChapterEndTime(s);if(this.isContainerTime(s))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(l)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
7
7
|
position: absolute;
|
|
8
8
|
top: 0;
|
|
9
9
|
left: 0;
|
|
@@ -11,13 +11,13 @@ import{loadVKLangPack as Rs,ValueSubject as H,Subscription as we,Observable as G
|
|
|
11
11
|
height: var(--interactive-height);
|
|
12
12
|
background-color: var(--black);
|
|
13
13
|
visibility: hidden;
|
|
14
|
-
`,this.lastFrameCanvas=new
|
|
14
|
+
`,this.lastFrameCanvas=new el,this.endOffsetMs=e,this._callbacks={onError:n},this.lastFrameCanvas.rootElement.style.cssText=`
|
|
15
15
|
position: absolute;
|
|
16
16
|
top: 50%;
|
|
17
17
|
left: 50%;
|
|
18
18
|
transform: translate(-50%, -50%);
|
|
19
|
-
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}updateCanvasDimensions(t=!1){return A(this,void 0,void 0,function*(){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);const
|
|
19
|
+
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}updateCanvasDimensions(t=!1){return A(this,void 0,void 0,function*(){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);const e=getComputedStyle(this.rootElement),n={width:parseInt(e.getPropertyValue("--interactive-content-width"),10),height:parseInt(e.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,t)}catch(r){this._onError(r)}})}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(t){return this.currentVideoDurationMs&&t>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(t){if(this.currentChapter)return this.currentChapter.containers.some(e=>{var n,r,s;return((n=e.controls)===null||n===void 0?void 0:n.length)&&t>=((r=e.startTime)!==null&&r!==void 0?r:0)&&t<=Math.min((s=e.endTime)!==null&&s!==void 0?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(t){var e,n;(n=(e=this._callbacks)===null||e===void 0?void 0:e.onError)===null||n===void 0||n.call(e,t)}}function nl(i=0){return new Promise(t=>{setTimeout(()=>{t(0)},i)})}var M,lt,q,ct,D,rt,B,U,nt,$,ht,At,F,jt,V,O,xn,ji,zt,Pn,Se,$i,Oe,It,$t,Ri,Te,Ai,Ln;const rl=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0,disableControlsOnPause:!0}),tt=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function sl(){const i=document.createElement("div");return i.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,e}class ku{constructor(t){M.add(this),yt.set(this,null),K.set(this,null),mt.set(this,null),G.set(this,null),ut.set(this,null),B.set(this,null),W.set(this,null),ht.set(this,null),$.set(this,null),Et.set(this,new H(!1)),Ut.set(this,new Set),V.set(this,null),Gt.set(this,null),k.set(this,null),O.set(this,null),this.state={prevChapter$:new H(null),isInitialChapter$:new H(!1),isEndChapter$:new H(!1),calledByInteractive$:new H(!1),lastChapterChangeWasInitiatedByInteractive$:new H(!1),disabledControls$:new H(!1)},this.emitPlayerChanged=i=>{a(this,O,"f").emit(I.playerChanged,i)},Ss.set(this,()=>{a(this,W,"f").fns.forEach(n=>n());const i=this.options.player.info.position$.getValue()*1e3,r=(a(this,$,"f").chapter.containers||[]).filter(n=>n.startTime>=Math.floor(i));for(const n of r){a(this,B,"f").remove({timestamp:1/0,priority:"container",initiator:n.id});for(const s of n.controls)a(this,B,"f").remove({timestamp:1/0,priority:"control",initiator:s.id});a(this,K,"f").find(s=>s.container.container.id===n.id).reset()}}),fi.set(this,()=>{a(this,yt,"f").calc(),a(this,W,"f").requestAnimation()}),At.set(this,(i=!0)=>{a(this,K,"f").forEach(r=>{!i&&r.isPermanentText||(a(this,W,"f").removeFn(r.whilePlaying),r.destroy())})}),this.options=Object.assign(Object.assign({},Pu),t),E(this,K,[],"f"),this.factories=new Map([["choice",gn]]),this.rootElement=xu(),this.options.parentElement.append(this.rootElement),E(this,O,new Zn,"f"),E(this,ut,new we,"f"),E(this,mt,new $u,"f"),E(this,G,new Tu({interactiveController:this,globalEventEmitter:a(this,O,"f"),videoId:this.options.projectInfo.videoId,apiController:this.options.apiController,localStorageController:this.options.localStorageController,historySettings:this.options.historySettings}),"f"),this.options.lastFrame&&E(this,k,new Ru({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:i=>a(this,O,"f").emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.SEAMLESS,i))}),"f"),a(this,mt,"f").listen(this.rootElement,"mousedown",i=>i.stopPropagation()),a(this,mt,"f").listen(this.rootElement,"mouseup",i=>i.stopPropagation()),E(this,$,new sc(this.options.loaders,i=>a(this,O,"f").emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.MANIFEST,i))),"f"),E(this,B,Or(this.options.player),"f"),E(this,W,new Wl,"f"),E(this,ht,$r({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,O,"f"),removeControllers:a(this,At,"f")}),"f"),E(this,yt,bc(()=>{var i;return{player:(i=this.options)===null||i===void 0?void 0:i.player,parentElement:this.options.parentElement,fns:this.options.lastFrame?[()=>{a(this,k,"f").updateCanvasDimensions(!0)}]:[]}}),"f"),this.options.graph&&E(this,V,new Tl({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:i=>{this.setChapter({chapterId:i}),a(this,O,"f").emit(I.graph,{type:Ir.watchAgainClicked,chapterId:i})},onError:i=>a(this,O,"f").emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.LOADERS,{message:i}))}),"f"),a(this,M,"m",Os).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=at.created}getStatEvents(){return{click$:new Gi(t=>{a(this,O,"f").on(I.graph,({type:i,visibility:r})=>{i==="visibility"&&t.next(r?gt.OPEN_GRAPH:gt.CLOSE_GRAPH),i==="watchAgainClicked"&&t.next(gt.WATCH_AGAIN)}),a(this,O,"f").on(I.interactives,({type:i,subjectName:r,subjectType:n})=>{i!=="action-choice"||r!=="control"||(n==="Button"&&t.next(gt.GO_NEXT_BUTTON),n==="Area"&&t.next(gt.GO_NEXT_AREA))})}),nextMovie$:new Gi(t=>{a(this,O,"f").on(I.playerChanged,({config:i})=>{i!=null&&i.unitedVideoId&&t.next(i.unitedVideoId)})})}}setPlayer(t){a(this,M,"m",pe).call(this),this.options.player=t,Lt.setPlayer(this.options.player),a(this,B,"f")?a(this,B,"f").setPlayer(this.options.player):E(this,B,Or(this.options.player),"f"),E(this,ht,$r({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,O,"f"),removeControllers:()=>a(this,At,"f").call(this,!1)}),"f"),this.appState===at.initiated&&(a(this,M,"m",vi).call(this),a(this,M,"m",Wt).call(this,a(this,$,"f").chapter))}setManifest(t){return A(this,void 0,void 0,function*(){a(this,M,"m",pe).call(this),this.isFirstChapterFetched=!1;const i=yield a(this,$,"f").setManifest(t);return a(this,V,"f")&&(yield a(this,V,"f").handleManifestChange(i.manifest)),a(this,O,"f").emit(I.manifestChanged,{manifest:i.manifest}),a(this,M,"m",Wt).call(this,a(this,$,"f").chapter),i.manifest})}setVisitedChapters(t){var i;Array.isArray(t)&&((i=a(this,V,"f"))===null||i===void 0||i.setVisitedChapters(t))}updateGraphVideosInfo(t){var i;Array.isArray(t)&&((i=a(this,V,"f"))===null||i===void 0||i.updateVideosInfo(t))}setChapter({chapterId:t,pushToHistory:i=!0}={}){var r;return A(this,void 0,void 0,function*(){a(this,M,"m",pe).call(this),a(this,k,"f")&&this.isFirstChapterFetched&&(a(this,k,"f").draw(),a(this,k,"f").show()),As().browser===Ps.Safari&&(yield Au(35));const s=yield t?a(this,$,"f").setNext(t):a(this,$,"f").setInitial(),{chapter:l,media:o,graph:c}=s;return i&&a(this,M,"m",Ts).call(this,l.id),this.state.isInitialChapter$.next(a(this,$,"f").isInitialChapter()),this.state.isEndChapter$.next(a(this,$,"f").isEndChapter()),a(this,V,"f")&&a(this,V,"f").handleChapterChange(c),(r=a(this,k,"f"))===null||r===void 0||r.setCurrentChapter(this.getCurrentChapter().chapter),a(this,O,"f").emit(I.chapterChanged,{chapter:l,media:o,graph:c}),a(this,M,"m",Wt).call(this,a(this,$,"f").chapter),E(this,Ut,new Set,"f"),this.isFirstChapterFetched=!0,{chapter:l,media:o,graph:c}})}toggleGraphView(t=!0){a(this,V,"f")&&(t?(a(this,V,"f").show(),a(this,Et,"f").next(!1)):(a(this,V,"f").hide(),a(this,M,"m",pi).call(this)),a(this,O,"f").emit(I.graph,{type:Ir.visibility,visibility:t}))}init(){a(this,$,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===at.created&&(a(this,yt,"f").resizeObserver.observe(this.options.fullscreenTargetElement),a(this,M,"m",vi).call(this),this.appState=at.initiated,a(this,M,"m",Wt).call(this,a(this,$,"f").chapter))}deadEndCheck(){var t,i;return!((i=(t=a(this,B,"f"))===null||t===void 0?void 0:t.getPreparedToExecActions())!==null&&i!==void 0?i:[]).some(s=>s.actionType===T.setNextBranch)}allControlsAreRemoved(){return!a(this,K,"f").some(i=>!i.container.isRemoved)}playPrevChapter(){const t=[...a(this,G,"f").state.history$.getValue()];if(t.length>1){t.pop();const i=ii(t,-1);a(this,G,"f").updateHistory(t),this.setChapter({chapterId:i})}}setDisabledControls(t){this.options.disableControlsOnPause?a(this,O,"f").emit(I.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,"To disable controls set disableControlsOnPause option to false")):this.state.disabledControls$.next(t)}isSupport(t=a(this,$,"f").manifest){return Qn(t.metadata.version)}getHistoryState(){return a(this,G,"f").state}getIsSeekable(){return a(this,Et,"f")}getInteractiveRanges(){var t;return rc((t=a(this,$,"f").chapter)===null||t===void 0?void 0:t.containers)}getNextInteractiveStartTime(t){return Lt.getNextInteractiveTime(t)}getChapterBranches(t){return a(this,$,"f").getBranches(t)}getCurrentChapter(){return a(this,$,"f").getCurrent()}getCurrentManifest(){return a(this,$,"f").manifest}addFactory(t,i){this.factories.set(t.trim().toLowerCase(),i)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,O,"f").on(...t),this}off(...t){return a(this,O,"f").off(...t),this}once(...t){return a(this,O,"f").once(...t),this}destroy(){var t,i;a(this,At,"f").call(this),E(this,K,void 0,"f"),this.state=void 0,(t=a(this,V,"f"))===null||t===void 0||t.destroy(),E(this,V,void 0,"f"),a(this,yt,"f").release(),E(this,yt,void 0,"f"),E(this,ht,void 0,"f"),a(this,W,"f").release(),E(this,W,void 0,"f"),a(this,B,"f").release(),E(this,B,void 0,"f"),a(this,$,"f").release(),E(this,ht,void 0,"f"),a(this,mt,"f").release(),E(this,mt,void 0,"f"),a(this,ut,"f").unsubscribe(),E(this,ut,void 0,"f"),a(this,O,"f").reset(),E(this,O,void 0,"f"),(i=a(this,k,"f"))===null||i===void 0||i.destroy(),E(this,k,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,a(this,G,"f").destroy(),E(this,G,void 0,"f"),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=at.destroyed}}yt=new WeakMap,K=new WeakMap,mt=new WeakMap,G=new WeakMap,ut=new WeakMap,B=new WeakMap,W=new WeakMap,ht=new WeakMap,$=new WeakMap,Et=new WeakMap,Ut=new WeakMap,V=new WeakMap,Gt=new WeakMap,k=new WeakMap,O=new WeakMap,Ss=new WeakMap,fi=new WeakMap,At=new WeakMap,M=new WeakSet,Os=function(t=!1){a(this,O,"f").on(I.historyInited,({initChapterId:i,videosInfo:r=[]})=>A(this,void 0,void 0,function*(){t&&(yield a(this,M,"m",nn).call(this,{initialChapter:i,videosInfo:r}))})),a(this,O,"f").on(I.interactives,i=>A(this,void 0,void 0,function*(){var r,n;if(i.type===L.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((r=i.payload)===null||r===void 0?void 0:r.behaviour)==="change-chapter"){const{chapterId:s}=i.payload;this.setChapter({chapterId:s})}if(((n=i.payload)===null||n===void 0?void 0:n.behaviour)==="change-manifest"){const{manifestURL:s}=i.payload;this.setManifest(s)}}})),a(this,O,"f").on(I.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},nn=function({source:t,videosInfo:i=[]}){return A(this,void 0,void 0,function*(){E(this,Gt,cc(this),"f");const r=document.createElement("div");a(this,Gt,"f").on(he.activePlayerChanged,this.emitPlayerChanged);const{player:n,config:s}=yield a(this,Gt,"f").init({source:t,initialChapter:a(this,G,"f").getInitialChapter(),container:r});return this.updateGraphVideosInfo(i),{player:n,config:s}})},pe=function(){var t;this.appState===at.ready&&(a(this,At,"f").call(this),E(this,K,[],"f"),a(this,W,"f").release(),(t=a(this,B,"f"))===null||t===void 0||t.release(),this.appState=at.initiated,a(this,Et,"f").next(!1))},sn=function(t){(!a(this,V,"f")||a(this,V,"f").isHidden)&&a(this,M,"m",pi).call(this);const i=t*1e3,n=this.getInteractiveRanges().findLast(({range:s})=>i>=s[1]);if(n){const s=n.range.join("-");a(this,Ut,"f").has(s)||(a(this,Ut,"f").add(s),a(this,O,"f").emit(I.interactives,{type:L.rangeEnded,payload:n,visibility:!0}))}},vi=function(){a(this,ut,"f").unsubscribe(),a(this,ut,"f").add(this.options.player.events.started$.pipe(xs()).subscribe(a(this,fi,"f"))).add(this.options.player.events.playing$.subscribe(a(this,W,"f").requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,W,"f").cancelAnimation)).add(this.options.player.info.position$.subscribe(a(this,M,"m",sn).bind(this))).add(a(this,$,"f").prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))),this.options.lastFrame&&a(this,ut,"f").add(this.options.player.info.duration$.subscribe(t=>{a(this,k,"f").setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,k,"f").setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,k,"f").reset(),setTimeout(()=>{a(this,k,"f").hide(),a(this,k,"f").lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,k,"f").onSeek))},Wt=function(t){a(this,$,"f").chapter&&this.appState===at.initiated&&(a(this,ht,"f").setManifestChapterEvents(t),E(this,K,a(this,M,"m",an).call(this,t),"f"),a(this,B,"f").containersEventsCallState.setData(t.containers),Lt.setContainers(a(this,K,"f").map(i=>i.container.container).filter(i=>!is(i.controls))),this.options.lastFrame&&a(this,W,"f").addFn(()=>{a(this,k,"f").onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.appState=at.ready)},an=function(t){var i,r;return(r=(i=t==null?void 0:t.containers)===null||i===void 0?void 0:i.reduce((n,s)=>{const l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){const c=new uc({player:this.options.player,container:o(s,this.rootElement),branches:a(this,$,"f").chapter.branches,selectBranches:a(this,ht,"f"),interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,O,"f"),ignoreContainerEvent:()=>nc(s,a(this,K,"f")),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.options.disableControlsOnPause?void 0:this.state.disabledControls$});return a(this,W,"f").addFn(c.whilePlaying,!0),[...n,c]}return[...n]},[]))!==null&&r!==void 0?r:[]},pi=function(){const t=a(this,Et,"f").getValue(),i=!!Lt.getNextInteractiveTime();(i&&!t||!i&&t)&&a(this,Et,"f").next(!t)},on=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Ts=function(t){var i;if(a(this,M,"m",on).call(this),!a(this,G,"f").inited)return;const r=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),s=(i=n&&Te(n)&&Jl(n))!==null&&i!==void 0?i:!1,l=a(this,$,"f").manifest.metadata.initChapterId===t,o=a(this,G,"f").state.history$.getValue();if(l||s&&r){a(this,G,"f").updateHistory([t]);return}o.at(-1)!==t&&a(this,G,"f").updateHistory([...o,t])};const Fu={Container:mn,createChoiceContainer:gn,createAreaControl:vn,createButtonControl:pn,createRelativeLayout:Hs,getRootEl:cn,classnamesPrefix:q},Vu={version:Ns};export{R as CustomError,I as EVENT_NAMES,gt as INTERACTIVE_CLICK_ACTIONS,ku as Interactives,sc as ManifestController,Vu as SDKInfo,me as compareVersions,Ir as graphEventTypes,Jl as hasEndTemplate,L as interactivesEventTypes,Te as isLastChapter,Qn as isSupportedManifest,Fu as utils};
|
|
23
|
+
`,i}class cl{constructor(t){M.add(this),lt.set(this,null),q.set(this,null),ct.set(this,null),D.set(this,null),rt.set(this,null),B.set(this,null),U.set(this,null),nt.set(this,null),$.set(this,null),ht.set(this,new H(!1)),At.set(this,new Set),F.set(this,null),jt.set(this,null),V.set(this,null),O.set(this,null),this.state={prevChapter$:new H(null),isInitialChapter$:new H(!1),isEndChapter$:new H(!1),calledByInteractive$:new H(!1),lastChapterChangeWasInitiatedByInteractive$:new H(!1),disabledControls$:new H(!1)},this.emitPlayerChanged=e=>{a(this,O,"f").emit(_.playerChanged,e)},Pn.set(this,()=>{a(this,U,"f").fns.forEach(r=>r());const e=this.options.player.info.position$.getValue()*1e3,n=(a(this,$,"f").chapter.containers||[]).filter(r=>r.startTime>=Math.floor(e));for(const r of n){a(this,B,"f").remove({timestamp:1/0,priority:"container",initiator:r.id});for(const s of r.controls)a(this,B,"f").remove({timestamp:1/0,priority:"control",initiator:s.id});a(this,q,"f").find(s=>s.container.container.id===r.id).reset()}}),Se.set(this,()=>{a(this,lt,"f").calc(),a(this,U,"f").requestAnimation()}),It.set(this,(e=!0)=>{a(this,q,"f").forEach(n=>{!e&&n.isPermanentText||(a(this,U,"f").removeFn(n.whilePlaying),n.destroy())})}),this.options=Object.assign(Object.assign({},rl),t),C(this,q,[],"f"),this.factories=new Map([["choice",Wi]]),this.rootElement=sl(),this.options.parentElement.append(this.rootElement),C(this,O,new Sn,"f"),C(this,rt,new Xt,"f"),C(this,ct,new tl,"f"),C(this,D,new Jo({interactiveController:this,globalEventEmitter:a(this,O,"f"),videoId:this.options.projectInfo.videoId,historyApi:this.options.historyApi}),"f"),this.options.lastFrame&&C(this,V,new il({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:e=>a(this,O,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.SEAMLESS,e))}),"f"),a(this,ct,"f").listen(this.rootElement,"mousedown",e=>e.stopPropagation()),a(this,ct,"f").listen(this.rootElement,"mouseup",e=>e.stopPropagation()),C(this,$,new jo(this.options.loaders,e=>a(this,O,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.MANIFEST,e))),"f"),C(this,B,_i(this.options.player),"f"),C(this,U,new uo,"f"),C(this,nt,Si({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,O,"f"),removeControllers:a(this,It,"f")}),"f"),C(this,lt,Wo(()=>{var e;return{player:(e=this.options)===null||e===void 0?void 0:e.player,parentElement:this.options.parentElement,fns:this.options.lastFrame?[()=>{a(this,V,"f").updateCanvasDimensions(!0)}]:[]}}),"f"),this.options.graph&&C(this,F,new Ka({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:e=>{this.setChapter({chapterId:e}),a(this,O,"f").emit(_.graph,{type:Ei.watchAgainClicked,chapterId:e})},onError:e=>a(this,O,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.LOADERS,{message:e}))}),"f"),a(this,M,"m",xn).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=tt.created}getStatEvents(){return{click$:new Fe(t=>{a(this,O,"f").on(_.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?dt.OPEN_GRAPH:dt.CLOSE_GRAPH),e==="watchAgainClicked"&&t.next(dt.WATCH_AGAIN)}),a(this,O,"f").on(_.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next(dt.GO_NEXT_BUTTON),r==="Area"&&t.next(dt.GO_NEXT_AREA))})}),nextMovie$:new Fe(t=>{a(this,O,"f").on(_.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){a(this,M,"m",zt).call(this),this.options.player=t,wt.setPlayer(this.options.player),a(this,B,"f")?a(this,B,"f").setPlayer(this.options.player):C(this,B,_i(this.options.player),"f"),C(this,nt,Si({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,O,"f"),removeControllers:()=>a(this,It,"f").call(this,!1)}),"f"),this.appState===tt.initiated&&(a(this,M,"m",Oe).call(this),a(this,M,"m",$t).call(this,a(this,$,"f").chapter))}setManifest(t){return A(this,void 0,void 0,function*(){a(this,M,"m",zt).call(this),this.isFirstChapterFetched=!1;const e=yield a(this,$,"f").setManifest(t);return a(this,F,"f")&&(yield a(this,F,"f").handleManifestChange(e.manifest)),yield a(this,D,"f").setManifest(e.manifest),a(this,O,"f").emit(_.manifestChanged,{manifest:e.manifest}),a(this,M,"m",$t).call(this,a(this,$,"f").chapter),e.manifest})}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,F,"f"))===null||e===void 0||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,F,"f"))===null||e===void 0||e.updateVideosInfo(t))}setChapter({chapterId:t,pushToHistory:e=!0}={}){var n;return A(this,void 0,void 0,function*(){a(this,M,"m",zt).call(this),a(this,V,"f")&&this.isFirstChapterFetched&&(a(this,V,"f").draw(),a(this,V,"f").show()),kn().browser===Fn.Safari&&(yield nl(35));const s=yield t?a(this,$,"f").setNext(t):a(this,$,"f").setInitial(),{chapter:l,media:o,graph:c}=s;return e&&a(this,M,"m",Ln).call(this,l.id),this.state.isInitialChapter$.next(a(this,$,"f").isInitialChapter()),this.state.isEndChapter$.next(a(this,$,"f").isEndChapter()),a(this,F,"f")&&a(this,F,"f").handleChapterChange(c),(n=a(this,V,"f"))===null||n===void 0||n.setCurrentChapter(this.getCurrentChapter().chapter),a(this,O,"f").emit(_.chapterChanged,{chapter:l,media:o,graph:c}),a(this,M,"m",$t).call(this,a(this,$,"f").chapter),C(this,At,new Set,"f"),this.isFirstChapterFetched=!0,{chapter:l,media:o,graph:c}})}toggleGraphView(t=!0){a(this,F,"f")&&(t?(a(this,F,"f").show(),a(this,ht,"f").next(!1)):(a(this,F,"f").hide(),a(this,M,"m",Te).call(this)),a(this,O,"f").emit(_.graph,{type:Ei.visibility,visibility:t}))}init(){a(this,$,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===tt.created&&(a(this,lt,"f").resizeObserver.observe(this.options.fullscreenTargetElement),a(this,M,"m",Oe).call(this),this.appState=tt.initiated,a(this,M,"m",$t).call(this,a(this,$,"f").chapter))}deadEndCheck(){var t,e;return!((e=(t=a(this,B,"f"))===null||t===void 0?void 0:t.getPreparedToExecActions())!==null&&e!==void 0?e:[]).some(s=>s.actionType===j.setNextBranch)}allControlsAreRemoved(){return!a(this,q,"f").some(e=>!e.container.isRemoved)}playPrevChapter(){const t=[...a(this,D,"f").state.history$.getValue()];if(t.length>1){t.pop();const e=Ee(t,-1);a(this,D,"f").updateHistory(t),this.setChapter({chapterId:e})}}setDisabledControls(t){this.options.disableControlsOnPause?a(this,O,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,"To disable controls set disableControlsOnPause option to false")):this.state.disabledControls$.next(t)}isSupport(t=a(this,$,"f").manifest){return In(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,D,"f").getInitialVideoId(),chapterId:a(this,D,"f").getInitialChapterId()}}getHistoryState(){return a(this,D,"f").state}getIsSeekable(){return a(this,ht,"f")}getInteractiveRanges(){var t;return Oo((t=a(this,$,"f").chapter)===null||t===void 0?void 0:t.containers)}getNextInteractiveStartTime(t){return wt.getNextInteractiveTime(t)}getChapterBranches(t){return a(this,$,"f").getBranches(t)}getCurrentChapter(){return a(this,$,"f").getCurrent()}getCurrentManifest(){return a(this,$,"f").manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,O,"f").on(...t),this}off(...t){return a(this,O,"f").off(...t),this}once(...t){return a(this,O,"f").once(...t),this}destroy(){var t,e;a(this,It,"f").call(this),C(this,q,void 0,"f"),this.state=void 0,(t=a(this,F,"f"))===null||t===void 0||t.destroy(),C(this,F,void 0,"f"),a(this,lt,"f").release(),C(this,lt,void 0,"f"),C(this,nt,void 0,"f"),a(this,U,"f").release(),C(this,U,void 0,"f"),a(this,B,"f").release(),C(this,B,void 0,"f"),a(this,$,"f").release(),C(this,nt,void 0,"f"),a(this,ct,"f").release(),C(this,ct,void 0,"f"),a(this,rt,"f").unsubscribe(),C(this,rt,void 0,"f"),a(this,O,"f").reset(),C(this,O,void 0,"f"),(e=a(this,V,"f"))===null||e===void 0||e.destroy(),C(this,V,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,a(this,D,"f").destroy(),C(this,D,void 0,"f"),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=tt.destroyed}}lt=new WeakMap,q=new WeakMap,ct=new WeakMap,D=new WeakMap,rt=new WeakMap,B=new WeakMap,U=new WeakMap,nt=new WeakMap,$=new WeakMap,ht=new WeakMap,At=new WeakMap,F=new WeakMap,jt=new WeakMap,V=new WeakMap,O=new WeakMap,Pn=new WeakMap,Se=new WeakMap,It=new WeakMap,M=new WeakSet,xn=function(t=!1){a(this,O,"f").on(_.historyInited,({initChapterId:e,videosInfo:n=[]})=>A(this,void 0,void 0,function*(){t&&(yield a(this,M,"m",ji).call(this,{initialChapter:e,videosInfo:n}))})),a(this,O,"f").on(_.interactives,e=>A(this,void 0,void 0,function*(){var n,r;if(e.type===L.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:s}=e.payload;this.setChapter({chapterId:s})}if(((r=e.payload)===null||r===void 0?void 0:r.behaviour)==="change-manifest"){const{manifestURL:s}=e.payload;this.setManifest(s)}}})),a(this,O,"f").on(_.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},ji=function({source:t,videosInfo:e=[]}){return A(this,void 0,void 0,function*(){C(this,jt,xo(this),"f");const n=document.createElement("div");a(this,jt,"f").on(Gt.activePlayerChanged,this.emitPlayerChanged);const{player:r,config:s}=yield a(this,jt,"f").init({source:t,initialChapter:a(this,D,"f").getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:r,config:s}})},zt=function(){var t;this.appState===tt.ready&&(a(this,It,"f").call(this),C(this,q,[],"f"),a(this,U,"f").release(),(t=a(this,B,"f"))===null||t===void 0||t.release(),this.appState=tt.initiated,a(this,ht,"f").next(!1))},$i=function(t){(!a(this,F,"f")||a(this,F,"f").isHidden)&&a(this,M,"m",Te).call(this);const e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){const s=r.range.join("-");a(this,At,"f").has(s)||(a(this,At,"f").add(s),a(this,O,"f").emit(_.interactives,{type:L.rangeEnded,payload:r,visibility:!0}))}},Oe=function(){a(this,rt,"f").unsubscribe(),a(this,rt,"f").add(this.options.player.events.started$.pipe(Bn()).subscribe(a(this,Se,"f"))).add(this.options.player.events.playing$.subscribe(a(this,U,"f").requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,U,"f").cancelAnimation)).add(this.options.player.info.position$.subscribe(a(this,M,"m",$i).bind(this))).add(a(this,$,"f").prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))),this.options.lastFrame&&a(this,rt,"f").add(this.options.player.info.duration$.subscribe(t=>{a(this,V,"f").setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,V,"f").setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,V,"f").reset(),setTimeout(()=>{a(this,V,"f").hide(),a(this,V,"f").lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,V,"f").onSeek))},$t=function(t){a(this,$,"f").chapter&&this.appState===tt.initiated&&(a(this,nt,"f").setManifestChapterEvents(t),C(this,q,a(this,M,"m",Ri).call(this,t),"f"),a(this,B,"f").containersEventsCallState.setData(t.containers),wt.setContainers(a(this,q,"f").map(e=>e.container.container).filter(e=>!$n(e.controls))),this.options.lastFrame&&a(this,U,"f").addFn(()=>{a(this,V,"f").onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.appState=tt.ready)},Ri=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)===null||e===void 0?void 0:e.reduce((r,s)=>{const l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){const c=new Mo({player:this.options.player,container:o(s,this.rootElement),branches:a(this,$,"f").chapter.branches,selectBranches:a(this,nt,"f"),interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,O,"f"),ignoreContainerEvent:()=>To(s,a(this,q,"f")),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.options.disableControlsOnPause?void 0:this.state.disabledControls$});return a(this,U,"f").addFn(c.whilePlaying,!0),[...r,c]}return[...r]},[]))!==null&&n!==void 0?n:[]},Te=function(){const t=a(this,ht,"f").getValue(),e=!!wt.getNextInteractiveTime();(e&&!t||!e&&t)&&a(this,ht,"f").next(!t)},Ai=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Ln=function(t){var e;if(a(this,M,"m",Ai).call(this),!a(this,D,"f").inited)return;const n=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),r=this.state.prevChapter$.getValue(),s=(e=r&&te(r)&&_o(r))!==null&&e!==void 0?e:!1,l=a(this,$,"f").manifest.metadata.initChapterId===t,o=a(this,D,"f").state.history$.getValue();if(l||s&&n){a(this,D,"f").updateHistory([t]);return}o.at(-1)!==t&&a(this,D,"f").updateHistory([...o,t])};const dl={Container:Di,createChoiceContainer:Wi,createAreaControl:ki,createButtonControl:Fi,createRelativeLayout:Xn,getRootEl:Pi,classnamesPrefix:Q},hl={version:Un};export{S as CustomError,_ as EVENT_NAMES,dt as INTERACTIVE_CLICK_ACTIONS,cl as Interactives,jo as ManifestController,hl as SDKInfo,Oi as chapterIdsToVKVideoIds,Qt as compareVersions,Xo as getChapterIdByVkVideoId,Rn as getVKVideoIdByMedia,Ko as getVideoRawIdByMedia,Ei as graphEventTypes,_o as hasEndTemplate,L as interactivesEventTypes,te as isLastChapter,In as isSupportedManifest,Yo as isVKVariantItem,dl as utils,Zo as vkVideoIdsToChapterIds};
|