@vkontakte/videoplayer-interactive 1.0.26-dev.23975e61.0 → 1.0.26-dev.ac7b329a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es2015.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.26-dev.23975e61.0
3
- * Thu, 21 Nov 2024 08:14:08 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.26-dev.ac7b329a.0
3
+ * Thu, 21 Nov 2024 07:49:17 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-26/doc/
5
5
  */
6
- var ia=Object.create;var kt=Object.defineProperty,na=Object.defineProperties,sa=Object.getOwnPropertyDescriptor,aa=Object.getOwnPropertyDescriptors,oa=Object.getOwnPropertyNames,We=Object.getOwnPropertySymbols,la=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable;var Wr=r=>{throw TypeError(r)};var Gr=(r,e,t)=>e in r?kt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e)=>{for(var t in e||(e={}))Pt.call(e,t)&&Gr(r,t,e[t]);if(We)for(var t of We(e))zr.call(e,t)&&Gr(r,t,e[t]);return r},C=(r,e)=>na(r,aa(e));var j=(r,e)=>{var t={};for(var i in r)Pt.call(r,i)&&e.indexOf(i)<0&&(t[i]=r[i]);if(r!=null&&We)for(var i of We(r))e.indexOf(i)<0&&zr.call(r,i)&&(t[i]=r[i]);return t};var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ca=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of oa(e))!Pt.call(r,n)&&n!==t&&kt(r,n,{get:()=>e[n],enumerable:!(i=sa(e,n))||i.enumerable});return r};var Qr=(r,e,t)=>(t=r!=null?ia(la(r)):{},ca(e||!r||!r.__esModule?kt(t,"default",{value:r,enumerable:!0}):t,r));var Kr=(r,e,t)=>e.has(r)||Wr("Cannot "+t);var S=(r,e,t)=>(Kr(r,e,"read from private field"),t?t.call(r):e.get(r)),H=(r,e,t)=>e.has(r)?Wr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),O=(r,e,t,i)=>(Kr(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var Yr=(r,e,t,i)=>({set _(n){O(r,e,n,t)},get _(){return S(r,e,i)}});var w=(r,e,t)=>new Promise((i,n)=>{var s=a=>{try{l(t.next(a))}catch(c){n(c)}},o=a=>{try{l(t.throw(a))}catch(c){n(c)}},l=a=>a.done?i(a.value):Promise.resolve(a.value).then(s,o);l((t=t.apply(r,e)).next())});var z=f((qt,ii)=>{"use strict";var we=function(r){return r&&r.Math===Math&&r};ii.exports=we(typeof globalThis=="object"&&globalThis)||we(typeof window=="object"&&window)||we(typeof self=="object"&&self)||we(typeof global=="object"&&global)||we(typeof qt=="object"&&qt)||function(){return this}()||Function("return this")()});var J=f((Jc,ni)=>{"use strict";ni.exports=function(r){try{return!!r()}catch(e){return!0}}});var Le=f((ep,si)=>{"use strict";var ha=J();si.exports=!ha(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var pi=f((tp,ci)=>{"use strict";var ua=Le(),li=Function.prototype,ai=li.apply,oi=li.call;ci.exports=typeof Reflect=="object"&&Reflect.apply||(ua?oi.bind(ai):function(){return oi.apply(ai,arguments)})});var ne=f((rp,di)=>{"use strict";var hi=Le(),ui=Function.prototype,Dt=ui.call,da=hi&&ui.bind.bind(Dt,Dt);di.exports=hi?da:function(r){return function(){return Dt.apply(r,arguments)}}});var Ht=f((ip,mi)=>{"use strict";var fi=ne(),fa=fi({}.toString),ma=fi("".slice);mi.exports=function(r){return ma(fa(r),8,-1)}});var Ut=f((np,yi)=>{"use strict";var ya=Ht(),va=ne();yi.exports=function(r){if(ya(r)==="Function")return va(r)}});var ee=f((sp,vi)=>{"use strict";var Gt=typeof document=="object"&&document.all;vi.exports=typeof Gt=="undefined"&&Gt!==void 0?function(r){return typeof r=="function"||r===Gt}:function(r){return typeof r=="function"}});var ye=f((ap,gi)=>{"use strict";var ga=J();gi.exports=!ga(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var st=f((op,bi)=>{"use strict";var ba=Le(),nt=Function.prototype.call;bi.exports=ba?nt.bind(nt):function(){return nt.apply(nt,arguments)}});var xi=f(Ii=>{"use strict";var Ci={}.propertyIsEnumerable,Ei=Object.getOwnPropertyDescriptor,Ca=Ei&&!Ci.call({1:2},1);Ii.f=Ca?function(e){var t=Ei(this,e);return!!t&&t.enumerable}:Ci});var zt=f((cp,Ti)=>{"use strict";Ti.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var wi=f((pp,Si)=>{"use strict";var Ea=ne(),Ia=J(),xa=Ht(),Wt=Object,Ta=Ea("".split);Si.exports=Ia(function(){return!Wt("z").propertyIsEnumerable(0)})?function(r){return xa(r)==="String"?Ta(r,""):Wt(r)}:Wt});var Qt=f((hp,Li)=>{"use strict";Li.exports=function(r){return r==null}});var Kt=f((up,Mi)=>{"use strict";var Sa=Qt(),wa=TypeError;Mi.exports=function(r){if(Sa(r))throw new wa("Can't call method on "+r);return r}});var Ai=f((dp,_i)=>{"use strict";var La=wi(),Ma=Kt();_i.exports=function(r){return La(Ma(r))}});var Me=f((fp,Ri)=>{"use strict";var _a=ee();Ri.exports=function(r){return typeof r=="object"?r!==null:_a(r)}});var Yt=f((mp,ki)=>{"use strict";ki.exports={}});var Jt=f((yp,Vi)=>{"use strict";var Zt=Yt(),Xt=z(),Aa=ee(),Pi=function(r){return Aa(r)?r:void 0};Vi.exports=function(r,e){return arguments.length<2?Pi(Zt[r])||Pi(Xt[r]):Zt[r]&&Zt[r][e]||Xt[r]&&Xt[r][e]}});var ji=f((vp,Oi)=>{"use strict";var Ra=ne();Oi.exports=Ra({}.isPrototypeOf)});var Bi=f((gp,Fi)=>{"use strict";var ka=z(),Ni=ka.navigator,$i=Ni&&Ni.userAgent;Fi.exports=$i?String($i):""});var Wi=f((bp,zi)=>{"use strict";var Gi=z(),er=Bi(),qi=Gi.process,Di=Gi.Deno,Hi=qi&&qi.versions||Di&&Di.version,Ui=Hi&&Hi.v8,G,at;Ui&&(G=Ui.split("."),at=G[0]>0&&G[0]<4?1:+(G[0]+G[1]));!at&&er&&(G=er.match(/Edge\/(\d+)/),(!G||G[1]>=74)&&(G=er.match(/Chrome\/(\d+)/),G&&(at=+G[1])));zi.exports=at});var tr=f((Cp,Ki)=>{"use strict";var Qi=Wi(),Pa=J(),Va=z(),Oa=Va.String;Ki.exports=!!Object.getOwnPropertySymbols&&!Pa(function(){var r=Symbol("symbol detection");return!Oa(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Qi&&Qi<41})});var rr=f((Ep,Yi)=>{"use strict";var ja=tr();Yi.exports=ja&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var ir=f((Ip,Zi)=>{"use strict";var Na=Jt(),$a=ee(),Fa=ji(),Ba=rr(),qa=Object;Zi.exports=Ba?function(r){return typeof r=="symbol"}:function(r){var e=Na("Symbol");return $a(e)&&Fa(e.prototype,qa(r))}});var Ji=f((xp,Xi)=>{"use strict";var Da=String;Xi.exports=function(r){try{return Da(r)}catch(e){return"Object"}}});var nr=f((Tp,en)=>{"use strict";var Ha=ee(),Ua=Ji(),Ga=TypeError;en.exports=function(r){if(Ha(r))return r;throw new Ga(Ua(r)+" is not a function")}});var rn=f((Sp,tn)=>{"use strict";var za=nr(),Wa=Qt();tn.exports=function(r,e){var t=r[e];return Wa(t)?void 0:za(t)}});var sn=f((wp,nn)=>{"use strict";var sr=st(),ar=ee(),or=Me(),Qa=TypeError;nn.exports=function(r,e){var t,i;if(e==="string"&&ar(t=r.toString)&&!or(i=sr(t,r))||ar(t=r.valueOf)&&!or(i=sr(t,r))||e!=="string"&&ar(t=r.toString)&&!or(i=sr(t,r)))return i;throw new Qa("Can't convert object to primitive value")}});var on=f((Lp,an)=>{"use strict";an.exports=!0});var pn=f((Mp,cn)=>{"use strict";var ln=z(),Ka=Object.defineProperty;cn.exports=function(r,e){try{Ka(ln,r,{value:e,configurable:!0,writable:!0})}catch(t){ln[r]=e}return e}});var lr=f((_p,dn)=>{"use strict";var Ya=on(),Za=z(),Xa=pn(),hn="__core-js_shared__",un=dn.exports=Za[hn]||Xa(hn,{});(un.versions||(un.versions=[])).push({version:"3.38.0",mode:Ya?"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 yn=f((Ap,mn)=>{"use strict";var fn=lr();mn.exports=function(r,e){return fn[r]||(fn[r]=e||{})}});var cr=f((Rp,vn)=>{"use strict";var Ja=Kt(),eo=Object;vn.exports=function(r){return eo(Ja(r))}});var ot=f((kp,gn)=>{"use strict";var to=ne(),ro=cr(),io=to({}.hasOwnProperty);gn.exports=Object.hasOwn||function(e,t){return io(ro(e),t)}});var Cn=f((Pp,bn)=>{"use strict";var no=ne(),so=0,ao=Math.random(),oo=no(1 .toString);bn.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+oo(++so+ao,36)}});var xn=f((Vp,In)=>{"use strict";var lo=z(),co=yn(),En=ot(),po=Cn(),ho=tr(),uo=rr(),ve=lo.Symbol,pr=co("wks"),fo=uo?ve.for||ve:ve&&ve.withoutSetter||po;In.exports=function(r){return En(pr,r)||(pr[r]=ho&&En(ve,r)?ve[r]:fo("Symbol."+r)),pr[r]}});var Ln=f((Op,wn)=>{"use strict";var mo=st(),Tn=Me(),Sn=ir(),yo=rn(),vo=sn(),go=xn(),bo=TypeError,Co=go("toPrimitive");wn.exports=function(r,e){if(!Tn(r)||Sn(r))return r;var t=yo(r,Co),i;if(t){if(e===void 0&&(e="default"),i=mo(t,r,e),!Tn(i)||Sn(i))return i;throw new bo("Can't convert object to primitive value")}return e===void 0&&(e="number"),vo(r,e)}});var hr=f((jp,Mn)=>{"use strict";var Eo=Ln(),Io=ir();Mn.exports=function(r){var e=Eo(r,"string");return Io(e)?e:e+""}});var Rn=f((Np,An)=>{"use strict";var xo=z(),_n=Me(),ur=xo.document,To=_n(ur)&&_n(ur.createElement);An.exports=function(r){return To?ur.createElement(r):{}}});var dr=f(($p,kn)=>{"use strict";var So=ye(),wo=J(),Lo=Rn();kn.exports=!So&&!wo(function(){return Object.defineProperty(Lo("div"),"a",{get:function(){return 7}}).a!==7})});var On=f(Vn=>{"use strict";var Mo=ye(),_o=st(),Ao=xi(),Ro=zt(),ko=Ai(),Po=hr(),Vo=ot(),Oo=dr(),Pn=Object.getOwnPropertyDescriptor;Vn.f=Mo?Pn:function(e,t){if(e=ko(e),t=Po(t),Oo)try{return Pn(e,t)}catch(i){}if(Vo(e,t))return Ro(!_o(Ao.f,e,t),e[t])}});var Nn=f((Bp,jn)=>{"use strict";var jo=J(),No=ee(),$o=/#|\.prototype\./,_e=function(r,e){var t=Bo[Fo(r)];return t===Do?!0:t===qo?!1:No(e)?jo(e):!!e},Fo=_e.normalize=function(r){return String(r).replace($o,".").toLowerCase()},Bo=_e.data={},qo=_e.NATIVE="N",Do=_e.POLYFILL="P";jn.exports=_e});var Bn=f((qp,Fn)=>{"use strict";var $n=Ut(),Ho=nr(),Uo=Le(),Go=$n($n.bind);Fn.exports=function(r,e){return Ho(r),e===void 0?r:Uo?Go(r,e):function(){return r.apply(e,arguments)}}});var Dn=f((Dp,qn)=>{"use strict";var zo=ye(),Wo=J();qn.exports=zo&&Wo(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Un=f((Hp,Hn)=>{"use strict";var Qo=Me(),Ko=String,Yo=TypeError;Hn.exports=function(r){if(Qo(r))return r;throw new Yo(Ko(r)+" is not an object")}});var Wn=f(zn=>{"use strict";var Zo=ye(),Xo=dr(),Jo=Dn(),lt=Un(),Gn=hr(),el=TypeError,fr=Object.defineProperty,tl=Object.getOwnPropertyDescriptor,mr="enumerable",yr="configurable",vr="writable";zn.f=Zo?Jo?function(e,t,i){if(lt(e),t=Gn(t),lt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&vr in i&&!i[vr]){var n=tl(e,t);n&&n[vr]&&(e[t]=i.value,i={configurable:yr in i?i[yr]:n[yr],enumerable:mr in i?i[mr]:n[mr],writable:!1})}return fr(e,t,i)}:fr:function(e,t,i){if(lt(e),t=Gn(t),lt(i),Xo)try{return fr(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new el("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Kn=f((Gp,Qn)=>{"use strict";var rl=ye(),il=Wn(),nl=zt();Qn.exports=rl?function(r,e,t){return il.f(r,e,nl(1,t))}:function(r,e,t){return r[e]=t,r}});var Xn=f((zp,Zn)=>{"use strict";var Ae=z(),sl=pi(),al=Ut(),ol=ee(),ll=On().f,cl=Nn(),ge=Yt(),pl=Bn(),be=Kn(),Yn=ot();lr();var hl=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 sl(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,o=i?Ae:n?Ae[t]:Ae[t]&&Ae[t].prototype,l=i?ge:ge[t]||be(ge,t,{})[t],a=l.prototype,c,m,y,d,E,x,L,b,p;for(d in e)c=cl(i?d:t+(n?".":"#")+d,r.forced),m=!c&&o&&Yn(o,d),x=l[d],m&&(r.dontCallGetSet?(p=ll(o,d),L=p&&p.value):L=o[d]),E=m&&L?L:e[d],!(!c&&!s&&typeof x==typeof E)&&(r.bind&&m?b=pl(E,Ae):r.wrap&&m?b=hl(E):s&&ol(E)?b=al(E):b=E,(r.sham||E&&E.sham||x&&x.sham)&&be(b,"sham",!0),be(l,d,b),s&&(y=t+"Prototype",Yn(ge,y)||be(ge,y,{}),be(ge[y],d,E),r.real&&a&&(c||!a[d])&&be(a,d,E)))}});var es=f((Wp,Jn)=>{"use strict";var ul=Math.ceil,dl=Math.floor;Jn.exports=Math.trunc||function(e){var t=+e;return(t>0?dl:ul)(t)}});var gr=f((Qp,ts)=>{"use strict";var fl=es();ts.exports=function(r){var e=+r;return e!==e||e===0?0:fl(e)}});var is=f((Kp,rs)=>{"use strict";var ml=gr(),yl=Math.min;rs.exports=function(r){var e=ml(r);return e>0?yl(e,9007199254740991):0}});var ss=f((Yp,ns)=>{"use strict";var vl=is();ns.exports=function(r){return vl(r.length)}});var os=f((Zp,as)=>{"use strict";as.exports=function(){}});var ls=f(()=>{"use strict";var gl=Xn(),bl=cr(),Cl=ss(),El=gr(),Il=os();gl({target:"Array",proto:!0},{at:function(e){var t=bl(this),i=Cl(t),n=El(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});Il("at")});var ps=f((eh,cs)=>{"use strict";var xl=Jt();cs.exports=xl});var us=f((th,hs)=>{"use strict";ls();var Tl=ps();hs.exports=Tl("Array","at")});var fs=f((rh,ds)=>{"use strict";var Sl=us();ds.exports=Sl});var br=f((ih,ms)=>{"use strict";var wl=fs();ms.exports=wl});var Zr="1.0.26-dev.23975e61.0";function Vt(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var q="interactive",pa="interactive-controls-container",Qe=()=>document.querySelector(`.${pa}`),Xr=.4,F={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Jr=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Jr||{}),ei=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(ei||{}),ti=(i=>(i.start="left",i.end="right",i.center="center",i))(ti||{}),Ke=({target:r,props:e})=>{var t,i,n,s,o,l;r.style.alignItems=(i=((t=e.text)==null?void 0:t.gravityVertical)&&Jr[e.text.gravityVertical])!=null?i:"center",r.style.justifyContent=(s=((n=e.text)==null?void 0:n.gravityHorizontal)&&ei[e.text.gravityHorizontal])!=null?s:"center",r.style.textAlign=(l=((o=e.text)==null?void 0:o.alignment)&&ti[e.text.alignment])!=null?l:"left"},Ye=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,o,l,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} * ${(l=(o=e==null?void 0:e.text)==null?void 0:o.size)!=null?l: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,o;r.style.backgroundColor=Vt((n=(i=e==null?void 0:e.background)==null?void 0:i.color)!=null?n:t.backgroundColor,(o=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?o:t.backgroundAlpha)},Xe=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,o,l,a,c,m,y,d,E,x;r.style.border=`calc(${i.height} * ${(o=(s=(n=e==null?void 0:e.shape)==null?void 0:n.border)==null?void 0:s.width)!=null?o:t.borderWidth}) solid ${Vt((c=(a=(l=e==null?void 0:e.shape)==null?void 0:l.border)==null?void 0:a.color)!=null?c:t.borderColor,(d=(y=(m=e==null?void 0:e.shape)==null?void 0:m.border)==null?void 0:y.alpha)!=null?d:t.borderAlpha)}`,r.style.borderRadius=`calc(${i.height} * ${(x=(E=e==null?void 0:e.shape)==null?void 0:E.roundCorners)!=null?x:t.roundCorners})`},fe=({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 K=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(`${q}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let i=((n=this.control.layoutParams.innerSizesDependOn)!=null?n:F.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 Ot="int",ie=(i=>(i.AREA=`${Ot}_area`,i.TEXT=`${Ot}_text`,i.BUTTON=`${Ot}_bttn`,i))(ie||{});var Je=r=>{if(r.type.trim().toLowerCase()==="area")return new jt(r)},jt=class extends K{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(`${q}-${this.control.id}`),i.setAttribute("data-testid",ie.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:C(u({},F),{backgroundColor:"transparent"})}),Xe({target:i,props:this.control.props,fallback:C(u({},F),{borderAlpha:0}),dependsOn:this.container.dimensions}),fe({target:i,layoutParams:this.control.layoutParams,fallback:F}),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 et=()=>{let r=document.createElement("span");return r.style.display="inline-block",r.style.whiteSpace="pre",r.style.overflow="hidden",r.style.textOverflow="ellipsis",r.style.maxWidth="100%",r.style.maxHeight="100%",r};var tt=r=>{if(r.type.trim().toLowerCase()==="button")return new Nt(r)},Nt=class extends K{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(`${q}-${this.control.id}`),i.setAttribute("data-testid",ie.BUTTON),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.cursor="pointer",i.style.fontFamily="inherit",fe({target:i,layoutParams:this.control.layoutParams,fallback:F}),Ze({target:i,props:this.control.props,fallback:F}),Xe({target:i,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),Ke({target:i,props:this.control.props});let n=et();Ye({target:n,props:this.control.props,fallback:F,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 ri=r=>{if(r.type.trim().toLowerCase()==="text")return new $t(r)},$t=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("div");i.classList.add(`${q}-${this.control.id}`),i.setAttribute("data-testid",ie.TEXT),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.fontFamily="inherit",fe({target:i,layoutParams:this.control.layoutParams,fallback:F}),Ke({target:i,props:this.control.props});let n=et();Ye({target:n,props:this.control.props,fallback:F,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 Ft=class{constructor(e){this.layout=e}},rt=class extends Ft{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 me=class{constructor(e){this.container=e,this.factories=new Map,this.controls=[],this.setControls()}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){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);if(s){let o=s(i);if(o)return[...t,o]}return[...t]},[]))||[]}};var it=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new Bt(r,e)},Bt=class extends me{constructor(e,t){super(e),this.rootElement=t!=null?t:Qe(),this.layout=new rt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",tt),this.addControlFactory("text",ri),this.addControlFactory("area",Je)}createView(e){let t=document.createElement("div");return t.classList.add(`${q}-${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=`${Xr}`,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(`.${q}-${this.container.id}`)}};var ta=Qr(br(),1);import{clientChecker as ac,combine as oc,InterfaceLanguage as lc,Observable as Xs,once as cc,Subject as re,Subscription as Js,ValueSubject as D}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Ue}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Ll}from"@vkontakte/videoplayer-shared";function Re(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var se=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,ke=r=>se(r,"Object"),ct=r=>se(r,"String"),pt=r=>se(r,"Array"),ht=r=>se(r,"Number"),ys=r=>se(r,"Function");var Cr=r=>ht(r)&&!isNaN(r);var ae=r=>ke(r)&&Object.keys(r).length===0,Er=r=>pt(r)&&!r.length;var Pe=(r,e)=>ct(r)&&(e?r.trim():r).length;var vs="video_interactive",gs="videoint";var bs=250,Ve=class{constructor(e){this.handleZoomChange=Re(e=>{this.lastZoomInfo=e},bs);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,!ht(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=Ml(e),this.resizeObserver=new ResizeObserver(Re(this.onResize,bs)),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)}show(){return w(this,null,function*(){var e;this.manifest&&(this.ngEditor||(yield this.initNgEditor()),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&((e=this.ngEditor)==null||e.focusChapter(this.currentChapterId)),this.isHidden=!1)})}initNgEditor(){return w(this,null,function*(){if(!this.manifest)return;let e;try{e=yield Ll(this.lang,vs,gs)}catch(i){console.log("Unable to load graph language pack")}let{GraphEditor:t}=yield 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",s=>{var o=s,{name:i}=o,n=j(o,["name"]);var l;i==="openPreview"&&"chapterId"in n&&((l=this.onOpenPreviewClick)==null||l.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 Ml(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 Oe=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 o=s.startTime-e;if(o<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<o&&(t=t===-1?o:Math.min(t,o))}return!i&&t!==-1?t:null}}};var te=(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 _l}from"uuid";var Al="3.1",Cs={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Rl={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Es=r=>{let e=[];for(let o of r.chapters){let l,a=[];for(let t of o.branches){let i=t,{isDefault:y}=i,d=j(i,["isDefault"]);y&&(l=d.id),a.push(d)}let c=[],m=[];for(let n of o.containers){let s=n,{fallbackStrategy:y}=s,d=j(s,["fallbackStrategy"]);let E=!!d.endTime,x=[Rl];switch(y){case"await":E?x=[]:c=[];break;case"default":{let L={type:"onSuspense",action:{type:Cs.default,args:{branchId:l,shouldOpenNow:!E,isDetachContainer:!0}}};E?x=[L]:c=[L];break}case"random":case"weightlessRandom":case"max":case"min":{let L={type:"onSuspense",action:{type:Cs[y],args:{}}};E?x=[L]:c=[L];break}}for(let L of d.controls)m.push(C(u({},d),{controls:[u({},L)],id:_l(),events:x}))}e.push(C(u({},o),{containers:m,events:c,branches:a}))}return r.metadata.version=Al,r.metadata.updated=new Date().toISOString(),C(u({},r),{chapters:e})};var kl="3.2",Is=r=>{if(!r.media){let e=r.metadata,{media:t}=e,i=j(e,["media"]);return C(u({},r),{metadata:C(u({},i),{version:kl}),media:t})}return r};var Pl="3.3",Vl=(r=[])=>({edit:{chapters:r},view:{}}),xs={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ts=r=>{var n;let e=[],t=[];for(let s of r.chapters){let i=s,{id:o,x:l,y:a}=i,c=j(i,["id","x","y"]),m=c.containers.map(y=>{var d;return C(u({},y),{controls:y.controls.map(b=>{var p=b,{subtype:E,type:x}=p,L=j(p,["subtype","type"]);return C(u({},L),{type:E!=null?E:x})}),events:(d=y.events)!=null&&d.length?y.events:[xs]})});e.push(C(u({id:o},c),{containers:m,events:(n=c.events)!=null&&n.length?c.events:[xs]})),t.push({id:o,x:l,y:a})}return C(u({},r),{chapters:e,graph:Vl(t),metadata:C(u({},r.metadata),{version:Pl})})};var Ol=[{version:"3.0",migrate:Es},{version:"3.1",migrate:Is},{version:"3.2",migrate:Ts}],Ir=r=>Ol.reduce((e,t)=>te(e.metadata.version,t.version)?e:t.migrate(e),r);var Ss={Button:"Button",Area:"Area",Text:"Text"};var A={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var ws={metadata:"Object",chapters:"Array"},jl="3.0.0",Nl="3.3.0",ut=r=>{let e=te(r,jl);return e===-1?!1:e===0?!0:te(r,Nl)!==1},Ls=r=>{if(!ke(r))return!1;for(let e in ws)if(!r[e]||!se(r[e],ws[e]))return!1;return ut(r.metadata.version)},dt=r=>r.type===Ss.Text;var N=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var ft=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 mt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{ys(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 Ul}from"@vkontakte/videoplayer-shared";var yt=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:[]}}exec(e,t){return w(this,null,function*(){return $l(...this.loaders[e])(t)})}};function $l(...r){return function(t){return w(this,null,function*(){let i=[...r];for(;i.length>0;)t=yield i.shift()(t);return t})}}function je(r,e,t){return r?C(u({},r),{[e]:r[e]?[t,...r[e]]:[t]}):{[e]:[t]}}function vt(n){var s=n,{actions:r,errors:e,chapterId:t}=s,i=j(s,["actions","errors","chapterId"]);if(t){let o=r.getManifest(),l=r.getChapter(o.chapters,t);if(l){let a=r.getMedia(o.media,l.videoId),c=r.getGraph(o.graph,l.id);return a?C(u({},i),{actions:r,errors:e,result:{chapter:l,media:a,graph:c}}):C(u({},i),{errors:je(e,vt.name,"Could not find media"),actions:r})}}return C(u({},i),{errors:je(e,vt.name,"Could not find chapter"),actions:r})}var gt=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 o=i[n];try{o.callback.call(this,e)}catch(l){Promise.resolve().then(()=>{throw l})}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}},Ce=class extends gt{constructor(){super(),this.listeners||gt.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)}},Ne=class{constructor(){Object.defineProperty(this,"signal",{value:new Ce,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&&(Ne.prototype[Symbol.toStringTag]="AbortController",Ce.prototype[Symbol.toStringTag]="AbortSignal");function bt(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 xr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!bt({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,m){let y;m&&m.signal&&(y=m.signal,delete m.signal);let d=new t(c,m);return y&&Object.defineProperty(d,"signal",{writable:!1,enumerable:!1,configurable:!0,value:y}),d},s.prototype=t.prototype);let o=e;return{fetch:(a,c)=>{let m=s&&s.prototype.isPrototypeOf(a)?a.signal:c?c.signal:void 0;if(m){let y;try{y=new DOMException("Aborted","AbortError")}catch(E){y=new Error("Aborted"),y.name="AbortError"}if(m.aborted)return Promise.reject(y);let d=new Promise((E,x)=>{m.addEventListener("abort",()=>x(y),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([d,o(a,c)])}return o(a,c)},Request:s}}var $e=bt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ms=$e?xr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Tr=$e?Ms.fetch:window.fetch,su=$e?Ms.Request:window.Request,au=$e?Ne:window.AbortController,ou=$e?Ce:window.AbortSignal;var Fl=r=>w(void 0,null,function*(){try{let e={},t;if(ct(r)){t=new URL(r).href;let n=yield Tr(t);if(!n.ok)return{};e=yield n.json()}else if(ke(r))e=r;else return{};if(!Ls(e))return{};let i=e.metadata.media;if(ct(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=yield Tr(n);if(!s.ok)throw new Error;e.metadata.media=yield s.json()}catch(n){return Dl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}});function _s(r){return w(this,null,function*(){let{manifest:e,manifestURL:t}=yield Fl(r),i=Ir(e);return i.media=Bl(i.media,t),delete i.metadata.media,i})}function Ct(r,e){if(e)return r.find(t=>t.id===e)}function Sr(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 wr(r,e){return r.videos.find(t=>t.id===e)}function Bl(r,e){return C(u({},r),{videos:r.videos.map(t=>C(u({},t),{variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=ql(n,e);return C(u({},i),{url:s||n})})}))})}function ql(r="",e){try{return new URL(r,e).href}catch(t){return""}}function Dl(r){return te(r,"3.2.0")>=0}var Et=r=>pt(r)&&!Er(r),W=r=>r.order==="end",It=r=>pt(r.containers)&&!Er(r.containers)&&W(r),As=(r,e)=>{var i;let t=r*1e3;return Et(e.controls)&&t<((i=e.startTime)!=null?i:0)},Lr=(r,e)=>{var i,n;let t=r*1e3;return Et(e.controls)&&t>=((i=e.startTime)!=null?i:0)&&t<=((n=e.endTime)!=null?n:1/0)};var oe=(r=[])=>r.some(e=>e.action.type==="expect"),Mr=(r=[])=>r.find(e=>e.action.type==="expect"),Hl=r=>(r==null?void 0:r.length)===1,Ee=r=>Hl(r)&&dt(r[0]);function Rs(r,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?r(u(u({},e[0]),t)):r(...e,...t)}var ks=(r,e)=>oe(r.events)?!1:e.some(({container:t})=>t.container.id!==r.id&&oe(t.container.events)&&t.container.endTime===r.endTime&&!t.isRemoved);var Ie=class extends yt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Ul(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}setManifest(t){return w(this,null,function*(){var n;this.release();let i=yield this.exec("manifestLoaders",{actions:{addErrorMessage:je},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=yield _s((n=i.result)!=null?n:t),this})}setInitial(){return w(this,null,function*(){return this.setNext()})}setNext(){return w(this,arguments,function*(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let n=yield this.exec("chapterLoaders",vt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Sr,getChapter:Ct,getMedia:wr,getByBranches:this.getByBranches.bind(this),addErrorMessage:je},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=Ct(this.manifest.chapters,t);if(n){let s=wr(this.manifest.media,n.videoId),o=Sr(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:o}}return null}getBranches(t=(i=>(i=this.chapter)==null?void 0:i.id)()){var n,s,o;if(t===((n=this.chapter)==null?void 0:n.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let l=Ct(((o=this.manifest)==null?void 0:o.chapters)||[],t);return this.getByBranches(l==null?void 0:l.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?W(this.chapter):!1}};import{Player as Gl}from"@vkontakte/videoplayer-core";import{Subscription as Rr,Tracer as zl,ValueSubject as Wl}from"@vkontakte/videoplayer-shared";var Ps=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 _r(){let r=new Map;function e(a){var c=a,{listId:s=Math.random().toString(),itemId:o=Math.random().toString()}=c,l=j(c,["listId","itemId"]);let m=r.get(s),y=u({},l);return m?m[o]=y:r.set(s,{[o]:y}),u({listId:s,itemId:o},l)}function t(s){var o,l;s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),(o=s.statistics)==null||o.oneStat.destroy(),(l=s.statistics)==null||l.statSubscription.unsubscribe()}function i(s,o){let l=r.get(s);if(!l)throw Error("Can't remove. Not find.");if(o){let a=l[o];a&&t(a),delete l[o],Object.keys(l).length||r.delete(s)}else{for(let a of Object.values(l))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 Ar(r,e=[]){var s,o,l;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=C(u({},t.MPEG),{[(s=a.standard)!=null?s:"Invariant quality"]:a.url}));break;case"mpeg":(n||e.includes("mpeg"))&&(t.MPEG=C(u({},t.MPEG),{[(o=a.standard)!=null?o:"Invariant quality"]:a.url}));break;case"hls":(n||e.includes("hls"))&&(t=C(u({},t),{HLS:{type:"url",url:a.url}}));break;case"dash":(n||e.includes("dash"))&&(t=C(u({},t),{DASH_SEP:{compatibilityMode:!0,type:"url",url:a.url}}));break;default:break}return{sources:t,thumbUrl:i,title:(l=r.title)!=null?l:""}}var Fe=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&i.includes(e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Ql=2;function kr(r){let e=_r(),t=new Rr,i={},n=null,s=!1,o,l=new Wl(null);r&&a(r);function a(b){n=b}function c(b,p,h){var v;if(!n)throw Error("need to set interactive controller");if(!n.options)return;let T=((v=e.map.get(b))!=null?v:{})[p];if(T){i=u({chapterId:h,listId:b,itemId:p},T);let R=i.player;i.subscription.add(R.info.currentQuality$.subscribe(M=>{let B=R.info.position$.getValue(),k=R.info.isAutoQualityEnabled$.getValue();if(!(!M||!B||k))for(let V of e.map)Object.values(V[1]).forEach(({player:P})=>{Fe(P,M)})})).add(R.events.started$.subscribe(()=>{m(p)})),T.container.remove(),n.setPlayer(T.player),s||(n.init(),s=!0),l.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}function m(b){return w(this,null,function*(){if(!n)throw Error("need to set interactive controller");if(ae(i)||b!==i.itemId)return;let p=n.getChapterBranches(),h=new Set;for(let g of p)h.has(g.media.id)||(yield d({media:g.media,chapterId:g.chapter.id,setAsActive:!1,title:g.chapter.label}),h.add(g.media.id))})}function y(h){return w(this,arguments,function*({chapter:{id:b},manifestVideo:p}){if(ae(i)||!n)return;let g=i.player.info.muted$.getValue(),T=i.player.info.currentQuality$.getValue(),v=i.player.info.isAutoQualityEnabled$.getValue(),R=i.player.info.volume$.getValue(),M=i.player.info.currentPlaybackRate$.getValue(),B=!v,k=!1;for(let V of e.map)if(V[0]===p.id&&!n.state.isReplay$.getValue()){let P=Object.keys(V[1]);for(let $ of P)$===i.itemId?(P.length<Ql||(k=!0),e.removePlayer(V[0],$)):(k=!0,c(V[0],$,b),B?Fe(i.player,T):i.player.setAutoQuality(!0),i.player.setVolume(R),i.player.setMuted(g),i.player.setPlaybackRate(M))}else e.removePlayer(V[0]);k||(yield d({media:p,chapterId:b,setAsActive:!0,playbackRate:M}),B?Fe(i.player,T):i.player.setAutoQuality(!0),i.player.setVolume(R),i.player.setMuted(g))})}function d(B){return w(this,arguments,function*({media:b,chapterId:p,prefetch:h=!0,setAsActive:g=!0,autoplay:T=!1,preferredExt:v,title:R,playbackRate:M}){var Fr,Br,qr,Dr,Hr;let k=Math.random().toString(),V=document.createElement("div");o.append(V);let P;if((Fr=n==null?void 0:n.options)!=null&&Fr.vkVideoLoader){let ze=Ps(b);ze.length&&(P=yield n.options.vkVideoLoader(...ze))}let $=((Br=n==null?void 0:n.options)==null?void 0:Br.coreConfig)||void 0,Se=C(u({},$),{configName:[...(qr=$==null?void 0:$.configName)!=null?qr:[],"interactive"]}),Ge=C(u({container:V},((Dr=P==null?void 0:P.videos)==null?void 0:Dr[0])||{sources:Ar(b,v).sources}),{title:R,failoverHosts:(P==null?void 0:P.failoverHosts)||[]}),ue=new Gl(Se,zl.createRootTracer());ue.initVideo(Ge);let Nr=null;if(P!=null&&P.videos&&(n!=null&&n.options.createOneStat)){let ze=P.videos[0],Rt=n.options.createOneStat(ze),Ur=new Rr;Rt&&(Ur.add(Rt.attachTo(ue)),Nr={oneStat:Rt,statSubscription:Ur})}let $r=new Rr,ra=(Hr=i==null?void 0:i.player)==null?void 0:Hr.info.isAutoQualityEnabled$.getValue();$r.add(ue.events.canplay$.subscribe(function(){ra||Fe(ue,i.player.info.currentQuality$.getValue()),M&&ue.setPlaybackRate(M)}));let de=e.createPlayer({listId:b.id,itemId:k,player:ue,container:V,sources:Ar(b,v).sources,config:Ge,subscription:$r,statistics:Nr});return g&&c(b.id,de.itemId,p),T&&de.player.play(),h&&!T&&de.player.prepare(),{player:de.player,config:de.config,statistics:de.statistics}})}function E(){x(),n=null,o.remove()}function x(){t.unsubscribe(),e.removeAll(),i={},s=!1}function L(){return w(this,null,function*(){if(!n)throw Error("need to set interactive controller");x(),o=document.createElement("div");let{media:b,chapter:p}=n.getCurrentChapter();b&&p?(t.add(n.events.chapterChanged$.subscribe(y)),yield d({media:b,chapterId:p.id,title:p.label})):console.error("not found")})}return C(u({},e),{init:L,setInteractiveController:a,createPlayer:d,removeAll:E,getActivePlayer:function(){return i},activePlayerChanged:l})}var I={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Be={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},_={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as Kl}from"@vkontakte/videoplayer-shared";var xt=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEvents:o,globalEventEmitter:l,ignoreContainerEvent:a,permanentTextControls:c,disabledControls$:m,onRemove:y}){this.hide=()=>{setTimeout(()=>{var e,t;this.gameState!==4&&(oe(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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!0,isFirst:!1});else{let o=Rs(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})},onEvent:(l,a)=>{this.isSelectedControlEvent=!0,l!==!1&&(this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),a(),this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(o),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.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(As(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Lr(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let m=this.gameState;this.gameState=3,m===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let o=Lr(s,this.container.container),l=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:l,currentTime:s,isInteractiveTime:o};this.globalEventEmitter.emit(I.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new Kl,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=c&&Ee(t.container.controls),this.disabledControls$=m,this.onRemove=y,this.globalEventEmitter=l,this.gameState=0,this.globalEvents=o,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=oe(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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.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 Vs=(r=[])=>r.reduce((e,t,i)=>{var s,o,l;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(a=>!dt(a));if(Et(n)){let a=[(o=t.startTime)!=null?o:0,(l=t.endTime)!=null?l:1/0],c=t.id;if(!i)e.push({subjects:[c],range:a});else{let m=[],y=-1/0,d=1/0,E=[],x=[];for(let L=0;L<e.length;L++){let b=e[L];if(x.push(...b.subjects),b.range[0]<d&&(d=b.range[0]),b.range[1]>y&&(y=b.range[1]),a[0]>=b.range[0]&&a[1]<=b.range[1])return e[L].subjects.push(c),e;a[0]<b.range[0]&&a[1]>b.range[0]&&(m.push(L),E=E.concat(b.subjects)),a[0]>=b.range[0]&&a[0]<=b.range[1]&&(m.push(L),E=E.concat(b.subjects),a[0]=b.range[0]),a[1]>=b.range[0]&&a[1]<=b.range[1]&&(m.push(L),E=E.concat(b.subjects),a[1]=b.range[1])}if(x.push(c),a[0]<=d&&a[1]>=y)return[{subjects:x,range:a}];m.length&&m.reverse().forEach(L=>{e.splice(L,1)}),e.push({subjects:E.concat([c]),range:a})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Os(){let r={};function e(){for(let l in r)Object.prototype.hasOwnProperty.call(r,l)&&delete r[l]}function t(l){let a={};for(let c in r)+c<=l&&(a[c]=r[c]);return a}function i(l){let a={};for(let c in r)+c>=l&&(a[c]=r[c]);return a}function n({timestamp:l,priority:a,initiator:c}){var m;if(Cr(l)){let y=(m=r[l])!=null?m:null;if(y&&a&&Pe(a,!0)){let d={},E=y[a];if(E&&(d=u(u({},d),E)),d=ae(d)?null:d,d&&Pe(c,!0)){let x=d[c];return x!=null?x:null}return d}return y}return null}function s({timestamp:l,priority:a,initiator:c}){if(Cr(l))if(r[l]){if(a&&Pe(a,!0))if(r[l][a]){if(c&&Pe(c,!0))if(r[l][a][c]){if(delete r[l][a][c],!ae(r[l][a]))return!0}else return!1;if(delete r[l][a],!ae(r[l]))return!0}else return!1;return delete r[l]}else return!1;return!1}function o(y){var d=y,{timestamp:l,priority:a,initiator:c}=d,m=j(d,["timestamp","priority","initiator"]);var E,x,L;(x=(E=r[l])==null?void 0:E[a])!=null&&x[c]?r[l][a][c].push(u({},m)):(L=r[l])!=null&&L[a]?r[l][a]=C(u({},r[l][a]),{[c]:[u({},m)]}):r[l]?r[l]=C(u({},r[l]),{[a]:{[c]:[u({},m)]}}):r[l]={[a]:{[c]:[u({},m)]}}}return{map:r,remove:s,add:o,removeAll:e,get:n,getLte:t,getGte:i}}var Yl=[A.expect,A.setNextBranch],Zl=1/0;function js(r){let e=r,t,i=Xl(),n=Os(),s,o=()=>{d(),p()},l=h=>{n.add.call(void 0,h),x()},a=(h=[])=>{for(let g of h)if(g.action(),Yl.includes(g.actionType))break},c=(h=1/0)=>{var R,M,B;let g=Tt((R=n.get({timestamp:h,priority:"control"}))!=null?R:{}),T=Tt((M=n.get({timestamp:h,priority:"container"}))!=null?M:{}),v=Tt((B=n.get({timestamp:h,priority:"chapter"}))!=null?B:{});return[...g,...T,...v]},m=h=>{i.isReady(h)&&a(c(h))},y=()=>{var h;a([...Tt((h=n.get({timestamp:1/0,priority:"chapter"}))!=null?h:{})])},d=()=>{t&&(s==null||s.unsubscribe(),t=void 0)},E=h=>{},x=()=>{t||(t=()=>setTimeout(()=>{m(1/0)}),s=e.events.ended$.subscribe(t))},L=h=>{d(),e=h},b=h=>{h.priority==="container"&&i.resetCalled(h.timestamp),n.remove(h)},p=()=>{i.release(),n.removeAll()};return{setPlayer:L,add:l,remove:b,exec:m,execEndOfVideo:y,listen:x,unlisten:d,release:o,containersEventsCallState:i,getPreparedToExecActions:c}}function Xl(){let r=new Map;return{setCalled:({timestamp:o,id:l})=>{let a=r.get(o);a&&a[l]!==void 0&&(a[l]=!0)},setData:(o=[])=>{var l,a;for(let c of o){let m=(l=c.endTime)!=null?l:Zl,y=(a=r.get(m))!=null?a:{};r.set(m,C(u({},y),{[c.id]:!1}))}},resetCalled:o=>{let l=r.get(o);if(l)for(let a in l)l[a]=!1},isReady:o=>{let l=r.get(o);return l?!Object.values(l).some(a=>!a):!0},release:()=>r.clear()}}function Tt(r){return Object.values(r).flat().sort(e=>e.actionType===A.expect?-1:1)}var Ns={videoContentHeight:0,videoContentWidth:0},$s=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return Ns;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return Ns;let o=t/i,l=n/s,a,c;return l>o?(c=s,a=s*o):l<o?(c=n/o,a=n):(c=s,a=n),{videoContentWidth:c,videoContentHeight:a}};var Jl=250;function Fs(r){let e=()=>{},t=new ResizeObserver(l=>{s(l),e=s.bind(null,l)});function i(l){let{parentElement:a,player:c}=r();if(a&&c){let{videoContentWidth:m,videoContentHeight:y}=$s(a,c);a.style.setProperty("--interactive-content-width",`${m}px`),a.style.setProperty("--interactive-content-height",`${y}px`),a.style.setProperty("--interactive-width",`${l[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${l[0].contentRect.height}px`)}}function n(){let{parentElement:l}=r();l.removeAttribute("style")}let s=Re(l=>{let{fns:a=[]}=r();i(l);for(let c of a)c()},Jl);function o(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e==null||e()},release:o}}var qe=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 ec=r=>Math.floor(Math.random()*r),qs=r=>{var n;let e=r.length,t=1/0,i=null;for(;e--;){let s=r[e],o=(n=s.weight)!=null?n:1;o<t&&(t=o,i=s)}return i},Ds=r=>{var n;let e=r.length,t=-1/0,i=null;for(;e--;){let s=r[e],o=(n=s.weight)!=null?n:0;o>t&&(t=o,i=s)}return i};var Hs=r=>{let e=r.length,t=ec(e);return r[t]},Bs=1,Us=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:Bs;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:Bs,e>=t)return r[s];return r[r.length-1]};var Gs={shouldOpenNow:!0,isDetachContainer:!0};var Pr=(r,e=!1)=>C(u({},r),{args:e?u(u({},r.args),Gs):u(u({},Gs),r.args)}),Qs=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},o=({action:p,controlType:h,controlId:g,containerId:T,branches:v=[],onEvent:R,isEOV:M=()=>!1,isDisabled:B=()=>!1})=>{let k=Pr(p,M()),V={timestamp:1/0,priority:"control",initiator:g,actionType:k.type},P=B(),$=r.emit.bind(r,I.interactives,{subjectId:g,subjectType:h,subjectName:"control",type:P?_.actionChoiceCanceled:_.actionChoice,actionType:p.type,payload:u({containerId:T},k.args)});if(P){$();return}switch(k.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let Se=v.find(Ge=>Ge.id===k.args.branchId);if(!Se)return;R(k.args.isDetachContainer,d.bind(null,{subjectId:g,subjectName:"control"})),$(),k.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{chapterId:Se.chapterId,autoSelect:!1}}):(t.add(C(u({},V),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{chapterId:Se.chapterId,autoSelect:!1}})})),i==null||i());return}case A.continuePlayback.trim().toLowerCase():{R(k.args.isDetachContainer,d.bind(null,{subjectId:g,subjectName:"control"})),$(),k.args.shouldOpenNow?E({subjectId:g,subjectName:"control",subjectType:h,action:p}):t.add(C(u({},V),{action:E.bind(null,{subjectId:g,subjectName:"control",subjectType:h,action:p})}));return}case A.openURI.trim().toLowerCase():{R(k.args.isDetachContainer,d.bind(null,{subjectId:g,subjectName:"control"})),$(),k.args.shouldOpenNow?b({subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{URI:p.args.uri}}):(t.add(C(u({},V),{action:b.bind(null,{subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{URI:p.args.uri}})})),i==null||i());return}default:console.error("Unexpected control event"),r.emit(I.errors,new N(1,1,{message:"Unexpected control event"}));return}},l=({action:p,container:{id:h,endTime:g},branches:T=[],isEOV:v=!1,autoSelected:R=!1})=>{let M=Pr(p,v),B={timestamp:!M.args.shouldOpenNow||v?1/0:g!=null?g:1/0,priority:"container",initiator:h,actionType:M.type},k=r.emit.bind(r,I.interactives,{subjectId:h,subjectName:"container",type:_.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let V=T.find(P=>P.id===M.args.branchId);if(!V)return;k(),t.add(C(u({},B),{action:x.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{chapterId:V.chapterId,autoSelect:R}})})),i==null||i();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{k(),t.add(C(u({},B),{action:E.bind(null,{subjectId:h,subjectName:"container",action:M})}));return}case A.openURI.trim().toLowerCase():{k(),t.add(C(u({},B),{action:b.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{URI:p.args.uri}})})),i==null||i();return}default:console.error("Unexpected container event"),r.emit(I.errors,new N(1,1,{message:"Unexpected container event"}));return}};function a({container:p,branches:h,isEOV:g=!1}){var v,R;let T=Mr(p.events);if(T){let M=Pr(T.action,g);r.emit(I.interactives,{subjectId:p.id,subjectName:"container",type:_.actionChoice,actionType:M.type,payload:M.args}),t.add({timestamp:g?1/0:(v=p.endTime)!=null?v:1/0,priority:"container",initiator:p.id,actionType:A.expect,action:y.bind(null,{subjectId:p.id,subjectName:"container"})}),n.isExpect=!0}else for(let M of(R=p.events)!=null?R:[])l({action:M.action,container:p,branches:h,isEOV:g})}let c=({chapterId:p,action:h,branches:g=[]})=>{let T=r.emit.bind(r,I.interactives,{subjectId:p,subjectName:"chapter",type:_.actionChoice,actionType:h.type,payload:h.args});switch(h.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let v=g.find(R=>R.id===h.args.branchId);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{let v=Hs(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{let v=Us(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{let v=Ds(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{let v=qs(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return T(),E.bind(null,{subjectId:p,subjectName:"chapter",action:h});case A.openURI.trim().toLowerCase():return T(),b.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:console.error("Unexpected chapter event"),r.emit(I.errors,new N(1,1,{message:"Unexpected chapter event"}));return}};function m(p){var g;let h=Mr(p.events);if(h){if(W(p))return;r.emit(I.interactives,{subjectId:p.id,subjectName:"chapter",type:_.actionChoice,actionType:h.action.type,payload:h.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:A.expect,action:y.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else(g=p.events)==null||g.forEach(T=>{let v=c({chapterId:p.id,action:T.action,branches:p.branches});v&&t.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:T.action.type,action:v})})}let y=({subjectId:p,subjectName:h})=>{e.pause(),r.emit(I.interactives,{subjectId:p,subjectName:h,type:_.actionExecution,actionType:A.expect})},d=({subjectId:p,subjectName:h})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(I.interactives,{subjectId:p,subjectName:h,type:_.actionExecution,actionType:"after-expect"})},E=({subjectId:p,subjectName:h,subjectType:g,action:T})=>{r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type})},x=({subjectId:p,subjectName:h,subjectType:g,action:T,payload:v})=>{v.behaviour="change-chapter",r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type,payload:v})},L=({subjectId:p,subjectName:h,subjectType:g,action:T,payload:v})=>{v.behaviour="change-manifest",r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type,payload:v})},b=({subjectId:p,subjectName:h,subjectType:g,action:T,payload:v})=>{if(!v.URI)return;let R=window.open(v.URI,"_blank","noopener,noreferrer");R&&(R.opener=null),r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type})};return{onControlEvent:o,onContainerEvent:l,onChapterEvent:c,onExpectEvent:y,expectEventHandler:d,setManifestChapterEvents:m,setManifestContainerEvents:a,stopExpect:s,state:n}};var jr=Qr(br(),1);import{Subscription as sc,Subject as Or,ValueSubject as De}from"@vkontakte/videoplayer-shared";var Vr=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(o=>o.id===i);if(!n)return null;let s=e.media.videos.find(o=>n.videoId===o.id);if(!s)return null;t[i]=Ks(s)}return t[i]}).filter(Boolean)},rc=r=>{for(let e of r.variants)if(ic(e)&&"payload"in e)return e.payload.id},ic=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",Ks=r=>{let e=rc(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},nc=(r,e)=>{for(let t of r.media.videos)if(e===Ks(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},Ys=(r,e)=>r.reduce((t,i)=>{let n=nc(e,i);return n?[...t,n]:t},[]);var Y,le,ce,U,St,Z,X,Q,pe,xe,Te,He=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new De([]),hasPrevChapter$:new De(!1),prevChapter$:new De(null),isInitialChapter$:new De(!1),isGoBackLimited$:new De(!1)};H(this,Y,null);H(this,le);H(this,ce,!1);H(this,U,null);H(this,St,null);this.events={inited$:new Or,destroyed$:new Or,error$:new Or};H(this,Z,null);H(this,X,null);H(this,Q,null);H(this,pe,new sc);H(this,xe,!1);H(this,Te,0);var o;O(this,Z,t),O(this,Q,e),O(this,X,i),O(this,Y,n),O(this,le,s),this.state.history$&&S(this,pe)&&((o=S(this,pe))==null||o.add(this.state.history$.subscribe(l=>{var a,c;this.state.prevChapter$.next((0,jr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((c=(a=S(this,U))==null?void 0:a.metadata)==null?void 0:c.initChapterId)),this.state.isGoBackLimited$.next(S(this,Te)===S(this,le).maxLength-1)})))}setManifest(e){return w(this,null,function*(){if(!S(this,X)||!S(this,Q))return;O(this,U,e),yield this.getProjectHistory();let t=this.getInitialChapterId();yield S(this,X).setChapter({chapterId:t,pushToHistory:!1}),S(this,ce)||(O(this,ce,!0),this.events.inited$.next({initChapterId:t}))})}get inited(){return S(this,ce)}updateHistory(e,t=!0){return w(this,null,function*(){var l;if(!S(this,U))return;S(this,xe)?(O(this,xe,!1),Yr(this,Te)._++):O(this,Te,0);let i=S(this,U),n=e.length-S(this,le).maxLength,s=n>0?e.slice(n):e,o=Vr(s,i);if(O(this,St,o),this.state.history$.next(s),!(!t||!S(this,Y)||!S(this,Z)))try{yield S(this,Y).save(S(this,Z),o)}catch(a){let c=new N(1,5,"Unable to save interactive history");this.events.error$.next(c),(l=S(this,Q))==null||l.emit(I.errors,c)}})}goBack(){return w(this,null,function*(){var i;if(!this.state||!S(this,X)){let n=new N(1,5,"Unable to save interactive history");return this.events.error$.next(n),(i=S(this,Q))==null?void 0:i.emit(I.errors,n)}O(this,xe,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),yield S(this,X).setChapter({chapterId:t,playPrev:!0})})}getProjectHistory(){return w(this,null,function*(){var n;if(!S(this,U)||!S(this,Z))return;let e=S(this,U),t=[this.getInitialVideoId()];if(S(this,Y))try{let s=yield S(this,Y).get(S(this,Z));s.length&&(t=s)}catch(s){let o=new N(1,5,"Error while trying to fetch data");this.events.error$.next(o),(n=S(this,Q))==null||n.emit(I.errors,o)}let i=Ys(t,e);this.state.history$.next(i)})}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,jr.default)(e,-1)||S(this,le).initChapterId||((t=S(this,U))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(S(this,U)){let e=this.getInitialChapterId();return Vr([e],S(this,U)).pop()}return null}destroy(){var e,t;O(this,Z,null),O(this,Y,null),O(this,X,null),(e=S(this,pe))==null||e.unsubscribe(),O(this,pe,null),O(this,ce,!1),(t=S(this,Q))==null||t.emit(I.historyDestroyed),this.events.destroyed$.next(),O(this,Q,null)}};Y=new WeakMap,le=new WeakMap,ce=new WeakMap,U=new WeakMap,St=new WeakMap,Z=new WeakMap,X=new WeakMap,Q=new WeakMap,pe=new WeakMap,xe=new WeakMap,Te=new WeakMap;var he=class he{constructor(e,t,i,n){this.target=e,this.type=t,this.listener=i,this.options=he._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(o=>!i.has(o));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),he._doesSupportObject(e)?t:t.capture||!1}}static _doesSupportObject(e){let t=he._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}he._supportsObject=t}return t||!1}};he._supportsObject=void 0;var wt=he;var Lt=class{constructor(){this.bindingMap=new qe}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new wt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=o=>{this.unlisten(e,t,s),i(o)};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 Mt=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))}updateCanvasDimensions(e,t=!1){return w(this,null,function*(){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=yield this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i})}save(){return w(this,null,function*(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,yield 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 _t=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 ia=Object.create;var kt=Object.defineProperty,na=Object.defineProperties,sa=Object.getOwnPropertyDescriptor,aa=Object.getOwnPropertyDescriptors,oa=Object.getOwnPropertyNames,We=Object.getOwnPropertySymbols,la=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable;var Wr=r=>{throw TypeError(r)};var Gr=(r,e,t)=>e in r?kt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e)=>{for(var t in e||(e={}))Pt.call(e,t)&&Gr(r,t,e[t]);if(We)for(var t of We(e))zr.call(e,t)&&Gr(r,t,e[t]);return r},C=(r,e)=>na(r,aa(e));var j=(r,e)=>{var t={};for(var i in r)Pt.call(r,i)&&e.indexOf(i)<0&&(t[i]=r[i]);if(r!=null&&We)for(var i of We(r))e.indexOf(i)<0&&zr.call(r,i)&&(t[i]=r[i]);return t};var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ca=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of oa(e))!Pt.call(r,n)&&n!==t&&kt(r,n,{get:()=>e[n],enumerable:!(i=sa(e,n))||i.enumerable});return r};var Qr=(r,e,t)=>(t=r!=null?ia(la(r)):{},ca(e||!r||!r.__esModule?kt(t,"default",{value:r,enumerable:!0}):t,r));var Kr=(r,e,t)=>e.has(r)||Wr("Cannot "+t);var S=(r,e,t)=>(Kr(r,e,"read from private field"),t?t.call(r):e.get(r)),H=(r,e,t)=>e.has(r)?Wr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),O=(r,e,t,i)=>(Kr(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var Yr=(r,e,t,i)=>({set _(n){O(r,e,n,t)},get _(){return S(r,e,i)}});var w=(r,e,t)=>new Promise((i,n)=>{var s=a=>{try{l(t.next(a))}catch(c){n(c)}},o=a=>{try{l(t.throw(a))}catch(c){n(c)}},l=a=>a.done?i(a.value):Promise.resolve(a.value).then(s,o);l((t=t.apply(r,e)).next())});var z=f((qt,ii)=>{"use strict";var we=function(r){return r&&r.Math===Math&&r};ii.exports=we(typeof globalThis=="object"&&globalThis)||we(typeof window=="object"&&window)||we(typeof self=="object"&&self)||we(typeof global=="object"&&global)||we(typeof qt=="object"&&qt)||function(){return this}()||Function("return this")()});var J=f((Jc,ni)=>{"use strict";ni.exports=function(r){try{return!!r()}catch(e){return!0}}});var Le=f((ep,si)=>{"use strict";var ha=J();si.exports=!ha(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var pi=f((tp,ci)=>{"use strict";var ua=Le(),li=Function.prototype,ai=li.apply,oi=li.call;ci.exports=typeof Reflect=="object"&&Reflect.apply||(ua?oi.bind(ai):function(){return oi.apply(ai,arguments)})});var ne=f((rp,di)=>{"use strict";var hi=Le(),ui=Function.prototype,Dt=ui.call,da=hi&&ui.bind.bind(Dt,Dt);di.exports=hi?da:function(r){return function(){return Dt.apply(r,arguments)}}});var Ht=f((ip,mi)=>{"use strict";var fi=ne(),fa=fi({}.toString),ma=fi("".slice);mi.exports=function(r){return ma(fa(r),8,-1)}});var Ut=f((np,yi)=>{"use strict";var ya=Ht(),va=ne();yi.exports=function(r){if(ya(r)==="Function")return va(r)}});var ee=f((sp,vi)=>{"use strict";var Gt=typeof document=="object"&&document.all;vi.exports=typeof Gt=="undefined"&&Gt!==void 0?function(r){return typeof r=="function"||r===Gt}:function(r){return typeof r=="function"}});var ye=f((ap,gi)=>{"use strict";var ga=J();gi.exports=!ga(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var st=f((op,bi)=>{"use strict";var ba=Le(),nt=Function.prototype.call;bi.exports=ba?nt.bind(nt):function(){return nt.apply(nt,arguments)}});var xi=f(Ii=>{"use strict";var Ci={}.propertyIsEnumerable,Ei=Object.getOwnPropertyDescriptor,Ca=Ei&&!Ci.call({1:2},1);Ii.f=Ca?function(e){var t=Ei(this,e);return!!t&&t.enumerable}:Ci});var zt=f((cp,Ti)=>{"use strict";Ti.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var wi=f((pp,Si)=>{"use strict";var Ea=ne(),Ia=J(),xa=Ht(),Wt=Object,Ta=Ea("".split);Si.exports=Ia(function(){return!Wt("z").propertyIsEnumerable(0)})?function(r){return xa(r)==="String"?Ta(r,""):Wt(r)}:Wt});var Qt=f((hp,Li)=>{"use strict";Li.exports=function(r){return r==null}});var Kt=f((up,Mi)=>{"use strict";var Sa=Qt(),wa=TypeError;Mi.exports=function(r){if(Sa(r))throw new wa("Can't call method on "+r);return r}});var Ai=f((dp,_i)=>{"use strict";var La=wi(),Ma=Kt();_i.exports=function(r){return La(Ma(r))}});var Me=f((fp,Ri)=>{"use strict";var _a=ee();Ri.exports=function(r){return typeof r=="object"?r!==null:_a(r)}});var Yt=f((mp,ki)=>{"use strict";ki.exports={}});var Jt=f((yp,Vi)=>{"use strict";var Zt=Yt(),Xt=z(),Aa=ee(),Pi=function(r){return Aa(r)?r:void 0};Vi.exports=function(r,e){return arguments.length<2?Pi(Zt[r])||Pi(Xt[r]):Zt[r]&&Zt[r][e]||Xt[r]&&Xt[r][e]}});var ji=f((vp,Oi)=>{"use strict";var Ra=ne();Oi.exports=Ra({}.isPrototypeOf)});var Bi=f((gp,Fi)=>{"use strict";var ka=z(),Ni=ka.navigator,$i=Ni&&Ni.userAgent;Fi.exports=$i?String($i):""});var Wi=f((bp,zi)=>{"use strict";var Gi=z(),er=Bi(),qi=Gi.process,Di=Gi.Deno,Hi=qi&&qi.versions||Di&&Di.version,Ui=Hi&&Hi.v8,G,at;Ui&&(G=Ui.split("."),at=G[0]>0&&G[0]<4?1:+(G[0]+G[1]));!at&&er&&(G=er.match(/Edge\/(\d+)/),(!G||G[1]>=74)&&(G=er.match(/Chrome\/(\d+)/),G&&(at=+G[1])));zi.exports=at});var tr=f((Cp,Ki)=>{"use strict";var Qi=Wi(),Pa=J(),Va=z(),Oa=Va.String;Ki.exports=!!Object.getOwnPropertySymbols&&!Pa(function(){var r=Symbol("symbol detection");return!Oa(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Qi&&Qi<41})});var rr=f((Ep,Yi)=>{"use strict";var ja=tr();Yi.exports=ja&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var ir=f((Ip,Zi)=>{"use strict";var Na=Jt(),$a=ee(),Fa=ji(),Ba=rr(),qa=Object;Zi.exports=Ba?function(r){return typeof r=="symbol"}:function(r){var e=Na("Symbol");return $a(e)&&Fa(e.prototype,qa(r))}});var Ji=f((xp,Xi)=>{"use strict";var Da=String;Xi.exports=function(r){try{return Da(r)}catch(e){return"Object"}}});var nr=f((Tp,en)=>{"use strict";var Ha=ee(),Ua=Ji(),Ga=TypeError;en.exports=function(r){if(Ha(r))return r;throw new Ga(Ua(r)+" is not a function")}});var rn=f((Sp,tn)=>{"use strict";var za=nr(),Wa=Qt();tn.exports=function(r,e){var t=r[e];return Wa(t)?void 0:za(t)}});var sn=f((wp,nn)=>{"use strict";var sr=st(),ar=ee(),or=Me(),Qa=TypeError;nn.exports=function(r,e){var t,i;if(e==="string"&&ar(t=r.toString)&&!or(i=sr(t,r))||ar(t=r.valueOf)&&!or(i=sr(t,r))||e!=="string"&&ar(t=r.toString)&&!or(i=sr(t,r)))return i;throw new Qa("Can't convert object to primitive value")}});var on=f((Lp,an)=>{"use strict";an.exports=!0});var pn=f((Mp,cn)=>{"use strict";var ln=z(),Ka=Object.defineProperty;cn.exports=function(r,e){try{Ka(ln,r,{value:e,configurable:!0,writable:!0})}catch(t){ln[r]=e}return e}});var lr=f((_p,dn)=>{"use strict";var Ya=on(),Za=z(),Xa=pn(),hn="__core-js_shared__",un=dn.exports=Za[hn]||Xa(hn,{});(un.versions||(un.versions=[])).push({version:"3.38.0",mode:Ya?"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 yn=f((Ap,mn)=>{"use strict";var fn=lr();mn.exports=function(r,e){return fn[r]||(fn[r]=e||{})}});var cr=f((Rp,vn)=>{"use strict";var Ja=Kt(),eo=Object;vn.exports=function(r){return eo(Ja(r))}});var ot=f((kp,gn)=>{"use strict";var to=ne(),ro=cr(),io=to({}.hasOwnProperty);gn.exports=Object.hasOwn||function(e,t){return io(ro(e),t)}});var Cn=f((Pp,bn)=>{"use strict";var no=ne(),so=0,ao=Math.random(),oo=no(1 .toString);bn.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+oo(++so+ao,36)}});var xn=f((Vp,In)=>{"use strict";var lo=z(),co=yn(),En=ot(),po=Cn(),ho=tr(),uo=rr(),ve=lo.Symbol,pr=co("wks"),fo=uo?ve.for||ve:ve&&ve.withoutSetter||po;In.exports=function(r){return En(pr,r)||(pr[r]=ho&&En(ve,r)?ve[r]:fo("Symbol."+r)),pr[r]}});var Ln=f((Op,wn)=>{"use strict";var mo=st(),Tn=Me(),Sn=ir(),yo=rn(),vo=sn(),go=xn(),bo=TypeError,Co=go("toPrimitive");wn.exports=function(r,e){if(!Tn(r)||Sn(r))return r;var t=yo(r,Co),i;if(t){if(e===void 0&&(e="default"),i=mo(t,r,e),!Tn(i)||Sn(i))return i;throw new bo("Can't convert object to primitive value")}return e===void 0&&(e="number"),vo(r,e)}});var hr=f((jp,Mn)=>{"use strict";var Eo=Ln(),Io=ir();Mn.exports=function(r){var e=Eo(r,"string");return Io(e)?e:e+""}});var Rn=f((Np,An)=>{"use strict";var xo=z(),_n=Me(),ur=xo.document,To=_n(ur)&&_n(ur.createElement);An.exports=function(r){return To?ur.createElement(r):{}}});var dr=f(($p,kn)=>{"use strict";var So=ye(),wo=J(),Lo=Rn();kn.exports=!So&&!wo(function(){return Object.defineProperty(Lo("div"),"a",{get:function(){return 7}}).a!==7})});var On=f(Vn=>{"use strict";var Mo=ye(),_o=st(),Ao=xi(),Ro=zt(),ko=Ai(),Po=hr(),Vo=ot(),Oo=dr(),Pn=Object.getOwnPropertyDescriptor;Vn.f=Mo?Pn:function(e,t){if(e=ko(e),t=Po(t),Oo)try{return Pn(e,t)}catch(i){}if(Vo(e,t))return Ro(!_o(Ao.f,e,t),e[t])}});var Nn=f((Bp,jn)=>{"use strict";var jo=J(),No=ee(),$o=/#|\.prototype\./,_e=function(r,e){var t=Bo[Fo(r)];return t===Do?!0:t===qo?!1:No(e)?jo(e):!!e},Fo=_e.normalize=function(r){return String(r).replace($o,".").toLowerCase()},Bo=_e.data={},qo=_e.NATIVE="N",Do=_e.POLYFILL="P";jn.exports=_e});var Bn=f((qp,Fn)=>{"use strict";var $n=Ut(),Ho=nr(),Uo=Le(),Go=$n($n.bind);Fn.exports=function(r,e){return Ho(r),e===void 0?r:Uo?Go(r,e):function(){return r.apply(e,arguments)}}});var Dn=f((Dp,qn)=>{"use strict";var zo=ye(),Wo=J();qn.exports=zo&&Wo(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Un=f((Hp,Hn)=>{"use strict";var Qo=Me(),Ko=String,Yo=TypeError;Hn.exports=function(r){if(Qo(r))return r;throw new Yo(Ko(r)+" is not an object")}});var Wn=f(zn=>{"use strict";var Zo=ye(),Xo=dr(),Jo=Dn(),lt=Un(),Gn=hr(),el=TypeError,fr=Object.defineProperty,tl=Object.getOwnPropertyDescriptor,mr="enumerable",yr="configurable",vr="writable";zn.f=Zo?Jo?function(e,t,i){if(lt(e),t=Gn(t),lt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&vr in i&&!i[vr]){var n=tl(e,t);n&&n[vr]&&(e[t]=i.value,i={configurable:yr in i?i[yr]:n[yr],enumerable:mr in i?i[mr]:n[mr],writable:!1})}return fr(e,t,i)}:fr:function(e,t,i){if(lt(e),t=Gn(t),lt(i),Xo)try{return fr(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new el("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var Kn=f((Gp,Qn)=>{"use strict";var rl=ye(),il=Wn(),nl=zt();Qn.exports=rl?function(r,e,t){return il.f(r,e,nl(1,t))}:function(r,e,t){return r[e]=t,r}});var Xn=f((zp,Zn)=>{"use strict";var Ae=z(),sl=pi(),al=Ut(),ol=ee(),ll=On().f,cl=Nn(),ge=Yt(),pl=Bn(),be=Kn(),Yn=ot();lr();var hl=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 sl(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,o=i?Ae:n?Ae[t]:Ae[t]&&Ae[t].prototype,l=i?ge:ge[t]||be(ge,t,{})[t],a=l.prototype,c,m,y,d,E,x,L,b,p;for(d in e)c=cl(i?d:t+(n?".":"#")+d,r.forced),m=!c&&o&&Yn(o,d),x=l[d],m&&(r.dontCallGetSet?(p=ll(o,d),L=p&&p.value):L=o[d]),E=m&&L?L:e[d],!(!c&&!s&&typeof x==typeof E)&&(r.bind&&m?b=pl(E,Ae):r.wrap&&m?b=hl(E):s&&ol(E)?b=al(E):b=E,(r.sham||E&&E.sham||x&&x.sham)&&be(b,"sham",!0),be(l,d,b),s&&(y=t+"Prototype",Yn(ge,y)||be(ge,y,{}),be(ge[y],d,E),r.real&&a&&(c||!a[d])&&be(a,d,E)))}});var es=f((Wp,Jn)=>{"use strict";var ul=Math.ceil,dl=Math.floor;Jn.exports=Math.trunc||function(e){var t=+e;return(t>0?dl:ul)(t)}});var gr=f((Qp,ts)=>{"use strict";var fl=es();ts.exports=function(r){var e=+r;return e!==e||e===0?0:fl(e)}});var is=f((Kp,rs)=>{"use strict";var ml=gr(),yl=Math.min;rs.exports=function(r){var e=ml(r);return e>0?yl(e,9007199254740991):0}});var ss=f((Yp,ns)=>{"use strict";var vl=is();ns.exports=function(r){return vl(r.length)}});var os=f((Zp,as)=>{"use strict";as.exports=function(){}});var ls=f(()=>{"use strict";var gl=Xn(),bl=cr(),Cl=ss(),El=gr(),Il=os();gl({target:"Array",proto:!0},{at:function(e){var t=bl(this),i=Cl(t),n=El(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});Il("at")});var ps=f((eh,cs)=>{"use strict";var xl=Jt();cs.exports=xl});var us=f((th,hs)=>{"use strict";ls();var Tl=ps();hs.exports=Tl("Array","at")});var fs=f((rh,ds)=>{"use strict";var Sl=us();ds.exports=Sl});var br=f((ih,ms)=>{"use strict";var wl=fs();ms.exports=wl});var Zr="1.0.26-dev.ac7b329a.0";function Vt(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var q="interactive",pa="interactive-controls-container",Qe=()=>document.querySelector(`.${pa}`),Xr=.4,F={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Jr=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Jr||{}),ei=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(ei||{}),ti=(i=>(i.start="left",i.end="right",i.center="center",i))(ti||{}),Ke=({target:r,props:e})=>{var t,i,n,s,o,l;r.style.alignItems=(i=((t=e.text)==null?void 0:t.gravityVertical)&&Jr[e.text.gravityVertical])!=null?i:"center",r.style.justifyContent=(s=((n=e.text)==null?void 0:n.gravityHorizontal)&&ei[e.text.gravityHorizontal])!=null?s:"center",r.style.textAlign=(l=((o=e.text)==null?void 0:o.alignment)&&ti[e.text.alignment])!=null?l:"left"},Ye=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,o,l,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} * ${(l=(o=e==null?void 0:e.text)==null?void 0:o.size)!=null?l: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,o;r.style.backgroundColor=Vt((n=(i=e==null?void 0:e.background)==null?void 0:i.color)!=null?n:t.backgroundColor,(o=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?o:t.backgroundAlpha)},Xe=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,o,l,a,c,m,y,d,E,x;r.style.border=`calc(${i.height} * ${(o=(s=(n=e==null?void 0:e.shape)==null?void 0:n.border)==null?void 0:s.width)!=null?o:t.borderWidth}) solid ${Vt((c=(a=(l=e==null?void 0:e.shape)==null?void 0:l.border)==null?void 0:a.color)!=null?c:t.borderColor,(d=(y=(m=e==null?void 0:e.shape)==null?void 0:m.border)==null?void 0:y.alpha)!=null?d:t.borderAlpha)}`,r.style.borderRadius=`calc(${i.height} * ${(x=(E=e==null?void 0:e.shape)==null?void 0:E.roundCorners)!=null?x:t.roundCorners})`},fe=({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 K=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(`${q}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let i=((n=this.control.layoutParams.innerSizesDependOn)!=null?n:F.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 Ot="int",ie=(i=>(i.AREA=`${Ot}_area`,i.TEXT=`${Ot}_text`,i.BUTTON=`${Ot}_bttn`,i))(ie||{});var Je=r=>{if(r.type.trim().toLowerCase()==="area")return new jt(r)},jt=class extends K{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(`${q}-${this.control.id}`),i.setAttribute("data-testid",ie.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:C(u({},F),{backgroundColor:"transparent"})}),Xe({target:i,props:this.control.props,fallback:C(u({},F),{borderAlpha:0}),dependsOn:this.container.dimensions}),fe({target:i,layoutParams:this.control.layoutParams,fallback:F}),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 et=()=>{let r=document.createElement("span");return r.style.display="inline-block",r.style.whiteSpace="pre",r.style.overflow="hidden",r.style.textOverflow="ellipsis",r.style.maxWidth="100%",r.style.maxHeight="100%",r};var tt=r=>{if(r.type.trim().toLowerCase()==="button")return new Nt(r)},Nt=class extends K{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(`${q}-${this.control.id}`),i.setAttribute("data-testid",ie.BUTTON),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.cursor="pointer",i.style.fontFamily="inherit",fe({target:i,layoutParams:this.control.layoutParams,fallback:F}),Ze({target:i,props:this.control.props,fallback:F}),Xe({target:i,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),Ke({target:i,props:this.control.props});let n=et();Ye({target:n,props:this.control.props,fallback:F,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 ri=r=>{if(r.type.trim().toLowerCase()==="text")return new $t(r)},$t=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("div");i.classList.add(`${q}-${this.control.id}`),i.setAttribute("data-testid",ie.TEXT),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.fontFamily="inherit",fe({target:i,layoutParams:this.control.layoutParams,fallback:F}),Ke({target:i,props:this.control.props});let n=et();Ye({target:n,props:this.control.props,fallback:F,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 Ft=class{constructor(e){this.layout=e}},rt=class extends Ft{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 me=class{constructor(e){this.container=e,this.factories=new Map,this.controls=[],this.setControls()}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){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);if(s){let o=s(i);if(o)return[...t,o]}return[...t]},[]))||[]}};var it=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new Bt(r,e)},Bt=class extends me{constructor(e,t){super(e),this.rootElement=t!=null?t:Qe(),this.layout=new rt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",tt),this.addControlFactory("text",ri),this.addControlFactory("area",Je)}createView(e){let t=document.createElement("div");return t.classList.add(`${q}-${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=`${Xr}`,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(`.${q}-${this.container.id}`)}};var ta=Qr(br(),1);import{clientChecker as ac,combine as oc,InterfaceLanguage as lc,Observable as Xs,once as cc,Subject as re,Subscription as Js,ValueSubject as D}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Ue}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Ll}from"@vkontakte/videoplayer-shared";function Re(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var se=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,ke=r=>se(r,"Object"),ct=r=>se(r,"String"),pt=r=>se(r,"Array"),ht=r=>se(r,"Number"),ys=r=>se(r,"Function");var Cr=r=>ht(r)&&!isNaN(r);var ae=r=>ke(r)&&Object.keys(r).length===0,Er=r=>pt(r)&&!r.length;var Pe=(r,e)=>ct(r)&&(e?r.trim():r).length;var vs="video_interactive",gs="videoint";var bs=250,Ve=class{constructor(e){this.handleZoomChange=Re(e=>{this.lastZoomInfo=e},bs);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,!ht(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=Ml(e),this.resizeObserver=new ResizeObserver(Re(this.onResize,bs)),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)}show(){return w(this,null,function*(){var e;this.manifest&&(this.ngEditor||(yield this.initNgEditor()),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&((e=this.ngEditor)==null||e.focusChapter(this.currentChapterId)),this.isHidden=!1)})}initNgEditor(){return w(this,null,function*(){if(!this.manifest)return;let e;try{e=yield Ll(this.lang,vs,gs)}catch(i){console.log("Unable to load graph language pack")}let{GraphEditor:t}=yield 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",s=>{var o=s,{name:i}=o,n=j(o,["name"]);var l;i==="openPreview"&&"chapterId"in n&&((l=this.onOpenPreviewClick)==null||l.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 Ml(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 Oe=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 o=s.startTime-e;if(o<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<o&&(t=t===-1?o:Math.min(t,o))}return!i&&t!==-1?t:null}}};var te=(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 _l}from"uuid";var Al="3.1",Cs={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Rl={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Es=r=>{let e=[];for(let o of r.chapters){let l,a=[];for(let t of o.branches){let i=t,{isDefault:y}=i,d=j(i,["isDefault"]);y&&(l=d.id),a.push(d)}let c=[],m=[];for(let n of o.containers){let s=n,{fallbackStrategy:y}=s,d=j(s,["fallbackStrategy"]);let E=!!d.endTime,x=[Rl];switch(y){case"await":E?x=[]:c=[];break;case"default":{let L={type:"onSuspense",action:{type:Cs.default,args:{branchId:l,shouldOpenNow:!E,isDetachContainer:!0}}};E?x=[L]:c=[L];break}case"random":case"weightlessRandom":case"max":case"min":{let L={type:"onSuspense",action:{type:Cs[y],args:{}}};E?x=[L]:c=[L];break}}for(let L of d.controls)m.push(C(u({},d),{controls:[u({},L)],id:_l(),events:x}))}e.push(C(u({},o),{containers:m,events:c,branches:a}))}return r.metadata.version=Al,r.metadata.updated=new Date().toISOString(),C(u({},r),{chapters:e})};var kl="3.2",Is=r=>{if(!r.media){let e=r.metadata,{media:t}=e,i=j(e,["media"]);return C(u({},r),{metadata:C(u({},i),{version:kl}),media:t})}return r};var Pl="3.3",Vl=(r=[])=>({edit:{chapters:r},view:{}}),xs={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ts=r=>{var n;let e=[],t=[];for(let s of r.chapters){let i=s,{id:o,x:l,y:a}=i,c=j(i,["id","x","y"]),m=c.containers.map(y=>{var d;return C(u({},y),{controls:y.controls.map(b=>{var p=b,{subtype:E,type:x}=p,L=j(p,["subtype","type"]);return C(u({},L),{type:E!=null?E:x})}),events:(d=y.events)!=null&&d.length?y.events:[xs]})});e.push(C(u({id:o},c),{containers:m,events:(n=c.events)!=null&&n.length?c.events:[xs]})),t.push({id:o,x:l,y:a})}return C(u({},r),{chapters:e,graph:Vl(t),metadata:C(u({},r.metadata),{version:Pl})})};var Ol=[{version:"3.0",migrate:Es},{version:"3.1",migrate:Is},{version:"3.2",migrate:Ts}],Ir=r=>Ol.reduce((e,t)=>te(e.metadata.version,t.version)?e:t.migrate(e),r);var Ss={Button:"Button",Area:"Area",Text:"Text"};var A={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var ws={metadata:"Object",chapters:"Array"},jl="3.0.0",Nl="3.3.0",ut=r=>{let e=te(r,jl);return e===-1?!1:e===0?!0:te(r,Nl)!==1},Ls=r=>{if(!ke(r))return!1;for(let e in ws)if(!r[e]||!se(r[e],ws[e]))return!1;return ut(r.metadata.version)},dt=r=>r.type===Ss.Text;var N=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var ft=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 mt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{ys(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 Ul}from"@vkontakte/videoplayer-shared";var yt=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:[]}}exec(e,t){return w(this,null,function*(){return $l(...this.loaders[e])(t)})}};function $l(...r){return function(t){return w(this,null,function*(){let i=[...r];for(;i.length>0;)t=yield i.shift()(t);return t})}}function je(r,e,t){return r?C(u({},r),{[e]:r[e]?[t,...r[e]]:[t]}):{[e]:[t]}}function vt(n){var s=n,{actions:r,errors:e,chapterId:t}=s,i=j(s,["actions","errors","chapterId"]);if(t){let o=r.getManifest(),l=r.getChapter(o.chapters,t);if(l){let a=r.getMedia(o.media,l.videoId),c=r.getGraph(o.graph,l.id);return a?C(u({},i),{actions:r,errors:e,result:{chapter:l,media:a,graph:c}}):C(u({},i),{errors:je(e,vt.name,"Could not find media"),actions:r})}}return C(u({},i),{errors:je(e,vt.name,"Could not find chapter"),actions:r})}var gt=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 o=i[n];try{o.callback.call(this,e)}catch(l){Promise.resolve().then(()=>{throw l})}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}},Ce=class extends gt{constructor(){super(),this.listeners||gt.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)}},Ne=class{constructor(){Object.defineProperty(this,"signal",{value:new Ce,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&&(Ne.prototype[Symbol.toStringTag]="AbortController",Ce.prototype[Symbol.toStringTag]="AbortSignal");function bt(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 xr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!bt({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,m){let y;m&&m.signal&&(y=m.signal,delete m.signal);let d=new t(c,m);return y&&Object.defineProperty(d,"signal",{writable:!1,enumerable:!1,configurable:!0,value:y}),d},s.prototype=t.prototype);let o=e;return{fetch:(a,c)=>{let m=s&&s.prototype.isPrototypeOf(a)?a.signal:c?c.signal:void 0;if(m){let y;try{y=new DOMException("Aborted","AbortError")}catch(E){y=new Error("Aborted"),y.name="AbortError"}if(m.aborted)return Promise.reject(y);let d=new Promise((E,x)=>{m.addEventListener("abort",()=>x(y),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([d,o(a,c)])}return o(a,c)},Request:s}}var $e=bt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ms=$e?xr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Tr=$e?Ms.fetch:window.fetch,su=$e?Ms.Request:window.Request,au=$e?Ne:window.AbortController,ou=$e?Ce:window.AbortSignal;var Fl=r=>w(void 0,null,function*(){try{let e={},t;if(ct(r)){t=new URL(r).href;let n=yield Tr(t);if(!n.ok)return{};e=yield n.json()}else if(ke(r))e=r;else return{};if(!Ls(e))return{};let i=e.metadata.media;if(ct(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=yield Tr(n);if(!s.ok)throw new Error;e.metadata.media=yield s.json()}catch(n){return Dl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}});function _s(r){return w(this,null,function*(){let{manifest:e,manifestURL:t}=yield Fl(r),i=Ir(e);return i.media=Bl(i.media,t),delete i.metadata.media,i})}function Ct(r,e){if(e)return r.find(t=>t.id===e)}function Sr(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 wr(r,e){return r.videos.find(t=>t.id===e)}function Bl(r,e){return C(u({},r),{videos:r.videos.map(t=>C(u({},t),{variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=ql(n,e);return C(u({},i),{url:s||n})})}))})}function ql(r="",e){try{return new URL(r,e).href}catch(t){return""}}function Dl(r){return te(r,"3.2.0")>=0}var Et=r=>pt(r)&&!Er(r),W=r=>r.order==="end",It=r=>pt(r.containers)&&!Er(r.containers)&&W(r),As=(r,e)=>{var i;let t=r*1e3;return Et(e.controls)&&t<((i=e.startTime)!=null?i:0)},Lr=(r,e)=>{var i,n;let t=r*1e3;return Et(e.controls)&&t>=((i=e.startTime)!=null?i:0)&&t<=((n=e.endTime)!=null?n:1/0)};var oe=(r=[])=>r.some(e=>e.action.type==="expect"),Mr=(r=[])=>r.find(e=>e.action.type==="expect"),Hl=r=>(r==null?void 0:r.length)===1,Ee=r=>Hl(r)&&dt(r[0]);function Rs(r,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?r(u(u({},e[0]),t)):r(...e,...t)}var ks=(r,e)=>oe(r.events)?!1:e.some(({container:t})=>t.container.id!==r.id&&oe(t.container.events)&&t.container.endTime===r.endTime&&!t.isRemoved);var Ie=class extends yt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Ul(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}setManifest(t){return w(this,null,function*(){var n;this.release();let i=yield this.exec("manifestLoaders",{actions:{addErrorMessage:je},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=yield _s((n=i.result)!=null?n:t),this})}setInitial(){return w(this,null,function*(){return this.setNext()})}setNext(){return w(this,arguments,function*(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let n=yield this.exec("chapterLoaders",vt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Sr,getChapter:Ct,getMedia:wr,getByBranches:this.getByBranches.bind(this),addErrorMessage:je},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=Ct(this.manifest.chapters,t);if(n){let s=wr(this.manifest.media,n.videoId),o=Sr(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:o}}return null}getBranches(t=(i=>(i=this.chapter)==null?void 0:i.id)()){var n,s,o;if(t===((n=this.chapter)==null?void 0:n.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let l=Ct(((o=this.manifest)==null?void 0:o.chapters)||[],t);return this.getByBranches(l==null?void 0:l.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?W(this.chapter):!1}};import{Player as Gl}from"@vkontakte/videoplayer-core";import{Subscription as Rr,Tracer as zl,ValueSubject as Wl}from"@vkontakte/videoplayer-shared";var Ps=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 _r(){let r=new Map;function e(a){var c=a,{listId:s=Math.random().toString(),itemId:o=Math.random().toString()}=c,l=j(c,["listId","itemId"]);let m=r.get(s),y=u({},l);return m?m[o]=y:r.set(s,{[o]:y}),u({listId:s,itemId:o},l)}function t(s){var o,l;s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),(o=s.statistics)==null||o.oneStat.destroy(),(l=s.statistics)==null||l.statSubscription.unsubscribe()}function i(s,o){let l=r.get(s);if(!l)throw Error("Can't remove. Not find.");if(o){let a=l[o];a&&t(a),delete l[o],Object.keys(l).length||r.delete(s)}else{for(let a of Object.values(l))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 Ar(r,e=[]){var s,o,l;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=C(u({},t.MPEG),{[(s=a.standard)!=null?s:"Invariant quality"]:a.url}));break;case"mpeg":(n||e.includes("mpeg"))&&(t.MPEG=C(u({},t.MPEG),{[(o=a.standard)!=null?o:"Invariant quality"]:a.url}));break;case"hls":(n||e.includes("hls"))&&(t=C(u({},t),{HLS:{type:"url",url:a.url}}));break;case"dash":(n||e.includes("dash"))&&(t=C(u({},t),{DASH_SEP:{compatibilityMode:!0,type:"url",url:a.url}}));break;default:break}return{sources:t,thumbUrl:i,title:(l=r.title)!=null?l:""}}var Fe=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&i.includes(e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Ql=2;function kr(r){let e=_r(),t=new Rr,i={},n=null,s=!1,o,l=new Wl(null);r&&a(r);function a(b){n=b}function c(b,p,h){var v;if(!n)throw Error("need to set interactive controller");if(!n.options)return;let T=((v=e.map.get(b))!=null?v:{})[p];if(T){i=u({chapterId:h,listId:b,itemId:p},T);let R=i.player;i.subscription.add(R.info.currentQuality$.subscribe(M=>{let B=R.info.position$.getValue(),k=R.info.isAutoQualityEnabled$.getValue();if(!(!M||!B||k))for(let V of e.map)Object.values(V[1]).forEach(({player:P})=>{Fe(P,M)})})).add(R.events.started$.subscribe(()=>{m(p)})),T.container.remove(),n.setPlayer(T.player),s||(n.init(),s=!0),l.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}function m(b){return w(this,null,function*(){if(!n)throw Error("need to set interactive controller");if(ae(i)||b!==i.itemId)return;let p=n.getChapterBranches(),h=new Set;for(let g of p)h.has(g.media.id)||(yield d({media:g.media,chapterId:g.chapter.id,setAsActive:!1,title:g.chapter.label}),h.add(g.media.id))})}function y(h){return w(this,arguments,function*({chapter:{id:b},manifestVideo:p}){if(ae(i)||!n)return;let g=i.player.info.muted$.getValue(),T=i.player.info.currentQuality$.getValue(),v=i.player.info.isAutoQualityEnabled$.getValue(),R=i.player.info.volume$.getValue(),M=i.player.info.currentPlaybackRate$.getValue(),B=!v,k=!1;for(let V of e.map)if(V[0]===p.id&&!n.state.isReplay$.getValue()){let P=Object.keys(V[1]);for(let $ of P)$===i.itemId?(P.length<Ql||(k=!0),e.removePlayer(V[0],$)):(k=!0,c(V[0],$,b),B?Fe(i.player,T):i.player.setAutoQuality(!0),i.player.setVolume(R),i.player.setMuted(g),i.player.setPlaybackRate(M))}else e.removePlayer(V[0]);k||(yield d({media:p,chapterId:b,setAsActive:!0,playbackRate:M}),B?Fe(i.player,T):i.player.setAutoQuality(!0),i.player.setVolume(R),i.player.setMuted(g))})}function d(B){return w(this,arguments,function*({media:b,chapterId:p,prefetch:h=!0,setAsActive:g=!0,autoplay:T=!1,preferredExt:v,title:R,playbackRate:M}){var Fr,Br,qr,Dr,Hr;let k=Math.random().toString(),V=document.createElement("div");o.append(V);let P;if((Fr=n==null?void 0:n.options)!=null&&Fr.vkVideoLoader){let ze=Ps(b);ze.length&&(P=yield n.options.vkVideoLoader(...ze))}let $=((Br=n==null?void 0:n.options)==null?void 0:Br.coreConfig)||void 0,Se=C(u({},$),{configName:[...(qr=$==null?void 0:$.configName)!=null?qr:[],"interactive"]}),Ge=C(u({container:V},((Dr=P==null?void 0:P.videos)==null?void 0:Dr[0])||{sources:Ar(b,v).sources}),{title:R,failoverHosts:(P==null?void 0:P.failoverHosts)||[]}),ue=new Gl(Se,zl.createRootTracer());ue.initVideo(Ge);let Nr=null;if(P!=null&&P.videos&&(n!=null&&n.options.createOneStat)){let ze=P.videos[0],Rt=n.options.createOneStat(ze),Ur=new Rr;Rt&&(Ur.add(Rt.attachTo(ue)),Nr={oneStat:Rt,statSubscription:Ur})}let $r=new Rr,ra=(Hr=i==null?void 0:i.player)==null?void 0:Hr.info.isAutoQualityEnabled$.getValue();$r.add(ue.events.canplay$.subscribe(function(){ra||Fe(ue,i.player.info.currentQuality$.getValue()),M&&ue.setPlaybackRate(M)}));let de=e.createPlayer({listId:b.id,itemId:k,player:ue,container:V,sources:Ar(b,v).sources,config:Ge,subscription:$r,statistics:Nr});return g&&c(b.id,de.itemId,p),T&&de.player.play(),h&&!T&&de.player.prepare(),{player:de.player,config:de.config,statistics:de.statistics}})}function E(){x(),n=null,o.remove()}function x(){t.unsubscribe(),e.removeAll(),i={},s=!1}function L(){return w(this,null,function*(){if(!n)throw Error("need to set interactive controller");x(),o=document.createElement("div");let{media:b,chapter:p}=n.getCurrentChapter();b&&p?(t.add(n.events.chapterChanged$.subscribe(y)),yield d({media:b,chapterId:p.id,title:p.label})):console.error("not found")})}return C(u({},e),{init:L,setInteractiveController:a,createPlayer:d,removeAll:E,getActivePlayer:function(){return i},activePlayerChanged:l})}var I={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Be={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},_={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as Kl}from"@vkontakte/videoplayer-shared";var xt=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEvents:o,globalEventEmitter:l,ignoreContainerEvent:a,permanentTextControls:c,disabledControls$:m,onRemove:y}){this.hide=()=>{setTimeout(()=>{var e,t;this.gameState!==4&&(oe(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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!0,isFirst:!1});else{let o=Rs(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})},onEvent:(l,a)=>{this.isSelectedControlEvent=!0,l!==!1&&(this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),a(),this.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(o),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.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(As(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Lr(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let m=this.gameState;this.gameState=3,m===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let o=Lr(s,this.container.container),l=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:l,currentTime:s,isInteractiveTime:o};this.globalEventEmitter.emit(I.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new Kl,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=c&&Ee(t.container.controls),this.disabledControls$=m,this.onRemove=y,this.globalEventEmitter=l,this.gameState=0,this.globalEvents=o,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=oe(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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.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 Vs=(r=[])=>r.reduce((e,t,i)=>{var s,o,l;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(a=>!dt(a));if(Et(n)){let a=[(o=t.startTime)!=null?o:0,(l=t.endTime)!=null?l:1/0],c=t.id;if(!i)e.push({subjects:[c],range:a});else{let m=[],y=-1/0,d=1/0,E=[],x=[];for(let L=0;L<e.length;L++){let b=e[L];if(x.push(...b.subjects),b.range[0]<d&&(d=b.range[0]),b.range[1]>y&&(y=b.range[1]),a[0]>=b.range[0]&&a[1]<=b.range[1])return e[L].subjects.push(c),e;a[0]<b.range[0]&&a[1]>b.range[0]&&(m.push(L),E=E.concat(b.subjects)),a[0]>=b.range[0]&&a[0]<=b.range[1]&&(m.push(L),E=E.concat(b.subjects),a[0]=b.range[0]),a[1]>=b.range[0]&&a[1]<=b.range[1]&&(m.push(L),E=E.concat(b.subjects),a[1]=b.range[1])}if(x.push(c),a[0]<=d&&a[1]>=y)return[{subjects:x,range:a}];m.length&&m.reverse().forEach(L=>{e.splice(L,1)}),e.push({subjects:E.concat([c]),range:a})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Os(){let r={};function e(){for(let l in r)Object.prototype.hasOwnProperty.call(r,l)&&delete r[l]}function t(l){let a={};for(let c in r)+c<=l&&(a[c]=r[c]);return a}function i(l){let a={};for(let c in r)+c>=l&&(a[c]=r[c]);return a}function n({timestamp:l,priority:a,initiator:c}){var m;if(Cr(l)){let y=(m=r[l])!=null?m:null;if(y&&a&&Pe(a,!0)){let d={},E=y[a];if(E&&(d=u(u({},d),E)),d=ae(d)?null:d,d&&Pe(c,!0)){let x=d[c];return x!=null?x:null}return d}return y}return null}function s({timestamp:l,priority:a,initiator:c}){if(Cr(l))if(r[l]){if(a&&Pe(a,!0))if(r[l][a]){if(c&&Pe(c,!0))if(r[l][a][c]){if(delete r[l][a][c],!ae(r[l][a]))return!0}else return!1;if(delete r[l][a],!ae(r[l]))return!0}else return!1;return delete r[l]}else return!1;return!1}function o(y){var d=y,{timestamp:l,priority:a,initiator:c}=d,m=j(d,["timestamp","priority","initiator"]);var E,x,L;(x=(E=r[l])==null?void 0:E[a])!=null&&x[c]?r[l][a][c].push(u({},m)):(L=r[l])!=null&&L[a]?r[l][a]=C(u({},r[l][a]),{[c]:[u({},m)]}):r[l]?r[l]=C(u({},r[l]),{[a]:{[c]:[u({},m)]}}):r[l]={[a]:{[c]:[u({},m)]}}}return{map:r,remove:s,add:o,removeAll:e,get:n,getLte:t,getGte:i}}var Yl=[A.expect,A.setNextBranch],Zl=1/0;function js(r){let e=r,t,i=Xl(),n=Os(),s,o=()=>{d(),p()},l=h=>{n.add.call(void 0,h),x()},a=(h=[])=>{for(let g of h)if(g.action(),Yl.includes(g.actionType))break},c=(h=1/0)=>{var R,M,B;let g=Tt((R=n.get({timestamp:h,priority:"control"}))!=null?R:{}),T=Tt((M=n.get({timestamp:h,priority:"container"}))!=null?M:{}),v=Tt((B=n.get({timestamp:h,priority:"chapter"}))!=null?B:{});return[...g,...T,...v]},m=h=>{i.isReady(h)&&a(c(h))},y=()=>{var h;a([...Tt((h=n.get({timestamp:1/0,priority:"chapter"}))!=null?h:{})])},d=()=>{t&&(s==null||s.unsubscribe(),t=void 0)},E=h=>{},x=()=>{t||(t=()=>setTimeout(()=>{m(1/0)}),s=e.events.ended$.subscribe(t))},L=h=>{d(),e=h},b=h=>{h.priority==="container"&&i.resetCalled(h.timestamp),n.remove(h)},p=()=>{i.release(),n.removeAll()};return{setPlayer:L,add:l,remove:b,exec:m,execEndOfVideo:y,listen:x,unlisten:d,release:o,containersEventsCallState:i,getPreparedToExecActions:c}}function Xl(){let r=new Map;return{setCalled:({timestamp:o,id:l})=>{let a=r.get(o);a&&a[l]!==void 0&&(a[l]=!0)},setData:(o=[])=>{var l,a;for(let c of o){let m=(l=c.endTime)!=null?l:Zl,y=(a=r.get(m))!=null?a:{};r.set(m,C(u({},y),{[c.id]:!1}))}},resetCalled:o=>{let l=r.get(o);if(l)for(let a in l)l[a]=!1},isReady:o=>{let l=r.get(o);return l?!Object.values(l).some(a=>!a):!0},release:()=>r.clear()}}function Tt(r){return Object.values(r).flat().sort(e=>e.actionType===A.expect?-1:1)}var Ns={videoContentHeight:0,videoContentWidth:0},$s=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return Ns;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return Ns;let o=t/i,l=n/s,a,c;return l>o?(c=s,a=s*o):l<o?(c=n/o,a=n):(c=s,a=n),{videoContentWidth:c,videoContentHeight:a}};var Jl=250;function Fs(r){let e=()=>{},t=new ResizeObserver(l=>{s(l),e=s.bind(null,l)});function i(l){let{parentElement:a,player:c}=r();if(a&&c){let{videoContentWidth:m,videoContentHeight:y}=$s(a,c);a.style.setProperty("--interactive-content-width",`${m}px`),a.style.setProperty("--interactive-content-height",`${y}px`),a.style.setProperty("--interactive-width",`${l[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${l[0].contentRect.height}px`)}}function n(){let{parentElement:l}=r();l.removeAttribute("style")}let s=Re(l=>{let{fns:a=[]}=r();i(l);for(let c of a)c()},Jl);function o(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e==null||e()},release:o}}var qe=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 ec=r=>Math.floor(Math.random()*r),qs=r=>{var n;let e=r.length,t=1/0,i=null;for(;e--;){let s=r[e],o=(n=s.weight)!=null?n:1;o<t&&(t=o,i=s)}return i},Ds=r=>{var n;let e=r.length,t=-1/0,i=null;for(;e--;){let s=r[e],o=(n=s.weight)!=null?n:0;o>t&&(t=o,i=s)}return i};var Hs=r=>{let e=r.length,t=ec(e);return r[t]},Bs=1,Us=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:Bs;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:Bs,e>=t)return r[s];return r[r.length-1]};var Gs={shouldOpenNow:!0,isDetachContainer:!0};var Pr=(r,e=!1)=>C(u({},r),{args:e?u(u({},r.args),Gs):u(u({},Gs),r.args)}),Qs=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},o=({action:p,controlType:h,controlId:g,containerId:T,branches:v=[],onEvent:R,isEOV:M=()=>!1,isDisabled:B=()=>!1})=>{let k=Pr(p,M()),V={timestamp:1/0,priority:"control",initiator:g,actionType:k.type},P=B(),$=r.emit.bind(r,I.interactives,{subjectId:g,subjectType:h,subjectName:"control",type:P?_.actionChoiceCanceled:_.actionChoice,actionType:p.type,payload:u({containerId:T},k.args)});if(P){$();return}switch(k.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let Se=v.find(Ge=>Ge.id===k.args.branchId);if(!Se)return;R(k.args.isDetachContainer,d.bind(null,{subjectId:g,subjectName:"control"})),$(),k.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{chapterId:Se.chapterId,autoSelect:!1}}):(t.add(C(u({},V),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{chapterId:Se.chapterId,autoSelect:!1}})})),i==null||i());return}case A.continuePlayback.trim().toLowerCase():{R(k.args.isDetachContainer,d.bind(null,{subjectId:g,subjectName:"control"})),$(),k.args.shouldOpenNow?E({subjectId:g,subjectName:"control",subjectType:h,action:p}):t.add(C(u({},V),{action:E.bind(null,{subjectId:g,subjectName:"control",subjectType:h,action:p})}));return}case A.openURI.trim().toLowerCase():{R(k.args.isDetachContainer,d.bind(null,{subjectId:g,subjectName:"control"})),$(),k.args.shouldOpenNow?b({subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{URI:p.args.uri}}):(t.add(C(u({},V),{action:b.bind(null,{subjectId:g,subjectName:"control",subjectType:h,action:k,payload:{URI:p.args.uri}})})),i==null||i());return}default:console.error("Unexpected control event"),r.emit(I.errors,new N(1,1,{message:"Unexpected control event"}));return}},l=({action:p,container:{id:h,endTime:g},branches:T=[],isEOV:v=!1,autoSelected:R=!1})=>{let M=Pr(p,v),B={timestamp:!M.args.shouldOpenNow||v?1/0:g!=null?g:1/0,priority:"container",initiator:h,actionType:M.type},k=r.emit.bind(r,I.interactives,{subjectId:h,subjectName:"container",type:_.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let V=T.find(P=>P.id===M.args.branchId);if(!V)return;k(),t.add(C(u({},B),{action:x.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{chapterId:V.chapterId,autoSelect:R}})})),i==null||i();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{k(),t.add(C(u({},B),{action:E.bind(null,{subjectId:h,subjectName:"container",action:M})}));return}case A.openURI.trim().toLowerCase():{k(),t.add(C(u({},B),{action:b.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{URI:p.args.uri}})})),i==null||i();return}default:console.error("Unexpected container event"),r.emit(I.errors,new N(1,1,{message:"Unexpected container event"}));return}};function a({container:p,branches:h,isEOV:g=!1}){var v,R;let T=Mr(p.events);if(T){let M=Pr(T.action,g);r.emit(I.interactives,{subjectId:p.id,subjectName:"container",type:_.actionChoice,actionType:M.type,payload:M.args}),t.add({timestamp:g?1/0:(v=p.endTime)!=null?v:1/0,priority:"container",initiator:p.id,actionType:A.expect,action:y.bind(null,{subjectId:p.id,subjectName:"container"})}),n.isExpect=!0}else for(let M of(R=p.events)!=null?R:[])l({action:M.action,container:p,branches:h,isEOV:g})}let c=({chapterId:p,action:h,branches:g=[]})=>{let T=r.emit.bind(r,I.interactives,{subjectId:p,subjectName:"chapter",type:_.actionChoice,actionType:h.type,payload:h.args});switch(h.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let v=g.find(R=>R.id===h.args.branchId);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{let v=Hs(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{let v=Us(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{let v=Ds(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{let v=qs(g);return v!=null&&v.chapterId?(T(),x.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return T(),E.bind(null,{subjectId:p,subjectName:"chapter",action:h});case A.openURI.trim().toLowerCase():return T(),b.bind(null,{subjectId:p,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:console.error("Unexpected chapter event"),r.emit(I.errors,new N(1,1,{message:"Unexpected chapter event"}));return}};function m(p){var g;let h=Mr(p.events);if(h){if(W(p))return;r.emit(I.interactives,{subjectId:p.id,subjectName:"chapter",type:_.actionChoice,actionType:h.action.type,payload:h.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:A.expect,action:y.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else(g=p.events)==null||g.forEach(T=>{let v=c({chapterId:p.id,action:T.action,branches:p.branches});v&&t.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:T.action.type,action:v})})}let y=({subjectId:p,subjectName:h})=>{e.pause(),r.emit(I.interactives,{subjectId:p,subjectName:h,type:_.actionExecution,actionType:A.expect})},d=({subjectId:p,subjectName:h})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(I.interactives,{subjectId:p,subjectName:h,type:_.actionExecution,actionType:"after-expect"})},E=({subjectId:p,subjectName:h,subjectType:g,action:T})=>{r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type})},x=({subjectId:p,subjectName:h,subjectType:g,action:T,payload:v})=>{v.behaviour="change-chapter",r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type,payload:v})},L=({subjectId:p,subjectName:h,subjectType:g,action:T,payload:v})=>{v.behaviour="change-manifest",r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type,payload:v})},b=({subjectId:p,subjectName:h,subjectType:g,action:T,payload:v})=>{if(!v.URI)return;let R=window.open(v.URI,"_blank","noopener,noreferrer");R&&(R.opener=null),r.emit(I.interactives,{subjectId:p,subjectName:h,subjectType:g,type:_.actionExecution,actionType:T.type})};return{onControlEvent:o,onContainerEvent:l,onChapterEvent:c,onExpectEvent:y,expectEventHandler:d,setManifestChapterEvents:m,setManifestContainerEvents:a,stopExpect:s,state:n}};var jr=Qr(br(),1);import{Subscription as sc,Subject as Or,ValueSubject as De}from"@vkontakte/videoplayer-shared";var Vr=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(o=>o.id===i);if(!n)return null;let s=e.media.videos.find(o=>n.videoId===o.id);if(!s)return null;t[i]=Ks(s)}return t[i]}).filter(Boolean)},rc=r=>{for(let e of r.variants)if(ic(e)&&"payload"in e)return e.payload.id},ic=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",Ks=r=>{let e=rc(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},nc=(r,e)=>{for(let t of r.media.videos)if(e===Ks(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},Ys=(r,e)=>r.reduce((t,i)=>{let n=nc(e,i);return n?[...t,n]:t},[]);var Y,le,ce,U,St,Z,X,Q,pe,xe,Te,He=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new De([]),hasPrevChapter$:new De(!1),prevChapter$:new De(null),isInitialChapter$:new De(!1),isGoBackLimited$:new De(!1)};H(this,Y,null);H(this,le);H(this,ce,!1);H(this,U,null);H(this,St,null);this.events={inited$:new Or,destroyed$:new Or,error$:new Or};H(this,Z,null);H(this,X,null);H(this,Q,null);H(this,pe,new sc);H(this,xe,!1);H(this,Te,0);var o;O(this,Z,t),O(this,Q,e),O(this,X,i),O(this,Y,n),O(this,le,s),this.state.history$&&S(this,pe)&&((o=S(this,pe))==null||o.add(this.state.history$.subscribe(l=>{var a,c;this.state.prevChapter$.next((0,jr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((c=(a=S(this,U))==null?void 0:a.metadata)==null?void 0:c.initChapterId)),this.state.isGoBackLimited$.next(S(this,Te)===S(this,le).maxLength-1)})))}setManifest(e){return w(this,null,function*(){if(!S(this,X)||!S(this,Q))return;O(this,U,e),yield this.getProjectHistory();let t=this.getInitialChapterId();yield S(this,X).setChapter({chapterId:t,pushToHistory:!1}),S(this,ce)||(O(this,ce,!0),this.events.inited$.next({initChapterId:t}))})}get inited(){return S(this,ce)}updateHistory(e,t=!0){return w(this,null,function*(){var l;if(!S(this,U))return;S(this,xe)?(O(this,xe,!1),Yr(this,Te)._++):O(this,Te,0);let i=S(this,U),n=e.length-S(this,le).maxLength,s=n>0?e.slice(n):e,o=Vr(s,i);if(O(this,St,o),this.state.history$.next(s),!(!t||!S(this,Y)||!S(this,Z)))try{yield S(this,Y).save(S(this,Z),o)}catch(a){let c=new N(1,5,"Unable to save interactive history");this.events.error$.next(c),(l=S(this,Q))==null||l.emit(I.errors,c)}})}goBack(){return w(this,null,function*(){var i;if(!this.state||!S(this,X)){let n=new N(1,5,"Unable to save interactive history");return this.events.error$.next(n),(i=S(this,Q))==null?void 0:i.emit(I.errors,n)}O(this,xe,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),yield S(this,X).setChapter({chapterId:t,playPrev:!0})})}getProjectHistory(){return w(this,null,function*(){var n;if(!S(this,U)||!S(this,Z))return;let e=S(this,U),t=[this.getInitialVideoId()];if(S(this,Y))try{let s=yield S(this,Y).get(S(this,Z));s.length&&(t=s)}catch(s){let o=new N(1,5,"Error while trying to fetch data");this.events.error$.next(o),(n=S(this,Q))==null||n.emit(I.errors,o)}let i=Ys(t,e);this.state.history$.next(i)})}getInitialChapterId(){var t;let e=this.state.history$.getValue();return(0,jr.default)(e,-1)||S(this,le).initChapterId||((t=S(this,U))==null?void 0:t.metadata.initChapterId)}getInitialVideoId(){if(S(this,U)){let e=this.getInitialChapterId();return Vr([e],S(this,U)).pop()}return null}destroy(){var e,t;O(this,Z,null),O(this,Y,null),O(this,X,null),(e=S(this,pe))==null||e.unsubscribe(),O(this,pe,null),O(this,ce,!1),(t=S(this,Q))==null||t.emit(I.historyDestroyed),this.events.destroyed$.next(),O(this,Q,null)}};Y=new WeakMap,le=new WeakMap,ce=new WeakMap,U=new WeakMap,St=new WeakMap,Z=new WeakMap,X=new WeakMap,Q=new WeakMap,pe=new WeakMap,xe=new WeakMap,Te=new WeakMap;var he=class he{constructor(e,t,i,n){this.target=e,this.type=t,this.listener=i,this.options=he._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(o=>!i.has(o));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),he._doesSupportObject(e)?t:t.capture||!1}}static _doesSupportObject(e){let t=he._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}he._supportsObject=t}return t||!1}};he._supportsObject=void 0;var wt=he;var Lt=class{constructor(){this.bindingMap=new qe}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new wt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=o=>{this.unlisten(e,t,s),i(o)};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 Mt=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))}updateCanvasDimensions(e,t=!1){return w(this,null,function*(){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=yield this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i})}save(){return w(this,null,function*(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,yield 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 _t=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;