@vkontakte/videoplayer-interactive 1.0.14-dev.1121b4e6.0 → 1.0.14-dev.2903553f.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 +5 -5
- package/esnext.esm.js +6 -6
- package/evergreen.esm.js +6 -6
- package/package.json +3 -3
- package/types/modules/Interactives/Interactives.d.ts +2 -2
- package/types/utils/typeCheck.d.ts +5 -0
package/es2018.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.14-dev.
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.14-dev.2903553f.0
|
|
3
|
+
* Wed, 21 Aug 2024 07:55:03 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-14/doc/
|
|
5
5
|
*/
|
|
6
|
-
"use strict";var bn=Object.create;var $t=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var En=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,xn=Object.prototype.hasOwnProperty;var mi=i=>{throw TypeError(i)};var Tn=(i,t,e)=>t in i?$t(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Sn=(i,t)=>{for(var e in t)$t(i,e,{get:t[e],enumerable:!0})},yi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of En(t))!xn.call(i,r)&&r!==e&&$t(i,r,{get:()=>t[r],enumerable:!(n=Cn(t,r))||n.enumerable});return i};var wn=(i,t,e)=>(e=i!=null?bn(In(i)):{},yi(t||!i||!i.__esModule?$t(e,"default",{value:i,enumerable:!0}):e,i)),Vn=i=>yi($t({},"__esModule",{value:!0}),i);var k=(i,t,e)=>Tn(i,typeof t!="symbol"?t+"":t,e),je=(i,t,e)=>t.has(i)||mi("Cannot "+e);var a=(i,t,e)=>(je(i,t,"read from private field"),e?e.call(i):t.get(i)),C=(i,t,e)=>t.has(i)?mi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),f=(i,t,e,n)=>(je(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e),N=(i,t,e)=>(je(i,t,"access private method"),e);var gi=(i,t,e,n)=>({set _(r){f(i,t,r,e)},get _(){return a(i,t,n)}});var ts={};Sn(ts,{CustomError:()=>I,EVENT_NAMES:()=>m,INTERACTIVE_CLICK_ACTIONS:()=>ye,Interactives:()=>Yt,ManifestController:()=>Ct,SDKInfo:()=>Jn,chapterIdsToVKVideoIds:()=>we,compareVersions:()=>et,getChapterIdByVkVideoId:()=>an,getVKVideoIdByMedia:()=>ni,getVideoRawIdByMedia:()=>sn,graphEventTypes:()=>Mt,hasEndTemplate:()=>zt,interactivesEventTypes:()=>S,isLastChapter:()=>J,isSupportedManifest:()=>Gt,isVKVariantItem:()=>rn,utils:()=>gn,vkVideoIdsToChapterIds:()=>si});module.exports=Vn(ts);var vi="1.0.14-dev.1121b4e6.0";function Pe(i,t=1){let e="0",n="0",r="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],r="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],r="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+r},${t})`}var H="SDK_NAME",Rn="SDK_NAME-controls-container",ie=()=>document.querySelector(`.${Rn}`),Ii=.4,K={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},bi={top:"flex-start",bottom:"flex-end",center:"center"},Ci={start:"flex-start",end:"flex-end",center:"center"},Ei={start:"left",end:"right",center:"center"},ne=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=bi[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:bi.center,i.style.justifyContent=(s=Ci[(r=t==null?void 0:t.text)==null?void 0:r.gravityHorizontal])!=null?s:Ci.center,i.style.textAlign=(o=Ei[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Ei.start},se=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d;i.style.color=(s=(r=t==null?void 0:t.text)==null?void 0:r.color)!=null?s:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(l=t==null?void 0:t.text)==null?void 0:l.size)!=null?o:e.textSize})`,i.textContent=(d=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?d:e.textContent},re=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Pe((r=(n=t==null?void 0:t.background)==null?void 0:n.color)!=null?r:e.backgroundColor,(l=(s=t==null?void 0:t.background)==null?void 0:s.alpha)!=null?l:e.backgroundAlpha)},ae=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d,g,v,E,T,x;i.style.border=`calc(${n.height} * ${(l=(s=(r=t==null?void 0:t.shape)==null?void 0:r.border)==null?void 0:s.width)!=null?l:e.borderWidth}) solid ${Pe((d=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?d:e.borderColor,(E=(v=(g=t==null?void 0:t.shape)==null?void 0:g.border)==null?void 0:v.alpha)!=null?E:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(T=t==null?void 0:t.shape)==null?void 0:T.roundCorners)!=null?x:e.roundCorners})`},Vt=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var $e="int",Rt={AREA:`${$e}_area`,TEXT:`${$e}_text`,BUTTON:`${$e}_bttn`};var lt=class{constructor(t){this.control=t}createView(t){var r;let e=document.createElement("div");e.classList.add(`${H}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((r=this.control.layoutParams.innerSizesDependOn)!=null?r:K.innerSizesDependOn)==="self"?{height:e.style.height,width:e.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:e,dependsOn:n}}setEvents(t,e){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",s=>{s.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${H}-control-container-${this.control.id}`)}};var oe=i=>{if(i.type.trim().toLowerCase()==="area")return new Oe(i)},Oe=class extends lt{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");return s.classList.add(`${H}-${this.control.id}`),s.setAttribute("data-testid",Rt.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",re({target:s,props:this.control.props,fallback:{...K,backgroundColor:"transparent"}}),ae({target:s,props:this.control.props,fallback:{...K,borderAlpha:0},dependsOn:n}),Vt({target:s,layoutParams:this.control.layoutParams,fallback:K}),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${H}-${this.control.id}`)}};var ce=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var le=i=>{if(i.type.trim().toLowerCase()==="button")return new Be(i)},Be=class extends lt{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("button");s.type="button",s.classList.add(`${H}-${this.control.id}`),s.setAttribute("data-testid",Rt.BUTTON),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.style.fontFamily="inherit";let l=ce();return Vt({target:s,layoutParams:this.control.layoutParams,fallback:K}),re({target:s,props:this.control.props,fallback:K}),ae({target:s,props:this.control.props,fallback:K,dependsOn:n}),ne({target:s,props:this.control.props}),se({target:l,props:this.control.props,fallback:K,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){this.controlEl&&(this.controlEl.style.cursor="default")}enable(){this.controlEl&&(this.controlEl.style.cursor="pointer")}getElement(){return document.querySelector(`.${H}-${this.control.id}`)}};var xi=i=>{if(i.type.trim().toLowerCase()==="text")return new Fe(i)},Fe=class extends lt{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:r}=super.createView(e),s=document.createElement("div");s.classList.add(`${H}-${this.control.id}`),s.setAttribute("data-testid",Rt.TEXT),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.fontFamily="inherit";let l=ce();return Vt({target:s,layoutParams:this.control.layoutParams,fallback:K}),ne({target:s,props:this.control.props}),se({target:l,props:this.control.props,fallback:K,dependsOn:n}),s.append(l),r.append(s),t.append(r),this.controlEl=s,r}disable(){}enable(){}getElement(){return document.querySelector(`.${H}-${this.control.id}`)}};var De=class{constructor(t){this.layout=t}},Ti=i=>{if(i.type.trim().toLowerCase()==="relative")return new Ot(i)},Ot=class extends De{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,e){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${e.width})`,t.style.height=`calc(var(--interactive-content-height) * ${e.height})`,t.style.left=`calc(var(--interactive-content-width) * ${e.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${e.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var ht,he,Si,_t=class{constructor(t){C(this,ht);this.container=t,this.factories=new Map,N(this,ht,he).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),N(this,ht,he).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),N(this,ht,he).call(this)}};ht=new WeakSet,he=function(){this.controls=N(this,ht,Si).call(this)},Si=function(){var t;return(t=this.container.controls)==null?void 0:t.reduce((e,n)=>{let r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};var de=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new He(i,t)},He=class extends _t{constructor(t,e){super(t),this.rootElement=e!=null?e:ie(),this.layout=new Ot(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",le),this.addControlFactory("text",xi),this.addControlFactory("area",oe)}createView(t){let e=document.createElement("div");return e.classList.add(`${H}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{let r=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(r,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){let t=this.getElement();t&&(t.style.visibility="hidden")}show(){let t=this.getElement();t&&(t.style.visibility="visible")}enable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=Ii,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())==null||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${H}-${this.container.id}`)}};var P=require("@vkontakte/videoplayer-shared");var _i=require("@vkontakte/videoplayer-shared");function pe(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Bt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},gt=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Ft=i=>gt(i,Bt.Object),ue=i=>gt(i,Bt.String),fe=i=>gt(i,Bt.Array),me=i=>gt(i,Bt.Number),wi=i=>gt(i,Bt.Function);var Ge=i=>me(i)&&!isNaN(i);var vt=i=>Ft(i)&&Object.keys(i).length===0,Ue=i=>fe(i)&&!i.length;var Dt=(i,t)=>ue(i)&&(t?i.trim():i).length;var Vi="video_interactive",Ri="videoint";var _n=250,Ht=class{constructor(t){k(this,"onResize",t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))});k(this,"handleChapterChange",t=>{var e;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.id)){(e=this.onError)==null||e.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}});k(this,"handleManifestChange",async(t,e=[])=>{var n;if(!me(t.graph.edit.chapters[0].x)){this.isReady=!1,(n=this.onError)==null||n.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(0,_i.loadVKLangPack)(this.lang,Vi,Ri)}catch(l){console.log("Unable to load graph language pack")}let{GraphEditor:s}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new s(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:r}),this.ngEditor.on("control",({name:l,chapterId:o})=>{l==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",l=>{this.lastZoomInfo={...l}})}this.visitedChapterIds=new Set(e),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0});this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:r,visitedChapters:s=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(s),this.onOpenPreviewClick=e,this.onError=n,this.lang=r!=null?r:"ru",this.zoom=.7,this.isReady=!1,this.lastZoomInfo=void 0,this.ngEditorSize=void 0,this.ngEditor=void 0,this.graphWrapperElement=An(t),this.resizeObserver=new ResizeObserver(pe(this.onResize,_n)),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,e;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)==null||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)==null||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function An(i){let 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",i.append(t),t}var ze=()=>{let i=[],t=null;return{setPlayer:l=>{t=l},setContainers:l=>{i=l},deleteContainer:l=>{i=i.filter(o=>o.id!==l)},getNextInteractiveTime:(l=3e3)=>{if(!i.length||t===null)return null;let o=-1,c=!1,d=Math.round(t.info.position$.getValue()*1e3);for(let g of i){let v=g.startTime-l;if(v<=d&&(d<=g.endTime||g.endTime===null)){c=!0;break}d<v&&(o=o===-1?v:Math.min(o,v))}return!c&&o!==-1?o:null}}};var et=(i="",t="")=>{i=i.split("."),t=t.split(".");let e=0;for(let n=0;n<Math.max(i.length,t.length)&&!e;n++)i[n]>t[n]?e=1:i[n]<t[n]?e=-1:e=0;return e};var Mi=require("uuid"),Mn="3.1",Ai={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},Ln={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Li=i=>{let t=[];for(let e of i.chapters){let n,r=[];for(let{isDefault:o,...c}of e.branches)o&&(n=c.id),r.push(c);let s=[],l=[];for(let{fallbackStrategy:o,...c}of e.containers){let d=!!c.endTime,g=[Ln];switch(o){case"await":d?g=[]:s=[];break;case"default":{let v={type:"onSuspense",action:{type:Ai.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?g=[v]:s=[v];break}case"random":case"weightlessRandom":case"max":case"min":{let v={type:"onSuspense",action:{type:Ai[o],args:{}}};d?g=[v]:s=[v];break}}for(let v of c.controls)l.push({...c,controls:[{...v}],id:(0,Mi.v4)(),events:g})}t.push({...e,containers:l,events:s,branches:r})}return i.metadata.version=Mn,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var Nn="3.2",Ni=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:Nn},media:t}}return i};var kn="3.3",jn=(i=[])=>({edit:{chapters:i},view:{}}),ki={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},ji=i=>{var n;let t=[],e=[];for(let r of i.chapters){let{id:s,x:l,y:o,...c}=r,d=c.containers.map(g=>{var v;return{...g,controls:g.controls.map(({subtype:E,type:T,...x})=>({...x,type:E!=null?E:T})),events:(v=g.events)!=null&&v.length?g.events:[ki]}});t.push({id:s,...c,containers:d,events:(n=c.events)!=null&&n.length?c.events:[ki]}),e.push({id:s,x:l,y:o})}return{...i,chapters:t,graph:jn(e),metadata:{...i.metadata,version:kn}}};var Pn=[{version:"3.0",migrate:Li},{version:"3.1",migrate:Ni},{version:"3.2",migrate:ji}],We=i=>Pn.reduce((t,e)=>et(t.metadata.version,e.version)?t:e.migrate(t),i);var dr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Pi=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),pr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),M=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),ye=(s=>(s.GO_NEXT_BUTTON="GO_NEXT_BUTTON",s.GO_NEXT_AREA="GO_NEXT_AREA",s.WATCH_AGAIN="WATCH_AGAIN",s.OPEN_GRAPH="OPEN_GRAPH",s.CLOSE_GRAPH="CLOSE_GRAPH",s))(ye||{});var $i={metadata:"Object",chapters:"Array"},$n="3.0.0",On="3.3.0",Gt=i=>{let t=et(i,$n);return t===-1?!1:t===0?!0:et(i,On)!==1},Oi=i=>{if(!Ft(i))return!1;for(let t in $i)if(!i[t]||!gt(i[t],$i[t]))return!1;return Gt(i.metadata.version)},ge=i=>i.type===Pi.Text;var I=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};k(I,"Severity",{RECOVERABLE:1,CRITICAL:2}),k(I,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var At=class{constructor(){k(this,"listeners",{})}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t];if(!n)return this;for(let r=n.length;r>0;r--)if(n[r]===e){n.splice(r,1);break}return this}emit(t,...e){let n=this.listeners[t];return n?(n.forEach(r=>{r(...e)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}};var ve=class{constructor(t){k(this,"addFn",(t,e=!1)=>{wi(t)&&(this.fns.push(t),e&&this.updateFn())});k(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});k(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});k(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});k(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});k(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=[]}};var Gi=require("@vkontakte/videoplayer-shared");var be=class{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!=null?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!=null?n:[]}}async exec(t,e){return Bn(...this.loaders[t])(e)}};function Bn(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function Ut(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function Ce({actions:i,errors:t,chapterId:e,...n}){if(e){let r=i.getManifest(),s=i.getChapter(r.chapters,e);if(s){let l=i.getMedia(r.media,s.videoId),o=i.getGraph(r.graph,s.id);return l?{...n,actions:i,errors:t,result:{chapter:s,media:l,graph:o}}:{...n,errors:Ut(t,Ce.name,"Could not find media"),actions:i}}}return{...n,errors:Ut(t,Ce.name,"Could not find chapter"),actions:i}}var Fn=async i=>{try{let t,e;if(Ft(i))t=i;else if(ue(i)){e=new URL(i).href;let r=await fetch(e);if(!r.ok)return{};t=await r.json()}else return{};if(!Oi(t))return{};let n=t.metadata.media;if(ue(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);let s=await fetch(r);if(!s.ok)throw new Error;t.metadata.media=await s.json()}catch(r){return Gn(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}};async function Bi(i){let{manifest:t,manifestURL:e}=await Fn(i),n=We(t);return n.media=Dn(n.media,e),delete n.metadata.media,n}function Ee(i,t){return i.find(e=>e.id===t)}function Qe(i,t){var e,n;return(e=i.edit)!=null&&e.chapters?i.edit.chapters.find(r=>r.id===t):(n=i.view)!=null&&n.chapters?i.view.chapters.find(r=>r.id===t):void 0}function Ke(i,t){return i.videos.find(e=>e.id===t)}function Dn(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let r=Hn(n.url,t);return{...n,url:r||n.url}})}))}}function Hn(i,t){try{return new URL(i,t).href}catch(e){return""}}function Gn(i){return et(i,"3.2.0")>=0}var O=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Ie=i=>fe(i)&&!Ue(i),J=i=>i.order==="end",zt=i=>fe(i.containers)&&!Ue(i.containers)&&J(i),Fi=(i,t)=>{var n;let e=i*1e3;return Ie(t.controls)&&e<((n=t.startTime)!=null?n:0)},Xe=(i,t)=>{var n,r;let e=i*1e3;return Ie(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((r=t.endTime)!=null?r:1/0)};var bt=i=>i.some(t=>t.action.type==="expect"),qe=i=>i.find(t=>t.action.type==="expect"),Un=i=>(i==null?void 0:i.length)===1,xe=i=>Un(i)&&ge(i[0]);var Di=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),Hi=(i,t)=>bt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&bt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var Ct=class extends be{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new Gi.ValueSubject(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var r;this.release();let e=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ut},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=await Bi((r=e.result)!=null?r:t);return this.manifest=n,this}async setInitial(){return this.setNext()}async setNext(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let e=await this.exec("chapterLoaders",Ce({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Qe,getChapter:Ee,getMedia:Ke,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ut},result:null,errors:null,chapterId:t}));return e.errors&&this.errorHandler(e.errors),this.chapter=e.result.chapter,this.media=e.result.media,this.graph=e.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){let e=Ee(this.manifest.chapters,t);if(e){let n=Ke(this.manifest.media,e.videoId),r=Qe(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:r}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{let e=Ee(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{let r=this.getByChapterId(n.chapterId);return r&&e.push(r),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return J(this.chapter)}};var zi=require("@vkontakte/videoplayer-core"),Wi=require("@vkontakte/videoplayer-shared");var Ui=i=>{let t=i.variants.find(e=>{var n;return((n=e.payload)==null?void 0:n.type)==="vk"});if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var m={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Mt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},S={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Ze(){let i=new Map;function t({listId:r=Math.random().toString(),itemId:s=Math.random().toString(),...l}){let o=i.get(r),c={...l};return o?o[s]=c:i.set(r,{[s]:c}),{listId:r,itemId:s,...l}}function e(r,s){var o,c,d;let l=i.get(r);if(l){if(s)return(o=l[s])==null||o.player.destroy(),(c=l[s])==null||c.container.remove(),(d=l[s])==null||d.subscription.unsubscribe(),delete l[s],Object.keys(l).length||i.delete(r),!0;for(let g of Object.values(l))g.player.destroy(),g.container.remove();return i.delete(r),!0}else throw Error("Can't remove. Not find.")}function n(){for(let r of i)e(r[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function Ye(i,t=[]){var s,l,o;let e={},n,r=!t.length;for(let c of i.variants)if(!n&&"cover"in c&&(n=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(r||t.includes("mp4"))&&(e.MPEG={...e.MPEG,[(s=c.standard)!=null?s:"Invariant quality"]:c.url});break;case"mpeg":(r||t.includes("mpeg"))&&(e.MPEG={...e.MPEG,[(l=c.standard)!=null?l:"Invariant quality"]:c.url});break;case"hls":(r||t.includes("hls"))&&(e={...e,HLS:{type:"url",url:c.url}});break;case"dash":(r||t.includes("dash"))&&(e={...e,DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}});break;default:break}return{sources:e,thumbUrl:n,title:(o=i.title)!=null?o:""}}var Wt=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var Qt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},zn=2;function Je(i){let t=Ze(),e,n,r=new At,s={},l=!1,o=null,c=!1,d;i&&g(i);function g(h){o=h}function v(h,p,b){var L;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let A=((L=t.map.get(h))!=null?L:{})[p];if(A){s={chapterId:b,listId:h,itemId:p,...A};let $=s.player;n=$.info.currentQuality$.subscribe(R=>{if(!(!R||!$.info.position$.getValue())){e=R;for(let Q of t.map)Object.values(Q[1]).forEach(({player:D})=>{$.info.isAutoQualityEnabled$.getValue()||Wt(D,R)})}}),A.container.remove(),l=!1,o.setPlayer(A.player),c||(o.init(),c=!0),r.emit(Qt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}async function E(h,p,b){if(!o)throw Error("need to set interactive controller");if(vt(s)||h!==s.itemId)return;if(b>=0&&!l){let A=o.getChapterBranches();l=!0;let L=new Set;for(let $ of A)L.has($.media.id)||(await x({media:$.media,chapterId:$.chapter.id,setAsActive:!1,title:$.chapter.label}),L.add($.media.id))}}async function T({chapter:{id:h},media:p}){if(vt(s))return;n==null||n.unsubscribe();let b=s.player.info.muted$.getValue(),u=s.player.info.currentQuality$.getValue(),A=s.player.info.isAutoQualityEnabled$.getValue(),L=s.player.info.volume$.getValue(),$=s.player.info.currentPlaybackRate$.getValue(),R=!A,Q=!1;for(let D of t.map)if(D[0]===p.id){let tt=Object.keys(D[1]);for(let z of tt)z===s.itemId?(tt.length<zn||(Q=!0),t.removePlayer(D[0],z)):(Q=!0,v(D[0],z,h),R?Wt(s.player,u):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(b),s.player.setPlaybackRate($))}else t.removePlayer(D[0]);Q||(await x({media:p,chapterId:h,setAsActive:!0,playbackRate:$}),R?Wt(s.player,u):s.player.setAutoQuality(!0),s.player.setVolume(L),s.player.setMuted(b))}async function x({media:h,chapterId:p,prefetch:b=!0,setAsActive:u=!0,autoplay:A=!1,preferredExt:L,title:$,playbackRate:R}){var hi,di,pi,ui,fi;let Q=Math.random().toString(),D=document.createElement("div");d.append(D);let tt=(hi=s==null?void 0:s.player)==null?void 0:hi.info.isAutoQualityEnabled$.getValue(),z;if((di=o==null?void 0:o.options)!=null&&di.vkVideoLoader){let ee=Ui(h);ee.length&&(z=await o.options.vkVideoLoader(...ee))}let te=((pi=o==null?void 0:o.options)==null?void 0:pi.coreConfig)||{},vn={...te,configName:[...(ui=te.configName)!=null?ui:[],"interactive"]},ci={container:D,...((fi=z==null?void 0:z.videos)==null?void 0:fi[0])||{sources:Ye(h,L).sources},title:$,failoverHosts:(z==null?void 0:z.failoverHosts)||[]},yt=new zi.Player(vn);yt.initVideo(ci);let li=new Wi.Subscription;li.add(yt.info.position$.subscribe(function(ee){E(Q,yt.info.duration$.getValue(),ee)})).add(yt.events.canplay$.subscribe(function(){tt||Wt(yt,e),R&&yt.setPlaybackRate(R)}));let wt=t.createPlayer({listId:h.id,itemId:Q,player:yt,container:D,sources:Ye(h,L).sources,config:ci,subscription:li});return u&&v(h.id,wt.itemId,p),A&&wt.player.play(),b&&!A&&wt.player.prepare(),r.emit(Qt.playerCreated,wt.player),{player:wt.player,config:wt.config}}function F(){V(),o=null}function V(){o==null||o.off(m.chapterChanged,T),t.removeAll(),s={},c=!1,l=!1}async function y({container:h}){if(!o)throw Error("need to set interactive controller");V(),d=h;let{media:p,chapter:b}=o.getCurrentChapter();if(p){o.on(m.chapterChanged,T);let{player:u,config:A}=await x({media:p,chapterId:b.id,title:b.label});return r.emit(Qt.initiated,{container:h,media:p,chapterId:b.id}),{player:u,config:A}}else console.error("not found")}return{...t,on:r.on.bind(r),off:r.off.bind(r),init:y,setInteractiveController:g,createPlayer:x,removeAll:F,getActivePlayer:function(){return s}}}var Qi=require("@vkontakte/videoplayer-shared");var Te=class{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d,onRemove:g}){k(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==O.end&&(bt(this.container.container.events)&&this.gameState===O.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==O.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})))})});k(this,"show",()=>{var t,e,n,r;if(this.gameState===O.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(r=(n=this.container).show)==null||r.call(n),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!0,isFirst:!1});else{let l=Di({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})),(this.gameState===O.end||this.gameState===O.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1}))},isEOV:()=>this.gameState===O.end});this.container.createView(l),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});k(this,"onEndOfVideo",()=>{this.gameState=O.end,this.selectContainerEvent(!0)});k(this,"whilePlaying",()=>{var s,l;if(((s=this.player.experimental.element$.getValue())==null?void 0:s.readyState)<1||[O.destroyed,O.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Fi(e,this.container.container))this.gameState!==O.beforeInteractive&&(this.gameState=O.beforeInteractive,this.onBeforeStartTime());else if(Xe(e,this.container.container))this.gameState!==O.interactive&&(this.gameState=O.interactive,this.onStartTime());else if(this.gameState!==O.afterInteractive){let o=this.gameState;this.gameState=O.afterInteractive,o===O.interactive&&this.onEndTime()}else this.gameState!==O.destroyed&&!this.isPermanentText&&this.removeView();let n=Xe(e,this.container.container),r=this.container.container.startTime?[this.container.container.startTime,(l=this.container.container.endTime)!=null?l:1/0]:[];this.globalEventEmitter.emit(m.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:r,currentTime:e,isInteractiveTime:n})});this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Qi.Subscription,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&xe(e.container.controls),this.disabledControls$=d,this.onRemove=g,this.globalEventEmitter=l,this.gameState=O.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 e,n,r,s;t?(n=(e=this.container).disable)==null||n.call(e):(s=(r=this.container).enable)==null||s.call(r)}))}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);let t=bt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)==null||e.call(t),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=O.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.containerRemoved,visibility:!1}),this.gameState=O.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=O.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!=null?t:1/0,id:this.container.container.id})}};var Ki=(i=[])=>i.reduce((t,e,n)=>{var s,l,o;let r=((s=e==null?void 0:e.controls)!=null?s:[]).filter(c=>!ge(c));if(Ie(r)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],d=e.id;if(!n)t.push({subjects:[d],range:c});else{let g=[],v=-1/0,E=1/0,T=[],x=[];for(let F=0;F<t.length;F++){let V=t[F];if(x.push(...V.subjects),V.range[0]<E&&(E=V.range[0]),V.range[1]>v&&(v=V.range[1]),c[0]>=V.range[0]&&c[1]<=V.range[1])return t[F].subjects.push(d),t;c[0]<V.range[0]&&c[1]>V.range[0]&&(g.push(F),T=T.concat(V.subjects)),c[0]>=V.range[0]&&c[0]<=V.range[1]&&(g.push(F),T=T.concat(V.subjects),c[0]=V.range[0]),c[1]>=V.range[0]&&c[1]<=V.range[1]&&(g.push(F),T=T.concat(V.subjects),c[1]=V.range[1])}if(x.push(d),c[0]<=E&&c[1]>=v)return[{subjects:x,range:c}];g.length&&g.reverse().forEach(F=>{t.splice(F,1)}),t.push({subjects:T.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function Xi(){let i={};function t(){for(let o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){let c={};for(let d in i)+d<=o&&(c[d]=i[d]);return c}function n(o){let c={};for(let d in i)+d>=o&&(c[d]=i[d]);return c}function r({timestamp:o,priority:c,initiator:d}){var g;if(Ge(o)){let v=(g=i[o])!=null?g:null;if(v&&Dt(c,!0)){let E={},T=v[c];if(T&&(E={...E,...T}),E=vt(E)?null:E,E&&Dt(d,!0)){let x=E[d];return x!=null?x:null}return E}return v}return null}function s({timestamp:o,priority:c,initiator:d}){if(Ge(o))if(i[o]){if(Dt(c,!0))if(i[o][c]){if(Dt(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!vt(i[o][c]))return!0}else return!1;if(delete i[o][c],!vt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l({timestamp:o,priority:c,initiator:d,...g}){var v,E,T;(E=(v=i[o])==null?void 0:v[c])!=null&&E[d]?i[o][c][d].push({...g}):(T=i[o])!=null&&T[c]?i[o][c]={...i[o][c],[d]:[{...g}]}:i[o]?i[o]={...i[o],[c]:{[d]:[{...g}]}}:i[o]={[c]:{[d]:[{...g}]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}var Wn=[M.expect,M.setNextBranch],Qn=1/0;function ti(i){let t=i,e,n=Kn(),r=new Xi,s,l=()=>{E(),y()},o=h=>{r.add.call(void 0,h),x()},c=(h=[])=>{for(let p of h)if(p.action(),Wn.includes(p.actionType))break},d=(h=1/0)=>{var A,L,$;let p=Se((A=r.get({timestamp:h,priority:"control"}))!=null?A:{}),b=Se((L=r.get({timestamp:h,priority:"container"}))!=null?L:{}),u=Se(($=r.get({timestamp:h,priority:"chapter"}))!=null?$:{});return[...p,...b,...u]},g=h=>{n.isReady(h)&&c(d(h))},v=()=>{var h;c([...Se((h=r.get({timestamp:1/0,priority:"chapter"}))!=null?h:{})])},E=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},T=h=>{},x=()=>{e||(e=()=>setTimeout(()=>{g(1/0)}),s=t.events.ended$.subscribe(e))},F=h=>{E(),t=h},V=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),r.remove(h)},y=()=>{n.release(),r.removeAll()};return{setPlayer:F,add:o,remove:V,exec:g,execEndOfVideo:v,listen:x,unlisten:E,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function Kn(){let i=new Map;return{setCalled:({timestamp:l,id:o})=>{let c=i.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(let d of l){let g=(o=d.endTime)!=null?o:Qn,v=(c=i.get(g))!=null?c:{};i.set(g,{...v,[d.id]:!1})}},resetCalled:l=>{let o=i.get(l);if(o)for(let c in o)o[c]=!1},isReady:l=>{let o=i.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>i.clear()}}function Se(i){return Object.values(i).flat().sort(t=>t.actionType===M.expect?-1:1)}var qi=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};let{clientHeight:r,clientWidth:s}=t.experimental.element$.value||{};if(!(r&&s))return{videoContentHeight:0,videoContentWidth:0};let l=e/n,o=r/s,c,d;return o>l?(d=s,c=s*l):o<l?(d=r/l,c=r):(d=s,c=r),{videoContentWidth:d,videoContentHeight:c}};var Xn=250;function Zi(i){let t=()=>{},e=new ResizeObserver(o=>{s(o),t=s.bind(null,o)});function n(o){let{parentElement:c,player:d}=i();if(c&&d){let{videoContentWidth:g,videoContentHeight:v}=qi(c,d);c.style.setProperty("--interactive-content-width",`${g}px`),c.style.setProperty("--interactive-content-height",`${v}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function r(){let{parentElement:o}=i();o.removeAttribute("style")}let s=pe(o=>{let{fns:c=[]}=i();n(o);for(let d of c)d()},Xn);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Kt=class{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){let e=this.map[t];return e?e.slice():null}getAll(){let t=[];for(let e in this.map)t.push(...this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),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)}};var qn=i=>Math.floor(Math.random()*i),Yi=i=>{let t=i.length,e=1/0,n=null;for(;t--;)i[t].weight<e&&(e=i[t].weight,n=i[t]);return n},Ji=i=>{let t=i.length,e=-1/0,n=null;for(;t--;)i[t].weight>e&&(e=i[t].weight,n=i[t]);return n};var tn=i=>{let t=i.length,e=qn(t);return i[e]};var en=i=>{var n,r;let t=0;for(let s=0;s<i.length;++s)t+=(n=i[s].weight)!=null?n:1;let e=Math.random()*t;t=0;for(let s=0;s<i.length-1;++s)if(t+=(r=i[s].weight)!=null?r:1,t>=e)return i[s];return i[i.length-1]};var nn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var ei=(i,t=!1)=>({...i,args:t?{...i.args,...nn}:{...nn,...i.args}}),ii=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:y,controlType:h,controlId:p,containerId:b,branches:u=[],onEvent:A,isEOV:L=()=>!1,isDisabled:$=()=>!1})=>{let R=ei(y,L()),Q={timestamp:1/0,priority:"control",initiator:p,actionType:R.type},D=$(),tt=i.emit.bind(i,m.interactives,{subjectId:p,subjectType:h,subjectName:"control",type:D?S.actionChoiceCanceled:S.actionChoice,actionType:y.type,payload:{containerId:b,...R.args}});if(D){tt();return}switch(R.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let z=u.find(te=>te.id===R.args.branchId);if(!z)return;A(R.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),tt(),R.args.shouldOpenNow?x({subjectId:p,subjectName:"control",subjectType:h,action:R,payload:{chapterId:z.chapterId,autoSelect:!1}}):(e.add({...Q,action:x.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:R,payload:{chapterId:z.chapterId,autoSelect:!1}})}),n==null||n());return}case M.continuePlayback.trim().toLowerCase():{A(R.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),tt(),R.args.shouldOpenNow?T({subjectId:p,subjectName:"control",subjectType:h,action:y}):e.add({...Q,action:T.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:y})});return}case M.openURI.trim().toLowerCase():{A(R.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),tt(),R.args.shouldOpenNow?V({subjectId:p,subjectName:"control",subjectType:h,action:R,payload:{URI:y.args.uri}}):(e.add({...Q,action:V.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:R,payload:{URI:y.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:y,container:{id:h,endTime:p},branches:b=[],isEOV:u=!1,autoSelected:A=!1})=>{let L=ei(y,u),$={timestamp:!L.args.shouldOpenNow||u?1/0:p,priority:"container",initiator:h,actionType:L.type},R=i.emit.bind(i,m.interactives,{subjectId:h,subjectName:"container",type:S.actionChoice,actionType:L.type,payload:L.args});switch(L.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let Q=b.find(D=>D.id===L.args.branchId);if(!Q)return;R(),e.add({...$,action:x.bind(null,{subjectId:h,subjectName:"container",action:L,payload:{chapterId:Q.chapterId,autoSelect:A}})}),n==null||n();return}case M.setMaxWeightBranch.trim().toLowerCase():return;case M.setMinWeightBranch.trim().toLowerCase():return;case M.setRandomBranch.trim().toLowerCase():return;case M.setWeightlessRandomBranch.trim().toLowerCase():return;case M.continuePlayback.trim().toLowerCase():{R(),e.add({...$,action:T.bind(null,{subjectId:h,subjectName:"container",action:L})});return}case M.openURI.trim().toLowerCase():{R(),e.add({...$,action:V.bind(null,{subjectId:h,subjectName:"container",action:L,payload:{URI:y.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:y,branches:h,isEOV:p=!1}){let b=qe(y.events);if(b){let u=ei(b.action,p);i.emit(m.interactives,{subjectId:y.id,subjectName:"container",type:S.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:p?1/0:y.endTime,priority:"container",initiator:y.id,actionType:M.expect,action:v.bind(null,{subjectId:y.id,subjectName:"container"})}),r.isExpect=!0}else for(let u of y.events)o({action:u.action,container:y,branches:h,isEOV:p})}let d=({chapterId:y,action:h,branches:p=[]})=>{let b=i.emit.bind(i,m.interactives,{subjectId:y,subjectName:"chapter",type:S.actionChoice,actionType:h.type,payload:h.args});switch(h.type.trim().toLowerCase()){case M.setNextBranch.trim().toLowerCase():{let u=p.find(A=>A.id===h.args.branchId);return u!=null&&u.chapterId?(b(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case M.setWeightlessRandomBranch.trim().toLowerCase():{let u=tn(p);return u!=null&&u.chapterId?(b(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case M.setRandomBranch.trim().toLowerCase():{let u=en(p);return u!=null&&u.chapterId?(b(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case M.setMaxWeightBranch.trim().toLowerCase():{let u=Ji(p);return u!=null&&u.chapterId?(b(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case M.setMinWeightBranch.trim().toLowerCase():{let u=Yi(p);return u!=null&&u.chapterId?(b(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case M.continuePlayback.trim().toLowerCase():return b(),T.bind(null,{subjectId:y,subjectName:"chapter",action:h});case M.openURI.trim().toLowerCase():return b(),V.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:console.error("Unexpected chapter event"),i.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function g(y){let h=qe(y.events);if(h){if(J(y))return;i.emit(m.interactives,{subjectId:y.id,subjectName:"chapter",type:S.actionChoice,actionType:h.action.type,payload:h.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:M.expect,action:v.bind(null,{subjectId:y.id,subjectName:"chapter"})})}else y.events.forEach(p=>{let b=d({chapterId:y.id,action:p.action,branches:y.branches});b&&e.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:p.action.type,action:b})})}let v=({subjectId:y,subjectName:h,action:p})=>{var b;t.pause(),i.emit(m.interactives,{subjectId:y,subjectName:h,type:S.actionExecution,actionType:(b=p==null?void 0:p.type)!=null?b:M.expect})},E=({subjectId:y,subjectName:h})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(m.interactives,{subjectId:y,subjectName:h,type:S.actionExecution,actionType:"after-expect"})},T=({subjectId:y,subjectName:h,subjectType:p,action:b})=>{i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:b.type})},x=({subjectId:y,subjectName:h,subjectType:p,action:b,payload:u})=>{u.behaviour="change-chapter",i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:b.type,payload:u})},F=({subjectId:y,subjectName:h,subjectType:p,action:b,payload:u})=>{u.behaviour="change-manifest",i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:b.type,payload:u})},V=({subjectId:y,subjectName:h,subjectType:p,action:b,payload:u})=>{if(!u.URI)return;let A=window.open(u.URI,"_blank","noopener,noreferrer");A&&(A.opener=null),i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:b.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:v,expectEventHandler:E,setManifestChapterEvents:g,setManifestContainerEvents:c,stopExpect:s,state:r}};var dt=require("@vkontakte/videoplayer-shared");var we=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let r=t.chapters.find(l=>l.id===n);if(!r)return null;let s=t.media.videos.find(l=>r.videoId===l.id);if(!s)return null;e[n]=ni(s)}return e[n]}).filter(Boolean)},sn=i=>{for(let t of i.variants)if(rn(t)&&"payload"in t)return t.payload.id},rn=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",ni=i=>{let t=sn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},an=(i,t)=>{for(let e of i.media.videos)if(t===ni(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},si=(i,t)=>i.reduce((e,n)=>{let r=an(t,n);return r?[...e,r]:e},[]);var it,Et,It,Z,Ve,nt,st,Y,xt,Lt,Nt,Xt=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:r,settings:s}){this.state={history$:new dt.ValueSubject([]),hasPrevChapter$:new dt.ValueSubject(!1),prevChapter$:new dt.ValueSubject(null),isInitialChapter$:new dt.ValueSubject(!1),isGoBackLimited$:new dt.ValueSubject(!1)};C(this,it,null);C(this,Et);C(this,It,!1);C(this,Z,null);C(this,Ve,null);C(this,nt,null);C(this,st,null);C(this,Y,null);C(this,xt,new dt.Subscription);C(this,Lt,!1);C(this,Nt,0);var l,o,c;f(this,nt,e),f(this,Y,t),f(this,st,n),f(this,it,r),f(this,Et,s),(l=this.state)!=null&&l.history$&&a(this,xt)&&((c=a(this,xt))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(d=>{var g,v,E,T,x,F;(g=this.state)==null||g.prevChapter$.next(d.at(-2)||null),(v=this.state)==null||v.hasPrevChapter$.next(d.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((T=(E=a(this,Z))==null?void 0:E.metadata)==null?void 0:T.initChapterId)),(F=this.state)==null||F.isGoBackLimited$.next(a(this,Nt)===a(this,Et).maxLength-1)})))}async setManifest(t){!a(this,st)||!a(this,Y)||(f(this,Z,t),await this.getProjectHistory(),await a(this,st).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,It)||(f(this,It,!0),a(this,Y).emit(m.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,It)}async updateHistory(t,e=!0){var o,c;if(!a(this,Z))return;a(this,Lt)?(f(this,Lt,!1),gi(this,Nt)._++):f(this,Nt,0);let n=a(this,Z),r=t.length-a(this,Et).maxLength,s=r>0?t.slice(r):t,l=we(s,n);if(f(this,Ve,l),(o=this==null?void 0:this.state)==null||o.history$.next(s),!(!e||!a(this,it)||!a(this,nt)))try{await a(this,it).save(a(this,nt),l)}catch(d){(c=a(this,Y))==null||c.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var n;if(!this.state||!a(this,st))return(n=a(this,Y))==null?void 0:n.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));f(this,Lt,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await a(this,st).setChapter({chapterId:e})}async getProjectHistory(){var r,s;if(!a(this,Z)||!a(this,nt))return;let t=a(this,Z),e=[this.getInitialVideoId()];if(a(this,it))try{let l=await a(this,it).get(a(this,nt));l.length&&(e=l)}catch(l){(r=a(this,Y))==null||r.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Error while trying to fetch data"))}let n=si(e,t);(s=this==null?void 0:this.state)==null||s.history$.next(n)}getInitialChapterId(){var e,n;let t=(e=this.state)==null?void 0:e.history$.getValue();return(t==null?void 0:t.at(-1))||a(this,Et).initChapterId||((n=a(this,Z))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,Z)){let t=this.getInitialChapterId();return we([t],a(this,Z)).pop()}return null}destroy(){var t,e;this.state=null,f(this,nt,null),f(this,it,null),f(this,st,null),(t=a(this,xt))==null||t.unsubscribe(),f(this,xt,null),f(this,It,!1),(e=a(this,Y))==null||e.emit(m.historyDestroyed),f(this,Y,null)}};it=new WeakMap,Et=new WeakMap,It=new WeakMap,Z=new WeakMap,Ve=new WeakMap,nt=new WeakMap,st=new WeakMap,Y=new WeakMap,xt=new WeakMap,Lt=new WeakMap,Nt=new WeakMap;var kt,on,qt,cn,pt=class pt{constructor(t,e,n,r){var s;this.target=t,this.type=e,this.listener=n,this.options=N(s=pt,kt,on).call(s,t,r),this.target.addEventListener(e,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}};kt=new WeakSet,on=function(t,e){var n;if(e===void 0)return!1;if(typeof e=="boolean")return e;{let r=new Set(["passive","capture"]),s=Object.keys(e).filter(o=>!r.has(o));return s.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+s.join(",")),N(n=pt,kt,cn).call(n,t)?e:e.capture||!1}},qt=new WeakMap,cn=function(t){let e=a(pt,qt);if(e===void 0){e=!1;try{let n={},r={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",r),Object.defineProperty(n,"capture",r);let s=()=>{};t.addEventListener("test",s,n),t.removeEventListener("test",s,n)}catch(n){e=!1}f(pt,qt,e)}return e||!1},C(pt,kt),C(pt,qt);var Re=pt;var _e=class{constructor(){this.bindingMap=new Kt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,r){if(!this.bindingMap)return;let s=new Re(t,e,n,r);this.bindingMap.push(e,s)}listenOnce(t,e,n,r){let s=l=>{this.unlisten(t,e,s),n(l)};this.listen(t,e,s,r)}unlisten(t,e,n){if(!this.bindingMap)return;let r=this.bindingMap.get(e)||[];for(let s of r)s.target===t&&(n===s.listener||!n)&&(s.unlisten(),this.bindingMap.remove(e,s))}removeAll(){if(!this.bindingMap)return;let t=this.bindingMap.getAll();for(let e of t)e.unlisten();this.bindingMap.clear()}};var Ae=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))==null||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var r;let t=(r=this.rootElement.getContext("2d"))==null?void 0:r.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;let e=t.data,n=e.length;for(let s=3;s<n;s+=40)if(e[s]!==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.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let r;e&&(r=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&r&&this.restore(r),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}};var Me=class{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=t=>{let e=t!=null?t:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(e);if(this.isContainerTime(e))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};this.onSeek=()=>{this.onEachTick(),!this._containerTimeFrameShouldReceived&&!this._endTimeFrameReceived&&(this.hide(),this.lastFrameCanvas.clear())};this.rootElement=document.createElement("div"),this.rootElement.style.cssText=`
|
|
6
|
+
"use strict";var Mn=Object.create;var Ot=Object.defineProperty;var Ln=Object.getOwnPropertyDescriptor;var Nn=Object.getOwnPropertyNames;var kn=Object.getPrototypeOf,jn=Object.prototype.hasOwnProperty;var Pn=(i,t,e)=>t in i?Ot(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var On=(i,t)=>{for(var e in t)Ot(i,e,{get:t[e],enumerable:!0})},Vi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Nn(t))!jn.call(i,s)&&s!==e&&Ot(i,s,{get:()=>t[s],enumerable:!(n=Ln(t,s))||n.enumerable});return i};var $n=(i,t,e)=>(e=i!=null?Mn(kn(i)):{},Vi(t||!i||!i.__esModule?Ot(e,"default",{value:i,enumerable:!0}):e,i)),Bn=i=>Vi(Ot({},"__esModule",{value:!0}),i);var k=(i,t,e)=>(Pn(i,typeof t!="symbol"?t+"":t,e),e),We=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var a=(i,t,e)=>(We(i,t,"read from private field"),e?e.call(i):t.get(i)),g=(i,t,e)=>{if(t.has(i))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(i):t.set(i,e)},f=(i,t,e,n)=>(We(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var Ri=(i,t,e,n)=>({set _(s){f(i,t,s,e)},get _(){return a(i,t,n)}}),L=(i,t,e)=>(We(i,t,"access private method"),e);var us={};On(us,{CustomError:()=>I,EVENT_NAMES:()=>m,INTERACTIVE_CLICK_ACTIONS:()=>be,Interactives:()=>Yt,ManifestController:()=>vt,SDKInfo:()=>ps,chapterIdsToVKVideoIds:()=>_e,compareVersions:()=>tt,getChapterIdByVkVideoId:()=>vn,getVKVideoIdByMedia:()=>mi,getVideoRawIdByMedia:()=>yn,graphEventTypes:()=>Mt,hasEndTemplate:()=>zt,interactivesEventTypes:()=>S,isLastChapter:()=>Y,isSupportedManifest:()=>Gt,isVKVariantItem:()=>gn,utils:()=>_n,vkVideoIdsToChapterIds:()=>yi});module.exports=Bn(us);var _i="1.0.14-dev.2903553f.0";function Qe(i,t=1){let e="0",n="0",s="0";return i.length===4?(e="0x"+i[1]+i[1],n="0x"+i[2]+i[2],s="0x"+i[3]+i[3]):i.length===7&&(e="0x"+i[1]+i[2],n="0x"+i[3]+i[4],s="0x"+i[5]+i[6]),`rgba(${+e},${+n},${+s},${t})`}var D="SDK_NAME",Fn="SDK_NAME-controls-container",se=()=>document.querySelector(`.${Fn}`),Ni=.4,Q={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Ai={top:"flex-start",bottom:"flex-end",center:"center"},Mi={start:"flex-start",end:"flex-end",center:"center"},Li={start:"left",end:"right",center:"center"},re=({target:i,props:t})=>{var e,n,s,r,l,o;i.style.alignItems=(n=Ai[(e=t==null?void 0:t.text)==null?void 0:e.gravityVertical])!=null?n:Ai.center,i.style.justifyContent=(r=Mi[(s=t==null?void 0:t.text)==null?void 0:s.gravityHorizontal])!=null?r:Mi.center,i.style.textAlign=(o=Li[(l=t==null?void 0:t.text)==null?void 0:l.alignment])!=null?o:Li.start},ae=({target:i,props:t,fallback:e,dependsOn:n})=>{var s,r,l,o,c,d;i.style.color=(r=(s=t==null?void 0:t.text)==null?void 0:s.color)!=null?r:e.textColor,i.style.fontSize=`calc(${n.height} * ${(o=(l=t==null?void 0:t.text)==null?void 0:l.size)!=null?o:e.textSize})`,i.textContent=(d=(c=t==null?void 0:t.text)==null?void 0:c.value)!=null?d:e.textContent},oe=({target:i,props:t,fallback:e})=>{var n,s,r,l;i.style.backgroundColor=Qe((s=(n=t==null?void 0:t.background)==null?void 0:n.color)!=null?s:e.backgroundColor,(l=(r=t==null?void 0:t.background)==null?void 0:r.alpha)!=null?l:e.backgroundAlpha)},ce=({target:i,props:t,fallback:e,dependsOn:n})=>{var s,r,l,o,c,d,v,b,E,T,x;i.style.border=`calc(${n.height} * ${(l=(r=(s=t==null?void 0:t.shape)==null?void 0:s.border)==null?void 0:r.width)!=null?l:e.borderWidth}) solid ${Qe((d=(c=(o=t==null?void 0:t.shape)==null?void 0:o.border)==null?void 0:c.color)!=null?d:e.borderColor,(E=(b=(v=t==null?void 0:t.shape)==null?void 0:v.border)==null?void 0:b.alpha)!=null?E:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(x=(T=t==null?void 0:t.shape)==null?void 0:T.roundCorners)!=null?x:e.roundCorners})`},wt=({target:i,layoutParams:t,fallback:e})=>{i.style.transform=`rotate(${-t.angle}rad)`};var Ke="int",Vt={AREA:`${Ke}_area`,TEXT:`${Ke}_text`,BUTTON:`${Ke}_bttn`};var lt=class{constructor(t){this.control=t}createView(t){var s;let e=document.createElement("div");e.classList.add(`${D}-control-container-${this.control.id}`),t(e,this.control.layoutParams);let n=((s=this.control.layoutParams.innerSizesDependOn)!=null?s:Q.innerSizesDependOn)==="self"?{height:e.style.height,width:e.style.width}:{height:"var(--interactive-content-height)",width:"var(--interactive-content-width)"};return{controlContainerEl:e,dependsOn:n}}setEvents(t,e){t&&this.control.events.forEach(n=>{switch(n.type.trim().toLowerCase()){case"onclick":t.addEventListener("click",r=>{r.stopPropagation(),e&&e({action:n.action,controlId:this.control.id,controlType:this.control.type})});break;default:break}})}getElement(){return document.querySelector(`.${D}-control-container-${this.control.id}`)}};var le=i=>{if(i.type.trim().toLowerCase()==="area")return new Xe(i)},Xe=class extends lt{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("button");return r.classList.add(`${D}-${this.control.id}`),r.setAttribute("data-testid",Vt.AREA),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.type="button",oe({target:r,props:this.control.props,fallback:{...Q,backgroundColor:"transparent"}}),ce({target:r,props:this.control.props,fallback:{...Q,borderAlpha:0},dependsOn:n}),wt({target:r,layoutParams:this.control.layoutParams,fallback:Q}),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(`.${D}-${this.control.id}`)}};var he=()=>{let i=document.createElement("span");return i.style.display="inline-block",i.style.whiteSpace="pre",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.maxWidth="100%",i.style.maxHeight="100%",i};var de=i=>{if(i.type.trim().toLowerCase()==="button")return new qe(i)},qe=class extends lt{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("button");r.type="button",r.classList.add(`${D}-${this.control.id}`),r.setAttribute("data-testid",Vt.BUTTON),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.cursor="pointer",r.style.fontFamily="inherit";let l=he();return wt({target:r,layoutParams:this.control.layoutParams,fallback:Q}),oe({target:r,props:this.control.props,fallback:Q}),ce({target:r,props:this.control.props,fallback:Q,dependsOn:n}),re({target:r,props:this.control.props}),ae({target:l,props:this.control.props,fallback:Q,dependsOn:n}),r.append(l),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(`.${D}-${this.control.id}`)}};var ki=i=>{if(i.type.trim().toLowerCase()==="text")return new Ze(i)},Ze=class extends lt{constructor(t){super(t)}createView({parent:t,layoutFn:e}){let{dependsOn:n,controlContainerEl:s}=super.createView(e),r=document.createElement("div");r.classList.add(`${D}-${this.control.id}`),r.setAttribute("data-testid",Vt.TEXT),r.style.display="flex",r.style.width="100%",r.style.height="100%",r.style.fontFamily="inherit";let l=he();return wt({target:r,layoutParams:this.control.layoutParams,fallback:Q}),re({target:r,props:this.control.props}),ae({target:l,props:this.control.props,fallback:Q,dependsOn:n}),r.append(l),s.append(r),t.append(s),this.controlEl=r,s}disable(){}enable(){}getElement(){return document.querySelector(`.${D}-${this.control.id}`)}};var Ye=class{constructor(t){this.layout=t}},ji=i=>{if(i.type.trim().toLowerCase()==="relative")return new $t(i)},$t=class extends Ye{constructor(t){super(t)}setContainerLayout(t){t.style.position="relative"}setControlLayout(t,e){t.style.position="absolute",t.style.width=`calc(var(--interactive-content-width) * ${e.width})`,t.style.height=`calc(var(--interactive-content-height) * ${e.height})`,t.style.left=`calc(var(--interactive-content-width) * ${e.x} + ((var(--interactive-width) - var(--interactive-content-width)) / 2))`,t.style.top=`calc(var(--interactive-content-height) * ${e.y} + ((var(--interactive-height) - var(--interactive-content-height)) / 2))`}};var Rt,pe,ue,Pi,_t=class{constructor(t){g(this,Rt);g(this,ue);this.container=t,this.factories=new Map,L(this,Rt,pe).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),L(this,Rt,pe).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),L(this,Rt,pe).call(this)}};Rt=new WeakSet,pe=function(){this.controls=L(this,ue,Pi).call(this)},ue=new WeakSet,Pi=function(){var t;return(t=this.container.controls)==null?void 0:t.reduce((e,n)=>{let s=n.type.trim().toLowerCase(),r=this.factories.get(s);return r?[...e,r(n)]:[...e]},[])};var fe=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Je(i,t)},Je=class extends _t{constructor(t,e){super(t),this.rootElement=e!=null?e:se(),this.layout=new $t(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",de),this.addControlFactory("text",ki),this.addControlFactory("area",le)}createView(t){let e=document.createElement("div");return e.classList.add(`${D}-${this.container.id}`),this.layout.setContainerLayout(e),this.controls.forEach(n=>{let s=n.createView({parent:e,layoutFn:this.layout.setControlLayout});n.setEvents(s,t)}),this.rootElement.append(e),this.isRemoved=!1,e}hide(){let t=this.getElement();t&&(t.style.visibility="hidden")}show(){let t=this.getElement();t&&(t.style.visibility="visible")}enable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.enable()),t.style.opacity=1,this.isDisabled=!1)}disable(){let t=this.getElement();t&&(this.controls.forEach(e=>e.disable()),t.style.opacity=Ni,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())==null||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${D}-${this.container.id}`)}};var N=require("@vkontakte/videoplayer-shared");var Di=require("@vkontakte/videoplayer-shared");function me(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}var Bt={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},mt=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Ft=i=>mt(i,Bt.Object),ye=i=>mt(i,Bt.String),ge=i=>mt(i,Bt.Array),ve=i=>mt(i,Bt.Number),Oi=i=>mt(i,Bt.Function);var ti=i=>ve(i)&&!isNaN(i);var yt=i=>Ft(i)&&Object.keys(i).length===0,ei=i=>ge(i)&&!i.length;var Dt=(i,t)=>ye(i)&&(t?i.trim():i).length;var ii=window.navigator.userAgent.toLowerCase(),er=/ipad|iphone|ipod/.test(ii),$i=/mobi/i.test(ii),ir=ii.indexOf("android")>-1&&$i,Dn=!$i,nr=window.safari!==void 0&&Dn;var Bi="video_interactive",Fi="videoint";var Hn=250,Ht=class{constructor(t){k(this,"onResize",t=>{this.isReady&&(!t[0].contentRect.width||!t[0].contentRect.height||(this.lastZoomInfo&&this.ngEditor.zoomTo(this.getNextPoint()),this.ngEditorSize={width:t[0].contentRect.width,height:t[0].contentRect.height}))});k(this,"handleChapterChange",t=>{var e;if(this.isReady){if(this.isHidden||this.hide(),!(t!=null&&t.id)){(e=this.onError)==null||e.call(this,"Id is not found"),console.error("Id is not found");return}this.visitedChapterIds.add(t.id),this.ngEditor.selectChapter(t.id),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.currentChapterId=t.id,this.lastZoomInfo=void 0}});k(this,"handleManifestChange",async(t,e=[])=>{var n;if(!ve(t.graph.edit.chapters[0].x)){this.isReady=!1,(n=this.onError)==null||n.call(this,"Can't show graph"),console.error("Can't show graph");return}if(this.lastZoomInfo=void 0,!this.ngEditor){let s;try{s=await(0,Di.loadVKLangPack)(this.lang,Bi,Fi)}catch(l){console.log("Unable to load graph language pack")}let{GraphEditor:r}=await import("@interactiveplatform/movika-graph-editor");this.ngEditor=new r(this.graphWrapperElement,{mode:"read",lang:this.lang,translation:s}),this.ngEditor.on("control",({name:l,chapterId:o})=>{l==="openPreview"&&this.onOpenPreviewClick(o)}),this.ngEditor.on("zoomEnd",l=>{this.lastZoomInfo={...l}})}this.visitedChapterIds=new Set(e),t.metadata.id!==this.currentManifestId?(this.ngEditor.update(t),this.currentManifestId=t.metadata.id):this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds)),this.isReady=!0});this.init(t)}init({root:t,onOpenPreviewClick:e,onError:n,lang:s,visitedChapters:r=[]}){this.isHidden=!0,this.currentManifestId=void 0,this.currentChapterId=void 0,this.visitedChapterIds=new Set(r),this.onOpenPreviewClick=e,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=Gn(t),this.resizeObserver=new ResizeObserver(me(this.onResize,Hn)),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,e;this.hide(),this.resizeObserver.disconnect(),(t=this.ngEditor)==null||t.setVisitedChapters([]),this.onOpenPreviewClick=void 0,(e=this.ngEditor)==null||e.dispose(),this.graphWrapperElement.remove(),this.isReady=!1}};function Gn(i){let 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",i.append(t),t}var ni=()=>{let i=[],t=null;return{setPlayer:l=>{t=l},setContainers:l=>{i=l},deleteContainer:l=>{i=i.filter(o=>o.id!==l)},getNextInteractiveTime:(l=3e3)=>{if(!i.length||t===null)return null;let o=-1,c=!1,d=Math.round(t.info.position$.getValue()*1e3);for(let v of i){let b=v.startTime-l;if(b<=d&&(d<=v.endTime||v.endTime===null)){c=!0;break}d<b&&(o=o===-1?b:Math.min(o,b))}return!c&&o!==-1?o:null}}};var tt=(i="",t="")=>{i=i.split("."),t=t.split(".");let e=0;for(let n=0;n<Math.max(i.length,t.length)&&!e;n++)i[n]>t[n]?e=1:i[n]<t[n]?e=-1:e=0;return e};var Gi=require("uuid"),Un="3.1",Hi={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},zn={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Ui=i=>{let t=[];for(let e of i.chapters){let n,s=[];for(let{isDefault:o,...c}of e.branches)o&&(n=c.id),s.push(c);let r=[],l=[];for(let{fallbackStrategy:o,...c}of e.containers){let d=!!c.endTime,v=[zn];switch(o){case"await":d?v=[]:r=[];break;case"default":{let b={type:"onSuspense",action:{type:Hi.default,args:{branchId:n,shouldOpenNow:!d,isDetachContainer:!0}}};d?v=[b]:r=[b];break}case"random":case"weightlessRandom":case"max":case"min":{let b={type:"onSuspense",action:{type:Hi[o],args:{}}};d?v=[b]:r=[b];break}}for(let b of c.controls)l.push({...c,controls:[{...b}],id:(0,Gi.v4)(),events:v})}t.push({...e,containers:l,events:r,branches:s})}return i.metadata.version=Un,i.metadata.updated=new Date().toISOString(),{...i,chapters:t}};var Wn="3.2",zi=i=>{if(!i.media){let{media:t,...e}=i.metadata;return{...i,metadata:{...e,version:Wn},media:t}}return i};var Qn="3.3",Kn=(i=[])=>({edit:{chapters:i},view:{}}),Wi={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},Qi=i=>{var n;let t=[],e=[];for(let s of i.chapters){let{id:r,x:l,y:o,...c}=s,d=c.containers.map(v=>{var b;return{...v,controls:v.controls.map(({subtype:E,type:T,...x})=>({...x,type:E!=null?E:T})),events:(b=v.events)!=null&&b.length?v.events:[Wi]}});t.push({id:r,...c,containers:d,events:(n=c.events)!=null&&n.length?c.events:[Wi]}),e.push({id:r,x:l,y:o})}return{...i,chapters:t,graph:Kn(e),metadata:{...i.metadata,version:Qn}}};var Xn=[{version:"3.0",migrate:Ui},{version:"3.1",migrate:zi},{version:"3.2",migrate:Qi}],si=i=>Xn.reduce((t,e)=>tt(t.metadata.version,e.version)?t:e.migrate(t),i);var Vr=Object.freeze({Choice:"Choice",TextInput:"TextInput"}),Ki=Object.freeze({Button:"Button",Area:"Area",Text:"Text"}),Rr=Object.freeze({onClick:"onClick",onSuspense:"onSuspense"}),A=Object.freeze({openURI:"openURI",setNextBranch:"setNextBranch",setWeightlessRandomBranch:"setWeightlessRandomBranch",setRandomBranch:"setRandomBranch",setMaxWeightBranch:"setMaxWeightBranch",setMinWeightBranch:"setMinWeightBranch",setDefaultBranch:"setDefaultBranch",continuePlayback:"continuePlayback",expect:"expect"}),be=(r=>(r.GO_NEXT_BUTTON="GO_NEXT_BUTTON",r.GO_NEXT_AREA="GO_NEXT_AREA",r.WATCH_AGAIN="WATCH_AGAIN",r.OPEN_GRAPH="OPEN_GRAPH",r.CLOSE_GRAPH="CLOSE_GRAPH",r))(be||{});var Xi={metadata:"Object",chapters:"Array"},qn="3.0.0",Zn="3.3.0",Gt=i=>{let t=tt(i,qn);return t===-1?!1:t===0?!0:tt(i,Zn)!==1},qi=i=>{if(!Ft(i))return!1;for(let t in Xi)if(!i[t]||!mt(i[t],Xi[t]))return!1;return Gt(i.metadata.version)},Ce=i=>i.type===Ki.Text;var I=class{constructor(t,e,...n){this.severity=t,this.category=e,this.data=n}toString(){return`SDK_NAME ERROR ${JSON.stringify(this,null," ")}`}};k(I,"Severity",{RECOVERABLE:1,CRITICAL:2}),k(I,"Category",{VIDEO:0,INTERACTIVES:1,GRAPH:2,MANIFEST:3,LOADERS:4,HISTORY:5,SEAMLESS:6});var At=class{constructor(){k(this,"listeners",{})}addListener(t,e){return this.listeners[t]=this.listeners[t]||[],this.listeners[t].push(e),this}on(t,e){return this.addListener(t,e)}once(t,e){this.listeners[t]=this.listeners[t]||[];let n=()=>{e(),this.off(t,n)};return this.listeners[t].push(n),this}off(t,e){return this.removeListener(t,e)}reset(){this.listeners={}}removeListener(t,e){let n=this.listeners[t];if(!n)return this;for(let s=n.length;s>0;s--)if(n[s]===e){n.splice(s,1);break}return this}emit(t,...e){let n=this.listeners[t];return n?(n.forEach(s=>{s(...e)}),!0):!1}listenerCount(t){return(this.listeners[t]||[]).length}rawListeners(t){return this.listeners[t]}};var Ee=class{constructor(t){k(this,"addFn",(t,e=!1)=>{Oi(t)&&(this.fns.push(t),e&&this.updateFn())});k(this,"removeFn",(t,e=!1)=>{this.fns=this.fns.filter(n=>n!==t),e&&this.updateFn()});k(this,"updateFn",()=>{this.fn=()=>{this.fns.forEach(t=>t()),this.raf&&this.forceRequestAnimation()}});k(this,"forceRequestAnimation",()=>{this.fn&&(this.raf=requestAnimationFrame(this.fn))});k(this,"requestAnimation",()=>{this.raf||this.forceRequestAnimation()});k(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=[]}};var en=require("@vkontakte/videoplayer-shared");var Ie=class{constructor(t){var e,n;this.loaders={chapterLoaders:(e=t==null?void 0:t.chapterLoaders)!=null?e:[],manifestLoaders:(n=t==null?void 0:t.manifestLoaders)!=null?n:[]}}async exec(t,e){return Yn(...this.loaders[t])(e)}};function Yn(...i){return async function(e){let n=[...i];for(;n.length>0;)e=await n.shift()(e);return e}}function Ut(i,t,e){return i?{...i,[t]:i[t]?[e,...i[t]]:[e]}:{[t]:[e]}}function xe({actions:i,errors:t,chapterId:e,...n}){if(e){let s=i.getManifest(),r=i.getChapter(s.chapters,e);if(r){let l=i.getMedia(s.media,r.videoId),o=i.getGraph(s.graph,r.id);return l?{...n,actions:i,errors:t,result:{chapter:r,media:l,graph:o}}:{...n,errors:Ut(t,xe.name,"Could not find media"),actions:i}}}return{...n,errors:Ut(t,xe.name,"Could not find chapter"),actions:i}}var Jn=async i=>{try{let t,e;if(Ft(i))t=i;else if(ye(i)){e=new URL(i).href;let s=await fetch(e);if(!s.ok)return{};t=await s.json()}else return{};if(!qi(t))return{};let n=t.metadata.media;if(ye(n)&&!t.media)try{let s;e?s=new URL(n,e).href:(s=new URL(n).href,e=s);let r=await fetch(s);if(!r.ok)throw new Error;t.metadata.media=await r.json()}catch(s){return is(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}};async function Zi(i){let{manifest:t,manifestURL:e}=await Jn(i),n=si(t);return n.media=ts(n.media,e),delete n.metadata.media,n}function Te(i,t){return i.find(e=>e.id===t)}function ri(i,t){var e,n;return(e=i.edit)!=null&&e.chapters?i.edit.chapters.find(s=>s.id===t):(n=i.view)!=null&&n.chapters?i.view.chapters.find(s=>s.id===t):void 0}function ai(i,t){return i.videos.find(e=>e.id===t)}function ts(i,t){return{...i,videos:i.videos.map(e=>({...e,variants:e.variants.map(n=>{let s=es(n.url,t);return{...n,url:s||n.url}})}))}}function es(i,t){try{return new URL(i,t).href}catch(e){return""}}function is(i){return tt(i,"3.2.0")>=0}var O=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Se=i=>ge(i)&&!ei(i),Y=i=>i.order==="end",zt=i=>ge(i.containers)&&!ei(i.containers)&&Y(i),Yi=(i,t)=>{var n;let e=i*1e3;return Se(t.controls)&&e<((n=t.startTime)!=null?n:0)},oi=(i,t)=>{var n,s;let e=i*1e3;return Se(t.controls)&&e>=((n=t.startTime)!=null?n:0)&&e<=((s=t.endTime)!=null?s:1/0)};var gt=i=>i.some(t=>t.action.type==="expect"),ci=i=>i.find(t=>t.action.type==="expect"),ns=i=>(i==null?void 0:i.length)===1,we=i=>ns(i)&&Ce(i[0]);var Ji=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i({...n[t],...e[t]}),tn=(i,t)=>gt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&>(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);var vt=class extends Ie{constructor(t,e){super(t),this.onError=e,this.prevChapter$=new en.ValueSubject(null),this.release()}release(){return this.manifest=null,this.chapter=null,this.media=null,this.graph=null,this.prevChapter$.next(null),this}async setManifest(t){var s;this.release();let e=await this.exec("manifestLoaders",{actions:{addErrorMessage:Ut},result:null,errors:null,source:t});e.errors&&this.errorHandler(e.errors);let n=await Zi((s=e.result)!=null?s:t);return this.manifest=n,this}async setInitial(){return this.setNext()}async setNext(t=this.manifest.metadata.initChapterId){this.prevChapter$.next(this.chapter);let e=await this.exec("chapterLoaders",xe({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:ri,getChapter:Te,getMedia:ai,getByBranches:this.getByBranches.bind(this),addErrorMessage:Ut},result:null,errors:null,chapterId:t}));return e.errors&&this.errorHandler(e.errors),this.chapter=e.result.chapter,this.media=e.result.media,this.graph=e.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){let e=Te(this.manifest.chapters,t);if(e){let n=ai(this.manifest.media,e.videoId),s=ri(this.manifest.graph,e.id);if(n)return{chapter:e,media:n,graph:s}}return null}getBranches(t=this.chapter.id){if(t===this.chapter.id)return this.getByBranches(this.chapter.branches);{let e=Te(this.manifest.chapters,t);return this.getByBranches(e==null?void 0:e.branches)}}getByBranches(t=[]){return t.reduce((e,n)=>{let s=this.getByChapterId(n.chapterId);return s&&e.push(s),e},[])}getCurrent(){return{chapter:this.chapter,media:this.media,graph:this.graph}}isInitialChapter(){return this.chapter.id===this.manifest.metadata.initChapterId}isEndChapter(){return Y(this.chapter)}};var sn=require("@vkontakte/videoplayer-core"),rn=require("@vkontakte/videoplayer-shared");var nn=i=>{let t=i.variants.find(e=>{var n;return((n=e.payload)==null?void 0:n.type)==="vk"});if(t&&"payload"in t){let[e,n]=t.payload.id.split("_");return[e,n]}return[]};var m={graph:"graph",interactives:"interactives",chapterChanged:"chapter-changed",playerChanged:"player-changed",manifestChanged:"manifest-changed",errors:"errors",eachTick:"eachTick",historyInited:"history-inited",historyDestroyed:"history-destroyed"},Mt={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},S={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function li(){let i=new Map;function t({listId:s=Math.random().toString(),itemId:r=Math.random().toString(),...l}){let o=i.get(s),c={...l};return o?o[r]=c:i.set(s,{[r]:c}),{listId:s,itemId:r,...l}}function e(s,r){var o,c,d;let l=i.get(s);if(l){if(r)return(o=l[r])==null||o.player.destroy(),(c=l[r])==null||c.container.remove(),(d=l[r])==null||d.subscription.unsubscribe(),delete l[r],Object.keys(l).length||i.delete(s),!0;for(let v of Object.values(l))v.player.destroy(),v.container.remove();return i.delete(s),!0}else throw Error("Can't remove. Not find.")}function n(){for(let s of i)e(s[0])}return{createPlayer:t,removePlayer:e,map:i,removeAll:n}}function hi(i,t=[]){var r,l,o;let e={},n,s=!t.length;for(let c of i.variants)if(!n&&"cover"in c&&(n=c.cover),"url"in c)switch(c.type.toLowerCase()){case"mp4":(s||t.includes("mp4"))&&(e.MPEG={...e.MPEG,[(r=c.standard)!=null?r:"Invariant quality"]:c.url});break;case"mpeg":(s||t.includes("mpeg"))&&(e.MPEG={...e.MPEG,[(l=c.standard)!=null?l:"Invariant quality"]:c.url});break;case"hls":(s||t.includes("hls"))&&(e={...e,HLS:{type:"url",url:c.url}});break;case"dash":(s||t.includes("dash"))&&(e={...e,DASH_SEP:{compatibilityMode:!0,type:"url",url:c.url}});break;default:break}return{sources:e,thumbUrl:n,title:(o=i.title)!=null?o:""}}var Wt=(i,t)=>{let e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))};var Qt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},ss=2;function di(i){let t=li(),e,n,s=new At,r={},l=!1,o=null,c=!1,d;i&&v(i);function v(h){o=h}function b(h,p,C){var M;if(!o)throw Error("need to set interactive controller");if(!o.options)return;let _=((M=t.map.get(h))!=null?M:{})[p];if(_){r={chapterId:C,listId:h,itemId:p,..._};let P=r.player;n=P.info.currentQuality$.subscribe(V=>{if(!(!V||!P.info.position$.getValue())){e=V;for(let W of t.map)Object.values(W[1]).forEach(({player:F})=>{P.info.isAutoQualityEnabled$.getValue()||Wt(F,V)})}}),_.container.remove(),l=!1,o.setPlayer(_.player),c||(o.init(),c=!0),s.emit(Qt.activePlayerChanged,{player:r.player,config:r.config});return}throw Error("Can't set. Not find.")}async function E(h,p,C){if(!o)throw Error("need to set interactive controller");if(yt(r)||h!==r.itemId)return;if(C>=0&&!l){let _=o.getChapterBranches();l=!0;let M=new Set;for(let P of _)M.has(P.media.id)||(await x({media:P.media,chapterId:P.chapter.id,setAsActive:!1,title:P.chapter.label}),M.add(P.media.id))}}async function T({chapter:{id:h},media:p}){if(yt(r))return;n==null||n.unsubscribe();let C=r.player.info.muted$.getValue(),u=r.player.info.currentQuality$.getValue(),_=r.player.info.isAutoQualityEnabled$.getValue(),M=r.player.info.volume$.getValue(),P=r.player.info.currentPlaybackRate$.getValue(),V=!_,W=!1;for(let F of t.map)if(F[0]===p.id){let J=Object.keys(F[1]);for(let U of J)U===r.itemId?(J.length<ss||(W=!0),t.removePlayer(F[0],U)):(W=!0,b(F[0],U,h),V?Wt(r.player,u):r.player.setAutoQuality(!0),r.player.setVolume(M),r.player.setMuted(C),r.player.setPlaybackRate(P))}else t.removePlayer(F[0]);W||(await x({media:p,chapterId:h,setAsActive:!0,playbackRate:P}),V?Wt(r.player,u):r.player.setAutoQuality(!0),r.player.setVolume(M),r.player.setMuted(C))}async function x({media:h,chapterId:p,prefetch:C=!0,setAsActive:u=!0,autoplay:_=!1,preferredExt:M,title:P,playbackRate:V}){var Ii,xi,Ti,Si,wi;let W=Math.random().toString(),F=document.createElement("div");d.append(F);let J=(Ii=r==null?void 0:r.player)==null?void 0:Ii.info.isAutoQualityEnabled$.getValue(),U;if((xi=o==null?void 0:o.options)!=null&&xi.vkVideoLoader){let ne=nn(h);ne.length&&(U=await o.options.vkVideoLoader(...ne))}let ie=((Ti=o==null?void 0:o.options)==null?void 0:Ti.coreConfig)||{},An={...ie,configName:[...(Si=ie.configName)!=null?Si:[],"interactive"]},Ci={container:F,...((wi=U==null?void 0:U.videos)==null?void 0:wi[0])||{sources:hi(h,M).sources},title:P,failoverHosts:(U==null?void 0:U.failoverHosts)||[]},ft=new sn.Player(An);ft.initVideo(Ci);let Ei=new rn.Subscription;Ei.add(ft.info.position$.subscribe(function(ne){E(W,ft.info.duration$.getValue(),ne)})).add(ft.events.canplay$.subscribe(function(){J||Wt(ft,e),V&&ft.setPlaybackRate(V)}));let St=t.createPlayer({listId:h.id,itemId:W,player:ft,container:F,sources:hi(h,M).sources,config:Ci,subscription:Ei});return u&&b(h.id,St.itemId,p),_&&St.player.play(),C&&!_&&St.player.prepare(),s.emit(Qt.playerCreated,St.player),{player:St.player,config:St.config}}function B(){w(),o=null}function w(){o==null||o.off(m.chapterChanged,T),t.removeAll(),r={},c=!1,l=!1}async function y({container:h}){if(!o)throw Error("need to set interactive controller");w(),d=h;let{media:p,chapter:C}=o.getCurrentChapter();if(p){o.on(m.chapterChanged,T);let{player:u,config:_}=await x({media:p,chapterId:C.id,title:C.label});return s.emit(Qt.initiated,{container:h,media:p,chapterId:C.id}),{player:u,config:_}}else console.error("not found")}return{...t,on:s.on.bind(s),off:s.off.bind(s),init:y,setInteractiveController:v,createPlayer:x,removeAll:B,getActivePlayer:function(){return r}}}var an=require("@vkontakte/videoplayer-shared");var Ve=class{constructor({player:t,container:e,branches:n,selectBranches:s,interactiveEvents:r,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d,onRemove:v}){k(this,"hide",()=>{setTimeout(()=>{var t,e;this.gameState!==O.end&&(gt(this.container.container.events)&&this.gameState===O.afterInteractive||this.selectBranches.state.isExpect||(this.gameState!==O.interactive&&((e=(t=this.container).hide)==null||e.call(t)),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})))})});k(this,"show",()=>{var t,e,n,s;if(this.gameState===O.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(s=(n=this.container).show)==null||s.call(n),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!0,isFirst:!1});else{let l=Ji({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})},onEvent:(o,c)=>{this.isSelectedControlEvent=!0,o!==!1&&(this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})),(this.gameState===O.end||this.gameState===O.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),c(),this.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1}))},isEOV:()=>this.gameState===O.end});this.container.createView(l),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!0,isFirst:!0}),this.disabledControls$.getValue()&&((e=(t=this.container).disable)==null||e.call(t))}});k(this,"onEndOfVideo",()=>{this.gameState=O.end,this.selectContainerEvent(!0)});k(this,"whilePlaying",()=>{var r,l;if(((r=this.player.experimental.element$.getValue())==null?void 0:r.readyState)<1||[O.destroyed,O.removed].includes(this.gameState)&&!this.isPermanentText)return;let e=this.player.getExactTime();if(Yi(e,this.container.container))this.gameState!==O.beforeInteractive&&(this.gameState=O.beforeInteractive,this.onBeforeStartTime());else if(oi(e,this.container.container))this.gameState!==O.interactive&&(this.gameState=O.interactive,this.onStartTime());else if(this.gameState!==O.afterInteractive){let o=this.gameState;this.gameState=O.afterInteractive,o===O.interactive&&this.onEndTime()}else this.gameState!==O.destroyed&&!this.isPermanentText&&this.removeView();let n=oi(e,this.container.container),s=this.container.container.startTime?[this.container.container.startTime,(l=this.container.container.endTime)!=null?l:1/0]:[];this.globalEventEmitter.emit(m.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:s,currentTime:e,isInteractiveTime:n})});this.container=e,this.branches=n,this.selectBranches=s,this.subscription=new an.Subscription,this.player=t,this.interactiveEvents=r,this.ignoreContainerEvent=o,this.isPermanentText=c&&we(e.container.controls),this.disabledControls$=d,this.onRemove=v,this.globalEventEmitter=l,this.gameState=O.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 e,n,s,r;t?(n=(e=this.container).disable)==null||n.call(e):(r=(s=this.container).enable)==null||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);let t=gt(this.container.container.events)||this.ignoreContainerEvent();(this.isSelectedControlEvent||!t)&&this.removeView()}onBeforeStartTime(){var t,e;(e=(t=this.container).hide)==null||e.call(t),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=O.beforeInteractive}removeView(){var t;this.container.removeView(),this.globalEventEmitter.emit(m.interactives,{subjectId:this.container.container.id,subjectName:"container",type:S.containerRemoved,visibility:!1}),this.gameState=O.removed,(t=this.onRemove)==null||t.call(this)}destroy(){var t;this.reset(),this.removeView(),this.gameState=O.destroyed,this.subscription.unsubscribe(),this.branches=[],this.interactiveEvents.containersEventsCallState.setCalled({timestamp:(t=this.container.container.endTime)!=null?t:1/0,id:this.container.container.id})}};var on=(i=[])=>i.reduce((t,e,n)=>{var r,l,o;let s=((r=e==null?void 0:e.controls)!=null?r:[]).filter(c=>!Ce(c));if(Se(s)){let c=[(l=e.startTime)!=null?l:0,(o=e.endTime)!=null?o:1/0],d=e.id;if(!n)t.push({subjects:[d],range:c});else{let v=[],b=-1/0,E=1/0,T=[],x=[];for(let B=0;B<t.length;B++){let w=t[B];if(x.push(...w.subjects),w.range[0]<E&&(E=w.range[0]),w.range[1]>b&&(b=w.range[1]),c[0]>=w.range[0]&&c[1]<=w.range[1])return t[B].subjects.push(d),t;c[0]<w.range[0]&&c[1]>w.range[0]&&(v.push(B),T=T.concat(w.subjects)),c[0]>=w.range[0]&&c[0]<=w.range[1]&&(v.push(B),T=T.concat(w.subjects),c[0]=w.range[0]),c[1]>=w.range[0]&&c[1]<=w.range[1]&&(v.push(B),T=T.concat(w.subjects),c[1]=w.range[1])}if(x.push(d),c[0]<=E&&c[1]>=b)return[{subjects:x,range:c}];v.length&&v.reverse().forEach(B=>{t.splice(B,1)}),t.push({subjects:T.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]);function cn(){let i={};function t(){for(let o in i)Object.prototype.hasOwnProperty.call(i,o)&&delete i[o];return!0}function e(o){let c={};for(let d in i)+d<=o&&(c[d]=i[d]);return c}function n(o){let c={};for(let d in i)+d>=o&&(c[d]=i[d]);return c}function s({timestamp:o,priority:c,initiator:d}){var v;if(ti(o)){let b=(v=i[o])!=null?v:null;if(b&&Dt(c,!0)){let E={},T=b[c];if(T&&(E={...E,...T}),E=yt(E)?null:E,E&&Dt(d,!0)){let x=E[d];return x!=null?x:null}return E}return b}return null}function r({timestamp:o,priority:c,initiator:d}){if(ti(o))if(i[o]){if(Dt(c,!0))if(i[o][c]){if(Dt(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!yt(i[o][c]))return!0}else return!1;if(delete i[o][c],!yt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l({timestamp:o,priority:c,initiator:d,...v}){var b,E,T;(E=(b=i[o])==null?void 0:b[c])!=null&&E[d]?i[o][c][d].push({...v}):(T=i[o])!=null&&T[c]?i[o][c]={...i[o][c],[d]:[{...v}]}:i[o]?i[o]={...i[o],[c]:{[d]:[{...v}]}}:i[o]={[c]:{[d]:[{...v}]}}}return{map:i,remove:r,add:l,removeAll:t,get:s,getLte:e,getGte:n}}var rs=[A.expect,A.setNextBranch],as=1/0;function pi(i){let t=i,e,n=os(),s=new cn,r,l=()=>{E(),y()},o=h=>{s.add.call(void 0,h),x()},c=(h=[])=>{for(let p of h)if(p.action(),rs.includes(p.actionType))break},d=(h=1/0)=>{var _,M,P;let p=Re((_=s.get({timestamp:h,priority:"control"}))!=null?_:{}),C=Re((M=s.get({timestamp:h,priority:"container"}))!=null?M:{}),u=Re((P=s.get({timestamp:h,priority:"chapter"}))!=null?P:{});return[...p,...C,...u]},v=h=>{n.isReady(h)&&c(d(h))},b=()=>{var h;c([...Re((h=s.get({timestamp:1/0,priority:"chapter"}))!=null?h:{})])},E=()=>{e&&(r==null||r.unsubscribe(),e=void 0)},T=h=>{},x=()=>{e||(e=()=>setTimeout(()=>{v(1/0)}),r=t.events.ended$.subscribe(e))},B=h=>{E(),t=h},w=h=>{h.priority==="container"&&n.resetCalled(h.timestamp),s.remove(h)},y=()=>{n.release(),s.removeAll()};return{setPlayer:B,add:o,remove:w,exec:v,execEndOfVideo:b,listen:x,unlisten:E,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function os(){let i=new Map;return{setCalled:({timestamp:l,id:o})=>{let c=i.get(l);c&&c[o]!==void 0&&(c[o]=!0)},setData:(l=[])=>{var o,c;for(let d of l){let v=(o=d.endTime)!=null?o:as,b=(c=i.get(v))!=null?c:{};i.set(v,{...b,[d.id]:!1})}},resetCalled:l=>{let o=i.get(l);if(o)for(let c in o)o[c]=!1},isReady:l=>{let o=i.get(l);return o?!Object.values(o).some(c=>!c):!0},release:()=>i.clear()}}function Re(i){return Object.values(i).flat().sort(t=>t.actionType===A.expect?-1:1)}var ln=(i,t)=>{let{height:e,width:n}=t.info.intrinsicVideoSize$.getValue()||{};if(!(e&&n))return{videoContentHeight:0,videoContentWidth:0};let{clientHeight:s,clientWidth:r}=t.experimental.element$.value||{};if(!(s&&r))return{videoContentHeight:0,videoContentWidth:0};let l=e/n,o=s/r,c,d;return o>l?(d=r,c=r*l):o<l?(d=s/l,c=s):(d=r,c=s),{videoContentWidth:d,videoContentHeight:c}};var cs=250;function hn(i){let t=()=>{},e=new ResizeObserver(o=>{r(o),t=r.bind(null,o)});function n(o){let{parentElement:c,player:d}=i();if(c&&d){let{videoContentWidth:v,videoContentHeight:b}=ln(c,d);c.style.setProperty("--interactive-content-width",`${v}px`),c.style.setProperty("--interactive-content-height",`${b}px`),c.style.setProperty("--interactive-width",`${o[0].contentRect.width}px`),c.style.setProperty("--interactive-height",`${o[0].contentRect.height}px`)}}function s(){let{parentElement:o}=i();o.removeAttribute("style")}let r=me(o=>{let{fns:c=[]}=i();n(o);for(let d of c)d()},cs);function l(){t=void 0,e.disconnect(),s()}return{resizeObserver:e,calc:()=>{t()},release:l}}var Kt=class{constructor(){this.map={}}push(t,e){t in this.map?this.map[t].push(e):this.map[t]=[e]}get(t){let e=this.map[t];return e?e.slice():null}getAll(){let t=[];for(let e in this.map)t.push(...this.map[e]);return t}remove(t,e){t in this.map&&(this.map[t]=this.map[t].filter(n=>n!==e),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)}};var ls=i=>Math.floor(Math.random()*i),dn=i=>{let t=i.length,e=1/0,n=null;for(;t--;)i[t].weight<e&&(e=i[t].weight,n=i[t]);return n},pn=i=>{let t=i.length,e=-1/0,n=null;for(;t--;)i[t].weight>e&&(e=i[t].weight,n=i[t]);return n};var un=i=>{let t=i.length,e=ls(t);return i[e]};var fn=i=>{var n,s;let t=0;for(let r=0;r<i.length;++r)t+=(n=i[r].weight)!=null?n:1;let e=Math.random()*t;t=0;for(let r=0;r<i.length-1;++r)if(t+=(s=i[r].weight)!=null?s:1,t>=e)return i[r];return i[i.length-1]};var mn=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0});var ui=(i,t=!1)=>({...i,args:t?{...i.args,...mn}:{...mn,...i.args}}),fi=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{let s={isExpect:!1},r=()=>{s.isExpect&&(s.isExpect=!1)},l=({action:y,controlType:h,controlId:p,containerId:C,branches:u=[],onEvent:_,isEOV:M=()=>!1,isDisabled:P=()=>!1})=>{let V=ui(y,M()),W={timestamp:1/0,priority:"control",initiator:p,actionType:V.type},F=P(),J=i.emit.bind(i,m.interactives,{subjectId:p,subjectType:h,subjectName:"control",type:F?S.actionChoiceCanceled:S.actionChoice,actionType:y.type,payload:{containerId:C,...V.args}});if(F){J();return}switch(V.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let U=u.find(ie=>ie.id===V.args.branchId);if(!U)return;_(V.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),J(),V.args.shouldOpenNow?x({subjectId:p,subjectName:"control",subjectType:h,action:V,payload:{chapterId:U.chapterId,autoSelect:!1}}):(e.add({...W,action:x.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:V,payload:{chapterId:U.chapterId,autoSelect:!1}})}),n==null||n());return}case A.continuePlayback.trim().toLowerCase():{_(V.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),J(),V.args.shouldOpenNow?T({subjectId:p,subjectName:"control",subjectType:h,action:y}):e.add({...W,action:T.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:y})});return}case A.openURI.trim().toLowerCase():{_(V.args.isDetachContainer,E.bind(null,{subjectId:p,subjectName:"control"})),J(),V.args.shouldOpenNow?w({subjectId:p,subjectName:"control",subjectType:h,action:V,payload:{URI:y.args.uri}}):(e.add({...W,action:w.bind(null,{subjectId:p,subjectName:"control",subjectType:h,action:V,payload:{URI:y.args.uri}})}),n==null||n());return}default:console.error("Unexpected control event"),i.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected control event"}));return}},o=({action:y,container:{id:h,endTime:p},branches:C=[],isEOV:u=!1,autoSelected:_=!1})=>{let M=ui(y,u),P={timestamp:!M.args.shouldOpenNow||u?1/0:p,priority:"container",initiator:h,actionType:M.type},V=i.emit.bind(i,m.interactives,{subjectId:h,subjectName:"container",type:S.actionChoice,actionType:M.type,payload:M.args});switch(M.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let W=C.find(F=>F.id===M.args.branchId);if(!W)return;V(),e.add({...P,action:x.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{chapterId:W.chapterId,autoSelect:_}})}),n==null||n();return}case A.setMaxWeightBranch.trim().toLowerCase():return;case A.setMinWeightBranch.trim().toLowerCase():return;case A.setRandomBranch.trim().toLowerCase():return;case A.setWeightlessRandomBranch.trim().toLowerCase():return;case A.continuePlayback.trim().toLowerCase():{V(),e.add({...P,action:T.bind(null,{subjectId:h,subjectName:"container",action:M})});return}case A.openURI.trim().toLowerCase():{V(),e.add({...P,action:w.bind(null,{subjectId:h,subjectName:"container",action:M,payload:{URI:y.args.uri}})}),n==null||n();return}default:console.error("Unexpected container event"),i.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected container event"}));return}};function c({container:y,branches:h,isEOV:p=!1}){let C=ci(y.events);if(C){let u=ui(C.action,p);i.emit(m.interactives,{subjectId:y.id,subjectName:"container",type:S.actionChoice,actionType:u.type,payload:u.args}),e.add({timestamp:p?1/0:y.endTime,priority:"container",initiator:y.id,actionType:A.expect,action:b.bind(null,{subjectId:y.id,subjectName:"container"})}),s.isExpect=!0}else for(let u of y.events)o({action:u.action,container:y,branches:h,isEOV:p})}let d=({chapterId:y,action:h,branches:p=[]})=>{let C=i.emit.bind(i,m.interactives,{subjectId:y,subjectName:"chapter",type:S.actionChoice,actionType:h.type,payload:h.args});switch(h.type.trim().toLowerCase()){case A.setNextBranch.trim().toLowerCase():{let u=p.find(_=>_.id===h.args.branchId);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setWeightlessRandomBranch.trim().toLowerCase():{let u=un(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setRandomBranch.trim().toLowerCase():{let u=fn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setMaxWeightBranch.trim().toLowerCase():{let u=pn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.setMinWeightBranch.trim().toLowerCase():{let u=dn(p);return u!=null&&u.chapterId?(C(),x.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{chapterId:u.chapterId,autoSelect:!0}})):void 0}case A.continuePlayback.trim().toLowerCase():return C(),T.bind(null,{subjectId:y,subjectName:"chapter",action:h});case A.openURI.trim().toLowerCase():return C(),w.bind(null,{subjectId:y,subjectName:"chapter",action:h,payload:{URI:h.args.uri}});default:console.error("Unexpected chapter event"),i.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.INTERACTIVES,{message:"Unexpected chapter event"}));return}};function v(y){let h=ci(y.events);if(h){if(Y(y))return;i.emit(m.interactives,{subjectId:y.id,subjectName:"chapter",type:S.actionChoice,actionType:h.action.type,payload:h.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:A.expect,action:b.bind(null,{subjectId:y.id,subjectName:"chapter"})})}else y.events.forEach(p=>{let C=d({chapterId:y.id,action:p.action,branches:y.branches});C&&e.add({timestamp:1/0,priority:"chapter",initiator:y.id,actionType:p.action.type,action:C})})}let b=({subjectId:y,subjectName:h,action:p})=>{var C;t.pause(),i.emit(m.interactives,{subjectId:y,subjectName:h,type:S.actionExecution,actionType:(C=p==null?void 0:p.type)!=null?C:A.expect})},E=({subjectId:y,subjectName:h})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(m.interactives,{subjectId:y,subjectName:h,type:S.actionExecution,actionType:"after-expect"})},T=({subjectId:y,subjectName:h,subjectType:p,action:C})=>{i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:C.type})},x=({subjectId:y,subjectName:h,subjectType:p,action:C,payload:u})=>{u.behaviour="change-chapter",i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:C.type,payload:u})},B=({subjectId:y,subjectName:h,subjectType:p,action:C,payload:u})=>{u.behaviour="change-manifest",i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:C.type,payload:u})},w=({subjectId:y,subjectName:h,subjectType:p,action:C,payload:u})=>{if(!u.URI)return;let _=window.open(u.URI,"_blank","noopener,noreferrer");_&&(_.opener=null),i.emit(m.interactives,{subjectId:y,subjectName:h,subjectType:p,type:S.actionExecution,actionType:C.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:b,expectEventHandler:E,setManifestChapterEvents:v,setManifestContainerEvents:c,stopExpect:r,state:s}};var ht=require("@vkontakte/videoplayer-shared");var _e=(i,t)=>{let e={};return i.map(n=>{if(!e[n]){let s=t.chapters.find(l=>l.id===n);if(!s)return null;let r=t.media.videos.find(l=>s.videoId===l.id);if(!r)return null;e[n]=mi(r)}return e[n]}).filter(Boolean)},yn=i=>{for(let t of i.variants)if(gn(t)&&"payload"in t)return t.payload.id},gn=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",mi=i=>{let t=yn(i);if(!t)return null;let e=t.split("_").pop();return e?parseInt(e,10):null},vn=(i,t)=>{for(let e of i.media.videos)if(t===mi(e)){for(let n of i.chapters)if(n.videoId===e.id)return n.id;return}},yi=(i,t)=>i.reduce((e,n)=>{let s=vn(t,n);return s?[...e,s]:e},[]);var et,bt,Ct,q,Ae,it,nt,Z,Et,Lt,Nt,Xt=class{constructor({globalEventEmitter:t,videoId:e,interactiveController:n,historyApi:s,settings:r}){this.state={history$:new ht.ValueSubject([]),hasPrevChapter$:new ht.ValueSubject(!1),prevChapter$:new ht.ValueSubject(null),isInitialChapter$:new ht.ValueSubject(!1),isGoBackLimited$:new ht.ValueSubject(!1)};g(this,et,null);g(this,bt,void 0);g(this,Ct,!1);g(this,q,null);g(this,Ae,null);g(this,it,null);g(this,nt,null);g(this,Z,null);g(this,Et,new ht.Subscription);g(this,Lt,!1);g(this,Nt,0);var l,o,c;f(this,it,e),f(this,Z,t),f(this,nt,n),f(this,et,s),f(this,bt,r),(l=this.state)!=null&&l.history$&&a(this,Et)&&((c=a(this,Et))==null||c.add((o=this.state)==null?void 0:o.history$.subscribe(d=>{var v,b,E,T,x,B;(v=this.state)==null||v.prevChapter$.next(d.at(-2)||null),(b=this.state)==null||b.hasPrevChapter$.next(d.length>1),(x=this.state)==null||x.isInitialChapter$.next(this.getInitialChapterId()===((T=(E=a(this,q))==null?void 0:E.metadata)==null?void 0:T.initChapterId)),(B=this.state)==null||B.isGoBackLimited$.next(a(this,Nt)===a(this,bt).maxLength-1)})))}async setManifest(t){!a(this,nt)||!a(this,Z)||(f(this,q,t),await this.getProjectHistory(),await a(this,nt).setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,Ct)||(f(this,Ct,!0),a(this,Z).emit(m.historyInited,{initChapterId:this.getInitialChapterId()})))}get inited(){return a(this,Ct)}async updateHistory(t,e=!0){var o,c;if(!a(this,q))return;a(this,Lt)?(f(this,Lt,!1),Ri(this,Nt)._++):f(this,Nt,0);let n=a(this,q),s=t.length-a(this,bt).maxLength,r=s>0?t.slice(s):t,l=_e(r,n);if(f(this,Ae,l),(o=this==null?void 0:this.state)==null||o.history$.next(r),!(!e||!a(this,et)||!a(this,it)))try{await a(this,et).save(a(this,it),l)}catch(d){(c=a(this,Z))==null||c.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Unable to save interactive history"))}}async goBack(){var n;if(!this.state||!a(this,nt))return(n=a(this,Z))==null?void 0:n.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Cannot go back because HistoryController has not been initialized"));f(this,Lt,!0);let t=this.state.history$.getValue().slice(0,-1),e=t.pop();this.state.history$.next(t),await a(this,nt).setChapter({chapterId:e})}async getProjectHistory(){var s,r;if(!a(this,q)||!a(this,it))return;let t=a(this,q),e=[this.getInitialVideoId()];if(a(this,et))try{let l=await a(this,et).get(a(this,it));l.length&&(e=l)}catch(l){(s=a(this,Z))==null||s.emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.HISTORY,"Error while trying to fetch data"))}let n=yi(e,t);(r=this==null?void 0:this.state)==null||r.history$.next(n)}getInitialChapterId(){var e,n;let t=(e=this.state)==null?void 0:e.history$.getValue();return(t==null?void 0:t.at(-1))||a(this,bt).initChapterId||((n=a(this,q))==null?void 0:n.metadata.initChapterId)}getInitialVideoId(){if(a(this,q)){let t=this.getInitialChapterId();return _e([t],a(this,q)).pop()}return null}destroy(){var t,e;this.state=null,f(this,it,null),f(this,et,null),f(this,nt,null),(t=a(this,Et))==null||t.unsubscribe(),f(this,Et,null),f(this,Ct,!1),(e=a(this,Z))==null||e.emit(m.historyDestroyed),f(this,Z,null)}};et=new WeakMap,bt=new WeakMap,Ct=new WeakMap,q=new WeakMap,Ae=new WeakMap,it=new WeakMap,nt=new WeakMap,Z=new WeakMap,Et=new WeakMap,Lt=new WeakMap,Nt=new WeakMap;var Le,bn,qt,Ne,Cn,st=class st{constructor(t,e,n,s){var r;this.target=t,this.type=e,this.listener=n,this.options=L(r=st,Le,bn).call(r,t,s),this.target.addEventListener(e,n,this.options)}unlisten(){this.target.removeEventListener(this.type,this.listener,this.options),this.target=null,this.listener=null,this.options=!1}};Le=new WeakSet,bn=function(t,e){var n;if(e===void 0)return!1;if(typeof e=="boolean")return e;{let s=new Set(["passive","capture"]),r=Object.keys(e).filter(o=>!s.has(o));return r.length===0&&console.warn("Unsupported flag(s) to addEventListener: "+r.join(",")),L(n=st,Ne,Cn).call(n,t)?e:e.capture||!1}},qt=new WeakMap,Ne=new WeakSet,Cn=function(t){let e=a(st,qt);if(e===void 0){e=!1;try{let n={},s={get:()=>(e=!0,!1)};Object.defineProperty(n,"passive",s),Object.defineProperty(n,"capture",s);let r=()=>{};t.addEventListener("test",r,n),t.removeEventListener("test",r,n)}catch(n){e=!1}f(st,qt,e)}return e||!1},g(st,Le),g(st,Ne),g(st,qt,void 0);var Me=st;var ke=class{constructor(){this.bindingMap=new Kt}release(){this.removeAll(),this.bindingMap=null}listen(t,e,n,s){if(!this.bindingMap)return;let r=new Me(t,e,n,s);this.bindingMap.push(e,r)}listenOnce(t,e,n,s){let r=l=>{this.unlisten(t,e,r),n(l)};this.listen(t,e,r,s)}unlisten(t,e,n){if(!this.bindingMap)return;let s=this.bindingMap.get(e)||[];for(let r of s)r.target===t&&(n===r.listener||!n)&&(r.unlisten(),this.bindingMap.remove(e,r))}removeAll(){if(!this.bindingMap)return;let t=this.bindingMap.getAll();for(let e of t)e.unlisten();this.bindingMap.clear()}};var je=class{constructor(){this._prevSizeId=0;this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))==null||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var s;let t=(s=this.rootElement.getContext("2d"))==null?void 0:s.getImageData(0,0,this.rootElement.width,this.rootElement.height);if(!t)return!1;let e=t.data,n=e.length;for(let r=3;r<n;r+=40)if(e[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.drawImage(this.canvasImgSrc,0,0,this.rootElement.width,this.rootElement.height))}async updateCanvasDimensions(t,e=!1){let n=t.width+t.height;if(this._prevSizeId===n)return;let s;e&&(s=await this.save()),this.rootElement.width=t.width,this.rootElement.height=t.height,e&&s&&this.restore(s),this._prevSizeId=n}async save(){let t=this.rootElement.toDataURL("image/jpeg",1),e=new Image;return e.crossOrigin="anonymous",e.src=t,await e.decode(),e}restore(t){var e;this.rootElement&&((e=this.rootElement.getContext("2d"))==null||e.drawImage(t,0,0,this.rootElement.width,this.rootElement.height))}};var Pe=class{constructor({parentElement:t,endOffsetMs:e=250,onError:n}){this.currentVideoDurationMs=1/0;this._containerTimeFrameShouldReceived=!1;this._endTimeFrameReceived=!1;this._shouldCallSkip=!1;this.onEachTick=t=>{let e=t!=null?t:this.lastFrameCanvas.canvasImgSrc.currentTime*1e3,n=this.isChapterEndTime(e);if(this.isContainerTime(e))this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!0,this._shouldCallSkip=!0;else if(n)this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1,this._endTimeFrameReceived||(this.draw(),this._endTimeFrameReceived=!0,this.show());else{if(this._shouldCallSkip){this._shouldCallSkip=!1;return}this.reset()}};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 @@
|
|
|
11
11
|
height: var(--interactive-height);
|
|
12
12
|
background-color: var(--black);
|
|
13
13
|
visibility: hidden;
|
|
14
|
-
`,this.lastFrameCanvas=new
|
|
14
|
+
`,this.lastFrameCanvas=new je,this.endOffsetMs=e,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);let e=getComputedStyle(this.rootElement),n={width:parseInt(e.getPropertyValue("--interactive-content-width"),10),height:parseInt(e.getPropertyValue("--interactive-content-height"),10)};try{this.lastFrameCanvas.updateCanvasDimensions(n,t)}catch(
|
|
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);let e=getComputedStyle(this.rootElement),n={width:parseInt(e.getPropertyValue("--interactive-content-width"),10),height:parseInt(e.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(e=>{var n,s,r;return((n=e.controls)==null?void 0:n.length)&&t>=((s=e.startTime)!=null?s:0)&&t<=Math.min((r=e.endTime)!=null?r:1/0,this.currentVideoDurationMs-this.endOffsetMs)})}reset(){this._endTimeFrameReceived=!1,this._containerTimeFrameShouldReceived=!1,this._shouldCallSkip=!1}_onError(t){var e,n;(n=(e=this._callbacks)==null?void 0:e.onError)==null||n.call(e,t)}};function En(i=0){return new Promise(t=>{setTimeout(()=>{t(0)},i)})}var In=Object.freeze({parentElement:null,fullscreenTargetElement:null,lang:"ru",loaders:{},graph:!1,historyApi:null,historyParams:null,projectInfo:{},initSeamless:!1,lastFrame:!1,permanentTextControls:!0,config:{historyMaxLength:100,noInteractionEventTimeout:3e4}}),rt=Object.freeze({created:0,initiated:1,ready:2,destroyed:3});function ds(){let i=document.createElement("div");return i.style.cssText=`
|
|
20
20
|
position: absolute;
|
|
21
21
|
top: 0;
|
|
22
22
|
left: 0;
|
|
23
|
-
`,i}var ut,X,ft,W,at,G,q,ot,j,ct,jt,U,Pt,B,_,mt,Tt,w,dn,pn,Le,oi,Ne,un,ri,St,Zt,fn,ai,mn,yn,ke,Jt,Yt=class{constructor(t){C(this,w);C(this,ut,null);C(this,X,null);C(this,ft,null);C(this,W,null);C(this,at,null);C(this,G,null);C(this,q,null);C(this,ot,null);C(this,j,null);C(this,ct,new P.ValueSubject(!1));C(this,jt,new Set);C(this,U,null);C(this,Pt,null);C(this,B,null);C(this,_,null);C(this,mt,ze());C(this,Tt,null);k(this,"state",{prevChapter$:new P.ValueSubject(null),isInitialChapter$:new P.ValueSubject(!1),isEndChapter$:new P.ValueSubject(!1),isInteractiveExpectation$:new P.ValueSubject(!1),calledByInteractive$:new P.ValueSubject(!1),lastChapterChangeWasInitiatedByInteractive$:new P.ValueSubject(!1),disabledControls$:new P.ValueSubject(!1),interactiveRanges$:new P.ValueSubject([]),isInteractiveTime$:new P.ValueSubject(!1)});k(this,"events",{noInteraction$:new P.Subject});k(this,"emitPlayerChanged",t=>{a(this,_).emit(m.playerChanged,t)});C(this,oi,()=>{a(this,q).fns.forEach(n=>n());let t=this.options.player.info.position$.getValue()*1e3,e=(a(this,j).chapter.containers||[]).filter(n=>n.startTime>=Math.floor(t));for(let n of e){a(this,G).remove({timestamp:1/0,priority:"container",initiator:n.id});for(let r of n.controls)a(this,G).remove({timestamp:1/0,priority:"control",initiator:r.id});a(this,X).find(r=>r.container.container.id===n.id).reset()}});C(this,Ne,()=>{a(this,ut).calc(),a(this,q).requestAnimation()});C(this,St,(t=!0)=>{a(this,X).forEach(e=>{!t&&e.isPermanentText||(a(this,q).removeFn(e.whilePlaying),e.destroy())})});C(this,ke,t=>{let{interactiveRanges$:e}=this.state,r=e.getValue().map(s=>({...s,subjects:s.subjects.filter(l=>l!==t)}));e.next(r)});C(this,Jt,()=>{a(this,Tt)&&(clearTimeout(a(this,Tt)),f(this,Tt,null))});var e;this.options={...hn,...t,config:{...hn.config,...t.config}},f(this,X,[]),this.factories=new Map([["choice",de]]),this.rootElement=Yn(),this.options.parentElement.append(this.rootElement),f(this,_,new At),f(this,at,new P.Subscription),f(this,ft,new _e),f(this,W,new Xt({interactiveController:this,globalEventEmitter:a(this,_),videoId:(e=this.options.projectInfo)==null?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&f(this,B,new Me({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,_).emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.SEAMLESS,n))})),a(this,ft).listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,ft).listen(this.rootElement,"mouseup",n=>n.stopPropagation()),f(this,j,new Ct(this.options.loaders,n=>a(this,_).emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.MANIFEST,n)))),f(this,G,ti(this.options.player)),f(this,q,new ve),f(this,ot,ii({player:this.options.player,interactiveEvents:a(this,G),globalEventEmitter:a(this,_),removeControllers:a(this,St)})),f(this,ut,Zi(()=>{var n,r,s;return{player:(n=this.options)==null?void 0:n.player,parentElement:(r=this.options)==null?void 0:r.parentElement,fns:(s=this.options)!=null&&s.lastFrame?[()=>{a(this,B).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&f(this,U,new Ht({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,_).emit(m.graph,{type:Mt.watchAgainClicked,chapterId:n})},onError:n=>a(this,_).emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.LOADERS,{message:n}))})),N(this,w,dn).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=rt.created}getStatEvents(){return{click$:new P.Observable(t=>{a(this,_).on(m.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?"OPEN_GRAPH":"CLOSE_GRAPH"),e==="watchAgainClicked"&&t.next("WATCH_AGAIN")}),a(this,_).on(m.interactives,({type:e,subjectName:n,subjectType:r})=>{e!=="action-choice"||n!=="control"||(r==="Button"&&t.next("GO_NEXT_BUTTON"),r==="Area"&&t.next("GO_NEXT_AREA"))})}),nextMovie$:new P.Observable(t=>{a(this,_).on(m.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){N(this,w,Le).call(this),this.options.player=t,a(this,mt).setPlayer(this.options.player),a(this,G)?a(this,G).setPlayer(this.options.player):f(this,G,ti(this.options.player)),f(this,ot,ii({player:this.options.player,interactiveEvents:a(this,G),globalEventEmitter:a(this,_),removeControllers:()=>a(this,St).call(this,!1)})),this.appState===rt.initiated&&(N(this,w,ri).call(this),N(this,w,Zt).call(this,a(this,j).chapter))}async setManifest(t){N(this,w,Le).call(this),this.isFirstChapterFetched=!1;let e=await a(this,j).setManifest(t);return a(this,U)&&await a(this,U).handleManifestChange(e.manifest),await a(this,W).setManifest(e.manifest),a(this,_).emit(m.manifestChanged,{manifest:e.manifest}),N(this,w,Zt).call(this,a(this,j).chapter),e.manifest}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,U))==null||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,U))==null||e.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:e=!0}={}){var l;N(this,w,Le).call(this),a(this,B)&&this.isFirstChapterFetched&&(a(this,B).draw(),a(this,B).show()),P.CC.isSafari&&await ln(35);let{chapter:n,media:r,graph:s}=await(t?a(this,j).setNext(t):a(this,j).setInitial());return e&&N(this,w,yn).call(this,n.id),this.state.isInitialChapter$.next(a(this,j).isInitialChapter()),this.state.isEndChapter$.next(a(this,j).isEndChapter()),a(this,U)&&a(this,U).handleChapterChange(s),(l=a(this,B))==null||l.setCurrentChapter(this.getCurrentChapter().chapter),a(this,_).emit(m.chapterChanged,{chapter:n,media:r,graph:s}),N(this,w,Zt).call(this,a(this,j).chapter),f(this,jt,new Set),this.isFirstChapterFetched=!0,{chapter:n,media:r,graph:s}}toggleGraphView(t=!0){a(this,U)&&(t?(a(this,U).show(),a(this,ct).next(!1)):(a(this,U).hide(),N(this,w,ai).call(this)),a(this,_).emit(m.graph,{type:Mt.visibility,visibility:t}))}init(){a(this,j).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===rt.created&&(a(this,ut).resizeObserver.observe(this.options.fullscreenTargetElement),N(this,w,ri).call(this),this.appState=rt.initiated,N(this,w,Zt).call(this,a(this,j).chapter))}deadEndCheck(){var n,r;return!((r=(n=a(this,G))==null?void 0:n.getPreparedToExecActions())!=null?r:[]).some(s=>s.actionType===M.setNextBranch)}allControlsAreRemoved(){return!a(this,X).some(e=>!e.container.isRemoved)}isEndedExpectation(){var n;if(!((n=this.options)!=null&&n.player)||!a(this,X))return!1;let t=this.options.player.info.position$.getValue(),e=this.options.player.info.duration$.getValue();return t===e&&a(this,X).some(r=>{let s=r.container.container;return!s.isRemoved&&s.endTime===null&&bt(s.events)})}playPrevChapter(){var t;(t=a(this,W))==null||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,j).manifest){return Gt(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,W).getInitialVideoId(),chapterId:a(this,W).getInitialChapterId()}}getHistoryState(){return a(this,W).state}getIsSeekable(){return a(this,ct)}getInteractiveRanges(){var t;return Ki((t=a(this,j).chapter)==null?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,mt).getNextInteractiveTime(t)}getChapterBranches(t){return a(this,j).getBranches(t)}getCurrentChapter(){return a(this,j).getCurrent()}getCurrentManifest(){return a(this,j).manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,_).on(...t),this}off(...t){return a(this,_).off(...t),this}once(...t){return a(this,_).once(...t),this}destroy(){var t,e;a(this,St).call(this),f(this,X,void 0),this.state=void 0,(t=a(this,U))==null||t.destroy(),f(this,U,void 0),a(this,ut).release(),f(this,ut,void 0),f(this,ot,void 0),a(this,q).release(),f(this,q,void 0),a(this,G).release(),f(this,G,void 0),a(this,j).release(),f(this,ot,void 0),a(this,ft).release(),f(this,ft,void 0),a(this,at).unsubscribe(),f(this,at,void 0),a(this,_).reset(),f(this,_,void 0),(e=a(this,B))==null||e.destroy(),f(this,B,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,W).destroy(),f(this,W,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=rt.destroyed}};ut=new WeakMap,X=new WeakMap,ft=new WeakMap,W=new WeakMap,at=new WeakMap,G=new WeakMap,q=new WeakMap,ot=new WeakMap,j=new WeakMap,ct=new WeakMap,jt=new WeakMap,U=new WeakMap,Pt=new WeakMap,B=new WeakMap,_=new WeakMap,mt=new WeakMap,Tt=new WeakMap,w=new WeakSet,dn=function(t=!1){a(this,_).on(m.historyInited,async({initChapterId:e,videosInfo:n=[]})=>{t&&await N(this,w,pn).call(this,{initialChapter:e,videosInfo:n})}),a(this,_).on(m.interactives,async e=>{var n,r;if(e.type===S.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)==null?void 0:n.behaviour)==="change-chapter"){let{chapterId:l}=e.payload;this.setChapter({chapterId:l})}if(((r=e.payload)==null?void 0:r.behaviour)==="change-manifest"){let{manifestURL:l}=e.payload;this.setManifest(l)}let s=e.type==="action-execution";s&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):s&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===S.containerRemoved&&a(this,ke).call(this,e.subjectId)}),a(this,_).on(m.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},pn=async function({source:t,videosInfo:e=[]}){f(this,Pt,Je(this));let n=document.createElement("div");a(this,Pt).on(Qt.activePlayerChanged,this.emitPlayerChanged);let{player:r,config:s}=await a(this,Pt).init({source:t,initialChapter:a(this,W).getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:r,config:s}},Le=function(){var t;this.appState===rt.ready&&(a(this,St).call(this),f(this,X,[]),a(this,q).release(),(t=a(this,G))==null||t.release(),this.appState=rt.initiated,a(this,ct).next(!1),a(this,Jt).call(this))},oi=new WeakMap,Ne=new WeakMap,un=function(t){(!a(this,U)||a(this,U).isHidden)&&N(this,w,ai).call(this);let e=t*1e3,r=this.getInteractiveRanges().findLast(({range:s})=>e>=s[1]);if(r){let s=r.range.join("-");a(this,jt).has(s)||(a(this,jt).add(s),a(this,_).emit(m.interactives,{type:S.rangeEnded,payload:r,visibility:!0}))}},ri=function(){a(this,at).unsubscribe(),a(this,at).add(this.options.player.events.started$.pipe((0,P.once)()).subscribe(a(this,Ne))).add(this.options.player.events.playing$.subscribe(a(this,q).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,q).cancelAnimation)).add(this.options.player.info.position$.subscribe(N(this,w,un).bind(this))).add(a(this,j).prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add((0,P.combine)({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let r;if(n)r=!0;else{let s=t*1e3;r=!!(e==null?void 0:e.find(({range:[o,c],subjects:d})=>o<s&&s<c&&d.length))}r!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(r),r?f(this,Tt,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):a(this,Jt).call(this))})),this.options.lastFrame&&a(this,at).add(this.options.player.info.duration$.subscribe(t=>{a(this,B).setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,B).setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,B).reset(),setTimeout(()=>{a(this,B).hide(),a(this,B).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,B).onSeek))},St=new WeakMap,Zt=function(t){a(this,j).chapter&&this.appState===rt.initiated&&(a(this,ot).setManifestChapterEvents(t),f(this,X,N(this,w,fn).call(this,t)),a(this,G).containersEventsCallState.setData(t.containers),a(this,mt).setContainers(a(this,X).map(e=>e.container.container).filter(e=>!xe(e.controls))),this.options.lastFrame&&a(this,q).addFn(()=>{a(this,B).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=rt.ready)},fn=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)==null?void 0:e.reduce((r,s)=>{let l=s.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Te({player:this.options.player,container:o(s,this.rootElement),branches:a(this,j).chapter.branches,selectBranches:a(this,ot),interactiveEvents:a(this,G),globalEventEmitter:a(this,_),ignoreContainerEvent:()=>Hi(s,a(this,X)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,mt).deleteContainer(s.id)}});return a(this,q).addFn(c.whilePlaying,!0),[...r,c]}return[...r]},[]))!=null?n:[]},ai=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,ct).next(!1);return}let e=a(this,ct).getValue(),n=!!a(this,mt).getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,ct).next(!e)},mn=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},yn=function(t){var o;if(N(this,w,mn).call(this),!a(this,W).inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),r=(o=n&&J(n)&&zt(n))!=null?o:!1,s=a(this,j).manifest.metadata.initChapterId===t,l=a(this,W).state.history$.getValue();if(s||r&&e){a(this,W).updateHistory([t]);return}l.at(-1)!==t&&a(this,W).updateHistory([...l,t])},ke=new WeakMap,Jt=new WeakMap;var gn={Container:_t,createChoiceContainer:de,createAreaControl:oe,createButtonControl:le,createRelativeLayout:Ti,getRootEl:ie,classnamesPrefix:H};var Jn={version:vi};
|
|
23
|
+
`,i}var dt,K,pt,z,at,H,X,ot,j,ct,kt,G,jt,$,R,ut,It,$e,xn,Be,Tn,Pt,Oe,bi,Fe,De,Sn,Jt,gi,xt,Tt,Zt,He,wn,te,vi,Ge,Vn,Ue,Rn,ze,ee,Yt=class{constructor(t){g(this,$e);g(this,Be);g(this,Pt);g(this,De);g(this,Jt);g(this,Tt);g(this,He);g(this,te);g(this,Ge);g(this,Ue);g(this,dt,null);g(this,K,null);g(this,pt,null);g(this,z,null);g(this,at,null);g(this,H,null);g(this,X,null);g(this,ot,null);g(this,j,null);g(this,ct,new N.ValueSubject(!1));g(this,kt,new Set);g(this,G,null);g(this,jt,null);g(this,$,null);g(this,R,null);g(this,ut,ni());g(this,It,null);k(this,"state",{prevChapter$:new N.ValueSubject(null),isInitialChapter$:new N.ValueSubject(!1),isEndChapter$:new N.ValueSubject(!1),isInteractiveExpectation$:new N.ValueSubject(!1),calledByInteractive$:new N.ValueSubject(!1),lastChapterChangeWasInitiatedByInteractive$:new N.ValueSubject(!1),disabledControls$:new N.ValueSubject(!1),interactiveRanges$:new N.ValueSubject([]),isInteractiveTime$:new N.ValueSubject(!1)});k(this,"events",{noInteraction$:new N.Subject});k(this,"emitPlayerChanged",t=>{a(this,R).emit(m.playerChanged,t)});g(this,bi,()=>{a(this,X).fns.forEach(n=>n());let t=this.options.player.info.position$.getValue()*1e3,e=(a(this,j).chapter.containers||[]).filter(n=>n.startTime>=Math.floor(t));for(let n of e){a(this,H).remove({timestamp:1/0,priority:"container",initiator:n.id});for(let s of n.controls)a(this,H).remove({timestamp:1/0,priority:"control",initiator:s.id});a(this,K).find(s=>s.container.container.id===n.id).reset()}});g(this,Fe,()=>{a(this,dt).calc(),a(this,X).requestAnimation()});g(this,xt,(t=!0)=>{a(this,K).forEach(e=>{!t&&e.isPermanentText||(a(this,X).removeFn(e.whilePlaying),e.destroy())})});g(this,ze,t=>{let{interactiveRanges$:e}=this.state,s=e.getValue().map(r=>({...r,subjects:r.subjects.filter(l=>l!==t)}));e.next(s)});g(this,ee,()=>{a(this,It)&&(clearTimeout(a(this,It)),f(this,It,null))});var e;this.options={...In,...t,config:{...In.config,...t.config}},f(this,K,[]),this.factories=new Map([["choice",fe]]),this.rootElement=ds(),this.options.parentElement.append(this.rootElement),f(this,R,new At),f(this,at,new N.Subscription),f(this,pt,new ke),f(this,z,new Xt({interactiveController:this,globalEventEmitter:a(this,R),videoId:(e=this.options.projectInfo)==null?void 0:e.videoId,historyApi:this.options.historyApi,settings:{maxLength:this.options.config.historyMaxLength,initChapterId:this.options.initChapterId}})),this.options.lastFrame&&f(this,$,new Pe({parentElement:this.options.parentElement,interactivesRootElement:this.rootElement,onError:n=>a(this,R).emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.SEAMLESS,n))})),a(this,pt).listen(this.rootElement,"mousedown",n=>n.stopPropagation()),a(this,pt).listen(this.rootElement,"mouseup",n=>n.stopPropagation()),f(this,j,new vt(this.options.loaders,n=>a(this,R).emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.MANIFEST,n)))),f(this,H,pi(this.options.player)),f(this,X,new Ee),f(this,ot,fi({player:this.options.player,interactiveEvents:a(this,H),globalEventEmitter:a(this,R),removeControllers:a(this,xt)})),f(this,dt,hn(()=>{var n,s,r;return{player:(n=this.options)==null?void 0:n.player,parentElement:(s=this.options)==null?void 0:s.parentElement,fns:(r=this.options)!=null&&r.lastFrame?[()=>{a(this,$).updateCanvasDimensions(!0)}]:[]}})),this.options.graph&&f(this,G,new Ht({root:this.options.parentElement,lang:this.options.lang,onOpenPreviewClick:n=>{this.setChapter({chapterId:n}),a(this,R).emit(m.graph,{type:Mt.watchAgainClicked,chapterId:n})},onError:n=>a(this,R).emit(m.errors,new I(I.Severity.RECOVERABLE,I.Category.LOADERS,{message:n}))})),L(this,$e,xn).call(this,this.options.initSeamless),this.isFirstChapterFetched=!1,this.appState=rt.created}getStatEvents(){return{click$:new N.Observable(t=>{a(this,R).on(m.graph,({type:e,visibility:n})=>{e==="visibility"&&t.next(n?"OPEN_GRAPH":"CLOSE_GRAPH"),e==="watchAgainClicked"&&t.next("WATCH_AGAIN")}),a(this,R).on(m.interactives,({type:e,subjectName:n,subjectType:s})=>{e!=="action-choice"||n!=="control"||(s==="Button"&&t.next("GO_NEXT_BUTTON"),s==="Area"&&t.next("GO_NEXT_AREA"))})}),nextMovie$:new N.Observable(t=>{a(this,R).on(m.playerChanged,({config:e})=>{e!=null&&e.unitedVideoId&&t.next(e.unitedVideoId)})})}}setPlayer(t){L(this,Pt,Oe).call(this),this.options.player=t,a(this,ut).setPlayer(this.options.player),a(this,H)?a(this,H).setPlayer(this.options.player):f(this,H,pi(this.options.player)),f(this,ot,fi({player:this.options.player,interactiveEvents:a(this,H),globalEventEmitter:a(this,R),removeControllers:()=>a(this,xt).call(this,!1)})),this.appState===rt.initiated&&(L(this,Jt,gi).call(this),L(this,Tt,Zt).call(this,a(this,j).chapter))}async setManifest(t){L(this,Pt,Oe).call(this),this.isFirstChapterFetched=!1;let e=await a(this,j).setManifest(t);return a(this,G)&&await a(this,G).handleManifestChange(e.manifest),await a(this,z).setManifest(e.manifest),a(this,R).emit(m.manifestChanged,{manifest:e.manifest}),L(this,Tt,Zt).call(this,a(this,j).chapter),e.manifest}setVisitedChapters(t){var e;Array.isArray(t)&&((e=a(this,G))==null||e.setVisitedChapters(t))}updateGraphVideosInfo(t){var e;Array.isArray(t)&&((e=a(this,G))==null||e.updateVideosInfo(t))}async setChapter({chapterId:t,pushToHistory:e=!0}={}){var o;L(this,Pt,Oe).call(this),a(this,$)&&this.isFirstChapterFetched&&(a(this,$).draw(),a(this,$).show()),(0,N.getCurrentBrowser)().browser===N.CurrentClientBrowser.Safari&&await En(35);let{chapter:s,media:r,graph:l}=await(t?a(this,j).setNext(t):a(this,j).setInitial());return e&&L(this,Ue,Rn).call(this,s.id),this.state.isInitialChapter$.next(a(this,j).isInitialChapter()),this.state.isEndChapter$.next(a(this,j).isEndChapter()),a(this,G)&&a(this,G).handleChapterChange(l),(o=a(this,$))==null||o.setCurrentChapter(this.getCurrentChapter().chapter),a(this,R).emit(m.chapterChanged,{chapter:s,media:r,graph:l}),L(this,Tt,Zt).call(this,a(this,j).chapter),f(this,kt,new Set),this.isFirstChapterFetched=!0,{chapter:s,media:r,graph:l}}toggleGraphView(t=!0){a(this,G)&&(t?(a(this,G).show(),a(this,ct).next(!1)):(a(this,G).hide(),L(this,te,vi).call(this)),a(this,R).emit(m.graph,{type:Mt.visibility,visibility:t}))}init(){a(this,j).chapter&&this.options.parentElement&&this.options.player&&this.options.fullscreenTargetElement&&this.appState===rt.created&&(a(this,dt).resizeObserver.observe(this.options.fullscreenTargetElement),L(this,Jt,gi).call(this),this.appState=rt.initiated,L(this,Tt,Zt).call(this,a(this,j).chapter))}deadEndCheck(){var n,s;return!((s=(n=a(this,H))==null?void 0:n.getPreparedToExecActions())!=null?s:[]).some(r=>r.actionType===A.setNextBranch)}allControlsAreRemoved(){return!a(this,K).some(e=>!e.container.isRemoved)}isEndedExpectation(){var n;if(!((n=this.options)!=null&&n.player)||!a(this,K))return!1;let t=this.options.player.info.position$.getValue(),e=this.options.player.info.duration$.getValue();return t===e&&a(this,K).some(s=>{let r=s.container.container;return!r.isRemoved&&r.endTime===null&>(r.events)})}playPrevChapter(){var t;(t=a(this,z))==null||t.goBack()}setDisabledControls(t){this.state.disabledControls$.next(t)}isSupport(t=a(this,j).manifest){return Gt(t.metadata.version)}getInitialVideoInfo(){return{videoId:a(this,z).getInitialVideoId(),chapterId:a(this,z).getInitialChapterId()}}getHistoryState(){return a(this,z).state}getIsSeekable(){return a(this,ct)}getInteractiveRanges(){var t;return on((t=a(this,j).chapter)==null?void 0:t.containers)}getNextInteractiveStartTime(t){return a(this,ut).getNextInteractiveTime(t)}getChapterBranches(t){return a(this,j).getBranches(t)}getCurrentChapter(){return a(this,j).getCurrent()}getCurrentManifest(){return a(this,j).manifest}addFactory(t,e){this.factories.set(t.trim().toLowerCase(),e)}removeFactory(t){this.factories.delete(t.trim().toLowerCase())}on(...t){return a(this,R).on(...t),this}off(...t){return a(this,R).off(...t),this}once(...t){return a(this,R).once(...t),this}destroy(){var t,e;a(this,xt).call(this),f(this,K,void 0),this.state=void 0,(t=a(this,G))==null||t.destroy(),f(this,G,void 0),a(this,dt).release(),f(this,dt,void 0),f(this,ot,void 0),a(this,X).release(),f(this,X,void 0),a(this,H).release(),f(this,H,void 0),a(this,j).release(),f(this,ot,void 0),a(this,pt).release(),f(this,pt,void 0),a(this,at).unsubscribe(),f(this,at,void 0),a(this,R).reset(),f(this,R,void 0),(e=a(this,$))==null||e.destroy(),f(this,$,void 0),this.rootElement.remove(),this.rootElement=void 0,a(this,z).destroy(),f(this,z,void 0),this.factories=void 0,this.options=void 0,this.isFirstChapterFetched=!1,this.appState=rt.destroyed}};dt=new WeakMap,K=new WeakMap,pt=new WeakMap,z=new WeakMap,at=new WeakMap,H=new WeakMap,X=new WeakMap,ot=new WeakMap,j=new WeakMap,ct=new WeakMap,kt=new WeakMap,G=new WeakMap,jt=new WeakMap,$=new WeakMap,R=new WeakMap,ut=new WeakMap,It=new WeakMap,$e=new WeakSet,xn=function(t=!1){a(this,R).on(m.historyInited,async({initChapterId:e,videosInfo:n=[]})=>{t&&await L(this,Be,Tn).call(this,{initialChapter:e,videosInfo:n})}),a(this,R).on(m.interactives,async e=>{var n,s;if(e.type===S.actionExecution){if(this.state.calledByInteractive$.next(!0),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!0),((n=e.payload)==null?void 0:n.behaviour)==="change-chapter"){let{chapterId:l}=e.payload;this.setChapter({chapterId:l})}if(((s=e.payload)==null?void 0:s.behaviour)==="change-manifest"){let{manifestURL:l}=e.payload;this.setManifest(l)}let r=e.type==="action-execution";r&&e.actionType==="expect"?this.state.isInteractiveExpectation$.next(!0):r&&e.actionType==="after-expect"&&this.state.isInteractiveExpectation$.next(!1)}e.type===S.containerRemoved&&a(this,ze).call(this,e.subjectId)}),a(this,R).on(m.manifestChanged,()=>{this.state.calledByInteractive$.next(!1),this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)})},Be=new WeakSet,Tn=async function({source:t,videosInfo:e=[]}){f(this,jt,di(this));let n=document.createElement("div");a(this,jt).on(Qt.activePlayerChanged,this.emitPlayerChanged);let{player:s,config:r}=await a(this,jt).init({source:t,initialChapter:a(this,z).getInitialChapterId(),container:n});return this.updateGraphVideosInfo(e),{player:s,config:r}},Pt=new WeakSet,Oe=function(){var t;this.appState===rt.ready&&(a(this,xt).call(this),f(this,K,[]),a(this,X).release(),(t=a(this,H))==null||t.release(),this.appState=rt.initiated,a(this,ct).next(!1),a(this,ee).call(this))},bi=new WeakMap,Fe=new WeakMap,De=new WeakSet,Sn=function(t){(!a(this,G)||a(this,G).isHidden)&&L(this,te,vi).call(this);let e=t*1e3,s=this.getInteractiveRanges().findLast(({range:r})=>e>=r[1]);if(s){let r=s.range.join("-");a(this,kt).has(r)||(a(this,kt).add(r),a(this,R).emit(m.interactives,{type:S.rangeEnded,payload:s,visibility:!0}))}},Jt=new WeakSet,gi=function(){a(this,at).unsubscribe(),a(this,at).add(this.options.player.events.started$.pipe((0,N.once)()).subscribe(a(this,Fe))).add(this.options.player.events.playing$.subscribe(a(this,X).requestAnimation)).add(this.options.player.events.willPause$.subscribe(a(this,X).cancelAnimation)).add(this.options.player.info.position$.subscribe(L(this,De,Sn).bind(this))).add(a(this,j).prevChapter$.subscribe(t=>this.state.prevChapter$.next(t))).add((0,N.combine)({position:this.options.player.info.position$,interactiveRanges:this.state.interactiveRanges$,isInteractiveExpectation:this.state.isInteractiveExpectation$}).subscribe(({position:t,interactiveRanges:e,isInteractiveExpectation:n})=>{let s;if(n)s=!0;else{let r=t*1e3;s=!!(e==null?void 0:e.find(({range:[o,c],subjects:d})=>o<r&&r<c&&d.length))}s!==this.state.isInteractiveTime$.getValue()&&(this.state.isInteractiveTime$.next(s),s?f(this,It,setTimeout(()=>{this.events.noInteraction$.next()},this.options.config.noInteractionEventTimeout)):a(this,ee).call(this))})),this.options.lastFrame&&a(this,at).add(this.options.player.info.duration$.subscribe(t=>{a(this,$).setVideoDuration(t*1e3)})).add(this.options.player.experimental.element$.subscribe(t=>{t&&a(this,$).setVideoElement(t)})).add(this.options.player.events.firstFrame$.subscribe(()=>{a(this,$).reset(),setTimeout(()=>{a(this,$).hide(),a(this,$).lastFrameCanvas.clear()},50)})).add(this.options.player.events.seeked$.subscribe(a(this,$).onSeek))},xt=new WeakMap,Tt=new WeakSet,Zt=function(t){a(this,j).chapter&&this.appState===rt.initiated&&(a(this,ot).setManifestChapterEvents(t),f(this,K,L(this,He,wn).call(this,t)),a(this,H).containersEventsCallState.setData(t.containers),a(this,ut).setContainers(a(this,K).map(e=>e.container.container).filter(e=>!we(e.controls))),this.options.lastFrame&&a(this,X).addFn(()=>{a(this,$).onEachTick(this.options.player.info.position$.getValue()*1e3)},!0),this.state.interactiveRanges$.next(this.getInteractiveRanges()),this.appState=rt.ready)},He=new WeakSet,wn=function(t){var e,n;return(n=(e=t==null?void 0:t.containers)==null?void 0:e.reduce((s,r)=>{let l=r.type.trim().toLowerCase(),o=this.factories.get(l);if(o){let c=new Ve({player:this.options.player,container:o(r,this.rootElement),branches:a(this,j).chapter.branches,selectBranches:a(this,ot),interactiveEvents:a(this,H),globalEventEmitter:a(this,R),ignoreContainerEvent:()=>tn(r,a(this,K)),permanentTextControls:this.options.permanentTextControls,disabledControls$:this.state.disabledControls$,onRemove:()=>{a(this,ut).deleteContainer(r.id)}});return a(this,X).addFn(c.whilePlaying,!0),[...s,c]}return[...s]},[]))!=null?n:[]},te=new WeakSet,vi=function(){if(this.state.isInteractiveExpectation$.getValue()){a(this,ct).next(!1);return}let e=a(this,ct).getValue(),n=!!a(this,ut).getNextInteractiveTime();(n&&!e||!n&&e)&&a(this,ct).next(!e)},Ge=new WeakSet,Vn=function(){this.state.calledByInteractive$.getValue()?this.state.calledByInteractive$.next(!1):this.state.lastChapterChangeWasInitiatedByInteractive$.next(!1)},Ue=new WeakSet,Rn=function(t){var o;if(L(this,Ge,Vn).call(this),!a(this,z).inited)return;let e=this.state.lastChapterChangeWasInitiatedByInteractive$.getValue(),n=this.state.prevChapter$.getValue(),s=(o=n&&Y(n)&&zt(n))!=null?o:!1,r=a(this,j).manifest.metadata.initChapterId===t,l=a(this,z).state.history$.getValue();if(r||s&&e){a(this,z).updateHistory([t]);return}l.at(-1)!==t&&a(this,z).updateHistory([...l,t])},ze=new WeakMap,ee=new WeakMap;var _n={Container:_t,createChoiceContainer:fe,createAreaControl:le,createButtonControl:de,createRelativeLayout:ji,getRootEl:se,classnamesPrefix:D};var ps={version:_i};
|