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