@vkontakte/videoplayer-interactive 1.0.16-dev.4720172e.0 → 1.0.16-dev.4f41c335.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 +6 -6
- package/es2015.esm.js +6 -6
- package/es2018.cjs.js +6 -6
- package/es2018.esm.js +6 -6
- package/esnext.cjs.js +6 -6
- package/esnext.esm.js +6 -6
- package/evergreen.esm.js +5 -5
- package/package.json +4 -3
- package/types/index.d.ts +1 -1
- package/types/modules/Interactives/Interactives.d.ts +1 -1
- package/types/modules/ManifestController/ManifestController.d.ts +29 -29
- package/types/modules/ManifestController/utils.d.ts +12 -15
- package/types/modules/SeamlessController/InstanceManager.d.ts +7 -1
- package/types/modules/SeamlessController/SeamlessController.d.ts +2 -10
- package/types/movika.core/manifest/index.d.ts +6 -2
- package/types/movika.core/manifest/types.d.ts +0 -7
package/es2015.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.16-dev.
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.16-dev.4f41c335.0
|
|
3
|
+
* Wed, 04 Sep 2024 09:12:43 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-16/doc/
|
|
5
5
|
*/
|
|
6
|
-
var Va=Object.create;var ii=Object.defineProperty,Ra=Object.defineProperties,Aa=Object.getOwnPropertyDescriptor,Ma=Object.getOwnPropertyDescriptors,Oa=Object.getOwnPropertyNames,mt=Object.getOwnPropertySymbols,La=Object.getPrototypeOf,ri=Object.prototype.hasOwnProperty,vr=Object.prototype.propertyIsEnumerable;var gr=i=>{throw TypeError(i)};var ti=(i,e,t)=>e in i?ii(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,p=(i,e)=>{for(var t in e||(e={}))ri.call(e,t)&&ti(i,t,e[t]);if(mt)for(var t of mt(e))vr.call(e,t)&&ti(i,t,e[t]);return i},C=(i,e)=>Ra(i,Ma(e));var Q=(i,e)=>{var t={};for(var r in i)ri.call(i,r)&&e.indexOf(r)<0&&(t[r]=i[r]);if(i!=null&&mt)for(var r of mt(i))e.indexOf(r)<0&&vr.call(i,r)&&(t[r]=i[r]);return t};var f=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var Na=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Oa(e))!ri.call(i,n)&&n!==t&&ii(i,n,{get:()=>e[n],enumerable:!(r=Aa(e,n))||r.enumerable});return i};var ja=(i,e,t)=>(t=i!=null?Va(La(i)):{},Na(e||!i||!i.__esModule?ii(t,"default",{value:i,enumerable:!0}):t,i));var ee=(i,e,t)=>ti(i,typeof e!="symbol"?e+"":e,t),ni=(i,e,t)=>e.has(i)||gr("Cannot "+t);var a=(i,e,t)=>(ni(i,e,"read from private field"),t?t.call(i):e.get(i)),w=(i,e,t)=>e.has(i)?gr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),b=(i,e,t,r)=>(ni(i,e,"write to private field"),r?r.call(i,t):e.set(i,t),t),F=(i,e,t)=>(ni(i,e,"access private method"),t);var br=(i,e,t,r)=>({set _(n){b(i,e,n,t)},get _(){return a(i,e,r)}});var R=(i,e,t)=>new Promise((r,n)=>{var s=c=>{try{o(t.next(c))}catch(h){n(h)}},l=c=>{try{o(t.throw(c))}catch(h){n(h)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(s,l);o((t=t.apply(i,e)).next())});var se=f((wi,rn)=>{"use strict";var st=function(i){return i&&i.Math===Math&&i};rn.exports=st(typeof globalThis=="object"&&globalThis)||st(typeof window=="object"&&window)||st(typeof self=="object"&&self)||st(typeof global=="object"&&global)||st(typeof wi=="object"&&wi)||function(){return this}()||Function("return this")()});var be=f((Ap,nn)=>{"use strict";nn.exports=function(i){try{return!!i()}catch(e){return!0}}});var at=f((Mp,sn)=>{"use strict";var po=be();sn.exports=!po(function(){var i=function(){}.bind();return typeof i!="function"||i.hasOwnProperty("prototype")})});var hn=f((Op,ln)=>{"use strict";var fo=at(),cn=Function.prototype,an=cn.apply,on=cn.call;ln.exports=typeof Reflect=="object"&&Reflect.apply||(fo?on.bind(an):function(){return on.apply(an,arguments)})});var Re=f((Lp,dn)=>{"use strict";var un=at(),pn=Function.prototype,_i=pn.call,mo=un&&pn.bind.bind(_i,_i);dn.exports=un?mo:function(i){return function(){return _i.apply(i,arguments)}}});var Vi=f((Np,mn)=>{"use strict";var fn=Re(),yo=fn({}.toString),vo=fn("".slice);mn.exports=function(i){return vo(yo(i),8,-1)}});var Ri=f((jp,yn)=>{"use strict";var go=Vi(),bo=Re();yn.exports=function(i){if(go(i)==="Function")return bo(i)}});var Ee=f((Pp,vn)=>{"use strict";var Ai=typeof document=="object"&&document.all;vn.exports=typeof Ai=="undefined"&&Ai!==void 0?function(i){return typeof i=="function"||i===Ai}:function(i){return typeof i=="function"}});var qe=f((kp,gn)=>{"use strict";var Eo=be();gn.exports=!Eo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Dt=f(($p,bn)=>{"use strict";var Co=at(),qt=Function.prototype.call;bn.exports=Co?qt.bind(qt):function(){return qt.apply(qt,arguments)}});var In=f(xn=>{"use strict";var En={}.propertyIsEnumerable,Cn=Object.getOwnPropertyDescriptor,xo=Cn&&!En.call({1:2},1);xn.f=xo?function(e){var t=Cn(this,e);return!!t&&t.enumerable}:En});var Mi=f((Bp,Tn)=>{"use strict";Tn.exports=function(i,e){return{enumerable:!(i&1),configurable:!(i&2),writable:!(i&4),value:e}}});var wn=f((qp,Sn)=>{"use strict";var Io=Re(),To=be(),So=Vi(),Oi=Object,wo=Io("".split);Sn.exports=To(function(){return!Oi("z").propertyIsEnumerable(0)})?function(i){return So(i)==="String"?wo(i,""):Oi(i)}:Oi});var Li=f((Dp,_n)=>{"use strict";_n.exports=function(i){return i==null}});var Ni=f((Hp,Vn)=>{"use strict";var _o=Li(),Vo=TypeError;Vn.exports=function(i){if(_o(i))throw new Vo("Can't call method on "+i);return i}});var An=f((Gp,Rn)=>{"use strict";var Ro=wn(),Ao=Ni();Rn.exports=function(i){return Ro(Ao(i))}});var ot=f((Up,Mn)=>{"use strict";var Mo=Ee();Mn.exports=function(i){return typeof i=="object"?i!==null:Mo(i)}});var ji=f((zp,On)=>{"use strict";On.exports={}});var $i=f((Wp,Nn)=>{"use strict";var Pi=ji(),ki=se(),Oo=Ee(),Ln=function(i){return Oo(i)?i:void 0};Nn.exports=function(i,e){return arguments.length<2?Ln(Pi[i])||Ln(ki[i]):Pi[i]&&Pi[i][e]||ki[i]&&ki[i][e]}});var Pn=f((Kp,jn)=>{"use strict";var Lo=Re();jn.exports=Lo({}.isPrototypeOf)});var Bn=f((Qp,Fn)=>{"use strict";var No=se(),kn=No.navigator,$n=kn&&kn.userAgent;Fn.exports=$n?String($n):""});var Wn=f((Yp,zn)=>{"use strict";var Un=se(),Fi=Bn(),qn=Un.process,Dn=Un.Deno,Hn=qn&&qn.versions||Dn&&Dn.version,Gn=Hn&&Hn.v8,re,Ht;Gn&&(re=Gn.split("."),Ht=re[0]>0&&re[0]<4?1:+(re[0]+re[1]));!Ht&&Fi&&(re=Fi.match(/Edge\/(\d+)/),(!re||re[1]>=74)&&(re=Fi.match(/Chrome\/(\d+)/),re&&(Ht=+re[1])));zn.exports=Ht});var Bi=f((Xp,Qn)=>{"use strict";var Kn=Wn(),jo=be(),Po=se(),ko=Po.String;Qn.exports=!!Object.getOwnPropertySymbols&&!jo(function(){var i=Symbol("symbol detection");return!ko(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&Kn&&Kn<41})});var qi=f((Zp,Yn)=>{"use strict";var $o=Bi();Yn.exports=$o&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Di=f((Jp,Xn)=>{"use strict";var Fo=$i(),Bo=Ee(),qo=Pn(),Do=qi(),Ho=Object;Xn.exports=Do?function(i){return typeof i=="symbol"}:function(i){var e=Fo("Symbol");return Bo(e)&&qo(e.prototype,Ho(i))}});var Jn=f((ed,Zn)=>{"use strict";var Go=String;Zn.exports=function(i){try{return Go(i)}catch(e){return"Object"}}});var Hi=f((td,es)=>{"use strict";var Uo=Ee(),zo=Jn(),Wo=TypeError;es.exports=function(i){if(Uo(i))return i;throw new Wo(zo(i)+" is not a function")}});var is=f((id,ts)=>{"use strict";var Ko=Hi(),Qo=Li();ts.exports=function(i,e){var t=i[e];return Qo(t)?void 0:Ko(t)}});var ns=f((rd,rs)=>{"use strict";var Gi=Dt(),Ui=Ee(),zi=ot(),Yo=TypeError;rs.exports=function(i,e){var t,r;if(e==="string"&&Ui(t=i.toString)&&!zi(r=Gi(t,i))||Ui(t=i.valueOf)&&!zi(r=Gi(t,i))||e!=="string"&&Ui(t=i.toString)&&!zi(r=Gi(t,i)))return r;throw new Yo("Can't convert object to primitive value")}});var as=f((nd,ss)=>{"use strict";ss.exports=!0});var ls=f((sd,cs)=>{"use strict";var os=se(),Xo=Object.defineProperty;cs.exports=function(i,e){try{Xo(os,i,{value:e,configurable:!0,writable:!0})}catch(t){os[i]=e}return e}});var Wi=f((ad,ps)=>{"use strict";var Zo=as(),Jo=se(),ec=ls(),hs="__core-js_shared__",us=ps.exports=Jo[hs]||ec(hs,{});(us.versions||(us.versions=[])).push({version:"3.38.0",mode:Zo?"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 ms=f((od,fs)=>{"use strict";var ds=Wi();fs.exports=function(i,e){return ds[i]||(ds[i]=e||{})}});var Ki=f((cd,ys)=>{"use strict";var tc=Ni(),ic=Object;ys.exports=function(i){return ic(tc(i))}});var Gt=f((ld,vs)=>{"use strict";var rc=Re(),nc=Ki(),sc=rc({}.hasOwnProperty);vs.exports=Object.hasOwn||function(e,t){return sc(nc(e),t)}});var bs=f((hd,gs)=>{"use strict";var ac=Re(),oc=0,cc=Math.random(),lc=ac(1 .toString);gs.exports=function(i){return"Symbol("+(i===void 0?"":i)+")_"+lc(++oc+cc,36)}});var xs=f((ud,Cs)=>{"use strict";var hc=se(),uc=ms(),Es=Gt(),pc=bs(),dc=Bi(),fc=qi(),De=hc.Symbol,Qi=uc("wks"),mc=fc?De.for||De:De&&De.withoutSetter||pc;Cs.exports=function(i){return Es(Qi,i)||(Qi[i]=dc&&Es(De,i)?De[i]:mc("Symbol."+i)),Qi[i]}});var ws=f((pd,Ss)=>{"use strict";var yc=Dt(),Is=ot(),Ts=Di(),vc=is(),gc=ns(),bc=xs(),Ec=TypeError,Cc=bc("toPrimitive");Ss.exports=function(i,e){if(!Is(i)||Ts(i))return i;var t=vc(i,Cc),r;if(t){if(e===void 0&&(e="default"),r=yc(t,i,e),!Is(r)||Ts(r))return r;throw new Ec("Can't convert object to primitive value")}return e===void 0&&(e="number"),gc(i,e)}});var Yi=f((dd,_s)=>{"use strict";var xc=ws(),Ic=Di();_s.exports=function(i){var e=xc(i,"string");return Ic(e)?e:e+""}});var As=f((fd,Rs)=>{"use strict";var Tc=se(),Vs=ot(),Xi=Tc.document,Sc=Vs(Xi)&&Vs(Xi.createElement);Rs.exports=function(i){return Sc?Xi.createElement(i):{}}});var Zi=f((md,Ms)=>{"use strict";var wc=qe(),_c=be(),Vc=As();Ms.exports=!wc&&!_c(function(){return Object.defineProperty(Vc("div"),"a",{get:function(){return 7}}).a!==7})});var Ns=f(Ls=>{"use strict";var Rc=qe(),Ac=Dt(),Mc=In(),Oc=Mi(),Lc=An(),Nc=Yi(),jc=Gt(),Pc=Zi(),Os=Object.getOwnPropertyDescriptor;Ls.f=Rc?Os:function(e,t){if(e=Lc(e),t=Nc(t),Pc)try{return Os(e,t)}catch(r){}if(jc(e,t))return Oc(!Ac(Mc.f,e,t),e[t])}});var Ps=f((vd,js)=>{"use strict";var kc=be(),$c=Ee(),Fc=/#|\.prototype\./,ct=function(i,e){var t=qc[Bc(i)];return t===Hc?!0:t===Dc?!1:$c(e)?kc(e):!!e},Bc=ct.normalize=function(i){return String(i).replace(Fc,".").toLowerCase()},qc=ct.data={},Dc=ct.NATIVE="N",Hc=ct.POLYFILL="P";js.exports=ct});var Fs=f((gd,$s)=>{"use strict";var ks=Ri(),Gc=Hi(),Uc=at(),zc=ks(ks.bind);$s.exports=function(i,e){return Gc(i),e===void 0?i:Uc?zc(i,e):function(){return i.apply(e,arguments)}}});var qs=f((bd,Bs)=>{"use strict";var Wc=qe(),Kc=be();Bs.exports=Wc&&Kc(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Hs=f((Ed,Ds)=>{"use strict";var Qc=ot(),Yc=String,Xc=TypeError;Ds.exports=function(i){if(Qc(i))return i;throw new Xc(Yc(i)+" is not an object")}});var zs=f(Us=>{"use strict";var Zc=qe(),Jc=Zi(),el=qs(),Ut=Hs(),Gs=Yi(),tl=TypeError,Ji=Object.defineProperty,il=Object.getOwnPropertyDescriptor,er="enumerable",tr="configurable",ir="writable";Us.f=Zc?el?function(e,t,r){if(Ut(e),t=Gs(t),Ut(r),typeof e=="function"&&t==="prototype"&&"value"in r&&ir in r&&!r[ir]){var n=il(e,t);n&&n[ir]&&(e[t]=r.value,r={configurable:tr in r?r[tr]:n[tr],enumerable:er in r?r[er]:n[er],writable:!1})}return Ji(e,t,r)}:Ji:function(e,t,r){if(Ut(e),t=Gs(t),Ut(r),Jc)try{return Ji(e,t,r)}catch(n){}if("get"in r||"set"in r)throw new tl("Accessors not supported");return"value"in r&&(e[t]=r.value),e}});var Ks=f((xd,Ws)=>{"use strict";var rl=qe(),nl=zs(),sl=Mi();Ws.exports=rl?function(i,e,t){return nl.f(i,e,sl(1,t))}:function(i,e,t){return i[e]=t,i}});var Xs=f((Id,Ys)=>{"use strict";var lt=se(),al=hn(),ol=Ri(),cl=Ee(),ll=Ns().f,hl=Ps(),He=ji(),ul=Fs(),Ge=Ks(),Qs=Gt();Wi();var pl=function(i){var e=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new i;case 1:return new i(t);case 2:return new i(t,r)}return new i(t,r,n)}return al(i,this,arguments)};return e.prototype=i.prototype,e};Ys.exports=function(i,e){var t=i.target,r=i.global,n=i.stat,s=i.proto,l=r?lt:n?lt[t]:lt[t]&<[t].prototype,o=r?He:He[t]||Ge(He,t,{})[t],c=o.prototype,h,v,T,m,x,I,V,_,d;for(m in e)h=hl(r?m:t+(n?".":"#")+m,i.forced),v=!h&&l&&Qs(l,m),I=o[m],v&&(i.dontCallGetSet?(d=ll(l,m),V=d&&d.value):V=l[m]),x=v&&V?V:e[m],!(!h&&!s&&typeof I==typeof x)&&(i.bind&&v?_=ul(x,lt):i.wrap&&v?_=pl(x):s&&cl(x)?_=ol(x):_=x,(i.sham||x&&x.sham||I&&I.sham)&&Ge(_,"sham",!0),Ge(o,m,_),s&&(T=t+"Prototype",Qs(He,T)||Ge(He,T,{}),Ge(He[T],m,x),i.real&&c&&(h||!c[m])&&Ge(c,m,x)))}});var Js=f((Td,Zs)=>{"use strict";var dl=Math.ceil,fl=Math.floor;Zs.exports=Math.trunc||function(e){var t=+e;return(t>0?fl:dl)(t)}});var rr=f((Sd,ea)=>{"use strict";var ml=Js();ea.exports=function(i){var e=+i;return e!==e||e===0?0:ml(e)}});var ia=f((wd,ta)=>{"use strict";var yl=rr(),vl=Math.min;ta.exports=function(i){var e=yl(i);return e>0?vl(e,9007199254740991):0}});var na=f((_d,ra)=>{"use strict";var gl=ia();ra.exports=function(i){return gl(i.length)}});var aa=f((Vd,sa)=>{"use strict";sa.exports=function(){}});var oa=f(()=>{"use strict";var bl=Xs(),El=Ki(),Cl=na(),xl=rr(),Il=aa();bl({target:"Array",proto:!0},{at:function(e){var t=El(this),r=Cl(t),n=xl(e),s=n>=0?n:r+n;return s<0||s>=r?void 0:t[s]}});Il("at")});var la=f((Md,ca)=>{"use strict";var Tl=$i();ca.exports=Tl});var ua=f((Od,ha)=>{"use strict";oa();var Sl=la();ha.exports=Sl("Array","at")});var da=f((Ld,pa)=>{"use strict";var wl=ua();pa.exports=wl});var ma=f((Nd,fa)=>{"use strict";var _l=da();fa.exports=_l});var Er="1.0.16-dev.4720172e.0";function si(i,e=1){let t="0",r="0",n="0";return i.length===4?(t="0x"+i[1]+i[1],r="0x"+i[2]+i[2],n="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],r="0x"+i[3]+i[4],n="0x"+i[5]+i[6]),`rgba(${+t},${+r},${+n},${e})`}var D="SDK_NAME",Pa="SDK_NAME-controls-container",yt=()=>document.querySelector(`.${Pa}`),Tr=.4,Y={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Cr={top:"flex-start",bottom:"flex-end",center:"center"},xr={start:"flex-start",end:"flex-end",center:"center"},Ir={start:"left",end:"right",center:"center"},vt=({target:i,props:e})=>{var t,r,n,s,l,o;i.style.alignItems=(r=Cr[(t=e==null?void 0:e.text)==null?void 0:t.gravityVertical])!=null?r:Cr.center,i.style.justifyContent=(s=xr[(n=e==null?void 0:e.text)==null?void 0:n.gravityHorizontal])!=null?s:xr.center,i.style.textAlign=(o=Ir[(l=e==null?void 0:e.text)==null?void 0:l.alignment])!=null?o:Ir.start},gt=({target:i,props:e,fallback:t,dependsOn:r})=>{var n,s,l,o,c,h;i.style.color=(s=(n=e==null?void 0:e.text)==null?void 0:n.color)!=null?s:t.textColor,i.style.fontSize=`calc(${r.height} * ${(o=(l=e==null?void 0:e.text)==null?void 0:l.size)!=null?o:t.textSize})`,i.textContent=(h=(c=e==null?void 0:e.text)==null?void 0:c.value)!=null?h:t.textContent},bt=({target:i,props:e,fallback:t})=>{var r,n,s,l;i.style.backgroundColor=si((n=(r=e==null?void 0:e.background)==null?void 0:r.color)!=null?n:t.backgroundColor,(l=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?l:t.backgroundAlpha)},Et=({target:i,props:e,fallback:t,dependsOn:r})=>{var n,s,l,o,c,h,v,T,m,x,I;i.style.border=`calc(${r.height} * ${(l=(s=(n=e==null?void 0:e.shape)==null?void 0:n.border)==null?void 0:s.width)!=null?l:t.borderWidth}) solid ${si((h=(c=(o=e==null?void 0:e.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?h:t.borderColor,(m=(T=(v=e==null?void 0:e.shape)==null?void 0:v.border)==null?void 0:T.alpha)!=null?m:t.borderAlpha)}`,i.style.borderRadius=`calc(${r.height} * ${(I=(x=e==null?void 0:e.shape)==null?void 0:x.roundCorners)!=null?I:t.roundCorners})`},Pe=({target:i,layoutParams:e,fallback:t})=>{i.style.transform=`rotate(${-e.angle}rad)`};var ai="int",ke={AREA:`${ai}_area`,TEXT:`${ai}_text`,BUTTON:`${ai}_bttn`};var ye=class{constructor(e){this.control=e}createView(e){var n;let t=document.createElement("div");t.classList.add(`${D}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let r=((n=this.control.layoutParams.innerSizesDependOn)!=null?n:Y.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:t,dependsOn:r}}setEvents(e,t){e&&this.control.events.forEach(r=>{switch(r.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",s=>{s.stopPropagation(),t&&t({action:r.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${D}-control-container-${this.control.id}`)}};var Ct=i=>{if(i.type.trim().toLowerCase()==="area")return new oi(i)},oi=class extends ye{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:r,controlContainerEl:n}=super.createView(t),s=document.createElement("button");return s.classList.add(`${D}-${this.control.id}`),s.setAttribute("data-testid",ke.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",bt({target:s,props:this.control.props,fallback:C(p({},Y),{backgroundColor:"transparent"})}),Et({target:s,props:this.control.props,fallback:C(p({},Y),{borderAlpha:0}),dependsOn:r}),Pe({target:s,layoutParams:this.control.layoutParams,fallback:Y}),n.append(s),e.append(n),this.controlEl=s,n}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var xt=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var It=i=>{if(i.type.trim().toLowerCase()==="button")return new ci(i)},ci=class extends ye{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:r,controlContainerEl:n}=super.createView(t),s=document.createElement("button");s.type="button",s.classList.add(`${D}-${this.control.id}`),s.setAttribute("data-testid",ke.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=xt();return Pe({target:s,layoutParams:this.control.layoutParams,fallback:Y}),bt({target:s,props:this.control.props,fallback:Y}),Et({target:s,props:this.control.props,fallback:Y,dependsOn:r}),vt({target:s,props:this.control.props}),gt({target:l,props:this.control.props,fallback:Y,dependsOn:r}),s.append(l),n.append(s),e.append(n),this.controlEl=s,n}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var Sr=i=>{if(i.type.trim().toLowerCase()==="text")return new li(i)},li=class extends ye{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:r,controlContainerEl:n}=super.createView(t),s=document.createElement("div");s.classList.add(`${D}-${this.control.id}`),s.setAttribute("data-testid",ke.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=xt();return Pe({target:s,layoutParams:this.control.layoutParams,fallback:Y}),vt({target:s,props:this.control.props}),gt({target:l,props:this.control.props,fallback:Y,dependsOn:r}),s.append(l),n.append(s),e.append(n),this.controlEl=s,n}disable(){}enable(){}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var hi=class{constructor(e){this.layout=e}},wr=i=>{if(i.type.trim().toLowerCase()==="relative")return new Qe(i)},Qe=class extends hi{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var ve,Tt,_r,$e=class{constructor(e){w(this,ve);this.container=e,this.factories=new Map,F(this,ve,Tt).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),F(this,ve,Tt).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),F(this,ve,Tt).call(this)}};ve=new WeakSet,Tt=function(){this.controls=F(this,ve,_r).call(this)},_r=function(){var e;return(e=this.container.controls)==null?void 0:e.reduce((t,r)=>{let n=r.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...t,s(r)]:[...t]},[])};var St=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new ui(i,e)},ui=class extends $e{constructor(e,t){super(e),this.rootElement=t!=null?t:yt(),this.layout=new Qe(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",It),this.addControlFactory("text",Sr),this.addControlFactory("area",Ct)}createView(e){let t=document.createElement("div");return t.classList.add(`${D}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(r=>{let n=r.createView({parent:t,layoutFn:this.layout.setControlLayout});r.setEvents(n,e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity=1,this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=Tr,this.isDisabled=!0)}removeView(){var e;this.isRemoved||((e=this.getElement())==null||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${D}-${this.container.id}`)}};import{Subject as Ol,ValueSubject as ae,Observable as ba,once as Ll,Subscription as Nl,clientChecker as jl,combine as Pl}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as ka}from"@vkontakte/videoplayer-shared";function wt(i,e){let t;return(...r)=>{clearTimeout(t),t=setTimeout(()=>i(...r),e)}}var we=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,Ye=i=>we(i,"Object"),_t=i=>we(i,"String"),Vt=i=>we(i,"Array"),Rt=i=>we(i,"Number"),Vr=i=>we(i,"Function");var pi=i=>Rt(i)&&!isNaN(i);var _e=i=>Ye(i)&&Object.keys(i).length===0,di=i=>Vt(i)&&!i.length;var Xe=(i,e)=>_t(i)&&(e?i.trim():i).length;var Rr="video_interactive",Ar="videoint";var $a=250,Ze=class{constructor(e){ee(this,"onResize",e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))});ee(this,"handleChapterChange",e=>{var t;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}});ee(this,"handleManifestChange",(r,...n)=>R(this,[r,...n],function*(e,t=[]){var s;if(!Rt(e.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)==null||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let l;try{l=yield ka(this.lang,Rr,Ar)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:o}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new o(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:l}),this.ngEditor.on("control",({name:c,chapterId:h})=>{c==="openPreview"&&this.onOpenPreviewClick(h)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo=p({},c)})}this.visitedChapterIds=new Set(t),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0}));this.init(e)}init({root:e,onOpenPreviewClick:t,onError:r,lang:n,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=r,this.lang=n!=null?n:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=Fa(e),this.resizeObserver=new ResizeObserver(wt(this.onResize,$a)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return[(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)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Fa(i){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",i.append(e),e}var Je=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,r=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let l=s.startTime-e;if(l<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){r=!0;break}n<l&&(t=t===-1?l:Math.min(t,l))}return!r&&t!==-1?t:null}}};var ge=(i="",e="")=>{let t=i.split("."),r=e.split("."),n=0;for(let s=0;s<Math.max(t.length,r.length)&&!n;s++)t[s]>r[s]?n=1:t[s]<r[s]?n=-1:n=0;return n};import{v4 as Ba}from"uuid";var qa="3.1",Mr={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Da={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Or=i=>{let e=[];for(let l of i.chapters){let o,c=[];for(let t of l.branches){let r=t,{isDefault:T}=r,m=Q(r,["isDefault"]);T&&(o=m.id),c.push(m)}let h=[],v=[];for(let n of l.containers){let s=n,{fallbackStrategy:T}=s,m=Q(s,["fallbackStrategy"]);let x=!!m.endTime,I=[Da];switch(T){case"await":x?I=[]:h=[];break;case"default":{let V={type:"onSuspense",action:{type:Mr.default,args:{branchId:o,shouldOpenNow:!x,isDetachContainer:!0}}};x?I=[V]:h=[V];break}case"random":case"weightlessRandom":case"max":case"min":{let V={type:"onSuspense",action:{type:Mr[T],args:{}}};x?I=[V]:h=[V];break}}for(let V of m.controls)v.push(C(p({},m),{controls:[p({},V)],id:Ba(),events:I}))}e.push(C(p({},l),{containers:v,events:h,branches:c}))}return i.metadata.version=qa,i.metadata.updated=new Date().toISOString(),C(p({},i),{chapters:e})};var Ha="3.2",Lr=i=>{if(!i.media){let e=i.metadata,{media:t}=e,r=Q(e,["media"]);return C(p({},i),{metadata:C(p({},r),{version:Ha}),media:t})}return i};var Ga="3.3",Ua=(i=[])=>({edit:{chapters:i},view:{}}),Nr={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},jr=i=>{var n;let e=[],t=[];for(let s of i.chapters){let r=s,{id:l,x:o,y:c}=r,h=Q(r,["id","x","y"]),v=h.containers.map(T=>{var m;return C(p({},T),{controls:T.controls.map(_=>{var d=_,{subtype:x,type:I}=d,V=Q(d,["subtype","type"]);return C(p({},V),{type:x!=null?x:I})}),events:(m=T.events)!=null&&m.length?T.events:[Nr]})});e.push(C(p({id:l},h),{containers:v,events:(n=h.events)!=null&&n.length?h.events:[Nr]})),t.push({id:l,x:o,y:c})}return C(p({},i),{chapters:e,graph:Ua(t),metadata:C(p({},i.metadata),{version:Ga})})};var za=[{version:"3.0",migrate:Or},{version:"3.1",migrate:Lr},{version:"3.2",migrate:jr}],fi=i=>za.reduce((e,t)=>ge(e.metadata.version,t.version)?e:t.migrate(e),i);var tu=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Pr=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),iu=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),P=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),mi=(s=>(s.GO_NEXT_BUTTON="GO_NEXT_BUTTON",s.GO_NEXT_AREA="GO_NEXT_AREA",s.WATCH_AGAIN="WATCH_AGAIN",s.OPEN_GRAPH="OPEN_GRAPH",s.CLOSE_GRAPH="CLOSE_GRAPH",s))(mi||{});var kr={metadata:"Object",chapters:"Array"},Wa="3.0.0",Ka="3.3.0",At=i=>{let e=ge(i,Wa);return e===-1?!1:e===0?!0:ge(i,Ka)!==1},$r=i=>{if(!Ye(i))return!1;for(let e in kr)if(!i[e]||!we(i[e],kr[e]))return!1;return At(i.metadata.version)},Mt=i=>i.type===Pr.Text;var W=class{constructor(e,t,...r){this.severity=e;this.category=t;this.data=r}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Fe=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 r=()=>{t(),this.off(e,r)};return this.listeners[e].push(r),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let r=this.listeners[e]||[];for(let n=r.length;n>0;n--)if(r[n]===t){r.splice(n,1);break}return this}emit(e,...t){let r=this.listeners[e];return r?(r.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Ot=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{Vr(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(r=>r!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};this.fn=e,this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as to}from"@vkontakte/videoplayer-shared";var Lt=class{constructor(e){var t,r;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(r=e==null?void 0:e.manifestLoaders)!=null?r:[]}}exec(e,t){return R(this,null,function*(){return Qa(...this.loaders[e])(t)})}};function Qa(...i){return function(t){return R(this,null,function*(){let r=[...i];for(;r.length>0;)t=yield r.shift()(t);return t})}}function et(i,e,t){return i?C(p({},i),{[e]:i[e]?[t,...i[e]]:[t]}):{[e]:[t]}}function Nt(n){var s=n,{actions:i,errors:e,chapterId:t}=s,r=Q(s,["actions","errors","chapterId"]);if(t){let l=i.getManifest(),o=i.getChapter(l.chapters,t);if(o){let c=i.getMedia(l.media,o.videoId),h=i.getGraph(l.graph,o.id);return c?C(p({},r),{actions:i,errors:e,result:{chapter:o,media:c,graph:h}}):C(p({},r),{errors:et(e,Nt.name,"Could not find media"),actions:i})}}return C(p({},r),{errors:et(e,Nt.name,"Could not find chapter"),actions:i})}var Ya=i=>R(void 0,null,function*(){try{let e,t;if(Ye(i))e=i;else if(_t(i)){t=new URL(i).href;let n=yield fetch(t);if(!n.ok)return{};e=yield n.json()}else return{};if(!$r(e))return{};let r=e.metadata.media;if(_t(r)&&!e.media)try{let n;t?n=new URL(r,t).href:(n=new URL(r).href,t=n);let s=yield fetch(n);if(!s.ok)throw new Error;e.metadata.media=yield s.json()}catch(n){return Ja(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}});function Fr(i){return R(this,null,function*(){let{manifest:e,manifestURL:t}=yield Ya(i),r=fi(e);return r.media=Xa(r.media,t),delete r.metadata.media,r})}function jt(i,e){return i.find(t=>t.id===e)}function yi(i,e){var t,r;return(t=i.edit)!=null&&t.chapters?i.edit.chapters.find(n=>n.id===e):(r=i.view)!=null&&r.chapters?i.view.chapters.find(n=>n.id===e):void 0}function vi(i,e){return i.videos.find(t=>t.id===e)}function Xa(i,e){return C(p({},i),{videos:i.videos.map(t=>C(p({},t),{variants:t.variants.map(r=>{let n=Za(r.url,e);return C(p({},r),{url:n||r.url})})}))})}function Za(i,e){try{return new URL(i,e).href}catch(t){return""}}function Ja(i){return ge(i,"3.2.0")>=0}var B=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Pt=i=>Vt(i)&&!di(i),oe=i=>i.order==="end",kt=i=>Vt(i.containers)&&!di(i.containers)&&oe(i),Br=(i,e)=>{var r;let t=i*1e3;return Pt(e.controls)&&t<((r=e.startTime)!=null?r:0)},gi=(i,e)=>{var r,n;let t=i*1e3;return Pt(e.controls)&&t>=((r=e.startTime)!=null?r:0)&&t<=((n=e.endTime)!=null?n:1/0)};var Ve=i=>i.some(e=>e.action.type==="expect"),bi=i=>i.find(e=>e.action.type==="expect"),eo=i=>(i==null?void 0:i.length)===1,$t=i=>eo(i)&&Mt(i[0]);var qr=({fn:i,type:e=1},...t)=>(...r)=>e?i(...r,...t):i(p(p({},r[e]),t[e])),Dr=(i,e)=>Ve(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&Ve(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);var Be=class extends Lt{constructor(e,t){super(e),this.onError=t,this.prevChapter$=new to(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(e){return R(this,null,function*(){var n;this.release();let t=yield this.exec("manifestLoaders",{actions:{addErrorMessage:et},result:null,errors:null,source:e});t.errors&&this.errorHandler(t.errors);let r=yield Fr((n=t.result)!=null?n:e);return this.manifest=r,this})}setInitial(){return R(this,null,function*(){return this.setNext()})}setNext(){return R(this,arguments,function*(e=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let t=yield this.exec("chapterLoaders",Nt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:yi,getChapter:jt,getMedia:vi,getByBranches:this.getByBranches.bind(this),addErrorMessage:et},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.result.graph,this})}errorHandler(e){this.onError(e),console.error("Something went wrong with loaders",{errors:e})}getInitial(){return this.getByChapterId(this.manifest.metadata.initChapterId)||null}getByChapterId(e=this.manifest.metadata.initChapterId){let t=jt(this.manifest.chapters,e);if(t){let r=vi(this.manifest.media,t.videoId),n=yi(this.manifest.graph,t.id);if(r)return{chapter:t,media:r,graph:n}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{let t=jt(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,r)=>{let n=this.getByChapterId(r.chapterId);return n&&t.push(n),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return oe(this.chapter)}};import{Player as io}from"@vkontakte/videoplayer-core";import{Subscription as ro}from"@vkontakte/videoplayer-shared";var Hr=i=>{let e=i.variants.find(t=>{var r;return((r=t.payload)==null?void 0:r.type)==="vk"});if(e&&"payload"in e){let[t,r]=e.payload.id.split("_");return[t,r]}return[]};var E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},tt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Ei(){let i=new Map;function e(o){var c=o,{listId:n=Math.random().toString(),itemId:s=Math.random().toString()}=c,l=Q(c,["listId","itemId"]);let h=i.get(n),v=p({},l);return h?h[s]=v:i.set(n,{[s]:v}),p({listId:n,itemId:s},l)}function t(n,s){var o,c,h;let l=i.get(n);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(h=l[s])==null||h.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(n),!0;for(let v of Object.values(l))v.player.destroy(),v.container.remove();return i.delete(n),!0}else throw Error("Can't remove. Not find.")}function r(){for(let n of i)t(n[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:r}}function Ci(i,e=[]){var s,l,o;let t={},r,n=!e.length;for(let c of i.variants)if(!r&&"cover"in c&&(r=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(n||e.includes("mp4"))&&(t.MPEG=C(p({},t.MPEG),{[(s=c.standard)!=null?s:"Invariant quality"]:c.url}));break;case"mpeg":(n||e.includes("mpeg"))&&(t.MPEG=C(p({},t.MPEG),{[(l=c.standard)!=null?l:"Invariant quality"]:c.url}));break;case"hls":(n||e.includes("hls"))&&(t=C(p({},t),{HLS:{type:"url",url:c.url}}));break;case"dash":(n||e.includes("dash"))&&(t=C(p({},t),{DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}}));break;default:break}return{sources:t,thumbUrl:r,title:(o=i.title)!=null?o:""}}var it=(i,e)=>{let t=i.info.currentQuality$.getValue(),r=i.info.availableQualities$.getValue();t!==e&&r.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))};var rt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},no=2;function xi(i){let e=Ei(),t,r,n=new Fe,s={},l=!1,o=null,c=!1,h;i&&v(i);function v(u){o=u}function T(u,g,S){var j;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let M=((j=e.map.get(u))!=null?j:{})[g];if(M){s=p({chapterId:S,listId:u,itemId:g},M);let $=s.player;r=$.info.currentQuality$.subscribe(O=>{if(!(!O||!$.info.position$.getValue())){t=O;for(let ie of e.map)Object.values(ie[1]).forEach(({player:J})=>{$.info.isAutoQualityEnabled$.getValue()||it(J,O)})}}),M.container.remove(),l=!1,o.setPlayer(M.player),c||(o.init(),c=!0),n.emit(rt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function m(u,g,S){return R(this,null,function*(){if(!o)throw Error("need to set interactive controller");if(_e(s)||u!==s.itemId)return;if(S>=0&&!l){let M=o.getChapterBranches();l=!0;let j=new Set;for(let $ of M)j.has($.media.id)||(yield I({media:$.media,chapterId:$.chapter.id,setAsActive:!1,title:$.chapter.label}),j.add($.media.id))}})}function x(S){return R(this,arguments,function*({chapter:{id:u},media:g}){if(_e(s))return;r==null||r.unsubscribe();let y=s.player.info.muted$.getValue(),M=s.player.info.currentQuality$.getValue(),j=s.player.info.isAutoQualityEnabled$.getValue(),$=s.player.info.volume$.getValue(),O=s.player.info.currentPlaybackRate$.getValue(),ie=!j,J=!1;for(let z of e.map)if(z[0]===g.id){let me=Object.keys(z[1]);for(let K of me)K===s.itemId?(me.length<no||(J=!0),e.removePlayer(z[0],K)):(J=!0,T(z[0],K,u),ie?it(s.player,M):s.player.setAutoQuality(!0),s.player.setVolume($),s.player.setMuted(y),s.player.setPlaybackRate(O))}else e.removePlayer(z[0]);J||(yield I({media:g,chapterId:u,setAsActive:!0,playbackRate:O}),ie?it(s.player,M):s.player.setAutoQuality(!0),s.player.setVolume($),s.player.setMuted(y))})}function I(ie){return R(this,arguments,function*({media:u,chapterId:g,prefetch:S=!0,setAsActive:y=!0,autoplay:M=!1,preferredExt:j,title:$,playbackRate:O}){var pr,dr,fr,mr,yr;let J=Math.random().toString(),z=document.createElement("div");h.append(z);let me=(pr=s==null?void 0:s.player)==null?void 0:pr.info.isAutoQualityEnabled$.getValue(),K;if((dr=o==null?void 0:o.options)!=null&&dr.vkVideoLoader){let ft=Hr(u);ft.length&&(K=yield o.options.vkVideoLoader(...ft))}let lr=((fr=o==null?void 0:o.options)==null?void 0:fr.coreConfig)||{},_a=C(p({},lr),{configName:[...(mr=lr.configName)!=null?mr:[],"interactive"]}),hr=C(p({container:z},((yr=K==null?void 0:K.videos)==null?void 0:yr[0])||{sources:Ci(u,j).sources}),{title:$,failoverHosts:(K==null?void 0:K.failoverHosts)||[]}),Se=new io(_a);Se.initVideo(hr);let ur=new ro;ur.add(Se.info.position$.subscribe(function(ft){m(J,Se.info.duration$.getValue(),ft)})).add(Se.events.canplay$.subscribe(function(){me||it(Se,t),O&&Se.setPlaybackRate(O)}));let je=e.createPlayer({listId:u.id,itemId:J,player:Se,container:z,sources:Ci(u,j).sources,config:hr,subscription:ur});return y&&T(u.id,je.itemId,g),M&&je.player.play(),S&&!M&&je.player.prepare(),n.emit(rt.playerCreated,je.player),{player:je.player,config:je.config}})}function V(){_(),o=null}function _(){o==null||o.off(E.chapterChanged,x),e.removeAll(),s={},c=!1,l=!1}function d(g){return R(this,arguments,function*({container:u}){if(!o)throw Error("need to set interactive controller");_(),h=u;let{media:S,chapter:y}=o.getCurrentChapter();if(S){o.on(E.chapterChanged,x);let{player:M,config:j}=yield I({media:S,chapterId:y.id,title:y.label});return n.emit(rt.initiated,{container:u,media:S,chapterId:y.id}),{player:M,config:j}}else console.error("not found")})}return C(p({},e),{on:n.on.bind(n),off:n.off.bind(n),init:d,setInteractiveController:v,createPlayer:I,removeAll:V,getActivePlayer:function(){return s}})}import{Subscription as so}from"@vkontakte/videoplayer-shared";var Ft=class{constructor({player:e,container:t,branches:r,selectBranches:n,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:h,onRemove:v}){ee(this,"hide",()=>{setTimeout(()=>{var e,t;this.gameState!==B.end&&(Ve(this.container.container.events)&&this.gameState===B.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==B.interactive&&((t=(e=this.container).hide)==null||t.call(e)),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})});ee(this,"show",()=>{var e,t,r,n;if(this.gameState===B.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(n=(r=this.container).show)==null||n.call(r),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{let l=qr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===B.end||this.gameState===B.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1}))},isEOV:()=>this.gameState===B.end});this.container.createView(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((t=(e=this.container).disable)==null||t.call(e))}});ee(this,"onEndOfVideo",()=>{this.gameState=B.end,this.selectContainerEvent(!0)});ee(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[B.destroyed,B.removed].includes(this.gameState)&&!this.isPermanentText)return;let t=this.player.getExactTime();if(Br(t,this.container.container))this.gameState!==B.beforeInteractive&&(this.gameState=B.beforeInteractive,this.onBeforeStartTime());else if(gi(t,this.container.container))this.gameState!==B.interactive&&(this.gameState=B.interactive,this.onStartTime());else if(this.gameState!==B.afterInteractive){let o=this.gameState;this.gameState=B.afterInteractive,o===B.interactive&&this.onEndTime()}else this.gameState!==B.destroyed&&!this.isPermanentText&&this.removeView();let r=gi(t,this.container.container),n=this.container.container.startTime?[this.container.container.startTime,(l=this.container.container.endTime)!=null?l:1/0]:[];this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:n,currentTime:t,isInteractiveTime:r})});this.container=t,this.branches=r,this.selectBranches=n,this.subscription=new so,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&$t(t.container.controls),this.disabledControls$=h,this.onRemove=v,this.globalEventEmitter=l,this.gameState=B.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,r,n,s;e?(r=(t=this.container).disable)==null||r.call(t):(s=(n=this.container).enable)==null||s.call(n)}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=Ve(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=B.beforeInteractive}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=B.removed,(e=this.onRemove)==null||e.call(this)}destroy(){var e;this.reset(),this.removeView(),this.gameState=B.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var Gr=(i=[])=>i.reduce((e,t,r)=>{var s,l,o;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(c=>!Mt(c));if(Pt(n)){let c=[(l=t.startTime)!=null?l:0,(o=t.endTime)!=null?o:1/0],h=t.id;if(!r)e.push({subjects:[h],range:c});else{let v=[],T=-1/0,m=1/0,x=[],I=[];for(let V=0;V<e.length;V++){let _=e[V];if(I.push(..._.subjects),_.range[0]<m&&(m=_.range[0]),_.range[1]>T&&(T=_.range[1]),c[0]>=_.range[0]&&c[1]<=_.range[1])return e[V].subjects.push(h),e;c[0]<_.range[0]&&c[1]>_.range[0]&&(v.push(V),x=x.concat(_.subjects)),c[0]>=_.range[0]&&c[0]<=_.range[1]&&(v.push(V),x=x.concat(_.subjects),c[0]=_.range[0]),c[1]>=_.range[0]&&c[1]<=_.range[1]&&(v.push(V),x=x.concat(_.subjects),c[1]=_.range[1])}if(I.push(h),c[0]<=m&&c[1]>=T)return[{subjects:I,range:c}];v.length&&v.reverse().forEach(V=>{e.splice(V,1)}),e.push({subjects:x.concat([h]),range:c})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Ur(){let i={};function e(){for(let o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function t(o){let c={};for(let h in i)+h<=o&&(c[h]=i[h]);return c}function r(o){let c={};for(let h in i)+h>=o&&(c[h]=i[h]);return c}function n({timestamp:o,priority:c,initiator:h}){var v;if(pi(o)){let T=(v=i[o])!=null?v:null;if(T&&Xe(c,!0)){let m={},x=T[c];if(x&&(m=p(p({},m),x)),m=_e(m)?null:m,m&&Xe(h,!0)){let I=m[h];return I!=null?I:null}return m}return T}return null}function s({timestamp:o,priority:c,initiator:h}){if(pi(o))if(i[o]){if(Xe(c,!0))if(i[o][c]){if(Xe(h,!0))if(i[o][c][h]){if(delete i[o][c][h],!_e(i[o][c]))return!0}else return!1;if(delete i[o][c],!_e(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(T){var m=T,{timestamp:o,priority:c,initiator:h}=m,v=Q(m,["timestamp","priority","initiator"]);var x,I,V;(I=(x=i[o])==null?void 0:x[c])!=null&&I[h]?i[o][c][h].push(p({},v)):(V=i[o])!=null&&V[c]?i[o][c]=C(p({},i[o][c]),{[h]:[p({},v)]}):i[o]?i[o]=C(p({},i[o]),{[c]:{[h]:[p({},v)]}}):i[o]={[c]:{[h]:[p({},v)]}}}return{map:i,remove:s,add:l,removeAll:e,get:n,getLte:t,getGte:r}}var ao=[P.expect,P.setNextBranch],oo=1/0;function Ii(i){let e=i,t,r=co(),n=new Ur,s,l=()=>{m(),d()},o=u=>{n.add.call(void 0,u),I()},c=(u=[])=>{for(let g of u)if(g.action(),ao.includes(g.actionType))break},h=(u=1/0)=>{var M,j,$;let g=Bt((M=n.get({timestamp:u,priority:"control"}))!=null?M:{}),S=Bt((j=n.get({timestamp:u,priority:"container"}))!=null?j:{}),y=Bt(($=n.get({timestamp:u,priority:"chapter"}))!=null?$:{});return[...g,...S,...y]},v=u=>{r.isReady(u)&&c(h(u))},T=()=>{var u;c([...Bt((u=n.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},m=()=>{t&&(s==null||s.unsubscribe(),t=void 0)},x=u=>{},I=()=>{t||(t=()=>setTimeout(()=>{v(1/0)}),s=e.events.ended$.subscribe(t))},V=u=>{m(),e=u},_=u=>{u.priority==="container"&&r.resetCalled(u.timestamp),n.remove(u)},d=()=>{r.release(),n.removeAll()};return{setPlayer:V,add:o,remove:_,exec:v,execEndOfVideo:T,listen:I,unlisten:m,release:l,containersEventsCallState:r,getPreparedToExecActions:h}}function co(){let i=new Map;return{setCalled:({timestamp:l,id:o})=>{let c=i.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(let h of l){let v=(o=h.endTime)!=null?o:oo,T=(c=i.get(v))!=null?c:{};i.set(v,C(p({},T),{[h.id]:!1}))}},resetCalled:l=>{let o=i.get(l);if(o)for(let c in o)o[c]=!1},isReady:l=>{let o=i.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>i.clear()}}function Bt(i){return Object.values(i).flat().sort(e=>e.actionType===P.expect?-1:1)}var zr={videoContentHeight:0,videoContentWidth:0},Wr=(i,e)=>{let{height:t,width:r}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&r))return zr;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return zr;let l=t/r,o=n/s,c,h;return o>l?(h=s,c=s*l):o<l?(h=n/l,c=n):(h=s,c=n),{videoContentWidth:h,videoContentHeight:c}};var lo=250;function Kr(i){let e=()=>{},t=new ResizeObserver(o=>{s(o),e=s.bind(null,o)});function r(o){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:v,videoContentHeight:T}=Wr(c,h);c.style.setProperty("--interactive-content-width",`${v}px`),c.style.setProperty("--interactive-content-height",`${T}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function n(){let{parentElement:o}=i();o.removeAttribute("style")}let s=wt(o=>{let{fns:c=[]}=i();r(o);for(let h of c)h()},lo);function l(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e()},release:l}}var nt=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(r=>r!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var ho=i=>Math.floor(Math.random()*i),Qr=i=>{let e=i.length,t=1/0,r=null;for(;e--;)i[e].weight<t&&(t=i[e].weight,r=i[e]);return r},Yr=i=>{let e=i.length,t=-1/0,r=null;for(;e--;)i[e].weight>t&&(t=i[e].weight,r=i[e]);return r};var Xr=i=>{let e=i.length,t=ho(e);return i[t]};var Zr=i=>{var r,n;let e=0;for(let s=0;s<i.length;++s)e+=(r=i[s].weight)!=null?r:1;let t=Math.random()*e;e=0;for(let s=0;s<i.length-1;++s)if(e+=(n=i[s].weight)!=null?n:1,e>=t)return i[s];return i[i.length-1]};var Jr=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var Ti=(i,e=!1)=>C(p({},i),{args:e?p(p({},i.args),Jr):p(p({},Jr),i.args)}),Si=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:r})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:d,controlType:u,controlId:g,containerId:S,branches:y=[],onEvent:M,isEOV:j=()=>!1,isDisabled:$=()=>!1})=>{let O=Ti(d,j()),ie={timestamp:1/0,priority:"control",initiator:g,actionType:O.type},J=$(),z=i.emit.bind(i,E.interactives,{subjectId:g,subjectType:u,subjectName:"control",type:J?L.actionChoiceCanceled:L.actionChoice,actionType:d.type,payload:p({containerId:S},O.args)});if(J){z();return}switch(O.type.trim().toLowerCase()){case P.setNextBranch.trim().toLowerCase():{let me=y.find(K=>K.id===O.args.branchId);if(!me)return;M(O.args.isDetachContainer,m.bind(null,{subjectId:g,subjectName:"control"})),z(),O.args.shouldOpenNow?I({subjectId:g,subjectName:"control",subjectType:u,action:O,payload:{chapterId:me.chapterId,autoSelect:!1}}):(t.add(C(p({},ie),{action:I.bind(null,{subjectId:g,subjectName:"control",subjectType:u,action:O,payload:{chapterId:me.chapterId,autoSelect:!1}})})),r==null||r());return}case P.continuePlayback.trim().toLowerCase():{M(O.args.isDetachContainer,m.bind(null,{subjectId:g,subjectName:"control"})),z(),O.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:u,action:d}):t.add(C(p({},ie),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:u,action:d})}));return}case P.openURI.trim().toLowerCase():{M(O.args.isDetachContainer,m.bind(null,{subjectId:g,subjectName:"control"})),z(),O.args.shouldOpenNow?_({subjectId:g,subjectName:"control",subjectType:u,action:O,payload:{URI:d.args.uri}}):(t.add(C(p({},ie),{action:_.bind(null,{subjectId:g,subjectName:"control",subjectType:u,action:O,payload:{URI:d.args.uri}})})),r==null||r());return}default:console.error("Unexpected control event"),i.emit(E.errors,new W(1,1,{message:"Unexpected control event"}));return}},o=({action:d,container:{id:u,endTime:g},branches:S=[],isEOV:y=!1,autoSelected:M=!1})=>{let j=Ti(d,y),$={timestamp:!j.args.shouldOpenNow||y?1/0:g,priority:"container",initiator:u,actionType:j.type},O=i.emit.bind(i,E.interactives,{subjectId:u,subjectName:"container",type:L.actionChoice,actionType:j.type,payload:j.args});switch(j.type.trim().toLowerCase()){case P.setNextBranch.trim().toLowerCase():{let ie=S.find(J=>J.id===j.args.branchId);if(!ie)return;O(),t.add(C(p({},$),{action:I.bind(null,{subjectId:u,subjectName:"container",action:j,payload:{chapterId:ie.chapterId,autoSelect:M}})})),r==null||r();return}case P.setMaxWeightBranch.trim().toLowerCase():return;case P.setMinWeightBranch.trim().toLowerCase():return;case P.setRandomBranch.trim().toLowerCase():return;case P.setWeightlessRandomBranch.trim().toLowerCase():return;case P.continuePlayback.trim().toLowerCase():{O(),t.add(C(p({},$),{action:x.bind(null,{subjectId:u,subjectName:"container",action:j})}));return}case P.openURI.trim().toLowerCase():{O(),t.add(C(p({},$),{action:_.bind(null,{subjectId:u,subjectName:"container",action:j,payload:{URI:d.args.uri}})})),r==null||r();return}default:console.error("Unexpected container event"),i.emit(E.errors,new W(1,1,{message:"Unexpected container event"}));return}};function c({container:d,branches:u,isEOV:g=!1}){let S=bi(d.events);if(S){let y=Ti(S.action,g);i.emit(E.interactives,{subjectId:d.id,subjectName:"container",type:L.actionChoice,actionType:y.type,payload:y.args}),t.add({timestamp:g?1/0:d.endTime,priority:"container",initiator:d.id,actionType:P.expect,action:T.bind(null,{subjectId:d.id,subjectName:"container"})}),n.isExpect=!0}else for(let y of d.events)o({action:y.action,container:d,branches:u,isEOV:g})}let h=({chapterId:d,action:u,branches:g=[]})=>{let S=i.emit.bind(i,E.interactives,{subjectId:d,subjectName:"chapter",type:L.actionChoice,actionType:u.type,payload:u.args});switch(u.type.trim().toLowerCase()){case P.setNextBranch.trim().toLowerCase():{let y=g.find(M=>M.id===u.args.branchId);return y!=null&&y.chapterId?(S(),I.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case P.setWeightlessRandomBranch.trim().toLowerCase():{let y=Xr(g);return y!=null&&y.chapterId?(S(),I.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case P.setRandomBranch.trim().toLowerCase():{let y=Zr(g);return y!=null&&y.chapterId?(S(),I.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case P.setMaxWeightBranch.trim().toLowerCase():{let y=Yr(g);return y!=null&&y.chapterId?(S(),I.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case P.setMinWeightBranch.trim().toLowerCase():{let y=Qr(g);return y!=null&&y.chapterId?(S(),I.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:y.chapterId,autoSelect:!0}})):void 0}case P.continuePlayback.trim().toLowerCase():return S(),x.bind(null,{subjectId:d,subjectName:"chapter",action:u});case P.openURI.trim().toLowerCase():return S(),_.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:console.error("Unexpected chapter event"),i.emit(E.errors,new W(1,1,{message:"Unexpected chapter event"}));return}};function v(d){let u=bi(d.events);if(u){if(oe(d))return;i.emit(E.interactives,{subjectId:d.id,subjectName:"chapter",type:L.actionChoice,actionType:u.action.type,payload:u.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:P.expect,action:T.bind(null,{subjectId:d.id,subjectName:"chapter"})})}else d.events.forEach(g=>{let S=h({chapterId:d.id,action:g.action,branches:d.branches});S&&t.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:g.action.type,action:S})})}let T=({subjectId:d,subjectName:u,action:g})=>{var S;e.pause(),i.emit(E.interactives,{subjectId:d,subjectName:u,type:L.actionExecution,actionType:(S=g==null?void 0:g.type)!=null?S:P.expect})},m=({subjectId:d,subjectName:u})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(E.interactives,{subjectId:d,subjectName:u,type:L.actionExecution,actionType:"after-expect"})},x=({subjectId:d,subjectName:u,subjectType:g,action:S})=>{i.emit(E.interactives,{subjectId:d,subjectName:u,subjectType:g,type:L.actionExecution,actionType:S.type})},I=({subjectId:d,subjectName:u,subjectType:g,action:S,payload:y})=>{y.behaviour="change-chapter",i.emit(E.interactives,{subjectId:d,subjectName:u,subjectType:g,type:L.actionExecution,actionType:S.type,payload:y})},V=({subjectId:d,subjectName:u,subjectType:g,action:S,payload:y})=>{y.behaviour="change-manifest",i.emit(E.interactives,{subjectId:d,subjectName:u,subjectType:g,type:L.actionExecution,actionType:S.type,payload:y})},_=({subjectId:d,subjectName:u,subjectType:g,action:S,payload:y})=>{if(!y.URI)return;let M=window.open(y.URI,"_blank","noopener,noreferrer");M&&(M.opener=null),i.emit(E.interactives,{subjectId:d,subjectName:u,subjectType:g,type:L.actionExecution,actionType:S.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:h,onExpectEvent:T,expectEventHandler:m,setManifestChapterEvents:v,setManifestContainerEvents:c,stopExpect:s,state:n}};var sr=ja(ma(),1);import{Subscription as Ml,ValueSubject as ht}from"@vkontakte/videoplayer-shared";var nr=(i,e)=>{let t={};return i.map(r=>{if(!t[r]){let n=e.chapters.find(l=>l.id===r);if(!n)return null;let s=e.media.videos.find(l=>n.videoId===l.id);if(!s)return null;t[r]=ya(s)}return t[r]}).filter(Boolean)},Vl=i=>{for(let e of i.variants)if(Rl(e)&&"payload"in e)return e.payload.id},Rl=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",ya=i=>{let e=Vl(i);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},Al=(i,e)=>{for(let t of i.media.videos)if(e===ya(t)){for(let r of i.chapters)if(r.videoId===t.id)return r.id;return}},va=(i,e)=>i.reduce((t,r)=>{let n=Al(e,r);return n?[...t,n]:t},[]);var ce,Ae,Me,te,zt,le,he,ne,Oe,Ue,ze,ut=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:r,historyApi:n,settings:s}){this.state={history$:new ht([]),hasPrevChapter$:new ht(!1),prevChapter$:new ht(null),isInitialChapter$:new ht(!1),isGoBackLimited$:new ht(!1)};w(this,ce,null);w(this,Ae);w(this,Me,!1);w(this,te,null);w(this,zt,null);w(this,le,null);w(this,he,null);w(this,ne,null);w(this,Oe,new Ml);w(this,Ue,!1);w(this,ze,0);var l,o,c;b(this,le,t),b(this,ne,e),b(this,he,r),b(this,ce,n),b(this,Ae,s),(l=this.state)!=null&&l.history$&&a(this,Oe)&&((c=a(this,Oe))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(h=>{var v,T,m,x,I,V;(v=this.state)==null||v.prevChapter$.next((0,sr.default)(h,-2)||null),(T=this.state)==null||T.hasPrevChapter$.next(h.length>1),(I=this.state)==null||I.isInitialChapter$.next(this.getInitialChapterId()===((x=(m=a(this,te))==null?void 0:m.metadata)==null?void 0:x.initChapterId)),(V=this.state)==null||V.isGoBackLimited$.next(a(this,ze)===a(this,Ae).maxLength-1)})))}setManifest(e){return R(this,null,function*(){!a(this,he)||!a(this,ne)||(b(this,te,e),yield this.getProjectHistory(),yield a(this,he).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,Me)||(b(this,Me,!0),a(this,ne).emit(E.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,Me)}updateHistory(e,t=!0){return R(this,null,function*(){var o,c;if(!a(this,te))return;a(this,Ue)?(b(this,Ue,!1),br(this,ze)._++):b(this,ze,0);let r=a(this,te),n=e.length-a(this,Ae).maxLength,s=n>0?e.slice(n):e,l=nr(s,r);if(b(this,zt,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!t||!a(this,ce)||!a(this,le)))try{yield a(this,ce).save(a(this,le),l)}catch(h){(c=a(this,ne))==null||c.emit(E.errors,new W(1,5,"Unable to save interactive history"))}})}goBack(){return R(this,null,function*(){var r;if(!this.state||!a(this,he))return(r=a(this,ne))==null?void 0:r.emit(E.errors,new W(1,5,"Cannot go back because HistoryController has not been initialized"));b(this,Ue,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),yield a(this,he).setChapter({chapterId:t})})}getProjectHistory(){return R(this,null,function*(){var n,s;if(!a(this,te)||!a(this,le))return;let e=a(this,te),t=[this.getInitialVideoId()];if(a(this,ce))try{let l=yield a(this,ce).get(a(this,le));l.length&&(t=l)}catch(l){(n=a(this,ne))==null||n.emit(E.errors,new W(1,5,"Error while trying to fetch data"))}let r=va(t,e);(s=this==null?void 0:this.state)==null||s.history$.next(r)})}getInitialChapterId(){var t,r;let e=(t=this.state)==null?void 0:t.history$.getValue();return(0,sr.default)(e,-1)||a(this,Ae).initChapterId||((r=a(this,te))==null?void 0:r.metadata.initChapterId)}getInitialVideoId(){if(a(this,te)){let e=this.getInitialChapterId();return nr([e],a(this,te)).pop()}return null}destroy(){var e,t;this.state=null,b(this,le,null),b(this,ce,null),b(this,he,null),(e=a(this,Oe))==null||e.unsubscribe(),b(this,Oe,null),b(this,Me,!1),(t=a(this,ne))==null||t.emit(E.historyDestroyed),b(this,ne,null)}};ce=new WeakMap,Ae=new WeakMap,Me=new WeakMap,te=new WeakMap,zt=new WeakMap,le=new WeakMap,he=new WeakMap,ne=new WeakMap,Oe=new WeakMap,Ue=new WeakMap,ze=new WeakMap;var Le=class Le{constructor(e,t,r,n){this.target=e,this.type=t,this.listener=r,this.options=Le._convertOptions(e,n),this.target.addEventListener(t,r,this.options)}unlisten(){var e;this.type&&this.listener&&this.options&&((e=this.target)==null||e.removeEventListener(this.type,this.listener,this.options)),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let r=new Set(["passive","capture"]),n=Object.keys(t).filter(l=>!r.has(l));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),Le._doesSupportObject(e)?t:t.capture||!1}}static _doesSupportObject(e){let t=Le._supportsObject;if(t===void 0){t=!1;try{let r={},n={get:()=>(t=!0,!1)};Object.defineProperty(r,"passive",n),Object.defineProperty(r,"capture",n);let s=()=>{};e.addEventListener("test",s,r),e.removeEventListener("test",s,r)}catch(r){t=!1}Le._supportsObject=t}return t||!1}};Le._supportsObject=void 0;var Wt=Le;var Kt=class{constructor(){this.bindingMap=new nt}release(){this.removeAll(),this.bindingMap=null}listen(e,t,r,n){if(!this.bindingMap)return;let s=new Wt(e,t,r,n);this.bindingMap.push(t,s)}listenOnce(e,t,r,n){let s=l=>{this.unlisten(e,t,s),r(l)};this.listen(e,t,s,n)}unlisten(e,t,r){if(!this.bindingMap)return;let n=this.bindingMap.get(t)||[];for(let s of n)s.target===e&&(r===s.listener||!r)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var Qt=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var n;let e=(n=this.rootElement.getContext("2d"))==null?void 0:n.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,r=t.length;for(let s=3;s<r;s+=40)if(t[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}updateCanvasDimensions(e,t=!1){return R(this,null,function*(){let r=e.width+e.height;if(this._prevSizeId===r)return;let n;t&&(n=yield this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=r})}save(){return R(this,null,function*(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,yield t.decode(),t})}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var Yt=class{constructor({parentElement:e,endOffsetMs:t=250,onError:r}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,r=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(r)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 Fa=Object.create;var cr=Object.defineProperty,$a=Object.defineProperties,Ba=Object.getOwnPropertyDescriptor,qa=Object.getOwnPropertyDescriptors,Da=Object.getOwnPropertyNames,vt=Object.getOwnPropertySymbols,Ha=Object.getPrototypeOf,lr=Object.prototype.hasOwnProperty,Si=Object.prototype.propertyIsEnumerable;var wi=r=>{throw TypeError(r)};var or=(r,e,t)=>e in r?cr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,p=(r,e)=>{for(var t in e||(e={}))lr.call(e,t)&&or(r,t,e[t]);if(vt)for(var t of vt(e))Si.call(e,t)&&or(r,t,e[t]);return r},T=(r,e)=>$a(r,qa(e));var z=(r,e)=>{var t={};for(var i in r)lr.call(r,i)&&e.indexOf(i)<0&&(t[i]=r[i]);if(r!=null&&vt)for(var i of vt(r))e.indexOf(i)<0&&Si.call(r,i)&&(t[i]=r[i]);return t};var v=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Ua=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Da(e))!lr.call(r,n)&&n!==t&&cr(r,n,{get:()=>e[n],enumerable:!(i=Ba(e,n))||i.enumerable});return r};var Ga=(r,e,t)=>(t=r!=null?Fa(Ha(r)):{},Ua(e||!r||!r.__esModule?cr(t,"default",{value:r,enumerable:!0}):t,r));var J=(r,e,t)=>or(r,typeof e!="symbol"?e+"":e,t),hr=(r,e,t)=>e.has(r)||wi("Cannot "+t);var a=(r,e,t)=>(hr(r,e,"read from private field"),t?t.call(r):e.get(r)),_=(r,e,t)=>e.has(r)?wi("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),E=(r,e,t,i)=>(hr(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t),P=(r,e,t)=>(hr(r,e,"access private method"),t);var _i=(r,e,t,i)=>({set _(n){E(r,e,n,t)},get _(){return a(r,e,i)}});var V=(r,e,t)=>new Promise((i,n)=>{var s=o=>{try{c(t.next(o))}catch(h){n(h)}},l=o=>{try{c(t.throw(o))}catch(h){n(h)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,l);c((t=t.apply(r,e)).next())});var ne=v((Or,dn)=>{"use strict";var at=function(r){return r&&r.Math===Math&&r};dn.exports=at(typeof globalThis=="object"&&globalThis)||at(typeof window=="object"&&window)||at(typeof self=="object"&&self)||at(typeof global=="object"&&global)||at(typeof Or=="object"&&Or)||function(){return this}()||Function("return this")()});var ve=v((Zp,fn)=>{"use strict";fn.exports=function(r){try{return!!r()}catch(e){return!0}}});var ot=v((Jp,mn)=>{"use strict";var xo=ve();mn.exports=!xo(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var En=v((ed,bn)=>{"use strict";var Io=ot(),gn=Function.prototype,yn=gn.apply,vn=gn.call;bn.exports=typeof Reflect=="object"&&Reflect.apply||(Io?vn.bind(yn):function(){return vn.apply(yn,arguments)})});var Re=v((td,In)=>{"use strict";var Cn=ot(),xn=Function.prototype,Nr=xn.call,To=Cn&&xn.bind.bind(Nr,Nr);In.exports=Cn?To:function(r){return function(){return Nr.apply(r,arguments)}}});var jr=v((rd,Sn)=>{"use strict";var Tn=Re(),So=Tn({}.toString),wo=Tn("".slice);Sn.exports=function(r){return wo(So(r),8,-1)}});var Pr=v((id,wn)=>{"use strict";var _o=jr(),Ro=Re();wn.exports=function(r){if(_o(r)==="Function")return Ro(r)}});var ge=v((nd,_n)=>{"use strict";var kr=typeof document=="object"&&document.all;_n.exports=typeof kr=="undefined"&&kr!==void 0?function(r){return typeof r=="function"||r===kr}:function(r){return typeof r=="function"}});var De=v((sd,Rn)=>{"use strict";var Vo=ve();Rn.exports=!Vo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var Wt=v((ad,Vn)=>{"use strict";var Mo=ot(),zt=Function.prototype.call;Vn.exports=Mo?zt.bind(zt):function(){return zt.apply(zt,arguments)}});var On=v(Ln=>{"use strict";var Mn={}.propertyIsEnumerable,An=Object.getOwnPropertyDescriptor,Ao=An&&!Mn.call({1:2},1);Ln.f=Ao?function(e){var t=An(this,e);return!!t&&t.enumerable}:Mn});var Fr=v((cd,Nn)=>{"use strict";Nn.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var Pn=v((ld,jn)=>{"use strict";var Lo=Re(),Oo=ve(),No=jr(),$r=Object,jo=Lo("".split);jn.exports=Oo(function(){return!$r("z").propertyIsEnumerable(0)})?function(r){return No(r)==="String"?jo(r,""):$r(r)}:$r});var Br=v((hd,kn)=>{"use strict";kn.exports=function(r){return r==null}});var qr=v((ud,Fn)=>{"use strict";var Po=Br(),ko=TypeError;Fn.exports=function(r){if(Po(r))throw new ko("Can't call method on "+r);return r}});var Bn=v((pd,$n)=>{"use strict";var Fo=Pn(),$o=qr();$n.exports=function(r){return Fo($o(r))}});var ct=v((dd,qn)=>{"use strict";var Bo=ge();qn.exports=function(r){return typeof r=="object"?r!==null:Bo(r)}});var Dr=v((fd,Dn)=>{"use strict";Dn.exports={}});var Gr=v((md,Un)=>{"use strict";var Hr=Dr(),Ur=ne(),qo=ge(),Hn=function(r){return qo(r)?r:void 0};Un.exports=function(r,e){return arguments.length<2?Hn(Hr[r])||Hn(Ur[r]):Hr[r]&&Hr[r][e]||Ur[r]&&Ur[r][e]}});var zn=v((yd,Gn)=>{"use strict";var Do=Re();Gn.exports=Do({}.isPrototypeOf)});var Yn=v((vd,Qn)=>{"use strict";var Ho=ne(),Wn=Ho.navigator,Kn=Wn&&Wn.userAgent;Qn.exports=Kn?String(Kn):""});var is=v((gd,rs)=>{"use strict";var ts=ne(),zr=Yn(),Xn=ts.process,Zn=ts.Deno,Jn=Xn&&Xn.versions||Zn&&Zn.version,es=Jn&&Jn.v8,te,Kt;es&&(te=es.split("."),Kt=te[0]>0&&te[0]<4?1:+(te[0]+te[1]));!Kt&&zr&&(te=zr.match(/Edge\/(\d+)/),(!te||te[1]>=74)&&(te=zr.match(/Chrome\/(\d+)/),te&&(Kt=+te[1])));rs.exports=Kt});var Wr=v((bd,ss)=>{"use strict";var ns=is(),Uo=ve(),Go=ne(),zo=Go.String;ss.exports=!!Object.getOwnPropertySymbols&&!Uo(function(){var r=Symbol("symbol detection");return!zo(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&ns&&ns<41})});var Kr=v((Ed,as)=>{"use strict";var Wo=Wr();as.exports=Wo&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Qr=v((Cd,os)=>{"use strict";var Ko=Gr(),Qo=ge(),Yo=zn(),Xo=Kr(),Zo=Object;os.exports=Xo?function(r){return typeof r=="symbol"}:function(r){var e=Ko("Symbol");return Qo(e)&&Yo(e.prototype,Zo(r))}});var ls=v((xd,cs)=>{"use strict";var Jo=String;cs.exports=function(r){try{return Jo(r)}catch(e){return"Object"}}});var Yr=v((Id,hs)=>{"use strict";var ec=ge(),tc=ls(),rc=TypeError;hs.exports=function(r){if(ec(r))return r;throw new rc(tc(r)+" is not a function")}});var ps=v((Td,us)=>{"use strict";var ic=Yr(),nc=Br();us.exports=function(r,e){var t=r[e];return nc(t)?void 0:ic(t)}});var fs=v((Sd,ds)=>{"use strict";var Xr=Wt(),Zr=ge(),Jr=ct(),sc=TypeError;ds.exports=function(r,e){var t,i;if(e==="string"&&Zr(t=r.toString)&&!Jr(i=Xr(t,r))||Zr(t=r.valueOf)&&!Jr(i=Xr(t,r))||e!=="string"&&Zr(t=r.toString)&&!Jr(i=Xr(t,r)))return i;throw new sc("Can't convert object to primitive value")}});var ys=v((wd,ms)=>{"use strict";ms.exports=!0});var bs=v((_d,gs)=>{"use strict";var vs=ne(),ac=Object.defineProperty;gs.exports=function(r,e){try{ac(vs,r,{value:e,configurable:!0,writable:!0})}catch(t){vs[r]=e}return e}});var ei=v((Rd,xs)=>{"use strict";var oc=ys(),cc=ne(),lc=bs(),Es="__core-js_shared__",Cs=xs.exports=cc[Es]||lc(Es,{});(Cs.versions||(Cs.versions=[])).push({version:"3.38.0",mode:oc?"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 Ss=v((Vd,Ts)=>{"use strict";var Is=ei();Ts.exports=function(r,e){return Is[r]||(Is[r]=e||{})}});var ti=v((Md,ws)=>{"use strict";var hc=qr(),uc=Object;ws.exports=function(r){return uc(hc(r))}});var Qt=v((Ad,_s)=>{"use strict";var pc=Re(),dc=ti(),fc=pc({}.hasOwnProperty);_s.exports=Object.hasOwn||function(e,t){return fc(dc(e),t)}});var Vs=v((Ld,Rs)=>{"use strict";var mc=Re(),yc=0,vc=Math.random(),gc=mc(1 .toString);Rs.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+gc(++yc+vc,36)}});var Ls=v((Od,As)=>{"use strict";var bc=ne(),Ec=Ss(),Ms=Qt(),Cc=Vs(),xc=Wr(),Ic=Kr(),He=bc.Symbol,ri=Ec("wks"),Tc=Ic?He.for||He:He&&He.withoutSetter||Cc;As.exports=function(r){return Ms(ri,r)||(ri[r]=xc&&Ms(He,r)?He[r]:Tc("Symbol."+r)),ri[r]}});var Ps=v((Nd,js)=>{"use strict";var Sc=Wt(),Os=ct(),Ns=Qr(),wc=ps(),_c=fs(),Rc=Ls(),Vc=TypeError,Mc=Rc("toPrimitive");js.exports=function(r,e){if(!Os(r)||Ns(r))return r;var t=wc(r,Mc),i;if(t){if(e===void 0&&(e="default"),i=Sc(t,r,e),!Os(i)||Ns(i))return i;throw new Vc("Can't convert object to primitive value")}return e===void 0&&(e="number"),_c(r,e)}});var ii=v((jd,ks)=>{"use strict";var Ac=Ps(),Lc=Qr();ks.exports=function(r){var e=Ac(r,"string");return Lc(e)?e:e+""}});var Bs=v((Pd,$s)=>{"use strict";var Oc=ne(),Fs=ct(),ni=Oc.document,Nc=Fs(ni)&&Fs(ni.createElement);$s.exports=function(r){return Nc?ni.createElement(r):{}}});var si=v((kd,qs)=>{"use strict";var jc=De(),Pc=ve(),kc=Bs();qs.exports=!jc&&!Pc(function(){return Object.defineProperty(kc("div"),"a",{get:function(){return 7}}).a!==7})});var Us=v(Hs=>{"use strict";var Fc=De(),$c=Wt(),Bc=On(),qc=Fr(),Dc=Bn(),Hc=ii(),Uc=Qt(),Gc=si(),Ds=Object.getOwnPropertyDescriptor;Hs.f=Fc?Ds:function(e,t){if(e=Dc(e),t=Hc(t),Gc)try{return Ds(e,t)}catch(i){}if(Uc(e,t))return qc(!$c(Bc.f,e,t),e[t])}});var zs=v(($d,Gs)=>{"use strict";var zc=ve(),Wc=ge(),Kc=/#|\.prototype\./,lt=function(r,e){var t=Yc[Qc(r)];return t===Zc?!0:t===Xc?!1:Wc(e)?zc(e):!!e},Qc=lt.normalize=function(r){return String(r).replace(Kc,".").toLowerCase()},Yc=lt.data={},Xc=lt.NATIVE="N",Zc=lt.POLYFILL="P";Gs.exports=lt});var Qs=v((Bd,Ks)=>{"use strict";var Ws=Pr(),Jc=Yr(),el=ot(),tl=Ws(Ws.bind);Ks.exports=function(r,e){return Jc(r),e===void 0?r:el?tl(r,e):function(){return r.apply(e,arguments)}}});var Xs=v((qd,Ys)=>{"use strict";var rl=De(),il=ve();Ys.exports=rl&&il(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var Js=v((Dd,Zs)=>{"use strict";var nl=ct(),sl=String,al=TypeError;Zs.exports=function(r){if(nl(r))return r;throw new al(sl(r)+" is not an object")}});var ra=v(ta=>{"use strict";var ol=De(),cl=si(),ll=Xs(),Yt=Js(),ea=ii(),hl=TypeError,ai=Object.defineProperty,ul=Object.getOwnPropertyDescriptor,oi="enumerable",ci="configurable",li="writable";ta.f=ol?ll?function(e,t,i){if(Yt(e),t=ea(t),Yt(i),typeof e=="function"&&t==="prototype"&&"value"in i&&li in i&&!i[li]){var n=ul(e,t);n&&n[li]&&(e[t]=i.value,i={configurable:ci in i?i[ci]:n[ci],enumerable:oi in i?i[oi]:n[oi],writable:!1})}return ai(e,t,i)}:ai:function(e,t,i){if(Yt(e),t=ea(t),Yt(i),cl)try{return ai(e,t,i)}catch(n){}if("get"in i||"set"in i)throw new hl("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var na=v((Ud,ia)=>{"use strict";var pl=De(),dl=ra(),fl=Fr();ia.exports=pl?function(r,e,t){return dl.f(r,e,fl(1,t))}:function(r,e,t){return r[e]=t,r}});var oa=v((Gd,aa)=>{"use strict";var ht=ne(),ml=En(),yl=Pr(),vl=ge(),gl=Us().f,bl=zs(),Ue=Dr(),El=Qs(),Ge=na(),sa=Qt();ei();var Cl=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 ml(r,this,arguments)};return e.prototype=r.prototype,e};aa.exports=function(r,e){var t=r.target,i=r.global,n=r.stat,s=r.proto,l=i?ht:n?ht[t]:ht[t]&&ht[t].prototype,c=i?Ue:Ue[t]||Ge(Ue,t,{})[t],o=c.prototype,h,m,y,f,I,w,C,S,d;for(f in e)h=bl(i?f:t+(n?".":"#")+f,r.forced),m=!h&&l&&sa(l,f),w=c[f],m&&(r.dontCallGetSet?(d=gl(l,f),C=d&&d.value):C=l[f]),I=m&&C?C:e[f],!(!h&&!s&&typeof w==typeof I)&&(r.bind&&m?S=El(I,ht):r.wrap&&m?S=Cl(I):s&&vl(I)?S=yl(I):S=I,(r.sham||I&&I.sham||w&&w.sham)&&Ge(S,"sham",!0),Ge(c,f,S),s&&(y=t+"Prototype",sa(Ue,y)||Ge(Ue,y,{}),Ge(Ue[y],f,I),r.real&&o&&(h||!o[f])&&Ge(o,f,I)))}});var la=v((zd,ca)=>{"use strict";var xl=Math.ceil,Il=Math.floor;ca.exports=Math.trunc||function(e){var t=+e;return(t>0?Il:xl)(t)}});var hi=v((Wd,ha)=>{"use strict";var Tl=la();ha.exports=function(r){var e=+r;return e!==e||e===0?0:Tl(e)}});var pa=v((Kd,ua)=>{"use strict";var Sl=hi(),wl=Math.min;ua.exports=function(r){var e=Sl(r);return e>0?wl(e,9007199254740991):0}});var fa=v((Qd,da)=>{"use strict";var _l=pa();da.exports=function(r){return _l(r.length)}});var ya=v((Yd,ma)=>{"use strict";ma.exports=function(){}});var va=v(()=>{"use strict";var Rl=oa(),Vl=ti(),Ml=fa(),Al=hi(),Ll=ya();Rl({target:"Array",proto:!0},{at:function(e){var t=Vl(this),i=Ml(t),n=Al(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:t[s]}});Ll("at")});var ba=v((Jd,ga)=>{"use strict";var Ol=Gr();ga.exports=Ol});var Ca=v((ef,Ea)=>{"use strict";va();var Nl=ba();Ea.exports=Nl("Array","at")});var Ia=v((tf,xa)=>{"use strict";var jl=Ca();xa.exports=jl});var Sa=v((rf,Ta)=>{"use strict";var Pl=Ia();Ta.exports=Pl});var Ri="1.0.16-dev.4f41c335.0";function ur(r,e=1){let t="0",i="0",n="0";return r.length===4?(t="0x"+r[1]+r[1],i="0x"+r[2]+r[2],n="0x"+r[3]+r[3]):r.length===7&&(t="0x"+r[1]+r[2],i="0x"+r[3]+r[4],n="0x"+r[5]+r[6]),`rgba(${+t},${+i},${+n},${e})`}var D="SDK_NAME",za="SDK_NAME-controls-container",gt=()=>document.querySelector(`.${za}`),Li=.4,Q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Vi={top:"flex-start",bottom:"flex-end",center:"center"},Mi={start:"flex-start",end:"flex-end",center:"center"},Ai={start:"left",end:"right",center:"center"},bt=({target:r,props:e})=>{var t,i,n,s,l,c;r.style.alignItems=(i=Vi[(t=e==null?void 0:e.text)==null?void 0:t.gravityVertical])!=null?i:Vi.center,r.style.justifyContent=(s=Mi[(n=e==null?void 0:e.text)==null?void 0:n.gravityHorizontal])!=null?s:Mi.center,r.style.textAlign=(c=Ai[(l=e==null?void 0:e.text)==null?void 0:l.alignment])!=null?c:Ai.start},Et=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,l,c,o,h;r.style.color=(s=(n=e==null?void 0:e.text)==null?void 0:n.color)!=null?s:t.textColor,r.style.fontSize=`calc(${i.height} * ${(c=(l=e==null?void 0:e.text)==null?void 0:l.size)!=null?c:t.textSize})`,r.textContent=(h=(o=e==null?void 0:e.text)==null?void 0:o.value)!=null?h:t.textContent},Ct=({target:r,props:e,fallback:t})=>{var i,n,s,l;r.style.backgroundColor=ur((n=(i=e==null?void 0:e.background)==null?void 0:i.color)!=null?n:t.backgroundColor,(l=(s=e==null?void 0:e.background)==null?void 0:s.alpha)!=null?l:t.backgroundAlpha)},xt=({target:r,props:e,fallback:t,dependsOn:i})=>{var n,s,l,c,o,h,m,y,f,I,w;r.style.border=`calc(${i.height} * ${(l=(s=(n=e==null?void 0:e.shape)==null?void 0:n.border)==null?void 0:s.width)!=null?l:t.borderWidth}) solid ${ur((h=(o=(c=e==null?void 0:e.shape)==null?void 0:c.border)==null?void 0:o.color)!=null?h:t.borderColor,(f=(y=(m=e==null?void 0:e.shape)==null?void 0:m.border)==null?void 0:y.alpha)!=null?f:t.borderAlpha)}`,r.style.borderRadius=`calc(${i.height} * ${(w=(I=e==null?void 0:e.shape)==null?void 0:I.roundCorners)!=null?w:t.roundCorners})`},Pe=({target:r,layoutParams:e,fallback:t})=>{r.style.transform=`rotate(${-e.angle}rad)`};var pr="int",ke={AREA:`${pr}_area`,TEXT:`${pr}_text`,BUTTON:`${pr}_bttn`};var fe=class{constructor(e){this.control=e}createView(e){var n;let t=document.createElement("div");t.classList.add(`${D}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let i=((n=this.control.layoutParams.innerSizesDependOn)!=null?n:Q.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:t,dependsOn:i}}setEvents(e,t){e&&this.control.events.forEach(i=>{switch(i.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",s=>{s.stopPropagation(),t&&t({action:i.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${D}-control-container-${this.control.id}`)}};var It=r=>{if(r.type.trim().toLowerCase()==="area")return new dr(r)},dr=class extends fe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("button");return s.classList.add(`${D}-${this.control.id}`),s.setAttribute("data-testid",ke.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",Ct({target:s,props:this.control.props,fallback:T(p({},Q),{backgroundColor:"transparent"})}),xt({target:s,props:this.control.props,fallback:T(p({},Q),{borderAlpha:0}),dependsOn:i}),Pe({target:s,layoutParams:this.control.layoutParams,fallback:Q}),n.append(s),e.append(n),this.controlEl=s,n}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var Tt=()=>{let r=document.createElement("span");return r.style.display="inline-block",r.style.whiteSpace="pre",r.style.overflow="hidden",r.style.textOverflow="ellipsis",r.style.maxWidth="100%",r.style.maxHeight="100%",r};var St=r=>{if(r.type.trim().toLowerCase()==="button")return new fr(r)},fr=class extends fe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("button");s.type="button",s.classList.add(`${D}-${this.control.id}`),s.setAttribute("data-testid",ke.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=Tt();return Pe({target:s,layoutParams:this.control.layoutParams,fallback:Q}),Ct({target:s,props:this.control.props,fallback:Q}),xt({target:s,props:this.control.props,fallback:Q,dependsOn:i}),bt({target:s,props:this.control.props}),Et({target:l,props:this.control.props,fallback:Q,dependsOn:i}),s.append(l),n.append(s),e.append(n),this.controlEl=s,n}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var Oi=r=>{if(r.type.trim().toLowerCase()==="text")return new mr(r)},mr=class extends fe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){let{dependsOn:i,controlContainerEl:n}=super.createView(t),s=document.createElement("div");s.classList.add(`${D}-${this.control.id}`),s.setAttribute("data-testid",ke.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=Tt();return Pe({target:s,layoutParams:this.control.layoutParams,fallback:Q}),bt({target:s,props:this.control.props}),Et({target:l,props:this.control.props,fallback:Q,dependsOn:i}),s.append(l),n.append(s),e.append(n),this.controlEl=s,n}disable(){}enable(){}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var yr=class{constructor(e){this.layout=e}},Ni=r=>{if(r.type.trim().toLowerCase()==="relative")return new Qe(r)},Qe=class extends yr{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var me,wt,ji,Fe=class{constructor(e){_(this,me);this.container=e,this.factories=new Map,P(this,me,wt).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),P(this,me,wt).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),P(this,me,wt).call(this)}};me=new WeakSet,wt=function(){this.controls=P(this,me,ji).call(this)},ji=function(){var e;return(e=this.container.controls)==null?void 0:e.reduce((t,i)=>{let n=i.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...t,s(i)]:[...t]},[])};var _t=(r,e)=>{if(r.type.trim().toLowerCase()==="choice")return new vr(r,e)},vr=class extends Fe{constructor(e,t){super(e),this.rootElement=t!=null?t:gt(),this.layout=new Qe(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",St),this.addControlFactory("text",Oi),this.addControlFactory("area",It)}createView(e){let t=document.createElement("div");return t.classList.add(`${D}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(i=>{let n=i.createView({parent:t,layoutFn:this.layout.setControlLayout});i.setEvents(n,e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity=1,this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=Li,this.isDisabled=!0)}removeView(){var e;this.isRemoved||((e=this.getElement())==null||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${D}-${this.container.id}`)}};import{Subject as ql,ValueSubject as ie,Observable as Va,once as Dl,Subscription as Hl,clientChecker as Ul,combine as Gl}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as dt}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Wa}from"@vkontakte/videoplayer-shared";function Rt(r,e){let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>r(...i),e)}}var Se=(r,e)=>Object.prototype.toString.call(r)===`[object ${e}]`,Ye=r=>Se(r,"Object"),Vt=r=>Se(r,"String"),Mt=r=>Se(r,"Array"),At=r=>Se(r,"Number"),Pi=r=>Se(r,"Function");var gr=r=>At(r)&&!isNaN(r);var we=r=>Ye(r)&&Object.keys(r).length===0,br=r=>Mt(r)&&!r.length;var Xe=(r,e)=>Vt(r)&&(e?r.trim():r).length;var ki="video_interactive",Fi="videoint";var Ka=250,Ze=class{constructor(e){J(this,"onResize",e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))});J(this,"handleChapterChange",e=>{var t;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(t=this.onError)==null||t.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}});J(this,"handleManifestChange",(i,...n)=>V(this,[i,...n],function*(e,t=[]){var s;if(!At(e.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)==null||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let l;try{l=yield Wa(this.lang,ki,Fi)}catch(o){console.log("Unable to load graph language pack")}let{GraphEditor:c}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new c(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:l}),this.ngEditor.on("control",({name:o,chapterId:h})=>{o==="openPreview"&&this.onOpenPreviewClick(h)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo=p({},o)})}this.visitedChapterIds=new Set(t),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0}));this.init(e)}init({root:e,onOpenPreviewClick:t,onError:i,lang:n,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=i,this.lang=n!=null?n:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=Qa(e),this.resizeObserver=new ResizeObserver(Rt(this.onResize,Ka)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return[(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)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)==null||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)==null||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Qa(r){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",r.append(e),e}var Je=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let l=s.startTime-e;if(l<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<l&&(t=t===-1?l:Math.min(t,l))}return!i&&t!==-1?t:null}}};var ye=(r="",e="")=>{let t=r.split("."),i=e.split("."),n=0;for(let s=0;s<Math.max(t.length,i.length)&&!n;s++)t[s]>i[s]?n=1:t[s]<i[s]?n=-1:n=0;return n};import{v4 as Ya}from"uuid";var Xa="3.1",$i={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Za={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Bi=r=>{let e=[];for(let l of r.chapters){let c,o=[];for(let t of l.branches){let i=t,{isDefault:y}=i,f=z(i,["isDefault"]);y&&(c=f.id),o.push(f)}let h=[],m=[];for(let n of l.containers){let s=n,{fallbackStrategy:y}=s,f=z(s,["fallbackStrategy"]);let I=!!f.endTime,w=[Za];switch(y){case"await":I?w=[]:h=[];break;case"default":{let C={type:"onSuspense",action:{type:$i.default,args:{branchId:c,shouldOpenNow:!I,isDetachContainer:!0}}};I?w=[C]:h=[C];break}case"random":case"weightlessRandom":case"max":case"min":{let C={type:"onSuspense",action:{type:$i[y],args:{}}};I?w=[C]:h=[C];break}}for(let C of f.controls)m.push(T(p({},f),{controls:[p({},C)],id:Ya(),events:w}))}e.push(T(p({},l),{containers:m,events:h,branches:o}))}return r.metadata.version=Xa,r.metadata.updated=new Date().toISOString(),T(p({},r),{chapters:e})};var Ja="3.2",qi=r=>{if(!r.media){let e=r.metadata,{media:t}=e,i=z(e,["media"]);return T(p({},r),{metadata:T(p({},i),{version:Ja}),media:t})}return r};var eo="3.3",to=(r=[])=>({edit:{chapters:r},view:{}}),Di={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Hi=r=>{var n;let e=[],t=[];for(let s of r.chapters){let i=s,{id:l,x:c,y:o}=i,h=z(i,["id","x","y"]),m=h.containers.map(y=>{var f;return T(p({},y),{controls:y.controls.map(S=>{var d=S,{subtype:I,type:w}=d,C=z(d,["subtype","type"]);return T(p({},C),{type:I!=null?I:w})}),events:(f=y.events)!=null&&f.length?y.events:[Di]})});e.push(T(p({id:l},h),{containers:m,events:(n=h.events)!=null&&n.length?h.events:[Di]})),t.push({id:l,x:c,y:o})}return T(p({},r),{chapters:e,graph:to(t),metadata:T(p({},r.metadata),{version:eo})})};var ro=[{version:"3.0",migrate:Bi},{version:"3.1",migrate:qi},{version:"3.2",migrate:Hi}],Er=r=>ro.reduce((e,t)=>ye(e.metadata.version,t.version)?e:t.migrate(e),r);var hu=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Ui=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),uu=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),N=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var Gi={metadata:"Object",chapters:"Array"},io="3.0.0",no="3.3.0",Lt=r=>{let e=ye(r,io);return e===-1?!1:e===0?!0:ye(r,no)!==1},zi=r=>{if(!Ye(r))return!1;for(let e in Gi)if(!r[e]||!Se(r[e],Gi[e]))return!1;return Lt(r.metadata.version)},Ot=r=>r.type===Ui.Text;var W=class{constructor(e,t,...i){this.severity=e;this.category=t;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var $e=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let i=()=>{t(),this.off(e,i)};return this.listeners[e].push(i),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let i=this.listeners[e]||[];for(let n=i.length;n>0;n--)if(i[n]===t){i.splice(n,1);break}return this}emit(e,...t){let i=this.listeners[e];return i?(i.forEach(n=>{n(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Nt=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{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)};this.fn=e,this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as uo}from"@vkontakte/videoplayer-shared";var jt=class{constructor(e){var t,i;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!=null?t:[],manifestLoaders:(i=e==null?void 0:e.manifestLoaders)!=null?i:[]}}exec(e,t){return V(this,null,function*(){return so(...this.loaders[e])(t)})}};function so(...r){return function(t){return V(this,null,function*(){let i=[...r];for(;i.length>0;)t=yield i.shift()(t);return t})}}function et(r,e,t){return r?T(p({},r),{[e]:r[e]?[t,...r[e]]:[t]}):{[e]:[t]}}function Pt(n){var s=n,{actions:r,errors:e,chapterId:t}=s,i=z(s,["actions","errors","chapterId"]);if(t){let l=r.getManifest(),c=r.getChapter(l.chapters,t);if(c){let o=r.getMedia(l.media,c.videoId),h=r.getGraph(l.graph,c.id);return o?T(p({},i),{actions:r,errors:e,result:{chapter:c,media:o,graph:h}}):T(p({},i),{errors:et(e,Pt.name,"Could not find media"),actions:r})}}return T(p({},i),{errors:et(e,Pt.name,"Could not find chapter"),actions:r})}var kt=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,s=i.length;n<s;n++)if(i[n].callback===t){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,s=i.length;n<s;n++){let l=i[n];try{l.callback.call(this,e)}catch(c){Promise.resolve().then(()=>{throw c})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},Be=class extends kt{constructor(){super(),this.listeners||kt.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)}},tt=class{constructor(){Object.defineProperty(this,"signal",{value:new Be,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(n){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document=="undefined")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch(n){i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol!="undefined"&&Symbol.toStringTag&&(tt.prototype[Symbol.toStringTag]="AbortController",Be.prototype[Symbol.toStringTag]="AbortSignal");function Ft(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function Cr(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=r;if(!Ft({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||n)&&(s=function(h,m){let y;m&&m.signal&&(y=m.signal,delete m.signal);let f=new t(h,m);return y&&Object.defineProperty(f,"signal",{writable:!1,enumerable:!1,configurable:!0,value:y}),f},s.prototype=t.prototype);let l=e;return{fetch:(o,h)=>{let m=s&&s.prototype.isPrototypeOf(o)?o.signal:h?h.signal:void 0;if(m){let y;try{y=new DOMException("Aborted","AbortError")}catch(I){y=new Error("Aborted"),y.name="AbortError"}if(m.aborted)return Promise.reject(y);let f=new Promise((I,w)=>{m.addEventListener("abort",()=>w(y),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([f,l(o,h)])}return l(o,h)},Request:s}}var rt=Ft({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Wi=rt?Cr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,xr=rt?Wi.fetch:window.fetch,Fu=rt?Wi.Request:window.Request,$u=rt?tt:window.AbortController,Bu=rt?Be:window.AbortSignal;var ao=r=>V(void 0,null,function*(){try{let e={},t;if(Vt(r)){t=new URL(r).href;let n=yield xr(t);if(!n.ok)return{};e=yield n.json()}else if(Ye(r))e=r;else return{};if(!zi(e))return{};let i=e.metadata.media;if(Vt(i)&&!e.media)try{let n;t?n=new URL(i,t).href:(n=new URL(i).href,t=n);let s=yield xr(n);if(!s.ok)throw new Error;e.metadata.media=yield s.json()}catch(n){return lo(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}});function Ki(r){return V(this,null,function*(){let{manifest:e,manifestURL:t}=yield ao(r),i=Er(e);return i.media=oo(i.media,t),delete i.metadata.media,i})}function $t(r,e){if(e)return r.find(t=>t.id===e)}function Ir(r,e){var t,i;return(t=r.edit)!=null&&t.chapters?r.edit.chapters.find(n=>n.id===e):(i=r.view)!=null&&i.chapters?r.view.chapters.find(n=>n.id===e):void 0}function Tr(r,e){return r.videos.find(t=>t.id===e)}function oo(r,e){return T(p({},r),{videos:r.videos.map(t=>T(p({},t),{variants:t.variants.map(i=>{let n="url"in i?i.url:"",s=co(n,e);return T(p({},i),{url:s||n})})}))})}function co(r="",e){try{return new URL(r,e).href}catch(t){return""}}function lo(r){return ye(r,"3.2.0")>=0}var k=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Bt=r=>Mt(r)&&!br(r),se=r=>r.order==="end",qt=r=>Mt(r.containers)&&!br(r.containers)&&se(r),Qi=(r,e)=>{var i;let t=r*1e3;return Bt(e.controls)&&t<((i=e.startTime)!=null?i:0)},Sr=(r,e)=>{var i,n;let t=r*1e3;return Bt(e.controls)&&t>=((i=e.startTime)!=null?i:0)&&t<=((n=e.endTime)!=null?n:1/0)};var _e=r=>r.some(e=>e.action.type==="expect"),wr=r=>r.find(e=>e.action.type==="expect"),ho=r=>(r==null?void 0:r.length)===1,Dt=r=>ho(r)&&Ot(r[0]);var Yi=({fn:r,type:e=1},...t)=>(...i)=>e?r(...i,...t):r(p(p({},i[e]),t[e])),Xi=(r,e)=>_e(r.events)?!1:e.some(({container:t})=>t.container.id!==r.id&&_e(t.container.events)&&t.container.endTime===r.endTime&&!t.isRemoved);var qe=class extends jt{constructor(t,i){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new uo(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){return V(this,null,function*(){var n;this.release();let i=yield this.exec("manifestLoaders",{actions:{addErrorMessage:et},result:null,errors:null,source:t});return i.errors&&this.errorHandler(i.errors),this.manifest=yield Ki((n=i.result)!=null?n:t),this})}setInitial(){return V(this,null,function*(){return this.setNext()})}setNext(){return V(this,arguments,function*(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t)return this;this.prevChapter$.next(this.chapter);let n=yield this.exec("chapterLoaders",Pt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Ir,getChapter:$t,getMedia:Tr,getByBranches:this.getByBranches.bind(this),addErrorMessage:et},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this})}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){var i;return this.getByChapterId((i=this.manifest)==null?void 0:i.metadata.initChapterId)||null}getByChapterId(t=(i=>(i=this.manifest)==null?void 0:i.metadata.initChapterId)()){if(!t||!this.manifest)return null;let n=$t(this.manifest.chapters,t);if(n){let s=Tr(this.manifest.media,n.videoId),l=Ir(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:l}}return null}getBranches(t=(i=>(i=this.chapter)==null?void 0:i.id)()){var n,s,l;if(t===((n=this.chapter)==null?void 0:n.id))return this.getByBranches((s=this.chapter)==null?void 0:s.branches);{let c=$t(((l=this.manifest)==null?void 0:l.chapters)||[],t);return this.getByBranches(c==null?void 0:c.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{let s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){var t,i;return((t=this.chapter)==null?void 0:t.id)===((i=this.manifest)==null?void 0:i.metadata.initChapterId)}isEndChapter(){return se(this.chapter)}};import{Player as po}from"@vkontakte/videoplayer-core";import{Subscription as Ji}from"@vkontakte/videoplayer-shared";var Zi=r=>{let e=r.variants.find(t=>{var i;return((i=t.payload)==null?void 0:i.type)==="vk"});if(e&&"payload"in e){let[t,i]=e.payload.id.split("_");return[t,i]}return[]};var x={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},it={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function _r(){let r=new Map;function e(o){var h=o,{listId:s=Math.random().toString(),itemId:l=Math.random().toString()}=h,c=z(h,["listId","itemId"]);let m=r.get(s),y=p({},c);return m?m[l]=y:r.set(s,{[l]:y}),p({listId:s,itemId:l},c)}function t(s){var l,c;s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),(l=s.statistics)==null||l.oneStat.destroy(),(c=s.statistics)==null||c.statSubscription.unsubscribe()}function i(s,l){let c=r.get(s);if(!c)throw Error("Can't remove. Not find.");if(l){let o=c[l];o&&t(o),delete c[l],Object.keys(c).length||r.delete(s)}else{for(let o of Object.values(c))t(o);r.delete(s)}}function n(){for(let s of r)i(s[0])}return{createPlayer:e,removePlayer:i,map:r,removeAll:n}}function Rr(r,e=[]){var s,l,c;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||e.includes("mp4"))&&(t.MPEG=T(p({},t.MPEG),{[(s=o.standard)!=null?s:"Invariant quality"]:o.url}));break;case"mpeg":(n||e.includes("mpeg"))&&(t.MPEG=T(p({},t.MPEG),{[(l=o.standard)!=null?l:"Invariant quality"]:o.url}));break;case"hls":(n||e.includes("hls"))&&(t=T(p({},t),{HLS:{type:"url",url:o.url}}));break;case"dash":(n||e.includes("dash"))&&(t=T(p({},t),{DASH_SEP:{compatibilityMode:!0,type:"url",url:o.url}}));break;default:break}return{sources:t,thumbUrl:i,title:(c=r.title)!=null?c:""}}var nt=(r,e)=>{let t=r.info.currentQuality$.getValue(),i=r.info.availableQualities$.getValue();t!==e&&i.includes(e)&&(r.setQuality(e),r.setAutoQuality(!1))};var Ht={activePlayerChanged:"sc-active-player-changed",playerCreated:"sc-player-created"},fo=2;function Vr(r){let e=_r(),t=new $e,i={},n=null,s=!1,l;r&&c(r);function c(C){n=C}function o(C,S,d){var R;if(!n)throw Error("need to set interactive controller");if(!n.options)return;let b=((R=e.map.get(C))!=null?R:{})[S];if(b){i=p({chapterId:d,listId:C,itemId:S},b);let g=i.player;i.subscription.add(g.info.currentQuality$.subscribe(F=>{let B=g.info.position$.getValue(),G=g.info.isAutoQualityEnabled$.getValue();if(!(!F||!B||G))for(let M of e.map)Object.values(M[1]).forEach(({player:$})=>{nt($,F)})})).add(g.events.started$.subscribe(()=>{h(S)})),b.container.remove(),n.setPlayer(b.player),s||(n.init(),s=!0),t.emit(Ht.activePlayerChanged,{player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}function h(C){return V(this,null,function*(){if(!n)throw Error("need to set interactive controller");if(we(i)||C!==i.itemId)return;let S=n.getChapterBranches(),d=new Set;for(let u of S)d.has(u.media.id)||(yield y({media:u.media,chapterId:u.chapter.id,setAsActive:!1,title:u.chapter.label}),d.add(u.media.id))})}function m(d){return V(this,arguments,function*({chapter:{id:C},media:S}){if(we(i))return;let u=i.player.info.muted$.getValue(),b=i.player.info.currentQuality$.getValue(),R=i.player.info.isAutoQualityEnabled$.getValue(),g=i.player.info.volume$.getValue(),F=i.player.info.currentPlaybackRate$.getValue(),B=!R,G=!1;for(let M of e.map)if(M[0]===S.id){let $=Object.keys(M[1]);for(let Z of $)Z===i.itemId?($.length<fo||(G=!0),e.removePlayer(M[0],Z)):(G=!0,o(M[0],Z,C),B?nt(i.player,b):i.player.setAutoQuality(!0),i.player.setVolume(g),i.player.setMuted(u),i.player.setPlaybackRate(F))}else e.removePlayer(M[0]);G||(yield y({media:S,chapterId:C,setAsActive:!0,playbackRate:F}),B?nt(i.player,b):i.player.setAutoQuality(!0),i.player.setVolume(g),i.player.setMuted(u))})}function y(B){return V(this,arguments,function*({media:C,chapterId:S,prefetch:d=!0,setAsActive:u=!0,autoplay:b=!1,preferredExt:R,title:g,playbackRate:F}){var gi,bi,Ei,Ci,xi;let G=Math.random().toString(),M=document.createElement("div");l.append(M);let $;if((gi=n==null?void 0:n.options)!=null&&gi.vkVideoLoader){let yt=Zi(C);yt.length&&($=yield n.options.vkVideoLoader(...yt))}let Z=((bi=n==null?void 0:n.options)==null?void 0:bi.coreConfig)||{},Ne=T(p({},Z),{configName:[...(Ei=Z.configName)!=null?Ei:[],"interactive"]}),je=T(p({container:M},((Ci=$==null?void 0:$.videos)==null?void 0:Ci[0])||{sources:Rr(C,R).sources}),{title:g,failoverHosts:($==null?void 0:$.failoverHosts)||[]}),de=new po(Ne);de.initVideo(je);let yi=null;if(n!=null&&n.options.createOneStat){let yt=$.videos[0],Ii=n.options.createOneStat(yt),Ti=new Ji;Ti.add(Ii.attachTo(de)),yi={oneStat:Ii,statSubscription:Ti}}let vi=new Ji,ka=(xi=i==null?void 0:i.player)==null?void 0:xi.info.isAutoQualityEnabled$.getValue();vi.add(de.events.canplay$.subscribe(function(){ka||nt(de,i.player.info.currentQuality$.getValue()),F&&de.setPlaybackRate(F)}));let Te=e.createPlayer({listId:C.id,itemId:G,player:de,container:M,sources:Rr(C,R).sources,config:je,subscription:vi,statistics:yi});return u&&o(C.id,Te.itemId,S),b&&Te.player.play(),d&&!b&&Te.player.prepare(),t.emit(Ht.playerCreated,Te.player),{player:Te.player,config:Te.config,statistics:Te.statistics}})}function f(){I(),n=null,l.remove()}function I(){n==null||n.off(x.chapterChanged,m),e.removeAll(),i={},s=!1}function w(){return V(this,null,function*(){if(!n)throw Error("need to set interactive controller");I(),l=document.createElement("div");let{media:C,chapter:S}=n.getCurrentChapter();C?(n.on(x.chapterChanged,m),yield y({media:C,chapterId:S.id,title:S.label})):console.error("not found")})}return T(p({},e),{on:t.on.bind(t),off:t.off.bind(t),init:w,setInteractiveController:c,createPlayer:y,removeAll:f,getActivePlayer:function(){return i}})}import{Subscription as mo}from"@vkontakte/videoplayer-shared";var Ut=class{constructor({player:e,container:t,branches:i,selectBranches:n,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:c,permanentTextControls:o,disabledControls$:h,onRemove:m}){J(this,"hide",()=>{setTimeout(()=>{var e,t;this.gameState!==k.end&&(_e(this.container.container.events)&&this.gameState===k.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==k.interactive&&((t=(e=this.container).hide)==null||t.call(e)),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})});J(this,"show",()=>{var e,t,i,n;if(this.gameState===k.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(n=(i=this.container).show)==null||n.call(i),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{let l=Yi({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(c,o)=>{this.isSelectedControlEvent=!0,c!==!1&&(this.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===k.end||this.gameState===k.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),o(),this.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1}))},isEOV:()=>this.gameState===k.end});this.container.createView(l),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((t=(e=this.container).disable)==null||t.call(e))}});J(this,"onEndOfVideo",()=>{this.gameState=k.end,this.selectContainerEvent(!0)});J(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[k.destroyed,k.removed].includes(this.gameState)&&!this.isPermanentText)return;let t=this.player.getExactTime();if(Qi(t,this.container.container))this.gameState!==k.beforeInteractive&&(this.gameState=k.beforeInteractive,this.onBeforeStartTime());else if(Sr(t,this.container.container))this.gameState!==k.interactive&&(this.gameState=k.interactive,this.onStartTime());else if(this.gameState!==k.afterInteractive){let c=this.gameState;this.gameState=k.afterInteractive,c===k.interactive&&this.onEndTime()}else this.gameState!==k.destroyed&&!this.isPermanentText&&this.removeView();let i=Sr(t,this.container.container),n=this.container.container.startTime?[this.container.container.startTime,(l=this.container.container.endTime)!=null?l:1/0]:[];this.globalEventEmitter.emit(x.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:n,currentTime:t,isInteractiveTime:i})});this.container=t,this.branches=i,this.selectBranches=n,this.subscription=new mo,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=c,this.isPermanentText=o&&Dt(t.container.controls),this.disabledControls$=h,this.onRemove=m,this.globalEventEmitter=l,this.gameState=k.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{var t,i,n,s;e?(i=(t=this.container).disable)==null||i.call(t):(s=(n=this.container).enable)==null||s.call(n)}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=_e(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)==null||t.call(e),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=k.beforeInteractive}removeView(){var e;this.container.removeView(),this.globalEventEmitter.emit(x.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=k.removed,(e=this.onRemove)==null||e.call(this)}destroy(){var e;this.reset(),this.removeView(),this.gameState=k.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(e=this.container.container.endTime)!=null?e:1/0,id:this.container.container.id})}};var en=(r=[])=>r.reduce((e,t,i)=>{var s,l,c;let n=((s=t==null?void 0:t.controls)!=null?s:[]).filter(o=>!Ot(o));if(Bt(n)){let o=[(l=t.startTime)!=null?l:0,(c=t.endTime)!=null?c:1/0],h=t.id;if(!i)e.push({subjects:[h],range:o});else{let m=[],y=-1/0,f=1/0,I=[],w=[];for(let C=0;C<e.length;C++){let S=e[C];if(w.push(...S.subjects),S.range[0]<f&&(f=S.range[0]),S.range[1]>y&&(y=S.range[1]),o[0]>=S.range[0]&&o[1]<=S.range[1])return e[C].subjects.push(h),e;o[0]<S.range[0]&&o[1]>S.range[0]&&(m.push(C),I=I.concat(S.subjects)),o[0]>=S.range[0]&&o[0]<=S.range[1]&&(m.push(C),I=I.concat(S.subjects),o[0]=S.range[0]),o[1]>=S.range[0]&&o[1]<=S.range[1]&&(m.push(C),I=I.concat(S.subjects),o[1]=S.range[1])}if(w.push(h),o[0]<=f&&o[1]>=y)return[{subjects:w,range:o}];m.length&&m.reverse().forEach(C=>{e.splice(C,1)}),e.push({subjects:I.concat([h]),range:o})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function tn(){let r={};function e(){for(let c in r)Object.prototype.hasOwnProperty.call(r,c)&&delete r[c];return!0}function t(c){let o={};for(let h in r)+h<=c&&(o[h]=r[h]);return o}function i(c){let o={};for(let h in r)+h>=c&&(o[h]=r[h]);return o}function n({timestamp:c,priority:o,initiator:h}){var m;if(gr(c)){let y=(m=r[c])!=null?m:null;if(y&&Xe(o,!0)){let f={},I=y[o];if(I&&(f=p(p({},f),I)),f=we(f)?null:f,f&&Xe(h,!0)){let w=f[h];return w!=null?w:null}return f}return y}return null}function s({timestamp:c,priority:o,initiator:h}){if(gr(c))if(r[c]){if(Xe(o,!0))if(r[c][o]){if(Xe(h,!0))if(r[c][o][h]){if(delete r[c][o][h],!we(r[c][o]))return!0}else return!1;if(delete r[c][o],!we(r[c]))return!0}else return!1;return delete r[c]}else return!1}function l(y){var f=y,{timestamp:c,priority:o,initiator:h}=f,m=z(f,["timestamp","priority","initiator"]);var I,w,C;(w=(I=r[c])==null?void 0:I[o])!=null&&w[h]?r[c][o][h].push(p({},m)):(C=r[c])!=null&&C[o]?r[c][o]=T(p({},r[c][o]),{[h]:[p({},m)]}):r[c]?r[c]=T(p({},r[c]),{[o]:{[h]:[p({},m)]}}):r[c]={[o]:{[h]:[p({},m)]}}}return{map:r,remove:s,add:l,removeAll:e,get:n,getLte:t,getGte:i}}var yo=[N.expect,N.setNextBranch],vo=1/0;function Mr(r){let e=r,t,i=go(),n=new tn,s,l=()=>{f(),d()},c=u=>{n.add.call(void 0,u),w()},o=(u=[])=>{for(let b of u)if(b.action(),yo.includes(b.actionType))break},h=(u=1/0)=>{var F,B,G;let b=Gt((F=n.get({timestamp:u,priority:"control"}))!=null?F:{}),R=Gt((B=n.get({timestamp:u,priority:"container"}))!=null?B:{}),g=Gt((G=n.get({timestamp:u,priority:"chapter"}))!=null?G:{});return[...b,...R,...g]},m=u=>{i.isReady(u)&&o(h(u))},y=()=>{var u;o([...Gt((u=n.get({timestamp:1/0,priority:"chapter"}))!=null?u:{})])},f=()=>{t&&(s==null||s.unsubscribe(),t=void 0)},I=u=>{},w=()=>{t||(t=()=>setTimeout(()=>{m(1/0)}),s=e.events.ended$.subscribe(t))},C=u=>{f(),e=u},S=u=>{u.priority==="container"&&i.resetCalled(u.timestamp),n.remove(u)},d=()=>{i.release(),n.removeAll()};return{setPlayer:C,add:c,remove:S,exec:m,execEndOfVideo:y,listen:w,unlisten:f,release:l,containersEventsCallState:i,getPreparedToExecActions:h}}function go(){let r=new Map;return{setCalled:({timestamp:l,id:c})=>{let o=r.get(l);o&&o[c]!==void 0&&(o[c]=!0)},setData:(l=[])=>{var c,o;for(let h of l){let m=(c=h.endTime)!=null?c:vo,y=(o=r.get(m))!=null?o:{};r.set(m,T(p({},y),{[h.id]:!1}))}},resetCalled:l=>{let c=r.get(l);if(c)for(let o in c)c[o]=!1},isReady:l=>{let c=r.get(l);return c?!Object.values(c).some(o=>!o):!0},release:()=>r.clear()}}function Gt(r){return Object.values(r).flat().sort(e=>e.actionType===N.expect?-1:1)}var rn={videoContentHeight:0,videoContentWidth:0},nn=(r,e)=>{let{height:t,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&i))return rn;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return rn;let l=t/i,c=n/s,o,h;return c>l?(h=s,o=s*l):c<l?(h=n/l,o=n):(h=s,o=n),{videoContentWidth:h,videoContentHeight:o}};var bo=250;function sn(r){let e=()=>{},t=new ResizeObserver(c=>{s(c),e=s.bind(null,c)});function i(c){let{parentElement:o,player:h}=r();if(o&&h){let{videoContentWidth:m,videoContentHeight:y}=nn(o,h);o.style.setProperty("--interactive-content-width",`${m}px`),o.style.setProperty("--interactive-content-height",`${y}px`),o.style.setProperty("--interactive-width",`${c[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${c[0].contentRect.height}px`)}}function n(){let{parentElement:c}=r();c.removeAttribute("style")}let s=Rt(c=>{let{fns:o=[]}=r();i(c);for(let h of o)h()},bo);function l(){e=void 0,t.disconnect(),n()}return{resizeObserver:t,calc:()=>{e()},release:l}}var st=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(i=>i!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var Eo=r=>Math.floor(Math.random()*r),an=r=>{let e=r.length,t=1/0,i=null;for(;e--;)r[e].weight<t&&(t=r[e].weight,i=r[e]);return i},on=r=>{let e=r.length,t=-1/0,i=null;for(;e--;)r[e].weight>t&&(t=r[e].weight,i=r[e]);return i};var cn=r=>{let e=r.length,t=Eo(e);return r[t]};var ln=r=>{var i,n;let e=0;for(let s=0;s<r.length;++s)e+=(i=r[s].weight)!=null?i:1;let t=Math.random()*e;e=0;for(let s=0;s<r.length-1;++s)if(e+=(n=r[s].weight)!=null?n:1,e>=t)return r[s];return r[r.length-1]};var hn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var Ar=(r,e=!1)=>T(p({},r),{args:e?p(p({},r.args),hn):p(p({},hn),r.args)}),Lr=({globalEventEmitter:r,player:e,interactiveEvents:t,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:d,controlType:u,controlId:b,containerId:R,branches:g=[],onEvent:F,isEOV:B=()=>!1,isDisabled:G=()=>!1})=>{let M=Ar(d,B()),$={timestamp:1/0,priority:"control",initiator:b,actionType:M.type},Z=G(),Ne=r.emit.bind(r,x.interactives,{subjectId:b,subjectType:u,subjectName:"control",type:Z?L.actionChoiceCanceled:L.actionChoice,actionType:d.type,payload:p({containerId:R},M.args)});if(Z){Ne();return}switch(M.type.trim().toLowerCase()){case N.setNextBranch.trim().toLowerCase():{let je=g.find(de=>de.id===M.args.branchId);if(!je)return;F(M.args.isDetachContainer,f.bind(null,{subjectId:b,subjectName:"control"})),Ne(),M.args.shouldOpenNow?w({subjectId:b,subjectName:"control",subjectType:u,action:M,payload:{chapterId:je.chapterId,autoSelect:!1}}):(t.add(T(p({},$),{action:w.bind(null,{subjectId:b,subjectName:"control",subjectType:u,action:M,payload:{chapterId:je.chapterId,autoSelect:!1}})})),i==null||i());return}case N.continuePlayback.trim().toLowerCase():{F(M.args.isDetachContainer,f.bind(null,{subjectId:b,subjectName:"control"})),Ne(),M.args.shouldOpenNow?I({subjectId:b,subjectName:"control",subjectType:u,action:d}):t.add(T(p({},$),{action:I.bind(null,{subjectId:b,subjectName:"control",subjectType:u,action:d})}));return}case N.openURI.trim().toLowerCase():{F(M.args.isDetachContainer,f.bind(null,{subjectId:b,subjectName:"control"})),Ne(),M.args.shouldOpenNow?S({subjectId:b,subjectName:"control",subjectType:u,action:M,payload:{URI:d.args.uri}}):(t.add(T(p({},$),{action:S.bind(null,{subjectId:b,subjectName:"control",subjectType:u,action:M,payload:{URI:d.args.uri}})})),i==null||i());return}default:console.error("Unexpected control event"),r.emit(x.errors,new W(1,1,{message:"Unexpected control event"}));return}},c=({action:d,container:{id:u,endTime:b},branches:R=[],isEOV:g=!1,autoSelected:F=!1})=>{let B=Ar(d,g),G={timestamp:!B.args.shouldOpenNow||g?1/0:b,priority:"container",initiator:u,actionType:B.type},M=r.emit.bind(r,x.interactives,{subjectId:u,subjectName:"container",type:L.actionChoice,actionType:B.type,payload:B.args});switch(B.type.trim().toLowerCase()){case N.setNextBranch.trim().toLowerCase():{let $=R.find(Z=>Z.id===B.args.branchId);if(!$)return;M(),t.add(T(p({},G),{action:w.bind(null,{subjectId:u,subjectName:"container",action:B,payload:{chapterId:$.chapterId,autoSelect:F}})})),i==null||i();return}case N.setMaxWeightBranch.trim().toLowerCase():return;case N.setMinWeightBranch.trim().toLowerCase():return;case N.setRandomBranch.trim().toLowerCase():return;case N.setWeightlessRandomBranch.trim().toLowerCase():return;case N.continuePlayback.trim().toLowerCase():{M(),t.add(T(p({},G),{action:I.bind(null,{subjectId:u,subjectName:"container",action:B})}));return}case N.openURI.trim().toLowerCase():{M(),t.add(T(p({},G),{action:S.bind(null,{subjectId:u,subjectName:"container",action:B,payload:{URI:d.args.uri}})})),i==null||i();return}default:console.error("Unexpected container event"),r.emit(x.errors,new W(1,1,{message:"Unexpected container event"}));return}};function o({container:d,branches:u,isEOV:b=!1}){let R=wr(d.events);if(R){let g=Ar(R.action,b);r.emit(x.interactives,{subjectId:d.id,subjectName:"container",type:L.actionChoice,actionType:g.type,payload:g.args}),t.add({timestamp:b?1/0:d.endTime,priority:"container",initiator:d.id,actionType:N.expect,action:y.bind(null,{subjectId:d.id,subjectName:"container"})}),n.isExpect=!0}else for(let g of d.events)c({action:g.action,container:d,branches:u,isEOV:b})}let h=({chapterId:d,action:u,branches:b=[]})=>{let R=r.emit.bind(r,x.interactives,{subjectId:d,subjectName:"chapter",type:L.actionChoice,actionType:u.type,payload:u.args});switch(u.type.trim().toLowerCase()){case N.setNextBranch.trim().toLowerCase():{let g=b.find(F=>F.id===u.args.branchId);return g!=null&&g.chapterId?(R(),w.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case N.setWeightlessRandomBranch.trim().toLowerCase():{let g=cn(b);return g!=null&&g.chapterId?(R(),w.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case N.setRandomBranch.trim().toLowerCase():{let g=ln(b);return g!=null&&g.chapterId?(R(),w.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case N.setMaxWeightBranch.trim().toLowerCase():{let g=on(b);return g!=null&&g.chapterId?(R(),w.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case N.setMinWeightBranch.trim().toLowerCase():{let g=an(b);return g!=null&&g.chapterId?(R(),w.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case N.continuePlayback.trim().toLowerCase():return R(),I.bind(null,{subjectId:d,subjectName:"chapter",action:u});case N.openURI.trim().toLowerCase():return R(),S.bind(null,{subjectId:d,subjectName:"chapter",action:u,payload:{URI:u.args.uri}});default:console.error("Unexpected chapter event"),r.emit(x.errors,new W(1,1,{message:"Unexpected chapter event"}));return}};function m(d){let u=wr(d.events);if(u){if(se(d))return;r.emit(x.interactives,{subjectId:d.id,subjectName:"chapter",type:L.actionChoice,actionType:u.action.type,payload:u.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:N.expect,action:y.bind(null,{subjectId:d.id,subjectName:"chapter"})})}else d.events.forEach(b=>{let R=h({chapterId:d.id,action:b.action,branches:d.branches});R&&t.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:b.action.type,action:R})})}let y=({subjectId:d,subjectName:u,action:b})=>{var R;e.pause(),r.emit(x.interactives,{subjectId:d,subjectName:u,type:L.actionExecution,actionType:(R=b==null?void 0:b.type)!=null?R:N.expect})},f=({subjectId:d,subjectName:u})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),r.emit(x.interactives,{subjectId:d,subjectName:u,type:L.actionExecution,actionType:"after-expect"})},I=({subjectId:d,subjectName:u,subjectType:b,action:R})=>{r.emit(x.interactives,{subjectId:d,subjectName:u,subjectType:b,type:L.actionExecution,actionType:R.type})},w=({subjectId:d,subjectName:u,subjectType:b,action:R,payload:g})=>{g.behaviour="change-chapter",r.emit(x.interactives,{subjectId:d,subjectName:u,subjectType:b,type:L.actionExecution,actionType:R.type,payload:g})},C=({subjectId:d,subjectName:u,subjectType:b,action:R,payload:g})=>{g.behaviour="change-manifest",r.emit(x.interactives,{subjectId:d,subjectName:u,subjectType:b,type:L.actionExecution,actionType:R.type,payload:g})},S=({subjectId:d,subjectName:u,subjectType:b,action:R,payload:g})=>{if(!g.URI)return;let F=window.open(g.URI,"_blank","noopener,noreferrer");F&&(F.opener=null),r.emit(x.interactives,{subjectId:d,subjectName:u,subjectType:b,type:L.actionExecution,actionType:R.type})};return{onControlEvent:l,onContainerEvent:c,onChapterEvent:h,onExpectEvent:y,expectEventHandler:f,setManifestChapterEvents:m,setManifestContainerEvents:o,stopExpect:s,state:n}};var pi=Ga(Sa(),1);import{Subscription as Bl,ValueSubject as ut}from"@vkontakte/videoplayer-shared";var ui=(r,e)=>{let t={};return r.map(i=>{if(!t[i]){let n=e.chapters.find(l=>l.id===i);if(!n)return null;let s=e.media.videos.find(l=>n.videoId===l.id);if(!s)return null;t[i]=wa(s)}return t[i]}).filter(Boolean)},kl=r=>{for(let e of r.variants)if(Fl(e)&&"payload"in e)return e.payload.id},Fl=r=>r.type==="custom"&&"payload"in r&&r.payload.type==="vk",wa=r=>{let e=kl(r);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},$l=(r,e)=>{for(let t of r.media.videos)if(e===wa(t)){for(let i of r.chapters)if(i.videoId===t.id)return i.id;return}},_a=(r,e)=>r.reduce((t,i)=>{let n=$l(e,i);return n?[...t,n]:t},[]);var ae,Ve,Me,ee,Xt,oe,ce,re,Ae,ze,We,pt=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new ut([]),hasPrevChapter$:new ut(!1),prevChapter$:new ut(null),isInitialChapter$:new ut(!1),isGoBackLimited$:new ut(!1)};_(this,ae,null);_(this,Ve);_(this,Me,!1);_(this,ee,null);_(this,Xt,null);_(this,oe,null);_(this,ce,null);_(this,re,null);_(this,Ae,new Bl);_(this,ze,!1);_(this,We,0);var l,c,o;E(this,oe,t),E(this,re,e),E(this,ce,i),E(this,ae,n),E(this,Ve,s),(l=this.state)!=null&&l.history$&&a(this,Ae)&&((o=a(this,Ae))==null||o.add((c=this.state)==null?void 0:c.history$.subscribe(h=>{var m,y,f,I,w,C;(m=this.state)==null||m.prevChapter$.next((0,pi.default)(h,-2)||null),(y=this.state)==null||y.hasPrevChapter$.next(h.length>1),(w=this.state)==null||w.isInitialChapter$.next(this.getInitialChapterId()===((I=(f=a(this,ee))==null?void 0:f.metadata)==null?void 0:I.initChapterId)),(C=this.state)==null||C.isGoBackLimited$.next(a(this,We)===a(this,Ve).maxLength-1)})))}setManifest(e){return V(this,null,function*(){!a(this,ce)||!a(this,re)||(E(this,ee,e),yield this.getProjectHistory(),yield a(this,ce).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,Me)||(E(this,Me,!0),a(this,re).emit(x.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,Me)}updateHistory(e,t=!0){return V(this,null,function*(){var c,o;if(!a(this,ee))return;a(this,ze)?(E(this,ze,!1),_i(this,We)._++):E(this,We,0);let i=a(this,ee),n=e.length-a(this,Ve).maxLength,s=n>0?e.slice(n):e,l=ui(s,i);if(E(this,Xt,l),(c=this==null?void 0:this.state)==null||c.history$.next(s),!(!t||!a(this,ae)||!a(this,oe)))try{yield a(this,ae).save(a(this,oe),l)}catch(h){(o=a(this,re))==null||o.emit(x.errors,new W(1,5,"Unable to save interactive history"))}})}goBack(){return V(this,null,function*(){var i;if(!this.state||!a(this,ce))return(i=a(this,re))==null?void 0:i.emit(x.errors,new W(1,5,"Cannot go back because HistoryController has not been initialized"));E(this,ze,!0);let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),yield a(this,ce).setChapter({chapterId:t})})}getProjectHistory(){return V(this,null,function*(){var n,s;if(!a(this,ee)||!a(this,oe))return;let e=a(this,ee),t=[this.getInitialVideoId()];if(a(this,ae))try{let l=yield a(this,ae).get(a(this,oe));l.length&&(t=l)}catch(l){(n=a(this,re))==null||n.emit(x.errors,new W(1,5,"Error while trying to fetch data"))}let i=_a(t,e);(s=this==null?void 0:this.state)==null||s.history$.next(i)})}getInitialChapterId(){var t,i;let e=(t=this.state)==null?void 0:t.history$.getValue();return(0,pi.default)(e,-1)||a(this,Ve).initChapterId||((i=a(this,ee))==null?void 0:i.metadata.initChapterId)}getInitialVideoId(){if(a(this,ee)){let e=this.getInitialChapterId();return ui([e],a(this,ee)).pop()}return null}destroy(){var e,t;this.state=null,E(this,oe,null),E(this,ae,null),E(this,ce,null),(e=a(this,Ae))==null||e.unsubscribe(),E(this,Ae,null),E(this,Me,!1),(t=a(this,re))==null||t.emit(x.historyDestroyed),E(this,re,null)}};ae=new WeakMap,Ve=new WeakMap,Me=new WeakMap,ee=new WeakMap,Xt=new WeakMap,oe=new WeakMap,ce=new WeakMap,re=new WeakMap,Ae=new WeakMap,ze=new WeakMap,We=new WeakMap;var Le=class Le{constructor(e,t,i,n){this.target=e,this.type=t,this.listener=i,this.options=Le._convertOptions(e,n),this.target.addEventListener(t,i,this.options)}unlisten(){var e;this.type&&this.listener&&this.options&&((e=this.target)==null||e.removeEventListener(this.type,this.listener,this.options)),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let i=new Set(["passive","capture"]),n=Object.keys(t).filter(l=>!i.has(l));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),Le._doesSupportObject(e)?t:t.capture||!1}}static _doesSupportObject(e){let t=Le._supportsObject;if(t===void 0){t=!1;try{let i={},n={get:()=>(t=!0,!1)};Object.defineProperty(i,"passive",n),Object.defineProperty(i,"capture",n);let s=()=>{};e.addEventListener("test",s,i),e.removeEventListener("test",s,i)}catch(i){t=!1}Le._supportsObject=t}return t||!1}};Le._supportsObject=void 0;var Zt=Le;var Jt=class{constructor(){this.bindingMap=new st}release(){this.removeAll(),this.bindingMap=null}listen(e,t,i,n){if(!this.bindingMap)return;let s=new Zt(e,t,i,n);this.bindingMap.push(t,s)}listenOnce(e,t,i,n){let s=l=>{this.unlisten(e,t,s),i(l)};this.listen(e,t,s,n)}unlisten(e,t,i){if(!this.bindingMap)return;let n=this.bindingMap.get(t)||[];for(let s of n)s.target===e&&(i===s.listener||!i)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var er=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var e;(e=this.rootElement.getContext("2d"))==null||e.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var n;let e=(n=this.rootElement.getContext("2d"))==null?void 0:n.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,i=t.length;for(let s=3;s<i;s+=40)if(t[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){var e;this.canvasImgSrc&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}updateCanvasDimensions(e,t=!1){return V(this,null,function*(){let i=e.width+e.height;if(this._prevSizeId===i)return;let n;t&&(n=yield this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&n&&this.restore(n),this._prevSizeId=i})}save(){return V(this,null,function*(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,yield t.decode(),t})}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}};var tr=class{constructor({parentElement:e,endOffsetMs:t=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e!=null?e:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
7
7
|
position: absolute;
|
|
8
8
|
top: 0;
|
|
9
9
|
left: 0;
|
|
@@ -11,13 +11,13 @@ var Va=Object.create;var ii=Object.defineProperty,Ra=Object.defineProperties,Aa=
|
|
|
11
11
|
height: var(--interactive-height);
|
|
12
12
|
background-color: var(--black);
|
|
13
13
|
visibility: hidden;
|
|
14
|
-
`,this.lastFrameCanvas=new
|
|
14
|
+
`,this.lastFrameCanvas=new er,this.endOffsetMs=t,this._callbacks={onError:i},this.lastFrameCanvas.rootElement.style.cssText=`
|
|
15
15
|
position: absolute;
|
|
16
16
|
top: 50%;
|
|
17
17
|
left: 50%;
|
|
18
18
|
transform: translate(-50%, -50%);
|
|
19
|
-
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}updateCanvasDimensions(e=!1){return
|
|
19
|
+
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}updateCanvasDimensions(e=!1){return V(this,null,function*(){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),i={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(i,e)}catch(n){this._onError(n)}})}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>{var i,n,s;return((i=t.controls)==null?void 0:i.length)&&e>=((n=t.startTime)!=null?n:0)&&e<=Math.min((s=t.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){var t,i;(i=(t=this._callbacks)==null?void 0:t.onError)==null||i.call(t,e)}};function Ra(r=0){return new Promise(e=>{setTimeout(()=>{e(0)},r)})}var Ma=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,historyParams:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}}),le=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function zl(){let r=document.createElement("div");return r.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,i}var Ce,X,xe,U,pe,H,Z,de,k,fe,We,G,Ke,q,N,Ie,Te,A,Ca,xa,Xt,cr,Jt,Ia,ar,Ne,pt,Ta,or,Sa,wa,ei,dt,Zt=class{constructor(e){w(this,A);w(this,Ce,null);w(this,X,null);w(this,xe,null);w(this,U,null);w(this,pe,null);w(this,H,null);w(this,Z,null);w(this,de,null);w(this,k,null);w(this,fe,new ae(!1));w(this,We,new Set);w(this,G,null);w(this,Ke,null);w(this,q,null);w(this,N,null);w(this,Ie,new Je);w(this,Te,null);ee(this,"state",{prevChapter$:new ae(null),isInitialChapter$:new ae(!1),isEndChapter$:new ae(!1),isInteractiveExpectation$:new ae(!1),calledByInteractive$:new ae(!1),lastChapterChangeWasInitiatedByInteractive$:new ae(!1),disabledControls$:new ae(!1),interactiveRanges$:new ae([]),isInteractiveTime$:new ae(!1)});ee(this,"events",{noInteraction$:new Ol});ee(this,"emitPlayerChanged",e=>{a(this,N).emit(E.playerChanged,e)});w(this,cr,()=>{a(this,Z).fns.forEach(r=>r());let e=this.options.player.info.position$.getValue()*1e3,t=(a(this,k).chapter.containers||[]).filter(r=>r.startTime>=Math.floor(e));for(let r of t){a(this,H).remove({timestamp:1/0,priority:"container",initiator:r.id});for(let n of r.controls)a(this,H).remove({timestamp:1/0,priority:"control",initiator:n.id});a(this,X).find(n=>n.container.container.id===r.id).reset()}});w(this,Jt,()=>{a(this,Ce).calc(),a(this,Z).requestAnimation()});w(this,Ne,(e=!0)=>{a(this,X).forEach(t=>{!e&&t.isPermanentText||(a(this,Z).removeFn(t.whilePlaying),t.destroy())})});w(this,ei,e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(s=>C(p({},s),{subjects:s.subjects.filter(l=>l!==e)}));t.next(n)});w(this,dt,()=>{a(this,Te)&&(clearTimeout(a(this,Te)),b(this,Te,null))});var t;this.options=C(p(p({},Ea),e),{config:p(p({},Ea.config),e.config)}),b(this,X,[]),this.factories=new Map([["choice",St]]),this.rootElement=kl(),this.options.parentElement.append(this.rootElement),b(this,N,new Fe),b(this,pe,new Nl),b(this,xe,new Kt),b(this,U,new ut({interactiveController:this,globalEventEmitter:a(this,N),videoId:(t=this.options.projectInfo)==null?void 0:t.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&b(this,q,new Yt({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:r=>a(this,N).emit(E.errors,new W(1,6,r))})),a(this,xe).listen(this.rootElement,"mousedown",r=>r.stopPropagation()),a(this,xe).listen(this.rootElement,"mouseup",r=>r.stopPropagation()),b(this,k,new Be(this.options.loaders,r=>a(this,N).emit(E.errors,new W(1,3,r)))),b(this,H,Ii(this.options.player)),b(this,Z,new Ot),b(this,de,Si({player:this.options.player,interactiveEvents:a(this,H),globalEventEmitter:a(this,N),removeControllers:a(this,Ne)})),b(this,Ce,Kr(()=>{var r,n,s;return{player:(r=this.options)==null?void 0:r.player,parentElement:(n=this.options)==null?void 0:n.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,q).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&b(this,G,new Ze({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:r=>{this.setChapter({chapterId:r}),a(this,N).emit(E.graph,{type:tt.watchAgainClicked,chapterId:r})},onError:r=>a(this,N).emit(E.errors,new W(1,4,{message:r}))})),F(this,A,Ca).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=ue.created}getStatEvents(){return{click$:new ba(e=>{a(this,N).on(E.graph,({type:t,visibility:r})=>{t==="visibility"&&e.next(r?"OPEN_GRAPH":"CLOSE_GRAPH"),t==="watchAgainClicked"&&e.next("WATCH_AGAIN")}),a(this,N).on(E.interactives,({type:t,subjectName:r,subjectType:n})=>{t!=="action-choice"||r!=="control"||(n==="Button"&&e.next("GO_NEXT_BUTTON"),n==="Area"&&e.next("GO_NEXT_AREA"))})}),nextMovie$:new ba(e=>{a(this,N).on(E.playerChanged,({config:t})=>{t!=null&&t.unitedVideoId&&e.next(t.unitedVideoId)})})}}setPlayer(e){F(this,A,Xt).call(this),this.options.player=e,a(this,Ie).setPlayer(this.options.player),a(this,H)?a(this,H).setPlayer(this.options.player):b(this,H,Ii(this.options.player)),b(this,de,Si({player:this.options.player,interactiveEvents:a(this,H),globalEventEmitter:a(this,N),removeControllers:()=>a(this,Ne).call(this,!1)})),this.appState===ue.initiated&&(F(this,A,ar).call(this),F(this,A,pt).call(this,a(this,k).chapter))}setManifest(e){return R(this,null,function*(){F(this,A,Xt).call(this),this.isFirstChapterFetched=!1;let t=yield a(this,k).setManifest(e);return a(this,G)&&(yield a(this,G).handleManifestChange(t.manifest)),yield a(this,U).setManifest(t.manifest),a(this,N).emit(E.manifestChanged,{manifest:t.manifest}),F(this,A,pt).call(this,a(this,k).chapter),t.manifest})}setVisitedChapters(e){var t;Array.isArray(e)&&((t=a(this,G))==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=a(this,G))==null||t.updateVideosInfo(e))}setChapter(){return R(this,arguments,function*({chapterId:e,pushToHistory:t=!0}={}){var l;F(this,A,Xt).call(this),a(this,q)&&this.isFirstChapterFetched&&(a(this,q).draw(),a(this,q).show()),jl.isSafari&&(yield ga(35));let{chapter:r,media:n,graph:s}=yield e?a(this,k).setNext(e):a(this,k).setInitial();return t&&F(this,A,wa).call(this,r.id),this.state.isInitialChapter$.next(a(this,k).isInitialChapter()),this.state.isEndChapter$.next(a(this,k).isEndChapter()),a(this,G)&&a(this,G).handleChapterChange(s),(l=a(this,q))==null||l.setCurrentChapter(this.getCurrentChapter().chapter),a(this,N).emit(E.chapterChanged,{chapter:r,media:n,graph:s}),F(this,A,pt).call(this,a(this,k).chapter),b(this,We,new Set),this.isFirstChapterFetched=!0,{chapter:r,media:n,graph:s}})}toggleGraphView(e=!0){a(this,G)&&(e?(a(this,G).show(),a(this,fe).next(!1)):(a(this,G).hide(),F(this,A,or).call(this)),a(this,N).emit(E.graph,{type:tt.visibility,visibility:e}))}init(){a(this,k).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===ue.created&&(a(this,Ce).resizeObserver.observe(this.options.fullscreenTargetElement),F(this,A,ar).call(this),this.appState=ue.initiated,F(this,A,pt).call(this,a(this,k).chapter))}deadEndCheck(){var r,n;return!((n=(r=a(this,H))==null?void 0:r.getPreparedToExecActions())!=null?n:[]).some(s=>s.actionType===P.setNextBranch)}allControlsAreRemoved(){return!a(this,X).some(t=>!t.container.isRemoved)}isEndedExpectation(){var r;if(!((r=this.options)!=null&&r.player)||!a(this,X))return!1;let e=this.options.player.info.position$.getValue(),t=this.options.player.info.duration$.getValue();return e===t&&a(this,X).some(n=>{let s=n.container.container;return!s.isRemoved&&s.endTime===null&&Ve(s.events)})}playPrevChapter(){var e;(e=a(this,U))==null||e.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=a(this,k).manifest){return At(e.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,U).getInitialVideoId(),chapterId:a(this,U).getInitialChapterId()}}getHistoryState(){return a(this,U).state}getIsSeekable(){return a(this,fe)}getInteractiveRanges(){var e;return Gr((e=a(this,k).chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return a(this,Ie).getNextInteractiveTime(e)}getChapterBranches(e){return a(this,k).getBranches(e)}getCurrentChapter(){return a(this,k).getCurrent()}getCurrentManifest(){return a(this,k).manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return a(this,N).on(...e),this}off(...e){return a(this,N).off(...e),this}once(...e){return a(this,N).once(...e),this}destroy(){var e,t;a(this,Ne).call(this),b(this,X,void 0),this.state=void 0,(e=a(this,G))==null||e.destroy(),b(this,G,void 0),a(this,Ce).release(),b(this,Ce,void 0),b(this,de,void 0),a(this,Z).release(),b(this,Z,void 0),a(this,H).release(),b(this,H,void 0),a(this,k).release(),b(this,de,void 0),a(this,xe).release(),b(this,xe,void 0),a(this,pe).unsubscribe(),b(this,pe,void 0),a(this,N).reset(),b(this,N,void 0),(t=a(this,q))==null||t.destroy(),b(this,q,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,U).destroy(),b(this,U,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=ue.destroyed}};Ce=new WeakMap,X=new WeakMap,xe=new WeakMap,U=new WeakMap,pe=new WeakMap,H=new WeakMap,Z=new WeakMap,de=new WeakMap,k=new WeakMap,fe=new WeakMap,We=new WeakMap,G=new WeakMap,Ke=new WeakMap,q=new WeakMap,N=new WeakMap,Ie=new WeakMap,Te=new WeakMap,A=new WeakSet,Ca=function(e=!1){a(this,N).on(E.historyInited,n=>R(this,[n],function*({initChapterId:t,videosInfo:r=[]}){e&&(yield F(this,A,xa).call(this,{initialChapter:t,videosInfo:r}))})),a(this,N).on(E.interactives,t=>R(this,null,function*(){var r,n;if(t.type===L.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((r=t.payload)==null?void 0:r.behaviour)==="change-chapter"){let{chapterId:l}=t.payload;this.setChapter({chapterId:l})}if(((n=t.payload)==null?void 0:n.behaviour)==="change-manifest"){let{manifestURL:l}=t.payload;this.setManifest(l)}let s=t.type==="action-execution";s&&t.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&t.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}t.type===L.containerRemoved&&a(this,ei).call(this,t.subjectId)})),a(this,N).on(E.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},xa=function(r){return R(this,arguments,function*({source:e,videosInfo:t=[]}){b(this,Ke,xi(this));let n=document.createElement("div");a(this,Ke).on(rt.activePlayerChanged,this.emitPlayerChanged);let{player:s,config:l}=yield a(this,Ke).init({source:e,initialChapter:a(this,U).getInitialChapterId(),container:n});return this.updateGraphVideosInfo(t),{player:s,config:l}})},Xt=function(){var e;this.appState===ue.ready&&(a(this,Ne).call(this),b(this,X,[]),a(this,Z).release(),(e=a(this,H))==null||e.release(),this.appState=ue.initiated,a(this,fe).next(!1),a(this,dt).call(this))},cr=new WeakMap,Jt=new WeakMap,Ia=function(e){(!a(this,G)||a(this,G).isHidden)&&F(this,A,or).call(this);let t=e*1e3,n=this.getInteractiveRanges().findLast(({range:s})=>t>=s[1]);if(n){let s=n.range.join("-");a(this,We).has(s)||(a(this,We).add(s),a(this,N).emit(E.interactives,{type:L.rangeEnded,payload:n,visibility:!0}))}},ar=function(){a(this,pe).unsubscribe(),a(this,pe).add(this.options.player.events.started$.pipe(Ll()).subscribe(a(this,Jt))).add(this.options.player.events.playing$.subscribe(a(this,Z).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,Z).cancelAnimation)).add(this.options.player.info.position$.subscribe(F(this,A,Ia).bind(this))).add(a(this,k).prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Pl({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:r})=>{let n;if(r)n=!0;else{let c=e*1e3;n=!!(t==null?void 0:t.find(({range:[v,T],subjects:m})=>v<c&&c<T&&m.length))}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let s=a(this,Te)!==null,o=this.options.player.info.playbackState$.getValue()==="playing"||r;n&&!s&&o?b(this,Te,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):s&&!o&&a(this,dt).call(this)})),this.options.lastFrame&&a(this,pe).add(this.options.player.info.duration$.subscribe(e=>{a(this,q).setVideoDuration(e*1e3)})).add(this.options.player.experimental.element$.subscribe(e=>{e&&a(this,q).setVideoElement(e)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,q).reset(),setTimeout(()=>{a(this,q).hide(),a(this,q).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,q).onSeek))},Ne=new WeakMap,pt=function(e){a(this,k).chapter&&this.appState===ue.initiated&&(a(this,de).setManifestChapterEvents(e),b(this,X,F(this,A,Ta).call(this,e)),a(this,H).containersEventsCallState.setData(e.containers),a(this,Ie).setContainers(a(this,X).map(t=>t.container.container).filter(t=>!$t(t.controls))),this.options.lastFrame&&a(this,Z).addFn(()=>{a(this,q).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=ue.ready)},Ta=function(e){var t,r;return(r=(t=e==null?void 0:e.containers)==null?void 0:t.reduce((n,s)=>{let l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Ft({player:this.options.player,container:o(s,this.rootElement),branches:a(this,k).chapter.branches,selectBranches:a(this,de),interactiveEvents:a(this,H),globalEventEmitter:a(this,N),ignoreContainerEvent:()=>Dr(s,a(this,X)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,Ie).deleteContainer(s.id)}});return a(this,Z).addFn(c.whilePlaying,!0),[...n,c]}return[...n]},[]))!=null?r:[]},or=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,fe).next(!1);return}let t=a(this,fe).getValue(),r=!!a(this,Ie).getNextInteractiveTime();(r&&!t||!r&&t)&&a(this,fe).next(!t)},Sa=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},wa=function(e){var o;if(F(this,A,Sa).call(this),!a(this,U).inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),r=this.state.prevChapter$.getValue(),n=(o=r&&oe(r)&&kt(r))!=null?o:!1,s=a(this,k).manifest.metadata.initChapterId===e,l=a(this,U).state.history$.getValue();if(s||n&&t){a(this,U).updateHistory([e]);return}l.at(-1)!==e&&a(this,U).updateHistory([...l,e])},ei=new WeakMap,dt=new WeakMap;var $l={Container:$e,createChoiceContainer:St,createAreaControl:Ct,createButtonControl:It,createRelativeLayout:wr,getRootEl:yt,classnamesPrefix:D};var Lf={version:Er};export{W as CustomError,E as EVENT_NAMES,mi as INTERACTIVE_CLICK_ACTIONS,Zt as Interactives,Be as ManifestController,Lf as SDKInfo,nr as chapterIdsToVKVideoIds,ge as compareVersions,Al as getChapterIdByVkVideoId,ya as getVKVideoIdByMedia,Vl as getVideoRawIdByMedia,tt as graphEventTypes,kt as hasEndTemplate,L as interactivesEventTypes,oe as isLastChapter,At as isSupportedManifest,Rl as isVKVariantItem,$l as utils,va as vkVideoIdsToChapterIds};
|
|
23
|
+
`,r}var be,Y,Ee,K,he,H,X,ue,j,pe,Ke,U,Ce,q,O,xe,Ie,A,Aa,nr,La,rr,mi,sr,Oa,di,Oe,ft,Na,fi,ja,Pa,ar,mt,ir=class{constructor(e){_(this,A);_(this,be,null);_(this,Y,null);_(this,Ee,null);_(this,K,null);_(this,he,null);_(this,H,null);_(this,X,null);_(this,ue,null);_(this,j,null);_(this,pe,new ie(!1));_(this,Ke,new Set);_(this,U,null);_(this,Ce,null);_(this,q,null);_(this,O,null);_(this,xe,new Je);_(this,Ie,null);J(this,"state",{prevChapter$:new ie(null),isInitialChapter$:new ie(!1),isEndChapter$:new ie(!1),isInteractiveExpectation$:new ie(!1),calledByInteractive$:new ie(!1),lastChapterChangeWasInitiatedByInteractive$:new ie(!1),disabledControls$:new ie(!1),interactiveRanges$:new ie([]),isInteractiveTime$:new ie(!1),statistics$:new ie(null)});J(this,"events",{noInteraction$:new ql});_(this,nr,i=>{var n=i,{statistics:e}=n,t=z(n,["statistics"]);if(e){let{statSubscription:s,oneStat:l}=e;s.add(l.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(e)}a(this,O).emit(x.playerChanged,t)});_(this,mi,()=>{a(this,X).fns.forEach(i=>i());let e=this.options.player.info.position$.getValue()*1e3,t=(a(this,j).chapter.containers||[]).filter(i=>i.startTime>=Math.floor(e));for(let i of t){a(this,H).remove({timestamp:1/0,priority:"container",initiator:i.id});for(let n of i.controls)a(this,H).remove({timestamp:1/0,priority:"control",initiator:n.id});a(this,Y).find(n=>n.container.container.id===i.id).reset()}});_(this,sr,()=>{a(this,be).calc(),a(this,X).requestAnimation()});_(this,Oe,(e=!0)=>{a(this,Y).forEach(t=>{!e&&t.isPermanentText||(a(this,X).removeFn(t.whilePlaying),t.destroy())})});_(this,ar,e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(s=>T(p({},s),{subjects:s.subjects.filter(l=>l!==e)}));t.next(n)});_(this,mt,()=>{a(this,Ie)&&(clearTimeout(a(this,Ie)),E(this,Ie,null))});var t;this.options=T(p(p({},Ma),e),{config:p(p({},Ma.config),e.config)}),E(this,Y,[]),this.factories=new Map([["choice",_t]]),this.rootElement=zl(),this.options.parentElement.append(this.rootElement),E(this,O,new $e),E(this,he,new Hl),E(this,Ee,new Jt),E(this,K,new pt({interactiveController:this,globalEventEmitter:a(this,O),videoId:(t=this.options.projectInfo)==null?void 0:t.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&E(this,q,new tr({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:i=>a(this,O).emit(x.errors,new W(1,6,i))})),a(this,Ee).listen(this.rootElement,"mousedown",i=>i.stopPropagation()),a(this,Ee).listen(this.rootElement,"mouseup",i=>i.stopPropagation()),E(this,j,new qe(this.options.loaders,i=>a(this,O).emit(x.errors,new W(1,3,i)))),E(this,H,Mr(this.options.player)),E(this,X,new Nt),E(this,ue,Lr({player:this.options.player,interactiveEvents:a(this,H),globalEventEmitter:a(this,O),removeControllers:a(this,Oe)})),E(this,be,sn(()=>{var i,n,s;return{player:(i=this.options)==null?void 0:i.player,parentElement:(n=this.options)==null?void 0:n.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,q).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&E(this,U,new Ze({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:i=>{this.setChapter({chapterId:i}),a(this,O).emit(x.graph,{type:it.watchAgainClicked,chapterId:i})},onError:i=>a(this,O).emit(x.errors,new W(1,4,{message:i}))})),P(this,A,Aa).call(this),this.isFirstChapterFetched=!1,this.appState=le.created}getStatEvents(){return{click$:new Va(e=>{a(this,O).on(x.graph,({type:t,visibility:i})=>{t==="visibility"&&e.next(i?dt.GRAPH_SHOW:dt.GRAPH_HIDE),t==="watchAgainClicked"&&e.next(dt.WATCH_AGAIN)}),a(this,O).on(x.interactives,({type:t,subjectName:i,subjectType:n})=>{t!=="action-choice"||i!=="control"||(n==="Button"&&e.next(dt.NEXT_BUTTON),n==="Area"&&e.next(dt.NEXT_AREA))})}),nextMovie$:new Va(e=>{a(this,O).on(x.playerChanged,({config:t})=>{t!=null&&t.unitedVideoId&&e.next(t.unitedVideoId)})})}}setPlayer(e){P(this,A,rr).call(this),this.options.player=e,a(this,xe).setPlayer(this.options.player),a(this,H)?a(this,H).setPlayer(this.options.player):E(this,H,Mr(this.options.player)),E(this,ue,Lr({player:this.options.player,interactiveEvents:a(this,H),globalEventEmitter:a(this,O),removeControllers:()=>a(this,Oe).call(this,!1)})),this.appState===le.initiated&&(P(this,A,di).call(this),P(this,A,ft).call(this,a(this,j).chapter))}setManifest(e){return V(this,null,function*(){P(this,A,rr).call(this),this.isFirstChapterFetched=!1;let t=yield a(this,j).setManifest(e);return a(this,U)&&(yield a(this,U).handleManifestChange(t.manifest)),yield a(this,K).setManifest(t.manifest),a(this,O).emit(x.manifestChanged,{manifest:t.manifest}),P(this,A,ft).call(this,a(this,j).chapter),t.manifest})}setVisitedChapters(e){var t;Array.isArray(e)&&((t=a(this,U))==null||t.setVisitedChapters(e))}updateGraphVideosInfo(e){var t;Array.isArray(e)&&((t=a(this,U))==null||t.updateVideosInfo(e))}setChapter(){return V(this,arguments,function*({chapterId:e,pushToHistory:t=!0}={}){var l;P(this,A,rr).call(this),a(this,q)&&this.isFirstChapterFetched&&(a(this,q).draw(),a(this,q).show()),Ul.isSafari&&(yield Ra(35));let{chapter:i,media:n,graph:s}=yield e?a(this,j).setNext(e):a(this,j).setInitial();return t&&P(this,A,Pa).call(this,i.id),this.state.isInitialChapter$.next(a(this,j).isInitialChapter()),this.state.isEndChapter$.next(a(this,j).isEndChapter()),a(this,U)&&a(this,U).handleChapterChange(s),(l=a(this,q))==null||l.setCurrentChapter(this.getCurrentChapter().chapter),a(this,O).emit(x.chapterChanged,{chapter:i,media:n,graph:s}),P(this,A,ft).call(this,a(this,j).chapter),E(this,Ke,new Set),this.isFirstChapterFetched=!0,{chapter:i,media:n,graph:s}})}toggleGraphView(e=!0){a(this,U)&&(e?(a(this,U).show(),a(this,pe).next(!1)):(a(this,U).hide(),P(this,A,fi).call(this)),a(this,O).emit(x.graph,{type:it.visibility,visibility:e}))}init(){a(this,j).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===le.created&&(a(this,be).resizeObserver.observe(this.options.fullscreenTargetElement),P(this,A,di).call(this),this.appState=le.initiated,P(this,A,ft).call(this,a(this,j).chapter))}deadEndCheck(){var i,n;return!((n=(i=a(this,H))==null?void 0:i.getPreparedToExecActions())!=null?n:[]).some(s=>s.actionType===N.setNextBranch)}allControlsAreRemoved(){return!a(this,Y).some(t=>!t.container.isRemoved)}isEndedExpectation(){var i;if(!((i=this.options)!=null&&i.player)||!a(this,Y))return!1;let e=this.options.player.info.position$.getValue(),t=this.options.player.info.duration$.getValue();return e===t&&a(this,Y).some(n=>{let s=n.container.container;return!s.isRemoved&&s.endTime===null&&_e(s.events)})}playPrevChapter(){var e;(e=a(this,K))==null||e.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=a(this,j).manifest){return Lt(e.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,K).getInitialVideoId(),chapterId:a(this,K).getInitialChapterId()}}getHistoryState(){return a(this,K).state}getIsSeekable(){return a(this,pe)}getInteractiveRanges(){var e;return en((e=a(this,j).chapter)==null?void 0:e.containers)}getNextInteractiveStartTime(e){return a(this,xe).getNextInteractiveTime(e)}getChapterBranches(e){return a(this,j).getBranches(e)}getCurrentChapter(){return a(this,j).getCurrent()}getCurrentManifest(){return a(this,j).manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return a(this,O).on(...e),this}off(...e){return a(this,O).off(...e),this}once(...e){return a(this,O).once(...e),this}destroy(){var e,t,i;a(this,Oe).call(this),E(this,Y,void 0),this.state=void 0,(e=a(this,U))==null||e.destroy(),E(this,U,void 0),a(this,be).release(),E(this,be,void 0),E(this,ue,void 0),a(this,X).release(),E(this,X,void 0),a(this,H).release(),E(this,H,void 0),a(this,j).release(),E(this,ue,void 0),a(this,Ee).release(),E(this,Ee,void 0),a(this,he).unsubscribe(),E(this,he,void 0),a(this,O).reset(),E(this,O,void 0),(t=a(this,q))==null||t.destroy(),E(this,q,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,K).destroy(),E(this,K,void 0),(i=a(this,Ce))==null||i.removeAll(),E(this,Ce,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=le.destroyed}};be=new WeakMap,Y=new WeakMap,Ee=new WeakMap,K=new WeakMap,he=new WeakMap,H=new WeakMap,X=new WeakMap,ue=new WeakMap,j=new WeakMap,pe=new WeakMap,Ke=new WeakMap,U=new WeakMap,Ce=new WeakMap,q=new WeakMap,O=new WeakMap,xe=new WeakMap,Ie=new WeakMap,A=new WeakSet,Aa=function(){a(this,O).on(x.historyInited,t=>V(this,[t],function*({videosInfo:e=[]}){this.options.initSeamless&&(yield P(this,A,La).call(this),this.updateGraphVideosInfo(e))})),a(this,O).on(x.interactives,e=>V(this,null,function*(){var t,i;if(e.type===L.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((t=e.payload)==null?void 0:t.behaviour)==="change-chapter"){let{chapterId:s}=e.payload;this.setChapter({chapterId:s})}if(((i=e.payload)==null?void 0:i.behaviour)==="change-manifest"){let{manifestURL:s}=e.payload;this.setManifest(s)}let n=e.type==="action-execution";n&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):n&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===L.containerRemoved&&a(this,ar).call(this,e.subjectId)})),a(this,O).on(x.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},nr=new WeakMap,La=function(){return V(this,null,function*(){E(this,Ce,Vr(this)),a(this,Ce).on(Ht.activePlayerChanged,a(this,nr)),a(this,Ce).init()})},rr=function(){var e;this.appState===le.ready&&(a(this,Oe).call(this),E(this,Y,[]),a(this,X).release(),(e=a(this,H))==null||e.release(),this.appState=le.initiated,a(this,pe).next(!1),a(this,mt).call(this))},mi=new WeakMap,sr=new WeakMap,Oa=function(e){(!a(this,U)||a(this,U).isHidden)&&P(this,A,fi).call(this);let t=e*1e3,n=this.getInteractiveRanges().findLast(({range:s})=>t>=s[1]);if(n){let s=n.range.join("-");a(this,Ke).has(s)||(a(this,Ke).add(s),a(this,O).emit(x.interactives,{type:L.rangeEnded,payload:n,visibility:!0}))}},di=function(){a(this,he).unsubscribe(),a(this,he).add(this.options.player.events.started$.pipe(Dl()).subscribe(a(this,sr))).add(this.options.player.events.playing$.subscribe(a(this,X).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,X).cancelAnimation)).add(this.options.player.info.position$.subscribe(P(this,A,Oa).bind(this))).add(a(this,j).prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Gl({position:this.options.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 o=e*1e3;n=!!(t==null?void 0:t.find(({range:[m,y],subjects:f})=>m<o&&o<y&&f.length))}n!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(n);let s=a(this,Ie)!==null,c=this.options.player.info.playbackState$.getValue()==="playing"||i;n&&!s&&c?E(this,Ie,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):s&&!c&&a(this,mt).call(this)})),this.options.lastFrame&&a(this,he).add(this.options.player.info.duration$.subscribe(e=>{a(this,q).setVideoDuration(e*1e3)})).add(this.options.player.experimental.element$.subscribe(e=>{e&&a(this,q).setVideoElement(e)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,q).reset(),setTimeout(()=>{a(this,q).hide(),a(this,q).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,q).onSeek))},Oe=new WeakMap,ft=function(e){a(this,j).chapter&&this.appState===le.initiated&&(a(this,ue).setManifestChapterEvents(e),E(this,Y,P(this,A,Na).call(this,e)),a(this,H).containersEventsCallState.setData(e.containers),a(this,xe).setContainers(a(this,Y).map(t=>t.container.container).filter(t=>!Dt(t.controls))),this.options.lastFrame&&a(this,X).addFn(()=>{a(this,q).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=le.ready)},Na=function(e){var t,i;return(i=(t=e==null?void 0:e.containers)==null?void 0:t.reduce((n,s)=>{let l=s.type.trim().toLowerCase(),c=this.factories.get(l);if(c){let o=new Ut({player:this.options.player,container:c(s,this.rootElement),branches:a(this,j).chapter.branches,selectBranches:a(this,ue),interactiveEvents:a(this,H),globalEventEmitter:a(this,O),ignoreContainerEvent:()=>Xi(s,a(this,Y)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,xe).deleteContainer(s.id)}});return a(this,X).addFn(o.whilePlaying,!0),[...n,o]}return[...n]},[]))!=null?i:[]},fi=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,pe).next(!1);return}let t=a(this,pe).getValue(),i=!!a(this,xe).getNextInteractiveTime();(i&&!t||!i&&t)&&a(this,pe).next(!t)},ja=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Pa=function(e){var c;if(P(this,A,ja).call(this),!a(this,K).inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),i=this.state.prevChapter$.getValue(),n=(c=i&&se(i)&&qt(i))!=null?c:!1,s=a(this,j).manifest.metadata.initChapterId===e,l=a(this,K).state.history$.getValue();if(s||n&&t){a(this,K).updateHistory([e]);return}l.at(-1)!==e&&a(this,K).updateHistory([...l,e])},ar=new WeakMap,mt=new WeakMap;var Wl={Container:Fe,createChoiceContainer:_t,createAreaControl:It,createButtonControl:St,createRelativeLayout:Ni,getRootEl:gt,classnamesPrefix:D};var rm={version:Ri};export{W as CustomError,x as EVENT_NAMES,ir as Interactives,qe as ManifestController,rm as SDKInfo,ui as chapterIdsToVKVideoIds,ye as compareVersions,$l as getChapterIdByVkVideoId,wa as getVKVideoIdByMedia,kl as getVideoRawIdByMedia,it as graphEventTypes,qt as hasEndTemplate,L as interactivesEventTypes,se as isLastChapter,Lt as isSupportedManifest,Fl as isVKVariantItem,Wl as utils,_a as vkVideoIdsToChapterIds};
|