@vkontakte/videoplayer-interactive 1.0.9-beta.0 → 1.0.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es2015.cjs.js +3 -3
- package/es2015.esm.js +3 -3
- package/es2018.cjs.js +3 -3
- package/es2018.esm.js +3 -3
- package/esnext.cjs.js +3 -3
- package/esnext.esm.js +3 -3
- package/evergreen.esm.js +3 -3
- package/package.json +3 -3
package/es2015.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-interactive v1.0.9-beta.
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-interactive v1.0.9-beta.1
|
|
3
|
+
* Wed, 24 Apr 2024 12:17:30 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-9/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{loadVKLangPack as Vn,ValueSubject as H,Subscription as Zt,Observable as Fe,getCurrentBrowser as Fn,CurrentClientBrowser as Bn,once as Dn}from"@vkontakte/videoplayer-shared/es2015.esm.js";import{v4 as Wn}from"uuid";import{Player as Hn}from"@vkontakte/videoplayer-core/es2015.esm.js";const Un="1.0.9-beta.0";function Pi(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",Gn="SDK_NAME-controls-container",Li=()=>document.querySelector(`.${Gn}`),zn=.4,X={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Be={top:"flex-start",bottom:"flex-end",center:"center"},De={start:"flex-start",end:"flex-end",center:"center"},We={start:"left",end:"right",center:"center"},Mi=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=Be[(e=t==null?void 0:t.text)===null||e===void 0?void 0:e.gravityVertical])!==null&&n!==void 0?n:Be.center,i.style.justifyContent=(s=De[(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.gravityHorizontal])!==null&&s!==void 0?s:De.center,i.style.textAlign=(o=We[(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.alignment])!==null&&o!==void 0?o:We.start},Ni=({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},ki=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Pi((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)},Vi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d,h,u,v,m,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 ${Pi((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,(v=(u=(h=t==null?void 0:t.shape)===null||h===void 0?void 0:h.border)===null||u===void 0?void 0:u.alpha)!==null&&v!==void 0?v:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(b=(m=t==null?void 0:t.shape)===null||m===void 0?void 0:m.roundCorners)!==null&&b!==void 0?b:e.roundCorners})`},je=({target:i,layoutParams:t,fallback:e})=>{var n;i.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:e.angle}rad)`},ie="int",$e={AREA:`${ie}_area`,TEXT:`${ie}_text`,BUTTON:`${ie}_bttn`};class xe{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 Fi=i=>{if(i.type.trim().toLowerCase()==="area")return new qn(i)};class qn extends xe{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",$e.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",ki({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},X),{backgroundColor:"transparent"})}),Vi({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},X),{borderAlpha:0}),dependsOn:n}),je({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 Bi=i=>{if(i.type.trim().toLowerCase()==="button")return new Qn(i)};class Qn extends xe{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",$e.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",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),ki({target:s,props:this.control.props,fallback:X}),Vi({target:s,props:this.control.props,fallback:X,dependsOn:n}),Mi({target:s,props:this.control.props}),Ni({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 Yn=i=>{if(i.type.trim().toLowerCase()==="text")return new Kn(i)};class Kn extends xe{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",$e.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",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),Mi({target:s,props:this.control.props}),Ni({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 Xn{constructor(t){this.layout=t}}const Zn=i=>{if(i.type.trim().toLowerCase()==="relative")return new Di(i)};class Di extends Xn{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(h){try{d(n.next(h))}catch(u){l(u)}}function c(h){try{d(n.throw(h))}catch(u){l(u)}}function d(h){h.done?s(h.value):r(h.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 C(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 Ct,Ut,He;class Wi{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",Ut).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),a(this,Ct,"m",Ut).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",Ut).call(this)}}Ct=new WeakSet,Ut=function(){this.controls=a(this,Ct,"m",He).call(this)},He=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((e,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};const Hi=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Jn(i,t)};class Jn extends Wi{constructor(t,e){super(t),this.rootElement=e!=null?e:Li(),this.layout=new Di(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Bi),this.addControlFactory("text",Yn),this.addControlFactory("area",Fi)}createView(t){const 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=zn,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${Q}-${this.container.id}`)}}function Ui(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const At={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},St=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Re=i=>St(i,At.Object),ge=i=>St(i,At.String),Ae=i=>St(i,At.Array),Gi=i=>St(i,At.Number),tr=i=>St(i,At.Function),Ue=i=>Gi(i)&&!isNaN(i),xt=i=>Re(i)&&Object.keys(i).length===0,zi=i=>Ae(i)&&!i.length,kt=(i,t)=>ge(i)&&(t?i.trim():i).length,qi=window.navigator.userAgent.toLowerCase(),er=/mobi/i.test(qi);qi.indexOf("android")>-1;const ir="video_interactive",nr="videoint",rr=250;class sr{constructor(t){this.onResize=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(!Gi(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 Vn(this.lang,ir,nr)}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=ar(t),this.resizeObserver=new ResizeObserver(Ui(this.onResize,rr)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var t,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 ar(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 Qt=(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},or="3.1",Ge={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},lr={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},cr=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"]),h=!!d.endTime;let u=[lr];switch(c){case"await":h?u=[]:s=[];break;case"default":{const v={type:"onSuspense",action:{type:Ge.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?u=[v]:s=[v];break}case"random":case"weightlessRandom":case"max":case"min":{const v={type:"onSuspense",action:{type:Ge[c],args:{}}};h?u=[v]:s=[v];break}}for(const v of d.controls)l.push(Object.assign(Object.assign({},d),{controls:[Object.assign({},v)],id:Wn(),events:u}))}t.push(Object.assign(Object.assign({},e),{containers:l,events:s,branches:r}))}return i.metadata.version=or,i.metadata.updated=new Date().toISOString(),Object.assign(Object.assign({},i),{chapters:t})},dr="3.2",hr=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:dr}),media:e})}return i},ur="3.3",fr=(i=[])=>({edit:{chapters:i},view:{}}),ze={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},vr=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(h=>{var u;return Object.assign(Object.assign({},h),{controls:h.controls.map(v=>{var{subtype:m,type:b}=v,w=ot(v,["subtype","type"]);return Object.assign(Object.assign({},w),{type:m!=null?m:b})}),events:!((u=h.events)===null||u===void 0)&&u.length?h.events:[ze]})});e.push(Object.assign(Object.assign({id:s},c),{containers:d,events:!((t=c.events)===null||t===void 0)&&t.length?c.events:[ze]})),n.push({id:s,x:l,y:o})}return Object.assign(Object.assign({},i),{chapters:e,graph:fr(n),metadata:Object.assign(Object.assign({},i.metadata),{version:ur})})},pr=[{version:"3.0",migrate:cr},{version:"3.1",migrate:hr},{version:"3.2",migrate:vr}],yr=i=>pr.reduce((t,e)=>Qt(t.metadata.version,e.version)?t:e.migrate(t),i),mr=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 qe={metadata:"Object",chapters:"Array"},gr="3.0.0",br="3.3.0",Qi=i=>{const t=Qt(i,gr);return t===-1?!1:t===0?!0:Qt(i,br)!==1},Er=i=>{if(!Re(i))return!1;for(const t in qe)if(!i[t]||!St(i[t],qe[t]))return!1;return Qi(i.metadata.version)},Yi=i=>i.type===mr.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 Ki{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 Cr{constructor(t){this.addFn=(e,n=!1)=>{tr(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 _r{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 Ir(...this.loaders[t])(e)})}}function Ir(...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 Yt(i,t,e){return i?Object.assign(Object.assign({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function be(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:Yt(e,be.name,"Could not find media"),actions:t})}}return Object.assign(Object.assign({},r),{errors:Yt(e,be.name,"Could not find chapter"),actions:t})}class Qe{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 Xi extends Qe{constructor(){super(),this.listeners||Qe.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class wr{constructor(){Object.defineProperty(this,"signal",{value:new Xi,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&&(wr.prototype[Symbol.toStringTag]="AbortController",Xi.prototype[Symbol.toStringTag]="AbortSignal");function Zi(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 Sr(i){typeof i=="function"&&(i={fetch:i});const{fetch:t,Request:e=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!Zi({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,h){let u;h&&h.signal&&(u=h.signal,delete h.signal);const v=new e(d,h);return u&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),v},s.prototype=e.prototype);const l=t;return{fetch:(c,d)=>{const h=s&&s.prototype.isPrototypeOf(c)?c.signal:d?d.signal:void 0;if(h){let u;try{u=new DOMException("Aborted","AbortError")}catch(m){u=new Error("Aborted"),u.name="AbortError"}if(h.aborted)return Promise.reject(u);const v=new Promise((m,b)=>{h.addEventListener("abort",()=>b(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([v,l(c,d)])}return l(c,d)},Request:s}}const Pe=Zi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ji=Pe?Sr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ye=Pe?Ji.fetch:window.fetch;Pe?Ji.Request:window.Request;const Or=i=>x(void 0,void 0,void 0,function*(){try{let t,e;if(Re(i))t=i;else if(ge(i)){e=new URL(i).href;const r=yield Ye(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!Er(t))return{};const n=t.metadata.media;if(ge(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);const s=yield Ye(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return xr(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function Tr(i){return x(this,void 0,void 0,function*(){const{manifest:t,manifestURL:e}=yield Or(i),n=yr(t);return n.media=jr(n.media,e),delete n.metadata.media,n})}function ne(i,t){return i.find(e=>e.id===t)}function Ke(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 Xe(i,t){return i.videos.find(e=>e.id===t)}function jr(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=$r(n.url,t);return Object.assign(Object.assign({},n),{url:r||n.url})})}))})}function $r(i,t){try{return new URL(i,t).href}catch(e){return""}}function xr(i){return Qt(i,"3.2.0")>=0}const A=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Le=i=>Ae(i)&&!zi(i),Jt=i=>i.order==="end",Rr=i=>Ae(i.containers)&&!zi(i.containers)&&Jt(i),Ar=(i,t)=>{var e;const n=i*1e3;return Le(t.controls)&&n<((e=t.startTime)!==null&&e!==void 0?e:0)},Ze=(i,t)=>{var e,n;const r=i*1e3;return Le(t.controls)&&r>=((e=t.startTime)!==null&&e!==void 0?e:0)&&r<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Kt=i=>i.some(t=>t.action.type==="expect"),Je=i=>i.find(t=>t.action.type==="expect"),Pr=i=>(i==null?void 0:i.length)===1,tn=i=>Pr(i)&&Yi(i[0]),Lr=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(Object.assign(Object.assign({},n[t]),e[t])),Mr=(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=>!Yi(c));if(Le(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 h=[];let u=-1/0,v=1/0,m=[];const b=[];for(let w=0;w<t.length;w++){const f=t[w];if(b.push(...f.subjects),f.range[0]<v&&(v=f.range[0]),f.range[1]>u&&(u=f.range[1]),f.range[0]<=c[0]&&f.range[1]>=c[1])return t[w].subjects.push(d),t;c[0]>=f.range[0]&&c[0]<=f.range[1]&&(h.push(w),m=m.concat(f.subjects),c[0]=f.range[0]),c[1]>=f.range[0]&&c[1]<=f.range[1]&&(h.push(w),m=m.concat(f.subjects),c[1]=f.range[1])}if(b.push(d),c[0]<=v&&c[1]>=u)return[{subjects:b,range:c}];h.length&&h.reverse().forEach(w=>{t.splice(w,1)}),t.push({subjects:m.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),Nr=(i,t)=>Kt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Kt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);class kr extends _r{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:Yt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const r=yield Tr((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",be({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Ke,getChapter:ne,getMedia:Xe,getByBranches:this.getByBranches.bind(this),addErrorMessage:Yt},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=ne(this.manifest.chapters,t);if(e){const n=Xe(this.manifest.media,e.videoId),r=Ke(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=ne(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 Jt(this.chapter)}}const Vr=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"},ti={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Fr(){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 h of Object.values(d))h.player.destroy(),h.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 ei(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 Vt=(i,t)=>{const e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))},Gt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Br=2;function Dr(i){const t=Fr();let e,n;const r=new Ki;let s={},l=!1,o=null,c=!1,d;i&&h(i);function h(y){o=y}function u(y,E,g){var T;if(!o)throw Error("need to set interactive controller");const P=((T=t.map.get(y))!==null&&T!==void 0?T:{})[E];if(P){s=Object.assign({chapterId:g,listId:y,itemId:E},P);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()||Vt(N,V)})}}),P.container.remove(),l=!1,o.setPlayer(P.player),c||(o.init(),c=!0),r.emit(Gt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function v(y,E,g){return x(this,void 0,void 0,function*(){if(!o)throw Error("need to set interactive controller");if(xt(s)||y!==s.itemId)return;if(g>=0&&!l){const R=o.getChapterBranches();l=!0;const P=new Set;for(const I of R)P.has(I.media.id)||(yield b({media:I.media,chapterId:I.chapter.id,setAsActive:!1,title:I.chapter.label}),P.add(I.media.id))}})}function m({chapter:{id:y},media:E}){return x(this,void 0,void 0,function*(){if(xt(s))return;n==null||n.unsubscribe();const g=s.player.info.muted$.getValue(),T=s.player.info.currentQuality$.getValue(),R=s.player.info.isAutoQualityEnabled$.getValue(),P=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]===E.id){const Y=Object.keys(N[1]);for(const Z of Y)Z===s.itemId?(Y.length<Br||(W=!0),t.removePlayer(N[0],Z)):(W=!0,u(N[0],Z,y),V?Vt(s.player,T):s.player.setAutoQuality(!0),s.player.setVolume(P),s.player.setMuted(g),s.player.setPlaybackRate(I))}else t.removePlayer(N[0]);W||(yield b({media:E,chapterId:y,setAsActive:!0,playbackRate:I}),V?Vt(s.player,T):s.player.setAutoQuality(!0),s.player.setVolume(P),s.player.setMuted(g))})}function b({media:y,chapterId:E,prefetch:g=!0,setAsActive:T=!0,autoplay:R=!1,preferredExt:P,title:I,playbackRate:V}){var W,N,Y;return x(this,void 0,void 0,function*(){const Z=Math.random().toString(),pt=document.createElement("div");d.append(pt);const Nn=(W=s==null?void 0:s.player)===null||W===void 0?void 0:W.info.isAutoQualityEnabled$.getValue();let Mt;if(!((N=o==null?void 0:o.options)===null||N===void 0)&&N.vkVideoLoader){const Nt=Vr(y);Nt.length&&(Mt=yield o.options.vkVideoLoader(...Nt))}const ke=Object.assign(Object.assign({container:pt},((Y=Mt==null?void 0:Mt.videos)===null||Y===void 0?void 0:Y[0])||{sources:ei(y,P).sources}),{title:I}),ct=new Hn;ct.initVideo(ke);const kn=pt.lastChild,Ve=new Zt;Ve.add(ct.info.position$.subscribe(function(Nt){v(Z,ct.info.duration$.getValue(),Nt)})).add(ct.events.canplay$.subscribe(function(){Nn||Vt(ct,e),V&&ct.setPlaybackRate(V)})),kn&&(pt.style.display="none",pt.classList.add(E));const yt=t.createPlayer({listId:y.id,itemId:Z,player:ct,container:pt,sources:ei(y,P).sources,config:ke,subscription:Ve});return T&&u(y.id,yt.itemId,E),R&&yt.player.play(),g&&!R&&yt.player.prepare(),r.emit(Gt.playerCreated,yt.player),{player:yt.player,config:yt.config}})}function w(){f(),o=null}function f(){o==null||o.off(_.chapterChanged,m),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");f(),d=y;const{media:E,chapter:g}=o.getCurrentChapter();if(E){o.on(_.chapterChanged,m);const{player:T,config:R}=yield b({media:E,chapterId:g.id,title:g.label});return r.emit(Gt.initiated,{container:y,media:E,chapterId:g.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:h,createPlayer:b,removeAll:w,getActivePlayer:function(){return s}})}const Wr=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=Wr)=>{if(!i.length||t===null)return null;let o=-1,c=!1;const d=Math.round(t.info.position$.getValue()*1e3);for(const h of i){const u=h.startTime-l;if(u<=d&&(d<=h.endTime||h.endTime===null)){c=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!c&&o!==-1?o:null}}},wt=Hr();class Ur{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d}){this.hide=()=>{setTimeout(()=>{var h,u;this.gameState!==A.end&&(Kt(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:L.visibility,visibility:!1})))})},this.show=()=>{var h,u,v,m;if(this.gameState===A.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(m=(v=this.container).show)===null||m===void 0||m.call(v),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const w=Lr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(f,p)=>{this.isSelectedControlEvent=!0,f!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===A.end||this.gameState===A.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),p(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),wt.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===A.end});this.container.createView(w),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.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,v,m;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 w=this.player.getExactTime();if(Ar(w,this.container.container))this.gameState!==A.beforeInteractive&&(this.gameState=A.beforeInteractive,this.onBeforeStartTime());else if(Ze(w,this.container.container))this.gameState!==A.interactive&&(this.gameState=A.interactive,this.onStartTime());else if(this.gameState!==A.afterInteractive){const y=this.gameState;this.gameState=A.afterInteractive,y===A.interactive&&this.onEndTime()}else this.gameState!==A.destroyed&&this.removeView();const f=Ze(w,this.container.container),p=this.container.container.startTime?[this.container.container.startTime,(u=this.container.container.endTime)!==null&&u!==void 0?u:1/0]:[];(m=(v=this.container).onProgress)===null||m===void 0||m.call(v,w,f),this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:p,currentTime:w,isInteractiveTime:f})},this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Zt,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&tn(e.container.controls),this.disabledControls$=d,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)),this.subscription.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=Kt(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:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=A.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=A.removed}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}),wt.deleteContainer(this.container.container.id)}}function Gr(){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 h;if(Ue(o)){const u=(h=i[o])!==null&&h!==void 0?h:null;if(u&&kt(c,!0)){let v={};const m=u[c];if(m&&(v=Object.assign(Object.assign({},v),m)),v=xt(v)?null:v,v&&kt(d,!0)){const b=v[d];return b!=null?b:null}return v}return u}return null}function s({timestamp:o,priority:c,initiator:d}){if(Ue(o))if(i[o]){if(kt(c,!0))if(i[o][c]){if(kt(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!xt(i[o][c]))return!0}else return!1;if(delete i[o][c],!xt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(o){var c,d,h,{timestamp:u,priority:v,initiator:m}=o,b=ot(o,["timestamp","priority","initiator"]);!((d=(c=i[u])===null||c===void 0?void 0:c[v])===null||d===void 0)&&d[m]?i[u][v][m].push(Object.assign({},b)):!((h=i[u])===null||h===void 0)&&h[v]?i[u][v]=Object.assign(Object.assign({},i[u][v]),{[m]:[Object.assign({},b)]}):i[u]?i[u]=Object.assign(Object.assign({},i[u]),{[v]:{[m]:[Object.assign({},b)]}}):i[u]={[v]:{[m]:[Object.assign({},b)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}const zr=[j.expect,j.setNextBranch],qr=1/0;function ii(i){let t=i,e;const n=Qr(),r=new Gr;let s;const l=()=>{v(),f()},o=p=>{r.add.call(void 0,p),m()},c=(p=[])=>{for(const y of p)if(y.action(),zr.includes(y.actionType))break},d=(p=1/0)=>{var y,E,g;const T=Ft((y=r.get({timestamp:p,priority:"control"}))!==null&&y!==void 0?y:{}),R=Ft((E=r.get({timestamp:p,priority:"container"}))!==null&&E!==void 0?E:{}),P=Ft((g=r.get({timestamp:p,priority:"chapter"}))!==null&&g!==void 0?g:{});return[...T,...R,...P]},h=p=>{n.isReady(p)&&c(d(p))},u=()=>{var p;c([...Ft((p=r.get({timestamp:1/0,priority:"chapter"}))!==null&&p!==void 0?p:{})])},v=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},m=()=>{e||(e=()=>setTimeout(()=>{h(1/0)}),s=t.events.ended$.subscribe(e))},b=p=>{v(),t=p},w=p=>{p.priority==="container"&&n.resetCalled(p.timestamp),r.remove(p)},f=()=>{n.release(),r.removeAll()};return{setPlayer:b,add:o,remove:w,exec:h,execEndOfVideo:u,listen:m,unlisten:v,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function Qr(){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 h=(o=d.endTime)!==null&&o!==void 0?o:qr,u=(c=i.get(h))!==null&&c!==void 0?c:{};i.set(h,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 Ft(i){return Object.values(i).flat().sort(t=>t.actionType===j.expect?-1:1)}const Yr=(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}},Kr=250;function Xr(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:h,videoContentHeight:u}=Yr(c,d);c.style.setProperty("--interactive-content-width",`${h}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=Ui(o=>{const{fns:c=[]}=i();n(o);for(const d of c)d()},Kr);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}class Zr{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 Jr=i=>Math.floor(Math.random()*i),ts=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},es=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},is=i=>{const t=i.length,e=Jr(t);return i[e]},ni=1,ns=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:ni;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:ni,n>=r)return i[s];return i[i.length-1]},ri=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),re=(i,t=!1)=>Object.assign(Object.assign({},i),{args:t?Object.assign(Object.assign({},i.args),ri):Object.assign(Object.assign({},ri),i.args)}),si=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:p,controlId:y,containerId:E,branches:g=[],onEvent:T,isEOV:R=()=>!1,isDisabled:P=()=>!1})=>{const I=re(f,R()),V={timestamp:1/0,priority:"control",initiator:y,actionType:I.type},W=P(),N=i.emit.bind(i,_.interactives,{subjectId:y,subjectType:p,subjectName:"control",type:W?L.actionChoiceCanceled:L.actionChoice,actionType:f.type,payload:Object.assign({containerId:E},I.args)});if(W){N();return}switch(I.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const Y=g.find(Z=>Z.id===I.args.branchId);if(!Y)return;T(I.args.isDetachContainer,v.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,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?m({subjectId:y,subjectName:"control",subjectType:p,action:f}):e.add(Object.assign(Object.assign({},V),{action:m.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:f})}));return}case j.openURI.trim().toLowerCase():{T(I.args.isDetachContainer,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?w({subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{URI:f.args.uri}}):(e.add(Object.assign(Object.assign({},V),{action:w.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{URI:f.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:f,container:{id:p,endTime:y},branches:E=[],isEOV:g=!1,autoSelected:T=!1})=>{const R=re(f,g),P={timestamp:!R.args.shouldOpenNow||g?1/0:y,priority:"container",initiator:p,actionType:R.type},I=i.emit.bind(i,_.interactives,{subjectId:p,subjectName:"container",type:L.actionChoice,actionType:R.type,payload:R.args});switch(R.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const V=E.find(W=>W.id===R.args.branchId);if(!V)return;I(),e.add(Object.assign(Object.assign({},P),{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({},P),{action:m.bind(null,{subjectId:p,subjectName:"container",action:R})}));return}case j.openURI.trim().toLowerCase():{I(),e.add(Object.assign(Object.assign({},P),{action:w.bind(null,{subjectId:p,subjectName:"container",action:R,payload:{URI:f.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:f,branches:p,isEOV:y=!1}){const E=Je(f.events);if(E){const g=re(E.action,y);i.emit(_.interactives,{subjectId:f.id,subjectName:"container",type:L.actionChoice,actionType:g.type,payload:g.args}),e.add({timestamp:y?1/0:f.endTime,priority:"container",initiator:f.id,actionType:j.expect,action:u.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(const g of f.events)o({action:g.action,container:f,branches:p,isEOV:y})}const d=({chapterId:f,action:p,branches:y=[]})=>{const E=i.emit.bind(i,_.interactives,{subjectId:f,subjectName:"chapter",type:L.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const g=y.find(T=>T.id===p.args.branchId);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setWeightlessRandomBranch.trim().toLowerCase():{const g=is(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setRandomBranch.trim().toLowerCase():{const g=ns(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setMaxWeightBranch.trim().toLowerCase():{const g=es(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setMinWeightBranch.trim().toLowerCase():{const g=ts(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.continuePlayback.trim().toLowerCase():return E(),m.bind(null,{subjectId:f,subjectName:"chapter",action:p});case j.openURI.trim().toLowerCase():return E(),w.bind(null,{subjectId:f,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 h(f){const p=Je(f.events);if(p){if(Jt(f))return;i.emit(_.interactives,{subjectId:f.id,subjectName:"chapter",type:L.actionChoice,actionType:p.action.type,payload:p.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:j.expect,action:u.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(y=>{const E=d({chapterId:f.id,action:y.action,branches:f.branches});E&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:y.action.type,action:E})})}const u=({subjectId:f,subjectName:p,action:y})=>{var E;t.pause(),i.emit(_.interactives,{subjectId:f,subjectName:p,type:L.actionExecution,actionType:(E=y==null?void 0:y.type)!==null&&E!==void 0?E:j.expect})},v=({subjectId:f,subjectName:p})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(_.interactives,{subjectId:f,subjectName:p,type:L.actionExecution,actionType:"after-expect"})},m=({subjectId:f,subjectName:p,subjectType:y,action:E})=>{i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type})},b=({subjectId:f,subjectName:p,subjectType:y,action:E,payload:g})=>{g.behaviour="change-chapter",i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type,payload:g})},w=({subjectId:f,subjectName:p,subjectType:y,action:E,payload:g})=>{if(!g.URI)return;const T=window.open(g.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:v,setManifestChapterEvents:h,setManifestContainerEvents:c,stopExpect:s,state:r}};var se=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function rs(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Bt=function(i){return i&&i.Math==Math&&i},lt=Bt(typeof globalThis=="object"&&globalThis)||Bt(typeof window=="object"&&window)||Bt(typeof self=="object"&&self)||Bt(typeof se=="object"&&se)||function(){return this}()||se||Function("return this")(),ft=function(i){try{return!!i()}catch(t){return!0}},ss=ft,te=!ss(function(){var i=function(){}.bind();return typeof i!="function"||i.hasOwnProperty("prototype")}),as=te,en=Function.prototype,ai=en.apply,oi=en.call,os=typeof Reflect=="object"&&Reflect.apply||(as?oi.bind(ai):function(){return oi.apply(ai,arguments)}),nn=te,rn=Function.prototype,Ee=rn.call,ls=nn&&rn.bind.bind(Ee,Ee),Ot=nn?ls:function(i){return function(){return Ee.apply(i,arguments)}},sn=Ot,cs=sn({}.toString),ds=sn("".slice),an=function(i){return ds(cs(i),8,-1)},hs=an,us=Ot,on=function(i){if(hs(i)==="Function")return us(i)},Ce=typeof document=="object"&&document.all,fs=typeof Ce=="undefined"&&Ce!==void 0,ln={all:Ce,IS_HTMLDDA:fs},cn=ln,vs=cn.all,vt=cn.IS_HTMLDDA?function(i){return typeof i=="function"||i===vs}:function(i){return typeof i=="function"},dn={},ps=ft,Pt=!ps(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),ys=te,Dt=Function.prototype.call,Me=ys?Dt.bind(Dt):function(){return Dt.apply(Dt,arguments)},hn={},un={}.propertyIsEnumerable,fn=Object.getOwnPropertyDescriptor,ms=fn&&!un.call({1:2},1);hn.f=ms?function(t){var e=fn(this,t);return!!e&&e.enumerable}:un;var vn=function(i,t){return{enumerable:!(i&1),configurable:!(i&2),writable:!(i&4),value:t}},gs=Ot,bs=ft,Es=an,ae=Object,Cs=gs("".split),_s=bs(function(){return!ae("z").propertyIsEnumerable(0)})?function(i){return Es(i)=="String"?Cs(i,""):ae(i)}:ae,pn=function(i){return i==null},Is=pn,ws=TypeError,yn=function(i){if(Is(i))throw ws("Can't call method on "+i);return i},Ss=_s,Os=yn,Ts=function(i){return Ss(Os(i))},li=vt,mn=ln,js=mn.all,ee=mn.IS_HTMLDDA?function(i){return typeof i=="object"?i!==null:li(i)||i===js}:function(i){return typeof i=="object"?i!==null:li(i)},gn={},oe=gn,le=lt,$s=vt,ci=function(i){return $s(i)?i:void 0},bn=function(i,t){return arguments.length<2?ci(oe[i])||ci(le[i]):oe[i]&&oe[i][t]||le[i]&&le[i][t]},xs=Ot,Rs=xs({}.isPrototypeOf),As=typeof navigator!="undefined"&&String(navigator.userAgent)||"",En=lt,ce=As,di=En.process,hi=En.Deno,ui=di&&di.versions||hi&&hi.version,fi=ui&&ui.v8,z,Xt;fi&&(z=fi.split("."),Xt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!Xt&&ce&&(z=ce.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=ce.match(/Chrome\/(\d+)/),z&&(Xt=+z[1])));var Ps=Xt,vi=Ps,Ls=ft,Ms=lt,Ns=Ms.String,Cn=!!Object.getOwnPropertySymbols&&!Ls(function(){var i=Symbol();return!Ns(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&vi&&vi<41}),ks=Cn,_n=ks&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Vs=bn,Fs=vt,Bs=Rs,Ds=_n,Ws=Object,In=Ds?function(i){return typeof i=="symbol"}:function(i){var t=Vs("Symbol");return Fs(t)&&Bs(t.prototype,Ws(i))},Hs=String,Us=function(i){try{return Hs(i)}catch(t){return"Object"}},Gs=vt,zs=Us,qs=TypeError,wn=function(i){if(Gs(i))return i;throw qs(zs(i)+" is not a function")},Qs=wn,Ys=pn,Ks=function(i,t){var e=i[t];return Ys(e)?void 0:Qs(e)},de=Me,he=vt,ue=ee,Xs=TypeError,Zs=function(i,t){var e,n;if(t==="string"&&he(e=i.toString)&&!ue(n=de(e,i))||he(e=i.valueOf)&&!ue(n=de(e,i))||t!=="string"&&he(e=i.toString)&&!ue(n=de(e,i)))return n;throw Xs("Can't convert object to primitive value")},Sn={exports:{}},pi=lt,Js=Object.defineProperty,ta=function(i,t){try{Js(pi,i,{value:t,configurable:!0,writable:!0})}catch(e){pi[i]=t}return t},ea=lt,ia=ta,yi="__core-js_shared__",na=ea[yi]||ia(yi,{}),ra=na,mi=ra;(Sn.exports=function(i,t){return mi[i]||(mi[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 sa=Sn.exports,aa=yn,oa=Object,On=function(i){return oa(aa(i))},la=Ot,ca=On,da=la({}.hasOwnProperty),Ne=Object.hasOwn||function(t,e){return da(ca(t),e)},ha=Ot,ua=0,fa=Math.random(),va=ha(1 .toString),pa=function(i){return"Symbol("+(i===void 0?"":i)+")_"+va(++ua+fa,36)},ya=lt,ma=sa,gi=Ne,ga=pa,ba=Cn,Ea=_n,_t=ya.Symbol,fe=ma("wks"),Ca=Ea?_t.for||_t:_t&&_t.withoutSetter||ga,_a=function(i){return gi(fe,i)||(fe[i]=ba&&gi(_t,i)?_t[i]:Ca("Symbol."+i)),fe[i]},Ia=Me,bi=ee,Ei=In,wa=Ks,Sa=Zs,Oa=_a,Ta=TypeError,ja=Oa("toPrimitive"),$a=function(i,t){if(!bi(i)||Ei(i))return i;var e=wa(i,ja),n;if(e){if(t===void 0&&(t="default"),n=Ia(e,i,t),!bi(n)||Ei(n))return n;throw Ta("Can't convert object to primitive value")}return t===void 0&&(t="number"),Sa(i,t)},xa=$a,Ra=In,Tn=function(i){var t=xa(i,"string");return Ra(t)?t:t+""},Aa=lt,Ci=ee,_e=Aa.document,Pa=Ci(_e)&&Ci(_e.createElement),La=function(i){return Pa?_e.createElement(i):{}},Ma=Pt,Na=ft,ka=La,jn=!Ma&&!Na(function(){return Object.defineProperty(ka("div"),"a",{get:function(){return 7}}).a!=7}),Va=Pt,Fa=Me,Ba=hn,Da=vn,Wa=Ts,Ha=Tn,Ua=Ne,Ga=jn,_i=Object.getOwnPropertyDescriptor;dn.f=Va?_i:function(t,e){if(t=Wa(t),e=Ha(e),Ga)try{return _i(t,e)}catch(n){}if(Ua(t,e))return Da(!Fa(Ba.f,t,e),t[e])};var za=ft,qa=vt,Qa=/#|\.prototype\./,Lt=function(i,t){var e=Ka[Ya(i)];return e==Za?!0:e==Xa?!1:qa(t)?za(t):!!t},Ya=Lt.normalize=function(i){return String(i).replace(Qa,".").toLowerCase()},Ka=Lt.data={},Xa=Lt.NATIVE="N",Za=Lt.POLYFILL="P",Ja=Lt,Ii=on,to=wn,eo=te,io=Ii(Ii.bind),no=function(i,t){return to(i),t===void 0?i:eo?io(i,t):function(){return i.apply(t,arguments)}},$n={},ro=Pt,so=ft,ao=ro&&so(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),oo=ee,lo=String,co=TypeError,ho=function(i){if(oo(i))return i;throw co(lo(i)+" is not an object")},uo=Pt,fo=jn,vo=ao,Wt=ho,wi=Tn,po=TypeError,ve=Object.defineProperty,yo=Object.getOwnPropertyDescriptor,pe="enumerable",ye="configurable",me="writable";$n.f=uo?vo?function(t,e,n){if(Wt(t),e=wi(e),Wt(n),typeof t=="function"&&e==="prototype"&&"value"in n&&me in n&&!n[me]){var r=yo(t,e);r&&r[me]&&(t[e]=n.value,n={configurable:ye in n?n[ye]:r[ye],enumerable:pe in n?n[pe]:r[pe],writable:!1})}return ve(t,e,n)}:ve:function(t,e,n){if(Wt(t),e=wi(e),Wt(n),fo)try{return ve(t,e,n)}catch(r){}if("get"in n||"set"in n)throw po("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var mo=Pt,go=$n,bo=vn,Eo=mo?function(i,t,e){return go.f(i,t,bo(1,e))}:function(i,t,e){return i[t]=e,i},Ht=lt,Co=os,_o=on,Io=vt,wo=dn.f,So=Ja,mt=gn,Oo=no,gt=Eo,Si=Ne,To=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 Co(i,this,arguments)};return t.prototype=i.prototype,t},jo=function(i,t){var e=i.target,n=i.global,r=i.stat,s=i.proto,l=n?Ht:r?Ht[e]:(Ht[e]||{}).prototype,o=n?mt:mt[e]||gt(mt,e,{})[e],c=o.prototype,d,h,u,v,m,b,w,f,p;for(v in t)d=So(n?v:e+(r?".":"#")+v,i.forced),h=!d&&l&&Si(l,v),b=o[v],h&&(i.dontCallGetSet?(p=wo(l,v),w=p&&p.value):w=l[v]),m=h&&w?w:t[v],!(h&&typeof b==typeof m)&&(i.bind&&h?f=Oo(m,Ht):i.wrap&&h?f=To(m):s&&Io(m)?f=_o(m):f=m,(i.sham||m&&m.sham||b&&b.sham)&>(f,"sham",!0),gt(o,v,f),s&&(u=e+"Prototype",Si(mt,u)||gt(mt,u,{}),gt(mt[u],v,m),i.real&&c&&(d||!c[v])&>(c,v,m)))},$o=Math.ceil,xo=Math.floor,Ro=Math.trunc||function(t){var e=+t;return(e>0?xo:$o)(e)},Ao=Ro,xn=function(i){var t=+i;return t!==t||t===0?0:Ao(t)},Po=xn,Lo=Math.min,Mo=function(i){return i>0?Lo(Po(i),9007199254740991):0},No=Mo,ko=function(i){return No(i.length)},Vo=jo,Fo=On,Bo=ko,Do=xn;Vo({target:"Array",proto:!0},{at:function(t){var e=Fo(this),n=Bo(e),r=Do(t),s=r>=0?r:n+r;return s<0||s>=n?void 0:e[s]}});var Wo=bn,Ho=Wo,Uo=Ho,Go=Uo("Array","at"),zo=Go,qo=zo,Qo=qo,Yo=Qo,Oi=rs(Yo);const Ti=(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]=Rn(s)}return e[n]}).filter(Boolean)},Ko=i=>{for(const t of i.variants)if(Xo(t)&&"payload"in t)return t.payload.id},Xo=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Rn=i=>{const t=Ko(i);if(!t)return null;const e=t.split("_").pop();return e?parseInt(e,10):null},Zo=(i,t)=>{for(const e of i.media.videos)if(t===Rn(e)){for(const n of i.chapters)if(n.videoId===e.id)return n.id;return}},Jo=(i,t)=>i.reduce((e,n)=>{const r=Zo(t,n);return r?[...e,r]:e},[]);var et,zt,bt,G,Ie,it,nt,K,Et;const tl=100;class el{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)},et.set(this,null),zt.set(this,void 0),bt.set(this,!1),G.set(this,null),Ie.set(this,null),it.set(this,null),nt.set(this,null),K.set(this,null),Et.set(this,new Zt),C(this,it,e,"f"),C(this,K,t,"f"),C(this,nt,n,"f"),C(this,et,r,"f"),C(this,zt,{maxLength:(s==null?void 0:s.maxLength)||tl},"f"),!((l=this.state)===null||l===void 0)&&l.history$&&a(this,Et,"f")&&((o=a(this,Et,"f"))===null||o===void 0||o.add((c=this.state)===null||c===void 0?void 0:c.history$.subscribe(d=>{var h,u,v,m,b;(h=this.state)===null||h===void 0||h.prevChapter$.next(Oi(d,-2)||null),(u=this.state)===null||u===void 0||u.hasPrevChapter$.next(d.length>1),(v=this.state)===null||v===void 0||v.isInitialChapter$.next(this.getInitialChapterId()===((b=(m=a(this,G,"f"))===null||m===void 0?void 0:m.metadata)===null||b===void 0?void 0:b.initChapterId))})))}setManifest(t){return x(this,void 0,void 0,function*(){!a(this,nt,"f")||!a(this,K,"f")||(C(this,G,t,"f"),yield this.getProjectHistory(),yield a(this,nt,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,bt,"f")||(C(this,bt,!0,"f"),a(this,K,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,bt,"f")}updateHistory(t,e=!0){var n,r;return x(this,void 0,void 0,function*(){if(!a(this,G,"f"))return;const s=a(this,G,"f"),l=t.length-a(this,zt,"f").maxLength,o=l>0?t.slice(l):t,c=Ti(o,s);if(C(this,Ie,c,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(o),!(!e||!a(this,et,"f")||!a(this,it,"f")))try{yield a(this,et,"f").save(a(this,it,"f"),c)}catch(d){(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"));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,G,"f")||!a(this,it,"f"))return;const n=a(this,G,"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=Jo(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 Oi(n,-1)||((e=a(this,G,"f"))===null||e===void 0?void 0:e.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return Ti([t],a(this,G,"f")).pop()}return null}destroy(){var t,e;this.state=null,C(this,it,null,"f"),C(this,et,null,"f"),C(this,nt,null,"f"),(t=a(this,Et,"f"))===null||t===void 0||t.unsubscribe(),C(this,Et,null,"f"),C(this,bt,!1,"f"),(e=a(this,K,"f"))===null||e===void 0||e.emit(_.historyDestroyed),C(this,K,null,"f")}}et=new WeakMap,zt=new WeakMap,bt=new WeakMap,G=new WeakMap,Ie=new WeakMap,it=new WeakMap,nt=new WeakMap,K=new WeakMap,Et=new WeakMap;var Tt,An,we,ji;class J{constructor(t,e,n,r){this.target=t,this.type=e,this.listener=n,this.options=a(J,Tt,"m",An).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}}Tt=J,An=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,Tt,"m",ji).call(J,t)?e:e.capture||!1}},ji=function(t){let e=a(J,Tt,"f",we);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}C(J,Tt,e,"f",we)}return e||!1};we={value:void 0};class il{constructor(){this.bindingMap=new Zr}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 nl{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const 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 rl{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 Vn,ValueSubject as H,Subscription as Zt,Observable as Fe,getCurrentBrowser as Fn,CurrentClientBrowser as Bn,once as Dn}from"@vkontakte/videoplayer-shared/es2015.esm.js";import{v4 as Wn}from"uuid";import{Player as Hn}from"@vkontakte/videoplayer-core/es2015.esm.js";const Un="1.0.9-beta.1";function Pi(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",Gn="SDK_NAME-controls-container",Li=()=>document.querySelector(`.${Gn}`),zn=.4,X={textColor:"#000",textSize:.4,textContent:"",roundCorners:0,borderWidth:0,borderColor:"#000",borderAlpha:1,backgroundColor:"#fff",backgroundAlpha:1,innerSizesDependOn:"self",angle:0},Be={top:"flex-start",bottom:"flex-end",center:"center"},De={start:"flex-start",end:"flex-end",center:"center"},We={start:"left",end:"right",center:"center"},Mi=({target:i,props:t})=>{var e,n,r,s,l,o;i.style.alignItems=(n=Be[(e=t==null?void 0:t.text)===null||e===void 0?void 0:e.gravityVertical])!==null&&n!==void 0?n:Be.center,i.style.justifyContent=(s=De[(r=t==null?void 0:t.text)===null||r===void 0?void 0:r.gravityHorizontal])!==null&&s!==void 0?s:De.center,i.style.textAlign=(o=We[(l=t==null?void 0:t.text)===null||l===void 0?void 0:l.alignment])!==null&&o!==void 0?o:We.start},Ni=({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},ki=({target:i,props:t,fallback:e})=>{var n,r,s,l;i.style.backgroundColor=Pi((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)},Vi=({target:i,props:t,fallback:e,dependsOn:n})=>{var r,s,l,o,c,d,h,u,v,m,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 ${Pi((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,(v=(u=(h=t==null?void 0:t.shape)===null||h===void 0?void 0:h.border)===null||u===void 0?void 0:u.alpha)!==null&&v!==void 0?v:e.borderAlpha)}`,i.style.borderRadius=`calc(${n.height} * ${(b=(m=t==null?void 0:t.shape)===null||m===void 0?void 0:m.roundCorners)!==null&&b!==void 0?b:e.roundCorners})`},je=({target:i,layoutParams:t,fallback:e})=>{var n;i.style.transform=`rotate(${(n=-t.angle)!==null&&n!==void 0?n:e.angle}rad)`},ie="int",$e={AREA:`${ie}_area`,TEXT:`${ie}_text`,BUTTON:`${ie}_bttn`};class xe{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 Fi=i=>{if(i.type.trim().toLowerCase()==="area")return new qn(i)};class qn extends xe{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",$e.AREA),s.style.display="flex",s.style.width="100%",s.style.height="100%",s.style.cursor="pointer",s.type="button",ki({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},X),{backgroundColor:"transparent"})}),Vi({target:s,props:this.control.props,fallback:Object.assign(Object.assign({},X),{borderAlpha:0}),dependsOn:n}),je({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 Bi=i=>{if(i.type.trim().toLowerCase()==="button")return new Qn(i)};class Qn extends xe{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",$e.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",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),ki({target:s,props:this.control.props,fallback:X}),Vi({target:s,props:this.control.props,fallback:X,dependsOn:n}),Mi({target:s,props:this.control.props}),Ni({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 Yn=i=>{if(i.type.trim().toLowerCase()==="text")return new Kn(i)};class Kn extends xe{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",$e.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",je({target:s,layoutParams:this.control.layoutParams,fallback:X}),Mi({target:s,props:this.control.props}),Ni({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 Xn{constructor(t){this.layout=t}}const Zn=i=>{if(i.type.trim().toLowerCase()==="relative")return new Di(i)};class Di extends Xn{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(h){try{d(n.next(h))}catch(u){l(u)}}function c(h){try{d(n.throw(h))}catch(u){l(u)}}function d(h){h.done?s(h.value):r(h.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 C(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 Ct,Ut,He;class Wi{constructor(t){Ct.add(this),this.container=t,this.factories=new Map,a(this,Ct,"m",Ut).call(this)}addControlFactory(t,e){this.factories.set(t.trim().toLowerCase(),e),a(this,Ct,"m",Ut).call(this)}removeControlFactory(t){this.factories.delete(t.trim().toLowerCase()),a(this,Ct,"m",Ut).call(this)}}Ct=new WeakSet,Ut=function(){this.controls=a(this,Ct,"m",He).call(this)},He=function(){var t;return(t=this.container.controls)===null||t===void 0?void 0:t.reduce((e,n)=>{const r=n.type.trim().toLowerCase(),s=this.factories.get(r);return s?[...e,s(n)]:[...e]},[])};const Hi=(i,t)=>{if(i.type.trim().toLowerCase()==="choice")return new Jn(i,t)};class Jn extends Wi{constructor(t,e){super(t),this.rootElement=e!=null?e:Li(),this.layout=new Di(this.container.layout),this.isRemoved=!1,this.isDisabled=!1,this.addControlFactory("button",Bi),this.addControlFactory("text",Yn),this.addControlFactory("area",Fi)}createView(t){const 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=zn,this.isDisabled=!0)}removeView(){var t;this.isRemoved||((t=this.getElement())===null||t===void 0||t.remove(),this.isRemoved=!0)}getElement(){return this.rootElement.querySelector(`.${Q}-${this.container.id}`)}}function Ui(i,t){let e;return(...n)=>{clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const At={Object:"Object",String:"String",Array:"Array",Number:"Number",Function:"Function",Boolean:"Boolean"},St=(i,t)=>Object.prototype.toString.call(i)===`[object ${t}]`,Re=i=>St(i,At.Object),ge=i=>St(i,At.String),Ae=i=>St(i,At.Array),Gi=i=>St(i,At.Number),tr=i=>St(i,At.Function),Ue=i=>Gi(i)&&!isNaN(i),xt=i=>Re(i)&&Object.keys(i).length===0,zi=i=>Ae(i)&&!i.length,kt=(i,t)=>ge(i)&&(t?i.trim():i).length,qi=window.navigator.userAgent.toLowerCase(),er=/mobi/i.test(qi);qi.indexOf("android")>-1;const ir="video_interactive",nr="videoint",rr=250;class sr{constructor(t){this.onResize=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(!Gi(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 Vn(this.lang,ir,nr)}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=ar(t),this.resizeObserver=new ResizeObserver(Ui(this.onResize,rr)),this.resizeObserver.observe(this.graphWrapperElement)}getNextPoint(t=this.ngEditorSize){return[(this.lastZoomInfo.x-t.width/2)/this.lastZoomInfo.value*-1,(this.lastZoomInfo.y-t.height/2)/this.lastZoomInfo.value*-1]}setVisitedChapters(t){this.visitedChapterIds=new Set([...this.visitedChapterIds,...t]),this.ngEditor.setVisitedChapters(Array.from(this.visitedChapterIds))}updateVideosInfo(t){this.ngEditor.updateVideosInfo(t)}show(){!this.ngEditor||!this.isReady||(this.graphWrapperElement.style.display="block",this.lastZoomInfo||this.ngEditor.focusChapter(this.currentChapterId),this.isHidden=!1)}hide(){this.graphWrapperElement.style.display="none",this.isHidden=!0}destroy(){var t,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 ar(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 Qt=(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},or="3.1",Ge={default:"setNextBranch",random:"setRandomBranch",weightlessRandom:"setWeightlessRandomBranch",max:"setMaxWeightBranch",min:"setMinWeightBranch"},lr={type:"onSuspense",action:{type:"continuePlayback",args:{shouldOpenNow:!0,isDetachContainer:!0}}},cr=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"]),h=!!d.endTime;let u=[lr];switch(c){case"await":h?u=[]:s=[];break;case"default":{const v={type:"onSuspense",action:{type:Ge.default,args:{branchId:n,shouldOpenNow:!h,isDetachContainer:!0}}};h?u=[v]:s=[v];break}case"random":case"weightlessRandom":case"max":case"min":{const v={type:"onSuspense",action:{type:Ge[c],args:{}}};h?u=[v]:s=[v];break}}for(const v of d.controls)l.push(Object.assign(Object.assign({},d),{controls:[Object.assign({},v)],id:Wn(),events:u}))}t.push(Object.assign(Object.assign({},e),{containers:l,events:s,branches:r}))}return i.metadata.version=or,i.metadata.updated=new Date().toISOString(),Object.assign(Object.assign({},i),{chapters:t})},dr="3.2",hr=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:dr}),media:e})}return i},ur="3.3",fr=(i=[])=>({edit:{chapters:i},view:{}}),ze={type:"onSuspense",action:{type:"expect",args:{shouldOpenNow:!0,isDetachContainer:!0}}},vr=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(h=>{var u;return Object.assign(Object.assign({},h),{controls:h.controls.map(v=>{var{subtype:m,type:b}=v,w=ot(v,["subtype","type"]);return Object.assign(Object.assign({},w),{type:m!=null?m:b})}),events:!((u=h.events)===null||u===void 0)&&u.length?h.events:[ze]})});e.push(Object.assign(Object.assign({id:s},c),{containers:d,events:!((t=c.events)===null||t===void 0)&&t.length?c.events:[ze]})),n.push({id:s,x:l,y:o})}return Object.assign(Object.assign({},i),{chapters:e,graph:fr(n),metadata:Object.assign(Object.assign({},i.metadata),{version:ur})})},pr=[{version:"3.0",migrate:cr},{version:"3.1",migrate:hr},{version:"3.2",migrate:vr}],yr=i=>pr.reduce((t,e)=>Qt(t.metadata.version,e.version)?t:e.migrate(t),i),mr=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 qe={metadata:"Object",chapters:"Array"},gr="3.0.0",br="3.3.0",Qi=i=>{const t=Qt(i,gr);return t===-1?!1:t===0?!0:Qt(i,br)!==1},Er=i=>{if(!Re(i))return!1;for(const t in qe)if(!i[t]||!St(i[t],qe[t]))return!1;return Qi(i.metadata.version)},Yi=i=>i.type===mr.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 Ki{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 Cr{constructor(t){this.addFn=(e,n=!1)=>{tr(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 _r{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 Ir(...this.loaders[t])(e)})}}function Ir(...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 Yt(i,t,e){return i?Object.assign(Object.assign({},i),{[t]:i[t]?[e,...i[t]]:[e]}):{[t]:[e]}}function be(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:Yt(e,be.name,"Could not find media"),actions:t})}}return Object.assign(Object.assign({},r),{errors:Yt(e,be.name,"Could not find chapter"),actions:t})}class Qe{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 Xi extends Qe{constructor(){super(),this.listeners||Qe.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class wr{constructor(){Object.defineProperty(this,"signal",{value:new Xi,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&&(wr.prototype[Symbol.toStringTag]="AbortController",Xi.prototype[Symbol.toStringTag]="AbortSignal");function Zi(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 Sr(i){typeof i=="function"&&(i={fetch:i});const{fetch:t,Request:e=t.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=i;if(!Zi({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,h){let u;h&&h.signal&&(u=h.signal,delete h.signal);const v=new e(d,h);return u&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),v},s.prototype=e.prototype);const l=t;return{fetch:(c,d)=>{const h=s&&s.prototype.isPrototypeOf(c)?c.signal:d?d.signal:void 0;if(h){let u;try{u=new DOMException("Aborted","AbortError")}catch(m){u=new Error("Aborted"),u.name="AbortError"}if(h.aborted)return Promise.reject(u);const v=new Promise((m,b)=>{h.addEventListener("abort",()=>b(u),{once:!0})});return d&&d.signal&&delete d.signal,Promise.race([v,l(c,d)])}return l(c,d)},Request:s}}const Pe=Zi({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ji=Pe?Sr({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ye=Pe?Ji.fetch:window.fetch;Pe?Ji.Request:window.Request;const Or=i=>x(void 0,void 0,void 0,function*(){try{let t,e;if(Re(i))t=i;else if(ge(i)){e=new URL(i).href;const r=yield Ye(e);if(!r.ok)return{};t=yield r.json()}else return{};if(!Er(t))return{};const n=t.metadata.media;if(ge(n)&&!t.media)try{let r;e?r=new URL(n,e).href:(r=new URL(n).href,e=r);const s=yield Ye(r);if(!s.ok)throw new Error;t.metadata.media=yield s.json()}catch(r){return xr(t.metadata.version)?{manifest:t}:{}}return{manifest:t,manifestURL:e}}catch(t){return{}}});function Tr(i){return x(this,void 0,void 0,function*(){const{manifest:t,manifestURL:e}=yield Or(i),n=yr(t);return n.media=jr(n.media,e),delete n.metadata.media,n})}function ne(i,t){return i.find(e=>e.id===t)}function Ke(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 Xe(i,t){return i.videos.find(e=>e.id===t)}function jr(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=$r(n.url,t);return Object.assign(Object.assign({},n),{url:r||n.url})})}))})}function $r(i,t){try{return new URL(i,t).href}catch(e){return""}}function xr(i){return Qt(i,"3.2.0")>=0}const A=Object.freeze({nothing:0,beforeInteractive:1,interactive:2,afterInteractive:3,end:4,removed:5,destroyed:6}),Le=i=>Ae(i)&&!zi(i),Jt=i=>i.order==="end",Rr=i=>Ae(i.containers)&&!zi(i.containers)&&Jt(i),Ar=(i,t)=>{var e;const n=i*1e3;return Le(t.controls)&&n<((e=t.startTime)!==null&&e!==void 0?e:0)},Ze=(i,t)=>{var e,n;const r=i*1e3;return Le(t.controls)&&r>=((e=t.startTime)!==null&&e!==void 0?e:0)&&r<=((n=t.endTime)!==null&&n!==void 0?n:1/0)},Kt=i=>i.some(t=>t.action.type==="expect"),Je=i=>i.find(t=>t.action.type==="expect"),Pr=i=>(i==null?void 0:i.length)===1,tn=i=>Pr(i)&&Yi(i[0]),Lr=({fn:i,type:t=1},...e)=>(...n)=>t?i(...n,...e):i(Object.assign(Object.assign({},n[t]),e[t])),Mr=(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=>!Yi(c));if(Le(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 h=[];let u=-1/0,v=1/0,m=[];const b=[];for(let w=0;w<t.length;w++){const f=t[w];if(b.push(...f.subjects),f.range[0]<v&&(v=f.range[0]),f.range[1]>u&&(u=f.range[1]),f.range[0]<=c[0]&&f.range[1]>=c[1])return t[w].subjects.push(d),t;c[0]>=f.range[0]&&c[0]<=f.range[1]&&(h.push(w),m=m.concat(f.subjects),c[0]=f.range[0]),c[1]>=f.range[0]&&c[1]<=f.range[1]&&(h.push(w),m=m.concat(f.subjects),c[1]=f.range[1])}if(b.push(d),c[0]<=v&&c[1]>=u)return[{subjects:b,range:c}];h.length&&h.reverse().forEach(w=>{t.splice(w,1)}),t.push({subjects:m.concat([d]),range:c})}}return t},[]).sort((t,e)=>t.range[0]-e.range[0]),Nr=(i,t)=>Kt(i.events)?!1:t.some(({container:e})=>e.container.id!==i.id&&Kt(e.container.events)&&e.container.endTime===i.endTime&&!e.isRemoved);class kr extends _r{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:Yt},result:null,errors:null,source:t});n.errors&&this.errorHandler(n.errors);const r=yield Tr((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",be({actions:{getManifest:()=>this.manifest,getCurrent:this.getCurrent,getGraph:Ke,getChapter:ne,getMedia:Xe,getByBranches:this.getByBranches.bind(this),addErrorMessage:Yt},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=ne(this.manifest.chapters,t);if(e){const n=Xe(this.manifest.media,e.videoId),r=Ke(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=ne(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 Jt(this.chapter)}}const Vr=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"},ti={visibility:"visibility",watchAgainClicked:"watchAgainClicked"},L={actionChoiceCanceled:"action-choice-canceled",actionChoice:"action-choice",actionExecution:"action-execution",visibility:"visibility",containerRemoved:"container-removed",rangeEnded:"range-ended"};function Fr(){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 h of Object.values(d))h.player.destroy(),h.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 ei(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 Vt=(i,t)=>{const e=i.info.currentQuality$.getValue(),n=i.info.availableQualities$.getValue();e!==t&&n.includes(t)&&(i.setQuality(t),i.setAutoQuality(!1))},Gt={activePlayerChanged:"sc-active-player-changed",initiated:"sc-initiated",playerCreated:"sc-player-created"},Br=2;function Dr(i){const t=Fr();let e,n;const r=new Ki;let s={},l=!1,o=null,c=!1,d;i&&h(i);function h(y){o=y}function u(y,E,g){var T;if(!o)throw Error("need to set interactive controller");const P=((T=t.map.get(y))!==null&&T!==void 0?T:{})[E];if(P){s=Object.assign({chapterId:g,listId:y,itemId:E},P);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()||Vt(N,V)})}}),P.container.remove(),l=!1,o.setPlayer(P.player),c||(o.init(),c=!0),r.emit(Gt.activePlayerChanged,{player:s.player,config:s.config});return}throw Error("Can't set. Not find.")}function v(y,E,g){return x(this,void 0,void 0,function*(){if(!o)throw Error("need to set interactive controller");if(xt(s)||y!==s.itemId)return;if(g>=0&&!l){const R=o.getChapterBranches();l=!0;const P=new Set;for(const I of R)P.has(I.media.id)||(yield b({media:I.media,chapterId:I.chapter.id,setAsActive:!1,title:I.chapter.label}),P.add(I.media.id))}})}function m({chapter:{id:y},media:E}){return x(this,void 0,void 0,function*(){if(xt(s))return;n==null||n.unsubscribe();const g=s.player.info.muted$.getValue(),T=s.player.info.currentQuality$.getValue(),R=s.player.info.isAutoQualityEnabled$.getValue(),P=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]===E.id){const Y=Object.keys(N[1]);for(const Z of Y)Z===s.itemId?(Y.length<Br||(W=!0),t.removePlayer(N[0],Z)):(W=!0,u(N[0],Z,y),V?Vt(s.player,T):s.player.setAutoQuality(!0),s.player.setVolume(P),s.player.setMuted(g),s.player.setPlaybackRate(I))}else t.removePlayer(N[0]);W||(yield b({media:E,chapterId:y,setAsActive:!0,playbackRate:I}),V?Vt(s.player,T):s.player.setAutoQuality(!0),s.player.setVolume(P),s.player.setMuted(g))})}function b({media:y,chapterId:E,prefetch:g=!0,setAsActive:T=!0,autoplay:R=!1,preferredExt:P,title:I,playbackRate:V}){var W,N,Y;return x(this,void 0,void 0,function*(){const Z=Math.random().toString(),pt=document.createElement("div");d.append(pt);const Nn=(W=s==null?void 0:s.player)===null||W===void 0?void 0:W.info.isAutoQualityEnabled$.getValue();let Mt;if(!((N=o==null?void 0:o.options)===null||N===void 0)&&N.vkVideoLoader){const Nt=Vr(y);Nt.length&&(Mt=yield o.options.vkVideoLoader(...Nt))}const ke=Object.assign(Object.assign({container:pt},((Y=Mt==null?void 0:Mt.videos)===null||Y===void 0?void 0:Y[0])||{sources:ei(y,P).sources}),{title:I}),ct=new Hn;ct.initVideo(ke);const kn=pt.lastChild,Ve=new Zt;Ve.add(ct.info.position$.subscribe(function(Nt){v(Z,ct.info.duration$.getValue(),Nt)})).add(ct.events.canplay$.subscribe(function(){Nn||Vt(ct,e),V&&ct.setPlaybackRate(V)})),kn&&(pt.style.display="none",pt.classList.add(E));const yt=t.createPlayer({listId:y.id,itemId:Z,player:ct,container:pt,sources:ei(y,P).sources,config:ke,subscription:Ve});return T&&u(y.id,yt.itemId,E),R&&yt.player.play(),g&&!R&&yt.player.prepare(),r.emit(Gt.playerCreated,yt.player),{player:yt.player,config:yt.config}})}function w(){f(),o=null}function f(){o==null||o.off(_.chapterChanged,m),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");f(),d=y;const{media:E,chapter:g}=o.getCurrentChapter();if(E){o.on(_.chapterChanged,m);const{player:T,config:R}=yield b({media:E,chapterId:g.id,title:g.label});return r.emit(Gt.initiated,{container:y,media:E,chapterId:g.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:h,createPlayer:b,removeAll:w,getActivePlayer:function(){return s}})}const Wr=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=Wr)=>{if(!i.length||t===null)return null;let o=-1,c=!1;const d=Math.round(t.info.position$.getValue()*1e3);for(const h of i){const u=h.startTime-l;if(u<=d&&(d<=h.endTime||h.endTime===null)){c=!0;break}d<u&&(o=o===-1?u:Math.min(o,u))}return!c&&o!==-1?o:null}}},wt=Hr();class Ur{constructor({player:t,container:e,branches:n,selectBranches:r,interactiveEvents:s,globalEventEmitter:l,ignoreContainerEvent:o,permanentTextControls:c,disabledControls$:d}){this.hide=()=>{setTimeout(()=>{var h,u;this.gameState!==A.end&&(Kt(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:L.visibility,visibility:!1})))})},this.show=()=>{var h,u,v,m;if(this.gameState===A.interactive&&!this.isSelectedControlEvent)if(this.container.getElement())(m=(v=this.container).show)===null||m===void 0||m.call(v),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!0,isFirst:!1});else{const w=Lr({fn:this.selectBranches.onControlEvent,type:0},{isDisabled:()=>this.container.isDisabled,branches:this.branches,containerId:this.container.container.id,onDetachContainer:()=>{this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})},onEvent:(f,p)=>{this.isSelectedControlEvent=!0,f!==!1&&(this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),(this.gameState===A.end||this.gameState===A.afterInteractive||this.selectBranches.state.isExpect)&&(this.selectBranches.stopExpect(),p(),this.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.visibility,visibility:!1})),wt.deleteContainer(this.container.container.id)},isEOV:()=>this.gameState===A.end});this.container.createView(w),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.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,v,m;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 w=this.player.getExactTime();if(Ar(w,this.container.container))this.gameState!==A.beforeInteractive&&(this.gameState=A.beforeInteractive,this.onBeforeStartTime());else if(Ze(w,this.container.container))this.gameState!==A.interactive&&(this.gameState=A.interactive,this.onStartTime());else if(this.gameState!==A.afterInteractive){const y=this.gameState;this.gameState=A.afterInteractive,y===A.interactive&&this.onEndTime()}else this.gameState!==A.destroyed&&this.removeView();const f=Ze(w,this.container.container),p=this.container.container.startTime?[this.container.container.startTime,(u=this.container.container.endTime)!==null&&u!==void 0?u:1/0]:[];(m=(v=this.container).onProgress)===null||m===void 0||m.call(v,w,f),this.globalEventEmitter.emit(_.eachTick,{subjectId:this.container.container.id,subjectName:"container",range:p,currentTime:w,isInteractiveTime:f})},this.container=e,this.branches=n,this.selectBranches=r,this.subscription=new Zt,this.player=t,this.interactiveEvents=s,this.ignoreContainerEvent=o,this.isPermanentText=c&&tn(e.container.controls),this.disabledControls$=d,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)),this.subscription.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=Kt(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:L.visibility,visibility:!1})}reset(){this.isSelectedControlEvent=!1,this.isSelectedContainerEvent=!1,this.gameState=A.beforeInteractive}removeView(){this.container.removeView(),this.globalEventEmitter.emit(_.interactives,{subjectId:this.container.container.id,subjectName:"container",type:L.containerRemoved,visibility:!1}),this.gameState=A.removed}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}),wt.deleteContainer(this.container.container.id)}}function Gr(){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 h;if(Ue(o)){const u=(h=i[o])!==null&&h!==void 0?h:null;if(u&&kt(c,!0)){let v={};const m=u[c];if(m&&(v=Object.assign(Object.assign({},v),m)),v=xt(v)?null:v,v&&kt(d,!0)){const b=v[d];return b!=null?b:null}return v}return u}return null}function s({timestamp:o,priority:c,initiator:d}){if(Ue(o))if(i[o]){if(kt(c,!0))if(i[o][c]){if(kt(d,!0))if(i[o][c][d]){if(delete i[o][c][d],!xt(i[o][c]))return!0}else return!1;if(delete i[o][c],!xt(i[o]))return!0}else return!1;return delete i[o]}else return!1}function l(o){var c,d,h,{timestamp:u,priority:v,initiator:m}=o,b=ot(o,["timestamp","priority","initiator"]);!((d=(c=i[u])===null||c===void 0?void 0:c[v])===null||d===void 0)&&d[m]?i[u][v][m].push(Object.assign({},b)):!((h=i[u])===null||h===void 0)&&h[v]?i[u][v]=Object.assign(Object.assign({},i[u][v]),{[m]:[Object.assign({},b)]}):i[u]?i[u]=Object.assign(Object.assign({},i[u]),{[v]:{[m]:[Object.assign({},b)]}}):i[u]={[v]:{[m]:[Object.assign({},b)]}}}return{map:i,remove:s,add:l,removeAll:t,get:r,getLte:e,getGte:n}}const zr=[j.expect,j.setNextBranch],qr=1/0;function ii(i){let t=i,e;const n=Qr(),r=new Gr;let s;const l=()=>{v(),f()},o=p=>{r.add.call(void 0,p),m()},c=(p=[])=>{for(const y of p)if(y.action(),zr.includes(y.actionType))break},d=(p=1/0)=>{var y,E,g;const T=Ft((y=r.get({timestamp:p,priority:"control"}))!==null&&y!==void 0?y:{}),R=Ft((E=r.get({timestamp:p,priority:"container"}))!==null&&E!==void 0?E:{}),P=Ft((g=r.get({timestamp:p,priority:"chapter"}))!==null&&g!==void 0?g:{});return[...T,...R,...P]},h=p=>{n.isReady(p)&&c(d(p))},u=()=>{var p;c([...Ft((p=r.get({timestamp:1/0,priority:"chapter"}))!==null&&p!==void 0?p:{})])},v=()=>{e&&(s==null||s.unsubscribe(),e=void 0)},m=()=>{e||(e=()=>setTimeout(()=>{h(1/0)}),s=t.events.ended$.subscribe(e))},b=p=>{v(),t=p},w=p=>{p.priority==="container"&&n.resetCalled(p.timestamp),r.remove(p)},f=()=>{n.release(),r.removeAll()};return{setPlayer:b,add:o,remove:w,exec:h,execEndOfVideo:u,listen:m,unlisten:v,release:l,containersEventsCallState:n,getPreparedToExecActions:d}}function Qr(){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 h=(o=d.endTime)!==null&&o!==void 0?o:qr,u=(c=i.get(h))!==null&&c!==void 0?c:{};i.set(h,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 Ft(i){return Object.values(i).flat().sort(t=>t.actionType===j.expect?-1:1)}const Yr=(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}},Kr=250;function Xr(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:h,videoContentHeight:u}=Yr(c,d);c.style.setProperty("--interactive-content-width",`${h}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=Ui(o=>{const{fns:c=[]}=i();n(o);for(const d of c)d()},Kr);function l(){t=void 0,e.disconnect(),r()}return{resizeObserver:e,calc:()=>{t()},release:l}}class Zr{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 Jr=i=>Math.floor(Math.random()*i),ts=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},es=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},is=i=>{const t=i.length,e=Jr(t);return i[e]},ni=1,ns=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:ni;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:ni,n>=r)return i[s];return i[i.length-1]},ri=Object.freeze({shouldOpenNow:!0,isDetachContainer:!0}),re=(i,t=!1)=>Object.assign(Object.assign({},i),{args:t?Object.assign(Object.assign({},i.args),ri):Object.assign(Object.assign({},ri),i.args)}),si=({globalEventEmitter:i,player:t,interactiveEvents:e,removeControllers:n})=>{const r={isExpect:!1},s=()=>{r.isExpect&&(r.isExpect=!1)},l=({action:f,controlType:p,controlId:y,containerId:E,branches:g=[],onEvent:T,isEOV:R=()=>!1,isDisabled:P=()=>!1})=>{const I=re(f,R()),V={timestamp:1/0,priority:"control",initiator:y,actionType:I.type},W=P(),N=i.emit.bind(i,_.interactives,{subjectId:y,subjectType:p,subjectName:"control",type:W?L.actionChoiceCanceled:L.actionChoice,actionType:f.type,payload:Object.assign({containerId:E},I.args)});if(W){N();return}switch(I.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const Y=g.find(Z=>Z.id===I.args.branchId);if(!Y)return;T(I.args.isDetachContainer,v.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,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?m({subjectId:y,subjectName:"control",subjectType:p,action:f}):e.add(Object.assign(Object.assign({},V),{action:m.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:f})}));return}case j.openURI.trim().toLowerCase():{T(I.args.isDetachContainer,v.bind(null,{subjectId:y,subjectName:"control"})),N(),I.args.shouldOpenNow?w({subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{URI:f.args.uri}}):(e.add(Object.assign(Object.assign({},V),{action:w.bind(null,{subjectId:y,subjectName:"control",subjectType:p,action:I,payload:{URI:f.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:f,container:{id:p,endTime:y},branches:E=[],isEOV:g=!1,autoSelected:T=!1})=>{const R=re(f,g),P={timestamp:!R.args.shouldOpenNow||g?1/0:y,priority:"container",initiator:p,actionType:R.type},I=i.emit.bind(i,_.interactives,{subjectId:p,subjectName:"container",type:L.actionChoice,actionType:R.type,payload:R.args});switch(R.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const V=E.find(W=>W.id===R.args.branchId);if(!V)return;I(),e.add(Object.assign(Object.assign({},P),{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({},P),{action:m.bind(null,{subjectId:p,subjectName:"container",action:R})}));return}case j.openURI.trim().toLowerCase():{I(),e.add(Object.assign(Object.assign({},P),{action:w.bind(null,{subjectId:p,subjectName:"container",action:R,payload:{URI:f.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:f,branches:p,isEOV:y=!1}){const E=Je(f.events);if(E){const g=re(E.action,y);i.emit(_.interactives,{subjectId:f.id,subjectName:"container",type:L.actionChoice,actionType:g.type,payload:g.args}),e.add({timestamp:y?1/0:f.endTime,priority:"container",initiator:f.id,actionType:j.expect,action:u.bind(null,{subjectId:f.id,subjectName:"container"})}),r.isExpect=!0}else for(const g of f.events)o({action:g.action,container:f,branches:p,isEOV:y})}const d=({chapterId:f,action:p,branches:y=[]})=>{const E=i.emit.bind(i,_.interactives,{subjectId:f,subjectName:"chapter",type:L.actionChoice,actionType:p.type,payload:p.args});switch(p.type.trim().toLowerCase()){case j.setNextBranch.trim().toLowerCase():{const g=y.find(T=>T.id===p.args.branchId);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setWeightlessRandomBranch.trim().toLowerCase():{const g=is(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setRandomBranch.trim().toLowerCase():{const g=ns(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setMaxWeightBranch.trim().toLowerCase():{const g=es(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.setMinWeightBranch.trim().toLowerCase():{const g=ts(y);return g!=null&&g.chapterId?(E(),b.bind(null,{subjectId:f,subjectName:"chapter",action:p,payload:{chapterId:g.chapterId,autoSelect:!0}})):void 0}case j.continuePlayback.trim().toLowerCase():return E(),m.bind(null,{subjectId:f,subjectName:"chapter",action:p});case j.openURI.trim().toLowerCase():return E(),w.bind(null,{subjectId:f,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 h(f){const p=Je(f.events);if(p){if(Jt(f))return;i.emit(_.interactives,{subjectId:f.id,subjectName:"chapter",type:L.actionChoice,actionType:p.action.type,payload:p.action.args}),e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:j.expect,action:u.bind(null,{subjectId:f.id,subjectName:"chapter"})})}else f.events.forEach(y=>{const E=d({chapterId:f.id,action:y.action,branches:f.branches});E&&e.add({timestamp:1/0,priority:"chapter",initiator:f.id,actionType:y.action.type,action:E})})}const u=({subjectId:f,subjectName:p,action:y})=>{var E;t.pause(),i.emit(_.interactives,{subjectId:f,subjectName:p,type:L.actionExecution,actionType:(E=y==null?void 0:y.type)!==null&&E!==void 0?E:j.expect})},v=({subjectId:f,subjectName:p})=>{t.info.isEnded$.getValue()?e.execEndOfVideo():t.play(),i.emit(_.interactives,{subjectId:f,subjectName:p,type:L.actionExecution,actionType:"after-expect"})},m=({subjectId:f,subjectName:p,subjectType:y,action:E})=>{i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type})},b=({subjectId:f,subjectName:p,subjectType:y,action:E,payload:g})=>{g.behaviour="change-chapter",i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type,payload:g})},w=({subjectId:f,subjectName:p,subjectType:y,action:E,payload:g})=>{if(!g.URI)return;const T=window.open(g.URI,"_blank","noopener,noreferrer");T&&(T.opener=null),i.emit(_.interactives,{subjectId:f,subjectName:p,subjectType:y,type:L.actionExecution,actionType:E.type})};return{onControlEvent:l,onContainerEvent:o,onChapterEvent:d,onExpectEvent:u,expectEventHandler:v,setManifestChapterEvents:h,setManifestContainerEvents:c,stopExpect:s,state:r}};var se=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function rs(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Bt=function(i){return i&&i.Math==Math&&i},lt=Bt(typeof globalThis=="object"&&globalThis)||Bt(typeof window=="object"&&window)||Bt(typeof self=="object"&&self)||Bt(typeof se=="object"&&se)||function(){return this}()||se||Function("return this")(),ft=function(i){try{return!!i()}catch(t){return!0}},ss=ft,te=!ss(function(){var i=function(){}.bind();return typeof i!="function"||i.hasOwnProperty("prototype")}),as=te,en=Function.prototype,ai=en.apply,oi=en.call,os=typeof Reflect=="object"&&Reflect.apply||(as?oi.bind(ai):function(){return oi.apply(ai,arguments)}),nn=te,rn=Function.prototype,Ee=rn.call,ls=nn&&rn.bind.bind(Ee,Ee),Ot=nn?ls:function(i){return function(){return Ee.apply(i,arguments)}},sn=Ot,cs=sn({}.toString),ds=sn("".slice),an=function(i){return ds(cs(i),8,-1)},hs=an,us=Ot,on=function(i){if(hs(i)==="Function")return us(i)},Ce=typeof document=="object"&&document.all,fs=typeof Ce=="undefined"&&Ce!==void 0,ln={all:Ce,IS_HTMLDDA:fs},cn=ln,vs=cn.all,vt=cn.IS_HTMLDDA?function(i){return typeof i=="function"||i===vs}:function(i){return typeof i=="function"},dn={},ps=ft,Pt=!ps(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),ys=te,Dt=Function.prototype.call,Me=ys?Dt.bind(Dt):function(){return Dt.apply(Dt,arguments)},hn={},un={}.propertyIsEnumerable,fn=Object.getOwnPropertyDescriptor,ms=fn&&!un.call({1:2},1);hn.f=ms?function(t){var e=fn(this,t);return!!e&&e.enumerable}:un;var vn=function(i,t){return{enumerable:!(i&1),configurable:!(i&2),writable:!(i&4),value:t}},gs=Ot,bs=ft,Es=an,ae=Object,Cs=gs("".split),_s=bs(function(){return!ae("z").propertyIsEnumerable(0)})?function(i){return Es(i)=="String"?Cs(i,""):ae(i)}:ae,pn=function(i){return i==null},Is=pn,ws=TypeError,yn=function(i){if(Is(i))throw ws("Can't call method on "+i);return i},Ss=_s,Os=yn,Ts=function(i){return Ss(Os(i))},li=vt,mn=ln,js=mn.all,ee=mn.IS_HTMLDDA?function(i){return typeof i=="object"?i!==null:li(i)||i===js}:function(i){return typeof i=="object"?i!==null:li(i)},gn={},oe=gn,le=lt,$s=vt,ci=function(i){return $s(i)?i:void 0},bn=function(i,t){return arguments.length<2?ci(oe[i])||ci(le[i]):oe[i]&&oe[i][t]||le[i]&&le[i][t]},xs=Ot,Rs=xs({}.isPrototypeOf),As=typeof navigator!="undefined"&&String(navigator.userAgent)||"",En=lt,ce=As,di=En.process,hi=En.Deno,ui=di&&di.versions||hi&&hi.version,fi=ui&&ui.v8,z,Xt;fi&&(z=fi.split("."),Xt=z[0]>0&&z[0]<4?1:+(z[0]+z[1]));!Xt&&ce&&(z=ce.match(/Edge\/(\d+)/),(!z||z[1]>=74)&&(z=ce.match(/Chrome\/(\d+)/),z&&(Xt=+z[1])));var Ps=Xt,vi=Ps,Ls=ft,Ms=lt,Ns=Ms.String,Cn=!!Object.getOwnPropertySymbols&&!Ls(function(){var i=Symbol();return!Ns(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&vi&&vi<41}),ks=Cn,_n=ks&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Vs=bn,Fs=vt,Bs=Rs,Ds=_n,Ws=Object,In=Ds?function(i){return typeof i=="symbol"}:function(i){var t=Vs("Symbol");return Fs(t)&&Bs(t.prototype,Ws(i))},Hs=String,Us=function(i){try{return Hs(i)}catch(t){return"Object"}},Gs=vt,zs=Us,qs=TypeError,wn=function(i){if(Gs(i))return i;throw qs(zs(i)+" is not a function")},Qs=wn,Ys=pn,Ks=function(i,t){var e=i[t];return Ys(e)?void 0:Qs(e)},de=Me,he=vt,ue=ee,Xs=TypeError,Zs=function(i,t){var e,n;if(t==="string"&&he(e=i.toString)&&!ue(n=de(e,i))||he(e=i.valueOf)&&!ue(n=de(e,i))||t!=="string"&&he(e=i.toString)&&!ue(n=de(e,i)))return n;throw Xs("Can't convert object to primitive value")},Sn={exports:{}},pi=lt,Js=Object.defineProperty,ta=function(i,t){try{Js(pi,i,{value:t,configurable:!0,writable:!0})}catch(e){pi[i]=t}return t},ea=lt,ia=ta,yi="__core-js_shared__",na=ea[yi]||ia(yi,{}),ra=na,mi=ra;(Sn.exports=function(i,t){return mi[i]||(mi[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 sa=Sn.exports,aa=yn,oa=Object,On=function(i){return oa(aa(i))},la=Ot,ca=On,da=la({}.hasOwnProperty),Ne=Object.hasOwn||function(t,e){return da(ca(t),e)},ha=Ot,ua=0,fa=Math.random(),va=ha(1 .toString),pa=function(i){return"Symbol("+(i===void 0?"":i)+")_"+va(++ua+fa,36)},ya=lt,ma=sa,gi=Ne,ga=pa,ba=Cn,Ea=_n,_t=ya.Symbol,fe=ma("wks"),Ca=Ea?_t.for||_t:_t&&_t.withoutSetter||ga,_a=function(i){return gi(fe,i)||(fe[i]=ba&&gi(_t,i)?_t[i]:Ca("Symbol."+i)),fe[i]},Ia=Me,bi=ee,Ei=In,wa=Ks,Sa=Zs,Oa=_a,Ta=TypeError,ja=Oa("toPrimitive"),$a=function(i,t){if(!bi(i)||Ei(i))return i;var e=wa(i,ja),n;if(e){if(t===void 0&&(t="default"),n=Ia(e,i,t),!bi(n)||Ei(n))return n;throw Ta("Can't convert object to primitive value")}return t===void 0&&(t="number"),Sa(i,t)},xa=$a,Ra=In,Tn=function(i){var t=xa(i,"string");return Ra(t)?t:t+""},Aa=lt,Ci=ee,_e=Aa.document,Pa=Ci(_e)&&Ci(_e.createElement),La=function(i){return Pa?_e.createElement(i):{}},Ma=Pt,Na=ft,ka=La,jn=!Ma&&!Na(function(){return Object.defineProperty(ka("div"),"a",{get:function(){return 7}}).a!=7}),Va=Pt,Fa=Me,Ba=hn,Da=vn,Wa=Ts,Ha=Tn,Ua=Ne,Ga=jn,_i=Object.getOwnPropertyDescriptor;dn.f=Va?_i:function(t,e){if(t=Wa(t),e=Ha(e),Ga)try{return _i(t,e)}catch(n){}if(Ua(t,e))return Da(!Fa(Ba.f,t,e),t[e])};var za=ft,qa=vt,Qa=/#|\.prototype\./,Lt=function(i,t){var e=Ka[Ya(i)];return e==Za?!0:e==Xa?!1:qa(t)?za(t):!!t},Ya=Lt.normalize=function(i){return String(i).replace(Qa,".").toLowerCase()},Ka=Lt.data={},Xa=Lt.NATIVE="N",Za=Lt.POLYFILL="P",Ja=Lt,Ii=on,to=wn,eo=te,io=Ii(Ii.bind),no=function(i,t){return to(i),t===void 0?i:eo?io(i,t):function(){return i.apply(t,arguments)}},$n={},ro=Pt,so=ft,ao=ro&&so(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),oo=ee,lo=String,co=TypeError,ho=function(i){if(oo(i))return i;throw co(lo(i)+" is not an object")},uo=Pt,fo=jn,vo=ao,Wt=ho,wi=Tn,po=TypeError,ve=Object.defineProperty,yo=Object.getOwnPropertyDescriptor,pe="enumerable",ye="configurable",me="writable";$n.f=uo?vo?function(t,e,n){if(Wt(t),e=wi(e),Wt(n),typeof t=="function"&&e==="prototype"&&"value"in n&&me in n&&!n[me]){var r=yo(t,e);r&&r[me]&&(t[e]=n.value,n={configurable:ye in n?n[ye]:r[ye],enumerable:pe in n?n[pe]:r[pe],writable:!1})}return ve(t,e,n)}:ve:function(t,e,n){if(Wt(t),e=wi(e),Wt(n),fo)try{return ve(t,e,n)}catch(r){}if("get"in n||"set"in n)throw po("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var mo=Pt,go=$n,bo=vn,Eo=mo?function(i,t,e){return go.f(i,t,bo(1,e))}:function(i,t,e){return i[t]=e,i},Ht=lt,Co=os,_o=on,Io=vt,wo=dn.f,So=Ja,mt=gn,Oo=no,gt=Eo,Si=Ne,To=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 Co(i,this,arguments)};return t.prototype=i.prototype,t},jo=function(i,t){var e=i.target,n=i.global,r=i.stat,s=i.proto,l=n?Ht:r?Ht[e]:(Ht[e]||{}).prototype,o=n?mt:mt[e]||gt(mt,e,{})[e],c=o.prototype,d,h,u,v,m,b,w,f,p;for(v in t)d=So(n?v:e+(r?".":"#")+v,i.forced),h=!d&&l&&Si(l,v),b=o[v],h&&(i.dontCallGetSet?(p=wo(l,v),w=p&&p.value):w=l[v]),m=h&&w?w:t[v],!(h&&typeof b==typeof m)&&(i.bind&&h?f=Oo(m,Ht):i.wrap&&h?f=To(m):s&&Io(m)?f=_o(m):f=m,(i.sham||m&&m.sham||b&&b.sham)&>(f,"sham",!0),gt(o,v,f),s&&(u=e+"Prototype",Si(mt,u)||gt(mt,u,{}),gt(mt[u],v,m),i.real&&c&&(d||!c[v])&>(c,v,m)))},$o=Math.ceil,xo=Math.floor,Ro=Math.trunc||function(t){var e=+t;return(e>0?xo:$o)(e)},Ao=Ro,xn=function(i){var t=+i;return t!==t||t===0?0:Ao(t)},Po=xn,Lo=Math.min,Mo=function(i){return i>0?Lo(Po(i),9007199254740991):0},No=Mo,ko=function(i){return No(i.length)},Vo=jo,Fo=On,Bo=ko,Do=xn;Vo({target:"Array",proto:!0},{at:function(t){var e=Fo(this),n=Bo(e),r=Do(t),s=r>=0?r:n+r;return s<0||s>=n?void 0:e[s]}});var Wo=bn,Ho=Wo,Uo=Ho,Go=Uo("Array","at"),zo=Go,qo=zo,Qo=qo,Yo=Qo,Oi=rs(Yo);const Ti=(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]=Rn(s)}return e[n]}).filter(Boolean)},Ko=i=>{for(const t of i.variants)if(Xo(t)&&"payload"in t)return t.payload.id},Xo=i=>i.type==="custom"&&"payload"in i&&i.payload.type==="vk",Rn=i=>{const t=Ko(i);if(!t)return null;const e=t.split("_").pop();return e?parseInt(e,10):null},Zo=(i,t)=>{for(const e of i.media.videos)if(t===Rn(e)){for(const n of i.chapters)if(n.videoId===e.id)return n.id;return}},Jo=(i,t)=>i.reduce((e,n)=>{const r=Zo(t,n);return r?[...e,r]:e},[]);var et,zt,bt,G,Ie,it,nt,K,Et;const tl=100;class el{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)},et.set(this,null),zt.set(this,void 0),bt.set(this,!1),G.set(this,null),Ie.set(this,null),it.set(this,null),nt.set(this,null),K.set(this,null),Et.set(this,new Zt),C(this,it,e,"f"),C(this,K,t,"f"),C(this,nt,n,"f"),C(this,et,r,"f"),C(this,zt,{maxLength:(s==null?void 0:s.maxLength)||tl},"f"),!((l=this.state)===null||l===void 0)&&l.history$&&a(this,Et,"f")&&((o=a(this,Et,"f"))===null||o===void 0||o.add((c=this.state)===null||c===void 0?void 0:c.history$.subscribe(d=>{var h,u,v,m,b;(h=this.state)===null||h===void 0||h.prevChapter$.next(Oi(d,-2)||null),(u=this.state)===null||u===void 0||u.hasPrevChapter$.next(d.length>1),(v=this.state)===null||v===void 0||v.isInitialChapter$.next(this.getInitialChapterId()===((b=(m=a(this,G,"f"))===null||m===void 0?void 0:m.metadata)===null||b===void 0?void 0:b.initChapterId))})))}setManifest(t){return x(this,void 0,void 0,function*(){!a(this,nt,"f")||!a(this,K,"f")||(C(this,G,t,"f"),yield this.getProjectHistory(),yield a(this,nt,"f").setChapter({chapterId:this.getInitialChapterId(),pushToHistory:!1}),a(this,bt,"f")||(C(this,bt,!0,"f"),a(this,K,"f").emit(_.historyInited,{initChapterId:this.getInitialChapterId()})))})}get inited(){return a(this,bt,"f")}updateHistory(t,e=!0){var n,r;return x(this,void 0,void 0,function*(){if(!a(this,G,"f"))return;const s=a(this,G,"f"),l=t.length-a(this,zt,"f").maxLength,o=l>0?t.slice(l):t,c=Ti(o,s);if(C(this,Ie,c,"f"),(n=this===null||this===void 0?void 0:this.state)===null||n===void 0||n.history$.next(o),!(!e||!a(this,et,"f")||!a(this,it,"f")))try{yield a(this,et,"f").save(a(this,it,"f"),c)}catch(d){(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"));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,G,"f")||!a(this,it,"f"))return;const n=a(this,G,"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=Jo(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 Oi(n,-1)||((e=a(this,G,"f"))===null||e===void 0?void 0:e.metadata.initChapterId)}getInitialVideoId(){if(a(this,G,"f")){const t=this.getInitialChapterId();return Ti([t],a(this,G,"f")).pop()}return null}destroy(){var t,e;this.state=null,C(this,it,null,"f"),C(this,et,null,"f"),C(this,nt,null,"f"),(t=a(this,Et,"f"))===null||t===void 0||t.unsubscribe(),C(this,Et,null,"f"),C(this,bt,!1,"f"),(e=a(this,K,"f"))===null||e===void 0||e.emit(_.historyDestroyed),C(this,K,null,"f")}}et=new WeakMap,zt=new WeakMap,bt=new WeakMap,G=new WeakMap,Ie=new WeakMap,it=new WeakMap,nt=new WeakMap,K=new WeakMap,Et=new WeakMap;var Tt,An,we,ji;class J{constructor(t,e,n,r){this.target=t,this.type=e,this.listener=n,this.options=a(J,Tt,"m",An).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}}Tt=J,An=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,Tt,"m",ji).call(J,t)?e:e.capture||!1}},ji=function(t){let e=a(J,Tt,"f",we);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}C(J,Tt,e,"f",we)}return e||!1};we={value:void 0};class il{constructor(){this.bindingMap=new Zr}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 nl{constructor(){this._prevSizeId=0,this.rootElement=document.createElement("canvas")}clear(){var t;(t=this.rootElement.getContext("2d"))===null||t===void 0||t.clearRect(0,0,this.rootElement.width,this.rootElement.height)}isImageDrawn(){var t;const 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 rl{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;
|