commit
Updates
diff --git a/src/lib/components/Hamburger.svelte b/src/lib/components/Hamburger.svelte
index 2defbf7..bc948ce 100644
--- a/src/lib/components/Hamburger.svelte
+++ b/src/lib/components/Hamburger.svelte
@@ -20,7 +20,6 @@
{ href: '/specs', label: 'Specs' },
{ href: '/projects', label: 'Projects' },
{ href: '/discord', label: 'Discord' },
- { href: '/music', label: 'Music' },
{ href: '/friends', label: 'Friends' },
{ href: '/88x31', label: '88x31' },
{ href: '/guestbook', label: 'Guestbook' },
diff --git a/src/lib/components/NowPlaying.svelte b/src/lib/components/NowPlaying.svelte
index aea3022..16f7453 100644
--- a/src/lib/components/NowPlaying.svelte
+++ b/src/lib/components/NowPlaying.svelte
@@ -3,76 +3,213 @@
-->
<script lang="ts">
+ import IcClose from '~icons/ic/outline-close';
+ import IcMusicNote from '~icons/ic/outline-music-note';
import '#lib/styles/nowplaying.css';
import { page } from '$app/state';
import { resolve } from '$app/paths';
+ import { untrack } from 'svelte';
import { fly } from 'svelte/transition';
+ import LyricWords from '#lib/components/LyricWords.svelte';
import { STATUS_LABEL, clamp, subscribePresence, type Presence } from '#lib/scripts/discord.ts';
- import { trackFromPresence } from '#lib/scripts/music.ts';
+ import {
+ artTint,
+ fetchLyrics,
+ trackFromPresence,
+ trackKey,
+ type Lyrics
+ } from '#lib/scripts/music.ts';
import { discordId } from '#lib';
- // These pages already show all of this in full
- const HIDDEN_ON = ['/', '/music', '/discord'];
+ // The Discord page already shows the status in full
+ const STATUS_HIDDEN_ON = ['/discord'];
+ const COLLAPSED_KEY = 'dough:nowplaying:collapsed';
+ const SPOTIFY_SEARCH = 'https://open.spotify.com/search/';
let presence = $state<Presence | null>(null);
let now = $state(Date.now());
+ let lyrics = $state<Lyrics | null>(null);
+ let tint = $state<string | null>(null);
let reduceMotion = $state(false);
+ // The visitor tucked it away; remembered between visits
+ let collapsed = $state(false);
+
+ let lyricsRequest = 0;
+ let tintRequest = 0;
// The socket is already open for the whole visit (hooks.client.ts)
$effect(() => {
reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
+ try {
+ collapsed = localStorage.getItem(COLLAPSED_KEY) === '1';
+ } catch {
+ // Storage unavailable, so it just starts open
+ }
return subscribePresence([discordId], (p) => (presence = p));
});
+ function setCollapsed(value: boolean) {
+ collapsed = value;
+ try {
+ if (value) localStorage.setItem(COLLAPSED_KEY, '1');
+ else localStorage.removeItem(COLLAPSED_KEY);
+ } catch {
+ // Storage unavailable, so it only lasts for this visit
+ }
+ }
+
const track = $derived(trackFromPresence(presence));
const status = $derived(presence ? (presence.streaming ? 'streaming' : presence.status) : null);
const customStatus = $derived(presence?.custom_status?.text ?? '');
+ const key = $derived(trackKey(track));
+ const art = $derived(track?.art ?? '');
+
+ // Straight to the song when Spotify gave an id, otherwise a search for it
+ const songUrl = $derived(
+ track
+ ? track.url || SPOTIFY_SEARCH + encodeURIComponent(`${track.song} ${track.artist}`.trim())
+ : ''
+ );
+
+ // Only reload lyrics when the song itself changes, not on every presence update.
+ // Nothing is fetched while it's tucked away
+ $effect(() => {
+ const request = ++lyricsRequest;
+ const current = untrack(() => track);
+ lyrics = null;
+ if (!key || !current || collapsed) return;
+ fetchLyrics(current).then((found) => {
+ if (request === lyricsRequest) lyrics = found;
+ });
+ });
+
+ // Borrow a colour from the cover. The old tint stays until the new one is known
+ $effect(() => {
+ const request = ++tintRequest;
+ if (!art) {
+ tint = null;
+ return;
+ }
+ artTint(art).then((found) => {
+ if (request === tintRequest) tint = found;
+ });
+ });
+
+ // Lyrics can only follow a song that says where it started and ends
+ const synced = $derived(lyrics?.kind === 'synced' && track?.start && track.end ? lyrics : null);
- // Only tick while there's a progress bar to move
+ // Tick each second for the progress bar, faster while a lyric line is following
$effect(() => {
- if (!track?.duration) return;
- const tick = setInterval(() => (now = Date.now()), 1000);
+ if (!track?.duration || collapsed) return;
+ const wordSynced = synced?.lines.some((lyricLine) => lyricLine.words);
+ const ms = wordSynced ? 100 : synced ? 250 : 1000;
+ const tick = setInterval(() => (now = Date.now()), ms);
return () => clearInterval(tick);
});
- const progress = $derived(
- track?.start && track.duration ? clamp((now - track.start) / track.duration, 0, 1) : 0
+ const position = $derived(track?.start ? clamp(now - track.start, 0, track.duration) : 0);
+ const progress = $derived(track?.duration ? position / track.duration : 0);
+
+ const activeLine = $derived(
+ synced ? synced.lines.findLastIndex((lyricLine) => lyricLine.t <= position) : -1
);
- const hidden = $derived(HIDDEN_ON.includes(page.url.pathname));
+ const line = $derived(synced && activeLine >= 0 ? synced.lines[activeLine] : null);
+
+ // Shown in the lyric's place, so the card keeps its size whatever the song has
+ const lyricNote = $derived.by(() => {
+ if (!lyrics) return 'Finding lyrics…';
+ if (lyrics.kind === 'instrumental') return 'Instrumental';
+ if (lyrics.kind === 'synced' || lyrics.kind === 'plain') return 'Lyrics are not synced';
+ return 'No lyrics for this song';
+ });
+
+ const statusShown = $derived(status && !STATUS_HIDDEN_ON.includes(page.url.pathname));
const flyIn = $derived({ y: -8, duration: reduceMotion ? 0 : 250 });
+ const lyricMs = $derived(reduceMotion ? 0 : 350);
</script>
-{#if !hidden && track}
- <a
- class="now-playing"
- href={resolve('/music')}
- title="Listening to {track.song}{track.artist ? ` by ${track.artist}` : ''}"
- transition:fly={flyIn}
+{#snippet hideButton()}
+ <button
+ class="pill-hide"
+ type="button"
+ title="Hide"
+ aria-label="Hide what Clove is listening to"
+ onclick={() => setCollapsed(true)}
>
- {#if track.art}
- <img class="np-art" src={track.art} alt="" width="28" height="28" />
- {/if}
- <span class="np-text">
- <strong>{track.song}</strong>{#if track.artist}<span class="np-muted"
- > — {track.artist}</span
- >{/if}
- </span>
- <span class="np-eq" aria-hidden="true"><i></i><i></i><i></i></span>
+ <IcClose />
+ </button>
+{/snippet}
+
+{#if collapsed}
+ {#if track || statusShown}
+ <button
+ class="now-playing pill-collapsed"
+ type="button"
+ title={track ? 'Show what Clove is listening to' : 'Show Discord status'}
+ aria-label={track ? 'Show what Clove is listening to' : 'Show Discord status'}
+ style:--accent={tint}
+ onclick={() => setCollapsed(false)}
+ transition:fly={flyIn}
+ >
+ <IcMusicNote />
+ </button>
+ {/if}
+{:else if track}
+ <div class="now-playing pill-song" style:--accent={tint} transition:fly={flyIn}>
+ <!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- always an external Spotify link -->
+ <a
+ class="pill-link"
+ href={songUrl}
+ target="_blank"
+ rel="noopener external"
+ title="{track.song}{track.artist ? ` by ${track.artist}` : ''}, open on Spotify"
+ >
+ <span class="pill-row">
+ {#if track.art}
+ <img class="pill-art" src={track.art} alt="" width="28" height="28" />
+ {/if}
+ <span class="pill-text">
+ <strong>{track.song}</strong>{#if track.artist}<span class="pill-muted"
+ > — {track.artist}</span
+ >{/if}
+ </span>
+ <span class="pill-eq" aria-hidden="true"><i></i><i></i><i></i></span>
+ </span>
+ <!-- Lines share one grid cell so the old and new line can overlap while they fly -->
+ <span class="pill-lyric">
+ {#if synced}
+ {#key activeLine}
+ <span
+ class="pill-lyric-line"
+ class:pill-lyric-gap={!line?.text}
+ in:fly={{ y: 10, duration: lyricMs, delay: lyricMs / 3 }}
+ out:fly={{ y: -10, duration: lyricMs }}
+ >{#if line?.words}<LyricWords words={line.words} at={position} />{:else}{line?.text ||
+ '♪'}{/if}</span
+ >
+ {/key}
+ {:else}
+ <span class="pill-lyric-line pill-lyric-note">{lyricNote}</span>
+ {/if}
+ </span>
+ </a>
+ {@render hideButton()}
{#if track.duration}
- <span class="np-progress" style:--progress={progress} aria-hidden="true"></span>
+ <span class="pill-progress" style:--progress={progress} aria-hidden="true"></span>
{/if}
- </a>
-{:else if !hidden && status}
- <a
- class="now-playing"
- href={resolve('/discord')}
- data-status={status}
- title="{STATUS_LABEL[status]} on Discord"
- transition:fly={flyIn}
- >
- <span class="np-dot" aria-hidden="true"></span>
- <span class="np-text">
- {STATUS_LABEL[status]}{#if customStatus}<span class="np-muted"> · {customStatus}</span>{/if}
- </span>
- </a>
+ </div>
+{:else if statusShown && status}
+ <div class="now-playing" data-status={status} transition:fly={flyIn}>
+ <a class="pill-link" href={resolve('/discord')} title="{STATUS_LABEL[status]} on Discord">
+ <span class="pill-row">
+ <span class="pill-dot" aria-hidden="true"></span>
+ <span class="pill-text">
+ {STATUS_LABEL[status]}{#if customStatus}<span class="pill-muted">
+ · {customStatus}</span
+ >{/if}
+ </span>
+ </span>
+ </a>
+ {@render hideButton()}
+ </div>
{/if}
diff --git a/src/lib/index.ts b/src/lib/index.ts
index 9243734..e5685b7 100644
--- a/src/lib/index.ts
+++ b/src/lib/index.ts
@@ -46,14 +46,4 @@ export const youtubeUrl = 'https://www.youtube.com/@CloveTwiGaming';
// Music
-export const lfmApi = 'https://ws.audioscrobbler.com/2.0/';
-
-export const lfmUser = 'Real_AlexTLM';
-
-export const lmfKey = '768e8bd0d366f4d6c7874740ca6610ad';
-
-export const lfmPlaceholder = '2a96cbd8b46e442fc41c2b86b821562f';
-
export const lrcLibHosts = [`https://lyrics.${websiteDomain}`, 'https://lrclib.net'];
-
-export const tadbApi = 'https://www.theaudiodb.com/api/v1/json/123';
diff --git a/src/lib/scripts/music.ts b/src/lib/scripts/music.ts
index b3dce67..7e140d8 100644
--- a/src/lib/scripts/music.ts
+++ b/src/lib/scripts/music.ts
@@ -2,24 +2,11 @@
* DASL-1.2 — (c) Clove Twilight
*/
-// Music page: Last.fm scrobbles, LRCLIB lyrics and TheAudioDB artist images
+// Live track from Discord presence and its LRCLIB lyrics
import { pickListening, type Presence } from '#lib/scripts/discord.ts';
-import { cached } from '#lib/scripts/cache.ts';
-
-import {
- lfmApi,
- lfmUser,
- lmfKey,
- lfmPlaceholder,
- lrcLibHosts,
- tadbApi,
- websiteDomain,
- websiteUrl
-} from '#lib';
-
-const ART_CACHE_PREFIX = 'dough:artimg:';
-const DAY = 86_400_000;
+
+import { lrcLibHosts, websiteDomain, websiteUrl } from '#lib';
export interface Track {
song: string;
@@ -31,8 +18,8 @@ export interface Track {
end: number | null;
duration: number;
live: boolean;
- // Which app a live track is playing in; null for Last.fm scrobbles
- source: 'doughmination' | 'spotify' | null;
+ // Which app the track is playing in
+ source: 'doughmination' | 'spotify';
}
export interface LyricWord {
@@ -55,97 +42,6 @@ export type Lyrics =
| { kind: 'synced'; lines: LyricLine[] }
| { kind: 'plain'; lines: string[] };
-export interface Scrobble {
- name: string;
- artist: string;
- album: string;
- url: string;
- art: string;
- playing: boolean;
- uts: number | null;
-}
-
-export interface TopArtist {
- name: string;
- url: string;
- plays: number;
-}
-
-// ---- Last.fm --------------------------------------------------------------
-
-interface LfmImage {
- '#text'?: string;
-}
-
-interface LfmTrack {
- name: string;
- url?: string;
- artist?: { '#text'?: string; name?: string };
- album?: { '#text'?: string };
- image?: LfmImage[];
- date?: { uts: string };
- '@attr'?: { nowplaying?: string };
-}
-
-async function lastfm<T>(method: string, params: Record<string, string> = {}): Promise<T> {
- const qs = new URLSearchParams({
- method,
- user: lfmUser,
- api_key: lmfKey,
- format: 'json',
- ...params
- });
- const res = await fetch(`${lfmApi}?${qs}`);
- if (!res.ok) throw new Error(`Last.fm ${res.status}`);
- return (await res.json()) as T;
-}
-
-function lfmArt(images: LfmImage[] | undefined): string {
- const url = images?.at(-1)?.['#text'] ?? '';
- return url.includes(lfmPlaceholder) ? '' : url;
-}
-
-// Last.fm sends a bare object instead of an array when there's only one item
-function asArray<T>(x: T | T[] | undefined): T[] {
- return x === undefined ? [] : Array.isArray(x) ? x : [x];
-}
-
-// Scrobbles change as songs end, so these are only kept briefly
-export function fetchRecent(limit: number): Promise<Scrobble[]> {
- return cached(`lastfm:recent:${limit}`, () => loadRecent(limit), { ttl: 30_000 });
-}
-
-async function loadRecent(limit: number): Promise<Scrobble[]> {
- const data = await lastfm<{ recenttracks?: { track?: LfmTrack | LfmTrack[] } }>(
- 'user.getrecenttracks',
- { limit: String(limit) }
- );
- return asArray(data.recenttracks?.track).map((t) => ({
- name: t.name,
- artist: t.artist?.['#text'] || t.artist?.name || '',
- album: t.album?.['#text'] ?? '',
- url: t.url ?? '',
- art: lfmArt(t.image),
- playing: t['@attr']?.nowplaying === 'true',
- uts: t.date ? Number(t.date.uts) : null
- }));
-}
-
-export function fetchTopArtists(limit: number): Promise<TopArtist[]> {
- return cached(`lastfm:top:${limit}`, () => loadTopArtists(limit), { ttl: 30 * 60_000 });
-}
-
-async function loadTopArtists(limit: number): Promise<TopArtist[]> {
- const data = await lastfm<{
- topartists?: { artist?: { name: string; url: string; playcount: string }[] };
- }>('user.gettopartists', { period: '7day', limit: String(limit) });
- return (data.topartists?.artist ?? []).map((a) => ({
- name: a.name,
- url: a.url,
- plays: Number(a.playcount)
- }));
-}
-
// ---- Tracks ---------------------------------------------------------------
export function trackFromPresence(p: Presence | null): Track | null {
@@ -168,21 +64,6 @@ export function trackFromPresence(p: Presence | null): Track | null {
};
}
-export function trackFromScrobble(s: Scrobble): Track {
- return {
- song: s.name,
- artist: s.artist,
- album: s.album,
- art: s.art,
- url: s.url,
- start: null,
- end: null,
- duration: 0,
- live: false,
- source: null
- };
-}
-
export function trackKey(t: Track | null): string {
return t ? [t.song, t.artist, t.album].map((x) => x.toLowerCase()).join('␟') : '';
}
@@ -379,36 +260,78 @@ export async function fetchLyrics(track: Track): Promise<Lyrics> {
return lyrics;
}
-// ---- Artist images --------------------------------------------------------
+// ---- Album art tint -------------------------------------------------------
-// Cached in localStorage: hits for 30 days, misses for 3
-export async function artistImage(name: string): Promise<string> {
- const key = ART_CACHE_PREFIX + name.toLowerCase();
- try {
- const hit = JSON.parse(localStorage.getItem(key) ?? 'null') as {
- url: string;
- ts: number;
- } | null;
- if (hit && Date.now() - hit.ts < (hit.url ? 30 : 3) * DAY) return hit.url;
- } catch {
- // Storage unavailable, fetch it fresh
- }
- let url = '';
+const TINT_SIZE = 24;
+const HUE_BUCKETS = 12;
+const tintCache = new Map<string, string | null>();
+
+function loadForCanvas(url: string): Promise<HTMLImageElement> {
+ return new Promise((resolve, reject) => {
+ const img = new Image();
+ // Without CORS the canvas can't be read back, so the load fails instead
+ img.crossOrigin = 'anonymous';
+ img.onload = () => resolve(img);
+ img.onerror = reject;
+ img.src = url;
+ });
+}
+
+// The cover's most vivid hue, at a fixed lightness so it reads on the dark page.
+// Null when the cover is close to greyscale or its host won't allow reading it
+export async function artTint(url: string): Promise<string | null> {
+ const hit = tintCache.get(url);
+ if (hit !== undefined) return hit;
+ let tint: string | null = null;
try {
- const res = await fetch(`${tadbApi}/search.php?s=${encodeURIComponent(name)}`);
- if (res.ok) {
- const data = (await res.json()) as { artists?: { strArtistThumb?: string }[] | null };
- url = data.artists?.[0]?.strArtistThumb ?? '';
- }
+ tint = vividHue(await loadForCanvas(url));
} catch {
- // Leave the placeholder in place
+ // Keep the site's own accent
}
- try {
- localStorage.setItem(key, JSON.stringify({ url, ts: Date.now() }));
- } catch {
- // Storage unavailable
+ tintCache.set(url, tint);
+ return tint;
+}
+
+function vividHue(img: HTMLImageElement): string | null {
+ const canvas = document.createElement('canvas');
+ canvas.width = TINT_SIZE;
+ canvas.height = TINT_SIZE;
+ const ctx = canvas.getContext('2d', { willReadFrequently: true })!;
+ ctx.drawImage(img, 0, 0, TINT_SIZE, TINT_SIZE);
+ const pixels = ctx.getImageData(0, 0, TINT_SIZE, TINT_SIZE).data;
+
+ // Colourfulness per slice of the hue wheel, with the hue kept as a vector
+ // so reds either side of 0° average properly
+ const weight = new Array<number>(HUE_BUCKETS).fill(0);
+ const sumX = new Array<number>(HUE_BUCKETS).fill(0);
+ const sumY = new Array<number>(HUE_BUCKETS).fill(0);
+
+ for (let i = 0; i < pixels.length; i += 4) {
+ const red = pixels[i] / 255;
+ const green = pixels[i + 1] / 255;
+ const blue = pixels[i + 2] / 255;
+ const max = Math.max(red, green, blue);
+ const chroma = max - Math.min(red, green, blue);
+ if (chroma < 0.08) continue;
+
+ let hue: number;
+ if (max === red) hue = ((green - blue) / chroma + 6) % 6;
+ else if (max === green) hue = (blue - red) / chroma + 2;
+ else hue = (red - green) / chroma + 4;
+
+ const bucket = Math.floor((hue / 6) * HUE_BUCKETS) % HUE_BUCKETS;
+ const angle = (hue / 6) * 2 * Math.PI;
+ weight[bucket] += chroma;
+ sumX[bucket] += Math.cos(angle) * chroma;
+ sumY[bucket] += Math.sin(angle) * chroma;
}
- return url;
+
+ const best = weight.indexOf(Math.max(...weight));
+ // Too little colour to call it a tint
+ if (weight[best] / (TINT_SIZE * TINT_SIZE) < 0.02) return null;
+
+ const degrees = (Math.atan2(sumY[best], sumX[best]) * 180) / Math.PI;
+ return `hsl(${Math.round((degrees + 360) % 360)} 75% 68%)`;
}
// ---- Formatting -----------------------------------------------------------
diff --git a/src/lib/styles/index.css b/src/lib/styles/index.css
index db7cab9..823eb1f 100644
--- a/src/lib/styles/index.css
+++ b/src/lib/styles/index.css
@@ -217,56 +217,6 @@
}
}
-/* Current lyric line, hung off the music pill by an accent bar so it reads
- as part of the same thing. Lines share one grid cell so the outgoing and
- incoming lines can overlap while they fly */
-
-.now-lyric {
- display: flex;
- flex-direction: column;
- gap: 0.35rem;
- margin: 0.75rem 0 0 1rem;
- padding: 0.2rem 0 0.2rem 1rem;
- border-left: 3px solid var(--accent);
- color: var(--text);
- text-decoration: none;
-}
-
-.now-lyric:hover {
- color: #fff;
-}
-
-.now-lyric-label {
- display: inline-flex;
- gap: 0.4rem;
- align-items: center;
- color: var(--accent);
- font-size: 0.7rem;
- font-weight: 600;
- letter-spacing: 0.14em;
- text-transform: uppercase;
-}
-
-.now-lyric-stage {
- display: grid;
- min-height: 2.6em;
- overflow: hidden;
- font-size: clamp(1.05rem, 2.5vw, 1.35rem);
- font-style: italic;
- font-weight: 500;
-}
-
-.now-lyric-line {
- grid-area: 1 / 1;
- align-self: center;
- text-wrap: balance;
-}
-
-.now-lyric-gap {
- color: var(--accent);
- font-style: normal;
-}
-
/* Fronting and phone pills. Their contents are one centred flex row so the
avatars and icons line up with the text instead of shifting its baseline */
diff --git a/src/lib/styles/music.css b/src/lib/styles/music.css
deleted file mode 100644
index 0cc78b7..0000000
--- a/src/lib/styles/music.css
+++ /dev/null
@@ -1,505 +0,0 @@
-/* src/lib/styles/music.css
- * DASL-1.2 — (c) Clove Twilight
- */
-
-/* Music */
-
-.music {
- display: flex;
- flex-direction: column;
- gap: 0.75rem;
- padding-block: 2rem;
-}
-
-.mu-heading {
- margin: 1.25rem 0 0;
- color: var(--accent);
- font-size: 0.7rem;
- font-weight: 600;
- letter-spacing: 0.14em;
- text-transform: uppercase;
-}
-
-.mu-heading-row {
- display: flex;
- gap: 0.75rem;
- align-items: center;
- justify-content: space-between;
- margin-top: 1.25rem;
-}
-
-.mu-heading-row .mu-heading {
- margin: 0;
-}
-
-.mu-empty {
- margin: 0;
- color: var(--muted);
- font-style: italic;
-}
-
-.mu-art-blank {
- display: grid;
- place-items: center;
- background: var(--line);
- color: var(--muted);
-}
-
-.mu-art-blank svg {
- width: 45%;
- height: 45%;
-}
-
-/* Now playing */
-
-.mu-card {
- position: relative;
- display: flex;
- gap: 1.25rem;
- align-items: center;
- padding: 1.25rem;
- overflow: hidden;
- isolation: isolate;
- border: 1px solid var(--line);
- border-radius: 1rem;
- background: var(--raised);
- color: var(--text);
- text-decoration: none;
- transition:
- border-color 0.2s ease,
- box-shadow 0.2s ease;
-}
-
-.mu-card::before {
- content: '';
- position: absolute;
- inset: 0;
- z-index: -1;
- background: radial-gradient(120% 140% at 0% 0%, rgb(235 69 158 / 18%), transparent 60%);
- opacity: 0;
- transition: opacity 0.6s ease;
-}
-
-.music.live .mu-card {
- border-color: rgb(235 69 158 / 40%);
- box-shadow: 0 0 0 4px var(--accent-dim);
-}
-
-.music.live .mu-card::before {
- opacity: 1;
-}
-
-.mu-art {
- flex: 0 0 auto;
- width: 8rem;
- height: 8rem;
- border-radius: 0.75rem;
- object-fit: cover;
-}
-
-.mu-meta {
- flex: 1 1 auto;
- min-width: 0;
-}
-
-.mu-state {
- display: flex;
- gap: 0.4rem;
- align-items: center;
- margin: 0 0 0.35rem;
- color: var(--muted);
- font-size: 0.7rem;
- font-weight: 600;
- letter-spacing: 0.14em;
- text-transform: uppercase;
-}
-
-.music.live .mu-state {
- color: var(--accent);
-}
-
-.mu-song,
-.mu-artist,
-.mu-album {
- margin: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.mu-song {
- font-size: 1.35rem;
- font-weight: 600;
- line-height: 1.25;
- transition: color 0.2s ease;
-}
-
-a.mu-card:hover .mu-song {
- color: var(--accent);
-}
-
-.mu-artist {
- font-size: 0.95rem;
-}
-
-.mu-album {
- color: var(--muted);
- font-size: 0.85rem;
-}
-
-.mu-progress {
- display: flex;
- gap: 0.6rem;
- align-items: center;
- margin-top: 0.8rem;
-}
-
-.mu-bar {
- flex: 1;
- height: 0.35rem;
- overflow: hidden;
- border-radius: 999px;
- background: var(--line);
-}
-
-.mu-fill {
- height: 100%;
- border-radius: inherit;
- background: var(--accent);
- transition: width 0.25s linear;
-}
-
-.mu-time {
- color: var(--muted);
- font-size: 0.75rem;
- font-variant-numeric: tabular-nums;
-}
-
-/* Sync toggle */
-
-.mu-sync {
- display: inline-flex;
- gap: 0.45rem;
- align-items: center;
- padding: 0.3rem 0.8rem;
- border: 1px solid var(--line);
- border-radius: 999px;
- background: var(--raised);
- color: var(--muted);
- font: inherit;
- font-size: 0.75rem;
- font-weight: 500;
- cursor: pointer;
- transition:
- color 0.15s ease,
- border-color 0.15s ease,
- background 0.15s ease;
-}
-
-.mu-sync:hover {
- border-color: rgb(235 69 158 / 40%);
- color: var(--text);
-}
-
-.mu-sync.on {
- border-color: var(--accent);
- background: var(--accent-dim);
- color: var(--accent);
-}
-
-.mu-sync:focus-visible {
- outline: 2px solid var(--text);
- outline-offset: 2px;
-}
-
-.mu-eq {
- display: inline-flex;
- gap: 2px;
- align-items: flex-end;
- width: 0.8rem;
- height: 0.7rem;
-}
-
-.mu-eq span {
- flex: 1;
- height: 100%;
- background: currentColor;
- opacity: 0.55;
- transform: scaleY(0.4);
- transform-origin: bottom;
-}
-
-.mu-sync.on .mu-eq span {
- opacity: 1;
- animation: mu-eq 0.9s ease-in-out infinite;
-}
-
-.mu-sync.on .mu-eq span:nth-child(2) {
- animation-delay: 0.15s;
-}
-
-.mu-sync.on .mu-eq span:nth-child(3) {
- animation-delay: 0.3s;
-}
-
-.mu-sync.on .mu-eq span:nth-child(4) {
- animation-delay: 0.45s;
-}
-
-@keyframes mu-eq {
- 0%,
- 100% {
- transform: scaleY(0.3);
- }
-
- 50% {
- transform: scaleY(1);
- }
-}
-
-/* Lyrics */
-
-.mu-lyrics {
- position: relative;
- height: 21rem;
- padding: 1.5rem;
- overflow-y: auto;
- overscroll-behavior: contain;
- border: 1px solid var(--line);
- border-radius: 1rem;
- background: var(--raised);
- scrollbar-color: rgb(235 69 158 / 40%) transparent;
- scrollbar-width: thin;
- mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
-}
-
-.mu-lyrics:focus-visible {
- outline: 2px solid var(--accent);
- outline-offset: 2px;
-}
-
-.mu-lyrics:not([data-kind='synced'], [data-kind='plain']) {
- display: grid;
- place-content: center;
- height: 11rem;
- mask-image: none;
-}
-
-.mu-line {
- margin: 0;
- padding: 0.3rem 0;
- color: var(--muted);
- font-size: 1.2rem;
- line-height: 1.4;
- transition:
- color 0.3s ease,
- opacity 0.3s ease,
- transform 0.3s ease;
-}
-
-[data-kind='synced'] .mu-line {
- opacity: 0.55;
-}
-
-[data-kind='synced'] .mu-line.active {
- color: var(--accent);
- font-weight: 600;
- opacity: 1;
- transform: translateX(2px);
-}
-
-[data-kind='plain'] .mu-line {
- color: var(--text);
- font-size: 1.05rem;
-}
-
-.mu-note {
- display: flex;
- gap: 0.5rem;
- align-items: center;
- margin: 0;
- color: var(--muted);
- text-align: center;
-}
-
-.mu-note svg {
- width: 1em;
- height: 1em;
-}
-
-[data-kind='instrumental'] .mu-note {
- color: var(--accent);
- font-size: 1.2rem;
-}
-
-/* Recently played */
-
-.mu-recent {
- display: grid;
- gap: 0.25rem;
- margin: 0;
- padding: 0;
- list-style: none;
-}
-
-.mu-recent-item {
- display: grid;
- grid-template-columns: 2.75rem 1fr auto;
- gap: 0.75rem;
- align-items: center;
- padding: 0.45rem 0.6rem;
- border-radius: 0.75rem;
- color: var(--text);
- text-decoration: none;
- transition: background 0.15s ease;
-}
-
-.mu-recent-item:hover {
- background: var(--raised);
- color: var(--text);
-}
-
-.mu-recent-item.playing {
- background: var(--accent-dim);
-}
-
-.mu-recent-art {
- width: 2.75rem;
- height: 2.75rem;
- border-radius: 0.5rem;
- object-fit: cover;
-}
-
-.mu-recent-text {
- min-width: 0;
-}
-
-.mu-recent-name,
-.mu-recent-artist {
- display: block;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.mu-recent-name {
- font-size: 0.95rem;
- font-weight: 500;
-}
-
-.mu-recent-artist {
- color: var(--muted);
- font-size: 0.8rem;
-}
-
-.mu-recent-when {
- color: var(--muted);
- font-size: 0.75rem;
- white-space: nowrap;
-}
-
-.mu-recent-item.playing .mu-recent-when {
- color: var(--accent);
- font-weight: 600;
-}
-
-/* Top artists */
-
-.mu-top {
- display: flex;
- flex-wrap: wrap;
- gap: 0.5rem;
- margin: 0;
- padding: 0;
- list-style: none;
-}
-
-.mu-top-item {
- display: inline-flex;
- gap: 0.55rem;
- align-items: center;
- padding: 0.35rem 0.9rem 0.35rem 0.75rem;
- border: 1px solid var(--line);
- border-radius: 999px;
- background: var(--raised);
- color: var(--text);
- text-decoration: none;
- transition: border-color 0.15s ease;
-}
-
-.mu-top-item:hover {
- border-color: rgb(235 69 158 / 40%);
- color: var(--text);
-}
-
-.mu-top-rank {
- color: var(--accent);
- font-size: 0.8rem;
- font-weight: 700;
-}
-
-.mu-top-art {
- flex: none;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
- object-fit: cover;
-}
-
-.mu-top-text {
- display: flex;
- flex-direction: column;
- line-height: 1.2;
-}
-
-.mu-top-name {
- font-size: 0.85rem;
- font-weight: 500;
-}
-
-.mu-top-plays {
- color: var(--muted);
- font-size: 0.72rem;
-}
-
-@media (max-width: 30rem) {
- .mu-card {
- gap: 0.9rem;
- padding: 1rem;
- }
-
- .mu-art {
- width: 5.5rem;
- height: 5.5rem;
- }
-
- .mu-song {
- font-size: 1.1rem;
- }
-
- .mu-lyrics {
- height: 18rem;
- }
-
- .mu-line {
- font-size: 1.05rem;
- }
-}
-
-@media (prefers-reduced-motion: reduce) {
- .mu-card,
- .mu-card::before,
- .mu-song,
- .mu-fill,
- .mu-sync,
- .mu-line,
- .mu-recent-item,
- .mu-top-item {
- transition: none;
- }
-
- .mu-sync.on .mu-eq span {
- animation: none;
- transform: scaleY(0.65);
- }
-}
diff --git a/src/lib/styles/nowplaying.css b/src/lib/styles/nowplaying.css
index eebf879..7fd8b63 100644
--- a/src/lib/styles/nowplaying.css
+++ b/src/lib/styles/nowplaying.css
@@ -3,66 +3,86 @@
*/
/* Now playing / status pill, hanging just under the hamburger. It's absolutely
- placed so it never pushes the page down when it appears or goes away */
+ placed so it never pushes the page down when it appears or goes away.
+ --accent is swapped for a colour from the album cover while a song plays */
.now-playing {
position: absolute;
top: calc(100% - 0.4rem);
right: 1.5rem;
display: flex;
- gap: 0.55rem;
- align-items: center;
max-width: min(22rem, calc(100% - 3rem));
min-height: 2.25rem;
- padding: 0.25rem 0.85rem 0.25rem 0.3rem;
overflow: hidden;
- border: 1px solid var(--line);
+ border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
border-radius: 999px;
- background: rgb(11 10 13 / 72%);
+ background: color-mix(in srgb, var(--accent) 7%, rgb(11 10 13 / 72%));
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 0.8rem;
line-height: 1.3;
- text-decoration: none;
transition:
border-color 0.2s ease,
color 0.2s ease;
}
.now-playing:hover {
- border-color: rgb(235 69 158 / 45%);
+ border-color: color-mix(in srgb, var(--accent) 55%, transparent);
color: var(--text);
}
-.np-art {
+/* The whole pill is the link, apart from the hide button on its corner */
+
+.pill-link,
+.pill-link:hover {
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ justify-content: center;
+ min-width: 0;
+ padding: 0.25rem 0.5rem 0.25rem 0.3rem;
+ color: inherit;
+ text-decoration: none;
+}
+
+.pill-row {
+ display: flex;
+ gap: 0.55rem;
+ align-items: center;
+ min-width: 0;
+ /* Room for the hide button */
+ padding-right: 1.6rem;
+}
+
+.pill-art {
flex: none;
border-radius: 50%;
object-fit: cover;
}
-.np-text {
+.pill-text {
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
-.np-text strong {
+.pill-text strong {
color: var(--text);
font-weight: 600;
}
-.np-muted {
+.pill-muted {
color: var(--muted);
}
/* Status-only version: just a dot, so leave the art's padding to it */
-.now-playing[data-status] {
+.now-playing[data-status] .pill-link {
padding-left: 0.8rem;
}
-.np-dot {
+.pill-dot {
flex: none;
width: 0.55rem;
height: 0.55rem;
@@ -71,9 +91,122 @@
box-shadow: 0 0 0.5rem var(--status);
}
+/* Hide button, pinned to the top row so it stays put when a lyric line
+ makes the pill taller */
+
+.pill-hide {
+ position: absolute;
+ top: 0;
+ right: 0.3rem;
+ display: grid;
+ place-items: center;
+ width: 1.75rem;
+ height: 2.25rem;
+ padding: 0;
+ border: 0;
+ background: none;
+ color: var(--muted);
+ font-size: 0.95rem;
+ cursor: pointer;
+}
+
+.pill-hide:hover {
+ color: var(--text);
+}
+
+/* The pill clips its overflow, so focus rings sit just inside the edge */
+
+.pill-link:focus-visible,
+.pill-hide:focus-visible,
+.pill-collapsed:focus-visible {
+ outline: 2px solid var(--accent);
+ outline-offset: -3px;
+ border-radius: 999px;
+}
+
+/* Tucked away: a small round button that brings it back */
+
+.pill-collapsed {
+ place-items: center;
+ display: grid;
+ width: 2.25rem;
+ height: 2.25rem;
+ padding: 0;
+ font-size: 1.05rem;
+ cursor: pointer;
+}
+
+/* A song gets a small card rather than a pill: the song on top, its current
+ lyric line underneath. Width and height are both fixed, so it never
+ resizes as lines change or when a song has no lyrics to follow */
+
+.pill-song {
+ width: 22rem;
+ border-radius: 1.1rem;
+}
+
+.pill-song .pill-link {
+ padding-bottom: 0.5rem;
+}
+
+/* The card is wider than a short title, so the equaliser sits at the far end */
+
+.pill-song .pill-eq {
+ margin-left: auto;
+}
+
+.pill-lyric {
+ display: grid;
+ height: 2.6em;
+ margin-top: 0.3rem;
+ padding: 0 0.35rem 0 0.5rem;
+ overflow: hidden;
+ color: var(--text);
+ font-size: 0.85rem;
+ font-style: italic;
+ font-weight: 500;
+}
+
+/* Two lines at most; anything longer is cut with an ellipsis */
+
+.pill-lyric-line {
+ display: -webkit-box;
+ grid-area: 1 / 1;
+ align-self: center;
+ min-width: 0;
+ overflow: hidden;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ line-clamp: 2;
+ text-wrap: balance;
+}
+
+.pill-lyric-gap {
+ color: var(--accent);
+ font-style: normal;
+}
+
+.pill-lyric-note {
+ color: var(--muted);
+}
+
+/* Narrow screens: the card spans the page, so the lyric stays on one line to
+ keep it inside the hero's top padding, clear of the heading below */
+
+@media (max-width: 40rem) {
+ .pill-lyric {
+ height: 1.3em;
+ }
+
+ .pill-lyric-line {
+ -webkit-line-clamp: 1;
+ line-clamp: 1;
+ }
+}
+
/* Little bouncing equaliser */
-.np-eq {
+.pill-eq {
display: inline-flex;
flex: none;
gap: 2px;
@@ -81,7 +214,7 @@
height: 0.8rem;
}
-.np-eq i {
+.pill-eq i {
width: 3px;
height: 100%;
border-radius: 1px;
@@ -90,12 +223,12 @@
animation: eq 0.9s ease-in-out infinite alternate;
}
-.np-eq i:nth-child(2) {
+.pill-eq i:nth-child(2) {
animation-duration: 0.7s;
animation-delay: -0.3s;
}
-.np-eq i:nth-child(3) {
+.pill-eq i:nth-child(3) {
animation-duration: 1.1s;
animation-delay: -0.6s;
}
@@ -111,7 +244,7 @@
/* Song progress, as a thin line along the bottom edge */
-.np-progress {
+.pill-progress {
position: absolute;
right: 0;
bottom: 0;
@@ -121,19 +254,20 @@
transform: scaleX(var(--progress));
transform-origin: left;
transition: transform 1s linear;
+ pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
- .np-eq i {
+ .pill-eq i {
animation: none;
transform: scaleY(0.6);
}
- .np-eq i:nth-child(2) {
+ .pill-eq i:nth-child(2) {
transform: scaleY(1);
}
- .np-progress {
+ .pill-progress {
transition: none;
}
}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 0f0002f..c47d629 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -9,27 +9,14 @@
import IcBatteryFull from '~icons/ic/outline-battery-full';
import IcBatteryUnknown from '~icons/ic/outline-battery-unknown';
import IcFavorite from '~icons/ic/outline-favorite';
- import IcMusicNote from '~icons/ic/outline-music-note';
import IcPeople from '~icons/ic/outline-people';
import IcSmartphone from '~icons/ic/outline-smartphone';
import Meta from '#lib/components/Meta.svelte';
import '#lib/styles/index.css';
import '#lib/styles/presence.css';
- import { untrack } from 'svelte';
- import { fly } from 'svelte/transition';
- import ListeningIcon from '#lib/components/ListeningIcon.svelte';
- import LyricWords from '#lib/components/LyricWords.svelte';
import SelfieDust from '#lib/components/SelfieDust.svelte';
- import { STATUS_LABEL, clamp, subscribePresence, type Presence } from '#lib/scripts/discord.ts';
- import {
- fetchLyrics,
- fetchRecent,
- timeAgo,
- trackFromPresence,
- trackKey,
- type Lyrics,
- type Scrobble
- } from '#lib/scripts/music.ts';
+ import { STATUS_LABEL, subscribePresence, type Presence } from '#lib/scripts/discord.ts';
+ import { timeAgo } from '#lib/scripts/music.ts';
import {
fetchDevice,
fetchFronters,
@@ -38,30 +25,19 @@
type Member
} from '#lib/scripts/plural.ts';
- import { discordId, lrcLibHosts } from '#lib';
+ import { discordId } from '#lib';
const PHONE = 'S26';
let presence = $state<Presence | null>(null);
- let lastPlayed = $state<Scrobble | null>(null);
let now = $state(Date.now());
- let lyrics = $state<Lyrics | null>(null);
let fronters = $state<Member[]>([]);
let phone = $state<Device | null>(null);
- let reduceMotion = $state(false);
// Hover, keyboard focus or a tap on phones swaps to the real selfie
let revealed = $state(false);
- let lyricsRequest = 0;
$effect(() => {
- reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
-
- fetchRecent(1)
- .then(([last]) => (lastPlayed = last ?? null))
- .catch(() => {
- // The strip just leaves the music part out
- });
// Fronting and phone pills are left out if these fail
const loadFronters = () =>
fetchFronters()
@@ -91,42 +67,7 @@
};
});
- const live = $derived(trackFromPresence(presence));
const status = $derived(presence ? (presence.streaming ? 'streaming' : presence.status) : null);
- const key = $derived(trackKey(live));
-
- // Only reload lyrics when the song itself changes, not on every presence update
- $effect(() => {
- const request = ++lyricsRequest;
- const current = untrack(() => live);
- lyrics = null;
- if (!key || !current) return;
- fetchLyrics(current).then((l) => {
- if (request === lyricsRequest) lyrics = l;
- });
- });
-
- const synced = $derived(lyrics?.kind === 'synced' && live?.start && live.end ? lyrics : null);
-
- // Tick fast only while there's a line to follow, faster still for word-by-word lyrics
- $effect(() => {
- if (!synced) return;
- const ms = synced.lines.some((l) => l.words) ? 100 : 250;
- const tick = setInterval(() => (now = Date.now()), ms);
- return () => clearInterval(tick);
- });
-
- const position = $derived(live?.start ? clamp(now - live.start, 0, live.duration) : 0);
-
- const activeLine = $derived.by(() => {
- if (!synced || !live?.start) return -1;
- const at = position;
- return synced.lines.findLastIndex((line) => line.t <= at);
- });
-
- const line = $derived(synced && activeLine >= 0 ? synced.lines[activeLine] : null);
- const lineText = $derived(line?.text ?? '');
- const flyMs = $derived(reduceMotion ? 0 : 450);
const BatteryIcon = $derived.by(() => {
const level = phone?.level;
@@ -143,10 +84,6 @@
description="Clove Twilight, an AI-neutral software developer and music enthusiast. Projects, languages, live Discord presence and more."
/>
-<svelte:head>
- <link rel="preconnect" href={lrcLibHosts[0]} crossorigin="" />
-</svelte:head>
-
<section class="hero">
<div class="wrap">
<p class="eyebrow">Doughmination</p>
@@ -209,22 +146,6 @@
</figure>
</div>
<p class="now">
- {#if live?.source}
- <a class="now-item" href="/music">
- <ListeningIcon source={live.source} />
- <span
- >Listening to <strong>{live.song}</strong>{#if live.artist} — {live.artist}{/if}</span
- >
- </a>
- {:else if lastPlayed}
- <a class="now-item" href="/music">
- <span class="now-icon" aria-hidden="true"><IcMusicNote /></span>
- <span>
- Last played <strong>{lastPlayed.name}</strong>{#if lastPlayed.artist} — {lastPlayed.artist}{/if}
- {#if lastPlayed.uts}<span class="now-muted">· {timeAgo(lastPlayed.uts, now)}</span>{/if}
- </span>
- </a>
- {/if}
{#if fronters.length}
<span class="now-item" title="Currently fronting">
<span class="now-icon" aria-hidden="true"><IcPeople /></span>
@@ -274,25 +195,5 @@
<span>In a relationship with <strong>Aria</strong></span>
</a>
</p>
- {#if synced}
- <a class="now-lyric" href="/music">
- <span class="now-lyric-label">
- <span class="now-icon" aria-hidden="true"><IcMusicNote /></span>
- Lyrics
- </span>
- <span class="now-lyric-stage">
- {#key activeLine}
- <span
- class="now-lyric-line"
- class:now-lyric-gap={!lineText}
- in:fly={{ y: 14, duration: flyMs, delay: flyMs / 3 }}
- out:fly={{ y: -14, duration: flyMs }}
- >{#if line?.words}<LyricWords words={line.words} at={position} />{:else}{lineText ||
- '♪'}{/if}</span
- >
- {/key}
- </span>
- </a>
- {/if}
</div>
</section>
diff --git a/src/routes/music/+page.svelte b/src/routes/music/+page.svelte
deleted file mode 100644
index e960fac..0000000
--- a/src/routes/music/+page.svelte
+++ /dev/null
@@ -1,339 +0,0 @@
-<!-- src/routes/music/+page.svelte
- DASL-1.2 — (c) Clove Twilight
--->
-
-<script lang="ts">
- import IcMusicNote from '~icons/ic/outline-music-note';
- import Meta from '#lib/components/Meta.svelte';
- import '#lib/styles/music.css';
- import { untrack } from 'svelte';
- import ListeningIcon from '#lib/components/ListeningIcon.svelte';
- import LyricWords from '#lib/components/LyricWords.svelte';
- import { subscribePresence, clamp, fmtDuration, hideBroken } from '#lib/scripts/discord.ts';
- import {
- artistImage,
- fetchLyrics,
- fetchRecent,
- fetchTopArtists,
- timeAgo,
- trackFromPresence,
- trackFromScrobble,
- trackKey,
- type Lyrics,
- type Scrobble,
- type TopArtist,
- type Track
- } from '#lib/scripts/music.ts';
-
- import { discordId, apiBase, lfmApi, lrcLibHosts } from '#lib';
-
- const SCROLL_KEYS = ['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' '];
-
- let track = $state<Track | null>(null);
- let lyrics = $state<Lyrics>({ kind: 'note', text: 'Waiting for a track…' });
- let locked = $state(true);
- let recent = $state<Scrobble[] | null>(null);
- let recentError = $state(false);
- let top = $state<TopArtist[]>([]);
- let topArt = $state<Record<string, string>>({});
- let now = $state(Date.now());
- let lyricsBox = $state<HTMLDivElement>();
-
- let reduceMotion = false;
- let lyricsRequest = 0;
-
- async function showLastPlayed() {
- try {
- const [last] = await fetchRecent(1);
- // A live track may have arrived while this was loading
- if (last && !track?.live) track = trackFromScrobble(last);
- } catch {
- // Keep whatever is showing
- }
- }
-
- async function loadRecent() {
- try {
- recent = await fetchRecent(12);
- recentError = false;
- } catch {
- recentError = true;
- }
- }
-
- async function loadTop() {
- try {
- top = await fetchTopArtists(8);
- for (const a of top) {
- artistImage(a.name).then((url) => {
- if (url) topArt[a.name] = url;
- });
- }
- } catch {
- // Top artists are optional
- }
- }
-
- $effect(() => {
- reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
- (async () => {
- await showLastPlayed();
- await loadRecent();
- await loadTop();
- })();
- const unsubscribe = subscribePresence([discordId], (p) => {
- const live = trackFromPresence(p);
- if (live) {
- track = live;
- } else if (!track || track.live) {
- track = null;
- showLastPlayed();
- }
- });
- const refresh = setInterval(loadRecent, 45_000);
- const tick = setInterval(() => (now = Date.now()), 250);
- return () => {
- unsubscribe();
- clearInterval(refresh);
- clearInterval(tick);
- };
- });
-
- const key = $derived(trackKey(track));
-
- // Only reload lyrics when the song itself changes, not on every presence update
- $effect(() => {
- const request = ++lyricsRequest;
- const current = untrack(() => track);
- locked = true;
- if (!key || !current) {
- lyrics = { kind: 'note', text: 'No track playing.' };
- return;
- }
- lyrics = { kind: 'loading' };
- fetchLyrics(current).then((l) => {
- if (request === lyricsRequest) lyrics = l;
- });
- });
-
- const position = $derived(
- track?.live && track.start && track.end ? clamp(now - track.start, 0, track.duration) : null
- );
-
- // Words move faster than lines, so tick faster while they're on screen
- const wordSynced = $derived(lyrics.kind === 'synced' && lyrics.lines.some((l) => l.words));
- $effect(() => {
- if (!wordSynced || !track?.live) return;
- const tick = setInterval(() => (now = Date.now()), 100);
- return () => clearInterval(tick);
- });
-
- const activeLine = $derived.by(() => {
- if (lyrics.kind !== 'synced' || position === null) return -1;
- const at = position;
- return lyrics.lines.findLastIndex((line) => line.t <= at);
- });
-
- $effect(() => {
- if (!locked || activeLine < 0 || !lyricsBox) return;
- const line = lyricsBox.children[activeLine] as HTMLElement | undefined;
- if (!line) return;
- lyricsBox.scrollTo({
- top: line.offsetTop - lyricsBox.clientHeight / 2 + line.clientHeight / 2,
- behavior: reduceMotion ? 'auto' : 'smooth'
- });
- });
-
- // Scrolling the lyrics yourself stops them following the song
- function unlock() {
- locked = false;
- }
-</script>
-
-<Meta
- title="Music"
- description="What Clove is listening to: live now-playing track, synced lyrics, and recent plays from Last.fm."
-/>
-
-<svelte:head>
- <link rel="preconnect" href={apiBase} crossorigin="" />
- <link rel="preconnect" href={new URL(lfmApi).origin} crossorigin="" />
- <link rel="preconnect" href={lrcLibHosts[0]} crossorigin="" />
-</svelte:head>
-
-<section class="hero">
- <div class="wrap">
- <p class="eyebrow">Clove Twilight</p>
- <h1>Music</h1>
- <p class="subtitle">What I'm listening to, with lyrics that follow along</p>
- </div>
-</section>
-
-<section class="music wrap" class:live={track?.live}>
- <svelte:element
- this={track?.url ? 'a' : 'div'}
- class="mu-card"
- href={track?.url || undefined}
- target={track?.url ? '_blank' : undefined}
- rel={track?.url ? 'noopener' : undefined}
- >
- {#if track?.art}
- <img
- class="mu-art"
- src={track.art}
- alt=""
- referrerpolicy="no-referrer"
- onerror={hideBroken}
- />
- {:else}
- <span class="mu-art mu-art-blank" aria-hidden="true"><IcMusicNote /></span>
- {/if}
- <div class="mu-meta">
- <p class="mu-state">
- {#if track?.source}
- <ListeningIcon source={track.source} />
- {track.source === 'doughmination'
- ? 'Listening on Doughmination Music'
- : 'Listening to Spotify'}
- {:else}
- {track ? 'Last played' : 'Not listening right now'}
- {/if}
- </p>
- <p class="mu-song">{track ? track.song || 'Unknown track' : '—'}</p>
- {#if track?.artist}<p class="mu-artist">{track.artist}</p>{/if}
- {#if track?.album}<p class="mu-album">{track.album}</p>{/if}
- {#if track && position !== null}
- <div class="mu-progress">
- <span class="mu-time">{fmtDuration(position)}</span>
- <div
- class="mu-bar"
- role="progressbar"
- aria-label="Track progress"
- aria-valuemin={0}
- aria-valuemax={100}
- aria-valuenow={Math.round((position / track.duration) * 100)}
- >
- <div class="mu-fill" style:width="{(position / track.duration) * 100}%"></div>
- </div>
- <span class="mu-time">{fmtDuration(track.duration)}</span>
- </div>
- {/if}
- </div>
- </svelte:element>
-
- <div class="mu-heading-row">
- <h2 class="mu-heading">Lyrics</h2>
- {#if lyrics.kind === 'synced'}
- <button
- class="mu-sync"
- class:on={locked}
- type="button"
- aria-pressed={locked}
- onclick={() => (locked = !locked)}
- >
- <span class="mu-eq" aria-hidden="true"
- ><span></span><span></span><span></span><span></span></span
- >
- {locked ? 'Synced' : 'Sync'}
- </button>
- {/if}
- </div>
- <!-- A fresh box per song so it starts scrolled to the top -->
- {#key key}
- <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
- <div
- class="mu-lyrics"
- data-kind={lyrics.kind}
- role="region"
- aria-label="Lyrics"
- tabindex="0"
- bind:this={lyricsBox}
- onwheel={unlock}
- ontouchmove={unlock}
- onkeydown={(e) => SCROLL_KEYS.includes(e.key) && unlock()}
- >
- {#if lyrics.kind === 'loading'}
- <p class="mu-note">Finding lyrics…</p>
- {:else if lyrics.kind === 'note'}
- <p class="mu-note">{lyrics.text}</p>
- {:else if lyrics.kind === 'instrumental'}
- <p class="mu-note">
- <IcMusicNote aria-hidden="true" />Instrumental<IcMusicNote aria-hidden="true" />
- </p>
- {:else if lyrics.kind === 'synced'}
- {#each lyrics.lines as line, i (i)}
- <p class="mu-line" class:active={i === activeLine}>
- {#if line.words && i === activeLine && position !== null}
- <LyricWords words={line.words} at={position} />
- {:else}
- {line.text || ' '}
- {/if}
- </p>
- {/each}
- {:else}
- {#each lyrics.lines as line, i (i)}
- <p class="mu-line">{line || ' '}</p>
- {/each}
- {/if}
- </div>
- {/key}
-
- <h2 class="mu-heading">Recently played</h2>
- {#if recent?.length}
- <ul class="mu-recent">
- {#each recent as r, i (i)}
- <li>
- <a
- class="mu-recent-item"
- class:playing={r.playing}
- href={r.url}
- target="_blank"
- rel="noopener"
- >
- {#if r.art}
- <img class="mu-recent-art" src={r.art} alt="" loading="lazy" />
- {:else}
- <span class="mu-recent-art mu-art-blank" aria-hidden="true"><IcMusicNote /></span>
- {/if}
- <span class="mu-recent-text">
- <span class="mu-recent-name">{r.name}</span>
- <span class="mu-recent-artist">{r.artist}</span>
- </span>
- <span class="mu-recent-when">
- {r.playing ? 'Scrobbling now' : r.uts ? timeAgo(r.uts, now) : ''}
- </span>
- </a>
- </li>
- {/each}
- </ul>
- {:else if recentError}
- <p class="mu-empty">Couldn't reach Last.fm just now</p>
- {:else if recent}
- <p class="mu-empty">No recent scrobbles</p>
- {/if}
-
- {#if top.length}
- <h2 class="mu-heading">Top artists · last 7 days</h2>
- <ol class="mu-top">
- {#each top as a, i (a.name)}
- <li>
- <a class="mu-top-item" href={a.url} target="_blank" rel="noopener">
- <span class="mu-top-rank">{i + 1}</span>
- {#if topArt[a.name]}
- <img class="mu-top-art" src={topArt[a.name]} alt="" referrerpolicy="no-referrer" />
- {:else}
- <span class="mu-top-art mu-art-blank" aria-hidden="true"><IcMusicNote /></span>
- {/if}
- <span class="mu-top-text">
- <span class="mu-top-name">{a.name}</span>
- <span class="mu-top-plays">
- {a.plays.toLocaleString('en-GB')}
- {a.plays === 1 ? 'play' : 'plays'}
- </span>
- </span>
- </a>
- </li>
- {/each}
- </ol>
- {/if}
-</section>