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