@vkontakte/videoplayer-interactive 1.0.11-dev.b4747814.0 → 1.0.11-dev.b72fcea2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es2018.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.11-dev.b4747814.0
3
- * Thu, 30 May 2024 12:04:59 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.11-dev.b72fcea2.0
3
+ * Fri, 31 May 2024 10:56:17 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-11/doc/
5
5
  */
6
- import{loadVKLangPack as Gn,ValueSubject as F,Subscription as Jt,Subject as zn,Observable as Ge,getCurrentBrowser as qn,CurrentClientBrowser as Qn,once as Yn,combine as Kn}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{v4 as Xn}from"uuid";import{Player as Zn}from"@vkontakte/videoplayer-core/es2018.esm.js";const Jn="1.0.11-dev.b4747814.0";function Fi(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})`}const q="SDK_NAME",tr="SDK_NAME-controls-container",Di=()=>document.querySelector(`.${tr}`),er=.4,X={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},ze={top:"flex-start",bottom:"flex-end",center:"center"},qe={start:"flex-start",end:"flex-end",center:"center"},Qe={start:"left",end:"right",center:"center"},Wi=({target:i,props:t})=>{var e,n,r,s,c,o;i.style.alignItems=(n=ze[(e=t==null?void 0:t.text)===null||e===void 0?void 0:e.gravityVertical])!==null&&n!==void 0?n:ze.center,i.style.justifyContent=(s=qe[(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.gravityHorizontal])!==null&&s!==void 0?s:qe.center,i.style.textAlign=(o=Qe[(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:Qe.start},Hi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,c,o,l,h;i.style.color=(s=(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.color)!==null&&s!==void 0?s:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.size)!==null&&o!==void 0?o:e.textSize})`,i.textContent=(h=(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.value)!==null&&h!==void 0?h:e.textContent},Ui=({target:i,props:t,fallback:e})=>{var n,r,s,c;i.style.backgroundColor=Fi((r=(n=t==null?void 0:t.background)===null||n===void 0?void 0:n.color)!==null&&r!==void 0?r:e.backgroundColor,(c=(s=t==null?void 0:t.background)===null||s===void 0?void 0:s.alpha)!==null&&c!==void 0?c:e.backgroundAlpha)},Gi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,c,o,l,h,v,u,p,g,E;i.style.border=`calc(${n.height} * ${(c=(s=(r=t==null?void 0:t.shape)===null||r===void 0?void 0:r.border)===null||s===void 0?void 0:s.width)!==null&&c!==void 0?c:e.borderWidth}) solid ${Fi((h=(l=(o=t==null?void 0:t.shape)===null||o===void 0?void 0:o.border)===null||l===void 0?void 0:l.color)!==null&&h!==void 0?h:e.borderColor,(p=(u=(v=t==null?void 0:t.shape)===null||v===void 0?void 0:v.border)===null||u===void 0?void 0:u.alpha)!==null&&p!==void 0?p:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(E=(g=t==null?void 0:t.shape)===null||g===void 0?void 0:g.roundCorners)!==null&&E!==void 0?E:e.roundCorners})`},je=({target:i,layoutParams:t,fallback:e})=>{var n;i.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:e.angle}rad)`},se="int",Le={AREA:`${se}_area`,TEXT:`${se}_text`,BUTTON:`${se}_bttn`};class Pe{constructor(t){this.control=t}createView(t){var e;const n=document.createElement("div");n.classList.add(`${q}-control-container-${this.control.id}`),t(n,this.control.layoutParams);const r=((e=this.control.layoutParams.innerSizesDependOn)!==null&&e!==void 0?e:X.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:r}}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}})}getElement(){return document.querySelector(`.${q}-control-container-${this.control.id}`)}}const zi=i=>{if(i.type.trim().toLowerCase()==="area")return new ir(i)};class ir extends Pe{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");return s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",Le.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",Ui({target:s,props:this.control.props,fallback:{...X,backgroundColor:"transparent"}}),Gi({target:s,props:this.control.props,fallback:{...X,borderAlpha:0},dependsOn:n}),je({target:s,layoutParams:this.control.layoutParams,fallback:X}),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const qi=i=>{if(i.type.trim().toLowerCase()==="button")return new nr(i)};class nr extends Pe{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");s.type="button",s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",Le.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";const c=document.createElement("span");return c.style.display="inline-block",c.style.whiteSpace="pre",c.style.overflow="hidden",c.style.textOverflow="ellipsis",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),Ui({target:s,props:this.control.props,fallback:X}),Gi({target:s,props:this.control.props,fallback:X,dependsOn:n}),Wi({target:s,props:this.control.props}),Hi({target:c,props:this.control.props,fallback:X,dependsOn:n}),s.append(c),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(`.${q}-${this.control.id}`)}}const rr=i=>{if(i.type.trim().toLowerCase()==="text")return new sr(i)};class sr extends Pe{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",Le.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),Wi({target:s,props:this.control.props}),Hi({target:c,props:this.control.props,fallback:X,dependsOn:n}),s.append(c),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}class ar{constructor(t){this.layout=t}}const or=i=>{if(i.type.trim().toLowerCase()==="relative")return new Qi(i)};class Qi extends ar{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))`}}function a(i,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?i!==t||!n:!t.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(i):n?n.value:t.get(i)}function b(i,t,e,n,r){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?i!==t||!r:!t.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?r.call(i,e):r?r.value=e:t.set(i,e),e}var Ct,zt,Ye;class Yi{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",zt).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),a(this,Ct,"m",zt).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",zt).call(this)}}Ct=new WeakSet,zt=function(){this.controls=a(this,Ct,"m",Ye).call(this)},Ye=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((e,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};const Ki=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new lr(i,t)};class lr extends Yi{constructor(t,e){super(t),this.rootElement=e!=null?e:Di(),this.layout=new Qi(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",qi),this.addControlFactory("text",rr),this.addControlFactory("area",zi)}createView(t){const e=document.createElement("div");return e.classList.add(`${q}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{const r=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(r,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){const t=this.getElement();t&&(t.style.visibility="hidden")}show(){const t=this.getElement();t&&(t.style.visibility="visible")}enable(){const t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){const t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=er,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${q}-${this.container.id}`)}}function Xi(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const Pt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},St=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Me=i=>St(i,Pt.Object),Ce=i=>St(i,Pt.String),Ne=i=>St(i,Pt.Array),Zi=i=>St(i,Pt.Number),cr=i=>St(i,Pt.Function),Ke=i=>Zi(i)&&!isNaN(i),At=i=>Me(i)&&Object.keys(i).length===0,Ji=i=>Ne(i)&&!i.length,Bt=(i,t)=>Ce(i)&&(t?i.trim():i).length,tn=window.navigator.userAgent.toLowerCase(),hr=/mobi/i.test(tn);tn.indexOf("android")>-1;const dr="video_interactive",ur="videoint",fr=250;class vr{constructor(t){this.onResize=e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))},this.handleChapterChange=e=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(n=this.onError)===null||n===void 0||n.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(e,n=[])=>{var r;if(!Zi(e.graph.edit.chapters[0].x)){this.isReady=!1,(r=this.onError)===null||r===void 0||r.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let s;try{s=await Gn(this.lang,dr,ur)}catch(o){console.log("Unable to load graph language pack")}const{GraphEditor:c}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new c(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:s}),this.ngEditor.on("control",({name:o,chapterId:l})=>{o==="openPreview"&&this.onOpenPreviewClick(l)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo={...o}})}this.visitedChapterIds=new Set(n),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.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=pr(t),this.resizeObserver=new ResizeObserver(Xi(this.onResize,fr)),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===void 0||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)===null||e===void 0||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function pr(i){const 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}const yr=3e3,mr=()=>{let i=[],t=null;return{setPlayer:c=>{t=c},setContainers:c=>{i=c},deleteContainer:c=>{i=i.filter(o=>o.id!==c)},getNextInteractiveTime:(c=yr)=>{if(!i.length||t===null)return null;let o=-1,l=!1;const h=Math.round(t.info.position$.getValue()*1e3);for(const v of i){const u=v.startTime-c;if(u<=h&&(h<=v.endTime||v.endTime===null)){l=!0;break}h<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},Kt=(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},gr="3.1",Xe={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},br={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Er=i=>{const t=[];for(const e of i.chapters){let n;const r=[];for(const{isDefault:o,...l}of e.branches)o&&(n=l.id),r.push(l);let s=[];const c=[];for(const{fallbackStrategy:o,...l}of e.containers){const h=!!l.endTime;let v=[br];switch(o){case"await":h?v=[]:s=[];break;case"default":{const u={type:"onSuspense",action:{type:Xe.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?v=[u]:s=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:Xe[o],args:{}}};h?v=[u]:s=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:Xn(),events:v})}t.push({...e,containers:c,events:s,branches:r})}return i.metadata.version=gr,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}},Cr="3.2",_r=i=>{if(!i.media){const{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:Cr},media:t}}return i},Ir="3.3",wr=(i=[])=>({edit:{chapters:i},view:{}}),Ze={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Sr=i=>{var t;const e=[],n=[];for(const r of i.chapters){const{id:s,x:c,y:o,...l}=r,h=l.containers.map(v=>{var u;return{...v,controls:v.controls.map(({subtype:p,type:g,...E})=>({...E,type:p!=null?p:g})),events:!((u=v.events)===null||u===void 0)&&u.length?v.events:[Ze]}});e.push({id:s,...l,containers:h,events:!((t=l.events)===null||t===void 0)&&t.length?l.events:[Ze]}),n.push({id:s,x:c,y:o})}return{...i,chapters:e,graph:wr(n),metadata:{...i.metadata,version:Ir}}},Tr=[{version:"3.0",migrate:Er},{version:"3.1",migrate:_r},{version:"3.2",migrate:Sr}],$r=i=>Tr.reduce((t,e)=>Kt(t.metadata.version,e.version)?t:e.migrate(t),i),Rr=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),R=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var ht;(function(i){i.GO_NEXT_BUTTON="GO_NEXT_BUTTON",i.GO_NEXT_AREA="GO_NEXT_AREA",i.WATCH_AGAIN="WATCH_AGAIN",i.OPEN_GRAPH="OPEN_GRAPH",i.CLOSE_GRAPH="CLOSE_GRAPH"})(ht||(ht={}));const Je={metadata:"Object",chapters:"Array"},xr="3.0.0",Or="3.3.0",en=i=>{const t=Kt(i,xr);return t===-1?!1:t===0?!0:Kt(i,Or)!==1},Ar=i=>{if(!Me(i))return!1;for(const t in Je)if(!i[t]||!St(i[t],Je[t]))return!1;return en(i.metadata.version)},nn=i=>i.type===Rr.Text;class S{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}S.Severity={RECOVERABLE:1,CRITICAL:2};S.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class rn{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]||[];const 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){const 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){const 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]}}class jr{constructor(t){this.addFn=(e,n=!1)=>{cr(e)&&(this.fns.push(e),n&&this.updateFn())},this.removeFn=(e,n=!1)=>{this.fns=this.fns.filter(r=>r!==e),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),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=[]}}class Lr{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!==null&&e!==void 0?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(t,e){return Pr(...this.loaders[t])(e)}}function Pr(...i){return async function(e){const n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function Xt(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function _e({actions:i,errors:t,chapterId:e,...n}){if(e){const r=i.getManifest(),s=i.getChapter(r.chapters,e);if(s){const c=i.getMedia(r.media,s.videoId),o=i.getGraph(r.graph,s.id);return c?{...n,actions:i,errors:t,result:{chapter:s,media:c,graph:o}}:{...n,errors:Xt(t,_e.name,"Could not find media"),actions:i}}}return{...n,errors:Xt(t,_e.name,"Could not find chapter"),actions:i}}class ti{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}removeEventListener(t,e){if(!(t in this.listeners))return;const n=this.listeners[t];for(let r=0,s=n.length;r<s;r++)if(n[r].callback===e){n.splice(r,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const n=this.listeners[t.type].slice();for(let r=0,s=n.length;r<s;r++){const c=n[r];try{c.callback.call(this,t)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(t.type,c.callback)}return!t.defaultPrevented}}class sn extends ti{constructor(){super(),this.listeners||ti.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class Mr{constructor(){Object.defineProperty(this,"signal",{value:new sn,writable:!0,configurable:!0})}abort(t){let e;try{e=new Event("abort")}catch(r){typeof document!="undefined"?document.createEvent?(e=document.createEvent("Event"),e.initEvent("abort",!1,!1)):(e=document.createEventObject(),e.type="abort"):e={type:"abort",bubbles:!1,cancelable:!1}}let n=t;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(r){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(Mr.prototype[Symbol.toStringTag]="AbortController",sn.prototype[Symbol.toStringTag]="AbortSignal");function an(i){return i.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof i.Request=="function"&&!i.Request.prototype.hasOwnProperty("signal")||!i.AbortController}function Nr(i){typeof i=="function"&&(i={fetch:i});const{fetch:t,Request:e=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!an({fetch:t,Request:e,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:t,Request:s};let s=e;(s&&!s.prototype.hasOwnProperty("signal")||r)&&(s=function(h,v){let u;v&&v.signal&&(u=v.signal,delete v.signal);const p=new e(h,v);return u&&Object.defineProperty(p,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),p},s.prototype=e.prototype);const c=t;return{fetch:(l,h)=>{const v=s&&s.prototype.isPrototypeOf(l)?l.signal:h?h.signal:void 0;if(v){let u;try{u=new DOMException("Aborted","AbortError")}catch(g){u=new Error("Aborted"),u.name="AbortError"}if(v.aborted)return Promise.reject(u);const p=new Promise((g,E)=>{v.addEventListener("abort",()=>E(u),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([p,c(l,h)])}return c(l,h)},Request:s}}const ke=an({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),on=ke?Nr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,ei=ke?on.fetch:window.fetch;ke?on.Request:window.Request;const kr=async i=>{try{let t,e;if(Me(i))t=i;else if(Ce(i)){e=new URL(i).href;const r=await ei(e);if(!r.ok)return{};t=await r.json()}else return{};if(!Ar(t))return{};const n=t.metadata.media;if(Ce(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);const s=await ei(r);if(!s.ok)throw new Error;t.metadata.media=await s.json()}catch(r){return Dr(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}};async function Vr(i){const{manifest:t,manifestURL:e}=await kr(i),n=$r(t);return n.media=Br(n.media,e),delete n.metadata.media,n}function ae(i,t){return i.find(e=>e.id===t)}function ii(i,t){var e,n;return!((e=i.edit)===null||e===void 0)&&e.chapters?i.edit.chapters.find(r=>r.id===t):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(r=>r.id===t):void 0}function ni(i,t){return i.videos.find(e=>e.id===t)}function Br(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{const r=Fr(n.url,t);return{...n,url:r||n.url}})}))}}function Fr(i,t){try{return new URL(i,t).href}catch(e){return""}}function Dr(i){return Kt(i,"3.2.0")>=0}const A=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ve=i=>Ne(i)&&!Ji(i),te=i=>i.order==="end",Wr=i=>Ne(i.containers)&&!Ji(i.containers)&&te(i),Hr=(i,t)=>{var e;const n=i*1e3;return Ve(t.controls)&&n<((e=t.startTime)!==null&&e!==void 0?e:0)},ri=(i,t)=>{var e,n;const r=i*1e3;return Ve(t.controls)&&r>=((e=t.startTime)!==null&&e!==void 0?e:0)&&r<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Lt=i=>i.some(t=>t.action.type==="expect"),si=i=>i.find(t=>t.action.type==="expect"),Ur=i=>(i==null?void 0:i.length)===1,ln=i=>Ur(i)&&nn(i[0]),Gr=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),zr=(i=[])=>i.reduce((t,e,n)=>{var r,s,c;const o=((r=e==null?void 0:e.controls)!==null&&r!==void 0?r:[]).filter(l=>!nn(l));if(Ve(o)){const l=[(s=e.startTime)!==null&&s!==void 0?s:0,(c=e.endTime)!==null&&c!==void 0?c:1/0],h=e.id;if(!n)t.push({subjects:[h],range:l});else{const v=[];let u=-1/0,p=1/0,g=[];const E=[];for(let w=0;w<t.length;w++){const d=t[w];if(E.push(...d.subjects),d.range[0]<p&&(p=d.range[0]),d.range[1]>u&&(u=d.range[1]),d.range[0]<=l[0]&&d.range[1]>=l[1])return t[w].subjects.push(h),t;l[0]>=d.range[0]&&l[0]<=d.range[1]&&(v.push(w),g=g.concat(d.subjects),l[0]=d.range[0]),l[1]>=d.range[0]&&l[1]<=d.range[1]&&(v.push(w),g=g.concat(d.subjects),l[1]=d.range[1])}if(E.push(h),l[0]<=p&&l[1]>=u)return[{subjects:E,range:l}];v.length&&v.reverse().forEach(w=>{t.splice(w,1)}),t.push({subjects:g.concat([h]),range:l})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),qr=(i,t)=>Lt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Lt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);class Qr extends Lr{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new F(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var e;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Xt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const r=await Vr((e=n.result)!==null&&e!==void 0?e:t);return this.manifest=r,this}async setInitial(){return this.setNext()}async setNext(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);const e=await this.exec("chapterLoaders",_e({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ii,getChapter:ae,getMedia:ni,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){const e=ae(this.manifest.chapters,t);if(e){const n=ni(this.manifest.media,e.videoId),r=ii(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:r}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{const e=ae(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{const 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 te(this.chapter)}}const Yr=i=>{const t=i.variants.find(e=>{var n;return((n=e.payload)===null||n===void 0?void 0:n.type)==="vk"});if(t&&"payload"in t){const[e,n]=t.payload.id.split("_");return[e,n]}return[]},_={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ai={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},j={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Kr(){const i=new Map;function t({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...c}){const o=i.get(r),l={...c};return o?o[s]=l:i.set(r,{[s]:l}),{listId:r,itemId:s,...c}}function e(r,s){var c,o,l;const h=i.get(r);if(h){if(s)return(c=h[s])===null||c===void 0||c.player.destroy(),(o=h[s])===null||o===void 0||o.container.remove(),(l=h[s])===null||l===void 0||l.subscription.unsubscribe(),delete h[s],Object.keys(h).length||i.delete(r),!0;for(const v of Object.values(h))v.player.destroy(),v.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(const r of i)e(r[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function oi(i,t=[]){var e,n,r;let s={},c;const o=!t.length;for(const l of i.variants)if(!c&&"cover"in l&&(c=l.cover),"url"in l)switch(l.type.toLowerCase()){case"mp4":(o||t.includes("mp4"))&&(s.MPEG={...s.MPEG,[(e=l.standard)!==null&&e!==void 0?e:"Invariant quality"]:l.url});break;case"mpeg":(o||t.includes("mpeg"))&&(s.MPEG={...s.MPEG,[(n=l.standard)!==null&&n!==void 0?n:"Invariant quality"]:l.url});break;case"hls":(o||t.includes("hls"))&&(s={...s,HLS:{type:"url",url:l.url}});break;case"dash":(o||t.includes("dash"))&&(s={...s,DASH_SEP:{compatibilityMode:!0,type:"url",url:l.url}});break}return{sources:s,thumbUrl:c,title:(r=i.title)!==null&&r!==void 0?r:""}}const Ft=(i,t)=>{const e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))},qt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Xr=2;function Zr(i){const t=Kr();let e,n;const r=new rn;let s={},c=!1,o=null,l=!1,h;i&&v(i);function v(y){o=y}function u(y,C,m){var $;if(!o)throw Error("need to set interactive controller");if(!o.options)return;const L=(($=t.map.get(y))!==null&&$!==void 0?$:{})[C];if(L){s={chapterId:m,listId:y,itemId:C,...L};const I=s.player;n=I.info.currentQuality$.subscribe(k=>{if(!(!k||!I.info.position$.getValue())){e=k;for(const W of t.map)Object.values(W[1]).forEach(({player:M})=>{I.info.isAutoQualityEnabled$.getValue()||Ft(M,k)})}}),L.container.remove(),c=!1,o.setPlayer(L.player),l||(o.init(),l=!0),r.emit(qt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function p(y,C,m){if(!o)throw Error("need to set interactive controller");if(At(s)||y!==s.itemId)return;if(m>=0&&!c){const O=o.getChapterBranches();c=!0;const L=new Set;for(const I of O)L.has(I.media.id)||(await E({media:I.media,chapterId:I.chapter.id,setAsActive:!1,title:I.chapter.label}),L.add(I.media.id))}}async function g({chapter:{id:y},media:C}){if(At(s))return;n==null||n.unsubscribe();const m=s.player.info.muted$.getValue(),$=s.player.info.currentQuality$.getValue(),O=s.player.info.isAutoQualityEnabled$.getValue(),L=s.player.info.volume$.getValue(),I=s.player.info.currentPlaybackRate$.getValue(),k=!O;let W=!1;for(const M of t.map)if(M[0]===C.id){const Q=Object.keys(M[1]);for(const Y of Q)Y===s.itemId?(Q.length<Xr||(W=!0),t.removePlayer(M[0],Y)):(W=!0,u(M[0],Y,y),k?Ft(s.player,$):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(m),s.player.setPlaybackRate(I))}else t.removePlayer(M[0]);W||(await E({media:C,chapterId:y,setAsActive:!0,playbackRate:I}),k?Ft(s.player,$):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(m))}async function E({media:y,chapterId:C,prefetch:m=!0,setAsActive:$=!0,autoplay:O=!1,preferredExt:L,title:I,playbackRate:k}){var W,M,Q,Y,ne;const De=Math.random().toString(),re=document.createElement("div");h.append(re);const Hn=(W=s==null?void 0:s.player)===null||W===void 0?void 0:W.info.isAutoQualityEnabled$.getValue();let kt;if(!((M=o==null?void 0:o.options)===null||M===void 0)&&M.vkVideoLoader){const Vt=Yr(y);Vt.length&&(kt=await o.options.vkVideoLoader(...Vt))}const We=((Q=o==null?void 0:o.options)===null||Q===void 0?void 0:Q.coreConfig)||{},Un={...We,configName:[...(Y=We.configName)!==null&&Y!==void 0?Y:[],"interactive"]},He={container:re,...((ne=kt==null?void 0:kt.videos)===null||ne===void 0?void 0:ne[0])||{sources:oi(y,L).sources},title:I},ot=new Zn(Un);ot.initVideo(He);const Ue=new Jt;Ue.add(ot.info.position$.subscribe(function(Vt){p(De,ot.info.duration$.getValue(),Vt)})).add(ot.events.canplay$.subscribe(function(){Hn||Ft(ot,e),k&&ot.setPlaybackRate(k)}));const vt=t.createPlayer({listId:y.id,itemId:De,player:ot,container:re,sources:oi(y,L).sources,config:He,subscription:Ue});return $&&u(y.id,vt.itemId,C),O&&vt.player.play(),m&&!O&&vt.player.prepare(),r.emit(qt.playerCreated,vt.player),{player:vt.player,config:vt.config}}function w(){d(),o=null}function d(){o==null||o.off(_.chapterChanged,g),t.removeAll(),s={},l=!1,c=!1}async function f({container:y}){if(!o)throw Error("need to set interactive controller");d(),h=y;const{media:C,chapter:m}=o.getCurrentChapter();if(C){o.on(_.chapterChanged,g);const{player:$,config:O}=await E({media:C,chapterId:m.id,title:m.label});return r.emit(qt.initiated,{container:y,media:C,chapterId:m.id}),{player:$,config:O}}else console.error("not found")}return{...t,on:r.on.bind(r),off:r.off.bind(r),init:f,setInteractiveController:v,createPlayer:E,removeAll:w,getActivePlayer:function(){return s}}}class Jr{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:c,ignoreContainerEvent:o,permanentTextControls:l,disabledControls$:h,onRemove:v}){this.hide=()=>{setTimeout(()=>{var u,p;this.gameState!==A.end&&(Lt(this.container.container.events)&&this.gameState===A.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==A.interactive&&((p=(u=this.container).hide)===null||p===void 0||p.call(u)),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})))})},this.show=()=>{var u,p,g,E;if(this.gameState===A.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(E=(g=this.container).show)===null||E===void 0||E.call(g),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!0,isFirst:!1});else{const d=Gr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})},onEvent:(f,y)=>{this.isSelectedControlEvent=!0,f!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})),(this.gameState===A.end||this.gameState===A.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1}))},isEOV:()=>this.gameState===A.end});this.container.createView(d),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((p=(u=this.container).disable)===null||p===void 0||p.call(u))}},this.onEndOfVideo=()=>{this.gameState=A.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var u,p;if(((u=this.player.experimental.element$.getValue())===null||u===void 0?void 0:u.readyState)<1||[A.destroyed,A.removed].includes(this.gameState)&&!this.isPermanentText)return;const E=this.player.getExactTime();if(Hr(E,this.container.container))this.gameState!==A.beforeInteractive&&(this.gameState=A.beforeInteractive,this.onBeforeStartTime());else if(ri(E,this.container.container))this.gameState!==A.interactive&&(this.gameState=A.interactive,this.onStartTime());else if(this.gameState!==A.afterInteractive){const f=this.gameState;this.gameState=A.afterInteractive,f===A.interactive&&this.onEndTime()}else this.gameState!==A.destroyed&&!this.isPermanentText&&this.removeView();const w=ri(E,this.container.container),d=this.container.container.startTime?[this.container.container.startTime,(p=this.container.container.endTime)!==null&&p!==void 0?p:1/0]:[];this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:d,currentTime:E,isInteractiveTime:w})},this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Jt,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=l&&ln(e.container.controls),this.disabledControls$=h,this.onRemove=v,this.globalEventEmitter=c,this.gameState=A.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===void 0||n.call(e):(s=(r=this.container).enable)===null||s===void 0||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);const t=Lt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)===null||e===void 0||e.call(t),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=A.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.containerRemoved,visibility:!1}),this.gameState=A.removed,(t=this.onRemove)===null||t===void 0||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=A.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!==null&&t!==void 0?t:1/0,id:this.container.container.id})}}function ts(){const i={};function t(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){const l={};for(const h in i)+h<=o&&(l[h]=i[h]);return l}function n(o){const l={};for(const h in i)+h>=o&&(l[h]=i[h]);return l}function r({timestamp:o,priority:l,initiator:h}){var v;if(Ke(o)){const u=(v=i[o])!==null&&v!==void 0?v:null;if(u&&Bt(l,!0)){let p={};const g=u[l];if(g&&(p={...p,...g}),p=At(p)?null:p,p&&Bt(h,!0)){const E=p[h];return E!=null?E:null}return p}return u}return null}function s({timestamp:o,priority:l,initiator:h}){if(Ke(o))if(i[o]){if(Bt(l,!0))if(i[o][l]){if(Bt(h,!0))if(i[o][l][h]){if(delete i[o][l][h],!At(i[o][l]))return!0}else return!1;if(delete i[o][l],!At(i[o]))return!0}else return!1;return delete i[o]}else return!1}function c({timestamp:o,priority:l,initiator:h,...v}){var u,p,g;!((p=(u=i[o])===null||u===void 0?void 0:u[l])===null||p===void 0)&&p[h]?i[o][l][h].push({...v}):!((g=i[o])===null||g===void 0)&&g[l]?i[o][l]={...i[o][l],[h]:[{...v}]}:i[o]?i[o]={...i[o],[l]:{[h]:[{...v}]}}:i[o]={[l]:{[h]:[{...v}]}}}return{map:i,remove:s,add:c,removeAll:t,get:r,getLte:e,getGte:n}}const es=[R.expect,R.setNextBranch],is=1/0;function li(i){let t=i,e;const n=ns(),r=new ts;let s;const c=()=>{p(),d()},o=f=>{r.add.call(void 0,f),g()},l=(f=[])=>{for(const y of f)if(y.action(),es.includes(y.actionType))break},h=(f=1/0)=>{var y,C,m;const $=Dt((y=r.get({timestamp:f,priority:"control"}))!==null&&y!==void 0?y:{}),O=Dt((C=r.get({timestamp:f,priority:"container"}))!==null&&C!==void 0?C:{}),L=Dt((m=r.get({timestamp:f,priority:"chapter"}))!==null&&m!==void 0?m:{});return[...$,...O,...L]},v=f=>{n.isReady(f)&&l(h(f))},u=()=>{var f;l([...Dt((f=r.get({timestamp:1/0,priority:"chapter"}))!==null&&f!==void 0?f:{})])},p=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},g=()=>{e||(e=()=>setTimeout(()=>{v(1/0)}),s=t.events.ended$.subscribe(e))},E=f=>{p(),t=f},w=f=>{f.priority==="container"&&n.resetCalled(f.timestamp),r.remove(f)},d=()=>{n.release(),r.removeAll()};return{setPlayer:E,add:o,remove:w,exec:v,execEndOfVideo:u,listen:g,unlisten:p,release:c,containersEventsCallState:n,getPreparedToExecActions:h}}function ns(){const i=new Map;return{setCalled:({timestamp:c,id:o})=>{const l=i.get(c);l&&l[o]!==void 0&&(l[o]=!0)},setData:(c=[])=>{var o,l;for(const h of c){const v=(o=h.endTime)!==null&&o!==void 0?o:is,u=(l=i.get(v))!==null&&l!==void 0?l:{};i.set(v,{...u,[h.id]:!1})}},resetCalled:c=>{const o=i.get(c);if(o)for(const l in o)o[l]=!1},isReady:c=>{const o=i.get(c);return o?!Object.values(o).some(l=>!l):!0},release:()=>i.clear()}}function Dt(i){return Object.values(i).flat().sort(t=>t.actionType===R.expect?-1:1)}const rs=(i,t)=>{const{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:r,clientWidth:s}=t.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};const c=e/n,o=r/s;let l,h;return o>c?(h=s,l=s*c):o<c?(h=r/c,l=r):(h=s,l=r),{videoContentWidth:h,videoContentHeight:l}},ss=250;function as(i){let t=()=>{};const e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){const{parentElement:l,player:h}=i();if(l&&h){const{videoContentWidth:v,videoContentHeight:u}=rs(l,h);l.style.setProperty("--interactive-content-width",`${v}px`),l.style.setProperty("--interactive-content-height",`${u}px`),l.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),l.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function r(){const{parentElement:o}=i();o.removeAttribute("style")}const s=Xi(o=>{const{fns:l=[]}=i();n(o);for(const h of l)h()},ss);function c(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:c}}class os{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){const e=this.map[t];return e?e.slice():null}getAll(){const t=[];for(const 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)}}const ls=i=>Math.floor(Math.random()*i),cs=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},hs=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},ds=i=>{const t=i.length,e=ls(t);return i[e]},ci=1,us=i=>{var t,e;let n=0;for(let s=0;s<i.length;++s)n+=(t=i[s].weight)!==null&&t!==void 0?t:ci;const r=Math.random()*n;n=0;for(let s=0;s<i.length-1;++s)if(n+=(e=i[s].weight)!==null&&e!==void 0?e:ci,n>=r)return i[s];return i[i.length-1]},hi=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),oe=(i,t=!1)=>({...i,args:t?{...i.args,...hi}:{...hi,...i.args}}),di=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},c=({action:d,controlType:f,controlId:y,containerId:C,branches:m=[],onEvent:$,isEOV:O=()=>!1,isDisabled:L=()=>!1})=>{const I=oe(d,O()),k={timestamp:1/0,priority:"control",initiator:y,actionType:I.type},W=L(),M=i.emit.bind(i,_.interactives,{subjectId:y,subjectType:f,subjectName:"control",type:W?j.actionChoiceCanceled:j.actionChoice,actionType:d.type,payload:{containerId:C,...I.args}});if(W){M();return}switch(I.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const Q=m.find(Y=>Y.id===I.args.branchId);if(!Q)return;$(I.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),I.args.shouldOpenNow?E({subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{chapterId:Q.chapterId,autoSelect:!1}}):(e.add({...k,action:E.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{chapterId:Q.chapterId,autoSelect:!1}})}),n==null||n());return}case R.continuePlayback.trim().toLowerCase():{$(I.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),I.args.shouldOpenNow?g({subjectId:y,subjectName:"control",subjectType:f,action:d}):e.add({...k,action:g.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:d})});return}case R.openURI.trim().toLowerCase():{$(I.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),I.args.shouldOpenNow?w({subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{URI:d.args.uri}}):(e.add({...k,action:w.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{URI:d.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:d,container:{id:f,endTime:y},branches:C=[],isEOV:m=!1,autoSelected:$=!1})=>{const O=oe(d,m),L={timestamp:!O.args.shouldOpenNow||m?1/0:y,priority:"container",initiator:f,actionType:O.type},I=i.emit.bind(i,_.interactives,{subjectId:f,subjectName:"container",type:j.actionChoice,actionType:O.type,payload:O.args});switch(O.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const k=C.find(W=>W.id===O.args.branchId);if(!k)return;I(),e.add({...L,action:E.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{chapterId:k.chapterId,autoSelect:$}})}),n==null||n();return}case R.setMaxWeightBranch.trim().toLowerCase():return;case R.setMinWeightBranch.trim().toLowerCase():return;case R.setRandomBranch.trim().toLowerCase():return;case R.setWeightlessRandomBranch.trim().toLowerCase():return;case R.continuePlayback.trim().toLowerCase():{I(),e.add({...L,action:g.bind(null,{subjectId:f,subjectName:"container",action:O})});return}case R.openURI.trim().toLowerCase():{I(),e.add({...L,action:w.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{URI:d.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:d,branches:f,isEOV:y=!1}){const C=si(d.events);if(C){const m=oe(C.action,y);i.emit(_.interactives,{subjectId:d.id,subjectName:"container",type:j.actionChoice,actionType:m.type,payload:m.args}),e.add({timestamp:y?1/0:d.endTime,priority:"container",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"container"})}),r.isExpect=!0}else for(const m of d.events)o({action:m.action,container:d,branches:f,isEOV:y})}const h=({chapterId:d,action:f,branches:y=[]})=>{const C=i.emit.bind(i,_.interactives,{subjectId:d,subjectName:"chapter",type:j.actionChoice,actionType:f.type,payload:f.args});switch(f.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const m=y.find($=>$.id===f.args.branchId);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setWeightlessRandomBranch.trim().toLowerCase():{const m=ds(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setRandomBranch.trim().toLowerCase():{const m=us(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMaxWeightBranch.trim().toLowerCase():{const m=hs(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMinWeightBranch.trim().toLowerCase():{const m=cs(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.continuePlayback.trim().toLowerCase():return C(),g.bind(null,{subjectId:d,subjectName:"chapter",action:f});case R.openURI.trim().toLowerCase():return C(),w.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{URI:f.args.uri}});default:console.error("Unexpected chapter event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(d){const f=si(d.events);if(f){if(te(d))return;i.emit(_.interactives,{subjectId:d.id,subjectName:"chapter",type:j.actionChoice,actionType:f.action.type,payload:f.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"chapter"})})}else d.events.forEach(y=>{const C=h({chapterId:d.id,action:y.action,branches:d.branches});C&&e.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:y.action.type,action:C})})}const u=({subjectId:d,subjectName:f,action:y})=>{var C;t.pause(),i.emit(_.interactives,{subjectId:d,subjectName:f,type:j.actionExecution,actionType:(C=y==null?void 0:y.type)!==null&&C!==void 0?C:R.expect})},p=({subjectId:d,subjectName:f})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(_.interactives,{subjectId:d,subjectName:f,type:j.actionExecution,actionType:"after-expect"})},g=({subjectId:d,subjectName:f,subjectType:y,action:C})=>{i.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:j.actionExecution,actionType:C.type})},E=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{m.behaviour="change-chapter",i.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:j.actionExecution,actionType:C.type,payload:m})},w=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{if(!m.URI)return;const $=window.open(m.URI,"_blank","noopener,noreferrer");$&&($.opener=null),i.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:j.actionExecution,actionType:C.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:h,onExpectEvent:u,expectEventHandler:p,setManifestChapterEvents:v,setManifestContainerEvents:l,stopExpect:s,state:r}};var le=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function fs(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Wt=function(i){return i&&i.Math==Math&&i},at=Wt(typeof globalThis=="object"&&globalThis)||Wt(typeof window=="object"&&window)||Wt(typeof self=="object"&&self)||Wt(typeof le=="object"&&le)||function(){return this}()||le||Function("return this")(),ut=function(i){try{return!!i()}catch(t){return!0}},vs=ut,ee=!vs(function(){var i=function(){}.bind();return typeof i!="function"||i.hasOwnProperty("prototype")}),ps=ee,cn=Function.prototype,ui=cn.apply,fi=cn.call,ys=typeof Reflect=="object"&&Reflect.apply||(ps?fi.bind(ui):function(){return fi.apply(ui,arguments)}),hn=ee,dn=Function.prototype,Ie=dn.call,ms=hn&&dn.bind.bind(Ie,Ie),Tt=hn?ms:function(i){return function(){return Ie.apply(i,arguments)}},un=Tt,gs=un({}.toString),bs=un("".slice),fn=function(i){return bs(gs(i),8,-1)},Es=fn,Cs=Tt,vn=function(i){if(Es(i)==="Function")return Cs(i)},we=typeof document=="object"&&document.all,_s=typeof we=="undefined"&&we!==void 0,pn={all:we,IS_HTMLDDA:_s},yn=pn,Is=yn.all,ft=yn.IS_HTMLDDA?function(i){return typeof i=="function"||i===Is}:function(i){return typeof i=="function"},mn={},ws=ut,Mt=!ws(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),Ss=ee,Ht=Function.prototype.call,Be=Ss?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},gn={},bn={}.propertyIsEnumerable,En=Object.getOwnPropertyDescriptor,Ts=En&&!bn.call({1:2},1);gn.f=Ts?function(t){var e=En(this,t);return!!e&&e.enumerable}:bn;var Cn=function(i,t){return{enumerable:!(i&1),configurable:!(i&2),writable:!(i&4),value:t}},$s=Tt,Rs=ut,xs=fn,ce=Object,Os=$s("".split),As=Rs(function(){return!ce("z").propertyIsEnumerable(0)})?function(i){return xs(i)=="String"?Os(i,""):ce(i)}:ce,_n=function(i){return i==null},js=_n,Ls=TypeError,In=function(i){if(js(i))throw Ls("Can't call method on "+i);return i},Ps=As,Ms=In,Ns=function(i){return Ps(Ms(i))},vi=ft,wn=pn,ks=wn.all,ie=wn.IS_HTMLDDA?function(i){return typeof i=="object"?i!==null:vi(i)||i===ks}:function(i){return typeof i=="object"?i!==null:vi(i)},Sn={},he=Sn,de=at,Vs=ft,pi=function(i){return Vs(i)?i:void 0},Tn=function(i,t){return arguments.length<2?pi(he[i])||pi(de[i]):he[i]&&he[i][t]||de[i]&&de[i][t]},Bs=Tt,Fs=Bs({}.isPrototypeOf),Ds=typeof navigator!="undefined"&&String(navigator.userAgent)||"",$n=at,ue=Ds,yi=$n.process,mi=$n.Deno,gi=yi&&yi.versions||mi&&mi.version,bi=gi&&gi.v8,z,Zt;bi&&(z=bi.split("."),Zt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!Zt&&ue&&(z=ue.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=ue.match(/Chrome\/(\d+)/),z&&(Zt=+z[1])));var Ws=Zt,Ei=Ws,Hs=ut,Us=at,Gs=Us.String,Rn=!!Object.getOwnPropertySymbols&&!Hs(function(){var i=Symbol();return!Gs(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&Ei&&Ei<41}),zs=Rn,xn=zs&&!Symbol.sham&&typeof Symbol.iterator=="symbol",qs=Tn,Qs=ft,Ys=Fs,Ks=xn,Xs=Object,On=Ks?function(i){return typeof i=="symbol"}:function(i){var t=qs("Symbol");return Qs(t)&&Ys(t.prototype,Xs(i))},Zs=String,Js=function(i){try{return Zs(i)}catch(t){return"Object"}},ta=ft,ea=Js,ia=TypeError,An=function(i){if(ta(i))return i;throw ia(ea(i)+" is not a function")},na=An,ra=_n,sa=function(i,t){var e=i[t];return ra(e)?void 0:na(e)},fe=Be,ve=ft,pe=ie,aa=TypeError,oa=function(i,t){var e,n;if(t==="string"&&ve(e=i.toString)&&!pe(n=fe(e,i))||ve(e=i.valueOf)&&!pe(n=fe(e,i))||t!=="string"&&ve(e=i.toString)&&!pe(n=fe(e,i)))return n;throw aa("Can't convert object to primitive value")},jn={exports:{}},Ci=at,la=Object.defineProperty,ca=function(i,t){try{la(Ci,i,{value:t,configurable:!0,writable:!0})}catch(e){Ci[i]=t}return t},ha=at,da=ca,_i="__core-js_shared__",ua=ha[_i]||da(_i,{}),fa=ua,Ii=fa;(jn.exports=function(i,t){return Ii[i]||(Ii[i]=t!==void 0?t:{})})("versions",[]).push({version:"3.31.0",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"});var va=jn.exports,pa=In,ya=Object,Ln=function(i){return ya(pa(i))},ma=Tt,ga=Ln,ba=ma({}.hasOwnProperty),Fe=Object.hasOwn||function(t,e){return ba(ga(t),e)},Ea=Tt,Ca=0,_a=Math.random(),Ia=Ea(1 .toString),wa=function(i){return"Symbol("+(i===void 0?"":i)+")_"+Ia(++Ca+_a,36)},Sa=at,Ta=va,wi=Fe,$a=wa,Ra=Rn,xa=xn,_t=Sa.Symbol,ye=Ta("wks"),Oa=xa?_t.for||_t:_t&&_t.withoutSetter||$a,Aa=function(i){return wi(ye,i)||(ye[i]=Ra&&wi(_t,i)?_t[i]:Oa("Symbol."+i)),ye[i]},ja=Be,Si=ie,Ti=On,La=sa,Pa=oa,Ma=Aa,Na=TypeError,ka=Ma("toPrimitive"),Va=function(i,t){if(!Si(i)||Ti(i))return i;var e=La(i,ka),n;if(e){if(t===void 0&&(t="default"),n=ja(e,i,t),!Si(n)||Ti(n))return n;throw Na("Can't convert object to primitive value")}return t===void 0&&(t="number"),Pa(i,t)},Ba=Va,Fa=On,Pn=function(i){var t=Ba(i,"string");return Fa(t)?t:t+""},Da=at,$i=ie,Se=Da.document,Wa=$i(Se)&&$i(Se.createElement),Ha=function(i){return Wa?Se.createElement(i):{}},Ua=Mt,Ga=ut,za=Ha,Mn=!Ua&&!Ga(function(){return Object.defineProperty(za("div"),"a",{get:function(){return 7}}).a!=7}),qa=Mt,Qa=Be,Ya=gn,Ka=Cn,Xa=Ns,Za=Pn,Ja=Fe,to=Mn,Ri=Object.getOwnPropertyDescriptor;mn.f=qa?Ri:function(t,e){if(t=Xa(t),e=Za(e),to)try{return Ri(t,e)}catch(n){}if(Ja(t,e))return Ka(!Qa(Ya.f,t,e),t[e])};var eo=ut,io=ft,no=/#|\.prototype\./,Nt=function(i,t){var e=so[ro(i)];return e==oo?!0:e==ao?!1:io(t)?eo(t):!!t},ro=Nt.normalize=function(i){return String(i).replace(no,".").toLowerCase()},so=Nt.data={},ao=Nt.NATIVE="N",oo=Nt.POLYFILL="P",lo=Nt,xi=vn,co=An,ho=ee,uo=xi(xi.bind),fo=function(i,t){return co(i),t===void 0?i:ho?uo(i,t):function(){return i.apply(t,arguments)}},Nn={},vo=Mt,po=ut,yo=vo&&po(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),mo=ie,go=String,bo=TypeError,Eo=function(i){if(mo(i))return i;throw bo(go(i)+" is not an object")},Co=Mt,_o=Mn,Io=yo,Ut=Eo,Oi=Pn,wo=TypeError,me=Object.defineProperty,So=Object.getOwnPropertyDescriptor,ge="enumerable",be="configurable",Ee="writable";Nn.f=Co?Io?function(t,e,n){if(Ut(t),e=Oi(e),Ut(n),typeof t=="function"&&e==="prototype"&&"value"in n&&Ee in n&&!n[Ee]){var r=So(t,e);r&&r[Ee]&&(t[e]=n.value,n={configurable:be in n?n[be]:r[be],enumerable:ge in n?n[ge]:r[ge],writable:!1})}return me(t,e,n)}:me:function(t,e,n){if(Ut(t),e=Oi(e),Ut(n),_o)try{return me(t,e,n)}catch(r){}if("get"in n||"set"in n)throw wo("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var To=Mt,$o=Nn,Ro=Cn,xo=To?function(i,t,e){return $o.f(i,t,Ro(1,e))}:function(i,t,e){return i[t]=e,i},Gt=at,Oo=ys,Ao=vn,jo=ft,Lo=mn.f,Po=lo,pt=Sn,Mo=fo,yt=xo,Ai=Fe,No=function(i){var t=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new i;case 1:return new i(e);case 2:return new i(e,n)}return new i(e,n,r)}return Oo(i,this,arguments)};return t.prototype=i.prototype,t},ko=function(i,t){var e=i.target,n=i.global,r=i.stat,s=i.proto,c=n?Gt:r?Gt[e]:(Gt[e]||{}).prototype,o=n?pt:pt[e]||yt(pt,e,{})[e],l=o.prototype,h,v,u,p,g,E,w,d,f;for(p in t)h=Po(n?p:e+(r?".":"#")+p,i.forced),v=!h&&c&&Ai(c,p),E=o[p],v&&(i.dontCallGetSet?(f=Lo(c,p),w=f&&f.value):w=c[p]),g=v&&w?w:t[p],!(v&&typeof E==typeof g)&&(i.bind&&v?d=Mo(g,Gt):i.wrap&&v?d=No(g):s&&jo(g)?d=Ao(g):d=g,(i.sham||g&&g.sham||E&&E.sham)&&yt(d,"sham",!0),yt(o,p,d),s&&(u=e+"Prototype",Ai(pt,u)||yt(pt,u,{}),yt(pt[u],p,g),i.real&&l&&(h||!l[p])&&yt(l,p,g)))},Vo=Math.ceil,Bo=Math.floor,Fo=Math.trunc||function(t){var e=+t;return(e>0?Bo:Vo)(e)},Do=Fo,kn=function(i){var t=+i;return t!==t||t===0?0:Do(t)},Wo=kn,Ho=Math.min,Uo=function(i){return i>0?Ho(Wo(i),9007199254740991):0},Go=Uo,zo=function(i){return Go(i.length)},qo=ko,Qo=Ln,Yo=zo,Ko=kn;qo({target:"Array",proto:!0},{at:function(t){var e=Qo(this),n=Yo(e),r=Ko(t),s=r>=0?r:n+r;return s<0||s>=n?void 0:e[s]}});var Xo=Tn,Zo=Xo,Jo=Zo,tl=Jo("Array","at"),el=tl,il=el,nl=il,rl=nl,ji=fs(rl);const Li=(i,t)=>{const e={};return i.map(n=>{if(!e[n]){const r=t.chapters.find(c=>c.id===n);if(!r)return null;const s=t.media.videos.find(c=>r.videoId===c.id);if(!s)return null;e[n]=Vn(s)}return e[n]}).filter(Boolean)},sl=i=>{for(const t of i.variants)if(al(t)&&"payload"in t)return t.payload.id},al=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Vn=i=>{const t=sl(i);if(!t)return null;const e=t.split("_").pop();return e?parseInt(e,10):null},ol=(i,t)=>{for(const e of i.media.videos)if(t===Vn(e)){for(const n of i.chapters)if(n.videoId===e.id)return n.id;return}},ll=(i,t)=>i.reduce((e,n)=>{const r=ol(t,n);return r?[...e,r]:e},[]);var tt,mt,gt,G,Te,et,it,K,bt,$t,Et;class cl{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){var c,o,l;this.state={history$:new F([]),hasPrevChapter$:new F(!1),prevChapter$:new F(null),isInitialChapter$:new F(!1),isGoBackLimited$:new F(!1)},tt.set(this,null),mt.set(this,void 0),gt.set(this,!1),G.set(this,null),Te.set(this,null),et.set(this,null),it.set(this,null),K.set(this,null),bt.set(this,new Jt),$t.set(this,!1),Et.set(this,0),b(this,et,e,"f"),b(this,K,t,"f"),b(this,it,n,"f"),b(this,tt,r,"f"),b(this,mt,s,"f"),!((c=this.state)===null||c===void 0)&&c.history$&&a(this,bt,"f")&&((o=a(this,bt,"f"))===null||o===void 0||o.add((l=this.state)===null||l===void 0?void 0:l.history$.subscribe(h=>{var v,u,p,g,E,w;(v=this.state)===null||v===void 0||v.prevChapter$.next(ji(h,-2)||null),(u=this.state)===null||u===void 0||u.hasPrevChapter$.next(h.length>1),(p=this.state)===null||p===void 0||p.isInitialChapter$.next(this.getInitialChapterId()===((E=(g=a(this,G,"f"))===null||g===void 0?void 0:g.metadata)===null||E===void 0?void 0:E.initChapterId)),(w=this.state)===null||w===void 0||w.isGoBackLimited$.next(a(this,Et,"f")===a(this,mt,"f").maxLength-1)})))}async setManifest(t){!a(this,it,"f")||!a(this,K,"f")||(b(this,G,t,"f"),await this.getProjectHistory(),await a(this,it,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,gt,"f")||(b(this,gt,!0,"f"),a(this,K,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,gt,"f")}async updateHistory(t,e=!0){var n,r,s;if(!a(this,G,"f"))return;a(this,$t,"f")?(b(this,$t,!1,"f"),b(this,Et,(s=a(this,Et,"f"),s++,s),"f")):b(this,Et,0,"f");const c=a(this,G,"f"),o=t.length-a(this,mt,"f").maxLength,l=o>0?t.slice(o):t,h=Li(l,c);if(b(this,Te,h,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(l),!(!e||!a(this,tt,"f")||!a(this,et,"f")))try{await a(this,tt,"f").save(a(this,et,"f"),h)}catch(v){(r=a(this,K,"f"))===null||r===void 0||r.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var t;if(!this.state||!a(this,it,"f"))return(t=a(this,K,"f"))===null||t===void 0?void 0:t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));b(this,$t,!0,"f");const e=this.state.history$.getValue().slice(0,-1),n=e.pop();this.state.history$.next(e),await a(this,it,"f").setChapter({chapterId:n})}async getProjectHistory(){var t,e;if(!a(this,G,"f")||!a(this,et,"f"))return;const n=a(this,G,"f");let r=[this.getInitialVideoId()];if(a(this,tt,"f"))try{const c=await a(this,tt,"f").get(a(this,et,"f"));c.length&&(r=c)}catch(c){(t=a(this,K,"f"))===null||t===void 0||t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}const s=ll(r,n);(e=this===null||this===void 0?void 0:this.state)===null||e===void 0||e.history$.next(s)}getInitialChapterId(){var t,e;const n=(t=this.state)===null||t===void 0?void 0:t.history$.getValue();return ji(n,-1)||a(this,mt,"f").initChapterId||((e=a(this,G,"f"))===null||e===void 0?void 0:e.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return Li([t],a(this,G,"f")).pop()}return null}destroy(){var t,e;this.state=null,b(this,et,null,"f"),b(this,tt,null,"f"),b(this,it,null,"f"),(t=a(this,bt,"f"))===null||t===void 0||t.unsubscribe(),b(this,bt,null,"f"),b(this,gt,!1,"f"),(e=a(this,K,"f"))===null||e===void 0||e.emit(_.historyDestroyed),b(this,K,null,"f")}}tt=new WeakMap,mt=new WeakMap,gt=new WeakMap,G=new WeakMap,Te=new WeakMap,et=new WeakMap,it=new WeakMap,K=new WeakMap,bt=new WeakMap,$t=new WeakMap,Et=new WeakMap;var Rt,Bn,$e,Pi;class Z{constructor(t,e,n,r){this.target=t,this.type=e,this.listener=n,this.options=a(Z,Rt,"m",Bn).call(Z,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}}Rt=Z,Bn=function(t,e){if(e===void 0)return!1;if(typeof e=="boolean")return e;{const n=new Set(["passive","capture"]),r=Object.keys(e).filter(c=>!n.has(c));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),a(Z,Rt,"m",Pi).call(Z,t)?e:e.capture||!1}},Pi=function(t){let e=a(Z,Rt,"f",$e);if(e===void 0){e=!1;try{const n={},r={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);const s=()=>{};t.addEventListener("test",s,n),t.removeEventListener("test",s,n)}catch(n){e=!1}b(Z,Rt,e,"f",$e)}return e||!1};$e={value:void 0};class hl{constructor(){this.bindingMap=new os}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;const s=new Z(t,e,n,r);this.bindingMap.push(e,s)}listenOnce(t,e,n,r){const s=c=>{this.unlisten(t,e,s),n(c)};this.listen(t,e,s,r)}unlisten(t,e,n){if(!this.bindingMap)return;const r=this.bindingMap.get(e)||[];for(const s of r)s.target===t&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(e,s))}removeAll(){if(!this.bindingMap)return;const t=this.bindingMap.getAll();for(const e of t)e.unlisten();this.bindingMap.clear()}}class dl{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const e=(t=this.rootElement.getContext("2d"))===null||t===void 0?void 0:t.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;const n=e.data,r=n.length;for(let s=3;s<r;s+=40)if(n[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===void 0||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,e=!1){const n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n}async save(){const t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))===null||e===void 0||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}}class ul{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=r=>{const s=r!=null?r:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(s);if(this.isContainerTime(s))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(c)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
+ import{loadVKLangPack as Gn,ValueSubject as F,Subscription as Jt,Subject as zn,Observable as Ge,getCurrentBrowser as qn,CurrentClientBrowser as Qn,once as Yn,combine as Kn}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{v4 as Xn}from"uuid";import{Player as Zn}from"@vkontakte/videoplayer-core/es2018.esm.js";const Jn="1.0.11-dev.b72fcea2.0";function Fi(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})`}const q="SDK_NAME",tr="SDK_NAME-controls-container",Di=()=>document.querySelector(`.${tr}`),er=.4,X={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},ze={top:"flex-start",bottom:"flex-end",center:"center"},qe={start:"flex-start",end:"flex-end",center:"center"},Qe={start:"left",end:"right",center:"center"},Wi=({target:i,props:t})=>{var e,n,r,s,c,o;i.style.alignItems=(n=ze[(e=t==null?void 0:t.text)===null||e===void 0?void 0:e.gravityVertical])!==null&&n!==void 0?n:ze.center,i.style.justifyContent=(s=qe[(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.gravityHorizontal])!==null&&s!==void 0?s:qe.center,i.style.textAlign=(o=Qe[(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:Qe.start},Hi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,c,o,l,h;i.style.color=(s=(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.color)!==null&&s!==void 0?s:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.size)!==null&&o!==void 0?o:e.textSize})`,i.textContent=(h=(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.value)!==null&&h!==void 0?h:e.textContent},Ui=({target:i,props:t,fallback:e})=>{var n,r,s,c;i.style.backgroundColor=Fi((r=(n=t==null?void 0:t.background)===null||n===void 0?void 0:n.color)!==null&&r!==void 0?r:e.backgroundColor,(c=(s=t==null?void 0:t.background)===null||s===void 0?void 0:s.alpha)!==null&&c!==void 0?c:e.backgroundAlpha)},Gi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,c,o,l,h,v,u,p,g,E;i.style.border=`calc(${n.height} * ${(c=(s=(r=t==null?void 0:t.shape)===null||r===void 0?void 0:r.border)===null||s===void 0?void 0:s.width)!==null&&c!==void 0?c:e.borderWidth}) solid ${Fi((h=(l=(o=t==null?void 0:t.shape)===null||o===void 0?void 0:o.border)===null||l===void 0?void 0:l.color)!==null&&h!==void 0?h:e.borderColor,(p=(u=(v=t==null?void 0:t.shape)===null||v===void 0?void 0:v.border)===null||u===void 0?void 0:u.alpha)!==null&&p!==void 0?p:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(E=(g=t==null?void 0:t.shape)===null||g===void 0?void 0:g.roundCorners)!==null&&E!==void 0?E:e.roundCorners})`},je=({target:i,layoutParams:t,fallback:e})=>{var n;i.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:e.angle}rad)`},se="int",Le={AREA:`${se}_area`,TEXT:`${se}_text`,BUTTON:`${se}_bttn`};class Pe{constructor(t){this.control=t}createView(t){var e;const n=document.createElement("div");n.classList.add(`${q}-control-container-${this.control.id}`),t(n,this.control.layoutParams);const r=((e=this.control.layoutParams.innerSizesDependOn)!==null&&e!==void 0?e:X.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:r}}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}})}getElement(){return document.querySelector(`.${q}-control-container-${this.control.id}`)}}const zi=i=>{if(i.type.trim().toLowerCase()==="area")return new ir(i)};class ir extends Pe{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");return s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",Le.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",Ui({target:s,props:this.control.props,fallback:{...X,backgroundColor:"transparent"}}),Gi({target:s,props:this.control.props,fallback:{...X,borderAlpha:0},dependsOn:n}),je({target:s,layoutParams:this.control.layoutParams,fallback:X}),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const qi=i=>{if(i.type.trim().toLowerCase()==="button")return new nr(i)};class nr extends Pe{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");s.type="button",s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",Le.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";const c=document.createElement("span");return c.style.display="inline-block",c.style.whiteSpace="pre",c.style.overflow="hidden",c.style.textOverflow="ellipsis",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),Ui({target:s,props:this.control.props,fallback:X}),Gi({target:s,props:this.control.props,fallback:X,dependsOn:n}),Wi({target:s,props:this.control.props}),Hi({target:c,props:this.control.props,fallback:X,dependsOn:n}),s.append(c),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(`.${q}-${this.control.id}`)}}const rr=i=>{if(i.type.trim().toLowerCase()==="text")return new sr(i)};class sr extends Pe{constructor(t){super(t)}createView({parent:t,layoutFn:e}){const{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${q}-${this.control.id}`),s.setAttribute("data-testid",Le.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),Wi({target:s,props:this.control.props}),Hi({target:c,props:this.control.props,fallback:X,dependsOn:n}),s.append(c),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}class ar{constructor(t){this.layout=t}}const or=i=>{if(i.type.trim().toLowerCase()==="relative")return new Qi(i)};class Qi extends ar{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))`}}function a(i,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?i!==t||!n:!t.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(i):n?n.value:t.get(i)}function b(i,t,e,n,r){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?i!==t||!r:!t.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?r.call(i,e):r?r.value=e:t.set(i,e),e}var Ct,zt,Ye;class Yi{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",zt).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),a(this,Ct,"m",zt).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",zt).call(this)}}Ct=new WeakSet,zt=function(){this.controls=a(this,Ct,"m",Ye).call(this)},Ye=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((e,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};const Ki=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new lr(i,t)};class lr extends Yi{constructor(t,e){super(t),this.rootElement=e!=null?e:Di(),this.layout=new Qi(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",qi),this.addControlFactory("text",rr),this.addControlFactory("area",zi)}createView(t){const e=document.createElement("div");return e.classList.add(`${q}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{const r=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(r,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){const t=this.getElement();t&&(t.style.visibility="hidden")}show(){const t=this.getElement();t&&(t.style.visibility="visible")}enable(){const t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){const t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=er,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${q}-${this.container.id}`)}}function Xi(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const Pt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},St=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Me=i=>St(i,Pt.Object),Ce=i=>St(i,Pt.String),ke=i=>St(i,Pt.Array),Zi=i=>St(i,Pt.Number),cr=i=>St(i,Pt.Function),Ke=i=>Zi(i)&&!isNaN(i),At=i=>Me(i)&&Object.keys(i).length===0,Ji=i=>ke(i)&&!i.length,Bt=(i,t)=>Ce(i)&&(t?i.trim():i).length,tn=window.navigator.userAgent.toLowerCase(),hr=/mobi/i.test(tn);tn.indexOf("android")>-1;const dr="video_interactive",ur="videoint",fr=250;class vr{constructor(t){this.onResize=e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))},this.handleChapterChange=e=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(e!=null&&e.id)){(n=this.onError)===null||n===void 0||n.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(e,n=[])=>{var r;if(!Zi(e.graph.edit.chapters[0].x)){this.isReady=!1,(r=this.onError)===null||r===void 0||r.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let s;try{s=await Gn(this.lang,dr,ur)}catch(o){console.log("Unable to load graph language pack")}const{GraphEditor:c}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new c(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:s}),this.ngEditor.on("control",({name:o,chapterId:l})=>{o==="openPreview"&&this.onOpenPreviewClick(l)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo={...o}})}this.visitedChapterIds=new Set(n),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.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=pr(t),this.resizeObserver=new ResizeObserver(Xi(this.onResize,fr)),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===void 0||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)===null||e===void 0||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function pr(i){const 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}const yr=3e3,mr=()=>{let i=[],t=null;return{setPlayer:c=>{t=c},setContainers:c=>{i=c},deleteContainer:c=>{i=i.filter(o=>o.id!==c)},getNextInteractiveTime:(c=yr)=>{if(!i.length||t===null)return null;let o=-1,l=!1;const h=Math.round(t.info.position$.getValue()*1e3);for(const v of i){const u=v.startTime-c;if(u<=h&&(h<=v.endTime||v.endTime===null)){l=!0;break}h<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},Kt=(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},gr="3.1",Xe={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},br={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Er=i=>{const t=[];for(const e of i.chapters){let n;const r=[];for(const{isDefault:o,...l}of e.branches)o&&(n=l.id),r.push(l);let s=[];const c=[];for(const{fallbackStrategy:o,...l}of e.containers){const h=!!l.endTime;let v=[br];switch(o){case"await":h?v=[]:s=[];break;case"default":{const u={type:"onSuspense",action:{type:Xe.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?v=[u]:s=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:Xe[o],args:{}}};h?v=[u]:s=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:Xn(),events:v})}t.push({...e,containers:c,events:s,branches:r})}return i.metadata.version=gr,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}},Cr="3.2",_r=i=>{if(!i.media){const{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:Cr},media:t}}return i},Ir="3.3",wr=(i=[])=>({edit:{chapters:i},view:{}}),Ze={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Sr=i=>{var t;const e=[],n=[];for(const r of i.chapters){const{id:s,x:c,y:o,...l}=r,h=l.containers.map(v=>{var u;return{...v,controls:v.controls.map(({subtype:p,type:g,...E})=>({...E,type:p!=null?p:g})),events:!((u=v.events)===null||u===void 0)&&u.length?v.events:[Ze]}});e.push({id:s,...l,containers:h,events:!((t=l.events)===null||t===void 0)&&t.length?l.events:[Ze]}),n.push({id:s,x:c,y:o})}return{...i,chapters:e,graph:wr(n),metadata:{...i.metadata,version:Ir}}},Tr=[{version:"3.0",migrate:Er},{version:"3.1",migrate:_r},{version:"3.2",migrate:Sr}],$r=i=>Tr.reduce((t,e)=>Kt(t.metadata.version,e.version)?t:e.migrate(t),i),Rr=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),R=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var ht;(function(i){i.GO_NEXT_BUTTON="GO_NEXT_BUTTON",i.GO_NEXT_AREA="GO_NEXT_AREA",i.WATCH_AGAIN="WATCH_AGAIN",i.OPEN_GRAPH="OPEN_GRAPH",i.CLOSE_GRAPH="CLOSE_GRAPH"})(ht||(ht={}));const Je={metadata:"Object",chapters:"Array"},xr="3.0.0",Or="3.3.0",en=i=>{const t=Kt(i,xr);return t===-1?!1:t===0?!0:Kt(i,Or)!==1},Ar=i=>{if(!Me(i))return!1;for(const t in Je)if(!i[t]||!St(i[t],Je[t]))return!1;return en(i.metadata.version)},nn=i=>i.type===Rr.Text;class S{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}S.Severity={RECOVERABLE:1,CRITICAL:2};S.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class rn{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]||[];const 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){const 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){const 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]}}class jr{constructor(t){this.addFn=(e,n=!1)=>{cr(e)&&(this.fns.push(e),n&&this.updateFn())},this.removeFn=(e,n=!1)=>{this.fns=this.fns.filter(r=>r!==e),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),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=[]}}class Lr{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!==null&&e!==void 0?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(t,e){return Pr(...this.loaders[t])(e)}}function Pr(...i){return async function(e){const n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function Xt(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function _e({actions:i,errors:t,chapterId:e,...n}){if(e){const r=i.getManifest(),s=i.getChapter(r.chapters,e);if(s){const c=i.getMedia(r.media,s.videoId),o=i.getGraph(r.graph,s.id);return c?{...n,actions:i,errors:t,result:{chapter:s,media:c,graph:o}}:{...n,errors:Xt(t,_e.name,"Could not find media"),actions:i}}}return{...n,errors:Xt(t,_e.name,"Could not find chapter"),actions:i}}class ti{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}removeEventListener(t,e){if(!(t in this.listeners))return;const n=this.listeners[t];for(let r=0,s=n.length;r<s;r++)if(n[r].callback===e){n.splice(r,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const n=this.listeners[t.type].slice();for(let r=0,s=n.length;r<s;r++){const c=n[r];try{c.callback.call(this,t)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(t.type,c.callback)}return!t.defaultPrevented}}class sn extends ti{constructor(){super(),this.listeners||ti.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class Mr{constructor(){Object.defineProperty(this,"signal",{value:new sn,writable:!0,configurable:!0})}abort(t){let e;try{e=new Event("abort")}catch(r){typeof document!="undefined"?document.createEvent?(e=document.createEvent("Event"),e.initEvent("abort",!1,!1)):(e=document.createEventObject(),e.type="abort"):e={type:"abort",bubbles:!1,cancelable:!1}}let n=t;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(r){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(Mr.prototype[Symbol.toStringTag]="AbortController",sn.prototype[Symbol.toStringTag]="AbortSignal");function an(i){return i.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof i.Request=="function"&&!i.Request.prototype.hasOwnProperty("signal")||!i.AbortController}function kr(i){typeof i=="function"&&(i={fetch:i});const{fetch:t,Request:e=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!an({fetch:t,Request:e,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:t,Request:s};let s=e;(s&&!s.prototype.hasOwnProperty("signal")||r)&&(s=function(h,v){let u;v&&v.signal&&(u=v.signal,delete v.signal);const p=new e(h,v);return u&&Object.defineProperty(p,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),p},s.prototype=e.prototype);const c=t;return{fetch:(l,h)=>{const v=s&&s.prototype.isPrototypeOf(l)?l.signal:h?h.signal:void 0;if(v){let u;try{u=new DOMException("Aborted","AbortError")}catch(g){u=new Error("Aborted"),u.name="AbortError"}if(v.aborted)return Promise.reject(u);const p=new Promise((g,E)=>{v.addEventListener("abort",()=>E(u),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([p,c(l,h)])}return c(l,h)},Request:s}}const Ne=an({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),on=Ne?kr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,ei=Ne?on.fetch:window.fetch;Ne?on.Request:window.Request;const Nr=async i=>{try{let t,e;if(Me(i))t=i;else if(Ce(i)){e=new URL(i).href;const r=await ei(e);if(!r.ok)return{};t=await r.json()}else return{};if(!Ar(t))return{};const n=t.metadata.media;if(Ce(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);const s=await ei(r);if(!s.ok)throw new Error;t.metadata.media=await s.json()}catch(r){return Dr(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}};async function Vr(i){const{manifest:t,manifestURL:e}=await Nr(i),n=$r(t);return n.media=Br(n.media,e),delete n.metadata.media,n}function ae(i,t){return i.find(e=>e.id===t)}function ii(i,t){var e,n;return!((e=i.edit)===null||e===void 0)&&e.chapters?i.edit.chapters.find(r=>r.id===t):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(r=>r.id===t):void 0}function ni(i,t){return i.videos.find(e=>e.id===t)}function Br(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{const r=Fr(n.url,t);return{...n,url:r||n.url}})}))}}function Fr(i,t){try{return new URL(i,t).href}catch(e){return""}}function Dr(i){return Kt(i,"3.2.0")>=0}const A=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ve=i=>ke(i)&&!Ji(i),te=i=>i.order==="end",Wr=i=>ke(i.containers)&&!Ji(i.containers)&&te(i),Hr=(i,t)=>{var e;const n=i*1e3;return Ve(t.controls)&&n<((e=t.startTime)!==null&&e!==void 0?e:0)},ri=(i,t)=>{var e,n;const r=i*1e3;return Ve(t.controls)&&r>=((e=t.startTime)!==null&&e!==void 0?e:0)&&r<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Lt=i=>i.some(t=>t.action.type==="expect"),si=i=>i.find(t=>t.action.type==="expect"),Ur=i=>(i==null?void 0:i.length)===1,ln=i=>Ur(i)&&nn(i[0]),Gr=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),zr=(i=[])=>i.reduce((t,e,n)=>{var r,s,c;const o=((r=e==null?void 0:e.controls)!==null&&r!==void 0?r:[]).filter(l=>!nn(l));if(Ve(o)){const l=[(s=e.startTime)!==null&&s!==void 0?s:0,(c=e.endTime)!==null&&c!==void 0?c:1/0],h=e.id;if(!n)t.push({subjects:[h],range:l});else{const v=[];let u=-1/0,p=1/0,g=[];const E=[];for(let w=0;w<t.length;w++){const d=t[w];if(E.push(...d.subjects),d.range[0]<p&&(p=d.range[0]),d.range[1]>u&&(u=d.range[1]),d.range[0]<=l[0]&&d.range[1]>=l[1])return t[w].subjects.push(h),t;l[0]>=d.range[0]&&l[0]<=d.range[1]&&(v.push(w),g=g.concat(d.subjects),l[0]=d.range[0]),l[1]>=d.range[0]&&l[1]<=d.range[1]&&(v.push(w),g=g.concat(d.subjects),l[1]=d.range[1])}if(E.push(h),l[0]<=p&&l[1]>=u)return[{subjects:E,range:l}];v.length&&v.reverse().forEach(w=>{t.splice(w,1)}),t.push({subjects:g.concat([h]),range:l})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),qr=(i,t)=>Lt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Lt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);class Qr extends Lr{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new F(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var e;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Xt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const r=await Vr((e=n.result)!==null&&e!==void 0?e:t);return this.manifest=r,this}async setInitial(){return this.setNext()}async setNext(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);const e=await this.exec("chapterLoaders",_e({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ii,getChapter:ae,getMedia:ni,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){const e=ae(this.manifest.chapters,t);if(e){const n=ni(this.manifest.media,e.videoId),r=ii(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:r}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{const e=ae(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{const 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 te(this.chapter)}}const Yr=i=>{const t=i.variants.find(e=>{var n;return((n=e.payload)===null||n===void 0?void 0:n.type)==="vk"});if(t&&"payload"in t){const[e,n]=t.payload.id.split("_");return[e,n]}return[]},_={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ai={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},j={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Kr(){const i=new Map;function t({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...c}){const o=i.get(r),l={...c};return o?o[s]=l:i.set(r,{[s]:l}),{listId:r,itemId:s,...c}}function e(r,s){var c,o,l;const h=i.get(r);if(h){if(s)return(c=h[s])===null||c===void 0||c.player.destroy(),(o=h[s])===null||o===void 0||o.container.remove(),(l=h[s])===null||l===void 0||l.subscription.unsubscribe(),delete h[s],Object.keys(h).length||i.delete(r),!0;for(const v of Object.values(h))v.player.destroy(),v.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(const r of i)e(r[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function oi(i,t=[]){var e,n,r;let s={},c;const o=!t.length;for(const l of i.variants)if(!c&&"cover"in l&&(c=l.cover),"url"in l)switch(l.type.toLowerCase()){case"mp4":(o||t.includes("mp4"))&&(s.MPEG={...s.MPEG,[(e=l.standard)!==null&&e!==void 0?e:"Invariant quality"]:l.url});break;case"mpeg":(o||t.includes("mpeg"))&&(s.MPEG={...s.MPEG,[(n=l.standard)!==null&&n!==void 0?n:"Invariant quality"]:l.url});break;case"hls":(o||t.includes("hls"))&&(s={...s,HLS:{type:"url",url:l.url}});break;case"dash":(o||t.includes("dash"))&&(s={...s,DASH_SEP:{compatibilityMode:!0,type:"url",url:l.url}});break}return{sources:s,thumbUrl:c,title:(r=i.title)!==null&&r!==void 0?r:""}}const Ft=(i,t)=>{const e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))},qt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Xr=2;function Zr(i){const t=Kr();let e,n;const r=new rn;let s={},c=!1,o=null,l=!1,h;i&&v(i);function v(y){o=y}function u(y,C,m){var $;if(!o)throw Error("need to set interactive controller");if(!o.options)return;const L=(($=t.map.get(y))!==null&&$!==void 0?$:{})[C];if(L){s={chapterId:m,listId:y,itemId:C,...L};const I=s.player;n=I.info.currentQuality$.subscribe(N=>{if(!(!N||!I.info.position$.getValue())){e=N;for(const W of t.map)Object.values(W[1]).forEach(({player:M})=>{I.info.isAutoQualityEnabled$.getValue()||Ft(M,N)})}}),L.container.remove(),c=!1,o.setPlayer(L.player),l||(o.init(),l=!0),r.emit(qt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function p(y,C,m){if(!o)throw Error("need to set interactive controller");if(At(s)||y!==s.itemId)return;if(m>=0&&!c){const O=o.getChapterBranches();c=!0;const L=new Set;for(const I of O)L.has(I.media.id)||(await E({media:I.media,chapterId:I.chapter.id,setAsActive:!1,title:I.chapter.label}),L.add(I.media.id))}}async function g({chapter:{id:y},media:C}){if(At(s))return;n==null||n.unsubscribe();const m=s.player.info.muted$.getValue(),$=s.player.info.currentQuality$.getValue(),O=s.player.info.isAutoQualityEnabled$.getValue(),L=s.player.info.volume$.getValue(),I=s.player.info.currentPlaybackRate$.getValue(),N=!O;let W=!1;for(const M of t.map)if(M[0]===C.id){const Q=Object.keys(M[1]);for(const Y of Q)Y===s.itemId?(Q.length<Xr||(W=!0),t.removePlayer(M[0],Y)):(W=!0,u(M[0],Y,y),N?Ft(s.player,$):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(m),s.player.setPlaybackRate(I))}else t.removePlayer(M[0]);W||(await E({media:C,chapterId:y,setAsActive:!0,playbackRate:I}),N?Ft(s.player,$):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(m))}async function E({media:y,chapterId:C,prefetch:m=!0,setAsActive:$=!0,autoplay:O=!1,preferredExt:L,title:I,playbackRate:N}){var W,M,Q,Y,ne;const De=Math.random().toString(),re=document.createElement("div");h.append(re);const Hn=(W=s==null?void 0:s.player)===null||W===void 0?void 0:W.info.isAutoQualityEnabled$.getValue();let Nt;if(!((M=o==null?void 0:o.options)===null||M===void 0)&&M.vkVideoLoader){const Vt=Yr(y);Vt.length&&(Nt=await o.options.vkVideoLoader(...Vt))}const We=((Q=o==null?void 0:o.options)===null||Q===void 0?void 0:Q.coreConfig)||{},Un={...We,configName:[...(Y=We.configName)!==null&&Y!==void 0?Y:[],"interactive"]},He={container:re,...((ne=Nt==null?void 0:Nt.videos)===null||ne===void 0?void 0:ne[0])||{sources:oi(y,L).sources},title:I},ot=new Zn(Un);ot.initVideo(He);const Ue=new Jt;Ue.add(ot.info.position$.subscribe(function(Vt){p(De,ot.info.duration$.getValue(),Vt)})).add(ot.events.canplay$.subscribe(function(){Hn||Ft(ot,e),N&&ot.setPlaybackRate(N)}));const vt=t.createPlayer({listId:y.id,itemId:De,player:ot,container:re,sources:oi(y,L).sources,config:He,subscription:Ue});return $&&u(y.id,vt.itemId,C),O&&vt.player.play(),m&&!O&&vt.player.prepare(),r.emit(qt.playerCreated,vt.player),{player:vt.player,config:vt.config}}function w(){d(),o=null}function d(){o==null||o.off(_.chapterChanged,g),t.removeAll(),s={},l=!1,c=!1}async function f({container:y}){if(!o)throw Error("need to set interactive controller");d(),h=y;const{media:C,chapter:m}=o.getCurrentChapter();if(C){o.on(_.chapterChanged,g);const{player:$,config:O}=await E({media:C,chapterId:m.id,title:m.label});return r.emit(qt.initiated,{container:y,media:C,chapterId:m.id}),{player:$,config:O}}else console.error("not found")}return{...t,on:r.on.bind(r),off:r.off.bind(r),init:f,setInteractiveController:v,createPlayer:E,removeAll:w,getActivePlayer:function(){return s}}}class Jr{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:c,ignoreContainerEvent:o,permanentTextControls:l,disabledControls$:h,onRemove:v}){this.hide=()=>{setTimeout(()=>{var u,p;this.gameState!==A.end&&(Lt(this.container.container.events)&&this.gameState===A.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==A.interactive&&((p=(u=this.container).hide)===null||p===void 0||p.call(u)),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})))})},this.show=()=>{var u,p,g,E;if(this.gameState===A.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(E=(g=this.container).show)===null||E===void 0||E.call(g),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!0,isFirst:!1});else{const d=Gr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})},onEvent:(f,y)=>{this.isSelectedControlEvent=!0,f!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})),(this.gameState===A.end||this.gameState===A.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1}))},isEOV:()=>this.gameState===A.end});this.container.createView(d),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((p=(u=this.container).disable)===null||p===void 0||p.call(u))}},this.onEndOfVideo=()=>{this.gameState=A.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var u,p;if(((u=this.player.experimental.element$.getValue())===null||u===void 0?void 0:u.readyState)<1||[A.destroyed,A.removed].includes(this.gameState)&&!this.isPermanentText)return;const E=this.player.getExactTime();if(Hr(E,this.container.container))this.gameState!==A.beforeInteractive&&(this.gameState=A.beforeInteractive,this.onBeforeStartTime());else if(ri(E,this.container.container))this.gameState!==A.interactive&&(this.gameState=A.interactive,this.onStartTime());else if(this.gameState!==A.afterInteractive){const f=this.gameState;this.gameState=A.afterInteractive,f===A.interactive&&this.onEndTime()}else this.gameState!==A.destroyed&&!this.isPermanentText&&this.removeView();const w=ri(E,this.container.container),d=this.container.container.startTime?[this.container.container.startTime,(p=this.container.container.endTime)!==null&&p!==void 0?p:1/0]:[];this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:d,currentTime:E,isInteractiveTime:w})},this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Jt,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=l&&ln(e.container.controls),this.disabledControls$=h,this.onRemove=v,this.globalEventEmitter=c,this.gameState=A.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===void 0||n.call(e):(s=(r=this.container).enable)===null||s===void 0||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);const t=Lt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)===null||e===void 0||e.call(t),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=A.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:j.containerRemoved,visibility:!1}),this.gameState=A.removed,(t=this.onRemove)===null||t===void 0||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=A.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!==null&&t!==void 0?t:1/0,id:this.container.container.id})}}function ts(){const i={};function t(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){const l={};for(const h in i)+h<=o&&(l[h]=i[h]);return l}function n(o){const l={};for(const h in i)+h>=o&&(l[h]=i[h]);return l}function r({timestamp:o,priority:l,initiator:h}){var v;if(Ke(o)){const u=(v=i[o])!==null&&v!==void 0?v:null;if(u&&Bt(l,!0)){let p={};const g=u[l];if(g&&(p={...p,...g}),p=At(p)?null:p,p&&Bt(h,!0)){const E=p[h];return E!=null?E:null}return p}return u}return null}function s({timestamp:o,priority:l,initiator:h}){if(Ke(o))if(i[o]){if(Bt(l,!0))if(i[o][l]){if(Bt(h,!0))if(i[o][l][h]){if(delete i[o][l][h],!At(i[o][l]))return!0}else return!1;if(delete i[o][l],!At(i[o]))return!0}else return!1;return delete i[o]}else return!1}function c({timestamp:o,priority:l,initiator:h,...v}){var u,p,g;!((p=(u=i[o])===null||u===void 0?void 0:u[l])===null||p===void 0)&&p[h]?i[o][l][h].push({...v}):!((g=i[o])===null||g===void 0)&&g[l]?i[o][l]={...i[o][l],[h]:[{...v}]}:i[o]?i[o]={...i[o],[l]:{[h]:[{...v}]}}:i[o]={[l]:{[h]:[{...v}]}}}return{map:i,remove:s,add:c,removeAll:t,get:r,getLte:e,getGte:n}}const es=[R.expect,R.setNextBranch],is=1/0;function li(i){let t=i,e;const n=ns(),r=new ts;let s;const c=()=>{p(),d()},o=f=>{r.add.call(void 0,f),g()},l=(f=[])=>{for(const y of f)if(y.action(),es.includes(y.actionType))break},h=(f=1/0)=>{var y,C,m;const $=Dt((y=r.get({timestamp:f,priority:"control"}))!==null&&y!==void 0?y:{}),O=Dt((C=r.get({timestamp:f,priority:"container"}))!==null&&C!==void 0?C:{}),L=Dt((m=r.get({timestamp:f,priority:"chapter"}))!==null&&m!==void 0?m:{});return[...$,...O,...L]},v=f=>{n.isReady(f)&&l(h(f))},u=()=>{var f;l([...Dt((f=r.get({timestamp:1/0,priority:"chapter"}))!==null&&f!==void 0?f:{})])},p=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},g=()=>{e||(e=()=>setTimeout(()=>{v(1/0)}),s=t.events.ended$.subscribe(e))},E=f=>{p(),t=f},w=f=>{f.priority==="container"&&n.resetCalled(f.timestamp),r.remove(f)},d=()=>{n.release(),r.removeAll()};return{setPlayer:E,add:o,remove:w,exec:v,execEndOfVideo:u,listen:g,unlisten:p,release:c,containersEventsCallState:n,getPreparedToExecActions:h}}function ns(){const i=new Map;return{setCalled:({timestamp:c,id:o})=>{const l=i.get(c);l&&l[o]!==void 0&&(l[o]=!0)},setData:(c=[])=>{var o,l;for(const h of c){const v=(o=h.endTime)!==null&&o!==void 0?o:is,u=(l=i.get(v))!==null&&l!==void 0?l:{};i.set(v,{...u,[h.id]:!1})}},resetCalled:c=>{const o=i.get(c);if(o)for(const l in o)o[l]=!1},isReady:c=>{const o=i.get(c);return o?!Object.values(o).some(l=>!l):!0},release:()=>i.clear()}}function Dt(i){return Object.values(i).flat().sort(t=>t.actionType===R.expect?-1:1)}const rs=(i,t)=>{const{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:r,clientWidth:s}=t.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};const c=e/n,o=r/s;let l,h;return o>c?(h=s,l=s*c):o<c?(h=r/c,l=r):(h=s,l=r),{videoContentWidth:h,videoContentHeight:l}},ss=250;function as(i){let t=()=>{};const e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){const{parentElement:l,player:h}=i();if(l&&h){const{videoContentWidth:v,videoContentHeight:u}=rs(l,h);l.style.setProperty("--interactive-content-width",`${v}px`),l.style.setProperty("--interactive-content-height",`${u}px`),l.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),l.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function r(){const{parentElement:o}=i();o.removeAttribute("style")}const s=Xi(o=>{const{fns:l=[]}=i();n(o);for(const h of l)h()},ss);function c(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:c}}class os{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){const e=this.map[t];return e?e.slice():null}getAll(){const t=[];for(const 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)}}const ls=i=>Math.floor(Math.random()*i),cs=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},hs=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},ds=i=>{const t=i.length,e=ls(t);return i[e]},ci=1,us=i=>{var t,e;let n=0;for(let s=0;s<i.length;++s)n+=(t=i[s].weight)!==null&&t!==void 0?t:ci;const r=Math.random()*n;n=0;for(let s=0;s<i.length-1;++s)if(n+=(e=i[s].weight)!==null&&e!==void 0?e:ci,n>=r)return i[s];return i[i.length-1]},hi=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),oe=(i,t=!1)=>({...i,args:t?{...i.args,...hi}:{...hi,...i.args}}),di=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},c=({action:d,controlType:f,controlId:y,containerId:C,branches:m=[],onEvent:$,isEOV:O=()=>!1,isDisabled:L=()=>!1})=>{const I=oe(d,O()),N={timestamp:1/0,priority:"control",initiator:y,actionType:I.type},W=L(),M=i.emit.bind(i,_.interactives,{subjectId:y,subjectType:f,subjectName:"control",type:W?j.actionChoiceCanceled:j.actionChoice,actionType:d.type,payload:{containerId:C,...I.args}});if(W){M();return}switch(I.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const Q=m.find(Y=>Y.id===I.args.branchId);if(!Q)return;$(I.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),I.args.shouldOpenNow?E({subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{chapterId:Q.chapterId,autoSelect:!1}}):(e.add({...N,action:E.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{chapterId:Q.chapterId,autoSelect:!1}})}),n==null||n());return}case R.continuePlayback.trim().toLowerCase():{$(I.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),I.args.shouldOpenNow?g({subjectId:y,subjectName:"control",subjectType:f,action:d}):e.add({...N,action:g.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:d})});return}case R.openURI.trim().toLowerCase():{$(I.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),I.args.shouldOpenNow?w({subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{URI:d.args.uri}}):(e.add({...N,action:w.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:I,payload:{URI:d.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:d,container:{id:f,endTime:y},branches:C=[],isEOV:m=!1,autoSelected:$=!1})=>{const O=oe(d,m),L={timestamp:!O.args.shouldOpenNow||m?1/0:y,priority:"container",initiator:f,actionType:O.type},I=i.emit.bind(i,_.interactives,{subjectId:f,subjectName:"container",type:j.actionChoice,actionType:O.type,payload:O.args});switch(O.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const N=C.find(W=>W.id===O.args.branchId);if(!N)return;I(),e.add({...L,action:E.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{chapterId:N.chapterId,autoSelect:$}})}),n==null||n();return}case R.setMaxWeightBranch.trim().toLowerCase():return;case R.setMinWeightBranch.trim().toLowerCase():return;case R.setRandomBranch.trim().toLowerCase():return;case R.setWeightlessRandomBranch.trim().toLowerCase():return;case R.continuePlayback.trim().toLowerCase():{I(),e.add({...L,action:g.bind(null,{subjectId:f,subjectName:"container",action:O})});return}case R.openURI.trim().toLowerCase():{I(),e.add({...L,action:w.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{URI:d.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:d,branches:f,isEOV:y=!1}){const C=si(d.events);if(C){const m=oe(C.action,y);i.emit(_.interactives,{subjectId:d.id,subjectName:"container",type:j.actionChoice,actionType:m.type,payload:m.args}),e.add({timestamp:y?1/0:d.endTime,priority:"container",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"container"})}),r.isExpect=!0}else for(const m of d.events)o({action:m.action,container:d,branches:f,isEOV:y})}const h=({chapterId:d,action:f,branches:y=[]})=>{const C=i.emit.bind(i,_.interactives,{subjectId:d,subjectName:"chapter",type:j.actionChoice,actionType:f.type,payload:f.args});switch(f.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const m=y.find($=>$.id===f.args.branchId);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setWeightlessRandomBranch.trim().toLowerCase():{const m=ds(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setRandomBranch.trim().toLowerCase():{const m=us(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMaxWeightBranch.trim().toLowerCase():{const m=hs(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMinWeightBranch.trim().toLowerCase():{const m=cs(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.continuePlayback.trim().toLowerCase():return C(),g.bind(null,{subjectId:d,subjectName:"chapter",action:f});case R.openURI.trim().toLowerCase():return C(),w.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{URI:f.args.uri}});default:console.error("Unexpected chapter event"),i.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(d){const f=si(d.events);if(f){if(te(d))return;i.emit(_.interactives,{subjectId:d.id,subjectName:"chapter",type:j.actionChoice,actionType:f.action.type,payload:f.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"chapter"})})}else d.events.forEach(y=>{const C=h({chapterId:d.id,action:y.action,branches:d.branches});C&&e.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:y.action.type,action:C})})}const u=({subjectId:d,subjectName:f,action:y})=>{var C;t.pause(),i.emit(_.interactives,{subjectId:d,subjectName:f,type:j.actionExecution,actionType:(C=y==null?void 0:y.type)!==null&&C!==void 0?C:R.expect})},p=({subjectId:d,subjectName:f})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(_.interactives,{subjectId:d,subjectName:f,type:j.actionExecution,actionType:"after-expect"})},g=({subjectId:d,subjectName:f,subjectType:y,action:C})=>{i.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:j.actionExecution,actionType:C.type})},E=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{m.behaviour="change-chapter",i.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:j.actionExecution,actionType:C.type,payload:m})},w=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{if(!m.URI)return;const $=window.open(m.URI,"_blank","noopener,noreferrer");$&&($.opener=null),i.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:j.actionExecution,actionType:C.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:h,onExpectEvent:u,expectEventHandler:p,setManifestChapterEvents:v,setManifestContainerEvents:l,stopExpect:s,state:r}};var le=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function fs(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Wt=function(i){return i&&i.Math==Math&&i},at=Wt(typeof globalThis=="object"&&globalThis)||Wt(typeof window=="object"&&window)||Wt(typeof self=="object"&&self)||Wt(typeof le=="object"&&le)||function(){return this}()||le||Function("return this")(),ut=function(i){try{return!!i()}catch(t){return!0}},vs=ut,ee=!vs(function(){var i=function(){}.bind();return typeof i!="function"||i.hasOwnProperty("prototype")}),ps=ee,cn=Function.prototype,ui=cn.apply,fi=cn.call,ys=typeof Reflect=="object"&&Reflect.apply||(ps?fi.bind(ui):function(){return fi.apply(ui,arguments)}),hn=ee,dn=Function.prototype,Ie=dn.call,ms=hn&&dn.bind.bind(Ie,Ie),Tt=hn?ms:function(i){return function(){return Ie.apply(i,arguments)}},un=Tt,gs=un({}.toString),bs=un("".slice),fn=function(i){return bs(gs(i),8,-1)},Es=fn,Cs=Tt,vn=function(i){if(Es(i)==="Function")return Cs(i)},we=typeof document=="object"&&document.all,_s=typeof we=="undefined"&&we!==void 0,pn={all:we,IS_HTMLDDA:_s},yn=pn,Is=yn.all,ft=yn.IS_HTMLDDA?function(i){return typeof i=="function"||i===Is}:function(i){return typeof i=="function"},mn={},ws=ut,Mt=!ws(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),Ss=ee,Ht=Function.prototype.call,Be=Ss?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},gn={},bn={}.propertyIsEnumerable,En=Object.getOwnPropertyDescriptor,Ts=En&&!bn.call({1:2},1);gn.f=Ts?function(t){var e=En(this,t);return!!e&&e.enumerable}:bn;var Cn=function(i,t){return{enumerable:!(i&1),configurable:!(i&2),writable:!(i&4),value:t}},$s=Tt,Rs=ut,xs=fn,ce=Object,Os=$s("".split),As=Rs(function(){return!ce("z").propertyIsEnumerable(0)})?function(i){return xs(i)=="String"?Os(i,""):ce(i)}:ce,_n=function(i){return i==null},js=_n,Ls=TypeError,In=function(i){if(js(i))throw Ls("Can't call method on "+i);return i},Ps=As,Ms=In,ks=function(i){return Ps(Ms(i))},vi=ft,wn=pn,Ns=wn.all,ie=wn.IS_HTMLDDA?function(i){return typeof i=="object"?i!==null:vi(i)||i===Ns}:function(i){return typeof i=="object"?i!==null:vi(i)},Sn={},he=Sn,de=at,Vs=ft,pi=function(i){return Vs(i)?i:void 0},Tn=function(i,t){return arguments.length<2?pi(he[i])||pi(de[i]):he[i]&&he[i][t]||de[i]&&de[i][t]},Bs=Tt,Fs=Bs({}.isPrototypeOf),Ds=typeof navigator!="undefined"&&String(navigator.userAgent)||"",$n=at,ue=Ds,yi=$n.process,mi=$n.Deno,gi=yi&&yi.versions||mi&&mi.version,bi=gi&&gi.v8,z,Zt;bi&&(z=bi.split("."),Zt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!Zt&&ue&&(z=ue.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=ue.match(/Chrome\/(\d+)/),z&&(Zt=+z[1])));var Ws=Zt,Ei=Ws,Hs=ut,Us=at,Gs=Us.String,Rn=!!Object.getOwnPropertySymbols&&!Hs(function(){var i=Symbol();return!Gs(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&Ei&&Ei<41}),zs=Rn,xn=zs&&!Symbol.sham&&typeof Symbol.iterator=="symbol",qs=Tn,Qs=ft,Ys=Fs,Ks=xn,Xs=Object,On=Ks?function(i){return typeof i=="symbol"}:function(i){var t=qs("Symbol");return Qs(t)&&Ys(t.prototype,Xs(i))},Zs=String,Js=function(i){try{return Zs(i)}catch(t){return"Object"}},ta=ft,ea=Js,ia=TypeError,An=function(i){if(ta(i))return i;throw ia(ea(i)+" is not a function")},na=An,ra=_n,sa=function(i,t){var e=i[t];return ra(e)?void 0:na(e)},fe=Be,ve=ft,pe=ie,aa=TypeError,oa=function(i,t){var e,n;if(t==="string"&&ve(e=i.toString)&&!pe(n=fe(e,i))||ve(e=i.valueOf)&&!pe(n=fe(e,i))||t!=="string"&&ve(e=i.toString)&&!pe(n=fe(e,i)))return n;throw aa("Can't convert object to primitive value")},jn={exports:{}},Ci=at,la=Object.defineProperty,ca=function(i,t){try{la(Ci,i,{value:t,configurable:!0,writable:!0})}catch(e){Ci[i]=t}return t},ha=at,da=ca,_i="__core-js_shared__",ua=ha[_i]||da(_i,{}),fa=ua,Ii=fa;(jn.exports=function(i,t){return Ii[i]||(Ii[i]=t!==void 0?t:{})})("versions",[]).push({version:"3.31.0",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"});var va=jn.exports,pa=In,ya=Object,Ln=function(i){return ya(pa(i))},ma=Tt,ga=Ln,ba=ma({}.hasOwnProperty),Fe=Object.hasOwn||function(t,e){return ba(ga(t),e)},Ea=Tt,Ca=0,_a=Math.random(),Ia=Ea(1 .toString),wa=function(i){return"Symbol("+(i===void 0?"":i)+")_"+Ia(++Ca+_a,36)},Sa=at,Ta=va,wi=Fe,$a=wa,Ra=Rn,xa=xn,_t=Sa.Symbol,ye=Ta("wks"),Oa=xa?_t.for||_t:_t&&_t.withoutSetter||$a,Aa=function(i){return wi(ye,i)||(ye[i]=Ra&&wi(_t,i)?_t[i]:Oa("Symbol."+i)),ye[i]},ja=Be,Si=ie,Ti=On,La=sa,Pa=oa,Ma=Aa,ka=TypeError,Na=Ma("toPrimitive"),Va=function(i,t){if(!Si(i)||Ti(i))return i;var e=La(i,Na),n;if(e){if(t===void 0&&(t="default"),n=ja(e,i,t),!Si(n)||Ti(n))return n;throw ka("Can't convert object to primitive value")}return t===void 0&&(t="number"),Pa(i,t)},Ba=Va,Fa=On,Pn=function(i){var t=Ba(i,"string");return Fa(t)?t:t+""},Da=at,$i=ie,Se=Da.document,Wa=$i(Se)&&$i(Se.createElement),Ha=function(i){return Wa?Se.createElement(i):{}},Ua=Mt,Ga=ut,za=Ha,Mn=!Ua&&!Ga(function(){return Object.defineProperty(za("div"),"a",{get:function(){return 7}}).a!=7}),qa=Mt,Qa=Be,Ya=gn,Ka=Cn,Xa=ks,Za=Pn,Ja=Fe,to=Mn,Ri=Object.getOwnPropertyDescriptor;mn.f=qa?Ri:function(t,e){if(t=Xa(t),e=Za(e),to)try{return Ri(t,e)}catch(n){}if(Ja(t,e))return Ka(!Qa(Ya.f,t,e),t[e])};var eo=ut,io=ft,no=/#|\.prototype\./,kt=function(i,t){var e=so[ro(i)];return e==oo?!0:e==ao?!1:io(t)?eo(t):!!t},ro=kt.normalize=function(i){return String(i).replace(no,".").toLowerCase()},so=kt.data={},ao=kt.NATIVE="N",oo=kt.POLYFILL="P",lo=kt,xi=vn,co=An,ho=ee,uo=xi(xi.bind),fo=function(i,t){return co(i),t===void 0?i:ho?uo(i,t):function(){return i.apply(t,arguments)}},kn={},vo=Mt,po=ut,yo=vo&&po(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),mo=ie,go=String,bo=TypeError,Eo=function(i){if(mo(i))return i;throw bo(go(i)+" is not an object")},Co=Mt,_o=Mn,Io=yo,Ut=Eo,Oi=Pn,wo=TypeError,me=Object.defineProperty,So=Object.getOwnPropertyDescriptor,ge="enumerable",be="configurable",Ee="writable";kn.f=Co?Io?function(t,e,n){if(Ut(t),e=Oi(e),Ut(n),typeof t=="function"&&e==="prototype"&&"value"in n&&Ee in n&&!n[Ee]){var r=So(t,e);r&&r[Ee]&&(t[e]=n.value,n={configurable:be in n?n[be]:r[be],enumerable:ge in n?n[ge]:r[ge],writable:!1})}return me(t,e,n)}:me:function(t,e,n){if(Ut(t),e=Oi(e),Ut(n),_o)try{return me(t,e,n)}catch(r){}if("get"in n||"set"in n)throw wo("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var To=Mt,$o=kn,Ro=Cn,xo=To?function(i,t,e){return $o.f(i,t,Ro(1,e))}:function(i,t,e){return i[t]=e,i},Gt=at,Oo=ys,Ao=vn,jo=ft,Lo=mn.f,Po=lo,pt=Sn,Mo=fo,yt=xo,Ai=Fe,ko=function(i){var t=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new i;case 1:return new i(e);case 2:return new i(e,n)}return new i(e,n,r)}return Oo(i,this,arguments)};return t.prototype=i.prototype,t},No=function(i,t){var e=i.target,n=i.global,r=i.stat,s=i.proto,c=n?Gt:r?Gt[e]:(Gt[e]||{}).prototype,o=n?pt:pt[e]||yt(pt,e,{})[e],l=o.prototype,h,v,u,p,g,E,w,d,f;for(p in t)h=Po(n?p:e+(r?".":"#")+p,i.forced),v=!h&&c&&Ai(c,p),E=o[p],v&&(i.dontCallGetSet?(f=Lo(c,p),w=f&&f.value):w=c[p]),g=v&&w?w:t[p],!(v&&typeof E==typeof g)&&(i.bind&&v?d=Mo(g,Gt):i.wrap&&v?d=ko(g):s&&jo(g)?d=Ao(g):d=g,(i.sham||g&&g.sham||E&&E.sham)&&yt(d,"sham",!0),yt(o,p,d),s&&(u=e+"Prototype",Ai(pt,u)||yt(pt,u,{}),yt(pt[u],p,g),i.real&&l&&(h||!l[p])&&yt(l,p,g)))},Vo=Math.ceil,Bo=Math.floor,Fo=Math.trunc||function(t){var e=+t;return(e>0?Bo:Vo)(e)},Do=Fo,Nn=function(i){var t=+i;return t!==t||t===0?0:Do(t)},Wo=Nn,Ho=Math.min,Uo=function(i){return i>0?Ho(Wo(i),9007199254740991):0},Go=Uo,zo=function(i){return Go(i.length)},qo=No,Qo=Ln,Yo=zo,Ko=Nn;qo({target:"Array",proto:!0},{at:function(t){var e=Qo(this),n=Yo(e),r=Ko(t),s=r>=0?r:n+r;return s<0||s>=n?void 0:e[s]}});var Xo=Tn,Zo=Xo,Jo=Zo,tl=Jo("Array","at"),el=tl,il=el,nl=il,rl=nl,ji=fs(rl);const Li=(i,t)=>{const e={};return i.map(n=>{if(!e[n]){const r=t.chapters.find(c=>c.id===n);if(!r)return null;const s=t.media.videos.find(c=>r.videoId===c.id);if(!s)return null;e[n]=Vn(s)}return e[n]}).filter(Boolean)},sl=i=>{for(const t of i.variants)if(al(t)&&"payload"in t)return t.payload.id},al=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Vn=i=>{const t=sl(i);if(!t)return null;const e=t.split("_").pop();return e?parseInt(e,10):null},ol=(i,t)=>{for(const e of i.media.videos)if(t===Vn(e)){for(const n of i.chapters)if(n.videoId===e.id)return n.id;return}},ll=(i,t)=>i.reduce((e,n)=>{const r=ol(t,n);return r?[...e,r]:e},[]);var tt,mt,gt,G,Te,et,it,K,bt,$t,Et;class cl{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){var c,o,l;this.state={history$:new F([]),hasPrevChapter$:new F(!1),prevChapter$:new F(null),isInitialChapter$:new F(!1),isGoBackLimited$:new F(!1)},tt.set(this,null),mt.set(this,void 0),gt.set(this,!1),G.set(this,null),Te.set(this,null),et.set(this,null),it.set(this,null),K.set(this,null),bt.set(this,new Jt),$t.set(this,!1),Et.set(this,0),b(this,et,e,"f"),b(this,K,t,"f"),b(this,it,n,"f"),b(this,tt,r,"f"),b(this,mt,s,"f"),!((c=this.state)===null||c===void 0)&&c.history$&&a(this,bt,"f")&&((o=a(this,bt,"f"))===null||o===void 0||o.add((l=this.state)===null||l===void 0?void 0:l.history$.subscribe(h=>{var v,u,p,g,E,w;(v=this.state)===null||v===void 0||v.prevChapter$.next(ji(h,-2)||null),(u=this.state)===null||u===void 0||u.hasPrevChapter$.next(h.length>1),(p=this.state)===null||p===void 0||p.isInitialChapter$.next(this.getInitialChapterId()===((E=(g=a(this,G,"f"))===null||g===void 0?void 0:g.metadata)===null||E===void 0?void 0:E.initChapterId)),(w=this.state)===null||w===void 0||w.isGoBackLimited$.next(a(this,Et,"f")===a(this,mt,"f").maxLength-1)})))}async setManifest(t){!a(this,it,"f")||!a(this,K,"f")||(b(this,G,t,"f"),await this.getProjectHistory(),await a(this,it,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,gt,"f")||(b(this,gt,!0,"f"),a(this,K,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,gt,"f")}async updateHistory(t,e=!0){var n,r,s;if(!a(this,G,"f"))return;a(this,$t,"f")?(b(this,$t,!1,"f"),b(this,Et,(s=a(this,Et,"f"),s++,s),"f")):b(this,Et,0,"f");const c=a(this,G,"f"),o=t.length-a(this,mt,"f").maxLength,l=o>0?t.slice(o):t,h=Li(l,c);if(b(this,Te,h,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(l),!(!e||!a(this,tt,"f")||!a(this,et,"f")))try{await a(this,tt,"f").save(a(this,et,"f"),h)}catch(v){(r=a(this,K,"f"))===null||r===void 0||r.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var t;if(!this.state||!a(this,it,"f"))return(t=a(this,K,"f"))===null||t===void 0?void 0:t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));b(this,$t,!0,"f");const e=this.state.history$.getValue().slice(0,-1),n=e.pop();this.state.history$.next(e),await a(this,it,"f").setChapter({chapterId:n})}async getProjectHistory(){var t,e;if(!a(this,G,"f")||!a(this,et,"f"))return;const n=a(this,G,"f");let r=[this.getInitialVideoId()];if(a(this,tt,"f"))try{const c=await a(this,tt,"f").get(a(this,et,"f"));c.length&&(r=c)}catch(c){(t=a(this,K,"f"))===null||t===void 0||t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}const s=ll(r,n);(e=this===null||this===void 0?void 0:this.state)===null||e===void 0||e.history$.next(s)}getInitialChapterId(){var t,e;const n=(t=this.state)===null||t===void 0?void 0:t.history$.getValue();return ji(n,-1)||a(this,mt,"f").initChapterId||((e=a(this,G,"f"))===null||e===void 0?void 0:e.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return Li([t],a(this,G,"f")).pop()}return null}destroy(){var t,e;this.state=null,b(this,et,null,"f"),b(this,tt,null,"f"),b(this,it,null,"f"),(t=a(this,bt,"f"))===null||t===void 0||t.unsubscribe(),b(this,bt,null,"f"),b(this,gt,!1,"f"),(e=a(this,K,"f"))===null||e===void 0||e.emit(_.historyDestroyed),b(this,K,null,"f")}}tt=new WeakMap,mt=new WeakMap,gt=new WeakMap,G=new WeakMap,Te=new WeakMap,et=new WeakMap,it=new WeakMap,K=new WeakMap,bt=new WeakMap,$t=new WeakMap,Et=new WeakMap;var Rt,Bn,$e,Pi;class Z{constructor(t,e,n,r){this.target=t,this.type=e,this.listener=n,this.options=a(Z,Rt,"m",Bn).call(Z,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}}Rt=Z,Bn=function(t,e){if(e===void 0)return!1;if(typeof e=="boolean")return e;{const n=new Set(["passive","capture"]),r=Object.keys(e).filter(c=>!n.has(c));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),a(Z,Rt,"m",Pi).call(Z,t)?e:e.capture||!1}},Pi=function(t){let e=a(Z,Rt,"f",$e);if(e===void 0){e=!1;try{const n={},r={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);const s=()=>{};t.addEventListener("test",s,n),t.removeEventListener("test",s,n)}catch(n){e=!1}b(Z,Rt,e,"f",$e)}return e||!1};$e={value:void 0};class hl{constructor(){this.bindingMap=new os}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;const s=new Z(t,e,n,r);this.bindingMap.push(e,s)}listenOnce(t,e,n,r){const s=c=>{this.unlisten(t,e,s),n(c)};this.listen(t,e,s,r)}unlisten(t,e,n){if(!this.bindingMap)return;const r=this.bindingMap.get(e)||[];for(const s of r)s.target===t&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(e,s))}removeAll(){if(!this.bindingMap)return;const t=this.bindingMap.getAll();for(const e of t)e.unlisten();this.bindingMap.clear()}}class dl{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const e=(t=this.rootElement.getContext("2d"))===null||t===void 0?void 0:t.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;const n=e.data,r=n.length;for(let s=3;s<r;s+=40)if(n[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===void 0||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,e=!1){const n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n}async save(){const t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))===null||e===void 0||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}}class ul{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=r=>{const s=r!=null?r:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(s);if(this.isContainerTime(s))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(c)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 @@ import{loadVKLangPack as Gn,ValueSubject as F,Subscription as Jt,Subject as zn,O
16
16
  top: 50%;
17
17
  left: 50%;
18
18
  transform: translate(-50%, -50%);
19
- `,this.rootElement.prepend(this.lastFrameCanvas.rootElement),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(t=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);const 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||n===void 0?void 0:n.length)&&t>=((r=e.startTime)!==null&&r!==void 0?r:0)&&t<=Math.min((s=e.endTime)!==null&&s!==void 0?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||e===void 0?void 0:e.onError)===null||n===void 0||n.call(e,t)}}function fl(i=0){return new Promise(t=>{setTimeout(()=>{t(0)},i)})}var P,lt,H,ct,D,st,B,U,nt,x,rt,jt,V,xt,N,T,dt,It,Fn,Mi,Qt,Dn,Re,Ni,xe,wt,Ot,ki,Oe,Vi,Wn,Ae,Yt;const Bi=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}}),J=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function vl(){const 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"}async updateCanvasDimensions(t=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);const 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||n===void 0?void 0:n.length)&&t>=((r=e.startTime)!==null&&r!==void 0?r:0)&&t<=Math.min((s=e.endTime)!==null&&s!==void 0?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||e===void 0?void 0:e.onError)===null||n===void 0||n.call(e,t)}}function fl(i=0){return new Promise(t=>{setTimeout(()=>{t(0)},i)})}var P,lt,H,ct,D,st,B,U,nt,x,rt,jt,V,xt,k,T,dt,It,Fn,Mi,Qt,Dn,Re,ki,xe,wt,Ot,Ni,Oe,Vi,Wn,Ae,Yt;const Bi=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}}),J=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function vl(){const i=document.createElement("div");return i.style.cssText=`
20
20
  position: absolute;
21
21
  top: 0;
22
22
  left: 0;
23
- `,i}class gl{constructor(t){var e;P.add(this),lt.set(this,null),H.set(this,null),ct.set(this,null),D.set(this,null),st.set(this,null),B.set(this,null),U.set(this,null),nt.set(this,null),x.set(this,null),rt.set(this,new F(!1)),jt.set(this,new Set),V.set(this,null),xt.set(this,null),N.set(this,null),T.set(this,null),dt.set(this,mr()),It.set(this,null),this.state={prevChapter$:new F(null),isInitialChapter$:new F(!1),isEndChapter$:new F(!1),isInteractiveExpectation$:new F(!1),calledByInteractive$:new F(!1),lastChapterChangeWasInitiatedByInteractive$:new F(!1),disabledControls$:new F(!1),interactiveRanges$:new F([]),isInteractiveTime$:new F(!1)},this.events={noInteraction$:new zn},this.emitPlayerChanged=n=>{setTimeout(()=>{a(this,T,"f").emit(_.playerChanged,n)})},Dn.set(this,()=>{a(this,U,"f").fns.forEach(s=>s());const n=this.options.player.info.position$.getValue()*1e3,r=(a(this,x,"f").chapter.containers||[]).filter(s=>s.startTime>=Math.floor(n));for(const s of r){a(this,B,"f").remove({timestamp:1/0,priority:"container",initiator:s.id});for(const c of s.controls)a(this,B,"f").remove({timestamp:1/0,priority:"control",initiator:c.id});a(this,H,"f").find(c=>c.container.container.id===s.id).reset()}}),Re.set(this,()=>{a(this,lt,"f").calc(),a(this,U,"f").requestAnimation()}),wt.set(this,(n=!0)=>{a(this,H,"f").forEach(r=>{!n&&r.isPermanentText||(a(this,U,"f").removeFn(r.whilePlaying),r.destroy())})}),Ae.set(this,n=>{const{interactiveRanges$:r}=this.state,c=r.getValue().map(o=>({...o,subjects:o.subjects.filter(l=>l!==n)}));r.next(c)}),Yt.set(this,()=>{a(this,It,"f")&&(clearTimeout(a(this,It,"f")),b(this,It,null,"f"))}),this.options={...Bi,...t,config:{...Bi.config,...t.config}},b(this,H,[],"f"),this.factories=new Map([["choice",Ki]]),this.rootElement=vl(),this.options.parentElement.append(this.rootElement),b(this,T,new rn,"f"),b(this,st,new Jt,"f"),b(this,ct,new hl,"f"),b(this,D,new cl({interactiveController:this,globalEventEmitter:a(this,T,"f"),videoId:(e=this.options.projectInfo)===null||e===void 0?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}}),"f"),this.options.lastFrame&&b(this,N,new ul({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.SEAMLESS,n))}),"f"),a(this,ct,"f").listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,ct,"f").listen(this.rootElement,"mouseup",n=>n.stopPropagation()),b(this,x,new Qr(this.options.loaders,n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.MANIFEST,n))),"f"),b(this,B,li(this.options.player),"f"),b(this,U,new jr,"f"),b(this,nt,di({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:a(this,wt,"f")}),"f"),b(this,lt,as(()=>{var n,r,s;return{player:(n=this.options)===null||n===void 0?void 0:n.player,parentElement:(r=this.options)===null||r===void 0?void 0:r.parentElement,fns:!((s=this.options)===null||s===void 0)&&s.lastFrame?[()=>{a(this,N,"f").updateCanvasDimensions(!0)}]:[]}}),"f"),this.options.graph&&b(this,V,new vr({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,T,"f").emit(_.graph,{type:ai.watchAgainClicked,chapterId:n})},onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.LOADERS,{message:n}))}),"f"),a(this,P,"m",Fn).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=J.created}getStatEvents(){return{click$:new Ge(t=>{a(this,T,"f").on(_.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?ht.OPEN_GRAPH:ht.CLOSE_GRAPH),e==="watchAgainClicked"&&t.next(ht.WATCH_AGAIN)}),a(this,T,"f").on(_.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next(ht.GO_NEXT_BUTTON),r==="Area"&&t.next(ht.GO_NEXT_AREA))})}),nextMovie$:new Ge(t=>{a(this,T,"f").on(_.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){a(this,P,"m",Qt).call(this),this.options.player=t,a(this,dt,"f").setPlayer(this.options.player),a(this,B,"f")?a(this,B,"f").setPlayer(this.options.player):b(this,B,li(this.options.player),"f"),b(this,nt,di({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:()=>a(this,wt,"f").call(this,!1)}),"f"),this.appState===J.initiated&&(a(this,P,"m",xe).call(this),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}async setManifest(t){a(this,P,"m",Qt).call(this),this.isFirstChapterFetched=!1;const e=await a(this,x,"f").setManifest(t);return a(this,V,"f")&&await a(this,V,"f").handleManifestChange(e.manifest),await a(this,D,"f").setManifest(e.manifest),a(this,T,"f").emit(_.manifestChanged,{manifest:e.manifest}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),e.manifest}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,V,"f"))===null||e===void 0||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,V,"f"))===null||e===void 0||e.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:e=!0}={}){var n;a(this,P,"m",Qt).call(this),a(this,N,"f")&&this.isFirstChapterFetched&&(a(this,N,"f").draw(),a(this,N,"f").show()),qn().browser===Qn.Safari&&await fl(35);const{chapter:s,media:c,graph:o}=await(t?a(this,x,"f").setNext(t):a(this,x,"f").setInitial());return e&&a(this,P,"m",Wn).call(this,s.id),this.state.isInitialChapter$.next(a(this,x,"f").isInitialChapter()),this.state.isEndChapter$.next(a(this,x,"f").isEndChapter()),a(this,V,"f")&&a(this,V,"f").handleChapterChange(o),(n=a(this,N,"f"))===null||n===void 0||n.setCurrentChapter(this.getCurrentChapter().chapter),a(this,T,"f").emit(_.chapterChanged,{chapter:s,media:c,graph:o}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),b(this,jt,new Set,"f"),this.isFirstChapterFetched=!0,{chapter:s,media:c,graph:o}}toggleGraphView(t=!0){a(this,V,"f")&&(t?(a(this,V,"f").show(),a(this,rt,"f").next(!1)):(a(this,V,"f").hide(),a(this,P,"m",Oe).call(this)),a(this,T,"f").emit(_.graph,{type:ai.visibility,visibility:t}))}init(){a(this,x,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===J.created&&(a(this,lt,"f").resizeObserver.observe(this.options.fullscreenTargetElement),a(this,P,"m",xe).call(this),this.appState=J.initiated,a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}deadEndCheck(){var t,e;return!((e=(t=a(this,B,"f"))===null||t===void 0?void 0:t.getPreparedToExecActions())!==null&&e!==void 0?e:[]).some(s=>s.actionType===R.setNextBranch)}allControlsAreRemoved(){return!a(this,H,"f").some(e=>!e.container.isRemoved)}isEndedExpectation(){var t;if(!(!((t=this.options)===null||t===void 0)&&t.player)||!a(this,H,"f"))return!1;const e=this.options.player.info.position$.getValue(),n=this.options.player.info.duration$.getValue();return e===n&&a(this,H,"f").some(r=>{const s=r.container.container;return!s.isRemoved&&s.endTime===null&&Lt(s.events)})}playPrevChapter(){var t;(t=a(this,D,"f"))===null||t===void 0||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,x,"f").manifest){return en(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,D,"f").getInitialVideoId(),chapterId:a(this,D,"f").getInitialChapterId()}}getHistoryState(){return a(this,D,"f").state}getIsSeekable(){return a(this,rt,"f")}getInteractiveRanges(){var t;return zr((t=a(this,x,"f").chapter)===null||t===void 0?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,dt,"f").getNextInteractiveTime(t)}getChapterBranches(t){return a(this,x,"f").getBranches(t)}getCurrentChapter(){return a(this,x,"f").getCurrent()}getCurrentManifest(){return a(this,x,"f").manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,T,"f").on(...t),this}off(...t){return a(this,T,"f").off(...t),this}once(...t){return a(this,T,"f").once(...t),this}destroy(){var t,e;a(this,wt,"f").call(this),b(this,H,void 0,"f"),this.state=void 0,(t=a(this,V,"f"))===null||t===void 0||t.destroy(),b(this,V,void 0,"f"),a(this,lt,"f").release(),b(this,lt,void 0,"f"),b(this,nt,void 0,"f"),a(this,U,"f").release(),b(this,U,void 0,"f"),a(this,B,"f").release(),b(this,B,void 0,"f"),a(this,x,"f").release(),b(this,nt,void 0,"f"),a(this,ct,"f").release(),b(this,ct,void 0,"f"),a(this,st,"f").unsubscribe(),b(this,st,void 0,"f"),a(this,T,"f").reset(),b(this,T,void 0,"f"),(e=a(this,N,"f"))===null||e===void 0||e.destroy(),b(this,N,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,a(this,D,"f").destroy(),b(this,D,void 0,"f"),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=J.destroyed}}lt=new WeakMap,H=new WeakMap,ct=new WeakMap,D=new WeakMap,st=new WeakMap,B=new WeakMap,U=new WeakMap,nt=new WeakMap,x=new WeakMap,rt=new WeakMap,jt=new WeakMap,V=new WeakMap,xt=new WeakMap,N=new WeakMap,T=new WeakMap,dt=new WeakMap,It=new WeakMap,Dn=new WeakMap,Re=new WeakMap,wt=new WeakMap,Ae=new WeakMap,Yt=new WeakMap,P=new WeakSet,Fn=function(t=!1){a(this,T,"f").on(_.historyInited,async({initChapterId:e,videosInfo:n=[]})=>{t&&await a(this,P,"m",Mi).call(this,{initialChapter:e,videosInfo:n})}),a(this,T,"f").on(_.interactives,async e=>{var n,r;if(e.type===j.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:c}=e.payload;this.setChapter({chapterId:c})}if(((r=e.payload)===null||r===void 0?void 0:r.behaviour)==="change-manifest"){const{manifestURL:c}=e.payload;this.setManifest(c)}const 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===j.containerRemoved&&a(this,Ae,"f").call(this,e.subjectId)}),a(this,T,"f").on(_.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Mi=async function({source:t,videosInfo:e=[]}){b(this,xt,Zr(this),"f");const n=document.createElement("div");a(this,xt,"f").on(qt.activePlayerChanged,this.emitPlayerChanged);const{player:r,config:s}=await a(this,xt,"f").init({source:t,initialChapter:a(this,D,"f").getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:r,config:s}},Qt=function(){var t;this.appState===J.ready&&(a(this,wt,"f").call(this),b(this,H,[],"f"),a(this,U,"f").release(),(t=a(this,B,"f"))===null||t===void 0||t.release(),this.appState=J.initiated,a(this,rt,"f").next(!1),a(this,Yt,"f").call(this))},Ni=function(t){(!a(this,V,"f")||a(this,V,"f").isHidden)&&a(this,P,"m",Oe).call(this);const e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){const s=r.range.join("-");a(this,jt,"f").has(s)||(a(this,jt,"f").add(s),a(this,T,"f").emit(_.interactives,{type:j.rangeEnded,payload:r,visibility:!0}))}},xe=function(){a(this,st,"f").unsubscribe(),a(this,st,"f").add(this.options.player.events.started$.pipe(Yn()).subscribe(a(this,Re,"f"))).add(this.options.player.events.playing$.subscribe(a(this,U,"f").requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,U,"f").cancelAnimation)).add(this.options.player.info.position$.subscribe(a(this,P,"m",Ni).bind(this))).add(a(this,x,"f").prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add(Kn({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{const s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,l],subjects:h})=>o<s&&s<l&&h.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?b(this,It,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout),"f"):a(this,Yt,"f").call(this))})),this.options.lastFrame&&a(this,st,"f").add(this.options.player.info.duration$.subscribe(t=>{a(this,N,"f").setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,N,"f").setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,N,"f").reset(),setTimeout(()=>{a(this,N,"f").hide(),a(this,N,"f").lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,N,"f").onSeek))},Ot=function(t){a(this,x,"f").chapter&&this.appState===J.initiated&&(a(this,nt,"f").setManifestChapterEvents(t),b(this,H,a(this,P,"m",ki).call(this,t),"f"),a(this,B,"f").containersEventsCallState.setData(t.containers),a(this,dt,"f").setContainers(a(this,H,"f").map(e=>e.container.container).filter(e=>!ln(e.controls))),this.options.lastFrame&&a(this,U,"f").addFn(()=>{a(this,N,"f").onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=J.ready)},ki=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)===null||e===void 0?void 0:e.reduce((r,s)=>{const c=s.type.trim().toLowerCase(),o=this.factories.get(c);if(o){const l=new Jr({player:this.options.player,container:o(s,this.rootElement),branches:a(this,x,"f").chapter.branches,selectBranches:a(this,nt,"f"),interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,T,"f"),ignoreContainerEvent:()=>qr(s,a(this,H,"f")),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,dt,"f").deleteContainer(s.id)}});return a(this,U,"f").addFn(l.whilePlaying,!0),[...r,l]}return[...r]},[]))!==null&&n!==void 0?n:[]},Oe=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,rt,"f").next(!1);return}const e=a(this,rt,"f").getValue(),n=!!a(this,dt,"f").getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,rt,"f").next(!e)},Vi=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Wn=function(t){var e;if(a(this,P,"m",Vi).call(this),!a(this,D,"f").inited)return;const n=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),r=this.state.prevChapter$.getValue(),s=(e=r&&te(r)&&Wr(r))!==null&&e!==void 0?e:!1,c=a(this,x,"f").manifest.metadata.initChapterId===t,o=a(this,D,"f").state.history$.getValue();if(c||s&&n){a(this,D,"f").updateHistory([t]);return}o.at(-1)!==t&&a(this,D,"f").updateHistory([...o,t])};const bl={Container:Yi,createChoiceContainer:Ki,createAreaControl:zi,createButtonControl:qi,createRelativeLayout:or,getRootEl:Di,classnamesPrefix:q},El={version:Jn};export{S as CustomError,_ as EVENT_NAMES,ht as INTERACTIVE_CLICK_ACTIONS,gl as Interactives,Qr as ManifestController,El as SDKInfo,Li as chapterIdsToVKVideoIds,Kt as compareVersions,ol as getChapterIdByVkVideoId,Vn as getVKVideoIdByMedia,sl as getVideoRawIdByMedia,ai as graphEventTypes,Wr as hasEndTemplate,j as interactivesEventTypes,te as isLastChapter,en as isSupportedManifest,al as isVKVariantItem,bl as utils,ll as vkVideoIdsToChapterIds};
23
+ `,i}class gl{constructor(t){var e;P.add(this),lt.set(this,null),H.set(this,null),ct.set(this,null),D.set(this,null),st.set(this,null),B.set(this,null),U.set(this,null),nt.set(this,null),x.set(this,null),rt.set(this,new F(!1)),jt.set(this,new Set),V.set(this,null),xt.set(this,null),k.set(this,null),T.set(this,null),dt.set(this,mr()),It.set(this,null),this.state={prevChapter$:new F(null),isInitialChapter$:new F(!1),isEndChapter$:new F(!1),isInteractiveExpectation$:new F(!1),calledByInteractive$:new F(!1),lastChapterChangeWasInitiatedByInteractive$:new F(!1),disabledControls$:new F(!1),interactiveRanges$:new F([]),isInteractiveTime$:new F(!1)},this.events={noInteraction$:new zn},this.emitPlayerChanged=n=>{setTimeout(()=>{a(this,T,"f").emit(_.playerChanged,n)})},Dn.set(this,()=>{a(this,U,"f").fns.forEach(s=>s());const n=this.options.player.info.position$.getValue()*1e3,r=(a(this,x,"f").chapter.containers||[]).filter(s=>s.startTime>=Math.floor(n));for(const s of r){a(this,B,"f").remove({timestamp:1/0,priority:"container",initiator:s.id});for(const c of s.controls)a(this,B,"f").remove({timestamp:1/0,priority:"control",initiator:c.id});a(this,H,"f").find(c=>c.container.container.id===s.id).reset()}}),Re.set(this,()=>{a(this,lt,"f").calc(),a(this,U,"f").requestAnimation()}),wt.set(this,(n=!0)=>{a(this,H,"f").forEach(r=>{!n&&r.isPermanentText||(a(this,U,"f").removeFn(r.whilePlaying),r.destroy())})}),Ae.set(this,n=>{const{interactiveRanges$:r}=this.state,c=r.getValue().map(o=>({...o,subjects:o.subjects.filter(l=>l!==n)}));r.next(c)}),Yt.set(this,()=>{a(this,It,"f")&&(clearTimeout(a(this,It,"f")),b(this,It,null,"f"))}),this.options={...Bi,...t,config:{...Bi.config,...t.config}},b(this,H,[],"f"),this.factories=new Map([["choice",Ki]]),this.rootElement=vl(),this.options.parentElement.append(this.rootElement),b(this,T,new rn,"f"),b(this,st,new Jt,"f"),b(this,ct,new hl,"f"),b(this,D,new cl({interactiveController:this,globalEventEmitter:a(this,T,"f"),videoId:(e=this.options.projectInfo)===null||e===void 0?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}}),"f"),this.options.lastFrame&&b(this,k,new ul({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.SEAMLESS,n))}),"f"),a(this,ct,"f").listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,ct,"f").listen(this.rootElement,"mouseup",n=>n.stopPropagation()),b(this,x,new Qr(this.options.loaders,n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.MANIFEST,n))),"f"),b(this,B,li(this.options.player),"f"),b(this,U,new jr,"f"),b(this,nt,di({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:a(this,wt,"f")}),"f"),b(this,lt,as(()=>{var n,r,s;return{player:(n=this.options)===null||n===void 0?void 0:n.player,parentElement:(r=this.options)===null||r===void 0?void 0:r.parentElement,fns:!((s=this.options)===null||s===void 0)&&s.lastFrame?[()=>{a(this,k,"f").updateCanvasDimensions(!0)}]:[]}}),"f"),this.options.graph&&b(this,V,new vr({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,T,"f").emit(_.graph,{type:ai.watchAgainClicked,chapterId:n})},onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.LOADERS,{message:n}))}),"f"),a(this,P,"m",Fn).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=J.created}getStatEvents(){return{click$:new Ge(t=>{a(this,T,"f").on(_.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?ht.OPEN_GRAPH:ht.CLOSE_GRAPH),e==="watchAgainClicked"&&t.next(ht.WATCH_AGAIN)}),a(this,T,"f").on(_.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next(ht.GO_NEXT_BUTTON),r==="Area"&&t.next(ht.GO_NEXT_AREA))})}),nextMovie$:new Ge(t=>{a(this,T,"f").on(_.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){a(this,P,"m",Qt).call(this),this.options.player=t,a(this,dt,"f").setPlayer(this.options.player),a(this,B,"f")?a(this,B,"f").setPlayer(this.options.player):b(this,B,li(this.options.player),"f"),b(this,nt,di({player:this.options.player,interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:()=>a(this,wt,"f").call(this,!1)}),"f"),this.appState===J.initiated&&(a(this,P,"m",xe).call(this),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}async setManifest(t){a(this,P,"m",Qt).call(this),this.isFirstChapterFetched=!1;const e=await a(this,x,"f").setManifest(t);return a(this,V,"f")&&await a(this,V,"f").handleManifestChange(e.manifest),await a(this,D,"f").setManifest(e.manifest),a(this,T,"f").emit(_.manifestChanged,{manifest:e.manifest}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),e.manifest}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,V,"f"))===null||e===void 0||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,V,"f"))===null||e===void 0||e.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:e=!0}={}){var n;a(this,P,"m",Qt).call(this),a(this,k,"f")&&this.isFirstChapterFetched&&(a(this,k,"f").draw(),a(this,k,"f").show()),qn().browser===Qn.Safari&&await fl(35);const{chapter:s,media:c,graph:o}=await(t?a(this,x,"f").setNext(t):a(this,x,"f").setInitial());return e&&a(this,P,"m",Wn).call(this,s.id),this.state.isInitialChapter$.next(a(this,x,"f").isInitialChapter()),this.state.isEndChapter$.next(a(this,x,"f").isEndChapter()),a(this,V,"f")&&a(this,V,"f").handleChapterChange(o),(n=a(this,k,"f"))===null||n===void 0||n.setCurrentChapter(this.getCurrentChapter().chapter),a(this,T,"f").emit(_.chapterChanged,{chapter:s,media:c,graph:o}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),b(this,jt,new Set,"f"),this.isFirstChapterFetched=!0,{chapter:s,media:c,graph:o}}toggleGraphView(t=!0){a(this,V,"f")&&(t?(a(this,V,"f").show(),a(this,rt,"f").next(!1)):(a(this,V,"f").hide(),a(this,P,"m",Oe).call(this)),a(this,T,"f").emit(_.graph,{type:ai.visibility,visibility:t}))}init(){a(this,x,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===J.created&&(a(this,lt,"f").resizeObserver.observe(this.options.fullscreenTargetElement),a(this,P,"m",xe).call(this),this.appState=J.initiated,a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}deadEndCheck(){var t,e;return!((e=(t=a(this,B,"f"))===null||t===void 0?void 0:t.getPreparedToExecActions())!==null&&e!==void 0?e:[]).some(s=>s.actionType===R.setNextBranch)}allControlsAreRemoved(){return!a(this,H,"f").some(e=>!e.container.isRemoved)}isEndedExpectation(){var t;if(!(!((t=this.options)===null||t===void 0)&&t.player)||!a(this,H,"f"))return!1;const e=this.options.player.info.position$.getValue(),n=this.options.player.info.duration$.getValue();return e===n&&a(this,H,"f").some(r=>{const s=r.container.container;return!s.isRemoved&&s.endTime===null&&Lt(s.events)})}playPrevChapter(){var t;(t=a(this,D,"f"))===null||t===void 0||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,x,"f").manifest){return en(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,D,"f").getInitialVideoId(),chapterId:a(this,D,"f").getInitialChapterId()}}getHistoryState(){return a(this,D,"f").state}getIsSeekable(){return a(this,rt,"f")}getInteractiveRanges(){var t;return zr((t=a(this,x,"f").chapter)===null||t===void 0?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,dt,"f").getNextInteractiveTime(t)}getChapterBranches(t){return a(this,x,"f").getBranches(t)}getCurrentChapter(){return a(this,x,"f").getCurrent()}getCurrentManifest(){return a(this,x,"f").manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,T,"f").on(...t),this}off(...t){return a(this,T,"f").off(...t),this}once(...t){return a(this,T,"f").once(...t),this}destroy(){var t,e;a(this,wt,"f").call(this),b(this,H,void 0,"f"),this.state=void 0,(t=a(this,V,"f"))===null||t===void 0||t.destroy(),b(this,V,void 0,"f"),a(this,lt,"f").release(),b(this,lt,void 0,"f"),b(this,nt,void 0,"f"),a(this,U,"f").release(),b(this,U,void 0,"f"),a(this,B,"f").release(),b(this,B,void 0,"f"),a(this,x,"f").release(),b(this,nt,void 0,"f"),a(this,ct,"f").release(),b(this,ct,void 0,"f"),a(this,st,"f").unsubscribe(),b(this,st,void 0,"f"),a(this,T,"f").reset(),b(this,T,void 0,"f"),(e=a(this,k,"f"))===null||e===void 0||e.destroy(),b(this,k,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,a(this,D,"f").destroy(),b(this,D,void 0,"f"),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=J.destroyed}}lt=new WeakMap,H=new WeakMap,ct=new WeakMap,D=new WeakMap,st=new WeakMap,B=new WeakMap,U=new WeakMap,nt=new WeakMap,x=new WeakMap,rt=new WeakMap,jt=new WeakMap,V=new WeakMap,xt=new WeakMap,k=new WeakMap,T=new WeakMap,dt=new WeakMap,It=new WeakMap,Dn=new WeakMap,Re=new WeakMap,wt=new WeakMap,Ae=new WeakMap,Yt=new WeakMap,P=new WeakSet,Fn=function(t=!1){a(this,T,"f").on(_.historyInited,async({initChapterId:e,videosInfo:n=[]})=>{t&&await a(this,P,"m",Mi).call(this,{initialChapter:e,videosInfo:n})}),a(this,T,"f").on(_.interactives,async e=>{var n,r;if(e.type===j.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:c}=e.payload;this.setChapter({chapterId:c})}if(((r=e.payload)===null||r===void 0?void 0:r.behaviour)==="change-manifest"){const{manifestURL:c}=e.payload;this.setManifest(c)}const 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===j.containerRemoved&&a(this,Ae,"f").call(this,e.subjectId)}),a(this,T,"f").on(_.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Mi=async function({source:t,videosInfo:e=[]}){b(this,xt,Zr(this),"f");const n=document.createElement("div");a(this,xt,"f").on(qt.activePlayerChanged,this.emitPlayerChanged);const{player:r,config:s}=await a(this,xt,"f").init({source:t,initialChapter:a(this,D,"f").getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:r,config:s}},Qt=function(){var t;this.appState===J.ready&&(a(this,wt,"f").call(this),b(this,H,[],"f"),a(this,U,"f").release(),(t=a(this,B,"f"))===null||t===void 0||t.release(),this.appState=J.initiated,a(this,rt,"f").next(!1),a(this,Yt,"f").call(this))},ki=function(t){(!a(this,V,"f")||a(this,V,"f").isHidden)&&a(this,P,"m",Oe).call(this);const e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){const s=r.range.join("-");a(this,jt,"f").has(s)||(a(this,jt,"f").add(s),a(this,T,"f").emit(_.interactives,{type:j.rangeEnded,payload:r,visibility:!0}))}},xe=function(){a(this,st,"f").unsubscribe(),a(this,st,"f").add(this.options.player.events.started$.pipe(Yn()).subscribe(a(this,Re,"f"))).add(this.options.player.events.playing$.subscribe(a(this,U,"f").requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,U,"f").cancelAnimation)).add(this.options.player.info.position$.subscribe(a(this,P,"m",ki).bind(this))).add(a(this,x,"f").prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add(Kn({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{const s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,l],subjects:h})=>o<s&&s<l&&h.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?b(this,It,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout),"f"):a(this,Yt,"f").call(this))})),this.options.lastFrame&&a(this,st,"f").add(this.options.player.info.duration$.subscribe(t=>{a(this,k,"f").setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,k,"f").setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,k,"f").reset(),setTimeout(()=>{a(this,k,"f").hide(),a(this,k,"f").lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,k,"f").onSeek))},Ot=function(t){a(this,x,"f").chapter&&this.appState===J.initiated&&(a(this,nt,"f").setManifestChapterEvents(t),b(this,H,a(this,P,"m",Ni).call(this,t),"f"),a(this,B,"f").containersEventsCallState.setData(t.containers),a(this,dt,"f").setContainers(a(this,H,"f").map(e=>e.container.container).filter(e=>!ln(e.controls))),this.options.lastFrame&&a(this,U,"f").addFn(()=>{a(this,k,"f").onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=J.ready)},Ni=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)===null||e===void 0?void 0:e.reduce((r,s)=>{const c=s.type.trim().toLowerCase(),o=this.factories.get(c);if(o){const l=new Jr({player:this.options.player,container:o(s,this.rootElement),branches:a(this,x,"f").chapter.branches,selectBranches:a(this,nt,"f"),interactiveEvents:a(this,B,"f"),globalEventEmitter:a(this,T,"f"),ignoreContainerEvent:()=>qr(s,a(this,H,"f")),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,dt,"f").deleteContainer(s.id)}});return a(this,U,"f").addFn(l.whilePlaying,!0),[...r,l]}return[...r]},[]))!==null&&n!==void 0?n:[]},Oe=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,rt,"f").next(!1);return}const e=a(this,rt,"f").getValue(),n=!!a(this,dt,"f").getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,rt,"f").next(!e)},Vi=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Wn=function(t){var e;if(a(this,P,"m",Vi).call(this),!a(this,D,"f").inited)return;const n=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),r=this.state.prevChapter$.getValue(),s=(e=r&&te(r)&&Wr(r))!==null&&e!==void 0?e:!1,c=a(this,x,"f").manifest.metadata.initChapterId===t,o=a(this,D,"f").state.history$.getValue();if(c||s&&n){a(this,D,"f").updateHistory([t]);return}o.at(-1)!==t&&a(this,D,"f").updateHistory([...o,t])};const bl={Container:Yi,createChoiceContainer:Ki,createAreaControl:zi,createButtonControl:qi,createRelativeLayout:or,getRootEl:Di,classnamesPrefix:q},El={version:Jn};export{S as CustomError,_ as EVENT_NAMES,ht as INTERACTIVE_CLICK_ACTIONS,gl as Interactives,Qr as ManifestController,El as SDKInfo,Li as chapterIdsToVKVideoIds,Kt as compareVersions,ol as getChapterIdByVkVideoId,Vn as getVKVideoIdByMedia,sl as getVideoRawIdByMedia,ai as graphEventTypes,Wr as hasEndTemplate,j as interactivesEventTypes,te as isLastChapter,en as isSupportedManifest,al as isVKVariantItem,bl as utils,ll as vkVideoIdsToChapterIds};