@vkontakte/videoplayer-interactive 1.0.16-dev.7f2d8e7b.0 → 1.0.16-dev.9968010.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.16-dev.7f2d8e7b.0
3
- * Wed, 04 Sep 2024 18:16:45 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.16-dev.09968010.0
3
+ * Mon, 09 Sep 2024 09:28:19 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-16/doc/
5
5
  */
6
- var pe="1.0.16-dev.7f2d8e7b.0";function Dt(i,t=1){let e="0",n="0",s="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+s},${t})`}var M="SDK_NAME",Je="SDK_NAME-controls-container",pt=()=>document.querySelector(`.${Je}`),me=.4,L={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},de={top:"flex-start",bottom:"flex-end",center:"center"},ue={start:"flex-start",end:"flex-end",center:"center"},fe={start:"left",end:"right",center:"center"},dt=({target:i,props:t})=>{i.style.alignItems=de[t?.text?.gravityVertical]??de.center,i.style.justifyContent=ue[t?.text?.gravityHorizontal]??ue.center,i.style.textAlign=fe[t?.text?.alignment]??fe.start},ut=({target:i,props:t,fallback:e,dependsOn:n})=>{i.style.color=t?.text?.color??e.textColor,i.style.fontSize=`calc(${n.height} * ${t?.text?.size??e.textSize})`,i.textContent=t?.text?.value??e.textContent},ft=({target:i,props:t,fallback:e})=>{i.style.backgroundColor=Dt(t?.background?.color??e.backgroundColor,t?.background?.alpha??e.backgroundAlpha)},mt=({target:i,props:t,fallback:e,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${t?.shape?.border?.width??e.borderWidth}) solid ${Dt(t?.shape?.border?.color??e.borderColor,t?.shape?.border?.alpha??e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${t?.shape?.roundCorners??e.roundCorners})`},W=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Ht="int",Q={AREA:`${Ht}_area`,TEXT:`${Ht}_text`,BUTTON:`${Ht}_bttn`};var $=class{constructor(t){this.control=t}createView(t){let e=document.createElement("div");e.classList.add(`${M}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??L.innerSizesDependOn)==="self"?{height:e.style.height,width:e.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:e,dependsOn:n}}setEvents(t,e){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",r=>{r.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${M}-control-container-${this.control.id}`)}};var yt=i=>{if(i.type.trim().toLowerCase()==="area")return new Gt(i)},Gt=class extends ${constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("button");return r.classList.add(`${M}-${this.control.id}`),r.setAttribute("data-testid",Q.AREA),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",ft({target:r,props:this.control.props,fallback:{...L,backgroundColor:"transparent"}}),mt({target:r,props:this.control.props,fallback:{...L,borderAlpha:0},dependsOn:n}),W({target:r,layoutParams:this.control.layoutParams,fallback:L}),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${M}-${this.control.id}`)}};var gt=()=>{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 vt=i=>{if(i.type.trim().toLowerCase()==="button")return new Ut(i)},Ut=class extends ${constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("button");r.type="button",r.classList.add(`${M}-${this.control.id}`),r.setAttribute("data-testid",Q.BUTTON),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";let o=gt();return W({target:r,layoutParams:this.control.layoutParams,fallback:L}),ft({target:r,props:this.control.props,fallback:L}),mt({target:r,props:this.control.props,fallback:L,dependsOn:n}),dt({target:r,props:this.control.props}),ut({target:o,props:this.control.props,fallback:L,dependsOn:n}),r.append(o),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${M}-${this.control.id}`)}};var ye=i=>{if(i.type.trim().toLowerCase()==="text")return new zt(i)},zt=class extends ${constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("div");r.classList.add(`${M}-${this.control.id}`),r.setAttribute("data-testid",Q.TEXT),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";let o=gt();return W({target:r,layoutParams:this.control.layoutParams,fallback:L}),dt({target:r,props:this.control.props}),ut({target:o,props:this.control.props,fallback:L,dependsOn:n}),r.append(o),s.append(r),t.append(s),this.controlEl=r,s}disable(){}enable(){}getElement(){return document.querySelector(`.${M}-${this.control.id}`)}};var Wt=class{constructor(t){this.layout=t}},ge=i=>{if(i.type.trim().toLowerCase()==="relative")return new X(i)},X=class extends Wt{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,e){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${e.width})`,t.style.height=`calc(var(--interactive-content-height) * ${e.height})`,t.style.left=`calc(var(--interactive-content-width) * ${e.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${e.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var K=class{constructor(t){this.container=t,this.factories=new Map,this.#a()}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),this.#a()}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),this.#a()}#a(){this.controls=this.#s()}#s(){return this.container.controls?.reduce((t,e)=>{let n=e.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...t,s(e)]:[...t]},[])}};var bt=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Qt(i,t)},Qt=class extends K{constructor(t,e){super(t),this.rootElement=e??pt(),this.layout=new X(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",vt),this.addControlFactory("text",ye),this.addControlFactory("area",yt)}createView(t){let e=document.createElement("div");return e.classList.add(`${M}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{let s=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(s,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){let t=this.getElement();t&&(t.style.visibility="hidden")}show(){let t=this.getElement();t&&(t.style.visibility="visible")}enable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=me,this.isDisabled=!0)}removeView(){this.isRemoved||(this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${M}-${this.container.id}`)}};import{Subject as ki,ValueSubject as N,Observable as Ze,once as Ni,Subscription as ji,clientChecker as Oi,combine as Pi}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ct}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as ti}from"@vkontakte/videoplayer-shared";function Ct(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var H=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Y=i=>H(i,"Object"),Et=i=>H(i,"String"),It=i=>H(i,"Array"),xt=i=>H(i,"Number"),ve=i=>H(i,"Function");var Kt=i=>xt(i)&&!isNaN(i);var G=i=>Y(i)&&Object.keys(i).length===0,qt=i=>It(i)&&!i.length;var J=(i,t)=>Et(i)&&(t?i.trim():i).length;var be="video_interactive",Ce="videoint";var ei=250,tt=class{constructor(t){this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=e,this.onError=n,this.lang=s??"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=ii(t),this.resizeObserver=new ResizeObserver(Ct(this.onResize,ei)),this.resizeObserver.observe(this.graphWrapperElement)}onResize=t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))};getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}handleChapterChange=t=>{if(this.isReady){if(this.isHidden||this.hide(),!t?.id){this.onError?.("Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}};handleManifestChange=async(t,e=[])=>{if(!xt(t.graph.edit.chapters[0].x)){this.isReady=!1,this.onError?.("Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let n;try{n=await ti(this.lang,be,Ce)}catch{console.log("Unable to load graph language pack")}let{GraphEditor:s}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new s(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:n}),this.ngEditor.on("control",({name:r,chapterId:o})=>{r==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",r=>{this.lastZoomInfo={...r}})}this.visitedChapterIds=new Set(e),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0};setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function ii(i){let t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height="100%",t.style.width="100%",t.style.display="none",i.append(t),t}var et=class{constructor(){this._containers=[];this._player=null;this.setPlayer=t=>{this._player=t};this.setContainers=t=>{this._containers=t};this.deleteContainer=t=>{this._containers=this._containers.filter(e=>e.id!==t)};this.getNextInteractiveTime=(t=3e3)=>{if(!this._containers.length||this._player===null)return null;let e=-1,n=!1,s=Math.round(this._player.info.position$.getValue()*1e3);for(let r of this._containers){let o=r.startTime-t;if(o<=s&&(r.endTime&&s<=r.endTime||r.endTime===null)){n=!0;break}s<o&&(e=e===-1?o:Math.min(e,o))}return!n&&e!==-1?e:null}}};var B=(i="",t="")=>{let e=i.split("."),n=t.split("."),s=0;for(let r=0;r<Math.max(e.length,n.length)&&!s;r++)e[r]>n[r]?s=1:e[r]<n[r]?s=-1:s=0;return s};import{v4 as ni}from"uuid";var si="3.1",Ee={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ri={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ie=i=>{let t=[];for(let e of i.chapters){let n,s=[];for(let{isDefault:a,...c}of e.branches)a&&(n=c.id),s.push(c);let r=[],o=[];for(let{fallbackStrategy:a,...c}of e.containers){let h=!!c.endTime,y=[ri];switch(a){case"await":h?y=[]:r=[];break;case"default":{let g={type:"onSuspense",action:{type:Ee.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?y=[g]:r=[g];break}case"random":case"weightlessRandom":case"max":case"min":{let g={type:"onSuspense",action:{type:Ee[a],args:{}}};h?y=[g]:r=[g];break}}for(let g of c.controls)o.push({...c,controls:[{...g}],id:ni(),events:y})}t.push({...e,containers:o,events:r,branches:s})}return i.metadata.version=si,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var ai="3.2",xe=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:ai},media:t}}return i};var oi="3.3",ci=(i=[])=>({edit:{chapters:i},view:{}}),Te={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Se=i=>{let t=[],e=[];for(let n of i.chapters){let{id:s,x:r,y:o,...a}=n,c=a.containers.map(h=>({...h,controls:h.controls.map(({subtype:y,type:g,...E})=>({...E,type:y??g})),events:h.events?.length?h.events:[Te]}));t.push({id:s,...a,containers:c,events:a.events?.length?a.events:[Te]}),e.push({id:s,x:r,y:o})}return{...i,chapters:t,graph:ci(e),metadata:{...i.metadata,version:oi}}};var li=[{version:"3.0",migrate:Ie},{version:"3.1",migrate:xe},{version:"3.2",migrate:Se}],Zt=i=>li.reduce((t,e)=>B(t.metadata.version,e.version)?t:e.migrate(t),i);var Zn=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),we=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Xn=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),I=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var _e={metadata:"Object",chapters:"Array"},hi="3.0.0",pi="3.3.0",Tt=i=>{let t=B(i,hi);return t===-1?!1:t===0?!0:B(i,pi)!==1},Ve=i=>{if(!Y(i))return!1;for(let t in _e)if(!i[t]||!H(i[t],_e[t]))return!1;return Tt(i.metadata.version)},St=i=>i.type===we.Text;var R=class{constructor(t,e,...n){this.severity=t;this.category=e;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var q=class{constructor(){this.listeners={}}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t]||[];for(let s=n.length;s>0;s--)if(n[s]===e){n.splice(s,1);break}return this}emit(t,...e){let n=this.listeners[t];return n?(n.forEach(s=>{s(...e)}),!0):!1}listenerCount(t){return this.rawListeners(t).length}rawListeners(t){return this.listeners[t]||[]}};var wt=class{constructor(t){this.fns=[];this.addFn=(t,e=!1)=>{ve(t)&&(this.fns.push(t),e&&this.updateFn())};this.removeFn=(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(t=>t()),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)};this.fn=t,this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as vi}from"@vkontakte/videoplayer-shared";var _t=class{constructor(t){this.loaders={chapterLoaders:t?.chapterLoaders??[],manifestLoaders:t?.manifestLoaders??[]}}async exec(t,e){return di(...this.loaders[t])(e)}};function di(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function it(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function Vt({actions:i,errors:t,chapterId:e,...n}){if(e){let s=i.getManifest(),r=i.getChapter(s.chapters,e);if(r){let o=i.getMedia(s.media,r.videoId),a=i.getGraph(s.graph,r.id);return o?{...n,actions:i,errors:t,result:{chapter:r,media:o,graph:a}}:{...n,errors:it(t,Vt.name,"Could not find media"),actions:i}}}return{...n,errors:it(t,Vt.name,"Could not find chapter"),actions:i}}var ui=async i=>{try{let t={},e;if(Et(i)){e=new URL(i).href;let s=await fetch(e);if(!s.ok)return{};t=await s.json()}else if(Y(i))t=i;else return{};if(!Ve(t))return{};let n=t.metadata.media;if(Et(n)&&!t.media)try{let s;e?s=new URL(n,e).href:(s=new URL(n).href,e=s);let r=await fetch(s);if(!r.ok)throw new Error;t.metadata.media=await r.json()}catch{return yi(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch{return{}}};async function Me(i){let{manifest:t,manifestURL:e}=await ui(i),n=Zt(t);return n.media=fi(n.media,e),delete n.metadata.media,n}function Mt(i,t){if(t)return i.find(e=>e.id===t)}function Xt(i,t){return i.edit?.chapters?i.edit.chapters.find(e=>e.id===t):i.view?.chapters?i.view.chapters.find(e=>e.id===t):void 0}function Yt(i,t){return i.videos.find(e=>e.id===t)}function fi(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let s="url"in n?n.url:"",r=mi(s,t);return{...n,url:r||s}})}))}}function mi(i="",t){try{return new URL(i,t).href}catch{return""}}function yi(i){return B(i,"3.2.0")>=0}var x=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Rt=i=>It(i)&&!qt(i),O=i=>i.order==="end",At=i=>It(i.containers)&&!qt(i.containers)&&O(i),Re=(i,t)=>{let e=i*1e3;return Rt(t.controls)&&e<(t.startTime??0)},Jt=(i,t)=>{let e=i*1e3;return Rt(t.controls)&&e>=(t.startTime??0)&&e<=(t.endTime??1/0)};var U=i=>i.some(t=>t.action.type==="expect"),te=i=>i.find(t=>t.action.type==="expect"),gi=i=>i?.length===1,Lt=i=>gi(i)&&St(i[0]);var Ae=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),Le=(i,t)=>U(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&U(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var Z=class extends _t{constructor(e,n){super(e);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new vi(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(e){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:it},result:null,errors:null,source:e});return n.errors&&this.errorHandler(n.errors),this.manifest=await Me(n.result??e),this}async setInitial(){return this.setNext()}async setNext(e=this.manifest?.metadata.initChapterId){if(!e)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",Vt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Xt,getChapter:Mt,getMedia:Yt,getByBranches:this.getByBranches.bind(this),addErrorMessage:it},result:null,errors:null,chapterId:e}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(e){this.onError(e),console.error("Something went wrong with loaders",{errors:e})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(e=this.manifest?.metadata.initChapterId){if(!e||!this.manifest)return null;let n=Mt(this.manifest.chapters,e);if(n){let s=Yt(this.manifest.media,n.videoId),r=Xt(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:r}}return null}getBranches(e=this.chapter?.id){if(e===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=Mt(this.manifest?.chapters||[],e);return this.getByBranches(n?.branches)}}getByBranches(e=[]){return e.reduce((n,s)=>{let r=this.getByChapterId(s.chapterId);return r&&n.push(r),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return O(this.chapter)}};import{Player as bi}from"@vkontakte/videoplayer-core";import{Subscription as Ne,Tracer as Ci}from"@vkontakte/videoplayer-shared";var ke=i=>{let t=i.variants.find(e=>e.payload?.type==="vk");if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var d={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},nt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},C={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function ee(){let i=new Map;function t({listId:r=Math.random().toString(),itemId:o=Math.random().toString(),...a}){let c=i.get(r),h={...a};return c?c[o]=h:i.set(r,{[o]:h}),{listId:r,itemId:o,...a}}function e(r){r.player.destroy(),r.container.remove(),r.subscription.unsubscribe(),r.statistics?.oneStat.destroy(),r.statistics?.statSubscription.unsubscribe()}function n(r,o){let a=i.get(r);if(!a)throw Error("Can't remove. Not find.");if(o){let c=a[o];c&&e(c),delete a[o],Object.keys(a).length||i.delete(r)}else{for(let c of Object.values(a))e(c);i.delete(r)}}function s(){for(let r of i)n(r[0])}return{createPlayer:t,removePlayer:n,map:i,removeAll:s}}function ie(i,t=[]){let e={},n,s=!t.length;for(let r of i.variants)if(!n&&"cover"in r&&(n=r.cover),"url"in r)switch(r.type.toLowerCase()){case"mp4":(s||t.includes("mp4"))&&(e.MPEG={...e.MPEG,[r.standard??"Invariant quality"]:r.url});break;case"mpeg":(s||t.includes("mpeg"))&&(e.MPEG={...e.MPEG,[r.standard??"Invariant quality"]:r.url});break;case"hls":(s||t.includes("hls"))&&(e={...e,HLS:{type:"url",url:r.url}});break;case"dash":(s||t.includes("dash"))&&(e={...e,DASH_SEP:{compatibilityMode:!0,type:"url",url:r.url}});break;default:break}return{sources:e,thumbUrl:n,title:i.title??""}}var st=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var kt={activePlayerChanged:"sc-active-player-changed",playerCreated:"sc-player-created"},Ei=2;function ne(i){let t=ee(),e=new q,n={},s=null,r=!1,o;i&&a(i);function a(T){s=T}function c(T,S,p){if(!s)throw Error("need to set interactive controller");if(!s.options)return;let u=(t.map.get(T)??{})[S];if(u){n={chapterId:p,listId:T,itemId:S,...u};let m=n.player;n.subscription.add(m.info.currentQuality$.subscribe(f=>{let _=m.info.position$.getValue(),w=m.info.isAutoQualityEnabled$.getValue();if(!(!f||!_||w))for(let V of t.map)Object.values(V[1]).forEach(({player:b})=>{st(b,f)})})).add(m.events.started$.subscribe(()=>{h(S)})),u.container.remove(),s.setPlayer(u.player),r||(s.init(),r=!0),e.emit(kt.activePlayerChanged,{player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function h(T){if(!s)throw Error("need to set interactive controller");if(G(n)||T!==n.itemId)return;let S=s.getChapterBranches(),p=new Set;for(let l of S)p.has(l.media.id)||(await g({media:l.media,chapterId:l.chapter.id,setAsActive:!1,title:l.chapter.label}),p.add(l.media.id))}async function y({chapter:{id:T},media:S}){if(G(n))return;let p=n.player.info.muted$.getValue(),l=n.player.info.currentQuality$.getValue(),u=n.player.info.isAutoQualityEnabled$.getValue(),m=n.player.info.volume$.getValue(),f=n.player.info.currentPlaybackRate$.getValue(),_=!u,w=!1;for(let V of t.map)if(V[0]===S.id){let b=Object.keys(V[1]);for(let A of b)A===n.itemId?(b.length<Ei||(w=!0),t.removePlayer(V[0],A)):(w=!0,c(V[0],A,T),_?st(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(m),n.player.setMuted(p),n.player.setPlaybackRate(f))}else t.removePlayer(V[0]);w||(await g({media:S,chapterId:T,setAsActive:!0,playbackRate:f}),_?st(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(m),n.player.setMuted(p))}async function g({media:T,chapterId:S,prefetch:p=!0,setAsActive:l=!0,autoplay:u=!1,preferredExt:m,title:f,playbackRate:_}){let w=Math.random().toString(),V=document.createElement("div");o.append(V);let b;if(s?.options?.vkVideoLoader){let ht=ke(T);ht.length&&(b=await s.options.vkVideoLoader(...ht))}let A=s?.options?.coreConfig||{},z={...A,configName:[...A.configName??[],"interactive"]},F={container:V,...b?.videos?.[0]||{sources:ie(T,m).sources},title:f,failoverHosts:b?.failoverHosts||[]},j=new bi(z,Ci.createRootTracer());j.initVideo(F);let lt=null;if(s?.options.createOneStat){let ht=b.videos[0],le=s.options.createOneStat(ht),he=new Ne;he.add(le.attachTo(j)),lt={oneStat:le,statSubscription:he}}let ce=new Ne,Ye=n?.player?.info.isAutoQualityEnabled$.getValue();ce.add(j.events.canplay$.subscribe(function(){Ye||st(j,n.player.info.currentQuality$.getValue()),_&&j.setPlaybackRate(_)}));let D=t.createPlayer({listId:T.id,itemId:w,player:j,container:V,sources:ie(T,m).sources,config:F,subscription:ce,statistics:lt});return l&&c(T.id,D.itemId,S),u&&D.player.play(),p&&!u&&D.player.prepare(),e.emit(kt.playerCreated,D.player),{player:D.player,config:D.config,statistics:D.statistics}}function E(){v(),s=null,o.remove()}function v(){s?.off(d.chapterChanged,y),t.removeAll(),n={},r=!1}async function k(){if(!s)throw Error("need to set interactive controller");v(),o=document.createElement("div");let{media:T,chapter:S}=s.getCurrentChapter();T?(s.on(d.chapterChanged,y),await g({media:T,chapterId:S.id,title:S.label})):console.error("not found")}return{...t,on:e.on.bind(e),off:e.off.bind(e),init:k,setInteractiveController:a,createPlayer:g,removeAll:E,getActivePlayer:function(){return n}}}import{Subscription as Ii}from"@vkontakte/videoplayer-shared";var Nt=class{constructor({player:t,container:e,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:o,ignoreContainerEvent:a,permanentTextControls:c,disabledControls$:h,onRemove:y}){this.container=e,this.branches=n,this.selectBranches=s,this.subscription=new Ii,this.player=t,this.interactiveEvents=r,this.ignoreContainerEvent=a,this.isPermanentText=c&&Lt(e.container.controls),this.disabledControls$=h,this.onRemove=y,this.globalEventEmitter=o,this.gameState=x.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}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(t=>{t?this.container.disable?.():this.container.enable?.()}))}hide=()=>{setTimeout(()=>{this.gameState!==x.end&&(U(this.container.container.events)&&this.gameState===x.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==x.interactive&&this.container.hide?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})))})};show=()=>{if(this.gameState===x.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!0,isFirst:!1});else{let e=Ae({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})},onEvent:(n,s)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})),(this.gameState===x.end||this.gameState===x.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),s(),this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1}))},isEOV:()=>this.gameState===x.end});this.container.createView(e),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&this.container.disable?.()}};selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?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:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let t=U(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})}onEndOfVideo=()=>{this.gameState=x.end,this.selectContainerEvent(!0)};whilePlaying=()=>{if(this.player.experimental.element$.getValue()?.readyState<1||[x.destroyed,x.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Re(e,this.container.container))this.gameState!==x.beforeInteractive&&(this.gameState=x.beforeInteractive,this.onBeforeStartTime());else if(Jt(e,this.container.container))this.gameState!==x.interactive&&(this.gameState=x.interactive,this.onStartTime());else if(this.gameState!==x.afterInteractive){let r=this.gameState;this.gameState=x.afterInteractive,r===x.interactive&&this.onEndTime()}else this.gameState!==x.destroyed&&!this.isPermanentText&&this.removeView();let n=Jt(e,this.container.container),s=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[];this.globalEventEmitter.emit(d.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:s,currentTime:e,isInteractiveTime:n})};reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=x.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.containerRemoved,visibility:!1}),this.gameState=x.removed,this.onRemove?.()}destroy(){this.reset(),this.removeView(),this.gameState=x.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var je=(i=[])=>i.reduce((t,e,n)=>{let s=(e?.controls??[]).filter(r=>!St(r));if(Rt(s)){let r=[e.startTime??0,e.endTime??1/0],o=e.id;if(!n)t.push({subjects:[o],range:r});else{let a=[],c=-1/0,h=1/0,y=[],g=[];for(let E=0;E<t.length;E++){let v=t[E];if(g.push(...v.subjects),v.range[0]<h&&(h=v.range[0]),v.range[1]>c&&(c=v.range[1]),r[0]>=v.range[0]&&r[1]<=v.range[1])return t[E].subjects.push(o),t;r[0]<v.range[0]&&r[1]>v.range[0]&&(a.push(E),y=y.concat(v.subjects)),r[0]>=v.range[0]&&r[0]<=v.range[1]&&(a.push(E),y=y.concat(v.subjects),r[0]=v.range[0]),r[1]>=v.range[0]&&r[1]<=v.range[1]&&(a.push(E),y=y.concat(v.subjects),r[1]=v.range[1])}if(g.push(o),r[0]<=h&&r[1]>=c)return[{subjects:g,range:r}];a.length&&a.reverse().forEach(E=>{t.splice(E,1)}),t.push({subjects:y.concat([o]),range:r})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Oe(){let i={};function t(){for(let a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a];return!0}function e(a){let c={};for(let h in i)+h<=a&&(c[h]=i[h]);return c}function n(a){let c={};for(let h in i)+h>=a&&(c[h]=i[h]);return c}function s({timestamp:a,priority:c,initiator:h}){if(Kt(a)){let y=i[a]??null;if(y&&J(c,!0)){let g={},E=y[c];return E&&(g={...g,...E}),g=G(g)?null:g,g&&J(h,!0)?g[h]??null:g}return y}return null}function r({timestamp:a,priority:c,initiator:h}){if(Kt(a))if(i[a]){if(J(c,!0))if(i[a][c]){if(J(h,!0))if(i[a][c][h]){if(delete i[a][c][h],!G(i[a][c]))return!0}else return!1;if(delete i[a][c],!G(i[a]))return!0}else return!1;return delete i[a]}else return!1}function o({timestamp:a,priority:c,initiator:h,...y}){i[a]?.[c]?.[h]?i[a][c][h].push({...y}):i[a]?.[c]?i[a][c]={...i[a][c],[h]:[{...y}]}:i[a]?i[a]={...i[a],[c]:{[h]:[{...y}]}}:i[a]={[c]:{[h]:[{...y}]}}}return{map:i,remove:r,add:o,removeAll:t,get:s,getLte:e,getGte:n}}var xi=[I.expect,I.setNextBranch],Ti=1/0;function se(i){let t=i,e,n=Si(),s=new Oe,r,o=()=>{E(),p()},a=l=>{s.add.call(void 0,l),k()},c=(l=[])=>{for(let u of l)if(u.action(),xi.includes(u.actionType))break},h=(l=1/0)=>{let u=jt(s.get({timestamp:l,priority:"control"})??{}),m=jt(s.get({timestamp:l,priority:"container"})??{}),f=jt(s.get({timestamp:l,priority:"chapter"})??{});return[...u,...m,...f]},y=l=>{n.isReady(l)&&c(h(l))},g=()=>{c([...jt(s.get({timestamp:1/0,priority:"chapter"})??{})])},E=()=>{e&&(r?.unsubscribe(),e=void 0)},v=l=>{},k=()=>{e||(e=()=>setTimeout(()=>{y(1/0)}),r=t.events.ended$.subscribe(e))},T=l=>{E(),t=l},S=l=>{l.priority==="container"&&n.resetCalled(l.timestamp),s.remove(l)},p=()=>{n.release(),s.removeAll()};return{setPlayer:T,add:a,remove:S,exec:y,execEndOfVideo:g,listen:k,unlisten:E,release:o,containersEventsCallState:n,getPreparedToExecActions:h}}function Si(){let i=new Map;return{setCalled:({timestamp:o,id:a})=>{let c=i.get(o);c&&c[a]!==void 0&&(c[a]=!0)},setData:(o=[])=>{for(let a of o){let c=a.endTime??Ti,h=i.get(c)??{};i.set(c,{...h,[a.id]:!1})}},resetCalled:o=>{let a=i.get(o);if(a)for(let c in a)a[c]=!1},isReady:o=>{let a=i.get(o);return a?!Object.values(a).some(c=>!c):!0},release:()=>i.clear()}}function jt(i){return Object.values(i).flat().sort(t=>t.actionType===I.expect?-1:1)}var Pe={videoContentHeight:0,videoContentWidth:0},$e=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return Pe;let{clientHeight:s,clientWidth:r}=t.experimental.element$.getValue()||{};if(!(s&&r))return Pe;let o=e/n,a=s/r,c,h;return a>o?(h=r,c=r*o):a<o?(h=s/o,c=s):(h=r,c=s),{videoContentWidth:h,videoContentHeight:c}};var wi=250;function Be(i){let t=()=>{},e=new ResizeObserver(a=>{r(a),t=r.bind(null,a)});function n(a){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:y,videoContentHeight:g}=$e(c,h);c.style.setProperty("--interactive-content-width",`${y}px`),c.style.setProperty("--interactive-content-height",`${g}px`),c.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function s(){let{parentElement:a}=i();a.removeAttribute("style")}let r=Ct(a=>{let{fns:c=[]}=i();n(a);for(let h of c)h()},wi);function o(){t=void 0,e.disconnect(),s()}return{resizeObserver:e,calc:()=>{t()},release:o}}var rt=class{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){let e=this.map[t];return e?e.slice():null}getAll(){let t=[];for(let e in this.map)t.concat(this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var _i=i=>Math.floor(Math.random()*i),Fe=i=>{let t=i.length,e=1/0,n=null;for(;t--;)i[t].weight<e&&(e=i[t].weight,n=i[t]);return n},De=i=>{let t=i.length,e=-1/0,n=null;for(;t--;)i[t].weight>e&&(e=i[t].weight,n=i[t]);return n};var He=i=>{let t=i.length,e=_i(t);return i[e]};var Ge=i=>{let t=0;for(let n=0;n<i.length;++n)t+=i[n].weight??1;let e=Math.random()*t;t=0;for(let n=0;n<i.length-1;++n)if(t+=i[n].weight??1,t>=e)return i[n];return i[i.length-1]};var Ue=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var re=(i,t=!1)=>({...i,args:t?{...i.args,...Ue}:{...Ue,...i.args}}),ae=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},o=({action:p,controlType:l,controlId:u,containerId:m,branches:f=[],onEvent:_,isEOV:w=()=>!1,isDisabled:V=()=>!1})=>{let b=re(p,w()),A={timestamp:1/0,priority:"control",initiator:u,actionType:b.type},z=V(),F=i.emit.bind(i,d.interactives,{subjectId:u,subjectType:l,subjectName:"control",type:z?C.actionChoiceCanceled:C.actionChoice,actionType:p.type,payload:{containerId:m,...b.args}});if(z){F();return}switch(b.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let j=f.find(lt=>lt.id===b.args.branchId);if(!j)return;_(b.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),F(),b.args.shouldOpenNow?k({subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}}):(e.add({...A,action:k.bind(null,{subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}})}),n?.());return}case I.continuePlayback.trim().toLowerCase():{_(b.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),F(),b.args.shouldOpenNow?v({subjectId:u,subjectName:"control",subjectType:l,action:p}):e.add({...A,action:v.bind(null,{subjectId:u,subjectName:"control",subjectType:l,action:p})});return}case I.openURI.trim().toLowerCase():{_(b.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),F(),b.args.shouldOpenNow?S({subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{URI:p.args.uri}}):(e.add({...A,action:S.bind(null,{subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{URI:p.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(d.errors,new R(1,1,{message:"Unexpected control event"}));return}},a=({action:p,container:{id:l,endTime:u},branches:m=[],isEOV:f=!1,autoSelected:_=!1})=>{let w=re(p,f),V={timestamp:!w.args.shouldOpenNow||f?1/0:u,priority:"container",initiator:l,actionType:w.type},b=i.emit.bind(i,d.interactives,{subjectId:l,subjectName:"container",type:C.actionChoice,actionType:w.type,payload:w.args});switch(w.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let A=m.find(z=>z.id===w.args.branchId);if(!A)return;b(),e.add({...V,action:k.bind(null,{subjectId:l,subjectName:"container",action:w,payload:{chapterId:A.chapterId,autoSelect:_}})}),n?.();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(),e.add({...V,action:v.bind(null,{subjectId:l,subjectName:"container",action:w})});return}case I.openURI.trim().toLowerCase():{b(),e.add({...V,action:S.bind(null,{subjectId:l,subjectName:"container",action:w,payload:{URI:p.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(d.errors,new R(1,1,{message:"Unexpected container event"}));return}};function c({container:p,branches:l,isEOV:u=!1}){let m=te(p.events);if(m){let f=re(m.action,u);i.emit(d.interactives,{subjectId:p.id,subjectName:"container",type:C.actionChoice,actionType:f.type,payload:f.args}),e.add({timestamp:u?1/0:p.endTime,priority:"container",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"container"})}),s.isExpect=!0}else for(let f of p.events)a({action:f.action,container:p,branches:l,isEOV:u})}let h=({chapterId:p,action:l,branches:u=[]})=>{let m=i.emit.bind(i,d.interactives,{subjectId:p,subjectName:"chapter",type:C.actionChoice,actionType:l.type,payload:l.args});switch(l.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let f=u.find(_=>_.id===l.args.branchId);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let f=He(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let f=Ge(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let f=De(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let f=Fe(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return m(),v.bind(null,{subjectId:p,subjectName:"chapter",action:l});case I.openURI.trim().toLowerCase():return m(),S.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{URI:l.args.uri}});default:console.error("Unexpected chapter event"),i.emit(d.errors,new R(1,1,{message:"Unexpected chapter event"}));return}};function y(p){let l=te(p.events);if(l){if(O(p))return;i.emit(d.interactives,{subjectId:p.id,subjectName:"chapter",type:C.actionChoice,actionType:l.action.type,payload:l.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else p.events.forEach(u=>{let m=h({chapterId:p.id,action:u.action,branches:p.branches});m&&e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:u.action.type,action:m})})}let g=({subjectId:p,subjectName:l,action:u})=>{t.pause(),i.emit(d.interactives,{subjectId:p,subjectName:l,type:C.actionExecution,actionType:u?.type??I.expect})},E=({subjectId:p,subjectName:l})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(d.interactives,{subjectId:p,subjectName:l,type:C.actionExecution,actionType:"after-expect"})},v=({subjectId:p,subjectName:l,subjectType:u,action:m})=>{i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type})},k=({subjectId:p,subjectName:l,subjectType:u,action:m,payload:f})=>{f.behaviour="change-chapter",i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type,payload:f})},T=({subjectId:p,subjectName:l,subjectType:u,action:m,payload:f})=>{f.behaviour="change-manifest",i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type,payload:f})},S=({subjectId:p,subjectName:l,subjectType:u,action:m,payload:f})=>{if(!f.URI)return;let _=window.open(f.URI,"_blank","noopener,noreferrer");_&&(_.opener=null),i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type})};return{onControlEvent:o,onContainerEvent:a,onChapterEvent:h,onExpectEvent:g,expectEventHandler:E,setManifestChapterEvents:y,setManifestContainerEvents:c,stopExpect:r,state:s}};import{Subscription as Li,ValueSubject as at}from"@vkontakte/videoplayer-shared";var oe=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let s=t.chapters.find(o=>o.id===n);if(!s)return null;let r=t.media.videos.find(o=>s.videoId===o.id);if(!r)return null;e[n]=Qe(r)}return e[n]}).filter(Boolean)},Mi=i=>{for(let t of i.variants)if(Ri(t)&&"payload"in t)return t.payload.id},Ri=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Qe=i=>{let t=Mi(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Ai=(i,t)=>{for(let e of i.media.videos)if(t===Qe(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},Ke=(i,t)=>i.reduce((e,n)=>{let s=Ai(t,n);return s?[...e,s]:e},[]);var ot=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:s,settings:r}){this.state={history$:new at([]),hasPrevChapter$:new at(!1),prevChapter$:new at(null),isInitialChapter$:new at(!1),isGoBackLimited$:new at(!1)};this.#a=null;this.#h=!1;this.#i=null;this.#d=null;this.#n=null;this.#r=null;this.#o=null;this.#t=new Li;this.#p=!1;this.#u=0;this.#n=e,this.#o=t,this.#r=n,this.#a=s,this.#s=r,this.state?.history$&&this.#t&&this.#t?.add(this.state?.history$.subscribe(o=>{this.state?.prevChapter$.next(o.at(-2)||null),this.state?.hasPrevChapter$.next(o.length>1),this.state?.isInitialChapter$.next(this.getInitialChapterId()===this.#i?.metadata?.initChapterId),this.state?.isGoBackLimited$.next(this.#u===this.#s.maxLength-1)}))}#a;#s;#h;#i;#d;#n;#r;#o;#t;#p;#u;async setManifest(t){!this.#r||!this.#o||(this.#i=t,await this.getProjectHistory(),await this.#r.setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),this.#h||(this.#h=!0,this.#o.emit(d.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return this.#h}async updateHistory(t,e=!0){if(!this.#i)return;this.#p?(this.#p=!1,this.#u++):this.#u=0;let n=this.#i,s=t.length-this.#s.maxLength,r=s>0?t.slice(s):t,o=oe(r,n);if(this.#d=o,this?.state?.history$.next(r),!(!e||!this.#a||!this.#n))try{await this.#a.save(this.#n,o)}catch{this.#o?.emit(d.errors,new R(1,5,"Unable to save interactive history"))}}async goBack(){if(!this.state||!this.#r)return this.#o?.emit(d.errors,new R(1,5,"Cannot go back because HistoryController has not been initialized"));this.#p=!0;let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await this.#r.setChapter({chapterId:e})}async getProjectHistory(){if(!this.#i||!this.#n)return;let t=this.#i,e=[this.getInitialVideoId()];if(this.#a)try{let s=await this.#a.get(this.#n);s.length&&(e=s)}catch{this.#o?.emit(d.errors,new R(1,5,"Error while trying to fetch data"))}let n=Ke(e,t);this?.state?.history$.next(n)}getInitialChapterId(){return this.state?.history$.getValue()?.at(-1)||this.#s.initChapterId||this.#i?.metadata.initChapterId}getInitialVideoId(){if(this.#i){let t=this.getInitialChapterId();return oe([t],this.#i).pop()}return null}destroy(){this.state=null,this.#n=null,this.#a=null,this.#r=null,this.#t?.unsubscribe(),this.#t=null,this.#h=!1,this.#o?.emit(d.historyDestroyed),this.#o=null}};var Ot=class i{constructor(t,e,n,s){this.target=t,this.type=e,this.listener=n,this.options=i._convertOptions(t,s),this.target.addEventListener(e,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(t,e){if(e===void 0)return!1;if(typeof e=="boolean")return e;{let n=new Set(["passive","capture"]),s=Object.keys(e).filter(o=>!n.has(o));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),i._doesSupportObject(t)?e:e.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(t){let e=i._supportsObject;if(e===void 0){e=!1;try{let n={},s={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);let r=()=>{};t.addEventListener("test",r,n),t.removeEventListener("test",r,n)}catch{e=!1}i._supportsObject=e}return e||!1}};var Pt=class{constructor(){this.bindingMap=new rt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,s){if(!this.bindingMap)return;let r=new Ot(t,e,n,s);this.bindingMap.push(e,r)}listenOnce(t,e,n,s){let r=o=>{this.unlisten(t,e,r),n(o)};this.listen(t,e,r,s)}unlisten(t,e,n){if(!this.bindingMap)return;let s=this.bindingMap.get(e)||[];for(let r of s)r.target===t&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(e,r))}removeAll(){if(!this.bindingMap)return;let t=this.bindingMap.getAll();for(let e of t)e.unlisten();this.bindingMap.clear()}};var $t=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 t=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;let e=t.data,n=e.length;for(let s=3;s<n;s+=40)if(e[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let s;e&&(s=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&s&&this.restore(s),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(t,0,0,this.rootElement.width,this.rootElement.height)}};var Bt=class{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=t=>{let e=t??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(e);if(this.isContainerTime(e))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 pe="1.0.16-dev.09968010.0";function Dt(i,t=1){let e="0",n="0",s="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+s},${t})`}var M="SDK_NAME",Je="SDK_NAME-controls-container",pt=()=>document.querySelector(`.${Je}`),me=.4,L={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},de={top:"flex-start",bottom:"flex-end",center:"center"},ue={start:"flex-start",end:"flex-end",center:"center"},fe={start:"left",end:"right",center:"center"},dt=({target:i,props:t})=>{i.style.alignItems=de[t?.text?.gravityVertical]??de.center,i.style.justifyContent=ue[t?.text?.gravityHorizontal]??ue.center,i.style.textAlign=fe[t?.text?.alignment]??fe.start},ut=({target:i,props:t,fallback:e,dependsOn:n})=>{i.style.color=t?.text?.color??e.textColor,i.style.fontSize=`calc(${n.height} * ${t?.text?.size??e.textSize})`,i.textContent=t?.text?.value??e.textContent},ft=({target:i,props:t,fallback:e})=>{i.style.backgroundColor=Dt(t?.background?.color??e.backgroundColor,t?.background?.alpha??e.backgroundAlpha)},mt=({target:i,props:t,fallback:e,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${t?.shape?.border?.width??e.borderWidth}) solid ${Dt(t?.shape?.border?.color??e.borderColor,t?.shape?.border?.alpha??e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${t?.shape?.roundCorners??e.roundCorners})`},W=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Ht="int",Q={AREA:`${Ht}_area`,TEXT:`${Ht}_text`,BUTTON:`${Ht}_bttn`};var $=class{constructor(t){this.control=t}createView(t){let e=document.createElement("div");e.classList.add(`${M}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??L.innerSizesDependOn)==="self"?{height:e.style.height,width:e.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:e,dependsOn:n}}setEvents(t,e){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",r=>{r.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${M}-control-container-${this.control.id}`)}};var yt=i=>{if(i.type.trim().toLowerCase()==="area")return new Gt(i)},Gt=class extends ${constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("button");return r.classList.add(`${M}-${this.control.id}`),r.setAttribute("data-testid",Q.AREA),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",ft({target:r,props:this.control.props,fallback:{...L,backgroundColor:"transparent"}}),mt({target:r,props:this.control.props,fallback:{...L,borderAlpha:0},dependsOn:n}),W({target:r,layoutParams:this.control.layoutParams,fallback:L}),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${M}-${this.control.id}`)}};var gt=()=>{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 vt=i=>{if(i.type.trim().toLowerCase()==="button")return new Ut(i)},Ut=class extends ${constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("button");r.type="button",r.classList.add(`${M}-${this.control.id}`),r.setAttribute("data-testid",Q.BUTTON),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";let o=gt();return W({target:r,layoutParams:this.control.layoutParams,fallback:L}),ft({target:r,props:this.control.props,fallback:L}),mt({target:r,props:this.control.props,fallback:L,dependsOn:n}),dt({target:r,props:this.control.props}),ut({target:o,props:this.control.props,fallback:L,dependsOn:n}),r.append(o),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${M}-${this.control.id}`)}};var ye=i=>{if(i.type.trim().toLowerCase()==="text")return new zt(i)},zt=class extends ${constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("div");r.classList.add(`${M}-${this.control.id}`),r.setAttribute("data-testid",Q.TEXT),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";let o=gt();return W({target:r,layoutParams:this.control.layoutParams,fallback:L}),dt({target:r,props:this.control.props}),ut({target:o,props:this.control.props,fallback:L,dependsOn:n}),r.append(o),s.append(r),t.append(s),this.controlEl=r,s}disable(){}enable(){}getElement(){return document.querySelector(`.${M}-${this.control.id}`)}};var Wt=class{constructor(t){this.layout=t}},ge=i=>{if(i.type.trim().toLowerCase()==="relative")return new X(i)},X=class extends Wt{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,e){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${e.width})`,t.style.height=`calc(var(--interactive-content-height) * ${e.height})`,t.style.left=`calc(var(--interactive-content-width) * ${e.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${e.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var K=class{constructor(t){this.container=t,this.factories=new Map,this.#a()}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),this.#a()}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),this.#a()}#a(){this.controls=this.#s()}#s(){return this.container.controls?.reduce((t,e)=>{let n=e.type.trim().toLowerCase(),s=this.factories.get(n);return s?[...t,s(e)]:[...t]},[])}};var bt=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Qt(i,t)},Qt=class extends K{constructor(t,e){super(t),this.rootElement=e??pt(),this.layout=new X(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",vt),this.addControlFactory("text",ye),this.addControlFactory("area",yt)}createView(t){let e=document.createElement("div");return e.classList.add(`${M}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{let s=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(s,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){let t=this.getElement();t&&(t.style.visibility="hidden")}show(){let t=this.getElement();t&&(t.style.visibility="visible")}enable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=me,this.isDisabled=!0)}removeView(){this.isRemoved||(this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${M}-${this.container.id}`)}};import{Subject as ki,ValueSubject as N,Observable as Ze,once as Ni,Subscription as ji,clientChecker as Oi,combine as Pi}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ct}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as ti}from"@vkontakte/videoplayer-shared";function Ct(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var H=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Y=i=>H(i,"Object"),Et=i=>H(i,"String"),It=i=>H(i,"Array"),xt=i=>H(i,"Number"),ve=i=>H(i,"Function");var Kt=i=>xt(i)&&!isNaN(i);var G=i=>Y(i)&&Object.keys(i).length===0,qt=i=>It(i)&&!i.length;var J=(i,t)=>Et(i)&&(t?i.trim():i).length;var be="video_interactive",Ce="videoint";var ei=250,tt=class{constructor(t){this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=e,this.onError=n,this.lang=s??"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=ii(t),this.resizeObserver=new ResizeObserver(Ct(this.onResize,ei)),this.resizeObserver.observe(this.graphWrapperElement)}onResize=t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))};getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}handleChapterChange=t=>{if(this.isReady){if(this.isHidden||this.hide(),!t?.id){this.onError?.("Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}};handleManifestChange=async(t,e=[])=>{if(!xt(t.graph.edit.chapters[0].x)){this.isReady=!1,this.onError?.("Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let n;try{n=await ti(this.lang,be,Ce)}catch{console.log("Unable to load graph language pack")}let{GraphEditor:s}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new s(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:n}),this.ngEditor.on("control",({name:r,chapterId:o})=>{r==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",r=>{this.lastZoomInfo={...r}})}this.visitedChapterIds=new Set(e),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0};setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function ii(i){let t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height="100%",t.style.width="100%",t.style.display="none",i.append(t),t}var et=class{constructor(){this._containers=[];this._player=null;this.setPlayer=t=>{this._player=t};this.setContainers=t=>{this._containers=t};this.deleteContainer=t=>{this._containers=this._containers.filter(e=>e.id!==t)};this.getNextInteractiveTime=(t=3e3)=>{if(!this._containers.length||this._player===null)return null;let e=-1,n=!1,s=Math.round(this._player.info.position$.getValue()*1e3);for(let r of this._containers){let o=r.startTime-t;if(o<=s&&(r.endTime&&s<=r.endTime||r.endTime===null)){n=!0;break}s<o&&(e=e===-1?o:Math.min(e,o))}return!n&&e!==-1?e:null}}};var B=(i="",t="")=>{let e=i.split("."),n=t.split("."),s=0;for(let r=0;r<Math.max(e.length,n.length)&&!s;r++)e[r]>n[r]?s=1:e[r]<n[r]?s=-1:s=0;return s};import{v4 as ni}from"uuid";var si="3.1",Ee={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ri={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ie=i=>{let t=[];for(let e of i.chapters){let n,s=[];for(let{isDefault:a,...c}of e.branches)a&&(n=c.id),s.push(c);let r=[],o=[];for(let{fallbackStrategy:a,...c}of e.containers){let h=!!c.endTime,y=[ri];switch(a){case"await":h?y=[]:r=[];break;case"default":{let g={type:"onSuspense",action:{type:Ee.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?y=[g]:r=[g];break}case"random":case"weightlessRandom":case"max":case"min":{let g={type:"onSuspense",action:{type:Ee[a],args:{}}};h?y=[g]:r=[g];break}}for(let g of c.controls)o.push({...c,controls:[{...g}],id:ni(),events:y})}t.push({...e,containers:o,events:r,branches:s})}return i.metadata.version=si,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var ai="3.2",xe=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:ai},media:t}}return i};var oi="3.3",ci=(i=[])=>({edit:{chapters:i},view:{}}),Te={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Se=i=>{let t=[],e=[];for(let n of i.chapters){let{id:s,x:r,y:o,...a}=n,c=a.containers.map(h=>({...h,controls:h.controls.map(({subtype:y,type:g,...E})=>({...E,type:y??g})),events:h.events?.length?h.events:[Te]}));t.push({id:s,...a,containers:c,events:a.events?.length?a.events:[Te]}),e.push({id:s,x:r,y:o})}return{...i,chapters:t,graph:ci(e),metadata:{...i.metadata,version:oi}}};var li=[{version:"3.0",migrate:Ie},{version:"3.1",migrate:xe},{version:"3.2",migrate:Se}],Zt=i=>li.reduce((t,e)=>B(t.metadata.version,e.version)?t:e.migrate(t),i);var Zn=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),we=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Xn=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),I=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var _e={metadata:"Object",chapters:"Array"},hi="3.0.0",pi="3.3.0",Tt=i=>{let t=B(i,hi);return t===-1?!1:t===0?!0:B(i,pi)!==1},Ve=i=>{if(!Y(i))return!1;for(let t in _e)if(!i[t]||!H(i[t],_e[t]))return!1;return Tt(i.metadata.version)},St=i=>i.type===we.Text;var R=class{constructor(t,e,...n){this.severity=t;this.category=e;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var q=class{constructor(){this.listeners={}}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t]||[];for(let s=n.length;s>0;s--)if(n[s]===e){n.splice(s,1);break}return this}emit(t,...e){let n=this.listeners[t];return n?(n.forEach(s=>{s(...e)}),!0):!1}listenerCount(t){return this.rawListeners(t).length}rawListeners(t){return this.listeners[t]||[]}};var wt=class{constructor(t){this.fns=[];this.addFn=(t,e=!1)=>{ve(t)&&(this.fns.push(t),e&&this.updateFn())};this.removeFn=(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(t=>t()),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)};this.fn=t,this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as vi}from"@vkontakte/videoplayer-shared";var _t=class{constructor(t){this.loaders={chapterLoaders:t?.chapterLoaders??[],manifestLoaders:t?.manifestLoaders??[]}}async exec(t,e){return di(...this.loaders[t])(e)}};function di(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function it(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function Vt({actions:i,errors:t,chapterId:e,...n}){if(e){let s=i.getManifest(),r=i.getChapter(s.chapters,e);if(r){let o=i.getMedia(s.media,r.videoId),a=i.getGraph(s.graph,r.id);return o?{...n,actions:i,errors:t,result:{chapter:r,media:o,graph:a}}:{...n,errors:it(t,Vt.name,"Could not find media"),actions:i}}}return{...n,errors:it(t,Vt.name,"Could not find chapter"),actions:i}}var ui=async i=>{try{let t={},e;if(Et(i)){e=new URL(i).href;let s=await fetch(e);if(!s.ok)return{};t=await s.json()}else if(Y(i))t=i;else return{};if(!Ve(t))return{};let n=t.metadata.media;if(Et(n)&&!t.media)try{let s;e?s=new URL(n,e).href:(s=new URL(n).href,e=s);let r=await fetch(s);if(!r.ok)throw new Error;t.metadata.media=await r.json()}catch{return yi(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch{return{}}};async function Me(i){let{manifest:t,manifestURL:e}=await ui(i),n=Zt(t);return n.media=fi(n.media,e),delete n.metadata.media,n}function Mt(i,t){if(t)return i.find(e=>e.id===t)}function Xt(i,t){return i.edit?.chapters?i.edit.chapters.find(e=>e.id===t):i.view?.chapters?i.view.chapters.find(e=>e.id===t):void 0}function Yt(i,t){return i.videos.find(e=>e.id===t)}function fi(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let s="url"in n?n.url:"",r=mi(s,t);return{...n,url:r||s}})}))}}function mi(i="",t){try{return new URL(i,t).href}catch{return""}}function yi(i){return B(i,"3.2.0")>=0}var x=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Rt=i=>It(i)&&!qt(i),O=i=>i.order==="end",At=i=>It(i.containers)&&!qt(i.containers)&&O(i),Re=(i,t)=>{let e=i*1e3;return Rt(t.controls)&&e<(t.startTime??0)},Jt=(i,t)=>{let e=i*1e3;return Rt(t.controls)&&e>=(t.startTime??0)&&e<=(t.endTime??1/0)};var U=i=>i.some(t=>t.action.type==="expect"),te=i=>i.find(t=>t.action.type==="expect"),gi=i=>i?.length===1,Lt=i=>gi(i)&&St(i[0]);var Ae=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),Le=(i,t)=>U(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&U(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var Z=class extends _t{constructor(e,n){super(e);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new vi(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(e){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:it},result:null,errors:null,source:e});return n.errors&&this.errorHandler(n.errors),this.manifest=await Me(n.result??e),this}async setInitial(){return this.setNext()}async setNext(e=this.manifest?.metadata.initChapterId){if(!e)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",Vt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Xt,getChapter:Mt,getMedia:Yt,getByBranches:this.getByBranches.bind(this),addErrorMessage:it},result:null,errors:null,chapterId:e}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(e){this.onError(e),console.error("Something went wrong with loaders",{errors:e})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(e=this.manifest?.metadata.initChapterId){if(!e||!this.manifest)return null;let n=Mt(this.manifest.chapters,e);if(n){let s=Yt(this.manifest.media,n.videoId),r=Xt(this.manifest.graph,n.id);if(s)return{chapter:n,media:s,graph:r}}return null}getBranches(e=this.chapter?.id){if(e===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=Mt(this.manifest?.chapters||[],e);return this.getByBranches(n?.branches)}}getByBranches(e=[]){return e.reduce((n,s)=>{let r=this.getByChapterId(s.chapterId);return r&&n.push(r),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return O(this.chapter)}};import{Player as bi}from"@vkontakte/videoplayer-core";import{Subscription as Ne,Tracer as Ci}from"@vkontakte/videoplayer-shared";var ke=i=>{let t=i.variants.find(e=>e.payload?.type==="vk");if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var d={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},nt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},C={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function ee(){let i=new Map;function t({listId:r=Math.random().toString(),itemId:o=Math.random().toString(),...a}){let c=i.get(r),h={...a};return c?c[o]=h:i.set(r,{[o]:h}),{listId:r,itemId:o,...a}}function e(r){r.player.destroy(),r.container.remove(),r.subscription.unsubscribe(),r.statistics?.oneStat.destroy(),r.statistics?.statSubscription.unsubscribe()}function n(r,o){let a=i.get(r);if(!a)throw Error("Can't remove. Not find.");if(o){let c=a[o];c&&e(c),delete a[o],Object.keys(a).length||i.delete(r)}else{for(let c of Object.values(a))e(c);i.delete(r)}}function s(){for(let r of i)n(r[0])}return{createPlayer:t,removePlayer:n,map:i,removeAll:s}}function ie(i,t=[]){let e={},n,s=!t.length;for(let r of i.variants)if(!n&&"cover"in r&&(n=r.cover),"url"in r)switch(r.type.toLowerCase()){case"mp4":(s||t.includes("mp4"))&&(e.MPEG={...e.MPEG,[r.standard??"Invariant quality"]:r.url});break;case"mpeg":(s||t.includes("mpeg"))&&(e.MPEG={...e.MPEG,[r.standard??"Invariant quality"]:r.url});break;case"hls":(s||t.includes("hls"))&&(e={...e,HLS:{type:"url",url:r.url}});break;case"dash":(s||t.includes("dash"))&&(e={...e,DASH_SEP:{compatibilityMode:!0,type:"url",url:r.url}});break;default:break}return{sources:e,thumbUrl:n,title:i.title??""}}var st=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var kt={activePlayerChanged:"sc-active-player-changed",playerCreated:"sc-player-created"},Ei=2;function ne(i){let t=ee(),e=new q,n={},s=null,r=!1,o;i&&a(i);function a(T){s=T}function c(T,S,p){if(!s)throw Error("need to set interactive controller");if(!s.options)return;let u=(t.map.get(T)??{})[S];if(u){n={chapterId:p,listId:T,itemId:S,...u};let m=n.player;n.subscription.add(m.info.currentQuality$.subscribe(f=>{let _=m.info.position$.getValue(),w=m.info.isAutoQualityEnabled$.getValue();if(!(!f||!_||w))for(let V of t.map)Object.values(V[1]).forEach(({player:b})=>{st(b,f)})})).add(m.events.started$.subscribe(()=>{h(S)})),u.container.remove(),s.setPlayer(u.player),r||(s.init(),r=!0),e.emit(kt.activePlayerChanged,{player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function h(T){if(!s)throw Error("need to set interactive controller");if(G(n)||T!==n.itemId)return;let S=s.getChapterBranches(),p=new Set;for(let l of S)p.has(l.media.id)||(await g({media:l.media,chapterId:l.chapter.id,setAsActive:!1,title:l.chapter.label}),p.add(l.media.id))}async function y({chapter:{id:T},media:S}){if(G(n))return;let p=n.player.info.muted$.getValue(),l=n.player.info.currentQuality$.getValue(),u=n.player.info.isAutoQualityEnabled$.getValue(),m=n.player.info.volume$.getValue(),f=n.player.info.currentPlaybackRate$.getValue(),_=!u,w=!1;for(let V of t.map)if(V[0]===S.id){let b=Object.keys(V[1]);for(let A of b)A===n.itemId?(b.length<Ei||(w=!0),t.removePlayer(V[0],A)):(w=!0,c(V[0],A,T),_?st(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(m),n.player.setMuted(p),n.player.setPlaybackRate(f))}else t.removePlayer(V[0]);w||(await g({media:S,chapterId:T,setAsActive:!0,playbackRate:f}),_?st(n.player,l):n.player.setAutoQuality(!0),n.player.setVolume(m),n.player.setMuted(p))}async function g({media:T,chapterId:S,prefetch:p=!0,setAsActive:l=!0,autoplay:u=!1,preferredExt:m,title:f,playbackRate:_}){let w=Math.random().toString(),V=document.createElement("div");o.append(V);let b;if(s?.options?.vkVideoLoader){let ht=ke(T);ht.length&&(b=await s.options.vkVideoLoader(...ht))}let A=s?.options?.coreConfig||{},z={...A,configName:[...A.configName??[],"interactive"]},F={container:V,...b?.videos?.[0]||{sources:ie(T,m).sources},title:f,failoverHosts:b?.failoverHosts||[]},j=new bi(z,Ci.createRootTracer());j.initVideo(F);let lt=null;if(s?.options.createOneStat){let ht=b.videos[0],le=s.options.createOneStat(ht),he=new Ne;he.add(le.attachTo(j)),lt={oneStat:le,statSubscription:he}}let ce=new Ne,Ye=n?.player?.info.isAutoQualityEnabled$.getValue();ce.add(j.events.canplay$.subscribe(function(){Ye||st(j,n.player.info.currentQuality$.getValue()),_&&j.setPlaybackRate(_)}));let D=t.createPlayer({listId:T.id,itemId:w,player:j,container:V,sources:ie(T,m).sources,config:F,subscription:ce,statistics:lt});return l&&c(T.id,D.itemId,S),u&&D.player.play(),p&&!u&&D.player.prepare(),e.emit(kt.playerCreated,D.player),{player:D.player,config:D.config,statistics:D.statistics}}function E(){v(),s=null,o.remove()}function v(){s?.off(d.chapterChanged,y),t.removeAll(),n={},r=!1}async function k(){if(!s)throw Error("need to set interactive controller");v(),o=document.createElement("div");let{media:T,chapter:S}=s.getCurrentChapter();T?(s.on(d.chapterChanged,y),await g({media:T,chapterId:S.id,title:S.label})):console.error("not found")}return{...t,on:e.on.bind(e),off:e.off.bind(e),init:k,setInteractiveController:a,createPlayer:g,removeAll:E,getActivePlayer:function(){return n}}}import{Subscription as Ii}from"@vkontakte/videoplayer-shared";var Nt=class{constructor({player:t,container:e,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:o,ignoreContainerEvent:a,permanentTextControls:c,disabledControls$:h,onRemove:y}){this.container=e,this.branches=n,this.selectBranches=s,this.subscription=new Ii,this.player=t,this.interactiveEvents=r,this.ignoreContainerEvent=a,this.isPermanentText=c&&Lt(e.container.controls),this.disabledControls$=h,this.onRemove=y,this.globalEventEmitter=o,this.gameState=x.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}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(t=>{t?this.container.disable?.():this.container.enable?.()}))}hide=()=>{setTimeout(()=>{this.gameState!==x.end&&(U(this.container.container.events)&&this.gameState===x.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==x.interactive&&this.container.hide?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})))})};show=()=>{if(this.gameState===x.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!0,isFirst:!1});else{let e=Ae({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})},onEvent:(n,s)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})),(this.gameState===x.end||this.gameState===x.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),s(),this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1}))},isEOV:()=>this.gameState===x.end});this.container.createView(e),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&this.container.disable?.()}};selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?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:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let t=U(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})}onEndOfVideo=()=>{this.gameState=x.end,this.selectContainerEvent(!0)};whilePlaying=()=>{if(this.player.experimental.element$.getValue()?.readyState<1||[x.destroyed,x.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Re(e,this.container.container))this.gameState!==x.beforeInteractive&&(this.gameState=x.beforeInteractive,this.onBeforeStartTime());else if(Jt(e,this.container.container))this.gameState!==x.interactive&&(this.gameState=x.interactive,this.onStartTime());else if(this.gameState!==x.afterInteractive){let r=this.gameState;this.gameState=x.afterInteractive,r===x.interactive&&this.onEndTime()}else this.gameState!==x.destroyed&&!this.isPermanentText&&this.removeView();let n=Jt(e,this.container.container),s=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[];this.globalEventEmitter.emit(d.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:s,currentTime:e,isInteractiveTime:n})};reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=x.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.containerRemoved,visibility:!1}),this.gameState=x.removed,this.onRemove?.()}destroy(){this.reset(),this.removeView(),this.gameState=x.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var je=(i=[])=>i.reduce((t,e,n)=>{let s=(e?.controls??[]).filter(r=>!St(r));if(Rt(s)){let r=[e.startTime??0,e.endTime??1/0],o=e.id;if(!n)t.push({subjects:[o],range:r});else{let a=[],c=-1/0,h=1/0,y=[],g=[];for(let E=0;E<t.length;E++){let v=t[E];if(g.push(...v.subjects),v.range[0]<h&&(h=v.range[0]),v.range[1]>c&&(c=v.range[1]),r[0]>=v.range[0]&&r[1]<=v.range[1])return t[E].subjects.push(o),t;r[0]<v.range[0]&&r[1]>v.range[0]&&(a.push(E),y=y.concat(v.subjects)),r[0]>=v.range[0]&&r[0]<=v.range[1]&&(a.push(E),y=y.concat(v.subjects),r[0]=v.range[0]),r[1]>=v.range[0]&&r[1]<=v.range[1]&&(a.push(E),y=y.concat(v.subjects),r[1]=v.range[1])}if(g.push(o),r[0]<=h&&r[1]>=c)return[{subjects:g,range:r}];a.length&&a.reverse().forEach(E=>{t.splice(E,1)}),t.push({subjects:y.concat([o]),range:r})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Oe(){let i={};function t(){for(let a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a];return!0}function e(a){let c={};for(let h in i)+h<=a&&(c[h]=i[h]);return c}function n(a){let c={};for(let h in i)+h>=a&&(c[h]=i[h]);return c}function s({timestamp:a,priority:c,initiator:h}){if(Kt(a)){let y=i[a]??null;if(y&&J(c,!0)){let g={},E=y[c];return E&&(g={...g,...E}),g=G(g)?null:g,g&&J(h,!0)?g[h]??null:g}return y}return null}function r({timestamp:a,priority:c,initiator:h}){if(Kt(a))if(i[a]){if(J(c,!0))if(i[a][c]){if(J(h,!0))if(i[a][c][h]){if(delete i[a][c][h],!G(i[a][c]))return!0}else return!1;if(delete i[a][c],!G(i[a]))return!0}else return!1;return delete i[a]}else return!1}function o({timestamp:a,priority:c,initiator:h,...y}){i[a]?.[c]?.[h]?i[a][c][h].push({...y}):i[a]?.[c]?i[a][c]={...i[a][c],[h]:[{...y}]}:i[a]?i[a]={...i[a],[c]:{[h]:[{...y}]}}:i[a]={[c]:{[h]:[{...y}]}}}return{map:i,remove:r,add:o,removeAll:t,get:s,getLte:e,getGte:n}}var xi=[I.expect,I.setNextBranch],Ti=1/0;function se(i){let t=i,e,n=Si(),s=new Oe,r,o=()=>{E(),p()},a=l=>{s.add.call(void 0,l),k()},c=(l=[])=>{for(let u of l)if(u.action(),xi.includes(u.actionType))break},h=(l=1/0)=>{let u=jt(s.get({timestamp:l,priority:"control"})??{}),m=jt(s.get({timestamp:l,priority:"container"})??{}),f=jt(s.get({timestamp:l,priority:"chapter"})??{});return[...u,...m,...f]},y=l=>{n.isReady(l)&&c(h(l))},g=()=>{c([...jt(s.get({timestamp:1/0,priority:"chapter"})??{})])},E=()=>{e&&(r?.unsubscribe(),e=void 0)},v=l=>{},k=()=>{e||(e=()=>setTimeout(()=>{y(1/0)}),r=t.events.ended$.subscribe(e))},T=l=>{E(),t=l},S=l=>{l.priority==="container"&&n.resetCalled(l.timestamp),s.remove(l)},p=()=>{n.release(),s.removeAll()};return{setPlayer:T,add:a,remove:S,exec:y,execEndOfVideo:g,listen:k,unlisten:E,release:o,containersEventsCallState:n,getPreparedToExecActions:h}}function Si(){let i=new Map;return{setCalled:({timestamp:o,id:a})=>{let c=i.get(o);c&&c[a]!==void 0&&(c[a]=!0)},setData:(o=[])=>{for(let a of o){let c=a.endTime??Ti,h=i.get(c)??{};i.set(c,{...h,[a.id]:!1})}},resetCalled:o=>{let a=i.get(o);if(a)for(let c in a)a[c]=!1},isReady:o=>{let a=i.get(o);return a?!Object.values(a).some(c=>!c):!0},release:()=>i.clear()}}function jt(i){return Object.values(i).flat().sort(t=>t.actionType===I.expect?-1:1)}var Pe={videoContentHeight:0,videoContentWidth:0},$e=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return Pe;let{clientHeight:s,clientWidth:r}=t.experimental.element$.getValue()||{};if(!(s&&r))return Pe;let o=e/n,a=s/r,c,h;return a>o?(h=r,c=r*o):a<o?(h=s/o,c=s):(h=r,c=s),{videoContentWidth:h,videoContentHeight:c}};var wi=250;function Be(i){let t=()=>{},e=new ResizeObserver(a=>{r(a),t=r.bind(null,a)});function n(a){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:y,videoContentHeight:g}=$e(c,h);c.style.setProperty("--interactive-content-width",`${y}px`),c.style.setProperty("--interactive-content-height",`${g}px`),c.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function s(){let{parentElement:a}=i();a.removeAttribute("style")}let r=Ct(a=>{let{fns:c=[]}=i();n(a);for(let h of c)h()},wi);function o(){t=void 0,e.disconnect(),s()}return{resizeObserver:e,calc:()=>{t()},release:o}}var rt=class{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){let e=this.map[t];return e?e.slice():null}getAll(){let t=[];for(let e in this.map)t.concat(this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var _i=i=>Math.floor(Math.random()*i),Fe=i=>{let t=i.length,e=1/0,n=null;for(;t--;)i[t].weight<e&&(e=i[t].weight,n=i[t]);return n},De=i=>{let t=i.length,e=-1/0,n=null;for(;t--;)i[t].weight>e&&(e=i[t].weight,n=i[t]);return n};var He=i=>{let t=i.length,e=_i(t);return i[e]};var Ge=i=>{let t=0;for(let n=0;n<i.length;++n)t+=i[n].weight??1;let e=Math.random()*t;t=0;for(let n=0;n<i.length-1;++n)if(t+=i[n].weight??1,t>=e)return i[n];return i[i.length-1]};var Ue=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var re=(i,t=!1)=>({...i,args:t?{...i.args,...Ue}:{...Ue,...i.args}}),ae=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},o=({action:p,controlType:l,controlId:u,containerId:m,branches:f=[],onEvent:_,isEOV:w=()=>!1,isDisabled:V=()=>!1})=>{let b=re(p,w()),A={timestamp:1/0,priority:"control",initiator:u,actionType:b.type},z=V(),F=i.emit.bind(i,d.interactives,{subjectId:u,subjectType:l,subjectName:"control",type:z?C.actionChoiceCanceled:C.actionChoice,actionType:p.type,payload:{containerId:m,...b.args}});if(z){F();return}switch(b.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let j=f.find(lt=>lt.id===b.args.branchId);if(!j)return;_(b.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),F(),b.args.shouldOpenNow?k({subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}}):(e.add({...A,action:k.bind(null,{subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}})}),n?.());return}case I.continuePlayback.trim().toLowerCase():{_(b.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),F(),b.args.shouldOpenNow?v({subjectId:u,subjectName:"control",subjectType:l,action:p}):e.add({...A,action:v.bind(null,{subjectId:u,subjectName:"control",subjectType:l,action:p})});return}case I.openURI.trim().toLowerCase():{_(b.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),F(),b.args.shouldOpenNow?S({subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{URI:p.args.uri}}):(e.add({...A,action:S.bind(null,{subjectId:u,subjectName:"control",subjectType:l,action:b,payload:{URI:p.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(d.errors,new R(1,1,{message:"Unexpected control event"}));return}},a=({action:p,container:{id:l,endTime:u},branches:m=[],isEOV:f=!1,autoSelected:_=!1})=>{let w=re(p,f),V={timestamp:!w.args.shouldOpenNow||f?1/0:u,priority:"container",initiator:l,actionType:w.type},b=i.emit.bind(i,d.interactives,{subjectId:l,subjectName:"container",type:C.actionChoice,actionType:w.type,payload:w.args});switch(w.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let A=m.find(z=>z.id===w.args.branchId);if(!A)return;b(),e.add({...V,action:k.bind(null,{subjectId:l,subjectName:"container",action:w,payload:{chapterId:A.chapterId,autoSelect:_}})}),n?.();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(),e.add({...V,action:v.bind(null,{subjectId:l,subjectName:"container",action:w})});return}case I.openURI.trim().toLowerCase():{b(),e.add({...V,action:S.bind(null,{subjectId:l,subjectName:"container",action:w,payload:{URI:p.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(d.errors,new R(1,1,{message:"Unexpected container event"}));return}};function c({container:p,branches:l,isEOV:u=!1}){let m=te(p.events);if(m){let f=re(m.action,u);i.emit(d.interactives,{subjectId:p.id,subjectName:"container",type:C.actionChoice,actionType:f.type,payload:f.args}),e.add({timestamp:u?1/0:p.endTime,priority:"container",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"container"})}),s.isExpect=!0}else for(let f of p.events)a({action:f.action,container:p,branches:l,isEOV:u})}let h=({chapterId:p,action:l,branches:u=[]})=>{let m=i.emit.bind(i,d.interactives,{subjectId:p,subjectName:"chapter",type:C.actionChoice,actionType:l.type,payload:l.args});switch(l.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let f=u.find(_=>_.id===l.args.branchId);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let f=He(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let f=Ge(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let f=De(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let f=Fe(u);return f?.chapterId?(m(),k.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:f.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return m(),v.bind(null,{subjectId:p,subjectName:"chapter",action:l});case I.openURI.trim().toLowerCase():return m(),S.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{URI:l.args.uri}});default:console.error("Unexpected chapter event"),i.emit(d.errors,new R(1,1,{message:"Unexpected chapter event"}));return}};function y(p){let l=te(p.events);if(l){if(O(p))return;i.emit(d.interactives,{subjectId:p.id,subjectName:"chapter",type:C.actionChoice,actionType:l.action.type,payload:l.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else p.events.forEach(u=>{let m=h({chapterId:p.id,action:u.action,branches:p.branches});m&&e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:u.action.type,action:m})})}let g=({subjectId:p,subjectName:l,action:u})=>{t.pause(),i.emit(d.interactives,{subjectId:p,subjectName:l,type:C.actionExecution,actionType:u?.type??I.expect})},E=({subjectId:p,subjectName:l})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(d.interactives,{subjectId:p,subjectName:l,type:C.actionExecution,actionType:"after-expect"})},v=({subjectId:p,subjectName:l,subjectType:u,action:m})=>{i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type})},k=({subjectId:p,subjectName:l,subjectType:u,action:m,payload:f})=>{f.behaviour="change-chapter",i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type,payload:f})},T=({subjectId:p,subjectName:l,subjectType:u,action:m,payload:f})=>{f.behaviour="change-manifest",i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type,payload:f})},S=({subjectId:p,subjectName:l,subjectType:u,action:m,payload:f})=>{if(!f.URI)return;let _=window.open(f.URI,"_blank","noopener,noreferrer");_&&(_.opener=null),i.emit(d.interactives,{subjectId:p,subjectName:l,subjectType:u,type:C.actionExecution,actionType:m.type})};return{onControlEvent:o,onContainerEvent:a,onChapterEvent:h,onExpectEvent:g,expectEventHandler:E,setManifestChapterEvents:y,setManifestContainerEvents:c,stopExpect:r,state:s}};import{Subscription as Li,ValueSubject as at}from"@vkontakte/videoplayer-shared";var oe=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let s=t.chapters.find(o=>o.id===n);if(!s)return null;let r=t.media.videos.find(o=>s.videoId===o.id);if(!r)return null;e[n]=Qe(r)}return e[n]}).filter(Boolean)},Mi=i=>{for(let t of i.variants)if(Ri(t)&&"payload"in t)return t.payload.id},Ri=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Qe=i=>{let t=Mi(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Ai=(i,t)=>{for(let e of i.media.videos)if(t===Qe(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},Ke=(i,t)=>i.reduce((e,n)=>{let s=Ai(t,n);return s?[...e,s]:e},[]);var ot=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:s,settings:r}){this.state={history$:new at([]),hasPrevChapter$:new at(!1),prevChapter$:new at(null),isInitialChapter$:new at(!1),isGoBackLimited$:new at(!1)};this.#a=null;this.#h=!1;this.#i=null;this.#d=null;this.#n=null;this.#r=null;this.#o=null;this.#t=new Li;this.#p=!1;this.#u=0;this.#n=e,this.#o=t,this.#r=n,this.#a=s,this.#s=r,this.state?.history$&&this.#t&&this.#t?.add(this.state?.history$.subscribe(o=>{this.state?.prevChapter$.next(o.at(-2)||null),this.state?.hasPrevChapter$.next(o.length>1),this.state?.isInitialChapter$.next(this.getInitialChapterId()===this.#i?.metadata?.initChapterId),this.state?.isGoBackLimited$.next(this.#u===this.#s.maxLength-1)}))}#a;#s;#h;#i;#d;#n;#r;#o;#t;#p;#u;async setManifest(t){!this.#r||!this.#o||(this.#i=t,await this.getProjectHistory(),await this.#r.setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),this.#h||(this.#h=!0,this.#o.emit(d.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return this.#h}async updateHistory(t,e=!0){if(!this.#i)return;this.#p?(this.#p=!1,this.#u++):this.#u=0;let n=this.#i,s=t.length-this.#s.maxLength,r=s>0?t.slice(s):t,o=oe(r,n);if(this.#d=o,this?.state?.history$.next(r),!(!e||!this.#a||!this.#n))try{await this.#a.save(this.#n,o)}catch{this.#o?.emit(d.errors,new R(1,5,"Unable to save interactive history"))}}async goBack(){if(!this.state||!this.#r)return this.#o?.emit(d.errors,new R(1,5,"Cannot go back because HistoryController has not been initialized"));this.#p=!0;let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await this.#r.setChapter({chapterId:e})}async getProjectHistory(){if(!this.#i||!this.#n)return;let t=this.#i,e=[this.getInitialVideoId()];if(this.#a)try{let s=await this.#a.get(this.#n);s.length&&(e=s)}catch{this.#o?.emit(d.errors,new R(1,5,"Error while trying to fetch data"))}let n=Ke(e,t);this?.state?.history$.next(n)}getInitialChapterId(){return this.state?.history$.getValue()?.at(-1)||this.#s.initChapterId||this.#i?.metadata.initChapterId}getInitialVideoId(){if(this.#i){let t=this.getInitialChapterId();return oe([t],this.#i).pop()}return null}destroy(){this.state=null,this.#n=null,this.#a=null,this.#r=null,this.#t?.unsubscribe(),this.#t=null,this.#h=!1,this.#o?.emit(d.historyDestroyed),this.#o=null}};var Ot=class i{constructor(t,e,n,s){this.target=t,this.type=e,this.listener=n,this.options=i._convertOptions(t,s),this.target.addEventListener(e,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(t,e){if(e===void 0)return!1;if(typeof e=="boolean")return e;{let n=new Set(["passive","capture"]),s=Object.keys(e).filter(o=>!n.has(o));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),i._doesSupportObject(t)?e:e.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(t){let e=i._supportsObject;if(e===void 0){e=!1;try{let n={},s={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);let r=()=>{};t.addEventListener("test",r,n),t.removeEventListener("test",r,n)}catch{e=!1}i._supportsObject=e}return e||!1}};var Pt=class{constructor(){this.bindingMap=new rt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,s){if(!this.bindingMap)return;let r=new Ot(t,e,n,s);this.bindingMap.push(e,r)}listenOnce(t,e,n,s){let r=o=>{this.unlisten(t,e,r),n(o)};this.listen(t,e,r,s)}unlisten(t,e,n){if(!this.bindingMap)return;let s=this.bindingMap.get(e)||[];for(let r of s)r.target===t&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(e,r))}removeAll(){if(!this.bindingMap)return;let t=this.bindingMap.getAll();for(let e of t)e.unlisten();this.bindingMap.clear()}};var $t=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 t=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;let e=t.data,n=e.length;for(let s=3;s<n;s+=40)if(e[s]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let s;e&&(s=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&s&&this.restore(s),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(t,0,0,this.rootElement.width,this.rootElement.height)}};var Bt=class{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=t=>{let e=t??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(e);if(this.isContainerTime(e))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.16-dev.7f2d8e7b.0",
3
+ "version": "1.0.16-dev.09968010.0",
4
4
  "author": "vk.com",
5
5
  "description": "Movika interactive SDK",
6
6
  "homepage": "https://vk.com",
@@ -50,9 +50,9 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@interactiveplatform/movika-graph-editor": "^1.11.0",
53
- "@vkontakte/videoplayer-core": "2.0.108-dev.a4d70592.0",
54
- "@vkontakte/videoplayer-shared": "1.0.40-dev.9357735d.0",
55
- "@vkontakte/videoplayer-statistics": "1.0.54-dev.7933a2f4.0",
53
+ "@vkontakte/videoplayer-core": "2.0.108-dev.4eaeede1.0",
54
+ "@vkontakte/videoplayer-shared": "1.0.40-dev.db6498e5.0",
55
+ "@vkontakte/videoplayer-statistics": "1.0.54-dev.efcf1898.0",
56
56
  "uuid": "^9.0.0"
57
57
  }
58
58
  }