@vkontakte/videoplayer-interactive 1.0.71 → 1.0.72-dev.abb27aca7.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/es2015.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.71
3
- * Wed, 01 Jul 2026 15:20:09 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-71/doc/
2
+ * @vkontakte/videoplayer-interactive v1.0.72-dev.abb27aca7.0
3
+ * Thu, 02 Jul 2026 09:03:32 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-72/doc/
5
5
  */
6
- import{fromEvent as ae,Subscription as oe}from"@vkontakte/videoplayer-shared/es2015";import{Subject as le}from"@vkontakte/videoplayer-shared/es2015";import{fromEvent as A,once as pe}from"@vkontakte/videoplayer-shared/es2015";import{fromEvent as Ne,Subject as Pe,Subscription as Fe}from"@vkontakte/videoplayer-shared/es2015";import{arrayIncludes as Ue}from"@vkontakte/videoplayer-shared/es2015";import{isSupportedManifest as We,ContainerTypes as Ge,ControlTypes as Ke,EventActionTypes as I,EventTypes as qe,migrateManifestToLatestVersion as Je}from"@interactiveplatform/movika-manifest";import{fromEvent as H,once as bt}from"@vkontakte/videoplayer-shared/es2015";import{combine as Vt,InterfaceLanguage as Ht,Observable as Ut,once as Wt,Subject as G,Subscription as Gt,ValueSubject as K,fromEvent as Kt}from"@vkontakte/videoplayer-shared/es2015";import{InteractiveInterfaceClick as qt}from"@vkontakte/videoplayer-statistics/es2015";import{loadVKLangPack as Jt}from"@vkontakte/videoplayer-shared/es2015";import{objectEntries as on}from"@vkontakte/videoplayer-shared/es2015";import{ValueSubject as cn}from"@vkontakte/videoplayer-shared/es2015";import{fetchPolyfilled as pn}from"@vkontakte/videoplayer-shared/es2015";import{objectValues as Tn}from"@vkontakte/videoplayer-shared/es2015";import{Player as En}from"@vkontakte/videoplayer-core/es2015";import{Subscription as Dn,TracerFactory as On,ValueSubject as kn}from"@vkontakte/videoplayer-shared/es2015";import{objectValues as jn}from"@vkontakte/videoplayer-shared/es2015";import{arrayIncludes as Nn}from"@vkontakte/videoplayer-shared/es2015";import{Subscription as zn}from"@vkontakte/videoplayer-shared/es2015";import{arrayIncludes as Wn}from"@vkontakte/videoplayer-shared/es2015";import{objectValues as Gn}from"@vkontakte/videoplayer-shared/es2015";import{arrayFlat as Kn}from"@vkontakte/videoplayer-shared/es2015";import{Subscription as pr,Subject as mr,ValueSubject as hr}from"@vkontakte/videoplayer-shared/es2015";import{clientChecker as Pr}from"@vkontakte/videoplayer-core/es2015";var _oxcModd8h2c7=function(){function e(t){"@babel/helpers - typeof";return e=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},e(t)}var t=e;function n(e,n){if(t(e)!=`object`||!e)return e;var r=e[Symbol._oxc_toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(t(i)!=`object`)return i;throw TypeError(`@@_oxc_toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}var t=e,r=n;function i(e){var n=r(e,`string`);return t(n)==`symbol`?n:n+``}var a=i;function o(e,t,n){return(t=a(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s=o;function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?c(Object(n),!0).forEach(function(t){s(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function u(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function d(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){u(a,r,i,o,s,`next`,e)}function s(e){u(a,r,i,o,s,`throw`,e)}o(void 0)})}}function f(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}var p=f;function m(e,t){if(e==null)return{};var n,r,i=p(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function h(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}var g=h;function _(e,t,n){g(e,t),t.set(e,n)}function v(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}var y=v;function b(e,t,n){return e.set(y(e,t),n),n}var y=v;function ee(e,t){return e.get(y(e,t))}const x=[`name`],te=[`actions`,`errors`,`chapterId`],ne=[`listId`,`itemId`],re=[`timestamp`,`priority`,`initiator`],S=[`statistics`];var C=l,w=d,T=m,E=_,D=b,O=ee,ie=`1.0.71`;class se{constructor(e,t){this.layout=void 0,this.cssVarsManager=void 0,this.layout=e,this.cssVarsManager=t}}class ce extends se{constructor(e,t){super(e,t),this.cssVarsManager=void 0,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))`}}function ue(e){return`features`in e}class k{constructor(e,t,...n){this.severity=void 0,this.category=void 0,this.data=void 0,this.severity=e,this.category=t,this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null,` `)}`}}function de({emitter$:e,error:t,subjectId:n,message:r=``,severity:i=1,category:a=1}){let o=new k(i,a,{message:r,error:t,details:{id:n}});e.next(o)}class fe{constructor(e,t,n){this.container=void 0,this.options=void 0,this.factories=void 0,this.controls=void 0,this.error$=new le,this.cssVarsManager=void 0,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&&ue(this.options)&&this.options.features[e])}onError(e=``,t){de({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]},[])||[]}}var j=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,M=e=>j(e,`Object`),me=e=>j(e,`String`),he=e=>j(e,`Array`),ge=e=>j(e,`Number`),_e=e=>j(e,`Function`),ve=e=>j(e,`Boolean`),ye=e=>ge(e)&&!isNaN(e),be=e=>M(e)&&Object.keys(e).length===0,xe=e=>he(e)&&!e.length,Se=(e,t)=>me(e)&&!!(t?e.trim():e).length;function Ce(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 we=`interactive`,N={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},Te;(e=>{e.top=`flex-start`,e.bottom=`flex-end`,e.center=`center`})(Te||={});var Ee;(e=>{e.start=`flex-start`,e.end=`flex-end`,e.center=`center`})(Ee||={});var De=({target:e,props:t})=>{e.style.alignItems=(t?.gravityVertical&&Te[t.gravityVertical])??`center`,e.style.justifyContent=(t?.gravityHorizontal&&Ee[t.gravityHorizontal])??`center`,e.style.textAlign=t?.alignment??`center`},Oe=({target:e,props:t,fallback:n,dependsOn:r})=>{var i,a,o;e.style.color=(t==null||(i=t.text)==null?void 0:i.color)??n.textColor,e.style.fontSize=`calc(${r.height} * ${(t==null||(a=t.text)==null?void 0:a.size)??n.textSize})`,e.textContent=(t==null||(o=t.text)==null?void 0:o.value)??n.textContent},ke=({target:e,props:t,fallback:n})=>{var r,i;e.style.backgroundColor=Ce((t==null||(r=t.background)==null?void 0:r.color)??n.backgroundColor,(t==null||(i=t.background)==null?void 0:i.alpha)??n.backgroundAlpha)},Ae=({target:e,props:t,fallback:n,dependsOn:r,useRawValues:i=!1})=>{var a,o,s,c;let l=i?n.borderWidthRawValue:`calc(${r.height} * ${(t==null||(a=t.shape)==null||(a=a.border)==null?void 0:a.width)??n.borderWidth})`,u=i?n.roundCornersRawValue:`calc(${r.height} * ${(t==null||(o=t.shape)==null?void 0:o.roundCorners)??n.roundCorners})`;e.style.borderWidth=l,e.style.borderStyle=`solid`,e.style.borderColor=Ce(i?n.borderColor:(t==null||(s=t.shape)==null||(s=s.border)==null?void 0:s.color)??n.borderColor,i?n.borderAlpha:(t==null||(c=t.shape)==null||(c=c.border)==null?void 0:c.alpha)??n.borderAlpha),e.style.borderRadius=u},je=({target:e,isDark:t,baseDimension:n,fallback:r})=>{let i=Ce(r.shadowColorLight,r.shadowColorAlpha),a=Ce(r.shadowColorDark,r.shadowColorAlpha),o=`0px 0px ${`calc(${n} * 0.25)`} ${`calc(${n} * 0.11)`} ${t?a:i}`;e.style.boxShadow=o},Me=({target:e,layoutParams:t,fallback:n})=>{let r=t.angle??n.angle;r&&=r*-1,e.style.transform=`rotate(${r}rad)`};var Ie=`interactive-control-tap`,Le={common:Ie,animation:`${Ie}-animation`,visible:`${Ie}-visible`},Re=60;class ze{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=Re,useDimensionsBasedSize:r=!1}){this.element=void 0,this.controlRotateAngleRad=void 0,this.clickCancelCondition=void 0,this.circleDiameterPx=void 0,this.useDimensionsBasedSize=void 0,this.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=Be(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(Le.visible,Le.animation)},this.onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(Le.visible,Le.animation)};let i=document.createElement(`div`);i.classList.add(Le.common),this.controlRotateAngleRad=e,this.element=i,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=r}}function Be(e,t,n){return{x:e*Math.cos(n)-t*Math.sin(n),y:e*Math.sin(n)+t*Math.cos(n)}}function Ve(e){return`features`in e}var P=`interactive-control`,F={common:P,selected:`${P}-selected`,wrapper:`${P}-wrapper`,disabled:`${P}-disabled`,button:`${P}-button`,area:`${P}-area`,text:`${P}-text`,blinkAnim:`${P}-blink-anim`,blinkAnimButton:`${P}-blink-anim-button`,blinkAnimArea:`${P}-blink-anim-area`},He=40;var Ye={metadata:`Object`,chapters:`Array`},Xe=e=>{if(!M(e))return!1;for(let t in Ye){let n=e[t];if(!n||!j(n,Ye[t]))return!1}return We(e.metadata.version)};function Ze(e){return e.type===Ke.Text}function Qe(e){return e.type===Ke.Button}function $e(e){return e.type===Ke.Area}var et={Choice:`Choice`,TextInput:`TextInput`},tt={Button:`Button`,Area:`Area`,Text:`Text`},nt={onClick:`onClick`,onSuspense:`onSuspense`},rt={openURI:`openURI`,setNextBranch:`setNextBranch`,setWeightlessRandomBranch:`setWeightlessRandomBranch`,setRandomBranch:`setRandomBranch`,setMaxWeightBranch:`setMaxWeightBranch`,setMinWeightBranch:`setMinWeightBranch`,setDefaultBranch:`setDefaultBranch`,continuePlayback:`continuePlayback`,expect:`expect`},it=e=>he(e)&&!xe(e),L=e=>e.order===`end`,at=e=>he(e.containers)&&!xe(e.containers)&&L(e),ot=(e,t)=>{let n=e*1e3;return it(t.controls)&&n<(t.startTime??0)},st=(e,t)=>{let n=e*1e3;return it(t.controls)&&n>=(t.startTime??0)&&n<=(t.endTime??1/0)},R=(e=[])=>e.some(e=>e.action.type===`expect`),ct=(e=[])=>e.find(e=>e.action.type===`expect`),lt=e=>e?.length===1,ut=e=>lt(e)&&Ze(e[0]);function dt(e=[],t=1/0,n=[]){return e.filter(({container:e})=>!Ue(n,e.container.id)&&R(e.container.events)&&e.container.endTime===t&&!e.isRemoved&&!e.willRemoved)}function ft({gameControllers:e=[],subjectName:t,subjectId:n,execFn:r}){for(let i of e)if(t===`container`&&i.container.container.id===n){r(i),dt(e,i.container.container.endTime,[i.container.container.id]).forEach(e=>{r(e)});break}}function pt(e){for(let t of e.events)if(t.action.type===`openURI`)return!0;return!1}var mt=(e,t)=>{let n=R(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===I.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=dt(t,e.endTime,[e.id]).length,s=e=>e.controls.some(e=>e.events?.some(e=>{var t;return(t=e.action)==null||(t=t.args)==null?void 0:t.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 z{constructor(e,t=void 0){this.control=void 0,this.options=void 0,this.container=null,this.controlElement=null,this.subscriptions=new Fe,this.error$=new Pe,this.controlTap=void 0,this.isInteracted=!1,this.isRemoved=!1,this.cssVarsManager=null,this.onControlSelect=()=>{var e;this.container?.isManifestContainerDisabled()||pt(this.control)||(e=this.container)==null||(e=e.element)==null||e.classList.add(`interactive-control-wrapper-selected`)},this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()},this.control=e,this.options=t}setCssVarsManager(e){this.cssVarsManager=e}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(Ne(t,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${z.name} remove view transition error`,e))).add(Ne(t,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${z.name} remove view transition error`,e)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e=``,t){de({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){if(this.featureIsEnabled(`controlsTapPlace`)&&this.container){let t=this.control.layoutParams.angle??N.angle;this.controlTap=new ze({controlRotateAngleRad:t,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?He:void 0}),this.subscriptions.add(Ne(e,`click`).subscribe(this.controlTap.onElementClick,e=>this.onError(`Control click tap animation error`,e))).add(Ne(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(F.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??N.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},r=()=>e.isContainerDisabled?.call(e)??!1;this.container={element:t,dimensions:n,isManifestContainerDisabled:r}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&Ve(this.options)&&this.options.features[e])}isTouch(){return!!(this.options&&Ve(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(Ne(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 ht=`interactive-blink-anim-reference`,B={common:ht,animation:`${ht}-animation`,disabled:`${ht}-disabled`};class gt{constructor(){this._RAFId=0,this._element=void 0}get element(){return this._element}create(){if(this._element)return;let e=document.createElement(`div`);e.classList.add(B.common,B.animation),this._element=e}restart(){this._element&&(this._element.classList.add(B.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(B.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&=(cancelAnimationFrame(this._RAFId),0)}destroy(){this.cleanupRAF(),this._element=void 0}}var _t=`interactive-container`,V={common:_t,hidden:`${_t}-hidden`,disabled:`${_t}-disabled`},vt=(e,t)=>{if(e.type.trim().toLowerCase()===`area`)return new yt(e,t)};class yt extends z{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(F.common,F.area),n.setAttribute(`data-testid`,`int_area`),ke({target:n,props:this.control.props,fallback:C(C({},N),{},{backgroundColor:`transparent`})}),Me({target:n,layoutParams:this.control.layoutParams,fallback:N}),this.addControlTap(n),this.subscriptions.add(A(this.container.element,`click`).pipe(pe()).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(A(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(V.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${B.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(A(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(V.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(A(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(F.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(F.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(ve(e)){var t;let n=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+`px`;je({target:this.controlElement,props:this.control.props,fallback:N,isDark:e,baseDimension:n}),Ae({target:this.controlElement,props:this.control.props,fallback:C(C({},N),{},{borderColor:e?N.shadowColorDark:N.shadowColorLight,borderAlpha:1,borderWidthRawValue:`0.1px`,roundCornersRawValue:`calc(${this.container.dimensions.height} * ${((t=this.control.props)==null||(t=t.shape)==null?void 0:t.roundCorners)??N.roundCorners})`}),dependsOn:this.container.dimensions,useRawValues:!0})}else Ae({target:this.controlElement,props:this.control.props,fallback:C(C({},N),{},{borderAlpha:0}),dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(F.blinkAnim,e),this.controlElement?.classList.toggle(F.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${F.blinkAnimArea}`)||this.controlElement.classList.contains(F.selected)||this.controlElement.classList.contains(B.disabled)||(this.controlElement.classList.add(B.disabled),this.subscriptions.add(A(e,`animationiteration`).pipe(pe()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(B.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${F.blinkAnimArea}`)||this.controlElement.classList.contains(F.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(){}}var xt=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}},St=Math.PI,Ct=2*St,wt=St/2,Tt=3*wt,Et=[0,wt,St,Tt];function Dt(e){return e===wt}function Ot(e){return e===St}function kt(e){return e===Tt}function At(e){return(e%Ct+Ct)%Ct}function jt(e){for(let t of Et)if(e===t)return t}function Mt(e){return jt(e)?null:[1,2,3,4][Math.floor(e/wt)+1-1]}function Nt(e){return e*180/Math.PI}var U=`interactive-control-fill-animation`,W={common:U,fillerWrapper:`${U}-filler-wrapper`,filler:`${U}-filler`,fillHeight:`${U}-fill-height`,fillWidth:`${U}-fill-width`,fromTop:`${U}-from-top`,fromBottom:`${U}-from-bottom`,fromLeft:`${U}-from-left`,fromRight:`${U}-from-right`};class Pt{constructor(e){this.fillAnimationElement=void 0,this.fillAnimationFillerElement=void 0,this.fillAnimationFillerWrapperElement=void 0,this.startTime=void 0,this.endTime=void 0,this.shouldFillHeight=void 0,this.widthExpansionCoef=0,this.isDebug=void 0,this.fromLeft=void 0,this.useSkew=void 0,this.rotateAngle=void 0;let t=document.createElement(`div`);t.classList.add(W.common);let n=document.createElement(`div`);n.classList.add(W.fillerWrapper);let r=document.createElement(`div`);r.classList.add(W.filler),n.append(r),t.append(n);let i=At(e.rotateAngle),a=Mt(i),o=a!==null,s=a===2||!o&&Ot(i)||a===3,c=!o&&Dt(i),l=!o&&kt(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(W.fillHeight,c?W.fromTop:W.fromBottom),n.classList.add(W.fillHeight,c?W.fromTop:W.fromBottom)):(r.classList.add(W.fillWidth,u?W.fromLeft:W.fromRight),n.classList.add(W.fillWidth)),e.debug&&console.log(`[interactive ${Pt.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:d,rotateAngleRad:i,rotateAngelDeg:Nt(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 Ft=(e,t)=>{if(e.type.trim().toLowerCase()===`button`)return new It(e,t)};class It extends z{constructor(e,t){super(e,t),this.startTime=void 0,this.endTime=void 0,this.controlFillAnimation=void 0}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(F.common,F.button),n.setAttribute(`data-testid`,`int_bttn`),Me({target:n,layoutParams:this.control.layoutParams,fallback:N}),ke({target:n,props:this.control.props,fallback:N}),Ae({target:n,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),De({target:n,props:C(C({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=xt(this.control.type.trim().toLowerCase());Oe({target:r.firstElementChild??r,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),this.addControlTap(n),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled(`controlsFillAnimation`)&&(this.controlFillAnimation=new Pt({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??N.angle,borderRadius:n.style.borderRadius})),this.subscriptions.add(H(n,`click`).pipe(bt()).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(H(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(V.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${B.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(H(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(V.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(H(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(F.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(F.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(F.blinkAnim,e),this.controlElement?.classList.toggle(F.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${F.blinkAnimButton}`)||this.controlElement.classList.contains(F.selected)||this.controlElement.classList.contains(B.disabled)||(this.controlElement.classList.add(B.disabled),this.subscriptions.add(H(e,`animationiteration`).pipe(bt()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(B.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${F.blinkAnimButton}`)||this.controlElement.classList.contains(F.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 Lt=(e,t)=>{if(e.type.trim().toLowerCase()===`text`)return new Rt(e,t)};class Rt extends z{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(F.common,F.text),n.setAttribute(`data-testid`,`int_text`),Me({target:n,layoutParams:this.control.layoutParams,fallback:N}),De({target:n,props:C(C({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=xt(this.control.type.trim().toLowerCase());Oe({target:r.firstElementChild??r,props:this.control.props,fallback:N,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 zt=(e,t,n,r)=>{if(e.type.trim().toLowerCase()===`choice`)return new Bt(e,t,n,r)};class Bt extends fe{constructor(e,t,n,r){super(e,n,r),this.rootElement=void 0,this.containerElement=null,this.layout=void 0,this.subscriptions=new oe,this.isRemoved=void 0,this.isDisabled=void 0,this.willRemoved=void 0,this.cssVarsManager=void 0,this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()},this.rootElement=t,this.layout=new ce(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory(`button`,Ft),this.addControlFactory(`text`,Lt),this.addControlFactory(`area`,vt)}createView({eventCallback:e,videoDurationMs:t}){let n=document.createElement(`div`);return n.classList.add(V.common,V.disabled),n.setAttribute(`data-subjectId`,this.container.id),requestAnimationFrame(()=>{n.classList.remove(V.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(V.hidden)}show(){let e=this.getElement();e&&e.classList.remove(V.hidden)}enable(){let e=this.getElement();e&&(e.classList.remove(V.disabled),this.controls.forEach(e=>e.enable()),this.isDisabled=!1)}disable(){let e=this.getElement();e&&(e.classList.add(V.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(ae(n,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${Bt.name} remove view transition error`,e))).add(ae(n,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${Bt.name} remove view transition error`,e)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}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))}}function Yt(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}var Xt=`video_interactive`,Zt=`videoint`,Qt=250;class $t{constructor(e){this.isHidden=void 0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=void 0,this.onOpenPreviewClick=void 0,this.onError=void 0,this.lang=void 0,this.zoom=void 0,this.lastZoomInfo=void 0,this.isReady=void 0,this.ngEditor=void 0,this.ngEditorSize=void 0,this.graphWrapperElement=void 0,this.resizeObserver=void 0,this.manifest=void 0,this.handleZoomChange=Yt(e=>{this.lastZoomInfo=e},Qt),this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}},this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.call(this,`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}},this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!ge(e.graph.edit.chapters[0].x)){this.onError?.call(this,`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)},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=en(e),this.resizeObserver=new ResizeObserver(Yt(this.onResize,Qt)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}show(){var e=this;return w(function*(){e.manifest&&(e.ngEditor||(yield e.initNgEditor()),e.graphWrapperElement.style.display=`block`,!e.lastZoomInfo&&e.currentChapterId&&e.ngEditor?.focusChapter(e.currentChapterId),e.isHidden=!1)})()}initNgEditor(){var e=this;return w(function*(){if(!e.manifest)return;let t;try{t=yield Jt(e.lang,Xt,Zt)}catch{e.onError?.call(e,`Unable to load graph language pack`)}let{GraphEditor:n}=yield import(`@interactiveplatform/movika-graph-editor`);e.ngEditor=new n(e.graphWrapperElement,{mode:`view`,lang:e.lang===`ru`?`ru`:`en`,translation:t}),e.currentManifestId=e.manifest.metadata.id,e.ngEditor.update(e.manifest),e.ngEditor.setVisitedChapters(Array.from(e.visitedChapterIds)),e.currentChapterId&&e.ngEditor.selectChapter(e.currentChapterId),e.ngEditor.on(`control`,t=>{let{name:n}=t,r=T(t,x);n===`openPreview`&&`chapterId`in r&&e.onOpenPreviewClick?.call(e,r.chapterId)}),e.ngEditor.on(`zoom`,e.handleZoomChange),e.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 en(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 tn=3e3;class nn{constructor(){this._containers=[],this._player=null,this.setPlayer=e=>{this._player=e},this.setContainers=e=>{this._containers=e},this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)},this.getNextInteractiveTime=(e=tn)=>{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 rn{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let 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 an{constructor(e){this.raf=void 0,this.fn=void 0,this.fns=[],this.addFn=(e,t=!1)=>{_e(e)&&(this.fns.push(e),t&&this.updateFn())},this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(t=>t!==e),t&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{this.raf&&=(cancelAnimationFrame(this.raf),void 0)},e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class sn{constructor(e){this.rootElement=void 0,this.isCssVarsSupported=void 0,this.rootElementProps={},this.rootElement=e,this.isCssVarsSupported=sn.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=C(C({},this.rootElementProps),e),this.isCssVarsSupported)for(let[t,n]of on(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)}}class ln{constructor(e){this.loaders=void 0,this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}exec(e,t){var n=this;return w(function*(){return un(...n.loaders[e])(t)})()}}function un(...e){return function(){var t=w(function*(t){let n=[...e];for(;n.length>0;)t=yield n.shift()(t);return t});function n(e){return t.apply(this,arguments)}return n}()}function dn(e,t,n){return e?C(C({},e),{},{[t]:e[t]?[n,...e[t]]:[n]}):{[t]:[n]}}function fn(e){let{actions:t,errors:n,chapterId:r}=e,i=T(e,te);if(r){let e=t.getManifest();if(e){let a=t.getChapter(e.chapters,r);if(a){let r=t.getMedia(e.media,a.videoId),o=t.getGraph(e.graph,a.id);return r?C(C({},i),{},{actions:t,errors:n,result:{chapter:a,media:r,graph:o}}):C(C({},i),{},{errors:dn(n,fn.name,`Could not find media`),actions:t})}}}return C(C({},i),{},{errors:dn(n,fn.name,`Could not find chapter`),actions:t})}var mn=(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},hn=function(){var e=w(function*(e){try{let t={},n;if(me(e)){n=new URL(e).href;let r=yield pn(n);if(!r.ok)return{};t=yield r.json()}else if(M(e))t=e;else return{};if(!Xe(t))return{};let r=t.metadata.media;if(me(r)&&!(`media`in t))try{let e;n?e=new URL(r,n).href:(e=new URL(r).href,n=e);let i=yield pn(e);if(!i.ok)throw Error();t.metadata.media=yield i.json()}catch{return Cn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:n}}catch{return{}}});return function(t){return e.apply(this,arguments)}}();function gn(e){return _n.apply(this,arguments)}function _n(){return _n=w(function*(e){let{manifest:t,manifestURL:n}=yield hn(e);if(!t)throw Error(`Failed on fetch`);let r=Je(t);return r.media=xn(r.media,n),delete r.metadata.media,r}),_n.apply(this,arguments)}function vn(e,t){if(t)return e.find(e=>e.id===t)}function yn(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 bn(e,t){return e.videos.find(e=>e.id===t)}function xn(e,t){return C(C({},e),{},{videos:e.videos.map(e=>C(C({},e),{},{variants:e.variants.map(e=>{let n=`url`in e?e.url:``,r=Sn(n,t);return C(C({},e),{},{url:r||n})})}))})}function Sn(e=``,t){try{return new URL(e,t).href}catch{return``}}function Cn(e){return mn(e,`3.2.0`)>=0}class wn extends ln{constructor(e,t){super(e),this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$=new cn(null),this.onError=void 0,this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(e){var t=this;return w(function*(){t.release();let n=yield t.exec(`manifestLoaders`,{actions:{addErrorMessage:dn},result:null,errors:null,source:e});return n.errors&&t.errorHandler(n.errors),t.manifest=yield gn(n.result??e),t})()}setInitial(){var e=this;return w(function*(){return e.setNext()})()}setNext(){var e=this;return w(function*(t=this.manifest?.metadata.initChapterId){if(!t)return e;e.prevChapter$.next(e.chapter);let n=yield e.exec(`chapterLoaders`,fn({actions:{getManifest:()=>e.manifest,getCurrent:e.getCurrent,getGraph:yn,getChapter:vn,getMedia:bn,getByBranches:e.getByBranches.bind(e),addErrorMessage:dn},result:null,errors:null,chapterId:t}));return n.errors&&e.errorHandler(n.errors),n.result&&(e.chapter=n.result.chapter,e.media=n.result.media,e.graph=n.result.graph),e}).apply(this,arguments)}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=vn(this.manifest.chapters,e);if(t){let e=bn(this.manifest.media,t.videoId),n=yn(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=vn(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?L(this.chapter):!1}}var An=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[]};function Mn(){let e=new Map;function t(t){let{listId:n=Math.random().toString(),itemId:r=Math.random().toString()}=t,i=T(t,ne),a=e.get(n),o=C({},i);return a?a[r]=o:e.set(n,{[r]:o}),C({listId:n,itemId:r},i)}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 jn(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}}function Pn(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||Nn(t,`mp4`))&&(n.MPEG=C(C({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`mpeg`:(i||Nn(t,`mpeg`))&&(n.MPEG=C(C({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`hls`:(i||Nn(t,`hls`))&&(n=C(C({},n),{},{HLS:{type:`url`,url:a.url}}));break;case`dash`:(i||Nn(t,`dash`))&&(n=C(C({},n),{},{DASH_SEP:{compatibilityMode:!0,type:`url`,url:a.url}}));break;default:break}return{sources:n,thumbUrl:r,title:e.title??``}}var Fn=(e,t)=>{let n=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();n!==t&&Nn(r,t)&&(e.setQuality(t),e.setAutoQuality(!1))},In=2;function Ln(e){let t=Mn(),n=new Dn,r={},i=null,a=!1,o,s=new kn(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=C({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)Tn(n[1]).forEach(({player:t})=>{Fn(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.`)}function u(e){return d.apply(this,arguments)}function d(){return d=w(function*(e){if(!i)throw Error(`need to set interactive controller`);if(be(r)||e!==r.itemId)return;let t=i.getChapterBranches(),n=new Set;for(let e of t)n.has(e.media.id)||(yield m({media:e.media,chapterId:e.chapter.id,setAsActive:!1,title:e.chapter.label}),n.add(e.media.id))}),d.apply(this,arguments)}function f(e){return p.apply(this,arguments)}function p(){return p=w(function*({chapter:{id:e},manifestVideo:n}){if(be(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,f=!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<In||(f=!0),t.removePlayer(s[0],i)):(f=!0,l(s[0],i,e),d?Fn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a),r.player.setPlaybackRate(u))}else t.removePlayer(s[0]);f||(yield m({media:n,chapterId:e,setAsActive:!0,playbackRate:u}),d?Fn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a))}),p.apply(this,arguments)}function m(e){return h.apply(this,arguments)}function h(){return h=w(function*({media:e,chapterId:n,prefetch:a=!0,setAsActive:s=!0,autoplay:c=!1,preferredExt:u,title:d,playbackRate:f}){var p,m,h,g;let _=Math.random().toString(),v=document.createElement(`div`);o.append(v);let y;if(!(i==null||(p=i.options)==null)&&p.vkVideoLoader){let t=An(e);t.length&&(y=yield i.options.vkVideoLoader(...t))}let b=C({},(i==null||(m=i.options)==null?void 0:m.coreConfig)||void 0),ee=C(C({container:v,sources:Pn(e,u).sources},y==null||(h=y.videos)==null?void 0:h[0]),{},{title:d,failoverHosts:y?.failoverHosts||[]}),x=new En(b,On.createRootTracer());x.initVideo(ee);let te=null;if(y?.videos&&i?.options.createOneStat){let e=y.videos[0],t=i.options.createOneStat(e),n=new Dn;t&&(n.add(t.attachTo(x)),te={oneStat:t,statSubscription:n})}let ne=new Dn,re=r==null||(g=r.player)==null?void 0:g.info.isAutoQualityEnabled$.getValue();ne.add(x.events.canplay$.subscribe(function(){re||Fn(x,r.player.info.currentQuality$.getValue()),f&&x.setPlaybackRate(f)}));let S=t.createPlayer({listId:e.id,itemId:_,player:x,container:v,sources:Pn(e,u).sources,config:ee,subscription:ne,statistics:te});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}}),h.apply(this,arguments)}function g(){_(),i=null,o.remove()}function _(){n.unsubscribe(),t.removeAll(),r={},a=!1}function v(){return y.apply(this,arguments)}function y(){return y=w(function*(){if(!i)throw Error(`need to set interactive controller`);_(),o=document.createElement(`div`);let{media:e,chapter:t}=i.getCurrentChapter();e&&t?(n.add(i.events.chapterChanged$.subscribe(f)),yield m({media:e,chapterId:t.id,title:t.label})):console.error(`not found`)}),y.apply(this,arguments)}return{map:t.map,removePlayer:t.removePlayer,init:v,setInteractiveController:c,createPlayer:m,removeAll:g,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`},Rn={visibility:`visibility`,watchAgainClicked:`watchAgainClicked`},J={actionChoiceCanceled:`action-choice-canceled`,actionChoice:`action-choice`,actionExecution:`action-execution`,visibility:`visibility`,containerRemoved:`container-removed`,rangeEnded:`range-ended`};function Bn(e){return function(...t){return e(...t.reverse())}}function Vn(e,...t){return(...n)=>M(t[0])&&M(n[0])?e(C(C({},t[0]),n[0])):e(...t,...n)}class Hn{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=void 0,this.branches=void 0,this.selectBranches=void 0,this.subscription=void 0,this.player=void 0,this.interactiveEvents=void 0,this.getContainerEventState=void 0,this.isPermanentText=void 0,this.interactiveTimeOpenUri=void 0,this.disabledControls$=void 0,this.onRemove=void 0,this.globalEventEmitter=void 0,this.gameState=void 0,this.isSelectedControlEvent=void 0,this.isSelectedContainerEvent=void 0,this.globalEvents=void 0,this.onError=void 0,this.disableTextControlContainerVisibilityEvents=void 0,this.features=void 0,this.hide=()=>{setTimeout(()=>{if(this.gameState!==4&&!(R(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect)){if(this.gameState!==2){var e;(e=this.container).hide?.call(e)}this.emitContainerVisibilityEvent(!1)}})},this.show=()=>{if(!(this.gameState!==2||this.isSelectedControlEvent))if(this.container.getElement()){var e;let{hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState();if((e=this.container).show?.call(e),this.interactiveTimeOpenUri&&t||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},n=Vn(this.selectBranches.onControlEvent,e),r=(this.player?.info.duration$.getValue()??1/0)*1e3;if(this.container.createView({eventCallback:n,videoDurationMs:r}),this.disableTextControlContainerVisibilityEvents||this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()){var t;(t=this.container).disable?.call(t)}}},this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)},this.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(ot(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(st(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();if(e){if(e.style.visibility!==`hidden`){var r;(r=this.container).hide?.call(r)}this.container.isRemoved||this.fakeRemoveView()}}!this.isPermanentText&&!n&&this.removeView()}let i=st(n,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:`container`,range:a,currentTime:n,isInteractiveTime:i};this.container.onProgress(n*1e3,i),this.globalEventEmitter.emit(q.eachTick,o),this.globalEvents.eachTick$.next(o)},this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new zn,this.player=e,this.interactiveEvents=i,this.getContainerEventState=s;let h=ut(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:J.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:J.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=>{if(e){var t;(t=this.container).disable?.call(t)}else{var n;(n=this.container).enable?.call(n)}})),this.subscription.add(this.container.error$.subscribe(this.onError))}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:R(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){var e;(e=this.container).hide?.call(e),this.emitContainerVisibilityEvent(!1)}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:J.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-removed`}),this.gameState=5,this.onRemove?.call(this)}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 Un=(e=[])=>e.reduce((e,t,n)=>{if(it((t?.controls??[]).filter(e=>!Ze(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]);function qn(){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(ye(t)){let i=e[t]??null;if(i&&n&&Se(n,!0)){let e={},t=i[n];return t&&(e=C(C({},e),t)),e=be(e)?null:e,e&&Se(r,!0)?e[r]??null:e}return i}return null}function a({timestamp:t,priority:n,initiator:r}){if(ye(t))if(e[t]){if(n&&Se(n,!0))if(e[t][n]){if(r&&Se(r,!0))if(e[t][n][r]){if(delete e[t][n][r],!be(e[t][n]))return!0}else return!1;if(delete e[t][n],!be(e[t]))return!0}else return!1;return delete e[t]}else return!1;return!1}function o(t){var n;let{timestamp:r,priority:i,initiator:a}=t,o=T(t,re);!((n=e[r])==null||(n=n[i])==null)&&n[a]?e[r][i][a].push(C({},o)):e[r]?.[i]?e[r][i]=C(C({},e[r][i]),{},{[a]:[C({},o)]}):e[r]?e[r]=C(C({},e[r]),{},{[i]:{[a]:[C({},o)]}}):e[r]={[i]:{[a]:[C({},o)]}}}return{map:e,remove:a,add:o,removeAll:t,get:i,getLte:n,getGte:r}}var Jn=[I.expect,I.setNextBranch],Yn=1/0;function Xn(e,t){let n=e,r,i=Zn(t),a=qn(),o,s=()=>{p(),_()},c=e=>{a.add.call(void 0,e),m()},l=(e=[])=>{for(let t of e)if(t.action(),Wn(Jn,t.actionType))break},u=(e=1/0)=>{let t=Qn(a.get({timestamp:e,priority:`control`})??{}),n=Qn(a.get({timestamp:e,priority:`container`})??{}),r=Qn(a.get({timestamp:e,priority:`chapter`})??{});return[...t,...n,...r]},d=e=>{i.isReady(e)&&l(u(e))},f=()=>{l([...Qn(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 Zn(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??Yn,r=t.get(e);t.set(e,C(C({},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=Gn(r);return e?i.some(e=>e):!i.some(e=>!e)},release:()=>t.clear()}}function Qn(e){return Kn(Gn(e)).sort(e=>e.actionType===I.expect?-1:1)}var $n={videoContentHeight:0,videoContentWidth:0},er=e=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return $n;let{clientHeight:r,clientWidth:i}=e.experimental.element$.getValue()||{};if(!(r&&i))return $n;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}},tr=250;function nr(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}=er(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=Yt(t=>{let{fns:n=[]}=e();r(t);for(let e of n)e()},tr);function o(){t=void 0,n.disconnect(),i()}return{resizeObserver:n,calc:()=>{t?.()},release:o}}var rr=e=>Math.floor(Math.random()*e),ir=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},ar=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},or=e=>{let t=e.length;return e[rr(t)]},sr=1,cr=e=>{let t=0;for(let n=0;n<e.length;++n)t+=e[n].weight??sr;let n=Math.random()*t;t=0;for(let r=0;r<e.length-1;++r)if(t+=e[r].weight??sr,t>=n)return e[r];return e[e.length-1]},lr={shouldOpenNow:!0,isDetachContainer:!0},ur=`after-expect`,dr=(e,t=!1)=>C(C({},e),{},{args:t?C(C({},e.args),lr):C(C({},lr),e.args)}),fr=({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=dr(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?J.actionChoiceCanceled:J.actionChoice,actionType:n.type,payload:C({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:C({invokeImmediately:f.args.shouldOpenNow,containerId:o},f.args)})};if(v){y(),b();return}switch(f.type.trim().toLowerCase()){case I.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(C(C({},_),{},{action:h.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{chapterId:e.chapterId,autoSelect:!1}})}));return}case I.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(C(C({},_),{},{action:m.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:n})}));return;case I.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(C(C({},_),{},{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 k(1,1,{message:e}),e);return}}},s=({action:n,container:{id:i,endTime:a},branches:o=[],isEOV:s=!1,autoSelected:c=!1})=>{let l=dr(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:J.actionChoice,actionType:l.type,payload:C({invokeImmediately:l.args.shouldOpenNow},l.args)}),p=()=>{t.interactiveActionChoice$.next({subjectId:i,subjectName:`container`,type:`action-choice`,actionType:l.type,payload:C({invokeImmediately:l.args.shouldOpenNow},l.args)})};switch(l.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let e=o.find(e=>e.id===l.args.branchId);if(!e)return;f(),p(),r.add(C(C({},d),{},{action:h.bind(null,{subjectId:i,subjectName:`container`,action:l,payload:{chapterId:e.chapterId,autoSelect:c}})}));return}case I.setMaxWeightBranch.trim().toLowerCase():return;case I.setMinWeightBranch.trim().toLowerCase():return;case I.setRandomBranch.trim().toLowerCase():return;case I.setWeightlessRandomBranch.trim().toLowerCase():return;case I.continuePlayback.trim().toLowerCase():f(),p(),r.add(C(C({},d),{},{action:m.bind(null,{subjectId:i,subjectName:`container`,action:l})}));return;case I.openURI.trim().toLowerCase():f(),p(),r.add(C(C({},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 k(1,1,{message:e}),e);return}}};function c({container:n,branches:a,isEOV:o=!1}){let c=ct(n.events);if(c){let a=dr(c.action,o);e.emit(q.interactives,{subjectId:n.id,subjectName:`container`,type:J.actionChoice,actionType:a.type,payload:C({invokeImmediately:a.args.shouldOpenNow},a.args)}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`container`,type:`action-choice`,actionType:a.type,payload:C({invokeImmediately:a.args.shouldOpenNow},a.args)}),r.add({timestamp:o?1/0:n.endTime??1/0,priority:`container`,initiator:n.id,actionType:I.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:J.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 I.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 I.setWeightlessRandomBranch.trim().toLowerCase():{let e=or(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let e=cr(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let e=ar(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let e=ir(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return a(),o(),m.bind(null,{subjectId:n,subjectName:`chapter`,action:r});case I.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 k(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=ct(n.events);if(i){if(L(n))return;e.emit(q.interactives,{subjectId:n.id,subjectName:`chapter`,type:J.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:I.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:J.actionExecution,actionType:I.expect}),t.interactiveActionExecution$.next({subjectId:r,subjectName:i,type:`action-execution`,actionType:I.expect})},p=({subjectId:i,subjectName:a})=>{n.info.isEnded$.getValue()?r.execEndOfVideo():n.play(),e.emit(q.interactives,{subjectId:i,subjectName:a,type:J.actionExecution,actionType:ur}),t.interactiveActionExecution$.next({subjectId:i,subjectName:a,type:`action-execution`,actionType:ur})},m=({subjectId:n,subjectName:r,subjectType:i,action:a})=>{e.emit(q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:J.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:J.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:J.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}};var gr=(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]=yr(i)}return n[e]}).filter(e=>e!==null)},_r=e=>{for(let t of e.variants)if(vr(t)&&t.payload)return t.payload.id},vr=e=>!!(e.type===`custom`&&e.payload&&e.payload.type===`vk`),yr=e=>{let t=_r(e);if(!t)return null;let n=t.split(`_`).pop();return n?parseInt(n,10):null},br=(e,t)=>{for(let n of e.media.videos)if(t===yr(n)){for(let t of e.chapters)if(t.videoId===n.id)return t.id;return}},xr=(e,t)=>e.reduce((e,n)=>{let r=br(t,n);return r?[...e,r]:e},[]),Y=new WeakMap,Sr=new WeakMap,Cr=new WeakMap,X=new WeakMap,wr=new WeakMap,Z=new WeakMap,Q=new WeakMap,$=new WeakMap,Tr=new WeakMap,Er=new WeakMap,Dr=new WeakMap;class Or{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:i}){this.state={history$:new hr([]),hasPrevChapter$:new hr(!1),prevChapter$:new hr(null),isInitialChapter$:new hr(!1),isGoBackLimited$:new hr(!1)},E(this,Y,null),E(this,Sr,void 0),E(this,Cr,!1),E(this,X,null),E(this,wr,null),this.events={inited$:new mr,destroyed$:new mr,error$:new mr},E(this,Z,null),E(this,Q,null),E(this,$,null),E(this,Tr,new pr),E(this,Er,!1),E(this,Dr,0),D(Z,this,t),D($,this,e),D(Q,this,n),D(Y,this,r),D(Sr,this,i),this.state.history$&&O(Tr,this)&&O(Tr,this)?.add(this.state.history$.subscribe(e=>{var t;this.state.prevChapter$.next(e.at(-2)||null),this.state.hasPrevChapter$.next(e.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((t=O(X,this))==null||(t=t.metadata)==null?void 0:t.initChapterId)),this.state.isGoBackLimited$.next(O(Dr,this)===O(Sr,this).maxLength-1)}))}setManifest(e){var t=this;return w(function*(){if(!O(Q,t)||!O($,t))return;D(X,t,e),yield t.getProjectHistory();let n=t.getInitialChapterId();yield O(Q,t).setChapter({chapterId:n,pushToHistory:!1}),O(Cr,t)||(D(Cr,t,!0),t.events.inited$.next({initChapterId:n}))})()}get inited(){return O(Cr,this)}updateHistory(e,t=!0){var n=this;return w(function*(){if(!O(X,n))return;if(O(Er,n)){var r;D(Er,n,!1),D(Dr,n,(r=O(Dr,n),r++,r))}else D(Dr,n,0);let i=O(X,n),a=e.length-O(Sr,n).maxLength,o=a>0?e.slice(a):e,s=gr(o,i);if(D(wr,n,s),n.state.history$.next(o),!(!t||!O(Y,n)||!O(Z,n)))try{yield O(Y,n).save(O(Z,n),s)}catch{let e=new k(1,5,`Unable to save interactive history`);n.events.error$.next(e),O($,n)?.emit(q.errors,e)}})()}goBack(){var e=this;return w(function*(){if(!e.state||!O(Q,e)){let t=new k(1,5,`Unable to save interactive history`);e.events.error$.next(t),O($,e)?.emit(q.errors,t);return}D(Er,e,!0);let t=e.state.history$.getValue().slice(0,-1),n=t.pop();e.state.history$.next(t),yield O(Q,e).setChapter({chapterId:n,playPrev:!0})})()}getProjectHistory(){var e=this;return w(function*(){if(!O(X,e)||!O(Z,e))return;let t=O(X,e),n=[e.getInitialVideoId()];if(O(Y,e))try{let t=yield O(Y,e).get(O(Z,e));t.length&&(n=t)}catch{let t=new k(1,5,`Error while trying to fetch data`);e.events.error$.next(t),O($,e)?.emit(q.errors,t)}let r=xr(n,t);e.state.history$.next(r)})()}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||O(Sr,this).initChapterId||O(X,this)?.metadata.initChapterId}getInitialVideoId(){return O(X,this)?gr([this.getInitialChapterId()],O(X,this)).pop():null}destroy(){D(Z,this,null),D(Y,this,null),D(Q,this,null),O(Tr,this)?.unsubscribe(),D(Tr,this,null),D(Cr,this,!1),O($,this)?.emit(q.historyDestroyed),this.events.destroyed$.next(),D($,this,null)}}class kr{constructor(){this.rootElement=void 0,this.canvasImgSrc=void 0,this._prevSizeId=0,this.rootElement=document.createElement(`canvas`)}clear(){this.rootElement.getContext(`2d`)?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext(`2d`)?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,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)}updateCanvasDimensions(e,t=!1){var n=this;return w(function*(){let r=e.width+e.height;if(n._prevSizeId===r)return;let i;t&&(i=yield n.save()),n.rootElement.width=e.width,n.rootElement.height=e.height,t&&i&&n.restore(i),n._prevSizeId=r})()}save(){var e=this;return w(function*(){let t=e.rootElement.toDataURL(`image/jpeg`,1),n=new Image;return n.crossOrigin=`anonymous`,n.src=t,yield n.decode(),n})()}restore(e){this.rootElement&&this.rootElement.getContext(`2d`)?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}}class Ar{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.lastFrameCanvas=void 0,this.endOffsetMs=void 0,this.currentChapter=void 0,this.currentVideoDurationMs=1/0,this.rootElement=void 0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this._callbacks=void 0,this.onEachTick=e=>{let t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},this.rootElement=document.createElement(`div`),this.rootElement.style.cssText=`
6
+ import{fromEvent as ae,Subscription as oe}from"@vkontakte/videoplayer-shared/es2015";import{Subject as le}from"@vkontakte/videoplayer-shared/es2015";import{fromEvent as A,once as pe}from"@vkontakte/videoplayer-shared/es2015";import{fromEvent as Ne,Subject as Pe,Subscription as Fe}from"@vkontakte/videoplayer-shared/es2015";import{arrayIncludes as Ue}from"@vkontakte/videoplayer-shared/es2015";import{isSupportedManifest as We,ContainerTypes as Ge,ControlTypes as Ke,EventActionTypes as I,EventTypes as qe,migrateManifestToLatestVersion as Je}from"@interactiveplatform/movika-manifest";import{fromEvent as H,once as bt}from"@vkontakte/videoplayer-shared/es2015";import{combine as Vt,InterfaceLanguage as Ht,Observable as Ut,once as Wt,Subject as G,Subscription as Gt,ValueSubject as K,fromEvent as Kt}from"@vkontakte/videoplayer-shared/es2015";import{InteractiveInterfaceClick as qt}from"@vkontakte/videoplayer-statistics/es2015";import{loadVKLangPack as Jt}from"@vkontakte/videoplayer-shared/es2015";import{objectEntries as on}from"@vkontakte/videoplayer-shared/es2015";import{ValueSubject as cn}from"@vkontakte/videoplayer-shared/es2015";import{fetchPolyfilled as pn}from"@vkontakte/videoplayer-shared/es2015";import{objectValues as Tn}from"@vkontakte/videoplayer-shared/es2015";import{Player as En}from"@vkontakte/videoplayer-core/es2015";import{Subscription as Dn,TracerFactory as On,ValueSubject as kn}from"@vkontakte/videoplayer-shared/es2015";import{objectValues as jn}from"@vkontakte/videoplayer-shared/es2015";import{arrayIncludes as Nn}from"@vkontakte/videoplayer-shared/es2015";import{Subscription as zn}from"@vkontakte/videoplayer-shared/es2015";import{arrayIncludes as Wn}from"@vkontakte/videoplayer-shared/es2015";import{objectValues as Gn}from"@vkontakte/videoplayer-shared/es2015";import{arrayFlat as Kn}from"@vkontakte/videoplayer-shared/es2015";import{Subscription as pr,Subject as mr,ValueSubject as hr}from"@vkontakte/videoplayer-shared/es2015";import{clientChecker as Pr}from"@vkontakte/videoplayer-core/es2015";var _oxcMods3febh=function(){function e(t){"@babel/helpers - typeof";return e=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},e(t)}var t=e;function n(e,n){if(t(e)!=`object`||!e)return e;var r=e[Symbol._oxc_toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(t(i)!=`object`)return i;throw TypeError(`@@_oxc_toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}var t=e,r=n;function i(e){var n=r(e,`string`);return t(n)==`symbol`?n:n+``}var a=i;function o(e,t,n){return(t=a(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s=o;function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?c(Object(n),!0).forEach(function(t){s(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function u(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function d(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){u(a,r,i,o,s,`next`,e)}function s(e){u(a,r,i,o,s,`throw`,e)}o(void 0)})}}function f(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}var p=f;function m(e,t){if(e==null)return{};var n,r,i=p(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function h(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}var g=h;function _(e,t,n){g(e,t),t.set(e,n)}function v(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}var y=v;function b(e,t,n){return e.set(y(e,t),n),n}var y=v;function ee(e,t){return e.get(y(e,t))}const x=[`name`],te=[`actions`,`errors`,`chapterId`],ne=[`listId`,`itemId`],re=[`timestamp`,`priority`,`initiator`],S=[`statistics`];var C=l,w=d,T=m,E=_,D=b,O=ee,ie=`1.0.72-dev.abb27aca7.0`;class se{constructor(e,t){this.layout=void 0,this.cssVarsManager=void 0,this.layout=e,this.cssVarsManager=t}}class ce extends se{constructor(e,t){super(e,t),this.cssVarsManager=void 0,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))`}}function ue(e){return`features`in e}class k{constructor(e,t,...n){this.severity=void 0,this.category=void 0,this.data=void 0,this.severity=e,this.category=t,this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null,` `)}`}}function de({emitter$:e,error:t,subjectId:n,message:r=``,severity:i=1,category:a=1}){let o=new k(i,a,{message:r,error:t,details:{id:n}});e.next(o)}class fe{constructor(e,t,n){this.container=void 0,this.options=void 0,this.factories=void 0,this.controls=void 0,this.error$=new le,this.cssVarsManager=void 0,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&&ue(this.options)&&this.options.features[e])}onError(e=``,t){de({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]},[])||[]}}var j=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,M=e=>j(e,`Object`),me=e=>j(e,`String`),he=e=>j(e,`Array`),ge=e=>j(e,`Number`),_e=e=>j(e,`Function`),ve=e=>j(e,`Boolean`),ye=e=>ge(e)&&!isNaN(e),be=e=>M(e)&&Object.keys(e).length===0,xe=e=>he(e)&&!e.length,Se=(e,t)=>me(e)&&!!(t?e.trim():e).length;function Ce(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 we=`interactive`,N={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},Te;(e=>{e.top=`flex-start`,e.bottom=`flex-end`,e.center=`center`})(Te||={});var Ee;(e=>{e.start=`flex-start`,e.end=`flex-end`,e.center=`center`})(Ee||={});var De=({target:e,props:t})=>{e.style.alignItems=(t?.gravityVertical&&Te[t.gravityVertical])??`center`,e.style.justifyContent=(t?.gravityHorizontal&&Ee[t.gravityHorizontal])??`center`,e.style.textAlign=t?.alignment??`center`},Oe=({target:e,props:t,fallback:n,dependsOn:r})=>{var i,a,o;e.style.color=(t==null||(i=t.text)==null?void 0:i.color)??n.textColor,e.style.fontSize=`calc(${r.height} * ${(t==null||(a=t.text)==null?void 0:a.size)??n.textSize})`,e.textContent=(t==null||(o=t.text)==null?void 0:o.value)??n.textContent},ke=({target:e,props:t,fallback:n})=>{var r,i;e.style.backgroundColor=Ce((t==null||(r=t.background)==null?void 0:r.color)??n.backgroundColor,(t==null||(i=t.background)==null?void 0:i.alpha)??n.backgroundAlpha)},Ae=({target:e,props:t,fallback:n,dependsOn:r,useRawValues:i=!1})=>{var a,o,s,c;let l=i?n.borderWidthRawValue:`calc(${r.height} * ${(t==null||(a=t.shape)==null||(a=a.border)==null?void 0:a.width)??n.borderWidth})`,u=i?n.roundCornersRawValue:`calc(${r.height} * ${(t==null||(o=t.shape)==null?void 0:o.roundCorners)??n.roundCorners})`;e.style.borderWidth=l,e.style.borderStyle=`solid`,e.style.borderColor=Ce(i?n.borderColor:(t==null||(s=t.shape)==null||(s=s.border)==null?void 0:s.color)??n.borderColor,i?n.borderAlpha:(t==null||(c=t.shape)==null||(c=c.border)==null?void 0:c.alpha)??n.borderAlpha),e.style.borderRadius=u},je=({target:e,isDark:t,baseDimension:n,fallback:r})=>{let i=Ce(r.shadowColorLight,r.shadowColorAlpha),a=Ce(r.shadowColorDark,r.shadowColorAlpha),o=`0px 0px ${`calc(${n} * 0.25)`} ${`calc(${n} * 0.11)`} ${t?a:i}`;e.style.boxShadow=o},Me=({target:e,layoutParams:t,fallback:n})=>{let r=t.angle??n.angle;r&&=r*-1,e.style.transform=`rotate(${r}rad)`};var Ie=`interactive-control-tap`,Le={common:Ie,animation:`${Ie}-animation`,visible:`${Ie}-visible`},Re=60;class ze{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=Re,useDimensionsBasedSize:r=!1}){this.element=void 0,this.controlRotateAngleRad=void 0,this.clickCancelCondition=void 0,this.circleDiameterPx=void 0,this.useDimensionsBasedSize=void 0,this.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=Be(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(Le.visible,Le.animation)},this.onAnimationEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(Le.visible,Le.animation)};let i=document.createElement(`div`);i.classList.add(Le.common),this.controlRotateAngleRad=e,this.element=i,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=r}}function Be(e,t,n){return{x:e*Math.cos(n)-t*Math.sin(n),y:e*Math.sin(n)+t*Math.cos(n)}}function Ve(e){return`features`in e}var P=`interactive-control`,F={common:P,selected:`${P}-selected`,wrapper:`${P}-wrapper`,disabled:`${P}-disabled`,button:`${P}-button`,area:`${P}-area`,text:`${P}-text`,blinkAnim:`${P}-blink-anim`,blinkAnimButton:`${P}-blink-anim-button`,blinkAnimArea:`${P}-blink-anim-area`},He=40;var Ye={metadata:`Object`,chapters:`Array`},Xe=e=>{if(!M(e))return!1;for(let t in Ye){let n=e[t];if(!n||!j(n,Ye[t]))return!1}return We(e.metadata.version)};function Ze(e){return e.type===Ke.Text}function Qe(e){return e.type===Ke.Button}function $e(e){return e.type===Ke.Area}var et={Choice:`Choice`,TextInput:`TextInput`},tt={Button:`Button`,Area:`Area`,Text:`Text`},nt={onClick:`onClick`,onSuspense:`onSuspense`},rt={openURI:`openURI`,setNextBranch:`setNextBranch`,setWeightlessRandomBranch:`setWeightlessRandomBranch`,setRandomBranch:`setRandomBranch`,setMaxWeightBranch:`setMaxWeightBranch`,setMinWeightBranch:`setMinWeightBranch`,setDefaultBranch:`setDefaultBranch`,continuePlayback:`continuePlayback`,expect:`expect`},it=e=>he(e)&&!xe(e),L=e=>e.order===`end`,at=e=>he(e.containers)&&!xe(e.containers)&&L(e),ot=(e,t)=>{let n=e*1e3;return it(t.controls)&&n<(t.startTime??0)},st=(e,t)=>{let n=e*1e3;return it(t.controls)&&n>=(t.startTime??0)&&n<=(t.endTime??1/0)},R=(e=[])=>e.some(e=>e.action.type===`expect`),ct=(e=[])=>e.find(e=>e.action.type===`expect`),lt=e=>e?.length===1,ut=e=>lt(e)&&Ze(e[0]);function dt(e=[],t=1/0,n=[]){return e.filter(({container:e})=>!Ue(n,e.container.id)&&R(e.container.events)&&e.container.endTime===t&&!e.isRemoved&&!e.willRemoved)}function ft({gameControllers:e=[],subjectName:t,subjectId:n,execFn:r}){for(let i of e)if(t===`container`&&i.container.container.id===n){r(i),dt(e,i.container.container.endTime,[i.container.container.id]).forEach(e=>{r(e)});break}}function pt(e){for(let t of e.events)if(t.action.type===`openURI`)return!0;return!1}var mt=(e,t)=>{let n=R(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===I.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=dt(t,e.endTime,[e.id]).length,s=e=>e.controls.some(e=>e.events?.some(e=>{var t;return(t=e.action)==null||(t=t.args)==null?void 0:t.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 z{constructor(e,t=void 0){this.control=void 0,this.options=void 0,this.container=null,this.controlElement=null,this.subscriptions=new Fe,this.error$=new Pe,this.controlTap=void 0,this.isInteracted=!1,this.isRemoved=!1,this.cssVarsManager=null,this.onControlSelect=()=>{var e;this.container?.isManifestContainerDisabled()||pt(this.control)||(e=this.container)==null||(e=e.element)==null||e.classList.add(`interactive-control-wrapper-selected`)},this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()},this.control=e,this.options=t}setCssVarsManager(e){this.cssVarsManager=e}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(Ne(t,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${z.name} remove view transition error`,e))).add(Ne(t,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${z.name} remove view transition error`,e)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e=``,t){de({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){if(this.featureIsEnabled(`controlsTapPlace`)&&this.container){let t=this.control.layoutParams.angle??N.angle;this.controlTap=new ze({controlRotateAngleRad:t,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?He:void 0}),this.subscriptions.add(Ne(e,`click`).subscribe(this.controlTap.onElementClick,e=>this.onError(`Control click tap animation error`,e))).add(Ne(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(F.wrapper),e.setControlLayout(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??N.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},r=()=>e.isContainerDisabled?.call(e)??!1;this.container={element:t,dimensions:n,isManifestContainerDisabled:r}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&Ve(this.options)&&this.options.features[e])}isTouch(){return!!(this.options&&Ve(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(Ne(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 ht=`interactive-blink-anim-reference`,B={common:ht,animation:`${ht}-animation`,disabled:`${ht}-disabled`};class gt{constructor(){this._RAFId=0,this._element=void 0}get element(){return this._element}create(){if(this._element)return;let e=document.createElement(`div`);e.classList.add(B.common,B.animation),this._element=e}restart(){this._element&&(this._element.classList.add(B.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(B.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&=(cancelAnimationFrame(this._RAFId),0)}destroy(){this.cleanupRAF(),this._element=void 0}}var _t=`interactive-container`,V={common:_t,hidden:`${_t}-hidden`,disabled:`${_t}-disabled`},vt=(e,t)=>{if(e.type.trim().toLowerCase()===`area`)return new yt(e,t)};class yt extends z{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(F.common,F.area),n.setAttribute(`data-testid`,`int_area`),ke({target:n,props:this.control.props,fallback:C(C({},N),{},{backgroundColor:`transparent`})}),Me({target:n,layoutParams:this.control.layoutParams,fallback:N}),this.addControlTap(n),this.subscriptions.add(A(this.container.element,`click`).pipe(pe()).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(A(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(V.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${B.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(A(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(V.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(A(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(F.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(F.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(ve(e)){var t;let n=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+`px`;je({target:this.controlElement,props:this.control.props,fallback:N,isDark:e,baseDimension:n}),Ae({target:this.controlElement,props:this.control.props,fallback:C(C({},N),{},{borderColor:e?N.shadowColorDark:N.shadowColorLight,borderAlpha:1,borderWidthRawValue:`0.1px`,roundCornersRawValue:`calc(${this.container.dimensions.height} * ${((t=this.control.props)==null||(t=t.shape)==null?void 0:t.roundCorners)??N.roundCorners})`}),dependsOn:this.container.dimensions,useRawValues:!0})}else Ae({target:this.controlElement,props:this.control.props,fallback:C(C({},N),{},{borderAlpha:0}),dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(F.blinkAnim,e),this.controlElement?.classList.toggle(F.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${F.blinkAnimArea}`)||this.controlElement.classList.contains(F.selected)||this.controlElement.classList.contains(B.disabled)||(this.controlElement.classList.add(B.disabled),this.subscriptions.add(A(e,`animationiteration`).pipe(pe()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(B.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${F.blinkAnimArea}`)||this.controlElement.classList.contains(F.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(){}}var xt=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}},St=Math.PI,Ct=2*St,wt=St/2,Tt=3*wt,Et=[0,wt,St,Tt];function Dt(e){return e===wt}function Ot(e){return e===St}function kt(e){return e===Tt}function At(e){return(e%Ct+Ct)%Ct}function jt(e){for(let t of Et)if(e===t)return t}function Mt(e){return jt(e)?null:[1,2,3,4][Math.floor(e/wt)+1-1]}function Nt(e){return e*180/Math.PI}var U=`interactive-control-fill-animation`,W={common:U,fillerWrapper:`${U}-filler-wrapper`,filler:`${U}-filler`,fillHeight:`${U}-fill-height`,fillWidth:`${U}-fill-width`,fromTop:`${U}-from-top`,fromBottom:`${U}-from-bottom`,fromLeft:`${U}-from-left`,fromRight:`${U}-from-right`};class Pt{constructor(e){this.fillAnimationElement=void 0,this.fillAnimationFillerElement=void 0,this.fillAnimationFillerWrapperElement=void 0,this.startTime=void 0,this.endTime=void 0,this.shouldFillHeight=void 0,this.widthExpansionCoef=0,this.isDebug=void 0,this.fromLeft=void 0,this.useSkew=void 0,this.rotateAngle=void 0;let t=document.createElement(`div`);t.classList.add(W.common);let n=document.createElement(`div`);n.classList.add(W.fillerWrapper);let r=document.createElement(`div`);r.classList.add(W.filler),n.append(r),t.append(n);let i=At(e.rotateAngle),a=Mt(i),o=a!==null,s=a===2||!o&&Ot(i)||a===3,c=!o&&Dt(i),l=!o&&kt(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(W.fillHeight,c?W.fromTop:W.fromBottom),n.classList.add(W.fillHeight,c?W.fromTop:W.fromBottom)):(r.classList.add(W.fillWidth,u?W.fromLeft:W.fromRight),n.classList.add(W.fillWidth)),e.debug&&console.log(`[interactive ${Pt.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:d,rotateAngleRad:i,rotateAngelDeg:Nt(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 Ft=(e,t)=>{if(e.type.trim().toLowerCase()===`button`)return new It(e,t)};class It extends z{constructor(e,t){super(e,t),this.startTime=void 0,this.endTime=void 0,this.controlFillAnimation=void 0}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(F.common,F.button),n.setAttribute(`data-testid`,`int_bttn`),Me({target:n,layoutParams:this.control.layoutParams,fallback:N}),ke({target:n,props:this.control.props,fallback:N}),Ae({target:n,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),De({target:n,props:C(C({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=xt(this.control.type.trim().toLowerCase());Oe({target:r.firstElementChild??r,props:this.control.props,fallback:N,dependsOn:this.container.dimensions}),this.addControlTap(n),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled(`controlsFillAnimation`)&&(this.controlFillAnimation=new Pt({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??N.angle,borderRadius:n.style.borderRadius})),this.subscriptions.add(H(n,`click`).pipe(bt()).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(H(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(V.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${B.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(H(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(V.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(H(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(F.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(F.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(F.blinkAnim,e),this.controlElement?.classList.toggle(F.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${F.blinkAnimButton}`)||this.controlElement.classList.contains(F.selected)||this.controlElement.classList.contains(B.disabled)||(this.controlElement.classList.add(B.disabled),this.subscriptions.add(H(e,`animationiteration`).pipe(bt()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(B.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${F.blinkAnimButton}`)||this.controlElement.classList.contains(F.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 Lt=(e,t)=>{if(e.type.trim().toLowerCase()===`text`)return new Rt(e,t)};class Rt extends z{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(F.common,F.text),n.setAttribute(`data-testid`,`int_text`),Me({target:n,layoutParams:this.control.layoutParams,fallback:N}),De({target:n,props:C(C({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=xt(this.control.type.trim().toLowerCase());Oe({target:r.firstElementChild??r,props:this.control.props,fallback:N,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 zt=(e,t,n,r)=>{if(e.type.trim().toLowerCase()===`choice`)return new Bt(e,t,n,r)};class Bt extends fe{constructor(e,t,n,r){super(e,n,r),this.rootElement=void 0,this.containerElement=null,this.layout=void 0,this.subscriptions=new oe,this.isRemoved=void 0,this.isDisabled=void 0,this.willRemoved=void 0,this.cssVarsManager=void 0,this.onTransitionEnd=e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()},this.rootElement=t,this.layout=new ce(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory(`button`,Ft),this.addControlFactory(`text`,Lt),this.addControlFactory(`area`,vt)}createView({eventCallback:e,videoDurationMs:t}){let n=document.createElement(`div`);return n.classList.add(V.common,V.disabled),n.setAttribute(`data-subjectId`,this.container.id),requestAnimationFrame(()=>{n.classList.remove(V.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(V.hidden)}show(){let e=this.getElement();e&&e.classList.remove(V.hidden)}enable(){let e=this.getElement();e&&(e.classList.remove(V.disabled),this.controls.forEach(e=>e.enable()),this.isDisabled=!1)}disable(){let e=this.getElement();e&&(e.classList.add(V.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(ae(n,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${Bt.name} remove view transition error`,e))).add(ae(n,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${Bt.name} remove view transition error`,e)));return}this.subscriptions.unsubscribe(),this.removeAllControls(),n.remove(),this.isRemoved=!0,this.willRemoved=!1,this.containerElement=null}}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))}}function Yt(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}var Xt=`video_interactive`,Zt=`videoint`,Qt=250;class $t{constructor(e){this.isHidden=void 0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=void 0,this.onOpenPreviewClick=void 0,this.onError=void 0,this.lang=void 0,this.zoom=void 0,this.lastZoomInfo=void 0,this.isReady=void 0,this.ngEditor=void 0,this.ngEditorSize=void 0,this.graphWrapperElement=void 0,this.resizeObserver=void 0,this.manifest=void 0,this.handleZoomChange=Yt(e=>{this.lastZoomInfo=e},Qt),this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t,void 0,{isFromCenter:!0}),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}},this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.call(this,`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}},this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!ge(e.graph.edit.chapters[0].x)){this.onError?.call(this,`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)},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=en(e),this.resizeObserver=new ResizeObserver(Yt(this.onResize,Qt)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}show(){var e=this;return w(function*(){e.manifest&&(e.ngEditor||(yield e.initNgEditor()),e.graphWrapperElement.style.display=`block`,!e.lastZoomInfo&&e.currentChapterId&&e.ngEditor?.focusChapter(e.currentChapterId),e.isHidden=!1)})()}initNgEditor(){var e=this;return w(function*(){if(!e.manifest)return;let t;try{t=yield Jt(e.lang,Xt,Zt)}catch{e.onError?.call(e,`Unable to load graph language pack`)}let{GraphEditor:n}=yield import(`@interactiveplatform/movika-graph-editor`);e.ngEditor=new n(e.graphWrapperElement,{mode:`view`,lang:e.lang===`ru`?`ru`:`en`,translation:t}),e.currentManifestId=e.manifest.metadata.id,e.ngEditor.update(e.manifest),e.ngEditor.setVisitedChapters(Array.from(e.visitedChapterIds)),e.currentChapterId&&e.ngEditor.selectChapter(e.currentChapterId),e.ngEditor.on(`control`,t=>{let{name:n}=t,r=T(t,x);n===`openPreview`&&`chapterId`in r&&e.onOpenPreviewClick?.call(e,r.chapterId)}),e.ngEditor.on(`zoom`,e.handleZoomChange),e.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 en(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 tn=3e3;class nn{constructor(){this._containers=[],this._player=null,this.setPlayer=e=>{this._player=e},this.setContainers=e=>{this._containers=e},this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)},this.getNextInteractiveTime=(e=tn)=>{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 rn{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let 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 an{constructor(e){this.raf=void 0,this.fn=void 0,this.fns=[],this.addFn=(e,t=!1)=>{_e(e)&&(this.fns.push(e),t&&this.updateFn())},this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(t=>t!==e),t&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{this.raf&&=(cancelAnimationFrame(this.raf),void 0)},e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class sn{constructor(e){this.rootElement=void 0,this.isCssVarsSupported=void 0,this.rootElementProps={},this.rootElement=e,this.isCssVarsSupported=sn.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=C(C({},this.rootElementProps),e),this.isCssVarsSupported)for(let[t,n]of on(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)}}class ln{constructor(e){this.loaders=void 0,this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}exec(e,t){var n=this;return w(function*(){return un(...n.loaders[e])(t)})()}}function un(...e){return function(){var t=w(function*(t){let n=[...e];for(;n.length>0;)t=yield n.shift()(t);return t});function n(e){return t.apply(this,arguments)}return n}()}function dn(e,t,n){return e?C(C({},e),{},{[t]:e[t]?[n,...e[t]]:[n]}):{[t]:[n]}}function fn(e){let{actions:t,errors:n,chapterId:r}=e,i=T(e,te);if(r){let e=t.getManifest();if(e){let a=t.getChapter(e.chapters,r);if(a){let r=t.getMedia(e.media,a.videoId),o=t.getGraph(e.graph,a.id);return r?C(C({},i),{},{actions:t,errors:n,result:{chapter:a,media:r,graph:o}}):C(C({},i),{},{errors:dn(n,fn.name,`Could not find media`),actions:t})}}}return C(C({},i),{},{errors:dn(n,fn.name,`Could not find chapter`),actions:t})}var mn=(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},hn=function(){var e=w(function*(e){try{let t={},n;if(me(e)){n=new URL(e).href;let r=yield pn(n);if(!r.ok)return{};t=yield r.json()}else if(M(e))t=e;else return{};if(!Xe(t))return{};let r=t.metadata.media;if(me(r)&&!(`media`in t))try{let e;n?e=new URL(r,n).href:(e=new URL(r).href,n=e);let i=yield pn(e);if(!i.ok)throw Error();t.metadata.media=yield i.json()}catch{return Cn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:n}}catch{return{}}});return function(t){return e.apply(this,arguments)}}();function gn(e){return _n.apply(this,arguments)}function _n(){return _n=w(function*(e){let{manifest:t,manifestURL:n}=yield hn(e);if(!t)throw Error(`Failed on fetch`);let r=Je(t);return r.media=xn(r.media,n),delete r.metadata.media,r}),_n.apply(this,arguments)}function vn(e,t){if(t)return e.find(e=>e.id===t)}function yn(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 bn(e,t){return e.videos.find(e=>e.id===t)}function xn(e,t){return C(C({},e),{},{videos:e.videos.map(e=>C(C({},e),{},{variants:e.variants.map(e=>{let n=`url`in e?e.url:``,r=Sn(n,t);return C(C({},e),{},{url:r||n})})}))})}function Sn(e=``,t){try{return new URL(e,t).href}catch{return``}}function Cn(e){return mn(e,`3.2.0`)>=0}class wn extends ln{constructor(e,t){super(e),this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$=new cn(null),this.onError=void 0,this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(e){var t=this;return w(function*(){t.release();let n=yield t.exec(`manifestLoaders`,{actions:{addErrorMessage:dn},result:null,errors:null,source:e});return n.errors&&t.errorHandler(n.errors),t.manifest=yield gn(n.result??e),t})()}setInitial(){var e=this;return w(function*(){return e.setNext()})()}setNext(){var e=this;return w(function*(t=this.manifest?.metadata.initChapterId){if(!t)return e;e.prevChapter$.next(e.chapter);let n=yield e.exec(`chapterLoaders`,fn({actions:{getManifest:()=>e.manifest,getCurrent:e.getCurrent,getGraph:yn,getChapter:vn,getMedia:bn,getByBranches:e.getByBranches.bind(e),addErrorMessage:dn},result:null,errors:null,chapterId:t}));return n.errors&&e.errorHandler(n.errors),n.result&&(e.chapter=n.result.chapter,e.media=n.result.media,e.graph=n.result.graph),e}).apply(this,arguments)}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=vn(this.manifest.chapters,e);if(t){let e=bn(this.manifest.media,t.videoId),n=yn(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=vn(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?L(this.chapter):!1}}var An=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[]};function Mn(){let e=new Map;function t(t){let{listId:n=Math.random().toString(),itemId:r=Math.random().toString()}=t,i=T(t,ne),a=e.get(n),o=C({},i);return a?a[r]=o:e.set(n,{[r]:o}),C({listId:n,itemId:r},i)}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 jn(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}}function Pn(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||Nn(t,`mp4`))&&(n.MPEG=C(C({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`mpeg`:(i||Nn(t,`mpeg`))&&(n.MPEG=C(C({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`hls`:(i||Nn(t,`hls`))&&(n=C(C({},n),{},{HLS:{type:`url`,url:a.url}}));break;case`dash`:(i||Nn(t,`dash`))&&(n=C(C({},n),{},{DASH_SEP:{compatibilityMode:!0,type:`url`,url:a.url}}));break;default:break}return{sources:n,thumbUrl:r,title:e.title??``}}var Fn=(e,t)=>{let n=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();n!==t&&Nn(r,t)&&(e.setQuality(t),e.setAutoQuality(!1))},In=2;function Ln(e){let t=Mn(),n=new Dn,r={},i=null,a=!1,o,s=new kn(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=C({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)Tn(n[1]).forEach(({player:t})=>{Fn(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.`)}function u(e){return d.apply(this,arguments)}function d(){return d=w(function*(e){if(!i)throw Error(`need to set interactive controller`);if(be(r)||e!==r.itemId)return;let t=i.getChapterBranches(),n=new Set;for(let e of t)n.has(e.media.id)||(yield m({media:e.media,chapterId:e.chapter.id,setAsActive:!1,title:e.chapter.label}),n.add(e.media.id))}),d.apply(this,arguments)}function f(e){return p.apply(this,arguments)}function p(){return p=w(function*({chapter:{id:e},manifestVideo:n}){if(be(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,f=!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<In||(f=!0),t.removePlayer(s[0],i)):(f=!0,l(s[0],i,e),d?Fn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a),r.player.setPlaybackRate(u))}else t.removePlayer(s[0]);f||(yield m({media:n,chapterId:e,setAsActive:!0,playbackRate:u}),d?Fn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a))}),p.apply(this,arguments)}function m(e){return h.apply(this,arguments)}function h(){return h=w(function*({media:e,chapterId:n,prefetch:a=!0,setAsActive:s=!0,autoplay:c=!1,preferredExt:u,title:d,playbackRate:f}){var p,m,h,g;let _=Math.random().toString(),v=document.createElement(`div`);o.append(v);let y;if(!(i==null||(p=i.options)==null)&&p.vkVideoLoader){let t=An(e);t.length&&(y=yield i.options.vkVideoLoader(...t))}let b=C({},(i==null||(m=i.options)==null?void 0:m.coreConfig)||void 0),ee=C(C({container:v,sources:Pn(e,u).sources},y==null||(h=y.videos)==null?void 0:h[0]),{},{title:d,failoverHosts:y?.failoverHosts||[]}),x=new En(b,On.createRootTracer());x.initVideo(ee);let te=null;if(y?.videos&&i?.options.createOneStat){let e=y.videos[0],t=i.options.createOneStat(e),n=new Dn;t&&(n.add(t.attachTo(x)),te={oneStat:t,statSubscription:n})}let ne=new Dn,re=r==null||(g=r.player)==null?void 0:g.info.isAutoQualityEnabled$.getValue();ne.add(x.events.canplay$.subscribe(function(){re||Fn(x,r.player.info.currentQuality$.getValue()),f&&x.setPlaybackRate(f)}));let S=t.createPlayer({listId:e.id,itemId:_,player:x,container:v,sources:Pn(e,u).sources,config:ee,subscription:ne,statistics:te});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}}),h.apply(this,arguments)}function g(){_(),i=null,o.remove()}function _(){n.unsubscribe(),t.removeAll(),r={},a=!1}function v(){return y.apply(this,arguments)}function y(){return y=w(function*(){if(!i)throw Error(`need to set interactive controller`);_(),o=document.createElement(`div`);let{media:e,chapter:t}=i.getCurrentChapter();e&&t?(n.add(i.events.chapterChanged$.subscribe(f)),yield m({media:e,chapterId:t.id,title:t.label})):console.error(`not found`)}),y.apply(this,arguments)}return{map:t.map,removePlayer:t.removePlayer,init:v,setInteractiveController:c,createPlayer:m,removeAll:g,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`},Rn={visibility:`visibility`,watchAgainClicked:`watchAgainClicked`},J={actionChoiceCanceled:`action-choice-canceled`,actionChoice:`action-choice`,actionExecution:`action-execution`,visibility:`visibility`,containerRemoved:`container-removed`,rangeEnded:`range-ended`};function Bn(e){return function(...t){return e(...t.reverse())}}function Vn(e,...t){return(...n)=>M(t[0])&&M(n[0])?e(C(C({},t[0]),n[0])):e(...t,...n)}class Hn{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=void 0,this.branches=void 0,this.selectBranches=void 0,this.subscription=void 0,this.player=void 0,this.interactiveEvents=void 0,this.getContainerEventState=void 0,this.isPermanentText=void 0,this.interactiveTimeOpenUri=void 0,this.disabledControls$=void 0,this.onRemove=void 0,this.globalEventEmitter=void 0,this.gameState=void 0,this.isSelectedControlEvent=void 0,this.isSelectedContainerEvent=void 0,this.globalEvents=void 0,this.onError=void 0,this.disableTextControlContainerVisibilityEvents=void 0,this.features=void 0,this.hide=()=>{setTimeout(()=>{if(this.gameState!==4&&!(R(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect)){if(this.gameState!==2){var e;(e=this.container).hide?.call(e)}this.emitContainerVisibilityEvent(!1)}})},this.show=()=>{if(!(this.gameState!==2||this.isSelectedControlEvent))if(this.container.getElement()){var e;let{hasOpenURIEventInCurrentContainer:t}=this.getContainerEventState();if((e=this.container).show?.call(e),this.interactiveTimeOpenUri&&t||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},n=Vn(this.selectBranches.onControlEvent,e),r=(this.player?.info.duration$.getValue()??1/0)*1e3;if(this.container.createView({eventCallback:n,videoDurationMs:r}),this.disableTextControlContainerVisibilityEvents||this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()){var t;(t=this.container).disable?.call(t)}}},this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)},this.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(ot(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(st(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();if(e){if(e.style.visibility!==`hidden`){var r;(r=this.container).hide?.call(r)}this.container.isRemoved||this.fakeRemoveView()}}!this.isPermanentText&&!n&&this.removeView()}let i=st(n,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:`container`,range:a,currentTime:n,isInteractiveTime:i};this.container.onProgress(n*1e3,i),this.globalEventEmitter.emit(q.eachTick,o),this.globalEvents.eachTick$.next(o)},this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new zn,this.player=e,this.interactiveEvents=i,this.getContainerEventState=s;let h=ut(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:J.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:J.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=>{if(e){var t;(t=this.container).disable?.call(t)}else{var n;(n=this.container).enable?.call(n)}})),this.subscription.add(this.container.error$.subscribe(this.onError))}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:R(this.container.container.events)||e;(this.isSelectedControlEvent||!n)&&this.removeView()}onBeforeStartTime(){var e;(e=this.container).hide?.call(e),this.emitContainerVisibilityEvent(!1)}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:J.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:`container`,type:`container-removed`}),this.gameState=5,this.onRemove?.call(this)}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 Un=(e=[])=>e.reduce((e,t,n)=>{if(it((t?.controls??[]).filter(e=>!Ze(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]);function qn(){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(ye(t)){let i=e[t]??null;if(i&&n&&Se(n,!0)){let e={},t=i[n];return t&&(e=C(C({},e),t)),e=be(e)?null:e,e&&Se(r,!0)?e[r]??null:e}return i}return null}function a({timestamp:t,priority:n,initiator:r}){if(ye(t))if(e[t]){if(n&&Se(n,!0))if(e[t][n]){if(r&&Se(r,!0))if(e[t][n][r]){if(delete e[t][n][r],!be(e[t][n]))return!0}else return!1;if(delete e[t][n],!be(e[t]))return!0}else return!1;return delete e[t]}else return!1;return!1}function o(t){var n;let{timestamp:r,priority:i,initiator:a}=t,o=T(t,re);!((n=e[r])==null||(n=n[i])==null)&&n[a]?e[r][i][a].push(C({},o)):e[r]?.[i]?e[r][i]=C(C({},e[r][i]),{},{[a]:[C({},o)]}):e[r]?e[r]=C(C({},e[r]),{},{[i]:{[a]:[C({},o)]}}):e[r]={[i]:{[a]:[C({},o)]}}}return{map:e,remove:a,add:o,removeAll:t,get:i,getLte:n,getGte:r}}var Jn=[I.expect,I.setNextBranch],Yn=1/0;function Xn(e,t){let n=e,r,i=Zn(t),a=qn(),o,s=()=>{p(),_()},c=e=>{a.add.call(void 0,e),m()},l=(e=[])=>{for(let t of e)if(t.action(),Wn(Jn,t.actionType))break},u=(e=1/0)=>{let t=Qn(a.get({timestamp:e,priority:`control`})??{}),n=Qn(a.get({timestamp:e,priority:`container`})??{}),r=Qn(a.get({timestamp:e,priority:`chapter`})??{});return[...t,...n,...r]},d=e=>{i.isReady(e)&&l(u(e))},f=()=>{l([...Qn(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 Zn(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??Yn,r=t.get(e);t.set(e,C(C({},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=Gn(r);return e?i.some(e=>e):!i.some(e=>!e)},release:()=>t.clear()}}function Qn(e){return Kn(Gn(e)).sort(e=>e.actionType===I.expect?-1:1)}var $n={videoContentHeight:0,videoContentWidth:0},er=e=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return $n;let{clientHeight:r,clientWidth:i}=e.experimental.element$.getValue()||{};if(!(r&&i))return $n;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}},tr=250;function nr(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}=er(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=Yt(t=>{let{fns:n=[]}=e();r(t);for(let e of n)e()},tr);function o(){t=void 0,n.disconnect(),i()}return{resizeObserver:n,calc:()=>{t?.()},release:o}}var rr=e=>Math.floor(Math.random()*e),ir=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},ar=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},or=e=>{let t=e.length;return e[rr(t)]},sr=1,cr=e=>{let t=0;for(let n=0;n<e.length;++n)t+=e[n].weight??sr;let n=Math.random()*t;t=0;for(let r=0;r<e.length-1;++r)if(t+=e[r].weight??sr,t>=n)return e[r];return e[e.length-1]},lr={shouldOpenNow:!0,isDetachContainer:!0},ur=`after-expect`,dr=(e,t=!1)=>C(C({},e),{},{args:t?C(C({},e.args),lr):C(C({},lr),e.args)}),fr=({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=dr(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?J.actionChoiceCanceled:J.actionChoice,actionType:n.type,payload:C({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:C({invokeImmediately:f.args.shouldOpenNow,containerId:o},f.args)})};if(v){y(),b();return}switch(f.type.trim().toLowerCase()){case I.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(C(C({},_),{},{action:h.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:f,payload:{chapterId:e.chapterId,autoSelect:!1}})}));return}case I.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(C(C({},_),{},{action:m.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:n})}));return;case I.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(C(C({},_),{},{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 k(1,1,{message:e}),e);return}}},s=({action:n,container:{id:i,endTime:a},branches:o=[],isEOV:s=!1,autoSelected:c=!1})=>{let l=dr(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:J.actionChoice,actionType:l.type,payload:C({invokeImmediately:l.args.shouldOpenNow},l.args)}),p=()=>{t.interactiveActionChoice$.next({subjectId:i,subjectName:`container`,type:`action-choice`,actionType:l.type,payload:C({invokeImmediately:l.args.shouldOpenNow},l.args)})};switch(l.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let e=o.find(e=>e.id===l.args.branchId);if(!e)return;f(),p(),r.add(C(C({},d),{},{action:h.bind(null,{subjectId:i,subjectName:`container`,action:l,payload:{chapterId:e.chapterId,autoSelect:c}})}));return}case I.setMaxWeightBranch.trim().toLowerCase():return;case I.setMinWeightBranch.trim().toLowerCase():return;case I.setRandomBranch.trim().toLowerCase():return;case I.setWeightlessRandomBranch.trim().toLowerCase():return;case I.continuePlayback.trim().toLowerCase():f(),p(),r.add(C(C({},d),{},{action:m.bind(null,{subjectId:i,subjectName:`container`,action:l})}));return;case I.openURI.trim().toLowerCase():f(),p(),r.add(C(C({},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 k(1,1,{message:e}),e);return}}};function c({container:n,branches:a,isEOV:o=!1}){let c=ct(n.events);if(c){let a=dr(c.action,o);e.emit(q.interactives,{subjectId:n.id,subjectName:`container`,type:J.actionChoice,actionType:a.type,payload:C({invokeImmediately:a.args.shouldOpenNow},a.args)}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`container`,type:`action-choice`,actionType:a.type,payload:C({invokeImmediately:a.args.shouldOpenNow},a.args)}),r.add({timestamp:o?1/0:n.endTime??1/0,priority:`container`,initiator:n.id,actionType:I.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:J.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 I.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 I.setWeightlessRandomBranch.trim().toLowerCase():{let e=or(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let e=cr(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let e=ar(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let e=ir(i);return e?.chapterId?(a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return a(),o(),m.bind(null,{subjectId:n,subjectName:`chapter`,action:r});case I.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 k(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=ct(n.events);if(i){if(L(n))return;e.emit(q.interactives,{subjectId:n.id,subjectName:`chapter`,type:J.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:I.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:J.actionExecution,actionType:I.expect}),t.interactiveActionExecution$.next({subjectId:r,subjectName:i,type:`action-execution`,actionType:I.expect})},p=({subjectId:i,subjectName:a})=>{n.info.isEnded$.getValue()?r.execEndOfVideo():n.play(),e.emit(q.interactives,{subjectId:i,subjectName:a,type:J.actionExecution,actionType:ur}),t.interactiveActionExecution$.next({subjectId:i,subjectName:a,type:`action-execution`,actionType:ur})},m=({subjectId:n,subjectName:r,subjectType:i,action:a})=>{e.emit(q.interactives,{subjectId:n,subjectName:r,subjectType:i,type:J.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:J.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:J.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}};var gr=(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]=yr(i)}return n[e]}).filter(e=>e!==null)},_r=e=>{for(let t of e.variants)if(vr(t)&&t.payload)return t.payload.id},vr=e=>!!(e.type===`custom`&&e.payload&&e.payload.type===`vk`),yr=e=>{let t=_r(e);if(!t)return null;let n=t.split(`_`).pop();return n?parseInt(n,10):null},br=(e,t)=>{for(let n of e.media.videos)if(t===yr(n)){for(let t of e.chapters)if(t.videoId===n.id)return t.id;return}},xr=(e,t)=>e.reduce((e,n)=>{let r=br(t,n);return r?[...e,r]:e},[]),Y=new WeakMap,Sr=new WeakMap,Cr=new WeakMap,X=new WeakMap,wr=new WeakMap,Z=new WeakMap,Q=new WeakMap,$=new WeakMap,Tr=new WeakMap,Er=new WeakMap,Dr=new WeakMap;class Or{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:i}){this.state={history$:new hr([]),hasPrevChapter$:new hr(!1),prevChapter$:new hr(null),isInitialChapter$:new hr(!1),isGoBackLimited$:new hr(!1)},E(this,Y,null),E(this,Sr,void 0),E(this,Cr,!1),E(this,X,null),E(this,wr,null),this.events={inited$:new mr,destroyed$:new mr,error$:new mr},E(this,Z,null),E(this,Q,null),E(this,$,null),E(this,Tr,new pr),E(this,Er,!1),E(this,Dr,0),D(Z,this,t),D($,this,e),D(Q,this,n),D(Y,this,r),D(Sr,this,i),this.state.history$&&O(Tr,this)&&O(Tr,this)?.add(this.state.history$.subscribe(e=>{var t;this.state.prevChapter$.next(e.at(-2)||null),this.state.hasPrevChapter$.next(e.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===((t=O(X,this))==null||(t=t.metadata)==null?void 0:t.initChapterId)),this.state.isGoBackLimited$.next(O(Dr,this)===O(Sr,this).maxLength-1)}))}setManifest(e){var t=this;return w(function*(){if(!O(Q,t)||!O($,t))return;D(X,t,e),yield t.getProjectHistory();let n=t.getInitialChapterId();yield O(Q,t).setChapter({chapterId:n,pushToHistory:!1}),O(Cr,t)||(D(Cr,t,!0),t.events.inited$.next({initChapterId:n}))})()}get inited(){return O(Cr,this)}updateHistory(e,t=!0){var n=this;return w(function*(){if(!O(X,n))return;if(O(Er,n)){var r;D(Er,n,!1),D(Dr,n,(r=O(Dr,n),r++,r))}else D(Dr,n,0);let i=O(X,n),a=e.length-O(Sr,n).maxLength,o=a>0?e.slice(a):e,s=gr(o,i);if(D(wr,n,s),n.state.history$.next(o),!(!t||!O(Y,n)||!O(Z,n)))try{yield O(Y,n).save(O(Z,n),s)}catch{let e=new k(1,5,`Unable to save interactive history`);n.events.error$.next(e),O($,n)?.emit(q.errors,e)}})()}goBack(){var e=this;return w(function*(){if(!e.state||!O(Q,e)){let t=new k(1,5,`Unable to save interactive history`);e.events.error$.next(t),O($,e)?.emit(q.errors,t);return}D(Er,e,!0);let t=e.state.history$.getValue().slice(0,-1),n=t.pop();e.state.history$.next(t),yield O(Q,e).setChapter({chapterId:n,playPrev:!0})})()}getProjectHistory(){var e=this;return w(function*(){if(!O(X,e)||!O(Z,e))return;let t=O(X,e),n=[e.getInitialVideoId()];if(O(Y,e))try{let t=yield O(Y,e).get(O(Z,e));t.length&&(n=t)}catch{let t=new k(1,5,`Error while trying to fetch data`);e.events.error$.next(t),O($,e)?.emit(q.errors,t)}let r=xr(n,t);e.state.history$.next(r)})()}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||O(Sr,this).initChapterId||O(X,this)?.metadata.initChapterId}getInitialVideoId(){return O(X,this)?gr([this.getInitialChapterId()],O(X,this)).pop():null}destroy(){D(Z,this,null),D(Y,this,null),D(Q,this,null),O(Tr,this)?.unsubscribe(),D(Tr,this,null),D(Cr,this,!1),O($,this)?.emit(q.historyDestroyed),this.events.destroyed$.next(),D($,this,null)}}class kr{constructor(){this.rootElement=void 0,this.canvasImgSrc=void 0,this._prevSizeId=0,this.rootElement=document.createElement(`canvas`)}clear(){this.rootElement.getContext(`2d`)?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext(`2d`)?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,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)}updateCanvasDimensions(e,t=!1){var n=this;return w(function*(){let r=e.width+e.height;if(n._prevSizeId===r)return;let i;t&&(i=yield n.save()),n.rootElement.width=e.width,n.rootElement.height=e.height,t&&i&&n.restore(i),n._prevSizeId=r})()}save(){var e=this;return w(function*(){let t=e.rootElement.toDataURL(`image/jpeg`,1),n=new Image;return n.crossOrigin=`anonymous`,n.src=t,yield n.decode(),n})()}restore(e){this.rootElement&&this.rootElement.getContext(`2d`)?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}}class Ar{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.lastFrameCanvas=void 0,this.endOffsetMs=void 0,this.currentChapter=void 0,this.currentVideoDurationMs=1/0,this.rootElement=void 0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this._callbacks=void 0,this.onEachTick=e=>{let t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},this.rootElement=document.createElement(`div`),this.rootElement.style.cssText=`
7
7
  position: absolute;
8
8
  top: 0;
9
9
  left: 0;
@@ -282,4 +282,4 @@ import{fromEvent as ae,Subscription as oe}from"@vkontakte/videoplayer-shared/es2
282
282
  .interactive-control-fill-animation-filler.interactive-control-fill-animation-from-bottom {
283
283
  transform-origin: bottom;
284
284
  }
285
- `,Nr=e=>{let t=document.createElement(`style`);t.textContent=Mr,e.prepend(t)};var Fr=Object.freeze({lang:Ht.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4},isTouch:!1,disableTextControlContainerVisibilityEvents:!1,animationsFeatureToggles:{areaControlShadow:!1,controlsExpectTimeBlinkAnimation:!1,controlsTapPlace:!1,controlsFillAnimation:!1,controlsHideAnimation:!1},enableAvPlayerSupport:!1});function Ir(){let e=document.createElement(`div`);return e.classList.add(`interactive-chapter`),e}class Lr{constructor(e){if(this.playerSubscriptions=new Gt,this.subscriptions=new Gt,this.globalEventEmitter=new rn,this.animation=new an,this.seekToInteractiveController=new nn,this.endedRanges=new Set,this.gameControllers=[],this.rootElement=Ir(),this.factories=new Map([[`choice`,zt]]),this.isFirstChapterFetched=!1,this._options=void 0,this.manifestController=void 0,this.resizeManager=void 0,this.cssVarsManager=void 0,this.historyController=void 0,this.player=null,this.interactiveEvents=null,this.selectBranches=null,this.seamlessController=null,this.seamlessControllerSubs=new Gt,this.graph=null,this.lastFrame=null,this.noInteractionTimeout=void 0,this.blinkAnimationRef=null,this.appState=0,this.state={prevChapter$:new K(null),isInitialChapter$:new K(!1),isFirstChapter$:new K(!0),isEndChapter$:new K(!1),isInteractiveExpectation$:new K(!1),isReplay$:new K(!1),calledByInteractive$:new K(!1),lastChapterChangeWasInitiatedByInteractive$:new K(!1),disabledControls$:new K(!1),interactiveRanges$:new K([]),isInteractiveTime$:new K(!1),statistics$:new K(null),isSeekable$:new K(!1)},this.events={noInteraction$:new G,graphVisibilityChanged$:new G,watchAgainIsClicked$:new G,chapterChanged$:new G,playerChanged$:new G,error$:new G,eachTick$:new G,manifestChanged$:new G,interactiveRangeEnded$:new G,interactiveContainerRemoved$:new G,interactiveContainerFakeRemoved$:new G,interactiveActionExecution$:new G,interactiveActionChoice$:new G,interactiveVisibilityChanged$:new G},this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(q.errors,e)},this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&L(n)&&!t&&this.historyController.updateHistory([]),window.removeEventListener(`beforeunload`,this.clearHistoryIfEnded)},this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t}=e,n=T(e,S);if(t){let{statSubscription:e,oneStat:n}=t;e.add(n.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(q.playerChanged,n)},this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()},this.destroyGameControllers=({removeTextControls:e=!0,withTransition:t=!1}={})=>{for(let n of this.gameControllers)!e&&n.isPermanentText||(this.animation.removeFn(n.whilePlaying),n.destroy(t))},this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(t=>C(C({},t),{},{subjects:t.subjects.filter(t=>t.id!==e)}));t.next(n)},this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&=(clearTimeout(this.noInteractionTimeout),void 0)},this._options=C(C(C({},Fr),e),{},{config:C(C({},Fr.config),e.config)}),this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation){this.blinkAnimationRef=new gt,this.blinkAnimationRef.create();let e=this.blinkAnimationRef.element;e&&this.rootElement.append(e)}this._options.parentElement.append(this.rootElement),this.historyController=new Or({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new Ar({parentElement:this._options.parentElement,onError:e=>{let t=new k(1,6,e);this.emitErrorEvent(t)}})),Nr(this._options.parentElement),this.subscriptions.add(Kt(this.rootElement,`mousedown`).subscribe(e=>e.stopPropagation())).add(Kt(this.rootElement,`mouseup`).subscribe(e=>e.stopPropagation())),this.manifestController=new wn(this._options.loaders,e=>{let t=new k(1,3,e);this.emitErrorEvent(t)});let t=[];this._options.lastFrame&&t.push(()=>{this.lastFrame?.updateCanvasDimensions(!0)}),t.push(()=>{let e=this.state.isInteractiveTime$.getValue();for(let t of this.gameControllers)t.onResize(e)}),this.cssVarsManager=new sn(this._options?.parentElement),this.resizeManager=nr(()=>({player:this.player,cssVarsManager:this.cssVarsManager,parentElement:this._options.parentElement,fns:t})),this._options.graph&&(this.graph=new $t({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:e=>{this.setChapter({chapterId:e}),this.globalEventEmitter.emit(q.graph,{type:Rn.watchAgainClicked,chapterId:e}),this.events.watchAgainIsClicked$.next(e)},onError:e=>{let t=new k(1,2,{message:e});this.emitErrorEvent(t)}})),this.initSubscriptions()}initSubscriptions(){var e=this;this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(function(){var t=w(function*({videosInfo:t=[]}){e._options.initSeamless&&(yield e.initSeamless(),e.updateGraphVideosInfo(t))});return function(e){return t.apply(this,arguments)}}())),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{if(this.state.calledByInteractive$.next(!0),(e.actionType===`setNextBranch`||!this._options.endChapterHistoryFix)&&this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour===`change-chapter`){let{chapterId:t}=e.payload;this.setChapter({chapterId:t}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(e.payload?.behaviour===`change-manifest`){let{manifestURL:t}=e.payload;t&&this.setManifest(t)}e.actionType===`expect`?(this.state.isInteractiveExpectation$.next(!0),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0})):e.actionType===`after-expect`&&(this.state.isInteractiveExpectation$.next(!1),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}))})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:n})=>{e!==`action-choice`||t===`chapter`||`invokeImmediately`in n&&n.invokeImmediately||this.destroyGameControllers({removeTextControls:!1,withTransition:this._options.animationsFeatureToggles?.controlsHideAnimation})}))}initSeamless(){var e=this;return w(function*(){e.seamlessController=Ln(e),e.seamlessControllerSubs.add(e.seamlessController.activePlayerChanged.subscribe(e.handleSeamlessPlayerChanged)),yield e.seamlessController.init()})()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,n=this.getInteractiveRanges().reverse().find(({range:e})=>t>=e[1]);if(n){let e=n.range.join(`-`);this.endedRanges.has(e)||(this.endedRanges.add(e),this.globalEventEmitter.emit(q.interactives,{type:J.rangeEnded,payload:n,visibility:!0}),this.events.interactiveRangeEnded$.next({type:`range-ended`,payload:n}))}}registerVideoEvents(){this.player&&(window.removeEventListener(`beforeunload`,this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener(`beforeunload`,this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Wt()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Vt({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let n=e*1e3;r=!!t.find(({range:[e,t],subjects:r})=>e<n&&n<t&&r.some(e=>!e.isRemoved)&&r.length)}r!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(r);let i=!!this.noInteractionTimeout,a=this.player?.info.playbackState$.getValue()===`playing`||n;r&&!i&&a?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):i&&!a&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(e=>e.container.container).filter(e=>!ut(e.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(n=>{let r=n.type.trim().toLowerCase(),i=this.factories.get(r)?.(n,this.rootElement,this.cssVarsManager,{isTouch:this._options?.isTouch??!1,features:{controlsExpectTimeBlinkAnimation:this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation,controlsTapPlace:this._options.animationsFeatureToggles?.controlsTapPlace,controlsFillAnimation:this._options.animationsFeatureToggles?.controlsFillAnimation}});if(i&&this.selectBranches&&this.interactiveEvents&&this.player){let r=new Hn({player:this.player,container:i,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>mt(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)},onError:this.emitErrorEvent,disableTextControlContainerVisibilityEvents:this.options.disableTextControlContainerVisibilityEvents??!1,features:{controlsHideAnimation:this._options.animationsFeatureToggles?.controlsHideAnimation,enableAvPlayerSupport:this._options.enableAvPlayerSupport}});this.animation.addFn(r.whilePlaying,!0),t.push(r)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let e=this.state.isSeekable$.getValue(),t=!!this.seekToInteractiveController.getNextInteractiveTime();(t&&!e||!t&&e)&&this.state.isSeekable$.next(!e)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(n&&L(n)&&at(n))??!1,i=this.manifestController.manifest?.metadata.initChapterId===e,a=this.historyController.state.history$.getValue();if(i||r&&t){this.historyController.updateHistory([e]);return}a.at(-1)!==e&&this.historyController.updateHistory([...a,e])}handleFakeRemoval(e,t){let{interactiveRanges$:n}=this.state,r=n.getValue().map(n=>{let r=n.subjects.some(t=>t.id===e),i=n.subjects.map(n=>t&&r||n.id===e?C(C({},n),{},{isRemoved:!0}):n);return C(C({},n),{},{subjects:i})});n.next(r)}reset(){this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this._options.endChapterHistoryFix&&this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1),this.clearNoInteractionTimeout())}toggleBlinkAnimation(e){this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation&&(ft(C(C({},e),{},{gameControllers:this.gameControllers,execFn:Vn(Bn((e,t)=>{e.toggleBlinkAnimation(t)}),e.isExpect)})),e.isExpect)&&this.blinkAnimationRef?.restart()}updateControlsShadowStyles(e){if(!this._options.animationsFeatureToggles?.areaControlShadow)return;let t=(e,t)=>{e.updateControlsShadowStyles(t)};e.isExpect?ft(C(C({},e),{},{gameControllers:this.gameControllers,execFn:Vn(Bn(t),!1)})):ft(C(C({},e),{},{gameControllers:this.gameControllers,execFn:t}))}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}setManifest(e){var t=this;return w(function*(){t.reset(),t.isFirstChapterFetched=!1;let n=yield t.manifestController.setManifest(e);if(n.manifest)return t.graph&&t.graph.handleManifestChange(n.manifest),yield t.historyController.setManifest(n.manifest),t.events.manifestChanged$.next(n.manifest),t.globalEventEmitter.emit(q.manifestChanged,{manifest:n.manifest}),t.setGameControllers(),n.manifest})()}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Xn(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=fr({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}setChapter(){var e=this;return w(function*({chapterId:t,pushToHistory:n=!0,playPrev:r=!1}={}){e.reset(),e.lastFrame&&e.isFirstChapterFetched&&(e.lastFrame.draw(),e.lastFrame.show()),e.lastFrame&&Pr.browser.isSafari&&(yield jr(35));let i=!r&&e.state.isEndChapter$.getValue()&&e.getCurrentManifest()?.metadata.initChapterId===t;e.state.isReplay$.next(i);let{chapter:a,media:o,graph:s}=yield t?e.manifestController.setNext(t):e.manifestController.setInitial();(!t||i)&&e.state.isFirstChapter$.next(!0),!(!a||!o)&&(n&&e.pushChapterToHistory(a.id),e.state.isInitialChapter$.next(e.manifestController.isInitialChapter()),e.state.isEndChapter$.next(e.manifestController.isEndChapter()),e.graph&&e.graph.handleChapterChange(a),e.state.isInteractiveTime$.next(!1),e.state.isInteractiveExpectation$.next(!1),e.lastFrame?.setCurrentChapter(a),e.events.chapterChanged$.next({chapter:a,manifestVideo:o}),e.globalEventEmitter.emit(q.chapterChanged,{chapter:a,media:o,graph:s}),e.setGameControllers(),e.endedRanges=new Set,e.isFirstChapterFetched=!0)}).apply(this,arguments)}getStatEvents(){return{click$:new Ut(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?qt.GRAPH_SHOW:qt.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(qt.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:n,subjectType:r})=>{t!==`action-choice`||n!==`control`||(r===`Button`&&e.next(qt.NEXT_BUTTON),r===`Area`&&e.next(qt.NEXT_AREA))}))}),nextMovie$:new Ut(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}toggleGraphView(e=!0){var t=this;return w(function*(){t.graph&&(e?(yield t.graph.show(),t.state.isSeekable$.next(!1)):(t.graph.hide(),t.checkIfSeekable()),t.globalEventEmitter.emit(q.graph,{type:Rn.visibility,visibility:e}),t.events.graphVisibilityChanged$.next(e))})()}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(e=>e.actionType===I.setNextBranch)}allControlsAreRemoved(e=!0){return!this.gameControllers.some(t=>{let n=e&&this._options.animationsFeatureToggles?.controlsHideAnimation?t.container.willRemoved:!0;return!t.container.isRemoved||!n})}isEndedExpectation(){return!this.player||!this.gameControllers?!1:this.player.info.position$.getValue()===this.player.info.duration$.getValue()&&this.gameControllers.some(e=>{let t=e.container.container;return!e.container.isRemoved&&!e.container.willRemoved&&t.endTime===null&&R(t.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&We(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return Un(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){this.clearHistoryIfEnded(),this.blinkAnimationRef?.destroy(),this.destroyGameControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}}var Rr={Container:fe,createChoiceContainer:zt,createAreaControl:vt,createButtonControl:Ft,classnamesPrefix:we},zr={version:ie};;return{xr,Rr,Je,Xe,vr,Ze,We,ut,L,Qe,$e,J,at,Rn,_r,yr,br,nt,rt,tt,et,mn,gr,zr,wn,Lr,qe,I,q,k,Ke,Ge};}();var{xr:_oxcModd8h2c7_xr,Rr:_oxcModd8h2c7_Rr,Je:_oxcModd8h2c7_Je,Xe:_oxcModd8h2c7_Xe,vr:_oxcModd8h2c7_vr,Ze:_oxcModd8h2c7_Ze,We:_oxcModd8h2c7_We,ut:_oxcModd8h2c7_ut,L:_oxcModd8h2c7_L,Qe:_oxcModd8h2c7_Qe,$e:_oxcModd8h2c7_$e,J:_oxcModd8h2c7_J,at:_oxcModd8h2c7_at,Rn:_oxcModd8h2c7_Rn,_r:_oxcModd8h2c7__r,yr:_oxcModd8h2c7_yr,br:_oxcModd8h2c7_br,nt:_oxcModd8h2c7_nt,rt:_oxcModd8h2c7_rt,tt:_oxcModd8h2c7_tt,et:_oxcModd8h2c7_et,mn:_oxcModd8h2c7_mn,gr:_oxcModd8h2c7_gr,zr:_oxcModd8h2c7_zr,wn:_oxcModd8h2c7_wn,Lr:_oxcModd8h2c7_Lr,qe:_oxcModd8h2c7_qe,I:_oxcModd8h2c7_I,q:_oxcModd8h2c7_q,k:_oxcModd8h2c7_k,Ke:_oxcModd8h2c7_Ke,Ge:_oxcModd8h2c7_Ge}=_oxcModd8h2c7;export{_oxcModd8h2c7_xr as vkVideoIdsToChapterIds,_oxcModd8h2c7_Rr as utils,_oxcModd8h2c7_Je as migrateManifestToLatestVersion,_oxcModd8h2c7_Xe as isValidManifest,_oxcModd8h2c7_vr as isVKVariantItem,_oxcModd8h2c7_Ze as isTextControl,_oxcModd8h2c7_We as isSupportedManifest,_oxcModd8h2c7_ut as isOneTextCtrlContainer,_oxcModd8h2c7_L as isLastChapter,_oxcModd8h2c7_Qe as isButtonControl,_oxcModd8h2c7_$e as isAreaControl,_oxcModd8h2c7_J as interactivesEventTypes,_oxcModd8h2c7_at as hasEndTemplate,_oxcModd8h2c7_Rn as graphEventTypes,_oxcModd8h2c7__r as getVideoRawIdByMedia,_oxcModd8h2c7_yr as getVKVideoIdByMedia,_oxcModd8h2c7_br as getChapterIdByVkVideoId,_oxcModd8h2c7_nt as eventTypes,_oxcModd8h2c7_rt as eventActionTypes,_oxcModd8h2c7_tt as controlTypes,_oxcModd8h2c7_et as containerTypes,_oxcModd8h2c7_mn as compareVersions,_oxcModd8h2c7_gr as chapterIdsToVKVideoIds,_oxcModd8h2c7_zr as SDKInfo,_oxcModd8h2c7_wn as ManifestController,_oxcModd8h2c7_Lr as Interactives,_oxcModd8h2c7_qe as EventTypes,_oxcModd8h2c7_I as EventActionTypes,_oxcModd8h2c7_q as EVENT_NAMES,_oxcModd8h2c7_k as CustomError,_oxcModd8h2c7_Ke as ControlTypes,_oxcModd8h2c7_Ge as ContainerTypes};
285
+ `,Nr=e=>{let t=document.createElement(`style`);t.textContent=Mr,e.prepend(t)};var Fr=Object.freeze({lang:Ht.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,interactiveTimeOpenUri:!1,config:{historyMaxLength:100,noInteractionEventTimeout:3e4},isTouch:!1,disableTextControlContainerVisibilityEvents:!1,animationsFeatureToggles:{areaControlShadow:!1,controlsExpectTimeBlinkAnimation:!1,controlsTapPlace:!1,controlsFillAnimation:!1,controlsHideAnimation:!1},enableAvPlayerSupport:!1});function Ir(){let e=document.createElement(`div`);return e.classList.add(`interactive-chapter`),e}class Lr{constructor(e){if(this.playerSubscriptions=new Gt,this.subscriptions=new Gt,this.globalEventEmitter=new rn,this.animation=new an,this.seekToInteractiveController=new nn,this.endedRanges=new Set,this.gameControllers=[],this.rootElement=Ir(),this.factories=new Map([[`choice`,zt]]),this.isFirstChapterFetched=!1,this._options=void 0,this.manifestController=void 0,this.resizeManager=void 0,this.cssVarsManager=void 0,this.historyController=void 0,this.player=null,this.interactiveEvents=null,this.selectBranches=null,this.seamlessController=null,this.seamlessControllerSubs=new Gt,this.graph=null,this.lastFrame=null,this.noInteractionTimeout=void 0,this.blinkAnimationRef=null,this.appState=0,this.state={prevChapter$:new K(null),isInitialChapter$:new K(!1),isFirstChapter$:new K(!0),isEndChapter$:new K(!1),isInteractiveExpectation$:new K(!1),isReplay$:new K(!1),calledByInteractive$:new K(!1),lastChapterChangeWasInitiatedByInteractive$:new K(!1),disabledControls$:new K(!1),interactiveRanges$:new K([]),isInteractiveTime$:new K(!1),statistics$:new K(null),isSeekable$:new K(!1)},this.events={noInteraction$:new G,graphVisibilityChanged$:new G,watchAgainIsClicked$:new G,chapterChanged$:new G,playerChanged$:new G,error$:new G,eachTick$:new G,manifestChanged$:new G,interactiveRangeEnded$:new G,interactiveContainerRemoved$:new G,interactiveContainerFakeRemoved$:new G,interactiveActionExecution$:new G,interactiveActionChoice$:new G,interactiveVisibilityChanged$:new G},this.emitErrorEvent=e=>{this.events.error$.next(e),this.globalEventEmitter.emit(q.errors,e)},this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&L(n)&&!t&&this.historyController.updateHistory([]),window.removeEventListener(`beforeunload`,this.clearHistoryIfEnded)},this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t}=e,n=T(e,S);if(t){let{statSubscription:e,oneStat:n}=t;e.add(n.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.state.isReplay$.getValue()&&this.state.isReplay$.next(!1),this.events.playerChanged$.next(n),this.globalEventEmitter.emit(q.playerChanged,n)},this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()},this.destroyGameControllers=({removeTextControls:e=!0,withTransition:t=!1}={})=>{for(let n of this.gameControllers)!e&&n.isPermanentText||(this.animation.removeFn(n.whilePlaying),n.destroy(t))},this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,n=t.getValue().map(t=>C(C({},t),{},{subjects:t.subjects.filter(t=>t.id!==e)}));t.next(n)},this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&=(clearTimeout(this.noInteractionTimeout),void 0)},this._options=C(C(C({},Fr),e),{},{config:C(C({},Fr.config),e.config)}),this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation){this.blinkAnimationRef=new gt,this.blinkAnimationRef.create();let e=this.blinkAnimationRef.element;e&&this.rootElement.append(e)}this._options.parentElement.append(this.rootElement),this.historyController=new Or({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new Ar({parentElement:this._options.parentElement,onError:e=>{let t=new k(1,6,e);this.emitErrorEvent(t)}})),Nr(this._options.parentElement),this.subscriptions.add(Kt(this.rootElement,`mousedown`).subscribe(e=>e.stopPropagation())).add(Kt(this.rootElement,`mouseup`).subscribe(e=>e.stopPropagation())),this.manifestController=new wn(this._options.loaders,e=>{let t=new k(1,3,e);this.emitErrorEvent(t)});let t=[];this._options.lastFrame&&t.push(()=>{this.lastFrame?.updateCanvasDimensions(!0)}),t.push(()=>{let e=this.state.isInteractiveTime$.getValue();for(let t of this.gameControllers)t.onResize(e)}),this.cssVarsManager=new sn(this._options?.parentElement),this.resizeManager=nr(()=>({player:this.player,cssVarsManager:this.cssVarsManager,parentElement:this._options.parentElement,fns:t})),this._options.graph&&(this.graph=new $t({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:e=>{this.setChapter({chapterId:e}),this.globalEventEmitter.emit(q.graph,{type:Rn.watchAgainClicked,chapterId:e}),this.events.watchAgainIsClicked$.next(e)},onError:e=>{let t=new k(1,2,{message:e});this.emitErrorEvent(t)}})),this.initSubscriptions()}initSubscriptions(){var e=this;this.playerSubscriptions.add(this.historyController.events.inited$.subscribe(function(){var t=w(function*({videosInfo:t=[]}){e._options.initSeamless&&(yield e.initSeamless(),e.updateGraphVideosInfo(t))});return function(e){return t.apply(this,arguments)}}())),this.subscriptions.add(this.events.interactiveContainerRemoved$.subscribe(({subjectId:e})=>{this.completeInteractiveRange(e)})).add(this.events.interactiveContainerFakeRemoved$.subscribe(({subjectId:e,removeAllOpenURI:t})=>{this.handleFakeRemoval(e,t)})).add(this.events.interactiveActionExecution$.subscribe(e=>{if(this.state.calledByInteractive$.next(!0),(e.actionType===`setNextBranch`||!this._options.endChapterHistoryFix)&&this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour===`change-chapter`){let{chapterId:t}=e.payload;this.setChapter({chapterId:t}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}else if(e.payload?.behaviour===`change-manifest`){let{manifestURL:t}=e.payload;t&&this.setManifest(t)}e.actionType===`expect`?(this.state.isInteractiveExpectation$.next(!0),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!0})):e.actionType===`after-expect`&&(this.state.isInteractiveExpectation$.next(!1),this.updateControlsShadowStyles({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}),this.toggleBlinkAnimation({subjectName:e.subjectName,subjectId:e.subjectId,isExpect:!1}))})).add(this.events.manifestChanged$.subscribe(()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})).add(this.events.interactiveActionChoice$.subscribe(({type:e,subjectName:t,payload:n})=>{e!==`action-choice`||t===`chapter`||`invokeImmediately`in n&&n.invokeImmediately||this.destroyGameControllers({removeTextControls:!1,withTransition:this._options.animationsFeatureToggles?.controlsHideAnimation})}))}initSeamless(){var e=this;return w(function*(){e.seamlessController=Ln(e),e.seamlessControllerSubs.add(e.seamlessController.activePlayerChanged.subscribe(e.handleSeamlessPlayerChanged)),yield e.seamlessController.init()})()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,n=this.getInteractiveRanges().reverse().find(({range:e})=>t>=e[1]);if(n){let e=n.range.join(`-`);this.endedRanges.has(e)||(this.endedRanges.add(e),this.globalEventEmitter.emit(q.interactives,{type:J.rangeEnded,payload:n,visibility:!0}),this.events.interactiveRangeEnded$.next({type:`range-ended`,payload:n}))}}registerVideoEvents(){this.player&&(window.removeEventListener(`beforeunload`,this.clearHistoryIfEnded),this.playerSubscriptions.unsubscribe(),window.addEventListener(`beforeunload`,this.clearHistoryIfEnded),this.playerSubscriptions.add(this.player.events.started$.pipe(Wt()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Vt({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let n=e*1e3;r=!!t.find(({range:[e,t],subjects:r})=>e<n&&n<t&&r.some(e=>!e.isRemoved)&&r.length)}r!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(r);let i=!!this.noInteractionTimeout,a=this.player?.info.playbackState$.getValue()===`playing`||n;r&&!i&&a?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):i&&!a&&this.clearNoInteractionTimeout()})),this.playerSubscriptions.add(this.historyController.events.error$.subscribe(this.events.error$)),this._options.lastFrame&&this.playerSubscriptions.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.getGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(e=>e.container.container).filter(e=>!ut(e.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}getGameControllers(e){let t=[];return e.containers.forEach(n=>{let r=n.type.trim().toLowerCase(),i=this.factories.get(r)?.(n,this.rootElement,this.cssVarsManager,{isTouch:this._options?.isTouch??!1,features:{controlsExpectTimeBlinkAnimation:this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation,controlsTapPlace:this._options.animationsFeatureToggles?.controlsTapPlace,controlsFillAnimation:this._options.animationsFeatureToggles?.controlsFillAnimation}});if(i&&this.selectBranches&&this.interactiveEvents&&this.player){let r=new Hn({player:this.player,container:i,branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter,getContainerEventState:()=>mt(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,interactiveTimeOpenUri:this._options.interactiveTimeOpenUri,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)},onError:this.emitErrorEvent,disableTextControlContainerVisibilityEvents:this.options.disableTextControlContainerVisibilityEvents??!1,features:{controlsHideAnimation:this._options.animationsFeatureToggles?.controlsHideAnimation,enableAvPlayerSupport:this._options.enableAvPlayerSupport}});this.animation.addFn(r.whilePlaying,!0),t.push(r)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let e=this.state.isSeekable$.getValue(),t=!!this.seekToInteractiveController.getNextInteractiveTime();(t&&!e||!t&&e)&&this.state.isSeekable$.next(!e)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(n&&L(n)&&at(n))??!1,i=this.manifestController.manifest?.metadata.initChapterId===e,a=this.historyController.state.history$.getValue();if(i||r&&t){this.historyController.updateHistory([e]);return}a.at(-1)!==e&&this.historyController.updateHistory([...a,e])}handleFakeRemoval(e,t){let{interactiveRanges$:n}=this.state,r=n.getValue().map(n=>{let r=n.subjects.some(t=>t.id===e),i=n.subjects.map(n=>t&&r||n.id===e?C(C({},n),{},{isRemoved:!0}):n);return C(C({},n),{},{subjects:i})});n.next(r)}reset(){this.appState===2&&(this.destroyGameControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this._options.endChapterHistoryFix&&this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1),this.clearNoInteractionTimeout())}toggleBlinkAnimation(e){this._options.animationsFeatureToggles?.controlsExpectTimeBlinkAnimation&&(ft(C(C({},e),{},{gameControllers:this.gameControllers,execFn:Vn(Bn((e,t)=>{e.toggleBlinkAnimation(t)}),e.isExpect)})),e.isExpect)&&this.blinkAnimationRef?.restart()}updateControlsShadowStyles(e){if(!this._options.animationsFeatureToggles?.areaControlShadow)return;let t=(e,t)=>{e.updateControlsShadowStyles(t)};e.isExpect?ft(C(C({},e),{},{gameControllers:this.gameControllers,execFn:Vn(Bn(t),!1)})):ft(C(C({},e),{},{gameControllers:this.gameControllers,execFn:t}))}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}setManifest(e){var t=this;return w(function*(){t.reset(),t.isFirstChapterFetched=!1;let n=yield t.manifestController.setManifest(e);if(n.manifest)return t.graph&&t.graph.handleManifestChange(n.manifest),yield t.historyController.setManifest(n.manifest),t.events.manifestChanged$.next(n.manifest),t.globalEventEmitter.emit(q.manifestChanged,{manifest:n.manifest}),t.setGameControllers(),n.manifest})()}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Xn(this.player,this._options.interactiveTimeOpenUri),this.selectBranches=fr({player:this.player,interactiveEvents:this.interactiveEvents,globalEvents:this.events,globalEventEmitter:this.globalEventEmitter}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}setChapter(){var e=this;return w(function*({chapterId:t,pushToHistory:n=!0,playPrev:r=!1}={}){e.reset(),e.lastFrame&&e.isFirstChapterFetched&&(e.lastFrame.draw(),e.lastFrame.show()),e.lastFrame&&Pr.browser.isSafari&&(yield jr(35));let i=!r&&e.state.isEndChapter$.getValue()&&e.getCurrentManifest()?.metadata.initChapterId===t;e.state.isReplay$.next(i);let{chapter:a,media:o,graph:s}=yield t?e.manifestController.setNext(t):e.manifestController.setInitial();(!t||i)&&e.state.isFirstChapter$.next(!0),!(!a||!o)&&(n&&e.pushChapterToHistory(a.id),e.state.isInitialChapter$.next(e.manifestController.isInitialChapter()),e.state.isEndChapter$.next(e.manifestController.isEndChapter()),e.graph&&e.graph.handleChapterChange(a),e.state.isInteractiveTime$.next(!1),e.state.isInteractiveExpectation$.next(!1),e.lastFrame?.setCurrentChapter(a),e.events.chapterChanged$.next({chapter:a,manifestVideo:o}),e.globalEventEmitter.emit(q.chapterChanged,{chapter:a,media:o,graph:s}),e.setGameControllers(),e.endedRanges=new Set,e.isFirstChapterFetched=!0)}).apply(this,arguments)}getStatEvents(){return{click$:new Ut(e=>{this.subscriptions.add(this.events.graphVisibilityChanged$.subscribe(t=>{e.next(t?qt.GRAPH_SHOW:qt.GRAPH_HIDE)})).add(this.events.watchAgainIsClicked$.subscribe(()=>{e.next(qt.WATCH_AGAIN)})).add(this.events.interactiveActionChoice$.subscribe(({type:t,subjectName:n,subjectType:r})=>{t!==`action-choice`||n!==`control`||(r===`Button`&&e.next(qt.NEXT_BUTTON),r===`Area`&&e.next(qt.NEXT_AREA))}))}),nextMovie$:new Ut(e=>{this.events.playerChanged$.subscribe(({config:t})=>{t?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}toggleGraphView(e=!0){var t=this;return w(function*(){t.graph&&(e?(yield t.graph.show(),t.state.isSeekable$.next(!1)):(t.graph.hide(),t.checkIfSeekable()),t.globalEventEmitter.emit(q.graph,{type:Rn.visibility,visibility:e}),t.events.graphVisibilityChanged$.next(e))})()}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(e=>e.actionType===I.setNextBranch)}allControlsAreRemoved(e=!0){return!this.gameControllers.some(t=>{let n=e&&this._options.animationsFeatureToggles?.controlsHideAnimation?t.container.willRemoved:!0;return!t.container.isRemoved||!n})}isEndedExpectation(){return!this.player||!this.gameControllers?!1:this.player.info.position$.getValue()===this.player.info.duration$.getValue()&&this.gameControllers.some(e=>{let t=e.container.container;return!e.container.isRemoved&&!e.container.willRemoved&&t.endTime===null&&R(t.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&We(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return Un(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){this.clearHistoryIfEnded(),this.blinkAnimationRef?.destroy(),this.destroyGameControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.playerSubscriptions.unsubscribe(),this.subscriptions.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}}var Rr={Container:fe,createChoiceContainer:zt,createAreaControl:vt,createButtonControl:Ft,classnamesPrefix:we},zr={version:ie};;return{xr,Rr,Je,Xe,vr,Ze,We,ut,L,Qe,$e,J,at,Rn,_r,yr,br,nt,rt,tt,et,mn,gr,zr,wn,Lr,qe,I,q,k,Ke,Ge};}();var{xr:_oxcMods3febh_xr,Rr:_oxcMods3febh_Rr,Je:_oxcMods3febh_Je,Xe:_oxcMods3febh_Xe,vr:_oxcMods3febh_vr,Ze:_oxcMods3febh_Ze,We:_oxcMods3febh_We,ut:_oxcMods3febh_ut,L:_oxcMods3febh_L,Qe:_oxcMods3febh_Qe,$e:_oxcMods3febh_$e,J:_oxcMods3febh_J,at:_oxcMods3febh_at,Rn:_oxcMods3febh_Rn,_r:_oxcMods3febh__r,yr:_oxcMods3febh_yr,br:_oxcMods3febh_br,nt:_oxcMods3febh_nt,rt:_oxcMods3febh_rt,tt:_oxcMods3febh_tt,et:_oxcMods3febh_et,mn:_oxcMods3febh_mn,gr:_oxcMods3febh_gr,zr:_oxcMods3febh_zr,wn:_oxcMods3febh_wn,Lr:_oxcMods3febh_Lr,qe:_oxcMods3febh_qe,I:_oxcMods3febh_I,q:_oxcMods3febh_q,k:_oxcMods3febh_k,Ke:_oxcMods3febh_Ke,Ge:_oxcMods3febh_Ge}=_oxcMods3febh;export{_oxcMods3febh_xr as vkVideoIdsToChapterIds,_oxcMods3febh_Rr as utils,_oxcMods3febh_Je as migrateManifestToLatestVersion,_oxcMods3febh_Xe as isValidManifest,_oxcMods3febh_vr as isVKVariantItem,_oxcMods3febh_Ze as isTextControl,_oxcMods3febh_We as isSupportedManifest,_oxcMods3febh_ut as isOneTextCtrlContainer,_oxcMods3febh_L as isLastChapter,_oxcMods3febh_Qe as isButtonControl,_oxcMods3febh_$e as isAreaControl,_oxcMods3febh_J as interactivesEventTypes,_oxcMods3febh_at as hasEndTemplate,_oxcMods3febh_Rn as graphEventTypes,_oxcMods3febh__r as getVideoRawIdByMedia,_oxcMods3febh_yr as getVKVideoIdByMedia,_oxcMods3febh_br as getChapterIdByVkVideoId,_oxcMods3febh_nt as eventTypes,_oxcMods3febh_rt as eventActionTypes,_oxcMods3febh_tt as controlTypes,_oxcMods3febh_et as containerTypes,_oxcMods3febh_mn as compareVersions,_oxcMods3febh_gr as chapterIdsToVKVideoIds,_oxcMods3febh_zr as SDKInfo,_oxcMods3febh_wn as ManifestController,_oxcMods3febh_Lr as Interactives,_oxcMods3febh_qe as EventTypes,_oxcMods3febh_I as EventActionTypes,_oxcMods3febh_q as EVENT_NAMES,_oxcMods3febh_k as CustomError,_oxcMods3febh_Ke as ControlTypes,_oxcMods3febh_Ge as ContainerTypes};