@vkontakte/videoplayer-interactive 1.0.13-dev.e654cf31.0 → 1.0.14-dev.25eb2840.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/es2018.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.13-dev.e654cf31.0
3
- * Wed, 24 Jul 2024 16:28:13 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-13/doc/
2
+ * @vkontakte/videoplayer-interactive v1.0.14-dev.25eb2840.0
3
+ * Tue, 06 Aug 2024 14:01:34 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-14/doc/
5
5
  */
6
- var Cn=Object.defineProperty;var En=(i,t,e)=>t in i?Cn(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var N=(i,t,e)=>(En(i,typeof t!="symbol"?t+"":t,e),e),De=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(De(i,t,"read from private field"),e?e.call(i):t.get(i)),y=(i,t,e)=>{if(t.has(i))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(i):t.set(i,e)},f=(i,t,e,n)=>(De(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Ti=(i,t,e,n)=>({set _(r){f(i,t,r,e)},get _(){return a(i,t,n)}}),A=(i,t,e)=>(De(i,t,"access private method"),e);var Si="1.0.13-dev.e654cf31.0";function He(i,t=1){let e="0",n="0",r="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+r},${t})`}var B="SDK_NAME",In="SDK_NAME-controls-container",te=()=>document.querySelector(`.${In}`),_i=.4,W={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},wi={top:"flex-start",bottom:"flex-end",center:"center"},Vi={start:"flex-start",end:"flex-end",center:"center"},Ri={start:"left",end:"right",center:"center"},ee=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=wi[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:wi.center,i.style.justifyContent=(s=Vi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Vi.center,i.style.textAlign=(o=Ri[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Ri.start},ie=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d;i.style.color=(s=(r=t==null?void 0:t.text)==null?void 0:r.color)!=null?s:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(l=t==null?void 0:t.text)==null?void 0:l.size)!=null?o:e.textSize})`,i.textContent=(d=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?d:e.textContent},ne=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=He((r=(n=t==null?void 0:t.background)==null?void 0:n.color)!=null?r:e.backgroundColor,(l=(s=t==null?void 0:t.background)==null?void 0:s.alpha)!=null?l:e.backgroundAlpha)},se=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d,v,b,E,T,x;i.style.border=`calc(${n.height} * ${(l=(s=(r=t==null?void 0:t.shape)==null?void 0:r.border)==null?void 0:s.width)!=null?l:e.borderWidth}) solid ${He((d=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?d:e.borderColor,(E=(b=(v=t==null?void 0:t.shape)==null?void 0:v.border)==null?void 0:b.alpha)!=null?E:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(T=t==null?void 0:t.shape)==null?void 0:T.roundCorners)!=null?x:e.roundCorners})`},Tt=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Ge="int",St={AREA:`${Ge}_area`,TEXT:`${Ge}_text`,BUTTON:`${Ge}_bttn`};var ct=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${B}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:W.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",s=>{s.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${B}-control-container-${this.control.id}`)}};var re=i=>{if(i.type.trim().toLowerCase()==="area")return new Ue(i)},Ue=class extends ct{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");return s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",St.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",ne({target:s,props:this.control.props,fallback:{...W,backgroundColor:"transparent"}}),se({target:s,props:this.control.props,fallback:{...W,borderAlpha:0},dependsOn:n}),Tt({target:s,layoutParams:this.control.layoutParams,fallback:W}),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${B}-${this.control.id}`)}};var ae=()=>{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 oe=i=>{if(i.type.trim().toLowerCase()==="button")return new ze(i)},ze=class extends ct{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");s.type="button",s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",St.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=ae();return Tt({target:s,layoutParams:this.control.layoutParams,fallback:W}),ne({target:s,props:this.control.props,fallback:W}),se({target:s,props:this.control.props,fallback:W,dependsOn:n}),ee({target:s,props:this.control.props}),ie({target:l,props:this.control.props,fallback:W,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${B}-${this.control.id}`)}};var Mi=i=>{if(i.type.trim().toLowerCase()==="text")return new We(i)},We=class extends ct{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${B}-${this.control.id}`),s.setAttribute("data-testid",St.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=ae();return Tt({target:s,layoutParams:this.control.layoutParams,fallback:W}),ee({target:s,props:this.control.props}),ie({target:l,props:this.control.props,fallback:W,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${B}-${this.control.id}`)}};var Qe=class{constructor(t){this.layout=t}},Ai=i=>{if(i.type.trim().toLowerCase()==="relative")return new jt(i)},jt=class extends Qe{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 wt,ce,le,Li,Vt=class{constructor(t){y(this,wt);y(this,le);this.container=t,this.factories=new Map,A(this,wt,ce).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),A(this,wt,ce).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),A(this,wt,ce).call(this)}};wt=new WeakSet,ce=function(){this.controls=A(this,le,Li).call(this)},le=new WeakSet,Li=function(){var t;return(t=this.container.controls)==null?void 0:t.reduce((e,n)=>{let r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};var he=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Ke(i,t)},Ke=class extends Vt{constructor(t,e){super(t),this.rootElement=e!=null?e:te(),this.layout=new jt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",oe),this.addControlFactory("text",Mi),this.addControlFactory("area",re)}createView(t){let e=document.createElement("div");return e.classList.add(`${B}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{let r=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(r,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=_i,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())==null||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${B}-${this.container.id}`)}};import{Subject as ns,ValueSubject as Z,Observable as dn,once as ss,Subscription as rs,getCurrentBrowser as as,CurrentClientBrowser as os,combine as cs}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as Tn}from"@vkontakte/videoplayer-shared";function de(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Pt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},ft=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Ot=i=>ft(i,Pt.Object),pe=i=>ft(i,Pt.String),ue=i=>ft(i,Pt.Array),fe=i=>ft(i,Pt.Number),Ni=i=>ft(i,Pt.Function);var Xe=i=>fe(i)&&!isNaN(i);var mt=i=>Ot(i)&&Object.keys(i).length===0,qe=i=>ue(i)&&!i.length;var $t=(i,t)=>pe(i)&&(t?i.trim():i).length;var Ze=window.navigator.userAgent.toLowerCase(),Ys=/ipad|iphone|ipod/.test(Ze),ki=/mobi/i.test(Ze),Js=Ze.indexOf("android")>-1&&ki,xn=!ki,tr=window.safari!==void 0&&xn;var ji="video_interactive",Pi="videoint";var Sn=250,Bt=class{constructor(t){N(this,"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}))});N(this,"handleChapterChange",t=>{var e;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.id)){(e=this.onError)==null||e.call(this,"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}});N(this,"handleManifestChange",async(t,e=[])=>{var n;if(!fe(t.graph.edit.chapters[0].x)){this.isReady=!1,(n=this.onError)==null||n.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await Tn(this.lang,ji,Pi)}catch(l){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:r}),this.ngEditor.on("control",({name:l,chapterId:o})=>{l==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",l=>{this.lastZoomInfo={...l}})}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});this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:r,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=e,this.onError=n,this.lang=r!=null?r:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=wn(t),this.resizeObserver=new ResizeObserver(de(this.onResize,Sn)),this.resizeObserver.observe(this.graphWrapperElement)}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]}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(){var t,e;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)==null||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)==null||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function wn(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 Ye=()=>{let i=[],t=null;return{setPlayer:l=>{t=l},setContainers:l=>{i=l},deleteContainer:l=>{i=i.filter(o=>o.id!==l)},getNextInteractiveTime:(l=3e3)=>{if(!i.length||t===null)return null;let o=-1,c=!1,d=Math.round(t.info.position$.getValue()*1e3);for(let v of i){let b=v.startTime-l;if(b<=d&&(d<=v.endTime||v.endTime===null)){c=!0;break}d<b&&(o=o===-1?b:Math.min(o,b))}return!c&&o!==-1?o:null}}};var lt=(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 Vn}from"uuid";var Rn="3.1",Oi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},_n={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},$i=i=>{let t=[];for(let e of i.chapters){let n,r=[];for(let{isDefault:o,...c}of e.branches)o&&(n=c.id),r.push(c);let s=[],l=[];for(let{fallbackStrategy:o,...c}of e.containers){let d=!!c.endTime,v=[_n];switch(o){case"await":d?v=[]:s=[];break;case"default":{let b={type:"onSuspense",action:{type:Oi.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?v=[b]:s=[b];break}case"random":case"weightlessRandom":case"max":case"min":{let b={type:"onSuspense",action:{type:Oi[o],args:{}}};d?v=[b]:s=[b];break}}for(let b of c.controls)l.push({...c,controls:[{...b}],id:Vn(),events:v})}t.push({...e,containers:l,events:s,branches:r})}return i.metadata.version=Rn,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var Mn="3.2",Bi=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:Mn},media:t}}return i};var An="3.3",Ln=(i=[])=>({edit:{chapters:i},view:{}}),Fi={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Di=i=>{var n;let t=[],e=[];for(let r of i.chapters){let{id:s,x:l,y:o,...c}=r,d=c.containers.map(v=>{var b;return{...v,controls:v.controls.map(({subtype:E,type:T,...x})=>({...x,type:E!=null?E:T})),events:(b=v.events)!=null&&b.length?v.events:[Fi]}});t.push({id:s,...c,containers:d,events:(n=c.events)!=null&&n.length?c.events:[Fi]}),e.push({id:s,x:l,y:o})}return{...i,chapters:t,graph:Ln(e),metadata:{...i.metadata,version:An}}};var Nn=[{version:"3.0",migrate:$i},{version:"3.1",migrate:Bi},{version:"3.2",migrate:Di}],Je=i=>Nn.reduce((t,e)=>lt(t.metadata.version,e.version)?t:e.migrate(t),i);var wr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Hi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Vr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),_=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),ti=(s=>(s.GO_NEXT_BUTTON="GO_NEXT_BUTTON",s.GO_NEXT_AREA="GO_NEXT_AREA",s.WATCH_AGAIN="WATCH_AGAIN",s.OPEN_GRAPH="OPEN_GRAPH",s.CLOSE_GRAPH="CLOSE_GRAPH",s))(ti||{});var Gi={metadata:"Object",chapters:"Array"},kn="3.0.0",jn="3.3.0",me=i=>{let t=lt(i,kn);return t===-1?!1:t===0?!0:lt(i,jn)!==1},Ui=i=>{if(!Ot(i))return!1;for(let t in Gi)if(!i[t]||!ft(i[t],Gi[t]))return!1;return me(i.metadata.version)},ei=i=>i.type===Hi.Text;var I=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};N(I,"Severity",{RECOVERABLE:1,CRITICAL:2}),N(I,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var Rt=class{constructor(){N(this,"listeners",{})}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t];if(!n)return this;for(let r=n.length;r>0;r--)if(n[r]===e){n.splice(r,1);break}return this}emit(t,...e){let n=this.listeners[t];return n?(n.forEach(r=>{r(...e)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}};var ye=class{constructor(t){N(this,"addFn",(t,e=!1)=>{Ni(t)&&(this.fns.push(t),e&&this.updateFn())});N(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});N(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});N(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});N(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});N(this,"cancelAnimation",()=>{cancelAnimationFrame(this.raf),this.raf=void 0});this.raf,this.fn,this.fns=[],this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as Hn}from"@vkontakte/videoplayer-shared";var ge=class{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!=null?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!=null?n:[]}}async exec(t,e){return Pn(...this.loaders[t])(e)}};function Pn(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function Ft(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function ve({actions:i,errors:t,chapterId:e,...n}){if(e){let r=i.getManifest(),s=i.getChapter(r.chapters,e);if(s){let l=i.getMedia(r.media,s.videoId),o=i.getGraph(r.graph,s.id);return l?{...n,actions:i,errors:t,result:{chapter:s,media:l,graph:o}}:{...n,errors:Ft(t,ve.name,"Could not find media"),actions:i}}}return{...n,errors:Ft(t,ve.name,"Could not find chapter"),actions:i}}var On=async i=>{try{let t,e;if(Ot(i))t=i;else if(pe(i)){e=new URL(i).href;let r=await fetch(e);if(!r.ok)return{};t=await r.json()}else return{};if(!Ui(t))return{};let n=t.metadata.media;if(pe(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=await fetch(r);if(!s.ok)throw new Error;t.metadata.media=await s.json()}catch(r){return Fn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}};async function zi(i){let{manifest:t,manifestURL:e}=await On(i),n=Je(t);return n.media=$n(n.media,e),delete n.metadata.media,n}function be(i,t){return i.find(e=>e.id===t)}function ii(i,t){var e,n;return(e=i.edit)!=null&&e.chapters?i.edit.chapters.find(r=>r.id===t):(n=i.view)!=null&&n.chapters?i.view.chapters.find(r=>r.id===t):void 0}function ni(i,t){return i.videos.find(e=>e.id===t)}function $n(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let r=Bn(n.url,t);return{...n,url:r||n.url}})}))}}function Bn(i,t){try{return new URL(i,t).href}catch(e){return""}}function Fn(i){return lt(i,"3.2.0")>=0}var P=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),si=i=>ue(i)&&!qe(i),J=i=>i.order==="end",Ce=i=>ue(i.containers)&&!qe(i.containers)&&J(i),Wi=(i,t)=>{var n;let e=i*1e3;return si(t.controls)&&e<((n=t.startTime)!=null?n:0)},ri=(i,t)=>{var n,r;let e=i*1e3;return si(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var yt=i=>i.some(t=>t.action.type==="expect"),ai=i=>i.find(t=>t.action.type==="expect"),Dn=i=>(i==null?void 0:i.length)===1,Ee=i=>Dn(i)&&ei(i[0]);var Qi=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),Ki=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!ei(c));if(si(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],d=e.id;if(!n)t.push({subjects:[d],range:c});else{let v=[],b=-1/0,E=1/0,T=[],x=[];for(let H=0;H<t.length;H++){let L=t[H];if(x.push(...L.subjects),L.range[0]<E&&(E=L.range[0]),L.range[1]>b&&(b=L.range[1]),L.range[0]<=c[0]&&L.range[1]>=c[1])return t[H].subjects.push(d),t;c[0]>=L.range[0]&&c[0]<=L.range[1]&&(v.push(H),T=T.concat(L.subjects),c[0]=L.range[0]),c[1]>=L.range[0]&&c[1]<=L.range[1]&&(v.push(H),T=T.concat(L.subjects),c[1]=L.range[1])}if(x.push(d),c[0]<=E&&c[1]>=b)return[{subjects:x,range:c}];v.length&&v.reverse().forEach(H=>{t.splice(H,1)}),t.push({subjects:T.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),Xi=(i,t)=>yt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&yt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var _t=class extends ge{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new Hn(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){var r;this.release();let e=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ft},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=await zi((r=e.result)!=null?r: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",ve({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ii,getChapter:be,getMedia:ni,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ft},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=be(this.manifest.chapters,t);if(e){let n=ni(this.manifest.media,e.videoId),r=ii(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:r}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{let e=be(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{let r=this.getByChapterId(n.chapterId);return r&&e.push(r),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return J(this.chapter)}};import{Player as Gn}from"@vkontakte/videoplayer-core";import{Subscription as Un}from"@vkontakte/videoplayer-shared";var qi=i=>{let t=i.variants.find(e=>{var n;return((n=e.payload)==null?void 0:n.type)==="vk"});if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var g={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Dt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},w={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function oi(){let i=new Map;function t({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...l}){let o=i.get(r),c={...l};return o?o[s]=c:i.set(r,{[s]:c}),{listId:r,itemId:s,...l}}function e(r,s){var o,c,d;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(d=l[s])==null||d.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let v of Object.values(l))v.player.destroy(),v.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(let r of i)e(r[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function ci(i,t=[]){var s,l,o;let e={},n,r=!t.length;for(let c of i.variants)if(!n&&"cover"in c&&(n=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(r||t.includes("mp4"))&&(e.MPEG={...e.MPEG,[(s=c.standard)!=null?s:"Invariant quality"]:c.url});break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG={...e.MPEG,[(l=c.standard)!=null?l:"Invariant quality"]:c.url});break;case"hls":(r||t.includes("hls"))&&(e={...e,HLS:{type:"url",url:c.url}});break;case"dash":(r||t.includes("dash"))&&(e={...e,DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}});break;default:break}return{sources:e,thumbUrl:n,title:(o=i.title)!=null?o:""}}var Ht=(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 Gt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},zn=2;function li(i){let t=oi(),e,n,r=new Rt,s={},l=!1,o=null,c=!1,d;i&&v(i);function v(h){o=h}function b(h,p,C){var M;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let R=((M=t.map.get(h))!=null?M:{})[p];if(R){s={chapterId:C,listId:h,itemId:p,...R};let j=s.player;n=j.info.currentQuality$.subscribe(S=>{if(!(!S||!j.info.position$.getValue())){e=S;for(let z of t.map)Object.values(z[1]).forEach(({player:$})=>{j.info.isAutoQualityEnabled$.getValue()||Ht($,S)})}}),R.container.remove(),l=!1,o.setPlayer(R.player),c||(o.init(),c=!0),r.emit(Gt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function E(h,p,C){if(!o)throw Error("need to set interactive controller");if(mt(s)||h!==s.itemId)return;if(C>=0&&!l){let R=o.getChapterBranches();l=!0;let M=new Set;for(let j of R)M.has(j.media.id)||(await x({media:j.media,chapterId:j.chapter.id,setAsActive:!1,title:j.chapter.label}),M.add(j.media.id))}}async function T({chapter:{id:h},media:p}){if(mt(s))return;n==null||n.unsubscribe();let C=s.player.info.muted$.getValue(),u=s.player.info.currentQuality$.getValue(),R=s.player.info.isAutoQualityEnabled$.getValue(),M=s.player.info.volume$.getValue(),j=s.player.info.currentPlaybackRate$.getValue(),S=!R,z=!1;for(let $ of t.map)if($[0]===p.id){let Y=Object.keys($[1]);for(let G of Y)G===s.itemId?(Y.length<zn||(z=!0),t.removePlayer($[0],G)):(z=!0,b($[0],G,h),S?Ht(s.player,u):s.player.setAutoQuality(!0),s.player.setVolume(M),s.player.setMuted(C),s.player.setPlaybackRate(j))}else t.removePlayer($[0]);z||(await x({media:p,chapterId:h,setAsActive:!0,playbackRate:j}),S?Ht(s.player,u):s.player.setAutoQuality(!0),s.player.setVolume(M),s.player.setMuted(C))}async function x({media:h,chapterId:p,prefetch:C=!0,setAsActive:u=!0,autoplay:R=!1,preferredExt:M,title:j,playbackRate:S}){var bi,Ci,Ei,Ii,xi;let z=Math.random().toString(),$=document.createElement("div");d.append($);let Y=(bi=s==null?void 0:s.player)==null?void 0:bi.info.isAutoQualityEnabled$.getValue(),G;if((Ci=o==null?void 0:o.options)!=null&&Ci.vkVideoLoader){let Jt=qi(h);Jt.length&&(G=await o.options.vkVideoLoader(...Jt))}let Yt=((Ei=o==null?void 0:o.options)==null?void 0:Ei.coreConfig)||{},bn={...Yt,configName:[...(Ii=Yt.configName)!=null?Ii:[],"interactive"]},gi={container:$,...((xi=G==null?void 0:G.videos)==null?void 0:xi[0])||{sources:ci(h,M).sources},title:j,failoverHosts:(G==null?void 0:G.failoverHosts)||[]},ut=new Gn(bn);ut.initVideo(gi);let vi=new Un;vi.add(ut.info.position$.subscribe(function(Jt){E(z,ut.info.duration$.getValue(),Jt)})).add(ut.events.canplay$.subscribe(function(){Y||Ht(ut,e),S&&ut.setPlaybackRate(S)}));let xt=t.createPlayer({listId:h.id,itemId:z,player:ut,container:$,sources:ci(h,M).sources,config:gi,subscription:vi});return u&&b(h.id,xt.itemId,p),R&&xt.player.play(),C&&!R&&xt.player.prepare(),r.emit(Gt.playerCreated,xt.player),{player:xt.player,config:xt.config}}function H(){L(),o=null}function L(){o==null||o.off(g.chapterChanged,T),t.removeAll(),s={},c=!1,l=!1}async function m({container:h}){if(!o)throw Error("need to set interactive controller");L(),d=h;let{media:p,chapter:C}=o.getCurrentChapter();if(p){o.on(g.chapterChanged,T);let{player:u,config:R}=await x({media:p,chapterId:C.id,title:C.label});return r.emit(Gt.initiated,{container:h,media:p,chapterId:C.id}),{player:u,config:R}}else console.error("not found")}return{...t,on:r.on.bind(r),off:r.off.bind(r),init:m,setInteractiveController:v,createPlayer:x,removeAll:H,getActivePlayer:function(){return s}}}import{Subscription as Wn}from"@vkontakte/videoplayer-shared";var Ie=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d,onRemove:v}){N(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==P.end&&(yt(this.container.container.events)&&this.gameState===P.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==P.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1})))})});N(this,"show",()=>{var t,e,n,r;if(this.gameState===P.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!0,isFirst:!1});else{let l=Qi({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1})),(this.gameState===P.end||this.gameState===P.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1}))},isEOV:()=>this.gameState===P.end});this.container.createView(l),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});N(this,"onEndOfVideo",()=>{this.gameState=P.end,this.selectContainerEvent(!0)});N(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[P.destroyed,P.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Wi(e,this.container.container))this.gameState!==P.beforeInteractive&&(this.gameState=P.beforeInteractive,this.onBeforeStartTime());else if(ri(e,this.container.container))this.gameState!==P.interactive&&(this.gameState=P.interactive,this.onStartTime());else if(this.gameState!==P.afterInteractive){let o=this.gameState;this.gameState=P.afterInteractive,o===P.interactive&&this.onEndTime()}else this.gameState!==P.destroyed&&!this.isPermanentText&&this.removeView();let n=ri(e,this.container.container),r=this.container.container.startTime?[this.container.container.startTime,(l=this.container.container.endTime)!=null?l:1/0]:[];this.globalEventEmitter.emit(g.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:r,currentTime:e,isInteractiveTime:n})});this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Wn,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&Ee(e.container.controls),this.disabledControls$=d,this.onRemove=v,this.globalEventEmitter=l,this.gameState=P.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=>{var e,n,r,s;t?(n=(e=this.container).disable)==null||n.call(e):(s=(r=this.container).enable)==null||s.call(r)}))}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=yt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)==null||e.call(t),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=P.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:w.containerRemoved,visibility:!1}),this.gameState=P.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=P.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!=null?t:1/0,id:this.container.container.id})}};function Zi(){let i={};function t(){for(let o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){let c={};for(let d in i)+d<=o&&(c[d]=i[d]);return c}function n(o){let c={};for(let d in i)+d>=o&&(c[d]=i[d]);return c}function r({timestamp:o,priority:c,initiator:d}){var v;if(Xe(o)){let b=(v=i[o])!=null?v:null;if(b&&$t(c,!0)){let E={},T=b[c];if(T&&(E={...E,...T}),E=mt(E)?null:E,E&&$t(d,!0)){let x=E[d];return x!=null?x:null}return E}return b}return null}function s({timestamp:o,priority:c,initiator:d}){if(Xe(o))if(i[o]){if($t(c,!0))if(i[o][c]){if($t(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!mt(i[o][c]))return!0}else return!1;if(delete i[o][c],!mt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l({timestamp:o,priority:c,initiator:d,...v}){var b,E,T;(E=(b=i[o])==null?void 0:b[c])!=null&&E[d]?i[o][c][d].push({...v}):(T=i[o])!=null&&T[c]?i[o][c]={...i[o][c],[d]:[{...v}]}:i[o]?i[o]={...i[o],[c]:{[d]:[{...v}]}}:i[o]={[c]:{[d]:[{...v}]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var Qn=[_.expect,_.setNextBranch],Kn=1/0;function hi(i){let t=i,e,n=Xn(),r=new Zi,s,l=()=>{E(),m()},o=h=>{r.add.call(void 0,h),x()},c=(h=[])=>{for(let p of h)if(p.action(),Qn.includes(p.actionType))break},d=(h=1/0)=>{var R,M,j;let p=xe((R=r.get({timestamp:h,priority:"control"}))!=null?R:{}),C=xe((M=r.get({timestamp:h,priority:"container"}))!=null?M:{}),u=xe((j=r.get({timestamp:h,priority:"chapter"}))!=null?j:{});return[...p,...C,...u]},v=h=>{n.isReady(h)&&c(d(h))},b=()=>{var h;c([...xe((h=r.get({timestamp:1/0,priority:"chapter"}))!=null?h:{})])},E=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},T=h=>{},x=()=>{e||(e=()=>setTimeout(()=>{v(1/0)}),s=t.events.ended$.subscribe(e))},H=h=>{E(),t=h},L=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),r.remove(h)},m=()=>{n.release(),r.removeAll()};return{setPlayer:H,add:o,remove:L,exec:v,execEndOfVideo:b,listen:x,unlisten:E,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function Xn(){let i=new Map;return{setCalled:({timestamp:l,id:o})=>{let c=i.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(let d of l){let v=(o=d.endTime)!=null?o:Kn,b=(c=i.get(v))!=null?c:{};i.set(v,{...b,[d.id]:!1})}},resetCalled:l=>{let o=i.get(l);if(o)for(let c in o)o[c]=!1},isReady:l=>{let o=i.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>i.clear()}}function xe(i){return Object.values(i).flat().sort(t=>t.actionType===_.expect?-1:1)}var Yi=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};let{clientHeight:r,clientWidth:s}=t.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};let l=e/n,o=r/s,c,d;return o>l?(d=s,c=s*l):o<l?(d=r/l,c=r):(d=s,c=r),{videoContentWidth:d,videoContentHeight:c}};var qn=250;function Ji(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:d}=i();if(c&&d){let{videoContentWidth:v,videoContentHeight:b}=Yi(c,d);c.style.setProperty("--interactive-content-width",`${v}px`),c.style.setProperty("--interactive-content-height",`${b}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function r(){let{parentElement:o}=i();o.removeAttribute("style")}let s=de(o=>{let{fns:c=[]}=i();n(o);for(let d of c)d()},qn);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Ut=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 Zn=i=>Math.floor(Math.random()*i),tn=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},en=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 nn=i=>{let t=i.length,e=Zn(t);return i[e]};var sn=i=>{var n,r;let t=0;for(let s=0;s<i.length;++s)t+=(n=i[s].weight)!=null?n:1;let e=Math.random()*t;t=0;for(let s=0;s<i.length-1;++s)if(t+=(r=i[s].weight)!=null?r:1,t>=e)return i[s];return i[i.length-1]};var rn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var di=(i,t=!1)=>({...i,args:t?{...i.args,...rn}:{...rn,...i.args}}),pi=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:m,controlType:h,controlId:p,containerId:C,branches:u=[],onEvent:R,isEOV:M=()=>!1,isDisabled:j=()=>!1})=>{let S=di(m,M()),z={timestamp:1/0,priority:"control",initiator:p,actionType:S.type},$=j(),Y=i.emit.bind(i,g.interactives,{subjectId:p,subjectType:h,subjectName:"control",type:$?w.actionChoiceCanceled:w.actionChoice,actionType:m.type,payload:{containerId:C,...S.args}});if($){Y();return}switch(S.type.trim().toLowerCase()){case _.setNextBranch.trim().toLowerCase():{let G=u.find(Yt=>Yt.id===S.args.branchId);if(!G)return;R(S.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),Y(),S.args.shouldOpenNow?x({subjectId:p,subjectName:"control",subjectType:h,action:S,payload:{chapterId:G.chapterId,autoSelect:!1}}):(e.add({...z,action:x.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:S,payload:{chapterId:G.chapterId,autoSelect:!1}})}),n==null||n());return}case _.continuePlayback.trim().toLowerCase():{R(S.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),Y(),S.args.shouldOpenNow?T({subjectId:p,subjectName:"control",subjectType:h,action:m}):e.add({...z,action:T.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:m})});return}case _.openURI.trim().toLowerCase():{R(S.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),Y(),S.args.shouldOpenNow?L({subjectId:p,subjectName:"control",subjectType:h,action:S,payload:{URI:m.args.uri}}):(e.add({...z,action:L.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:S,payload:{URI:m.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:m,container:{id:h,endTime:p},branches:C=[],isEOV:u=!1,autoSelected:R=!1})=>{let M=di(m,u),j={timestamp:!M.args.shouldOpenNow||u?1/0:p,priority:"container",initiator:h,actionType:M.type},S=i.emit.bind(i,g.interactives,{subjectId:h,subjectName:"container",type:w.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case _.setNextBranch.trim().toLowerCase():{let z=C.find($=>$.id===M.args.branchId);if(!z)return;S(),e.add({...j,action:x.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{chapterId:z.chapterId,autoSelect:R}})}),n==null||n();return}case _.setMaxWeightBranch.trim().toLowerCase():return;case _.setMinWeightBranch.trim().toLowerCase():return;case _.setRandomBranch.trim().toLowerCase():return;case _.setWeightlessRandomBranch.trim().toLowerCase():return;case _.continuePlayback.trim().toLowerCase():{S(),e.add({...j,action:T.bind(null,{subjectId:h,subjectName:"container",action:M})});return}case _.openURI.trim().toLowerCase():{S(),e.add({...j,action:L.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{URI:m.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:m,branches:h,isEOV:p=!1}){let C=ai(m.events);if(C){let u=di(C.action,p);i.emit(g.interactives,{subjectId:m.id,subjectName:"container",type:w.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:p?1/0:m.endTime,priority:"container",initiator:m.id,actionType:_.expect,action:b.bind(null,{subjectId:m.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of m.events)o({action:u.action,container:m,branches:h,isEOV:p})}let d=({chapterId:m,action:h,branches:p=[]})=>{let C=i.emit.bind(i,g.interactives,{subjectId:m,subjectName:"chapter",type:w.actionChoice,actionType:h.type,payload:h.args});switch(h.type.trim().toLowerCase()){case _.setNextBranch.trim().toLowerCase():{let u=p.find(R=>R.id===h.args.branchId);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case _.setWeightlessRandomBranch.trim().toLowerCase():{let u=nn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case _.setRandomBranch.trim().toLowerCase():{let u=sn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case _.setMaxWeightBranch.trim().toLowerCase():{let u=en(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case _.setMinWeightBranch.trim().toLowerCase():{let u=tn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case _.continuePlayback.trim().toLowerCase():return C(),T.bind(null,{subjectId:m,subjectName:"chapter",action:h});case _.openURI.trim().toLowerCase():return C(),L.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:console.error("Unexpected chapter event"),i.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(m){let h=ai(m.events);if(h){if(J(m))return;i.emit(g.interactives,{subjectId:m.id,subjectName:"chapter",type:w.actionChoice,actionType:h.action.type,payload:h.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:m.id,actionType:_.expect,action:b.bind(null,{subjectId:m.id,subjectName:"chapter"})})}else m.events.forEach(p=>{let C=d({chapterId:m.id,action:p.action,branches:m.branches});C&&e.add({timestamp:1/0,priority:"chapter",initiator:m.id,actionType:p.action.type,action:C})})}let b=({subjectId:m,subjectName:h,action:p})=>{var C;t.pause(),i.emit(g.interactives,{subjectId:m,subjectName:h,type:w.actionExecution,actionType:(C=p==null?void 0:p.type)!=null?C:_.expect})},E=({subjectId:m,subjectName:h})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(g.interactives,{subjectId:m,subjectName:h,type:w.actionExecution,actionType:"after-expect"})},T=({subjectId:m,subjectName:h,subjectType:p,action:C})=>{i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:w.actionExecution,actionType:C.type})},x=({subjectId:m,subjectName:h,subjectType:p,action:C,payload:u})=>{u.behaviour="change-chapter",i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:w.actionExecution,actionType:C.type,payload:u})},H=({subjectId:m,subjectName:h,subjectType:p,action:C,payload:u})=>{u.behaviour="change-manifest",i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:w.actionExecution,actionType:C.type,payload:u})},L=({subjectId:m,subjectName:h,subjectType:p,action:C,payload:u})=>{if(!u.URI)return;let R=window.open(u.URI,"_blank","noopener,noreferrer");R&&(R.opener=null),i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:w.actionExecution,actionType:C.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:b,expectEventHandler:E,setManifestChapterEvents:v,setManifestContainerEvents:c,stopExpect:s,state:r}};import{Subscription as is,ValueSubject as zt}from"@vkontakte/videoplayer-shared";var ui=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let r=t.chapters.find(l=>l.id===n);if(!r)return null;let s=t.media.videos.find(l=>r.videoId===l.id);if(!s)return null;e[n]=an(s)}return e[n]}).filter(Boolean)},Jn=i=>{for(let t of i.variants)if(ts(t)&&"payload"in t)return t.payload.id},ts=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",an=i=>{let t=Jn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},es=(i,t)=>{for(let e of i.media.videos)if(t===an(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},on=(i,t)=>i.reduce((e,n)=>{let r=es(t,n);return r?[...e,r]:e},[]);var tt,gt,vt,X,Te,et,it,q,bt,Mt,At,Wt=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new zt([]),hasPrevChapter$:new zt(!1),prevChapter$:new zt(null),isInitialChapter$:new zt(!1),isGoBackLimited$:new zt(!1)};y(this,tt,null);y(this,gt,void 0);y(this,vt,!1);y(this,X,null);y(this,Te,null);y(this,et,null);y(this,it,null);y(this,q,null);y(this,bt,new is);y(this,Mt,!1);y(this,At,0);var l,o,c;f(this,et,e),f(this,q,t),f(this,it,n),f(this,tt,r),f(this,gt,s),(l=this.state)!=null&&l.history$&&a(this,bt)&&((c=a(this,bt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(d=>{var v,b,E,T,x,H;(v=this.state)==null||v.prevChapter$.next(d.at(-2)||null),(b=this.state)==null||b.hasPrevChapter$.next(d.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((T=(E=a(this,X))==null?void 0:E.metadata)==null?void 0:T.initChapterId)),(H=this.state)==null||H.isGoBackLimited$.next(a(this,At)===a(this,gt).maxLength-1)})))}async setManifest(t){!a(this,it)||!a(this,q)||(f(this,X,t),await this.getProjectHistory(),await a(this,it).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,vt)||(f(this,vt,!0),a(this,q).emit(g.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,vt)}async updateHistory(t,e=!0){var o,c;if(!a(this,X))return;a(this,Mt)?(f(this,Mt,!1),Ti(this,At)._++):f(this,At,0);let n=a(this,X),r=t.length-a(this,gt).maxLength,s=r>0?t.slice(r):t,l=ui(s,n);if(f(this,Te,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,tt)||!a(this,et)))try{await a(this,tt).save(a(this,et),l)}catch(d){(c=a(this,q))==null||c.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var n;if(!this.state||!a(this,it))return(n=a(this,q))==null?void 0:n.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));f(this,Mt,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await a(this,it).setChapter({chapterId:e})}async getProjectHistory(){var r,s;if(!a(this,X)||!a(this,et))return;let t=a(this,X),e=[this.getInitialVideoId()];if(a(this,tt))try{let l=await a(this,tt).get(a(this,et));l.length&&(e=l)}catch(l){(r=a(this,q))==null||r.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Error while trying to fetch data"))}let n=on(e,t);(s=this==null?void 0:this.state)==null||s.history$.next(n)}getInitialChapterId(){var e,n;let t=(e=this.state)==null?void 0:e.history$.getValue();return(t==null?void 0:t.at(-1))||a(this,gt).initChapterId||((n=a(this,X))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,X)){let t=this.getInitialChapterId();return ui([t],a(this,X)).pop()}return null}destroy(){var t,e;this.state=null,f(this,et,null),f(this,tt,null),f(this,it,null),(t=a(this,bt))==null||t.unsubscribe(),f(this,bt,null),f(this,vt,!1),(e=a(this,q))==null||e.emit(g.historyDestroyed),f(this,q,null)}};tt=new WeakMap,gt=new WeakMap,vt=new WeakMap,X=new WeakMap,Te=new WeakMap,et=new WeakMap,it=new WeakMap,q=new WeakMap,bt=new WeakMap,Mt=new WeakMap,At=new WeakMap;var we,cn,Qt,Ve,ln,nt=class nt{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=A(s=nt,we,cn).call(s,t,r),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}};we=new WeakSet,cn=function(t,e){var n;if(e===void 0)return!1;if(typeof e=="boolean")return e;{let r=new Set(["passive","capture"]),s=Object.keys(e).filter(o=>!r.has(o));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),A(n=nt,Ve,ln).call(n,t)?e:e.capture||!1}},Qt=new WeakMap,Ve=new WeakSet,ln=function(t){let e=a(nt,Qt);if(e===void 0){e=!1;try{let n={},r={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);let s=()=>{};t.addEventListener("test",s,n),t.removeEventListener("test",s,n)}catch(n){e=!1}f(nt,Qt,e)}return e||!1},y(nt,we),y(nt,Ve),y(nt,Qt,void 0);var Se=nt;var Re=class{constructor(){this.bindingMap=new Ut}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Se(t,e,n,r);this.bindingMap.push(e,s)}listenOnce(t,e,n,r){let s=l=>{this.unlisten(t,e,s),n(l)};this.listen(t,e,s,r)}unlisten(t,e,n){if(!this.bindingMap)return;let r=this.bindingMap.get(e)||[];for(let s of r)s.target===t&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(e,s))}removeAll(){if(!this.bindingMap)return;let t=this.bindingMap.getAll();for(let e of t)e.unlisten();this.bindingMap.clear()}};var _e=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))==null||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var r;let t=(r=this.rootElement.getContext("2d"))==null?void 0:r.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(){var t;this.canvasImgSrc&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}};var Me=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!=null?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 Cn=Object.defineProperty;var En=(i,t,e)=>t in i?Cn(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var N=(i,t,e)=>(En(i,typeof t!="symbol"?t+"":t,e),e),Ge=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Ge(i,t,"read from private field"),e?e.call(i):t.get(i)),y=(i,t,e)=>{if(t.has(i))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(i):t.set(i,e)},f=(i,t,e,n)=>(Ge(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Ti=(i,t,e,n)=>({set _(r){f(i,t,r,e)},get _(){return a(i,t,n)}}),L=(i,t,e)=>(Ge(i,t,"access private method"),e);var Si="1.0.14-dev.25eb2840.0";function Ue(i,t=1){let e="0",n="0",r="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+r},${t})`}var F="SDK_NAME",In="SDK_NAME-controls-container",te=()=>document.querySelector(`.${In}`),_i=.4,W={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},wi={top:"flex-start",bottom:"flex-end",center:"center"},Vi={start:"flex-start",end:"flex-end",center:"center"},Ri={start:"left",end:"right",center:"center"},ee=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=wi[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:wi.center,i.style.justifyContent=(s=Vi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Vi.center,i.style.textAlign=(o=Ri[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Ri.start},ie=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d;i.style.color=(s=(r=t==null?void 0:t.text)==null?void 0:r.color)!=null?s:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(l=t==null?void 0:t.text)==null?void 0:l.size)!=null?o:e.textSize})`,i.textContent=(d=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?d:e.textContent},ne=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Ue((r=(n=t==null?void 0:t.background)==null?void 0:n.color)!=null?r:e.backgroundColor,(l=(s=t==null?void 0:t.background)==null?void 0:s.alpha)!=null?l:e.backgroundAlpha)},se=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d,v,b,E,T,x;i.style.border=`calc(${n.height} * ${(l=(s=(r=t==null?void 0:t.shape)==null?void 0:r.border)==null?void 0:s.width)!=null?l:e.borderWidth}) solid ${Ue((d=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?d:e.borderColor,(E=(b=(v=t==null?void 0:t.shape)==null?void 0:v.border)==null?void 0:b.alpha)!=null?E:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(T=t==null?void 0:t.shape)==null?void 0:T.roundCorners)!=null?x:e.roundCorners})`},Tt=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var ze="int",St={AREA:`${ze}_area`,TEXT:`${ze}_text`,BUTTON:`${ze}_bttn`};var ct=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${F}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:W.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",s=>{s.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${F}-control-container-${this.control.id}`)}};var re=i=>{if(i.type.trim().toLowerCase()==="area")return new We(i)},We=class extends ct{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");return s.classList.add(`${F}-${this.control.id}`),s.setAttribute("data-testid",St.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",ne({target:s,props:this.control.props,fallback:{...W,backgroundColor:"transparent"}}),se({target:s,props:this.control.props,fallback:{...W,borderAlpha:0},dependsOn:n}),Tt({target:s,layoutParams:this.control.layoutParams,fallback:W}),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${F}-${this.control.id}`)}};var ae=()=>{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 oe=i=>{if(i.type.trim().toLowerCase()==="button")return new Qe(i)},Qe=class extends ct{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");s.type="button",s.classList.add(`${F}-${this.control.id}`),s.setAttribute("data-testid",St.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=ae();return Tt({target:s,layoutParams:this.control.layoutParams,fallback:W}),ne({target:s,props:this.control.props,fallback:W}),se({target:s,props:this.control.props,fallback:W,dependsOn:n}),ee({target:s,props:this.control.props}),ie({target:l,props:this.control.props,fallback:W,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${F}-${this.control.id}`)}};var Ai=i=>{if(i.type.trim().toLowerCase()==="text")return new Ke(i)},Ke=class extends ct{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${F}-${this.control.id}`),s.setAttribute("data-testid",St.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=ae();return Tt({target:s,layoutParams:this.control.layoutParams,fallback:W}),ee({target:s,props:this.control.props}),ie({target:l,props:this.control.props,fallback:W,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${F}-${this.control.id}`)}};var Xe=class{constructor(t){this.layout=t}},Mi=i=>{if(i.type.trim().toLowerCase()==="relative")return new jt(i)},jt=class extends Xe{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 wt,ce,le,Li,Vt=class{constructor(t){y(this,wt);y(this,le);this.container=t,this.factories=new Map,L(this,wt,ce).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),L(this,wt,ce).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),L(this,wt,ce).call(this)}};wt=new WeakSet,ce=function(){this.controls=L(this,le,Li).call(this)},le=new WeakSet,Li=function(){var t;return(t=this.container.controls)==null?void 0:t.reduce((e,n)=>{let r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};var he=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new qe(i,t)},qe=class extends Vt{constructor(t,e){super(t),this.rootElement=e!=null?e:te(),this.layout=new jt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",oe),this.addControlFactory("text",Ai),this.addControlFactory("area",re)}createView(t){let e=document.createElement("div");return e.classList.add(`${F}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{let r=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(r,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=_i,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())==null||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${F}-${this.container.id}`)}};import{Subject as ns,ValueSubject as Z,Observable as dn,once as ss,Subscription as rs,getCurrentBrowser as as,CurrentClientBrowser as os,combine as cs}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as Tn}from"@vkontakte/videoplayer-shared";function de(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Pt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},ft=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Ot=i=>ft(i,Pt.Object),pe=i=>ft(i,Pt.String),ue=i=>ft(i,Pt.Array),fe=i=>ft(i,Pt.Number),Ni=i=>ft(i,Pt.Function);var Ze=i=>fe(i)&&!isNaN(i);var mt=i=>Ot(i)&&Object.keys(i).length===0,Ye=i=>ue(i)&&!i.length;var $t=(i,t)=>pe(i)&&(t?i.trim():i).length;var Je=window.navigator.userAgent.toLowerCase(),Ys=/ipad|iphone|ipod/.test(Je),ki=/mobi/i.test(Je),Js=Je.indexOf("android")>-1&&ki,xn=!ki,tr=window.safari!==void 0&&xn;var ji="video_interactive",Pi="videoint";var Sn=250,Bt=class{constructor(t){N(this,"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}))});N(this,"handleChapterChange",t=>{var e;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.id)){(e=this.onError)==null||e.call(this,"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}});N(this,"handleManifestChange",async(t,e=[])=>{var n;if(!fe(t.graph.edit.chapters[0].x)){this.isReady=!1,(n=this.onError)==null||n.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await Tn(this.lang,ji,Pi)}catch(l){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:r}),this.ngEditor.on("control",({name:l,chapterId:o})=>{l==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",l=>{this.lastZoomInfo={...l}})}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});this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:r,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=e,this.onError=n,this.lang=r!=null?r:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=wn(t),this.resizeObserver=new ResizeObserver(de(this.onResize,Sn)),this.resizeObserver.observe(this.graphWrapperElement)}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]}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(){var t,e;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)==null||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)==null||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function wn(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 ti=()=>{let i=[],t=null;return{setPlayer:l=>{t=l},setContainers:l=>{i=l},deleteContainer:l=>{i=i.filter(o=>o.id!==l)},getNextInteractiveTime:(l=3e3)=>{if(!i.length||t===null)return null;let o=-1,c=!1,d=Math.round(t.info.position$.getValue()*1e3);for(let v of i){let b=v.startTime-l;if(b<=d&&(d<=v.endTime||v.endTime===null)){c=!0;break}d<b&&(o=o===-1?b:Math.min(o,b))}return!c&&o!==-1?o:null}}};var lt=(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 Vn}from"uuid";var Rn="3.1",Oi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},_n={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},$i=i=>{let t=[];for(let e of i.chapters){let n,r=[];for(let{isDefault:o,...c}of e.branches)o&&(n=c.id),r.push(c);let s=[],l=[];for(let{fallbackStrategy:o,...c}of e.containers){let d=!!c.endTime,v=[_n];switch(o){case"await":d?v=[]:s=[];break;case"default":{let b={type:"onSuspense",action:{type:Oi.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?v=[b]:s=[b];break}case"random":case"weightlessRandom":case"max":case"min":{let b={type:"onSuspense",action:{type:Oi[o],args:{}}};d?v=[b]:s=[b];break}}for(let b of c.controls)l.push({...c,controls:[{...b}],id:Vn(),events:v})}t.push({...e,containers:l,events:s,branches:r})}return i.metadata.version=Rn,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var An="3.2",Bi=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:An},media:t}}return i};var Mn="3.3",Ln=(i=[])=>({edit:{chapters:i},view:{}}),Fi={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Di=i=>{var n;let t=[],e=[];for(let r of i.chapters){let{id:s,x:l,y:o,...c}=r,d=c.containers.map(v=>{var b;return{...v,controls:v.controls.map(({subtype:E,type:T,...x})=>({...x,type:E!=null?E:T})),events:(b=v.events)!=null&&b.length?v.events:[Fi]}});t.push({id:s,...c,containers:d,events:(n=c.events)!=null&&n.length?c.events:[Fi]}),e.push({id:s,x:l,y:o})}return{...i,chapters:t,graph:Ln(e),metadata:{...i.metadata,version:Mn}}};var Nn=[{version:"3.0",migrate:$i},{version:"3.1",migrate:Bi},{version:"3.2",migrate:Di}],ei=i=>Nn.reduce((t,e)=>lt(t.metadata.version,e.version)?t:e.migrate(t),i);var wr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Hi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Vr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),A=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),ii=(s=>(s.GO_NEXT_BUTTON="GO_NEXT_BUTTON",s.GO_NEXT_AREA="GO_NEXT_AREA",s.WATCH_AGAIN="WATCH_AGAIN",s.OPEN_GRAPH="OPEN_GRAPH",s.CLOSE_GRAPH="CLOSE_GRAPH",s))(ii||{});var Gi={metadata:"Object",chapters:"Array"},kn="3.0.0",jn="3.3.0",me=i=>{let t=lt(i,kn);return t===-1?!1:t===0?!0:lt(i,jn)!==1},Ui=i=>{if(!Ot(i))return!1;for(let t in Gi)if(!i[t]||!ft(i[t],Gi[t]))return!1;return me(i.metadata.version)},ye=i=>i.type===Hi.Text;var I=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};N(I,"Severity",{RECOVERABLE:1,CRITICAL:2}),N(I,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var Rt=class{constructor(){N(this,"listeners",{})}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t];if(!n)return this;for(let r=n.length;r>0;r--)if(n[r]===e){n.splice(r,1);break}return this}emit(t,...e){let n=this.listeners[t];return n?(n.forEach(r=>{r(...e)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}};var ge=class{constructor(t){N(this,"addFn",(t,e=!1)=>{Ni(t)&&(this.fns.push(t),e&&this.updateFn())});N(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});N(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});N(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});N(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});N(this,"cancelAnimation",()=>{cancelAnimationFrame(this.raf),this.raf=void 0});this.raf,this.fn,this.fns=[],this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}};import{ValueSubject as Hn}from"@vkontakte/videoplayer-shared";var ve=class{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!=null?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!=null?n:[]}}async exec(t,e){return Pn(...this.loaders[t])(e)}};function Pn(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function Ft(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function be({actions:i,errors:t,chapterId:e,...n}){if(e){let r=i.getManifest(),s=i.getChapter(r.chapters,e);if(s){let l=i.getMedia(r.media,s.videoId),o=i.getGraph(r.graph,s.id);return l?{...n,actions:i,errors:t,result:{chapter:s,media:l,graph:o}}:{...n,errors:Ft(t,be.name,"Could not find media"),actions:i}}}return{...n,errors:Ft(t,be.name,"Could not find chapter"),actions:i}}var On=async i=>{try{let t,e;if(Ot(i))t=i;else if(pe(i)){e=new URL(i).href;let r=await fetch(e);if(!r.ok)return{};t=await r.json()}else return{};if(!Ui(t))return{};let n=t.metadata.media;if(pe(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=await fetch(r);if(!s.ok)throw new Error;t.metadata.media=await s.json()}catch(r){return Fn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}};async function zi(i){let{manifest:t,manifestURL:e}=await On(i),n=ei(t);return n.media=$n(n.media,e),delete n.metadata.media,n}function Ce(i,t){return i.find(e=>e.id===t)}function ni(i,t){var e,n;return(e=i.edit)!=null&&e.chapters?i.edit.chapters.find(r=>r.id===t):(n=i.view)!=null&&n.chapters?i.view.chapters.find(r=>r.id===t):void 0}function si(i,t){return i.videos.find(e=>e.id===t)}function $n(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let r=Bn(n.url,t);return{...n,url:r||n.url}})}))}}function Bn(i,t){try{return new URL(i,t).href}catch(e){return""}}function Fn(i){return lt(i,"3.2.0")>=0}var P=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ee=i=>ue(i)&&!Ye(i),J=i=>i.order==="end",Ie=i=>ue(i.containers)&&!Ye(i.containers)&&J(i),Wi=(i,t)=>{var n;let e=i*1e3;return Ee(t.controls)&&e<((n=t.startTime)!=null?n:0)},ri=(i,t)=>{var n,r;let e=i*1e3;return Ee(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var yt=i=>i.some(t=>t.action.type==="expect"),ai=i=>i.find(t=>t.action.type==="expect"),Dn=i=>(i==null?void 0:i.length)===1,xe=i=>Dn(i)&&ye(i[0]);var Qi=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),Ki=(i,t)=>yt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&yt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var _t=class extends ve{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new Hn(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){var r;this.release();let e=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ft},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=await zi((r=e.result)!=null?r: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",be({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ni,getChapter:Ce,getMedia:si,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ft},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=Ce(this.manifest.chapters,t);if(e){let n=si(this.manifest.media,e.videoId),r=ni(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:r}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{let e=Ce(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{let r=this.getByChapterId(n.chapterId);return r&&e.push(r),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return J(this.chapter)}};import{Player as Gn}from"@vkontakte/videoplayer-core";import{Subscription as Un}from"@vkontakte/videoplayer-shared";var Xi=i=>{let t=i.variants.find(e=>{var n;return((n=e.payload)==null?void 0:n.type)==="vk"});if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var g={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Dt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},V={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function oi(){let i=new Map;function t({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...l}){let o=i.get(r),c={...l};return o?o[s]=c:i.set(r,{[s]:c}),{listId:r,itemId:s,...l}}function e(r,s){var o,c,d;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(d=l[s])==null||d.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let v of Object.values(l))v.player.destroy(),v.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(let r of i)e(r[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function ci(i,t=[]){var s,l,o;let e={},n,r=!t.length;for(let c of i.variants)if(!n&&"cover"in c&&(n=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(r||t.includes("mp4"))&&(e.MPEG={...e.MPEG,[(s=c.standard)!=null?s:"Invariant quality"]:c.url});break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG={...e.MPEG,[(l=c.standard)!=null?l:"Invariant quality"]:c.url});break;case"hls":(r||t.includes("hls"))&&(e={...e,HLS:{type:"url",url:c.url}});break;case"dash":(r||t.includes("dash"))&&(e={...e,DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}});break;default:break}return{sources:e,thumbUrl:n,title:(o=i.title)!=null?o:""}}var Ht=(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 Gt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},zn=2;function li(i){let t=oi(),e,n,r=new Rt,s={},l=!1,o=null,c=!1,d;i&&v(i);function v(h){o=h}function b(h,p,C){var M;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let _=((M=t.map.get(h))!=null?M:{})[p];if(_){s={chapterId:C,listId:h,itemId:p,..._};let j=s.player;n=j.info.currentQuality$.subscribe(w=>{if(!(!w||!j.info.position$.getValue())){e=w;for(let z of t.map)Object.values(z[1]).forEach(({player:B})=>{j.info.isAutoQualityEnabled$.getValue()||Ht(B,w)})}}),_.container.remove(),l=!1,o.setPlayer(_.player),c||(o.init(),c=!0),r.emit(Gt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function E(h,p,C){if(!o)throw Error("need to set interactive controller");if(mt(s)||h!==s.itemId)return;if(C>=0&&!l){let _=o.getChapterBranches();l=!0;let M=new Set;for(let j of _)M.has(j.media.id)||(await x({media:j.media,chapterId:j.chapter.id,setAsActive:!1,title:j.chapter.label}),M.add(j.media.id))}}async function T({chapter:{id:h},media:p}){if(mt(s))return;n==null||n.unsubscribe();let C=s.player.info.muted$.getValue(),u=s.player.info.currentQuality$.getValue(),_=s.player.info.isAutoQualityEnabled$.getValue(),M=s.player.info.volume$.getValue(),j=s.player.info.currentPlaybackRate$.getValue(),w=!_,z=!1;for(let B of t.map)if(B[0]===p.id){let Y=Object.keys(B[1]);for(let G of Y)G===s.itemId?(Y.length<zn||(z=!0),t.removePlayer(B[0],G)):(z=!0,b(B[0],G,h),w?Ht(s.player,u):s.player.setAutoQuality(!0),s.player.setVolume(M),s.player.setMuted(C),s.player.setPlaybackRate(j))}else t.removePlayer(B[0]);z||(await x({media:p,chapterId:h,setAsActive:!0,playbackRate:j}),w?Ht(s.player,u):s.player.setAutoQuality(!0),s.player.setVolume(M),s.player.setMuted(C))}async function x({media:h,chapterId:p,prefetch:C=!0,setAsActive:u=!0,autoplay:_=!1,preferredExt:M,title:j,playbackRate:w}){var bi,Ci,Ei,Ii,xi;let z=Math.random().toString(),B=document.createElement("div");d.append(B);let Y=(bi=s==null?void 0:s.player)==null?void 0:bi.info.isAutoQualityEnabled$.getValue(),G;if((Ci=o==null?void 0:o.options)!=null&&Ci.vkVideoLoader){let Jt=Xi(h);Jt.length&&(G=await o.options.vkVideoLoader(...Jt))}let Yt=((Ei=o==null?void 0:o.options)==null?void 0:Ei.coreConfig)||{},bn={...Yt,configName:[...(Ii=Yt.configName)!=null?Ii:[],"interactive"]},gi={container:B,...((xi=G==null?void 0:G.videos)==null?void 0:xi[0])||{sources:ci(h,M).sources},title:j,failoverHosts:(G==null?void 0:G.failoverHosts)||[]},ut=new Gn(bn);ut.initVideo(gi);let vi=new Un;vi.add(ut.info.position$.subscribe(function(Jt){E(z,ut.info.duration$.getValue(),Jt)})).add(ut.events.canplay$.subscribe(function(){Y||Ht(ut,e),w&&ut.setPlaybackRate(w)}));let xt=t.createPlayer({listId:h.id,itemId:z,player:ut,container:B,sources:ci(h,M).sources,config:gi,subscription:vi});return u&&b(h.id,xt.itemId,p),_&&xt.player.play(),C&&!_&&xt.player.prepare(),r.emit(Gt.playerCreated,xt.player),{player:xt.player,config:xt.config}}function $(){S(),o=null}function S(){o==null||o.off(g.chapterChanged,T),t.removeAll(),s={},c=!1,l=!1}async function m({container:h}){if(!o)throw Error("need to set interactive controller");S(),d=h;let{media:p,chapter:C}=o.getCurrentChapter();if(p){o.on(g.chapterChanged,T);let{player:u,config:_}=await x({media:p,chapterId:C.id,title:C.label});return r.emit(Gt.initiated,{container:h,media:p,chapterId:C.id}),{player:u,config:_}}else console.error("not found")}return{...t,on:r.on.bind(r),off:r.off.bind(r),init:m,setInteractiveController:v,createPlayer:x,removeAll:$,getActivePlayer:function(){return s}}}import{Subscription as Wn}from"@vkontakte/videoplayer-shared";var Te=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d,onRemove:v}){N(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==P.end&&(yt(this.container.container.events)&&this.gameState===P.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==P.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!1})))})});N(this,"show",()=>{var t,e,n,r;if(this.gameState===P.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!0,isFirst:!1});else{let l=Qi({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!1})),(this.gameState===P.end||this.gameState===P.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!1}))},isEOV:()=>this.gameState===P.end});this.container.createView(l),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});N(this,"onEndOfVideo",()=>{this.gameState=P.end,this.selectContainerEvent(!0)});N(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[P.destroyed,P.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Wi(e,this.container.container))this.gameState!==P.beforeInteractive&&(this.gameState=P.beforeInteractive,this.onBeforeStartTime());else if(ri(e,this.container.container))this.gameState!==P.interactive&&(this.gameState=P.interactive,this.onStartTime());else if(this.gameState!==P.afterInteractive){let o=this.gameState;this.gameState=P.afterInteractive,o===P.interactive&&this.onEndTime()}else this.gameState!==P.destroyed&&!this.isPermanentText&&this.removeView();let n=ri(e,this.container.container),r=this.container.container.startTime?[this.container.container.startTime,(l=this.container.container.endTime)!=null?l:1/0]:[];this.globalEventEmitter.emit(g.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:r,currentTime:e,isInteractiveTime:n})});this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Wn,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&xe(e.container.controls),this.disabledControls$=d,this.onRemove=v,this.globalEventEmitter=l,this.gameState=P.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=>{var e,n,r,s;t?(n=(e=this.container).disable)==null||n.call(e):(s=(r=this.container).enable)==null||s.call(r)}))}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=yt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)==null||e.call(t),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=P.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(g.interactives,{subjectId:this.container.container.id,subjectName:"container",type:V.containerRemoved,visibility:!1}),this.gameState=P.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=P.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!=null?t:1/0,id:this.container.container.id})}};var qi=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!ye(c));if(Ee(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],d=e.id;if(!n)t.push({subjects:[d],range:c});else{let v=[],b=-1/0,E=1/0,T=[],x=[];for(let $=0;$<t.length;$++){let S=t[$];if(x.push(...S.subjects),S.range[0]<E&&(E=S.range[0]),S.range[1]>b&&(b=S.range[1]),c[0]>=S.range[0]&&c[1]<=S.range[1])return t[$].subjects.push(d),t;c[0]<S.range[0]&&c[1]>S.range[0]&&(v.push($),T=T.concat(S.subjects)),c[0]>=S.range[0]&&c[0]<=S.range[1]&&(v.push($),T=T.concat(S.subjects),c[0]=S.range[0]),c[1]>=S.range[0]&&c[1]<=S.range[1]&&(v.push($),T=T.concat(S.subjects),c[1]=S.range[1])}if(x.push(d),c[0]<=E&&c[1]>=b)return[{subjects:x,range:c}];v.length&&v.reverse().forEach($=>{t.splice($,1)}),t.push({subjects:T.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Zi(){let i={};function t(){for(let o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){let c={};for(let d in i)+d<=o&&(c[d]=i[d]);return c}function n(o){let c={};for(let d in i)+d>=o&&(c[d]=i[d]);return c}function r({timestamp:o,priority:c,initiator:d}){var v;if(Ze(o)){let b=(v=i[o])!=null?v:null;if(b&&$t(c,!0)){let E={},T=b[c];if(T&&(E={...E,...T}),E=mt(E)?null:E,E&&$t(d,!0)){let x=E[d];return x!=null?x:null}return E}return b}return null}function s({timestamp:o,priority:c,initiator:d}){if(Ze(o))if(i[o]){if($t(c,!0))if(i[o][c]){if($t(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!mt(i[o][c]))return!0}else return!1;if(delete i[o][c],!mt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l({timestamp:o,priority:c,initiator:d,...v}){var b,E,T;(E=(b=i[o])==null?void 0:b[c])!=null&&E[d]?i[o][c][d].push({...v}):(T=i[o])!=null&&T[c]?i[o][c]={...i[o][c],[d]:[{...v}]}:i[o]?i[o]={...i[o],[c]:{[d]:[{...v}]}}:i[o]={[c]:{[d]:[{...v}]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var Qn=[A.expect,A.setNextBranch],Kn=1/0;function hi(i){let t=i,e,n=Xn(),r=new Zi,s,l=()=>{E(),m()},o=h=>{r.add.call(void 0,h),x()},c=(h=[])=>{for(let p of h)if(p.action(),Qn.includes(p.actionType))break},d=(h=1/0)=>{var _,M,j;let p=Se((_=r.get({timestamp:h,priority:"control"}))!=null?_:{}),C=Se((M=r.get({timestamp:h,priority:"container"}))!=null?M:{}),u=Se((j=r.get({timestamp:h,priority:"chapter"}))!=null?j:{});return[...p,...C,...u]},v=h=>{n.isReady(h)&&c(d(h))},b=()=>{var h;c([...Se((h=r.get({timestamp:1/0,priority:"chapter"}))!=null?h:{})])},E=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},T=h=>{},x=()=>{e||(e=()=>setTimeout(()=>{v(1/0)}),s=t.events.ended$.subscribe(e))},$=h=>{E(),t=h},S=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),r.remove(h)},m=()=>{n.release(),r.removeAll()};return{setPlayer:$,add:o,remove:S,exec:v,execEndOfVideo:b,listen:x,unlisten:E,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function Xn(){let i=new Map;return{setCalled:({timestamp:l,id:o})=>{let c=i.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(let d of l){let v=(o=d.endTime)!=null?o:Kn,b=(c=i.get(v))!=null?c:{};i.set(v,{...b,[d.id]:!1})}},resetCalled:l=>{let o=i.get(l);if(o)for(let c in o)o[c]=!1},isReady:l=>{let o=i.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>i.clear()}}function Se(i){return Object.values(i).flat().sort(t=>t.actionType===A.expect?-1:1)}var Yi=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};let{clientHeight:r,clientWidth:s}=t.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};let l=e/n,o=r/s,c,d;return o>l?(d=s,c=s*l):o<l?(d=r/l,c=r):(d=s,c=r),{videoContentWidth:d,videoContentHeight:c}};var qn=250;function Ji(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:d}=i();if(c&&d){let{videoContentWidth:v,videoContentHeight:b}=Yi(c,d);c.style.setProperty("--interactive-content-width",`${v}px`),c.style.setProperty("--interactive-content-height",`${b}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function r(){let{parentElement:o}=i();o.removeAttribute("style")}let s=de(o=>{let{fns:c=[]}=i();n(o);for(let d of c)d()},qn);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Ut=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 Zn=i=>Math.floor(Math.random()*i),tn=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},en=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 nn=i=>{let t=i.length,e=Zn(t);return i[e]};var sn=i=>{var n,r;let t=0;for(let s=0;s<i.length;++s)t+=(n=i[s].weight)!=null?n:1;let e=Math.random()*t;t=0;for(let s=0;s<i.length-1;++s)if(t+=(r=i[s].weight)!=null?r:1,t>=e)return i[s];return i[i.length-1]};var rn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var di=(i,t=!1)=>({...i,args:t?{...i.args,...rn}:{...rn,...i.args}}),pi=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:m,controlType:h,controlId:p,containerId:C,branches:u=[],onEvent:_,isEOV:M=()=>!1,isDisabled:j=()=>!1})=>{let w=di(m,M()),z={timestamp:1/0,priority:"control",initiator:p,actionType:w.type},B=j(),Y=i.emit.bind(i,g.interactives,{subjectId:p,subjectType:h,subjectName:"control",type:B?V.actionChoiceCanceled:V.actionChoice,actionType:m.type,payload:{containerId:C,...w.args}});if(B){Y();return}switch(w.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let G=u.find(Yt=>Yt.id===w.args.branchId);if(!G)return;_(w.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),Y(),w.args.shouldOpenNow?x({subjectId:p,subjectName:"control",subjectType:h,action:w,payload:{chapterId:G.chapterId,autoSelect:!1}}):(e.add({...z,action:x.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:w,payload:{chapterId:G.chapterId,autoSelect:!1}})}),n==null||n());return}case A.continuePlayback.trim().toLowerCase():{_(w.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),Y(),w.args.shouldOpenNow?T({subjectId:p,subjectName:"control",subjectType:h,action:m}):e.add({...z,action:T.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:m})});return}case A.openURI.trim().toLowerCase():{_(w.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),Y(),w.args.shouldOpenNow?S({subjectId:p,subjectName:"control",subjectType:h,action:w,payload:{URI:m.args.uri}}):(e.add({...z,action:S.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:w,payload:{URI:m.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:m,container:{id:h,endTime:p},branches:C=[],isEOV:u=!1,autoSelected:_=!1})=>{let M=di(m,u),j={timestamp:!M.args.shouldOpenNow||u?1/0:p,priority:"container",initiator:h,actionType:M.type},w=i.emit.bind(i,g.interactives,{subjectId:h,subjectName:"container",type:V.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let z=C.find(B=>B.id===M.args.branchId);if(!z)return;w(),e.add({...j,action:x.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{chapterId:z.chapterId,autoSelect:_}})}),n==null||n();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{w(),e.add({...j,action:T.bind(null,{subjectId:h,subjectName:"container",action:M})});return}case A.openURI.trim().toLowerCase():{w(),e.add({...j,action:S.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{URI:m.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:m,branches:h,isEOV:p=!1}){let C=ai(m.events);if(C){let u=di(C.action,p);i.emit(g.interactives,{subjectId:m.id,subjectName:"container",type:V.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:p?1/0:m.endTime,priority:"container",initiator:m.id,actionType:A.expect,action:b.bind(null,{subjectId:m.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of m.events)o({action:u.action,container:m,branches:h,isEOV:p})}let d=({chapterId:m,action:h,branches:p=[]})=>{let C=i.emit.bind(i,g.interactives,{subjectId:m,subjectName:"chapter",type:V.actionChoice,actionType:h.type,payload:h.args});switch(h.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let u=p.find(_=>_.id===h.args.branchId);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{let u=nn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{let u=sn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{let u=en(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{let u=tn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return C(),T.bind(null,{subjectId:m,subjectName:"chapter",action:h});case A.openURI.trim().toLowerCase():return C(),S.bind(null,{subjectId:m,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:console.error("Unexpected chapter event"),i.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(m){let h=ai(m.events);if(h){if(J(m))return;i.emit(g.interactives,{subjectId:m.id,subjectName:"chapter",type:V.actionChoice,actionType:h.action.type,payload:h.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:m.id,actionType:A.expect,action:b.bind(null,{subjectId:m.id,subjectName:"chapter"})})}else m.events.forEach(p=>{let C=d({chapterId:m.id,action:p.action,branches:m.branches});C&&e.add({timestamp:1/0,priority:"chapter",initiator:m.id,actionType:p.action.type,action:C})})}let b=({subjectId:m,subjectName:h,action:p})=>{var C;t.pause(),i.emit(g.interactives,{subjectId:m,subjectName:h,type:V.actionExecution,actionType:(C=p==null?void 0:p.type)!=null?C:A.expect})},E=({subjectId:m,subjectName:h})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(g.interactives,{subjectId:m,subjectName:h,type:V.actionExecution,actionType:"after-expect"})},T=({subjectId:m,subjectName:h,subjectType:p,action:C})=>{i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:V.actionExecution,actionType:C.type})},x=({subjectId:m,subjectName:h,subjectType:p,action:C,payload:u})=>{u.behaviour="change-chapter",i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:V.actionExecution,actionType:C.type,payload:u})},$=({subjectId:m,subjectName:h,subjectType:p,action:C,payload:u})=>{u.behaviour="change-manifest",i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:V.actionExecution,actionType:C.type,payload:u})},S=({subjectId:m,subjectName:h,subjectType:p,action:C,payload:u})=>{if(!u.URI)return;let _=window.open(u.URI,"_blank","noopener,noreferrer");_&&(_.opener=null),i.emit(g.interactives,{subjectId:m,subjectName:h,subjectType:p,type:V.actionExecution,actionType:C.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:b,expectEventHandler:E,setManifestChapterEvents:v,setManifestContainerEvents:c,stopExpect:s,state:r}};import{Subscription as is,ValueSubject as zt}from"@vkontakte/videoplayer-shared";var ui=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let r=t.chapters.find(l=>l.id===n);if(!r)return null;let s=t.media.videos.find(l=>r.videoId===l.id);if(!s)return null;e[n]=an(s)}return e[n]}).filter(Boolean)},Jn=i=>{for(let t of i.variants)if(ts(t)&&"payload"in t)return t.payload.id},ts=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",an=i=>{let t=Jn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},es=(i,t)=>{for(let e of i.media.videos)if(t===an(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},on=(i,t)=>i.reduce((e,n)=>{let r=es(t,n);return r?[...e,r]:e},[]);var tt,gt,vt,X,we,et,it,q,bt,At,Mt,Wt=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new zt([]),hasPrevChapter$:new zt(!1),prevChapter$:new zt(null),isInitialChapter$:new zt(!1),isGoBackLimited$:new zt(!1)};y(this,tt,null);y(this,gt,void 0);y(this,vt,!1);y(this,X,null);y(this,we,null);y(this,et,null);y(this,it,null);y(this,q,null);y(this,bt,new is);y(this,At,!1);y(this,Mt,0);var l,o,c;f(this,et,e),f(this,q,t),f(this,it,n),f(this,tt,r),f(this,gt,s),(l=this.state)!=null&&l.history$&&a(this,bt)&&((c=a(this,bt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(d=>{var v,b,E,T,x,$;(v=this.state)==null||v.prevChapter$.next(d.at(-2)||null),(b=this.state)==null||b.hasPrevChapter$.next(d.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((T=(E=a(this,X))==null?void 0:E.metadata)==null?void 0:T.initChapterId)),($=this.state)==null||$.isGoBackLimited$.next(a(this,Mt)===a(this,gt).maxLength-1)})))}async setManifest(t){!a(this,it)||!a(this,q)||(f(this,X,t),await this.getProjectHistory(),await a(this,it).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,vt)||(f(this,vt,!0),a(this,q).emit(g.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,vt)}async updateHistory(t,e=!0){var o,c;if(!a(this,X))return;a(this,At)?(f(this,At,!1),Ti(this,Mt)._++):f(this,Mt,0);let n=a(this,X),r=t.length-a(this,gt).maxLength,s=r>0?t.slice(r):t,l=ui(s,n);if(f(this,we,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,tt)||!a(this,et)))try{await a(this,tt).save(a(this,et),l)}catch(d){(c=a(this,q))==null||c.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var n;if(!this.state||!a(this,it))return(n=a(this,q))==null?void 0:n.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));f(this,At,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await a(this,it).setChapter({chapterId:e})}async getProjectHistory(){var r,s;if(!a(this,X)||!a(this,et))return;let t=a(this,X),e=[this.getInitialVideoId()];if(a(this,tt))try{let l=await a(this,tt).get(a(this,et));l.length&&(e=l)}catch(l){(r=a(this,q))==null||r.emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Error while trying to fetch data"))}let n=on(e,t);(s=this==null?void 0:this.state)==null||s.history$.next(n)}getInitialChapterId(){var e,n;let t=(e=this.state)==null?void 0:e.history$.getValue();return(t==null?void 0:t.at(-1))||a(this,gt).initChapterId||((n=a(this,X))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,X)){let t=this.getInitialChapterId();return ui([t],a(this,X)).pop()}return null}destroy(){var t,e;this.state=null,f(this,et,null),f(this,tt,null),f(this,it,null),(t=a(this,bt))==null||t.unsubscribe(),f(this,bt,null),f(this,vt,!1),(e=a(this,q))==null||e.emit(g.historyDestroyed),f(this,q,null)}};tt=new WeakMap,gt=new WeakMap,vt=new WeakMap,X=new WeakMap,we=new WeakMap,et=new WeakMap,it=new WeakMap,q=new WeakMap,bt=new WeakMap,At=new WeakMap,Mt=new WeakMap;var Re,cn,Qt,_e,ln,nt=class nt{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=L(s=nt,Re,cn).call(s,t,r),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}};Re=new WeakSet,cn=function(t,e){var n;if(e===void 0)return!1;if(typeof e=="boolean")return e;{let r=new Set(["passive","capture"]),s=Object.keys(e).filter(o=>!r.has(o));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),L(n=nt,_e,ln).call(n,t)?e:e.capture||!1}},Qt=new WeakMap,_e=new WeakSet,ln=function(t){let e=a(nt,Qt);if(e===void 0){e=!1;try{let n={},r={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);let s=()=>{};t.addEventListener("test",s,n),t.removeEventListener("test",s,n)}catch(n){e=!1}f(nt,Qt,e)}return e||!1},y(nt,Re),y(nt,_e),y(nt,Qt,void 0);var Ve=nt;var Ae=class{constructor(){this.bindingMap=new Ut}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Ve(t,e,n,r);this.bindingMap.push(e,s)}listenOnce(t,e,n,r){let s=l=>{this.unlisten(t,e,s),n(l)};this.listen(t,e,s,r)}unlisten(t,e,n){if(!this.bindingMap)return;let r=this.bindingMap.get(e)||[];for(let s of r)s.target===t&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(e,s))}removeAll(){if(!this.bindingMap)return;let t=this.bindingMap.getAll();for(let e of t)e.unlisten();this.bindingMap.clear()}};var Me=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))==null||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var r;let t=(r=this.rootElement.getContext("2d"))==null?void 0:r.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(){var t;this.canvasImgSrc&&((t=this.rootElement.getContext("2d"))==null||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}};var Le=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!=null?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;
@@ -11,7 +11,7 @@ var Cn=Object.defineProperty;var En=(i,t,e)=>t in i?Cn(i,t,{enumerable:!0,config
11
11
  height: var(--interactive-height);
12
12
  background-color: var(--black);
13
13
  visibility: hidden;
14
- `,this.lastFrameCanvas=new _e,this.endOffsetMs=e,this._callbacks={onError:n},this.lastFrameCanvas.rootElement.style.cssText=`
14
+ `,this.lastFrameCanvas=new Me,this.endOffsetMs=e,this._callbacks={onError:n},this.lastFrameCanvas.rootElement.style.cssText=`
15
15
  position: absolute;
16
16
  top: 50%;
17
17
  left: 50%;
@@ -20,4 +20,4 @@ var Cn=Object.defineProperty;var En=(i,t,e)=>t in i?Cn(i,t,{enumerable:!0,config
20
20
  position: absolute;
21
21
  top: 0;
22
22
  left: 0;
23
- `,i}var ht,Q,dt,U,rt,F,K,at,k,ot,Lt,D,Nt,O,V,pt,Ct,Ne,un,ke,fn,kt,Ae,yi,je,Pe,mn,Xt,fi,Et,It,Kt,Oe,yn,qt,mi,$e,gn,Be,vn,Fe,Zt,Le=class{constructor(t){y(this,Ne);y(this,ke);y(this,kt);y(this,Pe);y(this,Xt);y(this,It);y(this,Oe);y(this,qt);y(this,$e);y(this,Be);y(this,ht,null);y(this,Q,null);y(this,dt,null);y(this,U,null);y(this,rt,null);y(this,F,null);y(this,K,null);y(this,at,null);y(this,k,null);y(this,ot,new Z(!1));y(this,Lt,new Set);y(this,D,null);y(this,Nt,null);y(this,O,null);y(this,V,null);y(this,pt,Ye());y(this,Ct,null);N(this,"state",{prevChapter$:new Z(null),isInitialChapter$:new Z(!1),isEndChapter$:new Z(!1),isInteractiveExpectation$:new Z(!1),calledByInteractive$:new Z(!1),lastChapterChangeWasInitiatedByInteractive$:new Z(!1),disabledControls$:new Z(!1),interactiveRanges$:new Z([]),isInteractiveTime$:new Z(!1)});N(this,"events",{noInteraction$:new ns});N(this,"emitPlayerChanged",t=>{a(this,V).emit(g.playerChanged,t)});y(this,yi,()=>{a(this,K).fns.forEach(n=>n());let t=this.options.player.info.position$.getValue()*1e3,e=(a(this,k).chapter.containers||[]).filter(n=>n.startTime>=Math.floor(t));for(let n of e){a(this,F).remove({timestamp:1/0,priority:"container",initiator:n.id});for(let r of n.controls)a(this,F).remove({timestamp:1/0,priority:"control",initiator:r.id});a(this,Q).find(r=>r.container.container.id===n.id).reset()}});y(this,je,()=>{a(this,ht).calc(),a(this,K).requestAnimation()});y(this,Et,(t=!0)=>{a(this,Q).forEach(e=>{!t&&e.isPermanentText||(a(this,K).removeFn(e.whilePlaying),e.destroy())})});y(this,Fe,t=>{let{interactiveRanges$:e}=this.state,r=e.getValue().map(s=>({...s,subjects:s.subjects.filter(l=>l!==t)}));e.next(r)});y(this,Zt,()=>{a(this,Ct)&&(clearTimeout(a(this,Ct)),f(this,Ct,null))});var e;this.options={...pn,...t,config:{...pn.config,...t.config}},f(this,Q,[]),this.factories=new Map([["choice",he]]),this.rootElement=ls(),this.options.parentElement.append(this.rootElement),f(this,V,new Rt),f(this,rt,new rs),f(this,dt,new Re),f(this,U,new Wt({interactiveController:this,globalEventEmitter:a(this,V),videoId:(e=this.options.projectInfo)==null?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&f(this,O,new Me({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,V).emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.SEAMLESS,n))})),a(this,dt).listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,dt).listen(this.rootElement,"mouseup",n=>n.stopPropagation()),f(this,k,new _t(this.options.loaders,n=>a(this,V).emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.MANIFEST,n)))),f(this,F,hi(this.options.player)),f(this,K,new ye),f(this,at,pi({player:this.options.player,interactiveEvents:a(this,F),globalEventEmitter:a(this,V),removeControllers:a(this,Et)})),f(this,ht,Ji(()=>{var n,r,s;return{player:(n=this.options)==null?void 0:n.player,parentElement:(r=this.options)==null?void 0:r.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,O).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&f(this,D,new Bt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,V).emit(g.graph,{type:Dt.watchAgainClicked,chapterId:n})},onError:n=>a(this,V).emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.LOADERS,{message:n}))})),A(this,Ne,un).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=st.created}getStatEvents(){return{click$:new dn(t=>{a(this,V).on(g.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?"OPEN_GRAPH":"CLOSE_GRAPH"),e==="watchAgainClicked"&&t.next("WATCH_AGAIN")}),a(this,V).on(g.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next("GO_NEXT_BUTTON"),r==="Area"&&t.next("GO_NEXT_AREA"))})}),nextMovie$:new dn(t=>{a(this,V).on(g.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){A(this,kt,Ae).call(this),this.options.player=t,a(this,pt).setPlayer(this.options.player),a(this,F)?a(this,F).setPlayer(this.options.player):f(this,F,hi(this.options.player)),f(this,at,pi({player:this.options.player,interactiveEvents:a(this,F),globalEventEmitter:a(this,V),removeControllers:()=>a(this,Et).call(this,!1)})),this.appState===st.initiated&&(A(this,Xt,fi).call(this),A(this,It,Kt).call(this,a(this,k).chapter))}async setManifest(t){A(this,kt,Ae).call(this),this.isFirstChapterFetched=!1;let e=await a(this,k).setManifest(t);return a(this,D)&&await a(this,D).handleManifestChange(e.manifest),await a(this,U).setManifest(e.manifest),a(this,V).emit(g.manifestChanged,{manifest:e.manifest}),A(this,It,Kt).call(this,a(this,k).chapter),e.manifest}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,D))==null||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,D))==null||e.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:e=!0}={}){var o;A(this,kt,Ae).call(this),a(this,O)&&this.isFirstChapterFetched&&(a(this,O).draw(),a(this,O).show()),as().browser===os.Safari&&await hn(35);let{chapter:r,media:s,graph:l}=await(t?a(this,k).setNext(t):a(this,k).setInitial());return e&&A(this,Be,vn).call(this,r.id),this.state.isInitialChapter$.next(a(this,k).isInitialChapter()),this.state.isEndChapter$.next(a(this,k).isEndChapter()),a(this,D)&&a(this,D).handleChapterChange(l),(o=a(this,O))==null||o.setCurrentChapter(this.getCurrentChapter().chapter),a(this,V).emit(g.chapterChanged,{chapter:r,media:s,graph:l}),A(this,It,Kt).call(this,a(this,k).chapter),f(this,Lt,new Set),this.isFirstChapterFetched=!0,{chapter:r,media:s,graph:l}}toggleGraphView(t=!0){a(this,D)&&(t?(a(this,D).show(),a(this,ot).next(!1)):(a(this,D).hide(),A(this,qt,mi).call(this)),a(this,V).emit(g.graph,{type:Dt.visibility,visibility:t}))}init(){a(this,k).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===st.created&&(a(this,ht).resizeObserver.observe(this.options.fullscreenTargetElement),A(this,Xt,fi).call(this),this.appState=st.initiated,A(this,It,Kt).call(this,a(this,k).chapter))}deadEndCheck(){var n,r;return!((r=(n=a(this,F))==null?void 0:n.getPreparedToExecActions())!=null?r:[]).some(s=>s.actionType===_.setNextBranch)}allControlsAreRemoved(){return!a(this,Q).some(e=>!e.container.isRemoved)}isEndedExpectation(){var n;if(!((n=this.options)!=null&&n.player)||!a(this,Q))return!1;let t=this.options.player.info.position$.getValue(),e=this.options.player.info.duration$.getValue();return t===e&&a(this,Q).some(r=>{let s=r.container.container;return!s.isRemoved&&s.endTime===null&&yt(s.events)})}playPrevChapter(){var t;(t=a(this,U))==null||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,k).manifest){return me(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,U).getInitialVideoId(),chapterId:a(this,U).getInitialChapterId()}}getHistoryState(){return a(this,U).state}getIsSeekable(){return a(this,ot)}getInteractiveRanges(){var t;return Ki((t=a(this,k).chapter)==null?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,pt).getNextInteractiveTime(t)}getChapterBranches(t){return a(this,k).getBranches(t)}getCurrentChapter(){return a(this,k).getCurrent()}getCurrentManifest(){return a(this,k).manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,V).on(...t),this}off(...t){return a(this,V).off(...t),this}once(...t){return a(this,V).once(...t),this}destroy(){var t,e;a(this,Et).call(this),f(this,Q,void 0),this.state=void 0,(t=a(this,D))==null||t.destroy(),f(this,D,void 0),a(this,ht).release(),f(this,ht,void 0),f(this,at,void 0),a(this,K).release(),f(this,K,void 0),a(this,F).release(),f(this,F,void 0),a(this,k).release(),f(this,at,void 0),a(this,dt).release(),f(this,dt,void 0),a(this,rt).unsubscribe(),f(this,rt,void 0),a(this,V).reset(),f(this,V,void 0),(e=a(this,O))==null||e.destroy(),f(this,O,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,U).destroy(),f(this,U,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=st.destroyed}};ht=new WeakMap,Q=new WeakMap,dt=new WeakMap,U=new WeakMap,rt=new WeakMap,F=new WeakMap,K=new WeakMap,at=new WeakMap,k=new WeakMap,ot=new WeakMap,Lt=new WeakMap,D=new WeakMap,Nt=new WeakMap,O=new WeakMap,V=new WeakMap,pt=new WeakMap,Ct=new WeakMap,Ne=new WeakSet,un=function(t=!1){a(this,V).on(g.historyInited,async({initChapterId:e,videosInfo:n=[]})=>{t&&await A(this,ke,fn).call(this,{initialChapter:e,videosInfo:n})}),a(this,V).on(g.interactives,async e=>{var n,r;if(e.type===w.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)==null?void 0:n.behaviour)==="change-chapter"){let{chapterId:l}=e.payload;this.setChapter({chapterId:l})}if(((r=e.payload)==null?void 0:r.behaviour)==="change-manifest"){let{manifestURL:l}=e.payload;this.setManifest(l)}let s=e.type==="action-execution";s&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===w.containerRemoved&&a(this,Fe).call(this,e.subjectId)}),a(this,V).on(g.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},ke=new WeakSet,fn=async function({source:t,videosInfo:e=[]}){f(this,Nt,li(this));let n=document.createElement("div");a(this,Nt).on(Gt.activePlayerChanged,this.emitPlayerChanged);let{player:r,config:s}=await a(this,Nt).init({source:t,initialChapter:a(this,U).getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:r,config:s}},kt=new WeakSet,Ae=function(){var t;this.appState===st.ready&&(a(this,Et).call(this),f(this,Q,[]),a(this,K).release(),(t=a(this,F))==null||t.release(),this.appState=st.initiated,a(this,ot).next(!1),a(this,Zt).call(this))},yi=new WeakMap,je=new WeakMap,Pe=new WeakSet,mn=function(t){(!a(this,D)||a(this,D).isHidden)&&A(this,qt,mi).call(this);let e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){let s=r.range.join("-");a(this,Lt).has(s)||(a(this,Lt).add(s),a(this,V).emit(g.interactives,{type:w.rangeEnded,payload:r,visibility:!0}))}},Xt=new WeakSet,fi=function(){a(this,rt).unsubscribe(),a(this,rt).add(this.options.player.events.started$.pipe(ss()).subscribe(a(this,je))).add(this.options.player.events.playing$.subscribe(a(this,K).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,K).cancelAnimation)).add(this.options.player.info.position$.subscribe(A(this,Pe,mn).bind(this))).add(a(this,k).prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add(cs({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,c],subjects:d})=>o<s&&s<c&&d.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?f(this,Ct,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):a(this,Zt).call(this))})),this.options.lastFrame&&a(this,rt).add(this.options.player.info.duration$.subscribe(t=>{a(this,O).setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,O).setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,O).reset(),setTimeout(()=>{a(this,O).hide(),a(this,O).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,O).onSeek))},Et=new WeakMap,It=new WeakSet,Kt=function(t){a(this,k).chapter&&this.appState===st.initiated&&(a(this,at).setManifestChapterEvents(t),f(this,Q,A(this,Oe,yn).call(this,t)),a(this,F).containersEventsCallState.setData(t.containers),a(this,pt).setContainers(a(this,Q).map(e=>e.container.container).filter(e=>!Ee(e.controls))),this.options.lastFrame&&a(this,K).addFn(()=>{a(this,O).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=st.ready)},Oe=new WeakSet,yn=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)==null?void 0:e.reduce((r,s)=>{let l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Ie({player:this.options.player,container:o(s,this.rootElement),branches:a(this,k).chapter.branches,selectBranches:a(this,at),interactiveEvents:a(this,F),globalEventEmitter:a(this,V),ignoreContainerEvent:()=>Xi(s,a(this,Q)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,pt).deleteContainer(s.id)}});return a(this,K).addFn(c.whilePlaying,!0),[...r,c]}return[...r]},[]))!=null?n:[]},qt=new WeakSet,mi=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,ot).next(!1);return}let e=a(this,ot).getValue(),n=!!a(this,pt).getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,ot).next(!e)},$e=new WeakSet,gn=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Be=new WeakSet,vn=function(t){var o;if(A(this,$e,gn).call(this),!a(this,U).inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(o=n&&J(n)&&Ce(n))!=null?o:!1,s=a(this,k).manifest.metadata.initChapterId===t,l=a(this,U).state.history$.getValue();if(s||r&&e){a(this,U).updateHistory([t]);return}l.at(-1)!==t&&a(this,U).updateHistory([...l,t])},Fe=new WeakMap,Zt=new WeakMap;var hs={Container:Vt,createChoiceContainer:he,createAreaControl:re,createButtonControl:oe,createRelativeLayout:Ai,getRootEl:te,classnamesPrefix:B};var ko={version:Si};export{I as CustomError,g as EVENT_NAMES,ti as INTERACTIVE_CLICK_ACTIONS,Le as Interactives,_t as ManifestController,ko as SDKInfo,ui as chapterIdsToVKVideoIds,lt as compareVersions,es as getChapterIdByVkVideoId,an as getVKVideoIdByMedia,Jn as getVideoRawIdByMedia,Dt as graphEventTypes,Ce as hasEndTemplate,w as interactivesEventTypes,J as isLastChapter,me as isSupportedManifest,ts as isVKVariantItem,hs as utils,on as vkVideoIdsToChapterIds};
23
+ `,i}var ht,Q,dt,U,rt,D,K,at,k,ot,Lt,H,Nt,O,R,pt,Ct,je,un,Pe,fn,kt,Ne,yi,Oe,$e,mn,Xt,fi,Et,It,Kt,Be,yn,qt,mi,Fe,gn,De,vn,He,Zt,ke=class{constructor(t){y(this,je);y(this,Pe);y(this,kt);y(this,$e);y(this,Xt);y(this,It);y(this,Be);y(this,qt);y(this,Fe);y(this,De);y(this,ht,null);y(this,Q,null);y(this,dt,null);y(this,U,null);y(this,rt,null);y(this,D,null);y(this,K,null);y(this,at,null);y(this,k,null);y(this,ot,new Z(!1));y(this,Lt,new Set);y(this,H,null);y(this,Nt,null);y(this,O,null);y(this,R,null);y(this,pt,ti());y(this,Ct,null);N(this,"state",{prevChapter$:new Z(null),isInitialChapter$:new Z(!1),isEndChapter$:new Z(!1),isInteractiveExpectation$:new Z(!1),calledByInteractive$:new Z(!1),lastChapterChangeWasInitiatedByInteractive$:new Z(!1),disabledControls$:new Z(!1),interactiveRanges$:new Z([]),isInteractiveTime$:new Z(!1)});N(this,"events",{noInteraction$:new ns});N(this,"emitPlayerChanged",t=>{a(this,R).emit(g.playerChanged,t)});y(this,yi,()=>{a(this,K).fns.forEach(n=>n());let t=this.options.player.info.position$.getValue()*1e3,e=(a(this,k).chapter.containers||[]).filter(n=>n.startTime>=Math.floor(t));for(let n of e){a(this,D).remove({timestamp:1/0,priority:"container",initiator:n.id});for(let r of n.controls)a(this,D).remove({timestamp:1/0,priority:"control",initiator:r.id});a(this,Q).find(r=>r.container.container.id===n.id).reset()}});y(this,Oe,()=>{a(this,ht).calc(),a(this,K).requestAnimation()});y(this,Et,(t=!0)=>{a(this,Q).forEach(e=>{!t&&e.isPermanentText||(a(this,K).removeFn(e.whilePlaying),e.destroy())})});y(this,He,t=>{let{interactiveRanges$:e}=this.state,r=e.getValue().map(s=>({...s,subjects:s.subjects.filter(l=>l!==t)}));e.next(r)});y(this,Zt,()=>{a(this,Ct)&&(clearTimeout(a(this,Ct)),f(this,Ct,null))});var e;this.options={...pn,...t,config:{...pn.config,...t.config}},f(this,Q,[]),this.factories=new Map([["choice",he]]),this.rootElement=ls(),this.options.parentElement.append(this.rootElement),f(this,R,new Rt),f(this,rt,new rs),f(this,dt,new Ae),f(this,U,new Wt({interactiveController:this,globalEventEmitter:a(this,R),videoId:(e=this.options.projectInfo)==null?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&f(this,O,new Le({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,R).emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.SEAMLESS,n))})),a(this,dt).listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,dt).listen(this.rootElement,"mouseup",n=>n.stopPropagation()),f(this,k,new _t(this.options.loaders,n=>a(this,R).emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.MANIFEST,n)))),f(this,D,hi(this.options.player)),f(this,K,new ge),f(this,at,pi({player:this.options.player,interactiveEvents:a(this,D),globalEventEmitter:a(this,R),removeControllers:a(this,Et)})),f(this,ht,Ji(()=>{var n,r,s;return{player:(n=this.options)==null?void 0:n.player,parentElement:(r=this.options)==null?void 0:r.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,O).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&f(this,H,new Bt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,R).emit(g.graph,{type:Dt.watchAgainClicked,chapterId:n})},onError:n=>a(this,R).emit(g.errors,new I(I.Severity.RECOVERABLE,I.Category.LOADERS,{message:n}))})),L(this,je,un).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=st.created}getStatEvents(){return{click$:new dn(t=>{a(this,R).on(g.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?"OPEN_GRAPH":"CLOSE_GRAPH"),e==="watchAgainClicked"&&t.next("WATCH_AGAIN")}),a(this,R).on(g.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next("GO_NEXT_BUTTON"),r==="Area"&&t.next("GO_NEXT_AREA"))})}),nextMovie$:new dn(t=>{a(this,R).on(g.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){L(this,kt,Ne).call(this),this.options.player=t,a(this,pt).setPlayer(this.options.player),a(this,D)?a(this,D).setPlayer(this.options.player):f(this,D,hi(this.options.player)),f(this,at,pi({player:this.options.player,interactiveEvents:a(this,D),globalEventEmitter:a(this,R),removeControllers:()=>a(this,Et).call(this,!1)})),this.appState===st.initiated&&(L(this,Xt,fi).call(this),L(this,It,Kt).call(this,a(this,k).chapter))}async setManifest(t){L(this,kt,Ne).call(this),this.isFirstChapterFetched=!1;let e=await a(this,k).setManifest(t);return a(this,H)&&await a(this,H).handleManifestChange(e.manifest),await a(this,U).setManifest(e.manifest),a(this,R).emit(g.manifestChanged,{manifest:e.manifest}),L(this,It,Kt).call(this,a(this,k).chapter),e.manifest}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,H))==null||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,H))==null||e.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:e=!0}={}){var o;L(this,kt,Ne).call(this),a(this,O)&&this.isFirstChapterFetched&&(a(this,O).draw(),a(this,O).show()),as().browser===os.Safari&&await hn(35);let{chapter:r,media:s,graph:l}=await(t?a(this,k).setNext(t):a(this,k).setInitial());return e&&L(this,De,vn).call(this,r.id),this.state.isInitialChapter$.next(a(this,k).isInitialChapter()),this.state.isEndChapter$.next(a(this,k).isEndChapter()),a(this,H)&&a(this,H).handleChapterChange(l),(o=a(this,O))==null||o.setCurrentChapter(this.getCurrentChapter().chapter),a(this,R).emit(g.chapterChanged,{chapter:r,media:s,graph:l}),L(this,It,Kt).call(this,a(this,k).chapter),f(this,Lt,new Set),this.isFirstChapterFetched=!0,{chapter:r,media:s,graph:l}}toggleGraphView(t=!0){a(this,H)&&(t?(a(this,H).show(),a(this,ot).next(!1)):(a(this,H).hide(),L(this,qt,mi).call(this)),a(this,R).emit(g.graph,{type:Dt.visibility,visibility:t}))}init(){a(this,k).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===st.created&&(a(this,ht).resizeObserver.observe(this.options.fullscreenTargetElement),L(this,Xt,fi).call(this),this.appState=st.initiated,L(this,It,Kt).call(this,a(this,k).chapter))}deadEndCheck(){var n,r;return!((r=(n=a(this,D))==null?void 0:n.getPreparedToExecActions())!=null?r:[]).some(s=>s.actionType===A.setNextBranch)}allControlsAreRemoved(){return!a(this,Q).some(e=>!e.container.isRemoved)}isEndedExpectation(){var n;if(!((n=this.options)!=null&&n.player)||!a(this,Q))return!1;let t=this.options.player.info.position$.getValue(),e=this.options.player.info.duration$.getValue();return t===e&&a(this,Q).some(r=>{let s=r.container.container;return!s.isRemoved&&s.endTime===null&&yt(s.events)})}playPrevChapter(){var t;(t=a(this,U))==null||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,k).manifest){return me(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,U).getInitialVideoId(),chapterId:a(this,U).getInitialChapterId()}}getHistoryState(){return a(this,U).state}getIsSeekable(){return a(this,ot)}getInteractiveRanges(){var t;return qi((t=a(this,k).chapter)==null?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,pt).getNextInteractiveTime(t)}getChapterBranches(t){return a(this,k).getBranches(t)}getCurrentChapter(){return a(this,k).getCurrent()}getCurrentManifest(){return a(this,k).manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,R).on(...t),this}off(...t){return a(this,R).off(...t),this}once(...t){return a(this,R).once(...t),this}destroy(){var t,e;a(this,Et).call(this),f(this,Q,void 0),this.state=void 0,(t=a(this,H))==null||t.destroy(),f(this,H,void 0),a(this,ht).release(),f(this,ht,void 0),f(this,at,void 0),a(this,K).release(),f(this,K,void 0),a(this,D).release(),f(this,D,void 0),a(this,k).release(),f(this,at,void 0),a(this,dt).release(),f(this,dt,void 0),a(this,rt).unsubscribe(),f(this,rt,void 0),a(this,R).reset(),f(this,R,void 0),(e=a(this,O))==null||e.destroy(),f(this,O,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,U).destroy(),f(this,U,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=st.destroyed}};ht=new WeakMap,Q=new WeakMap,dt=new WeakMap,U=new WeakMap,rt=new WeakMap,D=new WeakMap,K=new WeakMap,at=new WeakMap,k=new WeakMap,ot=new WeakMap,Lt=new WeakMap,H=new WeakMap,Nt=new WeakMap,O=new WeakMap,R=new WeakMap,pt=new WeakMap,Ct=new WeakMap,je=new WeakSet,un=function(t=!1){a(this,R).on(g.historyInited,async({initChapterId:e,videosInfo:n=[]})=>{t&&await L(this,Pe,fn).call(this,{initialChapter:e,videosInfo:n})}),a(this,R).on(g.interactives,async e=>{var n,r;if(e.type===V.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)==null?void 0:n.behaviour)==="change-chapter"){let{chapterId:l}=e.payload;this.setChapter({chapterId:l})}if(((r=e.payload)==null?void 0:r.behaviour)==="change-manifest"){let{manifestURL:l}=e.payload;this.setManifest(l)}let s=e.type==="action-execution";s&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===V.containerRemoved&&a(this,He).call(this,e.subjectId)}),a(this,R).on(g.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Pe=new WeakSet,fn=async function({source:t,videosInfo:e=[]}){f(this,Nt,li(this));let n=document.createElement("div");a(this,Nt).on(Gt.activePlayerChanged,this.emitPlayerChanged);let{player:r,config:s}=await a(this,Nt).init({source:t,initialChapter:a(this,U).getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:r,config:s}},kt=new WeakSet,Ne=function(){var t;this.appState===st.ready&&(a(this,Et).call(this),f(this,Q,[]),a(this,K).release(),(t=a(this,D))==null||t.release(),this.appState=st.initiated,a(this,ot).next(!1),a(this,Zt).call(this))},yi=new WeakMap,Oe=new WeakMap,$e=new WeakSet,mn=function(t){(!a(this,H)||a(this,H).isHidden)&&L(this,qt,mi).call(this);let e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){let s=r.range.join("-");a(this,Lt).has(s)||(a(this,Lt).add(s),a(this,R).emit(g.interactives,{type:V.rangeEnded,payload:r,visibility:!0}))}},Xt=new WeakSet,fi=function(){a(this,rt).unsubscribe(),a(this,rt).add(this.options.player.events.started$.pipe(ss()).subscribe(a(this,Oe))).add(this.options.player.events.playing$.subscribe(a(this,K).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,K).cancelAnimation)).add(this.options.player.info.position$.subscribe(L(this,$e,mn).bind(this))).add(a(this,k).prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add(cs({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,c],subjects:d})=>o<s&&s<c&&d.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?f(this,Ct,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):a(this,Zt).call(this))})),this.options.lastFrame&&a(this,rt).add(this.options.player.info.duration$.subscribe(t=>{a(this,O).setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,O).setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,O).reset(),setTimeout(()=>{a(this,O).hide(),a(this,O).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,O).onSeek))},Et=new WeakMap,It=new WeakSet,Kt=function(t){a(this,k).chapter&&this.appState===st.initiated&&(a(this,at).setManifestChapterEvents(t),f(this,Q,L(this,Be,yn).call(this,t)),a(this,D).containersEventsCallState.setData(t.containers),a(this,pt).setContainers(a(this,Q).map(e=>e.container.container).filter(e=>!xe(e.controls))),this.options.lastFrame&&a(this,K).addFn(()=>{a(this,O).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=st.ready)},Be=new WeakSet,yn=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)==null?void 0:e.reduce((r,s)=>{let l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Te({player:this.options.player,container:o(s,this.rootElement),branches:a(this,k).chapter.branches,selectBranches:a(this,at),interactiveEvents:a(this,D),globalEventEmitter:a(this,R),ignoreContainerEvent:()=>Ki(s,a(this,Q)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,pt).deleteContainer(s.id)}});return a(this,K).addFn(c.whilePlaying,!0),[...r,c]}return[...r]},[]))!=null?n:[]},qt=new WeakSet,mi=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,ot).next(!1);return}let e=a(this,ot).getValue(),n=!!a(this,pt).getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,ot).next(!e)},Fe=new WeakSet,gn=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},De=new WeakSet,vn=function(t){var o;if(L(this,Fe,gn).call(this),!a(this,U).inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(o=n&&J(n)&&Ie(n))!=null?o:!1,s=a(this,k).manifest.metadata.initChapterId===t,l=a(this,U).state.history$.getValue();if(s||r&&e){a(this,U).updateHistory([t]);return}l.at(-1)!==t&&a(this,U).updateHistory([...l,t])},He=new WeakMap,Zt=new WeakMap;var hs={Container:Vt,createChoiceContainer:he,createAreaControl:re,createButtonControl:oe,createRelativeLayout:Mi,getRootEl:te,classnamesPrefix:F};var $o={version:Si};export{I as CustomError,g as EVENT_NAMES,ii as INTERACTIVE_CLICK_ACTIONS,ke as Interactives,_t as ManifestController,$o as SDKInfo,ui as chapterIdsToVKVideoIds,lt as compareVersions,es as getChapterIdByVkVideoId,an as getVKVideoIdByMedia,Jn as getVideoRawIdByMedia,Dt as graphEventTypes,Ie as hasEndTemplate,V as interactivesEventTypes,J as isLastChapter,me as isSupportedManifest,ts as isVKVariantItem,hs as utils,on as vkVideoIdsToChapterIds};