The first public release of Fabled Minstrel #158

Merged
bvandeusen merged 256 commits from dev into main 2026-12-03 21:41:58 -05:00
2 changed files with 17 additions and 7 deletions
Showing only changes of commit c4eaa33e24 - Show all commits
+8 -2
View File
@@ -6,6 +6,7 @@ import {
refreshedLabel, refreshedLabel,
shelfMeta, shelfMeta,
shelfTileWidth, shelfTileWidth,
MAX_TILE_GROWTH,
songsLikeArtist, songsLikeArtist,
washTone washTone
} from './shelf.js'; } from './shelf.js';
@@ -148,9 +149,14 @@ describe('shelfTileWidth', () => {
expect(cols * w + (cols - 1) * 16).toBeGreaterThan(1000 - cols); expect(cols * w + (cols - 1) * 16).toBeGreaterThan(1000 - cols);
}); });
test('a short shelf splits the whole width between its items', () => { test('a short shelf splits the width between its items', () => {
expect(shelfTileWidth(1000, 2, 150, 16)).toBe(492);
expect(shelfTileWidth(400, 2, 150, 16)).toBe(192); expect(shelfTileWidth(400, 2, 150, 16)).toBe(192);
expect(shelfTileWidth(1000, 3, 300, 16)).toBe(322);
});
test('a tile on a near-empty shelf stops growing at twice its minimum', () => {
expect(shelfTileWidth(1400, 1, 144, 16)).toBe(144 * MAX_TILE_GROWTH);
expect(shelfTileWidth(1000, 2, 150, 16)).toBe(150 * MAX_TILE_GROWTH);
}); });
test('a narrow window still gets one tile at the min', () => { test('a narrow window still gets one tile at the min', () => {
+9 -5
View File
@@ -123,13 +123,17 @@ function fromHsl(h: number, s: number, l: number): { r: number; g: number; b: nu
}; };
} }
// How wide each tile on a shelf is, so the shelf's tiles always fill its // How wide each tile on a shelf is, so the shelf's tiles fill its width: as
// width: as many columns as fit at `min` pixels, each grown to share the // many columns as fit at `min` pixels, each grown to share the width. A shelf
// width. A shelf with fewer items than that splits the whole width between // with fewer items than that splits the width between the items it has, but
// the items it has, so no shelf ends partway across the page. // no tile grows past MAX_TILE_GROWTH times `min`: a lone album on a wide
// window would otherwise become a cover the size of the page.
export const MAX_TILE_GROWTH = 2;
export function shelfTileWidth(width: number, count: number, min: number, gap: number): number { export function shelfTileWidth(width: number, count: number, min: number, gap: number): number {
if (width <= 0) return min; if (width <= 0) return min;
let cols = Math.max(1, Math.floor((width + gap) / (min + gap))); let cols = Math.max(1, Math.floor((width + gap) / (min + gap)));
if (count > 0 && count < cols) cols = count; if (count > 0 && count < cols) cols = count;
return Math.max(min, Math.floor((width - (cols - 1) * gap) / cols)); const shared = Math.floor((width - (cols - 1) * gap) / cols);
return Math.max(min, Math.min(shared, min * MAX_TILE_GROWTH));
} }