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