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