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