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