fix(web): home shelves fill the window and their text stays readable on any cover
release / web (push) Failing after 11s
release / go (push) Successful in 1m52s
release / govulncheck (push) Successful in 23s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / integration (push) Canceled after 4m12s
release / android (push) Canceled after 4m3s
release / Build signed APK (push) Canceled after 2m3s

A wide card or genre band's wash keeps its cover's hue but caps its
lightness and saturation, so a pale or loud cover no longer washes the
card too light for its text; the faintest text on it is 80% parchment,
and a test checks 4.5:1 against the lightest wash allowed. A genre's
name keeps clear of its fan of covers.

Shelves size their tiles to the window: each shows a whole number of
tiles that fill its width, a short shelf grows its tiles up to a cap,
and the arrows page by whole tiles. On a very wide screen the page stops
at 140rem and centres.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 17:25:27 -05:00
co-authored by Claude Opus 5.5
parent 16225f09f7
commit e311e434a8
5 changed files with 178 additions and 23 deletions
@@ -1,12 +1,14 @@
<script lang="ts" generics="T"> <script lang="ts" generics="T">
import { ChevronLeft, ChevronRight } from 'lucide-svelte'; import { ChevronLeft, ChevronRight } from 'lucide-svelte';
import type { Snippet } from 'svelte'; import type { Snippet } from 'svelte';
import { shelfTileWidth } from '#lib/playlists/shelf.js';
let { let {
rows, rows,
item, item,
title, title,
meta, meta,
fit,
ariaLabel ariaLabel
}: { }: {
/** One or more visual rows of items rendered inside a single shared /** One or more visual rows of items rendered inside a single shared
@@ -25,6 +27,11 @@
each · refreshed today"), shown beside the title so the items need each · refreshed today"), shown beside the title so the items need
not repeat it. */ not repeat it. */
meta?: string; meta?: string;
/** Size items to the row instead of a fixed width: the row shows a whole
number of items that fill its width, each at least `min` px wide (and,
when there are fewer items than fit, at most `max` px). The width is
set as --tile-w on the track; an item wrapper uses it as its width. */
fit?: { min: number; max: number };
/** Accessible label for the section as a whole. */ /** Accessible label for the section as a whole. */
ariaLabel?: string; ariaLabel?: string;
} = $props(); } = $props();
@@ -56,12 +63,34 @@
function page(direction: -1 | 1) { function page(direction: -1 | 1) {
if (!scroller) return; if (!scroller) return;
const delta = direction * scroller.clientWidth * 0.85; // A fitted row pages by its whole visible tiles; any other by most of a
// screen, leaving a sliver of the last page for context.
const delta = fit && tileWidth > 0
? direction * Math.max(1, Math.floor((clientWidth - BLEED + GAP) / (tileWidth + GAP))) * (tileWidth + GAP)
: direction * scroller.clientWidth * 0.85;
scroller.scrollBy({ left: delta, behavior: 'smooth' }); scroller.scrollBy({ left: delta, behavior: 'smooth' });
setTimeout(refreshMetrics, 350); setTimeout(refreshMetrics, 350);
} }
$effect(() => { refreshMetrics(); }); $effect(() => { refreshMetrics(); });
// The gap between items (gap-4), and the 1rem the scroller bleeds past the
// page's right padding: whole tiles fill the width up to the page edge,
// not into the bleed.
const GAP = 16;
const BLEED = 16;
const itemCount = $derived(Math.max(0, ...rows.map((r) => r.length)));
const tileWidth = $derived(
fit ? shelfTileWidth(clientWidth - BLEED, itemCount, fit.min, fit.max, GAP) : 0
);
// clientWidth follows the window, not just scrolling, so tiles resize live.
$effect(() => {
if (!scroller || typeof ResizeObserver === 'undefined') return;
const ro = new ResizeObserver(refreshMetrics);
ro.observe(scroller);
return () => ro.disconnect();
});
</script> </script>
<div class="section" aria-label={ariaLabel}> <div class="section" aria-label={ariaLabel}>
@@ -105,7 +134,7 @@
data-testid="scroll-container" data-testid="scroll-container"
class="scroller overflow-x-auto" class="scroller overflow-x-auto"
> >
<div class="track inline-flex flex-col gap-4"> <div class="track inline-flex flex-col gap-4" style:--tile-w={fit ? `${tileWidth}px` : undefined}>
{#each rows as row, rowIdx (rowIdx)} {#each rows as row, rowIdx (rowIdx)}
<div class="rack flex gap-4"> <div class="rack flex gap-4">
{#each row as it, colIdx (colIdx)} {#each row as it, colIdx (colIdx)}
+15 -8
View File
@@ -7,7 +7,7 @@
import { getPlaylist, systemShuffle, refreshSystem } from '#lib/api/playlists.js'; import { getPlaylist, systemShuffle, refreshSystem } from '#lib/api/playlists.js';
import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js'; import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js';
import { systemPlaylistRefetch } from '#lib/playlists/systemRefetch.js'; import { systemPlaylistRefetch } from '#lib/playlists/systemRefetch.js';
import { refreshedLabel, songsLikeArtist } from '#lib/playlists/shelf.js'; import { refreshedLabel, songsLikeArtist, washTone } from '#lib/playlists/shelf.js';
import { coverUrl } from '#lib/media/covers.js'; import { coverUrl } from '#lib/media/covers.js';
import { dominantColorFromUrl, rgbToCssString } from '#lib/media/dominantColor.js'; import { dominantColorFromUrl, rgbToCssString } from '#lib/media/dominantColor.js';
import { errCode } from '#lib/api/errors.js'; import { errCode } from '#lib/api/errors.js';
@@ -50,7 +50,8 @@
const lead = $derived(coverUrls[0] ?? playlist.cover_url ?? ''); const lead = $derived(coverUrls[0] ?? playlist.cover_url ?? '');
// The wash behind a wide card or band is the lead cover's main colour, // The wash behind a wide card or band is the lead cover's main colour,
// darkened so light text reads on it in either theme. Until the colour is // toned down (washTone) and darkened so light text reads on it in either
// theme, whatever the cover. Until the colour is
// known (or when there is no cover) the wash is a neutral slate. // known (or when there is no cover) the wash is a neutral slate.
let washRgb = $state('rgb(44 49 58)'); let washRgb = $state('rgb(44 49 58)');
$effect(() => { $effect(() => {
@@ -58,7 +59,7 @@
const url = lead; const url = lead;
if (!url) return; if (!url) return;
dominantColorFromUrl(url).then((rgb) => { dominantColorFromUrl(url).then((rgb) => {
if (rgb && url === lead) washRgb = rgbToCssString(rgb); if (rgb && url === lead) washRgb = rgbToCssString(washTone(rgb));
}); });
}); });
@@ -289,7 +290,7 @@
<img src={url} alt="" /> <img src={url} alt="" />
{/each} {/each}
</div> </div>
<div class="relative z-10 max-w-[55%] font-display text-xl font-medium leading-tight on-wash">{playlist.name.replace(/\s+mix$/i, '')}</div> <div class="band-name relative z-10 font-display text-xl font-medium leading-tight on-wash">{playlist.name.replace(/\s+mix$/i, '')}</div>
{#if showMeta} {#if showMeta}
<div class="relative z-10 truncate text-xs on-wash-3">{plural(playlist.track_count, 'track', 'tracks')}{refreshed ? ` · ${refreshed}` : ''}</div> <div class="relative z-10 truncate text-xs on-wash-3">{plural(playlist.track_count, 'track', 'tracks')}{refreshed ? ` · ${refreshed}` : ''}</div>
{/if} {/if}
@@ -372,8 +373,13 @@
); );
} }
.on-wash { color: var(--fs-parchment); } .on-wash { color: var(--fs-parchment); }
.on-wash-2 { color: color-mix(in srgb, var(--fs-parchment) 82%, transparent); } /* Fainter text stays at 90% and 80%: at those strengths it still clears
.on-wash-3 { color: color-mix(in srgb, var(--fs-parchment) 68%, transparent); } 4.5:1 on the lightest wash washTone allows (shelf.test.ts checks it). */
.on-wash-2 { color: color-mix(in srgb, var(--fs-parchment) 90%, transparent); }
.on-wash-3 { color: color-mix(in srgb, var(--fs-parchment) 80%, transparent); }
/* The genre name keeps clear of the fan: the fan is three 3.75rem covers
overlapping by half (7.5rem) plus its 0.75rem inset. */
.band-name { max-width: calc(100% - 8.75rem); overflow-wrap: anywhere; }
.fan { .fan {
position: absolute; position: absolute;
right: 0.75rem; right: 0.75rem;
@@ -382,13 +388,14 @@
display: flex; display: flex;
} }
.fan img { .fan img {
width: 4.5rem; width: 3.75rem;
aspect-ratio: 1; aspect-ratio: 1;
object-fit: cover; object-fit: cover;
border-radius: 6px; border-radius: 6px;
box-shadow: 0 6px 16px rgb(0 0 0 / 0.45); box-shadow: 0 6px 16px rgb(0 0 0 / 0.45);
margin-left: -2.25rem; margin-left: -1.875rem;
} }
.fan img:first-child { margin-left: 0; }
.fan img:nth-child(1) { transform: rotate(-8deg) translateY(4px); } .fan img:nth-child(1) { transform: rotate(-8deg) translateY(4px); }
.fan img:nth-child(2) { transform: translateY(-4px); z-index: 1; } .fan img:nth-child(2) { transform: translateY(-4px); z-index: 1; }
.fan img:nth-child(3) { transform: rotate(8deg) translateY(4px); z-index: 2; } .fan img:nth-child(3) { transform: rotate(8deg) translateY(4px); z-index: 2; }
+53
View File
@@ -96,3 +96,56 @@ test('songsLikeArtist drops the shelf-wide prefix', () => {
expect(songsLikeArtist(pl({ name: 'Songs like Low Tide Choir' }))).toBe('Low Tide Choir'); expect(songsLikeArtist(pl({ name: 'Songs like Low Tide Choir' }))).toBe('Low Tide Choir');
expect(songsLikeArtist(pl({ name: 'Something else' }))).toBe('Something else'); expect(songsLikeArtist(pl({ name: 'Something else' }))).toBe('Something else');
}); });
describe('washTone', () => {
// WCAG relative luminance and contrast, to check the promise in the doc.
const lum = ({ r, g, b }: { r: number; g: number; b: number }) => {
const c = (v: number) => {
const s = v / 255;
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * c(r) + 0.7152 * c(g) + 0.0722 * c(b);
};
// The card mixes the tone 62% toward #0e1013 at its lightest end, and its
// faintest text is parchment at 80% over that.
const mix = (a: { r: number; g: number; b: number }, t: number, b = { r: 14, g: 16, b: 19 }) => ({
r: a.r * t + b.r * (1 - t),
g: a.g * t + b.g * (1 - t),
b: a.b * t + b.b * (1 - t)
});
const parchment = { r: 232, g: 228, b: 216 };
test.each([
['beige', { r: 200, g: 190, b: 160 }],
['near white', { r: 245, g: 245, b: 245 }],
['acid yellow', { r: 240, g: 240, b: 20 }],
['light grey', { r: 170, g: 175, b: 180 }]
])('a %s cover still leaves the faintest text at 4.5:1', (_, cover) => {
const ground = mix(washTone(cover), 0.62);
const text = mix(parchment, 0.8, ground);
const ratio = (lum(text) + 0.05) / (lum(ground) + 0.05);
expect(ratio).toBeGreaterThanOrEqual(4.5);
});
test('a dark cover keeps its own colour', () => {
expect(washTone({ r: 30, g: 60, b: 90 })).toEqual({ r: 30, g: 60, b: 90 });
});
});
describe('shelfTileWidth', () => {
test('a long shelf shows whole tiles that fill its width', () => {
const w = shelfTileWidth(1000, 20, 150, 200, 16);
const cols = Math.floor((1000 + 16) / (150 + 16));
expect(cols * w + (cols - 1) * 16).toBeLessThanOrEqual(1000);
expect(cols * w + (cols - 1) * 16).toBeGreaterThan(1000 - cols);
});
test('a short shelf grows its tiles up to the max', () => {
expect(shelfTileWidth(1000, 2, 150, 200, 16)).toBe(200);
expect(shelfTileWidth(400, 2, 150, 300, 16)).toBe(192);
});
test('a narrow window still gets one tile at the min', () => {
expect(shelfTileWidth(100, 5, 150, 200, 16)).toBe(150);
});
});
+55
View File
@@ -71,3 +71,58 @@ export function shelfMeta(playlists: Playlist[], now: Date = new Date()): string
export function songsLikeArtist(p: Playlist): string { export function songsLikeArtist(p: Playlist): string {
return p.name.replace(/^Songs like\s+/i, ''); return p.name.replace(/^Songs like\s+/i, '');
} }
// The colour a wide card or genre band is washed in, from its lead cover's
// main colour. A light or loud cover would wash the card too light for the
// light text on it, so the tone keeps the cover's hue but caps its lightness
// and saturation. The card's gradient then darkens it further, and its text
// clears 4.5:1 on any cover.
export function washTone({ r, g, b }: { r: number; g: number; b: number }): { r: number; g: number; b: number } {
const [h, s, l] = toHsl(r / 255, g / 255, b / 255);
return fromHsl(h, Math.min(s, 0.6), Math.min(l, 0.3));
}
function toHsl(r: number, g: number, b: number): [number, number, number] {
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
const l = (max + min) / 2;
if (max === min) return [0, 0, l];
const d = max - min;
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
let h: number;
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
else if (max === g) h = (b - r) / d + 2;
else h = (r - g) / d + 4;
return [h / 6, s, l];
}
function fromHsl(h: number, s: number, l: number): { r: number; g: number; b: number } {
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
const channel = (t: number) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p;
};
return {
r: Math.round(channel(h + 1 / 3) * 255),
g: Math.round(channel(h) * 255),
b: Math.round(channel(h - 1 / 3) * 255)
};
}
// How wide each tile on a shelf is, so the shelf shows a whole number of
// tiles that fill its width: as many columns as fit at `min` pixels, each
// then grown to share the width. A shelf with fewer items than columns
// gives each item up to `max` instead, so a short shelf is not a row of
// tiny tiles in a wide window.
export function shelfTileWidth(width: number, count: number, min: number, max: number, gap: number): number {
if (width <= 0) return min;
let cols = Math.max(1, Math.floor((width + gap) / (min + gap)));
if (count > 0 && count < cols) cols = count;
const w = (width - (cols - 1) * gap) / cols;
return Math.floor(Math.min(Math.max(w, min), count > 0 && count <= cols ? max : Infinity));
}
+24 -13
View File
@@ -170,19 +170,22 @@
<svelte:head><title>{pageTitle('Home')}</title></svelte:head> <svelte:head><title>{pageTitle('Home')}</title></svelte:head>
<div class="space-y-8"> <!-- On a very wide screen the page stops growing and centres, so shelves
of a few items do not leave half the window empty. -->
<div class="mx-auto max-w-[140rem] space-y-8">
<!-- Playlists: For You, Discover, the other daily mixes, then your own playlists --> <!-- Playlists: For You, Discover, the other daily mixes, then your own playlists -->
<section class="space-y-3"> <section class="space-y-3">
<HorizontalScrollRow <HorizontalScrollRow
rows={[playlistsRow]} rows={[playlistsRow]}
title="Playlists" title="Playlists"
meta={shelfMeta(realPlaylists)} meta={shelfMeta(realPlaylists)}
fit={{ min: 352, max: 480 }}
ariaLabel="Playlists" ariaLabel="Playlists"
> >
{#snippet item(rowItem: PlaylistRowItem)} {#snippet item(rowItem: PlaylistRowItem)}
<!-- The page's front door: the biggest tiles on it, wide cards that <!-- The page's front door: the biggest tiles on it, wide cards that
say what each mix is built from. Every shelf below steps down. --> say what each mix is built from. Every shelf below steps down. -->
<div class="h-44 w-[26rem] max-w-[85vw]"> <div class="aspect-[64/27]" style:width="var(--tile-w)">
{#if rowItem.kind === 'real'} {#if rowItem.kind === 'real'}
<PlaylistCard <PlaylistCard
playlist={rowItem.playlist} playlist={rowItem.playlist}
@@ -206,12 +209,13 @@
rows={[songsLikeRow]} rows={[songsLikeRow]}
title="Songs like…" title="Songs like…"
meta={shelfMeta(songsLikePlaylists)} meta={shelfMeta(songsLikePlaylists)}
fit={{ min: 144, max: 200 }}
ariaLabel="Songs like" ariaLabel="Songs like"
> >
{#snippet item(rowItem: PlaylistRowItem)} {#snippet item(rowItem: PlaylistRowItem)}
<!-- Circles: the shape artists have everywhere else, so a Songs like <!-- Circles: the shape artists have everywhere else, so a Songs like
mix reads as "about this artist" before its name is read. --> mix reads as "about this artist" before its name is read. -->
<div class="w-40"> <div style:width="var(--tile-w)">
{#if rowItem.kind === 'real'} {#if rowItem.kind === 'real'}
<PlaylistCard <PlaylistCard
playlist={rowItem.playlist} playlist={rowItem.playlist}
@@ -236,11 +240,12 @@
rows={[genreMixPlaylists]} rows={[genreMixPlaylists]}
title="Your genres" title="Your genres"
meta={shelfMeta(genreMixPlaylists)} meta={shelfMeta(genreMixPlaylists)}
fit={{ min: 240, max: 320 }}
ariaLabel="Your genres" ariaLabel="Your genres"
> >
{#snippet item(playlist: Playlist)} {#snippet item(playlist: Playlist)}
<!-- Short, wide bands: a colour field and a fan of three covers. --> <!-- Short, wide bands: a colour field and a fan of three covers. -->
<div class="h-28 w-64"> <div class="aspect-[16/7]" style:width="var(--tile-w)">
<PlaylistCard <PlaylistCard
{playlist} {playlist}
shape="band" shape="band"
@@ -273,10 +278,11 @@
<HorizontalScrollRow <HorizontalScrollRow
rows={[data.you_might_like_albums]} rows={[data.you_might_like_albums]}
title="You might like" title="You might like"
fit={{ min: 144, max: 200 }}
ariaLabel="You might like albums" ariaLabel="You might like albums"
> >
{#snippet item(album: import('#lib/api/types.js').AlbumRef)} {#snippet item(album: import('#lib/api/types.js').AlbumRef)}
<div class="w-40"><AlbumCard {album} /></div> <div style:width="var(--tile-w)"><AlbumCard {album} /></div>
{/snippet} {/snippet}
</HorizontalScrollRow> </HorizontalScrollRow>
{/if} {/if}
@@ -284,10 +290,11 @@
<HorizontalScrollRow <HorizontalScrollRow
rows={[data.you_might_like_artists]} rows={[data.you_might_like_artists]}
title={data.you_might_like_albums.length === 0 ? 'You might like' : undefined} title={data.you_might_like_albums.length === 0 ? 'You might like' : undefined}
fit={{ min: 128, max: 176 }}
ariaLabel="You might like artists" ariaLabel="You might like artists"
> >
{#snippet item(artist: import('#lib/api/types.js').ArtistRef)} {#snippet item(artist: import('#lib/api/types.js').ArtistRef)}
<div class="w-36"><ArtistCard {artist} /></div> <div style:width="var(--tile-w)"><ArtistCard {artist} /></div>
{/snippet} {/snippet}
</HorizontalScrollRow> </HorizontalScrollRow>
{/if} {/if}
@@ -305,10 +312,11 @@
<HorizontalScrollRow <HorizontalScrollRow
rows={chunk(data.recently_added_albums, 25)} rows={chunk(data.recently_added_albums, 25)}
title="Recently added" title="Recently added"
ariaLabel="Recently added" fit={{ min: 176, max: 240 }}
ariaLabel="Recently added"
> >
{#snippet item(album: import('#lib/api/types.js').AlbumRef)} {#snippet item(album: import('#lib/api/types.js').AlbumRef)}
<div class="w-48"><AlbumCard {album} /></div> <div style:width="var(--tile-w)"><AlbumCard {album} /></div>
{/snippet} {/snippet}
</HorizontalScrollRow> </HorizontalScrollRow>
{/if} {/if}
@@ -328,13 +336,14 @@
<HorizontalScrollRow <HorizontalScrollRow
rows={[data.rediscover_albums]} rows={[data.rediscover_albums]}
title="Rediscover" title="Rediscover"
fit={{ min: 144, max: 200 }}
ariaLabel="Rediscover albums" ariaLabel="Rediscover albums"
> >
{#snippet item(album: import('#lib/api/types.js').AlbumRef)} {#snippet item(album: import('#lib/api/types.js').AlbumRef)}
<!-- Rediscover sits below Recently Added in the size <!-- Rediscover sits below Recently Added in the size
hierarchy. w-40 keeps it readable without competing hierarchy: its tiles start smaller (144px against
with the freshest content above. --> 176px), so the freshest albums above lead. -->
<div class="w-40"><AlbumCard {album} /></div> <div style:width="var(--tile-w)"><AlbumCard {album} /></div>
{/snippet} {/snippet}
</HorizontalScrollRow> </HorizontalScrollRow>
{/if} {/if}
@@ -342,10 +351,11 @@
<HorizontalScrollRow <HorizontalScrollRow
rows={[data.rediscover_artists]} rows={[data.rediscover_artists]}
title={data.rediscover_albums.length === 0 ? 'Rediscover' : undefined} title={data.rediscover_albums.length === 0 ? 'Rediscover' : undefined}
fit={{ min: 128, max: 176 }}
ariaLabel="Rediscover artists" ariaLabel="Rediscover artists"
> >
{#snippet item(artist: import('#lib/api/types.js').ArtistRef)} {#snippet item(artist: import('#lib/api/types.js').ArtistRef)}
<div class="w-36"><ArtistCard {artist} /></div> <div style:width="var(--tile-w)"><ArtistCard {artist} /></div>
{/snippet} {/snippet}
</HorizontalScrollRow> </HorizontalScrollRow>
{/if} {/if}
@@ -387,10 +397,11 @@
<HorizontalScrollRow <HorizontalScrollRow
rows={[data.last_played_artists]} rows={[data.last_played_artists]}
title="Last played" title="Last played"
fit={{ min: 128, max: 176 }}
ariaLabel="Last played artists" ariaLabel="Last played artists"
> >
{#snippet item(artist: import('#lib/api/types.js').ArtistRef)} {#snippet item(artist: import('#lib/api/types.js').ArtistRef)}
<div class="w-36"><ArtistCard {artist} /></div> <div style:width="var(--tile-w)"><ArtistCard {artist} /></div>
{/snippet} {/snippet}
</HorizontalScrollRow> </HorizontalScrollRow>
{/if} {/if}