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