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