@vkontakte/videoplayer-interactive 1.0.1-beta.1 → 1.0.1-beta.2

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,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-interactive v1.0.1-beta.1
3
- * Tue, 29 Aug 2023 12:52:55 GMT
2
+ * @vkontakte/videoplayer-interactive v1.0.1-beta.2
3
+ * Tue, 29 Aug 2023 13:06:34 GMT
4
4
  * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-1/doc/
5
5
  */
6
- "use strict";var je=require("@vkontakte/videoplayer-shared/es2015.cjs.js"),kt=require("@interactiveplatform/movika-graph-editor"),ke=require("uuid"),Bt=require("@vkontakte/videoplayer-core/es2015.cjs.js");const Pt="1.0.1-beta.1";function ht(i,e=1){let t="0",n="0",s="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+s},${e})`}const W="SDK_NAME",Vt="SDK_NAME-controls-container",ut=()=>document.querySelector(`.${Vt}`),q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},We={top:"flex-start",bottom:"flex-end",center:"center"},Ue={start:"flex-start",end:"flex-end",center:"center"},He={start:"left",end:"right",center:"center"},ft=({target:i,props:e})=>{var t,n,s,r,a,c;i.style.alignItems=(n=We[(t=e==null?void 0:e.text)===null||t===void 0?void 0:t.gravityVertical])!==null&&n!==void 0?n:We.center,i.style.justifyContent=(r=Ue[(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:Ue.center,i.style.textAlign=(c=He[(a=e==null?void 0:e.text)===null||a===void 0?void 0:a.alignment])!==null&&c!==void 0?c:He.start},pt=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,a,c,l,d;i.style.color=(r=(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:t.textColor,i.style.fontSize=`calc(${n.height} * ${(c=(a=e==null?void 0:e.text)===null||a===void 0?void 0:a.size)!==null&&c!==void 0?c:t.textSize})`,i.textContent=(d=(l=e==null?void 0:e.text)===null||l===void 0?void 0:l.value)!==null&&d!==void 0?d:t.textContent},vt=({target:i,props:e,fallback:t})=>{var n,s,r,a;i.style.backgroundColor=ht((s=(n=e==null?void 0:e.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:t.backgroundColor,(a=(r=e==null?void 0:e.background)===null||r===void 0?void 0:r.alpha)!==null&&a!==void 0?a:t.backgroundAlpha)},mt=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,a,c,l,d,f,u,v,y,g;i.style.border=`calc(${n.height} * ${(a=(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&&a!==void 0?a:t.borderWidth}) solid ${ht((d=(l=(c=e==null?void 0:e.shape)===null||c===void 0?void 0:c.border)===null||l===void 0?void 0:l.color)!==null&&d!==void 0?d:t.borderColor,(v=(u=(f=e==null?void 0:e.shape)===null||f===void 0?void 0:f.border)===null||u===void 0?void 0:u.alpha)!==null&&v!==void 0?v:t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(g=(y=e==null?void 0:e.shape)===null||y===void 0?void 0:y.roundCorners)!==null&&g!==void 0?g:t.roundCorners})`},Be=({target:i,layoutParams:e,fallback:t})=>{var n;i.style.transform=`rotate(${(n=-e.angle)!==null&&n!==void 0?n:t.angle}rad)`};class Pe{constructor(e){this.control=e}createView(e){var t;const n=document.createElement("div");n.classList.add(`${W}-control-container-${this.control.id}`),e(n,this.control.layoutParams);const s=((t=this.control.layoutParams.innerSizesDependOn)!==null&&t!==void 0?t: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",()=>{t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${W}-control-container-${this.control.id}`)}}const gt=i=>{if(i.type.trim().toLowerCase()==="area")return new $t(i)};class $t extends Pe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");return r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",vt({target:r,props:this.control.props,fallback:Object.assign(Object.assign({},q),{backgroundColor:"transparent"})}),mt({target:r,props:this.control.props,fallback:Object.assign(Object.assign({},q),{borderAlpha:0}),dependsOn:n}),Be({target:r,layoutParams:this.control.layoutParams,fallback:q}),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const bt=i=>{if(i.type.trim().toLowerCase()==="button")return new Ft(i)};class Ft extends Pe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");r.type="button",r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";const a=document.createElement("span");return a.style.display="inline-block",a.style.whiteSpace="pre",a.style.overflow="hidden",a.style.textOverflow="ellipsis",Be({target:r,layoutParams:this.control.layoutParams,fallback:q}),vt({target:r,props:this.control.props,fallback:q}),mt({target:r,props:this.control.props,fallback:q,dependsOn:n}),ft({target:r,props:this.control.props}),pt({target:a,props:this.control.props,fallback:q,dependsOn:n}),r.append(a),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const Dt=i=>{if(i.type.trim().toLowerCase()==="text")return new Wt(i)};class Wt extends Pe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("div");r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const a=document.createElement("span");return a.style.whiteSpace="pre",Be({target:r,layoutParams:this.control.layoutParams,fallback:q}),ft({target:r,props:this.control.props}),pt({target:a,props:this.control.props,fallback:q,dependsOn:n}),r.append(a),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}class Ut{constructor(e){this.layout=e}}const Ht=i=>{if(i.type.trim().toLowerCase()==="relative")return new yt(i)};class yt extends Ut{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 B(i,e,t,n){function s(r){return r instanceof t?r:new t(function(a){a(r)})}return new(t||(t=Promise))(function(r,a){function c(f){try{d(n.next(f))}catch(u){a(u)}}function l(f){try{d(n.throw(f))}catch(u){a(u)}}function d(f){f.done?r(f.value):s(f.value).then(c,l)}d((n=n.apply(i,e||[])).next())})}function o(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)}function _(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t}var ee,ye,qe;class Ct{constructor(e){ee.add(this),this.container=e,this.factories=new Map,o(this,ee,"m",ye).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),o(this,ee,"m",ye).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),o(this,ee,"m",ye).call(this)}}ee=new WeakSet,ye=function(){this.controls=o(this,ee,"m",qe).call(this)},qe=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 Et=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new qt(i,e)};class qt extends Ct{constructor(e,t){super(e),this.rootElement=t!=null?t:ut(),this.layout=new yt(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",bt),this.addControlFactory("text",Dt),this.addControlFactory("area",gt)}createView(e){const t=document.createElement("div");return t.classList.add(`${W}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const s=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(s,e)}),this.rootElement.append(t),t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){var e;this.isRemoved||((e=this.getElement())===null||e===void 0||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${W}-${this.container.id}`)}}const pe={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},ae=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,Ve=i=>ae(i,pe.Object),Re=i=>ae(i,pe.String),ne=i=>ae(i,pe.Array),wt=i=>ae(i,pe.Number),Gt=i=>ae(i,pe.Function),Ge=i=>wt(i)&&!isNaN(i),zt=i=>i==null,ue=i=>Ve(i)&&Object.keys(i).length===0,_t=i=>ne(i)&&!i.length,me=(i,e)=>Re(i)&&(e?i.trim():i).length,It=window.navigator.userAgent.toLowerCase(),Kt=/mobi/i.test(It);It.indexOf("android")>-1;const Yt="video_interactive",Qt="videoint";class Xt{constructor(e){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.nodePos=[t.x,t.y]}},this.handleManifestChange=(t,n=[])=>B(this,void 0,void 0,function*(){var s;if(!wt(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.ngEditor){let r;try{r=yield je.loadVKLangPack(this.lang,Yt,Qt)}catch(a){console.log("Unable to load graph language pack")}this.ngEditor=new kt.GraphEditor(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:r}),this.ngEditor.on("control",({name:a,chapterId:c})=>{a==="openPreview"&&this.onOpenPreviewClick(c)})}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.visitedChapterIds=new Set(r),this.onOpenPreviewClick=t,this.onError=n,this.nodePos=[],this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.ngEditor=void 0,this.graphWrapperElement=Jt(e)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.ngEditor.zoomTo(this.nodePos),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),(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 Jt(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 Zt=(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()))},ze=(i=[],e="")=>i.reduce((t,n)=>(t.find(s=>s[e]===n[e])||t.push(n),t),[]),Ke="chapterId";class te{constructor(e){var t;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:ke.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?ze(Array.from(e.visitedChapters),Ke):[],this.branches=ne(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()),ne(e==null?void 0:e.visitedChapters)&&(this.visitedChapters=ze([...this.visitedChapters,...e.visitedChapters],Ke)),ne(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 ge{constructor(e){var t,n;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:ke.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=ne(e==null?void 0:e.sessions)?e==null?void 0:e.sessions.map(s=>new te(s)):[],this.isCompleted=(n=e==null?void 0:e.isCompleted)!==null&&n!==void 0?n:!1}update(e){var t,n,s,r,a;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=(a=e==null?void 0:e.isCompleted)!==null&&a!==void 0?a:this.isCompleted}addSession(e){this.sessions.push(new te(e))}updateSession(e,t){let n;zt(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 xe="SDK_NAME-history-changed";class ei extends EventTarget{constructor(){super(),this.history=new ge,this.sendEvent()}onChapterChange({chapterId:e,mediaId:t,autoSelect:n=!1,isLastChapter:s=!1}){this.history.isCompleted?this.history=new ge({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:te.createVisitedChapter(e),branches:te.createBranch(e,t,n)}):this.history.addSession({updateOn:Date.now(),visitedChapters:te.createVisitedChapter(e),branches:te.createBranch(e,t,!1)}),this.sendEvent()}onManifestChange(e,t){t?this.history=new ge(t):this.history=new ge({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(xe,{bubbles:!1,detail:this.getHistory()}))}destroy(){this.history=void 0}}function ti(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 fe=(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},ii="3.1",Ye={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ni={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},si=i=>{const e=[];for(const t of i.chapters){let n;const s=[];for(let c of t.branches){const{isDefault:l}=c,d=Y(c,["isDefault"]);l&&(n=d.id),s.push(d)}let r=[];const a=[];for(let c of t.containers){const{fallbackStrategy:l}=c,d=Y(c,["fallbackStrategy"]),f=!!d.endTime;let u=[ni];switch(l){case"await":f?u=[]:r=[];break;case"default":{const v={type:"onSuspense",action:{type:Ye.default,args:{branchId:n,shouldOpenNow:!f,isDetachContainer:!0}}};f?u=[v]:r=[v];break}case"random":case"weightlessRandom":case"max":case"min":{const v={type:"onSuspense",action:{type:Ye[l],args:{}}};f?u=[v]:r=[v];break}}for(const v of d.controls)a.push(Object.assign(Object.assign({},d),{controls:[Object.assign({},v)],id:ke.v4(),events:u}))}e.push(Object.assign(Object.assign({},t),{containers:a,events:r,branches:s}))}return i.metadata.version=ii,i.metadata.updated=new Date().toISOString(),Object.assign(Object.assign({},i),{chapters:e})},ri="3.2",ai=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:ri}),media:t})}return i},oi="3.3",ci=(i=[])=>({edit:{chapters:i},view:{}}),Qe={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},li=i=>{var e;const t=[],n=[];for(const s of i.chapters){const{id:r,x:a,y:c}=s,l=Y(s,["id","x","y"]),d=l.containers.map(f=>{var u;return Object.assign(Object.assign({},f),{controls:f.controls.map(v=>{var{subtype:y,type:g}=v,V=Y(v,["subtype","type"]);return Object.assign(Object.assign({},V),{type:y!=null?y:g})}),events:!((u=f.events)===null||u===void 0)&&u.length?f.events:[Qe]})});t.push(Object.assign(Object.assign({id:r},l),{containers:d,events:!((e=l.events)===null||e===void 0)&&e.length?l.events:[Qe]})),n.push({id:r,x:a,y:c})}return Object.assign(Object.assign({},i),{chapters:t,graph:ci(n),metadata:Object.assign(Object.assign({},i.metadata),{version:oi})})},di=[{version:"3.0",migrate:si},{version:"3.1",migrate:ai},{version:"3.2",migrate:li}],hi=i=>di.reduce((e,t)=>fe(e.metadata.version,t.version)?e:t.migrate(e),i),O=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),Xe={metadata:"Object",chapters:"Array"},ui="3.0.0",fi="3.3.0",$e=i=>{const e=fe(i,ui);return e===-1?!1:e===0?!0:fe(i,fi)!==1},pi=i=>{if(!Ve(i))return!1;for(const e in Xe)if(!i[e]||!ae(i[e],Xe[e]))return!1;return $e(i.metadata.version)};class x{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}x.Severity={RECOVERABLE:1,CRITICAL:2};x.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5};class jt{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)=>{Gt(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.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class mi{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!==null&&t!==void 0?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!==null&&n!==void 0?n:[]}}exec(e,t){return B(this,void 0,void 0,function*(){return gi(...this.loaders[e])(t)})}}function gi(...i){return function(t){return B(this,void 0,void 0,function*(){const n=[...i];for(;n.length>0;)t=yield n.shift()(t);return t})}}function Ie(i,e,t){return i?Object.assign(Object.assign({},i),{[e]:i[e]?[t,...i[e]]:[t]}):{[e]:[t]}}function Ae(i){var{actions:e,errors:t,chapterId:n}=i,s=Y(i,["actions","errors","chapterId"]);if(n){const r=e.getManifest(),a=e.getChapter(r.chapters,n);if(a){const c=e.getMedia(r.media,a.videoId),l=e.getGraph(r.graph,a.id);return c?Object.assign(Object.assign({},s),{actions:e,errors:t,result:{chapter:a,media:c,graph:l}}):Object.assign(Object.assign({},s),{errors:Ie(t,Ae.name,"Could not find media"),actions:e})}}return Object.assign(Object.assign({},s),{errors:Ie(t,Ae.name,"Could not find chapter"),actions:e})}class Je{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 a=n[s];try{a.callback.call(this,e)}catch(c){Promise.resolve().then(()=>{throw c})}a.options&&a.options.once&&this.removeEventListener(e.type,a.callback)}return!e.defaultPrevented}}class Ot extends Je{constructor(){super(),this.listeners||Je.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 Ot,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",Ot.prototype[Symbol.toStringTag]="AbortSignal");function St(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 yi(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=i;if(!St({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:e,Request:r};let r=t;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(d,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const v=new t(d,f);return u&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),v},r.prototype=t.prototype);const a=e;return{fetch:(l,d)=>{const f=r&&r.prototype.isPrototypeOf(l)?l.signal:d?d.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch(y){u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const v=new Promise((y,g)=>{f.addEventListener("abort",()=>g(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([v,a(l,d)])}return a(l,d)},Request:r}}const Fe=St({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Tt=Fe?yi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ze=Fe?Tt.fetch:window.fetch;Fe?Tt.Request:window.Request;const Ci=i=>B(void 0,void 0,void 0,function*(){try{let e,t;if(Ve(i))e=i;else if(Re(i)){t=new URL(i).href;const s=yield Ze(t);if(!s.ok)return{};e=yield s.json()}else return{};if(!pi(e))return{};const n=e.metadata.media;if(Re(n))try{let s;t?s=new URL(n,t).href:(s=new URL(n).href,t=s);const r=yield Ze(s);if(!r.ok)throw new Error;e.metadata.media=yield r.json()}catch(s){return Ii(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}});function Ei(i){return B(this,void 0,void 0,function*(){const{manifest:e,manifestURL:t}=yield Ci(i),n=hi(e);return n.media=wi(n.media,t),delete n.metadata.media,n})}function Se(i,e){return i.find(t=>t.id===e)}function et(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 tt(i,e){return i.videos.find(t=>t.id===e)}function wi(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=_i(n.url,e);return Object.assign(Object.assign({},n),{url:s||n.url})})}))})}function _i(i,e){try{return new URL(i,e).href}catch(t){return""}}function Ii(i){return fe(i,"3.2.0")>=0}class Rt extends mi{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}setManifest(e){var t;return B(this,void 0,void 0,function*(){this.release();const n=yield this.exec("manifestLoaders",{actions:{addErrorMessage:Ie},result:null,errors:null,source:e});n.errors&&this.errorHandler(n.errors);const s=yield Ei((t=n.result)!==null&&t!==void 0?t:e);return this.manifest=s,this})}setInitial(){return B(this,void 0,void 0,function*(){return this.setNext()})}setNext(e=this.manifest.metadata.initChapterId){return B(this,void 0,void 0,function*(){const t=yield this.exec("chapterLoaders",Ae({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:et,getChapter:Se,getMedia:tt,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ie},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=Se(this.manifest.chapters,e);if(t){const n=tt(this.manifest.media,t.videoId),s=et(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=Se(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const s=this.getByChapterId(n.chapterId);return s&&t.push(s),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",goToActionAvailabilityChanged:"go-to-action-availability-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},it={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed"};function ji(){const i=new Map;function e(s){var{listId:r=Math.random().toString(),itemId:a=Math.random().toString()}=s,c=Y(s,["listId","itemId"]);const l=i.get(r),d=Object.assign({},c);return l?l[a]=d:i.set(r,{[a]:d}),Object.assign({listId:r,itemId:a},c)}function t(s,r){var a,c;const l=i.get(s);if(l){if(r)return(a=l[r])===null||a===void 0||a.player.destroy(),(c=l[r])===null||c===void 0||c.container.remove(),delete l[r],Object.keys(l).length||i.delete(s),!0;for(const d of Object.values(l))d.player.destroy(),d.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 Te(i,e=[]){let t={},n;const s=!e.length;for(const r of i.variants)switch(!n&&"cover"in r&&(n=r.cover),r.type){case"mp4":(s||e.includes("mp4"))&&(t=Object.assign(Object.assign({},t),{MPEG:{"Invariant quality":r.url}}));break;case"hls":(s||e.includes("hls"))&&(t=Object.assign(Object.assign({},t),{HLS:{type:"url",url:r.url}}));break;case"dash":(s||e.includes("dash"))&&(t=Object.assign(Object.assign({},t),{DASH:{type:"url",url:r.url}}));break}return{sources:t,thumbUrl:n,title:i.id}}const Ce={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Oi=2;function Si(i){const e=ji(),t=new jt;let n={},s=!1,r=null,a=!1,c;i&&l(i);function l(h){r=h}function d(h,p,m){var C;if(!r)throw Error("need to set interactive controller");const w=((C=e.map.get(h))!==null&&C!==void 0?C:{})[p];if(w){n=Object.assign({chapterId:m,listId:h,itemId:p},w),w.container.remove(),s=!1,r.setPlayer(w.player),a||(r.init(),a=!0),t.emit(Ce.activePlayerChanged,n);return}throw Error("Can't set. Not find.")}function f(h,p,m){return B(this,void 0,void 0,function*(){if(!r)throw Error("need to set interactive controller");if(ue(n)||h!==n.itemId)return;if(m>=0&&!s){const b=r.getChapterBranches();s=!0;const w=new Set;for(const j of b)w.has(j.media.id)||(yield v({media:j.media,chapterId:j.chapter.id,setAsActive:!1,title:j.chapter.label}),w.add(j.media.id))}})}function u({chapter:{id:h},media:p}){return B(this,void 0,void 0,function*(){if(ue(n))return;const m=n.player.info.muted$.getValue(),C=n.player.info.currentQuality$.getValue(),b=n.player.info.isAutoQualityEnabled$.getValue(),w=n.player.info.volume$.getValue(),j=n.player.info.currentPlaybackRate$.getValue(),I=!b;let A=!1;if(n.chapterId===h){n.player.seekTime(0),n.player.play();return}for(const M of e.map)if(M[0]===p.id){const N=Object.keys(M[1]);for(const D of N)D===n.itemId?(N.length<Oi||(A=!0),e.removePlayer(M[0],D)):(A=!0,d(M[0],D,h),I&&n.player.setQuality(C),n.player.setVolume(w),n.player.setMuted(m),n.player.setPlaybackRate(j))}else e.removePlayer(M[0]);A||(yield v({media:p,chapterId:h,setAsActive:!0}),I&&n.player.setQuality(C),n.player.setVolume(w),n.player.setMuted(m),n.player.setPlaybackRate(j))})}function v({media:h,chapterId:p,prefetch:m=!0,setAsActive:C=!0,autoplay:b=!1,preferredExt:w,title:j}){var I,A;return B(this,void 0,void 0,function*(){const M=Math.random().toString(),N=document.createElement("div");c.append(N);let D;if(!((I=r==null?void 0:r.options)===null||I===void 0)&&I.vkVideoLoader){const oe=h.variants.find(Oe=>{var ce;return((ce=Oe.payload)===null||ce===void 0?void 0:ce.type)==="vk"});if(oe&&"payload"in oe){const[Oe,ce]=oe.payload.id.split("_");D=yield r.options.vkVideoLoader(Oe,ce)}}const Mt=Object.assign({container:N},((A=D==null?void 0:D.videos)===null||A===void 0?void 0:A[0])||{sources:Te(h,w).sources}),ve=new Bt.Player;ve.initVideo(Mt);const Nt=N.lastChild;ve.info.position$.subscribe(function(oe){f(M,ve.info.duration$.getValue(),oe)}),Nt&&(N.style.display="none",N.classList.add(p));const J=e.createPlayer({listId:h.id,itemId:M,player:ve,container:N,sources:Te(h,w).sources,title:j});return C&&d(h.id,J.itemId,p),b&&J.player.play(),m&&!b&&(J.player.play(),J.player.pause()),t.emit(Ce.playerCreated,J.player),J.player})}function y(){g(),r=null}function g(){r==null||r.off(E.chapterChanged,u),e.removeAll(),n={},a=!1,s=!1}function V({source:h,initialChapter:p,container:m}){return B(this,void 0,void 0,function*(){if(!r)throw Error("need to set interactive controller");yield r.setManifest(h),g(),c=m;const{media:C,chapter:b}=yield r.setChapter({chapterId:p});if(C){r.on(E.chapterChanged,u);const w=yield v({media:C,chapterId:b.id});t.emit(Ce.initiated,{container:m,media:C,chapterId:b.id});const{sources:j,thumbUrl:I}=Te(C);return{player:w,sources:j,thumbUrl:I,title:b.label}}else console.error("not found")})}return Object.assign(Object.assign({},e),{on:t.on.bind(t),off:t.off.bind(t),init:V,setInteractiveController:l,createPlayer:v,removeAll:y,getActivePlayer:function(){return n}})}const Ti=3e3,Ri=()=>{let i=[],e=null;return{setPlayer:a=>{e=a},setContainers:a=>{i=a},deleteContainer:a=>{i=i.filter(c=>c.id!==a)},getNextInteractiveTime:(a=Ti)=>{if(!i.length||e===null)return null;let c=-1,l=!1;const d=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-a;if(u<=d&&(d<=f.endTime||f.endTime===null)){l=!0;break}d<u&&(c=c===-1?u:Math.min(c,u))}return!l&&c!==-1?c:null}}},se=Ri();var le,xt,Le,nt;class G{constructor(e,t,n,s){this.target=e,this.type=t,this.listener=n,this.options=o(G,le,"m",xt).call(G,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}}le=G,xt=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(a=>!n.has(a));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),o(G,le,"m",nt).call(G,e)?t:t.capture||!1}},nt=function(e){let t=o(G,le,"f",Le);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}_(G,le,t,"f",Le)}return t||!1};Le={value:void 0};class xi{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)}}class Ai{constructor(){this.bindingMap=new xi}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,s){if(!this.bindingMap)return;const r=new G(e,t,n,s);this.bindingMap.push(t,r)}listenOnce(e,t,n,s){const r=a=>{this.unlisten(e,t,r),n(a)};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()}}const R=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),De=i=>ne(i)&&!_t(i),At=i=>_t(i.branches)||i.order==="end",Li=(i,e)=>{var t;const n=i*1e3;return De(e.controls)&&n<((t=e.startTime)!==null&&t!==void 0?t:0)},st=(i,e)=>{var t,n;const s=i*1e3;return De(e.controls)&&s>=((t=e.startTime)!==null&&t!==void 0?t:0)&&s<=((n=e.endTime)!==null&&n!==void 0?n:1/0)},re=i=>i.some(e=>e.action.type==="expect"),Mi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i(Object.assign(Object.assign({},n[e]),t[e])),Ni=(i=[])=>i.reduce((e,t,n)=>{var s,r;if(De(t==null?void 0:t.controls)){const a=[(s=t.startTime)!==null&&s!==void 0?s:0,(r=t.endTime)!==null&&r!==void 0?r:1/0],c=t.id;if(!n)e.push({subjects:[c],range:a});else{const l=[];let d=-1/0,f=1/0,u=[];const v=[];for(let y=0;y<e.length;y++){const g=e[y];if(v.push(...g.subjects),g.range[0]<f&&(f=g.range[0]),g.range[1]>d&&(d=g.range[1]),g.range[0]<=a[0]&&g.range[1]>=a[1])return e[y].subjects.push(c),e;a[0]>=g.range[0]&&a[0]<=g.range[1]&&(l.push(y),u=u.concat(g.subjects),a[0]=g.range[0]),a[1]>=g.range[0]&&a[1]<=g.range[1]&&(l.push(y),u=u.concat(g.subjects),a[1]=g.range[1])}if(v.push(c),a[0]<=f&&a[1]>=d)return[{subjects:v,range:a}];l.length&&l.reverse().forEach(y=>{e.splice(y,1)}),e.push({subjects:u.concat([c]),range:a})}}return e},[]),ki=(i,e)=>re(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&re(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class Bi{constructor({player:e,container:t,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:a,ignoreContainerEvent:c}){this.hide=()=>{setTimeout(()=>{var l,d;this.gameState!==R.end&&(re(this.container.container.events)&&this.gameState===R.afterInteractive||this.selectBranches.state.isExpect||((d=(l=this.container).hide)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var l,d;if(this.gameState===R.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(d=(l=this.container).show)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const u=Mi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(v,y)=>{this.isSelectedControlEvent=!0,v&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===R.end||this.gameState===R.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),se.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===R.end});this.container.createView(u),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0})}},this.onEndOfVideo=()=>{this.gameState=R.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var l,d,f,u;if(((l=this.player.experimental.element$.getValue())===null||l===void 0?void 0:l.readyState)<1||[R.destroyed,R.removed].includes(this.gameState))return;const y=this.player.info.position$.getValue();if(Li(y,this.container.container))this.gameState!==R.beforeInteractive&&(this.gameState=R.beforeInteractive,this.onBeforeStartTime());else if(st(y,this.container.container))this.gameState!==R.interactive&&(this.gameState=R.interactive,this.onStartTime());else if(this.gameState!==R.afterInteractive){const h=this.gameState;this.gameState=R.afterInteractive,h===R.interactive&&this.onEndTime()}else this.gameState!==R.destroyed&&this.removeView();const g=st(y,this.container.container),V=this.container.container.startTime?[this.container.container.startTime,(d=this.container.container.endTime)!==null&&d!==void 0?d:1/0]:[];(u=(f=this.container).onProgress)===null||u===void 0||u.call(f,y,g),this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:V,currentTime:y,isInteractiveTime:g})},this.container=t,this.branches=n,this.selectBranches=s,this.eventManager=new Ai,this.subscription=new je.Subscription,this.player=e,this.interactiveEvents=r,this.ignoreContainerEvent=c,this.globalEventEmitter=a,this.gameState=R.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=re(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)===null||t===void 0||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=R.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=R.removed}destroy(){var e;this.reset(),this.removeView(),this.gameState=R.destroyed,this.eventManager.release(),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}),se.deleteContainer(this.container.container.id)}}function Pi(){const i={};function e(){for(const c in i)Object.prototype.hasOwnProperty.call(i,c)&&delete i[c];return!0}function t(c){const l={};for(const d in i)+d<=c&&(l[d]=i[d]);return l}function n(c){const l={};for(const d in i)+d>=c&&(l[d]=i[d]);return l}function s({timestamp:c,priority:l,initiator:d}){var f;if(Ge(c)){const u=(f=i[c])!==null&&f!==void 0?f:null;if(u&&me(l,!0)){let v={};const y=u[l];if(y&&(v=Object.assign(Object.assign({},v),y)),v=ue(v)?null:v,v&&me(d,!0)){const g=v[d];return g!=null?g:null}return v}return u}return null}function r({timestamp:c,priority:l,initiator:d}){if(Ge(c))if(i[c]){if(me(l,!0))if(i[c][l]){if(me(d,!0))if(i[c][l][d]){if(delete i[c][l][d],!ue(i[c][l]))return!0}else return!1;if(delete i[c][l],!ue(i[c]))return!0}else return!1;return delete i[c]}else return!1}function a(c){var l,d,f,{timestamp:u,priority:v,initiator:y}=c,g=Y(c,["timestamp","priority","initiator"]);!((d=(l=i[u])===null||l===void 0?void 0:l[v])===null||d===void 0)&&d[y]?i[u][v][y].push(Object.assign({},g)):!((f=i[u])===null||f===void 0)&&f[v]?i[u][v]=Object.assign(Object.assign({},i[u][v]),{[y]:[Object.assign({},g)]}):i[u]?i[u]=Object.assign(Object.assign({},i[u]),{[v]:{[y]:[Object.assign({},g)]}}):i[u]={[v]:{[y]:[Object.assign({},g)]}}}return{map:i,remove:r,add:a,removeAll:e,get:s,getLte:t,getGte:n}}const Vi=[O.expect,O.setNextBranch],$i=1/0;function rt(i){let e=i,t;const n=Fi(),s=new Pi;let r;const a=()=>{u(),V()},c=h=>{s.add.call(void 0,h),v()},l=(h=[])=>{for(const p of h)if(p.action(),Vi.includes(p.actionType))break},d=h=>{var p,m,C;if(!n.isReady(h))return;const b=be((p=s.get({timestamp:h,priority:"control"}))!==null&&p!==void 0?p:{}),w=be((m=s.get({timestamp:h,priority:"container"}))!==null&&m!==void 0?m:{}),j=be((C=s.get({timestamp:h,priority:"chapter"}))!==null&&C!==void 0?C:{});l([...b,...w,...j])},f=()=>{var h;l([...be((h=s.get({timestamp:1/0,priority:"chapter"}))!==null&&h!==void 0?h:{})])},u=()=>{t&&(r==null||r.unsubscribe(),t=void 0)},v=()=>{t||(t=()=>setTimeout(()=>{d(1/0)}),r=e.events.ended$.subscribe(t))},y=h=>{u(),e=h},g=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},V=()=>{n.release(),s.removeAll()};return{setPlayer:y,add:c,remove:g,exec:d,execEndOfVideo:f,listen:v,unlisten:u,release:a,containersEventsCallState:n}}function Fi(){const i=new Map;return{setCalled:({timestamp:a,id:c})=>{const l=i.get(a);l&&l[c]!==void 0&&(l[c]=!0)},setData:(a=[])=>{var c,l;for(const d of a){const f=(c=d.endTime)!==null&&c!==void 0?c:$i,u=(l=i.get(f))!==null&&l!==void 0?l:{};i.set(f,Object.assign(Object.assign({},u),{[d.id]:!1}))}},resetCalled:a=>{const c=i.get(a);if(c)for(const l in c)c[l]=!1},isReady:a=>{const c=i.get(a);return c?!Object.values(c).some(l=>!l):!0},release:()=>i.clear()}}function be(i){return Object.values(i).flat().sort(e=>e.actionType===O.expect?-1:1)}function Di(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const Wi=(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 a=t/n,c=s/r;let l,d;return c>a?(d=r,l=r*a):c<a?(d=s/a,l=s):(d=r,l=s),{videoContentWidth:d,videoContentHeight:l}},Ui=250;function Hi(i){let e=()=>{};const t=new ResizeObserver(r=>{n(r),e=n.bind(null,r)}),n=Di(r=>{const{parentElement:a,player:c}=i();if(a&&c){const{videoContentWidth:l,videoContentHeight:d}=Wi(a,c);a.style.setProperty("--interactive-content-width",`${l}px`),a.style.setProperty("--interactive-content-height",`${d}px`),a.style.setProperty("--interactive-width",`${r[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${r[0].contentRect.height}px`)}},Ui);function s(){const{parentElement:r}=i();e=void 0,r.removeAttribute("style"),t.disconnect()}return{resizeObserver:t,calc:()=>{e()},release:s}}const qi=i=>Math.floor(Math.random()*i),Gi=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},zi=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},Ki=i=>{const e=i.length,t=qi(e);return i[t]},at=1,Yi=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:at;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:at,n>=s)return i[r];return i[i.length-1]},ot=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),ct=(i,e=!1)=>Object.assign(Object.assign({},i),{args:e?Object.assign(Object.assign({},i.args),ot):Object.assign(Object.assign({},ot),i.args)}),lt=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},a=({action:h,controlType:p,controlId:m,containerId:C,branches:b=[],onEvent:w,isEOV:j=()=>!1})=>{const I=ct(h,j()),A={timestamp:1/0,priority:"control",initiator:m,actionType:I.type},M=i.emit.bind(i,E.interactives,{subjectId:m,subjectType:p,subjectName:"control",type:L.actionChoice,actionType:h.type,payload:Object.assign({containerId:C},I.args)});switch(I.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{const N=b.find(D=>D.id===I.args.branchId);if(!N)return;w(I.args.isDetachContainer,v.bind(null,{subjectId:m,subjectName:"control"})),M(),I.args.shouldOpenNow?g({subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{chapterId:N.chapterId,autoSelect:!1}}):(t.add(Object.assign(Object.assign({},A),{action:g.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{chapterId:N.chapterId,autoSelect:!1}})})),n==null||n());return}case O.continuePlayback.trim().toLowerCase():{w(I.args.isDetachContainer,v.bind(null,{subjectId:m,subjectName:"control"})),M(),I.args.shouldOpenNow?y({subjectId:m,subjectName:"control",subjectType:p,action:h}):t.add(Object.assign(Object.assign({},A),{action:y.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:h})}));return}case O.openURI.trim().toLowerCase():{w(I.args.isDetachContainer,v.bind(null,{subjectId:m,subjectName:"control"})),M(),I.args.shouldOpenNow?V({subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{URI:h.args.uri}}):(t.add(Object.assign(Object.assign({},A),{action:V.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{URI:h.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},c=({action:h,container:{id:p,endTime:m},branches:C=[],isEOV:b=!1,autoSelected:w=!1})=>{const j=ct(h,b),I={timestamp:!j.args.shouldOpenNow||b?1/0:m,priority:"container",initiator:p,actionType:j.type},A=i.emit.bind(i,E.interactives,{subjectId:p,subjectName:"container",type:L.actionChoice,actionType:h.type,payload:j.args});switch(j.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{const M=C.find(N=>N.id===j.args.branchId);if(!M)return;A(),t.add(Object.assign(Object.assign({},I),{action:g.bind(null,{subjectId:p,subjectName:"container",action:j,payload:{chapterId:M.chapterId,autoSelect:w}})})),n==null||n(),A();return}case O.setMaxWeightBranch.trim().toLowerCase():return;case O.setMinWeightBranch.trim().toLowerCase():return;case O.setRandomBranch.trim().toLowerCase():return;case O.setWeightlessRandomBranch.trim().toLowerCase():return;case O.continuePlayback.trim().toLowerCase():{A(),t.add(Object.assign(Object.assign({},I),{action:y.bind(null,{subjectId:p,subjectName:"container",action:j})}));return}case O.openURI.trim().toLowerCase():{A(),t.add(Object.assign(Object.assign({},I),{action:V.bind(null,{subjectId:p,subjectName:"container",action:j,payload:{URI:h.args.uri}})})),n==null||n(),A();return}default:console.error("Unexpected container event"),i.emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:h,branches:p,isEOV:m=!1}){if(re(h.events))t.add({timestamp:m?1/0:h.endTime,priority:"container",initiator:h.id,actionType:O.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),s.isExpect=!0;else for(const C of h.events)c({action:C.action,container:h,branches:p,isEOV:m})}const d=({chapterId:h,action:p,branches:m=[]})=>{const C=i.emit.bind(i,E.interactives,{subjectId:h,subjectName:"chapter",type:L.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{const b=m.find(w=>w.id===p.args.branchId);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setWeightlessRandomBranch.trim().toLowerCase():{const b=Ki(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setRandomBranch.trim().toLowerCase():{const b=Yi(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMaxWeightBranch.trim().toLowerCase():{const b=zi(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMinWeightBranch.trim().toLowerCase():{const b=Gi(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.continuePlayback.trim().toLowerCase():return C(),y.bind(null,{subjectId:h,subjectName:"chapter",action:p});case O.openURI.trim().toLowerCase():return C(),V.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),i.emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){re(h.events)?At(h)||t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:O.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})}):h.events.forEach(p=>{const m=d({chapterId:h.id,action:p.action,branches:h.branches});m&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:p.action.type,action:m})})}const u=({subjectId:h,subjectName:p,action:m})=>{var C;e.pause(),i.emit(E.interactives,{subjectId:h,subjectName:p,type:L.actionExecution,actionType:(C=m==null?void 0:m.type)!==null&&C!==void 0?C:O.expect})},v=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(E.interactives,{subjectId:h,subjectName:p,type:L.actionExecution,actionType:"after-expect"})},y=({subjectId:h,subjectName:p,subjectType:m,action:C})=>{i.emit(E.interactives,{subjectId:h,subjectName:p,subjectType:m,type:L.actionExecution,actionType:C.type})},g=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:b})=>{b.behaviour="change-chapter",i.emit(E.interactives,{subjectId:h,subjectName:p,subjectType:m,type:L.actionExecution,actionType:C.type,payload:b})},V=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:b})=>{if(!b.URI)return;const w=window.open(b.URI,"_blank","noopener,noreferrer");w&&(w.opener=null),i.emit(E.interactives,{subjectId:h,subjectName:p,subjectType:m,type:L.actionExecution,actionType:C.type})};return{onControlEvent:a,onContainerEvent:c,onChapterEvent:d,onExpectEvent:u,expectEventHandler:v,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:r,state:s}};var F,Q,H,X,k,P,K,T,Z,$,U,de,S,Ee,Lt,Me,Ne,ie,he,dt,we,_e;const Qi=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1}),z=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function Xi(){const i=document.createElement("div");return i.classList.add("root"),i}class Ji{constructor(e){F.add(this),Q.set(this,null),H.set(this,null),X.set(this,null),k.set(this,null),P.set(this,null),K.set(this,null),T.set(this,null),Z.set(this,!0),$.set(this,null),U.set(this,null),de.set(this,null),S.set(this,null),this.emitPlayerChanged=({player:t,sources:n,title:s})=>{o(this,S,"f").emit(E.playerChanged,{player:t,sources:n,title:s})},Lt.set(this,()=>{o(this,P,"f").fns.forEach(s=>s());const t=this.options.player.info.position$.getValue()*1e3,n=(o(this,T,"f").chapter.containers||[]).filter(s=>s.startTime>=Math.floor(t));for(const s of n){o(this,k,"f").remove({timestamp:1/0,priority:"container",initiator:s.id});for(const r of s.controls)o(this,k,"f").remove({timestamp:1/0,priority:"control",initiator:r.id});o(this,H,"f").find(r=>r.container.container.id===s.id).reset()}}),Me.set(this,()=>{o(this,Q,"f").calc(),o(this,P,"f").requestAnimation()}),ie.set(this,()=>{o(this,H,"f").forEach(t=>{o(this,P,"f").removeFn(t.whilePlaying),t.destroy()})}),we.set(this,()=>{se.getNextInteractiveTime()===null?o(this,Z,"f")&&(o(this,S,"f").emit(E.goToActionAvailabilityChanged,!1),_(this,Z,!1,"f")):o(this,Z,"f")||(o(this,S,"f").emit(E.goToActionAvailabilityChanged,!0),_(this,Z,!0,"f"))}),_e.set(this,({detail:t})=>{o(this,S,"f").emit(E.historyChanged,t)}),this.options=Object.assign(Object.assign({},Qi),e),_(this,H,[],"f"),this.factories=new Map([["choice",Et]]),this.rootElement=Xi(),this.options.parentElement.append(this.rootElement),_(this,S,new jt,"f"),_(this,X,new je.Subscription,"f"),_(this,T,new Rt(this.options.loaders,t=>o(this,S,"f").emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.MANIFEST,t))),"f"),_(this,k,rt(this.options.player),"f"),_(this,P,new vi,"f"),_(this,K,lt({player:this.options.player,interactiveEvents:o(this,k,"f"),globalEventEmitter:o(this,S,"f"),removeControllers:o(this,ie,"f")}),"f"),_(this,Q,Hi(()=>{var t;return{player:(t=this.options)===null||t===void 0?void 0:t.player,parentElement:this.rootElement}}),"f"),this.options.graph&&_(this,$,new Xt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:t=>{this.setChapter({chapterId:t}),o(this,S,"f").emit(E.graph,{type:it.watchAgainClicked,chapterId:t})},onError:t=>o(this,S,"f").emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.LOADERS,{message:t}))}),"f"),_(this,U,new ei,"f"),o(this,U,"f").addEventListener(xe,o(this,_e,"f")),o(this,S,"f").on(E.interactives,t=>{var n,s;if(t.type===L.actionExecution){if(((n=t.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:r,autoSelect:a}=t.payload;this.setChapter({chapterId:r,autoSelect:a})}if(((s=t.payload)===null||s===void 0?void 0:s.behaviour)==="change-manifest"){const{manifestURL:r}=t.payload;this.setManifest(r)}}}),this.state=z.created}initSeamless({source:e,initialChapter:t}){return B(this,void 0,void 0,function*(){_(this,de,Si(this),"f");const n=document.createElement("div"),{player:s,sources:r,title:a,thumbUrl:c}=yield o(this,de,"f").init({source:e,initialChapter:t,container:n});return o(this,de,"f").on(Ce.activePlayerChanged,this.emitPlayerChanged),{player:s,sources:r,title:a,thumbUrl:c}})}setPlayer(e){o(this,F,"m",Ee).call(this),this.options.player=e,se.setPlayer(this.options.player),o(this,k,"f")?o(this,k,"f").setPlayer(this.options.player):_(this,k,rt(this.options.player),"f"),_(this,K,lt({player:this.options.player,interactiveEvents:o(this,k,"f"),globalEventEmitter:o(this,S,"f"),removeControllers:o(this,ie,"f")}),"f"),this.state===z.initiated&&(o(this,F,"m",Ne).call(this),o(this,F,"m",he).call(this,o(this,T,"f").chapter))}setManifest(e,t){return B(this,void 0,void 0,function*(){o(this,F,"m",Ee).call(this);const n=yield o(this,T,"f").setManifest(e),s=t&&t.manifestId===n.manifest.metadata.id?Object.assign({},t):void 0;return o(this,U,"f").onManifestChange(n.manifest.metadata,s),o(this,$,"f")&&o(this,$,"f").handleManifestChange(n.manifest,s?Zt(s):[]),o(this,S,"f").emit(E.manifestChanged,{manifest:n.manifest}),o(this,F,"m",he).call(this,o(this,T,"f").chapter),n.manifest})}setChapter({chapterId:e,autoSelect:t,tryContinueFromHistory:n=!1}={}){return B(this,void 0,void 0,function*(){o(this,F,"m",Ee).call(this);let s;e?s=yield o(this,T,"f").setNext(e):s=yield n?o(this,T,"f").setNext(ti(o(this,T,"f").manifest,this.getHistory())):o(this,T,"f").setInitial();const{chapter:r,media:a,graph:c}=s;return o(this,U,"f").onChapterChange({chapterId:r.id,mediaId:a.id,autoSelect:t,isLastChapter:At(r)}),o(this,$,"f")&&o(this,$,"f").handleChapterChange(c),o(this,S,"f").emit(E.chapterChanged,{chapter:r,media:a,graph:c}),o(this,F,"m",he).call(this,o(this,T,"f").chapter),{chapter:r,media:a,graph:c}})}toggleGraphView(e=!0){o(this,$,"f")&&(e?o(this,$,"f").show():o(this,$,"f").hide(),o(this,S,"f").emit(E.graph,{type:it.visibility,visibility:e}))}init(){o(this,T,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.state===z.created&&(o(this,Q,"f").resizeObserver.observe(this.options.fullscreenTargetElement),o(this,F,"m",Ne).call(this),this.state=z.initiated,o(this,F,"m",he).call(this,o(this,T,"f").chapter))}isSupport(e=o(this,T,"f").manifest){return $e(e.metadata.version)}getHistory(){return o(this,U,"f").getHistory()}getInteractiveRanges(){var e;return Ni((e=o(this,T,"f").chapter)===null||e===void 0?void 0:e.containers)}getNextInteractiveStartTime(e){return se.getNextInteractiveTime(e)}getChapterBranches(e){return o(this,T,"f").getBranches(e)}getCurrentChapter(){return o(this,T,"f").getCurrent()}getCurrentManifest(){return o(this,T,"f").manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return o(this,S,"f").on(...e),this}off(...e){return o(this,S,"f").off(...e),this}once(...e){return o(this,S,"f").once(...e),this}destroy(){var e;o(this,ie,"f").call(this),_(this,H,void 0,"f"),o(this,U,"f").removeEventListener(xe,o(this,_e,"f")),o(this,U,"f").destroy(),_(this,U,void 0,"f"),(e=o(this,$,"f"))===null||e===void 0||e.destroy(),_(this,$,void 0,"f"),o(this,Q,"f").release(),_(this,Q,void 0,"f"),_(this,K,void 0,"f"),o(this,P,"f").release(),_(this,P,void 0,"f"),o(this,k,"f").release(),_(this,k,void 0,"f"),o(this,T,"f").release(),_(this,K,void 0,"f"),o(this,X,"f").unsubscribe(),_(this,X,void 0,"f"),o(this,S,"f").reset(),_(this,S,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,this.factories=void 0,this.options=void 0,this.state=z.destroyed}}Q=new WeakMap,H=new WeakMap,X=new WeakMap,k=new WeakMap,P=new WeakMap,K=new WeakMap,T=new WeakMap,Z=new WeakMap,$=new WeakMap,U=new WeakMap,de=new WeakMap,S=new WeakMap,Lt=new WeakMap,Me=new WeakMap,ie=new WeakMap,we=new WeakMap,_e=new WeakMap,F=new WeakSet,Ee=function(){var e;this.state===z.ready&&(o(this,ie,"f").call(this),_(this,H,[],"f"),o(this,P,"f").release(),(e=o(this,k,"f"))===null||e===void 0||e.release(),this.state=z.initiated)},Ne=function(){o(this,X,"f").unsubscribe(),o(this,X,"f").add(this.options.player.events.started$.pipe(je.once()).subscribe(o(this,Me,"f"))).add(this.options.player.events.playing$.subscribe(o(this,P,"f").requestAnimation)).add(this.options.player.events.paused$.subscribe(o(this,P,"f").cancelAnimation))},he=function(e){o(this,T,"f").chapter&&this.state===z.initiated&&(o(this,K,"f").setManifestChapterEvents(e),_(this,H,o(this,F,"m",dt).call(this,e),"f"),o(this,k,"f").containersEventsCallState.setData(e.containers),se.setContainers(o(this,H,"f").map(t=>t.container.container)),o(this,P,"f").addFn(o(this,we,"f")),o(this,we,"f").call(this),this.state=z.ready)},dt=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 a=r.type.trim().toLowerCase(),c=this.factories.get(a);if(c){const l=new Bi({player:this.options.player,container:c(r,this.rootElement),branches:o(this,T,"f").chapter.branches,selectBranches:o(this,K,"f"),interactiveEvents:o(this,k,"f"),globalEventEmitter:o(this,S,"f"),ignoreContainerEvent:()=>ki(r,o(this,H,"f"))});return o(this,P,"f").addFn(l.whilePlaying,!0),[...s,l]}return[...s]},[]))!==null&&n!==void 0?n:[]};const Zi={Container:Ct,createChoiceContainer:Et,createAreaControl:gt,createButtonControl:bt,createRelativeLayout:Ht,getRootEl:ut,classnamesPrefix:W},en={version:Pt};exports.CustomError=x;exports.EVENT_NAMES=E;exports.Interactives=Ji;exports.ManifestController=Rt;exports.SDKInfo=en;exports.compareVersions=fe;exports.isSupportedManifest=$e;exports.utils=Zi;
6
+ "use strict";var je=require("@vkontakte/videoplayer-shared/es2015.cjs.js"),kt=require("@interactiveplatform/movika-graph-editor"),ke=require("uuid"),Bt=require("@vkontakte/videoplayer-core/es2015.cjs.js");const Pt="1.0.1-beta.2";function ht(i,e=1){let t="0",n="0",s="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+s},${e})`}const W="SDK_NAME",Vt="SDK_NAME-controls-container",ut=()=>document.querySelector(`.${Vt}`),q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},We={top:"flex-start",bottom:"flex-end",center:"center"},Ue={start:"flex-start",end:"flex-end",center:"center"},He={start:"left",end:"right",center:"center"},ft=({target:i,props:e})=>{var t,n,s,r,a,c;i.style.alignItems=(n=We[(t=e==null?void 0:e.text)===null||t===void 0?void 0:t.gravityVertical])!==null&&n!==void 0?n:We.center,i.style.justifyContent=(r=Ue[(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:Ue.center,i.style.textAlign=(c=He[(a=e==null?void 0:e.text)===null||a===void 0?void 0:a.alignment])!==null&&c!==void 0?c:He.start},pt=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,a,c,l,d;i.style.color=(r=(s=e==null?void 0:e.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:t.textColor,i.style.fontSize=`calc(${n.height} * ${(c=(a=e==null?void 0:e.text)===null||a===void 0?void 0:a.size)!==null&&c!==void 0?c:t.textSize})`,i.textContent=(d=(l=e==null?void 0:e.text)===null||l===void 0?void 0:l.value)!==null&&d!==void 0?d:t.textContent},vt=({target:i,props:e,fallback:t})=>{var n,s,r,a;i.style.backgroundColor=ht((s=(n=e==null?void 0:e.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:t.backgroundColor,(a=(r=e==null?void 0:e.background)===null||r===void 0?void 0:r.alpha)!==null&&a!==void 0?a:t.backgroundAlpha)},mt=({target:i,props:e,fallback:t,dependsOn:n})=>{var s,r,a,c,l,d,f,u,v,y,g;i.style.border=`calc(${n.height} * ${(a=(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&&a!==void 0?a:t.borderWidth}) solid ${ht((d=(l=(c=e==null?void 0:e.shape)===null||c===void 0?void 0:c.border)===null||l===void 0?void 0:l.color)!==null&&d!==void 0?d:t.borderColor,(v=(u=(f=e==null?void 0:e.shape)===null||f===void 0?void 0:f.border)===null||u===void 0?void 0:u.alpha)!==null&&v!==void 0?v:t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(g=(y=e==null?void 0:e.shape)===null||y===void 0?void 0:y.roundCorners)!==null&&g!==void 0?g:t.roundCorners})`},Be=({target:i,layoutParams:e,fallback:t})=>{var n;i.style.transform=`rotate(${(n=-e.angle)!==null&&n!==void 0?n:t.angle}rad)`};class Pe{constructor(e){this.control=e}createView(e){var t;const n=document.createElement("div");n.classList.add(`${W}-control-container-${this.control.id}`),e(n,this.control.layoutParams);const s=((t=this.control.layoutParams.innerSizesDependOn)!==null&&t!==void 0?t: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",()=>{t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${W}-control-container-${this.control.id}`)}}const gt=i=>{if(i.type.trim().toLowerCase()==="area")return new $t(i)};class $t extends Pe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");return r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",vt({target:r,props:this.control.props,fallback:Object.assign(Object.assign({},q),{backgroundColor:"transparent"})}),mt({target:r,props:this.control.props,fallback:Object.assign(Object.assign({},q),{borderAlpha:0}),dependsOn:n}),Be({target:r,layoutParams:this.control.layoutParams,fallback:q}),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const bt=i=>{if(i.type.trim().toLowerCase()==="button")return new Ft(i)};class Ft extends Pe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("button");r.type="button",r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";const a=document.createElement("span");return a.style.display="inline-block",a.style.whiteSpace="pre",a.style.overflow="hidden",a.style.textOverflow="ellipsis",Be({target:r,layoutParams:this.control.layoutParams,fallback:q}),vt({target:r,props:this.control.props,fallback:q}),mt({target:r,props:this.control.props,fallback:q,dependsOn:n}),ft({target:r,props:this.control.props}),pt({target:a,props:this.control.props,fallback:q,dependsOn:n}),r.append(a),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}const Dt=i=>{if(i.type.trim().toLowerCase()==="text")return new Wt(i)};class Wt extends Pe{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:s}=super.createView(t),r=document.createElement("div");r.classList.add(`${W}-${this.control.id}`),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const a=document.createElement("span");return a.style.whiteSpace="pre",Be({target:r,layoutParams:this.control.layoutParams,fallback:q}),ft({target:r,props:this.control.props}),pt({target:a,props:this.control.props,fallback:q,dependsOn:n}),r.append(a),s.append(r),e.append(s),s}getElement(){return document.querySelector(`.${W}-${this.control.id}`)}}class Ut{constructor(e){this.layout=e}}const Ht=i=>{if(i.type.trim().toLowerCase()==="relative")return new yt(i)};class yt extends Ut{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 B(i,e,t,n){function s(r){return r instanceof t?r:new t(function(a){a(r)})}return new(t||(t=Promise))(function(r,a){function c(f){try{d(n.next(f))}catch(u){a(u)}}function l(f){try{d(n.throw(f))}catch(u){a(u)}}function d(f){f.done?r(f.value):s(f.value).then(c,l)}d((n=n.apply(i,e||[])).next())})}function o(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)}function _(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t}var ee,ye,qe;class Ct{constructor(e){ee.add(this),this.container=e,this.factories=new Map,o(this,ee,"m",ye).call(this)}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),o(this,ee,"m",ye).call(this)}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),o(this,ee,"m",ye).call(this)}}ee=new WeakSet,ye=function(){this.controls=o(this,ee,"m",qe).call(this)},qe=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 Et=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new qt(i,e)};class qt extends Ct{constructor(e,t){super(e),this.rootElement=t!=null?t:ut(),this.layout=new yt(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",bt),this.addControlFactory("text",Dt),this.addControlFactory("area",gt)}createView(e){const t=document.createElement("div");return t.classList.add(`${W}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const s=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(s,e)}),this.rootElement.append(t),t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){var e;this.isRemoved||((e=this.getElement())===null||e===void 0||e.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${W}-${this.container.id}`)}}const pe={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},ae=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,Ve=i=>ae(i,pe.Object),Re=i=>ae(i,pe.String),ne=i=>ae(i,pe.Array),wt=i=>ae(i,pe.Number),Gt=i=>ae(i,pe.Function),Ge=i=>wt(i)&&!isNaN(i),zt=i=>i==null,ue=i=>Ve(i)&&Object.keys(i).length===0,_t=i=>ne(i)&&!i.length,me=(i,e)=>Re(i)&&(e?i.trim():i).length,It=window.navigator.userAgent.toLowerCase(),Kt=/mobi/i.test(It);It.indexOf("android")>-1;const Yt="video_interactive",Qt="videoint";class Xt{constructor(e){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.nodePos=[t.x,t.y]}},this.handleManifestChange=(t,n=[])=>B(this,void 0,void 0,function*(){var s;if(!wt(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.ngEditor){let r;try{r=yield je.loadVKLangPack(this.lang,Yt,Qt)}catch(a){console.log("Unable to load graph language pack")}this.ngEditor=new kt.GraphEditor(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:r}),this.ngEditor.on("control",({name:a,chapterId:c})=>{a==="openPreview"&&this.onOpenPreviewClick(c)})}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.visitedChapterIds=new Set(r),this.onOpenPreviewClick=t,this.onError=n,this.nodePos=[],this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.ngEditor=void 0,this.graphWrapperElement=Jt(e)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.ngEditor.zoomTo(this.nodePos),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var e,t;this.hide(),(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 Jt(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 Zt=(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()))},ze=(i=[],e="")=>i.reduce((t,n)=>(t.find(s=>s[e]===n[e])||t.push(n),t),[]),Ke="chapterId";class te{constructor(e){var t;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:ke.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?ze(Array.from(e.visitedChapters),Ke):[],this.branches=ne(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()),ne(e==null?void 0:e.visitedChapters)&&(this.visitedChapters=ze([...this.visitedChapters,...e.visitedChapters],Ke)),ne(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 ge{constructor(e){var t,n;this.id=(t=e==null?void 0:e.id)!==null&&t!==void 0?t:ke.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=ne(e==null?void 0:e.sessions)?e==null?void 0:e.sessions.map(s=>new te(s)):[],this.isCompleted=(n=e==null?void 0:e.isCompleted)!==null&&n!==void 0?n:!1}update(e){var t,n,s,r,a;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=(a=e==null?void 0:e.isCompleted)!==null&&a!==void 0?a:this.isCompleted}addSession(e){this.sessions.push(new te(e))}updateSession(e,t){let n;zt(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 xe="SDK_NAME-history-changed";class ei extends EventTarget{constructor(){super(),this.history=new ge,this.sendEvent()}onChapterChange({chapterId:e,mediaId:t,autoSelect:n=!1,isLastChapter:s=!1}){this.history.isCompleted?this.history=new ge({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:te.createVisitedChapter(e),branches:te.createBranch(e,t,n)}):this.history.addSession({updateOn:Date.now(),visitedChapters:te.createVisitedChapter(e),branches:te.createBranch(e,t,!1)}),this.sendEvent()}onManifestChange(e,t){t?this.history=new ge(t):this.history=new ge({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(xe,{bubbles:!1,detail:this.getHistory()}))}destroy(){this.history=void 0}}function ti(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 fe=(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},ii="3.1",Ye={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},ni={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},si=i=>{const e=[];for(const t of i.chapters){let n;const s=[];for(let c of t.branches){const{isDefault:l}=c,d=Y(c,["isDefault"]);l&&(n=d.id),s.push(d)}let r=[];const a=[];for(let c of t.containers){const{fallbackStrategy:l}=c,d=Y(c,["fallbackStrategy"]),f=!!d.endTime;let u=[ni];switch(l){case"await":f?u=[]:r=[];break;case"default":{const v={type:"onSuspense",action:{type:Ye.default,args:{branchId:n,shouldOpenNow:!f,isDetachContainer:!0}}};f?u=[v]:r=[v];break}case"random":case"weightlessRandom":case"max":case"min":{const v={type:"onSuspense",action:{type:Ye[l],args:{}}};f?u=[v]:r=[v];break}}for(const v of d.controls)a.push(Object.assign(Object.assign({},d),{controls:[Object.assign({},v)],id:ke.v4(),events:u}))}e.push(Object.assign(Object.assign({},t),{containers:a,events:r,branches:s}))}return i.metadata.version=ii,i.metadata.updated=new Date().toISOString(),Object.assign(Object.assign({},i),{chapters:e})},ri="3.2",ai=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:ri}),media:t})}return i},oi="3.3",ci=(i=[])=>({edit:{chapters:i},view:{}}),Qe={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},li=i=>{var e;const t=[],n=[];for(const s of i.chapters){const{id:r,x:a,y:c}=s,l=Y(s,["id","x","y"]),d=l.containers.map(f=>{var u;return Object.assign(Object.assign({},f),{controls:f.controls.map(v=>{var{subtype:y,type:g}=v,V=Y(v,["subtype","type"]);return Object.assign(Object.assign({},V),{type:y!=null?y:g})}),events:!((u=f.events)===null||u===void 0)&&u.length?f.events:[Qe]})});t.push(Object.assign(Object.assign({id:r},l),{containers:d,events:!((e=l.events)===null||e===void 0)&&e.length?l.events:[Qe]})),n.push({id:r,x:a,y:c})}return Object.assign(Object.assign({},i),{chapters:t,graph:ci(n),metadata:Object.assign(Object.assign({},i.metadata),{version:oi})})},di=[{version:"3.0",migrate:si},{version:"3.1",migrate:ai},{version:"3.2",migrate:li}],hi=i=>di.reduce((e,t)=>fe(e.metadata.version,t.version)?e:t.migrate(e),i),O=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),Xe={metadata:"Object",chapters:"Array"},ui="3.0.0",fi="3.3.0",$e=i=>{const e=fe(i,ui);return e===-1?!1:e===0?!0:fe(i,fi)!==1},pi=i=>{if(!Ve(i))return!1;for(const e in Xe)if(!i[e]||!ae(i[e],Xe[e]))return!1;return $e(i.metadata.version)};class x{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}x.Severity={RECOVERABLE:1,CRITICAL:2};x.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5};class jt{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)=>{Gt(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.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(e)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class mi{constructor(e){var t,n;this.loaders={chapterLoaders:(t=e==null?void 0:e.chapterLoaders)!==null&&t!==void 0?t:[],manifestLoaders:(n=e==null?void 0:e.manifestLoaders)!==null&&n!==void 0?n:[]}}exec(e,t){return B(this,void 0,void 0,function*(){return gi(...this.loaders[e])(t)})}}function gi(...i){return function(t){return B(this,void 0,void 0,function*(){const n=[...i];for(;n.length>0;)t=yield n.shift()(t);return t})}}function Ie(i,e,t){return i?Object.assign(Object.assign({},i),{[e]:i[e]?[t,...i[e]]:[t]}):{[e]:[t]}}function Ae(i){var{actions:e,errors:t,chapterId:n}=i,s=Y(i,["actions","errors","chapterId"]);if(n){const r=e.getManifest(),a=e.getChapter(r.chapters,n);if(a){const c=e.getMedia(r.media,a.videoId),l=e.getGraph(r.graph,a.id);return c?Object.assign(Object.assign({},s),{actions:e,errors:t,result:{chapter:a,media:c,graph:l}}):Object.assign(Object.assign({},s),{errors:Ie(t,Ae.name,"Could not find media"),actions:e})}}return Object.assign(Object.assign({},s),{errors:Ie(t,Ae.name,"Could not find chapter"),actions:e})}class Je{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 a=n[s];try{a.callback.call(this,e)}catch(c){Promise.resolve().then(()=>{throw c})}a.options&&a.options.once&&this.removeEventListener(e.type,a.callback)}return!e.defaultPrevented}}class Ot extends Je{constructor(){super(),this.listeners||Je.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 Ot,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",Ot.prototype[Symbol.toStringTag]="AbortSignal");function St(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 yi(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=i;if(!St({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:e,Request:r};let r=t;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(d,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const v=new t(d,f);return u&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),v},r.prototype=t.prototype);const a=e;return{fetch:(l,d)=>{const f=r&&r.prototype.isPrototypeOf(l)?l.signal:d?d.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch(y){u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const v=new Promise((y,g)=>{f.addEventListener("abort",()=>g(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([v,a(l,d)])}return a(l,d)},Request:r}}const Fe=St({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Tt=Fe?yi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ze=Fe?Tt.fetch:window.fetch;Fe?Tt.Request:window.Request;const Ci=i=>B(void 0,void 0,void 0,function*(){try{let e,t;if(Ve(i))e=i;else if(Re(i)){t=new URL(i).href;const s=yield Ze(t);if(!s.ok)return{};e=yield s.json()}else return{};if(!pi(e))return{};const n=e.metadata.media;if(Re(n))try{let s;t?s=new URL(n,t).href:(s=new URL(n).href,t=s);const r=yield Ze(s);if(!r.ok)throw new Error;e.metadata.media=yield r.json()}catch(s){return Ii(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch(e){return{}}});function Ei(i){return B(this,void 0,void 0,function*(){const{manifest:e,manifestURL:t}=yield Ci(i),n=hi(e);return n.media=wi(n.media,t),delete n.metadata.media,n})}function Se(i,e){return i.find(t=>t.id===e)}function et(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 tt(i,e){return i.videos.find(t=>t.id===e)}function wi(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=_i(n.url,e);return Object.assign(Object.assign({},n),{url:s||n.url})})}))})}function _i(i,e){try{return new URL(i,e).href}catch(t){return""}}function Ii(i){return fe(i,"3.2.0")>=0}class Rt extends mi{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}setManifest(e){var t;return B(this,void 0,void 0,function*(){this.release();const n=yield this.exec("manifestLoaders",{actions:{addErrorMessage:Ie},result:null,errors:null,source:e});n.errors&&this.errorHandler(n.errors);const s=yield Ei((t=n.result)!==null&&t!==void 0?t:e);return this.manifest=s,this})}setInitial(){return B(this,void 0,void 0,function*(){return this.setNext()})}setNext(e=this.manifest.metadata.initChapterId){return B(this,void 0,void 0,function*(){const t=yield this.exec("chapterLoaders",Ae({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:et,getChapter:Se,getMedia:tt,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ie},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=Se(this.manifest.chapters,e);if(t){const n=tt(this.manifest.media,t.videoId),s=et(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=Se(this.manifest.chapters,e);return this.getByBranches(t==null?void 0:t.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const s=this.getByChapterId(n.chapterId);return s&&t.push(s),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const E={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",goToActionAvailabilityChanged:"go-to-action-availability-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},it={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed"};function ji(){const i=new Map;function e(s){var{listId:r=Math.random().toString(),itemId:a=Math.random().toString()}=s,c=Y(s,["listId","itemId"]);const l=i.get(r),d=Object.assign({},c);return l?l[a]=d:i.set(r,{[a]:d}),Object.assign({listId:r,itemId:a},c)}function t(s,r){var a,c;const l=i.get(s);if(l){if(r)return(a=l[r])===null||a===void 0||a.player.destroy(),(c=l[r])===null||c===void 0||c.container.remove(),delete l[r],Object.keys(l).length||i.delete(s),!0;for(const d of Object.values(l))d.player.destroy(),d.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 Te(i,e=[]){let t={},n;const s=!e.length;for(const r of i.variants)switch(!n&&"cover"in r&&(n=r.cover),r.type){case"mp4":(s||e.includes("mp4"))&&(t=Object.assign(Object.assign({},t),{MPEG:{"Invariant quality":r.url}}));break;case"hls":(s||e.includes("hls"))&&(t=Object.assign(Object.assign({},t),{HLS:{type:"url",url:r.url}}));break;case"dash":(s||e.includes("dash"))&&(t=Object.assign(Object.assign({},t),{DASH:{type:"url",url:r.url}}));break}return{sources:t,thumbUrl:n,title:i.id}}const Ce={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Oi=2;function Si(i){const e=ji(),t=new jt;let n={},s=!1,r=null,a=!1,c;i&&l(i);function l(h){r=h}function d(h,p,m){var C;if(!r)throw Error("need to set interactive controller");const w=((C=e.map.get(h))!==null&&C!==void 0?C:{})[p];if(w){n=Object.assign({chapterId:m,listId:h,itemId:p},w),w.container.remove(),s=!1,r.setPlayer(w.player),a||(r.init(),a=!0),t.emit(Ce.activePlayerChanged,n);return}throw Error("Can't set. Not find.")}function f(h,p,m){return B(this,void 0,void 0,function*(){if(!r)throw Error("need to set interactive controller");if(ue(n)||h!==n.itemId)return;if(m>=0&&!s){const b=r.getChapterBranches();s=!0;const w=new Set;for(const j of b)w.has(j.media.id)||(yield v({media:j.media,chapterId:j.chapter.id,setAsActive:!1,title:j.chapter.label}),w.add(j.media.id))}})}function u({chapter:{id:h},media:p}){return B(this,void 0,void 0,function*(){if(ue(n))return;const m=n.player.info.muted$.getValue(),C=n.player.info.currentQuality$.getValue(),b=n.player.info.isAutoQualityEnabled$.getValue(),w=n.player.info.volume$.getValue(),j=n.player.info.currentPlaybackRate$.getValue(),I=!b;let A=!1;if(n.chapterId===h){n.player.seekTime(0),n.player.play();return}for(const M of e.map)if(M[0]===p.id){const N=Object.keys(M[1]);for(const D of N)D===n.itemId?(N.length<Oi||(A=!0),e.removePlayer(M[0],D)):(A=!0,d(M[0],D,h),I&&n.player.setQuality(C),n.player.setVolume(w),n.player.setMuted(m),n.player.setPlaybackRate(j))}else e.removePlayer(M[0]);A||(yield v({media:p,chapterId:h,setAsActive:!0}),I&&n.player.setQuality(C),n.player.setVolume(w),n.player.setMuted(m),n.player.setPlaybackRate(j))})}function v({media:h,chapterId:p,prefetch:m=!0,setAsActive:C=!0,autoplay:b=!1,preferredExt:w,title:j}){var I,A;return B(this,void 0,void 0,function*(){const M=Math.random().toString(),N=document.createElement("div");c.append(N);let D;if(!((I=r==null?void 0:r.options)===null||I===void 0)&&I.vkVideoLoader){const oe=h.variants.find(Oe=>{var ce;return((ce=Oe.payload)===null||ce===void 0?void 0:ce.type)==="vk"});if(oe&&"payload"in oe){const[Oe,ce]=oe.payload.id.split("_");D=yield r.options.vkVideoLoader(Oe,ce)}}const Mt=Object.assign({container:N},((A=D==null?void 0:D.videos)===null||A===void 0?void 0:A[0])||{sources:Te(h,w).sources}),ve=new Bt.Player;ve.initVideo(Mt);const Nt=N.lastChild;ve.info.position$.subscribe(function(oe){f(M,ve.info.duration$.getValue(),oe)}),Nt&&(N.style.display="none",N.classList.add(p));const J=e.createPlayer({listId:h.id,itemId:M,player:ve,container:N,sources:Te(h,w).sources,title:j});return C&&d(h.id,J.itemId,p),b&&J.player.play(),m&&!b&&(J.player.play(),J.player.pause()),t.emit(Ce.playerCreated,J.player),J.player})}function y(){g(),r=null}function g(){r==null||r.off(E.chapterChanged,u),e.removeAll(),n={},a=!1,s=!1}function V({source:h,initialChapter:p,container:m}){return B(this,void 0,void 0,function*(){if(!r)throw Error("need to set interactive controller");yield r.setManifest(h),g(),c=m;const{media:C,chapter:b}=yield r.setChapter({chapterId:p});if(C){r.on(E.chapterChanged,u);const w=yield v({media:C,chapterId:b.id});t.emit(Ce.initiated,{container:m,media:C,chapterId:b.id});const{sources:j,thumbUrl:I}=Te(C);return{player:w,sources:j,thumbUrl:I,title:b.label}}else console.error("not found")})}return Object.assign(Object.assign({},e),{on:t.on.bind(t),off:t.off.bind(t),init:V,setInteractiveController:l,createPlayer:v,removeAll:y,getActivePlayer:function(){return n}})}const Ti=3e3,Ri=()=>{let i=[],e=null;return{setPlayer:a=>{e=a},setContainers:a=>{i=a},deleteContainer:a=>{i=i.filter(c=>c.id!==a)},getNextInteractiveTime:(a=Ti)=>{if(!i.length||e===null)return null;let c=-1,l=!1;const d=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-a;if(u<=d&&(d<=f.endTime||f.endTime===null)){l=!0;break}d<u&&(c=c===-1?u:Math.min(c,u))}return!l&&c!==-1?c:null}}},se=Ri();var le,xt,Le,nt;class G{constructor(e,t,n,s){this.target=e,this.type=t,this.listener=n,this.options=o(G,le,"m",xt).call(G,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}}le=G,xt=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(a=>!n.has(a));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),o(G,le,"m",nt).call(G,e)?t:t.capture||!1}},nt=function(e){let t=o(G,le,"f",Le);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}_(G,le,t,"f",Le)}return t||!1};Le={value:void 0};class xi{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)}}class Ai{constructor(){this.bindingMap=new xi}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,s){if(!this.bindingMap)return;const r=new G(e,t,n,s);this.bindingMap.push(t,r)}listenOnce(e,t,n,s){const r=a=>{this.unlisten(e,t,r),n(a)};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()}}const R=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),De=i=>ne(i)&&!_t(i),At=i=>_t(i.branches)||i.order==="end",Li=(i,e)=>{var t;const n=i*1e3;return De(e.controls)&&n<((t=e.startTime)!==null&&t!==void 0?t:0)},st=(i,e)=>{var t,n;const s=i*1e3;return De(e.controls)&&s>=((t=e.startTime)!==null&&t!==void 0?t:0)&&s<=((n=e.endTime)!==null&&n!==void 0?n:1/0)},re=i=>i.some(e=>e.action.type==="expect"),Mi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i(Object.assign(Object.assign({},n[e]),t[e])),Ni=(i=[])=>i.reduce((e,t,n)=>{var s,r;if(De(t==null?void 0:t.controls)){const a=[(s=t.startTime)!==null&&s!==void 0?s:0,(r=t.endTime)!==null&&r!==void 0?r:1/0],c=t.id;if(!n)e.push({subjects:[c],range:a});else{const l=[];let d=-1/0,f=1/0,u=[];const v=[];for(let y=0;y<e.length;y++){const g=e[y];if(v.push(...g.subjects),g.range[0]<f&&(f=g.range[0]),g.range[1]>d&&(d=g.range[1]),g.range[0]<=a[0]&&g.range[1]>=a[1])return e[y].subjects.push(c),e;a[0]>=g.range[0]&&a[0]<=g.range[1]&&(l.push(y),u=u.concat(g.subjects),a[0]=g.range[0]),a[1]>=g.range[0]&&a[1]<=g.range[1]&&(l.push(y),u=u.concat(g.subjects),a[1]=g.range[1])}if(v.push(c),a[0]<=f&&a[1]>=d)return[{subjects:v,range:a}];l.length&&l.reverse().forEach(y=>{e.splice(y,1)}),e.push({subjects:u.concat([c]),range:a})}}return e},[]),ki=(i,e)=>re(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&re(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class Bi{constructor({player:e,container:t,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:a,ignoreContainerEvent:c}){this.hide=()=>{setTimeout(()=>{var l,d;this.gameState!==R.end&&(re(this.container.container.events)&&this.gameState===R.afterInteractive||this.selectBranches.state.isExpect||((d=(l=this.container).hide)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var l,d;if(this.gameState===R.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(d=(l=this.container).show)===null||d===void 0||d.call(l),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const u=Mi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(v,y)=>{this.isSelectedControlEvent=!0,v&&(this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===R.end||this.gameState===R.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),se.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===R.end});this.container.createView(u),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0})}},this.onEndOfVideo=()=>{this.gameState=R.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var l,d,f,u;if(((l=this.player.experimental.element$.getValue())===null||l===void 0?void 0:l.readyState)<1||[R.destroyed,R.removed].includes(this.gameState))return;const y=this.player.info.position$.getValue();if(Li(y,this.container.container))this.gameState!==R.beforeInteractive&&(this.gameState=R.beforeInteractive,this.onBeforeStartTime());else if(st(y,this.container.container))this.gameState!==R.interactive&&(this.gameState=R.interactive,this.onStartTime());else if(this.gameState!==R.afterInteractive){const h=this.gameState;this.gameState=R.afterInteractive,h===R.interactive&&this.onEndTime()}else this.gameState!==R.destroyed&&this.removeView();const g=st(y,this.container.container),V=this.container.container.startTime?[this.container.container.startTime,(d=this.container.container.endTime)!==null&&d!==void 0?d:1/0]:[];(u=(f=this.container).onProgress)===null||u===void 0||u.call(f,y,g),this.globalEventEmitter.emit(E.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:V,currentTime:y,isInteractiveTime:g})},this.container=t,this.branches=n,this.selectBranches=s,this.eventManager=new Ai,this.subscription=new je.Subscription,this.player=e,this.interactiveEvents=r,this.ignoreContainerEvent=c,this.globalEventEmitter=a,this.gameState=R.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=re(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){var e,t;(t=(e=this.container).hide)===null||t===void 0||t.call(e),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=R.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(E.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=R.removed}destroy(){var e;this.reset(),this.removeView(),this.gameState=R.destroyed,this.eventManager.release(),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}),se.deleteContainer(this.container.container.id)}}function Pi(){const i={};function e(){for(const c in i)Object.prototype.hasOwnProperty.call(i,c)&&delete i[c];return!0}function t(c){const l={};for(const d in i)+d<=c&&(l[d]=i[d]);return l}function n(c){const l={};for(const d in i)+d>=c&&(l[d]=i[d]);return l}function s({timestamp:c,priority:l,initiator:d}){var f;if(Ge(c)){const u=(f=i[c])!==null&&f!==void 0?f:null;if(u&&me(l,!0)){let v={};const y=u[l];if(y&&(v=Object.assign(Object.assign({},v),y)),v=ue(v)?null:v,v&&me(d,!0)){const g=v[d];return g!=null?g:null}return v}return u}return null}function r({timestamp:c,priority:l,initiator:d}){if(Ge(c))if(i[c]){if(me(l,!0))if(i[c][l]){if(me(d,!0))if(i[c][l][d]){if(delete i[c][l][d],!ue(i[c][l]))return!0}else return!1;if(delete i[c][l],!ue(i[c]))return!0}else return!1;return delete i[c]}else return!1}function a(c){var l,d,f,{timestamp:u,priority:v,initiator:y}=c,g=Y(c,["timestamp","priority","initiator"]);!((d=(l=i[u])===null||l===void 0?void 0:l[v])===null||d===void 0)&&d[y]?i[u][v][y].push(Object.assign({},g)):!((f=i[u])===null||f===void 0)&&f[v]?i[u][v]=Object.assign(Object.assign({},i[u][v]),{[y]:[Object.assign({},g)]}):i[u]?i[u]=Object.assign(Object.assign({},i[u]),{[v]:{[y]:[Object.assign({},g)]}}):i[u]={[v]:{[y]:[Object.assign({},g)]}}}return{map:i,remove:r,add:a,removeAll:e,get:s,getLte:t,getGte:n}}const Vi=[O.expect,O.setNextBranch],$i=1/0;function rt(i){let e=i,t;const n=Fi(),s=new Pi;let r;const a=()=>{u(),V()},c=h=>{s.add.call(void 0,h),v()},l=(h=[])=>{for(const p of h)if(p.action(),Vi.includes(p.actionType))break},d=h=>{var p,m,C;if(!n.isReady(h))return;const b=be((p=s.get({timestamp:h,priority:"control"}))!==null&&p!==void 0?p:{}),w=be((m=s.get({timestamp:h,priority:"container"}))!==null&&m!==void 0?m:{}),j=be((C=s.get({timestamp:h,priority:"chapter"}))!==null&&C!==void 0?C:{});l([...b,...w,...j])},f=()=>{var h;l([...be((h=s.get({timestamp:1/0,priority:"chapter"}))!==null&&h!==void 0?h:{})])},u=()=>{t&&(r==null||r.unsubscribe(),t=void 0)},v=()=>{t||(t=()=>setTimeout(()=>{d(1/0)}),r=e.events.ended$.subscribe(t))},y=h=>{u(),e=h},g=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},V=()=>{n.release(),s.removeAll()};return{setPlayer:y,add:c,remove:g,exec:d,execEndOfVideo:f,listen:v,unlisten:u,release:a,containersEventsCallState:n}}function Fi(){const i=new Map;return{setCalled:({timestamp:a,id:c})=>{const l=i.get(a);l&&l[c]!==void 0&&(l[c]=!0)},setData:(a=[])=>{var c,l;for(const d of a){const f=(c=d.endTime)!==null&&c!==void 0?c:$i,u=(l=i.get(f))!==null&&l!==void 0?l:{};i.set(f,Object.assign(Object.assign({},u),{[d.id]:!1}))}},resetCalled:a=>{const c=i.get(a);if(c)for(const l in c)c[l]=!1},isReady:a=>{const c=i.get(a);return c?!Object.values(c).some(l=>!l):!0},release:()=>i.clear()}}function be(i){return Object.values(i).flat().sort(e=>e.actionType===O.expect?-1:1)}function Di(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const Wi=(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 a=t/n,c=s/r;let l,d;return c>a?(d=r,l=r*a):c<a?(d=s/a,l=s):(d=r,l=s),{videoContentWidth:d,videoContentHeight:l}},Ui=250;function Hi(i){let e=()=>{};const t=new ResizeObserver(r=>{n(r),e=n.bind(null,r)}),n=Di(r=>{const{parentElement:a,player:c}=i();if(a&&c){const{videoContentWidth:l,videoContentHeight:d}=Wi(a,c);a.style.setProperty("--interactive-content-width",`${l}px`),a.style.setProperty("--interactive-content-height",`${d}px`),a.style.setProperty("--interactive-width",`${r[0].contentRect.width}px`),a.style.setProperty("--interactive-height",`${r[0].contentRect.height}px`)}},Ui);function s(){const{parentElement:r}=i();e=void 0,r.removeAttribute("style"),t.disconnect()}return{resizeObserver:t,calc:()=>{e()},release:s}}const qi=i=>Math.floor(Math.random()*i),Gi=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},zi=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},Ki=i=>{const e=i.length,t=qi(e);return i[t]},at=1,Yi=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:at;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:at,n>=s)return i[r];return i[i.length-1]},ot=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),ct=(i,e=!1)=>Object.assign(Object.assign({},i),{args:e?Object.assign(Object.assign({},i.args),ot):Object.assign(Object.assign({},ot),i.args)}),lt=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},a=({action:h,controlType:p,controlId:m,containerId:C,branches:b=[],onEvent:w,isEOV:j=()=>!1})=>{const I=ct(h,j()),A={timestamp:1/0,priority:"control",initiator:m,actionType:I.type},M=i.emit.bind(i,E.interactives,{subjectId:m,subjectType:p,subjectName:"control",type:L.actionChoice,actionType:h.type,payload:Object.assign({containerId:C},I.args)});switch(I.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{const N=b.find(D=>D.id===I.args.branchId);if(!N)return;w(I.args.isDetachContainer,v.bind(null,{subjectId:m,subjectName:"control"})),M(),I.args.shouldOpenNow?g({subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{chapterId:N.chapterId,autoSelect:!1}}):(t.add(Object.assign(Object.assign({},A),{action:g.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{chapterId:N.chapterId,autoSelect:!1}})})),n==null||n());return}case O.continuePlayback.trim().toLowerCase():{w(I.args.isDetachContainer,v.bind(null,{subjectId:m,subjectName:"control"})),M(),I.args.shouldOpenNow?y({subjectId:m,subjectName:"control",subjectType:p,action:h}):t.add(Object.assign(Object.assign({},A),{action:y.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:h})}));return}case O.openURI.trim().toLowerCase():{w(I.args.isDetachContainer,v.bind(null,{subjectId:m,subjectName:"control"})),M(),I.args.shouldOpenNow?V({subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{URI:h.args.uri}}):(t.add(Object.assign(Object.assign({},A),{action:V.bind(null,{subjectId:m,subjectName:"control",subjectType:p,action:I,payload:{URI:h.args.uri}})})),n==null||n());return}default:console.error("Unexpected control event"),i.emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},c=({action:h,container:{id:p,endTime:m},branches:C=[],isEOV:b=!1,autoSelected:w=!1})=>{const j=ct(h,b),I={timestamp:!j.args.shouldOpenNow||b?1/0:m,priority:"container",initiator:p,actionType:j.type},A=i.emit.bind(i,E.interactives,{subjectId:p,subjectName:"container",type:L.actionChoice,actionType:h.type,payload:j.args});switch(j.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{const M=C.find(N=>N.id===j.args.branchId);if(!M)return;A(),t.add(Object.assign(Object.assign({},I),{action:g.bind(null,{subjectId:p,subjectName:"container",action:j,payload:{chapterId:M.chapterId,autoSelect:w}})})),n==null||n(),A();return}case O.setMaxWeightBranch.trim().toLowerCase():return;case O.setMinWeightBranch.trim().toLowerCase():return;case O.setRandomBranch.trim().toLowerCase():return;case O.setWeightlessRandomBranch.trim().toLowerCase():return;case O.continuePlayback.trim().toLowerCase():{A(),t.add(Object.assign(Object.assign({},I),{action:y.bind(null,{subjectId:p,subjectName:"container",action:j})}));return}case O.openURI.trim().toLowerCase():{A(),t.add(Object.assign(Object.assign({},I),{action:V.bind(null,{subjectId:p,subjectName:"container",action:j,payload:{URI:h.args.uri}})})),n==null||n(),A();return}default:console.error("Unexpected container event"),i.emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:h,branches:p,isEOV:m=!1}){if(re(h.events))t.add({timestamp:m?1/0:h.endTime,priority:"container",initiator:h.id,actionType:O.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),s.isExpect=!0;else for(const C of h.events)c({action:C.action,container:h,branches:p,isEOV:m})}const d=({chapterId:h,action:p,branches:m=[]})=>{const C=i.emit.bind(i,E.interactives,{subjectId:h,subjectName:"chapter",type:L.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case O.setNextBranch.trim().toLowerCase():{const b=m.find(w=>w.id===p.args.branchId);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setWeightlessRandomBranch.trim().toLowerCase():{const b=Ki(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setRandomBranch.trim().toLowerCase():{const b=Yi(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMaxWeightBranch.trim().toLowerCase():{const b=zi(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.setMinWeightBranch.trim().toLowerCase():{const b=Gi(m);return b!=null&&b.chapterId?(C(),g.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:b.chapterId,autoSelect:!0}})):void 0}case O.continuePlayback.trim().toLowerCase():return C(),y.bind(null,{subjectId:h,subjectName:"chapter",action:p});case O.openURI.trim().toLowerCase():return C(),V.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),i.emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){re(h.events)?At(h)||t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:O.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})}):h.events.forEach(p=>{const m=d({chapterId:h.id,action:p.action,branches:h.branches});m&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:p.action.type,action:m})})}const u=({subjectId:h,subjectName:p,action:m})=>{var C;e.pause(),i.emit(E.interactives,{subjectId:h,subjectName:p,type:L.actionExecution,actionType:(C=m==null?void 0:m.type)!==null&&C!==void 0?C:O.expect})},v=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(E.interactives,{subjectId:h,subjectName:p,type:L.actionExecution,actionType:"after-expect"})},y=({subjectId:h,subjectName:p,subjectType:m,action:C})=>{i.emit(E.interactives,{subjectId:h,subjectName:p,subjectType:m,type:L.actionExecution,actionType:C.type})},g=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:b})=>{b.behaviour="change-chapter",i.emit(E.interactives,{subjectId:h,subjectName:p,subjectType:m,type:L.actionExecution,actionType:C.type,payload:b})},V=({subjectId:h,subjectName:p,subjectType:m,action:C,payload:b})=>{if(!b.URI)return;const w=window.open(b.URI,"_blank","noopener,noreferrer");w&&(w.opener=null),i.emit(E.interactives,{subjectId:h,subjectName:p,subjectType:m,type:L.actionExecution,actionType:C.type})};return{onControlEvent:a,onContainerEvent:c,onChapterEvent:d,onExpectEvent:u,expectEventHandler:v,setManifestChapterEvents:f,setManifestContainerEvents:l,stopExpect:r,state:s}};var F,Q,H,X,k,P,K,T,Z,$,U,de,S,Ee,Lt,Me,Ne,ie,he,dt,we,_e;const Qi=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1}),z=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function Xi(){const i=document.createElement("div");return i.classList.add("root"),i}class Ji{constructor(e){F.add(this),Q.set(this,null),H.set(this,null),X.set(this,null),k.set(this,null),P.set(this,null),K.set(this,null),T.set(this,null),Z.set(this,!0),$.set(this,null),U.set(this,null),de.set(this,null),S.set(this,null),this.emitPlayerChanged=({player:t,sources:n,title:s})=>{o(this,S,"f").emit(E.playerChanged,{player:t,sources:n,title:s})},Lt.set(this,()=>{o(this,P,"f").fns.forEach(s=>s());const t=this.options.player.info.position$.getValue()*1e3,n=(o(this,T,"f").chapter.containers||[]).filter(s=>s.startTime>=Math.floor(t));for(const s of n){o(this,k,"f").remove({timestamp:1/0,priority:"container",initiator:s.id});for(const r of s.controls)o(this,k,"f").remove({timestamp:1/0,priority:"control",initiator:r.id});o(this,H,"f").find(r=>r.container.container.id===s.id).reset()}}),Me.set(this,()=>{o(this,Q,"f").calc(),o(this,P,"f").requestAnimation()}),ie.set(this,()=>{o(this,H,"f").forEach(t=>{o(this,P,"f").removeFn(t.whilePlaying),t.destroy()})}),we.set(this,()=>{se.getNextInteractiveTime()===null?o(this,Z,"f")&&(o(this,S,"f").emit(E.goToActionAvailabilityChanged,!1),_(this,Z,!1,"f")):o(this,Z,"f")||(o(this,S,"f").emit(E.goToActionAvailabilityChanged,!0),_(this,Z,!0,"f"))}),_e.set(this,({detail:t})=>{o(this,S,"f").emit(E.historyChanged,t)}),this.options=Object.assign(Object.assign({},Qi),e),_(this,H,[],"f"),this.factories=new Map([["choice",Et]]),this.rootElement=Xi(),this.options.parentElement.append(this.rootElement),_(this,S,new jt,"f"),_(this,X,new je.Subscription,"f"),_(this,T,new Rt(this.options.loaders,t=>o(this,S,"f").emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.MANIFEST,t))),"f"),_(this,k,rt(this.options.player),"f"),_(this,P,new vi,"f"),_(this,K,lt({player:this.options.player,interactiveEvents:o(this,k,"f"),globalEventEmitter:o(this,S,"f"),removeControllers:o(this,ie,"f")}),"f"),_(this,Q,Hi(()=>{var t;return{player:(t=this.options)===null||t===void 0?void 0:t.player,parentElement:this.rootElement}}),"f"),this.options.graph&&_(this,$,new Xt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:t=>{this.setChapter({chapterId:t}),o(this,S,"f").emit(E.graph,{type:it.watchAgainClicked,chapterId:t})},onError:t=>o(this,S,"f").emit(E.errors,new x(x.Severity.RECOVERABLE,x.Category.LOADERS,{message:t}))}),"f"),_(this,U,new ei,"f"),o(this,U,"f").addEventListener(xe,o(this,_e,"f")),o(this,S,"f").on(E.interactives,t=>{var n,s;if(t.type===L.actionExecution){if(((n=t.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:r,autoSelect:a}=t.payload;this.setChapter({chapterId:r,autoSelect:a})}if(((s=t.payload)===null||s===void 0?void 0:s.behaviour)==="change-manifest"){const{manifestURL:r}=t.payload;this.setManifest(r)}}}),this.state=z.created}initSeamless({source:e,initialChapter:t}){return B(this,void 0,void 0,function*(){_(this,de,Si(this),"f");const n=document.createElement("div"),{player:s,sources:r,title:a,thumbUrl:c}=yield o(this,de,"f").init({source:e,initialChapter:t,container:n});return o(this,de,"f").on(Ce.activePlayerChanged,this.emitPlayerChanged),{player:s,sources:r,title:a,thumbUrl:c}})}setPlayer(e){o(this,F,"m",Ee).call(this),this.options.player=e,se.setPlayer(this.options.player),o(this,k,"f")?o(this,k,"f").setPlayer(this.options.player):_(this,k,rt(this.options.player),"f"),_(this,K,lt({player:this.options.player,interactiveEvents:o(this,k,"f"),globalEventEmitter:o(this,S,"f"),removeControllers:o(this,ie,"f")}),"f"),this.state===z.initiated&&(o(this,F,"m",Ne).call(this),o(this,F,"m",he).call(this,o(this,T,"f").chapter))}setManifest(e,t){return B(this,void 0,void 0,function*(){o(this,F,"m",Ee).call(this);const n=yield o(this,T,"f").setManifest(e),s=t&&t.manifestId===n.manifest.metadata.id?Object.assign({},t):void 0;return o(this,U,"f").onManifestChange(n.manifest.metadata,s),o(this,$,"f")&&o(this,$,"f").handleManifestChange(n.manifest,s?Zt(s):[]),o(this,S,"f").emit(E.manifestChanged,{manifest:n.manifest}),o(this,F,"m",he).call(this,o(this,T,"f").chapter),n.manifest})}setChapter({chapterId:e,autoSelect:t,tryContinueFromHistory:n=!1}={}){return B(this,void 0,void 0,function*(){o(this,F,"m",Ee).call(this);let s;e?s=yield o(this,T,"f").setNext(e):s=yield n?o(this,T,"f").setNext(ti(o(this,T,"f").manifest,this.getHistory())):o(this,T,"f").setInitial();const{chapter:r,media:a,graph:c}=s;return o(this,U,"f").onChapterChange({chapterId:r.id,mediaId:a.id,autoSelect:t,isLastChapter:At(r)}),o(this,$,"f")&&o(this,$,"f").handleChapterChange(c),o(this,S,"f").emit(E.chapterChanged,{chapter:r,media:a,graph:c}),o(this,F,"m",he).call(this,o(this,T,"f").chapter),{chapter:r,media:a,graph:c}})}toggleGraphView(e=!0){o(this,$,"f")&&(e?o(this,$,"f").show():o(this,$,"f").hide(),o(this,S,"f").emit(E.graph,{type:it.visibility,visibility:e}))}init(){o(this,T,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.state===z.created&&(o(this,Q,"f").resizeObserver.observe(this.options.fullscreenTargetElement),o(this,F,"m",Ne).call(this),this.state=z.initiated,o(this,F,"m",he).call(this,o(this,T,"f").chapter))}isSupport(e=o(this,T,"f").manifest){return $e(e.metadata.version)}getHistory(){return o(this,U,"f").getHistory()}getInteractiveRanges(){var e;return Ni((e=o(this,T,"f").chapter)===null||e===void 0?void 0:e.containers)}getNextInteractiveStartTime(e){return se.getNextInteractiveTime(e)}getChapterBranches(e){return o(this,T,"f").getBranches(e)}getCurrentChapter(){return o(this,T,"f").getCurrent()}getCurrentManifest(){return o(this,T,"f").manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return o(this,S,"f").on(...e),this}off(...e){return o(this,S,"f").off(...e),this}once(...e){return o(this,S,"f").once(...e),this}destroy(){var e;o(this,ie,"f").call(this),_(this,H,void 0,"f"),o(this,U,"f").removeEventListener(xe,o(this,_e,"f")),o(this,U,"f").destroy(),_(this,U,void 0,"f"),(e=o(this,$,"f"))===null||e===void 0||e.destroy(),_(this,$,void 0,"f"),o(this,Q,"f").release(),_(this,Q,void 0,"f"),_(this,K,void 0,"f"),o(this,P,"f").release(),_(this,P,void 0,"f"),o(this,k,"f").release(),_(this,k,void 0,"f"),o(this,T,"f").release(),_(this,K,void 0,"f"),o(this,X,"f").unsubscribe(),_(this,X,void 0,"f"),o(this,S,"f").reset(),_(this,S,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,this.factories=void 0,this.options=void 0,this.state=z.destroyed}}Q=new WeakMap,H=new WeakMap,X=new WeakMap,k=new WeakMap,P=new WeakMap,K=new WeakMap,T=new WeakMap,Z=new WeakMap,$=new WeakMap,U=new WeakMap,de=new WeakMap,S=new WeakMap,Lt=new WeakMap,Me=new WeakMap,ie=new WeakMap,we=new WeakMap,_e=new WeakMap,F=new WeakSet,Ee=function(){var e;this.state===z.ready&&(o(this,ie,"f").call(this),_(this,H,[],"f"),o(this,P,"f").release(),(e=o(this,k,"f"))===null||e===void 0||e.release(),this.state=z.initiated)},Ne=function(){o(this,X,"f").unsubscribe(),o(this,X,"f").add(this.options.player.events.started$.pipe(je.once()).subscribe(o(this,Me,"f"))).add(this.options.player.events.playing$.subscribe(o(this,P,"f").requestAnimation)).add(this.options.player.events.paused$.subscribe(o(this,P,"f").cancelAnimation))},he=function(e){o(this,T,"f").chapter&&this.state===z.initiated&&(o(this,K,"f").setManifestChapterEvents(e),_(this,H,o(this,F,"m",dt).call(this,e),"f"),o(this,k,"f").containersEventsCallState.setData(e.containers),se.setContainers(o(this,H,"f").map(t=>t.container.container)),o(this,P,"f").addFn(o(this,we,"f")),o(this,we,"f").call(this),this.state=z.ready)},dt=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 a=r.type.trim().toLowerCase(),c=this.factories.get(a);if(c){const l=new Bi({player:this.options.player,container:c(r,this.rootElement),branches:o(this,T,"f").chapter.branches,selectBranches:o(this,K,"f"),interactiveEvents:o(this,k,"f"),globalEventEmitter:o(this,S,"f"),ignoreContainerEvent:()=>ki(r,o(this,H,"f"))});return o(this,P,"f").addFn(l.whilePlaying,!0),[...s,l]}return[...s]},[]))!==null&&n!==void 0?n:[]};const Zi={Container:Ct,createChoiceContainer:Et,createAreaControl:gt,createButtonControl:bt,createRelativeLayout:Ht,getRootEl:ut,classnamesPrefix:W},en={version:Pt};exports.CustomError=x;exports.EVENT_NAMES=E;exports.Interactives=Ji;exports.ManifestController=Rt;exports.SDKInfo=en;exports.compareVersions=fe;exports.isSupportedManifest=$e;exports.utils=Zi;