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