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