@vkontakte/videoplayer-interactive 1.0.19-beta.0 → 1.0.19-beta.2

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