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