@vkontakte/videoplayer-interactive 1.0.23-dev.75664bee.0 → 1.0.23-dev.8a9f6a57.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.23-dev.75664bee.0
3
- * Thu, 24 Oct 2024 10:02:53 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.23-dev.8a9f6a57.0
3
+ * Thu, 24 Oct 2024 10:53:09 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-23/doc/
5
5
  */
6
- "use strict";var Rs=Object.create;var Ae=Object.defineProperty;var ks=Object.getOwnPropertyDescriptor;var Ps=Object.getOwnPropertyNames;var Vs=Object.getPrototypeOf,Os=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),js=(t,e)=>{for(var r in e)Ae(t,r,{get:e[r],enumerable:!0})},br=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ps(e))!Os.call(t,n)&&n!==r&&Ae(t,n,{get:()=>e[n],enumerable:!(i=ks(e,n))||i.enumerable});return t};var dt=(t,e,r)=>(r=t!=null?Rs(Vs(t)):{},br(e||!t||!t.__esModule?Ae(r,"default",{value:t,enumerable:!0}):r,t)),Ns=t=>br(Ae({},"__esModule",{value:!0}),t);var F=u((Et,wr)=>{"use strict";var pe=function(t){return t&&t.Math===Math&&t};wr.exports=pe(typeof globalThis=="object"&&globalThis)||pe(typeof window=="object"&&window)||pe(typeof self=="object"&&self)||pe(typeof global=="object"&&global)||pe(typeof Et=="object"&&Et)||function(){return this}()||Function("return this")()});var H=u((uc,Mr)=>{"use strict";Mr.exports=function(t){try{return!!t()}catch{return!0}}});var he=u((dc,Lr)=>{"use strict";var $s=H();Lr.exports=!$s(function(){var t=function(){}.bind();return typeof t!="function"||t.hasOwnProperty("prototype")})});var Pr=u((fc,kr)=>{"use strict";var Bs=he(),Rr=Function.prototype,_r=Rr.apply,Ar=Rr.call;kr.exports=typeof Reflect=="object"&&Reflect.apply||(Bs?Ar.bind(_r):function(){return Ar.apply(_r,arguments)})});var W=u((mc,jr)=>{"use strict";var Vr=he(),Or=Function.prototype,It=Or.call,qs=Vr&&Or.bind.bind(It,It);jr.exports=Vr?qs:function(t){return function(){return It.apply(t,arguments)}}});var xt=u((yc,Fr)=>{"use strict";var Nr=W(),Ds=Nr({}.toString),Hs=Nr("".slice);Fr.exports=function(t){return Hs(Ds(t),8,-1)}});var Tt=u((vc,$r)=>{"use strict";var Us=xt(),Gs=W();$r.exports=function(t){if(Us(t)==="Function")return Gs(t)}});var U=u((gc,Br)=>{"use strict";var St=typeof document=="object"&&document.all;Br.exports=typeof St>"u"&&St!==void 0?function(t){return typeof t=="function"||t===St}:function(t){return typeof t=="function"}});var ie=u((bc,qr)=>{"use strict";var zs=H();qr.exports=!zs(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var De=u((Cc,Dr)=>{"use strict";var Ws=he(),qe=Function.prototype.call;Dr.exports=Ws?qe.bind(qe):function(){return qe.apply(qe,arguments)}});var zr=u(Gr=>{"use strict";var Hr={}.propertyIsEnumerable,Ur=Object.getOwnPropertyDescriptor,Qs=Ur&&!Hr.call({1:2},1);Gr.f=Qs?function(e){var r=Ur(this,e);return!!r&&r.enumerable}:Hr});var wt=u((Ic,Wr)=>{"use strict";Wr.exports=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}});var Kr=u((xc,Qr)=>{"use strict";var Ks=W(),Ys=H(),Zs=xt(),Mt=Object,Xs=Ks("".split);Qr.exports=Ys(function(){return!Mt("z").propertyIsEnumerable(0)})?function(t){return Zs(t)==="String"?Xs(t,""):Mt(t)}:Mt});var Lt=u((Tc,Yr)=>{"use strict";Yr.exports=function(t){return t==null}});var _t=u((Sc,Zr)=>{"use strict";var Js=Lt(),ea=TypeError;Zr.exports=function(t){if(Js(t))throw new ea("Can't call method on "+t);return t}});var Jr=u((wc,Xr)=>{"use strict";var ta=Kr(),ra=_t();Xr.exports=function(t){return ta(ra(t))}});var ue=u((Mc,ei)=>{"use strict";var ia=U();ei.exports=function(t){return typeof t=="object"?t!==null:ia(t)}});var At=u((Lc,ti)=>{"use strict";ti.exports={}});var Pt=u((_c,ii)=>{"use strict";var Rt=At(),kt=F(),na=U(),ri=function(t){return na(t)?t:void 0};ii.exports=function(t,e){return arguments.length<2?ri(Rt[t])||ri(kt[t]):Rt[t]&&Rt[t][e]||kt[t]&&kt[t][e]}});var si=u((Ac,ni)=>{"use strict";var sa=W();ni.exports=sa({}.isPrototypeOf)});var ci=u((Rc,li)=>{"use strict";var aa=F(),ai=aa.navigator,oi=ai&&ai.userAgent;li.exports=oi?String(oi):""});var yi=u((kc,mi)=>{"use strict";var fi=F(),Vt=ci(),pi=fi.process,hi=fi.Deno,ui=pi&&pi.versions||hi&&hi.version,di=ui&&ui.v8,j,He;di&&(j=di.split("."),He=j[0]>0&&j[0]<4?1:+(j[0]+j[1]));!He&&Vt&&(j=Vt.match(/Edge\/(\d+)/),(!j||j[1]>=74)&&(j=Vt.match(/Chrome\/(\d+)/),j&&(He=+j[1])));mi.exports=He});var Ot=u((Pc,gi)=>{"use strict";var vi=yi(),oa=H(),la=F(),ca=la.String;gi.exports=!!Object.getOwnPropertySymbols&&!oa(function(){var t=Symbol("symbol detection");return!ca(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&vi&&vi<41})});var jt=u((Vc,bi)=>{"use strict";var pa=Ot();bi.exports=pa&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Nt=u((Oc,Ci)=>{"use strict";var ha=Pt(),ua=U(),da=si(),fa=jt(),ma=Object;Ci.exports=fa?function(t){return typeof t=="symbol"}:function(t){var e=ha("Symbol");return ua(e)&&da(e.prototype,ma(t))}});var Ii=u((jc,Ei)=>{"use strict";var ya=String;Ei.exports=function(t){try{return ya(t)}catch{return"Object"}}});var Ft=u((Nc,xi)=>{"use strict";var va=U(),ga=Ii(),ba=TypeError;xi.exports=function(t){if(va(t))return t;throw new ba(ga(t)+" is not a function")}});var Si=u((Fc,Ti)=>{"use strict";var Ca=Ft(),Ea=Lt();Ti.exports=function(t,e){var r=t[e];return Ea(r)?void 0:Ca(r)}});var Mi=u(($c,wi)=>{"use strict";var $t=De(),Bt=U(),qt=ue(),Ia=TypeError;wi.exports=function(t,e){var r,i;if(e==="string"&&Bt(r=t.toString)&&!qt(i=$t(r,t))||Bt(r=t.valueOf)&&!qt(i=$t(r,t))||e!=="string"&&Bt(r=t.toString)&&!qt(i=$t(r,t)))return i;throw new Ia("Can't convert object to primitive value")}});var _i=u((Bc,Li)=>{"use strict";Li.exports=!0});var ki=u((qc,Ri)=>{"use strict";var Ai=F(),xa=Object.defineProperty;Ri.exports=function(t,e){try{xa(Ai,t,{value:e,configurable:!0,writable:!0})}catch{Ai[t]=e}return e}});var Dt=u((Dc,Oi)=>{"use strict";var Ta=_i(),Sa=F(),wa=ki(),Pi="__core-js_shared__",Vi=Oi.exports=Sa[Pi]||wa(Pi,{});(Vi.versions||(Vi.versions=[])).push({version:"3.38.0",mode:Ta?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var Fi=u((Hc,Ni)=>{"use strict";var ji=Dt();Ni.exports=function(t,e){return ji[t]||(ji[t]=e||{})}});var Ht=u((Uc,$i)=>{"use strict";var Ma=_t(),La=Object;$i.exports=function(t){return La(Ma(t))}});var Ue=u((Gc,Bi)=>{"use strict";var _a=W(),Aa=Ht(),Ra=_a({}.hasOwnProperty);Bi.exports=Object.hasOwn||function(e,r){return Ra(Aa(e),r)}});var Di=u((zc,qi)=>{"use strict";var ka=W(),Pa=0,Va=Math.random(),Oa=ka(1 .toString);qi.exports=function(t){return"Symbol("+(t===void 0?"":t)+")_"+Oa(++Pa+Va,36)}});var Gi=u((Wc,Ui)=>{"use strict";var ja=F(),Na=Fi(),Hi=Ue(),Fa=Di(),$a=Ot(),Ba=jt(),ne=ja.Symbol,Ut=Na("wks"),qa=Ba?ne.for||ne:ne&&ne.withoutSetter||Fa;Ui.exports=function(t){return Hi(Ut,t)||(Ut[t]=$a&&Hi(ne,t)?ne[t]:qa("Symbol."+t)),Ut[t]}});var Ki=u((Qc,Qi)=>{"use strict";var Da=De(),zi=ue(),Wi=Nt(),Ha=Si(),Ua=Mi(),Ga=Gi(),za=TypeError,Wa=Ga("toPrimitive");Qi.exports=function(t,e){if(!zi(t)||Wi(t))return t;var r=Ha(t,Wa),i;if(r){if(e===void 0&&(e="default"),i=Da(r,t,e),!zi(i)||Wi(i))return i;throw new za("Can't convert object to primitive value")}return e===void 0&&(e="number"),Ua(t,e)}});var Gt=u((Kc,Yi)=>{"use strict";var Qa=Ki(),Ka=Nt();Yi.exports=function(t){var e=Qa(t,"string");return Ka(e)?e:e+""}});var Ji=u((Yc,Xi)=>{"use strict";var Ya=F(),Zi=ue(),zt=Ya.document,Za=Zi(zt)&&Zi(zt.createElement);Xi.exports=function(t){return Za?zt.createElement(t):{}}});var Wt=u((Zc,en)=>{"use strict";var Xa=ie(),Ja=H(),eo=Ji();en.exports=!Xa&&!Ja(function(){return Object.defineProperty(eo("div"),"a",{get:function(){return 7}}).a!==7})});var nn=u(rn=>{"use strict";var to=ie(),ro=De(),io=zr(),no=wt(),so=Jr(),ao=Gt(),oo=Ue(),lo=Wt(),tn=Object.getOwnPropertyDescriptor;rn.f=to?tn:function(e,r){if(e=so(e),r=ao(r),lo)try{return tn(e,r)}catch{}if(oo(e,r))return no(!ro(io.f,e,r),e[r])}});var an=u((Jc,sn)=>{"use strict";var co=H(),po=U(),ho=/#|\.prototype\./,de=function(t,e){var r=fo[uo(t)];return r===yo?!0:r===mo?!1:po(e)?co(e):!!e},uo=de.normalize=function(t){return String(t).replace(ho,".").toLowerCase()},fo=de.data={},mo=de.NATIVE="N",yo=de.POLYFILL="P";sn.exports=de});var cn=u((ep,ln)=>{"use strict";var on=Tt(),vo=Ft(),go=he(),bo=on(on.bind);ln.exports=function(t,e){return vo(t),e===void 0?t:go?bo(t,e):function(){return t.apply(e,arguments)}}});var hn=u((tp,pn)=>{"use strict";var Co=ie(),Eo=H();pn.exports=Co&&Eo(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var dn=u((rp,un)=>{"use strict";var Io=ue(),xo=String,To=TypeError;un.exports=function(t){if(Io(t))return t;throw new To(xo(t)+" is not an object")}});var yn=u(mn=>{"use strict";var So=ie(),wo=Wt(),Mo=hn(),Ge=dn(),fn=Gt(),Lo=TypeError,Qt=Object.defineProperty,_o=Object.getOwnPropertyDescriptor,Kt="enumerable",Yt="configurable",Zt="writable";mn.f=So?Mo?function(e,r,i){if(Ge(e),r=fn(r),Ge(i),typeof e=="function"&&r==="prototype"&&"value"in i&&Zt in i&&!i[Zt]){var n=_o(e,r);n&&n[Zt]&&(e[r]=i.value,i={configurable:Yt in i?i[Yt]:n[Yt],enumerable:Kt in i?i[Kt]:n[Kt],writable:!1})}return Qt(e,r,i)}:Qt:function(e,r,i){if(Ge(e),r=fn(r),Ge(i),wo)try{return Qt(e,r,i)}catch{}if("get"in i||"set"in i)throw new Lo("Accessors not supported");return"value"in i&&(e[r]=i.value),e}});var gn=u((np,vn)=>{"use strict";var Ao=ie(),Ro=yn(),ko=wt();vn.exports=Ao?function(t,e,r){return Ro.f(t,e,ko(1,r))}:function(t,e,r){return t[e]=r,t}});var En=u((sp,Cn)=>{"use strict";var fe=F(),Po=Pr(),Vo=Tt(),Oo=U(),jo=nn().f,No=an(),se=At(),Fo=cn(),ae=gn(),bn=Ue();Dt();var $o=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 Po(t,this,arguments)};return e.prototype=t.prototype,e};Cn.exports=function(t,e){var r=t.target,i=t.global,n=t.stat,s=t.proto,l=i?fe:n?fe[r]:fe[r]&&fe[r].prototype,a=i?se:se[r]||ae(se,r,{})[r],o=a.prototype,c,d,f,y,b,w,$,I,h;for(y in e)c=No(i?y:r+(n?".":"#")+y,t.forced),d=!c&&l&&bn(l,y),w=a[y],d&&(t.dontCallGetSet?(h=jo(l,y),$=h&&h.value):$=l[y]),b=d&&$?$:e[y],!(!c&&!s&&typeof w==typeof b)&&(t.bind&&d?I=Fo(b,fe):t.wrap&&d?I=$o(b):s&&Oo(b)?I=Vo(b):I=b,(t.sham||b&&b.sham||w&&w.sham)&&ae(I,"sham",!0),ae(a,y,I),s&&(f=r+"Prototype",bn(se,f)||ae(se,f,{}),ae(se[f],y,b),t.real&&o&&(c||!o[y])&&ae(o,y,b)))}});var xn=u((ap,In)=>{"use strict";var Bo=Math.ceil,qo=Math.floor;In.exports=Math.trunc||function(e){var r=+e;return(r>0?qo:Bo)(r)}});var Xt=u((op,Tn)=>{"use strict";var Do=xn();Tn.exports=function(t){var e=+t;return e!==e||e===0?0:Do(e)}});var wn=u((lp,Sn)=>{"use strict";var Ho=Xt(),Uo=Math.min;Sn.exports=function(t){var e=Ho(t);return e>0?Uo(e,9007199254740991):0}});var Ln=u((cp,Mn)=>{"use strict";var Go=wn();Mn.exports=function(t){return Go(t.length)}});var An=u((pp,_n)=>{"use strict";_n.exports=function(){}});var Rn=u(()=>{"use strict";var zo=En(),Wo=Ht(),Qo=Ln(),Ko=Xt(),Yo=An();zo({target:"Array",proto:!0},{at:function(e){var r=Wo(this),i=Qo(r),n=Ko(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:r[s]}});Yo("at")});var Pn=u((dp,kn)=>{"use strict";var Zo=Pt();kn.exports=Zo});var On=u((fp,Vn)=>{"use strict";Rn();var Xo=Pn();Vn.exports=Xo("Array","at")});var Nn=u((mp,jn)=>{"use strict";var Jo=On();jn.exports=Jo});var Jt=u((yp,Fn)=>{"use strict";var el=Nn();Fn.exports=el});var Sl={};js(Sl,{CustomError:()=>A,EVENT_NAMES:()=>v,Interactives:()=>Le,ManifestController:()=>Z,SDKInfo:()=>Tl,chapterIdsToVKVideoIds:()=>ot,compareVersions:()=>q,getChapterIdByVkVideoId:()=>Ss,getVKVideoIdByMedia:()=>dr,getVideoRawIdByMedia:()=>xs,graphEventTypes:()=>le,hasEndTemplate:()=>Te,interactivesEventTypes:()=>T,isLastChapter:()=>N,isSupportedManifest:()=>Ce,isVKVariantItem:()=>Ts,utils:()=>_s,vkVideoIdsToChapterIds:()=>fr});module.exports=Ns(Sl);var Cr="1.0.23-dev.75664bee.0";function ft(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 P="interactive",Fs="interactive-controls-container",Re=()=>document.querySelector(`.${Fs}`),Er=.4,R={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Ir=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Ir||{}),xr=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(xr||{}),Tr=(i=>(i.start="left",i.end="right",i.center="center",i))(Tr||{}),ke=({target:t,props:e})=>{t.style.alignItems=(e.text?.gravityVertical&&Ir[e.text.gravityVertical])??"center",t.style.justifyContent=(e.text?.gravityHorizontal&&xr[e.text.gravityHorizontal])??"center",t.style.textAlign=(e.text?.alignment&&Tr[e.text.alignment])??"left"},Pe=({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},Ve=({target:t,props:e,fallback:r})=>{t.style.backgroundColor=ft(e?.background?.color??r.backgroundColor,e?.background?.alpha??r.backgroundAlpha)},Oe=({target:t,props:e,fallback:r,dependsOn:i})=>{t.style.border=`calc(${i.height} * ${e?.shape?.border?.width??r.borderWidth}) solid ${ft(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})=>{let i=e.angle??r.angle;i=i&&i*-1,t.style.transform=`rotate(${i}rad)`};var B=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let r=document.createElement("div");r.classList.add(`${P}-control-container-${this.control.id}`),e(r,this.control.layoutParams);let i=(this.control.layoutParams.innerSizesDependOn??R.innerSizesDependOn)==="self"?{height:r.style.height,width:r.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:r,dimensions:i}}createClickListener(e){return r=>{r.stopPropagation(),e()}}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(r=>{switch(r.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:r.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var mt="int",z=(i=>(i.AREA=`${mt}_area`,i.TEXT=`${mt}_text`,i.BUTTON=`${mt}_bttn`,i))(z||{});var je=t=>{if(t.type.trim().toLowerCase()==="area")return new yt(t)},yt=class extends B{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(`${P}-${this.control.id}`),i.setAttribute("data-testid",z.AREA),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.cursor="pointer",Ve({target:i,props:this.control.props,fallback:{...R,backgroundColor:"transparent"}}),Oe({target:i,props:this.control.props,fallback:{...R,borderAlpha:0},dependsOn:this.container.dimensions}),te({target:i,layoutParams:this.control.layoutParams,fallback:R}),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Ne=()=>{let t=document.createElement("span");return t.style.display="inline-block",t.style.whiteSpace="pre",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.maxWidth="100%",t.style.maxHeight="100%",t};var Fe=t=>{if(t.type.trim().toLowerCase()==="button")return new vt(t)},vt=class extends B{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(`${P}-${this.control.id}`),i.setAttribute("data-testid",z.BUTTON),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.cursor="pointer",i.style.fontFamily="inherit",te({target:i,layoutParams:this.control.layoutParams,fallback:R}),Ve({target:i,props:this.control.props,fallback:R}),Oe({target:i,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),ke({target:i,props:this.control.props});let n=Ne();Pe({target:n,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Sr=t=>{if(t.type.trim().toLowerCase()==="text")return new gt(t)},gt=class extends B{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let i=document.createElement("div");i.classList.add(`${P}-${this.control.id}`),i.setAttribute("data-testid",z.TEXT),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.fontFamily="inherit",te({target:i,layoutParams:this.control.layoutParams,fallback:R}),ke({target:i,props:this.control.props});let n=Ne();Pe({target:n,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}disable(){}enable(){}getElement(){return this.controlElement}};var bt=class{constructor(e){this.layout=e}},$e=class extends bt{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 re=class{constructor(e){this.container=e,this.factories=new Map,this.#e()}addControlFactory(e,r){this.factories.set(e.trim().toLowerCase(),r),this.#e()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.#e()}#e(){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 Be=(t,e)=>{if(t.type.trim().toLowerCase()==="choice")return new Ct(t,e)},Ct=class extends re{constructor(e,r){super(e),this.rootElement=r??Re(),this.layout=new $e(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Fe),this.addControlFactory("text",Sr),this.addControlFactory("area",je)}createView(e){let r=document.createElement("div");return r.classList.add(`${P}-${this.container.id}`),this.layout.setContainerLayout(r),this.controls.forEach(i=>{i.createView({parentElement:r,layoutCallback:this.layout.setControlLayout}),i.setEvents(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=Er,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${P}-${this.container.id}`)}};var Ls=dt(Jt(),1),E=require("@vkontakte/videoplayer-shared"),ce=require("@vkontakte/videoplayer-statistics");var Hn=require("@vkontakte/videoplayer-shared");function me(t,e){let r;return(...i)=>{clearTimeout(r),r=setTimeout(()=>t(...i),e)}}var Q=(t,e)=>Object.prototype.toString.call(t)===`[object ${e}]`,ye=t=>Q(t,"Object"),ze=t=>Q(t,"String"),We=t=>Q(t,"Array"),Qe=t=>Q(t,"Number"),$n=t=>Q(t,"Function");var er=t=>Qe(t)&&!isNaN(t);var K=t=>ye(t)&&Object.keys(t).length===0,tr=t=>We(t)&&!t.length;var ve=(t,e)=>ze(t)&&(e?t.trim():t).length;var Bn="video_interactive",qn="videoint";var Dn=250,ge=class{constructor(e){this.handleZoomChange=me(e=>{this.lastZoomInfo=e},Dn);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let r=this.getNextPoint();r&&this.ngEditor?.zoomTo(r),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){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=null}};this.handleManifestChange=(e,r=[])=>{if(this.isReady=!1,!Qe(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph"),console.error("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(r),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(r)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:r,onError:i,lang:n,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=r,this.onError=i,this.lang=n??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=tl(e),this.resizeObserver=new ResizeObserver(me(this.onResize,Dn)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await(0,Hn.loadVKLangPack)(this.lang,Bn,qn)}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==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.ngEditor.on("control",({name:i,...n})=>{i==="openPreview"&&"chapterId"in n&&this.onOpenPreviewClick?.(n.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function tl(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 be=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(r=>r.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let r=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let l=s.startTime-e;if(l<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<l&&(r=r===-1?l:Math.min(r,l))}return!i&&r!==-1?r:null}}};var q=(t="",e="")=>{let r=t.split("."),i=e.split("."),n=0;for(let s=0;s<Math.max(r.length,i.length)&&!n;s++)r[s]>i[s]?n=1:r[s]<i[s]?n=-1:n=0;return n};var Gn=require("uuid"),rl="3.1",Un={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},il={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},zn=t=>{let e=[];for(let r of t.chapters){let i,n=[];for(let{isDefault:a,...o}of r.branches)a&&(i=o.id),n.push(o);let s=[],l=[];for(let{fallbackStrategy:a,...o}of r.containers){let c=!!o.endTime,d=[il];switch(a){case"await":c?d=[]:s=[];break;case"default":{let f={type:"onSuspense",action:{type:Un.default,args:{branchId:i,shouldOpenNow:!c,isDetachContainer:!0}}};c?d=[f]:s=[f];break}case"random":case"weightlessRandom":case"max":case"min":{let f={type:"onSuspense",action:{type:Un[a],args:{}}};c?d=[f]:s=[f];break}}for(let f of o.controls)l.push({...o,controls:[{...f}],id:(0,Gn.v4)(),events:d})}e.push({...r,containers:l,events:s,branches:n})}return t.metadata.version=rl,t.metadata.updated=new Date().toISOString(),{...t,chapters:e}};var nl="3.2",Wn=t=>{if(!t.media){let{media:e,...r}=t.metadata;return{...t,metadata:{...r,version:nl},media:e}}return t};var sl="3.3",al=(t=[])=>({edit:{chapters:t},view:{}}),Qn={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Kn=t=>{let e=[],r=[];for(let i of t.chapters){let{id:n,x:s,y:l,...a}=i,o=a.containers.map(c=>({...c,controls:c.controls.map(({subtype:d,type:f,...y})=>({...y,type:d??f})),events:c.events?.length?c.events:[Qn]}));e.push({id:n,...a,containers:o,events:a.events?.length?a.events:[Qn]}),r.push({id:n,x:s,y:l})}return{...t,chapters:e,graph:al(r),metadata:{...t.metadata,version:sl}}};var ol=[{version:"3.0",migrate:zn},{version:"3.1",migrate:Wn},{version:"3.2",migrate:Kn}],rr=t=>ol.reduce((e,r)=>q(e.metadata.version,r.version)?e:r.migrate(e),t);var Yn={Button:"Button",Area:"Area",Text:"Text"};var S={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var Zn={metadata:"Object",chapters:"Array"},ll="3.0.0",cl="3.3.0",Ce=t=>{let e=q(t,ll);return e===-1?!1:e===0?!0:q(t,cl)!==1},Xn=t=>{if(!ye(t))return!1;for(let e in Zn)if(!t[e]||!Q(t[e],Zn[e]))return!1;return Ce(t.metadata.version)},Ke=t=>t.type===Yn.Text;var A=class{constructor(e,r,...i){this.severity=e;this.category=r;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Ye=class{constructor(){this.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]||[];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.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Ze=class{constructor(e){this.fns=[];this.addFn=(e,r=!1)=>{$n(e)&&(this.fns.push(e),r&&this.updateFn())};this.removeFn=(e,r=!1)=>{this.fns=this.fns.filter(i=>i!==e),r&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};var ns=require("@vkontakte/videoplayer-shared");var Xe=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,r){return pl(...this.loaders[e])(r)}};function pl(...t){return async function(r){let i=[...t];for(;i.length>0;)r=await i.shift()(r);return r}}function Ee(t,e,r){return t?{...t,[e]:t[e]?[r,...t[e]]:[r]}:{[e]:[r]}}function Je({actions:t,errors:e,chapterId:r,...i}){if(r){let n=t.getManifest(),s=t.getChapter(n.chapters,r);if(s){let l=t.getMedia(n.media,s.videoId),a=t.getGraph(n.graph,s.id);return l?{...i,actions:t,errors:e,result:{chapter:s,media:l,graph:a}}:{...i,errors:Ee(e,Je.name,"Could not find media"),actions:t}}}return{...i,errors:Ee(e,Je.name,"Could not find chapter"),actions:t}}var et=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:i})}removeEventListener(e,r){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,s=i.length;n<s;n++)if(i[n].callback===r){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,s=i.length;n<s;n++){let l=i[n];try{l.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},oe=class extends et{constructor(){super(),this.listeners||et.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Ie=class{constructor(){Object.defineProperty(this,"signal",{value:new oe,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch{typeof document<"u"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document>"u")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch{i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(Ie.prototype[Symbol.toStringTag]="AbortController",oe.prototype[Symbol.toStringTag]="AbortSignal");function tt(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function ir(t){typeof t=="function"&&(t={fetch:t});let{fetch:e,Request:r=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=t;if(!tt({fetch:e,Request:r,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:s};let s=r;(s&&!s.prototype.hasOwnProperty("signal")||n)&&(s=function(c,d){let f;d&&d.signal&&(f=d.signal,delete d.signal);let y=new r(c,d);return f&&Object.defineProperty(y,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),y},s.prototype=r.prototype);let l=e;return{fetch:(o,c)=>{let d=s&&s.prototype.isPrototypeOf(o)?o.signal:c?c.signal:void 0;if(d){let f;try{f=new DOMException("Aborted","AbortError")}catch{f=new Error("Aborted"),f.name="AbortError"}if(d.aborted)return Promise.reject(f);let y=new Promise((b,w)=>{d.addEventListener("abort",()=>w(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([y,l(o,c)])}return l(o,c)},Request:s}}var xe=tt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Jn=xe?ir({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,nr=xe?Jn.fetch:window.fetch,hh=xe?Jn.Request:window.Request,uh=xe?Ie:window.AbortController,dh=xe?oe:window.AbortSignal;var hl=async t=>{try{let e={},r;if(ze(t)){r=new URL(t).href;let n=await nr(r);if(!n.ok)return{};e=await n.json()}else if(ye(t))e=t;else return{};if(!Xn(e))return{};let i=e.metadata.media;if(ze(i)&&!e.media)try{let n;r?n=new URL(i,r).href:(n=new URL(i).href,r=n);let s=await nr(n);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return fl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:r}}catch{return{}}};async function es(t){let{manifest:e,manifestURL:r}=await hl(t),i=rr(e);return i.media=ul(i.media,r),delete i.metadata.media,i}function rt(t,e){if(e)return t.find(r=>r.id===e)}function sr(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 ar(t,e){return t.videos.find(r=>r.id===e)}function ul(t,e){return{...t,videos:t.videos.map(r=>({...r,variants:r.variants.map(i=>{let n="url"in i?i.url:"",s=dl(n,e);return{...i,url:s||n}})}))}}function dl(t="",e){try{return new URL(t,e).href}catch{return""}}function fl(t){return q(t,"3.2.0")>=0}var it=t=>We(t)&&!tr(t),N=t=>t.order==="end",Te=t=>We(t.containers)&&!tr(t.containers)&&N(t),ts=(t,e)=>{let r=t*1e3;return it(e.controls)&&r<(e.startTime??0)},or=(t,e)=>{let r=t*1e3;return it(e.controls)&&r>=(e.startTime??0)&&r<=(e.endTime??1/0)};var Y=(t=[])=>t.some(e=>e.action.type==="expect"),lr=(t=[])=>t.find(e=>e.action.type==="expect"),ml=t=>t?.length===1,nt=t=>ml(t)&&Ke(t[0]);function rs(t,...e){return r=>typeof e[0]=="object"&&typeof r=="object"?t({...e[0],...r}):t(...e,...r)}var is=(t,e)=>Y(t.events)?!1:e.some(({container:r})=>r.container.id!==t.id&&Y(r.container.events)&&r.container.endTime===t.endTime&&!r.isRemoved);var Z=class extends Xe{constructor(r,i){super(r);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new ns.ValueSubject(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(r){this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ee},result:null,errors:null,source:r});return i.errors&&this.errorHandler(i.errors),this.manifest=await es(i.result??r),this}async setInitial(){return this.setNext()}async setNext(r=this.manifest?.metadata.initChapterId){if(!r)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",Je({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:sr,getChapter:rt,getMedia:ar,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ee},result:null,errors:null,chapterId:r}));return i.errors&&this.errorHandler(i.errors),this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph,this}errorHandler(r){this.onError(r),console.error("Something went wrong with loaders",{errors:r})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(r=this.manifest?.metadata.initChapterId){if(!r||!this.manifest)return null;let i=rt(this.manifest.chapters,r);if(i){let n=ar(this.manifest.media,i.videoId),s=sr(this.manifest.graph,i.id);if(n)return{chapter:i,media:n,graph:s}}return null}getBranches(r=this.chapter?.id){if(r===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let i=rt(this.manifest?.chapters||[],r);return this.getByBranches(i?.branches)}}getByBranches(r=[]){return r.reduce((i,n)=>{let s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?N(this.chapter):!1}};var as=require("@vkontakte/videoplayer-core"),G=require("@vkontakte/videoplayer-shared");var ss=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[]};function cr(){let t=new Map;function e({listId:s=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let o=t.get(s),c={...a};return o?o[l]=c:t.set(s,{[l]:c}),{listId:s,itemId:l,...a}}function r(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function i(s,l){let a=t.get(s);if(!a)throw Error("Can't remove. Not find.");if(l){let o=a[l];o&&r(o),delete a[l],Object.keys(a).length||t.delete(s)}else{for(let o of Object.values(a))r(o);t.delete(s)}}function n(){for(let s of t)i(s[0])}return{createPlayer:e,removePlayer:i,map:t,removeAll:n}}function pr(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 Se=(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 yl=2;function hr(t){let e=cr(),r=new G.Subscription,i={},n=null,s=!1,l,a=new G.ValueSubject(null);t&&o(t);function o(I){n=I}function c(I,h,p){if(!n)throw Error("need to set interactive controller");if(!n.options)return;let C=(e.map.get(I)??{})[h];if(C){i={chapterId:p,listId:I,itemId:h,...C};let g=i.player;i.subscription.add(g.info.currentQuality$.subscribe(L=>{let M=g.info.position$.getValue(),k=g.info.isAutoQualityEnabled$.getValue();if(!(!L||!M||k))for(let x of e.map)Object.values(x[1]).forEach(({player:_})=>{Se(_,L)})})).add(g.events.started$.subscribe(()=>{d(h)})),C.container.remove(),n.setPlayer(C.player),s||(n.init(),s=!0),a.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}async function d(I){if(!n)throw Error("need to set interactive controller");if(K(i)||I!==i.itemId)return;let h=n.getChapterBranches(),p=new Set;for(let m of h)p.has(m.media.id)||(await y({media:m.media,chapterId:m.chapter.id,setAsActive:!1,title:m.chapter.label}),p.add(m.media.id))}async function f({chapter:{id:I},manifestVideo:h}){if(K(i)||!n)return;let p=i.player.info.muted$.getValue(),m=i.player.info.currentQuality$.getValue(),C=i.player.info.isAutoQualityEnabled$.getValue(),g=i.player.info.volume$.getValue(),L=i.player.info.currentPlaybackRate$.getValue(),M=!C,k=!1;for(let x of e.map)if(x[0]===h.id&&!n.state.isReplay$.getValue()){let _=Object.keys(x[1]);for(let V of _)V===i.itemId?(_.length<yl||(k=!0),e.removePlayer(x[0],V)):(k=!0,c(x[0],V,I),M?Se(i.player,m):i.player.setAutoQuality(!0),i.player.setVolume(g),i.player.setMuted(p),i.player.setPlaybackRate(L))}else e.removePlayer(x[0]);k||(await y({media:h,chapterId:I,setAsActive:!0,playbackRate:L}),M?Se(i.player,m):i.player.setAutoQuality(!0),i.player.setVolume(g),i.player.setMuted(p))}async function y({media:I,chapterId:h,prefetch:p=!0,setAsActive:m=!0,autoplay:C=!1,preferredExt:g,title:L,playbackRate:M}){let k=Math.random().toString(),x=document.createElement("div");l.append(x);let _;if(n?.options?.vkVideoLoader){let _e=ss(I);_e.length&&(_=await n.options.vkVideoLoader(..._e))}let V=n?.options?.coreConfig||void 0,X={...V,configName:[...V?.configName??[],"interactive"]},J={container:x,..._?.videos?.[0]||{sources:pr(I,g).sources},title:L,failoverHosts:_?.failoverHosts||[]},D=new as.Player(X,G.Tracer.createRootTracer());D.initVideo(J);let yr=null;if(_?.videos&&n?.options.createOneStat){let _e=_.videos[0],ut=n.options.createOneStat(_e),gr=new G.Subscription;ut&&(gr.add(ut.attachTo(D)),yr={oneStat:ut,statSubscription:gr})}let vr=new G.Subscription,As=i?.player?.info.isAutoQualityEnabled$.getValue();vr.add(D.events.canplay$.subscribe(function(){As||Se(D,i.player.info.currentQuality$.getValue()),M&&D.setPlaybackRate(M)}));let ee=e.createPlayer({listId:I.id,itemId:k,player:D,container:x,sources:pr(I,g).sources,config:J,subscription:vr,statistics:yr});return m&&c(I.id,ee.itemId,h),C&&ee.player.play(),p&&!C&&ee.player.prepare(),{player:ee.player,config:ee.config,statistics:ee.statistics}}function b(){w(),n=null,l.remove()}function w(){r.unsubscribe(),e.removeAll(),i={},s=!1}async function $(){if(!n)throw Error("need to set interactive controller");w(),l=document.createElement("div");let{media:I,chapter:h}=n.getCurrentChapter();I&&h?(r.add(n.events.chapterChanged$.subscribe(f)),await y({media:I,chapterId:h.id,title:h.label})):console.error("not found")}return{...e,init:$,setInteractiveController:o,createPlayer:y,removeAll:b,getActivePlayer:function(){return i},activePlayerChanged:a}}var v={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},le={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},T={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var os=require("@vkontakte/videoplayer-shared");var st=class{constructor({player:e,container:r,branches:i,selectBranches:n,interactiveEvents:s,globalEvents:l,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d,onRemove:f}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(Y(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})))})};this.show=()=>{if(this.gameState===2&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!0,isFirst:!1});else{let r=rs(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})},onEvent:(i,n)=>{this.isSelectedControlEvent=!0,i!==!1&&(this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),n(),this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(r),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),i=e instanceof HTMLVideoElement?e.readyState:void 0,n=[6,5];if(!i||n.includes(this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(ts(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(or(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let c=this.gameState;this.gameState=3,c===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=or(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(v.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=r,this.branches=i,this.selectBranches=n,this.subscription=new os.Subscription,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&nt(r.container.controls),this.disabledControls$=d,this.onRemove=f,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,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?.()}))}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??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=Y(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.containerRemoved,visibility:!1}),this.gameState=5,this.onRemove?.()}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var ls=(t=[])=>t.reduce((e,r,i)=>{let n=(r?.controls??[]).filter(s=>!Ke(s));if(it(n)){let s=[r.startTime??0,r.endTime??1/0],l=r.id;if(!i)e.push({subjects:[l],range:s});else{let a=[],o=-1/0,c=1/0,d=[],f=[];for(let y=0;y<e.length;y++){let b=e[y];if(f.push(...b.subjects),b.range[0]<c&&(c=b.range[0]),b.range[1]>o&&(o=b.range[1]),s[0]>=b.range[0]&&s[1]<=b.range[1])return e[y].subjects.push(l),e;s[0]<b.range[0]&&s[1]>b.range[0]&&(a.push(y),d=d.concat(b.subjects)),s[0]>=b.range[0]&&s[0]<=b.range[1]&&(a.push(y),d=d.concat(b.subjects),s[0]=b.range[0]),s[1]>=b.range[0]&&s[1]<=b.range[1]&&(a.push(y),d=d.concat(b.subjects),s[1]=b.range[1])}if(f.push(l),s[0]<=c&&s[1]>=o)return[{subjects:f,range:s}];a.length&&a.reverse().forEach(y=>{e.splice(y,1)}),e.push({subjects:d.concat([l]),range:s})}}return e},[]).sort((e,r)=>e.range[0]-r.range[0]);function cs(){let t={};function e(){for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&delete t[a]}function r(a){let o={};for(let c in t)+c<=a&&(o[c]=t[c]);return o}function i(a){let o={};for(let c in t)+c>=a&&(o[c]=t[c]);return o}function n({timestamp:a,priority:o,initiator:c}){if(er(a)){let d=t[a]??null;if(d&&o&&ve(o,!0)){let f={},y=d[o];return y&&(f={...f,...y}),f=K(f)?null:f,f&&ve(c,!0)?f[c]??null:f}return d}return null}function s({timestamp:a,priority:o,initiator:c}){if(er(a))if(t[a]){if(o&&ve(o,!0))if(t[a][o]){if(c&&ve(c,!0))if(t[a][o][c]){if(delete t[a][o][c],!K(t[a][o]))return!0}else return!1;if(delete t[a][o],!K(t[a]))return!0}else return!1;return delete t[a]}else return!1;return!1}function l({timestamp:a,priority:o,initiator:c,...d}){t[a]?.[o]?.[c]?t[a][o][c].push({...d}):t[a]?.[o]?t[a][o]={...t[a][o],[c]:[{...d}]}:t[a]?t[a]={...t[a],[o]:{[c]:[{...d}]}}:t[a]={[o]:{[c]:[{...d}]}}}return{map:t,remove:s,add:l,removeAll:e,get:n,getLte:r,getGte:i}}var vl=[S.expect,S.setNextBranch],gl=1/0;function ps(t){let e=t,r,i=bl(),n=cs(),s,l=()=>{y(),h()},a=p=>{n.add.call(void 0,p),w()},o=(p=[])=>{for(let m of p)if(m.action(),vl.includes(m.actionType))break},c=(p=1/0)=>{let m=at(n.get({timestamp:p,priority:"control"})??{}),C=at(n.get({timestamp:p,priority:"container"})??{}),g=at(n.get({timestamp:p,priority:"chapter"})??{});return[...m,...C,...g]},d=p=>{i.isReady(p)&&o(c(p))},f=()=>{o([...at(n.get({timestamp:1/0,priority:"chapter"})??{})])},y=()=>{r&&(s?.unsubscribe(),r=void 0)},b=p=>{},w=()=>{r||(r=()=>setTimeout(()=>{d(1/0)}),s=e.events.ended$.subscribe(r))},$=p=>{y(),e=p},I=p=>{p.priority==="container"&&i.resetCalled(p.timestamp),n.remove(p)},h=()=>{i.release(),n.removeAll()};return{setPlayer:$,add:a,remove:I,exec:d,execEndOfVideo:f,listen:w,unlisten:y,release:l,containersEventsCallState:i,getPreparedToExecActions:c}}function bl(){let t=new Map;return{setCalled:({timestamp:l,id:a})=>{let o=t.get(l);o&&o[a]!==void 0&&(o[a]=!0)},setData:(l=[])=>{for(let a of l){let o=a.endTime??gl,c=t.get(o)??{};t.set(o,{...c,[a.id]:!1})}},resetCalled:l=>{let a=t.get(l);if(a)for(let o in a)a[o]=!1},isReady:l=>{let a=t.get(l);return a?!Object.values(a).some(o=>!o):!0},release:()=>t.clear()}}function at(t){return Object.values(t).flat().sort(e=>e.actionType===S.expect?-1:1)}var hs={videoContentHeight:0,videoContentWidth:0},us=(t,e)=>{let{height:r,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(r&&i))return hs;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return hs;let l=r/i,a=n/s,o,c;return a>l?(c=s,o=s*l):a<l?(c=n/l,o=n):(c=s,o=n),{videoContentWidth:c,videoContentHeight:o}};var Cl=250;function ds(t){let e=()=>{},r=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function i(a){let{parentElement:o,player:c}=t();if(o&&c){let{videoContentWidth:d,videoContentHeight:f}=us(o,c);o.style.setProperty("--interactive-content-width",`${d}px`),o.style.setProperty("--interactive-content-height",`${f}px`),o.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function n(){let{parentElement:a}=t();a.removeAttribute("style")}let s=me(a=>{let{fns:o=[]}=t();i(a);for(let c of o)c()},Cl);function l(){e=void 0,r.disconnect(),n()}return{resizeObserver:r,calc:()=>{e?.()},release:l}}var we=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.concat(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={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var El=t=>Math.floor(Math.random()*t),ms=t=>{let e=t.length,r=1/0,i=null;for(;e--;){let n=t[e],s=n.weight??1;s<r&&(r=s,i=n)}return i},ys=t=>{let e=t.length,r=-1/0,i=null;for(;e--;){let n=t[e],s=n.weight??0;s>r&&(r=s,i=n)}return i};var vs=t=>{let e=t.length,r=El(e);return t[r]},fs=1,gs=t=>{let e=0;for(let i=0;i<t.length;++i)e+=t[i].weight??fs;let r=Math.random()*e;e=0;for(let i=0;i<t.length-1;++i)if(e+=t[i].weight??fs,e>=r)return t[i];return t[t.length-1]};var bs={shouldOpenNow:!0,isDetachContainer:!0};var ur=(t,e=!1)=>({...t,args:e?{...t.args,...bs}:{...bs,...t.args}}),Is=({globalEventEmitter:t,player:e,interactiveEvents:r,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:h,controlType:p,controlId:m,containerId:C,branches:g=[],onEvent:L,isEOV:M=()=>!1,isDisabled:k=()=>!1})=>{let x=ur(h,M()),_={timestamp:1/0,priority:"control",initiator:m,actionType:x.type},V=k(),X=t.emit.bind(t,v.interactives,{subjectId:m,subjectType:p,subjectName:"control",type:V?T.actionChoiceCanceled:T.actionChoice,actionType:h.type,payload:{containerId:C,...x.args}});if(V){X();return}switch(x.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let J=g.find(D=>D.id===x.args.branchId);if(!J)return;L(x.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),X(),x.args.shouldOpenNow?w({subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{chapterId:J.chapterId,autoSelect:!1}}):(r.add({..._,action:w.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{chapterId:J.chapterId,autoSelect:!1}})}),i?.());return}case S.continuePlayback.trim().toLowerCase():{L(x.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),X(),x.args.shouldOpenNow?b({subjectId:m,subjectName:"control",subjectType:p,action:h}):r.add({..._,action:b.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:h})});return}case S.openURI.trim().toLowerCase():{L(x.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),X(),x.args.shouldOpenNow?I({subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{URI:h.args.uri}}):(r.add({..._,action:I.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{URI:h.args.uri}})}),i?.());return}default:console.error("Unexpected control event"),t.emit(v.errors,new A(1,1,{message:"Unexpected control event"}));return}},a=({action:h,container:{id:p,endTime:m},branches:C=[],isEOV:g=!1,autoSelected:L=!1})=>{let M=ur(h,g),k={timestamp:!M.args.shouldOpenNow||g?1/0:m??1/0,priority:"container",initiator:p,actionType:M.type},x=t.emit.bind(t,v.interactives,{subjectId:p,subjectName:"container",type:T.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let _=C.find(V=>V.id===M.args.branchId);if(!_)return;x(),r.add({...k,action:w.bind(null,{subjectId:p,subjectName:"container",action:M,payload:{chapterId:_.chapterId,autoSelect:L}})}),i?.();return}case S.setMaxWeightBranch.trim().toLowerCase():return;case S.setMinWeightBranch.trim().toLowerCase():return;case S.setRandomBranch.trim().toLowerCase():return;case S.setWeightlessRandomBranch.trim().toLowerCase():return;case S.continuePlayback.trim().toLowerCase():{x(),r.add({...k,action:b.bind(null,{subjectId:p,subjectName:"container",action:M})});return}case S.openURI.trim().toLowerCase():{x(),r.add({...k,action:I.bind(null,{subjectId:p,subjectName:"container",action:M,payload:{URI:h.args.uri}})}),i?.();return}default:console.error("Unexpected container event"),t.emit(v.errors,new A(1,1,{message:"Unexpected container event"}));return}};function o({container:h,branches:p,isEOV:m=!1}){let C=lr(h.events);if(C){let g=ur(C.action,m);t.emit(v.interactives,{subjectId:h.id,subjectName:"container",type:T.actionChoice,actionType:g.type,payload:g.args}),r.add({timestamp:m?1/0:h.endTime??1/0,priority:"container",initiator:h.id,actionType:S.expect,action:f.bind(null,{subjectId:h.id,subjectName:"container"})}),n.isExpect=!0}else for(let g of h.events??[])a({action:g.action,container:h,branches:p,isEOV:m})}let c=({chapterId:h,action:p,branches:m=[]})=>{let C=t.emit.bind(t,v.interactives,{subjectId:h,subjectName:"chapter",type:T.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let g=m.find(L=>L.id===p.args.branchId);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setWeightlessRandomBranch.trim().toLowerCase():{let g=vs(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setRandomBranch.trim().toLowerCase():{let g=gs(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setMaxWeightBranch.trim().toLowerCase():{let g=ys(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setMinWeightBranch.trim().toLowerCase():{let g=ms(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.continuePlayback.trim().toLowerCase():return C(),b.bind(null,{subjectId:h,subjectName:"chapter",action:p});case S.openURI.trim().toLowerCase():return C(),I.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),t.emit(v.errors,new A(1,1,{message:"Unexpected chapter event"}));return}};function d(h){let p=lr(h.events);if(p){if(N(h))return;t.emit(v.interactives,{subjectId:h.id,subjectName:"chapter",type:T.actionChoice,actionType:p.action.type,payload:p.action.args}),r.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:S.expect,action:f.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events?.forEach(m=>{let C=c({chapterId:h.id,action:m.action,branches:h.branches});C&&r.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:m.action.type,action:C})})}let f=({subjectId:h,subjectName:p})=>{e.pause(),t.emit(v.interactives,{subjectId:h,subjectName:p,type:T.actionExecution,actionType:S.expect})},y=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?r.execEndOfVideo():e.play(),t.emit(v.interactives,{subjectId:h,subjectName:p,type:T.actionExecution,actionType:"after-expect"})},b=({subjectId:h,subjectName:p,subjectType:m,action:C})=>{t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type})},w=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:g})=>{g.behaviour="change-chapter",t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type,payload:g})},$=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:g})=>{g.behaviour="change-manifest",t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type,payload:g})},I=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:g})=>{if(!g.URI)return;let L=window.open(g.URI,"_blank","noopener,noreferrer");L&&(L.opener=null),t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:c,onExpectEvent:f,expectEventHandler:y,setManifestChapterEvents:d,setManifestContainerEvents:o,stopExpect:s,state:n}};var mr=dt(Jt(),1),O=require("@vkontakte/videoplayer-shared");var ot=(t,e)=>{let r={};return t.map(i=>{if(!r[i]){let n=e.chapters.find(l=>l.id===i);if(!n)return null;let s=e.media.videos.find(l=>n.videoId===l.id);if(!s)return null;r[i]=dr(s)}return r[i]}).filter(Boolean)},xs=t=>{for(let e of t.variants)if(Ts(e)&&"payload"in e)return e.payload.id},Ts=t=>t.type==="custom"&&"payload"in t&&t.payload.type==="vk",dr=t=>{let e=xs(t);if(!e)return null;let r=e.split("_").pop();return r?parseInt(r,10):null},Ss=(t,e)=>{for(let r of t.media.videos)if(e===dr(r)){for(let i of t.chapters)if(i.videoId===r.id)return i.id;return}},fr=(t,e)=>t.reduce((r,i)=>{let n=Ss(e,i);return n?[...r,n]:r},[]);var Me=class{constructor({globalEventEmitter:e,videoId:r,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new O.ValueSubject([]),hasPrevChapter$:new O.ValueSubject(!1),prevChapter$:new O.ValueSubject(null),isInitialChapter$:new O.ValueSubject(!1),isGoBackLimited$:new O.ValueSubject(!1)};this.#e=null;this.#a=!1;this.#t=null;this.#p=null;this.events={inited$:new O.Subject,destroyed$:new O.Subject,error$:new O.Subject};this.#n=null;this.#s=null;this.#r=null;this.#o=new O.Subscription;this.#l=!1;this.#c=0;this.#n=r,this.#r=e,this.#s=i,this.#e=n,this.#i=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,mr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#t?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#i.maxLength-1)}))}#e;#i;#a;#t;#p;#n;#s;#r;#o;#l;#c;async setManifest(e){if(!this.#s||!this.#r)return;this.#t=e,await this.getProjectHistory();let r=this.getInitialChapterId();await this.#s.setChapter({chapterId:r,pushToHistory:!1}),this.#a||(this.#a=!0,this.events.inited$.next({initChapterId:r}))}get inited(){return this.#a}async updateHistory(e,r=!0){if(!this.#t)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let i=this.#t,n=e.length-this.#i.maxLength,s=n>0?e.slice(n):e,l=ot(s,i);if(this.#p=l,this.state.history$.next(s),!(!r||!this.#e||!this.#n))try{await this.#e.save(this.#n,l)}catch{let o=new A(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#r?.emit(v.errors,o)}}async goBack(){if(!this.state||!this.#s){let i=new A(1,5,"Unable to save interactive history");return this.events.error$.next(i),this.#r?.emit(v.errors,i)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),r=e.pop();this.state.history$.next(e),await this.#s.setChapter({chapterId:r,playPrev:!0})}async getProjectHistory(){if(!this.#t||!this.#n)return;let e=this.#t,r=[this.getInitialVideoId()];if(this.#e)try{let n=await this.#e.get(this.#n);n.length&&(r=n)}catch{let s=new A(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#r?.emit(v.errors,s)}let i=fr(r,e);this.state.history$.next(i)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,mr.default)(e,-1)||this.#i.initChapterId||this.#t?.metadata.initChapterId}getInitialVideoId(){if(this.#t){let e=this.getInitialChapterId();return ot([e],this.#t).pop()}return null}destroy(){this.#n=null,this.#e=null,this.#s=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#r?.emit(v.historyDestroyed),this.events.destroyed$.next(),this.#r=null}};var lt=class t{constructor(e,r,i,n){this.target=e,this.type=r,this.listener=i,this.options=t._convertOptions(e,n),this.target.addEventListener(r,i,this.options)}unlisten(){this.type&&this.listener&&this.options&&this.target?.removeEventListener(this.type,this.listener,this.options),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(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(l=>!i.has(l));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),t._doesSupportObject(e)?r:r.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(e){let r=t._supportsObject;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._supportsObject=r}return r||!1}};var ct=class{constructor(){this.bindingMap=new we}release(){this.removeAll(),this.bindingMap=null}listen(e,r,i,n){if(!this.bindingMap)return;let s=new lt(e,r,i,n);this.bindingMap.push(r,s)}listenOnce(e,r,i,n){let s=l=>{this.unlisten(e,r,s),i(l)};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 pt=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 ht=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 Rs=Object.create;var Ae=Object.defineProperty;var ks=Object.getOwnPropertyDescriptor;var Ps=Object.getOwnPropertyNames;var Vs=Object.getPrototypeOf,Os=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),js=(t,e)=>{for(var r in e)Ae(t,r,{get:e[r],enumerable:!0})},br=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ps(e))!Os.call(t,n)&&n!==r&&Ae(t,n,{get:()=>e[n],enumerable:!(i=ks(e,n))||i.enumerable});return t};var dt=(t,e,r)=>(r=t!=null?Rs(Vs(t)):{},br(e||!t||!t.__esModule?Ae(r,"default",{value:t,enumerable:!0}):r,t)),Ns=t=>br(Ae({},"__esModule",{value:!0}),t);var F=u((Et,wr)=>{"use strict";var pe=function(t){return t&&t.Math===Math&&t};wr.exports=pe(typeof globalThis=="object"&&globalThis)||pe(typeof window=="object"&&window)||pe(typeof self=="object"&&self)||pe(typeof global=="object"&&global)||pe(typeof Et=="object"&&Et)||function(){return this}()||Function("return this")()});var H=u((uc,Mr)=>{"use strict";Mr.exports=function(t){try{return!!t()}catch{return!0}}});var he=u((dc,Lr)=>{"use strict";var $s=H();Lr.exports=!$s(function(){var t=function(){}.bind();return typeof t!="function"||t.hasOwnProperty("prototype")})});var Pr=u((fc,kr)=>{"use strict";var Bs=he(),Rr=Function.prototype,_r=Rr.apply,Ar=Rr.call;kr.exports=typeof Reflect=="object"&&Reflect.apply||(Bs?Ar.bind(_r):function(){return Ar.apply(_r,arguments)})});var W=u((mc,jr)=>{"use strict";var Vr=he(),Or=Function.prototype,It=Or.call,qs=Vr&&Or.bind.bind(It,It);jr.exports=Vr?qs:function(t){return function(){return It.apply(t,arguments)}}});var xt=u((yc,Fr)=>{"use strict";var Nr=W(),Ds=Nr({}.toString),Hs=Nr("".slice);Fr.exports=function(t){return Hs(Ds(t),8,-1)}});var Tt=u((vc,$r)=>{"use strict";var Us=xt(),Gs=W();$r.exports=function(t){if(Us(t)==="Function")return Gs(t)}});var U=u((gc,Br)=>{"use strict";var St=typeof document=="object"&&document.all;Br.exports=typeof St>"u"&&St!==void 0?function(t){return typeof t=="function"||t===St}:function(t){return typeof t=="function"}});var ie=u((bc,qr)=>{"use strict";var zs=H();qr.exports=!zs(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})});var De=u((Cc,Dr)=>{"use strict";var Ws=he(),qe=Function.prototype.call;Dr.exports=Ws?qe.bind(qe):function(){return qe.apply(qe,arguments)}});var zr=u(Gr=>{"use strict";var Hr={}.propertyIsEnumerable,Ur=Object.getOwnPropertyDescriptor,Qs=Ur&&!Hr.call({1:2},1);Gr.f=Qs?function(e){var r=Ur(this,e);return!!r&&r.enumerable}:Hr});var wt=u((Ic,Wr)=>{"use strict";Wr.exports=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}});var Kr=u((xc,Qr)=>{"use strict";var Ks=W(),Ys=H(),Zs=xt(),Mt=Object,Xs=Ks("".split);Qr.exports=Ys(function(){return!Mt("z").propertyIsEnumerable(0)})?function(t){return Zs(t)==="String"?Xs(t,""):Mt(t)}:Mt});var Lt=u((Tc,Yr)=>{"use strict";Yr.exports=function(t){return t==null}});var _t=u((Sc,Zr)=>{"use strict";var Js=Lt(),ea=TypeError;Zr.exports=function(t){if(Js(t))throw new ea("Can't call method on "+t);return t}});var Jr=u((wc,Xr)=>{"use strict";var ta=Kr(),ra=_t();Xr.exports=function(t){return ta(ra(t))}});var ue=u((Mc,ei)=>{"use strict";var ia=U();ei.exports=function(t){return typeof t=="object"?t!==null:ia(t)}});var At=u((Lc,ti)=>{"use strict";ti.exports={}});var Pt=u((_c,ii)=>{"use strict";var Rt=At(),kt=F(),na=U(),ri=function(t){return na(t)?t:void 0};ii.exports=function(t,e){return arguments.length<2?ri(Rt[t])||ri(kt[t]):Rt[t]&&Rt[t][e]||kt[t]&&kt[t][e]}});var si=u((Ac,ni)=>{"use strict";var sa=W();ni.exports=sa({}.isPrototypeOf)});var ci=u((Rc,li)=>{"use strict";var aa=F(),ai=aa.navigator,oi=ai&&ai.userAgent;li.exports=oi?String(oi):""});var yi=u((kc,mi)=>{"use strict";var fi=F(),Vt=ci(),pi=fi.process,hi=fi.Deno,ui=pi&&pi.versions||hi&&hi.version,di=ui&&ui.v8,j,He;di&&(j=di.split("."),He=j[0]>0&&j[0]<4?1:+(j[0]+j[1]));!He&&Vt&&(j=Vt.match(/Edge\/(\d+)/),(!j||j[1]>=74)&&(j=Vt.match(/Chrome\/(\d+)/),j&&(He=+j[1])));mi.exports=He});var Ot=u((Pc,gi)=>{"use strict";var vi=yi(),oa=H(),la=F(),ca=la.String;gi.exports=!!Object.getOwnPropertySymbols&&!oa(function(){var t=Symbol("symbol detection");return!ca(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&vi&&vi<41})});var jt=u((Vc,bi)=>{"use strict";var pa=Ot();bi.exports=pa&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Nt=u((Oc,Ci)=>{"use strict";var ha=Pt(),ua=U(),da=si(),fa=jt(),ma=Object;Ci.exports=fa?function(t){return typeof t=="symbol"}:function(t){var e=ha("Symbol");return ua(e)&&da(e.prototype,ma(t))}});var Ii=u((jc,Ei)=>{"use strict";var ya=String;Ei.exports=function(t){try{return ya(t)}catch{return"Object"}}});var Ft=u((Nc,xi)=>{"use strict";var va=U(),ga=Ii(),ba=TypeError;xi.exports=function(t){if(va(t))return t;throw new ba(ga(t)+" is not a function")}});var Si=u((Fc,Ti)=>{"use strict";var Ca=Ft(),Ea=Lt();Ti.exports=function(t,e){var r=t[e];return Ea(r)?void 0:Ca(r)}});var Mi=u(($c,wi)=>{"use strict";var $t=De(),Bt=U(),qt=ue(),Ia=TypeError;wi.exports=function(t,e){var r,i;if(e==="string"&&Bt(r=t.toString)&&!qt(i=$t(r,t))||Bt(r=t.valueOf)&&!qt(i=$t(r,t))||e!=="string"&&Bt(r=t.toString)&&!qt(i=$t(r,t)))return i;throw new Ia("Can't convert object to primitive value")}});var _i=u((Bc,Li)=>{"use strict";Li.exports=!0});var ki=u((qc,Ri)=>{"use strict";var Ai=F(),xa=Object.defineProperty;Ri.exports=function(t,e){try{xa(Ai,t,{value:e,configurable:!0,writable:!0})}catch{Ai[t]=e}return e}});var Dt=u((Dc,Oi)=>{"use strict";var Ta=_i(),Sa=F(),wa=ki(),Pi="__core-js_shared__",Vi=Oi.exports=Sa[Pi]||wa(Pi,{});(Vi.versions||(Vi.versions=[])).push({version:"3.38.0",mode:Ta?"pure":"global",copyright:"\xA9 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var Fi=u((Hc,Ni)=>{"use strict";var ji=Dt();Ni.exports=function(t,e){return ji[t]||(ji[t]=e||{})}});var Ht=u((Uc,$i)=>{"use strict";var Ma=_t(),La=Object;$i.exports=function(t){return La(Ma(t))}});var Ue=u((Gc,Bi)=>{"use strict";var _a=W(),Aa=Ht(),Ra=_a({}.hasOwnProperty);Bi.exports=Object.hasOwn||function(e,r){return Ra(Aa(e),r)}});var Di=u((zc,qi)=>{"use strict";var ka=W(),Pa=0,Va=Math.random(),Oa=ka(1 .toString);qi.exports=function(t){return"Symbol("+(t===void 0?"":t)+")_"+Oa(++Pa+Va,36)}});var Gi=u((Wc,Ui)=>{"use strict";var ja=F(),Na=Fi(),Hi=Ue(),Fa=Di(),$a=Ot(),Ba=jt(),ne=ja.Symbol,Ut=Na("wks"),qa=Ba?ne.for||ne:ne&&ne.withoutSetter||Fa;Ui.exports=function(t){return Hi(Ut,t)||(Ut[t]=$a&&Hi(ne,t)?ne[t]:qa("Symbol."+t)),Ut[t]}});var Ki=u((Qc,Qi)=>{"use strict";var Da=De(),zi=ue(),Wi=Nt(),Ha=Si(),Ua=Mi(),Ga=Gi(),za=TypeError,Wa=Ga("toPrimitive");Qi.exports=function(t,e){if(!zi(t)||Wi(t))return t;var r=Ha(t,Wa),i;if(r){if(e===void 0&&(e="default"),i=Da(r,t,e),!zi(i)||Wi(i))return i;throw new za("Can't convert object to primitive value")}return e===void 0&&(e="number"),Ua(t,e)}});var Gt=u((Kc,Yi)=>{"use strict";var Qa=Ki(),Ka=Nt();Yi.exports=function(t){var e=Qa(t,"string");return Ka(e)?e:e+""}});var Ji=u((Yc,Xi)=>{"use strict";var Ya=F(),Zi=ue(),zt=Ya.document,Za=Zi(zt)&&Zi(zt.createElement);Xi.exports=function(t){return Za?zt.createElement(t):{}}});var Wt=u((Zc,en)=>{"use strict";var Xa=ie(),Ja=H(),eo=Ji();en.exports=!Xa&&!Ja(function(){return Object.defineProperty(eo("div"),"a",{get:function(){return 7}}).a!==7})});var nn=u(rn=>{"use strict";var to=ie(),ro=De(),io=zr(),no=wt(),so=Jr(),ao=Gt(),oo=Ue(),lo=Wt(),tn=Object.getOwnPropertyDescriptor;rn.f=to?tn:function(e,r){if(e=so(e),r=ao(r),lo)try{return tn(e,r)}catch{}if(oo(e,r))return no(!ro(io.f,e,r),e[r])}});var an=u((Jc,sn)=>{"use strict";var co=H(),po=U(),ho=/#|\.prototype\./,de=function(t,e){var r=fo[uo(t)];return r===yo?!0:r===mo?!1:po(e)?co(e):!!e},uo=de.normalize=function(t){return String(t).replace(ho,".").toLowerCase()},fo=de.data={},mo=de.NATIVE="N",yo=de.POLYFILL="P";sn.exports=de});var cn=u((ep,ln)=>{"use strict";var on=Tt(),vo=Ft(),go=he(),bo=on(on.bind);ln.exports=function(t,e){return vo(t),e===void 0?t:go?bo(t,e):function(){return t.apply(e,arguments)}}});var hn=u((tp,pn)=>{"use strict";var Co=ie(),Eo=H();pn.exports=Co&&Eo(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})});var dn=u((rp,un)=>{"use strict";var Io=ue(),xo=String,To=TypeError;un.exports=function(t){if(Io(t))return t;throw new To(xo(t)+" is not an object")}});var yn=u(mn=>{"use strict";var So=ie(),wo=Wt(),Mo=hn(),Ge=dn(),fn=Gt(),Lo=TypeError,Qt=Object.defineProperty,_o=Object.getOwnPropertyDescriptor,Kt="enumerable",Yt="configurable",Zt="writable";mn.f=So?Mo?function(e,r,i){if(Ge(e),r=fn(r),Ge(i),typeof e=="function"&&r==="prototype"&&"value"in i&&Zt in i&&!i[Zt]){var n=_o(e,r);n&&n[Zt]&&(e[r]=i.value,i={configurable:Yt in i?i[Yt]:n[Yt],enumerable:Kt in i?i[Kt]:n[Kt],writable:!1})}return Qt(e,r,i)}:Qt:function(e,r,i){if(Ge(e),r=fn(r),Ge(i),wo)try{return Qt(e,r,i)}catch{}if("get"in i||"set"in i)throw new Lo("Accessors not supported");return"value"in i&&(e[r]=i.value),e}});var gn=u((np,vn)=>{"use strict";var Ao=ie(),Ro=yn(),ko=wt();vn.exports=Ao?function(t,e,r){return Ro.f(t,e,ko(1,r))}:function(t,e,r){return t[e]=r,t}});var En=u((sp,Cn)=>{"use strict";var fe=F(),Po=Pr(),Vo=Tt(),Oo=U(),jo=nn().f,No=an(),se=At(),Fo=cn(),ae=gn(),bn=Ue();Dt();var $o=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 Po(t,this,arguments)};return e.prototype=t.prototype,e};Cn.exports=function(t,e){var r=t.target,i=t.global,n=t.stat,s=t.proto,l=i?fe:n?fe[r]:fe[r]&&fe[r].prototype,a=i?se:se[r]||ae(se,r,{})[r],o=a.prototype,c,d,f,y,b,w,$,I,h;for(y in e)c=No(i?y:r+(n?".":"#")+y,t.forced),d=!c&&l&&bn(l,y),w=a[y],d&&(t.dontCallGetSet?(h=jo(l,y),$=h&&h.value):$=l[y]),b=d&&$?$:e[y],!(!c&&!s&&typeof w==typeof b)&&(t.bind&&d?I=Fo(b,fe):t.wrap&&d?I=$o(b):s&&Oo(b)?I=Vo(b):I=b,(t.sham||b&&b.sham||w&&w.sham)&&ae(I,"sham",!0),ae(a,y,I),s&&(f=r+"Prototype",bn(se,f)||ae(se,f,{}),ae(se[f],y,b),t.real&&o&&(c||!o[y])&&ae(o,y,b)))}});var xn=u((ap,In)=>{"use strict";var Bo=Math.ceil,qo=Math.floor;In.exports=Math.trunc||function(e){var r=+e;return(r>0?qo:Bo)(r)}});var Xt=u((op,Tn)=>{"use strict";var Do=xn();Tn.exports=function(t){var e=+t;return e!==e||e===0?0:Do(e)}});var wn=u((lp,Sn)=>{"use strict";var Ho=Xt(),Uo=Math.min;Sn.exports=function(t){var e=Ho(t);return e>0?Uo(e,9007199254740991):0}});var Ln=u((cp,Mn)=>{"use strict";var Go=wn();Mn.exports=function(t){return Go(t.length)}});var An=u((pp,_n)=>{"use strict";_n.exports=function(){}});var Rn=u(()=>{"use strict";var zo=En(),Wo=Ht(),Qo=Ln(),Ko=Xt(),Yo=An();zo({target:"Array",proto:!0},{at:function(e){var r=Wo(this),i=Qo(r),n=Ko(e),s=n>=0?n:i+n;return s<0||s>=i?void 0:r[s]}});Yo("at")});var Pn=u((dp,kn)=>{"use strict";var Zo=Pt();kn.exports=Zo});var On=u((fp,Vn)=>{"use strict";Rn();var Xo=Pn();Vn.exports=Xo("Array","at")});var Nn=u((mp,jn)=>{"use strict";var Jo=On();jn.exports=Jo});var Jt=u((yp,Fn)=>{"use strict";var el=Nn();Fn.exports=el});var Sl={};js(Sl,{CustomError:()=>A,EVENT_NAMES:()=>v,Interactives:()=>Le,ManifestController:()=>Z,SDKInfo:()=>Tl,chapterIdsToVKVideoIds:()=>ot,compareVersions:()=>q,getChapterIdByVkVideoId:()=>Ss,getVKVideoIdByMedia:()=>dr,getVideoRawIdByMedia:()=>xs,graphEventTypes:()=>le,hasEndTemplate:()=>Te,interactivesEventTypes:()=>T,isLastChapter:()=>N,isSupportedManifest:()=>Ce,isVKVariantItem:()=>Ts,utils:()=>_s,vkVideoIdsToChapterIds:()=>fr});module.exports=Ns(Sl);var Cr="1.0.23-dev.8a9f6a57.0";function ft(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 P="interactive",Fs="interactive-controls-container",Re=()=>document.querySelector(`.${Fs}`),Er=.4,R={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Ir=(i=>(i.top="flex-start",i.bottom="flex-end",i.center="center",i))(Ir||{}),xr=(i=>(i.start="flex-start",i.end="flex-end",i.center="center",i))(xr||{}),Tr=(i=>(i.start="left",i.end="right",i.center="center",i))(Tr||{}),ke=({target:t,props:e})=>{t.style.alignItems=(e.text?.gravityVertical&&Ir[e.text.gravityVertical])??"center",t.style.justifyContent=(e.text?.gravityHorizontal&&xr[e.text.gravityHorizontal])??"center",t.style.textAlign=(e.text?.alignment&&Tr[e.text.alignment])??"left"},Pe=({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},Ve=({target:t,props:e,fallback:r})=>{t.style.backgroundColor=ft(e?.background?.color??r.backgroundColor,e?.background?.alpha??r.backgroundAlpha)},Oe=({target:t,props:e,fallback:r,dependsOn:i})=>{t.style.border=`calc(${i.height} * ${e?.shape?.border?.width??r.borderWidth}) solid ${ft(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})=>{let i=e.angle??r.angle;i=i&&i*-1,t.style.transform=`rotate(${i}rad)`};var B=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let r=document.createElement("div");r.classList.add(`${P}-control-container-${this.control.id}`),e(r,this.control.layoutParams);let i=(this.control.layoutParams.innerSizesDependOn??R.innerSizesDependOn)==="self"?{height:r.style.height,width:r.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:r,dimensions:i}}createClickListener(e){return r=>{r.stopPropagation(),e()}}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(r=>{switch(r.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:r.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var mt="int",z=(i=>(i.AREA=`${mt}_area`,i.TEXT=`${mt}_text`,i.BUTTON=`${mt}_bttn`,i))(z||{});var je=t=>{if(t.type.trim().toLowerCase()==="area")return new yt(t)},yt=class extends B{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(`${P}-${this.control.id}`),i.setAttribute("data-testid",z.AREA),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.cursor="pointer",Ve({target:i,props:this.control.props,fallback:{...R,backgroundColor:"transparent"}}),Oe({target:i,props:this.control.props,fallback:{...R,borderAlpha:0},dependsOn:this.container.dimensions}),te({target:i,layoutParams:this.control.layoutParams,fallback:R}),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Ne=()=>{let t=document.createElement("span");return t.style.display="inline-block",t.style.whiteSpace="pre",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.maxWidth="100%",t.style.maxHeight="100%",t};var Fe=t=>{if(t.type.trim().toLowerCase()==="button")return new vt(t)},vt=class extends B{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let i=document.createElement("button");i.type="button",i.classList.add(`${P}-${this.control.id}`),i.setAttribute("data-testid",z.BUTTON),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.cursor="pointer",i.style.fontFamily="inherit",te({target:i,layoutParams:this.control.layoutParams,fallback:R}),Ve({target:i,props:this.control.props,fallback:R}),Oe({target:i,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),ke({target:i,props:this.control.props});let n=Ne();Pe({target:n,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var Sr=t=>{if(t.type.trim().toLowerCase()==="text")return new gt(t)},gt=class extends B{constructor(e){super(e)}createView({parentElement:e,layoutCallback:r}){if(super.createContainerElement(r),!this.container)return;let i=document.createElement("div");i.classList.add(`${P}-${this.control.id}`),i.setAttribute("data-testid",z.TEXT),i.style.display="flex",i.style.width="100%",i.style.height="100%",i.style.fontFamily="inherit",te({target:i,layoutParams:this.control.layoutParams,fallback:R}),ke({target:i,props:this.control.props});let n=Ne();Pe({target:n,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),i.append(n),this.container.element.append(i),e.append(this.container.element),this.controlElement=i}disable(){}enable(){}getElement(){return this.controlElement}};var bt=class{constructor(e){this.layout=e}},$e=class extends bt{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 re=class{constructor(e){this.container=e,this.factories=new Map,this.#e()}addControlFactory(e,r){this.factories.set(e.trim().toLowerCase(),r),this.#e()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.#e()}#e(){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 Be=(t,e)=>{if(t.type.trim().toLowerCase()==="choice")return new Ct(t,e)},Ct=class extends re{constructor(e,r){super(e),this.rootElement=r??Re(),this.layout=new $e(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Fe),this.addControlFactory("text",Sr),this.addControlFactory("area",je)}createView(e){let r=document.createElement("div");return r.classList.add(`${P}-${this.container.id}`),this.layout.setContainerLayout(r),this.controls.forEach(i=>{i.createView({parentElement:r,layoutCallback:this.layout.setControlLayout}),i.setEvents(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=Er,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${P}-${this.container.id}`)}};var Ls=dt(Jt(),1),E=require("@vkontakte/videoplayer-shared"),ce=require("@vkontakte/videoplayer-statistics");var Hn=require("@vkontakte/videoplayer-shared");function me(t,e){let r;return(...i)=>{clearTimeout(r),r=setTimeout(()=>t(...i),e)}}var Q=(t,e)=>Object.prototype.toString.call(t)===`[object ${e}]`,ye=t=>Q(t,"Object"),ze=t=>Q(t,"String"),We=t=>Q(t,"Array"),Qe=t=>Q(t,"Number"),$n=t=>Q(t,"Function");var er=t=>Qe(t)&&!isNaN(t);var K=t=>ye(t)&&Object.keys(t).length===0,tr=t=>We(t)&&!t.length;var ve=(t,e)=>ze(t)&&(e?t.trim():t).length;var Bn="video_interactive",qn="videoint";var Dn=250,ge=class{constructor(e){this.handleZoomChange=me(e=>{this.lastZoomInfo=e},Dn);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let r=this.getNextPoint();r&&this.ngEditor?.zoomTo(r),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){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=null}};this.handleManifestChange=(e,r=[])=>{if(this.isReady=!1,!Qe(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph"),console.error("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(r),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(r)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:r,onError:i,lang:n,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=r,this.onError=i,this.lang=n??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=tl(e),this.resizeObserver=new ResizeObserver(me(this.onResize,Dn)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await(0,Hn.loadVKLangPack)(this.lang,Bn,qn)}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==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.ngEditor.on("control",({name:i,...n})=>{i==="openPreview"&&"chapterId"in n&&this.onOpenPreviewClick?.(n.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function tl(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 be=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(r=>r.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let r=-1,i=!1,n=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let l=s.startTime-e;if(l<=n&&(s.endTime&&n<=s.endTime||s.endTime===null)){i=!0;break}n<l&&(r=r===-1?l:Math.min(r,l))}return!i&&r!==-1?r:null}}};var q=(t="",e="")=>{let r=t.split("."),i=e.split("."),n=0;for(let s=0;s<Math.max(r.length,i.length)&&!n;s++)r[s]>i[s]?n=1:r[s]<i[s]?n=-1:n=0;return n};var Gn=require("uuid"),rl="3.1",Un={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},il={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},zn=t=>{let e=[];for(let r of t.chapters){let i,n=[];for(let{isDefault:a,...o}of r.branches)a&&(i=o.id),n.push(o);let s=[],l=[];for(let{fallbackStrategy:a,...o}of r.containers){let c=!!o.endTime,d=[il];switch(a){case"await":c?d=[]:s=[];break;case"default":{let f={type:"onSuspense",action:{type:Un.default,args:{branchId:i,shouldOpenNow:!c,isDetachContainer:!0}}};c?d=[f]:s=[f];break}case"random":case"weightlessRandom":case"max":case"min":{let f={type:"onSuspense",action:{type:Un[a],args:{}}};c?d=[f]:s=[f];break}}for(let f of o.controls)l.push({...o,controls:[{...f}],id:(0,Gn.v4)(),events:d})}e.push({...r,containers:l,events:s,branches:n})}return t.metadata.version=rl,t.metadata.updated=new Date().toISOString(),{...t,chapters:e}};var nl="3.2",Wn=t=>{if(!t.media){let{media:e,...r}=t.metadata;return{...t,metadata:{...r,version:nl},media:e}}return t};var sl="3.3",al=(t=[])=>({edit:{chapters:t},view:{}}),Qn={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Kn=t=>{let e=[],r=[];for(let i of t.chapters){let{id:n,x:s,y:l,...a}=i,o=a.containers.map(c=>({...c,controls:c.controls.map(({subtype:d,type:f,...y})=>({...y,type:d??f})),events:c.events?.length?c.events:[Qn]}));e.push({id:n,...a,containers:o,events:a.events?.length?a.events:[Qn]}),r.push({id:n,x:s,y:l})}return{...t,chapters:e,graph:al(r),metadata:{...t.metadata,version:sl}}};var ol=[{version:"3.0",migrate:zn},{version:"3.1",migrate:Wn},{version:"3.2",migrate:Kn}],rr=t=>ol.reduce((e,r)=>q(e.metadata.version,r.version)?e:r.migrate(e),t);var Yn={Button:"Button",Area:"Area",Text:"Text"};var S={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var Zn={metadata:"Object",chapters:"Array"},ll="3.0.0",cl="3.3.0",Ce=t=>{let e=q(t,ll);return e===-1?!1:e===0?!0:q(t,cl)!==1},Xn=t=>{if(!ye(t))return!1;for(let e in Zn)if(!t[e]||!Q(t[e],Zn[e]))return!1;return Ce(t.metadata.version)},Ke=t=>t.type===Yn.Text;var A=class{constructor(e,r,...i){this.severity=e;this.category=r;this.data=i}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Ye=class{constructor(){this.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]||[];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.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Ze=class{constructor(e){this.fns=[];this.addFn=(e,r=!1)=>{$n(e)&&(this.fns.push(e),r&&this.updateFn())};this.removeFn=(e,r=!1)=>{this.fns=this.fns.filter(i=>i!==e),r&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};var ns=require("@vkontakte/videoplayer-shared");var Xe=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,r){return pl(...this.loaders[e])(r)}};function pl(...t){return async function(r){let i=[...t];for(;i.length>0;)r=await i.shift()(r);return r}}function Ee(t,e,r){return t?{...t,[e]:t[e]?[r,...t[e]]:[r]}:{[e]:[r]}}function Je({actions:t,errors:e,chapterId:r,...i}){if(r){let n=t.getManifest(),s=t.getChapter(n.chapters,r);if(s){let l=t.getMedia(n.media,s.videoId),a=t.getGraph(n.graph,s.id);return l?{...i,actions:t,errors:e,result:{chapter:s,media:l,graph:a}}:{...i,errors:Ee(e,Je.name,"Could not find media"),actions:t}}}return{...i,errors:Ee(e,Je.name,"Could not find chapter"),actions:t}}var et=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:i})}removeEventListener(e,r){if(!(e in this.listeners))return;let i=this.listeners[e];for(let n=0,s=i.length;n<s;n++)if(i[n].callback===r){i.splice(n,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let n=0,s=i.length;n<s;n++){let l=i[n];try{l.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}l.options&&l.options.once&&this.removeEventListener(e.type,l.callback)}return!e.defaultPrevented}},oe=class extends et{constructor(){super(),this.listeners||et.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},Ie=class{constructor(){Object.defineProperty(this,"signal",{value:new oe,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch{typeof document<"u"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document>"u")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch{i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&(Ie.prototype[Symbol.toStringTag]="AbortController",oe.prototype[Symbol.toStringTag]="AbortSignal");function tt(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function ir(t){typeof t=="function"&&(t={fetch:t});let{fetch:e,Request:r=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=t;if(!tt({fetch:e,Request:r,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:s};let s=r;(s&&!s.prototype.hasOwnProperty("signal")||n)&&(s=function(c,d){let f;d&&d.signal&&(f=d.signal,delete d.signal);let y=new r(c,d);return f&&Object.defineProperty(y,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),y},s.prototype=r.prototype);let l=e;return{fetch:(o,c)=>{let d=s&&s.prototype.isPrototypeOf(o)?o.signal:c?c.signal:void 0;if(d){let f;try{f=new DOMException("Aborted","AbortError")}catch{f=new Error("Aborted"),f.name="AbortError"}if(d.aborted)return Promise.reject(f);let y=new Promise((b,w)=>{d.addEventListener("abort",()=>w(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([y,l(o,c)])}return l(o,c)},Request:s}}var xe=tt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Jn=xe?ir({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,nr=xe?Jn.fetch:window.fetch,hh=xe?Jn.Request:window.Request,uh=xe?Ie:window.AbortController,dh=xe?oe:window.AbortSignal;var hl=async t=>{try{let e={},r;if(ze(t)){r=new URL(t).href;let n=await nr(r);if(!n.ok)return{};e=await n.json()}else if(ye(t))e=t;else return{};if(!Xn(e))return{};let i=e.metadata.media;if(ze(i)&&!e.media)try{let n;r?n=new URL(i,r).href:(n=new URL(i).href,r=n);let s=await nr(n);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return fl(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:r}}catch{return{}}};async function es(t){let{manifest:e,manifestURL:r}=await hl(t),i=rr(e);return i.media=ul(i.media,r),delete i.metadata.media,i}function rt(t,e){if(e)return t.find(r=>r.id===e)}function sr(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 ar(t,e){return t.videos.find(r=>r.id===e)}function ul(t,e){return{...t,videos:t.videos.map(r=>({...r,variants:r.variants.map(i=>{let n="url"in i?i.url:"",s=dl(n,e);return{...i,url:s||n}})}))}}function dl(t="",e){try{return new URL(t,e).href}catch{return""}}function fl(t){return q(t,"3.2.0")>=0}var it=t=>We(t)&&!tr(t),N=t=>t.order==="end",Te=t=>We(t.containers)&&!tr(t.containers)&&N(t),ts=(t,e)=>{let r=t*1e3;return it(e.controls)&&r<(e.startTime??0)},or=(t,e)=>{let r=t*1e3;return it(e.controls)&&r>=(e.startTime??0)&&r<=(e.endTime??1/0)};var Y=(t=[])=>t.some(e=>e.action.type==="expect"),lr=(t=[])=>t.find(e=>e.action.type==="expect"),ml=t=>t?.length===1,nt=t=>ml(t)&&Ke(t[0]);function rs(t,...e){return r=>typeof e[0]=="object"&&typeof r=="object"?t({...e[0],...r}):t(...e,...r)}var is=(t,e)=>Y(t.events)?!1:e.some(({container:r})=>r.container.id!==t.id&&Y(r.container.events)&&r.container.endTime===t.endTime&&!r.isRemoved);var Z=class extends Xe{constructor(r,i){super(r);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new ns.ValueSubject(null);this.onError=i,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(r){this.release();let i=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ee},result:null,errors:null,source:r});return i.errors&&this.errorHandler(i.errors),this.manifest=await es(i.result??r),this}async setInitial(){return this.setNext()}async setNext(r=this.manifest?.metadata.initChapterId){if(!r)return this;this.prevChapter$.next(this.chapter);let i=await this.exec("chapterLoaders",Je({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:sr,getChapter:rt,getMedia:ar,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ee},result:null,errors:null,chapterId:r}));return i.errors&&this.errorHandler(i.errors),this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph,this}errorHandler(r){this.onError(r),console.error("Something went wrong with loaders",{errors:r})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(r=this.manifest?.metadata.initChapterId){if(!r||!this.manifest)return null;let i=rt(this.manifest.chapters,r);if(i){let n=ar(this.manifest.media,i.videoId),s=sr(this.manifest.graph,i.id);if(n)return{chapter:i,media:n,graph:s}}return null}getBranches(r=this.chapter?.id){if(r===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let i=rt(this.manifest?.chapters||[],r);return this.getByBranches(i?.branches)}}getByBranches(r=[]){return r.reduce((i,n)=>{let s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?N(this.chapter):!1}};var as=require("@vkontakte/videoplayer-core"),G=require("@vkontakte/videoplayer-shared");var ss=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[]};function cr(){let t=new Map;function e({listId:s=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let o=t.get(s),c={...a};return o?o[l]=c:t.set(s,{[l]:c}),{listId:s,itemId:l,...a}}function r(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function i(s,l){let a=t.get(s);if(!a)throw Error("Can't remove. Not find.");if(l){let o=a[l];o&&r(o),delete a[l],Object.keys(a).length||t.delete(s)}else{for(let o of Object.values(a))r(o);t.delete(s)}}function n(){for(let s of t)i(s[0])}return{createPlayer:e,removePlayer:i,map:t,removeAll:n}}function pr(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 Se=(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 yl=2;function hr(t){let e=cr(),r=new G.Subscription,i={},n=null,s=!1,l,a=new G.ValueSubject(null);t&&o(t);function o(I){n=I}function c(I,h,p){if(!n)throw Error("need to set interactive controller");if(!n.options)return;let C=(e.map.get(I)??{})[h];if(C){i={chapterId:p,listId:I,itemId:h,...C};let g=i.player;i.subscription.add(g.info.currentQuality$.subscribe(L=>{let M=g.info.position$.getValue(),k=g.info.isAutoQualityEnabled$.getValue();if(!(!L||!M||k))for(let x of e.map)Object.values(x[1]).forEach(({player:_})=>{Se(_,L)})})).add(g.events.started$.subscribe(()=>{d(h)})),C.container.remove(),n.setPlayer(C.player),s||(n.init(),s=!0),a.next({player:i.player,config:i.config,statistics:i.statistics});return}throw Error("Can't set. Not find.")}async function d(I){if(!n)throw Error("need to set interactive controller");if(K(i)||I!==i.itemId)return;let h=n.getChapterBranches(),p=new Set;for(let m of h)p.has(m.media.id)||(await y({media:m.media,chapterId:m.chapter.id,setAsActive:!1,title:m.chapter.label}),p.add(m.media.id))}async function f({chapter:{id:I},manifestVideo:h}){if(K(i)||!n)return;let p=i.player.info.muted$.getValue(),m=i.player.info.currentQuality$.getValue(),C=i.player.info.isAutoQualityEnabled$.getValue(),g=i.player.info.volume$.getValue(),L=i.player.info.currentPlaybackRate$.getValue(),M=!C,k=!1;for(let x of e.map)if(x[0]===h.id&&!n.state.isReplay$.getValue()){let _=Object.keys(x[1]);for(let V of _)V===i.itemId?(_.length<yl||(k=!0),e.removePlayer(x[0],V)):(k=!0,c(x[0],V,I),M?Se(i.player,m):i.player.setAutoQuality(!0),i.player.setVolume(g),i.player.setMuted(p),i.player.setPlaybackRate(L))}else e.removePlayer(x[0]);k||(await y({media:h,chapterId:I,setAsActive:!0,playbackRate:L}),M?Se(i.player,m):i.player.setAutoQuality(!0),i.player.setVolume(g),i.player.setMuted(p))}async function y({media:I,chapterId:h,prefetch:p=!0,setAsActive:m=!0,autoplay:C=!1,preferredExt:g,title:L,playbackRate:M}){let k=Math.random().toString(),x=document.createElement("div");l.append(x);let _;if(n?.options?.vkVideoLoader){let _e=ss(I);_e.length&&(_=await n.options.vkVideoLoader(..._e))}let V=n?.options?.coreConfig||void 0,X={...V,configName:[...V?.configName??[],"interactive"]},J={container:x,..._?.videos?.[0]||{sources:pr(I,g).sources},title:L,failoverHosts:_?.failoverHosts||[]},D=new as.Player(X,G.Tracer.createRootTracer());D.initVideo(J);let yr=null;if(_?.videos&&n?.options.createOneStat){let _e=_.videos[0],ut=n.options.createOneStat(_e),gr=new G.Subscription;ut&&(gr.add(ut.attachTo(D)),yr={oneStat:ut,statSubscription:gr})}let vr=new G.Subscription,As=i?.player?.info.isAutoQualityEnabled$.getValue();vr.add(D.events.canplay$.subscribe(function(){As||Se(D,i.player.info.currentQuality$.getValue()),M&&D.setPlaybackRate(M)}));let ee=e.createPlayer({listId:I.id,itemId:k,player:D,container:x,sources:pr(I,g).sources,config:J,subscription:vr,statistics:yr});return m&&c(I.id,ee.itemId,h),C&&ee.player.play(),p&&!C&&ee.player.prepare(),{player:ee.player,config:ee.config,statistics:ee.statistics}}function b(){w(),n=null,l.remove()}function w(){r.unsubscribe(),e.removeAll(),i={},s=!1}async function $(){if(!n)throw Error("need to set interactive controller");w(),l=document.createElement("div");let{media:I,chapter:h}=n.getCurrentChapter();I&&h?(r.add(n.events.chapterChanged$.subscribe(f)),await y({media:I,chapterId:h.id,title:h.label})):console.error("not found")}return{...e,init:$,setInteractiveController:o,createPlayer:y,removeAll:b,getActivePlayer:function(){return i},activePlayerChanged:a}}var v={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},le={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},T={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};var os=require("@vkontakte/videoplayer-shared");var st=class{constructor({player:e,container:r,branches:i,selectBranches:n,interactiveEvents:s,globalEvents:l,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d,onRemove:f}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(Y(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})))})};this.show=()=>{if(this.gameState===2&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!0,isFirst:!1});else{let r=rs(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})},onEvent:(i,n)=>{this.isSelectedControlEvent=!0,i!==!1&&(this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),n(),this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(r),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),i=e instanceof HTMLVideoElement?e.readyState:void 0,n=[6,5];if(!i||n.includes(this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(ts(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(or(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let c=this.gameState;this.gameState=3,c===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=or(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(v.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=r,this.branches=i,this.selectBranches=n,this.subscription=new os.Subscription,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&nt(r.container.controls),this.disabledControls$=d,this.onRemove=f,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,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?.()}))}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??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=Y(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:T.containerRemoved,visibility:!1}),this.gameState=5,this.onRemove?.()}destroy(){this.reset(),this.removeView(),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var ls=(t=[])=>t.reduce((e,r,i)=>{let n=(r?.controls??[]).filter(s=>!Ke(s));if(it(n)){let s=[r.startTime??0,r.endTime??1/0],l=r.id;if(!i)e.push({subjects:[l],range:s});else{let a=[],o=-1/0,c=1/0,d=[],f=[];for(let y=0;y<e.length;y++){let b=e[y];if(f.push(...b.subjects),b.range[0]<c&&(c=b.range[0]),b.range[1]>o&&(o=b.range[1]),s[0]>=b.range[0]&&s[1]<=b.range[1])return e[y].subjects.push(l),e;s[0]<b.range[0]&&s[1]>b.range[0]&&(a.push(y),d=d.concat(b.subjects)),s[0]>=b.range[0]&&s[0]<=b.range[1]&&(a.push(y),d=d.concat(b.subjects),s[0]=b.range[0]),s[1]>=b.range[0]&&s[1]<=b.range[1]&&(a.push(y),d=d.concat(b.subjects),s[1]=b.range[1])}if(f.push(l),s[0]<=c&&s[1]>=o)return[{subjects:f,range:s}];a.length&&a.reverse().forEach(y=>{e.splice(y,1)}),e.push({subjects:d.concat([l]),range:s})}}return e},[]).sort((e,r)=>e.range[0]-r.range[0]);function cs(){let t={};function e(){for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&delete t[a]}function r(a){let o={};for(let c in t)+c<=a&&(o[c]=t[c]);return o}function i(a){let o={};for(let c in t)+c>=a&&(o[c]=t[c]);return o}function n({timestamp:a,priority:o,initiator:c}){if(er(a)){let d=t[a]??null;if(d&&o&&ve(o,!0)){let f={},y=d[o];return y&&(f={...f,...y}),f=K(f)?null:f,f&&ve(c,!0)?f[c]??null:f}return d}return null}function s({timestamp:a,priority:o,initiator:c}){if(er(a))if(t[a]){if(o&&ve(o,!0))if(t[a][o]){if(c&&ve(c,!0))if(t[a][o][c]){if(delete t[a][o][c],!K(t[a][o]))return!0}else return!1;if(delete t[a][o],!K(t[a]))return!0}else return!1;return delete t[a]}else return!1;return!1}function l({timestamp:a,priority:o,initiator:c,...d}){t[a]?.[o]?.[c]?t[a][o][c].push({...d}):t[a]?.[o]?t[a][o]={...t[a][o],[c]:[{...d}]}:t[a]?t[a]={...t[a],[o]:{[c]:[{...d}]}}:t[a]={[o]:{[c]:[{...d}]}}}return{map:t,remove:s,add:l,removeAll:e,get:n,getLte:r,getGte:i}}var vl=[S.expect,S.setNextBranch],gl=1/0;function ps(t){let e=t,r,i=bl(),n=cs(),s,l=()=>{y(),h()},a=p=>{n.add.call(void 0,p),w()},o=(p=[])=>{for(let m of p)if(m.action(),vl.includes(m.actionType))break},c=(p=1/0)=>{let m=at(n.get({timestamp:p,priority:"control"})??{}),C=at(n.get({timestamp:p,priority:"container"})??{}),g=at(n.get({timestamp:p,priority:"chapter"})??{});return[...m,...C,...g]},d=p=>{i.isReady(p)&&o(c(p))},f=()=>{o([...at(n.get({timestamp:1/0,priority:"chapter"})??{})])},y=()=>{r&&(s?.unsubscribe(),r=void 0)},b=p=>{},w=()=>{r||(r=()=>setTimeout(()=>{d(1/0)}),s=e.events.ended$.subscribe(r))},$=p=>{y(),e=p},I=p=>{p.priority==="container"&&i.resetCalled(p.timestamp),n.remove(p)},h=()=>{i.release(),n.removeAll()};return{setPlayer:$,add:a,remove:I,exec:d,execEndOfVideo:f,listen:w,unlisten:y,release:l,containersEventsCallState:i,getPreparedToExecActions:c}}function bl(){let t=new Map;return{setCalled:({timestamp:l,id:a})=>{let o=t.get(l);o&&o[a]!==void 0&&(o[a]=!0)},setData:(l=[])=>{for(let a of l){let o=a.endTime??gl,c=t.get(o)??{};t.set(o,{...c,[a.id]:!1})}},resetCalled:l=>{let a=t.get(l);if(a)for(let o in a)a[o]=!1},isReady:l=>{let a=t.get(l);return a?!Object.values(a).some(o=>!o):!0},release:()=>t.clear()}}function at(t){return Object.values(t).flat().sort(e=>e.actionType===S.expect?-1:1)}var hs={videoContentHeight:0,videoContentWidth:0},us=(t,e)=>{let{height:r,width:i}=e.info.intrinsicVideoSize$.getValue()||{};if(!(r&&i))return hs;let{clientHeight:n,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(n&&s))return hs;let l=r/i,a=n/s,o,c;return a>l?(c=s,o=s*l):a<l?(c=n/l,o=n):(c=s,o=n),{videoContentWidth:c,videoContentHeight:o}};var Cl=250;function ds(t){let e=()=>{},r=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function i(a){let{parentElement:o,player:c}=t();if(o&&c){let{videoContentWidth:d,videoContentHeight:f}=us(o,c);o.style.setProperty("--interactive-content-width",`${d}px`),o.style.setProperty("--interactive-content-height",`${f}px`),o.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function n(){let{parentElement:a}=t();a.removeAttribute("style")}let s=me(a=>{let{fns:o=[]}=t();i(a);for(let c of o)c()},Cl);function l(){e=void 0,r.disconnect(),n()}return{resizeObserver:r,calc:()=>{e?.()},release:l}}var we=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.concat(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={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var El=t=>Math.floor(Math.random()*t),ms=t=>{let e=t.length,r=1/0,i=null;for(;e--;){let n=t[e],s=n.weight??1;s<r&&(r=s,i=n)}return i},ys=t=>{let e=t.length,r=-1/0,i=null;for(;e--;){let n=t[e],s=n.weight??0;s>r&&(r=s,i=n)}return i};var vs=t=>{let e=t.length,r=El(e);return t[r]},fs=1,gs=t=>{let e=0;for(let i=0;i<t.length;++i)e+=t[i].weight??fs;let r=Math.random()*e;e=0;for(let i=0;i<t.length-1;++i)if(e+=t[i].weight??fs,e>=r)return t[i];return t[t.length-1]};var bs={shouldOpenNow:!0,isDetachContainer:!0};var ur=(t,e=!1)=>({...t,args:e?{...t.args,...bs}:{...bs,...t.args}}),Is=({globalEventEmitter:t,player:e,interactiveEvents:r,removeControllers:i})=>{let n={isExpect:!1},s=()=>{n.isExpect&&(n.isExpect=!1)},l=({action:h,controlType:p,controlId:m,containerId:C,branches:g=[],onEvent:L,isEOV:M=()=>!1,isDisabled:k=()=>!1})=>{let x=ur(h,M()),_={timestamp:1/0,priority:"control",initiator:m,actionType:x.type},V=k(),X=t.emit.bind(t,v.interactives,{subjectId:m,subjectType:p,subjectName:"control",type:V?T.actionChoiceCanceled:T.actionChoice,actionType:h.type,payload:{containerId:C,...x.args}});if(V){X();return}switch(x.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let J=g.find(D=>D.id===x.args.branchId);if(!J)return;L(x.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),X(),x.args.shouldOpenNow?w({subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{chapterId:J.chapterId,autoSelect:!1}}):(r.add({..._,action:w.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{chapterId:J.chapterId,autoSelect:!1}})}),i?.());return}case S.continuePlayback.trim().toLowerCase():{L(x.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),X(),x.args.shouldOpenNow?b({subjectId:m,subjectName:"control",subjectType:p,action:h}):r.add({..._,action:b.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:h})});return}case S.openURI.trim().toLowerCase():{L(x.args.isDetachContainer,y.bind(null,{subjectId:m,subjectName:"control"})),X(),x.args.shouldOpenNow?I({subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{URI:h.args.uri}}):(r.add({..._,action:I.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:x,payload:{URI:h.args.uri}})}),i?.());return}default:console.error("Unexpected control event"),t.emit(v.errors,new A(1,1,{message:"Unexpected control event"}));return}},a=({action:h,container:{id:p,endTime:m},branches:C=[],isEOV:g=!1,autoSelected:L=!1})=>{let M=ur(h,g),k={timestamp:!M.args.shouldOpenNow||g?1/0:m??1/0,priority:"container",initiator:p,actionType:M.type},x=t.emit.bind(t,v.interactives,{subjectId:p,subjectName:"container",type:T.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let _=C.find(V=>V.id===M.args.branchId);if(!_)return;x(),r.add({...k,action:w.bind(null,{subjectId:p,subjectName:"container",action:M,payload:{chapterId:_.chapterId,autoSelect:L}})}),i?.();return}case S.setMaxWeightBranch.trim().toLowerCase():return;case S.setMinWeightBranch.trim().toLowerCase():return;case S.setRandomBranch.trim().toLowerCase():return;case S.setWeightlessRandomBranch.trim().toLowerCase():return;case S.continuePlayback.trim().toLowerCase():{x(),r.add({...k,action:b.bind(null,{subjectId:p,subjectName:"container",action:M})});return}case S.openURI.trim().toLowerCase():{x(),r.add({...k,action:I.bind(null,{subjectId:p,subjectName:"container",action:M,payload:{URI:h.args.uri}})}),i?.();return}default:console.error("Unexpected container event"),t.emit(v.errors,new A(1,1,{message:"Unexpected container event"}));return}};function o({container:h,branches:p,isEOV:m=!1}){let C=lr(h.events);if(C){let g=ur(C.action,m);t.emit(v.interactives,{subjectId:h.id,subjectName:"container",type:T.actionChoice,actionType:g.type,payload:g.args}),r.add({timestamp:m?1/0:h.endTime??1/0,priority:"container",initiator:h.id,actionType:S.expect,action:f.bind(null,{subjectId:h.id,subjectName:"container"})}),n.isExpect=!0}else for(let g of h.events??[])a({action:g.action,container:h,branches:p,isEOV:m})}let c=({chapterId:h,action:p,branches:m=[]})=>{let C=t.emit.bind(t,v.interactives,{subjectId:h,subjectName:"chapter",type:T.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{let g=m.find(L=>L.id===p.args.branchId);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setWeightlessRandomBranch.trim().toLowerCase():{let g=vs(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setRandomBranch.trim().toLowerCase():{let g=gs(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setMaxWeightBranch.trim().toLowerCase():{let g=ys(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.setMinWeightBranch.trim().toLowerCase():{let g=ms(m);return g?.chapterId?(C(),w.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case S.continuePlayback.trim().toLowerCase():return C(),b.bind(null,{subjectId:h,subjectName:"chapter",action:p});case S.openURI.trim().toLowerCase():return C(),I.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),t.emit(v.errors,new A(1,1,{message:"Unexpected chapter event"}));return}};function d(h){let p=lr(h.events);if(p){if(N(h))return;t.emit(v.interactives,{subjectId:h.id,subjectName:"chapter",type:T.actionChoice,actionType:p.action.type,payload:p.action.args}),r.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:S.expect,action:f.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events?.forEach(m=>{let C=c({chapterId:h.id,action:m.action,branches:h.branches});C&&r.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:m.action.type,action:C})})}let f=({subjectId:h,subjectName:p})=>{e.pause(),t.emit(v.interactives,{subjectId:h,subjectName:p,type:T.actionExecution,actionType:S.expect})},y=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?r.execEndOfVideo():e.play(),t.emit(v.interactives,{subjectId:h,subjectName:p,type:T.actionExecution,actionType:"after-expect"})},b=({subjectId:h,subjectName:p,subjectType:m,action:C})=>{t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type})},w=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:g})=>{g.behaviour="change-chapter",t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type,payload:g})},$=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:g})=>{g.behaviour="change-manifest",t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type,payload:g})},I=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:g})=>{if(!g.URI)return;let L=window.open(g.URI,"_blank","noopener,noreferrer");L&&(L.opener=null),t.emit(v.interactives,{subjectId:h,subjectName:p,subjectType:m,type:T.actionExecution,actionType:C.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:c,onExpectEvent:f,expectEventHandler:y,setManifestChapterEvents:d,setManifestContainerEvents:o,stopExpect:s,state:n}};var mr=dt(Jt(),1),O=require("@vkontakte/videoplayer-shared");var ot=(t,e)=>{let r={};return t.map(i=>{if(!r[i]){let n=e.chapters.find(l=>l.id===i);if(!n)return null;let s=e.media.videos.find(l=>n.videoId===l.id);if(!s)return null;r[i]=dr(s)}return r[i]}).filter(Boolean)},xs=t=>{for(let e of t.variants)if(Ts(e)&&"payload"in e)return e.payload.id},Ts=t=>t.type==="custom"&&"payload"in t&&t.payload.type==="vk",dr=t=>{let e=xs(t);if(!e)return null;let r=e.split("_").pop();return r?parseInt(r,10):null},Ss=(t,e)=>{for(let r of t.media.videos)if(e===dr(r)){for(let i of t.chapters)if(i.videoId===r.id)return i.id;return}},fr=(t,e)=>t.reduce((r,i)=>{let n=Ss(e,i);return n?[...r,n]:r},[]);var Me=class{constructor({globalEventEmitter:e,videoId:r,interactiveController:i,historyApi:n,settings:s}){this.state={history$:new O.ValueSubject([]),hasPrevChapter$:new O.ValueSubject(!1),prevChapter$:new O.ValueSubject(null),isInitialChapter$:new O.ValueSubject(!1),isGoBackLimited$:new O.ValueSubject(!1)};this.#e=null;this.#a=!1;this.#t=null;this.#p=null;this.events={inited$:new O.Subject,destroyed$:new O.Subject,error$:new O.Subject};this.#n=null;this.#s=null;this.#r=null;this.#o=new O.Subscription;this.#l=!1;this.#c=0;this.#n=r,this.#r=e,this.#s=i,this.#e=n,this.#i=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next((0,mr.default)(l,-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#t?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#i.maxLength-1)}))}#e;#i;#a;#t;#p;#n;#s;#r;#o;#l;#c;async setManifest(e){if(!this.#s||!this.#r)return;this.#t=e,await this.getProjectHistory();let r=this.getInitialChapterId();await this.#s.setChapter({chapterId:r,pushToHistory:!1}),this.#a||(this.#a=!0,this.events.inited$.next({initChapterId:r}))}get inited(){return this.#a}async updateHistory(e,r=!0){if(!this.#t)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let i=this.#t,n=e.length-this.#i.maxLength,s=n>0?e.slice(n):e,l=ot(s,i);if(this.#p=l,this.state.history$.next(s),!(!r||!this.#e||!this.#n))try{await this.#e.save(this.#n,l)}catch{let o=new A(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#r?.emit(v.errors,o)}}async goBack(){if(!this.state||!this.#s){let i=new A(1,5,"Unable to save interactive history");return this.events.error$.next(i),this.#r?.emit(v.errors,i)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),r=e.pop();this.state.history$.next(e),await this.#s.setChapter({chapterId:r,playPrev:!0})}async getProjectHistory(){if(!this.#t||!this.#n)return;let e=this.#t,r=[this.getInitialVideoId()];if(this.#e)try{let n=await this.#e.get(this.#n);n.length&&(r=n)}catch{let s=new A(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#r?.emit(v.errors,s)}let i=fr(r,e);this.state.history$.next(i)}getInitialChapterId(){let e=this.state.history$.getValue();return(0,mr.default)(e,-1)||this.#i.initChapterId||this.#t?.metadata.initChapterId}getInitialVideoId(){if(this.#t){let e=this.getInitialChapterId();return ot([e],this.#t).pop()}return null}destroy(){this.#n=null,this.#e=null,this.#s=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#r?.emit(v.historyDestroyed),this.events.destroyed$.next(),this.#r=null}};var lt=class t{constructor(e,r,i,n){this.target=e,this.type=r,this.listener=i,this.options=t._convertOptions(e,n),this.target.addEventListener(r,i,this.options)}unlisten(){this.type&&this.listener&&this.options&&this.target?.removeEventListener(this.type,this.listener,this.options),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(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(l=>!i.has(l));return n.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+n.join(",")),t._doesSupportObject(e)?r:r.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(e){let r=t._supportsObject;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._supportsObject=r}return r||!1}};var ct=class{constructor(){this.bindingMap=new we}release(){this.removeAll(),this.bindingMap=null}listen(e,r,i,n){if(!this.bindingMap)return;let s=new lt(e,r,i,n);this.bindingMap.push(r,s)}listenOnce(e,r,i,n){let s=l=>{this.unlisten(e,r,s),i(l)};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 pt=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 ht=class{constructor({parentElement:e,endOffsetMs:r=250,onError:i}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let r=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,i=this.isChapterEndTime(r);if(this.isContainerTime(r))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(i)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
7
7
  position: absolute;
8
8
  top: 0;
9
9
  left: 0;