@vkontakte/videoplayer-interactive 1.0.19-dev.c9e593de.0 → 1.0.19-dev.d5db4341.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 +6 -6
- package/es2015.esm.js +6 -6
- package/es2018.cjs.js +6 -6
- package/es2018.esm.js +6 -6
- package/esnext.cjs.js +6 -6
- package/esnext.esm.js +6 -6
- package/evergreen.esm.js +6 -6
- package/package.json +5 -5
- package/types/index.d.ts +2 -3
- package/types/manifest/index.d.ts +3 -0
- package/types/manifest/utils.d.ts +11 -0
- package/types/modules/Graph/Graph.d.ts +2 -2
- package/types/modules/Interactives/Interactives.d.ts +21 -16
- package/types/modules/Interactives/Layout.d.ts +7 -7
- package/types/modules/Interactives/controls/Control.d.ts +3 -4
- package/types/modules/Interactives/controls/types.d.ts +4 -5
- package/types/modules/Interactives/index.d.ts +2 -1
- package/types/modules/Interactives/types.d.ts +12 -15
- package/types/modules/Interactives/utils/GameController.d.ts +35 -16
- package/types/modules/Interactives/utils/GroupsStack.d.ts +31 -21
- package/types/modules/Interactives/utils/HistoryController.d.ts +4 -4
- package/types/modules/Interactives/utils/InteractiveEvents.d.ts +16 -10
- package/types/modules/Interactives/utils/ResizeManager.d.ts +8 -1
- package/types/modules/Interactives/utils/SelectBranches.d.ts +15 -51
- package/types/modules/Interactives/utils/SelectBranches.types.d.ts +73 -0
- package/types/modules/Interactives/utils/events.d.ts +8 -0
- package/types/modules/Interactives/utils/fallbackStrategies.d.ts +23 -6
- package/types/modules/Interactives/utils/gameUtils.d.ts +28 -26
- package/types/modules/Interactives/utils/getInteractiveRanges.d.ts +2 -3
- package/types/modules/Interactives/utils/renderingUtils.d.ts +64 -59
- package/types/modules/Loaders/vkVideoLoader/types.d.ts +2 -2
- package/types/modules/Loaders/vkVideoLoader/utils.d.ts +1 -1
- package/types/modules/ManifestController/ManifestController.d.ts +11 -12
- package/types/modules/ManifestController/utils.d.ts +6 -6
- package/types/modules/SeamlessController/SeamlessController.d.ts +10 -12
- package/types/modules/SeamlessController/utils.d.ts +2 -2
- package/types/modules/SeekToInteractiveController/SeekToInteractiveController.d.ts +2 -2
- package/types/utils/LastFrame.d.ts +1 -1
- package/types/utils/chapterHelpers.d.ts +1 -1
- package/types/utils/extractVkMovieId.d.ts +2 -2
- package/types/movika.core/manifest/index.d.ts +0 -23
- package/types/movika.core/manifest/manifest_3_2/chapter.d.ts +0 -62
- package/types/movika.core/manifest/manifest_3_2/control.d.ts +0 -67
- package/types/movika.core/manifest/manifest_3_2/manifest.d.ts +0 -50
- package/types/movika.core/manifest/manifest_3_2/template.d.ts +0 -34
- package/types/movika.core/manifest/manifest_3_3/chapter.d.ts +0 -70
- package/types/movika.core/manifest/manifest_3_3/control.d.ts +0 -66
- package/types/movika.core/manifest/manifest_3_3/graph.d.ts +0 -73
- package/types/movika.core/manifest/manifest_3_3/manifest.d.ts +0 -52
- package/types/movika.core/manifest/manifest_3_3/template.d.ts +0 -34
- package/types/movika.core/manifest/migrations/index.d.ts +0 -1
- package/types/movika.core/manifest/migrations/migrateManifestToLatestVersion.d.ts +0 -1
- package/types/movika.core/manifest/migrations/migrate_from_3_0_to_3_1.d.ts +0 -21
- package/types/movika.core/manifest/migrations/migrate_from_3_1_to_3_2.d.ts +0 -2
- package/types/movika.core/manifest/migrations/migrate_from_3_2_to_3_3.d.ts +0 -8
- package/types/movika.core/manifest/types.d.ts +0 -29
- package/types/movika.core/manifest/utils.d.ts +0 -5
package/evergreen.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.19-dev.
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.19-dev.d5db4341.0
|
|
3
|
+
* Mon, 30 Sep 2024 16:19:41 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-19/doc/
|
|
5
5
|
*/
|
|
6
|
-
var le="1.0.19-dev.c9e593de.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",Ye="interactive-controls-container",ht=()=>document.querySelector(`.${Ye}`),de=.4,R={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},ce={top:"flex-start",bottom:"flex-end",center:"center"},he={start:"flex-start",end:"flex-end",center:"center"},pe={start:"left",end:"right",center:"center"},pt=({target:i,props:t})=>{i.style.alignItems=ce[t?.text?.gravityVertical]??ce.center,i.style.justifyContent=he[t?.text?.gravityHorizontal]??he.center,i.style.textAlign=pe[t?.text?.alignment]??pe.start},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})=>{i.style.transform=`rotate(${-t.angle}rad)`};var O=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??R.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",H=(n=>(n.AREA=`${Ht}_area`,n.TEXT=`${Ht}_text`,n.BUTTON=`${Ht}_bttn`,n))(H||{});var ft=i=>{if(i.type.trim().toLowerCase()==="area")return new Dt(i)},Dt=class extends O{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",H.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:{...R,backgroundColor:"transparent"}}),mt({target:n,props:this.control.props,fallback:{...R,borderAlpha:0},dependsOn:this.container.dimensions}),W({target:n,layoutParams:this.control.layoutParams,fallback: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 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 O{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",H.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:R}),ut({target:n,props:this.control.props,fallback:R}),mt({target:n,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),pt({target:n,props:this.control.props});let r=yt();dt({target:r,props:this.control.props,fallback:R,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 ue=i=>{if(i.type.trim().toLowerCase()==="text")return new zt(i)},zt=class extends O{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",H.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:R}),pt({target:n,props:this.control.props});let r=yt();dt({target:r,props:this.control.props,fallback:R,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),t.append(this.container.element),this.controlElement=n}disable(){}enable(){}getElement(){return this.controlElement}};var Ut=class{constructor(t){this.layout=t}},vt=class extends Ut{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,e){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${e.width})`,t.style.height=`calc(var(--interactive-content-height) * ${e.height})`,t.style.left=`calc(var(--interactive-content-width) * ${e.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${e.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var Q=class{constructor(t){this.container=t,this.factories=new Map,this.#t()}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),this.#t()}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),this.#t()}#t(){this.controls=this.#n()}#n(){return this.container.controls?.reduce((t,e)=>{let n=e.type.trim().toLowerCase(),r=this.factories.get(n);return r?[...t,r(e)]:[...t]},[])}};var bt=(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??ht(),this.layout=new vt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",gt),this.addControlFactory("text",ue),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=de,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 Ri,combine as ki,InterfaceLanguage as Ai,Observable as Ze,once as Ni,Subject as Pi,Subscription as ji,ValueSubject as N}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as ot}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Je}from"@vkontakte/videoplayer-shared";function q(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var D=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,X=i=>D(i,"Object"),Ct=i=>D(i,"String"),Et=i=>D(i,"Array"),It=i=>D(i,"Number"),me=i=>D(i,"Function");var Qt=i=>It(i)&&!isNaN(i);var G=i=>X(i)&&Object.keys(i).length===0,Kt=i=>Et(i)&&!i.length;var Y=(i,t)=>Ct(i)&&(t?i.trim():i).length;var fe="video_interactive",ye="videoint";var ge=250,J=class{constructor(t){this.handleZoomChange=q(t=>{this.lastZoomInfo=t},ge);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=ti(t),this.resizeObserver=new ResizeObserver(q(this.onResize,ge)),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 Je(this.lang,fe,ye)}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 ti(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 F=(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 ei}from"uuid";var ii="3.1",ve={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ni={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},be=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=[ni];switch(a){case"await":h?y=[]:s=[];break;case"default":{let g={type:"onSuspense",action:{type:ve.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:ve[a],args:{}}};h?y=[g]:s=[g];break}}for(let g of o.controls)l.push({...o,controls:[{...g}],id:ei(),events:y})}t.push({...e,containers:l,events:s,branches:r})}return i.metadata.version=ii,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var ri="3.2",Ce=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:ri},media:t}}return i};var si="3.3",ai=(i=[])=>({edit:{chapters:i},view:{}}),Ee={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ie=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,...E})=>({...E,type:y??g})),events:h.events?.length?h.events:[Ee]}));t.push({id:r,...a,containers:o,events:a.events?.length?a.events:[Ee]}),e.push({id:r,x:s,y:l})}return{...i,chapters:t,graph:ai(e),metadata:{...i.metadata,version:si}}};var oi=[{version:"3.0",migrate:be},{version:"3.1",migrate:Ce},{version:"3.2",migrate:Ie}],Zt=i=>oi.reduce((t,e)=>F(t.metadata.version,e.version)?t:e.migrate(t),i);var qn=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),xe=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Xn=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),I=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var Te={metadata:"Object",chapters:"Array"},li="3.0.0",ci="3.3.0",xt=i=>{let t=F(i,li);return t===-1?!1:t===0?!0:F(i,ci)!==1},Se=i=>{if(!X(i))return!1;for(let t in Te)if(!i[t]||!D(i[t],Te[t]))return!1;return xt(i.metadata.version)},Tt=i=>i.type===xe.Text;var _=class{constructor(t,e,...n){this.severity=t;this.category=e;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var K=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 St=class{constructor(t){this.fns=[];this.addFn=(t,e=!1)=>{me(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 yi}from"@vkontakte/videoplayer-shared";var wt=class{constructor(t){this.loaders={chapterLoaders:t?.chapterLoaders??[],manifestLoaders:t?.manifestLoaders??[]}}async exec(t,e){return hi(...this.loaders[t])(e)}};function hi(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function et(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function Mt({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,Mt.name,"Could not find media"),actions:i}}}return{...n,errors:et(t,Mt.name,"Could not find chapter"),actions:i}}var pi=async i=>{try{let t={},e;if(Ct(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(!Se(t))return{};let n=t.metadata.media;if(Ct(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 mi(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch{return{}}};async function we(i){let{manifest:t,manifestURL:e}=await pi(i),n=Zt(t);return n.media=di(n.media,e),delete n.metadata.media,n}function Vt(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 di(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let r="url"in n?n.url:"",s=ui(r,t);return{...n,url:s||r}})}))}}function ui(i="",t){try{return new URL(i,t).href}catch{return""}}function mi(i){return F(i,"3.2.0")>=0}var x=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),_t=i=>Et(i)&&!Kt(i),j=i=>i.order==="end",Lt=i=>Et(i.containers)&&!Kt(i.containers)&&j(i),Me=(i,t)=>{let e=i*1e3;return _t(t.controls)&&e<(t.startTime??0)},Yt=(i,t)=>{let e=i*1e3;return _t(t.controls)&&e>=(t.startTime??0)&&e<=(t.endTime??1/0)};var z=i=>i.some(t=>t.action.type==="expect"),Jt=i=>i.find(t=>t.action.type==="expect"),fi=i=>i?.length===1,Rt=i=>fi(i)&&Tt(i[0]);var Ve=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),_e=(i,t)=>z(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&z(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var Z=class extends wt{constructor(e,n){super(e);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new yi(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 we(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",Mt({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:qt,getChapter:Vt,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=Vt(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=Vt(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 j(this.chapter)}};import{Player as gi}from"@vkontakte/videoplayer-core";import{Subscription as Re,Tracer as vi}from"@vkontakte/videoplayer-shared";var Le=i=>{let t=i.variants.find(e=>e.payload?.type==="vk");if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var d={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},it={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},C={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};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 nt=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var kt={activePlayerChanged:"sc-active-player-changed",playerCreated:"sc-player-created"},bi=2;function ie(i){let t=te(),e=new K,n={},r=null,s=!1,l;i&&a(i);function a(T){r=T}function o(T,S,p){if(!r)throw Error("need to set interactive controller");if(!r.options)return;let u=(t.map.get(T)??{})[S];if(u){n={chapterId:p,listId:T,itemId:S,...u};let f=n.player;n.subscription.add(f.info.currentQuality$.subscribe(m=>{let M=f.info.position$.getValue(),w=f.info.isAutoQualityEnabled$.getValue();if(!(!m||!M||w))for(let V of t.map)Object.values(V[1]).forEach(({player:v})=>{nt(v,m)})})).add(f.events.started$.subscribe(()=>{h(S)})),u.container.remove(),r.setPlayer(u.player),s||(r.init(),s=!0),e.emit(kt.activePlayerChanged,{player:n.player,config:n.config,statistics:n.statistics});return}throw Error("Can't set. Not find.")}async function h(T){if(!r)throw Error("need to set interactive controller");if(G(n)||T!==n.itemId)return;let S=r.getChapterBranches(),p=new Set;for(let c of S)p.has(c.media.id)||(await g({media:c.media,chapterId:c.chapter.id,setAsActive:!1,title:c.chapter.label}),p.add(c.media.id))}async function y({chapter:{id:T},media:S}){if(G(n))return;let p=n.player.info.muted$.getValue(),c=n.player.info.currentQuality$.getValue(),u=n.player.info.isAutoQualityEnabled$.getValue(),f=n.player.info.volume$.getValue(),m=n.player.info.currentPlaybackRate$.getValue(),M=!u,w=!1;for(let V of t.map)if(V[0]===S.id){let v=Object.keys(V[1]);for(let L of v)L===n.itemId?(v.length<bi||(w=!0),t.removePlayer(V[0],L)):(w=!0,o(V[0],L,T),M?nt(n.player,c):n.player.setAutoQuality(!0),n.player.setVolume(f),n.player.setMuted(p),n.player.setPlaybackRate(m))}else t.removePlayer(V[0]);w||(await g({media:S,chapterId:T,setAsActive:!0,playbackRate:m}),M?nt(n.player,c):n.player.setAutoQuality(!0),n.player.setVolume(f),n.player.setMuted(p))}async function g({media:T,chapterId:S,prefetch:p=!0,setAsActive:c=!0,autoplay:u=!1,preferredExt:f,title:m,playbackRate:M}){let w=Math.random().toString(),V=document.createElement("div");l.append(V);let v;if(r?.options?.vkVideoLoader){let ct=Le(T);ct.length&&(v=await r.options.vkVideoLoader(...ct))}let L=r?.options?.coreConfig||{},U={...L,configName:[...L.configName??[],"interactive"]},$={container:V,...v?.videos?.[0]||{sources:ee(T,f).sources},title:m,failoverHosts:v?.failoverHosts||[]},P=new gi(U,vi.createRootTracer());P.initVideo($);let lt=null;if(v?.videos&&r?.options.createOneStat){let ct=v.videos[0],ae=r.options.createOneStat(ct),oe=new Re;oe.add(ae.attachTo(P)),lt={oneStat:ae,statSubscription:oe}}let se=new Re,Xe=n?.player?.info.isAutoQualityEnabled$.getValue();se.add(P.events.canplay$.subscribe(function(){Xe||nt(P,n.player.info.currentQuality$.getValue()),M&&P.setPlaybackRate(M)}));let B=t.createPlayer({listId:T.id,itemId:w,player:P,container:V,sources:ee(T,f).sources,config:$,subscription:se,statistics:lt});return c&&o(T.id,B.itemId,S),u&&B.player.play(),p&&!u&&B.player.prepare(),e.emit(kt.playerCreated,B.player),{player:B.player,config:B.config,statistics:B.statistics}}function E(){b(),r=null,l.remove()}function b(){r?.off(d.chapterChanged,y),t.removeAll(),n={},s=!1}async function k(){if(!r)throw Error("need to set interactive controller");b(),l=document.createElement("div");let{media:T,chapter:S}=r.getCurrentChapter();T?(r.on(d.chapterChanged,y),await g({media:T,chapterId:S.id,title:S.label})):console.error("not found")}return{...t,on:e.on.bind(e),off:e.off.bind(e),init:k,setInteractiveController:a,createPlayer:g,removeAll:E,getActivePlayer:function(){return n}}}import{Subscription as Ci}from"@vkontakte/videoplayer-shared";var At=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:a,permanentTextControls:o,disabledControls$:h,onRemove:y}){this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Ci,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=o&&Rt(e.container.controls),this.disabledControls$=h,this.onRemove=y,this.globalEventEmitter=l,this.gameState=x.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(t=>{t?this.container.disable?.():this.container.enable?.()}))}hide=()=>{setTimeout(()=>{this.gameState!==x.end&&(z(this.container.container.events)&&this.gameState===x.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==x.interactive&&this.container.hide?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})))})};show=()=>{if(this.gameState===x.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!0,isFirst:!1});else{let e=Ve({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})),(this.gameState===x.end||this.gameState===x.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1}))},isEOV:()=>this.gameState===x.end});this.container.createView(e),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&this.container.disable?.()}};selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let t=z(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.visibility,visibility:!1})}onEndOfVideo=()=>{this.gameState=x.end,this.selectContainerEvent(!0)};whilePlaying=()=>{if(this.player.experimental.element$.getValue()?.readyState<1||[x.destroyed,x.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Me(e,this.container.container))this.gameState!==x.beforeInteractive&&(this.gameState=x.beforeInteractive,this.onBeforeStartTime());else if(Yt(e,this.container.container))this.gameState!==x.interactive&&(this.gameState=x.interactive,this.onStartTime());else if(this.gameState!==x.afterInteractive){let s=this.gameState;this.gameState=x.afterInteractive,s===x.interactive&&this.onEndTime()}else this.gameState!==x.destroyed&&!this.isPermanentText&&this.removeView();let n=Yt(e,this.container.container),r=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[];this.globalEventEmitter.emit(d.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:r,currentTime:e,isInteractiveTime:n})};reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=x.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(d.interactives,{subjectId:this.container.container.id,subjectName:"container",type:C.containerRemoved,visibility:!1}),this.gameState=x.removed,this.onRemove?.()}destroy(){this.reset(),this.removeView(),this.gameState=x.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id})}};var ke=(i=[])=>i.reduce((t,e,n)=>{let r=(e?.controls??[]).filter(s=>!Tt(s));if(_t(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 E=0;E<t.length;E++){let b=t[E];if(g.push(...b.subjects),b.range[0]<h&&(h=b.range[0]),b.range[1]>o&&(o=b.range[1]),s[0]>=b.range[0]&&s[1]<=b.range[1])return t[E].subjects.push(l),t;s[0]<b.range[0]&&s[1]>b.range[0]&&(a.push(E),y=y.concat(b.subjects)),s[0]>=b.range[0]&&s[0]<=b.range[1]&&(a.push(E),y=y.concat(b.subjects),s[0]=b.range[0]),s[1]>=b.range[0]&&s[1]<=b.range[1]&&(a.push(E),y=y.concat(b.subjects),s[1]=b.range[1])}if(g.push(l),s[0]<=h&&s[1]>=o)return[{subjects:g,range:s}];a.length&&a.reverse().forEach(E=>{t.splice(E,1)}),t.push({subjects:y.concat([l]),range:s})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Ae(){let i={};function t(){for(let a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a];return!0}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&&Y(o,!0)){let g={},E=y[o];return E&&(g={...g,...E}),g=G(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(Y(o,!0))if(i[a][o]){if(Y(h,!0))if(i[a][o][h]){if(delete i[a][o][h],!G(i[a][o]))return!0}else return!1;if(delete i[a][o],!G(i[a]))return!0}else return!1;return delete i[a]}else 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 Ei=[I.expect,I.setNextBranch],Ii=1/0;function Ne(i){let t=i,e,n=xi(),r=new Ae,s,l=()=>{E(),p()},a=c=>{r.add.call(void 0,c),k()},o=(c=[])=>{for(let u of c)if(u.action(),Ei.includes(u.actionType))break},h=(c=1/0)=>{let u=Nt(r.get({timestamp:c,priority:"control"})??{}),f=Nt(r.get({timestamp:c,priority:"container"})??{}),m=Nt(r.get({timestamp:c,priority:"chapter"})??{});return[...u,...f,...m]},y=c=>{n.isReady(c)&&o(h(c))},g=()=>{o([...Nt(r.get({timestamp:1/0,priority:"chapter"})??{})])},E=()=>{e&&(s?.unsubscribe(),e=void 0)},b=c=>{},k=()=>{e||(e=()=>setTimeout(()=>{y(1/0)}),s=t.events.ended$.subscribe(e))},T=c=>{E(),t=c},S=c=>{c.priority==="container"&&n.resetCalled(c.timestamp),r.remove(c)},p=()=>{n.release(),r.removeAll()};return{setPlayer:T,add:a,remove:S,exec:y,execEndOfVideo:g,listen:k,unlisten:E,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function xi(){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??Ii,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 Nt(i){return Object.values(i).flat().sort(t=>t.actionType===I.expect?-1:1)}var Pe={videoContentHeight:0,videoContentWidth:0},je=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return Pe;let{clientHeight:r,clientWidth:s}=t.experimental.element$.getValue()||{};if(!(r&&s))return Pe;let l=e/n,a=r/s,o,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 Ti=250;function Oe(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}=je(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()},Ti);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 Si=i=>Math.floor(Math.random()*i),Fe=i=>{let t=i.length,e=1/0,n=null;for(;t--;)i[t].weight<e&&(e=i[t].weight,n=i[t]);return n},$e=i=>{let t=i.length,e=-1/0,n=null;for(;t--;)i[t].weight>e&&(e=i[t].weight,n=i[t]);return n};var Be=i=>{let t=i.length,e=Si(t);return i[e]};var He=i=>{let t=0;for(let n=0;n<i.length;++n)t+=i[n].weight??1;let e=Math.random()*t;t=0;for(let n=0;n<i.length-1;++n)if(t+=i[n].weight??1,t>=e)return i[n];return i[i.length-1]};var De=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var ne=(i,t=!1)=>({...i,args:t?{...i.args,...De}:{...De,...i.args}}),Ue=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:p,controlType:c,controlId:u,containerId:f,branches:m=[],onEvent:M,isEOV:w=()=>!1,isDisabled:V=()=>!1})=>{let v=ne(p,w()),L={timestamp:1/0,priority:"control",initiator:u,actionType:v.type},U=V(),$=i.emit.bind(i,d.interactives,{subjectId:u,subjectType:c,subjectName:"control",type:U?C.actionChoiceCanceled:C.actionChoice,actionType:p.type,payload:{containerId:f,...v.args}});if(U){$();return}switch(v.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let P=m.find(lt=>lt.id===v.args.branchId);if(!P)return;M(v.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),$(),v.args.shouldOpenNow?k({subjectId:u,subjectName:"control",subjectType:c,action:v,payload:{chapterId:P.chapterId,autoSelect:!1}}):(e.add({...L,action:k.bind(null,{subjectId:u,subjectName:"control",subjectType:c,action:v,payload:{chapterId:P.chapterId,autoSelect:!1}})}),n?.());return}case I.continuePlayback.trim().toLowerCase():{M(v.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),$(),v.args.shouldOpenNow?b({subjectId:u,subjectName:"control",subjectType:c,action:p}):e.add({...L,action:b.bind(null,{subjectId:u,subjectName:"control",subjectType:c,action:p})});return}case I.openURI.trim().toLowerCase():{M(v.args.isDetachContainer,E.bind(null,{subjectId:u,subjectName:"control"})),$(),v.args.shouldOpenNow?S({subjectId:u,subjectName:"control",subjectType:c,action:v,payload:{URI:p.args.uri}}):(e.add({...L,action:S.bind(null,{subjectId:u,subjectName:"control",subjectType:c,action:v,payload:{URI:p.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(d.errors,new _(1,1,{message:"Unexpected control event"}));return}},a=({action:p,container:{id:c,endTime:u},branches:f=[],isEOV:m=!1,autoSelected:M=!1})=>{let w=ne(p,m),V={timestamp:!w.args.shouldOpenNow||m?1/0:u,priority:"container",initiator:c,actionType:w.type},v=i.emit.bind(i,d.interactives,{subjectId:c,subjectName:"container",type:C.actionChoice,actionType:w.type,payload:w.args});switch(w.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let L=f.find(U=>U.id===w.args.branchId);if(!L)return;v(),e.add({...V,action:k.bind(null,{subjectId:c,subjectName:"container",action:w,payload:{chapterId:L.chapterId,autoSelect:M}})}),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:b.bind(null,{subjectId:c,subjectName:"container",action:w})});return}case I.openURI.trim().toLowerCase():{v(),e.add({...V,action:S.bind(null,{subjectId:c,subjectName:"container",action:w,payload:{URI:p.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(d.errors,new _(1,1,{message:"Unexpected container event"}));return}};function o({container:p,branches:c,isEOV:u=!1}){let f=Jt(p.events);if(f){let m=ne(f.action,u);i.emit(d.interactives,{subjectId:p.id,subjectName:"container",type:C.actionChoice,actionType:m.type,payload:m.args}),e.add({timestamp:u?1/0:p.endTime,priority:"container",initiator:p.id,actionType:I.expect,action:g.bind(null,{subjectId:p.id,subjectName:"container"})}),r.isExpect=!0}else for(let m of p.events)a({action:m.action,container:p,branches:c,isEOV:u})}let h=({chapterId:p,action:c,branches:u=[]})=>{let f=i.emit.bind(i,d.interactives,{subjectId:p,subjectName:"chapter",type:C.actionChoice,actionType:c.type,payload:c.args});switch(c.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{let m=u.find(M=>M.id===c.args.branchId);return m?.chapterId?(f(),k.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{let m=Be(u);return m?.chapterId?(f(),k.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{let m=He(u);return m?.chapterId?(f(),k.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{let m=$e(u);return m?.chapterId?(f(),k.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{let m=Fe(u);return m?.chapterId?(f(),k.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return f(),b.bind(null,{subjectId:p,subjectName:"chapter",action:c});case I.openURI.trim().toLowerCase():return f(),S.bind(null,{subjectId:p,subjectName:"chapter",action:c,payload:{URI:c.args.uri}});default:console.error("Unexpected chapter event"),i.emit(d.errors,new _(1,1,{message:"Unexpected chapter event"}));return}};function y(p){let c=Jt(p.events);if(c){if(j(p))return;i.emit(d.interactives,{subjectId:p.id,subjectName:"chapter",type:C.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(u=>{let f=h({chapterId:p.id,action:u.action,branches:p.branches});f&&e.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:u.action.type,action:f})})}let g=({subjectId:p,subjectName:c,action:u})=>{t.pause(),i.emit(d.interactives,{subjectId:p,subjectName:c,type:C.actionExecution,actionType:u?.type??I.expect})},E=({subjectId:p,subjectName:c})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(d.interactives,{subjectId:p,subjectName:c,type:C.actionExecution,actionType:"after-expect"})},b=({subjectId:p,subjectName:c,subjectType:u,action:f})=>{i.emit(d.interactives,{subjectId:p,subjectName:c,subjectType:u,type:C.actionExecution,actionType:f.type})},k=({subjectId:p,subjectName:c,subjectType:u,action:f,payload:m})=>{m.behaviour="change-chapter",i.emit(d.interactives,{subjectId:p,subjectName:c,subjectType:u,type:C.actionExecution,actionType:f.type,payload:m})},T=({subjectId:p,subjectName:c,subjectType:u,action:f,payload:m})=>{m.behaviour="change-manifest",i.emit(d.interactives,{subjectId:p,subjectName:c,subjectType:u,type:C.actionExecution,actionType:f.type,payload:m})},S=({subjectId:p,subjectName:c,subjectType:u,action:f,payload:m})=>{if(!m.URI)return;let M=window.open(m.URI,"_blank","noopener,noreferrer");M&&(M.opener=null),i.emit(d.interactives,{subjectId:p,subjectName:c,subjectType:u,type:C.actionExecution,actionType:f.type})};return{onControlEvent:l,onContainerEvent:a,onChapterEvent:h,onExpectEvent:g,expectEventHandler:E,setManifestChapterEvents:y,setManifestContainerEvents:o,stopExpect:s,state:r}};import{Subscription as Li,ValueSubject as st}from"@vkontakte/videoplayer-shared";var re=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let r=t.chapters.find(l=>l.id===n);if(!r)return null;let s=t.media.videos.find(l=>r.videoId===l.id);if(!s)return null;e[n]=We(s)}return e[n]}).filter(Boolean)},Mi=i=>{for(let t of i.variants)if(Vi(t)&&"payload"in t)return t.payload.id},Vi=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",We=i=>{let t=Mi(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},_i=(i,t)=>{for(let e of i.media.videos)if(t===We(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},Qe=(i,t)=>i.reduce((e,n)=>{let r=_i(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.#t=null;this.#a=!1;this.#e=null;this.#h=null;this.#r=null;this.#s=null;this.#i=null;this.#o=new Li;this.#l=!1;this.#c=0;this.#r=e,this.#i=t,this.#s=n,this.#t=r,this.#n=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(l=>{this.state.prevChapter$.next(l.at(-2)||null),this.state.hasPrevChapter$.next(l.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#e?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#n.maxLength-1)}))}#t;#n;#a;#e;#h;#r;#s;#i;#o;#l;#c;async setManifest(t){!this.#s||!this.#i||(this.#e=t,await this.getProjectHistory(),await this.#s.setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),this.#a||(this.#a=!0,this.#i.emit(d.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return this.#a}async updateHistory(t,e=!0){if(!this.#e)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#e,r=t.length-this.#n.maxLength,s=r>0?t.slice(r):t,l=re(s,n);if(this.#h=l,this.state.history$.next(s),!(!e||!this.#t||!this.#r))try{await this.#t.save(this.#r,l)}catch{this.#i?.emit(d.errors,new _(1,5,"Unable to save interactive history"))}}async goBack(){if(!this.state||!this.#s)return this.#i?.emit(d.errors,new _(1,5,"Cannot go back because HistoryController has not been initialized"));this.#l=!0;let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await this.#s.setChapter({chapterId:e,playPrev:!0})}async getProjectHistory(){if(!this.#e||!this.#r)return;let t=this.#e,e=[this.getInitialVideoId()];if(this.#t)try{let r=await this.#t.get(this.#r);r.length&&(e=r)}catch{this.#i?.emit(d.errors,new _(1,5,"Error while trying to fetch data"))}let n=Qe(e,t);this.state.history$.next(n)}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||this.#n.initChapterId||this.#e?.metadata.initChapterId}getInitialVideoId(){if(this.#e){let t=this.getInitialChapterId();return re([t],this.#e).pop()}return null}destroy(){this.#r=null,this.#t=null,this.#s=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#i?.emit(d.historyDestroyed),this.#i=null}};var 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 jt=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 Ot=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let t=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;let e=t.data,n=e.length;for(let r=3;r<n;r+=40)if(e[r]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(t,0,0,this.rootElement.width,this.rootElement.height)}};var Ft=class{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=t=>{let e=t??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(e);if(this.isContainerTime(e))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
var ot="1.0.19-dev.d5db4341.0";function Be(i,e=1){let t="0",n="0",r="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+r},${e})`}var P="interactive",Kt="interactive-controls-container",oe=()=>document.querySelector(`.${Kt}`),lt=.4,V={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},ct=(n=>(n.top="flex-start",n.bottom="flex-end",n.center="center",n))(ct||{}),pt=(n=>(n.start="flex-start",n.end="flex-end",n.center="center",n))(pt||{}),ht=(n=>(n.start="left",n.end="right",n.center="center",n))(ht||{}),le=({target:i,props:e})=>{i.style.alignItems=(e.text?.gravityVertical&&ct[e.text.gravityVertical])??"center",i.style.justifyContent=(e.text?.gravityHorizontal&&pt[e.text.gravityHorizontal])??"center",i.style.textAlign=(e.text?.alignment&&ht[e.text.alignment])??"left"},ce=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.color=e?.text?.color??t.textColor,i.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,i.textContent=e?.text?.value??t.textContent},pe=({target:i,props:e,fallback:t})=>{i.style.backgroundColor=Be(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},he=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth}) solid ${Be(e?.shape?.border?.color??t.borderColor,e?.shape?.border?.alpha??t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`},z=({target:i,layoutParams:e,fallback:t})=>{let n=e.angle??t.angle;n=n&&n*-1,i.style.transform=`rotate(${n}rad)`};var j=class{constructor(e){this.control=e;this.container=null;this.controlElement=null;this.clickListener=null}createContainerElement(e){let t=document.createElement("div");t.classList.add(`${P}-control-container-${this.control.id}`),e(t,this.control.layoutParams);let n=(this.control.layoutParams.innerSizesDependOn??V.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};this.container={element:t,dimensions:n}}createClickListener(e){return t=>{t.stopPropagation(),e()}}setEvents(e){!this.container||!this.control.events||this.control.events.forEach(t=>{switch(t.type.trim().toLowerCase()){case"onclick":this.clickListener=this.createClickListener(()=>e({action:t.action,controlId:this.control.id,controlType:this.control.type})),this.container?.element.addEventListener("click",this.clickListener);break;default:break}})}removeListeners(){this.container?.element&&this.clickListener&&this.container?.element.removeEventListener("click",this.clickListener)}};var _e="int",$=(n=>(n.AREA=`${_e}_area`,n.TEXT=`${_e}_text`,n.BUTTON=`${_e}_bttn`,n))($||{});var ue=i=>{if(i.type.trim().toLowerCase()==="area")return new He(i)},He=class extends j{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",$.AREA),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",pe({target:n,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),he({target:n,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:this.container.dimensions}),z({target:n,layoutParams:this.control.layoutParams,fallback:V}),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var de=()=>{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 me=i=>{if(i.type.trim().toLowerCase()==="button")return new De(i)},De=class extends j{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("button");n.type="button",n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",$.BUTTON),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.cursor="pointer",n.style.fontFamily="inherit",z({target:n,layoutParams:this.control.layoutParams,fallback:V}),pe({target:n,props:this.control.props,fallback:V}),he({target:n,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),le({target:n,props:this.control.props});let r=de();ce({target:r,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){this.controlElement&&(this.controlElement.style.cursor="default")}enable(){this.controlElement&&(this.controlElement.style.cursor="pointer")}getElement(){return this.controlElement}};var ut=i=>{if(i.type.trim().toLowerCase()==="text")return new Ge(i)},Ge=class extends j{constructor(e){super(e)}createView({parentElement:e,layoutCallback:t}){if(super.createContainerElement(t),!this.container)return;let n=document.createElement("div");n.classList.add(`${P}-${this.control.id}`),n.setAttribute("data-testid",$.TEXT),n.style.display="flex",n.style.width="100%",n.style.height="100%",n.style.fontFamily="inherit",z({target:n,layoutParams:this.control.layoutParams,fallback:V}),le({target:n,props:this.control.props});let r=de();ce({target:r,props:this.control.props,fallback:V,dependsOn:this.container.dimensions}),n.append(r),this.container.element.append(n),e.append(this.container.element),this.controlElement=n}disable(){}enable(){}getElement(){return this.controlElement}};var ze=class{constructor(e){this.layout=e}},fe=class extends ze{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var U=class{constructor(e){this.container=e,this.factories=new Map,this.#e()}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.#e()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.#e()}#e(){this.controls=this.#n()}#n(){return this.container.controls?.reduce((e,t)=>{let n=t.type.trim().toLowerCase(),r=this.factories.get(n);return r?[...e,r(t)]:[...e]},[])}};var ye=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new Ue(i,e)},Ue=class extends U{constructor(e,t){super(e),this.rootElement=t??oe(),this.layout=new fe(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",me),this.addControlFactory("text",ut),this.addControlFactory("area",ue)}createView(e){let t=document.createElement("div");return t.classList.add(`${P}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{n.createView({parentElement:t,layoutCallback:this.layout.setControlLayout}),n.setEvents(e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){let e=this.getElement();e&&(e.style.visibility="hidden")}show(){let e=this.getElement();e&&(e.style.visibility="visible")}enable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.enable()),e.style.opacity=1,this.isDisabled=!1)}disable(){let e=this.getElement();e&&(this.controls.forEach(t=>t.disable()),e.style.opacity=lt,this.isDisabled=!0)}removeView(){this.isRemoved||(this.controls.forEach(e=>e.removeListeners()),this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${P}-${this.container.id}`)}};import{clientChecker as bi,combine as Ci,InterfaceLanguage as Ei,Observable as zt,once as Ii,Subject as rt,Subscription as Ut,ValueSubject as L}from"@vkontakte/videoplayer-shared";import{InteractiveInterfaceClick as re}from"@vkontakte/videoplayer-statistics";import{loadVKLangPack as Zt}from"@vkontakte/videoplayer-shared";function Q(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}var B=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,K=i=>B(i,"Object"),ge=i=>B(i,"String"),ve=i=>B(i,"Array"),be=i=>B(i,"Number"),dt=i=>B(i,"Function");var We=i=>be(i)&&!isNaN(i);var _=i=>K(i)&&Object.keys(i).length===0,Qe=i=>ve(i)&&!i.length;var Z=(i,e)=>ge(i)&&(e?i.trim():i).length;var mt="video_interactive",ft="videoint";var yt=250,q=class{constructor(e){this.handleZoomChange=Q(e=>{this.lastZoomInfo=e},yt);this.onResize=e=>{if(!this.isReady||this.isHidden||!e[0].contentRect.width||!e[0].contentRect.height)return;let t=this.getNextPoint();t&&this.ngEditor?.zoomTo(t),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}};this.handleChapterChange=e=>{if(this.manifest){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor?.selectChapter(e.id),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=null}};this.handleManifestChange=(e,t=[])=>{if(this.isReady=!1,!be(e.graph.edit.chapters[0].x)){this.onError?.("Can't show graph"),console.error("Can't show graph");return}this.lastZoomInfo=null,this.manifest=e,this.visitedChapterIds=new Set(t),this.ngEditor&&(this.manifest.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=this.manifest.metadata.id):this.ngEditor.setVisitedChapters(Array.from(t)),this.isReady=!0)};this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:s=[]}){this.isReady=!1,this.isHidden=!0,this.manifest=null,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??"ru",this.zoom=.7,this.lastZoomInfo=null,this.currentManifestId=null,this.currentChapterId=null,this.ngEditor=null,this.ngEditorSize=null,this.graphWrapperElement=qt(e),this.resizeObserver=new ResizeObserver(Q(this.onResize,yt)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(e=this.ngEditorSize){return!this.lastZoomInfo||!e?null:[(this.lastZoomInfo.x-e.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-e.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(e){this.visitedChapterIds=new Set([...this.visitedChapterIds,...e]),this.ngEditor?.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(e){this.ngEditor?.updateVideosInfo(e)}async show(){this.manifest&&(this.ngEditor||await this.initNgEditor(),this.graphWrapperElement.style.display="block",!this.lastZoomInfo&&this.currentChapterId&&this.ngEditor?.focusChapter(this.currentChapterId),this.isHidden=!1)}async initNgEditor(){if(!this.manifest)return;let e;try{e=await Zt(this.lang,mt,ft)}catch{console.log("Unable to load graph language pack")}let{GraphEditor:t}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new t(this.graphWrapperElement,{mode:"read",lang:this.lang==="ru"?"ru":"en",translation:e}),this.currentManifestId=this.manifest.metadata.id,this.ngEditor.update(this.manifest),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId&&this.ngEditor.selectChapter(this.currentChapterId),this.ngEditor.on("control",({name:n,...r})=>{n==="openPreview"&&"chapterId"in r&&this.onOpenPreviewClick?.(r.chapterId)}),this.ngEditor.on("zoom",this.handleZoomChange),this.isReady=!0}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){this.hide(),this.manifest=null,this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function qt(i){let e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.display="none",i.append(e),e}var X=class{constructor(){this._containers=[];this._player=null;this.setPlayer=e=>{this._player=e};this.setContainers=e=>{this._containers=e};this.deleteContainer=e=>{this._containers=this._containers.filter(t=>t.id!==e)};this.getNextInteractiveTime=(e=3e3)=>{if(!this._containers.length||this._player===null)return null;let t=-1,n=!1,r=Math.round(this._player.info.position$.getValue()*1e3);for(let s of this._containers){let c=s.startTime-e;if(c<=r&&(s.endTime&&r<=s.endTime||s.endTime===null)){n=!0;break}r<c&&(t=t===-1?c:Math.min(t,c))}return!n&&t!==-1?t:null}}};import{isSupportedManifest as Ee,ControlTypes as Ie,EventActionTypes as E,migrateManifestToLatestVersion as bt,compareVersions as Pn}from"@interactiveplatform/movika-graph-editor";var gt={metadata:"Object",chapters:"Array"},vt=i=>{if(!K(i))return!1;for(let e in gt)if(!i[e]||!B(i[e],gt[e]))return!1;return Ee(i.metadata.version)},Ce=i=>i.type===Ie.Text,An=i=>i.type===Ie.Button,Mn=i=>i.type===Ie.Area;var M=class{constructor(e,t,...n){this.severity=e;this.category=t;this.data=n}toString(){return`Interactive SDK error ${JSON.stringify(this,null," ")}`}};var xe=class{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];let n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){let n=this.listeners[e]||[];for(let r=n.length;r>0;r--)if(n[r]===t){n.splice(r,1);break}return this}emit(e,...t){let n=this.listeners[e];return n?(n.forEach(r=>{r(...t)}),!0):!1}listenerCount(e){return this.rawListeners(e).length}rawListeners(e){return this.listeners[e]||[]}};var Te=class{constructor(e){this.fns=[];this.addFn=(e,t=!1)=>{dt(e)&&(this.fns.push(e),t&&this.updateFn())};this.removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==e),t&&this.updateFn()};this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()};this.cancelAnimation=()=>{this.raf&&(cancelAnimationFrame(this.raf),this.raf=void 0)};e&&(this.fn=e,this.addFn(e))}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as ni}from"@vkontakte/videoplayer-shared";var Se=class{constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return Xt(...this.loaders[e])(t)}};function Xt(...i){return async function(t){let n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Y(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function we({actions:i,errors:e,chapterId:t,...n}){if(t){let r=i.getManifest(),s=i.getChapter(r.chapters,t);if(s){let c=i.getMedia(r.media,s.videoId),a=i.getGraph(r.graph,s.id);return c?{...n,actions:i,errors:e,result:{chapter:s,media:c,graph:a}}:{...n,errors:Y(e,we.name,"Could not find media"),actions:i}}}return{...n,errors:Y(e,we.name,"Could not find chapter"),actions:i}}var Ke=(i="",e="")=>{let t=i.split("."),n=e.split("."),r=0;for(let s=0;s<Math.max(t.length,n.length)&&!r;s++)t[s]>n[s]?r=1:t[s]<n[s]?r=-1:r=0;return r};var Yt=async i=>{try{let e={},t;if(ge(i)){t=new URL(i).href;let r=await fetch(t);if(!r.ok)return{};e=await r.json()}else if(K(i))e=i;else return{};if(!vt(e))return{};let n=e.metadata.media;if(ge(n)&&!("media"in e))try{let r;t?r=new URL(n,t).href:(r=new URL(n).href,t=r);let s=await fetch(r);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return ti(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function Ct(i){let{manifest:e,manifestURL:t}=await Yt(i);if(!e)throw new Error("Failed on fetch");let n=bt(e);return n.media=Jt(n.media,t),delete n.metadata.media,n}function Ae(i,e){if(e)return i.find(t=>t.id===e)}function Ze(i,e){return i.edit?.chapters?i.edit.chapters.find(t=>t.id===e):i.view?.chapters?i.view.chapters.find(t=>t.id===e):void 0}function qe(i,e){return i.videos.find(t=>t.id===e)}function Jt(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{let r="url"in n?n.url:"",s=ei(r,e);return{...n,url:s||r}})}))}}function ei(i="",e){try{return new URL(i,e).href}catch{return""}}function ti(i){return Ke(i,"3.2.0")>=0}var Me=i=>ve(i)&&!Qe(i),F=i=>i.order==="end",ke=i=>ve(i.containers)&&!Qe(i.containers)&&F(i),Et=(i,e)=>{let t=i*1e3;return Me(e.controls)&&t<(e.startTime??0)},Xe=(i,e)=>{let t=i*1e3;return Me(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)};var H=(i=[])=>i.some(e=>e.action.type==="expect"),Ye=(i=[])=>i.find(e=>e.action.type==="expect"),ii=i=>i?.length===1,Ve=i=>ii(i)&&Ce(i[0]);function It(i,...e){return t=>typeof e[0]=="object"&&typeof t=="object"?i({...e[0],...t}):i(...e,...t)}var xt=(i,e)=>H(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&H(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);var W=class extends Se{constructor(t,n){super(t);this.manifest=null;this.chapter=null;this.media=null;this.graph=null;this.prevChapter$=new ni(null);this.onError=n,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){this.release();let n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Y},result:null,errors:null,source:t});return n.errors&&this.errorHandler(n.errors),this.manifest=await Ct(n.result??t),this}async setInitial(){return this.setNext()}async setNext(t=this.manifest?.metadata.initChapterId){if(!t)return this;this.prevChapter$.next(this.chapter);let n=await this.exec("chapterLoaders",we({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Ze,getChapter:Ae,getMedia:qe,getByBranches:this.getByBranches.bind(this),addErrorMessage:Y},result:null,errors:null,chapterId:t}));return n.errors&&this.errorHandler(n.errors),this.chapter=n.result.chapter,this.media=n.result.media,this.graph=n.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest?.metadata.initChapterId)||null}getByChapterId(t=this.manifest?.metadata.initChapterId){if(!t||!this.manifest)return null;let n=Ae(this.manifest.chapters,t);if(n){let r=qe(this.manifest.media,n.videoId),s=Ze(this.manifest.graph,n.id);if(r)return{chapter:n,media:r,graph:s}}return null}getBranches(t=this.chapter?.id){if(t===this.chapter?.id)return this.getByBranches(this.chapter?.branches);{let n=Ae(this.manifest?.chapters||[],t);return this.getByBranches(n?.branches)}}getByBranches(t=[]){return t.reduce((n,r)=>{let s=this.getByChapterId(r.chapterId);return s&&n.push(s),n},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter?.id===this.manifest?.metadata.initChapterId}isEndChapter(){return this.chapter?F(this.chapter):!1}};import{Player as ri}from"@vkontakte/videoplayer-core";import{Subscription as St,Tracer as si,ValueSubject as ai}from"@vkontakte/videoplayer-shared";var Tt=i=>{let e=i.variants.find(t=>t.payload?.type==="vk");if(e&&"payload"in e){let[t,n]=e.payload.id.split("_");return[t,n]}return[]};function Je(){let i=new Map;function e({listId:s=Math.random().toString(),itemId:c=Math.random().toString(),...a}){let o=i.get(s),u={...a};return o?o[c]=u:i.set(s,{[c]:u}),{listId:s,itemId:c,...a}}function t(s){s.player.destroy(),s.container.remove(),s.subscription.unsubscribe(),s.statistics?.oneStat.destroy(),s.statistics?.statSubscription.unsubscribe()}function n(s,c){let a=i.get(s);if(!a)throw Error("Can't remove. Not find.");if(c){let o=a[c];o&&t(o),delete a[c],Object.keys(a).length||i.delete(s)}else{for(let o of Object.values(a))t(o);i.delete(s)}}function r(){for(let s of i)n(s[0])}return{createPlayer:e,removePlayer:n,map:i,removeAll:r}}function et(i,e=[]){let t={},n,r=!e.length;for(let s of i.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(r||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(r||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(r||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(r||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break;default:break}return{sources:t,thumbUrl:n,title:i.title??""}}var J=(i,e)=>{let t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))};var oi=2;function tt(i){let e=Je(),t={},n=null,r=!1,s,c=new ai(null);i&&a(i);function a(x){n=x}function o(x,T,p){if(!n)throw Error("need to set interactive controller");if(!n.options)return;let d=(e.map.get(x)??{})[T];if(d){t={chapterId:p,listId:x,itemId:T,...d};let f=t.player;t.subscription.add(f.info.currentQuality$.subscribe(m=>{let w=f.info.position$.getValue(),S=f.info.isAutoQualityEnabled$.getValue();if(!(!m||!w||S))for(let A of e.map)Object.values(A[1]).forEach(({player:g})=>{J(g,m)})})).add(f.events.started$.subscribe(()=>{u(T)})),d.container.remove(),n.setPlayer(d.player),r||(n.init(),r=!0),c.next({player:t.player,config:t.config,statistics:t.statistics});return}throw Error("Can't set. Not find.")}async function u(x){if(!n)throw Error("need to set interactive controller");if(_(t)||x!==t.itemId)return;let T=n.getChapterBranches(),p=new Set;for(let l of T)p.has(l.media.id)||(await C({media:l.media,chapterId:l.chapter.id,setAsActive:!1,title:l.chapter.label}),p.add(l.media.id))}async function y({chapter:{id:x},media:T}){if(_(t))return;let p=t.player.info.muted$.getValue(),l=t.player.info.currentQuality$.getValue(),d=t.player.info.isAutoQualityEnabled$.getValue(),f=t.player.info.volume$.getValue(),m=t.player.info.currentPlaybackRate$.getValue(),w=!d,S=!1;for(let A of e.map)if(A[0]===T.id){let g=Object.keys(A[1]);for(let k of g)k===t.itemId?(g.length<oi||(S=!0),e.removePlayer(A[0],k)):(S=!0,o(A[0],k,x),w?J(t.player,l):t.player.setAutoQuality(!0),t.player.setVolume(f),t.player.setMuted(p),t.player.setPlaybackRate(m))}else e.removePlayer(A[0]);S||(await C({media:T,chapterId:x,setAsActive:!0,playbackRate:m}),w?J(t.player,l):t.player.setAutoQuality(!0),t.player.setVolume(f),t.player.setMuted(p))}async function C({media:x,chapterId:T,prefetch:p=!0,setAsActive:l=!0,autoplay:d=!1,preferredExt:f,title:m,playbackRate:w}){let S=Math.random().toString(),A=document.createElement("div");s.append(A);let g;if(n?.options?.vkVideoLoader){let ae=Tt(x);ae.length&&(g=await n.options.vkVideoLoader(...ae))}let k=n?.options?.coreConfig||void 0,D={...k,configName:[...k?.configName??[],"interactive"]},O={container:A,...g?.videos?.[0]||{sources:et(x,f).sources},title:m,failoverHosts:g?.failoverHosts||[]},N=new ri(D,si.createRootTracer());N.initVideo(O);let se=null;if(g?.videos&&n?.options.createOneStat){let ae=g.videos[0],$e=n.options.createOneStat(ae),at=new St;$e&&(at.add($e.attachTo(N)),se={oneStat:$e,statSubscription:at})}let st=new St,Qt=t?.player?.info.isAutoQualityEnabled$.getValue();st.add(N.events.canplay$.subscribe(function(){Qt||J(N,t.player.info.currentQuality$.getValue()),w&&N.setPlaybackRate(w)}));let G=e.createPlayer({listId:x.id,itemId:S,player:N,container:A,sources:et(x,f).sources,config:O,subscription:st,statistics:se});return l&&o(x.id,G.itemId,T),d&&G.player.play(),p&&!d&&G.player.prepare(),{player:G.player,config:G.config,statistics:G.statistics}}function I(){v(),n=null,s.remove()}function v(){n?.off(h.chapterChanged,y),e.removeAll(),t={},r=!1}async function R(){if(!n)throw Error("need to set interactive controller");v(),s=document.createElement("div");let{media:x,chapter:T}=n.getCurrentChapter();x&&T?(n.on(h.chapterChanged,y),await C({media:x,chapterId:T.id,title:T.label})):console.error("not found")}return{...e,init:R,setInteractiveController:a,createPlayer:C,removeAll:I,getActivePlayer:function(){return t},activePlayerChanged:c}}var h={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ee={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 li}from"@vkontakte/videoplayer-shared";var Re=class{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:c,ignoreContainerEvent:a,permanentTextControls:o,disabledControls$:u,onRemove:y}){this.hide=()=>{setTimeout(()=>{this.gameState!==4&&(H(this.container.container.events)&&this.gameState===3||this.selectBranches.state.isExpect||(this.gameState!==2&&this.container.hide?.(),this.globalEventEmitter.emit(h.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(h.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!0,isFirst:!1});else{let t=It(this.selectBranches.onControlEvent,{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(h.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(h.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(h.interactives,{subjectId:this.container.container.id,subjectName:"container",type:b.visibility,visibility:!1}))},isEOV:()=>this.gameState===4});this.container.createView(t),this.globalEventEmitter.emit(h.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 e=this.player.experimental.element$.getValue(),n=e instanceof HTMLVideoElement?e.readyState:void 0,r=[6,5];if(!n||r.includes(this.gameState)&&!this.isPermanentText)return;let s=this.player.getExactTime();if(Et(s,this.container.container))this.gameState!==1&&(this.gameState=1,this.onBeforeStartTime());else if(Xe(s,this.container.container))this.gameState!==2&&(this.gameState=2,this.onStartTime());else if(this.gameState!==3){let o=this.gameState;this.gameState=3,o===2&&this.onEndTime()}else this.isPermanentText||this.removeView();let c=Xe(s,this.container.container),a=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[];this.globalEventEmitter.emit(h.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:a,currentTime:s,isInteractiveTime:c})};this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new li,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=o&&Ve(t.container.controls),this.disabledControls$=u,this.onRemove=y,this.globalEventEmitter=c,this.gameState=0,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(e=>{e?this.container.disable?.():this.container.enable?.()}))}selectContainerEvent(e=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:e?1/0:this.container.container.endTime,id:this.container.container.id}),!(this.isSelectedControlEvent||this.isSelectedContainerEvent)&&(this.isSelectedContainerEvent=!0,this.ignoreContainerEvent()||this.selectBranches.setManifestContainerEvents({container:this.container.container,branches:this.branches,isEOV:e}),!e&&this.interactiveEvents.exec(this.container.container.endTime??1/0))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);let e=H(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(h.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(h.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 wt=(i=[])=>i.reduce((e,t,n)=>{let r=(t?.controls??[]).filter(s=>!Ce(s));if(Me(r)){let s=[t.startTime??0,t.endTime??1/0],c=t.id;if(!n)e.push({subjects:[c],range:s});else{let a=[],o=-1/0,u=1/0,y=[],C=[];for(let I=0;I<e.length;I++){let v=e[I];if(C.push(...v.subjects),v.range[0]<u&&(u=v.range[0]),v.range[1]>o&&(o=v.range[1]),s[0]>=v.range[0]&&s[1]<=v.range[1])return e[I].subjects.push(c),e;s[0]<v.range[0]&&s[1]>v.range[0]&&(a.push(I),y=y.concat(v.subjects)),s[0]>=v.range[0]&&s[0]<=v.range[1]&&(a.push(I),y=y.concat(v.subjects),s[0]=v.range[0]),s[1]>=v.range[0]&&s[1]<=v.range[1]&&(a.push(I),y=y.concat(v.subjects),s[1]=v.range[1])}if(C.push(c),s[0]<=u&&s[1]>=o)return[{subjects:C,range:s}];a.length&&a.reverse().forEach(I=>{e.splice(I,1)}),e.push({subjects:y.concat([c]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]);function At(){let i={};function e(){for(let a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a]}function t(a){let o={};for(let u in i)+u<=a&&(o[u]=i[u]);return o}function n(a){let o={};for(let u in i)+u>=a&&(o[u]=i[u]);return o}function r({timestamp:a,priority:o,initiator:u}){if(We(a)){let y=i[a]??null;if(y&&o&&Z(o,!0)){let C={},I=y[o];return I&&(C={...C,...I}),C=_(C)?null:C,C&&Z(u,!0)?C[u]??null:C}return y}return null}function s({timestamp:a,priority:o,initiator:u}){if(We(a))if(i[a]){if(o&&Z(o,!0))if(i[a][o]){if(u&&Z(u,!0))if(i[a][o][u]){if(delete i[a][o][u],!_(i[a][o]))return!0}else return!1;if(delete i[a][o],!_(i[a]))return!0}else return!1;return delete i[a]}else return!1;return!1}function c({timestamp:a,priority:o,initiator:u,...y}){i[a]?.[o]?.[u]?i[a][o][u].push({...y}):i[a]?.[o]?i[a][o]={...i[a][o],[u]:[{...y}]}:i[a]?i[a]={...i[a],[o]:{[u]:[{...y}]}}:i[a]={[o]:{[u]:[{...y}]}}}return{map:i,remove:s,add:c,removeAll:e,get:r,getLte:t,getGte:n}}var ci=[E.expect,E.setNextBranch],pi=1/0;function Mt(i){let e=i,t,n=hi(),r=At(),s,c=()=>{I(),p()},a=l=>{r.add.call(void 0,l),R()},o=(l=[])=>{for(let d of l)if(d.action(),ci.includes(d.actionType))break},u=(l=1/0)=>{let d=Pe(r.get({timestamp:l,priority:"control"})??{}),f=Pe(r.get({timestamp:l,priority:"container"})??{}),m=Pe(r.get({timestamp:l,priority:"chapter"})??{});return[...d,...f,...m]},y=l=>{n.isReady(l)&&o(u(l))},C=()=>{o([...Pe(r.get({timestamp:1/0,priority:"chapter"})??{})])},I=()=>{t&&(s?.unsubscribe(),t=void 0)},v=l=>{},R=()=>{t||(t=()=>setTimeout(()=>{y(1/0)}),s=e.events.ended$.subscribe(t))},x=l=>{I(),e=l},T=l=>{l.priority==="container"&&n.resetCalled(l.timestamp),r.remove(l)},p=()=>{n.release(),r.removeAll()};return{setPlayer:x,add:a,remove:T,exec:y,execEndOfVideo:C,listen:R,unlisten:I,release:c,containersEventsCallState:n,getPreparedToExecActions:u}}function hi(){let i=new Map;return{setCalled:({timestamp:c,id:a})=>{let o=i.get(c);o&&o[a]!==void 0&&(o[a]=!0)},setData:(c=[])=>{for(let a of c){let o=a.endTime??pi,u=i.get(o)??{};i.set(o,{...u,[a.id]:!1})}},resetCalled:c=>{let a=i.get(c);if(a)for(let o in a)a[o]=!1},isReady:c=>{let a=i.get(c);return a?!Object.values(a).some(o=>!o):!0},release:()=>i.clear()}}function Pe(i){return Object.values(i).flat().sort(e=>e.actionType===E.expect?-1:1)}var kt={videoContentHeight:0,videoContentWidth:0},Vt=(i,e)=>{let{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return kt;let{clientHeight:r,clientWidth:s}=e.experimental.element$.getValue()||{};if(!(r&&s))return kt;let c=t/n,a=r/s,o,u;return a>c?(u=s,o=s*c):a<c?(u=r/c,o=r):(u=s,o=r),{videoContentWidth:u,videoContentHeight:o}};var ui=250;function Rt(i){let e=()=>{},t=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){let{parentElement:o,player:u}=i();if(o&&u){let{videoContentWidth:y,videoContentHeight:C}=Vt(o,u);o.style.setProperty("--interactive-content-width",`${y}px`),o.style.setProperty("--interactive-content-height",`${C}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 u of o)u()},ui);function c(){e=void 0,t.disconnect(),r()}return{resizeObserver:t,calc:()=>{e?.()},release:c}}var te=class{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){let t=this.map[e];return t?t.slice():null}getAll(){let e=[];for(let t in this.map)e.concat(this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),this.map[e].length===0&&delete this.map[e])}clear(){this.map={}}keys(){return Object.keys(this.map)}size(){return this.keys().length}};var di=i=>Math.floor(Math.random()*i),Lt=i=>{let e=i.length,t=1/0,n=null;for(;e--;){let r=i[e],s=r.weight??1;s<t&&(t=s,n=r)}return n},Nt=i=>{let e=i.length,t=-1/0,n=null;for(;e--;){let r=i[e],s=r.weight??0;s>t&&(t=s,n=r)}return n};var Ft=i=>{let e=i.length,t=di(e);return i[t]},Pt=1,jt=i=>{let e=0;for(let n=0;n<i.length;++n)e+=i[n].weight??Pt;let t=Math.random()*e;e=0;for(let n=0;n<i.length-1;++n)if(e+=i[n].weight??Pt,e>=t)return i[n];return i[i.length-1]};var Ot={shouldOpenNow:!0,isDetachContainer:!0};var it=(i,e=!1)=>({...i,args:e?{...i.args,...Ot}:{...Ot,...i.args}}),_t=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},c=({action:p,controlType:l,controlId:d,containerId:f,branches:m=[],onEvent:w,isEOV:S=()=>!1,isDisabled:A=()=>!1})=>{let g=it(p,S()),k={timestamp:1/0,priority:"control",initiator:d,actionType:g.type},D=A(),O=i.emit.bind(i,h.interactives,{subjectId:d,subjectType:l,subjectName:"control",type:D?b.actionChoiceCanceled:b.actionChoice,actionType:p.type,payload:{containerId:f,...g.args}});if(D){O();return}switch(g.type.trim().toLowerCase()){case E.setNextBranch.trim().toLowerCase():{let N=m.find(se=>se.id===g.args.branchId);if(!N)return;w(g.args.isDetachContainer,I.bind(null,{subjectId:d,subjectName:"control"})),O(),g.args.shouldOpenNow?R({subjectId:d,subjectName:"control",subjectType:l,action:g,payload:{chapterId:N.chapterId,autoSelect:!1}}):(t.add({...k,action:R.bind(null,{subjectId:d,subjectName:"control",subjectType:l,action:g,payload:{chapterId:N.chapterId,autoSelect:!1}})}),n?.());return}case E.continuePlayback.trim().toLowerCase():{w(g.args.isDetachContainer,I.bind(null,{subjectId:d,subjectName:"control"})),O(),g.args.shouldOpenNow?v({subjectId:d,subjectName:"control",subjectType:l,action:p}):t.add({...k,action:v.bind(null,{subjectId:d,subjectName:"control",subjectType:l,action:p})});return}case E.openURI.trim().toLowerCase():{w(g.args.isDetachContainer,I.bind(null,{subjectId:d,subjectName:"control"})),O(),g.args.shouldOpenNow?T({subjectId:d,subjectName:"control",subjectType:l,action:g,payload:{URI:p.args.uri}}):(t.add({...k,action:T.bind(null,{subjectId:d,subjectName:"control",subjectType:l,action:g,payload:{URI:p.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(h.errors,new M(1,1,{message:"Unexpected control event"}));return}},a=({action:p,container:{id:l,endTime:d},branches:f=[],isEOV:m=!1,autoSelected:w=!1})=>{let S=it(p,m),A={timestamp:!S.args.shouldOpenNow||m?1/0:d??1/0,priority:"container",initiator:l,actionType:S.type},g=i.emit.bind(i,h.interactives,{subjectId:l,subjectName:"container",type:b.actionChoice,actionType:S.type,payload:S.args});switch(S.type.trim().toLowerCase()){case E.setNextBranch.trim().toLowerCase():{let k=f.find(D=>D.id===S.args.branchId);if(!k)return;g(),t.add({...A,action:R.bind(null,{subjectId:l,subjectName:"container",action:S,payload:{chapterId:k.chapterId,autoSelect:w}})}),n?.();return}case E.setMaxWeightBranch.trim().toLowerCase():return;case E.setMinWeightBranch.trim().toLowerCase():return;case E.setRandomBranch.trim().toLowerCase():return;case E.setWeightlessRandomBranch.trim().toLowerCase():return;case E.continuePlayback.trim().toLowerCase():{g(),t.add({...A,action:v.bind(null,{subjectId:l,subjectName:"container",action:S})});return}case E.openURI.trim().toLowerCase():{g(),t.add({...A,action:T.bind(null,{subjectId:l,subjectName:"container",action:S,payload:{URI:p.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(h.errors,new M(1,1,{message:"Unexpected container event"}));return}};function o({container:p,branches:l,isEOV:d=!1}){let f=Ye(p.events);if(f){let m=it(f.action,d);i.emit(h.interactives,{subjectId:p.id,subjectName:"container",type:b.actionChoice,actionType:m.type,payload:m.args}),t.add({timestamp:d?1/0:p.endTime??1/0,priority:"container",initiator:p.id,actionType:E.expect,action:C.bind(null,{subjectId:p.id,subjectName:"container"})}),r.isExpect=!0}else for(let m of p.events??[])a({action:m.action,container:p,branches:l,isEOV:d})}let u=({chapterId:p,action:l,branches:d=[]})=>{let f=i.emit.bind(i,h.interactives,{subjectId:p,subjectName:"chapter",type:b.actionChoice,actionType:l.type,payload:l.args});switch(l.type.trim().toLowerCase()){case E.setNextBranch.trim().toLowerCase():{let m=d.find(w=>w.id===l.args.branchId);return m?.chapterId?(f(),R.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case E.setWeightlessRandomBranch.trim().toLowerCase():{let m=Ft(d);return m?.chapterId?(f(),R.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case E.setRandomBranch.trim().toLowerCase():{let m=jt(d);return m?.chapterId?(f(),R.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case E.setMaxWeightBranch.trim().toLowerCase():{let m=Nt(d);return m?.chapterId?(f(),R.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case E.setMinWeightBranch.trim().toLowerCase():{let m=Lt(d);return m?.chapterId?(f(),R.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case E.continuePlayback.trim().toLowerCase():return f(),v.bind(null,{subjectId:p,subjectName:"chapter",action:l});case E.openURI.trim().toLowerCase():return f(),T.bind(null,{subjectId:p,subjectName:"chapter",action:l,payload:{URI:l.args.uri}});default:console.error("Unexpected chapter event"),i.emit(h.errors,new M(1,1,{message:"Unexpected chapter event"}));return}};function y(p){let l=Ye(p.events);if(l){if(F(p))return;i.emit(h.interactives,{subjectId:p.id,subjectName:"chapter",type:b.actionChoice,actionType:l.action.type,payload:l.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:E.expect,action:C.bind(null,{subjectId:p.id,subjectName:"chapter"})})}else p.events?.forEach(d=>{let f=u({chapterId:p.id,action:d.action,branches:p.branches});f&&t.add({timestamp:1/0,priority:"chapter",initiator:p.id,actionType:d.action.type,action:f})})}let C=({subjectId:p,subjectName:l})=>{e.pause(),i.emit(h.interactives,{subjectId:p,subjectName:l,type:b.actionExecution,actionType:E.expect})},I=({subjectId:p,subjectName:l})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(h.interactives,{subjectId:p,subjectName:l,type:b.actionExecution,actionType:"after-expect"})},v=({subjectId:p,subjectName:l,subjectType:d,action:f})=>{i.emit(h.interactives,{subjectId:p,subjectName:l,subjectType:d,type:b.actionExecution,actionType:f.type})},R=({subjectId:p,subjectName:l,subjectType:d,action:f,payload:m})=>{m.behaviour="change-chapter",i.emit(h.interactives,{subjectId:p,subjectName:l,subjectType:d,type:b.actionExecution,actionType:f.type,payload:m})},x=({subjectId:p,subjectName:l,subjectType:d,action:f,payload:m})=>{m.behaviour="change-manifest",i.emit(h.interactives,{subjectId:p,subjectName:l,subjectType:d,type:b.actionExecution,actionType:f.type,payload:m})},T=({subjectId:p,subjectName:l,subjectType:d,action:f,payload:m})=>{if(!m.URI)return;let w=window.open(m.URI,"_blank","noopener,noreferrer");w&&(w.opener=null),i.emit(h.interactives,{subjectId:p,subjectName:l,subjectType:d,type:b.actionExecution,actionType:f.type})};return{onControlEvent:c,onContainerEvent:a,onChapterEvent:u,onExpectEvent:C,expectEventHandler:I,setManifestChapterEvents:y,setManifestContainerEvents:o,stopExpect:s,state:r}};import{Subscription as vi,ValueSubject as ie}from"@vkontakte/videoplayer-shared";var nt=(i,e)=>{let t={};return i.map(n=>{if(!t[n]){let r=e.chapters.find(c=>c.id===n);if(!r)return null;let s=e.media.videos.find(c=>r.videoId===c.id);if(!s)return null;t[n]=Ht(s)}return t[n]}).filter(Boolean)},fi=i=>{for(let e of i.variants)if(yi(e)&&"payload"in e)return e.payload.id},yi=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Ht=i=>{let e=fi(i);if(!e)return null;let t=e.split("_").pop();return t?parseInt(t,10):null},gi=(i,e)=>{for(let t of i.media.videos)if(e===Ht(t)){for(let n of i.chapters)if(n.videoId===t.id)return n.id;return}},Dt=(i,e)=>i.reduce((t,n)=>{let r=gi(e,n);return r?[...t,r]:t},[]);var ne=class{constructor({globalEventEmitter:e,videoId:t,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new ie([]),hasPrevChapter$:new ie(!1),prevChapter$:new ie(null),isInitialChapter$:new ie(!1),isGoBackLimited$:new ie(!1)};this.#e=null;this.#a=!1;this.#t=null;this.#p=null;this.#r=null;this.#s=null;this.#i=null;this.#o=new vi;this.#l=!1;this.#c=0;this.#r=t,this.#i=e,this.#s=n,this.#e=r,this.#n=s,this.state.history$&&this.#o&&this.#o?.add(this.state.history$.subscribe(c=>{this.state.prevChapter$.next(c.at(-2)||null),this.state.hasPrevChapter$.next(c.length>1),this.state.isInitialChapter$.next(this.getInitialChapterId()===this.#t?.metadata?.initChapterId),this.state.isGoBackLimited$.next(this.#c===this.#n.maxLength-1)}))}#e;#n;#a;#t;#p;#r;#s;#i;#o;#l;#c;async setManifest(e){!this.#s||!this.#i||(this.#t=e,await this.getProjectHistory(),await this.#s.setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),this.#a||(this.#a=!0,this.#i.emit(h.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return this.#a}async updateHistory(e,t=!0){if(!this.#t)return;this.#l?(this.#l=!1,this.#c++):this.#c=0;let n=this.#t,r=e.length-this.#n.maxLength,s=r>0?e.slice(r):e,c=nt(s,n);if(this.#p=c,this.state.history$.next(s),!(!t||!this.#e||!this.#r))try{await this.#e.save(this.#r,c)}catch{this.#i?.emit(h.errors,new M(1,5,"Unable to save interactive history"))}}async goBack(){if(!this.state||!this.#s)return this.#i?.emit(h.errors,new M(1,5,"Cannot go back because HistoryController has not been initialized"));this.#l=!0;let e=this.state.history$.getValue().slice(0,-1),t=e.pop();this.state.history$.next(e),await this.#s.setChapter({chapterId:t,playPrev:!0})}async getProjectHistory(){if(!this.#t||!this.#r)return;let e=this.#t,t=[this.getInitialVideoId()];if(this.#e)try{let r=await this.#e.get(this.#r);r.length&&(t=r)}catch{this.#i?.emit(h.errors,new M(1,5,"Error while trying to fetch data"))}let n=Dt(t,e);this.state.history$.next(n)}getInitialChapterId(){return this.state.history$.getValue()?.at(-1)||this.#n.initChapterId||this.#t?.metadata.initChapterId}getInitialVideoId(){if(this.#t){let e=this.getInitialChapterId();return nt([e],this.#t).pop()}return null}destroy(){this.#r=null,this.#e=null,this.#s=null,this.#o?.unsubscribe(),this.#o=null,this.#a=!1,this.#i?.emit(h.historyDestroyed),this.#i=null}};var Le=class i{constructor(e,t,n,r){this.target=e,this.type=t,this.listener=n,this.options=i._convertOptions(e,r),this.target.addEventListener(t,n,this.options)}unlisten(){this.type&&this.listener&&this.options&&this.target?.removeEventListener(this.type,this.listener,this.options),this.target=null,this.type=null,this.listener=null,this.options=!1}static _convertOptions(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{let n=new Set(["passive","capture"]),r=Object.keys(t).filter(c=>!n.has(c));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),i._doesSupportObject(e)?t:t.capture||!1}}static{this._supportsObject=void 0}static _doesSupportObject(e){let t=i._supportsObject;if(t===void 0){t=!1;try{let n={},r={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);let s=()=>{};e.addEventListener("test",s,n),e.removeEventListener("test",s,n)}catch{t=!1}i._supportsObject=t}return t||!1}};var Ne=class{constructor(){this.bindingMap=new te}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,r){if(!this.bindingMap)return;let s=new Le(e,t,n,r);this.bindingMap.push(t,s)}listenOnce(e,t,n,r){let s=c=>{this.unlisten(e,t,s),n(c)};this.listen(e,t,s,r)}unlisten(e,t,n){if(!this.bindingMap)return;let r=this.bindingMap.get(t)||[];for(let s of r)s.target===e&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;let e=this.bindingMap.getAll();for(let t of e)t.unlisten();this.bindingMap.clear()}};var Fe=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){let e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;let t=e.data,n=t.length;for(let r=3;r<n;r+=40)if(t[r]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(e){this.canvasImgSrc=e}draw(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){let n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){let e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}};var je=class{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=e=>{let t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
7
7
|
position: absolute;
|
|
8
8
|
top: 0;
|
|
9
9
|
left: 0;
|
|
@@ -11,13 +11,13 @@ var le="1.0.19-dev.c9e593de.0";function Bt(i,t=1){let e="0",n="0",r="0";return i
|
|
|
11
11
|
height: var(--interactive-height);
|
|
12
12
|
background-color: var(--black);
|
|
13
13
|
visibility: hidden;
|
|
14
|
-
`,this.lastFrameCanvas=new
|
|
14
|
+
`,this.lastFrameCanvas=new Fe,this.endOffsetMs=t,this._callbacks={onError:n},this.lastFrameCanvas.rootElement.style.cssText=`
|
|
15
15
|
position: absolute;
|
|
16
16
|
top: 50%;
|
|
17
17
|
left: 50%;
|
|
18
18
|
transform: translate(-50%, -50%);
|
|
19
|
-
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),
|
|
19
|
+
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);let t=getComputedStyle(this.rootElement),n={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(r){this._onError(r)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>t.controls?.length&&e>=(t.startTime??0)&&e<=Math.min(t.endTime??1/0,this.currentVideoDurationMs-this.endOffsetMs))}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){this._callbacks?.onError?.(e)}};function Gt(i=0){return new Promise(e=>{setTimeout(()=>{e(0)},i)})}var Wt=Object.freeze({lang:Ei.RU,loaders:{},graph:!1,initSeamless:!1,lastFrame:!1,permanentTextControls:!0,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}});function xi(){let i=document.createElement("div");return i.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,i}var $t=class{constructor(t){this.subscription=new ji;this.globalEventEmitter=new K;this.animation=new St;this.eventManager=new jt;this.seekToInteractiveController=new tt;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=Oi();this.factories=new Map([["choice",bt]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.graph=null;this.lastFrame=null;this.appState=0;this.state={prevChapter$:new N(null),isInitialChapter$:new N(!1),isFirstChapter$:new N(!0),isEndChapter$:new N(!1),isInteractiveExpectation$:new N(!1),calledByInteractive$:new N(!1),lastChapterChangeWasInitiatedByInteractive$:new N(!1),disabledControls$:new N(!1),interactiveRanges$:new N([]),isInteractiveTime$:new N(!1),statistics$:new N(null),isSeekable$:new N(!1)};this.events={noInteraction$:new Pi};this.clearHistoryIfEnded=()=>{let t=this.player?.info.isEnded$.getValue(),e=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();t&&j(n)&&!e&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=({statistics:t,...e})=>{if(t){let{statSubscription:n,oneStat:r}=t;n.add(r.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.globalEventEmitter.emit(d.playerChanged,e)};this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()};this.removeControllers=(t=!0)=>{this.gameControllers.forEach(e=>{!t&&e.isPermanentText||(this.animation.removeFn(e.whilePlaying),e.destroy())})};this.completeInteractiveRange=t=>{let{interactiveRanges$:e}=this.state,r=e.getValue().map(s=>({...s,subjects:s.subjects.filter(l=>l!==t)}));e.next(r)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};this.options={...qe,...t,config:{...qe.config,...t.config}},this.options.parentElement.append(this.rootElement),this.historyController=new at({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this.options.projectInfo?.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}}),this.options.lastFrame&&(this.lastFrame=new Ft({parentElement:this.options.parentElement,onError:e=>this.globalEventEmitter.emit(d.errors,new _(1,6,e))})),this.eventManager.listen(this.rootElement,"mousedown",e=>e.stopPropagation()),this.eventManager.listen(this.rootElement,"mouseup",e=>e.stopPropagation()),this.manifestController=new Z(this.options.loaders,e=>this.globalEventEmitter.emit(d.errors,new _(1,3,e))),this.resizeManager=Oe(()=>({player:this.player,parentElement:this.options?.parentElement,fns:this.options?.lastFrame?[()=>{this.lastFrame?.updateCanvasDimensions(!0)}]:[]})),this.options.graph&&(this.graph=new J({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:e=>{this.setChapter({chapterId:e}),this.globalEventEmitter.emit(d.graph,{type:it.watchAgainClicked,chapterId:e})},onError:e=>this.globalEventEmitter.emit(d.errors,new _(1,4,{message:e}))})),this.initSubscriptions()}initSubscriptions(){this.globalEventEmitter.on(d.historyInited,async({videosInfo:t=[]})=>{this.options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(t))}),this.globalEventEmitter.on(d.interactives,async t=>{if(t.type===C.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),t.payload?.behaviour==="change-chapter"){let{chapterId:n}=t.payload;this.setChapter({chapterId:n}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}if(t.payload?.behaviour==="change-manifest"){let{manifestURL:n}=t.payload;this.setManifest(n)}let e=t.type==="action-execution";e&&t.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):e&&t.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}t.type===C.containerRemoved&&this.completeInteractiveRange(t.subjectId)}),this.globalEventEmitter.on(d.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})}async initSeamless(){this.seamlessController=ie(this),this.seamlessController.on(kt.activePlayerChanged,this.handleSeamlessPlayerChanged),await this.seamlessController.init()}handlePositionChange(t){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let e=t*1e3,r=this.getInteractiveRanges().reverse().find(({range:s})=>e>=s[1]);if(r){let s=r.range.join("-");this.endedRanges.has(s)||(this.endedRanges.add(s),this.globalEventEmitter.emit(d.interactives,{type:C.rangeEnded,payload:r,visibility:!0}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.subscription.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.subscription.add(this.player.events.started$.pipe(Ni()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add(ki({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let o=t*1e3;r=!!e.find(({range:[y,g],subjects:E})=>y<o&&o<g&&E.length)}r!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(r);let s=!!this.noInteractionTimeout,a=this.player?.info.playbackState$.getValue()==="playing"||n;r&&!s&&a?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout):s&&!a&&this.clearNoInteractionTimeout()})),this.options.lastFrame&&this.subscription.add(this.player.info.duration$.subscribe(t=>{this.lastFrame?.setVideoDuration(t*1e3)})).add(this.player.experimental.element$.subscribe(t=>{t&&this.lastFrame?.setVideoElement(t)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let t=this.manifestController.chapter;t&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(t),this.gameControllers=this.filterGameControllers(t),this.interactiveEvents?.containersEventsCallState.setData(t.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(e=>e.container.container).filter(e=>!Rt(e.controls))),this.options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}filterGameControllers(t){let e=[];return t.containers.forEach(n=>{let r=n.type.trim().toLowerCase(),s=this.factories.get(r);if(s){let l=new At({player:this.player,container:s(n,this.rootElement),branches:t.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEventEmitter:this.globalEventEmitter,ignoreContainerEvent:()=>_e(n,this.gameControllers),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)}});this.animation.addFn(l.whilePlaying,!0),e.push(l)}}),e}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let e=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!e||!n&&e)&&this.state.isSeekable$.next(!e)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(t){if(this.updateLastEventInfo(),!this.historyController.inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(n&&j(n)&&Lt(n))??!1,s=this.historyController.state.isInitialChapter$.getValue(),l=this.historyController.state.history$.getValue();if(s||r&&e){this.historyController.updateHistory([t]);return}l.at(-1)!==t&&this.historyController.updateHistory([...l,t])}reset(){this.appState===2&&(this.removeControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}init(){this.manifestController.chapter&&this.options.parentElement&&this.player&&this.options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this.options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(t){this.reset(),this.isFirstChapterFetched=!1;let e=await this.manifestController.setManifest(t);if(e.manifest)return this.graph&&await this.graph.handleManifestChange(e.manifest),await this.historyController.setManifest(e.manifest),this.globalEventEmitter.emit(d.manifestChanged,{manifest:e.manifest}),this.setGameControllers(),e.manifest}setPlayer(t){this.reset(),this.player=t,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Ne(this.player),this.selectBranches=Ue({player:this.player,interactiveEvents:this.interactiveEvents,globalEventEmitter:this.globalEventEmitter,removeControllers:()=>this.removeControllers(!1)}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:t,pushToHistory:e=!0,playPrev:n=!1}={}){this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),Ri.isSafari&&await Ke(35);let r=!n&&this.state.isEndChapter$.getValue()&&this.getCurrentManifest()?.metadata.initChapterId===t,{chapter:s,media:l,graph:a}=await(t?this.manifestController.setNext(t):this.manifestController.setInitial());(!t||r)&&this.state.isFirstChapter$.next(!0),s&&(e&&this.pushChapterToHistory(s.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(s),this.lastFrame?.setCurrentChapter(s),this.globalEventEmitter.emit(d.chapterChanged,{chapter:s,media:l,graph:a}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new Ze(t=>{this.globalEventEmitter.on(d.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?ot.GRAPH_SHOW:ot.GRAPH_HIDE),e==="watchAgainClicked"&&t.next(ot.WATCH_AGAIN)}),this.globalEventEmitter.on(d.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next(ot.NEXT_BUTTON),r==="Area"&&t.next(ot.NEXT_AREA))})}),nextMovie$:new Ze(t=>{this.globalEventEmitter.on(d.playerChanged,({config:e})=>{e?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&t.next(e.unitedVideoId)})})}}toggleGraphView(t=!0){this.graph&&(t?(this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(d.graph,{type:it.visibility,visibility:t}))}setVisitedChapters(t){Array.isArray(t)&&this.graph?.setVisitedChapters(t)}updateGraphVideosInfo(t){Array.isArray(t)&&this.graph?.updateVideosInfo(t)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(n=>n.actionType===I.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(e=>!e.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let t=this.player.info.position$.getValue(),e=this.player.info.duration$.getValue();return t===e&&this.gameControllers.some(n=>{let r=n.container.container;return!r.isRemoved&&r.endTime===null&&z(r.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=this.manifestController.manifest){return!!t&&xt(t.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return ke(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(t){return this.seekToInteractiveController.getNextInteractiveTime(t)}getChapterBranches(t){return this.manifestController.getBranches(t)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(t,e){return this.globalEventEmitter.on(t,e),this}off(t,e){return this.globalEventEmitter.off(t,e),this}once(t,e){return this.globalEventEmitter.once(t,e),this}destroy(){this.clearHistoryIfEnded(),this.removeControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.eventManager.release(),this.subscription.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Fi={Container:Q,createChoiceContainer:bt,createAreaControl:ft,createButtonControl:gt,getRootEl:ht,classnamesPrefix:A};var pa={version:le};export{_ as CustomError,d as EVENT_NAMES,$t as Interactives,Z as ManifestController,pa as SDKInfo,re as chapterIdsToVKVideoIds,F as compareVersions,_i as getChapterIdByVkVideoId,We as getVKVideoIdByMedia,Mi as getVideoRawIdByMedia,it as graphEventTypes,Lt as hasEndTemplate,C as interactivesEventTypes,j as isLastChapter,xt as isSupportedManifest,Vi as isVKVariantItem,Fi as utils,Qe as vkVideoIdsToChapterIds};
|
|
23
|
+
`,i}var Oe=class{constructor(e){this.subscription=new Ut;this.globalEventEmitter=new xe;this.animation=new Te;this.eventManager=new Ne;this.seekToInteractiveController=new X;this.endedRanges=new Set;this.gameControllers=[];this.rootElement=xi();this.factories=new Map([["choice",ye]]);this.isFirstChapterFetched=!1;this.player=null;this.interactiveEvents=null;this.selectBranches=null;this.seamlessController=null;this.seamlessControllerSubs=new Ut;this.graph=null;this.lastFrame=null;this.appState=0;this.state={prevChapter$:new L(null),isInitialChapter$:new L(!1),isFirstChapter$:new L(!0),isEndChapter$:new L(!1),isInteractiveExpectation$:new L(!1),calledByInteractive$:new L(!1),lastChapterChangeWasInitiatedByInteractive$:new L(!1),disabledControls$:new L(!1),interactiveRanges$:new L([]),isInteractiveTime$:new L(!1),statistics$:new L(null),isSeekable$:new L(!1)};this.events={noInteraction$:new rt,graphVisibilityChanged$:new rt,watchAgainIsClicked$:new rt};this.clearHistoryIfEnded=()=>{let e=this.player?.info.isEnded$.getValue(),t=this.state.isInteractiveExpectation$.getValue(),{chapter:n}=this.getCurrentChapter();e&&n&&F(n)&&!t&&this.historyController.updateHistory([]),window.removeEventListener("beforeunload",this.clearHistoryIfEnded)};this.handleSeamlessPlayerChanged=e=>{if(!e)return;let{statistics:t,...n}=e;if(t){let{statSubscription:r,oneStat:s}=t;r.add(s.attachToInteractive(this.getStatEvents())),this.state.statistics$.next(t)}this.globalEventEmitter.emit(h.playerChanged,n)};this.onPlaybackStarted=()=>{this.resizeManager?.calc(),this.animation.requestAnimation()};this.removeControllers=(e=!0)=>{this.gameControllers.forEach(t=>{!e&&t.isPermanentText||(this.animation.removeFn(t.whilePlaying),t.destroy())})};this.completeInteractiveRange=e=>{let{interactiveRanges$:t}=this.state,r=t.getValue().map(s=>({...s,subjects:s.subjects.filter(c=>c!==e)}));t.next(r)};this.clearNoInteractionTimeout=()=>{this.noInteractionTimeout&&(clearTimeout(this.noInteractionTimeout),this.noInteractionTimeout=void 0)};this._options={...Wt,...e,config:{...Wt.config,...e.config}},this._options.parentElement.append(this.rootElement),this.historyController=new ne({interactiveController:this,globalEventEmitter:this.globalEventEmitter,videoId:this._options.projectInfo?.videoId,historyApi:this._options.historyApi,settings:{maxLength:this._options.config.historyMaxLength,initChapterId:this._options.initChapterId}}),this._options.lastFrame&&(this.lastFrame=new je({parentElement:this._options.parentElement,onError:t=>this.globalEventEmitter.emit(h.errors,new M(1,6,t))})),this.eventManager.listen(this.rootElement,"mousedown",t=>t.stopPropagation()),this.eventManager.listen(this.rootElement,"mouseup",t=>t.stopPropagation()),this.manifestController=new W(this._options.loaders,t=>this.globalEventEmitter.emit(h.errors,new M(1,3,t))),this.resizeManager=Rt(()=>({player:this.player,parentElement:this._options?.parentElement,fns:this._options?.lastFrame?[()=>{this.lastFrame?.updateCanvasDimensions(!0)}]:[]})),this._options.graph&&(this.graph=new q({root:this._options.parentElement,lang:this._options.lang,onOpenPreviewClick:t=>{this.setChapter({chapterId:t}),this.globalEventEmitter.emit(h.graph,{type:ee.watchAgainClicked,chapterId:t}),this.events.watchAgainIsClicked$.next(t)},onError:t=>this.globalEventEmitter.emit(h.errors,new M(1,4,{message:t}))})),this.initSubscriptions()}initSubscriptions(){this.globalEventEmitter.on(h.historyInited,async({videosInfo:e=[]})=>{this._options.initSeamless&&(await this.initSeamless(),this.updateGraphVideosInfo(e))}),this.globalEventEmitter.on(h.interactives,async e=>{if(e.type===b.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),e.payload?.behaviour==="change-chapter"){let{chapterId:n}=e.payload;this.setChapter({chapterId:n}),this.state.isFirstChapter$.getValue()&&this.state.isFirstChapter$.next(!1)}if(e.payload?.behaviour==="change-manifest"){let{manifestURL:n}=e.payload;this.setManifest(n)}let t=e.type==="action-execution";t&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):t&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===b.containerRemoved&&this.completeInteractiveRange(e.subjectId)}),this.globalEventEmitter.on(h.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})}async initSeamless(){this.seamlessController=tt(this),this.seamlessControllerSubs.add(this.seamlessController.activePlayerChanged.subscribe(this.handleSeamlessPlayerChanged)),await this.seamlessController.init()}handlePositionChange(e){(!this.graph||this.graph.isHidden)&&this.checkIfSeekable();let t=e*1e3,r=this.getInteractiveRanges().reverse().find(({range:s})=>t>=s[1]);if(r){let s=r.range.join("-");this.endedRanges.has(s)||(this.endedRanges.add(s),this.globalEventEmitter.emit(h.interactives,{type:b.rangeEnded,payload:r,visibility:!0}))}}registerVideoEvents(){this.player&&(window.removeEventListener("beforeunload",this.clearHistoryIfEnded),this.subscription.unsubscribe(),window.addEventListener("beforeunload",this.clearHistoryIfEnded),this.subscription.add(this.player.events.started$.pipe(Ii()).subscribe(this.onPlaybackStarted)).add(this.player.events.playing$.subscribe(this.animation.requestAnimation)).add(this.player.events.willPause$.subscribe(this.animation.cancelAnimation)).add(this.player.info.position$.subscribe(this.handlePositionChange.bind(this))).add(this.manifestController.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))).add(Ci({position:this.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:e,interactiveRanges:t,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let o=e*1e3;r=!!t.find(({range:[y,C],subjects:I})=>y<o&&o<C&&I.length)}r!==this.state.isInteractiveTime$.getValue()&&this.state.isInteractiveTime$.next(r);let s=!!this.noInteractionTimeout,a=this.player?.info.playbackState$.getValue()==="playing"||n;r&&!s&&a?this.noInteractionTimeout=window.setTimeout(()=>{this.events.noInteraction$.next()},this._options.config.noInteractionEventTimeout):s&&!a&&this.clearNoInteractionTimeout()})),this._options.lastFrame&&this.subscription.add(this.player.info.duration$.subscribe(e=>{this.lastFrame?.setVideoDuration(e*1e3)})).add(this.player.experimental.element$.subscribe(e=>{e&&this.lastFrame?.setVideoElement(e)})).add(this.player.events.firstFrame$.subscribe(()=>{this.lastFrame?.reset(),setTimeout(()=>{this.lastFrame?.hide(),this.lastFrame?.lastFrameCanvas.clear()},50)})).add(this.player.events.seeked$.subscribe(this.lastFrame.onSeek)))}setGameControllers(){let e=this.manifestController.chapter;e&&this.appState===1&&(this.selectBranches?.setManifestChapterEvents(e),this.gameControllers=this.filterGameControllers(e),this.interactiveEvents?.containersEventsCallState.setData(e.containers),this.seekToInteractiveController.setContainers(this.gameControllers.map(t=>t.container.container).filter(t=>!Ve(t.controls))),this._options.lastFrame&&this.animation.addFn(()=>{this.player&&this.lastFrame?.onEachTick(this.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=2)}filterGameControllers(e){let t=[];return e.containers.forEach(n=>{let r=n.type.trim().toLowerCase(),s=this.factories.get(r);if(s){let c=new Re({player:this.player,container:s(n,this.rootElement),branches:e.branches,selectBranches:this.selectBranches,interactiveEvents:this.interactiveEvents,globalEventEmitter:this.globalEventEmitter,ignoreContainerEvent:()=>xt(n,this.gameControllers),permanentTextControls:this._options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{this.seekToInteractiveController.deleteContainer(n.id)}});this.animation.addFn(c.whilePlaying,!0),t.push(c)}}),t}checkIfSeekable(){if(this.state.isInteractiveExpectation$.getValue()){this.state.isSeekable$.next(!1);return}let t=this.state.isSeekable$.getValue(),n=!!this.seekToInteractiveController.getNextInteractiveTime();(n&&!t||!n&&t)&&this.state.isSeekable$.next(!t)}updateLastEventInfo(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}pushChapterToHistory(e){if(this.updateLastEventInfo(),!this.historyController.inited)return;let t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(n&&F(n)&&ke(n))??!1,s=this.manifestController.manifest?.metadata.initChapterId===e,c=this.historyController.state.history$.getValue();if(s||r&&t){this.historyController.updateHistory([e]);return}c.at(-1)!==e&&this.historyController.updateHistory([...c,e])}reset(){this.appState===2&&(this.removeControllers(),this.gameControllers=[],this.animation.release(),this.interactiveEvents?.release(),this.appState=1,this.state.isSeekable$.next(!1),this.clearNoInteractionTimeout())}get options(){return this._options}init(){this.manifestController.chapter&&this._options.parentElement&&this.player&&this._options.fullscreenTargetElement&&this.appState===0&&(this.resizeManager?.resizeObserver.observe(this._options.fullscreenTargetElement),this.registerVideoEvents(),this.appState=1,this.setGameControllers())}async setManifest(e){this.reset(),this.isFirstChapterFetched=!1;let t=await this.manifestController.setManifest(e);if(t.manifest)return this.graph&&this.graph.handleManifestChange(t.manifest),await this.historyController.setManifest(t.manifest),this.globalEventEmitter.emit(h.manifestChanged,{manifest:t.manifest}),this.setGameControllers(),t.manifest}setPlayer(e){this.reset(),this.player=e,this.seekToInteractiveController.setPlayer(this.player),this.interactiveEvents?this.interactiveEvents.setPlayer(this.player):this.interactiveEvents=Mt(this.player),this.selectBranches=_t({player:this.player,interactiveEvents:this.interactiveEvents,globalEventEmitter:this.globalEventEmitter,removeControllers:()=>this.removeControllers(!1)}),this.appState===1&&(this.registerVideoEvents(),this.setGameControllers())}async setChapter({chapterId:e,pushToHistory:t=!0,playPrev:n=!1}={}){this.reset(),this.lastFrame&&this.isFirstChapterFetched&&(this.lastFrame.draw(),this.lastFrame.show()),bi.isSafari&&await Gt(35);let r=!n&&this.state.isEndChapter$.getValue()&&this.getCurrentManifest()?.metadata.initChapterId===e,{chapter:s,media:c,graph:a}=await(e?this.manifestController.setNext(e):this.manifestController.setInitial());(!e||r)&&this.state.isFirstChapter$.next(!0),s&&(t&&this.pushChapterToHistory(s.id),this.state.isInitialChapter$.next(this.manifestController.isInitialChapter()),this.state.isEndChapter$.next(this.manifestController.isEndChapter()),this.graph&&this.graph.handleChapterChange(s),this.lastFrame?.setCurrentChapter(s),this.globalEventEmitter.emit(h.chapterChanged,{chapter:s,media:c,graph:a}),this.setGameControllers(),this.endedRanges=new Set,this.isFirstChapterFetched=!0)}getStatEvents(){return{click$:new zt(e=>{this.globalEventEmitter.on(h.graph,({type:t,visibility:n})=>{t==="visibility"&&e.next(n?re.GRAPH_SHOW:re.GRAPH_HIDE),t==="watchAgainClicked"&&e.next(re.WATCH_AGAIN)}),this.globalEventEmitter.on(h.interactives,({type:t,subjectName:n,subjectType:r})=>{t!=="action-choice"||n!=="control"||(r==="Button"&&e.next(re.NEXT_BUTTON),r==="Area"&&e.next(re.NEXT_AREA))})}),nextMovie$:new zt(e=>{this.globalEventEmitter.on(h.playerChanged,({config:t})=>{t?.unitedVideoId&&!this.state.isFirstChapter$.getValue()&&e.next(t.unitedVideoId)})})}}toggleGraphView(e=!0){this.graph&&(e?(this.graph.show(),this.state.isSeekable$.next(!1)):(this.graph.hide(),this.checkIfSeekable()),this.globalEventEmitter.emit(h.graph,{type:ee.visibility,visibility:e}),this.events.graphVisibilityChanged$.next(e))}setVisitedChapters(e){Array.isArray(e)&&this.graph?.setVisitedChapters(e)}updateGraphVideosInfo(e){Array.isArray(e)&&this.graph?.updateVideosInfo(e)}deadEndCheck(){return!(this.interactiveEvents?.getPreparedToExecActions()||[]).some(n=>n.actionType===E.setNextBranch)}allControlsAreRemoved(){return!this.gameControllers.some(t=>!t.container.isRemoved)}isEndedExpectation(){if(!this.player||!this.gameControllers)return!1;let e=this.player.info.position$.getValue(),t=this.player.info.duration$.getValue();return e===t&&this.gameControllers.some(n=>{let r=n.container.container;return!n.container.isRemoved&&r.endTime===null&&H(r.events)})}playPrevChapter(){this.historyController.goBack()}setDisabledControls(e){this.state.disabledControls$.next(e)}isSupport(e=this.manifestController.manifest){return!!e&&Ee(e.metadata.version)}getInitialVideoInfo(){return{videoId:this.historyController.getInitialVideoId(),chapterId:this.historyController.getInitialChapterId()}}getHistoryState(){return this.historyController.state}getIsSeekable(){return this.state.isSeekable$}getInteractiveRanges(){return wt(this.manifestController.chapter?.containers)}getNextInteractiveStartTime(e){return this.seekToInteractiveController.getNextInteractiveTime(e)}getChapterBranches(e){return this.manifestController.getBranches(e)}getCurrentChapter(){return this.manifestController.getCurrent()}getCurrentManifest(){return this.manifestController.manifest}on(e,t){return this.globalEventEmitter.on(e,t),this}off(e,t){return this.globalEventEmitter.off(e,t),this}once(e,t){return this.globalEventEmitter.once(e,t),this}destroy(){this.clearHistoryIfEnded(),this.removeControllers(),this.gameControllers=[],this.graph?.destroy(),this.seamlessControllerSubs.unsubscribe(),this.seamlessController?.removeAll(),this.resizeManager?.release(),this.animation.release(),this.interactiveEvents?.release(),this.manifestController.release(),this.eventManager.release(),this.subscription.unsubscribe(),this.globalEventEmitter.reset(),this.lastFrame?.destroy(),this.rootElement.remove(),this.historyController.destroy(),this.isFirstChapterFetched=!1,this.appState=3}};var Ti={Container:U,createChoiceContainer:ye,createAreaControl:ue,createButtonControl:me,getRootEl:oe,classnamesPrefix:P};var Fs={version:ot};export{Ie as ControlTypes,M as CustomError,h as EVENT_NAMES,E as EventActionTypes,Oe as Interactives,W as ManifestController,Fs as SDKInfo,nt as chapterIdsToVKVideoIds,Ke as compareVersions,gi as getChapterIdByVkVideoId,Ht as getVKVideoIdByMedia,fi as getVideoRawIdByMedia,ee as graphEventTypes,ke as hasEndTemplate,b as interactivesEventTypes,Mn as isAreaControl,An as isButtonControl,F as isLastChapter,Ee as isSupportedManifest,Ce as isTextControl,yi as isVKVariantItem,vt as isValidManifest,bt as migrateManifestToLatestVersion,Ti as utils,Dt as vkVideoIdsToChapterIds};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vkontakte/videoplayer-interactive",
|
|
3
|
-
"version": "1.0.19-dev.
|
|
3
|
+
"version": "1.0.19-dev.d5db4341.0",
|
|
4
4
|
"author": "vk.com",
|
|
5
5
|
"description": "Movika interactive SDK",
|
|
6
6
|
"homepage": "https://vk.com",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"**/*.d.ts"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@interactiveplatform/movika-graph-editor": "^1.
|
|
53
|
-
"@vkontakte/videoplayer-core": "2.0.
|
|
54
|
-
"@vkontakte/videoplayer-shared": "1.0.
|
|
55
|
-
"@vkontakte/videoplayer-statistics": "1.0.
|
|
52
|
+
"@interactiveplatform/movika-graph-editor": "^1.23.2-dev.0",
|
|
53
|
+
"@vkontakte/videoplayer-core": "^2.0.110",
|
|
54
|
+
"@vkontakte/videoplayer-shared": "^1.0.42",
|
|
55
|
+
"@vkontakte/videoplayer-statistics": "^1.0.57",
|
|
56
56
|
"uuid": "^9.0.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { EVENT_NAMES, Interactives, utils, graphEventTypes, interactivesEventTypes, isLastChapter, hasEndTemplate, InteractiveProjectInfo, } from './modules/Interactives';
|
|
2
|
-
export type { InteractiveRange
|
|
2
|
+
export type { InteractiveRange } from './modules/Interactives';
|
|
3
3
|
export { ManifestController } from './modules/ManifestController';
|
|
4
|
-
export
|
|
5
|
-
export { isSupportedManifest } from './movika.core/manifest';
|
|
4
|
+
export * from './manifest';
|
|
6
5
|
export { compareVersions } from './utils/compareVersions';
|
|
7
6
|
export { CustomError } from './utils/Error';
|
|
8
7
|
export * from './utils/chapterHelpers';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { ChapterContainer, ChapterContainer as Container, Chapter, Control, Manifest, ManifestVideo, ManifestVideoVariant, Media, Metadata, VideoInfo, VideoId, CustomManifestVideoVariant, Extension, AnyManifest, AnyControl, GraphEditChapter, GraphViewChapter, ChapterBranch, Standard, ControlLayoutParams, ControlEvent, ContainerEvent, ChapterEvent, } from '@interactiveplatform/movika-graph-editor';
|
|
2
|
+
export { isSupportedManifest, ControlTypes, EventActionTypes, migrateManifestToLatestVersion, compareVersions, } from '@interactiveplatform/movika-graph-editor';
|
|
3
|
+
export * from './utils';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventActionTypes, type AnyManifest, type AnyControl } from '../manifest';
|
|
2
|
+
/**
|
|
3
|
+
* checks manifest object validity
|
|
4
|
+
* @param manifest - manifest to check
|
|
5
|
+
* @returns true is valid, false is invalid
|
|
6
|
+
*/
|
|
7
|
+
export declare const isValidManifest: (manifest: AnyManifest) => boolean;
|
|
8
|
+
export declare const isTextControl: (controlItem: AnyControl) => boolean;
|
|
9
|
+
export declare const isButtonControl: (controlItem: AnyControl) => boolean;
|
|
10
|
+
export declare const isAreaControl: (controlItem: AnyControl) => boolean;
|
|
11
|
+
export type EventActionKeys = keyof typeof EventActionTypes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type InterfaceLanguage } from '@vkontakte/videoplayer-shared';
|
|
2
2
|
import type { GraphEditor } from '@interactiveplatform/movika-graph-editor';
|
|
3
|
-
import type { Chapter,
|
|
3
|
+
import type { Chapter, Manifest, VideoInfo } from '../../manifest';
|
|
4
4
|
interface GraphOptions {
|
|
5
5
|
lang: InterfaceLanguage | string;
|
|
6
6
|
root: HTMLElement;
|
|
@@ -43,7 +43,7 @@ export declare class Graph {
|
|
|
43
43
|
handleChapterChange: (chapter: Chapter) => void;
|
|
44
44
|
handleManifestChange: (manifest: Manifest, visitedChapters?: string[]) => void;
|
|
45
45
|
setVisitedChapters(chapterIds: string[]): void;
|
|
46
|
-
updateVideosInfo(videosInfo:
|
|
46
|
+
updateVideosInfo(videosInfo: VideoInfo[]): void;
|
|
47
47
|
show(): Promise<void>;
|
|
48
48
|
private initNgEditor;
|
|
49
49
|
hide(): void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Observable, Subject, ValueSubject } from '@vkontakte/videoplayer-shared';
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
2
|
+
import type { Chapter, Manifest, VideoInfo, AnyManifest } from '../../manifest';
|
|
3
|
+
import { type InteractiveRange } from './utils/getInteractiveRanges';
|
|
4
|
+
import type { IInteractiveOptions, IOptionalInteractiveOptions } from "./types";
|
|
5
|
+
import type { IPlayer } from "@vkontakte/videoplayer-core";
|
|
5
6
|
import { InstanceStatistics } from '../../modules/SeamlessController/InstanceManager';
|
|
6
7
|
declare enum INTERACTIVE_APP_STATES {
|
|
7
8
|
created = 0,
|
|
@@ -20,7 +21,7 @@ export declare class Interactives {
|
|
|
20
21
|
private rootElement;
|
|
21
22
|
private factories;
|
|
22
23
|
private isFirstChapterFetched;
|
|
23
|
-
private
|
|
24
|
+
private _options;
|
|
24
25
|
private manifestController;
|
|
25
26
|
private resizeManager;
|
|
26
27
|
private historyController;
|
|
@@ -28,12 +29,13 @@ export declare class Interactives {
|
|
|
28
29
|
private interactiveEvents;
|
|
29
30
|
private selectBranches;
|
|
30
31
|
private seamlessController;
|
|
32
|
+
private seamlessControllerSubs;
|
|
31
33
|
private graph;
|
|
32
34
|
private lastFrame;
|
|
33
35
|
private noInteractionTimeout;
|
|
34
36
|
appState: INTERACTIVE_APP_STATES;
|
|
35
37
|
state: {
|
|
36
|
-
prevChapter$: ValueSubject<Nullable<
|
|
38
|
+
prevChapter$: ValueSubject<Nullable<Chapter>>;
|
|
37
39
|
isInitialChapter$: ValueSubject<boolean>;
|
|
38
40
|
isFirstChapter$: ValueSubject<boolean>;
|
|
39
41
|
isEndChapter$: ValueSubject<boolean>;
|
|
@@ -48,6 +50,8 @@ export declare class Interactives {
|
|
|
48
50
|
};
|
|
49
51
|
events: {
|
|
50
52
|
noInteraction$: Subject<void>;
|
|
53
|
+
graphVisibilityChanged$: Subject<unknown>;
|
|
54
|
+
watchAgainIsClicked$: Subject<unknown>;
|
|
51
55
|
};
|
|
52
56
|
constructor(options: IOptionalInteractiveOptions);
|
|
53
57
|
private clearHistoryIfEnded;
|
|
@@ -66,8 +70,9 @@ export declare class Interactives {
|
|
|
66
70
|
private completeInteractiveRange;
|
|
67
71
|
private clearNoInteractionTimeout;
|
|
68
72
|
private reset;
|
|
73
|
+
get options(): IInteractiveOptions;
|
|
69
74
|
init(): void;
|
|
70
|
-
setManifest(manifest:
|
|
75
|
+
setManifest(manifest: AnyManifest | string): Promise<Manifest | undefined>;
|
|
71
76
|
setPlayer(player: IPlayer): void;
|
|
72
77
|
setChapter({ chapterId, pushToHistory, playPrev }?: {
|
|
73
78
|
chapterId?: string;
|
|
@@ -80,15 +85,15 @@ export declare class Interactives {
|
|
|
80
85
|
};
|
|
81
86
|
toggleGraphView(show?: boolean): void;
|
|
82
87
|
setVisitedChapters(chapterIds: string[]): void;
|
|
83
|
-
updateGraphVideosInfo(videosInfo:
|
|
88
|
+
updateGraphVideosInfo(videosInfo: VideoInfo[]): void;
|
|
84
89
|
deadEndCheck(): boolean;
|
|
85
90
|
allControlsAreRemoved(): boolean;
|
|
86
91
|
isEndedExpectation(): boolean;
|
|
87
92
|
playPrevChapter(): void;
|
|
88
93
|
setDisabledControls(value: boolean): void;
|
|
89
|
-
isSupport(manifest?: Nullable<
|
|
94
|
+
isSupport(manifest?: Nullable<Manifest>): boolean;
|
|
90
95
|
getInitialVideoInfo(): {
|
|
91
|
-
videoId:
|
|
96
|
+
videoId: string | null;
|
|
92
97
|
chapterId: string;
|
|
93
98
|
};
|
|
94
99
|
getHistoryState(): import("./utils/HistoryController").HistoryControllerState;
|
|
@@ -99,16 +104,16 @@ export declare class Interactives {
|
|
|
99
104
|
getInteractiveRanges(): import("./utils/getInteractiveRanges").InteractiveRanges;
|
|
100
105
|
getNextInteractiveStartTime(offsetMs?: number): number | null;
|
|
101
106
|
getChapterBranches(chapterId?: string): {
|
|
102
|
-
chapter:
|
|
103
|
-
graph: import("
|
|
104
|
-
media: import("
|
|
107
|
+
chapter: Chapter;
|
|
108
|
+
graph: import("@interactiveplatform/movika-graph-editor").GraphEditChapter | import("@interactiveplatform/movika-graph-editor").GraphViewChapter | undefined;
|
|
109
|
+
media: import("@interactiveplatform/movika-graph-editor").ManifestVideo;
|
|
105
110
|
}[];
|
|
106
111
|
getCurrentChapter(): {
|
|
107
|
-
chapter: Nullable<
|
|
108
|
-
media: Nullable<import("
|
|
109
|
-
graph: Nullable<import("
|
|
112
|
+
chapter: Nullable<Chapter>;
|
|
113
|
+
media: Nullable<import("@interactiveplatform/movika-graph-editor").ManifestVideo>;
|
|
114
|
+
graph: Nullable<import("@interactiveplatform/movika-graph-editor").GraphDesign>;
|
|
110
115
|
};
|
|
111
|
-
getCurrentManifest(): Nullable<
|
|
116
|
+
getCurrentManifest(): Nullable<Manifest>;
|
|
112
117
|
on(eventName: string, fn: Function): this;
|
|
113
118
|
off(eventName: string, fn: Function): this;
|
|
114
119
|
once(eventName: string, fn: Function): this;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChapterContainer, ControlLayoutParams } from '../../manifest';
|
|
2
2
|
declare abstract class Layout {
|
|
3
|
-
layout:
|
|
4
|
-
protected constructor(layout:
|
|
5
|
-
abstract setContainerLayout(target: HTMLElement):
|
|
6
|
-
abstract setControlLayout(target: HTMLElement, layoutParams:
|
|
3
|
+
layout: ChapterContainer['layout'];
|
|
4
|
+
protected constructor(layout: ChapterContainer['layout']);
|
|
5
|
+
abstract setContainerLayout(target: HTMLElement): void;
|
|
6
|
+
abstract setControlLayout(target: HTMLElement, layoutParams: ControlLayoutParams): void;
|
|
7
7
|
}
|
|
8
8
|
export declare class RelativeLayout extends Layout {
|
|
9
|
-
constructor(layout:
|
|
9
|
+
constructor(layout: ChapterContainer['layout']);
|
|
10
10
|
setContainerLayout(target: HTMLElement): void;
|
|
11
|
-
setControlLayout(target: HTMLElement, layoutParams:
|
|
11
|
+
setControlLayout(target: HTMLElement, layoutParams: ControlLayoutParams): void;
|
|
12
12
|
}
|
|
13
13
|
export {};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ControlEventCallback, CreateViewParams, Dimensions, LayoutCallback } from './types';
|
|
1
|
+
import type { ControlEventCallback, CreateViewParams, Dimensions, LayoutCallback, TControl } from './types';
|
|
3
2
|
type ControlContainer = {
|
|
4
3
|
element: HTMLElement;
|
|
5
4
|
dimensions: Dimensions;
|
|
6
5
|
};
|
|
7
6
|
export default abstract class Control {
|
|
8
|
-
control:
|
|
7
|
+
control: TControl;
|
|
9
8
|
protected container: Nullable<ControlContainer>;
|
|
10
9
|
protected controlElement: Nullable<HTMLElement>;
|
|
11
10
|
private clickListener;
|
|
12
|
-
protected constructor(control:
|
|
11
|
+
protected constructor(control: TControl);
|
|
13
12
|
abstract createView(params: CreateViewParams): void;
|
|
14
13
|
abstract getElement(): Nullable<HTMLElement>;
|
|
15
14
|
abstract disable(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ControlEvent, ControlLayoutParams } from '../../../
|
|
2
|
-
import { LatestControl } from '../../../movika.core/manifest';
|
|
1
|
+
import type { Control as TControl, ControlEvent, ControlLayoutParams } from '../../../manifest';
|
|
3
2
|
import Control from '../../../modules/Interactives/controls/Control';
|
|
3
|
+
export { TControl };
|
|
4
4
|
export declare enum CONTROLLER_IDS {
|
|
5
5
|
AREA = "int_area",
|
|
6
6
|
TEXT = "int_text",
|
|
@@ -18,8 +18,7 @@ export type CreateViewParams = {
|
|
|
18
18
|
type ControlEventCallbackParams = {
|
|
19
19
|
action: ControlEvent['action'];
|
|
20
20
|
controlId: string;
|
|
21
|
-
controlType:
|
|
21
|
+
controlType: TControl['type'];
|
|
22
22
|
};
|
|
23
23
|
export type ControlEventCallback = (params: ControlEventCallbackParams) => void;
|
|
24
|
-
export type ControlCreator = (control:
|
|
25
|
-
export {};
|
|
24
|
+
export type ControlCreator = (control: TControl) => Control | undefined;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Container } from './containers/index';
|
|
2
2
|
export { Interactives } from './Interactives';
|
|
3
3
|
export { EVENT_NAMES, graphEventTypes, interactivesEventTypes } from './utils/events';
|
|
4
|
-
export type {
|
|
4
|
+
export type { InteractiveProjectInfo } from './types';
|
|
5
5
|
export { isLastChapter, hasEndTemplate } from './utils/gameUtils';
|
|
6
|
+
export type { InteractiveRange } from './utils/getInteractiveRanges';
|
|
6
7
|
export declare const utils: {
|
|
7
8
|
Container: typeof Container;
|
|
8
9
|
createChoiceContainer: (container: any, rootElement: any) => import("./containers/ChoiceContainer").ChoiceContainer | undefined;
|