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