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