@vkontakte/videoplayer-interactive 1.0.10-beta.2 → 1.0.10-dev.45d43b13.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 +4 -4
- package/esnext.esm.js +4 -4
- package/evergreen.esm.js +4 -4
- package/package.json +1 -1
package/es2018.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.10-
|
|
3
|
-
* Fri, 17 May 2024
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.10-dev.45d43b13.0
|
|
3
|
+
* Fri, 17 May 2024 12:52:31 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-10/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{loadVKLangPack as Vn,ValueSubject as W,Subscription as Zt,Observable as Fe,getCurrentBrowser as Fn,CurrentClientBrowser as Bn,once as Dn}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{v4 as Wn}from"uuid";import{Player as Hn}from"@vkontakte/videoplayer-core/es2018.esm.js";const Un="1.0.10-beta.2";function Li(e,t=1){let i="0",n="0",s="0";return e.length===4?(i="0x"+e[1]+e[1],n="0x"+e[2]+e[2],s="0x"+e[3]+e[3]):e.length===7&&(i="0x"+e[1]+e[2],n="0x"+e[3]+e[4],s="0x"+e[5]+e[6]),`rgba(${+i},${+n},${+s},${t})`}const q="SDK_NAME",Gn="SDK_NAME-controls-container",Pi=()=>document.querySelector(`.${Gn}`),zn=.4,K={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Be={top:"flex-start",bottom:"flex-end",center:"center"},De={start:"flex-start",end:"flex-end",center:"center"},We={start:"left",end:"right",center:"center"},Mi=({target:e,props:t})=>{var i,n,s,r,c,o;e.style.alignItems=(n=Be[(i=t==null?void 0:t.text)===null||i===void 0?void 0:i.gravityVertical])!==null&&n!==void 0?n:Be.center,e.style.justifyContent=(r=De[(s=t==null?void 0:t.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:De.center,e.style.textAlign=(o=We[(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:We.start},Ni=({target:e,props:t,fallback:i,dependsOn:n})=>{var s,r,c,o,l,h;e.style.color=(r=(s=t==null?void 0:t.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:i.textColor,e.style.fontSize=`calc(${n.height} * ${(o=(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.size)!==null&&o!==void 0?o:i.textSize})`,e.textContent=(h=(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.value)!==null&&h!==void 0?h:i.textContent},ki=({target:e,props:t,fallback:i})=>{var n,s,r,c;e.style.backgroundColor=Li((s=(n=t==null?void 0:t.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:i.backgroundColor,(c=(r=t==null?void 0:t.background)===null||r===void 0?void 0:r.alpha)!==null&&c!==void 0?c:i.backgroundAlpha)},Vi=({target:e,props:t,fallback:i,dependsOn:n})=>{var s,r,c,o,l,h,v,u,p,g,b;e.style.border=`calc(${n.height} * ${(c=(r=(s=t==null?void 0:t.shape)===null||s===void 0?void 0:s.border)===null||r===void 0?void 0:r.width)!==null&&c!==void 0?c:i.borderWidth}) solid ${Li((h=(l=(o=t==null?void 0:t.shape)===null||o===void 0?void 0:o.border)===null||l===void 0?void 0:l.color)!==null&&h!==void 0?h:i.borderColor,(p=(u=(v=t==null?void 0:t.shape)===null||v===void 0?void 0:v.border)===null||u===void 0?void 0:u.alpha)!==null&&p!==void 0?p:i.borderAlpha)}`,e.style.borderRadius=`calc(${n.height} * ${(b=(g=t==null?void 0:t.shape)===null||g===void 0?void 0:g.roundCorners)!==null&&b!==void 0?b:i.roundCorners})`},Re=({target:e,layoutParams:t,fallback:i})=>{var n;e.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:i.angle}rad)`},ie="int",xe={AREA:`${ie}_area`,TEXT:`${ie}_text`,BUTTON:`${ie}_bttn`};class Oe{constructor(t){this.control=t}createView(t){var i;const n=document.createElement("div");n.classList.add(`${q}-control-container-${this.control.id}`),t(n,this.control.layoutParams);const s=((i=this.control.layoutParams.innerSizesDependOn)!==null&&i!==void 0?i:K.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:s}}setEvents(t,i){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",r=>{r.stopPropagation(),i&&i({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${q}-control-container-${this.control.id}`)}}const Fi=e=>{if(e.type.trim().toLowerCase()==="area")return new qn(e)};class qn extends Oe{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:n,controlContainerEl:s}=super.createView(i),r=document.createElement("button");return r.classList.add(`${q}-${this.control.id}`),r.setAttribute("data-testid",xe.AREA),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",ki({target:r,props:this.control.props,fallback:{...K,backgroundColor:"transparent"}}),Vi({target:r,props:this.control.props,fallback:{...K,borderAlpha:0},dependsOn:n}),Re({target:r,layoutParams:this.control.layoutParams,fallback:K}),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const Bi=e=>{if(e.type.trim().toLowerCase()==="button")return new Qn(e)};class Qn extends Oe{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:n,controlContainerEl:s}=super.createView(i),r=document.createElement("button");r.type="button",r.classList.add(`${q}-${this.control.id}`),r.setAttribute("data-testid",xe.BUTTON),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.display="inline-block",c.style.whiteSpace="pre",c.style.overflow="hidden",c.style.textOverflow="ellipsis",Re({target:r,layoutParams:this.control.layoutParams,fallback:K}),ki({target:r,props:this.control.props,fallback:K}),Vi({target:r,props:this.control.props,fallback:K,dependsOn:n}),Mi({target:r,props:this.control.props}),Ni({target:c,props:this.control.props,fallback:K,dependsOn:n}),r.append(c),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const Yn=e=>{if(e.type.trim().toLowerCase()==="text")return new Kn(e)};class Kn extends Oe{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:n,controlContainerEl:s}=super.createView(i),r=document.createElement("div");r.classList.add(`${q}-${this.control.id}`),r.setAttribute("data-testid",xe.TEXT),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",Re({target:r,layoutParams:this.control.layoutParams,fallback:K}),Mi({target:r,props:this.control.props}),Ni({target:c,props:this.control.props,fallback:K,dependsOn:n}),r.append(c),s.append(r),t.append(s),this.controlEl=r,s}disable(){}enable(){}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}class Xn{constructor(t){this.layout=t}}const Zn=e=>{if(e.type.trim().toLowerCase()==="relative")return new Di(e)};class Di extends Xn{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,i){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${i.width})`,t.style.height=`calc(var(--interactive-content-height) * ${i.height})`,t.style.left=`calc(var(--interactive-content-width) * ${i.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${i.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function a(e,t,i,n){if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?n:i==="a"?n.call(e):n?n.value:t.get(e)}function E(e,t,i,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(e,i):s?s.value=i:t.set(e,i),i}var Ct,zt,He;class Wi{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",zt).call(this)}addControlFactory(t,i){this.factories.set(t.trim().toLowerCase(),i),a(this,Ct,"m",zt).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",zt).call(this)}}Ct=new WeakSet,zt=function(){this.controls=a(this,Ct,"m",He).call(this)},He=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((i,n)=>{const s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...i,r(n)]:[...i]},[])};const Hi=(e,t)=>{if(e.type.trim().toLowerCase()==="choice")return new Jn(e,t)};class Jn extends Wi{constructor(t,i){super(t),this.rootElement=i!=null?i:Pi(),this.layout=new Di(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Bi),this.addControlFactory("text",Yn),this.addControlFactory("area",Fi)}createView(t){const i=document.createElement("div");return i.classList.add(`${q}-${this.container.id}`),this.layout.setContainerLayout(i),this.controls.forEach(n=>{const s=n.createView({parent:i,layoutFn:this.layout.setControlLayout});n.setEvents(s,t)}),this.rootElement.append(i),this.isRemoved=!1,i}hide(){const t=this.getElement();t&&(t.style.visibility="hidden")}show(){const t=this.getElement();t&&(t.style.visibility="visible")}enable(){const t=this.getElement();t&&(this.controls.forEach(i=>i.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){const t=this.getElement();t&&(this.controls.forEach(i=>i.disable()),t.style.opacity=zn,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${q}-${this.container.id}`)}}function Ui(e,t){let i;return(...n)=>{clearTimeout(i),i=setTimeout(()=>e(...n),t)}}const Pt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},It=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,Ae=e=>It(e,Pt.Object),ge=e=>It(e,Pt.String),je=e=>It(e,Pt.Array),Gi=e=>It(e,Pt.Number),tr=e=>It(e,Pt.Function),Ue=e=>Gi(e)&&!isNaN(e),At=e=>Ae(e)&&Object.keys(e).length===0,zi=e=>je(e)&&!e.length,Ft=(e,t)=>ge(e)&&(t?e.trim():e).length,qi=window.navigator.userAgent.toLowerCase(),er=/mobi/i.test(qi);qi.indexOf("android")>-1;const ir="video_interactive",nr="videoint",rr=250;class sr{constructor(t){this.onResize=i=>{this.isReady&&(!i[0].contentRect.width||!i[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:i[0].contentRect.width,height:i[0].contentRect.height}))},this.handleChapterChange=i=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(i!=null&&i.id)){(n=this.onError)===null||n===void 0||n.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(i.id),this.ngEditor.selectChapter(i.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=i.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(i,n=[])=>{var s;if(!Gi(i.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)===null||s===void 0||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await Vn(this.lang,ir,nr)}catch(o){console.log("Unable to load graph language pack")}const{GraphEditor:c}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new c(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:r}),this.ngEditor.on("control",({name:o,chapterId:l})=>{o==="openPreview"&&this.onOpenPreviewClick(l)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo={...o}})}this.visitedChapterIds=new Set(n),i.metadata.id!==this.currentManifestId?(this.ngEditor.update(i),this.currentManifestId=i.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0},this.init(t)}init({root:t,onOpenPreviewClick:i,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=i,this.onError=n,this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=ar(t),this.resizeObserver=new ResizeObserver(Ui(this.onResize,rr)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var t,i;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)===null||t===void 0||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(i=this.ngEditor)===null||i===void 0||i.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function ar(e){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height="100%",t.style.width="100%",t.style.display="none",e.append(t),t}const or=3e3,lr=()=>{let e=[],t=null;return{setPlayer:c=>{t=c},setContainers:c=>{e=c},deleteContainer:c=>{e=e.filter(o=>o.id!==c)},getNextInteractiveTime:(c=or)=>{if(!e.length||t===null)return null;let o=-1,l=!1;const h=Math.round(t.info.position$.getValue()*1e3);for(const v of e){const u=v.startTime-c;if(u<=h&&(h<=v.endTime||v.endTime===null)){l=!0;break}h<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},Yt=(e="",t="")=>{e=e.split("."),t=t.split(".");let i=0;for(let n=0;n<Math.max(e.length,t.length)&&!i;n++)e[n]>t[n]?i=1:e[n]<t[n]?i=-1:i=0;return i},cr="3.1",Ge={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},hr={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},dr=e=>{const t=[];for(const i of e.chapters){let n;const s=[];for(const{isDefault:o,...l}of i.branches)o&&(n=l.id),s.push(l);let r=[];const c=[];for(const{fallbackStrategy:o,...l}of i.containers){const h=!!l.endTime;let v=[hr];switch(o){case"await":h?v=[]:r=[];break;case"default":{const u={type:"onSuspense",action:{type:Ge.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?v=[u]:r=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:Ge[o],args:{}}};h?v=[u]:r=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:Wn(),events:v})}t.push({...i,containers:c,events:r,branches:s})}return e.metadata.version=cr,e.metadata.updated=new Date().toISOString(),{...e,chapters:t}},ur="3.2",fr=e=>{if(!e.media){const{media:t,...i}=e.metadata;return{...e,metadata:{...i,version:ur},media:t}}return e},vr="3.3",pr=(e=[])=>({edit:{chapters:e},view:{}}),ze={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},yr=e=>{var t;const i=[],n=[];for(const s of e.chapters){const{id:r,x:c,y:o,...l}=s,h=l.containers.map(v=>{var u;return{...v,controls:v.controls.map(({subtype:p,type:g,...b})=>({...b,type:p!=null?p:g})),events:!((u=v.events)===null||u===void 0)&&u.length?v.events:[ze]}});i.push({id:r,...l,containers:h,events:!((t=l.events)===null||t===void 0)&&t.length?l.events:[ze]}),n.push({id:r,x:c,y:o})}return{...e,chapters:i,graph:pr(n),metadata:{...e.metadata,version:vr}}},mr=[{version:"3.0",migrate:dr},{version:"3.1",migrate:fr},{version:"3.2",migrate:yr}],gr=e=>mr.reduce((t,i)=>Yt(t.metadata.version,i.version)?t:i.migrate(t),e),br=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),R=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var ht;(function(e){e.GO_NEXT_BUTTON="GO_NEXT_BUTTON",e.GO_NEXT_AREA="GO_NEXT_AREA",e.WATCH_AGAIN="WATCH_AGAIN",e.OPEN_GRAPH="OPEN_GRAPH",e.CLOSE_GRAPH="CLOSE_GRAPH"})(ht||(ht={}));const qe={metadata:"Object",chapters:"Array"},Er="3.0.0",Cr="3.3.0",Qi=e=>{const t=Yt(e,Er);return t===-1?!1:t===0?!0:Yt(e,Cr)!==1},_r=e=>{if(!Ae(e))return!1;for(const t in qe)if(!e[t]||!It(e[t],qe[t]))return!1;return Qi(e.metadata.version)},Yi=e=>e.type===br.Text;class S{constructor(t,i,...n){this.severity=t,this.category=i,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}S.Severity={RECOVERABLE:1,CRITICAL:2};S.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Ki{constructor(){this.listeners={}}addListener(t,i){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(i),this}on(t,i){return this.addListener(t,i)}once(t,i){this.listeners[t]=this.listeners[t]||[];const n=()=>{i(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,i){return this.removeListener(t,i)}reset(){this.listeners={}}removeListener(t,i){const n=this.listeners[t];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===i){n.splice(s,1);break}return this}emit(t,...i){const n=this.listeners[t];return n?(n.forEach(s=>{s(...i)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}}class wr{constructor(t){this.addFn=(i,n=!1)=>{tr(i)&&(this.fns.push(i),n&&this.updateFn())},this.removeFn=(i,n=!1)=>{this.fns=this.fns.filter(s=>s!==i),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(i=>i()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Ir{constructor(t){var i,n;this.loaders={chapterLoaders:(i=t==null?void 0:t.chapterLoaders)!==null&&i!==void 0?i:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(t,i){return Sr(...this.loaders[t])(i)}}function Sr(...e){return async function(i){const n=[...e];for(;n.length>0;)i=await n.shift()(i);return i}}function Kt(e,t,i){return e?{...e,[t]:e[t]?[i,...e[t]]:[i]}:{[t]:[i]}}function be({actions:e,errors:t,chapterId:i,...n}){if(i){const s=e.getManifest(),r=e.getChapter(s.chapters,i);if(r){const c=e.getMedia(s.media,r.videoId),o=e.getGraph(s.graph,r.id);return c?{...n,actions:e,errors:t,result:{chapter:r,media:c,graph:o}}:{...n,errors:Kt(t,be.name,"Could not find media"),actions:e}}}return{...n,errors:Kt(t,be.name,"Could not find chapter"),actions:e}}class Qe{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,i,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:i,options:n})}removeEventListener(t,i){if(!(t in this.listeners))return;const n=this.listeners[t];for(let s=0,r=n.length;s<r;s++)if(n[s].callback===i){n.splice(s,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const n=this.listeners[t.type].slice();for(let s=0,r=n.length;s<r;s++){const c=n[s];try{c.callback.call(this,t)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(t.type,c.callback)}return!t.defaultPrevented}}class Xi extends Qe{constructor(){super(),this.listeners||Qe.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class Tr{constructor(){Object.defineProperty(this,"signal",{value:new Xi,writable:!0,configurable:!0})}abort(t){let i;try{i=new Event("abort")}catch(s){typeof document!="undefined"?document.createEvent?(i=document.createEvent("Event"),i.initEvent("abort",!1,!1)):(i=document.createEventObject(),i.type="abort"):i={type:"abort",bubbles:!1,cancelable:!1}}let n=t;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(s){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(Tr.prototype[Symbol.toStringTag]="AbortController",Xi.prototype[Symbol.toStringTag]="AbortSignal");function Zi(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function $r(e){typeof e=="function"&&(e={fetch:e});const{fetch:t,Request:i=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=e;if(!Zi({fetch:t,Request:i,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:t,Request:r};let r=i;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(h,v){let u;v&&v.signal&&(u=v.signal,delete v.signal);const p=new i(h,v);return u&&Object.defineProperty(p,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),p},r.prototype=i.prototype);const c=t;return{fetch:(l,h)=>{const v=r&&r.prototype.isPrototypeOf(l)?l.signal:h?h.signal:void 0;if(v){let u;try{u=new DOMException("Aborted","AbortError")}catch(g){u=new Error("Aborted"),u.name="AbortError"}if(v.aborted)return Promise.reject(u);const p=new Promise((g,b)=>{v.addEventListener("abort",()=>b(u),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([p,c(l,h)])}return c(l,h)},Request:r}}const Le=Zi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ji=Le?$r({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ye=Le?Ji.fetch:window.fetch;Le?Ji.Request:window.Request;const Rr=async e=>{try{let t,i;if(Ae(e))t=e;else if(ge(e)){i=new URL(e).href;const s=await Ye(i);if(!s.ok)return{};t=await s.json()}else return{};if(!_r(t))return{};const n=t.metadata.media;if(ge(n)&&!t.media)try{let s;i?s=new URL(n,i).href:(s=new URL(n).href,i=s);const r=await Ye(s);if(!r.ok)throw new Error;t.metadata.media=await r.json()}catch(s){return jr(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:i}}catch(t){return{}}};async function xr(e){const{manifest:t,manifestURL:i}=await Rr(e),n=gr(t);return n.media=Or(n.media,i),delete n.metadata.media,n}function ne(e,t){return e.find(i=>i.id===t)}function Ke(e,t){var i,n;return!((i=e.edit)===null||i===void 0)&&i.chapters?e.edit.chapters.find(s=>s.id===t):!((n=e.view)===null||n===void 0)&&n.chapters?e.view.chapters.find(s=>s.id===t):void 0}function Xe(e,t){return e.videos.find(i=>i.id===t)}function Or(e,t){return{...e,videos:e.videos.map(i=>({...i,variants:i.variants.map(n=>{const s=Ar(n.url,t);return{...n,url:s||n.url}})}))}}function Ar(e,t){try{return new URL(e,t).href}catch(i){return""}}function jr(e){return Yt(e,"3.2.0")>=0}const A=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Pe=e=>je(e)&&!zi(e),Jt=e=>e.order==="end",Lr=e=>je(e.containers)&&!zi(e.containers)&&Jt(e),Pr=(e,t)=>{var i;const n=e*1e3;return Pe(t.controls)&&n<((i=t.startTime)!==null&&i!==void 0?i:0)},Ze=(e,t)=>{var i,n;const s=e*1e3;return Pe(t.controls)&&s>=((i=t.startTime)!==null&&i!==void 0?i:0)&&s<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Lt=e=>e.some(t=>t.action.type==="expect"),Je=e=>e.find(t=>t.action.type==="expect"),Mr=e=>(e==null?void 0:e.length)===1,tn=e=>Mr(e)&&Yi(e[0]),Nr=({fn:e,type:t=1},...i)=>(...n)=>t?e(...n,...i):e({...n[t],...i[t]}),kr=(e=[])=>e.reduce((t,i,n)=>{var s,r,c;const o=((s=i==null?void 0:i.controls)!==null&&s!==void 0?s:[]).filter(l=>!Yi(l));if(Pe(o)){const l=[(r=i.startTime)!==null&&r!==void 0?r:0,(c=i.endTime)!==null&&c!==void 0?c:1/0],h=i.id;if(!n)t.push({subjects:[h],range:l});else{const v=[];let u=-1/0,p=1/0,g=[];const b=[];for(let I=0;I<t.length;I++){const d=t[I];if(b.push(...d.subjects),d.range[0]<p&&(p=d.range[0]),d.range[1]>u&&(u=d.range[1]),d.range[0]<=l[0]&&d.range[1]>=l[1])return t[I].subjects.push(h),t;l[0]>=d.range[0]&&l[0]<=d.range[1]&&(v.push(I),g=g.concat(d.subjects),l[0]=d.range[0]),l[1]>=d.range[0]&&l[1]<=d.range[1]&&(v.push(I),g=g.concat(d.subjects),l[1]=d.range[1])}if(b.push(h),l[0]<=p&&l[1]>=u)return[{subjects:b,range:l}];v.length&&v.reverse().forEach(I=>{t.splice(I,1)}),t.push({subjects:g.concat([h]),range:l})}}return t},[]).sort((t,i)=>t.range[0]-i.range[0]),Vr=(e,t)=>Lt(e.events)?!1:t.some(({container:i})=>i.container.id!==e.id&&Lt(i.container.events)&&i.container.endTime===e.endTime&&!i.isRemoved);class Fr extends Ir{constructor(t,i){super(t),this.onError=i,this.prevChapter$=new W(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var i;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Kt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const s=await xr((i=n.result)!==null&&i!==void 0?i:t);return this.manifest=s,this}async setInitial(){return this.setNext()}async setNext(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);const i=await this.exec("chapterLoaders",be({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Ke,getChapter:ne,getMedia:Xe,getByBranches:this.getByBranches.bind(this),addErrorMessage:Kt},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest.metadata.initChapterId)||null}getByChapterId(t=this.manifest.metadata.initChapterId){const i=ne(this.manifest.chapters,t);if(i){const n=Xe(this.manifest.media,i.videoId),s=Ke(this.manifest.graph,i.id);if(n)return{chapter:i,media:n,graph:s}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{const i=ne(this.manifest.chapters,t);return this.getByBranches(i==null?void 0:i.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{const s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return Jt(this.chapter)}}const Br=e=>{const t=e.variants.find(i=>{var n;return((n=i.payload)===null||n===void 0?void 0:n.type)==="vk"});if(t&&"payload"in t){const[i,n]=t.payload.id.split("_");return[i,n]}return[]},_={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ti={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Dr(){const e=new Map;function t({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...c}){const o=e.get(s),l={...c};return o?o[r]=l:e.set(s,{[r]:l}),{listId:s,itemId:r,...c}}function i(s,r){var c,o,l;const h=e.get(s);if(h){if(r)return(c=h[r])===null||c===void 0||c.player.destroy(),(o=h[r])===null||o===void 0||o.container.remove(),(l=h[r])===null||l===void 0||l.subscription.unsubscribe(),delete h[r],Object.keys(h).length||e.delete(s),!0;for(const v of Object.values(h))v.player.destroy(),v.container.remove();return e.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(const s of e)i(s[0])}return{createPlayer:t,removePlayer:i,map:e,removeAll:n}}function ei(e,t=[]){var i,n,s;let r={},c;const o=!t.length;for(const l of e.variants)if(!c&&"cover"in l&&(c=l.cover),"url"in l)switch(l.type.toLowerCase()){case"mp4":(o||t.includes("mp4"))&&(r.MPEG={...r.MPEG,[(i=l.standard)!==null&&i!==void 0?i:"Invariant quality"]:l.url});break;case"mpeg":(o||t.includes("mpeg"))&&(r.MPEG={...r.MPEG,[(n=l.standard)!==null&&n!==void 0?n:"Invariant quality"]:l.url});break;case"hls":(o||t.includes("hls"))&&(r={...r,HLS:{type:"url",url:l.url}});break;case"dash":(o||t.includes("dash"))&&(r={...r,DASH_SEP:{compatibilityMode:!0,type:"url",url:l.url}});break}return{sources:r,thumbUrl:c,title:(s=e.title)!==null&&s!==void 0?s:""}}const Bt=(e,t)=>{const i=e.info.currentQuality$.getValue(),n=e.info.availableQualities$.getValue();i!==t&&n.includes(t)&&(e.setQuality(t),e.setAutoQuality(!1))},qt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Wr=2;function Hr(e){const t=Dr();let i,n;const s=new Ki;let r={},c=!1,o=null,l=!1,h;e&&v(e);function v(y){o=y}function u(y,C,m){var $;if(!o)throw Error("need to set interactive controller");const j=(($=t.map.get(y))!==null&&$!==void 0?$:{})[C];if(j){r={chapterId:m,listId:y,itemId:C,...j};const w=r.player;n=w.info.currentQuality$.subscribe(k=>{if(!(!k||!w.info.position$.getValue())){i=k;for(const D of t.map)Object.values(D[1]).forEach(({player:M})=>{w.info.isAutoQualityEnabled$.getValue()||Bt(M,k)})}}),j.container.remove(),c=!1,o.setPlayer(j.player),l||(o.init(),l=!0),s.emit(qt.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function p(y,C,m){if(!o)throw Error("need to set interactive controller");if(At(r)||y!==r.itemId)return;if(m>=0&&!c){const O=o.getChapterBranches();c=!0;const j=new Set;for(const w of O)j.has(w.media.id)||(await b({media:w.media,chapterId:w.chapter.id,setAsActive:!1,title:w.chapter.label}),j.add(w.media.id))}}async function g({chapter:{id:y},media:C}){if(At(r))return;n==null||n.unsubscribe();const m=r.player.info.muted$.getValue(),$=r.player.info.currentQuality$.getValue(),O=r.player.info.isAutoQualityEnabled$.getValue(),j=r.player.info.volume$.getValue(),w=r.player.info.currentPlaybackRate$.getValue(),k=!O;let D=!1;for(const M of t.map)if(M[0]===C.id){const Q=Object.keys(M[1]);for(const X of Q)X===r.itemId?(Q.length<Wr||(D=!0),t.removePlayer(M[0],X)):(D=!0,u(M[0],X,y),k?Bt(r.player,$):r.player.setAutoQuality(!0),r.player.setVolume(j),r.player.setMuted(m),r.player.setPlaybackRate(w))}else t.removePlayer(M[0]);D||(await b({media:C,chapterId:y,setAsActive:!0,playbackRate:w}),k?Bt(r.player,$):r.player.setAutoQuality(!0),r.player.setVolume(j),r.player.setMuted(m))}async function b({media:y,chapterId:C,prefetch:m=!0,setAsActive:$=!0,autoplay:O=!1,preferredExt:j,title:w,playbackRate:k}){var D,M,Q;const X=Math.random().toString(),vt=document.createElement("div");h.append(vt);const Nn=(D=r==null?void 0:r.player)===null||D===void 0?void 0:D.info.isAutoQualityEnabled$.getValue();let kt;if(!((M=o==null?void 0:o.options)===null||M===void 0)&&M.vkVideoLoader){const Vt=Br(y);Vt.length&&(kt=await o.options.vkVideoLoader(...Vt))}const ke={container:vt,...((Q=kt==null?void 0:kt.videos)===null||Q===void 0?void 0:Q[0])||{sources:ei(y,j).sources},title:w},ot=new Hn;ot.initVideo(ke);const kn=vt.lastChild,Ve=new Zt;Ve.add(ot.info.position$.subscribe(function(Vt){p(X,ot.info.duration$.getValue(),Vt)})).add(ot.events.canplay$.subscribe(function(){Nn||Bt(ot,i),k&&ot.setPlaybackRate(k)})),kn&&(vt.style.display="none",vt.classList.add(C));const pt=t.createPlayer({listId:y.id,itemId:X,player:ot,container:vt,sources:ei(y,j).sources,config:ke,subscription:Ve});return $&&u(y.id,pt.itemId,C),O&&pt.player.play(),m&&!O&&pt.player.prepare(),s.emit(qt.playerCreated,pt.player),{player:pt.player,config:pt.config}}function I(){d(),o=null}function d(){o==null||o.off(_.chapterChanged,g),t.removeAll(),r={},l=!1,c=!1}async function f({container:y}){if(!o)throw Error("need to set interactive controller");d(),h=y;const{media:C,chapter:m}=o.getCurrentChapter();if(C){o.on(_.chapterChanged,g);const{player:$,config:O}=await b({media:C,chapterId:m.id,title:m.label});return s.emit(qt.initiated,{container:y,media:C,chapterId:m.id}),{player:$,config:O}}else console.error("not found")}return{...t,on:s.on.bind(s),off:s.off.bind(s),init:f,setInteractiveController:v,createPlayer:b,removeAll:I,getActivePlayer:function(){return r}}}class Ur{constructor({player:t,container:i,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:c,ignoreContainerEvent:o,permanentTextControls:l,disabledControls$:h,onRemove:v}){this.hide=()=>{setTimeout(()=>{var u,p;this.gameState!==A.end&&(Lt(this.container.container.events)&&this.gameState===A.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==A.interactive&&((p=(u=this.container).hide)===null||p===void 0||p.call(u)),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var u,p,g,b;if(this.gameState===A.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(b=(g=this.container).show)===null||b===void 0||b.call(g),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const d=Nr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(f,y)=>{this.isSelectedControlEvent=!0,f!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===A.end||this.gameState===A.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1}))},isEOV:()=>this.gameState===A.end});this.container.createView(d),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((p=(u=this.container).disable)===null||p===void 0||p.call(u))}},this.onEndOfVideo=()=>{this.gameState=A.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var u,p;if(((u=this.player.experimental.element$.getValue())===null||u===void 0?void 0:u.readyState)<1||[A.destroyed,A.removed].includes(this.gameState)&&!this.isPermanentText)return;const b=this.player.getExactTime();if(Pr(b,this.container.container))this.gameState!==A.beforeInteractive&&(this.gameState=A.beforeInteractive,this.onBeforeStartTime());else if(Ze(b,this.container.container))this.gameState!==A.interactive&&(this.gameState=A.interactive,this.onStartTime());else if(this.gameState!==A.afterInteractive){const f=this.gameState;this.gameState=A.afterInteractive,f===A.interactive&&this.onEndTime()}else this.gameState!==A.destroyed&&!this.isPermanentText&&this.removeView();const I=Ze(b,this.container.container),d=this.container.container.startTime?[this.container.container.startTime,(p=this.container.container.endTime)!==null&&p!==void 0?p:1/0]:[];this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:d,currentTime:b,isInteractiveTime:I})},this.container=i,this.branches=n,this.selectBranches=s,this.subscription=new Zt,this.player=t,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.isPermanentText=l&&tn(i.container.controls),this.disabledControls$=h,this.onRemove=v,this.globalEventEmitter=c,this.gameState=A.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(t=>{var i,n,s,r;t?(n=(i=this.container).disable)===null||n===void 0||n.call(i):(r=(s=this.container).enable)===null||r===void 0||r.call(s)}))}selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?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:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);const t=Lt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,i;(i=(t=this.container).hide)===null||i===void 0||i.call(t),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=A.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=A.removed,(t=this.onRemove)===null||t===void 0||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=A.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!==null&&t!==void 0?t:1/0,id:this.container.container.id})}}function Gr(){const e={};function t(){for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&delete e[o];return!0}function i(o){const l={};for(const h in e)+h<=o&&(l[h]=e[h]);return l}function n(o){const l={};for(const h in e)+h>=o&&(l[h]=e[h]);return l}function s({timestamp:o,priority:l,initiator:h}){var v;if(Ue(o)){const u=(v=e[o])!==null&&v!==void 0?v:null;if(u&&Ft(l,!0)){let p={};const g=u[l];if(g&&(p={...p,...g}),p=At(p)?null:p,p&&Ft(h,!0)){const b=p[h];return b!=null?b:null}return p}return u}return null}function r({timestamp:o,priority:l,initiator:h}){if(Ue(o))if(e[o]){if(Ft(l,!0))if(e[o][l]){if(Ft(h,!0))if(e[o][l][h]){if(delete e[o][l][h],!At(e[o][l]))return!0}else return!1;if(delete e[o][l],!At(e[o]))return!0}else return!1;return delete e[o]}else return!1}function c({timestamp:o,priority:l,initiator:h,...v}){var u,p,g;!((p=(u=e[o])===null||u===void 0?void 0:u[l])===null||p===void 0)&&p[h]?e[o][l][h].push({...v}):!((g=e[o])===null||g===void 0)&&g[l]?e[o][l]={...e[o][l],[h]:[{...v}]}:e[o]?e[o]={...e[o],[l]:{[h]:[{...v}]}}:e[o]={[l]:{[h]:[{...v}]}}}return{map:e,remove:r,add:c,removeAll:t,get:s,getLte:i,getGte:n}}const zr=[R.expect,R.setNextBranch],qr=1/0;function ii(e){let t=e,i;const n=Qr(),s=new Gr;let r;const c=()=>{p(),d()},o=f=>{s.add.call(void 0,f),g()},l=(f=[])=>{for(const y of f)if(y.action(),zr.includes(y.actionType))break},h=(f=1/0)=>{var y,C,m;const $=Dt((y=s.get({timestamp:f,priority:"control"}))!==null&&y!==void 0?y:{}),O=Dt((C=s.get({timestamp:f,priority:"container"}))!==null&&C!==void 0?C:{}),j=Dt((m=s.get({timestamp:f,priority:"chapter"}))!==null&&m!==void 0?m:{});return[...$,...O,...j]},v=f=>{n.isReady(f)&&l(h(f))},u=()=>{var f;l([...Dt((f=s.get({timestamp:1/0,priority:"chapter"}))!==null&&f!==void 0?f:{})])},p=()=>{i&&(r==null||r.unsubscribe(),i=void 0)},g=()=>{i||(i=()=>setTimeout(()=>{v(1/0)}),r=t.events.ended$.subscribe(i))},b=f=>{p(),t=f},I=f=>{f.priority==="container"&&n.resetCalled(f.timestamp),s.remove(f)},d=()=>{n.release(),s.removeAll()};return{setPlayer:b,add:o,remove:I,exec:v,execEndOfVideo:u,listen:g,unlisten:p,release:c,containersEventsCallState:n,getPreparedToExecActions:h}}function Qr(){const e=new Map;return{setCalled:({timestamp:c,id:o})=>{const l=e.get(c);l&&l[o]!==void 0&&(l[o]=!0)},setData:(c=[])=>{var o,l;for(const h of c){const v=(o=h.endTime)!==null&&o!==void 0?o:qr,u=(l=e.get(v))!==null&&l!==void 0?l:{};e.set(v,{...u,[h.id]:!1})}},resetCalled:c=>{const o=e.get(c);if(o)for(const l in o)o[l]=!1},isReady:c=>{const o=e.get(c);return o?!Object.values(o).some(l=>!l):!0},release:()=>e.clear()}}function Dt(e){return Object.values(e).flat().sort(t=>t.actionType===R.expect?-1:1)}const Yr=(e,t)=>{const{height:i,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(i&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:s,clientWidth:r}=t.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};const c=i/n,o=s/r;let l,h;return o>c?(h=r,l=r*c):o<c?(h=s/c,l=s):(h=r,l=s),{videoContentWidth:h,videoContentHeight:l}},Kr=250;function Xr(e){let t=()=>{};const i=new ResizeObserver(o=>{r(o),t=r.bind(null,o)});function n(o){const{parentElement:l,player:h}=e();if(l&&h){const{videoContentWidth:v,videoContentHeight:u}=Yr(l,h);l.style.setProperty("--interactive-content-width",`${v}px`),l.style.setProperty("--interactive-content-height",`${u}px`),l.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),l.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function s(){const{parentElement:o}=e();o.removeAttribute("style")}const r=Ui(o=>{const{fns:l=[]}=e();n(o);for(const h of l)h()},Kr);function c(){t=void 0,i.disconnect(),s()}return{resizeObserver:i,calc:()=>{t()},release:c}}class Zr{constructor(){this.map={}}push(t,i){t in this.map?this.map[t].push(i):this.map[t]=[i]}get(t){const i=this.map[t];return i?i.slice():null}getAll(){const t=[];for(const i in this.map)t.push(...this.map[i]);return t}remove(t,i){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==i),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}size(){return Object.keys(this.map).length}keys(){return Object.keys(this.map)}}const Jr=e=>Math.floor(Math.random()*e),ts=e=>{let t=e.length,i=1/0,n=null;for(;t--;)e[t].weight<i&&(i=e[t].weight,n=e[t]);return n},es=e=>{let t=e.length,i=-1/0,n=null;for(;t--;)e[t].weight>i&&(i=e[t].weight,n=e[t]);return n},is=e=>{const t=e.length,i=Jr(t);return e[i]},ni=1,ns=e=>{var t,i;let n=0;for(let r=0;r<e.length;++r)n+=(t=e[r].weight)!==null&&t!==void 0?t:ni;const s=Math.random()*n;n=0;for(let r=0;r<e.length-1;++r)if(n+=(i=e[r].weight)!==null&&i!==void 0?i:ni,n>=s)return e[r];return e[e.length-1]},ri=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),re=(e,t=!1)=>({...e,args:t?{...e.args,...ri}:{...ri,...e.args}}),si=({globalEventEmitter:e,player:t,interactiveEvents:i,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},c=({action:d,controlType:f,controlId:y,containerId:C,branches:m=[],onEvent:$,isEOV:O=()=>!1,isDisabled:j=()=>!1})=>{const w=re(d,O()),k={timestamp:1/0,priority:"control",initiator:y,actionType:w.type},D=j(),M=e.emit.bind(e,_.interactives,{subjectId:y,subjectType:f,subjectName:"control",type:D?L.actionChoiceCanceled:L.actionChoice,actionType:d.type,payload:{containerId:C,...w.args}});if(D){M();return}switch(w.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const Q=m.find(X=>X.id===w.args.branchId);if(!Q)return;$(w.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),w.args.shouldOpenNow?b({subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{chapterId:Q.chapterId,autoSelect:!1}}):(i.add({...k,action:b.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{chapterId:Q.chapterId,autoSelect:!1}})}),n==null||n());return}case R.continuePlayback.trim().toLowerCase():{$(w.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),w.args.shouldOpenNow?g({subjectId:y,subjectName:"control",subjectType:f,action:d}):i.add({...k,action:g.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:d})});return}case R.openURI.trim().toLowerCase():{$(w.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),w.args.shouldOpenNow?I({subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{URI:d.args.uri}}):(i.add({...k,action:I.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{URI:d.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),e.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:d,container:{id:f,endTime:y},branches:C=[],isEOV:m=!1,autoSelected:$=!1})=>{const O=re(d,m),j={timestamp:!O.args.shouldOpenNow||m?1/0:y,priority:"container",initiator:f,actionType:O.type},w=e.emit.bind(e,_.interactives,{subjectId:f,subjectName:"container",type:L.actionChoice,actionType:O.type,payload:O.args});switch(O.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const k=C.find(D=>D.id===O.args.branchId);if(!k)return;w(),i.add({...j,action:b.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{chapterId:k.chapterId,autoSelect:$}})}),n==null||n();return}case R.setMaxWeightBranch.trim().toLowerCase():return;case R.setMinWeightBranch.trim().toLowerCase():return;case R.setRandomBranch.trim().toLowerCase():return;case R.setWeightlessRandomBranch.trim().toLowerCase():return;case R.continuePlayback.trim().toLowerCase():{w(),i.add({...j,action:g.bind(null,{subjectId:f,subjectName:"container",action:O})});return}case R.openURI.trim().toLowerCase():{w(),i.add({...j,action:I.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{URI:d.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),e.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:d,branches:f,isEOV:y=!1}){const C=Je(d.events);if(C){const m=re(C.action,y);e.emit(_.interactives,{subjectId:d.id,subjectName:"container",type:L.actionChoice,actionType:m.type,payload:m.args}),i.add({timestamp:y?1/0:d.endTime,priority:"container",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"container"})}),s.isExpect=!0}else for(const m of d.events)o({action:m.action,container:d,branches:f,isEOV:y})}const h=({chapterId:d,action:f,branches:y=[]})=>{const C=e.emit.bind(e,_.interactives,{subjectId:d,subjectName:"chapter",type:L.actionChoice,actionType:f.type,payload:f.args});switch(f.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const m=y.find($=>$.id===f.args.branchId);return m!=null&&m.chapterId?(C(),b.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setWeightlessRandomBranch.trim().toLowerCase():{const m=is(y);return m!=null&&m.chapterId?(C(),b.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setRandomBranch.trim().toLowerCase():{const m=ns(y);return m!=null&&m.chapterId?(C(),b.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMaxWeightBranch.trim().toLowerCase():{const m=es(y);return m!=null&&m.chapterId?(C(),b.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMinWeightBranch.trim().toLowerCase():{const m=ts(y);return m!=null&&m.chapterId?(C(),b.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.continuePlayback.trim().toLowerCase():return C(),g.bind(null,{subjectId:d,subjectName:"chapter",action:f});case R.openURI.trim().toLowerCase():return C(),I.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{URI:f.args.uri}});default:console.error("Unexpected chapter event"),e.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(d){const f=Je(d.events);if(f){if(Jt(d))return;e.emit(_.interactives,{subjectId:d.id,subjectName:"chapter",type:L.actionChoice,actionType:f.action.type,payload:f.action.args}),i.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"chapter"})})}else d.events.forEach(y=>{const C=h({chapterId:d.id,action:y.action,branches:d.branches});C&&i.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:y.action.type,action:C})})}const u=({subjectId:d,subjectName:f,action:y})=>{var C;t.pause(),e.emit(_.interactives,{subjectId:d,subjectName:f,type:L.actionExecution,actionType:(C=y==null?void 0:y.type)!==null&&C!==void 0?C:R.expect})},p=({subjectId:d,subjectName:f})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),e.emit(_.interactives,{subjectId:d,subjectName:f,type:L.actionExecution,actionType:"after-expect"})},g=({subjectId:d,subjectName:f,subjectType:y,action:C})=>{e.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:L.actionExecution,actionType:C.type})},b=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{m.behaviour="change-chapter",e.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:L.actionExecution,actionType:C.type,payload:m})},I=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{if(!m.URI)return;const $=window.open(m.URI,"_blank","noopener,noreferrer");$&&($.opener=null),e.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:L.actionExecution,actionType:C.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:h,onExpectEvent:u,expectEventHandler:p,setManifestChapterEvents:v,setManifestContainerEvents:l,stopExpect:r,state:s}};var se=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function rs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Wt=function(e){return e&&e.Math==Math&&e},at=Wt(typeof globalThis=="object"&&globalThis)||Wt(typeof window=="object"&&window)||Wt(typeof self=="object"&&self)||Wt(typeof se=="object"&&se)||function(){return this}()||se||Function("return this")(),ut=function(e){try{return!!e()}catch(t){return!0}},ss=ut,te=!ss(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),as=te,en=Function.prototype,ai=en.apply,oi=en.call,os=typeof Reflect=="object"&&Reflect.apply||(as?oi.bind(ai):function(){return oi.apply(ai,arguments)}),nn=te,rn=Function.prototype,Ee=rn.call,ls=nn&&rn.bind.bind(Ee,Ee),St=nn?ls:function(e){return function(){return Ee.apply(e,arguments)}},sn=St,cs=sn({}.toString),hs=sn("".slice),an=function(e){return hs(cs(e),8,-1)},ds=an,us=St,on=function(e){if(ds(e)==="Function")return us(e)},Ce=typeof document=="object"&&document.all,fs=typeof Ce=="undefined"&&Ce!==void 0,ln={all:Ce,IS_HTMLDDA:fs},cn=ln,vs=cn.all,ft=cn.IS_HTMLDDA?function(e){return typeof e=="function"||e===vs}:function(e){return typeof e=="function"},hn={},ps=ut,Mt=!ps(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),ys=te,Ht=Function.prototype.call,Me=ys?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},dn={},un={}.propertyIsEnumerable,fn=Object.getOwnPropertyDescriptor,ms=fn&&!un.call({1:2},1);dn.f=ms?function(t){var i=fn(this,t);return!!i&&i.enumerable}:un;var vn=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},gs=St,bs=ut,Es=an,ae=Object,Cs=gs("".split),_s=bs(function(){return!ae("z").propertyIsEnumerable(0)})?function(e){return Es(e)=="String"?Cs(e,""):ae(e)}:ae,pn=function(e){return e==null},ws=pn,Is=TypeError,yn=function(e){if(ws(e))throw Is("Can't call method on "+e);return e},Ss=_s,Ts=yn,$s=function(e){return Ss(Ts(e))},li=ft,mn=ln,Rs=mn.all,ee=mn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:li(e)||e===Rs}:function(e){return typeof e=="object"?e!==null:li(e)},gn={},oe=gn,le=at,xs=ft,ci=function(e){return xs(e)?e:void 0},bn=function(e,t){return arguments.length<2?ci(oe[e])||ci(le[e]):oe[e]&&oe[e][t]||le[e]&&le[e][t]},Os=St,As=Os({}.isPrototypeOf),js=typeof navigator!="undefined"&&String(navigator.userAgent)||"",En=at,ce=js,hi=En.process,di=En.Deno,ui=hi&&hi.versions||di&&di.version,fi=ui&&ui.v8,z,Xt;fi&&(z=fi.split("."),Xt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!Xt&&ce&&(z=ce.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=ce.match(/Chrome\/(\d+)/),z&&(Xt=+z[1])));var Ls=Xt,vi=Ls,Ps=ut,Ms=at,Ns=Ms.String,Cn=!!Object.getOwnPropertySymbols&&!Ps(function(){var e=Symbol();return!Ns(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&vi&&vi<41}),ks=Cn,_n=ks&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Vs=bn,Fs=ft,Bs=As,Ds=_n,Ws=Object,wn=Ds?function(e){return typeof e=="symbol"}:function(e){var t=Vs("Symbol");return Fs(t)&&Bs(t.prototype,Ws(e))},Hs=String,Us=function(e){try{return Hs(e)}catch(t){return"Object"}},Gs=ft,zs=Us,qs=TypeError,In=function(e){if(Gs(e))return e;throw qs(zs(e)+" is not a function")},Qs=In,Ys=pn,Ks=function(e,t){var i=e[t];return Ys(i)?void 0:Qs(i)},he=Me,de=ft,ue=ee,Xs=TypeError,Zs=function(e,t){var i,n;if(t==="string"&&de(i=e.toString)&&!ue(n=he(i,e))||de(i=e.valueOf)&&!ue(n=he(i,e))||t!=="string"&&de(i=e.toString)&&!ue(n=he(i,e)))return n;throw Xs("Can't convert object to primitive value")},Sn={exports:{}},pi=at,Js=Object.defineProperty,ta=function(e,t){try{Js(pi,e,{value:t,configurable:!0,writable:!0})}catch(i){pi[e]=t}return t},ea=at,ia=ta,yi="__core-js_shared__",na=ea[yi]||ia(yi,{}),ra=na,mi=ra;(Sn.exports=function(e,t){return mi[e]||(mi[e]=t!==void 0?t:{})})("versions",[]).push({version:"3.31.0",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"});var sa=Sn.exports,aa=yn,oa=Object,Tn=function(e){return oa(aa(e))},la=St,ca=Tn,ha=la({}.hasOwnProperty),Ne=Object.hasOwn||function(t,i){return ha(ca(t),i)},da=St,ua=0,fa=Math.random(),va=da(1 .toString),pa=function(e){return"Symbol("+(e===void 0?"":e)+")_"+va(++ua+fa,36)},ya=at,ma=sa,gi=Ne,ga=pa,ba=Cn,Ea=_n,_t=ya.Symbol,fe=ma("wks"),Ca=Ea?_t.for||_t:_t&&_t.withoutSetter||ga,_a=function(e){return gi(fe,e)||(fe[e]=ba&&gi(_t,e)?_t[e]:Ca("Symbol."+e)),fe[e]},wa=Me,bi=ee,Ei=wn,Ia=Ks,Sa=Zs,Ta=_a,$a=TypeError,Ra=Ta("toPrimitive"),xa=function(e,t){if(!bi(e)||Ei(e))return e;var i=Ia(e,Ra),n;if(i){if(t===void 0&&(t="default"),n=wa(i,e,t),!bi(n)||Ei(n))return n;throw $a("Can't convert object to primitive value")}return t===void 0&&(t="number"),Sa(e,t)},Oa=xa,Aa=wn,$n=function(e){var t=Oa(e,"string");return Aa(t)?t:t+""},ja=at,Ci=ee,_e=ja.document,La=Ci(_e)&&Ci(_e.createElement),Pa=function(e){return La?_e.createElement(e):{}},Ma=Mt,Na=ut,ka=Pa,Rn=!Ma&&!Na(function(){return Object.defineProperty(ka("div"),"a",{get:function(){return 7}}).a!=7}),Va=Mt,Fa=Me,Ba=dn,Da=vn,Wa=$s,Ha=$n,Ua=Ne,Ga=Rn,_i=Object.getOwnPropertyDescriptor;hn.f=Va?_i:function(t,i){if(t=Wa(t),i=Ha(i),Ga)try{return _i(t,i)}catch(n){}if(Ua(t,i))return Da(!Fa(Ba.f,t,i),t[i])};var za=ut,qa=ft,Qa=/#|\.prototype\./,Nt=function(e,t){var i=Ka[Ya(e)];return i==Za?!0:i==Xa?!1:qa(t)?za(t):!!t},Ya=Nt.normalize=function(e){return String(e).replace(Qa,".").toLowerCase()},Ka=Nt.data={},Xa=Nt.NATIVE="N",Za=Nt.POLYFILL="P",Ja=Nt,wi=on,to=In,eo=te,io=wi(wi.bind),no=function(e,t){return to(e),t===void 0?e:eo?io(e,t):function(){return e.apply(t,arguments)}},xn={},ro=Mt,so=ut,ao=ro&&so(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),oo=ee,lo=String,co=TypeError,ho=function(e){if(oo(e))return e;throw co(lo(e)+" is not an object")},uo=Mt,fo=Rn,vo=ao,Ut=ho,Ii=$n,po=TypeError,ve=Object.defineProperty,yo=Object.getOwnPropertyDescriptor,pe="enumerable",ye="configurable",me="writable";xn.f=uo?vo?function(t,i,n){if(Ut(t),i=Ii(i),Ut(n),typeof t=="function"&&i==="prototype"&&"value"in n&&me in n&&!n[me]){var s=yo(t,i);s&&s[me]&&(t[i]=n.value,n={configurable:ye in n?n[ye]:s[ye],enumerable:pe in n?n[pe]:s[pe],writable:!1})}return ve(t,i,n)}:ve:function(t,i,n){if(Ut(t),i=Ii(i),Ut(n),fo)try{return ve(t,i,n)}catch(s){}if("get"in n||"set"in n)throw po("Accessors not supported");return"value"in n&&(t[i]=n.value),t};var mo=Mt,go=xn,bo=vn,Eo=mo?function(e,t,i){return go.f(e,t,bo(1,i))}:function(e,t,i){return e[t]=i,e},Gt=at,Co=os,_o=on,wo=ft,Io=hn.f,So=Ja,yt=gn,To=no,mt=Eo,Si=Ne,$o=function(e){var t=function(i,n,s){if(this instanceof t){switch(arguments.length){case 0:return new e;case 1:return new e(i);case 2:return new e(i,n)}return new e(i,n,s)}return Co(e,this,arguments)};return t.prototype=e.prototype,t},Ro=function(e,t){var i=e.target,n=e.global,s=e.stat,r=e.proto,c=n?Gt:s?Gt[i]:(Gt[i]||{}).prototype,o=n?yt:yt[i]||mt(yt,i,{})[i],l=o.prototype,h,v,u,p,g,b,I,d,f;for(p in t)h=So(n?p:i+(s?".":"#")+p,e.forced),v=!h&&c&&Si(c,p),b=o[p],v&&(e.dontCallGetSet?(f=Io(c,p),I=f&&f.value):I=c[p]),g=v&&I?I:t[p],!(v&&typeof b==typeof g)&&(e.bind&&v?d=To(g,Gt):e.wrap&&v?d=$o(g):r&&wo(g)?d=_o(g):d=g,(e.sham||g&&g.sham||b&&b.sham)&&mt(d,"sham",!0),mt(o,p,d),r&&(u=i+"Prototype",Si(yt,u)||mt(yt,u,{}),mt(yt[u],p,g),e.real&&l&&(h||!l[p])&&mt(l,p,g)))},xo=Math.ceil,Oo=Math.floor,Ao=Math.trunc||function(t){var i=+t;return(i>0?Oo:xo)(i)},jo=Ao,On=function(e){var t=+e;return t!==t||t===0?0:jo(t)},Lo=On,Po=Math.min,Mo=function(e){return e>0?Po(Lo(e),9007199254740991):0},No=Mo,ko=function(e){return No(e.length)},Vo=Ro,Fo=Tn,Bo=ko,Do=On;Vo({target:"Array",proto:!0},{at:function(t){var i=Fo(this),n=Bo(i),s=Do(t),r=s>=0?s:n+s;return r<0||r>=n?void 0:i[r]}});var Wo=bn,Ho=Wo,Uo=Ho,Go=Uo("Array","at"),zo=Go,qo=zo,Qo=qo,Yo=Qo,Ti=rs(Yo);const $i=(e,t)=>{const i={};return e.map(n=>{if(!i[n]){const s=t.chapters.find(c=>c.id===n);if(!s)return null;const r=t.media.videos.find(c=>s.videoId===c.id);if(!r)return null;i[n]=An(r)}return i[n]}).filter(Boolean)},Ko=e=>{for(const t of e.variants)if(Xo(t)&&"payload"in t)return t.payload.id},Xo=e=>e.type==="custom"&&"payload"in e&&e.payload.type==="vk",An=e=>{const t=Ko(e);if(!t)return null;const i=t.split("_").pop();return i?parseInt(i,10):null},Zo=(e,t)=>{for(const i of e.media.videos)if(t===An(i)){for(const n of e.chapters)if(n.videoId===i.id)return n.id;return}},Jo=(e,t)=>e.reduce((i,n)=>{const s=Zo(t,n);return s?[...i,s]:i},[]);var tt,Tt,gt,G,we,et,it,Y,bt,$t,Et;const tl=100;class el{constructor({globalEventEmitter:t,videoId:i,interactiveController:n,historyApi:s,historyParams:r}){var c,o,l;this.state={history$:new W([]),hasPrevChapter$:new W(!1),prevChapter$:new W(null),isInitialChapter$:new W(!1),isGoBackLimited$:new W(!1)},tt.set(this,null),Tt.set(this,void 0),gt.set(this,!1),G.set(this,null),we.set(this,null),et.set(this,null),it.set(this,null),Y.set(this,null),bt.set(this,new Zt),$t.set(this,!1),Et.set(this,0),E(this,et,i,"f"),E(this,Y,t,"f"),E(this,it,n,"f"),E(this,tt,s,"f"),E(this,Tt,{maxLength:(r==null?void 0:r.maxLength)||tl},"f"),!((c=this.state)===null||c===void 0)&&c.history$&&a(this,bt,"f")&&((o=a(this,bt,"f"))===null||o===void 0||o.add((l=this.state)===null||l===void 0?void 0:l.history$.subscribe(h=>{var v,u,p,g,b,I;(v=this.state)===null||v===void 0||v.prevChapter$.next(Ti(h,-2)||null),(u=this.state)===null||u===void 0||u.hasPrevChapter$.next(h.length>1),(p=this.state)===null||p===void 0||p.isInitialChapter$.next(this.getInitialChapterId()===((b=(g=a(this,G,"f"))===null||g===void 0?void 0:g.metadata)===null||b===void 0?void 0:b.initChapterId)),(I=this.state)===null||I===void 0||I.isGoBackLimited$.next(a(this,Et,"f")===a(this,Tt,"f").maxLength-1)})))}async setManifest(t){!a(this,it,"f")||!a(this,Y,"f")||(E(this,G,t,"f"),await this.getProjectHistory(),await a(this,it,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,gt,"f")||(E(this,gt,!0,"f"),a(this,Y,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,gt,"f")}async updateHistory(t,i=!0){var n,s,r;if(!a(this,G,"f"))return;a(this,$t,"f")?(E(this,$t,!1,"f"),E(this,Et,(r=a(this,Et,"f"),r++,r),"f")):E(this,Et,0,"f");const c=a(this,G,"f"),o=t.length-a(this,Tt,"f").maxLength,l=o>0?t.slice(o):t,h=$i(l,c);if(E(this,we,h,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(l),!(!i||!a(this,tt,"f")||!a(this,et,"f")))try{await a(this,tt,"f").save(a(this,et,"f"),h)}catch(v){(s=a(this,Y,"f"))===null||s===void 0||s.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var t;if(!this.state||!a(this,it,"f"))return(t=a(this,Y,"f"))===null||t===void 0?void 0:t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));E(this,$t,!0,"f");const i=this.state.history$.getValue().slice(0,-1),n=i.pop();this.state.history$.next(i),await a(this,it,"f").setChapter({chapterId:n})}async getProjectHistory(){var t,i;if(!a(this,G,"f")||!a(this,et,"f"))return;const n=a(this,G,"f");let s=[this.getInitialVideoId()];if(a(this,tt,"f"))try{const c=await a(this,tt,"f").get(a(this,et,"f"));c.length&&(s=c)}catch(c){(t=a(this,Y,"f"))===null||t===void 0||t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}const r=Jo(s,n);(i=this===null||this===void 0?void 0:this.state)===null||i===void 0||i.history$.next(r)}getInitialChapterId(){var t,i;const n=(t=this.state)===null||t===void 0?void 0:t.history$.getValue();return Ti(n,-1)||((i=a(this,G,"f"))===null||i===void 0?void 0:i.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return $i([t],a(this,G,"f")).pop()}return null}destroy(){var t,i;this.state=null,E(this,et,null,"f"),E(this,tt,null,"f"),E(this,it,null,"f"),(t=a(this,bt,"f"))===null||t===void 0||t.unsubscribe(),E(this,bt,null,"f"),E(this,gt,!1,"f"),(i=a(this,Y,"f"))===null||i===void 0||i.emit(_.historyDestroyed),E(this,Y,null,"f")}}tt=new WeakMap,Tt=new WeakMap,gt=new WeakMap,G=new WeakMap,we=new WeakMap,et=new WeakMap,it=new WeakMap,Y=new WeakMap,bt=new WeakMap,$t=new WeakMap,Et=new WeakMap;var Rt,jn,Ie,Ri;class Z{constructor(t,i,n,s){this.target=t,this.type=i,this.listener=n,this.options=a(Z,Rt,"m",jn).call(Z,t,s),this.target.addEventListener(i,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}Rt=Z,jn=function(t,i){if(i===void 0)return!1;if(typeof i=="boolean")return i;{const n=new Set(["passive","capture"]),s=Object.keys(i).filter(c=>!n.has(c));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),a(Z,Rt,"m",Ri).call(Z,t)?i:i.capture||!1}},Ri=function(t){let i=a(Z,Rt,"f",Ie);if(i===void 0){i=!1;try{const n={},s={get:()=>(i=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);const r=()=>{};t.addEventListener("test",r,n),t.removeEventListener("test",r,n)}catch(n){i=!1}E(Z,Rt,i,"f",Ie)}return i||!1};Ie={value:void 0};class il{constructor(){this.bindingMap=new Zr}release(){this.removeAll(),this.bindingMap=null}listen(t,i,n,s){if(!this.bindingMap)return;const r=new Z(t,i,n,s);this.bindingMap.push(i,r)}listenOnce(t,i,n,s){const r=c=>{this.unlisten(t,i,r),n(c)};this.listen(t,i,r,s)}unlisten(t,i,n){if(!this.bindingMap)return;const s=this.bindingMap.get(i)||[];for(const r of s)r.target===t&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(i,r))}removeAll(){if(!this.bindingMap)return;const t=this.bindingMap.getAll();for(const i of t)i.unlisten();this.bindingMap.clear()}}class nl{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const i=(t=this.rootElement.getContext("2d"))===null||t===void 0?void 0:t.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!i)return!1;const n=i.data,s=n.length;for(let r=3;r<s;r+=40)if(n[r]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){var t;this.canvasImgSrc&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,i=!1){const n=t.width+t.height;if(this._prevSizeId===n)return;let s;i&&(s=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,i&&s&&this.restore(s),this._prevSizeId=n}async save(){const t=this.rootElement.toDataURL("image/jpeg",1),i=new Image;return i.crossOrigin="anonymous",i.src=t,await i.decode(),i}restore(t){var i;this.rootElement&&((i=this.rootElement.getContext("2d"))===null||i===void 0||i.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}}class rl{constructor({parentElement:t,endOffsetMs:i=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=s=>{const r=s!=null?s:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(r);if(this.isContainerTime(r))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(c)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()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
import{loadVKLangPack as Fn,ValueSubject as W,Subscription as Jt,Observable as Be,getCurrentBrowser as Bn,CurrentClientBrowser as Dn,once as Wn}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{v4 as Hn}from"uuid";import{Player as Un}from"@vkontakte/videoplayer-core/es2018.esm.js";const Gn="1.0.10-dev.45d43b13.0";function Pi(e,t=1){let i="0",n="0",s="0";return e.length===4?(i="0x"+e[1]+e[1],n="0x"+e[2]+e[2],s="0x"+e[3]+e[3]):e.length===7&&(i="0x"+e[1]+e[2],n="0x"+e[3]+e[4],s="0x"+e[5]+e[6]),`rgba(${+i},${+n},${+s},${t})`}const q="SDK_NAME",zn="SDK_NAME-controls-container",Mi=()=>document.querySelector(`.${zn}`),qn=.4,K={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},De={top:"flex-start",bottom:"flex-end",center:"center"},We={start:"flex-start",end:"flex-end",center:"center"},He={start:"left",end:"right",center:"center"},Ni=({target:e,props:t})=>{var i,n,s,r,c,o;e.style.alignItems=(n=De[(i=t==null?void 0:t.text)===null||i===void 0?void 0:i.gravityVertical])!==null&&n!==void 0?n:De.center,e.style.justifyContent=(r=We[(s=t==null?void 0:t.text)===null||s===void 0?void 0:s.gravityHorizontal])!==null&&r!==void 0?r:We.center,e.style.textAlign=(o=He[(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.alignment])!==null&&o!==void 0?o:He.start},ki=({target:e,props:t,fallback:i,dependsOn:n})=>{var s,r,c,o,l,h;e.style.color=(r=(s=t==null?void 0:t.text)===null||s===void 0?void 0:s.color)!==null&&r!==void 0?r:i.textColor,e.style.fontSize=`calc(${n.height} * ${(o=(c=t==null?void 0:t.text)===null||c===void 0?void 0:c.size)!==null&&o!==void 0?o:i.textSize})`,e.textContent=(h=(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.value)!==null&&h!==void 0?h:i.textContent},Vi=({target:e,props:t,fallback:i})=>{var n,s,r,c;e.style.backgroundColor=Pi((s=(n=t==null?void 0:t.background)===null||n===void 0?void 0:n.color)!==null&&s!==void 0?s:i.backgroundColor,(c=(r=t==null?void 0:t.background)===null||r===void 0?void 0:r.alpha)!==null&&c!==void 0?c:i.backgroundAlpha)},Fi=({target:e,props:t,fallback:i,dependsOn:n})=>{var s,r,c,o,l,h,v,u,p,g,E;e.style.border=`calc(${n.height} * ${(c=(r=(s=t==null?void 0:t.shape)===null||s===void 0?void 0:s.border)===null||r===void 0?void 0:r.width)!==null&&c!==void 0?c:i.borderWidth}) solid ${Pi((h=(l=(o=t==null?void 0:t.shape)===null||o===void 0?void 0:o.border)===null||l===void 0?void 0:l.color)!==null&&h!==void 0?h:i.borderColor,(p=(u=(v=t==null?void 0:t.shape)===null||v===void 0?void 0:v.border)===null||u===void 0?void 0:u.alpha)!==null&&p!==void 0?p:i.borderAlpha)}`,e.style.borderRadius=`calc(${n.height} * ${(E=(g=t==null?void 0:t.shape)===null||g===void 0?void 0:g.roundCorners)!==null&&E!==void 0?E:i.roundCorners})`},xe=({target:e,layoutParams:t,fallback:i})=>{var n;e.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:i.angle}rad)`},ne="int",Oe={AREA:`${ne}_area`,TEXT:`${ne}_text`,BUTTON:`${ne}_bttn`};class Ae{constructor(t){this.control=t}createView(t){var i;const n=document.createElement("div");n.classList.add(`${q}-control-container-${this.control.id}`),t(n,this.control.layoutParams);const s=((i=this.control.layoutParams.innerSizesDependOn)!==null&&i!==void 0?i:K.innerSizesDependOn)==="self"?{height:n.style.height,width:n.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:n,dependsOn:s}}setEvents(t,i){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",r=>{r.stopPropagation(),i&&i({action:n.action,controlId:this.control.id,controlType:this.control.type})});break}})}getElement(){return document.querySelector(`.${q}-control-container-${this.control.id}`)}}const Bi=e=>{if(e.type.trim().toLowerCase()==="area")return new Qn(e)};class Qn extends Ae{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:n,controlContainerEl:s}=super.createView(i),r=document.createElement("button");return r.classList.add(`${q}-${this.control.id}`),r.setAttribute("data-testid",Oe.AREA),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",Vi({target:r,props:this.control.props,fallback:{...K,backgroundColor:"transparent"}}),Fi({target:r,props:this.control.props,fallback:{...K,borderAlpha:0},dependsOn:n}),xe({target:r,layoutParams:this.control.layoutParams,fallback:K}),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const Di=e=>{if(e.type.trim().toLowerCase()==="button")return new Yn(e)};class Yn extends Ae{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:n,controlContainerEl:s}=super.createView(i),r=document.createElement("button");r.type="button",r.classList.add(`${q}-${this.control.id}`),r.setAttribute("data-testid",Oe.BUTTON),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.display="inline-block",c.style.whiteSpace="pre",c.style.overflow="hidden",c.style.textOverflow="ellipsis",xe({target:r,layoutParams:this.control.layoutParams,fallback:K}),Vi({target:r,props:this.control.props,fallback:K}),Fi({target:r,props:this.control.props,fallback:K,dependsOn:n}),Ni({target:r,props:this.control.props}),ki({target:c,props:this.control.props,fallback:K,dependsOn:n}),r.append(c),s.append(r),t.append(s),this.controlEl=r,s}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}const Kn=e=>{if(e.type.trim().toLowerCase()==="text")return new Xn(e)};class Xn extends Ae{constructor(t){super(t)}createView({parent:t,layoutFn:i}){const{dependsOn:n,controlContainerEl:s}=super.createView(i),r=document.createElement("div");r.classList.add(`${q}-${this.control.id}`),r.setAttribute("data-testid",Oe.TEXT),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";const c=document.createElement("span");return c.style.whiteSpace="pre",xe({target:r,layoutParams:this.control.layoutParams,fallback:K}),Ni({target:r,props:this.control.props}),ki({target:c,props:this.control.props,fallback:K,dependsOn:n}),r.append(c),s.append(r),t.append(s),this.controlEl=r,s}disable(){}enable(){}getElement(){return document.querySelector(`.${q}-${this.control.id}`)}}class Zn{constructor(t){this.layout=t}}const Jn=e=>{if(e.type.trim().toLowerCase()==="relative")return new Wi(e)};class Wi extends Zn{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,i){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${i.width})`,t.style.height=`calc(var(--interactive-content-height) * ${i.height})`,t.style.left=`calc(var(--interactive-content-width) * ${i.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${i.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}}function a(e,t,i,n){if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?n:i==="a"?n.call(e):n?n.value:t.get(e)}function b(e,t,i,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(e,i):s?s.value=i:t.set(e,i),i}var Ct,zt,Ue;class Hi{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",zt).call(this)}addControlFactory(t,i){this.factories.set(t.trim().toLowerCase(),i),a(this,Ct,"m",zt).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",zt).call(this)}}Ct=new WeakSet,zt=function(){this.controls=a(this,Ct,"m",Ue).call(this)},Ue=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((i,n)=>{const s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...i,r(n)]:[...i]},[])};const Ui=(e,t)=>{if(e.type.trim().toLowerCase()==="choice")return new tr(e,t)};class tr extends Hi{constructor(t,i){super(t),this.rootElement=i!=null?i:Mi(),this.layout=new Wi(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Di),this.addControlFactory("text",Kn),this.addControlFactory("area",Bi)}createView(t){const i=document.createElement("div");return i.classList.add(`${q}-${this.container.id}`),this.layout.setContainerLayout(i),this.controls.forEach(n=>{const s=n.createView({parent:i,layoutFn:this.layout.setControlLayout});n.setEvents(s,t)}),this.rootElement.append(i),this.isRemoved=!1,i}hide(){const t=this.getElement();t&&(t.style.visibility="hidden")}show(){const t=this.getElement();t&&(t.style.visibility="visible")}enable(){const t=this.getElement();t&&(this.controls.forEach(i=>i.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){const t=this.getElement();t&&(this.controls.forEach(i=>i.disable()),t.style.opacity=qn,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${q}-${this.container.id}`)}}function Gi(e,t){let i;return(...n)=>{clearTimeout(i),i=setTimeout(()=>e(...n),t)}}const Pt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},It=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,je=e=>It(e,Pt.Object),be=e=>It(e,Pt.String),Le=e=>It(e,Pt.Array),zi=e=>It(e,Pt.Number),er=e=>It(e,Pt.Function),Ge=e=>zi(e)&&!isNaN(e),At=e=>je(e)&&Object.keys(e).length===0,qi=e=>Le(e)&&!e.length,Ft=(e,t)=>be(e)&&(t?e.trim():e).length,Qi=window.navigator.userAgent.toLowerCase(),ir=/mobi/i.test(Qi);Qi.indexOf("android")>-1;const nr="video_interactive",rr="videoint",sr=250;class ar{constructor(t){this.onResize=i=>{this.isReady&&(!i[0].contentRect.width||!i[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:i[0].contentRect.width,height:i[0].contentRect.height}))},this.handleChapterChange=i=>{var n;if(this.isReady){if(this.isHidden||this.hide(),!(i!=null&&i.id)){(n=this.onError)===null||n===void 0||n.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(i.id),this.ngEditor.selectChapter(i.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=i.id,this.lastZoomInfo=void 0}},this.handleManifestChange=async(i,n=[])=>{var s;if(!zi(i.graph.edit.chapters[0].x)){this.isReady=!1,(s=this.onError)===null||s===void 0||s.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let r;try{r=await Fn(this.lang,nr,rr)}catch(o){console.log("Unable to load graph language pack")}const{GraphEditor:c}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new c(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:r}),this.ngEditor.on("control",({name:o,chapterId:l})=>{o==="openPreview"&&this.onOpenPreviewClick(l)}),this.ngEditor.on("zoomEnd",o=>{this.lastZoomInfo={...o}})}this.visitedChapterIds=new Set(n),i.metadata.id!==this.currentManifestId?(this.ngEditor.update(i),this.currentManifestId=i.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0},this.init(t)}init({root:t,onOpenPreviewClick:i,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=i,this.onError=n,this.lang=s!=null?s:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=or(t),this.resizeObserver=new ResizeObserver(Gi(this.onResize,sr)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var t,i;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)===null||t===void 0||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(i=this.ngEditor)===null||i===void 0||i.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}}function or(e){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height="100%",t.style.width="100%",t.style.display="none",e.append(t),t}const lr=3e3,cr=()=>{let e=[],t=null;return{setPlayer:c=>{t=c},setContainers:c=>{e=c},deleteContainer:c=>{e=e.filter(o=>o.id!==c)},getNextInteractiveTime:(c=lr)=>{if(!e.length||t===null)return null;let o=-1,l=!1;const h=Math.round(t.info.position$.getValue()*1e3);for(const v of e){const u=v.startTime-c;if(u<=h&&(h<=v.endTime||v.endTime===null)){l=!0;break}h<u&&(o=o===-1?u:Math.min(o,u))}return!l&&o!==-1?o:null}}},Kt=(e="",t="")=>{e=e.split("."),t=t.split(".");let i=0;for(let n=0;n<Math.max(e.length,t.length)&&!i;n++)e[n]>t[n]?i=1:e[n]<t[n]?i=-1:i=0;return i},hr="3.1",ze={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},dr={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},ur=e=>{const t=[];for(const i of e.chapters){let n;const s=[];for(const{isDefault:o,...l}of i.branches)o&&(n=l.id),s.push(l);let r=[];const c=[];for(const{fallbackStrategy:o,...l}of i.containers){const h=!!l.endTime;let v=[dr];switch(o){case"await":h?v=[]:r=[];break;case"default":{const u={type:"onSuspense",action:{type:ze.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?v=[u]:r=[u];break}case"random":case"weightlessRandom":case"max":case"min":{const u={type:"onSuspense",action:{type:ze[o],args:{}}};h?v=[u]:r=[u];break}}for(const u of l.controls)c.push({...l,controls:[{...u}],id:Hn(),events:v})}t.push({...i,containers:c,events:r,branches:s})}return e.metadata.version=hr,e.metadata.updated=new Date().toISOString(),{...e,chapters:t}},fr="3.2",vr=e=>{if(!e.media){const{media:t,...i}=e.metadata;return{...e,metadata:{...i,version:fr},media:t}}return e},pr="3.3",yr=(e=[])=>({edit:{chapters:e},view:{}}),qe={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},mr=e=>{var t;const i=[],n=[];for(const s of e.chapters){const{id:r,x:c,y:o,...l}=s,h=l.containers.map(v=>{var u;return{...v,controls:v.controls.map(({subtype:p,type:g,...E})=>({...E,type:p!=null?p:g})),events:!((u=v.events)===null||u===void 0)&&u.length?v.events:[qe]}});i.push({id:r,...l,containers:h,events:!((t=l.events)===null||t===void 0)&&t.length?l.events:[qe]}),n.push({id:r,x:c,y:o})}return{...e,chapters:i,graph:yr(n),metadata:{...e.metadata,version:pr}}},gr=[{version:"3.0",migrate:ur},{version:"3.1",migrate:vr},{version:"3.2",migrate:mr}],br=e=>gr.reduce((t,i)=>Kt(t.metadata.version,i.version)?t:i.migrate(t),e),Er=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),R=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"});var ht;(function(e){e.GO_NEXT_BUTTON="GO_NEXT_BUTTON",e.GO_NEXT_AREA="GO_NEXT_AREA",e.WATCH_AGAIN="WATCH_AGAIN",e.OPEN_GRAPH="OPEN_GRAPH",e.CLOSE_GRAPH="CLOSE_GRAPH"})(ht||(ht={}));const Qe={metadata:"Object",chapters:"Array"},Cr="3.0.0",_r="3.3.0",Yi=e=>{const t=Kt(e,Cr);return t===-1?!1:t===0?!0:Kt(e,_r)!==1},wr=e=>{if(!je(e))return!1;for(const t in Qe)if(!e[t]||!It(e[t],Qe[t]))return!1;return Yi(e.metadata.version)},Ki=e=>e.type===Er.Text;class S{constructor(t,i,...n){this.severity=t,this.category=i,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}}S.Severity={RECOVERABLE:1,CRITICAL:2};S.Category={VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6};class Xi{constructor(){this.listeners={}}addListener(t,i){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(i),this}on(t,i){return this.addListener(t,i)}once(t,i){this.listeners[t]=this.listeners[t]||[];const n=()=>{i(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,i){return this.removeListener(t,i)}reset(){this.listeners={}}removeListener(t,i){const n=this.listeners[t];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===i){n.splice(s,1);break}return this}emit(t,...i){const n=this.listeners[t];return n?(n.forEach(s=>{s(...i)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}}class Ir{constructor(t){this.addFn=(i,n=!1)=>{er(i)&&(this.fns.push(i),n&&this.updateFn())},this.removeFn=(i,n=!1)=>{this.fns=this.fns.filter(s=>s!==i),n&&this.updateFn()},this.updateFn=()=>{this.fn=()=>{this.fns.forEach(i=>i()),this.raf&&this.forceRequestAnimation()}},this.forceRequestAnimation=()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))},this.requestAnimation=()=>{this.raf||this.forceRequestAnimation()},this.cancelAnimation=()=>{cancelAnimationFrame(this.raf),this.raf=void 0},this.raf,this.fn,this.fns=[],this.addFn(t)}release(){this.cancelAnimation(),this.fn=void 0,this.fns=[]}}class Sr{constructor(t){var i,n;this.loaders={chapterLoaders:(i=t==null?void 0:t.chapterLoaders)!==null&&i!==void 0?i:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!==null&&n!==void 0?n:[]}}async exec(t,i){return Tr(...this.loaders[t])(i)}}function Tr(...e){return async function(i){const n=[...e];for(;n.length>0;)i=await n.shift()(i);return i}}function Xt(e,t,i){return e?{...e,[t]:e[t]?[i,...e[t]]:[i]}:{[t]:[i]}}function Ee({actions:e,errors:t,chapterId:i,...n}){if(i){const s=e.getManifest(),r=e.getChapter(s.chapters,i);if(r){const c=e.getMedia(s.media,r.videoId),o=e.getGraph(s.graph,r.id);return c?{...n,actions:e,errors:t,result:{chapter:r,media:c,graph:o}}:{...n,errors:Xt(t,Ee.name,"Could not find media"),actions:e}}}return{...n,errors:Xt(t,Ee.name,"Could not find chapter"),actions:e}}class Ye{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,i,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:i,options:n})}removeEventListener(t,i){if(!(t in this.listeners))return;const n=this.listeners[t];for(let s=0,r=n.length;s<r;s++)if(n[s].callback===i){n.splice(s,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const n=this.listeners[t.type].slice();for(let s=0,r=n.length;s<r;s++){const c=n[s];try{c.callback.call(this,t)}catch(o){Promise.resolve().then(()=>{throw o})}c.options&&c.options.once&&this.removeEventListener(t.type,c.callback)}return!t.defaultPrevented}}class Zi extends Ye{constructor(){super(),this.listeners||Ye.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class $r{constructor(){Object.defineProperty(this,"signal",{value:new Zi,writable:!0,configurable:!0})}abort(t){let i;try{i=new Event("abort")}catch(s){typeof document!="undefined"?document.createEvent?(i=document.createEvent("Event"),i.initEvent("abort",!1,!1)):(i=document.createEventObject(),i.type="abort"):i={type:"abort",bubbles:!1,cancelable:!1}}let n=t;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(s){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&($r.prototype[Symbol.toStringTag]="AbortController",Zi.prototype[Symbol.toStringTag]="AbortSignal");function Ji(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function Rr(e){typeof e=="function"&&(e={fetch:e});const{fetch:t,Request:i=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s=!1}=e;if(!Ji({fetch:t,Request:i,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:s}))return{fetch:t,Request:r};let r=i;(r&&!r.prototype.hasOwnProperty("signal")||s)&&(r=function(h,v){let u;v&&v.signal&&(u=v.signal,delete v.signal);const p=new i(h,v);return u&&Object.defineProperty(p,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),p},r.prototype=i.prototype);const c=t;return{fetch:(l,h)=>{const v=r&&r.prototype.isPrototypeOf(l)?l.signal:h?h.signal:void 0;if(v){let u;try{u=new DOMException("Aborted","AbortError")}catch(g){u=new Error("Aborted"),u.name="AbortError"}if(v.aborted)return Promise.reject(u);const p=new Promise((g,E)=>{v.addEventListener("abort",()=>E(u),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([p,c(l,h)])}return c(l,h)},Request:r}}const Pe=Ji({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),tn=Pe?Rr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ke=Pe?tn.fetch:window.fetch;Pe?tn.Request:window.Request;const xr=async e=>{try{let t,i;if(je(e))t=e;else if(be(e)){i=new URL(e).href;const s=await Ke(i);if(!s.ok)return{};t=await s.json()}else return{};if(!wr(t))return{};const n=t.metadata.media;if(be(n)&&!t.media)try{let s;i?s=new URL(n,i).href:(s=new URL(n).href,i=s);const r=await Ke(s);if(!r.ok)throw new Error;t.metadata.media=await r.json()}catch(s){return Lr(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:i}}catch(t){return{}}};async function Or(e){const{manifest:t,manifestURL:i}=await xr(e),n=br(t);return n.media=Ar(n.media,i),delete n.metadata.media,n}function re(e,t){return e.find(i=>i.id===t)}function Xe(e,t){var i,n;return!((i=e.edit)===null||i===void 0)&&i.chapters?e.edit.chapters.find(s=>s.id===t):!((n=e.view)===null||n===void 0)&&n.chapters?e.view.chapters.find(s=>s.id===t):void 0}function Ze(e,t){return e.videos.find(i=>i.id===t)}function Ar(e,t){return{...e,videos:e.videos.map(i=>({...i,variants:i.variants.map(n=>{const s=jr(n.url,t);return{...n,url:s||n.url}})}))}}function jr(e,t){try{return new URL(e,t).href}catch(i){return""}}function Lr(e){return Kt(e,"3.2.0")>=0}const A=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Me=e=>Le(e)&&!qi(e),te=e=>e.order==="end",Pr=e=>Le(e.containers)&&!qi(e.containers)&&te(e),Mr=(e,t)=>{var i;const n=e*1e3;return Me(t.controls)&&n<((i=t.startTime)!==null&&i!==void 0?i:0)},Je=(e,t)=>{var i,n;const s=e*1e3;return Me(t.controls)&&s>=((i=t.startTime)!==null&&i!==void 0?i:0)&&s<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Lt=e=>e.some(t=>t.action.type==="expect"),ti=e=>e.find(t=>t.action.type==="expect"),Nr=e=>(e==null?void 0:e.length)===1,en=e=>Nr(e)&&Ki(e[0]),kr=({fn:e,type:t=1},...i)=>(...n)=>t?e(...n,...i):e({...n[t],...i[t]}),Vr=(e=[])=>e.reduce((t,i,n)=>{var s,r,c;const o=((s=i==null?void 0:i.controls)!==null&&s!==void 0?s:[]).filter(l=>!Ki(l));if(Me(o)){const l=[(r=i.startTime)!==null&&r!==void 0?r:0,(c=i.endTime)!==null&&c!==void 0?c:1/0],h=i.id;if(!n)t.push({subjects:[h],range:l});else{const v=[];let u=-1/0,p=1/0,g=[];const E=[];for(let I=0;I<t.length;I++){const d=t[I];if(E.push(...d.subjects),d.range[0]<p&&(p=d.range[0]),d.range[1]>u&&(u=d.range[1]),d.range[0]<=l[0]&&d.range[1]>=l[1])return t[I].subjects.push(h),t;l[0]>=d.range[0]&&l[0]<=d.range[1]&&(v.push(I),g=g.concat(d.subjects),l[0]=d.range[0]),l[1]>=d.range[0]&&l[1]<=d.range[1]&&(v.push(I),g=g.concat(d.subjects),l[1]=d.range[1])}if(E.push(h),l[0]<=p&&l[1]>=u)return[{subjects:E,range:l}];v.length&&v.reverse().forEach(I=>{t.splice(I,1)}),t.push({subjects:g.concat([h]),range:l})}}return t},[]).sort((t,i)=>t.range[0]-i.range[0]),Fr=(e,t)=>Lt(e.events)?!1:t.some(({container:i})=>i.container.id!==e.id&&Lt(i.container.events)&&i.container.endTime===e.endTime&&!i.isRemoved);class Br extends Sr{constructor(t,i){super(t),this.onError=i,this.prevChapter$=new W(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var i;this.release();const n=await this.exec("manifestLoaders",{actions:{addErrorMessage:Xt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const s=await Or((i=n.result)!==null&&i!==void 0?i:t);return this.manifest=s,this}async setInitial(){return this.setNext()}async setNext(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);const i=await this.exec("chapterLoaders",Ee({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Xe,getChapter:re,getMedia:Ze,getByBranches:this.getByBranches.bind(this),addErrorMessage:Xt},result:null,errors:null,chapterId:t}));return i.errors&&this.errorHandler(i.errors),this.chapter=i.result.chapter,this.media=i.result.media,this.graph=i.result.graph,this}errorHandler(t){this.onError(t),console.error("Something went wrong with loaders",{errors:t})}getInitial(){return this.getByChapterId(this.manifest.metadata.initChapterId)||null}getByChapterId(t=this.manifest.metadata.initChapterId){const i=re(this.manifest.chapters,t);if(i){const n=Ze(this.manifest.media,i.videoId),s=Xe(this.manifest.graph,i.id);if(n)return{chapter:i,media:n,graph:s}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{const i=re(this.manifest.chapters,t);return this.getByBranches(i==null?void 0:i.branches)}}getByBranches(t=[]){return t.reduce((i,n)=>{const s=this.getByChapterId(n.chapterId);return s&&i.push(s),i},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return te(this.chapter)}}const Dr=e=>{const t=e.variants.find(i=>{var n;return((n=i.payload)===null||n===void 0?void 0:n.type)==="vk"});if(t&&"payload"in t){const[i,n]=t.payload.id.split("_");return[i,n]}return[]},_={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},ei={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Wr(){const e=new Map;function t({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...c}){const o=e.get(s),l={...c};return o?o[r]=l:e.set(s,{[r]:l}),{listId:s,itemId:r,...c}}function i(s,r){var c,o,l;const h=e.get(s);if(h){if(r)return(c=h[r])===null||c===void 0||c.player.destroy(),(o=h[r])===null||o===void 0||o.container.remove(),(l=h[r])===null||l===void 0||l.subscription.unsubscribe(),delete h[r],Object.keys(h).length||e.delete(s),!0;for(const v of Object.values(h))v.player.destroy(),v.container.remove();return e.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(const s of e)i(s[0])}return{createPlayer:t,removePlayer:i,map:e,removeAll:n}}function ii(e,t=[]){var i,n,s;let r={},c;const o=!t.length;for(const l of e.variants)if(!c&&"cover"in l&&(c=l.cover),"url"in l)switch(l.type.toLowerCase()){case"mp4":(o||t.includes("mp4"))&&(r.MPEG={...r.MPEG,[(i=l.standard)!==null&&i!==void 0?i:"Invariant quality"]:l.url});break;case"mpeg":(o||t.includes("mpeg"))&&(r.MPEG={...r.MPEG,[(n=l.standard)!==null&&n!==void 0?n:"Invariant quality"]:l.url});break;case"hls":(o||t.includes("hls"))&&(r={...r,HLS:{type:"url",url:l.url}});break;case"dash":(o||t.includes("dash"))&&(r={...r,DASH_SEP:{compatibilityMode:!0,type:"url",url:l.url}});break}return{sources:r,thumbUrl:c,title:(s=e.title)!==null&&s!==void 0?s:""}}const Bt=(e,t)=>{const i=e.info.currentQuality$.getValue(),n=e.info.availableQualities$.getValue();i!==t&&n.includes(t)&&(e.setQuality(t),e.setAutoQuality(!1))},qt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Hr=2;function Ur(e){const t=Wr();let i,n;const s=new Xi;let r={},c=!1,o=null,l=!1,h;e&&v(e);function v(y){o=y}function u(y,C,m){var $;if(!o)throw Error("need to set interactive controller");const j=(($=t.map.get(y))!==null&&$!==void 0?$:{})[C];if(j){r={chapterId:m,listId:y,itemId:C,...j};const w=r.player;n=w.info.currentQuality$.subscribe(k=>{if(!(!k||!w.info.position$.getValue())){i=k;for(const D of t.map)Object.values(D[1]).forEach(({player:M})=>{w.info.isAutoQualityEnabled$.getValue()||Bt(M,k)})}}),j.container.remove(),c=!1,o.setPlayer(j.player),l||(o.init(),l=!0),s.emit(qt.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function p(y,C,m){if(!o)throw Error("need to set interactive controller");if(At(r)||y!==r.itemId)return;if(m>=0&&!c){const O=o.getChapterBranches();c=!0;const j=new Set;for(const w of O)j.has(w.media.id)||(await E({media:w.media,chapterId:w.chapter.id,setAsActive:!1,title:w.chapter.label}),j.add(w.media.id))}}async function g({chapter:{id:y},media:C}){if(At(r))return;n==null||n.unsubscribe();const m=r.player.info.muted$.getValue(),$=r.player.info.currentQuality$.getValue(),O=r.player.info.isAutoQualityEnabled$.getValue(),j=r.player.info.volume$.getValue(),w=r.player.info.currentPlaybackRate$.getValue(),k=!O;let D=!1;for(const M of t.map)if(M[0]===C.id){const Q=Object.keys(M[1]);for(const X of Q)X===r.itemId?(Q.length<Hr||(D=!0),t.removePlayer(M[0],X)):(D=!0,u(M[0],X,y),k?Bt(r.player,$):r.player.setAutoQuality(!0),r.player.setVolume(j),r.player.setMuted(m),r.player.setPlaybackRate(w))}else t.removePlayer(M[0]);D||(await E({media:C,chapterId:y,setAsActive:!0,playbackRate:w}),k?Bt(r.player,$):r.player.setAutoQuality(!0),r.player.setVolume(j),r.player.setMuted(m))}async function E({media:y,chapterId:C,prefetch:m=!0,setAsActive:$=!0,autoplay:O=!1,preferredExt:j,title:w,playbackRate:k}){var D,M,Q;const X=Math.random().toString(),vt=document.createElement("div");h.append(vt);const kn=(D=r==null?void 0:r.player)===null||D===void 0?void 0:D.info.isAutoQualityEnabled$.getValue();let kt;if(!((M=o==null?void 0:o.options)===null||M===void 0)&&M.vkVideoLoader){const Vt=Dr(y);Vt.length&&(kt=await o.options.vkVideoLoader(...Vt))}const Ve={container:vt,...((Q=kt==null?void 0:kt.videos)===null||Q===void 0?void 0:Q[0])||{sources:ii(y,j).sources},title:w},ot=new Un;ot.initVideo(Ve);const Vn=vt.lastChild,Fe=new Jt;Fe.add(ot.info.position$.subscribe(function(Vt){p(X,ot.info.duration$.getValue(),Vt)})).add(ot.events.canplay$.subscribe(function(){kn||Bt(ot,i),k&&ot.setPlaybackRate(k)})),Vn&&(vt.style.display="none",vt.classList.add(C));const pt=t.createPlayer({listId:y.id,itemId:X,player:ot,container:vt,sources:ii(y,j).sources,config:Ve,subscription:Fe});return $&&u(y.id,pt.itemId,C),O&&pt.player.play(),m&&!O&&pt.player.prepare(),s.emit(qt.playerCreated,pt.player),{player:pt.player,config:pt.config}}function I(){d(),o=null}function d(){o==null||o.off(_.chapterChanged,g),t.removeAll(),r={},l=!1,c=!1}async function f({container:y}){if(!o)throw Error("need to set interactive controller");d(),h=y;const{media:C,chapter:m}=o.getCurrentChapter();if(C){o.on(_.chapterChanged,g);const{player:$,config:O}=await E({media:C,chapterId:m.id,title:m.label});return s.emit(qt.initiated,{container:y,media:C,chapterId:m.id}),{player:$,config:O}}else console.error("not found")}return{...t,on:s.on.bind(s),off:s.off.bind(s),init:f,setInteractiveController:v,createPlayer:E,removeAll:I,getActivePlayer:function(){return r}}}class Gr{constructor({player:t,container:i,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:c,ignoreContainerEvent:o,permanentTextControls:l,disabledControls$:h,onRemove:v}){this.hide=()=>{setTimeout(()=>{var u,p;this.gameState!==A.end&&(Lt(this.container.container.events)&&this.gameState===A.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==A.interactive&&((p=(u=this.container).hide)===null||p===void 0||p.call(u)),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})))})},this.show=()=>{var u,p,g,E;if(this.gameState===A.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(E=(g=this.container).show)===null||E===void 0||E.call(g),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const d=kr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(f,y)=>{this.isSelectedControlEvent=!0,f!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===A.end||this.gameState===A.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),y(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1}))},isEOV:()=>this.gameState===A.end});this.container.createView(d),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((p=(u=this.container).disable)===null||p===void 0||p.call(u))}},this.onEndOfVideo=()=>{this.gameState=A.end,this.selectContainerEvent(!0)},this.whilePlaying=()=>{var u,p;if(((u=this.player.experimental.element$.getValue())===null||u===void 0?void 0:u.readyState)<1||[A.destroyed,A.removed].includes(this.gameState)&&!this.isPermanentText)return;const E=this.player.getExactTime();if(Mr(E,this.container.container))this.gameState!==A.beforeInteractive&&(this.gameState=A.beforeInteractive,this.onBeforeStartTime());else if(Je(E,this.container.container))this.gameState!==A.interactive&&(this.gameState=A.interactive,this.onStartTime());else if(this.gameState!==A.afterInteractive){const f=this.gameState;this.gameState=A.afterInteractive,f===A.interactive&&this.onEndTime()}else this.gameState!==A.destroyed&&!this.isPermanentText&&this.removeView();const I=Je(E,this.container.container),d=this.container.container.startTime?[this.container.container.startTime,(p=this.container.container.endTime)!==null&&p!==void 0?p:1/0]:[];this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:d,currentTime:E,isInteractiveTime:I})},this.container=i,this.branches=n,this.selectBranches=s,this.subscription=new Jt,this.player=t,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.isPermanentText=l&&en(i.container.controls),this.disabledControls$=h,this.onRemove=v,this.globalEventEmitter=c,this.gameState=A.nothing,this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.registerEvents()}registerEvents(){this.subscription.add(this.player.events.playing$.subscribe(this.show)).add(this.player.events.paused$.subscribe(this.hide)).add(this.player.events.ended$.subscribe(this.onEndOfVideo)).add(this.disabledControls$.subscribe(t=>{var i,n,s,r;t?(n=(i=this.container).disable)===null||n===void 0||n.call(i):(r=(s=this.container).enable)===null||r===void 0||r.call(s)}))}selectContainerEvent(t=!1){this.interactiveEvents.containersEventsCallState.setCalled({timestamp:t?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:t}),!t&&this.interactiveEvents.exec(this.container.container.endTime))}onStartTime(){this.show()}onEndTime(){this.selectContainerEvent(!1);const t=Lt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,i;(i=(t=this.container).hide)===null||i===void 0||i.call(t),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=A.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=A.removed,(t=this.onRemove)===null||t===void 0||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=A.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!==null&&t!==void 0?t:1/0,id:this.container.container.id})}}function zr(){const e={};function t(){for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&delete e[o];return!0}function i(o){const l={};for(const h in e)+h<=o&&(l[h]=e[h]);return l}function n(o){const l={};for(const h in e)+h>=o&&(l[h]=e[h]);return l}function s({timestamp:o,priority:l,initiator:h}){var v;if(Ge(o)){const u=(v=e[o])!==null&&v!==void 0?v:null;if(u&&Ft(l,!0)){let p={};const g=u[l];if(g&&(p={...p,...g}),p=At(p)?null:p,p&&Ft(h,!0)){const E=p[h];return E!=null?E:null}return p}return u}return null}function r({timestamp:o,priority:l,initiator:h}){if(Ge(o))if(e[o]){if(Ft(l,!0))if(e[o][l]){if(Ft(h,!0))if(e[o][l][h]){if(delete e[o][l][h],!At(e[o][l]))return!0}else return!1;if(delete e[o][l],!At(e[o]))return!0}else return!1;return delete e[o]}else return!1}function c({timestamp:o,priority:l,initiator:h,...v}){var u,p,g;!((p=(u=e[o])===null||u===void 0?void 0:u[l])===null||p===void 0)&&p[h]?e[o][l][h].push({...v}):!((g=e[o])===null||g===void 0)&&g[l]?e[o][l]={...e[o][l],[h]:[{...v}]}:e[o]?e[o]={...e[o],[l]:{[h]:[{...v}]}}:e[o]={[l]:{[h]:[{...v}]}}}return{map:e,remove:r,add:c,removeAll:t,get:s,getLte:i,getGte:n}}const qr=[R.expect,R.setNextBranch],Qr=1/0;function ni(e){let t=e,i;const n=Yr(),s=new zr;let r;const c=()=>{p(),d()},o=f=>{s.add.call(void 0,f),g()},l=(f=[])=>{for(const y of f)if(y.action(),qr.includes(y.actionType))break},h=(f=1/0)=>{var y,C,m;const $=Dt((y=s.get({timestamp:f,priority:"control"}))!==null&&y!==void 0?y:{}),O=Dt((C=s.get({timestamp:f,priority:"container"}))!==null&&C!==void 0?C:{}),j=Dt((m=s.get({timestamp:f,priority:"chapter"}))!==null&&m!==void 0?m:{});return[...$,...O,...j]},v=f=>{n.isReady(f)&&l(h(f))},u=()=>{var f;l([...Dt((f=s.get({timestamp:1/0,priority:"chapter"}))!==null&&f!==void 0?f:{})])},p=()=>{i&&(r==null||r.unsubscribe(),i=void 0)},g=()=>{i||(i=()=>setTimeout(()=>{v(1/0)}),r=t.events.ended$.subscribe(i))},E=f=>{p(),t=f},I=f=>{f.priority==="container"&&n.resetCalled(f.timestamp),s.remove(f)},d=()=>{n.release(),s.removeAll()};return{setPlayer:E,add:o,remove:I,exec:v,execEndOfVideo:u,listen:g,unlisten:p,release:c,containersEventsCallState:n,getPreparedToExecActions:h}}function Yr(){const e=new Map;return{setCalled:({timestamp:c,id:o})=>{const l=e.get(c);l&&l[o]!==void 0&&(l[o]=!0)},setData:(c=[])=>{var o,l;for(const h of c){const v=(o=h.endTime)!==null&&o!==void 0?o:Qr,u=(l=e.get(v))!==null&&l!==void 0?l:{};e.set(v,{...u,[h.id]:!1})}},resetCalled:c=>{const o=e.get(c);if(o)for(const l in o)o[l]=!1},isReady:c=>{const o=e.get(c);return o?!Object.values(o).some(l=>!l):!0},release:()=>e.clear()}}function Dt(e){return Object.values(e).flat().sort(t=>t.actionType===R.expect?-1:1)}const Kr=(e,t)=>{const{height:i,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(i&&n))return{videoContentHeight:0,videoContentWidth:0};const{clientHeight:s,clientWidth:r}=t.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};const c=i/n,o=s/r;let l,h;return o>c?(h=r,l=r*c):o<c?(h=s/c,l=s):(h=r,l=s),{videoContentWidth:h,videoContentHeight:l}},Xr=250;function Zr(e){let t=()=>{};const i=new ResizeObserver(o=>{r(o),t=r.bind(null,o)});function n(o){const{parentElement:l,player:h}=e();if(l&&h){const{videoContentWidth:v,videoContentHeight:u}=Kr(l,h);l.style.setProperty("--interactive-content-width",`${v}px`),l.style.setProperty("--interactive-content-height",`${u}px`),l.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),l.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function s(){const{parentElement:o}=e();o.removeAttribute("style")}const r=Gi(o=>{const{fns:l=[]}=e();n(o);for(const h of l)h()},Xr);function c(){t=void 0,i.disconnect(),s()}return{resizeObserver:i,calc:()=>{t()},release:c}}class Jr{constructor(){this.map={}}push(t,i){t in this.map?this.map[t].push(i):this.map[t]=[i]}get(t){const i=this.map[t];return i?i.slice():null}getAll(){const t=[];for(const i in this.map)t.push(...this.map[i]);return t}remove(t,i){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==i),this.map[t].length===0&&delete this.map[t])}clear(){this.map={}}size(){return Object.keys(this.map).length}keys(){return Object.keys(this.map)}}const ts=e=>Math.floor(Math.random()*e),es=e=>{let t=e.length,i=1/0,n=null;for(;t--;)e[t].weight<i&&(i=e[t].weight,n=e[t]);return n},is=e=>{let t=e.length,i=-1/0,n=null;for(;t--;)e[t].weight>i&&(i=e[t].weight,n=e[t]);return n},ns=e=>{const t=e.length,i=ts(t);return e[i]},ri=1,rs=e=>{var t,i;let n=0;for(let r=0;r<e.length;++r)n+=(t=e[r].weight)!==null&&t!==void 0?t:ri;const s=Math.random()*n;n=0;for(let r=0;r<e.length-1;++r)if(n+=(i=e[r].weight)!==null&&i!==void 0?i:ri,n>=s)return e[r];return e[e.length-1]},si=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),se=(e,t=!1)=>({...e,args:t?{...e.args,...si}:{...si,...e.args}}),ai=({globalEventEmitter:e,player:t,interactiveEvents:i,removeControllers:n})=>{const s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},c=({action:d,controlType:f,controlId:y,containerId:C,branches:m=[],onEvent:$,isEOV:O=()=>!1,isDisabled:j=()=>!1})=>{const w=se(d,O()),k={timestamp:1/0,priority:"control",initiator:y,actionType:w.type},D=j(),M=e.emit.bind(e,_.interactives,{subjectId:y,subjectType:f,subjectName:"control",type:D?L.actionChoiceCanceled:L.actionChoice,actionType:d.type,payload:{containerId:C,...w.args}});if(D){M();return}switch(w.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const Q=m.find(X=>X.id===w.args.branchId);if(!Q)return;$(w.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),w.args.shouldOpenNow?E({subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{chapterId:Q.chapterId,autoSelect:!1}}):(i.add({...k,action:E.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{chapterId:Q.chapterId,autoSelect:!1}})}),n==null||n());return}case R.continuePlayback.trim().toLowerCase():{$(w.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),w.args.shouldOpenNow?g({subjectId:y,subjectName:"control",subjectType:f,action:d}):i.add({...k,action:g.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:d})});return}case R.openURI.trim().toLowerCase():{$(w.args.isDetachContainer,p.bind(null,{subjectId:y,subjectName:"control"})),M(),w.args.shouldOpenNow?I({subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{URI:d.args.uri}}):(i.add({...k,action:I.bind(null,{subjectId:y,subjectName:"control",subjectType:f,action:w,payload:{URI:d.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),e.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:d,container:{id:f,endTime:y},branches:C=[],isEOV:m=!1,autoSelected:$=!1})=>{const O=se(d,m),j={timestamp:!O.args.shouldOpenNow||m?1/0:y,priority:"container",initiator:f,actionType:O.type},w=e.emit.bind(e,_.interactives,{subjectId:f,subjectName:"container",type:L.actionChoice,actionType:O.type,payload:O.args});switch(O.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const k=C.find(D=>D.id===O.args.branchId);if(!k)return;w(),i.add({...j,action:E.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{chapterId:k.chapterId,autoSelect:$}})}),n==null||n();return}case R.setMaxWeightBranch.trim().toLowerCase():return;case R.setMinWeightBranch.trim().toLowerCase():return;case R.setRandomBranch.trim().toLowerCase():return;case R.setWeightlessRandomBranch.trim().toLowerCase():return;case R.continuePlayback.trim().toLowerCase():{w(),i.add({...j,action:g.bind(null,{subjectId:f,subjectName:"container",action:O})});return}case R.openURI.trim().toLowerCase():{w(),i.add({...j,action:I.bind(null,{subjectId:f,subjectName:"container",action:O,payload:{URI:d.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),e.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function l({container:d,branches:f,isEOV:y=!1}){const C=ti(d.events);if(C){const m=se(C.action,y);e.emit(_.interactives,{subjectId:d.id,subjectName:"container",type:L.actionChoice,actionType:m.type,payload:m.args}),i.add({timestamp:y?1/0:d.endTime,priority:"container",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"container"})}),s.isExpect=!0}else for(const m of d.events)o({action:m.action,container:d,branches:f,isEOV:y})}const h=({chapterId:d,action:f,branches:y=[]})=>{const C=e.emit.bind(e,_.interactives,{subjectId:d,subjectName:"chapter",type:L.actionChoice,actionType:f.type,payload:f.args});switch(f.type.trim().toLowerCase()){case R.setNextBranch.trim().toLowerCase():{const m=y.find($=>$.id===f.args.branchId);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setWeightlessRandomBranch.trim().toLowerCase():{const m=ns(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setRandomBranch.trim().toLowerCase():{const m=rs(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMaxWeightBranch.trim().toLowerCase():{const m=is(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.setMinWeightBranch.trim().toLowerCase():{const m=es(y);return m!=null&&m.chapterId?(C(),E.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{chapterId:m.chapterId,autoSelect:!0}})):void 0}case R.continuePlayback.trim().toLowerCase():return C(),g.bind(null,{subjectId:d,subjectName:"chapter",action:f});case R.openURI.trim().toLowerCase():return C(),I.bind(null,{subjectId:d,subjectName:"chapter",action:f,payload:{URI:f.args.uri}});default:console.error("Unexpected chapter event"),e.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(d){const f=ti(d.events);if(f){if(te(d))return;e.emit(_.interactives,{subjectId:d.id,subjectName:"chapter",type:L.actionChoice,actionType:f.action.type,payload:f.action.args}),i.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:R.expect,action:u.bind(null,{subjectId:d.id,subjectName:"chapter"})})}else d.events.forEach(y=>{const C=h({chapterId:d.id,action:y.action,branches:d.branches});C&&i.add({timestamp:1/0,priority:"chapter",initiator:d.id,actionType:y.action.type,action:C})})}const u=({subjectId:d,subjectName:f,action:y})=>{var C;t.pause(),e.emit(_.interactives,{subjectId:d,subjectName:f,type:L.actionExecution,actionType:(C=y==null?void 0:y.type)!==null&&C!==void 0?C:R.expect})},p=({subjectId:d,subjectName:f})=>{t.info.isEnded$.getValue()?i.execEndOfVideo():t.play(),e.emit(_.interactives,{subjectId:d,subjectName:f,type:L.actionExecution,actionType:"after-expect"})},g=({subjectId:d,subjectName:f,subjectType:y,action:C})=>{e.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:L.actionExecution,actionType:C.type})},E=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{m.behaviour="change-chapter",e.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:L.actionExecution,actionType:C.type,payload:m})},I=({subjectId:d,subjectName:f,subjectType:y,action:C,payload:m})=>{if(!m.URI)return;const $=window.open(m.URI,"_blank","noopener,noreferrer");$&&($.opener=null),e.emit(_.interactives,{subjectId:d,subjectName:f,subjectType:y,type:L.actionExecution,actionType:C.type})};return{onControlEvent:c,onContainerEvent:o,onChapterEvent:h,onExpectEvent:u,expectEventHandler:p,setManifestChapterEvents:v,setManifestContainerEvents:l,stopExpect:r,state:s}};var ae=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function ss(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Wt=function(e){return e&&e.Math==Math&&e},at=Wt(typeof globalThis=="object"&&globalThis)||Wt(typeof window=="object"&&window)||Wt(typeof self=="object"&&self)||Wt(typeof ae=="object"&&ae)||function(){return this}()||ae||Function("return this")(),ut=function(e){try{return!!e()}catch(t){return!0}},as=ut,ee=!as(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),os=ee,nn=Function.prototype,oi=nn.apply,li=nn.call,ls=typeof Reflect=="object"&&Reflect.apply||(os?li.bind(oi):function(){return li.apply(oi,arguments)}),rn=ee,sn=Function.prototype,Ce=sn.call,cs=rn&&sn.bind.bind(Ce,Ce),St=rn?cs:function(e){return function(){return Ce.apply(e,arguments)}},an=St,hs=an({}.toString),ds=an("".slice),on=function(e){return ds(hs(e),8,-1)},us=on,fs=St,ln=function(e){if(us(e)==="Function")return fs(e)},_e=typeof document=="object"&&document.all,vs=typeof _e=="undefined"&&_e!==void 0,cn={all:_e,IS_HTMLDDA:vs},hn=cn,ps=hn.all,ft=hn.IS_HTMLDDA?function(e){return typeof e=="function"||e===ps}:function(e){return typeof e=="function"},dn={},ys=ut,Mt=!ys(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),ms=ee,Ht=Function.prototype.call,Ne=ms?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},un={},fn={}.propertyIsEnumerable,vn=Object.getOwnPropertyDescriptor,gs=vn&&!fn.call({1:2},1);un.f=gs?function(t){var i=vn(this,t);return!!i&&i.enumerable}:fn;var pn=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},bs=St,Es=ut,Cs=on,oe=Object,_s=bs("".split),ws=Es(function(){return!oe("z").propertyIsEnumerable(0)})?function(e){return Cs(e)=="String"?_s(e,""):oe(e)}:oe,yn=function(e){return e==null},Is=yn,Ss=TypeError,mn=function(e){if(Is(e))throw Ss("Can't call method on "+e);return e},Ts=ws,$s=mn,Rs=function(e){return Ts($s(e))},ci=ft,gn=cn,xs=gn.all,ie=gn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:ci(e)||e===xs}:function(e){return typeof e=="object"?e!==null:ci(e)},bn={},le=bn,ce=at,Os=ft,hi=function(e){return Os(e)?e:void 0},En=function(e,t){return arguments.length<2?hi(le[e])||hi(ce[e]):le[e]&&le[e][t]||ce[e]&&ce[e][t]},As=St,js=As({}.isPrototypeOf),Ls=typeof navigator!="undefined"&&String(navigator.userAgent)||"",Cn=at,he=Ls,di=Cn.process,ui=Cn.Deno,fi=di&&di.versions||ui&&ui.version,vi=fi&&fi.v8,z,Zt;vi&&(z=vi.split("."),Zt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!Zt&&he&&(z=he.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=he.match(/Chrome\/(\d+)/),z&&(Zt=+z[1])));var Ps=Zt,pi=Ps,Ms=ut,Ns=at,ks=Ns.String,_n=!!Object.getOwnPropertySymbols&&!Ms(function(){var e=Symbol();return!ks(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&pi&&pi<41}),Vs=_n,wn=Vs&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Fs=En,Bs=ft,Ds=js,Ws=wn,Hs=Object,In=Ws?function(e){return typeof e=="symbol"}:function(e){var t=Fs("Symbol");return Bs(t)&&Ds(t.prototype,Hs(e))},Us=String,Gs=function(e){try{return Us(e)}catch(t){return"Object"}},zs=ft,qs=Gs,Qs=TypeError,Sn=function(e){if(zs(e))return e;throw Qs(qs(e)+" is not a function")},Ys=Sn,Ks=yn,Xs=function(e,t){var i=e[t];return Ks(i)?void 0:Ys(i)},de=Ne,ue=ft,fe=ie,Zs=TypeError,Js=function(e,t){var i,n;if(t==="string"&&ue(i=e.toString)&&!fe(n=de(i,e))||ue(i=e.valueOf)&&!fe(n=de(i,e))||t!=="string"&&ue(i=e.toString)&&!fe(n=de(i,e)))return n;throw Zs("Can't convert object to primitive value")},Tn={exports:{}},yi=at,ta=Object.defineProperty,ea=function(e,t){try{ta(yi,e,{value:t,configurable:!0,writable:!0})}catch(i){yi[e]=t}return t},ia=at,na=ea,mi="__core-js_shared__",ra=ia[mi]||na(mi,{}),sa=ra,gi=sa;(Tn.exports=function(e,t){return gi[e]||(gi[e]=t!==void 0?t:{})})("versions",[]).push({version:"3.31.0",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"});var aa=Tn.exports,oa=mn,la=Object,$n=function(e){return la(oa(e))},ca=St,ha=$n,da=ca({}.hasOwnProperty),ke=Object.hasOwn||function(t,i){return da(ha(t),i)},ua=St,fa=0,va=Math.random(),pa=ua(1 .toString),ya=function(e){return"Symbol("+(e===void 0?"":e)+")_"+pa(++fa+va,36)},ma=at,ga=aa,bi=ke,ba=ya,Ea=_n,Ca=wn,_t=ma.Symbol,ve=ga("wks"),_a=Ca?_t.for||_t:_t&&_t.withoutSetter||ba,wa=function(e){return bi(ve,e)||(ve[e]=Ea&&bi(_t,e)?_t[e]:_a("Symbol."+e)),ve[e]},Ia=Ne,Ei=ie,Ci=In,Sa=Xs,Ta=Js,$a=wa,Ra=TypeError,xa=$a("toPrimitive"),Oa=function(e,t){if(!Ei(e)||Ci(e))return e;var i=Sa(e,xa),n;if(i){if(t===void 0&&(t="default"),n=Ia(i,e,t),!Ei(n)||Ci(n))return n;throw Ra("Can't convert object to primitive value")}return t===void 0&&(t="number"),Ta(e,t)},Aa=Oa,ja=In,Rn=function(e){var t=Aa(e,"string");return ja(t)?t:t+""},La=at,_i=ie,we=La.document,Pa=_i(we)&&_i(we.createElement),Ma=function(e){return Pa?we.createElement(e):{}},Na=Mt,ka=ut,Va=Ma,xn=!Na&&!ka(function(){return Object.defineProperty(Va("div"),"a",{get:function(){return 7}}).a!=7}),Fa=Mt,Ba=Ne,Da=un,Wa=pn,Ha=Rs,Ua=Rn,Ga=ke,za=xn,wi=Object.getOwnPropertyDescriptor;dn.f=Fa?wi:function(t,i){if(t=Ha(t),i=Ua(i),za)try{return wi(t,i)}catch(n){}if(Ga(t,i))return Wa(!Ba(Da.f,t,i),t[i])};var qa=ut,Qa=ft,Ya=/#|\.prototype\./,Nt=function(e,t){var i=Xa[Ka(e)];return i==Ja?!0:i==Za?!1:Qa(t)?qa(t):!!t},Ka=Nt.normalize=function(e){return String(e).replace(Ya,".").toLowerCase()},Xa=Nt.data={},Za=Nt.NATIVE="N",Ja=Nt.POLYFILL="P",to=Nt,Ii=ln,eo=Sn,io=ee,no=Ii(Ii.bind),ro=function(e,t){return eo(e),t===void 0?e:io?no(e,t):function(){return e.apply(t,arguments)}},On={},so=Mt,ao=ut,oo=so&&ao(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),lo=ie,co=String,ho=TypeError,uo=function(e){if(lo(e))return e;throw ho(co(e)+" is not an object")},fo=Mt,vo=xn,po=oo,Ut=uo,Si=Rn,yo=TypeError,pe=Object.defineProperty,mo=Object.getOwnPropertyDescriptor,ye="enumerable",me="configurable",ge="writable";On.f=fo?po?function(t,i,n){if(Ut(t),i=Si(i),Ut(n),typeof t=="function"&&i==="prototype"&&"value"in n&&ge in n&&!n[ge]){var s=mo(t,i);s&&s[ge]&&(t[i]=n.value,n={configurable:me in n?n[me]:s[me],enumerable:ye in n?n[ye]:s[ye],writable:!1})}return pe(t,i,n)}:pe:function(t,i,n){if(Ut(t),i=Si(i),Ut(n),vo)try{return pe(t,i,n)}catch(s){}if("get"in n||"set"in n)throw yo("Accessors not supported");return"value"in n&&(t[i]=n.value),t};var go=Mt,bo=On,Eo=pn,Co=go?function(e,t,i){return bo.f(e,t,Eo(1,i))}:function(e,t,i){return e[t]=i,e},Gt=at,_o=ls,wo=ln,Io=ft,So=dn.f,To=to,yt=bn,$o=ro,mt=Co,Ti=ke,Ro=function(e){var t=function(i,n,s){if(this instanceof t){switch(arguments.length){case 0:return new e;case 1:return new e(i);case 2:return new e(i,n)}return new e(i,n,s)}return _o(e,this,arguments)};return t.prototype=e.prototype,t},xo=function(e,t){var i=e.target,n=e.global,s=e.stat,r=e.proto,c=n?Gt:s?Gt[i]:(Gt[i]||{}).prototype,o=n?yt:yt[i]||mt(yt,i,{})[i],l=o.prototype,h,v,u,p,g,E,I,d,f;for(p in t)h=To(n?p:i+(s?".":"#")+p,e.forced),v=!h&&c&&Ti(c,p),E=o[p],v&&(e.dontCallGetSet?(f=So(c,p),I=f&&f.value):I=c[p]),g=v&&I?I:t[p],!(v&&typeof E==typeof g)&&(e.bind&&v?d=$o(g,Gt):e.wrap&&v?d=Ro(g):r&&Io(g)?d=wo(g):d=g,(e.sham||g&&g.sham||E&&E.sham)&&mt(d,"sham",!0),mt(o,p,d),r&&(u=i+"Prototype",Ti(yt,u)||mt(yt,u,{}),mt(yt[u],p,g),e.real&&l&&(h||!l[p])&&mt(l,p,g)))},Oo=Math.ceil,Ao=Math.floor,jo=Math.trunc||function(t){var i=+t;return(i>0?Ao:Oo)(i)},Lo=jo,An=function(e){var t=+e;return t!==t||t===0?0:Lo(t)},Po=An,Mo=Math.min,No=function(e){return e>0?Mo(Po(e),9007199254740991):0},ko=No,Vo=function(e){return ko(e.length)},Fo=xo,Bo=$n,Do=Vo,Wo=An;Fo({target:"Array",proto:!0},{at:function(t){var i=Bo(this),n=Do(i),s=Wo(t),r=s>=0?s:n+s;return r<0||r>=n?void 0:i[r]}});var Ho=En,Uo=Ho,Go=Uo,zo=Go("Array","at"),qo=zo,Qo=qo,Yo=Qo,Ko=Yo,$i=ss(Ko);const Ri=(e,t)=>{const i={};return e.map(n=>{if(!i[n]){const s=t.chapters.find(c=>c.id===n);if(!s)return null;const r=t.media.videos.find(c=>s.videoId===c.id);if(!r)return null;i[n]=jn(r)}return i[n]}).filter(Boolean)},Xo=e=>{for(const t of e.variants)if(Zo(t)&&"payload"in t)return t.payload.id},Zo=e=>e.type==="custom"&&"payload"in e&&e.payload.type==="vk",jn=e=>{const t=Xo(e);if(!t)return null;const i=t.split("_").pop();return i?parseInt(i,10):null},Jo=(e,t)=>{for(const i of e.media.videos)if(t===jn(i)){for(const n of e.chapters)if(n.videoId===i.id)return n.id;return}},tl=(e,t)=>e.reduce((i,n)=>{const s=Jo(t,n);return s?[...i,s]:i},[]);var tt,Tt,gt,G,Ie,Qt,et,it,Y,bt,$t,Et;const el=100;class il{constructor({globalEventEmitter:t,videoId:i,interactiveController:n,historyApi:s,historyParams:r,initChapterId:c}){var o,l,h;this.state={history$:new W([]),hasPrevChapter$:new W(!1),prevChapter$:new W(null),isInitialChapter$:new W(!1),isGoBackLimited$:new W(!1)},tt.set(this,null),Tt.set(this,void 0),gt.set(this,!1),G.set(this,null),Ie.set(this,null),Qt.set(this,null),et.set(this,null),it.set(this,null),Y.set(this,null),bt.set(this,new Jt),$t.set(this,!1),Et.set(this,0),b(this,et,i,"f"),b(this,Y,t,"f"),b(this,it,n,"f"),b(this,tt,s,"f"),b(this,Qt,c,"f"),b(this,Tt,{maxLength:(r==null?void 0:r.maxLength)||el},"f"),!((o=this.state)===null||o===void 0)&&o.history$&&a(this,bt,"f")&&((l=a(this,bt,"f"))===null||l===void 0||l.add((h=this.state)===null||h===void 0?void 0:h.history$.subscribe(v=>{var u,p,g,E,I,d;(u=this.state)===null||u===void 0||u.prevChapter$.next($i(v,-2)||null),(p=this.state)===null||p===void 0||p.hasPrevChapter$.next(v.length>1),(g=this.state)===null||g===void 0||g.isInitialChapter$.next(this.getInitialChapterId()===((I=(E=a(this,G,"f"))===null||E===void 0?void 0:E.metadata)===null||I===void 0?void 0:I.initChapterId)),(d=this.state)===null||d===void 0||d.isGoBackLimited$.next(a(this,Et,"f")===a(this,Tt,"f").maxLength-1)})))}async setManifest(t){!a(this,it,"f")||!a(this,Y,"f")||(b(this,G,t,"f"),await this.getProjectHistory(),await a(this,it,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,gt,"f")||(b(this,gt,!0,"f"),a(this,Y,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,gt,"f")}async updateHistory(t,i=!0){var n,s,r;if(!a(this,G,"f"))return;a(this,$t,"f")?(b(this,$t,!1,"f"),b(this,Et,(r=a(this,Et,"f"),r++,r),"f")):b(this,Et,0,"f");const c=a(this,G,"f"),o=t.length-a(this,Tt,"f").maxLength,l=o>0?t.slice(o):t,h=Ri(l,c);if(b(this,Ie,h,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(l),!(!i||!a(this,tt,"f")||!a(this,et,"f")))try{await a(this,tt,"f").save(a(this,et,"f"),h)}catch(v){(s=a(this,Y,"f"))===null||s===void 0||s.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var t;if(!this.state||!a(this,it,"f"))return(t=a(this,Y,"f"))===null||t===void 0?void 0:t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));b(this,$t,!0,"f");const i=this.state.history$.getValue().slice(0,-1),n=i.pop();this.state.history$.next(i),await a(this,it,"f").setChapter({chapterId:n})}async getProjectHistory(){var t,i;if(!a(this,G,"f")||!a(this,et,"f"))return;const n=a(this,G,"f");let s=[this.getInitialVideoId()];if(a(this,tt,"f"))try{const c=await a(this,tt,"f").get(a(this,et,"f"));c.length&&(s=c)}catch(c){(t=a(this,Y,"f"))===null||t===void 0||t.emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.HISTORY,"Error while trying to fetch data"))}const r=tl(s,n);(i=this===null||this===void 0?void 0:this.state)===null||i===void 0||i.history$.next(r)}getInitialChapterId(){var t,i;const n=(t=this.state)===null||t===void 0?void 0:t.history$.getValue();return $i(n,-1)||a(this,Qt,"f")||((i=a(this,G,"f"))===null||i===void 0?void 0:i.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return Ri([t],a(this,G,"f")).pop()}return null}destroy(){var t,i;this.state=null,b(this,et,null,"f"),b(this,tt,null,"f"),b(this,it,null,"f"),(t=a(this,bt,"f"))===null||t===void 0||t.unsubscribe(),b(this,bt,null,"f"),b(this,gt,!1,"f"),(i=a(this,Y,"f"))===null||i===void 0||i.emit(_.historyDestroyed),b(this,Y,null,"f")}}tt=new WeakMap,Tt=new WeakMap,gt=new WeakMap,G=new WeakMap,Ie=new WeakMap,Qt=new WeakMap,et=new WeakMap,it=new WeakMap,Y=new WeakMap,bt=new WeakMap,$t=new WeakMap,Et=new WeakMap;var Rt,Ln,Se,xi;class Z{constructor(t,i,n,s){this.target=t,this.type=i,this.listener=n,this.options=a(Z,Rt,"m",Ln).call(Z,t,s),this.target.addEventListener(i,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}}Rt=Z,Ln=function(t,i){if(i===void 0)return!1;if(typeof i=="boolean")return i;{const n=new Set(["passive","capture"]),s=Object.keys(i).filter(c=>!n.has(c));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),a(Z,Rt,"m",xi).call(Z,t)?i:i.capture||!1}},xi=function(t){let i=a(Z,Rt,"f",Se);if(i===void 0){i=!1;try{const n={},s={get:()=>(i=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);const r=()=>{};t.addEventListener("test",r,n),t.removeEventListener("test",r,n)}catch(n){i=!1}b(Z,Rt,i,"f",Se)}return i||!1};Se={value:void 0};class nl{constructor(){this.bindingMap=new Jr}release(){this.removeAll(),this.bindingMap=null}listen(t,i,n,s){if(!this.bindingMap)return;const r=new Z(t,i,n,s);this.bindingMap.push(i,r)}listenOnce(t,i,n,s){const r=c=>{this.unlisten(t,i,r),n(c)};this.listen(t,i,r,s)}unlisten(t,i,n){if(!this.bindingMap)return;const s=this.bindingMap.get(i)||[];for(const r of s)r.target===t&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(i,r))}removeAll(){if(!this.bindingMap)return;const t=this.bindingMap.getAll();for(const i of t)i.unlisten();this.bindingMap.clear()}}class rl{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const i=(t=this.rootElement.getContext("2d"))===null||t===void 0?void 0:t.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!i)return!1;const n=i.data,s=n.length;for(let r=3;r<s;r+=40)if(n[r]!==0)return!0;return!1}destroy(){this.rootElement.remove()}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}setCanvasImageSource(t){this.canvasImgSrc=t}draw(){var t;this.canvasImgSrc&&((t=this.rootElement.getContext("2d"))===null||t===void 0||t.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,i=!1){const n=t.width+t.height;if(this._prevSizeId===n)return;let s;i&&(s=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,i&&s&&this.restore(s),this._prevSizeId=n}async save(){const t=this.rootElement.toDataURL("image/jpeg",1),i=new Image;return i.crossOrigin="anonymous",i.src=t,await i.decode(),i}restore(t){var i;this.rootElement&&((i=this.rootElement.getContext("2d"))===null||i===void 0||i.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}}class sl{constructor({parentElement:t,endOffsetMs:i=250,onError:n}){this.currentVideoDurationMs=1/0,this._containerTimeFrameShouldReceived=!1,this._endTimeFrameReceived=!1,this._shouldCallSkip=!1,this.onEachTick=s=>{const r=s!=null?s:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,c=this.isChapterEndTime(r);if(this.isContainerTime(r))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(c)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()}},this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())},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 @@ import{loadVKLangPack as Vn,ValueSubject as W,Subscription as Zt,Observable as F
|
|
|
11
11
|
height: var(--interactive-height);
|
|
12
12
|
background-color: var(--black);
|
|
13
13
|
visibility: hidden;
|
|
14
|
-
`,this.lastFrameCanvas=new
|
|
14
|
+
`,this.lastFrameCanvas=new rl,this.endOffsetMs=i,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),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(t=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);const i=getComputedStyle(this.rootElement),n={width:parseInt(i.getPropertyValue("--interactive-content-width"),10),height:parseInt(i.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,t)}catch(s){this._onError(s)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(t){return this.currentVideoDurationMs&&t>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(t){if(this.currentChapter)return this.currentChapter.containers.some(i=>{var n,s,r;return((n=i.controls)===null||n===void 0?void 0:n.length)&&t>=((s=i.startTime)!==null&&s!==void 0?s:0)&&t<=Math.min((r=i.endTime)!==null&&r!==void 0?r:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(t){var i,n;(n=(i=this._callbacks)===null||i===void 0?void 0:i.onError)===null||n===void 0||n.call(i,t)}}function
|
|
19
|
+
`,this.rootElement.prepend(this.lastFrameCanvas.rootElement),t.prepend(this.rootElement)}destroy(){this.hide(),this.reset(),this._callbacks=void 0,this.lastFrameCanvas.destroy(),this.rootElement.remove()}setVideoDuration(t){this.currentVideoDurationMs=t}setVideoElement(t){this.lastFrameCanvas.setCanvasImageSource(t)}setCurrentChapter(t){this.currentChapter=t}show(){this.rootElement.style.visibility="visible"}hide(){this.rootElement.style.visibility="hidden"}async updateCanvasDimensions(t=!1){this._containerTimeFrameShouldReceived||this._endTimeFrameReceived||(t=!1);const i=getComputedStyle(this.rootElement),n={width:parseInt(i.getPropertyValue("--interactive-content-width"),10),height:parseInt(i.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,t)}catch(s){this._onError(s)}}draw(){(this._containerTimeFrameShouldReceived||!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived)&&this.lastFrameCanvas.draw()}isChapterEndTime(t){return this.currentVideoDurationMs&&t>=this.currentVideoDurationMs-this.endOffsetMs}isContainerTime(t){if(this.currentChapter)return this.currentChapter.containers.some(i=>{var n,s,r;return((n=i.controls)===null||n===void 0?void 0:n.length)&&t>=((s=i.startTime)!==null&&s!==void 0?s:0)&&t<=Math.min((r=i.endTime)!==null&&r!==void 0?r:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(t){var i,n;(n=(i=this._callbacks)===null||i===void 0?void 0:i.onError)===null||n===void 0||n.call(i,t)}}function al(e=0){return new Promise(t=>{setTimeout(()=>{t(0)},e)})}var P,lt,H,ct,B,st,F,U,nt,x,rt,jt,V,xt,N,T,dt,Pn,Oi,Yt,Mn,Te,Ai,$e,wt,Ot,ji,Re,Li,Nn;const ol=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,historyParams:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0}),J=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function ll(){const e=document.createElement("div");return e.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,e}class dl{constructor(t){var i;P.add(this),lt.set(this,null),H.set(this,null),ct.set(this,null),B.set(this,null),st.set(this,null),F.set(this,null),U.set(this,null),nt.set(this,null),x.set(this,null),rt.set(this,new W(!1)),jt.set(this,new Set),V.set(this,null),xt.set(this,null),N.set(this,null),T.set(this,null),dt.set(this,lr()),this.state={prevChapter$:new W(null),isInitialChapter$:new W(!1),isEndChapter$:new W(!1),isInteractiveExpectation$:new W(!1),calledByInteractive$:new W(!1),lastChapterChangeWasInitiatedByInteractive$:new W(!1),disabledControls$:new W(!1)},this.emitPlayerChanged=n=>{setTimeout(()=>{a(this,T,"f").emit(_.playerChanged,n)})},Pn.set(this,()=>{a(this,U,"f").fns.forEach(r=>r());const n=this.options.player.info.position$.getValue()*1e3,s=(a(this,x,"f").chapter.containers||[]).filter(r=>r.startTime>=Math.floor(n));for(const r of s){a(this,F,"f").remove({timestamp:1/0,priority:"container",initiator:r.id});for(const c of r.controls)a(this,F,"f").remove({timestamp:1/0,priority:"control",initiator:c.id});a(this,H,"f").find(c=>c.container.container.id===r.id).reset()}}),Se.set(this,()=>{a(this,lt,"f").calc(),a(this,U,"f").requestAnimation()}),wt.set(this,(n=!0)=>{a(this,H,"f").forEach(s=>{!n&&s.isPermanentText||(a(this,U,"f").removeFn(s.whilePlaying),s.destroy())})}),this.options={...al,...t},E(this,H,[],"f"),this.factories=new Map([["choice",Hi]]),this.rootElement=ol(),this.options.parentElement.append(this.rootElement),E(this,T,new Ki,"f"),E(this,st,new Zt,"f"),E(this,ct,new il,"f"),E(this,B,new el({interactiveController:this,globalEventEmitter:a(this,T,"f"),videoId:(i=this.options.projectInfo)===null||i===void 0?void 0:i.videoId,historyApi:this.options.historyApi,historyParams:this.options.historyParams}),"f"),this.options.lastFrame&&E(this,N,new rl({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.SEAMLESS,n))}),"f"),a(this,ct,"f").listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,ct,"f").listen(this.rootElement,"mouseup",n=>n.stopPropagation()),E(this,x,new Fr(this.options.loaders,n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.MANIFEST,n))),"f"),E(this,F,ii(this.options.player),"f"),E(this,U,new wr,"f"),E(this,nt,si({player:this.options.player,interactiveEvents:a(this,F,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:a(this,wt,"f")}),"f"),E(this,lt,Xr(()=>{var n;return{player:(n=this.options)===null||n===void 0?void 0:n.player,parentElement:this.options.parentElement,fns:this.options.lastFrame?[()=>{a(this,N,"f").updateCanvasDimensions(!0)}]:[]}}),"f"),this.options.graph&&E(this,V,new sr({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,T,"f").emit(_.graph,{type:ti.watchAgainClicked,chapterId:n})},onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.LOADERS,{message:n}))}),"f"),a(this,P,"m",Ln).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=J.created}getStatEvents(){return{click$:new Fe(t=>{a(this,T,"f").on(_.graph,({type:i,visibility:n})=>{i==="visibility"&&t.next(n?ht.OPEN_GRAPH:ht.CLOSE_GRAPH),i==="watchAgainClicked"&&t.next(ht.WATCH_AGAIN)}),a(this,T,"f").on(_.interactives,({type:i,subjectName:n,subjectType:s})=>{i!=="action-choice"||n!=="control"||(s==="Button"&&t.next(ht.GO_NEXT_BUTTON),s==="Area"&&t.next(ht.GO_NEXT_AREA))})}),nextMovie$:new Fe(t=>{a(this,T,"f").on(_.playerChanged,({config:i})=>{i!=null&&i.unitedVideoId&&t.next(i.unitedVideoId)})})}}setPlayer(t){a(this,P,"m",Qt).call(this),this.options.player=t,a(this,dt,"f").setPlayer(this.options.player),a(this,F,"f")?a(this,F,"f").setPlayer(this.options.player):E(this,F,ii(this.options.player),"f"),E(this,nt,si({player:this.options.player,interactiveEvents:a(this,F,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:()=>a(this,wt,"f").call(this,!1)}),"f"),this.appState===J.initiated&&(a(this,P,"m",Te).call(this),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}async setManifest(t){a(this,P,"m",Qt).call(this),this.isFirstChapterFetched=!1;const i=await a(this,x,"f").setManifest(t);return a(this,V,"f")&&await a(this,V,"f").handleManifestChange(i.manifest),await a(this,B,"f").setManifest(i.manifest),a(this,T,"f").emit(_.manifestChanged,{manifest:i.manifest}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),i.manifest}setVisitedChapters(t){var i;Array.isArray(t)&&((i=a(this,V,"f"))===null||i===void 0||i.setVisitedChapters(t))}updateGraphVideosInfo(t){var i;Array.isArray(t)&&((i=a(this,V,"f"))===null||i===void 0||i.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:i=!0}={}){var n;a(this,P,"m",Qt).call(this),a(this,N,"f")&&this.isFirstChapterFetched&&(a(this,N,"f").draw(),a(this,N,"f").show()),Fn().browser===Bn.Safari&&await sl(35);const r=await(t?a(this,x,"f").setNext(t):a(this,x,"f").setInitial()),{chapter:c,media:o,graph:l}=r;return i&&a(this,P,"m",Mn).call(this,c.id),this.state.isInitialChapter$.next(a(this,x,"f").isInitialChapter()),this.state.isEndChapter$.next(a(this,x,"f").isEndChapter()),a(this,V,"f")&&a(this,V,"f").handleChapterChange(l),(n=a(this,N,"f"))===null||n===void 0||n.setCurrentChapter(this.getCurrentChapter().chapter),a(this,T,"f").emit(_.chapterChanged,{chapter:c,media:o,graph:l}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),E(this,jt,new Set,"f"),this.isFirstChapterFetched=!0,{chapter:c,media:o,graph:l}}toggleGraphView(t=!0){a(this,V,"f")&&(t?(a(this,V,"f").show(),a(this,rt,"f").next(!1)):(a(this,V,"f").hide(),a(this,P,"m",$e).call(this)),a(this,T,"f").emit(_.graph,{type:ti.visibility,visibility:t}))}init(){a(this,x,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===J.created&&(a(this,lt,"f").resizeObserver.observe(this.options.fullscreenTargetElement),a(this,P,"m",Te).call(this),this.appState=J.initiated,a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}deadEndCheck(){var t,i;return!((i=(t=a(this,F,"f"))===null||t===void 0?void 0:t.getPreparedToExecActions())!==null&&i!==void 0?i:[]).some(r=>r.actionType===R.setNextBranch)}allControlsAreRemoved(){return!a(this,H,"f").some(i=>!i.container.isRemoved)}isEndedExpectation(){var t;if(!(!((t=this.options)===null||t===void 0)&&t.player)||!a(this,H,"f"))return!1;const i=this.options.player.info.position$.getValue(),n=this.options.player.info.duration$.getValue();return i===n&&a(this,H,"f").some(s=>{const r=s.container.container;return!r.isRemoved&&r.endTime===null&&Lt(r.events)})}playPrevChapter(){var t;(t=a(this,B,"f"))===null||t===void 0||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,x,"f").manifest){return Qi(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,B,"f").getInitialVideoId(),chapterId:a(this,B,"f").getInitialChapterId()}}getHistoryState(){return a(this,B,"f").state}getIsSeekable(){return a(this,rt,"f")}getInteractiveRanges(){var t;return kr((t=a(this,x,"f").chapter)===null||t===void 0?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,dt,"f").getNextInteractiveTime(t)}getChapterBranches(t){return a(this,x,"f").getBranches(t)}getCurrentChapter(){return a(this,x,"f").getCurrent()}getCurrentManifest(){return a(this,x,"f").manifest}addFactory(t,i){this.factories.set(t.trim().toLowerCase(),i)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,T,"f").on(...t),this}off(...t){return a(this,T,"f").off(...t),this}once(...t){return a(this,T,"f").once(...t),this}destroy(){var t,i;a(this,wt,"f").call(this),E(this,H,void 0,"f"),this.state=void 0,(t=a(this,V,"f"))===null||t===void 0||t.destroy(),E(this,V,void 0,"f"),a(this,lt,"f").release(),E(this,lt,void 0,"f"),E(this,nt,void 0,"f"),a(this,U,"f").release(),E(this,U,void 0,"f"),a(this,F,"f").release(),E(this,F,void 0,"f"),a(this,x,"f").release(),E(this,nt,void 0,"f"),a(this,ct,"f").release(),E(this,ct,void 0,"f"),a(this,st,"f").unsubscribe(),E(this,st,void 0,"f"),a(this,T,"f").reset(),E(this,T,void 0,"f"),(i=a(this,N,"f"))===null||i===void 0||i.destroy(),E(this,N,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,a(this,B,"f").destroy(),E(this,B,void 0,"f"),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=J.destroyed}}lt=new WeakMap,H=new WeakMap,ct=new WeakMap,B=new WeakMap,st=new WeakMap,F=new WeakMap,U=new WeakMap,nt=new WeakMap,x=new WeakMap,rt=new WeakMap,jt=new WeakMap,V=new WeakMap,xt=new WeakMap,N=new WeakMap,T=new WeakMap,dt=new WeakMap,Pn=new WeakMap,Se=new WeakMap,wt=new WeakMap,P=new WeakSet,Ln=function(t=!1){a(this,T,"f").on(_.historyInited,async({initChapterId:i,videosInfo:n=[]})=>{t&&await a(this,P,"m",xi).call(this,{initialChapter:i,videosInfo:n})}),a(this,T,"f").on(_.interactives,async i=>{var n,s;if(i.type===L.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=i.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:c}=i.payload;this.setChapter({chapterId:c})}if(((s=i.payload)===null||s===void 0?void 0:s.behaviour)==="change-manifest"){const{manifestURL:c}=i.payload;this.setManifest(c)}const r=i.type==="action-execution";r&&i.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):r&&i.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}}),a(this,T,"f").on(_.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},xi=async function({source:t,videosInfo:i=[]}){E(this,xt,Hr(this),"f");const n=document.createElement("div");a(this,xt,"f").on(qt.activePlayerChanged,this.emitPlayerChanged);const{player:s,config:r}=await a(this,xt,"f").init({source:t,initialChapter:a(this,B,"f").getInitialChapterId(),container:n});return this.updateGraphVideosInfo(i),{player:s,config:r}},Qt=function(){var t;this.appState===J.ready&&(a(this,wt,"f").call(this),E(this,H,[],"f"),a(this,U,"f").release(),(t=a(this,F,"f"))===null||t===void 0||t.release(),this.appState=J.initiated,a(this,rt,"f").next(!1))},Oi=function(t){(!a(this,V,"f")||a(this,V,"f").isHidden)&&a(this,P,"m",$e).call(this);const i=t*1e3,s=this.getInteractiveRanges().findLast(({range:r})=>i>=r[1]);if(s){const r=s.range.join("-");a(this,jt,"f").has(r)||(a(this,jt,"f").add(r),a(this,T,"f").emit(_.interactives,{type:L.rangeEnded,payload:s,visibility:!0}))}},Te=function(){a(this,st,"f").unsubscribe(),a(this,st,"f").add(this.options.player.events.started$.pipe(Dn()).subscribe(a(this,Se,"f"))).add(this.options.player.events.playing$.subscribe(a(this,U,"f").requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,U,"f").cancelAnimation)).add(this.options.player.info.position$.subscribe(a(this,P,"m",Oi).bind(this))).add(a(this,x,"f").prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))),this.options.lastFrame&&a(this,st,"f").add(this.options.player.info.duration$.subscribe(t=>{a(this,N,"f").setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,N,"f").setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,N,"f").reset(),setTimeout(()=>{a(this,N,"f").hide(),a(this,N,"f").lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,N,"f").onSeek))},Ot=function(t){a(this,x,"f").chapter&&this.appState===J.initiated&&(a(this,nt,"f").setManifestChapterEvents(t),E(this,H,a(this,P,"m",Ai).call(this,t),"f"),a(this,F,"f").containersEventsCallState.setData(t.containers),a(this,dt,"f").setContainers(a(this,H,"f").map(i=>i.container.container).filter(i=>!tn(i.controls))),this.options.lastFrame&&a(this,U,"f").addFn(()=>{a(this,N,"f").onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.appState=J.ready)},Ai=function(t){var i,n;return(n=(i=t==null?void 0:t.containers)===null||i===void 0?void 0:i.reduce((s,r)=>{const c=r.type.trim().toLowerCase(),o=this.factories.get(c);if(o){const l=new Ur({player:this.options.player,container:o(r,this.rootElement),branches:a(this,x,"f").chapter.branches,selectBranches:a(this,nt,"f"),interactiveEvents:a(this,F,"f"),globalEventEmitter:a(this,T,"f"),ignoreContainerEvent:()=>Vr(r,a(this,H,"f")),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,dt,"f").deleteContainer(r.id)}});return a(this,U,"f").addFn(l.whilePlaying,!0),[...s,l]}return[...s]},[]))!==null&&n!==void 0?n:[]},$e=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,rt,"f").next(!1);return}const i=a(this,rt,"f").getValue(),n=!!a(this,dt,"f").getNextInteractiveTime();(n&&!i||!n&&i)&&a(this,rt,"f").next(!i)},ji=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Mn=function(t){var i;if(a(this,P,"m",ji).call(this),!a(this,B,"f").inited)return;const n=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),s=this.state.prevChapter$.getValue(),r=(i=s&&Jt(s)&&Lr(s))!==null&&i!==void 0?i:!1,c=a(this,x,"f").manifest.metadata.initChapterId===t,o=a(this,B,"f").state.history$.getValue();if(c||r&&n){a(this,B,"f").updateHistory([t]);return}o.at(-1)!==t&&a(this,B,"f").updateHistory([...o,t])};const ul={Container:Wi,createChoiceContainer:Hi,createAreaControl:Fi,createButtonControl:Bi,createRelativeLayout:Zn,getRootEl:Pi,classnamesPrefix:q},fl={version:Un};export{S as CustomError,_ as EVENT_NAMES,ht as INTERACTIVE_CLICK_ACTIONS,dl as Interactives,Fr as ManifestController,fl as SDKInfo,$i as chapterIdsToVKVideoIds,Yt as compareVersions,Zo as getChapterIdByVkVideoId,An as getVKVideoIdByMedia,Ko as getVideoRawIdByMedia,ti as graphEventTypes,Lr as hasEndTemplate,L as interactivesEventTypes,Jt as isLastChapter,Qi as isSupportedManifest,Xo as isVKVariantItem,ul as utils,Jo as vkVideoIdsToChapterIds};
|
|
23
|
+
`,e}class ul{constructor(t){var i;P.add(this),lt.set(this,null),H.set(this,null),ct.set(this,null),B.set(this,null),st.set(this,null),F.set(this,null),U.set(this,null),nt.set(this,null),x.set(this,null),rt.set(this,new W(!1)),jt.set(this,new Set),V.set(this,null),xt.set(this,null),N.set(this,null),T.set(this,null),dt.set(this,cr()),this.state={prevChapter$:new W(null),isInitialChapter$:new W(!1),isEndChapter$:new W(!1),isInteractiveExpectation$:new W(!1),calledByInteractive$:new W(!1),lastChapterChangeWasInitiatedByInteractive$:new W(!1),disabledControls$:new W(!1)},this.emitPlayerChanged=n=>{setTimeout(()=>{a(this,T,"f").emit(_.playerChanged,n)})},Mn.set(this,()=>{a(this,U,"f").fns.forEach(r=>r());const n=this.options.player.info.position$.getValue()*1e3,s=(a(this,x,"f").chapter.containers||[]).filter(r=>r.startTime>=Math.floor(n));for(const r of s){a(this,F,"f").remove({timestamp:1/0,priority:"container",initiator:r.id});for(const c of r.controls)a(this,F,"f").remove({timestamp:1/0,priority:"control",initiator:c.id});a(this,H,"f").find(c=>c.container.container.id===r.id).reset()}}),Te.set(this,()=>{a(this,lt,"f").calc(),a(this,U,"f").requestAnimation()}),wt.set(this,(n=!0)=>{a(this,H,"f").forEach(s=>{!n&&s.isPermanentText||(a(this,U,"f").removeFn(s.whilePlaying),s.destroy())})}),this.options={...ol,...t},b(this,H,[],"f"),this.factories=new Map([["choice",Ui]]),this.rootElement=ll(),this.options.parentElement.append(this.rootElement),b(this,T,new Xi,"f"),b(this,st,new Jt,"f"),b(this,ct,new nl,"f"),b(this,B,new il({interactiveController:this,globalEventEmitter:a(this,T,"f"),videoId:(i=this.options.projectInfo)===null||i===void 0?void 0:i.videoId,historyApi:this.options.historyApi,historyParams:this.options.historyParams,initChapterId:this.options.initChapterId}),"f"),this.options.lastFrame&&b(this,N,new sl({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.SEAMLESS,n))}),"f"),a(this,ct,"f").listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,ct,"f").listen(this.rootElement,"mouseup",n=>n.stopPropagation()),b(this,x,new Br(this.options.loaders,n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.MANIFEST,n))),"f"),b(this,F,ni(this.options.player),"f"),b(this,U,new Ir,"f"),b(this,nt,ai({player:this.options.player,interactiveEvents:a(this,F,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:a(this,wt,"f")}),"f"),b(this,lt,Zr(()=>{var n;return{player:(n=this.options)===null||n===void 0?void 0:n.player,parentElement:this.options.parentElement,fns:this.options.lastFrame?[()=>{a(this,N,"f").updateCanvasDimensions(!0)}]:[]}}),"f"),this.options.graph&&b(this,V,new ar({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,T,"f").emit(_.graph,{type:ei.watchAgainClicked,chapterId:n})},onError:n=>a(this,T,"f").emit(_.errors,new S(S.Severity.RECOVERABLE,S.Category.LOADERS,{message:n}))}),"f"),a(this,P,"m",Pn).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=J.created}getStatEvents(){return{click$:new Be(t=>{a(this,T,"f").on(_.graph,({type:i,visibility:n})=>{i==="visibility"&&t.next(n?ht.OPEN_GRAPH:ht.CLOSE_GRAPH),i==="watchAgainClicked"&&t.next(ht.WATCH_AGAIN)}),a(this,T,"f").on(_.interactives,({type:i,subjectName:n,subjectType:s})=>{i!=="action-choice"||n!=="control"||(s==="Button"&&t.next(ht.GO_NEXT_BUTTON),s==="Area"&&t.next(ht.GO_NEXT_AREA))})}),nextMovie$:new Be(t=>{a(this,T,"f").on(_.playerChanged,({config:i})=>{i!=null&&i.unitedVideoId&&t.next(i.unitedVideoId)})})}}setPlayer(t){a(this,P,"m",Yt).call(this),this.options.player=t,a(this,dt,"f").setPlayer(this.options.player),a(this,F,"f")?a(this,F,"f").setPlayer(this.options.player):b(this,F,ni(this.options.player),"f"),b(this,nt,ai({player:this.options.player,interactiveEvents:a(this,F,"f"),globalEventEmitter:a(this,T,"f"),removeControllers:()=>a(this,wt,"f").call(this,!1)}),"f"),this.appState===J.initiated&&(a(this,P,"m",$e).call(this),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}async setManifest(t){a(this,P,"m",Yt).call(this),this.isFirstChapterFetched=!1;const i=await a(this,x,"f").setManifest(t);return a(this,V,"f")&&await a(this,V,"f").handleManifestChange(i.manifest),await a(this,B,"f").setManifest(i.manifest),a(this,T,"f").emit(_.manifestChanged,{manifest:i.manifest}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),i.manifest}setVisitedChapters(t){var i;Array.isArray(t)&&((i=a(this,V,"f"))===null||i===void 0||i.setVisitedChapters(t))}updateGraphVideosInfo(t){var i;Array.isArray(t)&&((i=a(this,V,"f"))===null||i===void 0||i.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:i=!0}={}){var n;a(this,P,"m",Yt).call(this),a(this,N,"f")&&this.isFirstChapterFetched&&(a(this,N,"f").draw(),a(this,N,"f").show()),Bn().browser===Dn.Safari&&await al(35);const r=await(t?a(this,x,"f").setNext(t):a(this,x,"f").setInitial()),{chapter:c,media:o,graph:l}=r;return i&&a(this,P,"m",Nn).call(this,c.id),this.state.isInitialChapter$.next(a(this,x,"f").isInitialChapter()),this.state.isEndChapter$.next(a(this,x,"f").isEndChapter()),a(this,V,"f")&&a(this,V,"f").handleChapterChange(l),(n=a(this,N,"f"))===null||n===void 0||n.setCurrentChapter(this.getCurrentChapter().chapter),a(this,T,"f").emit(_.chapterChanged,{chapter:c,media:o,graph:l}),a(this,P,"m",Ot).call(this,a(this,x,"f").chapter),b(this,jt,new Set,"f"),this.isFirstChapterFetched=!0,{chapter:c,media:o,graph:l}}toggleGraphView(t=!0){a(this,V,"f")&&(t?(a(this,V,"f").show(),a(this,rt,"f").next(!1)):(a(this,V,"f").hide(),a(this,P,"m",Re).call(this)),a(this,T,"f").emit(_.graph,{type:ei.visibility,visibility:t}))}init(){a(this,x,"f").chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===J.created&&(a(this,lt,"f").resizeObserver.observe(this.options.fullscreenTargetElement),a(this,P,"m",$e).call(this),this.appState=J.initiated,a(this,P,"m",Ot).call(this,a(this,x,"f").chapter))}deadEndCheck(){var t,i;return!((i=(t=a(this,F,"f"))===null||t===void 0?void 0:t.getPreparedToExecActions())!==null&&i!==void 0?i:[]).some(r=>r.actionType===R.setNextBranch)}allControlsAreRemoved(){return!a(this,H,"f").some(i=>!i.container.isRemoved)}isEndedExpectation(){var t;if(!(!((t=this.options)===null||t===void 0)&&t.player)||!a(this,H,"f"))return!1;const i=this.options.player.info.position$.getValue(),n=this.options.player.info.duration$.getValue();return i===n&&a(this,H,"f").some(s=>{const r=s.container.container;return!r.isRemoved&&r.endTime===null&&Lt(r.events)})}playPrevChapter(){var t;(t=a(this,B,"f"))===null||t===void 0||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,x,"f").manifest){return Yi(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,B,"f").getInitialVideoId(),chapterId:a(this,B,"f").getInitialChapterId()}}getHistoryState(){return a(this,B,"f").state}getIsSeekable(){return a(this,rt,"f")}getInteractiveRanges(){var t;return Vr((t=a(this,x,"f").chapter)===null||t===void 0?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,dt,"f").getNextInteractiveTime(t)}getChapterBranches(t){return a(this,x,"f").getBranches(t)}getCurrentChapter(){return a(this,x,"f").getCurrent()}getCurrentManifest(){return a(this,x,"f").manifest}addFactory(t,i){this.factories.set(t.trim().toLowerCase(),i)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,T,"f").on(...t),this}off(...t){return a(this,T,"f").off(...t),this}once(...t){return a(this,T,"f").once(...t),this}destroy(){var t,i;a(this,wt,"f").call(this),b(this,H,void 0,"f"),this.state=void 0,(t=a(this,V,"f"))===null||t===void 0||t.destroy(),b(this,V,void 0,"f"),a(this,lt,"f").release(),b(this,lt,void 0,"f"),b(this,nt,void 0,"f"),a(this,U,"f").release(),b(this,U,void 0,"f"),a(this,F,"f").release(),b(this,F,void 0,"f"),a(this,x,"f").release(),b(this,nt,void 0,"f"),a(this,ct,"f").release(),b(this,ct,void 0,"f"),a(this,st,"f").unsubscribe(),b(this,st,void 0,"f"),a(this,T,"f").reset(),b(this,T,void 0,"f"),(i=a(this,N,"f"))===null||i===void 0||i.destroy(),b(this,N,void 0,"f"),this.rootElement.remove(),this.rootElement=void 0,a(this,B,"f").destroy(),b(this,B,void 0,"f"),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=J.destroyed}}lt=new WeakMap,H=new WeakMap,ct=new WeakMap,B=new WeakMap,st=new WeakMap,F=new WeakMap,U=new WeakMap,nt=new WeakMap,x=new WeakMap,rt=new WeakMap,jt=new WeakMap,V=new WeakMap,xt=new WeakMap,N=new WeakMap,T=new WeakMap,dt=new WeakMap,Mn=new WeakMap,Te=new WeakMap,wt=new WeakMap,P=new WeakSet,Pn=function(t=!1){a(this,T,"f").on(_.historyInited,async({initChapterId:i,videosInfo:n=[]})=>{t&&await a(this,P,"m",Oi).call(this,{initialChapter:i,videosInfo:n})}),a(this,T,"f").on(_.interactives,async i=>{var n,s;if(i.type===L.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=i.payload)===null||n===void 0?void 0:n.behaviour)==="change-chapter"){const{chapterId:c}=i.payload;this.setChapter({chapterId:c})}if(((s=i.payload)===null||s===void 0?void 0:s.behaviour)==="change-manifest"){const{manifestURL:c}=i.payload;this.setManifest(c)}const r=i.type==="action-execution";r&&i.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):r&&i.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}}),a(this,T,"f").on(_.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Oi=async function({source:t,videosInfo:i=[]}){b(this,xt,Ur(this),"f");const n=document.createElement("div");a(this,xt,"f").on(qt.activePlayerChanged,this.emitPlayerChanged);const{player:s,config:r}=await a(this,xt,"f").init({source:t,initialChapter:a(this,B,"f").getInitialChapterId(),container:n});return this.updateGraphVideosInfo(i),{player:s,config:r}},Yt=function(){var t;this.appState===J.ready&&(a(this,wt,"f").call(this),b(this,H,[],"f"),a(this,U,"f").release(),(t=a(this,F,"f"))===null||t===void 0||t.release(),this.appState=J.initiated,a(this,rt,"f").next(!1))},Ai=function(t){(!a(this,V,"f")||a(this,V,"f").isHidden)&&a(this,P,"m",Re).call(this);const i=t*1e3,s=this.getInteractiveRanges().findLast(({range:r})=>i>=r[1]);if(s){const r=s.range.join("-");a(this,jt,"f").has(r)||(a(this,jt,"f").add(r),a(this,T,"f").emit(_.interactives,{type:L.rangeEnded,payload:s,visibility:!0}))}},$e=function(){a(this,st,"f").unsubscribe(),a(this,st,"f").add(this.options.player.events.started$.pipe(Wn()).subscribe(a(this,Te,"f"))).add(this.options.player.events.playing$.subscribe(a(this,U,"f").requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,U,"f").cancelAnimation)).add(this.options.player.info.position$.subscribe(a(this,P,"m",Ai).bind(this))).add(a(this,x,"f").prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))),this.options.lastFrame&&a(this,st,"f").add(this.options.player.info.duration$.subscribe(t=>{a(this,N,"f").setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,N,"f").setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,N,"f").reset(),setTimeout(()=>{a(this,N,"f").hide(),a(this,N,"f").lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,N,"f").onSeek))},Ot=function(t){a(this,x,"f").chapter&&this.appState===J.initiated&&(a(this,nt,"f").setManifestChapterEvents(t),b(this,H,a(this,P,"m",ji).call(this,t),"f"),a(this,F,"f").containersEventsCallState.setData(t.containers),a(this,dt,"f").setContainers(a(this,H,"f").map(i=>i.container.container).filter(i=>!en(i.controls))),this.options.lastFrame&&a(this,U,"f").addFn(()=>{a(this,N,"f").onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.appState=J.ready)},ji=function(t){var i,n;return(n=(i=t==null?void 0:t.containers)===null||i===void 0?void 0:i.reduce((s,r)=>{const c=r.type.trim().toLowerCase(),o=this.factories.get(c);if(o){const l=new Gr({player:this.options.player,container:o(r,this.rootElement),branches:a(this,x,"f").chapter.branches,selectBranches:a(this,nt,"f"),interactiveEvents:a(this,F,"f"),globalEventEmitter:a(this,T,"f"),ignoreContainerEvent:()=>Fr(r,a(this,H,"f")),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,dt,"f").deleteContainer(r.id)}});return a(this,U,"f").addFn(l.whilePlaying,!0),[...s,l]}return[...s]},[]))!==null&&n!==void 0?n:[]},Re=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,rt,"f").next(!1);return}const i=a(this,rt,"f").getValue(),n=!!a(this,dt,"f").getNextInteractiveTime();(n&&!i||!n&&i)&&a(this,rt,"f").next(!i)},Li=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Nn=function(t){var i;if(a(this,P,"m",Li).call(this),!a(this,B,"f").inited)return;const n=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),s=this.state.prevChapter$.getValue(),r=(i=s&&te(s)&&Pr(s))!==null&&i!==void 0?i:!1,c=a(this,x,"f").manifest.metadata.initChapterId===t,o=a(this,B,"f").state.history$.getValue();if(c||r&&n){a(this,B,"f").updateHistory([t]);return}o.at(-1)!==t&&a(this,B,"f").updateHistory([...o,t])};const fl={Container:Hi,createChoiceContainer:Ui,createAreaControl:Bi,createButtonControl:Di,createRelativeLayout:Jn,getRootEl:Mi,classnamesPrefix:q},vl={version:Gn};export{S as CustomError,_ as EVENT_NAMES,ht as INTERACTIVE_CLICK_ACTIONS,ul as Interactives,Br as ManifestController,vl as SDKInfo,Ri as chapterIdsToVKVideoIds,Kt as compareVersions,Jo as getChapterIdByVkVideoId,jn as getVKVideoIdByMedia,Xo as getVideoRawIdByMedia,ei as graphEventTypes,Pr as hasEndTemplate,L as interactivesEventTypes,te as isLastChapter,Yi as isSupportedManifest,Zo as isVKVariantItem,fl as utils,tl as vkVideoIdsToChapterIds};
|