@vkontakte/videoplayer-interactive 1.0.13-dev.bd51f176.0 → 1.0.13-dev.ce34fb1e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es2015.cjs.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.13-dev.bd51f176.0
3
- * Fri, 05 Jul 2024 11:13:53 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.13-dev.ce34fb1e.0
3
+ * Wed, 10 Jul 2024 13:08:24 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-13/doc/
5
5
  */
6
- "use strict";var Fn=Object.create;var Ht=Object.defineProperty,Dn=Object.defineProperties,Hn=Object.getOwnPropertyDescriptor,Gn=Object.getOwnPropertyDescriptors,Un=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,zn=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty,ji=Object.prototype.propertyIsEnumerable;var Xe=(i,t,e)=>t in i?Ht(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))qe.call(t,e)&&Xe(i,e,t[e]);if(ce)for(var e of ce(t))ji.call(t,e)&&Xe(i,e,t[e]);return i},b=(i,t)=>Dn(i,Gn(t));var X=(i,t)=>{var e={};for(var n in i)qe.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&ce)for(var n of ce(i))t.indexOf(n)<0&&ji.call(i,n)&&(e[n]=i[n]);return e};var Wn=(i,t)=>{for(var e in t)Ht(i,e,{get:t[e],enumerable:!0})},Pi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Un(t))!qe.call(i,r)&&r!==e&&Ht(i,r,{get:()=>t[r],enumerable:!(n=Hn(t,r))||n.enumerable});return i};var Qn=(i,t,e)=>(e=i!=null?Fn(zn(i)):{},Pi(t||!i||!i.__esModule?Ht(e,"default",{value:i,enumerable:!0}):e,i)),Kn=i=>Pi(Ht({},"__esModule",{value:!0}),i);var $=(i,t,e)=>(Xe(i,typeof t!="symbol"?t+"":t,e),e),Ze=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Ze(i,t,"read from private field"),e?e.call(i):t.get(i)),v=(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)},m=(i,t,e,n)=>(Ze(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Oi=(i,t,e,n)=>({set _(r){m(i,t,r,e)},get _(){return a(i,t,n)}}),P=(i,t,e)=>(Ze(i,t,"access private method"),e);var V=(i,t,e)=>new Promise((n,r)=>{var s=c=>{try{o(e.next(c))}catch(h){r(h)}},l=c=>{try{o(e.throw(c))}catch(h){r(h)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,l);o((e=e.apply(i,t)).next())});var Is={};Wn(Is,{CustomError:()=>S,EVENT_NAMES:()=>y,INTERACTIVE_CLICK_ACTIONS:()=>Te,Interactives:()=>ne,ManifestController:()=>xt,SDKInfo:()=>Es,chapterIdsToVKVideoIds:()=>Le,compareVersions:()=>st,getChapterIdByVkVideoId:()=>Vn,getVKVideoIdByMedia:()=>Ii,getVideoRawIdByMedia:()=>Sn,graphEventTypes:()=>Pt,hasEndTemplate:()=>qt,interactivesEventTypes:()=>_,isLastChapter:()=>nt,isSupportedManifest:()=>Kt,isVKVariantItem:()=>wn,utils:()=>$n,vkVideoIdsToChapterIds:()=>xi});module.exports=Kn(Is);var $i="1.0.13-dev.bd51f176.0";function Ye(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 G="SDK_NAME",Xn="SDK_NAME-controls-container",le=()=>document.querySelector(`.${Xn}`),Hi=.4,q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Bi={top:"flex-start",bottom:"flex-end",center:"center"},Fi={start:"flex-start",end:"flex-end",center:"center"},Di={start:"left",end:"right",center:"center"},he=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=Bi[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:Bi.center,i.style.justifyContent=(s=Fi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Fi.center,i.style.textAlign=(o=Di[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Di.start},de=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h;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=(h=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?h:e.textContent},pe=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Ye((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)},ue=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h,C,E,I,w,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 ${Ye((h=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?h:e.borderColor,(I=(E=(C=t==null?void 0:t.shape)==null?void 0:C.border)==null?void 0:E.alpha)!=null?I:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(w=t==null?void 0:t.shape)==null?void 0:w.roundCorners)!=null?x:e.roundCorners})`},At=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Je="int",Lt={AREA:`${Je}_area`,TEXT:`${Je}_text`,BUTTON:`${Je}_bttn`};var ft=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${G}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:q.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(`.${G}-control-container-${this.control.id}`)}};var fe=i=>{if(i.type.trim().toLowerCase()==="area")return new ti(i)},ti=class extends ft{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(`${G}-${this.control.id}`),s.setAttribute("data-testid",Lt.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",pe({target:s,props:this.control.props,fallback:b(p({},q),{backgroundColor:"transparent"})}),ue({target:s,props:this.control.props,fallback:b(p({},q),{borderAlpha:0}),dependsOn:n}),At({target:s,layoutParams:this.control.layoutParams,fallback:q}),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(`.${G}-${this.control.id}`)}};var me=()=>{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 ye=i=>{if(i.type.trim().toLowerCase()==="button")return new ei(i)},ei=class extends ft{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(`${G}-${this.control.id}`),s.setAttribute("data-testid",Lt.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=me();return At({target:s,layoutParams:this.control.layoutParams,fallback:q}),pe({target:s,props:this.control.props,fallback:q}),ue({target:s,props:this.control.props,fallback:q,dependsOn:n}),he({target:s,props:this.control.props}),de({target:l,props:this.control.props,fallback:q,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(`.${G}-${this.control.id}`)}};var Gi=i=>{if(i.type.trim().toLowerCase()==="text")return new ii(i)},ii=class extends ft{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${G}-${this.control.id}`),s.setAttribute("data-testid",Lt.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=me();return At({target:s,layoutParams:this.control.layoutParams,fallback:q}),he({target:s,props:this.control.props}),de({target:l,props:this.control.props,fallback:q,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${G}-${this.control.id}`)}};var ni=class{constructor(t){this.layout=t}},Ui=i=>{if(i.type.trim().toLowerCase()==="relative")return new Gt(i)},Gt=class extends ni{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 Nt,ge,ve,zi,kt=class{constructor(t){v(this,Nt);v(this,ve);this.container=t,this.factories=new Map,P(this,Nt,ge).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),P(this,Nt,ge).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),P(this,Nt,ge).call(this)}};Nt=new WeakSet,ge=function(){this.controls=P(this,ve,zi).call(this)},ve=new WeakSet,zi=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 be=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new si(i,t)},si=class extends kt{constructor(t,e){super(t),this.rootElement=e!=null?e:le(),this.layout=new Gt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ye),this.addControlFactory("text",Gi),this.addControlFactory("area",fe)}createView(t){let e=document.createElement("div");return e.classList.add(`${G}-${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=Hi,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())==null||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${G}-${this.container.id}`)}};var O=require("@vkontakte/videoplayer-shared");var qi=require("@vkontakte/videoplayer-shared");function Ce(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Ut={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},Ct=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,zt=i=>Ct(i,Ut.Object),Ee=i=>Ct(i,Ut.String),Ie=i=>Ct(i,Ut.Array),xe=i=>Ct(i,Ut.Number),Wi=i=>Ct(i,Ut.Function);var ri=i=>xe(i)&&!isNaN(i);var Et=i=>zt(i)&&Object.keys(i).length===0,ai=i=>Ie(i)&&!i.length;var Wt=(i,t)=>Ee(i)&&(t?i.trim():i).length;var oi=window.navigator.userAgent.toLowerCase(),dr=/ipad|iphone|ipod/.test(oi),Qi=/mobi/i.test(oi),pr=oi.indexOf("android")>-1&&Qi,qn=!Qi,ur=window.safari!==void 0&&qn;var Ki="video_interactive",Xi="videoint";var Zn=250,Qt=class{constructor(t){$(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}))});$(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}});$(this,"handleManifestChange",(n,...r)=>V(this,[n,...r],function*(t,e=[]){var s;if(!xe(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)==null||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let l;try{l=yield(0,qi.loadVKLangPack)(this.lang,Ki,Xi)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:o}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new o(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:l}),this.ngEditor.on("control",({name:c,chapterId:h})=>{c==="openPreview"&&this.onOpenPreviewClick(h)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo=p({},c)})}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=Yn(t),this.resizeObserver=new ResizeObserver(Ce(this.onResize,Zn)),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 Yn(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 ci=()=>{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,h=Math.round(t.info.position$.getValue()*1e3);for(let C of i){let E=C.startTime-l;if(E<=h&&(h<=C.endTime||C.endTime===null)){c=!0;break}h<E&&(o=o===-1?E:Math.min(o,E))}return!c&&o!==-1?o:null}}};var st=(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};var Yi=require("uuid");var Jn="3.1",Zi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ts={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ji=i=>{let t=[];for(let l of i.chapters){let o,c=[];for(let e of l.branches){let n=e,{isDefault:E}=n,I=X(n,["isDefault"]);E&&(o=I.id),c.push(I)}let h=[],C=[];for(let r of l.containers){let s=r,{fallbackStrategy:E}=s,I=X(s,["fallbackStrategy"]);let w=!!I.endTime,x=[ts];switch(E){case"await":w?x=[]:h=[];break;case"default":{let R={type:"onSuspense",action:{type:Zi.default,args:{branchId:o,shouldOpenNow:!w,isDetachContainer:!0}}};w?x=[R]:h=[R];break}case"random":case"weightlessRandom":case"max":case"min":{let R={type:"onSuspense",action:{type:Zi[E],args:{}}};w?x=[R]:h=[R];break}}for(let R of I.controls)C.push(b(p({},I),{controls:[p({},R)],id:(0,Yi.v4)(),events:x}))}t.push(b(p({},l),{containers:C,events:h,branches:c}))}return i.metadata.version=Jn,i.metadata.updated=new Date().toISOString(),b(p({},i),{chapters:t})};var es="3.2",tn=i=>{if(!i.media){let t=i.metadata,{media:e}=t,n=X(t,["media"]);return b(p({},i),{metadata:b(p({},n),{version:es}),media:e})}return i};var is="3.3",ns=(i=[])=>({edit:{chapters:i},view:{}}),en={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},nn=i=>{var r;let t=[],e=[];for(let s of i.chapters){let n=s,{id:l,x:o,y:c}=n,h=X(n,["id","x","y"]),C=h.containers.map(E=>{var I;return b(p({},E),{controls:E.controls.map(j=>{var f=j,{subtype:w,type:x}=f,R=X(f,["subtype","type"]);return b(p({},R),{type:w!=null?w:x})}),events:(I=E.events)!=null&&I.length?E.events:[en]})});t.push(b(p({id:l},h),{containers:C,events:(r=h.events)!=null&&r.length?h.events:[en]})),e.push({id:l,x:o,y:c})}return b(p({},i),{chapters:t,graph:ns(e),metadata:b(p({},i.metadata),{version:is})})};var ss=[{version:"3.0",migrate:Ji},{version:"3.1",migrate:tn},{version:"3.2",migrate:nn}],li=i=>ss.reduce((t,e)=>st(t.metadata.version,e.version)?t:e.migrate(t),i);var Fr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),sn=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Dr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),k=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),Te=(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))(Te||{});var rn={metadata:"Object",chapters:"Array"},rs="3.0.0",as="3.3.0",Kt=i=>{let t=st(i,rs);return t===-1?!1:t===0?!0:st(i,as)!==1},an=i=>{if(!zt(i))return!1;for(let t in rn)if(!i[t]||!Ct(i[t],rn[t]))return!1;return Kt(i.metadata.version)},hi=i=>i.type===sn.Text;var S=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};$(S,"Severity",{RECOVERABLE:1,CRITICAL:2}),$(S,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var jt=class{constructor(){$(this,"listeners",{})}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t];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 Se=class{constructor(t){$(this,"addFn",(t,e=!1)=>{Wi(t)&&(this.fns.push(t),e&&this.updateFn())});$(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});$(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});$(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});$(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});$(this,"cancelAnimation",()=>{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=[]}};var pn=require("@vkontakte/videoplayer-shared");var we=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:[]}}exec(t,e){return V(this,null,function*(){return os(...this.loaders[t])(e)})}};function os(...i){return function(e){return V(this,null,function*(){let n=[...i];for(;n.length>0;)e=yield n.shift()(e);return e})}}function Xt(i,t,e){return i?b(p({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function Ve(r){var s=r,{actions:i,errors:t,chapterId:e}=s,n=X(s,["actions","errors","chapterId"]);if(e){let l=i.getManifest(),o=i.getChapter(l.chapters,e);if(o){let c=i.getMedia(l.media,o.videoId),h=i.getGraph(l.graph,o.id);return c?b(p({},n),{actions:i,errors:t,result:{chapter:o,media:c,graph:h}}):b(p({},n),{errors:Xt(t,Ve.name,"Could not find media"),actions:i})}}return b(p({},n),{errors:Xt(t,Ve.name,"Could not find chapter"),actions:i})}var cs=i=>V(void 0,null,function*(){try{let t,e;if(zt(i))t=i;else if(Ee(i)){e=new URL(i).href;let r=yield fetch(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!an(t))return{};let n=t.metadata.media;if(Ee(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=yield fetch(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return ds(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function on(i){return V(this,null,function*(){let{manifest:t,manifestURL:e}=yield cs(i),n=li(t);return n.media=ls(n.media,e),delete n.metadata.media,n})}function Re(i,t){return i.find(e=>e.id===t)}function di(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 pi(i,t){return i.videos.find(e=>e.id===t)}function ls(i,t){return b(p({},i),{videos:i.videos.map(e=>b(p({},e),{variants:e.variants.map(n=>{let r=hs(n.url,t);return b(p({},n),{url:r||n.url})})}))})}function hs(i,t){try{return new URL(i,t).href}catch(e){return""}}function ds(i){return st(i,"3.2.0")>=0}var D=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),ui=i=>Ie(i)&&!ai(i),nt=i=>i.order==="end",qt=i=>Ie(i.containers)&&!ai(i.containers)&&nt(i),cn=(i,t)=>{var n;let e=i*1e3;return ui(t.controls)&&e<((n=t.startTime)!=null?n:0)},fi=(i,t)=>{var n,r;let e=i*1e3;return ui(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var It=i=>i.some(t=>t.action.type==="expect"),mi=i=>i.find(t=>t.action.type==="expect"),ps=i=>(i==null?void 0:i.length)===1,_e=i=>ps(i)&&hi(i[0]);var ln=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(p(p({},n[t]),e[t])),hn=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!hi(c));if(ui(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],h=e.id;if(!n)t.push({subjects:[h],range:c});else{let C=[],E=-1/0,I=1/0,w=[],x=[];for(let R=0;R<t.length;R++){let j=t[R];if(x.push(...j.subjects),j.range[0]<I&&(I=j.range[0]),j.range[1]>E&&(E=j.range[1]),j.range[0]<=c[0]&&j.range[1]>=c[1])return t[R].subjects.push(h),t;c[0]>=j.range[0]&&c[0]<=j.range[1]&&(C.push(R),w=w.concat(j.subjects),c[0]=j.range[0]),c[1]>=j.range[0]&&c[1]<=j.range[1]&&(C.push(R),w=w.concat(j.subjects),c[1]=j.range[1])}if(x.push(h),c[0]<=I&&c[1]>=E)return[{subjects:x,range:c}];C.length&&C.reverse().forEach(R=>{t.splice(R,1)}),t.push({subjects:w.concat([h]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),dn=(i,t)=>It(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&It(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var xt=class extends we{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new pn.ValueSubject(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){return V(this,null,function*(){var r;this.release();let e=yield this.exec("manifestLoaders",{actions:{addErrorMessage:Xt},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=yield on((r=e.result)!=null?r:t);return this.manifest=n,this})}setInitial(){return V(this,null,function*(){return this.setNext()})}setNext(){return V(this,arguments,function*(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let e=yield this.exec("chapterLoaders",Ve({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:di,getChapter:Re,getMedia:pi,getByBranches:this.getByBranches.bind(this),addErrorMessage:Xt},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=Re(this.manifest.chapters,t);if(e){let n=pi(this.manifest.media,e.videoId),r=di(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=Re(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 nt(this.chapter)}};var fn=require("@vkontakte/videoplayer-core"),mn=require("@vkontakte/videoplayer-shared");var un=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 y={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Pt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},_={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function yi(){let i=new Map;function t(o){var c=o,{listId:r=Math.random().toString(),itemId:s=Math.random().toString()}=c,l=X(c,["listId","itemId"]);let h=i.get(r),C=p({},l);return h?h[s]=C:i.set(r,{[s]:C}),p({listId:r,itemId:s},l)}function e(r,s){var o,c,h;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(h=l[s])==null||h.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let C of Object.values(l))C.player.destroy(),C.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 gi(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=b(p({},e.MPEG),{[(s=c.standard)!=null?s:"Invariant quality"]:c.url}));break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG=b(p({},e.MPEG),{[(l=c.standard)!=null?l:"Invariant quality"]:c.url}));break;case"hls":(r||t.includes("hls"))&&(e=b(p({},e),{HLS:{type:"url",url:c.url}}));break;case"dash":(r||t.includes("dash"))&&(e=b(p({},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 Zt=(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 Yt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},us=2;function vi(i){let t=yi(),e,n,r=new jt,s={},l=!1,o=null,c=!1,h;i&&C(i);function C(d){o=d}function E(d,g,T){var N;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let M=((N=t.map.get(d))!=null?N:{})[g];if(M){s=p({chapterId:T,listId:d,itemId:g},M);let F=s.player;n=F.info.currentQuality$.subscribe(A=>{if(!(!A||!F.info.position$.getValue())){e=A;for(let et of t.map)Object.values(et[1]).forEach(({player:J})=>{F.info.isAutoQualityEnabled$.getValue()||Zt(J,A)})}}),M.container.remove(),l=!1,o.setPlayer(M.player),c||(o.init(),c=!0),r.emit(Yt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function I(d,g,T){return V(this,null,function*(){if(!o)throw Error("need to set interactive controller");if(Et(s)||d!==s.itemId)return;if(T>=0&&!l){let M=o.getChapterBranches();l=!0;let N=new Set;for(let F of M)N.has(F.media.id)||(yield x({media:F.media,chapterId:F.chapter.id,setAsActive:!1,title:F.chapter.label}),N.add(F.media.id))}})}function w(T){return V(this,arguments,function*({chapter:{id:d},media:g}){if(Et(s))return;n==null||n.unsubscribe();let u=s.player.info.muted$.getValue(),M=s.player.info.currentQuality$.getValue(),N=s.player.info.isAutoQualityEnabled$.getValue(),F=s.player.info.volume$.getValue(),A=s.player.info.currentPlaybackRate$.getValue(),et=!N,J=!1;for(let Q of t.map)if(Q[0]===g.id){let ut=Object.keys(Q[1]);for(let K of ut)K===s.itemId?(ut.length<us||(J=!0),t.removePlayer(Q[0],K)):(J=!0,E(Q[0],K,d),et?Zt(s.player,M):s.player.setAutoQuality(!0),s.player.setVolume(F),s.player.setMuted(u),s.player.setPlaybackRate(A))}else t.removePlayer(Q[0]);J||(yield x({media:g,chapterId:d,setAsActive:!0,playbackRate:A}),et?Zt(s.player,M):s.player.setAutoQuality(!0),s.player.setVolume(F),s.player.setMuted(u))})}function x(et){return V(this,arguments,function*({media:d,chapterId:g,prefetch:T=!0,setAsActive:u=!0,autoplay:M=!1,preferredExt:N,title:F,playbackRate:A}){var Mi,Ai,Li,Ni,ki;let J=Math.random().toString(),Q=document.createElement("div");h.append(Q);let ut=(Mi=s==null?void 0:s.player)==null?void 0:Mi.info.isAutoQualityEnabled$.getValue(),K;if((Ai=o==null?void 0:o.options)!=null&&Ai.vkVideoLoader){let oe=un(d);oe.length&&(K=yield o.options.vkVideoLoader(...oe))}let Vi=((Li=o==null?void 0:o.options)==null?void 0:Li.coreConfig)||{},Bn=b(p({},Vi),{configName:[...(Ni=Vi.configName)!=null?Ni:[],"interactive"]}),Ri=b(p({container:Q},((ki=K==null?void 0:K.videos)==null?void 0:ki[0])||{sources:gi(d,N).sources}),{title:F,failoverHosts:(K==null?void 0:K.failoverHosts)||[]}),bt=new fn.Player(Bn);bt.initVideo(Ri);let _i=new mn.Subscription;_i.add(bt.info.position$.subscribe(function(oe){I(J,bt.info.duration$.getValue(),oe)})).add(bt.events.canplay$.subscribe(function(){ut||Zt(bt,e),A&&bt.setPlaybackRate(A)}));let Mt=t.createPlayer({listId:d.id,itemId:J,player:bt,container:Q,sources:gi(d,N).sources,config:Ri,subscription:_i});return u&&E(d.id,Mt.itemId,g),M&&Mt.player.play(),T&&!M&&Mt.player.prepare(),r.emit(Yt.playerCreated,Mt.player),{player:Mt.player,config:Mt.config}})}function R(){j(),o=null}function j(){o==null||o.off(y.chapterChanged,w),t.removeAll(),s={},c=!1,l=!1}function f(g){return V(this,arguments,function*({container:d}){if(!o)throw Error("need to set interactive controller");j(),h=d;let{media:T,chapter:u}=o.getCurrentChapter();if(T){o.on(y.chapterChanged,w);let{player:M,config:N}=yield x({media:T,chapterId:u.id,title:u.label});return r.emit(Yt.initiated,{container:d,media:T,chapterId:u.id}),{player:M,config:N}}else console.error("not found")})}return b(p({},t),{on:r.on.bind(r),off:r.off.bind(r),init:f,setInteractiveController:C,createPlayer:x,removeAll:R,getActivePlayer:function(){return s}})}var yn=require("@vkontakte/videoplayer-shared");var Me=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:h,onRemove:C}){$(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==D.end&&(It(this.container.container.events)&&this.gameState===D.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==D.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})))})});$(this,"show",()=>{var t,e,n,r;if(this.gameState===D.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!0,isFirst:!1});else{let l=ln({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})),(this.gameState===D.end||this.gameState===D.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1}))},isEOV:()=>this.gameState===D.end});this.container.createView(l),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});$(this,"onEndOfVideo",()=>{this.gameState=D.end,this.selectContainerEvent(!0)});$(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[D.destroyed,D.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(cn(e,this.container.container))this.gameState!==D.beforeInteractive&&(this.gameState=D.beforeInteractive,this.onBeforeStartTime());else if(fi(e,this.container.container))this.gameState!==D.interactive&&(this.gameState=D.interactive,this.onStartTime());else if(this.gameState!==D.afterInteractive){let o=this.gameState;this.gameState=D.afterInteractive,o===D.interactive&&this.onEndTime()}else this.gameState!==D.destroyed&&!this.isPermanentText&&this.removeView();let n=fi(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(y.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 yn.Subscription,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&_e(e.container.controls),this.disabledControls$=h,this.onRemove=C,this.globalEventEmitter=l,this.gameState=D.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=It(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(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=D.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.containerRemoved,visibility:!1}),this.gameState=D.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=D.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 gn(){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 h in i)+h<=o&&(c[h]=i[h]);return c}function n(o){let c={};for(let h in i)+h>=o&&(c[h]=i[h]);return c}function r({timestamp:o,priority:c,initiator:h}){var C;if(ri(o)){let E=(C=i[o])!=null?C:null;if(E&&Wt(c,!0)){let I={},w=E[c];if(w&&(I=p(p({},I),w)),I=Et(I)?null:I,I&&Wt(h,!0)){let x=I[h];return x!=null?x:null}return I}return E}return null}function s({timestamp:o,priority:c,initiator:h}){if(ri(o))if(i[o]){if(Wt(c,!0))if(i[o][c]){if(Wt(h,!0))if(i[o][c][h]){if(delete i[o][c][h],!Et(i[o][c]))return!0}else return!1;if(delete i[o][c],!Et(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(E){var I=E,{timestamp:o,priority:c,initiator:h}=I,C=X(I,["timestamp","priority","initiator"]);var w,x,R;(x=(w=i[o])==null?void 0:w[c])!=null&&x[h]?i[o][c][h].push(p({},C)):(R=i[o])!=null&&R[c]?i[o][c]=b(p({},i[o][c]),{[h]:[p({},C)]}):i[o]?i[o]=b(p({},i[o]),{[c]:{[h]:[p({},C)]}}):i[o]={[c]:{[h]:[p({},C)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var fs=[k.expect,k.setNextBranch],ms=1/0;function bi(i){let t=i,e,n=ys(),r=new gn,s,l=()=>{I(),f()},o=d=>{r.add.call(void 0,d),x()},c=(d=[])=>{for(let g of d)if(g.action(),fs.includes(g.actionType))break},h=(d=1/0)=>{var M,N,F;let g=Ae((M=r.get({timestamp:d,priority:"control"}))!=null?M:{}),T=Ae((N=r.get({timestamp:d,priority:"container"}))!=null?N:{}),u=Ae((F=r.get({timestamp:d,priority:"chapter"}))!=null?F:{});return[...g,...T,...u]},C=d=>{n.isReady(d)&&c(h(d))},E=()=>{var d;c([...Ae((d=r.get({timestamp:1/0,priority:"chapter"}))!=null?d:{})])},I=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},w=d=>{},x=()=>{e||(e=()=>setTimeout(()=>{C(1/0)}),s=t.events.ended$.subscribe(e))},R=d=>{I(),t=d},j=d=>{d.priority==="container"&&n.resetCalled(d.timestamp),r.remove(d)},f=()=>{n.release(),r.removeAll()};return{setPlayer:R,add:o,remove:j,exec:C,execEndOfVideo:E,listen:x,unlisten:I,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function ys(){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 h of l){let C=(o=h.endTime)!=null?o:ms,E=(c=i.get(C))!=null?c:{};i.set(C,b(p({},E),{[h.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 Ae(i){return Object.values(i).flat().sort(t=>t.actionType===k.expect?-1:1)}var vn=(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,h;return o>l?(h=s,c=s*l):o<l?(h=r/l,c=r):(h=s,c=r),{videoContentWidth:h,videoContentHeight:c}};var gs=250;function bn(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:C,videoContentHeight:E}=vn(c,h);c.style.setProperty("--interactive-content-width",`${C}px`),c.style.setProperty("--interactive-content-height",`${E}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=Ce(o=>{let{fns:c=[]}=i();n(o);for(let h of c)h()},gs);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Jt=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 vs=i=>Math.floor(Math.random()*i),Cn=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 In=i=>{let t=i.length,e=vs(t);return i[e]};var xn=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 Tn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var Ci=(i,t=!1)=>b(p({},i),{args:t?p(p({},i.args),Tn):p(p({},Tn),i.args)}),Ei=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:d,controlId:g,containerId:T,branches:u=[],onEvent:M,isEOV:N=()=>!1,isDisabled:F=()=>!1})=>{let A=Ci(f,N()),et={timestamp:1/0,priority:"control",initiator:g,actionType:A.type},J=F(),Q=i.emit.bind(i,y.interactives,{subjectId:g,subjectType:d,subjectName:"control",type:J?_.actionChoiceCanceled:_.actionChoice,actionType:f.type,payload:p({containerId:T},A.args)});if(J){Q();return}switch(A.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let ut=u.find(K=>K.id===A.args.branchId);if(!ut)return;M(A.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),A.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{chapterId:ut.chapterId,autoSelect:!1}}):(e.add(b(p({},et),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{chapterId:ut.chapterId,autoSelect:!1}})})),n==null||n());return}case k.continuePlayback.trim().toLowerCase():{M(A.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),A.args.shouldOpenNow?w({subjectId:g,subjectName:"control",subjectType:d,action:f}):e.add(b(p({},et),{action:w.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:f})}));return}case k.openURI.trim().toLowerCase():{M(A.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),A.args.shouldOpenNow?j({subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{URI:f.args.uri}}):(e.add(b(p({},et),{action:j.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:d,endTime:g},branches:T=[],isEOV:u=!1,autoSelected:M=!1})=>{let N=Ci(f,u),F={timestamp:!N.args.shouldOpenNow||u?1/0:g,priority:"container",initiator:d,actionType:N.type},A=i.emit.bind(i,y.interactives,{subjectId:d,subjectName:"container",type:_.actionChoice,actionType:N.type,payload:N.args});switch(N.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let et=T.find(J=>J.id===N.args.branchId);if(!et)return;A(),e.add(b(p({},F),{action:x.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{chapterId:et.chapterId,autoSelect:M}})})),n==null||n();return}case k.setMaxWeightBranch.trim().toLowerCase():return;case k.setMinWeightBranch.trim().toLowerCase():return;case k.setRandomBranch.trim().toLowerCase():return;case k.setWeightlessRandomBranch.trim().toLowerCase():return;case k.continuePlayback.trim().toLowerCase():{A(),e.add(b(p({},F),{action:w.bind(null,{subjectId:d,subjectName:"container",action:N})}));return}case k.openURI.trim().toLowerCase():{A(),e.add(b(p({},F),{action:j.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:f,branches:d,isEOV:g=!1}){let T=mi(f.events);if(T){let u=Ci(T.action,g);i.emit(y.interactives,{subjectId:f.id,subjectName:"container",type:_.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:g?1/0:f.endTime,priority:"container",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of f.events)o({action:u.action,container:f,branches:d,isEOV:g})}let h=({chapterId:f,action:d,branches:g=[]})=>{let T=i.emit.bind(i,y.interactives,{subjectId:f,subjectName:"chapter",type:_.actionChoice,actionType:d.type,payload:d.args});switch(d.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let u=g.find(M=>M.id===d.args.branchId);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setWeightlessRandomBranch.trim().toLowerCase():{let u=In(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setRandomBranch.trim().toLowerCase():{let u=xn(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMaxWeightBranch.trim().toLowerCase():{let u=En(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMinWeightBranch.trim().toLowerCase():{let u=Cn(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.continuePlayback.trim().toLowerCase():return T(),w.bind(null,{subjectId:f,subjectName:"chapter",action:d});case k.openURI.trim().toLowerCase():return T(),j.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{URI:d.args.uri}});default:console.error("Unexpected chapter event"),i.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function C(f){let d=mi(f.events);if(d){if(nt(f))return;i.emit(y.interactives,{subjectId:f.id,subjectName:"chapter",type:_.actionChoice,actionType:d.action.type,payload:d.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(g=>{let T=h({chapterId:f.id,action:g.action,branches:f.branches});T&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:g.action.type,action:T})})}let E=({subjectId:f,subjectName:d,action:g})=>{var T;t.pause(),i.emit(y.interactives,{subjectId:f,subjectName:d,type:_.actionExecution,actionType:(T=g==null?void 0:g.type)!=null?T:k.expect})},I=({subjectId:f,subjectName:d})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(y.interactives,{subjectId:f,subjectName:d,type:_.actionExecution,actionType:"after-expect"})},w=({subjectId:f,subjectName:d,subjectType:g,action:T})=>{i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type})},x=({subjectId:f,subjectName:d,subjectType:g,action:T,payload:u})=>{u.behaviour="change-chapter",i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type,payload:u})},R=({subjectId:f,subjectName:d,subjectType:g,action:T,payload:u})=>{u.behaviour="change-manifest",i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type,payload:u})},j=({subjectId:f,subjectName:d,subjectType:g,action:T,payload:u})=>{if(!u.URI)return;let M=window.open(u.URI,"_blank","noopener,noreferrer");M&&(M.opener=null),i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:h,onExpectEvent:E,expectEventHandler:I,setManifestChapterEvents:C,setManifestContainerEvents:c,stopExpect:s,state:r}};var mt=require("@vkontakte/videoplayer-shared");var Le=(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]=Ii(s)}return e[n]}).filter(Boolean)},Sn=i=>{for(let t of i.variants)if(wn(t)&&"payload"in t)return t.payload.id},wn=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Ii=i=>{let t=Sn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Vn=(i,t)=>{for(let e of i.media.videos)if(t===Ii(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},xi=(i,t)=>i.reduce((e,n)=>{let r=Vn(t,n);return r?[...e,r]:e},[]);var rt,Tt,St,tt,Ne,at,ot,it,wt,Ot,$t,te=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new mt.ValueSubject([]),hasPrevChapter$:new mt.ValueSubject(!1),prevChapter$:new mt.ValueSubject(null),isInitialChapter$:new mt.ValueSubject(!1),isGoBackLimited$:new mt.ValueSubject(!1)};v(this,rt,null);v(this,Tt,void 0);v(this,St,!1);v(this,tt,null);v(this,Ne,null);v(this,at,null);v(this,ot,null);v(this,it,null);v(this,wt,new mt.Subscription);v(this,Ot,!1);v(this,$t,0);var l,o,c;m(this,at,e),m(this,it,t),m(this,ot,n),m(this,rt,r),m(this,Tt,s),(l=this.state)!=null&&l.history$&&a(this,wt)&&((c=a(this,wt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(h=>{var C,E,I,w,x,R;(C=this.state)==null||C.prevChapter$.next(h.at(-2)||null),(E=this.state)==null||E.hasPrevChapter$.next(h.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((w=(I=a(this,tt))==null?void 0:I.metadata)==null?void 0:w.initChapterId)),(R=this.state)==null||R.isGoBackLimited$.next(a(this,$t)===a(this,Tt).maxLength-1)})))}setManifest(t){return V(this,null,function*(){!a(this,ot)||!a(this,it)||(m(this,tt,t),yield this.getProjectHistory(),yield a(this,ot).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,St)||(m(this,St,!0),a(this,it).emit(y.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,St)}updateHistory(t,e=!0){return V(this,null,function*(){var o,c;if(!a(this,tt))return;a(this,Ot)?(m(this,Ot,!1),Oi(this,$t)._++):m(this,$t,0);let n=a(this,tt),r=t.length-a(this,Tt).maxLength,s=r>0?t.slice(r):t,l=Le(s,n);if(m(this,Ne,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,rt)||!a(this,at)))try{yield a(this,rt).save(a(this,at),l)}catch(h){(c=a(this,it))==null||c.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}})}goBack(){return V(this,null,function*(){var n;if(!this.state||!a(this,ot))return(n=a(this,it))==null?void 0:n.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));m(this,Ot,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),yield a(this,ot).setChapter({chapterId:e})})}getProjectHistory(){return V(this,null,function*(){var r,s;if(!a(this,tt)||!a(this,at))return;let t=a(this,tt),e=[this.getInitialVideoId()];if(a(this,rt))try{let l=yield a(this,rt).get(a(this,at));l.length&&(e=l)}catch(l){(r=a(this,it))==null||r.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}let n=xi(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,Tt).initChapterId||((n=a(this,tt))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,tt)){let t=this.getInitialChapterId();return Le([t],a(this,tt)).pop()}return null}destroy(){var t,e;this.state=null,m(this,at,null),m(this,rt,null),m(this,ot,null),(t=a(this,wt))==null||t.unsubscribe(),m(this,wt,null),m(this,St,!1),(e=a(this,it))==null||e.emit(y.historyDestroyed),m(this,it,null)}};rt=new WeakMap,Tt=new WeakMap,St=new WeakMap,tt=new WeakMap,Ne=new WeakMap,at=new WeakMap,ot=new WeakMap,it=new WeakMap,wt=new WeakMap,Ot=new WeakMap,$t=new WeakMap;var je,Rn,ee,Pe,_n,ct=class ct{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=P(s=ct,je,Rn).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}};je=new WeakSet,Rn=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(",")),P(n=ct,Pe,_n).call(n,t)?e:e.capture||!1}},ee=new WeakMap,Pe=new WeakSet,_n=function(t){let e=a(ct,ee);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}m(ct,ee,e)}return e||!1},v(ct,je),v(ct,Pe),v(ct,ee,void 0);var ke=ct;var Oe=class{constructor(){this.bindingMap=new Jt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new ke(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))}updateCanvasDimensions(t,e=!1){return V(this,null,function*(){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=yield this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n})}save(){return V(this,null,function*(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,yield 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 Be=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
+ "use strict";var Fn=Object.create;var Ht=Object.defineProperty,Dn=Object.defineProperties,Hn=Object.getOwnPropertyDescriptor,Gn=Object.getOwnPropertyDescriptors,Un=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,zn=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty,ji=Object.prototype.propertyIsEnumerable;var Xe=(i,t,e)=>t in i?Ht(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))qe.call(t,e)&&Xe(i,e,t[e]);if(ce)for(var e of ce(t))ji.call(t,e)&&Xe(i,e,t[e]);return i},b=(i,t)=>Dn(i,Gn(t));var X=(i,t)=>{var e={};for(var n in i)qe.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&ce)for(var n of ce(i))t.indexOf(n)<0&&ji.call(i,n)&&(e[n]=i[n]);return e};var Wn=(i,t)=>{for(var e in t)Ht(i,e,{get:t[e],enumerable:!0})},Pi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Un(t))!qe.call(i,r)&&r!==e&&Ht(i,r,{get:()=>t[r],enumerable:!(n=Hn(t,r))||n.enumerable});return i};var Qn=(i,t,e)=>(e=i!=null?Fn(zn(i)):{},Pi(t||!i||!i.__esModule?Ht(e,"default",{value:i,enumerable:!0}):e,i)),Kn=i=>Pi(Ht({},"__esModule",{value:!0}),i);var $=(i,t,e)=>(Xe(i,typeof t!="symbol"?t+"":t,e),e),Ze=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Ze(i,t,"read from private field"),e?e.call(i):t.get(i)),v=(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)},m=(i,t,e,n)=>(Ze(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Oi=(i,t,e,n)=>({set _(r){m(i,t,r,e)},get _(){return a(i,t,n)}}),P=(i,t,e)=>(Ze(i,t,"access private method"),e);var V=(i,t,e)=>new Promise((n,r)=>{var s=c=>{try{o(e.next(c))}catch(h){r(h)}},l=c=>{try{o(e.throw(c))}catch(h){r(h)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,l);o((e=e.apply(i,t)).next())});var Is={};Wn(Is,{CustomError:()=>S,EVENT_NAMES:()=>y,INTERACTIVE_CLICK_ACTIONS:()=>Te,Interactives:()=>ne,ManifestController:()=>xt,SDKInfo:()=>Es,chapterIdsToVKVideoIds:()=>Le,compareVersions:()=>st,getChapterIdByVkVideoId:()=>Vn,getVKVideoIdByMedia:()=>Ii,getVideoRawIdByMedia:()=>Sn,graphEventTypes:()=>Pt,hasEndTemplate:()=>qt,interactivesEventTypes:()=>_,isLastChapter:()=>nt,isSupportedManifest:()=>Kt,isVKVariantItem:()=>wn,utils:()=>$n,vkVideoIdsToChapterIds:()=>xi});module.exports=Kn(Is);var $i="1.0.13-dev.ce34fb1e.0";function Ye(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 G="SDK_NAME",Xn="SDK_NAME-controls-container",le=()=>document.querySelector(`.${Xn}`),Hi=.4,q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Bi={top:"flex-start",bottom:"flex-end",center:"center"},Fi={start:"flex-start",end:"flex-end",center:"center"},Di={start:"left",end:"right",center:"center"},he=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=Bi[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:Bi.center,i.style.justifyContent=(s=Fi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Fi.center,i.style.textAlign=(o=Di[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Di.start},de=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h;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=(h=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?h:e.textContent},pe=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Ye((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)},ue=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h,C,E,I,w,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 ${Ye((h=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?h:e.borderColor,(I=(E=(C=t==null?void 0:t.shape)==null?void 0:C.border)==null?void 0:E.alpha)!=null?I:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(w=t==null?void 0:t.shape)==null?void 0:w.roundCorners)!=null?x:e.roundCorners})`},At=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Je="int",Lt={AREA:`${Je}_area`,TEXT:`${Je}_text`,BUTTON:`${Je}_bttn`};var ft=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${G}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:q.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(`.${G}-control-container-${this.control.id}`)}};var fe=i=>{if(i.type.trim().toLowerCase()==="area")return new ti(i)},ti=class extends ft{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(`${G}-${this.control.id}`),s.setAttribute("data-testid",Lt.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",pe({target:s,props:this.control.props,fallback:b(p({},q),{backgroundColor:"transparent"})}),ue({target:s,props:this.control.props,fallback:b(p({},q),{borderAlpha:0}),dependsOn:n}),At({target:s,layoutParams:this.control.layoutParams,fallback:q}),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(`.${G}-${this.control.id}`)}};var me=()=>{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 ye=i=>{if(i.type.trim().toLowerCase()==="button")return new ei(i)},ei=class extends ft{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(`${G}-${this.control.id}`),s.setAttribute("data-testid",Lt.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=me();return At({target:s,layoutParams:this.control.layoutParams,fallback:q}),pe({target:s,props:this.control.props,fallback:q}),ue({target:s,props:this.control.props,fallback:q,dependsOn:n}),he({target:s,props:this.control.props}),de({target:l,props:this.control.props,fallback:q,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(`.${G}-${this.control.id}`)}};var Gi=i=>{if(i.type.trim().toLowerCase()==="text")return new ii(i)},ii=class extends ft{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${G}-${this.control.id}`),s.setAttribute("data-testid",Lt.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=me();return At({target:s,layoutParams:this.control.layoutParams,fallback:q}),he({target:s,props:this.control.props}),de({target:l,props:this.control.props,fallback:q,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${G}-${this.control.id}`)}};var ni=class{constructor(t){this.layout=t}},Ui=i=>{if(i.type.trim().toLowerCase()==="relative")return new Gt(i)},Gt=class extends ni{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 Nt,ge,ve,zi,kt=class{constructor(t){v(this,Nt);v(this,ve);this.container=t,this.factories=new Map,P(this,Nt,ge).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),P(this,Nt,ge).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),P(this,Nt,ge).call(this)}};Nt=new WeakSet,ge=function(){this.controls=P(this,ve,zi).call(this)},ve=new WeakSet,zi=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 be=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new si(i,t)},si=class extends kt{constructor(t,e){super(t),this.rootElement=e!=null?e:le(),this.layout=new Gt(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",ye),this.addControlFactory("text",Gi),this.addControlFactory("area",fe)}createView(t){let e=document.createElement("div");return e.classList.add(`${G}-${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=Hi,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())==null||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${G}-${this.container.id}`)}};var O=require("@vkontakte/videoplayer-shared");var qi=require("@vkontakte/videoplayer-shared");function Ce(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Ut={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},Ct=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,zt=i=>Ct(i,Ut.Object),Ee=i=>Ct(i,Ut.String),Ie=i=>Ct(i,Ut.Array),xe=i=>Ct(i,Ut.Number),Wi=i=>Ct(i,Ut.Function);var ri=i=>xe(i)&&!isNaN(i);var Et=i=>zt(i)&&Object.keys(i).length===0,ai=i=>Ie(i)&&!i.length;var Wt=(i,t)=>Ee(i)&&(t?i.trim():i).length;var oi=window.navigator.userAgent.toLowerCase(),dr=/ipad|iphone|ipod/.test(oi),Qi=/mobi/i.test(oi),pr=oi.indexOf("android")>-1&&Qi,qn=!Qi,ur=window.safari!==void 0&&qn;var Ki="video_interactive",Xi="videoint";var Zn=250,Qt=class{constructor(t){$(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}))});$(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}});$(this,"handleManifestChange",(n,...r)=>V(this,[n,...r],function*(t,e=[]){var s;if(!xe(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)==null||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let l;try{l=yield(0,qi.loadVKLangPack)(this.lang,Ki,Xi)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:o}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new o(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:l}),this.ngEditor.on("control",({name:c,chapterId:h})=>{c==="openPreview"&&this.onOpenPreviewClick(h)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo=p({},c)})}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=Yn(t),this.resizeObserver=new ResizeObserver(Ce(this.onResize,Zn)),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 Yn(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 ci=()=>{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,h=Math.round(t.info.position$.getValue()*1e3);for(let C of i){let E=C.startTime-l;if(E<=h&&(h<=C.endTime||C.endTime===null)){c=!0;break}h<E&&(o=o===-1?E:Math.min(o,E))}return!c&&o!==-1?o:null}}};var st=(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};var Yi=require("uuid");var Jn="3.1",Zi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ts={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ji=i=>{let t=[];for(let l of i.chapters){let o,c=[];for(let e of l.branches){let n=e,{isDefault:E}=n,I=X(n,["isDefault"]);E&&(o=I.id),c.push(I)}let h=[],C=[];for(let r of l.containers){let s=r,{fallbackStrategy:E}=s,I=X(s,["fallbackStrategy"]);let w=!!I.endTime,x=[ts];switch(E){case"await":w?x=[]:h=[];break;case"default":{let R={type:"onSuspense",action:{type:Zi.default,args:{branchId:o,shouldOpenNow:!w,isDetachContainer:!0}}};w?x=[R]:h=[R];break}case"random":case"weightlessRandom":case"max":case"min":{let R={type:"onSuspense",action:{type:Zi[E],args:{}}};w?x=[R]:h=[R];break}}for(let R of I.controls)C.push(b(p({},I),{controls:[p({},R)],id:(0,Yi.v4)(),events:x}))}t.push(b(p({},l),{containers:C,events:h,branches:c}))}return i.metadata.version=Jn,i.metadata.updated=new Date().toISOString(),b(p({},i),{chapters:t})};var es="3.2",tn=i=>{if(!i.media){let t=i.metadata,{media:e}=t,n=X(t,["media"]);return b(p({},i),{metadata:b(p({},n),{version:es}),media:e})}return i};var is="3.3",ns=(i=[])=>({edit:{chapters:i},view:{}}),en={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},nn=i=>{var r;let t=[],e=[];for(let s of i.chapters){let n=s,{id:l,x:o,y:c}=n,h=X(n,["id","x","y"]),C=h.containers.map(E=>{var I;return b(p({},E),{controls:E.controls.map(j=>{var f=j,{subtype:w,type:x}=f,R=X(f,["subtype","type"]);return b(p({},R),{type:w!=null?w:x})}),events:(I=E.events)!=null&&I.length?E.events:[en]})});t.push(b(p({id:l},h),{containers:C,events:(r=h.events)!=null&&r.length?h.events:[en]})),e.push({id:l,x:o,y:c})}return b(p({},i),{chapters:t,graph:ns(e),metadata:b(p({},i.metadata),{version:is})})};var ss=[{version:"3.0",migrate:Ji},{version:"3.1",migrate:tn},{version:"3.2",migrate:nn}],li=i=>ss.reduce((t,e)=>st(t.metadata.version,e.version)?t:e.migrate(t),i);var Fr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),sn=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Dr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),k=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),Te=(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))(Te||{});var rn={metadata:"Object",chapters:"Array"},rs="3.0.0",as="3.3.0",Kt=i=>{let t=st(i,rs);return t===-1?!1:t===0?!0:st(i,as)!==1},an=i=>{if(!zt(i))return!1;for(let t in rn)if(!i[t]||!Ct(i[t],rn[t]))return!1;return Kt(i.metadata.version)},hi=i=>i.type===sn.Text;var S=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};$(S,"Severity",{RECOVERABLE:1,CRITICAL:2}),$(S,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var jt=class{constructor(){$(this,"listeners",{})}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t];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 Se=class{constructor(t){$(this,"addFn",(t,e=!1)=>{Wi(t)&&(this.fns.push(t),e&&this.updateFn())});$(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});$(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});$(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});$(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});$(this,"cancelAnimation",()=>{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=[]}};var pn=require("@vkontakte/videoplayer-shared");var we=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:[]}}exec(t,e){return V(this,null,function*(){return os(...this.loaders[t])(e)})}};function os(...i){return function(e){return V(this,null,function*(){let n=[...i];for(;n.length>0;)e=yield n.shift()(e);return e})}}function Xt(i,t,e){return i?b(p({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function Ve(r){var s=r,{actions:i,errors:t,chapterId:e}=s,n=X(s,["actions","errors","chapterId"]);if(e){let l=i.getManifest(),o=i.getChapter(l.chapters,e);if(o){let c=i.getMedia(l.media,o.videoId),h=i.getGraph(l.graph,o.id);return c?b(p({},n),{actions:i,errors:t,result:{chapter:o,media:c,graph:h}}):b(p({},n),{errors:Xt(t,Ve.name,"Could not find media"),actions:i})}}return b(p({},n),{errors:Xt(t,Ve.name,"Could not find chapter"),actions:i})}var cs=i=>V(void 0,null,function*(){try{let t,e;if(zt(i))t=i;else if(Ee(i)){e=new URL(i).href;let r=yield fetch(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!an(t))return{};let n=t.metadata.media;if(Ee(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=yield fetch(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return ds(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function on(i){return V(this,null,function*(){let{manifest:t,manifestURL:e}=yield cs(i),n=li(t);return n.media=ls(n.media,e),delete n.metadata.media,n})}function Re(i,t){return i.find(e=>e.id===t)}function di(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 pi(i,t){return i.videos.find(e=>e.id===t)}function ls(i,t){return b(p({},i),{videos:i.videos.map(e=>b(p({},e),{variants:e.variants.map(n=>{let r=hs(n.url,t);return b(p({},n),{url:r||n.url})})}))})}function hs(i,t){try{return new URL(i,t).href}catch(e){return""}}function ds(i){return st(i,"3.2.0")>=0}var D=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),ui=i=>Ie(i)&&!ai(i),nt=i=>i.order==="end",qt=i=>Ie(i.containers)&&!ai(i.containers)&&nt(i),cn=(i,t)=>{var n;let e=i*1e3;return ui(t.controls)&&e<((n=t.startTime)!=null?n:0)},fi=(i,t)=>{var n,r;let e=i*1e3;return ui(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var It=i=>i.some(t=>t.action.type==="expect"),mi=i=>i.find(t=>t.action.type==="expect"),ps=i=>(i==null?void 0:i.length)===1,_e=i=>ps(i)&&hi(i[0]);var ln=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(p(p({},n[t]),e[t])),hn=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!hi(c));if(ui(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],h=e.id;if(!n)t.push({subjects:[h],range:c});else{let C=[],E=-1/0,I=1/0,w=[],x=[];for(let R=0;R<t.length;R++){let j=t[R];if(x.push(...j.subjects),j.range[0]<I&&(I=j.range[0]),j.range[1]>E&&(E=j.range[1]),j.range[0]<=c[0]&&j.range[1]>=c[1])return t[R].subjects.push(h),t;c[0]>=j.range[0]&&c[0]<=j.range[1]&&(C.push(R),w=w.concat(j.subjects),c[0]=j.range[0]),c[1]>=j.range[0]&&c[1]<=j.range[1]&&(C.push(R),w=w.concat(j.subjects),c[1]=j.range[1])}if(x.push(h),c[0]<=I&&c[1]>=E)return[{subjects:x,range:c}];C.length&&C.reverse().forEach(R=>{t.splice(R,1)}),t.push({subjects:w.concat([h]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),dn=(i,t)=>It(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&It(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var xt=class extends we{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new pn.ValueSubject(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){return V(this,null,function*(){var r;this.release();let e=yield this.exec("manifestLoaders",{actions:{addErrorMessage:Xt},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=yield on((r=e.result)!=null?r:t);return this.manifest=n,this})}setInitial(){return V(this,null,function*(){return this.setNext()})}setNext(){return V(this,arguments,function*(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let e=yield this.exec("chapterLoaders",Ve({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:di,getChapter:Re,getMedia:pi,getByBranches:this.getByBranches.bind(this),addErrorMessage:Xt},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=Re(this.manifest.chapters,t);if(e){let n=pi(this.manifest.media,e.videoId),r=di(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=Re(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 nt(this.chapter)}};var fn=require("@vkontakte/videoplayer-core"),mn=require("@vkontakte/videoplayer-shared");var un=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 y={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Pt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},_={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function yi(){let i=new Map;function t(o){var c=o,{listId:r=Math.random().toString(),itemId:s=Math.random().toString()}=c,l=X(c,["listId","itemId"]);let h=i.get(r),C=p({},l);return h?h[s]=C:i.set(r,{[s]:C}),p({listId:r,itemId:s},l)}function e(r,s){var o,c,h;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(h=l[s])==null||h.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let C of Object.values(l))C.player.destroy(),C.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 gi(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=b(p({},e.MPEG),{[(s=c.standard)!=null?s:"Invariant quality"]:c.url}));break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG=b(p({},e.MPEG),{[(l=c.standard)!=null?l:"Invariant quality"]:c.url}));break;case"hls":(r||t.includes("hls"))&&(e=b(p({},e),{HLS:{type:"url",url:c.url}}));break;case"dash":(r||t.includes("dash"))&&(e=b(p({},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 Zt=(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 Yt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},us=2;function vi(i){let t=yi(),e,n,r=new jt,s={},l=!1,o=null,c=!1,h;i&&C(i);function C(d){o=d}function E(d,g,T){var N;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let M=((N=t.map.get(d))!=null?N:{})[g];if(M){s=p({chapterId:T,listId:d,itemId:g},M);let F=s.player;n=F.info.currentQuality$.subscribe(A=>{if(!(!A||!F.info.position$.getValue())){e=A;for(let et of t.map)Object.values(et[1]).forEach(({player:J})=>{F.info.isAutoQualityEnabled$.getValue()||Zt(J,A)})}}),M.container.remove(),l=!1,o.setPlayer(M.player),c||(o.init(),c=!0),r.emit(Yt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function I(d,g,T){return V(this,null,function*(){if(!o)throw Error("need to set interactive controller");if(Et(s)||d!==s.itemId)return;if(T>=0&&!l){let M=o.getChapterBranches();l=!0;let N=new Set;for(let F of M)N.has(F.media.id)||(yield x({media:F.media,chapterId:F.chapter.id,setAsActive:!1,title:F.chapter.label}),N.add(F.media.id))}})}function w(T){return V(this,arguments,function*({chapter:{id:d},media:g}){if(Et(s))return;n==null||n.unsubscribe();let u=s.player.info.muted$.getValue(),M=s.player.info.currentQuality$.getValue(),N=s.player.info.isAutoQualityEnabled$.getValue(),F=s.player.info.volume$.getValue(),A=s.player.info.currentPlaybackRate$.getValue(),et=!N,J=!1;for(let Q of t.map)if(Q[0]===g.id){let ut=Object.keys(Q[1]);for(let K of ut)K===s.itemId?(ut.length<us||(J=!0),t.removePlayer(Q[0],K)):(J=!0,E(Q[0],K,d),et?Zt(s.player,M):s.player.setAutoQuality(!0),s.player.setVolume(F),s.player.setMuted(u),s.player.setPlaybackRate(A))}else t.removePlayer(Q[0]);J||(yield x({media:g,chapterId:d,setAsActive:!0,playbackRate:A}),et?Zt(s.player,M):s.player.setAutoQuality(!0),s.player.setVolume(F),s.player.setMuted(u))})}function x(et){return V(this,arguments,function*({media:d,chapterId:g,prefetch:T=!0,setAsActive:u=!0,autoplay:M=!1,preferredExt:N,title:F,playbackRate:A}){var Mi,Ai,Li,Ni,ki;let J=Math.random().toString(),Q=document.createElement("div");h.append(Q);let ut=(Mi=s==null?void 0:s.player)==null?void 0:Mi.info.isAutoQualityEnabled$.getValue(),K;if((Ai=o==null?void 0:o.options)!=null&&Ai.vkVideoLoader){let oe=un(d);oe.length&&(K=yield o.options.vkVideoLoader(...oe))}let Vi=((Li=o==null?void 0:o.options)==null?void 0:Li.coreConfig)||{},Bn=b(p({},Vi),{configName:[...(Ni=Vi.configName)!=null?Ni:[],"interactive"]}),Ri=b(p({container:Q},((ki=K==null?void 0:K.videos)==null?void 0:ki[0])||{sources:gi(d,N).sources}),{title:F,failoverHosts:(K==null?void 0:K.failoverHosts)||[]}),bt=new fn.Player(Bn);bt.initVideo(Ri);let _i=new mn.Subscription;_i.add(bt.info.position$.subscribe(function(oe){I(J,bt.info.duration$.getValue(),oe)})).add(bt.events.canplay$.subscribe(function(){ut||Zt(bt,e),A&&bt.setPlaybackRate(A)}));let Mt=t.createPlayer({listId:d.id,itemId:J,player:bt,container:Q,sources:gi(d,N).sources,config:Ri,subscription:_i});return u&&E(d.id,Mt.itemId,g),M&&Mt.player.play(),T&&!M&&Mt.player.prepare(),r.emit(Yt.playerCreated,Mt.player),{player:Mt.player,config:Mt.config}})}function R(){j(),o=null}function j(){o==null||o.off(y.chapterChanged,w),t.removeAll(),s={},c=!1,l=!1}function f(g){return V(this,arguments,function*({container:d}){if(!o)throw Error("need to set interactive controller");j(),h=d;let{media:T,chapter:u}=o.getCurrentChapter();if(T){o.on(y.chapterChanged,w);let{player:M,config:N}=yield x({media:T,chapterId:u.id,title:u.label});return r.emit(Yt.initiated,{container:d,media:T,chapterId:u.id}),{player:M,config:N}}else console.error("not found")})}return b(p({},t),{on:r.on.bind(r),off:r.off.bind(r),init:f,setInteractiveController:C,createPlayer:x,removeAll:R,getActivePlayer:function(){return s}})}var yn=require("@vkontakte/videoplayer-shared");var Me=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:h,onRemove:C}){$(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==D.end&&(It(this.container.container.events)&&this.gameState===D.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==D.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})))})});$(this,"show",()=>{var t,e,n,r;if(this.gameState===D.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!0,isFirst:!1});else{let l=ln({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})),(this.gameState===D.end||this.gameState===D.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1}))},isEOV:()=>this.gameState===D.end});this.container.createView(l),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});$(this,"onEndOfVideo",()=>{this.gameState=D.end,this.selectContainerEvent(!0)});$(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[D.destroyed,D.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(cn(e,this.container.container))this.gameState!==D.beforeInteractive&&(this.gameState=D.beforeInteractive,this.onBeforeStartTime());else if(fi(e,this.container.container))this.gameState!==D.interactive&&(this.gameState=D.interactive,this.onStartTime());else if(this.gameState!==D.afterInteractive){let o=this.gameState;this.gameState=D.afterInteractive,o===D.interactive&&this.onEndTime()}else this.gameState!==D.destroyed&&!this.isPermanentText&&this.removeView();let n=fi(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(y.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 yn.Subscription,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&_e(e.container.controls),this.disabledControls$=h,this.onRemove=C,this.globalEventEmitter=l,this.gameState=D.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=It(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(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=D.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:_.containerRemoved,visibility:!1}),this.gameState=D.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=D.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 gn(){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 h in i)+h<=o&&(c[h]=i[h]);return c}function n(o){let c={};for(let h in i)+h>=o&&(c[h]=i[h]);return c}function r({timestamp:o,priority:c,initiator:h}){var C;if(ri(o)){let E=(C=i[o])!=null?C:null;if(E&&Wt(c,!0)){let I={},w=E[c];if(w&&(I=p(p({},I),w)),I=Et(I)?null:I,I&&Wt(h,!0)){let x=I[h];return x!=null?x:null}return I}return E}return null}function s({timestamp:o,priority:c,initiator:h}){if(ri(o))if(i[o]){if(Wt(c,!0))if(i[o][c]){if(Wt(h,!0))if(i[o][c][h]){if(delete i[o][c][h],!Et(i[o][c]))return!0}else return!1;if(delete i[o][c],!Et(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(E){var I=E,{timestamp:o,priority:c,initiator:h}=I,C=X(I,["timestamp","priority","initiator"]);var w,x,R;(x=(w=i[o])==null?void 0:w[c])!=null&&x[h]?i[o][c][h].push(p({},C)):(R=i[o])!=null&&R[c]?i[o][c]=b(p({},i[o][c]),{[h]:[p({},C)]}):i[o]?i[o]=b(p({},i[o]),{[c]:{[h]:[p({},C)]}}):i[o]={[c]:{[h]:[p({},C)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var fs=[k.expect,k.setNextBranch],ms=1/0;function bi(i){let t=i,e,n=ys(),r=new gn,s,l=()=>{I(),f()},o=d=>{r.add.call(void 0,d),x()},c=(d=[])=>{for(let g of d)if(g.action(),fs.includes(g.actionType))break},h=(d=1/0)=>{var M,N,F;let g=Ae((M=r.get({timestamp:d,priority:"control"}))!=null?M:{}),T=Ae((N=r.get({timestamp:d,priority:"container"}))!=null?N:{}),u=Ae((F=r.get({timestamp:d,priority:"chapter"}))!=null?F:{});return[...g,...T,...u]},C=d=>{n.isReady(d)&&c(h(d))},E=()=>{var d;c([...Ae((d=r.get({timestamp:1/0,priority:"chapter"}))!=null?d:{})])},I=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},w=d=>{},x=()=>{e||(e=()=>setTimeout(()=>{C(1/0)}),s=t.events.ended$.subscribe(e))},R=d=>{I(),t=d},j=d=>{d.priority==="container"&&n.resetCalled(d.timestamp),r.remove(d)},f=()=>{n.release(),r.removeAll()};return{setPlayer:R,add:o,remove:j,exec:C,execEndOfVideo:E,listen:x,unlisten:I,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function ys(){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 h of l){let C=(o=h.endTime)!=null?o:ms,E=(c=i.get(C))!=null?c:{};i.set(C,b(p({},E),{[h.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 Ae(i){return Object.values(i).flat().sort(t=>t.actionType===k.expect?-1:1)}var vn=(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,h;return o>l?(h=s,c=s*l):o<l?(h=r/l,c=r):(h=s,c=r),{videoContentWidth:h,videoContentHeight:c}};var gs=250;function bn(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:C,videoContentHeight:E}=vn(c,h);c.style.setProperty("--interactive-content-width",`${C}px`),c.style.setProperty("--interactive-content-height",`${E}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=Ce(o=>{let{fns:c=[]}=i();n(o);for(let h of c)h()},gs);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Jt=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 vs=i=>Math.floor(Math.random()*i),Cn=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 In=i=>{let t=i.length,e=vs(t);return i[e]};var xn=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 Tn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var Ci=(i,t=!1)=>b(p({},i),{args:t?p(p({},i.args),Tn):p(p({},Tn),i.args)}),Ei=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:d,controlId:g,containerId:T,branches:u=[],onEvent:M,isEOV:N=()=>!1,isDisabled:F=()=>!1})=>{let A=Ci(f,N()),et={timestamp:1/0,priority:"control",initiator:g,actionType:A.type},J=F(),Q=i.emit.bind(i,y.interactives,{subjectId:g,subjectType:d,subjectName:"control",type:J?_.actionChoiceCanceled:_.actionChoice,actionType:f.type,payload:p({containerId:T},A.args)});if(J){Q();return}switch(A.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let ut=u.find(K=>K.id===A.args.branchId);if(!ut)return;M(A.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),A.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{chapterId:ut.chapterId,autoSelect:!1}}):(e.add(b(p({},et),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{chapterId:ut.chapterId,autoSelect:!1}})})),n==null||n());return}case k.continuePlayback.trim().toLowerCase():{M(A.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),A.args.shouldOpenNow?w({subjectId:g,subjectName:"control",subjectType:d,action:f}):e.add(b(p({},et),{action:w.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:f})}));return}case k.openURI.trim().toLowerCase():{M(A.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),A.args.shouldOpenNow?j({subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{URI:f.args.uri}}):(e.add(b(p({},et),{action:j.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:A,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:d,endTime:g},branches:T=[],isEOV:u=!1,autoSelected:M=!1})=>{let N=Ci(f,u),F={timestamp:!N.args.shouldOpenNow||u?1/0:g,priority:"container",initiator:d,actionType:N.type},A=i.emit.bind(i,y.interactives,{subjectId:d,subjectName:"container",type:_.actionChoice,actionType:N.type,payload:N.args});switch(N.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let et=T.find(J=>J.id===N.args.branchId);if(!et)return;A(),e.add(b(p({},F),{action:x.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{chapterId:et.chapterId,autoSelect:M}})})),n==null||n();return}case k.setMaxWeightBranch.trim().toLowerCase():return;case k.setMinWeightBranch.trim().toLowerCase():return;case k.setRandomBranch.trim().toLowerCase():return;case k.setWeightlessRandomBranch.trim().toLowerCase():return;case k.continuePlayback.trim().toLowerCase():{A(),e.add(b(p({},F),{action:w.bind(null,{subjectId:d,subjectName:"container",action:N})}));return}case k.openURI.trim().toLowerCase():{A(),e.add(b(p({},F),{action:j.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:f,branches:d,isEOV:g=!1}){let T=mi(f.events);if(T){let u=Ci(T.action,g);i.emit(y.interactives,{subjectId:f.id,subjectName:"container",type:_.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:g?1/0:f.endTime,priority:"container",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of f.events)o({action:u.action,container:f,branches:d,isEOV:g})}let h=({chapterId:f,action:d,branches:g=[]})=>{let T=i.emit.bind(i,y.interactives,{subjectId:f,subjectName:"chapter",type:_.actionChoice,actionType:d.type,payload:d.args});switch(d.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let u=g.find(M=>M.id===d.args.branchId);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setWeightlessRandomBranch.trim().toLowerCase():{let u=In(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setRandomBranch.trim().toLowerCase():{let u=xn(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMaxWeightBranch.trim().toLowerCase():{let u=En(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMinWeightBranch.trim().toLowerCase():{let u=Cn(g);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.continuePlayback.trim().toLowerCase():return T(),w.bind(null,{subjectId:f,subjectName:"chapter",action:d});case k.openURI.trim().toLowerCase():return T(),j.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{URI:d.args.uri}});default:console.error("Unexpected chapter event"),i.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function C(f){let d=mi(f.events);if(d){if(nt(f))return;i.emit(y.interactives,{subjectId:f.id,subjectName:"chapter",type:_.actionChoice,actionType:d.action.type,payload:d.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(g=>{let T=h({chapterId:f.id,action:g.action,branches:f.branches});T&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:g.action.type,action:T})})}let E=({subjectId:f,subjectName:d,action:g})=>{var T;t.pause(),i.emit(y.interactives,{subjectId:f,subjectName:d,type:_.actionExecution,actionType:(T=g==null?void 0:g.type)!=null?T:k.expect})},I=({subjectId:f,subjectName:d})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(y.interactives,{subjectId:f,subjectName:d,type:_.actionExecution,actionType:"after-expect"})},w=({subjectId:f,subjectName:d,subjectType:g,action:T})=>{i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type})},x=({subjectId:f,subjectName:d,subjectType:g,action:T,payload:u})=>{u.behaviour="change-chapter",i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type,payload:u})},R=({subjectId:f,subjectName:d,subjectType:g,action:T,payload:u})=>{u.behaviour="change-manifest",i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type,payload:u})},j=({subjectId:f,subjectName:d,subjectType:g,action:T,payload:u})=>{if(!u.URI)return;let M=window.open(u.URI,"_blank","noopener,noreferrer");M&&(M.opener=null),i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:_.actionExecution,actionType:T.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:h,onExpectEvent:E,expectEventHandler:I,setManifestChapterEvents:C,setManifestContainerEvents:c,stopExpect:s,state:r}};var mt=require("@vkontakte/videoplayer-shared");var Le=(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]=Ii(s)}return e[n]}).filter(Boolean)},Sn=i=>{for(let t of i.variants)if(wn(t)&&"payload"in t)return t.payload.id},wn=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Ii=i=>{let t=Sn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Vn=(i,t)=>{for(let e of i.media.videos)if(t===Ii(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},xi=(i,t)=>i.reduce((e,n)=>{let r=Vn(t,n);return r?[...e,r]:e},[]);var rt,Tt,St,tt,Ne,at,ot,it,wt,Ot,$t,te=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new mt.ValueSubject([]),hasPrevChapter$:new mt.ValueSubject(!1),prevChapter$:new mt.ValueSubject(null),isInitialChapter$:new mt.ValueSubject(!1),isGoBackLimited$:new mt.ValueSubject(!1)};v(this,rt,null);v(this,Tt,void 0);v(this,St,!1);v(this,tt,null);v(this,Ne,null);v(this,at,null);v(this,ot,null);v(this,it,null);v(this,wt,new mt.Subscription);v(this,Ot,!1);v(this,$t,0);var l,o,c;m(this,at,e),m(this,it,t),m(this,ot,n),m(this,rt,r),m(this,Tt,s),(l=this.state)!=null&&l.history$&&a(this,wt)&&((c=a(this,wt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(h=>{var C,E,I,w,x,R;(C=this.state)==null||C.prevChapter$.next(h.at(-2)||null),(E=this.state)==null||E.hasPrevChapter$.next(h.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((w=(I=a(this,tt))==null?void 0:I.metadata)==null?void 0:w.initChapterId)),(R=this.state)==null||R.isGoBackLimited$.next(a(this,$t)===a(this,Tt).maxLength-1)})))}setManifest(t){return V(this,null,function*(){!a(this,ot)||!a(this,it)||(m(this,tt,t),yield this.getProjectHistory(),yield a(this,ot).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,St)||(m(this,St,!0),a(this,it).emit(y.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,St)}updateHistory(t,e=!0){return V(this,null,function*(){var o,c;if(!a(this,tt))return;a(this,Ot)?(m(this,Ot,!1),Oi(this,$t)._++):m(this,$t,0);let n=a(this,tt),r=t.length-a(this,Tt).maxLength,s=r>0?t.slice(r):t,l=Le(s,n);if(m(this,Ne,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,rt)||!a(this,at)))try{yield a(this,rt).save(a(this,at),l)}catch(h){(c=a(this,it))==null||c.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}})}goBack(){return V(this,null,function*(){var n;if(!this.state||!a(this,ot))return(n=a(this,it))==null?void 0:n.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));m(this,Ot,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),yield a(this,ot).setChapter({chapterId:e})})}getProjectHistory(){return V(this,null,function*(){var r,s;if(!a(this,tt)||!a(this,at))return;let t=a(this,tt),e=[this.getInitialVideoId()];if(a(this,rt))try{let l=yield a(this,rt).get(a(this,at));l.length&&(e=l)}catch(l){(r=a(this,it))==null||r.emit(y.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}let n=xi(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,Tt).initChapterId||((n=a(this,tt))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,tt)){let t=this.getInitialChapterId();return Le([t],a(this,tt)).pop()}return null}destroy(){var t,e;this.state=null,m(this,at,null),m(this,rt,null),m(this,ot,null),(t=a(this,wt))==null||t.unsubscribe(),m(this,wt,null),m(this,St,!1),(e=a(this,it))==null||e.emit(y.historyDestroyed),m(this,it,null)}};rt=new WeakMap,Tt=new WeakMap,St=new WeakMap,tt=new WeakMap,Ne=new WeakMap,at=new WeakMap,ot=new WeakMap,it=new WeakMap,wt=new WeakMap,Ot=new WeakMap,$t=new WeakMap;var je,Rn,ee,Pe,_n,ct=class ct{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=P(s=ct,je,Rn).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}};je=new WeakSet,Rn=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(",")),P(n=ct,Pe,_n).call(n,t)?e:e.capture||!1}},ee=new WeakMap,Pe=new WeakSet,_n=function(t){let e=a(ct,ee);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}m(ct,ee,e)}return e||!1},v(ct,je),v(ct,Pe),v(ct,ee,void 0);var ke=ct;var Oe=class{constructor(){this.bindingMap=new Jt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new ke(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))}updateCanvasDimensions(t,e=!1){return V(this,null,function*(){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=yield this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n})}save(){return V(this,null,function*(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,yield 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 Be=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;
package/es2015.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.13-dev.bd51f176.0
3
- * Fri, 05 Jul 2024 11:13:53 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.13-dev.ce34fb1e.0
3
+ * Wed, 10 Jul 2024 13:08:24 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-13/doc/
5
5
  */
6
- var _n=Object.defineProperty,Mn=Object.defineProperties;var An=Object.getOwnPropertyDescriptors;var se=Object.getOwnPropertySymbols;var Ai=Object.prototype.hasOwnProperty,Li=Object.prototype.propertyIsEnumerable;var We=(i,t,e)=>t in i?_n(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))Ai.call(t,e)&&We(i,e,t[e]);if(se)for(var e of se(t))Li.call(t,e)&&We(i,e,t[e]);return i},b=(i,t)=>Mn(i,An(t));var K=(i,t)=>{var e={};for(var n in i)Ai.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&se)for(var n of se(i))t.indexOf(n)<0&&Li.call(i,n)&&(e[n]=i[n]);return e};var O=(i,t,e)=>(We(i,typeof t!="symbol"?t+"":t,e),e),Qe=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Qe(i,t,"read from private field"),e?e.call(i):t.get(i)),g=(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)},m=(i,t,e,n)=>(Qe(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Ni=(i,t,e,n)=>({set _(r){m(i,t,r,e)},get _(){return a(i,t,n)}}),P=(i,t,e)=>(Qe(i,t,"access private method"),e);var V=(i,t,e)=>new Promise((n,r)=>{var s=c=>{try{o(e.next(c))}catch(h){r(h)}},l=c=>{try{o(e.throw(c))}catch(h){r(h)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,l);o((e=e.apply(i,t)).next())});var ki="1.0.13-dev.bd51f176.0";function Ke(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 H="SDK_NAME",Ln="SDK_NAME-controls-container",re=()=>document.querySelector(`.${Ln}`),$i=.4,X={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},ji={top:"flex-start",bottom:"flex-end",center:"center"},Pi={start:"flex-start",end:"flex-end",center:"center"},Oi={start:"left",end:"right",center:"center"},ae=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=ji[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:ji.center,i.style.justifyContent=(s=Pi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Pi.center,i.style.textAlign=(o=Oi[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Oi.start},oe=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h;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=(h=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?h:e.textContent},ce=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Ke((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)},le=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h,C,E,I,S,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 ${Ke((h=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?h:e.borderColor,(I=(E=(C=t==null?void 0:t.shape)==null?void 0:C.border)==null?void 0:E.alpha)!=null?I:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(S=t==null?void 0:t.shape)==null?void 0:S.roundCorners)!=null?x:e.roundCorners})`},_t=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Xe="int",Mt={AREA:`${Xe}_area`,TEXT:`${Xe}_text`,BUTTON:`${Xe}_bttn`};var ut=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${H}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:X.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(`.${H}-control-container-${this.control.id}`)}};var he=i=>{if(i.type.trim().toLowerCase()==="area")return new qe(i)},qe=class extends ut{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(`${H}-${this.control.id}`),s.setAttribute("data-testid",Mt.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",ce({target:s,props:this.control.props,fallback:b(p({},X),{backgroundColor:"transparent"})}),le({target:s,props:this.control.props,fallback:b(p({},X),{borderAlpha:0}),dependsOn:n}),_t({target:s,layoutParams:this.control.layoutParams,fallback:X}),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(`.${H}-${this.control.id}`)}};var de=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var pe=i=>{if(i.type.trim().toLowerCase()==="button")return new Ze(i)},Ze=class extends ut{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(`${H}-${this.control.id}`),s.setAttribute("data-testid",Mt.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=de();return _t({target:s,layoutParams:this.control.layoutParams,fallback:X}),ce({target:s,props:this.control.props,fallback:X}),le({target:s,props:this.control.props,fallback:X,dependsOn:n}),ae({target:s,props:this.control.props}),oe({target:l,props:this.control.props,fallback:X,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(`.${H}-${this.control.id}`)}};var Bi=i=>{if(i.type.trim().toLowerCase()==="text")return new Ye(i)},Ye=class extends ut{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${H}-${this.control.id}`),s.setAttribute("data-testid",Mt.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=de();return _t({target:s,layoutParams:this.control.layoutParams,fallback:X}),ae({target:s,props:this.control.props}),oe({target:l,props:this.control.props,fallback:X,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${H}-${this.control.id}`)}};var Je=class{constructor(t){this.layout=t}},Fi=i=>{if(i.type.trim().toLowerCase()==="relative")return new Ft(i)},Ft=class extends Je{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 At,ue,fe,Di,Lt=class{constructor(t){g(this,At);g(this,fe);this.container=t,this.factories=new Map,P(this,At,ue).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),P(this,At,ue).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),P(this,At,ue).call(this)}};At=new WeakSet,ue=function(){this.controls=P(this,fe,Di).call(this)},fe=new WeakSet,Di=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 me=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new ti(i,t)},ti=class extends Lt{constructor(t,e){super(t),this.rootElement=e!=null?e:re(),this.layout=new Ft(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pe),this.addControlFactory("text",Bi),this.addControlFactory("area",he)}createView(t){let e=document.createElement("div");return e.classList.add(`${H}-${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(`.${H}-${this.container.id}`)}};import{Subject as us,ValueSubject as it,Observable as Cn,once as fs,Subscription as ms,getCurrentBrowser as ys,CurrentClientBrowser as gs,combine as vs}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as kn}from"@vkontakte/videoplayer-shared";function ye(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Dt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},bt=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Ht=i=>bt(i,Dt.Object),ge=i=>bt(i,Dt.String),ve=i=>bt(i,Dt.Array),be=i=>bt(i,Dt.Number),Hi=i=>bt(i,Dt.Function);var ei=i=>be(i)&&!isNaN(i);var Ct=i=>Ht(i)&&Object.keys(i).length===0,ii=i=>ve(i)&&!i.length;var Gt=(i,t)=>ge(i)&&(t?i.trim():i).length;var ni=window.navigator.userAgent.toLowerCase(),lr=/ipad|iphone|ipod/.test(ni),Gi=/mobi/i.test(ni),hr=ni.indexOf("android")>-1&&Gi,Nn=!Gi,dr=window.safari!==void 0&&Nn;var Ui="video_interactive",zi="videoint";var jn=250,Ut=class{constructor(t){O(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}))});O(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}});O(this,"handleManifestChange",(n,...r)=>V(this,[n,...r],function*(t,e=[]){var s;if(!be(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)==null||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let l;try{l=yield kn(this.lang,Ui,zi)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:o}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new o(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:l}),this.ngEditor.on("control",({name:c,chapterId:h})=>{c==="openPreview"&&this.onOpenPreviewClick(h)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo=p({},c)})}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=Pn(t),this.resizeObserver=new ResizeObserver(ye(this.onResize,jn)),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 Pn(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 si=()=>{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,h=Math.round(t.info.position$.getValue()*1e3);for(let C of i){let E=C.startTime-l;if(E<=h&&(h<=C.endTime||C.endTime===null)){c=!0;break}h<E&&(o=o===-1?E:Math.min(o,E))}return!c&&o!==-1?o:null}}};var ft=(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 On}from"uuid";var $n="3.1",Wi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Bn={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Qi=i=>{let t=[];for(let l of i.chapters){let o,c=[];for(let e of l.branches){let n=e,{isDefault:E}=n,I=K(n,["isDefault"]);E&&(o=I.id),c.push(I)}let h=[],C=[];for(let r of l.containers){let s=r,{fallbackStrategy:E}=s,I=K(s,["fallbackStrategy"]);let S=!!I.endTime,x=[Bn];switch(E){case"await":S?x=[]:h=[];break;case"default":{let R={type:"onSuspense",action:{type:Wi.default,args:{branchId:o,shouldOpenNow:!S,isDetachContainer:!0}}};S?x=[R]:h=[R];break}case"random":case"weightlessRandom":case"max":case"min":{let R={type:"onSuspense",action:{type:Wi[E],args:{}}};S?x=[R]:h=[R];break}}for(let R of I.controls)C.push(b(p({},I),{controls:[p({},R)],id:On(),events:x}))}t.push(b(p({},l),{containers:C,events:h,branches:c}))}return i.metadata.version=$n,i.metadata.updated=new Date().toISOString(),b(p({},i),{chapters:t})};var Fn="3.2",Ki=i=>{if(!i.media){let t=i.metadata,{media:e}=t,n=K(t,["media"]);return b(p({},i),{metadata:b(p({},n),{version:Fn}),media:e})}return i};var Dn="3.3",Hn=(i=[])=>({edit:{chapters:i},view:{}}),Xi={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},qi=i=>{var r;let t=[],e=[];for(let s of i.chapters){let n=s,{id:l,x:o,y:c}=n,h=K(n,["id","x","y"]),C=h.containers.map(E=>{var I;return b(p({},E),{controls:E.controls.map(j=>{var f=j,{subtype:S,type:x}=f,R=K(f,["subtype","type"]);return b(p({},R),{type:S!=null?S:x})}),events:(I=E.events)!=null&&I.length?E.events:[Xi]})});t.push(b(p({id:l},h),{containers:C,events:(r=h.events)!=null&&r.length?h.events:[Xi]})),e.push({id:l,x:o,y:c})}return b(p({},i),{chapters:t,graph:Hn(e),metadata:b(p({},i.metadata),{version:Dn})})};var Gn=[{version:"3.0",migrate:Qi},{version:"3.1",migrate:Ki},{version:"3.2",migrate:qi}],ri=i=>Gn.reduce((t,e)=>ft(t.metadata.version,e.version)?t:e.migrate(t),i);var Fr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Zi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Dr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),k=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),ai=(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))(ai||{});var Yi={metadata:"Object",chapters:"Array"},Un="3.0.0",zn="3.3.0",Ce=i=>{let t=ft(i,Un);return t===-1?!1:t===0?!0:ft(i,zn)!==1},Ji=i=>{if(!Ht(i))return!1;for(let t in Yi)if(!i[t]||!bt(i[t],Yi[t]))return!1;return Ce(i.metadata.version)},oi=i=>i.type===Zi.Text;var w=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};O(w,"Severity",{RECOVERABLE:1,CRITICAL:2}),O(w,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var Nt=class{constructor(){O(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 Ee=class{constructor(t){O(this,"addFn",(t,e=!1)=>{Hi(t)&&(this.fns.push(t),e&&this.updateFn())});O(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});O(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});O(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});O(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});O(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 Yn}from"@vkontakte/videoplayer-shared";var Ie=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:[]}}exec(t,e){return V(this,null,function*(){return Wn(...this.loaders[t])(e)})}};function Wn(...i){return function(e){return V(this,null,function*(){let n=[...i];for(;n.length>0;)e=yield n.shift()(e);return e})}}function zt(i,t,e){return i?b(p({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function xe(r){var s=r,{actions:i,errors:t,chapterId:e}=s,n=K(s,["actions","errors","chapterId"]);if(e){let l=i.getManifest(),o=i.getChapter(l.chapters,e);if(o){let c=i.getMedia(l.media,o.videoId),h=i.getGraph(l.graph,o.id);return c?b(p({},n),{actions:i,errors:t,result:{chapter:o,media:c,graph:h}}):b(p({},n),{errors:zt(t,xe.name,"Could not find media"),actions:i})}}return b(p({},n),{errors:zt(t,xe.name,"Could not find chapter"),actions:i})}var Qn=i=>V(void 0,null,function*(){try{let t,e;if(Ht(i))t=i;else if(ge(i)){e=new URL(i).href;let r=yield fetch(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!Ji(t))return{};let n=t.metadata.media;if(ge(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=yield fetch(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return qn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function tn(i){return V(this,null,function*(){let{manifest:t,manifestURL:e}=yield Qn(i),n=ri(t);return n.media=Kn(n.media,e),delete n.metadata.media,n})}function Te(i,t){return i.find(e=>e.id===t)}function ci(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 li(i,t){return i.videos.find(e=>e.id===t)}function Kn(i,t){return b(p({},i),{videos:i.videos.map(e=>b(p({},e),{variants:e.variants.map(n=>{let r=Xn(n.url,t);return b(p({},n),{url:r||n.url})})}))})}function Xn(i,t){try{return new URL(i,t).href}catch(e){return""}}function qn(i){return ft(i,"3.2.0")>=0}var F=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),hi=i=>ve(i)&&!ii(i),nt=i=>i.order==="end",Se=i=>ve(i.containers)&&!ii(i.containers)&&nt(i),en=(i,t)=>{var n;let e=i*1e3;return hi(t.controls)&&e<((n=t.startTime)!=null?n:0)},di=(i,t)=>{var n,r;let e=i*1e3;return hi(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var Et=i=>i.some(t=>t.action.type==="expect"),pi=i=>i.find(t=>t.action.type==="expect"),Zn=i=>(i==null?void 0:i.length)===1,we=i=>Zn(i)&&oi(i[0]);var nn=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(p(p({},n[t]),e[t])),sn=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!oi(c));if(hi(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],h=e.id;if(!n)t.push({subjects:[h],range:c});else{let C=[],E=-1/0,I=1/0,S=[],x=[];for(let R=0;R<t.length;R++){let j=t[R];if(x.push(...j.subjects),j.range[0]<I&&(I=j.range[0]),j.range[1]>E&&(E=j.range[1]),j.range[0]<=c[0]&&j.range[1]>=c[1])return t[R].subjects.push(h),t;c[0]>=j.range[0]&&c[0]<=j.range[1]&&(C.push(R),S=S.concat(j.subjects),c[0]=j.range[0]),c[1]>=j.range[0]&&c[1]<=j.range[1]&&(C.push(R),S=S.concat(j.subjects),c[1]=j.range[1])}if(x.push(h),c[0]<=I&&c[1]>=E)return[{subjects:x,range:c}];C.length&&C.reverse().forEach(R=>{t.splice(R,1)}),t.push({subjects:S.concat([h]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),rn=(i,t)=>Et(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Et(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var kt=class extends Ie{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new Yn(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){return V(this,null,function*(){var r;this.release();let e=yield this.exec("manifestLoaders",{actions:{addErrorMessage:zt},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=yield tn((r=e.result)!=null?r:t);return this.manifest=n,this})}setInitial(){return V(this,null,function*(){return this.setNext()})}setNext(){return V(this,arguments,function*(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let e=yield this.exec("chapterLoaders",xe({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ci,getChapter:Te,getMedia:li,getByBranches:this.getByBranches.bind(this),addErrorMessage:zt},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=Te(this.manifest.chapters,t);if(e){let n=li(this.manifest.media,e.videoId),r=ci(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=Te(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 nt(this.chapter)}};import{Player as Jn}from"@vkontakte/videoplayer-core";import{Subscription as ts}from"@vkontakte/videoplayer-shared";var an=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 v={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Wt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},A={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function ui(){let i=new Map;function t(o){var c=o,{listId:r=Math.random().toString(),itemId:s=Math.random().toString()}=c,l=K(c,["listId","itemId"]);let h=i.get(r),C=p({},l);return h?h[s]=C:i.set(r,{[s]:C}),p({listId:r,itemId:s},l)}function e(r,s){var o,c,h;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(h=l[s])==null||h.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let C of Object.values(l))C.player.destroy(),C.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 fi(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=b(p({},e.MPEG),{[(s=c.standard)!=null?s:"Invariant quality"]:c.url}));break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG=b(p({},e.MPEG),{[(l=c.standard)!=null?l:"Invariant quality"]:c.url}));break;case"hls":(r||t.includes("hls"))&&(e=b(p({},e),{HLS:{type:"url",url:c.url}}));break;case"dash":(r||t.includes("dash"))&&(e=b(p({},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 Qt=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var Kt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},es=2;function mi(i){let t=ui(),e,n,r=new Nt,s={},l=!1,o=null,c=!1,h;i&&C(i);function C(d){o=d}function E(d,y,T){var N;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let _=((N=t.map.get(d))!=null?N:{})[y];if(_){s=p({chapterId:T,listId:d,itemId:y},_);let B=s.player;n=B.info.currentQuality$.subscribe(M=>{if(!(!M||!B.info.position$.getValue())){e=M;for(let tt of t.map)Object.values(tt[1]).forEach(({player:Y})=>{B.info.isAutoQualityEnabled$.getValue()||Qt(Y,M)})}}),_.container.remove(),l=!1,o.setPlayer(_.player),c||(o.init(),c=!0),r.emit(Kt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function I(d,y,T){return V(this,null,function*(){if(!o)throw Error("need to set interactive controller");if(Ct(s)||d!==s.itemId)return;if(T>=0&&!l){let _=o.getChapterBranches();l=!0;let N=new Set;for(let B of _)N.has(B.media.id)||(yield x({media:B.media,chapterId:B.chapter.id,setAsActive:!1,title:B.chapter.label}),N.add(B.media.id))}})}function S(T){return V(this,arguments,function*({chapter:{id:d},media:y}){if(Ct(s))return;n==null||n.unsubscribe();let u=s.player.info.muted$.getValue(),_=s.player.info.currentQuality$.getValue(),N=s.player.info.isAutoQualityEnabled$.getValue(),B=s.player.info.volume$.getValue(),M=s.player.info.currentPlaybackRate$.getValue(),tt=!N,Y=!1;for(let W of t.map)if(W[0]===y.id){let pt=Object.keys(W[1]);for(let Q of pt)Q===s.itemId?(pt.length<es||(Y=!0),t.removePlayer(W[0],Q)):(Y=!0,E(W[0],Q,d),tt?Qt(s.player,_):s.player.setAutoQuality(!0),s.player.setVolume(B),s.player.setMuted(u),s.player.setPlaybackRate(M))}else t.removePlayer(W[0]);Y||(yield x({media:y,chapterId:d,setAsActive:!0,playbackRate:M}),tt?Qt(s.player,_):s.player.setAutoQuality(!0),s.player.setVolume(B),s.player.setMuted(u))})}function x(tt){return V(this,arguments,function*({media:d,chapterId:y,prefetch:T=!0,setAsActive:u=!0,autoplay:_=!1,preferredExt:N,title:B,playbackRate:M}){var wi,Vi,Ri,_i,Mi;let Y=Math.random().toString(),W=document.createElement("div");h.append(W);let pt=(wi=s==null?void 0:s.player)==null?void 0:wi.info.isAutoQualityEnabled$.getValue(),Q;if((Vi=o==null?void 0:o.options)!=null&&Vi.vkVideoLoader){let ne=an(d);ne.length&&(Q=yield o.options.vkVideoLoader(...ne))}let xi=((Ri=o==null?void 0:o.options)==null?void 0:Ri.coreConfig)||{},Rn=b(p({},xi),{configName:[...(_i=xi.configName)!=null?_i:[],"interactive"]}),Ti=b(p({container:W},((Mi=Q==null?void 0:Q.videos)==null?void 0:Mi[0])||{sources:fi(d,N).sources}),{title:B,failoverHosts:(Q==null?void 0:Q.failoverHosts)||[]}),vt=new Jn(Rn);vt.initVideo(Ti);let Si=new ts;Si.add(vt.info.position$.subscribe(function(ne){I(Y,vt.info.duration$.getValue(),ne)})).add(vt.events.canplay$.subscribe(function(){pt||Qt(vt,e),M&&vt.setPlaybackRate(M)}));let Rt=t.createPlayer({listId:d.id,itemId:Y,player:vt,container:W,sources:fi(d,N).sources,config:Ti,subscription:Si});return u&&E(d.id,Rt.itemId,y),_&&Rt.player.play(),T&&!_&&Rt.player.prepare(),r.emit(Kt.playerCreated,Rt.player),{player:Rt.player,config:Rt.config}})}function R(){j(),o=null}function j(){o==null||o.off(v.chapterChanged,S),t.removeAll(),s={},c=!1,l=!1}function f(y){return V(this,arguments,function*({container:d}){if(!o)throw Error("need to set interactive controller");j(),h=d;let{media:T,chapter:u}=o.getCurrentChapter();if(T){o.on(v.chapterChanged,S);let{player:_,config:N}=yield x({media:T,chapterId:u.id,title:u.label});return r.emit(Kt.initiated,{container:d,media:T,chapterId:u.id}),{player:_,config:N}}else console.error("not found")})}return b(p({},t),{on:r.on.bind(r),off:r.off.bind(r),init:f,setInteractiveController:C,createPlayer:x,removeAll:R,getActivePlayer:function(){return s}})}import{Subscription as is}from"@vkontakte/videoplayer-shared";var Ve=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:h,onRemove:C}){O(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==F.end&&(Et(this.container.container.events)&&this.gameState===F.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==F.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})))})});O(this,"show",()=>{var t,e,n,r;if(this.gameState===F.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!0,isFirst:!1});else{let l=nn({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})),(this.gameState===F.end||this.gameState===F.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1}))},isEOV:()=>this.gameState===F.end});this.container.createView(l),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});O(this,"onEndOfVideo",()=>{this.gameState=F.end,this.selectContainerEvent(!0)});O(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[F.destroyed,F.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(en(e,this.container.container))this.gameState!==F.beforeInteractive&&(this.gameState=F.beforeInteractive,this.onBeforeStartTime());else if(di(e,this.container.container))this.gameState!==F.interactive&&(this.gameState=F.interactive,this.onStartTime());else if(this.gameState!==F.afterInteractive){let o=this.gameState;this.gameState=F.afterInteractive,o===F.interactive&&this.onEndTime()}else this.gameState!==F.destroyed&&!this.isPermanentText&&this.removeView();let n=di(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(v.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 is,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&we(e.container.controls),this.disabledControls$=h,this.onRemove=C,this.globalEventEmitter=l,this.gameState=F.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=Et(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(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=F.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.containerRemoved,visibility:!1}),this.gameState=F.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=F.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 on(){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 h in i)+h<=o&&(c[h]=i[h]);return c}function n(o){let c={};for(let h in i)+h>=o&&(c[h]=i[h]);return c}function r({timestamp:o,priority:c,initiator:h}){var C;if(ei(o)){let E=(C=i[o])!=null?C:null;if(E&&Gt(c,!0)){let I={},S=E[c];if(S&&(I=p(p({},I),S)),I=Ct(I)?null:I,I&&Gt(h,!0)){let x=I[h];return x!=null?x:null}return I}return E}return null}function s({timestamp:o,priority:c,initiator:h}){if(ei(o))if(i[o]){if(Gt(c,!0))if(i[o][c]){if(Gt(h,!0))if(i[o][c][h]){if(delete i[o][c][h],!Ct(i[o][c]))return!0}else return!1;if(delete i[o][c],!Ct(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(E){var I=E,{timestamp:o,priority:c,initiator:h}=I,C=K(I,["timestamp","priority","initiator"]);var S,x,R;(x=(S=i[o])==null?void 0:S[c])!=null&&x[h]?i[o][c][h].push(p({},C)):(R=i[o])!=null&&R[c]?i[o][c]=b(p({},i[o][c]),{[h]:[p({},C)]}):i[o]?i[o]=b(p({},i[o]),{[c]:{[h]:[p({},C)]}}):i[o]={[c]:{[h]:[p({},C)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var ns=[k.expect,k.setNextBranch],ss=1/0;function yi(i){let t=i,e,n=rs(),r=new on,s,l=()=>{I(),f()},o=d=>{r.add.call(void 0,d),x()},c=(d=[])=>{for(let y of d)if(y.action(),ns.includes(y.actionType))break},h=(d=1/0)=>{var _,N,B;let y=Re((_=r.get({timestamp:d,priority:"control"}))!=null?_:{}),T=Re((N=r.get({timestamp:d,priority:"container"}))!=null?N:{}),u=Re((B=r.get({timestamp:d,priority:"chapter"}))!=null?B:{});return[...y,...T,...u]},C=d=>{n.isReady(d)&&c(h(d))},E=()=>{var d;c([...Re((d=r.get({timestamp:1/0,priority:"chapter"}))!=null?d:{})])},I=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},S=d=>{},x=()=>{e||(e=()=>setTimeout(()=>{C(1/0)}),s=t.events.ended$.subscribe(e))},R=d=>{I(),t=d},j=d=>{d.priority==="container"&&n.resetCalled(d.timestamp),r.remove(d)},f=()=>{n.release(),r.removeAll()};return{setPlayer:R,add:o,remove:j,exec:C,execEndOfVideo:E,listen:x,unlisten:I,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function rs(){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 h of l){let C=(o=h.endTime)!=null?o:ss,E=(c=i.get(C))!=null?c:{};i.set(C,b(p({},E),{[h.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 Re(i){return Object.values(i).flat().sort(t=>t.actionType===k.expect?-1:1)}var cn=(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,h;return o>l?(h=s,c=s*l):o<l?(h=r/l,c=r):(h=s,c=r),{videoContentWidth:h,videoContentHeight:c}};var as=250;function ln(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:C,videoContentHeight:E}=cn(c,h);c.style.setProperty("--interactive-content-width",`${C}px`),c.style.setProperty("--interactive-content-height",`${E}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=ye(o=>{let{fns:c=[]}=i();n(o);for(let h of c)h()},as);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Xt=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 os=i=>Math.floor(Math.random()*i),hn=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},dn=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 pn=i=>{let t=i.length,e=os(t);return i[e]};var un=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 fn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var gi=(i,t=!1)=>b(p({},i),{args:t?p(p({},i.args),fn):p(p({},fn),i.args)}),vi=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:d,controlId:y,containerId:T,branches:u=[],onEvent:_,isEOV:N=()=>!1,isDisabled:B=()=>!1})=>{let M=gi(f,N()),tt={timestamp:1/0,priority:"control",initiator:y,actionType:M.type},Y=B(),W=i.emit.bind(i,v.interactives,{subjectId:y,subjectType:d,subjectName:"control",type:Y?A.actionChoiceCanceled:A.actionChoice,actionType:f.type,payload:p({containerId:T},M.args)});if(Y){W();return}switch(M.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let pt=u.find(Q=>Q.id===M.args.branchId);if(!pt)return;_(M.args.isDetachContainer,I.bind(null,{subjectId:y,subjectName:"control"})),W(),M.args.shouldOpenNow?x({subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{chapterId:pt.chapterId,autoSelect:!1}}):(e.add(b(p({},tt),{action:x.bind(null,{subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{chapterId:pt.chapterId,autoSelect:!1}})})),n==null||n());return}case k.continuePlayback.trim().toLowerCase():{_(M.args.isDetachContainer,I.bind(null,{subjectId:y,subjectName:"control"})),W(),M.args.shouldOpenNow?S({subjectId:y,subjectName:"control",subjectType:d,action:f}):e.add(b(p({},tt),{action:S.bind(null,{subjectId:y,subjectName:"control",subjectType:d,action:f})}));return}case k.openURI.trim().toLowerCase():{_(M.args.isDetachContainer,I.bind(null,{subjectId:y,subjectName:"control"})),W(),M.args.shouldOpenNow?j({subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{URI:f.args.uri}}):(e.add(b(p({},tt),{action:j.bind(null,{subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:d,endTime:y},branches:T=[],isEOV:u=!1,autoSelected:_=!1})=>{let N=gi(f,u),B={timestamp:!N.args.shouldOpenNow||u?1/0:y,priority:"container",initiator:d,actionType:N.type},M=i.emit.bind(i,v.interactives,{subjectId:d,subjectName:"container",type:A.actionChoice,actionType:N.type,payload:N.args});switch(N.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let tt=T.find(Y=>Y.id===N.args.branchId);if(!tt)return;M(),e.add(b(p({},B),{action:x.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{chapterId:tt.chapterId,autoSelect:_}})})),n==null||n();return}case k.setMaxWeightBranch.trim().toLowerCase():return;case k.setMinWeightBranch.trim().toLowerCase():return;case k.setRandomBranch.trim().toLowerCase():return;case k.setWeightlessRandomBranch.trim().toLowerCase():return;case k.continuePlayback.trim().toLowerCase():{M(),e.add(b(p({},B),{action:S.bind(null,{subjectId:d,subjectName:"container",action:N})}));return}case k.openURI.trim().toLowerCase():{M(),e.add(b(p({},B),{action:j.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:f,branches:d,isEOV:y=!1}){let T=pi(f.events);if(T){let u=gi(T.action,y);i.emit(v.interactives,{subjectId:f.id,subjectName:"container",type:A.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:y?1/0:f.endTime,priority:"container",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of f.events)o({action:u.action,container:f,branches:d,isEOV:y})}let h=({chapterId:f,action:d,branches:y=[]})=>{let T=i.emit.bind(i,v.interactives,{subjectId:f,subjectName:"chapter",type:A.actionChoice,actionType:d.type,payload:d.args});switch(d.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let u=y.find(_=>_.id===d.args.branchId);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setWeightlessRandomBranch.trim().toLowerCase():{let u=pn(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setRandomBranch.trim().toLowerCase():{let u=un(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMaxWeightBranch.trim().toLowerCase():{let u=dn(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMinWeightBranch.trim().toLowerCase():{let u=hn(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.continuePlayback.trim().toLowerCase():return T(),S.bind(null,{subjectId:f,subjectName:"chapter",action:d});case k.openURI.trim().toLowerCase():return T(),j.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{URI:d.args.uri}});default:console.error("Unexpected chapter event"),i.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function C(f){let d=pi(f.events);if(d){if(nt(f))return;i.emit(v.interactives,{subjectId:f.id,subjectName:"chapter",type:A.actionChoice,actionType:d.action.type,payload:d.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(y=>{let T=h({chapterId:f.id,action:y.action,branches:f.branches});T&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:y.action.type,action:T})})}let E=({subjectId:f,subjectName:d,action:y})=>{var T;t.pause(),i.emit(v.interactives,{subjectId:f,subjectName:d,type:A.actionExecution,actionType:(T=y==null?void 0:y.type)!=null?T:k.expect})},I=({subjectId:f,subjectName:d})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(v.interactives,{subjectId:f,subjectName:d,type:A.actionExecution,actionType:"after-expect"})},S=({subjectId:f,subjectName:d,subjectType:y,action:T})=>{i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type})},x=({subjectId:f,subjectName:d,subjectType:y,action:T,payload:u})=>{u.behaviour="change-chapter",i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type,payload:u})},R=({subjectId:f,subjectName:d,subjectType:y,action:T,payload:u})=>{u.behaviour="change-manifest",i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type,payload:u})},j=({subjectId:f,subjectName:d,subjectType:y,action:T,payload:u})=>{if(!u.URI)return;let _=window.open(u.URI,"_blank","noopener,noreferrer");_&&(_.opener=null),i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:h,onExpectEvent:E,expectEventHandler:I,setManifestChapterEvents:C,setManifestContainerEvents:c,stopExpect:s,state:r}};import{Subscription as ps,ValueSubject as qt}from"@vkontakte/videoplayer-shared";var bi=(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]=mn(s)}return e[n]}).filter(Boolean)},ls=i=>{for(let t of i.variants)if(hs(t)&&"payload"in t)return t.payload.id},hs=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",mn=i=>{let t=ls(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},ds=(i,t)=>{for(let e of i.media.videos)if(t===mn(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},yn=(i,t)=>i.reduce((e,n)=>{let r=ds(t,n);return r?[...e,r]:e},[]);var st,It,xt,J,_e,rt,at,et,Tt,jt,Pt,Zt=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new qt([]),hasPrevChapter$:new qt(!1),prevChapter$:new qt(null),isInitialChapter$:new qt(!1),isGoBackLimited$:new qt(!1)};g(this,st,null);g(this,It,void 0);g(this,xt,!1);g(this,J,null);g(this,_e,null);g(this,rt,null);g(this,at,null);g(this,et,null);g(this,Tt,new ps);g(this,jt,!1);g(this,Pt,0);var l,o,c;m(this,rt,e),m(this,et,t),m(this,at,n),m(this,st,r),m(this,It,s),(l=this.state)!=null&&l.history$&&a(this,Tt)&&((c=a(this,Tt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(h=>{var C,E,I,S,x,R;(C=this.state)==null||C.prevChapter$.next(h.at(-2)||null),(E=this.state)==null||E.hasPrevChapter$.next(h.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((S=(I=a(this,J))==null?void 0:I.metadata)==null?void 0:S.initChapterId)),(R=this.state)==null||R.isGoBackLimited$.next(a(this,Pt)===a(this,It).maxLength-1)})))}setManifest(t){return V(this,null,function*(){!a(this,at)||!a(this,et)||(m(this,J,t),yield this.getProjectHistory(),yield a(this,at).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,xt)||(m(this,xt,!0),a(this,et).emit(v.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,xt)}updateHistory(t,e=!0){return V(this,null,function*(){var o,c;if(!a(this,J))return;a(this,jt)?(m(this,jt,!1),Ni(this,Pt)._++):m(this,Pt,0);let n=a(this,J),r=t.length-a(this,It).maxLength,s=r>0?t.slice(r):t,l=bi(s,n);if(m(this,_e,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,st)||!a(this,rt)))try{yield a(this,st).save(a(this,rt),l)}catch(h){(c=a(this,et))==null||c.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Unable to save interactive history"))}})}goBack(){return V(this,null,function*(){var n;if(!this.state||!a(this,at))return(n=a(this,et))==null?void 0:n.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));m(this,jt,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),yield a(this,at).setChapter({chapterId:e})})}getProjectHistory(){return V(this,null,function*(){var r,s;if(!a(this,J)||!a(this,rt))return;let t=a(this,J),e=[this.getInitialVideoId()];if(a(this,st))try{let l=yield a(this,st).get(a(this,rt));l.length&&(e=l)}catch(l){(r=a(this,et))==null||r.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Error while trying to fetch data"))}let n=yn(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,It).initChapterId||((n=a(this,J))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,J)){let t=this.getInitialChapterId();return bi([t],a(this,J)).pop()}return null}destroy(){var t,e;this.state=null,m(this,rt,null),m(this,st,null),m(this,at,null),(t=a(this,Tt))==null||t.unsubscribe(),m(this,Tt,null),m(this,xt,!1),(e=a(this,et))==null||e.emit(v.historyDestroyed),m(this,et,null)}};st=new WeakMap,It=new WeakMap,xt=new WeakMap,J=new WeakMap,_e=new WeakMap,rt=new WeakMap,at=new WeakMap,et=new WeakMap,Tt=new WeakMap,jt=new WeakMap,Pt=new WeakMap;var Ae,gn,Yt,Le,vn,ot=class ot{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=P(s=ot,Ae,gn).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}};Ae=new WeakSet,gn=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(",")),P(n=ot,Le,vn).call(n,t)?e:e.capture||!1}},Yt=new WeakMap,Le=new WeakSet,vn=function(t){let e=a(ot,Yt);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}m(ot,Yt,e)}return e||!1},g(ot,Ae),g(ot,Le),g(ot,Yt,void 0);var Me=ot;var Ne=class{constructor(){this.bindingMap=new Xt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Me(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 ke=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))}updateCanvasDimensions(t,e=!1){return V(this,null,function*(){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=yield this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n})}save(){return V(this,null,function*(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,yield 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 je=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 _n=Object.defineProperty,Mn=Object.defineProperties;var An=Object.getOwnPropertyDescriptors;var se=Object.getOwnPropertySymbols;var Ai=Object.prototype.hasOwnProperty,Li=Object.prototype.propertyIsEnumerable;var We=(i,t,e)=>t in i?_n(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))Ai.call(t,e)&&We(i,e,t[e]);if(se)for(var e of se(t))Li.call(t,e)&&We(i,e,t[e]);return i},b=(i,t)=>Mn(i,An(t));var K=(i,t)=>{var e={};for(var n in i)Ai.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&se)for(var n of se(i))t.indexOf(n)<0&&Li.call(i,n)&&(e[n]=i[n]);return e};var O=(i,t,e)=>(We(i,typeof t!="symbol"?t+"":t,e),e),Qe=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Qe(i,t,"read from private field"),e?e.call(i):t.get(i)),g=(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)},m=(i,t,e,n)=>(Qe(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Ni=(i,t,e,n)=>({set _(r){m(i,t,r,e)},get _(){return a(i,t,n)}}),P=(i,t,e)=>(Qe(i,t,"access private method"),e);var V=(i,t,e)=>new Promise((n,r)=>{var s=c=>{try{o(e.next(c))}catch(h){r(h)}},l=c=>{try{o(e.throw(c))}catch(h){r(h)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,l);o((e=e.apply(i,t)).next())});var ki="1.0.13-dev.ce34fb1e.0";function Ke(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 H="SDK_NAME",Ln="SDK_NAME-controls-container",re=()=>document.querySelector(`.${Ln}`),$i=.4,X={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},ji={top:"flex-start",bottom:"flex-end",center:"center"},Pi={start:"flex-start",end:"flex-end",center:"center"},Oi={start:"left",end:"right",center:"center"},ae=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=ji[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:ji.center,i.style.justifyContent=(s=Pi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Pi.center,i.style.textAlign=(o=Oi[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Oi.start},oe=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h;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=(h=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?h:e.textContent},ce=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Ke((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)},le=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,h,C,E,I,S,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 ${Ke((h=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?h:e.borderColor,(I=(E=(C=t==null?void 0:t.shape)==null?void 0:C.border)==null?void 0:E.alpha)!=null?I:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(S=t==null?void 0:t.shape)==null?void 0:S.roundCorners)!=null?x:e.roundCorners})`},_t=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Xe="int",Mt={AREA:`${Xe}_area`,TEXT:`${Xe}_text`,BUTTON:`${Xe}_bttn`};var ut=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${H}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:X.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(`.${H}-control-container-${this.control.id}`)}};var he=i=>{if(i.type.trim().toLowerCase()==="area")return new qe(i)},qe=class extends ut{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(`${H}-${this.control.id}`),s.setAttribute("data-testid",Mt.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",ce({target:s,props:this.control.props,fallback:b(p({},X),{backgroundColor:"transparent"})}),le({target:s,props:this.control.props,fallback:b(p({},X),{borderAlpha:0}),dependsOn:n}),_t({target:s,layoutParams:this.control.layoutParams,fallback:X}),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(`.${H}-${this.control.id}`)}};var de=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var pe=i=>{if(i.type.trim().toLowerCase()==="button")return new Ze(i)},Ze=class extends ut{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(`${H}-${this.control.id}`),s.setAttribute("data-testid",Mt.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=de();return _t({target:s,layoutParams:this.control.layoutParams,fallback:X}),ce({target:s,props:this.control.props,fallback:X}),le({target:s,props:this.control.props,fallback:X,dependsOn:n}),ae({target:s,props:this.control.props}),oe({target:l,props:this.control.props,fallback:X,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(`.${H}-${this.control.id}`)}};var Bi=i=>{if(i.type.trim().toLowerCase()==="text")return new Ye(i)},Ye=class extends ut{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${H}-${this.control.id}`),s.setAttribute("data-testid",Mt.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=de();return _t({target:s,layoutParams:this.control.layoutParams,fallback:X}),ae({target:s,props:this.control.props}),oe({target:l,props:this.control.props,fallback:X,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${H}-${this.control.id}`)}};var Je=class{constructor(t){this.layout=t}},Fi=i=>{if(i.type.trim().toLowerCase()==="relative")return new Ft(i)},Ft=class extends Je{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 At,ue,fe,Di,Lt=class{constructor(t){g(this,At);g(this,fe);this.container=t,this.factories=new Map,P(this,At,ue).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),P(this,At,ue).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),P(this,At,ue).call(this)}};At=new WeakSet,ue=function(){this.controls=P(this,fe,Di).call(this)},fe=new WeakSet,Di=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 me=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new ti(i,t)},ti=class extends Lt{constructor(t,e){super(t),this.rootElement=e!=null?e:re(),this.layout=new Ft(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",pe),this.addControlFactory("text",Bi),this.addControlFactory("area",he)}createView(t){let e=document.createElement("div");return e.classList.add(`${H}-${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(`.${H}-${this.container.id}`)}};import{Subject as us,ValueSubject as it,Observable as Cn,once as fs,Subscription as ms,getCurrentBrowser as ys,CurrentClientBrowser as gs,combine as vs}from"@vkontakte/videoplayer-shared";import{loadVKLangPack as kn}from"@vkontakte/videoplayer-shared";function ye(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Dt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},bt=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Ht=i=>bt(i,Dt.Object),ge=i=>bt(i,Dt.String),ve=i=>bt(i,Dt.Array),be=i=>bt(i,Dt.Number),Hi=i=>bt(i,Dt.Function);var ei=i=>be(i)&&!isNaN(i);var Ct=i=>Ht(i)&&Object.keys(i).length===0,ii=i=>ve(i)&&!i.length;var Gt=(i,t)=>ge(i)&&(t?i.trim():i).length;var ni=window.navigator.userAgent.toLowerCase(),lr=/ipad|iphone|ipod/.test(ni),Gi=/mobi/i.test(ni),hr=ni.indexOf("android")>-1&&Gi,Nn=!Gi,dr=window.safari!==void 0&&Nn;var Ui="video_interactive",zi="videoint";var jn=250,Ut=class{constructor(t){O(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}))});O(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}});O(this,"handleManifestChange",(n,...r)=>V(this,[n,...r],function*(t,e=[]){var s;if(!be(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)==null||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let l;try{l=yield kn(this.lang,Ui,zi)}catch(c){console.log("Unable to load graph language pack")}let{GraphEditor:o}=yield import("@interactiveplatform/movika-graph-editor");this.ngEditor=new o(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:l}),this.ngEditor.on("control",({name:c,chapterId:h})=>{c==="openPreview"&&this.onOpenPreviewClick(h)}),this.ngEditor.on("zoomEnd",c=>{this.lastZoomInfo=p({},c)})}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=Pn(t),this.resizeObserver=new ResizeObserver(ye(this.onResize,jn)),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 Pn(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 si=()=>{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,h=Math.round(t.info.position$.getValue()*1e3);for(let C of i){let E=C.startTime-l;if(E<=h&&(h<=C.endTime||C.endTime===null)){c=!0;break}h<E&&(o=o===-1?E:Math.min(o,E))}return!c&&o!==-1?o:null}}};var ft=(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 On}from"uuid";var $n="3.1",Wi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Bn={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Qi=i=>{let t=[];for(let l of i.chapters){let o,c=[];for(let e of l.branches){let n=e,{isDefault:E}=n,I=K(n,["isDefault"]);E&&(o=I.id),c.push(I)}let h=[],C=[];for(let r of l.containers){let s=r,{fallbackStrategy:E}=s,I=K(s,["fallbackStrategy"]);let S=!!I.endTime,x=[Bn];switch(E){case"await":S?x=[]:h=[];break;case"default":{let R={type:"onSuspense",action:{type:Wi.default,args:{branchId:o,shouldOpenNow:!S,isDetachContainer:!0}}};S?x=[R]:h=[R];break}case"random":case"weightlessRandom":case"max":case"min":{let R={type:"onSuspense",action:{type:Wi[E],args:{}}};S?x=[R]:h=[R];break}}for(let R of I.controls)C.push(b(p({},I),{controls:[p({},R)],id:On(),events:x}))}t.push(b(p({},l),{containers:C,events:h,branches:c}))}return i.metadata.version=$n,i.metadata.updated=new Date().toISOString(),b(p({},i),{chapters:t})};var Fn="3.2",Ki=i=>{if(!i.media){let t=i.metadata,{media:e}=t,n=K(t,["media"]);return b(p({},i),{metadata:b(p({},n),{version:Fn}),media:e})}return i};var Dn="3.3",Hn=(i=[])=>({edit:{chapters:i},view:{}}),Xi={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},qi=i=>{var r;let t=[],e=[];for(let s of i.chapters){let n=s,{id:l,x:o,y:c}=n,h=K(n,["id","x","y"]),C=h.containers.map(E=>{var I;return b(p({},E),{controls:E.controls.map(j=>{var f=j,{subtype:S,type:x}=f,R=K(f,["subtype","type"]);return b(p({},R),{type:S!=null?S:x})}),events:(I=E.events)!=null&&I.length?E.events:[Xi]})});t.push(b(p({id:l},h),{containers:C,events:(r=h.events)!=null&&r.length?h.events:[Xi]})),e.push({id:l,x:o,y:c})}return b(p({},i),{chapters:t,graph:Hn(e),metadata:b(p({},i.metadata),{version:Dn})})};var Gn=[{version:"3.0",migrate:Qi},{version:"3.1",migrate:Ki},{version:"3.2",migrate:qi}],ri=i=>Gn.reduce((t,e)=>ft(t.metadata.version,e.version)?t:e.migrate(t),i);var Fr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Zi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Dr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),k=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),ai=(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))(ai||{});var Yi={metadata:"Object",chapters:"Array"},Un="3.0.0",zn="3.3.0",Ce=i=>{let t=ft(i,Un);return t===-1?!1:t===0?!0:ft(i,zn)!==1},Ji=i=>{if(!Ht(i))return!1;for(let t in Yi)if(!i[t]||!bt(i[t],Yi[t]))return!1;return Ce(i.metadata.version)},oi=i=>i.type===Zi.Text;var w=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};O(w,"Severity",{RECOVERABLE:1,CRITICAL:2}),O(w,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var Nt=class{constructor(){O(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 Ee=class{constructor(t){O(this,"addFn",(t,e=!1)=>{Hi(t)&&(this.fns.push(t),e&&this.updateFn())});O(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});O(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});O(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});O(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});O(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 Yn}from"@vkontakte/videoplayer-shared";var Ie=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:[]}}exec(t,e){return V(this,null,function*(){return Wn(...this.loaders[t])(e)})}};function Wn(...i){return function(e){return V(this,null,function*(){let n=[...i];for(;n.length>0;)e=yield n.shift()(e);return e})}}function zt(i,t,e){return i?b(p({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function xe(r){var s=r,{actions:i,errors:t,chapterId:e}=s,n=K(s,["actions","errors","chapterId"]);if(e){let l=i.getManifest(),o=i.getChapter(l.chapters,e);if(o){let c=i.getMedia(l.media,o.videoId),h=i.getGraph(l.graph,o.id);return c?b(p({},n),{actions:i,errors:t,result:{chapter:o,media:c,graph:h}}):b(p({},n),{errors:zt(t,xe.name,"Could not find media"),actions:i})}}return b(p({},n),{errors:zt(t,xe.name,"Could not find chapter"),actions:i})}var Qn=i=>V(void 0,null,function*(){try{let t,e;if(Ht(i))t=i;else if(ge(i)){e=new URL(i).href;let r=yield fetch(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!Ji(t))return{};let n=t.metadata.media;if(ge(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=yield fetch(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return qn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function tn(i){return V(this,null,function*(){let{manifest:t,manifestURL:e}=yield Qn(i),n=ri(t);return n.media=Kn(n.media,e),delete n.metadata.media,n})}function Te(i,t){return i.find(e=>e.id===t)}function ci(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 li(i,t){return i.videos.find(e=>e.id===t)}function Kn(i,t){return b(p({},i),{videos:i.videos.map(e=>b(p({},e),{variants:e.variants.map(n=>{let r=Xn(n.url,t);return b(p({},n),{url:r||n.url})})}))})}function Xn(i,t){try{return new URL(i,t).href}catch(e){return""}}function qn(i){return ft(i,"3.2.0")>=0}var F=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),hi=i=>ve(i)&&!ii(i),nt=i=>i.order==="end",Se=i=>ve(i.containers)&&!ii(i.containers)&&nt(i),en=(i,t)=>{var n;let e=i*1e3;return hi(t.controls)&&e<((n=t.startTime)!=null?n:0)},di=(i,t)=>{var n,r;let e=i*1e3;return hi(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var Et=i=>i.some(t=>t.action.type==="expect"),pi=i=>i.find(t=>t.action.type==="expect"),Zn=i=>(i==null?void 0:i.length)===1,we=i=>Zn(i)&&oi(i[0]);var nn=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(p(p({},n[t]),e[t])),sn=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!oi(c));if(hi(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],h=e.id;if(!n)t.push({subjects:[h],range:c});else{let C=[],E=-1/0,I=1/0,S=[],x=[];for(let R=0;R<t.length;R++){let j=t[R];if(x.push(...j.subjects),j.range[0]<I&&(I=j.range[0]),j.range[1]>E&&(E=j.range[1]),j.range[0]<=c[0]&&j.range[1]>=c[1])return t[R].subjects.push(h),t;c[0]>=j.range[0]&&c[0]<=j.range[1]&&(C.push(R),S=S.concat(j.subjects),c[0]=j.range[0]),c[1]>=j.range[0]&&c[1]<=j.range[1]&&(C.push(R),S=S.concat(j.subjects),c[1]=j.range[1])}if(x.push(h),c[0]<=I&&c[1]>=E)return[{subjects:x,range:c}];C.length&&C.reverse().forEach(R=>{t.splice(R,1)}),t.push({subjects:S.concat([h]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),rn=(i,t)=>Et(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Et(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var kt=class extends Ie{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new Yn(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}setManifest(t){return V(this,null,function*(){var r;this.release();let e=yield this.exec("manifestLoaders",{actions:{addErrorMessage:zt},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=yield tn((r=e.result)!=null?r:t);return this.manifest=n,this})}setInitial(){return V(this,null,function*(){return this.setNext()})}setNext(){return V(this,arguments,function*(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let e=yield this.exec("chapterLoaders",xe({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ci,getChapter:Te,getMedia:li,getByBranches:this.getByBranches.bind(this),addErrorMessage:zt},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=Te(this.manifest.chapters,t);if(e){let n=li(this.manifest.media,e.videoId),r=ci(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=Te(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 nt(this.chapter)}};import{Player as Jn}from"@vkontakte/videoplayer-core";import{Subscription as ts}from"@vkontakte/videoplayer-shared";var an=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 v={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Wt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},A={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function ui(){let i=new Map;function t(o){var c=o,{listId:r=Math.random().toString(),itemId:s=Math.random().toString()}=c,l=K(c,["listId","itemId"]);let h=i.get(r),C=p({},l);return h?h[s]=C:i.set(r,{[s]:C}),p({listId:r,itemId:s},l)}function e(r,s){var o,c,h;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(h=l[s])==null||h.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let C of Object.values(l))C.player.destroy(),C.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 fi(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=b(p({},e.MPEG),{[(s=c.standard)!=null?s:"Invariant quality"]:c.url}));break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG=b(p({},e.MPEG),{[(l=c.standard)!=null?l:"Invariant quality"]:c.url}));break;case"hls":(r||t.includes("hls"))&&(e=b(p({},e),{HLS:{type:"url",url:c.url}}));break;case"dash":(r||t.includes("dash"))&&(e=b(p({},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 Qt=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var Kt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},es=2;function mi(i){let t=ui(),e,n,r=new Nt,s={},l=!1,o=null,c=!1,h;i&&C(i);function C(d){o=d}function E(d,y,T){var N;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let _=((N=t.map.get(d))!=null?N:{})[y];if(_){s=p({chapterId:T,listId:d,itemId:y},_);let B=s.player;n=B.info.currentQuality$.subscribe(M=>{if(!(!M||!B.info.position$.getValue())){e=M;for(let tt of t.map)Object.values(tt[1]).forEach(({player:Y})=>{B.info.isAutoQualityEnabled$.getValue()||Qt(Y,M)})}}),_.container.remove(),l=!1,o.setPlayer(_.player),c||(o.init(),c=!0),r.emit(Kt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function I(d,y,T){return V(this,null,function*(){if(!o)throw Error("need to set interactive controller");if(Ct(s)||d!==s.itemId)return;if(T>=0&&!l){let _=o.getChapterBranches();l=!0;let N=new Set;for(let B of _)N.has(B.media.id)||(yield x({media:B.media,chapterId:B.chapter.id,setAsActive:!1,title:B.chapter.label}),N.add(B.media.id))}})}function S(T){return V(this,arguments,function*({chapter:{id:d},media:y}){if(Ct(s))return;n==null||n.unsubscribe();let u=s.player.info.muted$.getValue(),_=s.player.info.currentQuality$.getValue(),N=s.player.info.isAutoQualityEnabled$.getValue(),B=s.player.info.volume$.getValue(),M=s.player.info.currentPlaybackRate$.getValue(),tt=!N,Y=!1;for(let W of t.map)if(W[0]===y.id){let pt=Object.keys(W[1]);for(let Q of pt)Q===s.itemId?(pt.length<es||(Y=!0),t.removePlayer(W[0],Q)):(Y=!0,E(W[0],Q,d),tt?Qt(s.player,_):s.player.setAutoQuality(!0),s.player.setVolume(B),s.player.setMuted(u),s.player.setPlaybackRate(M))}else t.removePlayer(W[0]);Y||(yield x({media:y,chapterId:d,setAsActive:!0,playbackRate:M}),tt?Qt(s.player,_):s.player.setAutoQuality(!0),s.player.setVolume(B),s.player.setMuted(u))})}function x(tt){return V(this,arguments,function*({media:d,chapterId:y,prefetch:T=!0,setAsActive:u=!0,autoplay:_=!1,preferredExt:N,title:B,playbackRate:M}){var wi,Vi,Ri,_i,Mi;let Y=Math.random().toString(),W=document.createElement("div");h.append(W);let pt=(wi=s==null?void 0:s.player)==null?void 0:wi.info.isAutoQualityEnabled$.getValue(),Q;if((Vi=o==null?void 0:o.options)!=null&&Vi.vkVideoLoader){let ne=an(d);ne.length&&(Q=yield o.options.vkVideoLoader(...ne))}let xi=((Ri=o==null?void 0:o.options)==null?void 0:Ri.coreConfig)||{},Rn=b(p({},xi),{configName:[...(_i=xi.configName)!=null?_i:[],"interactive"]}),Ti=b(p({container:W},((Mi=Q==null?void 0:Q.videos)==null?void 0:Mi[0])||{sources:fi(d,N).sources}),{title:B,failoverHosts:(Q==null?void 0:Q.failoverHosts)||[]}),vt=new Jn(Rn);vt.initVideo(Ti);let Si=new ts;Si.add(vt.info.position$.subscribe(function(ne){I(Y,vt.info.duration$.getValue(),ne)})).add(vt.events.canplay$.subscribe(function(){pt||Qt(vt,e),M&&vt.setPlaybackRate(M)}));let Rt=t.createPlayer({listId:d.id,itemId:Y,player:vt,container:W,sources:fi(d,N).sources,config:Ti,subscription:Si});return u&&E(d.id,Rt.itemId,y),_&&Rt.player.play(),T&&!_&&Rt.player.prepare(),r.emit(Kt.playerCreated,Rt.player),{player:Rt.player,config:Rt.config}})}function R(){j(),o=null}function j(){o==null||o.off(v.chapterChanged,S),t.removeAll(),s={},c=!1,l=!1}function f(y){return V(this,arguments,function*({container:d}){if(!o)throw Error("need to set interactive controller");j(),h=d;let{media:T,chapter:u}=o.getCurrentChapter();if(T){o.on(v.chapterChanged,S);let{player:_,config:N}=yield x({media:T,chapterId:u.id,title:u.label});return r.emit(Kt.initiated,{container:d,media:T,chapterId:u.id}),{player:_,config:N}}else console.error("not found")})}return b(p({},t),{on:r.on.bind(r),off:r.off.bind(r),init:f,setInteractiveController:C,createPlayer:x,removeAll:R,getActivePlayer:function(){return s}})}import{Subscription as is}from"@vkontakte/videoplayer-shared";var Ve=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:h,onRemove:C}){O(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==F.end&&(Et(this.container.container.events)&&this.gameState===F.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==F.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})))})});O(this,"show",()=>{var t,e,n,r;if(this.gameState===F.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!0,isFirst:!1});else{let l=nn({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})),(this.gameState===F.end||this.gameState===F.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1}))},isEOV:()=>this.gameState===F.end});this.container.createView(l),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});O(this,"onEndOfVideo",()=>{this.gameState=F.end,this.selectContainerEvent(!0)});O(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[F.destroyed,F.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(en(e,this.container.container))this.gameState!==F.beforeInteractive&&(this.gameState=F.beforeInteractive,this.onBeforeStartTime());else if(di(e,this.container.container))this.gameState!==F.interactive&&(this.gameState=F.interactive,this.onStartTime());else if(this.gameState!==F.afterInteractive){let o=this.gameState;this.gameState=F.afterInteractive,o===F.interactive&&this.onEndTime()}else this.gameState!==F.destroyed&&!this.isPermanentText&&this.removeView();let n=di(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(v.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 is,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&we(e.container.controls),this.disabledControls$=h,this.onRemove=C,this.globalEventEmitter=l,this.gameState=F.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=Et(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(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=F.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(v.interactives,{subjectId:this.container.container.id,subjectName:"container",type:A.containerRemoved,visibility:!1}),this.gameState=F.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=F.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 on(){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 h in i)+h<=o&&(c[h]=i[h]);return c}function n(o){let c={};for(let h in i)+h>=o&&(c[h]=i[h]);return c}function r({timestamp:o,priority:c,initiator:h}){var C;if(ei(o)){let E=(C=i[o])!=null?C:null;if(E&&Gt(c,!0)){let I={},S=E[c];if(S&&(I=p(p({},I),S)),I=Ct(I)?null:I,I&&Gt(h,!0)){let x=I[h];return x!=null?x:null}return I}return E}return null}function s({timestamp:o,priority:c,initiator:h}){if(ei(o))if(i[o]){if(Gt(c,!0))if(i[o][c]){if(Gt(h,!0))if(i[o][c][h]){if(delete i[o][c][h],!Ct(i[o][c]))return!0}else return!1;if(delete i[o][c],!Ct(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(E){var I=E,{timestamp:o,priority:c,initiator:h}=I,C=K(I,["timestamp","priority","initiator"]);var S,x,R;(x=(S=i[o])==null?void 0:S[c])!=null&&x[h]?i[o][c][h].push(p({},C)):(R=i[o])!=null&&R[c]?i[o][c]=b(p({},i[o][c]),{[h]:[p({},C)]}):i[o]?i[o]=b(p({},i[o]),{[c]:{[h]:[p({},C)]}}):i[o]={[c]:{[h]:[p({},C)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var ns=[k.expect,k.setNextBranch],ss=1/0;function yi(i){let t=i,e,n=rs(),r=new on,s,l=()=>{I(),f()},o=d=>{r.add.call(void 0,d),x()},c=(d=[])=>{for(let y of d)if(y.action(),ns.includes(y.actionType))break},h=(d=1/0)=>{var _,N,B;let y=Re((_=r.get({timestamp:d,priority:"control"}))!=null?_:{}),T=Re((N=r.get({timestamp:d,priority:"container"}))!=null?N:{}),u=Re((B=r.get({timestamp:d,priority:"chapter"}))!=null?B:{});return[...y,...T,...u]},C=d=>{n.isReady(d)&&c(h(d))},E=()=>{var d;c([...Re((d=r.get({timestamp:1/0,priority:"chapter"}))!=null?d:{})])},I=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},S=d=>{},x=()=>{e||(e=()=>setTimeout(()=>{C(1/0)}),s=t.events.ended$.subscribe(e))},R=d=>{I(),t=d},j=d=>{d.priority==="container"&&n.resetCalled(d.timestamp),r.remove(d)},f=()=>{n.release(),r.removeAll()};return{setPlayer:R,add:o,remove:j,exec:C,execEndOfVideo:E,listen:x,unlisten:I,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function rs(){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 h of l){let C=(o=h.endTime)!=null?o:ss,E=(c=i.get(C))!=null?c:{};i.set(C,b(p({},E),{[h.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 Re(i){return Object.values(i).flat().sort(t=>t.actionType===k.expect?-1:1)}var cn=(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,h;return o>l?(h=s,c=s*l):o<l?(h=r/l,c=r):(h=s,c=r),{videoContentWidth:h,videoContentHeight:c}};var as=250;function ln(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:h}=i();if(c&&h){let{videoContentWidth:C,videoContentHeight:E}=cn(c,h);c.style.setProperty("--interactive-content-width",`${C}px`),c.style.setProperty("--interactive-content-height",`${E}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=ye(o=>{let{fns:c=[]}=i();n(o);for(let h of c)h()},as);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Xt=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 os=i=>Math.floor(Math.random()*i),hn=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},dn=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 pn=i=>{let t=i.length,e=os(t);return i[e]};var un=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 fn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var gi=(i,t=!1)=>b(p({},i),{args:t?p(p({},i.args),fn):p(p({},fn),i.args)}),vi=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:d,controlId:y,containerId:T,branches:u=[],onEvent:_,isEOV:N=()=>!1,isDisabled:B=()=>!1})=>{let M=gi(f,N()),tt={timestamp:1/0,priority:"control",initiator:y,actionType:M.type},Y=B(),W=i.emit.bind(i,v.interactives,{subjectId:y,subjectType:d,subjectName:"control",type:Y?A.actionChoiceCanceled:A.actionChoice,actionType:f.type,payload:p({containerId:T},M.args)});if(Y){W();return}switch(M.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let pt=u.find(Q=>Q.id===M.args.branchId);if(!pt)return;_(M.args.isDetachContainer,I.bind(null,{subjectId:y,subjectName:"control"})),W(),M.args.shouldOpenNow?x({subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{chapterId:pt.chapterId,autoSelect:!1}}):(e.add(b(p({},tt),{action:x.bind(null,{subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{chapterId:pt.chapterId,autoSelect:!1}})})),n==null||n());return}case k.continuePlayback.trim().toLowerCase():{_(M.args.isDetachContainer,I.bind(null,{subjectId:y,subjectName:"control"})),W(),M.args.shouldOpenNow?S({subjectId:y,subjectName:"control",subjectType:d,action:f}):e.add(b(p({},tt),{action:S.bind(null,{subjectId:y,subjectName:"control",subjectType:d,action:f})}));return}case k.openURI.trim().toLowerCase():{_(M.args.isDetachContainer,I.bind(null,{subjectId:y,subjectName:"control"})),W(),M.args.shouldOpenNow?j({subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{URI:f.args.uri}}):(e.add(b(p({},tt),{action:j.bind(null,{subjectId:y,subjectName:"control",subjectType:d,action:M,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:d,endTime:y},branches:T=[],isEOV:u=!1,autoSelected:_=!1})=>{let N=gi(f,u),B={timestamp:!N.args.shouldOpenNow||u?1/0:y,priority:"container",initiator:d,actionType:N.type},M=i.emit.bind(i,v.interactives,{subjectId:d,subjectName:"container",type:A.actionChoice,actionType:N.type,payload:N.args});switch(N.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let tt=T.find(Y=>Y.id===N.args.branchId);if(!tt)return;M(),e.add(b(p({},B),{action:x.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{chapterId:tt.chapterId,autoSelect:_}})})),n==null||n();return}case k.setMaxWeightBranch.trim().toLowerCase():return;case k.setMinWeightBranch.trim().toLowerCase():return;case k.setRandomBranch.trim().toLowerCase():return;case k.setWeightlessRandomBranch.trim().toLowerCase():return;case k.continuePlayback.trim().toLowerCase():{M(),e.add(b(p({},B),{action:S.bind(null,{subjectId:d,subjectName:"container",action:N})}));return}case k.openURI.trim().toLowerCase():{M(),e.add(b(p({},B),{action:j.bind(null,{subjectId:d,subjectName:"container",action:N,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:f,branches:d,isEOV:y=!1}){let T=pi(f.events);if(T){let u=gi(T.action,y);i.emit(v.interactives,{subjectId:f.id,subjectName:"container",type:A.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:y?1/0:f.endTime,priority:"container",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of f.events)o({action:u.action,container:f,branches:d,isEOV:y})}let h=({chapterId:f,action:d,branches:y=[]})=>{let T=i.emit.bind(i,v.interactives,{subjectId:f,subjectName:"chapter",type:A.actionChoice,actionType:d.type,payload:d.args});switch(d.type.trim().toLowerCase()){case k.setNextBranch.trim().toLowerCase():{let u=y.find(_=>_.id===d.args.branchId);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setWeightlessRandomBranch.trim().toLowerCase():{let u=pn(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setRandomBranch.trim().toLowerCase():{let u=un(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMaxWeightBranch.trim().toLowerCase():{let u=dn(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.setMinWeightBranch.trim().toLowerCase():{let u=hn(y);return u!=null&&u.chapterId?(T(),x.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case k.continuePlayback.trim().toLowerCase():return T(),S.bind(null,{subjectId:f,subjectName:"chapter",action:d});case k.openURI.trim().toLowerCase():return T(),j.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{URI:d.args.uri}});default:console.error("Unexpected chapter event"),i.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function C(f){let d=pi(f.events);if(d){if(nt(f))return;i.emit(v.interactives,{subjectId:f.id,subjectName:"chapter",type:A.actionChoice,actionType:d.action.type,payload:d.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:k.expect,action:E.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(y=>{let T=h({chapterId:f.id,action:y.action,branches:f.branches});T&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:y.action.type,action:T})})}let E=({subjectId:f,subjectName:d,action:y})=>{var T;t.pause(),i.emit(v.interactives,{subjectId:f,subjectName:d,type:A.actionExecution,actionType:(T=y==null?void 0:y.type)!=null?T:k.expect})},I=({subjectId:f,subjectName:d})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(v.interactives,{subjectId:f,subjectName:d,type:A.actionExecution,actionType:"after-expect"})},S=({subjectId:f,subjectName:d,subjectType:y,action:T})=>{i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type})},x=({subjectId:f,subjectName:d,subjectType:y,action:T,payload:u})=>{u.behaviour="change-chapter",i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type,payload:u})},R=({subjectId:f,subjectName:d,subjectType:y,action:T,payload:u})=>{u.behaviour="change-manifest",i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type,payload:u})},j=({subjectId:f,subjectName:d,subjectType:y,action:T,payload:u})=>{if(!u.URI)return;let _=window.open(u.URI,"_blank","noopener,noreferrer");_&&(_.opener=null),i.emit(v.interactives,{subjectId:f,subjectName:d,subjectType:y,type:A.actionExecution,actionType:T.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:h,onExpectEvent:E,expectEventHandler:I,setManifestChapterEvents:C,setManifestContainerEvents:c,stopExpect:s,state:r}};import{Subscription as ps,ValueSubject as qt}from"@vkontakte/videoplayer-shared";var bi=(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]=mn(s)}return e[n]}).filter(Boolean)},ls=i=>{for(let t of i.variants)if(hs(t)&&"payload"in t)return t.payload.id},hs=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",mn=i=>{let t=ls(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},ds=(i,t)=>{for(let e of i.media.videos)if(t===mn(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},yn=(i,t)=>i.reduce((e,n)=>{let r=ds(t,n);return r?[...e,r]:e},[]);var st,It,xt,J,_e,rt,at,et,Tt,jt,Pt,Zt=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new qt([]),hasPrevChapter$:new qt(!1),prevChapter$:new qt(null),isInitialChapter$:new qt(!1),isGoBackLimited$:new qt(!1)};g(this,st,null);g(this,It,void 0);g(this,xt,!1);g(this,J,null);g(this,_e,null);g(this,rt,null);g(this,at,null);g(this,et,null);g(this,Tt,new ps);g(this,jt,!1);g(this,Pt,0);var l,o,c;m(this,rt,e),m(this,et,t),m(this,at,n),m(this,st,r),m(this,It,s),(l=this.state)!=null&&l.history$&&a(this,Tt)&&((c=a(this,Tt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(h=>{var C,E,I,S,x,R;(C=this.state)==null||C.prevChapter$.next(h.at(-2)||null),(E=this.state)==null||E.hasPrevChapter$.next(h.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((S=(I=a(this,J))==null?void 0:I.metadata)==null?void 0:S.initChapterId)),(R=this.state)==null||R.isGoBackLimited$.next(a(this,Pt)===a(this,It).maxLength-1)})))}setManifest(t){return V(this,null,function*(){!a(this,at)||!a(this,et)||(m(this,J,t),yield this.getProjectHistory(),yield a(this,at).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,xt)||(m(this,xt,!0),a(this,et).emit(v.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,xt)}updateHistory(t,e=!0){return V(this,null,function*(){var o,c;if(!a(this,J))return;a(this,jt)?(m(this,jt,!1),Ni(this,Pt)._++):m(this,Pt,0);let n=a(this,J),r=t.length-a(this,It).maxLength,s=r>0?t.slice(r):t,l=bi(s,n);if(m(this,_e,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,st)||!a(this,rt)))try{yield a(this,st).save(a(this,rt),l)}catch(h){(c=a(this,et))==null||c.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Unable to save interactive history"))}})}goBack(){return V(this,null,function*(){var n;if(!this.state||!a(this,at))return(n=a(this,et))==null?void 0:n.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));m(this,jt,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),yield a(this,at).setChapter({chapterId:e})})}getProjectHistory(){return V(this,null,function*(){var r,s;if(!a(this,J)||!a(this,rt))return;let t=a(this,J),e=[this.getInitialVideoId()];if(a(this,st))try{let l=yield a(this,st).get(a(this,rt));l.length&&(e=l)}catch(l){(r=a(this,et))==null||r.emit(v.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Error while trying to fetch data"))}let n=yn(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,It).initChapterId||((n=a(this,J))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,J)){let t=this.getInitialChapterId();return bi([t],a(this,J)).pop()}return null}destroy(){var t,e;this.state=null,m(this,rt,null),m(this,st,null),m(this,at,null),(t=a(this,Tt))==null||t.unsubscribe(),m(this,Tt,null),m(this,xt,!1),(e=a(this,et))==null||e.emit(v.historyDestroyed),m(this,et,null)}};st=new WeakMap,It=new WeakMap,xt=new WeakMap,J=new WeakMap,_e=new WeakMap,rt=new WeakMap,at=new WeakMap,et=new WeakMap,Tt=new WeakMap,jt=new WeakMap,Pt=new WeakMap;var Ae,gn,Yt,Le,vn,ot=class ot{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=P(s=ot,Ae,gn).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}};Ae=new WeakSet,gn=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(",")),P(n=ot,Le,vn).call(n,t)?e:e.capture||!1}},Yt=new WeakMap,Le=new WeakSet,vn=function(t){let e=a(ot,Yt);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}m(ot,Yt,e)}return e||!1},g(ot,Ae),g(ot,Le),g(ot,Yt,void 0);var Me=ot;var Ne=class{constructor(){this.bindingMap=new Xt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Me(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 ke=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))}updateCanvasDimensions(t,e=!1){return V(this,null,function*(){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=yield this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n})}save(){return V(this,null,function*(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,yield 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 je=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;