@vkontakte/videoplayer-interactive 1.0.6-dev.5a11a96.0 → 1.0.6-dev.9aa76b8.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 +3 -3
- package/es2015.esm.js +3 -3
- package/es2018.cjs.js +3 -3
- package/es2018.esm.js +3 -3
- package/esnext.cjs.js +3 -3
- package/esnext.esm.js +3 -3
- package/evergreen.esm.js +3 -3
- package/package.json +3 -5
- package/es2015.umd.js +0 -31071
package/es2018.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.6-dev.
|
|
3
|
-
* Tue, 12 Dec 2023
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.6-dev.9aa76b8.0
|
|
3
|
+
* Tue, 12 Dec 2023 10:50:05 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-6/doc/
|
|
5
5
|
*/
|
|
6
|
-
"use strict";var Ut=Object.create;var Qe=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var Xt=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of qt(e))!Kt.call(i,s)&&s!==t&&Qe(i,s,{get:()=>e[s],enumerable:!(n=zt(e,s))||n.enumerable});return i};var Zt=(i,e,t)=>(t=i!=null?Ut(Qt(i)):{},Xt(e||!i||!i.__esModule?Qe(t,"default",{value:i,enumerable:!0}):t,i));var G=require("@vkontakte/videoplayer-shared/es2018.cjs.js"),Be=require("uuid"),Yt=require("@vkontakte/videoplayer-core/es2018.cjs.js");const Jt="1.0.6-dev.5a11a96.0";function Ct(i,e=1){let t="0",n="0",s="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+s},${e})`}const W="SDK_NAME",ei="SDK_NAME-controls-container",Et=()=>document.querySelector(`.${ei}`),z={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"},Xe={start:"flex-start",end:"flex-end",center:"center"},Ze={start:"left",end:"right",center:"center"},wt=({target:i,props:e})=>{var t,n,s,r,c,o;i.style.alignItems=(n=Ke[(t=e==null?void 0:e.text)===null||t===void 0?void 0:t.gravityVertical])!==null&&n!==void 0?n:Ke.center,i.style.justifyContent=(r=Xe[(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:Xe.center,i.style.textAlign=(o=Ze[(c=e==null?void 0:e.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:Ze.start},_t=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d;i.style.color=(r=(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:t.textColor,i.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:t.textSize})`,i.textContent=(d=(l=e==null?void 0:e.text)===null||l===void 0?void 0:l.value)!==null&&d!==void 0?d:t.textContent},It=({target:i,props:e,fallback:t})=>{var n,s,r,c;i.style.backgroundColor=Ct((s=(n=e==null?void 0:e.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:t.backgroundColor,(c=(r=e==null?void 0:e.background)===null||r===void 0?void 0:r.alpha)!==null&&c!==void 0?c:t.backgroundAlpha)},St=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d,f,u,y,C,E;i.style.border=`calc(${n.height} * ${(c=(r=(s=e==null?void 0:e.shape)===null||s===void 0?void 0:s.border)===null||r===void 0?void 0:r.width)!==null&&c!==void 0?c:t.borderWidth}) solid ${Ct((d=(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&&d!==void 0?d:t.borderColor,(y=(u=(f=e==null?void 0:e.shape)===null||f===void 0?void 0:f.border)===null||u===void 0?void 0:u.alpha)!==null&&y!==void 0?y:t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(E=(C=e==null?void 0:e.shape)===null||C===void 0?void 0:C.roundCorners)!==null&&E!==void 0?E:t.roundCorners})`},$e=({target:i,layoutParams:e,fallback:t})=>{var n;i.style.transform=`rotate(${(n=-e.angle)!==null&&n!==void 0?n:t.angle}rad)`};class De{constructor(e){this.control=e}createView(e){var t;const n=document.createElement("div");n.classList.add(`${W}-control-container-${this.control.id}`),e(n,this.control.layoutParams);const s=((t=this.control.layoutParams.innerSizesDependOn)!==null&&t!==void 0?t:z.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:s}}setEvents(e,t){e&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",r=>{r.stopPropagation(),t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${W}-control-container-${this.control.id}`)}}const Tt=i=>{if(i.type.trim().toLowerCase()==="area")return new ti(i)};class ti extends De{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");return r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",It({target:r,props:this.control.props,fallback:{...z,backgroundColor:"transparent"}}),St({target:r,props:this.control.props,fallback:{...z,borderAlpha:0},dependsOn:n}),$e({target:r,layoutParams:this.control.layoutParams,fallback:z}),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const Rt=i=>{if(i.type.trim().toLowerCase()==="button")return new ii(i)};class ii extends De{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");r.type="button",r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.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",$e({target:r,layoutParams:this.control.layoutParams,fallback:z}),It({target:r,props:this.control.props,fallback:z}),St({target:r,props:this.control.props,fallback:z,dependsOn:n}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:z,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const ni=i=>{if(i.type.trim().toLowerCase()==="text")return new si(i)};class si extends De{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("div");r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",$e({target:r,layoutParams:this.control.layoutParams,fallback:z}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:z,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}class ri{constructor(e){this.layout=e}}const ai=i=>{if(i.type.trim().toLowerCase()==="relative")return new At(i)};class At extends ri{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function a(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)}function _(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t}var re,Ie,Ye;class xt{constructor(e){re.add(this),this.container=e,this.factories=new Map,a(this,re,"m",Ie).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),a(this,re,"m",Ie).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),a(this,re,"m",Ie).call(this)}}re=new WeakSet,Ie=function(){this.controls=a(this,re,"m",Ye).call(this)},Ye=function(){var e;return(e=this.container.controls)===null||e===void 0?void 0:e.reduce((t,n)=>{const s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...t,r(n)]:[...t]},[])};const Ot=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new oi(i,e)};class oi extends xt{constructor(e,t){super(e),this.rootElement=t!=null?t:Et(),this.layout=new At(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",Rt),this.addControlFactory("text",ni),this.addControlFactory("area",Tt)}createView(e){const t=document.createElement("div");return t.classList.add(`${W}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const s=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(s,e)}),this.rootElement.append(t),t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){var e;this.isRemoved||((e=this.getElement())===null||e===void 0||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${W}-${this.container.id}`)}}function Lt(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const ge={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},de=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,We=i=>de(i,ge.Object),Ne=i=>de(i,ge.String),le=i=>de(i,ge.Array),Nt=i=>de(i,ge.Number),li=i=>de(i,ge.Function),Je=i=>Nt(i)&&!isNaN(i),ci=i=>i==null,pe=i=>We(i)&&Object.keys(i).length===0,jt=i=>le(i)&&!i.length,Ce=(i,e)=>Ne(i)&&(e?i.trim():i).length,Mt=window.navigator.userAgent.toLowerCase(),di=/mobi/i.test(Mt);Mt.indexOf("android")>-1;const hi="video_interactive",ui="videoint",fi=250;class pi{constructor(e){this.onResize=t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))},this.handleChapterChange=t=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.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(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(t,n=[])=>{var s;if(!Nt(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)===null||s===void 0||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await G.loadVKLangPack(this.lang,hi,ui)}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:r}),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),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0},this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=t,this.onError=n,this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=vi(e),this.resizeObserver=new ResizeObserver(Lt(this.onResize,fi)),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,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)===null||e===void 0||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)===null||t===void 0||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function vi(i){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",i.append(e),e}const mi=(i={})=>{var e;return Array.from(new Set((e=i.sessions)===null||e===void 0?void 0:e.map(t=>{var n;return(n=t.visitedChapters.map(s=>s.chapterId))!==null&&n!==void 0?n:[]}).flat()))},et=(i=[],e="")=>i.reduce((t,n)=>(t.find(s=>s[e]===n[e])||t.push(n),t),[]),tt="chapterId";class ae{constructor(e){var t;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:Be.v4(),this.startDate=e!=null&&e.startDate?new Date(e.startDate).toISOString():new Date(Date.now()).toISOString(),this.updateOn=e!=null&&e.updateOn?new Date(e.updateOn).toISOString():null,this.visitedChapters=e!=null&&e.visitedChapters?et(Array.from(e.visitedChapters),tt):[],this.branches=le(e==null?void 0:e.branches)?e.branches:[]}update(e){e!=null&&e.startDate&&(this.startDate=new Date(e.startDate).toISOString()),e!=null&&e.updateOn&&(this.updateOn=new Date(e.updateOn).toISOString()),le(e==null?void 0:e.visitedChapters)&&(this.visitedChapters=et([...this.visitedChapters,...e.visitedChapters],tt)),le(e==null?void 0:e.branches)&&(this.branches=this.branches.concat(e.branches))}getSession(){return{...this}}static createVisitedChapter(e){return[{chapterId:e}]}static createBranch(e,t,n){return[{chapterId:e,branchId:t,autoSelect:n}]}}class Ee{constructor(e){var t,n;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:Be.v4(),this.manifestId=e==null?void 0:e.manifestId,this.manifestVersion=e==null?void 0:e.manifestVersion,this.manifestBuild=e==null?void 0:e.manifestBuild,this.sessions=le(e==null?void 0:e.sessions)?e==null?void 0:e.sessions.map(s=>new ae(s)):[],this.isCompleted=(n=e==null?void 0:e.isCompleted)!==null&&n!==void 0?n:!1}update(e){var t,n,s,r,c;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:this.id,this.manifestId=(n=e==null?void 0:e.manifestId)!==null&&n!==void 0?n:this.manifestId,this.manifestVersion=(s=e==null?void 0:e.manifestVersion)!==null&&s!==void 0?s:this.manifestVersion,this.manifestBuild=(r=e==null?void 0:e.manifestBuild)!==null&&r!==void 0?r:this.manifestBuild,this.isCompleted=(c=e==null?void 0:e.isCompleted)!==null&&c!==void 0?c:this.isCompleted}addSession(e){this.sessions.push(new ae(e))}updateSession(e,t){let n;ci(e)?n=this.sessions[this.sessions.length-1]:n=this.sessions.find(s=>s.id===e),n&&n.update(t)}resetSession(){this.sessions=[]}getHistory(){return{...this,sessions:this.sessions.map(e=>e.getSession())}}}const je="SDK_NAME-history-changed";class gi extends EventTarget{constructor(){super(),this.history=new Ee,this.sendEvent()}onChapterChange({chapterId:e,mediaId:t,autoSelect:n=!1,isLastChapter:s=!1}){this.history.isCompleted?this.history=new Ee({manifestId:this.history.manifestId,manifestVersion:this.history.manifestVersion,manifestBuild:this.history.manifestBuild}):s&&this.history.update({isCompleted:!0}),this.history.sessions.length?this.history.updateSession(null,{updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,n)}):this.history.addSession({updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,!1)}),this.sendEvent()}onManifestChange(e,t){t?this.history=new Ee(t):this.history=new Ee({manifestId:e.id,manifestVersion:e.version,manifestBuild:e.build}),this.history.addSession({updateOn:Date.now()}),this.sendEvent()}getHistory(){if(history)return this.history.getHistory()}sendEvent(){this.dispatchEvent(new CustomEvent(je,{bubbles:!1,detail:this.getHistory()}))}destroy(){this.history=void 0}}function yi(i,e){var t;if(!e||!i||!e.sessions.length)return;const n=e.sessions.reverse().find(s=>s.branches.length);return(t=n.branches[n.branches.length-1].chapterId)!==null&&t!==void 0?t:void 0}const me=(i="",e="")=>{i=i.split("."),e=e.split(".");let t=0;for(let n=0;n<Math.max(i.length,e.length)&&!t;n++)i[n]>e[n]?t=1:i[n]<e[n]?t=-1:t=0;return t},bi="3.1",it={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Ci={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ei=i=>{const e=[];for(const t of i.chapters){let n;const s=[];for(const{isDefault:o,...l}of t.branches)o&&(n=l.id),s.push(l);let r=[];const c=[];for(const{fallbackStrategy:o,...l}of t.containers){const d=!!l.endTime;let f=[Ci];switch(o){case"await":d?f=[]:r=[];break;case"default":{const u={type:"onSuspense",action:{type:it.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?f=[u]:r=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:it[o],args:{}}};d?f=[u]:r=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:Be.v4(),events:f})}e.push({...t,containers:c,events:r,branches:s})}return i.metadata.version=bi,i.metadata.updated=new Date().toISOString(),{...i,chapters:e}},wi="3.2",_i=i=>{if(!i.media){const{media:e,...t}=i.metadata;return{...i,metadata:{...t,version:wi},media:e}}return i},Ii="3.3",Si=(i=[])=>({edit:{chapters:i},view:{}}),nt={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ti=i=>{var e;const t=[],n=[];for(const s of i.chapters){const{id:r,x:c,y:o,...l}=s,d=l.containers.map(f=>{var u;return{...f,controls:f.controls.map(({subtype:y,type:C,...E})=>({...E,type:y!=null?y:C})),events:!((u=f.events)===null||u===void 0)&&u.length?f.events:[nt]}});t.push({id:r,...l,containers:d,events:!((e=l.events)===null||e===void 0)&&e.length?l.events:[nt]}),n.push({id:r,x:c,y:o})}return{...i,chapters:t,graph:Si(n),metadata:{...i.metadata,version:Ii}}},Ri=[{version:"3.0",migrate:Ei},{version:"3.1",migrate:_i},{version:"3.2",migrate:Ti}],Ai=i=>Ri.reduce((e,t)=>me(e.metadata.version,t.version)?e:t.migrate(e),i),xi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),A=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 st={metadata:"Object",chapters:"Array"},Oi="3.0.0",Li="3.3.0",He=i=>{const e=me(i,Oi);return e===-1?!1:e===0?!0:me(i,Li)!==1},Ni=i=>{if(!We(i))return!1;for(const e in st)if(!i[e]||!de(i[e],st[e]))return!1;return He(i.metadata.version)},ji=i=>i.type===xi.Text;class L{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}L.Severity={RECOVERABLE:1,CRITICAL:2};L.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Vt{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];const n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){const n=this.listeners[e];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===t){n.splice(s,1);break}return this}emit(e,...t){const n=this.listeners[e];return n?(n.forEach(s=>{s(...t)}),!0):!1}listenerCount(e){return(this.listeners[e]||[]).length}rawListeners(e){return this.listeners[e]}}class Mi{constructor(e){this.addFn=(t,n=!1)=>{li(t)&&(this.fns.push(t),n&&this.updateFn())},this.removeFn=(t,n=!1)=>{this.fns=this.fns.filter(s=>s!==t),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Vi{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!==null&&t!==void 0?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(e,t){return ki(...this.loaders[e])(t)}}function ki(...i){return async function(t){const n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Ae(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function Me({actions:i,errors:e,chapterId:t,...n}){if(t){const s=i.getManifest(),r=i.getChapter(s.chapters,t);if(r){const c=i.getMedia(s.media,r.videoId),o=i.getGraph(s.graph,r.id);return c?{...n,actions:i,errors:e,result:{chapter:r,media:c,graph:o}}:{...n,errors:Ae(e,Me.name,"Could not find media"),actions:i}}}return{...n,errors:Ae(e,Me.name,"Could not find chapter"),actions:i}}class rt{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;const n=this.listeners[e];for(let s=0,r=n.length;s<r;s++)if(n[s].callback===t){n.splice(s,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const n=this.listeners[e.type].slice();for(let s=0,r=n.length;s<r;s++){const c=n[s];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 kt extends rt{constructor(){super(),this.listeners||rt.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 Pi{constructor(){Object.defineProperty(this,"signal",{value:new kt,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(s){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={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(s){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(Pi.prototype[Symbol.toStringTag]="AbortController",kt.prototype[Symbol.toStringTag]="AbortSignal");function Pt(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 Fi(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=i;if(!Pt({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:e,Request:r};let r=t;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(d,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const y=new t(d,f);return u&&Object.defineProperty(y,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),y},r.prototype=t.prototype);const c=e;return{fetch:(l,d)=>{const f=r&&r.prototype.isPrototypeOf(l)?l.signal:d?d.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch(C){u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const y=new Promise((C,E)=>{f.addEventListener("abort",()=>E(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([y,c(l,d)])}return c(l,d)},Request:r}}const Ge=Pt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ft=Ge?Fi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,at=Ge?Ft.fetch:window.fetch;Ge?Ft.Request:window.Request;const Bi=async i=>{try{let e,t;if(We(i))e=i;else if(Ne(i)){t=new URL(i).href;const s=await at(t);if(!s.ok)return{};e=await s.json()}else return{};if(!Ni(e))return{};const n=e.metadata.media;if(Ne(n)&&!e.media)try{let s;t?s=new URL(n,t).href:(s=new URL(n).href,t=s);const r=await at(s);if(!r.ok)throw new Error;e.metadata.media=await r.json()}catch(s){return Hi(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function $i(i){const{manifest:e,manifestURL:t}=await Bi(i),n=Ai(e);return n.media=Di(n.media,t),delete n.metadata.media,n}function Oe(i,e){return i.find(t=>t.id===e)}function ot(i,e){var t,n;return!((t=i.edit)===null||t===void 0)&&t.chapters?i.edit.chapters.find(s=>s.id===e):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(s=>s.id===e):void 0}function lt(i,e){return i.videos.find(t=>t.id===e)}function Di(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{const s=Wi(n.url,e);return{...n,url:s||n.url}})}))}}function Wi(i,e){try{return new URL(i,e).href}catch(t){return""}}function Hi(i){return me(i,"3.2.0")>=0}class Bt extends Vi{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}async setManifest(e){var t;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ae},result:null,errors:null,source:e});n.errors&&this.errorHandler(n.errors);const s=await $i((t=n.result)!==null&&t!==void 0?t:e);return this.manifest=s,this}async setInitial(){return this.setNext()}async setNext(e=this.manifest.metadata.initChapterId){const t=await this.exec("chapterLoaders",Me({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ot,getChapter:Oe,getMedia:lt,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ae},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.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 t=Oe(this.manifest.chapters,e);if(t){const n=lt(this.manifest.media,t.videoId),s=ot(this.manifest.graph,t.id);if(n)return{chapter:t,media:n,graph:s}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{const t=Oe(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const s=this.getByChapterId(n.chapterId);return s&&t.push(s),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const b={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},ct={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},N={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Gi(){const i=new Map;function e({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...c}){const o=i.get(s),l={...c};return o?o[r]=l:i.set(s,{[r]:l}),{listId:s,itemId:r,...c}}function t(s,r){var c,o,l;const d=i.get(s);if(d){if(r)return(c=d[r])===null||c===void 0||c.player.destroy(),(o=d[r])===null||o===void 0||o.container.remove(),(l=d[r])===null||l===void 0||l.subscription.unsubscribe(),delete d[r],Object.keys(d).length||i.delete(s),!0;for(const f of Object.values(d))f.player.destroy(),f.container.remove();return i.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(const s of i)t(s[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:n}}function dt(i,e=[]){let t={},n;const s=!e.length;for(const r of i.variants)switch(!n&&"cover"in r&&(n=r.cover),r.type){case"mp4":(s||e.includes("mp4"))&&(t={...t,MPEG:{"Invariant quality":r.url}});break;case"hls":(s||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:r.url}});break;case"dash":(s||e.includes("dash"))&&(t={...t,DASH:{type:"url",url:r.url}});break}return{sources:t,thumbUrl:n,title:i.id}}const we=(i,e)=>{const t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))},Ui=i=>{const e=i.variants.find(t=>{var n;return((n=t.payload)===null||n===void 0?void 0:n.type)==="vk"});if(e&&"payload"in e){const[t,n]=e.payload.id.split("_");return[t,n]}return[]},Se={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},zi=2;function qi(i){const e=Gi();let t,n;const s=new Vt;let r={},c=!1,o=null,l=!1,d;i&&f(i);function f(p){o=p}function u(p,g,v){var I;if(!o)throw Error("need to set interactive controller");const w=((I=e.map.get(p))!==null&&I!==void 0?I:{})[g];if(w){r={chapterId:v,listId:p,itemId:g,...w};const R=r.player;n=R.info.currentQuality$.subscribe(V=>{if(!(!V||!R.info.position$.getValue())){t=V;for(const P of e.map)Object.values(P[1]).forEach(({player:$})=>{R.info.isAutoQualityEnabled$.getValue()||we($,V)})}}),w.container.remove(),c=!1,o.setPlayer(w.player),l||(o.init(),l=!0),s.emit(Se.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function y(p,g,v){if(!o)throw Error("need to set interactive controller");if(pe(r)||p!==r.itemId)return;if(v>=0&&!c){const S=o.getChapterBranches();c=!0;const w=new Set;for(const R of S)w.has(R.media.id)||(await E({media:R.media,chapterId:R.chapter.id,setAsActive:!1,title:R.chapter.label}),w.add(R.media.id))}}async function C({chapter:{id:p},media:g}){if(pe(r))return;n==null||n.unsubscribe();const v=r.player.info.muted$.getValue(),I=r.player.info.currentQuality$.getValue(),S=r.player.info.isAutoQualityEnabled$.getValue(),w=r.player.info.volume$.getValue(),R=r.player.info.currentPlaybackRate$.getValue(),V=!S;let P=!1;for(const $ of e.map)if($[0]===g.id){const ie=Object.keys($[1]);for(const Z of ie)Z===r.itemId?(ie.length<zi||(P=!0),e.removePlayer($[0],Z)):(P=!0,u($[0],Z,p),V?we(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v),r.player.setPlaybackRate(R))}else e.removePlayer($[0]);P||(await E({media:g,chapterId:p,setAsActive:!0,playbackRate:R}),V?we(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v))}async function E({media:p,chapterId:g,prefetch:v=!0,setAsActive:I=!0,autoplay:S=!1,preferredExt:w,title:R,playbackRate:V}){var P,$,ie;const Z=Math.random().toString(),ne=document.createElement("div");d.append(ne);const Ht=(P=r==null?void 0:r.player)===null||P===void 0?void 0:P.info.isAutoQualityEnabled$.getValue();let ye;if(!(($=o==null?void 0:o.options)===null||$===void 0)&&$.vkVideoLoader){const be=Ui(p);be.length&&(ye=await o.options.vkVideoLoader(...be))}const ze={container:ne,...((ie=ye==null?void 0:ye.videos)===null||ie===void 0?void 0:ie[0])||{sources:dt(p,w).sources},title:R},Y=new Yt.Player;Y.initVideo(ze);const Gt=ne.lastChild,qe=new G.Subscription;qe.add(Y.info.position$.subscribe(function(be){y(Z,Y.info.duration$.getValue(),be)})).add(Y.events.canplay$.subscribe(function(){Ht||we(Y,t),V&&Y.setPlaybackRate(V)})),Gt&&(ne.style.display="none",ne.classList.add(g));const se=e.createPlayer({listId:p.id,itemId:Z,player:Y,container:ne,sources:dt(p,w).sources,config:ze,subscription:qe});return I&&u(p.id,se.itemId,g),S&&se.player.play(),v&&!S&&se.player.prepare(),s.emit(Se.playerCreated,se.player),{player:se.player,config:se.config}}function j(){h(),o=null}function h(){o==null||o.off(b.chapterChanged,C),e.removeAll(),r={},l=!1,c=!1}async function m({source:p,initialChapter:g,container:v}){if(!o)throw Error("need to set interactive controller");await o.setManifest(p),h(),d=v;const{media:I,chapter:S}=await o.setChapter({chapterId:g});if(I){o.on(b.chapterChanged,C);const{player:w,config:R}=await E({media:I,chapterId:S.id,title:S.label});return s.emit(Se.initiated,{container:v,media:I,chapterId:S.id}),{player:w,config:R}}else console.error("not found")}return{...e,on:s.on.bind(s),off:s.off.bind(s),init:m,setInteractiveController:f,createPlayer:E,removeAll:j,getActivePlayer:function(){return r}}}const Qi=3e3,Ki=()=>{let i=[],e=null;return{setPlayer:c=>{e=c},setContainers:c=>{i=c},deleteContainer:c=>{i=i.filter(o=>o.id!==c)},getNextInteractiveTime:(c=Qi)=>{if(!i.length||e===null)return null;let o=-1,l=!1;const d=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-c;if(u<=d&&(d<=f.endTime||f.endTime===null)){l=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},ce=Ki(),O=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ue=i=>le(i)&&!jt(i),$t=i=>jt(i.branches)||i.order==="end",Xi=(i,e)=>{var t;const n=i*1e3;return Ue(e.controls)&&n<((t=e.startTime)!==null&&t!==void 0?t:0)},ht=(i,e)=>{var t,n;const s=i*1e3;return Ue(e.controls)&&s>=((t=e.startTime)!==null&&t!==void 0?t:0)&&s<=((n=e.endTime)!==null&&n!==void 0?n:1/0)},xe=i=>i.some(e=>e.action.type==="expect"),ut=i=>i.find(e=>e.action.type==="expect"),Zi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i({...n[e],...t[e]}),Yi=(i=[])=>i.reduce((e,t,n)=>{var s,r,c;const o=((s=t==null?void 0:t.controls)!==null&&s!==void 0?s:[]).filter(l=>!ji(l));if(Ue(o)){const l=[(r=t.startTime)!==null&&r!==void 0?r:0,(c=t.endTime)!==null&&c!==void 0?c:1/0],d=t.id;if(!n)e.push({subjects:[d],range:l});else{const f=[];let u=-1/0,y=1/0,C=[];const E=[];for(let j=0;j<e.length;j++){const h=e[j];if(E.push(...h.subjects),h.range[0]<y&&(y=h.range[0]),h.range[1]>u&&(u=h.range[1]),h.range[0]<=l[0]&&h.range[1]>=l[1])return e[j].subjects.push(d),e;l[0]>=h.range[0]&&l[0]<=h.range[1]&&(f.push(j),C=C.concat(h.subjects),l[0]=h.range[0]),l[1]>=h.range[0]&&l[1]<=h.range[1]&&(f.push(j),C=C.concat(h.subjects),l[1]=h.range[1])}if(E.push(d),l[0]<=y&&l[1]>=u)return[{subjects:E,range:l}];f.length&&f.reverse().forEach(j=>{e.splice(j,1)}),e.push({subjects:C.concat([d]),range:l})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),Ji=(i,e)=>xe(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&xe(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class en{constructor({player:e,container:t,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:c,ignoreContainerEvent:o}){this.hide=()=>{setTimeout(()=>{var l,d;this.gameState!==O.end&&(xe(this.container.container.events)&&this.gameState===O.afterInteractive||this.selectBranches.state.isExpect||((d=(l=this.container).hide)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})))})},this.show=()=>{var l,d;if(this.gameState===O.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(d=(l=this.container).show)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!0,isFirst:!1});else{const u=Zi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})},onEvent:(y,C)=>{this.isSelectedControlEvent=!0,y!==!1&&(this.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})),(this.gameState===O.end||this.gameState===O.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),C(),this.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})),ce.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===O.end});this.container.createView(u),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!0,isFirst:!0})}},this.onEndOfVideo=()=>{this.gameState=O.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var l,d,f,u;if(((l=this.player.experimental.element$.getValue())===null||l===void 0?void 0:l.readyState)<1||[O.destroyed,O.removed].includes(this.gameState))return;const C=this.player.info.position$.getValue();if(Xi(C,this.container.container))this.gameState!==O.beforeInteractive&&(this.gameState=O.beforeInteractive,this.onBeforeStartTime());else if(ht(C,this.container.container))this.gameState!==O.interactive&&(this.gameState=O.interactive,this.onStartTime());else if(this.gameState!==O.afterInteractive){const h=this.gameState;this.gameState=O.afterInteractive,h===O.interactive&&this.onEndTime()}else this.gameState!==O.destroyed&&this.removeView();const E=ht(C,this.container.container),j=this.container.container.startTime?[this.container.container.startTime,(d=this.container.container.endTime)!==null&&d!==void 0?d:1/0]:[];(u=(f=this.container).onProgress)===null||u===void 0||u.call(f,C,E),this.globalEventEmitter.emit(b.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:j,currentTime:C,isInteractiveTime:E})},this.container=t,this.branches=n,this.selectBranches=s,this.subscription=new G.Subscription,this.player=e,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.globalEventEmitter=c,this.gameState=O.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))}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=xe(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)===null||t===void 0||t.call(e),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=O.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.containerRemoved,visibility:!1}),this.gameState=O.removed}destroy(){var e;this.reset(),this.removeView(),this.gameState=O.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}),ce.deleteContainer(this.container.container.id)}}function tn(){const i={};function e(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function t(o){const l={};for(const d in i)+d<=o&&(l[d]=i[d]);return l}function n(o){const l={};for(const d in i)+d>=o&&(l[d]=i[d]);return l}function s({timestamp:o,priority:l,initiator:d}){var f;if(Je(o)){const u=(f=i[o])!==null&&f!==void 0?f:null;if(u&&Ce(l,!0)){let y={};const C=u[l];if(C&&(y={...y,...C}),y=pe(y)?null:y,y&&Ce(d,!0)){const E=y[d];return E!=null?E:null}return y}return u}return null}function r({timestamp:o,priority:l,initiator:d}){if(Je(o))if(i[o]){if(Ce(l,!0))if(i[o][l]){if(Ce(d,!0))if(i[o][l][d]){if(delete i[o][l][d],!pe(i[o][l]))return!0}else return!1;if(delete i[o][l],!pe(i[o]))return!0}else return!1;return delete i[o]}else return!1}function c({timestamp:o,priority:l,initiator:d,...f}){var u,y,C;!((y=(u=i[o])===null||u===void 0?void 0:u[l])===null||y===void 0)&&y[d]?i[o][l][d].push({...f}):!((C=i[o])===null||C===void 0)&&C[l]?i[o][l]={...i[o][l],[d]:[{...f}]}:i[o]?i[o]={...i[o],[l]:{[d]:[{...f}]}}:i[o]={[l]:{[d]:[{...f}]}}}return{map:i,remove:r,add:c,removeAll:e,get:s,getLte:t,getGte:n}}const nn=[A.expect,A.setNextBranch],sn=1/0;function ft(i){let e=i,t;const n=rn(),s=new tn;let r;const c=()=>{u(),j()},o=h=>{s.add.call(void 0,h),y()},l=(h=[])=>{for(const m of h)if(m.action(),nn.includes(m.actionType))break},d=h=>{var m,p,g;if(!n.isReady(h))return;const v=_e((m=s.get({timestamp:h,priority:"control"}))!==null&&m!==void 0?m:{}),I=_e((p=s.get({timestamp:h,priority:"container"}))!==null&&p!==void 0?p:{}),S=_e((g=s.get({timestamp:h,priority:"chapter"}))!==null&&g!==void 0?g:{});l([...v,...I,...S])},f=()=>{var h;l([..._e((h=s.get({timestamp:1/0,priority:"chapter"}))!==null&&h!==void 0?h:{})])},u=()=>{t&&(r==null||r.unsubscribe(),t=void 0)},y=()=>{t||(t=()=>setTimeout(()=>{d(1/0)}),r=e.events.ended$.subscribe(t))},C=h=>{u(),e=h},E=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},j=()=>{n.release(),s.removeAll()};return{setPlayer:C,add:o,remove:E,exec:d,execEndOfVideo:f,listen:y,unlisten:u,release:c,containersEventsCallState:n}}function rn(){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 d of c){const f=(o=d.endTime)!==null&&o!==void 0?o:sn,u=(l=i.get(f))!==null&&l!==void 0?l:{};i.set(f,{...u,[d.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 _e(i){return Object.values(i).flat().sort(e=>e.actionType===A.expect?-1:1)}const an=(i,e)=>{const{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:s,clientWidth:r}=e.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};const c=t/n,o=s/r;let l,d;return o>c?(d=r,l=r*c):o<c?(d=s/c,l=s):(d=r,l=s),{videoContentWidth:d,videoContentHeight:l}},on=250;function ln(i){let e=()=>{};const t=new ResizeObserver(o=>{r(o),e=r.bind(null,o)});function n(o){const{parentElement:l,player:d}=i();if(l&&d){const{videoContentWidth:f,videoContentHeight:u}=an(l,d);l.style.setProperty("--interactive-content-width",`${f}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 s(){const{parentElement:o}=i();o.removeAttribute("style")}const r=Lt(o=>{const{fns:l=[]}=i();n(o);for(const d of l)d()},on);function c(){e=void 0,t.disconnect(),s()}return{resizeObserver:t,calc:()=>{e()},release:c}}class cn{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){const t=this.map[e];return t?t.slice():null}getAll(){const e=[];for(const t in this.map)e.push(...this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),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 dn=i=>Math.floor(Math.random()*i),hn=i=>{let e=i.length,t=1/0,n=null;for(;e--;)i[e].weight<t&&(t=i[e].weight,n=i[e]);return n},un=i=>{let e=i.length,t=-1/0,n=null;for(;e--;)i[e].weight>t&&(t=i[e].weight,n=i[e]);return n},fn=i=>{const e=i.length,t=dn(e);return i[t]},pt=1,pn=i=>{var e,t;let n=0;for(let r=0;r<i.length;++r)n+=(e=i[r].weight)!==null&&e!==void 0?e:pt;const s=Math.random()*n;n=0;for(let r=0;r<i.length-1;++r)if(n+=(t=i[r].weight)!==null&&t!==void 0?t:pt,n>=s)return i[r];return i[i.length-1]},vt=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),Le=(i,e=!1)=>({...i,args:e?{...i.args,...vt}:{...vt,...i.args}}),mt=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},c=({action:h,controlType:m,controlId:p,containerId:g,branches:v=[],onEvent:I,isEOV:S=()=>!1})=>{const w=Le(h,S()),R={timestamp:1/0,priority:"control",initiator:p,actionType:w.type},V=i.emit.bind(i,b.interactives,{subjectId:p,subjectType:m,subjectName:"control",type:N.actionChoice,actionType:h.type,payload:{containerId:g,...w.args}});switch(w.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const P=v.find($=>$.id===w.args.branchId);if(!P)return;I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),V(),w.args.shouldOpenNow?E({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}}):(t.add({...R,action:E.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}})}),n==null||n());return}case A.continuePlayback.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),V(),w.args.shouldOpenNow?C({subjectId:p,subjectName:"control",subjectType:m,action:h}):t.add({...R,action:C.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:h})});return}case A.openURI.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),V(),w.args.shouldOpenNow?j({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}}):(t.add({...R,action:j.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(b.errors,new L(L.Severity.RECOVERABLE,L.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:h,container:{id:m,endTime:p},branches:g=[],isEOV:v=!1,autoSelected:I=!1})=>{const S=Le(h,v),w={timestamp:!S.args.shouldOpenNow||v?1/0:p,priority:"container",initiator:m,actionType:S.type},R=i.emit.bind(i,b.interactives,{subjectId:m,subjectName:"container",type:N.actionChoice,actionType:S.type,payload:S.args});switch(S.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const V=g.find(P=>P.id===S.args.branchId);if(!V)return;R(),t.add({...w,action:E.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{chapterId:V.chapterId,autoSelect:I}})}),n==null||n();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{R(),t.add({...w,action:C.bind(null,{subjectId:m,subjectName:"container",action:S})});return}case A.openURI.trim().toLowerCase():{R(),t.add({...w,action:j.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{URI:h.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(b.errors,new L(L.Severity.RECOVERABLE,L.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:h,branches:m,isEOV:p=!1}){const g=ut(h.events);if(g){const v=Le(g.action,p);i.emit(b.interactives,{subjectId:h.id,subjectName:"container",type:N.actionChoice,actionType:v.type,payload:v.args}),t.add({timestamp:p?1/0:h.endTime,priority:"container",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),s.isExpect=!0}else for(const v of h.events)o({action:v.action,container:h,branches:m,isEOV:p})}const d=({chapterId:h,action:m,branches:p=[]})=>{const g=i.emit.bind(i,b.interactives,{subjectId:h,subjectName:"chapter",type:N.actionChoice,actionType:m.type,payload:m.args});switch(m.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const v=p.find(I=>I.id===m.args.branchId);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{const v=fn(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{const v=pn(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{const v=un(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{const v=hn(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m});case A.openURI.trim().toLowerCase():return g(),j.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{URI:m.args.uri}});default:console.error("Unexpected chapter event"),i.emit(b.errors,new L(L.Severity.RECOVERABLE,L.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){const m=ut(h.events);if(m){if($t(h))return;i.emit(b.interactives,{subjectId:h.id,subjectName:"chapter",type:N.actionChoice,actionType:m.action.type,payload:m.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events.forEach(p=>{const g=d({chapterId:h.id,action:p.action,branches:h.branches});g&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:p.action.type,action:g})})}const u=({subjectId:h,subjectName:m,action:p})=>{var g;e.pause(),i.emit(b.interactives,{subjectId:h,subjectName:m,type:N.actionExecution,actionType:(g=p==null?void 0:p.type)!==null&&g!==void 0?g:A.expect})},y=({subjectId:h,subjectName:m})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(b.interactives,{subjectId:h,subjectName:m,type:N.actionExecution,actionType:"after-expect"})},C=({subjectId:h,subjectName:m,subjectType:p,action:g})=>{i.emit(b.interactives,{subjectId:h,subjectName:m,subjectType:p,type:N.actionExecution,actionType:g.type})},E=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{v.behaviour="change-chapter",i.emit(b.interactives,{subjectId:h,subjectName:m,subjectType:p,type:N.actionExecution,actionType:g.type,payload:v})},j=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{if(!v.URI)return;const I=window.open(v.URI,"_blank","noopener,noreferrer");I&&(I.opener=null),i.emit(b.interactives,{subjectId:h,subjectName:m,subjectType:p,type:N.actionExecution,actionType:g.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:r,state:s}};var he,Dt,Ve,gt;class q{constructor(e,t,n,s){this.target=e,this.type=t,this.listener=n,this.options=a(q,he,"m",Dt).call(q,e,s),this.target.addEventListener(t,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}he=q,Dt=function(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{const n=new Set(["passive","capture"]),s=Object.keys(t).filter(c=>!n.has(c));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),a(q,he,"m",gt).call(q,e)?t:t.capture||!1}},gt=function(e){let t=a(q,he,"f",Ve);if(t===void 0){t=!1;try{const n={},s={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);const r=()=>{};e.addEventListener("test",r,n),e.removeEventListener("test",r,n)}catch(n){t=!1}_(q,he,t,"f",Ve)}return t||!1};Ve={value:void 0};class vn{constructor(){this.bindingMap=new cn}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,s){if(!this.bindingMap)return;const r=new q(e,t,n,s);this.bindingMap.push(t,r)}listenOnce(e,t,n,s){const r=c=>{this.unlisten(e,t,r),n(c)};this.listen(e,t,r,s)}unlisten(e,t,n){if(!this.bindingMap)return;const s=this.bindingMap.get(t)||[];for(const r of s)r.target===e&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(t,r))}removeAll(){if(!this.bindingMap)return;const e=this.bindingMap.getAll();for(const t of e)t.unlisten();this.bindingMap.clear()}}class mn{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 t=(e=this.rootElement.getContext("2d"))===null||e===void 0?void 0:e.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;const n=t.data,s=n.length;for(let r=3;r<s;r+=40)if(n[r]!==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,t=!1){const n=e.width+e.height;if(this._prevSizeId===n)return;let s;t&&(s=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&s&&this.restore(s),this._prevSizeId=n}async save(){const e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}}class gn{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=s=>{const r=s!=null?s:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(r);if(this.isContainerTime(r))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 Ut=Object.create;var Qe=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var Xt=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of qt(e))!Kt.call(i,s)&&s!==t&&Qe(i,s,{get:()=>e[s],enumerable:!(n=zt(e,s))||n.enumerable});return i};var Zt=(i,e,t)=>(t=i!=null?Ut(Qt(i)):{},Xt(e||!i||!i.__esModule?Qe(t,"default",{value:i,enumerable:!0}):t,i));var G=require("@vkontakte/videoplayer-shared/es2018.cjs.js"),Be=require("uuid"),Yt=require("@vkontakte/videoplayer-core/es2018.cjs.js");const Jt="1.0.6-dev.9aa76b8.0";function Ct(i,e=1){let t="0",n="0",s="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+s},${e})`}const W="SDK_NAME",ei="SDK_NAME-controls-container",Et=()=>document.querySelector(`.${ei}`),z={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"},Xe={start:"flex-start",end:"flex-end",center:"center"},Ze={start:"left",end:"right",center:"center"},wt=({target:i,props:e})=>{var t,n,s,r,c,o;i.style.alignItems=(n=Ke[(t=e==null?void 0:e.text)===null||t===void 0?void 0:t.gravityVertical])!==null&&n!==void 0?n:Ke.center,i.style.justifyContent=(r=Xe[(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:Xe.center,i.style.textAlign=(o=Ze[(c=e==null?void 0:e.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:Ze.start},_t=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d;i.style.color=(r=(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:t.textColor,i.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:t.textSize})`,i.textContent=(d=(l=e==null?void 0:e.text)===null||l===void 0?void 0:l.value)!==null&&d!==void 0?d:t.textContent},It=({target:i,props:e,fallback:t})=>{var n,s,r,c;i.style.backgroundColor=Ct((s=(n=e==null?void 0:e.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:t.backgroundColor,(c=(r=e==null?void 0:e.background)===null||r===void 0?void 0:r.alpha)!==null&&c!==void 0?c:t.backgroundAlpha)},St=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d,f,u,y,C,E;i.style.border=`calc(${n.height} * ${(c=(r=(s=e==null?void 0:e.shape)===null||s===void 0?void 0:s.border)===null||r===void 0?void 0:r.width)!==null&&c!==void 0?c:t.borderWidth}) solid ${Ct((d=(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&&d!==void 0?d:t.borderColor,(y=(u=(f=e==null?void 0:e.shape)===null||f===void 0?void 0:f.border)===null||u===void 0?void 0:u.alpha)!==null&&y!==void 0?y:t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(E=(C=e==null?void 0:e.shape)===null||C===void 0?void 0:C.roundCorners)!==null&&E!==void 0?E:t.roundCorners})`},$e=({target:i,layoutParams:e,fallback:t})=>{var n;i.style.transform=`rotate(${(n=-e.angle)!==null&&n!==void 0?n:t.angle}rad)`};class De{constructor(e){this.control=e}createView(e){var t;const n=document.createElement("div");n.classList.add(`${W}-control-container-${this.control.id}`),e(n,this.control.layoutParams);const s=((t=this.control.layoutParams.innerSizesDependOn)!==null&&t!==void 0?t:z.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:s}}setEvents(e,t){e&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",r=>{r.stopPropagation(),t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${W}-control-container-${this.control.id}`)}}const Tt=i=>{if(i.type.trim().toLowerCase()==="area")return new ti(i)};class ti extends De{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");return r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",It({target:r,props:this.control.props,fallback:{...z,backgroundColor:"transparent"}}),St({target:r,props:this.control.props,fallback:{...z,borderAlpha:0},dependsOn:n}),$e({target:r,layoutParams:this.control.layoutParams,fallback:z}),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const Rt=i=>{if(i.type.trim().toLowerCase()==="button")return new ii(i)};class ii extends De{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");r.type="button",r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.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",$e({target:r,layoutParams:this.control.layoutParams,fallback:z}),It({target:r,props:this.control.props,fallback:z}),St({target:r,props:this.control.props,fallback:z,dependsOn:n}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:z,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const ni=i=>{if(i.type.trim().toLowerCase()==="text")return new si(i)};class si extends De{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("div");r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",$e({target:r,layoutParams:this.control.layoutParams,fallback:z}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:z,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}class ri{constructor(e){this.layout=e}}const ai=i=>{if(i.type.trim().toLowerCase()==="relative")return new At(i)};class At extends ri{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function a(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)}function _(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t}var re,Ie,Ye;class xt{constructor(e){re.add(this),this.container=e,this.factories=new Map,a(this,re,"m",Ie).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),a(this,re,"m",Ie).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),a(this,re,"m",Ie).call(this)}}re=new WeakSet,Ie=function(){this.controls=a(this,re,"m",Ye).call(this)},Ye=function(){var e;return(e=this.container.controls)===null||e===void 0?void 0:e.reduce((t,n)=>{const s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...t,r(n)]:[...t]},[])};const Ot=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new oi(i,e)};class oi extends xt{constructor(e,t){super(e),this.rootElement=t!=null?t:Et(),this.layout=new At(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",Rt),this.addControlFactory("text",ni),this.addControlFactory("area",Tt)}createView(e){const t=document.createElement("div");return t.classList.add(`${W}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const s=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(s,e)}),this.rootElement.append(t),t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){var e;this.isRemoved||((e=this.getElement())===null||e===void 0||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${W}-${this.container.id}`)}}function Lt(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const ge={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},de=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,We=i=>de(i,ge.Object),Ne=i=>de(i,ge.String),le=i=>de(i,ge.Array),Nt=i=>de(i,ge.Number),li=i=>de(i,ge.Function),Je=i=>Nt(i)&&!isNaN(i),ci=i=>i==null,pe=i=>We(i)&&Object.keys(i).length===0,jt=i=>le(i)&&!i.length,Ce=(i,e)=>Ne(i)&&(e?i.trim():i).length,Mt=window.navigator.userAgent.toLowerCase(),di=/mobi/i.test(Mt);Mt.indexOf("android")>-1;const hi="video_interactive",ui="videoint",fi=250;class pi{constructor(e){this.onResize=t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))},this.handleChapterChange=t=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.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(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(t,n=[])=>{var s;if(!Nt(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)===null||s===void 0||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await G.loadVKLangPack(this.lang,hi,ui)}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:r}),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),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0},this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=t,this.onError=n,this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=vi(e),this.resizeObserver=new ResizeObserver(Lt(this.onResize,fi)),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,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)===null||e===void 0||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)===null||t===void 0||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function vi(i){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",i.append(e),e}const mi=(i={})=>{var e;return Array.from(new Set((e=i.sessions)===null||e===void 0?void 0:e.map(t=>{var n;return(n=t.visitedChapters.map(s=>s.chapterId))!==null&&n!==void 0?n:[]}).flat()))},et=(i=[],e="")=>i.reduce((t,n)=>(t.find(s=>s[e]===n[e])||t.push(n),t),[]),tt="chapterId";class ae{constructor(e){var t;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:Be.v4(),this.startDate=e!=null&&e.startDate?new Date(e.startDate).toISOString():new Date(Date.now()).toISOString(),this.updateOn=e!=null&&e.updateOn?new Date(e.updateOn).toISOString():null,this.visitedChapters=e!=null&&e.visitedChapters?et(Array.from(e.visitedChapters),tt):[],this.branches=le(e==null?void 0:e.branches)?e.branches:[]}update(e){e!=null&&e.startDate&&(this.startDate=new Date(e.startDate).toISOString()),e!=null&&e.updateOn&&(this.updateOn=new Date(e.updateOn).toISOString()),le(e==null?void 0:e.visitedChapters)&&(this.visitedChapters=et([...this.visitedChapters,...e.visitedChapters],tt)),le(e==null?void 0:e.branches)&&(this.branches=this.branches.concat(e.branches))}getSession(){return{...this}}static createVisitedChapter(e){return[{chapterId:e}]}static createBranch(e,t,n){return[{chapterId:e,branchId:t,autoSelect:n}]}}class Ee{constructor(e){var t,n;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:Be.v4(),this.manifestId=e==null?void 0:e.manifestId,this.manifestVersion=e==null?void 0:e.manifestVersion,this.manifestBuild=e==null?void 0:e.manifestBuild,this.sessions=le(e==null?void 0:e.sessions)?e==null?void 0:e.sessions.map(s=>new ae(s)):[],this.isCompleted=(n=e==null?void 0:e.isCompleted)!==null&&n!==void 0?n:!1}update(e){var t,n,s,r,c;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:this.id,this.manifestId=(n=e==null?void 0:e.manifestId)!==null&&n!==void 0?n:this.manifestId,this.manifestVersion=(s=e==null?void 0:e.manifestVersion)!==null&&s!==void 0?s:this.manifestVersion,this.manifestBuild=(r=e==null?void 0:e.manifestBuild)!==null&&r!==void 0?r:this.manifestBuild,this.isCompleted=(c=e==null?void 0:e.isCompleted)!==null&&c!==void 0?c:this.isCompleted}addSession(e){this.sessions.push(new ae(e))}updateSession(e,t){let n;ci(e)?n=this.sessions[this.sessions.length-1]:n=this.sessions.find(s=>s.id===e),n&&n.update(t)}resetSession(){this.sessions=[]}getHistory(){return{...this,sessions:this.sessions.map(e=>e.getSession())}}}const je="SDK_NAME-history-changed";class gi extends EventTarget{constructor(){super(),this.history=new Ee,this.sendEvent()}onChapterChange({chapterId:e,mediaId:t,autoSelect:n=!1,isLastChapter:s=!1}){this.history.isCompleted?this.history=new Ee({manifestId:this.history.manifestId,manifestVersion:this.history.manifestVersion,manifestBuild:this.history.manifestBuild}):s&&this.history.update({isCompleted:!0}),this.history.sessions.length?this.history.updateSession(null,{updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,n)}):this.history.addSession({updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,!1)}),this.sendEvent()}onManifestChange(e,t){t?this.history=new Ee(t):this.history=new Ee({manifestId:e.id,manifestVersion:e.version,manifestBuild:e.build}),this.history.addSession({updateOn:Date.now()}),this.sendEvent()}getHistory(){if(history)return this.history.getHistory()}sendEvent(){this.dispatchEvent(new CustomEvent(je,{bubbles:!1,detail:this.getHistory()}))}destroy(){this.history=void 0}}function yi(i,e){var t;if(!e||!i||!e.sessions.length)return;const n=e.sessions.reverse().find(s=>s.branches.length);return(t=n.branches[n.branches.length-1].chapterId)!==null&&t!==void 0?t:void 0}const me=(i="",e="")=>{i=i.split("."),e=e.split(".");let t=0;for(let n=0;n<Math.max(i.length,e.length)&&!t;n++)i[n]>e[n]?t=1:i[n]<e[n]?t=-1:t=0;return t},bi="3.1",it={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Ci={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ei=i=>{const e=[];for(const t of i.chapters){let n;const s=[];for(const{isDefault:o,...l}of t.branches)o&&(n=l.id),s.push(l);let r=[];const c=[];for(const{fallbackStrategy:o,...l}of t.containers){const d=!!l.endTime;let f=[Ci];switch(o){case"await":d?f=[]:r=[];break;case"default":{const u={type:"onSuspense",action:{type:it.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?f=[u]:r=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:it[o],args:{}}};d?f=[u]:r=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:Be.v4(),events:f})}e.push({...t,containers:c,events:r,branches:s})}return i.metadata.version=bi,i.metadata.updated=new Date().toISOString(),{...i,chapters:e}},wi="3.2",_i=i=>{if(!i.media){const{media:e,...t}=i.metadata;return{...i,metadata:{...t,version:wi},media:e}}return i},Ii="3.3",Si=(i=[])=>({edit:{chapters:i},view:{}}),nt={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ti=i=>{var e;const t=[],n=[];for(const s of i.chapters){const{id:r,x:c,y:o,...l}=s,d=l.containers.map(f=>{var u;return{...f,controls:f.controls.map(({subtype:y,type:C,...E})=>({...E,type:y!=null?y:C})),events:!((u=f.events)===null||u===void 0)&&u.length?f.events:[nt]}});t.push({id:r,...l,containers:d,events:!((e=l.events)===null||e===void 0)&&e.length?l.events:[nt]}),n.push({id:r,x:c,y:o})}return{...i,chapters:t,graph:Si(n),metadata:{...i.metadata,version:Ii}}},Ri=[{version:"3.0",migrate:Ei},{version:"3.1",migrate:_i},{version:"3.2",migrate:Ti}],Ai=i=>Ri.reduce((e,t)=>me(e.metadata.version,t.version)?e:t.migrate(e),i),xi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),A=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 st={metadata:"Object",chapters:"Array"},Oi="3.0.0",Li="3.3.0",He=i=>{const e=me(i,Oi);return e===-1?!1:e===0?!0:me(i,Li)!==1},Ni=i=>{if(!We(i))return!1;for(const e in st)if(!i[e]||!de(i[e],st[e]))return!1;return He(i.metadata.version)},ji=i=>i.type===xi.Text;class L{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}L.Severity={RECOVERABLE:1,CRITICAL:2};L.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Vt{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];const n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){const n=this.listeners[e];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===t){n.splice(s,1);break}return this}emit(e,...t){const n=this.listeners[e];return n?(n.forEach(s=>{s(...t)}),!0):!1}listenerCount(e){return(this.listeners[e]||[]).length}rawListeners(e){return this.listeners[e]}}class Mi{constructor(e){this.addFn=(t,n=!1)=>{li(t)&&(this.fns.push(t),n&&this.updateFn())},this.removeFn=(t,n=!1)=>{this.fns=this.fns.filter(s=>s!==t),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Vi{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!==null&&t!==void 0?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(e,t){return ki(...this.loaders[e])(t)}}function ki(...i){return async function(t){const n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Ae(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function Me({actions:i,errors:e,chapterId:t,...n}){if(t){const s=i.getManifest(),r=i.getChapter(s.chapters,t);if(r){const c=i.getMedia(s.media,r.videoId),o=i.getGraph(s.graph,r.id);return c?{...n,actions:i,errors:e,result:{chapter:r,media:c,graph:o}}:{...n,errors:Ae(e,Me.name,"Could not find media"),actions:i}}}return{...n,errors:Ae(e,Me.name,"Could not find chapter"),actions:i}}class rt{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;const n=this.listeners[e];for(let s=0,r=n.length;s<r;s++)if(n[s].callback===t){n.splice(s,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const n=this.listeners[e.type].slice();for(let s=0,r=n.length;s<r;s++){const c=n[s];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 kt extends rt{constructor(){super(),this.listeners||rt.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 Pi{constructor(){Object.defineProperty(this,"signal",{value:new kt,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(s){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={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(s){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(Pi.prototype[Symbol.toStringTag]="AbortController",kt.prototype[Symbol.toStringTag]="AbortSignal");function Pt(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 Fi(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=i;if(!Pt({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:e,Request:r};let r=t;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(d,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const y=new t(d,f);return u&&Object.defineProperty(y,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),y},r.prototype=t.prototype);const c=e;return{fetch:(l,d)=>{const f=r&&r.prototype.isPrototypeOf(l)?l.signal:d?d.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch(C){u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const y=new Promise((C,E)=>{f.addEventListener("abort",()=>E(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([y,c(l,d)])}return c(l,d)},Request:r}}const Ge=Pt({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ft=Ge?Fi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,at=Ge?Ft.fetch:window.fetch;Ge?Ft.Request:window.Request;const Bi=async i=>{try{let e,t;if(We(i))e=i;else if(Ne(i)){t=new URL(i).href;const s=await at(t);if(!s.ok)return{};e=await s.json()}else return{};if(!Ni(e))return{};const n=e.metadata.media;if(Ne(n)&&!e.media)try{let s;t?s=new URL(n,t).href:(s=new URL(n).href,t=s);const r=await at(s);if(!r.ok)throw new Error;e.metadata.media=await r.json()}catch(s){return Hi(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function $i(i){const{manifest:e,manifestURL:t}=await Bi(i),n=Ai(e);return n.media=Di(n.media,t),delete n.metadata.media,n}function Oe(i,e){return i.find(t=>t.id===e)}function ot(i,e){var t,n;return!((t=i.edit)===null||t===void 0)&&t.chapters?i.edit.chapters.find(s=>s.id===e):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(s=>s.id===e):void 0}function lt(i,e){return i.videos.find(t=>t.id===e)}function Di(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{const s=Wi(n.url,e);return{...n,url:s||n.url}})}))}}function Wi(i,e){try{return new URL(i,e).href}catch(t){return""}}function Hi(i){return me(i,"3.2.0")>=0}class Bt extends Vi{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}async setManifest(e){var t;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ae},result:null,errors:null,source:e});n.errors&&this.errorHandler(n.errors);const s=await $i((t=n.result)!==null&&t!==void 0?t:e);return this.manifest=s,this}async setInitial(){return this.setNext()}async setNext(e=this.manifest.metadata.initChapterId){const t=await this.exec("chapterLoaders",Me({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ot,getChapter:Oe,getMedia:lt,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ae},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.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 t=Oe(this.manifest.chapters,e);if(t){const n=lt(this.manifest.media,t.videoId),s=ot(this.manifest.graph,t.id);if(n)return{chapter:t,media:n,graph:s}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{const t=Oe(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const s=this.getByChapterId(n.chapterId);return s&&t.push(s),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const b={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},ct={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},N={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Gi(){const i=new Map;function e({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...c}){const o=i.get(s),l={...c};return o?o[r]=l:i.set(s,{[r]:l}),{listId:s,itemId:r,...c}}function t(s,r){var c,o,l;const d=i.get(s);if(d){if(r)return(c=d[r])===null||c===void 0||c.player.destroy(),(o=d[r])===null||o===void 0||o.container.remove(),(l=d[r])===null||l===void 0||l.subscription.unsubscribe(),delete d[r],Object.keys(d).length||i.delete(s),!0;for(const f of Object.values(d))f.player.destroy(),f.container.remove();return i.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(const s of i)t(s[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:n}}function dt(i,e=[]){let t={},n;const s=!e.length;for(const r of i.variants)switch(!n&&"cover"in r&&(n=r.cover),r.type){case"mp4":(s||e.includes("mp4"))&&(t={...t,MPEG:{"Invariant quality":r.url}});break;case"hls":(s||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:r.url}});break;case"dash":(s||e.includes("dash"))&&(t={...t,DASH:{type:"url",url:r.url}});break}return{sources:t,thumbUrl:n,title:i.id}}const we=(i,e)=>{const t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))},Ui=i=>{const e=i.variants.find(t=>{var n;return((n=t.payload)===null||n===void 0?void 0:n.type)==="vk"});if(e&&"payload"in e){const[t,n]=e.payload.id.split("_");return[t,n]}return[]},Se={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},zi=2;function qi(i){const e=Gi();let t,n;const s=new Vt;let r={},c=!1,o=null,l=!1,d;i&&f(i);function f(p){o=p}function u(p,g,v){var I;if(!o)throw Error("need to set interactive controller");const w=((I=e.map.get(p))!==null&&I!==void 0?I:{})[g];if(w){r={chapterId:v,listId:p,itemId:g,...w};const R=r.player;n=R.info.currentQuality$.subscribe(V=>{if(!(!V||!R.info.position$.getValue())){t=V;for(const P of e.map)Object.values(P[1]).forEach(({player:$})=>{R.info.isAutoQualityEnabled$.getValue()||we($,V)})}}),w.container.remove(),c=!1,o.setPlayer(w.player),l||(o.init(),l=!0),s.emit(Se.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function y(p,g,v){if(!o)throw Error("need to set interactive controller");if(pe(r)||p!==r.itemId)return;if(v>=0&&!c){const S=o.getChapterBranches();c=!0;const w=new Set;for(const R of S)w.has(R.media.id)||(await E({media:R.media,chapterId:R.chapter.id,setAsActive:!1,title:R.chapter.label}),w.add(R.media.id))}}async function C({chapter:{id:p},media:g}){if(pe(r))return;n==null||n.unsubscribe();const v=r.player.info.muted$.getValue(),I=r.player.info.currentQuality$.getValue(),S=r.player.info.isAutoQualityEnabled$.getValue(),w=r.player.info.volume$.getValue(),R=r.player.info.currentPlaybackRate$.getValue(),V=!S;let P=!1;for(const $ of e.map)if($[0]===g.id){const ie=Object.keys($[1]);for(const Z of ie)Z===r.itemId?(ie.length<zi||(P=!0),e.removePlayer($[0],Z)):(P=!0,u($[0],Z,p),V?we(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v),r.player.setPlaybackRate(R))}else e.removePlayer($[0]);P||(await E({media:g,chapterId:p,setAsActive:!0,playbackRate:R}),V?we(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v))}async function E({media:p,chapterId:g,prefetch:v=!0,setAsActive:I=!0,autoplay:S=!1,preferredExt:w,title:R,playbackRate:V}){var P,$,ie;const Z=Math.random().toString(),ne=document.createElement("div");d.append(ne);const Ht=(P=r==null?void 0:r.player)===null||P===void 0?void 0:P.info.isAutoQualityEnabled$.getValue();let ye;if(!(($=o==null?void 0:o.options)===null||$===void 0)&&$.vkVideoLoader){const be=Ui(p);be.length&&(ye=await o.options.vkVideoLoader(...be))}const ze={container:ne,...((ie=ye==null?void 0:ye.videos)===null||ie===void 0?void 0:ie[0])||{sources:dt(p,w).sources},title:R},Y=new Yt.Player;Y.initVideo(ze);const Gt=ne.lastChild,qe=new G.Subscription;qe.add(Y.info.position$.subscribe(function(be){y(Z,Y.info.duration$.getValue(),be)})).add(Y.events.canplay$.subscribe(function(){Ht||we(Y,t),V&&Y.setPlaybackRate(V)})),Gt&&(ne.style.display="none",ne.classList.add(g));const se=e.createPlayer({listId:p.id,itemId:Z,player:Y,container:ne,sources:dt(p,w).sources,config:ze,subscription:qe});return I&&u(p.id,se.itemId,g),S&&se.player.play(),v&&!S&&se.player.prepare(),s.emit(Se.playerCreated,se.player),{player:se.player,config:se.config}}function j(){h(),o=null}function h(){o==null||o.off(b.chapterChanged,C),e.removeAll(),r={},l=!1,c=!1}async function m({source:p,initialChapter:g,container:v}){if(!o)throw Error("need to set interactive controller");await o.setManifest(p),h(),d=v;const{media:I,chapter:S}=await o.setChapter({chapterId:g});if(I){o.on(b.chapterChanged,C);const{player:w,config:R}=await E({media:I,chapterId:S.id,title:S.label});return s.emit(Se.initiated,{container:v,media:I,chapterId:S.id}),{player:w,config:R}}else console.error("not found")}return{...e,on:s.on.bind(s),off:s.off.bind(s),init:m,setInteractiveController:f,createPlayer:E,removeAll:j,getActivePlayer:function(){return r}}}const Qi=3e3,Ki=()=>{let i=[],e=null;return{setPlayer:c=>{e=c},setContainers:c=>{i=c},deleteContainer:c=>{i=i.filter(o=>o.id!==c)},getNextInteractiveTime:(c=Qi)=>{if(!i.length||e===null)return null;let o=-1,l=!1;const d=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-c;if(u<=d&&(d<=f.endTime||f.endTime===null)){l=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},ce=Ki(),O=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ue=i=>le(i)&&!jt(i),$t=i=>jt(i.branches)||i.order==="end",Xi=(i,e)=>{var t;const n=i*1e3;return Ue(e.controls)&&n<((t=e.startTime)!==null&&t!==void 0?t:0)},ht=(i,e)=>{var t,n;const s=i*1e3;return Ue(e.controls)&&s>=((t=e.startTime)!==null&&t!==void 0?t:0)&&s<=((n=e.endTime)!==null&&n!==void 0?n:1/0)},xe=i=>i.some(e=>e.action.type==="expect"),ut=i=>i.find(e=>e.action.type==="expect"),Zi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i({...n[e],...t[e]}),Yi=(i=[])=>i.reduce((e,t,n)=>{var s,r,c;const o=((s=t==null?void 0:t.controls)!==null&&s!==void 0?s:[]).filter(l=>!ji(l));if(Ue(o)){const l=[(r=t.startTime)!==null&&r!==void 0?r:0,(c=t.endTime)!==null&&c!==void 0?c:1/0],d=t.id;if(!n)e.push({subjects:[d],range:l});else{const f=[];let u=-1/0,y=1/0,C=[];const E=[];for(let j=0;j<e.length;j++){const h=e[j];if(E.push(...h.subjects),h.range[0]<y&&(y=h.range[0]),h.range[1]>u&&(u=h.range[1]),h.range[0]<=l[0]&&h.range[1]>=l[1])return e[j].subjects.push(d),e;l[0]>=h.range[0]&&l[0]<=h.range[1]&&(f.push(j),C=C.concat(h.subjects),l[0]=h.range[0]),l[1]>=h.range[0]&&l[1]<=h.range[1]&&(f.push(j),C=C.concat(h.subjects),l[1]=h.range[1])}if(E.push(d),l[0]<=y&&l[1]>=u)return[{subjects:E,range:l}];f.length&&f.reverse().forEach(j=>{e.splice(j,1)}),e.push({subjects:C.concat([d]),range:l})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),Ji=(i,e)=>xe(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&xe(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class en{constructor({player:e,container:t,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:c,ignoreContainerEvent:o}){this.hide=()=>{setTimeout(()=>{var l,d;this.gameState!==O.end&&(xe(this.container.container.events)&&this.gameState===O.afterInteractive||this.selectBranches.state.isExpect||((d=(l=this.container).hide)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})))})},this.show=()=>{var l,d;if(this.gameState===O.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(d=(l=this.container).show)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!0,isFirst:!1});else{const u=Zi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})},onEvent:(y,C)=>{this.isSelectedControlEvent=!0,y!==!1&&(this.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})),(this.gameState===O.end||this.gameState===O.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),C(),this.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})),ce.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===O.end});this.container.createView(u),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!0,isFirst:!0})}},this.onEndOfVideo=()=>{this.gameState=O.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var l,d,f,u;if(((l=this.player.experimental.element$.getValue())===null||l===void 0?void 0:l.readyState)<1||[O.destroyed,O.removed].includes(this.gameState))return;const C=this.player.info.position$.getValue();if(Xi(C,this.container.container))this.gameState!==O.beforeInteractive&&(this.gameState=O.beforeInteractive,this.onBeforeStartTime());else if(ht(C,this.container.container))this.gameState!==O.interactive&&(this.gameState=O.interactive,this.onStartTime());else if(this.gameState!==O.afterInteractive){const h=this.gameState;this.gameState=O.afterInteractive,h===O.interactive&&this.onEndTime()}else this.gameState!==O.destroyed&&this.removeView();const E=ht(C,this.container.container),j=this.container.container.startTime?[this.container.container.startTime,(d=this.container.container.endTime)!==null&&d!==void 0?d:1/0]:[];(u=(f=this.container).onProgress)===null||u===void 0||u.call(f,C,E),this.globalEventEmitter.emit(b.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:j,currentTime:C,isInteractiveTime:E})},this.container=t,this.branches=n,this.selectBranches=s,this.subscription=new G.Subscription,this.player=e,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.globalEventEmitter=c,this.gameState=O.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))}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=xe(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)===null||t===void 0||t.call(e),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=O.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(b.interactives,{subjectId:this.container.container.id,subjectName:"container",type:N.containerRemoved,visibility:!1}),this.gameState=O.removed}destroy(){var e;this.reset(),this.removeView(),this.gameState=O.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}),ce.deleteContainer(this.container.container.id)}}function tn(){const i={};function e(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function t(o){const l={};for(const d in i)+d<=o&&(l[d]=i[d]);return l}function n(o){const l={};for(const d in i)+d>=o&&(l[d]=i[d]);return l}function s({timestamp:o,priority:l,initiator:d}){var f;if(Je(o)){const u=(f=i[o])!==null&&f!==void 0?f:null;if(u&&Ce(l,!0)){let y={};const C=u[l];if(C&&(y={...y,...C}),y=pe(y)?null:y,y&&Ce(d,!0)){const E=y[d];return E!=null?E:null}return y}return u}return null}function r({timestamp:o,priority:l,initiator:d}){if(Je(o))if(i[o]){if(Ce(l,!0))if(i[o][l]){if(Ce(d,!0))if(i[o][l][d]){if(delete i[o][l][d],!pe(i[o][l]))return!0}else return!1;if(delete i[o][l],!pe(i[o]))return!0}else return!1;return delete i[o]}else return!1}function c({timestamp:o,priority:l,initiator:d,...f}){var u,y,C;!((y=(u=i[o])===null||u===void 0?void 0:u[l])===null||y===void 0)&&y[d]?i[o][l][d].push({...f}):!((C=i[o])===null||C===void 0)&&C[l]?i[o][l]={...i[o][l],[d]:[{...f}]}:i[o]?i[o]={...i[o],[l]:{[d]:[{...f}]}}:i[o]={[l]:{[d]:[{...f}]}}}return{map:i,remove:r,add:c,removeAll:e,get:s,getLte:t,getGte:n}}const nn=[A.expect,A.setNextBranch],sn=1/0;function ft(i){let e=i,t;const n=rn(),s=new tn;let r;const c=()=>{u(),j()},o=h=>{s.add.call(void 0,h),y()},l=(h=[])=>{for(const m of h)if(m.action(),nn.includes(m.actionType))break},d=h=>{var m,p,g;if(!n.isReady(h))return;const v=_e((m=s.get({timestamp:h,priority:"control"}))!==null&&m!==void 0?m:{}),I=_e((p=s.get({timestamp:h,priority:"container"}))!==null&&p!==void 0?p:{}),S=_e((g=s.get({timestamp:h,priority:"chapter"}))!==null&&g!==void 0?g:{});l([...v,...I,...S])},f=()=>{var h;l([..._e((h=s.get({timestamp:1/0,priority:"chapter"}))!==null&&h!==void 0?h:{})])},u=()=>{t&&(r==null||r.unsubscribe(),t=void 0)},y=()=>{t||(t=()=>setTimeout(()=>{d(1/0)}),r=e.events.ended$.subscribe(t))},C=h=>{u(),e=h},E=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},j=()=>{n.release(),s.removeAll()};return{setPlayer:C,add:o,remove:E,exec:d,execEndOfVideo:f,listen:y,unlisten:u,release:c,containersEventsCallState:n}}function rn(){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 d of c){const f=(o=d.endTime)!==null&&o!==void 0?o:sn,u=(l=i.get(f))!==null&&l!==void 0?l:{};i.set(f,{...u,[d.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 _e(i){return Object.values(i).flat().sort(e=>e.actionType===A.expect?-1:1)}const an=(i,e)=>{const{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:s,clientWidth:r}=e.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};const c=t/n,o=s/r;let l,d;return o>c?(d=r,l=r*c):o<c?(d=s/c,l=s):(d=r,l=s),{videoContentWidth:d,videoContentHeight:l}},on=250;function ln(i){let e=()=>{};const t=new ResizeObserver(o=>{r(o),e=r.bind(null,o)});function n(o){const{parentElement:l,player:d}=i();if(l&&d){const{videoContentWidth:f,videoContentHeight:u}=an(l,d);l.style.setProperty("--interactive-content-width",`${f}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 s(){const{parentElement:o}=i();o.removeAttribute("style")}const r=Lt(o=>{const{fns:l=[]}=i();n(o);for(const d of l)d()},on);function c(){e=void 0,t.disconnect(),s()}return{resizeObserver:t,calc:()=>{e()},release:c}}class cn{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){const t=this.map[e];return t?t.slice():null}getAll(){const e=[];for(const t in this.map)e.push(...this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),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 dn=i=>Math.floor(Math.random()*i),hn=i=>{let e=i.length,t=1/0,n=null;for(;e--;)i[e].weight<t&&(t=i[e].weight,n=i[e]);return n},un=i=>{let e=i.length,t=-1/0,n=null;for(;e--;)i[e].weight>t&&(t=i[e].weight,n=i[e]);return n},fn=i=>{const e=i.length,t=dn(e);return i[t]},pt=1,pn=i=>{var e,t;let n=0;for(let r=0;r<i.length;++r)n+=(e=i[r].weight)!==null&&e!==void 0?e:pt;const s=Math.random()*n;n=0;for(let r=0;r<i.length-1;++r)if(n+=(t=i[r].weight)!==null&&t!==void 0?t:pt,n>=s)return i[r];return i[i.length-1]},vt=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),Le=(i,e=!1)=>({...i,args:e?{...i.args,...vt}:{...vt,...i.args}}),mt=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},c=({action:h,controlType:m,controlId:p,containerId:g,branches:v=[],onEvent:I,isEOV:S=()=>!1})=>{const w=Le(h,S()),R={timestamp:1/0,priority:"control",initiator:p,actionType:w.type},V=i.emit.bind(i,b.interactives,{subjectId:p,subjectType:m,subjectName:"control",type:N.actionChoice,actionType:h.type,payload:{containerId:g,...w.args}});switch(w.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const P=v.find($=>$.id===w.args.branchId);if(!P)return;I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),V(),w.args.shouldOpenNow?E({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}}):(t.add({...R,action:E.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}})}),n==null||n());return}case A.continuePlayback.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),V(),w.args.shouldOpenNow?C({subjectId:p,subjectName:"control",subjectType:m,action:h}):t.add({...R,action:C.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:h})});return}case A.openURI.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),V(),w.args.shouldOpenNow?j({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}}):(t.add({...R,action:j.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(b.errors,new L(L.Severity.RECOVERABLE,L.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:h,container:{id:m,endTime:p},branches:g=[],isEOV:v=!1,autoSelected:I=!1})=>{const S=Le(h,v),w={timestamp:!S.args.shouldOpenNow||v?1/0:p,priority:"container",initiator:m,actionType:S.type},R=i.emit.bind(i,b.interactives,{subjectId:m,subjectName:"container",type:N.actionChoice,actionType:S.type,payload:S.args});switch(S.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const V=g.find(P=>P.id===S.args.branchId);if(!V)return;R(),t.add({...w,action:E.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{chapterId:V.chapterId,autoSelect:I}})}),n==null||n();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{R(),t.add({...w,action:C.bind(null,{subjectId:m,subjectName:"container",action:S})});return}case A.openURI.trim().toLowerCase():{R(),t.add({...w,action:j.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{URI:h.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(b.errors,new L(L.Severity.RECOVERABLE,L.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:h,branches:m,isEOV:p=!1}){const g=ut(h.events);if(g){const v=Le(g.action,p);i.emit(b.interactives,{subjectId:h.id,subjectName:"container",type:N.actionChoice,actionType:v.type,payload:v.args}),t.add({timestamp:p?1/0:h.endTime,priority:"container",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),s.isExpect=!0}else for(const v of h.events)o({action:v.action,container:h,branches:m,isEOV:p})}const d=({chapterId:h,action:m,branches:p=[]})=>{const g=i.emit.bind(i,b.interactives,{subjectId:h,subjectName:"chapter",type:N.actionChoice,actionType:m.type,payload:m.args});switch(m.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const v=p.find(I=>I.id===m.args.branchId);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{const v=fn(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{const v=pn(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{const v=un(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{const v=hn(p);return v!=null&&v.chapterId?(g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m});case A.openURI.trim().toLowerCase():return g(),j.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{URI:m.args.uri}});default:console.error("Unexpected chapter event"),i.emit(b.errors,new L(L.Severity.RECOVERABLE,L.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){const m=ut(h.events);if(m){if($t(h))return;i.emit(b.interactives,{subjectId:h.id,subjectName:"chapter",type:N.actionChoice,actionType:m.action.type,payload:m.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events.forEach(p=>{const g=d({chapterId:h.id,action:p.action,branches:h.branches});g&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:p.action.type,action:g})})}const u=({subjectId:h,subjectName:m,action:p})=>{var g;e.pause(),i.emit(b.interactives,{subjectId:h,subjectName:m,type:N.actionExecution,actionType:(g=p==null?void 0:p.type)!==null&&g!==void 0?g:A.expect})},y=({subjectId:h,subjectName:m})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(b.interactives,{subjectId:h,subjectName:m,type:N.actionExecution,actionType:"after-expect"})},C=({subjectId:h,subjectName:m,subjectType:p,action:g})=>{i.emit(b.interactives,{subjectId:h,subjectName:m,subjectType:p,type:N.actionExecution,actionType:g.type})},E=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{v.behaviour="change-chapter",i.emit(b.interactives,{subjectId:h,subjectName:m,subjectType:p,type:N.actionExecution,actionType:g.type,payload:v})},j=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{if(!v.URI)return;const I=window.open(v.URI,"_blank","noopener,noreferrer");I&&(I.opener=null),i.emit(b.interactives,{subjectId:h,subjectName:m,subjectType:p,type:N.actionExecution,actionType:g.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:r,state:s}};var he,Dt,Ve,gt;class q{constructor(e,t,n,s){this.target=e,this.type=t,this.listener=n,this.options=a(q,he,"m",Dt).call(q,e,s),this.target.addEventListener(t,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}he=q,Dt=function(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{const n=new Set(["passive","capture"]),s=Object.keys(t).filter(c=>!n.has(c));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),a(q,he,"m",gt).call(q,e)?t:t.capture||!1}},gt=function(e){let t=a(q,he,"f",Ve);if(t===void 0){t=!1;try{const n={},s={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);const r=()=>{};e.addEventListener("test",r,n),e.removeEventListener("test",r,n)}catch(n){t=!1}_(q,he,t,"f",Ve)}return t||!1};Ve={value:void 0};class vn{constructor(){this.bindingMap=new cn}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,s){if(!this.bindingMap)return;const r=new q(e,t,n,s);this.bindingMap.push(t,r)}listenOnce(e,t,n,s){const r=c=>{this.unlisten(e,t,r),n(c)};this.listen(e,t,r,s)}unlisten(e,t,n){if(!this.bindingMap)return;const s=this.bindingMap.get(t)||[];for(const r of s)r.target===e&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(t,r))}removeAll(){if(!this.bindingMap)return;const e=this.bindingMap.getAll();for(const t of e)t.unlisten();this.bindingMap.clear()}}class mn{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 t=(e=this.rootElement.getContext("2d"))===null||e===void 0?void 0:e.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;const n=t.data,s=n.length;for(let r=3;r<s;r+=40)if(n[r]!==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,t=!1){const n=e.width+e.height;if(this._prevSizeId===n)return;let s;t&&(s=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&s&&this.restore(s),this._prevSizeId=n}async save(){const e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}}class gn{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=s=>{const r=s!=null?s:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(r);if(this.isContainerTime(r))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;
|
package/es2018.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.6-dev.
|
|
3
|
-
* Tue, 12 Dec 2023
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.6-dev.9aa76b8.0
|
|
3
|
+
* Tue, 12 Dec 2023 10:50:05 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-6/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{loadVKLangPack as Ut,Subscription as Be,ValueSubject as zt,Observable as Qe,getCurrentBrowser as qt,CurrentClientBrowser as Qt,once as Xt}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{v4 as $e}from"uuid";import{Player as Zt}from"@vkontakte/videoplayer-core/es2018.esm.js";const Kt="1.0.6-dev.5a11a96.0";function Et(i,e=1){let t="0",n="0",s="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+s},${e})`}const W="SDK_NAME",Yt="SDK_NAME-controls-container",Ct=()=>document.querySelector(`.${Yt}`),U={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Xe={top:"flex-start",bottom:"flex-end",center:"center"},Ze={start:"flex-start",end:"flex-end",center:"center"},Ke={start:"left",end:"right",center:"center"},wt=({target:i,props:e})=>{var t,n,s,r,c,o;i.style.alignItems=(n=Xe[(t=e==null?void 0:e.text)===null||t===void 0?void 0:t.gravityVertical])!==null&&n!==void 0?n:Xe.center,i.style.justifyContent=(r=Ze[(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:Ze.center,i.style.textAlign=(o=Ke[(c=e==null?void 0:e.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:Ke.start},_t=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d;i.style.color=(r=(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:t.textColor,i.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:t.textSize})`,i.textContent=(d=(l=e==null?void 0:e.text)===null||l===void 0?void 0:l.value)!==null&&d!==void 0?d:t.textContent},It=({target:i,props:e,fallback:t})=>{var n,s,r,c;i.style.backgroundColor=Et((s=(n=e==null?void 0:e.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:t.backgroundColor,(c=(r=e==null?void 0:e.background)===null||r===void 0?void 0:r.alpha)!==null&&c!==void 0?c:t.backgroundAlpha)},St=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d,f,u,y,b,C;i.style.border=`calc(${n.height} * ${(c=(r=(s=e==null?void 0:e.shape)===null||s===void 0?void 0:s.border)===null||r===void 0?void 0:r.width)!==null&&c!==void 0?c:t.borderWidth}) solid ${Et((d=(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&&d!==void 0?d:t.borderColor,(y=(u=(f=e==null?void 0:e.shape)===null||f===void 0?void 0:f.border)===null||u===void 0?void 0:u.alpha)!==null&&y!==void 0?y:t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(C=(b=e==null?void 0:e.shape)===null||b===void 0?void 0:b.roundCorners)!==null&&C!==void 0?C:t.roundCorners})`},De=({target:i,layoutParams:e,fallback:t})=>{var n;i.style.transform=`rotate(${(n=-e.angle)!==null&&n!==void 0?n:t.angle}rad)`};class We{constructor(e){this.control=e}createView(e){var t;const n=document.createElement("div");n.classList.add(`${W}-control-container-${this.control.id}`),e(n,this.control.layoutParams);const s=((t=this.control.layoutParams.innerSizesDependOn)!==null&&t!==void 0?t:U.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:s}}setEvents(e,t){e&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",r=>{r.stopPropagation(),t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${W}-control-container-${this.control.id}`)}}const Tt=i=>{if(i.type.trim().toLowerCase()==="area")return new Jt(i)};class Jt extends We{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");return r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",It({target:r,props:this.control.props,fallback:{...U,backgroundColor:"transparent"}}),St({target:r,props:this.control.props,fallback:{...U,borderAlpha:0},dependsOn:n}),De({target:r,layoutParams:this.control.layoutParams,fallback:U}),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const Rt=i=>{if(i.type.trim().toLowerCase()==="button")return new ei(i)};class ei extends We{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");r.type="button",r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.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",De({target:r,layoutParams:this.control.layoutParams,fallback:U}),It({target:r,props:this.control.props,fallback:U}),St({target:r,props:this.control.props,fallback:U,dependsOn:n}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:U,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const ti=i=>{if(i.type.trim().toLowerCase()==="text")return new ii(i)};class ii extends We{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("div");r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",De({target:r,layoutParams:this.control.layoutParams,fallback:U}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:U,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}class ni{constructor(e){this.layout=e}}const si=i=>{if(i.type.trim().toLowerCase()==="relative")return new At(i)};class At extends ni{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function a(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)}function _(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t}var re,_e,Ye;class xt{constructor(e){re.add(this),this.container=e,this.factories=new Map,a(this,re,"m",_e).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),a(this,re,"m",_e).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),a(this,re,"m",_e).call(this)}}re=new WeakSet,_e=function(){this.controls=a(this,re,"m",Ye).call(this)},Ye=function(){var e;return(e=this.container.controls)===null||e===void 0?void 0:e.reduce((t,n)=>{const s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...t,r(n)]:[...t]},[])};const Ot=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new ri(i,e)};class ri extends xt{constructor(e,t){super(e),this.rootElement=t!=null?t:Ct(),this.layout=new At(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",Rt),this.addControlFactory("text",ti),this.addControlFactory("area",Tt)}createView(e){const t=document.createElement("div");return t.classList.add(`${W}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const s=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(s,e)}),this.rootElement.append(t),t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){var e;this.isRemoved||((e=this.getElement())===null||e===void 0||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${W}-${this.container.id}`)}}function Lt(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const me={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},de=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,He=i=>de(i,me.Object),je=i=>de(i,me.String),le=i=>de(i,me.Array),jt=i=>de(i,me.Number),ai=i=>de(i,me.Function),Je=i=>jt(i)&&!isNaN(i),oi=i=>i==null,pe=i=>He(i)&&Object.keys(i).length===0,Mt=i=>le(i)&&!i.length,be=(i,e)=>je(i)&&(e?i.trim():i).length,Nt=window.navigator.userAgent.toLowerCase(),li=/mobi/i.test(Nt);Nt.indexOf("android")>-1;const ci="video_interactive",di="videoint",hi=250;class ui{constructor(e){this.onResize=t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))},this.handleChapterChange=t=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.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(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(t,n=[])=>{var s;if(!jt(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)===null||s===void 0||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await Ut(this.lang,ci,di)}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:r}),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),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0},this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=t,this.onError=n,this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=fi(e),this.resizeObserver=new ResizeObserver(Lt(this.onResize,hi)),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,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)===null||e===void 0||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)===null||t===void 0||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function fi(i){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",i.append(e),e}const pi=(i={})=>{var e;return Array.from(new Set((e=i.sessions)===null||e===void 0?void 0:e.map(t=>{var n;return(n=t.visitedChapters.map(s=>s.chapterId))!==null&&n!==void 0?n:[]}).flat()))},et=(i=[],e="")=>i.reduce((t,n)=>(t.find(s=>s[e]===n[e])||t.push(n),t),[]),tt="chapterId";class ae{constructor(e){var t;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:$e(),this.startDate=e!=null&&e.startDate?new Date(e.startDate).toISOString():new Date(Date.now()).toISOString(),this.updateOn=e!=null&&e.updateOn?new Date(e.updateOn).toISOString():null,this.visitedChapters=e!=null&&e.visitedChapters?et(Array.from(e.visitedChapters),tt):[],this.branches=le(e==null?void 0:e.branches)?e.branches:[]}update(e){e!=null&&e.startDate&&(this.startDate=new Date(e.startDate).toISOString()),e!=null&&e.updateOn&&(this.updateOn=new Date(e.updateOn).toISOString()),le(e==null?void 0:e.visitedChapters)&&(this.visitedChapters=et([...this.visitedChapters,...e.visitedChapters],tt)),le(e==null?void 0:e.branches)&&(this.branches=this.branches.concat(e.branches))}getSession(){return{...this}}static createVisitedChapter(e){return[{chapterId:e}]}static createBranch(e,t,n){return[{chapterId:e,branchId:t,autoSelect:n}]}}class Ee{constructor(e){var t,n;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:$e(),this.manifestId=e==null?void 0:e.manifestId,this.manifestVersion=e==null?void 0:e.manifestVersion,this.manifestBuild=e==null?void 0:e.manifestBuild,this.sessions=le(e==null?void 0:e.sessions)?e==null?void 0:e.sessions.map(s=>new ae(s)):[],this.isCompleted=(n=e==null?void 0:e.isCompleted)!==null&&n!==void 0?n:!1}update(e){var t,n,s,r,c;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:this.id,this.manifestId=(n=e==null?void 0:e.manifestId)!==null&&n!==void 0?n:this.manifestId,this.manifestVersion=(s=e==null?void 0:e.manifestVersion)!==null&&s!==void 0?s:this.manifestVersion,this.manifestBuild=(r=e==null?void 0:e.manifestBuild)!==null&&r!==void 0?r:this.manifestBuild,this.isCompleted=(c=e==null?void 0:e.isCompleted)!==null&&c!==void 0?c:this.isCompleted}addSession(e){this.sessions.push(new ae(e))}updateSession(e,t){let n;oi(e)?n=this.sessions[this.sessions.length-1]:n=this.sessions.find(s=>s.id===e),n&&n.update(t)}resetSession(){this.sessions=[]}getHistory(){return{...this,sessions:this.sessions.map(e=>e.getSession())}}}const Me="SDK_NAME-history-changed";class vi extends EventTarget{constructor(){super(),this.history=new Ee,this.sendEvent()}onChapterChange({chapterId:e,mediaId:t,autoSelect:n=!1,isLastChapter:s=!1}){this.history.isCompleted?this.history=new Ee({manifestId:this.history.manifestId,manifestVersion:this.history.manifestVersion,manifestBuild:this.history.manifestBuild}):s&&this.history.update({isCompleted:!0}),this.history.sessions.length?this.history.updateSession(null,{updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,n)}):this.history.addSession({updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,!1)}),this.sendEvent()}onManifestChange(e,t){t?this.history=new Ee(t):this.history=new Ee({manifestId:e.id,manifestVersion:e.version,manifestBuild:e.build}),this.history.addSession({updateOn:Date.now()}),this.sendEvent()}getHistory(){if(history)return this.history.getHistory()}sendEvent(){this.dispatchEvent(new CustomEvent(Me,{bubbles:!1,detail:this.getHistory()}))}destroy(){this.history=void 0}}function mi(i,e){var t;if(!e||!i||!e.sessions.length)return;const n=e.sessions.reverse().find(s=>s.branches.length);return(t=n.branches[n.branches.length-1].chapterId)!==null&&t!==void 0?t:void 0}const Re=(i="",e="")=>{i=i.split("."),e=e.split(".");let t=0;for(let n=0;n<Math.max(i.length,e.length)&&!t;n++)i[n]>e[n]?t=1:i[n]<e[n]?t=-1:t=0;return t},gi="3.1",it={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},yi={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},bi=i=>{const e=[];for(const t of i.chapters){let n;const s=[];for(const{isDefault:o,...l}of t.branches)o&&(n=l.id),s.push(l);let r=[];const c=[];for(const{fallbackStrategy:o,...l}of t.containers){const d=!!l.endTime;let f=[yi];switch(o){case"await":d?f=[]:r=[];break;case"default":{const u={type:"onSuspense",action:{type:it.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?f=[u]:r=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:it[o],args:{}}};d?f=[u]:r=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:$e(),events:f})}e.push({...t,containers:c,events:r,branches:s})}return i.metadata.version=gi,i.metadata.updated=new Date().toISOString(),{...i,chapters:e}},Ei="3.2",Ci=i=>{if(!i.media){const{media:e,...t}=i.metadata;return{...i,metadata:{...t,version:Ei},media:e}}return i},wi="3.3",_i=(i=[])=>({edit:{chapters:i},view:{}}),nt={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ii=i=>{var e;const t=[],n=[];for(const s of i.chapters){const{id:r,x:c,y:o,...l}=s,d=l.containers.map(f=>{var u;return{...f,controls:f.controls.map(({subtype:y,type:b,...C})=>({...C,type:y!=null?y:b})),events:!((u=f.events)===null||u===void 0)&&u.length?f.events:[nt]}});t.push({id:r,...l,containers:d,events:!((e=l.events)===null||e===void 0)&&e.length?l.events:[nt]}),n.push({id:r,x:c,y:o})}return{...i,chapters:t,graph:_i(n),metadata:{...i.metadata,version:wi}}},Si=[{version:"3.0",migrate:bi},{version:"3.1",migrate:Ci},{version:"3.2",migrate:Ii}],Ti=i=>Si.reduce((e,t)=>Re(e.metadata.version,t.version)?e:t.migrate(e),i),Ri=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),A=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var ee;(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"})(ee||(ee={}));const st={metadata:"Object",chapters:"Array"},Ai="3.0.0",xi="3.3.0",kt=i=>{const e=Re(i,Ai);return e===-1?!1:e===0?!0:Re(i,xi)!==1},Oi=i=>{if(!He(i))return!1;for(const e in st)if(!i[e]||!de(i[e],st[e]))return!1;return kt(i.metadata.version)},Li=i=>i.type===Ri.Text;class j{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}j.Severity={RECOVERABLE:1,CRITICAL:2};j.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Vt{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];const n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){const n=this.listeners[e];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===t){n.splice(s,1);break}return this}emit(e,...t){const n=this.listeners[e];return n?(n.forEach(s=>{s(...t)}),!0):!1}listenerCount(e){return(this.listeners[e]||[]).length}rawListeners(e){return this.listeners[e]}}class ji{constructor(e){this.addFn=(t,n=!1)=>{ai(t)&&(this.fns.push(t),n&&this.updateFn())},this.removeFn=(t,n=!1)=>{this.fns=this.fns.filter(s=>s!==t),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Mi{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!==null&&t!==void 0?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(e,t){return Ni(...this.loaders[e])(t)}}function Ni(...i){return async function(t){const n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Ae(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function Ne({actions:i,errors:e,chapterId:t,...n}){if(t){const s=i.getManifest(),r=i.getChapter(s.chapters,t);if(r){const c=i.getMedia(s.media,r.videoId),o=i.getGraph(s.graph,r.id);return c?{...n,actions:i,errors:e,result:{chapter:r,media:c,graph:o}}:{...n,errors:Ae(e,Ne.name,"Could not find media"),actions:i}}}return{...n,errors:Ae(e,Ne.name,"Could not find chapter"),actions:i}}class rt{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;const n=this.listeners[e];for(let s=0,r=n.length;s<r;s++)if(n[s].callback===t){n.splice(s,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const n=this.listeners[e.type].slice();for(let s=0,r=n.length;s<r;s++){const c=n[s];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 Pt extends rt{constructor(){super(),this.listeners||rt.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 ki{constructor(){Object.defineProperty(this,"signal",{value:new Pt,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(s){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={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(s){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(ki.prototype[Symbol.toStringTag]="AbortController",Pt.prototype[Symbol.toStringTag]="AbortSignal");function Ft(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 Vi(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=i;if(!Ft({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:e,Request:r};let r=t;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(d,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const y=new t(d,f);return u&&Object.defineProperty(y,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),y},r.prototype=t.prototype);const c=e;return{fetch:(l,d)=>{const f=r&&r.prototype.isPrototypeOf(l)?l.signal:d?d.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch(b){u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const y=new Promise((b,C)=>{f.addEventListener("abort",()=>C(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([y,c(l,d)])}return c(l,d)},Request:r}}const Ge=Ft({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Bt=Ge?Vi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,at=Ge?Bt.fetch:window.fetch;Ge?Bt.Request:window.Request;const Pi=async i=>{try{let e,t;if(He(i))e=i;else if(je(i)){t=new URL(i).href;const s=await at(t);if(!s.ok)return{};e=await s.json()}else return{};if(!Oi(e))return{};const n=e.metadata.media;if(je(n)&&!e.media)try{let s;t?s=new URL(n,t).href:(s=new URL(n).href,t=s);const r=await at(s);if(!r.ok)throw new Error;e.metadata.media=await r.json()}catch(s){return Di(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Fi(i){const{manifest:e,manifestURL:t}=await Pi(i),n=Ti(e);return n.media=Bi(n.media,t),delete n.metadata.media,n}function Oe(i,e){return i.find(t=>t.id===e)}function ot(i,e){var t,n;return!((t=i.edit)===null||t===void 0)&&t.chapters?i.edit.chapters.find(s=>s.id===e):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(s=>s.id===e):void 0}function lt(i,e){return i.videos.find(t=>t.id===e)}function Bi(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{const s=$i(n.url,e);return{...n,url:s||n.url}})}))}}function $i(i,e){try{return new URL(i,e).href}catch(t){return""}}function Di(i){return Re(i,"3.2.0")>=0}class Wi extends Mi{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}async setManifest(e){var t;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ae},result:null,errors:null,source:e});n.errors&&this.errorHandler(n.errors);const s=await Fi((t=n.result)!==null&&t!==void 0?t:e);return this.manifest=s,this}async setInitial(){return this.setNext()}async setNext(e=this.manifest.metadata.initChapterId){const t=await this.exec("chapterLoaders",Ne({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ot,getChapter:Oe,getMedia:lt,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ae},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.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 t=Oe(this.manifest.chapters,e);if(t){const n=lt(this.manifest.media,t.videoId),s=ot(this.manifest.graph,t.id);if(n)return{chapter:t,media:n,graph:s}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{const t=Oe(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const s=this.getByChapterId(n.chapterId);return s&&t.push(s),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},ct={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Hi(){const i=new Map;function e({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...c}){const o=i.get(s),l={...c};return o?o[r]=l:i.set(s,{[r]:l}),{listId:s,itemId:r,...c}}function t(s,r){var c,o,l;const d=i.get(s);if(d){if(r)return(c=d[r])===null||c===void 0||c.player.destroy(),(o=d[r])===null||o===void 0||o.container.remove(),(l=d[r])===null||l===void 0||l.subscription.unsubscribe(),delete d[r],Object.keys(d).length||i.delete(s),!0;for(const f of Object.values(d))f.player.destroy(),f.container.remove();return i.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(const s of i)t(s[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:n}}function dt(i,e=[]){let t={},n;const s=!e.length;for(const r of i.variants)switch(!n&&"cover"in r&&(n=r.cover),r.type){case"mp4":(s||e.includes("mp4"))&&(t={...t,MPEG:{"Invariant quality":r.url}});break;case"hls":(s||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:r.url}});break;case"dash":(s||e.includes("dash"))&&(t={...t,DASH:{type:"url",url:r.url}});break}return{sources:t,thumbUrl:n,title:i.id}}const Ce=(i,e)=>{const t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))},Gi=i=>{const e=i.variants.find(t=>{var n;return((n=t.payload)===null||n===void 0?void 0:n.type)==="vk"});if(e&&"payload"in e){const[t,n]=e.payload.id.split("_");return[t,n]}return[]},Ie={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Ui=2;function zi(i){const e=Hi();let t,n;const s=new Vt;let r={},c=!1,o=null,l=!1,d;i&&f(i);function f(p){o=p}function u(p,g,v){var I;if(!o)throw Error("need to set interactive controller");const w=((I=e.map.get(p))!==null&&I!==void 0?I:{})[g];if(w){r={chapterId:v,listId:p,itemId:g,...w};const R=r.player;n=R.info.currentQuality$.subscribe(k=>{if(!(!k||!R.info.position$.getValue())){t=k;for(const P of e.map)Object.values(P[1]).forEach(({player:$})=>{R.info.isAutoQualityEnabled$.getValue()||Ce($,k)})}}),w.container.remove(),c=!1,o.setPlayer(w.player),l||(o.init(),l=!0),s.emit(Ie.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function y(p,g,v){if(!o)throw Error("need to set interactive controller");if(pe(r)||p!==r.itemId)return;if(v>=0&&!c){const S=o.getChapterBranches();c=!0;const w=new Set;for(const R of S)w.has(R.media.id)||(await C({media:R.media,chapterId:R.chapter.id,setAsActive:!1,title:R.chapter.label}),w.add(R.media.id))}}async function b({chapter:{id:p},media:g}){if(pe(r))return;n==null||n.unsubscribe();const v=r.player.info.muted$.getValue(),I=r.player.info.currentQuality$.getValue(),S=r.player.info.isAutoQualityEnabled$.getValue(),w=r.player.info.volume$.getValue(),R=r.player.info.currentPlaybackRate$.getValue(),k=!S;let P=!1;for(const $ of e.map)if($[0]===g.id){const ie=Object.keys($[1]);for(const Z of ie)Z===r.itemId?(ie.length<Ui||(P=!0),e.removePlayer($[0],Z)):(P=!0,u($[0],Z,p),k?Ce(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v),r.player.setPlaybackRate(R))}else e.removePlayer($[0]);P||(await C({media:g,chapterId:p,setAsActive:!0,playbackRate:R}),k?Ce(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v))}async function C({media:p,chapterId:g,prefetch:v=!0,setAsActive:I=!0,autoplay:S=!1,preferredExt:w,title:R,playbackRate:k}){var P,$,ie;const Z=Math.random().toString(),ne=document.createElement("div");d.append(ne);const Ht=(P=r==null?void 0:r.player)===null||P===void 0?void 0:P.info.isAutoQualityEnabled$.getValue();let ge;if(!(($=o==null?void 0:o.options)===null||$===void 0)&&$.vkVideoLoader){const ye=Gi(p);ye.length&&(ge=await o.options.vkVideoLoader(...ye))}const ze={container:ne,...((ie=ge==null?void 0:ge.videos)===null||ie===void 0?void 0:ie[0])||{sources:dt(p,w).sources},title:R},K=new Zt;K.initVideo(ze);const Gt=ne.lastChild,qe=new Be;qe.add(K.info.position$.subscribe(function(ye){y(Z,K.info.duration$.getValue(),ye)})).add(K.events.canplay$.subscribe(function(){Ht||Ce(K,t),k&&K.setPlaybackRate(k)})),Gt&&(ne.style.display="none",ne.classList.add(g));const se=e.createPlayer({listId:p.id,itemId:Z,player:K,container:ne,sources:dt(p,w).sources,config:ze,subscription:qe});return I&&u(p.id,se.itemId,g),S&&se.player.play(),v&&!S&&se.player.prepare(),s.emit(Ie.playerCreated,se.player),{player:se.player,config:se.config}}function M(){h(),o=null}function h(){o==null||o.off(E.chapterChanged,b),e.removeAll(),r={},l=!1,c=!1}async function m({source:p,initialChapter:g,container:v}){if(!o)throw Error("need to set interactive controller");await o.setManifest(p),h(),d=v;const{media:I,chapter:S}=await o.setChapter({chapterId:g});if(I){o.on(E.chapterChanged,b);const{player:w,config:R}=await C({media:I,chapterId:S.id,title:S.label});return s.emit(Ie.initiated,{container:v,media:I,chapterId:S.id}),{player:w,config:R}}else console.error("not found")}return{...e,on:s.on.bind(s),off:s.off.bind(s),init:m,setInteractiveController:f,createPlayer:C,removeAll:M,getActivePlayer:function(){return r}}}const qi=3e3,Qi=()=>{let i=[],e=null;return{setPlayer:c=>{e=c},setContainers:c=>{i=c},deleteContainer:c=>{i=i.filter(o=>o.id!==c)},getNextInteractiveTime:(c=qi)=>{if(!i.length||e===null)return null;let o=-1,l=!1;const d=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-c;if(u<=d&&(d<=f.endTime||f.endTime===null)){l=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},ce=Qi(),O=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ue=i=>le(i)&&!Mt(i),$t=i=>Mt(i.branches)||i.order==="end",Xi=(i,e)=>{var t;const n=i*1e3;return Ue(e.controls)&&n<((t=e.startTime)!==null&&t!==void 0?t:0)},ht=(i,e)=>{var t,n;const s=i*1e3;return Ue(e.controls)&&s>=((t=e.startTime)!==null&&t!==void 0?t:0)&&s<=((n=e.endTime)!==null&&n!==void 0?n:1/0)},xe=i=>i.some(e=>e.action.type==="expect"),ut=i=>i.find(e=>e.action.type==="expect"),Zi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i({...n[e],...t[e]}),Ki=(i=[])=>i.reduce((e,t,n)=>{var s,r,c;const o=((s=t==null?void 0:t.controls)!==null&&s!==void 0?s:[]).filter(l=>!Li(l));if(Ue(o)){const l=[(r=t.startTime)!==null&&r!==void 0?r:0,(c=t.endTime)!==null&&c!==void 0?c:1/0],d=t.id;if(!n)e.push({subjects:[d],range:l});else{const f=[];let u=-1/0,y=1/0,b=[];const C=[];for(let M=0;M<e.length;M++){const h=e[M];if(C.push(...h.subjects),h.range[0]<y&&(y=h.range[0]),h.range[1]>u&&(u=h.range[1]),h.range[0]<=l[0]&&h.range[1]>=l[1])return e[M].subjects.push(d),e;l[0]>=h.range[0]&&l[0]<=h.range[1]&&(f.push(M),b=b.concat(h.subjects),l[0]=h.range[0]),l[1]>=h.range[0]&&l[1]<=h.range[1]&&(f.push(M),b=b.concat(h.subjects),l[1]=h.range[1])}if(C.push(d),l[0]<=y&&l[1]>=u)return[{subjects:C,range:l}];f.length&&f.reverse().forEach(M=>{e.splice(M,1)}),e.push({subjects:b.concat([d]),range:l})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),Yi=(i,e)=>xe(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&xe(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class Ji{constructor({player:e,container:t,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:c,ignoreContainerEvent:o}){this.hide=()=>{setTimeout(()=>{var l,d;this.gameState!==O.end&&(xe(this.container.container.events)&&this.gameState===O.afterInteractive||this.selectBranches.state.isExpect||((d=(l=this.container).hide)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var l,d;if(this.gameState===O.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(d=(l=this.container).show)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const u=Zi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(y,b)=>{this.isSelectedControlEvent=!0,y!==!1&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===O.end||this.gameState===O.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),b(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),ce.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===O.end});this.container.createView(u),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0})}},this.onEndOfVideo=()=>{this.gameState=O.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var l,d,f,u;if(((l=this.player.experimental.element$.getValue())===null||l===void 0?void 0:l.readyState)<1||[O.destroyed,O.removed].includes(this.gameState))return;const b=this.player.info.position$.getValue();if(Xi(b,this.container.container))this.gameState!==O.beforeInteractive&&(this.gameState=O.beforeInteractive,this.onBeforeStartTime());else if(ht(b,this.container.container))this.gameState!==O.interactive&&(this.gameState=O.interactive,this.onStartTime());else if(this.gameState!==O.afterInteractive){const h=this.gameState;this.gameState=O.afterInteractive,h===O.interactive&&this.onEndTime()}else this.gameState!==O.destroyed&&this.removeView();const C=ht(b,this.container.container),M=this.container.container.startTime?[this.container.container.startTime,(d=this.container.container.endTime)!==null&&d!==void 0?d:1/0]:[];(u=(f=this.container).onProgress)===null||u===void 0||u.call(f,b,C),this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:M,currentTime:b,isInteractiveTime:C})},this.container=t,this.branches=n,this.selectBranches=s,this.subscription=new Be,this.player=e,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.globalEventEmitter=c,this.gameState=O.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))}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=xe(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)===null||t===void 0||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=O.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=O.removed}destroy(){var e;this.reset(),this.removeView(),this.gameState=O.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}),ce.deleteContainer(this.container.container.id)}}function en(){const i={};function e(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function t(o){const l={};for(const d in i)+d<=o&&(l[d]=i[d]);return l}function n(o){const l={};for(const d in i)+d>=o&&(l[d]=i[d]);return l}function s({timestamp:o,priority:l,initiator:d}){var f;if(Je(o)){const u=(f=i[o])!==null&&f!==void 0?f:null;if(u&&be(l,!0)){let y={};const b=u[l];if(b&&(y={...y,...b}),y=pe(y)?null:y,y&&be(d,!0)){const C=y[d];return C!=null?C:null}return y}return u}return null}function r({timestamp:o,priority:l,initiator:d}){if(Je(o))if(i[o]){if(be(l,!0))if(i[o][l]){if(be(d,!0))if(i[o][l][d]){if(delete i[o][l][d],!pe(i[o][l]))return!0}else return!1;if(delete i[o][l],!pe(i[o]))return!0}else return!1;return delete i[o]}else return!1}function c({timestamp:o,priority:l,initiator:d,...f}){var u,y,b;!((y=(u=i[o])===null||u===void 0?void 0:u[l])===null||y===void 0)&&y[d]?i[o][l][d].push({...f}):!((b=i[o])===null||b===void 0)&&b[l]?i[o][l]={...i[o][l],[d]:[{...f}]}:i[o]?i[o]={...i[o],[l]:{[d]:[{...f}]}}:i[o]={[l]:{[d]:[{...f}]}}}return{map:i,remove:r,add:c,removeAll:e,get:s,getLte:t,getGte:n}}const tn=[A.expect,A.setNextBranch],nn=1/0;function ft(i){let e=i,t;const n=sn(),s=new en;let r;const c=()=>{u(),M()},o=h=>{s.add.call(void 0,h),y()},l=(h=[])=>{for(const m of h)if(m.action(),tn.includes(m.actionType))break},d=h=>{var m,p,g;if(!n.isReady(h))return;const v=we((m=s.get({timestamp:h,priority:"control"}))!==null&&m!==void 0?m:{}),I=we((p=s.get({timestamp:h,priority:"container"}))!==null&&p!==void 0?p:{}),S=we((g=s.get({timestamp:h,priority:"chapter"}))!==null&&g!==void 0?g:{});l([...v,...I,...S])},f=()=>{var h;l([...we((h=s.get({timestamp:1/0,priority:"chapter"}))!==null&&h!==void 0?h:{})])},u=()=>{t&&(r==null||r.unsubscribe(),t=void 0)},y=()=>{t||(t=()=>setTimeout(()=>{d(1/0)}),r=e.events.ended$.subscribe(t))},b=h=>{u(),e=h},C=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},M=()=>{n.release(),s.removeAll()};return{setPlayer:b,add:o,remove:C,exec:d,execEndOfVideo:f,listen:y,unlisten:u,release:c,containersEventsCallState:n}}function sn(){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 d of c){const f=(o=d.endTime)!==null&&o!==void 0?o:nn,u=(l=i.get(f))!==null&&l!==void 0?l:{};i.set(f,{...u,[d.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 we(i){return Object.values(i).flat().sort(e=>e.actionType===A.expect?-1:1)}const rn=(i,e)=>{const{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:s,clientWidth:r}=e.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};const c=t/n,o=s/r;let l,d;return o>c?(d=r,l=r*c):o<c?(d=s/c,l=s):(d=r,l=s),{videoContentWidth:d,videoContentHeight:l}},an=250;function on(i){let e=()=>{};const t=new ResizeObserver(o=>{r(o),e=r.bind(null,o)});function n(o){const{parentElement:l,player:d}=i();if(l&&d){const{videoContentWidth:f,videoContentHeight:u}=rn(l,d);l.style.setProperty("--interactive-content-width",`${f}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 s(){const{parentElement:o}=i();o.removeAttribute("style")}const r=Lt(o=>{const{fns:l=[]}=i();n(o);for(const d of l)d()},an);function c(){e=void 0,t.disconnect(),s()}return{resizeObserver:t,calc:()=>{e()},release:c}}class ln{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){const t=this.map[e];return t?t.slice():null}getAll(){const e=[];for(const t in this.map)e.push(...this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),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 cn=i=>Math.floor(Math.random()*i),dn=i=>{let e=i.length,t=1/0,n=null;for(;e--;)i[e].weight<t&&(t=i[e].weight,n=i[e]);return n},hn=i=>{let e=i.length,t=-1/0,n=null;for(;e--;)i[e].weight>t&&(t=i[e].weight,n=i[e]);return n},un=i=>{const e=i.length,t=cn(e);return i[t]},pt=1,fn=i=>{var e,t;let n=0;for(let r=0;r<i.length;++r)n+=(e=i[r].weight)!==null&&e!==void 0?e:pt;const s=Math.random()*n;n=0;for(let r=0;r<i.length-1;++r)if(n+=(t=i[r].weight)!==null&&t!==void 0?t:pt,n>=s)return i[r];return i[i.length-1]},vt=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),Le=(i,e=!1)=>({...i,args:e?{...i.args,...vt}:{...vt,...i.args}}),mt=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},c=({action:h,controlType:m,controlId:p,containerId:g,branches:v=[],onEvent:I,isEOV:S=()=>!1})=>{const w=Le(h,S()),R={timestamp:1/0,priority:"control",initiator:p,actionType:w.type},k=i.emit.bind(i,E.interactives,{subjectId:p,subjectType:m,subjectName:"control",type:L.actionChoice,actionType:h.type,payload:{containerId:g,...w.args}});switch(w.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const P=v.find($=>$.id===w.args.branchId);if(!P)return;I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),k(),w.args.shouldOpenNow?C({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}}):(t.add({...R,action:C.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}})}),n==null||n());return}case A.continuePlayback.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),k(),w.args.shouldOpenNow?b({subjectId:p,subjectName:"control",subjectType:m,action:h}):t.add({...R,action:b.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:h})});return}case A.openURI.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),k(),w.args.shouldOpenNow?M({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}}):(t.add({...R,action:M.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(E.errors,new j(j.Severity.RECOVERABLE,j.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:h,container:{id:m,endTime:p},branches:g=[],isEOV:v=!1,autoSelected:I=!1})=>{const S=Le(h,v),w={timestamp:!S.args.shouldOpenNow||v?1/0:p,priority:"container",initiator:m,actionType:S.type},R=i.emit.bind(i,E.interactives,{subjectId:m,subjectName:"container",type:L.actionChoice,actionType:S.type,payload:S.args});switch(S.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const k=g.find(P=>P.id===S.args.branchId);if(!k)return;R(),t.add({...w,action:C.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{chapterId:k.chapterId,autoSelect:I}})}),n==null||n();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{R(),t.add({...w,action:b.bind(null,{subjectId:m,subjectName:"container",action:S})});return}case A.openURI.trim().toLowerCase():{R(),t.add({...w,action:M.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{URI:h.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(E.errors,new j(j.Severity.RECOVERABLE,j.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:h,branches:m,isEOV:p=!1}){const g=ut(h.events);if(g){const v=Le(g.action,p);i.emit(E.interactives,{subjectId:h.id,subjectName:"container",type:L.actionChoice,actionType:v.type,payload:v.args}),t.add({timestamp:p?1/0:h.endTime,priority:"container",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),s.isExpect=!0}else for(const v of h.events)o({action:v.action,container:h,branches:m,isEOV:p})}const d=({chapterId:h,action:m,branches:p=[]})=>{const g=i.emit.bind(i,E.interactives,{subjectId:h,subjectName:"chapter",type:L.actionChoice,actionType:m.type,payload:m.args});switch(m.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const v=p.find(I=>I.id===m.args.branchId);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{const v=un(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{const v=fn(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{const v=hn(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{const v=dn(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return g(),b.bind(null,{subjectId:h,subjectName:"chapter",action:m});case A.openURI.trim().toLowerCase():return g(),M.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{URI:m.args.uri}});default:console.error("Unexpected chapter event"),i.emit(E.errors,new j(j.Severity.RECOVERABLE,j.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){const m=ut(h.events);if(m){if($t(h))return;i.emit(E.interactives,{subjectId:h.id,subjectName:"chapter",type:L.actionChoice,actionType:m.action.type,payload:m.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events.forEach(p=>{const g=d({chapterId:h.id,action:p.action,branches:h.branches});g&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:p.action.type,action:g})})}const u=({subjectId:h,subjectName:m,action:p})=>{var g;e.pause(),i.emit(E.interactives,{subjectId:h,subjectName:m,type:L.actionExecution,actionType:(g=p==null?void 0:p.type)!==null&&g!==void 0?g:A.expect})},y=({subjectId:h,subjectName:m})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(E.interactives,{subjectId:h,subjectName:m,type:L.actionExecution,actionType:"after-expect"})},b=({subjectId:h,subjectName:m,subjectType:p,action:g})=>{i.emit(E.interactives,{subjectId:h,subjectName:m,subjectType:p,type:L.actionExecution,actionType:g.type})},C=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{v.behaviour="change-chapter",i.emit(E.interactives,{subjectId:h,subjectName:m,subjectType:p,type:L.actionExecution,actionType:g.type,payload:v})},M=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{if(!v.URI)return;const I=window.open(v.URI,"_blank","noopener,noreferrer");I&&(I.opener=null),i.emit(E.interactives,{subjectId:h,subjectName:m,subjectType:p,type:L.actionExecution,actionType:g.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:r,state:s}};var he,Dt,ke,gt;class z{constructor(e,t,n,s){this.target=e,this.type=t,this.listener=n,this.options=a(z,he,"m",Dt).call(z,e,s),this.target.addEventListener(t,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}he=z,Dt=function(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{const n=new Set(["passive","capture"]),s=Object.keys(t).filter(c=>!n.has(c));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),a(z,he,"m",gt).call(z,e)?t:t.capture||!1}},gt=function(e){let t=a(z,he,"f",ke);if(t===void 0){t=!1;try{const n={},s={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);const r=()=>{};e.addEventListener("test",r,n),e.removeEventListener("test",r,n)}catch(n){t=!1}_(z,he,t,"f",ke)}return t||!1};ke={value:void 0};class pn{constructor(){this.bindingMap=new ln}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,s){if(!this.bindingMap)return;const r=new z(e,t,n,s);this.bindingMap.push(t,r)}listenOnce(e,t,n,s){const r=c=>{this.unlisten(e,t,r),n(c)};this.listen(e,t,r,s)}unlisten(e,t,n){if(!this.bindingMap)return;const s=this.bindingMap.get(t)||[];for(const r of s)r.target===e&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(t,r))}removeAll(){if(!this.bindingMap)return;const e=this.bindingMap.getAll();for(const t of e)t.unlisten();this.bindingMap.clear()}}class vn{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 t=(e=this.rootElement.getContext("2d"))===null||e===void 0?void 0:e.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;const n=t.data,s=n.length;for(let r=3;r<s;r+=40)if(n[r]!==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,t=!1){const n=e.width+e.height;if(this._prevSizeId===n)return;let s;t&&(s=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&s&&this.restore(s),this._prevSizeId=n}async save(){const e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}}class mn{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=s=>{const r=s!=null?s:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(r);if(this.isContainerTime(r))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(c)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
import{loadVKLangPack as Ut,Subscription as Be,ValueSubject as zt,Observable as Qe,getCurrentBrowser as qt,CurrentClientBrowser as Qt,once as Xt}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{v4 as $e}from"uuid";import{Player as Zt}from"@vkontakte/videoplayer-core/es2018.esm.js";const Kt="1.0.6-dev.9aa76b8.0";function Et(i,e=1){let t="0",n="0",s="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+s},${e})`}const W="SDK_NAME",Yt="SDK_NAME-controls-container",Ct=()=>document.querySelector(`.${Yt}`),U={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Xe={top:"flex-start",bottom:"flex-end",center:"center"},Ze={start:"flex-start",end:"flex-end",center:"center"},Ke={start:"left",end:"right",center:"center"},wt=({target:i,props:e})=>{var t,n,s,r,c,o;i.style.alignItems=(n=Xe[(t=e==null?void 0:e.text)===null||t===void 0?void 0:t.gravityVertical])!==null&&n!==void 0?n:Xe.center,i.style.justifyContent=(r=Ze[(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:Ze.center,i.style.textAlign=(o=Ke[(c=e==null?void 0:e.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:Ke.start},_t=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d;i.style.color=(r=(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:t.textColor,i.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:t.textSize})`,i.textContent=(d=(l=e==null?void 0:e.text)===null||l===void 0?void 0:l.value)!==null&&d!==void 0?d:t.textContent},It=({target:i,props:e,fallback:t})=>{var n,s,r,c;i.style.backgroundColor=Et((s=(n=e==null?void 0:e.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:t.backgroundColor,(c=(r=e==null?void 0:e.background)===null||r===void 0?void 0:r.alpha)!==null&&c!==void 0?c:t.backgroundAlpha)},St=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,c,o,l,d,f,u,y,b,C;i.style.border=`calc(${n.height} * ${(c=(r=(s=e==null?void 0:e.shape)===null||s===void 0?void 0:s.border)===null||r===void 0?void 0:r.width)!==null&&c!==void 0?c:t.borderWidth}) solid ${Et((d=(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&&d!==void 0?d:t.borderColor,(y=(u=(f=e==null?void 0:e.shape)===null||f===void 0?void 0:f.border)===null||u===void 0?void 0:u.alpha)!==null&&y!==void 0?y:t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(C=(b=e==null?void 0:e.shape)===null||b===void 0?void 0:b.roundCorners)!==null&&C!==void 0?C:t.roundCorners})`},De=({target:i,layoutParams:e,fallback:t})=>{var n;i.style.transform=`rotate(${(n=-e.angle)!==null&&n!==void 0?n:t.angle}rad)`};class We{constructor(e){this.control=e}createView(e){var t;const n=document.createElement("div");n.classList.add(`${W}-control-container-${this.control.id}`),e(n,this.control.layoutParams);const s=((t=this.control.layoutParams.innerSizesDependOn)!==null&&t!==void 0?t:U.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:s}}setEvents(e,t){e&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",r=>{r.stopPropagation(),t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${W}-control-container-${this.control.id}`)}}const Tt=i=>{if(i.type.trim().toLowerCase()==="area")return new Jt(i)};class Jt extends We{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");return r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",It({target:r,props:this.control.props,fallback:{...U,backgroundColor:"transparent"}}),St({target:r,props:this.control.props,fallback:{...U,borderAlpha:0},dependsOn:n}),De({target:r,layoutParams:this.control.layoutParams,fallback:U}),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const Rt=i=>{if(i.type.trim().toLowerCase()==="button")return new ei(i)};class ei extends We{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");r.type="button",r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.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",De({target:r,layoutParams:this.control.layoutParams,fallback:U}),It({target:r,props:this.control.props,fallback:U}),St({target:r,props:this.control.props,fallback:U,dependsOn:n}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:U,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const ti=i=>{if(i.type.trim().toLowerCase()==="text")return new ii(i)};class ii extends We{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("div");r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",De({target:r,layoutParams:this.control.layoutParams,fallback:U}),wt({target:r,props:this.control.props}),_t({target:c,props:this.control.props,fallback:U,dependsOn:n}),r.append(c),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}class ni{constructor(e){this.layout=e}}const si=i=>{if(i.type.trim().toLowerCase()==="relative")return new At(i)};class At extends ni{constructor(e){super(e)}setContainerLayout(e){e.style.position="relative"}setControlLayout(e,t){e.style.position="absolute",e.style.width=`calc(var(--interactive-content-width) * ${t.width})`,e.style.height=`calc(var(--interactive-content-height) * ${t.height})`,e.style.left=`calc(var(--interactive-content-width) * ${t.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,e.style.top=`calc(var(--interactive-content-height) * ${t.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function a(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)}function _(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t}var re,_e,Ye;class xt{constructor(e){re.add(this),this.container=e,this.factories=new Map,a(this,re,"m",_e).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),a(this,re,"m",_e).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),a(this,re,"m",_e).call(this)}}re=new WeakSet,_e=function(){this.controls=a(this,re,"m",Ye).call(this)},Ye=function(){var e;return(e=this.container.controls)===null||e===void 0?void 0:e.reduce((t,n)=>{const s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...t,r(n)]:[...t]},[])};const Ot=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new ri(i,e)};class ri extends xt{constructor(e,t){super(e),this.rootElement=t!=null?t:Ct(),this.layout=new At(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",Rt),this.addControlFactory("text",ti),this.addControlFactory("area",Tt)}createView(e){const t=document.createElement("div");return t.classList.add(`${W}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const s=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(s,e)}),this.rootElement.append(t),t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){var e;this.isRemoved||((e=this.getElement())===null||e===void 0||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${W}-${this.container.id}`)}}function Lt(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const me={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},de=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,He=i=>de(i,me.Object),je=i=>de(i,me.String),le=i=>de(i,me.Array),jt=i=>de(i,me.Number),ai=i=>de(i,me.Function),Je=i=>jt(i)&&!isNaN(i),oi=i=>i==null,pe=i=>He(i)&&Object.keys(i).length===0,Mt=i=>le(i)&&!i.length,be=(i,e)=>je(i)&&(e?i.trim():i).length,Nt=window.navigator.userAgent.toLowerCase(),li=/mobi/i.test(Nt);Nt.indexOf("android")>-1;const ci="video_interactive",di="videoint",hi=250;class ui{constructor(e){this.onResize=t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))},this.handleChapterChange=t=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.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(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(t,n=[])=>{var s;if(!jt(t.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)===null||s===void 0||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await Ut(this.lang,ci,di)}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:r}),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),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0},this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=t,this.onError=n,this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=fi(e),this.resizeObserver=new ResizeObserver(Lt(this.onResize,hi)),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,t;this.hide(),this.resizeObserver.disconnect(),(e=this.ngEditor)===null||e===void 0||e.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(t=this.ngEditor)===null||t===void 0||t.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function fi(i){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",i.append(e),e}const pi=(i={})=>{var e;return Array.from(new Set((e=i.sessions)===null||e===void 0?void 0:e.map(t=>{var n;return(n=t.visitedChapters.map(s=>s.chapterId))!==null&&n!==void 0?n:[]}).flat()))},et=(i=[],e="")=>i.reduce((t,n)=>(t.find(s=>s[e]===n[e])||t.push(n),t),[]),tt="chapterId";class ae{constructor(e){var t;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:$e(),this.startDate=e!=null&&e.startDate?new Date(e.startDate).toISOString():new Date(Date.now()).toISOString(),this.updateOn=e!=null&&e.updateOn?new Date(e.updateOn).toISOString():null,this.visitedChapters=e!=null&&e.visitedChapters?et(Array.from(e.visitedChapters),tt):[],this.branches=le(e==null?void 0:e.branches)?e.branches:[]}update(e){e!=null&&e.startDate&&(this.startDate=new Date(e.startDate).toISOString()),e!=null&&e.updateOn&&(this.updateOn=new Date(e.updateOn).toISOString()),le(e==null?void 0:e.visitedChapters)&&(this.visitedChapters=et([...this.visitedChapters,...e.visitedChapters],tt)),le(e==null?void 0:e.branches)&&(this.branches=this.branches.concat(e.branches))}getSession(){return{...this}}static createVisitedChapter(e){return[{chapterId:e}]}static createBranch(e,t,n){return[{chapterId:e,branchId:t,autoSelect:n}]}}class Ee{constructor(e){var t,n;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:$e(),this.manifestId=e==null?void 0:e.manifestId,this.manifestVersion=e==null?void 0:e.manifestVersion,this.manifestBuild=e==null?void 0:e.manifestBuild,this.sessions=le(e==null?void 0:e.sessions)?e==null?void 0:e.sessions.map(s=>new ae(s)):[],this.isCompleted=(n=e==null?void 0:e.isCompleted)!==null&&n!==void 0?n:!1}update(e){var t,n,s,r,c;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:this.id,this.manifestId=(n=e==null?void 0:e.manifestId)!==null&&n!==void 0?n:this.manifestId,this.manifestVersion=(s=e==null?void 0:e.manifestVersion)!==null&&s!==void 0?s:this.manifestVersion,this.manifestBuild=(r=e==null?void 0:e.manifestBuild)!==null&&r!==void 0?r:this.manifestBuild,this.isCompleted=(c=e==null?void 0:e.isCompleted)!==null&&c!==void 0?c:this.isCompleted}addSession(e){this.sessions.push(new ae(e))}updateSession(e,t){let n;oi(e)?n=this.sessions[this.sessions.length-1]:n=this.sessions.find(s=>s.id===e),n&&n.update(t)}resetSession(){this.sessions=[]}getHistory(){return{...this,sessions:this.sessions.map(e=>e.getSession())}}}const Me="SDK_NAME-history-changed";class vi extends EventTarget{constructor(){super(),this.history=new Ee,this.sendEvent()}onChapterChange({chapterId:e,mediaId:t,autoSelect:n=!1,isLastChapter:s=!1}){this.history.isCompleted?this.history=new Ee({manifestId:this.history.manifestId,manifestVersion:this.history.manifestVersion,manifestBuild:this.history.manifestBuild}):s&&this.history.update({isCompleted:!0}),this.history.sessions.length?this.history.updateSession(null,{updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,n)}):this.history.addSession({updateOn:Date.now(),visitedChapters:ae.createVisitedChapter(e),branches:ae.createBranch(e,t,!1)}),this.sendEvent()}onManifestChange(e,t){t?this.history=new Ee(t):this.history=new Ee({manifestId:e.id,manifestVersion:e.version,manifestBuild:e.build}),this.history.addSession({updateOn:Date.now()}),this.sendEvent()}getHistory(){if(history)return this.history.getHistory()}sendEvent(){this.dispatchEvent(new CustomEvent(Me,{bubbles:!1,detail:this.getHistory()}))}destroy(){this.history=void 0}}function mi(i,e){var t;if(!e||!i||!e.sessions.length)return;const n=e.sessions.reverse().find(s=>s.branches.length);return(t=n.branches[n.branches.length-1].chapterId)!==null&&t!==void 0?t:void 0}const Re=(i="",e="")=>{i=i.split("."),e=e.split(".");let t=0;for(let n=0;n<Math.max(i.length,e.length)&&!t;n++)i[n]>e[n]?t=1:i[n]<e[n]?t=-1:t=0;return t},gi="3.1",it={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},yi={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},bi=i=>{const e=[];for(const t of i.chapters){let n;const s=[];for(const{isDefault:o,...l}of t.branches)o&&(n=l.id),s.push(l);let r=[];const c=[];for(const{fallbackStrategy:o,...l}of t.containers){const d=!!l.endTime;let f=[yi];switch(o){case"await":d?f=[]:r=[];break;case"default":{const u={type:"onSuspense",action:{type:it.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?f=[u]:r=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:it[o],args:{}}};d?f=[u]:r=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:$e(),events:f})}e.push({...t,containers:c,events:r,branches:s})}return i.metadata.version=gi,i.metadata.updated=new Date().toISOString(),{...i,chapters:e}},Ei="3.2",Ci=i=>{if(!i.media){const{media:e,...t}=i.metadata;return{...i,metadata:{...t,version:Ei},media:e}}return i},wi="3.3",_i=(i=[])=>({edit:{chapters:i},view:{}}),nt={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ii=i=>{var e;const t=[],n=[];for(const s of i.chapters){const{id:r,x:c,y:o,...l}=s,d=l.containers.map(f=>{var u;return{...f,controls:f.controls.map(({subtype:y,type:b,...C})=>({...C,type:y!=null?y:b})),events:!((u=f.events)===null||u===void 0)&&u.length?f.events:[nt]}});t.push({id:r,...l,containers:d,events:!((e=l.events)===null||e===void 0)&&e.length?l.events:[nt]}),n.push({id:r,x:c,y:o})}return{...i,chapters:t,graph:_i(n),metadata:{...i.metadata,version:wi}}},Si=[{version:"3.0",migrate:bi},{version:"3.1",migrate:Ci},{version:"3.2",migrate:Ii}],Ti=i=>Si.reduce((e,t)=>Re(e.metadata.version,t.version)?e:t.migrate(e),i),Ri=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),A=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var ee;(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"})(ee||(ee={}));const st={metadata:"Object",chapters:"Array"},Ai="3.0.0",xi="3.3.0",kt=i=>{const e=Re(i,Ai);return e===-1?!1:e===0?!0:Re(i,xi)!==1},Oi=i=>{if(!He(i))return!1;for(const e in st)if(!i[e]||!de(i[e],st[e]))return!1;return kt(i.metadata.version)},Li=i=>i.type===Ri.Text;class j{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}j.Severity={RECOVERABLE:1,CRITICAL:2};j.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Vt{constructor(){this.listeners={}}addListener(e,t){return this.listeners[e]=this.listeners[e]||[],this.listeners[e].push(t),this}on(e,t){return this.addListener(e,t)}once(e,t){this.listeners[e]=this.listeners[e]||[];const n=()=>{t(),this.off(e,n)};return this.listeners[e].push(n),this}off(e,t){return this.removeListener(e,t)}reset(){this.listeners={}}removeListener(e,t){const n=this.listeners[e];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===t){n.splice(s,1);break}return this}emit(e,...t){const n=this.listeners[e];return n?(n.forEach(s=>{s(...t)}),!0):!1}listenerCount(e){return(this.listeners[e]||[]).length}rawListeners(e){return this.listeners[e]}}class ji{constructor(e){this.addFn=(t,n=!1)=>{ai(t)&&(this.fns.push(t),n&&this.updateFn())},this.removeFn=(t,n=!1)=>{this.fns=this.fns.filter(s=>s!==t),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Mi{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!==null&&t!==void 0?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(e,t){return Ni(...this.loaders[e])(t)}}function Ni(...i){return async function(t){const n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Ae(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function Ne({actions:i,errors:e,chapterId:t,...n}){if(t){const s=i.getManifest(),r=i.getChapter(s.chapters,t);if(r){const c=i.getMedia(s.media,r.videoId),o=i.getGraph(s.graph,r.id);return c?{...n,actions:i,errors:e,result:{chapter:r,media:c,graph:o}}:{...n,errors:Ae(e,Ne.name,"Could not find media"),actions:i}}}return{...n,errors:Ae(e,Ne.name,"Could not find chapter"),actions:i}}class rt{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,n){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:n})}removeEventListener(e,t){if(!(e in this.listeners))return;const n=this.listeners[e];for(let s=0,r=n.length;s<r;s++)if(n[s].callback===t){n.splice(s,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const n=this.listeners[e.type].slice();for(let s=0,r=n.length;s<r;s++){const c=n[s];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 Pt extends rt{constructor(){super(),this.listeners||rt.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 ki{constructor(){Object.defineProperty(this,"signal",{value:new Pt,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch(s){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={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(s){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(ki.prototype[Symbol.toStringTag]="AbortController",Pt.prototype[Symbol.toStringTag]="AbortSignal");function Ft(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 Vi(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=i;if(!Ft({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:e,Request:r};let r=t;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(d,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const y=new t(d,f);return u&&Object.defineProperty(y,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),y},r.prototype=t.prototype);const c=e;return{fetch:(l,d)=>{const f=r&&r.prototype.isPrototypeOf(l)?l.signal:d?d.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch(b){u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const y=new Promise((b,C)=>{f.addEventListener("abort",()=>C(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([y,c(l,d)])}return c(l,d)},Request:r}}const Ge=Ft({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Bt=Ge?Vi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,at=Ge?Bt.fetch:window.fetch;Ge?Bt.Request:window.Request;const Pi=async i=>{try{let e,t;if(He(i))e=i;else if(je(i)){t=new URL(i).href;const s=await at(t);if(!s.ok)return{};e=await s.json()}else return{};if(!Oi(e))return{};const n=e.metadata.media;if(je(n)&&!e.media)try{let s;t?s=new URL(n,t).href:(s=new URL(n).href,t=s);const r=await at(s);if(!r.ok)throw new Error;e.metadata.media=await r.json()}catch(s){return Di(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}};async function Fi(i){const{manifest:e,manifestURL:t}=await Pi(i),n=Ti(e);return n.media=Bi(n.media,t),delete n.metadata.media,n}function Oe(i,e){return i.find(t=>t.id===e)}function ot(i,e){var t,n;return!((t=i.edit)===null||t===void 0)&&t.chapters?i.edit.chapters.find(s=>s.id===e):!((n=i.view)===null||n===void 0)&&n.chapters?i.view.chapters.find(s=>s.id===e):void 0}function lt(i,e){return i.videos.find(t=>t.id===e)}function Bi(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{const s=$i(n.url,e);return{...n,url:s||n.url}})}))}}function $i(i,e){try{return new URL(i,e).href}catch(t){return""}}function Di(i){return Re(i,"3.2.0")>=0}class Wi extends Mi{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}async setManifest(e){var t;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ae},result:null,errors:null,source:e});n.errors&&this.errorHandler(n.errors);const s=await Fi((t=n.result)!==null&&t!==void 0?t:e);return this.manifest=s,this}async setInitial(){return this.setNext()}async setNext(e=this.manifest.metadata.initChapterId){const t=await this.exec("chapterLoaders",Ne({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ot,getChapter:Oe,getMedia:lt,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ae},result:null,errors:null,chapterId:e}));return t.errors&&this.errorHandler(t.errors),this.chapter=t.result.chapter,this.media=t.result.media,this.graph=t.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 t=Oe(this.manifest.chapters,e);if(t){const n=lt(this.manifest.media,t.videoId),s=ot(this.manifest.graph,t.id);if(n)return{chapter:t,media:n,graph:s}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{const t=Oe(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const s=this.getByChapterId(n.chapterId);return s&&t.push(s),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},ct={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Hi(){const i=new Map;function e({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...c}){const o=i.get(s),l={...c};return o?o[r]=l:i.set(s,{[r]:l}),{listId:s,itemId:r,...c}}function t(s,r){var c,o,l;const d=i.get(s);if(d){if(r)return(c=d[r])===null||c===void 0||c.player.destroy(),(o=d[r])===null||o===void 0||o.container.remove(),(l=d[r])===null||l===void 0||l.subscription.unsubscribe(),delete d[r],Object.keys(d).length||i.delete(s),!0;for(const f of Object.values(d))f.player.destroy(),f.container.remove();return i.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(const s of i)t(s[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:n}}function dt(i,e=[]){let t={},n;const s=!e.length;for(const r of i.variants)switch(!n&&"cover"in r&&(n=r.cover),r.type){case"mp4":(s||e.includes("mp4"))&&(t={...t,MPEG:{"Invariant quality":r.url}});break;case"hls":(s||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:r.url}});break;case"dash":(s||e.includes("dash"))&&(t={...t,DASH:{type:"url",url:r.url}});break}return{sources:t,thumbUrl:n,title:i.id}}const Ce=(i,e)=>{const t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))},Gi=i=>{const e=i.variants.find(t=>{var n;return((n=t.payload)===null||n===void 0?void 0:n.type)==="vk"});if(e&&"payload"in e){const[t,n]=e.payload.id.split("_");return[t,n]}return[]},Ie={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Ui=2;function zi(i){const e=Hi();let t,n;const s=new Vt;let r={},c=!1,o=null,l=!1,d;i&&f(i);function f(p){o=p}function u(p,g,v){var I;if(!o)throw Error("need to set interactive controller");const w=((I=e.map.get(p))!==null&&I!==void 0?I:{})[g];if(w){r={chapterId:v,listId:p,itemId:g,...w};const R=r.player;n=R.info.currentQuality$.subscribe(k=>{if(!(!k||!R.info.position$.getValue())){t=k;for(const P of e.map)Object.values(P[1]).forEach(({player:$})=>{R.info.isAutoQualityEnabled$.getValue()||Ce($,k)})}}),w.container.remove(),c=!1,o.setPlayer(w.player),l||(o.init(),l=!0),s.emit(Ie.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function y(p,g,v){if(!o)throw Error("need to set interactive controller");if(pe(r)||p!==r.itemId)return;if(v>=0&&!c){const S=o.getChapterBranches();c=!0;const w=new Set;for(const R of S)w.has(R.media.id)||(await C({media:R.media,chapterId:R.chapter.id,setAsActive:!1,title:R.chapter.label}),w.add(R.media.id))}}async function b({chapter:{id:p},media:g}){if(pe(r))return;n==null||n.unsubscribe();const v=r.player.info.muted$.getValue(),I=r.player.info.currentQuality$.getValue(),S=r.player.info.isAutoQualityEnabled$.getValue(),w=r.player.info.volume$.getValue(),R=r.player.info.currentPlaybackRate$.getValue(),k=!S;let P=!1;for(const $ of e.map)if($[0]===g.id){const ie=Object.keys($[1]);for(const Z of ie)Z===r.itemId?(ie.length<Ui||(P=!0),e.removePlayer($[0],Z)):(P=!0,u($[0],Z,p),k?Ce(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v),r.player.setPlaybackRate(R))}else e.removePlayer($[0]);P||(await C({media:g,chapterId:p,setAsActive:!0,playbackRate:R}),k?Ce(r.player,I):r.player.setAutoQuality(!0),r.player.setVolume(w),r.player.setMuted(v))}async function C({media:p,chapterId:g,prefetch:v=!0,setAsActive:I=!0,autoplay:S=!1,preferredExt:w,title:R,playbackRate:k}){var P,$,ie;const Z=Math.random().toString(),ne=document.createElement("div");d.append(ne);const Ht=(P=r==null?void 0:r.player)===null||P===void 0?void 0:P.info.isAutoQualityEnabled$.getValue();let ge;if(!(($=o==null?void 0:o.options)===null||$===void 0)&&$.vkVideoLoader){const ye=Gi(p);ye.length&&(ge=await o.options.vkVideoLoader(...ye))}const ze={container:ne,...((ie=ge==null?void 0:ge.videos)===null||ie===void 0?void 0:ie[0])||{sources:dt(p,w).sources},title:R},K=new Zt;K.initVideo(ze);const Gt=ne.lastChild,qe=new Be;qe.add(K.info.position$.subscribe(function(ye){y(Z,K.info.duration$.getValue(),ye)})).add(K.events.canplay$.subscribe(function(){Ht||Ce(K,t),k&&K.setPlaybackRate(k)})),Gt&&(ne.style.display="none",ne.classList.add(g));const se=e.createPlayer({listId:p.id,itemId:Z,player:K,container:ne,sources:dt(p,w).sources,config:ze,subscription:qe});return I&&u(p.id,se.itemId,g),S&&se.player.play(),v&&!S&&se.player.prepare(),s.emit(Ie.playerCreated,se.player),{player:se.player,config:se.config}}function M(){h(),o=null}function h(){o==null||o.off(E.chapterChanged,b),e.removeAll(),r={},l=!1,c=!1}async function m({source:p,initialChapter:g,container:v}){if(!o)throw Error("need to set interactive controller");await o.setManifest(p),h(),d=v;const{media:I,chapter:S}=await o.setChapter({chapterId:g});if(I){o.on(E.chapterChanged,b);const{player:w,config:R}=await C({media:I,chapterId:S.id,title:S.label});return s.emit(Ie.initiated,{container:v,media:I,chapterId:S.id}),{player:w,config:R}}else console.error("not found")}return{...e,on:s.on.bind(s),off:s.off.bind(s),init:m,setInteractiveController:f,createPlayer:C,removeAll:M,getActivePlayer:function(){return r}}}const qi=3e3,Qi=()=>{let i=[],e=null;return{setPlayer:c=>{e=c},setContainers:c=>{i=c},deleteContainer:c=>{i=i.filter(o=>o.id!==c)},getNextInteractiveTime:(c=qi)=>{if(!i.length||e===null)return null;let o=-1,l=!1;const d=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-c;if(u<=d&&(d<=f.endTime||f.endTime===null)){l=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},ce=Qi(),O=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ue=i=>le(i)&&!Mt(i),$t=i=>Mt(i.branches)||i.order==="end",Xi=(i,e)=>{var t;const n=i*1e3;return Ue(e.controls)&&n<((t=e.startTime)!==null&&t!==void 0?t:0)},ht=(i,e)=>{var t,n;const s=i*1e3;return Ue(e.controls)&&s>=((t=e.startTime)!==null&&t!==void 0?t:0)&&s<=((n=e.endTime)!==null&&n!==void 0?n:1/0)},xe=i=>i.some(e=>e.action.type==="expect"),ut=i=>i.find(e=>e.action.type==="expect"),Zi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i({...n[e],...t[e]}),Ki=(i=[])=>i.reduce((e,t,n)=>{var s,r,c;const o=((s=t==null?void 0:t.controls)!==null&&s!==void 0?s:[]).filter(l=>!Li(l));if(Ue(o)){const l=[(r=t.startTime)!==null&&r!==void 0?r:0,(c=t.endTime)!==null&&c!==void 0?c:1/0],d=t.id;if(!n)e.push({subjects:[d],range:l});else{const f=[];let u=-1/0,y=1/0,b=[];const C=[];for(let M=0;M<e.length;M++){const h=e[M];if(C.push(...h.subjects),h.range[0]<y&&(y=h.range[0]),h.range[1]>u&&(u=h.range[1]),h.range[0]<=l[0]&&h.range[1]>=l[1])return e[M].subjects.push(d),e;l[0]>=h.range[0]&&l[0]<=h.range[1]&&(f.push(M),b=b.concat(h.subjects),l[0]=h.range[0]),l[1]>=h.range[0]&&l[1]<=h.range[1]&&(f.push(M),b=b.concat(h.subjects),l[1]=h.range[1])}if(C.push(d),l[0]<=y&&l[1]>=u)return[{subjects:C,range:l}];f.length&&f.reverse().forEach(M=>{e.splice(M,1)}),e.push({subjects:b.concat([d]),range:l})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),Yi=(i,e)=>xe(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&xe(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class Ji{constructor({player:e,container:t,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:c,ignoreContainerEvent:o}){this.hide=()=>{setTimeout(()=>{var l,d;this.gameState!==O.end&&(xe(this.container.container.events)&&this.gameState===O.afterInteractive||this.selectBranches.state.isExpect||((d=(l=this.container).hide)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var l,d;if(this.gameState===O.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(d=(l=this.container).show)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const u=Zi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(y,b)=>{this.isSelectedControlEvent=!0,y!==!1&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===O.end||this.gameState===O.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),b(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),ce.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===O.end});this.container.createView(u),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0})}},this.onEndOfVideo=()=>{this.gameState=O.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var l,d,f,u;if(((l=this.player.experimental.element$.getValue())===null||l===void 0?void 0:l.readyState)<1||[O.destroyed,O.removed].includes(this.gameState))return;const b=this.player.info.position$.getValue();if(Xi(b,this.container.container))this.gameState!==O.beforeInteractive&&(this.gameState=O.beforeInteractive,this.onBeforeStartTime());else if(ht(b,this.container.container))this.gameState!==O.interactive&&(this.gameState=O.interactive,this.onStartTime());else if(this.gameState!==O.afterInteractive){const h=this.gameState;this.gameState=O.afterInteractive,h===O.interactive&&this.onEndTime()}else this.gameState!==O.destroyed&&this.removeView();const C=ht(b,this.container.container),M=this.container.container.startTime?[this.container.container.startTime,(d=this.container.container.endTime)!==null&&d!==void 0?d:1/0]:[];(u=(f=this.container).onProgress)===null||u===void 0||u.call(f,b,C),this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:M,currentTime:b,isInteractiveTime:C})},this.container=t,this.branches=n,this.selectBranches=s,this.subscription=new Be,this.player=e,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.globalEventEmitter=c,this.gameState=O.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))}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=xe(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)===null||t===void 0||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=O.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=O.removed}destroy(){var e;this.reset(),this.removeView(),this.gameState=O.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}),ce.deleteContainer(this.container.container.id)}}function en(){const i={};function e(){for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function t(o){const l={};for(const d in i)+d<=o&&(l[d]=i[d]);return l}function n(o){const l={};for(const d in i)+d>=o&&(l[d]=i[d]);return l}function s({timestamp:o,priority:l,initiator:d}){var f;if(Je(o)){const u=(f=i[o])!==null&&f!==void 0?f:null;if(u&&be(l,!0)){let y={};const b=u[l];if(b&&(y={...y,...b}),y=pe(y)?null:y,y&&be(d,!0)){const C=y[d];return C!=null?C:null}return y}return u}return null}function r({timestamp:o,priority:l,initiator:d}){if(Je(o))if(i[o]){if(be(l,!0))if(i[o][l]){if(be(d,!0))if(i[o][l][d]){if(delete i[o][l][d],!pe(i[o][l]))return!0}else return!1;if(delete i[o][l],!pe(i[o]))return!0}else return!1;return delete i[o]}else return!1}function c({timestamp:o,priority:l,initiator:d,...f}){var u,y,b;!((y=(u=i[o])===null||u===void 0?void 0:u[l])===null||y===void 0)&&y[d]?i[o][l][d].push({...f}):!((b=i[o])===null||b===void 0)&&b[l]?i[o][l]={...i[o][l],[d]:[{...f}]}:i[o]?i[o]={...i[o],[l]:{[d]:[{...f}]}}:i[o]={[l]:{[d]:[{...f}]}}}return{map:i,remove:r,add:c,removeAll:e,get:s,getLte:t,getGte:n}}const tn=[A.expect,A.setNextBranch],nn=1/0;function ft(i){let e=i,t;const n=sn(),s=new en;let r;const c=()=>{u(),M()},o=h=>{s.add.call(void 0,h),y()},l=(h=[])=>{for(const m of h)if(m.action(),tn.includes(m.actionType))break},d=h=>{var m,p,g;if(!n.isReady(h))return;const v=we((m=s.get({timestamp:h,priority:"control"}))!==null&&m!==void 0?m:{}),I=we((p=s.get({timestamp:h,priority:"container"}))!==null&&p!==void 0?p:{}),S=we((g=s.get({timestamp:h,priority:"chapter"}))!==null&&g!==void 0?g:{});l([...v,...I,...S])},f=()=>{var h;l([...we((h=s.get({timestamp:1/0,priority:"chapter"}))!==null&&h!==void 0?h:{})])},u=()=>{t&&(r==null||r.unsubscribe(),t=void 0)},y=()=>{t||(t=()=>setTimeout(()=>{d(1/0)}),r=e.events.ended$.subscribe(t))},b=h=>{u(),e=h},C=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},M=()=>{n.release(),s.removeAll()};return{setPlayer:b,add:o,remove:C,exec:d,execEndOfVideo:f,listen:y,unlisten:u,release:c,containersEventsCallState:n}}function sn(){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 d of c){const f=(o=d.endTime)!==null&&o!==void 0?o:nn,u=(l=i.get(f))!==null&&l!==void 0?l:{};i.set(f,{...u,[d.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 we(i){return Object.values(i).flat().sort(e=>e.actionType===A.expect?-1:1)}const rn=(i,e)=>{const{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:s,clientWidth:r}=e.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};const c=t/n,o=s/r;let l,d;return o>c?(d=r,l=r*c):o<c?(d=s/c,l=s):(d=r,l=s),{videoContentWidth:d,videoContentHeight:l}},an=250;function on(i){let e=()=>{};const t=new ResizeObserver(o=>{r(o),e=r.bind(null,o)});function n(o){const{parentElement:l,player:d}=i();if(l&&d){const{videoContentWidth:f,videoContentHeight:u}=rn(l,d);l.style.setProperty("--interactive-content-width",`${f}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 s(){const{parentElement:o}=i();o.removeAttribute("style")}const r=Lt(o=>{const{fns:l=[]}=i();n(o);for(const d of l)d()},an);function c(){e=void 0,t.disconnect(),s()}return{resizeObserver:t,calc:()=>{e()},release:c}}class ln{constructor(){this.map={}}push(e,t){e in this.map?this.map[e].push(t):this.map[e]=[t]}get(e){const t=this.map[e];return t?t.slice():null}getAll(){const e=[];for(const t in this.map)e.push(...this.map[t]);return e}remove(e,t){e in this.map&&(this.map[e]=this.map[e].filter(n=>n!==t),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 cn=i=>Math.floor(Math.random()*i),dn=i=>{let e=i.length,t=1/0,n=null;for(;e--;)i[e].weight<t&&(t=i[e].weight,n=i[e]);return n},hn=i=>{let e=i.length,t=-1/0,n=null;for(;e--;)i[e].weight>t&&(t=i[e].weight,n=i[e]);return n},un=i=>{const e=i.length,t=cn(e);return i[t]},pt=1,fn=i=>{var e,t;let n=0;for(let r=0;r<i.length;++r)n+=(e=i[r].weight)!==null&&e!==void 0?e:pt;const s=Math.random()*n;n=0;for(let r=0;r<i.length-1;++r)if(n+=(t=i[r].weight)!==null&&t!==void 0?t:pt,n>=s)return i[r];return i[i.length-1]},vt=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),Le=(i,e=!1)=>({...i,args:e?{...i.args,...vt}:{...vt,...i.args}}),mt=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},c=({action:h,controlType:m,controlId:p,containerId:g,branches:v=[],onEvent:I,isEOV:S=()=>!1})=>{const w=Le(h,S()),R={timestamp:1/0,priority:"control",initiator:p,actionType:w.type},k=i.emit.bind(i,E.interactives,{subjectId:p,subjectType:m,subjectName:"control",type:L.actionChoice,actionType:h.type,payload:{containerId:g,...w.args}});switch(w.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const P=v.find($=>$.id===w.args.branchId);if(!P)return;I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),k(),w.args.shouldOpenNow?C({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}}):(t.add({...R,action:C.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{chapterId:P.chapterId,autoSelect:!1}})}),n==null||n());return}case A.continuePlayback.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),k(),w.args.shouldOpenNow?b({subjectId:p,subjectName:"control",subjectType:m,action:h}):t.add({...R,action:b.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:h})});return}case A.openURI.trim().toLowerCase():{I(w.args.isDetachContainer,y.bind(null,{subjectId:p,subjectName:"control"})),k(),w.args.shouldOpenNow?M({subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}}):(t.add({...R,action:M.bind(null,{subjectId:p,subjectName:"control",subjectType:m,action:w,payload:{URI:h.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(E.errors,new j(j.Severity.RECOVERABLE,j.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:h,container:{id:m,endTime:p},branches:g=[],isEOV:v=!1,autoSelected:I=!1})=>{const S=Le(h,v),w={timestamp:!S.args.shouldOpenNow||v?1/0:p,priority:"container",initiator:m,actionType:S.type},R=i.emit.bind(i,E.interactives,{subjectId:m,subjectName:"container",type:L.actionChoice,actionType:S.type,payload:S.args});switch(S.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const k=g.find(P=>P.id===S.args.branchId);if(!k)return;R(),t.add({...w,action:C.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{chapterId:k.chapterId,autoSelect:I}})}),n==null||n();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{R(),t.add({...w,action:b.bind(null,{subjectId:m,subjectName:"container",action:S})});return}case A.openURI.trim().toLowerCase():{R(),t.add({...w,action:M.bind(null,{subjectId:m,subjectName:"container",action:S,payload:{URI:h.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(E.errors,new j(j.Severity.RECOVERABLE,j.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:h,branches:m,isEOV:p=!1}){const g=ut(h.events);if(g){const v=Le(g.action,p);i.emit(E.interactives,{subjectId:h.id,subjectName:"container",type:L.actionChoice,actionType:v.type,payload:v.args}),t.add({timestamp:p?1/0:h.endTime,priority:"container",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),s.isExpect=!0}else for(const v of h.events)o({action:v.action,container:h,branches:m,isEOV:p})}const d=({chapterId:h,action:m,branches:p=[]})=>{const g=i.emit.bind(i,E.interactives,{subjectId:h,subjectName:"chapter",type:L.actionChoice,actionType:m.type,payload:m.args});switch(m.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{const v=p.find(I=>I.id===m.args.branchId);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{const v=un(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{const v=fn(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{const v=hn(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{const v=dn(p);return v!=null&&v.chapterId?(g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{chapterId:v.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return g(),b.bind(null,{subjectId:h,subjectName:"chapter",action:m});case A.openURI.trim().toLowerCase():return g(),M.bind(null,{subjectId:h,subjectName:"chapter",action:m,payload:{URI:m.args.uri}});default:console.error("Unexpected chapter event"),i.emit(E.errors,new j(j.Severity.RECOVERABLE,j.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){const m=ut(h.events);if(m){if($t(h))return;i.emit(E.interactives,{subjectId:h.id,subjectName:"chapter",type:L.actionChoice,actionType:m.action.type,payload:m.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:A.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events.forEach(p=>{const g=d({chapterId:h.id,action:p.action,branches:h.branches});g&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:p.action.type,action:g})})}const u=({subjectId:h,subjectName:m,action:p})=>{var g;e.pause(),i.emit(E.interactives,{subjectId:h,subjectName:m,type:L.actionExecution,actionType:(g=p==null?void 0:p.type)!==null&&g!==void 0?g:A.expect})},y=({subjectId:h,subjectName:m})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(E.interactives,{subjectId:h,subjectName:m,type:L.actionExecution,actionType:"after-expect"})},b=({subjectId:h,subjectName:m,subjectType:p,action:g})=>{i.emit(E.interactives,{subjectId:h,subjectName:m,subjectType:p,type:L.actionExecution,actionType:g.type})},C=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{v.behaviour="change-chapter",i.emit(E.interactives,{subjectId:h,subjectName:m,subjectType:p,type:L.actionExecution,actionType:g.type,payload:v})},M=({subjectId:h,subjectName:m,subjectType:p,action:g,payload:v})=>{if(!v.URI)return;const I=window.open(v.URI,"_blank","noopener,noreferrer");I&&(I.opener=null),i.emit(E.interactives,{subjectId:h,subjectName:m,subjectType:p,type:L.actionExecution,actionType:g.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:y,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:r,state:s}};var he,Dt,ke,gt;class z{constructor(e,t,n,s){this.target=e,this.type=t,this.listener=n,this.options=a(z,he,"m",Dt).call(z,e,s),this.target.addEventListener(t,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}he=z,Dt=function(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{const n=new Set(["passive","capture"]),s=Object.keys(t).filter(c=>!n.has(c));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),a(z,he,"m",gt).call(z,e)?t:t.capture||!1}},gt=function(e){let t=a(z,he,"f",ke);if(t===void 0){t=!1;try{const n={},s={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);const r=()=>{};e.addEventListener("test",r,n),e.removeEventListener("test",r,n)}catch(n){t=!1}_(z,he,t,"f",ke)}return t||!1};ke={value:void 0};class pn{constructor(){this.bindingMap=new ln}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,s){if(!this.bindingMap)return;const r=new z(e,t,n,s);this.bindingMap.push(t,r)}listenOnce(e,t,n,s){const r=c=>{this.unlisten(e,t,r),n(c)};this.listen(e,t,r,s)}unlisten(e,t,n){if(!this.bindingMap)return;const s=this.bindingMap.get(t)||[];for(const r of s)r.target===e&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(t,r))}removeAll(){if(!this.bindingMap)return;const e=this.bindingMap.getAll();for(const t of e)t.unlisten();this.bindingMap.clear()}}class vn{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 t=(e=this.rootElement.getContext("2d"))===null||e===void 0?void 0:e.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;const n=t.data,s=n.length;for(let r=3;r<s;r+=40)if(n[r]!==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,t=!1){const n=e.width+e.height;if(this._prevSizeId===n)return;let s;t&&(s=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&s&&this.restore(s),this._prevSizeId=n}async save(){const e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){var t;this.rootElement&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(e,0,0,this.rootElement.width,this.rootElement.height))}}class mn{constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=s=>{const r=s!=null?s:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(r);if(this.isContainerTime(r))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;
|