text: (()=>{"use strict";class t{constructor(t){if(this.artStackElement=t,!this.artStackElement)throw new Error("ArtStack::Constructor - DOM element with class 'art-stack' could not be found.")}set artwork(t){this.appendImage(t),1===this.artStackElement.children.length?this.fadeInImage(0):Promise.all([this.fadeOutImage(0),this.fadeInImage(1)]).then((()=>{const t=this.artStackElement.children[0];this.artStackElement.removeChild(t)}))}appendImage(t){const e=document.createElement("img");e.classList.add("art"),e.classList.add("transparent"),e.src=t,this.artStackElement.appendChild(e),this.requestBrowserAnimation(e)}fadeInImage(t){if(this.artStackElement.children.length<=t)throw new Error(`ArtStack::fadeInImage - Parameter 'index' with value '${t}' is out of bounds.`);const e=this.artStackElement.children[t];return new Promise((t=>{const r=s=>{"opacity"===s.propertyName&&(e.removeEventListener("transitionend",r),t())};e.addEventListener("transitionend",r),e.classList.remove("transparent")}))}fadeOutImage(t){if(this.artStackElement.children.length<=t)throw new Error(`ArtStack::fadeOutImage - Parameter 'index' with value '${t}' is out of bounds.`);const e=this.artStackElement.children[t];return new Promise((t=>{const r=s=>{"opacity"===s.propertyName&&(e.removeEventListener("transitionend",r),t())};e.addEventListener("transitionend",r),e.classList.add("transparent")}))}requestBrowserAnimation(t){t.offsetWidth}}class e{constructor(t){this.album=t?.album?.["#text"],this.artist=t?.artist?.["#text"],this.nowPlaying=!!t?.["@attr"]?.nowplaying,this.title=t?.name;const e=t?.image;Array.isArray(e)?(this.albumArtSmall=e.find((t=>"small"===t?.size))?.["#text"],this.albumArtMedium=e.find((t=>"medium"===t?.size))?.["#text"],this.albumArtLarge=e.find((t=>"large"===t?.size))?.["#text"],this.albumArtExtraLarge=e.find((t=>"extralarge"===t?.size))?.["#text"]):(this.albumArtSmall=null,this.albumArtMedium=null,this.albumArtLarge=null,this.albumArtExtraLarge=null)}equals(t){return!!t&&this.album===t.album&&this.artist===t.artist&&this.title===t.title}}class r{constructor(t){if(this.apiKey=t,!this.apiKey)throw new Error("LastFmService::Constructor - Parameter 'apiKey' was not provided. An API key must be provided.")}async getMostRecentTrack(t){return this.getRecentTracks(t,1).then((t=>t&&t.length>0?t[0]:null))}async getRecentTracks(t,r){if(!t)throw new Error("LastFmService::getRecentTracks - Parameter 'user' cannot be null or undefined.");if(r<1||r>200)throw new Error("LastFmService::getRecentTracks - Parameter 'limit' must be a positive integer with a maximum value of 200.");const s=`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${t}&limit=${r}&api_key=${this.apiKey}&format=json`;return fetch(s,{mode:"cors",headers:{"Content-Type":"application/json",SameSite:"Strict"}}).then((t=>t.json())).then((t=>{const r=t?.recenttracks?.track,s=[];return r.forEach((t=>s.push(new e(t)))),s}))}}class s{constructor(e){if(!e)throw new Error("NowPlayingWidget::Constructor - Parameter 'options was not provided. Options must be provided.");if(!e.lastFmUsername)throw new Error("NowPlayingWidget::Constructor -  Options value for 'lastFmUsername' was not provided. A valid username must be provided.");if(e.apiPollFrequency<1e4)throw new Error("NowPlayingWidget::Constructor - Options value for 'apiPollFrequency' cannot be less than 10 seconds.");this.user=e.lastFmUsername,this.apiPollFrequency=e.apiPollFrequency,this.showAlbum=e.showAlbum,this.showArtist=e.showArtist,this.showTitle=e.showTitle,this.lastFmService=new r(e.lastFmApiKey),this.artStack=new t(document.querySelector(".art-stack")),this.albumElement=document.querySelector(".album"),this.artistElement=document.querySelector(".artist"),this.titleElement=document.querySelector(".title"),this.removeUnusedDomElements()}set album(t){this.albumElement.innerText=t}set artist(t){this.artistElement.innerText=t}set title(t){this.titleElement.innerText=t}checkNowPlaying(){this.lastFmService.getMostRecentTrack(this.user).then((t=>{const e=t.equals(this.currentTrack);if(t.nowPlaying&&!e){const e=!!this.currentTrack&&t.album===this.currentTrack.album;this.currentTrack=t,e?this.updateCurrentTrackInformation(this.currentTrack):this.updateCurrentTrack(this.currentTrack)}})).finally((()=>{setTimeout((()=>this.checkNowPlaying()),this.apiPollFrequency)}))}start(){this.checkNowPlaying()}removeUnusedDomElements(){this.showAlbum||this.albumElement.remove(),this.showArtist||this.artistElement.remove(),this.showTitle||this.titleElement.remove()}updateCurrentTrack(t){this.updateCurrentTrackArtwork(t),this.updateCurrentTrackInformation(t)}updateCurrentTrackArtwork(t){this.artStack.artwork=t.albumArtExtraLarge}updateCurrentTrackInformation(t){this.showAlbum&&(this.album=t.album),this.showArtist&&(this.artist=t.artist),this.showTitle&&(this.title=t.title)}}let a;window.addEventListener("onWidgetLoad",(function(t){const e=t.detail.fieldData,r=e.lastFmApiKey,i=e.lastFmUsername,n=class{static toMilliseconds(t){return 1e3*t}static toSeconds(t){return t/1e3}}.toMilliseconds(e.lastFmApiPollFrequency),o="true"===e.showAlbum,l="true"===e.showArtist,c="true"===e.showTitle;a=new s({apiPollFrequency:n,lastFmApiKey:r,lastFmUsername:i,showAlbum:o,showArtist:l,showTitle:c}),a.start()}))})();