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