diff --git a/src/components/playing/NowPlaying.astro b/src/components/playing/NowPlaying.astro index 7d15c2e..6229d16 100644 --- a/src/components/playing/NowPlaying.astro +++ b/src/components/playing/NowPlaying.astro @@ -348,12 +348,11 @@ const dataTrack = ( } now-playing { - [slot="art"] { + & img { mask-image: var(--small-box-mask-png); mask-size: contain; } - - a { + & a { color: black; &:focus, @@ -372,49 +371,51 @@ const dataTrack = ( import { type nowPlaying, isNowPlaying } from "./spotify/client"; class HTMLNowPlayingElement extends HTMLElement { - internals = this.attachInternals(); + internals = this.attachInternals(); - elements = { - // typecast bc checked in constructor - title: this.querySelector("[slot=title]") as HTMLAnchorElement, - album: this.querySelector("[slot=album]") as HTMLSpanElement, - artists: this.querySelector("[slot=artists]") as HTMLSpanElement, - art: this.querySelector("[slot=art]") as HTMLImageElement, - } as const; + elements = { + // typecast bc checked in constructor + title: this.querySelector("[slot=title]") as HTMLAnchorElement, + album: this.querySelector("[slot=album]") as HTMLSpanElement, + artists: this.querySelector("[slot=artists]") as HTMLSpanElement, + art: this.querySelector("[slot=art]") as HTMLImageElement, + } as const; - constructor() { - super(); + constructor() { + super(); - if (!(this.elements.title instanceof HTMLAnchorElement)) - throw new Error("[slot=title] not defined or wrong type"); + if (!(this.elements.title instanceof HTMLAnchorElement)) + throw new Error("[slot=title] not defined or wrong type"); - if (!(this.elements.album instanceof HTMLSpanElement)) - throw new Error("[slot=album] not defined or wrong type"); + if (!(this.elements.album instanceof HTMLSpanElement)) + throw new Error("[slot=album] not defined or wrong type"); - if (!(this.elements.artists instanceof HTMLSpanElement)) - throw new Error("[slot=artists] not defined or wrong type"); + if (!(this.elements.artists instanceof HTMLSpanElement)) + throw new Error("[slot=artists] not defined or wrong type"); - if (!(this.elements.art instanceof HTMLImageElement)) - throw new Error("[slot=art] not defined or wrong type"); - } + if (!(this.elements.art instanceof HTMLImageElement)) + throw new Error("[slot=art] not defined or wrong type"); + } - updateMetadata(metadata: Exclude) { - this.elements.title.innerText = metadata.name; - this.elements.title.href = metadata.external_urls.spotify; + updateMetadata(metadata: Exclude) { + this.elements.title.innerText = metadata.name; + this.elements.title.href = metadata.external_urls.spotify; - this.elements.album.innerText = metadata.album.name; + this.elements.album.innerText = metadata.album.name; - this.elements.artists.innerText = ""; - this.elements.artists.append(...metadata.artists.flatMap((artist, i) => { + this.elements.artists.innerText = ""; + this.elements.artists.append( + ...metadata.artists.flatMap((artist, i) => { const a = document.createElement("a"); a.innerText = artist.name; a.href = artist.external_urls.spotify; return i === 0 ? a : [", ", a]; - })); + }), + ); - this.elements.art.src = metadata.album.images[0].url - } + this.elements.art.src = metadata.album.images[0].url; } + } const nowPlayingEl = document.getElementById("now-playing"); if (!nowPlayingEl) throw new Error("Could not find #now-playing"); @@ -423,14 +424,13 @@ const dataTrack = ( throw new Error("Could not find #now-playing img.art"); const nowPlayings = document.querySelectorAll("now-playing"); - customElements.define( - "now-playing", - HTMLNowPlayingElement, - ); + customElements.define("now-playing", HTMLNowPlayingElement); const renderNowPlaying = (playing: Exclude) => { art.src = playing.album.images[0].url; - nowPlayings.forEach(el => el instanceof HTMLNowPlayingElement && el.updateMetadata(playing)) + nowPlayings.forEach( + (el) => el instanceof HTMLNowPlayingElement && el.updateMetadata(playing), + ); }; const renderSilent = () => {