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