@vkontakte/videoplayer-interactive 1.0.34-dev.d1ff213b.0 → 1.0.34-dev.f77434fe.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esnext.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.34-dev.d1ff213b.0
3
- * Thu, 13 Mar 2025 07:21:12 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.34-dev.f77434fe.0
3
+ * Tue, 25 Mar 2025 06:55:54 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-34/doc/
5
5
  */
6
- var ca=Object.create;var qr=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ua=Object.getPrototypeOf,ha=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var da=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pa(e))!ha.call(t,i)&&i!==r&&qr(t,i,{get:()=>e[i],enumerable:!(n=la(e,i))||n.enumerable});return t};var K=(t,e,r)=>(r=t!=null?ca(ua(t)):{},da(e||!t||!t.__esModule?qr(r,"default",{value:t,enumerable:!0}):r,t));var G=u(($t,Qr)=>{"use strict";var fe=function(t){return t&&t.Math===Math&&t};Qr.exports=fe(typeof globalThis=="object"&&globalThis)||fe(typeof window=="object"&&window)||fe(typeof self=="object"&&self)||fe(typeof global=="object"&&global)||fe(typeof $t=="object"&&$t)||function(){return this}()||Function("return this")()});var _=u((Vh,Xr)=>{"use strict";Xr.exports=function(t){try{return!!t()}catch{return!0}}});var ve=u((Mh,Yr)=>{"use strict";var ma=_();Yr.exports=!ma(function(){var t=function(){}.bind();return typeof t!="function"||t.hasOwnProperty("prototype")})});var rn=u((Nh,tn)=>{"use strict";var fa=ve(),en=Function.prototype,Zr=en.apply,Jr=en.call;tn.exports=typeof Reflect=="object"&&Reflect.apply||(fa?Jr.bind(Zr):function(){return Jr.apply(Zr,arguments)})});var H=u((jh,on)=>{"use strict";var nn=ve(),sn=Function.prototype,_t=sn.call,va=nn&&sn.bind.bind(_t,_t);on.exports=nn?va:function(t){return function(){return _t.apply(t,arguments)}}});var ye=u((Lh,cn)=>{"use strict";var an=H(),ya=an({}.toString),ba=an("".slice);cn.exports=function(t){return ba(ya(t),8,-1)}});var Ft=u(($h,ln)=>{"use strict";var Ca=ye(),ga=H();ln.exports=function(t){if(Ca(t)==="Function")return ga(t)}});var F=u((_h,pn)=>{"use strict";var qt=typeof document=="object"&&document.all;pn.exports=typeof qt>"u"&&qt!==void 0?function(t){return typeof t=="function"||t===qt}:function(t){return typeof t=="function"}});var Y=u((Fh,un)=>{"use strict";var Ea=_();un.exports=!Ea(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Ye=u((qh,hn)=>{"use strict";var Ia=ve(),Xe=Function.prototype.call;hn.exports=Ia?Xe.bind(Xe):function(){return Xe.apply(Xe,arguments)}});var Bt=u(fn=>{"use strict";var dn={}.propertyIsEnumerable,mn=Object.getOwnPropertyDescriptor,Ta=mn&&!dn.call({1:2},1);fn.f=Ta?function(e){var r=mn(this,e);return!!r&&r.enumerable}:dn});var Dt=u((Dh,vn)=>{"use strict";vn.exports=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}});var bn=u((Hh,yn)=>{"use strict";var xa=H(),Sa=_(),wa=ye(),Ht=Object,Aa=xa("".split);yn.exports=Sa(function(){return!Ht("z").propertyIsEnumerable(0)})?function(t){return wa(t)==="String"?Aa(t,""):Ht(t)}:Ht});var Ut=u((Uh,Cn)=>{"use strict";Cn.exports=function(t){return t==null}});var Gt=u((Gh,gn)=>{"use strict";var Ra=Ut(),Oa=TypeError;gn.exports=function(t){if(Ra(t))throw new Oa("Can't call method on "+t);return t}});var be=u((zh,En)=>{"use strict";var Pa=bn(),ka=Gt();En.exports=function(t){return Pa(ka(t))}});var oe=u((Wh,In)=>{"use strict";var Va=F();In.exports=function(t){return typeof t=="object"?t!==null:Va(t)}});var Ze=u((Kh,Tn)=>{"use strict";Tn.exports={}});var Je=u((Qh,Sn)=>{"use strict";var zt=Ze(),Wt=G(),Ma=F(),xn=function(t){return Ma(t)?t:void 0};Sn.exports=function(t,e){return arguments.length<2?xn(zt[t])||xn(Wt[t]):zt[t]&&zt[t][e]||Wt[t]&&Wt[t][e]}});var An=u((Xh,wn)=>{"use strict";var Na=H();wn.exports=Na({}.isPrototypeOf)});var kn=u((Yh,Pn)=>{"use strict";var ja=G(),Rn=ja.navigator,On=Rn&&Rn.userAgent;Pn.exports=On?String(On):""});var _n=u((Zh,$n)=>{"use strict";var Ln=G(),Kt=kn(),Vn=Ln.process,Mn=Ln.Deno,Nn=Vn&&Vn.versions||Mn&&Mn.version,jn=Nn&&Nn.v8,U,et;jn&&(U=jn.split("."),et=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!et&&Kt&&(U=Kt.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=Kt.match(/Chrome\/(\d+)/),U&&(et=+U[1])));$n.exports=et});var Qt=u((Jh,qn)=>{"use strict";var Fn=_n(),La=_(),$a=G(),_a=$a.String;qn.exports=!!Object.getOwnPropertySymbols&&!La(function(){var t=Symbol("symbol detection");return!_a(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&Fn&&Fn<41})});var Xt=u((ed,Bn)=>{"use strict";var Fa=Qt();Bn.exports=Fa&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Yt=u((td,Dn)=>{"use strict";var qa=Je(),Ba=F(),Da=An(),Ha=Xt(),Ua=Object;Dn.exports=Ha?function(t){return typeof t=="symbol"}:function(t){var e=qa("Symbol");return Ba(e)&&Da(e.prototype,Ua(t))}});var Un=u((rd,Hn)=>{"use strict";var Ga=String;Hn.exports=function(t){try{return Ga(t)}catch{return"Object"}}});var Zt=u((nd,Gn)=>{"use strict";var za=F(),Wa=Un(),Ka=TypeError;Gn.exports=function(t){if(za(t))return t;throw new Ka(Wa(t)+" is not a function")}});var Wn=u((id,zn)=>{"use strict";var Qa=Zt(),Xa=Ut();zn.exports=function(t,e){var r=t[e];return Xa(r)?void 0:Qa(r)}});var Qn=u((sd,Kn)=>{"use strict";var Jt=Ye(),er=F(),tr=oe(),Ya=TypeError;Kn.exports=function(t,e){var r,n;if(e==="string"&&er(r=t.toString)&&!tr(n=Jt(r,t))||er(r=t.valueOf)&&!tr(n=Jt(r,t))||e!=="string"&&er(r=t.toString)&&!tr(n=Jt(r,t)))return n;throw new Ya("Can't convert object to primitive value")}});var Yn=u((od,Xn)=>{"use strict";Xn.exports=!0});var ei=u((ad,Jn)=>{"use strict";var Zn=G(),Za=Object.defineProperty;Jn.exports=function(t,e){try{Za(Zn,t,{value:e,configurable:!0,writable:!0})}catch{Zn[t]=e}return e}});var tt=u((cd,ni)=>{"use strict";var Ja=Yn(),ec=G(),tc=ei(),ti="__core-js_shared__",ri=ni.exports=ec[ti]||tc(ti,{});(ri.versions||(ri.versions=[])).push({version:"3.38.0",mode:Ja?"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 rr=u((ld,si)=>{"use strict";var ii=tt();si.exports=function(t,e){return ii[t]||(ii[t]=e||{})}});var Ce=u((pd,oi)=>{"use strict";var rc=Gt(),nc=Object;oi.exports=function(t){return nc(rc(t))}});var ae=u((ud,ai)=>{"use strict";var ic=H(),sc=Ce(),oc=ic({}.hasOwnProperty);ai.exports=Object.hasOwn||function(e,r){return oc(sc(e),r)}});var nr=u((hd,ci)=>{"use strict";var ac=H(),cc=0,lc=Math.random(),pc=ac(1 .toString);ci.exports=function(t){return"Symbol("+(t===void 0?"":t)+")_"+pc(++cc+lc,36)}});var ge=u((dd,pi)=>{"use strict";var uc=G(),hc=rr(),li=ae(),dc=nr(),mc=Qt(),fc=Xt(),ce=uc.Symbol,ir=hc("wks"),vc=fc?ce.for||ce:ce&&ce.withoutSetter||dc;pi.exports=function(t){return li(ir,t)||(ir[t]=mc&&li(ce,t)?ce[t]:vc("Symbol."+t)),ir[t]}});var mi=u((md,di)=>{"use strict";var yc=Ye(),ui=oe(),hi=Yt(),bc=Wn(),Cc=Qn(),gc=ge(),Ec=TypeError,Ic=gc("toPrimitive");di.exports=function(t,e){if(!ui(t)||hi(t))return t;var r=bc(t,Ic),n;if(r){if(e===void 0&&(e="default"),n=yc(r,t,e),!ui(n)||hi(n))return n;throw new Ec("Can't convert object to primitive value")}return e===void 0&&(e="number"),Cc(t,e)}});var sr=u((fd,fi)=>{"use strict";var Tc=mi(),xc=Yt();fi.exports=function(t){var e=Tc(t,"string");return xc(e)?e:e+""}});var bi=u((vd,yi)=>{"use strict";var Sc=G(),vi=oe(),or=Sc.document,wc=vi(or)&&vi(or.createElement);yi.exports=function(t){return wc?or.createElement(t):{}}});var ar=u((yd,Ci)=>{"use strict";var Ac=Y(),Rc=_(),Oc=bi();Ci.exports=!Ac&&!Rc(function(){return Object.defineProperty(Oc("div"),"a",{get:function(){return 7}}).a!==7})});var Ii=u(Ei=>{"use strict";var Pc=Y(),kc=Ye(),Vc=Bt(),Mc=Dt(),Nc=be(),jc=sr(),Lc=ae(),$c=ar(),gi=Object.getOwnPropertyDescriptor;Ei.f=Pc?gi:function(e,r){if(e=Nc(e),r=jc(r),$c)try{return gi(e,r)}catch{}if(Lc(e,r))return Mc(!kc(Vc.f,e,r),e[r])}});var xi=u((Cd,Ti)=>{"use strict";var _c=_(),Fc=F(),qc=/#|\.prototype\./,Ee=function(t,e){var r=Dc[Bc(t)];return r===Uc?!0:r===Hc?!1:Fc(e)?_c(e):!!e},Bc=Ee.normalize=function(t){return String(t).replace(qc,".").toLowerCase()},Dc=Ee.data={},Hc=Ee.NATIVE="N",Uc=Ee.POLYFILL="P";Ti.exports=Ee});var cr=u((gd,wi)=>{"use strict";var Si=Ft(),Gc=Zt(),zc=ve(),Wc=Si(Si.bind);wi.exports=function(t,e){return Gc(t),e===void 0?t:zc?Wc(t,e):function(){return t.apply(e,arguments)}}});var Ri=u((Ed,Ai)=>{"use strict";var Kc=Y(),Qc=_();Ai.exports=Kc&&Qc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Pi=u((Id,Oi)=>{"use strict";var Xc=oe(),Yc=String,Zc=TypeError;Oi.exports=function(t){if(Xc(t))return t;throw new Zc(Yc(t)+" is not an object")}});var Mi=u(Vi=>{"use strict";var Jc=Y(),el=ar(),tl=Ri(),rt=Pi(),ki=sr(),rl=TypeError,lr=Object.defineProperty,nl=Object.getOwnPropertyDescriptor,pr="enumerable",ur="configurable",hr="writable";Vi.f=Jc?tl?function(e,r,n){if(rt(e),r=ki(r),rt(n),typeof e=="function"&&r==="prototype"&&"value"in n&&hr in n&&!n[hr]){var i=nl(e,r);i&&i[hr]&&(e[r]=n.value,n={configurable:ur in n?n[ur]:i[ur],enumerable:pr in n?n[pr]:i[pr],writable:!1})}return lr(e,r,n)}:lr:function(e,r,n){if(rt(e),r=ki(r),rt(n),el)try{return lr(e,r,n)}catch{}if("get"in n||"set"in n)throw new rl("Accessors not supported");return"value"in n&&(e[r]=n.value),e}});var ji=u((xd,Ni)=>{"use strict";var il=Y(),sl=Mi(),ol=Dt();Ni.exports=il?function(t,e,r){return sl.f(t,e,ol(1,r))}:function(t,e,r){return t[e]=r,t}});var Te=u((Sd,$i)=>{"use strict";var Ie=G(),al=rn(),cl=Ft(),ll=F(),pl=Ii().f,ul=xi(),le=Ze(),hl=cr(),pe=ji(),Li=ae();tt();var dl=function(t){var e=function(r,n,i){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,n)}return new t(r,n,i)}return al(t,this,arguments)};return e.prototype=t.prototype,e};$i.exports=function(t,e){var r=t.target,n=t.global,i=t.stat,s=t.proto,c=n?Ie:i?Ie[r]:Ie[r]&&Ie[r].prototype,o=n?le:le[r]||pe(le,r,{})[r],a=o.prototype,l,d,m,f,y,R,E,C,I;for(f in e)l=ul(n?f:r+(i?".":"#")+f,t.forced),d=!l&&c&&Li(c,f),R=o[f],d&&(t.dontCallGetSet?(I=pl(c,f),E=I&&I.value):E=c[f]),y=d&&E?E:e[f],!(!l&&!s&&typeof R==typeof y)&&(t.bind&&d?C=hl(y,Ie):t.wrap&&d?C=dl(y):s&&ll(y)?C=cl(y):C=y,(t.sham||y&&y.sham||R&&R.sham)&&pe(C,"sham",!0),pe(o,f,C),s&&(m=r+"Prototype",Li(le,m)||pe(le,m,{}),pe(le[m],f,y),t.real&&a&&(l||!a[f])&&pe(a,f,y)))}});var Fi=u((wd,_i)=>{"use strict";var ml=Math.ceil,fl=Math.floor;_i.exports=Math.trunc||function(e){var r=+e;return(r>0?fl:ml)(r)}});var xe=u((Ad,qi)=>{"use strict";var vl=Fi();qi.exports=function(t){var e=+t;return e!==e||e===0?0:vl(e)}});var Di=u((Rd,Bi)=>{"use strict";var yl=xe(),bl=Math.min;Bi.exports=function(t){var e=yl(t);return e>0?bl(e,9007199254740991):0}});var Se=u((Od,Hi)=>{"use strict";var Cl=Di();Hi.exports=function(t){return Cl(t.length)}});var nt=u((Pd,Ui)=>{"use strict";Ui.exports=function(){}});var Gi=u(()=>{"use strict";var gl=Te(),El=Ce(),Il=Se(),Tl=xe(),xl=nt();gl({target:"Array",proto:!0},{at:function(e){var r=El(this),n=Il(r),i=Tl(e),s=i>=0?i:n+i;return s<0||s>=n?void 0:r[s]}});xl("at")});var it=u((Md,zi)=>{"use strict";var Sl=Je();zi.exports=Sl});var Ki=u((Nd,Wi)=>{"use strict";Gi();var wl=it();Wi.exports=wl("Array","at")});var Xi=u((jd,Qi)=>{"use strict";var Al=Ki();Qi.exports=Al});var dr=u((Ld,Yi)=>{"use strict";var Rl=Xi();Yi.exports=Rl});var ds=u((Wm,hs)=>{"use strict";var _l=rr(),Fl=nr(),us=_l("keys");hs.exports=function(t){return us[t]||(us[t]=Fl(t))}});var fs=u((Km,ms)=>{"use strict";var ql=_();ms.exports=!ql(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})});var bs=u((Qm,ys)=>{"use strict";var Bl=ae(),Dl=F(),Hl=Ce(),Ul=ds(),Gl=fs(),vs=Ul("IE_PROTO"),Tr=Object,zl=Tr.prototype;ys.exports=Gl?Tr.getPrototypeOf:function(t){var e=Hl(t);if(Bl(e,vs))return e[vs];var r=e.constructor;return Dl(r)&&e instanceof r?r.prototype:e instanceof Tr?zl:null}});var gs=u((Xm,Cs)=>{"use strict";var Wl=xe(),Kl=Math.max,Ql=Math.min;Cs.exports=function(t,e){var r=Wl(t);return r<0?Kl(r+e,0):Ql(r,e)}});var xr=u((Ym,Is)=>{"use strict";var Xl=be(),Yl=gs(),Zl=Se(),Es=function(t){return function(e,r,n){var i=Xl(e),s=Zl(i);if(s===0)return!t&&-1;var c=Yl(n,s),o;if(t&&r!==r){for(;s>c;)if(o=i[c++],o!==o)return!0}else for(;s>c;c++)if((t||c in i)&&i[c]===r)return t||c||0;return!t&&-1}};Is.exports={includes:Es(!0),indexOf:Es(!1)}});var xs=u((Zm,Ts)=>{"use strict";Ts.exports={}});var As=u((Jm,ws)=>{"use strict";var Jl=H(),Sr=ae(),ep=be(),tp=xr().indexOf,rp=xs(),Ss=Jl([].push);ws.exports=function(t,e){var r=ep(t),n=0,i=[],s;for(s in r)!Sr(rp,s)&&Sr(r,s)&&Ss(i,s);for(;e.length>n;)Sr(r,s=e[n++])&&(~tp(i,s)||Ss(i,s));return i}});var Os=u((ef,Rs)=>{"use strict";Rs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var ks=u((tf,Ps)=>{"use strict";var np=As(),ip=Os();Ps.exports=Object.keys||function(e){return np(e,ip)}});var $s=u((rf,Ls)=>{"use strict";var Ms=Y(),sp=_(),Ns=H(),op=bs(),ap=ks(),cp=be(),lp=Bt().f,js=Ns(lp),pp=Ns([].push),up=Ms&&sp(function(){var t=Object.create(null);return t[2]=2,!js(t,2)}),Vs=function(t){return function(e){for(var r=cp(e),n=ap(r),i=up&&op(r)===null,s=n.length,c=0,o=[],a;s>c;)a=n[c++],(!Ms||(i?a in r:js(r,a)))&&pp(o,t?[a,r[a]]:r[a]);return o}};Ls.exports={entries:Vs(!0),values:Vs(!1)}});var _s=u(()=>{"use strict";var hp=Te(),dp=$s().values;hp({target:"Object",stat:!0},{values:function(e){return dp(e)}})});var qs=u((of,Fs)=>{"use strict";_s();var mp=Ze();Fs.exports=mp.Object.values});var Ds=u((af,Bs)=>{"use strict";var fp=qs();Bs.exports=fp});var gt=u((cf,Hs)=>{"use strict";var vp=Ds();Hs.exports=vp});var zs=u(()=>{"use strict";var yp=Te(),bp=xr().includes,Cp=_(),gp=nt(),Ep=Cp(function(){return!Array(1).includes()});yp({target:"Array",proto:!0,forced:Ep},{includes:function(e){return bp(this,e,arguments.length>1?arguments[1]:void 0)}});gp("includes")});var Ks=u((df,Ws)=>{"use strict";zs();var Ip=it();Ws.exports=Ip("Array","includes")});var Xs=u((mf,Qs)=>{"use strict";var Tp=Ks();Qs.exports=Tp});var Et=u((ff,Ys)=>{"use strict";var xp=Xs();Ys.exports=xp});var Pr=u((Mf,ro)=>{"use strict";var Pp=ye();ro.exports=Array.isArray||function(e){return Pp(e)==="Array"}});var io=u((Nf,no)=>{"use strict";var kp=TypeError,Vp=9007199254740991;no.exports=function(t){if(t>Vp)throw kp("Maximum allowed index exceeded");return t}});var ao=u((jf,oo)=>{"use strict";var Mp=Pr(),Np=Se(),jp=io(),Lp=cr(),so=function(t,e,r,n,i,s,c,o){for(var a=i,l=0,d=c?Lp(c,o):!1,m,f;l<n;)l in r&&(m=d?d(r[l],l,e):r[l],s>0&&Mp(m)?(f=Np(m),a=so(t,e,m,f,a,s-1)-1):(jp(a+1),t[a]=m),a++),l++;return a};oo.exports=so});var po=u((Lf,lo)=>{"use strict";var $p=ge(),_p=$p("toStringTag"),co={};co[_p]="z";lo.exports=String(co)==="[object z]"});var ho=u(($f,uo)=>{"use strict";var Fp=po(),qp=F(),Tt=ye(),Bp=ge(),Dp=Bp("toStringTag"),Hp=Object,Up=Tt(function(){return arguments}())==="Arguments",Gp=function(t,e){try{return t[e]}catch{}};uo.exports=Fp?Tt:function(t){var e,r,n;return t===void 0?"Undefined":t===null?"Null":typeof(r=Gp(e=Hp(t),Dp))=="string"?r:Up?Tt(e):(n=Tt(e))==="Object"&&qp(e.callee)?"Arguments":n}});var fo=u((_f,mo)=>{"use strict";var zp=H(),Wp=F(),kr=tt(),Kp=zp(Function.toString);Wp(kr.inspectSource)||(kr.inspectSource=function(t){return Kp(t)});mo.exports=kr.inspectSource});var Eo=u((Ff,go)=>{"use strict";var Qp=H(),Xp=_(),vo=F(),Yp=ho(),Zp=Je(),Jp=fo(),yo=function(){},bo=Zp("Reflect","construct"),Vr=/^\s*(?:class|function)\b/,eu=Qp(Vr.exec),tu=!Vr.test(yo),Le=function(e){if(!vo(e))return!1;try{return bo(yo,[],e),!0}catch{return!1}},Co=function(e){if(!vo(e))return!1;switch(Yp(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return tu||!!eu(Vr,Jp(e))}catch{return!0}};Co.sham=!0;go.exports=!bo||Xp(function(){var t;return Le(Le.call)||!Le(Object)||!Le(function(){t=!0})||t})?Co:Le});var So=u((qf,xo)=>{"use strict";var Io=Pr(),ru=Eo(),nu=oe(),iu=ge(),su=iu("species"),To=Array;xo.exports=function(t){var e;return Io(t)&&(e=t.constructor,ru(e)&&(e===To||Io(e.prototype))?e=void 0:nu(e)&&(e=e[su],e===null&&(e=void 0))),e===void 0?To:e}});var Ao=u((Bf,wo)=>{"use strict";var ou=So();wo.exports=function(t,e){return new(ou(t))(e===0?0:e)}});var Ro=u(()=>{"use strict";var au=Te(),cu=ao(),lu=Ce(),pu=Se(),uu=xe(),hu=Ao();au({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,r=lu(this),n=pu(r),i=hu(r,0);return i.length=cu(i,r,r,n,0,e===void 0?1:uu(e)),i}})});var Oo=u(()=>{"use strict";var du=nt();du("flat")});var ko=u((zf,Po)=>{"use strict";Ro();Oo();var mu=it();Po.exports=mu("Array","flat")});var Mo=u((Wf,Vo)=>{"use strict";var fu=ko();Vo.exports=fu});var jo=u((Kf,No)=>{"use strict";var vu=Mo();No.exports=vu});var Br="1.0.34-dev.d1ff213b.0";var Ot=class{constructor(e){this.layout=e}},Be=class extends Ot{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,r){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${r.width})`,e.style.height=`calc(var(--interactive-content-height) * ${r.height})`,e.style.left=`calc(var(--interactive-content-width) * ${r.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${r.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};function Dr(t){return"features"in t}var ne=class{constructor(e,r){this.container=e,this.options=r,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&Dr(this.options)&&this.options.features[e]}addControlFactory(e,r){this.factories.set(e.trim().toLowerCase(),r),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((e,r)=>{let n=r.type.trim().toLowerCase(),i=this.factories.get(n);if(i){let s=i(r,this.options);if(s)return[...e,s]}return[...e]},[])||[]}};function Pt(t,e=1){let r="0",n="0",i="0";return t.length===4?(r="0x"+t[1]+t[1],n="0x"+t[2]+t[2],i="0x"+t[3]+t[3]):t.length===7&&(r="0x"+t[1]+t[2],n="0x"+t[3]+t[4],i="0x"+t[5]+t[6]),`rgba(${+r},${+n},${+i},${e})`}var Hr="interactive",N={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Ur=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(Ur||{}),Gr=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(Gr||{}),zr=(n=>(n.start="left",n.end="right",n.center="center",n))(zr||{}),De=({target:t,props:e})=>{t.style.alignItems=(e?.gravityVertical&&Ur[e.gravityVertical])??"center",t.style.justifyContent=(e?.gravityHorizontal&&Gr[e.gravityHorizontal])??"center",t.style.textAlign=(e?.alignment&&zr[e.alignment])??"center"},He=({target:t,props:e,fallback:r,dependsOn:n})=>{t.style.color=e?.text?.color??r.textColor,t.style.fontSize=`calc(${n.height} * ${e?.text?.size??r.textSize})`,t.textContent=e?.text?.value??r.textContent},Ue=({target:t,props:e,fallback:r})=>{t.style.backgroundColor=Pt(e?.background?.color??r.backgroundColor,e?.background?.alpha??r.backgroundAlpha)},Ge=({target:t,props:e,fallback:r,dependsOn:n})=>{t.style.border=`calc(${n.height} * ${e?.shape?.border?.width??r.borderWidth}) solid ${Pt(e?.shape?.border?.color??r.borderColor,e?.shape?.border?.alpha??r.borderAlpha)}`,t.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??r.roundCorners})`},ie=({target:t,layoutParams:e,fallback:r})=>{let n=e.angle??r.angle;n=n&&n*-1,t.style.transform=`rotate(${n}rad)`};var kt="int",X=(n=>(n.AREA=`${kt}_area`,n.TEXT=`${kt}_text`,n.BUTTON=`${kt}_bttn`,n))(X||{});function Wr(t){return"features"in t}var se="interactive-control",P={common:se,wrapper:`${se}-wrapper`,disabled:`${se}-disabled`,button:`${se}-button`,area:`${se}-area`,text:`${se}-text`};var Q=class{constructor(e,r){this.control=e;this.options=r;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let r=document.createElement("div");r.classList.add(P.wrapper),e.setControlLayout(r,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??N.innerSizesDependOn)==="self"?{height:r.style.height,width:r.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:r,dimensions:n}}createClickListener(e){return r=>{r.stopPropagation(),e()}}featureIsEnabled(e){return this.options&&Wr(this.options)&&this.options.features[e]}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(r=>{switch(r.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:r.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var ze=(t,e)=>{if(t.type.trim().toLowerCase()==="area")return new Vt(t,e)},Vt=class extends Q{constructor(e,r){super(e,r)}createView({parentElement:e,callbacks:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(P.common,P.area),n.setAttribute("data-testid",X.AREA),Ue({target:n,props:this.control.props,fallback:{...N,backgroundColor:"transparent"}}),Ge({target:n,props:this.control.props,fallback:{...N,borderAlpha:0},dependsOn:this.container.dimensions}),ie({target:n,layoutParams:this.control.layoutParams,fallback:N}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(P.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(P.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var We=t=>{let e=document.createElement("span");switch(t){case"Button":case"button":{let r=document.createElement("div"),n={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(r.style,n),r.append(e);let i={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,i),r}default:{let r={display:"inline-block",whiteSpace:"break-spaces",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",maxHeight:"100%",wordBreak:"break-all"};return Object.assign(e.style,r),e}}};var Ke=(t,e)=>{if(t.type.trim().toLowerCase()==="button")return new Mt(t,e)},Mt=class extends Q{constructor(e,r){super(e,r)}createView({parentElement:e,callbacks:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(P.common,P.button),n.setAttribute("data-testid",X.BUTTON),ie({target:n,layoutParams:this.control.layoutParams,fallback:N}),Ue({target:n,props:this.control.props,fallback:N}),Ge({target:n,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),De({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=We(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;He({target:s,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(P.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(P.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var Kr=(t,e)=>{if(t.type.trim().toLowerCase()==="text")return new Nt(t,e)},Nt=class extends Q{constructor(e,r){super(e,r)}createView({parentElement:e,callbacks:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("div");n.classList.add(P.common,P.text),n.setAttribute("data-testid",X.TEXT),ie({target:n,layoutParams:this.control.layoutParams,fallback:N}),De({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=We(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;He({target:s,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}};var jt="interactive-container",$={common:jt,hidden:`${jt}-hidden`,disabled:`${jt}-disabled`};var Qe=(t,e,r)=>{if(t.type.trim().toLowerCase()==="choice")return new Lt(t,e,r)},Lt=class extends ne{constructor(r,n,i){super(r,i);this.containerElement=null;this.rootElement=n,this.layout=new Be(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Ke),this.addControlFactory("text",Kr),this.addControlFactory("area",ze)}createView({eventCallback:r}){let n=document.createElement("div");return n.classList.add($.common,$.disabled),requestAnimationFrame(()=>{n.classList.remove($.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout}}),i.setEvents(r)}),this.rootElement.append(n),this.isRemoved=!1,this.containerElement=n,n}hide(){let r=this.getElement();r&&r.classList.add($.hidden)}show(){let r=this.getElement();r&&r.classList.remove($.hidden)}enable(){let r=this.getElement();r&&(r.classList.remove($.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let r=this.getElement();r&&(r.classList.add($.disabled),this.controls.forEach(n=>n.disable()),this.isDisabled=!0)}removeView(){let r=this.getElement();r&&(this.controls.forEach(n=>n.removeListeners()),r.remove(),this.isRemoved=!0,this.containerElement=null)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(r,n){n&&this.controls.forEach(i=>{i.onProgress(r)})}onResize(r){r&&this.controls.forEach(n=>{n.onResize()})}};var oa=K(dr(),1);import{combine as Ou,InterfaceLanguage as Pu,Observable as na,once as ku,Subject as j,Subscription as _r,ValueSubject as L,fromEvent as ia}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Fe}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Ol}from"@vkontakte/videoplayer-shared";function we(t,e){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>t(...n),e)}}var Z=(t,e)=>Object.prototype.toString.call(t)===`[object ${e}]`,Ae=t=>Z(t,"Object"),st=t=>Z(t,"String"),ot=t=>Z(t,"Array"),at=t=>Z(t,"Number"),Zi=t=>Z(t,"Function");var mr=t=>at(t)&&!isNaN(t);var J=t=>Ae(t)&&Object.keys(t).length===0,fr=t=>ot(t)&&!t.length;var Re=(t,e)=>st(t)&&(e?t.trim():t).length;var Ji="video_interactive",es="videoint";var ts=250,Oe=class{constructor(e){this.handleZoomChange=we(e=>{this.lastZoomInfo=e},ts);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let r=this.getNextPoint();r&&this.ngEditor?.zoomTo(r),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Chapter id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,r=[])=>{if(this.isReady=!1,!at(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(r),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(r)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:r,onError:n,lang:i,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=r,this.onError=n,this.lang=i??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Pl(e),this.resizeObserver=new ResizeObserver(we(this.onResize,ts)),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){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await Ol(this.lang,Ji,es)}catch{this.onError?.("Unable to load graph language pack")}let{GraphEditor:r}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new r(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:n,...i})=>{n==="openPreview"&&"chapterId"in i&&this.onOpenPreviewClick?.(i.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Pl(t){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",t.append(e),e}var Pe=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(r=>r.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let r=-1,n=!1,i=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let c=s.startTime-e;if(c<=i&&(s.endTime&&i<=s.endTime||s.endTime===null)){n=!0;break}i<c&&(r=r===-1?c:Math.min(r,c))}return!n&&r!==-1?r:null}}};import{isSupportedManifest as lt,ContainerTypes as am,ControlTypes as pt,EventActionTypes as w,EventTypes as cm,migrateManifestToLatestVersion as ss,compareVersions as lm}from"@interactiveplatform/movika-manifest";var rs={metadata:"Object",chapters:"Array"},ns=t=>{if(!Ae(t))return!1;for(let e in rs)if(!t[e]||!Z(t[e],rs[e]))return!1;return lt(t.metadata.version)},ct=t=>t.type===pt.Text,Jd=t=>t.type===pt.Button,em=t=>t.type===pt.Area,tm={Choice:"Choice",TextInput:"TextInput"},rm={Button:"Button",Area:"Area",Text:"Text"},nm={onClick:"onClick",onSuspense:"onSuspense"},is={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var M=class{constructor(e,r,...n){this.severity=e;this.category=r;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var ut=class{constructor(){this.listeners={}}addListener(e,r){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(r),this}on(e,r){return this.addListener(e,r)}once(e,r){this.listeners[e]=this.listeners[e]||[];let n=()=>{r(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,r){return this.removeListener(e,r)}reset(){this.listeners={}}removeListener(e,r){let n=this.listeners[e]||[];for(let i=n.length;i>0;i--)if(n[i]===r){n.splice(i,1);break}return this}emit(e,...r){let n=this.listeners[e];return n?(n.forEach(i=>{i(...r)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var ht=class{constructor(e){this.fns=[];this.addFn=(e,r=!1)=>{Zi(e)&&(this.fns.push(e),r&&this.updateFn())};this.removeFn=(e,r=!1)=>{this.fns=this.fns.filter(n=>n!==e),r&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as $l}from"@vkontakte/videoplayer-shared";var dt=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,r){return kl(...this.loaders[e])(r)}};function kl(...t){return async function(r){let n=[...t];for(;n.length>0;)r=await n.shift()(r);return r}}function ke(t,e,r){return t?{...t,[e]:t[e]?[r,...t[e]]:[r]}:{[e]:[r]}}function mt({actions:t,errors:e,chapterId:r,...n}){if(r){let i=t.getManifest();if(i){let s=t.getChapter(i.chapters,r);if(s){let c=t.getMedia(i.media,s.videoId),o=t.getGraph(i.graph,s.id);return c?{...n,actions:t,errors:e,result:{chapter:s,media:c,graph:o}}:{...n,errors:ke(e,mt.name,"Could not find media"),actions:t}}}}return{...n,errors:ke(e,mt.name,"Could not find chapter"),actions:t}}var ft=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:n})}removeEventListener(e,r){if(!(e in this.listeners))return;let n=this.listeners[e];for(let i=0,s=n.length;i<s;i++)if(n[i].callback===r){n.splice(i,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let n=this.listeners[e.type].slice();for(let i=0,s=n.length;i<s;i++){let c=n[i];try{c.callback.call(this,e)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(e.type,c.callback)}return!e.defaultPrevented}},ue=class extends ft{constructor(){super(),this.listeners||ft.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Ve=class{constructor(){Object.defineProperty(this,"signal",{value:new ue,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch{typeof document<"u"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let n=e;if(n===void 0)if(typeof document>"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(Ve.prototype[Symbol.toStringTag]="AbortController",ue.prototype[Symbol.toStringTag]="AbortSignal");function vt(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function vr(t){typeof t=="function"&&(t={fetch:t});let{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!vt({fetch:e,Request:r,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:s};let s=r;(s&&!s.prototype.hasOwnProperty("signal")||i)&&(s=function(l,d){let m;d&&d.signal&&(m=d.signal,delete d.signal);let f=new r(l,d);return m&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),f},s.prototype=r.prototype);let c=e;return{fetch:(a,l)=>{let d=s&&s.prototype.isPrototypeOf(a)?a.signal:l?l.signal:void 0;if(d){let m;try{m=new DOMException("Aborted","AbortError")}catch{m=new Error("Aborted"),m.name="AbortError"}if(d.aborted)return Promise.reject(m);let f=new Promise((y,R)=>{d.addEventListener("abort",()=>R(m),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([f,c(a,l)])}return c(a,l)},Request:s}}var Me=vt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),os=Me?vr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,yr=Me?os.fetch:window.fetch,Am=Me?os.Request:window.Request,Rm=Me?Ve:window.AbortController,Om=Me?ue:window.AbortSignal;var br=(t="",e="")=>{let r=t.split("."),n=e.split("."),i=0;for(let s=0;s<Math.max(r.length,n.length)&&!i;s++)r[s]>n[s]?i=1:r[s]<n[s]?i=-1:i=0;return i};var Vl=async t=>{try{let e={},r;if(st(t)){r=new URL(t).href;let i=await yr(r);if(!i.ok)return{};e=await i.json()}else if(Ae(t))e=t;else return{};if(!ns(e))return{};let n=e.metadata.media;if(st(n)&&!("media"in e))try{let i;r?i=new URL(n,r).href:(i=new URL(n).href,r=i);let s=await yr(i);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return jl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:r}}catch{return{}}};async function as(t){let{manifest:e,manifestURL:r}=await Vl(t);if(!e)throw new Error("Failed on fetch");let n=ss(e);return n.media=Ml(n.media,r),delete n.metadata.media,n}function yt(t,e){if(e)return t.find(r=>r.id===e)}function Cr(t,e){return t.edit?.chapters?t.edit.chapters.find(r=>r.id===e):t.view?.chapters?t.view.chapters.find(r=>r.id===e):void 0}function gr(t,e){return t.videos.find(r=>r.id===e)}function Ml(t,e){return{...t,videos:t.videos.map(r=>({...r,variants:r.variants.map(n=>{let i="url"in n?n.url:"",s=Nl(i,e);return{...n,url:s||i}})}))}}function Nl(t="",e){try{return new URL(t,e).href}catch{return""}}function jl(t){return br(t,"3.2.0")>=0}var bt=t=>ot(t)&&!fr(t),z=t=>t.order==="end",Ct=t=>ot(t.containers)&&!fr(t.containers)&&z(t),cs=(t,e)=>{let r=t*1e3;return bt(e.controls)&&r<(e.startTime??0)},Er=(t,e)=>{let r=t*1e3;return bt(e.controls)&&r>=(e.startTime??0)&&r<=(e.endTime??1/0)};var ee=(t=[])=>t.some(e=>e.action.type==="expect"),Ir=(t=[])=>t.find(e=>e.action.type==="expect"),Ll=t=>t?.length===1,he=t=>Ll(t)&&ct(t[0]);function ls(t,...e){return r=>typeof e[0]=="object"&&typeof r=="object"?t({...e[0],...r}):t(...e,...r)}var ps=(t,e)=>{let r=E=>e.find(({container:I})=>I.container.id===E)?.container.isRemoved,n=ee(t.events)&&!r(t.id),i=(E,C=!1,I=!1)=>{let h=I?"every":"some";return E.controls[h](p=>{let v=C?E.endTime===t.endTime:!0;return p.events?.[h](b=>b.action?.type===is.openURI)&&v})},s=E=>E.some(({container:C})=>i(C.container,!0,!1)&&!C.isRemoved),c=E=>E.every(({container:C})=>C.isRemoved?!0:i(C.container,!0,!0)),o=e.filter(({container:E})=>E.container.id!==t.id&&ee(E.container.events)&&E.container.endTime===t.endTime&&!E.isRemoved).length,a=E=>E.controls.some(C=>C.events?.some(I=>I.action?.args?.shouldOpenNow)),l=n||o>0,d=s(e),m=i(t),f=c(e),y=n?!1:o>0,R=a(t);return{isExpectTime:l,hasOtherExpect:o>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:m,isAllOpenURIEventsValid:f,isExpectEventForCurrentContainer:y,hasShouldOpenNowEvent:R}};var de=class extends dt{constructor(r,n){super(r);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new $l(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(r){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:ke},result:null,errors:null,source:r});return n.errors&&this.errorHandler(n.errors),this.manifest=await as(n.result??r),this}async setInitial(){return this.setNext()}async setNext(r=this.manifest?.metadata.initChapterId){if(!r)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",mt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Cr,getChapter:yt,getMedia:gr,getByBranches:this.getByBranches.bind(this),addErrorMessage:ke},result:null,errors:null,chapterId:r}));return n.errors&&this.errorHandler(n.errors),n.result&&(this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph),this}errorHandler(r){this.onError(r),console.error("Something went wrong with loaders",{errors:r})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(r=this.manifest?.metadata.initChapterId){if(!r||!this.manifest)return null;let n=yt(this.manifest.chapters,r);if(n){let i=gr(this.manifest.media,n.videoId),s=Cr(this.manifest.graph,n.id);if(i)return{chapter:n,media:i,graph:s}}return null}getBranches(r=this.chapter?.id){if(r===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=yt(this.manifest?.chapters||[],r);return this.getByBranches(n?.branches)}}getByBranches(r=[]){return r.reduce((n,i)=>{let s=this.getByChapterId(i.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?z(this.chapter):!1}};var Zs=K(gt(),1);import{Player as Sp}from"@vkontakte/videoplayer-core";import{Subscription as Rr,Tracer as wp,ValueSubject as Ap}from"@vkontakte/videoplayer-shared";var Us=t=>{let e=t.variants.find(r=>r.payload?.type==="vk");if(e&&e.payload){let[r,n]=e.payload.id.split("_");return[r,n]}return[]};var Gs=K(gt(),1);function wr(){let t=new Map;function e({listId:s=Math.random().toString(),itemId:c=Math.random().toString(),...o}){let a=t.get(s),l={...o};return a?a[c]=l:t.set(s,{[c]:l}),{listId:s,itemId:c,...o}}function r(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,c){let o=t.get(s);if(!o)throw Error("Can't remove. Not find.");if(c){let a=o[c];a&&r(a),delete o[c],Object.keys(o).length||t.delete(s)}else{for(let a of(0,Gs.default)(o))r(a);t.delete(s)}}function i(){for(let s of t)n(s[0])}return{createPlayer:e,removePlayer:n,map:t,removeAll:i}}var me=K(Et(),1);function Ar(t,e=[]){let r={},n,i=!e.length;for(let s of t.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(i||(0,me.default)(e,"mp4"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(i||(0,me.default)(e,"mpeg"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(i||(0,me.default)(e,"hls"))&&(r={...r,HLS:{type:"url",url:s.url}});break;case"dash":(i||(0,me.default)(e,"dash"))&&(r={...r,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:r,thumbUrl:n,title:t.title??""}}var Ne=(t,e)=>{let r=t.info.currentQuality$.getValue(),n=t.info.availableQualities$.getValue();r!==e&&(0,me.default)(n,e)&&(t.setQuality(e),t.setAutoQuality(!1))};var Rp=2;function Or(t){let e=wr(),r=new Rr,n={},i=null,s=!1,c,o=new Ap(null);t&&a(t);function a(C){i=C}function l(C,I,h){if(!i)throw Error("need to set interactive controller");if(!i.options)return;let v=(e.map.get(C)??{})[I];if(v){n={chapterId:h,listId:C,itemId:I,...v};let b=n.player;n.subscription.add(b.info.currentQuality$.subscribe(g=>{let T=b.info.position$.getValue(),A=b.info.isAutoQualityEnabled$.getValue();if(!(!g||!T||A))for(let k of e.map)(0,Zs.default)(k[1]).forEach(({player:S})=>{Ne(S,g)})})).add(b.events.started$.subscribe(()=>{d(I)})),v.container.remove(),i.setPlayer(v.player),s||(i.init(),s=!0),o.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function d(C){if(!i)throw Error("need to set interactive controller");if(J(n)||C!==n.itemId)return;let I=i.getChapterBranches(),h=new Set;for(let p of I)h.has(p.media.id)||(await f({media:p.media,chapterId:p.chapter.id,setAsActive:!1,title:p.chapter.label}),h.add(p.media.id))}async function m({chapter:{id:C},manifestVideo:I}){if(J(n)||!i)return;let h=n.player.info.muted$.getValue(),p=n.player.info.currentQuality$.getValue(),v=n.player.info.isAutoQualityEnabled$.getValue(),b=n.player.info.volume$.getValue(),g=n.player.info.currentPlaybackRate$.getValue(),T=!v,A=!1;for(let k of e.map)if(k[0]===I.id&&!i.state.isReplay$.getValue()){let S=Object.keys(k[1]);for(let V of S)V===n.itemId?(S.length<Rp||(A=!0),e.removePlayer(k[0],V)):(A=!0,l(k[0],V,C),T?Ne(n.player,p):n.player.setAutoQuality(!0),n.player.setVolume(b),n.player.setMuted(h),n.player.setPlaybackRate(g))}else e.removePlayer(k[0]);A||(await f({media:I,chapterId:C,setAsActive:!0,playbackRate:g}),T?Ne(n.player,p):n.player.setAutoQuality(!0),n.player.setVolume(b),n.player.setMuted(h))}async function f({media:C,chapterId:I,prefetch:h=!0,setAsActive:p=!0,autoplay:v=!1,preferredExt:b,title:g,playbackRate:T}){let A=Math.random().toString(),k=document.createElement("div");c.append(k);let S;if(i?.options?.vkVideoLoader){let qe=Us(C);qe.length&&(S=await i.options.vkVideoLoader(...qe))}let V=i?.options?.coreConfig||void 0,q={...V,configName:[...V?.configName??[],"interactive"]},B={container:k,...S?.videos?.[0]||{sources:Ar(C,b).sources},title:g,failoverHosts:S?.failoverHosts||[]},D=new Sp(q,wp.createRootTracer());D.initVideo(B);let W=null;if(S?.videos&&i?.options.createOneStat){let qe=S.videos[0],Rt=i.options.createOneStat(qe),Fr=new Rr;Rt&&(Fr.add(Rt.attachTo(D)),W={oneStat:Rt,statSubscription:Fr})}let te=new Rr,aa=n?.player?.info.isAutoQualityEnabled$.getValue();te.add(D.events.canplay$.subscribe(function(){aa||Ne(D,n.player.info.currentQuality$.getValue()),T&&D.setPlaybackRate(T)}));let re=e.createPlayer({listId:C.id,itemId:A,player:D,container:k,sources:Ar(C,b).sources,config:B,subscription:te,statistics:W});return p&&l(C.id,re.itemId,I),v&&re.player.play(),h&&!v&&re.player.prepare(),{player:re.player,config:re.config,statistics:re.statistics}}function y(){R(),i=null,c.remove()}function R(){r.unsubscribe(),e.removeAll(),n={},s=!1}async function E(){if(!i)throw Error("need to set interactive controller");R(),c=document.createElement("div");let{media:C,chapter:I}=i.getCurrentChapter();C&&I?(r.add(i.events.chapterChanged$.subscribe(m)),await f({media:C,chapterId:I.id,title:I.label})):console.error("not found")}return{...e,init:E,setInteractiveController:a,createPlayer:f,removeAll:y,getActivePlayer:function(){return n},activePlayerChanged:o}}var x={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},je={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},O={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var eo=K(Et(),1);import{Subscription as Op}from"@vkontakte/videoplayer-shared";var It=class{constructor({player:e,container:r,branches:n,selectBranches:i,interactiveEvents:s,globalEvents:c,globalEventEmitter:o,getContainerEventState:a,permanentTextControls:l,interactiveTimeOpenUri:d,disabledControls$:m,onRemove:f}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(ee(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:r}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&r)return;this.emitContainerVisibilityEvent(!0,!1)}else{let r={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(i,s)=>{let{isExpectTime:c,hasOtherExpect:o,hasOpenURIEvent:a,hasOpenURIEventInCurrentContainer:l,isAllOpenURIEventsValid:d,hasShouldOpenNowEvent:m}=this.getContainerEventState(),f=this.interactiveTimeOpenUri&&!l,y=this.interactiveTimeOpenUri&&l;if((!this.interactiveTimeOpenUri||f)&&(this.isSelectedControlEvent=!0),i!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||f)){if(this.interactiveTimeOpenUri){let R=!o&&!d&&l;R&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:R})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&a&&this.gameState!==5){if(y){let E=((C,I,h,p)=>!C&&!I&&h||C&&!I&&h&&!p||C&&!I&&h&&p)(c,o,d,this.isSelectedContainerEvent);this.fakeRemoveView(E)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!c||!o||!m)&&(this.selectBranches.stopExpect(),s())}},isEOV:()=>this.gameState===4},n=ls(this.selectBranches.onControlEvent,r);this.container.createView({eventCallback:n}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,eo.default)(i,this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(cs(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Er(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let l=this.gameState;this.gameState=3,l===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:l}=this.getContainerEventState(),d=this.selectBranches.state.isExpect,m=this.interactiveTimeOpenUri&&l;if(m&&!d){let f=this.container.getElement();f&&(f.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!m&&this.removeView()}let c=Er(s,this.container.container),o=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:o,currentTime:s,isInteractiveTime:c};this.container.onProgress(s*1e3,c),this.globalEventEmitter.emit(x.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=r,this.branches=n,this.selectBranches=i,this.subscription=new Op,this.player=e,this.interactiveEvents=s,this.getContainerEventState=a,this.isPermanentText=l&&he(r.container.controls),this.interactiveTimeOpenUri=d,this.disabledControls$=m,this.onRemove=f,this.globalEventEmitter=o,this.gameState=0,this.globalEvents=c,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,r=!1){e?(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.visibility,visibility:e,isFirst:r}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e,isFirst:r})):(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}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=>{e?this.container.disable?.():this.container.enable?.()}))}selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:r}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!r&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:r}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||r:ee(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var to=(t=[])=>t.reduce((e,r,n)=>{let i=(r?.controls??[]).filter(s=>!ct(s));if(bt(i)){let s=[r.startTime??0,r.endTime??1/0],c={id:r.id,isRemoved:!1};if(!n)e.push({subjects:[c],range:s});else{let o=[],a=-1/0,l=1/0,d=[],m=[];for(let f=0;f<e.length;f++){let y=e[f];if(m.push(...y.subjects),y.range[0]<l&&(l=y.range[0]),y.range[1]>a&&(a=y.range[1]),s[0]>=y.range[0]&&s[1]<=y.range[1])return e[f].subjects.push(c),e;s[0]<y.range[0]&&s[1]>y.range[0]&&(o.push(f),d=d.concat(y.subjects)),s[0]>=y.range[0]&&s[0]<=y.range[1]&&(o.push(f),d=d.concat(y.subjects),s[0]=y.range[0]),s[1]>=y.range[0]&&s[1]<=y.range[1]&&(o.push(f),d=d.concat(y.subjects),s[1]=y.range[1])}if(m.push(c),s[0]<=l&&s[1]>=a)return[{subjects:m,range:s}];o.length&&o.reverse().forEach(f=>{e.splice(f,1)}),e.push({subjects:d.concat([c]),range:s})}}return e},[]).sort((e,r)=>e.range[0]-r.range[0]);var $o=K(Et(),1),Mr=K(gt(),1),_o=K(jo(),1);function Lo(){let t={};function e(){for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&delete t[o]}function r(o){let a={};for(let l in t)+l<=o&&(a[l]=t[l]);return a}function n(o){let a={};for(let l in t)+l>=o&&(a[l]=t[l]);return a}function i({timestamp:o,priority:a,initiator:l}){if(mr(o)){let d=t[o]??null;if(d&&a&&Re(a,!0)){let m={},f=d[a];return f&&(m={...m,...f}),m=J(m)?null:m,m&&Re(l,!0)?m[l]??null:m}return d}return null}function s({timestamp:o,priority:a,initiator:l}){if(mr(o))if(t[o]){if(a&&Re(a,!0))if(t[o][a]){if(l&&Re(l,!0))if(t[o][a][l]){if(delete t[o][a][l],!J(t[o][a]))return!0}else return!1;if(delete t[o][a],!J(t[o]))return!0}else return!1;return delete t[o]}else return!1;return!1}function c({timestamp:o,priority:a,initiator:l,...d}){t[o]?.[a]?.[l]?t[o][a][l].push({...d}):t[o]?.[a]?t[o][a]={...t[o][a],[l]:[{...d}]}:t[o]?t[o]={...t[o],[a]:{[l]:[{...d}]}}:t[o]={[a]:{[l]:[{...d}]}}}return{map:t,remove:s,add:c,removeAll:e,get:i,getLte:r,getGte:n}}var yu=[w.expect,w.setNextBranch],bu=1/0;function Fo(t,e){let r=t,n,i=Cu(e),s=Lo(),c,o=()=>{y(),h()},a=p=>{s.add.call(void 0,p),E()},l=(p=[])=>{for(let v of p)if(v.action(),(0,$o.default)(yu,v.actionType))break},d=(p=1/0)=>{let v=xt(s.get({timestamp:p,priority:"control"})??{}),b=xt(s.get({timestamp:p,priority:"container"})??{}),g=xt(s.get({timestamp:p,priority:"chapter"})??{});return[...v,...b,...g]},m=p=>{i.isReady(p)&&l(d(p))},f=()=>{l([...xt(s.get({timestamp:1/0,priority:"chapter"})??{})])},y=()=>{n&&(c?.unsubscribe(),n=void 0)},R=p=>{},E=()=>{n||(n=()=>setTimeout(()=>{m(1/0)}),c=r.events.ended$.subscribe(n))},C=p=>{y(),r=p},I=p=>{p.priority==="container"&&i.resetCalled(p.timestamp),s.remove(p)},h=()=>{i.release(),s.removeAll()};return{setPlayer:C,add:a,remove:I,exec:m,execEndOfVideo:f,listen:E,unlisten:y,release:o,containersEventsCallState:i,getPreparedToExecActions:d}}function Cu(t){let e=new Map;return{setCalled:({timestamp:o,id:a})=>{let l=e.get(o);l&&l[a]!==void 0&&(l[a]=!0)},setData:(o=[])=>{for(let a of o){let l=a.endTime??bu,d=e.get(l);e.set(l,{...d,[a.id]:!1})}},resetCalled:o=>{let a=e.get(o);if(a)for(let l in a)a[l]=!1},isReady:o=>{let a=e.get(o);if(!a)return!0;let l=(0,Mr.default)(a);return t?l.some(m=>m):!l.some(m=>!m)},release:()=>e.clear()}}function xt(t){return(0,_o.default)((0,Mr.default)(t)).sort(e=>e.actionType===w.expect?-1:1)}var qo={videoContentHeight:0,videoContentWidth:0},Bo=t=>{let{height:e,width:r}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&r))return qo;let{clientHeight:n,clientWidth:i}=t.experimental.element$.getValue()||{};if(!(n&&i))return qo;let s=e/r,c=n/i,o,a;return c>s?(a=i,o=i*s):c<s?(a=n/s,o=n):(a=i,o=n),{videoContentWidth:a,videoContentHeight:o}};var gu=250;function Do(t){let e,r=new ResizeObserver(o=>{s(o),e=s.bind(null,o)});function n(o){let{parentElement:a,player:l}=t();if(a&&l){let{videoContentWidth:d,videoContentHeight:m}=Bo(l);a.style.setProperty("--interactive-content-width",`${d}px`),a.style.setProperty("--interactive-content-height",`${m}px`),a.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function i(){let{parentElement:o}=t();o.removeAttribute("style")}let s=we(o=>{let{fns:a=[]}=t();n(o);for(let l of a)l()},gu);function c(){e=void 0,r.disconnect(),i()}return{resizeObserver:r,calc:()=>{e?.()},release:c}}var Eu=t=>Math.floor(Math.random()*t),Uo=t=>{let e=t.length,r=1/0,n=null;for(;e--;){let i=t[e],s=i.weight??1;s<r&&(r=s,n=i)}return n},Go=t=>{let e=t.length,r=-1/0,n=null;for(;e--;){let i=t[e],s=i.weight??0;s>r&&(r=s,n=i)}return n};var zo=t=>{let e=t.length,r=Eu(e);return t[r]},Ho=1,Wo=t=>{let e=0;for(let n=0;n<t.length;++n)e+=t[n].weight??Ho;let r=Math.random()*e;e=0;for(let n=0;n<t.length-1;++n)if(e+=t[n].weight??Ho,e>=r)return t[n];return t[t.length-1]};var Ko={shouldOpenNow:!0,isDetachContainer:!0},Qo="after-expect";var Nr=(t,e=!1)=>({...t,args:e?{...t.args,...Ko}:{...Ko,...t.args}}),Zo=({globalEventEmitter:t,globalEvents:e,player:r,interactiveEvents:n})=>{let i={isExpect:!1},s=()=>{i.isExpect&&(i.isExpect=!1)},c=({action:h,controlType:p,controlId:v,containerId:b,branches:g=[],onEvent:T,isEOV:A=()=>!1,isDisabled:k=()=>!1})=>{let S=Nr(h,A()),V={timestamp:1/0,priority:"control",initiator:v,actionType:S.type},q=k(),B=t.emit.bind(t,x.interactives,{subjectId:v,subjectType:p,subjectName:"control",type:q?O.actionChoiceCanceled:O.actionChoice,actionType:h.type,payload:{invokeImmediately:S.args.shouldOpenNow,containerId:b,...S.args}}),D=()=>{e.interactiveActionChoice$.next({subjectId:v,subjectType:p,subjectName:"control",type:q?"action-choice-canceled":"action-choice",actionType:h.type,payload:{invokeImmediately:S.args.shouldOpenNow,containerId:b,...S.args}})};if(q){B(),D();return}switch(S.type.trim().toLowerCase()){case w.setNextBranch.trim().toLowerCase():{let W=g.find(te=>te.id===S.args.branchId);if(!W)return;T(S.args.isDetachContainer,y.bind(null,{subjectId:v,subjectName:"control"})),B(),D(),S.args.shouldOpenNow?E({subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{chapterId:W.chapterId,autoSelect:!1}}):n.add({...V,action:E.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{chapterId:W.chapterId,autoSelect:!1}})});return}case w.continuePlayback.trim().toLowerCase():{T(S.args.isDetachContainer,y.bind(null,{subjectId:v,subjectName:"control"})),B(),D(),S.args.shouldOpenNow?R({subjectId:v,subjectName:"control",subjectType:p,action:h}):n.add({...V,action:R.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:h})});return}case w.openURI.trim().toLowerCase():{T(S.args.isDetachContainer,y.bind(null,{subjectId:v,subjectName:"control"})),B(),D(),S.args.shouldOpenNow?I({subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{URI:h.args.uri}}):n.add({...V,action:I.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{URI:h.args.uri}})});return}default:{let W="Unexpected control event",te=new M(1,1,{message:W});d(te,W);return}}},o=({action:h,container:{id:p,endTime:v},branches:b=[],isEOV:g=!1,autoSelected:T=!1})=>{let A=Nr(h,g),k={timestamp:!A.args.shouldOpenNow||g?1/0:v??1/0,priority:"container",initiator:p,actionType:A.type},S=t.emit.bind(t,x.interactives,{subjectId:p,subjectName:"container",type:O.actionChoice,actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}}),V=()=>{e.interactiveActionChoice$.next({subjectId:p,subjectName:"container",type:"action-choice",actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}})};switch(A.type.trim().toLowerCase()){case w.setNextBranch.trim().toLowerCase():{let q=b.find(B=>B.id===A.args.branchId);if(!q)return;S(),V(),n.add({...k,action:E.bind(null,{subjectId:p,subjectName:"container",action:A,payload:{chapterId:q.chapterId,autoSelect:T}})});return}case w.setMaxWeightBranch.trim().toLowerCase():return;case w.setMinWeightBranch.trim().toLowerCase():return;case w.setRandomBranch.trim().toLowerCase():return;case w.setWeightlessRandomBranch.trim().toLowerCase():return;case w.continuePlayback.trim().toLowerCase():{S(),V(),n.add({...k,action:R.bind(null,{subjectId:p,subjectName:"container",action:A})});return}case w.openURI.trim().toLowerCase():{S(),V(),n.add({...k,action:I.bind(null,{subjectId:p,subjectName:"container",action:A,payload:{URI:h.args.uri}})});return}default:{let q="Unexpected container event",B=new M(1,1,{message:q});d(B,q);return}}};function a({container:h,branches:p,isEOV:v=!1}){let b=Ir(h.events);if(b){let g=Nr(b.action,v);t.emit(x.interactives,{subjectId:h.id,subjectName:"container",type:O.actionChoice,actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"container",type:"action-choice",actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),n.add({timestamp:v?1/0:h.endTime??1/0,priority:"container",initiator:h.id,actionType:w.expect,action:f.bind(null,{subjectId:h.id,subjectName:"container"})}),i.isExpect=!0}else for(let g of h.events??[])o({action:g.action,container:h,branches:p,isEOV:v})}let l=({chapterId:h,action:p,branches:v=[]})=>{let b=t.emit.bind(t,x.interactives,{subjectId:h,subjectName:"chapter",type:O.actionChoice,actionType:p.type,payload:p.args}),g=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"chapter",type:"action-choice",actionType:p.type,payload:p.args})};switch(p.type.trim().toLowerCase()){case w.setNextBranch.trim().toLowerCase():{let T=v.find(A=>A.id===p.args.branchId);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setWeightlessRandomBranch.trim().toLowerCase():{let T=zo(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setRandomBranch.trim().toLowerCase():{let T=Wo(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setMaxWeightBranch.trim().toLowerCase():{let T=Go(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setMinWeightBranch.trim().toLowerCase():{let T=Uo(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.continuePlayback.trim().toLowerCase():return b(),g(),R.bind(null,{subjectId:h,subjectName:"chapter",action:p});case w.openURI.trim().toLowerCase():return b(),g(),I.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:{let T="Unexpected chapter event",A=new M(1,1,{message:T});d(A,T);return}}};function d(h,p){console.error(p),e.error$.next(h),t.emit(x.errors,h)}function m(h){let p=Ir(h.events);if(p){if(z(h))return;t.emit(x.interactives,{subjectId:h.id,subjectName:"chapter",type:O.actionChoice,actionType:p.action.type,payload:p.action.args}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"chapter",type:"action-choice",actionType:p.action.type,payload:p.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:w.expect,action:f.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events?.forEach(v=>{let b=l({chapterId:h.id,action:v.action,branches:h.branches});b&&n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:v.action.type,action:b})})}let f=({subjectId:h,subjectName:p})=>{r.pause(),t.emit(x.interactives,{subjectId:h,subjectName:p,type:O.actionExecution,actionType:w.expect}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,type:"action-execution",actionType:w.expect})},y=({subjectId:h,subjectName:p})=>{r.info.isEnded$.getValue()?n.execEndOfVideo():r.play(),t.emit(x.interactives,{subjectId:h,subjectName:p,type:O.actionExecution,actionType:Qo}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,type:"action-execution",actionType:Qo})},R=({subjectId:h,subjectName:p,subjectType:v,action:b})=>{t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type})},E=({subjectId:h,subjectName:p,subjectType:v,action:b,payload:g})=>{g.behaviour="change-chapter",t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type,payload:g}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type,payload:g})},C=({subjectId:h,subjectName:p,subjectType:v,action:b,payload:g})=>{g.behaviour="change-manifest",t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type,payload:g}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type,payload:g})},I=({subjectId:h,subjectName:p,subjectType:v,action:b,payload:g})=>{if(!g.URI)return;let T=window.open(g.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:l,onExpectEvent:f,expectEventHandler:y,setManifestChapterEvents:m,setManifestContainerEvents:a,stopExpect:s,state:i}};var $r=K(dr(),1);import{Subscription as wu,Subject as Lr,ValueSubject as $e}from"@vkontakte/videoplayer-shared";var jr=(t,e)=>{let r={};return t.map(n=>{if(!r[n]){let i=e.chapters.find(c=>c.id===n);if(!i)return null;let s=e.media.videos.find(c=>i.videoId===c.id);if(!s)return null;r[n]=Jo(s)}return r[n]}).filter(Boolean)},Tu=t=>{for(let e of t.variants)if(xu(e)&&e.payload)return e.payload.id},xu=t=>!!(t.type==="custom"&&t.payload&&t.payload.type==="vk"),Jo=t=>{let e=Tu(t);if(!e)return null;let r=e.split("_").pop();return r?parseInt(r,10):null},Su=(t,e)=>{for(let r of t.media.videos)if(e===Jo(r)){for(let n of t.chapters)if(n.videoId===r.id)return n.id;return}},ea=(t,e)=>t.reduce((r,n)=>{let i=Su(e,n);return i?[...r,i]:r},[]);var _e=class{constructor({globalEventEmitter:e,videoId:r,interactiveController:n,historyApi:i,settings:s}){this.state={history$:new $e([]),hasPrevChapter$:new $e(!1),prevChapter$:new $e(null),isInitialChapter$:new $e(!1),isGoBackLimited$:new $e(!1)};this.#r=null;this.#o=!1;this.#e=null;this.#p=null;this.events={inited$:new Lr,destroyed$:new Lr,error$:new Lr};this.#n=null;this.#i=null;this.#t=null;this.#a=new wu;this.#c=!1;this.#l=0;this.#n=r,this.#t=e,this.#i=n,this.#r=i,this.#s=s,this.state.history$&&this.#a&&this.#a?.add(this.state.history$.subscribe(c=>{this.state.prevChapter$.next((0,$r.default)(c,-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#l===this.#s.maxLength-1)}))}#r;#s;#o;#e;#p;#n;#i;#t;#a;#c;#l;async setManifest(e){if(!this.#i||!this.#t)return;this.#e=e,await this.getProjectHistory();let r=this.getInitialChapterId();await this.#i.setChapter({chapterId:r,pushToHistory:!1}),this.#o||(this.#o=!0,this.events.inited$.next({initChapterId:r}))}get inited(){return this.#o}async updateHistory(e,r=!0){if(!this.#e)return;this.#c?(this.#c=!1,this.#l++):this.#l=0;let n=this.#e,i=e.length-this.#s.maxLength,s=i>0?e.slice(i):e,c=jr(s,n);if(this.#p=c,this.state.history$.next(s),!(!r||!this.#r||!this.#n))try{await this.#r.save(this.#n,c)}catch{let a=new M(1,5,"Unable to save interactive history");this.events.error$.next(a),this.#t?.emit(x.errors,a)}}async goBack(){if(!this.state||!this.#i){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#t?.emit(x.errors,n)}this.#c=!0;let e=this.state.history$.getValue().slice(0,-1),r=e.pop();this.state.history$.next(e),await this.#i.setChapter({chapterId:r,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#n)return;let e=this.#e,r=[this.getInitialVideoId()];if(this.#r)try{let i=await this.#r.get(this.#n);i.length&&(r=i)}catch{let s=new M(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#t?.emit(x.errors,s)}let n=ea(r,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,$r.default)(e,-1)||this.#s.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return jr([e],this.#e).pop()}return null}destroy(){this.#n=null,this.#r=null,this.#i=null,this.#a?.unsubscribe(),this.#a=null,this.#o=!1,this.#t?.emit(x.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var St=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let r=e.data,n=r.length;for(let i=3;i<n;i+=40)if(r[i]!==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(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,r=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let i;r&&(i=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,r&&i&&this.restore(i),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),r=new Image;return r.crossOrigin="anonymous",r.src=e,await r.decode(),r}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var wt=class{constructor({parentElement:e,endOffsetMs:r=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let r=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(r);if(this.isContainerTime(r))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)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 ca=Object.create;var qr=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ua=Object.getPrototypeOf,ha=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var da=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pa(e))!ha.call(t,i)&&i!==r&&qr(t,i,{get:()=>e[i],enumerable:!(n=la(e,i))||n.enumerable});return t};var K=(t,e,r)=>(r=t!=null?ca(ua(t)):{},da(e||!t||!t.__esModule?qr(r,"default",{value:t,enumerable:!0}):r,t));var G=u(($t,Qr)=>{"use strict";var fe=function(t){return t&&t.Math===Math&&t};Qr.exports=fe(typeof globalThis=="object"&&globalThis)||fe(typeof window=="object"&&window)||fe(typeof self=="object"&&self)||fe(typeof global=="object"&&global)||fe(typeof $t=="object"&&$t)||function(){return this}()||Function("return this")()});var _=u((kh,Xr)=>{"use strict";Xr.exports=function(t){try{return!!t()}catch{return!0}}});var ve=u((Vh,Yr)=>{"use strict";var ma=_();Yr.exports=!ma(function(){var t=function(){}.bind();return typeof t!="function"||t.hasOwnProperty("prototype")})});var rn=u((Mh,tn)=>{"use strict";var fa=ve(),en=Function.prototype,Zr=en.apply,Jr=en.call;tn.exports=typeof Reflect=="object"&&Reflect.apply||(fa?Jr.bind(Zr):function(){return Jr.apply(Zr,arguments)})});var H=u((Nh,on)=>{"use strict";var nn=ve(),sn=Function.prototype,_t=sn.call,va=nn&&sn.bind.bind(_t,_t);on.exports=nn?va:function(t){return function(){return _t.apply(t,arguments)}}});var ye=u((Lh,cn)=>{"use strict";var an=H(),ya=an({}.toString),ba=an("".slice);cn.exports=function(t){return ba(ya(t),8,-1)}});var Ft=u((jh,ln)=>{"use strict";var Ca=ye(),ga=H();ln.exports=function(t){if(Ca(t)==="Function")return ga(t)}});var F=u(($h,pn)=>{"use strict";var qt=typeof document=="object"&&document.all;pn.exports=typeof qt>"u"&&qt!==void 0?function(t){return typeof t=="function"||t===qt}:function(t){return typeof t=="function"}});var Y=u((_h,un)=>{"use strict";var Ea=_();un.exports=!Ea(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Ye=u((Fh,hn)=>{"use strict";var Ia=ve(),Xe=Function.prototype.call;hn.exports=Ia?Xe.bind(Xe):function(){return Xe.apply(Xe,arguments)}});var Bt=u(fn=>{"use strict";var dn={}.propertyIsEnumerable,mn=Object.getOwnPropertyDescriptor,Ta=mn&&!dn.call({1:2},1);fn.f=Ta?function(e){var r=mn(this,e);return!!r&&r.enumerable}:dn});var Dt=u((Bh,vn)=>{"use strict";vn.exports=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}});var bn=u((Dh,yn)=>{"use strict";var xa=H(),Sa=_(),wa=ye(),Ht=Object,Aa=xa("".split);yn.exports=Sa(function(){return!Ht("z").propertyIsEnumerable(0)})?function(t){return wa(t)==="String"?Aa(t,""):Ht(t)}:Ht});var Ut=u((Hh,Cn)=>{"use strict";Cn.exports=function(t){return t==null}});var Gt=u((Uh,gn)=>{"use strict";var Ra=Ut(),Oa=TypeError;gn.exports=function(t){if(Ra(t))throw new Oa("Can't call method on "+t);return t}});var be=u((Gh,En)=>{"use strict";var Pa=bn(),ka=Gt();En.exports=function(t){return Pa(ka(t))}});var oe=u((zh,In)=>{"use strict";var Va=F();In.exports=function(t){return typeof t=="object"?t!==null:Va(t)}});var Ze=u((Wh,Tn)=>{"use strict";Tn.exports={}});var Je=u((Kh,Sn)=>{"use strict";var zt=Ze(),Wt=G(),Ma=F(),xn=function(t){return Ma(t)?t:void 0};Sn.exports=function(t,e){return arguments.length<2?xn(zt[t])||xn(Wt[t]):zt[t]&&zt[t][e]||Wt[t]&&Wt[t][e]}});var An=u((Qh,wn)=>{"use strict";var Na=H();wn.exports=Na({}.isPrototypeOf)});var kn=u((Xh,Pn)=>{"use strict";var La=G(),Rn=La.navigator,On=Rn&&Rn.userAgent;Pn.exports=On?String(On):""});var _n=u((Yh,$n)=>{"use strict";var jn=G(),Kt=kn(),Vn=jn.process,Mn=jn.Deno,Nn=Vn&&Vn.versions||Mn&&Mn.version,Ln=Nn&&Nn.v8,U,et;Ln&&(U=Ln.split("."),et=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!et&&Kt&&(U=Kt.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=Kt.match(/Chrome\/(\d+)/),U&&(et=+U[1])));$n.exports=et});var Qt=u((Zh,qn)=>{"use strict";var Fn=_n(),ja=_(),$a=G(),_a=$a.String;qn.exports=!!Object.getOwnPropertySymbols&&!ja(function(){var t=Symbol("symbol detection");return!_a(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&Fn&&Fn<41})});var Xt=u((Jh,Bn)=>{"use strict";var Fa=Qt();Bn.exports=Fa&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Yt=u((ed,Dn)=>{"use strict";var qa=Je(),Ba=F(),Da=An(),Ha=Xt(),Ua=Object;Dn.exports=Ha?function(t){return typeof t=="symbol"}:function(t){var e=qa("Symbol");return Ba(e)&&Da(e.prototype,Ua(t))}});var Un=u((td,Hn)=>{"use strict";var Ga=String;Hn.exports=function(t){try{return Ga(t)}catch{return"Object"}}});var Zt=u((rd,Gn)=>{"use strict";var za=F(),Wa=Un(),Ka=TypeError;Gn.exports=function(t){if(za(t))return t;throw new Ka(Wa(t)+" is not a function")}});var Wn=u((nd,zn)=>{"use strict";var Qa=Zt(),Xa=Ut();zn.exports=function(t,e){var r=t[e];return Xa(r)?void 0:Qa(r)}});var Qn=u((id,Kn)=>{"use strict";var Jt=Ye(),er=F(),tr=oe(),Ya=TypeError;Kn.exports=function(t,e){var r,n;if(e==="string"&&er(r=t.toString)&&!tr(n=Jt(r,t))||er(r=t.valueOf)&&!tr(n=Jt(r,t))||e!=="string"&&er(r=t.toString)&&!tr(n=Jt(r,t)))return n;throw new Ya("Can't convert object to primitive value")}});var Yn=u((sd,Xn)=>{"use strict";Xn.exports=!0});var ei=u((od,Jn)=>{"use strict";var Zn=G(),Za=Object.defineProperty;Jn.exports=function(t,e){try{Za(Zn,t,{value:e,configurable:!0,writable:!0})}catch{Zn[t]=e}return e}});var tt=u((ad,ni)=>{"use strict";var Ja=Yn(),ec=G(),tc=ei(),ti="__core-js_shared__",ri=ni.exports=ec[ti]||tc(ti,{});(ri.versions||(ri.versions=[])).push({version:"3.38.0",mode:Ja?"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 rr=u((cd,si)=>{"use strict";var ii=tt();si.exports=function(t,e){return ii[t]||(ii[t]=e||{})}});var Ce=u((ld,oi)=>{"use strict";var rc=Gt(),nc=Object;oi.exports=function(t){return nc(rc(t))}});var ae=u((pd,ai)=>{"use strict";var ic=H(),sc=Ce(),oc=ic({}.hasOwnProperty);ai.exports=Object.hasOwn||function(e,r){return oc(sc(e),r)}});var nr=u((ud,ci)=>{"use strict";var ac=H(),cc=0,lc=Math.random(),pc=ac(1 .toString);ci.exports=function(t){return"Symbol("+(t===void 0?"":t)+")_"+pc(++cc+lc,36)}});var ge=u((hd,pi)=>{"use strict";var uc=G(),hc=rr(),li=ae(),dc=nr(),mc=Qt(),fc=Xt(),ce=uc.Symbol,ir=hc("wks"),vc=fc?ce.for||ce:ce&&ce.withoutSetter||dc;pi.exports=function(t){return li(ir,t)||(ir[t]=mc&&li(ce,t)?ce[t]:vc("Symbol."+t)),ir[t]}});var mi=u((dd,di)=>{"use strict";var yc=Ye(),ui=oe(),hi=Yt(),bc=Wn(),Cc=Qn(),gc=ge(),Ec=TypeError,Ic=gc("toPrimitive");di.exports=function(t,e){if(!ui(t)||hi(t))return t;var r=bc(t,Ic),n;if(r){if(e===void 0&&(e="default"),n=yc(r,t,e),!ui(n)||hi(n))return n;throw new Ec("Can't convert object to primitive value")}return e===void 0&&(e="number"),Cc(t,e)}});var sr=u((md,fi)=>{"use strict";var Tc=mi(),xc=Yt();fi.exports=function(t){var e=Tc(t,"string");return xc(e)?e:e+""}});var bi=u((fd,yi)=>{"use strict";var Sc=G(),vi=oe(),or=Sc.document,wc=vi(or)&&vi(or.createElement);yi.exports=function(t){return wc?or.createElement(t):{}}});var ar=u((vd,Ci)=>{"use strict";var Ac=Y(),Rc=_(),Oc=bi();Ci.exports=!Ac&&!Rc(function(){return Object.defineProperty(Oc("div"),"a",{get:function(){return 7}}).a!==7})});var Ii=u(Ei=>{"use strict";var Pc=Y(),kc=Ye(),Vc=Bt(),Mc=Dt(),Nc=be(),Lc=sr(),jc=ae(),$c=ar(),gi=Object.getOwnPropertyDescriptor;Ei.f=Pc?gi:function(e,r){if(e=Nc(e),r=Lc(r),$c)try{return gi(e,r)}catch{}if(jc(e,r))return Mc(!kc(Vc.f,e,r),e[r])}});var xi=u((bd,Ti)=>{"use strict";var _c=_(),Fc=F(),qc=/#|\.prototype\./,Ee=function(t,e){var r=Dc[Bc(t)];return r===Uc?!0:r===Hc?!1:Fc(e)?_c(e):!!e},Bc=Ee.normalize=function(t){return String(t).replace(qc,".").toLowerCase()},Dc=Ee.data={},Hc=Ee.NATIVE="N",Uc=Ee.POLYFILL="P";Ti.exports=Ee});var cr=u((Cd,wi)=>{"use strict";var Si=Ft(),Gc=Zt(),zc=ve(),Wc=Si(Si.bind);wi.exports=function(t,e){return Gc(t),e===void 0?t:zc?Wc(t,e):function(){return t.apply(e,arguments)}}});var Ri=u((gd,Ai)=>{"use strict";var Kc=Y(),Qc=_();Ai.exports=Kc&&Qc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Pi=u((Ed,Oi)=>{"use strict";var Xc=oe(),Yc=String,Zc=TypeError;Oi.exports=function(t){if(Xc(t))return t;throw new Zc(Yc(t)+" is not an object")}});var Mi=u(Vi=>{"use strict";var Jc=Y(),el=ar(),tl=Ri(),rt=Pi(),ki=sr(),rl=TypeError,lr=Object.defineProperty,nl=Object.getOwnPropertyDescriptor,pr="enumerable",ur="configurable",hr="writable";Vi.f=Jc?tl?function(e,r,n){if(rt(e),r=ki(r),rt(n),typeof e=="function"&&r==="prototype"&&"value"in n&&hr in n&&!n[hr]){var i=nl(e,r);i&&i[hr]&&(e[r]=n.value,n={configurable:ur in n?n[ur]:i[ur],enumerable:pr in n?n[pr]:i[pr],writable:!1})}return lr(e,r,n)}:lr:function(e,r,n){if(rt(e),r=ki(r),rt(n),el)try{return lr(e,r,n)}catch{}if("get"in n||"set"in n)throw new rl("Accessors not supported");return"value"in n&&(e[r]=n.value),e}});var Li=u((Td,Ni)=>{"use strict";var il=Y(),sl=Mi(),ol=Dt();Ni.exports=il?function(t,e,r){return sl.f(t,e,ol(1,r))}:function(t,e,r){return t[e]=r,t}});var Te=u((xd,$i)=>{"use strict";var Ie=G(),al=rn(),cl=Ft(),ll=F(),pl=Ii().f,ul=xi(),le=Ze(),hl=cr(),pe=Li(),ji=ae();tt();var dl=function(t){var e=function(r,n,i){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,n)}return new t(r,n,i)}return al(t,this,arguments)};return e.prototype=t.prototype,e};$i.exports=function(t,e){var r=t.target,n=t.global,i=t.stat,s=t.proto,c=n?Ie:i?Ie[r]:Ie[r]&&Ie[r].prototype,o=n?le:le[r]||pe(le,r,{})[r],a=o.prototype,l,d,m,f,y,R,E,C,I;for(f in e)l=ul(n?f:r+(i?".":"#")+f,t.forced),d=!l&&c&&ji(c,f),R=o[f],d&&(t.dontCallGetSet?(I=pl(c,f),E=I&&I.value):E=c[f]),y=d&&E?E:e[f],!(!l&&!s&&typeof R==typeof y)&&(t.bind&&d?C=hl(y,Ie):t.wrap&&d?C=dl(y):s&&ll(y)?C=cl(y):C=y,(t.sham||y&&y.sham||R&&R.sham)&&pe(C,"sham",!0),pe(o,f,C),s&&(m=r+"Prototype",ji(le,m)||pe(le,m,{}),pe(le[m],f,y),t.real&&a&&(l||!a[f])&&pe(a,f,y)))}});var Fi=u((Sd,_i)=>{"use strict";var ml=Math.ceil,fl=Math.floor;_i.exports=Math.trunc||function(e){var r=+e;return(r>0?fl:ml)(r)}});var xe=u((wd,qi)=>{"use strict";var vl=Fi();qi.exports=function(t){var e=+t;return e!==e||e===0?0:vl(e)}});var Di=u((Ad,Bi)=>{"use strict";var yl=xe(),bl=Math.min;Bi.exports=function(t){var e=yl(t);return e>0?bl(e,9007199254740991):0}});var Se=u((Rd,Hi)=>{"use strict";var Cl=Di();Hi.exports=function(t){return Cl(t.length)}});var nt=u((Od,Ui)=>{"use strict";Ui.exports=function(){}});var Gi=u(()=>{"use strict";var gl=Te(),El=Ce(),Il=Se(),Tl=xe(),xl=nt();gl({target:"Array",proto:!0},{at:function(e){var r=El(this),n=Il(r),i=Tl(e),s=i>=0?i:n+i;return s<0||s>=n?void 0:r[s]}});xl("at")});var it=u((Vd,zi)=>{"use strict";var Sl=Je();zi.exports=Sl});var Ki=u((Md,Wi)=>{"use strict";Gi();var wl=it();Wi.exports=wl("Array","at")});var Xi=u((Nd,Qi)=>{"use strict";var Al=Ki();Qi.exports=Al});var dr=u((Ld,Yi)=>{"use strict";var Rl=Xi();Yi.exports=Rl});var ds=u((zm,hs)=>{"use strict";var _l=rr(),Fl=nr(),us=_l("keys");hs.exports=function(t){return us[t]||(us[t]=Fl(t))}});var fs=u((Wm,ms)=>{"use strict";var ql=_();ms.exports=!ql(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})});var bs=u((Km,ys)=>{"use strict";var Bl=ae(),Dl=F(),Hl=Ce(),Ul=ds(),Gl=fs(),vs=Ul("IE_PROTO"),Tr=Object,zl=Tr.prototype;ys.exports=Gl?Tr.getPrototypeOf:function(t){var e=Hl(t);if(Bl(e,vs))return e[vs];var r=e.constructor;return Dl(r)&&e instanceof r?r.prototype:e instanceof Tr?zl:null}});var gs=u((Qm,Cs)=>{"use strict";var Wl=xe(),Kl=Math.max,Ql=Math.min;Cs.exports=function(t,e){var r=Wl(t);return r<0?Kl(r+e,0):Ql(r,e)}});var xr=u((Xm,Is)=>{"use strict";var Xl=be(),Yl=gs(),Zl=Se(),Es=function(t){return function(e,r,n){var i=Xl(e),s=Zl(i);if(s===0)return!t&&-1;var c=Yl(n,s),o;if(t&&r!==r){for(;s>c;)if(o=i[c++],o!==o)return!0}else for(;s>c;c++)if((t||c in i)&&i[c]===r)return t||c||0;return!t&&-1}};Is.exports={includes:Es(!0),indexOf:Es(!1)}});var xs=u((Ym,Ts)=>{"use strict";Ts.exports={}});var As=u((Zm,ws)=>{"use strict";var Jl=H(),Sr=ae(),ep=be(),tp=xr().indexOf,rp=xs(),Ss=Jl([].push);ws.exports=function(t,e){var r=ep(t),n=0,i=[],s;for(s in r)!Sr(rp,s)&&Sr(r,s)&&Ss(i,s);for(;e.length>n;)Sr(r,s=e[n++])&&(~tp(i,s)||Ss(i,s));return i}});var Os=u((Jm,Rs)=>{"use strict";Rs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var ks=u((ef,Ps)=>{"use strict";var np=As(),ip=Os();Ps.exports=Object.keys||function(e){return np(e,ip)}});var $s=u((tf,js)=>{"use strict";var Ms=Y(),sp=_(),Ns=H(),op=bs(),ap=ks(),cp=be(),lp=Bt().f,Ls=Ns(lp),pp=Ns([].push),up=Ms&&sp(function(){var t=Object.create(null);return t[2]=2,!Ls(t,2)}),Vs=function(t){return function(e){for(var r=cp(e),n=ap(r),i=up&&op(r)===null,s=n.length,c=0,o=[],a;s>c;)a=n[c++],(!Ms||(i?a in r:Ls(r,a)))&&pp(o,t?[a,r[a]]:r[a]);return o}};js.exports={entries:Vs(!0),values:Vs(!1)}});var _s=u(()=>{"use strict";var hp=Te(),dp=$s().values;hp({target:"Object",stat:!0},{values:function(e){return dp(e)}})});var qs=u((sf,Fs)=>{"use strict";_s();var mp=Ze();Fs.exports=mp.Object.values});var Ds=u((of,Bs)=>{"use strict";var fp=qs();Bs.exports=fp});var gt=u((af,Hs)=>{"use strict";var vp=Ds();Hs.exports=vp});var zs=u(()=>{"use strict";var yp=Te(),bp=xr().includes,Cp=_(),gp=nt(),Ep=Cp(function(){return!Array(1).includes()});yp({target:"Array",proto:!0,forced:Ep},{includes:function(e){return bp(this,e,arguments.length>1?arguments[1]:void 0)}});gp("includes")});var Ks=u((hf,Ws)=>{"use strict";zs();var Ip=it();Ws.exports=Ip("Array","includes")});var Xs=u((df,Qs)=>{"use strict";var Tp=Ks();Qs.exports=Tp});var Et=u((mf,Ys)=>{"use strict";var xp=Xs();Ys.exports=xp});var Pr=u((Mf,ro)=>{"use strict";var Op=ye();ro.exports=Array.isArray||function(e){return Op(e)==="Array"}});var io=u((Nf,no)=>{"use strict";var Pp=TypeError,kp=9007199254740991;no.exports=function(t){if(t>kp)throw Pp("Maximum allowed index exceeded");return t}});var ao=u((Lf,oo)=>{"use strict";var Vp=Pr(),Mp=Se(),Np=io(),Lp=cr(),so=function(t,e,r,n,i,s,c,o){for(var a=i,l=0,d=c?Lp(c,o):!1,m,f;l<n;)l in r&&(m=d?d(r[l],l,e):r[l],s>0&&Vp(m)?(f=Mp(m),a=so(t,e,m,f,a,s-1)-1):(Np(a+1),t[a]=m),a++),l++;return a};oo.exports=so});var po=u((jf,lo)=>{"use strict";var jp=ge(),$p=jp("toStringTag"),co={};co[$p]="z";lo.exports=String(co)==="[object z]"});var ho=u(($f,uo)=>{"use strict";var _p=po(),Fp=F(),Tt=ye(),qp=ge(),Bp=qp("toStringTag"),Dp=Object,Hp=Tt(function(){return arguments}())==="Arguments",Up=function(t,e){try{return t[e]}catch{}};uo.exports=_p?Tt:function(t){var e,r,n;return t===void 0?"Undefined":t===null?"Null":typeof(r=Up(e=Dp(t),Bp))=="string"?r:Hp?Tt(e):(n=Tt(e))==="Object"&&Fp(e.callee)?"Arguments":n}});var fo=u((_f,mo)=>{"use strict";var Gp=H(),zp=F(),kr=tt(),Wp=Gp(Function.toString);zp(kr.inspectSource)||(kr.inspectSource=function(t){return Wp(t)});mo.exports=kr.inspectSource});var Eo=u((Ff,go)=>{"use strict";var Kp=H(),Qp=_(),vo=F(),Xp=ho(),Yp=Je(),Zp=fo(),yo=function(){},bo=Yp("Reflect","construct"),Vr=/^\s*(?:class|function)\b/,Jp=Kp(Vr.exec),eu=!Vr.test(yo),je=function(e){if(!vo(e))return!1;try{return bo(yo,[],e),!0}catch{return!1}},Co=function(e){if(!vo(e))return!1;switch(Xp(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return eu||!!Jp(Vr,Zp(e))}catch{return!0}};Co.sham=!0;go.exports=!bo||Qp(function(){var t;return je(je.call)||!je(Object)||!je(function(){t=!0})||t})?Co:je});var So=u((qf,xo)=>{"use strict";var Io=Pr(),tu=Eo(),ru=oe(),nu=ge(),iu=nu("species"),To=Array;xo.exports=function(t){var e;return Io(t)&&(e=t.constructor,tu(e)&&(e===To||Io(e.prototype))?e=void 0:ru(e)&&(e=e[iu],e===null&&(e=void 0))),e===void 0?To:e}});var Ao=u((Bf,wo)=>{"use strict";var su=So();wo.exports=function(t,e){return new(su(t))(e===0?0:e)}});var Ro=u(()=>{"use strict";var ou=Te(),au=ao(),cu=Ce(),lu=Se(),pu=xe(),uu=Ao();ou({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,r=cu(this),n=lu(r),i=uu(r,0);return i.length=au(i,r,r,n,0,e===void 0?1:pu(e)),i}})});var Oo=u(()=>{"use strict";var hu=nt();hu("flat")});var ko=u((zf,Po)=>{"use strict";Ro();Oo();var du=it();Po.exports=du("Array","flat")});var Mo=u((Wf,Vo)=>{"use strict";var mu=ko();Vo.exports=mu});var Lo=u((Kf,No)=>{"use strict";var fu=Mo();No.exports=fu});var Br="1.0.34-dev.f77434fe.0";var Ot=class{constructor(e){this.layout=e}},Be=class extends Ot{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,r){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${r.width})`,e.style.height=`calc(var(--interactive-content-height) * ${r.height})`,e.style.left=`calc(var(--interactive-content-width) * ${r.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${r.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};function Dr(t){return"features"in t}var ne=class{constructor(e,r){this.container=e,this.options=r,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&Dr(this.options)&&this.options.features[e]}addControlFactory(e,r){this.factories.set(e.trim().toLowerCase(),r),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((e,r)=>{let n=r.type.trim().toLowerCase(),i=this.factories.get(n);if(i){let s=i(r,this.options);if(s)return[...e,s]}return[...e]},[])||[]}};function Pt(t,e=1){let r="0",n="0",i="0";return t.length===4?(r="0x"+t[1]+t[1],n="0x"+t[2]+t[2],i="0x"+t[3]+t[3]):t.length===7&&(r="0x"+t[1]+t[2],n="0x"+t[3]+t[4],i="0x"+t[5]+t[6]),`rgba(${+r},${+n},${+i},${e})`}var Hr="interactive",N={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Ur=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(Ur||{}),Gr=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(Gr||{}),zr=(n=>(n.start="left",n.end="right",n.center="center",n))(zr||{}),De=({target:t,props:e})=>{t.style.alignItems=(e?.gravityVertical&&Ur[e.gravityVertical])??"center",t.style.justifyContent=(e?.gravityHorizontal&&Gr[e.gravityHorizontal])??"center",t.style.textAlign=(e?.alignment&&zr[e.alignment])??"center"},He=({target:t,props:e,fallback:r,dependsOn:n})=>{t.style.color=e?.text?.color??r.textColor,t.style.fontSize=`calc(${n.height} * ${e?.text?.size??r.textSize})`,t.textContent=e?.text?.value??r.textContent},Ue=({target:t,props:e,fallback:r})=>{t.style.backgroundColor=Pt(e?.background?.color??r.backgroundColor,e?.background?.alpha??r.backgroundAlpha)},Ge=({target:t,props:e,fallback:r,dependsOn:n})=>{t.style.border=`calc(${n.height} * ${e?.shape?.border?.width??r.borderWidth}) solid ${Pt(e?.shape?.border?.color??r.borderColor,e?.shape?.border?.alpha??r.borderAlpha)}`,t.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??r.roundCorners})`},ie=({target:t,layoutParams:e,fallback:r})=>{let n=e.angle??r.angle;n=n&&n*-1,t.style.transform=`rotate(${n}rad)`};var kt="int",X=(n=>(n.AREA=`${kt}_area`,n.TEXT=`${kt}_text`,n.BUTTON=`${kt}_bttn`,n))(X||{});function Wr(t){return"features"in t}var se="interactive-control",P={common:se,wrapper:`${se}-wrapper`,disabled:`${se}-disabled`,button:`${se}-button`,area:`${se}-area`,text:`${se}-text`};var Q=class{constructor(e,r){this.control=e;this.options=r;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let r=document.createElement("div");r.classList.add(P.wrapper),e.setControlLayout(r,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??N.innerSizesDependOn)==="self"?{height:r.style.height,width:r.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:r,dimensions:n}}createClickListener(e){return r=>{r.stopPropagation(),e()}}featureIsEnabled(e){return this.options&&Wr(this.options)&&this.options.features[e]}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(r=>{switch(r.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:r.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var ze=(t,e)=>{if(t.type.trim().toLowerCase()==="area")return new Vt(t,e)},Vt=class extends Q{constructor(e,r){super(e,r)}createView({parentElement:e,callbacks:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(P.common,P.area),n.setAttribute("data-testid",X.AREA),Ue({target:n,props:this.control.props,fallback:{...N,backgroundColor:"transparent"}}),Ge({target:n,props:this.control.props,fallback:{...N,borderAlpha:0},dependsOn:this.container.dimensions}),ie({target:n,layoutParams:this.control.layoutParams,fallback:N}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(P.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(P.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var We=t=>{let e=document.createElement("span");switch(t){case"Button":case"button":{let r=document.createElement("div"),n={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(r.style,n),r.append(e);let i={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,i),r}default:{let r={display:"inline-block",whiteSpace:"break-spaces",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",maxHeight:"100%",wordBreak:"break-all"};return Object.assign(e.style,r),e}}};var Ke=(t,e)=>{if(t.type.trim().toLowerCase()==="button")return new Mt(t,e)},Mt=class extends Q{constructor(e,r){super(e,r)}createView({parentElement:e,callbacks:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(P.common,P.button),n.setAttribute("data-testid",X.BUTTON),ie({target:n,layoutParams:this.control.layoutParams,fallback:N}),Ue({target:n,props:this.control.props,fallback:N}),Ge({target:n,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),De({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=We(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;He({target:s,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&this.controlElement.classList.add(P.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(P.disabled)}getElement(){return this.controlElement}onProgress(){}onResize(){}};var Kr=(t,e)=>{if(t.type.trim().toLowerCase()==="text")return new Nt(t,e)},Nt=class extends Q{constructor(e,r){super(e,r)}createView({parentElement:e,callbacks:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("div");n.classList.add(P.common,P.text),n.setAttribute("data-testid",X.TEXT),ie({target:n,layoutParams:this.control.layoutParams,fallback:N}),De({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=We(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;He({target:s,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}};var Lt="interactive-container",$={common:Lt,hidden:`${Lt}-hidden`,disabled:`${Lt}-disabled`};var Qe=(t,e,r)=>{if(t.type.trim().toLowerCase()==="choice")return new jt(t,e,r)},jt=class extends ne{constructor(r,n,i){super(r,i);this.containerElement=null;this.rootElement=n,this.layout=new Be(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Ke),this.addControlFactory("text",Kr),this.addControlFactory("area",ze)}createView({eventCallback:r}){let n=document.createElement("div");return n.classList.add($.common,$.disabled),requestAnimationFrame(()=>{n.classList.remove($.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(i=>{i.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout}}),i.setEvents(r)}),this.rootElement.append(n),this.isRemoved=!1,this.containerElement=n,n}hide(){let r=this.getElement();r&&r.classList.add($.hidden)}show(){let r=this.getElement();r&&r.classList.remove($.hidden)}enable(){let r=this.getElement();r&&(r.classList.remove($.disabled),this.controls.forEach(n=>n.enable()),this.isDisabled=!1)}disable(){let r=this.getElement();r&&(r.classList.add($.disabled),this.controls.forEach(n=>n.disable()),this.isDisabled=!0)}removeView(){let r=this.getElement();r&&(this.controls.forEach(n=>n.removeListeners()),r.remove(),this.isRemoved=!0,this.containerElement=null)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(r,n){n&&this.controls.forEach(i=>{i.onProgress(r)})}onResize(r){r&&this.controls.forEach(n=>{n.onResize()})}};var oa=K(dr(),1);import{combine as Ru,InterfaceLanguage as Ou,Observable as na,once as Pu,Subject as L,Subscription as _r,ValueSubject as j,fromEvent as ia}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Fe}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Ol}from"@vkontakte/videoplayer-shared";function we(t,e){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>t(...n),e)}}var Z=(t,e)=>Object.prototype.toString.call(t)===`[object ${e}]`,Ae=t=>Z(t,"Object"),st=t=>Z(t,"String"),ot=t=>Z(t,"Array"),at=t=>Z(t,"Number"),Zi=t=>Z(t,"Function");var mr=t=>at(t)&&!isNaN(t);var J=t=>Ae(t)&&Object.keys(t).length===0,fr=t=>ot(t)&&!t.length;var Re=(t,e)=>st(t)&&(e?t.trim():t).length;var Ji="video_interactive",es="videoint";var ts=250,Oe=class{constructor(e){this.handleZoomChange=we(e=>{this.lastZoomInfo=e},ts);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let r=this.getNextPoint();r&&this.ngEditor?.zoomTo(r),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Chapter id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,r=[])=>{if(this.isReady=!1,!at(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(r),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(r)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:r,onError:n,lang:i,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=r,this.onError=n,this.lang=i??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Pl(e),this.resizeObserver=new ResizeObserver(we(this.onResize,ts)),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){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await Ol(this.lang,Ji,es)}catch{this.onError?.("Unable to load graph language pack")}let{GraphEditor:r}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new r(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:n,...i})=>{n==="openPreview"&&"chapterId"in i&&this.onOpenPreviewClick?.(i.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Pl(t){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",t.append(e),e}var Pe=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(r=>r.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let r=-1,n=!1,i=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let c=s.startTime-e;if(c<=i&&(s.endTime&&i<=s.endTime||s.endTime===null)){n=!0;break}i<c&&(r=r===-1?c:Math.min(r,c))}return!n&&r!==-1?r:null}}};import{isSupportedManifest as lt,ContainerTypes as om,ControlTypes as pt,EventActionTypes as w,EventTypes as am,migrateManifestToLatestVersion as ss,compareVersions as cm}from"@interactiveplatform/movika-manifest";var rs={metadata:"Object",chapters:"Array"},ns=t=>{if(!Ae(t))return!1;for(let e in rs)if(!t[e]||!Z(t[e],rs[e]))return!1;return lt(t.metadata.version)},ct=t=>t.type===pt.Text,Zd=t=>t.type===pt.Button,Jd=t=>t.type===pt.Area,em={Choice:"Choice",TextInput:"TextInput"},tm={Button:"Button",Area:"Area",Text:"Text"},rm={onClick:"onClick",onSuspense:"onSuspense"},is={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var M=class{constructor(e,r,...n){this.severity=e;this.category=r;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var ut=class{constructor(){this.listeners={}}addListener(e,r){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(r),this}on(e,r){return this.addListener(e,r)}once(e,r){this.listeners[e]=this.listeners[e]||[];let n=()=>{r(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,r){return this.removeListener(e,r)}reset(){this.listeners={}}removeListener(e,r){let n=this.listeners[e]||[];for(let i=n.length;i>0;i--)if(n[i]===r){n.splice(i,1);break}return this}emit(e,...r){let n=this.listeners[e];return n?(n.forEach(i=>{i(...r)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var ht=class{constructor(e){this.fns=[];this.addFn=(e,r=!1)=>{Zi(e)&&(this.fns.push(e),r&&this.updateFn())};this.removeFn=(e,r=!1)=>{this.fns=this.fns.filter(n=>n!==e),r&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as $l}from"@vkontakte/videoplayer-shared";var dt=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,r){return kl(...this.loaders[e])(r)}};function kl(...t){return async function(r){let n=[...t];for(;n.length>0;)r=await n.shift()(r);return r}}function ke(t,e,r){return t?{...t,[e]:t[e]?[r,...t[e]]:[r]}:{[e]:[r]}}function mt({actions:t,errors:e,chapterId:r,...n}){if(r){let i=t.getManifest();if(i){let s=t.getChapter(i.chapters,r);if(s){let c=t.getMedia(i.media,s.videoId),o=t.getGraph(i.graph,s.id);return c?{...n,actions:t,errors:e,result:{chapter:s,media:c,graph:o}}:{...n,errors:ke(e,mt.name,"Could not find media"),actions:t}}}}return{...n,errors:ke(e,mt.name,"Could not find chapter"),actions:t}}var ft=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:n})}removeEventListener(e,r){if(!(e in this.listeners))return;let n=this.listeners[e];for(let i=0,s=n.length;i<s;i++)if(n[i].callback===r){n.splice(i,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let n=this.listeners[e.type].slice();for(let i=0,s=n.length;i<s;i++){let c=n[i];try{c.callback.call(this,e)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(e.type,c.callback)}return!e.defaultPrevented}},ue=class extends ft{constructor(){super(),this.listeners||ft.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Ve=class{constructor(){Object.defineProperty(this,"signal",{value:new ue,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch{typeof document<"u"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let n=e;if(n===void 0)if(typeof document>"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(Ve.prototype[Symbol.toStringTag]="AbortController",ue.prototype[Symbol.toStringTag]="AbortSignal");function vt(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function vr(t){typeof t=="function"&&(t={fetch:t});let{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!vt({fetch:e,Request:r,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:s};let s=r;(s&&!s.prototype.hasOwnProperty("signal")||i)&&(s=function(l,d){let m;d&&d.signal&&(m=d.signal,delete d.signal);let f=new r(l,d);return m&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),f},s.prototype=r.prototype);let c=e;return{fetch:(a,l)=>{let d=s&&s.prototype.isPrototypeOf(a)?a.signal:l?l.signal:void 0;if(d){let m;try{m=new DOMException("Aborted","AbortError")}catch{m=new Error("Aborted"),m.name="AbortError"}if(d.aborted)return Promise.reject(m);let f=new Promise((y,R)=>{d.addEventListener("abort",()=>R(m),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([f,c(a,l)])}return c(a,l)},Request:s}}var Me=vt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),os=Me?vr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,yr=Me?os.fetch:window.fetch,wm=Me?os.Request:window.Request,Am=Me?Ve:window.AbortController,Rm=Me?ue:window.AbortSignal;var br=(t="",e="")=>{let r=t.split("."),n=e.split("."),i=0;for(let s=0;s<Math.max(r.length,n.length)&&!i;s++)r[s]>n[s]?i=1:r[s]<n[s]?i=-1:i=0;return i};var Vl=async t=>{try{let e={},r;if(st(t)){r=new URL(t).href;let i=await yr(r);if(!i.ok)return{};e=await i.json()}else if(Ae(t))e=t;else return{};if(!ns(e))return{};let n=e.metadata.media;if(st(n)&&!("media"in e))try{let i;r?i=new URL(n,r).href:(i=new URL(n).href,r=i);let s=await yr(i);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return Ll(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:r}}catch{return{}}};async function as(t){let{manifest:e,manifestURL:r}=await Vl(t);if(!e)throw new Error("Failed on fetch");let n=ss(e);return n.media=Ml(n.media,r),delete n.metadata.media,n}function yt(t,e){if(e)return t.find(r=>r.id===e)}function Cr(t,e){return t.edit?.chapters?t.edit.chapters.find(r=>r.id===e):t.view?.chapters?t.view.chapters.find(r=>r.id===e):void 0}function gr(t,e){return t.videos.find(r=>r.id===e)}function Ml(t,e){return{...t,videos:t.videos.map(r=>({...r,variants:r.variants.map(n=>{let i="url"in n?n.url:"",s=Nl(i,e);return{...n,url:s||i}})}))}}function Nl(t="",e){try{return new URL(t,e).href}catch{return""}}function Ll(t){return br(t,"3.2.0")>=0}var bt=t=>ot(t)&&!fr(t),z=t=>t.order==="end",Ct=t=>ot(t.containers)&&!fr(t.containers)&&z(t),cs=(t,e)=>{let r=t*1e3;return bt(e.controls)&&r<(e.startTime??0)},Er=(t,e)=>{let r=t*1e3;return bt(e.controls)&&r>=(e.startTime??0)&&r<=(e.endTime??1/0)};var ee=(t=[])=>t.some(e=>e.action.type==="expect"),Ir=(t=[])=>t.find(e=>e.action.type==="expect"),jl=t=>t?.length===1,he=t=>jl(t)&&ct(t[0]);function ls(t,...e){return r=>typeof e[0]=="object"&&typeof r=="object"?t({...e[0],...r}):t(...e,...r)}var ps=(t,e)=>{let r=E=>e.find(({container:I})=>I.container.id===E)?.container.isRemoved,n=ee(t.events)&&!r(t.id),i=(E,C=!1,I=!1)=>{let h=I?"every":"some";return E.controls[h](p=>{let v=C?E.endTime===t.endTime:!0;return p.events?.[h](b=>b.action?.type===is.openURI)&&v})},s=E=>E.some(({container:C})=>i(C.container,!0,!1)&&!C.isRemoved),c=E=>E.every(({container:C})=>C.isRemoved?!0:i(C.container,!0,!0)),o=e.filter(({container:E})=>E.container.id!==t.id&&ee(E.container.events)&&E.container.endTime===t.endTime&&!E.isRemoved).length,a=E=>E.controls.some(C=>C.events?.some(I=>I.action?.args?.shouldOpenNow)),l=n||o>0,d=s(e),m=i(t),f=c(e),y=n?!1:o>0,R=a(t);return{isExpectTime:l,hasOtherExpect:o>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:m,isAllOpenURIEventsValid:f,isExpectEventForCurrentContainer:y,hasShouldOpenNowEvent:R}};var de=class extends dt{constructor(r,n){super(r);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new $l(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(r){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:ke},result:null,errors:null,source:r});return n.errors&&this.errorHandler(n.errors),this.manifest=await as(n.result??r),this}async setInitial(){return this.setNext()}async setNext(r=this.manifest?.metadata.initChapterId){if(!r)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",mt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Cr,getChapter:yt,getMedia:gr,getByBranches:this.getByBranches.bind(this),addErrorMessage:ke},result:null,errors:null,chapterId:r}));return n.errors&&this.errorHandler(n.errors),n.result&&(this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph),this}errorHandler(r){this.onError(r),console.error("Something went wrong with loaders",{errors:r})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(r=this.manifest?.metadata.initChapterId){if(!r||!this.manifest)return null;let n=yt(this.manifest.chapters,r);if(n){let i=gr(this.manifest.media,n.videoId),s=Cr(this.manifest.graph,n.id);if(i)return{chapter:n,media:i,graph:s}}return null}getBranches(r=this.chapter?.id){if(r===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=yt(this.manifest?.chapters||[],r);return this.getByBranches(n?.branches)}}getByBranches(r=[]){return r.reduce((n,i)=>{let s=this.getByChapterId(i.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?z(this.chapter):!1}};var Zs=K(gt(),1);import{Player as Sp}from"@vkontakte/videoplayer-core";import{Subscription as Rr,ValueSubject as wp}from"@vkontakte/videoplayer-shared";var Us=t=>{let e=t.variants.find(r=>r.payload?.type==="vk");if(e&&e.payload){let[r,n]=e.payload.id.split("_");return[r,n]}return[]};var Gs=K(gt(),1);function wr(){let t=new Map;function e({listId:s=Math.random().toString(),itemId:c=Math.random().toString(),...o}){let a=t.get(s),l={...o};return a?a[c]=l:t.set(s,{[c]:l}),{listId:s,itemId:c,...o}}function r(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,c){let o=t.get(s);if(!o)throw Error("Can't remove. Not find.");if(c){let a=o[c];a&&r(a),delete o[c],Object.keys(o).length||t.delete(s)}else{for(let a of(0,Gs.default)(o))r(a);t.delete(s)}}function i(){for(let s of t)n(s[0])}return{createPlayer:e,removePlayer:n,map:t,removeAll:i}}var me=K(Et(),1);function Ar(t,e=[]){let r={},n,i=!e.length;for(let s of t.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(i||(0,me.default)(e,"mp4"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(i||(0,me.default)(e,"mpeg"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(i||(0,me.default)(e,"hls"))&&(r={...r,HLS:{type:"url",url:s.url}});break;case"dash":(i||(0,me.default)(e,"dash"))&&(r={...r,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:r,thumbUrl:n,title:t.title??""}}var Ne=(t,e)=>{let r=t.info.currentQuality$.getValue(),n=t.info.availableQualities$.getValue();r!==e&&(0,me.default)(n,e)&&(t.setQuality(e),t.setAutoQuality(!1))};var Ap=2;function Or(t){let e=wr(),r=new Rr,n={},i=null,s=!1,c,o=new wp(null);t&&a(t);function a(C){i=C}function l(C,I,h){if(!i)throw Error("need to set interactive controller");if(!i.options)return;let v=(e.map.get(C)??{})[I];if(v){n={chapterId:h,listId:C,itemId:I,...v};let b=n.player;n.subscription.add(b.info.currentQuality$.subscribe(g=>{let T=b.info.position$.getValue(),A=b.info.isAutoQualityEnabled$.getValue();if(!(!g||!T||A))for(let k of e.map)(0,Zs.default)(k[1]).forEach(({player:S})=>{Ne(S,g)})})).add(b.events.started$.subscribe(()=>{d(I)})),v.container.remove(),i.setPlayer(v.player),s||(i.init(),s=!0),o.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function d(C){if(!i)throw Error("need to set interactive controller");if(J(n)||C!==n.itemId)return;let I=i.getChapterBranches(),h=new Set;for(let p of I)h.has(p.media.id)||(await f({media:p.media,chapterId:p.chapter.id,setAsActive:!1,title:p.chapter.label}),h.add(p.media.id))}async function m({chapter:{id:C},manifestVideo:I}){if(J(n)||!i)return;let h=n.player.info.muted$.getValue(),p=n.player.info.currentQuality$.getValue(),v=n.player.info.isAutoQualityEnabled$.getValue(),b=n.player.info.volume$.getValue(),g=n.player.info.currentPlaybackRate$.getValue(),T=!v,A=!1;for(let k of e.map)if(k[0]===I.id&&!i.state.isReplay$.getValue()){let S=Object.keys(k[1]);for(let V of S)V===n.itemId?(S.length<Ap||(A=!0),e.removePlayer(k[0],V)):(A=!0,l(k[0],V,C),T?Ne(n.player,p):n.player.setAutoQuality(!0),n.player.setVolume(b),n.player.setMuted(h),n.player.setPlaybackRate(g))}else e.removePlayer(k[0]);A||(await f({media:I,chapterId:C,setAsActive:!0,playbackRate:g}),T?Ne(n.player,p):n.player.setAutoQuality(!0),n.player.setVolume(b),n.player.setMuted(h))}async function f({media:C,chapterId:I,prefetch:h=!0,setAsActive:p=!0,autoplay:v=!1,preferredExt:b,title:g,playbackRate:T}){let A=Math.random().toString(),k=document.createElement("div");c.append(k);let S;if(i?.options?.vkVideoLoader){let qe=Us(C);qe.length&&(S=await i.options.vkVideoLoader(...qe))}let V=i?.options?.coreConfig||void 0,q={...V,configName:[...V?.configName??[],"interactive"]},B={container:k,...S?.videos?.[0]||{sources:Ar(C,b).sources},title:g,failoverHosts:S?.failoverHosts||[]},D=new Sp(q);D.initVideo(B);let W=null;if(S?.videos&&i?.options.createOneStat){let qe=S.videos[0],Rt=i.options.createOneStat(qe),Fr=new Rr;Rt&&(Fr.add(Rt.attachTo(D)),W={oneStat:Rt,statSubscription:Fr})}let te=new Rr,aa=n?.player?.info.isAutoQualityEnabled$.getValue();te.add(D.events.canplay$.subscribe(function(){aa||Ne(D,n.player.info.currentQuality$.getValue()),T&&D.setPlaybackRate(T)}));let re=e.createPlayer({listId:C.id,itemId:A,player:D,container:k,sources:Ar(C,b).sources,config:B,subscription:te,statistics:W});return p&&l(C.id,re.itemId,I),v&&re.player.play(),h&&!v&&re.player.prepare(),{player:re.player,config:re.config,statistics:re.statistics}}function y(){R(),i=null,c.remove()}function R(){r.unsubscribe(),e.removeAll(),n={},s=!1}async function E(){if(!i)throw Error("need to set interactive controller");R(),c=document.createElement("div");let{media:C,chapter:I}=i.getCurrentChapter();C&&I?(r.add(i.events.chapterChanged$.subscribe(m)),await f({media:C,chapterId:I.id,title:I.label})):console.error("not found")}return{...e,init:E,setInteractiveController:a,createPlayer:f,removeAll:y,getActivePlayer:function(){return n},activePlayerChanged:o}}var x={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Le={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},O={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var eo=K(Et(),1);import{Subscription as Rp}from"@vkontakte/videoplayer-shared";var It=class{constructor({player:e,container:r,branches:n,selectBranches:i,interactiveEvents:s,globalEvents:c,globalEventEmitter:o,getContainerEventState:a,permanentTextControls:l,interactiveTimeOpenUri:d,disabledControls$:m,onRemove:f}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(ee(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:r}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&r)return;this.emitContainerVisibilityEvent(!0,!1)}else{let r={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(i,s)=>{let{isExpectTime:c,hasOtherExpect:o,hasOpenURIEvent:a,hasOpenURIEventInCurrentContainer:l,isAllOpenURIEventsValid:d,hasShouldOpenNowEvent:m}=this.getContainerEventState(),f=this.interactiveTimeOpenUri&&!l,y=this.interactiveTimeOpenUri&&l;if((!this.interactiveTimeOpenUri||f)&&(this.isSelectedControlEvent=!0),i!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||f)){if(this.interactiveTimeOpenUri){let R=!o&&!d&&l;R&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:R})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&a&&this.gameState!==5){if(y){let E=((C,I,h,p)=>!C&&!I&&h||C&&!I&&h&&!p||C&&!I&&h&&p)(c,o,d,this.isSelectedContainerEvent);this.fakeRemoveView(E)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!c||!o||!m)&&(this.selectBranches.stopExpect(),s())}},isEOV:()=>this.gameState===4},n=ls(this.selectBranches.onControlEvent,r);this.container.createView({eventCallback:n}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,i=[6,5];if(!n||(0,eo.default)(i,this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(cs(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Er(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let l=this.gameState;this.gameState=3,l===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:l}=this.getContainerEventState(),d=this.selectBranches.state.isExpect,m=this.interactiveTimeOpenUri&&l;if(m&&!d){let f=this.container.getElement();f&&(f.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!m&&this.removeView()}let c=Er(s,this.container.container),o=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],a={subjectId:this.container.container.id,subjectName:"container",range:o,currentTime:s,isInteractiveTime:c};this.container.onProgress(s*1e3,c),this.globalEventEmitter.emit(x.eachTick,a),this.globalEvents.eachTick$.next(a)};this.container=r,this.branches=n,this.selectBranches=i,this.subscription=new Rp,this.player=e,this.interactiveEvents=s,this.getContainerEventState=a,this.isPermanentText=l&&he(r.container.controls),this.interactiveTimeOpenUri=d,this.disabledControls$=m,this.onRemove=f,this.globalEventEmitter=o,this.gameState=0,this.globalEvents=c,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,r=!1){e?(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.visibility,visibility:e,isFirst:r}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e,isFirst:r})):(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}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=>{e?this.container.disable?.():this.container.enable?.()}))}selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:r}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!r&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:r}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||r:ee(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var to=(t=[])=>t.reduce((e,r,n)=>{let i=(r?.controls??[]).filter(s=>!ct(s));if(bt(i)){let s=[r.startTime??0,r.endTime??1/0],c={id:r.id,isRemoved:!1};if(!n)e.push({subjects:[c],range:s});else{let o=[],a=-1/0,l=1/0,d=[],m=[];for(let f=0;f<e.length;f++){let y=e[f];if(m.push(...y.subjects),y.range[0]<l&&(l=y.range[0]),y.range[1]>a&&(a=y.range[1]),s[0]>=y.range[0]&&s[1]<=y.range[1])return e[f].subjects.push(c),e;s[0]<y.range[0]&&s[1]>y.range[0]&&(o.push(f),d=d.concat(y.subjects)),s[0]>=y.range[0]&&s[0]<=y.range[1]&&(o.push(f),d=d.concat(y.subjects),s[0]=y.range[0]),s[1]>=y.range[0]&&s[1]<=y.range[1]&&(o.push(f),d=d.concat(y.subjects),s[1]=y.range[1])}if(m.push(c),s[0]<=l&&s[1]>=a)return[{subjects:m,range:s}];o.length&&o.reverse().forEach(f=>{e.splice(f,1)}),e.push({subjects:d.concat([c]),range:s})}}return e},[]).sort((e,r)=>e.range[0]-r.range[0]);var $o=K(Et(),1),Mr=K(gt(),1),_o=K(Lo(),1);function jo(){let t={};function e(){for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&delete t[o]}function r(o){let a={};for(let l in t)+l<=o&&(a[l]=t[l]);return a}function n(o){let a={};for(let l in t)+l>=o&&(a[l]=t[l]);return a}function i({timestamp:o,priority:a,initiator:l}){if(mr(o)){let d=t[o]??null;if(d&&a&&Re(a,!0)){let m={},f=d[a];return f&&(m={...m,...f}),m=J(m)?null:m,m&&Re(l,!0)?m[l]??null:m}return d}return null}function s({timestamp:o,priority:a,initiator:l}){if(mr(o))if(t[o]){if(a&&Re(a,!0))if(t[o][a]){if(l&&Re(l,!0))if(t[o][a][l]){if(delete t[o][a][l],!J(t[o][a]))return!0}else return!1;if(delete t[o][a],!J(t[o]))return!0}else return!1;return delete t[o]}else return!1;return!1}function c({timestamp:o,priority:a,initiator:l,...d}){t[o]?.[a]?.[l]?t[o][a][l].push({...d}):t[o]?.[a]?t[o][a]={...t[o][a],[l]:[{...d}]}:t[o]?t[o]={...t[o],[a]:{[l]:[{...d}]}}:t[o]={[a]:{[l]:[{...d}]}}}return{map:t,remove:s,add:c,removeAll:e,get:i,getLte:r,getGte:n}}var vu=[w.expect,w.setNextBranch],yu=1/0;function Fo(t,e){let r=t,n,i=bu(e),s=jo(),c,o=()=>{y(),h()},a=p=>{s.add.call(void 0,p),E()},l=(p=[])=>{for(let v of p)if(v.action(),(0,$o.default)(vu,v.actionType))break},d=(p=1/0)=>{let v=xt(s.get({timestamp:p,priority:"control"})??{}),b=xt(s.get({timestamp:p,priority:"container"})??{}),g=xt(s.get({timestamp:p,priority:"chapter"})??{});return[...v,...b,...g]},m=p=>{i.isReady(p)&&l(d(p))},f=()=>{l([...xt(s.get({timestamp:1/0,priority:"chapter"})??{})])},y=()=>{n&&(c?.unsubscribe(),n=void 0)},R=p=>{},E=()=>{n||(n=()=>setTimeout(()=>{m(1/0)}),c=r.events.ended$.subscribe(n))},C=p=>{y(),r=p},I=p=>{p.priority==="container"&&i.resetCalled(p.timestamp),s.remove(p)},h=()=>{i.release(),s.removeAll()};return{setPlayer:C,add:a,remove:I,exec:m,execEndOfVideo:f,listen:E,unlisten:y,release:o,containersEventsCallState:i,getPreparedToExecActions:d}}function bu(t){let e=new Map;return{setCalled:({timestamp:o,id:a})=>{let l=e.get(o);l&&l[a]!==void 0&&(l[a]=!0)},setData:(o=[])=>{for(let a of o){let l=a.endTime??yu,d=e.get(l);e.set(l,{...d,[a.id]:!1})}},resetCalled:o=>{let a=e.get(o);if(a)for(let l in a)a[l]=!1},isReady:o=>{let a=e.get(o);if(!a)return!0;let l=(0,Mr.default)(a);return t?l.some(m=>m):!l.some(m=>!m)},release:()=>e.clear()}}function xt(t){return(0,_o.default)((0,Mr.default)(t)).sort(e=>e.actionType===w.expect?-1:1)}var qo={videoContentHeight:0,videoContentWidth:0},Bo=t=>{let{height:e,width:r}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&r))return qo;let{clientHeight:n,clientWidth:i}=t.experimental.element$.getValue()||{};if(!(n&&i))return qo;let s=e/r,c=n/i,o,a;return c>s?(a=i,o=i*s):c<s?(a=n/s,o=n):(a=i,o=n),{videoContentWidth:a,videoContentHeight:o}};var Cu=250;function Do(t){let e,r=new ResizeObserver(o=>{s(o),e=s.bind(null,o)});function n(o){let{parentElement:a,player:l}=t();if(a&&l){let{videoContentWidth:d,videoContentHeight:m}=Bo(l);a.style.setProperty("--interactive-content-width",`${d}px`),a.style.setProperty("--interactive-content-height",`${m}px`),a.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function i(){let{parentElement:o}=t();o.removeAttribute("style")}let s=we(o=>{let{fns:a=[]}=t();n(o);for(let l of a)l()},Cu);function c(){e=void 0,r.disconnect(),i()}return{resizeObserver:r,calc:()=>{e?.()},release:c}}var gu=t=>Math.floor(Math.random()*t),Uo=t=>{let e=t.length,r=1/0,n=null;for(;e--;){let i=t[e],s=i.weight??1;s<r&&(r=s,n=i)}return n},Go=t=>{let e=t.length,r=-1/0,n=null;for(;e--;){let i=t[e],s=i.weight??0;s>r&&(r=s,n=i)}return n};var zo=t=>{let e=t.length,r=gu(e);return t[r]},Ho=1,Wo=t=>{let e=0;for(let n=0;n<t.length;++n)e+=t[n].weight??Ho;let r=Math.random()*e;e=0;for(let n=0;n<t.length-1;++n)if(e+=t[n].weight??Ho,e>=r)return t[n];return t[t.length-1]};var Ko={shouldOpenNow:!0,isDetachContainer:!0},Qo="after-expect";var Nr=(t,e=!1)=>({...t,args:e?{...t.args,...Ko}:{...Ko,...t.args}}),Zo=({globalEventEmitter:t,globalEvents:e,player:r,interactiveEvents:n})=>{let i={isExpect:!1},s=()=>{i.isExpect&&(i.isExpect=!1)},c=({action:h,controlType:p,controlId:v,containerId:b,branches:g=[],onEvent:T,isEOV:A=()=>!1,isDisabled:k=()=>!1})=>{let S=Nr(h,A()),V={timestamp:1/0,priority:"control",initiator:v,actionType:S.type},q=k(),B=t.emit.bind(t,x.interactives,{subjectId:v,subjectType:p,subjectName:"control",type:q?O.actionChoiceCanceled:O.actionChoice,actionType:h.type,payload:{invokeImmediately:S.args.shouldOpenNow,containerId:b,...S.args}}),D=()=>{e.interactiveActionChoice$.next({subjectId:v,subjectType:p,subjectName:"control",type:q?"action-choice-canceled":"action-choice",actionType:h.type,payload:{invokeImmediately:S.args.shouldOpenNow,containerId:b,...S.args}})};if(q){B(),D();return}switch(S.type.trim().toLowerCase()){case w.setNextBranch.trim().toLowerCase():{let W=g.find(te=>te.id===S.args.branchId);if(!W)return;T(S.args.isDetachContainer,y.bind(null,{subjectId:v,subjectName:"control"})),B(),D(),S.args.shouldOpenNow?E({subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{chapterId:W.chapterId,autoSelect:!1}}):n.add({...V,action:E.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{chapterId:W.chapterId,autoSelect:!1}})});return}case w.continuePlayback.trim().toLowerCase():{T(S.args.isDetachContainer,y.bind(null,{subjectId:v,subjectName:"control"})),B(),D(),S.args.shouldOpenNow?R({subjectId:v,subjectName:"control",subjectType:p,action:h}):n.add({...V,action:R.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:h})});return}case w.openURI.trim().toLowerCase():{T(S.args.isDetachContainer,y.bind(null,{subjectId:v,subjectName:"control"})),B(),D(),S.args.shouldOpenNow?I({subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{URI:h.args.uri}}):n.add({...V,action:I.bind(null,{subjectId:v,subjectName:"control",subjectType:p,action:S,payload:{URI:h.args.uri}})});return}default:{let W="Unexpected control event",te=new M(1,1,{message:W});d(te,W);return}}},o=({action:h,container:{id:p,endTime:v},branches:b=[],isEOV:g=!1,autoSelected:T=!1})=>{let A=Nr(h,g),k={timestamp:!A.args.shouldOpenNow||g?1/0:v??1/0,priority:"container",initiator:p,actionType:A.type},S=t.emit.bind(t,x.interactives,{subjectId:p,subjectName:"container",type:O.actionChoice,actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}}),V=()=>{e.interactiveActionChoice$.next({subjectId:p,subjectName:"container",type:"action-choice",actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}})};switch(A.type.trim().toLowerCase()){case w.setNextBranch.trim().toLowerCase():{let q=b.find(B=>B.id===A.args.branchId);if(!q)return;S(),V(),n.add({...k,action:E.bind(null,{subjectId:p,subjectName:"container",action:A,payload:{chapterId:q.chapterId,autoSelect:T}})});return}case w.setMaxWeightBranch.trim().toLowerCase():return;case w.setMinWeightBranch.trim().toLowerCase():return;case w.setRandomBranch.trim().toLowerCase():return;case w.setWeightlessRandomBranch.trim().toLowerCase():return;case w.continuePlayback.trim().toLowerCase():{S(),V(),n.add({...k,action:R.bind(null,{subjectId:p,subjectName:"container",action:A})});return}case w.openURI.trim().toLowerCase():{S(),V(),n.add({...k,action:I.bind(null,{subjectId:p,subjectName:"container",action:A,payload:{URI:h.args.uri}})});return}default:{let q="Unexpected container event",B=new M(1,1,{message:q});d(B,q);return}}};function a({container:h,branches:p,isEOV:v=!1}){let b=Ir(h.events);if(b){let g=Nr(b.action,v);t.emit(x.interactives,{subjectId:h.id,subjectName:"container",type:O.actionChoice,actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"container",type:"action-choice",actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),n.add({timestamp:v?1/0:h.endTime??1/0,priority:"container",initiator:h.id,actionType:w.expect,action:f.bind(null,{subjectId:h.id,subjectName:"container"})}),i.isExpect=!0}else for(let g of h.events??[])o({action:g.action,container:h,branches:p,isEOV:v})}let l=({chapterId:h,action:p,branches:v=[]})=>{let b=t.emit.bind(t,x.interactives,{subjectId:h,subjectName:"chapter",type:O.actionChoice,actionType:p.type,payload:p.args}),g=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"chapter",type:"action-choice",actionType:p.type,payload:p.args})};switch(p.type.trim().toLowerCase()){case w.setNextBranch.trim().toLowerCase():{let T=v.find(A=>A.id===p.args.branchId);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setWeightlessRandomBranch.trim().toLowerCase():{let T=zo(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setRandomBranch.trim().toLowerCase():{let T=Wo(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setMaxWeightBranch.trim().toLowerCase():{let T=Go(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.setMinWeightBranch.trim().toLowerCase():{let T=Uo(v);return T?.chapterId?(b(),g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case w.continuePlayback.trim().toLowerCase():return b(),g(),R.bind(null,{subjectId:h,subjectName:"chapter",action:p});case w.openURI.trim().toLowerCase():return b(),g(),I.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:{let T="Unexpected chapter event",A=new M(1,1,{message:T});d(A,T);return}}};function d(h,p){console.error(p),e.error$.next(h),t.emit(x.errors,h)}function m(h){let p=Ir(h.events);if(p){if(z(h))return;t.emit(x.interactives,{subjectId:h.id,subjectName:"chapter",type:O.actionChoice,actionType:p.action.type,payload:p.action.args}),e.interactiveActionChoice$.next({subjectId:h.id,subjectName:"chapter",type:"action-choice",actionType:p.action.type,payload:p.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:w.expect,action:f.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events?.forEach(v=>{let b=l({chapterId:h.id,action:v.action,branches:h.branches});b&&n.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:v.action.type,action:b})})}let f=({subjectId:h,subjectName:p})=>{r.pause(),t.emit(x.interactives,{subjectId:h,subjectName:p,type:O.actionExecution,actionType:w.expect}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,type:"action-execution",actionType:w.expect})},y=({subjectId:h,subjectName:p})=>{r.info.isEnded$.getValue()?n.execEndOfVideo():r.play(),t.emit(x.interactives,{subjectId:h,subjectName:p,type:O.actionExecution,actionType:Qo}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,type:"action-execution",actionType:Qo})},R=({subjectId:h,subjectName:p,subjectType:v,action:b})=>{t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type})},E=({subjectId:h,subjectName:p,subjectType:v,action:b,payload:g})=>{g.behaviour="change-chapter",t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type,payload:g}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type,payload:g})},C=({subjectId:h,subjectName:p,subjectType:v,action:b,payload:g})=>{g.behaviour="change-manifest",t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type,payload:g}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type,payload:g})},I=({subjectId:h,subjectName:p,subjectType:v,action:b,payload:g})=>{if(!g.URI)return;let T=window.open(g.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),t.emit(x.interactives,{subjectId:h,subjectName:p,subjectType:v,type:O.actionExecution,actionType:b.type}),e.interactiveActionExecution$.next({subjectId:h,subjectName:p,subjectType:v,type:"action-execution",actionType:b.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:l,onExpectEvent:f,expectEventHandler:y,setManifestChapterEvents:m,setManifestContainerEvents:a,stopExpect:s,state:i}};var $r=K(dr(),1);import{Subscription as Su,Subject as jr,ValueSubject as $e}from"@vkontakte/videoplayer-shared";var Lr=(t,e)=>{let r={};return t.map(n=>{if(!r[n]){let i=e.chapters.find(c=>c.id===n);if(!i)return null;let s=e.media.videos.find(c=>i.videoId===c.id);if(!s)return null;r[n]=Jo(s)}return r[n]}).filter(Boolean)},Iu=t=>{for(let e of t.variants)if(Tu(e)&&e.payload)return e.payload.id},Tu=t=>!!(t.type==="custom"&&t.payload&&t.payload.type==="vk"),Jo=t=>{let e=Iu(t);if(!e)return null;let r=e.split("_").pop();return r?parseInt(r,10):null},xu=(t,e)=>{for(let r of t.media.videos)if(e===Jo(r)){for(let n of t.chapters)if(n.videoId===r.id)return n.id;return}},ea=(t,e)=>t.reduce((r,n)=>{let i=xu(e,n);return i?[...r,i]:r},[]);var _e=class{constructor({globalEventEmitter:e,videoId:r,interactiveController:n,historyApi:i,settings:s}){this.state={history$:new $e([]),hasPrevChapter$:new $e(!1),prevChapter$:new $e(null),isInitialChapter$:new $e(!1),isGoBackLimited$:new $e(!1)};this.#r=null;this.#o=!1;this.#e=null;this.#p=null;this.events={inited$:new jr,destroyed$:new jr,error$:new jr};this.#n=null;this.#i=null;this.#t=null;this.#a=new Su;this.#c=!1;this.#l=0;this.#n=r,this.#t=e,this.#i=n,this.#r=i,this.#s=s,this.state.history$&&this.#a&&this.#a?.add(this.state.history$.subscribe(c=>{this.state.prevChapter$.next((0,$r.default)(c,-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#l===this.#s.maxLength-1)}))}#r;#s;#o;#e;#p;#n;#i;#t;#a;#c;#l;async setManifest(e){if(!this.#i||!this.#t)return;this.#e=e,await this.getProjectHistory();let r=this.getInitialChapterId();await this.#i.setChapter({chapterId:r,pushToHistory:!1}),this.#o||(this.#o=!0,this.events.inited$.next({initChapterId:r}))}get inited(){return this.#o}async updateHistory(e,r=!0){if(!this.#e)return;this.#c?(this.#c=!1,this.#l++):this.#l=0;let n=this.#e,i=e.length-this.#s.maxLength,s=i>0?e.slice(i):e,c=Lr(s,n);if(this.#p=c,this.state.history$.next(s),!(!r||!this.#r||!this.#n))try{await this.#r.save(this.#n,c)}catch{let a=new M(1,5,"Unable to save interactive history");this.events.error$.next(a),this.#t?.emit(x.errors,a)}}async goBack(){if(!this.state||!this.#i){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#t?.emit(x.errors,n)}this.#c=!0;let e=this.state.history$.getValue().slice(0,-1),r=e.pop();this.state.history$.next(e),await this.#i.setChapter({chapterId:r,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#n)return;let e=this.#e,r=[this.getInitialVideoId()];if(this.#r)try{let i=await this.#r.get(this.#n);i.length&&(r=i)}catch{let s=new M(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#t?.emit(x.errors,s)}let n=ea(r,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,$r.default)(e,-1)||this.#s.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return Lr([e],this.#e).pop()}return null}destroy(){this.#n=null,this.#r=null,this.#i=null,this.#a?.unsubscribe(),this.#a=null,this.#o=!1,this.#t?.emit(x.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var St=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let r=e.data,n=r.length;for(let i=3;i<n;i+=40)if(r[i]!==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(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,r=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let i;r&&(i=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,r&&i&&this.restore(i),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),r=new Image;return r.crossOrigin="anonymous",r.src=e,await r.decode(),r}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var wt=class{constructor({parentElement:e,endOffsetMs:r=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let r=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(r);if(this.isContainerTime(r))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)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;
@@ -16,7 +16,7 @@ var ca=Object.create;var qr=Object.defineProperty;var la=Object.getOwnPropertyDe
16
16
  top: 50%;
17
17
  left: 50%;
18
18
  transform: translate(-50%, -50%);
19
- `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let r=getComputedStyle(this.rootElement),n={width:parseInt(r.getPropertyValue("--interactive-content-width"),10),height:parseInt(r.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(i){this._onError(i)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(r=>r.controls?.length&&e>=(r.startTime??0)&&e<=Math.min(r.endTime??1/0,this.currentVideoDurationMs-this.endOffsetMs))}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){this._callbacks?.onError?.(e)}};function ta(t=0){return new Promise(e=>{setTimeout(()=>{e(0)},t)})}var Au=`
19
+ `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let r=getComputedStyle(this.rootElement),n={width:parseInt(r.getPropertyValue("--interactive-content-width"),10),height:parseInt(r.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(i){this._onError(i)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(r=>r.controls?.length&&e>=(r.startTime??0)&&e<=Math.min(r.endTime??1/0,this.currentVideoDurationMs-this.endOffsetMs))}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){this._callbacks?.onError?.(e)}};function ta(t=0){return new Promise(e=>{setTimeout(()=>{e(0)},t)})}var wu=`
20
20
  .${$.common} {
21
21
  opacity: 1;
22
22
  visibility: visible;
@@ -30,7 +30,7 @@ var ca=Object.create;var qr=Object.defineProperty;var la=Object.getOwnPropertyDe
30
30
  .${$.hidden} {
31
31
  visibility: hidden;
32
32
  }
33
- `,Ru=`
33
+ `,Au=`
34
34
  .interactive-chapter {
35
35
  position: absolute;
36
36
  top: 0;
@@ -40,7 +40,7 @@ var ca=Object.create;var qr=Object.defineProperty;var la=Object.getOwnPropertyDe
40
40
  --interactive-transition-1: 100ms ease-in-out;
41
41
  }
42
42
 
43
- ${Au}
43
+ ${wu}
44
44
 
45
45
  .${P.common} {
46
46
  display: flex;
@@ -57,4 +57,4 @@ var ca=Object.create;var qr=Object.defineProperty;var la=Object.getOwnPropertyDe
57
57
  .${P.area} {
58
58
  cursor: pointer;
59
59
  }
60
- `,ra=t=>{let e=document.createElement("style");e.textContent=Ru,t.prepend(e)};import{clientChecker as Vu}from"@vkontakte/videoplayer-core";var sa=Object.freeze({lang:Pu.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}});function Mu(){let t=document.createElement("div");return t.classList.add("interactive-chapter"),t}var At=class{constructor(e){this.playerSubscriptions=new _r;this.subscriptions=new _r;this.globalEventEmitter=new ut;this.animation=new ht;this.seekToInteractiveController=new Pe;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Mu();this.factories=new Map([["choice",Qe]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new _r;this.graph=null;this.lastFrame=null;this.appState=0;this.state={prevChapter$:new L(null),isInitialChapter$:new L(!1),isFirstChapter$:new L(!0),isEndChapter$:new L(!1),isInteractiveExpectation$:new L(!1),isReplay$:new L(!1),calledByInteractive$:new L(!1),lastChapterChangeWasInitiatedByInteractive$:new L(!1),disabledControls$:new L(!1),interactiveRanges$:new L([]),isInteractiveTime$:new L(!1),statistics$:new L(null),isSeekable$:new L(!1)};this.events={noInteraction$:new j,graphVisibilityChanged$:new j,watchAgainIsClicked$:new j,chapterChanged$:new j,playerChanged$:new j,error$:new j,eachTick$:new j,manifestChanged$:new j,interactiveRangeEnded$:new j,interactiveContainerRemoved$:new j,interactiveContainerFakeRemoved$:new j,interactiveActionExecution$:new j,interactiveActionChoice$:new j,interactiveVisibilityChanged$:new j};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(x.errors,e)};this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),r=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&z(n)&&!r&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:r,...n}=e;if(r){let{statSubscription:i,oneStat:s}=r;i.add(s.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(r)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(x.playerChanged,n)};this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(r=>{!e&&r.isPermanentText||(this.animation.removeFn(r.whilePlaying),r.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:r}=this.state,i=r.getValue().map(s=>({...s,subjects:s.subjects.filter(c=>c.id!==e)}));r.next(i)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};this._options={...sa,...e,config:{...sa.config,...e.config}},this._options.parentElement.append(this.rootElement),this.historyController=new _e({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new wt({parentElement:this._options.parentElement,onError:n=>{let i=new M(1,6,n);this.emitErrorEvent(i)}})),ra(this._options.parentElement),this.subscriptions.add(ia(this.rootElement,"mousedown").subscribe(n=>n.stopPropagation())).add(ia(this.rootElement,"mouseup").subscribe(n=>n.stopPropagation())),this.manifestController=new de(this._options.loaders,n=>{let i=new M(1,3,n);this.emitErrorEvent(i)});let r=[];this._options.lastFrame&&r.push(()=>{this.lastFrame?.updateCanvasDimensions(!0)}),r.push(()=>{let n=this.state.isInteractiveTime$.getValue();for(let i of this.gameControllers)i.onResize(n)}),this.resizeManager=Do(()=>({player:this.player,parentElement:this._options.parentElement,fns:r})),this._options.graph&&(this.graph=new Oe({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),this.globalEventEmitter.emit(x.graph,{type:je.watchAgainClicked,chapterId:n}),this.events.watchAgainIsClicked$.next(n)},onError:n=>{let i=new M(1,2,{message:n});this.emitErrorEvent(i)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:r})=>{this.handleFakeRemoval(e,r)})).add(this.events.interactiveActionExecution$.subscribe(e=>{if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour==="change-chapter"){let{chapterId:r}=e.payload;this.setChapter({chapterId:r}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(e.payload?.behaviour==="change-manifest"){let{manifestURL:r}=e.payload;r&&this.setManifest(r)}e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:r,payload:n})=>{e!=="action-choice"||r==="chapter"||"invokeImmediately"in n&&n.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=Or(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let r=e*1e3,i=this.getInteractiveRanges().reverse().find(({range:s})=>r>=s[1]);if(i){let s=i.range.join("-");this.endedRanges.has(s)||(this.endedRanges.add(s),this.globalEventEmitter.emit(x.interactives,{type:O.rangeEnded,payload:i,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:i}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(ku()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Ou({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:r,isInteractiveExpectation:n})=>{let i;if(n)i=!0;else{let a=e*1e3;i=!!r.find(({range:[d,m],subjects:f})=>d<a&&a<m&&f.some(y=>!y.isRemoved)&&f.length)}i!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(i);let s=!!this.noInteractionTimeout,o=this.player?.info.playbackState$.getValue()==="playing"||n;i&&!s&&o?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):s&&!o&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(r=>r.container.container).filter(r=>!he(r.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let r=[];return e.containers.forEach(n=>{let i=n.type.trim().toLowerCase(),c=this.factories.get(i)?.(n,this.rootElement);if(c&&this.selectBranches&&this.interactiveEvents&&this.player){let o=new It({player:this.player,container:c,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>ps(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)}});this.animation.addFn(o.whilePlaying,!0),r.push(o)}}),r}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let r=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!r||!n&&r)&&this.state.isSeekable$.next(!r)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let r=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),i=(n&&z(n)&&Ct(n))??!1,s=this.manifestController.manifest?.metadata.initChapterId===e,c=this.historyController.state.history$.getValue();if(s||i&&r){this.historyController.updateHistory([e]);return}(0,oa.default)(c,-1)!==e&&this.historyController.updateHistory([...c,e])}handleFakeRemoval(e,r){let{interactiveRanges$:n}=this.state,s=n.getValue().map(c=>{let o=c.subjects.some(l=>l.id===e),a=c.subjects.map(l=>r&&o||l.id===e?{...l,isRemoved:!0}:l);return{...c,subjects:a}});n.next(s)}reset(){this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let r=await this.manifestController.setManifest(e);if(r.manifest)return this.graph&&this.graph.handleManifestChange(r.manifest),await this.historyController.setManifest(r.manifest),this.events.manifestChanged$.next(r.manifest),this.globalEventEmitter.emit(x.manifestChanged,{manifest:r.manifest}),this.setGameControllers(),r.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Fo(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=Zo({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:r=!0,playPrev:n=!1}={}){this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&Vu.browser.isSafari&&await ta(35);let i=!n&&this.state.isEndChapter$.getValue()&&this.getCurrentManifest()?.metadata.initChapterId===e;this.state.isReplay$.next(i);let{chapter:s,media:c,graph:o}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||i)&&this.state.isFirstChapter$.next(!0),!(!s||!c)&&(r&&this.pushChapterToHistory(s.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(s),this.lastFrame?.setCurrentChapter(s),this.events.chapterChanged$.next({chapter:s,manifestVideo:c}),this.globalEventEmitter.emit(x.chapterChanged,{chapter:s,media:c,graph:o}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new na(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(r=>{e.next(r?Fe.GRAPH_SHOW:Fe.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(Fe.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:r,subjectName:n,subjectType:i})=>{r!=="action-choice"||n!=="control"||(i==="Button"&&e.next(Fe.NEXT_BUTTON),i==="Area"&&e.next(Fe.NEXT_AREA))}))}),nextMovie$:new na(e=>{this.events.playerChanged$.subscribe(({config:r})=>{r?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(r.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(x.graph,{type:je.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(n=>n.actionType===w.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(r=>!r.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),r=this.player.info.duration$.getValue();return e===r&&this.gameControllers.some(n=>{let i=n.container.container;return!n.container.isRemoved&&i.endTime===null&&ee(i.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&lt(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return to(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,r){return this.globalEventEmitter.on(e,r),this}off(e,r){return this.globalEventEmitter.off(e,r),this}once(e,r){return this.globalEventEmitter.once(e,r),this}destroy(){this.clearHistoryIfEnded(),this.destroyGameControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Nu={Container:ne,createChoiceContainer:Qe,createAreaControl:ze,createButtonControl:Ke,classnamesPrefix:Hr};var ay={version:Br};export{am as ContainerTypes,pt as ControlTypes,M as CustomError,x as EVENT_NAMES,w as EventActionTypes,cm as EventTypes,At as Interactives,de as ManifestController,ay as SDKInfo,jr as chapterIdsToVKVideoIds,br as compareVersions,tm as containerTypes,rm as controlTypes,is as eventActionTypes,nm as eventTypes,Su as getChapterIdByVkVideoId,Jo as getVKVideoIdByMedia,Tu as getVideoRawIdByMedia,je as graphEventTypes,Ct as hasEndTemplate,O as interactivesEventTypes,em as isAreaControl,Jd as isButtonControl,z as isLastChapter,he as isOneTextCtrlContainer,lt as isSupportedManifest,ct as isTextControl,xu as isVKVariantItem,ns as isValidManifest,ss as migrateManifestToLatestVersion,Nu as utils,ea as vkVideoIdsToChapterIds};
60
+ `,ra=t=>{let e=document.createElement("style");e.textContent=Au,t.prepend(e)};import{clientChecker as ku}from"@vkontakte/videoplayer-core";var sa=Object.freeze({lang:Ou.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}});function Vu(){let t=document.createElement("div");return t.classList.add("interactive-chapter"),t}var At=class{constructor(e){this.playerSubscriptions=new _r;this.subscriptions=new _r;this.globalEventEmitter=new ut;this.animation=new ht;this.seekToInteractiveController=new Pe;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Vu();this.factories=new Map([["choice",Qe]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new _r;this.graph=null;this.lastFrame=null;this.appState=0;this.state={prevChapter$:new j(null),isInitialChapter$:new j(!1),isFirstChapter$:new j(!0),isEndChapter$:new j(!1),isInteractiveExpectation$:new j(!1),isReplay$:new j(!1),calledByInteractive$:new j(!1),lastChapterChangeWasInitiatedByInteractive$:new j(!1),disabledControls$:new j(!1),interactiveRanges$:new j([]),isInteractiveTime$:new j(!1),statistics$:new j(null),isSeekable$:new j(!1)};this.events={noInteraction$:new L,graphVisibilityChanged$:new L,watchAgainIsClicked$:new L,chapterChanged$:new L,playerChanged$:new L,error$:new L,eachTick$:new L,manifestChanged$:new L,interactiveRangeEnded$:new L,interactiveContainerRemoved$:new L,interactiveContainerFakeRemoved$:new L,interactiveActionExecution$:new L,interactiveActionChoice$:new L,interactiveVisibilityChanged$:new L};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(x.errors,e)};this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),r=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&z(n)&&!r&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:r,...n}=e;if(r){let{statSubscription:i,oneStat:s}=r;i.add(s.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(r)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(x.playerChanged,n)};this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(r=>{!e&&r.isPermanentText||(this.animation.removeFn(r.whilePlaying),r.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:r}=this.state,i=r.getValue().map(s=>({...s,subjects:s.subjects.filter(c=>c.id!==e)}));r.next(i)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};this._options={...sa,...e,config:{...sa.config,...e.config}},this._options.parentElement.append(this.rootElement),this.historyController=new _e({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new wt({parentElement:this._options.parentElement,onError:n=>{let i=new M(1,6,n);this.emitErrorEvent(i)}})),ra(this._options.parentElement),this.subscriptions.add(ia(this.rootElement,"mousedown").subscribe(n=>n.stopPropagation())).add(ia(this.rootElement,"mouseup").subscribe(n=>n.stopPropagation())),this.manifestController=new de(this._options.loaders,n=>{let i=new M(1,3,n);this.emitErrorEvent(i)});let r=[];this._options.lastFrame&&r.push(()=>{this.lastFrame?.updateCanvasDimensions(!0)}),r.push(()=>{let n=this.state.isInteractiveTime$.getValue();for(let i of this.gameControllers)i.onResize(n)}),this.resizeManager=Do(()=>({player:this.player,parentElement:this._options.parentElement,fns:r})),this._options.graph&&(this.graph=new Oe({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),this.globalEventEmitter.emit(x.graph,{type:Le.watchAgainClicked,chapterId:n}),this.events.watchAgainIsClicked$.next(n)},onError:n=>{let i=new M(1,2,{message:n});this.emitErrorEvent(i)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:r})=>{this.handleFakeRemoval(e,r)})).add(this.events.interactiveActionExecution$.subscribe(e=>{if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour==="change-chapter"){let{chapterId:r}=e.payload;this.setChapter({chapterId:r}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(e.payload?.behaviour==="change-manifest"){let{manifestURL:r}=e.payload;r&&this.setManifest(r)}e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:r,payload:n})=>{e!=="action-choice"||r==="chapter"||"invokeImmediately"in n&&n.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=Or(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let r=e*1e3,i=this.getInteractiveRanges().reverse().find(({range:s})=>r>=s[1]);if(i){let s=i.range.join("-");this.endedRanges.has(s)||(this.endedRanges.add(s),this.globalEventEmitter.emit(x.interactives,{type:O.rangeEnded,payload:i,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:i}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Pu()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Ru({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:r,isInteractiveExpectation:n})=>{let i;if(n)i=!0;else{let a=e*1e3;i=!!r.find(({range:[d,m],subjects:f})=>d<a&&a<m&&f.some(y=>!y.isRemoved)&&f.length)}i!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(i);let s=!!this.noInteractionTimeout,o=this.player?.info.playbackState$.getValue()==="playing"||n;i&&!s&&o?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):s&&!o&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(r=>r.container.container).filter(r=>!he(r.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let r=[];return e.containers.forEach(n=>{let i=n.type.trim().toLowerCase(),c=this.factories.get(i)?.(n,this.rootElement);if(c&&this.selectBranches&&this.interactiveEvents&&this.player){let o=new It({player:this.player,container:c,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>ps(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)}});this.animation.addFn(o.whilePlaying,!0),r.push(o)}}),r}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let r=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!r||!n&&r)&&this.state.isSeekable$.next(!r)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let r=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),i=(n&&z(n)&&Ct(n))??!1,s=this.manifestController.manifest?.metadata.initChapterId===e,c=this.historyController.state.history$.getValue();if(s||i&&r){this.historyController.updateHistory([e]);return}(0,oa.default)(c,-1)!==e&&this.historyController.updateHistory([...c,e])}handleFakeRemoval(e,r){let{interactiveRanges$:n}=this.state,s=n.getValue().map(c=>{let o=c.subjects.some(l=>l.id===e),a=c.subjects.map(l=>r&&o||l.id===e?{...l,isRemoved:!0}:l);return{...c,subjects:a}});n.next(s)}reset(){this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let r=await this.manifestController.setManifest(e);if(r.manifest)return this.graph&&this.graph.handleManifestChange(r.manifest),await this.historyController.setManifest(r.manifest),this.events.manifestChanged$.next(r.manifest),this.globalEventEmitter.emit(x.manifestChanged,{manifest:r.manifest}),this.setGameControllers(),r.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Fo(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=Zo({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:r=!0,playPrev:n=!1}={}){this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&ku.browser.isSafari&&await ta(35);let i=!n&&this.state.isEndChapter$.getValue()&&this.getCurrentManifest()?.metadata.initChapterId===e;this.state.isReplay$.next(i);let{chapter:s,media:c,graph:o}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||i)&&this.state.isFirstChapter$.next(!0),!(!s||!c)&&(r&&this.pushChapterToHistory(s.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(s),this.lastFrame?.setCurrentChapter(s),this.events.chapterChanged$.next({chapter:s,manifestVideo:c}),this.globalEventEmitter.emit(x.chapterChanged,{chapter:s,media:c,graph:o}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new na(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(r=>{e.next(r?Fe.GRAPH_SHOW:Fe.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(Fe.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:r,subjectName:n,subjectType:i})=>{r!=="action-choice"||n!=="control"||(i==="Button"&&e.next(Fe.NEXT_BUTTON),i==="Area"&&e.next(Fe.NEXT_AREA))}))}),nextMovie$:new na(e=>{this.events.playerChanged$.subscribe(({config:r})=>{r?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(r.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(x.graph,{type:Le.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(n=>n.actionType===w.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(r=>!r.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),r=this.player.info.duration$.getValue();return e===r&&this.gameControllers.some(n=>{let i=n.container.container;return!n.container.isRemoved&&i.endTime===null&&ee(i.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&lt(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return to(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,r){return this.globalEventEmitter.on(e,r),this}off(e,r){return this.globalEventEmitter.off(e,r),this}once(e,r){return this.globalEventEmitter.once(e,r),this}destroy(){this.clearHistoryIfEnded(),this.destroyGameControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Mu={Container:ne,createChoiceContainer:Qe,createAreaControl:ze,createButtonControl:Ke,classnamesPrefix:Hr};var ay={version:Br};export{om as ContainerTypes,pt as ControlTypes,M as CustomError,x as EVENT_NAMES,w as EventActionTypes,am as EventTypes,At as Interactives,de as ManifestController,ay as SDKInfo,Lr as chapterIdsToVKVideoIds,br as compareVersions,em as containerTypes,tm as controlTypes,is as eventActionTypes,rm as eventTypes,xu as getChapterIdByVkVideoId,Jo as getVKVideoIdByMedia,Iu as getVideoRawIdByMedia,Le as graphEventTypes,Ct as hasEndTemplate,O as interactivesEventTypes,Jd as isAreaControl,Zd as isButtonControl,z as isLastChapter,he as isOneTextCtrlContainer,lt as isSupportedManifest,ct as isTextControl,Tu as isVKVariantItem,ns as isValidManifest,ss as migrateManifestToLatestVersion,Mu as utils,ea as vkVideoIdsToChapterIds};