@vkontakte/videoplayer-interactive 1.0.16-dev.c0c9cf1c.0 → 1.0.16-dev.fce168eb.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es2015.cjs.js +6 -6
- package/es2015.esm.js +5 -5
- package/es2018.cjs.js +6 -6
- package/es2018.esm.js +5 -5
- package/esnext.cjs.js +5 -5
- package/esnext.esm.js +5 -5
- package/evergreen.esm.js +5 -5
- package/package.json +3 -3
package/es2018.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.16-dev.
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.16-dev.fce168eb.0
|
|
3
|
+
* Mon, 02 Sep 2024 14:52:06 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-16/doc/
|
|
5
5
|
*/
|
|
6
|
-
var Ro=Object.create;var tr=Object.defineProperty;var Vo=Object.getOwnPropertyDescriptor;var Ao=Object.getOwnPropertyNames;var Mo=Object.getPrototypeOf,Lo=Object.prototype.hasOwnProperty;var yi=r=>{throw TypeError(r)};var Oo=(r,e,t)=>e in r?tr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var d=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Po=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ao(e))!Lo.call(r,n)&&n!==t&&tr(r,n,{get:()=>e[n],enumerable:!(i=Vo(e,n))||i.enumerable});return r};var No=(r,e,t)=>(t=r!=null?Ro(Mo(r)):{},Po(e||!r||!r.__esModule?tr(t,"default",{value:r,enumerable:!0}):t,r));var Y=(r,e,t)=>Oo(r,typeof e!="symbol"?e+"":e,t),rr=(r,e,t)=>e.has(r)||yi("Cannot "+t);var o=(r,e,t)=>(rr(r,e,"read from private field"),t?t.call(r):e.get(r)),T=(r,e,t)=>e.has(r)?yi("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),b=(r,e,t,i)=>(rr(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t),N=(r,e,t)=>(rr(r,e,"access private method"),t);var vi=(r,e,t,i)=>({set _(n){b(r,e,n,t)},get _(){return o(r,e,i)}});var ee=d((Sr,tn)=>{"use strict";var it=function(r){return r&&r.Math===Math&&r};tn.exports=it(typeof globalThis=="object"&&globalThis)||it(typeof window=="object"&&window)||it(typeof self=="object"&&self)||it(typeof global=="object"&&global)||it(typeof Sr=="object"&&Sr)||function(){return this}()||Function("return this")()});var fe=d((_p,rn)=>{"use strict";rn.exports=function(r){try{return!!r()}catch(e){return!0}}});var nt=d((Rp,nn)=>{"use strict";var pa=fe();nn.exports=!pa(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var ln=d((Vp,cn)=>{"use strict";var da=nt(),an=Function.prototype,sn=an.apply,on=an.call;cn.exports=typeof Reflect=="object"&&Reflect.apply||(da?on.bind(sn):function(){return on.apply(sn,arguments)})});var Te=d((Ap,pn)=>{"use strict";var hn=nt(),un=Function.prototype,_r=un.call,fa=hn&&un.bind.bind(_r,_r);pn.exports=hn?fa:function(r){return function(){return _r.apply(r,arguments)}}});var Rr=d((Mp,fn)=>{"use strict";var dn=Te(),ma=dn({}.toString),ya=dn("".slice);fn.exports=function(r){return ya(ma(r),8,-1)}});var Vr=d((Lp,mn)=>{"use strict";var va=Rr(),ga=Te();mn.exports=function(r){if(va(r)==="Function")return ga(r)}});var me=d((Op,yn)=>{"use strict";var Ar=typeof document=="object"&&document.all;yn.exports=typeof Ar=="undefined"&&Ar!==void 0?function(r){return typeof r=="function"||r===Ar}:function(r){return typeof r=="function"}});var ke=d((Pp,vn)=>{"use strict";var ba=fe();vn.exports=!ba(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Dt=d((Np,gn)=>{"use strict";var Ea=nt(),qt=Function.prototype.call;gn.exports=Ea?qt.bind(qt):function(){return qt.apply(qt,arguments)}});var xn=d(Cn=>{"use strict";var bn={}.propertyIsEnumerable,En=Object.getOwnPropertyDescriptor,Ca=En&&!bn.call({1:2},1);Cn.f=Ca?function(e){var t=En(this,e);return!!t&&t.enumerable}:bn});var Mr=d((kp,In)=>{"use strict";In.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var wn=d((Fp,Tn)=>{"use strict";var xa=Te(),Ia=fe(),Ta=Rr(),Lr=Object,wa=xa("".split);Tn.exports=Ia(function(){return!Lr("z").propertyIsEnumerable(0)})?function(r){return Ta(r)==="String"?wa(r,""):Lr(r)}:Lr});var Or=d(($p,Sn)=>{"use strict";Sn.exports=function(r){return r==null}});var Pr=d((Bp,_n)=>{"use strict";var Sa=Or(),_a=TypeError;_n.exports=function(r){if(Sa(r))throw new _a("Can't call method on "+r);return r}});var Vn=d((qp,Rn)=>{"use strict";var Ra=wn(),Va=Pr();Rn.exports=function(r){return Ra(Va(r))}});var st=d((Dp,An)=>{"use strict";var Aa=me();An.exports=function(r){return typeof r=="object"?r!==null:Aa(r)}});var Nr=d((Hp,Mn)=>{"use strict";Mn.exports={}});var Fr=d((Gp,On)=>{"use strict";var jr=Nr(),kr=ee(),Ma=me(),Ln=function(r){return Ma(r)?r:void 0};On.exports=function(r,e){return arguments.length<2?Ln(jr[r])||Ln(kr[r]):jr[r]&&jr[r][e]||kr[r]&&kr[r][e]}});var Nn=d((Up,Pn)=>{"use strict";var La=Te();Pn.exports=La({}.isPrototypeOf)});var $n=d((zp,Fn)=>{"use strict";var Oa=ee(),jn=Oa.navigator,kn=jn&&jn.userAgent;Fn.exports=kn?String(kn):""});var zn=d((Wp,Un)=>{"use strict";var Gn=ee(),$r=$n(),Bn=Gn.process,qn=Gn.Deno,Dn=Bn&&Bn.versions||qn&&qn.version,Hn=Dn&&Dn.v8,Z,Ht;Hn&&(Z=Hn.split("."),Ht=Z[0]>0&&Z[0]<4?1:+(Z[0]+Z[1]));!Ht&&$r&&(Z=$r.match(/Edge\/(\d+)/),(!Z||Z[1]>=74)&&(Z=$r.match(/Chrome\/(\d+)/),Z&&(Ht=+Z[1])));Un.exports=Ht});var Br=d((Kp,Kn)=>{"use strict";var Wn=zn(),Pa=fe(),Na=ee(),ja=Na.String;Kn.exports=!!Object.getOwnPropertySymbols&&!Pa(function(){var r=Symbol("symbol detection");return!ja(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Wn&&Wn<41})});var qr=d((Qp,Qn)=>{"use strict";var ka=Br();Qn.exports=ka&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Dr=d((Yp,Yn)=>{"use strict";var Fa=Fr(),$a=me(),Ba=Nn(),qa=qr(),Da=Object;Yn.exports=qa?function(r){return typeof r=="symbol"}:function(r){var e=Fa("Symbol");return $a(e)&&Ba(e.prototype,Da(r))}});var Zn=d((Xp,Xn)=>{"use strict";var Ha=String;Xn.exports=function(r){try{return Ha(r)}catch(e){return"Object"}}});var Hr=d((Zp,Jn)=>{"use strict";var Ga=me(),Ua=Zn(),za=TypeError;Jn.exports=function(r){if(Ga(r))return r;throw new za(Ua(r)+" is not a function")}});var ts=d((Jp,es)=>{"use strict";var Wa=Hr(),Ka=Or();es.exports=function(r,e){var t=r[e];return Ka(t)?void 0:Wa(t)}});var is=d((ed,rs)=>{"use strict";var Gr=Dt(),Ur=me(),zr=st(),Qa=TypeError;rs.exports=function(r,e){var t,i;if(e==="string"&&Ur(t=r.toString)&&!zr(i=Gr(t,r))||Ur(t=r.valueOf)&&!zr(i=Gr(t,r))||e!=="string"&&Ur(t=r.toString)&&!zr(i=Gr(t,r)))return i;throw new Qa("Can't convert object to primitive value")}});var ss=d((td,ns)=>{"use strict";ns.exports=!0});var cs=d((rd,as)=>{"use strict";var os=ee(),Ya=Object.defineProperty;as.exports=function(r,e){try{Ya(os,r,{value:e,configurable:!0,writable:!0})}catch(t){os[r]=e}return e}});var Wr=d((id,us)=>{"use strict";var Xa=ss(),Za=ee(),Ja=cs(),ls="__core-js_shared__",hs=us.exports=Za[ls]||Ja(ls,{});(hs.versions||(hs.versions=[])).push({version:"3.38.0",mode:Xa?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var fs=d((nd,ds)=>{"use strict";var ps=Wr();ds.exports=function(r,e){return ps[r]||(ps[r]=e||{})}});var Kr=d((sd,ms)=>{"use strict";var ec=Pr(),tc=Object;ms.exports=function(r){return tc(ec(r))}});var Gt=d((od,ys)=>{"use strict";var rc=Te(),ic=Kr(),nc=rc({}.hasOwnProperty);ys.exports=Object.hasOwn||function(e,t){return nc(ic(e),t)}});var gs=d((ad,vs)=>{"use strict";var sc=Te(),oc=0,ac=Math.random(),cc=sc(1 .toString);vs.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+cc(++oc+ac,36)}});var Cs=d((cd,Es)=>{"use strict";var lc=ee(),hc=fs(),bs=Gt(),uc=gs(),pc=Br(),dc=qr(),Fe=lc.Symbol,Qr=hc("wks"),fc=dc?Fe.for||Fe:Fe&&Fe.withoutSetter||uc;Es.exports=function(r){return bs(Qr,r)||(Qr[r]=pc&&bs(Fe,r)?Fe[r]:fc("Symbol."+r)),Qr[r]}});var ws=d((ld,Ts)=>{"use strict";var mc=Dt(),xs=st(),Is=Dr(),yc=ts(),vc=is(),gc=Cs(),bc=TypeError,Ec=gc("toPrimitive");Ts.exports=function(r,e){if(!xs(r)||Is(r))return r;var t=yc(r,Ec),i;if(t){if(e===void 0&&(e="default"),i=mc(t,r,e),!xs(i)||Is(i))return i;throw new bc("Can't convert object to primitive value")}return e===void 0&&(e="number"),vc(r,e)}});var Yr=d((hd,Ss)=>{"use strict";var Cc=ws(),xc=Dr();Ss.exports=function(r){var e=Cc(r,"string");return xc(e)?e:e+""}});var Vs=d((ud,Rs)=>{"use strict";var Ic=ee(),_s=st(),Xr=Ic.document,Tc=_s(Xr)&&_s(Xr.createElement);Rs.exports=function(r){return Tc?Xr.createElement(r):{}}});var Zr=d((pd,As)=>{"use strict";var wc=ke(),Sc=fe(),_c=Vs();As.exports=!wc&&!Sc(function(){return Object.defineProperty(_c("div"),"a",{get:function(){return 7}}).a!==7})});var Os=d(Ls=>{"use strict";var Rc=ke(),Vc=Dt(),Ac=xn(),Mc=Mr(),Lc=Vn(),Oc=Yr(),Pc=Gt(),Nc=Zr(),Ms=Object.getOwnPropertyDescriptor;Ls.f=Rc?Ms:function(e,t){if(e=Lc(e),t=Oc(t),Nc)try{return Ms(e,t)}catch(i){}if(Pc(e,t))return Mc(!Vc(Ac.f,e,t),e[t])}});var Ns=d((fd,Ps)=>{"use strict";var jc=fe(),kc=me(),Fc=/#|\.prototype\./,ot=function(r,e){var t=Bc[$c(r)];return t===Dc?!0:t===qc?!1:kc(e)?jc(e):!!e},$c=ot.normalize=function(r){return String(r).replace(Fc,".").toLowerCase()},Bc=ot.data={},qc=ot.NATIVE="N",Dc=ot.POLYFILL="P";Ps.exports=ot});var Fs=d((md,ks)=>{"use strict";var js=Vr(),Hc=Hr(),Gc=nt(),Uc=js(js.bind);ks.exports=function(r,e){return Hc(r),e===void 0?r:Gc?Uc(r,e):function(){return r.apply(e,arguments)}}});var Bs=d((yd,$s)=>{"use strict";var zc=ke(),Wc=fe();$s.exports=zc&&Wc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Ds=d((vd,qs)=>{"use strict";var Kc=st(),Qc=String,Yc=TypeError;qs.exports=function(r){if(Kc(r))return r;throw new Yc(Qc(r)+" is not an object")}});var Us=d(Gs=>{"use strict";var Xc=ke(),Zc=Zr(),Jc=Bs(),Ut=Ds(),Hs=Yr(),el=TypeError,Jr=Object.defineProperty,tl=Object.getOwnPropertyDescriptor,ei="enumerable",ti="configurable",ri="writable";Gs.f=Xc?Jc?function(e,t,i){if(Ut(e),t=Hs(t),Ut(i),typeof e=="function"&&t==="prototype"&&"value"in i&&ri in i&&!i[ri]){var n=tl(e,t);n&&n[ri]&&(e[t]=i.value,i={configurable:ti in i?i[ti]:n[ti],enumerable:ei in i?i[ei]:n[ei],writable:!1})}return Jr(e,t,i)}:Jr:function(e,t,i){if(Ut(e),t=Hs(t),Ut(i),Zc)try{return Jr(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new el("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Ws=d((bd,zs)=>{"use strict";var rl=ke(),il=Us(),nl=Mr();zs.exports=rl?function(r,e,t){return il.f(r,e,nl(1,t))}:function(r,e,t){return r[e]=t,r}});var Ys=d((Ed,Qs)=>{"use strict";var at=ee(),sl=ln(),ol=Vr(),al=me(),cl=Os().f,ll=Ns(),$e=Nr(),hl=Fs(),Be=Ws(),Ks=Gt();Wr();var ul=function(r){var e=function(t,i,n){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,i)}return new r(t,i,n)}return sl(r,this,arguments)};return e.prototype=r.prototype,e};Qs.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,s=r.proto,c=i?at:n?at[t]:at[t]&&at[t].prototype,a=i?$e:$e[t]||Be($e,t,{})[t],l=a.prototype,h,p,f,m,C,I,k,w,y;for(m in e)h=ll(i?m:t+(n?".":"#")+m,r.forced),p=!h&&c&&Ks(c,m),I=a[m],p&&(r.dontCallGetSet?(y=cl(c,m),k=y&&y.value):k=c[m]),C=p&&k?k:e[m],!(!h&&!s&&typeof I==typeof C)&&(r.bind&&p?w=hl(C,at):r.wrap&&p?w=ul(C):s&&al(C)?w=ol(C):w=C,(r.sham||C&&C.sham||I&&I.sham)&&Be(w,"sham",!0),Be(a,m,w),s&&(f=t+"Prototype",Ks($e,f)||Be($e,f,{}),Be($e[f],m,C),r.real&&l&&(h||!l[m])&&Be(l,m,C)))}});var Zs=d((Cd,Xs)=>{"use strict";var pl=Math.ceil,dl=Math.floor;Xs.exports=Math.trunc||function(e){var t=+e;return(t>0?dl:pl)(t)}});var ii=d((xd,Js)=>{"use strict";var fl=Zs();Js.exports=function(r){var e=+r;return e!==e||e===0?0:fl(e)}});var to=d((Id,eo)=>{"use strict";var ml=ii(),yl=Math.min;eo.exports=function(r){var e=ml(r);return e>0?yl(e,9007199254740991):0}});var io=d((Td,ro)=>{"use strict";var vl=to();ro.exports=function(r){return vl(r.length)}});var so=d((wd,no)=>{"use strict";no.exports=function(){}});var oo=d(()=>{"use strict";var gl=Ys(),bl=Kr(),El=io(),Cl=ii(),xl=so();gl({target:"Array",proto:!0},{at:function(e){var t=bl(this),i=El(t),n=Cl(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});xl("at")});var co=d((Rd,ao)=>{"use strict";var Il=Fr();ao.exports=Il});var ho=d((Vd,lo)=>{"use strict";oo();var Tl=co();lo.exports=Tl("Array","at")});var po=d((Ad,uo)=>{"use strict";var wl=ho();uo.exports=wl});var mo=d((Md,fo)=>{"use strict";var Sl=po();fo.exports=Sl});var gi="1.0.16-dev.c0c9cf1c.0";function ir(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var B="SDK_NAME",jo="SDK_NAME-controls-container",ft=()=>document.querySelector(`.${jo}`),xi=.4,W={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},bi={top:"flex-start",bottom:"flex-end",center:"center"},Ei={start:"flex-start",end:"flex-end",center:"center"},Ci={start:"left",end:"right",center:"center"},mt=({target:r,props:e})=>{var t,i,n,s,c,a;r.style.alignItems=(i=bi[(t=e==null?void 0:e.text)==null?void 0:t.gravityVertical])!=null?i:bi.center,r.style.justifyContent=(s=Ei[(n=e==null?void 0:e.text)==null?void 0:n.gravityHorizontal])!=null?s:Ei.center,r.style.textAlign=(a=Ci[(c=e==null?void 0:e.text)==null?void 0:c.alignment])!=null?a:Ci.start},yt=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,c,a,l,h;r.style.color=(s=(n=e==null?void 0:e.text)==null?void 0:n.color)!=null?s:t.textColor,r.style.fontSize=`calc(${i.height} * ${(a=(c=e==null?void 0:e.text)==null?void 0:c.size)!=null?a:t.textSize})`,r.textContent=(h=(l=e==null?void 0:e.text)==null?void 0:l.value)!=null?h:t.textContent},vt=({target:r,props:e,fallback:t})=>{var i,n,s,c;r.style.backgroundColor=ir((n=(i=e==null?void 0:e.background)==null?void 0:i.color)!=null?n:t.backgroundColor,(c=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?c:t.backgroundAlpha)},gt=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,c,a,l,h,p,f,m,C,I;r.style.border=`calc(${i.height} * ${(c=(s=(n=e==null?void 0:e.shape)==null?void 0:n.border)==null?void 0:s.width)!=null?c:t.borderWidth}) solid ${ir((h=(l=(a=e==null?void 0:e.shape)==null?void 0:a.border)==null?void 0:l.color)!=null?h:t.borderColor,(m=(f=(p=e==null?void 0:e.shape)==null?void 0:p.border)==null?void 0:f.alpha)!=null?m:t.borderAlpha)}`,r.style.borderRadius=`calc(${i.height} * ${(I=(C=e==null?void 0:e.shape)==null?void 0:C.roundCorners)!=null?I:t.roundCorners})`},Me=({target:r,layoutParams:e,fallback:t})=>{r.style.transform=`rotate(${-e.angle}rad)`};var nr="int",Le={AREA:`${nr}_area`,TEXT:`${nr}_text`,BUTTON:`${nr}_bttn`};var ue=class{constructor(e){this.control=e}createView(e){var n;let t=document.createElement("div");t.classList.add(`${B}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let i=((n=this.control.layoutParams.innerSizesDependOn)!=null?n:W.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:t,dependsOn:i}}setEvents(e,t){e&&this.control.events.forEach(i=>{switch(i.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",s=>{s.stopPropagation(),t&&t({action:i.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${B}-control-container-${this.control.id}`)}};var bt=r=>{if(r.type.trim().toLowerCase()==="area")return new sr(r)},sr=class extends ue{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("button");return s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",Le.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",vt({target:s,props:this.control.props,fallback:{...W,backgroundColor:"transparent"}}),gt({target:s,props:this.control.props,fallback:{...W,borderAlpha:0},dependsOn:i}),Me({target:s,layoutParams:this.control.layoutParams,fallback:W}),n.append(s),e.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(`.${B}-${this.control.id}`)}};var Et=()=>{let r=document.createElement("span");return r.style.display="inline-block",r.style.whiteSpace="pre",r.style.overflow="hidden",r.style.textOverflow="ellipsis",r.style.maxWidth="100%",r.style.maxHeight="100%",r};var Ct=r=>{if(r.type.trim().toLowerCase()==="button")return new or(r)},or=class extends ue{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("button");s.type="button",s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",Le.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let c=Et();return Me({target:s,layoutParams:this.control.layoutParams,fallback:W}),vt({target:s,props:this.control.props,fallback:W}),gt({target:s,props:this.control.props,fallback:W,dependsOn:i}),mt({target:s,props:this.control.props}),yt({target:c,props:this.control.props,fallback:W,dependsOn:i}),s.append(c),n.append(s),e.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(`.${B}-${this.control.id}`)}};var Ii=r=>{if(r.type.trim().toLowerCase()==="text")return new ar(r)},ar=class extends ue{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("div");s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",Le.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let c=Et();return Me({target:s,layoutParams:this.control.layoutParams,fallback:W}),mt({target:s,props:this.control.props}),yt({target:c,props:this.control.props,fallback:W,dependsOn:i}),s.append(c),n.append(s),e.append(n),this.controlEl=s,n}disable(){}enable(){}getElement(){return document.querySelector(`.${B}-${this.control.id}`)}};var cr=class{constructor(e){this.layout=e}},Ti=r=>{if(r.type.trim().toLowerCase()==="relative")return new Ue(r)},Ue=class extends cr{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var pe,xt,wi,Oe=class{constructor(e){T(this,pe);this.container=e,this.factories=new Map,N(this,pe,xt).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),N(this,pe,xt).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),N(this,pe,xt).call(this)}};pe=new WeakSet,xt=function(){this.controls=N(this,pe,wi).call(this)},wi=function(){var e;return(e=this.container.controls)==null?void 0:e.reduce((t,i)=>{let n=i.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...t,s(i)]:[...t]},[])};var It=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new lr(r,e)},lr=class extends Oe{constructor(e,t){super(e),this.rootElement=t!=null?t:ft(),this.layout=new Ue(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Ct),this.addControlFactory("text",Ii),this.addControlFactory("area",bt)}createView(e){let t=document.createElement("div");return t.classList.add(`${B}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(i=>{let n=i.createView({parent:t,layoutFn:this.layout.setControlLayout});i.setEvents(n,e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity=1,this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=xi,this.isDisabled=!0)}removeView(){var e;this.isRemoved||((e=this.getElement())==null||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${B}-${this.container.id}`)}};import{Subject as Ml,ValueSubject as te,Observable as bo,once as Ll,Subscription as Ol,clientChecker as Pl,combine as Nl}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as ko}from"@vkontakte/videoplayer-shared";function Tt(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var Ce=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,ze=r=>Ce(r,"Object"),wt=r=>Ce(r,"String"),St=r=>Ce(r,"Array"),_t=r=>Ce(r,"Number"),Si=r=>Ce(r,"Function");var hr=r=>_t(r)&&!isNaN(r);var xe=r=>ze(r)&&Object.keys(r).length===0,ur=r=>St(r)&&!r.length;var We=(r,e)=>wt(r)&&(e?r.trim():r).length;var _i="video_interactive",Ri="videoint";var Fo=250,Ke=class{constructor(e){Y(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}))});Y(this,"handleChapterChange",e=>{var t;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.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}});Y(this,"handleManifestChange",async(e,t=[])=>{var i;if(!_t(e.graph.edit.chapters[0].x)){this.isReady=!1,(i=this.onError)==null||i.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let n;try{n=await ko(this.lang,_i,Ri)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:s}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new s(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:n}),this.ngEditor.on("control",({name:c,chapterId:a})=>{c==="openPreview"&&this.onOpenPreviewClick(a)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo={...c}})}this.visitedChapterIds=new Set(t),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0});this.init(e)}init({root:e,onOpenPreviewClick:t,onError:i,lang:n,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=i,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=$o(e),this.resizeObserver=new ResizeObserver(Tt(this.onResize,Fo)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor.updateVideosInfo(e)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function $o(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var Qe=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let c=s.startTime-e;if(c<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<c&&(t=t===-1?c:Math.min(t,c))}return!i&&t!==-1?t:null}}};var de=(r="",e="")=>{let t=r.split("."),i=e.split("."),n=0;for(let s=0;s<Math.max(t.length,i.length)&&!n;s++)t[s]>i[s]?n=1:t[s]<i[s]?n=-1:n=0;return n};import{v4 as Bo}from"uuid";var qo="3.1",Vi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Do={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ai=r=>{let e=[];for(let t of r.chapters){let i,n=[];for(let{isDefault:a,...l}of t.branches)a&&(i=l.id),n.push(l);let s=[],c=[];for(let{fallbackStrategy:a,...l}of t.containers){let h=!!l.endTime,p=[Do];switch(a){case"await":h?p=[]:s=[];break;case"default":{let f={type:"onSuspense",action:{type:Vi.default,args:{branchId:i,shouldOpenNow:!h,isDetachContainer:!0}}};h?p=[f]:s=[f];break}case"random":case"weightlessRandom":case"max":case"min":{let f={type:"onSuspense",action:{type:Vi[a],args:{}}};h?p=[f]:s=[f];break}}for(let f of l.controls)c.push({...l,controls:[{...f}],id:Bo(),events:p})}e.push({...t,containers:c,events:s,branches:n})}return r.metadata.version=qo,r.metadata.updated=new Date().toISOString(),{...r,chapters:e}};var Ho="3.2",Mi=r=>{if(!r.media){let{media:e,...t}=r.metadata;return{...r,metadata:{...t,version:Ho},media:e}}return r};var Go="3.3",Uo=(r=[])=>({edit:{chapters:r},view:{}}),Li={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Oi=r=>{var i;let e=[],t=[];for(let n of r.chapters){let{id:s,x:c,y:a,...l}=n,h=l.containers.map(p=>{var f;return{...p,controls:p.controls.map(({subtype:m,type:C,...I})=>({...I,type:m!=null?m:C})),events:(f=p.events)!=null&&f.length?p.events:[Li]}});e.push({id:s,...l,containers:h,events:(i=l.events)!=null&&i.length?l.events:[Li]}),t.push({id:s,x:c,y:a})}return{...r,chapters:e,graph:Uo(t),metadata:{...r.metadata,version:Go}}};var zo=[{version:"3.0",migrate:Ai},{version:"3.1",migrate:Mi},{version:"3.2",migrate:Oi}],pr=r=>zo.reduce((e,t)=>de(e.metadata.version,t.version)?e:t.migrate(e),r);var Yh=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Pi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Xh=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),M=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),dr=(s=>(s.GO_NEXT_BUTTON="GO_NEXT_BUTTON",s.GO_NEXT_AREA="GO_NEXT_AREA",s.WATCH_AGAIN="WATCH_AGAIN",s.OPEN_GRAPH="OPEN_GRAPH",s.CLOSE_GRAPH="CLOSE_GRAPH",s))(dr||{});var Ni={metadata:"Object",chapters:"Array"},Wo="3.0.0",Ko="3.3.0",Rt=r=>{let e=de(r,Wo);return e===-1?!1:e===0?!0:de(r,Ko)!==1},ji=r=>{if(!ze(r))return!1;for(let e in Ni)if(!r[e]||!Ce(r[e],Ni[e]))return!1;return Rt(r.metadata.version)},Vt=r=>r.type===Pi.Text;var z=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Pe=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let i=()=>{t(),this.off(e,i)};return this.listeners[e].push(i),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let i=this.listeners[e]||[];for(let n=i.length;n>0;n--)if(i[n]===t){i.splice(n,1);break}return this}emit(e,...t){let i=this.listeners[e];return i?(i.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var At=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{Si(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(i=>i!==e),t&&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=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};this.fn=e,this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as ta}from"@vkontakte/videoplayer-shared";var Mt=class{constructor(e){var t,i;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(i=e==null?void 0:e.manifestLoaders)!=null?i:[]}}async exec(e,t){return Qo(...this.loaders[e])(t)}};function Qo(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function Ye(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function Lt({actions:r,errors:e,chapterId:t,...i}){if(t){let n=r.getManifest(),s=r.getChapter(n.chapters,t);if(s){let c=r.getMedia(n.media,s.videoId),a=r.getGraph(n.graph,s.id);return c?{...i,actions:r,errors:e,result:{chapter:s,media:c,graph:a}}:{...i,errors:Ye(e,Lt.name,"Could not find media"),actions:r}}}return{...i,errors:Ye(e,Lt.name,"Could not find chapter"),actions:r}}var Ot=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,s=i.length;n<s;n++)if(i[n].callback===t){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,s=i.length;n<s;n++){let c=i[n];try{c.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}c.options&&c.options.once&&this.removeEventListener(e.type,c.callback)}return!e.defaultPrevented}},Ne=class extends Ot{constructor(){super(),this.listeners||Ot.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Xe=class{constructor(){Object.defineProperty(this,"signal",{value:new Ne,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(n){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document=="undefined")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch(n){i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(Xe.prototype[Symbol.toStringTag]="AbortController",Ne.prototype[Symbol.toStringTag]="AbortSignal");function Pt(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function fr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!Pt({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||n)&&(s=function(h,p){let f;p&&p.signal&&(f=p.signal,delete p.signal);let m=new t(h,p);return f&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),m},s.prototype=t.prototype);let c=e;return{fetch:(l,h)=>{let p=s&&s.prototype.isPrototypeOf(l)?l.signal:h?h.signal:void 0;if(p){let f;try{f=new DOMException("Aborted","AbortError")}catch(C){f=new Error("Aborted"),f.name="AbortError"}if(p.aborted)return Promise.reject(f);let m=new Promise((C,I)=>{p.addEventListener("abort",()=>I(f),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([m,c(l,h)])}return c(l,h)},Request:s}}var Ze=Pt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),ki=Ze?fr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,mr=Ze?ki.fetch:window.fetch,Iu=Ze?ki.Request:window.Request,Tu=Ze?Xe:window.AbortController,wu=Ze?Ne:window.AbortSignal;var Yo=async r=>{try{let e={},t;if(wt(r)){t=new URL(r).href;let n=await mr(t);if(!n.ok)return{};e=await n.json()}else if(ze(r))e=r;else return{};if(!ji(e))return{};let i=e.metadata.media;if(wt(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=await mr(n);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch(n){return Jo(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Fi(r){let{manifest:e,manifestURL:t}=await Yo(r),i=pr(e);return i.media=Xo(i.media,t),delete i.metadata.media,i}function Nt(r,e){if(e)return r.find(t=>t.id===e)}function yr(r,e){var t,i;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(n=>n.id===e):(i=r.view)!=null&&i.chapters?r.view.chapters.find(n=>n.id===e):void 0}function vr(r,e){return r.videos.find(t=>t.id===e)}function Xo(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=Zo(n,e);return{...i,url:s||n}})}))}}function Zo(r="",e){try{return new URL(r,e).href}catch(t){return""}}function Jo(r){return de(r,"3.2.0")>=0}var j=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),jt=r=>St(r)&&!ur(r),ie=r=>r.order==="end",kt=r=>St(r.containers)&&!ur(r.containers)&&ie(r),$i=(r,e)=>{var i;let t=r*1e3;return jt(e.controls)&&t<((i=e.startTime)!=null?i:0)},gr=(r,e)=>{var i,n;let t=r*1e3;return jt(e.controls)&&t>=((i=e.startTime)!=null?i:0)&&t<=((n=e.endTime)!=null?n:1/0)};var Ie=r=>r.some(e=>e.action.type==="expect"),br=r=>r.find(e=>e.action.type==="expect"),ea=r=>(r==null?void 0:r.length)===1,Ft=r=>ea(r)&&Vt(r[0]);var Bi=({fn:r,type:e=1},...t)=>(...i)=>e?r(...i,...t):r({...i[e],...t[e]}),qi=(r,e)=>Ie(r.events)?!1:e.some(({container:t})=>t.container.id!==r.id&&Ie(t.container.events)&&t.container.endTime===r.endTime&&!t.isRemoved);var je=class extends Mt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new ta(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var n;this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ye},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await Fi((n=i.result)!=null?n:t),this}async setInitial(){return this.setNext()}async setNext(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",Lt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:yr,getChapter:Nt,getMedia:vr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ye},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){var i;return this.getByChapterId((i=this.manifest)==null?void 0:i.metadata.initChapterId)||null}getByChapterId(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t||!this.manifest)return null;let n=Nt(this.manifest.chapters,t);if(n){let s=vr(this.manifest.media,n.videoId),c=yr(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:c}}return null}getBranches(t=(i=>(i=this.chapter)==null?void 0:i.id)()){var n,s,c;if(t===((n=this.chapter)==null?void 0:n.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let a=Nt(((c=this.manifest)==null?void 0:c.chapters)||[],t);return this.getByBranches(a==null?void 0:a.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{let s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){var t,i;return((t=this.chapter)==null?void 0:t.id)===((i=this.manifest)==null?void 0:i.metadata.initChapterId)}isEndChapter(){return ie(this.chapter)}};import{Player as ra}from"@vkontakte/videoplayer-core";import{Subscription as ia}from"@vkontakte/videoplayer-shared";var Di=r=>{let e=r.variants.find(t=>{var i;return((i=t.payload)==null?void 0:i.type)==="vk"});if(e&&"payload"in e){let[t,i]=e.payload.id.split("_");return[t,i]}return[]};var E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Je={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},R={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Er(){let r=new Map;function e({listId:n=Math.random().toString(),itemId:s=Math.random().toString(),...c}){let a=r.get(n),l={...c};return a?a[s]=l:r.set(n,{[s]:l}),{listId:n,itemId:s,...c}}function t(n,s){var a,l,h;let c=r.get(n);if(c){if(s)return(a=c[s])==null||a.player.destroy(),(l=c[s])==null||l.container.remove(),(h=c[s])==null||h.subscription.unsubscribe(),delete c[s],Object.keys(c).length||r.delete(n),!0;for(let p of Object.values(c))p.player.destroy(),p.container.remove();return r.delete(n),!0}else throw Error("Can't remove. Not find.")}function i(){for(let n of r)t(n[0])}return{createPlayer:e,removePlayer:t,map:r,removeAll:i}}function Cr(r,e=[]){var s,c,a;let t={},i,n=!e.length;for(let l of r.variants)if(!i&&"cover"in l&&(i=l.cover),"url"in l)switch(l.type.toLowerCase()){case"mp4":(n||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[(s=l.standard)!=null?s:"Invariant quality"]:l.url});break;case"mpeg":(n||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[(c=l.standard)!=null?c:"Invariant quality"]:l.url});break;case"hls":(n||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:l.url}});break;case"dash":(n||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:l.url}});break;default:break}return{sources:t,thumbUrl:i,title:(a=r.title)!=null?a:""}}var et=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&i.includes(e)&&(r.setQuality(e),r.setAutoQuality(!1))};var tt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},na=2;function xr(r){let e=Er(),t,i,n=new Pe,s={},c=!1,a=null,l=!1,h;r&&p(r);function p(u){a=u}function f(u,v,x){var L;if(!a)throw Error("need to set interactive controller");if(!a.options)return;let A=((L=e.map.get(u))!=null?L:{})[v];if(A){s={chapterId:x,listId:u,itemId:v,...A};let P=s.player;i=P.info.currentQuality$.subscribe(_=>{if(!(!_||!P.info.position$.getValue())){t=_;for(let U of e.map)Object.values(U[1]).forEach(({player:$})=>{P.info.isAutoQualityEnabled$.getValue()||et($,_)})}}),A.container.remove(),c=!1,a.setPlayer(A.player),l||(a.init(),l=!0),n.emit(tt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function m(u,v,x){if(!a)throw Error("need to set interactive controller");if(xe(s)||u!==s.itemId)return;if(x>=0&&!c){let A=a.getChapterBranches();c=!0;let L=new Set;for(let P of A)L.has(P.media.id)||(await I({media:P.media,chapterId:P.chapter.id,setAsActive:!1,title:P.chapter.label}),L.add(P.media.id))}}async function C({chapter:{id:u},media:v}){if(xe(s))return;i==null||i.unsubscribe();let x=s.player.info.muted$.getValue(),g=s.player.info.currentQuality$.getValue(),A=s.player.info.isAutoQualityEnabled$.getValue(),L=s.player.info.volume$.getValue(),P=s.player.info.currentPlaybackRate$.getValue(),_=!A,U=!1;for(let $ of e.map)if($[0]===v.id){let re=Object.keys($[1]);for(let H of re)H===s.itemId?(re.length<na||(U=!0),e.removePlayer($[0],H)):(U=!0,f($[0],H,u),_?et(s.player,g):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(x),s.player.setPlaybackRate(P))}else e.removePlayer($[0]);U||(await I({media:v,chapterId:u,setAsActive:!0,playbackRate:P}),_?et(s.player,g):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(x))}async function I({media:u,chapterId:v,prefetch:x=!0,setAsActive:g=!0,autoplay:A=!1,preferredExt:L,title:P,playbackRate:_}){var ui,pi,di,fi,mi;let U=Math.random().toString(),$=document.createElement("div");h.append($);let re=(ui=s==null?void 0:s.player)==null?void 0:ui.info.isAutoQualityEnabled$.getValue(),H;if((pi=a==null?void 0:a.options)!=null&&pi.vkVideoLoader){let dt=Di(u);dt.length&&(H=await a.options.vkVideoLoader(...dt))}let pt=((di=a==null?void 0:a.options)==null?void 0:di.coreConfig)||{},_o={...pt,configName:[...(fi=pt.configName)!=null?fi:[],"interactive"]},li={container:$,...((mi=H==null?void 0:H.videos)==null?void 0:mi[0])||{sources:Cr(u,L).sources},title:P,failoverHosts:(H==null?void 0:H.failoverHosts)||[]},Ee=new ra(_o);Ee.initVideo(li);let hi=new ia;hi.add(Ee.info.position$.subscribe(function(dt){m(U,Ee.info.duration$.getValue(),dt)})).add(Ee.events.canplay$.subscribe(function(){re||et(Ee,t),_&&Ee.setPlaybackRate(_)}));let Ae=e.createPlayer({listId:u.id,itemId:U,player:Ee,container:$,sources:Cr(u,L).sources,config:li,subscription:hi});return g&&f(u.id,Ae.itemId,v),A&&Ae.player.play(),x&&!A&&Ae.player.prepare(),n.emit(tt.playerCreated,Ae.player),{player:Ae.player,config:Ae.config}}function k(){w(),a=null}function w(){a==null||a.off(E.chapterChanged,C),e.removeAll(),s={},l=!1,c=!1}async function y({container:u}){if(!a)throw Error("need to set interactive controller");w(),h=u;let{media:v,chapter:x}=a.getCurrentChapter();if(v){a.on(E.chapterChanged,C);let{player:g,config:A}=await I({media:v,chapterId:x.id,title:x.label});return n.emit(tt.initiated,{container:u,media:v,chapterId:x.id}),{player:g,config:A}}else console.error("not found")}return{...e,on:n.on.bind(n),off:n.off.bind(n),init:y,setInteractiveController:p,createPlayer:I,removeAll:k,getActivePlayer:function(){return s}}}import{Subscription as sa}from"@vkontakte/videoplayer-shared";var $t=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEventEmitter:c,ignoreContainerEvent:a,permanentTextControls:l,disabledControls$:h,onRemove:p}){Y(this,"hide",()=>{setTimeout(()=>{var e,t;this.gameState!==j.end&&(Ie(this.container.container.events)&&this.gameState===j.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==j.interactive&&((t=(e=this.container).hide)==null||t.call(e)),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})))})});Y(this,"show",()=>{var e,t,i,n;if(this.gameState===j.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(n=(i=this.container).show)==null||n.call(i),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!0,isFirst:!1});else{let c=Bi({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})},onEvent:(a,l)=>{this.isSelectedControlEvent=!0,a!==!1&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})),(this.gameState===j.end||this.gameState===j.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),l(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1}))},isEOV:()=>this.gameState===j.end});this.container.createView(c),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((t=(e=this.container).disable)==null||t.call(e))}});Y(this,"onEndOfVideo",()=>{this.gameState=j.end,this.selectContainerEvent(!0)});Y(this,"whilePlaying",()=>{var s,c;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[j.destroyed,j.removed].includes(this.gameState)&&!this.isPermanentText)return;let t=this.player.getExactTime();if($i(t,this.container.container))this.gameState!==j.beforeInteractive&&(this.gameState=j.beforeInteractive,this.onBeforeStartTime());else if(gr(t,this.container.container))this.gameState!==j.interactive&&(this.gameState=j.interactive,this.onStartTime());else if(this.gameState!==j.afterInteractive){let a=this.gameState;this.gameState=j.afterInteractive,a===j.interactive&&this.onEndTime()}else this.gameState!==j.destroyed&&!this.isPermanentText&&this.removeView();let i=gr(t,this.container.container),n=this.container.container.startTime?[this.container.container.startTime,(c=this.container.container.endTime)!=null?c:1/0]:[];this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:n,currentTime:t,isInteractiveTime:i})});this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new sa,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=l&&Ft(t.container.controls),this.disabledControls$=h,this.onRemove=p,this.globalEventEmitter=c,this.gameState=j.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,i,n,s;e?(i=(t=this.container).disable)==null||i.call(t):(s=(n=this.container).enable)==null||s.call(n)}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=Ie(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=j.beforeInteractive}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.containerRemoved,visibility:!1}),this.gameState=j.removed,(e=this.onRemove)==null||e.call(this)}destroy(){var e;this.reset(),this.removeView(),this.gameState=j.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var Hi=(r=[])=>r.reduce((e,t,i)=>{var s,c,a;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(l=>!Vt(l));if(jt(n)){let l=[(c=t.startTime)!=null?c:0,(a=t.endTime)!=null?a:1/0],h=t.id;if(!i)e.push({subjects:[h],range:l});else{let p=[],f=-1/0,m=1/0,C=[],I=[];for(let k=0;k<e.length;k++){let w=e[k];if(I.push(...w.subjects),w.range[0]<m&&(m=w.range[0]),w.range[1]>f&&(f=w.range[1]),l[0]>=w.range[0]&&l[1]<=w.range[1])return e[k].subjects.push(h),e;l[0]<w.range[0]&&l[1]>w.range[0]&&(p.push(k),C=C.concat(w.subjects)),l[0]>=w.range[0]&&l[0]<=w.range[1]&&(p.push(k),C=C.concat(w.subjects),l[0]=w.range[0]),l[1]>=w.range[0]&&l[1]<=w.range[1]&&(p.push(k),C=C.concat(w.subjects),l[1]=w.range[1])}if(I.push(h),l[0]<=m&&l[1]>=f)return[{subjects:I,range:l}];p.length&&p.reverse().forEach(k=>{e.splice(k,1)}),e.push({subjects:C.concat([h]),range:l})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Gi(){let r={};function e(){for(let a in r)Object.prototype.hasOwnProperty.call(r,a)&&delete r[a];return!0}function t(a){let l={};for(let h in r)+h<=a&&(l[h]=r[h]);return l}function i(a){let l={};for(let h in r)+h>=a&&(l[h]=r[h]);return l}function n({timestamp:a,priority:l,initiator:h}){var p;if(hr(a)){let f=(p=r[a])!=null?p:null;if(f&&We(l,!0)){let m={},C=f[l];if(C&&(m={...m,...C}),m=xe(m)?null:m,m&&We(h,!0)){let I=m[h];return I!=null?I:null}return m}return f}return null}function s({timestamp:a,priority:l,initiator:h}){if(hr(a))if(r[a]){if(We(l,!0))if(r[a][l]){if(We(h,!0))if(r[a][l][h]){if(delete r[a][l][h],!xe(r[a][l]))return!0}else return!1;if(delete r[a][l],!xe(r[a]))return!0}else return!1;return delete r[a]}else return!1}function c({timestamp:a,priority:l,initiator:h,...p}){var f,m,C;(m=(f=r[a])==null?void 0:f[l])!=null&&m[h]?r[a][l][h].push({...p}):(C=r[a])!=null&&C[l]?r[a][l]={...r[a][l],[h]:[{...p}]}:r[a]?r[a]={...r[a],[l]:{[h]:[{...p}]}}:r[a]={[l]:{[h]:[{...p}]}}}return{map:r,remove:s,add:c,removeAll:e,get:n,getLte:t,getGte:i}}var oa=[M.expect,M.setNextBranch],aa=1/0;function Ir(r){let e=r,t,i=ca(),n=new Gi,s,c=()=>{m(),y()},a=u=>{n.add.call(void 0,u),I()},l=(u=[])=>{for(let v of u)if(v.action(),oa.includes(v.actionType))break},h=(u=1/0)=>{var A,L,P;let v=Bt((A=n.get({timestamp:u,priority:"control"}))!=null?A:{}),x=Bt((L=n.get({timestamp:u,priority:"container"}))!=null?L:{}),g=Bt((P=n.get({timestamp:u,priority:"chapter"}))!=null?P:{});return[...v,...x,...g]},p=u=>{i.isReady(u)&&l(h(u))},f=()=>{var u;l([...Bt((u=n.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},m=()=>{t&&(s==null||s.unsubscribe(),t=void 0)},C=u=>{},I=()=>{t||(t=()=>setTimeout(()=>{p(1/0)}),s=e.events.ended$.subscribe(t))},k=u=>{m(),e=u},w=u=>{u.priority==="container"&&i.resetCalled(u.timestamp),n.remove(u)},y=()=>{i.release(),n.removeAll()};return{setPlayer:k,add:a,remove:w,exec:p,execEndOfVideo:f,listen:I,unlisten:m,release:c,containersEventsCallState:i,getPreparedToExecActions:h}}function ca(){let r=new Map;return{setCalled:({timestamp:c,id:a})=>{let l=r.get(c);l&&l[a]!==void 0&&(l[a]=!0)},setData:(c=[])=>{var a,l;for(let h of c){let p=(a=h.endTime)!=null?a:aa,f=(l=r.get(p))!=null?l:{};r.set(p,{...f,[h.id]:!1})}},resetCalled:c=>{let a=r.get(c);if(a)for(let l in a)a[l]=!1},isReady:c=>{let a=r.get(c);return a?!Object.values(a).some(l=>!l):!0},release:()=>r.clear()}}function Bt(r){return Object.values(r).flat().sort(e=>e.actionType===M.expect?-1:1)}var Ui={videoContentHeight:0,videoContentWidth:0},zi=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return Ui;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return Ui;let c=t/i,a=n/s,l,h;return a>c?(h=s,l=s*c):a<c?(h=n/c,l=n):(h=s,l=n),{videoContentWidth:h,videoContentHeight:l}};var la=250;function Wi(r){let e=()=>{},t=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function i(a){let{parentElement:l,player:h}=r();if(l&&h){let{videoContentWidth:p,videoContentHeight:f}=zi(l,h);l.style.setProperty("--interactive-content-width",`${p}px`),l.style.setProperty("--interactive-content-height",`${f}px`),l.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),l.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function n(){let{parentElement:a}=r();a.removeAttribute("style")}let s=Tt(a=>{let{fns:l=[]}=r();i(a);for(let h of l)h()},la);function c(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e()},release:c}}var rt=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(i=>i!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var ha=r=>Math.floor(Math.random()*r),Ki=r=>{let e=r.length,t=1/0,i=null;for(;e--;)r[e].weight<t&&(t=r[e].weight,i=r[e]);return i},Qi=r=>{let e=r.length,t=-1/0,i=null;for(;e--;)r[e].weight>t&&(t=r[e].weight,i=r[e]);return i};var Yi=r=>{let e=r.length,t=ha(e);return r[t]};var Xi=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:1;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:1,e>=t)return r[s];return r[r.length-1]};var Zi=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var Tr=(r,e=!1)=>({...r,args:e?{...r.args,...Zi}:{...Zi,...r.args}}),wr=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},c=({action:y,controlType:u,controlId:v,containerId:x,branches:g=[],onEvent:A,isEOV:L=()=>!1,isDisabled:P=()=>!1})=>{let _=Tr(y,L()),U={timestamp:1/0,priority:"control",initiator:v,actionType:_.type},$=P(),re=r.emit.bind(r,E.interactives,{subjectId:v,subjectType:u,subjectName:"control",type:$?R.actionChoiceCanceled:R.actionChoice,actionType:y.type,payload:{containerId:x,..._.args}});if($){re();return}switch(_.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let H=g.find(pt=>pt.id===_.args.branchId);if(!H)return;A(_.args.isDetachContainer,m.bind(null,{subjectId:v,subjectName:"control"})),re(),_.args.shouldOpenNow?I({subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{chapterId:H.chapterId,autoSelect:!1}}):(t.add({...U,action:I.bind(null,{subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{chapterId:H.chapterId,autoSelect:!1}})}),i==null||i());return}case M.continuePlayback.trim().toLowerCase():{A(_.args.isDetachContainer,m.bind(null,{subjectId:v,subjectName:"control"})),re(),_.args.shouldOpenNow?C({subjectId:v,subjectName:"control",subjectType:u,action:y}):t.add({...U,action:C.bind(null,{subjectId:v,subjectName:"control",subjectType:u,action:y})});return}case M.openURI.trim().toLowerCase():{A(_.args.isDetachContainer,m.bind(null,{subjectId:v,subjectName:"control"})),re(),_.args.shouldOpenNow?w({subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{URI:y.args.uri}}):(t.add({...U,action:w.bind(null,{subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{URI:y.args.uri}})}),i==null||i());return}default:console.error("Unexpected control event"),r.emit(E.errors,new z(1,1,{message:"Unexpected control event"}));return}},a=({action:y,container:{id:u,endTime:v},branches:x=[],isEOV:g=!1,autoSelected:A=!1})=>{let L=Tr(y,g),P={timestamp:!L.args.shouldOpenNow||g?1/0:v,priority:"container",initiator:u,actionType:L.type},_=r.emit.bind(r,E.interactives,{subjectId:u,subjectName:"container",type:R.actionChoice,actionType:L.type,payload:L.args});switch(L.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let U=x.find($=>$.id===L.args.branchId);if(!U)return;_(),t.add({...P,action:I.bind(null,{subjectId:u,subjectName:"container",action:L,payload:{chapterId:U.chapterId,autoSelect:A}})}),i==null||i();return}case M.setMaxWeightBranch.trim().toLowerCase():return;case M.setMinWeightBranch.trim().toLowerCase():return;case M.setRandomBranch.trim().toLowerCase():return;case M.setWeightlessRandomBranch.trim().toLowerCase():return;case M.continuePlayback.trim().toLowerCase():{_(),t.add({...P,action:C.bind(null,{subjectId:u,subjectName:"container",action:L})});return}case M.openURI.trim().toLowerCase():{_(),t.add({...P,action:w.bind(null,{subjectId:u,subjectName:"container",action:L,payload:{URI:y.args.uri}})}),i==null||i();return}default:console.error("Unexpected container event"),r.emit(E.errors,new z(1,1,{message:"Unexpected container event"}));return}};function l({container:y,branches:u,isEOV:v=!1}){let x=br(y.events);if(x){let g=Tr(x.action,v);r.emit(E.interactives,{subjectId:y.id,subjectName:"container",type:R.actionChoice,actionType:g.type,payload:g.args}),t.add({timestamp:v?1/0:y.endTime,priority:"container",initiator:y.id,actionType:M.expect,action:f.bind(null,{subjectId:y.id,subjectName:"container"})}),n.isExpect=!0}else for(let g of y.events)a({action:g.action,container:y,branches:u,isEOV:v})}let h=({chapterId:y,action:u,branches:v=[]})=>{let x=r.emit.bind(r,E.interactives,{subjectId:y,subjectName:"chapter",type:R.actionChoice,actionType:u.type,payload:u.args});switch(u.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let g=v.find(A=>A.id===u.args.branchId);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setWeightlessRandomBranch.trim().toLowerCase():{let g=Yi(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setRandomBranch.trim().toLowerCase():{let g=Xi(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setMaxWeightBranch.trim().toLowerCase():{let g=Qi(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setMinWeightBranch.trim().toLowerCase():{let g=Ki(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.continuePlayback.trim().toLowerCase():return x(),C.bind(null,{subjectId:y,subjectName:"chapter",action:u});case M.openURI.trim().toLowerCase():return x(),w.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:console.error("Unexpected chapter event"),r.emit(E.errors,new z(1,1,{message:"Unexpected chapter event"}));return}};function p(y){let u=br(y.events);if(u){if(ie(y))return;r.emit(E.interactives,{subjectId:y.id,subjectName:"chapter",type:R.actionChoice,actionType:u.action.type,payload:u.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:M.expect,action:f.bind(null,{subjectId:y.id,subjectName:"chapter"})})}else y.events.forEach(v=>{let x=h({chapterId:y.id,action:v.action,branches:y.branches});x&&t.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:v.action.type,action:x})})}let f=({subjectId:y,subjectName:u,action:v})=>{var x;e.pause(),r.emit(E.interactives,{subjectId:y,subjectName:u,type:R.actionExecution,actionType:(x=v==null?void 0:v.type)!=null?x:M.expect})},m=({subjectId:y,subjectName:u})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(E.interactives,{subjectId:y,subjectName:u,type:R.actionExecution,actionType:"after-expect"})},C=({subjectId:y,subjectName:u,subjectType:v,action:x})=>{r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type})},I=({subjectId:y,subjectName:u,subjectType:v,action:x,payload:g})=>{g.behaviour="change-chapter",r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type,payload:g})},k=({subjectId:y,subjectName:u,subjectType:v,action:x,payload:g})=>{g.behaviour="change-manifest",r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type,payload:g})},w=({subjectId:y,subjectName:u,subjectType:v,action:x,payload:g})=>{if(!g.URI)return;let A=window.open(g.URI,"_blank","noopener,noreferrer");A&&(A.opener=null),r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type})};return{onControlEvent:c,onContainerEvent:a,onChapterEvent:h,onExpectEvent:f,expectEventHandler:m,setManifestChapterEvents:p,setManifestContainerEvents:l,stopExpect:s,state:n}};var si=No(mo(),1);import{Subscription as Al,ValueSubject as ct}from"@vkontakte/videoplayer-shared";var ni=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(c=>c.id===i);if(!n)return null;let s=e.media.videos.find(c=>n.videoId===c.id);if(!s)return null;t[i]=yo(s)}return t[i]}).filter(Boolean)},_l=r=>{for(let e of r.variants)if(Rl(e)&&"payload"in e)return e.payload.id},Rl=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",yo=r=>{let e=_l(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},Vl=(r,e)=>{for(let t of r.media.videos)if(e===yo(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},vo=(r,e)=>r.reduce((t,i)=>{let n=Vl(e,i);return n?[...t,n]:t},[]);var ne,we,Se,X,zt,se,oe,J,_e,qe,De,lt=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new ct([]),hasPrevChapter$:new ct(!1),prevChapter$:new ct(null),isInitialChapter$:new ct(!1),isGoBackLimited$:new ct(!1)};T(this,ne,null);T(this,we);T(this,Se,!1);T(this,X,null);T(this,zt,null);T(this,se,null);T(this,oe,null);T(this,J,null);T(this,_e,new Al);T(this,qe,!1);T(this,De,0);var c,a,l;b(this,se,t),b(this,J,e),b(this,oe,i),b(this,ne,n),b(this,we,s),(c=this.state)!=null&&c.history$&&o(this,_e)&&((l=o(this,_e))==null||l.add((a=this.state)==null?void 0:a.history$.subscribe(h=>{var p,f,m,C,I,k;(p=this.state)==null||p.prevChapter$.next((0,si.default)(h,-2)||null),(f=this.state)==null||f.hasPrevChapter$.next(h.length>1),(I=this.state)==null||I.isInitialChapter$.next(this.getInitialChapterId()===((C=(m=o(this,X))==null?void 0:m.metadata)==null?void 0:C.initChapterId)),(k=this.state)==null||k.isGoBackLimited$.next(o(this,De)===o(this,we).maxLength-1)})))}async setManifest(e){!o(this,oe)||!o(this,J)||(b(this,X,e),await this.getProjectHistory(),await o(this,oe).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),o(this,Se)||(b(this,Se,!0),o(this,J).emit(E.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return o(this,Se)}async updateHistory(e,t=!0){var a,l;if(!o(this,X))return;o(this,qe)?(b(this,qe,!1),vi(this,De)._++):b(this,De,0);let i=o(this,X),n=e.length-o(this,we).maxLength,s=n>0?e.slice(n):e,c=ni(s,i);if(b(this,zt,c),(a=this==null?void 0:this.state)==null||a.history$.next(s),!(!t||!o(this,ne)||!o(this,se)))try{await o(this,ne).save(o(this,se),c)}catch(h){(l=o(this,J))==null||l.emit(E.errors,new z(1,5,"Unable to save interactive history"))}}async goBack(){var i;if(!this.state||!o(this,oe))return(i=o(this,J))==null?void 0:i.emit(E.errors,new z(1,5,"Cannot go back because HistoryController has not been initialized"));b(this,qe,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await o(this,oe).setChapter({chapterId:t})}async getProjectHistory(){var n,s;if(!o(this,X)||!o(this,se))return;let e=o(this,X),t=[this.getInitialVideoId()];if(o(this,ne))try{let c=await o(this,ne).get(o(this,se));c.length&&(t=c)}catch(c){(n=o(this,J))==null||n.emit(E.errors,new z(1,5,"Error while trying to fetch data"))}let i=vo(t,e);(s=this==null?void 0:this.state)==null||s.history$.next(i)}getInitialChapterId(){var t,i;let e=(t=this.state)==null?void 0:t.history$.getValue();return(0,si.default)(e,-1)||o(this,we).initChapterId||((i=o(this,X))==null?void 0:i.metadata.initChapterId)}getInitialVideoId(){if(o(this,X)){let e=this.getInitialChapterId();return ni([e],o(this,X)).pop()}return null}destroy(){var e,t;this.state=null,b(this,se,null),b(this,ne,null),b(this,oe,null),(e=o(this,_e))==null||e.unsubscribe(),b(this,_e,null),b(this,Se,!1),(t=o(this,J))==null||t.emit(E.historyDestroyed),b(this,J,null)}};ne=new WeakMap,we=new WeakMap,Se=new WeakMap,X=new WeakMap,zt=new WeakMap,se=new WeakMap,oe=new WeakMap,J=new WeakMap,_e=new WeakMap,qe=new WeakMap,De=new WeakMap;var Re=class Re{constructor(e,t,i,n){this.target=e,this.type=t,this.listener=i,this.options=Re._convertOptions(e,n),this.target.addEventListener(t,i,this.options)}unlisten(){var e;this.type&&this.listener&&this.options&&((e=this.target)==null||e.removeEventListener(this.type,this.listener,this.options)),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let i=new Set(["passive","capture"]),n=Object.keys(t).filter(c=>!i.has(c));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),Re._doesSupportObject(e)?t:t.capture||!1}}static _doesSupportObject(e){let t=Re._supportsObject;if(t===void 0){t=!1;try{let i={},n={get:()=>(t=!0,!1)};Object.defineProperty(i,"passive",n),Object.defineProperty(i,"capture",n);let s=()=>{};e.addEventListener("test",s,i),e.removeEventListener("test",s,i)}catch(i){t=!1}Re._supportsObject=t}return t||!1}};Re._supportsObject=void 0;var Wt=Re;var Kt=class{constructor(){this.bindingMap=new rt}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new Wt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=c=>{this.unlisten(e,t,s),i(c)};this.listen(e,t,s,n)}unlisten(e,t,i){if(!this.bindingMap)return;let n=this.bindingMap.get(t)||[];for(let s of n)s.target===e&&(i===s.listener||!i)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var Qt=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var n;let e=(n=this.rootElement.getContext("2d"))==null?void 0:n.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,i=t.length;for(let s=3;s<i;s+=40)if(t[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(e,t=!1){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var Yt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)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
|
+
var _a=Object.create;var tr=Object.defineProperty;var Ra=Object.getOwnPropertyDescriptor;var Va=Object.getOwnPropertyNames;var Aa=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var yi=r=>{throw TypeError(r)};var La=(r,e,t)=>e in r?tr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var d=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Oa=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Va(e))!Ma.call(r,n)&&n!==t&&tr(r,n,{get:()=>e[n],enumerable:!(i=Ra(e,n))||i.enumerable});return r};var Pa=(r,e,t)=>(t=r!=null?_a(Aa(r)):{},Oa(e||!r||!r.__esModule?tr(t,"default",{value:r,enumerable:!0}):t,r));var Y=(r,e,t)=>La(r,typeof e!="symbol"?e+"":e,t),rr=(r,e,t)=>e.has(r)||yi("Cannot "+t);var a=(r,e,t)=>(rr(r,e,"read from private field"),t?t.call(r):e.get(r)),T=(r,e,t)=>e.has(r)?yi("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),b=(r,e,t,i)=>(rr(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t),N=(r,e,t)=>(rr(r,e,"access private method"),t);var vi=(r,e,t,i)=>({set _(n){b(r,e,n,t)},get _(){return a(r,e,i)}});var ee=d((Sr,tn)=>{"use strict";var it=function(r){return r&&r.Math===Math&&r};tn.exports=it(typeof globalThis=="object"&&globalThis)||it(typeof window=="object"&&window)||it(typeof self=="object"&&self)||it(typeof global=="object"&&global)||it(typeof Sr=="object"&&Sr)||function(){return this}()||Function("return this")()});var fe=d((Rp,rn)=>{"use strict";rn.exports=function(r){try{return!!r()}catch(e){return!0}}});var nt=d((Vp,nn)=>{"use strict";var po=fe();nn.exports=!po(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var ln=d((Ap,cn)=>{"use strict";var fo=nt(),on=Function.prototype,sn=on.apply,an=on.call;cn.exports=typeof Reflect=="object"&&Reflect.apply||(fo?an.bind(sn):function(){return an.apply(sn,arguments)})});var Te=d((Mp,pn)=>{"use strict";var hn=nt(),un=Function.prototype,_r=un.call,mo=hn&&un.bind.bind(_r,_r);pn.exports=hn?mo:function(r){return function(){return _r.apply(r,arguments)}}});var Rr=d((Lp,fn)=>{"use strict";var dn=Te(),yo=dn({}.toString),vo=dn("".slice);fn.exports=function(r){return vo(yo(r),8,-1)}});var Vr=d((Op,mn)=>{"use strict";var go=Rr(),bo=Te();mn.exports=function(r){if(go(r)==="Function")return bo(r)}});var me=d((Pp,yn)=>{"use strict";var Ar=typeof document=="object"&&document.all;yn.exports=typeof Ar=="undefined"&&Ar!==void 0?function(r){return typeof r=="function"||r===Ar}:function(r){return typeof r=="function"}});var ke=d((Np,vn)=>{"use strict";var Eo=fe();vn.exports=!Eo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Dt=d((jp,gn)=>{"use strict";var Co=nt(),qt=Function.prototype.call;gn.exports=Co?qt.bind(qt):function(){return qt.apply(qt,arguments)}});var xn=d(Cn=>{"use strict";var bn={}.propertyIsEnumerable,En=Object.getOwnPropertyDescriptor,xo=En&&!bn.call({1:2},1);Cn.f=xo?function(e){var t=En(this,e);return!!t&&t.enumerable}:bn});var Mr=d((Fp,In)=>{"use strict";In.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var wn=d(($p,Tn)=>{"use strict";var Io=Te(),To=fe(),wo=Rr(),Lr=Object,So=Io("".split);Tn.exports=To(function(){return!Lr("z").propertyIsEnumerable(0)})?function(r){return wo(r)==="String"?So(r,""):Lr(r)}:Lr});var Or=d((Bp,Sn)=>{"use strict";Sn.exports=function(r){return r==null}});var Pr=d((qp,_n)=>{"use strict";var _o=Or(),Ro=TypeError;_n.exports=function(r){if(_o(r))throw new Ro("Can't call method on "+r);return r}});var Vn=d((Dp,Rn)=>{"use strict";var Vo=wn(),Ao=Pr();Rn.exports=function(r){return Vo(Ao(r))}});var st=d((Hp,An)=>{"use strict";var Mo=me();An.exports=function(r){return typeof r=="object"?r!==null:Mo(r)}});var Nr=d((Gp,Mn)=>{"use strict";Mn.exports={}});var Fr=d((Up,On)=>{"use strict";var jr=Nr(),kr=ee(),Lo=me(),Ln=function(r){return Lo(r)?r:void 0};On.exports=function(r,e){return arguments.length<2?Ln(jr[r])||Ln(kr[r]):jr[r]&&jr[r][e]||kr[r]&&kr[r][e]}});var Nn=d((zp,Pn)=>{"use strict";var Oo=Te();Pn.exports=Oo({}.isPrototypeOf)});var $n=d((Wp,Fn)=>{"use strict";var Po=ee(),jn=Po.navigator,kn=jn&&jn.userAgent;Fn.exports=kn?String(kn):""});var zn=d((Kp,Un)=>{"use strict";var Gn=ee(),$r=$n(),Bn=Gn.process,qn=Gn.Deno,Dn=Bn&&Bn.versions||qn&&qn.version,Hn=Dn&&Dn.v8,Z,Ht;Hn&&(Z=Hn.split("."),Ht=Z[0]>0&&Z[0]<4?1:+(Z[0]+Z[1]));!Ht&&$r&&(Z=$r.match(/Edge\/(\d+)/),(!Z||Z[1]>=74)&&(Z=$r.match(/Chrome\/(\d+)/),Z&&(Ht=+Z[1])));Un.exports=Ht});var Br=d((Qp,Kn)=>{"use strict";var Wn=zn(),No=fe(),jo=ee(),ko=jo.String;Kn.exports=!!Object.getOwnPropertySymbols&&!No(function(){var r=Symbol("symbol detection");return!ko(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Wn&&Wn<41})});var qr=d((Yp,Qn)=>{"use strict";var Fo=Br();Qn.exports=Fo&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Dr=d((Xp,Yn)=>{"use strict";var $o=Fr(),Bo=me(),qo=Nn(),Do=qr(),Ho=Object;Yn.exports=Do?function(r){return typeof r=="symbol"}:function(r){var e=$o("Symbol");return Bo(e)&&qo(e.prototype,Ho(r))}});var Zn=d((Zp,Xn)=>{"use strict";var Go=String;Xn.exports=function(r){try{return Go(r)}catch(e){return"Object"}}});var Hr=d((Jp,Jn)=>{"use strict";var Uo=me(),zo=Zn(),Wo=TypeError;Jn.exports=function(r){if(Uo(r))return r;throw new Wo(zo(r)+" is not a function")}});var ts=d((ed,es)=>{"use strict";var Ko=Hr(),Qo=Or();es.exports=function(r,e){var t=r[e];return Qo(t)?void 0:Ko(t)}});var is=d((td,rs)=>{"use strict";var Gr=Dt(),Ur=me(),zr=st(),Yo=TypeError;rs.exports=function(r,e){var t,i;if(e==="string"&&Ur(t=r.toString)&&!zr(i=Gr(t,r))||Ur(t=r.valueOf)&&!zr(i=Gr(t,r))||e!=="string"&&Ur(t=r.toString)&&!zr(i=Gr(t,r)))return i;throw new Yo("Can't convert object to primitive value")}});var ss=d((rd,ns)=>{"use strict";ns.exports=!0});var cs=d((id,os)=>{"use strict";var as=ee(),Xo=Object.defineProperty;os.exports=function(r,e){try{Xo(as,r,{value:e,configurable:!0,writable:!0})}catch(t){as[r]=e}return e}});var Wr=d((nd,us)=>{"use strict";var Zo=ss(),Jo=ee(),ec=cs(),ls="__core-js_shared__",hs=us.exports=Jo[ls]||ec(ls,{});(hs.versions||(hs.versions=[])).push({version:"3.38.0",mode:Zo?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var fs=d((sd,ds)=>{"use strict";var ps=Wr();ds.exports=function(r,e){return ps[r]||(ps[r]=e||{})}});var Kr=d((ad,ms)=>{"use strict";var tc=Pr(),rc=Object;ms.exports=function(r){return rc(tc(r))}});var Gt=d((od,ys)=>{"use strict";var ic=Te(),nc=Kr(),sc=ic({}.hasOwnProperty);ys.exports=Object.hasOwn||function(e,t){return sc(nc(e),t)}});var gs=d((cd,vs)=>{"use strict";var ac=Te(),oc=0,cc=Math.random(),lc=ac(1 .toString);vs.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+lc(++oc+cc,36)}});var Cs=d((ld,Es)=>{"use strict";var hc=ee(),uc=fs(),bs=Gt(),pc=gs(),dc=Br(),fc=qr(),Fe=hc.Symbol,Qr=uc("wks"),mc=fc?Fe.for||Fe:Fe&&Fe.withoutSetter||pc;Es.exports=function(r){return bs(Qr,r)||(Qr[r]=dc&&bs(Fe,r)?Fe[r]:mc("Symbol."+r)),Qr[r]}});var ws=d((hd,Ts)=>{"use strict";var yc=Dt(),xs=st(),Is=Dr(),vc=ts(),gc=is(),bc=Cs(),Ec=TypeError,Cc=bc("toPrimitive");Ts.exports=function(r,e){if(!xs(r)||Is(r))return r;var t=vc(r,Cc),i;if(t){if(e===void 0&&(e="default"),i=yc(t,r,e),!xs(i)||Is(i))return i;throw new Ec("Can't convert object to primitive value")}return e===void 0&&(e="number"),gc(r,e)}});var Yr=d((ud,Ss)=>{"use strict";var xc=ws(),Ic=Dr();Ss.exports=function(r){var e=xc(r,"string");return Ic(e)?e:e+""}});var Vs=d((pd,Rs)=>{"use strict";var Tc=ee(),_s=st(),Xr=Tc.document,wc=_s(Xr)&&_s(Xr.createElement);Rs.exports=function(r){return wc?Xr.createElement(r):{}}});var Zr=d((dd,As)=>{"use strict";var Sc=ke(),_c=fe(),Rc=Vs();As.exports=!Sc&&!_c(function(){return Object.defineProperty(Rc("div"),"a",{get:function(){return 7}}).a!==7})});var Os=d(Ls=>{"use strict";var Vc=ke(),Ac=Dt(),Mc=xn(),Lc=Mr(),Oc=Vn(),Pc=Yr(),Nc=Gt(),jc=Zr(),Ms=Object.getOwnPropertyDescriptor;Ls.f=Vc?Ms:function(e,t){if(e=Oc(e),t=Pc(t),jc)try{return Ms(e,t)}catch(i){}if(Nc(e,t))return Lc(!Ac(Mc.f,e,t),e[t])}});var Ns=d((md,Ps)=>{"use strict";var kc=fe(),Fc=me(),$c=/#|\.prototype\./,at=function(r,e){var t=qc[Bc(r)];return t===Hc?!0:t===Dc?!1:Fc(e)?kc(e):!!e},Bc=at.normalize=function(r){return String(r).replace($c,".").toLowerCase()},qc=at.data={},Dc=at.NATIVE="N",Hc=at.POLYFILL="P";Ps.exports=at});var Fs=d((yd,ks)=>{"use strict";var js=Vr(),Gc=Hr(),Uc=nt(),zc=js(js.bind);ks.exports=function(r,e){return Gc(r),e===void 0?r:Uc?zc(r,e):function(){return r.apply(e,arguments)}}});var Bs=d((vd,$s)=>{"use strict";var Wc=ke(),Kc=fe();$s.exports=Wc&&Kc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Ds=d((gd,qs)=>{"use strict";var Qc=st(),Yc=String,Xc=TypeError;qs.exports=function(r){if(Qc(r))return r;throw new Xc(Yc(r)+" is not an object")}});var Us=d(Gs=>{"use strict";var Zc=ke(),Jc=Zr(),el=Bs(),Ut=Ds(),Hs=Yr(),tl=TypeError,Jr=Object.defineProperty,rl=Object.getOwnPropertyDescriptor,ei="enumerable",ti="configurable",ri="writable";Gs.f=Zc?el?function(e,t,i){if(Ut(e),t=Hs(t),Ut(i),typeof e=="function"&&t==="prototype"&&"value"in i&&ri in i&&!i[ri]){var n=rl(e,t);n&&n[ri]&&(e[t]=i.value,i={configurable:ti in i?i[ti]:n[ti],enumerable:ei in i?i[ei]:n[ei],writable:!1})}return Jr(e,t,i)}:Jr:function(e,t,i){if(Ut(e),t=Hs(t),Ut(i),Jc)try{return Jr(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new tl("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Ws=d((Ed,zs)=>{"use strict";var il=ke(),nl=Us(),sl=Mr();zs.exports=il?function(r,e,t){return nl.f(r,e,sl(1,t))}:function(r,e,t){return r[e]=t,r}});var Ys=d((Cd,Qs)=>{"use strict";var ot=ee(),al=ln(),ol=Vr(),cl=me(),ll=Os().f,hl=Ns(),$e=Nr(),ul=Fs(),Be=Ws(),Ks=Gt();Wr();var pl=function(r){var e=function(t,i,n){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,i)}return new r(t,i,n)}return al(r,this,arguments)};return e.prototype=r.prototype,e};Qs.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,s=r.proto,c=i?ot:n?ot[t]:ot[t]&&ot[t].prototype,o=i?$e:$e[t]||Be($e,t,{})[t],l=o.prototype,h,p,f,m,C,I,k,w,y;for(m in e)h=hl(i?m:t+(n?".":"#")+m,r.forced),p=!h&&c&&Ks(c,m),I=o[m],p&&(r.dontCallGetSet?(y=ll(c,m),k=y&&y.value):k=c[m]),C=p&&k?k:e[m],!(!h&&!s&&typeof I==typeof C)&&(r.bind&&p?w=ul(C,ot):r.wrap&&p?w=pl(C):s&&cl(C)?w=ol(C):w=C,(r.sham||C&&C.sham||I&&I.sham)&&Be(w,"sham",!0),Be(o,m,w),s&&(f=t+"Prototype",Ks($e,f)||Be($e,f,{}),Be($e[f],m,C),r.real&&l&&(h||!l[m])&&Be(l,m,C)))}});var Zs=d((xd,Xs)=>{"use strict";var dl=Math.ceil,fl=Math.floor;Xs.exports=Math.trunc||function(e){var t=+e;return(t>0?fl:dl)(t)}});var ii=d((Id,Js)=>{"use strict";var ml=Zs();Js.exports=function(r){var e=+r;return e!==e||e===0?0:ml(e)}});var ta=d((Td,ea)=>{"use strict";var yl=ii(),vl=Math.min;ea.exports=function(r){var e=yl(r);return e>0?vl(e,9007199254740991):0}});var ia=d((wd,ra)=>{"use strict";var gl=ta();ra.exports=function(r){return gl(r.length)}});var sa=d((Sd,na)=>{"use strict";na.exports=function(){}});var aa=d(()=>{"use strict";var bl=Ys(),El=Kr(),Cl=ia(),xl=ii(),Il=sa();bl({target:"Array",proto:!0},{at:function(e){var t=El(this),i=Cl(t),n=xl(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});Il("at")});var ca=d((Vd,oa)=>{"use strict";var Tl=Fr();oa.exports=Tl});var ha=d((Ad,la)=>{"use strict";aa();var wl=ca();la.exports=wl("Array","at")});var pa=d((Md,ua)=>{"use strict";var Sl=ha();ua.exports=Sl});var fa=d((Ld,da)=>{"use strict";var _l=pa();da.exports=_l});var gi="1.0.16-dev.fce168eb.0";function ir(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var B="SDK_NAME",Na="SDK_NAME-controls-container",ft=()=>document.querySelector(`.${Na}`),xi=.4,W={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},bi={top:"flex-start",bottom:"flex-end",center:"center"},Ei={start:"flex-start",end:"flex-end",center:"center"},Ci={start:"left",end:"right",center:"center"},mt=({target:r,props:e})=>{var t,i,n,s,c,o;r.style.alignItems=(i=bi[(t=e==null?void 0:e.text)==null?void 0:t.gravityVertical])!=null?i:bi.center,r.style.justifyContent=(s=Ei[(n=e==null?void 0:e.text)==null?void 0:n.gravityHorizontal])!=null?s:Ei.center,r.style.textAlign=(o=Ci[(c=e==null?void 0:e.text)==null?void 0:c.alignment])!=null?o:Ci.start},yt=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,c,o,l,h;r.style.color=(s=(n=e==null?void 0:e.text)==null?void 0:n.color)!=null?s:t.textColor,r.style.fontSize=`calc(${i.height} * ${(o=(c=e==null?void 0:e.text)==null?void 0:c.size)!=null?o:t.textSize})`,r.textContent=(h=(l=e==null?void 0:e.text)==null?void 0:l.value)!=null?h:t.textContent},vt=({target:r,props:e,fallback:t})=>{var i,n,s,c;r.style.backgroundColor=ir((n=(i=e==null?void 0:e.background)==null?void 0:i.color)!=null?n:t.backgroundColor,(c=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?c:t.backgroundAlpha)},gt=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,c,o,l,h,p,f,m,C,I;r.style.border=`calc(${i.height} * ${(c=(s=(n=e==null?void 0:e.shape)==null?void 0:n.border)==null?void 0:s.width)!=null?c:t.borderWidth}) solid ${ir((h=(l=(o=e==null?void 0:e.shape)==null?void 0:o.border)==null?void 0:l.color)!=null?h:t.borderColor,(m=(f=(p=e==null?void 0:e.shape)==null?void 0:p.border)==null?void 0:f.alpha)!=null?m:t.borderAlpha)}`,r.style.borderRadius=`calc(${i.height} * ${(I=(C=e==null?void 0:e.shape)==null?void 0:C.roundCorners)!=null?I:t.roundCorners})`},Me=({target:r,layoutParams:e,fallback:t})=>{r.style.transform=`rotate(${-e.angle}rad)`};var nr="int",Le={AREA:`${nr}_area`,TEXT:`${nr}_text`,BUTTON:`${nr}_bttn`};var ue=class{constructor(e){this.control=e}createView(e){var n;let t=document.createElement("div");t.classList.add(`${B}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let i=((n=this.control.layoutParams.innerSizesDependOn)!=null?n:W.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:t,dependsOn:i}}setEvents(e,t){e&&this.control.events.forEach(i=>{switch(i.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",s=>{s.stopPropagation(),t&&t({action:i.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${B}-control-container-${this.control.id}`)}};var bt=r=>{if(r.type.trim().toLowerCase()==="area")return new sr(r)},sr=class extends ue{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("button");return s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",Le.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",vt({target:s,props:this.control.props,fallback:{...W,backgroundColor:"transparent"}}),gt({target:s,props:this.control.props,fallback:{...W,borderAlpha:0},dependsOn:i}),Me({target:s,layoutParams:this.control.layoutParams,fallback:W}),n.append(s),e.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(`.${B}-${this.control.id}`)}};var Et=()=>{let r=document.createElement("span");return r.style.display="inline-block",r.style.whiteSpace="pre",r.style.overflow="hidden",r.style.textOverflow="ellipsis",r.style.maxWidth="100%",r.style.maxHeight="100%",r};var Ct=r=>{if(r.type.trim().toLowerCase()==="button")return new ar(r)},ar=class extends ue{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("button");s.type="button",s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",Le.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let c=Et();return Me({target:s,layoutParams:this.control.layoutParams,fallback:W}),vt({target:s,props:this.control.props,fallback:W}),gt({target:s,props:this.control.props,fallback:W,dependsOn:i}),mt({target:s,props:this.control.props}),yt({target:c,props:this.control.props,fallback:W,dependsOn:i}),s.append(c),n.append(s),e.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(`.${B}-${this.control.id}`)}};var Ii=r=>{if(r.type.trim().toLowerCase()==="text")return new or(r)},or=class extends ue{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("div");s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",Le.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let c=Et();return Me({target:s,layoutParams:this.control.layoutParams,fallback:W}),mt({target:s,props:this.control.props}),yt({target:c,props:this.control.props,fallback:W,dependsOn:i}),s.append(c),n.append(s),e.append(n),this.controlEl=s,n}disable(){}enable(){}getElement(){return document.querySelector(`.${B}-${this.control.id}`)}};var cr=class{constructor(e){this.layout=e}},Ti=r=>{if(r.type.trim().toLowerCase()==="relative")return new Ue(r)},Ue=class extends cr{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var pe,xt,wi,Oe=class{constructor(e){T(this,pe);this.container=e,this.factories=new Map,N(this,pe,xt).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),N(this,pe,xt).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),N(this,pe,xt).call(this)}};pe=new WeakSet,xt=function(){this.controls=N(this,pe,wi).call(this)},wi=function(){var e;return(e=this.container.controls)==null?void 0:e.reduce((t,i)=>{let n=i.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...t,s(i)]:[...t]},[])};var It=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new lr(r,e)},lr=class extends Oe{constructor(e,t){super(e),this.rootElement=t!=null?t:ft(),this.layout=new Ue(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Ct),this.addControlFactory("text",Ii),this.addControlFactory("area",bt)}createView(e){let t=document.createElement("div");return t.classList.add(`${B}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(i=>{let n=i.createView({parent:t,layoutFn:this.layout.setControlLayout});i.setEvents(n,e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity=1,this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=xi,this.isDisabled=!0)}removeView(){var e;this.isRemoved||((e=this.getElement())==null||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${B}-${this.container.id}`)}};import{Subject as Ll,ValueSubject as te,Observable as ga,once as Ol,Subscription as Pl,clientChecker as Nl,combine as jl}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as ja}from"@vkontakte/videoplayer-shared";function Tt(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var Ce=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,ze=r=>Ce(r,"Object"),wt=r=>Ce(r,"String"),St=r=>Ce(r,"Array"),_t=r=>Ce(r,"Number"),Si=r=>Ce(r,"Function");var hr=r=>_t(r)&&!isNaN(r);var xe=r=>ze(r)&&Object.keys(r).length===0,ur=r=>St(r)&&!r.length;var We=(r,e)=>wt(r)&&(e?r.trim():r).length;var _i="video_interactive",Ri="videoint";var ka=250,Ke=class{constructor(e){Y(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}))});Y(this,"handleChapterChange",e=>{var t;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.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}});Y(this,"handleManifestChange",async(e,t=[])=>{var i;if(!_t(e.graph.edit.chapters[0].x)){this.isReady=!1,(i=this.onError)==null||i.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let n;try{n=await ja(this.lang,_i,Ri)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:s}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new s(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:n}),this.ngEditor.on("control",({name:c,chapterId:o})=>{c==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo={...c}})}this.visitedChapterIds=new Set(t),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0});this.init(e)}init({root:e,onOpenPreviewClick:t,onError:i,lang:n,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=i,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=Fa(e),this.resizeObserver=new ResizeObserver(Tt(this.onResize,ka)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor.updateVideosInfo(e)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Fa(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var Qe=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let c=s.startTime-e;if(c<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<c&&(t=t===-1?c:Math.min(t,c))}return!i&&t!==-1?t:null}}};var de=(r="",e="")=>{let t=r.split("."),i=e.split("."),n=0;for(let s=0;s<Math.max(t.length,i.length)&&!n;s++)t[s]>i[s]?n=1:t[s]<i[s]?n=-1:n=0;return n};import{v4 as $a}from"uuid";var Ba="3.1",Vi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},qa={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ai=r=>{let e=[];for(let t of r.chapters){let i,n=[];for(let{isDefault:o,...l}of t.branches)o&&(i=l.id),n.push(l);let s=[],c=[];for(let{fallbackStrategy:o,...l}of t.containers){let h=!!l.endTime,p=[qa];switch(o){case"await":h?p=[]:s=[];break;case"default":{let f={type:"onSuspense",action:{type:Vi.default,args:{branchId:i,shouldOpenNow:!h,isDetachContainer:!0}}};h?p=[f]:s=[f];break}case"random":case"weightlessRandom":case"max":case"min":{let f={type:"onSuspense",action:{type:Vi[o],args:{}}};h?p=[f]:s=[f];break}}for(let f of l.controls)c.push({...l,controls:[{...f}],id:$a(),events:p})}e.push({...t,containers:c,events:s,branches:n})}return r.metadata.version=Ba,r.metadata.updated=new Date().toISOString(),{...r,chapters:e}};var Da="3.2",Mi=r=>{if(!r.media){let{media:e,...t}=r.metadata;return{...r,metadata:{...t,version:Da},media:e}}return r};var Ha="3.3",Ga=(r=[])=>({edit:{chapters:r},view:{}}),Li={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Oi=r=>{var i;let e=[],t=[];for(let n of r.chapters){let{id:s,x:c,y:o,...l}=n,h=l.containers.map(p=>{var f;return{...p,controls:p.controls.map(({subtype:m,type:C,...I})=>({...I,type:m!=null?m:C})),events:(f=p.events)!=null&&f.length?p.events:[Li]}});e.push({id:s,...l,containers:h,events:(i=l.events)!=null&&i.length?l.events:[Li]}),t.push({id:s,x:c,y:o})}return{...r,chapters:e,graph:Ga(t),metadata:{...r.metadata,version:Ha}}};var Ua=[{version:"3.0",migrate:Ai},{version:"3.1",migrate:Mi},{version:"3.2",migrate:Oi}],pr=r=>Ua.reduce((e,t)=>de(e.metadata.version,t.version)?e:t.migrate(e),r);var Xh=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Pi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Zh=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),M=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),dr=(s=>(s.GO_NEXT_BUTTON="GO_NEXT_BUTTON",s.GO_NEXT_AREA="GO_NEXT_AREA",s.WATCH_AGAIN="WATCH_AGAIN",s.OPEN_GRAPH="OPEN_GRAPH",s.CLOSE_GRAPH="CLOSE_GRAPH",s))(dr||{});var Ni={metadata:"Object",chapters:"Array"},za="3.0.0",Wa="3.3.0",Rt=r=>{let e=de(r,za);return e===-1?!1:e===0?!0:de(r,Wa)!==1},ji=r=>{if(!ze(r))return!1;for(let e in Ni)if(!r[e]||!Ce(r[e],Ni[e]))return!1;return Rt(r.metadata.version)},Vt=r=>r.type===Pi.Text;var z=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Pe=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let i=()=>{t(),this.off(e,i)};return this.listeners[e].push(i),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let i=this.listeners[e]||[];for(let n=i.length;n>0;n--)if(i[n]===t){i.splice(n,1);break}return this}emit(e,...t){let i=this.listeners[e];return i?(i.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var At=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{Si(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(i=>i!==e),t&&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=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};this.fn=e,this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as eo}from"@vkontakte/videoplayer-shared";var Mt=class{constructor(e){var t,i;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(i=e==null?void 0:e.manifestLoaders)!=null?i:[]}}async exec(e,t){return Ka(...this.loaders[e])(t)}};function Ka(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function Ye(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function Lt({actions:r,errors:e,chapterId:t,...i}){if(t){let n=r.getManifest(),s=r.getChapter(n.chapters,t);if(s){let c=r.getMedia(n.media,s.videoId),o=r.getGraph(n.graph,s.id);return c?{...i,actions:r,errors:e,result:{chapter:s,media:c,graph:o}}:{...i,errors:Ye(e,Lt.name,"Could not find media"),actions:r}}}return{...i,errors:Ye(e,Lt.name,"Could not find chapter"),actions:r}}var Ot=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,s=i.length;n<s;n++)if(i[n].callback===t){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,s=i.length;n<s;n++){let c=i[n];try{c.callback.call(this,e)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(e.type,c.callback)}return!e.defaultPrevented}},Ne=class extends Ot{constructor(){super(),this.listeners||Ot.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Xe=class{constructor(){Object.defineProperty(this,"signal",{value:new Ne,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(n){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document=="undefined")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch(n){i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(Xe.prototype[Symbol.toStringTag]="AbortController",Ne.prototype[Symbol.toStringTag]="AbortSignal");function Pt(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function fr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!Pt({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||n)&&(s=function(h,p){let f;p&&p.signal&&(f=p.signal,delete p.signal);let m=new t(h,p);return f&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),m},s.prototype=t.prototype);let c=e;return{fetch:(l,h)=>{let p=s&&s.prototype.isPrototypeOf(l)?l.signal:h?h.signal:void 0;if(p){let f;try{f=new DOMException("Aborted","AbortError")}catch(C){f=new Error("Aborted"),f.name="AbortError"}if(p.aborted)return Promise.reject(f);let m=new Promise((C,I)=>{p.addEventListener("abort",()=>I(f),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([m,c(l,h)])}return c(l,h)},Request:s}}var Ze=Pt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),ki=Ze?fr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,mr=Ze?ki.fetch:window.fetch,Tu=Ze?ki.Request:window.Request,wu=Ze?Xe:window.AbortController,Su=Ze?Ne:window.AbortSignal;var Qa=async r=>{try{let e={},t;if(wt(r)){t=new URL(r).href;let n=await mr(t);if(!n.ok)return{};e=await n.json()}else if(ze(r))e=r;else return{};if(!ji(e))return{};let i=e.metadata.media;if(wt(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=await mr(n);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch(n){return Za(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Fi(r){let{manifest:e,manifestURL:t}=await Qa(r),i=pr(e);return i.media=Ya(i.media,t),delete i.metadata.media,i}function Nt(r,e){if(e)return r.find(t=>t.id===e)}function yr(r,e){var t,i;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(n=>n.id===e):(i=r.view)!=null&&i.chapters?r.view.chapters.find(n=>n.id===e):void 0}function vr(r,e){return r.videos.find(t=>t.id===e)}function Ya(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=Xa(n,e);return{...i,url:s||n}})}))}}function Xa(r="",e){try{return new URL(r,e).href}catch(t){return""}}function Za(r){return de(r,"3.2.0")>=0}var j=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),jt=r=>St(r)&&!ur(r),ie=r=>r.order==="end",kt=r=>St(r.containers)&&!ur(r.containers)&&ie(r),$i=(r,e)=>{var i;let t=r*1e3;return jt(e.controls)&&t<((i=e.startTime)!=null?i:0)},gr=(r,e)=>{var i,n;let t=r*1e3;return jt(e.controls)&&t>=((i=e.startTime)!=null?i:0)&&t<=((n=e.endTime)!=null?n:1/0)};var Ie=r=>r.some(e=>e.action.type==="expect"),br=r=>r.find(e=>e.action.type==="expect"),Ja=r=>(r==null?void 0:r.length)===1,Ft=r=>Ja(r)&&Vt(r[0]);var Bi=({fn:r,type:e=1},...t)=>(...i)=>e?r(...i,...t):r({...i[e],...t[e]}),qi=(r,e)=>Ie(r.events)?!1:e.some(({container:t})=>t.container.id!==r.id&&Ie(t.container.events)&&t.container.endTime===r.endTime&&!t.isRemoved);var je=class extends Mt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new eo(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var n;this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ye},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await Fi((n=i.result)!=null?n:t),this}async setInitial(){return this.setNext()}async setNext(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",Lt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:yr,getChapter:Nt,getMedia:vr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ye},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){var i;return this.getByChapterId((i=this.manifest)==null?void 0:i.metadata.initChapterId)||null}getByChapterId(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t||!this.manifest)return null;let n=Nt(this.manifest.chapters,t);if(n){let s=vr(this.manifest.media,n.videoId),c=yr(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:c}}return null}getBranches(t=(i=>(i=this.chapter)==null?void 0:i.id)()){var n,s,c;if(t===((n=this.chapter)==null?void 0:n.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let o=Nt(((c=this.manifest)==null?void 0:c.chapters)||[],t);return this.getByBranches(o==null?void 0:o.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{let s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){var t,i;return((t=this.chapter)==null?void 0:t.id)===((i=this.manifest)==null?void 0:i.metadata.initChapterId)}isEndChapter(){return ie(this.chapter)}};import{Player as to}from"@vkontakte/videoplayer-core";import{Subscription as ro,Tracer as io}from"@vkontakte/videoplayer-shared";var Di=r=>{let e=r.variants.find(t=>{var i;return((i=t.payload)==null?void 0:i.type)==="vk"});if(e&&"payload"in e){let[t,i]=e.payload.id.split("_");return[t,i]}return[]};var E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Je={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},R={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Er(){let r=new Map;function e({listId:n=Math.random().toString(),itemId:s=Math.random().toString(),...c}){let o=r.get(n),l={...c};return o?o[s]=l:r.set(n,{[s]:l}),{listId:n,itemId:s,...c}}function t(n,s){var o,l,h;let c=r.get(n);if(c){if(s)return(o=c[s])==null||o.player.destroy(),(l=c[s])==null||l.container.remove(),(h=c[s])==null||h.subscription.unsubscribe(),delete c[s],Object.keys(c).length||r.delete(n),!0;for(let p of Object.values(c))p.player.destroy(),p.container.remove();return r.delete(n),!0}else throw Error("Can't remove. Not find.")}function i(){for(let n of r)t(n[0])}return{createPlayer:e,removePlayer:t,map:r,removeAll:i}}function Cr(r,e=[]){var s,c,o;let t={},i,n=!e.length;for(let l of r.variants)if(!i&&"cover"in l&&(i=l.cover),"url"in l)switch(l.type.toLowerCase()){case"mp4":(n||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[(s=l.standard)!=null?s:"Invariant quality"]:l.url});break;case"mpeg":(n||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[(c=l.standard)!=null?c:"Invariant quality"]:l.url});break;case"hls":(n||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:l.url}});break;case"dash":(n||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:l.url}});break;default:break}return{sources:t,thumbUrl:i,title:(o=r.title)!=null?o:""}}var et=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&i.includes(e)&&(r.setQuality(e),r.setAutoQuality(!1))};var tt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},no=2;function xr(r){let e=Er(),t,i,n=new Pe,s={},c=!1,o=null,l=!1,h;r&&p(r);function p(u){o=u}function f(u,v,x){var L;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let A=((L=e.map.get(u))!=null?L:{})[v];if(A){s={chapterId:x,listId:u,itemId:v,...A};let P=s.player;i=P.info.currentQuality$.subscribe(_=>{if(!(!_||!P.info.position$.getValue())){t=_;for(let U of e.map)Object.values(U[1]).forEach(({player:$})=>{P.info.isAutoQualityEnabled$.getValue()||et($,_)})}}),A.container.remove(),c=!1,o.setPlayer(A.player),l||(o.init(),l=!0),n.emit(tt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function m(u,v,x){if(!o)throw Error("need to set interactive controller");if(xe(s)||u!==s.itemId)return;if(x>=0&&!c){let A=o.getChapterBranches();c=!0;let L=new Set;for(let P of A)L.has(P.media.id)||(await I({media:P.media,chapterId:P.chapter.id,setAsActive:!1,title:P.chapter.label}),L.add(P.media.id))}}async function C({chapter:{id:u},media:v}){if(xe(s))return;i==null||i.unsubscribe();let x=s.player.info.muted$.getValue(),g=s.player.info.currentQuality$.getValue(),A=s.player.info.isAutoQualityEnabled$.getValue(),L=s.player.info.volume$.getValue(),P=s.player.info.currentPlaybackRate$.getValue(),_=!A,U=!1;for(let $ of e.map)if($[0]===v.id){let re=Object.keys($[1]);for(let H of re)H===s.itemId?(re.length<no||(U=!0),e.removePlayer($[0],H)):(U=!0,f($[0],H,u),_?et(s.player,g):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(x),s.player.setPlaybackRate(P))}else e.removePlayer($[0]);U||(await I({media:v,chapterId:u,setAsActive:!0,playbackRate:P}),_?et(s.player,g):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(x))}async function I({media:u,chapterId:v,prefetch:x=!0,setAsActive:g=!0,autoplay:A=!1,preferredExt:L,title:P,playbackRate:_}){var ui,pi,di,fi,mi;let U=Math.random().toString(),$=document.createElement("div");h.append($);let re=(ui=s==null?void 0:s.player)==null?void 0:ui.info.isAutoQualityEnabled$.getValue(),H;if((pi=o==null?void 0:o.options)!=null&&pi.vkVideoLoader){let dt=Di(u);dt.length&&(H=await o.options.vkVideoLoader(...dt))}let pt=((di=o==null?void 0:o.options)==null?void 0:di.coreConfig)||{},Sa={...pt,configName:[...(fi=pt.configName)!=null?fi:[],"interactive"]},li={container:$,...((mi=H==null?void 0:H.videos)==null?void 0:mi[0])||{sources:Cr(u,L).sources},title:P,failoverHosts:(H==null?void 0:H.failoverHosts)||[]},Ee=new to(Sa,io.createRootTracer());Ee.initVideo(li);let hi=new ro;hi.add(Ee.info.position$.subscribe(function(dt){m(U,Ee.info.duration$.getValue(),dt)})).add(Ee.events.canplay$.subscribe(function(){re||et(Ee,t),_&&Ee.setPlaybackRate(_)}));let Ae=e.createPlayer({listId:u.id,itemId:U,player:Ee,container:$,sources:Cr(u,L).sources,config:li,subscription:hi});return g&&f(u.id,Ae.itemId,v),A&&Ae.player.play(),x&&!A&&Ae.player.prepare(),n.emit(tt.playerCreated,Ae.player),{player:Ae.player,config:Ae.config}}function k(){w(),o=null}function w(){o==null||o.off(E.chapterChanged,C),e.removeAll(),s={},l=!1,c=!1}async function y({container:u}){if(!o)throw Error("need to set interactive controller");w(),h=u;let{media:v,chapter:x}=o.getCurrentChapter();if(v){o.on(E.chapterChanged,C);let{player:g,config:A}=await I({media:v,chapterId:x.id,title:x.label});return n.emit(tt.initiated,{container:u,media:v,chapterId:x.id}),{player:g,config:A}}else console.error("not found")}return{...e,on:n.on.bind(n),off:n.off.bind(n),init:y,setInteractiveController:p,createPlayer:I,removeAll:k,getActivePlayer:function(){return s}}}import{Subscription as so}from"@vkontakte/videoplayer-shared";var $t=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEventEmitter:c,ignoreContainerEvent:o,permanentTextControls:l,disabledControls$:h,onRemove:p}){Y(this,"hide",()=>{setTimeout(()=>{var e,t;this.gameState!==j.end&&(Ie(this.container.container.events)&&this.gameState===j.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==j.interactive&&((t=(e=this.container).hide)==null||t.call(e)),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})))})});Y(this,"show",()=>{var e,t,i,n;if(this.gameState===j.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(n=(i=this.container).show)==null||n.call(i),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!0,isFirst:!1});else{let c=Bi({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})},onEvent:(o,l)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})),(this.gameState===j.end||this.gameState===j.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),l(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1}))},isEOV:()=>this.gameState===j.end});this.container.createView(c),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((t=(e=this.container).disable)==null||t.call(e))}});Y(this,"onEndOfVideo",()=>{this.gameState=j.end,this.selectContainerEvent(!0)});Y(this,"whilePlaying",()=>{var s,c;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[j.destroyed,j.removed].includes(this.gameState)&&!this.isPermanentText)return;let t=this.player.getExactTime();if($i(t,this.container.container))this.gameState!==j.beforeInteractive&&(this.gameState=j.beforeInteractive,this.onBeforeStartTime());else if(gr(t,this.container.container))this.gameState!==j.interactive&&(this.gameState=j.interactive,this.onStartTime());else if(this.gameState!==j.afterInteractive){let o=this.gameState;this.gameState=j.afterInteractive,o===j.interactive&&this.onEndTime()}else this.gameState!==j.destroyed&&!this.isPermanentText&&this.removeView();let i=gr(t,this.container.container),n=this.container.container.startTime?[this.container.container.startTime,(c=this.container.container.endTime)!=null?c:1/0]:[];this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:n,currentTime:t,isInteractiveTime:i})});this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new so,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=l&&Ft(t.container.controls),this.disabledControls$=h,this.onRemove=p,this.globalEventEmitter=c,this.gameState=j.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,i,n,s;e?(i=(t=this.container).disable)==null||i.call(t):(s=(n=this.container).enable)==null||s.call(n)}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=Ie(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=j.beforeInteractive}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.containerRemoved,visibility:!1}),this.gameState=j.removed,(e=this.onRemove)==null||e.call(this)}destroy(){var e;this.reset(),this.removeView(),this.gameState=j.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var Hi=(r=[])=>r.reduce((e,t,i)=>{var s,c,o;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(l=>!Vt(l));if(jt(n)){let l=[(c=t.startTime)!=null?c:0,(o=t.endTime)!=null?o:1/0],h=t.id;if(!i)e.push({subjects:[h],range:l});else{let p=[],f=-1/0,m=1/0,C=[],I=[];for(let k=0;k<e.length;k++){let w=e[k];if(I.push(...w.subjects),w.range[0]<m&&(m=w.range[0]),w.range[1]>f&&(f=w.range[1]),l[0]>=w.range[0]&&l[1]<=w.range[1])return e[k].subjects.push(h),e;l[0]<w.range[0]&&l[1]>w.range[0]&&(p.push(k),C=C.concat(w.subjects)),l[0]>=w.range[0]&&l[0]<=w.range[1]&&(p.push(k),C=C.concat(w.subjects),l[0]=w.range[0]),l[1]>=w.range[0]&&l[1]<=w.range[1]&&(p.push(k),C=C.concat(w.subjects),l[1]=w.range[1])}if(I.push(h),l[0]<=m&&l[1]>=f)return[{subjects:I,range:l}];p.length&&p.reverse().forEach(k=>{e.splice(k,1)}),e.push({subjects:C.concat([h]),range:l})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Gi(){let r={};function e(){for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&delete r[o];return!0}function t(o){let l={};for(let h in r)+h<=o&&(l[h]=r[h]);return l}function i(o){let l={};for(let h in r)+h>=o&&(l[h]=r[h]);return l}function n({timestamp:o,priority:l,initiator:h}){var p;if(hr(o)){let f=(p=r[o])!=null?p:null;if(f&&We(l,!0)){let m={},C=f[l];if(C&&(m={...m,...C}),m=xe(m)?null:m,m&&We(h,!0)){let I=m[h];return I!=null?I:null}return m}return f}return null}function s({timestamp:o,priority:l,initiator:h}){if(hr(o))if(r[o]){if(We(l,!0))if(r[o][l]){if(We(h,!0))if(r[o][l][h]){if(delete r[o][l][h],!xe(r[o][l]))return!0}else return!1;if(delete r[o][l],!xe(r[o]))return!0}else return!1;return delete r[o]}else return!1}function c({timestamp:o,priority:l,initiator:h,...p}){var f,m,C;(m=(f=r[o])==null?void 0:f[l])!=null&&m[h]?r[o][l][h].push({...p}):(C=r[o])!=null&&C[l]?r[o][l]={...r[o][l],[h]:[{...p}]}:r[o]?r[o]={...r[o],[l]:{[h]:[{...p}]}}:r[o]={[l]:{[h]:[{...p}]}}}return{map:r,remove:s,add:c,removeAll:e,get:n,getLte:t,getGte:i}}var ao=[M.expect,M.setNextBranch],oo=1/0;function Ir(r){let e=r,t,i=co(),n=new Gi,s,c=()=>{m(),y()},o=u=>{n.add.call(void 0,u),I()},l=(u=[])=>{for(let v of u)if(v.action(),ao.includes(v.actionType))break},h=(u=1/0)=>{var A,L,P;let v=Bt((A=n.get({timestamp:u,priority:"control"}))!=null?A:{}),x=Bt((L=n.get({timestamp:u,priority:"container"}))!=null?L:{}),g=Bt((P=n.get({timestamp:u,priority:"chapter"}))!=null?P:{});return[...v,...x,...g]},p=u=>{i.isReady(u)&&l(h(u))},f=()=>{var u;l([...Bt((u=n.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},m=()=>{t&&(s==null||s.unsubscribe(),t=void 0)},C=u=>{},I=()=>{t||(t=()=>setTimeout(()=>{p(1/0)}),s=e.events.ended$.subscribe(t))},k=u=>{m(),e=u},w=u=>{u.priority==="container"&&i.resetCalled(u.timestamp),n.remove(u)},y=()=>{i.release(),n.removeAll()};return{setPlayer:k,add:o,remove:w,exec:p,execEndOfVideo:f,listen:I,unlisten:m,release:c,containersEventsCallState:i,getPreparedToExecActions:h}}function co(){let r=new Map;return{setCalled:({timestamp:c,id:o})=>{let l=r.get(c);l&&l[o]!==void 0&&(l[o]=!0)},setData:(c=[])=>{var o,l;for(let h of c){let p=(o=h.endTime)!=null?o:oo,f=(l=r.get(p))!=null?l:{};r.set(p,{...f,[h.id]:!1})}},resetCalled:c=>{let o=r.get(c);if(o)for(let l in o)o[l]=!1},isReady:c=>{let o=r.get(c);return o?!Object.values(o).some(l=>!l):!0},release:()=>r.clear()}}function Bt(r){return Object.values(r).flat().sort(e=>e.actionType===M.expect?-1:1)}var Ui={videoContentHeight:0,videoContentWidth:0},zi=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return Ui;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return Ui;let c=t/i,o=n/s,l,h;return o>c?(h=s,l=s*c):o<c?(h=n/c,l=n):(h=s,l=n),{videoContentWidth:h,videoContentHeight:l}};var lo=250;function Wi(r){let e=()=>{},t=new ResizeObserver(o=>{s(o),e=s.bind(null,o)});function i(o){let{parentElement:l,player:h}=r();if(l&&h){let{videoContentWidth:p,videoContentHeight:f}=zi(l,h);l.style.setProperty("--interactive-content-width",`${p}px`),l.style.setProperty("--interactive-content-height",`${f}px`),l.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),l.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function n(){let{parentElement:o}=r();o.removeAttribute("style")}let s=Tt(o=>{let{fns:l=[]}=r();i(o);for(let h of l)h()},lo);function c(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e()},release:c}}var rt=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(i=>i!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var ho=r=>Math.floor(Math.random()*r),Ki=r=>{let e=r.length,t=1/0,i=null;for(;e--;)r[e].weight<t&&(t=r[e].weight,i=r[e]);return i},Qi=r=>{let e=r.length,t=-1/0,i=null;for(;e--;)r[e].weight>t&&(t=r[e].weight,i=r[e]);return i};var Yi=r=>{let e=r.length,t=ho(e);return r[t]};var Xi=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:1;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:1,e>=t)return r[s];return r[r.length-1]};var Zi=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var Tr=(r,e=!1)=>({...r,args:e?{...r.args,...Zi}:{...Zi,...r.args}}),wr=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},c=({action:y,controlType:u,controlId:v,containerId:x,branches:g=[],onEvent:A,isEOV:L=()=>!1,isDisabled:P=()=>!1})=>{let _=Tr(y,L()),U={timestamp:1/0,priority:"control",initiator:v,actionType:_.type},$=P(),re=r.emit.bind(r,E.interactives,{subjectId:v,subjectType:u,subjectName:"control",type:$?R.actionChoiceCanceled:R.actionChoice,actionType:y.type,payload:{containerId:x,..._.args}});if($){re();return}switch(_.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let H=g.find(pt=>pt.id===_.args.branchId);if(!H)return;A(_.args.isDetachContainer,m.bind(null,{subjectId:v,subjectName:"control"})),re(),_.args.shouldOpenNow?I({subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{chapterId:H.chapterId,autoSelect:!1}}):(t.add({...U,action:I.bind(null,{subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{chapterId:H.chapterId,autoSelect:!1}})}),i==null||i());return}case M.continuePlayback.trim().toLowerCase():{A(_.args.isDetachContainer,m.bind(null,{subjectId:v,subjectName:"control"})),re(),_.args.shouldOpenNow?C({subjectId:v,subjectName:"control",subjectType:u,action:y}):t.add({...U,action:C.bind(null,{subjectId:v,subjectName:"control",subjectType:u,action:y})});return}case M.openURI.trim().toLowerCase():{A(_.args.isDetachContainer,m.bind(null,{subjectId:v,subjectName:"control"})),re(),_.args.shouldOpenNow?w({subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{URI:y.args.uri}}):(t.add({...U,action:w.bind(null,{subjectId:v,subjectName:"control",subjectType:u,action:_,payload:{URI:y.args.uri}})}),i==null||i());return}default:console.error("Unexpected control event"),r.emit(E.errors,new z(1,1,{message:"Unexpected control event"}));return}},o=({action:y,container:{id:u,endTime:v},branches:x=[],isEOV:g=!1,autoSelected:A=!1})=>{let L=Tr(y,g),P={timestamp:!L.args.shouldOpenNow||g?1/0:v,priority:"container",initiator:u,actionType:L.type},_=r.emit.bind(r,E.interactives,{subjectId:u,subjectName:"container",type:R.actionChoice,actionType:L.type,payload:L.args});switch(L.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let U=x.find($=>$.id===L.args.branchId);if(!U)return;_(),t.add({...P,action:I.bind(null,{subjectId:u,subjectName:"container",action:L,payload:{chapterId:U.chapterId,autoSelect:A}})}),i==null||i();return}case M.setMaxWeightBranch.trim().toLowerCase():return;case M.setMinWeightBranch.trim().toLowerCase():return;case M.setRandomBranch.trim().toLowerCase():return;case M.setWeightlessRandomBranch.trim().toLowerCase():return;case M.continuePlayback.trim().toLowerCase():{_(),t.add({...P,action:C.bind(null,{subjectId:u,subjectName:"container",action:L})});return}case M.openURI.trim().toLowerCase():{_(),t.add({...P,action:w.bind(null,{subjectId:u,subjectName:"container",action:L,payload:{URI:y.args.uri}})}),i==null||i();return}default:console.error("Unexpected container event"),r.emit(E.errors,new z(1,1,{message:"Unexpected container event"}));return}};function l({container:y,branches:u,isEOV:v=!1}){let x=br(y.events);if(x){let g=Tr(x.action,v);r.emit(E.interactives,{subjectId:y.id,subjectName:"container",type:R.actionChoice,actionType:g.type,payload:g.args}),t.add({timestamp:v?1/0:y.endTime,priority:"container",initiator:y.id,actionType:M.expect,action:f.bind(null,{subjectId:y.id,subjectName:"container"})}),n.isExpect=!0}else for(let g of y.events)o({action:g.action,container:y,branches:u,isEOV:v})}let h=({chapterId:y,action:u,branches:v=[]})=>{let x=r.emit.bind(r,E.interactives,{subjectId:y,subjectName:"chapter",type:R.actionChoice,actionType:u.type,payload:u.args});switch(u.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let g=v.find(A=>A.id===u.args.branchId);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setWeightlessRandomBranch.trim().toLowerCase():{let g=Yi(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setRandomBranch.trim().toLowerCase():{let g=Xi(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setMaxWeightBranch.trim().toLowerCase():{let g=Qi(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.setMinWeightBranch.trim().toLowerCase():{let g=Ki(v);return g!=null&&g.chapterId?(x(),I.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case M.continuePlayback.trim().toLowerCase():return x(),C.bind(null,{subjectId:y,subjectName:"chapter",action:u});case M.openURI.trim().toLowerCase():return x(),w.bind(null,{subjectId:y,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:console.error("Unexpected chapter event"),r.emit(E.errors,new z(1,1,{message:"Unexpected chapter event"}));return}};function p(y){let u=br(y.events);if(u){if(ie(y))return;r.emit(E.interactives,{subjectId:y.id,subjectName:"chapter",type:R.actionChoice,actionType:u.action.type,payload:u.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:M.expect,action:f.bind(null,{subjectId:y.id,subjectName:"chapter"})})}else y.events.forEach(v=>{let x=h({chapterId:y.id,action:v.action,branches:y.branches});x&&t.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:v.action.type,action:x})})}let f=({subjectId:y,subjectName:u,action:v})=>{var x;e.pause(),r.emit(E.interactives,{subjectId:y,subjectName:u,type:R.actionExecution,actionType:(x=v==null?void 0:v.type)!=null?x:M.expect})},m=({subjectId:y,subjectName:u})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(E.interactives,{subjectId:y,subjectName:u,type:R.actionExecution,actionType:"after-expect"})},C=({subjectId:y,subjectName:u,subjectType:v,action:x})=>{r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type})},I=({subjectId:y,subjectName:u,subjectType:v,action:x,payload:g})=>{g.behaviour="change-chapter",r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type,payload:g})},k=({subjectId:y,subjectName:u,subjectType:v,action:x,payload:g})=>{g.behaviour="change-manifest",r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type,payload:g})},w=({subjectId:y,subjectName:u,subjectType:v,action:x,payload:g})=>{if(!g.URI)return;let A=window.open(g.URI,"_blank","noopener,noreferrer");A&&(A.opener=null),r.emit(E.interactives,{subjectId:y,subjectName:u,subjectType:v,type:R.actionExecution,actionType:x.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:h,onExpectEvent:f,expectEventHandler:m,setManifestChapterEvents:p,setManifestContainerEvents:l,stopExpect:s,state:n}};var si=Pa(fa(),1);import{Subscription as Ml,ValueSubject as ct}from"@vkontakte/videoplayer-shared";var ni=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(c=>c.id===i);if(!n)return null;let s=e.media.videos.find(c=>n.videoId===c.id);if(!s)return null;t[i]=ma(s)}return t[i]}).filter(Boolean)},Rl=r=>{for(let e of r.variants)if(Vl(e)&&"payload"in e)return e.payload.id},Vl=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",ma=r=>{let e=Rl(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},Al=(r,e)=>{for(let t of r.media.videos)if(e===ma(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},ya=(r,e)=>r.reduce((t,i)=>{let n=Al(e,i);return n?[...t,n]:t},[]);var ne,we,Se,X,zt,se,ae,J,_e,qe,De,lt=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new ct([]),hasPrevChapter$:new ct(!1),prevChapter$:new ct(null),isInitialChapter$:new ct(!1),isGoBackLimited$:new ct(!1)};T(this,ne,null);T(this,we);T(this,Se,!1);T(this,X,null);T(this,zt,null);T(this,se,null);T(this,ae,null);T(this,J,null);T(this,_e,new Ml);T(this,qe,!1);T(this,De,0);var c,o,l;b(this,se,t),b(this,J,e),b(this,ae,i),b(this,ne,n),b(this,we,s),(c=this.state)!=null&&c.history$&&a(this,_e)&&((l=a(this,_e))==null||l.add((o=this.state)==null?void 0:o.history$.subscribe(h=>{var p,f,m,C,I,k;(p=this.state)==null||p.prevChapter$.next((0,si.default)(h,-2)||null),(f=this.state)==null||f.hasPrevChapter$.next(h.length>1),(I=this.state)==null||I.isInitialChapter$.next(this.getInitialChapterId()===((C=(m=a(this,X))==null?void 0:m.metadata)==null?void 0:C.initChapterId)),(k=this.state)==null||k.isGoBackLimited$.next(a(this,De)===a(this,we).maxLength-1)})))}async setManifest(e){!a(this,ae)||!a(this,J)||(b(this,X,e),await this.getProjectHistory(),await a(this,ae).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,Se)||(b(this,Se,!0),a(this,J).emit(E.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,Se)}async updateHistory(e,t=!0){var o,l;if(!a(this,X))return;a(this,qe)?(b(this,qe,!1),vi(this,De)._++):b(this,De,0);let i=a(this,X),n=e.length-a(this,we).maxLength,s=n>0?e.slice(n):e,c=ni(s,i);if(b(this,zt,c),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!t||!a(this,ne)||!a(this,se)))try{await a(this,ne).save(a(this,se),c)}catch(h){(l=a(this,J))==null||l.emit(E.errors,new z(1,5,"Unable to save interactive history"))}}async goBack(){var i;if(!this.state||!a(this,ae))return(i=a(this,J))==null?void 0:i.emit(E.errors,new z(1,5,"Cannot go back because HistoryController has not been initialized"));b(this,qe,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await a(this,ae).setChapter({chapterId:t})}async getProjectHistory(){var n,s;if(!a(this,X)||!a(this,se))return;let e=a(this,X),t=[this.getInitialVideoId()];if(a(this,ne))try{let c=await a(this,ne).get(a(this,se));c.length&&(t=c)}catch(c){(n=a(this,J))==null||n.emit(E.errors,new z(1,5,"Error while trying to fetch data"))}let i=ya(t,e);(s=this==null?void 0:this.state)==null||s.history$.next(i)}getInitialChapterId(){var t,i;let e=(t=this.state)==null?void 0:t.history$.getValue();return(0,si.default)(e,-1)||a(this,we).initChapterId||((i=a(this,X))==null?void 0:i.metadata.initChapterId)}getInitialVideoId(){if(a(this,X)){let e=this.getInitialChapterId();return ni([e],a(this,X)).pop()}return null}destroy(){var e,t;this.state=null,b(this,se,null),b(this,ne,null),b(this,ae,null),(e=a(this,_e))==null||e.unsubscribe(),b(this,_e,null),b(this,Se,!1),(t=a(this,J))==null||t.emit(E.historyDestroyed),b(this,J,null)}};ne=new WeakMap,we=new WeakMap,Se=new WeakMap,X=new WeakMap,zt=new WeakMap,se=new WeakMap,ae=new WeakMap,J=new WeakMap,_e=new WeakMap,qe=new WeakMap,De=new WeakMap;var Re=class Re{constructor(e,t,i,n){this.target=e,this.type=t,this.listener=i,this.options=Re._convertOptions(e,n),this.target.addEventListener(t,i,this.options)}unlisten(){var e;this.type&&this.listener&&this.options&&((e=this.target)==null||e.removeEventListener(this.type,this.listener,this.options)),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let i=new Set(["passive","capture"]),n=Object.keys(t).filter(c=>!i.has(c));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),Re._doesSupportObject(e)?t:t.capture||!1}}static _doesSupportObject(e){let t=Re._supportsObject;if(t===void 0){t=!1;try{let i={},n={get:()=>(t=!0,!1)};Object.defineProperty(i,"passive",n),Object.defineProperty(i,"capture",n);let s=()=>{};e.addEventListener("test",s,i),e.removeEventListener("test",s,i)}catch(i){t=!1}Re._supportsObject=t}return t||!1}};Re._supportsObject=void 0;var Wt=Re;var Kt=class{constructor(){this.bindingMap=new rt}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new Wt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=c=>{this.unlisten(e,t,s),i(c)};this.listen(e,t,s,n)}unlisten(e,t,i){if(!this.bindingMap)return;let n=this.bindingMap.get(t)||[];for(let s of n)s.target===e&&(i===s.listener||!i)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var Qt=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var n;let e=(n=this.rootElement.getContext("2d"))==null?void 0:n.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,i=t.length;for(let s=3;s<i;s+=40)if(t[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(e,t=!1){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var Yt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)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;
|
|
@@ -16,8 +16,8 @@ var Ro=Object.create;var tr=Object.defineProperty;var Vo=Object.getOwnPropertyDe
|
|
|
16
16
|
top: 50%;
|
|
17
17
|
left: 50%;
|
|
18
18
|
transform: translate(-50%, -50%);
|
|
19
|
-
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),i={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(i,e)}catch(n){this._onError(n)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var i,n,s;return((i=t.controls)==null?void 0:i.length)&&e>=((n=t.startTime)!=null?n:0)&&e<=Math.min((s=t.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,i;(i=(t=this._callbacks)==null?void 0:t.onError)==null||i.call(t,e)}};function
|
|
19
|
+
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),i={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(i,e)}catch(n){this._onError(n)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var i,n,s;return((i=t.controls)==null?void 0:i.length)&&e>=((n=t.startTime)!=null?n:0)&&e<=Math.min((s=t.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,i;(i=(t=this._callbacks)==null?void 0:t.onError)==null||i.call(t,e)}};function va(r=0){return new Promise(e=>{setTimeout(()=>{e(0)},r)})}var ba=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,historyParams:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}}),oe=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function kl(){let r=document.createElement("div");return r.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,r}var ye,K,ve,G,ce,q,Q,le,O,he,He,D,Ge,F,V,ge,be,S,Co,xo,Xt,ci,Jt,Io,oi,Ve,ht,To,ai,wo,So,er,ut,Zt=class{constructor(e){T(this,S);T(this,ye,null);T(this,K,null);T(this,ve,null);T(this,G,null);T(this,ce,null);T(this,q,null);T(this,Q,null);T(this,le,null);T(this,O,null);T(this,he,new te(!1));T(this,He,new Set);T(this,D,null);T(this,Ge,null);T(this,F,null);T(this,V,null);T(this,ge,new Qe);T(this,be,null);Y(this,"state",{prevChapter$:new te(null),isInitialChapter$:new te(!1),isEndChapter$:new te(!1),isInteractiveExpectation$:new te(!1),calledByInteractive$:new te(!1),lastChapterChangeWasInitiatedByInteractive$:new te(!1),disabledControls$:new te(!1),interactiveRanges$:new te([]),isInteractiveTime$:new te(!1)});Y(this,"events",{noInteraction$:new Ml});Y(this,"emitPlayerChanged",e=>{o(this,V).emit(E.playerChanged,e)});T(this,ci,()=>{o(this,Q).fns.forEach(i=>i());let e=this.options.player.info.position$.getValue()*1e3,t=(o(this,O).chapter.containers||[]).filter(i=>i.startTime>=Math.floor(e));for(let i of t){o(this,q).remove({timestamp:1/0,priority:"container",initiator:i.id});for(let n of i.controls)o(this,q).remove({timestamp:1/0,priority:"control",initiator:n.id});o(this,K).find(n=>n.container.container.id===i.id).reset()}});T(this,Jt,()=>{o(this,ye).calc(),o(this,Q).requestAnimation()});T(this,Ve,(e=!0)=>{o(this,K).forEach(t=>{!e&&t.isPermanentText||(o(this,Q).removeFn(t.whilePlaying),t.destroy())})});T(this,er,e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(s=>({...s,subjects:s.subjects.filter(c=>c!==e)}));t.next(n)});T(this,ut,()=>{o(this,be)&&(clearTimeout(o(this,be)),b(this,be,null))});var t;this.options={...Eo,...e,config:{...Eo.config,...e.config}},b(this,K,[]),this.factories=new Map([["choice",It]]),this.rootElement=jl(),this.options.parentElement.append(this.rootElement),b(this,V,new Pe),b(this,ce,new Ol),b(this,ve,new Kt),b(this,G,new lt({interactiveController:this,globalEventEmitter:o(this,V),videoId:(t=this.options.projectInfo)==null?void 0:t.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&b(this,F,new Yt({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:i=>o(this,V).emit(E.errors,new z(1,6,i))})),o(this,ve).listen(this.rootElement,"mousedown",i=>i.stopPropagation()),o(this,ve).listen(this.rootElement,"mouseup",i=>i.stopPropagation()),b(this,O,new je(this.options.loaders,i=>o(this,V).emit(E.errors,new z(1,3,i)))),b(this,q,Ir(this.options.player)),b(this,Q,new At),b(this,le,wr({player:this.options.player,interactiveEvents:o(this,q),globalEventEmitter:o(this,V),removeControllers:o(this,Ve)})),b(this,ye,Wi(()=>{var i,n,s;return{player:(i=this.options)==null?void 0:i.player,parentElement:(n=this.options)==null?void 0:n.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{o(this,F).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&b(this,D,new Ke({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:i=>{this.setChapter({chapterId:i}),o(this,V).emit(E.graph,{type:Je.watchAgainClicked,chapterId:i})},onError:i=>o(this,V).emit(E.errors,new z(1,4,{message:i}))})),N(this,S,Co).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=ae.created}getStatEvents(){return{click$:new bo(e=>{o(this,V).on(E.graph,({type:t,visibility:i})=>{t==="visibility"&&e.next(i?"OPEN_GRAPH":"CLOSE_GRAPH"),t==="watchAgainClicked"&&e.next("WATCH_AGAIN")}),o(this,V).on(E.interactives,({type:t,subjectName:i,subjectType:n})=>{t!=="action-choice"||i!=="control"||(n==="Button"&&e.next("GO_NEXT_BUTTON"),n==="Area"&&e.next("GO_NEXT_AREA"))})}),nextMovie$:new bo(e=>{o(this,V).on(E.playerChanged,({config:t})=>{t!=null&&t.unitedVideoId&&e.next(t.unitedVideoId)})})}}setPlayer(e){N(this,S,Xt).call(this),this.options.player=e,o(this,ge).setPlayer(this.options.player),o(this,q)?o(this,q).setPlayer(this.options.player):b(this,q,Ir(this.options.player)),b(this,le,wr({player:this.options.player,interactiveEvents:o(this,q),globalEventEmitter:o(this,V),removeControllers:()=>o(this,Ve).call(this,!1)})),this.appState===ae.initiated&&(N(this,S,oi).call(this),N(this,S,ht).call(this,o(this,O).chapter))}async setManifest(e){N(this,S,Xt).call(this),this.isFirstChapterFetched=!1;let t=await o(this,O).setManifest(e);return o(this,D)&&await o(this,D).handleManifestChange(t.manifest),await o(this,G).setManifest(t.manifest),o(this,V).emit(E.manifestChanged,{manifest:t.manifest}),N(this,S,ht).call(this,o(this,O).chapter),t.manifest}setVisitedChapters(e){var t;Array.isArray(e)&&((t=o(this,D))==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=o(this,D))==null||t.updateVideosInfo(e))}async setChapter({chapterId:e,pushToHistory:t=!0}={}){var c;N(this,S,Xt).call(this),o(this,F)&&this.isFirstChapterFetched&&(o(this,F).draw(),o(this,F).show()),Pl.isSafari&&await go(35);let{chapter:i,media:n,graph:s}=await(e?o(this,O).setNext(e):o(this,O).setInitial());return t&&N(this,S,So).call(this,i.id),this.state.isInitialChapter$.next(o(this,O).isInitialChapter()),this.state.isEndChapter$.next(o(this,O).isEndChapter()),o(this,D)&&o(this,D).handleChapterChange(s),(c=o(this,F))==null||c.setCurrentChapter(this.getCurrentChapter().chapter),o(this,V).emit(E.chapterChanged,{chapter:i,media:n,graph:s}),N(this,S,ht).call(this,o(this,O).chapter),b(this,He,new Set),this.isFirstChapterFetched=!0,{chapter:i,media:n,graph:s}}toggleGraphView(e=!0){o(this,D)&&(e?(o(this,D).show(),o(this,he).next(!1)):(o(this,D).hide(),N(this,S,ai).call(this)),o(this,V).emit(E.graph,{type:Je.visibility,visibility:e}))}init(){o(this,O).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===ae.created&&(o(this,ye).resizeObserver.observe(this.options.fullscreenTargetElement),N(this,S,oi).call(this),this.appState=ae.initiated,N(this,S,ht).call(this,o(this,O).chapter))}deadEndCheck(){var i,n;return!((n=(i=o(this,q))==null?void 0:i.getPreparedToExecActions())!=null?n:[]).some(s=>s.actionType===M.setNextBranch)}allControlsAreRemoved(){return!o(this,K).some(t=>!t.container.isRemoved)}isEndedExpectation(){var i;if(!((i=this.options)!=null&&i.player)||!o(this,K))return!1;let e=this.options.player.info.position$.getValue(),t=this.options.player.info.duration$.getValue();return e===t&&o(this,K).some(n=>{let s=n.container.container;return!s.isRemoved&&s.endTime===null&&Ie(s.events)})}playPrevChapter(){var e;(e=o(this,G))==null||e.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=o(this,O).manifest){return Rt(e.metadata.version)}getInitialVideoInfo(){return{videoId:o(this,G).getInitialVideoId(),chapterId:o(this,G).getInitialChapterId()}}getHistoryState(){return o(this,G).state}getIsSeekable(){return o(this,he)}getInteractiveRanges(){var e;return Hi((e=o(this,O).chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return o(this,ge).getNextInteractiveTime(e)}getChapterBranches(e){return o(this,O).getBranches(e)}getCurrentChapter(){return o(this,O).getCurrent()}getCurrentManifest(){return o(this,O).manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return o(this,V).on(...e),this}off(...e){return o(this,V).off(...e),this}once(...e){return o(this,V).once(...e),this}destroy(){var e,t;o(this,Ve).call(this),b(this,K,void 0),this.state=void 0,(e=o(this,D))==null||e.destroy(),b(this,D,void 0),o(this,ye).release(),b(this,ye,void 0),b(this,le,void 0),o(this,Q).release(),b(this,Q,void 0),o(this,q).release(),b(this,q,void 0),o(this,O).release(),b(this,le,void 0),o(this,ve).release(),b(this,ve,void 0),o(this,ce).unsubscribe(),b(this,ce,void 0),o(this,V).reset(),b(this,V,void 0),(t=o(this,F))==null||t.destroy(),b(this,F,void 0),this.rootElement.remove(),this.rootElement=void 0,o(this,G).destroy(),b(this,G,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=ae.destroyed}};ye=new WeakMap,K=new WeakMap,ve=new WeakMap,G=new WeakMap,ce=new WeakMap,q=new WeakMap,Q=new WeakMap,le=new WeakMap,O=new WeakMap,he=new WeakMap,He=new WeakMap,D=new WeakMap,Ge=new WeakMap,F=new WeakMap,V=new WeakMap,ge=new WeakMap,be=new WeakMap,S=new WeakSet,Co=function(e=!1){o(this,V).on(E.historyInited,async({initChapterId:t,videosInfo:i=[]})=>{e&&await N(this,S,xo).call(this,{initialChapter:t,videosInfo:i})}),o(this,V).on(E.interactives,async t=>{var i,n;if(t.type===R.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((i=t.payload)==null?void 0:i.behaviour)==="change-chapter"){let{chapterId:c}=t.payload;this.setChapter({chapterId:c})}if(((n=t.payload)==null?void 0:n.behaviour)==="change-manifest"){let{manifestURL:c}=t.payload;this.setManifest(c)}let s=t.type==="action-execution";s&&t.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&t.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}t.type===R.containerRemoved&&o(this,er).call(this,t.subjectId)}),o(this,V).on(E.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},xo=async function({source:e,videosInfo:t=[]}){b(this,Ge,xr(this));let i=document.createElement("div");o(this,Ge).on(tt.activePlayerChanged,this.emitPlayerChanged);let{player:n,config:s}=await o(this,Ge).init({source:e,initialChapter:o(this,G).getInitialChapterId(),container:i});return this.updateGraphVideosInfo(t),{player:n,config:s}},Xt=function(){var e;this.appState===ae.ready&&(o(this,Ve).call(this),b(this,K,[]),o(this,Q).release(),(e=o(this,q))==null||e.release(),this.appState=ae.initiated,o(this,he).next(!1),o(this,ut).call(this))},ci=new WeakMap,Jt=new WeakMap,Io=function(e){(!o(this,D)||o(this,D).isHidden)&&N(this,S,ai).call(this);let t=e*1e3,n=this.getInteractiveRanges().findLast(({range:s})=>t>=s[1]);if(n){let s=n.range.join("-");o(this,He).has(s)||(o(this,He).add(s),o(this,V).emit(E.interactives,{type:R.rangeEnded,payload:n,visibility:!0}))}},oi=function(){o(this,ce).unsubscribe(),o(this,ce).add(this.options.player.events.started$.pipe(Ll()).subscribe(o(this,Jt))).add(this.options.player.events.playing$.subscribe(o(this,Q).requestAnimation)).add(this.options.player.events.willPause$.subscribe(o(this,Q).cancelAnimation)).add(this.options.player.info.position$.subscribe(N(this,S,Io).bind(this))).add(o(this,O).prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Nl({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:i})=>{let n;if(i)n=!0;else{let l=e*1e3;n=!!(t==null?void 0:t.find(({range:[p,f],subjects:m})=>p<l&&l<f&&m.length))}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let s=o(this,be)!==null,a=this.options.player.info.playbackState$.getValue()==="playing"||i;n&&!s&&a?b(this,be,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):s&&!a&&o(this,ut).call(this)})),this.options.lastFrame&&o(this,ce).add(this.options.player.info.duration$.subscribe(e=>{o(this,F).setVideoDuration(e*1e3)})).add(this.options.player.experimental.element$.subscribe(e=>{e&&o(this,F).setVideoElement(e)})).add(this.options.player.events.firstFrame$.subscribe(()=>{o(this,F).reset(),setTimeout(()=>{o(this,F).hide(),o(this,F).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(o(this,F).onSeek))},Ve=new WeakMap,ht=function(e){o(this,O).chapter&&this.appState===ae.initiated&&(o(this,le).setManifestChapterEvents(e),b(this,K,N(this,S,To).call(this,e)),o(this,q).containersEventsCallState.setData(e.containers),o(this,ge).setContainers(o(this,K).map(t=>t.container.container).filter(t=>!Ft(t.controls))),this.options.lastFrame&&o(this,Q).addFn(()=>{o(this,F).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=ae.ready)},To=function(e){var t,i;return(i=(t=e==null?void 0:e.containers)==null?void 0:t.reduce((n,s)=>{let c=s.type.trim().toLowerCase(),a=this.factories.get(c);if(a){let l=new $t({player:this.options.player,container:a(s,this.rootElement),branches:o(this,O).chapter.branches,selectBranches:o(this,le),interactiveEvents:o(this,q),globalEventEmitter:o(this,V),ignoreContainerEvent:()=>qi(s,o(this,K)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{o(this,ge).deleteContainer(s.id)}});return o(this,Q).addFn(l.whilePlaying,!0),[...n,l]}return[...n]},[]))!=null?i:[]},ai=function(){if(this.state.isInteractiveExpectation$.getValue()){o(this,he).next(!1);return}let t=o(this,he).getValue(),i=!!o(this,ge).getNextInteractiveTime();(i&&!t||!i&&t)&&o(this,he).next(!t)},wo=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},So=function(e){var a;if(N(this,S,wo).call(this),!o(this,G).inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),i=this.state.prevChapter$.getValue(),n=(a=i&&ie(i)&&kt(i))!=null?a:!1,s=o(this,O).manifest.metadata.initChapterId===e,c=o(this,G).state.history$.getValue();if(s||n&&t){o(this,G).updateHistory([e]);return}c.at(-1)!==e&&o(this,G).updateHistory([...c,e])},er=new WeakMap,ut=new WeakMap;var kl={Container:Oe,createChoiceContainer:It,createAreaControl:bt,createButtonControl:Ct,createRelativeLayout:Ti,getRootEl:ft,classnamesPrefix:B};var Rf={version:gi};export{z as CustomError,E as EVENT_NAMES,dr as INTERACTIVE_CLICK_ACTIONS,Zt as Interactives,je as ManifestController,Rf as SDKInfo,ni as chapterIdsToVKVideoIds,de as compareVersions,Vl as getChapterIdByVkVideoId,yo as getVKVideoIdByMedia,_l as getVideoRawIdByMedia,Je as graphEventTypes,kt as hasEndTemplate,R as interactivesEventTypes,ie as isLastChapter,Rt as isSupportedManifest,Rl as isVKVariantItem,kl as utils,vo as vkVideoIdsToChapterIds};
|
|
23
|
+
`,r}var ye,K,ve,G,ce,q,Q,le,O,he,He,D,Ge,F,V,ge,be,S,Ea,Ca,Xt,ci,Jt,xa,ai,Ve,ht,Ia,oi,Ta,wa,er,ut,Zt=class{constructor(e){T(this,S);T(this,ye,null);T(this,K,null);T(this,ve,null);T(this,G,null);T(this,ce,null);T(this,q,null);T(this,Q,null);T(this,le,null);T(this,O,null);T(this,he,new te(!1));T(this,He,new Set);T(this,D,null);T(this,Ge,null);T(this,F,null);T(this,V,null);T(this,ge,new Qe);T(this,be,null);Y(this,"state",{prevChapter$:new te(null),isInitialChapter$:new te(!1),isEndChapter$:new te(!1),isInteractiveExpectation$:new te(!1),calledByInteractive$:new te(!1),lastChapterChangeWasInitiatedByInteractive$:new te(!1),disabledControls$:new te(!1),interactiveRanges$:new te([]),isInteractiveTime$:new te(!1)});Y(this,"events",{noInteraction$:new Ll});Y(this,"emitPlayerChanged",e=>{a(this,V).emit(E.playerChanged,e)});T(this,ci,()=>{a(this,Q).fns.forEach(i=>i());let e=this.options.player.info.position$.getValue()*1e3,t=(a(this,O).chapter.containers||[]).filter(i=>i.startTime>=Math.floor(e));for(let i of t){a(this,q).remove({timestamp:1/0,priority:"container",initiator:i.id});for(let n of i.controls)a(this,q).remove({timestamp:1/0,priority:"control",initiator:n.id});a(this,K).find(n=>n.container.container.id===i.id).reset()}});T(this,Jt,()=>{a(this,ye).calc(),a(this,Q).requestAnimation()});T(this,Ve,(e=!0)=>{a(this,K).forEach(t=>{!e&&t.isPermanentText||(a(this,Q).removeFn(t.whilePlaying),t.destroy())})});T(this,er,e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(s=>({...s,subjects:s.subjects.filter(c=>c!==e)}));t.next(n)});T(this,ut,()=>{a(this,be)&&(clearTimeout(a(this,be)),b(this,be,null))});var t;this.options={...ba,...e,config:{...ba.config,...e.config}},b(this,K,[]),this.factories=new Map([["choice",It]]),this.rootElement=kl(),this.options.parentElement.append(this.rootElement),b(this,V,new Pe),b(this,ce,new Pl),b(this,ve,new Kt),b(this,G,new lt({interactiveController:this,globalEventEmitter:a(this,V),videoId:(t=this.options.projectInfo)==null?void 0:t.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&b(this,F,new Yt({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:i=>a(this,V).emit(E.errors,new z(1,6,i))})),a(this,ve).listen(this.rootElement,"mousedown",i=>i.stopPropagation()),a(this,ve).listen(this.rootElement,"mouseup",i=>i.stopPropagation()),b(this,O,new je(this.options.loaders,i=>a(this,V).emit(E.errors,new z(1,3,i)))),b(this,q,Ir(this.options.player)),b(this,Q,new At),b(this,le,wr({player:this.options.player,interactiveEvents:a(this,q),globalEventEmitter:a(this,V),removeControllers:a(this,Ve)})),b(this,ye,Wi(()=>{var i,n,s;return{player:(i=this.options)==null?void 0:i.player,parentElement:(n=this.options)==null?void 0:n.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,F).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&b(this,D,new Ke({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:i=>{this.setChapter({chapterId:i}),a(this,V).emit(E.graph,{type:Je.watchAgainClicked,chapterId:i})},onError:i=>a(this,V).emit(E.errors,new z(1,4,{message:i}))})),N(this,S,Ea).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=oe.created}getStatEvents(){return{click$:new ga(e=>{a(this,V).on(E.graph,({type:t,visibility:i})=>{t==="visibility"&&e.next(i?"OPEN_GRAPH":"CLOSE_GRAPH"),t==="watchAgainClicked"&&e.next("WATCH_AGAIN")}),a(this,V).on(E.interactives,({type:t,subjectName:i,subjectType:n})=>{t!=="action-choice"||i!=="control"||(n==="Button"&&e.next("GO_NEXT_BUTTON"),n==="Area"&&e.next("GO_NEXT_AREA"))})}),nextMovie$:new ga(e=>{a(this,V).on(E.playerChanged,({config:t})=>{t!=null&&t.unitedVideoId&&e.next(t.unitedVideoId)})})}}setPlayer(e){N(this,S,Xt).call(this),this.options.player=e,a(this,ge).setPlayer(this.options.player),a(this,q)?a(this,q).setPlayer(this.options.player):b(this,q,Ir(this.options.player)),b(this,le,wr({player:this.options.player,interactiveEvents:a(this,q),globalEventEmitter:a(this,V),removeControllers:()=>a(this,Ve).call(this,!1)})),this.appState===oe.initiated&&(N(this,S,ai).call(this),N(this,S,ht).call(this,a(this,O).chapter))}async setManifest(e){N(this,S,Xt).call(this),this.isFirstChapterFetched=!1;let t=await a(this,O).setManifest(e);return a(this,D)&&await a(this,D).handleManifestChange(t.manifest),await a(this,G).setManifest(t.manifest),a(this,V).emit(E.manifestChanged,{manifest:t.manifest}),N(this,S,ht).call(this,a(this,O).chapter),t.manifest}setVisitedChapters(e){var t;Array.isArray(e)&&((t=a(this,D))==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=a(this,D))==null||t.updateVideosInfo(e))}async setChapter({chapterId:e,pushToHistory:t=!0}={}){var c;N(this,S,Xt).call(this),a(this,F)&&this.isFirstChapterFetched&&(a(this,F).draw(),a(this,F).show()),Nl.isSafari&&await va(35);let{chapter:i,media:n,graph:s}=await(e?a(this,O).setNext(e):a(this,O).setInitial());return t&&N(this,S,wa).call(this,i.id),this.state.isInitialChapter$.next(a(this,O).isInitialChapter()),this.state.isEndChapter$.next(a(this,O).isEndChapter()),a(this,D)&&a(this,D).handleChapterChange(s),(c=a(this,F))==null||c.setCurrentChapter(this.getCurrentChapter().chapter),a(this,V).emit(E.chapterChanged,{chapter:i,media:n,graph:s}),N(this,S,ht).call(this,a(this,O).chapter),b(this,He,new Set),this.isFirstChapterFetched=!0,{chapter:i,media:n,graph:s}}toggleGraphView(e=!0){a(this,D)&&(e?(a(this,D).show(),a(this,he).next(!1)):(a(this,D).hide(),N(this,S,oi).call(this)),a(this,V).emit(E.graph,{type:Je.visibility,visibility:e}))}init(){a(this,O).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===oe.created&&(a(this,ye).resizeObserver.observe(this.options.fullscreenTargetElement),N(this,S,ai).call(this),this.appState=oe.initiated,N(this,S,ht).call(this,a(this,O).chapter))}deadEndCheck(){var i,n;return!((n=(i=a(this,q))==null?void 0:i.getPreparedToExecActions())!=null?n:[]).some(s=>s.actionType===M.setNextBranch)}allControlsAreRemoved(){return!a(this,K).some(t=>!t.container.isRemoved)}isEndedExpectation(){var i;if(!((i=this.options)!=null&&i.player)||!a(this,K))return!1;let e=this.options.player.info.position$.getValue(),t=this.options.player.info.duration$.getValue();return e===t&&a(this,K).some(n=>{let s=n.container.container;return!s.isRemoved&&s.endTime===null&&Ie(s.events)})}playPrevChapter(){var e;(e=a(this,G))==null||e.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=a(this,O).manifest){return Rt(e.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,G).getInitialVideoId(),chapterId:a(this,G).getInitialChapterId()}}getHistoryState(){return a(this,G).state}getIsSeekable(){return a(this,he)}getInteractiveRanges(){var e;return Hi((e=a(this,O).chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return a(this,ge).getNextInteractiveTime(e)}getChapterBranches(e){return a(this,O).getBranches(e)}getCurrentChapter(){return a(this,O).getCurrent()}getCurrentManifest(){return a(this,O).manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return a(this,V).on(...e),this}off(...e){return a(this,V).off(...e),this}once(...e){return a(this,V).once(...e),this}destroy(){var e,t;a(this,Ve).call(this),b(this,K,void 0),this.state=void 0,(e=a(this,D))==null||e.destroy(),b(this,D,void 0),a(this,ye).release(),b(this,ye,void 0),b(this,le,void 0),a(this,Q).release(),b(this,Q,void 0),a(this,q).release(),b(this,q,void 0),a(this,O).release(),b(this,le,void 0),a(this,ve).release(),b(this,ve,void 0),a(this,ce).unsubscribe(),b(this,ce,void 0),a(this,V).reset(),b(this,V,void 0),(t=a(this,F))==null||t.destroy(),b(this,F,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,G).destroy(),b(this,G,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=oe.destroyed}};ye=new WeakMap,K=new WeakMap,ve=new WeakMap,G=new WeakMap,ce=new WeakMap,q=new WeakMap,Q=new WeakMap,le=new WeakMap,O=new WeakMap,he=new WeakMap,He=new WeakMap,D=new WeakMap,Ge=new WeakMap,F=new WeakMap,V=new WeakMap,ge=new WeakMap,be=new WeakMap,S=new WeakSet,Ea=function(e=!1){a(this,V).on(E.historyInited,async({initChapterId:t,videosInfo:i=[]})=>{e&&await N(this,S,Ca).call(this,{initialChapter:t,videosInfo:i})}),a(this,V).on(E.interactives,async t=>{var i,n;if(t.type===R.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((i=t.payload)==null?void 0:i.behaviour)==="change-chapter"){let{chapterId:c}=t.payload;this.setChapter({chapterId:c})}if(((n=t.payload)==null?void 0:n.behaviour)==="change-manifest"){let{manifestURL:c}=t.payload;this.setManifest(c)}let s=t.type==="action-execution";s&&t.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&t.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}t.type===R.containerRemoved&&a(this,er).call(this,t.subjectId)}),a(this,V).on(E.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Ca=async function({source:e,videosInfo:t=[]}){b(this,Ge,xr(this));let i=document.createElement("div");a(this,Ge).on(tt.activePlayerChanged,this.emitPlayerChanged);let{player:n,config:s}=await a(this,Ge).init({source:e,initialChapter:a(this,G).getInitialChapterId(),container:i});return this.updateGraphVideosInfo(t),{player:n,config:s}},Xt=function(){var e;this.appState===oe.ready&&(a(this,Ve).call(this),b(this,K,[]),a(this,Q).release(),(e=a(this,q))==null||e.release(),this.appState=oe.initiated,a(this,he).next(!1),a(this,ut).call(this))},ci=new WeakMap,Jt=new WeakMap,xa=function(e){(!a(this,D)||a(this,D).isHidden)&&N(this,S,oi).call(this);let t=e*1e3,n=this.getInteractiveRanges().findLast(({range:s})=>t>=s[1]);if(n){let s=n.range.join("-");a(this,He).has(s)||(a(this,He).add(s),a(this,V).emit(E.interactives,{type:R.rangeEnded,payload:n,visibility:!0}))}},ai=function(){a(this,ce).unsubscribe(),a(this,ce).add(this.options.player.events.started$.pipe(Ol()).subscribe(a(this,Jt))).add(this.options.player.events.playing$.subscribe(a(this,Q).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,Q).cancelAnimation)).add(this.options.player.info.position$.subscribe(N(this,S,xa).bind(this))).add(a(this,O).prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(jl({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:i})=>{let n;if(i)n=!0;else{let l=e*1e3;n=!!(t==null?void 0:t.find(({range:[p,f],subjects:m})=>p<l&&l<f&&m.length))}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let s=a(this,be)!==null,o=this.options.player.info.playbackState$.getValue()==="playing"||i;n&&!s&&o?b(this,be,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):s&&!o&&a(this,ut).call(this)})),this.options.lastFrame&&a(this,ce).add(this.options.player.info.duration$.subscribe(e=>{a(this,F).setVideoDuration(e*1e3)})).add(this.options.player.experimental.element$.subscribe(e=>{e&&a(this,F).setVideoElement(e)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,F).reset(),setTimeout(()=>{a(this,F).hide(),a(this,F).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,F).onSeek))},Ve=new WeakMap,ht=function(e){a(this,O).chapter&&this.appState===oe.initiated&&(a(this,le).setManifestChapterEvents(e),b(this,K,N(this,S,Ia).call(this,e)),a(this,q).containersEventsCallState.setData(e.containers),a(this,ge).setContainers(a(this,K).map(t=>t.container.container).filter(t=>!Ft(t.controls))),this.options.lastFrame&&a(this,Q).addFn(()=>{a(this,F).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=oe.ready)},Ia=function(e){var t,i;return(i=(t=e==null?void 0:e.containers)==null?void 0:t.reduce((n,s)=>{let c=s.type.trim().toLowerCase(),o=this.factories.get(c);if(o){let l=new $t({player:this.options.player,container:o(s,this.rootElement),branches:a(this,O).chapter.branches,selectBranches:a(this,le),interactiveEvents:a(this,q),globalEventEmitter:a(this,V),ignoreContainerEvent:()=>qi(s,a(this,K)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,ge).deleteContainer(s.id)}});return a(this,Q).addFn(l.whilePlaying,!0),[...n,l]}return[...n]},[]))!=null?i:[]},oi=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,he).next(!1);return}let t=a(this,he).getValue(),i=!!a(this,ge).getNextInteractiveTime();(i&&!t||!i&&t)&&a(this,he).next(!t)},Ta=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},wa=function(e){var o;if(N(this,S,Ta).call(this),!a(this,G).inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),i=this.state.prevChapter$.getValue(),n=(o=i&&ie(i)&&kt(i))!=null?o:!1,s=a(this,O).manifest.metadata.initChapterId===e,c=a(this,G).state.history$.getValue();if(s||n&&t){a(this,G).updateHistory([e]);return}c.at(-1)!==e&&a(this,G).updateHistory([...c,e])},er=new WeakMap,ut=new WeakMap;var Fl={Container:Oe,createChoiceContainer:It,createAreaControl:bt,createButtonControl:Ct,createRelativeLayout:Ti,getRootEl:ft,classnamesPrefix:B};var Vf={version:gi};export{z as CustomError,E as EVENT_NAMES,dr as INTERACTIVE_CLICK_ACTIONS,Zt as Interactives,je as ManifestController,Vf as SDKInfo,ni as chapterIdsToVKVideoIds,de as compareVersions,Al as getChapterIdByVkVideoId,ma as getVKVideoIdByMedia,Rl as getVideoRawIdByMedia,Je as graphEventTypes,kt as hasEndTemplate,R as interactivesEventTypes,ie as isLastChapter,Rt as isSupportedManifest,Vl as isVKVariantItem,Fl as utils,ya as vkVideoIdsToChapterIds};
|