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