@vouchfor/embeds-legacy 5.0.1 → 5.0.2

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.
@@ -202,7 +202,7 @@ class FetcherController {
202
202
  return this._fetching;
203
203
  }
204
204
  }
205
- const version = "5.0.1";
205
+ const version = "5.0.2";
206
206
  const packageJson = {
207
207
  version
208
208
  };
@@ -1495,7 +1495,7 @@ Schedule: ${l.map(d=>qi(d))}`),c.length&&this.log(`Removed events ${c}`),this.pl
1495
1495
  vmp-legacy-captions.hiddenControls {
1496
1496
  transform: translateY(calc(var(--space-small) * -1));
1497
1497
  }
1498
- `],Ct([V({type:Boolean})],ot.prototype,"loading",2),Ct([V({type:Boolean})],ot.prototype,"playing",2),Ct([V({type:Number})],ot.prototype,"volume",2),Ct([V({type:Boolean})],ot.prototype,"muted",2),Ct([V({type:Number})],ot.prototype,"currentTime",2),Ct([V({type:Number})],ot.prototype,"duration",2),Ct([V({type:Array})],ot.prototype,"languages",2),Ct([V({type:String})],ot.prototype,"language",2),Ct([V({type:Array,attribute:!1})],ot.prototype,"levels",2),Ct([V({type:Number})],ot.prototype,"level",2),Ct([V({type:Number})],ot.prototype,"playbackRate",2),Ct([V({type:String})],ot.prototype,"caption",2),Ct([V({type:Array})],ot.prototype,"buffer",2),Ct([V({type:Boolean})],ot.prototype,"captions",2),Ct([V({type:Boolean})],ot.prototype,"fullscreen",2),Ct([V({type:Array})],ot.prototype,"controls",2),Ct([rt()],ot.prototype,"showControls",2),ot=Ct([Lt("vmp-legacy-player-overlay")],ot);var VB=Object.defineProperty,JB=Object.getOwnPropertyDescriptor,je=(s,e,t,i)=>{for(var r=i>1?void 0:i?JB(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(e,t,r):o(r))||r);return i&&r&&VB(e,t,r),r};const WB=1e3/60;let We=class extends Je{constructor(){super(...arguments),this.burnCaptions=!1,this.debug=!1,this.translateBaseUrl="https://public.vouchfor.com",this.propAspectRatio=0,this.preload="auto",this.autoplay=!1,this.loading=!1,this.compilation=ha,this.dataResolver=Ia,this._sceneController=new Zv(this),this._drawController=new Jv(this),this._observer=null,this._wasPlaying=!1,this._manualMute=this.muted,this._seekerRAF=null,this._seekerTimeout=null,this._lastWaiting=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this._pageHidden=document.visibilityState==="hidden",this._aspectRatio=this.propAspectRatio,this._processing=!1,this._waiting=!1,this._errors=[],this._seeking=!1,this._language=null,this._translatedCaptions=new Map,this._captions=!1,this._fullscreen=!1,this._playerRef=St(),this._canvasRef=St(),this._initialised=null,this._paused=!0,this._playbackRate=1,this._volume=null,this._muted=null,this._videoResolution=-1,this._handleContainerResize=()=>{var s;if((s=this.shadowRoot)!=null&&s.host){const e=this.shadowRoot.host.clientWidth,t=this.shadowRoot.host.clientHeight;if(e<=0||t<=0)return;this.propAspectRatio||(this._aspectRatio=e/t),Object.values(this.videos).forEach(({node:i})=>{i instanceof HTMLVideoElement&&(i.width=e,i.height=t)}),this._updateHlsLevelCap(e,t)}},this._handleCanvasResize=()=>{this.draw()},this._loop=()=>{this._endLoop(),this._pageHidden?this._seekerTimeout=setTimeout(this._seeker,WB):this._seekerRAF=requestAnimationFrame(this._seeker)},this._endLoop=()=>{this._seekerRAF&&cancelAnimationFrame(this._seekerRAF),this._seekerTimeout&&clearTimeout(this._seekerTimeout),this._seekerRAF=null,this._seekerTimeout=null},this._seeker=(s=performance.now())=>{if(this.sceneConfig&&this.scenes.length>0){if(this._waiting=this._drawController.activeScenes.some(({video:e})=>{if(e){const{key:t}=e,i=this.videoState[t];return!i||!i.initialised||i.waiting||e.node.readyState<3}}),this.waiting?(this._lastTimestamp=null,this._lastWaiting||this.dispatchEvent(new CustomEvent("waiting"))):this._lastWaiting&&this.dispatchEvent(new CustomEvent("playing")),s-(this._lastTimestamp??0)>1e3/this.sceneConfig.frameRate){let e=this._drawController.currentTime;const t=(s-(this._lastTimestamp??s))/1e3*this.playbackRate;if(this.sceneConfig&&this.activeScenes[0]&&this.activeScenes[0].video){const i=this.activeScenes[0].video;this._lastCurrentTime!==i.node.currentTime&&(e+=t),this._lastCurrentTime=i.node.currentTime}else e+=t;this._drawController.currentTime=e,this._lastTimestamp=s}this._lastWaiting=this._waiting,this._drawController.currentTime>=this.duration&&(this.pause(),this.dispatchEvent(new CustomEvent("ended")))}this.paused||this._loop()},this._translatedAnswerIds=new Set,this._handleScenesUpdate=()=>{const s=this.language;if(this.defaultLanguage==null&&this._language==null||s===this.defaultLanguage)return;const e=this._getAnswerIds();this._setsEqual(e,this._translatedAnswerIds)||this._fetchTranslations(s)},this._handleError=s=>{this._errors=[...this.errors,s.error],s.error.fatal&&this.pause()},this._handleFullscreenChange=()=>{var s;const e=!!(((s=this.shadowRoot)==null?void 0:s.fullscreenElement)??document.fullscreenElement===this),t=this._fullscreen;this._fullscreen=e,e?this._updateHlsLevelCap(window.screen.width,window.screen.height,!0):t&&requestAnimationFrame(()=>{var i;this._handleContainerResize(),(i=this.shadowRoot)!=null&&i.host&&this._updateHlsLevelCap(this.shadowRoot.host.clientWidth,this.shadowRoot.host.clientHeight,!0)})},this._handleVisibilityChange=()=>{this._pageHidden=document.visibilityState==="hidden",this.paused||this._loop()}}get aspectRatio(){return this._aspectRatio}get processing(){return this._processing}get waiting(){return!this.paused&&this._waiting}get errors(){return this._errors}get seeking(){return this._seeking}set language(s){var e;s!==this._language&&(this._language=s,localStorage.setItem("vmp-legacy-player-language",s),(e=this._translateAbortController)==null||e.abort(),this._translatedCaptions=new Map,this._translatedAnswerIds=new Set,this._drawController.refreshCaptions(),(!this.defaultLanguage||s!==this.defaultLanguage)&&(this._captions||(this._captions=!0),this._fetchTranslations(s)),this.requestUpdate())}get language(){const s=this._language??localStorage.getItem("vmp-legacy-player-language")??this.defaultLanguage??"en",e=this._resolvedLanguages;return e.length&&!e.find(({value:t})=>t===s)?e[0].value:s}get _resolvedLanguages(){var s;let e;if(!((s=this.languages)!=null&&s.length))e=[...hB];else{const t=new Map(tA.map(i=>[i.value,i]));e=this.languages.map(i=>t.get(i)).filter(i=>!!i)}return this.defaultLanguage&&!e.find(({value:t})=>t===this.defaultLanguage)&&e.unshift(dB(this.defaultLanguage)),e}get captions(){return this._captions}get fullscreen(){return this._fullscreen}get playerElement(){return this._playerRef.value??null}get canvasElement(){return this._canvasRef.value??null}get initialised(){return this._initialised=this._initialised??new Promise(s=>{const e=setInterval(()=>{!!this.errors.find(i=>i.fatal)&&s(!1),!this.loading&&!this.processing&&this.scenes.length>0&&s(!0)},500);setTimeout(()=>{clearInterval(e),s(!1)},60*1e3)}),this._initialised}get duration(){return this._sceneController.duration}get activeScenes(){return this._drawController.activeScenes}get scene(){return this._drawController.activeScenes[this._drawController.activeScenes.length-1]}get scenes(){var s;return((s=this._sceneController.scenes)==null?void 0:s.scenes)??[]}get sceneConfig(){return this._sceneController.scenes}get videos(){return this._sceneController.videos??{}}get videoState(){return this._sceneController.videoState}get sceneVideoState(){return this.scenes.reduce((s,{video:e,start:t,duration:i})=>{const r=(e==null?void 0:e.key)??`${t}-${i}`;return s[r]=this.videoState[r],s},{})}set paused(s){s!==this._paused&&(this._paused=s,this.requestUpdate(),this.dispatchEvent(new CustomEvent(s?"pause":"play")))}get paused(){return this._paused}set playbackRate(s){s!==this._playbackRate&&(this._playbackRate=s,this.scenes.forEach(({video:e})=>{e&&(e.node.playbackRate=s)}),this.requestUpdate(),this.dispatchEvent(new CustomEvent("ratechange",{detail:s})))}get playbackRate(){return this._playbackRate}set volume(s){const e=Math.min(1,Math.max(0,s));e!==this._volume&&(this.scenes.forEach(({video:t})=>{t&&(t.node.volume=e)}),localStorage.setItem("vmp-legacy-player-volume",e.toString()),this._volume=e,e>0&&(this.muted=!1),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:s})))}get volume(){return this._volume??(this._volume=parseFloat(localStorage.getItem("vmp-legacy-player-volume")??"1"))}set muted(s){this.scenes.forEach(({video:e})=>{e&&(e.node.muted=s)}),s!==this._muted&&(this._muted=s,localStorage.setItem("vmp-legacy-player-muted",s.toString()),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:s?0:this.volume})))}get muted(){return this._muted??(this._muted=this.autoplay||localStorage.getItem("vmp-legacy-player-muted")==="true")}get _hlsLevels(){var s;for(const e of this.scenes)if((s=e.video)!=null&&s.hls&&e.video.hls.levels.length>0)return e.video.hls.levels;return[]}get _currentLevel(){var s;if(this._videoResolution===-1)return-1;for(const e of this.scenes)if((s=e.video)!=null&&s.hls&&e.video.hls.levels.length>0)return e.video.hls.levels.findIndex(t=>Math.min(t.height,t.width)===this._videoResolution);return-1}set videoResolution(s){var e;s!==this._videoResolution&&(this._videoResolution=s,this.scenes.forEach(({video:t})=>{if(t!=null&&t.hls)if(s===-1)t.hls.nextLevel=-1;else{const i=t.hls.levels.findIndex(r=>Math.min(r.height,r.width)===s);i!==-1&&(t.hls.nextLevel=i,t.hls.autoLevelCapping=i)}}),s===-1&&((e=this.shadowRoot)!=null&&e.host)&&this._updateHlsLevelCap(this.shadowRoot.host.clientWidth,this.shadowRoot.host.clientHeight),this.requestUpdate())}get videoResolution(){return this._videoResolution}set currentTime(s){s!==this._drawController.currentTime&&(this._drawController.currentTime=s,this._sceneController.setVideosCurrentTime(s))}get currentTime(){return this._drawController.currentTime}_updateHlsLevelCap(s,e,t=!1){if(s<=0||e<=0||this._videoResolution!==-1)return;const i=window.devicePixelRatio||1,r=Math.min(s,e)*i;this.scenes.forEach(({video:n})=>{if(n!=null&&n.hls&&n.hls.levels.length>0){let o=0;for(let a=n.hls.levels.length-1;a>=0;a--)if(Math.min(n.hls.levels[a].width,n.hls.levels[a].height)<=r){o=a;break}n.hls.autoLevelCapping=o,t&&(n.hls.nextLevel=o)}})}reset(s=0,e=!1){this._lastTimestamp=null,this._lastCurrentTime=null,this._drawController.currentTime=s,this._sceneController.setVideosCurrentTime(s),e?this.play():this.pause()}clear(){this._drawController.clear()}play(){this.paused=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this.duration>0&&this._drawController.currentTime>=this.duration&&this.reset(0,!0),this._loop()}pause(){this._endLoop(),this.paused=!0,this.scenes.forEach(({video:s})=>{s&&s.node.pause()})}draw(s){return this._drawController.draw(s)}setScene(s){var e,t;if((e=this._sceneController)!=null&&e.scenes){const i=(t=this.scenes)==null?void 0:t[s];if(!i){const r=new Ei(`No scene at index: ${s}`);return this.dispatchEvent(new ErrorEvent("error",{composed:!0,bubbles:!0,error:r,message:r.message}))}this.reset(i.start+this._sceneController.scenes.transitionDuration,!this.paused)}}toggleFullscreen(s){s??this.fullscreen?tB():this._playerRef.value&&eB(this._playerRef.value)}_getAnswerIds(){const s=new Set;return this.scenes.forEach(({videoMeta:e})=>{e!=null&&e.id&&s.add(e.id)}),s}_setsEqual(s,e){if(s.size!==e.size)return!1;for(const t of s)if(!e.has(t))return!1;return!0}async _fetchTranslations(s){var e;(e=this._translateAbortController)==null||e.abort();const t=new AbortController;this._translateAbortController=t;const i=this._getAnswerIds();try{const r=await Promise.all(Array.from(i).map(async o=>{try{const a=await uB(o,s,this.translateBaseUrl);return[o,a]}catch{return[o,null]}}));if(t.signal.aborted)return;const n=new Map;for(const[o,a]of r)a&&n.set(o,a);this._translatedCaptions=n,this._translatedAnswerIds=i,this._drawController.refreshCaptions()}catch{}}connectedCallback(){var s;super.connectedCallback(),this.addEventListener("error",this._handleError),this.addEventListener("scenesupdate",this._handleScenesUpdate),document.addEventListener("fullscreenchange",this._handleFullscreenChange),document.addEventListener("webkitfullscreenchange",this._handleFullscreenChange),document.addEventListener("visibilitychange",this._handleVisibilityChange),(s=this.shadowRoot)!=null&&s.host&&(this._observer=new ResizeObserver(this._handleContainerResize),this._observer.observe(this.shadowRoot.host))}willUpdate(s){var e,t;if(s.has("propAspectRatio")&&(this._aspectRatio=this.propAspectRatio),s.has("data")&&s.get("data")!==void 0&&((e=this._translateAbortController)==null||e.abort(),this._translatedCaptions=new Map,this._translatedAnswerIds=new Set,this._drawController.refreshCaptions()),s.has("defaultLanguage")&&this._language===null){(t=this._translateAbortController)==null||t.abort(),this._translatedCaptions=new Map,this._translatedAnswerIds=new Set,this._drawController.refreshCaptions();const i=this.language;this.defaultLanguage!=null&&i!==this.defaultLanguage&&this._fetchTranslations(i)}}updated(s){var e;s.has("propAspectRatio")&&!this.propAspectRatio&&this._handleContainerResize(),this.autoplay&&!this._sceneController.hasPlayed&&!this.processing&&s.get("_processing")&&this.play(),s.has("_processing")&&this.processing&&this.dispatchEvent(new CustomEvent("processing")),s.has("_processing")&&!this.processing&&s.get("_processing")&&(e=this.shadowRoot)!=null&&e.host&&this._updateHlsLevelCap(this.shadowRoot.host.clientWidth,this.shadowRoot.host.clientHeight)}disconnectedCallback(){var s,e;super.disconnectedCallback(),(s=this._translateAbortController)==null||s.abort(),(e=this._observer)==null||e.disconnect(),this.removeEventListener("scenesupdate",this._handleScenesUpdate),document.removeEventListener("fullscreenchange",this._handleFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._handleFullscreenChange),document.removeEventListener("visibilitychange",this._handleVisibilityChange)}_renderStyles(){return this.propAspectRatio?typeof this.propAspectRatio=="number"?ve`
1498
+ `],Ct([V({type:Boolean})],ot.prototype,"loading",2),Ct([V({type:Boolean})],ot.prototype,"playing",2),Ct([V({type:Number})],ot.prototype,"volume",2),Ct([V({type:Boolean})],ot.prototype,"muted",2),Ct([V({type:Number})],ot.prototype,"currentTime",2),Ct([V({type:Number})],ot.prototype,"duration",2),Ct([V({type:Array})],ot.prototype,"languages",2),Ct([V({type:String})],ot.prototype,"language",2),Ct([V({type:Array,attribute:!1})],ot.prototype,"levels",2),Ct([V({type:Number})],ot.prototype,"level",2),Ct([V({type:Number})],ot.prototype,"playbackRate",2),Ct([V({type:String})],ot.prototype,"caption",2),Ct([V({type:Array})],ot.prototype,"buffer",2),Ct([V({type:Boolean})],ot.prototype,"captions",2),Ct([V({type:Boolean})],ot.prototype,"fullscreen",2),Ct([V({type:Array})],ot.prototype,"controls",2),Ct([rt()],ot.prototype,"showControls",2),ot=Ct([Lt("vmp-legacy-player-overlay")],ot);var VB=Object.defineProperty,JB=Object.getOwnPropertyDescriptor,je=(s,e,t,i)=>{for(var r=i>1?void 0:i?JB(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(e,t,r):o(r))||r);return i&&r&&VB(e,t,r),r};const WB=1e3/60;let We=class extends Je{constructor(){super(...arguments),this.burnCaptions=!1,this.debug=!1,this.translateBaseUrl="https://public.vouchfor.com",this.propAspectRatio=0,this.preload="auto",this.autoplay=!1,this.loading=!1,this.compilation=ha,this.dataResolver=Ia,this._sceneController=new Zv(this),this._drawController=new Jv(this),this._observer=null,this._wasPlaying=!1,this._manualMute=this.muted,this._seekerRAF=null,this._seekerTimeout=null,this._lastWaiting=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this._pageHidden=document.visibilityState==="hidden",this._aspectRatio=this.propAspectRatio,this._processing=!1,this._waiting=!1,this._errors=[],this._seeking=!1,this._language=null,this._translatedCaptions=new Map,this._captions=!1,this._fullscreen=!1,this._playerRef=St(),this._canvasRef=St(),this._initialised=null,this._paused=!0,this._playbackRate=1,this._volume=null,this._muted=null,this._videoResolution=-1,this._handleContainerResize=()=>{var s;if((s=this.shadowRoot)!=null&&s.host){const e=this.shadowRoot.host.clientWidth,t=this.shadowRoot.host.clientHeight;if(e<=0||t<=0)return;this.propAspectRatio||(this._aspectRatio=e/t),Object.values(this.videos).forEach(({node:i})=>{i instanceof HTMLVideoElement&&(i.width=e,i.height=t)}),this._updateHlsLevelCap(e,t)}},this._handleCanvasResize=()=>{this.draw()},this._loop=()=>{this._endLoop(),this._pageHidden?this._seekerTimeout=setTimeout(this._seeker,WB):this._seekerRAF=requestAnimationFrame(this._seeker)},this._endLoop=()=>{this._seekerRAF&&cancelAnimationFrame(this._seekerRAF),this._seekerTimeout&&clearTimeout(this._seekerTimeout),this._seekerRAF=null,this._seekerTimeout=null},this._seeker=(s=performance.now())=>{if(this.sceneConfig&&this.scenes.length>0){if(this._waiting=this._drawController.activeScenes.some(({video:e})=>{if(e){const{key:t}=e,i=this.videoState[t];return!i||!i.initialised||i.waiting||e.node.readyState<3}}),this.waiting?(this._lastTimestamp=null,this._lastWaiting||this.dispatchEvent(new CustomEvent("waiting"))):this._lastWaiting&&this.dispatchEvent(new CustomEvent("playing")),s-(this._lastTimestamp??0)>1e3/this.sceneConfig.frameRate){let e=this._drawController.currentTime;const t=(s-(this._lastTimestamp??s))/1e3*this.playbackRate;if(this.sceneConfig&&this.activeScenes[0]&&this.activeScenes[0].video){const i=this.activeScenes[0].video;this._lastCurrentTime!==i.node.currentTime&&(e+=t),this._lastCurrentTime=i.node.currentTime}else e+=t;this._drawController.currentTime=e,this._lastTimestamp=s}this._lastWaiting=this._waiting,this._drawController.currentTime>=this.duration&&(this.pause(),this.dispatchEvent(new CustomEvent("ended")))}this.paused||this._loop()},this._translatedAnswerIds=new Set,this._handleScenesUpdate=()=>{const s=this.language;if(this.defaultLanguage==null&&this._language==null||s===this.defaultLanguage)return;const e=this._getAnswerIds();this._setsEqual(e,this._translatedAnswerIds)||this._fetchTranslations(s)},this._handleError=s=>{this._errors=[...this.errors,s.error],s.error.fatal&&this.pause()},this._handleFullscreenChange=()=>{var s;const e=!!(((s=this.shadowRoot)==null?void 0:s.fullscreenElement)??document.fullscreenElement===this),t=this._fullscreen;this._fullscreen=e,e?(this._aspectRatio=window.screen.width/window.screen.height,this._updateHlsLevelCap(window.screen.width,window.screen.height,!0)):t&&(this.propAspectRatio&&(this._aspectRatio=this.propAspectRatio),requestAnimationFrame(()=>{var i;this._handleContainerResize(),(i=this.shadowRoot)!=null&&i.host&&this._updateHlsLevelCap(this.shadowRoot.host.clientWidth,this.shadowRoot.host.clientHeight,!0)}))},this._handleVisibilityChange=()=>{this._pageHidden=document.visibilityState==="hidden",this.paused||this._loop()}}get aspectRatio(){return this._aspectRatio}get processing(){return this._processing}get waiting(){return!this.paused&&this._waiting}get errors(){return this._errors}get seeking(){return this._seeking}set language(s){var e;s!==this._language&&(this._language=s,localStorage.setItem("vmp-legacy-player-language",s),(e=this._translateAbortController)==null||e.abort(),this._translatedCaptions=new Map,this._translatedAnswerIds=new Set,this._drawController.refreshCaptions(),(!this.defaultLanguage||s!==this.defaultLanguage)&&(this._captions||(this._captions=!0),this._fetchTranslations(s)),this.requestUpdate())}get language(){const s=this._language??localStorage.getItem("vmp-legacy-player-language")??this.defaultLanguage??"en",e=this._resolvedLanguages;return e.length&&!e.find(({value:t})=>t===s)?e[0].value:s}get _resolvedLanguages(){var s;let e;if(!((s=this.languages)!=null&&s.length))e=[...hB];else{const t=new Map(tA.map(i=>[i.value,i]));e=this.languages.map(i=>t.get(i)).filter(i=>!!i)}return this.defaultLanguage&&!e.find(({value:t})=>t===this.defaultLanguage)&&e.unshift(dB(this.defaultLanguage)),e}get captions(){return this._captions}get fullscreen(){return this._fullscreen}get playerElement(){return this._playerRef.value??null}get canvasElement(){return this._canvasRef.value??null}get initialised(){return this._initialised=this._initialised??new Promise(s=>{const e=setInterval(()=>{!!this.errors.find(i=>i.fatal)&&s(!1),!this.loading&&!this.processing&&this.scenes.length>0&&s(!0)},500);setTimeout(()=>{clearInterval(e),s(!1)},60*1e3)}),this._initialised}get duration(){return this._sceneController.duration}get activeScenes(){return this._drawController.activeScenes}get scene(){return this._drawController.activeScenes[this._drawController.activeScenes.length-1]}get scenes(){var s;return((s=this._sceneController.scenes)==null?void 0:s.scenes)??[]}get sceneConfig(){return this._sceneController.scenes}get videos(){return this._sceneController.videos??{}}get videoState(){return this._sceneController.videoState}get sceneVideoState(){return this.scenes.reduce((s,{video:e,start:t,duration:i})=>{const r=(e==null?void 0:e.key)??`${t}-${i}`;return s[r]=this.videoState[r],s},{})}set paused(s){s!==this._paused&&(this._paused=s,this.requestUpdate(),this.dispatchEvent(new CustomEvent(s?"pause":"play")))}get paused(){return this._paused}set playbackRate(s){s!==this._playbackRate&&(this._playbackRate=s,this.scenes.forEach(({video:e})=>{e&&(e.node.playbackRate=s)}),this.requestUpdate(),this.dispatchEvent(new CustomEvent("ratechange",{detail:s})))}get playbackRate(){return this._playbackRate}set volume(s){const e=Math.min(1,Math.max(0,s));e!==this._volume&&(this.scenes.forEach(({video:t})=>{t&&(t.node.volume=e)}),localStorage.setItem("vmp-legacy-player-volume",e.toString()),this._volume=e,e>0&&(this.muted=!1),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:s})))}get volume(){return this._volume??(this._volume=parseFloat(localStorage.getItem("vmp-legacy-player-volume")??"1"))}set muted(s){this.scenes.forEach(({video:e})=>{e&&(e.node.muted=s)}),s!==this._muted&&(this._muted=s,localStorage.setItem("vmp-legacy-player-muted",s.toString()),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:s?0:this.volume})))}get muted(){return this._muted??(this._muted=this.autoplay||localStorage.getItem("vmp-legacy-player-muted")==="true")}get _hlsLevels(){var s;for(const e of this.scenes)if((s=e.video)!=null&&s.hls&&e.video.hls.levels.length>0){const t=new Map;for(const i of e.video.hls.levels){const r=Math.min(i.height,i.width),n=t.get(r);(!n||(i.bitrate??0)>(n.bitrate??0))&&t.set(r,i)}return[...t.values()]}return[]}get _currentLevel(){return this._videoResolution===-1?-1:this._hlsLevels.findIndex(s=>Math.min(s.height,s.width)===this._videoResolution)}set videoResolution(s){var e;s!==this._videoResolution&&(this._videoResolution=s,this.scenes.forEach(({video:t})=>{if(t!=null&&t.hls)if(s===-1)t.hls.nextLevel=-1;else{const i=t.hls.levels.reduce((r,n,o)=>Math.min(n.height,n.width)!==s?r:r===-1||(n.bitrate??0)>(t.hls.levels[r].bitrate??0)?o:r,-1);i!==-1&&(t.hls.nextLevel=i,t.hls.autoLevelCapping=i)}}),s===-1&&((e=this.shadowRoot)!=null&&e.host)&&this._updateHlsLevelCap(this.shadowRoot.host.clientWidth,this.shadowRoot.host.clientHeight),this.requestUpdate())}get videoResolution(){return this._videoResolution}set currentTime(s){s!==this._drawController.currentTime&&(this._drawController.currentTime=s,this._sceneController.setVideosCurrentTime(s))}get currentTime(){return this._drawController.currentTime}_updateHlsLevelCap(s,e,t=!1){if(s<=0||e<=0||this._videoResolution!==-1)return;const i=window.devicePixelRatio||1,r=Math.min(s,e)*i;this.scenes.forEach(({video:n})=>{if(n!=null&&n.hls&&n.hls.levels.length>0){let o=0;for(let a=n.hls.levels.length-1;a>=0;a--)if(Math.min(n.hls.levels[a].width,n.hls.levels[a].height)<=r){o=a;break}n.hls.autoLevelCapping=o,t&&(n.hls.nextLevel=o)}})}reset(s=0,e=!1){this._lastTimestamp=null,this._lastCurrentTime=null,this._drawController.currentTime=s,this._sceneController.setVideosCurrentTime(s),e?this.play():this.pause()}clear(){this._drawController.clear()}play(){this.paused=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this.duration>0&&this._drawController.currentTime>=this.duration&&this.reset(0,!0),this._loop()}pause(){this._endLoop(),this.paused=!0,this.scenes.forEach(({video:s})=>{s&&s.node.pause()})}draw(s){return this._drawController.draw(s)}setScene(s){var e,t;if((e=this._sceneController)!=null&&e.scenes){const i=(t=this.scenes)==null?void 0:t[s];if(!i){const r=new Ei(`No scene at index: ${s}`);return this.dispatchEvent(new ErrorEvent("error",{composed:!0,bubbles:!0,error:r,message:r.message}))}this.reset(i.start+this._sceneController.scenes.transitionDuration,!this.paused)}}toggleFullscreen(s){s??this.fullscreen?tB():this._playerRef.value&&eB(this._playerRef.value)}_getAnswerIds(){const s=new Set;return this.scenes.forEach(({videoMeta:e})=>{e!=null&&e.id&&s.add(e.id)}),s}_setsEqual(s,e){if(s.size!==e.size)return!1;for(const t of s)if(!e.has(t))return!1;return!0}async _fetchTranslations(s){var e;(e=this._translateAbortController)==null||e.abort();const t=new AbortController;this._translateAbortController=t;const i=this._getAnswerIds();try{const r=await Promise.all(Array.from(i).map(async o=>{try{const a=await uB(o,s,this.translateBaseUrl);return[o,a]}catch{return[o,null]}}));if(t.signal.aborted)return;const n=new Map;for(const[o,a]of r)a&&n.set(o,a);this._translatedCaptions=n,this._translatedAnswerIds=i,this._drawController.refreshCaptions()}catch{}}connectedCallback(){var s;super.connectedCallback(),this.addEventListener("error",this._handleError),this.addEventListener("scenesupdate",this._handleScenesUpdate),document.addEventListener("fullscreenchange",this._handleFullscreenChange),document.addEventListener("webkitfullscreenchange",this._handleFullscreenChange),document.addEventListener("visibilitychange",this._handleVisibilityChange),(s=this.shadowRoot)!=null&&s.host&&(this._observer=new ResizeObserver(this._handleContainerResize),this._observer.observe(this.shadowRoot.host))}willUpdate(s){var e,t;if(s.has("propAspectRatio")&&(this._aspectRatio=this.propAspectRatio),s.has("data")&&s.get("data")!==void 0&&((e=this._translateAbortController)==null||e.abort(),this._translatedCaptions=new Map,this._translatedAnswerIds=new Set,this._drawController.refreshCaptions()),s.has("defaultLanguage")&&this._language===null){(t=this._translateAbortController)==null||t.abort(),this._translatedCaptions=new Map,this._translatedAnswerIds=new Set,this._drawController.refreshCaptions();const i=this.language;this.defaultLanguage!=null&&i!==this.defaultLanguage&&this._fetchTranslations(i)}}updated(s){var e;s.has("propAspectRatio")&&!this.propAspectRatio&&this._handleContainerResize(),this.autoplay&&!this._sceneController.hasPlayed&&!this.processing&&s.get("_processing")&&this.play(),s.has("_processing")&&this.processing&&this.dispatchEvent(new CustomEvent("processing")),s.has("_processing")&&!this.processing&&s.get("_processing")&&(e=this.shadowRoot)!=null&&e.host&&this._updateHlsLevelCap(this.shadowRoot.host.clientWidth,this.shadowRoot.host.clientHeight)}disconnectedCallback(){var s,e;super.disconnectedCallback(),(s=this._translateAbortController)==null||s.abort(),(e=this._observer)==null||e.disconnect(),this.removeEventListener("scenesupdate",this._handleScenesUpdate),document.removeEventListener("fullscreenchange",this._handleFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._handleFullscreenChange),document.removeEventListener("visibilitychange",this._handleVisibilityChange)}_renderStyles(){return this.propAspectRatio?typeof this.propAspectRatio=="number"?ve`
1499
1499
  <style>
1500
1500
  :host {
1501
1501
  aspect-ratio: ${this.propAspectRatio};
@@ -1635,7 +1635,7 @@ Schedule: ${l.map(d=>qi(d))}`),c.length&&this.log(`Removed events ${c}`),this.pl
1635
1635
  top: 0;
1636
1636
  left: 0;
1637
1637
  }
1638
- `],je([V({type:Object})],We.prototype,"data",2),je([V({type:Object})],We.prototype,"template",2),je([V({type:Boolean})],We.prototype,"burnCaptions",2),je([V({type:Boolean})],We.prototype,"debug",2),je([V({type:String})],We.prototype,"src",2),je([V({type:String})],We.prototype,"track",2),je([V({type:String})],We.prototype,"translateBaseUrl",2),je([V({type:String})],We.prototype,"defaultLanguage",2),je([V({type:Array})],We.prototype,"languages",2),je([V({type:Number,attribute:"aspectratio"})],We.prototype,"propAspectRatio",2),je([V({type:String})],We.prototype,"preload",2),je([V({type:Boolean})],We.prototype,"autoplay",2),je([V({type:Boolean})],We.prototype,"loading",2),je([V({type:Array})],We.prototype,"controls",2),je([V({attribute:!1})],We.prototype,"compilation",2),je([V({attribute:!1})],We.prototype,"dataResolver",2),je([rt()],We.prototype,"_pageHidden",2),je([rt()],We.prototype,"_aspectRatio",2),je([rt()],We.prototype,"_processing",2),je([rt()],We.prototype,"_waiting",2),je([rt()],We.prototype,"_errors",2),je([rt()],We.prototype,"_seeking",2),je([rt()],We.prototype,"_language",2),je([rt()],We.prototype,"_translatedCaptions",2),je([rt()],We.prototype,"_captions",2),je([rt()],We.prototype,"_fullscreen",2),We=je([Lt("vmp-legacy-media-player")],We);function qB(s,e,t){function i(r){t.dispatchEvent(new CustomEvent(r.type,r))}return e.addEventListener(s,i),()=>{e.removeEventListener(s,i)}}class jB{constructor(e,t){this._events=[],this._cleanup=[],this._forwardElementRef=St(),this.host=e,this._events=t,e.addController(this)}register(){return bt(this._forwardElementRef)}hostConnected(){requestAnimationFrame(()=>{this._events.forEach(e=>{this._forwardElementRef.value&&this._cleanup.push(qB(e,this._forwardElementRef.value,this.host))})})}hostDisconnected(){this._cleanup.forEach(e=>{e()}),this._cleanup=[]}}const yf="https://d2rxhdlm2q91uk.cloudfront.net",XB="https://d1ix11aj5kfygl.cloudfront.net",zB="https://d157jlwnudd93d.cloudfront.net",vf="https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws.com/dev",ZB="https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging",eQ="https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod",tQ="http://localhost:6060/v2",iQ="https://embed-dev.vouchfor.com/v2",sQ="https://embed-staging.vouchfor.com/v2",rQ="https://embed.vouchfor.com/v2",Bf="https://public-dev.vouchfor.com",nQ="https://public-staging.vouchfor.com",oQ="https://public.vouchfor.com";function Xr(s){if(!["local","dev","staging","prod"].includes(s))throw new Error(`Unknown environment: ${s}`);if(s==="local")return{videoUrl:yf,publicApiUrl:vf,embedApiUrl:tQ,translateApiUrl:Bf};if(s==="dev")return{videoUrl:yf,publicApiUrl:vf,embedApiUrl:iQ,translateApiUrl:Bf};if(s==="staging")return{videoUrl:XB,publicApiUrl:ZB,embedApiUrl:sQ,translateApiUrl:nQ};if(s==="prod")return{videoUrl:zB,publicApiUrl:eQ,embedApiUrl:rQ,translateApiUrl:oQ}}class aQ{constructor(e){this._fetching=!1,this.getVouch=async(t,i,r)=>{var c;const{embedApiUrl:n}=Xr(t),o=Oi(),a=await fetch(`${n}/vouches/${r}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",o]]}),l=await a.json();return this.host.dispatchEvent(new CustomEvent("vouch:loaded",{detail:l==null?void 0:l.id})),((c=a==null?void 0:a.headers)==null?void 0:c.get("X-Cache-Check"))!==o&&fetch(`${n}/vouches/${r}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),l},this.getTemplate=async(t,i,r)=>{var c;const{embedApiUrl:n}=Xr(t),o=Oi(),a=await fetch(`${n}/templates/${r}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",o]]}),l=await a.json();return((c=a==null?void 0:a.headers)==null?void 0:c.get("X-Cache-Check"))!==o&&fetch(`${n}/templates/${r}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),l},this.host=e,new Pn(this.host,async([t,i,r,n,o])=>{var a,l,A,c;try{if(e.vouch=void 0,e.template=void 0,r){let h;o&&(this.fetching=!0,h=await this.getTemplate(t,i,o)),this._vouch=r,e.template=h??((l=(a=r==null?void 0:r.settings)==null?void 0:a.template)==null?void 0:l.instance)}else if(n){this.fetching=!0;const[h,u]=await Promise.all([this.getVouch(t,i,n),o?this.getTemplate(t,i,o):null]);this._vouch=h,e.template=u??((c=(A=h==null?void 0:h.settings)==null?void 0:A.template)==null?void 0:c.instance)}}finally{this.fetching=!1}},()=>[e.env,e.apiKey,e.data,e.vouchId,e.templateId]),new Pn(this.host,([t,i])=>{e.vouch=t?{...t,questions:{items:t==null?void 0:t.questions.items.filter((r,n)=>!(i!=null&&i.length)||(i==null?void 0:i.includes(n+1)))}}:void 0},()=>[this._vouch,e.questions])}set fetching(e){this._fetching!==e&&(this._fetching=e,this.host.requestUpdate())}get fetching(){return this._fetching}}const lQ={version:"5.0.1"};function AQ(s){const{publicApiUrl:e}=Xr(s),t=Oi();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function cQ(s){var n,o,a,l,A,c,h,u,d,f,g,p;if(typeof window>"u")return{client:null,tab:null,request:Oi()};let e=(o=(n=window.localStorage)==null?void 0:n.getItem)==null?void 0:o.call(n,"vouch-uid-visitor"),t=(l=(a=window.localStorage)==null?void 0:a.getItem)==null?void 0:l.call(a,"vouch-uid-client"),i=(c=(A=window.sessionStorage)==null?void 0:A.getItem)==null?void 0:c.call(A,"vouch-uid-tab");const r=Oi();return e||(e=AQ(s),(u=(h=window.localStorage)==null?void 0:h.setItem)==null||u.call(h,"vouch-uid-visitor",e)),t||(t=Oi(),(f=(d=window.localStorage)==null?void 0:d.setItem)==null||f.call(d,"vouch-uid-client",t)),i||(i=Oi(),(p=(g=window.sessionStorage)==null?void 0:g.setItem)==null||p.call(g,"vouch-uid-tab",i)),{client:t,tab:i,request:r,visitor:e}}function hQ(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function uQ(s="embedded_player"){var r,n;const[e,t]=((n=(r=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:r.split)==null?void 0:n.call(r,"/"))??[],i={};return[...new URLSearchParams(location.search).entries()].forEach(([o,a])=>{if(/utm/.test(o)){const l=o.toLowerCase().replace(/[-_][a-z0-9]/g,A=>A.slice(-1).toUpperCase());i[l]=a}}),{source:s,time:new Date,region:t,country:e,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,embedType:"media-player-embed",embedVersion:lQ.version,templateVersion:pa,...i}}const Qf=1;class dQ{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=hQ(i,this.host.vouch);!r||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...i,senderId:this.host.senderId,vouchId:r,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=Xr(this.host.env),{client:i,tab:r,request:n,visitor:o}=cQ(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":i,"x-uid-tab":r,"x-uid-request":n,"x-uid-visitor":o,"x-reporting-metadata":uQ(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Qf&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]}},this._handleVouchLoaded=({detail:t})=>{t&&(this._hasLoaded[t]||(this._createTrackingEvent("VOUCH_LOADED",{vouchId:t}),this._hasLoaded[t]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._createTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:t,key:i}})=>{this._answersViewed[i]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:t}),this._answersViewed[i]=!0)},this._handleVideoTimeUpdate=({detail:{id:t,key:i,node:r}})=>{var n,o;!this.host.paused&&t===((o=(n=this.host.scene)==null?void 0:n.video)==null?void 0:o.id)&&(this._currentlyPlayingVideo={id:t,key:i,node:r},this._streamLatestTime[i]=r.currentTime,this._streamStartTime[i]||(this._streamStartTime[i]=r.currentTime,this._streamLatestTime[i]=r.currentTime))},this._handleVideoPause=({detail:{id:t,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+Qf&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]},this._pageUnloading=()=>{this._streamEnded(),this._sendTrackingEvent()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=e,e.addController(this)}hostConnected(){requestAnimationFrame(()=>{var e,t,i,r;"onvisibilitychange"in document?document.addEventListener("visibilitychange",this._handleVisibilityChange):window.addEventListener("pagehide",this._handlePageHide),this.host.addEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.addEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.addEventListener("video:play",this._handleVideoPlay),(i=this.host.mediaPlayer)==null||i.addEventListener("video:pause",this._handleVideoPause),(r=this.host.mediaPlayer)==null||r.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,i,r;this._pageUnloading(),"onvisibilitychange"in document?document.removeEventListener("visibilitychange",this._handleVisibilityChange):window.removeEventListener("pagehide",this._handlePageHide),this.host.removeEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.removeEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.removeEventListener("video:play",this._handleVideoPlay),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:pause",this._handleVideoPause),(r=this.host.mediaPlayer)==null||r.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var fQ=Object.defineProperty,gQ=Object.getOwnPropertyDescriptor,yt=(s,e,t,i)=>{for(var r=i>1?void 0:i?gQ(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(e,t,r):o(r))||r);return i&&r&&fQ(e,t,r),r};let at=class extends Ci{constructor(){super(...arguments),this.env="prod",this.apiKey="",this.disableTracking=!1,this.trackingSource="embedded_player",this.preload="auto",this.autoplay=!1,this.aspectRatio=0,this.eventController=new jB(this,["durationchange","ended","error","loadeddata","pause","stalled","play","playing","ratechange","scenechange","scenesupdate","seeking","seeked","timeupdate","volumechange","processing","waiting","video:loadeddata","video:seeking","video:seeked","video:play","video:playing","video:pause","video:stalled","video:timeupdate","video:ended","video:error"]),this._fetcherController=new aQ(this),this._trackingController=new dQ(this),this._mediaPlayerRef=St()}get fetching(){return this._fetcherController.fetching}get waiting(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.waiting}get initialised(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.initialised}get seeking(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.seeking}get paused(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.paused}get captions(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.captions}get fullscreen(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.fullscreen}get duration(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.duration}set currentTime(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.currentTime=s)}get currentTime(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.currentTime)??0}set playbackRate(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.playbackRate=s)}get playbackRate(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.playbackRate)??1}set volume(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.volume=s)}get volume(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.volume)??1}set muted(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.muted=s)}get muted(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.muted)??!1}get scene(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.scene)??null}get scenes(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.scenes)??[]}get sceneConfig(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.sceneConfig)??null}get videoState(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.videoState}get mediaPlayer(){return this._mediaPlayerRef.value}play(){var s;(s=this._mediaPlayerRef.value)==null||s.play()}pause(){var s;(s=this._mediaPlayerRef.value)==null||s.pause()}reset(s=0,e=!1){var t;(t=this._mediaPlayerRef.value)==null||t.reset(s,e)}setScene(s){var e;(e=this._mediaPlayerRef.value)==null||e.setScene(s)}_renderStyles(){return this.aspectRatio?typeof this.aspectRatio=="number"?ve`
1638
+ `],je([V({type:Object})],We.prototype,"data",2),je([V({type:Object})],We.prototype,"template",2),je([V({type:Boolean})],We.prototype,"burnCaptions",2),je([V({type:Boolean})],We.prototype,"debug",2),je([V({type:String})],We.prototype,"src",2),je([V({type:String})],We.prototype,"track",2),je([V({type:String})],We.prototype,"translateBaseUrl",2),je([V({type:String})],We.prototype,"defaultLanguage",2),je([V({type:Array})],We.prototype,"languages",2),je([V({type:Number,attribute:"aspectratio"})],We.prototype,"propAspectRatio",2),je([V({type:String})],We.prototype,"preload",2),je([V({type:Boolean})],We.prototype,"autoplay",2),je([V({type:Boolean})],We.prototype,"loading",2),je([V({type:Array})],We.prototype,"controls",2),je([V({attribute:!1})],We.prototype,"compilation",2),je([V({attribute:!1})],We.prototype,"dataResolver",2),je([rt()],We.prototype,"_pageHidden",2),je([rt()],We.prototype,"_aspectRatio",2),je([rt()],We.prototype,"_processing",2),je([rt()],We.prototype,"_waiting",2),je([rt()],We.prototype,"_errors",2),je([rt()],We.prototype,"_seeking",2),je([rt()],We.prototype,"_language",2),je([rt()],We.prototype,"_translatedCaptions",2),je([rt()],We.prototype,"_captions",2),je([rt()],We.prototype,"_fullscreen",2),We=je([Lt("vmp-legacy-media-player")],We);function qB(s,e,t){function i(r){t.dispatchEvent(new CustomEvent(r.type,r))}return e.addEventListener(s,i),()=>{e.removeEventListener(s,i)}}class jB{constructor(e,t){this._events=[],this._cleanup=[],this._forwardElementRef=St(),this.host=e,this._events=t,e.addController(this)}register(){return bt(this._forwardElementRef)}hostConnected(){requestAnimationFrame(()=>{this._events.forEach(e=>{this._forwardElementRef.value&&this._cleanup.push(qB(e,this._forwardElementRef.value,this.host))})})}hostDisconnected(){this._cleanup.forEach(e=>{e()}),this._cleanup=[]}}const yf="https://d2rxhdlm2q91uk.cloudfront.net",XB="https://d1ix11aj5kfygl.cloudfront.net",zB="https://d157jlwnudd93d.cloudfront.net",vf="https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws.com/dev",ZB="https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging",eQ="https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod",tQ="http://localhost:6060/v2",iQ="https://embed-dev.vouchfor.com/v2",sQ="https://embed-staging.vouchfor.com/v2",rQ="https://embed.vouchfor.com/v2",Bf="https://public-dev.vouchfor.com",nQ="https://public-staging.vouchfor.com",oQ="https://public.vouchfor.com";function Xr(s){if(!["local","dev","staging","prod"].includes(s))throw new Error(`Unknown environment: ${s}`);if(s==="local")return{videoUrl:yf,publicApiUrl:vf,embedApiUrl:tQ,translateApiUrl:Bf};if(s==="dev")return{videoUrl:yf,publicApiUrl:vf,embedApiUrl:iQ,translateApiUrl:Bf};if(s==="staging")return{videoUrl:XB,publicApiUrl:ZB,embedApiUrl:sQ,translateApiUrl:nQ};if(s==="prod")return{videoUrl:zB,publicApiUrl:eQ,embedApiUrl:rQ,translateApiUrl:oQ}}class aQ{constructor(e){this._fetching=!1,this.getVouch=async(t,i,r)=>{var c;const{embedApiUrl:n}=Xr(t),o=Oi(),a=await fetch(`${n}/vouches/${r}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",o]]}),l=await a.json();return this.host.dispatchEvent(new CustomEvent("vouch:loaded",{detail:l==null?void 0:l.id})),((c=a==null?void 0:a.headers)==null?void 0:c.get("X-Cache-Check"))!==o&&fetch(`${n}/vouches/${r}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),l},this.getTemplate=async(t,i,r)=>{var c;const{embedApiUrl:n}=Xr(t),o=Oi(),a=await fetch(`${n}/templates/${r}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",o]]}),l=await a.json();return((c=a==null?void 0:a.headers)==null?void 0:c.get("X-Cache-Check"))!==o&&fetch(`${n}/templates/${r}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),l},this.host=e,new Pn(this.host,async([t,i,r,n,o])=>{var a,l,A,c;try{if(e.vouch=void 0,e.template=void 0,r){let h;o&&(this.fetching=!0,h=await this.getTemplate(t,i,o)),this._vouch=r,e.template=h??((l=(a=r==null?void 0:r.settings)==null?void 0:a.template)==null?void 0:l.instance)}else if(n){this.fetching=!0;const[h,u]=await Promise.all([this.getVouch(t,i,n),o?this.getTemplate(t,i,o):null]);this._vouch=h,e.template=u??((c=(A=h==null?void 0:h.settings)==null?void 0:A.template)==null?void 0:c.instance)}}finally{this.fetching=!1}},()=>[e.env,e.apiKey,e.data,e.vouchId,e.templateId]),new Pn(this.host,([t,i])=>{e.vouch=t?{...t,questions:{items:t==null?void 0:t.questions.items.filter((r,n)=>!(i!=null&&i.length)||(i==null?void 0:i.includes(n+1)))}}:void 0},()=>[this._vouch,e.questions])}set fetching(e){this._fetching!==e&&(this._fetching=e,this.host.requestUpdate())}get fetching(){return this._fetching}}const lQ={version:"5.0.2"};function AQ(s){const{publicApiUrl:e}=Xr(s),t=Oi();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function cQ(s){var n,o,a,l,A,c,h,u,d,f,g,p;if(typeof window>"u")return{client:null,tab:null,request:Oi()};let e=(o=(n=window.localStorage)==null?void 0:n.getItem)==null?void 0:o.call(n,"vouch-uid-visitor"),t=(l=(a=window.localStorage)==null?void 0:a.getItem)==null?void 0:l.call(a,"vouch-uid-client"),i=(c=(A=window.sessionStorage)==null?void 0:A.getItem)==null?void 0:c.call(A,"vouch-uid-tab");const r=Oi();return e||(e=AQ(s),(u=(h=window.localStorage)==null?void 0:h.setItem)==null||u.call(h,"vouch-uid-visitor",e)),t||(t=Oi(),(f=(d=window.localStorage)==null?void 0:d.setItem)==null||f.call(d,"vouch-uid-client",t)),i||(i=Oi(),(p=(g=window.sessionStorage)==null?void 0:g.setItem)==null||p.call(g,"vouch-uid-tab",i)),{client:t,tab:i,request:r,visitor:e}}function hQ(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function uQ(s="embedded_player"){var r,n;const[e,t]=((n=(r=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:r.split)==null?void 0:n.call(r,"/"))??[],i={};return[...new URLSearchParams(location.search).entries()].forEach(([o,a])=>{if(/utm/.test(o)){const l=o.toLowerCase().replace(/[-_][a-z0-9]/g,A=>A.slice(-1).toUpperCase());i[l]=a}}),{source:s,time:new Date,region:t,country:e,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,embedType:"media-player-embed",embedVersion:lQ.version,templateVersion:pa,...i}}const Qf=1;class dQ{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=hQ(i,this.host.vouch);!r||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...i,senderId:this.host.senderId,vouchId:r,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=Xr(this.host.env),{client:i,tab:r,request:n,visitor:o}=cQ(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":i,"x-uid-tab":r,"x-uid-request":n,"x-uid-visitor":o,"x-reporting-metadata":uQ(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Qf&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]}},this._handleVouchLoaded=({detail:t})=>{t&&(this._hasLoaded[t]||(this._createTrackingEvent("VOUCH_LOADED",{vouchId:t}),this._hasLoaded[t]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._createTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:t,key:i}})=>{this._answersViewed[i]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:t}),this._answersViewed[i]=!0)},this._handleVideoTimeUpdate=({detail:{id:t,key:i,node:r}})=>{var n,o;!this.host.paused&&t===((o=(n=this.host.scene)==null?void 0:n.video)==null?void 0:o.id)&&(this._currentlyPlayingVideo={id:t,key:i,node:r},this._streamLatestTime[i]=r.currentTime,this._streamStartTime[i]||(this._streamStartTime[i]=r.currentTime,this._streamLatestTime[i]=r.currentTime))},this._handleVideoPause=({detail:{id:t,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+Qf&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]},this._pageUnloading=()=>{this._streamEnded(),this._sendTrackingEvent()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=e,e.addController(this)}hostConnected(){requestAnimationFrame(()=>{var e,t,i,r;"onvisibilitychange"in document?document.addEventListener("visibilitychange",this._handleVisibilityChange):window.addEventListener("pagehide",this._handlePageHide),this.host.addEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.addEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.addEventListener("video:play",this._handleVideoPlay),(i=this.host.mediaPlayer)==null||i.addEventListener("video:pause",this._handleVideoPause),(r=this.host.mediaPlayer)==null||r.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,i,r;this._pageUnloading(),"onvisibilitychange"in document?document.removeEventListener("visibilitychange",this._handleVisibilityChange):window.removeEventListener("pagehide",this._handlePageHide),this.host.removeEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.removeEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.removeEventListener("video:play",this._handleVideoPlay),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:pause",this._handleVideoPause),(r=this.host.mediaPlayer)==null||r.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var fQ=Object.defineProperty,gQ=Object.getOwnPropertyDescriptor,yt=(s,e,t,i)=>{for(var r=i>1?void 0:i?gQ(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(e,t,r):o(r))||r);return i&&r&&fQ(e,t,r),r};let at=class extends Ci{constructor(){super(...arguments),this.env="prod",this.apiKey="",this.disableTracking=!1,this.trackingSource="embedded_player",this.preload="auto",this.autoplay=!1,this.aspectRatio=0,this.eventController=new jB(this,["durationchange","ended","error","loadeddata","pause","stalled","play","playing","ratechange","scenechange","scenesupdate","seeking","seeked","timeupdate","volumechange","processing","waiting","video:loadeddata","video:seeking","video:seeked","video:play","video:playing","video:pause","video:stalled","video:timeupdate","video:ended","video:error"]),this._fetcherController=new aQ(this),this._trackingController=new dQ(this),this._mediaPlayerRef=St()}get fetching(){return this._fetcherController.fetching}get waiting(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.waiting}get initialised(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.initialised}get seeking(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.seeking}get paused(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.paused}get captions(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.captions}get fullscreen(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.fullscreen}get duration(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.duration}set currentTime(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.currentTime=s)}get currentTime(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.currentTime)??0}set playbackRate(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.playbackRate=s)}get playbackRate(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.playbackRate)??1}set volume(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.volume=s)}get volume(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.volume)??1}set muted(s){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.muted=s)}get muted(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.muted)??!1}get scene(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.scene)??null}get scenes(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.scenes)??[]}get sceneConfig(){var s;return((s=this._mediaPlayerRef.value)==null?void 0:s.sceneConfig)??null}get videoState(){var s;return(s=this._mediaPlayerRef.value)==null?void 0:s.videoState}get mediaPlayer(){return this._mediaPlayerRef.value}play(){var s;(s=this._mediaPlayerRef.value)==null||s.play()}pause(){var s;(s=this._mediaPlayerRef.value)==null||s.pause()}reset(s=0,e=!1){var t;(t=this._mediaPlayerRef.value)==null||t.reset(s,e)}setScene(s){var e;(e=this._mediaPlayerRef.value)==null||e.setScene(s)}_renderStyles(){return this.aspectRatio?typeof this.aspectRatio=="number"?ve`
1639
1639
  <style>
1640
1640
  :host {
1641
1641
  aspect-ratio: ${this.aspectRatio};