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