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