@vkontakte/videoplayer-interactive 1.0.54-dev.08f9b022.0 → 1.0.54-dev.4058ce66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esnext.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.54-dev.08f9b022.0
3
- * Tue, 25 Nov 2025 11:57:06 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.54-dev.4058ce66.0
3
+ * Tue, 25 Nov 2025 20:19:28 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-54/doc/
5
5
  */
6
- var Za=Object.create;var pi=Object.defineProperty;var Ja=Object.getOwnPropertyDescriptor;var el=Object.getOwnPropertyNames;var tl=Object.getPrototypeOf,rl=Object.prototype.hasOwnProperty;var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var il=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of el(e))!rl.call(r,n)&&n!==t&&pi(r,n,{get:()=>e[n],enumerable:!(i=Ja(e,n))||i.enumerable});return r};var W=(r,e,t)=>(t=r!=null?Za(tl(r)):{},il(e||!r||!r.__esModule?pi(t,"default",{value:r,enumerable:!0}):t,r));var K=p((Jt,Ei)=>{"use strict";var xe=function(r){return r&&r.Math===Math&&r};Ei.exports=xe(typeof globalThis=="object"&&globalThis)||xe(typeof window=="object"&&window)||xe(typeof self=="object"&&self)||xe(typeof global=="object"&&global)||xe(typeof Jt=="object"&&Jt)||function(){return this}()||Function("return this")()});var q=p((hd,Ti)=>{"use strict";Ti.exports=function(r){try{return!!r()}catch{return!0}}});var Ae=p((dd,Ii)=>{"use strict";var al=q();Ii.exports=!al(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Ri=p((md,wi)=>{"use strict";var ll=Ae(),Si=Function.prototype,xi=Si.apply,Ai=Si.call;wi.exports=typeof Reflect=="object"&&Reflect.apply||(ll?Ai.bind(xi):function(){return Ai.apply(xi,arguments)})});var H=p((fd,Pi)=>{"use strict";var Oi=Ae(),ki=Function.prototype,er=ki.call,cl=Oi&&ki.bind.bind(er,er);Pi.exports=Oi?cl:function(r){return function(){return er.apply(r,arguments)}}});var Se=p((vd,Mi)=>{"use strict";var Vi=H(),pl=Vi({}.toString),ul=Vi("".slice);Mi.exports=function(r){return ul(pl(r),8,-1)}});var tr=p((bd,_i)=>{"use strict";var hl=Se(),dl=H();_i.exports=function(r){if(hl(r)==="Function")return dl(r)}});var D=p((yd,Li)=>{"use strict";var rr=typeof document=="object"&&document.all;Li.exports=typeof rr>"u"&&rr!==void 0?function(r){return typeof r=="function"||r===rr}:function(r){return typeof r=="function"}});var ie=p((gd,Fi)=>{"use strict";var ml=q();Fi.exports=!ml(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var at=p((Cd,Ni)=>{"use strict";var fl=Ae(),st=Function.prototype.call;Ni.exports=fl?st.bind(st):function(){return st.apply(st,arguments)}});var ir=p(Bi=>{"use strict";var $i={}.propertyIsEnumerable,ji=Object.getOwnPropertyDescriptor,vl=ji&&!$i.call({1:2},1);Bi.f=vl?function(e){var t=ji(this,e);return!!t&&t.enumerable}:$i});var nr=p((Td,qi)=>{"use strict";qi.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Hi=p((Id,Di)=>{"use strict";var bl=H(),yl=q(),gl=Se(),or=Object,Cl=bl("".split);Di.exports=yl(function(){return!or("z").propertyIsEnumerable(0)})?function(r){return gl(r)==="String"?Cl(r,""):or(r)}:or});var sr=p((xd,Ui)=>{"use strict";Ui.exports=function(r){return r==null}});var ar=p((Ad,Gi)=>{"use strict";var El=sr(),Tl=TypeError;Gi.exports=function(r){if(El(r))throw new Tl("Can't call method on "+r);return r}});var we=p((Sd,Wi)=>{"use strict";var Il=Hi(),xl=ar();Wi.exports=function(r){return Il(xl(r))}});var ue=p((wd,zi)=>{"use strict";var Al=D();zi.exports=function(r){return typeof r=="object"?r!==null:Al(r)}});var Re=p((Rd,Ki)=>{"use strict";Ki.exports={}});var lt=p((Od,Xi)=>{"use strict";var lr=Re(),cr=K(),Sl=D(),Qi=function(r){return Sl(r)?r:void 0};Xi.exports=function(r,e){return arguments.length<2?Qi(lr[r])||Qi(cr[r]):lr[r]&&lr[r][e]||cr[r]&&cr[r][e]}});var Zi=p((kd,Yi)=>{"use strict";var wl=H();Yi.exports=wl({}.isPrototypeOf)});var rn=p((Pd,tn)=>{"use strict";var Rl=K(),Ji=Rl.navigator,en=Ji&&Ji.userAgent;tn.exports=en?String(en):""});var pn=p((Vd,cn)=>{"use strict";var ln=K(),pr=rn(),nn=ln.process,on=ln.Deno,sn=nn&&nn.versions||on&&on.version,an=sn&&sn.v8,U,ct;an&&(U=an.split("."),ct=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!ct&&pr&&(U=pr.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=pr.match(/Chrome\/(\d+)/),U&&(ct=+U[1])));cn.exports=ct});var ur=p((Md,hn)=>{"use strict";var un=pn(),Ol=q(),kl=K(),Pl=kl.String;hn.exports=!!Object.getOwnPropertySymbols&&!Ol(function(){var r=Symbol("symbol detection");return!Pl(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&un&&un<41})});var hr=p((_d,dn)=>{"use strict";var Vl=ur();dn.exports=Vl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var dr=p((Ld,mn)=>{"use strict";var Ml=lt(),_l=D(),Ll=Zi(),Fl=hr(),Nl=Object;mn.exports=Fl?function(r){return typeof r=="symbol"}:function(r){var e=Ml("Symbol");return _l(e)&&Ll(e.prototype,Nl(r))}});var vn=p((Fd,fn)=>{"use strict";var $l=String;fn.exports=function(r){try{return $l(r)}catch{return"Object"}}});var mr=p((Nd,bn)=>{"use strict";var jl=D(),Bl=vn(),ql=TypeError;bn.exports=function(r){if(jl(r))return r;throw new ql(Bl(r)+" is not a function")}});var gn=p(($d,yn)=>{"use strict";var Dl=mr(),Hl=sr();yn.exports=function(r,e){var t=r[e];return Hl(t)?void 0:Dl(t)}});var En=p((jd,Cn)=>{"use strict";var fr=at(),vr=D(),br=ue(),Ul=TypeError;Cn.exports=function(r,e){var t,i;if(e==="string"&&vr(t=r.toString)&&!br(i=fr(t,r))||vr(t=r.valueOf)&&!br(i=fr(t,r))||e!=="string"&&vr(t=r.toString)&&!br(i=fr(t,r)))return i;throw new Ul("Can't convert object to primitive value")}});var In=p((Bd,Tn)=>{"use strict";Tn.exports=!0});var Sn=p((qd,An)=>{"use strict";var xn=K(),Gl=Object.defineProperty;An.exports=function(r,e){try{Gl(xn,r,{value:e,configurable:!0,writable:!0})}catch{xn[r]=e}return e}});var pt=p((Dd,On)=>{"use strict";var Wl=In(),zl=K(),Kl=Sn(),wn="__core-js_shared__",Rn=On.exports=zl[wn]||Kl(wn,{});(Rn.versions||(Rn.versions=[])).push({version:"3.43.0",mode:Wl?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var yr=p((Hd,Pn)=>{"use strict";var kn=pt();Pn.exports=function(r,e){return kn[r]||(kn[r]=e||{})}});var Oe=p((Ud,Vn)=>{"use strict";var Ql=ar(),Xl=Object;Vn.exports=function(r){return Xl(Ql(r))}});var he=p((Gd,Mn)=>{"use strict";var Yl=H(),Zl=Oe(),Jl=Yl({}.hasOwnProperty);Mn.exports=Object.hasOwn||function(e,t){return Jl(Zl(e),t)}});var gr=p((Wd,_n)=>{"use strict";var ec=H(),tc=0,rc=Math.random(),ic=ec(1.1.toString);_n.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+ic(++tc+rc,36)}});var ke=p((zd,Fn)=>{"use strict";var nc=K(),oc=yr(),Ln=he(),sc=gr(),ac=ur(),lc=hr(),de=nc.Symbol,Cr=oc("wks"),cc=lc?de.for||de:de&&de.withoutSetter||sc;Fn.exports=function(r){return Ln(Cr,r)||(Cr[r]=ac&&Ln(de,r)?de[r]:cc("Symbol."+r)),Cr[r]}});var Bn=p((Kd,jn)=>{"use strict";var pc=at(),Nn=ue(),$n=dr(),uc=gn(),hc=En(),dc=ke(),mc=TypeError,fc=dc("toPrimitive");jn.exports=function(r,e){if(!Nn(r)||$n(r))return r;var t=uc(r,fc),i;if(t){if(e===void 0&&(e="default"),i=pc(t,r,e),!Nn(i)||$n(i))return i;throw new mc("Can't convert object to primitive value")}return e===void 0&&(e="number"),hc(r,e)}});var Er=p((Qd,qn)=>{"use strict";var vc=Bn(),bc=dr();qn.exports=function(r){var e=vc(r,"string");return bc(e)?e:e+""}});var Un=p((Xd,Hn)=>{"use strict";var yc=K(),Dn=ue(),Tr=yc.document,gc=Dn(Tr)&&Dn(Tr.createElement);Hn.exports=function(r){return gc?Tr.createElement(r):{}}});var Ir=p((Yd,Gn)=>{"use strict";var Cc=ie(),Ec=q(),Tc=Un();Gn.exports=!Cc&&!Ec(function(){return Object.defineProperty(Tc("div"),"a",{get:function(){return 7}}).a!==7})});var Kn=p(zn=>{"use strict";var Ic=ie(),xc=at(),Ac=ir(),Sc=nr(),wc=we(),Rc=Er(),Oc=he(),kc=Ir(),Wn=Object.getOwnPropertyDescriptor;zn.f=Ic?Wn:function(e,t){if(e=wc(e),t=Rc(t),kc)try{return Wn(e,t)}catch{}if(Oc(e,t))return Sc(!xc(Ac.f,e,t),e[t])}});var Xn=p((Jd,Qn)=>{"use strict";var Pc=q(),Vc=D(),Mc=/#|\.prototype\./,Pe=function(r,e){var t=Lc[_c(r)];return t===Nc?!0:t===Fc?!1:Vc(e)?Pc(e):!!e},_c=Pe.normalize=function(r){return String(r).replace(Mc,".").toLowerCase()},Lc=Pe.data={},Fc=Pe.NATIVE="N",Nc=Pe.POLYFILL="P";Qn.exports=Pe});var xr=p((em,Zn)=>{"use strict";var Yn=tr(),$c=mr(),jc=Ae(),Bc=Yn(Yn.bind);Zn.exports=function(r,e){return $c(r),e===void 0?r:jc?Bc(r,e):function(){return r.apply(e,arguments)}}});var eo=p((tm,Jn)=>{"use strict";var qc=ie(),Dc=q();Jn.exports=qc&&Dc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var ro=p((rm,to)=>{"use strict";var Hc=ue(),Uc=String,Gc=TypeError;to.exports=function(r){if(Hc(r))return r;throw new Gc(Uc(r)+" is not an object")}});var oo=p(no=>{"use strict";var Wc=ie(),zc=Ir(),Kc=eo(),ut=ro(),io=Er(),Qc=TypeError,Ar=Object.defineProperty,Xc=Object.getOwnPropertyDescriptor,Sr="enumerable",wr="configurable",Rr="writable";no.f=Wc?Kc?function(e,t,i){if(ut(e),t=io(t),ut(i),typeof e=="function"&&t==="prototype"&&"value"in i&&Rr in i&&!i[Rr]){var n=Xc(e,t);n&&n[Rr]&&(e[t]=i.value,i={configurable:wr in i?i[wr]:n[wr],enumerable:Sr in i?i[Sr]:n[Sr],writable:!1})}return Ar(e,t,i)}:Ar:function(e,t,i){if(ut(e),t=io(t),ut(i),zc)try{return Ar(e,t,i)}catch{}if("get"in i||"set"in i)throw new Qc("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var ao=p((nm,so)=>{"use strict";var Yc=ie(),Zc=oo(),Jc=nr();so.exports=Yc?function(r,e,t){return Zc.f(r,e,Jc(1,t))}:function(r,e,t){return r[e]=t,r}});var ve=p((om,co)=>{"use strict";var Ve=K(),ep=Ri(),tp=tr(),rp=D(),ip=Kn().f,np=Xn(),me=Re(),op=xr(),fe=ao(),lo=he();pt();var sp=function(r){var e=function(t,i,n){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,i)}return new r(t,i,n)}return ep(r,this,arguments)};return e.prototype=r.prototype,e};co.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,o=r.proto,a=i?Ve:n?Ve[t]:Ve[t]&&Ve[t].prototype,s=i?me:me[t]||fe(me,t,{})[t],l=s.prototype,c,d,m,f,b,R,E,y,u;for(f in e)c=np(i?f:t+(n?".":"#")+f,r.forced),d=!c&&a&&lo(a,f),R=s[f],d&&(r.dontCallGetSet?(u=ip(a,f),E=u&&u.value):E=a[f]),b=d&&E?E:e[f],!(!c&&!o&&typeof R==typeof b)&&(r.bind&&d?y=op(b,Ve):r.wrap&&d?y=sp(b):o&&rp(b)?y=tp(b):y=b,(r.sham||b&&b.sham||R&&R.sham)&&fe(y,"sham",!0),fe(s,f,y),o&&(m=t+"Prototype",lo(me,m)||fe(me,m,{}),fe(me[m],f,b),r.real&&l&&(c||!l[f])&&fe(l,f,b)))}});var uo=p((sm,po)=>{"use strict";var ap=Math.ceil,lp=Math.floor;po.exports=Math.trunc||function(e){var t=+e;return(t>0?lp:ap)(t)}});var Me=p((am,ho)=>{"use strict";var cp=uo();ho.exports=function(r){var e=+r;return e!==e||e===0?0:cp(e)}});var fo=p((lm,mo)=>{"use strict";var pp=Me(),up=Math.max,hp=Math.min;mo.exports=function(r,e){var t=pp(r);return t<0?up(t+e,0):hp(t,e)}});var bo=p((cm,vo)=>{"use strict";var dp=Me(),mp=Math.min;vo.exports=function(r){var e=dp(r);return e>0?mp(e,9007199254740991):0}});var _e=p((pm,yo)=>{"use strict";var fp=bo();yo.exports=function(r){return fp(r.length)}});var Or=p((um,Co)=>{"use strict";var vp=we(),bp=fo(),yp=_e(),go=function(r){return function(e,t,i){var n=vp(e),o=yp(n);if(o===0)return!r&&-1;var a=bp(i,o),s;if(r&&t!==t){for(;o>a;)if(s=n[a++],s!==s)return!0}else for(;o>a;a++)if((r||a in n)&&n[a]===t)return r||a||0;return!r&&-1}};Co.exports={includes:go(!0),indexOf:go(!1)}});var ht=p((hm,Eo)=>{"use strict";Eo.exports=function(){}});var To=p(()=>{"use strict";var gp=ve(),Cp=Or().includes,Ep=q(),Tp=ht(),Ip=Ep(function(){return!Array(1).includes()});gp({target:"Array",proto:!0,forced:Ip},{includes:function(e){return Cp(this,e,arguments.length>1?arguments[1]:void 0)}});Tp("includes")});var dt=p((fm,Io)=>{"use strict";var xp=lt();Io.exports=xp});var Ao=p((vm,xo)=>{"use strict";To();var Ap=dt();xo.exports=Ap("Array","includes")});var wo=p((bm,So)=>{"use strict";var Sp=Ao();So.exports=Sp});var mt=p((ym,Ro)=>{"use strict";var wp=wo();Ro.exports=wp});var Ko=p(()=>{"use strict";var Lp=ve(),Fp=Oe(),Np=_e(),$p=Me(),jp=ht();Lp({target:"Array",proto:!0},{at:function(e){var t=Fp(this),i=Np(t),n=$p(e),o=n>=0?n:i+n;return o<0||o>=i?void 0:t[o]}});jp("at")});var Xo=p((Qf,Qo)=>{"use strict";Ko();var Bp=dt();Qo.exports=Bp("Array","at")});var Zo=p((Xf,Yo)=>{"use strict";var qp=Xo();Yo.exports=qp});var jr=p((Yf,Jo)=>{"use strict";var Dp=Zo();Jo.exports=Dp});var os=p((mv,ns)=>{"use strict";var Gp=yr(),Wp=gr(),is=Gp("keys");ns.exports=function(r){return is[r]||(is[r]=Wp(r))}});var as=p((fv,ss)=>{"use strict";var zp=q();ss.exports=!zp(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var ps=p((vv,cs)=>{"use strict";var Kp=he(),Qp=D(),Xp=Oe(),Yp=os(),Zp=as(),ls=Yp("IE_PROTO"),Br=Object,Jp=Br.prototype;cs.exports=Zp?Br.getPrototypeOf:function(r){var e=Xp(r);if(Kp(e,ls))return e[ls];var t=e.constructor;return Qp(t)&&e instanceof t?t.prototype:e instanceof Br?Jp:null}});var hs=p((bv,us)=>{"use strict";us.exports={}});var fs=p((yv,ms)=>{"use strict";var eu=H(),qr=he(),tu=we(),ru=Or().indexOf,iu=hs(),ds=eu([].push);ms.exports=function(r,e){var t=tu(r),i=0,n=[],o;for(o in t)!qr(iu,o)&&qr(t,o)&&ds(n,o);for(;e.length>i;)qr(t,o=e[i++])&&(~ru(n,o)||ds(n,o));return n}});var bs=p((gv,vs)=>{"use strict";vs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var gs=p((Cv,ys)=>{"use strict";var nu=fs(),ou=bs();ys.exports=Object.keys||function(e){return nu(e,ou)}});var Dr=p((Ev,xs)=>{"use strict";var Es=ie(),su=q(),Ts=H(),au=ps(),lu=gs(),cu=we(),pu=ir().f,Is=Ts(pu),uu=Ts([].push),hu=Es&&su(function(){var r=Object.create(null);return r[2]=2,!Is(r,2)}),Cs=function(r){return function(e){for(var t=cu(e),i=lu(t),n=hu&&au(t)===null,o=i.length,a=0,s=[],l;o>a;)l=i[a++],(!Es||(n?l in t:Is(t,l)))&&uu(s,r?[l,t[l]]:t[l]);return s}};xs.exports={entries:Cs(!0),values:Cs(!1)}});var As=p(()=>{"use strict";var du=ve(),mu=Dr().entries;du({target:"Object",stat:!0},{entries:function(e){return mu(e)}})});var ws=p((xv,Ss)=>{"use strict";As();var fu=Re();Ss.exports=fu.Object.entries});var Os=p((Av,Rs)=>{"use strict";var vu=ws();Rs.exports=vu});var Ps=p((Sv,ks)=>{"use strict";var bu=Os();ks.exports=bu});var Ns=p(()=>{"use strict";var Au=ve(),Su=Dr().values;Au({target:"Object",stat:!0},{values:function(e){return Su(e)}})});var js=p((ob,$s)=>{"use strict";Ns();var wu=Re();$s.exports=wu.Object.values});var qs=p((sb,Bs)=>{"use strict";var Ru=js();Bs.exports=Ru});var Nt=p((ab,Ds)=>{"use strict";var Ou=qs();Ds.exports=Ou});var Jr=p((Pb,Ks)=>{"use strict";var Lu=Se();Ks.exports=Array.isArray||function(e){return Lu(e)==="Array"}});var Xs=p((Vb,Qs)=>{"use strict";var Fu=TypeError,Nu=9007199254740991;Qs.exports=function(r){if(r>Nu)throw Fu("Maximum allowed index exceeded");return r}});var Js=p((Mb,Zs)=>{"use strict";var $u=Jr(),ju=_e(),Bu=Xs(),qu=xr(),Ys=function(r,e,t,i,n,o,a,s){for(var l=n,c=0,d=a?qu(a,s):!1,m,f;c<i;)c in t&&(m=d?d(t[c],c,e):t[c],o>0&&$u(m)?(f=ju(m),l=Ys(r,e,m,f,l,o-1)-1):(Bu(l+1),r[l]=m),l++),c++;return l};Zs.exports=Ys});var ra=p((_b,ta)=>{"use strict";var Du=ke(),Hu=Du("toStringTag"),ea={};ea[Hu]="z";ta.exports=String(ea)==="[object z]"});var na=p((Lb,ia)=>{"use strict";var Uu=ra(),Gu=D(),jt=Se(),Wu=ke(),zu=Wu("toStringTag"),Ku=Object,Qu=jt(function(){return arguments}())==="Arguments",Xu=function(r,e){try{return r[e]}catch{}};ia.exports=Uu?jt:function(r){var e,t,i;return r===void 0?"Undefined":r===null?"Null":typeof(t=Xu(e=Ku(r),zu))=="string"?t:Qu?jt(e):(i=jt(e))==="Object"&&Gu(e.callee)?"Arguments":i}});var sa=p((Fb,oa)=>{"use strict";var Yu=H(),Zu=D(),ei=pt(),Ju=Yu(Function.toString);Zu(ei.inspectSource)||(ei.inspectSource=function(r){return Ju(r)});oa.exports=ei.inspectSource});var ha=p((Nb,ua)=>{"use strict";var eh=H(),th=q(),aa=D(),rh=na(),ih=lt(),nh=sa(),la=function(){},ca=ih("Reflect","construct"),ti=/^\s*(?:class|function)\b/,oh=eh(ti.exec),sh=!ti.test(la),We=function(e){if(!aa(e))return!1;try{return ca(la,[],e),!0}catch{return!1}},pa=function(e){if(!aa(e))return!1;switch(rh(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return sh||!!oh(ti,nh(e))}catch{return!0}};pa.sham=!0;ua.exports=!ca||th(function(){var r;return We(We.call)||!We(Object)||!We(function(){r=!0})||r})?pa:We});var va=p(($b,fa)=>{"use strict";var da=Jr(),ah=ha(),lh=ue(),ch=ke(),ph=ch("species"),ma=Array;fa.exports=function(r){var e;return da(r)&&(e=r.constructor,ah(e)&&(e===ma||da(e.prototype))?e=void 0:lh(e)&&(e=e[ph],e===null&&(e=void 0))),e===void 0?ma:e}});var ya=p((jb,ba)=>{"use strict";var uh=va();ba.exports=function(r,e){return new(uh(r))(e===0?0:e)}});var ga=p(()=>{"use strict";var hh=ve(),dh=Js(),mh=Oe(),fh=_e(),vh=Me(),bh=ya();hh({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=mh(this),i=fh(t),n=bh(t,0);return n.length=dh(n,t,t,i,0,e===void 0?1:vh(e)),n}})});var Ca=p(()=>{"use strict";var yh=ht();yh("flat")});var Ta=p((Ub,Ea)=>{"use strict";ga();Ca();var gh=dt();Ea.exports=gh("Array","flat")});var xa=p((Gb,Ia)=>{"use strict";var Ch=Ta();Ia.exports=Ch});var Sa=p((Wb,Aa)=>{"use strict";var Eh=xa();Aa.exports=Eh});var ui="1.0.54-dev.08f9b022.0";import{fromEvent as zo,Subscription as _p}from"@vkontakte/videoplayer-shared";var Gt=class{constructor(e,t){this.layout=e;this.cssVarsManager=t}},Ye=class extends Gt{constructor(t,i){super(t,i);this.cssVarsManager=i;this.cssVarsManager=i}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,i){let n=this.cssVarsManager.getPropValue("--interactive-content-width"),o=this.cssVarsManager.getPropValue("--interactive-content-height"),a=this.cssVarsManager.getPropValue("--interactive-width"),s=this.cssVarsManager.getPropValue("--interactive-height"),l=2e-4;t.style.position="absolute",t.style.width=`calc(${n} * (${i.width} + ${l}))`,t.style.height=`calc(${o} * ${i.height})`,t.style.left=`calc(${n} * ${i.x} + ((${a} - ${n}) / 2))`,t.style.top=`calc(${o} * ${i.y} + ((${s} - ${o}) / 2))`}};import{Subject as nl}from"@vkontakte/videoplayer-shared";function hi(r){return"features"in r}var M=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};function Ze({emitter$:r,error:e,subjectId:t,message:i="",severity:n=1,category:o=1}){let a=new M(n,o,{message:i,error:e,details:{id:t}});r.next(a)}var le=class{constructor(e,t,i){this.error$=new nl;this.container=e,this.options=i,this.factories=new Map,this.controls=[],this.setControls(),this.cssVarsManager=t}featureIsEnabled(e){return this.options&&this.options.features&&hi(this.options)&&this.options.features[e]}onError(e="",t){Ze({emitter$:this.error$,error:t,message:e,subjectId:this.container.id})}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((e,t)=>{let i=t.type.trim().toLowerCase(),n=this.factories.get(i);if(n){let o=n(t,this.options);if(o)return[...e,o]}return[...e]},[])||[]}};import{fromEvent as Fe,once as No}from"@vkontakte/videoplayer-shared";var Y=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Z=r=>Y(r,"Object"),Je=r=>Y(r,"String"),et=r=>Y(r,"Array"),tt=r=>Y(r,"Number"),di=r=>Y(r,"Function"),mi=r=>Y(r,"Boolean"),Kt=r=>tt(r)&&!isNaN(r);var te=r=>Z(r)&&Object.keys(r).length===0,Qt=r=>et(r)&&!r.length;var Ee=(r,e)=>Je(r)&&(e?r.trim():r).length;function Te(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var fi="interactive",O={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderWidthRawValue:"1px",roundCornersRawValue:"0",borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0,shadowColorLight:"#fff",shadowColorDark:"#000",shadowColorAlpha:.24},vi=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(vi||{}),bi=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(bi||{}),yi=(i=>(i.start="left",i.end="right",i.center="center",i))(yi||{}),rt=({target:r,props:e})=>{r.style.alignItems=(e?.gravityVertical&&vi[e.gravityVertical])??"center",r.style.justifyContent=(e?.gravityHorizontal&&bi[e.gravityHorizontal])??"center",r.style.textAlign=(e?.alignment&&yi[e.alignment])??"center"},it=({target:r,props:e,fallback:t,dependsOn:i})=>{r.style.color=e?.text?.color??t.textColor,r.style.fontSize=`calc(${i.height} * ${e?.text?.size??t.textSize})`,r.textContent=e?.text?.value??t.textContent},nt=({target:r,props:e,fallback:t})=>{r.style.backgroundColor=Te(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},Ie=({target:r,props:e,fallback:t,dependsOn:i,useRawValues:n=!1})=>{let o=n?t.borderWidthRawValue:`calc(${i.height} * ${e?.shape?.border?.width??t.borderWidth})`,a=n?t.roundCornersRawValue:`calc(${i.height} * ${e?.shape?.roundCorners??t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Te(n?t.borderColor:e?.shape?.border?.color??t.borderColor,n?t.borderAlpha:e?.shape?.border?.alpha??t.borderAlpha),r.style.borderRadius=a},gi=({target:r,isDark:e,baseDimension:t,fallback:i})=>{let a=Te(i.shadowColorLight,i.shadowColorAlpha),s=Te(i.shadowColorDark,i.shadowColorAlpha),l=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,d=`0px 0px ${l} ${c} ${e?s:a}`;r.style.boxShadow=d},ce=({target:r,layoutParams:e,fallback:t})=>{let i=e.angle??t.angle;i=i&&i*-1,r.style.transform=`rotate(${i}rad)`};import{fromEvent as Le,Subject as Op,Subscription as kp}from"@vkontakte/videoplayer-shared";var Xt="interactive-control-tap",pe={common:Xt,animation:`${Xt}-animation`,visible:`${Xt}-visible`};var ol=60,ot=class{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:i=ol,useDimensionsBasedSize:n=!1}){this.onElementClick=e=>{if(!e.target||!e.currentTarget||this.clickCancelCondition())return;let t=e.currentTarget.parentElement;if(!t)return;let i=t.getBoundingClientRect(),n={width:this.useDimensionsBasedSize?t.offsetWidth:this.circleDiameterPx,height:this.useDimensionsBasedSize?t.offsetHeight:this.circleDiameterPx},o=Math.min(n.width,n.height),a=i.left+i.width/2,s=i.top+i.height/2,l=e.clientX-a,c=e.clientY-s,d=sl(l,c,this.controlRotateAngleRad);this.element.style.width=o+"px",this.element.style.left=d.x+i.width/2-o/2+"px",this.element.style.top=d.y+i.height/2-o/2+"px",this.element.classList.add(pe.visible,pe.animation)};this.onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(pe.visible,pe.animation)};let o=document.createElement("div");o.classList.add(pe.common),this.controlRotateAngleRad=e,this.element=o,this.clickCancelCondition=t,this.circleDiameterPx=i,this.useDimensionsBasedSize=n}};function sl(r,e,t){return{x:r*Math.cos(t)-e*Math.sin(t),y:r*Math.sin(t)+e*Math.cos(t)}}var Yt="int",re=(i=>(i.AREA=`${Yt}_area`,i.TEXT=`${Yt}_text`,i.BUTTON=`${Yt}_bttn`,i))(re||{});function Zt(r){return"features"in r}var z="interactive-control",w={common:z,selected:`${z}-selected`,wrapper:`${z}-wrapper`,disabled:`${z}-disabled`,button:`${z}-button`,area:`${z}-area`,text:`${z}-text`,blinkAnim:`${z}-blink-anim`,blinkAnimButton:`${z}-blink-anim-button`,blinkAnimArea:`${z}-blink-anim-area`},Ci=40;var Vo=W(mt(),1);import{isSupportedManifest as vt,ContainerTypes as Pm,ControlTypes as bt,EventActionTypes as A,EventTypes as Vm,migrateManifestToLatestVersion as Po,compareVersions as Mm}from"@interactiveplatform/movika-manifest";var Oo={metadata:"Object",chapters:"Array"},ko=r=>{if(!Z(r))return!1;for(let e in Oo)if(!r[e]||!Y(r[e],Oo[e]))return!1;return vt(r.metadata.version)},ft=r=>r.type===bt.Text,Tm=r=>r.type===bt.Button,Im=r=>r.type===bt.Area,xm={Choice:"Choice",TextInput:"TextInput"},Am={Button:"Button",Area:"Area",Text:"Text"},Sm={onClick:"onClick",onSuspense:"onSuspense"},wm={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var yt=r=>et(r)&&!Qt(r),Q=r=>r.order==="end",gt=r=>et(r.containers)&&!Qt(r.containers)&&Q(r),Mo=(r,e)=>{let t=r*1e3;return yt(e.controls)&&t<(e.startTime??0)},kr=(r,e)=>{let t=r*1e3;return yt(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var ne=(r=[])=>r.some(e=>e.action.type==="expect"),Pr=(r=[])=>r.find(e=>e.action.type==="expect"),Rp=r=>r?.length===1,be=r=>Rp(r)&&ft(r[0]);function _o(r=[],e=1/0,t=[]){return r.filter(({container:i})=>!(0,Vo.default)(t,i.container.id)&&ne(i.container.events)&&i.container.endTime===e&&!i.isRemoved&&!i.willRemoved)}function Ct({gameControllers:r=[],subjectName:e,subjectId:t,execFn:i}){for(let n of r)if(e==="container"&&n.container.container.id===t){i(n),_o(r,n.container.container.endTime,[n.container.container.id]).forEach(a=>{i(a)});break}}function Lo(r){for(let e of r.events)if(e.action.type==="openURI")return!0;return!1}var Fo=(r,e)=>{let t=E=>e.find(({container:u})=>u.container.id===E)?.container.isRemoved,i=ne(r.events)&&!t(r.id),n=(E,y=!1,u=!1)=>{let h=u?"every":"some";return E.controls[h](v=>{let g=y?E.endTime===r.endTime:!0;return v.events?.[h](C=>C.action?.type===A.openURI)&&g})},o=E=>E.some(({container:y})=>n(y.container,!0,!1)&&!y.isRemoved),a=E=>E.every(({container:y})=>y.isRemoved||y.willRemoved?!0:n(y.container,!0,!0)),s=_o(e,r.endTime,[r.id]).length,l=E=>E.controls.some(y=>y.events?.some(u=>u.action?.args?.shouldOpenNow)),c=i||s>0,d=o(e),m=n(r),f=a(e),b=i?!1:s>0,R=l(r);return{isExpectTime:c,hasOtherExpect:s>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:m,isAllOpenURIEventsValid:f,isExpectEventForCurrentContainer:b,hasShouldOpenNowEvent:R}};var J=class r{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new kp;this.error$=new Op;this.isInteracted=!1;this.isRemoved=!1;this.cssVarsManager=null;this.onControlSelect=()=>{this.container?.isManifestContainerDisabled()||Lo(this.control)||this.container?.element?.classList.add("interactive-control-wrapper-selected")};this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()}}setCssVarsManager(e){this.cssVarsManager=e}removeView(e=!1){let t=this.getElement();if(t){if(e){if(t.classList.contains("interactive-control-before-remove"))return;t.classList.add("interactive-control-before-remove"),this.subscriptions.add(Le(t,"transitionend").subscribe(this.onTransitionEnd,n=>this.onError(`${r.name} remove view transition error`,n))).add(Le(t,"transitioncancel").subscribe(this.onTransitionEnd,n=>this.onError(`${r.name} remove view transition error`,n)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e="",t){Ze({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){if(this.featureIsEnabled("controlsTapPlace")&&this.container){let t=this.control.layoutParams.angle??O.angle;this.controlTap=new ot({controlRotateAngleRad:t,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?Ci:void 0}),this.subscriptions.add(Le(e,"click").subscribe(this.controlTap.onElementClick,i=>this.onError("Control click tap animation error",i))).add(Le(this.controlTap.element,"animationend").subscribe(this.controlTap.onAnimationEnd,i=>this.onError("Tap animationend error",i))),this.container.element.append(this.controlTap.element)}}createContainerElement(e){let t=document.createElement("div");t.classList.add(w.wrapper),e.setControlLayout(t,this.control.layoutParams);let i=(this.control.layoutParams.innerSizesDependOn??O.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:this.cssVarsManager?.getPropValue("--interactive-content-height")??0,width:this.cssVarsManager?.getPropValue("--interactive-content-width")??0},n=()=>e.isContainerDisabled?.()??!1;this.container={element:t,dimensions:i,isManifestContainerDisabled:n}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return this.options&&Zt(this.options)&&this.options.features[e]}isTouch(){return this.options&&Zt(this.options)&&this.options.isTouch}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":{if(!this.container)break;this.subscriptions.add(Le(this.container.element,"click").subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),n=>this.onError("Error happened on control interaction",n)));break}default:break}})}removeListeners(){this.subscriptions.unsubscribe()}};var Vr="interactive-blink-anim-reference",_={common:Vr,animation:`${Vr}-animation`,disabled:`${Vr}-disabled`},Et=class{constructor(){this._RAFId=0;this._element=void 0}get element(){return this._element}create(){if(this._element)return;let e=document.createElement("div");e.classList.add(_.common,_.animation),this._element=e}restart(){this._element&&(this._element.classList.add(_.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(_.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var Mr="interactive-container",L={common:Mr,hidden:`${Mr}-hidden`,disabled:`${Mr}-disabled`};var Tt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new _r(r,e)},_r=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.area),i.setAttribute("data-testid",re.AREA),nt({target:i,props:this.control.props,fallback:{...O,backgroundColor:"transparent"}}),ce({target:i,layoutParams:this.control.layoutParams,fallback:O}),this.addControlTap(i),this.subscriptions.add(Fe(this.container.element,"click").pipe(No()).subscribe(this.onControlSelect,n=>this.onError("Control click handler error",n))),this.container.element.append(i),e.append(this.container.element),this.controlElement=i,this.updateShadowStyles(),this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(Fe(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(L.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${_.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(Fe(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(L.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(Fe(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(w.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(w.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(mi(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";gi({target:this.controlElement,props:this.control.props,fallback:O,isDark:e,baseDimension:t}),Ie({target:this.controlElement,props:this.control.props,fallback:{...O,borderColor:e?O.shadowColorDark:O.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??O.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Ie({target:this.controlElement,props:this.control.props,fallback:{...O,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(w.blinkAnim,e),this.controlElement?.classList.toggle(w.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${w.blinkAnimArea}`)||this.controlElement.classList.contains(w.selected)||this.controlElement.classList.contains(_.disabled)||(this.controlElement.classList.add(_.disabled),this.subscriptions.add(Fe(e,"animationiteration").pipe(No()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(_.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${w.blinkAnimArea}`)||this.controlElement.classList.contains(w.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-area-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}setShowTimeRange(){}updateFillAnimationDimensions(){}onProgress(){}onResize(){}};import{fromEvent as Ne,once as Go}from"@vkontakte/videoplayer-shared";var It=r=>{let e=document.createElement("span");switch(r){case"Button":case"button":{let t=document.createElement("div"),i={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(t.style,i),t.append(e);let n={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,n),t}default:{let t={display:"inline-block",whiteSpace:"break-spaces",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",maxHeight:"100%",wordBreak:"break-all"};return Object.assign(e.style,t),e}}};var xt=Math.PI,Lr=2*xt,At=xt/2,$o=3*At,Pp=0,Vp=[Pp,At,xt,$o];function jo(r){return r===At}function Bo(r){return r===xt}function qo(r){return r===$o}function Do(r){return(r%Lr+Lr)%Lr}function Mp(r){for(let e of Vp)if(r===e)return e}function Ho(r){if(Mp(r))return null;let t=Math.floor(r/At)+1;return[1,2,3,4][t-1]}function Uo(r){return r*180/Math.PI}var X="interactive-control-fill-animation",F={common:X,fillerWrapper:`${X}-filler-wrapper`,filler:`${X}-filler`,fillHeight:`${X}-fill-height`,fillWidth:`${X}-fill-width`,fromTop:`${X}-from-top`,fromBottom:`${X}-from-bottom`,fromLeft:`${X}-from-left`,fromRight:`${X}-from-right`};var St=class r{constructor(e){this.widthExpansionCoef=0;let t=document.createElement("div");t.classList.add(F.common);let i=document.createElement("div");i.classList.add(F.fillerWrapper);let n=document.createElement("div");n.classList.add(F.filler),i.append(n),t.append(i);let o=Do(e.rotateAngle),a=Ho(o),s=a!==null,c=a===2||!s&&Bo(o)||a===3,d=!s&&jo(o),m=!s&&qo(o),f=!c&&!d&&!m,b=d||m,R=s&&!b,E=R?o:0;t.style.borderRadius=e.borderRadius,i.style.transform=`skew(${E*-1}rad)`,b?(n.classList.add(F.fillHeight,d?F.fromTop:F.fromBottom),i.classList.add(F.fillHeight,d?F.fromTop:F.fromBottom)):(n.classList.add(F.fillWidth,f?F.fromLeft:F.fromRight),i.classList.add(F.fillWidth)),e.debug&&console.log(`[interactive ${r.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:b,rotateAngleRad:o,rotateAngelDeg:Uo(o),rotateAngleRaw:e.rotateAngle,fromRight:c,fromTop:d,fromBottom:m,fromLeft:f}),this.useSkew=R,this.fromLeft=f,this.rotateAngle=o,this.fillAnimationElement=t,this.fillAnimationFillerElement=n,this.fillAnimationFillerWrapperElement=i,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=b,this.isDebug=e.debug??!1}updateDimension(e){this.fillAnimationElement.style.top=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.left=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.width=`${e.width}px`,this.fillAnimationElement.style.height=`${e.height}px`;let t=this.calcWidthExpansionCoef({rotateAngle:this.rotateAngle,isSkewed:this.useSkew,initWidth:e.width,initHeight:e.height});!this.shouldFillHeight&&(this.fillAnimationFillerWrapperElement.style.width=100*t+100+"%",this.fillAnimationFillerWrapperElement.style[`${this.fromLeft?"left":"right"}`]=`calc((${t} * 100%) / 2 * -1)`),this.widthExpansionCoef=t}updateAnimation(e){if((o=>o<this.startTime||o>this.endTime)(e))return;let i=this.endTime-this.startTime,n=Math.min(Math.max((e-this.startTime)/i,0),1);this.shouldFillHeight?this.fillAnimationFillerElement.style.transform=`scaleY(${n})`:this.fillAnimationFillerElement.style.transform=`scaleX(${n})`}calcWidthExpansionCoef({rotateAngle:e,isSkewed:t=!1,initWidth:i,initHeight:n}){return t?(i+n*Math.abs(Math.tan(e)))/i-1:0}};var wt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Fr(r,e)},Fr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.button),i.setAttribute("data-testid",re.BUTTON),ce({target:i,layoutParams:this.control.layoutParams,fallback:O}),nt({target:i,props:this.control.props,fallback:O}),Ie({target:i,props:this.control.props,fallback:O,dependsOn:this.container.dimensions}),rt({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=It(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;it({target:o,props:this.control.props,fallback:O,dependsOn:this.container.dimensions}),this.addControlTap(i),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled("controlsFillAnimation")&&(this.controlFillAnimation=new St({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??O.angle,borderRadius:i.style.borderRadius})),this.subscriptions.add(Ne(i,"click").pipe(Go()).subscribe(this.onControlSelect,a=>this.onError("Control click handler error",a))),i.append(n,this.controlFillAnimation?.fillAnimationElement??""),this.container.element.append(this.controlTap?.element??"",i),e.append(this.container.element),this.controlElement=i,this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(Ne(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(L.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${_.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(Ne(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(L.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(Ne(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(w.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(w.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(w.blinkAnim,e),this.controlElement?.classList.toggle(w.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${w.blinkAnimButton}`)||this.controlElement.classList.contains(w.selected)||this.controlElement.classList.contains(_.disabled)||(this.controlElement.classList.add(_.disabled),this.subscriptions.add(Ne(e,"animationiteration").pipe(Go()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(_.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${w.blinkAnimButton}`)||this.controlElement.classList.contains(w.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-button-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}updateFillAnimationDimensions(){if(!this.container||!this.controlElement||!this.controlFillAnimation)return;let e=getComputedStyle(this.controlElement),t={width:parseFloat(e.width),height:parseFloat(e.height),borderWidth:parseFloat(e.borderWidth)||0};this.controlFillAnimation.updateDimension(t)}setShowTimeRange(e,t){this.startTime=e,this.endTime=t}onProgress(e){this.controlFillAnimation?.updateAnimation(e)}onResize(){this.updateFillAnimationDimensions()}updateShadowStyles(){}};var Wo=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Nr(r,e)},Nr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("div");i.classList.add(w.common,w.text),i.setAttribute("data-testid",re.TEXT),ce({target:i,layoutParams:this.control.layoutParams,fallback:O}),rt({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=It(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;it({target:o,props:this.control.props,fallback:O,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}updateShadowStyles(){}toggleBlinkAnimation(){}setShowTimeRange(){}updateFillAnimationDimensions(){}};var Rt=(r,e,t,i)=>{if(r.type.trim().toLowerCase()==="choice")return new $r(r,e,t,i)},$r=class r extends le{constructor(t,i,n,o){super(t,n,o);this.containerElement=null;this.subscriptions=new _p;this.onTransitionEnd=t=>{t.stopPropagation(),!(!t.target||!t.currentTarget)&&t.target===t.currentTarget&&this.removeView()};this.rootElement=i,this.layout=new Ye(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",wt),this.addControlFactory("text",Wo),this.addControlFactory("area",Tt)}createView({eventCallback:t,videoDurationMs:i}){let n=document.createElement("div");return n.classList.add(L.common,L.disabled),n.setAttribute("data-subjectId",this.container.id),requestAnimationFrame(()=>{n.classList.remove(L.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(o=>{o.setShowTimeRange(this.container.startTime,this.container.endTime??i),o.setCssVarsManager(this.cssVarsManager),o.createView({parentElement:n,callbacks:{setControlLayout:(a,s)=>this.layout.setControlLayout(a,s),isContainerDisabled:()=>this.isDisabled}}),o.setEvents(t),this.subscriptions.add(o.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.willRemoved=!1,this.containerElement=n,this.updateControlsFillAnimationDimensions(),n}updateControlsFillAnimationDimensions(){for(let t of this.controls)t.updateFillAnimationDimensions()}hide(){let t=this.getElement();t&&t.classList.add(L.hidden)}show(){let t=this.getElement();t&&t.classList.remove(L.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(L.disabled),this.controls.forEach(i=>i.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(L.disabled),this.controls.forEach(i=>i.disable()),this.isDisabled=!0)}removeView(t=!1,i=!1){let n=this.getElement();if(n){if(t){if(this.willRemoved)return;this.willRemoved=!0,i&&n.classList.add("interactive-container-before-remove-delay"),n.classList.add("interactive-container-before-remove"),this.subscriptions.add(zo(n,"transitionend").subscribe(this.onTransitionEnd,a=>this.onError(`${r.name} remove view transition error`,a))).add(zo(n,"transitioncancel").subscribe(this.onTransitionEnd,a=>this.onError(`${r.name} remove view transition error`,a)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}removeAllControls(t=!1){this.controls.forEach(i=>i.removeView(t))}removeNonInteractedControls(t=!1){this.controls.forEach(i=>{i.isInteracted||i.removeView(t)})}isInteracted(){return this.controls.some(t=>t.isInteracted)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(t,i){i&&this.controls.forEach(n=>{n.onProgress(t)})}onResize(t){t&&this.controls.forEach(i=>{i.onResize()})}updateControlsShadowStyles(t){this.controls.forEach(i=>i.updateShadowStyles(t))}toggleBlinkAnimation(t){this.controls.forEach(i=>i.toggleBlinkAnimation(t))}};var Xa=W(jr(),1);import{combine as Mh,InterfaceLanguage as _h,Observable as za,once as Lh,Subject as N,Subscription as ai,ValueSubject as B,fromEvent as Ka}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Qe}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Hp}from"@vkontakte/videoplayer-shared";function $e(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var es="video_interactive",ts="videoint";var rs=250,je=class{constructor(e){this.handleZoomChange=$e(e=>{this.lastZoomInfo=e},rs);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Chapter id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!tt(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:i,lang:n,visitedChapters:o=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(o),this.onOpenPreviewClick=t,this.onError=i,this.lang=n??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Up(e),this.resizeObserver=new ResizeObserver($e(this.onResize,rs)),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 Hp(this.lang,es,ts)}catch{this.onError?.("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"view",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:i,...n})=>{i==="openPreview"&&"chapterId"in n&&this.onOpenPreviewClick?.(n.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 Up(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var Be=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let o of this._containers){let a=o.startTime-e;if(a<=n&&(o.endTime&&n<=o.endTime||o.endTime===null)){i=!0;break}n<a&&(t=t===-1?a:Math.min(t,a))}return!i&&t!==-1?t:null}}};var Ot=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let i=()=>{t(),this.off(e,i)};return this.listeners[e].push(i),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let i=this.listeners[e]||[];for(let n=i.length;n>0;n--)if(i[n]===t){i.splice(n,1);break}return this}emit(e,...t){let i=this.listeners[e];return i?(i.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var kt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{di(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(i=>i!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};var Vs=W(Ps(),1),Pt=class r{constructor(e){this.rootElement=e;this.rootElementProps={};this.isCssVarsSupported=r.checkCssVarsSupport(e)}static checkCssVarsSupport(e){let t="--test-key",i="test";e.style.setProperty(t,i);let n=e.style.getPropertyValue(t)===i;return n&&e.style.removeProperty(t),n}getPropValue(e){return this.isCssVarsSupported?`var(${e})`:this.rootElementProps[e]??""}setup(e){if(this.rootElementProps={...this.rootElementProps,...e},this.isCssVarsSupported)for(let[t,i]of(0,Vs.default)(e))this.rootElement.style.setProperty(t,i)}cleanup(){for(let e in this.rootElementProps)this.rootElement.style.removeProperty(e);this.rootElementProps={}}setProp(e,t){this.rootElementProps[e]=t,this.isCssVarsSupported&&this.rootElement.style.setProperty(e,t)}};import{ValueSubject as xu}from"@vkontakte/videoplayer-shared";var Vt=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return yu(...this.loaders[e])(t)}};function yu(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function qe(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function Mt({actions:r,errors:e,chapterId:t,...i}){if(t){let n=r.getManifest();if(n){let o=r.getChapter(n.chapters,t);if(o){let a=r.getMedia(n.media,o.videoId),s=r.getGraph(n.graph,o.id);return a?{...i,actions:r,errors:e,result:{chapter:o,media:a,graph:s}}:{...i,errors:qe(e,Mt.name,"Could not find media"),actions:r}}}}return{...i,errors:qe(e,Mt.name,"Could not find chapter"),actions:r}}var{NativeAbortSignal:Ov,NativeAbortController:kv}=function(r){return{NativeAbortSignal:r.AbortSignal,NativeAbortController:r.AbortController}}(typeof self<"u"?self:global);function Ms(r){let e;try{e=new Event("abort")}catch{typeof document<"u"?document.createEvent?(e=document.createEvent("Event"),e.initEvent("abort",!1,!1)):(e=document.createEventObject(),e.type="abort"):e={type:"abort",bubbles:!1,cancelable:!1}}return e.reason=r,e}function _s(r){if(r===void 0)if(typeof document>"u")r=new Error("This operation was aborted"),r.name="AbortError";else try{r=new DOMException("signal is aborted without reason"),Object.defineProperty(r,"name",{value:"AbortError"})}catch{r=new Error("This operation was aborted"),r.name="AbortError"}return r}var _t=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,o=i.length;n<o;n++)if(i[n].callback===t){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,o=i.length;n<o;n++){let a=i[n];try{a.callback.call(this,e)}catch(s){Promise.resolve().then(()=>{throw s})}a.options&&a.options.once&&this.removeEventListener(e.type,a.callback)}return!e.defaultPrevented}},ye=class extends _t{constructor(){super(),this.listeners||_t.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)}throwIfAborted(){let{aborted:e,reason:t="Aborted"}=this;if(e)throw t}static timeout(e){let t=new oe;return setTimeout(()=>t.abort(new DOMException(`This signal is timeout in ${e}ms`,"TimeoutError")),e),t.signal}static any(e){let t=new oe;function i(){t.abort(this.reason),n()}function n(){for(let o of e)o.removeEventListener("abort",i)}for(let o of e)if(o.aborted){t.abort(o.reason);break}else o.addEventListener("abort",i);return t.signal}},oe=class{constructor(){Object.defineProperty(this,"signal",{value:new ye,writable:!0,configurable:!0})}abort(e){let t=_s(e),i=Ms(t);this.signal.reason=t,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(oe.prototype[Symbol.toStringTag]="AbortController",ye.prototype[Symbol.toStringTag]="AbortSignal");function Lt(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function Hr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!Lt({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:o};let o=t;(o&&!o.prototype.hasOwnProperty("signal")||n)&&(o=function(c,d){let m;d&&d.signal&&(m=d.signal,delete d.signal);let f=new t(c,d);return m&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),f},o.prototype=t.prototype);let a=e;return{fetch:(l,c)=>{let d=o&&o.prototype.isPrototypeOf(l)?l.signal:c?c.signal:void 0;if(d){let m;try{m=new DOMException("Aborted","AbortError")}catch{m=new Error("Aborted"),m.name="AbortError"}if(d.aborted)return Promise.reject(m);let f=new Promise((b,R)=>{d.addEventListener("abort",()=>R(m),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([f,a(l,c)])}return a(l,c)},Request:o}}var gu=()=>"fetch"in window,De=gu()&&Lt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ls=De?Hr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ur=De?Ls.fetch:window.fetch,Bv=De?Ls.Request:window.Request,qv=De?oe:window.AbortController,Dv=De?ye:window.AbortSignal;var Gr=(r="",e="")=>{let t=r.split("."),i=e.split("."),n=0;for(let o=0;o<Math.max(t.length,i.length)&&!n;o++)t[o]>i[o]?n=1:t[o]<i[o]?n=-1:n=0;return n};var Cu=async r=>{try{let e={},t;if(Je(r)){t=new URL(r).href;let n=await Ur(t);if(!n.ok)return{};e=await n.json()}else if(Z(r))e=r;else return{};if(!ko(e))return{};let i=e.metadata.media;if(Je(i)&&!("media"in e))try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let o=await Ur(n);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch{return Iu(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function Fs(r){let{manifest:e,manifestURL:t}=await Cu(r);if(!e)throw new Error("Failed on fetch");let i=Po(e);return i.media=Eu(i.media,t),delete i.metadata.media,i}function Ft(r,e){if(e)return r.find(t=>t.id===e)}function Wr(r,e){return r.edit?.chapters?r.edit.chapters.find(t=>t.id===e):r.view?.chapters?r.view.chapters.find(t=>t.id===e):void 0}function zr(r,e){return r.videos.find(t=>t.id===e)}function Eu(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",o=Tu(n,e);return{...i,url:o||n}})}))}}function Tu(r="",e){try{return new URL(r,e).href}catch{return""}}function Iu(r){return Gr(r,"3.2.0")>=0}var ge=class extends Vt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new xu(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:qe},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await Fs(i.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",Mt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Wr,getChapter:Ft,getMedia:zr,getByBranches:this.getByBranches.bind(this),addErrorMessage:qe},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),i.result&&(this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let i=Ft(this.manifest.chapters,t);if(i){let n=zr(this.manifest.media,i.videoId),o=Wr(this.manifest.graph,i.id);if(n)return{chapter:i,media:n,graph:o}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let i=Ft(this.manifest?.chapters||[],t);return this.getByBranches(i?.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{let o=this.getByChapterId(n.chapterId);return o&&i.push(o),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?Q(this.chapter):!1}};var Gs=W(Nt(),1);import{Player as ku}from"@vkontakte/videoplayer-core";import{Subscription as Xr,TracerFactory as Pu,ValueSubject as Vu}from"@vkontakte/videoplayer-shared";var Hs=r=>{let e=r.variants.find(t=>t.payload?.type==="vk");if(e&&e.payload){let[t,i]=e.payload.id.split("_");return[t,i]}return[]};var Us=W(Nt(),1);function Kr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:a=Math.random().toString(),...s}){let l=r.get(o),c={...s};return l?l[a]=c:r.set(o,{[a]:c}),{listId:o,itemId:a,...s}}function t(o){o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),o.statistics?.oneStat.destroy(),o.statistics?.statSubscription.unsubscribe()}function i(o,a){let s=r.get(o);if(!s)throw Error("Can't remove. Not find.");if(a){let l=s[a];l&&t(l),delete s[a],Object.keys(s).length||r.delete(o)}else{for(let l of(0,Us.default)(s))t(l);r.delete(o)}}function n(){for(let o of r)i(o[0])}return{createPlayer:e,removePlayer:i,map:r,removeAll:n}}var Ce=W(mt(),1);function Qr(r,e=[]){let t={},i,n=!e.length;for(let o of r.variants)if(!i&&"cover"in o&&(i=o.cover),"url"in o)switch(o.type.toLowerCase()){case"mp4":(n||(0,Ce.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"mpeg":(n||(0,Ce.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"hls":(n||(0,Ce.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:o.url}});break;case"dash":(n||(0,Ce.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:o.url}});break;default:break}return{sources:t,thumbUrl:i,title:r.title??""}}var He=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&(0,Ce.default)(i,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Mu=2;function Yr(r){let e=Kr(),t=new Xr,i={},n=null,o=!1,a,s=new Vu(null);r&&l(r);function l(y){n=y}function c(y,u,h){if(!n)throw Error("need to set interactive controller");if(!n.options)return;let g=(e.map.get(y)??{})[u];if(g){i={chapterId:h,listId:y,itemId:u,...g};let C=i.player;i.subscription.add(C.info.currentQuality$.subscribe(T=>{let S=C.info.position$.getValue(),$=C.info.isAutoQualityEnabled$.getValue();if(!(!T||!S||$))for(let I of e.map)(0,Gs.default)(I[1]).forEach(({player:P})=>{He(P,T)})})).add(C.events.started$.subscribe(()=>{d(u)})),g.container.remove(),n.setPlayer(g.player),o||(n.init(),o=!0),s.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}async function d(y){if(!n)throw Error("need to set interactive controller");if(te(i)||y!==i.itemId)return;let u=n.getChapterBranches(),h=new Set;for(let v of u)h.has(v.media.id)||(await f({media:v.media,chapterId:v.chapter.id,setAsActive:!1,title:v.chapter.label}),h.add(v.media.id))}async function m({chapter:{id:y},manifestVideo:u}){if(te(i)||!n)return;let h=i.player.info.muted$.getValue(),v=i.player.info.currentQuality$.getValue(),g=i.player.info.isAutoQualityEnabled$.getValue(),C=i.player.info.volume$.getValue(),T=i.player.info.currentPlaybackRate$.getValue(),S=!g,$=!1;for(let I of e.map)if(I[0]===u.id&&!n.state.isReplay$.getValue()){let P=Object.keys(I[1]);for(let V of P)V===i.itemId?(P.length<Mu||($=!0),e.removePlayer(I[0],V)):($=!0,c(I[0],V,y),S?He(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(C),i.player.setMuted(h),i.player.setPlaybackRate(T))}else e.removePlayer(I[0]);$||(await f({media:u,chapterId:y,setAsActive:!0,playbackRate:T}),S?He(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(C),i.player.setMuted(h))}async function f({media:y,chapterId:u,prefetch:h=!0,setAsActive:v=!0,autoplay:g=!1,preferredExt:C,title:T,playbackRate:S}){let $=Math.random().toString(),I=document.createElement("div");a.append(I);let P;if(n?.options?.vkVideoLoader){let Xe=Hs(y);Xe.length&&(P=await n.options.vkVideoLoader(...Xe))}let V=n?.options?.coreConfig||void 0,G={...V,configName:[...V?.configName??[],"interactive"]},ee={container:I,...P?.videos?.[0]||{sources:Qr(y,C).sources},title:T,failoverHosts:P?.failoverHosts||[]},j=new ku(G,Pu.createRootTracer());j.initVideo(ee);let se=null;if(P?.videos&&n?.options.createOneStat){let Xe=P.videos[0],Ut=n.options.createOneStat(Xe),ci=new Xr;Ut&&(ci.add(Ut.attachTo(j)),se={oneStat:Ut,statSubscription:ci})}let li=new Xr,Ya=i?.player?.info.isAutoQualityEnabled$.getValue();li.add(j.events.canplay$.subscribe(function(){Ya||He(j,i.player.info.currentQuality$.getValue()),S&&j.setPlaybackRate(S)}));let ae=e.createPlayer({listId:y.id,itemId:$,player:j,container:I,sources:Qr(y,C).sources,config:ee,subscription:li,statistics:se});return v&&c(y.id,ae.itemId,u),g&&ae.player.play(),h&&!g&&ae.player.prepare(),{player:ae.player,config:ae.config,statistics:ae.statistics}}function b(){R(),n=null,a.remove()}function R(){t.unsubscribe(),e.removeAll(),i={},o=!1}async function E(){if(!n)throw Error("need to set interactive controller");R(),a=document.createElement("div");let{media:y,chapter:u}=n.getCurrentChapter();y&&u?(t.add(n.events.chapterChanged$.subscribe(m)),await f({media:y,chapterId:u.id,title:u.label})):console.error("not found")}return{...e,init:E,setInteractiveController:l,createPlayer:f,removeAll:b,getActivePlayer:function(){return i},activePlayerChanged:s}}var x={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ue={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},k={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as _u}from"@vkontakte/videoplayer-shared";function Zr(r){return function(...t){return r(...t.reverse())}}function Ge(r,...e){return(...t)=>Z(e[0])&&Z(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var $t=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:o,globalEvents:a,globalEventEmitter:s,getContainerEventState:l,permanentTextControls:c,interactiveTimeOpenUri:d,disabledControls$:m,onRemove:f,onError:b,disableTextControlContainerVisibilityEvents:R=!1,features:E}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(ne(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&t||this.disableTextControlContainerVisibilityEvents)return;this.emitContainerVisibilityEvent(!0,!1)}else{let t={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(o,a)=>{let{isExpectTime:s,hasOtherExpect:l,hasOpenURIEvent:c,hasOpenURIEventInCurrentContainer:d,isAllOpenURIEventsValid:m,hasShouldOpenNowEvent:f}=this.getContainerEventState(),b=this.interactiveTimeOpenUri&&!d,R=this.interactiveTimeOpenUri&&d;if((!this.interactiveTimeOpenUri||b)&&(this.isSelectedControlEvent=!0),o!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||b)){if(this.interactiveTimeOpenUri){let E=!l&&!m&&d;E&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:E})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&c&&this.gameState!==5){if(R){let y=((u,h,v,g)=>!u&&!h&&v||u&&!h&&v&&!g||u&&!h&&v&&g)(s,l,m,this.isSelectedContainerEvent);this.fakeRemoveView(y)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!s||!l||!f)&&(this.selectBranches.stopExpect(),a())}},isEOV:()=>this.gameState===4},i=Ge(this.selectBranches.onControlEvent,t),n=(this.player?.info.duration$.getValue()??1/0)*1e3;this.container.createView({eventCallback:i,videoDurationMs:n}),this.disableTextControlContainerVisibilityEvents||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(),t=e instanceof HTMLVideoElement;if(this.features.enableAvPlayerSupport&&(t||=e instanceof HTMLObjectElement&&e?.getAttribute("type")==="application/avplayer"),!(t?e?.readyState:void 0)||this.isRemovedOrDestroyed()&&!this.isPermanentText)return;let n=this.player.getExactTime();if(Mo(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(kr(n,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let l=this.gameState;this.gameState=3,l===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:l}=this.getContainerEventState(),c=this.selectBranches.state.isExpect,d=this.interactiveTimeOpenUri&&l;if(d&&!c){let m=this.container.getElement();m&&(m.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!d&&this.removeView()}let o=kr(n,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],s={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:n,isInteractiveTime:o};this.container.onProgress(n*1e3,o),this.globalEventEmitter.emit(x.eachTick,s),this.globalEvents.eachTick$.next(s)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new _u,this.player=e,this.interactiveEvents=o,this.getContainerEventState=l;let y=be(t.container.controls);this.isPermanentText=c&&y,this.disableTextControlContainerVisibilityEvents=R&&y,this.interactiveTimeOpenUri=d,this.disabledControls$=m,this.onRemove=f,this.globalEventEmitter=s,this.gameState=0,this.globalEvents=a,this.onError=b,this.features=E,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.visibility,visibility:e,isFirst:t}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e,isFirst:t})):(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.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?.()})),this.subscription.add(this.container.error$.subscribe(this.onError))}selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),i=this.interactiveTimeOpenUri?e||t:ne(this.container.container.events)||e;(this.isSelectedControlEvent||!i)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(e=this.features.controlsHideAnimation){if(e){if(this.isRemovedOrDestroyed())return;this.container.removeNonInteractedControls(!0),this.container.removeView(!0,!0)}else this.container.removeView();this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}isInteracted(){return this.container.isInteracted()}isRemovedOrDestroyed(e=!0){let t=e?this.container.willRemoved:!1;return this.gameState===5||t||this.gameState===6}destroy(e=!1){this.reset(),this.removeView(e),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 zs=(r=[])=>r.reduce((e,t,i)=>{let n=(t?.controls??[]).filter(o=>!ft(o));if(yt(n)){let o=[t.startTime??0,t.endTime??1/0],a={id:t.id,isRemoved:!1};if(!i)e.push({subjects:[a],range:o});else{let s=[],l=-1/0,c=1/0,d=[],m=[];for(let f=0;f<e.length;f++){let b=e[f];if(m.push(...b.subjects),b.range[0]<c&&(c=b.range[0]),b.range[1]>l&&(l=b.range[1]),o[0]>=b.range[0]&&o[1]<=b.range[1])return e[f].subjects.push(a),e;o[0]<b.range[0]&&o[1]>b.range[0]&&(s.push(f),d=d.concat(b.subjects)),o[0]>=b.range[0]&&o[0]<=b.range[1]&&(s.push(f),d=d.concat(b.subjects),o[0]=b.range[0]),o[1]>=b.range[0]&&o[1]<=b.range[1]&&(s.push(f),d=d.concat(b.subjects),o[1]=b.range[1])}if(m.push(a),o[0]<=c&&o[1]>=l)return[{subjects:m,range:o}];s.length&&s.reverse().forEach(f=>{e.splice(f,1)}),e.push({subjects:d.concat([a]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var Ra=W(mt(),1),ri=W(Nt(),1),Oa=W(Sa(),1);function wa(){let r={};function e(){for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&delete r[s]}function t(s){let l={};for(let c in r)+c<=s&&(l[c]=r[c]);return l}function i(s){let l={};for(let c in r)+c>=s&&(l[c]=r[c]);return l}function n({timestamp:s,priority:l,initiator:c}){if(Kt(s)){let d=r[s]??null;if(d&&l&&Ee(l,!0)){let m={},f=d[l];return f&&(m={...m,...f}),m=te(m)?null:m,m&&Ee(c,!0)?m[c]??null:m}return d}return null}function o({timestamp:s,priority:l,initiator:c}){if(Kt(s))if(r[s]){if(l&&Ee(l,!0))if(r[s][l]){if(c&&Ee(c,!0))if(r[s][l][c]){if(delete r[s][l][c],!te(r[s][l]))return!0}else return!1;if(delete r[s][l],!te(r[s]))return!0}else return!1;return delete r[s]}else return!1;return!1}function a({timestamp:s,priority:l,initiator:c,...d}){r[s]?.[l]?.[c]?r[s][l][c].push({...d}):r[s]?.[l]?r[s][l]={...r[s][l],[c]:[{...d}]}:r[s]?r[s]={...r[s],[l]:{[c]:[{...d}]}}:r[s]={[l]:{[c]:[{...d}]}}}return{map:r,remove:o,add:a,removeAll:e,get:n,getLte:t,getGte:i}}var Th=[A.expect,A.setNextBranch],Ih=1/0;function ka(r,e){let t=r,i,n=xh(e),o=wa(),a,s=()=>{b(),u()},l=h=>{o.add.call(void 0,h),R()},c=(h=[])=>{for(let v of h)if(v.action(),(0,Ra.default)(Th,v.actionType))break},d=(h=1/0)=>{let v=Bt(o.get({timestamp:h,priority:"control"})??{}),g=Bt(o.get({timestamp:h,priority:"container"})??{}),C=Bt(o.get({timestamp:h,priority:"chapter"})??{});return[...v,...g,...C]},m=h=>{n.isReady(h)&&c(d(h))},f=()=>{c([...Bt(o.get({timestamp:1/0,priority:"chapter"})??{})])},b=()=>{i&&(a?.unsubscribe(),i=void 0)},R=()=>{i||(i=()=>setTimeout(()=>{m(1/0)}),a=t.events.ended$.subscribe(i))},E=h=>{b(),t=h},y=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),o.remove(h)},u=()=>{n.release(),o.removeAll()};return{setPlayer:E,add:l,remove:y,exec:m,execEndOfVideo:f,listen:R,unlisten:b,release:s,containersEventsCallState:n,getPreparedToExecActions:d}}function xh(r){let e=new Map;return{setCalled:({timestamp:s,id:l})=>{let c=e.get(s);c&&c[l]!==void 0&&(c[l]=!0)},setData:(s=[])=>{for(let l of s){let c=l.endTime??Ih,d=e.get(c);e.set(c,{...d,[l.id]:!1})}},resetCalled:s=>{let l=e.get(s);if(l)for(let c in l)l[c]=!1},isReady:s=>{let l=e.get(s);if(!l)return!0;let c=(0,ri.default)(l);return r?c.some(m=>m):!c.some(m=>!m)},release:()=>e.clear()}}function Bt(r){return(0,Oa.default)((0,ri.default)(r)).sort(e=>e.actionType===A.expect?-1:1)}var Pa={videoContentHeight:0,videoContentWidth:0},Va=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return Pa;let{clientHeight:i,clientWidth:n}=r.experimental.element$.getValue()||{};if(!(i&&n))return Pa;let o=e/t,a=i/n,s,l;return a>o?(l=n,s=n*o):a<o?(l=i/o,s=i):(l=n,s=i),{videoContentWidth:l,videoContentHeight:s}};var Ah=250;function Ma(r){let e,t=new ResizeObserver(s=>{o(s),e=o.bind(null,s)});function i(s){let{parentElement:l,player:c,cssVarsManager:d}=r();if(!l||!c)return;let{videoContentWidth:m,videoContentHeight:f}=Va(c);d.setup({"--interactive-content-width":`${m}px`,"--interactive-content-height":`${f}px`,"--interactive-width":`${s[0].contentRect.width}px`,"--interactive-height":`${s[0].contentRect.height}px`})}function n(){let{parentElement:s}=r();s.removeAttribute("style")}let o=$e(s=>{let{fns:l=[]}=r();i(s);for(let c of l)c()},Ah);function a(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e?.()},release:a}}var Sh=r=>Math.floor(Math.random()*r),La=r=>{let e=r.length,t=1/0,i=null;for(;e--;){let n=r[e],o=n.weight??1;o<t&&(t=o,i=n)}return i},Fa=r=>{let e=r.length,t=-1/0,i=null;for(;e--;){let n=r[e],o=n.weight??0;o>t&&(t=o,i=n)}return i};var Na=r=>{let e=r.length,t=Sh(e);return r[t]},_a=1,$a=r=>{let e=0;for(let i=0;i<r.length;++i)e+=r[i].weight??_a;let t=Math.random()*e;e=0;for(let i=0;i<r.length-1;++i)if(e+=r[i].weight??_a,e>=t)return r[i];return r[r.length-1]};var ja={shouldOpenNow:!0,isDetachContainer:!0},Ba="after-expect",ii=(r,e=!1)=>({...r,args:e?{...r.args,...ja}:{...ja,...r.args}}),qa=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:i})=>{let n={isExpect:!1},o=()=>{n.isExpect&&(n.isExpect=!1)},a=({action:u,controlType:h,controlId:v,containerId:g,branches:C=[],onEvent:T,isEOV:S=()=>!1,isDisabled:$=()=>!1})=>{let I=ii(u,S()),P={timestamp:1/0,priority:"control",initiator:v,actionType:I.type},V=$(),G=r.emit.bind(r,x.interactives,{subjectId:v,subjectType:h,subjectName:"control",type:V?k.actionChoiceCanceled:k.actionChoice,actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:g,...I.args}}),ee=()=>{e.interactiveActionChoice$.next({subjectId:v,subjectType:h,subjectName:"control",type:V?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:g,...I.args}})};if(V){G(),ee();return}switch(I.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let j=C.find(se=>se.id===I.args.branchId);if(!j)return;T(I.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),I.args.shouldOpenNow?E({subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{chapterId:j.chapterId,autoSelect:!1}}):i.add({...P,action:E.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{chapterId:j.chapterId,autoSelect:!1}})});return}case A.continuePlayback.trim().toLowerCase():{T(I.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),I.args.shouldOpenNow?R({subjectId:v,subjectName:"control",subjectType:h,action:u}):i.add({...P,action:R.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:u})});return}case A.openURI.trim().toLowerCase():{T(I.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),I.args.shouldOpenNow?y({subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}}):i.add({...P,action:y.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}})});return}default:{let j="Unexpected control event",se=new M(1,1,{message:j});d(se,j);return}}},s=({action:u,container:{id:h,endTime:v},branches:g=[],isEOV:C=!1,autoSelected:T=!1})=>{let S=ii(u,C),$={timestamp:!S.args.shouldOpenNow||C?1/0:v??1/0,priority:"container",initiator:h,actionType:S.type},I=r.emit.bind(r,x.interactives,{subjectId:h,subjectName:"container",type:k.actionChoice,actionType:S.type,payload:{invokeImmediately:S.args.shouldOpenNow,...S.args}}),P=()=>{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 A.setNextBranch.trim().toLowerCase():{let V=g.find(G=>G.id===S.args.branchId);if(!V)return;I(),P(),i.add({...$,action:E.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{chapterId:V.chapterId,autoSelect:T}})});return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{I(),P(),i.add({...$,action:R.bind(null,{subjectId:h,subjectName:"container",action:S})});return}case A.openURI.trim().toLowerCase():{I(),P(),i.add({...$,action:y.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{URI:u.args.uri}})});return}default:{let V="Unexpected container event",G=new M(1,1,{message:V});d(G,V);return}}};function l({container:u,branches:h,isEOV:v=!1}){let g=Pr(u.events);if(g){let C=ii(g.action,v);r.emit(x.interactives,{subjectId:u.id,subjectName:"container",type:k.actionChoice,actionType:C.type,payload:{invokeImmediately:C.args.shouldOpenNow,...C.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:C.type,payload:{invokeImmediately:C.args.shouldOpenNow,...C.args}}),i.add({timestamp:v?1/0:u.endTime??1/0,priority:"container",initiator:u.id,actionType:A.expect,action:f.bind(null,{subjectId:u.id,subjectName:"container"})}),n.isExpect=!0}else for(let C of u.events??[])s({action:C.action,container:u,branches:h,isEOV:v})}let c=({chapterId:u,action:h,branches:v=[]})=>{let g=r.emit.bind(r,x.interactives,{subjectId:u,subjectName:"chapter",type:k.actionChoice,actionType:h.type,payload:h.args}),C=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:h.type,payload:h.args})};switch(h.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let T=v.find(S=>S.id===h.args.branchId);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{let T=Na(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{let T=$a(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{let T=Fa(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{let T=La(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return g(),C(),R.bind(null,{subjectId:u,subjectName:"chapter",action:h});case A.openURI.trim().toLowerCase():return g(),C(),y.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:{let T="Unexpected chapter event",S=new M(1,1,{message:T});d(S,T);return}}};function d(u,h){console.error(h),e.error$.next(u),r.emit(x.errors,u)}function m(u){let h=Pr(u.events);if(h){if(Q(u))return;r.emit(x.interactives,{subjectId:u.id,subjectName:"chapter",type:k.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}),i.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:A.expect,action:f.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else u.events?.forEach(v=>{let g=c({chapterId:u.id,action:v.action,branches:u.branches});g&&i.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:v.action.type,action:g})})}let f=({subjectId:u,subjectName:h})=>{t.pause(),r.emit(x.interactives,{subjectId:u,subjectName:h,type:k.actionExecution,actionType:A.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:A.expect})},b=({subjectId:u,subjectName:h})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),r.emit(x.interactives,{subjectId:u,subjectName:h,type:k.actionExecution,actionType:Ba}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:Ba})},R=({subjectId:u,subjectName:h,subjectType:v,action:g})=>{r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:k.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type})},E=({subjectId:u,subjectName:h,subjectType:v,action:g,payload:C})=>{C.behaviour="change-chapter",r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:k.actionExecution,actionType:g.type,payload:C}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type,payload:C})},y=({subjectId:u,subjectName:h,subjectType:v,action:g,payload:C})=>{if(!C.URI)return;let T=window.open(C.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:k.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type})};return{onControlEvent:a,onContainerEvent:s,onChapterEvent:c,onExpectEvent:f,expectEventHandler:b,setManifestChapterEvents:m,setManifestContainerEvents:l,stopExpect:o,state:n}};var si=W(jr(),1);import{Subscription as Ph,Subject as oi,ValueSubject as ze}from"@vkontakte/videoplayer-shared";var ni=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(a=>a.id===i);if(!n)return null;let o=e.media.videos.find(a=>n.videoId===a.id);if(!o)return null;t[i]=Da(o)}return t[i]}).filter(Boolean)},Rh=r=>{for(let e of r.variants)if(Oh(e)&&e.payload)return e.payload.id},Oh=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Da=r=>{let e=Rh(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},kh=(r,e)=>{for(let t of r.media.videos)if(e===Da(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},Ha=(r,e)=>r.reduce((t,i)=>{let n=kh(e,i);return n?[...t,n]:t},[]);var Ke=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:o}){this.state={history$:new ze([]),hasPrevChapter$:new ze(!1),prevChapter$:new ze(null),isInitialChapter$:new ze(!1),isGoBackLimited$:new ze(!1)};this.#r=null;this.#s=!1;this.#e=null;this.#p=null;this.events={inited$:new oi,destroyed$:new oi,error$:new oi};this.#i=null;this.#n=null;this.#t=null;this.#a=new Ph;this.#l=!1;this.#c=0;this.#i=t,this.#t=e,this.#n=i,this.#r=n,this.#o=o,this.state.history$&&this.#a&&this.#a?.add(this.state.history$.subscribe(a=>{this.state.prevChapter$.next((0,si.default)(a,-2)||null),this.state.hasPrevChapter$.next(a.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#o.maxLength-1)}))}#r;#o;#s;#e;#p;#i;#n;#t;#a;#l;#c;async setManifest(e){if(!this.#n||!this.#t)return;this.#e=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#n.setChapter({chapterId:t,pushToHistory:!1}),this.#s||(this.#s=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#s}async updateHistory(e,t=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let i=this.#e,n=e.length-this.#o.maxLength,o=n>0?e.slice(n):e,a=ni(o,i);if(this.#p=a,this.state.history$.next(o),!(!t||!this.#r||!this.#i))try{await this.#r.save(this.#i,a)}catch{let l=new M(1,5,"Unable to save interactive history");this.events.error$.next(l),this.#t?.emit(x.errors,l)}}async goBack(){if(!this.state||!this.#n){let i=new M(1,5,"Unable to save interactive history");return this.events.error$.next(i),this.#t?.emit(x.errors,i)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#n.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#i)return;let e=this.#e,t=[this.getInitialVideoId()];if(this.#r)try{let n=await this.#r.get(this.#i);n.length&&(t=n)}catch{let o=new M(1,5,"Error while trying to fetch data");this.events.error$.next(o),this.#t?.emit(x.errors,o)}let i=Ha(t,e);this.state.history$.next(i)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,si.default)(e,-1)||this.#o.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return ni([e],this.#e).pop()}return null}destroy(){this.#i=null,this.#r=null,this.#n=null,this.#a?.unsubscribe(),this.#a=null,this.#s=!1,this.#t?.emit(x.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var qt=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 t=e.data,i=t.length;for(let n=3;n<i;n+=40)if(t[n]!==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,t=!1){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var Dt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
6
+ var Za=Object.create;var pi=Object.defineProperty;var Ja=Object.getOwnPropertyDescriptor;var el=Object.getOwnPropertyNames;var tl=Object.getPrototypeOf,rl=Object.prototype.hasOwnProperty;var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var il=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of el(e))!rl.call(r,n)&&n!==t&&pi(r,n,{get:()=>e[n],enumerable:!(i=Ja(e,n))||i.enumerable});return r};var W=(r,e,t)=>(t=r!=null?Za(tl(r)):{},il(e||!r||!r.__esModule?pi(t,"default",{value:r,enumerable:!0}):t,r));var K=p((Jt,Ei)=>{"use strict";var xe=function(r){return r&&r.Math===Math&&r};Ei.exports=xe(typeof globalThis=="object"&&globalThis)||xe(typeof window=="object"&&window)||xe(typeof self=="object"&&self)||xe(typeof global=="object"&&global)||xe(typeof Jt=="object"&&Jt)||function(){return this}()||Function("return this")()});var q=p((hd,Ti)=>{"use strict";Ti.exports=function(r){try{return!!r()}catch{return!0}}});var Ae=p((dd,Ii)=>{"use strict";var al=q();Ii.exports=!al(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Ri=p((md,wi)=>{"use strict";var ll=Ae(),Si=Function.prototype,xi=Si.apply,Ai=Si.call;wi.exports=typeof Reflect=="object"&&Reflect.apply||(ll?Ai.bind(xi):function(){return Ai.apply(xi,arguments)})});var H=p((fd,Pi)=>{"use strict";var Oi=Ae(),ki=Function.prototype,er=ki.call,cl=Oi&&ki.bind.bind(er,er);Pi.exports=Oi?cl:function(r){return function(){return er.apply(r,arguments)}}});var Se=p((vd,Mi)=>{"use strict";var Vi=H(),pl=Vi({}.toString),ul=Vi("".slice);Mi.exports=function(r){return ul(pl(r),8,-1)}});var tr=p((bd,_i)=>{"use strict";var hl=Se(),dl=H();_i.exports=function(r){if(hl(r)==="Function")return dl(r)}});var D=p((yd,Li)=>{"use strict";var rr=typeof document=="object"&&document.all;Li.exports=typeof rr>"u"&&rr!==void 0?function(r){return typeof r=="function"||r===rr}:function(r){return typeof r=="function"}});var ie=p((gd,Fi)=>{"use strict";var ml=q();Fi.exports=!ml(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var at=p((Cd,Ni)=>{"use strict";var fl=Ae(),st=Function.prototype.call;Ni.exports=fl?st.bind(st):function(){return st.apply(st,arguments)}});var ir=p(Bi=>{"use strict";var $i={}.propertyIsEnumerable,ji=Object.getOwnPropertyDescriptor,vl=ji&&!$i.call({1:2},1);Bi.f=vl?function(e){var t=ji(this,e);return!!t&&t.enumerable}:$i});var nr=p((Td,qi)=>{"use strict";qi.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Hi=p((Id,Di)=>{"use strict";var bl=H(),yl=q(),gl=Se(),or=Object,Cl=bl("".split);Di.exports=yl(function(){return!or("z").propertyIsEnumerable(0)})?function(r){return gl(r)==="String"?Cl(r,""):or(r)}:or});var sr=p((xd,Ui)=>{"use strict";Ui.exports=function(r){return r==null}});var ar=p((Ad,Gi)=>{"use strict";var El=sr(),Tl=TypeError;Gi.exports=function(r){if(El(r))throw new Tl("Can't call method on "+r);return r}});var we=p((Sd,Wi)=>{"use strict";var Il=Hi(),xl=ar();Wi.exports=function(r){return Il(xl(r))}});var ue=p((wd,zi)=>{"use strict";var Al=D();zi.exports=function(r){return typeof r=="object"?r!==null:Al(r)}});var Re=p((Rd,Ki)=>{"use strict";Ki.exports={}});var lt=p((Od,Xi)=>{"use strict";var lr=Re(),cr=K(),Sl=D(),Qi=function(r){return Sl(r)?r:void 0};Xi.exports=function(r,e){return arguments.length<2?Qi(lr[r])||Qi(cr[r]):lr[r]&&lr[r][e]||cr[r]&&cr[r][e]}});var Zi=p((kd,Yi)=>{"use strict";var wl=H();Yi.exports=wl({}.isPrototypeOf)});var rn=p((Pd,tn)=>{"use strict";var Rl=K(),Ji=Rl.navigator,en=Ji&&Ji.userAgent;tn.exports=en?String(en):""});var pn=p((Vd,cn)=>{"use strict";var ln=K(),pr=rn(),nn=ln.process,on=ln.Deno,sn=nn&&nn.versions||on&&on.version,an=sn&&sn.v8,U,ct;an&&(U=an.split("."),ct=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!ct&&pr&&(U=pr.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=pr.match(/Chrome\/(\d+)/),U&&(ct=+U[1])));cn.exports=ct});var ur=p((Md,hn)=>{"use strict";var un=pn(),Ol=q(),kl=K(),Pl=kl.String;hn.exports=!!Object.getOwnPropertySymbols&&!Ol(function(){var r=Symbol("symbol detection");return!Pl(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&un&&un<41})});var hr=p((_d,dn)=>{"use strict";var Vl=ur();dn.exports=Vl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var dr=p((Ld,mn)=>{"use strict";var Ml=lt(),_l=D(),Ll=Zi(),Fl=hr(),Nl=Object;mn.exports=Fl?function(r){return typeof r=="symbol"}:function(r){var e=Ml("Symbol");return _l(e)&&Ll(e.prototype,Nl(r))}});var vn=p((Fd,fn)=>{"use strict";var $l=String;fn.exports=function(r){try{return $l(r)}catch{return"Object"}}});var mr=p((Nd,bn)=>{"use strict";var jl=D(),Bl=vn(),ql=TypeError;bn.exports=function(r){if(jl(r))return r;throw new ql(Bl(r)+" is not a function")}});var gn=p(($d,yn)=>{"use strict";var Dl=mr(),Hl=sr();yn.exports=function(r,e){var t=r[e];return Hl(t)?void 0:Dl(t)}});var En=p((jd,Cn)=>{"use strict";var fr=at(),vr=D(),br=ue(),Ul=TypeError;Cn.exports=function(r,e){var t,i;if(e==="string"&&vr(t=r.toString)&&!br(i=fr(t,r))||vr(t=r.valueOf)&&!br(i=fr(t,r))||e!=="string"&&vr(t=r.toString)&&!br(i=fr(t,r)))return i;throw new Ul("Can't convert object to primitive value")}});var In=p((Bd,Tn)=>{"use strict";Tn.exports=!0});var Sn=p((qd,An)=>{"use strict";var xn=K(),Gl=Object.defineProperty;An.exports=function(r,e){try{Gl(xn,r,{value:e,configurable:!0,writable:!0})}catch{xn[r]=e}return e}});var pt=p((Dd,On)=>{"use strict";var Wl=In(),zl=K(),Kl=Sn(),wn="__core-js_shared__",Rn=On.exports=zl[wn]||Kl(wn,{});(Rn.versions||(Rn.versions=[])).push({version:"3.43.0",mode:Wl?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var yr=p((Hd,Pn)=>{"use strict";var kn=pt();Pn.exports=function(r,e){return kn[r]||(kn[r]=e||{})}});var Oe=p((Ud,Vn)=>{"use strict";var Ql=ar(),Xl=Object;Vn.exports=function(r){return Xl(Ql(r))}});var he=p((Gd,Mn)=>{"use strict";var Yl=H(),Zl=Oe(),Jl=Yl({}.hasOwnProperty);Mn.exports=Object.hasOwn||function(e,t){return Jl(Zl(e),t)}});var gr=p((Wd,_n)=>{"use strict";var ec=H(),tc=0,rc=Math.random(),ic=ec(1.1.toString);_n.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+ic(++tc+rc,36)}});var ke=p((zd,Fn)=>{"use strict";var nc=K(),oc=yr(),Ln=he(),sc=gr(),ac=ur(),lc=hr(),de=nc.Symbol,Cr=oc("wks"),cc=lc?de.for||de:de&&de.withoutSetter||sc;Fn.exports=function(r){return Ln(Cr,r)||(Cr[r]=ac&&Ln(de,r)?de[r]:cc("Symbol."+r)),Cr[r]}});var Bn=p((Kd,jn)=>{"use strict";var pc=at(),Nn=ue(),$n=dr(),uc=gn(),hc=En(),dc=ke(),mc=TypeError,fc=dc("toPrimitive");jn.exports=function(r,e){if(!Nn(r)||$n(r))return r;var t=uc(r,fc),i;if(t){if(e===void 0&&(e="default"),i=pc(t,r,e),!Nn(i)||$n(i))return i;throw new mc("Can't convert object to primitive value")}return e===void 0&&(e="number"),hc(r,e)}});var Er=p((Qd,qn)=>{"use strict";var vc=Bn(),bc=dr();qn.exports=function(r){var e=vc(r,"string");return bc(e)?e:e+""}});var Un=p((Xd,Hn)=>{"use strict";var yc=K(),Dn=ue(),Tr=yc.document,gc=Dn(Tr)&&Dn(Tr.createElement);Hn.exports=function(r){return gc?Tr.createElement(r):{}}});var Ir=p((Yd,Gn)=>{"use strict";var Cc=ie(),Ec=q(),Tc=Un();Gn.exports=!Cc&&!Ec(function(){return Object.defineProperty(Tc("div"),"a",{get:function(){return 7}}).a!==7})});var Kn=p(zn=>{"use strict";var Ic=ie(),xc=at(),Ac=ir(),Sc=nr(),wc=we(),Rc=Er(),Oc=he(),kc=Ir(),Wn=Object.getOwnPropertyDescriptor;zn.f=Ic?Wn:function(e,t){if(e=wc(e),t=Rc(t),kc)try{return Wn(e,t)}catch{}if(Oc(e,t))return Sc(!xc(Ac.f,e,t),e[t])}});var Xn=p((Jd,Qn)=>{"use strict";var Pc=q(),Vc=D(),Mc=/#|\.prototype\./,Pe=function(r,e){var t=Lc[_c(r)];return t===Nc?!0:t===Fc?!1:Vc(e)?Pc(e):!!e},_c=Pe.normalize=function(r){return String(r).replace(Mc,".").toLowerCase()},Lc=Pe.data={},Fc=Pe.NATIVE="N",Nc=Pe.POLYFILL="P";Qn.exports=Pe});var xr=p((em,Zn)=>{"use strict";var Yn=tr(),$c=mr(),jc=Ae(),Bc=Yn(Yn.bind);Zn.exports=function(r,e){return $c(r),e===void 0?r:jc?Bc(r,e):function(){return r.apply(e,arguments)}}});var eo=p((tm,Jn)=>{"use strict";var qc=ie(),Dc=q();Jn.exports=qc&&Dc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var ro=p((rm,to)=>{"use strict";var Hc=ue(),Uc=String,Gc=TypeError;to.exports=function(r){if(Hc(r))return r;throw new Gc(Uc(r)+" is not an object")}});var oo=p(no=>{"use strict";var Wc=ie(),zc=Ir(),Kc=eo(),ut=ro(),io=Er(),Qc=TypeError,Ar=Object.defineProperty,Xc=Object.getOwnPropertyDescriptor,Sr="enumerable",wr="configurable",Rr="writable";no.f=Wc?Kc?function(e,t,i){if(ut(e),t=io(t),ut(i),typeof e=="function"&&t==="prototype"&&"value"in i&&Rr in i&&!i[Rr]){var n=Xc(e,t);n&&n[Rr]&&(e[t]=i.value,i={configurable:wr in i?i[wr]:n[wr],enumerable:Sr in i?i[Sr]:n[Sr],writable:!1})}return Ar(e,t,i)}:Ar:function(e,t,i){if(ut(e),t=io(t),ut(i),zc)try{return Ar(e,t,i)}catch{}if("get"in i||"set"in i)throw new Qc("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var ao=p((nm,so)=>{"use strict";var Yc=ie(),Zc=oo(),Jc=nr();so.exports=Yc?function(r,e,t){return Zc.f(r,e,Jc(1,t))}:function(r,e,t){return r[e]=t,r}});var ve=p((om,co)=>{"use strict";var Ve=K(),ep=Ri(),tp=tr(),rp=D(),ip=Kn().f,np=Xn(),me=Re(),op=xr(),fe=ao(),lo=he();pt();var sp=function(r){var e=function(t,i,n){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,i)}return new r(t,i,n)}return ep(r,this,arguments)};return e.prototype=r.prototype,e};co.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,o=r.proto,a=i?Ve:n?Ve[t]:Ve[t]&&Ve[t].prototype,s=i?me:me[t]||fe(me,t,{})[t],l=s.prototype,c,d,m,f,b,R,E,y,u;for(f in e)c=np(i?f:t+(n?".":"#")+f,r.forced),d=!c&&a&&lo(a,f),R=s[f],d&&(r.dontCallGetSet?(u=ip(a,f),E=u&&u.value):E=a[f]),b=d&&E?E:e[f],!(!c&&!o&&typeof R==typeof b)&&(r.bind&&d?y=op(b,Ve):r.wrap&&d?y=sp(b):o&&rp(b)?y=tp(b):y=b,(r.sham||b&&b.sham||R&&R.sham)&&fe(y,"sham",!0),fe(s,f,y),o&&(m=t+"Prototype",lo(me,m)||fe(me,m,{}),fe(me[m],f,b),r.real&&l&&(c||!l[f])&&fe(l,f,b)))}});var uo=p((sm,po)=>{"use strict";var ap=Math.ceil,lp=Math.floor;po.exports=Math.trunc||function(e){var t=+e;return(t>0?lp:ap)(t)}});var Me=p((am,ho)=>{"use strict";var cp=uo();ho.exports=function(r){var e=+r;return e!==e||e===0?0:cp(e)}});var fo=p((lm,mo)=>{"use strict";var pp=Me(),up=Math.max,hp=Math.min;mo.exports=function(r,e){var t=pp(r);return t<0?up(t+e,0):hp(t,e)}});var bo=p((cm,vo)=>{"use strict";var dp=Me(),mp=Math.min;vo.exports=function(r){var e=dp(r);return e>0?mp(e,9007199254740991):0}});var _e=p((pm,yo)=>{"use strict";var fp=bo();yo.exports=function(r){return fp(r.length)}});var Or=p((um,Co)=>{"use strict";var vp=we(),bp=fo(),yp=_e(),go=function(r){return function(e,t,i){var n=vp(e),o=yp(n);if(o===0)return!r&&-1;var a=bp(i,o),s;if(r&&t!==t){for(;o>a;)if(s=n[a++],s!==s)return!0}else for(;o>a;a++)if((r||a in n)&&n[a]===t)return r||a||0;return!r&&-1}};Co.exports={includes:go(!0),indexOf:go(!1)}});var ht=p((hm,Eo)=>{"use strict";Eo.exports=function(){}});var To=p(()=>{"use strict";var gp=ve(),Cp=Or().includes,Ep=q(),Tp=ht(),Ip=Ep(function(){return!Array(1).includes()});gp({target:"Array",proto:!0,forced:Ip},{includes:function(e){return Cp(this,e,arguments.length>1?arguments[1]:void 0)}});Tp("includes")});var dt=p((fm,Io)=>{"use strict";var xp=lt();Io.exports=xp});var Ao=p((vm,xo)=>{"use strict";To();var Ap=dt();xo.exports=Ap("Array","includes")});var wo=p((bm,So)=>{"use strict";var Sp=Ao();So.exports=Sp});var mt=p((ym,Ro)=>{"use strict";var wp=wo();Ro.exports=wp});var Ko=p(()=>{"use strict";var Lp=ve(),Fp=Oe(),Np=_e(),$p=Me(),jp=ht();Lp({target:"Array",proto:!0},{at:function(e){var t=Fp(this),i=Np(t),n=$p(e),o=n>=0?n:i+n;return o<0||o>=i?void 0:t[o]}});jp("at")});var Xo=p((Qf,Qo)=>{"use strict";Ko();var Bp=dt();Qo.exports=Bp("Array","at")});var Zo=p((Xf,Yo)=>{"use strict";var qp=Xo();Yo.exports=qp});var jr=p((Yf,Jo)=>{"use strict";var Dp=Zo();Jo.exports=Dp});var os=p((mv,ns)=>{"use strict";var Gp=yr(),Wp=gr(),is=Gp("keys");ns.exports=function(r){return is[r]||(is[r]=Wp(r))}});var as=p((fv,ss)=>{"use strict";var zp=q();ss.exports=!zp(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var ps=p((vv,cs)=>{"use strict";var Kp=he(),Qp=D(),Xp=Oe(),Yp=os(),Zp=as(),ls=Yp("IE_PROTO"),Br=Object,Jp=Br.prototype;cs.exports=Zp?Br.getPrototypeOf:function(r){var e=Xp(r);if(Kp(e,ls))return e[ls];var t=e.constructor;return Qp(t)&&e instanceof t?t.prototype:e instanceof Br?Jp:null}});var hs=p((bv,us)=>{"use strict";us.exports={}});var fs=p((yv,ms)=>{"use strict";var eu=H(),qr=he(),tu=we(),ru=Or().indexOf,iu=hs(),ds=eu([].push);ms.exports=function(r,e){var t=tu(r),i=0,n=[],o;for(o in t)!qr(iu,o)&&qr(t,o)&&ds(n,o);for(;e.length>i;)qr(t,o=e[i++])&&(~ru(n,o)||ds(n,o));return n}});var bs=p((gv,vs)=>{"use strict";vs.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var gs=p((Cv,ys)=>{"use strict";var nu=fs(),ou=bs();ys.exports=Object.keys||function(e){return nu(e,ou)}});var Dr=p((Ev,xs)=>{"use strict";var Es=ie(),su=q(),Ts=H(),au=ps(),lu=gs(),cu=we(),pu=ir().f,Is=Ts(pu),uu=Ts([].push),hu=Es&&su(function(){var r=Object.create(null);return r[2]=2,!Is(r,2)}),Cs=function(r){return function(e){for(var t=cu(e),i=lu(t),n=hu&&au(t)===null,o=i.length,a=0,s=[],l;o>a;)l=i[a++],(!Es||(n?l in t:Is(t,l)))&&uu(s,r?[l,t[l]]:t[l]);return s}};xs.exports={entries:Cs(!0),values:Cs(!1)}});var As=p(()=>{"use strict";var du=ve(),mu=Dr().entries;du({target:"Object",stat:!0},{entries:function(e){return mu(e)}})});var ws=p((xv,Ss)=>{"use strict";As();var fu=Re();Ss.exports=fu.Object.entries});var Os=p((Av,Rs)=>{"use strict";var vu=ws();Rs.exports=vu});var Ps=p((Sv,ks)=>{"use strict";var bu=Os();ks.exports=bu});var Ns=p(()=>{"use strict";var Au=ve(),Su=Dr().values;Au({target:"Object",stat:!0},{values:function(e){return Su(e)}})});var js=p((ob,$s)=>{"use strict";Ns();var wu=Re();$s.exports=wu.Object.values});var qs=p((sb,Bs)=>{"use strict";var Ru=js();Bs.exports=Ru});var Nt=p((ab,Ds)=>{"use strict";var Ou=qs();Ds.exports=Ou});var Jr=p((Pb,Ks)=>{"use strict";var Lu=Se();Ks.exports=Array.isArray||function(e){return Lu(e)==="Array"}});var Xs=p((Vb,Qs)=>{"use strict";var Fu=TypeError,Nu=9007199254740991;Qs.exports=function(r){if(r>Nu)throw Fu("Maximum allowed index exceeded");return r}});var Js=p((Mb,Zs)=>{"use strict";var $u=Jr(),ju=_e(),Bu=Xs(),qu=xr(),Ys=function(r,e,t,i,n,o,a,s){for(var l=n,c=0,d=a?qu(a,s):!1,m,f;c<i;)c in t&&(m=d?d(t[c],c,e):t[c],o>0&&$u(m)?(f=ju(m),l=Ys(r,e,m,f,l,o-1)-1):(Bu(l+1),r[l]=m),l++),c++;return l};Zs.exports=Ys});var ra=p((_b,ta)=>{"use strict";var Du=ke(),Hu=Du("toStringTag"),ea={};ea[Hu]="z";ta.exports=String(ea)==="[object z]"});var na=p((Lb,ia)=>{"use strict";var Uu=ra(),Gu=D(),jt=Se(),Wu=ke(),zu=Wu("toStringTag"),Ku=Object,Qu=jt(function(){return arguments}())==="Arguments",Xu=function(r,e){try{return r[e]}catch{}};ia.exports=Uu?jt:function(r){var e,t,i;return r===void 0?"Undefined":r===null?"Null":typeof(t=Xu(e=Ku(r),zu))=="string"?t:Qu?jt(e):(i=jt(e))==="Object"&&Gu(e.callee)?"Arguments":i}});var sa=p((Fb,oa)=>{"use strict";var Yu=H(),Zu=D(),ei=pt(),Ju=Yu(Function.toString);Zu(ei.inspectSource)||(ei.inspectSource=function(r){return Ju(r)});oa.exports=ei.inspectSource});var ha=p((Nb,ua)=>{"use strict";var eh=H(),th=q(),aa=D(),rh=na(),ih=lt(),nh=sa(),la=function(){},ca=ih("Reflect","construct"),ti=/^\s*(?:class|function)\b/,oh=eh(ti.exec),sh=!ti.test(la),We=function(e){if(!aa(e))return!1;try{return ca(la,[],e),!0}catch{return!1}},pa=function(e){if(!aa(e))return!1;switch(rh(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return sh||!!oh(ti,nh(e))}catch{return!0}};pa.sham=!0;ua.exports=!ca||th(function(){var r;return We(We.call)||!We(Object)||!We(function(){r=!0})||r})?pa:We});var va=p(($b,fa)=>{"use strict";var da=Jr(),ah=ha(),lh=ue(),ch=ke(),ph=ch("species"),ma=Array;fa.exports=function(r){var e;return da(r)&&(e=r.constructor,ah(e)&&(e===ma||da(e.prototype))?e=void 0:lh(e)&&(e=e[ph],e===null&&(e=void 0))),e===void 0?ma:e}});var ya=p((jb,ba)=>{"use strict";var uh=va();ba.exports=function(r,e){return new(uh(r))(e===0?0:e)}});var ga=p(()=>{"use strict";var hh=ve(),dh=Js(),mh=Oe(),fh=_e(),vh=Me(),bh=ya();hh({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=mh(this),i=fh(t),n=bh(t,0);return n.length=dh(n,t,t,i,0,e===void 0?1:vh(e)),n}})});var Ca=p(()=>{"use strict";var yh=ht();yh("flat")});var Ta=p((Ub,Ea)=>{"use strict";ga();Ca();var gh=dt();Ea.exports=gh("Array","flat")});var xa=p((Gb,Ia)=>{"use strict";var Ch=Ta();Ia.exports=Ch});var Sa=p((Wb,Aa)=>{"use strict";var Eh=xa();Aa.exports=Eh});var ui="1.0.54-dev.4058ce66.0";import{fromEvent as zo,Subscription as _p}from"@vkontakte/videoplayer-shared";var Gt=class{constructor(e,t){this.layout=e;this.cssVarsManager=t}},Ye=class extends Gt{constructor(t,i){super(t,i);this.cssVarsManager=i;this.cssVarsManager=i}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,i){let n=this.cssVarsManager.getPropValue("--interactive-content-width"),o=this.cssVarsManager.getPropValue("--interactive-content-height"),a=this.cssVarsManager.getPropValue("--interactive-width"),s=this.cssVarsManager.getPropValue("--interactive-height"),l=2e-4;t.style.position="absolute",t.style.width=`calc(${n} * (${i.width} + ${l}))`,t.style.height=`calc(${o} * ${i.height})`,t.style.left=`calc(${n} * ${i.x} + ((${a} - ${n}) / 2))`,t.style.top=`calc(${o} * ${i.y} + ((${s} - ${o}) / 2))`}};import{Subject as nl}from"@vkontakte/videoplayer-shared";function hi(r){return"features"in r}var M=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};function Ze({emitter$:r,error:e,subjectId:t,message:i="",severity:n=1,category:o=1}){let a=new M(n,o,{message:i,error:e,details:{id:t}});r.next(a)}var le=class{constructor(e,t,i){this.error$=new nl;this.container=e,this.options=i,this.factories=new Map,this.controls=[],this.setControls(),this.cssVarsManager=t}featureIsEnabled(e){return this.options&&this.options.features&&hi(this.options)&&this.options.features[e]}onError(e="",t){Ze({emitter$:this.error$,error:t,message:e,subjectId:this.container.id})}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((e,t)=>{let i=t.type.trim().toLowerCase(),n=this.factories.get(i);if(n){let o=n(t,this.options);if(o)return[...e,o]}return[...e]},[])||[]}};import{fromEvent as Fe,once as No}from"@vkontakte/videoplayer-shared";var Y=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Z=r=>Y(r,"Object"),Je=r=>Y(r,"String"),et=r=>Y(r,"Array"),tt=r=>Y(r,"Number"),di=r=>Y(r,"Function"),mi=r=>Y(r,"Boolean"),Kt=r=>tt(r)&&!isNaN(r);var te=r=>Z(r)&&Object.keys(r).length===0,Qt=r=>et(r)&&!r.length;var Ee=(r,e)=>Je(r)&&(e?r.trim():r).length;function Te(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var fi="interactive",O={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderWidthRawValue:"1px",roundCornersRawValue:"0",borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0,shadowColorLight:"#fff",shadowColorDark:"#000",shadowColorAlpha:.24},vi=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(vi||{}),bi=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(bi||{}),yi=(i=>(i.start="left",i.end="right",i.center="center",i))(yi||{}),rt=({target:r,props:e})=>{r.style.alignItems=(e?.gravityVertical&&vi[e.gravityVertical])??"center",r.style.justifyContent=(e?.gravityHorizontal&&bi[e.gravityHorizontal])??"center",r.style.textAlign=(e?.alignment&&yi[e.alignment])??"center"},it=({target:r,props:e,fallback:t,dependsOn:i})=>{r.style.color=e?.text?.color??t.textColor,r.style.fontSize=`calc(${i.height} * ${e?.text?.size??t.textSize})`,r.textContent=e?.text?.value??t.textContent},nt=({target:r,props:e,fallback:t})=>{r.style.backgroundColor=Te(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},Ie=({target:r,props:e,fallback:t,dependsOn:i,useRawValues:n=!1})=>{let o=n?t.borderWidthRawValue:`calc(${i.height} * ${e?.shape?.border?.width??t.borderWidth})`,a=n?t.roundCornersRawValue:`calc(${i.height} * ${e?.shape?.roundCorners??t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Te(n?t.borderColor:e?.shape?.border?.color??t.borderColor,n?t.borderAlpha:e?.shape?.border?.alpha??t.borderAlpha),r.style.borderRadius=a},gi=({target:r,isDark:e,baseDimension:t,fallback:i})=>{let a=Te(i.shadowColorLight,i.shadowColorAlpha),s=Te(i.shadowColorDark,i.shadowColorAlpha),l=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,d=`0px 0px ${l} ${c} ${e?s:a}`;r.style.boxShadow=d},ce=({target:r,layoutParams:e,fallback:t})=>{let i=e.angle??t.angle;i=i&&i*-1,r.style.transform=`rotate(${i}rad)`};import{fromEvent as Le,Subject as Op,Subscription as kp}from"@vkontakte/videoplayer-shared";var Xt="interactive-control-tap",pe={common:Xt,animation:`${Xt}-animation`,visible:`${Xt}-visible`};var ol=60,ot=class{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:i=ol,useDimensionsBasedSize:n=!1}){this.onElementClick=e=>{if(!e.target||!e.currentTarget||this.clickCancelCondition())return;let t=e.currentTarget.parentElement;if(!t)return;let i=t.getBoundingClientRect(),n={width:this.useDimensionsBasedSize?t.offsetWidth:this.circleDiameterPx,height:this.useDimensionsBasedSize?t.offsetHeight:this.circleDiameterPx},o=Math.min(n.width,n.height),a=i.left+i.width/2,s=i.top+i.height/2,l=e.clientX-a,c=e.clientY-s,d=sl(l,c,this.controlRotateAngleRad);this.element.style.width=o+"px",this.element.style.left=d.x+i.width/2-o/2+"px",this.element.style.top=d.y+i.height/2-o/2+"px",this.element.classList.add(pe.visible,pe.animation)};this.onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(pe.visible,pe.animation)};let o=document.createElement("div");o.classList.add(pe.common),this.controlRotateAngleRad=e,this.element=o,this.clickCancelCondition=t,this.circleDiameterPx=i,this.useDimensionsBasedSize=n}};function sl(r,e,t){return{x:r*Math.cos(t)-e*Math.sin(t),y:r*Math.sin(t)+e*Math.cos(t)}}var Yt="int",re=(i=>(i.AREA=`${Yt}_area`,i.TEXT=`${Yt}_text`,i.BUTTON=`${Yt}_bttn`,i))(re||{});function Zt(r){return"features"in r}var z="interactive-control",w={common:z,selected:`${z}-selected`,wrapper:`${z}-wrapper`,disabled:`${z}-disabled`,button:`${z}-button`,area:`${z}-area`,text:`${z}-text`,blinkAnim:`${z}-blink-anim`,blinkAnimButton:`${z}-blink-anim-button`,blinkAnimArea:`${z}-blink-anim-area`},Ci=40;var Vo=W(mt(),1);import{isSupportedManifest as vt,ContainerTypes as Pm,ControlTypes as bt,EventActionTypes as A,EventTypes as Vm,migrateManifestToLatestVersion as Po,compareVersions as Mm}from"@interactiveplatform/movika-manifest";var Oo={metadata:"Object",chapters:"Array"},ko=r=>{if(!Z(r))return!1;for(let e in Oo)if(!r[e]||!Y(r[e],Oo[e]))return!1;return vt(r.metadata.version)},ft=r=>r.type===bt.Text,Tm=r=>r.type===bt.Button,Im=r=>r.type===bt.Area,xm={Choice:"Choice",TextInput:"TextInput"},Am={Button:"Button",Area:"Area",Text:"Text"},Sm={onClick:"onClick",onSuspense:"onSuspense"},wm={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var yt=r=>et(r)&&!Qt(r),Q=r=>r.order==="end",gt=r=>et(r.containers)&&!Qt(r.containers)&&Q(r),Mo=(r,e)=>{let t=r*1e3;return yt(e.controls)&&t<(e.startTime??0)},kr=(r,e)=>{let t=r*1e3;return yt(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var ne=(r=[])=>r.some(e=>e.action.type==="expect"),Pr=(r=[])=>r.find(e=>e.action.type==="expect"),Rp=r=>r?.length===1,be=r=>Rp(r)&&ft(r[0]);function _o(r=[],e=1/0,t=[]){return r.filter(({container:i})=>!(0,Vo.default)(t,i.container.id)&&ne(i.container.events)&&i.container.endTime===e&&!i.isRemoved&&!i.willRemoved)}function Ct({gameControllers:r=[],subjectName:e,subjectId:t,execFn:i}){for(let n of r)if(e==="container"&&n.container.container.id===t){i(n),_o(r,n.container.container.endTime,[n.container.container.id]).forEach(a=>{i(a)});break}}function Lo(r){for(let e of r.events)if(e.action.type==="openURI")return!0;return!1}var Fo=(r,e)=>{let t=E=>e.find(({container:u})=>u.container.id===E)?.container.isRemoved,i=ne(r.events)&&!t(r.id),n=(E,y=!1,u=!1)=>{let h=u?"every":"some";return E.controls[h](v=>{let g=y?E.endTime===r.endTime:!0;return v.events?.[h](C=>C.action?.type===A.openURI)&&g})},o=E=>E.some(({container:y})=>n(y.container,!0,!1)&&!y.isRemoved),a=E=>E.every(({container:y})=>y.isRemoved||y.willRemoved?!0:n(y.container,!0,!0)),s=_o(e,r.endTime,[r.id]).length,l=E=>E.controls.some(y=>y.events?.some(u=>u.action?.args?.shouldOpenNow)),c=i||s>0,d=o(e),m=n(r),f=a(e),b=i?!1:s>0,R=l(r);return{isExpectTime:c,hasOtherExpect:s>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:m,isAllOpenURIEventsValid:f,isExpectEventForCurrentContainer:b,hasShouldOpenNowEvent:R}};var J=class r{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new kp;this.error$=new Op;this.isInteracted=!1;this.isRemoved=!1;this.cssVarsManager=null;this.onControlSelect=()=>{this.container?.isManifestContainerDisabled()||Lo(this.control)||this.container?.element?.classList.add("interactive-control-wrapper-selected")};this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()}}setCssVarsManager(e){this.cssVarsManager=e}removeView(e=!1){let t=this.getElement();if(t){if(e){if(t.classList.contains("interactive-control-before-remove"))return;t.classList.add("interactive-control-before-remove"),this.subscriptions.add(Le(t,"transitionend").subscribe(this.onTransitionEnd,n=>this.onError(`${r.name} remove view transition error`,n))).add(Le(t,"transitioncancel").subscribe(this.onTransitionEnd,n=>this.onError(`${r.name} remove view transition error`,n)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e="",t){Ze({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){if(this.featureIsEnabled("controlsTapPlace")&&this.container){let t=this.control.layoutParams.angle??O.angle;this.controlTap=new ot({controlRotateAngleRad:t,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?Ci:void 0}),this.subscriptions.add(Le(e,"click").subscribe(this.controlTap.onElementClick,i=>this.onError("Control click tap animation error",i))).add(Le(this.controlTap.element,"animationend").subscribe(this.controlTap.onAnimationEnd,i=>this.onError("Tap animationend error",i))),this.container.element.append(this.controlTap.element)}}createContainerElement(e){let t=document.createElement("div");t.classList.add(w.wrapper),e.setControlLayout(t,this.control.layoutParams);let i=(this.control.layoutParams.innerSizesDependOn??O.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:this.cssVarsManager?.getPropValue("--interactive-content-height")??0,width:this.cssVarsManager?.getPropValue("--interactive-content-width")??0},n=()=>e.isContainerDisabled?.()??!1;this.container={element:t,dimensions:i,isManifestContainerDisabled:n}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return this.options&&Zt(this.options)&&this.options.features[e]}isTouch(){return this.options&&Zt(this.options)&&this.options.isTouch}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":{if(!this.container)break;this.subscriptions.add(Le(this.container.element,"click").subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),n=>this.onError("Error happened on control interaction",n)));break}default:break}})}removeListeners(){this.subscriptions.unsubscribe()}};var Vr="interactive-blink-anim-reference",_={common:Vr,animation:`${Vr}-animation`,disabled:`${Vr}-disabled`},Et=class{constructor(){this._RAFId=0;this._element=void 0}get element(){return this._element}create(){if(this._element)return;let e=document.createElement("div");e.classList.add(_.common,_.animation),this._element=e}restart(){this._element&&(this._element.classList.add(_.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(_.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var Mr="interactive-container",L={common:Mr,hidden:`${Mr}-hidden`,disabled:`${Mr}-disabled`};var Tt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new _r(r,e)},_r=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.area),i.setAttribute("data-testid",re.AREA),nt({target:i,props:this.control.props,fallback:{...O,backgroundColor:"transparent"}}),ce({target:i,layoutParams:this.control.layoutParams,fallback:O}),this.addControlTap(i),this.subscriptions.add(Fe(this.container.element,"click").pipe(No()).subscribe(this.onControlSelect,n=>this.onError("Control click handler error",n))),this.container.element.append(i),e.append(this.container.element),this.controlElement=i,this.updateShadowStyles(),this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(Fe(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(L.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${_.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(Fe(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(L.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(Fe(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(w.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(w.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(mi(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";gi({target:this.controlElement,props:this.control.props,fallback:O,isDark:e,baseDimension:t}),Ie({target:this.controlElement,props:this.control.props,fallback:{...O,borderColor:e?O.shadowColorDark:O.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??O.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Ie({target:this.controlElement,props:this.control.props,fallback:{...O,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(w.blinkAnim,e),this.controlElement?.classList.toggle(w.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${w.blinkAnimArea}`)||this.controlElement.classList.contains(w.selected)||this.controlElement.classList.contains(_.disabled)||(this.controlElement.classList.add(_.disabled),this.subscriptions.add(Fe(e,"animationiteration").pipe(No()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(_.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${w.blinkAnimArea}`)||this.controlElement.classList.contains(w.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-area-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}setShowTimeRange(){}updateFillAnimationDimensions(){}onProgress(){}onResize(){}};import{fromEvent as Ne,once as Go}from"@vkontakte/videoplayer-shared";var It=r=>{let e=document.createElement("span");switch(r){case"Button":case"button":{let t=document.createElement("div"),i={overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center"};Object.assign(t.style,i),t.append(e);let n={display:"inline-block",whiteSpace:"pre",textOverflow:"ellipsis",maxWidth:"initial",maxHeight:"100%",wordBreak:"normal"};return Object.assign(e.style,n),t}default:{let t={display:"inline-block",whiteSpace:"break-spaces",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",maxHeight:"100%",wordBreak:"break-all"};return Object.assign(e.style,t),e}}};var xt=Math.PI,Lr=2*xt,At=xt/2,$o=3*At,Pp=0,Vp=[Pp,At,xt,$o];function jo(r){return r===At}function Bo(r){return r===xt}function qo(r){return r===$o}function Do(r){return(r%Lr+Lr)%Lr}function Mp(r){for(let e of Vp)if(r===e)return e}function Ho(r){if(Mp(r))return null;let t=Math.floor(r/At)+1;return[1,2,3,4][t-1]}function Uo(r){return r*180/Math.PI}var X="interactive-control-fill-animation",F={common:X,fillerWrapper:`${X}-filler-wrapper`,filler:`${X}-filler`,fillHeight:`${X}-fill-height`,fillWidth:`${X}-fill-width`,fromTop:`${X}-from-top`,fromBottom:`${X}-from-bottom`,fromLeft:`${X}-from-left`,fromRight:`${X}-from-right`};var St=class r{constructor(e){this.widthExpansionCoef=0;let t=document.createElement("div");t.classList.add(F.common);let i=document.createElement("div");i.classList.add(F.fillerWrapper);let n=document.createElement("div");n.classList.add(F.filler),i.append(n),t.append(i);let o=Do(e.rotateAngle),a=Ho(o),s=a!==null,c=a===2||!s&&Bo(o)||a===3,d=!s&&jo(o),m=!s&&qo(o),f=!c&&!d&&!m,b=d||m,R=s&&!b,E=R?o:0;t.style.borderRadius=e.borderRadius,i.style.transform=`skew(${E*-1}rad)`,b?(n.classList.add(F.fillHeight,d?F.fromTop:F.fromBottom),i.classList.add(F.fillHeight,d?F.fromTop:F.fromBottom)):(n.classList.add(F.fillWidth,f?F.fromLeft:F.fromRight),i.classList.add(F.fillWidth)),e.debug&&console.log(`[interactive ${r.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:b,rotateAngleRad:o,rotateAngelDeg:Uo(o),rotateAngleRaw:e.rotateAngle,fromRight:c,fromTop:d,fromBottom:m,fromLeft:f}),this.useSkew=R,this.fromLeft=f,this.rotateAngle=o,this.fillAnimationElement=t,this.fillAnimationFillerElement=n,this.fillAnimationFillerWrapperElement=i,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=b,this.isDebug=e.debug??!1}updateDimension(e){this.fillAnimationElement.style.top=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.left=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.width=`${e.width}px`,this.fillAnimationElement.style.height=`${e.height}px`;let t=this.calcWidthExpansionCoef({rotateAngle:this.rotateAngle,isSkewed:this.useSkew,initWidth:e.width,initHeight:e.height});!this.shouldFillHeight&&(this.fillAnimationFillerWrapperElement.style.width=100*t+100+"%",this.fillAnimationFillerWrapperElement.style[`${this.fromLeft?"left":"right"}`]=`calc((${t} * 100%) / 2 * -1)`),this.widthExpansionCoef=t}updateAnimation(e){if((o=>o<this.startTime||o>this.endTime)(e))return;let i=this.endTime-this.startTime,n=Math.min(Math.max((e-this.startTime)/i,0),1);this.shouldFillHeight?this.fillAnimationFillerElement.style.transform=`scaleY(${n})`:this.fillAnimationFillerElement.style.transform=`scaleX(${n})`}calcWidthExpansionCoef({rotateAngle:e,isSkewed:t=!1,initWidth:i,initHeight:n}){return t?(i+n*Math.abs(Math.tan(e)))/i-1:0}};var wt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new Fr(r,e)},Fr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.button),i.setAttribute("data-testid",re.BUTTON),ce({target:i,layoutParams:this.control.layoutParams,fallback:O}),nt({target:i,props:this.control.props,fallback:O}),Ie({target:i,props:this.control.props,fallback:O,dependsOn:this.container.dimensions}),rt({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=It(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;it({target:o,props:this.control.props,fallback:O,dependsOn:this.container.dimensions}),this.addControlTap(i),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled("controlsFillAnimation")&&(this.controlFillAnimation=new St({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??O.angle,borderRadius:i.style.borderRadius})),this.subscriptions.add(Ne(i,"click").pipe(Go()).subscribe(this.onControlSelect,a=>this.onError("Control click handler error",a))),i.append(n,this.controlFillAnimation?.fillAnimationElement??""),this.container.element.append(this.controlTap?.element??"",i),e.append(this.container.element),this.controlElement=i,this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(Ne(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(L.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${_.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(Ne(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(L.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(Ne(this.controlElement,"mouseleave").subscribe(()=>{this.controlElement&&(this.controlElement.style.animation="")},t=>this.onError("Error happened in mouseleave callback",t))))}disable(){this.controlElement&&this.controlElement.classList.add(w.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(w.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(w.blinkAnim,e),this.controlElement?.classList.toggle(w.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${w.blinkAnimButton}`)||this.controlElement.classList.contains(w.selected)||this.controlElement.classList.contains(_.disabled)||(this.controlElement.classList.add(_.disabled),this.subscriptions.add(Ne(e,"animationiteration").pipe(Go()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(_.disabled)},t=>this.onError("Error happened in animationiteration callback",t)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${w.blinkAnimButton}`)||this.controlElement.classList.contains(w.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue("--interactive-button-hover-opacity").trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation="none",requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}updateFillAnimationDimensions(){if(!this.container||!this.controlElement||!this.controlFillAnimation)return;let e=getComputedStyle(this.controlElement),t={width:parseFloat(e.width),height:parseFloat(e.height),borderWidth:parseFloat(e.borderWidth)||0};this.controlFillAnimation.updateDimension(t)}setShowTimeRange(e,t){this.startTime=e,this.endTime=t}onProgress(e){this.controlFillAnimation?.updateAnimation(e)}onResize(){this.updateFillAnimationDimensions()}updateShadowStyles(){}};var Wo=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new Nr(r,e)},Nr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let i=document.createElement("div");i.classList.add(w.common,w.text),i.setAttribute("data-testid",re.TEXT),ce({target:i,layoutParams:this.control.layoutParams,fallback:O}),rt({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=It(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;it({target:o,props:this.control.props,fallback:O,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}updateShadowStyles(){}toggleBlinkAnimation(){}setShowTimeRange(){}updateFillAnimationDimensions(){}};var Rt=(r,e,t,i)=>{if(r.type.trim().toLowerCase()==="choice")return new $r(r,e,t,i)},$r=class r extends le{constructor(t,i,n,o){super(t,n,o);this.containerElement=null;this.subscriptions=new _p;this.onTransitionEnd=t=>{t.stopPropagation(),!(!t.target||!t.currentTarget)&&t.target===t.currentTarget&&this.removeView()};this.rootElement=i,this.layout=new Ye(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",wt),this.addControlFactory("text",Wo),this.addControlFactory("area",Tt)}createView({eventCallback:t,videoDurationMs:i}){let n=document.createElement("div");return n.classList.add(L.common,L.disabled),n.setAttribute("data-subjectId",this.container.id),requestAnimationFrame(()=>{n.classList.remove(L.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(o=>{o.setShowTimeRange(this.container.startTime,this.container.endTime??i),o.setCssVarsManager(this.cssVarsManager),o.createView({parentElement:n,callbacks:{setControlLayout:(a,s)=>this.layout.setControlLayout(a,s),isContainerDisabled:()=>this.isDisabled}}),o.setEvents(t),this.subscriptions.add(o.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.willRemoved=!1,this.containerElement=n,this.updateControlsFillAnimationDimensions(),n}updateControlsFillAnimationDimensions(){for(let t of this.controls)t.updateFillAnimationDimensions()}hide(){let t=this.getElement();t&&t.classList.add(L.hidden)}show(){let t=this.getElement();t&&t.classList.remove(L.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(L.disabled),this.controls.forEach(i=>i.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(L.disabled),this.controls.forEach(i=>i.disable()),this.isDisabled=!0)}removeView(t=!1,i=!1){let n=this.getElement();if(n){if(t){if(this.willRemoved)return;this.willRemoved=!0,i&&n.classList.add("interactive-container-before-remove-delay"),n.classList.add("interactive-container-before-remove"),this.subscriptions.add(zo(n,"transitionend").subscribe(this.onTransitionEnd,a=>this.onError(`${r.name} remove view transition error`,a))).add(zo(n,"transitioncancel").subscribe(this.onTransitionEnd,a=>this.onError(`${r.name} remove view transition error`,a)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}removeAllControls(t=!1){this.controls.forEach(i=>i.removeView(t))}removeNonInteractedControls(t=!1){this.controls.forEach(i=>{i.isInteracted||i.removeView(t)})}isInteracted(){return this.controls.some(t=>t.isInteracted)}fakeRemove(){this.isRemoved||(this.isRemoved=!0)}getElement(){return this.containerElement}onProgress(t,i){i&&this.controls.forEach(n=>{n.onProgress(t)})}onResize(t){t&&this.controls.forEach(i=>{i.onResize()})}updateControlsShadowStyles(t){this.controls.forEach(i=>i.updateShadowStyles(t))}toggleBlinkAnimation(t){this.controls.forEach(i=>i.toggleBlinkAnimation(t))}};var Xa=W(jr(),1);import{combine as Mh,InterfaceLanguage as _h,Observable as za,once as Lh,Subject as N,Subscription as ai,ValueSubject as B,fromEvent as Ka}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as Qe}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Hp}from"@vkontakte/videoplayer-shared";function $e(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var es="video_interactive",ts="videoint";var rs=250,je=class{constructor(e){this.handleZoomChange=$e(e=>{this.lastZoomInfo=e},rs);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Chapter id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!tt(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:i,lang:n,visitedChapters:o=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(o),this.onOpenPreviewClick=t,this.onError=i,this.lang=n??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Up(e),this.resizeObserver=new ResizeObserver($e(this.onResize,rs)),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 Hp(this.lang,es,ts)}catch{this.onError?.("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"view",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:i,...n})=>{i==="openPreview"&&"chapterId"in n&&this.onOpenPreviewClick?.(n.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 Up(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var Be=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let o of this._containers){let a=o.startTime-e;if(a<=n&&(o.endTime&&n<=o.endTime||o.endTime===null)){i=!0;break}n<a&&(t=t===-1?a:Math.min(t,a))}return!i&&t!==-1?t:null}}};var Ot=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let i=()=>{t(),this.off(e,i)};return this.listeners[e].push(i),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let i=this.listeners[e]||[];for(let n=i.length;n>0;n--)if(i[n]===t){i.splice(n,1);break}return this}emit(e,...t){let i=this.listeners[e];return i?(i.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var kt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{di(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(i=>i!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};var Vs=W(Ps(),1),Pt=class r{constructor(e){this.rootElement=e;this.rootElementProps={};this.isCssVarsSupported=r.checkCssVarsSupport(e)}static checkCssVarsSupport(e){let t="--test-key",i="test";e.style.setProperty(t,i);let n=e.style.getPropertyValue(t)===i;return n&&e.style.removeProperty(t),n}getPropValue(e){return this.isCssVarsSupported?`var(${e})`:this.rootElementProps[e]??""}setup(e){if(this.rootElementProps={...this.rootElementProps,...e},this.isCssVarsSupported)for(let[t,i]of(0,Vs.default)(e))this.rootElement.style.setProperty(t,i)}cleanup(){for(let e in this.rootElementProps)this.rootElement.style.removeProperty(e);this.rootElementProps={}}setProp(e,t){this.rootElementProps[e]=t,this.isCssVarsSupported&&this.rootElement.style.setProperty(e,t)}};import{ValueSubject as xu}from"@vkontakte/videoplayer-shared";var Vt=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return yu(...this.loaders[e])(t)}};function yu(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function qe(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function Mt({actions:r,errors:e,chapterId:t,...i}){if(t){let n=r.getManifest();if(n){let o=r.getChapter(n.chapters,t);if(o){let a=r.getMedia(n.media,o.videoId),s=r.getGraph(n.graph,o.id);return a?{...i,actions:r,errors:e,result:{chapter:o,media:a,graph:s}}:{...i,errors:qe(e,Mt.name,"Could not find media"),actions:r}}}}return{...i,errors:qe(e,Mt.name,"Could not find chapter"),actions:r}}var{NativeAbortSignal:Ov,NativeAbortController:kv}=function(r){return{NativeAbortSignal:r.AbortSignal,NativeAbortController:r.AbortController}}(typeof self<"u"?self:global);function Ms(r){let e;try{e=new Event("abort")}catch{typeof document<"u"?document.createEvent?(e=document.createEvent("Event"),e.initEvent("abort",!1,!1)):(e=document.createEventObject(),e.type="abort"):e={type:"abort",bubbles:!1,cancelable:!1}}return e.reason=r,e}function _s(r){if(r===void 0)if(typeof document>"u")r=new Error("This operation was aborted"),r.name="AbortError";else try{r=new DOMException("signal is aborted without reason"),Object.defineProperty(r,"name",{value:"AbortError"})}catch{r=new Error("This operation was aborted"),r.name="AbortError"}return r}var _t=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,o=i.length;n<o;n++)if(i[n].callback===t){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,o=i.length;n<o;n++){let a=i[n];try{a.callback.call(this,e)}catch(s){Promise.resolve().then(()=>{throw s})}a.options&&a.options.once&&this.removeEventListener(e.type,a.callback)}return!e.defaultPrevented}},ye=class extends _t{constructor(){super(),this.listeners||_t.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)}throwIfAborted(){let{aborted:e,reason:t="Aborted"}=this;if(e)throw t}static timeout(e){let t=new oe;return setTimeout(()=>t.abort(new DOMException(`This signal is timeout in ${e}ms`,"TimeoutError")),e),t.signal}static any(e){let t=new oe;function i(){t.abort(this.reason),n()}function n(){for(let o of e)o.removeEventListener("abort",i)}for(let o of e)if(o.aborted){t.abort(o.reason);break}else o.addEventListener("abort",i);return t.signal}},oe=class{constructor(){Object.defineProperty(this,"signal",{value:new ye,writable:!0,configurable:!0})}abort(e){let t=_s(e),i=Ms(t);this.signal.reason=t,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(oe.prototype[Symbol.toStringTag]="AbortController",ye.prototype[Symbol.toStringTag]="AbortSignal");function Lt(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function Hr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!Lt({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:o};let o=t;(o&&!o.prototype.hasOwnProperty("signal")||n)&&(o=function(c,d){let m;d&&d.signal&&(m=d.signal,delete d.signal);let f=new t(c,d);return m&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),f},o.prototype=t.prototype);let a=e;return{fetch:(l,c)=>{let d=o&&o.prototype.isPrototypeOf(l)?l.signal:c?c.signal:void 0;if(d){let m;try{m=new DOMException("Aborted","AbortError")}catch{m=new Error("Aborted"),m.name="AbortError"}if(d.aborted)return Promise.reject(m);let f=new Promise((b,R)=>{d.addEventListener("abort",()=>R(m),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([f,a(l,c)])}return a(l,c)},Request:o}}var gu=()=>"fetch"in window,De=gu()&&Lt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ls=De?Hr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ur=De?Ls.fetch:window.fetch,Bv=De?Ls.Request:window.Request,qv=De?oe:window.AbortController,Dv=De?ye:window.AbortSignal;var Gr=(r="",e="")=>{let t=r.split("."),i=e.split("."),n=0;for(let o=0;o<Math.max(t.length,i.length)&&!n;o++)t[o]>i[o]?n=1:t[o]<i[o]?n=-1:n=0;return n};var Cu=async r=>{try{let e={},t;if(Je(r)){t=new URL(r).href;let n=await Ur(t);if(!n.ok)return{};e=await n.json()}else if(Z(r))e=r;else return{};if(!ko(e))return{};let i=e.metadata.media;if(Je(i)&&!("media"in e))try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let o=await Ur(n);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch{return Iu(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function Fs(r){let{manifest:e,manifestURL:t}=await Cu(r);if(!e)throw new Error("Failed on fetch");let i=Po(e);return i.media=Eu(i.media,t),delete i.metadata.media,i}function Ft(r,e){if(e)return r.find(t=>t.id===e)}function Wr(r,e){return r.edit?.chapters?r.edit.chapters.find(t=>t.id===e):r.view?.chapters?r.view.chapters.find(t=>t.id===e):void 0}function zr(r,e){return r.videos.find(t=>t.id===e)}function Eu(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",o=Tu(n,e);return{...i,url:o||n}})}))}}function Tu(r="",e){try{return new URL(r,e).href}catch{return""}}function Iu(r){return Gr(r,"3.2.0")>=0}var ge=class extends Vt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new xu(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:qe},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await Fs(i.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",Mt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Wr,getChapter:Ft,getMedia:zr,getByBranches:this.getByBranches.bind(this),addErrorMessage:qe},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),i.result&&(this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph),this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let i=Ft(this.manifest.chapters,t);if(i){let n=zr(this.manifest.media,i.videoId),o=Wr(this.manifest.graph,i.id);if(n)return{chapter:i,media:n,graph:o}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let i=Ft(this.manifest?.chapters||[],t);return this.getByBranches(i?.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{let o=this.getByChapterId(n.chapterId);return o&&i.push(o),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?Q(this.chapter):!1}};var Gs=W(Nt(),1);import{Player as ku}from"@vkontakte/videoplayer-core";import{Subscription as Xr,TracerFactory as Pu,ValueSubject as Vu}from"@vkontakte/videoplayer-shared";var Hs=r=>{let e=r.variants.find(t=>t.payload?.type==="vk");if(e&&e.payload){let[t,i]=e.payload.id.split("_");return[t,i]}return[]};var Us=W(Nt(),1);function Kr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:a=Math.random().toString(),...s}){let l=r.get(o),c={...s};return l?l[a]=c:r.set(o,{[a]:c}),{listId:o,itemId:a,...s}}function t(o){o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),o.statistics?.oneStat.destroy(),o.statistics?.statSubscription.unsubscribe()}function i(o,a){let s=r.get(o);if(!s)throw Error("Can't remove. Not find.");if(a){let l=s[a];l&&t(l),delete s[a],Object.keys(s).length||r.delete(o)}else{for(let l of(0,Us.default)(s))t(l);r.delete(o)}}function n(){for(let o of r)i(o[0])}return{createPlayer:e,removePlayer:i,map:r,removeAll:n}}var Ce=W(mt(),1);function Qr(r,e=[]){let t={},i,n=!e.length;for(let o of r.variants)if(!i&&"cover"in o&&(i=o.cover),"url"in o)switch(o.type.toLowerCase()){case"mp4":(n||(0,Ce.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"mpeg":(n||(0,Ce.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"hls":(n||(0,Ce.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:o.url}});break;case"dash":(n||(0,Ce.default)(e,"dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:o.url}});break;default:break}return{sources:t,thumbUrl:i,title:r.title??""}}var He=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&(0,Ce.default)(i,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Mu=2;function Yr(r){let e=Kr(),t=new Xr,i={},n=null,o=!1,a,s=new Vu(null);r&&l(r);function l(y){n=y}function c(y,u,h){if(!n)throw Error("need to set interactive controller");if(!n.options)return;let g=(e.map.get(y)??{})[u];if(g){i={chapterId:h,listId:y,itemId:u,...g};let C=i.player;i.subscription.add(C.info.currentQuality$.subscribe(T=>{let S=C.info.position$.getValue(),$=C.info.isAutoQualityEnabled$.getValue();if(!(!T||!S||$))for(let I of e.map)(0,Gs.default)(I[1]).forEach(({player:P})=>{He(P,T)})})).add(C.events.started$.subscribe(()=>{d(u)})),g.container.remove(),n.setPlayer(g.player),o||(n.init(),o=!0),s.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}async function d(y){if(!n)throw Error("need to set interactive controller");if(te(i)||y!==i.itemId)return;let u=n.getChapterBranches(),h=new Set;for(let v of u)h.has(v.media.id)||(await f({media:v.media,chapterId:v.chapter.id,setAsActive:!1,title:v.chapter.label}),h.add(v.media.id))}async function m({chapter:{id:y},manifestVideo:u}){if(te(i)||!n)return;let h=i.player.info.muted$.getValue(),v=i.player.info.currentQuality$.getValue(),g=i.player.info.isAutoQualityEnabled$.getValue(),C=i.player.info.volume$.getValue(),T=i.player.info.currentPlaybackRate$.getValue(),S=!g,$=!1;for(let I of e.map)if(I[0]===u.id&&!n.state.isReplay$.getValue()){let P=Object.keys(I[1]);for(let V of P)V===i.itemId?(P.length<Mu||($=!0),e.removePlayer(I[0],V)):($=!0,c(I[0],V,y),S?He(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(C),i.player.setMuted(h),i.player.setPlaybackRate(T))}else e.removePlayer(I[0]);$||(await f({media:u,chapterId:y,setAsActive:!0,playbackRate:T}),S?He(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(C),i.player.setMuted(h))}async function f({media:y,chapterId:u,prefetch:h=!0,setAsActive:v=!0,autoplay:g=!1,preferredExt:C,title:T,playbackRate:S}){let $=Math.random().toString(),I=document.createElement("div");a.append(I);let P;if(n?.options?.vkVideoLoader){let Xe=Hs(y);Xe.length&&(P=await n.options.vkVideoLoader(...Xe))}let V=n?.options?.coreConfig||void 0,G={...V,configName:[...V?.configName??[],"interactive"]},ee={container:I,...P?.videos?.[0]||{sources:Qr(y,C).sources},title:T,failoverHosts:P?.failoverHosts||[]},j=new ku(G,Pu.createRootTracer());j.initVideo(ee);let se=null;if(P?.videos&&n?.options.createOneStat){let Xe=P.videos[0],Ut=n.options.createOneStat(Xe),ci=new Xr;Ut&&(ci.add(Ut.attachTo(j)),se={oneStat:Ut,statSubscription:ci})}let li=new Xr,Ya=i?.player?.info.isAutoQualityEnabled$.getValue();li.add(j.events.canplay$.subscribe(function(){Ya||He(j,i.player.info.currentQuality$.getValue()),S&&j.setPlaybackRate(S)}));let ae=e.createPlayer({listId:y.id,itemId:$,player:j,container:I,sources:Qr(y,C).sources,config:ee,subscription:li,statistics:se});return v&&c(y.id,ae.itemId,u),g&&ae.player.play(),h&&!g&&ae.player.prepare(),{player:ae.player,config:ae.config,statistics:ae.statistics}}function b(){R(),n=null,a.remove()}function R(){t.unsubscribe(),e.removeAll(),i={},o=!1}async function E(){if(!n)throw Error("need to set interactive controller");R(),a=document.createElement("div");let{media:y,chapter:u}=n.getCurrentChapter();y&&u?(t.add(n.events.chapterChanged$.subscribe(m)),await f({media:y,chapterId:u.id,title:u.label})):console.error("not found")}return{...e,init:E,setInteractiveController:l,createPlayer:f,removeAll:b,getActivePlayer:function(){return i},activePlayerChanged:s}}var x={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Ue={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},k={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as _u}from"@vkontakte/videoplayer-shared";function Zr(r){return function(...t){return r(...t.reverse())}}function Ge(r,...e){return(...t)=>Z(e[0])&&Z(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var $t=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:o,globalEvents:a,globalEventEmitter:s,getContainerEventState:l,permanentTextControls:c,interactiveTimeOpenUri:d,disabledControls$:m,onRemove:f,onError:b,disableTextControlContainerVisibilityEvents:R=!1,features:E}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(ne(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState!==2||this.isSelectedControlEvent)return;if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&t||this.disableTextControlContainerVisibilityEvents)return;this.emitContainerVisibilityEvent(!0,!1)}else{let t={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(o,a)=>{let{isExpectTime:s,hasOtherExpect:l,hasOpenURIEvent:c,hasOpenURIEventInCurrentContainer:d,isAllOpenURIEventsValid:m,hasShouldOpenNowEvent:f}=this.getContainerEventState(),b=this.interactiveTimeOpenUri&&!d,R=this.interactiveTimeOpenUri&&d;if((!this.interactiveTimeOpenUri||b)&&(this.isSelectedControlEvent=!0),o!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||b)){if(this.interactiveTimeOpenUri){let E=!l&&!m&&d;E&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:E})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&c&&this.gameState!==5){if(R){let y=((u,h,v,g)=>!u&&!h&&v||u&&!h&&v&&!g||u&&!h&&v&&g)(s,l,m,this.isSelectedContainerEvent);this.fakeRemoveView(y)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!s||!l||!f)&&(this.selectBranches.stopExpect(),a())}},isEOV:()=>this.gameState===4},i=Ge(this.selectBranches.onControlEvent,t),n=(this.player?.info.duration$.getValue()??1/0)*1e3;this.container.createView({eventCallback:i,videoDurationMs:n}),this.disableTextControlContainerVisibilityEvents||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(),t=e instanceof HTMLVideoElement;if(this.features.enableAvPlayerSupport&&(t||=e instanceof HTMLObjectElement&&e?.getAttribute("type")==="application/avplayer"),!(t?e?.readyState:void 0)||this.isRemovedOrDestroyed()&&!this.isPermanentText)return;let n=this.player.getExactTime();if(Mo(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(kr(n,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let l=this.gameState;this.gameState=3,l===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:l}=this.getContainerEventState(),c=this.selectBranches.state.isExpect,d=this.interactiveTimeOpenUri&&l;if(d&&!c){let m=this.container.getElement();m&&(m.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!d&&this.removeView()}let o=kr(n,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],s={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:n,isInteractiveTime:o};this.container.onProgress(n*1e3,o),this.globalEventEmitter.emit(x.eachTick,s),this.globalEvents.eachTick$.next(s)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new _u,this.player=e,this.interactiveEvents=o,this.getContainerEventState=l;let y=be(t.container.controls);this.isPermanentText=c&&y,this.disableTextControlContainerVisibilityEvents=R&&y,this.interactiveTimeOpenUri=d,this.disabledControls$=m,this.onRemove=f,this.globalEventEmitter=s,this.gameState=0,this.globalEvents=a,this.onError=b,this.features=E,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.visibility,visibility:e,isFirst:t}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e,isFirst:t})):(this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.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?.()})),this.subscription.add(this.container.error$.subscribe(this.onError))}selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),i=this.interactiveTimeOpenUri?e||t:ne(this.container.container.events)||e;(this.isSelectedControlEvent||!i)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(e=this.features.controlsHideAnimation){if(e){if(this.isRemovedOrDestroyed())return;this.container.removeNonInteractedControls(!0),this.container.removeView(!0,!0)}else this.container.removeView();this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:k.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}isInteracted(){return this.container.isInteracted()}isRemovedOrDestroyed(e=!0){let t=e?this.container.willRemoved:!1;return this.gameState===5||t||this.gameState===6}destroy(e=!1){this.reset(),this.removeView(e),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 zs=(r=[])=>r.reduce((e,t,i)=>{let n=(t?.controls??[]).filter(o=>!ft(o));if(yt(n)){let o=[t.startTime??0,t.endTime??1/0],a={id:t.id,isRemoved:!1};if(!i)e.push({subjects:[a],range:o});else{let s=[],l=-1/0,c=1/0,d=[],m=[];for(let f=0;f<e.length;f++){let b=e[f];if(m.push(...b.subjects),b.range[0]<c&&(c=b.range[0]),b.range[1]>l&&(l=b.range[1]),o[0]>=b.range[0]&&o[1]<=b.range[1])return e[f].subjects.push(a),e;o[0]<b.range[0]&&o[1]>b.range[0]&&(s.push(f),d=d.concat(b.subjects)),o[0]>=b.range[0]&&o[0]<=b.range[1]&&(s.push(f),d=d.concat(b.subjects),o[0]=b.range[0]),o[1]>=b.range[0]&&o[1]<=b.range[1]&&(s.push(f),d=d.concat(b.subjects),o[1]=b.range[1])}if(m.push(a),o[0]<=c&&o[1]>=l)return[{subjects:m,range:o}];s.length&&s.reverse().forEach(f=>{e.splice(f,1)}),e.push({subjects:d.concat([a]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var Ra=W(mt(),1),ri=W(Nt(),1),Oa=W(Sa(),1);function wa(){let r={};function e(){for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&delete r[s]}function t(s){let l={};for(let c in r)+c<=s&&(l[c]=r[c]);return l}function i(s){let l={};for(let c in r)+c>=s&&(l[c]=r[c]);return l}function n({timestamp:s,priority:l,initiator:c}){if(Kt(s)){let d=r[s]??null;if(d&&l&&Ee(l,!0)){let m={},f=d[l];return f&&(m={...m,...f}),m=te(m)?null:m,m&&Ee(c,!0)?m[c]??null:m}return d}return null}function o({timestamp:s,priority:l,initiator:c}){if(Kt(s))if(r[s]){if(l&&Ee(l,!0))if(r[s][l]){if(c&&Ee(c,!0))if(r[s][l][c]){if(delete r[s][l][c],!te(r[s][l]))return!0}else return!1;if(delete r[s][l],!te(r[s]))return!0}else return!1;return delete r[s]}else return!1;return!1}function a({timestamp:s,priority:l,initiator:c,...d}){r[s]?.[l]?.[c]?r[s][l][c].push({...d}):r[s]?.[l]?r[s][l]={...r[s][l],[c]:[{...d}]}:r[s]?r[s]={...r[s],[l]:{[c]:[{...d}]}}:r[s]={[l]:{[c]:[{...d}]}}}return{map:r,remove:o,add:a,removeAll:e,get:n,getLte:t,getGte:i}}var Th=[A.expect,A.setNextBranch],Ih=1/0;function ka(r,e){let t=r,i,n=xh(e),o=wa(),a,s=()=>{b(),u()},l=h=>{o.add.call(void 0,h),R()},c=(h=[])=>{for(let v of h)if(v.action(),(0,Ra.default)(Th,v.actionType))break},d=(h=1/0)=>{let v=Bt(o.get({timestamp:h,priority:"control"})??{}),g=Bt(o.get({timestamp:h,priority:"container"})??{}),C=Bt(o.get({timestamp:h,priority:"chapter"})??{});return[...v,...g,...C]},m=h=>{n.isReady(h)&&c(d(h))},f=()=>{c([...Bt(o.get({timestamp:1/0,priority:"chapter"})??{})])},b=()=>{i&&(a?.unsubscribe(),i=void 0)},R=()=>{i||(i=()=>setTimeout(()=>{m(1/0)}),a=t.events.ended$.subscribe(i))},E=h=>{b(),t=h},y=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),o.remove(h)},u=()=>{n.release(),o.removeAll()};return{setPlayer:E,add:l,remove:y,exec:m,execEndOfVideo:f,listen:R,unlisten:b,release:s,containersEventsCallState:n,getPreparedToExecActions:d}}function xh(r){let e=new Map;return{setCalled:({timestamp:s,id:l})=>{let c=e.get(s);c&&c[l]!==void 0&&(c[l]=!0)},setData:(s=[])=>{for(let l of s){let c=l.endTime??Ih,d=e.get(c);e.set(c,{...d,[l.id]:!1})}},resetCalled:s=>{let l=e.get(s);if(l)for(let c in l)l[c]=!1},isReady:s=>{let l=e.get(s);if(!l)return!0;let c=(0,ri.default)(l);return r?c.some(m=>m):!c.some(m=>!m)},release:()=>e.clear()}}function Bt(r){return(0,Oa.default)((0,ri.default)(r)).sort(e=>e.actionType===A.expect?-1:1)}var Pa={videoContentHeight:0,videoContentWidth:0},Va=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return Pa;let{clientHeight:i,clientWidth:n}=r.experimental.element$.getValue()||{};if(!(i&&n))return Pa;let o=e/t,a=i/n,s,l;return a>o?(l=n,s=n*o):a<o?(l=i/o,s=i):(l=n,s=i),{videoContentWidth:l,videoContentHeight:s}};var Ah=250;function Ma(r){let e,t=new ResizeObserver(s=>{o(s),e=o.bind(null,s)});function i(s){let{parentElement:l,player:c,cssVarsManager:d}=r();if(!l||!c)return;let{videoContentWidth:m,videoContentHeight:f}=Va(c);d.setup({"--interactive-content-width":`${m}px`,"--interactive-content-height":`${f}px`,"--interactive-width":`${s[0].contentRect.width}px`,"--interactive-height":`${s[0].contentRect.height}px`})}function n(){let{parentElement:s}=r();s.removeAttribute("style")}let o=$e(s=>{let{fns:l=[]}=r();i(s);for(let c of l)c()},Ah);function a(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e?.()},release:a}}var Sh=r=>Math.floor(Math.random()*r),La=r=>{let e=r.length,t=1/0,i=null;for(;e--;){let n=r[e],o=n.weight??1;o<t&&(t=o,i=n)}return i},Fa=r=>{let e=r.length,t=-1/0,i=null;for(;e--;){let n=r[e],o=n.weight??0;o>t&&(t=o,i=n)}return i};var Na=r=>{let e=r.length,t=Sh(e);return r[t]},_a=1,$a=r=>{let e=0;for(let i=0;i<r.length;++i)e+=r[i].weight??_a;let t=Math.random()*e;e=0;for(let i=0;i<r.length-1;++i)if(e+=r[i].weight??_a,e>=t)return r[i];return r[r.length-1]};var ja={shouldOpenNow:!0,isDetachContainer:!0},Ba="after-expect",ii=(r,e=!1)=>({...r,args:e?{...r.args,...ja}:{...ja,...r.args}}),qa=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:i})=>{let n={isExpect:!1},o=()=>{n.isExpect&&(n.isExpect=!1)},a=({action:u,controlType:h,controlId:v,containerId:g,branches:C=[],onEvent:T,isEOV:S=()=>!1,isDisabled:$=()=>!1})=>{let I=ii(u,S()),P={timestamp:1/0,priority:"control",initiator:v,actionType:I.type},V=$(),G=r.emit.bind(r,x.interactives,{subjectId:v,subjectType:h,subjectName:"control",type:V?k.actionChoiceCanceled:k.actionChoice,actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:g,...I.args}}),ee=()=>{e.interactiveActionChoice$.next({subjectId:v,subjectType:h,subjectName:"control",type:V?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:g,...I.args}})};if(V){G(),ee();return}switch(I.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let j=C.find(se=>se.id===I.args.branchId);if(!j)return;T(I.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),I.args.shouldOpenNow?E({subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{chapterId:j.chapterId,autoSelect:!1}}):i.add({...P,action:E.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{chapterId:j.chapterId,autoSelect:!1}})});return}case A.continuePlayback.trim().toLowerCase():{T(I.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),I.args.shouldOpenNow?R({subjectId:v,subjectName:"control",subjectType:h,action:u}):i.add({...P,action:R.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:u})});return}case A.openURI.trim().toLowerCase():{T(I.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),I.args.shouldOpenNow?y({subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}}):i.add({...P,action:y.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:I,payload:{URI:u.args.uri}})});return}default:{let j="Unexpected control event",se=new M(1,1,{message:j});d(se,j);return}}},s=({action:u,container:{id:h,endTime:v},branches:g=[],isEOV:C=!1,autoSelected:T=!1})=>{let S=ii(u,C),$={timestamp:!S.args.shouldOpenNow||C?1/0:v??1/0,priority:"container",initiator:h,actionType:S.type},I=r.emit.bind(r,x.interactives,{subjectId:h,subjectName:"container",type:k.actionChoice,actionType:S.type,payload:{invokeImmediately:S.args.shouldOpenNow,...S.args}}),P=()=>{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 A.setNextBranch.trim().toLowerCase():{let V=g.find(G=>G.id===S.args.branchId);if(!V)return;I(),P(),i.add({...$,action:E.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{chapterId:V.chapterId,autoSelect:T}})});return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{I(),P(),i.add({...$,action:R.bind(null,{subjectId:h,subjectName:"container",action:S})});return}case A.openURI.trim().toLowerCase():{I(),P(),i.add({...$,action:y.bind(null,{subjectId:h,subjectName:"container",action:S,payload:{URI:u.args.uri}})});return}default:{let V="Unexpected container event",G=new M(1,1,{message:V});d(G,V);return}}};function l({container:u,branches:h,isEOV:v=!1}){let g=Pr(u.events);if(g){let C=ii(g.action,v);r.emit(x.interactives,{subjectId:u.id,subjectName:"container",type:k.actionChoice,actionType:C.type,payload:{invokeImmediately:C.args.shouldOpenNow,...C.args}}),e.interactiveActionChoice$.next({subjectId:u.id,subjectName:"container",type:"action-choice",actionType:C.type,payload:{invokeImmediately:C.args.shouldOpenNow,...C.args}}),i.add({timestamp:v?1/0:u.endTime??1/0,priority:"container",initiator:u.id,actionType:A.expect,action:f.bind(null,{subjectId:u.id,subjectName:"container"})}),n.isExpect=!0}else for(let C of u.events??[])s({action:C.action,container:u,branches:h,isEOV:v})}let c=({chapterId:u,action:h,branches:v=[]})=>{let g=r.emit.bind(r,x.interactives,{subjectId:u,subjectName:"chapter",type:k.actionChoice,actionType:h.type,payload:h.args}),C=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectName:"chapter",type:"action-choice",actionType:h.type,payload:h.args})};switch(h.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let T=v.find(S=>S.id===h.args.branchId);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{let T=Na(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{let T=$a(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{let T=Fa(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{let T=La(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return g(),C(),R.bind(null,{subjectId:u,subjectName:"chapter",action:h});case A.openURI.trim().toLowerCase():return g(),C(),y.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:{let T="Unexpected chapter event",S=new M(1,1,{message:T});d(S,T);return}}};function d(u,h){console.error(h),e.error$.next(u),r.emit(x.errors,u)}function m(u){let h=Pr(u.events);if(h){if(Q(u))return;r.emit(x.interactives,{subjectId:u.id,subjectName:"chapter",type:k.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}),i.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:A.expect,action:f.bind(null,{subjectId:u.id,subjectName:"chapter"})})}else u.events?.forEach(v=>{let g=c({chapterId:u.id,action:v.action,branches:u.branches});g&&i.add({timestamp:1/0,priority:"chapter",initiator:u.id,actionType:v.action.type,action:g})})}let f=({subjectId:u,subjectName:h})=>{t.pause(),r.emit(x.interactives,{subjectId:u,subjectName:h,type:k.actionExecution,actionType:A.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:A.expect})},b=({subjectId:u,subjectName:h})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),r.emit(x.interactives,{subjectId:u,subjectName:h,type:k.actionExecution,actionType:Ba}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:Ba})},R=({subjectId:u,subjectName:h,subjectType:v,action:g})=>{r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:k.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type})},E=({subjectId:u,subjectName:h,subjectType:v,action:g,payload:C})=>{C.behaviour="change-chapter",r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:k.actionExecution,actionType:g.type,payload:C}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type,payload:C})},y=({subjectId:u,subjectName:h,subjectType:v,action:g,payload:C})=>{if(!C.URI)return;let T=window.open(C.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:k.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type})};return{onControlEvent:a,onContainerEvent:s,onChapterEvent:c,onExpectEvent:f,expectEventHandler:b,setManifestChapterEvents:m,setManifestContainerEvents:l,stopExpect:o,state:n}};var si=W(jr(),1);import{Subscription as Ph,Subject as oi,ValueSubject as ze}from"@vkontakte/videoplayer-shared";var ni=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(a=>a.id===i);if(!n)return null;let o=e.media.videos.find(a=>n.videoId===a.id);if(!o)return null;t[i]=Da(o)}return t[i]}).filter(Boolean)},Rh=r=>{for(let e of r.variants)if(Oh(e)&&e.payload)return e.payload.id},Oh=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Da=r=>{let e=Rh(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},kh=(r,e)=>{for(let t of r.media.videos)if(e===Da(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},Ha=(r,e)=>r.reduce((t,i)=>{let n=kh(e,i);return n?[...t,n]:t},[]);var Ke=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:o}){this.state={history$:new ze([]),hasPrevChapter$:new ze(!1),prevChapter$:new ze(null),isInitialChapter$:new ze(!1),isGoBackLimited$:new ze(!1)};this.#r=null;this.#s=!1;this.#e=null;this.#p=null;this.events={inited$:new oi,destroyed$:new oi,error$:new oi};this.#i=null;this.#n=null;this.#t=null;this.#a=new Ph;this.#l=!1;this.#c=0;this.#i=t,this.#t=e,this.#n=i,this.#r=n,this.#o=o,this.state.history$&&this.#a&&this.#a?.add(this.state.history$.subscribe(a=>{this.state.prevChapter$.next((0,si.default)(a,-2)||null),this.state.hasPrevChapter$.next(a.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#o.maxLength-1)}))}#r;#o;#s;#e;#p;#i;#n;#t;#a;#l;#c;async setManifest(e){if(!this.#n||!this.#t)return;this.#e=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#n.setChapter({chapterId:t,pushToHistory:!1}),this.#s||(this.#s=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#s}async updateHistory(e,t=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let i=this.#e,n=e.length-this.#o.maxLength,o=n>0?e.slice(n):e,a=ni(o,i);if(this.#p=a,this.state.history$.next(o),!(!t||!this.#r||!this.#i))try{await this.#r.save(this.#i,a)}catch{let l=new M(1,5,"Unable to save interactive history");this.events.error$.next(l),this.#t?.emit(x.errors,l)}}async goBack(){if(!this.state||!this.#n){let i=new M(1,5,"Unable to save interactive history");return this.events.error$.next(i),this.#t?.emit(x.errors,i)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#n.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#i)return;let e=this.#e,t=[this.getInitialVideoId()];if(this.#r)try{let n=await this.#r.get(this.#i);n.length&&(t=n)}catch{let o=new M(1,5,"Error while trying to fetch data");this.events.error$.next(o),this.#t?.emit(x.errors,o)}let i=Ha(t,e);this.state.history$.next(i)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,si.default)(e,-1)||this.#o.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return ni([e],this.#e).pop()}return null}destroy(){this.#i=null,this.#r=null,this.#n=null,this.#a?.unsubscribe(),this.#a=null,this.#s=!1,this.#t?.emit(x.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var qt=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 t=e.data,i=t.length;for(let n=3;n<i;n+=40)if(t[n]!==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,t=!1){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var Dt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
7
7
  position: absolute;
8
8
  top: 0;
9
9
  left: 0;