@vkontakte/videoplayer-interactive 1.0.62 → 1.0.63-dev.55dfadaf.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es2024.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.62
3
- * Tue, 24 Mar 2026 10:15:38 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-62/doc/
2
+ * @vkontakte/videoplayer-interactive v1.0.63-dev.55dfadaf.0
3
+ * Wed, 25 Mar 2026 07:47:50 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-63/doc/
5
5
  */
6
- var e=Object.create,t=Object.getPrototypeOf,n=Object.defineProperty,r=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty;function a(e){return this[e]}var o,s,c=(c,l,u)=>{var d=typeof c==`object`&&!!c;if(d){var f=l?o??=new WeakMap:s??=new WeakMap,p=f.get(c);if(p)return p}u=c==null?{}:e(t(c));let m=l||!c||!c.__esModule?n(u,`default`,{value:c,enumerable:!0}):u;for(let e of r(c))i.call(m,e)||n(m,e,{get:a.bind(c,e),enumerable:!0});return d&&f.set(c,m),m},l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=l((e,t)=>{var n=function(e){return e&&e.Math===Math&&e};t.exports=n(typeof globalThis==`object`&&globalThis)||n(typeof window==`object`&&window)||n(typeof self==`object`&&self)||n(typeof global==`object`&&global)||n(typeof e==`object`&&e)||function(){return this}()||Function(`return this`)()}),d=l((e,t)=>{t.exports=function(e){try{return!!e()}catch{return!0}}}),f=l((e,t)=>{t.exports=!d()(function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)})}),p=l((e,t)=>{var n=f(),r=Function.prototype,i=r.apply,a=r.call;t.exports=typeof Reflect==`object`&&Reflect.apply||(n?a.bind(i):function(){return a.apply(i,arguments)})}),m=l((e,t)=>{var n=f(),r=Function.prototype,i=r.call,a=n&&r.bind.bind(i,i);t.exports=n?a:function(e){return function(){return i.apply(e,arguments)}}}),h=l((e,t)=>{var n=m(),r=n({}.toString),i=n(``.slice);t.exports=function(e){return i(r(e),8,-1)}}),g=l((e,t)=>{var n=h(),r=m();t.exports=function(e){if(n(e)===`Function`)return r(e)}}),_=l((e,t)=>{var n=typeof document==`object`&&document.all;t.exports=n===void 0&&n!==void 0?function(e){return typeof e==`function`||e===n}:function(e){return typeof e==`function`}}),v=l((e,t)=>{t.exports=!d()(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})}),y=l((e,t)=>{var n=f(),r=Function.prototype.call;t.exports=n?r.bind(r):function(){return r.apply(r,arguments)}}),b=l(e=>{var t={}.propertyIsEnumerable,n=Object.getOwnPropertyDescriptor;e.f=n&&!t.call({1:2},1)?function(e){var t=n(this,e);return!!t&&t.enumerable}:t}),x=l((e,t)=>{t.exports=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}}}),S=l((e,t)=>{var n=m(),r=d(),i=h(),a=Object,o=n(``.split);t.exports=r(function(){return!a(`z`).propertyIsEnumerable(0)})?function(e){return i(e)===`String`?o(e,``):a(e)}:a}),C=l((e,t)=>{t.exports=function(e){return e==null}}),w=l((e,t)=>{var n=C(),r=TypeError;t.exports=function(e){if(n(e))throw new r(`Can't call method on `+e);return e}}),T=l((e,t)=>{var n=S(),r=w();t.exports=function(e){return n(r(e))}}),E=l((e,t)=>{var n=_();t.exports=function(e){return typeof e==`object`?e!==null:n(e)}}),D=l((e,t)=>{t.exports={}}),ee=l((e,t)=>{var n=D(),r=u(),i=_(),a=function(e){return i(e)?e:void 0};t.exports=function(e,t){return arguments.length<2?a(n[e])||a(r[e]):n[e]&&n[e][t]||r[e]&&r[e][t]}}),te=l((e,t)=>{t.exports=m()({}.isPrototypeOf)}),ne=l((e,t)=>{var n=u().navigator,r=n&&n.userAgent;t.exports=r?String(r):``}),re=l((e,t)=>{var n=u(),r=ne(),i=n.process,a=n.Deno,o=i&&i.versions||a&&a.version,s=o&&o.v8,c,l;s&&(c=s.split(`.`),l=c[0]>0&&c[0]<4?1:+(c[0]+c[1])),!l&&r&&(c=r.match(/Edge\/(\d+)/),(!c||c[1]>=74)&&(c=r.match(/Chrome\/(\d+)/),c&&(l=+c[1]))),t.exports=l}),ie=l((e,t)=>{var n=re(),r=d(),i=u().String;t.exports=!!Object.getOwnPropertySymbols&&!r(function(){var e=Symbol(`symbol detection`);return!i(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&n&&n<41})}),ae=l((e,t)=>{t.exports=ie()&&!Symbol.sham&&typeof Symbol.iterator==`symbol`}),oe=l((e,t)=>{var n=ee(),r=_(),i=te(),a=ae(),o=Object;t.exports=a?function(e){return typeof e==`symbol`}:function(e){var t=n(`Symbol`);return r(t)&&i(t.prototype,o(e))}}),se=l((e,t)=>{var n=String;t.exports=function(e){try{return n(e)}catch{return`Object`}}}),ce=l((e,t)=>{var n=_(),r=se(),i=TypeError;t.exports=function(e){if(n(e))return e;throw new i(r(e)+` is not a function`)}}),le=l((e,t)=>{var n=ce(),r=C();t.exports=function(e,t){var i=e[t];return r(i)?void 0:n(i)}}),ue=l((e,t)=>{var n=y(),r=_(),i=E(),a=TypeError;t.exports=function(e,t){var o,s;if(t===`string`&&r(o=e.toString)&&!i(s=n(o,e))||r(o=e.valueOf)&&!i(s=n(o,e))||t!==`string`&&r(o=e.toString)&&!i(s=n(o,e)))return s;throw new a(`Can't convert object to primitive value`)}}),de=l((e,t)=>{t.exports=!0}),fe=l((e,t)=>{var n=u(),r=Object.defineProperty;t.exports=function(e,t){try{r(n,e,{value:t,configurable:!0,writable:!0})}catch{n[e]=t}return t}}),pe=l((e,t)=>{var n=de(),r=u(),i=fe(),a=`__core-js_shared__`,o=t.exports=r[a]||i(a,{});(o.versions||=[]).push({version:`3.43.0`,mode:n?`pure`:`global`,copyright:`© 2014-2025 Denis Pushkarev (zloirock.ru)`,license:`https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE`,source:`https://github.com/zloirock/core-js`})}),me=l((e,t)=>{var n=pe();t.exports=function(e,t){return n[e]||(n[e]=t||{})}}),he=l((e,t)=>{var n=w(),r=Object;t.exports=function(e){return r(n(e))}}),O=l((e,t)=>{var n=m(),r=he(),i=n({}.hasOwnProperty);t.exports=Object.hasOwn||function(e,t){return i(r(e),t)}}),ge=l((e,t)=>{var n=m(),r=0,i=Math.random(),a=n(1.1.toString);t.exports=function(e){return`Symbol(`+(e===void 0?``:e)+`)_`+a(++r+i,36)}}),_e=l((e,t)=>{var n=u(),r=me(),i=O(),a=ge(),o=ie(),s=ae(),c=n.Symbol,l=r(`wks`),d=s?c.for||c:c&&c.withoutSetter||a;t.exports=function(e){return i(l,e)||(l[e]=o&&i(c,e)?c[e]:d(`Symbol.`+e)),l[e]}}),ve=l((e,t)=>{var n=y(),r=E(),i=oe(),a=le(),o=ue(),s=_e(),c=TypeError,l=s(`toPrimitive`);t.exports=function(e,t){if(!r(e)||i(e))return e;var s=a(e,l),u;if(s){if(t===void 0&&(t=`default`),u=n(s,e,t),!r(u)||i(u))return u;throw new c(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),o(e,t)}}),ye=l((e,t)=>{var n=ve(),r=oe();t.exports=function(e){var t=n(e,`string`);return r(t)?t:t+``}}),be=l((e,t)=>{var n=u(),r=E(),i=n.document,a=r(i)&&r(i.createElement);t.exports=function(e){return a?i.createElement(e):{}}}),xe=l((e,t)=>{var n=v(),r=d(),i=be();t.exports=!n&&!r(function(){return Object.defineProperty(i(`div`),`a`,{get:function(){return 7}}).a!==7})}),Se=l(e=>{var t=v(),n=y(),r=b(),i=x(),a=T(),o=ye(),s=O(),c=xe(),l=Object.getOwnPropertyDescriptor;e.f=t?l:function(e,t){if(e=a(e),t=o(t),c)try{return l(e,t)}catch{}if(s(e,t))return i(!n(r.f,e,t),e[t])}}),Ce=l((e,t)=>{var n=d(),r=_(),i=/#|\.prototype\./,a=function(e,t){var i=s[o(e)];return i===l?!0:i===c?!1:r(t)?n(t):!!t},o=a.normalize=function(e){return String(e).replace(i,`.`).toLowerCase()},s=a.data={},c=a.NATIVE=`N`,l=a.POLYFILL=`P`;t.exports=a}),we=l((e,t)=>{var n=g(),r=ce(),i=f(),a=n(n.bind);t.exports=function(e,t){return r(e),t===void 0?e:i?a(e,t):function(){return e.apply(t,arguments)}}}),Te=l((e,t)=>{var n=v(),r=d();t.exports=n&&r(function(){return Object.defineProperty(function(){},`prototype`,{value:42,writable:!1}).prototype!==42})}),Ee=l((e,t)=>{var n=E(),r=String,i=TypeError;t.exports=function(e){if(n(e))return e;throw new i(r(e)+` is not an object`)}}),De=l(e=>{var t=v(),n=xe(),r=Te(),i=Ee(),a=ye(),o=TypeError,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=`enumerable`,u=`configurable`,d=`writable`;e.f=t?r?function(e,t,n){if(i(e),t=a(t),i(n),typeof e==`function`&&t===`prototype`&&`value`in n&&d in n&&!n[d]){var r=c(e,t);r&&r[d]&&(e[t]=n.value,n={configurable:u in n?n[u]:r[u],enumerable:l in n?n[l]:r[l],writable:!1})}return s(e,t,n)}:s:function(e,t,r){if(i(e),t=a(t),i(r),n)try{return s(e,t,r)}catch{}if(`get`in r||`set`in r)throw new o(`Accessors not supported`);return`value`in r&&(e[t]=r.value),e}}),Oe=l((e,t)=>{var n=v(),r=De(),i=x();t.exports=n?function(e,t,n){return r.f(e,t,i(1,n))}:function(e,t,n){return e[t]=n,e}}),k=l((e,t)=>{var n=u(),r=p(),i=g(),a=_(),o=Se().f,s=Ce(),c=D(),l=we(),d=Oe(),f=O();pe();var m=function(e){var t=function(n,i,a){if(this instanceof t){switch(arguments.length){case 0:return new e;case 1:return new e(n);case 2:return new e(n,i)}return new e(n,i,a)}return r(e,this,arguments)};return t.prototype=e.prototype,t};t.exports=function(e,t){var r=e.target,u=e.global,p=e.stat,h=e.proto,g=u?n:p?n[r]:n[r]&&n[r].prototype,_=u?c:c[r]||d(c,r,{})[r],v=_.prototype,y,b,x,S,C,w,T,E,D;for(S in t)y=s(u?S:r+(p?`.`:`#`)+S,e.forced),b=!y&&g&&f(g,S),w=_[S],b&&(e.dontCallGetSet?(D=o(g,S),T=D&&D.value):T=g[S]),C=b&&T?T:t[S],!(!y&&!h&&typeof w==typeof C)&&(E=e.bind&&b?l(C,n):e.wrap&&b?m(C):h&&a(C)?i(C):C,(e.sham||C&&C.sham||w&&w.sham)&&d(E,`sham`,!0),d(_,S,E),h&&(x=r+`Prototype`,f(c,x)||d(c,x,{}),d(c[x],S,C),e.real&&v&&(y||!v[S])&&d(v,S,C)))}}),ke=l((e,t)=>{var n=Math.ceil,r=Math.floor;t.exports=Math.trunc||function(e){var t=+e;return(t>0?r:n)(t)}}),A=l((e,t)=>{var n=ke();t.exports=function(e){var t=+e;return t!==t||t===0?0:n(t)}}),Ae=l((e,t)=>{var n=A(),r=Math.max,i=Math.min;t.exports=function(e,t){var a=n(e);return a<0?r(a+t,0):i(a,t)}}),je=l((e,t)=>{var n=A(),r=Math.min;t.exports=function(e){var t=n(e);return t>0?r(t,9007199254740991):0}}),Me=l((e,t)=>{var n=je();t.exports=function(e){return n(e.length)}}),Ne=l((e,t)=>{var n=T(),r=Ae(),i=Me(),a=function(e){return function(t,a,o){var s=n(t),c=i(s);if(c===0)return!e&&-1;var l=r(o,c),u;if(e&&a!==a){for(;c>l;)if(u=s[l++],u!==u)return!0}else for(;c>l;l++)if((e||l in s)&&s[l]===a)return e||l||0;return!e&&-1}};t.exports={includes:a(!0),indexOf:a(!1)}}),Pe=l((e,t)=>{t.exports=function(){}}),Fe=l(()=>{var e=k(),t=Ne().includes,n=d(),r=Pe();e({target:`Array`,proto:!0,forced:n(function(){return![,].includes()})},{includes:function(e){return t(this,e,arguments.length>1?arguments[1]:void 0)}}),r(`includes`)}),Ie=l((e,t)=>{t.exports=ee()}),Le=l((e,t)=>{Fe(),t.exports=Ie()(`Array`,`includes`)}),Re=l((e,t)=>{t.exports=Le()}),ze=l((e,t)=>{t.exports=Re()}),Be=l(()=>{var e=k(),t=he(),n=Me(),r=A(),i=Pe();e({target:`Array`,proto:!0},{at:function(e){var i=t(this),a=n(i),o=r(e),s=o>=0?o:a+o;return s<0||s>=a?void 0:i[s]}}),i(`at`)}),Ve=l((e,t)=>{Be(),t.exports=Ie()(`Array`,`at`)}),He=l((e,t)=>{t.exports=Ve()}),Ue=l((e,t)=>{t.exports=He()}),We=l((e,t)=>{var n=_e()(`toStringTag`),r={};r[n]=`z`,t.exports=String(r)===`[object z]`}),Ge=l((e,t)=>{var n=We(),r=_(),i=h(),a=_e()(`toStringTag`),o=Object,s=i(function(){return arguments}())===`Arguments`,c=function(e,t){try{return e[t]}catch{}};t.exports=n?i:function(e){var t,n,l;return e===void 0?`Undefined`:e===null?`Null`:typeof(n=c(t=o(e),a))==`string`?n:s?i(t):(l=i(t))===`Object`&&r(t.callee)?`Arguments`:l}}),Ke=l((e,t)=>{var n=Ge(),r=String;t.exports=function(e){if(n(e)===`Symbol`)throw TypeError(`Cannot convert a Symbol value to a string`);return r(e)}}),qe=l(()=>{var e=k(),t=m(),n=w(),r=A(),i=Ke(),a=d(),o=t(``.charAt);e({target:`String`,proto:!0,forced:a(function(){return`𠮷`.at(-2)!==`\ud842`})},{at:function(e){var t=i(n(this)),a=t.length,s=r(e),c=s>=0?s:a+s;return c<0||c>=a?void 0:o(t,c)}})}),Je=l((e,t)=>{qe(),t.exports=Ie()(`String`,`at`)}),Ye=l((e,t)=>{t.exports=Je()}),Xe=l((e,t)=>{t.exports=Ye()}),Ze=l((e,t)=>{var n=me(),r=ge(),i=n(`keys`);t.exports=function(e){return i[e]||(i[e]=r(e))}}),Qe=l((e,t)=>{t.exports=!d()(function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})}),$e=l((e,t)=>{var n=O(),r=_(),i=he(),a=Ze(),o=Qe(),s=a(`IE_PROTO`),c=Object,l=c.prototype;t.exports=o?c.getPrototypeOf:function(e){var t=i(e);if(n(t,s))return t[s];var a=t.constructor;return r(a)&&t instanceof a?a.prototype:t instanceof c?l:null}}),et=l((e,t)=>{t.exports={}}),tt=l((e,t)=>{var n=m(),r=O(),i=T(),a=Ne().indexOf,o=et(),s=n([].push);t.exports=function(e,t){var n=i(e),c=0,l=[],u;for(u in n)!r(o,u)&&r(n,u)&&s(l,u);for(;t.length>c;)r(n,u=t[c++])&&(~a(l,u)||s(l,u));return l}}),nt=l((e,t)=>{t.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]}),rt=l((e,t)=>{var n=tt(),r=nt();t.exports=Object.keys||function(e){return n(e,r)}}),it=l((e,t)=>{var n=v(),r=d(),i=m(),a=$e(),o=rt(),s=T(),c=b().f,l=i(c),u=i([].push),f=n&&r(function(){var e=Object.create(null);return e[2]=2,!l(e,2)}),p=function(e){return function(t){for(var r=s(t),i=o(r),c=f&&a(r)===null,d=i.length,p=0,m=[],h;d>p;)h=i[p++],(!n||(c?h in r:l(r,h)))&&u(m,e?[h,r[h]]:r[h]);return m}};t.exports={entries:p(!0),values:p(!1)}}),at=l(()=>{var e=k(),t=it().entries;e({target:`Object`,stat:!0},{entries:function(e){return t(e)}})}),ot=l((e,t)=>{at(),t.exports=D().Object.entries}),st=l((e,t)=>{t.exports=ot()}),ct=l((e,t)=>{t.exports=st()}),lt=l(()=>{var e=k(),t=it().values;e({target:`Object`,stat:!0},{values:function(e){return t(e)}})}),ut=l((e,t)=>{lt(),t.exports=D().Object.values}),dt=l((e,t)=>{t.exports=ut()}),ft=l((e,t)=>{t.exports=dt()}),pt=l((e,t)=>{var n=h();t.exports=Array.isArray||function(e){return n(e)===`Array`}}),mt=l((e,t)=>{var n=TypeError,r=9007199254740991;t.exports=function(e){if(e>r)throw n(`Maximum allowed index exceeded`);return e}}),ht=l((e,t)=>{var n=pt(),r=Me(),i=mt(),a=we(),o=function(e,t,s,c,l,u,d,f){for(var p=l,m=0,h=d?a(d,f):!1,g,_;m<c;)m in s&&(g=h?h(s[m],m,t):s[m],u>0&&n(g)?(_=r(g),p=o(e,t,g,_,p,u-1)-1):(i(p+1),e[p]=g),p++),m++;return p};t.exports=o}),gt=l((e,t)=>{var n=m(),r=_(),i=pe(),a=n(Function.toString);r(i.inspectSource)||(i.inspectSource=function(e){return a(e)}),t.exports=i.inspectSource}),_t=l((e,t)=>{var n=m(),r=d(),i=_(),a=Ge(),o=ee(),s=gt(),c=function(){},l=o(`Reflect`,`construct`),u=/^\s*(?:class|function)\b/,f=n(u.exec),p=!u.test(c),h=function(e){if(!i(e))return!1;try{return l(c,[],e),!0}catch{return!1}},g=function(e){if(!i(e))return!1;switch(a(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(u,s(e))}catch{return!0}};g.sham=!0,t.exports=!l||r(function(){var e;return h(h.call)||!h(Object)||!h(function(){e=!0})||e})?g:h}),vt=l((e,t)=>{var n=pt(),r=_t(),i=E(),a=_e()(`species`),o=Array;t.exports=function(e){var t;return n(e)&&(t=e.constructor,r(t)&&(t===o||n(t.prototype))?t=void 0:i(t)&&(t=t[a],t===null&&(t=void 0))),t===void 0?o:t}}),yt=l((e,t)=>{var n=vt();t.exports=function(e,t){return new(n(e))(t===0?0:t)}}),bt=l(()=>{var e=k(),t=ht(),n=he(),r=Me(),i=A(),a=yt();e({target:`Array`,proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,o=n(this),s=r(o),c=a(o,0);return c.length=t(c,o,o,s,0,e===void 0?1:i(e)),c}})}),xt=l(()=>{Pe()(`flat`)}),St=l((e,t)=>{bt(),xt(),t.exports=Ie()(`Array`,`flat`)}),Ct=l((e,t)=>{t.exports=St()}),wt=l((e,t)=>{t.exports=Ct()}),Tt=`1.0.62`;import{fromEvent as Et,Subscription as Dt}from"@vkontakte/videoplayer-shared/es2024";class Ot{layout;cssVarsManager;constructor(e,t){this.layout=e,this.cssVarsManager=t}}class kt extends Ot{cssVarsManager;constructor(e,t){super(e,t),this.cssVarsManager=t,this.cssVarsManager=t}setContainerLayout(e){e.style.position=`relative`}setControlLayout(e,t){let n=this.cssVarsManager.getPropValue(`--interactive-content-width`),r=this.cssVarsManager.getPropValue(`--interactive-content-height`),i=this.cssVarsManager.getPropValue(`--interactive-width`),a=this.cssVarsManager.getPropValue(`--interactive-height`);e.style.position=`absolute`,e.style.width=`calc(${n} * (${t.width} + 0.0002))`,e.style.height=`calc(${r} * ${t.height})`,e.style.left=`calc(${n} * ${t.x} + ((${i} - ${n}) / 2))`,e.style.top=`calc(${r} * ${t.y} + ((${a} - ${r}) / 2))`}}import{Subject as At}from"@vkontakte/videoplayer-shared/es2024";function jt(e){return`features`in e}class j{severity;category;data;constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null,` `)}`}}function Mt({emitter$:e,error:t,subjectId:n,message:r=``,severity:i=1,category:a=1}){let o=new j(i,a,{message:r,error:t,details:{id:n}});e.next(o)}class Nt{container;options;factories;controls;error$=new At;cssVarsManager;constructor(e,t,n){this.container=e,this.options=n,this.factories=new Map,this.controls=[],this.setControls(),this.cssVarsManager=t}featureIsEnabled(e){return!!(this.options&&this.options.features&&jt(this.options)&&this.options.features[e])}onError(e=``,t){Mt({emitter$:this.error$,error:t,message:e,subjectId:this.container.id})}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((e,t)=>{let n=t.type.trim().toLowerCase(),r=this.factories.get(n);if(r){let n=r(t,this.options);if(n)return[...e,n]}return[...e]},[])||[]}}import{fromEvent as M,once as Pt}from"@vkontakte/videoplayer-shared/es2024";var N=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,Ft=e=>N(e,`Object`),It=e=>N(e,`String`),Lt=e=>N(e,`Array`),Rt=e=>N(e,`Number`),zt=e=>N(e,`Function`),Bt=e=>N(e,`Boolean`),Vt=e=>Rt(e)&&!isNaN(e),P=e=>Ft(e)&&Object.keys(e).length===0,Ht=e=>Lt(e)&&!e.length,Ut=(e,t)=>It(e)&&!!(t?e.trim():e).length;function Wt(e,t=1){let n=`0`,r=`0`,i=`0`;return e.length===4?(n=`0x`+e[1]+e[1],r=`0x`+e[2]+e[2],i=`0x`+e[3]+e[3]):e.length===7&&(n=`0x`+e[1]+e[2],r=`0x`+e[3]+e[4],i=`0x`+e[5]+e[6]),`rgba(${+n},${+r},${+i},${t})`}var Gt=`interactive`,F={textColor:`#000`,textSize:.4,textContent:``,roundCorners:0,borderWidth:0,borderWidthRawValue:`1px`,roundCornersRawValue:`0`,borderColor:`#000`,borderAlpha:1,backgroundColor:`#fff`,backgroundAlpha:1,innerSizesDependOn:`self`,angle:0,shadowColorLight:`#fff`,shadowColorDark:`#000`,shadowColorAlpha:.24},Kt;(e=>{e.top=`flex-start`,e.bottom=`flex-end`,e.center=`center`})(Kt||={});var qt;(e=>{e.start=`flex-start`,e.end=`flex-end`,e.center=`center`})(qt||={});var Jt=({target:e,props:t})=>{e.style.alignItems=(t?.gravityVertical&&Kt[t.gravityVertical])??`center`,e.style.justifyContent=(t?.gravityHorizontal&&qt[t.gravityHorizontal])??`center`,e.style.textAlign=t?.alignment??`center`},Yt=({target:e,props:t,fallback:n,dependsOn:r})=>{e.style.color=t?.text?.color??n.textColor,e.style.fontSize=`calc(${r.height} * ${t?.text?.size??n.textSize})`,e.textContent=t?.text?.value??n.textContent},Xt=({target:e,props:t,fallback:n})=>{e.style.backgroundColor=Wt(t?.background?.color??n.backgroundColor,t?.background?.alpha??n.backgroundAlpha)},Zt=({target:e,props:t,fallback:n,dependsOn:r,useRawValues:i=!1})=>{let a=i?n.borderWidthRawValue:`calc(${r.height} * ${t?.shape?.border?.width??n.borderWidth})`,o=i?n.roundCornersRawValue:`calc(${r.height} * ${t?.shape?.roundCorners??n.roundCorners})`;e.style.borderWidth=a,e.style.borderStyle=`solid`,e.style.borderColor=Wt(i?n.borderColor:t?.shape?.border?.color??n.borderColor,i?n.borderAlpha:t?.shape?.border?.alpha??n.borderAlpha),e.style.borderRadius=o},Qt=({target:e,isDark:t,baseDimension:n,fallback:r})=>{let i=Wt(r.shadowColorLight,r.shadowColorAlpha),a=Wt(r.shadowColorDark,r.shadowColorAlpha),o=`0px 0px ${`calc(${n} * 0.25)`} ${`calc(${n} * 0.11)`} ${t?a:i}`;e.style.boxShadow=o},$t=({target:e,layoutParams:t,fallback:n})=>{let r=t.angle??n.angle;r&&=r*-1,e.style.transform=`rotate(${r}rad)`};import{fromEvent as I,Subject as en,Subscription as tn}from"@vkontakte/videoplayer-shared/es2024";var nn=`interactive-control-tap`,L={common:nn,animation:`${nn}-animation`,visible:`${nn}-visible`},rn=60;class an{element;controlRotateAngleRad;clickCancelCondition;circleDiameterPx;useDimensionsBasedSize;constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=rn,useDimensionsBasedSize:r=!1}){let i=document.createElement(`div`);i.classList.add(L.common),this.controlRotateAngleRad=e,this.element=i,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=r}onElementClick=e=>{if(!e.target||!e.currentTarget||this.clickCancelCondition())return;let t=e.currentTarget.parentElement;if(!t)return;let n=t.getBoundingClientRect(),r={width:this.useDimensionsBasedSize?t.offsetWidth:this.circleDiameterPx,height:this.useDimensionsBasedSize?t.offsetHeight:this.circleDiameterPx},i=Math.min(r.width,r.height),a=n.left+n.width/2,o=n.top+n.height/2,s=on(e.clientX-a,e.clientY-o,this.controlRotateAngleRad);this.element.style.width=i+`px`,this.element.style.left=s.x+n.width/2-i/2+`px`,this.element.style.top=s.y+n.height/2-i/2+`px`,this.element.classList.add(L.visible,L.animation)};onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(L.visible,L.animation)}}function on(e,t,n){return{x:e*Math.cos(n)-t*Math.sin(n),y:e*Math.sin(n)+t*Math.cos(n)}}function sn(e){return`features`in e}var R=`interactive-control`,z={common:R,selected:`${R}-selected`,wrapper:`${R}-wrapper`,disabled:`${R}-disabled`,button:`${R}-button`,area:`${R}-area`,text:`${R}-text`,blinkAnim:`${R}-blink-anim`,blinkAnimButton:`${R}-blink-anim-button`,blinkAnimArea:`${R}-blink-anim-area`},cn=40,ln=c(ze(),1);import{isSupportedManifest as un,ContainerTypes as dn,ControlTypes as fn,EventActionTypes as B,EventTypes as pn,migrateManifestToLatestVersion as mn}from"@interactiveplatform/movika-manifest";var hn={metadata:`Object`,chapters:`Array`},gn=e=>{if(!Ft(e))return!1;for(let t in hn){let n=e[t];if(!n||!N(n,hn[t]))return!1}return un(e.metadata.version)};function _n(e){return e.type===fn.Text}function vn(e){return e.type===fn.Button}function yn(e){return e.type===fn.Area}var bn={Choice:`Choice`,TextInput:`TextInput`},xn={Button:`Button`,Area:`Area`,Text:`Text`},Sn={onClick:`onClick`,onSuspense:`onSuspense`},Cn={openURI:`openURI`,setNextBranch:`setNextBranch`,setWeightlessRandomBranch:`setWeightlessRandomBranch`,setRandomBranch:`setRandomBranch`,setMaxWeightBranch:`setMaxWeightBranch`,setMinWeightBranch:`setMinWeightBranch`,setDefaultBranch:`setDefaultBranch`,continuePlayback:`continuePlayback`,expect:`expect`},wn=e=>Lt(e)&&!Ht(e),V=e=>e.order===`end`,Tn=e=>Lt(e.containers)&&!Ht(e.containers)&&V(e),En=(e,t)=>{let n=e*1e3;return wn(t.controls)&&n<(t.startTime??0)},Dn=(e,t)=>{let n=e*1e3;return wn(t.controls)&&n>=(t.startTime??0)&&n<=(t.endTime??1/0)},H=(e=[])=>e.some(e=>e.action.type===`expect`),On=(e=[])=>e.find(e=>e.action.type===`expect`),kn=e=>e?.length===1,An=e=>kn(e)&&_n(e[0]);function jn(e=[],t=1/0,n=[]){return e.filter(({container:e})=>!ln.default(n,e.container.id)&&H(e.container.events)&&e.container.endTime===t&&!e.isRemoved&&!e.willRemoved)}function Mn({gameControllers:e=[],subjectName:t,subjectId:n,execFn:r}){for(let i of e)if(t===`container`&&i.container.container.id===n){r(i),jn(e,i.container.container.endTime,[i.container.container.id]).forEach(e=>{r(e)});break}}function Nn(e){for(let t of e.events)if(t.action.type===`openURI`)return!0;return!1}var Pn=(e,t)=>{let n=H(e.events)&&!(e=>t.find(({container:t})=>t.container.id===e)?.container.isRemoved)(e.id),r=(t,n=!1,r=!1)=>{let i=r?`every`:`some`;return t.controls[i](r=>{let a=n?t.endTime===e.endTime:!0;return r.events?.[i](e=>e.action?.type===B.openURI)&&a})},i=e=>e.some(({container:e})=>r(e.container,!0,!1)&&!e.isRemoved),a=e=>e.every(({container:e})=>e.isRemoved||e.willRemoved?!0:r(e.container,!0,!0)),o=jn(t,e.endTime,[e.id]).length,s=e=>e.controls.some(e=>e.events?.some(e=>e.action?.args?.shouldOpenNow)),c=n||o>0,l=i(t),u=r(e),d=a(t),f=n?!1:o>0,p=s(e);return{isExpectTime:c,hasOtherExpect:o>0,hasOpenURIEvent:l,hasOpenURIEventInCurrentContainer:u,isAllOpenURIEventsValid:d,isExpectEventForCurrentContainer:f,hasShouldOpenNowEvent:p}};class U{control;options;container=null;controlElement=null;subscriptions=new tn;error$=new en;controlTap;isInteracted=!1;isRemoved=!1;cssVarsManager=null;constructor(e,t=void 0){this.control=e,this.options=t}setCssVarsManager(e){this.cssVarsManager=e}onControlSelect=()=>{this.container?.isManifestContainerDisabled()||Nn(this.control)||this.container?.element?.classList.add(`interactive-control-wrapper-selected`)};removeView(e=!1){let t=this.getElement();if(t){if(e){if(t.classList.contains(`interactive-control-before-remove`))return;t.classList.add(`interactive-control-before-remove`),this.subscriptions.add(I(t,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${U.name} remove view transition error`,e))).add(I(t,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${U.name} remove view transition error`,e)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()};onError(e=``,t){Mt({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){this.featureIsEnabled(`controlsTapPlace`)&&this.container&&(this.controlTap=new an({controlRotateAngleRad:this.control.layoutParams.angle??F.angle,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?cn:void 0}),this.subscriptions.add(I(e,`click`).subscribe(this.controlTap.onElementClick,e=>this.onError(`Control click tap animation error`,e))).add(I(this.controlTap.element,`animationend`).subscribe(this.controlTap.onAnimationEnd,e=>this.onError(`Tap animationend error`,e))),this.container.element.append(this.controlTap.element))}createContainerElement(e){let t=document.createElement(`div`);t.classList.add(z.wrapper),e.setControlLayout(t,this.control.layoutParams),this.container={element:t,dimensions:(this.control.layoutParams.innerSizesDependOn??F.innerSizesDependOn)===`self`?{height:t.style.height,width:t.style.width}:{height:this.cssVarsManager?.getPropValue(`--interactive-content-height`)??0,width:this.cssVarsManager?.getPropValue(`--interactive-content-width`)??0},isManifestContainerDisabled:()=>e.isContainerDisabled?.()??!1}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&sn(this.options)&&this.options.features[e])}isTouch(){return!!(this.options&&sn(this.options)&&this.options.isTouch)}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case`onclick`:if(!this.container)break;this.subscriptions.add(I(this.container.element,`click`).subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),e=>this.onError(`Error happened on control interaction`,e)));break;default:break}})}removeListeners(){this.subscriptions.unsubscribe()}}var Fn=`interactive-blink-anim-reference`,W={common:Fn,animation:`${Fn}-animation`,disabled:`${Fn}-disabled`};class In{_RAFId=0;_element=void 0;get element(){return this._element}create(){if(this._element)return;let e=document.createElement(`div`);e.classList.add(W.common,W.animation),this._element=e}restart(){this._element&&(this._element.classList.add(W.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(W.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&=(cancelAnimationFrame(this._RAFId),0)}destroy(){this.cleanupRAF(),this._element=void 0}}var Ln=`interactive-container`,G={common:Ln,hidden:`${Ln}-hidden`,disabled:`${Ln}-disabled`},Rn=(e,t)=>{if(e.type.trim().toLowerCase()===`area`)return new zn(e,t)};class zn extends U{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let n=document.createElement(`button`);n.type=`button`,n.classList.add(z.common,z.area),n.setAttribute(`data-testid`,`int_area`),Xt({target:n,props:this.control.props,fallback:{...F,backgroundColor:`transparent`}}),$t({target:n,layoutParams:this.control.layoutParams,fallback:F}),this.addControlTap(n),this.subscriptions.add(M(this.container.element,`click`).pipe(Pt()).subscribe(this.onControlSelect,e=>this.onError(`Control click handler error`,e))),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.updateShadowStyles(),this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled(`controlsExpectTimeBlinkAnimation`))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(M(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(G.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${W.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(M(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(G.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(M(this.controlElement,`mouseleave`).subscribe(()=>{this.controlElement&&(this.controlElement.style.animation=``)},e=>this.onError(`Error happened in mouseleave callback`,e))))}disable(){this.controlElement&&this.controlElement.classList.add(z.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(z.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(Bt(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+`px`;Qt({target:this.controlElement,props:this.control.props,fallback:F,isDark:e,baseDimension:t}),Zt({target:this.controlElement,props:this.control.props,fallback:{...F,borderColor:e?F.shadowColorDark:F.shadowColorLight,borderAlpha:1,borderWidthRawValue:`0.1px`,roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??F.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Zt({target:this.controlElement,props:this.control.props,fallback:{...F,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(z.blinkAnim,e),this.controlElement?.classList.toggle(z.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${z.blinkAnimArea}`)||this.controlElement.classList.contains(z.selected)||this.controlElement.classList.contains(W.disabled)||(this.controlElement.classList.add(W.disabled),this.subscriptions.add(M(e,`animationiteration`).pipe(Pt()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(W.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${z.blinkAnimArea}`)||this.controlElement.classList.contains(z.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue(`--interactive-area-hover-opacity`).trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation=`none`,requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}setShowTimeRange(){}updateFillAnimationDimensions(){}onProgress(){}onResize(){}}import{fromEvent as K,once as Bn}from"@vkontakte/videoplayer-shared/es2024";var Vn=e=>{let t=document.createElement(`span`);switch(e){case`Button`:case`button`:{let e=document.createElement(`div`);return Object.assign(e.style,{overflow:`hidden`,display:`flex`,justifyContent:`center`,alignItems:`center`}),e.append(t),Object.assign(t.style,{display:`inline-block`,whiteSpace:`pre`,textOverflow:`ellipsis`,maxWidth:`initial`,maxHeight:`100%`,wordBreak:`normal`}),e}default:return Object.assign(t.style,{display:`inline-block`,whiteSpace:`break-spaces`,overflow:`hidden`,textOverflow:`ellipsis`,maxWidth:`100%`,maxHeight:`100%`,wordBreak:`break-all`}),t}},Hn=Math.PI,Un=2*Hn,Wn=Hn/2,Gn=3*Wn,Kn=[0,Wn,Hn,Gn];function qn(e){return e===Wn}function Jn(e){return e===Hn}function Yn(e){return e===Gn}function Xn(e){return(e%Un+Un)%Un}function Zn(e){for(let t of Kn)if(e===t)return t}function Qn(e){return Zn(e)?null:[1,2,3,4][Math.floor(e/Wn)+1-1]}function $n(e){return e*180/Math.PI}var q=`interactive-control-fill-animation`,J={common:q,fillerWrapper:`${q}-filler-wrapper`,filler:`${q}-filler`,fillHeight:`${q}-fill-height`,fillWidth:`${q}-fill-width`,fromTop:`${q}-from-top`,fromBottom:`${q}-from-bottom`,fromLeft:`${q}-from-left`,fromRight:`${q}-from-right`};class er{fillAnimationElement;fillAnimationFillerElement;fillAnimationFillerWrapperElement;startTime;endTime;shouldFillHeight;widthExpansionCoef=0;isDebug;fromLeft;useSkew;rotateAngle;constructor(e){let t=document.createElement(`div`);t.classList.add(J.common);let n=document.createElement(`div`);n.classList.add(J.fillerWrapper);let r=document.createElement(`div`);r.classList.add(J.filler),n.append(r),t.append(n);let i=Xn(e.rotateAngle),a=Qn(i),o=a!==null,s=a===2||!o&&Jn(i)||a===3,c=!o&&qn(i),l=!o&&Yn(i),u=!s&&!c&&!l,d=c||l,f=o&&!d,p=f?i:0;t.style.borderRadius=e.borderRadius,n.style.transform=`skew(${p*-1}rad)`,d?(r.classList.add(J.fillHeight,c?J.fromTop:J.fromBottom),n.classList.add(J.fillHeight,c?J.fromTop:J.fromBottom)):(r.classList.add(J.fillWidth,u?J.fromLeft:J.fromRight),n.classList.add(J.fillWidth)),e.debug&&console.log(`[interactive ${er.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:d,rotateAngleRad:i,rotateAngelDeg:$n(i),rotateAngleRaw:e.rotateAngle,fromRight:s,fromTop:c,fromBottom:l,fromLeft:u}),this.useSkew=f,this.fromLeft=u,this.rotateAngle=i,this.fillAnimationElement=t,this.fillAnimationFillerElement=r,this.fillAnimationFillerWrapperElement=n,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=d,this.isDebug=e.debug??!1}updateDimension(e){this.fillAnimationElement.style.top=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.left=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.width=`${e.width}px`,this.fillAnimationElement.style.height=`${e.height}px`;let t=this.calcWidthExpansionCoef({rotateAngle:this.rotateAngle,isSkewed:this.useSkew,initWidth:e.width,initHeight:e.height});!this.shouldFillHeight&&(this.fillAnimationFillerWrapperElement.style.width=100*t+100+`%`,this.fillAnimationFillerWrapperElement.style[`${this.fromLeft?`left`:`right`}`]=`calc((${t} * 100%) / 2 * -1)`),this.widthExpansionCoef=t}updateAnimation(e){if((e=>e<this.startTime||e>this.endTime)(e))return;let t=this.endTime-this.startTime,n=Math.min(Math.max((e-this.startTime)/t,0),1);this.shouldFillHeight?this.fillAnimationFillerElement.style.transform=`scaleY(${n})`:this.fillAnimationFillerElement.style.transform=`scaleX(${n})`}calcWidthExpansionCoef({rotateAngle:e,isSkewed:t=!1,initWidth:n,initHeight:r}){return t?(n+r*Math.abs(Math.tan(e)))/n-1:0}}var tr=(e,t)=>{if(e.type.trim().toLowerCase()===`button`)return new nr(e,t)};class nr extends U{startTime;endTime;controlFillAnimation;constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let n=document.createElement(`button`);n.type=`button`,n.classList.add(z.common,z.button),n.setAttribute(`data-testid`,`int_bttn`),$t({target:n,layoutParams:this.control.layoutParams,fallback:F}),Xt({target:n,props:this.control.props,fallback:F}),Zt({target:n,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),Jt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=Vn(this.control.type.trim().toLowerCase());Yt({target:r.firstElementChild??r,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),this.addControlTap(n),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled(`controlsFillAnimation`)&&(this.controlFillAnimation=new er({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??F.angle,borderRadius:n.style.borderRadius})),this.subscriptions.add(K(n,`click`).pipe(Bn()).subscribe(this.onControlSelect,e=>this.onError(`Control click handler error`,e))),n.append(r,this.controlFillAnimation?.fillAnimationElement??``),this.container.element.append(this.controlTap?.element??``,n),e.append(this.container.element),this.controlElement=n,this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled(`controlsExpectTimeBlinkAnimation`))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(K(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(G.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${W.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(K(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(G.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(K(this.controlElement,`mouseleave`).subscribe(()=>{this.controlElement&&(this.controlElement.style.animation=``)},e=>this.onError(`Error happened in mouseleave callback`,e))))}disable(){this.controlElement&&this.controlElement.classList.add(z.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(z.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(z.blinkAnim,e),this.controlElement?.classList.toggle(z.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${z.blinkAnimButton}`)||this.controlElement.classList.contains(z.selected)||this.controlElement.classList.contains(W.disabled)||(this.controlElement.classList.add(W.disabled),this.subscriptions.add(K(e,`animationiteration`).pipe(Bn()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(W.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${z.blinkAnimButton}`)||this.controlElement.classList.contains(z.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue(`--interactive-button-hover-opacity`).trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation=`none`,requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}updateFillAnimationDimensions(){if(!this.container||!this.controlElement||!this.controlFillAnimation)return;let e=getComputedStyle(this.controlElement),t={width:parseFloat(e.width),height:parseFloat(e.height),borderWidth:parseFloat(e.borderWidth)||0};this.controlFillAnimation.updateDimension(t)}setShowTimeRange(e,t){this.startTime=e,this.endTime=t}onProgress(e){this.controlFillAnimation?.updateAnimation(e)}onResize(){this.updateFillAnimationDimensions()}updateShadowStyles(){}}var rr=(e,t)=>{if(e.type.trim().toLowerCase()===`text`)return new ir(e,t)};class ir extends U{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let n=document.createElement(`div`);n.classList.add(z.common,z.text),n.setAttribute(`data-testid`,`int_text`),$t({target:n,layoutParams:this.control.layoutParams,fallback:F}),Jt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=Vn(this.control.type.trim().toLowerCase());Yt({target:r.firstElementChild??r,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}updateShadowStyles(){}toggleBlinkAnimation(){}setShowTimeRange(){}updateFillAnimationDimensions(){}}var ar=(e,t,n,r)=>{if(e.type.trim().toLowerCase()===`choice`)return new or(e,t,n,r)};class or extends Nt{rootElement;containerElement=null;layout;subscriptions=new Dt;isRemoved;isDisabled;willRemoved;cssVarsManager;constructor(e,t,n,r){super(e,n,r),this.rootElement=t,this.layout=new kt(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory(`button`,tr),this.addControlFactory(`text`,rr),this.addControlFactory(`area`,Rn)}createView({eventCallback:e,videoDurationMs:t}){let n=document.createElement(`div`);return n.classList.add(G.common,G.disabled),n.setAttribute(`data-subjectId`,this.container.id),requestAnimationFrame(()=>{n.classList.remove(G.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(r=>{r.setShowTimeRange(this.container.startTime,this.container.endTime??t),r.setCssVarsManager(this.cssVarsManager),r.createView({parentElement:n,callbacks:{setControlLayout:(e,t)=>this.layout.setControlLayout(e,t),isContainerDisabled:()=>this.isDisabled}}),r.setEvents(e),this.subscriptions.add(r.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.willRemoved=!1,this.containerElement=n,this.updateControlsFillAnimationDimensions(),n}updateControlsFillAnimationDimensions(){for(let e of this.controls)e.updateFillAnimationDimensions()}hide(){let e=this.getElement();e&&e.classList.add(G.hidden)}show(){let e=this.getElement();e&&e.classList.remove(G.hidden)}enable(){let e=this.getElement();e&&(e.classList.remove(G.disabled),this.controls.forEach(e=>e.enable()),this.isDisabled=!1)}disable(){let e=this.getElement();e&&(e.classList.add(G.disabled),this.controls.forEach(e=>e.disable()),this.isDisabled=!0)}removeView(e=!1,t=!1){let n=this.getElement();if(n){if(e){if(this.willRemoved)return;this.willRemoved=!0,t&&n.classList.add(`interactive-container-before-remove-delay`),n.classList.add(`interactive-container-before-remove`),this.subscriptions.add(Et(n,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${or.name} remove view transition error`,e))).add(Et(n,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${or.name} remove view transition error`,e)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()};removeAllControls(e=!1){this.controls.forEach(t=>t.removeView(e))}removeNonInteractedControls(e=!1){this.controls.forEach(t=>{t.isInteracted||t.removeView(e)})}isInteracted(){return this.controls.some(e=>e.isInteracted)}fakeRemove(){this.isRemoved||=!0}getElement(){return this.containerElement}onProgress(e,t){t&&this.controls.forEach(t=>{t.onProgress(e)})}onResize(e){e&&this.controls.forEach(e=>{e.onResize()})}updateControlsShadowStyles(e){this.controls.forEach(t=>t.updateShadowStyles(e))}toggleBlinkAnimation(e){this.controls.forEach(t=>t.toggleBlinkAnimation(e))}}var sr=c(Ue(),1),cr=c(Xe(),1),lr=(e,t)=>typeof e==`string`?cr.default(e,t):sr.default(e,t);import{combine as ur,InterfaceLanguage as dr,Observable as fr,once as pr,Subject as Y,Subscription as mr,ValueSubject as X,fromEvent as hr}from"@vkontakte/videoplayer-shared/es2024";import{InteractiveInterfaceClick as gr}from"@vkontakte/videoplayer-statistics/es2024";import{loadVKLangPack as _r}from"@vkontakte/videoplayer-shared/es2024";function vr(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}var yr=`video_interactive`,br=`videoint`,xr=250;class Sr{isHidden;currentManifestId;currentChapterId;visitedChapterIds;onOpenPreviewClick;onError;lang;zoom;lastZoomInfo;isReady;ngEditor;ngEditorSize;graphWrapperElement;resizeObserver;manifest;constructor(e){this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:i=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(i),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??`ru`,this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Cr(e),this.resizeObserver=new ResizeObserver(vr(this.onResize,xr)),this.resizeObserver.observe(this.graphWrapperElement)}handleZoomChange=vr(e=>{this.lastZoomInfo=e},xr);onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};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]}handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.(`Chapter id is not found`);return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!Rt(e.graph.edit.chapters[0].x)){this.onError?.(`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.setVisitedChapters(Array.from(t)):(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id),this.isReady=!0)};setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display=`block`,!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await _r(this.lang,yr,br)}catch{this.onError?.(`Unable to load graph language pack`)}let{GraphEditor:t}=await import(`@interactiveplatform/movika-graph-editor`);this.ngEditor=new t(this.graphWrapperElement,{mode:`view`,lang:this.lang===`ru`?`ru`:`en`,translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on(`control`,({name:e,...t})=>{e===`openPreview`&&`chapterId`in t&&this.onOpenPreviewClick?.(t.chapterId)}),this.ngEditor.on(`zoom`,this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display=`none`,this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function Cr(e){let t=document.createElement(`div`);return t.style.position=`absolute`,t.style.top=`0`,t.style.left=`0`,t.style.height=`100%`,t.style.width=`100%`,t.style.display=`none`,e.append(t),t}var wr=3e3;class Tr{_containers=[];_player=null;setPlayer=e=>{this._player=e};setContainers=e=>{this._containers=e};deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};getNextInteractiveTime=(e=wr)=>{if(!this._containers.length||this._player===null)return null;let t=-1,n=!1,r=Math.round(this._player.info.position$.getValue()*1e3);for(let i of this._containers){let a=i.startTime-e;if(a<=r&&(i.endTime&&r<=i.endTime||i.endTime===null)){n=!0;break}r<a&&(t=t===-1?a:Math.min(t,a))}return!n&&t!==-1?t:null}}class Er{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 n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let n=this.listeners[e]||[];for(let e=n.length;e>0;e--)if(n[e]===t){n.splice(e,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(e=>{e(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}}class Dr{raf;fn;fns=[];constructor(e){e&&(this.fn=e,this.addFn(e))}addFn=(e,t=!1)=>{zt(e)&&(this.fns.push(e),t&&this.updateFn())};removeFn=(e,t=!1)=>{this.fns=this.fns.filter(t=>t!==e),t&&this.updateFn()};updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};requestAnimation=()=>{this.raf||this.forceRequestAnimation()};cancelAnimation=()=>{this.raf&&=(cancelAnimationFrame(this.raf),void 0)};release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}var Or=c(ct(),1);class kr{rootElement;isCssVarsSupported;rootElementProps={};constructor(e){this.rootElement=e,this.isCssVarsSupported=kr.checkCssVarsSupport(e)}static checkCssVarsSupport(e){let t=`--test-key`,n=`test`;e.style.setProperty(t,n);let r=e.style.getPropertyValue(t)===n;return r&&e.style.removeProperty(t),r}getPropValue(e){return this.isCssVarsSupported?`var(${e})`:this.rootElementProps[e]??``}setup(e){if(this.rootElementProps={...this.rootElementProps,...e},this.isCssVarsSupported)for(let[t,n]of Or.default(e))this.rootElement.style.setProperty(t,n)}cleanup(){for(let e in this.rootElementProps)this.rootElement.style.removeProperty(e);this.rootElementProps={}}setProp(e,t){this.rootElementProps[e]=t,this.isCssVarsSupported&&this.rootElement.style.setProperty(e,t)}}import{ValueSubject as Ar}from"@vkontakte/videoplayer-shared/es2024";class jr{loaders;constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return Mr(...this.loaders[e])(t)}}function Mr(...e){return async function(t){let n=[...e];for(;n.length>0;)t=await n.shift()(t);return t}}function Nr(e,t,n){return e?{...e,[t]:e[t]?[n,...e[t]]:[n]}:{[t]:[n]}}function Pr({actions:e,errors:t,chapterId:n,...r}){if(n){let i=e.getManifest();if(i){let a=e.getChapter(i.chapters,n);if(a){let n=e.getMedia(i.media,a.videoId),o=e.getGraph(i.graph,a.id);return n?{...r,actions:e,errors:t,result:{chapter:a,media:n,graph:o}}:{...r,errors:Nr(t,Pr.name,`Could not find media`),actions:e}}}}return{...r,errors:Nr(t,Pr.name,`Could not find chapter`),actions:e}}var{NativeAbortSignal:Fr,NativeAbortController:Ir}=function(e){return{NativeAbortSignal:e.AbortSignal,NativeAbortController:e.AbortController}}(typeof self<`u`?self:global);function Lr(e){let t;try{t=new Event(`abort`)}catch{typeof document<`u`?document.createEvent?(t=document.createEvent(`Event`),t.initEvent(`abort`,!1,!1)):(t=document.createEventObject(),t.type=`abort`):t={type:`abort`,bubbles:!1,cancelable:!1}}return t.reason=e,t}function Rr(e){if(e===void 0)if(typeof document>`u`)e=Error(`This operation was aborted`),e.name=`AbortError`;else try{e=new DOMException(`signal is aborted without reason`),Object.defineProperty(e,`name`,{value:`AbortError`})}catch{e=Error(`This operation was aborted`),e.name=`AbortError`}return e}class zr{constructor(){Object.defineProperty(this,`listeners`,{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;let n=this.listeners[e];for(let e=0,r=n.length;e<r;e++)if(n[e].callback===t){n.splice(e,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let t=this.listeners[e.type].slice();for(let n=0,r=t.length;n<r;n++){let r=t[n];try{r.callback.call(this,e)}catch(e){Promise.resolve().then(()=>{throw e})}r.options&&r.options.once&&this.removeEventListener(e.type,r.callback)}return!e.defaultPrevented}}class Br extends zr{constructor(){super(),this.listeners||zr.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)}throwIfAborted(){let{aborted:e,reason:t=`Aborted`}=this;if(e)throw t}static timeout(e){let t=new Vr;return setTimeout(()=>t.abort(new DOMException(`This signal is timeout in ${e}ms`,`TimeoutError`)),e),t.signal}static any(e){let t=new Vr;function n(){t.abort(this.reason),r()}function r(){for(let t of e)t.removeEventListener(`abort`,n)}for(let r of e)if(r.aborted){t.abort(r.reason);break}else r.addEventListener(`abort`,n);return t.signal}}class Vr{constructor(){Object.defineProperty(this,`signal`,{value:new Br,writable:!0,configurable:!0})}abort(e){let t=Rr(e),n=Lr(t);this.signal.reason=t,this.signal.dispatchEvent(n)}toString(){return`[object AbortController]`}}typeof Symbol<`u`&&Symbol.toStringTag&&(Vr.prototype[Symbol.toStringTag]=`AbortController`,Br.prototype[Symbol.toStringTag]=`AbortSignal`);function Hr(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log(`__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill`),!0):typeof e.Request==`function`&&!e.Request.prototype.hasOwnProperty(`signal`)||!e.AbortController}function Ur(e){typeof e==`function`&&(e={fetch:e});let{fetch:t,Request:n=t.Request,AbortController:r,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=e;if(!Hr({fetch:t,Request:n,AbortController:r,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:t,Request:a};let a=n;(a&&!a.prototype.hasOwnProperty(`signal`)||i)&&(a=function(e,t){let r;t&&t.signal&&(r=t.signal,delete t.signal);let i=new n(e,t);return r&&Object.defineProperty(i,`signal`,{writable:!1,enumerable:!1,configurable:!0,value:r}),i},a.prototype=n.prototype);let o=t;return{fetch:(e,t)=>{let n=a&&a.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(n){let r;try{r=new DOMException(`Aborted`,`AbortError`)}catch{r=Error(`Aborted`),r.name=`AbortError`}if(n.aborted)return Promise.reject(r);let i=new Promise((e,t)=>{n.addEventListener(`abort`,()=>t(r),{once:!0})});return t&&t.signal&&delete t.signal,Promise.race([i,o(e,t)])}return o(e,t)},Request:a}}var Z=typeof globalThis==`object`&&globalThis||typeof window==`object`&&window,Wr=`fetch`in Z&&Hr({fetch:Z.fetch,Request:Z.Request,AbortController:Z.AbortController}),Gr=Wr?Ur({fetch:Z.fetch,Request:Z.Request,AbortController:Z.AbortController}):void 0,Kr=Wr?Gr.fetch:Z.fetch;Wr?Gr.Request:Z.Request,Wr||Z.AbortController,Wr||Z.AbortSignal;var qr=(e=``,t=``)=>{let n=e.split(`.`),r=t.split(`.`),i=0;for(let e=0;e<Math.max(n.length,r.length)&&!i;e++)i=n[e]>r[e]?1:n[e]<r[e]?-1:0;return i},Jr=async e=>{try{let t={},n;if(It(e)){n=new URL(e).href;let r=await Kr(n);if(!r.ok)return{};t=await r.json()}else if(Ft(e))t=e;else return{};if(!gn(t))return{};let r=t.metadata.media;if(It(r)&&!(`media`in t))try{let e;n?e=new URL(r,n).href:(e=new URL(r).href,n=e);let i=await Kr(e);if(!i.ok)throw Error();t.metadata.media=await i.json()}catch{return ti(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:n}}catch{return{}}};async function Yr(e){let{manifest:t,manifestURL:n}=await Jr(e);if(!t)throw Error(`Failed on fetch`);let r=mn(t);return r.media=$r(r.media,n),delete r.metadata.media,r}function Xr(e,t){if(t)return e.find(e=>e.id===t)}function Zr(e,t){if(e.edit?.chapters)return e.edit.chapters.find(e=>e.id===t);if(e.view?.chapters)return e.view.chapters.find(e=>e.id===t)}function Qr(e,t){return e.videos.find(e=>e.id===t)}function $r(e,t){return{...e,videos:e.videos.map(e=>({...e,variants:e.variants.map(e=>{let n=`url`in e?e.url:``,r=ei(n,t);return{...e,url:r||n}})}))}}function ei(e=``,t){try{return new URL(e,t).href}catch{return``}}function ti(e){return qr(e,`3.2.0`)>=0}class ni extends jr{manifest=null;chapter=null;media=null;graph=null;prevChapter$=new Ar(null);onError;constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(e){this.release();let t=await this.exec(`manifestLoaders`,{actions:{addErrorMessage:Nr},result:null,errors:null,source:e});return t.errors&&this.errorHandler(t.errors),this.manifest=await Yr(t.result??e),this}async setInitial(){return this.setNext()}async setNext(e=this.manifest?.metadata.initChapterId){if(!e)return this;this.prevChapter$.next(this.chapter);let t=await this.exec(`chapterLoaders`,Pr({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Zr,getChapter:Xr,getMedia:Qr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Nr},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),t.result&&(this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.result.graph),this}errorHandler(e){this.onError(e),console.error(`Something went wrong with loaders`,{errors:e})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(e=this.manifest?.metadata.initChapterId){if(!e||!this.manifest)return null;let t=Xr(this.manifest.chapters,e);if(t){let e=Qr(this.manifest.media,t.videoId),n=Zr(this.manifest.graph,t.id);if(e)return{chapter:t,media:e,graph:n}}return null}getBranches(e=this.chapter?.id){if(e===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let t=Xr(this.manifest?.chapters||[],e);return this.getByBranches(t?.branches)}}getByBranches(e=[]){return e.reduce((e,t)=>{let n=this.getByChapterId(t.chapterId);return n&&e.push(n),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?V(this.chapter):!1}}var ri=c(ft(),1);import{Player as ii}from"@vkontakte/videoplayer-core/es2024";import{Subscription as ai,TracerFactory as oi,ValueSubject as si}from"@vkontakte/videoplayer-shared/es2024";var ci=e=>{let t=e.variants.find(e=>e.payload?.type===`vk`);if(t&&t.payload){let[e,n]=t.payload.id.split(`_`);return[e,n]}return[]},li=c(ft(),1);function ui(){let e=new Map;function t({listId:t=Math.random().toString(),itemId:n=Math.random().toString(),...r}){let i=e.get(t),a={...r};return i?i[n]=a:e.set(t,{[n]:a}),{listId:t,itemId:n,...r}}function n(e){e.player.destroy(),e.container.remove(),e.subscription.unsubscribe(),e.statistics?.oneStat.destroy(),e.statistics?.statSubscription.unsubscribe()}function r(t,r){let i=e.get(t);if(!i)throw Error(`Can't remove. Not find.`);if(r){let a=i[r];a&&n(a),delete i[r],Object.keys(i).length||e.delete(t)}else{for(let e of li.default(i))n(e);e.delete(t)}}function i(){for(let t of e)r(t[0])}return{createPlayer:t,removePlayer:r,map:e,removeAll:i}}var di=c(ze(),1),fi=c(ze(),1),pi=(e,...t)=>typeof e==`string`?e.includes(...t):fi.default(e,...t);function mi(e,t=[]){let n={},r,i=!t.length;for(let a of e.variants)if(!r&&`cover`in a&&(r=a.cover),`url`in a)switch(a.type.toLowerCase()){case`mp4`:(i||di.default(t,`mp4`))&&(n.MPEG={...n.MPEG,[a.standard??`Invariant quality`]:a.url});break;case`mpeg`:(i||di.default(t,`mpeg`))&&(n.MPEG={...n.MPEG,[a.standard??`Invariant quality`]:a.url});break;case`hls`:(i||di.default(t,`hls`))&&(n={...n,HLS:{type:`url`,url:a.url}});break;case`dash`:(i||di.default(t,`dash`))&&(n={...n,DASH_SEP:{compatibilityMode:!0,type:`url`,url:a.url}});break;default:break}return{sources:n,thumbUrl:r,title:e.title??``}}var hi=(e,t)=>{let n=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();n!==t&&pi(r,t)&&(e.setQuality(t),e.setAutoQuality(!1))},gi=2;function _i(e){let t=ui(),n=new ai,r={},i=null,a=!1,o,s=new si(null);e&&c(e);function c(e){i=e}function l(e,n,o){if(!i)throw Error(`need to set interactive controller`);if(!i.options)return;let c=(t.map.get(e)??{})[n];if(c){r={chapterId:o,listId:e,itemId:n,...c};let l=r.player;r.subscription.add(l.info.currentQuality$.subscribe(e=>{let n=l.info.position$.getValue(),r=l.info.isAutoQualityEnabled$.getValue();if(!(!e||!n||r))for(let n of t.map)ri.default(n[1]).forEach(({player:t})=>{hi(t,e)})})).add(l.events.started$.subscribe(()=>{u(n)})),c.container.remove(),i.setPlayer(c.player),a||=(i.init(),!0),s.next({player:r.player,config:r.config,statistics:r.statistics});return}throw Error(`Can't set. Not find.`)}async function u(e){if(!i)throw Error(`need to set interactive controller`);if(P(r)||e!==r.itemId)return;let t=i.getChapterBranches(),n=new Set;for(let e of t)n.has(e.media.id)||(await f({media:e.media,chapterId:e.chapter.id,setAsActive:!1,title:e.chapter.label}),n.add(e.media.id))}async function d({chapter:{id:e},manifestVideo:n}){if(P(r)||!i)return;let a=r.player.info.muted$.getValue(),o=r.player.info.currentQuality$.getValue(),s=r.player.info.isAutoQualityEnabled$.getValue(),c=r.player.info.volume$.getValue(),u=r.player.info.currentPlaybackRate$.getValue(),d=!s,p=!1;for(let s of t.map)if(s[0]===n.id&&!i.state.isReplay$.getValue()){let n=Object.keys(s[1]);for(let i of n)i===r.itemId?(n.length<gi||(p=!0),t.removePlayer(s[0],i)):(p=!0,l(s[0],i,e),d?hi(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a),r.player.setPlaybackRate(u))}else t.removePlayer(s[0]);p||(await f({media:n,chapterId:e,setAsActive:!0,playbackRate:u}),d?hi(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a))}async function f({media:e,chapterId:n,prefetch:a=!0,setAsActive:s=!0,autoplay:c=!1,preferredExt:u,title:d,playbackRate:f}){let p=Math.random().toString(),m=document.createElement(`div`);o.append(m);let h;if(i?.options?.vkVideoLoader){let t=ci(e);t.length&&(h=await i.options.vkVideoLoader(...t))}let g={...i?.options?.coreConfig||void 0},_={container:m,sources:mi(e,u).sources,...h?.videos?.[0],title:d,failoverHosts:h?.failoverHosts||[]},v=new ii(g,oi.createRootTracer());v.initVideo(_);let y=null;if(h?.videos&&i?.options.createOneStat){let e=h.videos[0],t=i.options.createOneStat(e),n=new ai;t&&(n.add(t.attachTo(v)),y={oneStat:t,statSubscription:n})}let b=new ai,x=r?.player?.info.isAutoQualityEnabled$.getValue();b.add(v.events.canplay$.subscribe(function(){x||hi(v,r.player.info.currentQuality$.getValue()),f&&v.setPlaybackRate(f)}));let S=t.createPlayer({listId:e.id,itemId:p,player:v,container:m,sources:mi(e,u).sources,config:_,subscription:b,statistics:y});return s&&l(e.id,S.itemId,n),c&&S.player.play(),a&&!c&&S.player.prepare(),{player:S.player,config:S.config,statistics:S.statistics}}function p(){m(),i=null,o.remove()}function m(){n.unsubscribe(),t.removeAll(),r={},a=!1}async function h(){if(!i)throw Error(`need to set interactive controller`);m(),o=document.createElement(`div`);let{media:e,chapter:t}=i.getCurrentChapter();e&&t?(n.add(i.events.chapterChanged$.subscribe(d)),await f({media:e,chapterId:t.id,title:t.label})):console.error(`not found`)}return{map:t.map,removePlayer:t.removePlayer,init:h,setInteractiveController:c,createPlayer:f,removeAll:p,getActivePlayer:function(){return r},activePlayerChanged:s}}var Q={graph:`graph`,interactives:`interactives`,chapterChanged:`chapter-changed`,playerChanged:`player-changed`,manifestChanged:`manifest-changed`,errors:`errors`,eachTick:`eachTick`,historyInited:`history-inited`,historyDestroyed:`history-destroyed`},vi={visibility:`visibility`,watchAgainClicked:`watchAgainClicked`},$={actionChoiceCanceled:`action-choice-canceled`,actionChoice:`action-choice`,actionExecution:`action-execution`,visibility:`visibility`,containerRemoved:`container-removed`,rangeEnded:`range-ended`};import{Subscription as yi}from"@vkontakte/videoplayer-shared/es2024";function bi(e){return function(...t){return e(...t.reverse())}}function xi(e,...t){return(...n)=>Ft(t[0])&&Ft(n[0])?e({...t[0],...n[0]}):e(...t,...n)}class Si{container;branches;selectBranches;subscription;player;interactiveEvents;getContainerEventState;isPermanentText;interactiveTimeOpenUri;disabledControls$;onRemove;globalEventEmitter;gameState;isSelectedControlEvent;isSelectedContainerEvent;globalEvents;onError;disableTextControlContainerVisibilityEvents;features;constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:i,globalEvents:a,globalEventEmitter:o,getContainerEventState:s,permanentTextControls:c,interactiveTimeOpenUri:l,disabledControls$:u,onRemove:d,onError:f,disableTextControlContainerVisibilityEvents:p=!1,features:m}){this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new yi,this.player=e,this.interactiveEvents=i,this.getContainerEventState=s;let h=An(t.container.controls);this.isPermanentText=c&&h,this.disableTextControlContainerVisibilityEvents=p&&h,this.interactiveTimeOpenUri=l,this.disabledControls$=u,this.onRemove=d,this.globalEventEmitter=o,this.gameState=0,this.globalEvents=a,this.onError=f,this.features=m,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(Q.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:$.visibility,visibility:e,isFirst:t}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:`container`,type:`visibility`,visibility:e,isFirst:t})):(this.globalEventEmitter.emit(Q.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:$.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:`container`,type:`visibility`,visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()})),this.subscription.add(this.container.error$.subscribe(this.onError))}hide=()=>{setTimeout(()=>{this.gameState!==4&&(H(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};show=()=>{if(!(this.gameState!==2||this.isSelectedControlEvent))if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:e}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&e||this.disableTextControlContainerVisibilityEvents)return;this.emitContainerVisibilityEvent(!0,!1)}else{let e={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(e,t)=>{let{isExpectTime:n,hasOtherExpect:r,hasOpenURIEvent:i,hasOpenURIEventInCurrentContainer:a,isAllOpenURIEventsValid:o,hasShouldOpenNowEvent:s}=this.getContainerEventState(),c=this.interactiveTimeOpenUri&&!a,l=this.interactiveTimeOpenUri&&a;if((!this.interactiveTimeOpenUri||c)&&(this.isSelectedControlEvent=!0),e!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||c)){if(this.interactiveTimeOpenUri){let e=!r&&!o&&a;e&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-fake-removed`,removeAllOpenURI:e})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&i&&this.gameState!==5){if(l){let e=((e,t,n,r)=>!e&&!t&&n||e&&!t&&n&&!r||e&&!t&&n&&r)(n,r,o,this.isSelectedContainerEvent);this.fakeRemoveView(e)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!n||!r||!s)&&(this.selectBranches.stopExpect(),t())}},isEOV:()=>this.gameState===4},t=xi(this.selectBranches.onControlEvent,e),n=(this.player?.info.duration$.getValue()??1/0)*1e3;this.container.createView({eventCallback:t,videoDurationMs:n}),this.disableTextControlContainerVisibilityEvents||this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:H(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),t=e instanceof HTMLVideoElement;if(this.features.enableAvPlayerSupport&&(t||=e instanceof HTMLObjectElement&&e?.getAttribute(`type`)===`application/avplayer`),!(t&&e?.readyState)||this.isRemovedOrDestroyed()&&!this.isPermanentText)return;let n=this.player.getExactTime();if(En(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Dn(n,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let e=this.gameState;this.gameState=3,e===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:e}=this.getContainerEventState(),t=this.selectBranches.state.isExpect,n=this.interactiveTimeOpenUri&&e;if(n&&!t){let e=this.container.getElement();e&&(e.style.visibility!==`hidden`&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!n&&this.removeView()}let r=Dn(n,this.container.container),i=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],a={subjectId:this.container.container.id,subjectName:`container`,range:i,currentTime:n,isInteractiveTime:r};this.container.onProgress(n*1e3,r),this.globalEventEmitter.emit(Q.eachTick,a),this.globalEvents.eachTick$.next(a)};onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(e=this.features.controlsHideAnimation){if(e){if(this.isRemovedOrDestroyed())return;this.container.removeNonInteractedControls(!0),this.container.removeView(!0,!0)}else this.container.removeView();this.globalEventEmitter.emit(Q.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:$.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-removed`}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-fake-removed`,removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}isInteracted(){return this.container.isInteracted()}isRemovedOrDestroyed(e=!0){let t=e?this.container.willRemoved:!1;return this.gameState===5||t||this.gameState===6}destroy(e=!1){this.reset(),this.removeView(e),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}}var Ci=(e=[])=>e.reduce((e,t,n)=>{if(wn((t?.controls??[]).filter(e=>!_n(e)))){let r=[t.startTime??0,t.endTime??1/0],i={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[i],range:r});else{let t=[],n=-1/0,a=1/0,o=[],s=[];for(let c=0;c<e.length;c++){let l=e[c];if(s.push(...l.subjects),l.range[0]<a&&(a=l.range[0]),l.range[1]>n&&(n=l.range[1]),r[0]>=l.range[0]&&r[1]<=l.range[1])return e[c].subjects.push(i),e;r[0]<l.range[0]&&r[1]>l.range[0]&&(t.push(c),o=o.concat(l.subjects)),r[0]>=l.range[0]&&r[0]<=l.range[1]&&(t.push(c),o=o.concat(l.subjects),r[0]=l.range[0]),r[1]>=l.range[0]&&r[1]<=l.range[1]&&(t.push(c),o=o.concat(l.subjects),r[1]=l.range[1])}if(s.push(i),r[0]<=a&&r[1]>=n)return[{subjects:s,range:r}];t.length&&t.reverse().forEach(t=>{e.splice(t,1)}),e.push({subjects:o.concat([i]),range:r})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),wi=c(ze(),1),Ti=c(ft(),1),Ei=c(wt(),1);function Di(){let e={};function t(){for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&delete e[t]}function n(t){let n={};for(let r in e)+r<=t&&(n[r]=e[r]);return n}function r(t){let n={};for(let r in e)+r>=t&&(n[r]=e[r]);return n}function i({timestamp:t,priority:n,initiator:r}){if(Vt(t)){let i=e[t]??null;if(i&&n&&Ut(n,!0)){let e={},t=i[n];return t&&(e={...e,...t}),e=P(e)?null:e,e&&Ut(r,!0)?e[r]??null:e}return i}return null}function a({timestamp:t,priority:n,initiator:r}){if(Vt(t))if(e[t]){if(n&&Ut(n,!0))if(e[t][n]){if(r&&Ut(r,!0))if(e[t][n][r]){if(delete e[t][n][r],!P(e[t][n]))return!0}else return!1;if(delete e[t][n],!P(e[t]))return!0}else return!1;return delete e[t]}else return!1;return!1}function o({timestamp:t,priority:n,initiator:r,...i}){e[t]?.[n]?.[r]?e[t][n][r].push({...i}):e[t]?.[n]?e[t][n]={...e[t][n],[r]:[{...i}]}:e[t]?e[t]={...e[t],[n]:{[r]:[{...i}]}}:e[t]={[n]:{[r]:[{...i}]}}}return{map:e,remove:a,add:o,removeAll:t,get:i,getLte:n,getGte:r}}var Oi=[B.expect,B.setNextBranch],ki=1/0;function Ai(e,t){let n=e,r,i=ji(t),a=Di(),o,s=()=>{p(),_()},c=e=>{a.add.call(void 0,e),m()},l=(e=[])=>{for(let t of e)if(t.action(),wi.default(Oi,t.actionType))break},u=(e=1/0)=>{let t=Mi(a.get({timestamp:e,priority:`control`})??{}),n=Mi(a.get({timestamp:e,priority:`container`})??{}),r=Mi(a.get({timestamp:e,priority:`chapter`})??{});return[...t,...n,...r]},d=e=>{i.isReady(e)&&l(u(e))},f=()=>{l([...Mi(a.get({timestamp:1/0,priority:`chapter`})??{})])},p=()=>{r&&=(o?.unsubscribe(),void 0)},m=()=>{r||(r=()=>setTimeout(()=>{d(1/0)}),o=n.events.ended$.subscribe(r))},h=e=>{p(),n=e},g=e=>{e.priority===`container`&&i.resetCalled(e.timestamp),a.remove(e)},_=()=>{i.release(),a.removeAll()};return{setPlayer:h,add:c,remove:g,exec:d,execEndOfVideo:f,listen:m,unlisten:p,release:s,containersEventsCallState:i,getPreparedToExecActions:u}}function ji(e){let t=new Map;return{setCalled:({timestamp:e,id:n})=>{let r=t.get(e);r&&r[n]!==void 0&&(r[n]=!0)},setData:(e=[])=>{for(let n of e){let e=n.endTime??ki,r=t.get(e);t.set(e,{...r,[n.id]:!1})}},resetCalled:e=>{let n=t.get(e);if(n)for(let e in n)n[e]=!1},isReady:n=>{let r=t.get(n);if(!r)return!0;let i=Ti.default(r);return e?i.some(e=>e):!i.some(e=>!e)},release:()=>t.clear()}}function Mi(e){return Ei.default(Ti.default(e)).sort(e=>e.actionType===B.expect?-1:1)}var Ni={videoContentHeight:0,videoContentWidth:0},Pi=e=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return Ni;let{clientHeight:r,clientWidth:i}=e.experimental.element$.getValue()||{};if(!(r&&i))return Ni;let a=t/n,o=r/i,s,c;return o>a?(c=i,s=i*a):o<a?(c=r/a,s=r):(c=i,s=r),{videoContentWidth:c,videoContentHeight:s}},Fi=250;function Ii(e){let t,n=new ResizeObserver(e=>{a(e),t=a.bind(null,e)});function r(t){let{parentElement:n,player:r,cssVarsManager:i}=e();if(!n||!r)return;let{videoContentWidth:a,videoContentHeight:o}=Pi(r);i.setup({"--interactive-content-width":`${a}px`,"--interactive-content-height":`${o}px`,"--interactive-width":`${t[0].contentRect.width}px`,"--interactive-height":`${t[0].contentRect.height}px`})}function i(){let{parentElement:t}=e();t.removeAttribute(`style`)}let a=vr(t=>{let{fns:n=[]}=e();r(t);for(let e of n)e()},Fi);function o(){t=void 0,n.disconnect(),i()}return{resizeObserver:n,calc:()=>{t?.()},release:o}}var Li=e=>Math.floor(Math.random()*e),Ri=e=>{let t=e.length,n=1/0,r=null;for(;t--;){let i=e[t],a=i.weight??1;a<n&&(n=a,r=i)}return r},zi=e=>{let t=e.length,n=-1/0,r=null;for(;t--;){let i=e[t],a=i.weight??0;a>n&&(n=a,r=i)}return r},Bi=e=>{let t=e.length;return e[Li(t)]},Vi=1,Hi=e=>{let t=0;for(let n=0;n<e.length;++n)t+=e[n].weight??Vi;let n=Math.random()*t;t=0;for(let r=0;r<e.length-1;++r)if(t+=e[r].weight??Vi,t>=n)return e[r];return e[e.length-1]},Ui={shouldOpenNow:!0,isDetachContainer:!0},Wi=`after-expect`,Gi=(e,t=!1)=>({...e,args:t?{...e.args,...Ui}:{...Ui,...e.args}}),Ki=({globalEventEmitter:e,globalEvents:t,player:n,interactiveEvents:r})=>{let i={isExpect:!1},a=()=>{i.isExpect&&=!1},o=({action:n,controlType:i,controlId:a,containerId:o,branches:s=[],onEvent:c,isEOV:l=()=>!1,isDisabled:d=()=>!1})=>{let f=Gi(n,l()),_={timestamp:1/0,priority:`control`,initiator:a,actionType:f.type},v=d(),y=e.emit.bind(e,Q.interactives,{subjectId:a,subjectType:i,subjectName:`control`,type:v?$.actionChoiceCanceled:$.actionChoice,actionType:n.type,payload:{invokeImmediately:f.args.shouldOpenNow,containerId:o,...f.args}}),b=()=>{t.interactiveActionChoice$.next({subjectId:a,subjectType:i,subjectName:`control`,type:v?`action-choice-canceled`:`action-choice`,actionType:n.type,payload:{invokeImmediately:f.args.shouldOpenNow,containerId:o,...f.args}})};if(v){y(),b();return}switch(f.type.trim().toLowerCase()){case B.setNextBranch.trim().toLowerCase():{let e=s.find(e=>e.id===f.args.branchId);if(!e)return;c(f.args.isDetachContainer,p.bind(null,{subjectId:a,subjectName:`control`})),y(),b(),f.args.shouldOpenNow?h({subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{chapterId:e.chapterId,autoSelect:!1}}):r.add({..._,action:h.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{chapterId:e.chapterId,autoSelect:!1}})});return}case B.continuePlayback.trim().toLowerCase():c(f.args.isDetachContainer,p.bind(null,{subjectId:a,subjectName:`control`})),y(),b(),f.args.shouldOpenNow?m({subjectId:a,subjectName:`control`,subjectType:i,action:n}):r.add({..._,action:m.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:n})});return;case B.openURI.trim().toLowerCase():c(f.args.isDetachContainer,p.bind(null,{subjectId:a,subjectName:`control`})),y(),b(),f.args.shouldOpenNow?g({subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{URI:n.args.uri}}):r.add({..._,action:g.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{URI:n.args.uri}})});return;default:{let e=`Unexpected control event`;u(new j(1,1,{message:e}),e);return}}},s=({action:n,container:{id:i,endTime:a},branches:o=[],isEOV:s=!1,autoSelected:c=!1})=>{let l=Gi(n,s),d={timestamp:!l.args.shouldOpenNow||s?1/0:a??1/0,priority:`container`,initiator:i,actionType:l.type},f=e.emit.bind(e,Q.interactives,{subjectId:i,subjectName:`container`,type:$.actionChoice,actionType:l.type,payload:{invokeImmediately:l.args.shouldOpenNow,...l.args}}),p=()=>{t.interactiveActionChoice$.next({subjectId:i,subjectName:`container`,type:`action-choice`,actionType:l.type,payload:{invokeImmediately:l.args.shouldOpenNow,...l.args}})};switch(l.type.trim().toLowerCase()){case B.setNextBranch.trim().toLowerCase():{let e=o.find(e=>e.id===l.args.branchId);if(!e)return;f(),p(),r.add({...d,action:h.bind(null,{subjectId:i,subjectName:`container`,action:l,payload:{chapterId:e.chapterId,autoSelect:c}})});return}case B.setMaxWeightBranch.trim().toLowerCase():return;case B.setMinWeightBranch.trim().toLowerCase():return;case B.setRandomBranch.trim().toLowerCase():return;case B.setWeightlessRandomBranch.trim().toLowerCase():return;case B.continuePlayback.trim().toLowerCase():f(),p(),r.add({...d,action:m.bind(null,{subjectId:i,subjectName:`container`,action:l})});return;case B.openURI.trim().toLowerCase():f(),p(),r.add({...d,action:g.bind(null,{subjectId:i,subjectName:`container`,action:l,payload:{URI:n.args.uri}})});return;default:{let e=`Unexpected container event`;u(new j(1,1,{message:e}),e);return}}};function c({container:n,branches:a,isEOV:o=!1}){let c=On(n.events);if(c){let a=Gi(c.action,o);e.emit(Q.interactives,{subjectId:n.id,subjectName:`container`,type:$.actionChoice,actionType:a.type,payload:{invokeImmediately:a.args.shouldOpenNow,...a.args}}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`container`,type:`action-choice`,actionType:a.type,payload:{invokeImmediately:a.args.shouldOpenNow,...a.args}}),r.add({timestamp:o?1/0:n.endTime??1/0,priority:`container`,initiator:n.id,actionType:B.expect,action:f.bind(null,{subjectId:n.id,subjectName:`container`})}),i.isExpect=!0}else for(let e of n.events??[])s({action:e.action,container:n,branches:a,isEOV:o})}let l=({chapterId:n,action:r,branches:i=[]})=>{let a=e.emit.bind(e,Q.interactives,{subjectId:n,subjectName:`chapter`,type:$.actionChoice,actionType:r.type,payload:r.args}),o=()=>{t.interactiveActionChoice$.next({subjectId:n,subjectName:`chapter`,type:`action-choice`,actionType:r.type,payload:r.args})};switch(r.type.trim().toLowerCase()){case B.setNextBranch.trim().toLowerCase():{let e=i.find(e=>e.id===r.args.branchId);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setWeightlessRandomBranch.trim().toLowerCase():{let e=Bi(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setRandomBranch.trim().toLowerCase():{let e=Hi(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setMaxWeightBranch.trim().toLowerCase():{let e=zi(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setMinWeightBranch.trim().toLowerCase():{let e=Ri(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.continuePlayback.trim().toLowerCase():return a(),o(),m.bind(null,{subjectId:n,subjectName:`chapter`,action:r});case B.openURI.trim().toLowerCase():return a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{URI:r.args.uri}});default:{let e=`Unexpected chapter event`;u(new j(1,1,{message:e}),e);return}}};function u(n,r){console.error(r),t.error$.next(n),e.emit(Q.errors,n)}function d(n){let i=On(n.events);if(i){if(V(n))return;e.emit(Q.interactives,{subjectId:n.id,subjectName:`chapter`,type:$.actionChoice,actionType:i.action.type,payload:i.action.args}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`chapter`,type:`action-choice`,actionType:i.action.type,payload:i.action.args}),r.add({timestamp:1/0,priority:`chapter`,initiator:n.id,actionType:B.expect,action:f.bind(null,{subjectId:n.id,subjectName:`chapter`})})}else n.events?.forEach(e=>{let t=l({chapterId:n.id,action:e.action,branches:n.branches});t&&r.add({timestamp:1/0,priority:`chapter`,initiator:n.id,actionType:e.action.type,action:t})})}let f=({subjectId:r,subjectName:i})=>{n.pause(),e.emit(Q.interactives,{subjectId:r,subjectName:i,type:$.actionExecution,actionType:B.expect}),t.interactiveActionExecution$.next({subjectId:r,subjectName:i,type:`action-execution`,actionType:B.expect})},p=({subjectId:i,subjectName:a})=>{n.info.isEnded$.getValue()?r.execEndOfVideo():n.play(),e.emit(Q.interactives,{subjectId:i,subjectName:a,type:$.actionExecution,actionType:Wi}),t.interactiveActionExecution$.next({subjectId:i,subjectName:a,type:`action-execution`,actionType:Wi})},m=({subjectId:n,subjectName:r,subjectType:i,action:a})=>{e.emit(Q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:$.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})},h=({subjectId:n,subjectName:r,subjectType:i,action:a,payload:o})=>{o.behaviour=`change-chapter`,e.emit(Q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:$.actionExecution,actionType:a.type,payload:o}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type,payload:o})},g=({subjectId:n,subjectName:r,subjectType:i,action:a,payload:o})=>{if(!o.URI)return;let s=window.open(o.URI,`_blank`,`noopener,noreferrer`);s&&(s.opener=null),e.emit(Q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:$.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})};return{onControlEvent:o,onContainerEvent:s,onChapterEvent:l,onExpectEvent:f,expectEventHandler:p,setManifestChapterEvents:d,setManifestContainerEvents:c,stopExpect:a,state:i}};import{Subscription as qi,Subject as Ji,ValueSubject as Yi}from"@vkontakte/videoplayer-shared/es2024";var Xi=(e,t)=>{let n={};return e.map(e=>{if(!n[e]){let r=t.chapters.find(t=>t.id===e);if(!r)return null;let i=t.media.videos.find(e=>r.videoId===e.id);if(!i)return null;n[e]=$i(i)}return n[e]}).filter(e=>e!==null)},Zi=e=>{for(let t of e.variants)if(Qi(t)&&t.payload)return t.payload.id},Qi=e=>!!(e.type===`custom`&&e.payload&&e.payload.type===`vk`),$i=e=>{let t=Zi(e);if(!t)return null;let n=t.split(`_`).pop();return n?parseInt(n,10):null},ea=(e,t)=>{for(let n of e.media.videos)if(t===$i(n)){for(let t of e.chapters)if(t.videoId===n.id)return t.id;return}},ta=(e,t)=>e.reduce((e,n)=>{let r=ea(t,n);return r?[...e,r]:e},[]);class na{state={history$:new Yi([]),hasPrevChapter$:new Yi(!1),prevChapter$:new Yi(null),isInitialChapter$:new Yi(!1),isGoBackLimited$:new Yi(!1)};#api=null;#settings;#inited=!1;#manifest=null;#videoIds=null;events={inited$:new Ji,destroyed$:new Ji,error$:new Ji};#rootVid=null;#interactiveController=null;#globalEventEmitter=null;#subscription=new qi;#isGoBackUpdate=!1;#goBackCounter=0;constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:i}){this.#rootVid=t,this.#globalEventEmitter=e,this.#interactiveController=n,this.#api=r,this.#settings=i,this.state.history$&&this.#subscription&&this.#subscription?.add(this.state.history$.subscribe(e=>{this.state.prevChapter$.next(lr(e,-2)||null),this.state.hasPrevChapter$.next(e.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#manifest?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#goBackCounter===this.#settings.maxLength-1)}))}async setManifest(e){if(!this.#interactiveController||!this.#globalEventEmitter)return;this.#manifest=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#interactiveController.setChapter({chapterId:t,pushToHistory:!1}),this.#inited||(this.#inited=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#inited}async updateHistory(e,t=!0){if(!this.#manifest)return;this.#isGoBackUpdate?(this.#isGoBackUpdate=!1,this.#goBackCounter++):this.#goBackCounter=0;let n=this.#manifest,r=e.length-this.#settings.maxLength,i=r>0?e.slice(r):e,a=Xi(i,n);if(this.#videoIds=a,this.state.history$.next(i),!(!t||!this.#api||!this.#rootVid))try{await this.#api.save(this.#rootVid,a)}catch{let e=new j(1,5,`Unable to save interactive history`);this.events.error$.next(e),this.#globalEventEmitter?.emit(Q.errors,e)}}async goBack(){if(!this.state||!this.#interactiveController){let e=new j(1,5,`Unable to save interactive history`);this.events.error$.next(e),this.#globalEventEmitter?.emit(Q.errors,e);return}this.#isGoBackUpdate=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#interactiveController.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#manifest||!this.#rootVid)return;let e=this.#manifest,t=[this.getInitialVideoId()];if(this.#api)try{let e=await this.#api.get(this.#rootVid);e.length&&(t=e)}catch{let e=new j(1,5,`Error while trying to fetch data`);this.events.error$.next(e),this.#globalEventEmitter?.emit(Q.errors,e)}let n=ta(t,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(e==null?void 0:lr(e,-1))||this.#settings.initChapterId||this.#manifest?.metadata.initChapterId}getInitialVideoId(){return this.#manifest?Xi([this.getInitialChapterId()],this.#manifest).pop():null}destroy(){this.#rootVid=null,this.#api=null,this.#interactiveController=null,this.#subscription?.unsubscribe(),this.#subscription=null,this.#inited=!1,this.#globalEventEmitter?.emit(Q.historyDestroyed),this.events.destroyed$.next(),this.#globalEventEmitter=null}}class ra{rootElement;canvasImgSrc;_prevSizeId=0;constructor(){this.rootElement=document.createElement(`canvas`)}clear(){this.rootElement.getContext(`2d`)?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext(`2d`)?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let e=3;e<n;e+=40)if(t[e]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility=`visible`}hide(){this.rootElement.style.visibility=`hidden`}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){this.canvasImgSrc&&this.rootElement.getContext(`2d`)?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL(`image/jpeg`,1),t=new Image;return t.crossOrigin=`anonymous`,t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext(`2d`)?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}}class ia{lastFrameCanvas;endOffsetMs;currentChapter;currentVideoDurationMs=1/0;rootElement;_containerTimeFrameShouldReceived=!1;_endTimeFrameReceived=!1;_shouldCallSkip=!1;_callbacks;constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.rootElement=document.createElement(`div`),this.rootElement.style.cssText=`
6
+ var e=Object.create,t=Object.getPrototypeOf,n=Object.defineProperty,r=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty;function a(e){return this[e]}var o,s,c=(c,l,u)=>{var d=typeof c==`object`&&!!c;if(d){var f=l?o??=new WeakMap:s??=new WeakMap,p=f.get(c);if(p)return p}u=c==null?{}:e(t(c));let m=l||!c||!c.__esModule?n(u,`default`,{value:c,enumerable:!0}):u;for(let e of r(c))i.call(m,e)||n(m,e,{get:a.bind(c,e),enumerable:!0});return d&&f.set(c,m),m},l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=l((e,t)=>{var n=function(e){return e&&e.Math===Math&&e};t.exports=n(typeof globalThis==`object`&&globalThis)||n(typeof window==`object`&&window)||n(typeof self==`object`&&self)||n(typeof global==`object`&&global)||n(typeof e==`object`&&e)||function(){return this}()||Function(`return this`)()}),d=l((e,t)=>{t.exports=function(e){try{return!!e()}catch{return!0}}}),f=l((e,t)=>{t.exports=!d()(function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)})}),p=l((e,t)=>{var n=f(),r=Function.prototype,i=r.apply,a=r.call;t.exports=typeof Reflect==`object`&&Reflect.apply||(n?a.bind(i):function(){return a.apply(i,arguments)})}),m=l((e,t)=>{var n=f(),r=Function.prototype,i=r.call,a=n&&r.bind.bind(i,i);t.exports=n?a:function(e){return function(){return i.apply(e,arguments)}}}),h=l((e,t)=>{var n=m(),r=n({}.toString),i=n(``.slice);t.exports=function(e){return i(r(e),8,-1)}}),g=l((e,t)=>{var n=h(),r=m();t.exports=function(e){if(n(e)===`Function`)return r(e)}}),_=l((e,t)=>{var n=typeof document==`object`&&document.all;t.exports=n===void 0&&n!==void 0?function(e){return typeof e==`function`||e===n}:function(e){return typeof e==`function`}}),v=l((e,t)=>{t.exports=!d()(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7})}),y=l((e,t)=>{var n=f(),r=Function.prototype.call;t.exports=n?r.bind(r):function(){return r.apply(r,arguments)}}),b=l(e=>{var t={}.propertyIsEnumerable,n=Object.getOwnPropertyDescriptor;e.f=n&&!t.call({1:2},1)?function(e){var t=n(this,e);return!!t&&t.enumerable}:t}),x=l((e,t)=>{t.exports=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}}}),S=l((e,t)=>{var n=m(),r=d(),i=h(),a=Object,o=n(``.split);t.exports=r(function(){return!a(`z`).propertyIsEnumerable(0)})?function(e){return i(e)===`String`?o(e,``):a(e)}:a}),C=l((e,t)=>{t.exports=function(e){return e==null}}),w=l((e,t)=>{var n=C(),r=TypeError;t.exports=function(e){if(n(e))throw new r(`Can't call method on `+e);return e}}),T=l((e,t)=>{var n=S(),r=w();t.exports=function(e){return n(r(e))}}),E=l((e,t)=>{var n=_();t.exports=function(e){return typeof e==`object`?e!==null:n(e)}}),D=l((e,t)=>{t.exports={}}),ee=l((e,t)=>{var n=D(),r=u(),i=_(),a=function(e){return i(e)?e:void 0};t.exports=function(e,t){return arguments.length<2?a(n[e])||a(r[e]):n[e]&&n[e][t]||r[e]&&r[e][t]}}),te=l((e,t)=>{t.exports=m()({}.isPrototypeOf)}),ne=l((e,t)=>{var n=u().navigator,r=n&&n.userAgent;t.exports=r?String(r):``}),re=l((e,t)=>{var n=u(),r=ne(),i=n.process,a=n.Deno,o=i&&i.versions||a&&a.version,s=o&&o.v8,c,l;s&&(c=s.split(`.`),l=c[0]>0&&c[0]<4?1:+(c[0]+c[1])),!l&&r&&(c=r.match(/Edge\/(\d+)/),(!c||c[1]>=74)&&(c=r.match(/Chrome\/(\d+)/),c&&(l=+c[1]))),t.exports=l}),ie=l((e,t)=>{var n=re(),r=d(),i=u().String;t.exports=!!Object.getOwnPropertySymbols&&!r(function(){var e=Symbol(`symbol detection`);return!i(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&n&&n<41})}),ae=l((e,t)=>{t.exports=ie()&&!Symbol.sham&&typeof Symbol.iterator==`symbol`}),oe=l((e,t)=>{var n=ee(),r=_(),i=te(),a=ae(),o=Object;t.exports=a?function(e){return typeof e==`symbol`}:function(e){var t=n(`Symbol`);return r(t)&&i(t.prototype,o(e))}}),se=l((e,t)=>{var n=String;t.exports=function(e){try{return n(e)}catch{return`Object`}}}),ce=l((e,t)=>{var n=_(),r=se(),i=TypeError;t.exports=function(e){if(n(e))return e;throw new i(r(e)+` is not a function`)}}),le=l((e,t)=>{var n=ce(),r=C();t.exports=function(e,t){var i=e[t];return r(i)?void 0:n(i)}}),ue=l((e,t)=>{var n=y(),r=_(),i=E(),a=TypeError;t.exports=function(e,t){var o,s;if(t===`string`&&r(o=e.toString)&&!i(s=n(o,e))||r(o=e.valueOf)&&!i(s=n(o,e))||t!==`string`&&r(o=e.toString)&&!i(s=n(o,e)))return s;throw new a(`Can't convert object to primitive value`)}}),de=l((e,t)=>{t.exports=!0}),fe=l((e,t)=>{var n=u(),r=Object.defineProperty;t.exports=function(e,t){try{r(n,e,{value:t,configurable:!0,writable:!0})}catch{n[e]=t}return t}}),pe=l((e,t)=>{var n=de(),r=u(),i=fe(),a=`__core-js_shared__`,o=t.exports=r[a]||i(a,{});(o.versions||=[]).push({version:`3.43.0`,mode:n?`pure`:`global`,copyright:`© 2014-2025 Denis Pushkarev (zloirock.ru)`,license:`https://github.com/zloirock/core-js/blob/v3.43.0/LICENSE`,source:`https://github.com/zloirock/core-js`})}),me=l((e,t)=>{var n=pe();t.exports=function(e,t){return n[e]||(n[e]=t||{})}}),he=l((e,t)=>{var n=w(),r=Object;t.exports=function(e){return r(n(e))}}),O=l((e,t)=>{var n=m(),r=he(),i=n({}.hasOwnProperty);t.exports=Object.hasOwn||function(e,t){return i(r(e),t)}}),ge=l((e,t)=>{var n=m(),r=0,i=Math.random(),a=n(1.1.toString);t.exports=function(e){return`Symbol(`+(e===void 0?``:e)+`)_`+a(++r+i,36)}}),_e=l((e,t)=>{var n=u(),r=me(),i=O(),a=ge(),o=ie(),s=ae(),c=n.Symbol,l=r(`wks`),d=s?c.for||c:c&&c.withoutSetter||a;t.exports=function(e){return i(l,e)||(l[e]=o&&i(c,e)?c[e]:d(`Symbol.`+e)),l[e]}}),ve=l((e,t)=>{var n=y(),r=E(),i=oe(),a=le(),o=ue(),s=_e(),c=TypeError,l=s(`toPrimitive`);t.exports=function(e,t){if(!r(e)||i(e))return e;var s=a(e,l),u;if(s){if(t===void 0&&(t=`default`),u=n(s,e,t),!r(u)||i(u))return u;throw new c(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),o(e,t)}}),ye=l((e,t)=>{var n=ve(),r=oe();t.exports=function(e){var t=n(e,`string`);return r(t)?t:t+``}}),be=l((e,t)=>{var n=u(),r=E(),i=n.document,a=r(i)&&r(i.createElement);t.exports=function(e){return a?i.createElement(e):{}}}),xe=l((e,t)=>{var n=v(),r=d(),i=be();t.exports=!n&&!r(function(){return Object.defineProperty(i(`div`),`a`,{get:function(){return 7}}).a!==7})}),Se=l(e=>{var t=v(),n=y(),r=b(),i=x(),a=T(),o=ye(),s=O(),c=xe(),l=Object.getOwnPropertyDescriptor;e.f=t?l:function(e,t){if(e=a(e),t=o(t),c)try{return l(e,t)}catch{}if(s(e,t))return i(!n(r.f,e,t),e[t])}}),Ce=l((e,t)=>{var n=d(),r=_(),i=/#|\.prototype\./,a=function(e,t){var i=s[o(e)];return i===l?!0:i===c?!1:r(t)?n(t):!!t},o=a.normalize=function(e){return String(e).replace(i,`.`).toLowerCase()},s=a.data={},c=a.NATIVE=`N`,l=a.POLYFILL=`P`;t.exports=a}),we=l((e,t)=>{var n=g(),r=ce(),i=f(),a=n(n.bind);t.exports=function(e,t){return r(e),t===void 0?e:i?a(e,t):function(){return e.apply(t,arguments)}}}),Te=l((e,t)=>{var n=v(),r=d();t.exports=n&&r(function(){return Object.defineProperty(function(){},`prototype`,{value:42,writable:!1}).prototype!==42})}),Ee=l((e,t)=>{var n=E(),r=String,i=TypeError;t.exports=function(e){if(n(e))return e;throw new i(r(e)+` is not an object`)}}),De=l(e=>{var t=v(),n=xe(),r=Te(),i=Ee(),a=ye(),o=TypeError,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=`enumerable`,u=`configurable`,d=`writable`;e.f=t?r?function(e,t,n){if(i(e),t=a(t),i(n),typeof e==`function`&&t===`prototype`&&`value`in n&&d in n&&!n[d]){var r=c(e,t);r&&r[d]&&(e[t]=n.value,n={configurable:u in n?n[u]:r[u],enumerable:l in n?n[l]:r[l],writable:!1})}return s(e,t,n)}:s:function(e,t,r){if(i(e),t=a(t),i(r),n)try{return s(e,t,r)}catch{}if(`get`in r||`set`in r)throw new o(`Accessors not supported`);return`value`in r&&(e[t]=r.value),e}}),Oe=l((e,t)=>{var n=v(),r=De(),i=x();t.exports=n?function(e,t,n){return r.f(e,t,i(1,n))}:function(e,t,n){return e[t]=n,e}}),k=l((e,t)=>{var n=u(),r=p(),i=g(),a=_(),o=Se().f,s=Ce(),c=D(),l=we(),d=Oe(),f=O();pe();var m=function(e){var t=function(n,i,a){if(this instanceof t){switch(arguments.length){case 0:return new e;case 1:return new e(n);case 2:return new e(n,i)}return new e(n,i,a)}return r(e,this,arguments)};return t.prototype=e.prototype,t};t.exports=function(e,t){var r=e.target,u=e.global,p=e.stat,h=e.proto,g=u?n:p?n[r]:n[r]&&n[r].prototype,_=u?c:c[r]||d(c,r,{})[r],v=_.prototype,y,b,x,S,C,w,T,E,D;for(S in t)y=s(u?S:r+(p?`.`:`#`)+S,e.forced),b=!y&&g&&f(g,S),w=_[S],b&&(e.dontCallGetSet?(D=o(g,S),T=D&&D.value):T=g[S]),C=b&&T?T:t[S],!(!y&&!h&&typeof w==typeof C)&&(E=e.bind&&b?l(C,n):e.wrap&&b?m(C):h&&a(C)?i(C):C,(e.sham||C&&C.sham||w&&w.sham)&&d(E,`sham`,!0),d(_,S,E),h&&(x=r+`Prototype`,f(c,x)||d(c,x,{}),d(c[x],S,C),e.real&&v&&(y||!v[S])&&d(v,S,C)))}}),ke=l((e,t)=>{var n=Math.ceil,r=Math.floor;t.exports=Math.trunc||function(e){var t=+e;return(t>0?r:n)(t)}}),A=l((e,t)=>{var n=ke();t.exports=function(e){var t=+e;return t!==t||t===0?0:n(t)}}),Ae=l((e,t)=>{var n=A(),r=Math.max,i=Math.min;t.exports=function(e,t){var a=n(e);return a<0?r(a+t,0):i(a,t)}}),je=l((e,t)=>{var n=A(),r=Math.min;t.exports=function(e){var t=n(e);return t>0?r(t,9007199254740991):0}}),Me=l((e,t)=>{var n=je();t.exports=function(e){return n(e.length)}}),Ne=l((e,t)=>{var n=T(),r=Ae(),i=Me(),a=function(e){return function(t,a,o){var s=n(t),c=i(s);if(c===0)return!e&&-1;var l=r(o,c),u;if(e&&a!==a){for(;c>l;)if(u=s[l++],u!==u)return!0}else for(;c>l;l++)if((e||l in s)&&s[l]===a)return e||l||0;return!e&&-1}};t.exports={includes:a(!0),indexOf:a(!1)}}),Pe=l((e,t)=>{t.exports=function(){}}),Fe=l(()=>{var e=k(),t=Ne().includes,n=d(),r=Pe();e({target:`Array`,proto:!0,forced:n(function(){return![,].includes()})},{includes:function(e){return t(this,e,arguments.length>1?arguments[1]:void 0)}}),r(`includes`)}),Ie=l((e,t)=>{t.exports=ee()}),Le=l((e,t)=>{Fe(),t.exports=Ie()(`Array`,`includes`)}),Re=l((e,t)=>{t.exports=Le()}),ze=l((e,t)=>{t.exports=Re()}),Be=l(()=>{var e=k(),t=he(),n=Me(),r=A(),i=Pe();e({target:`Array`,proto:!0},{at:function(e){var i=t(this),a=n(i),o=r(e),s=o>=0?o:a+o;return s<0||s>=a?void 0:i[s]}}),i(`at`)}),Ve=l((e,t)=>{Be(),t.exports=Ie()(`Array`,`at`)}),He=l((e,t)=>{t.exports=Ve()}),Ue=l((e,t)=>{t.exports=He()}),We=l((e,t)=>{var n=_e()(`toStringTag`),r={};r[n]=`z`,t.exports=String(r)===`[object z]`}),Ge=l((e,t)=>{var n=We(),r=_(),i=h(),a=_e()(`toStringTag`),o=Object,s=i(function(){return arguments}())===`Arguments`,c=function(e,t){try{return e[t]}catch{}};t.exports=n?i:function(e){var t,n,l;return e===void 0?`Undefined`:e===null?`Null`:typeof(n=c(t=o(e),a))==`string`?n:s?i(t):(l=i(t))===`Object`&&r(t.callee)?`Arguments`:l}}),Ke=l((e,t)=>{var n=Ge(),r=String;t.exports=function(e){if(n(e)===`Symbol`)throw TypeError(`Cannot convert a Symbol value to a string`);return r(e)}}),qe=l(()=>{var e=k(),t=m(),n=w(),r=A(),i=Ke(),a=d(),o=t(``.charAt);e({target:`String`,proto:!0,forced:a(function(){return`𠮷`.at(-2)!==`\ud842`})},{at:function(e){var t=i(n(this)),a=t.length,s=r(e),c=s>=0?s:a+s;return c<0||c>=a?void 0:o(t,c)}})}),Je=l((e,t)=>{qe(),t.exports=Ie()(`String`,`at`)}),Ye=l((e,t)=>{t.exports=Je()}),Xe=l((e,t)=>{t.exports=Ye()}),Ze=l((e,t)=>{var n=me(),r=ge(),i=n(`keys`);t.exports=function(e){return i[e]||(i[e]=r(e))}}),Qe=l((e,t)=>{t.exports=!d()(function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})}),$e=l((e,t)=>{var n=O(),r=_(),i=he(),a=Ze(),o=Qe(),s=a(`IE_PROTO`),c=Object,l=c.prototype;t.exports=o?c.getPrototypeOf:function(e){var t=i(e);if(n(t,s))return t[s];var a=t.constructor;return r(a)&&t instanceof a?a.prototype:t instanceof c?l:null}}),et=l((e,t)=>{t.exports={}}),tt=l((e,t)=>{var n=m(),r=O(),i=T(),a=Ne().indexOf,o=et(),s=n([].push);t.exports=function(e,t){var n=i(e),c=0,l=[],u;for(u in n)!r(o,u)&&r(n,u)&&s(l,u);for(;t.length>c;)r(n,u=t[c++])&&(~a(l,u)||s(l,u));return l}}),nt=l((e,t)=>{t.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]}),rt=l((e,t)=>{var n=tt(),r=nt();t.exports=Object.keys||function(e){return n(e,r)}}),it=l((e,t)=>{var n=v(),r=d(),i=m(),a=$e(),o=rt(),s=T(),c=b().f,l=i(c),u=i([].push),f=n&&r(function(){var e=Object.create(null);return e[2]=2,!l(e,2)}),p=function(e){return function(t){for(var r=s(t),i=o(r),c=f&&a(r)===null,d=i.length,p=0,m=[],h;d>p;)h=i[p++],(!n||(c?h in r:l(r,h)))&&u(m,e?[h,r[h]]:r[h]);return m}};t.exports={entries:p(!0),values:p(!1)}}),at=l(()=>{var e=k(),t=it().entries;e({target:`Object`,stat:!0},{entries:function(e){return t(e)}})}),ot=l((e,t)=>{at(),t.exports=D().Object.entries}),st=l((e,t)=>{t.exports=ot()}),ct=l((e,t)=>{t.exports=st()}),lt=l(()=>{var e=k(),t=it().values;e({target:`Object`,stat:!0},{values:function(e){return t(e)}})}),ut=l((e,t)=>{lt(),t.exports=D().Object.values}),dt=l((e,t)=>{t.exports=ut()}),ft=l((e,t)=>{t.exports=dt()}),pt=l((e,t)=>{var n=h();t.exports=Array.isArray||function(e){return n(e)===`Array`}}),mt=l((e,t)=>{var n=TypeError,r=9007199254740991;t.exports=function(e){if(e>r)throw n(`Maximum allowed index exceeded`);return e}}),ht=l((e,t)=>{var n=pt(),r=Me(),i=mt(),a=we(),o=function(e,t,s,c,l,u,d,f){for(var p=l,m=0,h=d?a(d,f):!1,g,_;m<c;)m in s&&(g=h?h(s[m],m,t):s[m],u>0&&n(g)?(_=r(g),p=o(e,t,g,_,p,u-1)-1):(i(p+1),e[p]=g),p++),m++;return p};t.exports=o}),gt=l((e,t)=>{var n=m(),r=_(),i=pe(),a=n(Function.toString);r(i.inspectSource)||(i.inspectSource=function(e){return a(e)}),t.exports=i.inspectSource}),_t=l((e,t)=>{var n=m(),r=d(),i=_(),a=Ge(),o=ee(),s=gt(),c=function(){},l=o(`Reflect`,`construct`),u=/^\s*(?:class|function)\b/,f=n(u.exec),p=!u.test(c),h=function(e){if(!i(e))return!1;try{return l(c,[],e),!0}catch{return!1}},g=function(e){if(!i(e))return!1;switch(a(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(u,s(e))}catch{return!0}};g.sham=!0,t.exports=!l||r(function(){var e;return h(h.call)||!h(Object)||!h(function(){e=!0})||e})?g:h}),vt=l((e,t)=>{var n=pt(),r=_t(),i=E(),a=_e()(`species`),o=Array;t.exports=function(e){var t;return n(e)&&(t=e.constructor,r(t)&&(t===o||n(t.prototype))?t=void 0:i(t)&&(t=t[a],t===null&&(t=void 0))),t===void 0?o:t}}),yt=l((e,t)=>{var n=vt();t.exports=function(e,t){return new(n(e))(t===0?0:t)}}),bt=l(()=>{var e=k(),t=ht(),n=he(),r=Me(),i=A(),a=yt();e({target:`Array`,proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,o=n(this),s=r(o),c=a(o,0);return c.length=t(c,o,o,s,0,e===void 0?1:i(e)),c}})}),xt=l(()=>{Pe()(`flat`)}),St=l((e,t)=>{bt(),xt(),t.exports=Ie()(`Array`,`flat`)}),Ct=l((e,t)=>{t.exports=St()}),wt=l((e,t)=>{t.exports=Ct()}),Tt=`1.0.63-dev.55dfadaf.0`;import{fromEvent as Et,Subscription as Dt}from"@vkontakte/videoplayer-shared/es2024";class Ot{layout;cssVarsManager;constructor(e,t){this.layout=e,this.cssVarsManager=t}}class kt extends Ot{cssVarsManager;constructor(e,t){super(e,t),this.cssVarsManager=t,this.cssVarsManager=t}setContainerLayout(e){e.style.position=`relative`}setControlLayout(e,t){let n=this.cssVarsManager.getPropValue(`--interactive-content-width`),r=this.cssVarsManager.getPropValue(`--interactive-content-height`),i=this.cssVarsManager.getPropValue(`--interactive-width`),a=this.cssVarsManager.getPropValue(`--interactive-height`);e.style.position=`absolute`,e.style.width=`calc(${n} * (${t.width} + 0.0002))`,e.style.height=`calc(${r} * ${t.height})`,e.style.left=`calc(${n} * ${t.x} + ((${i} - ${n}) / 2))`,e.style.top=`calc(${r} * ${t.y} + ((${a} - ${r}) / 2))`}}import{Subject as At}from"@vkontakte/videoplayer-shared/es2024";function jt(e){return`features`in e}class j{severity;category;data;constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null,` `)}`}}function Mt({emitter$:e,error:t,subjectId:n,message:r=``,severity:i=1,category:a=1}){let o=new j(i,a,{message:r,error:t,details:{id:n}});e.next(o)}class Nt{container;options;factories;controls;error$=new At;cssVarsManager;constructor(e,t,n){this.container=e,this.options=n,this.factories=new Map,this.controls=[],this.setControls(),this.cssVarsManager=t}featureIsEnabled(e){return!!(this.options&&this.options.features&&jt(this.options)&&this.options.features[e])}onError(e=``,t){Mt({emitter$:this.error$,error:t,message:e,subjectId:this.container.id})}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.setControls()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((e,t)=>{let n=t.type.trim().toLowerCase(),r=this.factories.get(n);if(r){let n=r(t,this.options);if(n)return[...e,n]}return[...e]},[])||[]}}import{fromEvent as M,once as Pt}from"@vkontakte/videoplayer-shared/es2024";var N=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,Ft=e=>N(e,`Object`),It=e=>N(e,`String`),Lt=e=>N(e,`Array`),Rt=e=>N(e,`Number`),zt=e=>N(e,`Function`),Bt=e=>N(e,`Boolean`),Vt=e=>Rt(e)&&!isNaN(e),P=e=>Ft(e)&&Object.keys(e).length===0,Ht=e=>Lt(e)&&!e.length,Ut=(e,t)=>It(e)&&!!(t?e.trim():e).length;function Wt(e,t=1){let n=`0`,r=`0`,i=`0`;return e.length===4?(n=`0x`+e[1]+e[1],r=`0x`+e[2]+e[2],i=`0x`+e[3]+e[3]):e.length===7&&(n=`0x`+e[1]+e[2],r=`0x`+e[3]+e[4],i=`0x`+e[5]+e[6]),`rgba(${+n},${+r},${+i},${t})`}var Gt=`interactive`,F={textColor:`#000`,textSize:.4,textContent:``,roundCorners:0,borderWidth:0,borderWidthRawValue:`1px`,roundCornersRawValue:`0`,borderColor:`#000`,borderAlpha:1,backgroundColor:`#fff`,backgroundAlpha:1,innerSizesDependOn:`self`,angle:0,shadowColorLight:`#fff`,shadowColorDark:`#000`,shadowColorAlpha:.24},Kt;(e=>{e.top=`flex-start`,e.bottom=`flex-end`,e.center=`center`})(Kt||={});var qt;(e=>{e.start=`flex-start`,e.end=`flex-end`,e.center=`center`})(qt||={});var Jt=({target:e,props:t})=>{e.style.alignItems=(t?.gravityVertical&&Kt[t.gravityVertical])??`center`,e.style.justifyContent=(t?.gravityHorizontal&&qt[t.gravityHorizontal])??`center`,e.style.textAlign=t?.alignment??`center`},Yt=({target:e,props:t,fallback:n,dependsOn:r})=>{e.style.color=t?.text?.color??n.textColor,e.style.fontSize=`calc(${r.height} * ${t?.text?.size??n.textSize})`,e.textContent=t?.text?.value??n.textContent},Xt=({target:e,props:t,fallback:n})=>{e.style.backgroundColor=Wt(t?.background?.color??n.backgroundColor,t?.background?.alpha??n.backgroundAlpha)},Zt=({target:e,props:t,fallback:n,dependsOn:r,useRawValues:i=!1})=>{let a=i?n.borderWidthRawValue:`calc(${r.height} * ${t?.shape?.border?.width??n.borderWidth})`,o=i?n.roundCornersRawValue:`calc(${r.height} * ${t?.shape?.roundCorners??n.roundCorners})`;e.style.borderWidth=a,e.style.borderStyle=`solid`,e.style.borderColor=Wt(i?n.borderColor:t?.shape?.border?.color??n.borderColor,i?n.borderAlpha:t?.shape?.border?.alpha??n.borderAlpha),e.style.borderRadius=o},Qt=({target:e,isDark:t,baseDimension:n,fallback:r})=>{let i=Wt(r.shadowColorLight,r.shadowColorAlpha),a=Wt(r.shadowColorDark,r.shadowColorAlpha),o=`0px 0px ${`calc(${n} * 0.25)`} ${`calc(${n} * 0.11)`} ${t?a:i}`;e.style.boxShadow=o},$t=({target:e,layoutParams:t,fallback:n})=>{let r=t.angle??n.angle;r&&=r*-1,e.style.transform=`rotate(${r}rad)`};import{fromEvent as I,Subject as en,Subscription as tn}from"@vkontakte/videoplayer-shared/es2024";var nn=`interactive-control-tap`,L={common:nn,animation:`${nn}-animation`,visible:`${nn}-visible`},rn=60;class an{element;controlRotateAngleRad;clickCancelCondition;circleDiameterPx;useDimensionsBasedSize;constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=rn,useDimensionsBasedSize:r=!1}){let i=document.createElement(`div`);i.classList.add(L.common),this.controlRotateAngleRad=e,this.element=i,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=r}onElementClick=e=>{if(!e.target||!e.currentTarget||this.clickCancelCondition())return;let t=e.currentTarget.parentElement;if(!t)return;let n=t.getBoundingClientRect(),r={width:this.useDimensionsBasedSize?t.offsetWidth:this.circleDiameterPx,height:this.useDimensionsBasedSize?t.offsetHeight:this.circleDiameterPx},i=Math.min(r.width,r.height),a=n.left+n.width/2,o=n.top+n.height/2,s=on(e.clientX-a,e.clientY-o,this.controlRotateAngleRad);this.element.style.width=i+`px`,this.element.style.left=s.x+n.width/2-i/2+`px`,this.element.style.top=s.y+n.height/2-i/2+`px`,this.element.classList.add(L.visible,L.animation)};onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(L.visible,L.animation)}}function on(e,t,n){return{x:e*Math.cos(n)-t*Math.sin(n),y:e*Math.sin(n)+t*Math.cos(n)}}function sn(e){return`features`in e}var R=`interactive-control`,z={common:R,selected:`${R}-selected`,wrapper:`${R}-wrapper`,disabled:`${R}-disabled`,button:`${R}-button`,area:`${R}-area`,text:`${R}-text`,blinkAnim:`${R}-blink-anim`,blinkAnimButton:`${R}-blink-anim-button`,blinkAnimArea:`${R}-blink-anim-area`},cn=40,ln=c(ze(),1);import{isSupportedManifest as un,ContainerTypes as dn,ControlTypes as fn,EventActionTypes as B,EventTypes as pn,migrateManifestToLatestVersion as mn}from"@interactiveplatform/movika-manifest";var hn={metadata:`Object`,chapters:`Array`},gn=e=>{if(!Ft(e))return!1;for(let t in hn){let n=e[t];if(!n||!N(n,hn[t]))return!1}return un(e.metadata.version)};function _n(e){return e.type===fn.Text}function vn(e){return e.type===fn.Button}function yn(e){return e.type===fn.Area}var bn={Choice:`Choice`,TextInput:`TextInput`},xn={Button:`Button`,Area:`Area`,Text:`Text`},Sn={onClick:`onClick`,onSuspense:`onSuspense`},Cn={openURI:`openURI`,setNextBranch:`setNextBranch`,setWeightlessRandomBranch:`setWeightlessRandomBranch`,setRandomBranch:`setRandomBranch`,setMaxWeightBranch:`setMaxWeightBranch`,setMinWeightBranch:`setMinWeightBranch`,setDefaultBranch:`setDefaultBranch`,continuePlayback:`continuePlayback`,expect:`expect`},wn=e=>Lt(e)&&!Ht(e),V=e=>e.order===`end`,Tn=e=>Lt(e.containers)&&!Ht(e.containers)&&V(e),En=(e,t)=>{let n=e*1e3;return wn(t.controls)&&n<(t.startTime??0)},Dn=(e,t)=>{let n=e*1e3;return wn(t.controls)&&n>=(t.startTime??0)&&n<=(t.endTime??1/0)},H=(e=[])=>e.some(e=>e.action.type===`expect`),On=(e=[])=>e.find(e=>e.action.type===`expect`),kn=e=>e?.length===1,An=e=>kn(e)&&_n(e[0]);function jn(e=[],t=1/0,n=[]){return e.filter(({container:e})=>!ln.default(n,e.container.id)&&H(e.container.events)&&e.container.endTime===t&&!e.isRemoved&&!e.willRemoved)}function Mn({gameControllers:e=[],subjectName:t,subjectId:n,execFn:r}){for(let i of e)if(t===`container`&&i.container.container.id===n){r(i),jn(e,i.container.container.endTime,[i.container.container.id]).forEach(e=>{r(e)});break}}function Nn(e){for(let t of e.events)if(t.action.type===`openURI`)return!0;return!1}var Pn=(e,t)=>{let n=H(e.events)&&!(e=>t.find(({container:t})=>t.container.id===e)?.container.isRemoved)(e.id),r=(t,n=!1,r=!1)=>{let i=r?`every`:`some`;return t.controls[i](r=>{let a=n?t.endTime===e.endTime:!0;return r.events?.[i](e=>e.action?.type===B.openURI)&&a})},i=e=>e.some(({container:e})=>r(e.container,!0,!1)&&!e.isRemoved),a=e=>e.every(({container:e})=>e.isRemoved||e.willRemoved?!0:r(e.container,!0,!0)),o=jn(t,e.endTime,[e.id]).length,s=e=>e.controls.some(e=>e.events?.some(e=>e.action?.args?.shouldOpenNow)),c=n||o>0,l=i(t),u=r(e),d=a(t),f=n?!1:o>0,p=s(e);return{isExpectTime:c,hasOtherExpect:o>0,hasOpenURIEvent:l,hasOpenURIEventInCurrentContainer:u,isAllOpenURIEventsValid:d,isExpectEventForCurrentContainer:f,hasShouldOpenNowEvent:p}};class U{control;options;container=null;controlElement=null;subscriptions=new tn;error$=new en;controlTap;isInteracted=!1;isRemoved=!1;cssVarsManager=null;constructor(e,t=void 0){this.control=e,this.options=t}setCssVarsManager(e){this.cssVarsManager=e}onControlSelect=()=>{this.container?.isManifestContainerDisabled()||Nn(this.control)||this.container?.element?.classList.add(`interactive-control-wrapper-selected`)};removeView(e=!1){let t=this.getElement();if(t){if(e){if(t.classList.contains(`interactive-control-before-remove`))return;t.classList.add(`interactive-control-before-remove`),this.subscriptions.add(I(t,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${U.name} remove view transition error`,e))).add(I(t,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${U.name} remove view transition error`,e)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()};onError(e=``,t){Mt({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){this.featureIsEnabled(`controlsTapPlace`)&&this.container&&(this.controlTap=new an({controlRotateAngleRad:this.control.layoutParams.angle??F.angle,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?cn:void 0}),this.subscriptions.add(I(e,`click`).subscribe(this.controlTap.onElementClick,e=>this.onError(`Control click tap animation error`,e))).add(I(this.controlTap.element,`animationend`).subscribe(this.controlTap.onAnimationEnd,e=>this.onError(`Tap animationend error`,e))),this.container.element.append(this.controlTap.element))}createContainerElement(e){let t=document.createElement(`div`);t.classList.add(z.wrapper),e.setControlLayout(t,this.control.layoutParams),this.container={element:t,dimensions:(this.control.layoutParams.innerSizesDependOn??F.innerSizesDependOn)===`self`?{height:t.style.height,width:t.style.width}:{height:this.cssVarsManager?.getPropValue(`--interactive-content-height`)??0,width:this.cssVarsManager?.getPropValue(`--interactive-content-width`)??0},isManifestContainerDisabled:()=>e.isContainerDisabled?.()??!1}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&sn(this.options)&&this.options.features[e])}isTouch(){return!!(this.options&&sn(this.options)&&this.options.isTouch)}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case`onclick`:if(!this.container)break;this.subscriptions.add(I(this.container.element,`click`).subscribe(this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),e=>this.onError(`Error happened on control interaction`,e)));break;default:break}})}removeListeners(){this.subscriptions.unsubscribe()}}var Fn=`interactive-blink-anim-reference`,W={common:Fn,animation:`${Fn}-animation`,disabled:`${Fn}-disabled`};class In{_RAFId=0;_element=void 0;get element(){return this._element}create(){if(this._element)return;let e=document.createElement(`div`);e.classList.add(W.common,W.animation),this._element=e}restart(){this._element&&(this._element.classList.add(W.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(W.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&=(cancelAnimationFrame(this._RAFId),0)}destroy(){this.cleanupRAF(),this._element=void 0}}var Ln=`interactive-container`,G={common:Ln,hidden:`${Ln}-hidden`,disabled:`${Ln}-disabled`},Rn=(e,t)=>{if(e.type.trim().toLowerCase()===`area`)return new zn(e,t)};class zn extends U{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let n=document.createElement(`button`);n.type=`button`,n.classList.add(z.common,z.area),n.setAttribute(`data-testid`,`int_area`),Xt({target:n,props:this.control.props,fallback:{...F,backgroundColor:`transparent`}}),$t({target:n,layoutParams:this.control.layoutParams,fallback:F}),this.addControlTap(n),this.subscriptions.add(M(this.container.element,`click`).pipe(Pt()).subscribe(this.onControlSelect,e=>this.onError(`Control click handler error`,e))),this.container.element.append(n),e.append(this.container.element),this.controlElement=n,this.updateShadowStyles(),this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled(`controlsExpectTimeBlinkAnimation`))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(M(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(G.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${W.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(M(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(G.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(M(this.controlElement,`mouseleave`).subscribe(()=>{this.controlElement&&(this.controlElement.style.animation=``)},e=>this.onError(`Error happened in mouseleave callback`,e))))}disable(){this.controlElement&&this.controlElement.classList.add(z.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(z.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(Bt(e)){let t=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+`px`;Qt({target:this.controlElement,props:this.control.props,fallback:F,isDark:e,baseDimension:t}),Zt({target:this.controlElement,props:this.control.props,fallback:{...F,borderColor:e?F.shadowColorDark:F.shadowColorLight,borderAlpha:1,borderWidthRawValue:`0.1px`,roundCornersRawValue:`calc(${this.container.dimensions.height} * ${this.control.props?.shape?.roundCorners??F.roundCorners})`},dependsOn:this.container.dimensions,useRawValues:!0})}else Zt({target:this.controlElement,props:this.control.props,fallback:{...F,borderAlpha:0},dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(z.blinkAnim,e),this.controlElement?.classList.toggle(z.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${z.blinkAnimArea}`)||this.controlElement.classList.contains(z.selected)||this.controlElement.classList.contains(W.disabled)||(this.controlElement.classList.add(W.disabled),this.subscriptions.add(M(e,`animationiteration`).pipe(Pt()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(W.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${z.blinkAnimArea}`)||this.controlElement.classList.contains(z.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue(`--interactive-area-hover-opacity`).trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation=`none`,requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}setShowTimeRange(){}updateFillAnimationDimensions(){}onProgress(){}onResize(){}}import{fromEvent as K,once as Bn}from"@vkontakte/videoplayer-shared/es2024";var Vn=e=>{let t=document.createElement(`span`);switch(e){case`Button`:case`button`:{let e=document.createElement(`div`);return Object.assign(e.style,{overflow:`hidden`,display:`flex`,justifyContent:`center`,alignItems:`center`}),e.append(t),Object.assign(t.style,{display:`inline-block`,whiteSpace:`pre`,textOverflow:`ellipsis`,maxWidth:`initial`,maxHeight:`100%`,wordBreak:`normal`}),e}default:return Object.assign(t.style,{display:`inline-block`,whiteSpace:`break-spaces`,overflow:`hidden`,textOverflow:`ellipsis`,maxWidth:`100%`,maxHeight:`100%`,wordBreak:`break-all`}),t}},Hn=Math.PI,Un=2*Hn,Wn=Hn/2,Gn=3*Wn,Kn=[0,Wn,Hn,Gn];function qn(e){return e===Wn}function Jn(e){return e===Hn}function Yn(e){return e===Gn}function Xn(e){return(e%Un+Un)%Un}function Zn(e){for(let t of Kn)if(e===t)return t}function Qn(e){return Zn(e)?null:[1,2,3,4][Math.floor(e/Wn)+1-1]}function $n(e){return e*180/Math.PI}var q=`interactive-control-fill-animation`,J={common:q,fillerWrapper:`${q}-filler-wrapper`,filler:`${q}-filler`,fillHeight:`${q}-fill-height`,fillWidth:`${q}-fill-width`,fromTop:`${q}-from-top`,fromBottom:`${q}-from-bottom`,fromLeft:`${q}-from-left`,fromRight:`${q}-from-right`};class er{fillAnimationElement;fillAnimationFillerElement;fillAnimationFillerWrapperElement;startTime;endTime;shouldFillHeight;widthExpansionCoef=0;isDebug;fromLeft;useSkew;rotateAngle;constructor(e){let t=document.createElement(`div`);t.classList.add(J.common);let n=document.createElement(`div`);n.classList.add(J.fillerWrapper);let r=document.createElement(`div`);r.classList.add(J.filler),n.append(r),t.append(n);let i=Xn(e.rotateAngle),a=Qn(i),o=a!==null,s=a===2||!o&&Jn(i)||a===3,c=!o&&qn(i),l=!o&&Yn(i),u=!s&&!c&&!l,d=c||l,f=o&&!d,p=f?i:0;t.style.borderRadius=e.borderRadius,n.style.transform=`skew(${p*-1}rad)`,d?(r.classList.add(J.fillHeight,c?J.fromTop:J.fromBottom),n.classList.add(J.fillHeight,c?J.fromTop:J.fromBottom)):(r.classList.add(J.fillWidth,u?J.fromLeft:J.fromRight),n.classList.add(J.fillWidth)),e.debug&&console.log(`[interactive ${er.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:d,rotateAngleRad:i,rotateAngelDeg:$n(i),rotateAngleRaw:e.rotateAngle,fromRight:s,fromTop:c,fromBottom:l,fromLeft:u}),this.useSkew=f,this.fromLeft=u,this.rotateAngle=i,this.fillAnimationElement=t,this.fillAnimationFillerElement=r,this.fillAnimationFillerWrapperElement=n,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=d,this.isDebug=e.debug??!1}updateDimension(e){this.fillAnimationElement.style.top=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.left=`${e.borderWidth*-1}px`,this.fillAnimationElement.style.width=`${e.width}px`,this.fillAnimationElement.style.height=`${e.height}px`;let t=this.calcWidthExpansionCoef({rotateAngle:this.rotateAngle,isSkewed:this.useSkew,initWidth:e.width,initHeight:e.height});!this.shouldFillHeight&&(this.fillAnimationFillerWrapperElement.style.width=100*t+100+`%`,this.fillAnimationFillerWrapperElement.style[`${this.fromLeft?`left`:`right`}`]=`calc((${t} * 100%) / 2 * -1)`),this.widthExpansionCoef=t}updateAnimation(e){if((e=>e<this.startTime||e>this.endTime)(e))return;let t=this.endTime-this.startTime,n=Math.min(Math.max((e-this.startTime)/t,0),1);this.shouldFillHeight?this.fillAnimationFillerElement.style.transform=`scaleY(${n})`:this.fillAnimationFillerElement.style.transform=`scaleX(${n})`}calcWidthExpansionCoef({rotateAngle:e,isSkewed:t=!1,initWidth:n,initHeight:r}){return t?(n+r*Math.abs(Math.tan(e)))/n-1:0}}var tr=(e,t)=>{if(e.type.trim().toLowerCase()===`button`)return new nr(e,t)};class nr extends U{startTime;endTime;controlFillAnimation;constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let n=document.createElement(`button`);n.type=`button`,n.classList.add(z.common,z.button),n.setAttribute(`data-testid`,`int_bttn`),$t({target:n,layoutParams:this.control.layoutParams,fallback:F}),Xt({target:n,props:this.control.props,fallback:F}),Zt({target:n,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),Jt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=Vn(this.control.type.trim().toLowerCase());Yt({target:r.firstElementChild??r,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),this.addControlTap(n),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled(`controlsFillAnimation`)&&(this.controlFillAnimation=new er({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??F.angle,borderRadius:n.style.borderRadius})),this.subscriptions.add(K(n,`click`).pipe(Bn()).subscribe(this.onControlSelect,e=>this.onError(`Control click handler error`,e))),n.append(r,this.controlFillAnimation?.fillAnimationElement??``),this.container.element.append(this.controlTap?.element??``,n),e.append(this.container.element),this.controlElement=n,this.registerBlinkAnimationEvents()}registerBlinkAnimationEvents(){if(!this.featureIsEnabled(`controlsExpectTimeBlinkAnimation`))return;let e=this.container?.element.parentElement;!e||!this.controlElement||(this.subscriptions.add(K(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(G.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${W.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(K(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(G.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(K(this.controlElement,`mouseleave`).subscribe(()=>{this.controlElement&&(this.controlElement.style.animation=``)},e=>this.onError(`Error happened in mouseleave callback`,e))))}disable(){this.controlElement&&this.controlElement.classList.add(z.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(z.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(z.blinkAnim,e),this.controlElement?.classList.toggle(z.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${z.blinkAnimButton}`)||this.controlElement.classList.contains(z.selected)||this.controlElement.classList.contains(W.disabled)||(this.controlElement.classList.add(W.disabled),this.subscriptions.add(K(e,`animationiteration`).pipe(Bn()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(W.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${z.blinkAnimButton}`)||this.controlElement.classList.contains(z.selected))return;let e=window.getComputedStyle(this.controlElement),t=e.getPropertyValue(`--interactive-button-hover-opacity`).trim();this.controlElement.style.opacity=e.opacity,this.controlElement.style.animation=`none`,requestAnimationFrame(()=>{this.controlElement&&(this.controlElement.style.opacity=t)})}updateFillAnimationDimensions(){if(!this.container||!this.controlElement||!this.controlFillAnimation)return;let e=getComputedStyle(this.controlElement),t={width:parseFloat(e.width),height:parseFloat(e.height),borderWidth:parseFloat(e.borderWidth)||0};this.controlFillAnimation.updateDimension(t)}setShowTimeRange(e,t){this.startTime=e,this.endTime=t}onProgress(e){this.controlFillAnimation?.updateAnimation(e)}onResize(){this.updateFillAnimationDimensions()}updateShadowStyles(){}}var rr=(e,t)=>{if(e.type.trim().toLowerCase()===`text`)return new ir(e,t)};class ir extends U{constructor(e,t){super(e,t)}createView({parentElement:e,callbacks:t}){if(super.createContainerElement(t),!this.container)return;this.isInteracted=!1,this.isRemoved=!1;let n=document.createElement(`div`);n.classList.add(z.common,z.text),n.setAttribute(`data-testid`,`int_text`),$t({target:n,layoutParams:this.control.layoutParams,fallback:F}),Jt({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=Vn(this.control.type.trim().toLowerCase());Yt({target:r.firstElementChild??r,props:this.control.props,fallback:F,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}getElement(){return this.controlElement}disable(){}enable(){}onProgress(){}onResize(){}updateShadowStyles(){}toggleBlinkAnimation(){}setShowTimeRange(){}updateFillAnimationDimensions(){}}var ar=(e,t,n,r)=>{if(e.type.trim().toLowerCase()===`choice`)return new or(e,t,n,r)};class or extends Nt{rootElement;containerElement=null;layout;subscriptions=new Dt;isRemoved;isDisabled;willRemoved;cssVarsManager;constructor(e,t,n,r){super(e,n,r),this.rootElement=t,this.layout=new kt(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory(`button`,tr),this.addControlFactory(`text`,rr),this.addControlFactory(`area`,Rn)}createView({eventCallback:e,videoDurationMs:t}){let n=document.createElement(`div`);return n.classList.add(G.common,G.disabled),n.setAttribute(`data-subjectId`,this.container.id),requestAnimationFrame(()=>{n.classList.remove(G.disabled)}),this.layout.setContainerLayout(n),this.controls.forEach(r=>{r.setShowTimeRange(this.container.startTime,this.container.endTime??t),r.setCssVarsManager(this.cssVarsManager),r.createView({parentElement:n,callbacks:{setControlLayout:(e,t)=>this.layout.setControlLayout(e,t),isContainerDisabled:()=>this.isDisabled}}),r.setEvents(e),this.subscriptions.add(r.error$.subscribe(this.error$))}),this.rootElement.append(n),this.isRemoved=!1,this.willRemoved=!1,this.containerElement=n,this.updateControlsFillAnimationDimensions(),n}updateControlsFillAnimationDimensions(){for(let e of this.controls)e.updateFillAnimationDimensions()}hide(){let e=this.getElement();e&&e.classList.add(G.hidden)}show(){let e=this.getElement();e&&e.classList.remove(G.hidden)}enable(){let e=this.getElement();e&&(e.classList.remove(G.disabled),this.controls.forEach(e=>e.enable()),this.isDisabled=!1)}disable(){let e=this.getElement();e&&(e.classList.add(G.disabled),this.controls.forEach(e=>e.disable()),this.isDisabled=!0)}removeView(e=!1,t=!1){let n=this.getElement();if(n){if(e){if(this.willRemoved)return;this.willRemoved=!0,t&&n.classList.add(`interactive-container-before-remove-delay`),n.classList.add(`interactive-container-before-remove`),this.subscriptions.add(Et(n,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${or.name} remove view transition error`,e))).add(Et(n,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${or.name} remove view transition error`,e)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()};removeAllControls(e=!1){this.controls.forEach(t=>t.removeView(e))}removeNonInteractedControls(e=!1){this.controls.forEach(t=>{t.isInteracted||t.removeView(e)})}isInteracted(){return this.controls.some(e=>e.isInteracted)}fakeRemove(){this.isRemoved||=!0}getElement(){return this.containerElement}onProgress(e,t){t&&this.controls.forEach(t=>{t.onProgress(e)})}onResize(e){e&&this.controls.forEach(e=>{e.onResize()})}updateControlsShadowStyles(e){this.controls.forEach(t=>t.updateShadowStyles(e))}toggleBlinkAnimation(e){this.controls.forEach(t=>t.toggleBlinkAnimation(e))}}var sr=c(Ue(),1),cr=c(Xe(),1),lr=(e,t)=>typeof e==`string`?cr.default(e,t):sr.default(e,t);import{combine as ur,InterfaceLanguage as dr,Observable as fr,once as pr,Subject as Y,Subscription as mr,ValueSubject as X,fromEvent as hr}from"@vkontakte/videoplayer-shared/es2024";import{InteractiveInterfaceClick as gr}from"@vkontakte/videoplayer-statistics/es2024";import{loadVKLangPack as _r}from"@vkontakte/videoplayer-shared/es2024";function vr(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}var yr=`video_interactive`,br=`videoint`,xr=250;class Sr{isHidden;currentManifestId;currentChapterId;visitedChapterIds;onOpenPreviewClick;onError;lang;zoom;lastZoomInfo;isReady;ngEditor;ngEditorSize;graphWrapperElement;resizeObserver;manifest;constructor(e){this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:i=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(i),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??`ru`,this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=Cr(e),this.resizeObserver=new ResizeObserver(vr(this.onResize,xr)),this.resizeObserver.observe(this.graphWrapperElement)}handleZoomChange=vr(e=>{this.lastZoomInfo=e},xr);onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};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]}handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.(`Chapter id is not found`);return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!Rt(e.graph.edit.chapters[0].x)){this.onError?.(`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.setVisitedChapters(Array.from(t)):(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id),this.isReady=!0)};setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display=`block`,!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await _r(this.lang,yr,br)}catch{this.onError?.(`Unable to load graph language pack`)}let{GraphEditor:t}=await import(`@interactiveplatform/movika-graph-editor`);this.ngEditor=new t(this.graphWrapperElement,{mode:`view`,lang:this.lang===`ru`?`ru`:`en`,translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on(`control`,({name:e,...t})=>{e===`openPreview`&&`chapterId`in t&&this.onOpenPreviewClick?.(t.chapterId)}),this.ngEditor.on(`zoom`,this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display=`none`,this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function Cr(e){let t=document.createElement(`div`);return t.style.position=`absolute`,t.style.top=`0`,t.style.left=`0`,t.style.height=`100%`,t.style.width=`100%`,t.style.display=`none`,e.append(t),t}var wr=3e3;class Tr{_containers=[];_player=null;setPlayer=e=>{this._player=e};setContainers=e=>{this._containers=e};deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};getNextInteractiveTime=(e=wr)=>{if(!this._containers.length||this._player===null)return null;let t=-1,n=!1,r=Math.round(this._player.info.position$.getValue()*1e3);for(let i of this._containers){let a=i.startTime-e;if(a<=r&&(i.endTime&&r<=i.endTime||i.endTime===null)){n=!0;break}r<a&&(t=t===-1?a:Math.min(t,a))}return!n&&t!==-1?t:null}}class Er{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 n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let n=this.listeners[e]||[];for(let e=n.length;e>0;e--)if(n[e]===t){n.splice(e,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(e=>{e(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}}class Dr{raf;fn;fns=[];constructor(e){e&&(this.fn=e,this.addFn(e))}addFn=(e,t=!1)=>{zt(e)&&(this.fns.push(e),t&&this.updateFn())};removeFn=(e,t=!1)=>{this.fns=this.fns.filter(t=>t!==e),t&&this.updateFn()};updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};requestAnimation=()=>{this.raf||this.forceRequestAnimation()};cancelAnimation=()=>{this.raf&&=(cancelAnimationFrame(this.raf),void 0)};release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}var Or=c(ct(),1);class kr{rootElement;isCssVarsSupported;rootElementProps={};constructor(e){this.rootElement=e,this.isCssVarsSupported=kr.checkCssVarsSupport(e)}static checkCssVarsSupport(e){let t=`--test-key`,n=`test`;e.style.setProperty(t,n);let r=e.style.getPropertyValue(t)===n;return r&&e.style.removeProperty(t),r}getPropValue(e){return this.isCssVarsSupported?`var(${e})`:this.rootElementProps[e]??``}setup(e){if(this.rootElementProps={...this.rootElementProps,...e},this.isCssVarsSupported)for(let[t,n]of Or.default(e))this.rootElement.style.setProperty(t,n)}cleanup(){for(let e in this.rootElementProps)this.rootElement.style.removeProperty(e);this.rootElementProps={}}setProp(e,t){this.rootElementProps[e]=t,this.isCssVarsSupported&&this.rootElement.style.setProperty(e,t)}}import{ValueSubject as Ar}from"@vkontakte/videoplayer-shared/es2024";class jr{loaders;constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return Mr(...this.loaders[e])(t)}}function Mr(...e){return async function(t){let n=[...e];for(;n.length>0;)t=await n.shift()(t);return t}}function Nr(e,t,n){return e?{...e,[t]:e[t]?[n,...e[t]]:[n]}:{[t]:[n]}}function Pr({actions:e,errors:t,chapterId:n,...r}){if(n){let i=e.getManifest();if(i){let a=e.getChapter(i.chapters,n);if(a){let n=e.getMedia(i.media,a.videoId),o=e.getGraph(i.graph,a.id);return n?{...r,actions:e,errors:t,result:{chapter:a,media:n,graph:o}}:{...r,errors:Nr(t,Pr.name,`Could not find media`),actions:e}}}}return{...r,errors:Nr(t,Pr.name,`Could not find chapter`),actions:e}}var{NativeAbortSignal:Fr,NativeAbortController:Ir}=function(e){return{NativeAbortSignal:e.AbortSignal,NativeAbortController:e.AbortController}}(typeof self<`u`?self:global);function Lr(e){let t;try{t=new Event(`abort`)}catch{typeof document<`u`?document.createEvent?(t=document.createEvent(`Event`),t.initEvent(`abort`,!1,!1)):(t=document.createEventObject(),t.type=`abort`):t={type:`abort`,bubbles:!1,cancelable:!1}}return t.reason=e,t}function Rr(e){if(e===void 0)if(typeof document>`u`)e=Error(`This operation was aborted`),e.name=`AbortError`;else try{e=new DOMException(`signal is aborted without reason`),Object.defineProperty(e,`name`,{value:`AbortError`})}catch{e=Error(`This operation was aborted`),e.name=`AbortError`}return e}class zr{constructor(){Object.defineProperty(this,`listeners`,{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;let n=this.listeners[e];for(let e=0,r=n.length;e<r;e++)if(n[e].callback===t){n.splice(e,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let t=this.listeners[e.type].slice();for(let n=0,r=t.length;n<r;n++){let r=t[n];try{r.callback.call(this,e)}catch(e){Promise.resolve().then(()=>{throw e})}r.options&&r.options.once&&this.removeEventListener(e.type,r.callback)}return!e.defaultPrevented}}class Br extends zr{constructor(){super(),this.listeners||zr.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)}throwIfAborted(){let{aborted:e,reason:t=`Aborted`}=this;if(e)throw t}static timeout(e){let t=new Vr;return setTimeout(()=>t.abort(new DOMException(`This signal is timeout in ${e}ms`,`TimeoutError`)),e),t.signal}static any(e){let t=new Vr;function n(){t.abort(this.reason),r()}function r(){for(let t of e)t.removeEventListener(`abort`,n)}for(let r of e)if(r.aborted){t.abort(r.reason);break}else r.addEventListener(`abort`,n);return t.signal}}class Vr{constructor(){Object.defineProperty(this,`signal`,{value:new Br,writable:!0,configurable:!0})}abort(e){let t=Rr(e),n=Lr(t);this.signal.reason=t,this.signal.dispatchEvent(n)}toString(){return`[object AbortController]`}}typeof Symbol<`u`&&Symbol.toStringTag&&(Vr.prototype[Symbol.toStringTag]=`AbortController`,Br.prototype[Symbol.toStringTag]=`AbortSignal`);function Hr(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log(`__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill`),!0):typeof e.Request==`function`&&!e.Request.prototype.hasOwnProperty(`signal`)||!e.AbortController}function Ur(e){typeof e==`function`&&(e={fetch:e});let{fetch:t,Request:n=t.Request,AbortController:r,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=e;if(!Hr({fetch:t,Request:n,AbortController:r,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:t,Request:a};let a=n;(a&&!a.prototype.hasOwnProperty(`signal`)||i)&&(a=function(e,t){let r;t&&t.signal&&(r=t.signal,delete t.signal);let i=new n(e,t);return r&&Object.defineProperty(i,`signal`,{writable:!1,enumerable:!1,configurable:!0,value:r}),i},a.prototype=n.prototype);let o=t;return{fetch:(e,t)=>{let n=a&&a.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(n){let r;try{r=new DOMException(`Aborted`,`AbortError`)}catch{r=Error(`Aborted`),r.name=`AbortError`}if(n.aborted)return Promise.reject(r);let i=new Promise((e,t)=>{n.addEventListener(`abort`,()=>t(r),{once:!0})});return t&&t.signal&&delete t.signal,Promise.race([i,o(e,t)])}return o(e,t)},Request:a}}var Z=typeof globalThis==`object`&&globalThis||typeof window==`object`&&window,Wr=`fetch`in Z&&Hr({fetch:Z.fetch,Request:Z.Request,AbortController:Z.AbortController}),Gr=Wr?Ur({fetch:Z.fetch,Request:Z.Request,AbortController:Z.AbortController}):void 0,Kr=Wr?Gr.fetch:Z.fetch;Wr?Gr.Request:Z.Request,Wr||Z.AbortController,Wr||Z.AbortSignal;var qr=(e=``,t=``)=>{let n=e.split(`.`),r=t.split(`.`),i=0;for(let e=0;e<Math.max(n.length,r.length)&&!i;e++)i=n[e]>r[e]?1:n[e]<r[e]?-1:0;return i},Jr=async e=>{try{let t={},n;if(It(e)){n=new URL(e).href;let r=await Kr(n);if(!r.ok)return{};t=await r.json()}else if(Ft(e))t=e;else return{};if(!gn(t))return{};let r=t.metadata.media;if(It(r)&&!(`media`in t))try{let e;n?e=new URL(r,n).href:(e=new URL(r).href,n=e);let i=await Kr(e);if(!i.ok)throw Error();t.metadata.media=await i.json()}catch{return ti(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:n}}catch{return{}}};async function Yr(e){let{manifest:t,manifestURL:n}=await Jr(e);if(!t)throw Error(`Failed on fetch`);let r=mn(t);return r.media=$r(r.media,n),delete r.metadata.media,r}function Xr(e,t){if(t)return e.find(e=>e.id===t)}function Zr(e,t){if(e.edit?.chapters)return e.edit.chapters.find(e=>e.id===t);if(e.view?.chapters)return e.view.chapters.find(e=>e.id===t)}function Qr(e,t){return e.videos.find(e=>e.id===t)}function $r(e,t){return{...e,videos:e.videos.map(e=>({...e,variants:e.variants.map(e=>{let n=`url`in e?e.url:``,r=ei(n,t);return{...e,url:r||n}})}))}}function ei(e=``,t){try{return new URL(e,t).href}catch{return``}}function ti(e){return qr(e,`3.2.0`)>=0}class ni extends jr{manifest=null;chapter=null;media=null;graph=null;prevChapter$=new Ar(null);onError;constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(e){this.release();let t=await this.exec(`manifestLoaders`,{actions:{addErrorMessage:Nr},result:null,errors:null,source:e});return t.errors&&this.errorHandler(t.errors),this.manifest=await Yr(t.result??e),this}async setInitial(){return this.setNext()}async setNext(e=this.manifest?.metadata.initChapterId){if(!e)return this;this.prevChapter$.next(this.chapter);let t=await this.exec(`chapterLoaders`,Pr({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Zr,getChapter:Xr,getMedia:Qr,getByBranches:this.getByBranches.bind(this),addErrorMessage:Nr},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),t.result&&(this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.result.graph),this}errorHandler(e){this.onError(e),console.error(`Something went wrong with loaders`,{errors:e})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(e=this.manifest?.metadata.initChapterId){if(!e||!this.manifest)return null;let t=Xr(this.manifest.chapters,e);if(t){let e=Qr(this.manifest.media,t.videoId),n=Zr(this.manifest.graph,t.id);if(e)return{chapter:t,media:e,graph:n}}return null}getBranches(e=this.chapter?.id){if(e===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let t=Xr(this.manifest?.chapters||[],e);return this.getByBranches(t?.branches)}}getByBranches(e=[]){return e.reduce((e,t)=>{let n=this.getByChapterId(t.chapterId);return n&&e.push(n),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?V(this.chapter):!1}}var ri=c(ft(),1);import{Player as ii}from"@vkontakte/videoplayer-core/es2024";import{Subscription as ai,TracerFactory as oi,ValueSubject as si}from"@vkontakte/videoplayer-shared/es2024";var ci=e=>{let t=e.variants.find(e=>e.payload?.type===`vk`);if(t&&t.payload){let[e,n]=t.payload.id.split(`_`);return[e,n]}return[]},li=c(ft(),1);function ui(){let e=new Map;function t({listId:t=Math.random().toString(),itemId:n=Math.random().toString(),...r}){let i=e.get(t),a={...r};return i?i[n]=a:e.set(t,{[n]:a}),{listId:t,itemId:n,...r}}function n(e){e.player.destroy(),e.container.remove(),e.subscription.unsubscribe(),e.statistics?.oneStat.destroy(),e.statistics?.statSubscription.unsubscribe()}function r(t,r){let i=e.get(t);if(!i)throw Error(`Can't remove. Not find.`);if(r){let a=i[r];a&&n(a),delete i[r],Object.keys(i).length||e.delete(t)}else{for(let e of li.default(i))n(e);e.delete(t)}}function i(){for(let t of e)r(t[0])}return{createPlayer:t,removePlayer:r,map:e,removeAll:i}}var di=c(ze(),1),fi=c(ze(),1),pi=(e,...t)=>typeof e==`string`?e.includes(...t):fi.default(e,...t);function mi(e,t=[]){let n={},r,i=!t.length;for(let a of e.variants)if(!r&&`cover`in a&&(r=a.cover),`url`in a)switch(a.type.toLowerCase()){case`mp4`:(i||di.default(t,`mp4`))&&(n.MPEG={...n.MPEG,[a.standard??`Invariant quality`]:a.url});break;case`mpeg`:(i||di.default(t,`mpeg`))&&(n.MPEG={...n.MPEG,[a.standard??`Invariant quality`]:a.url});break;case`hls`:(i||di.default(t,`hls`))&&(n={...n,HLS:{type:`url`,url:a.url}});break;case`dash`:(i||di.default(t,`dash`))&&(n={...n,DASH_SEP:{compatibilityMode:!0,type:`url`,url:a.url}});break;default:break}return{sources:n,thumbUrl:r,title:e.title??``}}var hi=(e,t)=>{let n=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();n!==t&&pi(r,t)&&(e.setQuality(t),e.setAutoQuality(!1))},gi=2;function _i(e){let t=ui(),n=new ai,r={},i=null,a=!1,o,s=new si(null);e&&c(e);function c(e){i=e}function l(e,n,o){if(!i)throw Error(`need to set interactive controller`);if(!i.options)return;let c=(t.map.get(e)??{})[n];if(c){r={chapterId:o,listId:e,itemId:n,...c};let l=r.player;r.subscription.add(l.info.currentQuality$.subscribe(e=>{let n=l.info.position$.getValue(),r=l.info.isAutoQualityEnabled$.getValue();if(!(!e||!n||r))for(let n of t.map)ri.default(n[1]).forEach(({player:t})=>{hi(t,e)})})).add(l.events.started$.subscribe(()=>{u(n)})),c.container.remove(),i.setPlayer(c.player),a||=(i.init(),!0),s.next({player:r.player,config:r.config,statistics:r.statistics});return}throw Error(`Can't set. Not find.`)}async function u(e){if(!i)throw Error(`need to set interactive controller`);if(P(r)||e!==r.itemId)return;let t=i.getChapterBranches(),n=new Set;for(let e of t)n.has(e.media.id)||(await f({media:e.media,chapterId:e.chapter.id,setAsActive:!1,title:e.chapter.label}),n.add(e.media.id))}async function d({chapter:{id:e},manifestVideo:n}){if(P(r)||!i)return;let a=r.player.info.muted$.getValue(),o=r.player.info.currentQuality$.getValue(),s=r.player.info.isAutoQualityEnabled$.getValue(),c=r.player.info.volume$.getValue(),u=r.player.info.currentPlaybackRate$.getValue(),d=!s,p=!1;for(let s of t.map)if(s[0]===n.id&&!i.state.isReplay$.getValue()){let n=Object.keys(s[1]);for(let i of n)i===r.itemId?(n.length<gi||(p=!0),t.removePlayer(s[0],i)):(p=!0,l(s[0],i,e),d?hi(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a),r.player.setPlaybackRate(u))}else t.removePlayer(s[0]);p||(await f({media:n,chapterId:e,setAsActive:!0,playbackRate:u}),d?hi(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a))}async function f({media:e,chapterId:n,prefetch:a=!0,setAsActive:s=!0,autoplay:c=!1,preferredExt:u,title:d,playbackRate:f}){let p=Math.random().toString(),m=document.createElement(`div`);o.append(m);let h;if(i?.options?.vkVideoLoader){let t=ci(e);t.length&&(h=await i.options.vkVideoLoader(...t))}let g={...i?.options?.coreConfig||void 0},_={container:m,sources:mi(e,u).sources,...h?.videos?.[0],title:d,failoverHosts:h?.failoverHosts||[]},v=new ii(g,oi.createRootTracer());v.initVideo(_);let y=null;if(h?.videos&&i?.options.createOneStat){let e=h.videos[0],t=i.options.createOneStat(e),n=new ai;t&&(n.add(t.attachTo(v)),y={oneStat:t,statSubscription:n})}let b=new ai,x=r?.player?.info.isAutoQualityEnabled$.getValue();b.add(v.events.canplay$.subscribe(function(){x||hi(v,r.player.info.currentQuality$.getValue()),f&&v.setPlaybackRate(f)}));let S=t.createPlayer({listId:e.id,itemId:p,player:v,container:m,sources:mi(e,u).sources,config:_,subscription:b,statistics:y});return s&&l(e.id,S.itemId,n),c&&S.player.play(),a&&!c&&S.player.prepare(),{player:S.player,config:S.config,statistics:S.statistics}}function p(){m(),i=null,o.remove()}function m(){n.unsubscribe(),t.removeAll(),r={},a=!1}async function h(){if(!i)throw Error(`need to set interactive controller`);m(),o=document.createElement(`div`);let{media:e,chapter:t}=i.getCurrentChapter();e&&t?(n.add(i.events.chapterChanged$.subscribe(d)),await f({media:e,chapterId:t.id,title:t.label})):console.error(`not found`)}return{map:t.map,removePlayer:t.removePlayer,init:h,setInteractiveController:c,createPlayer:f,removeAll:p,getActivePlayer:function(){return r},activePlayerChanged:s}}var Q={graph:`graph`,interactives:`interactives`,chapterChanged:`chapter-changed`,playerChanged:`player-changed`,manifestChanged:`manifest-changed`,errors:`errors`,eachTick:`eachTick`,historyInited:`history-inited`,historyDestroyed:`history-destroyed`},vi={visibility:`visibility`,watchAgainClicked:`watchAgainClicked`},$={actionChoiceCanceled:`action-choice-canceled`,actionChoice:`action-choice`,actionExecution:`action-execution`,visibility:`visibility`,containerRemoved:`container-removed`,rangeEnded:`range-ended`};import{Subscription as yi}from"@vkontakte/videoplayer-shared/es2024";function bi(e){return function(...t){return e(...t.reverse())}}function xi(e,...t){return(...n)=>Ft(t[0])&&Ft(n[0])?e({...t[0],...n[0]}):e(...t,...n)}class Si{container;branches;selectBranches;subscription;player;interactiveEvents;getContainerEventState;isPermanentText;interactiveTimeOpenUri;disabledControls$;onRemove;globalEventEmitter;gameState;isSelectedControlEvent;isSelectedContainerEvent;globalEvents;onError;disableTextControlContainerVisibilityEvents;features;constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:i,globalEvents:a,globalEventEmitter:o,getContainerEventState:s,permanentTextControls:c,interactiveTimeOpenUri:l,disabledControls$:u,onRemove:d,onError:f,disableTextControlContainerVisibilityEvents:p=!1,features:m}){this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new yi,this.player=e,this.interactiveEvents=i,this.getContainerEventState=s;let h=An(t.container.controls);this.isPermanentText=c&&h,this.disableTextControlContainerVisibilityEvents=p&&h,this.interactiveTimeOpenUri=l,this.disabledControls$=u,this.onRemove=d,this.globalEventEmitter=o,this.gameState=0,this.globalEvents=a,this.onError=f,this.features=m,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(Q.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:$.visibility,visibility:e,isFirst:t}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:`container`,type:`visibility`,visibility:e,isFirst:t})):(this.globalEventEmitter.emit(Q.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:$.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:`container`,type:`visibility`,visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()})),this.subscription.add(this.container.error$.subscribe(this.onError))}hide=()=>{setTimeout(()=>{this.gameState!==4&&(H(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};show=()=>{if(!(this.gameState!==2||this.isSelectedControlEvent))if(this.container.getElement()){let{hasOpenURIEventInCurrentContainer:e}=this.getContainerEventState();if(this.container.show?.(),this.interactiveTimeOpenUri&&e||this.disableTextControlContainerVisibilityEvents)return;this.emitContainerVisibilityEvent(!0,!1)}else{let e={isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(e,t)=>{let{isExpectTime:n,hasOtherExpect:r,hasOpenURIEvent:i,hasOpenURIEventInCurrentContainer:a,isAllOpenURIEventsValid:o,hasShouldOpenNowEvent:s}=this.getContainerEventState(),c=this.interactiveTimeOpenUri&&!a,l=this.interactiveTimeOpenUri&&a;if((!this.interactiveTimeOpenUri||c)&&(this.isSelectedControlEvent=!0),e!==!1){if(!this.selectBranches.state.isExpect&&(!this.interactiveTimeOpenUri||c)){if(this.interactiveTimeOpenUri){let e=!r&&!o&&a;e&&this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-fake-removed`,removeAllOpenURI:e})}this.removeView()}this.emitContainerVisibilityEvent(!1)}if(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect||this.interactiveTimeOpenUri&&i&&this.gameState!==5){if(l){let e=((e,t,n,r)=>!e&&!t&&n||e&&!t&&n&&!r||e&&!t&&n&&r)(n,r,o,this.isSelectedContainerEvent);this.fakeRemoveView(e)}else this.removeView(),this.emitContainerVisibilityEvent(!1);(!n||!r||!s)&&(this.selectBranches.stopExpect(),t())}},isEOV:()=>this.gameState===4},t=xi(this.selectBranches.onControlEvent,e),n=(this.player?.info.duration$.getValue()??1/0)*1e3;this.container.createView({eventCallback:t,videoDurationMs:n}),this.disableTextControlContainerVisibilityEvents||this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};selectContainerEvent(e=!1){let{isExpectEventForCurrentContainer:t}=this.getContainerEventState();this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime??1/0,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,!t&&!this.container.isRemoved&&this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let{isExpectTime:e,hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState(),n=this.interactiveTimeOpenUri?e||t:H(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),t=e instanceof HTMLVideoElement;if(this.features.enableAvPlayerSupport&&(t||=e instanceof HTMLObjectElement&&e?.getAttribute(`type`)===`application/avplayer`),!(t&&e?.readyState)||this.isRemovedOrDestroyed()&&!this.isPermanentText)return;let n=this.player.getExactTime();if(En(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Dn(n,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let e=this.gameState;this.gameState=3,e===2&&this.onEndTime()}else{let{hasOpenURIEventInCurrentContainer:e}=this.getContainerEventState(),t=this.selectBranches.state.isExpect,n=this.interactiveTimeOpenUri&&e;if(n&&!t){let e=this.container.getElement();e&&(e.style.visibility!==`hidden`&&this.container.hide?.(),this.container.isRemoved||this.fakeRemoveView())}!this.isPermanentText&&!n&&this.removeView()}let r=Dn(n,this.container.container),i=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],a={subjectId:this.container.container.id,subjectName:`container`,range:i,currentTime:n,isInteractiveTime:r};this.container.onProgress(n*1e3,r),this.globalEventEmitter.emit(Q.eachTick,a),this.globalEvents.eachTick$.next(a)};onResize(e){this.container.onResize(e)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(e=this.features.controlsHideAnimation){if(e){if(this.isRemovedOrDestroyed())return;this.container.removeNonInteractedControls(!0),this.container.removeView(!0,!0)}else this.container.removeView();this.globalEventEmitter.emit(Q.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:$.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-removed`}),this.gameState=5,this.onRemove?.()}fakeRemoveView(e=!1){this.container.isRemoved||this.globalEvents.interactiveContainerFakeRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-fake-removed`,removeAllOpenURI:e}),this.container.fakeRemove()}updateControlsShadowStyles(e){this.container.updateControlsShadowStyles(e)}toggleBlinkAnimation(e){this.container.toggleBlinkAnimation(e)}isInteracted(){return this.container.isInteracted()}isRemovedOrDestroyed(e=!0){let t=e?this.container.willRemoved:!1;return this.gameState===5||t||this.gameState===6}destroy(e=!1){this.reset(),this.removeView(e),this.gameState=6,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}}var Ci=(e=[])=>e.reduce((e,t,n)=>{if(wn((t?.controls??[]).filter(e=>!_n(e)))){let r=[t.startTime??0,t.endTime??1/0],i={id:t.id,isRemoved:!1};if(!n)e.push({subjects:[i],range:r});else{let t=[],n=-1/0,a=1/0,o=[],s=[];for(let c=0;c<e.length;c++){let l=e[c];if(s.push(...l.subjects),l.range[0]<a&&(a=l.range[0]),l.range[1]>n&&(n=l.range[1]),r[0]>=l.range[0]&&r[1]<=l.range[1])return e[c].subjects.push(i),e;r[0]<l.range[0]&&r[1]>l.range[0]&&(t.push(c),o=o.concat(l.subjects)),r[0]>=l.range[0]&&r[0]<=l.range[1]&&(t.push(c),o=o.concat(l.subjects),r[0]=l.range[0]),r[1]>=l.range[0]&&r[1]<=l.range[1]&&(t.push(c),o=o.concat(l.subjects),r[1]=l.range[1])}if(s.push(i),r[0]<=a&&r[1]>=n)return[{subjects:s,range:r}];t.length&&t.reverse().forEach(t=>{e.splice(t,1)}),e.push({subjects:o.concat([i]),range:r})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),wi=c(ze(),1),Ti=c(ft(),1),Ei=c(wt(),1);function Di(){let e={};function t(){for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&delete e[t]}function n(t){let n={};for(let r in e)+r<=t&&(n[r]=e[r]);return n}function r(t){let n={};for(let r in e)+r>=t&&(n[r]=e[r]);return n}function i({timestamp:t,priority:n,initiator:r}){if(Vt(t)){let i=e[t]??null;if(i&&n&&Ut(n,!0)){let e={},t=i[n];return t&&(e={...e,...t}),e=P(e)?null:e,e&&Ut(r,!0)?e[r]??null:e}return i}return null}function a({timestamp:t,priority:n,initiator:r}){if(Vt(t))if(e[t]){if(n&&Ut(n,!0))if(e[t][n]){if(r&&Ut(r,!0))if(e[t][n][r]){if(delete e[t][n][r],!P(e[t][n]))return!0}else return!1;if(delete e[t][n],!P(e[t]))return!0}else return!1;return delete e[t]}else return!1;return!1}function o({timestamp:t,priority:n,initiator:r,...i}){e[t]?.[n]?.[r]?e[t][n][r].push({...i}):e[t]?.[n]?e[t][n]={...e[t][n],[r]:[{...i}]}:e[t]?e[t]={...e[t],[n]:{[r]:[{...i}]}}:e[t]={[n]:{[r]:[{...i}]}}}return{map:e,remove:a,add:o,removeAll:t,get:i,getLte:n,getGte:r}}var Oi=[B.expect,B.setNextBranch],ki=1/0;function Ai(e,t){let n=e,r,i=ji(t),a=Di(),o,s=()=>{p(),_()},c=e=>{a.add.call(void 0,e),m()},l=(e=[])=>{for(let t of e)if(t.action(),wi.default(Oi,t.actionType))break},u=(e=1/0)=>{let t=Mi(a.get({timestamp:e,priority:`control`})??{}),n=Mi(a.get({timestamp:e,priority:`container`})??{}),r=Mi(a.get({timestamp:e,priority:`chapter`})??{});return[...t,...n,...r]},d=e=>{i.isReady(e)&&l(u(e))},f=()=>{l([...Mi(a.get({timestamp:1/0,priority:`chapter`})??{})])},p=()=>{r&&=(o?.unsubscribe(),void 0)},m=()=>{r||(r=()=>setTimeout(()=>{d(1/0)}),o=n.events.ended$.subscribe(r))},h=e=>{p(),n=e},g=e=>{e.priority===`container`&&i.resetCalled(e.timestamp),a.remove(e)},_=()=>{i.release(),a.removeAll()};return{setPlayer:h,add:c,remove:g,exec:d,execEndOfVideo:f,listen:m,unlisten:p,release:s,containersEventsCallState:i,getPreparedToExecActions:u}}function ji(e){let t=new Map;return{setCalled:({timestamp:e,id:n})=>{let r=t.get(e);r&&r[n]!==void 0&&(r[n]=!0)},setData:(e=[])=>{for(let n of e){let e=n.endTime??ki,r=t.get(e);t.set(e,{...r,[n.id]:!1})}},resetCalled:e=>{let n=t.get(e);if(n)for(let e in n)n[e]=!1},isReady:n=>{let r=t.get(n);if(!r)return!0;let i=Ti.default(r);return e?i.some(e=>e):!i.some(e=>!e)},release:()=>t.clear()}}function Mi(e){return Ei.default(Ti.default(e)).sort(e=>e.actionType===B.expect?-1:1)}var Ni={videoContentHeight:0,videoContentWidth:0},Pi=e=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return Ni;let{clientHeight:r,clientWidth:i}=e.experimental.element$.getValue()||{};if(!(r&&i))return Ni;let a=t/n,o=r/i,s,c;return o>a?(c=i,s=i*a):o<a?(c=r/a,s=r):(c=i,s=r),{videoContentWidth:c,videoContentHeight:s}},Fi=250;function Ii(e){let t,n=new ResizeObserver(e=>{a(e),t=a.bind(null,e)});function r(t){let{parentElement:n,player:r,cssVarsManager:i}=e();if(!n||!r)return;let{videoContentWidth:a,videoContentHeight:o}=Pi(r);i.setup({"--interactive-content-width":`${a}px`,"--interactive-content-height":`${o}px`,"--interactive-width":`${t[0].contentRect.width}px`,"--interactive-height":`${t[0].contentRect.height}px`})}function i(){let{parentElement:t}=e();t.removeAttribute(`style`)}let a=vr(t=>{let{fns:n=[]}=e();r(t);for(let e of n)e()},Fi);function o(){t=void 0,n.disconnect(),i()}return{resizeObserver:n,calc:()=>{t?.()},release:o}}var Li=e=>Math.floor(Math.random()*e),Ri=e=>{let t=e.length,n=1/0,r=null;for(;t--;){let i=e[t],a=i.weight??1;a<n&&(n=a,r=i)}return r},zi=e=>{let t=e.length,n=-1/0,r=null;for(;t--;){let i=e[t],a=i.weight??0;a>n&&(n=a,r=i)}return r},Bi=e=>{let t=e.length;return e[Li(t)]},Vi=1,Hi=e=>{let t=0;for(let n=0;n<e.length;++n)t+=e[n].weight??Vi;let n=Math.random()*t;t=0;for(let r=0;r<e.length-1;++r)if(t+=e[r].weight??Vi,t>=n)return e[r];return e[e.length-1]},Ui={shouldOpenNow:!0,isDetachContainer:!0},Wi=`after-expect`,Gi=(e,t=!1)=>({...e,args:t?{...e.args,...Ui}:{...Ui,...e.args}}),Ki=({globalEventEmitter:e,globalEvents:t,player:n,interactiveEvents:r})=>{let i={isExpect:!1},a=()=>{i.isExpect&&=!1},o=({action:n,controlType:i,controlId:a,containerId:o,branches:s=[],onEvent:c,isEOV:l=()=>!1,isDisabled:d=()=>!1})=>{let f=Gi(n,l()),_={timestamp:1/0,priority:`control`,initiator:a,actionType:f.type},v=d(),y=e.emit.bind(e,Q.interactives,{subjectId:a,subjectType:i,subjectName:`control`,type:v?$.actionChoiceCanceled:$.actionChoice,actionType:n.type,payload:{invokeImmediately:f.args.shouldOpenNow,containerId:o,...f.args}}),b=()=>{t.interactiveActionChoice$.next({subjectId:a,subjectType:i,subjectName:`control`,type:v?`action-choice-canceled`:`action-choice`,actionType:n.type,payload:{invokeImmediately:f.args.shouldOpenNow,containerId:o,...f.args}})};if(v){y(),b();return}switch(f.type.trim().toLowerCase()){case B.setNextBranch.trim().toLowerCase():{let e=s.find(e=>e.id===f.args.branchId);if(!e)return;c(f.args.isDetachContainer,p.bind(null,{subjectId:a,subjectName:`control`})),y(),b(),f.args.shouldOpenNow?h({subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{chapterId:e.chapterId,autoSelect:!1}}):r.add({..._,action:h.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{chapterId:e.chapterId,autoSelect:!1}})});return}case B.continuePlayback.trim().toLowerCase():c(f.args.isDetachContainer,p.bind(null,{subjectId:a,subjectName:`control`})),y(),b(),f.args.shouldOpenNow?m({subjectId:a,subjectName:`control`,subjectType:i,action:n}):r.add({..._,action:m.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:n})});return;case B.openURI.trim().toLowerCase():c(f.args.isDetachContainer,p.bind(null,{subjectId:a,subjectName:`control`})),y(),b(),f.args.shouldOpenNow?g({subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{URI:n.args.uri}}):r.add({..._,action:g.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{URI:n.args.uri}})});return;default:{let e=`Unexpected control event`;u(new j(1,1,{message:e}),e);return}}},s=({action:n,container:{id:i,endTime:a},branches:o=[],isEOV:s=!1,autoSelected:c=!1})=>{let l=Gi(n,s),d={timestamp:!l.args.shouldOpenNow||s?1/0:a??1/0,priority:`container`,initiator:i,actionType:l.type},f=e.emit.bind(e,Q.interactives,{subjectId:i,subjectName:`container`,type:$.actionChoice,actionType:l.type,payload:{invokeImmediately:l.args.shouldOpenNow,...l.args}}),p=()=>{t.interactiveActionChoice$.next({subjectId:i,subjectName:`container`,type:`action-choice`,actionType:l.type,payload:{invokeImmediately:l.args.shouldOpenNow,...l.args}})};switch(l.type.trim().toLowerCase()){case B.setNextBranch.trim().toLowerCase():{let e=o.find(e=>e.id===l.args.branchId);if(!e)return;f(),p(),r.add({...d,action:h.bind(null,{subjectId:i,subjectName:`container`,action:l,payload:{chapterId:e.chapterId,autoSelect:c}})});return}case B.setMaxWeightBranch.trim().toLowerCase():return;case B.setMinWeightBranch.trim().toLowerCase():return;case B.setRandomBranch.trim().toLowerCase():return;case B.setWeightlessRandomBranch.trim().toLowerCase():return;case B.continuePlayback.trim().toLowerCase():f(),p(),r.add({...d,action:m.bind(null,{subjectId:i,subjectName:`container`,action:l})});return;case B.openURI.trim().toLowerCase():f(),p(),r.add({...d,action:g.bind(null,{subjectId:i,subjectName:`container`,action:l,payload:{URI:n.args.uri}})});return;default:{let e=`Unexpected container event`;u(new j(1,1,{message:e}),e);return}}};function c({container:n,branches:a,isEOV:o=!1}){let c=On(n.events);if(c){let a=Gi(c.action,o);e.emit(Q.interactives,{subjectId:n.id,subjectName:`container`,type:$.actionChoice,actionType:a.type,payload:{invokeImmediately:a.args.shouldOpenNow,...a.args}}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`container`,type:`action-choice`,actionType:a.type,payload:{invokeImmediately:a.args.shouldOpenNow,...a.args}}),r.add({timestamp:o?1/0:n.endTime??1/0,priority:`container`,initiator:n.id,actionType:B.expect,action:f.bind(null,{subjectId:n.id,subjectName:`container`})}),i.isExpect=!0}else for(let e of n.events??[])s({action:e.action,container:n,branches:a,isEOV:o})}let l=({chapterId:n,action:r,branches:i=[]})=>{let a=e.emit.bind(e,Q.interactives,{subjectId:n,subjectName:`chapter`,type:$.actionChoice,actionType:r.type,payload:r.args}),o=()=>{t.interactiveActionChoice$.next({subjectId:n,subjectName:`chapter`,type:`action-choice`,actionType:r.type,payload:r.args})};switch(r.type.trim().toLowerCase()){case B.setNextBranch.trim().toLowerCase():{let e=i.find(e=>e.id===r.args.branchId);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setWeightlessRandomBranch.trim().toLowerCase():{let e=Bi(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setRandomBranch.trim().toLowerCase():{let e=Hi(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setMaxWeightBranch.trim().toLowerCase():{let e=zi(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.setMinWeightBranch.trim().toLowerCase():{let e=Ri(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case B.continuePlayback.trim().toLowerCase():return a(),o(),m.bind(null,{subjectId:n,subjectName:`chapter`,action:r});case B.openURI.trim().toLowerCase():return a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{URI:r.args.uri}});default:{let e=`Unexpected chapter event`;u(new j(1,1,{message:e}),e);return}}};function u(n,r){console.error(r),t.error$.next(n),e.emit(Q.errors,n)}function d(n){let i=On(n.events);if(i){if(V(n))return;e.emit(Q.interactives,{subjectId:n.id,subjectName:`chapter`,type:$.actionChoice,actionType:i.action.type,payload:i.action.args}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`chapter`,type:`action-choice`,actionType:i.action.type,payload:i.action.args}),r.add({timestamp:1/0,priority:`chapter`,initiator:n.id,actionType:B.expect,action:f.bind(null,{subjectId:n.id,subjectName:`chapter`})})}else n.events?.forEach(e=>{let t=l({chapterId:n.id,action:e.action,branches:n.branches});t&&r.add({timestamp:1/0,priority:`chapter`,initiator:n.id,actionType:e.action.type,action:t})})}let f=({subjectId:r,subjectName:i})=>{n.pause(),e.emit(Q.interactives,{subjectId:r,subjectName:i,type:$.actionExecution,actionType:B.expect}),t.interactiveActionExecution$.next({subjectId:r,subjectName:i,type:`action-execution`,actionType:B.expect})},p=({subjectId:i,subjectName:a})=>{n.info.isEnded$.getValue()?r.execEndOfVideo():n.play(),e.emit(Q.interactives,{subjectId:i,subjectName:a,type:$.actionExecution,actionType:Wi}),t.interactiveActionExecution$.next({subjectId:i,subjectName:a,type:`action-execution`,actionType:Wi})},m=({subjectId:n,subjectName:r,subjectType:i,action:a})=>{e.emit(Q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:$.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})},h=({subjectId:n,subjectName:r,subjectType:i,action:a,payload:o})=>{o.behaviour=`change-chapter`,e.emit(Q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:$.actionExecution,actionType:a.type,payload:o}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type,payload:o})},g=({subjectId:n,subjectName:r,subjectType:i,action:a,payload:o})=>{if(!o.URI)return;let s=window.open(o.URI,`_blank`,`noopener,noreferrer`);s&&(s.opener=null),e.emit(Q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:$.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})};return{onControlEvent:o,onContainerEvent:s,onChapterEvent:l,onExpectEvent:f,expectEventHandler:p,setManifestChapterEvents:d,setManifestContainerEvents:c,stopExpect:a,state:i}};import{Subscription as qi,Subject as Ji,ValueSubject as Yi}from"@vkontakte/videoplayer-shared/es2024";var Xi=(e,t)=>{let n={};return e.map(e=>{if(!n[e]){let r=t.chapters.find(t=>t.id===e);if(!r)return null;let i=t.media.videos.find(e=>r.videoId===e.id);if(!i)return null;n[e]=$i(i)}return n[e]}).filter(e=>e!==null)},Zi=e=>{for(let t of e.variants)if(Qi(t)&&t.payload)return t.payload.id},Qi=e=>!!(e.type===`custom`&&e.payload&&e.payload.type===`vk`),$i=e=>{let t=Zi(e);if(!t)return null;let n=t.split(`_`).pop();return n?parseInt(n,10):null},ea=(e,t)=>{for(let n of e.media.videos)if(t===$i(n)){for(let t of e.chapters)if(t.videoId===n.id)return t.id;return}},ta=(e,t)=>e.reduce((e,n)=>{let r=ea(t,n);return r?[...e,r]:e},[]);class na{state={history$:new Yi([]),hasPrevChapter$:new Yi(!1),prevChapter$:new Yi(null),isInitialChapter$:new Yi(!1),isGoBackLimited$:new Yi(!1)};#api=null;#settings;#inited=!1;#manifest=null;#videoIds=null;events={inited$:new Ji,destroyed$:new Ji,error$:new Ji};#rootVid=null;#interactiveController=null;#globalEventEmitter=null;#subscription=new qi;#isGoBackUpdate=!1;#goBackCounter=0;constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:i}){this.#rootVid=t,this.#globalEventEmitter=e,this.#interactiveController=n,this.#api=r,this.#settings=i,this.state.history$&&this.#subscription&&this.#subscription?.add(this.state.history$.subscribe(e=>{this.state.prevChapter$.next(lr(e,-2)||null),this.state.hasPrevChapter$.next(e.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#manifest?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#goBackCounter===this.#settings.maxLength-1)}))}async setManifest(e){if(!this.#interactiveController||!this.#globalEventEmitter)return;this.#manifest=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#interactiveController.setChapter({chapterId:t,pushToHistory:!1}),this.#inited||(this.#inited=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#inited}async updateHistory(e,t=!0){if(!this.#manifest)return;this.#isGoBackUpdate?(this.#isGoBackUpdate=!1,this.#goBackCounter++):this.#goBackCounter=0;let n=this.#manifest,r=e.length-this.#settings.maxLength,i=r>0?e.slice(r):e,a=Xi(i,n);if(this.#videoIds=a,this.state.history$.next(i),!(!t||!this.#api||!this.#rootVid))try{await this.#api.save(this.#rootVid,a)}catch{let e=new j(1,5,`Unable to save interactive history`);this.events.error$.next(e),this.#globalEventEmitter?.emit(Q.errors,e)}}async goBack(){if(!this.state||!this.#interactiveController){let e=new j(1,5,`Unable to save interactive history`);this.events.error$.next(e),this.#globalEventEmitter?.emit(Q.errors,e);return}this.#isGoBackUpdate=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#interactiveController.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#manifest||!this.#rootVid)return;let e=this.#manifest,t=[this.getInitialVideoId()];if(this.#api)try{let e=await this.#api.get(this.#rootVid);e.length&&(t=e)}catch{let e=new j(1,5,`Error while trying to fetch data`);this.events.error$.next(e),this.#globalEventEmitter?.emit(Q.errors,e)}let n=ta(t,e);this.state.history$.next(n)}getInitialChapterId(){let e=this.state.history$.getValue();return(e==null?void 0:lr(e,-1))||this.#settings.initChapterId||this.#manifest?.metadata.initChapterId}getInitialVideoId(){return this.#manifest?Xi([this.getInitialChapterId()],this.#manifest).pop():null}destroy(){this.#rootVid=null,this.#api=null,this.#interactiveController=null,this.#subscription?.unsubscribe(),this.#subscription=null,this.#inited=!1,this.#globalEventEmitter?.emit(Q.historyDestroyed),this.events.destroyed$.next(),this.#globalEventEmitter=null}}class ra{rootElement;canvasImgSrc;_prevSizeId=0;constructor(){this.rootElement=document.createElement(`canvas`)}clear(){this.rootElement.getContext(`2d`)?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext(`2d`)?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let e=3;e<n;e+=40)if(t[e]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility=`visible`}hide(){this.rootElement.style.visibility=`hidden`}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){this.canvasImgSrc&&this.rootElement.getContext(`2d`)?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL(`image/jpeg`,1),t=new Image;return t.crossOrigin=`anonymous`,t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext(`2d`)?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}}class ia{lastFrameCanvas;endOffsetMs;currentChapter;currentVideoDurationMs=1/0;rootElement;_containerTimeFrameShouldReceived=!1;_endTimeFrameReceived=!1;_shouldCallSkip=!1;_callbacks;constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.rootElement=document.createElement(`div`),this.rootElement.style.cssText=`
7
7
  position: absolute;
8
8
  top: 0;
9
9
  left: 0;