@vkontakte/videoplayer-interactive 1.0.6 → 1.0.7-beta.0

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