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