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