@vkontakte/videoplayer-interactive 1.0.7-dev.200de7b.0 → 1.0.7-dev.6e70b297.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es2015.cjs.js +6 -6
- package/es2015.esm.js +6 -6
- package/es2018.cjs.js +6 -6
- package/es2018.esm.js +6 -6
- package/esnext.cjs.js +6 -6
- package/esnext.esm.js +5 -5
- package/evergreen.esm.js +6 -6
- package/index.d.ts +4 -0
- package/package.json +5 -8
- package/es5.umd.js +0 -36829
package/esnext.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.7-dev.
|
|
3
|
-
* Wed,
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.7-dev.6e70b297.0
|
|
3
|
+
* Wed, 07 Feb 2024 10:02:44 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-7/doc/
|
|
5
5
|
*/
|
|
6
|
-
"use strict";var tt=Object.create;var ue=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var at=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of nt(e))!rt.call(i,r)&&r!==t&&ue(i,r,{get:()=>e[r],enumerable:!(n=it(e,r))||n.enumerable});return i};var ot=(i,e,t)=>(t=i!=null?tt(st(i)):{},at(e||!i||!i.__esModule?ue(t,"default",{value:i,enumerable:!0}):t,i));var O=require("@vkontakte/videoplayer-shared/esnext.cjs.js"),ct=require("uuid"),lt=require("@vkontakte/videoplayer-core/esnext.cjs.js");const ht="1.0.7-dev.200de7b.0";function Oe(i,e=1){let t="0",n="0",r="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+r},${e})`}const _="SDK_NAME",dt="SDK_NAME-controls-container",_e=()=>document.querySelector(`.${dt}`),M={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},pe={top:"flex-start",bottom:"flex-end",center:"center"},fe={start:"flex-start",end:"flex-end",center:"center"},me={start:"left",end:"right",center:"center"},Me=({target:i,props:e})=>{i.style.alignItems=pe[e?.text?.gravityVertical]??pe.center,i.style.justifyContent=fe[e?.text?.gravityHorizontal]??fe.center,i.style.textAlign=me[e?.text?.alignment]??me.start},Ve=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.color=e?.text?.color??t.textColor,i.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,i.textContent=e?.text?.value??t.textContent},Pe=({target:i,props:e,fallback:t})=>{i.style.backgroundColor=Oe(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},ke=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth}) solid ${Oe(e?.shape?.border?.color??t.borderColor,e?.shape?.border?.alpha??t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`},se=({target:i,layoutParams:e,fallback:t})=>{i.style.transform=`rotate(${-e.angle}rad)`};class re{constructor(e){this.control=e}createView(e){const t=document.createElement("div");t.classList.add(`${_}-control-container-${this.control.id}`),e(t,this.control.layoutParams);const n=(this.control.layoutParams.innerSizesDependOn??M.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:t,dependsOn:n}}setEvents(e,t){e&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",s=>{s.stopPropagation(),t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${_}-control-container-${this.control.id}`)}}const Fe=i=>{if(i.type.trim().toLowerCase()==="area")return new ut(i)};class ut extends re{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:r}=super.createView(t),s=document.createElement("button");return s.classList.add(`${_}-${this.control.id}`),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",Pe({target:s,props:this.control.props,fallback:{...M,backgroundColor:"transparent"}}),ke({target:s,props:this.control.props,fallback:{...M,borderAlpha:0},dependsOn:n}),se({target:s,layoutParams:this.control.layoutParams,fallback:M}),r.append(s),e.append(r),r}getElement(){return document.querySelector(`.${_}-${this.control.id}`)}}const $e=i=>{if(i.type.trim().toLowerCase()==="button")return new pt(i)};class pt extends re{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:r}=super.createView(t),s=document.createElement("button");s.type="button",s.classList.add(`${_}-${this.control.id}`),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";const o=document.createElement("span");return o.style.display="inline-block",o.style.whiteSpace="pre",o.style.overflow="hidden",o.style.textOverflow="ellipsis",se({target:s,layoutParams:this.control.layoutParams,fallback:M}),Pe({target:s,props:this.control.props,fallback:M}),ke({target:s,props:this.control.props,fallback:M,dependsOn:n}),Me({target:s,props:this.control.props}),Ve({target:o,props:this.control.props,fallback:M,dependsOn:n}),s.append(o),r.append(s),e.append(r),r}getElement(){return document.querySelector(`.${_}-${this.control.id}`)}}const ft=i=>{if(i.type.trim().toLowerCase()==="text")return new mt(i)};class mt extends re{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:r}=super.createView(t),s=document.createElement("div");s.classList.add(`${_}-${this.control.id}`),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";const o=document.createElement("span");return o.style.whiteSpace="pre",se({target:s,layoutParams:this.control.layoutParams,fallback:M}),Me({target:s,props:this.control.props}),Ve({target:o,props:this.control.props,fallback:M,dependsOn:n}),s.append(o),r.append(s),e.append(r),r}getElement(){return document.querySelector(`.${_}-${this.control.id}`)}}class yt{constructor(e){this.layout=e}}const gt=i=>{if(i.type.trim().toLowerCase()==="relative")return new Be(i)};class Be extends yt{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))`}}class De{constructor(e){this.container=e,this.factories=new Map,this.#a()}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.#a()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.#a()}#a(){this.controls=this.#s()}#s(){return this.container.controls?.reduce((e,t)=>{const n=t.type.trim().toLowerCase(),r=this.factories.get(n);return r?[...e,r(t)]:[...e]},[])}}const Ge=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new bt(i,e)};class bt extends De{constructor(e,t){super(e),this.rootElement=t??_e(),this.layout=new Be(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",$e),this.addControlFactory("text",ft),this.addControlFactory("area",Fe)}createView(e){const t=document.createElement("div");return t.classList.add(`${_}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const r=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(r,e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){this.isRemoved||(this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${_}-${this.container.id}`)}}function ze(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const W={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},G=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,ae=i=>G(i,W.Object),ie=i=>G(i,W.String),Ue=i=>G(i,W.Array),We=i=>G(i,W.Number),vt=i=>G(i,W.Function),ye=i=>We(i)&&!isNaN(i),z=i=>ae(i)&&Object.keys(i).length===0,He=i=>Ue(i)&&!i.length,Q=(i,e)=>ie(i)&&(e?i.trim():i).length,qe=window.navigator.userAgent.toLowerCase(),Et=/mobi/i.test(qe);qe.indexOf("android")>-1;const Ct="video_interactive",wt="videoint",St=250;class It{constructor(e){this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=Tt(e),this.resizeObserver=new ResizeObserver(ze(this.onResize,St)),this.resizeObserver.observe(this.graphWrapperElement)}onResize=e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))};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]}handleChapterChange=e=>{if(this.isReady){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}};handleManifestChange=async(e,t=[])=>{if(!We(e.graph.edit.chapters[0].x)){this.isReady=!1,this.onError?.("Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let n;try{n=await O.loadVKLangPack(this.lang,Ct,wt)}catch{console.log("Unable to load graph language pack")}const{GraphEditor:r}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new r(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:n}),this.ngEditor.on("control",({name:s,chapterId:o})=>{s==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",s=>{this.lastZoomInfo={...s}})}this.visitedChapterIds=new Set(t),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0};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(){this.hide(),this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function Tt(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 U=(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},Rt="3.1",ge={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},At={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},xt=i=>{const e=[];for(const t of i.chapters){let n;const r=[];for(const{isDefault:a,...c}of t.branches)a&&(n=c.id),r.push(c);let s=[];const o=[];for(const{fallbackStrategy:a,...c}of t.containers){const l=!!c.endTime;let f=[At];switch(a){case"await":l?f=[]:s=[];break;case"default":{const u={type:"onSuspense",action:{type:ge.default,args:{branchId:n,shouldOpenNow:!l,isDetachContainer:!0}}};l?f=[u]:s=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:ge[a],args:{}}};l?f=[u]:s=[u];break}}for(const u of c.controls)o.push({...c,controls:[{...u}],id:ct.v4(),events:f})}e.push({...t,containers:o,events:s,branches:r})}return i.metadata.version=Rt,i.metadata.updated=new Date().toISOString(),{...i,chapters:e}},Lt="3.2",Nt=i=>{if(!i.media){const{media:e,...t}=i.metadata;return{...i,metadata:{...t,version:Lt},media:e}}return i},jt="3.3",Ot=(i=[])=>({edit:{chapters:i},view:{}}),be={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},_t=i=>{const e=[],t=[];for(const n of i.chapters){const{id:r,x:s,y:o,...a}=n,c=a.containers.map(l=>({...l,controls:l.controls.map(({subtype:f,type:u,...v})=>({...v,type:f??u})),events:l.events?.length?l.events:[be]}));e.push({id:r,...a,containers:c,events:a.events?.length?a.events:[be]}),t.push({id:r,x:s,y:o})}return{...i,chapters:e,graph:Ot(t),metadata:{...i.metadata,version:jt}}},Mt=[{version:"3.0",migrate:xt},{version:"3.1",migrate:Nt},{version:"3.2",migrate:_t}],Vt=i=>Mt.reduce((e,t)=>U(e.metadata.version,t.version)?e:t.migrate(e),i),Pt=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),S=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 ve={metadata:"Object",chapters:"Array"},kt="3.0.0",Ft="3.3.0",oe=i=>{const e=U(i,kt);return e===-1?!1:e===0?!0:U(i,Ft)!==1},$t=i=>{if(!ae(i))return!1;for(const e in ve)if(!i[e]||!G(i[e],ve[e]))return!1;return oe(i.metadata.version)},Qe=i=>i.type===Pt.Text;class A{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}static Severity={RECOVERABLE:1,CRITICAL:2};static Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6}}class Ke{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 r=n.length;r>0;r--)if(n[r]===t){n.splice(r,1);break}return this}emit(e,...t){const n=this.listeners[e];return n?(n.forEach(r=>{r(...t)}),!0):!1}listenerCount(e){return(this.listeners[e]||[]).length}rawListeners(e){return this.listeners[e]}}class Bt{constructor(e){this.raf,this.fn,this.fns=[],this.addFn(e)}addFn=(e,t=!1)=>{vt(e)&&(this.fns.push(e),t&&this.updateFn())};removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==e),t&&this.updateFn()};updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};requestAnimation=()=>{this.raf||this.forceRequestAnimation()};cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0};release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Dt{loaders;constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return Gt(...this.loaders[e])(t)}}function Gt(...i){return async function(t){const n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Y(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function ne({actions:i,errors:e,chapterId:t,...n}){if(t){const r=i.getManifest(),s=i.getChapter(r.chapters,t);if(s){const o=i.getMedia(r.media,s.videoId),a=i.getGraph(r.graph,s.id);return o?{...n,actions:i,errors:e,result:{chapter:s,media:o,graph:a}}:{...n,errors:Y(e,ne.name,"Could not find media"),actions:i}}}return{...n,errors:Y(e,ne.name,"Could not find chapter"),actions:i}}class Ee{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 r=0,s=n.length;r<s;r++)if(n[r].callback===t){n.splice(r,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const n=this.listeners[e.type].slice();for(let r=0,s=n.length;r<s;r++){const o=n[r];try{o.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}}class Xe extends Ee{constructor(){super(),this.listeners||Ee.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 zt{constructor(){Object.defineProperty(this,"signal",{value:new Xe,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?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>"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(zt.prototype[Symbol.toStringTag]="AbortController",Xe.prototype[Symbol.toStringTag]="AbortSignal");function Ze(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 Ut(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!Ze({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||r)&&(s=function(l,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const v=new t(l,f);return u&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),v},s.prototype=t.prototype);const o=e;return{fetch:(c,l)=>{const f=s&&s.prototype.isPrototypeOf(c)?c.signal:l?l.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch{u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const v=new Promise((E,x)=>{f.addEventListener("abort",()=>x(u),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([v,o(c,l)])}return o(c,l)},Request:s}}const ce=Ze({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ye=ce?Ut({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ce=ce?Ye.fetch:window.fetch;ce?Ye.Request:window.Request;const Wt=async i=>{try{let e,t;if(ae(i))e=i;else if(ie(i)){t=new URL(i).href;const r=await Ce(t);if(!r.ok)return{};e=await r.json()}else return{};if(!$t(e))return{};const n=e.metadata.media;if(ie(n)&&!e.media)try{let r;t?r=new URL(n,t).href:(r=new URL(n).href,t=r);const s=await Ce(r);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return Kt(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function Ht(i){const{manifest:e,manifestURL:t}=await Wt(i),n=Vt(e);return n.media=qt(n.media,t),delete n.metadata.media,n}function ee(i,e){return i.find(t=>t.id===e)}function we(i,e){return i.edit?.chapters?i.edit.chapters.find(t=>t.id===e):i.view?.chapters?i.view.chapters.find(t=>t.id===e):void 0}function Se(i,e){return i.videos.find(t=>t.id===e)}function qt(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{const r=Qt(n.url,e);return{...n,url:r||n.url}})}))}}function Qt(i,e){try{return new URL(i,e).href}catch{return""}}function Kt(i){return U(i,"3.2.0")>=0}class Je extends Dt{constructor(e,t){super(e),this.onError=t,this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this}async setManifest(e){this.release();const t=await this.exec("manifestLoaders",{actions:{addErrorMessage:Y},result:null,errors:null,source:e});t.errors&&this.errorHandler(t.errors);const n=await Ht(t.result??e);return this.manifest=n,this}async setInitial(){return this.setNext()}async setNext(e=this.manifest.metadata.initChapterId){const t=await this.exec("chapterLoaders",ne({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:we,getChapter:ee,getMedia:Se,getByBranches:this.getByBranches.bind(this),addErrorMessage:Y},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=ee(this.manifest.chapters,e);if(t){const n=Se(this.manifest.media,t.videoId),r=we(this.manifest.graph,t.id);if(n)return{chapter:t,media:n,graph:r}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{const t=ee(this.manifest.chapters,e);return this.getByBranches(t?.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const r=this.getByChapterId(n.chapterId);return r&&t.push(r),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const y={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},Ie={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},R={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Xt(){const i=new Map;function e({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...o}){const a=i.get(r),c={...o};return a?a[s]=c:i.set(r,{[s]:c}),{listId:r,itemId:s,...o}}function t(r,s){const o=i.get(r);if(o){if(s)return o[s]?.player.destroy(),o[s]?.container.remove(),o[s]?.subscription.unsubscribe(),delete o[s],Object.keys(o).length||i.delete(r),!0;for(const a of Object.values(o))a.player.destroy(),a.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(const r of i)t(r[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:n}}function Te(i,e=[]){let t={},n;const r=!e.length;for(const s of i.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(r||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(r||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(r||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(r||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break}return{sources:t,thumbUrl:n,title:i.title??""}}const K=(i,e)=>{const t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))},Zt=i=>{const e=i.variants.find(t=>t.payload?.type==="vk");if(e&&"payload"in e){const[t,n]=e.payload.id.split("_");return[t,n]}return[]},Z={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Yt=2;function Jt(i){const e=Xt();let t,n;const r=new Ke;let s={},o=!1,a=null,c=!1,l;i&&f(i);function f(d){a=d}function u(d,g,m){if(!a)throw Error("need to set interactive controller");const C=(e.map.get(d)??{})[g];if(C){s={chapterId:m,listId:d,itemId:g,...C};const b=s.player;n=b.info.currentQuality$.subscribe(w=>{if(!(!w||!b.info.position$.getValue())){t=w;for(const N of e.map)Object.values(N[1]).forEach(({player:j})=>{b.info.isAutoQualityEnabled$.getValue()||K(j,w)})}}),C.container.remove(),o=!1,a.setPlayer(C.player),c||(a.init(),c=!0),r.emit(Z.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function v(d,g,m){if(!a)throw Error("need to set interactive controller");if(z(s)||d!==s.itemId)return;if(m>=0&&!o){const C=a.getChapterBranches();o=!0;const b=new Set;for(const w of C)b.has(w.media.id)||(await x({media:w.media,chapterId:w.chapter.id,setAsActive:!1,title:w.chapter.label}),b.add(w.media.id))}}async function E({chapter:{id:d},media:g}){if(z(s))return;n?.unsubscribe();const m=s.player.info.muted$.getValue(),I=s.player.info.currentQuality$.getValue(),C=s.player.info.isAutoQualityEnabled$.getValue(),b=s.player.info.volume$.getValue(),w=s.player.info.currentPlaybackRate$.getValue(),N=!C;let j=!1;for(const L of e.map)if(L[0]===g.id){const H=Object.keys(L[1]);for(const k of H)k===s.itemId?(H.length<Yt||(j=!0),e.removePlayer(L[0],k)):(j=!0,u(L[0],k,d),N?K(s.player,I):s.player.setAutoQuality(!0),s.player.setVolume(b),s.player.setMuted(m),s.player.setPlaybackRate(w))}else e.removePlayer(L[0]);j||(await x({media:g,chapterId:d,setAsActive:!0,playbackRate:w}),N?K(s.player,I):s.player.setAutoQuality(!0),s.player.setVolume(b),s.player.setMuted(m))}async function x({media:d,chapterId:g,prefetch:m=!0,setAsActive:I=!0,autoplay:C=!1,preferredExt:b,title:w,playbackRate:N}){const j=Math.random().toString(),L=document.createElement("div");l.append(L);const H=s?.player?.info.isAutoQualityEnabled$.getValue();let k;if(a?.options?.vkVideoLoader){const q=Zt(d);q.length&&(k=await a.options.vkVideoLoader(...q))}const he={container:L,...k?.videos?.[0]||{sources:Te(d,b).sources},title:w},F=new lt.Player;F.initVideo(he);const et=L.lastChild,de=new O.Subscription;de.add(F.info.position$.subscribe(function(q){v(j,F.info.duration$.getValue(),q)})).add(F.events.canplay$.subscribe(function(){H||K(F,t),N&&F.setPlaybackRate(N)})),et&&(L.style.display="none",L.classList.add(g));const $=e.createPlayer({listId:d.id,itemId:j,player:F,container:L,sources:Te(d,b).sources,config:he,subscription:de});return I&&u(d.id,$.itemId,g),C&&$.player.play(),m&&!C&&$.player.prepare(),r.emit(Z.playerCreated,$.player),{player:$.player,config:$.config}}function P(){h(),a=null}function h(){a?.off(y.chapterChanged,E),e.removeAll(),s={},c=!1,o=!1}async function p({source:d,initialChapter:g,container:m}){if(!a)throw Error("need to set interactive controller");await a.setManifest(d),h(),l=m;const{media:I,chapter:C}=await a.setChapter({chapterId:g});if(I){a.on(y.chapterChanged,E);const{player:b,config:w}=await x({media:I,chapterId:C.id,title:C.label});return r.emit(Z.initiated,{container:m,media:I,chapterId:C.id}),{player:b,config:w}}else console.error("not found")}return{...e,on:r.on.bind(r),off:r.off.bind(r),init:p,setInteractiveController:f,createPlayer:x,removeAll:P,getActivePlayer:function(){return s}}}const ei=3e3,ti=()=>{let i=[],e=null;return{setPlayer:o=>{e=o},setContainers:o=>{i=o},deleteContainer:o=>{i=i.filter(a=>a.id!==o)},getNextInteractiveTime:(o=ei)=>{if(!i.length||e===null)return null;let a=-1,c=!1;const l=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-o;if(u<=l&&(l<=f.endTime||f.endTime===null)){c=!0;break}l<u&&(a=a===-1?u:Math.min(a,u))}return!c&&a!==-1?a:null}}},B=ti(),T=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),le=i=>Ue(i)&&!He(i),ii=i=>He(i.branches)||i.order==="end",ni=(i,e)=>{const t=i*1e3;return le(e.controls)&&t<(e.startTime??0)},Re=(i,e)=>{const t=i*1e3;return le(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)},J=i=>i.some(e=>e.action.type==="expect"),Ae=i=>i.find(e=>e.action.type==="expect"),si=i=>i?.length===1,ri=i=>si(i)&&Qe(i[0]),ai=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i({...n[e],...t[e]}),oi=(i=[])=>i.reduce((e,t,n)=>{const r=(t?.controls??[]).filter(s=>!Qe(s));if(le(r)){const s=[t.startTime??0,t.endTime??1/0],o=t.id;if(!n)e.push({subjects:[o],range:s});else{const a=[];let c=-1/0,l=1/0,f=[];const u=[];for(let v=0;v<e.length;v++){const E=e[v];if(u.push(...E.subjects),E.range[0]<l&&(l=E.range[0]),E.range[1]>c&&(c=E.range[1]),E.range[0]<=s[0]&&E.range[1]>=s[1])return e[v].subjects.push(o),e;s[0]>=E.range[0]&&s[0]<=E.range[1]&&(a.push(v),f=f.concat(E.subjects),s[0]=E.range[0]),s[1]>=E.range[0]&&s[1]<=E.range[1]&&(a.push(v),f=f.concat(E.subjects),s[1]=E.range[1])}if(u.push(o),s[0]<=l&&s[1]>=c)return[{subjects:u,range:s}];a.length&&a.reverse().forEach(v=>{e.splice(v,1)}),e.push({subjects:f.concat([o]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),ci=(i,e)=>J(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&J(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class li{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:o,ignoreContainerEvent:a,permanentTextControls:c}){this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new O.Subscription,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=c&&ri(t.container.controls),this.globalEventEmitter=o,this.gameState=T.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))}hide=()=>{setTimeout(()=>{this.gameState!==T.end&&(J(this.container.container.events)&&this.gameState===T.afterInteractive||this.selectBranches.state.isExpect||(this.container.hide?.(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})))})};show=()=>{if(this.gameState===T.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!0,isFirst:!1});else{const t=ai({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})),(this.gameState===T.end||this.gameState===T.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})),B.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===T.end});this.container.createView(t),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!0,isFirst:!0})}};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=J(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.visibility,visibility:!1})}onEndOfVideo=()=>{this.gameState=T.end,this.selectContainerEvent(!0)};whilePlaying=()=>{if(this.player.experimental.element$.getValue()?.readyState<1||[T.destroyed,T.removed].includes(this.gameState)&&!this.isPermanentText)return;const t=this.player.getExactTime();if(ni(t,this.container.container))this.gameState!==T.beforeInteractive&&(this.gameState=T.beforeInteractive,this.onBeforeStartTime());else if(Re(t,this.container.container))this.gameState!==T.interactive&&(this.gameState=T.interactive,this.onStartTime());else if(this.gameState!==T.afterInteractive){const s=this.gameState;this.gameState=T.afterInteractive,s===T.interactive&&this.onEndTime()}else this.gameState!==T.destroyed&&this.removeView();const n=Re(t,this.container.container),r=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[];this.container.onProgress?.(t,n),this.globalEventEmitter.emit(y.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:r,currentTime:t,isInteractiveTime:n})};reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=T.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:R.containerRemoved,visibility:!1}),this.gameState=T.removed}destroy(){this.reset(),this.removeView(),this.gameState=T.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id}),B.deleteContainer(this.container.container.id)}}function hi(){const i={};function e(){for(const a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a];return!0}function t(a){const c={};for(const l in i)+l<=a&&(c[l]=i[l]);return c}function n(a){const c={};for(const l in i)+l>=a&&(c[l]=i[l]);return c}function r({timestamp:a,priority:c,initiator:l}){if(ye(a)){const f=i[a]??null;if(f&&Q(c,!0)){let u={};const v=f[c];return v&&(u={...u,...v}),u=z(u)?null:u,u&&Q(l,!0)?u[l]??null:u}return f}return null}function s({timestamp:a,priority:c,initiator:l}){if(ye(a))if(i[a]){if(Q(c,!0))if(i[a][c]){if(Q(l,!0))if(i[a][c][l]){if(delete i[a][c][l],!z(i[a][c]))return!0}else return!1;if(delete i[a][c],!z(i[a]))return!0}else return!1;return delete i[a]}else return!1}function o({timestamp:a,priority:c,initiator:l,...f}){i[a]?.[c]?.[l]?i[a][c][l].push({...f}):i[a]?.[c]?i[a][c]={...i[a][c],[l]:[{...f}]}:i[a]?i[a]={...i[a],[c]:{[l]:[{...f}]}}:i[a]={[c]:{[l]:[{...f}]}}}return{map:i,remove:s,add:o,removeAll:e,get:r,getLte:t,getGte:n}}const di=[S.expect,S.setNextBranch],ui=1/0;function xe(i){let e=i,t;const n=pi(),r=new hi;let s;const o=()=>{u(),P()},a=h=>{r.add.call(void 0,h),v()},c=(h=[])=>{for(const p of h)if(p.action(),di.includes(p.actionType))break},l=h=>{if(!n.isReady(h))return;const p=X(r.get({timestamp:h,priority:"control"})??{}),d=X(r.get({timestamp:h,priority:"container"})??{}),g=X(r.get({timestamp:h,priority:"chapter"})??{});c([...p,...d,...g])},f=()=>{c([...X(r.get({timestamp:1/0,priority:"chapter"})??{})])},u=()=>{t&&(s?.unsubscribe(),t=void 0)},v=()=>{t||(t=()=>setTimeout(()=>{l(1/0)}),s=e.events.ended$.subscribe(t))},E=h=>{u(),e=h},x=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),r.remove(h)},P=()=>{n.release(),r.removeAll()};return{setPlayer:E,add:a,remove:x,exec:l,execEndOfVideo:f,listen:v,unlisten:u,release:o,containersEventsCallState:n}}function pi(){const i=new Map;return{setCalled:({timestamp:o,id:a})=>{const c=i.get(o);c&&c[a]!==void 0&&(c[a]=!0)},setData:(o=[])=>{for(const a of o){const c=a.endTime??ui,l=i.get(c)??{};i.set(c,{...l,[a.id]:!1})}},resetCalled:o=>{const a=i.get(o);if(a)for(const c in a)a[c]=!1},isReady:o=>{const a=i.get(o);return a?!Object.values(a).some(c=>!c):!0},release:()=>i.clear()}}function X(i){return Object.values(i).flat().sort(e=>e.actionType===S.expect?-1:1)}const fi=(i,e)=>{const{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:r,clientWidth:s}=e.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};const o=t/n,a=r/s;let c,l;return a>o?(l=s,c=s*o):a<o?(l=r/o,c=r):(l=s,c=r),{videoContentWidth:l,videoContentHeight:c}},mi=250;function yi(i){let e=()=>{};const t=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){const{parentElement:c,player:l}=i();if(c&&l){const{videoContentWidth:f,videoContentHeight:u}=fi(c,l);c.style.setProperty("--interactive-content-width",`${f}px`),c.style.setProperty("--interactive-content-height",`${u}px`),c.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function r(){const{parentElement:a}=i();a.removeAttribute("style")}const s=ze(a=>{const{fns:c=[]}=i();n(a);for(const l of c)l()},mi);function o(){e=void 0,t.disconnect(),r()}return{resizeObserver:t,calc:()=>{e()},release:o}}class gi{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 bi=i=>Math.floor(Math.random()*i),vi=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},Ei=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},Ci=i=>{const e=i.length,t=bi(e);return i[t]},Le=1,wi=i=>{let e=0;for(let n=0;n<i.length;++n)e+=i[n].weight??Le;const t=Math.random()*e;e=0;for(let n=0;n<i.length-1;++n)if(e+=i[n].weight??Le,e>=t)return i[n];return i[i.length-1]},Ne=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),te=(i,e=!1)=>({...i,args:e?{...i.args,...Ne}:{...Ne,...i.args}}),je=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},o=({action:h,controlType:p,controlId:d,containerId:g,branches:m=[],onEvent:I,isEOV:C=()=>!1})=>{const b=te(h,C()),w={timestamp:1/0,priority:"control",initiator:d,actionType:b.type},N=i.emit.bind(i,y.interactives,{subjectId:d,subjectType:p,subjectName:"control",type:R.actionChoice,actionType:h.type,payload:{containerId:g,...b.args}});switch(b.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{const j=m.find(L=>L.id===b.args.branchId);if(!j)return;I(b.args.isDetachContainer,v.bind(null,{subjectId:d,subjectName:"control"})),N(),b.args.shouldOpenNow?x({subjectId:d,subjectName:"control",subjectType:p,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}}):(t.add({...w,action:x.bind(null,{subjectId:d,subjectName:"control",subjectType:p,action:b,payload:{chapterId:j.chapterId,autoSelect:!1}})}),n?.());return}case S.continuePlayback.trim().toLowerCase():{I(b.args.isDetachContainer,v.bind(null,{subjectId:d,subjectName:"control"})),N(),b.args.shouldOpenNow?E({subjectId:d,subjectName:"control",subjectType:p,action:h}):t.add({...w,action:E.bind(null,{subjectId:d,subjectName:"control",subjectType:p,action:h})});return}case S.openURI.trim().toLowerCase():{I(b.args.isDetachContainer,v.bind(null,{subjectId:d,subjectName:"control"})),N(),b.args.shouldOpenNow?P({subjectId:d,subjectName:"control",subjectType:p,action:b,payload:{URI:h.args.uri}}):(t.add({...w,action:P.bind(null,{subjectId:d,subjectName:"control",subjectType:p,action:b,payload:{URI:h.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(y.errors,new A(A.Severity.RECOVERABLE,A.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},a=({action:h,container:{id:p,endTime:d},branches:g=[],isEOV:m=!1,autoSelected:I=!1})=>{const C=te(h,m),b={timestamp:!C.args.shouldOpenNow||m?1/0:d,priority:"container",initiator:p,actionType:C.type},w=i.emit.bind(i,y.interactives,{subjectId:p,subjectName:"container",type:R.actionChoice,actionType:C.type,payload:C.args});switch(C.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{const N=g.find(j=>j.id===C.args.branchId);if(!N)return;w(),t.add({...b,action:x.bind(null,{subjectId:p,subjectName:"container",action:C,payload:{chapterId:N.chapterId,autoSelect:I}})}),n?.();return}case S.setMaxWeightBranch.trim().toLowerCase():return;case S.setMinWeightBranch.trim().toLowerCase():return;case S.setRandomBranch.trim().toLowerCase():return;case S.setWeightlessRandomBranch.trim().toLowerCase():return;case S.continuePlayback.trim().toLowerCase():{w(),t.add({...b,action:E.bind(null,{subjectId:p,subjectName:"container",action:C})});return}case S.openURI.trim().toLowerCase():{w(),t.add({...b,action:P.bind(null,{subjectId:p,subjectName:"container",action:C,payload:{URI:h.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(y.errors,new A(A.Severity.RECOVERABLE,A.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:h,branches:p,isEOV:d=!1}){const g=Ae(h.events);if(g){const m=te(g.action,d);i.emit(y.interactives,{subjectId:h.id,subjectName:"container",type:R.actionChoice,actionType:m.type,payload:m.args}),t.add({timestamp:d?1/0:h.endTime,priority:"container",initiator:h.id,actionType:S.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),r.isExpect=!0}else for(const m of h.events)a({action:m.action,container:h,branches:p,isEOV:d})}const l=({chapterId:h,action:p,branches:d=[]})=>{const g=i.emit.bind(i,y.interactives,{subjectId:h,subjectName:"chapter",type:R.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case S.setNextBranch.trim().toLowerCase():{const m=d.find(I=>I.id===p.args.branchId);return m?.chapterId?(g(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case S.setWeightlessRandomBranch.trim().toLowerCase():{const m=Ci(d);return m?.chapterId?(g(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case S.setRandomBranch.trim().toLowerCase():{const m=wi(d);return m?.chapterId?(g(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case S.setMaxWeightBranch.trim().toLowerCase():{const m=Ei(d);return m?.chapterId?(g(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case S.setMinWeightBranch.trim().toLowerCase():{const m=vi(d);return m?.chapterId?(g(),x.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case S.continuePlayback.trim().toLowerCase():return g(),E.bind(null,{subjectId:h,subjectName:"chapter",action:p});case S.openURI.trim().toLowerCase():return g(),P.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),i.emit(y.errors,new A(A.Severity.RECOVERABLE,A.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){const p=Ae(h.events);if(p){if(ii(h))return;i.emit(y.interactives,{subjectId:h.id,subjectName:"chapter",type:R.actionChoice,actionType:p.action.type,payload:p.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:S.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events.forEach(d=>{const g=l({chapterId:h.id,action:d.action,branches:h.branches});g&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:d.action.type,action:g})})}const u=({subjectId:h,subjectName:p,action:d})=>{e.pause(),i.emit(y.interactives,{subjectId:h,subjectName:p,type:R.actionExecution,actionType:d?.type??S.expect})},v=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(y.interactives,{subjectId:h,subjectName:p,type:R.actionExecution,actionType:"after-expect"})},E=({subjectId:h,subjectName:p,subjectType:d,action:g})=>{i.emit(y.interactives,{subjectId:h,subjectName:p,subjectType:d,type:R.actionExecution,actionType:g.type})},x=({subjectId:h,subjectName:p,subjectType:d,action:g,payload:m})=>{m.behaviour="change-chapter",i.emit(y.interactives,{subjectId:h,subjectName:p,subjectType:d,type:R.actionExecution,actionType:g.type,payload:m})},P=({subjectId:h,subjectName:p,subjectType:d,action:g,payload:m})=>{if(!m.URI)return;const I=window.open(m.URI,"_blank","noopener,noreferrer");I&&(I.opener=null),i.emit(y.interactives,{subjectId:h,subjectName:p,subjectType:d,type:R.actionExecution,actionType:g.type})};return{onControlEvent:o,onContainerEvent:a,onChapterEvent:l,onExpectEvent:u,expectEventHandler:v,setManifestChapterEvents:f,setManifestContainerEvents:c,stopExpect:s,state:r}};class D{constructor(e,t,n,r){this.target=e,this.type=t,this.listener=n,this.options=D.#a(e,r),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}static#a(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{const n=new Set(["passive","capture"]),r=Object.keys(t).filter(o=>!n.has(o));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),D.#c(e)?t:t.capture||!1}}static#s=void 0;static#c(e){let t=D.#s;if(t===void 0){t=!1;try{const n={},r={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);const s=()=>{};e.addEventListener("test",s,n),e.removeEventListener("test",s,n)}catch{t=!1}D.#s=t}return t||!1}}class Si{constructor(){this.bindingMap=new gi}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,r){if(!this.bindingMap)return;const s=new D(e,t,n,r);this.bindingMap.push(t,s)}listenOnce(e,t,n,r){const s=o=>{this.unlisten(e,t,s),n(o)};this.listen(e,t,s,r)}unlisten(e,t,n){if(!this.bindingMap)return;const r=this.bindingMap.get(t)||[];for(const s of r)s.target===e&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;const e=this.bindingMap.getAll();for(const t of e)t.unlisten();this.bindingMap.clear()}}class Ii{rootElement;canvasImgSrc;_prevSizeId=0;constructor(){this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){const e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;const t=e.data,n=t.length;for(let r=3;r<n;r+=40)if(t[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(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){const n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){const e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}}class Ti{lastFrameCanvas;endOffsetMs;currentChapter;currentVideoDurationMs=1/0;rootElement;_containerTimeFrameShouldReceived=!1;_endTimeFrameReceived=!1;_shouldCallSkip=!1;_callbacks;constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
"use strict";var nt=Object.create;var fe=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var ct=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of rt(e))!ot.call(i,r)&&r!==t&&fe(i,r,{get:()=>e[r],enumerable:!(n=st(e,r))||n.enumerable});return i};var lt=(i,e,t)=>(t=i!=null?nt(at(i)):{},ct(e||!i||!i.__esModule?fe(t,"default",{value:i,enumerable:!0}):t,i));var L=require("@vkontakte/videoplayer-shared/esnext.cjs.js"),ht=require("uuid"),dt=require("@vkontakte/videoplayer-core/esnext.cjs.js");const ut="1.0.7-dev.6e70b297.0";function Ve(i,e=1){let t="0",n="0",r="0";return i.length===4?(t="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(t="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+t},${+n},${+r},${e})`}const _="SDK_NAME",pt="SDK_NAME-controls-container",Me=()=>document.querySelector(`.${pt}`),V={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},me={top:"flex-start",bottom:"flex-end",center:"center"},ye={start:"flex-start",end:"flex-end",center:"center"},ge={start:"left",end:"right",center:"center"},Pe=({target:i,props:e})=>{i.style.alignItems=me[e?.text?.gravityVertical]??me.center,i.style.justifyContent=ye[e?.text?.gravityHorizontal]??ye.center,i.style.textAlign=ge[e?.text?.alignment]??ge.start},ke=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.color=e?.text?.color??t.textColor,i.style.fontSize=`calc(${n.height} * ${e?.text?.size??t.textSize})`,i.textContent=e?.text?.value??t.textContent},Fe=({target:i,props:e,fallback:t})=>{i.style.backgroundColor=Ve(e?.background?.color??t.backgroundColor,e?.background?.alpha??t.backgroundAlpha)},$e=({target:i,props:e,fallback:t,dependsOn:n})=>{i.style.border=`calc(${n.height} * ${e?.shape?.border?.width??t.borderWidth}) solid ${Ve(e?.shape?.border?.color??t.borderColor,e?.shape?.border?.alpha??t.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${e?.shape?.roundCorners??t.roundCorners})`},se=({target:i,layoutParams:e,fallback:t})=>{i.style.transform=`rotate(${-e.angle}rad)`};class re{constructor(e){this.control=e}createView(e){const t=document.createElement("div");t.classList.add(`${_}-control-container-${this.control.id}`),e(t,this.control.layoutParams);const n=(this.control.layoutParams.innerSizesDependOn??V.innerSizesDependOn)==="self"?{height:t.style.height,width:t.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:t,dependsOn:n}}setEvents(e,t){e&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":e.addEventListener("click",s=>{s.stopPropagation(),t&&t({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${_}-control-container-${this.control.id}`)}}const Be=i=>{if(i.type.trim().toLowerCase()==="area")return new ft(i)};class ft extends re{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:r}=super.createView(t),s=document.createElement("button");return s.classList.add(`${_}-${this.control.id}`),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",Fe({target:s,props:this.control.props,fallback:{...V,backgroundColor:"transparent"}}),$e({target:s,props:this.control.props,fallback:{...V,borderAlpha:0},dependsOn:n}),se({target:s,layoutParams:this.control.layoutParams,fallback:V}),r.append(s),e.append(r),r}getElement(){return document.querySelector(`.${_}-${this.control.id}`)}}const De=i=>{if(i.type.trim().toLowerCase()==="button")return new mt(i)};class mt extends re{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:r}=super.createView(t),s=document.createElement("button");s.type="button",s.classList.add(`${_}-${this.control.id}`),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";const o=document.createElement("span");return o.style.display="inline-block",o.style.whiteSpace="pre",o.style.overflow="hidden",o.style.textOverflow="ellipsis",se({target:s,layoutParams:this.control.layoutParams,fallback:V}),Fe({target:s,props:this.control.props,fallback:V}),$e({target:s,props:this.control.props,fallback:V,dependsOn:n}),Pe({target:s,props:this.control.props}),ke({target:o,props:this.control.props,fallback:V,dependsOn:n}),s.append(o),r.append(s),e.append(r),r}getElement(){return document.querySelector(`.${_}-${this.control.id}`)}}const yt=i=>{if(i.type.trim().toLowerCase()==="text")return new gt(i)};class gt extends re{constructor(e){super(e)}createView({parent:e,layoutFn:t}){const{dependsOn:n,controlContainerEl:r}=super.createView(t),s=document.createElement("div");s.classList.add(`${_}-${this.control.id}`),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";const o=document.createElement("span");return o.style.whiteSpace="pre",se({target:s,layoutParams:this.control.layoutParams,fallback:V}),Pe({target:s,props:this.control.props}),ke({target:o,props:this.control.props,fallback:V,dependsOn:n}),s.append(o),r.append(s),e.append(r),r}getElement(){return document.querySelector(`.${_}-${this.control.id}`)}}class vt{constructor(e){this.layout=e}}const bt=i=>{if(i.type.trim().toLowerCase()==="relative")return new We(i)};class We extends vt{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))`}}class Ge{constructor(e){this.container=e,this.factories=new Map,this.#a()}addControlFactory(e,t){this.factories.set(e.trim().toLowerCase(),t),this.#a()}removeControlFactory(e){this.factories.delete(e.trim().toLowerCase()),this.#a()}#a(){this.controls=this.#s()}#s(){return this.container.controls?.reduce((e,t)=>{const n=t.type.trim().toLowerCase(),r=this.factories.get(n);return r?[...e,r(t)]:[...e]},[])}}const ze=(i,e)=>{if(i.type.trim().toLowerCase()==="choice")return new Ct(i,e)};class Ct extends Ge{constructor(e,t){super(e),this.rootElement=t??Me(),this.layout=new We(this.container.layout),this.isRemoved=!1,this.addControlFactory("button",De),this.addControlFactory("text",yt),this.addControlFactory("area",Be)}createView(e){const t=document.createElement("div");return t.classList.add(`${_}-${this.container.id}`),this.layout.setContainerLayout(t),this.controls.forEach(n=>{const r=n.createView({parent:t,layoutFn:this.layout.setControlLayout});n.setEvents(r,e)}),this.rootElement.append(t),this.isRemoved=!1,t}hide(){const e=this.getElement();e&&(e.style.visibility="hidden")}show(){const e=this.getElement();e&&(e.style.visibility="visible")}removeView(){this.isRemoved||(this.getElement()?.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${_}-${this.container.id}`)}}function Ue(i,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>i(...n),e)}}const U={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},W=(i,e)=>Object.prototype.toString.call(i)===`[object ${e}]`,ae=i=>W(i,U.Object),ie=i=>W(i,U.String),oe=i=>W(i,U.Array),He=i=>W(i,U.Number),Et=i=>W(i,U.Function),ve=i=>He(i)&&!isNaN(i),G=i=>ae(i)&&Object.keys(i).length===0,ce=i=>oe(i)&&!i.length,Q=(i,e)=>ie(i)&&(e?i.trim():i).length,qe=window.navigator.userAgent.toLowerCase(),wt=/mobi/i.test(qe);qe.indexOf("android")>-1;const It="video_interactive",St="videoint",Tt=250;class xt{constructor(e){this.init(e)}init({root:e,onOpenPreviewClick:t,onError:n,lang:r,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=t,this.onError=n,this.lang=r??"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=Rt(e),this.resizeObserver=new ResizeObserver(Ue(this.onResize,Tt)),this.resizeObserver.observe(this.graphWrapperElement)}onResize=e=>{this.isReady&&(!e[0].contentRect.width||!e[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:e[0].contentRect.width,height:e[0].contentRect.height}))};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]}handleChapterChange=e=>{if(this.isReady){if(this.isHidden||this.hide(),!e?.id){this.onError?.("Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(e.id),this.ngEditor.selectChapter(e.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=e.id,this.lastZoomInfo=void 0}};handleManifestChange=async(e,t=[])=>{if(!He(e.graph.edit.chapters[0].x)){this.isReady=!1,this.onError?.("Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let n;try{n=await L.loadVKLangPack(this.lang,It,St)}catch{console.log("Unable to load graph language pack")}const{GraphEditor:r}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new r(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:n}),this.ngEditor.on("control",({name:s,chapterId:o})=>{s==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",s=>{this.lastZoomInfo={...s}})}this.visitedChapterIds=new Set(t),e.metadata.id!==this.currentManifestId?(this.ngEditor.update(e),this.currentManifestId=e.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0};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(){this.hide(),this.resizeObserver.disconnect(),this.ngEditor?.setVisitedChapters([]),this.onOpenPreviewClick=void 0,this.ngEditor?.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function Rt(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 z=(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},At="3.1",be={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Lt={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},jt=i=>{const e=[];for(const t of i.chapters){let n;const r=[];for(const{isDefault:a,...c}of t.branches)a&&(n=c.id),r.push(c);let s=[];const o=[];for(const{fallbackStrategy:a,...c}of t.containers){const l=!!c.endTime;let f=[Lt];switch(a){case"await":l?f=[]:s=[];break;case"default":{const u={type:"onSuspense",action:{type:be.default,args:{branchId:n,shouldOpenNow:!l,isDetachContainer:!0}}};l?f=[u]:s=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:be[a],args:{}}};l?f=[u]:s=[u];break}}for(const u of c.controls)o.push({...c,controls:[{...u}],id:ht.v4(),events:f})}e.push({...t,containers:o,events:s,branches:r})}return i.metadata.version=At,i.metadata.updated=new Date().toISOString(),{...i,chapters:e}},Nt="3.2",Ot=i=>{if(!i.media){const{media:e,...t}=i.metadata;return{...i,metadata:{...t,version:Nt},media:e}}return i},_t="3.3",Vt=(i=[])=>({edit:{chapters:i},view:{}}),Ce={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Mt=i=>{const e=[],t=[];for(const n of i.chapters){const{id:r,x:s,y:o,...a}=n,c=a.containers.map(l=>({...l,controls:l.controls.map(({subtype:f,type:u,...b})=>({...b,type:f??u})),events:l.events?.length?l.events:[Ce]}));e.push({id:r,...a,containers:c,events:a.events?.length?a.events:[Ce]}),t.push({id:r,x:s,y:o})}return{...i,chapters:e,graph:Vt(t),metadata:{...i.metadata,version:_t}}},Pt=[{version:"3.0",migrate:jt},{version:"3.1",migrate:Ot},{version:"3.2",migrate:Mt}],kt=i=>Pt.reduce((e,t)=>z(e.metadata.version,t.version)?e:t.migrate(e),i),Ft=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),I=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 Ee={metadata:"Object",chapters:"Array"},$t="3.0.0",Bt="3.3.0",le=i=>{const e=z(i,$t);return e===-1?!1:e===0?!0:z(i,Bt)!==1},Dt=i=>{if(!ae(i))return!1;for(const e in Ee)if(!i[e]||!W(i[e],Ee[e]))return!1;return le(i.metadata.version)},Qe=i=>i.type===Ft.Text;class R{constructor(e,t,...n){this.severity=e,this.category=t,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}static Severity={RECOVERABLE:1,CRITICAL:2};static Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6}}class Ke{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 r=n.length;r>0;r--)if(n[r]===t){n.splice(r,1);break}return this}emit(e,...t){const n=this.listeners[e];return n?(n.forEach(r=>{r(...t)}),!0):!1}listenerCount(e){return(this.listeners[e]||[]).length}rawListeners(e){return this.listeners[e]}}class Wt{constructor(e){this.raf,this.fn,this.fns=[],this.addFn(e)}addFn=(e,t=!1)=>{Et(e)&&(this.fns.push(e),t&&this.updateFn())};removeFn=(e,t=!1)=>{this.fns=this.fns.filter(n=>n!==e),t&&this.updateFn()};updateFn=()=>{this.fn=()=>{this.fns.forEach(e=>e()),this.raf&&this.forceRequestAnimation()}};forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))};requestAnimation=()=>{this.raf||this.forceRequestAnimation()};cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0};release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Gt{loaders;constructor(e){this.loaders={chapterLoaders:e?.chapterLoaders??[],manifestLoaders:e?.manifestLoaders??[]}}async exec(e,t){return zt(...this.loaders[e])(t)}}function zt(...i){return async function(t){const n=[...i];for(;n.length>0;)t=await n.shift()(t);return t}}function Y(i,e,t){return i?{...i,[e]:i[e]?[t,...i[e]]:[t]}:{[e]:[t]}}function ne({actions:i,errors:e,chapterId:t,...n}){if(t){const r=i.getManifest(),s=i.getChapter(r.chapters,t);if(s){const o=i.getMedia(r.media,s.videoId),a=i.getGraph(r.graph,s.id);return o?{...n,actions:i,errors:e,result:{chapter:s,media:o,graph:a}}:{...n,errors:Y(e,ne.name,"Could not find media"),actions:i}}}return{...n,errors:Y(e,ne.name,"Could not find chapter"),actions:i}}class we{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 r=0,s=n.length;r<s;r++)if(n[r].callback===t){n.splice(r,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const n=this.listeners[e.type].slice();for(let r=0,s=n.length;r<s;r++){const o=n[r];try{o.callback.call(this,e)}catch(a){Promise.resolve().then(()=>{throw a})}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}}class Xe extends we{constructor(){super(),this.listeners||we.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 Ut{constructor(){Object.defineProperty(this,"signal",{value:new Xe,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?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>"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(Ut.prototype[Symbol.toStringTag]="AbortController",Xe.prototype[Symbol.toStringTag]="AbortSignal");function Ze(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 Ht(i){typeof i=="function"&&(i={fetch:i});const{fetch:e,Request:t=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!Ze({fetch:e,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||r)&&(s=function(l,f){let u;f&&f.signal&&(u=f.signal,delete f.signal);const b=new t(l,f);return u&&Object.defineProperty(b,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),b},s.prototype=t.prototype);const o=e;return{fetch:(c,l)=>{const f=s&&s.prototype.isPrototypeOf(c)?c.signal:l?l.signal:void 0;if(f){let u;try{u=new DOMException("Aborted","AbortError")}catch{u=new Error("Aborted"),u.name="AbortError"}if(f.aborted)return Promise.reject(u);const b=new Promise((C,A)=>{f.addEventListener("abort",()=>A(u),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([b,o(c,l)])}return o(c,l)},Request:s}}const he=Ze({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ye=he?Ht({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ie=he?Ye.fetch:window.fetch;he?Ye.Request:window.Request;const qt=async i=>{try{let e,t;if(ae(i))e=i;else if(ie(i)){t=new URL(i).href;const r=await Ie(t);if(!r.ok)return{};e=await r.json()}else return{};if(!Dt(e))return{};const n=e.metadata.media;if(ie(n)&&!e.media)try{let r;t?r=new URL(n,t).href:(r=new URL(n).href,t=r);const s=await Ie(r);if(!s.ok)throw new Error;e.metadata.media=await s.json()}catch{return Zt(e.metadata.version)?{manifest:e}:{}}return{manifest:e,manifestURL:t}}catch{return{}}};async function Qt(i){const{manifest:e,manifestURL:t}=await qt(i),n=kt(e);return n.media=Kt(n.media,t),delete n.metadata.media,n}function ee(i,e){return i.find(t=>t.id===e)}function Se(i,e){return i.edit?.chapters?i.edit.chapters.find(t=>t.id===e):i.view?.chapters?i.view.chapters.find(t=>t.id===e):void 0}function Te(i,e){return i.videos.find(t=>t.id===e)}function Kt(i,e){return{...i,videos:i.videos.map(t=>({...t,variants:t.variants.map(n=>{const r=Xt(n.url,e);return{...n,url:r||n.url}})}))}}function Xt(i,e){try{return new URL(i,e).href}catch{return""}}function Zt(i){return z(i,"3.2.0")>=0}class Je extends Gt{constructor(e,t){super(e),this.onError=t,this.prevChapter$=new L.ValueSubject(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(e){this.release();const t=await this.exec("manifestLoaders",{actions:{addErrorMessage:Y},result:null,errors:null,source:e});t.errors&&this.errorHandler(t.errors);const n=await Qt(t.result??e);return this.manifest=n,this}async setInitial(){return this.setNext()}async setNext(e=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);const t=await this.exec("chapterLoaders",ne({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Se,getChapter:ee,getMedia:Te,getByBranches:this.getByBranches.bind(this),addErrorMessage:Y},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=ee(this.manifest.chapters,e);if(t){const n=Te(this.manifest.media,t.videoId),r=Se(this.manifest.graph,t.id);if(n)return{chapter:t,media:n,graph:r}}return null}getBranches(e=this.chapter.id){if(e===this.chapter.id)return this.getByBranches(this.chapter.branches);{const t=ee(this.manifest.chapters,e);return this.getByBranches(t?.branches)}}getByBranches(e=[]){return e.reduce((t,n)=>{const r=this.getByChapterId(n.chapterId);return r&&t.push(r),t},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}}const y={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyChanged:"history-changed"},xe={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},x={actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Yt(){const i=new Map;function e({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...o}){const a=i.get(r),c={...o};return a?a[s]=c:i.set(r,{[s]:c}),{listId:r,itemId:s,...o}}function t(r,s){const o=i.get(r);if(o){if(s)return o[s]?.player.destroy(),o[s]?.container.remove(),o[s]?.subscription.unsubscribe(),delete o[s],Object.keys(o).length||i.delete(r),!0;for(const a of Object.values(o))a.player.destroy(),a.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(const r of i)t(r[0])}return{createPlayer:e,removePlayer:t,map:i,removeAll:n}}function Re(i,e=[]){let t={},n;const r=!e.length;for(const s of i.variants)if(!n&&"cover"in s&&(n=s.cover),"url"in s)switch(s.type.toLowerCase()){case"mp4":(r||e.includes("mp4"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"mpeg":(r||e.includes("mpeg"))&&(t.MPEG={...t.MPEG,[s.standard??"Invariant quality"]:s.url});break;case"hls":(r||e.includes("hls"))&&(t={...t,HLS:{type:"url",url:s.url}});break;case"dash":(r||e.includes("dash"))&&(t={...t,DASH_SEP:{compatibilityMode:!0,type:"url",url:s.url}});break}return{sources:t,thumbUrl:n,title:i.title??""}}const K=(i,e)=>{const t=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();t!==e&&n.includes(e)&&(i.setQuality(e),i.setAutoQuality(!1))},Jt=i=>{const e=i.variants.find(t=>t.payload?.type==="vk");if(e&&"payload"in e){const[t,n]=e.payload.id.split("_");return[t,n]}return[]},Z={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},ei=2;function ti(i){const e=Yt();let t,n;const r=new Ke;let s={},o=!1,a=null,c=!1,l;i&&f(i);function f(d){a=d}function u(d,g,m){if(!a)throw Error("need to set interactive controller");const E=(e.map.get(d)??{})[g];if(E){s={chapterId:m,listId:d,itemId:g,...E};const v=s.player;n=v.info.currentQuality$.subscribe(w=>{if(!(!w||!v.info.position$.getValue())){t=w;for(const N of e.map)Object.values(N[1]).forEach(({player:O})=>{v.info.isAutoQualityEnabled$.getValue()||K(O,w)})}}),E.container.remove(),o=!1,a.setPlayer(E.player),c||(a.init(),c=!0),r.emit(Z.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function b(d,g,m){if(!a)throw Error("need to set interactive controller");if(G(s)||d!==s.itemId)return;if(m>=0&&!o){const E=a.getChapterBranches();o=!0;const v=new Set;for(const w of E)v.has(w.media.id)||(await A({media:w.media,chapterId:w.chapter.id,setAsActive:!1,title:w.chapter.label}),v.add(w.media.id))}}async function C({chapter:{id:d},media:g}){if(G(s))return;n?.unsubscribe();const m=s.player.info.muted$.getValue(),S=s.player.info.currentQuality$.getValue(),E=s.player.info.isAutoQualityEnabled$.getValue(),v=s.player.info.volume$.getValue(),w=s.player.info.currentPlaybackRate$.getValue(),N=!E;let O=!1;for(const j of e.map)if(j[0]===g.id){const H=Object.keys(j[1]);for(const k of H)k===s.itemId?(H.length<ei||(O=!0),e.removePlayer(j[0],k)):(O=!0,u(j[0],k,d),N?K(s.player,S):s.player.setAutoQuality(!0),s.player.setVolume(v),s.player.setMuted(m),s.player.setPlaybackRate(w))}else e.removePlayer(j[0]);O||(await A({media:g,chapterId:d,setAsActive:!0,playbackRate:w}),N?K(s.player,S):s.player.setAutoQuality(!0),s.player.setVolume(v),s.player.setMuted(m))}async function A({media:d,chapterId:g,prefetch:m=!0,setAsActive:S=!0,autoplay:E=!1,preferredExt:v,title:w,playbackRate:N}){const O=Math.random().toString(),j=document.createElement("div");l.append(j);const H=s?.player?.info.isAutoQualityEnabled$.getValue();let k;if(a?.options?.vkVideoLoader){const q=Jt(d);q.length&&(k=await a.options.vkVideoLoader(...q))}const ue={container:j,...k?.videos?.[0]||{sources:Re(d,v).sources},title:w},F=new dt.Player;F.initVideo(ue);const it=j.lastChild,pe=new L.Subscription;pe.add(F.info.position$.subscribe(function(q){b(O,F.info.duration$.getValue(),q)})).add(F.events.canplay$.subscribe(function(){H||K(F,t),N&&F.setPlaybackRate(N)})),it&&(j.style.display="none",j.classList.add(g));const $=e.createPlayer({listId:d.id,itemId:O,player:F,container:j,sources:Re(d,v).sources,config:ue,subscription:pe});return S&&u(d.id,$.itemId,g),E&&$.player.play(),m&&!E&&$.player.prepare(),r.emit(Z.playerCreated,$.player),{player:$.player,config:$.config}}function P(){h(),a=null}function h(){a?.off(y.chapterChanged,C),e.removeAll(),s={},c=!1,o=!1}async function p({source:d,initialChapter:g,container:m}){if(!a)throw Error("need to set interactive controller");await a.setManifest(d),h(),l=m;const{media:S,chapter:E}=await a.setChapter({chapterId:g});if(S){a.on(y.chapterChanged,C);const{player:v,config:w}=await A({media:S,chapterId:E.id,title:E.label});return r.emit(Z.initiated,{container:m,media:S,chapterId:E.id}),{player:v,config:w}}else console.error("not found")}return{...e,on:r.on.bind(r),off:r.off.bind(r),init:p,setInteractiveController:f,createPlayer:A,removeAll:P,getActivePlayer:function(){return s}}}const ii=3e3,ni=()=>{let i=[],e=null;return{setPlayer:o=>{e=o},setContainers:o=>{i=o},deleteContainer:o=>{i=i.filter(a=>a.id!==o)},getNextInteractiveTime:(o=ii)=>{if(!i.length||e===null)return null;let a=-1,c=!1;const l=e.info.position$.getValue()*1e3;for(const f of i){const u=f.startTime-o;if(u<=l&&(l<=f.endTime||f.endTime===null)){c=!0;break}l<u&&(a=a===-1?u:Math.min(a,u))}return!c&&a!==-1?a:null}}},B=ni(),T=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),de=i=>oe(i)&&!ce(i),et=i=>ce(i.branches)||i.order==="end",si=i=>oe(i.branches)&&!ce(i.branches),ri=(i,e)=>{const t=i*1e3;return de(e.controls)&&t<(e.startTime??0)},Ae=(i,e)=>{const t=i*1e3;return de(e.controls)&&t>=(e.startTime??0)&&t<=(e.endTime??1/0)},J=i=>i.some(e=>e.action.type==="expect"),Le=i=>i.find(e=>e.action.type==="expect"),ai=i=>i?.length===1,tt=i=>ai(i)&&Qe(i[0]),oi=({fn:i,type:e=1},...t)=>(...n)=>e?i(...n,...t):i({...n[e],...t[e]}),ci=(i=[])=>i.reduce((e,t,n)=>{const r=(t?.controls??[]).filter(s=>!Qe(s));if(de(r)){const s=[t.startTime??0,t.endTime??1/0],o=t.id;if(!n)e.push({subjects:[o],range:s});else{const a=[];let c=-1/0,l=1/0,f=[];const u=[];for(let b=0;b<e.length;b++){const C=e[b];if(u.push(...C.subjects),C.range[0]<l&&(l=C.range[0]),C.range[1]>c&&(c=C.range[1]),C.range[0]<=s[0]&&C.range[1]>=s[1])return e[b].subjects.push(o),e;s[0]>=C.range[0]&&s[0]<=C.range[1]&&(a.push(b),f=f.concat(C.subjects),s[0]=C.range[0]),s[1]>=C.range[0]&&s[1]<=C.range[1]&&(a.push(b),f=f.concat(C.subjects),s[1]=C.range[1])}if(u.push(o),s[0]<=l&&s[1]>=c)return[{subjects:u,range:s}];a.length&&a.reverse().forEach(b=>{e.splice(b,1)}),e.push({subjects:f.concat([o]),range:s})}}return e},[]).sort((e,t)=>e.range[0]-t.range[0]),li=(i,e)=>J(i.events)?!1:e.some(({container:t})=>t.container.id!==i.id&&J(t.container.events)&&t.container.endTime===i.endTime&&!t.isRemoved);class hi{constructor({player:e,container:t,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:o,ignoreContainerEvent:a,permanentTextControls:c}){this.container=t,this.branches=n,this.selectBranches=r,this.subscription=new L.Subscription,this.player=e,this.interactiveEvents=s,this.ignoreContainerEvent=a,this.isPermanentText=c&&tt(t.container.controls),this.globalEventEmitter=o,this.gameState=T.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))}hide=()=>{setTimeout(()=>{this.gameState!==T.end&&(J(this.container.container.events)&&this.gameState===T.afterInteractive||this.selectBranches.state.isExpect||(this.container.hide?.(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!1})))})};show=()=>{if(this.gameState===T.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())this.container.show?.(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!0,isFirst:!1});else{const t=oi({fn:this.selectBranches.onControlEvent,type:0},{branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!1})},onEvent:(n,r)=>{this.isSelectedControlEvent=!0,n!==!1&&(this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!1})),(this.gameState===T.end||this.gameState===T.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),r(),this.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!1})),B.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===T.end});this.container.createView(t),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!0,isFirst:!0})}};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=J(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!e)&&this.removeView()}onBeforeStartTime(){this.container.hide?.(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.visibility,visibility:!1})}onEndOfVideo=()=>{this.gameState=T.end,this.selectContainerEvent(!0)};whilePlaying=()=>{if(this.player.experimental.element$.getValue()?.readyState<1||[T.destroyed,T.removed].includes(this.gameState)&&!this.isPermanentText)return;const t=this.player.getExactTime();if(ri(t,this.container.container))this.gameState!==T.beforeInteractive&&(this.gameState=T.beforeInteractive,this.onBeforeStartTime());else if(Ae(t,this.container.container))this.gameState!==T.interactive&&(this.gameState=T.interactive,this.onStartTime());else if(this.gameState!==T.afterInteractive){const s=this.gameState;this.gameState=T.afterInteractive,s===T.interactive&&this.onEndTime()}else this.gameState!==T.destroyed&&this.removeView();const n=Ae(t,this.container.container),r=this.container.container.startTime?[this.container.container.startTime,this.container.container.endTime??1/0]:[];this.container.onProgress?.(t,n),this.globalEventEmitter.emit(y.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:r,currentTime:t,isInteractiveTime:n})};reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=T.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(y.interactives,{subjectId:this.container.container.id,subjectName:"container",type:x.containerRemoved,visibility:!1}),this.gameState=T.removed}destroy(){this.reset(),this.removeView(),this.gameState=T.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:this.container.container.endTime??1/0,id:this.container.container.id}),B.deleteContainer(this.container.container.id)}}function di(){const i={};function e(){for(const a in i)Object.prototype.hasOwnProperty.call(i,a)&&delete i[a];return!0}function t(a){const c={};for(const l in i)+l<=a&&(c[l]=i[l]);return c}function n(a){const c={};for(const l in i)+l>=a&&(c[l]=i[l]);return c}function r({timestamp:a,priority:c,initiator:l}){if(ve(a)){const f=i[a]??null;if(f&&Q(c,!0)){let u={};const b=f[c];return b&&(u={...u,...b}),u=G(u)?null:u,u&&Q(l,!0)?u[l]??null:u}return f}return null}function s({timestamp:a,priority:c,initiator:l}){if(ve(a))if(i[a]){if(Q(c,!0))if(i[a][c]){if(Q(l,!0))if(i[a][c][l]){if(delete i[a][c][l],!G(i[a][c]))return!0}else return!1;if(delete i[a][c],!G(i[a]))return!0}else return!1;return delete i[a]}else return!1}function o({timestamp:a,priority:c,initiator:l,...f}){i[a]?.[c]?.[l]?i[a][c][l].push({...f}):i[a]?.[c]?i[a][c]={...i[a][c],[l]:[{...f}]}:i[a]?i[a]={...i[a],[c]:{[l]:[{...f}]}}:i[a]={[c]:{[l]:[{...f}]}}}return{map:i,remove:s,add:o,removeAll:e,get:r,getLte:t,getGte:n}}const ui=[I.expect,I.setNextBranch],pi=1/0;function je(i){let e=i,t;const n=fi(),r=new di;let s;const o=()=>{u(),P()},a=h=>{r.add.call(void 0,h),b()},c=(h=[])=>{for(const p of h)if(p.action(),ui.includes(p.actionType))break},l=h=>{if(!n.isReady(h))return;const p=X(r.get({timestamp:h,priority:"control"})??{}),d=X(r.get({timestamp:h,priority:"container"})??{}),g=X(r.get({timestamp:h,priority:"chapter"})??{});c([...p,...d,...g])},f=()=>{c([...X(r.get({timestamp:1/0,priority:"chapter"})??{})])},u=()=>{t&&(s?.unsubscribe(),t=void 0)},b=()=>{t||(t=()=>setTimeout(()=>{l(1/0)}),s=e.events.ended$.subscribe(t))},C=h=>{u(),e=h},A=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),r.remove(h)},P=()=>{n.release(),r.removeAll()};return{setPlayer:C,add:a,remove:A,exec:l,execEndOfVideo:f,listen:b,unlisten:u,release:o,containersEventsCallState:n}}function fi(){const i=new Map;return{setCalled:({timestamp:o,id:a})=>{const c=i.get(o);c&&c[a]!==void 0&&(c[a]=!0)},setData:(o=[])=>{for(const a of o){const c=a.endTime??pi,l=i.get(c)??{};i.set(c,{...l,[a.id]:!1})}},resetCalled:o=>{const a=i.get(o);if(a)for(const c in a)a[c]=!1},isReady:o=>{const a=i.get(o);return a?!Object.values(a).some(c=>!c):!0},release:()=>i.clear()}}function X(i){return Object.values(i).flat().sort(e=>e.actionType===I.expect?-1:1)}const mi=(i,e)=>{const{height:t,width:n}=e.info.intrinsicVideoSize$.getValue()||{};if(!(t&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:r,clientWidth:s}=e.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};const o=t/n,a=r/s;let c,l;return a>o?(l=s,c=s*o):a<o?(l=r/o,c=r):(l=s,c=r),{videoContentWidth:l,videoContentHeight:c}},yi=250;function gi(i){let e=()=>{};const t=new ResizeObserver(a=>{s(a),e=s.bind(null,a)});function n(a){const{parentElement:c,player:l}=i();if(c&&l){const{videoContentWidth:f,videoContentHeight:u}=mi(c,l);c.style.setProperty("--interactive-content-width",`${f}px`),c.style.setProperty("--interactive-content-height",`${u}px`),c.style.setProperty("--interactive-width",`${a[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${a[0].contentRect.height}px`)}}function r(){const{parentElement:a}=i();a.removeAttribute("style")}const s=Ue(a=>{const{fns:c=[]}=i();n(a);for(const l of c)l()},yi);function o(){e=void 0,t.disconnect(),r()}return{resizeObserver:t,calc:()=>{e()},release:o}}class vi{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 bi=i=>Math.floor(Math.random()*i),Ci=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},Ei=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},wi=i=>{const e=i.length,t=bi(e);return i[t]},Ne=1,Ii=i=>{let e=0;for(let n=0;n<i.length;++n)e+=i[n].weight??Ne;const t=Math.random()*e;e=0;for(let n=0;n<i.length-1;++n)if(e+=i[n].weight??Ne,e>=t)return i[n];return i[i.length-1]},Oe=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),te=(i,e=!1)=>({...i,args:e?{...i.args,...Oe}:{...Oe,...i.args}}),_e=({globalEventEmitter:i,player:e,interactiveEvents:t,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},o=({action:h,controlType:p,controlId:d,containerId:g,branches:m=[],onEvent:S,isEOV:E=()=>!1})=>{const v=te(h,E()),w={timestamp:1/0,priority:"control",initiator:d,actionType:v.type},N=i.emit.bind(i,y.interactives,{subjectId:d,subjectType:p,subjectName:"control",type:x.actionChoice,actionType:h.type,payload:{containerId:g,...v.args}});switch(v.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{const O=m.find(j=>j.id===v.args.branchId);if(!O)return;S(v.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),N(),v.args.shouldOpenNow?A({subjectId:d,subjectName:"control",subjectType:p,action:v,payload:{chapterId:O.chapterId,autoSelect:!1}}):(t.add({...w,action:A.bind(null,{subjectId:d,subjectName:"control",subjectType:p,action:v,payload:{chapterId:O.chapterId,autoSelect:!1}})}),n?.());return}case I.continuePlayback.trim().toLowerCase():{S(v.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),N(),v.args.shouldOpenNow?C({subjectId:d,subjectName:"control",subjectType:p,action:h}):t.add({...w,action:C.bind(null,{subjectId:d,subjectName:"control",subjectType:p,action:h})});return}case I.openURI.trim().toLowerCase():{S(v.args.isDetachContainer,b.bind(null,{subjectId:d,subjectName:"control"})),N(),v.args.shouldOpenNow?P({subjectId:d,subjectName:"control",subjectType:p,action:v,payload:{URI:h.args.uri}}):(t.add({...w,action:P.bind(null,{subjectId:d,subjectName:"control",subjectType:p,action:v,payload:{URI:h.args.uri}})}),n?.());return}default:console.error("Unexpected control event"),i.emit(y.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},a=({action:h,container:{id:p,endTime:d},branches:g=[],isEOV:m=!1,autoSelected:S=!1})=>{const E=te(h,m),v={timestamp:!E.args.shouldOpenNow||m?1/0:d,priority:"container",initiator:p,actionType:E.type},w=i.emit.bind(i,y.interactives,{subjectId:p,subjectName:"container",type:x.actionChoice,actionType:E.type,payload:E.args});switch(E.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{const N=g.find(O=>O.id===E.args.branchId);if(!N)return;w(),t.add({...v,action:A.bind(null,{subjectId:p,subjectName:"container",action:E,payload:{chapterId:N.chapterId,autoSelect:S}})}),n?.();return}case I.setMaxWeightBranch.trim().toLowerCase():return;case I.setMinWeightBranch.trim().toLowerCase():return;case I.setRandomBranch.trim().toLowerCase():return;case I.setWeightlessRandomBranch.trim().toLowerCase():return;case I.continuePlayback.trim().toLowerCase():{w(),t.add({...v,action:C.bind(null,{subjectId:p,subjectName:"container",action:E})});return}case I.openURI.trim().toLowerCase():{w(),t.add({...v,action:P.bind(null,{subjectId:p,subjectName:"container",action:E,payload:{URI:h.args.uri}})}),n?.();return}default:console.error("Unexpected container event"),i.emit(y.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:h,branches:p,isEOV:d=!1}){const g=Le(h.events);if(g){const m=te(g.action,d);i.emit(y.interactives,{subjectId:h.id,subjectName:"container",type:x.actionChoice,actionType:m.type,payload:m.args}),t.add({timestamp:d?1/0:h.endTime,priority:"container",initiator:h.id,actionType:I.expect,action:u.bind(null,{subjectId:h.id,subjectName:"container"})}),r.isExpect=!0}else for(const m of h.events)a({action:m.action,container:h,branches:p,isEOV:d})}const l=({chapterId:h,action:p,branches:d=[]})=>{const g=i.emit.bind(i,y.interactives,{subjectId:h,subjectName:"chapter",type:x.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case I.setNextBranch.trim().toLowerCase():{const m=d.find(S=>S.id===p.args.branchId);return m?.chapterId?(g(),A.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setWeightlessRandomBranch.trim().toLowerCase():{const m=wi(d);return m?.chapterId?(g(),A.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setRandomBranch.trim().toLowerCase():{const m=Ii(d);return m?.chapterId?(g(),A.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setMaxWeightBranch.trim().toLowerCase():{const m=Ei(d);return m?.chapterId?(g(),A.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.setMinWeightBranch.trim().toLowerCase():{const m=Ci(d);return m?.chapterId?(g(),A.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case I.continuePlayback.trim().toLowerCase():return g(),C.bind(null,{subjectId:h,subjectName:"chapter",action:p});case I.openURI.trim().toLowerCase():return g(),P.bind(null,{subjectId:h,subjectName:"chapter",action:p,payload:{URI:p.args.uri}});default:console.error("Unexpected chapter event"),i.emit(y.errors,new R(R.Severity.RECOVERABLE,R.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function f(h){const p=Le(h.events);if(p){if(et(h))return;i.emit(y.interactives,{subjectId:h.id,subjectName:"chapter",type:x.actionChoice,actionType:p.action.type,payload:p.action.args}),t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:I.expect,action:u.bind(null,{subjectId:h.id,subjectName:"chapter"})})}else h.events.forEach(d=>{const g=l({chapterId:h.id,action:d.action,branches:h.branches});g&&t.add({timestamp:1/0,priority:"chapter",initiator:h.id,actionType:d.action.type,action:g})})}const u=({subjectId:h,subjectName:p,action:d})=>{e.pause(),i.emit(y.interactives,{subjectId:h,subjectName:p,type:x.actionExecution,actionType:d?.type??I.expect})},b=({subjectId:h,subjectName:p})=>{e.info.isEnded$.getValue()?t.execEndOfVideo():e.play(),i.emit(y.interactives,{subjectId:h,subjectName:p,type:x.actionExecution,actionType:"after-expect"})},C=({subjectId:h,subjectName:p,subjectType:d,action:g})=>{i.emit(y.interactives,{subjectId:h,subjectName:p,subjectType:d,type:x.actionExecution,actionType:g.type})},A=({subjectId:h,subjectName:p,subjectType:d,action:g,payload:m})=>{m.behaviour="change-chapter",i.emit(y.interactives,{subjectId:h,subjectName:p,subjectType:d,type:x.actionExecution,actionType:g.type,payload:m})},P=({subjectId:h,subjectName:p,subjectType:d,action:g,payload:m})=>{if(!m.URI)return;const S=window.open(m.URI,"_blank","noopener,noreferrer");S&&(S.opener=null),i.emit(y.interactives,{subjectId:h,subjectName:p,subjectType:d,type:x.actionExecution,actionType:g.type})};return{onControlEvent:o,onContainerEvent:a,onChapterEvent:l,onExpectEvent:u,expectEventHandler:b,setManifestChapterEvents:f,setManifestContainerEvents:c,stopExpect:s,state:r}};class D{constructor(e,t,n,r){this.target=e,this.type=t,this.listener=n,this.options=D.#a(e,r),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}static#a(e,t){if(t===void 0)return!1;if(typeof t=="boolean")return t;{const n=new Set(["passive","capture"]),r=Object.keys(t).filter(o=>!n.has(o));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),D.#c(e)?t:t.capture||!1}}static#s=void 0;static#c(e){let t=D.#s;if(t===void 0){t=!1;try{const n={},r={get:()=>(t=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);const s=()=>{};e.addEventListener("test",s,n),e.removeEventListener("test",s,n)}catch{t=!1}D.#s=t}return t||!1}}class Si{constructor(){this.bindingMap=new vi}release(){this.removeAll(),this.bindingMap=null}listen(e,t,n,r){if(!this.bindingMap)return;const s=new D(e,t,n,r);this.bindingMap.push(t,s)}listenOnce(e,t,n,r){const s=o=>{this.unlisten(e,t,s),n(o)};this.listen(e,t,s,r)}unlisten(e,t,n){if(!this.bindingMap)return;const r=this.bindingMap.get(t)||[];for(const s of r)s.target===e&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(t,s))}removeAll(){if(!this.bindingMap)return;const e=this.bindingMap.getAll();for(const t of e)t.unlisten();this.bindingMap.clear()}}class Ti{rootElement;canvasImgSrc;_prevSizeId=0;constructor(){this.rootElement=document.createElement("canvas")}clear(){this.rootElement.getContext("2d")?.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){const e=this.rootElement.getContext("2d")?.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!e)return!1;const t=e.data,n=t.length;for(let r=3;r<n;r+=40)if(t[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(){this.canvasImgSrc&&this.rootElement.getContext("2d")?.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height)}async updateCanvasDimensions(e,t=!1){const n=e.width+e.height;if(this._prevSizeId===n)return;let r;t&&(r=await this.save()),this.rootElement.width=e.width,this.rootElement.height=e.height,t&&r&&this.restore(r),this._prevSizeId=n}async save(){const e=this.rootElement.toDataURL("image/jpeg",1),t=new Image;return t.crossOrigin="anonymous",t.src=e,await t.decode(),t}restore(e){this.rootElement&&this.rootElement.getContext("2d")?.drawImage(e,0,0,this.rootElement.width,this.rootElement.height)}}class xi{lastFrameCanvas;endOffsetMs;currentChapter;currentVideoDurationMs=1/0;rootElement;_containerTimeFrameShouldReceived=!1;_endTimeFrameReceived=!1;_shouldCallSkip=!1;_callbacks;constructor({parentElement:e,endOffsetMs:t=250,onError:n}){this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
7
7
|
position: absolute;
|
|
8
8
|
top: 0;
|
|
9
9
|
left: 0;
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
height: var(--interactive-height);
|
|
12
12
|
background-color: var(--black);
|
|
13
13
|
visibility: hidden;
|
|
14
|
-
`,this.lastFrameCanvas=new
|
|
14
|
+
`,this.lastFrameCanvas=new Ti,this.endOffsetMs=t,this._callbacks={onError:n},this.lastFrameCanvas.rootElement.style.cssText=`
|
|
15
15
|
position: absolute;
|
|
16
16
|
top: 50%;
|
|
17
17
|
left: 50%;
|
|
18
18
|
transform: translate(-50%, -50%);
|
|
19
|
-
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);const t=getComputedStyle(this.rootElement),n={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(r){this._onError(r)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>t.controls?.length&&e>=(t.startTime??0)&&e<=Math.min(t.endTime??1/0,this.currentVideoDurationMs-this.endOffsetMs))}onEachTick=e=>{const t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){this._callbacks?.onError?.(e)}}function Ri(i=0){return new Promise(e=>{setTimeout(()=>{e(0)},i)})}const Ai=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,lastFrame:!1,permanentTextControls:!0}),
|
|
19
|
+
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),e.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(e){this.currentVideoDurationMs=e}setVideoElement(e){this.lastFrameCanvas.setCanvasImageSource(e)}setCurrentChapter(e){this.currentChapter=e}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(e=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(e=!1);const t=getComputedStyle(this.rootElement),n={width:parseInt(t.getPropertyValue("--interactive-content-width"),10),height:parseInt(t.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,e)}catch(r){this._onError(r)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(e){return this.currentVideoDurationMs&&e>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(e){if(this.currentChapter)return this.currentChapter.containers.some(t=>t.controls?.length&&e>=(t.startTime??0)&&e<=Math.min(t.endTime??1/0,this.currentVideoDurationMs-this.endOffsetMs))}onEachTick=e=>{const t=e??this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(t);if(this.isContainerTime(t))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(e){this._callbacks?.onError?.(e)}}function Ri(i=0){return new Promise(e=>{setTimeout(()=>{e(0)},i)})}const Ai=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,lastFrame:!1,permanentTextControls:!0}),M=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function Li(){const i=document.createElement("div");return i.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,i}class Li{#a=null;#s=null;#c=null;#l=null;#r=null;#o=null;#h=null;#t=null;#d=new O.ValueSubject(!1);#f=new Set;#n=null;#m=null;#i=null;#e=null;state={history$:new O.ValueSubject([]),hasPrevChapter$:new O.ValueSubject(!1)};constructor(e){this.options={...Ai,...e},this.#s=[],this.factories=new Map([["choice",Ge]]),this.rootElement=xi(),this.options.parentElement.append(this.rootElement),this.#e=new Ke,this.#l=new O.Subscription,this.#c=new Si,this.options.lastFrame&&(this.#i=new Ti({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:t=>this.#e.emit(y.errors,new A(A.Severity.RECOVERABLE,A.Category.SEAMLESS,t))})),this.#c.listen(this.rootElement,"mousedown",t=>t.stopPropagation()),this.#c.listen(this.rootElement,"mouseup",t=>t.stopPropagation()),this.#t=new Je(this.options.loaders,t=>this.#e.emit(y.errors,new A(A.Severity.RECOVERABLE,A.Category.MANIFEST,t))),this.#r=xe(this.options.player),this.#o=new Bt,this.#h=je({player:this.options.player,interactiveEvents:this.#r,globalEventEmitter:this.#e,removeControllers:this.#u}),this.#a=yi(()=>({player:this.options?.player,parentElement:this.options.parentElement,fns:this.options.lastFrame?[()=>{this.#i.updateCanvasDimensions(!0)}]:[]})),this.options.graph&&(this.#n=new It({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:t=>{this.setChapter({chapterId:t}),this.#e.emit(y.graph,{type:Ie.watchAgainClicked,chapterId:t})},onError:t=>this.#e.emit(y.errors,new A(A.Severity.RECOVERABLE,A.Category.LOADERS,{message:t}))})),this.#e.on(y.interactives,t=>{if(t.type===R.actionExecution){if(t.payload?.behaviour==="change-chapter"){const{chapterId:n}=t.payload;this.setChapter({chapterId:n})}if(t.payload?.behaviour==="change-manifest"){const{manifestURL:n}=t.payload;this.setManifest(n)}}}),this.isFirstChapterFetched=!1,this.appState=V.created}emitPlayerChanged=e=>{this.#e.emit(y.playerChanged,e)};async initSeamless({source:e,initialChapter:t,visitedChapters:n=[],videosInfo:r}){this.#m=Jt(this);const s=document.createElement("div");this.#m.on(Z.activePlayerChanged,this.emitPlayerChanged);const{player:o,config:a}=await this.#m.init({source:e,initialChapter:t,container:s});return this.setVisitedChapters(n),this.updateGraphVideosInfo(r),{player:o,config:a}}getStatEvents(){return{click$:new O.Observable(e=>{this.#e.on(y.graph,({type:t,visibility:n})=>{t==="visibility"&&e.next(n?exports.INTERACTIVE_CLICK_ACTIONS.OPEN_GRAPH:exports.INTERACTIVE_CLICK_ACTIONS.CLOSE_GRAPH),t==="watchAgainClicked"&&e.next(exports.INTERACTIVE_CLICK_ACTIONS.WATCH_AGAIN)}),this.#e.on(y.interactives,({type:t,subjectName:n,subjectType:r})=>{t!=="action-choice"||n!=="control"||(r==="Button"&&e.next(exports.INTERACTIVE_CLICK_ACTIONS.GO_NEXT_BUTTON),r==="Area"&&e.next(exports.INTERACTIVE_CLICK_ACTIONS.GO_NEXT_AREA))})}),nextMovie$:new O.Observable(e=>{this.#e.on(y.playerChanged,({config:t})=>{t?.unitedVideoId&&e.next(t.unitedVideoId)})})}}setPlayer(e){this.#y(),this.options.player=e,B.setPlayer(this.options.player),this.#r?this.#r.setPlayer(this.options.player):this.#r=xe(this.options.player),this.#h=je({player:this.options.player,interactiveEvents:this.#r,globalEventEmitter:this.#e,removeControllers:()=>this.#u(!1)}),this.appState===V.initiated&&(this.#g(),this.#p(this.#t.chapter))}async setManifest(e){this.#y(),this.isFirstChapterFetched=!1;const t=await this.#t.setManifest(e);return this.#n&&await this.#n.handleManifestChange(t.manifest),this.#e.emit(y.manifestChanged,{manifest:t.manifest}),this.#p(this.#t.chapter),t.manifest}setVisitedChapters(e){Array.isArray(e)&&(this.state.history$.next(e),this.#n?.setVisitedChapters(e))}updateGraphVideosInfo(e){Array.isArray(e)&&this.#n?.updateVideosInfo(e)}async setChapter({chapterId:e}={}){this.#y(),this.#i&&this.isFirstChapterFetched&&(this.#i.draw(),this.#i.show()),O.getCurrentBrowser().browser===O.CurrentClientBrowser.Safari&&await Ri(35);const n=await(e?this.#t.setNext(e):this.#t.setInitial()),{chapter:r,media:s,graph:o}=n;return this.#w(r.id),this.#n&&this.#n.handleChapterChange(o),this.#i?.setCurrentChapter(this.getCurrentChapter().chapter),this.#e.emit(y.chapterChanged,{chapter:r,media:s,graph:o}),this.#p(this.#t.chapter),this.#f=new Set,this.isFirstChapterFetched=!0,{chapter:r,media:s,graph:o}}toggleGraphView(e=!0){this.#n&&(e?(this.#n.show(),this.#d.next(!1)):(this.#n.hide(),this.#b()),this.#e.emit(y.graph,{type:Ie.visibility,visibility:e}))}init(){this.#t.chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===V.created&&(this.#a.resizeObserver.observe(this.options.fullscreenTargetElement),this.#g(),this.appState=V.initiated,this.#p(this.#t.chapter))}#y(){this.appState===V.ready&&(this.#u(),this.#s=[],this.#o.release(),this.#r?.release(),this.appState=V.initiated,this.#d.next(!1))}#S=()=>{this.#o.fns.forEach(n=>n());const e=this.options.player.info.position$.getValue()*1e3,t=(this.#t.chapter.containers||[]).filter(n=>n.startTime>=Math.floor(e));for(const n of t){this.#r.remove({timestamp:1/0,priority:"container",initiator:n.id});for(const r of n.controls)this.#r.remove({timestamp:1/0,priority:"control",initiator:r.id});this.#s.find(r=>r.container.container.id===n.id).reset()}};#v=()=>{this.#a.calc(),this.#o.requestAnimation()};#E(e){(!this.#n||this.#n.isHidden)&&this.#b();const t=e*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>t>=s[1]);if(r){const s=r.range.join("-");this.#f.has(s)||(this.#f.add(s),this.#e.emit(y.interactives,{type:R.rangeEnded,payload:r,visibility:!0}))}}#g(){this.#l.unsubscribe(),this.#l.add(this.options.player.events.started$.pipe(O.once()).subscribe(this.#v)).add(this.options.player.events.playing$.subscribe(this.#o.requestAnimation)).add(this.options.player.events.willPause$.subscribe(this.#o.cancelAnimation)).add(this.options.player.info.position$.subscribe(this.#E.bind(this))).add(this.state.history$.subscribe(e=>{this.state.hasPrevChapter$.next(e.length>1)})),this.options.lastFrame&&this.#l.add(this.options.player.info.duration$.subscribe(e=>{this.#i.setVideoDuration(e*1e3)})).add(this.options.player.experimental.element$.subscribe(e=>{e&&this.#i.setVideoElement(e)})).add(this.options.player.events.firstFrame$.subscribe(()=>{this.#i.reset(),setTimeout(()=>{this.#i.hide(),this.#i.lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(this.#i.onSeek))}#u=(e=!0)=>{this.#s.forEach(t=>{!e&&t.isPermanentText||(this.#o.removeFn(t.whilePlaying),t.destroy())})};#p(e){this.#t.chapter&&this.appState===V.initiated&&(this.#h.setManifestChapterEvents(e),this.#s=this.#C(e),this.#r.containersEventsCallState.setData(e.containers),B.setContainers(this.#s.map(t=>t.container.container)),this.options.lastFrame&&this.#o.addFn(()=>{this.#i.onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.appState=V.ready)}#C(e){return e?.containers?.reduce((t,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);if(s){const o=new li({player:this.options.player,container:s(n,this.rootElement),branches:this.#t.chapter.branches,selectBranches:this.#h,interactiveEvents:this.#r,globalEventEmitter:this.#e,ignoreContainerEvent:()=>ci(n,this.#s),permanentTextControls:this.options.permanentTextControls});return this.#o.addFn(o.whilePlaying,!0),[...t,o]}return[...t]},[])??[]}#b(){const e=this.#d.getValue(),t=!!B.getNextInteractiveTime();(t&&!e||!t&&e)&&this.#d.next(!e)}#w(e){if(this.#t.manifest.metadata.initChapterId===e){this.state.history$.next([e]);return}const t=this.state.history$.getValue();t.at(-1)!==e&&this.state.history$.next([...t,e])}playPrevChapter(){const e=this.state.history$.getValue();if(e.length>1){e.pop();const t=e.at(-1);this.state.history$.next(e),this.setChapter({chapterId:t})}}isSupport(e=this.#t.manifest){return oe(e.metadata.version)}getIsSeekable(){return this.#d}getInteractiveRanges(){return oi(this.#t.chapter?.containers)}getNextInteractiveStartTime(e){return B.getNextInteractiveTime(e)}getChapterBranches(e){return this.#t.getBranches(e)}getCurrentChapter(){return this.#t.getCurrent()}getCurrentManifest(){return this.#t.manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return this.#e.on(...e),this}off(...e){return this.#e.off(...e),this}once(...e){return this.#e.once(...e),this}destroy(){this.#u(),this.#s=void 0,this.state=void 0,this.#n?.destroy(),this.#n=void 0,this.#a.release(),this.#a=void 0,this.#h=void 0,this.#o.release(),this.#o=void 0,this.#r.release(),this.#r=void 0,this.#t.release(),this.#h=void 0,this.#c.release(),this.#c=void 0,this.#l.unsubscribe(),this.#l=void 0,this.#e.reset(),this.#e=void 0,this.#i?.destroy(),this.#i=void 0,this.rootElement.remove(),this.rootElement=void 0,this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=V.destroyed}}const Ni={Container:De,createChoiceContainer:Ge,createAreaControl:Fe,createButtonControl:$e,createRelativeLayout:gt,getRootEl:_e,classnamesPrefix:_},ji={version:ht};exports.CustomError=A;exports.EVENT_NAMES=y;exports.Interactives=Li;exports.ManifestController=Je;exports.SDKInfo=ji;exports.compareVersions=U;exports.isSupportedManifest=oe;exports.utils=Ni;
|
|
23
|
+
`,i}class ji{#a=null;#s=null;#c=null;#l=null;#r=null;#o=null;#h=null;#t=null;#d=new L.ValueSubject(!1);#f=new Set;#n=null;#m=null;#i=null;#e=null;state={history$:new L.ValueSubject([]),hasPrevChapter$:new L.ValueSubject(!1),prevChapter$:new L.ValueSubject(null),calledByInteractive$:new L.ValueSubject(!1),lastChapterChangeWasInitiatedByInteractive$:new L.ValueSubject(!1)};constructor(e){this.options={...Ai,...e},this.#s=[],this.factories=new Map([["choice",ze]]),this.rootElement=Li(),this.options.parentElement.append(this.rootElement),this.#e=new Ke,this.#l=new L.Subscription,this.#c=new Si,this.options.lastFrame&&(this.#i=new xi({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:t=>this.#e.emit(y.errors,new R(R.Severity.RECOVERABLE,R.Category.SEAMLESS,t))})),this.#c.listen(this.rootElement,"mousedown",t=>t.stopPropagation()),this.#c.listen(this.rootElement,"mouseup",t=>t.stopPropagation()),this.#t=new Je(this.options.loaders,t=>this.#e.emit(y.errors,new R(R.Severity.RECOVERABLE,R.Category.MANIFEST,t))),this.#r=je(this.options.player),this.#o=new Wt,this.#h=_e({player:this.options.player,interactiveEvents:this.#r,globalEventEmitter:this.#e,removeControllers:this.#u}),this.#a=gi(()=>({player:this.options?.player,parentElement:this.options.parentElement,fns:this.options.lastFrame?[()=>{this.#i.updateCanvasDimensions(!0)}]:[]})),this.options.graph&&(this.#n=new xt({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:t=>{this.setChapter({chapterId:t}),this.#e.emit(y.graph,{type:xe.watchAgainClicked,chapterId:t})},onError:t=>this.#e.emit(y.errors,new R(R.Severity.RECOVERABLE,R.Category.LOADERS,{message:t}))})),this.#e.on(y.interactives,t=>{if(t.type===x.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),t.payload?.behaviour==="change-chapter"){const{chapterId:n}=t.payload;this.setChapter({chapterId:n})}if(t.payload?.behaviour==="change-manifest"){const{manifestURL:n}=t.payload;this.setManifest(n)}}}),this.#e.on(y.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}),this.isFirstChapterFetched=!1,this.appState=M.created}emitPlayerChanged=e=>{this.#e.emit(y.playerChanged,e)};async initSeamless({source:e,initialChapter:t,visitedChapters:n=[],videosInfo:r}){this.#m=ti(this);const s=document.createElement("div");this.#m.on(Z.activePlayerChanged,this.emitPlayerChanged);const{player:o,config:a}=await this.#m.init({source:e,initialChapter:t,container:s});return this.setVisitedChapters(n),this.updateGraphVideosInfo(r),{player:o,config:a}}getStatEvents(){return{click$:new L.Observable(e=>{this.#e.on(y.graph,({type:t,visibility:n})=>{t==="visibility"&&e.next(n?exports.INTERACTIVE_CLICK_ACTIONS.OPEN_GRAPH:exports.INTERACTIVE_CLICK_ACTIONS.CLOSE_GRAPH),t==="watchAgainClicked"&&e.next(exports.INTERACTIVE_CLICK_ACTIONS.WATCH_AGAIN)}),this.#e.on(y.interactives,({type:t,subjectName:n,subjectType:r})=>{t!=="action-choice"||n!=="control"||(r==="Button"&&e.next(exports.INTERACTIVE_CLICK_ACTIONS.GO_NEXT_BUTTON),r==="Area"&&e.next(exports.INTERACTIVE_CLICK_ACTIONS.GO_NEXT_AREA))})}),nextMovie$:new L.Observable(e=>{this.#e.on(y.playerChanged,({config:t})=>{t?.unitedVideoId&&e.next(t.unitedVideoId)})})}}setPlayer(e){this.#y(),this.options.player=e,B.setPlayer(this.options.player),this.#r?this.#r.setPlayer(this.options.player):this.#r=je(this.options.player),this.#h=_e({player:this.options.player,interactiveEvents:this.#r,globalEventEmitter:this.#e,removeControllers:()=>this.#u(!1)}),this.appState===M.initiated&&(this.#g(),this.#p(this.#t.chapter))}async setManifest(e){this.#y(),this.isFirstChapterFetched=!1;const t=await this.#t.setManifest(e);return this.#n&&await this.#n.handleManifestChange(t.manifest),this.#e.emit(y.manifestChanged,{manifest:t.manifest}),this.#p(this.#t.chapter),t.manifest}setVisitedChapters(e){Array.isArray(e)&&(this.state.history$.next(e),this.#n?.setVisitedChapters(e))}updateGraphVideosInfo(e){Array.isArray(e)&&this.#n?.updateVideosInfo(e)}async setChapter({chapterId:e}={}){this.#y(),this.#i&&this.isFirstChapterFetched&&(this.#i.draw(),this.#i.show()),L.getCurrentBrowser().browser===L.CurrentClientBrowser.Safari&&await Ri(35);const n=await(e?this.#t.setNext(e):this.#t.setInitial()),{chapter:r,media:s,graph:o}=n;return this.#I(r.id),this.#n&&this.#n.handleChapterChange(o),this.#i?.setCurrentChapter(this.getCurrentChapter().chapter),this.#e.emit(y.chapterChanged,{chapter:r,media:s,graph:o}),this.#p(this.#t.chapter),this.#f=new Set,this.isFirstChapterFetched=!0,{chapter:r,media:s,graph:o}}toggleGraphView(e=!0){this.#n&&(e?(this.#n.show(),this.#d.next(!1)):(this.#n.hide(),this.#v()),this.#e.emit(y.graph,{type:xe.visibility,visibility:e}))}init(){this.#t.chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===M.created&&(this.#a.resizeObserver.observe(this.options.fullscreenTargetElement),this.#g(),this.appState=M.initiated,this.#p(this.#t.chapter))}#y(){this.appState===M.ready&&(this.#u(),this.#s=[],this.#o.release(),this.#r?.release(),this.appState=M.initiated,this.#d.next(!1))}#S=()=>{this.#o.fns.forEach(n=>n());const e=this.options.player.info.position$.getValue()*1e3,t=(this.#t.chapter.containers||[]).filter(n=>n.startTime>=Math.floor(e));for(const n of t){this.#r.remove({timestamp:1/0,priority:"container",initiator:n.id});for(const r of n.controls)this.#r.remove({timestamp:1/0,priority:"control",initiator:r.id});this.#s.find(r=>r.container.container.id===n.id).reset()}};#b=()=>{this.#a.calc(),this.#o.requestAnimation()};#C(e){(!this.#n||this.#n.isHidden)&&this.#v();const t=e*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>t>=s[1]);if(r){const s=r.range.join("-");this.#f.has(s)||(this.#f.add(s),this.#e.emit(y.interactives,{type:x.rangeEnded,payload:r,visibility:!0}))}}#g(){this.#l.unsubscribe(),this.#l.add(this.options.player.events.started$.pipe(L.once()).subscribe(this.#b)).add(this.options.player.events.playing$.subscribe(this.#o.requestAnimation)).add(this.options.player.events.willPause$.subscribe(this.#o.cancelAnimation)).add(this.options.player.info.position$.subscribe(this.#C.bind(this))).add(this.state.history$.subscribe(e=>{this.state.hasPrevChapter$.next(e.length>1)})).add(this.#t.prevChapter$.subscribe(e=>this.state.prevChapter$.next(e))),this.options.lastFrame&&this.#l.add(this.options.player.info.duration$.subscribe(e=>{this.#i.setVideoDuration(e*1e3)})).add(this.options.player.experimental.element$.subscribe(e=>{e&&this.#i.setVideoElement(e)})).add(this.options.player.events.firstFrame$.subscribe(()=>{this.#i.reset(),setTimeout(()=>{this.#i.hide(),this.#i.lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(this.#i.onSeek))}#u=(e=!0)=>{this.#s.forEach(t=>{!e&&t.isPermanentText||(this.#o.removeFn(t.whilePlaying),t.destroy())})};#p(e){this.#t.chapter&&this.appState===M.initiated&&(this.#h.setManifestChapterEvents(e),this.#s=this.#E(e),this.#r.containersEventsCallState.setData(e.containers),B.setContainers(this.#s.map(t=>t.container.container).filter(t=>!tt(t.controls))),this.options.lastFrame&&this.#o.addFn(()=>{this.#i.onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.appState=M.ready)}#E(e){return e?.containers?.reduce((t,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);if(s){const o=new hi({player:this.options.player,container:s(n,this.rootElement),branches:this.#t.chapter.branches,selectBranches:this.#h,interactiveEvents:this.#r,globalEventEmitter:this.#e,ignoreContainerEvent:()=>li(n,this.#s),permanentTextControls:this.options.permanentTextControls});return this.#o.addFn(o.whilePlaying,!0),[...t,o]}return[...t]},[])??[]}#v(){const e=this.#d.getValue(),t=!!B.getNextInteractiveTime();(t&&!e||!t&&e)&&this.#d.next(!e)}#w(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)}#I(e){this.#w();const t=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(n&&et(n)&&si(n))??!1;if(this.#t.manifest.metadata.initChapterId===e||r&&t){this.state.history$.next([e]);return}const o=this.state.history$.getValue();o.at(-1)!==e&&this.state.history$.next([...o,e])}playPrevChapter(){const e=this.state.history$.getValue();if(e.length>1){e.pop();const t=e.at(-1);this.state.history$.next(e),this.setChapter({chapterId:t})}}isSupport(e=this.#t.manifest){return le(e.metadata.version)}getIsSeekable(){return this.#d}getInteractiveRanges(){return ci(this.#t.chapter?.containers)}getNextInteractiveStartTime(e){return B.getNextInteractiveTime(e)}getChapterBranches(e){return this.#t.getBranches(e)}getCurrentChapter(){return this.#t.getCurrent()}getCurrentManifest(){return this.#t.manifest}addFactory(e,t){this.factories.set(e.trim().toLowerCase(),t)}removeFactory(e){this.factories.delete(e.trim().toLowerCase())}on(...e){return this.#e.on(...e),this}off(...e){return this.#e.off(...e),this}once(...e){return this.#e.once(...e),this}destroy(){this.#u(),this.#s=void 0,this.state=void 0,this.#n?.destroy(),this.#n=void 0,this.#a.release(),this.#a=void 0,this.#h=void 0,this.#o.release(),this.#o=void 0,this.#r.release(),this.#r=void 0,this.#t.release(),this.#h=void 0,this.#c.release(),this.#c=void 0,this.#l.unsubscribe(),this.#l=void 0,this.#e.reset(),this.#e=void 0,this.#i?.destroy(),this.#i=void 0,this.rootElement.remove(),this.rootElement=void 0,this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=M.destroyed}}const Ni={Container:Ge,createChoiceContainer:ze,createAreaControl:Be,createButtonControl:De,createRelativeLayout:bt,getRootEl:Me,classnamesPrefix:_},Oi={version:ut};exports.CustomError=R;exports.EVENT_NAMES=y;exports.Interactives=ji;exports.ManifestController=Je;exports.SDKInfo=Oi;exports.compareVersions=z;exports.isSupportedManifest=le;exports.utils=Ni;
|