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