@vkontakte/videoplayer-interactive 1.0.66 → 1.0.67-dev.04f50366b.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.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.66
3
- * Mon, 27 Apr 2026 12:43:05 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-66/doc/
2
+ * @vkontakte/videoplayer-interactive v1.0.67-dev.04f50366b.0
3
+ * Thu, 30 Apr 2026 13:18:35 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-67/doc/
5
5
  */
6
- const e=[`name`],t=[`actions`,`errors`,`chapterId`],n=[`listId`,`itemId`],r=[`timestamp`,`priority`,`initiator`],i=[`statistics`];var a=require(`@oxc-project/runtime/helpers/defineProperty`),o=require(`@oxc-project/runtime/helpers/objectSpread2`),s=require(`@oxc-project/runtime/helpers/asyncToGenerator`),c=require(`@oxc-project/runtime/helpers/objectWithoutProperties`),l=require(`@oxc-project/runtime/helpers/classPrivateFieldInitSpec`),u=require(`@oxc-project/runtime/helpers/classPrivateFieldSet2`),d=require(`@oxc-project/runtime/helpers/classPrivateFieldGet2`),f=Object.defineProperty,p=Object.getOwnPropertyNames,m=Object.getOwnPropertyDescriptor,h=Object.prototype.hasOwnProperty;function g(e){return this[e]}var _=e=>{var t=(v??=new WeakMap).get(e),n;if(t)return t;if(t=f({},`__esModule`,{value:!0}),e&&typeof e==`object`||typeof e==`function`)for(var r of p(e))h.call(t,r)||f(t,r,{get:g.bind(e,r),enumerable:!(n=m(e,r))||n.enumerable});return v.set(e,t),t},v,y=e=>e;function b(e,t){this[e]=y.bind(null,t)}var x=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0,configurable:!0,set:b.bind(t,n)})},ee={};x(ee,{vkVideoIdsToChapterIds:()=>Wn,utils:()=>sr,migrateManifestToLatestVersion:()=>N.migrateManifestToLatestVersion,isValidManifest:()=>Pe,isVKVariantItem:()=>Vn,isTextControl:()=>Fe,isSupportedManifest:()=>N.isSupportedManifest,isOneTextCtrlContainer:()=>Je,isLastChapter:()=>P,isButtonControl:()=>Ie,isAreaControl:()=>Le,interactivesEventTypes:()=>q,hasEndTemplate:()=>Ue,graphEventTypes:()=>un,getVideoRawIdByMedia:()=>Bn,getVKVideoIdByMedia:()=>Hn,getChapterIdByVkVideoId:()=>Un,eventTypes:()=>Be,eventActionTypes:()=>Ve,controlTypes:()=>ze,containerTypes:()=>Re,compareVersions:()=>Ut,chapterIdsToVKVideoIds:()=>zn,SDKInfo:()=>cr,ManifestController:()=>$t,Interactives:()=>or,EventTypes:()=>N.EventTypes,EventActionTypes:()=>N.EventActionTypes,EVENT_NAMES:()=>K,CustomError:()=>w,ControlTypes:()=>N.ControlTypes,ContainerTypes:()=>N.ContainerTypes}),module.exports=_(ee);var S=`1.0.66`,te=require(`@vkontakte/videoplayer-shared`);class ne{constructor(e,t){a(this,`layout`,void 0),a(this,`cssVarsManager`,void 0),this.layout=e,this.cssVarsManager=t}}class re extends ne{constructor(e,t){super(e,t),a(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))`}}var C=require(`@vkontakte/videoplayer-shared`);function ie(e){return`features`in e}class w{constructor(e,t,...n){a(this,`severity`,void 0),a(this,`category`,void 0),a(this,`data`,void 0),this.severity=e,this.category=t,this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null,` `)}`}}function ae({emitter$:e,error:t,subjectId:n,message:r=``,severity:i=1,category:a=1}){let o=new w(i,a,{message:r,error:t,details:{id:n}});e.next(o)}class oe{constructor(e,t,n){a(this,`container`,void 0),a(this,`options`,void 0),a(this,`factories`,void 0),a(this,`controls`,void 0),a(this,`error$`,new C.Subject),a(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&&ie(this.options)&&this.options.features[e])}onError(e=``,t){ae({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 T=require(`@vkontakte/videoplayer-shared`),E=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,D=e=>E(e,`Object`),se=e=>E(e,`String`),ce=e=>E(e,`Array`),le=e=>E(e,`Number`),ue=e=>E(e,`Function`),de=e=>E(e,`Boolean`),fe=e=>le(e)&&!isNaN(e),O=e=>D(e)&&Object.keys(e).length===0,pe=e=>ce(e)&&!e.length,me=(e,t)=>se(e)&&!!(t?e.trim():e).length;function he(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 ge=`interactive`,k={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},_e;(e=>{e.top=`flex-start`,e.bottom=`flex-end`,e.center=`center`})(_e||={});var ve;(e=>{e.start=`flex-start`,e.end=`flex-end`,e.center=`center`})(ve||={});var ye=({target:e,props:t})=>{e.style.alignItems=(t?.gravityVertical&&_e[t.gravityVertical])??`center`,e.style.justifyContent=(t?.gravityHorizontal&&ve[t.gravityHorizontal])??`center`,e.style.textAlign=t?.alignment??`center`},be=({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},xe=({target:e,props:t,fallback:n})=>{var r,i;e.style.backgroundColor=he((t==null||(r=t.background)==null?void 0:r.color)??n.backgroundColor,(t==null||(i=t.background)==null?void 0:i.alpha)??n.backgroundAlpha)},Se=({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=he(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},Ce=({target:e,isDark:t,baseDimension:n,fallback:r})=>{let i=he(r.shadowColorLight,r.shadowColorAlpha),a=he(r.shadowColorDark,r.shadowColorAlpha),o=`0px 0px ${`calc(${n} * 0.25)`} ${`calc(${n} * 0.11)`} ${t?a:i}`;e.style.boxShadow=o},we=({target:e,layoutParams:t,fallback:n})=>{let r=t.angle??n.angle;r&&=r*-1,e.style.transform=`rotate(${r}rad)`},A=require(`@vkontakte/videoplayer-shared`),Te=`interactive-control-tap`,Ee={common:Te,animation:`${Te}-animation`,visible:`${Te}-visible`},De=60;class Oe{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=De,useDimensionsBasedSize:r=!1}){a(this,`element`,void 0),a(this,`controlRotateAngleRad`,void 0),a(this,`clickCancelCondition`,void 0),a(this,`circleDiameterPx`,void 0),a(this,`useDimensionsBasedSize`,void 0),a(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=ke(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(Ee.visible,Ee.animation)}),a(this,`onAnimationEnd`,e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(Ee.visible,Ee.animation)});let i=document.createElement(`div`);i.classList.add(Ee.common),this.controlRotateAngleRad=e,this.element=i,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=r}}function ke(e,t,n){return{x:e*Math.cos(n)-t*Math.sin(n),y:e*Math.sin(n)+t*Math.cos(n)}}function Ae(e){return`features`in e}var j=`interactive-control`,M={common:j,selected:`${j}-selected`,wrapper:`${j}-wrapper`,disabled:`${j}-disabled`,button:`${j}-button`,area:`${j}-area`,text:`${j}-text`,blinkAnim:`${j}-blink-anim`,blinkAnimButton:`${j}-blink-anim-button`,blinkAnimArea:`${j}-blink-anim-area`},je=40,Me=require(`@vkontakte/videoplayer-shared`),N=require(`@interactiveplatform/movika-manifest`),Ne={metadata:`Object`,chapters:`Array`},Pe=e=>{if(!D(e))return!1;for(let t in Ne){let n=e[t];if(!n||!E(n,Ne[t]))return!1}return N.isSupportedManifest(e.metadata.version)};function Fe(e){return e.type===N.ControlTypes.Text}function Ie(e){return e.type===N.ControlTypes.Button}function Le(e){return e.type===N.ControlTypes.Area}var Re={Choice:`Choice`,TextInput:`TextInput`},ze={Button:`Button`,Area:`Area`,Text:`Text`},Be={onClick:`onClick`,onSuspense:`onSuspense`},Ve={openURI:`openURI`,setNextBranch:`setNextBranch`,setWeightlessRandomBranch:`setWeightlessRandomBranch`,setRandomBranch:`setRandomBranch`,setMaxWeightBranch:`setMaxWeightBranch`,setMinWeightBranch:`setMinWeightBranch`,setDefaultBranch:`setDefaultBranch`,continuePlayback:`continuePlayback`,expect:`expect`},He=e=>ce(e)&&!pe(e),P=e=>e.order===`end`,Ue=e=>ce(e.containers)&&!pe(e.containers)&&P(e),We=(e,t)=>{let n=e*1e3;return He(t.controls)&&n<(t.startTime??0)},Ge=(e,t)=>{let n=e*1e3;return He(t.controls)&&n>=(t.startTime??0)&&n<=(t.endTime??1/0)},F=(e=[])=>e.some(e=>e.action.type===`expect`),Ke=(e=[])=>e.find(e=>e.action.type===`expect`),qe=e=>e?.length===1,Je=e=>qe(e)&&Fe(e[0]);function Ye(e=[],t=1/0,n=[]){return e.filter(({container:e})=>!Me.arrayIncludes(n,e.container.id)&&F(e.container.events)&&e.container.endTime===t&&!e.isRemoved&&!e.willRemoved)}function Xe({gameControllers:e=[],subjectName:t,subjectId:n,execFn:r}){for(let i of e)if(t===`container`&&i.container.container.id===n){r(i),Ye(e,i.container.container.endTime,[i.container.container.id]).forEach(e=>{r(e)});break}}function Ze(e){for(let t of e.events)if(t.action.type===`openURI`)return!0;return!1}var Qe=(e,t)=>{let n=F(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===N.EventActionTypes.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=Ye(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 I{constructor(e,t=void 0){a(this,`control`,void 0),a(this,`options`,void 0),a(this,`container`,null),a(this,`controlElement`,null),a(this,`subscriptions`,new A.Subscription),a(this,`error$`,new A.Subject),a(this,`controlTap`,void 0),a(this,`isInteracted`,!1),a(this,`isRemoved`,!1),a(this,`cssVarsManager`,null),a(this,`onControlSelect`,()=>{var e;this.container?.isManifestContainerDisabled()||Ze(this.control)||(e=this.container)==null||(e=e.element)==null||e.classList.add(`interactive-control-wrapper-selected`)}),a(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(A.fromEvent(t,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${I.name} remove view transition error`,e))).add(A.fromEvent(t,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${I.name} remove view transition error`,e)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e=``,t){ae({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){this.featureIsEnabled(`controlsTapPlace`)&&this.container&&(this.controlTap=new Oe({controlRotateAngleRad:this.control.layoutParams.angle??k.angle,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?je:void 0}),this.subscriptions.add(A.fromEvent(e,`click`).subscribe(this.controlTap.onElementClick,e=>this.onError(`Control click tap animation error`,e))).add(A.fromEvent(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(M.wrapper),e.setControlLayout(t,this.control.layoutParams),this.container={element:t,dimensions:(this.control.layoutParams.innerSizesDependOn??k.innerSizesDependOn)===`self`?{height:t.style.height,width:t.style.width}:{height:this.cssVarsManager?.getPropValue(`--interactive-content-height`)??0,width:this.cssVarsManager?.getPropValue(`--interactive-content-width`)??0},isManifestContainerDisabled:()=>e.isContainerDisabled?.call(e)??!1}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&Ae(this.options)&&this.options.features[e])}isTouch(){return!!(this.options&&Ae(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(A.fromEvent(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 $e=`interactive-blink-anim-reference`,L={common:$e,animation:`${$e}-animation`,disabled:`${$e}-disabled`};class et{constructor(){a(this,`_RAFId`,0),a(this,`_element`,void 0)}get element(){return this._element}create(){if(this._element)return;let e=document.createElement(`div`);e.classList.add(L.common,L.animation),this._element=e}restart(){this._element&&(this._element.classList.add(L.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(L.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&=(cancelAnimationFrame(this._RAFId),0)}destroy(){this.cleanupRAF(),this._element=void 0}}var tt=`interactive-container`,R={common:tt,hidden:`${tt}-hidden`,disabled:`${tt}-disabled`},nt=(e,t)=>{if(e.type.trim().toLowerCase()===`area`)return new rt(e,t)};class rt extends I{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(M.common,M.area),n.setAttribute(`data-testid`,`int_area`),xe({target:n,props:this.control.props,fallback:o(o({},k),{},{backgroundColor:`transparent`})}),we({target:n,layoutParams:this.control.layoutParams,fallback:k}),this.addControlTap(n),this.subscriptions.add(T.fromEvent(this.container.element,`click`).pipe(T.once()).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(T.fromEvent(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(R.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${L.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(T.fromEvent(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(R.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(T.fromEvent(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(M.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(M.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(de(e)){var t;let n=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+`px`;Ce({target:this.controlElement,props:this.control.props,fallback:k,isDark:e,baseDimension:n}),Se({target:this.controlElement,props:this.control.props,fallback:o(o({},k),{},{borderColor:e?k.shadowColorDark:k.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)??k.roundCorners})`}),dependsOn:this.container.dimensions,useRawValues:!0})}else Se({target:this.controlElement,props:this.control.props,fallback:o(o({},k),{},{borderAlpha:0}),dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(M.blinkAnim,e),this.controlElement?.classList.toggle(M.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${M.blinkAnimArea}`)||this.controlElement.classList.contains(M.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add(T.fromEvent(e,`animationiteration`).pipe(T.once()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${M.blinkAnimArea}`)||this.controlElement.classList.contains(M.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 z=require(`@vkontakte/videoplayer-shared`),it=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}},at=Math.PI,ot=2*at,st=at/2,ct=3*st,lt=[0,st,at,ct];function ut(e){return e===st}function dt(e){return e===at}function ft(e){return e===ct}function pt(e){return(e%ot+ot)%ot}function mt(e){for(let t of lt)if(e===t)return t}function ht(e){return mt(e)?null:[1,2,3,4][Math.floor(e/st)+1-1]}function gt(e){return e*180/Math.PI}var B=`interactive-control-fill-animation`,V={common:B,fillerWrapper:`${B}-filler-wrapper`,filler:`${B}-filler`,fillHeight:`${B}-fill-height`,fillWidth:`${B}-fill-width`,fromTop:`${B}-from-top`,fromBottom:`${B}-from-bottom`,fromLeft:`${B}-from-left`,fromRight:`${B}-from-right`};class _t{constructor(e){a(this,`fillAnimationElement`,void 0),a(this,`fillAnimationFillerElement`,void 0),a(this,`fillAnimationFillerWrapperElement`,void 0),a(this,`startTime`,void 0),a(this,`endTime`,void 0),a(this,`shouldFillHeight`,void 0),a(this,`widthExpansionCoef`,0),a(this,`isDebug`,void 0),a(this,`fromLeft`,void 0),a(this,`useSkew`,void 0),a(this,`rotateAngle`,void 0);let t=document.createElement(`div`);t.classList.add(V.common);let n=document.createElement(`div`);n.classList.add(V.fillerWrapper);let r=document.createElement(`div`);r.classList.add(V.filler),n.append(r),t.append(n);let i=pt(e.rotateAngle),o=ht(i),s=o!==null,c=o===2||!s&&dt(i)||o===3,l=!s&&ut(i),u=!s&&ft(i),d=!c&&!l&&!u,f=l||u,p=s&&!f,m=p?i:0;t.style.borderRadius=e.borderRadius,n.style.transform=`skew(${m*-1}rad)`,f?(r.classList.add(V.fillHeight,l?V.fromTop:V.fromBottom),n.classList.add(V.fillHeight,l?V.fromTop:V.fromBottom)):(r.classList.add(V.fillWidth,d?V.fromLeft:V.fromRight),n.classList.add(V.fillWidth)),e.debug&&console.log(`[interactive ${_t.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:f,rotateAngleRad:i,rotateAngelDeg:gt(i),rotateAngleRaw:e.rotateAngle,fromRight:c,fromTop:l,fromBottom:u,fromLeft:d}),this.useSkew=p,this.fromLeft=d,this.rotateAngle=i,this.fillAnimationElement=t,this.fillAnimationFillerElement=r,this.fillAnimationFillerWrapperElement=n,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=f,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 vt=(e,t)=>{if(e.type.trim().toLowerCase()===`button`)return new yt(e,t)};class yt extends I{constructor(e,t){super(e,t),a(this,`startTime`,void 0),a(this,`endTime`,void 0),a(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(M.common,M.button),n.setAttribute(`data-testid`,`int_bttn`),we({target:n,layoutParams:this.control.layoutParams,fallback:k}),xe({target:n,props:this.control.props,fallback:k}),Se({target:n,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),ye({target:n,props:o(o({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=it(this.control.type.trim().toLowerCase());be({target:r.firstElementChild??r,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),this.addControlTap(n),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled(`controlsFillAnimation`)&&(this.controlFillAnimation=new _t({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??k.angle,borderRadius:n.style.borderRadius})),this.subscriptions.add(z.fromEvent(n,`click`).pipe(z.once()).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(z.fromEvent(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(R.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${L.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(z.fromEvent(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(R.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(z.fromEvent(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(M.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(M.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(M.blinkAnim,e),this.controlElement?.classList.toggle(M.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${M.blinkAnimButton}`)||this.controlElement.classList.contains(M.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add(z.fromEvent(e,`animationiteration`).pipe(z.once()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${M.blinkAnimButton}`)||this.controlElement.classList.contains(M.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 bt=(e,t)=>{if(e.type.trim().toLowerCase()===`text`)return new xt(e,t)};class xt extends I{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(M.common,M.text),n.setAttribute(`data-testid`,`int_text`),we({target:n,layoutParams:this.control.layoutParams,fallback:k}),ye({target:n,props:o(o({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=it(this.control.type.trim().toLowerCase());be({target:r.firstElementChild??r,props:this.control.props,fallback:k,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 St=(e,t,n,r)=>{if(e.type.trim().toLowerCase()===`choice`)return new Ct(e,t,n,r)};class Ct extends oe{constructor(e,t,n,r){super(e,n,r),a(this,`rootElement`,void 0),a(this,`containerElement`,null),a(this,`layout`,void 0),a(this,`subscriptions`,new te.Subscription),a(this,`isRemoved`,void 0),a(this,`isDisabled`,void 0),a(this,`willRemoved`,void 0),a(this,`cssVarsManager`,void 0),a(this,`onTransitionEnd`,e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()}),this.rootElement=t,this.layout=new re(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory(`button`,vt),this.addControlFactory(`text`,bt),this.addControlFactory(`area`,nt)}createView({eventCallback:e,videoDurationMs:t}){let n=document.createElement(`div`);return n.classList.add(R.common,R.disabled),n.setAttribute(`data-subjectId`,this.container.id),requestAnimationFrame(()=>{n.classList.remove(R.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(R.hidden)}show(){let e=this.getElement();e&&e.classList.remove(R.hidden)}enable(){let e=this.getElement();e&&(e.classList.remove(R.disabled),this.controls.forEach(e=>e.enable()),this.isDisabled=!1)}disable(){let e=this.getElement();e&&(e.classList.add(R.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(te.fromEvent(n,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${Ct.name} remove view transition error`,e))).add(te.fromEvent(n,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${Ct.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))}}var H=require(`@vkontakte/videoplayer-shared`),U=require(`@vkontakte/videoplayer-statistics`),wt=require(`@vkontakte/videoplayer-shared`);function Tt(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}var Et=`video_interactive`,Dt=`videoint`,Ot=250;class kt{constructor(e){a(this,`isHidden`,void 0),a(this,`currentManifestId`,void 0),a(this,`currentChapterId`,void 0),a(this,`visitedChapterIds`,void 0),a(this,`onOpenPreviewClick`,void 0),a(this,`onError`,void 0),a(this,`lang`,void 0),a(this,`zoom`,void 0),a(this,`lastZoomInfo`,void 0),a(this,`isReady`,void 0),a(this,`ngEditor`,void 0),a(this,`ngEditorSize`,void 0),a(this,`graphWrapperElement`,void 0),a(this,`resizeObserver`,void 0),a(this,`manifest`,void 0),a(this,`handleZoomChange`,Tt(e=>{this.lastZoomInfo=e},Ot)),a(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}}),a(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}}),a(this,`handleManifestChange`,(e,t=[])=>{if(this.isReady=!1,!le(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=At(e),this.resizeObserver=new ResizeObserver(Tt(this.onResize,Ot)),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 s(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 t=this;return s(function*(){if(!t.manifest)return;let n;try{n=yield wt.loadVKLangPack(t.lang,Et,Dt)}catch{t.onError?.call(t,`Unable to load graph language pack`)}let{GraphEditor:r}=yield import(`@interactiveplatform/movika-graph-editor`);t.ngEditor=new r(t.graphWrapperElement,{mode:`view`,lang:t.lang===`ru`?`ru`:`en`,translation:n}),t.currentManifestId=t.manifest.metadata.id,t.ngEditor.update(t.manifest),t.ngEditor.setVisitedChapters(Array.from(t.visitedChapterIds)),t.currentChapterId&&t.ngEditor.selectChapter(t.currentChapterId),t.ngEditor.on(`control`,n=>{let{name:r}=n,i=c(n,e);r===`openPreview`&&`chapterId`in i&&t.onOpenPreviewClick?.call(t,i.chapterId)}),t.ngEditor.on(`zoom`,t.handleZoomChange),t.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 At(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 jt=3e3;class Mt{constructor(){a(this,`_containers`,[]),a(this,`_player`,null),a(this,`setPlayer`,e=>{this._player=e}),a(this,`setContainers`,e=>{this._containers=e}),a(this,`deleteContainer`,e=>{this._containers=this._containers.filter(t=>t.id!==e)}),a(this,`getNextInteractiveTime`,(e=jt)=>{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 Nt{constructor(){a(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 Pt{constructor(e){a(this,`raf`,void 0),a(this,`fn`,void 0),a(this,`fns`,[]),a(this,`addFn`,(e,t=!1)=>{ue(e)&&(this.fns.push(e),t&&this.updateFn())}),a(this,`removeFn`,(e,t=!1)=>{this.fns=this.fns.filter(t=>t!==e),t&&this.updateFn()}),a(this,`updateFn`,()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}}),a(this,`forceRequestAnimation`,()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))}),a(this,`requestAnimation`,()=>{this.raf||this.forceRequestAnimation()}),a(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=[]}}var Ft=require(`@vkontakte/videoplayer-shared`);class It{constructor(e){a(this,`rootElement`,void 0),a(this,`isCssVarsSupported`,void 0),a(this,`rootElementProps`,{}),this.rootElement=e,this.isCssVarsSupported=It.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=o(o({},this.rootElementProps),e),this.isCssVarsSupported)for(let[t,n]of Ft.objectEntries(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)}}var Lt=require(`@vkontakte/videoplayer-shared`);class Rt{constructor(e){a(this,`loaders`,void 0),this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}exec(e,t){var n=this;return s(function*(){return zt(...n.loaders[e])(t)})()}}function zt(...e){return function(){var t=s(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 Bt(e,t,n){return e?o(o({},e),{},{[t]:e[t]?[n,...e[t]]:[n]}):{[t]:[n]}}function Vt(e){let{actions:n,errors:r,chapterId:i}=e,a=c(e,t);if(i){let e=n.getManifest();if(e){let t=n.getChapter(e.chapters,i);if(t){let i=n.getMedia(e.media,t.videoId),s=n.getGraph(e.graph,t.id);return i?o(o({},a),{},{actions:n,errors:r,result:{chapter:t,media:i,graph:s}}):o(o({},a),{},{errors:Bt(r,Vt.name,`Could not find media`),actions:n})}}}return o(o({},a),{},{errors:Bt(r,Vt.name,`Could not find chapter`),actions:n})}var Ht=require(`@vkontakte/videoplayer-shared`),Ut=(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},Wt=function(){var e=s(function*(e){try{let t={},n;if(se(e)){n=new URL(e).href;let r=yield Ht.fetchPolyfilled(n);if(!r.ok)return{};t=yield r.json()}else if(D(e))t=e;else return{};if(!Pe(t))return{};let r=t.metadata.media;if(se(r)&&!(`media`in t))try{let e;n?e=new URL(r,n).href:(e=new URL(r).href,n=e);let i=yield Ht.fetchPolyfilled(e);if(!i.ok)throw Error();t.metadata.media=yield i.json()}catch{return Qt(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:n}}catch{return{}}});return function(t){return e.apply(this,arguments)}}();function Gt(e){return Kt.apply(this,arguments)}function Kt(){return Kt=s(function*(e){let{manifest:t,manifestURL:n}=yield Wt(e);if(!t)throw Error(`Failed on fetch`);let r=N.migrateManifestToLatestVersion(t);return r.media=Xt(r.media,n),delete r.metadata.media,r}),Kt.apply(this,arguments)}function qt(e,t){if(t)return e.find(e=>e.id===t)}function Jt(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 Yt(e,t){return e.videos.find(e=>e.id===t)}function Xt(e,t){return o(o({},e),{},{videos:e.videos.map(e=>o(o({},e),{},{variants:e.variants.map(e=>{let n=`url`in e?e.url:``,r=Zt(n,t);return o(o({},e),{},{url:r||n})})}))})}function Zt(e=``,t){try{return new URL(e,t).href}catch{return``}}function Qt(e){return Ut(e,`3.2.0`)>=0}class $t extends Rt{constructor(e,t){super(e),a(this,`manifest`,null),a(this,`chapter`,null),a(this,`media`,null),a(this,`graph`,null),a(this,`prevChapter$`,new Lt.ValueSubject(null)),a(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 s(function*(){t.release();let n=yield t.exec(`manifestLoaders`,{actions:{addErrorMessage:Bt},result:null,errors:null,source:e});return n.errors&&t.errorHandler(n.errors),t.manifest=yield Gt(n.result??e),t})()}setInitial(){var e=this;return s(function*(){return e.setNext()})()}setNext(){var e=this;return s(function*(t=this.manifest?.metadata.initChapterId){if(!t)return e;e.prevChapter$.next(e.chapter);let n=yield e.exec(`chapterLoaders`,Vt({actions:{getManifest:()=>e.manifest,getCurrent:e.getCurrent,getGraph:Jt,getChapter:qt,getMedia:Yt,getByBranches:e.getByBranches.bind(e),addErrorMessage:Bt},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=qt(this.manifest.chapters,e);if(t){let e=Yt(this.manifest.media,t.videoId),n=Jt(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=qt(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?P(this.chapter):!1}}var en=require(`@vkontakte/videoplayer-shared`),tn=require(`@vkontakte/videoplayer-core`),W=require(`@vkontakte/videoplayer-shared`),nn=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[]},rn=require(`@vkontakte/videoplayer-shared`);function an(){let e=new Map;function t(t){let{listId:r=Math.random().toString(),itemId:i=Math.random().toString()}=t,a=c(t,n),s=e.get(r),l=o({},a);return s?s[i]=l:e.set(r,{[i]:l}),o({listId:r,itemId:i},a)}function r(e){e.player.destroy(),e.container.remove(),e.subscription.unsubscribe(),e.statistics?.oneStat.destroy(),e.statistics?.statSubscription.unsubscribe()}function i(t,n){let i=e.get(t);if(!i)throw Error(`Can't remove. Not find.`);if(n){let a=i[n];a&&r(a),delete i[n],Object.keys(i).length||e.delete(t)}else{for(let e of rn.objectValues(i))r(e);e.delete(t)}}function a(){for(let t of e)i(t[0])}return{createPlayer:t,removePlayer:i,map:e,removeAll:a}}var G=require(`@vkontakte/videoplayer-shared`);function on(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||G.arrayIncludes(t,`mp4`))&&(n.MPEG=o(o({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`mpeg`:(i||G.arrayIncludes(t,`mpeg`))&&(n.MPEG=o(o({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`hls`:(i||G.arrayIncludes(t,`hls`))&&(n=o(o({},n),{},{HLS:{type:`url`,url:a.url}}));break;case`dash`:(i||G.arrayIncludes(t,`dash`))&&(n=o(o({},n),{},{DASH_SEP:{compatibilityMode:!0,type:`url`,url:a.url}}));break;default:break}return{sources:n,thumbUrl:r,title:e.title??``}}var sn=(e,t)=>{let n=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();n!==t&&G.arrayIncludes(r,t)&&(e.setQuality(t),e.setAutoQuality(!1))},cn=2;function ln(e){let t=an(),n=new W.Subscription,r={},i=null,a=!1,c,l=new W.ValueSubject(null);e&&u(e);function u(e){i=e}function d(e,n,s){if(!i)throw Error(`need to set interactive controller`);if(!i.options)return;let c=(t.map.get(e)??{})[n];if(c){r=o({chapterId:s,listId:e,itemId:n},c);let u=r.player;r.subscription.add(u.info.currentQuality$.subscribe(e=>{let n=u.info.position$.getValue(),r=u.info.isAutoQualityEnabled$.getValue();if(!(!e||!n||r))for(let n of t.map)en.objectValues(n[1]).forEach(({player:t})=>{sn(t,e)})})).add(u.events.started$.subscribe(()=>{f(n)})),c.container.remove(),i.setPlayer(c.player),a||=(i.init(),!0),l.next({player:r.player,config:r.config,statistics:r.statistics});return}throw Error(`Can't set. Not find.`)}function f(e){return p.apply(this,arguments)}function p(){return p=s(function*(e){if(!i)throw Error(`need to set interactive controller`);if(O(r)||e!==r.itemId)return;let t=i.getChapterBranches(),n=new Set;for(let e of t)n.has(e.media.id)||(yield g({media:e.media,chapterId:e.chapter.id,setAsActive:!1,title:e.chapter.label}),n.add(e.media.id))}),p.apply(this,arguments)}function m(e){return h.apply(this,arguments)}function h(){return h=s(function*({chapter:{id:e},manifestVideo:n}){if(O(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(),l=r.player.info.currentPlaybackRate$.getValue(),u=!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<cn||(f=!0),t.removePlayer(s[0],i)):(f=!0,d(s[0],i,e),u?sn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a),r.player.setPlaybackRate(l))}else t.removePlayer(s[0]);f||(yield g({media:n,chapterId:e,setAsActive:!0,playbackRate:l}),u?sn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a))}),h.apply(this,arguments)}function g(e){return _.apply(this,arguments)}function _(){return _=s(function*({media:e,chapterId:n,prefetch:a=!0,setAsActive:s=!0,autoplay:l=!1,preferredExt:u,title:f,playbackRate:p}){var m,h,g,_;let v=Math.random().toString(),y=document.createElement(`div`);c.append(y);let b;if(!(i==null||(m=i.options)==null)&&m.vkVideoLoader){let t=nn(e);t.length&&(b=yield i.options.vkVideoLoader(...t))}let x=o({},(i==null||(h=i.options)==null?void 0:h.coreConfig)||void 0),ee=o(o({container:y,sources:on(e,u).sources},b==null||(g=b.videos)==null?void 0:g[0]),{},{title:f,failoverHosts:b?.failoverHosts||[]}),S=new tn.Player(x,W.TracerFactory.createRootTracer());S.initVideo(ee);let te=null;if(b?.videos&&i?.options.createOneStat){let e=b.videos[0],t=i.options.createOneStat(e),n=new W.Subscription;t&&(n.add(t.attachTo(S)),te={oneStat:t,statSubscription:n})}let ne=new W.Subscription,re=r==null||(_=r.player)==null?void 0:_.info.isAutoQualityEnabled$.getValue();ne.add(S.events.canplay$.subscribe(function(){re||sn(S,r.player.info.currentQuality$.getValue()),p&&S.setPlaybackRate(p)}));let C=t.createPlayer({listId:e.id,itemId:v,player:S,container:y,sources:on(e,u).sources,config:ee,subscription:ne,statistics:te});return s&&d(e.id,C.itemId,n),l&&C.player.play(),a&&!l&&C.player.prepare(),{player:C.player,config:C.config,statistics:C.statistics}}),_.apply(this,arguments)}function v(){y(),i=null,c.remove()}function y(){n.unsubscribe(),t.removeAll(),r={},a=!1}function b(){return x.apply(this,arguments)}function x(){return x=s(function*(){if(!i)throw Error(`need to set interactive controller`);y(),c=document.createElement(`div`);let{media:e,chapter:t}=i.getCurrentChapter();e&&t?(n.add(i.events.chapterChanged$.subscribe(m)),yield g({media:e,chapterId:t.id,title:t.label})):console.error(`not found`)}),x.apply(this,arguments)}return{map:t.map,removePlayer:t.removePlayer,init:b,setInteractiveController:u,createPlayer:g,removeAll:v,getActivePlayer:function(){return r},activePlayerChanged:l}}var K={graph:`graph`,interactives:`interactives`,chapterChanged:`chapter-changed`,playerChanged:`player-changed`,manifestChanged:`manifest-changed`,errors:`errors`,eachTick:`eachTick`,historyInited:`history-inited`,historyDestroyed:`history-destroyed`},un={visibility:`visibility`,watchAgainClicked:`watchAgainClicked`},q={actionChoiceCanceled:`action-choice-canceled`,actionChoice:`action-choice`,actionExecution:`action-execution`,visibility:`visibility`,containerRemoved:`container-removed`,rangeEnded:`range-ended`},dn=require(`@vkontakte/videoplayer-shared`);function fn(e){return function(...t){return e(...t.reverse())}}function pn(e,...t){return(...n)=>D(t[0])&&D(n[0])?e(o(o({},t[0]),n[0])):e(...t,...n)}class mn{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:i,globalEvents:o,globalEventEmitter:s,getContainerEventState:c,permanentTextControls:l,interactiveTimeOpenUri:u,disabledControls$:d,onRemove:f,onError:p,disableTextControlContainerVisibilityEvents:m=!1,features:h}){a(this,`container`,void 0),a(this,`branches`,void 0),a(this,`selectBranches`,void 0),a(this,`subscription`,void 0),a(this,`player`,void 0),a(this,`interactiveEvents`,void 0),a(this,`getContainerEventState`,void 0),a(this,`isPermanentText`,void 0),a(this,`interactiveTimeOpenUri`,void 0),a(this,`disabledControls$`,void 0),a(this,`onRemove`,void 0),a(this,`globalEventEmitter`,void 0),a(this,`gameState`,void 0),a(this,`isSelectedControlEvent`,void 0),a(this,`isSelectedContainerEvent`,void 0),a(this,`globalEvents`,void 0),a(this,`onError`,void 0),a(this,`disableTextControlContainerVisibilityEvents`,void 0),a(this,`features`,void 0),a(this,`hide`,()=>{setTimeout(()=>{if(this.gameState!==4&&!(F(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)}})}),a(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=pn(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)}}}),a(this,`onEndOfVideo`,()=>{this.gameState=4,this.selectContainerEvent(!0)}),a(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(We(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Ge(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=Ge(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(K.eachTick,o),this.globalEvents.eachTick$.next(o)}),this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new dn.Subscription,this.player=e,this.interactiveEvents=i,this.getContainerEventState=c;let g=Je(t.container.controls);this.isPermanentText=l&&g,this.disableTextControlContainerVisibilityEvents=m&&g,this.interactiveTimeOpenUri=u,this.disabledControls$=d,this.onRemove=f,this.globalEventEmitter=s,this.gameState=0,this.globalEvents=o,this.onError=p,this.features=h,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(K.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:q.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(K.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:q.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:F(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(K.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:q.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 hn=(e=[])=>e.reduce((e,t,n)=>{if(He((t?.controls??[]).filter(e=>!Fe(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]),gn=require(`@vkontakte/videoplayer-shared`),_n=require(`@vkontakte/videoplayer-shared`),vn=require(`@vkontakte/videoplayer-shared`);function yn(){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 i(t){let n={};for(let r in e)+r>=t&&(n[r]=e[r]);return n}function a({timestamp:t,priority:n,initiator:r}){if(fe(t)){let i=e[t]??null;if(i&&n&&me(n,!0)){let e={},t=i[n];return t&&(e=o(o({},e),t)),e=O(e)?null:e,e&&me(r,!0)?e[r]??null:e}return i}return null}function s({timestamp:t,priority:n,initiator:r}){if(fe(t))if(e[t]){if(n&&me(n,!0))if(e[t][n]){if(r&&me(r,!0))if(e[t][n][r]){if(delete e[t][n][r],!O(e[t][n]))return!0}else return!1;if(delete e[t][n],!O(e[t]))return!0}else return!1;return delete e[t]}else return!1;return!1}function l(t){var n;let{timestamp:i,priority:a,initiator:s}=t,l=c(t,r);!((n=e[i])==null||(n=n[a])==null)&&n[s]?e[i][a][s].push(o({},l)):e[i]?.[a]?e[i][a]=o(o({},e[i][a]),{},{[s]:[o({},l)]}):e[i]?e[i]=o(o({},e[i]),{},{[a]:{[s]:[o({},l)]}}):e[i]={[a]:{[s]:[o({},l)]}}}return{map:e,remove:s,add:l,removeAll:t,get:a,getLte:n,getGte:i}}var bn=[N.EventActionTypes.expect,N.EventActionTypes.setNextBranch],xn=1/0;function Sn(e,t){let n=e,r,i=Cn(t),a=yn(),o,s=()=>{p(),_()},c=e=>{a.add.call(void 0,e),m()},l=(e=[])=>{for(let t of e)if(t.action(),gn.arrayIncludes(bn,t.actionType))break},u=(e=1/0)=>{let t=wn(a.get({timestamp:e,priority:`control`})??{}),n=wn(a.get({timestamp:e,priority:`container`})??{}),r=wn(a.get({timestamp:e,priority:`chapter`})??{});return[...t,...n,...r]},d=e=>{i.isReady(e)&&l(u(e))},f=()=>{l([...wn(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 Cn(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??xn,r=t.get(e);t.set(e,o(o({},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=_n.objectValues(r);return e?i.some(e=>e):!i.some(e=>!e)},release:()=>t.clear()}}function wn(e){return vn.arrayFlat(_n.objectValues(e)).sort(e=>e.actionType===N.EventActionTypes.expect?-1:1)}var Tn={videoContentHeight:0,videoContentWidth:0},En=e=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return Tn;let{clientHeight:r,clientWidth:i}=e.experimental.element$.getValue()||{};if(!(r&&i))return Tn;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}},Dn=250;function On(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}=En(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=Tt(t=>{let{fns:n=[]}=e();r(t);for(let e of n)e()},Dn);function o(){t=void 0,n.disconnect(),i()}return{resizeObserver:n,calc:()=>{t?.()},release:o}}var kn=e=>Math.floor(Math.random()*e),An=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},jn=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},Mn=e=>{let t=e.length;return e[kn(t)]},Nn=1,Pn=e=>{let t=0;for(let n=0;n<e.length;++n)t+=e[n].weight??Nn;let n=Math.random()*t;t=0;for(let r=0;r<e.length-1;++r)if(t+=e[r].weight??Nn,t>=n)return e[r];return e[e.length-1]},Fn={shouldOpenNow:!0,isDetachContainer:!0},In=`after-expect`,Ln=(e,t=!1)=>o(o({},e),{},{args:t?o(o({},e.args),Fn):o(o({},Fn),e.args)}),Rn=({globalEventEmitter:e,globalEvents:t,player:n,interactiveEvents:r})=>{let i={isExpect:!1},a=()=>{i.isExpect&&=!1},s=({action:n,controlType:i,controlId:a,containerId:s,branches:c=[],onEvent:l,isEOV:u=()=>!1,isDisabled:f=()=>!1})=>{let p=Ln(n,u()),v={timestamp:1/0,priority:`control`,initiator:a,actionType:p.type},y=f(),b=e.emit.bind(e,K.interactives,{subjectId:a,subjectType:i,subjectName:`control`,type:y?q.actionChoiceCanceled:q.actionChoice,actionType:n.type,payload:o({invokeImmediately:p.args.shouldOpenNow,containerId:s},p.args)}),x=()=>{t.interactiveActionChoice$.next({subjectId:a,subjectType:i,subjectName:`control`,type:y?`action-choice-canceled`:`action-choice`,actionType:n.type,payload:o({invokeImmediately:p.args.shouldOpenNow,containerId:s},p.args)})};if(y){b(),x();return}switch(p.type.trim().toLowerCase()){case N.EventActionTypes.setNextBranch.trim().toLowerCase():{let e=c.find(e=>e.id===p.args.branchId);if(!e)return;l(p.args.isDetachContainer,m.bind(null,{subjectId:a,subjectName:`control`})),b(),x(),p.args.shouldOpenNow?g({subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{chapterId:e.chapterId,autoSelect:!1}}):r.add(o(o({},v),{},{action:g.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{chapterId:e.chapterId,autoSelect:!1}})}));return}case N.EventActionTypes.continuePlayback.trim().toLowerCase():l(p.args.isDetachContainer,m.bind(null,{subjectId:a,subjectName:`control`})),b(),x(),p.args.shouldOpenNow?h({subjectId:a,subjectName:`control`,subjectType:i,action:n}):r.add(o(o({},v),{},{action:h.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:n})}));return;case N.EventActionTypes.openURI.trim().toLowerCase():l(p.args.isDetachContainer,m.bind(null,{subjectId:a,subjectName:`control`})),b(),x(),p.args.shouldOpenNow?_({subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{URI:n.args.uri}}):r.add(o(o({},v),{},{action:_.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{URI:n.args.uri}})}));return;default:{let e=`Unexpected control event`;d(new w(1,1,{message:e}),e);return}}},c=({action:n,container:{id:i,endTime:a},branches:s=[],isEOV:c=!1,autoSelected:l=!1})=>{let u=Ln(n,c),f={timestamp:!u.args.shouldOpenNow||c?1/0:a??1/0,priority:`container`,initiator:i,actionType:u.type},p=e.emit.bind(e,K.interactives,{subjectId:i,subjectName:`container`,type:q.actionChoice,actionType:u.type,payload:o({invokeImmediately:u.args.shouldOpenNow},u.args)}),m=()=>{t.interactiveActionChoice$.next({subjectId:i,subjectName:`container`,type:`action-choice`,actionType:u.type,payload:o({invokeImmediately:u.args.shouldOpenNow},u.args)})};switch(u.type.trim().toLowerCase()){case N.EventActionTypes.setNextBranch.trim().toLowerCase():{let e=s.find(e=>e.id===u.args.branchId);if(!e)return;p(),m(),r.add(o(o({},f),{},{action:g.bind(null,{subjectId:i,subjectName:`container`,action:u,payload:{chapterId:e.chapterId,autoSelect:l}})}));return}case N.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():return;case N.EventActionTypes.setMinWeightBranch.trim().toLowerCase():return;case N.EventActionTypes.setRandomBranch.trim().toLowerCase():return;case N.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():return;case N.EventActionTypes.continuePlayback.trim().toLowerCase():p(),m(),r.add(o(o({},f),{},{action:h.bind(null,{subjectId:i,subjectName:`container`,action:u})}));return;case N.EventActionTypes.openURI.trim().toLowerCase():p(),m(),r.add(o(o({},f),{},{action:_.bind(null,{subjectId:i,subjectName:`container`,action:u,payload:{URI:n.args.uri}})}));return;default:{let e=`Unexpected container event`;d(new w(1,1,{message:e}),e);return}}};function l({container:n,branches:a,isEOV:s=!1}){let l=Ke(n.events);if(l){let a=Ln(l.action,s);e.emit(K.interactives,{subjectId:n.id,subjectName:`container`,type:q.actionChoice,actionType:a.type,payload:o({invokeImmediately:a.args.shouldOpenNow},a.args)}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`container`,type:`action-choice`,actionType:a.type,payload:o({invokeImmediately:a.args.shouldOpenNow},a.args)}),r.add({timestamp:s?1/0:n.endTime??1/0,priority:`container`,initiator:n.id,actionType:N.EventActionTypes.expect,action:p.bind(null,{subjectId:n.id,subjectName:`container`})}),i.isExpect=!0}else for(let e of n.events??[])c({action:e.action,container:n,branches:a,isEOV:s})}let u=({chapterId:n,action:r,branches:i=[]})=>{let a=e.emit.bind(e,K.interactives,{subjectId:n,subjectName:`chapter`,type:q.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 N.EventActionTypes.setNextBranch.trim().toLowerCase():{let e=i.find(e=>e.id===r.args.branchId);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():{let e=Mn(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setRandomBranch.trim().toLowerCase():{let e=Pn(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():{let e=jn(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setMinWeightBranch.trim().toLowerCase():{let e=An(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.continuePlayback.trim().toLowerCase():return a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r});case N.EventActionTypes.openURI.trim().toLowerCase():return a(),o(),_.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{URI:r.args.uri}});default:{let e=`Unexpected chapter event`;d(new w(1,1,{message:e}),e);return}}};function d(n,r){console.error(r),t.error$.next(n),e.emit(K.errors,n)}function f(n){let i=Ke(n.events);if(i){if(P(n))return;e.emit(K.interactives,{subjectId:n.id,subjectName:`chapter`,type:q.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:N.EventActionTypes.expect,action:p.bind(null,{subjectId:n.id,subjectName:`chapter`})})}else n.events?.forEach(e=>{let t=u({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 p=({subjectId:r,subjectName:i})=>{n.pause(),e.emit(K.interactives,{subjectId:r,subjectName:i,type:q.actionExecution,actionType:N.EventActionTypes.expect}),t.interactiveActionExecution$.next({subjectId:r,subjectName:i,type:`action-execution`,actionType:N.EventActionTypes.expect})},m=({subjectId:i,subjectName:a})=>{n.info.isEnded$.getValue()?r.execEndOfVideo():n.play(),e.emit(K.interactives,{subjectId:i,subjectName:a,type:q.actionExecution,actionType:In}),t.interactiveActionExecution$.next({subjectId:i,subjectName:a,type:`action-execution`,actionType:In})},h=({subjectId:n,subjectName:r,subjectType:i,action:a})=>{e.emit(K.interactives,{subjectId:n,subjectName:r,subjectType:i,type:q.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})},g=({subjectId:n,subjectName:r,subjectType:i,action:a,payload:o})=>{o.behaviour=`change-chapter`,e.emit(K.interactives,{subjectId:n,subjectName:r,subjectType:i,type:q.actionExecution,actionType:a.type,payload:o}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type,payload:o})},_=({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(K.interactives,{subjectId:n,subjectName:r,subjectType:i,type:q.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})};return{onControlEvent:s,onContainerEvent:c,onChapterEvent:u,onExpectEvent:p,expectEventHandler:m,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:a,state:i}},J=require(`@vkontakte/videoplayer-shared`),zn=(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]=Hn(i)}return n[e]}).filter(e=>e!==null)},Bn=e=>{for(let t of e.variants)if(Vn(t)&&t.payload)return t.payload.id},Vn=e=>!!(e.type===`custom`&&e.payload&&e.payload.type===`vk`),Hn=e=>{let t=Bn(e);if(!t)return null;let n=t.split(`_`).pop();return n?parseInt(n,10):null},Un=(e,t)=>{for(let n of e.media.videos)if(t===Hn(n)){for(let t of e.chapters)if(t.videoId===n.id)return t.id;return}},Wn=(e,t)=>e.reduce((e,n)=>{let r=Un(t,n);return r?[...e,r]:e},[]),Y=new WeakMap,Gn=new WeakMap,Kn=new WeakMap,X=new WeakMap,qn=new WeakMap,Z=new WeakMap,Q=new WeakMap,$=new WeakMap,Jn=new WeakMap,Yn=new WeakMap,Xn=new WeakMap;class Zn{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:i}){a(this,`state`,{history$:new J.ValueSubject([]),hasPrevChapter$:new J.ValueSubject(!1),prevChapter$:new J.ValueSubject(null),isInitialChapter$:new J.ValueSubject(!1),isGoBackLimited$:new J.ValueSubject(!1)}),l(this,Y,null),l(this,Gn,void 0),l(this,Kn,!1),l(this,X,null),l(this,qn,null),a(this,`events`,{inited$:new J.Subject,destroyed$:new J.Subject,error$:new J.Subject}),l(this,Z,null),l(this,Q,null),l(this,$,null),l(this,Jn,new J.Subscription),l(this,Yn,!1),l(this,Xn,0),u(Z,this,t),u($,this,e),u(Q,this,n),u(Y,this,r),u(Gn,this,i),this.state.history$&&d(Jn,this)&&d(Jn,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=d(X,this))==null||(t=t.metadata)==null?void 0:t.initChapterId)),this.state.isGoBackLimited$.next(d(Xn,this)===d(Gn,this).maxLength-1)}))}setManifest(e){var t=this;return s(function*(){if(!d(Q,t)||!d($,t))return;u(X,t,e),yield t.getProjectHistory();let n=t.getInitialChapterId();yield d(Q,t).setChapter({chapterId:n,pushToHistory:!1}),d(Kn,t)||(u(Kn,t,!0),t.events.inited$.next({initChapterId:n}))})()}get inited(){return d(Kn,this)}updateHistory(e,t=!0){var n=this;return s(function*(){if(!d(X,n))return;if(d(Yn,n)){var r;u(Yn,n,!1),u(Xn,n,(r=d(Xn,n),r++,r))}else u(Xn,n,0);let i=d(X,n),a=e.length-d(Gn,n).maxLength,o=a>0?e.slice(a):e,s=zn(o,i);if(u(qn,n,s),n.state.history$.next(o),!(!t||!d(Y,n)||!d(Z,n)))try{yield d(Y,n).save(d(Z,n),s)}catch{let e=new w(1,5,`Unable to save interactive history`);n.events.error$.next(e),d($,n)?.emit(K.errors,e)}})()}goBack(){var e=this;return s(function*(){if(!e.state||!d(Q,e)){let t=new w(1,5,`Unable to save interactive history`);e.events.error$.next(t),d($,e)?.emit(K.errors,t);return}u(Yn,e,!0);let t=e.state.history$.getValue().slice(0,-1),n=t.pop();e.state.history$.next(t),yield d(Q,e).setChapter({chapterId:n,playPrev:!0})})()}getProjectHistory(){var e=this;return s(function*(){if(!d(X,e)||!d(Z,e))return;let t=d(X,e),n=[e.getInitialVideoId()];if(d(Y,e))try{let t=yield d(Y,e).get(d(Z,e));t.length&&(n=t)}catch{let t=new w(1,5,`Error while trying to fetch data`);e.events.error$.next(t),d($,e)?.emit(K.errors,t)}let r=Wn(n,t);e.state.history$.next(r)})()}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||d(Gn,this).initChapterId||d(X,this)?.metadata.initChapterId}getInitialVideoId(){return d(X,this)?zn([this.getInitialChapterId()],d(X,this)).pop():null}destroy(){u(Z,this,null),u(Y,this,null),u(Q,this,null),d(Jn,this)?.unsubscribe(),u(Jn,this,null),u(Kn,this,!1),d($,this)?.emit(K.historyDestroyed),this.events.destroyed$.next(),u($,this,null)}}class Qn{constructor(){a(this,`rootElement`,void 0),a(this,`canvasImgSrc`,void 0),a(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 s(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 s(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 $n{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){a(this,`lastFrameCanvas`,void 0),a(this,`endOffsetMs`,void 0),a(this,`currentChapter`,void 0),a(this,`currentVideoDurationMs`,1/0),a(this,`rootElement`,void 0),a(this,`_containerTimeFrameShouldReceived`,!1),a(this,`_endTimeFrameReceived`,!1),a(this,`_shouldCallSkip`,!1),a(this,`_callbacks`,void 0),a(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()}}),a(this,`onSeek`,()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())}),this.rootElement=document.createElement(`div`),this.rootElement.style.cssText=`
6
+ const e=[`name`],t=[`actions`,`errors`,`chapterId`],n=[`listId`,`itemId`],r=[`timestamp`,`priority`,`initiator`],i=[`statistics`];var a=require(`@oxc-project/runtime/helpers/defineProperty`),o=require(`@oxc-project/runtime/helpers/objectSpread2`),s=require(`@oxc-project/runtime/helpers/asyncToGenerator`),c=require(`@oxc-project/runtime/helpers/objectWithoutProperties`),l=require(`@oxc-project/runtime/helpers/classPrivateFieldInitSpec`),u=require(`@oxc-project/runtime/helpers/classPrivateFieldSet2`),d=require(`@oxc-project/runtime/helpers/classPrivateFieldGet2`),f=Object.defineProperty,p=Object.getOwnPropertyNames,m=Object.getOwnPropertyDescriptor,h=Object.prototype.hasOwnProperty;function g(e){return this[e]}var _=e=>{var t=(v??=new WeakMap).get(e),n;if(t)return t;if(t=f({},`__esModule`,{value:!0}),e&&typeof e==`object`||typeof e==`function`)for(var r of p(e))h.call(t,r)||f(t,r,{get:g.bind(e,r),enumerable:!(n=m(e,r))||n.enumerable});return v.set(e,t),t},v,y=e=>e;function b(e,t){this[e]=y.bind(null,t)}var x=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0,configurable:!0,set:b.bind(t,n)})},ee={};x(ee,{vkVideoIdsToChapterIds:()=>Wn,utils:()=>sr,migrateManifestToLatestVersion:()=>N.migrateManifestToLatestVersion,isValidManifest:()=>Pe,isVKVariantItem:()=>Vn,isTextControl:()=>Fe,isSupportedManifest:()=>N.isSupportedManifest,isOneTextCtrlContainer:()=>Je,isLastChapter:()=>P,isButtonControl:()=>Ie,isAreaControl:()=>Le,interactivesEventTypes:()=>q,hasEndTemplate:()=>Ue,graphEventTypes:()=>un,getVideoRawIdByMedia:()=>Bn,getVKVideoIdByMedia:()=>Hn,getChapterIdByVkVideoId:()=>Un,eventTypes:()=>Be,eventActionTypes:()=>Ve,controlTypes:()=>ze,containerTypes:()=>Re,compareVersions:()=>Ut,chapterIdsToVKVideoIds:()=>zn,SDKInfo:()=>cr,ManifestController:()=>$t,Interactives:()=>or,EventTypes:()=>N.EventTypes,EventActionTypes:()=>N.EventActionTypes,EVENT_NAMES:()=>K,CustomError:()=>w,ControlTypes:()=>N.ControlTypes,ContainerTypes:()=>N.ContainerTypes}),module.exports=_(ee);var S=`1.0.67-dev.04f50366b.0`,te=require(`@vkontakte/videoplayer-shared`);class ne{constructor(e,t){a(this,`layout`,void 0),a(this,`cssVarsManager`,void 0),this.layout=e,this.cssVarsManager=t}}class re extends ne{constructor(e,t){super(e,t),a(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))`}}var C=require(`@vkontakte/videoplayer-shared`);function ie(e){return`features`in e}class w{constructor(e,t,...n){a(this,`severity`,void 0),a(this,`category`,void 0),a(this,`data`,void 0),this.severity=e,this.category=t,this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null,` `)}`}}function ae({emitter$:e,error:t,subjectId:n,message:r=``,severity:i=1,category:a=1}){let o=new w(i,a,{message:r,error:t,details:{id:n}});e.next(o)}class oe{constructor(e,t,n){a(this,`container`,void 0),a(this,`options`,void 0),a(this,`factories`,void 0),a(this,`controls`,void 0),a(this,`error$`,new C.Subject),a(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&&ie(this.options)&&this.options.features[e])}onError(e=``,t){ae({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 T=require(`@vkontakte/videoplayer-shared`),E=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,D=e=>E(e,`Object`),se=e=>E(e,`String`),ce=e=>E(e,`Array`),le=e=>E(e,`Number`),ue=e=>E(e,`Function`),de=e=>E(e,`Boolean`),fe=e=>le(e)&&!isNaN(e),O=e=>D(e)&&Object.keys(e).length===0,pe=e=>ce(e)&&!e.length,me=(e,t)=>se(e)&&!!(t?e.trim():e).length;function he(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 ge=`interactive`,k={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},_e;(e=>{e.top=`flex-start`,e.bottom=`flex-end`,e.center=`center`})(_e||={});var ve;(e=>{e.start=`flex-start`,e.end=`flex-end`,e.center=`center`})(ve||={});var ye=({target:e,props:t})=>{e.style.alignItems=(t?.gravityVertical&&_e[t.gravityVertical])??`center`,e.style.justifyContent=(t?.gravityHorizontal&&ve[t.gravityHorizontal])??`center`,e.style.textAlign=t?.alignment??`center`},be=({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},xe=({target:e,props:t,fallback:n})=>{var r,i;e.style.backgroundColor=he((t==null||(r=t.background)==null?void 0:r.color)??n.backgroundColor,(t==null||(i=t.background)==null?void 0:i.alpha)??n.backgroundAlpha)},Se=({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=he(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},Ce=({target:e,isDark:t,baseDimension:n,fallback:r})=>{let i=he(r.shadowColorLight,r.shadowColorAlpha),a=he(r.shadowColorDark,r.shadowColorAlpha),o=`0px 0px ${`calc(${n} * 0.25)`} ${`calc(${n} * 0.11)`} ${t?a:i}`;e.style.boxShadow=o},we=({target:e,layoutParams:t,fallback:n})=>{let r=t.angle??n.angle;r&&=r*-1,e.style.transform=`rotate(${r}rad)`},A=require(`@vkontakte/videoplayer-shared`),Te=`interactive-control-tap`,Ee={common:Te,animation:`${Te}-animation`,visible:`${Te}-visible`},De=60;class Oe{constructor({controlRotateAngleRad:e,clickCancelCondition:t,circleDiameterPx:n=De,useDimensionsBasedSize:r=!1}){a(this,`element`,void 0),a(this,`controlRotateAngleRad`,void 0),a(this,`clickCancelCondition`,void 0),a(this,`circleDiameterPx`,void 0),a(this,`useDimensionsBasedSize`,void 0),a(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=ke(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(Ee.visible,Ee.animation)}),a(this,`onAnimationEnd`,e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.element.classList.remove(Ee.visible,Ee.animation)});let i=document.createElement(`div`);i.classList.add(Ee.common),this.controlRotateAngleRad=e,this.element=i,this.clickCancelCondition=t,this.circleDiameterPx=n,this.useDimensionsBasedSize=r}}function ke(e,t,n){return{x:e*Math.cos(n)-t*Math.sin(n),y:e*Math.sin(n)+t*Math.cos(n)}}function Ae(e){return`features`in e}var j=`interactive-control`,M={common:j,selected:`${j}-selected`,wrapper:`${j}-wrapper`,disabled:`${j}-disabled`,button:`${j}-button`,area:`${j}-area`,text:`${j}-text`,blinkAnim:`${j}-blink-anim`,blinkAnimButton:`${j}-blink-anim-button`,blinkAnimArea:`${j}-blink-anim-area`},je=40,Me=require(`@vkontakte/videoplayer-shared`),N=require(`@interactiveplatform/movika-manifest`),Ne={metadata:`Object`,chapters:`Array`},Pe=e=>{if(!D(e))return!1;for(let t in Ne){let n=e[t];if(!n||!E(n,Ne[t]))return!1}return N.isSupportedManifest(e.metadata.version)};function Fe(e){return e.type===N.ControlTypes.Text}function Ie(e){return e.type===N.ControlTypes.Button}function Le(e){return e.type===N.ControlTypes.Area}var Re={Choice:`Choice`,TextInput:`TextInput`},ze={Button:`Button`,Area:`Area`,Text:`Text`},Be={onClick:`onClick`,onSuspense:`onSuspense`},Ve={openURI:`openURI`,setNextBranch:`setNextBranch`,setWeightlessRandomBranch:`setWeightlessRandomBranch`,setRandomBranch:`setRandomBranch`,setMaxWeightBranch:`setMaxWeightBranch`,setMinWeightBranch:`setMinWeightBranch`,setDefaultBranch:`setDefaultBranch`,continuePlayback:`continuePlayback`,expect:`expect`},He=e=>ce(e)&&!pe(e),P=e=>e.order===`end`,Ue=e=>ce(e.containers)&&!pe(e.containers)&&P(e),We=(e,t)=>{let n=e*1e3;return He(t.controls)&&n<(t.startTime??0)},Ge=(e,t)=>{let n=e*1e3;return He(t.controls)&&n>=(t.startTime??0)&&n<=(t.endTime??1/0)},F=(e=[])=>e.some(e=>e.action.type===`expect`),Ke=(e=[])=>e.find(e=>e.action.type===`expect`),qe=e=>e?.length===1,Je=e=>qe(e)&&Fe(e[0]);function Ye(e=[],t=1/0,n=[]){return e.filter(({container:e})=>!Me.arrayIncludes(n,e.container.id)&&F(e.container.events)&&e.container.endTime===t&&!e.isRemoved&&!e.willRemoved)}function Xe({gameControllers:e=[],subjectName:t,subjectId:n,execFn:r}){for(let i of e)if(t===`container`&&i.container.container.id===n){r(i),Ye(e,i.container.container.endTime,[i.container.container.id]).forEach(e=>{r(e)});break}}function Ze(e){for(let t of e.events)if(t.action.type===`openURI`)return!0;return!1}var Qe=(e,t)=>{let n=F(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===N.EventActionTypes.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=Ye(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 I{constructor(e,t=void 0){a(this,`control`,void 0),a(this,`options`,void 0),a(this,`container`,null),a(this,`controlElement`,null),a(this,`subscriptions`,new A.Subscription),a(this,`error$`,new A.Subject),a(this,`controlTap`,void 0),a(this,`isInteracted`,!1),a(this,`isRemoved`,!1),a(this,`cssVarsManager`,null),a(this,`onControlSelect`,()=>{var e;this.container?.isManifestContainerDisabled()||Ze(this.control)||(e=this.container)==null||(e=e.element)==null||e.classList.add(`interactive-control-wrapper-selected`)}),a(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(A.fromEvent(t,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${I.name} remove view transition error`,e))).add(A.fromEvent(t,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${I.name} remove view transition error`,e)));return}this.removeListeners(),t.remove(),this.isRemoved=!0}}onError(e=``,t){ae({emitter$:this.error$,error:t,message:e,subjectId:this.control.id})}addControlTap(e){this.featureIsEnabled(`controlsTapPlace`)&&this.container&&(this.controlTap=new Oe({controlRotateAngleRad:this.control.layoutParams.angle??k.angle,clickCancelCondition:this.container.isManifestContainerDisabled,circleDiameterPx:this.isTouch()?je:void 0}),this.subscriptions.add(A.fromEvent(e,`click`).subscribe(this.controlTap.onElementClick,e=>this.onError(`Control click tap animation error`,e))).add(A.fromEvent(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(M.wrapper),e.setControlLayout(t,this.control.layoutParams),this.container={element:t,dimensions:(this.control.layoutParams.innerSizesDependOn??k.innerSizesDependOn)===`self`?{height:t.style.height,width:t.style.width}:{height:this.cssVarsManager?.getPropValue(`--interactive-content-height`)??0,width:this.cssVarsManager?.getPropValue(`--interactive-content-width`)??0},isManifestContainerDisabled:()=>e.isContainerDisabled?.call(e)??!1}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&Ae(this.options)&&this.options.features[e])}isTouch(){return!!(this.options&&Ae(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(A.fromEvent(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 $e=`interactive-blink-anim-reference`,L={common:$e,animation:`${$e}-animation`,disabled:`${$e}-disabled`};class et{constructor(){a(this,`_RAFId`,0),a(this,`_element`,void 0)}get element(){return this._element}create(){if(this._element)return;let e=document.createElement(`div`);e.classList.add(L.common,L.animation),this._element=e}restart(){this._element&&(this._element.classList.add(L.disabled),this.cleanupRAF(),this._RAFId=requestAnimationFrame(()=>{this._element&&(this._element.classList.remove(L.disabled),this.cleanupRAF())}))}cleanupRAF(){this._RAFId&&=(cancelAnimationFrame(this._RAFId),0)}destroy(){this.cleanupRAF(),this._element=void 0}}var tt=`interactive-container`,R={common:tt,hidden:`${tt}-hidden`,disabled:`${tt}-disabled`},nt=(e,t)=>{if(e.type.trim().toLowerCase()===`area`)return new rt(e,t)};class rt extends I{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(M.common,M.area),n.setAttribute(`data-testid`,`int_area`),xe({target:n,props:this.control.props,fallback:o(o({},k),{},{backgroundColor:`transparent`})}),we({target:n,layoutParams:this.control.layoutParams,fallback:k}),this.addControlTap(n),this.subscriptions.add(T.fromEvent(this.container.element,`click`).pipe(T.once()).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(T.fromEvent(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(R.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${L.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(T.fromEvent(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(R.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(T.fromEvent(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(M.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(M.disabled)}getElement(){return this.controlElement}updateShadowStyles(e){if(!(!this.container||!this.controlElement))if(de(e)){var t;let n=Math.min(this.controlElement.offsetWidth,this.controlElement.offsetHeight)+`px`;Ce({target:this.controlElement,props:this.control.props,fallback:k,isDark:e,baseDimension:n}),Se({target:this.controlElement,props:this.control.props,fallback:o(o({},k),{},{borderColor:e?k.shadowColorDark:k.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)??k.roundCorners})`}),dependsOn:this.container.dimensions,useRawValues:!0})}else Se({target:this.controlElement,props:this.control.props,fallback:o(o({},k),{},{borderAlpha:0}),dependsOn:this.container.dimensions})}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(M.blinkAnim,e),this.controlElement?.classList.toggle(M.blinkAnimArea,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${M.blinkAnimArea}`)||this.controlElement.classList.contains(M.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add(T.fromEvent(e,`animationiteration`).pipe(T.once()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${M.blinkAnimArea}`)||this.controlElement.classList.contains(M.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 z=require(`@vkontakte/videoplayer-shared`),it=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}},at=Math.PI,ot=2*at,st=at/2,ct=3*st,lt=[0,st,at,ct];function ut(e){return e===st}function dt(e){return e===at}function ft(e){return e===ct}function pt(e){return(e%ot+ot)%ot}function mt(e){for(let t of lt)if(e===t)return t}function ht(e){return mt(e)?null:[1,2,3,4][Math.floor(e/st)+1-1]}function gt(e){return e*180/Math.PI}var B=`interactive-control-fill-animation`,V={common:B,fillerWrapper:`${B}-filler-wrapper`,filler:`${B}-filler`,fillHeight:`${B}-fill-height`,fillWidth:`${B}-fill-width`,fromTop:`${B}-from-top`,fromBottom:`${B}-from-bottom`,fromLeft:`${B}-from-left`,fromRight:`${B}-from-right`};class _t{constructor(e){a(this,`fillAnimationElement`,void 0),a(this,`fillAnimationFillerElement`,void 0),a(this,`fillAnimationFillerWrapperElement`,void 0),a(this,`startTime`,void 0),a(this,`endTime`,void 0),a(this,`shouldFillHeight`,void 0),a(this,`widthExpansionCoef`,0),a(this,`isDebug`,void 0),a(this,`fromLeft`,void 0),a(this,`useSkew`,void 0),a(this,`rotateAngle`,void 0);let t=document.createElement(`div`);t.classList.add(V.common);let n=document.createElement(`div`);n.classList.add(V.fillerWrapper);let r=document.createElement(`div`);r.classList.add(V.filler),n.append(r),t.append(n);let i=pt(e.rotateAngle),o=ht(i),s=o!==null,c=o===2||!s&&dt(i)||o===3,l=!s&&ut(i),u=!s&&ft(i),d=!c&&!l&&!u,f=l||u,p=s&&!f,m=p?i:0;t.style.borderRadius=e.borderRadius,n.style.transform=`skew(${m*-1}rad)`,f?(r.classList.add(V.fillHeight,l?V.fromTop:V.fromBottom),n.classList.add(V.fillHeight,l?V.fromTop:V.fromBottom)):(r.classList.add(V.fillWidth,d?V.fromLeft:V.fromRight),n.classList.add(V.fillWidth)),e.debug&&console.log(`[interactive ${_t.name}]`,{widthExpansionCoef:this.widthExpansionCoef,opts:e,shouldFillHeight:f,rotateAngleRad:i,rotateAngelDeg:gt(i),rotateAngleRaw:e.rotateAngle,fromRight:c,fromTop:l,fromBottom:u,fromLeft:d}),this.useSkew=p,this.fromLeft=d,this.rotateAngle=i,this.fillAnimationElement=t,this.fillAnimationFillerElement=r,this.fillAnimationFillerWrapperElement=n,this.startTime=e.startTime,this.endTime=e.endTime,this.shouldFillHeight=f,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 vt=(e,t)=>{if(e.type.trim().toLowerCase()===`button`)return new yt(e,t)};class yt extends I{constructor(e,t){super(e,t),a(this,`startTime`,void 0),a(this,`endTime`,void 0),a(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(M.common,M.button),n.setAttribute(`data-testid`,`int_bttn`),we({target:n,layoutParams:this.control.layoutParams,fallback:k}),xe({target:n,props:this.control.props,fallback:k}),Se({target:n,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),ye({target:n,props:o(o({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=it(this.control.type.trim().toLowerCase());be({target:r.firstElementChild??r,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),this.addControlTap(n),this.startTime!==void 0&&this.endTime!==void 0&&this.featureIsEnabled(`controlsFillAnimation`)&&(this.controlFillAnimation=new _t({startTime:this.startTime,endTime:this.endTime,rotateAngle:this.control.layoutParams.angle??k.angle,borderRadius:n.style.borderRadius})),this.subscriptions.add(z.fromEvent(n,`click`).pipe(z.once()).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(z.fromEvent(this.controlElement,`mouseleave`).subscribe(()=>{if(e.classList.contains(R.disabled))return;let t=e.parentElement;if(t){let e=t.querySelector(`.${L.common}`);e&&this.syncBlinkAnimation(e)}},e=>this.onError(`Error happened in mouseleave callback`,e))),this.subscriptions.add(z.fromEvent(this.controlElement,`mouseenter`).subscribe(()=>{e.classList.contains(R.disabled)||this.onBlinkHovering()},e=>this.onError(`Error happened in mouseenter callback`,e))).add(z.fromEvent(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(M.disabled)}enable(){this.controlElement&&this.controlElement.classList.remove(M.disabled)}getElement(){return this.controlElement}toggleBlinkAnimation(e){this.controlElement?.classList.toggle(M.blinkAnim,e),this.controlElement?.classList.toggle(M.blinkAnimButton,e)}syncBlinkAnimation(e){this.controlElement&&(!this.controlElement.classList.contains(`${M.blinkAnimButton}`)||this.controlElement.classList.contains(M.selected)||this.controlElement.classList.contains(L.disabled)||(this.controlElement.classList.add(L.disabled),this.subscriptions.add(z.fromEvent(e,`animationiteration`).pipe(z.once()).subscribe(()=>{this.controlElement&&this.controlElement.classList.remove(L.disabled)},e=>this.onError(`Error happened in animationiteration callback`,e)))))}onBlinkHovering(){if(!this.controlElement||!this.controlElement.classList.contains(`${M.blinkAnimButton}`)||this.controlElement.classList.contains(M.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 bt=(e,t)=>{if(e.type.trim().toLowerCase()===`text`)return new xt(e,t)};class xt extends I{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(M.common,M.text),n.setAttribute(`data-testid`,`int_text`),we({target:n,layoutParams:this.control.layoutParams,fallback:k}),ye({target:n,props:o(o({},this.control.props.text),{},{alignment:this.control.layoutParams.alignment})});let r=it(this.control.type.trim().toLowerCase());be({target:r.firstElementChild??r,props:this.control.props,fallback:k,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 St=(e,t,n,r)=>{if(e.type.trim().toLowerCase()===`choice`)return new Ct(e,t,n,r)};class Ct extends oe{constructor(e,t,n,r){super(e,n,r),a(this,`rootElement`,void 0),a(this,`containerElement`,null),a(this,`layout`,void 0),a(this,`subscriptions`,new te.Subscription),a(this,`isRemoved`,void 0),a(this,`isDisabled`,void 0),a(this,`willRemoved`,void 0),a(this,`cssVarsManager`,void 0),a(this,`onTransitionEnd`,e=>{e.stopPropagation(),!(!e.target||!e.currentTarget)&&e.target===e.currentTarget&&this.removeView()}),this.rootElement=t,this.layout=new re(this.container.layout,n),this.cssVarsManager=n,this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory(`button`,vt),this.addControlFactory(`text`,bt),this.addControlFactory(`area`,nt)}createView({eventCallback:e,videoDurationMs:t}){let n=document.createElement(`div`);return n.classList.add(R.common,R.disabled),n.setAttribute(`data-subjectId`,this.container.id),requestAnimationFrame(()=>{n.classList.remove(R.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(R.hidden)}show(){let e=this.getElement();e&&e.classList.remove(R.hidden)}enable(){let e=this.getElement();e&&(e.classList.remove(R.disabled),this.controls.forEach(e=>e.enable()),this.isDisabled=!1)}disable(){let e=this.getElement();e&&(e.classList.add(R.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(te.fromEvent(n,`transitionend`).subscribe(this.onTransitionEnd,e=>this.onError(`${Ct.name} remove view transition error`,e))).add(te.fromEvent(n,`transitioncancel`).subscribe(this.onTransitionEnd,e=>this.onError(`${Ct.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))}}var H=require(`@vkontakte/videoplayer-shared`),U=require(`@vkontakte/videoplayer-statistics`),wt=require(`@vkontakte/videoplayer-shared`);function Tt(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}var Et=`video_interactive`,Dt=`videoint`,Ot=250;class kt{constructor(e){a(this,`isHidden`,void 0),a(this,`currentManifestId`,void 0),a(this,`currentChapterId`,void 0),a(this,`visitedChapterIds`,void 0),a(this,`onOpenPreviewClick`,void 0),a(this,`onError`,void 0),a(this,`lang`,void 0),a(this,`zoom`,void 0),a(this,`lastZoomInfo`,void 0),a(this,`isReady`,void 0),a(this,`ngEditor`,void 0),a(this,`ngEditorSize`,void 0),a(this,`graphWrapperElement`,void 0),a(this,`resizeObserver`,void 0),a(this,`manifest`,void 0),a(this,`handleZoomChange`,Tt(e=>{this.lastZoomInfo=e},Ot)),a(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}}),a(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}}),a(this,`handleManifestChange`,(e,t=[])=>{if(this.isReady=!1,!le(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=At(e),this.resizeObserver=new ResizeObserver(Tt(this.onResize,Ot)),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 s(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 t=this;return s(function*(){if(!t.manifest)return;let n;try{n=yield wt.loadVKLangPack(t.lang,Et,Dt)}catch{t.onError?.call(t,`Unable to load graph language pack`)}let{GraphEditor:r}=yield import(`@interactiveplatform/movika-graph-editor`);t.ngEditor=new r(t.graphWrapperElement,{mode:`view`,lang:t.lang===`ru`?`ru`:`en`,translation:n}),t.currentManifestId=t.manifest.metadata.id,t.ngEditor.update(t.manifest),t.ngEditor.setVisitedChapters(Array.from(t.visitedChapterIds)),t.currentChapterId&&t.ngEditor.selectChapter(t.currentChapterId),t.ngEditor.on(`control`,n=>{let{name:r}=n,i=c(n,e);r===`openPreview`&&`chapterId`in i&&t.onOpenPreviewClick?.call(t,i.chapterId)}),t.ngEditor.on(`zoom`,t.handleZoomChange),t.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 At(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 jt=3e3;class Mt{constructor(){a(this,`_containers`,[]),a(this,`_player`,null),a(this,`setPlayer`,e=>{this._player=e}),a(this,`setContainers`,e=>{this._containers=e}),a(this,`deleteContainer`,e=>{this._containers=this._containers.filter(t=>t.id!==e)}),a(this,`getNextInteractiveTime`,(e=jt)=>{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 Nt{constructor(){a(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 Pt{constructor(e){a(this,`raf`,void 0),a(this,`fn`,void 0),a(this,`fns`,[]),a(this,`addFn`,(e,t=!1)=>{ue(e)&&(this.fns.push(e),t&&this.updateFn())}),a(this,`removeFn`,(e,t=!1)=>{this.fns=this.fns.filter(t=>t!==e),t&&this.updateFn()}),a(this,`updateFn`,()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}}),a(this,`forceRequestAnimation`,()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))}),a(this,`requestAnimation`,()=>{this.raf||this.forceRequestAnimation()}),a(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=[]}}var Ft=require(`@vkontakte/videoplayer-shared`);class It{constructor(e){a(this,`rootElement`,void 0),a(this,`isCssVarsSupported`,void 0),a(this,`rootElementProps`,{}),this.rootElement=e,this.isCssVarsSupported=It.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=o(o({},this.rootElementProps),e),this.isCssVarsSupported)for(let[t,n]of Ft.objectEntries(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)}}var Lt=require(`@vkontakte/videoplayer-shared`);class Rt{constructor(e){a(this,`loaders`,void 0),this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}exec(e,t){var n=this;return s(function*(){return zt(...n.loaders[e])(t)})()}}function zt(...e){return function(){var t=s(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 Bt(e,t,n){return e?o(o({},e),{},{[t]:e[t]?[n,...e[t]]:[n]}):{[t]:[n]}}function Vt(e){let{actions:n,errors:r,chapterId:i}=e,a=c(e,t);if(i){let e=n.getManifest();if(e){let t=n.getChapter(e.chapters,i);if(t){let i=n.getMedia(e.media,t.videoId),s=n.getGraph(e.graph,t.id);return i?o(o({},a),{},{actions:n,errors:r,result:{chapter:t,media:i,graph:s}}):o(o({},a),{},{errors:Bt(r,Vt.name,`Could not find media`),actions:n})}}}return o(o({},a),{},{errors:Bt(r,Vt.name,`Could not find chapter`),actions:n})}var Ht=require(`@vkontakte/videoplayer-shared`),Ut=(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},Wt=function(){var e=s(function*(e){try{let t={},n;if(se(e)){n=new URL(e).href;let r=yield Ht.fetchPolyfilled(n);if(!r.ok)return{};t=yield r.json()}else if(D(e))t=e;else return{};if(!Pe(t))return{};let r=t.metadata.media;if(se(r)&&!(`media`in t))try{let e;n?e=new URL(r,n).href:(e=new URL(r).href,n=e);let i=yield Ht.fetchPolyfilled(e);if(!i.ok)throw Error();t.metadata.media=yield i.json()}catch{return Qt(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:n}}catch{return{}}});return function(t){return e.apply(this,arguments)}}();function Gt(e){return Kt.apply(this,arguments)}function Kt(){return Kt=s(function*(e){let{manifest:t,manifestURL:n}=yield Wt(e);if(!t)throw Error(`Failed on fetch`);let r=N.migrateManifestToLatestVersion(t);return r.media=Xt(r.media,n),delete r.metadata.media,r}),Kt.apply(this,arguments)}function qt(e,t){if(t)return e.find(e=>e.id===t)}function Jt(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 Yt(e,t){return e.videos.find(e=>e.id===t)}function Xt(e,t){return o(o({},e),{},{videos:e.videos.map(e=>o(o({},e),{},{variants:e.variants.map(e=>{let n=`url`in e?e.url:``,r=Zt(n,t);return o(o({},e),{},{url:r||n})})}))})}function Zt(e=``,t){try{return new URL(e,t).href}catch{return``}}function Qt(e){return Ut(e,`3.2.0`)>=0}class $t extends Rt{constructor(e,t){super(e),a(this,`manifest`,null),a(this,`chapter`,null),a(this,`media`,null),a(this,`graph`,null),a(this,`prevChapter$`,new Lt.ValueSubject(null)),a(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 s(function*(){t.release();let n=yield t.exec(`manifestLoaders`,{actions:{addErrorMessage:Bt},result:null,errors:null,source:e});return n.errors&&t.errorHandler(n.errors),t.manifest=yield Gt(n.result??e),t})()}setInitial(){var e=this;return s(function*(){return e.setNext()})()}setNext(){var e=this;return s(function*(t=this.manifest?.metadata.initChapterId){if(!t)return e;e.prevChapter$.next(e.chapter);let n=yield e.exec(`chapterLoaders`,Vt({actions:{getManifest:()=>e.manifest,getCurrent:e.getCurrent,getGraph:Jt,getChapter:qt,getMedia:Yt,getByBranches:e.getByBranches.bind(e),addErrorMessage:Bt},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=qt(this.manifest.chapters,e);if(t){let e=Yt(this.manifest.media,t.videoId),n=Jt(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=qt(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?P(this.chapter):!1}}var en=require(`@vkontakte/videoplayer-shared`),tn=require(`@vkontakte/videoplayer-core`),W=require(`@vkontakte/videoplayer-shared`),nn=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[]},rn=require(`@vkontakte/videoplayer-shared`);function an(){let e=new Map;function t(t){let{listId:r=Math.random().toString(),itemId:i=Math.random().toString()}=t,a=c(t,n),s=e.get(r),l=o({},a);return s?s[i]=l:e.set(r,{[i]:l}),o({listId:r,itemId:i},a)}function r(e){e.player.destroy(),e.container.remove(),e.subscription.unsubscribe(),e.statistics?.oneStat.destroy(),e.statistics?.statSubscription.unsubscribe()}function i(t,n){let i=e.get(t);if(!i)throw Error(`Can't remove. Not find.`);if(n){let a=i[n];a&&r(a),delete i[n],Object.keys(i).length||e.delete(t)}else{for(let e of rn.objectValues(i))r(e);e.delete(t)}}function a(){for(let t of e)i(t[0])}return{createPlayer:t,removePlayer:i,map:e,removeAll:a}}var G=require(`@vkontakte/videoplayer-shared`);function on(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||G.arrayIncludes(t,`mp4`))&&(n.MPEG=o(o({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`mpeg`:(i||G.arrayIncludes(t,`mpeg`))&&(n.MPEG=o(o({},n.MPEG),{},{[a.standard??`Invariant quality`]:a.url}));break;case`hls`:(i||G.arrayIncludes(t,`hls`))&&(n=o(o({},n),{},{HLS:{type:`url`,url:a.url}}));break;case`dash`:(i||G.arrayIncludes(t,`dash`))&&(n=o(o({},n),{},{DASH_SEP:{compatibilityMode:!0,type:`url`,url:a.url}}));break;default:break}return{sources:n,thumbUrl:r,title:e.title??``}}var sn=(e,t)=>{let n=e.info.currentQuality$.getValue(),r=e.info.availableQualities$.getValue();n!==t&&G.arrayIncludes(r,t)&&(e.setQuality(t),e.setAutoQuality(!1))},cn=2;function ln(e){let t=an(),n=new W.Subscription,r={},i=null,a=!1,c,l=new W.ValueSubject(null);e&&u(e);function u(e){i=e}function d(e,n,s){if(!i)throw Error(`need to set interactive controller`);if(!i.options)return;let c=(t.map.get(e)??{})[n];if(c){r=o({chapterId:s,listId:e,itemId:n},c);let u=r.player;r.subscription.add(u.info.currentQuality$.subscribe(e=>{let n=u.info.position$.getValue(),r=u.info.isAutoQualityEnabled$.getValue();if(!(!e||!n||r))for(let n of t.map)en.objectValues(n[1]).forEach(({player:t})=>{sn(t,e)})})).add(u.events.started$.subscribe(()=>{f(n)})),c.container.remove(),i.setPlayer(c.player),a||=(i.init(),!0),l.next({player:r.player,config:r.config,statistics:r.statistics});return}throw Error(`Can't set. Not find.`)}function f(e){return p.apply(this,arguments)}function p(){return p=s(function*(e){if(!i)throw Error(`need to set interactive controller`);if(O(r)||e!==r.itemId)return;let t=i.getChapterBranches(),n=new Set;for(let e of t)n.has(e.media.id)||(yield g({media:e.media,chapterId:e.chapter.id,setAsActive:!1,title:e.chapter.label}),n.add(e.media.id))}),p.apply(this,arguments)}function m(e){return h.apply(this,arguments)}function h(){return h=s(function*({chapter:{id:e},manifestVideo:n}){if(O(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(),l=r.player.info.currentPlaybackRate$.getValue(),u=!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<cn||(f=!0),t.removePlayer(s[0],i)):(f=!0,d(s[0],i,e),u?sn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a),r.player.setPlaybackRate(l))}else t.removePlayer(s[0]);f||(yield g({media:n,chapterId:e,setAsActive:!0,playbackRate:l}),u?sn(r.player,o):r.player.setAutoQuality(!0),r.player.setVolume(c),r.player.setMuted(a))}),h.apply(this,arguments)}function g(e){return _.apply(this,arguments)}function _(){return _=s(function*({media:e,chapterId:n,prefetch:a=!0,setAsActive:s=!0,autoplay:l=!1,preferredExt:u,title:f,playbackRate:p}){var m,h,g,_;let v=Math.random().toString(),y=document.createElement(`div`);c.append(y);let b;if(!(i==null||(m=i.options)==null)&&m.vkVideoLoader){let t=nn(e);t.length&&(b=yield i.options.vkVideoLoader(...t))}let x=o({},(i==null||(h=i.options)==null?void 0:h.coreConfig)||void 0),ee=o(o({container:y,sources:on(e,u).sources},b==null||(g=b.videos)==null?void 0:g[0]),{},{title:f,failoverHosts:b?.failoverHosts||[]}),S=new tn.Player(x,W.TracerFactory.createRootTracer());S.initVideo(ee);let te=null;if(b?.videos&&i?.options.createOneStat){let e=b.videos[0],t=i.options.createOneStat(e),n=new W.Subscription;t&&(n.add(t.attachTo(S)),te={oneStat:t,statSubscription:n})}let ne=new W.Subscription,re=r==null||(_=r.player)==null?void 0:_.info.isAutoQualityEnabled$.getValue();ne.add(S.events.canplay$.subscribe(function(){re||sn(S,r.player.info.currentQuality$.getValue()),p&&S.setPlaybackRate(p)}));let C=t.createPlayer({listId:e.id,itemId:v,player:S,container:y,sources:on(e,u).sources,config:ee,subscription:ne,statistics:te});return s&&d(e.id,C.itemId,n),l&&C.player.play(),a&&!l&&C.player.prepare(),{player:C.player,config:C.config,statistics:C.statistics}}),_.apply(this,arguments)}function v(){y(),i=null,c.remove()}function y(){n.unsubscribe(),t.removeAll(),r={},a=!1}function b(){return x.apply(this,arguments)}function x(){return x=s(function*(){if(!i)throw Error(`need to set interactive controller`);y(),c=document.createElement(`div`);let{media:e,chapter:t}=i.getCurrentChapter();e&&t?(n.add(i.events.chapterChanged$.subscribe(m)),yield g({media:e,chapterId:t.id,title:t.label})):console.error(`not found`)}),x.apply(this,arguments)}return{map:t.map,removePlayer:t.removePlayer,init:b,setInteractiveController:u,createPlayer:g,removeAll:v,getActivePlayer:function(){return r},activePlayerChanged:l}}var K={graph:`graph`,interactives:`interactives`,chapterChanged:`chapter-changed`,playerChanged:`player-changed`,manifestChanged:`manifest-changed`,errors:`errors`,eachTick:`eachTick`,historyInited:`history-inited`,historyDestroyed:`history-destroyed`},un={visibility:`visibility`,watchAgainClicked:`watchAgainClicked`},q={actionChoiceCanceled:`action-choice-canceled`,actionChoice:`action-choice`,actionExecution:`action-execution`,visibility:`visibility`,containerRemoved:`container-removed`,rangeEnded:`range-ended`},dn=require(`@vkontakte/videoplayer-shared`);function fn(e){return function(...t){return e(...t.reverse())}}function pn(e,...t){return(...n)=>D(t[0])&&D(n[0])?e(o(o({},t[0]),n[0])):e(...t,...n)}class mn{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:i,globalEvents:o,globalEventEmitter:s,getContainerEventState:c,permanentTextControls:l,interactiveTimeOpenUri:u,disabledControls$:d,onRemove:f,onError:p,disableTextControlContainerVisibilityEvents:m=!1,features:h}){a(this,`container`,void 0),a(this,`branches`,void 0),a(this,`selectBranches`,void 0),a(this,`subscription`,void 0),a(this,`player`,void 0),a(this,`interactiveEvents`,void 0),a(this,`getContainerEventState`,void 0),a(this,`isPermanentText`,void 0),a(this,`interactiveTimeOpenUri`,void 0),a(this,`disabledControls$`,void 0),a(this,`onRemove`,void 0),a(this,`globalEventEmitter`,void 0),a(this,`gameState`,void 0),a(this,`isSelectedControlEvent`,void 0),a(this,`isSelectedContainerEvent`,void 0),a(this,`globalEvents`,void 0),a(this,`onError`,void 0),a(this,`disableTextControlContainerVisibilityEvents`,void 0),a(this,`features`,void 0),a(this,`hide`,()=>{setTimeout(()=>{if(this.gameState!==4&&!(F(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)}})}),a(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=pn(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)}}}),a(this,`onEndOfVideo`,()=>{this.gameState=4,this.selectContainerEvent(!0)}),a(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(We(n,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Ge(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=Ge(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(K.eachTick,o),this.globalEvents.eachTick$.next(o)}),this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new dn.Subscription,this.player=e,this.interactiveEvents=i,this.getContainerEventState=c;let g=Je(t.container.controls);this.isPermanentText=l&&g,this.disableTextControlContainerVisibilityEvents=m&&g,this.interactiveTimeOpenUri=u,this.disabledControls$=d,this.onRemove=f,this.globalEventEmitter=s,this.gameState=0,this.globalEvents=o,this.onError=p,this.features=h,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(K.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:q.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(K.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:q.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:F(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(K.interactives,{subjectId:this.container.container.id,subjectName:`container`,type:q.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 hn=(e=[])=>e.reduce((e,t,n)=>{if(He((t?.controls??[]).filter(e=>!Fe(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]),gn=require(`@vkontakte/videoplayer-shared`),_n=require(`@vkontakte/videoplayer-shared`),vn=require(`@vkontakte/videoplayer-shared`);function yn(){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 i(t){let n={};for(let r in e)+r>=t&&(n[r]=e[r]);return n}function a({timestamp:t,priority:n,initiator:r}){if(fe(t)){let i=e[t]??null;if(i&&n&&me(n,!0)){let e={},t=i[n];return t&&(e=o(o({},e),t)),e=O(e)?null:e,e&&me(r,!0)?e[r]??null:e}return i}return null}function s({timestamp:t,priority:n,initiator:r}){if(fe(t))if(e[t]){if(n&&me(n,!0))if(e[t][n]){if(r&&me(r,!0))if(e[t][n][r]){if(delete e[t][n][r],!O(e[t][n]))return!0}else return!1;if(delete e[t][n],!O(e[t]))return!0}else return!1;return delete e[t]}else return!1;return!1}function l(t){var n;let{timestamp:i,priority:a,initiator:s}=t,l=c(t,r);!((n=e[i])==null||(n=n[a])==null)&&n[s]?e[i][a][s].push(o({},l)):e[i]?.[a]?e[i][a]=o(o({},e[i][a]),{},{[s]:[o({},l)]}):e[i]?e[i]=o(o({},e[i]),{},{[a]:{[s]:[o({},l)]}}):e[i]={[a]:{[s]:[o({},l)]}}}return{map:e,remove:s,add:l,removeAll:t,get:a,getLte:n,getGte:i}}var bn=[N.EventActionTypes.expect,N.EventActionTypes.setNextBranch],xn=1/0;function Sn(e,t){let n=e,r,i=Cn(t),a=yn(),o,s=()=>{p(),_()},c=e=>{a.add.call(void 0,e),m()},l=(e=[])=>{for(let t of e)if(t.action(),gn.arrayIncludes(bn,t.actionType))break},u=(e=1/0)=>{let t=wn(a.get({timestamp:e,priority:`control`})??{}),n=wn(a.get({timestamp:e,priority:`container`})??{}),r=wn(a.get({timestamp:e,priority:`chapter`})??{});return[...t,...n,...r]},d=e=>{i.isReady(e)&&l(u(e))},f=()=>{l([...wn(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 Cn(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??xn,r=t.get(e);t.set(e,o(o({},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=_n.objectValues(r);return e?i.some(e=>e):!i.some(e=>!e)},release:()=>t.clear()}}function wn(e){return vn.arrayFlat(_n.objectValues(e)).sort(e=>e.actionType===N.EventActionTypes.expect?-1:1)}var Tn={videoContentHeight:0,videoContentWidth:0},En=e=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return Tn;let{clientHeight:r,clientWidth:i}=e.experimental.element$.getValue()||{};if(!(r&&i))return Tn;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}},Dn=250;function On(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}=En(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=Tt(t=>{let{fns:n=[]}=e();r(t);for(let e of n)e()},Dn);function o(){t=void 0,n.disconnect(),i()}return{resizeObserver:n,calc:()=>{t?.()},release:o}}var kn=e=>Math.floor(Math.random()*e),An=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},jn=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},Mn=e=>{let t=e.length;return e[kn(t)]},Nn=1,Pn=e=>{let t=0;for(let n=0;n<e.length;++n)t+=e[n].weight??Nn;let n=Math.random()*t;t=0;for(let r=0;r<e.length-1;++r)if(t+=e[r].weight??Nn,t>=n)return e[r];return e[e.length-1]},Fn={shouldOpenNow:!0,isDetachContainer:!0},In=`after-expect`,Ln=(e,t=!1)=>o(o({},e),{},{args:t?o(o({},e.args),Fn):o(o({},Fn),e.args)}),Rn=({globalEventEmitter:e,globalEvents:t,player:n,interactiveEvents:r})=>{let i={isExpect:!1},a=()=>{i.isExpect&&=!1},s=({action:n,controlType:i,controlId:a,containerId:s,branches:c=[],onEvent:l,isEOV:u=()=>!1,isDisabled:f=()=>!1})=>{let p=Ln(n,u()),v={timestamp:1/0,priority:`control`,initiator:a,actionType:p.type},y=f(),b=e.emit.bind(e,K.interactives,{subjectId:a,subjectType:i,subjectName:`control`,type:y?q.actionChoiceCanceled:q.actionChoice,actionType:n.type,payload:o({invokeImmediately:p.args.shouldOpenNow,containerId:s},p.args)}),x=()=>{t.interactiveActionChoice$.next({subjectId:a,subjectType:i,subjectName:`control`,type:y?`action-choice-canceled`:`action-choice`,actionType:n.type,payload:o({invokeImmediately:p.args.shouldOpenNow,containerId:s},p.args)})};if(y){b(),x();return}switch(p.type.trim().toLowerCase()){case N.EventActionTypes.setNextBranch.trim().toLowerCase():{let e=c.find(e=>e.id===p.args.branchId);if(!e)return;l(p.args.isDetachContainer,m.bind(null,{subjectId:a,subjectName:`control`})),b(),x(),p.args.shouldOpenNow?g({subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{chapterId:e.chapterId,autoSelect:!1}}):r.add(o(o({},v),{},{action:g.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{chapterId:e.chapterId,autoSelect:!1}})}));return}case N.EventActionTypes.continuePlayback.trim().toLowerCase():l(p.args.isDetachContainer,m.bind(null,{subjectId:a,subjectName:`control`})),b(),x(),p.args.shouldOpenNow?h({subjectId:a,subjectName:`control`,subjectType:i,action:n}):r.add(o(o({},v),{},{action:h.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:n})}));return;case N.EventActionTypes.openURI.trim().toLowerCase():l(p.args.isDetachContainer,m.bind(null,{subjectId:a,subjectName:`control`})),b(),x(),p.args.shouldOpenNow?_({subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{URI:n.args.uri}}):r.add(o(o({},v),{},{action:_.bind(null,{subjectId:a,subjectName:`control`,subjectType:i,action:p,payload:{URI:n.args.uri}})}));return;default:{let e=`Unexpected control event`;d(new w(1,1,{message:e}),e);return}}},c=({action:n,container:{id:i,endTime:a},branches:s=[],isEOV:c=!1,autoSelected:l=!1})=>{let u=Ln(n,c),f={timestamp:!u.args.shouldOpenNow||c?1/0:a??1/0,priority:`container`,initiator:i,actionType:u.type},p=e.emit.bind(e,K.interactives,{subjectId:i,subjectName:`container`,type:q.actionChoice,actionType:u.type,payload:o({invokeImmediately:u.args.shouldOpenNow},u.args)}),m=()=>{t.interactiveActionChoice$.next({subjectId:i,subjectName:`container`,type:`action-choice`,actionType:u.type,payload:o({invokeImmediately:u.args.shouldOpenNow},u.args)})};switch(u.type.trim().toLowerCase()){case N.EventActionTypes.setNextBranch.trim().toLowerCase():{let e=s.find(e=>e.id===u.args.branchId);if(!e)return;p(),m(),r.add(o(o({},f),{},{action:g.bind(null,{subjectId:i,subjectName:`container`,action:u,payload:{chapterId:e.chapterId,autoSelect:l}})}));return}case N.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():return;case N.EventActionTypes.setMinWeightBranch.trim().toLowerCase():return;case N.EventActionTypes.setRandomBranch.trim().toLowerCase():return;case N.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():return;case N.EventActionTypes.continuePlayback.trim().toLowerCase():p(),m(),r.add(o(o({},f),{},{action:h.bind(null,{subjectId:i,subjectName:`container`,action:u})}));return;case N.EventActionTypes.openURI.trim().toLowerCase():p(),m(),r.add(o(o({},f),{},{action:_.bind(null,{subjectId:i,subjectName:`container`,action:u,payload:{URI:n.args.uri}})}));return;default:{let e=`Unexpected container event`;d(new w(1,1,{message:e}),e);return}}};function l({container:n,branches:a,isEOV:s=!1}){let l=Ke(n.events);if(l){let a=Ln(l.action,s);e.emit(K.interactives,{subjectId:n.id,subjectName:`container`,type:q.actionChoice,actionType:a.type,payload:o({invokeImmediately:a.args.shouldOpenNow},a.args)}),t.interactiveActionChoice$.next({subjectId:n.id,subjectName:`container`,type:`action-choice`,actionType:a.type,payload:o({invokeImmediately:a.args.shouldOpenNow},a.args)}),r.add({timestamp:s?1/0:n.endTime??1/0,priority:`container`,initiator:n.id,actionType:N.EventActionTypes.expect,action:p.bind(null,{subjectId:n.id,subjectName:`container`})}),i.isExpect=!0}else for(let e of n.events??[])c({action:e.action,container:n,branches:a,isEOV:s})}let u=({chapterId:n,action:r,branches:i=[]})=>{let a=e.emit.bind(e,K.interactives,{subjectId:n,subjectName:`chapter`,type:q.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 N.EventActionTypes.setNextBranch.trim().toLowerCase():{let e=i.find(e=>e.id===r.args.branchId);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setWeightlessRandomBranch.trim().toLowerCase():{let e=Mn(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setRandomBranch.trim().toLowerCase():{let e=Pn(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setMaxWeightBranch.trim().toLowerCase():{let e=jn(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.setMinWeightBranch.trim().toLowerCase():{let e=An(i);return e?.chapterId?(a(),o(),g.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{chapterId:e.chapterId,autoSelect:!0}})):void 0}case N.EventActionTypes.continuePlayback.trim().toLowerCase():return a(),o(),h.bind(null,{subjectId:n,subjectName:`chapter`,action:r});case N.EventActionTypes.openURI.trim().toLowerCase():return a(),o(),_.bind(null,{subjectId:n,subjectName:`chapter`,action:r,payload:{URI:r.args.uri}});default:{let e=`Unexpected chapter event`;d(new w(1,1,{message:e}),e);return}}};function d(n,r){console.error(r),t.error$.next(n),e.emit(K.errors,n)}function f(n){let i=Ke(n.events);if(i){if(P(n))return;e.emit(K.interactives,{subjectId:n.id,subjectName:`chapter`,type:q.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:N.EventActionTypes.expect,action:p.bind(null,{subjectId:n.id,subjectName:`chapter`})})}else n.events?.forEach(e=>{let t=u({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 p=({subjectId:r,subjectName:i})=>{n.pause(),e.emit(K.interactives,{subjectId:r,subjectName:i,type:q.actionExecution,actionType:N.EventActionTypes.expect}),t.interactiveActionExecution$.next({subjectId:r,subjectName:i,type:`action-execution`,actionType:N.EventActionTypes.expect})},m=({subjectId:i,subjectName:a})=>{n.info.isEnded$.getValue()?r.execEndOfVideo():n.play(),e.emit(K.interactives,{subjectId:i,subjectName:a,type:q.actionExecution,actionType:In}),t.interactiveActionExecution$.next({subjectId:i,subjectName:a,type:`action-execution`,actionType:In})},h=({subjectId:n,subjectName:r,subjectType:i,action:a})=>{e.emit(K.interactives,{subjectId:n,subjectName:r,subjectType:i,type:q.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})},g=({subjectId:n,subjectName:r,subjectType:i,action:a,payload:o})=>{o.behaviour=`change-chapter`,e.emit(K.interactives,{subjectId:n,subjectName:r,subjectType:i,type:q.actionExecution,actionType:a.type,payload:o}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type,payload:o})},_=({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(K.interactives,{subjectId:n,subjectName:r,subjectType:i,type:q.actionExecution,actionType:a.type}),t.interactiveActionExecution$.next({subjectId:n,subjectName:r,subjectType:i,type:`action-execution`,actionType:a.type})};return{onControlEvent:s,onContainerEvent:c,onChapterEvent:u,onExpectEvent:p,expectEventHandler:m,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:a,state:i}},J=require(`@vkontakte/videoplayer-shared`),zn=(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]=Hn(i)}return n[e]}).filter(e=>e!==null)},Bn=e=>{for(let t of e.variants)if(Vn(t)&&t.payload)return t.payload.id},Vn=e=>!!(e.type===`custom`&&e.payload&&e.payload.type===`vk`),Hn=e=>{let t=Bn(e);if(!t)return null;let n=t.split(`_`).pop();return n?parseInt(n,10):null},Un=(e,t)=>{for(let n of e.media.videos)if(t===Hn(n)){for(let t of e.chapters)if(t.videoId===n.id)return t.id;return}},Wn=(e,t)=>e.reduce((e,n)=>{let r=Un(t,n);return r?[...e,r]:e},[]),Y=new WeakMap,Gn=new WeakMap,Kn=new WeakMap,X=new WeakMap,qn=new WeakMap,Z=new WeakMap,Q=new WeakMap,$=new WeakMap,Jn=new WeakMap,Yn=new WeakMap,Xn=new WeakMap;class Zn{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:i}){a(this,`state`,{history$:new J.ValueSubject([]),hasPrevChapter$:new J.ValueSubject(!1),prevChapter$:new J.ValueSubject(null),isInitialChapter$:new J.ValueSubject(!1),isGoBackLimited$:new J.ValueSubject(!1)}),l(this,Y,null),l(this,Gn,void 0),l(this,Kn,!1),l(this,X,null),l(this,qn,null),a(this,`events`,{inited$:new J.Subject,destroyed$:new J.Subject,error$:new J.Subject}),l(this,Z,null),l(this,Q,null),l(this,$,null),l(this,Jn,new J.Subscription),l(this,Yn,!1),l(this,Xn,0),u(Z,this,t),u($,this,e),u(Q,this,n),u(Y,this,r),u(Gn,this,i),this.state.history$&&d(Jn,this)&&d(Jn,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=d(X,this))==null||(t=t.metadata)==null?void 0:t.initChapterId)),this.state.isGoBackLimited$.next(d(Xn,this)===d(Gn,this).maxLength-1)}))}setManifest(e){var t=this;return s(function*(){if(!d(Q,t)||!d($,t))return;u(X,t,e),yield t.getProjectHistory();let n=t.getInitialChapterId();yield d(Q,t).setChapter({chapterId:n,pushToHistory:!1}),d(Kn,t)||(u(Kn,t,!0),t.events.inited$.next({initChapterId:n}))})()}get inited(){return d(Kn,this)}updateHistory(e,t=!0){var n=this;return s(function*(){if(!d(X,n))return;if(d(Yn,n)){var r;u(Yn,n,!1),u(Xn,n,(r=d(Xn,n),r++,r))}else u(Xn,n,0);let i=d(X,n),a=e.length-d(Gn,n).maxLength,o=a>0?e.slice(a):e,s=zn(o,i);if(u(qn,n,s),n.state.history$.next(o),!(!t||!d(Y,n)||!d(Z,n)))try{yield d(Y,n).save(d(Z,n),s)}catch{let e=new w(1,5,`Unable to save interactive history`);n.events.error$.next(e),d($,n)?.emit(K.errors,e)}})()}goBack(){var e=this;return s(function*(){if(!e.state||!d(Q,e)){let t=new w(1,5,`Unable to save interactive history`);e.events.error$.next(t),d($,e)?.emit(K.errors,t);return}u(Yn,e,!0);let t=e.state.history$.getValue().slice(0,-1),n=t.pop();e.state.history$.next(t),yield d(Q,e).setChapter({chapterId:n,playPrev:!0})})()}getProjectHistory(){var e=this;return s(function*(){if(!d(X,e)||!d(Z,e))return;let t=d(X,e),n=[e.getInitialVideoId()];if(d(Y,e))try{let t=yield d(Y,e).get(d(Z,e));t.length&&(n=t)}catch{let t=new w(1,5,`Error while trying to fetch data`);e.events.error$.next(t),d($,e)?.emit(K.errors,t)}let r=Wn(n,t);e.state.history$.next(r)})()}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||d(Gn,this).initChapterId||d(X,this)?.metadata.initChapterId}getInitialVideoId(){return d(X,this)?zn([this.getInitialChapterId()],d(X,this)).pop():null}destroy(){u(Z,this,null),u(Y,this,null),u(Q,this,null),d(Jn,this)?.unsubscribe(),u(Jn,this,null),u(Kn,this,!1),d($,this)?.emit(K.historyDestroyed),this.events.destroyed$.next(),u($,this,null)}}class Qn{constructor(){a(this,`rootElement`,void 0),a(this,`canvasImgSrc`,void 0),a(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 s(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 s(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 $n{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){a(this,`lastFrameCanvas`,void 0),a(this,`endOffsetMs`,void 0),a(this,`currentChapter`,void 0),a(this,`currentVideoDurationMs`,1/0),a(this,`rootElement`,void 0),a(this,`_containerTimeFrameShouldReceived`,!1),a(this,`_endTimeFrameReceived`,!1),a(this,`_shouldCallSkip`,!1),a(this,`_callbacks`,void 0),a(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()}}),a(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;