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