@vkontakte/videoplayer-interactive 1.0.12-dev.3f0b6cc2.0 → 1.0.13-beta.0

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