@vkontakte/videoplayer-interactive 1.0.39-dev.3ba6f931.0 → 1.0.39-dev.6edf3cda.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/es2015.cjs.js +4 -4
- package/es2015.esm.js +4 -4
- package/es2018.cjs.js +4 -4
- package/es2018.esm.js +4 -4
- package/es2024.cjs.js +5 -5
- package/es2024.esm.js +4 -4
- package/esnext.cjs.js +5 -5
- package/esnext.esm.js +4 -4
- package/evergreen.esm.js +6 -6
- package/package.json +4 -4
- package/types/modules/Interactives/types.d.ts +1 -0
- package/types/modules/Interactives/utils/GameController.d.ts +3 -1
package/esnext.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.39-dev.
|
|
3
|
-
* Mon, 09 Jun 2025
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.39-dev.6edf3cda.0
|
|
3
|
+
* Mon, 09 Jun 2025 10:20:24 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-39/doc/
|
|
5
5
|
*/
|
|
6
|
-
var $s=Object.create;var si=Object.defineProperty;var js=Object.getOwnPropertyDescriptor;var Bs=Object.getOwnPropertyNames;var qs=Object.getPrototypeOf,Ds=Object.prototype.hasOwnProperty;var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Hs=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Bs(e))!Ds.call(r,n)&&n!==t&&si(r,n,{get:()=>e[n],enumerable:!(i=js(e,n))||i.enumerable});return r};var z=(r,e,t)=>(t=r!=null?$s(qs(r)):{},Hs(e||!r||!r.__esModule?si(t,"default",{value:r,enumerable:!0}):t,r));var K=p((nr,Ai)=>{"use strict";var Te=function(r){return r&&r.Math===Math&&r};Ai.exports=Te(typeof globalThis=="object"&&globalThis)||Te(typeof window=="object"&&window)||Te(typeof self=="object"&&self)||Te(typeof global=="object"&&global)||Te(typeof nr=="object"&&nr)||function(){return this}()||Function("return this")()});var q=p((Zd,wi)=>{"use strict";wi.exports=function(r){try{return!!r()}catch{return!0}}});var Ie=p((Jd,Ri)=>{"use strict";var rl=q();Ri.exports=!rl(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Li=p((em,Mi)=>{"use strict";var il=Ie(),Pi=Function.prototype,ki=Pi.apply,Oi=Pi.call;Mi.exports=typeof Reflect=="object"&&Reflect.apply||(il?Oi.bind(ki):function(){return Oi.apply(ki,arguments)})});var H=p((tm,Ni)=>{"use strict";var Fi=Ie(),Vi=Function.prototype,or=Vi.call,nl=Fi&&Vi.bind.bind(or,or);Ni.exports=Fi?nl:function(r){return function(){return or.apply(r,arguments)}}});var xe=p((rm,$i)=>{"use strict";var _i=H(),ol=_i({}.toString),al=_i("".slice);$i.exports=function(r){return al(ol(r),8,-1)}});var ar=p((im,ji)=>{"use strict";var sl=xe(),ll=H();ji.exports=function(r){if(sl(r)==="Function")return ll(r)}});var D=p((nm,Bi)=>{"use strict";var sr=typeof document=="object"&&document.all;Bi.exports=typeof sr>"u"&&sr!==void 0?function(r){return typeof r=="function"||r===sr}:function(r){return typeof r=="function"}});var ie=p((om,qi)=>{"use strict";var cl=q();qi.exports=!cl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var dt=p((am,Di)=>{"use strict";var pl=Ie(),ht=Function.prototype.call;Di.exports=pl?ht.bind(ht):function(){return ht.apply(ht,arguments)}});var lr=p(Gi=>{"use strict";var Hi={}.propertyIsEnumerable,Ui=Object.getOwnPropertyDescriptor,ul=Ui&&!Hi.call({1:2},1);Gi.f=ul?function(e){var t=Ui(this,e);return!!t&&t.enumerable}:Hi});var cr=p((lm,zi)=>{"use strict";zi.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Ki=p((cm,Wi)=>{"use strict";var hl=H(),dl=q(),ml=xe(),pr=Object,fl=hl("".split);Wi.exports=dl(function(){return!pr("z").propertyIsEnumerable(0)})?function(r){return ml(r)==="String"?fl(r,""):pr(r)}:pr});var ur=p((pm,Qi)=>{"use strict";Qi.exports=function(r){return r==null}});var hr=p((um,Xi)=>{"use strict";var vl=ur(),bl=TypeError;Xi.exports=function(r){if(vl(r))throw new bl("Can't call method on "+r);return r}});var Se=p((hm,Yi)=>{"use strict";var yl=Ki(),gl=hr();Yi.exports=function(r){return yl(gl(r))}});var pe=p((dm,Zi)=>{"use strict";var Cl=D();Zi.exports=function(r){return typeof r=="object"?r!==null:Cl(r)}});var mt=p((mm,Ji)=>{"use strict";Ji.exports={}});var ft=p((fm,tn)=>{"use strict";var dr=mt(),mr=K(),El=D(),en=function(r){return El(r)?r:void 0};tn.exports=function(r,e){return arguments.length<2?en(dr[r])||en(mr[r]):dr[r]&&dr[r][e]||mr[r]&&mr[r][e]}});var nn=p((vm,rn)=>{"use strict";var Tl=H();rn.exports=Tl({}.isPrototypeOf)});var ln=p((bm,sn)=>{"use strict";var Il=K(),on=Il.navigator,an=on&&on.userAgent;sn.exports=an?String(an):""});var fn=p((ym,mn)=>{"use strict";var dn=K(),fr=ln(),cn=dn.process,pn=dn.Deno,un=cn&&cn.versions||pn&&pn.version,hn=un&&un.v8,U,vt;hn&&(U=hn.split("."),vt=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!vt&&fr&&(U=fr.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=fr.match(/Chrome\/(\d+)/),U&&(vt=+U[1])));mn.exports=vt});var vr=p((gm,bn)=>{"use strict";var vn=fn(),xl=q(),Sl=K(),Al=Sl.String;bn.exports=!!Object.getOwnPropertySymbols&&!xl(function(){var r=Symbol("symbol detection");return!Al(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&vn&&vn<41})});var br=p((Cm,yn)=>{"use strict";var wl=vr();yn.exports=wl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var yr=p((Em,gn)=>{"use strict";var Rl=ft(),kl=D(),Ol=nn(),Pl=br(),Ml=Object;gn.exports=Pl?function(r){return typeof r=="symbol"}:function(r){var e=Rl("Symbol");return kl(e)&&Ol(e.prototype,Ml(r))}});var En=p((Tm,Cn)=>{"use strict";var Ll=String;Cn.exports=function(r){try{return Ll(r)}catch{return"Object"}}});var gr=p((Im,Tn)=>{"use strict";var Fl=D(),Vl=En(),Nl=TypeError;Tn.exports=function(r){if(Fl(r))return r;throw new Nl(Vl(r)+" is not a function")}});var xn=p((xm,In)=>{"use strict";var _l=gr(),$l=ur();In.exports=function(r,e){var t=r[e];return $l(t)?void 0:_l(t)}});var An=p((Sm,Sn)=>{"use strict";var Cr=dt(),Er=D(),Tr=pe(),jl=TypeError;Sn.exports=function(r,e){var t,i;if(e==="string"&&Er(t=r.toString)&&!Tr(i=Cr(t,r))||Er(t=r.valueOf)&&!Tr(i=Cr(t,r))||e!=="string"&&Er(t=r.toString)&&!Tr(i=Cr(t,r)))return i;throw new jl("Can't convert object to primitive value")}});var Rn=p((Am,wn)=>{"use strict";wn.exports=!0});var Pn=p((wm,On)=>{"use strict";var kn=K(),Bl=Object.defineProperty;On.exports=function(r,e){try{Bl(kn,r,{value:e,configurable:!0,writable:!0})}catch{kn[r]=e}return e}});var bt=p((Rm,Fn)=>{"use strict";var ql=Rn(),Dl=K(),Hl=Pn(),Mn="__core-js_shared__",Ln=Fn.exports=Dl[Mn]||Hl(Mn,{});(Ln.versions||(Ln.versions=[])).push({version:"3.38.0",mode:ql?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var Ir=p((km,Nn)=>{"use strict";var Vn=bt();Nn.exports=function(r,e){return Vn[r]||(Vn[r]=e||{})}});var Ae=p((Om,_n)=>{"use strict";var Ul=hr(),Gl=Object;_n.exports=function(r){return Gl(Ul(r))}});var ue=p((Pm,$n)=>{"use strict";var zl=H(),Wl=Ae(),Kl=zl({}.hasOwnProperty);$n.exports=Object.hasOwn||function(e,t){return Kl(Wl(e),t)}});var xr=p((Mm,jn)=>{"use strict";var Ql=H(),Xl=0,Yl=Math.random(),Zl=Ql(1 .toString);jn.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Zl(++Xl+Yl,36)}});var we=p((Lm,qn)=>{"use strict";var Jl=K(),ec=Ir(),Bn=ue(),tc=xr(),rc=vr(),ic=br(),he=Jl.Symbol,Sr=ec("wks"),nc=ic?he.for||he:he&&he.withoutSetter||tc;qn.exports=function(r){return Bn(Sr,r)||(Sr[r]=rc&&Bn(he,r)?he[r]:nc("Symbol."+r)),Sr[r]}});var Gn=p((Fm,Un)=>{"use strict";var oc=dt(),Dn=pe(),Hn=yr(),ac=xn(),sc=An(),lc=we(),cc=TypeError,pc=lc("toPrimitive");Un.exports=function(r,e){if(!Dn(r)||Hn(r))return r;var t=ac(r,pc),i;if(t){if(e===void 0&&(e="default"),i=oc(t,r,e),!Dn(i)||Hn(i))return i;throw new cc("Can't convert object to primitive value")}return e===void 0&&(e="number"),sc(r,e)}});var Ar=p((Vm,zn)=>{"use strict";var uc=Gn(),hc=yr();zn.exports=function(r){var e=uc(r,"string");return hc(e)?e:e+""}});var Qn=p((Nm,Kn)=>{"use strict";var dc=K(),Wn=pe(),wr=dc.document,mc=Wn(wr)&&Wn(wr.createElement);Kn.exports=function(r){return mc?wr.createElement(r):{}}});var Rr=p((_m,Xn)=>{"use strict";var fc=ie(),vc=q(),bc=Qn();Xn.exports=!fc&&!vc(function(){return Object.defineProperty(bc("div"),"a",{get:function(){return 7}}).a!==7})});var Jn=p(Zn=>{"use strict";var yc=ie(),gc=dt(),Cc=lr(),Ec=cr(),Tc=Se(),Ic=Ar(),xc=ue(),Sc=Rr(),Yn=Object.getOwnPropertyDescriptor;Zn.f=yc?Yn:function(e,t){if(e=Tc(e),t=Ic(t),Sc)try{return Yn(e,t)}catch{}if(xc(e,t))return Ec(!gc(Cc.f,e,t),e[t])}});var to=p((jm,eo)=>{"use strict";var Ac=q(),wc=D(),Rc=/#|\.prototype\./,Re=function(r,e){var t=Oc[kc(r)];return t===Mc?!0:t===Pc?!1:wc(e)?Ac(e):!!e},kc=Re.normalize=function(r){return String(r).replace(Rc,".").toLowerCase()},Oc=Re.data={},Pc=Re.NATIVE="N",Mc=Re.POLYFILL="P";eo.exports=Re});var kr=p((Bm,io)=>{"use strict";var ro=ar(),Lc=gr(),Fc=Ie(),Vc=ro(ro.bind);io.exports=function(r,e){return Lc(r),e===void 0?r:Fc?Vc(r,e):function(){return r.apply(e,arguments)}}});var oo=p((qm,no)=>{"use strict";var Nc=ie(),_c=q();no.exports=Nc&&_c(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var so=p((Dm,ao)=>{"use strict";var $c=pe(),jc=String,Bc=TypeError;ao.exports=function(r){if($c(r))return r;throw new Bc(jc(r)+" is not an object")}});var po=p(co=>{"use strict";var qc=ie(),Dc=Rr(),Hc=oo(),yt=so(),lo=Ar(),Uc=TypeError,Or=Object.defineProperty,Gc=Object.getOwnPropertyDescriptor,Pr="enumerable",Mr="configurable",Lr="writable";co.f=qc?Hc?function(e,t,i){if(yt(e),t=lo(t),yt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&Lr in i&&!i[Lr]){var n=Gc(e,t);n&&n[Lr]&&(e[t]=i.value,i={configurable:Mr in i?i[Mr]:n[Mr],enumerable:Pr in i?i[Pr]:n[Pr],writable:!1})}return Or(e,t,i)}:Or:function(e,t,i){if(yt(e),t=lo(t),yt(i),Dc)try{return Or(e,t,i)}catch{}if("get"in i||"set"in i)throw new Uc("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var ho=p((Um,uo)=>{"use strict";var zc=ie(),Wc=po(),Kc=cr();uo.exports=zc?function(r,e,t){return Wc.f(r,e,Kc(1,t))}:function(r,e,t){return r[e]=t,r}});var Oe=p((Gm,fo)=>{"use strict";var ke=K(),Qc=Li(),Xc=ar(),Yc=D(),Zc=Jn().f,Jc=to(),de=mt(),ep=kr(),me=ho(),mo=ue();bt();var tp=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 Qc(r,this,arguments)};return e.prototype=r.prototype,e};fo.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,o=r.proto,l=i?ke:n?ke[t]:ke[t]&&ke[t].prototype,a=i?de:de[t]||me(de,t,{})[t],s=a.prototype,c,d,m,f,b,R,E,y,u;for(f in e)c=Jc(i?f:t+(n?".":"#")+f,r.forced),d=!c&&l&&mo(l,f),R=a[f],d&&(r.dontCallGetSet?(u=Zc(l,f),E=u&&u.value):E=l[f]),b=d&&E?E:e[f],!(!c&&!o&&typeof R==typeof b)&&(r.bind&&d?y=ep(b,ke):r.wrap&&d?y=tp(b):o&&Yc(b)?y=Xc(b):y=b,(r.sham||b&&b.sham||R&&R.sham)&&me(y,"sham",!0),me(a,f,y),o&&(m=t+"Prototype",mo(de,m)||me(de,m,{}),me(de[m],f,b),r.real&&s&&(c||!s[f])&&me(s,f,b)))}});var bo=p((zm,vo)=>{"use strict";var rp=Math.ceil,ip=Math.floor;vo.exports=Math.trunc||function(e){var t=+e;return(t>0?ip:rp)(t)}});var Pe=p((Wm,yo)=>{"use strict";var np=bo();yo.exports=function(r){var e=+r;return e!==e||e===0?0:np(e)}});var Co=p((Km,go)=>{"use strict";var op=Pe(),ap=Math.min;go.exports=function(r){var e=op(r);return e>0?ap(e,9007199254740991):0}});var Me=p((Qm,Eo)=>{"use strict";var sp=Co();Eo.exports=function(r){return sp(r.length)}});var gt=p((Xm,To)=>{"use strict";To.exports=function(){}});var Io=p(()=>{"use strict";var lp=Oe(),cp=Ae(),pp=Me(),up=Pe(),hp=gt();lp({target:"Array",proto:!0},{at:function(e){var t=cp(this),i=pp(t),n=up(e),o=n>=0?n:i+n;return o<0||o>=i?void 0:t[o]}});hp("at")});var Ct=p((Jm,xo)=>{"use strict";var dp=ft();xo.exports=dp});var Ao=p((ef,So)=>{"use strict";Io();var mp=Ct();So.exports=mp("Array","at")});var Ro=p((tf,wo)=>{"use strict";var fp=Ao();wo.exports=fp});var Fr=p((rf,ko)=>{"use strict";var vp=Ro();ko.exports=vp});var Bo=p((Jf,jo)=>{"use strict";var Sp=Pe(),Ap=Math.max,wp=Math.min;jo.exports=function(r,e){var t=Sp(r);return t<0?Ap(t+e,0):wp(t,e)}});var Br=p((ev,Do)=>{"use strict";var Rp=Se(),kp=Bo(),Op=Me(),qo=function(r){return function(e,t,i){var n=Rp(e),o=Op(n);if(o===0)return!r&&-1;var l=kp(i,o),a;if(r&&t!==t){for(;o>l;)if(a=n[l++],a!==a)return!0}else for(;o>l;l++)if((r||l in n)&&n[l]===t)return r||l||0;return!r&&-1}};Do.exports={includes:qo(!0),indexOf:qo(!1)}});var Ho=p(()=>{"use strict";var Pp=Oe(),Mp=Br().includes,Lp=q(),Fp=gt(),Vp=Lp(function(){return!Array(1).includes()});Pp({target:"Array",proto:!0,forced:Vp},{includes:function(e){return Mp(this,e,arguments.length>1?arguments[1]:void 0)}});Fp("includes")});var Go=p((iv,Uo)=>{"use strict";Ho();var Np=Ct();Uo.exports=Np("Array","includes")});var Wo=p((nv,zo)=>{"use strict";var _p=Go();zo.exports=_p});var je=p((ov,Ko)=>{"use strict";var $p=Wo();Ko.exports=$p});var ta=p((vv,ea)=>{"use strict";var qp=Ir(),Dp=xr(),Jo=qp("keys");ea.exports=function(r){return Jo[r]||(Jo[r]=Dp(r))}});var ia=p((bv,ra)=>{"use strict";var Hp=q();ra.exports=!Hp(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var aa=p((yv,oa)=>{"use strict";var Up=ue(),Gp=D(),zp=Ae(),Wp=ta(),Kp=ia(),na=Wp("IE_PROTO"),Hr=Object,Qp=Hr.prototype;oa.exports=Kp?Hr.getPrototypeOf:function(r){var e=zp(r);if(Up(e,na))return e[na];var t=e.constructor;return Gp(t)&&e instanceof t?t.prototype:e instanceof Hr?Qp:null}});var la=p((gv,sa)=>{"use strict";sa.exports={}});var ua=p((Cv,pa)=>{"use strict";var Xp=H(),Ur=ue(),Yp=Se(),Zp=Br().indexOf,Jp=la(),ca=Xp([].push);pa.exports=function(r,e){var t=Yp(r),i=0,n=[],o;for(o in t)!Ur(Jp,o)&&Ur(t,o)&&ca(n,o);for(;e.length>i;)Ur(t,o=e[i++])&&(~Zp(n,o)||ca(n,o));return n}});var da=p((Ev,ha)=>{"use strict";ha.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var fa=p((Tv,ma)=>{"use strict";var eu=ua(),tu=da();ma.exports=Object.keys||function(e){return eu(e,tu)}});var Ea=p((Iv,Ca)=>{"use strict";var ba=ie(),ru=q(),ya=H(),iu=aa(),nu=fa(),ou=Se(),au=lr().f,ga=ya(au),su=ya([].push),lu=ba&&ru(function(){var r=Object.create(null);return r[2]=2,!ga(r,2)}),va=function(r){return function(e){for(var t=ou(e),i=nu(t),n=lu&&iu(t)===null,o=i.length,l=0,a=[],s;o>l;)s=i[l++],(!ba||(n?s in t:ga(t,s)))&&su(a,r?[s,t[s]]:t[s]);return a}};Ca.exports={entries:va(!0),values:va(!1)}});var Ta=p(()=>{"use strict";var cu=Oe(),pu=Ea().values;cu({target:"Object",stat:!0},{values:function(e){return pu(e)}})});var xa=p((Av,Ia)=>{"use strict";Ta();var uu=mt();Ia.exports=uu.Object.values});var Aa=p((wv,Sa)=>{"use strict";var hu=xa();Sa.exports=hu});var Ft=p((Rv,wa)=>{"use strict";var du=Aa();wa.exports=du});var Xr=p((Zv,Fa)=>{"use strict";var gu=xe();Fa.exports=Array.isArray||function(e){return gu(e)==="Array"}});var Na=p((Jv,Va)=>{"use strict";var Cu=TypeError,Eu=9007199254740991;Va.exports=function(r){if(r>Eu)throw Cu("Maximum allowed index exceeded");return r}});var ja=p((eb,$a)=>{"use strict";var Tu=Xr(),Iu=Me(),xu=Na(),Su=kr(),_a=function(r,e,t,i,n,o,l,a){for(var s=n,c=0,d=l?Su(l,a):!1,m,f;c<i;)c in t&&(m=d?d(t[c],c,e):t[c],o>0&&Tu(m)?(f=Iu(m),s=_a(r,e,m,f,s,o-1)-1):(xu(s+1),r[s]=m),s++),c++;return s};$a.exports=_a});var Da=p((tb,qa)=>{"use strict";var Au=we(),wu=Au("toStringTag"),Ba={};Ba[wu]="z";qa.exports=String(Ba)==="[object z]"});var Ua=p((rb,Ha)=>{"use strict";var Ru=Da(),ku=D(),Nt=xe(),Ou=we(),Pu=Ou("toStringTag"),Mu=Object,Lu=Nt(function(){return arguments}())==="Arguments",Fu=function(r,e){try{return r[e]}catch{}};Ha.exports=Ru?Nt:function(r){var e,t,i;return r===void 0?"Undefined":r===null?"Null":typeof(t=Fu(e=Mu(r),Pu))=="string"?t:Lu?Nt(e):(i=Nt(e))==="Object"&&ku(e.callee)?"Arguments":i}});var za=p((ib,Ga)=>{"use strict";var Vu=H(),Nu=D(),Yr=bt(),_u=Vu(Function.toString);Nu(Yr.inspectSource)||(Yr.inspectSource=function(r){return _u(r)});Ga.exports=Yr.inspectSource});var Za=p((nb,Ya)=>{"use strict";var $u=H(),ju=q(),Wa=D(),Bu=Ua(),qu=ft(),Du=za(),Ka=function(){},Qa=qu("Reflect","construct"),Zr=/^\s*(?:class|function)\b/,Hu=$u(Zr.exec),Uu=!Zr.test(Ka),He=function(e){if(!Wa(e))return!1;try{return Qa(Ka,[],e),!0}catch{return!1}},Xa=function(e){if(!Wa(e))return!1;switch(Bu(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Uu||!!Hu(Zr,Du(e))}catch{return!0}};Xa.sham=!0;Ya.exports=!Qa||ju(function(){var r;return He(He.call)||!He(Object)||!He(function(){r=!0})||r})?Xa:He});var rs=p((ob,ts)=>{"use strict";var Ja=Xr(),Gu=Za(),zu=pe(),Wu=we(),Ku=Wu("species"),es=Array;ts.exports=function(r){var e;return Ja(r)&&(e=r.constructor,Gu(e)&&(e===es||Ja(e.prototype))?e=void 0:zu(e)&&(e=e[Ku],e===null&&(e=void 0))),e===void 0?es:e}});var ns=p((ab,is)=>{"use strict";var Qu=rs();is.exports=function(r,e){return new(Qu(r))(e===0?0:e)}});var os=p(()=>{"use strict";var Xu=Oe(),Yu=ja(),Zu=Ae(),Ju=Me(),eh=Pe(),th=ns();Xu({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=Zu(this),i=Ju(t),n=th(t,0);return n.length=Yu(n,t,t,i,0,e===void 0?1:eh(e)),n}})});var as=p(()=>{"use strict";var rh=gt();rh("flat")});var ls=p((ub,ss)=>{"use strict";os();as();var ih=Ct();ss.exports=ih("Array","flat")});var ps=p((hb,cs)=>{"use strict";var nh=ls();cs.exports=nh});var hs=p((db,us)=>{"use strict";var oh=ps();us.exports=oh});var li="1.0.39-dev.3ba6f931.0";import{Subject as el,Subscription as tl}from"@vkontakte/videoplayer-shared";var Dt=class{constructor(e){this.layout=e}},Ke=class extends Dt{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * (${t.width} + ${2e-4}))`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};function ci(r){return"features"in r}var se=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&ci(this.options)&&this.options.features[e]}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 it,once as Qs}from"@vkontakte/videoplayer-shared";var Y=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Z=r=>Y(r,"Object"),Qe=r=>Y(r,"String"),Xe=r=>Y(r,"Array"),Ye=r=>Y(r,"Number"),pi=r=>Y(r,"Function"),ui=r=>Y(r,"Boolean"),Ht=r=>Ye(r)&&!isNaN(r);var te=r=>Z(r)&&Object.keys(r).length===0,Ut=r=>Xe(r)&&!r.length;var ge=(r,e)=>Qe(r)&&(e?r.trim():r).length;function Ce(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 hi="interactive",k={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},di=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(di||{}),mi=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(mi||{}),fi=(i=>(i.start="left",i.end="right",i.center="center",i))(fi||{}),Ze=({target:r,props:e})=>{r.style.alignItems=(e?.gravityVertical&&di[e.gravityVertical])??"center",r.style.justifyContent=(e?.gravityHorizontal&&mi[e.gravityHorizontal])??"center",r.style.textAlign=(e?.alignment&&fi[e.alignment])??"center"},Je=({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},et=({target:r,props:e,fallback:t})=>{r.style.backgroundColor=Ce(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},Ee=({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})`,l=n?t.roundCornersRawValue:`calc(${i.height} * ${e?.shape?.roundCorners??t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Ce(n?t.borderColor:e?.shape?.border?.color??t.borderColor,n?t.borderAlpha:e?.shape?.border?.alpha??t.borderAlpha),r.style.borderRadius=l},vi=({target:r,isDark:e,baseDimension:t,fallback:i})=>{let l=Ce(i.shadowColorLight,i.shadowColorAlpha),a=Ce(i.shadowColorDark,i.shadowColorAlpha),s=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,d=`0px 0px ${s} ${c} ${e?a:l}`;r.style.boxShadow=d},le=({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 Kt,Subject as zs,Subscription as Ws,ValueSubject as Ks}from"@vkontakte/videoplayer-shared";var Gt="interactive-control-tap",ce={common:Gt,animation:`${Gt}-animation`,visible:`${Gt}-visible`};var Us=60,tt=class{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:i=Us,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),l=i.left+i.width/2,a=i.top+i.height/2,s=e.clientX-l,c=e.clientY-a,d=Gs(s,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(ce.visible,ce.animation)};this.onAnimationEnd=e=>{!e.target||!e.currentTarget||e.target===e.currentTarget&&this.element.classList.remove(ce.visible,ce.animation)};let o=document.createElement("div");o.classList.add(ce.common),this.controlRotateAngleRad=e,this.element=o,this.clickCancelCondition=t,this.circleDiameterPx=i,this.useDimensionsBasedSize=n}};function Gs(r,e,t){return{x:r*Math.cos(t)-e*Math.sin(t),y:r*Math.sin(t)+e*Math.cos(t)}}var zt="int",re=(i=>(i.AREA=`${zt}_area`,i.TEXT=`${zt}_text`,i.BUTTON=`${zt}_bttn`,i))(re||{});function Wt(r){return"features"in r}var W="interactive-control",w={common:W,selected:`${W}-selected`,wrapper:`${W}-wrapper`,disabled:`${W}-disabled`,button:`${W}-button`,area:`${W}-area`,text:`${W}-text`,blinkAnim:`${W}-blink-anim`,blinkAnimButton:`${W}-blink-anim-button`,blinkAnimArea:`${W}-blink-anim-area`},bi=40;var L=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var J=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new Ws;this.error$=new zs;this.isInteracted$=new Ks(!1)}onError(e="",t){let i=new L(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(i)}addControlTap(e){if(this.featureIsEnabled("controlsTapPlace")&&this.container){let t=this.control.layoutParams.angle??k.angle;this.controlTap=new tt({controlRotateAngleRad:t,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?bi:void 0}),this.subscriptions.add(Kt(e,"click").subscribe(this.controlTap.onElementClick,i=>this.onError("Control click tap animation error",i))).add(Kt(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??k.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"},n=()=>e.isContainerDisabled?.()??!1;this.container={element:t,dimensions:i,isManifestContainerDisabled:n}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted$.next(!0),e()}}featureIsEnabled(e){return this.options&&Wt(this.options)&&this.options.features[e]}isTouch(){return this.options&&Wt(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(Kt(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 Yt="interactive-blink-anim-reference",F={common:Yt,animation:`${Yt}-animation`,disabled:`${Yt}-disabled`},rt=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(F.common,F.animation),this._element=e}restart(){this._element&&(this._element.classList.add(F.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(F.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var Zt="interactive-container",V={common:Zt,hidden:`${Zt}-hidden`,disabled:`${Zt}-disabled`};var nt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new Jt(r,e)},Jt=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.area),i.setAttribute("data-testid",re.AREA),et({target:i,props:this.control.props,fallback:{...k,backgroundColor:"transparent"}}),le({target:i,layoutParams:this.control.layoutParams,fallback:k}),this.addControlTap(i),this.container.element.append(i),e.append(this.container.element),this.controlElement=i,this.updateShadowStyles(),this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(it(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(V.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${F.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(it(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(V.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(it(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(ui(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";vi({target:this.controlElement,props:this.control.props,fallback:k,isDark:e,baseDimension:t}),Ee({target:this.controlElement,props:this.control.props,fallback:{...k,borderColor:e?k.shadowColorDark:k.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??k.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Ee({target:this.controlElement,props:this.control.props,fallback:{...k,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(F.disabled)||(this.controlElement.classList.add(F.disabled),this.subscriptions.add(it(e,"animationiteration").pipe(Qs()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(F.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 ct,once as Js}from"@vkontakte/videoplayer-shared";var ot=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 at=Math.PI,er=2*at,st=at/2,yi=3*st,Xs=0,Ys=[Xs,st,at,yi];function gi(r){return r===st}function Ci(r){return r===at}function Ei(r){return r===yi}function Ti(r){return(r%er+er)%er}function Zs(r){for(let e of Ys)if(r===e)return e}function Ii(r){if(Zs(r))return null;let t=Math.floor(r/st)+1;return[1,2,3,4][t-1]}function xi(r){return r*180/Math.PI}var X="interactive-control-fill-animation",N={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 lt=class r{constructor(e){this.widthExpansionCoef=0;let t=document.createElement("div");t.classList.add(N.common);let i=document.createElement("div");i.classList.add(N.fillerWrapper);let n=document.createElement("div");n.classList.add(N.filler),i.append(n),t.append(i);let o=Ti(e.rotateAngle),l=Ii(o),a=l!==null,c=l===2||!a&&Ci(o)||l===3,d=!a&&gi(o),m=!a&&Ei(o),f=!c&&!d&&!m,b=d||m,R=a&&!b,E=R?o:0;t.style.borderRadius=e.borderRadius,i.style.transform=`skew(${E*-1}rad)`,b?(n.classList.add(N.fillHeight,d?N.fromTop:N.fromBottom),i.classList.add(N.fillHeight,d?N.fromTop:N.fromBottom)):(n.classList.add(N.fillWidth,f?N.fromLeft:N.fromRight),i.classList.add(N.fillWidth)),e.debug&&console.log(`[interactive ${r.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:b,rotateAngleRad:o,rotateAngelDeg:xi(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 pt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new tr(r,e)},tr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.button),i.setAttribute("data-testid",re.BUTTON),le({target:i,layoutParams:this.control.layoutParams,fallback:k}),et({target:i,props:this.control.props,fallback:k}),Ee({target:i,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),Ze({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=ot(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;Je({target:o,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),this.addControlTap(i),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled("controlsFillAnimation")&&(this.controlFillAnimation=new lt({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??k.angle,borderRadius:i.style.borderRadius})),i.append(n,this.controlFillAnimation?.fillAnimationElement??""),this.container.element.append(this.controlTap?.element??"",i),e.append(this.container.element),this.controlElement=i,this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(ct(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(V.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${F.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(ct(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(V.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(ct(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(F.disabled)||(this.controlElement.classList.add(F.disabled),this.subscriptions.add(ct(e,"animationiteration").pipe(Js()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(F.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 Si=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new rr(r,e)},rr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("div");i.classList.add(w.common,w.text),i.setAttribute("data-testid",re.TEXT),le({target:i,layoutParams:this.control.layoutParams,fallback:k}),Ze({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=ot(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;Je({target:o,props:this.control.props,fallback:k,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(){}onError(){}};var ut=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new ir(r,e,t)},ir=class extends se{constructor(t,i,n){super(t,n);this.containerElement=null;this.controlSubscriptions=new tl;this.error$=new el;this.rootElement=i,this.layout=new Ke(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pt),this.addControlFactory("text",Si),this.addControlFactory("area",nt)}createView({eventCallback:t,videoDurationMs:i}){let n=document.createElement("div");return n.classList.add(V.common,V.disabled),requestAnimationFrame(()=>{n.classList.remove(V.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(o=>{o.setShowTimeRange(this.container.startTime,this.container.endTime??i),o.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout,isContainerDisabled:()=>this.isDisabled}}),o.setEvents(t),this.controlSubscriptions.add(o.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!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(V.hidden)}show(){let t=this.getElement();t&&t.classList.remove(V.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(V.disabled),this.controls.forEach(i=>i.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(V.disabled),this.controls.forEach(i=>i.disable()),this.isDisabled=!0)}removeView(){let t=this.getElement();t&&(this.controlSubscriptions.unsubscribe(),this.controls.forEach(i=>i.removeListeners()),t.remove(),this.isRemoved=!0,this.containerElement=null)}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 Ns=z(Fr(),1);import{combine as bh,InterfaceLanguage as yh,Observable as Ls,once as gh,Subject as _,Subscription as ni,ValueSubject as B,fromEvent as Fs}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ze}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as bp}from"@vkontakte/videoplayer-shared";function Le(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var Oo="video_interactive",Po="videoint";var Mo=250,Fe=class{constructor(e){this.handleZoomChange=Le(e=>{this.lastZoomInfo=e},Mo);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,!Ye(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=yp(e),this.resizeObserver=new ResizeObserver(Le(this.onResize,Mo)),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 bp(this.lang,Oo,Po)}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 yp(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 Ve=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 l=o.startTime-e;if(l<=n&&(o.endTime&&n<=o.endTime||o.endTime===null)){i=!0;break}n<l&&(t=t===-1?l:Math.min(t,l))}return!i&&t!==-1?t:null}}};import{isSupportedManifest as Tt,ContainerTypes as Rf,ControlTypes as It,EventActionTypes as S,EventTypes as kf,migrateManifestToLatestVersion as No,compareVersions as Of}from"@interactiveplatform/movika-manifest";var Lo={metadata:"Object",chapters:"Array"},Fo=r=>{if(!Z(r))return!1;for(let e in Lo)if(!r[e]||!Y(r[e],Lo[e]))return!1;return Tt(r.metadata.version)},Et=r=>r.type===It.Text,Cf=r=>r.type===It.Button,Ef=r=>r.type===It.Area,Tf={Choice:"Choice",TextInput:"TextInput"},If={Button:"Button",Area:"Area",Text:"Text"},xf={onClick:"onClick",onSuspense:"onSuspense"},Vo={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var xt=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 St=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{pi(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=[]}};import{ValueSubject as Bp}from"@vkontakte/videoplayer-shared";var At=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return gp(...this.loaders[e])(t)}};function gp(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function Ne(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function wt({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 l=r.getMedia(n.media,o.videoId),a=r.getGraph(n.graph,o.id);return l?{...i,actions:r,errors:e,result:{chapter:o,media:l,graph:a}}:{...i,errors:Ne(e,wt.name,"Could not find media"),actions:r}}}}return{...i,errors:Ne(e,wt.name,"Could not find chapter"),actions:r}}var Rt=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 l=i[n];try{l.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},fe=class extends Rt{constructor(){super(),this.listeners||Rt.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)}},_e=class{constructor(){Object.defineProperty(this,"signal",{value:new fe,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document>"u")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch{i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(_e.prototype[Symbol.toStringTag]="AbortController",fe.prototype[Symbol.toStringTag]="AbortSignal");function kt(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 Vr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!kt({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 l=e;return{fetch:(s,c)=>{let d=o&&o.prototype.isPrototypeOf(s)?s.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,l(s,c)])}return l(s,c)},Request:o}}var Cp=()=>"fetch"in window,$e=Cp()&&kt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),_o=$e?Vr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Nr=$e?_o.fetch:window.fetch,Hf=$e?_o.Request:window.Request,Uf=$e?_e:window.AbortController,Gf=$e?fe:window.AbortSignal;var _r=(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 Ep=async r=>{try{let e={},t;if(Qe(r)){t=new URL(r).href;let n=await Nr(t);if(!n.ok)return{};e=await n.json()}else if(Z(r))e=r;else return{};if(!Fo(e))return{};let i=e.metadata.media;if(Qe(i)&&!("media"in e))try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let o=await Nr(n);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch{return xp(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function $o(r){let{manifest:e,manifestURL:t}=await Ep(r);if(!e)throw new Error("Failed on fetch");let i=No(e);return i.media=Tp(i.media,t),delete i.metadata.media,i}function Ot(r,e){if(e)return r.find(t=>t.id===e)}function $r(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 jr(r,e){return r.videos.find(t=>t.id===e)}function Tp(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",o=Ip(n,e);return{...i,url:o||n}})}))}}function Ip(r="",e){try{return new URL(r,e).href}catch{return""}}function xp(r){return _r(r,"3.2.0")>=0}var Qo=z(je(),1);var Pt=r=>Xe(r)&&!Ut(r),Q=r=>r.order==="end",Mt=r=>Xe(r.containers)&&!Ut(r.containers)&&Q(r),Xo=(r,e)=>{let t=r*1e3;return Pt(e.controls)&&t<(e.startTime??0)},qr=(r,e)=>{let t=r*1e3;return Pt(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var ne=(r=[])=>r.some(e=>e.action.type==="expect"),Dr=(r=[])=>r.find(e=>e.action.type==="expect"),jp=r=>r?.length===1,ve=r=>jp(r)&&Et(r[0]);function Yo(r=[],e=1/0,t=[]){return r.filter(({container:i})=>!(0,Qo.default)(t,i.container.id)&&ne(i.container.events)&&i.container.endTime===e&&!i.isRemoved)}function Lt({gameControllers:r=[],subjectName:e,subjectId:t,execFn:i}){for(let n of r)if(e==="container"&&n.container.container.id===t){i(n),Yo(r,n.container.container.endTime,[n.container.container.id]).forEach(l=>{i(l)});break}}var Zo=(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===Vo.openURI)&&g})},o=E=>E.some(({container:y})=>n(y.container,!0,!1)&&!y.isRemoved),l=E=>E.every(({container:y})=>y.isRemoved?!0:n(y.container,!0,!0)),a=Yo(e,r.endTime,[r.id]).length,s=E=>E.controls.some(y=>y.events?.some(u=>u.action?.args?.shouldOpenNow)),c=i||a>0,d=o(e),m=n(r),f=l(e),b=i?!1:a>0,R=s(r);return{isExpectTime:c,hasOtherExpect:a>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:m,isAllOpenURIEventsValid:f,isExpectEventForCurrentContainer:b,hasShouldOpenNowEvent:R}};var be=class extends At{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Bp(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:Ne},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await $o(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",wt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:$r,getChapter:Ot,getMedia:jr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ne},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=Ot(this.manifest.chapters,t);if(i){let n=jr(this.manifest.media,i.videoId),o=$r(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=Ot(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 Oa=z(Ft(),1);import{Player as mu}from"@vkontakte/videoplayer-core";import{Subscription as Wr,Tracer as fu,ValueSubject as vu}from"@vkontakte/videoplayer-shared";var Ra=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 ka=z(Ft(),1);function Gr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let s=r.get(o),c={...a};return s?s[l]=c:r.set(o,{[l]:c}),{listId:o,itemId:l,...a}}function t(o){o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),o.statistics?.oneStat.destroy(),o.statistics?.statSubscription.unsubscribe()}function i(o,l){let a=r.get(o);if(!a)throw Error("Can't remove. Not find.");if(l){let s=a[l];s&&t(s),delete a[l],Object.keys(a).length||r.delete(o)}else{for(let s of(0,ka.default)(a))t(s);r.delete(o)}}function n(){for(let o of r)i(o[0])}return{createPlayer:e,removePlayer:i,map:r,removeAll:n}}var ye=z(je(),1);function zr(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,ye.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"mpeg":(n||(0,ye.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"hls":(n||(0,ye.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:o.url}});break;case"dash":(n||(0,ye.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 Be=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&(0,ye.default)(i,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var bu=2;function Kr(r){let e=Gr(),t=new Wr,i={},n=null,o=!1,l,a=new vu(null);r&&s(r);function s(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 A=C.info.position$.getValue(),$=C.info.isAutoQualityEnabled$.getValue();if(!(!T||!A||$))for(let I of e.map)(0,Oa.default)(I[1]).forEach(({player:P})=>{Be(P,T)})})).add(C.events.started$.subscribe(()=>{d(u)})),g.container.remove(),n.setPlayer(g.player),o||(n.init(),o=!0),a.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(),A=!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 M of P)M===i.itemId?(P.length<bu||($=!0),e.removePlayer(I[0],M)):($=!0,c(I[0],M,y),A?Be(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}),A?Be(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:A}){let $=Math.random().toString(),I=document.createElement("div");l.append(I);let P;if(n?.options?.vkVideoLoader){let We=Ra(y);We.length&&(P=await n.options.vkVideoLoader(...We))}let M=n?.options?.coreConfig||void 0,G={...M,configName:[...M?.configName??[],"interactive"]},ee={container:I,...P?.videos?.[0]||{sources:zr(y,C).sources},title:T,failoverHosts:P?.failoverHosts||[]},j=new mu(G,fu.createRootTracer());j.initVideo(ee);let oe=null;if(P?.videos&&n?.options.createOneStat){let We=P.videos[0],qt=n.options.createOneStat(We),ai=new Wr;qt&&(ai.add(qt.attachTo(j)),oe={oneStat:qt,statSubscription:ai})}let oi=new Wr,_s=i?.player?.info.isAutoQualityEnabled$.getValue();oi.add(j.events.canplay$.subscribe(function(){_s||Be(j,i.player.info.currentQuality$.getValue()),A&&j.setPlaybackRate(A)}));let ae=e.createPlayer({listId:y.id,itemId:$,player:j,container:I,sources:zr(y,C).sources,config:ee,subscription:oi,statistics:oe});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,l.remove()}function R(){t.unsubscribe(),e.removeAll(),i={},o=!1}async function E(){if(!n)throw Error("need to set interactive controller");R(),l=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:s,createPlayer:f,removeAll:b,getActivePlayer:function(){return i},activePlayerChanged:a}}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"},qe={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},O={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var Ma=z(je(),1);import{Subscription as yu}from"@vkontakte/videoplayer-shared";function Qr(r){return function(...t){return r(...t.reverse())}}function De(r,...e){return(...t)=>Z(e[0])&&Z(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var Vt=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:o,globalEvents:l,globalEventEmitter:a,getContainerEventState:s,permanentTextControls:c,interactiveTimeOpenUri:d,disabledControls$:m,onRemove:f,onError:b}){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)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,l)=>{let{isExpectTime:a,hasOtherExpect:s,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=!s&&!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)(a,s,m,this.isSelectedContainerEvent);this.fakeRemoveView(y)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!a||!s||!f)&&(this.selectBranches.stopExpect(),l())}},isEOV:()=>this.gameState===4},i=De(this.selectBranches.onControlEvent,t),n=(this.player?.info.duration$.getValue()??1/0)*1e3;this.container.createView({eventCallback:i,videoDurationMs:n}),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),i=e instanceof HTMLVideoElement?e.readyState:void 0,n=[6,5];if(!i||(0,Ma.default)(n,this.gameState)&&!this.isPermanentText)return;let o=this.player.getExactTime();if(Xo(o,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(qr(o,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let c=this.gameState;this.gameState=3,c===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:c}=this.getContainerEventState(),d=this.selectBranches.state.isExpect,m=this.interactiveTimeOpenUri&&c;if(m&&!d){let f=this.container.getElement();f&&(f.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!m&&this.removeView()}let l=qr(o,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:o,isInteractiveTime:l};this.container.onProgress(o*1e3,l),this.globalEventEmitter.emit(x.eachTick,s),this.globalEvents.eachTick$.next(s)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new yu,this.player=e,this.interactiveEvents=o,this.getContainerEventState=s,this.isPermanentText=c&&ve(t.container.controls),this.interactiveTimeOpenUri=d,this.disabledControls$=m,this.onRemove=f,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,this.onError=b,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:O.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:O.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()})),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(){this.container.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var La=(r=[])=>r.reduce((e,t,i)=>{let n=(t?.controls??[]).filter(o=>!Et(o));if(Pt(n)){let o=[t.startTime??0,t.endTime??1/0],l={id:t.id,isRemoved:!1};if(!i)e.push({subjects:[l],range:o});else{let a=[],s=-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]>s&&(s=b.range[1]),o[0]>=b.range[0]&&o[1]<=b.range[1])return e[f].subjects.push(l),e;o[0]<b.range[0]&&o[1]>b.range[0]&&(a.push(f),d=d.concat(b.subjects)),o[0]>=b.range[0]&&o[0]<=b.range[1]&&(a.push(f),d=d.concat(b.subjects),o[0]=b.range[0]),o[1]>=b.range[0]&&o[1]<=b.range[1]&&(a.push(f),d=d.concat(b.subjects),o[1]=b.range[1])}if(m.push(l),o[0]<=c&&o[1]>=s)return[{subjects:m,range:o}];a.length&&a.reverse().forEach(f=>{e.splice(f,1)}),e.push({subjects:d.concat([l]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var ms=z(je(),1),Jr=z(Ft(),1),fs=z(hs(),1);function ds(){let r={};function e(){for(let a in r)Object.prototype.hasOwnProperty.call(r,a)&&delete r[a]}function t(a){let s={};for(let c in r)+c<=a&&(s[c]=r[c]);return s}function i(a){let s={};for(let c in r)+c>=a&&(s[c]=r[c]);return s}function n({timestamp:a,priority:s,initiator:c}){if(Ht(a)){let d=r[a]??null;if(d&&s&&ge(s,!0)){let m={},f=d[s];return f&&(m={...m,...f}),m=te(m)?null:m,m&&ge(c,!0)?m[c]??null:m}return d}return null}function o({timestamp:a,priority:s,initiator:c}){if(Ht(a))if(r[a]){if(s&&ge(s,!0))if(r[a][s]){if(c&&ge(c,!0))if(r[a][s][c]){if(delete r[a][s][c],!te(r[a][s]))return!0}else return!1;if(delete r[a][s],!te(r[a]))return!0}else return!1;return delete r[a]}else return!1;return!1}function l({timestamp:a,priority:s,initiator:c,...d}){r[a]?.[s]?.[c]?r[a][s][c].push({...d}):r[a]?.[s]?r[a][s]={...r[a][s],[c]:[{...d}]}:r[a]?r[a]={...r[a],[s]:{[c]:[{...d}]}}:r[a]={[s]:{[c]:[{...d}]}}}return{map:r,remove:o,add:l,removeAll:e,get:n,getLte:t,getGte:i}}var ah=[S.expect,S.setNextBranch],sh=1/0;function vs(r,e){let t=r,i,n=lh(e),o=ds(),l,a=()=>{b(),u()},s=h=>{o.add.call(void 0,h),R()},c=(h=[])=>{for(let v of h)if(v.action(),(0,ms.default)(ah,v.actionType))break},d=(h=1/0)=>{let v=_t(o.get({timestamp:h,priority:"control"})??{}),g=_t(o.get({timestamp:h,priority:"container"})??{}),C=_t(o.get({timestamp:h,priority:"chapter"})??{});return[...v,...g,...C]},m=h=>{n.isReady(h)&&c(d(h))},f=()=>{c([..._t(o.get({timestamp:1/0,priority:"chapter"})??{})])},b=()=>{i&&(l?.unsubscribe(),i=void 0)},R=()=>{i||(i=()=>setTimeout(()=>{m(1/0)}),l=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:s,remove:y,exec:m,execEndOfVideo:f,listen:R,unlisten:b,release:a,containersEventsCallState:n,getPreparedToExecActions:d}}function lh(r){let e=new Map;return{setCalled:({timestamp:a,id:s})=>{let c=e.get(a);c&&c[s]!==void 0&&(c[s]=!0)},setData:(a=[])=>{for(let s of a){let c=s.endTime??sh,d=e.get(c);e.set(c,{...d,[s.id]:!1})}},resetCalled:a=>{let s=e.get(a);if(s)for(let c in s)s[c]=!1},isReady:a=>{let s=e.get(a);if(!s)return!0;let c=(0,Jr.default)(s);return r?c.some(m=>m):!c.some(m=>!m)},release:()=>e.clear()}}function _t(r){return(0,fs.default)((0,Jr.default)(r)).sort(e=>e.actionType===S.expect?-1:1)}var bs={videoContentHeight:0,videoContentWidth:0},ys=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return bs;let{clientHeight:i,clientWidth:n}=r.experimental.element$.getValue()||{};if(!(i&&n))return bs;let o=e/t,l=i/n,a,s;return l>o?(s=n,a=n*o):l<o?(s=i/o,a=i):(s=n,a=i),{videoContentWidth:s,videoContentHeight:a}};var ch=250;function gs(r){let e,t=new ResizeObserver(a=>{o(a),e=o.bind(null,a)});function i(a){let{parentElement:s,player:c}=r();if(s&&c){let{videoContentWidth:d,videoContentHeight:m}=ys(c);s.style.setProperty("--interactive-content-width",`${d}px`),s.style.setProperty("--interactive-content-height",`${m}px`),s.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),s.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function n(){let{parentElement:a}=r();a.removeAttribute("style")}let o=Le(a=>{let{fns:s=[]}=r();i(a);for(let c of s)c()},ch);function l(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e?.()},release:l}}var ph=r=>Math.floor(Math.random()*r),Es=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},Ts=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 Is=r=>{let e=r.length,t=ph(e);return r[t]},Cs=1,xs=r=>{let e=0;for(let i=0;i<r.length;++i)e+=r[i].weight??Cs;let t=Math.random()*e;e=0;for(let i=0;i<r.length-1;++i)if(e+=r[i].weight??Cs,e>=t)return r[i];return r[r.length-1]};var Ss={shouldOpenNow:!0,isDetachContainer:!0},As="after-expect",ei=(r,e=!1)=>({...r,args:e?{...r.args,...Ss}:{...Ss,...r.args}}),ws=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:i})=>{let n={isExpect:!1},o=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:u,controlType:h,controlId:v,containerId:g,branches:C=[],onEvent:T,isEOV:A=()=>!1,isDisabled:$=()=>!1})=>{let I=ei(u,A()),P={timestamp:1/0,priority:"control",initiator:v,actionType:I.type},M=$(),G=r.emit.bind(r,x.interactives,{subjectId:v,subjectType:h,subjectName:"control",type:M?O.actionChoiceCanceled:O.actionChoice,actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:g,...I.args}}),ee=()=>{e.interactiveActionChoice$.next({subjectId:v,subjectType:h,subjectName:"control",type:M?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:I.args.shouldOpenNow,containerId:g,...I.args}})};if(M){G(),ee();return}switch(I.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let j=C.find(oe=>oe.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 S.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 S.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",oe=new L(1,1,{message:j});d(oe,j);return}}},a=({action:u,container:{id:h,endTime:v},branches:g=[],isEOV:C=!1,autoSelected:T=!1})=>{let A=ei(u,C),$={timestamp:!A.args.shouldOpenNow||C?1/0:v??1/0,priority:"container",initiator:h,actionType:A.type},I=r.emit.bind(r,x.interactives,{subjectId:h,subjectName:"container",type:O.actionChoice,actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}}),P=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"container",type:"action-choice",actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}})};switch(A.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let M=g.find(G=>G.id===A.args.branchId);if(!M)return;I(),P(),i.add({...$,action:E.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{chapterId:M.chapterId,autoSelect:T}})});return}case S.setMaxWeightBranch.trim().toLowerCase():return;case S.setMinWeightBranch.trim().toLowerCase():return;case S.setRandomBranch.trim().toLowerCase():return;case S.setWeightlessRandomBranch.trim().toLowerCase():return;case S.continuePlayback.trim().toLowerCase():{I(),P(),i.add({...$,action:R.bind(null,{subjectId:h,subjectName:"container",action:A})});return}case S.openURI.trim().toLowerCase():{I(),P(),i.add({...$,action:y.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{URI:u.args.uri}})});return}default:{let M="Unexpected container event",G=new L(1,1,{message:M});d(G,M);return}}};function s({container:u,branches:h,isEOV:v=!1}){let g=Dr(u.events);if(g){let C=ei(g.action,v);r.emit(x.interactives,{subjectId:u.id,subjectName:"container",type:O.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:S.expect,action:f.bind(null,{subjectId:u.id,subjectName:"container"})}),n.isExpect=!0}else for(let C of u.events??[])a({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:O.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 S.setNextBranch.trim().toLowerCase():{let T=v.find(A=>A.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 S.setWeightlessRandomBranch.trim().toLowerCase():{let T=Is(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.setRandomBranch.trim().toLowerCase():{let T=xs(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.setMaxWeightBranch.trim().toLowerCase():{let T=Ts(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.setMinWeightBranch.trim().toLowerCase():{let T=Es(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.continuePlayback.trim().toLowerCase():return g(),C(),R.bind(null,{subjectId:u,subjectName:"chapter",action:h});case S.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",A=new L(1,1,{message:T});d(A,T);return}}};function d(u,h){console.error(h),e.error$.next(u),r.emit(x.errors,u)}function m(u){let h=Dr(u.events);if(h){if(Q(u))return;r.emit(x.interactives,{subjectId:u.id,subjectName:"chapter",type:O.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:S.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:O.actionExecution,actionType:S.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:S.expect})},b=({subjectId:u,subjectName:h})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),r.emit(x.interactives,{subjectId:u,subjectName:h,type:O.actionExecution,actionType:As}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:As})},R=({subjectId:u,subjectName:h,subjectType:v,action:g})=>{r.emit(x.interactives,{subjectId:u,subjectName:h,subjectType:v,type:O.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:O.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:O.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:c,onExpectEvent:f,expectEventHandler:b,setManifestChapterEvents:m,setManifestContainerEvents:s,stopExpect:o,state:n}};var ii=z(Fr(),1);import{Subscription as fh,Subject as ri,ValueSubject as Ue}from"@vkontakte/videoplayer-shared";var ti=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(l=>l.id===i);if(!n)return null;let o=e.media.videos.find(l=>n.videoId===l.id);if(!o)return null;t[i]=Rs(o)}return t[i]}).filter(Boolean)},hh=r=>{for(let e of r.variants)if(dh(e)&&e.payload)return e.payload.id},dh=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Rs=r=>{let e=hh(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},mh=(r,e)=>{for(let t of r.media.videos)if(e===Rs(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},ks=(r,e)=>r.reduce((t,i)=>{let n=mh(e,i);return n?[...t,n]:t},[]);var Ge=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:o}){this.state={history$:new Ue([]),hasPrevChapter$:new Ue(!1),prevChapter$:new Ue(null),isInitialChapter$:new Ue(!1),isGoBackLimited$:new Ue(!1)};this.#r=null;this.#a=!1;this.#e=null;this.#p=null;this.events={inited$:new ri,destroyed$:new ri,error$:new ri};this.#i=null;this.#n=null;this.#t=null;this.#s=new fh;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.#s&&this.#s?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,ii.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#o.maxLength-1)}))}#r;#o;#a;#e;#p;#i;#n;#t;#s;#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.#a||(this.#a=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#a}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,l=ti(o,i);if(this.#p=l,this.state.history$.next(o),!(!t||!this.#r||!this.#i))try{await this.#r.save(this.#i,l)}catch{let s=new L(1,5,"Unable to save interactive history");this.events.error$.next(s),this.#t?.emit(x.errors,s)}}async goBack(){if(!this.state||!this.#n){let i=new L(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 L(1,5,"Error while trying to fetch data");this.events.error$.next(o),this.#t?.emit(x.errors,o)}let i=ks(t,e);this.state.history$.next(i)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,ii.default)(e,-1)||this.#o.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return ti([e],this.#e).pop()}return null}destroy(){this.#i=null,this.#r=null,this.#n=null,this.#s?.unsubscribe(),this.#s=null,this.#a=!1,this.#t?.emit(x.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var $t=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 jt=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 $s=Object.create;var si=Object.defineProperty;var js=Object.getOwnPropertyDescriptor;var Bs=Object.getOwnPropertyNames;var qs=Object.getPrototypeOf,Ds=Object.prototype.hasOwnProperty;var p=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Hs=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Bs(e))!Ds.call(r,n)&&n!==t&&si(r,n,{get:()=>e[n],enumerable:!(i=js(e,n))||i.enumerable});return r};var z=(r,e,t)=>(t=r!=null?$s(qs(r)):{},Hs(e||!r||!r.__esModule?si(t,"default",{value:r,enumerable:!0}):t,r));var K=p((nr,Ai)=>{"use strict";var Te=function(r){return r&&r.Math===Math&&r};Ai.exports=Te(typeof globalThis=="object"&&globalThis)||Te(typeof window=="object"&&window)||Te(typeof self=="object"&&self)||Te(typeof global=="object"&&global)||Te(typeof nr=="object"&&nr)||function(){return this}()||Function("return this")()});var q=p((Zd,wi)=>{"use strict";wi.exports=function(r){try{return!!r()}catch{return!0}}});var xe=p((Jd,Ri)=>{"use strict";var rl=q();Ri.exports=!rl(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var Vi=p((em,Mi)=>{"use strict";var il=xe(),Pi=Function.prototype,ki=Pi.apply,Oi=Pi.call;Mi.exports=typeof Reflect=="object"&&Reflect.apply||(il?Oi.bind(ki):function(){return Oi.apply(ki,arguments)})});var H=p((tm,Ni)=>{"use strict";var Li=xe(),Fi=Function.prototype,or=Fi.call,nl=Li&&Fi.bind.bind(or,or);Ni.exports=Li?nl:function(r){return function(){return or.apply(r,arguments)}}});var Ie=p((rm,$i)=>{"use strict";var _i=H(),ol=_i({}.toString),al=_i("".slice);$i.exports=function(r){return al(ol(r),8,-1)}});var ar=p((im,ji)=>{"use strict";var sl=Ie(),ll=H();ji.exports=function(r){if(sl(r)==="Function")return ll(r)}});var D=p((nm,Bi)=>{"use strict";var sr=typeof document=="object"&&document.all;Bi.exports=typeof sr>"u"&&sr!==void 0?function(r){return typeof r=="function"||r===sr}:function(r){return typeof r=="function"}});var ie=p((om,qi)=>{"use strict";var cl=q();qi.exports=!cl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var dt=p((am,Di)=>{"use strict";var pl=xe(),ht=Function.prototype.call;Di.exports=pl?ht.bind(ht):function(){return ht.apply(ht,arguments)}});var lr=p(Gi=>{"use strict";var Hi={}.propertyIsEnumerable,Ui=Object.getOwnPropertyDescriptor,ul=Ui&&!Hi.call({1:2},1);Gi.f=ul?function(e){var t=Ui(this,e);return!!t&&t.enumerable}:Hi});var cr=p((lm,zi)=>{"use strict";zi.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Ki=p((cm,Wi)=>{"use strict";var hl=H(),dl=q(),ml=Ie(),pr=Object,fl=hl("".split);Wi.exports=dl(function(){return!pr("z").propertyIsEnumerable(0)})?function(r){return ml(r)==="String"?fl(r,""):pr(r)}:pr});var ur=p((pm,Qi)=>{"use strict";Qi.exports=function(r){return r==null}});var hr=p((um,Xi)=>{"use strict";var vl=ur(),bl=TypeError;Xi.exports=function(r){if(vl(r))throw new bl("Can't call method on "+r);return r}});var Se=p((hm,Yi)=>{"use strict";var yl=Ki(),gl=hr();Yi.exports=function(r){return yl(gl(r))}});var pe=p((dm,Zi)=>{"use strict";var Cl=D();Zi.exports=function(r){return typeof r=="object"?r!==null:Cl(r)}});var mt=p((mm,Ji)=>{"use strict";Ji.exports={}});var ft=p((fm,tn)=>{"use strict";var dr=mt(),mr=K(),El=D(),en=function(r){return El(r)?r:void 0};tn.exports=function(r,e){return arguments.length<2?en(dr[r])||en(mr[r]):dr[r]&&dr[r][e]||mr[r]&&mr[r][e]}});var nn=p((vm,rn)=>{"use strict";var Tl=H();rn.exports=Tl({}.isPrototypeOf)});var ln=p((bm,sn)=>{"use strict";var xl=K(),on=xl.navigator,an=on&&on.userAgent;sn.exports=an?String(an):""});var fn=p((ym,mn)=>{"use strict";var dn=K(),fr=ln(),cn=dn.process,pn=dn.Deno,un=cn&&cn.versions||pn&&pn.version,hn=un&&un.v8,U,vt;hn&&(U=hn.split("."),vt=U[0]>0&&U[0]<4?1:+(U[0]+U[1]));!vt&&fr&&(U=fr.match(/Edge\/(\d+)/),(!U||U[1]>=74)&&(U=fr.match(/Chrome\/(\d+)/),U&&(vt=+U[1])));mn.exports=vt});var vr=p((gm,bn)=>{"use strict";var vn=fn(),Il=q(),Sl=K(),Al=Sl.String;bn.exports=!!Object.getOwnPropertySymbols&&!Il(function(){var r=Symbol("symbol detection");return!Al(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&vn&&vn<41})});var br=p((Cm,yn)=>{"use strict";var wl=vr();yn.exports=wl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var yr=p((Em,gn)=>{"use strict";var Rl=ft(),kl=D(),Ol=nn(),Pl=br(),Ml=Object;gn.exports=Pl?function(r){return typeof r=="symbol"}:function(r){var e=Rl("Symbol");return kl(e)&&Ol(e.prototype,Ml(r))}});var En=p((Tm,Cn)=>{"use strict";var Vl=String;Cn.exports=function(r){try{return Vl(r)}catch{return"Object"}}});var gr=p((xm,Tn)=>{"use strict";var Ll=D(),Fl=En(),Nl=TypeError;Tn.exports=function(r){if(Ll(r))return r;throw new Nl(Fl(r)+" is not a function")}});var In=p((Im,xn)=>{"use strict";var _l=gr(),$l=ur();xn.exports=function(r,e){var t=r[e];return $l(t)?void 0:_l(t)}});var An=p((Sm,Sn)=>{"use strict";var Cr=dt(),Er=D(),Tr=pe(),jl=TypeError;Sn.exports=function(r,e){var t,i;if(e==="string"&&Er(t=r.toString)&&!Tr(i=Cr(t,r))||Er(t=r.valueOf)&&!Tr(i=Cr(t,r))||e!=="string"&&Er(t=r.toString)&&!Tr(i=Cr(t,r)))return i;throw new jl("Can't convert object to primitive value")}});var Rn=p((Am,wn)=>{"use strict";wn.exports=!0});var Pn=p((wm,On)=>{"use strict";var kn=K(),Bl=Object.defineProperty;On.exports=function(r,e){try{Bl(kn,r,{value:e,configurable:!0,writable:!0})}catch{kn[r]=e}return e}});var bt=p((Rm,Ln)=>{"use strict";var ql=Rn(),Dl=K(),Hl=Pn(),Mn="__core-js_shared__",Vn=Ln.exports=Dl[Mn]||Hl(Mn,{});(Vn.versions||(Vn.versions=[])).push({version:"3.38.0",mode:ql?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var xr=p((km,Nn)=>{"use strict";var Fn=bt();Nn.exports=function(r,e){return Fn[r]||(Fn[r]=e||{})}});var Ae=p((Om,_n)=>{"use strict";var Ul=hr(),Gl=Object;_n.exports=function(r){return Gl(Ul(r))}});var ue=p((Pm,$n)=>{"use strict";var zl=H(),Wl=Ae(),Kl=zl({}.hasOwnProperty);$n.exports=Object.hasOwn||function(e,t){return Kl(Wl(e),t)}});var Ir=p((Mm,jn)=>{"use strict";var Ql=H(),Xl=0,Yl=Math.random(),Zl=Ql(1 .toString);jn.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Zl(++Xl+Yl,36)}});var we=p((Vm,qn)=>{"use strict";var Jl=K(),ec=xr(),Bn=ue(),tc=Ir(),rc=vr(),ic=br(),he=Jl.Symbol,Sr=ec("wks"),nc=ic?he.for||he:he&&he.withoutSetter||tc;qn.exports=function(r){return Bn(Sr,r)||(Sr[r]=rc&&Bn(he,r)?he[r]:nc("Symbol."+r)),Sr[r]}});var Gn=p((Lm,Un)=>{"use strict";var oc=dt(),Dn=pe(),Hn=yr(),ac=In(),sc=An(),lc=we(),cc=TypeError,pc=lc("toPrimitive");Un.exports=function(r,e){if(!Dn(r)||Hn(r))return r;var t=ac(r,pc),i;if(t){if(e===void 0&&(e="default"),i=oc(t,r,e),!Dn(i)||Hn(i))return i;throw new cc("Can't convert object to primitive value")}return e===void 0&&(e="number"),sc(r,e)}});var Ar=p((Fm,zn)=>{"use strict";var uc=Gn(),hc=yr();zn.exports=function(r){var e=uc(r,"string");return hc(e)?e:e+""}});var Qn=p((Nm,Kn)=>{"use strict";var dc=K(),Wn=pe(),wr=dc.document,mc=Wn(wr)&&Wn(wr.createElement);Kn.exports=function(r){return mc?wr.createElement(r):{}}});var Rr=p((_m,Xn)=>{"use strict";var fc=ie(),vc=q(),bc=Qn();Xn.exports=!fc&&!vc(function(){return Object.defineProperty(bc("div"),"a",{get:function(){return 7}}).a!==7})});var Jn=p(Zn=>{"use strict";var yc=ie(),gc=dt(),Cc=lr(),Ec=cr(),Tc=Se(),xc=Ar(),Ic=ue(),Sc=Rr(),Yn=Object.getOwnPropertyDescriptor;Zn.f=yc?Yn:function(e,t){if(e=Tc(e),t=xc(t),Sc)try{return Yn(e,t)}catch{}if(Ic(e,t))return Ec(!gc(Cc.f,e,t),e[t])}});var to=p((jm,eo)=>{"use strict";var Ac=q(),wc=D(),Rc=/#|\.prototype\./,Re=function(r,e){var t=Oc[kc(r)];return t===Mc?!0:t===Pc?!1:wc(e)?Ac(e):!!e},kc=Re.normalize=function(r){return String(r).replace(Rc,".").toLowerCase()},Oc=Re.data={},Pc=Re.NATIVE="N",Mc=Re.POLYFILL="P";eo.exports=Re});var kr=p((Bm,io)=>{"use strict";var ro=ar(),Vc=gr(),Lc=xe(),Fc=ro(ro.bind);io.exports=function(r,e){return Vc(r),e===void 0?r:Lc?Fc(r,e):function(){return r.apply(e,arguments)}}});var oo=p((qm,no)=>{"use strict";var Nc=ie(),_c=q();no.exports=Nc&&_c(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var so=p((Dm,ao)=>{"use strict";var $c=pe(),jc=String,Bc=TypeError;ao.exports=function(r){if($c(r))return r;throw new Bc(jc(r)+" is not an object")}});var po=p(co=>{"use strict";var qc=ie(),Dc=Rr(),Hc=oo(),yt=so(),lo=Ar(),Uc=TypeError,Or=Object.defineProperty,Gc=Object.getOwnPropertyDescriptor,Pr="enumerable",Mr="configurable",Vr="writable";co.f=qc?Hc?function(e,t,i){if(yt(e),t=lo(t),yt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&Vr in i&&!i[Vr]){var n=Gc(e,t);n&&n[Vr]&&(e[t]=i.value,i={configurable:Mr in i?i[Mr]:n[Mr],enumerable:Pr in i?i[Pr]:n[Pr],writable:!1})}return Or(e,t,i)}:Or:function(e,t,i){if(yt(e),t=lo(t),yt(i),Dc)try{return Or(e,t,i)}catch{}if("get"in i||"set"in i)throw new Uc("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var ho=p((Um,uo)=>{"use strict";var zc=ie(),Wc=po(),Kc=cr();uo.exports=zc?function(r,e,t){return Wc.f(r,e,Kc(1,t))}:function(r,e,t){return r[e]=t,r}});var Oe=p((Gm,fo)=>{"use strict";var ke=K(),Qc=Vi(),Xc=ar(),Yc=D(),Zc=Jn().f,Jc=to(),de=mt(),ep=kr(),me=ho(),mo=ue();bt();var tp=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 Qc(r,this,arguments)};return e.prototype=r.prototype,e};fo.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,o=r.proto,l=i?ke:n?ke[t]:ke[t]&&ke[t].prototype,a=i?de:de[t]||me(de,t,{})[t],s=a.prototype,c,d,m,f,b,R,E,y,u;for(f in e)c=Jc(i?f:t+(n?".":"#")+f,r.forced),d=!c&&l&&mo(l,f),R=a[f],d&&(r.dontCallGetSet?(u=Zc(l,f),E=u&&u.value):E=l[f]),b=d&&E?E:e[f],!(!c&&!o&&typeof R==typeof b)&&(r.bind&&d?y=ep(b,ke):r.wrap&&d?y=tp(b):o&&Yc(b)?y=Xc(b):y=b,(r.sham||b&&b.sham||R&&R.sham)&&me(y,"sham",!0),me(a,f,y),o&&(m=t+"Prototype",mo(de,m)||me(de,m,{}),me(de[m],f,b),r.real&&s&&(c||!s[f])&&me(s,f,b)))}});var bo=p((zm,vo)=>{"use strict";var rp=Math.ceil,ip=Math.floor;vo.exports=Math.trunc||function(e){var t=+e;return(t>0?ip:rp)(t)}});var Pe=p((Wm,yo)=>{"use strict";var np=bo();yo.exports=function(r){var e=+r;return e!==e||e===0?0:np(e)}});var Co=p((Km,go)=>{"use strict";var op=Pe(),ap=Math.min;go.exports=function(r){var e=op(r);return e>0?ap(e,9007199254740991):0}});var Me=p((Qm,Eo)=>{"use strict";var sp=Co();Eo.exports=function(r){return sp(r.length)}});var gt=p((Xm,To)=>{"use strict";To.exports=function(){}});var xo=p(()=>{"use strict";var lp=Oe(),cp=Ae(),pp=Me(),up=Pe(),hp=gt();lp({target:"Array",proto:!0},{at:function(e){var t=cp(this),i=pp(t),n=up(e),o=n>=0?n:i+n;return o<0||o>=i?void 0:t[o]}});hp("at")});var Ct=p((Jm,Io)=>{"use strict";var dp=ft();Io.exports=dp});var Ao=p((ef,So)=>{"use strict";xo();var mp=Ct();So.exports=mp("Array","at")});var Ro=p((tf,wo)=>{"use strict";var fp=Ao();wo.exports=fp});var Lr=p((rf,ko)=>{"use strict";var vp=Ro();ko.exports=vp});var Bo=p((Jf,jo)=>{"use strict";var Sp=Pe(),Ap=Math.max,wp=Math.min;jo.exports=function(r,e){var t=Sp(r);return t<0?Ap(t+e,0):wp(t,e)}});var Br=p((ev,Do)=>{"use strict";var Rp=Se(),kp=Bo(),Op=Me(),qo=function(r){return function(e,t,i){var n=Rp(e),o=Op(n);if(o===0)return!r&&-1;var l=kp(i,o),a;if(r&&t!==t){for(;o>l;)if(a=n[l++],a!==a)return!0}else for(;o>l;l++)if((r||l in n)&&n[l]===t)return r||l||0;return!r&&-1}};Do.exports={includes:qo(!0),indexOf:qo(!1)}});var Ho=p(()=>{"use strict";var Pp=Oe(),Mp=Br().includes,Vp=q(),Lp=gt(),Fp=Vp(function(){return!Array(1).includes()});Pp({target:"Array",proto:!0,forced:Fp},{includes:function(e){return Mp(this,e,arguments.length>1?arguments[1]:void 0)}});Lp("includes")});var Go=p((iv,Uo)=>{"use strict";Ho();var Np=Ct();Uo.exports=Np("Array","includes")});var Wo=p((nv,zo)=>{"use strict";var _p=Go();zo.exports=_p});var je=p((ov,Ko)=>{"use strict";var $p=Wo();Ko.exports=$p});var ta=p((vv,ea)=>{"use strict";var qp=xr(),Dp=Ir(),Jo=qp("keys");ea.exports=function(r){return Jo[r]||(Jo[r]=Dp(r))}});var ia=p((bv,ra)=>{"use strict";var Hp=q();ra.exports=!Hp(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var aa=p((yv,oa)=>{"use strict";var Up=ue(),Gp=D(),zp=Ae(),Wp=ta(),Kp=ia(),na=Wp("IE_PROTO"),Hr=Object,Qp=Hr.prototype;oa.exports=Kp?Hr.getPrototypeOf:function(r){var e=zp(r);if(Up(e,na))return e[na];var t=e.constructor;return Gp(t)&&e instanceof t?t.prototype:e instanceof Hr?Qp:null}});var la=p((gv,sa)=>{"use strict";sa.exports={}});var ua=p((Cv,pa)=>{"use strict";var Xp=H(),Ur=ue(),Yp=Se(),Zp=Br().indexOf,Jp=la(),ca=Xp([].push);pa.exports=function(r,e){var t=Yp(r),i=0,n=[],o;for(o in t)!Ur(Jp,o)&&Ur(t,o)&&ca(n,o);for(;e.length>i;)Ur(t,o=e[i++])&&(~Zp(n,o)||ca(n,o));return n}});var da=p((Ev,ha)=>{"use strict";ha.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var fa=p((Tv,ma)=>{"use strict";var eu=ua(),tu=da();ma.exports=Object.keys||function(e){return eu(e,tu)}});var Ea=p((xv,Ca)=>{"use strict";var ba=ie(),ru=q(),ya=H(),iu=aa(),nu=fa(),ou=Se(),au=lr().f,ga=ya(au),su=ya([].push),lu=ba&&ru(function(){var r=Object.create(null);return r[2]=2,!ga(r,2)}),va=function(r){return function(e){for(var t=ou(e),i=nu(t),n=lu&&iu(t)===null,o=i.length,l=0,a=[],s;o>l;)s=i[l++],(!ba||(n?s in t:ga(t,s)))&&su(a,r?[s,t[s]]:t[s]);return a}};Ca.exports={entries:va(!0),values:va(!1)}});var Ta=p(()=>{"use strict";var cu=Oe(),pu=Ea().values;cu({target:"Object",stat:!0},{values:function(e){return pu(e)}})});var Ia=p((Av,xa)=>{"use strict";Ta();var uu=mt();xa.exports=uu.Object.values});var Aa=p((wv,Sa)=>{"use strict";var hu=Ia();Sa.exports=hu});var Lt=p((Rv,wa)=>{"use strict";var du=Aa();wa.exports=du});var Xr=p((Zv,La)=>{"use strict";var gu=Ie();La.exports=Array.isArray||function(e){return gu(e)==="Array"}});var Na=p((Jv,Fa)=>{"use strict";var Cu=TypeError,Eu=9007199254740991;Fa.exports=function(r){if(r>Eu)throw Cu("Maximum allowed index exceeded");return r}});var ja=p((eb,$a)=>{"use strict";var Tu=Xr(),xu=Me(),Iu=Na(),Su=kr(),_a=function(r,e,t,i,n,o,l,a){for(var s=n,c=0,d=l?Su(l,a):!1,m,f;c<i;)c in t&&(m=d?d(t[c],c,e):t[c],o>0&&Tu(m)?(f=xu(m),s=_a(r,e,m,f,s,o-1)-1):(Iu(s+1),r[s]=m),s++),c++;return s};$a.exports=_a});var Da=p((tb,qa)=>{"use strict";var Au=we(),wu=Au("toStringTag"),Ba={};Ba[wu]="z";qa.exports=String(Ba)==="[object z]"});var Ua=p((rb,Ha)=>{"use strict";var Ru=Da(),ku=D(),Nt=Ie(),Ou=we(),Pu=Ou("toStringTag"),Mu=Object,Vu=Nt(function(){return arguments}())==="Arguments",Lu=function(r,e){try{return r[e]}catch{}};Ha.exports=Ru?Nt:function(r){var e,t,i;return r===void 0?"Undefined":r===null?"Null":typeof(t=Lu(e=Mu(r),Pu))=="string"?t:Vu?Nt(e):(i=Nt(e))==="Object"&&ku(e.callee)?"Arguments":i}});var za=p((ib,Ga)=>{"use strict";var Fu=H(),Nu=D(),Yr=bt(),_u=Fu(Function.toString);Nu(Yr.inspectSource)||(Yr.inspectSource=function(r){return _u(r)});Ga.exports=Yr.inspectSource});var Za=p((nb,Ya)=>{"use strict";var $u=H(),ju=q(),Wa=D(),Bu=Ua(),qu=ft(),Du=za(),Ka=function(){},Qa=qu("Reflect","construct"),Zr=/^\s*(?:class|function)\b/,Hu=$u(Zr.exec),Uu=!Zr.test(Ka),He=function(e){if(!Wa(e))return!1;try{return Qa(Ka,[],e),!0}catch{return!1}},Xa=function(e){if(!Wa(e))return!1;switch(Bu(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Uu||!!Hu(Zr,Du(e))}catch{return!0}};Xa.sham=!0;Ya.exports=!Qa||ju(function(){var r;return He(He.call)||!He(Object)||!He(function(){r=!0})||r})?Xa:He});var rs=p((ob,ts)=>{"use strict";var Ja=Xr(),Gu=Za(),zu=pe(),Wu=we(),Ku=Wu("species"),es=Array;ts.exports=function(r){var e;return Ja(r)&&(e=r.constructor,Gu(e)&&(e===es||Ja(e.prototype))?e=void 0:zu(e)&&(e=e[Ku],e===null&&(e=void 0))),e===void 0?es:e}});var ns=p((ab,is)=>{"use strict";var Qu=rs();is.exports=function(r,e){return new(Qu(r))(e===0?0:e)}});var os=p(()=>{"use strict";var Xu=Oe(),Yu=ja(),Zu=Ae(),Ju=Me(),eh=Pe(),th=ns();Xu({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=Zu(this),i=Ju(t),n=th(t,0);return n.length=Yu(n,t,t,i,0,e===void 0?1:eh(e)),n}})});var as=p(()=>{"use strict";var rh=gt();rh("flat")});var ls=p((ub,ss)=>{"use strict";os();as();var ih=Ct();ss.exports=ih("Array","flat")});var ps=p((hb,cs)=>{"use strict";var nh=ls();cs.exports=nh});var hs=p((db,us)=>{"use strict";var oh=ps();us.exports=oh});var li="1.0.39-dev.6edf3cda.0";import{Subject as el,Subscription as tl}from"@vkontakte/videoplayer-shared";var Dt=class{constructor(e){this.layout=e}},Ke=class extends Dt{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * (${t.width} + ${2e-4}))`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};function ci(r){return"features"in r}var se=class{constructor(e,t){this.container=e,this.options=t,this.factories=new Map,this.controls=[],this.setControls()}featureIsEnabled(e){return this.options&&ci(this.options)&&this.options.features[e]}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 it,once as Qs}from"@vkontakte/videoplayer-shared";var Y=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Z=r=>Y(r,"Object"),Qe=r=>Y(r,"String"),Xe=r=>Y(r,"Array"),Ye=r=>Y(r,"Number"),pi=r=>Y(r,"Function"),ui=r=>Y(r,"Boolean"),Ht=r=>Ye(r)&&!isNaN(r);var te=r=>Z(r)&&Object.keys(r).length===0,Ut=r=>Xe(r)&&!r.length;var ge=(r,e)=>Qe(r)&&(e?r.trim():r).length;function Ce(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 hi="interactive",k={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},di=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(di||{}),mi=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(mi||{}),fi=(i=>(i.start="left",i.end="right",i.center="center",i))(fi||{}),Ze=({target:r,props:e})=>{r.style.alignItems=(e?.gravityVertical&&di[e.gravityVertical])??"center",r.style.justifyContent=(e?.gravityHorizontal&&mi[e.gravityHorizontal])??"center",r.style.textAlign=(e?.alignment&&fi[e.alignment])??"center"},Je=({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},et=({target:r,props:e,fallback:t})=>{r.style.backgroundColor=Ce(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},Ee=({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})`,l=n?t.roundCornersRawValue:`calc(${i.height} * ${e?.shape?.roundCorners??t.roundCorners})`;r.style.borderWidth=o,r.style.borderStyle="solid",r.style.borderColor=Ce(n?t.borderColor:e?.shape?.border?.color??t.borderColor,n?t.borderAlpha:e?.shape?.border?.alpha??t.borderAlpha),r.style.borderRadius=l},vi=({target:r,isDark:e,baseDimension:t,fallback:i})=>{let l=Ce(i.shadowColorLight,i.shadowColorAlpha),a=Ce(i.shadowColorDark,i.shadowColorAlpha),s=`calc(${t} * ${.25})`,c=`calc(${t} * ${.11})`,d=`0px 0px ${s} ${c} ${e?a:l}`;r.style.boxShadow=d},le=({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 Kt,Subject as zs,Subscription as Ws,ValueSubject as Ks}from"@vkontakte/videoplayer-shared";var Gt="interactive-control-tap",ce={common:Gt,animation:`${Gt}-animation`,visible:`${Gt}-visible`};var Us=60,tt=class{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:i=Us,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),l=i.left+i.width/2,a=i.top+i.height/2,s=e.clientX-l,c=e.clientY-a,d=Gs(s,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(ce.visible,ce.animation)};this.onAnimationEnd=e=>{!e.target||!e.currentTarget||e.target===e.currentTarget&&this.element.classList.remove(ce.visible,ce.animation)};let o=document.createElement("div");o.classList.add(ce.common),this.controlRotateAngleRad=e,this.element=o,this.clickCancelCondition=t,this.circleDiameterPx=i,this.useDimensionsBasedSize=n}};function Gs(r,e,t){return{x:r*Math.cos(t)-e*Math.sin(t),y:r*Math.sin(t)+e*Math.cos(t)}}var zt="int",re=(i=>(i.AREA=`${zt}_area`,i.TEXT=`${zt}_text`,i.BUTTON=`${zt}_bttn`,i))(re||{});function Wt(r){return"features"in r}var W="interactive-control",w={common:W,selected:`${W}-selected`,wrapper:`${W}-wrapper`,disabled:`${W}-disabled`,button:`${W}-button`,area:`${W}-area`,text:`${W}-text`,blinkAnim:`${W}-blink-anim`,blinkAnimButton:`${W}-blink-anim-button`,blinkAnimArea:`${W}-blink-anim-area`},bi=40;var V=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var J=class{constructor(e,t){this.control=e;this.options=t;this.container=null;this.controlElement=null;this.subscriptions=new Ws;this.error$=new zs;this.isInteracted$=new Ks(!1)}onError(e="",t){let i=new V(1,1,{message:e,error:t,details:{id:this.control.id}});this.error$.next(i)}addControlTap(e){if(this.featureIsEnabled("controlsTapPlace")&&this.container){let t=this.control.layoutParams.angle??k.angle;this.controlTap=new tt({controlRotateAngleRad:t,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?bi:void 0}),this.subscriptions.add(Kt(e,"click").subscribe(this.controlTap.onElementClick,i=>this.onError("Control click tap animation error",i))).add(Kt(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??k.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"},n=()=>e.isContainerDisabled?.()??!1;this.container={element:t,dimensions:i,isManifestContainerDisabled:n}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted$.next(!0),e()}}featureIsEnabled(e){return this.options&&Wt(this.options)&&this.options.features[e]}isTouch(){return this.options&&Wt(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(Kt(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 Yt="interactive-blink-anim-reference",L={common:Yt,animation:`${Yt}-animation`,disabled:`${Yt}-disabled`},rt=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(L.common,L.animation),this._element=e}restart(){this._element&&(this._element.classList.add(L.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(L.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&(cancelAnimationFrame(this._RAFId),this._RAFId=0)}destroy(){this.cleanupRAF(),this._element=void 0}};var Zt="interactive-container",F={common:Zt,hidden:`${Zt}-hidden`,disabled:`${Zt}-disabled`};var nt=(r,e)=>{if(r.type.trim().toLowerCase()==="area")return new Jt(r,e)},Jt=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.area),i.setAttribute("data-testid",re.AREA),et({target:i,props:this.control.props,fallback:{...k,backgroundColor:"transparent"}}),le({target:i,layoutParams:this.control.layoutParams,fallback:k}),this.addControlTap(i),this.container.element.append(i),e.append(this.container.element),this.controlElement=i,this.updateShadowStyles(),this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(it(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(F.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${L.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(it(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(F.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(it(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(ui(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+"px";vi({target:this.controlElement,props:this.control.props,fallback:k,isDark:e,baseDimension:t}),Ee({target:this.controlElement,props:this.control.props,fallback:{...k,borderColor:e?k.shadowColorDark:k.shadowColorLight,borderAlpha:1,borderWidthRawValue:"0.1px",roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??k.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Ee({target:this.controlElement,props:this.control.props,fallback:{...k,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(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add(it(e,"animationiteration").pipe(Qs()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.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 ct,once as Js}from"@vkontakte/videoplayer-shared";var ot=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 at=Math.PI,er=2*at,st=at/2,yi=3*st,Xs=0,Ys=[Xs,st,at,yi];function gi(r){return r===st}function Ci(r){return r===at}function Ei(r){return r===yi}function Ti(r){return(r%er+er)%er}function Zs(r){for(let e of Ys)if(r===e)return e}function xi(r){if(Zs(r))return null;let t=Math.floor(r/st)+1;return[1,2,3,4][t-1]}function Ii(r){return r*180/Math.PI}var X="interactive-control-fill-animation",N={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 lt=class r{constructor(e){this.widthExpansionCoef=0;let t=document.createElement("div");t.classList.add(N.common);let i=document.createElement("div");i.classList.add(N.fillerWrapper);let n=document.createElement("div");n.classList.add(N.filler),i.append(n),t.append(i);let o=Ti(e.rotateAngle),l=xi(o),a=l!==null,c=l===2||!a&&Ci(o)||l===3,d=!a&&gi(o),m=!a&&Ei(o),f=!c&&!d&&!m,b=d||m,R=a&&!b,E=R?o:0;t.style.borderRadius=e.borderRadius,i.style.transform=`skew(${E*-1}rad)`,b?(n.classList.add(N.fillHeight,d?N.fromTop:N.fromBottom),i.classList.add(N.fillHeight,d?N.fromTop:N.fromBottom)):(n.classList.add(N.fillWidth,f?N.fromLeft:N.fromRight),i.classList.add(N.fillWidth)),e.debug&&console.log(`[interactive ${r.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:b,rotateAngleRad:o,rotateAngelDeg:Ii(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 pt=(r,e)=>{if(r.type.trim().toLowerCase()==="button")return new tr(r,e)},tr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(w.common,w.button),i.setAttribute("data-testid",re.BUTTON),le({target:i,layoutParams:this.control.layoutParams,fallback:k}),et({target:i,props:this.control.props,fallback:k}),Ee({target:i,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),Ze({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=ot(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;Je({target:o,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),this.addControlTap(i),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled("controlsFillAnimation")&&(this.controlFillAnimation=new lt({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??k.angle,borderRadius:i.style.borderRadius})),i.append(n,this.controlFillAnimation?.fillAnimationElement??""),this.container.element.append(this.controlTap?.element??"",i),e.append(this.container.element),this.controlElement=i,this.registerEvents()}registerEvents(){if(!this.featureIsEnabled("controlsExpectTimeBlinkAnimation"))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(ct(this.controlElement,"mouseleave").subscribe(()=>{if(e.classList.contains(F.disabled))return;let t=e.parentElement;if(t){let i=t.querySelector(`.${L.common}`);i&&this.syncBlinkAnimation(i)}},t=>this.onError("Error happened in mouseleave callback",t))),this.subscriptions.add(ct(this.controlElement,"mouseenter").subscribe(()=>{e.classList.contains(F.disabled)||this.onBlinkHovering()},t=>this.onError("Error happened in mouseenter callback",t))).add(ct(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(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add(ct(e,"animationiteration").pipe(Js()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.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 Si=(r,e)=>{if(r.type.trim().toLowerCase()==="text")return new rr(r,e)},rr=class extends J{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;let i=document.createElement("div");i.classList.add(w.common,w.text),i.setAttribute("data-testid",re.TEXT),le({target:i,layoutParams:this.control.layoutParams,fallback:k}),Ze({target:i,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let n=ot(this.control.type.trim().toLowerCase()),o=n.firstElementChild??n;Je({target:o,props:this.control.props,fallback:k,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(){}onError(){}};var ut=(r,e,t)=>{if(r.type.trim().toLowerCase()==="choice")return new ir(r,e,t)},ir=class extends se{constructor(t,i,n){super(t,n);this.containerElement=null;this.controlSubscriptions=new tl;this.error$=new el;this.rootElement=i,this.layout=new Ke(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pt),this.addControlFactory("text",Si),this.addControlFactory("area",nt)}createView({eventCallback:t,videoDurationMs:i}){let n=document.createElement("div");return n.classList.add(F.common,F.disabled),requestAnimationFrame(()=>{n.classList.remove(F.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(o=>{o.setShowTimeRange(this.container.startTime,this.container.endTime??i),o.createView({parentElement:n,callbacks:{setControlLayout:this.layout.setControlLayout,isContainerDisabled:()=>this.isDisabled}}),o.setEvents(t),this.controlSubscriptions.add(o.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!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(F.hidden)}show(){let t=this.getElement();t&&t.classList.remove(F.hidden)}enable(){let t=this.getElement();t&&(t.classList.remove(F.disabled),this.controls.forEach(i=>i.enable()),this.isDisabled=!1)}disable(){let t=this.getElement();t&&(t.classList.add(F.disabled),this.controls.forEach(i=>i.disable()),this.isDisabled=!0)}removeView(){let t=this.getElement();t&&(this.controlSubscriptions.unsubscribe(),this.controls.forEach(i=>i.removeListeners()),t.remove(),this.isRemoved=!0,this.containerElement=null)}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 Ns=z(Lr(),1);import{combine as bh,InterfaceLanguage as yh,Observable as Vs,once as gh,Subject as _,Subscription as ni,ValueSubject as B,fromEvent as Ls}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ze}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as bp}from"@vkontakte/videoplayer-shared";function Ve(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var Oo="video_interactive",Po="videoint";var Mo=250,Le=class{constructor(e){this.handleZoomChange=Ve(e=>{this.lastZoomInfo=e},Mo);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,!Ye(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=yp(e),this.resizeObserver=new ResizeObserver(Ve(this.onResize,Mo)),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 bp(this.lang,Oo,Po)}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 yp(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 Fe=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 l=o.startTime-e;if(l<=n&&(o.endTime&&n<=o.endTime||o.endTime===null)){i=!0;break}n<l&&(t=t===-1?l:Math.min(t,l))}return!i&&t!==-1?t:null}}};import{isSupportedManifest as Tt,ContainerTypes as Rf,ControlTypes as xt,EventActionTypes as S,EventTypes as kf,migrateManifestToLatestVersion as No,compareVersions as Of}from"@interactiveplatform/movika-manifest";var Vo={metadata:"Object",chapters:"Array"},Lo=r=>{if(!Z(r))return!1;for(let e in Vo)if(!r[e]||!Y(r[e],Vo[e]))return!1;return Tt(r.metadata.version)},Et=r=>r.type===xt.Text,Cf=r=>r.type===xt.Button,Ef=r=>r.type===xt.Area,Tf={Choice:"Choice",TextInput:"TextInput"},xf={Button:"Button",Area:"Area",Text:"Text"},If={onClick:"onClick",onSuspense:"onSuspense"},Fo={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var It=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 St=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{pi(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=[]}};import{ValueSubject as Bp}from"@vkontakte/videoplayer-shared";var At=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return gp(...this.loaders[e])(t)}};function gp(...r){return async function(t){let i=[...r];for(;i.length>0;)t=await i.shift()(t);return t}}function Ne(r,e,t){return r?{...r,[e]:r[e]?[t,...r[e]]:[t]}:{[e]:[t]}}function wt({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 l=r.getMedia(n.media,o.videoId),a=r.getGraph(n.graph,o.id);return l?{...i,actions:r,errors:e,result:{chapter:o,media:l,graph:a}}:{...i,errors:Ne(e,wt.name,"Could not find media"),actions:r}}}}return{...i,errors:Ne(e,wt.name,"Could not find chapter"),actions:r}}var Rt=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 l=i[n];try{l.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},fe=class extends Rt{constructor(){super(),this.listeners||Rt.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)}},_e=class{constructor(){Object.defineProperty(this,"signal",{value:new fe,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document>"u")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch{i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(_e.prototype[Symbol.toStringTag]="AbortController",fe.prototype[Symbol.toStringTag]="AbortSignal");function kt(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 Fr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!kt({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 l=e;return{fetch:(s,c)=>{let d=o&&o.prototype.isPrototypeOf(s)?s.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,l(s,c)])}return l(s,c)},Request:o}}var Cp=()=>"fetch"in window,$e=Cp()&&kt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),_o=$e?Fr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Nr=$e?_o.fetch:window.fetch,Hf=$e?_o.Request:window.Request,Uf=$e?_e:window.AbortController,Gf=$e?fe:window.AbortSignal;var _r=(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 Ep=async r=>{try{let e={},t;if(Qe(r)){t=new URL(r).href;let n=await Nr(t);if(!n.ok)return{};e=await n.json()}else if(Z(r))e=r;else return{};if(!Lo(e))return{};let i=e.metadata.media;if(Qe(i)&&!("media"in e))try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let o=await Nr(n);if(!o.ok)throw new Error;e.metadata.media=await o.json()}catch{return Ip(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function $o(r){let{manifest:e,manifestURL:t}=await Ep(r);if(!e)throw new Error("Failed on fetch");let i=No(e);return i.media=Tp(i.media,t),delete i.metadata.media,i}function Ot(r,e){if(e)return r.find(t=>t.id===e)}function $r(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 jr(r,e){return r.videos.find(t=>t.id===e)}function Tp(r,e){return{...r,videos:r.videos.map(t=>({...t,variants:t.variants.map(i=>{let n="url"in i?i.url:"",o=xp(n,e);return{...i,url:o||n}})}))}}function xp(r="",e){try{return new URL(r,e).href}catch{return""}}function Ip(r){return _r(r,"3.2.0")>=0}var Qo=z(je(),1);var Pt=r=>Xe(r)&&!Ut(r),Q=r=>r.order==="end",Mt=r=>Xe(r.containers)&&!Ut(r.containers)&&Q(r),Xo=(r,e)=>{let t=r*1e3;return Pt(e.controls)&&t<(e.startTime??0)},qr=(r,e)=>{let t=r*1e3;return Pt(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var ne=(r=[])=>r.some(e=>e.action.type==="expect"),Dr=(r=[])=>r.find(e=>e.action.type==="expect"),jp=r=>r?.length===1,ve=r=>jp(r)&&Et(r[0]);function Yo(r=[],e=1/0,t=[]){return r.filter(({container:i})=>!(0,Qo.default)(t,i.container.id)&&ne(i.container.events)&&i.container.endTime===e&&!i.isRemoved)}function Vt({gameControllers:r=[],subjectName:e,subjectId:t,execFn:i}){for(let n of r)if(e==="container"&&n.container.container.id===t){i(n),Yo(r,n.container.container.endTime,[n.container.container.id]).forEach(l=>{i(l)});break}}var Zo=(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===Fo.openURI)&&g})},o=E=>E.some(({container:y})=>n(y.container,!0,!1)&&!y.isRemoved),l=E=>E.every(({container:y})=>y.isRemoved?!0:n(y.container,!0,!0)),a=Yo(e,r.endTime,[r.id]).length,s=E=>E.controls.some(y=>y.events?.some(u=>u.action?.args?.shouldOpenNow)),c=i||a>0,d=o(e),m=n(r),f=l(e),b=i?!1:a>0,R=s(r);return{isExpectTime:c,hasOtherExpect:a>0,hasOpenURIEvent:d,hasOpenURIEventInCurrentContainer:m,isAllOpenURIEventsValid:f,isExpectEventForCurrentContainer:b,hasShouldOpenNowEvent:R}};var be=class extends At{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Bp(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:Ne},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=await $o(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",wt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:$r,getChapter:Ot,getMedia:jr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ne},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=Ot(this.manifest.chapters,t);if(i){let n=jr(this.manifest.media,i.videoId),o=$r(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=Ot(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 Oa=z(Lt(),1);import{Player as mu}from"@vkontakte/videoplayer-core";import{Subscription as Wr,Tracer as fu,ValueSubject as vu}from"@vkontakte/videoplayer-shared";var Ra=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 ka=z(Lt(),1);function Gr(){let r=new Map;function e({listId:o=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let s=r.get(o),c={...a};return s?s[l]=c:r.set(o,{[l]:c}),{listId:o,itemId:l,...a}}function t(o){o.player.destroy(),o.container.remove(),o.subscription.unsubscribe(),o.statistics?.oneStat.destroy(),o.statistics?.statSubscription.unsubscribe()}function i(o,l){let a=r.get(o);if(!a)throw Error("Can't remove. Not find.");if(l){let s=a[l];s&&t(s),delete a[l],Object.keys(a).length||r.delete(o)}else{for(let s of(0,ka.default)(a))t(s);r.delete(o)}}function n(){for(let o of r)i(o[0])}return{createPlayer:e,removePlayer:i,map:r,removeAll:n}}var ye=z(je(),1);function zr(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,ye.default)(e,"mp4"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"mpeg":(n||(0,ye.default)(e,"mpeg"))&&(t.MPEG={...t.MPEG,[o.standard??"Invariant quality"]:o.url});break;case"hls":(n||(0,ye.default)(e,"hls"))&&(t={...t,HLS:{type:"url",url:o.url}});break;case"dash":(n||(0,ye.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 Be=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&(0,ye.default)(i,e)&&(r.setQuality(e),r.setAutoQuality(!1))};var bu=2;function Kr(r){let e=Gr(),t=new Wr,i={},n=null,o=!1,l,a=new vu(null);r&&s(r);function s(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 A=C.info.position$.getValue(),$=C.info.isAutoQualityEnabled$.getValue();if(!(!T||!A||$))for(let x of e.map)(0,Oa.default)(x[1]).forEach(({player:P})=>{Be(P,T)})})).add(C.events.started$.subscribe(()=>{d(u)})),g.container.remove(),n.setPlayer(g.player),o||(n.init(),o=!0),a.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(),A=!g,$=!1;for(let x of e.map)if(x[0]===u.id&&!n.state.isReplay$.getValue()){let P=Object.keys(x[1]);for(let M of P)M===i.itemId?(P.length<bu||($=!0),e.removePlayer(x[0],M)):($=!0,c(x[0],M,y),A?Be(i.player,v):i.player.setAutoQuality(!0),i.player.setVolume(C),i.player.setMuted(h),i.player.setPlaybackRate(T))}else e.removePlayer(x[0]);$||(await f({media:u,chapterId:y,setAsActive:!0,playbackRate:T}),A?Be(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:A}){let $=Math.random().toString(),x=document.createElement("div");l.append(x);let P;if(n?.options?.vkVideoLoader){let We=Ra(y);We.length&&(P=await n.options.vkVideoLoader(...We))}let M=n?.options?.coreConfig||void 0,G={...M,configName:[...M?.configName??[],"interactive"]},ee={container:x,...P?.videos?.[0]||{sources:zr(y,C).sources},title:T,failoverHosts:P?.failoverHosts||[]},j=new mu(G,fu.createRootTracer());j.initVideo(ee);let oe=null;if(P?.videos&&n?.options.createOneStat){let We=P.videos[0],qt=n.options.createOneStat(We),ai=new Wr;qt&&(ai.add(qt.attachTo(j)),oe={oneStat:qt,statSubscription:ai})}let oi=new Wr,_s=i?.player?.info.isAutoQualityEnabled$.getValue();oi.add(j.events.canplay$.subscribe(function(){_s||Be(j,i.player.info.currentQuality$.getValue()),A&&j.setPlaybackRate(A)}));let ae=e.createPlayer({listId:y.id,itemId:$,player:j,container:x,sources:zr(y,C).sources,config:ee,subscription:oi,statistics:oe});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,l.remove()}function R(){t.unsubscribe(),e.removeAll(),i={},o=!1}async function E(){if(!n)throw Error("need to set interactive controller");R(),l=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:s,createPlayer:f,removeAll:b,getActivePlayer:function(){return i},activePlayerChanged:a}}var I={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},qe={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},O={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var Ma=z(je(),1);import{Subscription as yu}from"@vkontakte/videoplayer-shared";function Qr(r){return function(...t){return r(...t.reverse())}}function De(r,...e){return(...t)=>Z(e[0])&&Z(t[0])?r({...e[0],...t[0]}):r(...e,...t)}var Ft=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:o,globalEvents:l,globalEventEmitter:a,getContainerEventState:s,permanentTextControls:c,interactiveTimeOpenUri:d,disabledControls$:m,onRemove:f,onError:b,disableTextControlContainerVisibilityEvents:R=!1}){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,l)=>{let{isExpectTime:a,hasOtherExpect:s,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=!s&&!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)(a,s,m,this.isSelectedContainerEvent);this.fakeRemoveView(y)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!a||!s||!f)&&(this.selectBranches.stopExpect(),l())}},isEOV:()=>this.gameState===4},i=De(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(),i=e instanceof HTMLVideoElement?e.readyState:void 0,n=[6,5];if(!i||(0,Ma.default)(n,this.gameState)&&!this.isPermanentText)return;let o=this.player.getExactTime();if(Xo(o,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(qr(o,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let c=this.gameState;this.gameState=3,c===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:c}=this.getContainerEventState(),d=this.selectBranches.state.isExpect,m=this.interactiveTimeOpenUri&&c;if(m&&!d){let f=this.container.getElement();f&&(f.style.visibility!=="hidden"&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!m&&this.removeView()}let l=qr(o,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:o,isInteractiveTime:l};this.container.onProgress(o*1e3,l),this.globalEventEmitter.emit(I.eachTick,s),this.globalEvents.eachTick$.next(s)};this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new yu,this.player=e,this.interactiveEvents=o,this.getContainerEventState=s;let E=ve(t.container.controls);this.isPermanentText=c&&E,this.disableTextControlContainerVisibilityEvents=R&&E,this.interactiveTimeOpenUri=d,this.disabledControls$=m,this.onRemove=f,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,this.onError=b,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.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(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()})),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(){this.container.removeView(),this.globalEventEmitter.emit(I.interactives,{subjectId:this.container.container.id,subjectName:"container",type:O.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-fake-removed",removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var Va=(r=[])=>r.reduce((e,t,i)=>{let n=(t?.controls??[]).filter(o=>!Et(o));if(Pt(n)){let o=[t.startTime??0,t.endTime??1/0],l={id:t.id,isRemoved:!1};if(!i)e.push({subjects:[l],range:o});else{let a=[],s=-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]>s&&(s=b.range[1]),o[0]>=b.range[0]&&o[1]<=b.range[1])return e[f].subjects.push(l),e;o[0]<b.range[0]&&o[1]>b.range[0]&&(a.push(f),d=d.concat(b.subjects)),o[0]>=b.range[0]&&o[0]<=b.range[1]&&(a.push(f),d=d.concat(b.subjects),o[0]=b.range[0]),o[1]>=b.range[0]&&o[1]<=b.range[1]&&(a.push(f),d=d.concat(b.subjects),o[1]=b.range[1])}if(m.push(l),o[0]<=c&&o[1]>=s)return[{subjects:m,range:o}];a.length&&a.reverse().forEach(f=>{e.splice(f,1)}),e.push({subjects:d.concat([l]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);var ms=z(je(),1),Jr=z(Lt(),1),fs=z(hs(),1);function ds(){let r={};function e(){for(let a in r)Object.prototype.hasOwnProperty.call(r,a)&&delete r[a]}function t(a){let s={};for(let c in r)+c<=a&&(s[c]=r[c]);return s}function i(a){let s={};for(let c in r)+c>=a&&(s[c]=r[c]);return s}function n({timestamp:a,priority:s,initiator:c}){if(Ht(a)){let d=r[a]??null;if(d&&s&&ge(s,!0)){let m={},f=d[s];return f&&(m={...m,...f}),m=te(m)?null:m,m&&ge(c,!0)?m[c]??null:m}return d}return null}function o({timestamp:a,priority:s,initiator:c}){if(Ht(a))if(r[a]){if(s&&ge(s,!0))if(r[a][s]){if(c&&ge(c,!0))if(r[a][s][c]){if(delete r[a][s][c],!te(r[a][s]))return!0}else return!1;if(delete r[a][s],!te(r[a]))return!0}else return!1;return delete r[a]}else return!1;return!1}function l({timestamp:a,priority:s,initiator:c,...d}){r[a]?.[s]?.[c]?r[a][s][c].push({...d}):r[a]?.[s]?r[a][s]={...r[a][s],[c]:[{...d}]}:r[a]?r[a]={...r[a],[s]:{[c]:[{...d}]}}:r[a]={[s]:{[c]:[{...d}]}}}return{map:r,remove:o,add:l,removeAll:e,get:n,getLte:t,getGte:i}}var ah=[S.expect,S.setNextBranch],sh=1/0;function vs(r,e){let t=r,i,n=lh(e),o=ds(),l,a=()=>{b(),u()},s=h=>{o.add.call(void 0,h),R()},c=(h=[])=>{for(let v of h)if(v.action(),(0,ms.default)(ah,v.actionType))break},d=(h=1/0)=>{let v=_t(o.get({timestamp:h,priority:"control"})??{}),g=_t(o.get({timestamp:h,priority:"container"})??{}),C=_t(o.get({timestamp:h,priority:"chapter"})??{});return[...v,...g,...C]},m=h=>{n.isReady(h)&&c(d(h))},f=()=>{c([..._t(o.get({timestamp:1/0,priority:"chapter"})??{})])},b=()=>{i&&(l?.unsubscribe(),i=void 0)},R=()=>{i||(i=()=>setTimeout(()=>{m(1/0)}),l=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:s,remove:y,exec:m,execEndOfVideo:f,listen:R,unlisten:b,release:a,containersEventsCallState:n,getPreparedToExecActions:d}}function lh(r){let e=new Map;return{setCalled:({timestamp:a,id:s})=>{let c=e.get(a);c&&c[s]!==void 0&&(c[s]=!0)},setData:(a=[])=>{for(let s of a){let c=s.endTime??sh,d=e.get(c);e.set(c,{...d,[s.id]:!1})}},resetCalled:a=>{let s=e.get(a);if(s)for(let c in s)s[c]=!1},isReady:a=>{let s=e.get(a);if(!s)return!0;let c=(0,Jr.default)(s);return r?c.some(m=>m):!c.some(m=>!m)},release:()=>e.clear()}}function _t(r){return(0,fs.default)((0,Jr.default)(r)).sort(e=>e.actionType===S.expect?-1:1)}var bs={videoContentHeight:0,videoContentWidth:0},ys=r=>{let{height:e,width:t}=r.info.intrinsicVideoSize$.getValue()||{};if(!(e&&t))return bs;let{clientHeight:i,clientWidth:n}=r.experimental.element$.getValue()||{};if(!(i&&n))return bs;let o=e/t,l=i/n,a,s;return l>o?(s=n,a=n*o):l<o?(s=i/o,a=i):(s=n,a=i),{videoContentWidth:s,videoContentHeight:a}};var ch=250;function gs(r){let e,t=new ResizeObserver(a=>{o(a),e=o.bind(null,a)});function i(a){let{parentElement:s,player:c}=r();if(s&&c){let{videoContentWidth:d,videoContentHeight:m}=ys(c);s.style.setProperty("--interactive-content-width",`${d}px`),s.style.setProperty("--interactive-content-height",`${m}px`),s.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),s.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function n(){let{parentElement:a}=r();a.removeAttribute("style")}let o=Ve(a=>{let{fns:s=[]}=r();i(a);for(let c of s)c()},ch);function l(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e?.()},release:l}}var ph=r=>Math.floor(Math.random()*r),Es=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},Ts=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 xs=r=>{let e=r.length,t=ph(e);return r[t]},Cs=1,Is=r=>{let e=0;for(let i=0;i<r.length;++i)e+=r[i].weight??Cs;let t=Math.random()*e;e=0;for(let i=0;i<r.length-1;++i)if(e+=r[i].weight??Cs,e>=t)return r[i];return r[r.length-1]};var Ss={shouldOpenNow:!0,isDetachContainer:!0},As="after-expect",ei=(r,e=!1)=>({...r,args:e?{...r.args,...Ss}:{...Ss,...r.args}}),ws=({globalEventEmitter:r,globalEvents:e,player:t,interactiveEvents:i})=>{let n={isExpect:!1},o=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:u,controlType:h,controlId:v,containerId:g,branches:C=[],onEvent:T,isEOV:A=()=>!1,isDisabled:$=()=>!1})=>{let x=ei(u,A()),P={timestamp:1/0,priority:"control",initiator:v,actionType:x.type},M=$(),G=r.emit.bind(r,I.interactives,{subjectId:v,subjectType:h,subjectName:"control",type:M?O.actionChoiceCanceled:O.actionChoice,actionType:u.type,payload:{invokeImmediately:x.args.shouldOpenNow,containerId:g,...x.args}}),ee=()=>{e.interactiveActionChoice$.next({subjectId:v,subjectType:h,subjectName:"control",type:M?"action-choice-canceled":"action-choice",actionType:u.type,payload:{invokeImmediately:x.args.shouldOpenNow,containerId:g,...x.args}})};if(M){G(),ee();return}switch(x.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let j=C.find(oe=>oe.id===x.args.branchId);if(!j)return;T(x.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),x.args.shouldOpenNow?E({subjectId:v,subjectName:"control",subjectType:h,action:x,payload:{chapterId:j.chapterId,autoSelect:!1}}):i.add({...P,action:E.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:x,payload:{chapterId:j.chapterId,autoSelect:!1}})});return}case S.continuePlayback.trim().toLowerCase():{T(x.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),x.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 S.openURI.trim().toLowerCase():{T(x.args.isDetachContainer,b.bind(null,{subjectId:v,subjectName:"control"})),G(),ee(),x.args.shouldOpenNow?y({subjectId:v,subjectName:"control",subjectType:h,action:x,payload:{URI:u.args.uri}}):i.add({...P,action:y.bind(null,{subjectId:v,subjectName:"control",subjectType:h,action:x,payload:{URI:u.args.uri}})});return}default:{let j="Unexpected control event",oe=new V(1,1,{message:j});d(oe,j);return}}},a=({action:u,container:{id:h,endTime:v},branches:g=[],isEOV:C=!1,autoSelected:T=!1})=>{let A=ei(u,C),$={timestamp:!A.args.shouldOpenNow||C?1/0:v??1/0,priority:"container",initiator:h,actionType:A.type},x=r.emit.bind(r,I.interactives,{subjectId:h,subjectName:"container",type:O.actionChoice,actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}}),P=()=>{e.interactiveActionChoice$.next({subjectId:h,subjectName:"container",type:"action-choice",actionType:A.type,payload:{invokeImmediately:A.args.shouldOpenNow,...A.args}})};switch(A.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let M=g.find(G=>G.id===A.args.branchId);if(!M)return;x(),P(),i.add({...$,action:E.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{chapterId:M.chapterId,autoSelect:T}})});return}case S.setMaxWeightBranch.trim().toLowerCase():return;case S.setMinWeightBranch.trim().toLowerCase():return;case S.setRandomBranch.trim().toLowerCase():return;case S.setWeightlessRandomBranch.trim().toLowerCase():return;case S.continuePlayback.trim().toLowerCase():{x(),P(),i.add({...$,action:R.bind(null,{subjectId:h,subjectName:"container",action:A})});return}case S.openURI.trim().toLowerCase():{x(),P(),i.add({...$,action:y.bind(null,{subjectId:h,subjectName:"container",action:A,payload:{URI:u.args.uri}})});return}default:{let M="Unexpected container event",G=new V(1,1,{message:M});d(G,M);return}}};function s({container:u,branches:h,isEOV:v=!1}){let g=Dr(u.events);if(g){let C=ei(g.action,v);r.emit(I.interactives,{subjectId:u.id,subjectName:"container",type:O.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:S.expect,action:f.bind(null,{subjectId:u.id,subjectName:"container"})}),n.isExpect=!0}else for(let C of u.events??[])a({action:C.action,container:u,branches:h,isEOV:v})}let c=({chapterId:u,action:h,branches:v=[]})=>{let g=r.emit.bind(r,I.interactives,{subjectId:u,subjectName:"chapter",type:O.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 S.setNextBranch.trim().toLowerCase():{let T=v.find(A=>A.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 S.setWeightlessRandomBranch.trim().toLowerCase():{let T=xs(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.setRandomBranch.trim().toLowerCase():{let T=Is(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.setMaxWeightBranch.trim().toLowerCase():{let T=Ts(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.setMinWeightBranch.trim().toLowerCase():{let T=Es(v);return T?.chapterId?(g(),C(),E.bind(null,{subjectId:u,subjectName:"chapter",action:h,payload:{chapterId:T.chapterId,autoSelect:!0}})):void 0}case S.continuePlayback.trim().toLowerCase():return g(),C(),R.bind(null,{subjectId:u,subjectName:"chapter",action:h});case S.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",A=new V(1,1,{message:T});d(A,T);return}}};function d(u,h){console.error(h),e.error$.next(u),r.emit(I.errors,u)}function m(u){let h=Dr(u.events);if(h){if(Q(u))return;r.emit(I.interactives,{subjectId:u.id,subjectName:"chapter",type:O.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:S.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(I.interactives,{subjectId:u,subjectName:h,type:O.actionExecution,actionType:S.expect}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:S.expect})},b=({subjectId:u,subjectName:h})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),r.emit(I.interactives,{subjectId:u,subjectName:h,type:O.actionExecution,actionType:As}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,type:"action-execution",actionType:As})},R=({subjectId:u,subjectName:h,subjectType:v,action:g})=>{r.emit(I.interactives,{subjectId:u,subjectName:h,subjectType:v,type:O.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(I.interactives,{subjectId:u,subjectName:h,subjectType:v,type:O.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(I.interactives,{subjectId:u,subjectName:h,subjectType:v,type:O.actionExecution,actionType:g.type}),e.interactiveActionExecution$.next({subjectId:u,subjectName:h,subjectType:v,type:"action-execution",actionType:g.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:c,onExpectEvent:f,expectEventHandler:b,setManifestChapterEvents:m,setManifestContainerEvents:s,stopExpect:o,state:n}};var ii=z(Lr(),1);import{Subscription as fh,Subject as ri,ValueSubject as Ue}from"@vkontakte/videoplayer-shared";var ti=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(l=>l.id===i);if(!n)return null;let o=e.media.videos.find(l=>n.videoId===l.id);if(!o)return null;t[i]=Rs(o)}return t[i]}).filter(Boolean)},hh=r=>{for(let e of r.variants)if(dh(e)&&e.payload)return e.payload.id},dh=r=>!!(r.type==="custom"&&r.payload&&r.payload.type==="vk"),Rs=r=>{let e=hh(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},mh=(r,e)=>{for(let t of r.media.videos)if(e===Rs(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},ks=(r,e)=>r.reduce((t,i)=>{let n=mh(e,i);return n?[...t,n]:t},[]);var Ge=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:o}){this.state={history$:new Ue([]),hasPrevChapter$:new Ue(!1),prevChapter$:new Ue(null),isInitialChapter$:new Ue(!1),isGoBackLimited$:new Ue(!1)};this.#r=null;this.#a=!1;this.#e=null;this.#p=null;this.events={inited$:new ri,destroyed$:new ri,error$:new ri};this.#i=null;this.#n=null;this.#t=null;this.#s=new fh;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.#s&&this.#s?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,ii.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#o.maxLength-1)}))}#r;#o;#a;#e;#p;#i;#n;#t;#s;#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.#a||(this.#a=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#a}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,l=ti(o,i);if(this.#p=l,this.state.history$.next(o),!(!t||!this.#r||!this.#i))try{await this.#r.save(this.#i,l)}catch{let s=new V(1,5,"Unable to save interactive history");this.events.error$.next(s),this.#t?.emit(I.errors,s)}}async goBack(){if(!this.state||!this.#n){let i=new V(1,5,"Unable to save interactive history");return this.events.error$.next(i),this.#t?.emit(I.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 V(1,5,"Error while trying to fetch data");this.events.error$.next(o),this.#t?.emit(I.errors,o)}let i=ks(t,e);this.state.history$.next(i)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,ii.default)(e,-1)||this.#o.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return ti([e],this.#e).pop()}return null}destroy(){this.#i=null,this.#r=null,this.#n=null,this.#s?.unsubscribe(),this.#s=null,this.#a=!1,this.#t?.emit(I.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var $t=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 jt=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;
|
|
@@ -251,4 +251,4 @@ var $s=Object.create;var si=Object.defineProperty;var js=Object.getOwnPropertyDe
|
|
|
251
251
|
.interactive-control-fill-animation-filler.interactive-control-fill-animation-from-bottom {
|
|
252
252
|
transform-origin: bottom;
|
|
253
253
|
}
|
|
254
|
-
`;var Ms=r=>{let e=document.createElement("style");e.textContent=Ps,r.prepend(e)};import{clientChecker as Ch}from"@vkontakte/videoplayer-core";var Vs=Object.freeze({lang:yh.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4},isTouch:!1,animationsFeatureToggles:{areaControlShadow:!1,controlsExpectTimeBlinkAnimation:!1,controlsTapPlace:!1,controlsFillAnimation:!1}});function Eh(){let r=document.createElement("div");return r.classList.add("interactive-chapter"),r}var Bt=class{constructor(e){this.playerSubscriptions=new ni;this.subscriptions=new ni;this.globalEventEmitter=new xt;this.animation=new St;this.seekToInteractiveController=new Ve;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Eh();this.factories=new Map([["choice",ut]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new ni;this.graph=null;this.lastFrame=null;this.blinkAnimationRef=null;this.appState=0;this.state={prevChapter$:new B(null),isInitialChapter$:new B(!1),isFirstChapter$:new B(!0),isEndChapter$:new B(!1),isInteractiveExpectation$:new B(!1),isReplay$:new B(!1),calledByInteractive$:new B(!1),lastChapterChangeWasInitiatedByInteractive$:new B(!1),disabledControls$:new B(!1),interactiveRanges$:new B([]),isInteractiveTime$:new B(!1),statistics$:new B(null),isSeekable$:new B(!1)};this.events={noInteraction$:new _,graphVisibilityChanged$:new _,watchAgainIsClicked$:new _,chapterChanged$:new _,playerChanged$:new _,error$:new _,eachTick$:new _,manifestChanged$:new _,interactiveRangeEnded$:new _,interactiveContainerRemoved$:new _,interactiveContainerFakeRemoved$:new _,interactiveActionExecution$:new _,interactiveActionChoice$:new _,interactiveVisibilityChanged$:new _};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(x.errors,e)};this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:i}=this.getCurrentChapter();e&&i&&Q(i)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...i}=e;if(t){let{statSubscription:n,oneStat:o}=t;n.add(o.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(i),this.globalEventEmitter.emit(x.playerChanged,i)};this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(t=>{!e&&t.isPermanentText||(this.animation.removeFn(t.whilePlaying),t.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(o=>({...o,subjects:o.subjects.filter(l=>l.id!==e)}));t.next(n)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};if(this._options={...Vs,...e,config:{...Vs.config,...e.config}},this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation){this.blinkAnimationRef=new rt,this.blinkAnimationRef.create();let n=this.blinkAnimationRef.element;n&&this.rootElement.append(n)}this._options.parentElement.append(this.rootElement),this.historyController=new Ge({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new jt({parentElement:this._options.parentElement,onError:n=>{let o=new L(1,6,n);this.emitErrorEvent(o)}})),Ms(this._options.parentElement),this.subscriptions.add(Fs(this.rootElement,"mousedown").subscribe(n=>n.stopPropagation())).add(Fs(this.rootElement,"mouseup").subscribe(n=>n.stopPropagation())),this.manifestController=new be(this._options.loaders,n=>{let o=new L(1,3,n);this.emitErrorEvent(o)});let i=[];this._options.lastFrame&&i.push(()=>{this.lastFrame?.updateCanvasDimensions(!0)}),i.push(()=>{let n=this.state.isInteractiveTime$.getValue();for(let o of this.gameControllers)o.onResize(n)}),this.resizeManager=gs(()=>({player:this.player,parentElement:this._options.parentElement,fns:i})),this._options.graph&&(this.graph=new Fe({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),this.globalEventEmitter.emit(x.graph,{type:qe.watchAgainClicked,chapterId:n}),this.events.watchAgainIsClicked$.next(n)},onError:n=>{let o=new L(1,2,{message:n});this.emitErrorEvent(o)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour==="change-chapter"){let{chapterId:t}=e.payload;this.setChapter({chapterId:t}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(e.payload?.behaviour==="change-manifest"){let{manifestURL:t}=e.payload;t&&this.setManifest(t)}e.actionType==="expect"?(this.state.isInteractiveExpectation$.next(!0),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0})):e.actionType==="after-expect"&&(this.state.isInteractiveExpectation$.next(!1),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}))})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:i})=>{e!=="action-choice"||t==="chapter"||"invokeImmediately"in i&&i.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=Kr(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,n=this.getInteractiveRanges().reverse().find(({range:o})=>t>=o[1]);if(n){let o=n.range.join("-");this.endedRanges.has(o)||(this.endedRanges.add(o),this.globalEventEmitter.emit(x.interactives,{type:O.rangeEnded,payload:n,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:n}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(gh()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(bh({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:i})=>{let n;if(i)n=!0;else{let s=e*1e3;n=!!t.find(({range:[d,m],subjects:f})=>d<s&&s<m&&f.some(b=>!b.isRemoved)&&f.length)}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let o=!!this.noInteractionTimeout,a=this.player?.info.playbackState$.getValue()==="playing"||i;n&&!o&&a?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):o&&!a&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(t=>t.container.container).filter(t=>!ve(t.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(i=>{let n=i.type.trim().toLowerCase(),l=this.factories.get(n)?.(i,this.rootElement,{isTouch:this._options?.isTouch??!1,features:{controlsExpectTimeBlinkAnimation:this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation,controlsTapPlace:this._options.animationsFeatureToggles?.controlsTapPlace,controlsFillAnimation:this._options.animationsFeatureToggles?.controlsFillAnimation}});if(l&&this.selectBranches&&this.interactiveEvents&&this.player){let a=new Vt({player:this.player,container:l,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>Zo(i,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(i.id)},onError:this.emitErrorEvent});this.animation.addFn(a.whilePlaying,!0),t.push(a)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),i=!!this.seekToInteractiveController.getNextInteractiveTime();(i&&!t||!i&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),i=this.state.prevChapter$.getValue(),n=(i&&Q(i)&&Mt(i))??!1,o=this.manifestController.manifest?.metadata.initChapterId===e,l=this.historyController.state.history$.getValue();if(o||n&&t){this.historyController.updateHistory([e]);return}(0,Ns.default)(l,-1)!==e&&this.historyController.updateHistory([...l,e])}handleFakeRemoval(e,t){let{interactiveRanges$:i}=this.state,o=i.getValue().map(l=>{let a=l.subjects.some(c=>c.id===e),s=l.subjects.map(c=>t&&a||c.id===e?{...c,isRemoved:!0}:c);return{...l,subjects:s}});i.next(o)}reset(){this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}toggleBlinkAnimation(e){if(!this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation)return;let t=(i,n)=>{i.toggleBlinkAnimation(n)};Lt({...e,gameControllers:this.gameControllers,execFn:De(Qr(t),e.isExpect)}),e.isExpect&&this.blinkAnimationRef?.restart()}updateControlsShadowStyles(e){if(!this._options.animationsFeatureToggles?.areaControlShadow)return;let t=(i,n)=>{i.updateControlsShadowStyles(n)};e.isExpect?Lt({...e,gameControllers:this.gameControllers,execFn:De(Qr(t),!1)}):Lt({...e,gameControllers:this.gameControllers,execFn:t})}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.events.manifestChanged$.next(t.manifest),this.globalEventEmitter.emit(x.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=vs(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=ws({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:i=!1}={}){this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&Ch.browser.isSafari&&await Os(35);let n=!i&&this.state.isEndChapter$.getValue()&&this.getCurrentManifest()?.metadata.initChapterId===e;this.state.isReplay$.next(n);let{chapter:o,media:l,graph:a}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||n)&&this.state.isFirstChapter$.next(!0),!(!o||!l)&&(t&&this.pushChapterToHistory(o.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(o),this.lastFrame?.setCurrentChapter(o),this.events.chapterChanged$.next({chapter:o,manifestVideo:l}),this.globalEventEmitter.emit(x.chapterChanged,{chapter:o,media:l,graph:a}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new Ls(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?ze.GRAPH_SHOW:ze.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(ze.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:i,subjectType:n})=>{t!=="action-choice"||i!=="control"||(n==="Button"&&e.next(ze.NEXT_BUTTON),n==="Area"&&e.next(ze.NEXT_AREA))}))}),nextMovie$:new Ls(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(x.graph,{type:qe.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(i=>i.actionType===S.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(t=>!t.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(i=>{let n=i.container.container;return!i.container.isRemoved&&n.endTime===null&&ne(n.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&Tt(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return La(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){this.clearHistoryIfEnded(),this.blinkAnimationRef?.destroy(),this.destroyGameControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Th={Container:se,createChoiceContainer:ut,createAreaControl:nt,createButtonControl:pt,classnamesPrefix:hi};var Ry={version:li};export{Rf as ContainerTypes,It as ControlTypes,L as CustomError,x as EVENT_NAMES,S as EventActionTypes,kf as EventTypes,Bt as Interactives,be as ManifestController,Ry as SDKInfo,ti as chapterIdsToVKVideoIds,_r as compareVersions,Tf as containerTypes,If as controlTypes,Vo as eventActionTypes,xf as eventTypes,mh as getChapterIdByVkVideoId,Rs as getVKVideoIdByMedia,hh as getVideoRawIdByMedia,qe as graphEventTypes,Mt as hasEndTemplate,O as interactivesEventTypes,Ef as isAreaControl,Cf as isButtonControl,Q as isLastChapter,ve as isOneTextCtrlContainer,Tt as isSupportedManifest,Et as isTextControl,dh as isVKVariantItem,Fo as isValidManifest,No as migrateManifestToLatestVersion,Th as utils,ks as vkVideoIdsToChapterIds};
|
|
254
|
+
`;var Ms=r=>{let e=document.createElement("style");e.textContent=Ps,r.prepend(e)};import{clientChecker as Ch}from"@vkontakte/videoplayer-core";var Fs=Object.freeze({lang:yh.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4},isTouch:!1,disableTextControlContainerVisibilityEvents:!1,animationsFeatureToggles:{areaControlShadow:!1,controlsExpectTimeBlinkAnimation:!1,controlsTapPlace:!1,controlsFillAnimation:!1}});function Eh(){let r=document.createElement("div");return r.classList.add("interactive-chapter"),r}var Bt=class{constructor(e){this.playerSubscriptions=new ni;this.subscriptions=new ni;this.globalEventEmitter=new It;this.animation=new St;this.seekToInteractiveController=new Fe;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Eh();this.factories=new Map([["choice",ut]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new ni;this.graph=null;this.lastFrame=null;this.blinkAnimationRef=null;this.appState=0;this.state={prevChapter$:new B(null),isInitialChapter$:new B(!1),isFirstChapter$:new B(!0),isEndChapter$:new B(!1),isInteractiveExpectation$:new B(!1),isReplay$:new B(!1),calledByInteractive$:new B(!1),lastChapterChangeWasInitiatedByInteractive$:new B(!1),disabledControls$:new B(!1),interactiveRanges$:new B([]),isInteractiveTime$:new B(!1),statistics$:new B(null),isSeekable$:new B(!1)};this.events={noInteraction$:new _,graphVisibilityChanged$:new _,watchAgainIsClicked$:new _,chapterChanged$:new _,playerChanged$:new _,error$:new _,eachTick$:new _,manifestChanged$:new _,interactiveRangeEnded$:new _,interactiveContainerRemoved$:new _,interactiveContainerFakeRemoved$:new _,interactiveActionExecution$:new _,interactiveActionChoice$:new _,interactiveVisibilityChanged$:new _};this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(I.errors,e)};this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:i}=this.getCurrentChapter();e&&i&&Q(i)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...i}=e;if(t){let{statSubscription:n,oneStat:o}=t;n.add(o.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(i),this.globalEventEmitter.emit(I.playerChanged,i)};this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()};this.destroyGameControllers=(e=!0)=>{this.gameControllers.forEach(t=>{!e&&t.isPermanentText||(this.animation.removeFn(t.whilePlaying),t.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(o=>({...o,subjects:o.subjects.filter(l=>l.id!==e)}));t.next(n)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};if(this._options={...Fs,...e,config:{...Fs.config,...e.config}},this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation){this.blinkAnimationRef=new rt,this.blinkAnimationRef.create();let n=this.blinkAnimationRef.element;n&&this.rootElement.append(n)}this._options.parentElement.append(this.rootElement),this.historyController=new Ge({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new jt({parentElement:this._options.parentElement,onError:n=>{let o=new V(1,6,n);this.emitErrorEvent(o)}})),Ms(this._options.parentElement),this.subscriptions.add(Ls(this.rootElement,"mousedown").subscribe(n=>n.stopPropagation())).add(Ls(this.rootElement,"mouseup").subscribe(n=>n.stopPropagation())),this.manifestController=new be(this._options.loaders,n=>{let o=new V(1,3,n);this.emitErrorEvent(o)});let i=[];this._options.lastFrame&&i.push(()=>{this.lastFrame?.updateCanvasDimensions(!0)}),i.push(()=>{let n=this.state.isInteractiveTime$.getValue();for(let o of this.gameControllers)o.onResize(n)}),this.resizeManager=gs(()=>({player:this.player,parentElement:this._options.parentElement,fns:i})),this._options.graph&&(this.graph=new Le({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),this.globalEventEmitter.emit(I.graph,{type:qe.watchAgainClicked,chapterId:n}),this.events.watchAgainIsClicked$.next(n)},onError:n=>{let o=new V(1,2,{message:n});this.emitErrorEvent(o)}})),this.initSubscriptions()}initSubscriptions(){this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))})),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour==="change-chapter"){let{chapterId:t}=e.payload;this.setChapter({chapterId:t}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(e.payload?.behaviour==="change-manifest"){let{manifestURL:t}=e.payload;t&&this.setManifest(t)}e.actionType==="expect"?(this.state.isInteractiveExpectation$.next(!0),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0})):e.actionType==="after-expect"&&(this.state.isInteractiveExpectation$.next(!1),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}))})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:i})=>{e!=="action-choice"||t==="chapter"||"invokeImmediately"in i&&i.invokeImmediately||this.destroyGameControllers(!1)}))}async initSeamless(){this.seamlessController=Kr(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,n=this.getInteractiveRanges().reverse().find(({range:o})=>t>=o[1]);if(n){let o=n.range.join("-");this.endedRanges.has(o)||(this.endedRanges.add(o),this.globalEventEmitter.emit(I.interactives,{type:O.rangeEnded,payload:n,visibility:!0}),this.events.interactiveRangeEnded$.next({type:"range-ended",payload:n}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(gh()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(bh({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:i})=>{let n;if(i)n=!0;else{let s=e*1e3;n=!!t.find(({range:[d,m],subjects:f})=>d<s&&s<m&&f.some(b=>!b.isRemoved)&&f.length)}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let o=!!this.noInteractionTimeout,a=this.player?.info.playbackState$.getValue()==="playing"||i;n&&!o&&a?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):o&&!a&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(t=>t.container.container).filter(t=>!ve(t.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(i=>{let n=i.type.trim().toLowerCase(),l=this.factories.get(n)?.(i,this.rootElement,{isTouch:this._options?.isTouch??!1,features:{controlsExpectTimeBlinkAnimation:this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation,controlsTapPlace:this._options.animationsFeatureToggles?.controlsTapPlace,controlsFillAnimation:this._options.animationsFeatureToggles?.controlsFillAnimation}});if(l&&this.selectBranches&&this.interactiveEvents&&this.player){let a=new Ft({player:this.player,container:l,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>Zo(i,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(i.id)},onError:this.emitErrorEvent,disableTextControlContainerVisibilityEvents:this.options.disableTextControlContainerVisibilityEvents??!1});this.animation.addFn(a.whilePlaying,!0),t.push(a)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),i=!!this.seekToInteractiveController.getNextInteractiveTime();(i&&!t||!i&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),i=this.state.prevChapter$.getValue(),n=(i&&Q(i)&&Mt(i))??!1,o=this.manifestController.manifest?.metadata.initChapterId===e,l=this.historyController.state.history$.getValue();if(o||n&&t){this.historyController.updateHistory([e]);return}(0,Ns.default)(l,-1)!==e&&this.historyController.updateHistory([...l,e])}handleFakeRemoval(e,t){let{interactiveRanges$:i}=this.state,o=i.getValue().map(l=>{let a=l.subjects.some(c=>c.id===e),s=l.subjects.map(c=>t&&a||c.id===e?{...c,isRemoved:!0}:c);return{...l,subjects:s}});i.next(o)}reset(){this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}toggleBlinkAnimation(e){if(!this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation)return;let t=(i,n)=>{i.toggleBlinkAnimation(n)};Vt({...e,gameControllers:this.gameControllers,execFn:De(Qr(t),e.isExpect)}),e.isExpect&&this.blinkAnimationRef?.restart()}updateControlsShadowStyles(e){if(!this._options.animationsFeatureToggles?.areaControlShadow)return;let t=(i,n)=>{i.updateControlsShadowStyles(n)};e.isExpect?Vt({...e,gameControllers:this.gameControllers,execFn:De(Qr(t),!1)}):Vt({...e,gameControllers:this.gameControllers,execFn:t})}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.events.manifestChanged$.next(t.manifest),this.globalEventEmitter.emit(I.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=vs(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=ws({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:i=!1}={}){this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),this.lastFrame&&Ch.browser.isSafari&&await Os(35);let n=!i&&this.state.isEndChapter$.getValue()&&this.getCurrentManifest()?.metadata.initChapterId===e;this.state.isReplay$.next(n);let{chapter:o,media:l,graph:a}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||n)&&this.state.isFirstChapter$.next(!0),!(!o||!l)&&(t&&this.pushChapterToHistory(o.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(o),this.lastFrame?.setCurrentChapter(o),this.events.chapterChanged$.next({chapter:o,manifestVideo:l}),this.globalEventEmitter.emit(I.chapterChanged,{chapter:o,media:l,graph:a}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new Vs(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?ze.GRAPH_SHOW:ze.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(ze.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:i,subjectType:n})=>{t!=="action-choice"||i!=="control"||(n==="Button"&&e.next(ze.NEXT_BUTTON),n==="Area"&&e.next(ze.NEXT_AREA))}))}),nextMovie$:new Vs(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}async toggleGraphView(e=!0){this.graph&&(e?(await this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(I.graph,{type:qe.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(i=>i.actionType===S.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(t=>!t.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(i=>{let n=i.container.container;return!i.container.isRemoved&&n.endTime===null&&ne(n.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&Tt(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return Va(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){this.clearHistoryIfEnded(),this.blinkAnimationRef?.destroy(),this.destroyGameControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Th={Container:se,createChoiceContainer:ut,createAreaControl:nt,createButtonControl:pt,classnamesPrefix:hi};var Ry={version:li};export{Rf as ContainerTypes,xt as ControlTypes,V as CustomError,I as EVENT_NAMES,S as EventActionTypes,kf as EventTypes,Bt as Interactives,be as ManifestController,Ry as SDKInfo,ti as chapterIdsToVKVideoIds,_r as compareVersions,Tf as containerTypes,xf as controlTypes,Fo as eventActionTypes,If as eventTypes,mh as getChapterIdByVkVideoId,Rs as getVKVideoIdByMedia,hh as getVideoRawIdByMedia,qe as graphEventTypes,Mt as hasEndTemplate,O as interactivesEventTypes,Ef as isAreaControl,Cf as isButtonControl,Q as isLastChapter,ve as isOneTextCtrlContainer,Tt as isSupportedManifest,Et as isTextControl,dh as isVKVariantItem,Lo as isValidManifest,No as migrateManifestToLatestVersion,Th as utils,ks as vkVideoIdsToChapterIds};
|