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