@vkontakte/videoplayer-interactive 1.0.2 → 1.0.3

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