@vkontakte/videoplayer-interactive 1.0.72-dev.abb27aca7.0 → 1.0.72-dev.f2a56450b.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 +3 -3
- package/es2015.esm.js +4 -4
- package/esnext.cjs +3 -3
- package/esnext.esm.js +3 -3
- package/evergreen.esm.js +3 -3
- package/package.json +4 -4
package/es2015.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.72-dev.
|
|
3
|
-
* Thu, 02 Jul 2026
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.72-dev.f2a56450b.0
|
|
3
|
+
* Thu, 02 Jul 2026 16:58:39 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-72/doc/
|
|
5
5
|
*/
|
|
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.72-dev.abb27aca7.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){if(this.featureIsEnabled(`controlsTapPlace`)&&this.container){let t=this.control.layoutParams.angle??j.angle;this.controlTap=new qe({controlRotateAngleRad:t,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);let n=(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},r=()=>e.isContainerDisabled?.call(e)??!1;this.container={element:t,dimensions:n,isManifestContainerDisabled:r}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&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=`
|
|
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.72-dev.f2a56450b.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){if(this.featureIsEnabled(`controlsTapPlace`)&&this.container){let t=this.control.layoutParams.angle??j.angle;this.controlTap=new qe({controlRotateAngleRad:t,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);let n=(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},r=()=>e.isContainerDisabled?.call(e)??!1;this.container={element:t,dimensions:n,isManifestContainerDisabled:r}}createClickListener(e){return t=>{t.stopPropagation(),this.isInteracted=!0,e()}}featureIsEnabled(e){return!!(this.options&&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;
|