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