@vkontakte/videoplayer-interactive 1.0.30-dev.82195443.0 → 1.0.30-dev.954af6ed.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/evergreen.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.30-dev.82195443.0
3
- * Fri, 17 Jan 2025 13:55:18 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.30-dev.954af6ed.0
3
+ * Mon, 03 Feb 2025 21:07:05 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
5
5
  */
6
- var ut="1.0.30-dev.82195443.0";function Ge(i,e=1){let t="0",n="0",r="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+r},${e})`}var P="interactive",Yt="interactive-controls-container",he=()=>document.querySelector(`.${Yt}`),dt=.4,k={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},mt=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(mt||{}),ft=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(ft||{}),yt=(n=>(n.start="left",n.end="right",n.center="center",n))(yt||{}),ue=({target:i,props:e})=>{i.style.alignItems=(e?.gravityVertical&&mt[e.gravityVertical])??"center",i.style.justifyContent=(e?.gravityHorizontal&&ft[e.gravityHorizontal])??"center",i.style.textAlign=(e?.alignment&&yt[e.alignment])??"left"},de=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.color=e?.text?.color??t.textColor,i.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,i.textContent=e?.text?.value??t.textContent},me=({target:i,props:e,fallback:t})=>{i.style.backgroundColor=Ge(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},fe=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth}) solid ${Ge(e?.shape?.border?.color??t.borderColor,e?.shape?.border?.alpha??t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`},X=({target:i,layoutParams:e,fallback:t})=>{let n=e.angle??t.angle;n=n&&n*-1,i.style.transform=`rotate(${n}rad)`};var H=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let t=document.createElement("div");t.classList.add(`${P}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??k.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:t,dimensions:n}}createClickListener(e){return t=>{t.stopPropagation(),e()}}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var Ue="int",U=(n=>(n.AREA=`${Ue}_area`,n.TEXT=`${Ue}_text`,n.BUTTON=`${Ue}_bttn`,n))(U||{});var ye=i=>{if(i.type.trim().toLowerCase()==="area")return new ze(i)},ze=class extends H{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",U.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",me({target:n,props:this.control.props,fallback:{...k,backgroundColor:"transparent"}}),fe({target:n,props:this.control.props,fallback:{...k,borderAlpha:0},dependsOn:this.container.dimensions}),X({target:n,layoutParams:this.control.layoutParams,fallback:k}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var ve=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var ge=i=>{if(i.type.trim().toLowerCase()==="button")return new We(i)},We=class extends H{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",U.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",X({target:n,layoutParams:this.control.layoutParams,fallback:k}),me({target:n,props:this.control.props,fallback:k}),fe({target:n,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),ue({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=ve();de({target:r,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var vt=i=>{if(i.type.trim().toLowerCase()==="text")return new Qe(i)},Qe=class extends H{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",U.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",X({target:n,layoutParams:this.control.layoutParams,fallback:k}),ue({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=ve();de({target:r,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){}enable(){}getElement(){return this.controlElement}};var Ke=class{constructor(e){this.layout=e}},Ce=class extends Ke{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var Z=class{constructor(e){this.container=e,this.factories=new Map,this.controls=[],this.setControls()}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 s=r(t);if(s)return[...e,s]}return[...e]},[])||[]}};var be=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new Xe(i,e)},Xe=class extends Z{constructor(e,t){super(e),this.rootElement=t??he(),this.layout=new Ce(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ge),this.addControlFactory("text",vt),this.addControlFactory("area",ye)}createView(e){let t=document.createElement("div");return t.classList.add(`${P}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{n.createView({parentElement:t,layoutCallback:this.layout.setControlLayout}),n.setEvents(e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity="1",this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=`${dt}`,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${P}-${this.container.id}`)}};import{clientChecker as xn,combine as Sn,InterfaceLanguage as wn,Observable as Zt,once as An,Subject as $,Subscription as pt,ValueSubject as L}from"@vkontakte/videoplayer-shared/evergreen";import{InteractiveInterfaceClick as pe}from"@vkontakte/videoplayer-statistics/evergreen";import{loadVKLangPack as Jt}from"@vkontakte/videoplayer-shared/evergreen";function J(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}var z=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,ee=i=>z(i,"Object"),Ee=i=>z(i,"String"),Ie=i=>z(i,"Array"),Te=i=>z(i,"Number"),gt=i=>z(i,"Function");var Ze=i=>Te(i)&&!isNaN(i);var W=i=>ee(i)&&Object.keys(i).length===0,qe=i=>Ie(i)&&!i.length;var te=(i,e)=>Ee(i)&&(e?i.trim():i).length;var Ct="video_interactive",bt="videoint";var Et=250,ne=class{constructor(e){this.handleZoomChange=J(e=>{this.lastZoomInfo=e},Et);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),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?.("Id is not found"),console.error("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,!Te(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph"),console.error("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.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=en(e),this.resizeObserver=new ResizeObserver(J(this.onResize,Et)),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)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await Jt(this.lang,Ct,bt)}catch{console.log("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:n,...r})=>{n==="openPreview"&&"chapterId"in r&&this.onOpenPreviewClick?.(r.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function en(i){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",i.append(e),e}var ie=class{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=3e3)=>{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 s of this._containers){let c=s.startTime-e;if(c<=r&&(s.endTime&&r<=s.endTime||s.endTime===null)){n=!0;break}r<c&&(t=t===-1?c:Math.min(t,c))}return!n&&t!==-1?t:null}}};import{isSupportedManifest as Se,ContainerTypes as _i,ControlTypes as we,EventActionTypes as I,EventTypes as Hi,migrateManifestToLatestVersion as xt,compareVersions as Di}from"@interactiveplatform/movika-manifest";var It={metadata:"Object",chapters:"Array"},Tt=i=>{if(!ee(i))return!1;for(let e in It)if(!i[e]||!z(i[e],It[e]))return!1;return Se(i.metadata.version)},xe=i=>i.type===we.Text,Vi=i=>i.type===we.Button,Pi=i=>i.type===we.Area,$i={Choice:"Choice",TextInput:"TextInput"},Li={Button:"Button",Area:"Area",Text:"Text"},Ni={onClick:"onClick",onSuspense:"onSuspense"},Oi={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var M=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Ae=class{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 r=n.length;r>0;r--)if(n[r]===t){n.splice(r,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(r=>{r(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Re=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{gt(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==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),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as ln}from"@vkontakte/videoplayer-shared/evergreen";var Me=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return tn(...this.loaders[e])(t)}};function tn(...i){return async function(t){let n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function re(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function ke({actions:i,errors:e,chapterId:t,...n}){if(t){let r=i.getManifest(),s=i.getChapter(r.chapters,t);if(s){let c=i.getMedia(r.media,s.videoId),a=i.getGraph(r.graph,s.id);return c?{...n,actions:i,errors:e,result:{chapter:s,media:c,graph:a}}:{...n,errors:re(e,ke.name,"Could not find media"),actions:i}}}return{...n,errors:re(e,ke.name,"Could not find chapter"),actions:i}}var Ye=(i="",e="")=>{let t=i.split("."),n=e.split("."),r=0;for(let s=0;s<Math.max(t.length,n.length)&&!r;s++)t[s]>n[s]?r=1:t[s]<n[s]?r=-1:r=0;return r};var nn=async i=>{try{let e={},t;if(Ee(i)){t=new URL(i).href;let r=await fetch(t);if(!r.ok)return{};e=await r.json()}else if(ee(i))e=i;else return{};if(!Tt(e))return{};let n=e.metadata.media;if(Ee(n)&&!("media"in e))try{let r;t?r=new URL(n,t).href:(r=new URL(n).href,t=r);let s=await fetch(r);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return an(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function St(i){let{manifest:e,manifestURL:t}=await nn(i);if(!e)throw new Error("Failed on fetch");let n=xt(e);return n.media=rn(n.media,t),delete n.metadata.media,n}function Ve(i,e){if(e)return i.find(t=>t.id===e)}function Je(i,e){return i.edit?.chapters?i.edit.chapters.find(t=>t.id===e):i.view?.chapters?i.view.chapters.find(t=>t.id===e):void 0}function et(i,e){return i.videos.find(t=>t.id===e)}function rn(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{let r="url"in n?n.url:"",s=sn(r,e);return{...n,url:s||r}})}))}}function sn(i="",e){try{return new URL(i,e).href}catch{return""}}function an(i){return Ye(i,"3.2.0")>=0}var Pe=i=>Ie(i)&&!qe(i),F=i=>i.order==="end",$e=i=>Ie(i.containers)&&!qe(i.containers)&&F(i),wt=(i,e)=>{let t=i*1e3;return Pe(e.controls)&&t<(e.startTime??0)},tt=(i,e)=>{let t=i*1e3;return Pe(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var Q=(i=[])=>i.some(e=>e.action.type==="expect"),nt=(i=[])=>i.find(e=>e.action.type==="expect"),on=i=>i?.length===1,q=i=>on(i)&&xe(i[0]);function At(i,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?i({...e[0],...t}):i(...e,...t)}var Rt=(i,e)=>Q(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&Q(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);var Y=class extends Me{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new ln(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:re},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await St(n.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",ke({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Je,getChapter:Ve,getMedia:et,getByBranches:this.getByBranches.bind(this),addErrorMessage:re},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let n=Ve(this.manifest.chapters,t);if(n){let r=et(this.manifest.media,n.videoId),s=Je(this.manifest.graph,n.id);if(r)return{chapter:n,media:r,graph:s}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=Ve(this.manifest?.chapters||[],t);return this.getByBranches(n?.branches)}}getByBranches(t=[]){return t.reduce((n,r)=>{let s=this.getByChapterId(r.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?F(this.chapter):!1}};import{Player as cn}from"@vkontakte/videoplayer-core/evergreen";import{Subscription as st,Tracer as pn,ValueSubject as hn}from"@vkontakte/videoplayer-shared/evergreen";var Mt=i=>{let e=i.variants.find(t=>t.payload?.type==="vk");if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};function it(){let i=new Map;function e({listId:s=Math.random().toString(),itemId:c=Math.random().toString(),...a}){let o=i.get(s),h={...a};return o?o[c]=h:i.set(s,{[c]:h}),{listId:s,itemId:c,...a}}function t(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,c){let a=i.get(s);if(!a)throw Error("Can't remove. Not find.");if(c){let o=a[c];o&&t(o),delete a[c],Object.keys(a).length||i.delete(s)}else{for(let o of Object.values(a))t(o);i.delete(s)}}function r(){for(let s of i)n(s[0])}return{createPlayer:e,removePlayer:n,map:i,removeAll:r}}function rt(i,e=[]){let t={},n,r=!e.length;for(let s of i.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(r||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(r||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(r||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(r||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:t,thumbUrl:n,title:i.title??""}}var se=(i,e)=>{let t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))};var un=2;function at(i){let e=it(),t=new st,n={},r=null,s=!1,c,a=new hn(null);i&&o(i);function o(C){r=C}function h(C,R,y){if(!r)throw Error("need to set interactive controller");if(!r.options)return;let p=(e.map.get(C)??{})[R];if(p){n={chapterId:y,listId:C,itemId:R,...p};let u=n.player;n.subscription.add(u.info.currentQuality$.subscribe(d=>{let m=u.info.position$.getValue(),A=u.info.isAutoQualityEnabled$.getValue();if(!(!d||!m||A))for(let E of e.map)Object.values(E[1]).forEach(({player:v})=>{se(v,d)})})).add(u.events.started$.subscribe(()=>{g(R)})),p.container.remove(),r.setPlayer(p.player),s||(r.init(),s=!0),a.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function g(C){if(!r)throw Error("need to set interactive controller");if(W(n)||C!==n.itemId)return;let R=r.getChapterBranches(),y=new Set;for(let l of R)y.has(l.media.id)||(await S({media:l.media,chapterId:l.chapter.id,setAsActive:!1,title:l.chapter.label}),y.add(l.media.id))}async function T({chapter:{id:C},manifestVideo:R}){if(W(n)||!r)return;let y=n.player.info.muted$.getValue(),l=n.player.info.currentQuality$.getValue(),p=n.player.info.isAutoQualityEnabled$.getValue(),u=n.player.info.volume$.getValue(),d=n.player.info.currentPlaybackRate$.getValue(),m=!p,A=!1;for(let E of e.map)if(E[0]===R.id&&!r.state.isReplay$.getValue()){let v=Object.keys(E[1]);for(let b of v)b===n.itemId?(v.length<un||(A=!0),e.removePlayer(E[0],b)):(A=!0,h(E[0],b,C),m?se(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(y),n.player.setPlaybackRate(d))}else e.removePlayer(E[0]);A||(await S({media:R,chapterId:C,setAsActive:!0,playbackRate:d}),m?se(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(y))}async function S({media:C,chapterId:R,prefetch:y=!0,setAsActive:l=!0,autoplay:p=!1,preferredExt:u,title:d,playbackRate:m}){let A=Math.random().toString(),E=document.createElement("div");c.append(E);let v;if(r?.options?.vkVideoLoader){let K=Mt(C);K.length&&(v=await r.options.vkVideoLoader(...K))}let b=r?.options?.coreConfig||void 0,B={...b,configName:[...b?.configName??[],"interactive"]},_={container:E,...v?.videos?.[0]||{sources:rt(C,u).sources},title:d,failoverHosts:v?.failoverHosts||[]},V=new cn(B,pn.createRootTracer());V.initVideo(_);let O=null;if(v?.videos&&r?.options.createOneStat){let K=v.videos[0],De=r.options.createOneStat(K),ht=new st;De&&(ht.add(De.attachTo(V)),O={oneStat:De,statSubscription:ht})}let G=new st,He=n?.player?.info.isAutoQualityEnabled$.getValue();G.add(V.events.canplay$.subscribe(function(){He||se(V,n.player.info.currentQuality$.getValue()),m&&V.setPlaybackRate(m)}));let j=e.createPlayer({listId:C.id,itemId:A,player:V,container:E,sources:rt(C,u).sources,config:_,subscription:G,statistics:O});return l&&h(C.id,j.itemId,R),p&&j.player.play(),y&&!p&&j.player.prepare(),{player:j.player,config:j.config,statistics:j.statistics}}function x(){N(),r=null,c.remove()}function N(){t.unsubscribe(),e.removeAll(),n={},s=!1}async function D(){if(!r)throw Error("need to set interactive controller");N(),c=document.createElement("div");let{media:C,chapter:R}=r.getCurrentChapter();C&&R?(t.add(r.events.chapterChanged$.subscribe(T)),await S({media:C,chapterId:R.id,title:R.label})):console.error("not found")}return{...e,init:D,setInteractiveController:o,createPlayer:S,removeAll:x,getActivePlayer:function(){return n},activePlayerChanged:a}}var f={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ae={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},w={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as dn}from"@vkontakte/videoplayer-shared/evergreen";var Le=class{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:s,globalEvents:c,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:h,disabledControls$:g,onRemove:T}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(Q(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState===2&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.emitContainerVisibilityEvent(!0,!1);else{let t=At(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.emitContainerVisibilityEvent(!1)),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.emitContainerVisibilityEvent(!1))},isEOV:()=>this.gameState===4});this.container.createView(t),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,r=[6,5];if(!n||r.includes(this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(wt(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(tt(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let h=this.gameState;this.gameState=3,h===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let c=tt(s,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:s,isInteractiveTime:c};this.globalEventEmitter.emit(f.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new dn,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=h&&q(t.container.controls),this.disabledControls$=g,this.onRemove=T,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=c,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(f.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.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(f.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||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 e=Q(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(f.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}destroy(){this.reset(),this.removeView(),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 Vt=(i=[])=>i.reduce((e,t,n)=>{let r=(t?.controls??[]).filter(s=>!xe(s));if(Pe(r)){let s=[t.startTime??0,t.endTime??1/0],c=t.id;if(!n)e.push({subjects:[c],range:s});else{let a=[],o=-1/0,h=1/0,g=[],T=[];for(let S=0;S<e.length;S++){let x=e[S];if(T.push(...x.subjects),x.range[0]<h&&(h=x.range[0]),x.range[1]>o&&(o=x.range[1]),s[0]>=x.range[0]&&s[1]<=x.range[1])return e[S].subjects.push(c),e;s[0]<x.range[0]&&s[1]>x.range[0]&&(a.push(S),g=g.concat(x.subjects)),s[0]>=x.range[0]&&s[0]<=x.range[1]&&(a.push(S),g=g.concat(x.subjects),s[0]=x.range[0]),s[1]>=x.range[0]&&s[1]<=x.range[1]&&(a.push(S),g=g.concat(x.subjects),s[1]=x.range[1])}if(T.push(c),s[0]<=h&&s[1]>=o)return[{subjects:T,range:s}];a.length&&a.reverse().forEach(S=>{e.splice(S,1)}),e.push({subjects:g.concat([c]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Pt(){let i={};function e(){for(let a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a]}function t(a){let o={};for(let h in i)+h<=a&&(o[h]=i[h]);return o}function n(a){let o={};for(let h in i)+h>=a&&(o[h]=i[h]);return o}function r({timestamp:a,priority:o,initiator:h}){if(Ze(a)){let g=i[a]??null;if(g&&o&&te(o,!0)){let T={},S=g[o];return S&&(T={...T,...S}),T=W(T)?null:T,T&&te(h,!0)?T[h]??null:T}return g}return null}function s({timestamp:a,priority:o,initiator:h}){if(Ze(a))if(i[a]){if(o&&te(o,!0))if(i[a][o]){if(h&&te(h,!0))if(i[a][o][h]){if(delete i[a][o][h],!W(i[a][o]))return!0}else return!1;if(delete i[a][o],!W(i[a]))return!0}else return!1;return delete i[a]}else return!1;return!1}function c({timestamp:a,priority:o,initiator:h,...g}){i[a]?.[o]?.[h]?i[a][o][h].push({...g}):i[a]?.[o]?i[a][o]={...i[a][o],[h]:[{...g}]}:i[a]?i[a]={...i[a],[o]:{[h]:[{...g}]}}:i[a]={[o]:{[h]:[{...g}]}}}return{map:i,remove:s,add:c,removeAll:e,get:r,getLte:t,getGte:n}}var mn=[I.expect,I.setNextBranch],fn=1/0;function $t(i){let e=i,t,n=yn(),r=Pt(),s,c=()=>{S(),R()},a=y=>{r.add.call(void 0,y),N()},o=(y=[])=>{for(let l of y)if(l.action(),mn.includes(l.actionType))break},h=(y=1/0)=>{let l=Ne(r.get({timestamp:y,priority:"control"})??{}),p=Ne(r.get({timestamp:y,priority:"container"})??{}),u=Ne(r.get({timestamp:y,priority:"chapter"})??{});return[...l,...p,...u]},g=y=>{n.isReady(y)&&o(h(y))},T=()=>{o([...Ne(r.get({timestamp:1/0,priority:"chapter"})??{})])},S=()=>{t&&(s?.unsubscribe(),t=void 0)},x=y=>{},N=()=>{t||(t=()=>setTimeout(()=>{g(1/0)}),s=e.events.ended$.subscribe(t))},D=y=>{S(),e=y},C=y=>{y.priority==="container"&&n.resetCalled(y.timestamp),r.remove(y)},R=()=>{n.release(),r.removeAll()};return{setPlayer:D,add:a,remove:C,exec:g,execEndOfVideo:T,listen:N,unlisten:S,release:c,containersEventsCallState:n,getPreparedToExecActions:h}}function yn(){let i=new Map;return{setCalled:({timestamp:c,id:a})=>{let o=i.get(c);o&&o[a]!==void 0&&(o[a]=!0)},setData:(c=[])=>{for(let a of c){let o=a.endTime??fn,h=i.get(o)??{};i.set(o,{...h,[a.id]:!1})}},resetCalled:c=>{let a=i.get(c);if(a)for(let o in a)a[o]=!1},isReady:c=>{let a=i.get(c);return a?!Object.values(a).some(o=>!o):!0},release:()=>i.clear()}}function Ne(i){return Object.values(i).flat().sort(e=>e.actionType===I.expect?-1:1)}var Lt={videoContentHeight:0,videoContentWidth:0},Nt=(i,e)=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return Lt;let{clientHeight:r,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(r&&s))return Lt;let c=t/n,a=r/s,o,h;return a>c?(h=s,o=s*c):a<c?(h=r/c,o=r):(h=s,o=r),{videoContentWidth:h,videoContentHeight:o}};var vn=250;function Ot(i){let e=()=>{},t=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){let{parentElement:o,player:h}=i();if(o&&h){let{videoContentWidth:g,videoContentHeight:T}=Nt(o,h);o.style.setProperty("--interactive-content-width",`${g}px`),o.style.setProperty("--interactive-content-height",`${T}px`),o.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function r(){let{parentElement:a}=i();a.removeAttribute("style")}let s=J(a=>{let{fns:o=[]}=i();n(a);for(let h of o)h()},vn);function c(){e=void 0,t.disconnect(),r()}return{resizeObserver:t,calc:()=>{e?.()},release:c}}var oe=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var gn=i=>Math.floor(Math.random()*i),Ft=i=>{let e=i.length,t=1/0,n=null;for(;e--;){let r=i[e],s=r.weight??1;s<t&&(t=s,n=r)}return n},Bt=i=>{let e=i.length,t=-1/0,n=null;for(;e--;){let r=i[e],s=r.weight??0;s>t&&(t=s,n=r)}return n};var _t=i=>{let e=i.length,t=gn(e);return i[t]},jt=1,Ht=i=>{let e=0;for(let n=0;n<i.length;++n)e+=i[n].weight??jt;let t=Math.random()*e;e=0;for(let n=0;n<i.length-1;++n)if(e+=i[n].weight??jt,e>=t)return i[n];return i[i.length-1]};var Dt={shouldOpenNow:!0,isDetachContainer:!0},Gt="after-expect";var ot=(i,e=!1)=>({...i,args:e?{...i.args,...Dt}:{...Dt,...i.args}}),Wt=({globalEventEmitter:i,globalEvents:e,player:t,interactiveEvents:n,removeControllers:r})=>{let s={isExpect:!1},c=()=>{s.isExpect&&(s.isExpect=!1)},a=({action:l,controlType:p,controlId:u,containerId:d,branches:m=[],onEvent:A,isEOV:E=()=>!1,isDisabled:v=()=>!1})=>{let b=ot(l,E()),B={timestamp:1/0,priority:"control",initiator:u,actionType:b.type},_=v(),V=i.emit.bind(i,f.interactives,{subjectId:u,subjectType:p,subjectName:"control",type:_?w.actionChoiceCanceled:w.actionChoice,actionType:l.type,payload:{containerId:d,...b.args}}),O=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectType:p,subjectName:"control",type:_?"action-choice-canceled":"action-choice",actionType:l.type,payload:{containerId:d,...b.args}})};if(_){V(),O();return}switch(b.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let j=m.find(K=>K.id===b.args.branchId);if(!j)return;A(b.args.isDetachContainer,N.bind(null,{subjectId:u,subjectName:"control"})),V(),O(),b.args.shouldOpenNow?C({subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}}):(n.add({...B,action:C.bind(null,{subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}})}),r?.());return}case I.continuePlayback.trim().toLowerCase():{A(b.args.isDetachContainer,N.bind(null,{subjectId:u,subjectName:"control"})),V(),O(),b.args.shouldOpenNow?D({subjectId:u,subjectName:"control",subjectType:p,action:l}):n.add({...B,action:D.bind(null,{subjectId:u,subjectName:"control",subjectType:p,action:l})});return}case I.openURI.trim().toLowerCase():{A(b.args.isDetachContainer,N.bind(null,{subjectId:u,subjectName:"control"})),V(),O(),b.args.shouldOpenNow?y({subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{URI:l.args.uri}}):(n.add({...B,action:y.bind(null,{subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{URI:l.args.uri}})}),r?.());return}default:let G="Unexpected control event",He=new M(1,1,{message:G});T(He,G);return}},o=({action:l,container:{id:p,endTime:u},branches:d=[],isEOV:m=!1,autoSelected:A=!1})=>{let E=ot(l,m),v={timestamp:!E.args.shouldOpenNow||m?1/0:u??1/0,priority:"container",initiator:p,actionType:E.type},b=i.emit.bind(i,f.interactives,{subjectId:p,subjectName:"container",type:w.actionChoice,actionType:E.type,payload:E.args}),B=()=>{e.interactiveActionChoice$.next({subjectId:p,subjectName:"container",type:"action-choice",actionType:E.type,payload:E.args})};switch(E.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let O=d.find(G=>G.id===E.args.branchId);if(!O)return;b(),B(),n.add({...v,action:C.bind(null,{subjectId:p,subjectName:"container",action:E,payload:{chapterId:O.chapterId,autoSelect:A}})}),r?.();return}case I.setMaxWeightBranch.trim().toLowerCase():return;case I.setMinWeightBranch.trim().toLowerCase():return;case I.setRandomBranch.trim().toLowerCase():return;case I.setWeightlessRandomBranch.trim().toLowerCase():return;case I.continuePlayback.trim().toLowerCase():{b(),B(),n.add({...v,action:D.bind(null,{subjectId:p,subjectName:"container",action:E})});return}case I.openURI.trim().toLowerCase():{b(),B(),n.add({...v,action:y.bind(null,{subjectId:p,subjectName:"container",action:E,payload:{URI:l.args.uri}})}),r?.();return}default:let _="Unexpected container event",V=new M(1,1,{message:_});T(V,_);return}};function h({container:l,branches:p,isEOV:u=!1}){let d=nt(l.events);if(d){let m=ot(d.action,u);i.emit(f.interactives,{subjectId:l.id,subjectName:"container",type:w.actionChoice,actionType:m.type,payload:m.args}),e.interactiveActionChoice$.next({subjectId:l.id,subjectName:"container",type:"action-choice",actionType:m.type,payload:m.args}),n.add({timestamp:u?1/0:l.endTime??1/0,priority:"container",initiator:l.id,actionType:I.expect,action:x.bind(null,{subjectId:l.id,subjectName:"container"})}),s.isExpect=!0}else for(let m of l.events??[])o({action:m.action,container:l,branches:p,isEOV:u})}let g=({chapterId:l,action:p,branches:u=[]})=>{let d=i.emit.bind(i,f.interactives,{subjectId:l,subjectName:"chapter",type:w.actionChoice,actionType:p.type,payload:p.args}),m=()=>{e.interactiveActionChoice$.next({subjectId:l,subjectName:"chapter",type:"action-choice",actionType:p.type,payload:p.args})};switch(p.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let v=u.find(b=>b.id===p.args.branchId);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let v=_t(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let v=Ht(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let v=Bt(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let v=Ft(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return d(),m(),D.bind(null,{subjectId:l,subjectName:"chapter",action:p});case I.openURI.trim().toLowerCase():return d(),m(),y.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:let A="Unexpected chapter event",E=new M(1,1,{message:A});T(E,A);return}};function T(l,p){console.error(p),e.error$.next(l),i.emit(f.errors,l)}function S(l){let p=nt(l.events);if(p){if(F(l))return;i.emit(f.interactives,{subjectId:l.id,subjectName:"chapter",type:w.actionChoice,actionType:p.action.type,payload:p.action.args}),e.interactiveActionChoice$.next({subjectId:l.id,subjectName:"chapter",type:"action-choice",actionType:p.action.type,payload:p.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:l.id,actionType:I.expect,action:x.bind(null,{subjectId:l.id,subjectName:"chapter"})})}else l.events?.forEach(u=>{let d=g({chapterId:l.id,action:u.action,branches:l.branches});d&&n.add({timestamp:1/0,priority:"chapter",initiator:l.id,actionType:u.action.type,action:d})})}let x=({subjectId:l,subjectName:p})=>{t.pause(),i.emit(f.interactives,{subjectId:l,subjectName:p,type:w.actionExecution,actionType:I.expect}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,type:"action-execution",actionType:I.expect})},N=({subjectId:l,subjectName:p})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),i.emit(f.interactives,{subjectId:l,subjectName:p,type:w.actionExecution,actionType:Gt}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,type:"action-execution",actionType:Gt})},D=({subjectId:l,subjectName:p,subjectType:u,action:d})=>{i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type})},C=({subjectId:l,subjectName:p,subjectType:u,action:d,payload:m})=>{m.behaviour="change-chapter",i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type,payload:m}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type,payload:m})},R=({subjectId:l,subjectName:p,subjectType:u,action:d,payload:m})=>{m.behaviour="change-manifest",i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type,payload:m}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type,payload:m})},y=({subjectId:l,subjectName:p,subjectType:u,action:d,payload:m})=>{if(!m.URI)return;let A=window.open(m.URI,"_blank","noopener,noreferrer");A&&(A.opener=null),i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type})};return{onControlEvent:a,onContainerEvent:o,onChapterEvent:g,onExpectEvent:x,expectEventHandler:N,setManifestChapterEvents:S,setManifestContainerEvents:h,stopExpect:c,state:s}};import{Subscription as Tn,Subject as ct,ValueSubject as le}from"@vkontakte/videoplayer-shared/evergreen";var lt=(i,e)=>{let t={};return i.map(n=>{if(!t[n]){let r=e.chapters.find(c=>c.id===n);if(!r)return null;let s=e.media.videos.find(c=>r.videoId===c.id);if(!s)return null;t[n]=Qt(s)}return t[n]}).filter(Boolean)},bn=i=>{for(let e of i.variants)if(En(e)&&e.payload)return e.payload.id},En=i=>!!(i.type==="custom"&&i.payload&&i.payload.type==="vk"),Qt=i=>{let e=bn(i);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},In=(i,e)=>{for(let t of i.media.videos)if(e===Qt(t)){for(let n of i.chapters)if(n.videoId===t.id)return n.id;return}},Kt=(i,e)=>i.reduce((t,n)=>{let r=In(e,n);return r?[...t,r]:t},[]);var ce=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new le([]),hasPrevChapter$:new le(!1),prevChapter$:new le(null),isInitialChapter$:new le(!1),isGoBackLimited$:new le(!1)};this.#n=null;this.#a=!1;this.#e=null;this.#p=null;this.events={inited$:new ct,destroyed$:new ct,error$:new ct};this.#i=null;this.#r=null;this.#t=null;this.#o=new Tn;this.#l=!1;this.#c=0;this.#i=t,this.#t=e,this.#r=n,this.#n=r,this.#s=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(c=>{this.state.prevChapter$.next(c.at(-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#s.maxLength-1)}))}#n;#s;#a;#e;#p;#i;#r;#t;#o;#l;#c;async setManifest(e){if(!this.#r||!this.#t)return;this.#e=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#r.setChapter({chapterId:t,pushToHistory:!1}),this.#a||(this.#a=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#a}async updateHistory(e,t=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,r=e.length-this.#s.maxLength,s=r>0?e.slice(r):e,c=lt(s,n);if(this.#p=c,this.state.history$.next(s),!(!t||!this.#n||!this.#i))try{await this.#n.save(this.#i,c)}catch{let o=new M(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#t?.emit(f.errors,o)}}async goBack(){if(!this.state||!this.#r){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#t?.emit(f.errors,n)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#r.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#i)return;let e=this.#e,t=[this.getInitialVideoId()];if(this.#n)try{let r=await this.#n.get(this.#i);r.length&&(t=r)}catch{let s=new M(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#t?.emit(f.errors,s)}let n=Kt(t,e);this.state.history$.next(n)}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||this.#s.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return lt([e],this.#e).pop()}return null}destroy(){this.#i=null,this.#n=null,this.#r=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#t?.emit(f.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var Oe=class i{constructor(e,t,n,r){this.target=e,this.type=t,this.listener=n,this.options=i._convertOptions(e,r),this.target.addEventListener(t,n,this.options)}unlisten(){this.type&&this.listener&&this.options&&this.target?.removeEventListener(this.type,this.listener,this.options),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let n=new Set(["passive","capture"]),r=Object.keys(t).filter(c=>!n.has(c));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),i._doesSupportObject(e)?t:t.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(e){let t=i._supportsObject;if(t===void 0){t=!1;try{let n={},r={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);let s=()=>{};e.addEventListener("test",s,n),e.removeEventListener("test",s,n)}catch{t=!1}i._supportsObject=t}return t||!1}};var je=class{constructor(){this.bindingMap=new oe}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,r){if(!this.bindingMap)return;let s=new Oe(e,t,n,r);this.bindingMap.push(t,s)}listenOnce(e,t,n,r){let s=c=>{this.unlisten(e,t,s),n(c)};this.listen(e,t,s,r)}unlisten(e,t,n){if(!this.bindingMap)return;let r=this.bindingMap.get(t)||[];for(let s of r)s.target===e&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var Fe=class{constructor(){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 r=3;r<n;r+=40)if(t[r]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var Be=class{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;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
+ var ut="1.0.30-dev.954af6ed.0";function Ge(i,e=1){let t="0",n="0",r="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+r},${e})`}var P="interactive",Yt="interactive-controls-container",he=()=>document.querySelector(`.${Yt}`),dt=.4,k={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},mt=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(mt||{}),ft=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(ft||{}),yt=(n=>(n.start="left",n.end="right",n.center="center",n))(yt||{}),ue=({target:i,props:e})=>{i.style.alignItems=(e?.gravityVertical&&mt[e.gravityVertical])??"center",i.style.justifyContent=(e?.gravityHorizontal&&ft[e.gravityHorizontal])??"center",i.style.textAlign=(e?.alignment&&yt[e.alignment])??"left"},de=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.color=e?.text?.color??t.textColor,i.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,i.textContent=e?.text?.value??t.textContent},me=({target:i,props:e,fallback:t})=>{i.style.backgroundColor=Ge(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},fe=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth}) solid ${Ge(e?.shape?.border?.color??t.borderColor,e?.shape?.border?.alpha??t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`},X=({target:i,layoutParams:e,fallback:t})=>{let n=e.angle??t.angle;n=n&&n*-1,i.style.transform=`rotate(${n}rad)`};var H=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let t=document.createElement("div");t.classList.add(`${P}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??k.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:t,dimensions:n}}createClickListener(e){return t=>{t.stopPropagation(),e()}}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var Ue="int",U=(n=>(n.AREA=`${Ue}_area`,n.TEXT=`${Ue}_text`,n.BUTTON=`${Ue}_bttn`,n))(U||{});var ye=i=>{if(i.type.trim().toLowerCase()==="area")return new ze(i)},ze=class extends H{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",U.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",me({target:n,props:this.control.props,fallback:{...k,backgroundColor:"transparent"}}),fe({target:n,props:this.control.props,fallback:{...k,borderAlpha:0},dependsOn:this.container.dimensions}),X({target:n,layoutParams:this.control.layoutParams,fallback:k}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var ve=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var ge=i=>{if(i.type.trim().toLowerCase()==="button")return new We(i)},We=class extends H{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",U.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",X({target:n,layoutParams:this.control.layoutParams,fallback:k}),me({target:n,props:this.control.props,fallback:k}),fe({target:n,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),ue({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=ve();de({target:r,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var vt=i=>{if(i.type.trim().toLowerCase()==="text")return new Qe(i)},Qe=class extends H{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",U.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",X({target:n,layoutParams:this.control.layoutParams,fallback:k}),ue({target:n,props:{...this.control.props.text,alignment:this.control.layoutParams.alignment}});let r=ve();de({target:r,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){}enable(){}getElement(){return this.controlElement}};var Ke=class{constructor(e){this.layout=e}},Ce=class extends Ke{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var Z=class{constructor(e){this.container=e,this.factories=new Map,this.controls=[],this.setControls()}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 s=r(t);if(s)return[...e,s]}return[...e]},[])||[]}};var be=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new Xe(i,e)},Xe=class extends Z{constructor(e,t){super(e),this.rootElement=t??he(),this.layout=new Ce(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ge),this.addControlFactory("text",vt),this.addControlFactory("area",ye)}createView(e){let t=document.createElement("div");return t.classList.add(`${P}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{n.createView({parentElement:t,layoutCallback:this.layout.setControlLayout}),n.setEvents(e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity="1",this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=`${dt}`,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${P}-${this.container.id}`)}};import{clientChecker as xn,combine as Sn,InterfaceLanguage as wn,Observable as Zt,once as An,Subject as $,Subscription as pt,ValueSubject as L}from"@vkontakte/videoplayer-shared/evergreen";import{InteractiveInterfaceClick as pe}from"@vkontakte/videoplayer-statistics/evergreen";import{loadVKLangPack as Jt}from"@vkontakte/videoplayer-shared/evergreen";function J(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}var z=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,ee=i=>z(i,"Object"),Ee=i=>z(i,"String"),Ie=i=>z(i,"Array"),Te=i=>z(i,"Number"),gt=i=>z(i,"Function");var Ze=i=>Te(i)&&!isNaN(i);var W=i=>ee(i)&&Object.keys(i).length===0,qe=i=>Ie(i)&&!i.length;var te=(i,e)=>Ee(i)&&(e?i.trim():i).length;var Ct="video_interactive",bt="videoint";var Et=250,ne=class{constructor(e){this.handleZoomChange=J(e=>{this.lastZoomInfo=e},Et);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),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?.("Id is not found"),console.error("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,!Te(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph"),console.error("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.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=en(e),this.resizeObserver=new ResizeObserver(J(this.onResize,Et)),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)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await Jt(this.lang,Ct,bt)}catch{console.log("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:n,...r})=>{n==="openPreview"&&"chapterId"in r&&this.onOpenPreviewClick?.(r.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function en(i){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",i.append(e),e}var ie=class{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=3e3)=>{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 s of this._containers){let c=s.startTime-e;if(c<=r&&(s.endTime&&r<=s.endTime||s.endTime===null)){n=!0;break}r<c&&(t=t===-1?c:Math.min(t,c))}return!n&&t!==-1?t:null}}};import{isSupportedManifest as Se,ContainerTypes as _i,ControlTypes as we,EventActionTypes as I,EventTypes as Hi,migrateManifestToLatestVersion as xt,compareVersions as Di}from"@interactiveplatform/movika-manifest";var It={metadata:"Object",chapters:"Array"},Tt=i=>{if(!ee(i))return!1;for(let e in It)if(!i[e]||!z(i[e],It[e]))return!1;return Se(i.metadata.version)},xe=i=>i.type===we.Text,Vi=i=>i.type===we.Button,Pi=i=>i.type===we.Area,$i={Choice:"Choice",TextInput:"TextInput"},Li={Button:"Button",Area:"Area",Text:"Text"},Ni={onClick:"onClick",onSuspense:"onSuspense"},Oi={openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"};var M=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var Ae=class{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 r=n.length;r>0;r--)if(n[r]===t){n.splice(r,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(r=>{r(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Re=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{gt(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==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),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as ln}from"@vkontakte/videoplayer-shared/evergreen";var Me=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return tn(...this.loaders[e])(t)}};function tn(...i){return async function(t){let n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function re(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function ke({actions:i,errors:e,chapterId:t,...n}){if(t){let r=i.getManifest(),s=i.getChapter(r.chapters,t);if(s){let c=i.getMedia(r.media,s.videoId),a=i.getGraph(r.graph,s.id);return c?{...n,actions:i,errors:e,result:{chapter:s,media:c,graph:a}}:{...n,errors:re(e,ke.name,"Could not find media"),actions:i}}}return{...n,errors:re(e,ke.name,"Could not find chapter"),actions:i}}var Ye=(i="",e="")=>{let t=i.split("."),n=e.split("."),r=0;for(let s=0;s<Math.max(t.length,n.length)&&!r;s++)t[s]>n[s]?r=1:t[s]<n[s]?r=-1:r=0;return r};var nn=async i=>{try{let e={},t;if(Ee(i)){t=new URL(i).href;let r=await fetch(t);if(!r.ok)return{};e=await r.json()}else if(ee(i))e=i;else return{};if(!Tt(e))return{};let n=e.metadata.media;if(Ee(n)&&!("media"in e))try{let r;t?r=new URL(n,t).href:(r=new URL(n).href,t=r);let s=await fetch(r);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return an(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function St(i){let{manifest:e,manifestURL:t}=await nn(i);if(!e)throw new Error("Failed on fetch");let n=xt(e);return n.media=rn(n.media,t),delete n.metadata.media,n}function Ve(i,e){if(e)return i.find(t=>t.id===e)}function Je(i,e){return i.edit?.chapters?i.edit.chapters.find(t=>t.id===e):i.view?.chapters?i.view.chapters.find(t=>t.id===e):void 0}function et(i,e){return i.videos.find(t=>t.id===e)}function rn(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{let r="url"in n?n.url:"",s=sn(r,e);return{...n,url:s||r}})}))}}function sn(i="",e){try{return new URL(i,e).href}catch{return""}}function an(i){return Ye(i,"3.2.0")>=0}var Pe=i=>Ie(i)&&!qe(i),F=i=>i.order==="end",$e=i=>Ie(i.containers)&&!qe(i.containers)&&F(i),wt=(i,e)=>{let t=i*1e3;return Pe(e.controls)&&t<(e.startTime??0)},tt=(i,e)=>{let t=i*1e3;return Pe(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var Q=(i=[])=>i.some(e=>e.action.type==="expect"),nt=(i=[])=>i.find(e=>e.action.type==="expect"),on=i=>i?.length===1,q=i=>on(i)&&xe(i[0]);function At(i,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?i({...e[0],...t}):i(...e,...t)}var Rt=(i,e)=>Q(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&Q(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);var Y=class extends Me{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new ln(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:re},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await St(n.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",ke({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Je,getChapter:Ve,getMedia:et,getByBranches:this.getByBranches.bind(this),addErrorMessage:re},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let n=Ve(this.manifest.chapters,t);if(n){let r=et(this.manifest.media,n.videoId),s=Je(this.manifest.graph,n.id);if(r)return{chapter:n,media:r,graph:s}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=Ve(this.manifest?.chapters||[],t);return this.getByBranches(n?.branches)}}getByBranches(t=[]){return t.reduce((n,r)=>{let s=this.getByChapterId(r.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?F(this.chapter):!1}};import{Player as cn}from"@vkontakte/videoplayer-core/evergreen";import{Subscription as st,Tracer as pn,ValueSubject as hn}from"@vkontakte/videoplayer-shared/evergreen";var Mt=i=>{let e=i.variants.find(t=>t.payload?.type==="vk");if(e&&e.payload){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};function it(){let i=new Map;function e({listId:s=Math.random().toString(),itemId:c=Math.random().toString(),...a}){let o=i.get(s),h={...a};return o?o[c]=h:i.set(s,{[c]:h}),{listId:s,itemId:c,...a}}function t(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,c){let a=i.get(s);if(!a)throw Error("Can't remove. Not find.");if(c){let o=a[c];o&&t(o),delete a[c],Object.keys(a).length||i.delete(s)}else{for(let o of Object.values(a))t(o);i.delete(s)}}function r(){for(let s of i)n(s[0])}return{createPlayer:e,removePlayer:n,map:i,removeAll:r}}function rt(i,e=[]){let t={},n,r=!e.length;for(let s of i.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(r||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(r||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(r||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(r||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:t,thumbUrl:n,title:i.title??""}}var se=(i,e)=>{let t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))};var un=2;function at(i){let e=it(),t=new st,n={},r=null,s=!1,c,a=new hn(null);i&&o(i);function o(C){r=C}function h(C,R,y){if(!r)throw Error("need to set interactive controller");if(!r.options)return;let p=(e.map.get(C)??{})[R];if(p){n={chapterId:y,listId:C,itemId:R,...p};let u=n.player;n.subscription.add(u.info.currentQuality$.subscribe(d=>{let m=u.info.position$.getValue(),A=u.info.isAutoQualityEnabled$.getValue();if(!(!d||!m||A))for(let E of e.map)Object.values(E[1]).forEach(({player:v})=>{se(v,d)})})).add(u.events.started$.subscribe(()=>{g(R)})),p.container.remove(),r.setPlayer(p.player),s||(r.init(),s=!0),a.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function g(C){if(!r)throw Error("need to set interactive controller");if(W(n)||C!==n.itemId)return;let R=r.getChapterBranches(),y=new Set;for(let l of R)y.has(l.media.id)||(await S({media:l.media,chapterId:l.chapter.id,setAsActive:!1,title:l.chapter.label}),y.add(l.media.id))}async function T({chapter:{id:C},manifestVideo:R}){if(W(n)||!r)return;let y=n.player.info.muted$.getValue(),l=n.player.info.currentQuality$.getValue(),p=n.player.info.isAutoQualityEnabled$.getValue(),u=n.player.info.volume$.getValue(),d=n.player.info.currentPlaybackRate$.getValue(),m=!p,A=!1;for(let E of e.map)if(E[0]===R.id&&!r.state.isReplay$.getValue()){let v=Object.keys(E[1]);for(let b of v)b===n.itemId?(v.length<un||(A=!0),e.removePlayer(E[0],b)):(A=!0,h(E[0],b,C),m?se(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(y),n.player.setPlaybackRate(d))}else e.removePlayer(E[0]);A||(await S({media:R,chapterId:C,setAsActive:!0,playbackRate:d}),m?se(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(y))}async function S({media:C,chapterId:R,prefetch:y=!0,setAsActive:l=!0,autoplay:p=!1,preferredExt:u,title:d,playbackRate:m}){let A=Math.random().toString(),E=document.createElement("div");c.append(E);let v;if(r?.options?.vkVideoLoader){let K=Mt(C);K.length&&(v=await r.options.vkVideoLoader(...K))}let b=r?.options?.coreConfig||void 0,B={...b,configName:[...b?.configName??[],"interactive"]},_={container:E,...v?.videos?.[0]||{sources:rt(C,u).sources},title:d,failoverHosts:v?.failoverHosts||[]},V=new cn(B,pn.createRootTracer());V.initVideo(_);let O=null;if(v?.videos&&r?.options.createOneStat){let K=v.videos[0],De=r.options.createOneStat(K),ht=new st;De&&(ht.add(De.attachTo(V)),O={oneStat:De,statSubscription:ht})}let G=new st,He=n?.player?.info.isAutoQualityEnabled$.getValue();G.add(V.events.canplay$.subscribe(function(){He||se(V,n.player.info.currentQuality$.getValue()),m&&V.setPlaybackRate(m)}));let j=e.createPlayer({listId:C.id,itemId:A,player:V,container:E,sources:rt(C,u).sources,config:_,subscription:G,statistics:O});return l&&h(C.id,j.itemId,R),p&&j.player.play(),y&&!p&&j.player.prepare(),{player:j.player,config:j.config,statistics:j.statistics}}function x(){N(),r=null,c.remove()}function N(){t.unsubscribe(),e.removeAll(),n={},s=!1}async function D(){if(!r)throw Error("need to set interactive controller");N(),c=document.createElement("div");let{media:C,chapter:R}=r.getCurrentChapter();C&&R?(t.add(r.events.chapterChanged$.subscribe(T)),await S({media:C,chapterId:R.id,title:R.label})):console.error("not found")}return{...e,init:D,setInteractiveController:o,createPlayer:S,removeAll:x,getActivePlayer:function(){return n},activePlayerChanged:a}}var f={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ae={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},w={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as dn}from"@vkontakte/videoplayer-shared/evergreen";var Le=class{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:s,globalEvents:c,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:h,disabledControls$:g,onRemove:T}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(Q(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.emitContainerVisibilityEvent(!1)))})};this.show=()=>{if(this.gameState===2&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.emitContainerVisibilityEvent(!0,!1);else{let t=At(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.emitContainerVisibilityEvent(!1)},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.emitContainerVisibilityEvent(!1)),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.emitContainerVisibilityEvent(!1))},isEOV:()=>this.gameState===4});this.container.createView(t),this.emitContainerVisibilityEvent(!0,!0),this.disabledControls$.getValue()&&this.container.disable?.()}};this.onEndOfVideo=()=>{this.gameState=4,this.selectContainerEvent(!0)};this.whilePlaying=()=>{let e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,r=[6,5];if(!n||r.includes(this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(wt(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(tt(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let h=this.gameState;this.gameState=3,h===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let c=tt(s,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:s,isInteractiveTime:c};this.globalEventEmitter.emit(f.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new dn,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=h&&q(t.container.controls),this.disabledControls$=g,this.onRemove=T,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=c,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}emitContainerVisibilityEvent(e,t=!1){e?(this.globalEventEmitter.emit(f.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.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(f.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1}),this.globalEvents.interactiveVisibilityChanged$.next({subjectId:this.container.container.id,subjectName:"container",type:"visibility",visibility:e}))}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||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 e=Q(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.emitContainerVisibilityEvent(!1)}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(f.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.containerRemoved,visibility:!1}),this.globalEvents.interactiveContainerRemoved$.next({subjectId:this.container.container.id,subjectName:"container",type:"container-removed"}),this.gameState=5,this.onRemove?.()}destroy(){this.reset(),this.removeView(),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 Vt=(i=[])=>i.reduce((e,t,n)=>{let r=(t?.controls??[]).filter(s=>!xe(s));if(Pe(r)){let s=[t.startTime??0,t.endTime??1/0],c=t.id;if(!n)e.push({subjects:[c],range:s});else{let a=[],o=-1/0,h=1/0,g=[],T=[];for(let S=0;S<e.length;S++){let x=e[S];if(T.push(...x.subjects),x.range[0]<h&&(h=x.range[0]),x.range[1]>o&&(o=x.range[1]),s[0]>=x.range[0]&&s[1]<=x.range[1])return e[S].subjects.push(c),e;s[0]<x.range[0]&&s[1]>x.range[0]&&(a.push(S),g=g.concat(x.subjects)),s[0]>=x.range[0]&&s[0]<=x.range[1]&&(a.push(S),g=g.concat(x.subjects),s[0]=x.range[0]),s[1]>=x.range[0]&&s[1]<=x.range[1]&&(a.push(S),g=g.concat(x.subjects),s[1]=x.range[1])}if(T.push(c),s[0]<=h&&s[1]>=o)return[{subjects:T,range:s}];a.length&&a.reverse().forEach(S=>{e.splice(S,1)}),e.push({subjects:g.concat([c]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function Pt(){let i={};function e(){for(let a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a]}function t(a){let o={};for(let h in i)+h<=a&&(o[h]=i[h]);return o}function n(a){let o={};for(let h in i)+h>=a&&(o[h]=i[h]);return o}function r({timestamp:a,priority:o,initiator:h}){if(Ze(a)){let g=i[a]??null;if(g&&o&&te(o,!0)){let T={},S=g[o];return S&&(T={...T,...S}),T=W(T)?null:T,T&&te(h,!0)?T[h]??null:T}return g}return null}function s({timestamp:a,priority:o,initiator:h}){if(Ze(a))if(i[a]){if(o&&te(o,!0))if(i[a][o]){if(h&&te(h,!0))if(i[a][o][h]){if(delete i[a][o][h],!W(i[a][o]))return!0}else return!1;if(delete i[a][o],!W(i[a]))return!0}else return!1;return delete i[a]}else return!1;return!1}function c({timestamp:a,priority:o,initiator:h,...g}){i[a]?.[o]?.[h]?i[a][o][h].push({...g}):i[a]?.[o]?i[a][o]={...i[a][o],[h]:[{...g}]}:i[a]?i[a]={...i[a],[o]:{[h]:[{...g}]}}:i[a]={[o]:{[h]:[{...g}]}}}return{map:i,remove:s,add:c,removeAll:e,get:r,getLte:t,getGte:n}}var mn=[I.expect,I.setNextBranch],fn=1/0;function $t(i){let e=i,t,n=yn(),r=Pt(),s,c=()=>{S(),R()},a=y=>{r.add.call(void 0,y),N()},o=(y=[])=>{for(let l of y)if(l.action(),mn.includes(l.actionType))break},h=(y=1/0)=>{let l=Ne(r.get({timestamp:y,priority:"control"})??{}),p=Ne(r.get({timestamp:y,priority:"container"})??{}),u=Ne(r.get({timestamp:y,priority:"chapter"})??{});return[...l,...p,...u]},g=y=>{n.isReady(y)&&o(h(y))},T=()=>{o([...Ne(r.get({timestamp:1/0,priority:"chapter"})??{})])},S=()=>{t&&(s?.unsubscribe(),t=void 0)},x=y=>{},N=()=>{t||(t=()=>setTimeout(()=>{g(1/0)}),s=e.events.ended$.subscribe(t))},D=y=>{S(),e=y},C=y=>{y.priority==="container"&&n.resetCalled(y.timestamp),r.remove(y)},R=()=>{n.release(),r.removeAll()};return{setPlayer:D,add:a,remove:C,exec:g,execEndOfVideo:T,listen:N,unlisten:S,release:c,containersEventsCallState:n,getPreparedToExecActions:h}}function yn(){let i=new Map;return{setCalled:({timestamp:c,id:a})=>{let o=i.get(c);o&&o[a]!==void 0&&(o[a]=!0)},setData:(c=[])=>{for(let a of c){let o=a.endTime??fn,h=i.get(o)??{};i.set(o,{...h,[a.id]:!1})}},resetCalled:c=>{let a=i.get(c);if(a)for(let o in a)a[o]=!1},isReady:c=>{let a=i.get(c);return a?!Object.values(a).some(o=>!o):!0},release:()=>i.clear()}}function Ne(i){return Object.values(i).flat().sort(e=>e.actionType===I.expect?-1:1)}var Lt={videoContentHeight:0,videoContentWidth:0},Nt=(i,e)=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return Lt;let{clientHeight:r,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(r&&s))return Lt;let c=t/n,a=r/s,o,h;return a>c?(h=s,o=s*c):a<c?(h=r/c,o=r):(h=s,o=r),{videoContentWidth:h,videoContentHeight:o}};var vn=250;function Ot(i){let e=()=>{},t=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){let{parentElement:o,player:h}=i();if(o&&h){let{videoContentWidth:g,videoContentHeight:T}=Nt(o,h);o.style.setProperty("--interactive-content-width",`${g}px`),o.style.setProperty("--interactive-content-height",`${T}px`),o.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),o.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function r(){let{parentElement:a}=i();a.removeAttribute("style")}let s=J(a=>{let{fns:o=[]}=i();n(a);for(let h of o)h()},vn);function c(){e=void 0,t.disconnect(),r()}return{resizeObserver:t,calc:()=>{e?.()},release:c}}var oe=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var gn=i=>Math.floor(Math.random()*i),Ft=i=>{let e=i.length,t=1/0,n=null;for(;e--;){let r=i[e],s=r.weight??1;s<t&&(t=s,n=r)}return n},Bt=i=>{let e=i.length,t=-1/0,n=null;for(;e--;){let r=i[e],s=r.weight??0;s>t&&(t=s,n=r)}return n};var _t=i=>{let e=i.length,t=gn(e);return i[t]},jt=1,Ht=i=>{let e=0;for(let n=0;n<i.length;++n)e+=i[n].weight??jt;let t=Math.random()*e;e=0;for(let n=0;n<i.length-1;++n)if(e+=i[n].weight??jt,e>=t)return i[n];return i[i.length-1]};var Dt={shouldOpenNow:!0,isDetachContainer:!0},Gt="after-expect";var ot=(i,e=!1)=>({...i,args:e?{...i.args,...Dt}:{...Dt,...i.args}}),Wt=({globalEventEmitter:i,globalEvents:e,player:t,interactiveEvents:n,removeControllers:r})=>{let s={isExpect:!1},c=()=>{s.isExpect&&(s.isExpect=!1)},a=({action:l,controlType:p,controlId:u,containerId:d,branches:m=[],onEvent:A,isEOV:E=()=>!1,isDisabled:v=()=>!1})=>{let b=ot(l,E()),B={timestamp:1/0,priority:"control",initiator:u,actionType:b.type},_=v(),V=i.emit.bind(i,f.interactives,{subjectId:u,subjectType:p,subjectName:"control",type:_?w.actionChoiceCanceled:w.actionChoice,actionType:l.type,payload:{containerId:d,...b.args}}),O=()=>{e.interactiveActionChoice$.next({subjectId:u,subjectType:p,subjectName:"control",type:_?"action-choice-canceled":"action-choice",actionType:l.type,payload:{containerId:d,...b.args}})};if(_){V(),O();return}switch(b.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let j=m.find(K=>K.id===b.args.branchId);if(!j)return;A(b.args.isDetachContainer,N.bind(null,{subjectId:u,subjectName:"control"})),V(),O(),b.args.shouldOpenNow?C({subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}}):(n.add({...B,action:C.bind(null,{subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}})}),r?.());return}case I.continuePlayback.trim().toLowerCase():{A(b.args.isDetachContainer,N.bind(null,{subjectId:u,subjectName:"control"})),V(),O(),b.args.shouldOpenNow?D({subjectId:u,subjectName:"control",subjectType:p,action:l}):n.add({...B,action:D.bind(null,{subjectId:u,subjectName:"control",subjectType:p,action:l})});return}case I.openURI.trim().toLowerCase():{A(b.args.isDetachContainer,N.bind(null,{subjectId:u,subjectName:"control"})),V(),O(),b.args.shouldOpenNow?y({subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{URI:l.args.uri}}):(n.add({...B,action:y.bind(null,{subjectId:u,subjectName:"control",subjectType:p,action:b,payload:{URI:l.args.uri}})}),r?.());return}default:let G="Unexpected control event",He=new M(1,1,{message:G});T(He,G);return}},o=({action:l,container:{id:p,endTime:u},branches:d=[],isEOV:m=!1,autoSelected:A=!1})=>{let E=ot(l,m),v={timestamp:!E.args.shouldOpenNow||m?1/0:u??1/0,priority:"container",initiator:p,actionType:E.type},b=i.emit.bind(i,f.interactives,{subjectId:p,subjectName:"container",type:w.actionChoice,actionType:E.type,payload:E.args}),B=()=>{e.interactiveActionChoice$.next({subjectId:p,subjectName:"container",type:"action-choice",actionType:E.type,payload:E.args})};switch(E.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let O=d.find(G=>G.id===E.args.branchId);if(!O)return;b(),B(),n.add({...v,action:C.bind(null,{subjectId:p,subjectName:"container",action:E,payload:{chapterId:O.chapterId,autoSelect:A}})}),r?.();return}case I.setMaxWeightBranch.trim().toLowerCase():return;case I.setMinWeightBranch.trim().toLowerCase():return;case I.setRandomBranch.trim().toLowerCase():return;case I.setWeightlessRandomBranch.trim().toLowerCase():return;case I.continuePlayback.trim().toLowerCase():{b(),B(),n.add({...v,action:D.bind(null,{subjectId:p,subjectName:"container",action:E})});return}case I.openURI.trim().toLowerCase():{b(),B(),n.add({...v,action:y.bind(null,{subjectId:p,subjectName:"container",action:E,payload:{URI:l.args.uri}})}),r?.();return}default:let _="Unexpected container event",V=new M(1,1,{message:_});T(V,_);return}};function h({container:l,branches:p,isEOV:u=!1}){let d=nt(l.events);if(d){let m=ot(d.action,u);i.emit(f.interactives,{subjectId:l.id,subjectName:"container",type:w.actionChoice,actionType:m.type,payload:m.args}),e.interactiveActionChoice$.next({subjectId:l.id,subjectName:"container",type:"action-choice",actionType:m.type,payload:m.args}),n.add({timestamp:u?1/0:l.endTime??1/0,priority:"container",initiator:l.id,actionType:I.expect,action:x.bind(null,{subjectId:l.id,subjectName:"container"})}),s.isExpect=!0}else for(let m of l.events??[])o({action:m.action,container:l,branches:p,isEOV:u})}let g=({chapterId:l,action:p,branches:u=[]})=>{let d=i.emit.bind(i,f.interactives,{subjectId:l,subjectName:"chapter",type:w.actionChoice,actionType:p.type,payload:p.args}),m=()=>{e.interactiveActionChoice$.next({subjectId:l,subjectName:"chapter",type:"action-choice",actionType:p.type,payload:p.args})};switch(p.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let v=u.find(b=>b.id===p.args.branchId);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let v=_t(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let v=Ht(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let v=Bt(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let v=Ft(u);return v?.chapterId?(d(),m(),C.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return d(),m(),D.bind(null,{subjectId:l,subjectName:"chapter",action:p});case I.openURI.trim().toLowerCase():return d(),m(),y.bind(null,{subjectId:l,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:let A="Unexpected chapter event",E=new M(1,1,{message:A});T(E,A);return}};function T(l,p){console.error(p),e.error$.next(l),i.emit(f.errors,l)}function S(l){let p=nt(l.events);if(p){if(F(l))return;i.emit(f.interactives,{subjectId:l.id,subjectName:"chapter",type:w.actionChoice,actionType:p.action.type,payload:p.action.args}),e.interactiveActionChoice$.next({subjectId:l.id,subjectName:"chapter",type:"action-choice",actionType:p.action.type,payload:p.action.args}),n.add({timestamp:1/0,priority:"chapter",initiator:l.id,actionType:I.expect,action:x.bind(null,{subjectId:l.id,subjectName:"chapter"})})}else l.events?.forEach(u=>{let d=g({chapterId:l.id,action:u.action,branches:l.branches});d&&n.add({timestamp:1/0,priority:"chapter",initiator:l.id,actionType:u.action.type,action:d})})}let x=({subjectId:l,subjectName:p})=>{t.pause(),i.emit(f.interactives,{subjectId:l,subjectName:p,type:w.actionExecution,actionType:I.expect}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,type:"action-execution",actionType:I.expect})},N=({subjectId:l,subjectName:p})=>{t.info.isEnded$.getValue()?n.execEndOfVideo():t.play(),i.emit(f.interactives,{subjectId:l,subjectName:p,type:w.actionExecution,actionType:Gt}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,type:"action-execution",actionType:Gt})},D=({subjectId:l,subjectName:p,subjectType:u,action:d})=>{i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type})},C=({subjectId:l,subjectName:p,subjectType:u,action:d,payload:m})=>{m.behaviour="change-chapter",i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type,payload:m}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type,payload:m})},R=({subjectId:l,subjectName:p,subjectType:u,action:d,payload:m})=>{m.behaviour="change-manifest",i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type,payload:m}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type,payload:m})},y=({subjectId:l,subjectName:p,subjectType:u,action:d,payload:m})=>{if(!m.URI)return;let A=window.open(m.URI,"_blank","noopener,noreferrer");A&&(A.opener=null),i.emit(f.interactives,{subjectId:l,subjectName:p,subjectType:u,type:w.actionExecution,actionType:d.type}),e.interactiveActionExecution$.next({subjectId:l,subjectName:p,subjectType:u,type:"action-execution",actionType:d.type})};return{onControlEvent:a,onContainerEvent:o,onChapterEvent:g,onExpectEvent:x,expectEventHandler:N,setManifestChapterEvents:S,setManifestContainerEvents:h,stopExpect:c,state:s}};import{Subscription as Tn,Subject as ct,ValueSubject as le}from"@vkontakte/videoplayer-shared/evergreen";var lt=(i,e)=>{let t={};return i.map(n=>{if(!t[n]){let r=e.chapters.find(c=>c.id===n);if(!r)return null;let s=e.media.videos.find(c=>r.videoId===c.id);if(!s)return null;t[n]=Qt(s)}return t[n]}).filter(Boolean)},bn=i=>{for(let e of i.variants)if(En(e)&&e.payload)return e.payload.id},En=i=>!!(i.type==="custom"&&i.payload&&i.payload.type==="vk"),Qt=i=>{let e=bn(i);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},In=(i,e)=>{for(let t of i.media.videos)if(e===Qt(t)){for(let n of i.chapters)if(n.videoId===t.id)return n.id;return}},Kt=(i,e)=>i.reduce((t,n)=>{let r=In(e,n);return r?[...t,r]:t},[]);var ce=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new le([]),hasPrevChapter$:new le(!1),prevChapter$:new le(null),isInitialChapter$:new le(!1),isGoBackLimited$:new le(!1)};this.#n=null;this.#a=!1;this.#e=null;this.#p=null;this.events={inited$:new ct,destroyed$:new ct,error$:new ct};this.#i=null;this.#r=null;this.#t=null;this.#o=new Tn;this.#l=!1;this.#c=0;this.#i=t,this.#t=e,this.#r=n,this.#n=r,this.#s=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(c=>{this.state.prevChapter$.next(c.at(-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#s.maxLength-1)}))}#n;#s;#a;#e;#p;#i;#r;#t;#o;#l;#c;async setManifest(e){if(!this.#r||!this.#t)return;this.#e=e,await this.getProjectHistory();let t=this.getInitialChapterId();await this.#r.setChapter({chapterId:t,pushToHistory:!1}),this.#a||(this.#a=!0,this.events.inited$.next({initChapterId:t}))}get inited(){return this.#a}async updateHistory(e,t=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,r=e.length-this.#s.maxLength,s=r>0?e.slice(r):e,c=lt(s,n);if(this.#p=c,this.state.history$.next(s),!(!t||!this.#n||!this.#i))try{await this.#n.save(this.#i,c)}catch{let o=new M(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#t?.emit(f.errors,o)}}async goBack(){if(!this.state||!this.#r){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#t?.emit(f.errors,n)}this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#r.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#i)return;let e=this.#e,t=[this.getInitialVideoId()];if(this.#n)try{let r=await this.#n.get(this.#i);r.length&&(t=r)}catch{let s=new M(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#t?.emit(f.errors,s)}let n=Kt(t,e);this.state.history$.next(n)}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||this.#s.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let e=this.getInitialChapterId();return lt([e],this.#e).pop()}return null}destroy(){this.#i=null,this.#n=null,this.#r=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#t?.emit(f.historyDestroyed),this.events.destroyed$.next(),this.#t=null}};var Oe=class i{constructor(e,t,n,r){this.target=e,this.type=t,this.listener=n,this.options=i._convertOptions(e,r),this.target.addEventListener(t,n,this.options)}unlisten(){this.type&&this.listener&&this.options&&this.target?.removeEventListener(this.type,this.listener,this.options),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let n=new Set(["passive","capture"]),r=Object.keys(t).filter(c=>!n.has(c));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),i._doesSupportObject(e)?t:t.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(e){let t=i._supportsObject;if(t===void 0){t=!1;try{let n={},r={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);let s=()=>{};e.addEventListener("test",s,n),e.removeEventListener("test",s,n)}catch{t=!1}i._supportsObject=t}return t||!1}};var je=class{constructor(){this.bindingMap=new oe}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,r){if(!this.bindingMap)return;let s=new Oe(e,t,n,r);this.bindingMap.push(t,s)}listenOnce(e,t,n,r){let s=c=>{this.unlisten(e,t,s),n(c)};this.listen(e,t,s,r)}unlisten(e,t,n){if(!this.bindingMap)return;let r=this.bindingMap.get(t)||[];for(let s of r)s.target===e&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var Fe=class{constructor(){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 r=3;r<n;r+=40)if(t[r]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var Be=class{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/videoplayer-interactive",
3
- "version": "1.0.30-dev.82195443.0",
3
+ "version": "1.0.30-dev.954af6ed.0",
4
4
  "author": "vk.com",
5
5
  "description": "Movika interactive SDK",
6
6
  "homepage": "https://vk.com",
@@ -51,8 +51,8 @@
51
51
  "dependencies": {
52
52
  "@interactiveplatform/movika-graph-editor": "1.11.0",
53
53
  "@interactiveplatform/movika-manifest": "^1.0.0",
54
- "@vkontakte/videoplayer-core": "2.0.124-dev.d0d82c74.0",
55
- "@vkontakte/videoplayer-shared": "1.0.53-dev.4903a877.0",
56
- "@vkontakte/videoplayer-statistics": "1.0.70-dev.f4be8903.0"
54
+ "@vkontakte/videoplayer-core": "2.0.124-dev.3f8d0805.0",
55
+ "@vkontakte/videoplayer-shared": "1.0.53-dev.0120da43.0",
56
+ "@vkontakte/videoplayer-statistics": "1.0.70-dev.d1a78905.0"
57
57
  }
58
58
  }