@vkontakte/videoplayer-interactive 1.0.14-dev.d69cc93b.0 → 1.0.14-dev.e3975615.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.14-dev.d69cc93b.0
3
- * Fri, 02 Aug 2024 12:53:24 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.14-dev.e3975615.0
3
+ * Tue, 13 Aug 2024 12:38:03 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-14/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,Ye=Object.prototype.hasOwnProperty,ji=Object.prototype.propertyIsEnumerable;var Ze=(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={}))Ye.call(t,e)&&Ze(i,e,t[e]);if(ce)for(var e of ce(t))ji.call(t,e)&&Ze(i,e,t[e]);return i},b=(i,t)=>Dn(i,Gn(t));var X=(i,t)=>{var e={};for(var n in i)Ye.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))!Ye.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)=>(Ze(i,typeof t!="symbol"?t+"":t,e),e),Je=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Je(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)=>(Je(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)=>(Je(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:()=>w,EVENT_NAMES:()=>y,INTERACTIVE_CLICK_ACTIONS:()=>Te,Interactives:()=>ne,ManifestController:()=>xt,SDKInfo:()=>Es,chapterIdsToVKVideoIds:()=>ke,compareVersions:()=>st,getChapterIdByVkVideoId:()=>Vn,getVKVideoIdByMedia:()=>Ii,getVideoRawIdByMedia:()=>Sn,graphEventTypes:()=>Pt,hasEndTemplate:()=>qt,interactivesEventTypes:()=>A,isLastChapter:()=>nt,isSupportedManifest:()=>Kt,isVKVariantItem:()=>wn,utils:()=>$n,vkVideoIdsToChapterIds:()=>xi});module.exports=Kn(Is);var $i="1.0.14-dev.d69cc93b.0";function ti(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=ti((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,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 ${ti((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})`},Mt=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var ei="int",Lt={AREA:`${ei}_area`,TEXT:`${ei}_text`,BUTTON:`${ei}_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 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("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}),Mt({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 ni(i)},ni=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 Mt({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 si(i)},si=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 Mt({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 ri=class{constructor(t){this.layout=t}},Ui=i=>{if(i.type.trim().toLowerCase()==="relative")return new Gt(i)},Gt=class extends ri{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 ai(i,t)},ai=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 oi=i=>xe(i)&&!isNaN(i);var Et=i=>zt(i)&&Object.keys(i).length===0,ci=i=>Ie(i)&&!i.length;var Wt=(i,t)=>Ee(i)&&(t?i.trim():i).length;var li=window.navigator.userAgent.toLowerCase(),dr=/ipad|iphone|ipod/.test(li),Qi=/mobi/i.test(li),pr=li.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 hi=()=>{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 S=!!I.endTime,x=[ts];switch(E){case"await":S?x=[]:h=[];break;case"default":{let R={type:"onSuspense",action:{type:Zi.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:Zi[E],args:{}}};S?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(_=>{var f=_,{subtype:S,type:x}=f,R=X(f,["subtype","type"]);return b(p({},R),{type:S!=null?S: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}],di=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"}),j=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)},Se=i=>i.type===sn.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," ")}`}};$(w,"Severity",{RECOVERABLE:1,CRITICAL:2}),$(w,"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 we=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 dn=require("@vkontakte/videoplayer-shared");var Ve=class{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!=null?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!=null?n:[]}}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 Re(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,Re.name,"Could not find media"),actions:i})}}return b(p({},n),{errors:Xt(t,Re.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=di(t);return n.media=ls(n.media,e),delete n.metadata.media,n})}function _e(i,t){return i.find(e=>e.id===t)}function pi(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 ui(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}),Ae=i=>Ie(i)&&!ci(i),nt=i=>i.order==="end",qt=i=>Ie(i.containers)&&!ci(i.containers)&&nt(i),cn=(i,t)=>{var n;let e=i*1e3;return Ae(t.controls)&&e<((n=t.startTime)!=null?n:0)},fi=(i,t)=>{var n,r;let e=i*1e3;return Ae(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,Me=i=>ps(i)&&Se(i[0]);var ln=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(p(p({},n[t]),e[t])),hn=(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 Ve{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new dn.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",Re({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:pi,getChapter:_e,getMedia:ui,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=_e(this.manifest.chapters,t);if(e){let n=ui(this.manifest.media,e.videoId),r=pi(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=_e(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 un=require("@vkontakte/videoplayer-core"),fn=require("@vkontakte/videoplayer-shared");var pn=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"},A={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 k;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let M=((k=t.map.get(d))!=null?k:{})[g];if(M){s=p({chapterId:T,listId:d,itemId:g},M);let F=s.player;n=F.info.currentQuality$.subscribe(L=>{if(!(!L||!F.info.position$.getValue())){e=L;for(let et of t.map)Object.values(et[1]).forEach(({player:J})=>{F.info.isAutoQualityEnabled$.getValue()||Zt(J,L)})}}),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 k=new Set;for(let F of M)k.has(F.media.id)||(yield x({media:F.media,chapterId:F.chapter.id,setAsActive:!1,title:F.chapter.label}),k.add(F.media.id))}})}function S(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(),k=s.player.info.isAutoQualityEnabled$.getValue(),F=s.player.info.volume$.getValue(),L=s.player.info.currentPlaybackRate$.getValue(),et=!k,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(L))}else t.removePlayer(Q[0]);J||(yield x({media:g,chapterId:d,setAsActive:!0,playbackRate:L}),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:k,title:F,playbackRate:L}){var Ai,Mi,Li,Ni,ki;let J=Math.random().toString(),Q=document.createElement("div");h.append(Q);let ut=(Ai=s==null?void 0:s.player)==null?void 0:Ai.info.isAutoQualityEnabled$.getValue(),K;if((Mi=o==null?void 0:o.options)!=null&&Mi.vkVideoLoader){let oe=pn(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,k).sources}),{title:F,failoverHosts:(K==null?void 0:K.failoverHosts)||[]}),bt=new un.Player(Bn);bt.initVideo(Ri);let _i=new fn.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),L&&bt.setPlaybackRate(L)}));let At=t.createPlayer({listId:d.id,itemId:J,player:bt,container:Q,sources:gi(d,k).sources,config:Ri,subscription:_i});return u&&E(d.id,At.itemId,g),M&&At.player.play(),T&&!M&&At.player.prepare(),r.emit(Yt.playerCreated,At.player),{player:At.player,config:At.config}})}function R(){_(),o=null}function _(){o==null||o.off(y.chapterChanged,S),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");_(),h=d;let{media:T,chapter:u}=o.getCurrentChapter();if(T){o.on(y.chapterChanged,S);let{player:M,config:k}=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:k}}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 mn=require("@vkontakte/videoplayer-shared");var Le=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:A.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:A.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:A.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:A.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:A.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:A.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 mn.Subscription,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&Me(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:A.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:A.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})}};var yn=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!Se(c));if(Ae(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 _=t[R];if(x.push(..._.subjects),_.range[0]<I&&(I=_.range[0]),_.range[1]>E&&(E=_.range[1]),c[0]>=_.range[0]&&c[1]<=_.range[1])return t[R].subjects.push(h),t;c[0]<_.range[0]&&c[1]>_.range[0]&&(C.push(R),S=S.concat(_.subjects)),c[0]>=_.range[0]&&c[0]<=_.range[1]&&(C.push(R),S=S.concat(_.subjects),c[0]=_.range[0]),c[1]>=_.range[0]&&c[1]<=_.range[1]&&(C.push(R),S=S.concat(_.subjects),c[1]=_.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]);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(oi(o)){let E=(C=i[o])!=null?C:null;if(E&&Wt(c,!0)){let I={},S=E[c];if(S&&(I=p(p({},I),S)),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(oi(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 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 fs=[j.expect,j.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,k,F;let g=Ne((M=r.get({timestamp:d,priority:"control"}))!=null?M:{}),T=Ne((k=r.get({timestamp:d,priority:"container"}))!=null?k:{}),u=Ne((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([...Ne((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},_=d=>{d.priority==="container"&&n.resetCalled(d.timestamp),r.remove(d)},f=()=>{n.release(),r.removeAll()};return{setPlayer:R,add:o,remove:_,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 Ne(i){return Object.values(i).flat().sort(t=>t.actionType===j.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:k=()=>!1,isDisabled:F=()=>!1})=>{let L=Ci(f,k()),et={timestamp:1/0,priority:"control",initiator:g,actionType:L.type},J=F(),Q=i.emit.bind(i,y.interactives,{subjectId:g,subjectType:d,subjectName:"control",type:J?A.actionChoiceCanceled:A.actionChoice,actionType:f.type,payload:p({containerId:T},L.args)});if(J){Q();return}switch(L.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{let ut=u.find(K=>K.id===L.args.branchId);if(!ut)return;M(L.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),L.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{chapterId:ut.chapterId,autoSelect:!1}}):(e.add(b(p({},et),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{chapterId:ut.chapterId,autoSelect:!1}})})),n==null||n());return}case j.continuePlayback.trim().toLowerCase():{M(L.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),L.args.shouldOpenNow?S({subjectId:g,subjectName:"control",subjectType:d,action:f}):e.add(b(p({},et),{action:S.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:f})}));return}case j.openURI.trim().toLowerCase():{M(L.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),L.args.shouldOpenNow?_({subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{URI:f.args.uri}}):(e.add(b(p({},et),{action:_.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:d,endTime:g},branches:T=[],isEOV:u=!1,autoSelected:M=!1})=>{let k=Ci(f,u),F={timestamp:!k.args.shouldOpenNow||u?1/0:g,priority:"container",initiator:d,actionType:k.type},L=i.emit.bind(i,y.interactives,{subjectId:d,subjectName:"container",type:A.actionChoice,actionType:k.type,payload:k.args});switch(k.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{let et=T.find(J=>J.id===k.args.branchId);if(!et)return;L(),e.add(b(p({},F),{action:x.bind(null,{subjectId:d,subjectName:"container",action:k,payload:{chapterId:et.chapterId,autoSelect:M}})})),n==null||n();return}case j.setMaxWeightBranch.trim().toLowerCase():return;case j.setMinWeightBranch.trim().toLowerCase():return;case j.setRandomBranch.trim().toLowerCase():return;case j.setWeightlessRandomBranch.trim().toLowerCase():return;case j.continuePlayback.trim().toLowerCase():{L(),e.add(b(p({},F),{action:S.bind(null,{subjectId:d,subjectName:"container",action:k})}));return}case j.openURI.trim().toLowerCase():{L(),e.add(b(p({},F),{action:_.bind(null,{subjectId:d,subjectName:"container",action:k,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(y.errors,new w(w.Severity.RECOVERABLE,w.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:A.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:g?1/0:f.endTime,priority:"container",initiator:f.id,actionType:j.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:A.actionChoice,actionType:d.type,payload:d.args});switch(d.type.trim().toLowerCase()){case j.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 j.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 j.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 j.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 j.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 j.continuePlayback.trim().toLowerCase():return T(),S.bind(null,{subjectId:f,subjectName:"chapter",action:d});case j.openURI.trim().toLowerCase():return T(),_.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{URI:d.args.uri}});default:console.error("Unexpected chapter event"),i.emit(y.errors,new w(w.Severity.RECOVERABLE,w.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:A.actionChoice,actionType:d.action.type,payload:d.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:j.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:A.actionExecution,actionType:(T=g==null?void 0:g.type)!=null?T:j.expect})},I=({subjectId:f,subjectName:d})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(y.interactives,{subjectId:f,subjectName:d,type:A.actionExecution,actionType:"after-expect"})},S=({subjectId:f,subjectName:d,subjectType:g,action:T})=>{i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:A.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:A.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:A.actionExecution,actionType:T.type,payload:u})},_=({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:A.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 ke=(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,je,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,je,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,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,tt))==null?void 0:I.metadata)==null?void 0:S.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=ke(s,n);if(m(this,je,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 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,ot))return(n=a(this,it))==null?void 0:n.emit(y.errors,new w(w.Severity.RECOVERABLE,w.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 w(w.Severity.RECOVERABLE,w.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 ke([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,je=new WeakMap,at=new WeakMap,ot=new WeakMap,it=new WeakMap,wt=new WeakMap,Ot=new WeakMap,$t=new WeakMap;var Oe,Rn,ee,$e,_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,Oe,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}};Oe=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,$e,_n).call(n,t)?e:e.capture||!1}},ee=new WeakMap,$e=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,Oe),v(ct,$e),v(ct,ee,void 0);var Pe=ct;var Be=class{constructor(){this.bindingMap=new Jt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Pe(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 Fe=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 De=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 On=Object.create;var Ht=Object.defineProperty,Bn=Object.defineProperties,Fn=Object.getOwnPropertyDescriptor,Dn=Object.getOwnPropertyDescriptors,Hn=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,Gn=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty,ki=Object.prototype.propertyIsEnumerable;var Ze=(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={}))Ye.call(t,e)&&Ze(i,e,t[e]);if(ce)for(var e of ce(t))ki.call(t,e)&&Ze(i,e,t[e]);return i},b=(i,t)=>Bn(i,Dn(t));var X=(i,t)=>{var e={};for(var n in i)Ye.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&&ki.call(i,n)&&(e[n]=i[n]);return e};var Un=(i,t)=>{for(var e in t)Ht(i,e,{get:t[e],enumerable:!0})},ji=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Hn(t))!Ye.call(i,r)&&r!==e&&Ht(i,r,{get:()=>t[r],enumerable:!(n=Fn(t,r))||n.enumerable});return i};var zn=(i,t,e)=>(e=i!=null?On(Gn(i)):{},ji(t||!i||!i.__esModule?Ht(e,"default",{value:i,enumerable:!0}):e,i)),Wn=i=>ji(Ht({},"__esModule",{value:!0}),i);var $=(i,t,e)=>(Ze(i,typeof t!="symbol"?t+"":t,e),e),Je=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(Je(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)=>(Je(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Pi=(i,t,e,n)=>({set _(r){m(i,t,r,e)},get _(){return a(i,t,n)}}),P=(i,t,e)=>(Je(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 bs={};Un(bs,{CustomError:()=>w,EVENT_NAMES:()=>y,INTERACTIVE_CLICK_ACTIONS:()=>Te,Interactives:()=>ne,ManifestController:()=>xt,SDKInfo:()=>vs,chapterIdsToVKVideoIds:()=>ke,compareVersions:()=>st,getChapterIdByVkVideoId:()=>Sn,getVKVideoIdByMedia:()=>Ei,getVideoRawIdByMedia:()=>xn,graphEventTypes:()=>Pt,hasEndTemplate:()=>qt,interactivesEventTypes:()=>A,isLastChapter:()=>nt,isSupportedManifest:()=>Kt,isVKVariantItem:()=>Tn,utils:()=>Pn,vkVideoIdsToChapterIds:()=>Ii});module.exports=Wn(bs);var $i="1.0.14-dev.e3975615.0";function ti(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",Qn="SDK_NAME-controls-container",le=()=>document.querySelector(`.${Qn}`),Di=.4,q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Oi={top:"flex-start",bottom:"flex-end",center:"center"},Bi={start:"flex-start",end:"flex-end",center:"center"},Fi={start:"left",end:"right",center:"center"},he=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=Oi[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:Oi.center,i.style.justifyContent=(s=Bi[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Bi.center,i.style.textAlign=(o=Fi[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Fi.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=ti((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,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 ${ti((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})`},Mt=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var ei="int",Lt={AREA:`${ei}_area`,TEXT:`${ei}_text`,BUTTON:`${ei}_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 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("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}),Mt({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 ni(i)},ni=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 Mt({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 Hi=i=>{if(i.type.trim().toLowerCase()==="text")return new si(i)},si=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 Mt({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 ri=class{constructor(t){this.layout=t}},Gi=i=>{if(i.type.trim().toLowerCase()==="relative")return new Gt(i)},Gt=class extends ri{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,Ui,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,Ui).call(this)},ve=new WeakSet,Ui=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 ai(i,t)},ai=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",Hi),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=Di,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 B=require("@vkontakte/videoplayer-shared");var Ki=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),zi=i=>Ct(i,Ut.Function);var oi=i=>xe(i)&&!isNaN(i);var Et=i=>zt(i)&&Object.keys(i).length===0,ci=i=>Ie(i)&&!i.length;var Wt=(i,t)=>Ee(i)&&(t?i.trim():i).length;var Wi="video_interactive",Qi="videoint";var Kn=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,Ki.loadVKLangPack)(this.lang,Wi,Qi)}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=Xn(t),this.resizeObserver=new ResizeObserver(Ce(this.onResize,Kn)),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 Xn(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 li=()=>{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 qi=require("uuid");var qn="3.1",Xi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Zn={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Zi=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 S=!!I.endTime,x=[Zn];switch(E){case"await":S?x=[]:h=[];break;case"default":{let R={type:"onSuspense",action:{type:Xi.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:Xi[E],args:{}}};S?x=[R]:h=[R];break}}for(let R of I.controls)C.push(b(p({},I),{controls:[p({},R)],id:(0,qi.v4)(),events:x}))}t.push(b(p({},l),{containers:C,events:h,branches:c}))}return i.metadata.version=qn,i.metadata.updated=new Date().toISOString(),b(p({},i),{chapters:t})};var Yn="3.2",Yi=i=>{if(!i.media){let t=i.metadata,{media:e}=t,n=X(t,["media"]);return b(p({},i),{metadata:b(p({},n),{version:Yn}),media:e})}return i};var Jn="3.3",ts=(i=[])=>({edit:{chapters:i},view:{}}),Ji={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},tn=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(_=>{var f=_,{subtype:S,type:x}=f,R=X(f,["subtype","type"]);return b(p({},R),{type:S!=null?S:x})}),events:(I=E.events)!=null&&I.length?E.events:[Ji]})});t.push(b(p({id:l},h),{containers:C,events:(r=h.events)!=null&&r.length?h.events:[Ji]})),e.push({id:l,x:o,y:c})}return b(p({},i),{chapters:t,graph:ts(e),metadata:b(p({},i.metadata),{version:Jn})})};var es=[{version:"3.0",migrate:Zi},{version:"3.1",migrate:Yi},{version:"3.2",migrate:tn}],hi=i=>es.reduce((t,e)=>st(t.metadata.version,e.version)?t:e.migrate(t),i);var kr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),en=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),jr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),j=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 nn={metadata:"Object",chapters:"Array"},is="3.0.0",ns="3.3.0",Kt=i=>{let t=st(i,is);return t===-1?!1:t===0?!0:st(i,ns)!==1},sn=i=>{if(!zt(i))return!1;for(let t in nn)if(!i[t]||!Ct(i[t],nn[t]))return!1;return Kt(i.metadata.version)},Se=i=>i.type===en.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," ")}`}};$(w,"Severity",{RECOVERABLE:1,CRITICAL:2}),$(w,"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 we=class{constructor(t){$(this,"addFn",(t,e=!1)=>{zi(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 ln=require("@vkontakte/videoplayer-shared");var Ve=class{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!=null?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!=null?n:[]}}exec(t,e){return V(this,null,function*(){return ss(...this.loaders[t])(e)})}};function ss(...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 Re(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,Re.name,"Could not find media"),actions:i})}}return b(p({},n),{errors:Xt(t,Re.name,"Could not find chapter"),actions:i})}var rs=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(!sn(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 cs(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function rn(i){return V(this,null,function*(){let{manifest:t,manifestURL:e}=yield rs(i),n=hi(t);return n.media=as(n.media,e),delete n.metadata.media,n})}function _e(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 as(i,t){return b(p({},i),{videos:i.videos.map(e=>b(p({},e),{variants:e.variants.map(n=>{let r=os(n.url,t);return b(p({},n),{url:r||n.url})})}))})}function os(i,t){try{return new URL(i,t).href}catch(e){return""}}function cs(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}),Ae=i=>Ie(i)&&!ci(i),nt=i=>i.order==="end",qt=i=>Ie(i.containers)&&!ci(i.containers)&&nt(i),an=(i,t)=>{var n;let e=i*1e3;return Ae(t.controls)&&e<((n=t.startTime)!=null?n:0)},ui=(i,t)=>{var n,r;let e=i*1e3;return Ae(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"),fi=i=>i.find(t=>t.action.type==="expect"),ls=i=>(i==null?void 0:i.length)===1,Me=i=>ls(i)&&Se(i[0]);var on=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(p(p({},n[t]),e[t])),cn=(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 Ve{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new ln.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 rn((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",Re({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:di,getChapter:_e,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=_e(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=_e(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 dn=require("@vkontakte/videoplayer-core"),pn=require("@vkontakte/videoplayer-shared");var hn=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"},A={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function mi(){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 yi(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"},hs=2;function gi(i){let t=mi(),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 k;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let M=((k=t.map.get(d))!=null?k:{})[g];if(M){s=p({chapterId:T,listId:d,itemId:g},M);let F=s.player;n=F.info.currentQuality$.subscribe(L=>{if(!(!L||!F.info.position$.getValue())){e=L;for(let et of t.map)Object.values(et[1]).forEach(({player:J})=>{F.info.isAutoQualityEnabled$.getValue()||Zt(J,L)})}}),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 k=new Set;for(let F of M)k.has(F.media.id)||(yield x({media:F.media,chapterId:F.chapter.id,setAsActive:!1,title:F.chapter.label}),k.add(F.media.id))}})}function S(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(),k=s.player.info.isAutoQualityEnabled$.getValue(),F=s.player.info.volume$.getValue(),L=s.player.info.currentPlaybackRate$.getValue(),et=!k,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<hs||(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(L))}else t.removePlayer(Q[0]);J||(yield x({media:g,chapterId:d,setAsActive:!0,playbackRate:L}),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:k,title:F,playbackRate:L}){var _i,Ai,Mi,Li,Ni;let J=Math.random().toString(),Q=document.createElement("div");h.append(Q);let ut=(_i=s==null?void 0:s.player)==null?void 0:_i.info.isAutoQualityEnabled$.getValue(),K;if((Ai=o==null?void 0:o.options)!=null&&Ai.vkVideoLoader){let oe=hn(d);oe.length&&(K=yield o.options.vkVideoLoader(...oe))}let wi=((Mi=o==null?void 0:o.options)==null?void 0:Mi.coreConfig)||{},$n=b(p({},wi),{configName:[...(Li=wi.configName)!=null?Li:[],"interactive"]}),Vi=b(p({container:Q},((Ni=K==null?void 0:K.videos)==null?void 0:Ni[0])||{sources:yi(d,k).sources}),{title:F,failoverHosts:(K==null?void 0:K.failoverHosts)||[]}),bt=new dn.Player($n);bt.initVideo(Vi);let Ri=new pn.Subscription;Ri.add(bt.info.position$.subscribe(function(oe){I(J,bt.info.duration$.getValue(),oe)})).add(bt.events.canplay$.subscribe(function(){ut||Zt(bt,e),L&&bt.setPlaybackRate(L)}));let At=t.createPlayer({listId:d.id,itemId:J,player:bt,container:Q,sources:yi(d,k).sources,config:Vi,subscription:Ri});return u&&E(d.id,At.itemId,g),M&&At.player.play(),T&&!M&&At.player.prepare(),r.emit(Yt.playerCreated,At.player),{player:At.player,config:At.config}})}function R(){_(),o=null}function _(){o==null||o.off(y.chapterChanged,S),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");_(),h=d;let{media:T,chapter:u}=o.getCurrentChapter();if(T){o.on(y.chapterChanged,S);let{player:M,config:k}=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:k}}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 un=require("@vkontakte/videoplayer-shared");var Le=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:A.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:A.visibility,visibility:!0,isFirst:!1});else{let l=on({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:A.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:A.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:A.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:A.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(an(e,this.container.container))this.gameState!==D.beforeInteractive&&(this.gameState=D.beforeInteractive,this.onBeforeStartTime());else if(ui(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=ui(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 un.Subscription,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&Me(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:A.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:A.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})}};var fn=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!Se(c));if(Ae(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 _=t[R];if(x.push(..._.subjects),_.range[0]<I&&(I=_.range[0]),_.range[1]>E&&(E=_.range[1]),c[0]>=_.range[0]&&c[1]<=_.range[1])return t[R].subjects.push(h),t;c[0]<_.range[0]&&c[1]>_.range[0]&&(C.push(R),S=S.concat(_.subjects)),c[0]>=_.range[0]&&c[0]<=_.range[1]&&(C.push(R),S=S.concat(_.subjects),c[0]=_.range[0]),c[1]>=_.range[0]&&c[1]<=_.range[1]&&(C.push(R),S=S.concat(_.subjects),c[1]=_.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]);function mn(){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(oi(o)){let E=(C=i[o])!=null?C:null;if(E&&Wt(c,!0)){let I={},S=E[c];if(S&&(I=p(p({},I),S)),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(oi(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 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 ds=[j.expect,j.setNextBranch],ps=1/0;function vi(i){let t=i,e,n=us(),r=new mn,s,l=()=>{I(),f()},o=d=>{r.add.call(void 0,d),x()},c=(d=[])=>{for(let g of d)if(g.action(),ds.includes(g.actionType))break},h=(d=1/0)=>{var M,k,F;let g=Ne((M=r.get({timestamp:d,priority:"control"}))!=null?M:{}),T=Ne((k=r.get({timestamp:d,priority:"container"}))!=null?k:{}),u=Ne((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([...Ne((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},_=d=>{d.priority==="container"&&n.resetCalled(d.timestamp),r.remove(d)},f=()=>{n.release(),r.removeAll()};return{setPlayer:R,add:o,remove:_,exec:C,execEndOfVideo:E,listen:x,unlisten:I,release:l,containersEventsCallState:n,getPreparedToExecActions:h}}function us(){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:ps,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 Ne(i){return Object.values(i).flat().sort(t=>t.actionType===j.expect?-1:1)}var yn=(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 fs=250;function gn(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}=yn(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()},fs);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 ms=i=>Math.floor(Math.random()*i),vn=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},bn=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 Cn=i=>{let t=i.length,e=ms(t);return i[e]};var En=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 In=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var bi=(i,t=!1)=>b(p({},i),{args:t?p(p({},i.args),In):p(p({},In),i.args)}),Ci=({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:k=()=>!1,isDisabled:F=()=>!1})=>{let L=bi(f,k()),et={timestamp:1/0,priority:"control",initiator:g,actionType:L.type},J=F(),Q=i.emit.bind(i,y.interactives,{subjectId:g,subjectType:d,subjectName:"control",type:J?A.actionChoiceCanceled:A.actionChoice,actionType:f.type,payload:p({containerId:T},L.args)});if(J){Q();return}switch(L.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{let ut=u.find(K=>K.id===L.args.branchId);if(!ut)return;M(L.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),L.args.shouldOpenNow?x({subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{chapterId:ut.chapterId,autoSelect:!1}}):(e.add(b(p({},et),{action:x.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{chapterId:ut.chapterId,autoSelect:!1}})})),n==null||n());return}case j.continuePlayback.trim().toLowerCase():{M(L.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),L.args.shouldOpenNow?S({subjectId:g,subjectName:"control",subjectType:d,action:f}):e.add(b(p({},et),{action:S.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:f})}));return}case j.openURI.trim().toLowerCase():{M(L.args.isDetachContainer,I.bind(null,{subjectId:g,subjectName:"control"})),Q(),L.args.shouldOpenNow?_({subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{URI:f.args.uri}}):(e.add(b(p({},et),{action:_.bind(null,{subjectId:g,subjectName:"control",subjectType:d,action:L,payload:{URI:f.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:f,container:{id:d,endTime:g},branches:T=[],isEOV:u=!1,autoSelected:M=!1})=>{let k=bi(f,u),F={timestamp:!k.args.shouldOpenNow||u?1/0:g,priority:"container",initiator:d,actionType:k.type},L=i.emit.bind(i,y.interactives,{subjectId:d,subjectName:"container",type:A.actionChoice,actionType:k.type,payload:k.args});switch(k.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{let et=T.find(J=>J.id===k.args.branchId);if(!et)return;L(),e.add(b(p({},F),{action:x.bind(null,{subjectId:d,subjectName:"container",action:k,payload:{chapterId:et.chapterId,autoSelect:M}})})),n==null||n();return}case j.setMaxWeightBranch.trim().toLowerCase():return;case j.setMinWeightBranch.trim().toLowerCase():return;case j.setRandomBranch.trim().toLowerCase():return;case j.setWeightlessRandomBranch.trim().toLowerCase():return;case j.continuePlayback.trim().toLowerCase():{L(),e.add(b(p({},F),{action:S.bind(null,{subjectId:d,subjectName:"container",action:k})}));return}case j.openURI.trim().toLowerCase():{L(),e.add(b(p({},F),{action:_.bind(null,{subjectId:d,subjectName:"container",action:k,payload:{URI:f.args.uri}})})),n==null||n();return}default:console.error("Unexpected container event"),i.emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:f,branches:d,isEOV:g=!1}){let T=fi(f.events);if(T){let u=bi(T.action,g);i.emit(y.interactives,{subjectId:f.id,subjectName:"container",type:A.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:g?1/0:f.endTime,priority:"container",initiator:f.id,actionType:j.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:A.actionChoice,actionType:d.type,payload:d.args});switch(d.type.trim().toLowerCase()){case j.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 j.setWeightlessRandomBranch.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 j.setRandomBranch.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 j.setMaxWeightBranch.trim().toLowerCase():{let u=bn(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 j.setMinWeightBranch.trim().toLowerCase():{let u=vn(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 j.continuePlayback.trim().toLowerCase():return T(),S.bind(null,{subjectId:f,subjectName:"chapter",action:d});case j.openURI.trim().toLowerCase():return T(),_.bind(null,{subjectId:f,subjectName:"chapter",action:d,payload:{URI:d.args.uri}});default:console.error("Unexpected chapter event"),i.emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function C(f){let d=fi(f.events);if(d){if(nt(f))return;i.emit(y.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:j.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:A.actionExecution,actionType:(T=g==null?void 0:g.type)!=null?T:j.expect})},I=({subjectId:f,subjectName:d})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(y.interactives,{subjectId:f,subjectName:d,type:A.actionExecution,actionType:"after-expect"})},S=({subjectId:f,subjectName:d,subjectType:g,action:T})=>{i.emit(y.interactives,{subjectId:f,subjectName:d,subjectType:g,type:A.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:A.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:A.actionExecution,actionType:T.type,payload:u})},_=({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:A.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 ke=(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]=Ei(s)}return e[n]}).filter(Boolean)},xn=i=>{for(let t of i.variants)if(Tn(t)&&"payload"in t)return t.payload.id},Tn=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Ei=i=>{let t=xn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},Sn=(i,t)=>{for(let e of i.media.videos)if(t===Ei(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},Ii=(i,t)=>i.reduce((e,n)=>{let r=Sn(t,n);return r?[...e,r]:e},[]);var rt,Tt,St,tt,je,at,ot,it,wt,$t,Ot,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,je,null);v(this,at,null);v(this,ot,null);v(this,it,null);v(this,wt,new mt.Subscription);v(this,$t,!1);v(this,Ot,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,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,tt))==null?void 0:I.metadata)==null?void 0:S.initChapterId)),(R=this.state)==null||R.isGoBackLimited$.next(a(this,Ot)===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,$t)?(m(this,$t,!1),Pi(this,Ot)._++):m(this,Ot,0);let n=a(this,tt),r=t.length-a(this,Tt).maxLength,s=r>0?t.slice(r):t,l=ke(s,n);if(m(this,je,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 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,ot))return(n=a(this,it))==null?void 0:n.emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));m(this,$t,!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 w(w.Severity.RECOVERABLE,w.Category.HISTORY,"Error while trying to fetch data"))}let n=Ii(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 ke([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,je=new WeakMap,at=new WeakMap,ot=new WeakMap,it=new WeakMap,wt=new WeakMap,$t=new WeakMap,Ot=new WeakMap;var $e,wn,ee,Oe,Vn,ct=class ct{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=P(s=ct,$e,wn).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}};$e=new WeakSet,wn=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,Oe,Vn).call(n,t)?e:e.capture||!1}},ee=new WeakMap,Oe=new WeakSet,Vn=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,$e),v(ct,Oe),v(ct,ee,void 0);var Pe=ct;var Be=class{constructor(){this.bindingMap=new Jt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Pe(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 Fe=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 De=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;
@@ -16,8 +16,8 @@
16
16
  top: 50%;
17
17
  left: 50%;
18
18
  transform: translate(-50%, -50%);
19
- `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}updateCanvasDimensions(t=!1){return V(this,null,function*(){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);let e=getComputedStyle(this.rootElement),n={width:parseInt(e.getPropertyValue("--interactive-content-width"),10),height:parseInt(e.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,t)}catch(r){this._onError(r)}})}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(t){return this.currentVideoDurationMs&&t>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(t){if(this.currentChapter)return this.currentChapter.containers.some(e=>{var n,r,s;return((n=e.controls)==null?void 0:n.length)&&t>=((r=e.startTime)!=null?r:0)&&t<=Math.min((s=e.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(t){var e,n;(n=(e=this._callbacks)==null?void 0:e.onError)==null||n.call(e,t)}};function An(i=0){return new Promise(t=>{setTimeout(()=>{t(0)},i)})}var Mn=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,historyParams:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}}),lt=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function Cs(){let i=document.createElement("div");return i.style.cssText=`
19
+ `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}updateCanvasDimensions(t=!1){return V(this,null,function*(){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);let e=getComputedStyle(this.rootElement),n={width:parseInt(e.getPropertyValue("--interactive-content-width"),10),height:parseInt(e.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,t)}catch(r){this._onError(r)}})}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(t){return this.currentVideoDurationMs&&t>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(t){if(this.currentChapter)return this.currentChapter.containers.some(e=>{var n,r,s;return((n=e.controls)==null?void 0:n.length)&&t>=((r=e.startTime)!=null?r:0)&&t<=Math.min((s=e.endTime)!=null?s:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(t){var e,n;(n=(e=this._callbacks)==null?void 0:e.onError)==null||n.call(e,t)}};function Rn(i=0){return new Promise(t=>{setTimeout(()=>{t(0)},i)})}var _n=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,historyParams:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}}),lt=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function gs(){let i=document.createElement("div");return i.style.cssText=`
20
20
  position: absolute;
21
21
  top: 0;
22
22
  left: 0;
23
- `,i}var yt,Z,gt,W,ht,U,Y,dt,B,pt,Bt,z,Ft,H,N,vt,Vt,Ge,Ln,Ue,Nn,Dt,He,wi,ze,We,kn,se,Ti,Rt,_t,ie,Qe,jn,re,Si,Ke,Pn,Xe,On,qe,ae,ne=class{constructor(t){v(this,Ge);v(this,Ue);v(this,Dt);v(this,We);v(this,se);v(this,_t);v(this,Qe);v(this,re);v(this,Ke);v(this,Xe);v(this,yt,null);v(this,Z,null);v(this,gt,null);v(this,W,null);v(this,ht,null);v(this,U,null);v(this,Y,null);v(this,dt,null);v(this,B,null);v(this,pt,new O.ValueSubject(!1));v(this,Bt,new Set);v(this,z,null);v(this,Ft,null);v(this,H,null);v(this,N,null);v(this,vt,hi());v(this,Vt,null);$(this,"state",{prevChapter$:new O.ValueSubject(null),isInitialChapter$:new O.ValueSubject(!1),isEndChapter$:new O.ValueSubject(!1),isInteractiveExpectation$:new O.ValueSubject(!1),calledByInteractive$:new O.ValueSubject(!1),lastChapterChangeWasInitiatedByInteractive$:new O.ValueSubject(!1),disabledControls$:new O.ValueSubject(!1),interactiveRanges$:new O.ValueSubject([]),isInteractiveTime$:new O.ValueSubject(!1)});$(this,"events",{noInteraction$:new O.Subject});$(this,"emitPlayerChanged",t=>{a(this,N).emit(y.playerChanged,t)});v(this,wi,()=>{a(this,Y).fns.forEach(n=>n());let t=this.options.player.info.position$.getValue()*1e3,e=(a(this,B).chapter.containers||[]).filter(n=>n.startTime>=Math.floor(t));for(let n of e){a(this,U).remove({timestamp:1/0,priority:"container",initiator:n.id});for(let r of n.controls)a(this,U).remove({timestamp:1/0,priority:"control",initiator:r.id});a(this,Z).find(r=>r.container.container.id===n.id).reset()}});v(this,ze,()=>{a(this,yt).calc(),a(this,Y).requestAnimation()});v(this,Rt,(t=!0)=>{a(this,Z).forEach(e=>{!t&&e.isPermanentText||(a(this,Y).removeFn(e.whilePlaying),e.destroy())})});v(this,qe,t=>{let{interactiveRanges$:e}=this.state,r=e.getValue().map(s=>b(p({},s),{subjects:s.subjects.filter(l=>l!==t)}));e.next(r)});v(this,ae,()=>{a(this,Vt)&&(clearTimeout(a(this,Vt)),m(this,Vt,null))});var e;this.options=b(p(p({},Mn),t),{config:p(p({},Mn.config),t.config)}),m(this,Z,[]),this.factories=new Map([["choice",be]]),this.rootElement=Cs(),this.options.parentElement.append(this.rootElement),m(this,N,new jt),m(this,ht,new O.Subscription),m(this,gt,new Be),m(this,W,new te({interactiveController:this,globalEventEmitter:a(this,N),videoId:(e=this.options.projectInfo)==null?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&m(this,H,new De({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,N).emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.SEAMLESS,n))})),a(this,gt).listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,gt).listen(this.rootElement,"mouseup",n=>n.stopPropagation()),m(this,B,new xt(this.options.loaders,n=>a(this,N).emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.MANIFEST,n)))),m(this,U,bi(this.options.player)),m(this,Y,new we),m(this,dt,Ei({player:this.options.player,interactiveEvents:a(this,U),globalEventEmitter:a(this,N),removeControllers:a(this,Rt)})),m(this,yt,bn(()=>{var n,r,s;return{player:(n=this.options)==null?void 0:n.player,parentElement:(r=this.options)==null?void 0:r.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,H).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&m(this,z,new Qt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,N).emit(y.graph,{type:Pt.watchAgainClicked,chapterId:n})},onError:n=>a(this,N).emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.LOADERS,{message:n}))})),P(this,Ge,Ln).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=lt.created}getStatEvents(){return{click$:new O.Observable(t=>{a(this,N).on(y.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?"OPEN_GRAPH":"CLOSE_GRAPH"),e==="watchAgainClicked"&&t.next("WATCH_AGAIN")}),a(this,N).on(y.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next("GO_NEXT_BUTTON"),r==="Area"&&t.next("GO_NEXT_AREA"))})}),nextMovie$:new O.Observable(t=>{a(this,N).on(y.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){P(this,Dt,He).call(this),this.options.player=t,a(this,vt).setPlayer(this.options.player),a(this,U)?a(this,U).setPlayer(this.options.player):m(this,U,bi(this.options.player)),m(this,dt,Ei({player:this.options.player,interactiveEvents:a(this,U),globalEventEmitter:a(this,N),removeControllers:()=>a(this,Rt).call(this,!1)})),this.appState===lt.initiated&&(P(this,se,Ti).call(this),P(this,_t,ie).call(this,a(this,B).chapter))}setManifest(t){return V(this,null,function*(){P(this,Dt,He).call(this),this.isFirstChapterFetched=!1;let e=yield a(this,B).setManifest(t);return a(this,z)&&(yield a(this,z).handleManifestChange(e.manifest)),yield a(this,W).setManifest(e.manifest),a(this,N).emit(y.manifestChanged,{manifest:e.manifest}),P(this,_t,ie).call(this,a(this,B).chapter),e.manifest})}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,z))==null||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,z))==null||e.updateVideosInfo(t))}setChapter(){return V(this,arguments,function*({chapterId:t,pushToHistory:e=!0}={}){var o;P(this,Dt,He).call(this),a(this,H)&&this.isFirstChapterFetched&&(a(this,H).draw(),a(this,H).show()),(0,O.getCurrentBrowser)().browser===O.CurrentClientBrowser.Safari&&(yield An(35));let{chapter:r,media:s,graph:l}=yield t?a(this,B).setNext(t):a(this,B).setInitial();return e&&P(this,Xe,On).call(this,r.id),this.state.isInitialChapter$.next(a(this,B).isInitialChapter()),this.state.isEndChapter$.next(a(this,B).isEndChapter()),a(this,z)&&a(this,z).handleChapterChange(l),(o=a(this,H))==null||o.setCurrentChapter(this.getCurrentChapter().chapter),a(this,N).emit(y.chapterChanged,{chapter:r,media:s,graph:l}),P(this,_t,ie).call(this,a(this,B).chapter),m(this,Bt,new Set),this.isFirstChapterFetched=!0,{chapter:r,media:s,graph:l}})}toggleGraphView(t=!0){a(this,z)&&(t?(a(this,z).show(),a(this,pt).next(!1)):(a(this,z).hide(),P(this,re,Si).call(this)),a(this,N).emit(y.graph,{type:Pt.visibility,visibility:t}))}init(){a(this,B).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===lt.created&&(a(this,yt).resizeObserver.observe(this.options.fullscreenTargetElement),P(this,se,Ti).call(this),this.appState=lt.initiated,P(this,_t,ie).call(this,a(this,B).chapter))}deadEndCheck(){var n,r;return!((r=(n=a(this,U))==null?void 0:n.getPreparedToExecActions())!=null?r:[]).some(s=>s.actionType===j.setNextBranch)}allControlsAreRemoved(){return!a(this,Z).some(e=>!e.container.isRemoved)}isEndedExpectation(){var n;if(!((n=this.options)!=null&&n.player)||!a(this,Z))return!1;let t=this.options.player.info.position$.getValue(),e=this.options.player.info.duration$.getValue();return t===e&&a(this,Z).some(r=>{let s=r.container.container;return!s.isRemoved&&s.endTime===null&&It(s.events)})}playPrevChapter(){var t;(t=a(this,W))==null||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,B).manifest){return Kt(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,W).getInitialVideoId(),chapterId:a(this,W).getInitialChapterId()}}getHistoryState(){return a(this,W).state}getIsSeekable(){return a(this,pt)}getInteractiveRanges(){var t;return yn((t=a(this,B).chapter)==null?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,vt).getNextInteractiveTime(t)}getChapterBranches(t){return a(this,B).getBranches(t)}getCurrentChapter(){return a(this,B).getCurrent()}getCurrentManifest(){return a(this,B).manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,N).on(...t),this}off(...t){return a(this,N).off(...t),this}once(...t){return a(this,N).once(...t),this}destroy(){var t,e;a(this,Rt).call(this),m(this,Z,void 0),this.state=void 0,(t=a(this,z))==null||t.destroy(),m(this,z,void 0),a(this,yt).release(),m(this,yt,void 0),m(this,dt,void 0),a(this,Y).release(),m(this,Y,void 0),a(this,U).release(),m(this,U,void 0),a(this,B).release(),m(this,dt,void 0),a(this,gt).release(),m(this,gt,void 0),a(this,ht).unsubscribe(),m(this,ht,void 0),a(this,N).reset(),m(this,N,void 0),(e=a(this,H))==null||e.destroy(),m(this,H,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,W).destroy(),m(this,W,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=lt.destroyed}};yt=new WeakMap,Z=new WeakMap,gt=new WeakMap,W=new WeakMap,ht=new WeakMap,U=new WeakMap,Y=new WeakMap,dt=new WeakMap,B=new WeakMap,pt=new WeakMap,Bt=new WeakMap,z=new WeakMap,Ft=new WeakMap,H=new WeakMap,N=new WeakMap,vt=new WeakMap,Vt=new WeakMap,Ge=new WeakSet,Ln=function(t=!1){a(this,N).on(y.historyInited,r=>V(this,[r],function*({initChapterId:e,videosInfo:n=[]}){t&&(yield P(this,Ue,Nn).call(this,{initialChapter:e,videosInfo:n}))})),a(this,N).on(y.interactives,e=>V(this,null,function*(){var n,r;if(e.type===A.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)==null?void 0:n.behaviour)==="change-chapter"){let{chapterId:l}=e.payload;this.setChapter({chapterId:l})}if(((r=e.payload)==null?void 0:r.behaviour)==="change-manifest"){let{manifestURL:l}=e.payload;this.setManifest(l)}let s=e.type==="action-execution";s&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===A.containerRemoved&&a(this,qe).call(this,e.subjectId)})),a(this,N).on(y.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Ue=new WeakSet,Nn=function(n){return V(this,arguments,function*({source:t,videosInfo:e=[]}){m(this,Ft,vi(this));let r=document.createElement("div");a(this,Ft).on(Yt.activePlayerChanged,this.emitPlayerChanged);let{player:s,config:l}=yield a(this,Ft).init({source:t,initialChapter:a(this,W).getInitialChapterId(),container:r});return this.updateGraphVideosInfo(e),{player:s,config:l}})},Dt=new WeakSet,He=function(){var t;this.appState===lt.ready&&(a(this,Rt).call(this),m(this,Z,[]),a(this,Y).release(),(t=a(this,U))==null||t.release(),this.appState=lt.initiated,a(this,pt).next(!1),a(this,ae).call(this))},wi=new WeakMap,ze=new WeakMap,We=new WeakSet,kn=function(t){(!a(this,z)||a(this,z).isHidden)&&P(this,re,Si).call(this);let e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){let s=r.range.join("-");a(this,Bt).has(s)||(a(this,Bt).add(s),a(this,N).emit(y.interactives,{type:A.rangeEnded,payload:r,visibility:!0}))}},se=new WeakSet,Ti=function(){a(this,ht).unsubscribe(),a(this,ht).add(this.options.player.events.started$.pipe((0,O.once)()).subscribe(a(this,ze))).add(this.options.player.events.playing$.subscribe(a(this,Y).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,Y).cancelAnimation)).add(this.options.player.info.position$.subscribe(P(this,We,kn).bind(this))).add(a(this,B).prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add((0,O.combine)({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,c],subjects:h})=>o<s&&s<c&&h.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?m(this,Vt,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):a(this,ae).call(this))})),this.options.lastFrame&&a(this,ht).add(this.options.player.info.duration$.subscribe(t=>{a(this,H).setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,H).setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,H).reset(),setTimeout(()=>{a(this,H).hide(),a(this,H).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,H).onSeek))},Rt=new WeakMap,_t=new WeakSet,ie=function(t){a(this,B).chapter&&this.appState===lt.initiated&&(a(this,dt).setManifestChapterEvents(t),m(this,Z,P(this,Qe,jn).call(this,t)),a(this,U).containersEventsCallState.setData(t.containers),a(this,vt).setContainers(a(this,Z).map(e=>e.container.container).filter(e=>!Me(e.controls))),this.options.lastFrame&&a(this,Y).addFn(()=>{a(this,H).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=lt.ready)},Qe=new WeakSet,jn=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)==null?void 0:e.reduce((r,s)=>{let l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Le({player:this.options.player,container:o(s,this.rootElement),branches:a(this,B).chapter.branches,selectBranches:a(this,dt),interactiveEvents:a(this,U),globalEventEmitter:a(this,N),ignoreContainerEvent:()=>hn(s,a(this,Z)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,vt).deleteContainer(s.id)}});return a(this,Y).addFn(c.whilePlaying,!0),[...r,c]}return[...r]},[]))!=null?n:[]},re=new WeakSet,Si=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,pt).next(!1);return}let e=a(this,pt).getValue(),n=!!a(this,vt).getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,pt).next(!e)},Ke=new WeakSet,Pn=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Xe=new WeakSet,On=function(t){var o;if(P(this,Ke,Pn).call(this),!a(this,W).inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(o=n&&nt(n)&&qt(n))!=null?o:!1,s=a(this,B).manifest.metadata.initChapterId===t,l=a(this,W).state.history$.getValue();if(s||r&&e){a(this,W).updateHistory([t]);return}l.at(-1)!==t&&a(this,W).updateHistory([...l,t])},qe=new WeakMap,ae=new WeakMap;var $n={Container:kt,createChoiceContainer:be,createAreaControl:fe,createButtonControl:ye,createRelativeLayout:Ui,getRootEl:le,classnamesPrefix:G};var Es={version:$i};
23
+ `,i}var yt,Z,gt,W,ht,U,Y,dt,O,pt,Bt,z,Ft,H,N,vt,Vt,Ge,An,Ue,Mn,Dt,He,Si,ze,We,Ln,se,xi,Rt,_t,ie,Qe,Nn,re,Ti,Ke,kn,Xe,jn,qe,ae,ne=class{constructor(t){v(this,Ge);v(this,Ue);v(this,Dt);v(this,We);v(this,se);v(this,_t);v(this,Qe);v(this,re);v(this,Ke);v(this,Xe);v(this,yt,null);v(this,Z,null);v(this,gt,null);v(this,W,null);v(this,ht,null);v(this,U,null);v(this,Y,null);v(this,dt,null);v(this,O,null);v(this,pt,new B.ValueSubject(!1));v(this,Bt,new Set);v(this,z,null);v(this,Ft,null);v(this,H,null);v(this,N,null);v(this,vt,li());v(this,Vt,null);$(this,"state",{prevChapter$:new B.ValueSubject(null),isInitialChapter$:new B.ValueSubject(!1),isEndChapter$:new B.ValueSubject(!1),isInteractiveExpectation$:new B.ValueSubject(!1),calledByInteractive$:new B.ValueSubject(!1),lastChapterChangeWasInitiatedByInteractive$:new B.ValueSubject(!1),disabledControls$:new B.ValueSubject(!1),interactiveRanges$:new B.ValueSubject([]),isInteractiveTime$:new B.ValueSubject(!1)});$(this,"events",{noInteraction$:new B.Subject});$(this,"emitPlayerChanged",t=>{a(this,N).emit(y.playerChanged,t)});v(this,Si,()=>{a(this,Y).fns.forEach(n=>n());let t=this.options.player.info.position$.getValue()*1e3,e=(a(this,O).chapter.containers||[]).filter(n=>n.startTime>=Math.floor(t));for(let n of e){a(this,U).remove({timestamp:1/0,priority:"container",initiator:n.id});for(let r of n.controls)a(this,U).remove({timestamp:1/0,priority:"control",initiator:r.id});a(this,Z).find(r=>r.container.container.id===n.id).reset()}});v(this,ze,()=>{a(this,yt).calc(),a(this,Y).requestAnimation()});v(this,Rt,(t=!0)=>{a(this,Z).forEach(e=>{!t&&e.isPermanentText||(a(this,Y).removeFn(e.whilePlaying),e.destroy())})});v(this,qe,t=>{let{interactiveRanges$:e}=this.state,r=e.getValue().map(s=>b(p({},s),{subjects:s.subjects.filter(l=>l!==t)}));e.next(r)});v(this,ae,()=>{a(this,Vt)&&(clearTimeout(a(this,Vt)),m(this,Vt,null))});var e;this.options=b(p(p({},_n),t),{config:p(p({},_n.config),t.config)}),m(this,Z,[]),this.factories=new Map([["choice",be]]),this.rootElement=gs(),this.options.parentElement.append(this.rootElement),m(this,N,new jt),m(this,ht,new B.Subscription),m(this,gt,new Be),m(this,W,new te({interactiveController:this,globalEventEmitter:a(this,N),videoId:(e=this.options.projectInfo)==null?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&m(this,H,new De({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,N).emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.SEAMLESS,n))})),a(this,gt).listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,gt).listen(this.rootElement,"mouseup",n=>n.stopPropagation()),m(this,O,new xt(this.options.loaders,n=>a(this,N).emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.MANIFEST,n)))),m(this,U,vi(this.options.player)),m(this,Y,new we),m(this,dt,Ci({player:this.options.player,interactiveEvents:a(this,U),globalEventEmitter:a(this,N),removeControllers:a(this,Rt)})),m(this,yt,gn(()=>{var n,r,s;return{player:(n=this.options)==null?void 0:n.player,parentElement:(r=this.options)==null?void 0:r.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,H).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&m(this,z,new Qt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,N).emit(y.graph,{type:Pt.watchAgainClicked,chapterId:n})},onError:n=>a(this,N).emit(y.errors,new w(w.Severity.RECOVERABLE,w.Category.LOADERS,{message:n}))})),P(this,Ge,An).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=lt.created}getStatEvents(){return{click$:new B.Observable(t=>{a(this,N).on(y.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?"OPEN_GRAPH":"CLOSE_GRAPH"),e==="watchAgainClicked"&&t.next("WATCH_AGAIN")}),a(this,N).on(y.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next("GO_NEXT_BUTTON"),r==="Area"&&t.next("GO_NEXT_AREA"))})}),nextMovie$:new B.Observable(t=>{a(this,N).on(y.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){P(this,Dt,He).call(this),this.options.player=t,a(this,vt).setPlayer(this.options.player),a(this,U)?a(this,U).setPlayer(this.options.player):m(this,U,vi(this.options.player)),m(this,dt,Ci({player:this.options.player,interactiveEvents:a(this,U),globalEventEmitter:a(this,N),removeControllers:()=>a(this,Rt).call(this,!1)})),this.appState===lt.initiated&&(P(this,se,xi).call(this),P(this,_t,ie).call(this,a(this,O).chapter))}setManifest(t){return V(this,null,function*(){P(this,Dt,He).call(this),this.isFirstChapterFetched=!1;let e=yield a(this,O).setManifest(t);return a(this,z)&&(yield a(this,z).handleManifestChange(e.manifest)),yield a(this,W).setManifest(e.manifest),a(this,N).emit(y.manifestChanged,{manifest:e.manifest}),P(this,_t,ie).call(this,a(this,O).chapter),e.manifest})}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,z))==null||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,z))==null||e.updateVideosInfo(t))}setChapter(){return V(this,arguments,function*({chapterId:t,pushToHistory:e=!0}={}){var l;P(this,Dt,He).call(this),a(this,H)&&this.isFirstChapterFetched&&(a(this,H).draw(),a(this,H).show()),B.CC.isSafari&&(yield Rn(35));let{chapter:n,media:r,graph:s}=yield t?a(this,O).setNext(t):a(this,O).setInitial();return e&&P(this,Xe,jn).call(this,n.id),this.state.isInitialChapter$.next(a(this,O).isInitialChapter()),this.state.isEndChapter$.next(a(this,O).isEndChapter()),a(this,z)&&a(this,z).handleChapterChange(s),(l=a(this,H))==null||l.setCurrentChapter(this.getCurrentChapter().chapter),a(this,N).emit(y.chapterChanged,{chapter:n,media:r,graph:s}),P(this,_t,ie).call(this,a(this,O).chapter),m(this,Bt,new Set),this.isFirstChapterFetched=!0,{chapter:n,media:r,graph:s}})}toggleGraphView(t=!0){a(this,z)&&(t?(a(this,z).show(),a(this,pt).next(!1)):(a(this,z).hide(),P(this,re,Ti).call(this)),a(this,N).emit(y.graph,{type:Pt.visibility,visibility:t}))}init(){a(this,O).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===lt.created&&(a(this,yt).resizeObserver.observe(this.options.fullscreenTargetElement),P(this,se,xi).call(this),this.appState=lt.initiated,P(this,_t,ie).call(this,a(this,O).chapter))}deadEndCheck(){var n,r;return!((r=(n=a(this,U))==null?void 0:n.getPreparedToExecActions())!=null?r:[]).some(s=>s.actionType===j.setNextBranch)}allControlsAreRemoved(){return!a(this,Z).some(e=>!e.container.isRemoved)}isEndedExpectation(){var n;if(!((n=this.options)!=null&&n.player)||!a(this,Z))return!1;let t=this.options.player.info.position$.getValue(),e=this.options.player.info.duration$.getValue();return t===e&&a(this,Z).some(r=>{let s=r.container.container;return!s.isRemoved&&s.endTime===null&&It(s.events)})}playPrevChapter(){var t;(t=a(this,W))==null||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,O).manifest){return Kt(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,W).getInitialVideoId(),chapterId:a(this,W).getInitialChapterId()}}getHistoryState(){return a(this,W).state}getIsSeekable(){return a(this,pt)}getInteractiveRanges(){var t;return fn((t=a(this,O).chapter)==null?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,vt).getNextInteractiveTime(t)}getChapterBranches(t){return a(this,O).getBranches(t)}getCurrentChapter(){return a(this,O).getCurrent()}getCurrentManifest(){return a(this,O).manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,N).on(...t),this}off(...t){return a(this,N).off(...t),this}once(...t){return a(this,N).once(...t),this}destroy(){var t,e;a(this,Rt).call(this),m(this,Z,void 0),this.state=void 0,(t=a(this,z))==null||t.destroy(),m(this,z,void 0),a(this,yt).release(),m(this,yt,void 0),m(this,dt,void 0),a(this,Y).release(),m(this,Y,void 0),a(this,U).release(),m(this,U,void 0),a(this,O).release(),m(this,dt,void 0),a(this,gt).release(),m(this,gt,void 0),a(this,ht).unsubscribe(),m(this,ht,void 0),a(this,N).reset(),m(this,N,void 0),(e=a(this,H))==null||e.destroy(),m(this,H,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,W).destroy(),m(this,W,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=lt.destroyed}};yt=new WeakMap,Z=new WeakMap,gt=new WeakMap,W=new WeakMap,ht=new WeakMap,U=new WeakMap,Y=new WeakMap,dt=new WeakMap,O=new WeakMap,pt=new WeakMap,Bt=new WeakMap,z=new WeakMap,Ft=new WeakMap,H=new WeakMap,N=new WeakMap,vt=new WeakMap,Vt=new WeakMap,Ge=new WeakSet,An=function(t=!1){a(this,N).on(y.historyInited,r=>V(this,[r],function*({initChapterId:e,videosInfo:n=[]}){t&&(yield P(this,Ue,Mn).call(this,{initialChapter:e,videosInfo:n}))})),a(this,N).on(y.interactives,e=>V(this,null,function*(){var n,r;if(e.type===A.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)==null?void 0:n.behaviour)==="change-chapter"){let{chapterId:l}=e.payload;this.setChapter({chapterId:l})}if(((r=e.payload)==null?void 0:r.behaviour)==="change-manifest"){let{manifestURL:l}=e.payload;this.setManifest(l)}let s=e.type==="action-execution";s&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===A.containerRemoved&&a(this,qe).call(this,e.subjectId)})),a(this,N).on(y.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Ue=new WeakSet,Mn=function(n){return V(this,arguments,function*({source:t,videosInfo:e=[]}){m(this,Ft,gi(this));let r=document.createElement("div");a(this,Ft).on(Yt.activePlayerChanged,this.emitPlayerChanged);let{player:s,config:l}=yield a(this,Ft).init({source:t,initialChapter:a(this,W).getInitialChapterId(),container:r});return this.updateGraphVideosInfo(e),{player:s,config:l}})},Dt=new WeakSet,He=function(){var t;this.appState===lt.ready&&(a(this,Rt).call(this),m(this,Z,[]),a(this,Y).release(),(t=a(this,U))==null||t.release(),this.appState=lt.initiated,a(this,pt).next(!1),a(this,ae).call(this))},Si=new WeakMap,ze=new WeakMap,We=new WeakSet,Ln=function(t){(!a(this,z)||a(this,z).isHidden)&&P(this,re,Ti).call(this);let e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){let s=r.range.join("-");a(this,Bt).has(s)||(a(this,Bt).add(s),a(this,N).emit(y.interactives,{type:A.rangeEnded,payload:r,visibility:!0}))}},se=new WeakSet,xi=function(){a(this,ht).unsubscribe(),a(this,ht).add(this.options.player.events.started$.pipe((0,B.once)()).subscribe(a(this,ze))).add(this.options.player.events.playing$.subscribe(a(this,Y).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,Y).cancelAnimation)).add(this.options.player.info.position$.subscribe(P(this,We,Ln).bind(this))).add(a(this,O).prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add((0,B.combine)({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,c],subjects:h})=>o<s&&s<c&&h.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?m(this,Vt,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):a(this,ae).call(this))})),this.options.lastFrame&&a(this,ht).add(this.options.player.info.duration$.subscribe(t=>{a(this,H).setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,H).setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,H).reset(),setTimeout(()=>{a(this,H).hide(),a(this,H).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,H).onSeek))},Rt=new WeakMap,_t=new WeakSet,ie=function(t){a(this,O).chapter&&this.appState===lt.initiated&&(a(this,dt).setManifestChapterEvents(t),m(this,Z,P(this,Qe,Nn).call(this,t)),a(this,U).containersEventsCallState.setData(t.containers),a(this,vt).setContainers(a(this,Z).map(e=>e.container.container).filter(e=>!Me(e.controls))),this.options.lastFrame&&a(this,Y).addFn(()=>{a(this,H).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=lt.ready)},Qe=new WeakSet,Nn=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)==null?void 0:e.reduce((r,s)=>{let l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Le({player:this.options.player,container:o(s,this.rootElement),branches:a(this,O).chapter.branches,selectBranches:a(this,dt),interactiveEvents:a(this,U),globalEventEmitter:a(this,N),ignoreContainerEvent:()=>cn(s,a(this,Z)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,vt).deleteContainer(s.id)}});return a(this,Y).addFn(c.whilePlaying,!0),[...r,c]}return[...r]},[]))!=null?n:[]},re=new WeakSet,Ti=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,pt).next(!1);return}let e=a(this,pt).getValue(),n=!!a(this,vt).getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,pt).next(!e)},Ke=new WeakSet,kn=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Xe=new WeakSet,jn=function(t){var o;if(P(this,Ke,kn).call(this),!a(this,W).inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(o=n&&nt(n)&&qt(n))!=null?o:!1,s=a(this,O).manifest.metadata.initChapterId===t,l=a(this,W).state.history$.getValue();if(s||r&&e){a(this,W).updateHistory([t]);return}l.at(-1)!==t&&a(this,W).updateHistory([...l,t])},qe=new WeakMap,ae=new WeakMap;var Pn={Container:kt,createChoiceContainer:be,createAreaControl:fe,createButtonControl:ye,createRelativeLayout:Gi,getRootEl:le,classnamesPrefix:G};var vs={version:$i};