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