@vkontakte/videoplayer-interactive 1.0.26-dev.23975e61.0 → 1.0.26-dev.ac7b329a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es2015.cjs.js +3 -3
- package/es2015.esm.js +3 -3
- package/es2018.cjs.js +3 -3
- package/es2018.esm.js +3 -3
- package/esnext.cjs.js +4 -4
- package/esnext.esm.js +4 -4
- package/evergreen.esm.js +3 -3
- package/package.json +4 -4
package/evergreen.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.26-dev.
|
|
3
|
-
* Thu, 21 Nov 2024
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.26-dev.ac7b329a.0
|
|
3
|
+
* Thu, 21 Nov 2024 07:49:17 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-26/doc/
|
|
5
5
|
*/
|
|
6
|
-
var pe="1.0.26-dev.23975e61.0";function Bt(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 A="interactive",ei="interactive-controls-container",pt=()=>document.querySelector(`.${ei}`),he=.4,k={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},de=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(de||{}),ue=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(ue||{}),me=(n=>(n.start="left",n.end="right",n.center="center",n))(me||{}),ht=({target:i,props:t})=>{i.style.alignItems=(t.text?.gravityVertical&&de[t.text.gravityVertical])??"center",i.style.justifyContent=(t.text?.gravityHorizontal&&ue[t.text.gravityHorizontal])??"center",i.style.textAlign=(t.text?.alignment&&me[t.text.alignment])??"left"},dt=({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},ut=({target:i,props:t,fallback:e})=>{i.style.backgroundColor=Bt(t?.background?.color??e.backgroundColor,t?.background?.alpha??e.backgroundAlpha)},mt=({target:i,props:t,fallback:e,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${t?.shape?.border?.width??e.borderWidth}) solid ${Bt(t?.shape?.border?.color??e.borderColor,t?.shape?.border?.alpha??e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${t?.shape?.roundCorners??e.roundCorners})`},W=({target:i,layoutParams:t,fallback:e})=>{let n=t.angle??e.angle;n=n&&n*-1,i.style.transform=`rotate(${n}rad)`};var $=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(`${A}-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 Ht="int",F=(n=>(n.AREA=`${Ht}_area`,n.TEXT=`${Ht}_text`,n.BUTTON=`${Ht}_bttn`,n))(F||{});var ft=i=>{if(i.type.trim().toLowerCase()==="area")return new Dt(i)},Dt=class extends ${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(`${A}-${this.control.id}`),n.setAttribute("data-testid",F.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",ut({target:n,props:this.control.props,fallback:{...k,backgroundColor:"transparent"}}),mt({target:n,props:this.control.props,fallback:{...k,borderAlpha:0},dependsOn:this.container.dimensions}),W({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 yt=()=>{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 gt=i=>{if(i.type.trim().toLowerCase()==="button")return new Gt(i)},Gt=class extends ${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(`${A}-${this.control.id}`),n.setAttribute("data-testid",F.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",W({target:n,layoutParams:this.control.layoutParams,fallback:k}),ut({target:n,props:this.control.props,fallback:k}),mt({target:n,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),ht({target:n,props:this.control.props});let r=yt();dt({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 fe=i=>{if(i.type.trim().toLowerCase()==="text")return new Ut(i)},Ut=class extends ${constructor(t){super(t)}createView({parentElement:t,layoutCallback:e}){if(super.createContainerElement(e),!this.container)return;let n=document.createElement("div");n.classList.add(`${A}-${this.control.id}`),n.setAttribute("data-testid",F.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",W({target:n,layoutParams:this.control.layoutParams,fallback:k}),ht({target:n,props:this.control.props});let r=yt();dt({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 zt=class{constructor(t){this.layout=t}},vt=class extends zt{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 Q=class{constructor(t){this.container=t,this.factories=new Map,this.controls=[],this.setControls()}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),this.setControls()}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((t,e)=>{let n=e.type.trim().toLowerCase(),r=this.factories.get(n);if(r){let s=r(e);if(s)return[...t,s]}return[...t]},[])||[]}};var Ct=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Wt(i,t)},Wt=class extends Q{constructor(t,e){super(t),this.rootElement=e??pt(),this.layout=new vt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",gt),this.addControlFactory("text",fe),this.addControlFactory("area",ft)}createView(t){let e=document.createElement("div");return e.classList.add(`${A}-${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=`${he}`,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(t=>t.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${A}-${this.container.id}`)}};import{clientChecker as $i,combine as Ni,InterfaceLanguage as Oi,Observable as Xe,once as ji,Subject as j,Subscription as Ye,ValueSubject as _}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ot}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as ii}from"@vkontakte/videoplayer-shared";function q(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var B=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,X=i=>B(i,"Object"),bt=i=>B(i,"String"),Et=i=>B(i,"Array"),It=i=>B(i,"Number"),ye=i=>B(i,"Function");var Qt=i=>It(i)&&!isNaN(i);var H=i=>X(i)&&Object.keys(i).length===0,Kt=i=>Et(i)&&!i.length;var Y=(i,t)=>bt(i)&&(t?i.trim():i).length;var ge="video_interactive",ve="videoint";var Ce=250,J=class{constructor(t){this.handleZoomChange=q(t=>{this.lastZoomInfo=t},Ce);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,!It(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=ni(t),this.resizeObserver=new ResizeObserver(q(this.onResize,Ce)),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 ii(this.lang,ge,ve)}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 ni(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 tt=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 ri}from"uuid";var si="3.1",be={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ai={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ee=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 h=!!o.endTime,y=[ai];switch(a){case"await":h?y=[]:s=[];break;case"default":{let g={type:"onSuspense",action:{type:be.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?y=[g]:s=[g];break}case"random":case"weightlessRandom":case"max":case"min":{let g={type:"onSuspense",action:{type:be[a],args:{}}};h?y=[g]:s=[g];break}}for(let g of o.controls)l.push({...o,controls:[{...g}],id:ri(),events:y})}t.push({...e,containers:l,events:s,branches:r})}return i.metadata.version=si,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var oi="3.2",Ie=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:oi},media:t}}return i};var li="3.3",ci=(i=[])=>({edit:{chapters:i},view:{}}),xe={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Te=i=>{let t=[],e=[];for(let n of i.chapters){let{id:r,x:s,y:l,...a}=n,o=a.containers.map(h=>({...h,controls:h.controls.map(({subtype:y,type:g,...C})=>({...C,type:y??g})),events:h.events?.length?h.events:[xe]}));t.push({id:r,...a,containers:o,events:a.events?.length?a.events:[xe]}),e.push({id:r,x:s,y:l})}return{...i,chapters:t,graph:ci(e),metadata:{...i.metadata,version:li}}};var pi=[{version:"3.0",migrate:Ee},{version:"3.1",migrate:Ie},{version:"3.2",migrate:Te}],Zt=i=>pi.reduce((t,e)=>O(t.metadata.version,e.version)?t:e.migrate(t),i);var Se={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 we={metadata:"Object",chapters:"Array"},hi="3.0.0",di="3.3.0",xt=i=>{let t=O(i,hi);return t===-1?!1:t===0?!0:O(i,di)!==1},Me=i=>{if(!X(i))return!1;for(let t in we)if(!i[t]||!B(i[t],we[t]))return!1;return xt(i.metadata.version)},Tt=i=>i.type===Se.Text;var M=class{constructor(t,e,...n){this.severity=t;this.category=e;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var St=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 wt=class{constructor(t){this.fns=[];this.addFn=(t,e=!1)=>{ye(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 Ci}from"@vkontakte/videoplayer-shared";var Mt=class{constructor(t){this.loaders={chapterLoaders:t?.chapterLoaders??[],manifestLoaders:t?.manifestLoaders??[]}}async exec(t,e){return ui(...this.loaders[t])(e)}};function ui(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function et(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function Lt({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:et(t,Lt.name,"Could not find media"),actions:i}}}return{...n,errors:et(t,Lt.name,"Could not find chapter"),actions:i}}var mi=async i=>{try{let t={},e;if(bt(i)){e=new URL(i).href;let r=await fetch(e);if(!r.ok)return{};t=await r.json()}else if(X(i))t=i;else return{};if(!Me(t))return{};let n=t.metadata.media;if(bt(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 gi(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch{return{}}};async function Le(i){let{manifest:t,manifestURL:e}=await mi(i),n=Zt(t);return n.media=fi(n.media,e),delete n.metadata.media,n}function kt(i,t){if(t)return i.find(e=>e.id===t)}function qt(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 Xt(i,t){return i.videos.find(e=>e.id===t)}function fi(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let r="url"in n?n.url:"",s=yi(r,t);return{...n,url:s||r}})}))}}function yi(i="",t){try{return new URL(i,t).href}catch{return""}}function gi(i){return O(i,"3.2.0")>=0}var Vt=i=>Et(i)&&!Kt(i),P=i=>i.order==="end",At=i=>Et(i.containers)&&!Kt(i.containers)&&P(i),ke=(i,t)=>{let e=i*1e3;return Vt(t.controls)&&e<(t.startTime??0)},Yt=(i,t)=>{let e=i*1e3;return Vt(t.controls)&&e>=(t.startTime??0)&&e<=(t.endTime??1/0)};var D=(i=[])=>i.some(t=>t.action.type==="expect"),Jt=(i=[])=>i.find(t=>t.action.type==="expect"),vi=i=>i?.length===1,K=i=>vi(i)&&Tt(i[0]);function Ve(i,...t){return e=>typeof t[0]=="object"&&typeof e=="object"?i({...t[0],...e}):i(...t,...e)}var Ae=(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 Z=class extends Mt{constructor(e,n){super(e);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Ci(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:et},result:null,errors:null,source:e});return n.errors&&this.errorHandler(n.errors),this.manifest=await Le(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",Lt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:qt,getChapter:kt,getMedia:Xt,getByBranches:this.getByBranches.bind(this),addErrorMessage:et},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=kt(this.manifest.chapters,e);if(n){let r=Xt(this.manifest.media,n.videoId),s=qt(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=kt(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?P(this.chapter):!1}};import{Player as bi}from"@vkontakte/videoplayer-core";import{Subscription as ie,Tracer as Ei,ValueSubject as Ii}from"@vkontakte/videoplayer-shared";var _e=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 te(){let i=new Map;function t({listId:s=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let o=i.get(s),h={...a};return o?o[l]=h:i.set(s,{[l]:h}),{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 ee(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 it=(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 xi=2;function ne(i){let t=te(),e=new ie,n={},r=null,s=!1,l,a=new Ii(null);i&&o(i);function o(x){r=x}function h(x,p,c){if(!r)throw Error("need to set interactive controller");if(!r.options)return;let f=(t.map.get(x)??{})[p];if(f){n={chapterId:c,listId:x,itemId:p,...f};let u=n.player;n.subscription.add(u.info.currentQuality$.subscribe(S=>{let T=u.info.position$.getValue(),V=u.info.isAutoQualityEnabled$.getValue();if(!(!S||!T||V))for(let v of t.map)Object.values(v[1]).forEach(({player:w})=>{it(w,S)})})).add(u.events.started$.subscribe(()=>{y(p)})),f.container.remove(),r.setPlayer(f.player),s||(r.init(),s=!0),a.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function y(x){if(!r)throw Error("need to set interactive controller");if(H(n)||x!==n.itemId)return;let p=r.getChapterBranches(),c=new Set;for(let d of p)c.has(d.media.id)||(await C({media:d.media,chapterId:d.chapter.id,setAsActive:!1,title:d.chapter.label}),c.add(d.media.id))}async function g({chapter:{id:x},manifestVideo:p}){if(H(n)||!r)return;let c=n.player.info.muted$.getValue(),d=n.player.info.currentQuality$.getValue(),f=n.player.info.isAutoQualityEnabled$.getValue(),u=n.player.info.volume$.getValue(),S=n.player.info.currentPlaybackRate$.getValue(),T=!f,V=!1;for(let v of t.map)if(v[0]===p.id&&!r.state.isReplay$.getValue()){let w=Object.keys(v[1]);for(let R of w)R===n.itemId?(w.length<xi||(V=!0),t.removePlayer(v[0],R)):(V=!0,h(v[0],R,x),T?it(n.player,d):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(c),n.player.setPlaybackRate(S))}else t.removePlayer(v[0]);V||(await C({media:p,chapterId:x,setAsActive:!0,playbackRate:S}),T?it(n.player,d):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(c))}async function C({media:x,chapterId:p,prefetch:c=!0,setAsActive:d=!0,autoplay:f=!1,preferredExt:u,title:S,playbackRate:T}){let V=Math.random().toString(),v=document.createElement("div");l.append(v);let w;if(r?.options?.vkVideoLoader){let ct=_e(x);ct.length&&(w=await r.options.vkVideoLoader(...ct))}let R=r?.options?.coreConfig||void 0,G={...R,configName:[...R?.configName??[],"interactive"]},U={container:v,...w?.videos?.[0]||{sources:ee(x,u).sources},title:S,failoverHosts:w?.failoverHosts||[]},N=new bi(G,Ei.createRootTracer());N.initVideo(U);let oe=null;if(w?.videos&&r?.options.createOneStat){let ct=w.videos[0],Ft=r.options.createOneStat(ct),ce=new ie;Ft&&(ce.add(Ft.attachTo(N)),oe={oneStat:Ft,statSubscription:ce})}let le=new ie,ti=n?.player?.info.isAutoQualityEnabled$.getValue();le.add(N.events.canplay$.subscribe(function(){ti||it(N,n.player.info.currentQuality$.getValue()),T&&N.setPlaybackRate(T)}));let z=t.createPlayer({listId:x.id,itemId:V,player:N,container:v,sources:ee(x,u).sources,config:U,subscription:le,statistics:oe});return d&&h(x.id,z.itemId,p),f&&z.player.play(),c&&!f&&z.player.prepare(),{player:z.player,config:z.config,statistics:z.statistics}}function E(){L(),r=null,l.remove()}function L(){e.unsubscribe(),t.removeAll(),n={},s=!1}async function lt(){if(!r)throw Error("need to set interactive controller");L(),l=document.createElement("div");let{media:x,chapter:p}=r.getCurrentChapter();x&&p?(e.add(r.events.chapterChanged$.subscribe(g)),await C({media:x,chapterId:p.id,title:p.label})):console.error("not found")}return{...t,init:lt,setInteractiveController:o,createPlayer:C,removeAll:E,getActivePlayer:function(){return n},activePlayerChanged:a}}var m={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},nt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},b={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as Ti}from"@vkontakte/videoplayer-shared";var _t=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEvents:l,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:h,disabledControls$:y,onRemove:g}){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(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})))})};this.show=()=>{if(this.gameState===2&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!0,isFirst:!1});else{let e=Ve(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(e),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.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(ke(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Yt(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let h=this.gameState;this.gameState=3,h===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=Yt(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(m.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Ti,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=h&&K(e.container.controls),this.disabledControls$=y,this.onRemove=g,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,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(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.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 Re=(i=[])=>i.reduce((t,e,n)=>{let r=(e?.controls??[]).filter(s=>!Tt(s));if(Vt(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,h=1/0,y=[],g=[];for(let C=0;C<t.length;C++){let E=t[C];if(g.push(...E.subjects),E.range[0]<h&&(h=E.range[0]),E.range[1]>o&&(o=E.range[1]),s[0]>=E.range[0]&&s[1]<=E.range[1])return t[C].subjects.push(l),t;s[0]<E.range[0]&&s[1]>E.range[0]&&(a.push(C),y=y.concat(E.subjects)),s[0]>=E.range[0]&&s[0]<=E.range[1]&&(a.push(C),y=y.concat(E.subjects),s[0]=E.range[0]),s[1]>=E.range[0]&&s[1]<=E.range[1]&&(a.push(C),y=y.concat(E.subjects),s[1]=E.range[1])}if(g.push(l),s[0]<=h&&s[1]>=o)return[{subjects:g,range:s}];a.length&&a.reverse().forEach(C=>{t.splice(C,1)}),t.push({subjects:y.concat([l]),range:s})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Pe(){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 h in i)+h<=a&&(o[h]=i[h]);return o}function n(a){let o={};for(let h in i)+h>=a&&(o[h]=i[h]);return o}function r({timestamp:a,priority:o,initiator:h}){if(Qt(a)){let y=i[a]??null;if(y&&o&&Y(o,!0)){let g={},C=y[o];return C&&(g={...g,...C}),g=H(g)?null:g,g&&Y(h,!0)?g[h]??null:g}return y}return null}function s({timestamp:a,priority:o,initiator:h}){if(Qt(a))if(i[a]){if(o&&Y(o,!0))if(i[a][o]){if(h&&Y(h,!0))if(i[a][o][h]){if(delete i[a][o][h],!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:h,...y}){i[a]?.[o]?.[h]?i[a][o][h].push({...y}):i[a]?.[o]?i[a][o]={...i[a][o],[h]:[{...y}]}:i[a]?i[a]={...i[a],[o]:{[h]:[{...y}]}}:i[a]={[o]:{[h]:[{...y}]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var Si=[I.expect,I.setNextBranch],wi=1/0;function $e(i){let t=i,e,n=Mi(),r=Pe(),s,l=()=>{C(),p()},a=c=>{r.add.call(void 0,c),L()},o=(c=[])=>{for(let d of c)if(d.action(),Si.includes(d.actionType))break},h=(c=1/0)=>{let d=Rt(r.get({timestamp:c,priority:"control"})??{}),f=Rt(r.get({timestamp:c,priority:"container"})??{}),u=Rt(r.get({timestamp:c,priority:"chapter"})??{});return[...d,...f,...u]},y=c=>{n.isReady(c)&&o(h(c))},g=()=>{o([...Rt(r.get({timestamp:1/0,priority:"chapter"})??{})])},C=()=>{e&&(s?.unsubscribe(),e=void 0)},E=c=>{},L=()=>{e||(e=()=>setTimeout(()=>{y(1/0)}),s=t.events.ended$.subscribe(e))},lt=c=>{C(),t=c},x=c=>{c.priority==="container"&&n.resetCalled(c.timestamp),r.remove(c)},p=()=>{n.release(),r.removeAll()};return{setPlayer:lt,add:a,remove:x,exec:y,execEndOfVideo:g,listen:L,unlisten:C,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function Mi(){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??wi,h=i.get(o)??{};i.set(o,{...h,[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 Rt(i){return Object.values(i).flat().sort(t=>t.actionType===I.expect?-1:1)}var Ne={videoContentHeight:0,videoContentWidth:0},Oe=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return Ne;let{clientHeight:r,clientWidth:s}=t.experimental.element$.getValue()||{};if(!(r&&s))return Ne;let l=e/n,a=r/s,o,h;return a>l?(h=s,o=s*l):a<l?(h=r/l,o=r):(h=s,o=r),{videoContentWidth:h,videoContentHeight:o}};var Li=250;function je(i){let t=()=>{},e=new ResizeObserver(a=>{s(a),t=s.bind(null,a)});function n(a){let{parentElement:o,player:h}=i();if(o&&h){let{videoContentWidth:y,videoContentHeight:g}=Oe(o,h);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=q(a=>{let{fns:o=[]}=i();n(a);for(let h of o)h()},Li);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t?.()},release:l}}var rt=class{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){let e=this.map[t];return e?e.slice():null}getAll(){let t=[];for(let e in this.map)t.concat(this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var ki=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},He=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 De=i=>{let t=i.length,e=ki(t);return i[e]},Fe=1,Ge=i=>{let t=0;for(let n=0;n<i.length;++n)t+=i[n].weight??Fe;let e=Math.random()*t;t=0;for(let n=0;n<i.length-1;++n)if(t+=i[n].weight??Fe,t>=e)return i[n];return i[i.length-1]};var Ue={shouldOpenNow:!0,isDetachContainer:!0};var re=(i,t=!1)=>({...i,args:t?{...i.args,...Ue}:{...Ue,...i.args}}),Qe=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:p,controlType:c,controlId:d,containerId:f,branches:u=[],onEvent:S,isEOV:T=()=>!1,isDisabled:V=()=>!1})=>{let v=re(p,T()),w={timestamp:1/0,priority:"control",initiator:d,actionType:v.type},R=V(),G=i.emit.bind(i,m.interactives,{subjectId:d,subjectType:c,subjectName:"control",type:R?b.actionChoiceCanceled:b.actionChoice,actionType:p.type,payload:{containerId:f,...v.args}});if(R){G();return}switch(v.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let U=u.find(N=>N.id===v.args.branchId);if(!U)return;S(v.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),v.args.shouldOpenNow?L({subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{chapterId:U.chapterId,autoSelect:!1}}):(e.add({...w,action:L.bind(null,{subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{chapterId:U.chapterId,autoSelect:!1}})}),n?.());return}case I.continuePlayback.trim().toLowerCase():{S(v.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),v.args.shouldOpenNow?E({subjectId:d,subjectName:"control",subjectType:c,action:p}):e.add({...w,action:E.bind(null,{subjectId:d,subjectName:"control",subjectType:c,action:p})});return}case I.openURI.trim().toLowerCase():{S(v.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),v.args.shouldOpenNow?x({subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{URI:p.args.uri}}):(e.add({...w,action:x.bind(null,{subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{URI:p.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(m.errors,new M(1,1,{message:"Unexpected control event"}));return}},a=({action:p,container:{id:c,endTime:d},branches:f=[],isEOV:u=!1,autoSelected:S=!1})=>{let T=re(p,u),V={timestamp:!T.args.shouldOpenNow||u?1/0:d??1/0,priority:"container",initiator:c,actionType:T.type},v=i.emit.bind(i,m.interactives,{subjectId:c,subjectName:"container",type:b.actionChoice,actionType:T.type,payload:T.args});switch(T.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let w=f.find(R=>R.id===T.args.branchId);if(!w)return;v(),e.add({...V,action:L.bind(null,{subjectId:c,subjectName:"container",action:T,payload:{chapterId:w.chapterId,autoSelect:S}})}),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({...V,action:E.bind(null,{subjectId:c,subjectName:"container",action:T})});return}case I.openURI.trim().toLowerCase():{v(),e.add({...V,action:x.bind(null,{subjectId:c,subjectName:"container",action:T,payload:{URI:p.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(m.errors,new M(1,1,{message:"Unexpected container event"}));return}};function o({container:p,branches:c,isEOV:d=!1}){let f=Jt(p.events);if(f){let u=re(f.action,d);i.emit(m.interactives,{subjectId:p.id,subjectName:"container",type:b.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:d?1/0:p.endTime??1/0,priority:"container",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of p.events??[])a({action:u.action,container:p,branches:c,isEOV:d})}let h=({chapterId:p,action:c,branches:d=[]})=>{let f=i.emit.bind(i,m.interactives,{subjectId:p,subjectName:"chapter",type:b.actionChoice,actionType:c.type,payload:c.args});switch(c.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let u=d.find(S=>S.id===c.args.branchId);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let u=De(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let u=Ge(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let u=He(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let u=Be(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return f(),E.bind(null,{subjectId:p,subjectName:"chapter",action:c});case I.openURI.trim().toLowerCase():return f(),x.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{URI:c.args.uri}});default:console.error("Unexpected chapter event"),i.emit(m.errors,new M(1,1,{message:"Unexpected chapter event"}));return}};function y(p){let c=Jt(p.events);if(c){if(P(p))return;i.emit(m.interactives,{subjectId:p.id,subjectName:"chapter",type:b.actionChoice,actionType:c.action.type,payload:c.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else p.events?.forEach(d=>{let f=h({chapterId:p.id,action:d.action,branches:p.branches});f&&e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:d.action.type,action:f})})}let g=({subjectId:p,subjectName:c})=>{t.pause(),i.emit(m.interactives,{subjectId:p,subjectName:c,type:b.actionExecution,actionType:I.expect})},C=({subjectId:p,subjectName:c})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(m.interactives,{subjectId:p,subjectName:c,type:b.actionExecution,actionType:"after-expect"})},E=({subjectId:p,subjectName:c,subjectType:d,action:f})=>{i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type})},L=({subjectId:p,subjectName:c,subjectType:d,action:f,payload:u})=>{u.behaviour="change-chapter",i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type,payload:u})},lt=({subjectId:p,subjectName:c,subjectType:d,action:f,payload:u})=>{u.behaviour="change-manifest",i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type,payload:u})},x=({subjectId:p,subjectName:c,subjectType:d,action:f,payload:u})=>{if(!u.URI)return;let S=window.open(u.URI,"_blank","noopener,noreferrer");S&&(S.opener=null),i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:h,onExpectEvent:g,expectEventHandler:C,setManifestChapterEvents:y,setManifestContainerEvents:o,stopExpect:s,state:r}};import{Subscription as Pi,Subject as ae,ValueSubject as st}from"@vkontakte/videoplayer-shared";var se=(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]=Ke(s)}return e[n]}).filter(Boolean)},Ai=i=>{for(let t of i.variants)if(_i(t)&&"payload"in t)return t.payload.id},_i=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Ke=i=>{let t=Ai(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Ri=(i,t)=>{for(let e of i.media.videos)if(t===Ke(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},Ze=(i,t)=>i.reduce((e,n)=>{let r=Ri(t,n);return r?[...e,r]:e},[]);var at=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new st([]),hasPrevChapter$:new st(!1),prevChapter$:new st(null),isInitialChapter$:new st(!1),isGoBackLimited$:new st(!1)};this.#i=null;this.#a=!1;this.#t=null;this.#p=null;this.events={inited$:new ae,destroyed$:new ae,error$:new ae};this.#n=null;this.#r=null;this.#e=null;this.#o=new Pi;this.#l=!1;this.#c=0;this.#n=e,this.#e=t,this.#r=n,this.#i=r,this.#s=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.#t?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#s.maxLength-1)}))}#i;#s;#a;#t;#p;#n;#r;#e;#o;#l;#c;async setManifest(t){if(!this.#r||!this.#e)return;this.#t=t,await this.getProjectHistory();let e=this.getInitialChapterId();await this.#r.setChapter({chapterId:e,pushToHistory:!1}),this.#a||(this.#a=!0,this.events.inited$.next({initChapterId:e}))}get inited(){return this.#a}async updateHistory(t,e=!0){if(!this.#t)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#t,r=t.length-this.#s.maxLength,s=r>0?t.slice(r):t,l=se(s,n);if(this.#p=l,this.state.history$.next(s),!(!e||!this.#i||!this.#n))try{await this.#i.save(this.#n,l)}catch{let o=new M(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#e?.emit(m.errors,o)}}async goBack(){if(!this.state||!this.#r){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#e?.emit(m.errors,n)}this.#l=!0;let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await this.#r.setChapter({chapterId:e,playPrev:!0})}async getProjectHistory(){if(!this.#t||!this.#n)return;let t=this.#t,e=[this.getInitialVideoId()];if(this.#i)try{let r=await this.#i.get(this.#n);r.length&&(e=r)}catch{let s=new M(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#e?.emit(m.errors,s)}let n=Ze(e,t);this.state.history$.next(n)}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||this.#s.initChapterId||this.#t?.metadata.initChapterId}getInitialVideoId(){if(this.#t){let t=this.getInitialChapterId();return se([t],this.#t).pop()}return null}destroy(){this.#n=null,this.#i=null,this.#r=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#e?.emit(m.historyDestroyed),this.events.destroyed$.next(),this.#e=null}};var Pt=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 $t=class{constructor(){this.bindingMap=new rt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Pt(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 Ot=class{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=t=>{let e=t??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(e);if(this.isContainerTime(e))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
var pe="1.0.26-dev.ac7b329a.0";function Bt(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 A="interactive",ei="interactive-controls-container",pt=()=>document.querySelector(`.${ei}`),he=.4,k={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},de=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(de||{}),ue=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(ue||{}),me=(n=>(n.start="left",n.end="right",n.center="center",n))(me||{}),ht=({target:i,props:t})=>{i.style.alignItems=(t.text?.gravityVertical&&de[t.text.gravityVertical])??"center",i.style.justifyContent=(t.text?.gravityHorizontal&&ue[t.text.gravityHorizontal])??"center",i.style.textAlign=(t.text?.alignment&&me[t.text.alignment])??"left"},dt=({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},ut=({target:i,props:t,fallback:e})=>{i.style.backgroundColor=Bt(t?.background?.color??e.backgroundColor,t?.background?.alpha??e.backgroundAlpha)},mt=({target:i,props:t,fallback:e,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${t?.shape?.border?.width??e.borderWidth}) solid ${Bt(t?.shape?.border?.color??e.borderColor,t?.shape?.border?.alpha??e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${t?.shape?.roundCorners??e.roundCorners})`},W=({target:i,layoutParams:t,fallback:e})=>{let n=t.angle??e.angle;n=n&&n*-1,i.style.transform=`rotate(${n}rad)`};var $=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(`${A}-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 Ht="int",F=(n=>(n.AREA=`${Ht}_area`,n.TEXT=`${Ht}_text`,n.BUTTON=`${Ht}_bttn`,n))(F||{});var ft=i=>{if(i.type.trim().toLowerCase()==="area")return new Dt(i)},Dt=class extends ${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(`${A}-${this.control.id}`),n.setAttribute("data-testid",F.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",ut({target:n,props:this.control.props,fallback:{...k,backgroundColor:"transparent"}}),mt({target:n,props:this.control.props,fallback:{...k,borderAlpha:0},dependsOn:this.container.dimensions}),W({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 yt=()=>{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 gt=i=>{if(i.type.trim().toLowerCase()==="button")return new Gt(i)},Gt=class extends ${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(`${A}-${this.control.id}`),n.setAttribute("data-testid",F.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",W({target:n,layoutParams:this.control.layoutParams,fallback:k}),ut({target:n,props:this.control.props,fallback:k}),mt({target:n,props:this.control.props,fallback:k,dependsOn:this.container.dimensions}),ht({target:n,props:this.control.props});let r=yt();dt({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 fe=i=>{if(i.type.trim().toLowerCase()==="text")return new Ut(i)},Ut=class extends ${constructor(t){super(t)}createView({parentElement:t,layoutCallback:e}){if(super.createContainerElement(e),!this.container)return;let n=document.createElement("div");n.classList.add(`${A}-${this.control.id}`),n.setAttribute("data-testid",F.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",W({target:n,layoutParams:this.control.layoutParams,fallback:k}),ht({target:n,props:this.control.props});let r=yt();dt({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 zt=class{constructor(t){this.layout=t}},vt=class extends zt{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 Q=class{constructor(t){this.container=t,this.factories=new Map,this.controls=[],this.setControls()}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),this.setControls()}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),this.setControls()}setControls(){this.controls=this.chooseControls()}chooseControls(){return this.container.controls?.reduce((t,e)=>{let n=e.type.trim().toLowerCase(),r=this.factories.get(n);if(r){let s=r(e);if(s)return[...t,s]}return[...t]},[])||[]}};var Ct=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Wt(i,t)},Wt=class extends Q{constructor(t,e){super(t),this.rootElement=e??pt(),this.layout=new vt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",gt),this.addControlFactory("text",fe),this.addControlFactory("area",ft)}createView(t){let e=document.createElement("div");return e.classList.add(`${A}-${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=`${he}`,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(t=>t.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${A}-${this.container.id}`)}};import{clientChecker as $i,combine as Ni,InterfaceLanguage as Oi,Observable as Xe,once as ji,Subject as j,Subscription as Ye,ValueSubject as _}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ot}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as ii}from"@vkontakte/videoplayer-shared";function q(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var B=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,X=i=>B(i,"Object"),bt=i=>B(i,"String"),Et=i=>B(i,"Array"),It=i=>B(i,"Number"),ye=i=>B(i,"Function");var Qt=i=>It(i)&&!isNaN(i);var H=i=>X(i)&&Object.keys(i).length===0,Kt=i=>Et(i)&&!i.length;var Y=(i,t)=>bt(i)&&(t?i.trim():i).length;var ge="video_interactive",ve="videoint";var Ce=250,J=class{constructor(t){this.handleZoomChange=q(t=>{this.lastZoomInfo=t},Ce);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,!It(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=ni(t),this.resizeObserver=new ResizeObserver(q(this.onResize,Ce)),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 ii(this.lang,ge,ve)}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 ni(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 tt=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 ri}from"uuid";var si="3.1",be={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ai={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ee=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 h=!!o.endTime,y=[ai];switch(a){case"await":h?y=[]:s=[];break;case"default":{let g={type:"onSuspense",action:{type:be.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?y=[g]:s=[g];break}case"random":case"weightlessRandom":case"max":case"min":{let g={type:"onSuspense",action:{type:be[a],args:{}}};h?y=[g]:s=[g];break}}for(let g of o.controls)l.push({...o,controls:[{...g}],id:ri(),events:y})}t.push({...e,containers:l,events:s,branches:r})}return i.metadata.version=si,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var oi="3.2",Ie=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:oi},media:t}}return i};var li="3.3",ci=(i=[])=>({edit:{chapters:i},view:{}}),xe={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Te=i=>{let t=[],e=[];for(let n of i.chapters){let{id:r,x:s,y:l,...a}=n,o=a.containers.map(h=>({...h,controls:h.controls.map(({subtype:y,type:g,...C})=>({...C,type:y??g})),events:h.events?.length?h.events:[xe]}));t.push({id:r,...a,containers:o,events:a.events?.length?a.events:[xe]}),e.push({id:r,x:s,y:l})}return{...i,chapters:t,graph:ci(e),metadata:{...i.metadata,version:li}}};var pi=[{version:"3.0",migrate:Ee},{version:"3.1",migrate:Ie},{version:"3.2",migrate:Te}],Zt=i=>pi.reduce((t,e)=>O(t.metadata.version,e.version)?t:e.migrate(t),i);var Se={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 we={metadata:"Object",chapters:"Array"},hi="3.0.0",di="3.3.0",xt=i=>{let t=O(i,hi);return t===-1?!1:t===0?!0:O(i,di)!==1},Me=i=>{if(!X(i))return!1;for(let t in we)if(!i[t]||!B(i[t],we[t]))return!1;return xt(i.metadata.version)},Tt=i=>i.type===Se.Text;var M=class{constructor(t,e,...n){this.severity=t;this.category=e;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var St=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 wt=class{constructor(t){this.fns=[];this.addFn=(t,e=!1)=>{ye(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 Ci}from"@vkontakte/videoplayer-shared";var Mt=class{constructor(t){this.loaders={chapterLoaders:t?.chapterLoaders??[],manifestLoaders:t?.manifestLoaders??[]}}async exec(t,e){return ui(...this.loaders[t])(e)}};function ui(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function et(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function Lt({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:et(t,Lt.name,"Could not find media"),actions:i}}}return{...n,errors:et(t,Lt.name,"Could not find chapter"),actions:i}}var mi=async i=>{try{let t={},e;if(bt(i)){e=new URL(i).href;let r=await fetch(e);if(!r.ok)return{};t=await r.json()}else if(X(i))t=i;else return{};if(!Me(t))return{};let n=t.metadata.media;if(bt(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 gi(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch{return{}}};async function Le(i){let{manifest:t,manifestURL:e}=await mi(i),n=Zt(t);return n.media=fi(n.media,e),delete n.metadata.media,n}function kt(i,t){if(t)return i.find(e=>e.id===t)}function qt(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 Xt(i,t){return i.videos.find(e=>e.id===t)}function fi(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let r="url"in n?n.url:"",s=yi(r,t);return{...n,url:s||r}})}))}}function yi(i="",t){try{return new URL(i,t).href}catch{return""}}function gi(i){return O(i,"3.2.0")>=0}var Vt=i=>Et(i)&&!Kt(i),P=i=>i.order==="end",At=i=>Et(i.containers)&&!Kt(i.containers)&&P(i),ke=(i,t)=>{let e=i*1e3;return Vt(t.controls)&&e<(t.startTime??0)},Yt=(i,t)=>{let e=i*1e3;return Vt(t.controls)&&e>=(t.startTime??0)&&e<=(t.endTime??1/0)};var D=(i=[])=>i.some(t=>t.action.type==="expect"),Jt=(i=[])=>i.find(t=>t.action.type==="expect"),vi=i=>i?.length===1,K=i=>vi(i)&&Tt(i[0]);function Ve(i,...t){return e=>typeof t[0]=="object"&&typeof e=="object"?i({...t[0],...e}):i(...t,...e)}var Ae=(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 Z=class extends Mt{constructor(e,n){super(e);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new Ci(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:et},result:null,errors:null,source:e});return n.errors&&this.errorHandler(n.errors),this.manifest=await Le(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",Lt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:qt,getChapter:kt,getMedia:Xt,getByBranches:this.getByBranches.bind(this),addErrorMessage:et},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=kt(this.manifest.chapters,e);if(n){let r=Xt(this.manifest.media,n.videoId),s=qt(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=kt(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?P(this.chapter):!1}};import{Player as bi}from"@vkontakte/videoplayer-core";import{Subscription as ie,Tracer as Ei,ValueSubject as Ii}from"@vkontakte/videoplayer-shared";var _e=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 te(){let i=new Map;function t({listId:s=Math.random().toString(),itemId:l=Math.random().toString(),...a}){let o=i.get(s),h={...a};return o?o[l]=h:i.set(s,{[l]:h}),{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 ee(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 it=(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 xi=2;function ne(i){let t=te(),e=new ie,n={},r=null,s=!1,l,a=new Ii(null);i&&o(i);function o(x){r=x}function h(x,p,c){if(!r)throw Error("need to set interactive controller");if(!r.options)return;let f=(t.map.get(x)??{})[p];if(f){n={chapterId:c,listId:x,itemId:p,...f};let u=n.player;n.subscription.add(u.info.currentQuality$.subscribe(S=>{let T=u.info.position$.getValue(),V=u.info.isAutoQualityEnabled$.getValue();if(!(!S||!T||V))for(let v of t.map)Object.values(v[1]).forEach(({player:w})=>{it(w,S)})})).add(u.events.started$.subscribe(()=>{y(p)})),f.container.remove(),r.setPlayer(f.player),s||(r.init(),s=!0),a.next({player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function y(x){if(!r)throw Error("need to set interactive controller");if(H(n)||x!==n.itemId)return;let p=r.getChapterBranches(),c=new Set;for(let d of p)c.has(d.media.id)||(await C({media:d.media,chapterId:d.chapter.id,setAsActive:!1,title:d.chapter.label}),c.add(d.media.id))}async function g({chapter:{id:x},manifestVideo:p}){if(H(n)||!r)return;let c=n.player.info.muted$.getValue(),d=n.player.info.currentQuality$.getValue(),f=n.player.info.isAutoQualityEnabled$.getValue(),u=n.player.info.volume$.getValue(),S=n.player.info.currentPlaybackRate$.getValue(),T=!f,V=!1;for(let v of t.map)if(v[0]===p.id&&!r.state.isReplay$.getValue()){let w=Object.keys(v[1]);for(let R of w)R===n.itemId?(w.length<xi||(V=!0),t.removePlayer(v[0],R)):(V=!0,h(v[0],R,x),T?it(n.player,d):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(c),n.player.setPlaybackRate(S))}else t.removePlayer(v[0]);V||(await C({media:p,chapterId:x,setAsActive:!0,playbackRate:S}),T?it(n.player,d):n.player.setAutoQuality(!0),n.player.setVolume(u),n.player.setMuted(c))}async function C({media:x,chapterId:p,prefetch:c=!0,setAsActive:d=!0,autoplay:f=!1,preferredExt:u,title:S,playbackRate:T}){let V=Math.random().toString(),v=document.createElement("div");l.append(v);let w;if(r?.options?.vkVideoLoader){let ct=_e(x);ct.length&&(w=await r.options.vkVideoLoader(...ct))}let R=r?.options?.coreConfig||void 0,G={...R,configName:[...R?.configName??[],"interactive"]},U={container:v,...w?.videos?.[0]||{sources:ee(x,u).sources},title:S,failoverHosts:w?.failoverHosts||[]},N=new bi(G,Ei.createRootTracer());N.initVideo(U);let oe=null;if(w?.videos&&r?.options.createOneStat){let ct=w.videos[0],Ft=r.options.createOneStat(ct),ce=new ie;Ft&&(ce.add(Ft.attachTo(N)),oe={oneStat:Ft,statSubscription:ce})}let le=new ie,ti=n?.player?.info.isAutoQualityEnabled$.getValue();le.add(N.events.canplay$.subscribe(function(){ti||it(N,n.player.info.currentQuality$.getValue()),T&&N.setPlaybackRate(T)}));let z=t.createPlayer({listId:x.id,itemId:V,player:N,container:v,sources:ee(x,u).sources,config:U,subscription:le,statistics:oe});return d&&h(x.id,z.itemId,p),f&&z.player.play(),c&&!f&&z.player.prepare(),{player:z.player,config:z.config,statistics:z.statistics}}function E(){L(),r=null,l.remove()}function L(){e.unsubscribe(),t.removeAll(),n={},s=!1}async function lt(){if(!r)throw Error("need to set interactive controller");L(),l=document.createElement("div");let{media:x,chapter:p}=r.getCurrentChapter();x&&p?(e.add(r.events.chapterChanged$.subscribe(g)),await C({media:x,chapterId:p.id,title:p.label})):console.error("not found")}return{...t,init:lt,setInteractiveController:o,createPlayer:C,removeAll:E,getActivePlayer:function(){return n},activePlayerChanged:a}}var m={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},nt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},b={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};import{Subscription as Ti}from"@vkontakte/videoplayer-shared";var _t=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEvents:l,globalEventEmitter:a,ignoreContainerEvent:o,permanentTextControls:h,disabledControls$:y,onRemove:g}){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(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})))})};this.show=()=>{if(this.gameState===2&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!0,isFirst:!1});else{let e=Ve(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})),(this.gameState===4||this.gameState===3||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(e),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.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(ke(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Yt(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let h=this.gameState;this.gameState=3,h===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let l=Yt(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[],o={subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:l};this.globalEventEmitter.emit(m.eachTick,o),this.globalEvents.eachTick$.next(o)};this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Ti,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=h&&K(e.container.controls),this.disabledControls$=y,this.onRemove=g,this.globalEventEmitter=a,this.gameState=0,this.globalEvents=l,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(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=1}removeView(){this.container.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.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 Re=(i=[])=>i.reduce((t,e,n)=>{let r=(e?.controls??[]).filter(s=>!Tt(s));if(Vt(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,h=1/0,y=[],g=[];for(let C=0;C<t.length;C++){let E=t[C];if(g.push(...E.subjects),E.range[0]<h&&(h=E.range[0]),E.range[1]>o&&(o=E.range[1]),s[0]>=E.range[0]&&s[1]<=E.range[1])return t[C].subjects.push(l),t;s[0]<E.range[0]&&s[1]>E.range[0]&&(a.push(C),y=y.concat(E.subjects)),s[0]>=E.range[0]&&s[0]<=E.range[1]&&(a.push(C),y=y.concat(E.subjects),s[0]=E.range[0]),s[1]>=E.range[0]&&s[1]<=E.range[1]&&(a.push(C),y=y.concat(E.subjects),s[1]=E.range[1])}if(g.push(l),s[0]<=h&&s[1]>=o)return[{subjects:g,range:s}];a.length&&a.reverse().forEach(C=>{t.splice(C,1)}),t.push({subjects:y.concat([l]),range:s})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Pe(){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 h in i)+h<=a&&(o[h]=i[h]);return o}function n(a){let o={};for(let h in i)+h>=a&&(o[h]=i[h]);return o}function r({timestamp:a,priority:o,initiator:h}){if(Qt(a)){let y=i[a]??null;if(y&&o&&Y(o,!0)){let g={},C=y[o];return C&&(g={...g,...C}),g=H(g)?null:g,g&&Y(h,!0)?g[h]??null:g}return y}return null}function s({timestamp:a,priority:o,initiator:h}){if(Qt(a))if(i[a]){if(o&&Y(o,!0))if(i[a][o]){if(h&&Y(h,!0))if(i[a][o][h]){if(delete i[a][o][h],!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:h,...y}){i[a]?.[o]?.[h]?i[a][o][h].push({...y}):i[a]?.[o]?i[a][o]={...i[a][o],[h]:[{...y}]}:i[a]?i[a]={...i[a],[o]:{[h]:[{...y}]}}:i[a]={[o]:{[h]:[{...y}]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var Si=[I.expect,I.setNextBranch],wi=1/0;function $e(i){let t=i,e,n=Mi(),r=Pe(),s,l=()=>{C(),p()},a=c=>{r.add.call(void 0,c),L()},o=(c=[])=>{for(let d of c)if(d.action(),Si.includes(d.actionType))break},h=(c=1/0)=>{let d=Rt(r.get({timestamp:c,priority:"control"})??{}),f=Rt(r.get({timestamp:c,priority:"container"})??{}),u=Rt(r.get({timestamp:c,priority:"chapter"})??{});return[...d,...f,...u]},y=c=>{n.isReady(c)&&o(h(c))},g=()=>{o([...Rt(r.get({timestamp:1/0,priority:"chapter"})??{})])},C=()=>{e&&(s?.unsubscribe(),e=void 0)},E=c=>{},L=()=>{e||(e=()=>setTimeout(()=>{y(1/0)}),s=t.events.ended$.subscribe(e))},lt=c=>{C(),t=c},x=c=>{c.priority==="container"&&n.resetCalled(c.timestamp),r.remove(c)},p=()=>{n.release(),r.removeAll()};return{setPlayer:lt,add:a,remove:x,exec:y,execEndOfVideo:g,listen:L,unlisten:C,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function Mi(){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??wi,h=i.get(o)??{};i.set(o,{...h,[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 Rt(i){return Object.values(i).flat().sort(t=>t.actionType===I.expect?-1:1)}var Ne={videoContentHeight:0,videoContentWidth:0},Oe=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return Ne;let{clientHeight:r,clientWidth:s}=t.experimental.element$.getValue()||{};if(!(r&&s))return Ne;let l=e/n,a=r/s,o,h;return a>l?(h=s,o=s*l):a<l?(h=r/l,o=r):(h=s,o=r),{videoContentWidth:h,videoContentHeight:o}};var Li=250;function je(i){let t=()=>{},e=new ResizeObserver(a=>{s(a),t=s.bind(null,a)});function n(a){let{parentElement:o,player:h}=i();if(o&&h){let{videoContentWidth:y,videoContentHeight:g}=Oe(o,h);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=q(a=>{let{fns:o=[]}=i();n(a);for(let h of o)h()},Li);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t?.()},release:l}}var rt=class{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){let e=this.map[t];return e?e.slice():null}getAll(){let t=[];for(let e in this.map)t.concat(this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var ki=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},He=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 De=i=>{let t=i.length,e=ki(t);return i[e]},Fe=1,Ge=i=>{let t=0;for(let n=0;n<i.length;++n)t+=i[n].weight??Fe;let e=Math.random()*t;t=0;for(let n=0;n<i.length-1;++n)if(t+=i[n].weight??Fe,t>=e)return i[n];return i[i.length-1]};var Ue={shouldOpenNow:!0,isDetachContainer:!0};var re=(i,t=!1)=>({...i,args:t?{...i.args,...Ue}:{...Ue,...i.args}}),Qe=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:p,controlType:c,controlId:d,containerId:f,branches:u=[],onEvent:S,isEOV:T=()=>!1,isDisabled:V=()=>!1})=>{let v=re(p,T()),w={timestamp:1/0,priority:"control",initiator:d,actionType:v.type},R=V(),G=i.emit.bind(i,m.interactives,{subjectId:d,subjectType:c,subjectName:"control",type:R?b.actionChoiceCanceled:b.actionChoice,actionType:p.type,payload:{containerId:f,...v.args}});if(R){G();return}switch(v.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let U=u.find(N=>N.id===v.args.branchId);if(!U)return;S(v.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),v.args.shouldOpenNow?L({subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{chapterId:U.chapterId,autoSelect:!1}}):(e.add({...w,action:L.bind(null,{subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{chapterId:U.chapterId,autoSelect:!1}})}),n?.());return}case I.continuePlayback.trim().toLowerCase():{S(v.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),v.args.shouldOpenNow?E({subjectId:d,subjectName:"control",subjectType:c,action:p}):e.add({...w,action:E.bind(null,{subjectId:d,subjectName:"control",subjectType:c,action:p})});return}case I.openURI.trim().toLowerCase():{S(v.args.isDetachContainer,C.bind(null,{subjectId:d,subjectName:"control"})),G(),v.args.shouldOpenNow?x({subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{URI:p.args.uri}}):(e.add({...w,action:x.bind(null,{subjectId:d,subjectName:"control",subjectType:c,action:v,payload:{URI:p.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(m.errors,new M(1,1,{message:"Unexpected control event"}));return}},a=({action:p,container:{id:c,endTime:d},branches:f=[],isEOV:u=!1,autoSelected:S=!1})=>{let T=re(p,u),V={timestamp:!T.args.shouldOpenNow||u?1/0:d??1/0,priority:"container",initiator:c,actionType:T.type},v=i.emit.bind(i,m.interactives,{subjectId:c,subjectName:"container",type:b.actionChoice,actionType:T.type,payload:T.args});switch(T.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let w=f.find(R=>R.id===T.args.branchId);if(!w)return;v(),e.add({...V,action:L.bind(null,{subjectId:c,subjectName:"container",action:T,payload:{chapterId:w.chapterId,autoSelect:S}})}),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({...V,action:E.bind(null,{subjectId:c,subjectName:"container",action:T})});return}case I.openURI.trim().toLowerCase():{v(),e.add({...V,action:x.bind(null,{subjectId:c,subjectName:"container",action:T,payload:{URI:p.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(m.errors,new M(1,1,{message:"Unexpected container event"}));return}};function o({container:p,branches:c,isEOV:d=!1}){let f=Jt(p.events);if(f){let u=re(f.action,d);i.emit(m.interactives,{subjectId:p.id,subjectName:"container",type:b.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:d?1/0:p.endTime??1/0,priority:"container",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of p.events??[])a({action:u.action,container:p,branches:c,isEOV:d})}let h=({chapterId:p,action:c,branches:d=[]})=>{let f=i.emit.bind(i,m.interactives,{subjectId:p,subjectName:"chapter",type:b.actionChoice,actionType:c.type,payload:c.args});switch(c.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let u=d.find(S=>S.id===c.args.branchId);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let u=De(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let u=Ge(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let u=He(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let u=Be(d);return u?.chapterId?(f(),L.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return f(),E.bind(null,{subjectId:p,subjectName:"chapter",action:c});case I.openURI.trim().toLowerCase():return f(),x.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{URI:c.args.uri}});default:console.error("Unexpected chapter event"),i.emit(m.errors,new M(1,1,{message:"Unexpected chapter event"}));return}};function y(p){let c=Jt(p.events);if(c){if(P(p))return;i.emit(m.interactives,{subjectId:p.id,subjectName:"chapter",type:b.actionChoice,actionType:c.action.type,payload:c.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else p.events?.forEach(d=>{let f=h({chapterId:p.id,action:d.action,branches:p.branches});f&&e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:d.action.type,action:f})})}let g=({subjectId:p,subjectName:c})=>{t.pause(),i.emit(m.interactives,{subjectId:p,subjectName:c,type:b.actionExecution,actionType:I.expect})},C=({subjectId:p,subjectName:c})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(m.interactives,{subjectId:p,subjectName:c,type:b.actionExecution,actionType:"after-expect"})},E=({subjectId:p,subjectName:c,subjectType:d,action:f})=>{i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type})},L=({subjectId:p,subjectName:c,subjectType:d,action:f,payload:u})=>{u.behaviour="change-chapter",i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type,payload:u})},lt=({subjectId:p,subjectName:c,subjectType:d,action:f,payload:u})=>{u.behaviour="change-manifest",i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type,payload:u})},x=({subjectId:p,subjectName:c,subjectType:d,action:f,payload:u})=>{if(!u.URI)return;let S=window.open(u.URI,"_blank","noopener,noreferrer");S&&(S.opener=null),i.emit(m.interactives,{subjectId:p,subjectName:c,subjectType:d,type:b.actionExecution,actionType:f.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:h,onExpectEvent:g,expectEventHandler:C,setManifestChapterEvents:y,setManifestContainerEvents:o,stopExpect:s,state:r}};import{Subscription as Pi,Subject as ae,ValueSubject as st}from"@vkontakte/videoplayer-shared";var se=(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]=Ke(s)}return e[n]}).filter(Boolean)},Ai=i=>{for(let t of i.variants)if(_i(t)&&"payload"in t)return t.payload.id},_i=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Ke=i=>{let t=Ai(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Ri=(i,t)=>{for(let e of i.media.videos)if(t===Ke(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},Ze=(i,t)=>i.reduce((e,n)=>{let r=Ri(t,n);return r?[...e,r]:e},[]);var at=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new st([]),hasPrevChapter$:new st(!1),prevChapter$:new st(null),isInitialChapter$:new st(!1),isGoBackLimited$:new st(!1)};this.#i=null;this.#a=!1;this.#t=null;this.#p=null;this.events={inited$:new ae,destroyed$:new ae,error$:new ae};this.#n=null;this.#r=null;this.#e=null;this.#o=new Pi;this.#l=!1;this.#c=0;this.#n=e,this.#e=t,this.#r=n,this.#i=r,this.#s=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.#t?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#s.maxLength-1)}))}#i;#s;#a;#t;#p;#n;#r;#e;#o;#l;#c;async setManifest(t){if(!this.#r||!this.#e)return;this.#t=t,await this.getProjectHistory();let e=this.getInitialChapterId();await this.#r.setChapter({chapterId:e,pushToHistory:!1}),this.#a||(this.#a=!0,this.events.inited$.next({initChapterId:e}))}get inited(){return this.#a}async updateHistory(t,e=!0){if(!this.#t)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#t,r=t.length-this.#s.maxLength,s=r>0?t.slice(r):t,l=se(s,n);if(this.#p=l,this.state.history$.next(s),!(!e||!this.#i||!this.#n))try{await this.#i.save(this.#n,l)}catch{let o=new M(1,5,"Unable to save interactive history");this.events.error$.next(o),this.#e?.emit(m.errors,o)}}async goBack(){if(!this.state||!this.#r){let n=new M(1,5,"Unable to save interactive history");return this.events.error$.next(n),this.#e?.emit(m.errors,n)}this.#l=!0;let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await this.#r.setChapter({chapterId:e,playPrev:!0})}async getProjectHistory(){if(!this.#t||!this.#n)return;let t=this.#t,e=[this.getInitialVideoId()];if(this.#i)try{let r=await this.#i.get(this.#n);r.length&&(e=r)}catch{let s=new M(1,5,"Error while trying to fetch data");this.events.error$.next(s),this.#e?.emit(m.errors,s)}let n=Ze(e,t);this.state.history$.next(n)}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||this.#s.initChapterId||this.#t?.metadata.initChapterId}getInitialVideoId(){if(this.#t){let t=this.getInitialChapterId();return se([t],this.#t).pop()}return null}destroy(){this.#n=null,this.#i=null,this.#r=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#e?.emit(m.historyDestroyed),this.events.destroyed$.next(),this.#e=null}};var Pt=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 $t=class{constructor(){this.bindingMap=new rt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Pt(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 Ot=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.26-dev.
|
|
3
|
+
"version": "1.0.26-dev.ac7b329a.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.118-dev.
|
|
54
|
-
"@vkontakte/videoplayer-shared": "1.0.
|
|
55
|
-
"@vkontakte/videoplayer-statistics": "1.0.65-dev.
|
|
53
|
+
"@vkontakte/videoplayer-core": "2.0.118-dev.7e946179.0",
|
|
54
|
+
"@vkontakte/videoplayer-shared": "^1.0.49",
|
|
55
|
+
"@vkontakte/videoplayer-statistics": "1.0.65-dev.8b300994.0",
|
|
56
56
|
"uuid": "^9.0.0"
|
|
57
57
|
}
|
|
58
58
|
}
|