@vkontakte/videoplayer-interactive 1.0.31-dev.ea31bb81.0 → 1.0.31

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.31-dev.ea31bb81.0
3
- * Thu, 13 Feb 2025 15:09:27 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.31
3
+ * Wed, 12 Feb 2025 12:44:43 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- var to=Object.create;var _r=Object.defineProperty;var ro=Object.getOwnPropertyDescriptor;var no=Object.getOwnPropertyNames;var io=Object.getPrototypeOf,so=Object.prototype.hasOwnProperty;var c=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ao=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of no(e))!so.call(t,i)&&i!==r&&_r(t,i,{get:()=>e[i],enumerable:!(n=ro(e,i))||n.enumerable});return t};var W=(t,e,r)=>(r=t!=null?to(io(t)):{},ao(e||!t||!t.__esModule?_r(r,"default",{value:t,enumerable:!0}):r,t));var G=c((Lt,Ur)=>{"use strict";var de=function(t){return t&&t.Math===Math&&t};Ur.exports=de(typeof globalThis=="object"&&globalThis)||de(typeof window=="object"&&window)||de(typeof self=="object"&&self)||de(typeof global=="object"&&global)||de(typeof Lt=="object"&&Lt)||function(){return this}()||Function("return this")()});var N=c((fh,zr)=>{"use strict";zr.exports=function(t){try{return!!t()}catch{return!0}}});var fe=c((mh,Wr)=>{"use strict";var lo=N();Wr.exports=!lo(function(){var t=function(){}.bind();return typeof t!="function"||t.hasOwnProperty("prototype")})});var Zr=c((yh,Xr)=>{"use strict";var co=fe(),Yr=Function.prototype,Kr=Yr.apply,Qr=Yr.call;Xr.exports=typeof Reflect=="object"&&Reflect.apply||(co?Qr.bind(Kr):function(){return Qr.apply(Kr,arguments)})});var D=c((vh,tn)=>{"use strict";var Jr=fe(),en=Function.prototype,$t=en.call,uo=Jr&&en.bind.bind($t,$t);tn.exports=Jr?uo:function(t){return function(){return $t.apply(t,arguments)}}});var me=c((bh,nn)=>{"use strict";var rn=D(),po=rn({}.toString),ho=rn("".slice);nn.exports=function(t){return ho(po(t),8,-1)}});var Nt=c((gh,sn)=>{"use strict";var fo=me(),mo=D();sn.exports=function(t){if(fo(t)==="Function")return mo(t)}});var _=c((Ch,an)=>{"use strict";var _t=typeof document=="object"&&document.all;an.exports=typeof _t>"u"&&_t!==void 0?function(t){return typeof t=="function"||t===_t}:function(t){return typeof t=="function"}});var Y=c((Eh,on)=>{"use strict";var yo=N();on.exports=!yo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Ye=c((Ih,ln)=>{"use strict";var vo=fe(),Qe=Function.prototype.call;ln.exports=vo?Qe.bind(Qe):function(){return Qe.apply(Qe,arguments)}});var Ft=c(pn=>{"use strict";var cn={}.propertyIsEnumerable,un=Object.getOwnPropertyDescriptor,bo=un&&!cn.call({1:2},1);pn.f=bo?function(e){var r=un(this,e);return!!r&&r.enumerable}:cn});var qt=c((Th,hn)=>{"use strict";hn.exports=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}});var fn=c((Sh,dn)=>{"use strict";var go=D(),Co=N(),Eo=me(),Bt=Object,Io=go("".split);dn.exports=Co(function(){return!Bt("z").propertyIsEnumerable(0)})?function(t){return Eo(t)==="String"?Io(t,""):Bt(t)}:Bt});var Dt=c((wh,mn)=>{"use strict";mn.exports=function(t){return t==null}});var Ht=c((Ah,yn)=>{"use strict";var xo=Dt(),To=TypeError;yn.exports=function(t){if(xo(t))throw new To("Can't call method on "+t);return t}});var ye=c((Rh,vn)=>{"use strict";var So=fn(),wo=Ht();vn.exports=function(t){return So(wo(t))}});var ie=c((Ph,bn)=>{"use strict";var Ao=_();bn.exports=function(t){return typeof t=="object"?t!==null:Ao(t)}});var Xe=c((Oh,gn)=>{"use strict";gn.exports={}});var Ze=c((kh,En)=>{"use strict";var Gt=Xe(),Ut=G(),Ro=_(),Cn=function(t){return Ro(t)?t:void 0};En.exports=function(t,e){return arguments.length<2?Cn(Gt[t])||Cn(Ut[t]):Gt[t]&&Gt[t][e]||Ut[t]&&Ut[t][e]}});var xn=c((Mh,In)=>{"use strict";var Po=D();In.exports=Po({}.isPrototypeOf)});var An=c((Vh,wn)=>{"use strict";var Oo=G(),Tn=Oo.navigator,Sn=Tn&&Tn.userAgent;wn.exports=Sn?String(Sn):""});var jn=c((jh,Vn)=>{"use strict";var Mn=G(),zt=An(),Rn=Mn.process,Pn=Mn.Deno,On=Rn&&Rn.versions||Pn&&Pn.version,kn=On&&On.v8,H,Je;kn&&(H=kn.split("."),Je=H[0]>0&&H[0]<4?1:+(H[0]+H[1]));!Je&&zt&&(H=zt.match(/Edge\/(\d+)/),(!H||H[1]>=74)&&(H=zt.match(/Chrome\/(\d+)/),H&&(Je=+H[1])));Vn.exports=Je});var Wt=c((Lh,$n)=>{"use strict";var Ln=jn(),ko=N(),Mo=G(),Vo=Mo.String;$n.exports=!!Object.getOwnPropertySymbols&&!ko(function(){var t=Symbol("symbol detection");return!Vo(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&Ln&&Ln<41})});var Kt=c(($h,Nn)=>{"use strict";var jo=Wt();Nn.exports=jo&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Qt=c((Nh,_n)=>{"use strict";var Lo=Ze(),$o=_(),No=xn(),_o=Kt(),Fo=Object;_n.exports=_o?function(t){return typeof t=="symbol"}:function(t){var e=Lo("Symbol");return $o(e)&&No(e.prototype,Fo(t))}});var qn=c((_h,Fn)=>{"use strict";var qo=String;Fn.exports=function(t){try{return qo(t)}catch{return"Object"}}});var Yt=c((Fh,Bn)=>{"use strict";var Bo=_(),Do=qn(),Ho=TypeError;Bn.exports=function(t){if(Bo(t))return t;throw new Ho(Do(t)+" is not a function")}});var Hn=c((qh,Dn)=>{"use strict";var Go=Yt(),Uo=Dt();Dn.exports=function(t,e){var r=t[e];return Uo(r)?void 0:Go(r)}});var Un=c((Bh,Gn)=>{"use strict";var Xt=Ye(),Zt=_(),Jt=ie(),zo=TypeError;Gn.exports=function(t,e){var r,n;if(e==="string"&&Zt(r=t.toString)&&!Jt(n=Xt(r,t))||Zt(r=t.valueOf)&&!Jt(n=Xt(r,t))||e!=="string"&&Zt(r=t.toString)&&!Jt(n=Xt(r,t)))return n;throw new zo("Can't convert object to primitive value")}});var Wn=c((Dh,zn)=>{"use strict";zn.exports=!0});var Yn=c((Hh,Qn)=>{"use strict";var Kn=G(),Wo=Object.defineProperty;Qn.exports=function(t,e){try{Wo(Kn,t,{value:e,configurable:!0,writable:!0})}catch{Kn[t]=e}return e}});var et=c((Gh,Jn)=>{"use strict";var Ko=Wn(),Qo=G(),Yo=Yn(),Xn="__core-js_shared__",Zn=Jn.exports=Qo[Xn]||Yo(Xn,{});(Zn.versions||(Zn.versions=[])).push({version:"3.38.0",mode:Ko?"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 er=c((Uh,ti)=>{"use strict";var ei=et();ti.exports=function(t,e){return ei[t]||(ei[t]=e||{})}});var ve=c((zh,ri)=>{"use strict";var Xo=Ht(),Zo=Object;ri.exports=function(t){return Zo(Xo(t))}});var se=c((Wh,ni)=>{"use strict";var Jo=D(),el=ve(),tl=Jo({}.hasOwnProperty);ni.exports=Object.hasOwn||function(e,r){return tl(el(e),r)}});var tr=c((Kh,ii)=>{"use strict";var rl=D(),nl=0,il=Math.random(),sl=rl(1 .toString);ii.exports=function(t){return"Symbol("+(t===void 0?"":t)+")_"+sl(++nl+il,36)}});var be=c((Qh,ai)=>{"use strict";var al=G(),ol=er(),si=se(),ll=tr(),cl=Wt(),ul=Kt(),ae=al.Symbol,rr=ol("wks"),pl=ul?ae.for||ae:ae&&ae.withoutSetter||ll;ai.exports=function(t){return si(rr,t)||(rr[t]=cl&&si(ae,t)?ae[t]:pl("Symbol."+t)),rr[t]}});var ui=c((Yh,ci)=>{"use strict";var hl=Ye(),oi=ie(),li=Qt(),dl=Hn(),fl=Un(),ml=be(),yl=TypeError,vl=ml("toPrimitive");ci.exports=function(t,e){if(!oi(t)||li(t))return t;var r=dl(t,vl),n;if(r){if(e===void 0&&(e="default"),n=hl(r,t,e),!oi(n)||li(n))return n;throw new yl("Can't convert object to primitive value")}return e===void 0&&(e="number"),fl(t,e)}});var nr=c((Xh,pi)=>{"use strict";var bl=ui(),gl=Qt();pi.exports=function(t){var e=bl(t,"string");return gl(e)?e:e+""}});var fi=c((Zh,di)=>{"use strict";var Cl=G(),hi=ie(),ir=Cl.document,El=hi(ir)&&hi(ir.createElement);di.exports=function(t){return El?ir.createElement(t):{}}});var sr=c((Jh,mi)=>{"use strict";var Il=Y(),xl=N(),Tl=fi();mi.exports=!Il&&!xl(function(){return Object.defineProperty(Tl("div"),"a",{get:function(){return 7}}).a!==7})});var bi=c(vi=>{"use strict";var Sl=Y(),wl=Ye(),Al=Ft(),Rl=qt(),Pl=ye(),Ol=nr(),kl=se(),Ml=sr(),yi=Object.getOwnPropertyDescriptor;vi.f=Sl?yi:function(e,r){if(e=Pl(e),r=Ol(r),Ml)try{return yi(e,r)}catch{}if(kl(e,r))return Rl(!wl(Al.f,e,r),e[r])}});var Ci=c((td,gi)=>{"use strict";var Vl=N(),jl=_(),Ll=/#|\.prototype\./,ge=function(t,e){var r=Nl[$l(t)];return r===Fl?!0:r===_l?!1:jl(e)?Vl(e):!!e},$l=ge.normalize=function(t){return String(t).replace(Ll,".").toLowerCase()},Nl=ge.data={},_l=ge.NATIVE="N",Fl=ge.POLYFILL="P";gi.exports=ge});var ar=c((rd,Ii)=>{"use strict";var Ei=Nt(),ql=Yt(),Bl=fe(),Dl=Ei(Ei.bind);Ii.exports=function(t,e){return ql(t),e===void 0?t:Bl?Dl(t,e):function(){return t.apply(e,arguments)}}});var Ti=c((nd,xi)=>{"use strict";var Hl=Y(),Gl=N();xi.exports=Hl&&Gl(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var wi=c((id,Si)=>{"use strict";var Ul=ie(),zl=String,Wl=TypeError;Si.exports=function(t){if(Ul(t))return t;throw new Wl(zl(t)+" is not an object")}});var Pi=c(Ri=>{"use strict";var Kl=Y(),Ql=sr(),Yl=Ti(),tt=wi(),Ai=nr(),Xl=TypeError,or=Object.defineProperty,Zl=Object.getOwnPropertyDescriptor,lr="enumerable",cr="configurable",ur="writable";Ri.f=Kl?Yl?function(e,r,n){if(tt(e),r=Ai(r),tt(n),typeof e=="function"&&r==="prototype"&&"value"in n&&ur in n&&!n[ur]){var i=Zl(e,r);i&&i[ur]&&(e[r]=n.value,n={configurable:cr in n?n[cr]:i[cr],enumerable:lr in n?n[lr]:i[lr],writable:!1})}return or(e,r,n)}:or:function(e,r,n){if(tt(e),r=Ai(r),tt(n),Ql)try{return or(e,r,n)}catch{}if("get"in n||"set"in n)throw new Xl("Accessors not supported");return"value"in n&&(e[r]=n.value),e}});var ki=c((ad,Oi)=>{"use strict";var Jl=Y(),ec=Pi(),tc=qt();Oi.exports=Jl?function(t,e,r){return ec.f(t,e,tc(1,r))}:function(t,e,r){return t[e]=r,t}});var Ee=c((od,Vi)=>{"use strict";var Ce=G(),rc=Zr(),nc=Nt(),ic=_(),sc=bi().f,ac=Ci(),oe=Xe(),oc=ar(),le=ki(),Mi=se();et();var lc=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 rc(t,this,arguments)};return e.prototype=t.prototype,e};Vi.exports=function(t,e){var r=t.target,n=t.global,i=t.stat,s=t.proto,l=n?Ce:i?Ce[r]:Ce[r]&&Ce[r].prototype,a=n?oe:oe[r]||le(oe,r,{})[r],o=a.prototype,p,f,y,m,b,P,O,x,w;for(m in e)p=ac(n?m:r+(i?".":"#")+m,t.forced),f=!p&&l&&Mi(l,m),P=a[m],f&&(t.dontCallGetSet?(w=sc(l,m),O=w&&w.value):O=l[m]),b=f&&O?O:e[m],!(!p&&!s&&typeof P==typeof b)&&(t.bind&&f?x=oc(b,Ce):t.wrap&&f?x=lc(b):s&&ic(b)?x=nc(b):x=b,(t.sham||b&&b.sham||P&&P.sham)&&le(x,"sham",!0),le(a,m,x),s&&(y=r+"Prototype",Mi(oe,y)||le(oe,y,{}),le(oe[y],m,b),t.real&&o&&(p||!o[m])&&le(o,m,b)))}});var Li=c((ld,ji)=>{"use strict";var cc=Math.ceil,uc=Math.floor;ji.exports=Math.trunc||function(e){var r=+e;return(r>0?uc:cc)(r)}});var Ie=c((cd,$i)=>{"use strict";var pc=Li();$i.exports=function(t){var e=+t;return e!==e||e===0?0:pc(e)}});var _i=c((ud,Ni)=>{"use strict";var hc=Ie(),dc=Math.min;Ni.exports=function(t){var e=hc(t);return e>0?dc(e,9007199254740991):0}});var xe=c((pd,Fi)=>{"use strict";var fc=_i();Fi.exports=function(t){return fc(t.length)}});var rt=c((hd,qi)=>{"use strict";qi.exports=function(){}});var Bi=c(()=>{"use strict";var mc=Ee(),yc=ve(),vc=xe(),bc=Ie(),gc=rt();mc({target:"Array",proto:!0},{at:function(e){var r=yc(this),n=vc(r),i=bc(e),s=i>=0?i:n+i;return s<0||s>=n?void 0:r[s]}});gc("at")});var nt=c((md,Di)=>{"use strict";var Cc=Ze();Di.exports=Cc});var Gi=c((yd,Hi)=>{"use strict";Bi();var Ec=nt();Hi.exports=Ec("Array","at")});var zi=c((vd,Ui)=>{"use strict";var Ic=Gi();Ui.exports=Ic});var pr=c((bd,Wi)=>{"use strict";var xc=zi();Wi.exports=xc});var ls=c((kf,os)=>{"use strict";var Vc=er(),jc=tr(),as=Vc("keys");os.exports=function(t){return as[t]||(as[t]=jc(t))}});var us=c((Mf,cs)=>{"use strict";var Lc=N();cs.exports=!Lc(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})});var ds=c((Vf,hs)=>{"use strict";var $c=se(),Nc=_(),_c=ve(),Fc=ls(),qc=us(),ps=Fc("IE_PROTO"),Er=Object,Bc=Er.prototype;hs.exports=qc?Er.getPrototypeOf:function(t){var e=_c(t);if($c(e,ps))return e[ps];var r=e.constructor;return Nc(r)&&e instanceof r?r.prototype:e instanceof Er?Bc:null}});var ms=c((jf,fs)=>{"use strict";var Dc=Ie(),Hc=Math.max,Gc=Math.min;fs.exports=function(t,e){var r=Dc(t);return r<0?Hc(r+e,0):Gc(r,e)}});var Ir=c((Lf,vs)=>{"use strict";var Uc=ye(),zc=ms(),Wc=xe(),ys=function(t){return function(e,r,n){var i=Uc(e),s=Wc(i);if(s===0)return!t&&-1;var l=zc(n,s),a;if(t&&r!==r){for(;s>l;)if(a=i[l++],a!==a)return!0}else for(;s>l;l++)if((t||l in i)&&i[l]===r)return t||l||0;return!t&&-1}};vs.exports={includes:ys(!0),indexOf:ys(!1)}});var gs=c(($f,bs)=>{"use strict";bs.exports={}});var Is=c((Nf,Es)=>{"use strict";var Kc=D(),xr=se(),Qc=ye(),Yc=Ir().indexOf,Xc=gs(),Cs=Kc([].push);Es.exports=function(t,e){var r=Qc(t),n=0,i=[],s;for(s in r)!xr(Xc,s)&&xr(r,s)&&Cs(i,s);for(;e.length>n;)xr(r,s=e[n++])&&(~Yc(i,s)||Cs(i,s));return i}});var Ts=c((_f,xs)=>{"use strict";xs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var ws=c((Ff,Ss)=>{"use strict";var Zc=Is(),Jc=Ts();Ss.exports=Object.keys||function(e){return Zc(e,Jc)}});var Ms=c((qf,ks)=>{"use strict";var Rs=Y(),eu=N(),Ps=D(),tu=ds(),ru=ws(),nu=ye(),iu=Ft().f,Os=Ps(iu),su=Ps([].push),au=Rs&&eu(function(){var t=Object.create(null);return t[2]=2,!Os(t,2)}),As=function(t){return function(e){for(var r=nu(e),n=ru(r),i=au&&tu(r)===null,s=n.length,l=0,a=[],o;s>l;)o=n[l++],(!Rs||(i?o in r:Os(r,o)))&&su(a,t?[o,r[o]]:r[o]);return a}};ks.exports={entries:As(!0),values:As(!1)}});var Vs=c(()=>{"use strict";var ou=Ee(),lu=Ms().values;ou({target:"Object",stat:!0},{values:function(e){return lu(e)}})});var Ls=c((Hf,js)=>{"use strict";Vs();var cu=Xe();js.exports=cu.Object.values});var Ns=c((Gf,$s)=>{"use strict";var uu=Ls();$s.exports=uu});var gt=c((Uf,_s)=>{"use strict";var pu=Ns();_s.exports=pu});var Bs=c(()=>{"use strict";var hu=Ee(),du=Ir().includes,fu=N(),mu=rt(),yu=fu(function(){return!Array(1).includes()});hu({target:"Array",proto:!0,forced:yu},{includes:function(e){return du(this,e,arguments.length>1?arguments[1]:void 0)}});mu("includes")});var Hs=c((Yf,Ds)=>{"use strict";Bs();var vu=nt();Ds.exports=vu("Array","includes")});var Us=c((Xf,Gs)=>{"use strict";var bu=Hs();Gs.exports=bu});var Ct=c((Zf,zs)=>{"use strict";var gu=Us();zs.exports=gu});var Rr=c((ym,Xs)=>{"use strict";var Su=me();Xs.exports=Array.isArray||function(e){return Su(e)==="Array"}});var Js=c((vm,Zs)=>{"use strict";var wu=TypeError,Au=9007199254740991;Zs.exports=function(t){if(t>Au)throw wu("Maximum allowed index exceeded");return t}});var ra=c((bm,ta)=>{"use strict";var Ru=Rr(),Pu=xe(),Ou=Js(),ku=ar(),ea=function(t,e,r,n,i,s,l,a){for(var o=i,p=0,f=l?ku(l,a):!1,y,m;p<n;)p in r&&(y=f?f(r[p],p,e):r[p],s>0&&Ru(y)?(m=Pu(y),o=ea(t,e,y,m,o,s-1)-1):(Ou(o+1),t[o]=y),o++),p++;return o};ta.exports=ea});var sa=c((gm,ia)=>{"use strict";var Mu=be(),Vu=Mu("toStringTag"),na={};na[Vu]="z";ia.exports=String(na)==="[object z]"});var oa=c((Cm,aa)=>{"use strict";var ju=sa(),Lu=_(),It=me(),$u=be(),Nu=$u("toStringTag"),_u=Object,Fu=It(function(){return arguments}())==="Arguments",qu=function(t,e){try{return t[e]}catch{}};aa.exports=ju?It:function(t){var e,r,n;return t===void 0?"Undefined":t===null?"Null":typeof(r=qu(e=_u(t),Nu))=="string"?r:Fu?It(e):(n=It(e))==="Object"&&Lu(e.callee)?"Arguments":n}});var ca=c((Em,la)=>{"use strict";var Bu=D(),Du=_(),Pr=et(),Hu=Bu(Function.toString);Du(Pr.inspectSource)||(Pr.inspectSource=function(t){return Hu(t)});la.exports=Pr.inspectSource});var ma=c((Im,fa)=>{"use strict";var Gu=D(),Uu=N(),ua=_(),zu=oa(),Wu=Ze(),Ku=ca(),pa=function(){},ha=Wu("Reflect","construct"),Or=/^\s*(?:class|function)\b/,Qu=Gu(Or.exec),Yu=!Or.test(pa),je=function(e){if(!ua(e))return!1;try{return ha(pa,[],e),!0}catch{return!1}},da=function(e){if(!ua(e))return!1;switch(zu(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Yu||!!Qu(Or,Ku(e))}catch{return!0}};da.sham=!0;fa.exports=!ha||Uu(function(){var t;return je(je.call)||!je(Object)||!je(function(){t=!0})||t})?da:je});var ga=c((xm,ba)=>{"use strict";var ya=Rr(),Xu=ma(),Zu=ie(),Ju=be(),ep=Ju("species"),va=Array;ba.exports=function(t){var e;return ya(t)&&(e=t.constructor,Xu(e)&&(e===va||ya(e.prototype))?e=void 0:Zu(e)&&(e=e[ep],e===null&&(e=void 0))),e===void 0?va:e}});var Ea=c((Tm,Ca)=>{"use strict";var tp=ga();Ca.exports=function(t,e){return new(tp(t))(e===0?0:e)}});var Ia=c(()=>{"use strict";var rp=Ee(),np=ra(),ip=ve(),sp=xe(),ap=Ie(),op=Ea();rp({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,r=ip(this),n=sp(r),i=op(r,0);return i.length=np(i,r,r,n,0,e===void 0?1:ap(e)),i}})});var xa=c(()=>{"use strict";var lp=rt();lp("flat")});var Sa=c((Pm,Ta)=>{"use strict";Ia();xa();var cp=nt();Ta.exports=cp("Array","flat")});var Aa=c((Om,wa)=>{"use strict";var up=Sa();wa.exports=up});var Pa=c((km,Ra)=>{"use strict";var pp=Aa();Ra.exports=pp});var Fr="1.0.31-dev.ea31bb81.0";function Rt(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 j="interactive",oo="interactive-controls-container",Fe=()=>document.querySelector(`.${oo}`),qr=.4,V={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Br=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(Br||{}),Dr=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(Dr||{}),Hr=(n=>(n.start="left",n.end="right",n.center="center",n))(Hr||{}),qe=({target:t,props:e})=>{t.style.alignItems=(e?.gravityVertical&&Br[e.gravityVertical])??"center",t.style.justifyContent=(e?.gravityHorizontal&&Dr[e.gravityHorizontal])??"center",t.style.textAlign=(e?.alignment&&Hr[e.alignment])??"center"},Be=({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},De=({target:t,props:e,fallback:r})=>{t.style.backgroundColor=Rt(e?.background?.color??r.backgroundColor,e?.background?.alpha??r.backgroundAlpha)},He=({target:t,props:e,fallback:r,dependsOn:n})=>{t.style.border=`calc(${n.height} * ${e?.shape?.border?.width??r.borderWidth}) solid ${Rt(e?.shape?.border?.color??r.borderColor,e?.shape?.border?.alpha??r.borderAlpha)}`,t.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??r.roundCorners})`},re=({target:t,layoutParams:e,fallback:r})=>{let n=e.angle??r.angle;n=n&&n*-1,t.style.transform=`rotate(${n}rad)`};var K=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let r=document.createElement("div");r.classList.add(`${j}-control-container-${this.control.id}`),e(r,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??V.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()}}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 Pt="int",Q=(n=>(n.AREA=`${Pt}_area`,n.TEXT=`${Pt}_text`,n.BUTTON=`${Pt}_bttn`,n))(Q||{});var Ge=t=>{if(t.type.trim().toLowerCase()==="area")return new Ot(t)},Ot=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${j}-${this.control.id}`),n.setAttribute("data-testid",Q.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",De({target:n,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),He({target:n,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:this.container.dimensions}),re({target:n,layoutParams:this.control.layoutParams,fallback:V}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Ue=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 ze=t=>{if(t.type.trim().toLowerCase()==="button")return new kt(t)},kt=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${j}-${this.control.id}`),n.setAttribute("data-testid",Q.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",re({target:n,layoutParams:this.control.layoutParams,fallback:V}),De({target:n,props:this.control.props,fallback:V}),He({target:n,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),qe({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=Ue(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;Be({target:s,props:this.control.props,fallback:V,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.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Gr=t=>{if(t.type.trim().toLowerCase()==="text")return new Mt(t)},Mt=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("div");n.classList.add(`${j}-${this.control.id}`),n.setAttribute("data-testid",Q.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",re({target:n,layoutParams:this.control.layoutParams,fallback:V}),qe({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=Ue(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;Be({target:s,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){}enable(){}getElement(){return this.controlElement}};var Vt=class{constructor(e){this.layout=e}},We=class extends Vt{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))`}};var ne=class{constructor(e){this.container=e,this.factories=new Map,this.controls=[],this.setControls()}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);if(s)return[...e,s]}return[...e]},[])||[]}};var Ke=(t,e)=>{if(t.type.trim().toLowerCase()==="choice")return new jt(t,e)},jt=class extends ne{constructor(e,r){super(e),this.rootElement=r??Fe(),this.layout=new We(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ze),this.addControlFactory("text",Gr),this.addControlFactory("area",Ge)}createView(e){let r=document.createElement("div");return r.classList.add(`${j}-${this.container.id}`),this.layout.setContainerLayout(r),this.controls.forEach(n=>{n.createView({parentElement:r,layoutCallback:this.layout.setControlLayout}),n.setEvents(e)}),this.rootElement.append(r),this.isRemoved=!1,r}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(r=>r.enable()),e.style.opacity="1",this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(r=>r.disable()),e.style.opacity=`${qr}`,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${j}-${this.container.id}`)}};var Ja=W(pr(),1);import{clientChecker as Ip,combine as xp,InterfaceLanguage as Tp,Observable as Ya,once as Sp,Subject as L,Subscription as $r,ValueSubject as $,fromEvent as Xa}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Ne}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Tc}from"@vkontakte/videoplayer-shared";function Te(t,e){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>t(...n),e)}}var X=(t,e)=>Object.prototype.toString.call(t)===`[object ${e}]`,Se=t=>X(t,"Object"),it=t=>X(t,"String"),st=t=>X(t,"Array"),at=t=>X(t,"Number"),Ki=t=>X(t,"Function");var hr=t=>at(t)&&!isNaN(t);var Z=t=>Se(t)&&Object.keys(t).length===0,dr=t=>st(t)&&!t.length;var we=(t,e)=>it(t)&&(e?t.trim():t).length;var Qi="video_interactive",Yi="videoint";var Xi=250,Ae=class{constructor(e){this.handleZoomChange=Te(e=>{this.lastZoomInfo=e},Xi);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?.("Id is not found"),console.error("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"),console.error("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=Sc(e),this.resizeObserver=new ResizeObserver(Te(this.onResize,Xi)),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 Tc(this.lang,Qi,Yi)}catch{console.log("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 Sc(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 Re=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 l=s.startTime-e;if(l<=i&&(s.endTime&&i<=s.endTime||s.endTime===null)){n=!0;break}i<l&&(r=r===-1?l:Math.min(r,l))}return!n&&r!==-1?r:null}}};import{isSupportedManifest as lt,ContainerTypes as Gd,ControlTypes as ct,EventActionTypes as T,EventTypes as Ud,migrateManifestToLatestVersion as es,compareVersions as zd}from"@interactiveplatform/movika-manifest";var Zi={metadata:"Object",chapters:"Array"},Ji=t=>{if(!Se(t))return!1;for(let e in Zi)if(!t[e]||!X(t[e],Zi[e]))return!1;return lt(t.metadata.version)},ot=t=>t.type===ct.Text,Ld=t=>t.type===ct.Button,$d=t=>t.type===ct.Area,Nd={Choice:"Choice",TextInput:"TextInput"},_d={Button:"Button",Area:"Area",Text:"Text"},Fd={onClick:"onClick",onSuspense:"onSuspense"},qd={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 pt=class{constructor(e){this.fns=[];this.addFn=(e,r=!1)=>{Ki(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 Mc}from"@vkontakte/videoplayer-shared";var ht=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,r){return wc(...this.loaders[e])(r)}};function wc(...t){return async function(r){let n=[...t];for(;n.length>0;)r=await n.shift()(r);return r}}function Pe(t,e,r){return t?{...t,[e]:t[e]?[r,...t[e]]:[r]}:{[e]:[r]}}function dt({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 l=t.getMedia(i.media,s.videoId),a=t.getGraph(i.graph,s.id);return l?{...n,actions:t,errors:e,result:{chapter:s,media:l,graph:a}}:{...n,errors:Pe(e,dt.name,"Could not find media"),actions:t}}}}return{...n,errors:Pe(e,dt.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 l=n[i];try{l.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},ce=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)}},Oe=class{constructor(){Object.defineProperty(this,"signal",{value:new ce,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&&(Oe.prototype[Symbol.toStringTag]="AbortController",ce.prototype[Symbol.toStringTag]="AbortSignal");function mt(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 fr(t){typeof t=="function"&&(t={fetch:t});let{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!mt({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(p,f){let y;f&&f.signal&&(y=f.signal,delete f.signal);let m=new r(p,f);return y&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:y}),m},s.prototype=r.prototype);let l=e;return{fetch:(o,p)=>{let f=s&&s.prototype.isPrototypeOf(o)?o.signal:p?p.signal:void 0;if(f){let y;try{y=new DOMException("Aborted","AbortError")}catch{y=new Error("Aborted"),y.name="AbortError"}if(f.aborted)return Promise.reject(y);let m=new Promise((b,P)=>{f.addEventListener("abort",()=>P(y),{once:!0})});return p&&p.signal&&delete p.signal,Promise.race([m,l(o,p)])}return l(o,p)},Request:s}}var ke=mt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),ts=ke?fr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,mr=ke?ts.fetch:window.fetch,pf=ke?ts.Request:window.Request,hf=ke?Oe:window.AbortController,df=ke?ce:window.AbortSignal;var yr=(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 Ac=async t=>{try{let e={},r;if(it(t)){r=new URL(t).href;let i=await mr(r);if(!i.ok)return{};e=await i.json()}else if(Se(t))e=t;else return{};if(!Ji(e))return{};let n=e.metadata.media;if(it(n)&&!("media"in e))try{let i;r?i=new URL(n,r).href:(i=new URL(n).href,r=i);let s=await mr(i);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return Oc(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:r}}catch{return{}}};async function rs(t){let{manifest:e,manifestURL:r}=await Ac(t);if(!e)throw new Error("Failed on fetch");let n=es(e);return n.media=Rc(n.media,r),delete n.metadata.media,n}function yt(t,e){if(e)return t.find(r=>r.id===e)}function vr(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 br(t,e){return t.videos.find(r=>r.id===e)}function Rc(t,e){return{...t,videos:t.videos.map(r=>({...r,variants:r.variants.map(n=>{let i="url"in n?n.url:"",s=Pc(i,e);return{...n,url:s||i}})}))}}function Pc(t="",e){try{return new URL(t,e).href}catch{return""}}function Oc(t){return yr(t,"3.2.0")>=0}var vt=t=>st(t)&&!dr(t),U=t=>t.order==="end",bt=t=>st(t.containers)&&!dr(t.containers)&&U(t),ns=(t,e)=>{let r=t*1e3;return vt(e.controls)&&r<(e.startTime??0)},gr=(t,e)=>{let r=t*1e3;return vt(e.controls)&&r>=(e.startTime??0)&&r<=(e.endTime??1/0)};var J=(t=[])=>t.some(e=>e.action.type==="expect"),Cr=(t=[])=>t.find(e=>e.action.type==="expect"),kc=t=>t?.length===1,ue=t=>kc(t)&&ot(t[0]);function is(t,...e){return r=>typeof e[0]=="object"&&typeof r=="object"?t({...e[0],...r}):t(...e,...r)}var ss=(t,e)=>J(t.events)?!1:e.some(({container:r})=>r.container.id!==t.id&&J(r.container.events)&&r.container.endTime===t.endTime&&!r.isRemoved);var pe=class extends ht{constructor(r,n){super(r);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Mc(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:Pe},result:null,errors:null,source:r});return n.errors&&this.errorHandler(n.errors),this.manifest=await rs(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",dt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:vr,getChapter:yt,getMedia:br,getByBranches:this.getByBranches.bind(this),addErrorMessage:Pe},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=br(this.manifest.media,n.videoId),s=vr(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?U(this.chapter):!1}};var Ws=W(gt(),1);import{Player as Cu}from"@vkontakte/videoplayer-core";import{Subscription as wr,Tracer as Eu,ValueSubject as Iu}from"@vkontakte/videoplayer-shared";var Fs=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 qs=W(gt(),1);function Tr(){let t=new Map;function e({listId:s=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let o=t.get(s),p={...a};return o?o[l]=p:t.set(s,{[l]:p}),{listId:s,itemId:l,...a}}function r(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,l){let a=t.get(s);if(!a)throw Error("Can't remove. Not find.");if(l){let o=a[l];o&&r(o),delete a[l],Object.keys(a).length||t.delete(s)}else{for(let o of(0,qs.default)(a))r(o);t.delete(s)}}function i(){for(let s of t)n(s[0])}return{createPlayer:e,removePlayer:n,map:t,removeAll:i}}var he=W(Ct(),1);function Sr(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,he.default)(e,"mp4"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(i||(0,he.default)(e,"mpeg"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(i||(0,he.default)(e,"hls"))&&(r={...r,HLS:{type:"url",url:s.url}});break;case"dash":(i||(0,he.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 Me=(t,e)=>{let r=t.info.currentQuality$.getValue(),n=t.info.availableQualities$.getValue();r!==e&&(0,he.default)(n,e)&&(t.setQuality(e),t.setAutoQuality(!1))};var xu=2;function Ar(t){let e=Tr(),r=new wr,n={},i=null,s=!1,l,a=new Iu(null);t&&o(t);function o(x){i=x}function p(x,w,u){if(!i)throw Error("need to set interactive controller");if(!i.options)return;let d=(e.map.get(x)??{})[w];if(d){n={chapterId:u,listId:x,itemId:w,...d};let v=n.player;n.subscription.add(v.info.currentQuality$.subscribe(g=>{let C=v.info.position$.getValue(),S=v.info.isAutoQualityEnabled$.getValue();if(!(!g||!C||S))for(let R of e.map)(0,Ws.default)(R[1]).forEach(({player:I})=>{Me(I,g)})})).add(v.events.started$.subscribe(()=>{f(w)})),d.container.remove(),i.setPlayer(d.player),s||(i.init(),s=!0),a.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function f(x){if(!i)throw Error("need to set interactive controller");if(Z(n)||x!==n.itemId)return;let w=i.getChapterBranches(),u=new Set;for(let h of w)u.has(h.media.id)||(await m({media:h.media,chapterId:h.chapter.id,setAsActive:!1,title:h.chapter.label}),u.add(h.media.id))}async function y({chapter:{id:x},manifestVideo:w}){if(Z(n)||!i)return;let u=n.player.info.muted$.getValue(),h=n.player.info.currentQuality$.getValue(),d=n.player.info.isAutoQualityEnabled$.getValue(),v=n.player.info.volume$.getValue(),g=n.player.info.currentPlaybackRate$.getValue(),C=!d,S=!1;for(let R of e.map)if(R[0]===w.id&&!i.state.isReplay$.getValue()){let I=Object.keys(R[1]);for(let k of I)k===n.itemId?(I.length<xu||(S=!0),e.removePlayer(R[0],k)):(S=!0,p(R[0],k,x),C?Me(n.player,h):n.player.setAutoQuality(!0),n.player.setVolume(v),n.player.setMuted(u),n.player.setPlaybackRate(g))}else e.removePlayer(R[0]);S||(await m({media:w,chapterId:x,setAsActive:!0,playbackRate:g}),C?Me(n.player,h):n.player.setAutoQuality(!0),n.player.setVolume(v),n.player.setMuted(u))}async function m({media:x,chapterId:w,prefetch:u=!0,setAsActive:h=!0,autoplay:d=!1,preferredExt:v,title:g,playbackRate:C}){let S=Math.random().toString(),R=document.createElement("div");l.append(R);let I;if(i?.options?.vkVideoLoader){let _e=Fs(x);_e.length&&(I=await i.options.vkVideoLoader(..._e))}let k=i?.options?.coreConfig||void 0,F={...k,configName:[...k?.configName??[],"interactive"]},q={container:R,...I?.videos?.[0]||{sources:Sr(x,v).sources},title:g,failoverHosts:I?.failoverHosts||[]},B=new Cu(F,Eu.createRootTracer());B.initVideo(q);let z=null;if(I?.videos&&i?.options.createOneStat){let _e=I.videos[0],At=i.options.createOneStat(_e),Nr=new wr;At&&(Nr.add(At.attachTo(B)),z={oneStat:At,statSubscription:Nr})}let ee=new wr,eo=n?.player?.info.isAutoQualityEnabled$.getValue();ee.add(B.events.canplay$.subscribe(function(){eo||Me(B,n.player.info.currentQuality$.getValue()),C&&B.setPlaybackRate(C)}));let te=e.createPlayer({listId:x.id,itemId:S,player:B,container:R,sources:Sr(x,v).sources,config:q,subscription:ee,statistics:z});return h&&p(x.id,te.itemId,w),d&&te.player.play(),u&&!d&&te.player.prepare(),{player:te.player,config:te.config,statistics:te.statistics}}function b(){P(),i=null,l.remove()}function P(){r.unsubscribe(),e.removeAll(),n={},s=!1}async function O(){if(!i)throw Error("need to set interactive controller");P(),l=document.createElement("div");let{media:x,chapter:w}=i.getCurrentChapter();x&&w?(r.add(i.events.chapterChanged$.subscribe(y)),await m({media:x,chapterId:w.id,title:w.label})):console.error("not found")}return{...e,init:O,setInteractiveController:o,createPlayer:m,removeAll:b,getActivePlayer:function(){return n},activePlayerChanged:a}}var E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ve={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},A={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var Qs=W(Ct(),1);import{Subscription as Tu}from"@vkontakte/videoplayer-shared";var Et=class{constructor({player:e,container:r,branches:n,selectBranches:i,interactiveEvents:s,globalEvents:l,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:p,disabledControls$:f,onRemove:y}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(J(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())this.container.show?.(),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)=>{this.isSelectedControlEvent=!0,i!==!1&&(this.removeView(),this.emitContainerVisibilityEvent(!1)),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),s(),this.removeView(),this.emitContainerVisibilityEvent(!1))},isEOV:()=>this.gameState===4},n=is(this.selectBranches.onControlEvent,r);this.container.createView(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,Qs.default)(i,this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(ns(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(gr(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let p=this.gameState;this.gameState=3,p===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=gr(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(E.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=r,this.branches=n,this.selectBranches=i,this.subscription=new Tu,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=p&&ue(r.container.controls),this.disabledControls$=f,this.onRemove=y,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,r=!1){e?(this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.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(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.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){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,this.ignoreContainerEvent()||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 e=J(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}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 Ys=(t=[])=>t.reduce((e,r,n)=>{let i=(r?.controls??[]).filter(s=>!ot(s));if(vt(i)){let s=[r.startTime??0,r.endTime??1/0],l=r.id;if(!n)e.push({subjects:[l],range:s});else{let a=[],o=-1/0,p=1/0,f=[],y=[];for(let m=0;m<e.length;m++){let b=e[m];if(y.push(...b.subjects),b.range[0]<p&&(p=b.range[0]),b.range[1]>o&&(o=b.range[1]),s[0]>=b.range[0]&&s[1]<=b.range[1])return e[m].subjects.push(l),e;s[0]<b.range[0]&&s[1]>b.range[0]&&(a.push(m),f=f.concat(b.subjects)),s[0]>=b.range[0]&&s[0]<=b.range[1]&&(a.push(m),f=f.concat(b.subjects),s[0]=b.range[0]),s[1]>=b.range[0]&&s[1]<=b.range[1]&&(a.push(m),f=f.concat(b.subjects),s[1]=b.range[1])}if(y.push(l),s[0]<=p&&s[1]>=o)return[{subjects:y,range:s}];a.length&&a.reverse().forEach(m=>{e.splice(m,1)}),e.push({subjects:f.concat([l]),range:s})}}return e},[]).sort((e,r)=>e.range[0]-r.range[0]);var ka=W(Ct(),1),kr=W(gt(),1),Ma=W(Pa(),1);function Oa(){let t={};function e(){for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&delete t[a]}function r(a){let o={};for(let p in t)+p<=a&&(o[p]=t[p]);return o}function n(a){let o={};for(let p in t)+p>=a&&(o[p]=t[p]);return o}function i({timestamp:a,priority:o,initiator:p}){if(hr(a)){let f=t[a]??null;if(f&&o&&we(o,!0)){let y={},m=f[o];return m&&(y={...y,...m}),y=Z(y)?null:y,y&&we(p,!0)?y[p]??null:y}return f}return null}function s({timestamp:a,priority:o,initiator:p}){if(hr(a))if(t[a]){if(o&&we(o,!0))if(t[a][o]){if(p&&we(p,!0))if(t[a][o][p]){if(delete t[a][o][p],!Z(t[a][o]))return!0}else return!1;if(delete t[a][o],!Z(t[a]))return!0}else return!1;return delete t[a]}else return!1;return!1}function l({timestamp:a,priority:o,initiator:p,...f}){t[a]?.[o]?.[p]?t[a][o][p].push({...f}):t[a]?.[o]?t[a][o]={...t[a][o],[p]:[{...f}]}:t[a]?t[a]={...t[a],[o]:{[p]:[{...f}]}}:t[a]={[o]:{[p]:[{...f}]}}}return{map:t,remove:s,add:l,removeAll:e,get:i,getLte:r,getGte:n}}var hp=[T.expect,T.setNextBranch],dp=1/0;function Va(t){let e=t,r,n=fp(),i=Oa(),s,l=()=>{m(),w()},a=u=>{i.add.call(void 0,u),P()},o=(u=[])=>{for(let h of u)if(h.action(),(0,ka.default)(hp,h.actionType))break},p=(u=1/0)=>{let h=xt(i.get({timestamp:u,priority:"control"})??{}),d=xt(i.get({timestamp:u,priority:"container"})??{}),v=xt(i.get({timestamp:u,priority:"chapter"})??{});return[...h,...d,...v]},f=u=>{n.isReady(u)&&o(p(u))},y=()=>{o([...xt(i.get({timestamp:1/0,priority:"chapter"})??{})])},m=()=>{r&&(s?.unsubscribe(),r=void 0)},b=u=>{},P=()=>{r||(r=()=>setTimeout(()=>{f(1/0)}),s=e.events.ended$.subscribe(r))},O=u=>{m(),e=u},x=u=>{u.priority==="container"&&n.resetCalled(u.timestamp),i.remove(u)},w=()=>{n.release(),i.removeAll()};return{setPlayer:O,add:a,remove:x,exec:f,execEndOfVideo:y,listen:P,unlisten:m,release:l,containersEventsCallState:n,getPreparedToExecActions:p}}function fp(){let t=new Map;return{setCalled:({timestamp:l,id:a})=>{let o=t.get(l);o&&o[a]!==void 0&&(o[a]=!0)},setData:(l=[])=>{for(let a of l){let o=a.endTime??dp,p=t.get(o);t.set(o,{...p,[a.id]:!1})}},resetCalled:l=>{let a=t.get(l);if(a)for(let o in a)a[o]=!1},isReady:l=>{let a=t.get(l);return a?!(0,kr.default)(a).some(o=>!o):!0},release:()=>t.clear()}}function xt(t){return(0,Ma.default)((0,kr.default)(t)).sort(e=>e.actionType===T.expect?-1:1)}var ja={videoContentHeight:0,videoContentWidth:0},La=(t,e)=>{let{height:r,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(r&&n))return ja;let{clientHeight:i,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(i&&s))return ja;let l=r/n,a=i/s,o,p;return a>l?(p=s,o=s*l):a<l?(p=i/l,o=i):(p=s,o=i),{videoContentWidth:p,videoContentHeight:o}};var mp=250;function $a(t){let e=()=>{},r=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){let{parentElement:o,player:p}=t();if(o&&p){let{videoContentWidth:f,videoContentHeight:y}=La(o,p);o.style.setProperty("--interactive-content-width",`${f}px`),o.style.setProperty("--interactive-content-height",`${y}px`),o.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function i(){let{parentElement:a}=t();a.removeAttribute("style")}let s=Te(a=>{let{fns:o=[]}=t();n(a);for(let p of o)p()},mp);function l(){e=void 0,r.disconnect(),i()}return{resizeObserver:r,calc:()=>{e?.()},release:l}}var yp=t=>Math.floor(Math.random()*t),_a=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},Fa=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 qa=t=>{let e=t.length,r=yp(e);return t[r]},Na=1,Ba=t=>{let e=0;for(let n=0;n<t.length;++n)e+=t[n].weight??Na;let r=Math.random()*e;e=0;for(let n=0;n<t.length-1;++n)if(e+=t[n].weight??Na,e>=r)return t[n];return t[t.length-1]};var Da={shouldOpenNow:!0,isDetachContainer:!0},Ha="after-expect";var Mr=(t,e=!1)=>({...t,args:e?{...t.args,...Da}:{...Da,...t.args}}),za=({globalEventEmitter:t,globalEvents:e,player:r,interactiveEvents:n})=>{let i={isExpect:!1},s=()=>{i.isExpect&&(i.isExpect=!1)},l=({action:u,controlType:h,controlId:d,containerId:v,branches:g=[],onEvent:C,isEOV:S=()=>!1,isDisabled:R=()=>!1})=>{let I=Mr(u,S()),k={timestamp:1/0,priority:"control",initiator:d,actionType:I.type},F=R(),q=t.emit.bind(t,E.interactives,{subjectId:d,subjectType:h,subjectName:"control",type:F?A.actionChoiceCanceled:A.actionChoice,actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:v,...I.args}}),B=()=>{e.interactiveActionChoice$.next({subjectId:d,subjectType:h,subjectName:"control",type:F?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:v,...I.args}})};if(F){q(),B();return}switch(I.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{let z=g.find(ee=>ee.id===I.args.branchId);if(!z)return;C(I.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),q(),B(),I.args.shouldOpenNow?O({subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{chapterId:z.chapterId,autoSelect:!1}}):n.add({...k,action:O.bind(null,{subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{chapterId:z.chapterId,autoSelect:!1}})});return}case T.continuePlayback.trim().toLowerCase():{C(I.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),q(),B(),I.args.shouldOpenNow?P({subjectId:d,subjectName:"control",subjectType:h,action:u}):n.add({...k,action:P.bind(null,{subjectId:d,subjectName:"control",subjectType:h,action:u})});return}case T.openURI.trim().toLowerCase():{C(I.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),q(),B(),I.args.shouldOpenNow?w({subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}}):n.add({...k,action:w.bind(null,{subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}})});return}default:{let z="Unexpected control event",ee=new M(1,1,{message:z});f(ee,z);return}}},a=({action:u,container:{id:h,endTime:d},branches:v=[],isEOV:g=!1,autoSelected:C=!1})=>{let S=Mr(u,g),R={timestamp:!S.args.shouldOpenNow||g?1/0:d??1/0,priority:"container",initiator:h,actionType:S.type},I=t.emit.bind(t,E.interactives,{subjectId:h,subjectName:"container",type:A.actionChoice,actionType:S.type,payload:{invokeImmediately:S.args.shouldOpenNow,...S.args}}),k=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"container",type:"action-choice",actionType:S.type,payload:{invokeImmediately:S.args.shouldOpenNow,...S.args}})};switch(S.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{let F=v.find(q=>q.id===S.args.branchId);if(!F)return;I(),k(),n.add({...R,action:O.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{chapterId:F.chapterId,autoSelect:C}})});return}case T.setMaxWeightBranch.trim().toLowerCase():return;case T.setMinWeightBranch.trim().toLowerCase():return;case T.setRandomBranch.trim().toLowerCase():return;case T.setWeightlessRandomBranch.trim().toLowerCase():return;case T.continuePlayback.trim().toLowerCase():{I(),k(),n.add({...R,action:P.bind(null,{subjectId:h,subjectName:"container",action:S})});return}case T.openURI.trim().toLowerCase():{I(),k(),n.add({...R,action:w.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{URI:u.args.uri}})});return}default:{let F="Unexpected container event",q=new M(1,1,{message:F});f(q,F);return}}};function o({container:u,branches:h,isEOV:d=!1}){let v=Cr(u.events);if(v){let g=Mr(v.action,d);t.emit(E.interactives,{subjectId:u.id,subjectName:"container",type:A.actionChoice,actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),n.add({timestamp:d?1/0:u.endTime??1/0,priority:"container",initiator:u.id,actionType:T.expect,action:m.bind(null,{subjectId:u.id,subjectName:"container"})}),i.isExpect=!0}else for(let g of u.events??[])a({action:g.action,container:u,branches:h,isEOV:d})}let p=({chapterId:u,action:h,branches:d=[]})=>{let v=t.emit.bind(t,E.interactives,{subjectId:u,subjectName:"chapter",type:A.actionChoice,actionType:h.type,payload:h.args}),g=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:h.type,payload:h.args})};switch(h.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{let C=d.find(S=>S.id===h.args.branchId);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setWeightlessRandomBranch.trim().toLowerCase():{let C=qa(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setRandomBranch.trim().toLowerCase():{let C=Ba(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setMaxWeightBranch.trim().toLowerCase():{let C=Fa(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setMinWeightBranch.trim().toLowerCase():{let C=_a(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.continuePlayback.trim().toLowerCase():return v(),g(),P.bind(null,{subjectId:u,subjectName:"chapter",action:h});case T.openURI.trim().toLowerCase():return v(),g(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:{let C="Unexpected chapter event",S=new M(1,1,{message:C});f(S,C);return}}};function f(u,h){console.error(h),e.error$.next(u),t.emit(E.errors,u)}function y(u){let h=Cr(u.events);if(h){if(U(u))return;t.emit(E.interactives,{subjectId:u.id,subjectName:"chapter",type:A.actionChoice,actionType:h.action.type,payload:h.action.args}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"chapter",type:"action-choice",actionType:h.action.type,payload:h.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:T.expect,action:m.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else u.events?.forEach(d=>{let v=p({chapterId:u.id,action:d.action,branches:u.branches});v&&n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:d.action.type,action:v})})}let m=({subjectId:u,subjectName:h})=>{r.pause(),t.emit(E.interactives,{subjectId:u,subjectName:h,type:A.actionExecution,actionType:T.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:T.expect})},b=({subjectId:u,subjectName:h})=>{r.info.isEnded$.getValue()?n.execEndOfVideo():r.play(),t.emit(E.interactives,{subjectId:u,subjectName:h,type:A.actionExecution,actionType:Ha}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:Ha})},P=({subjectId:u,subjectName:h,subjectType:d,action:v})=>{t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type})},O=({subjectId:u,subjectName:h,subjectType:d,action:v,payload:g})=>{g.behaviour="change-chapter",t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type,payload:g}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type,payload:g})},x=({subjectId:u,subjectName:h,subjectType:d,action:v,payload:g})=>{g.behaviour="change-manifest",t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type,payload:g}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type,payload:g})},w=({subjectId:u,subjectName:h,subjectType:d,action:v,payload:g})=>{if(!g.URI)return;let C=window.open(g.URI,"_blank","noopener,noreferrer");C&&(C.opener=null),t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:p,onExpectEvent:m,expectEventHandler:b,setManifestChapterEvents:y,setManifestContainerEvents:o,stopExpect:s,state:i}};var Lr=W(pr(),1);import{Subscription as Ep,Subject as jr,ValueSubject as Le}from"@vkontakte/videoplayer-shared";var Vr=(t,e)=>{let r={};return t.map(n=>{if(!r[n]){let i=e.chapters.find(l=>l.id===n);if(!i)return null;let s=e.media.videos.find(l=>i.videoId===l.id);if(!s)return null;r[n]=Wa(s)}return r[n]}).filter(Boolean)},bp=t=>{for(let e of t.variants)if(gp(e)&&e.payload)return e.payload.id},gp=t=>!!(t.type==="custom"&&t.payload&&t.payload.type==="vk"),Wa=t=>{let e=bp(t);if(!e)return null;let r=e.split("_").pop();return r?parseInt(r,10):null},Cp=(t,e)=>{for(let r of t.media.videos)if(e===Wa(r)){for(let n of t.chapters)if(n.videoId===r.id)return n.id;return}},Ka=(t,e)=>t.reduce((r,n)=>{let i=Cp(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 Le([]),hasPrevChapter$:new Le(!1),prevChapter$:new Le(null),isInitialChapter$:new Le(!1),isGoBackLimited$:new Le(!1)};this.#r=null;this.#a=!1;this.#e=null;this.#u=null;this.events={inited$:new jr,destroyed$:new jr,error$:new jr};this.#n=null;this.#i=null;this.#t=null;this.#o=new Ep;this.#l=!1;this.#c=0;this.#n=r,this.#t=e,this.#i=n,this.#r=i,this.#s=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,Lr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#s.maxLength-1)}))}#r;#s;#a;#e;#u;#n;#i;#t;#o;#l;#c;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.#a||(this.#a=!0,this.events.inited$.next({initChapterId:r}))}get inited(){return this.#a}async updateHistory(e,r=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,i=e.length-this.#s.maxLength,s=i>0?e.slice(i):e,l=Vr(s,n);if(this.#u=l,this.state.history$.next(s),!(!r||!this.#r||!this.#n))try{await this.#r.save(this.#n,l)}catch{let o=new M(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#t?.emit(E.errors,o)}}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(E.errors,n)}this.#l=!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(E.errors,s)}let n=Ka(r,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,Lr.default)(e,-1)||this.#s.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return Vr([e],this.#e).pop()}return null}destroy(){this.#n=null,this.#r=null,this.#i=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#t?.emit(E.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var Tt=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 St=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 to=Object.create;var _r=Object.defineProperty;var ro=Object.getOwnPropertyDescriptor;var no=Object.getOwnPropertyNames;var io=Object.getPrototypeOf,so=Object.prototype.hasOwnProperty;var c=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ao=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of no(e))!so.call(t,i)&&i!==r&&_r(t,i,{get:()=>e[i],enumerable:!(n=ro(e,i))||n.enumerable});return t};var W=(t,e,r)=>(r=t!=null?to(io(t)):{},ao(e||!t||!t.__esModule?_r(r,"default",{value:t,enumerable:!0}):r,t));var G=c((Lt,Ur)=>{"use strict";var de=function(t){return t&&t.Math===Math&&t};Ur.exports=de(typeof globalThis=="object"&&globalThis)||de(typeof window=="object"&&window)||de(typeof self=="object"&&self)||de(typeof global=="object"&&global)||de(typeof Lt=="object"&&Lt)||function(){return this}()||Function("return this")()});var N=c((fh,zr)=>{"use strict";zr.exports=function(t){try{return!!t()}catch{return!0}}});var fe=c((mh,Wr)=>{"use strict";var lo=N();Wr.exports=!lo(function(){var t=function(){}.bind();return typeof t!="function"||t.hasOwnProperty("prototype")})});var Zr=c((yh,Xr)=>{"use strict";var co=fe(),Yr=Function.prototype,Kr=Yr.apply,Qr=Yr.call;Xr.exports=typeof Reflect=="object"&&Reflect.apply||(co?Qr.bind(Kr):function(){return Qr.apply(Kr,arguments)})});var D=c((vh,tn)=>{"use strict";var Jr=fe(),en=Function.prototype,$t=en.call,uo=Jr&&en.bind.bind($t,$t);tn.exports=Jr?uo:function(t){return function(){return $t.apply(t,arguments)}}});var me=c((bh,nn)=>{"use strict";var rn=D(),po=rn({}.toString),ho=rn("".slice);nn.exports=function(t){return ho(po(t),8,-1)}});var Nt=c((gh,sn)=>{"use strict";var fo=me(),mo=D();sn.exports=function(t){if(fo(t)==="Function")return mo(t)}});var _=c((Ch,an)=>{"use strict";var _t=typeof document=="object"&&document.all;an.exports=typeof _t>"u"&&_t!==void 0?function(t){return typeof t=="function"||t===_t}:function(t){return typeof t=="function"}});var Y=c((Eh,on)=>{"use strict";var yo=N();on.exports=!yo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Ye=c((Ih,ln)=>{"use strict";var vo=fe(),Qe=Function.prototype.call;ln.exports=vo?Qe.bind(Qe):function(){return Qe.apply(Qe,arguments)}});var Ft=c(pn=>{"use strict";var cn={}.propertyIsEnumerable,un=Object.getOwnPropertyDescriptor,bo=un&&!cn.call({1:2},1);pn.f=bo?function(e){var r=un(this,e);return!!r&&r.enumerable}:cn});var qt=c((Th,hn)=>{"use strict";hn.exports=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}});var fn=c((Sh,dn)=>{"use strict";var go=D(),Co=N(),Eo=me(),Bt=Object,Io=go("".split);dn.exports=Co(function(){return!Bt("z").propertyIsEnumerable(0)})?function(t){return Eo(t)==="String"?Io(t,""):Bt(t)}:Bt});var Dt=c((wh,mn)=>{"use strict";mn.exports=function(t){return t==null}});var Ht=c((Ah,yn)=>{"use strict";var xo=Dt(),To=TypeError;yn.exports=function(t){if(xo(t))throw new To("Can't call method on "+t);return t}});var ye=c((Rh,vn)=>{"use strict";var So=fn(),wo=Ht();vn.exports=function(t){return So(wo(t))}});var ie=c((Ph,bn)=>{"use strict";var Ao=_();bn.exports=function(t){return typeof t=="object"?t!==null:Ao(t)}});var Xe=c((Oh,gn)=>{"use strict";gn.exports={}});var Ze=c((kh,En)=>{"use strict";var Gt=Xe(),Ut=G(),Ro=_(),Cn=function(t){return Ro(t)?t:void 0};En.exports=function(t,e){return arguments.length<2?Cn(Gt[t])||Cn(Ut[t]):Gt[t]&&Gt[t][e]||Ut[t]&&Ut[t][e]}});var xn=c((Mh,In)=>{"use strict";var Po=D();In.exports=Po({}.isPrototypeOf)});var An=c((Vh,wn)=>{"use strict";var Oo=G(),Tn=Oo.navigator,Sn=Tn&&Tn.userAgent;wn.exports=Sn?String(Sn):""});var jn=c((jh,Vn)=>{"use strict";var Mn=G(),zt=An(),Rn=Mn.process,Pn=Mn.Deno,On=Rn&&Rn.versions||Pn&&Pn.version,kn=On&&On.v8,H,Je;kn&&(H=kn.split("."),Je=H[0]>0&&H[0]<4?1:+(H[0]+H[1]));!Je&&zt&&(H=zt.match(/Edge\/(\d+)/),(!H||H[1]>=74)&&(H=zt.match(/Chrome\/(\d+)/),H&&(Je=+H[1])));Vn.exports=Je});var Wt=c((Lh,$n)=>{"use strict";var Ln=jn(),ko=N(),Mo=G(),Vo=Mo.String;$n.exports=!!Object.getOwnPropertySymbols&&!ko(function(){var t=Symbol("symbol detection");return!Vo(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&Ln&&Ln<41})});var Kt=c(($h,Nn)=>{"use strict";var jo=Wt();Nn.exports=jo&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Qt=c((Nh,_n)=>{"use strict";var Lo=Ze(),$o=_(),No=xn(),_o=Kt(),Fo=Object;_n.exports=_o?function(t){return typeof t=="symbol"}:function(t){var e=Lo("Symbol");return $o(e)&&No(e.prototype,Fo(t))}});var qn=c((_h,Fn)=>{"use strict";var qo=String;Fn.exports=function(t){try{return qo(t)}catch{return"Object"}}});var Yt=c((Fh,Bn)=>{"use strict";var Bo=_(),Do=qn(),Ho=TypeError;Bn.exports=function(t){if(Bo(t))return t;throw new Ho(Do(t)+" is not a function")}});var Hn=c((qh,Dn)=>{"use strict";var Go=Yt(),Uo=Dt();Dn.exports=function(t,e){var r=t[e];return Uo(r)?void 0:Go(r)}});var Un=c((Bh,Gn)=>{"use strict";var Xt=Ye(),Zt=_(),Jt=ie(),zo=TypeError;Gn.exports=function(t,e){var r,n;if(e==="string"&&Zt(r=t.toString)&&!Jt(n=Xt(r,t))||Zt(r=t.valueOf)&&!Jt(n=Xt(r,t))||e!=="string"&&Zt(r=t.toString)&&!Jt(n=Xt(r,t)))return n;throw new zo("Can't convert object to primitive value")}});var Wn=c((Dh,zn)=>{"use strict";zn.exports=!0});var Yn=c((Hh,Qn)=>{"use strict";var Kn=G(),Wo=Object.defineProperty;Qn.exports=function(t,e){try{Wo(Kn,t,{value:e,configurable:!0,writable:!0})}catch{Kn[t]=e}return e}});var et=c((Gh,Jn)=>{"use strict";var Ko=Wn(),Qo=G(),Yo=Yn(),Xn="__core-js_shared__",Zn=Jn.exports=Qo[Xn]||Yo(Xn,{});(Zn.versions||(Zn.versions=[])).push({version:"3.38.0",mode:Ko?"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 er=c((Uh,ti)=>{"use strict";var ei=et();ti.exports=function(t,e){return ei[t]||(ei[t]=e||{})}});var ve=c((zh,ri)=>{"use strict";var Xo=Ht(),Zo=Object;ri.exports=function(t){return Zo(Xo(t))}});var se=c((Wh,ni)=>{"use strict";var Jo=D(),el=ve(),tl=Jo({}.hasOwnProperty);ni.exports=Object.hasOwn||function(e,r){return tl(el(e),r)}});var tr=c((Kh,ii)=>{"use strict";var rl=D(),nl=0,il=Math.random(),sl=rl(1 .toString);ii.exports=function(t){return"Symbol("+(t===void 0?"":t)+")_"+sl(++nl+il,36)}});var be=c((Qh,ai)=>{"use strict";var al=G(),ol=er(),si=se(),ll=tr(),cl=Wt(),ul=Kt(),ae=al.Symbol,rr=ol("wks"),pl=ul?ae.for||ae:ae&&ae.withoutSetter||ll;ai.exports=function(t){return si(rr,t)||(rr[t]=cl&&si(ae,t)?ae[t]:pl("Symbol."+t)),rr[t]}});var ui=c((Yh,ci)=>{"use strict";var hl=Ye(),oi=ie(),li=Qt(),dl=Hn(),fl=Un(),ml=be(),yl=TypeError,vl=ml("toPrimitive");ci.exports=function(t,e){if(!oi(t)||li(t))return t;var r=dl(t,vl),n;if(r){if(e===void 0&&(e="default"),n=hl(r,t,e),!oi(n)||li(n))return n;throw new yl("Can't convert object to primitive value")}return e===void 0&&(e="number"),fl(t,e)}});var nr=c((Xh,pi)=>{"use strict";var bl=ui(),gl=Qt();pi.exports=function(t){var e=bl(t,"string");return gl(e)?e:e+""}});var fi=c((Zh,di)=>{"use strict";var Cl=G(),hi=ie(),ir=Cl.document,El=hi(ir)&&hi(ir.createElement);di.exports=function(t){return El?ir.createElement(t):{}}});var sr=c((Jh,mi)=>{"use strict";var Il=Y(),xl=N(),Tl=fi();mi.exports=!Il&&!xl(function(){return Object.defineProperty(Tl("div"),"a",{get:function(){return 7}}).a!==7})});var bi=c(vi=>{"use strict";var Sl=Y(),wl=Ye(),Al=Ft(),Rl=qt(),Pl=ye(),Ol=nr(),kl=se(),Ml=sr(),yi=Object.getOwnPropertyDescriptor;vi.f=Sl?yi:function(e,r){if(e=Pl(e),r=Ol(r),Ml)try{return yi(e,r)}catch{}if(kl(e,r))return Rl(!wl(Al.f,e,r),e[r])}});var Ci=c((td,gi)=>{"use strict";var Vl=N(),jl=_(),Ll=/#|\.prototype\./,ge=function(t,e){var r=Nl[$l(t)];return r===Fl?!0:r===_l?!1:jl(e)?Vl(e):!!e},$l=ge.normalize=function(t){return String(t).replace(Ll,".").toLowerCase()},Nl=ge.data={},_l=ge.NATIVE="N",Fl=ge.POLYFILL="P";gi.exports=ge});var ar=c((rd,Ii)=>{"use strict";var Ei=Nt(),ql=Yt(),Bl=fe(),Dl=Ei(Ei.bind);Ii.exports=function(t,e){return ql(t),e===void 0?t:Bl?Dl(t,e):function(){return t.apply(e,arguments)}}});var Ti=c((nd,xi)=>{"use strict";var Hl=Y(),Gl=N();xi.exports=Hl&&Gl(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var wi=c((id,Si)=>{"use strict";var Ul=ie(),zl=String,Wl=TypeError;Si.exports=function(t){if(Ul(t))return t;throw new Wl(zl(t)+" is not an object")}});var Pi=c(Ri=>{"use strict";var Kl=Y(),Ql=sr(),Yl=Ti(),tt=wi(),Ai=nr(),Xl=TypeError,or=Object.defineProperty,Zl=Object.getOwnPropertyDescriptor,lr="enumerable",cr="configurable",ur="writable";Ri.f=Kl?Yl?function(e,r,n){if(tt(e),r=Ai(r),tt(n),typeof e=="function"&&r==="prototype"&&"value"in n&&ur in n&&!n[ur]){var i=Zl(e,r);i&&i[ur]&&(e[r]=n.value,n={configurable:cr in n?n[cr]:i[cr],enumerable:lr in n?n[lr]:i[lr],writable:!1})}return or(e,r,n)}:or:function(e,r,n){if(tt(e),r=Ai(r),tt(n),Ql)try{return or(e,r,n)}catch{}if("get"in n||"set"in n)throw new Xl("Accessors not supported");return"value"in n&&(e[r]=n.value),e}});var ki=c((ad,Oi)=>{"use strict";var Jl=Y(),ec=Pi(),tc=qt();Oi.exports=Jl?function(t,e,r){return ec.f(t,e,tc(1,r))}:function(t,e,r){return t[e]=r,t}});var Ee=c((od,Vi)=>{"use strict";var Ce=G(),rc=Zr(),nc=Nt(),ic=_(),sc=bi().f,ac=Ci(),oe=Xe(),oc=ar(),le=ki(),Mi=se();et();var lc=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 rc(t,this,arguments)};return e.prototype=t.prototype,e};Vi.exports=function(t,e){var r=t.target,n=t.global,i=t.stat,s=t.proto,l=n?Ce:i?Ce[r]:Ce[r]&&Ce[r].prototype,a=n?oe:oe[r]||le(oe,r,{})[r],o=a.prototype,p,f,y,m,b,P,O,x,w;for(m in e)p=ac(n?m:r+(i?".":"#")+m,t.forced),f=!p&&l&&Mi(l,m),P=a[m],f&&(t.dontCallGetSet?(w=sc(l,m),O=w&&w.value):O=l[m]),b=f&&O?O:e[m],!(!p&&!s&&typeof P==typeof b)&&(t.bind&&f?x=oc(b,Ce):t.wrap&&f?x=lc(b):s&&ic(b)?x=nc(b):x=b,(t.sham||b&&b.sham||P&&P.sham)&&le(x,"sham",!0),le(a,m,x),s&&(y=r+"Prototype",Mi(oe,y)||le(oe,y,{}),le(oe[y],m,b),t.real&&o&&(p||!o[m])&&le(o,m,b)))}});var Li=c((ld,ji)=>{"use strict";var cc=Math.ceil,uc=Math.floor;ji.exports=Math.trunc||function(e){var r=+e;return(r>0?uc:cc)(r)}});var Ie=c((cd,$i)=>{"use strict";var pc=Li();$i.exports=function(t){var e=+t;return e!==e||e===0?0:pc(e)}});var _i=c((ud,Ni)=>{"use strict";var hc=Ie(),dc=Math.min;Ni.exports=function(t){var e=hc(t);return e>0?dc(e,9007199254740991):0}});var xe=c((pd,Fi)=>{"use strict";var fc=_i();Fi.exports=function(t){return fc(t.length)}});var rt=c((hd,qi)=>{"use strict";qi.exports=function(){}});var Bi=c(()=>{"use strict";var mc=Ee(),yc=ve(),vc=xe(),bc=Ie(),gc=rt();mc({target:"Array",proto:!0},{at:function(e){var r=yc(this),n=vc(r),i=bc(e),s=i>=0?i:n+i;return s<0||s>=n?void 0:r[s]}});gc("at")});var nt=c((md,Di)=>{"use strict";var Cc=Ze();Di.exports=Cc});var Gi=c((yd,Hi)=>{"use strict";Bi();var Ec=nt();Hi.exports=Ec("Array","at")});var zi=c((vd,Ui)=>{"use strict";var Ic=Gi();Ui.exports=Ic});var pr=c((bd,Wi)=>{"use strict";var xc=zi();Wi.exports=xc});var ls=c((kf,os)=>{"use strict";var Vc=er(),jc=tr(),as=Vc("keys");os.exports=function(t){return as[t]||(as[t]=jc(t))}});var us=c((Mf,cs)=>{"use strict";var Lc=N();cs.exports=!Lc(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})});var ds=c((Vf,hs)=>{"use strict";var $c=se(),Nc=_(),_c=ve(),Fc=ls(),qc=us(),ps=Fc("IE_PROTO"),Er=Object,Bc=Er.prototype;hs.exports=qc?Er.getPrototypeOf:function(t){var e=_c(t);if($c(e,ps))return e[ps];var r=e.constructor;return Nc(r)&&e instanceof r?r.prototype:e instanceof Er?Bc:null}});var ms=c((jf,fs)=>{"use strict";var Dc=Ie(),Hc=Math.max,Gc=Math.min;fs.exports=function(t,e){var r=Dc(t);return r<0?Hc(r+e,0):Gc(r,e)}});var Ir=c((Lf,vs)=>{"use strict";var Uc=ye(),zc=ms(),Wc=xe(),ys=function(t){return function(e,r,n){var i=Uc(e),s=Wc(i);if(s===0)return!t&&-1;var l=zc(n,s),a;if(t&&r!==r){for(;s>l;)if(a=i[l++],a!==a)return!0}else for(;s>l;l++)if((t||l in i)&&i[l]===r)return t||l||0;return!t&&-1}};vs.exports={includes:ys(!0),indexOf:ys(!1)}});var gs=c(($f,bs)=>{"use strict";bs.exports={}});var Is=c((Nf,Es)=>{"use strict";var Kc=D(),xr=se(),Qc=ye(),Yc=Ir().indexOf,Xc=gs(),Cs=Kc([].push);Es.exports=function(t,e){var r=Qc(t),n=0,i=[],s;for(s in r)!xr(Xc,s)&&xr(r,s)&&Cs(i,s);for(;e.length>n;)xr(r,s=e[n++])&&(~Yc(i,s)||Cs(i,s));return i}});var Ts=c((_f,xs)=>{"use strict";xs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var ws=c((Ff,Ss)=>{"use strict";var Zc=Is(),Jc=Ts();Ss.exports=Object.keys||function(e){return Zc(e,Jc)}});var Ms=c((qf,ks)=>{"use strict";var Rs=Y(),eu=N(),Ps=D(),tu=ds(),ru=ws(),nu=ye(),iu=Ft().f,Os=Ps(iu),su=Ps([].push),au=Rs&&eu(function(){var t=Object.create(null);return t[2]=2,!Os(t,2)}),As=function(t){return function(e){for(var r=nu(e),n=ru(r),i=au&&tu(r)===null,s=n.length,l=0,a=[],o;s>l;)o=n[l++],(!Rs||(i?o in r:Os(r,o)))&&su(a,t?[o,r[o]]:r[o]);return a}};ks.exports={entries:As(!0),values:As(!1)}});var Vs=c(()=>{"use strict";var ou=Ee(),lu=Ms().values;ou({target:"Object",stat:!0},{values:function(e){return lu(e)}})});var Ls=c((Hf,js)=>{"use strict";Vs();var cu=Xe();js.exports=cu.Object.values});var Ns=c((Gf,$s)=>{"use strict";var uu=Ls();$s.exports=uu});var gt=c((Uf,_s)=>{"use strict";var pu=Ns();_s.exports=pu});var Bs=c(()=>{"use strict";var hu=Ee(),du=Ir().includes,fu=N(),mu=rt(),yu=fu(function(){return!Array(1).includes()});hu({target:"Array",proto:!0,forced:yu},{includes:function(e){return du(this,e,arguments.length>1?arguments[1]:void 0)}});mu("includes")});var Hs=c((Yf,Ds)=>{"use strict";Bs();var vu=nt();Ds.exports=vu("Array","includes")});var Us=c((Xf,Gs)=>{"use strict";var bu=Hs();Gs.exports=bu});var Ct=c((Zf,zs)=>{"use strict";var gu=Us();zs.exports=gu});var Rr=c((ym,Xs)=>{"use strict";var Su=me();Xs.exports=Array.isArray||function(e){return Su(e)==="Array"}});var Js=c((vm,Zs)=>{"use strict";var wu=TypeError,Au=9007199254740991;Zs.exports=function(t){if(t>Au)throw wu("Maximum allowed index exceeded");return t}});var ra=c((bm,ta)=>{"use strict";var Ru=Rr(),Pu=xe(),Ou=Js(),ku=ar(),ea=function(t,e,r,n,i,s,l,a){for(var o=i,p=0,f=l?ku(l,a):!1,y,m;p<n;)p in r&&(y=f?f(r[p],p,e):r[p],s>0&&Ru(y)?(m=Pu(y),o=ea(t,e,y,m,o,s-1)-1):(Ou(o+1),t[o]=y),o++),p++;return o};ta.exports=ea});var sa=c((gm,ia)=>{"use strict";var Mu=be(),Vu=Mu("toStringTag"),na={};na[Vu]="z";ia.exports=String(na)==="[object z]"});var oa=c((Cm,aa)=>{"use strict";var ju=sa(),Lu=_(),It=me(),$u=be(),Nu=$u("toStringTag"),_u=Object,Fu=It(function(){return arguments}())==="Arguments",qu=function(t,e){try{return t[e]}catch{}};aa.exports=ju?It:function(t){var e,r,n;return t===void 0?"Undefined":t===null?"Null":typeof(r=qu(e=_u(t),Nu))=="string"?r:Fu?It(e):(n=It(e))==="Object"&&Lu(e.callee)?"Arguments":n}});var ca=c((Em,la)=>{"use strict";var Bu=D(),Du=_(),Pr=et(),Hu=Bu(Function.toString);Du(Pr.inspectSource)||(Pr.inspectSource=function(t){return Hu(t)});la.exports=Pr.inspectSource});var ma=c((Im,fa)=>{"use strict";var Gu=D(),Uu=N(),ua=_(),zu=oa(),Wu=Ze(),Ku=ca(),pa=function(){},ha=Wu("Reflect","construct"),Or=/^\s*(?:class|function)\b/,Qu=Gu(Or.exec),Yu=!Or.test(pa),je=function(e){if(!ua(e))return!1;try{return ha(pa,[],e),!0}catch{return!1}},da=function(e){if(!ua(e))return!1;switch(zu(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Yu||!!Qu(Or,Ku(e))}catch{return!0}};da.sham=!0;fa.exports=!ha||Uu(function(){var t;return je(je.call)||!je(Object)||!je(function(){t=!0})||t})?da:je});var ga=c((xm,ba)=>{"use strict";var ya=Rr(),Xu=ma(),Zu=ie(),Ju=be(),ep=Ju("species"),va=Array;ba.exports=function(t){var e;return ya(t)&&(e=t.constructor,Xu(e)&&(e===va||ya(e.prototype))?e=void 0:Zu(e)&&(e=e[ep],e===null&&(e=void 0))),e===void 0?va:e}});var Ea=c((Tm,Ca)=>{"use strict";var tp=ga();Ca.exports=function(t,e){return new(tp(t))(e===0?0:e)}});var Ia=c(()=>{"use strict";var rp=Ee(),np=ra(),ip=ve(),sp=xe(),ap=Ie(),op=Ea();rp({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,r=ip(this),n=sp(r),i=op(r,0);return i.length=np(i,r,r,n,0,e===void 0?1:ap(e)),i}})});var xa=c(()=>{"use strict";var lp=rt();lp("flat")});var Sa=c((Pm,Ta)=>{"use strict";Ia();xa();var cp=nt();Ta.exports=cp("Array","flat")});var Aa=c((Om,wa)=>{"use strict";var up=Sa();wa.exports=up});var Pa=c((km,Ra)=>{"use strict";var pp=Aa();Ra.exports=pp});var Fr="1.0.31";function Rt(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 j="interactive",oo="interactive-controls-container",Fe=()=>document.querySelector(`.${oo}`),qr=.4,V={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Br=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(Br||{}),Dr=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(Dr||{}),Hr=(n=>(n.start="left",n.end="right",n.center="center",n))(Hr||{}),qe=({target:t,props:e})=>{t.style.alignItems=(e?.gravityVertical&&Br[e.gravityVertical])??"center",t.style.justifyContent=(e?.gravityHorizontal&&Dr[e.gravityHorizontal])??"center",t.style.textAlign=(e?.alignment&&Hr[e.alignment])??"center"},Be=({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},De=({target:t,props:e,fallback:r})=>{t.style.backgroundColor=Rt(e?.background?.color??r.backgroundColor,e?.background?.alpha??r.backgroundAlpha)},He=({target:t,props:e,fallback:r,dependsOn:n})=>{t.style.border=`calc(${n.height} * ${e?.shape?.border?.width??r.borderWidth}) solid ${Rt(e?.shape?.border?.color??r.borderColor,e?.shape?.border?.alpha??r.borderAlpha)}`,t.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??r.roundCorners})`},re=({target:t,layoutParams:e,fallback:r})=>{let n=e.angle??r.angle;n=n&&n*-1,t.style.transform=`rotate(${n}rad)`};var K=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let r=document.createElement("div");r.classList.add(`${j}-control-container-${this.control.id}`),e(r,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??V.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()}}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 Pt="int",Q=(n=>(n.AREA=`${Pt}_area`,n.TEXT=`${Pt}_text`,n.BUTTON=`${Pt}_bttn`,n))(Q||{});var Ge=t=>{if(t.type.trim().toLowerCase()==="area")return new Ot(t)},Ot=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${j}-${this.control.id}`),n.setAttribute("data-testid",Q.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",De({target:n,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),He({target:n,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:this.container.dimensions}),re({target:n,layoutParams:this.control.layoutParams,fallback:V}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Ue=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 ze=t=>{if(t.type.trim().toLowerCase()==="button")return new kt(t)},kt=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${j}-${this.control.id}`),n.setAttribute("data-testid",Q.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",re({target:n,layoutParams:this.control.layoutParams,fallback:V}),De({target:n,props:this.control.props,fallback:V}),He({target:n,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),qe({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=Ue(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;Be({target:s,props:this.control.props,fallback:V,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.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Gr=t=>{if(t.type.trim().toLowerCase()==="text")return new Mt(t)},Mt=class extends K{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let n=document.createElement("div");n.classList.add(`${j}-${this.control.id}`),n.setAttribute("data-testid",Q.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",re({target:n,layoutParams:this.control.layoutParams,fallback:V}),qe({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let i=Ue(this.control.type.trim().toLowerCase()),s=i.firstElementChild??i;Be({target:s,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),n.append(i),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){}enable(){}getElement(){return this.controlElement}};var Vt=class{constructor(e){this.layout=e}},We=class extends Vt{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))`}};var ne=class{constructor(e){this.container=e,this.factories=new Map,this.controls=[],this.setControls()}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);if(s)return[...e,s]}return[...e]},[])||[]}};var Ke=(t,e)=>{if(t.type.trim().toLowerCase()==="choice")return new jt(t,e)},jt=class extends ne{constructor(e,r){super(e),this.rootElement=r??Fe(),this.layout=new We(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ze),this.addControlFactory("text",Gr),this.addControlFactory("area",Ge)}createView(e){let r=document.createElement("div");return r.classList.add(`${j}-${this.container.id}`),this.layout.setContainerLayout(r),this.controls.forEach(n=>{n.createView({parentElement:r,layoutCallback:this.layout.setControlLayout}),n.setEvents(e)}),this.rootElement.append(r),this.isRemoved=!1,r}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(r=>r.enable()),e.style.opacity="1",this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(r=>r.disable()),e.style.opacity=`${qr}`,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${j}-${this.container.id}`)}};var Ja=W(pr(),1);import{clientChecker as Ip,combine as xp,InterfaceLanguage as Tp,Observable as Ya,once as Sp,Subject as L,Subscription as $r,ValueSubject as $,fromEvent as Xa}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Ne}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Tc}from"@vkontakte/videoplayer-shared";function Te(t,e){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>t(...n),e)}}var X=(t,e)=>Object.prototype.toString.call(t)===`[object ${e}]`,Se=t=>X(t,"Object"),it=t=>X(t,"String"),st=t=>X(t,"Array"),at=t=>X(t,"Number"),Ki=t=>X(t,"Function");var hr=t=>at(t)&&!isNaN(t);var Z=t=>Se(t)&&Object.keys(t).length===0,dr=t=>st(t)&&!t.length;var we=(t,e)=>it(t)&&(e?t.trim():t).length;var Qi="video_interactive",Yi="videoint";var Xi=250,Ae=class{constructor(e){this.handleZoomChange=Te(e=>{this.lastZoomInfo=e},Xi);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?.("Id is not found"),console.error("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"),console.error("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=Sc(e),this.resizeObserver=new ResizeObserver(Te(this.onResize,Xi)),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 Tc(this.lang,Qi,Yi)}catch{console.log("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 Sc(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 Re=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 l=s.startTime-e;if(l<=i&&(s.endTime&&i<=s.endTime||s.endTime===null)){n=!0;break}i<l&&(r=r===-1?l:Math.min(r,l))}return!n&&r!==-1?r:null}}};import{isSupportedManifest as lt,ContainerTypes as Gd,ControlTypes as ct,EventActionTypes as T,EventTypes as Ud,migrateManifestToLatestVersion as es,compareVersions as zd}from"@interactiveplatform/movika-manifest";var Zi={metadata:"Object",chapters:"Array"},Ji=t=>{if(!Se(t))return!1;for(let e in Zi)if(!t[e]||!X(t[e],Zi[e]))return!1;return lt(t.metadata.version)},ot=t=>t.type===ct.Text,Ld=t=>t.type===ct.Button,$d=t=>t.type===ct.Area,Nd={Choice:"Choice",TextInput:"TextInput"},_d={Button:"Button",Area:"Area",Text:"Text"},Fd={onClick:"onClick",onSuspense:"onSuspense"},qd={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 pt=class{constructor(e){this.fns=[];this.addFn=(e,r=!1)=>{Ki(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 Mc}from"@vkontakte/videoplayer-shared";var ht=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,r){return wc(...this.loaders[e])(r)}};function wc(...t){return async function(r){let n=[...t];for(;n.length>0;)r=await n.shift()(r);return r}}function Pe(t,e,r){return t?{...t,[e]:t[e]?[r,...t[e]]:[r]}:{[e]:[r]}}function dt({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 l=t.getMedia(i.media,s.videoId),a=t.getGraph(i.graph,s.id);return l?{...n,actions:t,errors:e,result:{chapter:s,media:l,graph:a}}:{...n,errors:Pe(e,dt.name,"Could not find media"),actions:t}}}}return{...n,errors:Pe(e,dt.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 l=n[i];try{l.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},ce=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)}},Oe=class{constructor(){Object.defineProperty(this,"signal",{value:new ce,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&&(Oe.prototype[Symbol.toStringTag]="AbortController",ce.prototype[Symbol.toStringTag]="AbortSignal");function mt(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 fr(t){typeof t=="function"&&(t={fetch:t});let{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!mt({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(p,f){let y;f&&f.signal&&(y=f.signal,delete f.signal);let m=new r(p,f);return y&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:y}),m},s.prototype=r.prototype);let l=e;return{fetch:(o,p)=>{let f=s&&s.prototype.isPrototypeOf(o)?o.signal:p?p.signal:void 0;if(f){let y;try{y=new DOMException("Aborted","AbortError")}catch{y=new Error("Aborted"),y.name="AbortError"}if(f.aborted)return Promise.reject(y);let m=new Promise((b,P)=>{f.addEventListener("abort",()=>P(y),{once:!0})});return p&&p.signal&&delete p.signal,Promise.race([m,l(o,p)])}return l(o,p)},Request:s}}var ke=mt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),ts=ke?fr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,mr=ke?ts.fetch:window.fetch,pf=ke?ts.Request:window.Request,hf=ke?Oe:window.AbortController,df=ke?ce:window.AbortSignal;var yr=(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 Ac=async t=>{try{let e={},r;if(it(t)){r=new URL(t).href;let i=await mr(r);if(!i.ok)return{};e=await i.json()}else if(Se(t))e=t;else return{};if(!Ji(e))return{};let n=e.metadata.media;if(it(n)&&!("media"in e))try{let i;r?i=new URL(n,r).href:(i=new URL(n).href,r=i);let s=await mr(i);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return Oc(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:r}}catch{return{}}};async function rs(t){let{manifest:e,manifestURL:r}=await Ac(t);if(!e)throw new Error("Failed on fetch");let n=es(e);return n.media=Rc(n.media,r),delete n.metadata.media,n}function yt(t,e){if(e)return t.find(r=>r.id===e)}function vr(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 br(t,e){return t.videos.find(r=>r.id===e)}function Rc(t,e){return{...t,videos:t.videos.map(r=>({...r,variants:r.variants.map(n=>{let i="url"in n?n.url:"",s=Pc(i,e);return{...n,url:s||i}})}))}}function Pc(t="",e){try{return new URL(t,e).href}catch{return""}}function Oc(t){return yr(t,"3.2.0")>=0}var vt=t=>st(t)&&!dr(t),U=t=>t.order==="end",bt=t=>st(t.containers)&&!dr(t.containers)&&U(t),ns=(t,e)=>{let r=t*1e3;return vt(e.controls)&&r<(e.startTime??0)},gr=(t,e)=>{let r=t*1e3;return vt(e.controls)&&r>=(e.startTime??0)&&r<=(e.endTime??1/0)};var J=(t=[])=>t.some(e=>e.action.type==="expect"),Cr=(t=[])=>t.find(e=>e.action.type==="expect"),kc=t=>t?.length===1,ue=t=>kc(t)&&ot(t[0]);function is(t,...e){return r=>typeof e[0]=="object"&&typeof r=="object"?t({...e[0],...r}):t(...e,...r)}var ss=(t,e)=>J(t.events)?!1:e.some(({container:r})=>r.container.id!==t.id&&J(r.container.events)&&r.container.endTime===t.endTime&&!r.isRemoved);var pe=class extends ht{constructor(r,n){super(r);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Mc(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:Pe},result:null,errors:null,source:r});return n.errors&&this.errorHandler(n.errors),this.manifest=await rs(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",dt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:vr,getChapter:yt,getMedia:br,getByBranches:this.getByBranches.bind(this),addErrorMessage:Pe},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=br(this.manifest.media,n.videoId),s=vr(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?U(this.chapter):!1}};var Ws=W(gt(),1);import{Player as Cu}from"@vkontakte/videoplayer-core";import{Subscription as wr,Tracer as Eu,ValueSubject as Iu}from"@vkontakte/videoplayer-shared";var Fs=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 qs=W(gt(),1);function Tr(){let t=new Map;function e({listId:s=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let o=t.get(s),p={...a};return o?o[l]=p:t.set(s,{[l]:p}),{listId:s,itemId:l,...a}}function r(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,l){let a=t.get(s);if(!a)throw Error("Can't remove. Not find.");if(l){let o=a[l];o&&r(o),delete a[l],Object.keys(a).length||t.delete(s)}else{for(let o of(0,qs.default)(a))r(o);t.delete(s)}}function i(){for(let s of t)n(s[0])}return{createPlayer:e,removePlayer:n,map:t,removeAll:i}}var he=W(Ct(),1);function Sr(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,he.default)(e,"mp4"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(i||(0,he.default)(e,"mpeg"))&&(r.MPEG={...r.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(i||(0,he.default)(e,"hls"))&&(r={...r,HLS:{type:"url",url:s.url}});break;case"dash":(i||(0,he.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 Me=(t,e)=>{let r=t.info.currentQuality$.getValue(),n=t.info.availableQualities$.getValue();r!==e&&(0,he.default)(n,e)&&(t.setQuality(e),t.setAutoQuality(!1))};var xu=2;function Ar(t){let e=Tr(),r=new wr,n={},i=null,s=!1,l,a=new Iu(null);t&&o(t);function o(x){i=x}function p(x,w,u){if(!i)throw Error("need to set interactive controller");if(!i.options)return;let d=(e.map.get(x)??{})[w];if(d){n={chapterId:u,listId:x,itemId:w,...d};let v=n.player;n.subscription.add(v.info.currentQuality$.subscribe(g=>{let C=v.info.position$.getValue(),S=v.info.isAutoQualityEnabled$.getValue();if(!(!g||!C||S))for(let R of e.map)(0,Ws.default)(R[1]).forEach(({player:I})=>{Me(I,g)})})).add(v.events.started$.subscribe(()=>{f(w)})),d.container.remove(),i.setPlayer(d.player),s||(i.init(),s=!0),a.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function f(x){if(!i)throw Error("need to set interactive controller");if(Z(n)||x!==n.itemId)return;let w=i.getChapterBranches(),u=new Set;for(let h of w)u.has(h.media.id)||(await m({media:h.media,chapterId:h.chapter.id,setAsActive:!1,title:h.chapter.label}),u.add(h.media.id))}async function y({chapter:{id:x},manifestVideo:w}){if(Z(n)||!i)return;let u=n.player.info.muted$.getValue(),h=n.player.info.currentQuality$.getValue(),d=n.player.info.isAutoQualityEnabled$.getValue(),v=n.player.info.volume$.getValue(),g=n.player.info.currentPlaybackRate$.getValue(),C=!d,S=!1;for(let R of e.map)if(R[0]===w.id&&!i.state.isReplay$.getValue()){let I=Object.keys(R[1]);for(let k of I)k===n.itemId?(I.length<xu||(S=!0),e.removePlayer(R[0],k)):(S=!0,p(R[0],k,x),C?Me(n.player,h):n.player.setAutoQuality(!0),n.player.setVolume(v),n.player.setMuted(u),n.player.setPlaybackRate(g))}else e.removePlayer(R[0]);S||(await m({media:w,chapterId:x,setAsActive:!0,playbackRate:g}),C?Me(n.player,h):n.player.setAutoQuality(!0),n.player.setVolume(v),n.player.setMuted(u))}async function m({media:x,chapterId:w,prefetch:u=!0,setAsActive:h=!0,autoplay:d=!1,preferredExt:v,title:g,playbackRate:C}){let S=Math.random().toString(),R=document.createElement("div");l.append(R);let I;if(i?.options?.vkVideoLoader){let _e=Fs(x);_e.length&&(I=await i.options.vkVideoLoader(..._e))}let k=i?.options?.coreConfig||void 0,F={...k,configName:[...k?.configName??[],"interactive"]},q={container:R,...I?.videos?.[0]||{sources:Sr(x,v).sources},title:g,failoverHosts:I?.failoverHosts||[]},B=new Cu(F,Eu.createRootTracer());B.initVideo(q);let z=null;if(I?.videos&&i?.options.createOneStat){let _e=I.videos[0],At=i.options.createOneStat(_e),Nr=new wr;At&&(Nr.add(At.attachTo(B)),z={oneStat:At,statSubscription:Nr})}let ee=new wr,eo=n?.player?.info.isAutoQualityEnabled$.getValue();ee.add(B.events.canplay$.subscribe(function(){eo||Me(B,n.player.info.currentQuality$.getValue()),C&&B.setPlaybackRate(C)}));let te=e.createPlayer({listId:x.id,itemId:S,player:B,container:R,sources:Sr(x,v).sources,config:q,subscription:ee,statistics:z});return h&&p(x.id,te.itemId,w),d&&te.player.play(),u&&!d&&te.player.prepare(),{player:te.player,config:te.config,statistics:te.statistics}}function b(){P(),i=null,l.remove()}function P(){r.unsubscribe(),e.removeAll(),n={},s=!1}async function O(){if(!i)throw Error("need to set interactive controller");P(),l=document.createElement("div");let{media:x,chapter:w}=i.getCurrentChapter();x&&w?(r.add(i.events.chapterChanged$.subscribe(y)),await m({media:x,chapterId:w.id,title:w.label})):console.error("not found")}return{...e,init:O,setInteractiveController:o,createPlayer:m,removeAll:b,getActivePlayer:function(){return n},activePlayerChanged:a}}var E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ve={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},A={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var Qs=W(Ct(),1);import{Subscription as Tu}from"@vkontakte/videoplayer-shared";var Et=class{constructor({player:e,container:r,branches:n,selectBranches:i,interactiveEvents:s,globalEvents:l,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:p,disabledControls$:f,onRemove:y}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(J(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())this.container.show?.(),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)=>{this.isSelectedControlEvent=!0,i!==!1&&(this.removeView(),this.emitContainerVisibilityEvent(!1)),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),s(),this.removeView(),this.emitContainerVisibilityEvent(!1))},isEOV:()=>this.gameState===4},n=is(this.selectBranches.onControlEvent,r);this.container.createView(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,Qs.default)(i,this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(ns(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(gr(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let p=this.gameState;this.gameState=3,p===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=gr(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(E.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=r,this.branches=n,this.selectBranches=i,this.subscription=new Tu,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=p&&ue(r.container.controls),this.disabledControls$=f,this.onRemove=y,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,r=!1){e?(this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.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(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.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){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,this.ignoreContainerEvent()||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 e=J(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}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 Ys=(t=[])=>t.reduce((e,r,n)=>{let i=(r?.controls??[]).filter(s=>!ot(s));if(vt(i)){let s=[r.startTime??0,r.endTime??1/0],l=r.id;if(!n)e.push({subjects:[l],range:s});else{let a=[],o=-1/0,p=1/0,f=[],y=[];for(let m=0;m<e.length;m++){let b=e[m];if(y.push(...b.subjects),b.range[0]<p&&(p=b.range[0]),b.range[1]>o&&(o=b.range[1]),s[0]>=b.range[0]&&s[1]<=b.range[1])return e[m].subjects.push(l),e;s[0]<b.range[0]&&s[1]>b.range[0]&&(a.push(m),f=f.concat(b.subjects)),s[0]>=b.range[0]&&s[0]<=b.range[1]&&(a.push(m),f=f.concat(b.subjects),s[0]=b.range[0]),s[1]>=b.range[0]&&s[1]<=b.range[1]&&(a.push(m),f=f.concat(b.subjects),s[1]=b.range[1])}if(y.push(l),s[0]<=p&&s[1]>=o)return[{subjects:y,range:s}];a.length&&a.reverse().forEach(m=>{e.splice(m,1)}),e.push({subjects:f.concat([l]),range:s})}}return e},[]).sort((e,r)=>e.range[0]-r.range[0]);var ka=W(Ct(),1),kr=W(gt(),1),Ma=W(Pa(),1);function Oa(){let t={};function e(){for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&delete t[a]}function r(a){let o={};for(let p in t)+p<=a&&(o[p]=t[p]);return o}function n(a){let o={};for(let p in t)+p>=a&&(o[p]=t[p]);return o}function i({timestamp:a,priority:o,initiator:p}){if(hr(a)){let f=t[a]??null;if(f&&o&&we(o,!0)){let y={},m=f[o];return m&&(y={...y,...m}),y=Z(y)?null:y,y&&we(p,!0)?y[p]??null:y}return f}return null}function s({timestamp:a,priority:o,initiator:p}){if(hr(a))if(t[a]){if(o&&we(o,!0))if(t[a][o]){if(p&&we(p,!0))if(t[a][o][p]){if(delete t[a][o][p],!Z(t[a][o]))return!0}else return!1;if(delete t[a][o],!Z(t[a]))return!0}else return!1;return delete t[a]}else return!1;return!1}function l({timestamp:a,priority:o,initiator:p,...f}){t[a]?.[o]?.[p]?t[a][o][p].push({...f}):t[a]?.[o]?t[a][o]={...t[a][o],[p]:[{...f}]}:t[a]?t[a]={...t[a],[o]:{[p]:[{...f}]}}:t[a]={[o]:{[p]:[{...f}]}}}return{map:t,remove:s,add:l,removeAll:e,get:i,getLte:r,getGte:n}}var hp=[T.expect,T.setNextBranch],dp=1/0;function Va(t){let e=t,r,n=fp(),i=Oa(),s,l=()=>{m(),w()},a=u=>{i.add.call(void 0,u),P()},o=(u=[])=>{for(let h of u)if(h.action(),(0,ka.default)(hp,h.actionType))break},p=(u=1/0)=>{let h=xt(i.get({timestamp:u,priority:"control"})??{}),d=xt(i.get({timestamp:u,priority:"container"})??{}),v=xt(i.get({timestamp:u,priority:"chapter"})??{});return[...h,...d,...v]},f=u=>{n.isReady(u)&&o(p(u))},y=()=>{o([...xt(i.get({timestamp:1/0,priority:"chapter"})??{})])},m=()=>{r&&(s?.unsubscribe(),r=void 0)},b=u=>{},P=()=>{r||(r=()=>setTimeout(()=>{f(1/0)}),s=e.events.ended$.subscribe(r))},O=u=>{m(),e=u},x=u=>{u.priority==="container"&&n.resetCalled(u.timestamp),i.remove(u)},w=()=>{n.release(),i.removeAll()};return{setPlayer:O,add:a,remove:x,exec:f,execEndOfVideo:y,listen:P,unlisten:m,release:l,containersEventsCallState:n,getPreparedToExecActions:p}}function fp(){let t=new Map;return{setCalled:({timestamp:l,id:a})=>{let o=t.get(l);o&&o[a]!==void 0&&(o[a]=!0)},setData:(l=[])=>{for(let a of l){let o=a.endTime??dp,p=t.get(o);t.set(o,{...p,[a.id]:!1})}},resetCalled:l=>{let a=t.get(l);if(a)for(let o in a)a[o]=!1},isReady:l=>{let a=t.get(l);return a?!(0,kr.default)(a).some(o=>!o):!0},release:()=>t.clear()}}function xt(t){return(0,Ma.default)((0,kr.default)(t)).sort(e=>e.actionType===T.expect?-1:1)}var ja={videoContentHeight:0,videoContentWidth:0},La=(t,e)=>{let{height:r,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(r&&n))return ja;let{clientHeight:i,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(i&&s))return ja;let l=r/n,a=i/s,o,p;return a>l?(p=s,o=s*l):a<l?(p=i/l,o=i):(p=s,o=i),{videoContentWidth:p,videoContentHeight:o}};var mp=250;function $a(t){let e=()=>{},r=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){let{parentElement:o,player:p}=t();if(o&&p){let{videoContentWidth:f,videoContentHeight:y}=La(o,p);o.style.setProperty("--interactive-content-width",`${f}px`),o.style.setProperty("--interactive-content-height",`${y}px`),o.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function i(){let{parentElement:a}=t();a.removeAttribute("style")}let s=Te(a=>{let{fns:o=[]}=t();n(a);for(let p of o)p()},mp);function l(){e=void 0,r.disconnect(),i()}return{resizeObserver:r,calc:()=>{e?.()},release:l}}var yp=t=>Math.floor(Math.random()*t),_a=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},Fa=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 qa=t=>{let e=t.length,r=yp(e);return t[r]},Na=1,Ba=t=>{let e=0;for(let n=0;n<t.length;++n)e+=t[n].weight??Na;let r=Math.random()*e;e=0;for(let n=0;n<t.length-1;++n)if(e+=t[n].weight??Na,e>=r)return t[n];return t[t.length-1]};var Da={shouldOpenNow:!0,isDetachContainer:!0},Ha="after-expect";var Mr=(t,e=!1)=>({...t,args:e?{...t.args,...Da}:{...Da,...t.args}}),za=({globalEventEmitter:t,globalEvents:e,player:r,interactiveEvents:n})=>{let i={isExpect:!1},s=()=>{i.isExpect&&(i.isExpect=!1)},l=({action:u,controlType:h,controlId:d,containerId:v,branches:g=[],onEvent:C,isEOV:S=()=>!1,isDisabled:R=()=>!1})=>{let I=Mr(u,S()),k={timestamp:1/0,priority:"control",initiator:d,actionType:I.type},F=R(),q=t.emit.bind(t,E.interactives,{subjectId:d,subjectType:h,subjectName:"control",type:F?A.actionChoiceCanceled:A.actionChoice,actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:v,...I.args}}),B=()=>{e.interactiveActionChoice$.next({subjectId:d,subjectType:h,subjectName:"control",type:F?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:v,...I.args}})};if(F){q(),B();return}switch(I.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{let z=g.find(ee=>ee.id===I.args.branchId);if(!z)return;C(I.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),q(),B(),I.args.shouldOpenNow?O({subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{chapterId:z.chapterId,autoSelect:!1}}):n.add({...k,action:O.bind(null,{subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{chapterId:z.chapterId,autoSelect:!1}})});return}case T.continuePlayback.trim().toLowerCase():{C(I.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),q(),B(),I.args.shouldOpenNow?P({subjectId:d,subjectName:"control",subjectType:h,action:u}):n.add({...k,action:P.bind(null,{subjectId:d,subjectName:"control",subjectType:h,action:u})});return}case T.openURI.trim().toLowerCase():{C(I.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),q(),B(),I.args.shouldOpenNow?w({subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}}):n.add({...k,action:w.bind(null,{subjectId:d,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}})});return}default:{let z="Unexpected control event",ee=new M(1,1,{message:z});f(ee,z);return}}},a=({action:u,container:{id:h,endTime:d},branches:v=[],isEOV:g=!1,autoSelected:C=!1})=>{let S=Mr(u,g),R={timestamp:!S.args.shouldOpenNow||g?1/0:d??1/0,priority:"container",initiator:h,actionType:S.type},I=t.emit.bind(t,E.interactives,{subjectId:h,subjectName:"container",type:A.actionChoice,actionType:S.type,payload:{invokeImmediately:S.args.shouldOpenNow,...S.args}}),k=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"container",type:"action-choice",actionType:S.type,payload:{invokeImmediately:S.args.shouldOpenNow,...S.args}})};switch(S.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{let F=v.find(q=>q.id===S.args.branchId);if(!F)return;I(),k(),n.add({...R,action:O.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{chapterId:F.chapterId,autoSelect:C}})});return}case T.setMaxWeightBranch.trim().toLowerCase():return;case T.setMinWeightBranch.trim().toLowerCase():return;case T.setRandomBranch.trim().toLowerCase():return;case T.setWeightlessRandomBranch.trim().toLowerCase():return;case T.continuePlayback.trim().toLowerCase():{I(),k(),n.add({...R,action:P.bind(null,{subjectId:h,subjectName:"container",action:S})});return}case T.openURI.trim().toLowerCase():{I(),k(),n.add({...R,action:w.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{URI:u.args.uri}})});return}default:{let F="Unexpected container event",q=new M(1,1,{message:F});f(q,F);return}}};function o({container:u,branches:h,isEOV:d=!1}){let v=Cr(u.events);if(v){let g=Mr(v.action,d);t.emit(E.interactives,{subjectId:u.id,subjectName:"container",type:A.actionChoice,actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:g.type,payload:{invokeImmediately:g.args.shouldOpenNow,...g.args}}),n.add({timestamp:d?1/0:u.endTime??1/0,priority:"container",initiator:u.id,actionType:T.expect,action:m.bind(null,{subjectId:u.id,subjectName:"container"})}),i.isExpect=!0}else for(let g of u.events??[])a({action:g.action,container:u,branches:h,isEOV:d})}let p=({chapterId:u,action:h,branches:d=[]})=>{let v=t.emit.bind(t,E.interactives,{subjectId:u,subjectName:"chapter",type:A.actionChoice,actionType:h.type,payload:h.args}),g=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:h.type,payload:h.args})};switch(h.type.trim().toLowerCase()){case T.setNextBranch.trim().toLowerCase():{let C=d.find(S=>S.id===h.args.branchId);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setWeightlessRandomBranch.trim().toLowerCase():{let C=qa(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setRandomBranch.trim().toLowerCase():{let C=Ba(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setMaxWeightBranch.trim().toLowerCase():{let C=Fa(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.setMinWeightBranch.trim().toLowerCase():{let C=_a(d);return C?.chapterId?(v(),g(),O.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:C.chapterId,autoSelect:!0}})):void 0}case T.continuePlayback.trim().toLowerCase():return v(),g(),P.bind(null,{subjectId:u,subjectName:"chapter",action:h});case T.openURI.trim().toLowerCase():return v(),g(),w.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:{let C="Unexpected chapter event",S=new M(1,1,{message:C});f(S,C);return}}};function f(u,h){console.error(h),e.error$.next(u),t.emit(E.errors,u)}function y(u){let h=Cr(u.events);if(h){if(U(u))return;t.emit(E.interactives,{subjectId:u.id,subjectName:"chapter",type:A.actionChoice,actionType:h.action.type,payload:h.action.args}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"chapter",type:"action-choice",actionType:h.action.type,payload:h.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:T.expect,action:m.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else u.events?.forEach(d=>{let v=p({chapterId:u.id,action:d.action,branches:u.branches});v&&n.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:d.action.type,action:v})})}let m=({subjectId:u,subjectName:h})=>{r.pause(),t.emit(E.interactives,{subjectId:u,subjectName:h,type:A.actionExecution,actionType:T.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:T.expect})},b=({subjectId:u,subjectName:h})=>{r.info.isEnded$.getValue()?n.execEndOfVideo():r.play(),t.emit(E.interactives,{subjectId:u,subjectName:h,type:A.actionExecution,actionType:Ha}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:Ha})},P=({subjectId:u,subjectName:h,subjectType:d,action:v})=>{t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type})},O=({subjectId:u,subjectName:h,subjectType:d,action:v,payload:g})=>{g.behaviour="change-chapter",t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type,payload:g}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type,payload:g})},x=({subjectId:u,subjectName:h,subjectType:d,action:v,payload:g})=>{g.behaviour="change-manifest",t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type,payload:g}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type,payload:g})},w=({subjectId:u,subjectName:h,subjectType:d,action:v,payload:g})=>{if(!g.URI)return;let C=window.open(g.URI,"_blank","noopener,noreferrer");C&&(C.opener=null),t.emit(E.interactives,{subjectId:u,subjectName:h,subjectType:d,type:A.actionExecution,actionType:v.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:d,type:"action-execution",actionType:v.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:p,onExpectEvent:m,expectEventHandler:b,setManifestChapterEvents:y,setManifestContainerEvents:o,stopExpect:s,state:i}};var Lr=W(pr(),1);import{Subscription as Ep,Subject as jr,ValueSubject as Le}from"@vkontakte/videoplayer-shared";var Vr=(t,e)=>{let r={};return t.map(n=>{if(!r[n]){let i=e.chapters.find(l=>l.id===n);if(!i)return null;let s=e.media.videos.find(l=>i.videoId===l.id);if(!s)return null;r[n]=Wa(s)}return r[n]}).filter(Boolean)},bp=t=>{for(let e of t.variants)if(gp(e)&&e.payload)return e.payload.id},gp=t=>!!(t.type==="custom"&&t.payload&&t.payload.type==="vk"),Wa=t=>{let e=bp(t);if(!e)return null;let r=e.split("_").pop();return r?parseInt(r,10):null},Cp=(t,e)=>{for(let r of t.media.videos)if(e===Wa(r)){for(let n of t.chapters)if(n.videoId===r.id)return n.id;return}},Ka=(t,e)=>t.reduce((r,n)=>{let i=Cp(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 Le([]),hasPrevChapter$:new Le(!1),prevChapter$:new Le(null),isInitialChapter$:new Le(!1),isGoBackLimited$:new Le(!1)};this.#r=null;this.#a=!1;this.#e=null;this.#u=null;this.events={inited$:new jr,destroyed$:new jr,error$:new jr};this.#n=null;this.#i=null;this.#t=null;this.#o=new Ep;this.#l=!1;this.#c=0;this.#n=r,this.#t=e,this.#i=n,this.#r=i,this.#s=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,Lr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#s.maxLength-1)}))}#r;#s;#a;#e;#u;#n;#i;#t;#o;#l;#c;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.#a||(this.#a=!0,this.events.inited$.next({initChapterId:r}))}get inited(){return this.#a}async updateHistory(e,r=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,i=e.length-this.#s.maxLength,s=i>0?e.slice(i):e,l=Vr(s,n);if(this.#u=l,this.state.history$.next(s),!(!r||!this.#r||!this.#n))try{await this.#r.save(this.#n,l)}catch{let o=new M(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#t?.emit(E.errors,o)}}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(E.errors,n)}this.#l=!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(E.errors,s)}let n=Ka(r,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,Lr.default)(e,-1)||this.#s.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return Vr([e],this.#e).pop()}return null}destroy(){this.#n=null,this.#r=null,this.#i=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#t?.emit(E.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var Tt=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 St=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;