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