@vkontakte/videoplayer-interactive 1.0.23-dev.75664bee.0 → 1.0.23-dev.8a9f6a57.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/es2018.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.23-dev.75664bee.0
3
- * Thu, 24 Oct 2024 10:02:53 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.23-dev.8a9f6a57.0
3
+ * Thu, 24 Oct 2024 10:53:09 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-23/doc/
5
5
  */
6
- var Xs=Object.create;var qr=Object.defineProperty;var Js=Object.getOwnPropertyDescriptor;var ea=Object.getOwnPropertyNames;var ta=Object.getPrototypeOf,ra=Object.prototype.hasOwnProperty;var Dr=r=>{throw TypeError(r)};var d=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ia=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ea(e))!ra.call(r,n)&&n!==t&&qr(r,n,{get:()=>e[n],enumerable:!(i=Js(e,n))||i.enumerable});return r};var Hr=(r,e,t)=>(t=r!=null?Xs(ta(r)):{},ia(e||!r||!r.__esModule?qr(t,"default",{value:r,enumerable:!0}):t,r));var _t=(r,e,t)=>e.has(r)||Dr("Cannot "+t);var I=(r,e,t)=>(_t(r,e,"read from private field"),t?t.call(r):e.get(r)),O=(r,e,t)=>e.has(r)?Dr("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),Ie=(r,e,t)=>(_t(r,e,"access private method"),t);var Ur=(r,e,t,i)=>({set _(n){R(r,e,n,t)},get _(){return I(r,e,i)}});var q=d((Nt,Xr)=>{"use strict";var xe=function(r){return r&&r.Math===Math&&r};Xr.exports=xe(typeof globalThis=="object"&&globalThis)||xe(typeof window=="object"&&window)||xe(typeof self=="object"&&self)||xe(typeof global=="object"&&global)||xe(typeof Nt=="object"&&Nt)||function(){return this}()||Function("return this")()});var Y=d((Wc,Jr)=>{"use strict";Jr.exports=function(r){try{return!!r()}catch(e){return!0}}});var Te=d((Qc,ei)=>{"use strict";var sa=Y();ei.exports=!sa(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var si=d((Kc,ni)=>{"use strict";var aa=Te(),ii=Function.prototype,ti=ii.apply,ri=ii.call;ni.exports=typeof Reflect=="object"&&Reflect.apply||(aa?ri.bind(ti):function(){return ri.apply(ti,arguments)})});var ee=d((Yc,li)=>{"use strict";var ai=Te(),oi=Function.prototype,Ft=oi.call,oa=ai&&oi.bind.bind(Ft,Ft);li.exports=ai?oa:function(r){return function(){return Ft.apply(r,arguments)}}});var $t=d((Zc,pi)=>{"use strict";var ci=ee(),la=ci({}.toString),ca=ci("".slice);pi.exports=function(r){return ca(la(r),8,-1)}});var Bt=d((Xc,hi)=>{"use strict";var pa=$t(),ha=ee();hi.exports=function(r){if(pa(r)==="Function")return ha(r)}});var Z=d((Jc,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=d((ep,di)=>{"use strict";var ua=Y();di.exports=!ua(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var tt=d((tp,fi)=>{"use strict";var da=Te(),et=Function.prototype.call;fi.exports=da?et.bind(et):function(){return et.apply(et,arguments)}});var gi=d(vi=>{"use strict";var mi={}.propertyIsEnumerable,yi=Object.getOwnPropertyDescriptor,fa=yi&&!mi.call({1:2},1);vi.f=fa?function(e){var t=yi(this,e);return!!t&&t.enumerable}:mi});var Dt=d((ip,bi)=>{"use strict";bi.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Ei=d((np,Ci)=>{"use strict";var ma=ee(),ya=Y(),va=$t(),Ht=Object,ga=ma("".split);Ci.exports=ya(function(){return!Ht("z").propertyIsEnumerable(0)})?function(r){return va(r)==="String"?ga(r,""):Ht(r)}:Ht});var Ut=d((sp,Ii)=>{"use strict";Ii.exports=function(r){return r==null}});var Gt=d((ap,xi)=>{"use strict";var ba=Ut(),Ca=TypeError;xi.exports=function(r){if(ba(r))throw new Ca("Can't call method on "+r);return r}});var Si=d((op,Ti)=>{"use strict";var Ea=Ei(),Ia=Gt();Ti.exports=function(r){return Ea(Ia(r))}});var Se=d((lp,wi)=>{"use strict";var xa=Z();wi.exports=function(r){return typeof r=="object"?r!==null:xa(r)}});var zt=d((cp,Li)=>{"use strict";Li.exports={}});var Kt=d((pp,_i)=>{"use strict";var Wt=zt(),Qt=q(),Ta=Z(),Mi=function(r){return Ta(r)?r:void 0};_i.exports=function(r,e){return arguments.length<2?Mi(Wt[r])||Mi(Qt[r]):Wt[r]&&Wt[r][e]||Qt[r]&&Qt[r][e]}});var Ri=d((hp,Ai)=>{"use strict";var Sa=ee();Ai.exports=Sa({}.isPrototypeOf)});var Oi=d((up,Vi)=>{"use strict";var wa=q(),ki=wa.navigator,Pi=ki&&ki.userAgent;Vi.exports=Pi?String(Pi):""});var Di=d((dp,qi)=>{"use strict";var Bi=q(),Yt=Oi(),ji=Bi.process,Ni=Bi.Deno,Fi=ji&&ji.versions||Ni&&Ni.version,$i=Fi&&Fi.v8,B,rt;$i&&(B=$i.split("."),rt=B[0]>0&&B[0]<4?1:+(B[0]+B[1]));!rt&&Yt&&(B=Yt.match(/Edge\/(\d+)/),(!B||B[1]>=74)&&(B=Yt.match(/Chrome\/(\d+)/),B&&(rt=+B[1])));qi.exports=rt});var Zt=d((fp,Ui)=>{"use strict";var Hi=Di(),La=Y(),Ma=q(),_a=Ma.String;Ui.exports=!!Object.getOwnPropertySymbols&&!La(function(){var r=Symbol("symbol detection");return!_a(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Hi&&Hi<41})});var Xt=d((mp,Gi)=>{"use strict";var Aa=Zt();Gi.exports=Aa&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Jt=d((yp,zi)=>{"use strict";var Ra=Kt(),ka=Z(),Pa=Ri(),Va=Xt(),Oa=Object;zi.exports=Va?function(r){return typeof r=="symbol"}:function(r){var e=Ra("Symbol");return ka(e)&&Pa(e.prototype,Oa(r))}});var Qi=d((vp,Wi)=>{"use strict";var ja=String;Wi.exports=function(r){try{return ja(r)}catch(e){return"Object"}}});var er=d((gp,Ki)=>{"use strict";var Na=Z(),Fa=Qi(),$a=TypeError;Ki.exports=function(r){if(Na(r))return r;throw new $a(Fa(r)+" is not a function")}});var Zi=d((bp,Yi)=>{"use strict";var Ba=er(),qa=Ut();Yi.exports=function(r,e){var t=r[e];return qa(t)?void 0:Ba(t)}});var Ji=d((Cp,Xi)=>{"use strict";var tr=tt(),rr=Z(),ir=Se(),Da=TypeError;Xi.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 Da("Can't convert object to primitive value")}});var tn=d((Ep,en)=>{"use strict";en.exports=!0});var sn=d((Ip,nn)=>{"use strict";var rn=q(),Ha=Object.defineProperty;nn.exports=function(r,e){try{Ha(rn,r,{value:e,configurable:!0,writable:!0})}catch(t){rn[r]=e}return e}});var nr=d((xp,ln)=>{"use strict";var Ua=tn(),Ga=q(),za=sn(),an="__core-js_shared__",on=ln.exports=Ga[an]||za(an,{});(on.versions||(on.versions=[])).push({version:"3.38.0",mode:Ua?"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 hn=d((Tp,pn)=>{"use strict";var cn=nr();pn.exports=function(r,e){return cn[r]||(cn[r]=e||{})}});var sr=d((Sp,un)=>{"use strict";var Wa=Gt(),Qa=Object;un.exports=function(r){return Qa(Wa(r))}});var it=d((wp,dn)=>{"use strict";var Ka=ee(),Ya=sr(),Za=Ka({}.hasOwnProperty);dn.exports=Object.hasOwn||function(e,t){return Za(Ya(e),t)}});var mn=d((Lp,fn)=>{"use strict";var Xa=ee(),Ja=0,eo=Math.random(),to=Xa(1 .toString);fn.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+to(++Ja+eo,36)}});var gn=d((Mp,vn)=>{"use strict";var ro=q(),io=hn(),yn=it(),no=mn(),so=Zt(),ao=Xt(),fe=ro.Symbol,ar=io("wks"),oo=ao?fe.for||fe:fe&&fe.withoutSetter||no;vn.exports=function(r){return yn(ar,r)||(ar[r]=so&&yn(fe,r)?fe[r]:oo("Symbol."+r)),ar[r]}});var In=d((_p,En)=>{"use strict";var lo=tt(),bn=Se(),Cn=Jt(),co=Zi(),po=Ji(),ho=gn(),uo=TypeError,fo=ho("toPrimitive");En.exports=function(r,e){if(!bn(r)||Cn(r))return r;var t=co(r,fo),i;if(t){if(e===void 0&&(e="default"),i=lo(t,r,e),!bn(i)||Cn(i))return i;throw new uo("Can't convert object to primitive value")}return e===void 0&&(e="number"),po(r,e)}});var or=d((Ap,xn)=>{"use strict";var mo=In(),yo=Jt();xn.exports=function(r){var e=mo(r,"string");return yo(e)?e:e+""}});var wn=d((Rp,Sn)=>{"use strict";var vo=q(),Tn=Se(),lr=vo.document,go=Tn(lr)&&Tn(lr.createElement);Sn.exports=function(r){return go?lr.createElement(r):{}}});var cr=d((kp,Ln)=>{"use strict";var bo=de(),Co=Y(),Eo=wn();Ln.exports=!bo&&!Co(function(){return Object.defineProperty(Eo("div"),"a",{get:function(){return 7}}).a!==7})});var An=d(_n=>{"use strict";var Io=de(),xo=tt(),To=gi(),So=Dt(),wo=Si(),Lo=or(),Mo=it(),_o=cr(),Mn=Object.getOwnPropertyDescriptor;_n.f=Io?Mn:function(e,t){if(e=wo(e),t=Lo(t),_o)try{return Mn(e,t)}catch(i){}if(Mo(e,t))return So(!xo(To.f,e,t),e[t])}});var kn=d((Vp,Rn)=>{"use strict";var Ao=Y(),Ro=Z(),ko=/#|\.prototype\./,we=function(r,e){var t=Vo[Po(r)];return t===jo?!0:t===Oo?!1:Ro(e)?Ao(e):!!e},Po=we.normalize=function(r){return String(r).replace(ko,".").toLowerCase()},Vo=we.data={},Oo=we.NATIVE="N",jo=we.POLYFILL="P";Rn.exports=we});var On=d((Op,Vn)=>{"use strict";var Pn=Bt(),No=er(),Fo=Te(),$o=Pn(Pn.bind);Vn.exports=function(r,e){return No(r),e===void 0?r:Fo?$o(r,e):function(){return r.apply(e,arguments)}}});var Nn=d((jp,jn)=>{"use strict";var Bo=de(),qo=Y();jn.exports=Bo&&qo(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var $n=d((Np,Fn)=>{"use strict";var Do=Se(),Ho=String,Uo=TypeError;Fn.exports=function(r){if(Do(r))return r;throw new Uo(Ho(r)+" is not an object")}});var Dn=d(qn=>{"use strict";var Go=de(),zo=cr(),Wo=Nn(),nt=$n(),Bn=or(),Qo=TypeError,pr=Object.defineProperty,Ko=Object.getOwnPropertyDescriptor,hr="enumerable",ur="configurable",dr="writable";qn.f=Go?Wo?function(e,t,i){if(nt(e),t=Bn(t),nt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&dr in i&&!i[dr]){var n=Ko(e,t);n&&n[dr]&&(e[t]=i.value,i={configurable:ur in i?i[ur]:n[ur],enumerable:hr in i?i[hr]:n[hr],writable:!1})}return pr(e,t,i)}:pr:function(e,t,i){if(nt(e),t=Bn(t),nt(i),zo)try{return pr(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new Qo("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Un=d(($p,Hn)=>{"use strict";var Yo=de(),Zo=Dn(),Xo=Dt();Hn.exports=Yo?function(r,e,t){return Zo.f(r,e,Xo(1,t))}:function(r,e,t){return r[e]=t,r}});var Wn=d((Bp,zn)=>{"use strict";var Le=q(),Jo=si(),el=Bt(),tl=Z(),rl=An().f,il=kn(),me=zt(),nl=On(),ye=Un(),Gn=it();nr();var sl=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 Jo(r,this,arguments)};return e.prototype=r.prototype,e};zn.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,s=r.proto,l=i?Le:n?Le[t]:Le[t]&&Le[t].prototype,o=i?me:me[t]||ye(me,t,{})[t],a=o.prototype,c,u,m,f,C,x,A,g,h;for(f in e)c=il(i?f:t+(n?".":"#")+f,r.forced),u=!c&&l&&Gn(l,f),x=o[f],u&&(r.dontCallGetSet?(h=rl(l,f),A=h&&h.value):A=l[f]),C=u&&A?A:e[f],!(!c&&!s&&typeof x==typeof C)&&(r.bind&&u?g=nl(C,Le):r.wrap&&u?g=sl(C):s&&tl(C)?g=el(C):g=C,(r.sham||C&&C.sham||x&&x.sham)&&ye(g,"sham",!0),ye(o,f,g),s&&(m=t+"Prototype",Gn(me,m)||ye(me,m,{}),ye(me[m],f,C),r.real&&a&&(c||!a[f])&&ye(a,f,C)))}});var Kn=d((qp,Qn)=>{"use strict";var al=Math.ceil,ol=Math.floor;Qn.exports=Math.trunc||function(e){var t=+e;return(t>0?ol:al)(t)}});var fr=d((Dp,Yn)=>{"use strict";var ll=Kn();Yn.exports=function(r){var e=+r;return e!==e||e===0?0:ll(e)}});var Xn=d((Hp,Zn)=>{"use strict";var cl=fr(),pl=Math.min;Zn.exports=function(r){var e=cl(r);return e>0?pl(e,9007199254740991):0}});var es=d((Up,Jn)=>{"use strict";var hl=Xn();Jn.exports=function(r){return hl(r.length)}});var rs=d((Gp,ts)=>{"use strict";ts.exports=function(){}});var is=d(()=>{"use strict";var ul=Wn(),dl=sr(),fl=es(),ml=fr(),yl=rs();ul({target:"Array",proto:!0},{at:function(e){var t=dl(this),i=fl(t),n=ml(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});yl("at")});var ss=d((Qp,ns)=>{"use strict";var vl=Kt();ns.exports=vl});var os=d((Kp,as)=>{"use strict";is();var gl=ss();as.exports=gl("Array","at")});var cs=d((Yp,ls)=>{"use strict";var bl=os();ls.exports=bl});var mr=d((Zp,ps)=>{"use strict";var Cl=cs();ps.exports=Cl});var Gr="1.0.23-dev.75664bee.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 N="interactive",na="interactive-controls-container",He=()=>document.querySelector(`.${na}`),zr=.4,j={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Wr=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Wr||{}),Qr=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(Qr||{}),Kr=(i=>(i.start="left",i.end="right",i.center="center",i))(Kr||{}),Ue=({target:r,props:e})=>{var t,i,n,s,l,o;r.style.alignItems=(i=((t=e.text)==null?void 0:t.gravityVertical)&&Wr[e.text.gravityVertical])!=null?i:"center",r.style.justifyContent=(s=((n=e.text)==null?void 0:n.gravityHorizontal)&&Qr[e.text.gravityHorizontal])!=null?s:"center",r.style.textAlign=(o=((l=e.text)==null?void 0:l.alignment)&&Kr[e.text.alignment])!=null?o:"left"},Ge=({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},ze=({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)},We=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,l,o,a,c,u,m,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=(m=(u=e==null?void 0:e.shape)==null?void 0:u.border)==null?void 0:m.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})`},he=({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:j.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 Qe=r=>{if(r.type.trim().toLowerCase()==="area")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(`${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",ze({target:i,props:this.control.props,fallback:{...j,backgroundColor:"transparent"}}),We({target:i,props:this.control.props,fallback:{...j,borderAlpha:0},dependsOn:this.container.dimensions}),he({target:i,layoutParams:this.control.layoutParams,fallback:j}),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 Ke=()=>{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 Ye=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",he({target:i,layoutParams:this.control.layoutParams,fallback:j}),ze({target:i,props:this.control.props,fallback:j}),We({target:i,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),Ue({target:i,props:this.control.props});let n=Ke();Ge({target:n,props:this.control.props,fallback:j,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 Yr=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",he({target:i,layoutParams:this.control.layoutParams,fallback:j}),Ue({target:i,props:this.control.props});let n=Ke();Ge({target:n,props:this.control.props,fallback:j,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}},Ze=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,Xe,Zr,ue=class{constructor(e){O(this,K);this.container=e,this.factories=new Map,Ie(this,K,Xe).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),Ie(this,K,Xe).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),Ie(this,K,Xe).call(this)}};K=new WeakSet,Xe=function(){this.controls=Ie(this,K,Zr).call(this)},Zr=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 Je=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new jt(r,e)},jt=class extends ue{constructor(e,t){super(e),this.rootElement=t!=null?t:He(),this.layout=new Ze(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Ye),this.addControlFactory("text",Yr),this.addControlFactory("area",Qe)}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=zr,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 Ys=Hr(mr(),1);import{clientChecker as ec,combine as tc,InterfaceLanguage as rc,Observable as Ws,once as ic,Subject as Ee,Subscription as Qs,ValueSubject as F}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as qe}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as El}from"@vkontakte/videoplayer-shared";function Me(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var te=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,_e=r=>te(r,"Object"),st=r=>te(r,"String"),at=r=>te(r,"Array"),ot=r=>te(r,"Number"),hs=r=>te(r,"Function");var yr=r=>ot(r)&&!isNaN(r);var re=r=>_e(r)&&Object.keys(r).length===0,vr=r=>at(r)&&!r.length;var Ae=(r,e)=>st(r)&&(e?r.trim():r).length;var us="video_interactive",ds="videoint";var fs=250,Re=class{constructor(e){this.handleZoomChange=Me(e=>{this.lastZoomInfo=e},fs);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,!ot(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=Il(e),this.resizeObserver=new ResizeObserver(Me(this.onResize,fs)),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 El(this.lang,us,ds)}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 Il(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 ke=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 xl}from"uuid";var Tl="3.1",ms={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Sl={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},ys=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,u=[Sl];switch(o){case"await":c?u=[]:s=[];break;case"default":{let m={type:"onSuspense",action:{type:ms.default,args:{branchId:i,shouldOpenNow:!c,isDetachContainer:!0}}};c?u=[m]:s=[m];break}case"random":case"weightlessRandom":case"max":case"min":{let m={type:"onSuspense",action:{type:ms[o],args:{}}};c?u=[m]:s=[m];break}}for(let m of a.controls)l.push({...a,controls:[{...m}],id:xl(),events:u})}e.push({...t,containers:l,events:s,branches:n})}return r.metadata.version=Tl,r.metadata.updated=new Date().toISOString(),{...r,chapters:e}};var wl="3.2",vs=r=>{if(!r.media){let{media:e,...t}=r.metadata;return{...r,metadata:{...t,version:wl},media:e}}return r};var Ll="3.3",Ml=(r=[])=>({edit:{chapters:r},view:{}}),gs={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},bs=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(u=>{var m;return{...u,controls:u.controls.map(({subtype:f,type:C,...x})=>({...x,type:f!=null?f:C})),events:(m=u.events)!=null&&m.length?u.events:[gs]}});e.push({id:s,...a,containers:c,events:(i=a.events)!=null&&i.length?a.events:[gs]}),t.push({id:s,x:l,y:o})}return{...r,chapters:e,graph:Ml(t),metadata:{...r.metadata,version:Ll}}};var _l=[{version:"3.0",migrate:ys},{version:"3.1",migrate:vs},{version:"3.2",migrate:bs}],gr=r=>_l.reduce((e,t)=>X(e.metadata.version,t.version)?e:t.migrate(e),r);var Cs={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 Es={metadata:"Object",chapters:"Array"},Al="3.0.0",Rl="3.3.0",lt=r=>{let e=X(r,Al);return e===-1?!1:e===0?!0:X(r,Rl)!==1},Is=r=>{if(!_e(r))return!1;for(let e in Es)if(!r[e]||!te(r[e],Es[e]))return!1;return lt(r.metadata.version)},ct=r=>r.type===Cs.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 pt=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 ht=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{hs(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 Fl}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 kl(...this.loaders[e])(t)}};function kl(...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 dt({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,dt.name,"Could not find media"),actions:r}}}return{...i,errors:Pe(e,dt.name,"Could not find chapter"),actions:r}}var ft=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 ft{constructor(){super(),this.listeners||ft.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)}},Ve=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&&(Ve.prototype[Symbol.toStringTag]="AbortController",ve.prototype[Symbol.toStringTag]="AbortSignal");function mt(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(!mt({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,u){let m;u&&u.signal&&(m=u.signal,delete u.signal);let f=new t(c,u);return m&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),f},s.prototype=t.prototype);let l=e;return{fetch:(a,c)=>{let u=s&&s.prototype.isPrototypeOf(a)?a.signal:c?c.signal:void 0;if(u){let m;try{m=new DOMException("Aborted","AbortError")}catch(C){m=new Error("Aborted"),m.name="AbortError"}if(u.aborted)return Promise.reject(m);let f=new Promise((C,x)=>{u.addEventListener("abort",()=>x(m),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([f,l(a,c)])}return l(a,c)},Request:s}}var Oe=mt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),xs=Oe?br({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Cr=Oe?xs.fetch:window.fetch,Qh=Oe?xs.Request:window.Request,Kh=Oe?Ve:window.AbortController,Yh=Oe?ve:window.AbortSignal;var Pl=async r=>{try{let e={},t;if(st(r)){t=new URL(r).href;let n=await Cr(t);if(!n.ok)return{};e=await n.json()}else if(_e(r))e=r;else return{};if(!Is(e))return{};let i=e.metadata.media;if(st(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=await Cr(n);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch(n){return jl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Ts(r){let{manifest:e,manifestURL:t}=await Pl(r),i=gr(e);return i.media=Vl(i.media,t),delete i.metadata.media,i}function yt(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 Vl(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=Ol(n,e);return{...i,url:s||n}})}))}}function Ol(r="",e){try{return new URL(r,e).href}catch(t){return""}}function jl(r){return X(r,"3.2.0")>=0}var vt=r=>at(r)&&!vr(r),D=r=>r.order==="end",gt=r=>at(r.containers)&&!vr(r.containers)&&D(r),Ss=(r,e)=>{var i;let t=r*1e3;return vt(e.controls)&&t<((i=e.startTime)!=null?i:0)},xr=(r,e)=>{var i,n;let t=r*1e3;return vt(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,bt=r=>Nl(r)&&ct(r[0]);function ws(r,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?r({...e[0],...t}):r(...e,...t)}var Ls=(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 Fl(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 Ts((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",dt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Er,getChapter:yt,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=yt(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=yt(((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?D(this.chapter):!1}};import{Player as $l}from"@vkontakte/videoplayer-core";import{Subscription as Lr,Tracer as Bl,ValueSubject as ql}from"@vkontakte/videoplayer-shared";var Ms=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 je=(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 Dl=2;function Mr(r){let e=Sr(),t=new Lr,i={},n=null,s=!1,l,o=new ql(null);r&&a(r);function a(g){n=g}function c(g,h,p){var y;if(!n)throw Error("need to set interactive controller");if(!n.options)return;let E=((y=e.map.get(g))!=null?y:{})[h];if(E){i={chapterId:p,listId:g,itemId:h,...E};let M=i.player;i.subscription.add(M.info.currentQuality$.subscribe(S=>{let k=M.info.position$.getValue(),T=M.info.isAutoQualityEnabled$.getValue();if(!(!S||!k||T))for(let _ of e.map)Object.values(_[1]).forEach(({player:P})=>{je(P,S)})})).add(M.events.started$.subscribe(()=>{u(h)})),E.container.remove(),n.setPlayer(E.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 u(g){if(!n)throw Error("need to set interactive controller");if(re(i)||g!==i.itemId)return;let h=n.getChapterBranches(),p=new Set;for(let v of h)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 m({chapter:{id:g},manifestVideo:h}){if(re(i)||!n)return;let p=i.player.info.muted$.getValue(),v=i.player.info.currentQuality$.getValue(),E=i.player.info.isAutoQualityEnabled$.getValue(),y=i.player.info.volume$.getValue(),M=i.player.info.currentPlaybackRate$.getValue(),S=!E,k=!1;for(let T of e.map)if(T[0]===h.id&&!n.state.isReplay$.getValue()){let _=Object.keys(T[1]);for(let P of _)P===i.itemId?(_.length<Dl||(k=!0),e.removePlayer(T[0],P)):(k=!0,c(T[0],P,g),S?je(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(y),i.player.setMuted(p),i.player.setPlaybackRate(M))}else e.removePlayer(T[0]);k||(await f({media:h,chapterId:g,setAsActive:!0,playbackRate:M}),S?je(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(y),i.player.setMuted(p))}async function f({media:g,chapterId:h,prefetch:p=!0,setAsActive:v=!0,autoplay:E=!1,preferredExt:y,title:M,playbackRate:S}){var Or,jr,Nr,Fr,$r;let k=Math.random().toString(),T=document.createElement("div");l.append(T);let _;if((Or=n==null?void 0:n.options)!=null&&Or.vkVideoLoader){let De=Ms(g);De.length&&(_=await n.options.vkVideoLoader(...De))}let P=((jr=n==null?void 0:n.options)==null?void 0:jr.coreConfig)||void 0,le={...P,configName:[...(Nr=P==null?void 0:P.configName)!=null?Nr:[],"interactive"]},ce={container:T,...((Fr=_==null?void 0:_.videos)==null?void 0:Fr[0])||{sources:wr(g,y).sources},title:M,failoverHosts:(_==null?void 0:_.failoverHosts)||[]},Q=new $l(le,Bl.createRootTracer());Q.initVideo(ce);let Pr=null;if(_!=null&&_.videos&&(n!=null&&n.options.createOneStat)){let De=_.videos[0],Mt=n.options.createOneStat(De),Br=new Lr;Mt&&(Br.add(Mt.attachTo(Q)),Pr={oneStat:Mt,statSubscription:Br})}let Vr=new Lr,Zs=($r=i==null?void 0:i.player)==null?void 0:$r.info.isAutoQualityEnabled$.getValue();Vr.add(Q.events.canplay$.subscribe(function(){Zs||je(Q,i.player.info.currentQuality$.getValue()),S&&Q.setPlaybackRate(S)}));let pe=e.createPlayer({listId:g.id,itemId:k,player:Q,container:T,sources:wr(g,y).sources,config:ce,subscription:Vr,statistics:Pr});return v&&c(g.id,pe.itemId,h),E&&pe.player.play(),p&&!E&&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:h}=n.getCurrentChapter();g&&h?(t.add(n.events.chapterChanged$.subscribe(m)),await f({media:g,chapterId:h.id,title:h.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 Hl}from"@vkontakte/videoplayer-shared";var Ct=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEvents:l,globalEventEmitter:o,ignoreContainerEvent:a,permanentTextControls:c,disabledControls$:u,onRemove:m}){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=ws(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 c;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(Ss(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 u=this.gameState;this.gameState=3,u===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=xr(s,this.container.container),o=this.container.container.startTime?[this.container.container.startTime,(c=this.container.container.endTime)!=null?c:1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:o,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(b.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new Hl,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=c&&bt(t.container.controls),this.disabledControls$=u,this.onRemove=m,this.globalEventEmitter=o,this.gameState=0,this.globalEvents=l,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 _s=(r=[])=>r.reduce((e,t,i)=>{var s,l,o;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(a=>!ct(a));if(vt(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 u=[],m=-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]>m&&(m=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]&&(u.push(A),C=C.concat(g.subjects)),a[0]>=g.range[0]&&a[0]<=g.range[1]&&(u.push(A),C=C.concat(g.subjects),a[0]=g.range[0]),a[1]>=g.range[0]&&a[1]<=g.range[1]&&(u.push(A),C=C.concat(g.subjects),a[1]=g.range[1])}if(x.push(c),a[0]<=f&&a[1]>=m)return[{subjects:x,range:a}];u.length&&u.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 As(){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 u;if(yr(o)){let m=(u=r[o])!=null?u:null;if(m&&a&&Ae(a,!0)){let f={},C=m[a];if(C&&(f={...f,...C}),f=re(f)?null:f,f&&Ae(c,!0)){let x=f[c];return x!=null?x:null}return f}return m}return null}function s({timestamp:o,priority:a,initiator:c}){if(yr(o))if(r[o]){if(a&&Ae(a,!0))if(r[o][a]){if(c&&Ae(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,...u}){var m,f,C;(f=(m=r[o])==null?void 0:m[a])!=null&&f[c]?r[o][a][c].push({...u}):(C=r[o])!=null&&C[a]?r[o][a]={...r[o][a],[c]:[{...u}]}:r[o]?r[o]={...r[o],[a]:{[c]:[{...u}]}}:r[o]={[a]:{[c]:[{...u}]}}}return{map:r,remove:s,add:l,removeAll:e,get:n,getLte:t,getGte:i}}var Ul=[L.expect,L.setNextBranch],Gl=1/0;function Rs(r){let e=r,t,i=zl(),n=As(),s,l=()=>{f(),h()},o=p=>{n.add.call(void 0,p),x()},a=(p=[])=>{for(let v of p)if(v.action(),Ul.includes(v.actionType))break},c=(p=1/0)=>{var M,S,k;let v=Et((M=n.get({timestamp:p,priority:"control"}))!=null?M:{}),E=Et((S=n.get({timestamp:p,priority:"container"}))!=null?S:{}),y=Et((k=n.get({timestamp:p,priority:"chapter"}))!=null?k:{});return[...v,...E,...y]},u=p=>{i.isReady(p)&&a(c(p))},m=()=>{var p;a([...Et((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(()=>{u(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)},h=()=>{i.release(),n.removeAll()};return{setPlayer:A,add:o,remove:g,exec:u,execEndOfVideo:m,listen:x,unlisten:f,release:l,containersEventsCallState:i,getPreparedToExecActions:c}}function zl(){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 u=(o=c.endTime)!=null?o:Gl,m=(a=r.get(u))!=null?a:{};r.set(u,{...m,[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 Et(r){return Object.values(r).flat().sort(e=>e.actionType===L.expect?-1:1)}var ks={videoContentHeight:0,videoContentWidth:0},Ps=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return ks;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return ks;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 Wl=250;function Vs(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:u,videoContentHeight:m}=Ps(a,c);a.style.setProperty("--interactive-content-width",`${u}px`),a.style.setProperty("--interactive-content-height",`${m}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=Me(o=>{let{fns:a=[]}=r();i(o);for(let c of a)c()},Wl);function l(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e==null||e()},release:l}}var Fe=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 Ql=r=>Math.floor(Math.random()*r),js=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 Fs=r=>{let e=r.length,t=Ql(e);return r[t]},Os=1,$s=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:Os;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:Os,e>=t)return r[s];return r[r.length-1]};var Bs={shouldOpenNow:!0,isDetachContainer:!0};var _r=(r,e=!1)=>({...r,args:e?{...r.args,...Bs}:{...Bs,...r.args}}),Hs=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:h,controlType:p,controlId:v,containerId:E,branches:y=[],onEvent:M,isEOV:S=()=>!1,isDisabled:k=()=>!1})=>{let T=_r(h,S()),_={timestamp:1/0,priority:"control",initiator:v,actionType:T.type},P=k(),le=r.emit.bind(r,b.interactives,{subjectId:v,subjectType:p,subjectName:"control",type:P?w.actionChoiceCanceled:w.actionChoice,actionType:h.type,payload:{containerId:E,...T.args}});if(P){le();return}switch(T.type.trim().toLowerCase()){case L.setNextBranch.trim().toLowerCase():{let ce=y.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:h}):t.add({..._,action:C.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:h})});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:h.args.uri}}):(t.add({..._,action:g.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:T,payload:{URI:h.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:h,container:{id:p,endTime:v},branches:E=[],isEOV:y=!1,autoSelected:M=!1})=>{let S=_r(h,y),k={timestamp:!S.args.shouldOpenNow||y?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 _=E.find(P=>P.id===S.args.branchId);if(!_)return;T(),t.add({...k,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({...k,action:C.bind(null,{subjectId:p,subjectName:"container",action:S})});return}case L.openURI.trim().toLowerCase():{T(),t.add({...k,action:g.bind(null,{subjectId:p,subjectName:"container",action:S,payload:{URI:h.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:h,branches:p,isEOV:v=!1}){var y,M;let E=Tr(h.events);if(E){let S=_r(E.action,v);r.emit(b.interactives,{subjectId:h.id,subjectName:"container",type:w.actionChoice,actionType:S.type,payload:S.args}),t.add({timestamp:v?1/0:(y=h.endTime)!=null?y:1/0,priority:"container",initiator:h.id,actionType:L.expect,action:m.bind(null,{subjectId:h.id,subjectName:"container"})}),n.isExpect=!0}else for(let S of(M=h.events)!=null?M:[])o({action:S.action,container:h,branches:p,isEOV:v})}let c=({chapterId:h,action:p,branches:v=[]})=>{let E=r.emit.bind(r,b.interactives,{subjectId:h,subjectName:"chapter",type:w.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case L.setNextBranch.trim().toLowerCase():{let y=v.find(M=>M.id===p.args.branchId);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setWeightlessRandomBranch.trim().toLowerCase():{let y=Fs(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setRandomBranch.trim().toLowerCase():{let y=$s(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setMaxWeightBranch.trim().toLowerCase():{let y=Ns(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setMinWeightBranch.trim().toLowerCase():{let y=js(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.continuePlayback.trim().toLowerCase():return E(),C.bind(null,{subjectId:h,subjectName:"chapter",action:p});case L.openURI.trim().toLowerCase():return E(),g.bind(null,{subjectId:h,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 u(h){var v;let p=Tr(h.events);if(p){if(D(h))return;r.emit(b.interactives,{subjectId:h.id,subjectName:"chapter",type:w.actionChoice,actionType:p.action.type,payload:p.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:L.expect,action:m.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else(v=h.events)==null||v.forEach(E=>{let y=c({chapterId:h.id,action:E.action,branches:h.branches});y&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:E.action.type,action:y})})}let m=({subjectId:h,subjectName:p})=>{e.pause(),r.emit(b.interactives,{subjectId:h,subjectName:p,type:w.actionExecution,actionType:L.expect})},f=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(b.interactives,{subjectId:h,subjectName:p,type:w.actionExecution,actionType:"after-expect"})},C=({subjectId:h,subjectName:p,subjectType:v,action:E})=>{r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type})},x=({subjectId:h,subjectName:p,subjectType:v,action:E,payload:y})=>{y.behaviour="change-chapter",r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type,payload:y})},A=({subjectId:h,subjectName:p,subjectType:v,action:E,payload:y})=>{y.behaviour="change-manifest",r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type,payload:y})},g=({subjectId:h,subjectName:p,subjectType:v,action:E,payload:y})=>{if(!y.URI)return;let M=window.open(y.URI,"_blank","noopener,noreferrer");M&&(M.opener=null),r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:c,onExpectEvent:m,expectEventHandler:f,setManifestChapterEvents:u,setManifestContainerEvents:a,stopExpect:s,state:n}};var kr=Hr(mr(),1);import{Subscription as Jl,Subject as Rr,ValueSubject as $e}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]=Us(s)}return t[i]}).filter(Boolean)},Yl=r=>{for(let e of r.variants)if(Zl(e)&&"payload"in e)return e.payload.id},Zl=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",Us=r=>{let e=Yl(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},Xl=(r,e)=>{for(let t of r.media.videos)if(e===Us(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},Gs=(r,e)=>r.reduce((t,i)=>{let n=Xl(e,i);return n?[...t,n]:t},[]);var G,ne,se,$,It,z,W,H,ae,be,Ce,Be=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new $e([]),hasPrevChapter$:new $e(!1),prevChapter$:new $e(null),isInitialChapter$:new $e(!1),isGoBackLimited$:new $e(!1)};O(this,G,null);O(this,ne);O(this,se,!1);O(this,$,null);O(this,It,null);this.events={inited$:new Rr,destroyed$:new Rr,error$:new Rr};O(this,z,null);O(this,W,null);O(this,H,null);O(this,ae,new Jl);O(this,be,!1);O(this,Ce,0);var l;R(this,z,t),R(this,H,e),R(this,W,i),R(this,G,n),R(this,ne,s),this.state.history$&&I(this,ae)&&((l=I(this,ae))==null||l.add(this.state.history$.subscribe(o=>{var a,c;this.state.prevChapter$.next((0,kr.default)(o,-2)||null),this.state.hasPrevChapter$.next(o.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((c=(a=I(this,$))==null?void 0:a.metadata)==null?void 0:c.initChapterId)),this.state.isGoBackLimited$.next(I(this,Ce)===I(this,ne).maxLength-1)})))}async setManifest(e){if(!I(this,W)||!I(this,H))return;R(this,$,e),await this.getProjectHistory();let t=this.getInitialChapterId();await I(this,W).setChapter({chapterId:t,pushToHistory:!1}),I(this,se)||(R(this,se,!0),this.events.inited$.next({initChapterId:t}))}get inited(){return I(this,se)}async updateHistory(e,t=!0){var o;if(!I(this,$))return;I(this,be)?(R(this,be,!1),Ur(this,Ce)._++):R(this,Ce,0);let i=I(this,$),n=e.length-I(this,ne).maxLength,s=n>0?e.slice(n):e,l=Ar(s,i);if(R(this,It,l),this.state.history$.next(s),!(!t||!I(this,G)||!I(this,z)))try{await I(this,G).save(I(this,z),l)}catch(a){let c=new V(1,5,"Unable to save interactive history");this.events.error$.next(c),(o=I(this,H))==null||o.emit(b.errors,c)}}async goBack(){var i;if(!this.state||!I(this,W)){let n=new V(1,5,"Unable to save interactive history");return this.events.error$.next(n),(i=I(this,H))==null?void 0:i.emit(b.errors,n)}R(this,be,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await I(this,W).setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){var n;if(!I(this,$)||!I(this,z))return;let e=I(this,$),t=[this.getInitialVideoId()];if(I(this,G))try{let s=await I(this,G).get(I(this,z));s.length&&(t=s)}catch(s){let l=new V(1,5,"Error while trying to fetch data");this.events.error$.next(l),(n=I(this,H))==null||n.emit(b.errors,l)}let i=Gs(t,e);this.state.history$.next(i)}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,kr.default)(e,-1)||I(this,ne).initChapterId||((t=I(this,$))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(I(this,$)){let e=this.getInitialChapterId();return Ar([e],I(this,$)).pop()}return null}destroy(){var e,t;R(this,z,null),R(this,G,null),R(this,W,null),(e=I(this,ae))==null||e.unsubscribe(),R(this,ae,null),R(this,se,!1),(t=I(this,H))==null||t.emit(b.historyDestroyed),this.events.destroyed$.next(),R(this,H,null)}};G=new WeakMap,ne=new WeakMap,se=new WeakMap,$=new WeakMap,It=new WeakMap,z=new WeakMap,W=new WeakMap,H=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 xt=oe;var Tt=class{constructor(){this.bindingMap=new Fe}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new xt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=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 St=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 wt=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 Xs=Object.create;var qr=Object.defineProperty;var Js=Object.getOwnPropertyDescriptor;var ea=Object.getOwnPropertyNames;var ta=Object.getPrototypeOf,ra=Object.prototype.hasOwnProperty;var Dr=r=>{throw TypeError(r)};var d=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ia=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ea(e))!ra.call(r,n)&&n!==t&&qr(r,n,{get:()=>e[n],enumerable:!(i=Js(e,n))||i.enumerable});return r};var Hr=(r,e,t)=>(t=r!=null?Xs(ta(r)):{},ia(e||!r||!r.__esModule?qr(t,"default",{value:r,enumerable:!0}):t,r));var _t=(r,e,t)=>e.has(r)||Dr("Cannot "+t);var I=(r,e,t)=>(_t(r,e,"read from private field"),t?t.call(r):e.get(r)),O=(r,e,t)=>e.has(r)?Dr("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),Ie=(r,e,t)=>(_t(r,e,"access private method"),t);var Ur=(r,e,t,i)=>({set _(n){R(r,e,n,t)},get _(){return I(r,e,i)}});var q=d((Nt,Xr)=>{"use strict";var xe=function(r){return r&&r.Math===Math&&r};Xr.exports=xe(typeof globalThis=="object"&&globalThis)||xe(typeof window=="object"&&window)||xe(typeof self=="object"&&self)||xe(typeof global=="object"&&global)||xe(typeof Nt=="object"&&Nt)||function(){return this}()||Function("return this")()});var Y=d((Wc,Jr)=>{"use strict";Jr.exports=function(r){try{return!!r()}catch(e){return!0}}});var Te=d((Qc,ei)=>{"use strict";var sa=Y();ei.exports=!sa(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var si=d((Kc,ni)=>{"use strict";var aa=Te(),ii=Function.prototype,ti=ii.apply,ri=ii.call;ni.exports=typeof Reflect=="object"&&Reflect.apply||(aa?ri.bind(ti):function(){return ri.apply(ti,arguments)})});var ee=d((Yc,li)=>{"use strict";var ai=Te(),oi=Function.prototype,Ft=oi.call,oa=ai&&oi.bind.bind(Ft,Ft);li.exports=ai?oa:function(r){return function(){return Ft.apply(r,arguments)}}});var $t=d((Zc,pi)=>{"use strict";var ci=ee(),la=ci({}.toString),ca=ci("".slice);pi.exports=function(r){return ca(la(r),8,-1)}});var Bt=d((Xc,hi)=>{"use strict";var pa=$t(),ha=ee();hi.exports=function(r){if(pa(r)==="Function")return ha(r)}});var Z=d((Jc,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=d((ep,di)=>{"use strict";var ua=Y();di.exports=!ua(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var tt=d((tp,fi)=>{"use strict";var da=Te(),et=Function.prototype.call;fi.exports=da?et.bind(et):function(){return et.apply(et,arguments)}});var gi=d(vi=>{"use strict";var mi={}.propertyIsEnumerable,yi=Object.getOwnPropertyDescriptor,fa=yi&&!mi.call({1:2},1);vi.f=fa?function(e){var t=yi(this,e);return!!t&&t.enumerable}:mi});var Dt=d((ip,bi)=>{"use strict";bi.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Ei=d((np,Ci)=>{"use strict";var ma=ee(),ya=Y(),va=$t(),Ht=Object,ga=ma("".split);Ci.exports=ya(function(){return!Ht("z").propertyIsEnumerable(0)})?function(r){return va(r)==="String"?ga(r,""):Ht(r)}:Ht});var Ut=d((sp,Ii)=>{"use strict";Ii.exports=function(r){return r==null}});var Gt=d((ap,xi)=>{"use strict";var ba=Ut(),Ca=TypeError;xi.exports=function(r){if(ba(r))throw new Ca("Can't call method on "+r);return r}});var Si=d((op,Ti)=>{"use strict";var Ea=Ei(),Ia=Gt();Ti.exports=function(r){return Ea(Ia(r))}});var Se=d((lp,wi)=>{"use strict";var xa=Z();wi.exports=function(r){return typeof r=="object"?r!==null:xa(r)}});var zt=d((cp,Li)=>{"use strict";Li.exports={}});var Kt=d((pp,_i)=>{"use strict";var Wt=zt(),Qt=q(),Ta=Z(),Mi=function(r){return Ta(r)?r:void 0};_i.exports=function(r,e){return arguments.length<2?Mi(Wt[r])||Mi(Qt[r]):Wt[r]&&Wt[r][e]||Qt[r]&&Qt[r][e]}});var Ri=d((hp,Ai)=>{"use strict";var Sa=ee();Ai.exports=Sa({}.isPrototypeOf)});var Oi=d((up,Vi)=>{"use strict";var wa=q(),ki=wa.navigator,Pi=ki&&ki.userAgent;Vi.exports=Pi?String(Pi):""});var Di=d((dp,qi)=>{"use strict";var Bi=q(),Yt=Oi(),ji=Bi.process,Ni=Bi.Deno,Fi=ji&&ji.versions||Ni&&Ni.version,$i=Fi&&Fi.v8,B,rt;$i&&(B=$i.split("."),rt=B[0]>0&&B[0]<4?1:+(B[0]+B[1]));!rt&&Yt&&(B=Yt.match(/Edge\/(\d+)/),(!B||B[1]>=74)&&(B=Yt.match(/Chrome\/(\d+)/),B&&(rt=+B[1])));qi.exports=rt});var Zt=d((fp,Ui)=>{"use strict";var Hi=Di(),La=Y(),Ma=q(),_a=Ma.String;Ui.exports=!!Object.getOwnPropertySymbols&&!La(function(){var r=Symbol("symbol detection");return!_a(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Hi&&Hi<41})});var Xt=d((mp,Gi)=>{"use strict";var Aa=Zt();Gi.exports=Aa&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Jt=d((yp,zi)=>{"use strict";var Ra=Kt(),ka=Z(),Pa=Ri(),Va=Xt(),Oa=Object;zi.exports=Va?function(r){return typeof r=="symbol"}:function(r){var e=Ra("Symbol");return ka(e)&&Pa(e.prototype,Oa(r))}});var Qi=d((vp,Wi)=>{"use strict";var ja=String;Wi.exports=function(r){try{return ja(r)}catch(e){return"Object"}}});var er=d((gp,Ki)=>{"use strict";var Na=Z(),Fa=Qi(),$a=TypeError;Ki.exports=function(r){if(Na(r))return r;throw new $a(Fa(r)+" is not a function")}});var Zi=d((bp,Yi)=>{"use strict";var Ba=er(),qa=Ut();Yi.exports=function(r,e){var t=r[e];return qa(t)?void 0:Ba(t)}});var Ji=d((Cp,Xi)=>{"use strict";var tr=tt(),rr=Z(),ir=Se(),Da=TypeError;Xi.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 Da("Can't convert object to primitive value")}});var tn=d((Ep,en)=>{"use strict";en.exports=!0});var sn=d((Ip,nn)=>{"use strict";var rn=q(),Ha=Object.defineProperty;nn.exports=function(r,e){try{Ha(rn,r,{value:e,configurable:!0,writable:!0})}catch(t){rn[r]=e}return e}});var nr=d((xp,ln)=>{"use strict";var Ua=tn(),Ga=q(),za=sn(),an="__core-js_shared__",on=ln.exports=Ga[an]||za(an,{});(on.versions||(on.versions=[])).push({version:"3.38.0",mode:Ua?"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 hn=d((Tp,pn)=>{"use strict";var cn=nr();pn.exports=function(r,e){return cn[r]||(cn[r]=e||{})}});var sr=d((Sp,un)=>{"use strict";var Wa=Gt(),Qa=Object;un.exports=function(r){return Qa(Wa(r))}});var it=d((wp,dn)=>{"use strict";var Ka=ee(),Ya=sr(),Za=Ka({}.hasOwnProperty);dn.exports=Object.hasOwn||function(e,t){return Za(Ya(e),t)}});var mn=d((Lp,fn)=>{"use strict";var Xa=ee(),Ja=0,eo=Math.random(),to=Xa(1 .toString);fn.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+to(++Ja+eo,36)}});var gn=d((Mp,vn)=>{"use strict";var ro=q(),io=hn(),yn=it(),no=mn(),so=Zt(),ao=Xt(),fe=ro.Symbol,ar=io("wks"),oo=ao?fe.for||fe:fe&&fe.withoutSetter||no;vn.exports=function(r){return yn(ar,r)||(ar[r]=so&&yn(fe,r)?fe[r]:oo("Symbol."+r)),ar[r]}});var In=d((_p,En)=>{"use strict";var lo=tt(),bn=Se(),Cn=Jt(),co=Zi(),po=Ji(),ho=gn(),uo=TypeError,fo=ho("toPrimitive");En.exports=function(r,e){if(!bn(r)||Cn(r))return r;var t=co(r,fo),i;if(t){if(e===void 0&&(e="default"),i=lo(t,r,e),!bn(i)||Cn(i))return i;throw new uo("Can't convert object to primitive value")}return e===void 0&&(e="number"),po(r,e)}});var or=d((Ap,xn)=>{"use strict";var mo=In(),yo=Jt();xn.exports=function(r){var e=mo(r,"string");return yo(e)?e:e+""}});var wn=d((Rp,Sn)=>{"use strict";var vo=q(),Tn=Se(),lr=vo.document,go=Tn(lr)&&Tn(lr.createElement);Sn.exports=function(r){return go?lr.createElement(r):{}}});var cr=d((kp,Ln)=>{"use strict";var bo=de(),Co=Y(),Eo=wn();Ln.exports=!bo&&!Co(function(){return Object.defineProperty(Eo("div"),"a",{get:function(){return 7}}).a!==7})});var An=d(_n=>{"use strict";var Io=de(),xo=tt(),To=gi(),So=Dt(),wo=Si(),Lo=or(),Mo=it(),_o=cr(),Mn=Object.getOwnPropertyDescriptor;_n.f=Io?Mn:function(e,t){if(e=wo(e),t=Lo(t),_o)try{return Mn(e,t)}catch(i){}if(Mo(e,t))return So(!xo(To.f,e,t),e[t])}});var kn=d((Vp,Rn)=>{"use strict";var Ao=Y(),Ro=Z(),ko=/#|\.prototype\./,we=function(r,e){var t=Vo[Po(r)];return t===jo?!0:t===Oo?!1:Ro(e)?Ao(e):!!e},Po=we.normalize=function(r){return String(r).replace(ko,".").toLowerCase()},Vo=we.data={},Oo=we.NATIVE="N",jo=we.POLYFILL="P";Rn.exports=we});var On=d((Op,Vn)=>{"use strict";var Pn=Bt(),No=er(),Fo=Te(),$o=Pn(Pn.bind);Vn.exports=function(r,e){return No(r),e===void 0?r:Fo?$o(r,e):function(){return r.apply(e,arguments)}}});var Nn=d((jp,jn)=>{"use strict";var Bo=de(),qo=Y();jn.exports=Bo&&qo(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var $n=d((Np,Fn)=>{"use strict";var Do=Se(),Ho=String,Uo=TypeError;Fn.exports=function(r){if(Do(r))return r;throw new Uo(Ho(r)+" is not an object")}});var Dn=d(qn=>{"use strict";var Go=de(),zo=cr(),Wo=Nn(),nt=$n(),Bn=or(),Qo=TypeError,pr=Object.defineProperty,Ko=Object.getOwnPropertyDescriptor,hr="enumerable",ur="configurable",dr="writable";qn.f=Go?Wo?function(e,t,i){if(nt(e),t=Bn(t),nt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&dr in i&&!i[dr]){var n=Ko(e,t);n&&n[dr]&&(e[t]=i.value,i={configurable:ur in i?i[ur]:n[ur],enumerable:hr in i?i[hr]:n[hr],writable:!1})}return pr(e,t,i)}:pr:function(e,t,i){if(nt(e),t=Bn(t),nt(i),zo)try{return pr(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new Qo("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Un=d(($p,Hn)=>{"use strict";var Yo=de(),Zo=Dn(),Xo=Dt();Hn.exports=Yo?function(r,e,t){return Zo.f(r,e,Xo(1,t))}:function(r,e,t){return r[e]=t,r}});var Wn=d((Bp,zn)=>{"use strict";var Le=q(),Jo=si(),el=Bt(),tl=Z(),rl=An().f,il=kn(),me=zt(),nl=On(),ye=Un(),Gn=it();nr();var sl=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 Jo(r,this,arguments)};return e.prototype=r.prototype,e};zn.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,s=r.proto,l=i?Le:n?Le[t]:Le[t]&&Le[t].prototype,o=i?me:me[t]||ye(me,t,{})[t],a=o.prototype,c,u,m,f,C,x,A,g,h;for(f in e)c=il(i?f:t+(n?".":"#")+f,r.forced),u=!c&&l&&Gn(l,f),x=o[f],u&&(r.dontCallGetSet?(h=rl(l,f),A=h&&h.value):A=l[f]),C=u&&A?A:e[f],!(!c&&!s&&typeof x==typeof C)&&(r.bind&&u?g=nl(C,Le):r.wrap&&u?g=sl(C):s&&tl(C)?g=el(C):g=C,(r.sham||C&&C.sham||x&&x.sham)&&ye(g,"sham",!0),ye(o,f,g),s&&(m=t+"Prototype",Gn(me,m)||ye(me,m,{}),ye(me[m],f,C),r.real&&a&&(c||!a[f])&&ye(a,f,C)))}});var Kn=d((qp,Qn)=>{"use strict";var al=Math.ceil,ol=Math.floor;Qn.exports=Math.trunc||function(e){var t=+e;return(t>0?ol:al)(t)}});var fr=d((Dp,Yn)=>{"use strict";var ll=Kn();Yn.exports=function(r){var e=+r;return e!==e||e===0?0:ll(e)}});var Xn=d((Hp,Zn)=>{"use strict";var cl=fr(),pl=Math.min;Zn.exports=function(r){var e=cl(r);return e>0?pl(e,9007199254740991):0}});var es=d((Up,Jn)=>{"use strict";var hl=Xn();Jn.exports=function(r){return hl(r.length)}});var rs=d((Gp,ts)=>{"use strict";ts.exports=function(){}});var is=d(()=>{"use strict";var ul=Wn(),dl=sr(),fl=es(),ml=fr(),yl=rs();ul({target:"Array",proto:!0},{at:function(e){var t=dl(this),i=fl(t),n=ml(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});yl("at")});var ss=d((Qp,ns)=>{"use strict";var vl=Kt();ns.exports=vl});var os=d((Kp,as)=>{"use strict";is();var gl=ss();as.exports=gl("Array","at")});var cs=d((Yp,ls)=>{"use strict";var bl=os();ls.exports=bl});var mr=d((Zp,ps)=>{"use strict";var Cl=cs();ps.exports=Cl});var Gr="1.0.23-dev.8a9f6a57.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 N="interactive",na="interactive-controls-container",He=()=>document.querySelector(`.${na}`),zr=.4,j={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Wr=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Wr||{}),Qr=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(Qr||{}),Kr=(i=>(i.start="left",i.end="right",i.center="center",i))(Kr||{}),Ue=({target:r,props:e})=>{var t,i,n,s,l,o;r.style.alignItems=(i=((t=e.text)==null?void 0:t.gravityVertical)&&Wr[e.text.gravityVertical])!=null?i:"center",r.style.justifyContent=(s=((n=e.text)==null?void 0:n.gravityHorizontal)&&Qr[e.text.gravityHorizontal])!=null?s:"center",r.style.textAlign=(o=((l=e.text)==null?void 0:l.alignment)&&Kr[e.text.alignment])!=null?o:"left"},Ge=({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},ze=({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)},We=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,l,o,a,c,u,m,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=(m=(u=e==null?void 0:e.shape)==null?void 0:u.border)==null?void 0:m.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})`},he=({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:j.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 Qe=r=>{if(r.type.trim().toLowerCase()==="area")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(`${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",ze({target:i,props:this.control.props,fallback:{...j,backgroundColor:"transparent"}}),We({target:i,props:this.control.props,fallback:{...j,borderAlpha:0},dependsOn:this.container.dimensions}),he({target:i,layoutParams:this.control.layoutParams,fallback:j}),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 Ke=()=>{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 Ye=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",he({target:i,layoutParams:this.control.layoutParams,fallback:j}),ze({target:i,props:this.control.props,fallback:j}),We({target:i,props:this.control.props,fallback:j,dependsOn:this.container.dimensions}),Ue({target:i,props:this.control.props});let n=Ke();Ge({target:n,props:this.control.props,fallback:j,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 Yr=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",he({target:i,layoutParams:this.control.layoutParams,fallback:j}),Ue({target:i,props:this.control.props});let n=Ke();Ge({target:n,props:this.control.props,fallback:j,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}},Ze=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,Xe,Zr,ue=class{constructor(e){O(this,K);this.container=e,this.factories=new Map,Ie(this,K,Xe).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),Ie(this,K,Xe).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),Ie(this,K,Xe).call(this)}};K=new WeakSet,Xe=function(){this.controls=Ie(this,K,Zr).call(this)},Zr=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 Je=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new jt(r,e)},jt=class extends ue{constructor(e,t){super(e),this.rootElement=t!=null?t:He(),this.layout=new Ze(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Ye),this.addControlFactory("text",Yr),this.addControlFactory("area",Qe)}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=zr,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 Ys=Hr(mr(),1);import{clientChecker as ec,combine as tc,InterfaceLanguage as rc,Observable as Ws,once as ic,Subject as Ee,Subscription as Qs,ValueSubject as F}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as qe}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as El}from"@vkontakte/videoplayer-shared";function Me(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var te=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,_e=r=>te(r,"Object"),st=r=>te(r,"String"),at=r=>te(r,"Array"),ot=r=>te(r,"Number"),hs=r=>te(r,"Function");var yr=r=>ot(r)&&!isNaN(r);var re=r=>_e(r)&&Object.keys(r).length===0,vr=r=>at(r)&&!r.length;var Ae=(r,e)=>st(r)&&(e?r.trim():r).length;var us="video_interactive",ds="videoint";var fs=250,Re=class{constructor(e){this.handleZoomChange=Me(e=>{this.lastZoomInfo=e},fs);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,!ot(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=Il(e),this.resizeObserver=new ResizeObserver(Me(this.onResize,fs)),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 El(this.lang,us,ds)}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 Il(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 ke=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 xl}from"uuid";var Tl="3.1",ms={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Sl={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},ys=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,u=[Sl];switch(o){case"await":c?u=[]:s=[];break;case"default":{let m={type:"onSuspense",action:{type:ms.default,args:{branchId:i,shouldOpenNow:!c,isDetachContainer:!0}}};c?u=[m]:s=[m];break}case"random":case"weightlessRandom":case"max":case"min":{let m={type:"onSuspense",action:{type:ms[o],args:{}}};c?u=[m]:s=[m];break}}for(let m of a.controls)l.push({...a,controls:[{...m}],id:xl(),events:u})}e.push({...t,containers:l,events:s,branches:n})}return r.metadata.version=Tl,r.metadata.updated=new Date().toISOString(),{...r,chapters:e}};var wl="3.2",vs=r=>{if(!r.media){let{media:e,...t}=r.metadata;return{...r,metadata:{...t,version:wl},media:e}}return r};var Ll="3.3",Ml=(r=[])=>({edit:{chapters:r},view:{}}),gs={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},bs=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(u=>{var m;return{...u,controls:u.controls.map(({subtype:f,type:C,...x})=>({...x,type:f!=null?f:C})),events:(m=u.events)!=null&&m.length?u.events:[gs]}});e.push({id:s,...a,containers:c,events:(i=a.events)!=null&&i.length?a.events:[gs]}),t.push({id:s,x:l,y:o})}return{...r,chapters:e,graph:Ml(t),metadata:{...r.metadata,version:Ll}}};var _l=[{version:"3.0",migrate:ys},{version:"3.1",migrate:vs},{version:"3.2",migrate:bs}],gr=r=>_l.reduce((e,t)=>X(e.metadata.version,t.version)?e:t.migrate(e),r);var Cs={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 Es={metadata:"Object",chapters:"Array"},Al="3.0.0",Rl="3.3.0",lt=r=>{let e=X(r,Al);return e===-1?!1:e===0?!0:X(r,Rl)!==1},Is=r=>{if(!_e(r))return!1;for(let e in Es)if(!r[e]||!te(r[e],Es[e]))return!1;return lt(r.metadata.version)},ct=r=>r.type===Cs.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 pt=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 ht=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{hs(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 Fl}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 kl(...this.loaders[e])(t)}};function kl(...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 dt({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,dt.name,"Could not find media"),actions:r}}}return{...i,errors:Pe(e,dt.name,"Could not find chapter"),actions:r}}var ft=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 ft{constructor(){super(),this.listeners||ft.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)}},Ve=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&&(Ve.prototype[Symbol.toStringTag]="AbortController",ve.prototype[Symbol.toStringTag]="AbortSignal");function mt(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(!mt({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,u){let m;u&&u.signal&&(m=u.signal,delete u.signal);let f=new t(c,u);return m&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),f},s.prototype=t.prototype);let l=e;return{fetch:(a,c)=>{let u=s&&s.prototype.isPrototypeOf(a)?a.signal:c?c.signal:void 0;if(u){let m;try{m=new DOMException("Aborted","AbortError")}catch(C){m=new Error("Aborted"),m.name="AbortError"}if(u.aborted)return Promise.reject(m);let f=new Promise((C,x)=>{u.addEventListener("abort",()=>x(m),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([f,l(a,c)])}return l(a,c)},Request:s}}var Oe=mt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),xs=Oe?br({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Cr=Oe?xs.fetch:window.fetch,Qh=Oe?xs.Request:window.Request,Kh=Oe?Ve:window.AbortController,Yh=Oe?ve:window.AbortSignal;var Pl=async r=>{try{let e={},t;if(st(r)){t=new URL(r).href;let n=await Cr(t);if(!n.ok)return{};e=await n.json()}else if(_e(r))e=r;else return{};if(!Is(e))return{};let i=e.metadata.media;if(st(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=await Cr(n);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch(n){return jl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Ts(r){let{manifest:e,manifestURL:t}=await Pl(r),i=gr(e);return i.media=Vl(i.media,t),delete i.metadata.media,i}function yt(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 Vl(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=Ol(n,e);return{...i,url:s||n}})}))}}function Ol(r="",e){try{return new URL(r,e).href}catch(t){return""}}function jl(r){return X(r,"3.2.0")>=0}var vt=r=>at(r)&&!vr(r),D=r=>r.order==="end",gt=r=>at(r.containers)&&!vr(r.containers)&&D(r),Ss=(r,e)=>{var i;let t=r*1e3;return vt(e.controls)&&t<((i=e.startTime)!=null?i:0)},xr=(r,e)=>{var i,n;let t=r*1e3;return vt(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,bt=r=>Nl(r)&&ct(r[0]);function ws(r,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?r({...e[0],...t}):r(...e,...t)}var Ls=(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 Fl(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 Ts((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",dt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Er,getChapter:yt,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=yt(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=yt(((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?D(this.chapter):!1}};import{Player as $l}from"@vkontakte/videoplayer-core";import{Subscription as Lr,Tracer as Bl,ValueSubject as ql}from"@vkontakte/videoplayer-shared";var Ms=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 je=(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 Dl=2;function Mr(r){let e=Sr(),t=new Lr,i={},n=null,s=!1,l,o=new ql(null);r&&a(r);function a(g){n=g}function c(g,h,p){var y;if(!n)throw Error("need to set interactive controller");if(!n.options)return;let E=((y=e.map.get(g))!=null?y:{})[h];if(E){i={chapterId:p,listId:g,itemId:h,...E};let M=i.player;i.subscription.add(M.info.currentQuality$.subscribe(S=>{let k=M.info.position$.getValue(),T=M.info.isAutoQualityEnabled$.getValue();if(!(!S||!k||T))for(let _ of e.map)Object.values(_[1]).forEach(({player:P})=>{je(P,S)})})).add(M.events.started$.subscribe(()=>{u(h)})),E.container.remove(),n.setPlayer(E.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 u(g){if(!n)throw Error("need to set interactive controller");if(re(i)||g!==i.itemId)return;let h=n.getChapterBranches(),p=new Set;for(let v of h)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 m({chapter:{id:g},manifestVideo:h}){if(re(i)||!n)return;let p=i.player.info.muted$.getValue(),v=i.player.info.currentQuality$.getValue(),E=i.player.info.isAutoQualityEnabled$.getValue(),y=i.player.info.volume$.getValue(),M=i.player.info.currentPlaybackRate$.getValue(),S=!E,k=!1;for(let T of e.map)if(T[0]===h.id&&!n.state.isReplay$.getValue()){let _=Object.keys(T[1]);for(let P of _)P===i.itemId?(_.length<Dl||(k=!0),e.removePlayer(T[0],P)):(k=!0,c(T[0],P,g),S?je(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(y),i.player.setMuted(p),i.player.setPlaybackRate(M))}else e.removePlayer(T[0]);k||(await f({media:h,chapterId:g,setAsActive:!0,playbackRate:M}),S?je(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(y),i.player.setMuted(p))}async function f({media:g,chapterId:h,prefetch:p=!0,setAsActive:v=!0,autoplay:E=!1,preferredExt:y,title:M,playbackRate:S}){var Or,jr,Nr,Fr,$r;let k=Math.random().toString(),T=document.createElement("div");l.append(T);let _;if((Or=n==null?void 0:n.options)!=null&&Or.vkVideoLoader){let De=Ms(g);De.length&&(_=await n.options.vkVideoLoader(...De))}let P=((jr=n==null?void 0:n.options)==null?void 0:jr.coreConfig)||void 0,le={...P,configName:[...(Nr=P==null?void 0:P.configName)!=null?Nr:[],"interactive"]},ce={container:T,...((Fr=_==null?void 0:_.videos)==null?void 0:Fr[0])||{sources:wr(g,y).sources},title:M,failoverHosts:(_==null?void 0:_.failoverHosts)||[]},Q=new $l(le,Bl.createRootTracer());Q.initVideo(ce);let Pr=null;if(_!=null&&_.videos&&(n!=null&&n.options.createOneStat)){let De=_.videos[0],Mt=n.options.createOneStat(De),Br=new Lr;Mt&&(Br.add(Mt.attachTo(Q)),Pr={oneStat:Mt,statSubscription:Br})}let Vr=new Lr,Zs=($r=i==null?void 0:i.player)==null?void 0:$r.info.isAutoQualityEnabled$.getValue();Vr.add(Q.events.canplay$.subscribe(function(){Zs||je(Q,i.player.info.currentQuality$.getValue()),S&&Q.setPlaybackRate(S)}));let pe=e.createPlayer({listId:g.id,itemId:k,player:Q,container:T,sources:wr(g,y).sources,config:ce,subscription:Vr,statistics:Pr});return v&&c(g.id,pe.itemId,h),E&&pe.player.play(),p&&!E&&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:h}=n.getCurrentChapter();g&&h?(t.add(n.events.chapterChanged$.subscribe(m)),await f({media:g,chapterId:h.id,title:h.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 Hl}from"@vkontakte/videoplayer-shared";var Ct=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEvents:l,globalEventEmitter:o,ignoreContainerEvent:a,permanentTextControls:c,disabledControls$:u,onRemove:m}){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=ws(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 c;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(Ss(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 u=this.gameState;this.gameState=3,u===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=xr(s,this.container.container),o=this.container.container.startTime?[this.container.container.startTime,(c=this.container.container.endTime)!=null?c:1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:o,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(b.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new Hl,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=c&&bt(t.container.controls),this.disabledControls$=u,this.onRemove=m,this.globalEventEmitter=o,this.gameState=0,this.globalEvents=l,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 _s=(r=[])=>r.reduce((e,t,i)=>{var s,l,o;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(a=>!ct(a));if(vt(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 u=[],m=-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]>m&&(m=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]&&(u.push(A),C=C.concat(g.subjects)),a[0]>=g.range[0]&&a[0]<=g.range[1]&&(u.push(A),C=C.concat(g.subjects),a[0]=g.range[0]),a[1]>=g.range[0]&&a[1]<=g.range[1]&&(u.push(A),C=C.concat(g.subjects),a[1]=g.range[1])}if(x.push(c),a[0]<=f&&a[1]>=m)return[{subjects:x,range:a}];u.length&&u.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 As(){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 u;if(yr(o)){let m=(u=r[o])!=null?u:null;if(m&&a&&Ae(a,!0)){let f={},C=m[a];if(C&&(f={...f,...C}),f=re(f)?null:f,f&&Ae(c,!0)){let x=f[c];return x!=null?x:null}return f}return m}return null}function s({timestamp:o,priority:a,initiator:c}){if(yr(o))if(r[o]){if(a&&Ae(a,!0))if(r[o][a]){if(c&&Ae(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,...u}){var m,f,C;(f=(m=r[o])==null?void 0:m[a])!=null&&f[c]?r[o][a][c].push({...u}):(C=r[o])!=null&&C[a]?r[o][a]={...r[o][a],[c]:[{...u}]}:r[o]?r[o]={...r[o],[a]:{[c]:[{...u}]}}:r[o]={[a]:{[c]:[{...u}]}}}return{map:r,remove:s,add:l,removeAll:e,get:n,getLte:t,getGte:i}}var Ul=[L.expect,L.setNextBranch],Gl=1/0;function Rs(r){let e=r,t,i=zl(),n=As(),s,l=()=>{f(),h()},o=p=>{n.add.call(void 0,p),x()},a=(p=[])=>{for(let v of p)if(v.action(),Ul.includes(v.actionType))break},c=(p=1/0)=>{var M,S,k;let v=Et((M=n.get({timestamp:p,priority:"control"}))!=null?M:{}),E=Et((S=n.get({timestamp:p,priority:"container"}))!=null?S:{}),y=Et((k=n.get({timestamp:p,priority:"chapter"}))!=null?k:{});return[...v,...E,...y]},u=p=>{i.isReady(p)&&a(c(p))},m=()=>{var p;a([...Et((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(()=>{u(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)},h=()=>{i.release(),n.removeAll()};return{setPlayer:A,add:o,remove:g,exec:u,execEndOfVideo:m,listen:x,unlisten:f,release:l,containersEventsCallState:i,getPreparedToExecActions:c}}function zl(){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 u=(o=c.endTime)!=null?o:Gl,m=(a=r.get(u))!=null?a:{};r.set(u,{...m,[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 Et(r){return Object.values(r).flat().sort(e=>e.actionType===L.expect?-1:1)}var ks={videoContentHeight:0,videoContentWidth:0},Ps=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return ks;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return ks;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 Wl=250;function Vs(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:u,videoContentHeight:m}=Ps(a,c);a.style.setProperty("--interactive-content-width",`${u}px`),a.style.setProperty("--interactive-content-height",`${m}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=Me(o=>{let{fns:a=[]}=r();i(o);for(let c of a)c()},Wl);function l(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e==null||e()},release:l}}var Fe=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 Ql=r=>Math.floor(Math.random()*r),js=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 Fs=r=>{let e=r.length,t=Ql(e);return r[t]},Os=1,$s=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:Os;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:Os,e>=t)return r[s];return r[r.length-1]};var Bs={shouldOpenNow:!0,isDetachContainer:!0};var _r=(r,e=!1)=>({...r,args:e?{...r.args,...Bs}:{...Bs,...r.args}}),Hs=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:h,controlType:p,controlId:v,containerId:E,branches:y=[],onEvent:M,isEOV:S=()=>!1,isDisabled:k=()=>!1})=>{let T=_r(h,S()),_={timestamp:1/0,priority:"control",initiator:v,actionType:T.type},P=k(),le=r.emit.bind(r,b.interactives,{subjectId:v,subjectType:p,subjectName:"control",type:P?w.actionChoiceCanceled:w.actionChoice,actionType:h.type,payload:{containerId:E,...T.args}});if(P){le();return}switch(T.type.trim().toLowerCase()){case L.setNextBranch.trim().toLowerCase():{let ce=y.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:h}):t.add({..._,action:C.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:h})});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:h.args.uri}}):(t.add({..._,action:g.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:T,payload:{URI:h.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:h,container:{id:p,endTime:v},branches:E=[],isEOV:y=!1,autoSelected:M=!1})=>{let S=_r(h,y),k={timestamp:!S.args.shouldOpenNow||y?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 _=E.find(P=>P.id===S.args.branchId);if(!_)return;T(),t.add({...k,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({...k,action:C.bind(null,{subjectId:p,subjectName:"container",action:S})});return}case L.openURI.trim().toLowerCase():{T(),t.add({...k,action:g.bind(null,{subjectId:p,subjectName:"container",action:S,payload:{URI:h.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:h,branches:p,isEOV:v=!1}){var y,M;let E=Tr(h.events);if(E){let S=_r(E.action,v);r.emit(b.interactives,{subjectId:h.id,subjectName:"container",type:w.actionChoice,actionType:S.type,payload:S.args}),t.add({timestamp:v?1/0:(y=h.endTime)!=null?y:1/0,priority:"container",initiator:h.id,actionType:L.expect,action:m.bind(null,{subjectId:h.id,subjectName:"container"})}),n.isExpect=!0}else for(let S of(M=h.events)!=null?M:[])o({action:S.action,container:h,branches:p,isEOV:v})}let c=({chapterId:h,action:p,branches:v=[]})=>{let E=r.emit.bind(r,b.interactives,{subjectId:h,subjectName:"chapter",type:w.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case L.setNextBranch.trim().toLowerCase():{let y=v.find(M=>M.id===p.args.branchId);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setWeightlessRandomBranch.trim().toLowerCase():{let y=Fs(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setRandomBranch.trim().toLowerCase():{let y=$s(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setMaxWeightBranch.trim().toLowerCase():{let y=Ns(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.setMinWeightBranch.trim().toLowerCase():{let y=js(v);return y!=null&&y.chapterId?(E(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case L.continuePlayback.trim().toLowerCase():return E(),C.bind(null,{subjectId:h,subjectName:"chapter",action:p});case L.openURI.trim().toLowerCase():return E(),g.bind(null,{subjectId:h,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 u(h){var v;let p=Tr(h.events);if(p){if(D(h))return;r.emit(b.interactives,{subjectId:h.id,subjectName:"chapter",type:w.actionChoice,actionType:p.action.type,payload:p.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:L.expect,action:m.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else(v=h.events)==null||v.forEach(E=>{let y=c({chapterId:h.id,action:E.action,branches:h.branches});y&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:E.action.type,action:y})})}let m=({subjectId:h,subjectName:p})=>{e.pause(),r.emit(b.interactives,{subjectId:h,subjectName:p,type:w.actionExecution,actionType:L.expect})},f=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(b.interactives,{subjectId:h,subjectName:p,type:w.actionExecution,actionType:"after-expect"})},C=({subjectId:h,subjectName:p,subjectType:v,action:E})=>{r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type})},x=({subjectId:h,subjectName:p,subjectType:v,action:E,payload:y})=>{y.behaviour="change-chapter",r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type,payload:y})},A=({subjectId:h,subjectName:p,subjectType:v,action:E,payload:y})=>{y.behaviour="change-manifest",r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type,payload:y})},g=({subjectId:h,subjectName:p,subjectType:v,action:E,payload:y})=>{if(!y.URI)return;let M=window.open(y.URI,"_blank","noopener,noreferrer");M&&(M.opener=null),r.emit(b.interactives,{subjectId:h,subjectName:p,subjectType:v,type:w.actionExecution,actionType:E.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:c,onExpectEvent:m,expectEventHandler:f,setManifestChapterEvents:u,setManifestContainerEvents:a,stopExpect:s,state:n}};var kr=Hr(mr(),1);import{Subscription as Jl,Subject as Rr,ValueSubject as $e}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]=Us(s)}return t[i]}).filter(Boolean)},Yl=r=>{for(let e of r.variants)if(Zl(e)&&"payload"in e)return e.payload.id},Zl=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",Us=r=>{let e=Yl(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},Xl=(r,e)=>{for(let t of r.media.videos)if(e===Us(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},Gs=(r,e)=>r.reduce((t,i)=>{let n=Xl(e,i);return n?[...t,n]:t},[]);var G,ne,se,$,It,z,W,H,ae,be,Ce,Be=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new $e([]),hasPrevChapter$:new $e(!1),prevChapter$:new $e(null),isInitialChapter$:new $e(!1),isGoBackLimited$:new $e(!1)};O(this,G,null);O(this,ne);O(this,se,!1);O(this,$,null);O(this,It,null);this.events={inited$:new Rr,destroyed$:new Rr,error$:new Rr};O(this,z,null);O(this,W,null);O(this,H,null);O(this,ae,new Jl);O(this,be,!1);O(this,Ce,0);var l;R(this,z,t),R(this,H,e),R(this,W,i),R(this,G,n),R(this,ne,s),this.state.history$&&I(this,ae)&&((l=I(this,ae))==null||l.add(this.state.history$.subscribe(o=>{var a,c;this.state.prevChapter$.next((0,kr.default)(o,-2)||null),this.state.hasPrevChapter$.next(o.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((c=(a=I(this,$))==null?void 0:a.metadata)==null?void 0:c.initChapterId)),this.state.isGoBackLimited$.next(I(this,Ce)===I(this,ne).maxLength-1)})))}async setManifest(e){if(!I(this,W)||!I(this,H))return;R(this,$,e),await this.getProjectHistory();let t=this.getInitialChapterId();await I(this,W).setChapter({chapterId:t,pushToHistory:!1}),I(this,se)||(R(this,se,!0),this.events.inited$.next({initChapterId:t}))}get inited(){return I(this,se)}async updateHistory(e,t=!0){var o;if(!I(this,$))return;I(this,be)?(R(this,be,!1),Ur(this,Ce)._++):R(this,Ce,0);let i=I(this,$),n=e.length-I(this,ne).maxLength,s=n>0?e.slice(n):e,l=Ar(s,i);if(R(this,It,l),this.state.history$.next(s),!(!t||!I(this,G)||!I(this,z)))try{await I(this,G).save(I(this,z),l)}catch(a){let c=new V(1,5,"Unable to save interactive history");this.events.error$.next(c),(o=I(this,H))==null||o.emit(b.errors,c)}}async goBack(){var i;if(!this.state||!I(this,W)){let n=new V(1,5,"Unable to save interactive history");return this.events.error$.next(n),(i=I(this,H))==null?void 0:i.emit(b.errors,n)}R(this,be,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await I(this,W).setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){var n;if(!I(this,$)||!I(this,z))return;let e=I(this,$),t=[this.getInitialVideoId()];if(I(this,G))try{let s=await I(this,G).get(I(this,z));s.length&&(t=s)}catch(s){let l=new V(1,5,"Error while trying to fetch data");this.events.error$.next(l),(n=I(this,H))==null||n.emit(b.errors,l)}let i=Gs(t,e);this.state.history$.next(i)}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,kr.default)(e,-1)||I(this,ne).initChapterId||((t=I(this,$))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(I(this,$)){let e=this.getInitialChapterId();return Ar([e],I(this,$)).pop()}return null}destroy(){var e,t;R(this,z,null),R(this,G,null),R(this,W,null),(e=I(this,ae))==null||e.unsubscribe(),R(this,ae,null),R(this,se,!1),(t=I(this,H))==null||t.emit(b.historyDestroyed),this.events.destroyed$.next(),R(this,H,null)}};G=new WeakMap,ne=new WeakMap,se=new WeakMap,$=new WeakMap,It=new WeakMap,z=new WeakMap,W=new WeakMap,H=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 xt=oe;var Tt=class{constructor(){this.bindingMap=new Fe}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new xt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=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 St=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 wt=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;