Album art theme on web and iOS, roomier player bar

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-11-19 22:39:05 -08:00
1 parent 0c9cae5b11
commit 8e57b9d0cd
8 files changed
+116 -10

No files matched your search

+52 -3
View File
@@ -28,8 +28,55 @@ const inkFor = hex => {
const n = parseInt(hex.slice(1), 16), l = (0.299 * (n >> 16) + 0.587 * (n >> 8 & 255) + 0.114 * (n & 255)) / 255;
return l > 0.6 ? "#141414" : "#ffffff";
};
// Theme from the playing track's art: one hue taken from the art, laid over the chosen theme's lightness.
const hex = (h, s, l) => {
const f = n => { const k = (n + h * 12) % 12, c = l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1)); return Math.round(c * 255).toString(16).padStart(2, "0"); };
return "#" + f(0) + f(8) + f(4);
};
function artPalette([h, s0, v], base) {
const s = Math.min(s0, 0.9), tint = Math.min(s * 0.55, 0.32), clamp = (x, a, b) => Math.max(a, Math.min(b, x));
if (base.light) return { bg: hex(h, tint, .955), panel: hex(h, tint, .985), raised: hex(h, tint, .9), line: hex(h, tint, .85),
text: hex(h, .2, .1), muted: hex(h, .08, .42), accent: hex(h, Math.max(s, .55), clamp(v * .45, .32, .42)), light: true };
const black = base.bg === "#000000";
return { bg: black ? "#000000" : hex(h, tint, .09), panel: black ? "#000000" : hex(h, tint, .06), raised: hex(h, tint, black ? .085 : .145), line: hex(h, tint, black ? .12 : .18),
text: hex(h, .15, .93), muted: hex(h, .1, .66), accent: hex(h, Math.max(s, .55), clamp(v * .7, .58, .7)) };
}
// Roughly a vibrant swatch: the circular mean hue of the most colourful mid-bright pixels.
function vibrant(bm) {
const n = 24, cv = new OffscreenCanvas(n, n), cx = cv.getContext("2d", { willReadFrequently: true });
cx.drawImage(bm, 0, 0, n, n);
const d = cx.getImageData(0, 0, n, n).data, px = [];
for (let i = 0; i < d.length; i += 4) {
const r = d[i] / 255, g = d[i + 1] / 255, b = d[i + 2] / 255, mx = Math.max(r, g, b), mn = Math.min(r, g, b), c = mx - mn;
const h = !c ? 0 : mx === r ? ((g - b) / c + 6) % 6 / 6 : mx === g ? ((b - r) / c + 2) / 6 : ((r - g) / c + 4) / 6, s = mx ? c / mx : 0;
px.push([h, s, mx, s * (1 - Math.abs(mx - 0.55) * 1.4)]);
}
const top = px.sort((a, b) => b[3] - a[3]).slice(0, px.length / 6);
let x = 0, y = 0, s = 0, v = 0;
for (const p of top) { x += Math.cos(p[0] * 2 * Math.PI); y += Math.sin(p[0] * 2 * Math.PI); s += p[1]; v += p[2]; }
return s / top.length < 0.12 ? null : [(Math.atan2(y, x) / (2 * Math.PI) + 1) % 1, s / top.length, v / top.length];
}
const ArtTheme = {
url: "", hsv: null, seq: 0, cache: new Map(),
async set(url) {
if (!S.artTheme) url = "";
if (url === this.url) return;
this.url = url;
const n = ++this.seq;
let hsv = url ? this.cache.get(url) : null;
if (url && !this.cache.has(url)) {
try {
const r = await fetch(url, { signal: AbortSignal.timeout(8000) });
hsv = vibrant(await createImageBitmap(await r.blob()));
this.cache.set(url, hsv);
} catch { hsv = null; }
if (n !== this.seq) return;
}
this.hsv = hsv; applyTheme();
},
};
function applyTheme() {
const t = THEMES[S.theme] || THEMES.graphite, a = S.accent || t.accent;
const base = THEMES[S.theme] || THEMES.graphite, t = ArtTheme.hsv ? artPalette(ArtTheme.hsv, base) : base, a = ArtTheme.hsv ? t.accent : S.accent || t.accent;
$("#theme").textContent = `:root{--bg:${t.bg};--panel:${t.panel};--raised:${t.raised};--line:${t.line};--text:${t.text};--muted:${t.muted};` +
`--accent:${a};--accent-ink:${inkFor(a)};--glass:${t.panel}ee;--hover:${t.text}0d;--shadow:${t.light ? "#0003" : "#0009"};` +
`--wave:${t.text}44;--wave-ghost:${t.text}14;color-scheme:${t.light ? "light" : "dark"}}`;
@@ -174,7 +221,7 @@ const UI = {
$("#np-title").textContent = st.name;
$("#np-sub").textContent = "Web Radio";
$("#np-art").removeAttribute("src");
$("#b-art").hidden = true; SideArt.fill();
$("#b-art").hidden = true; SideArt.fill(); ArtTheme.set("");
document.title = `${st.name} · Stemify`;
if ("mediaSession" in navigator) navigator.mediaSession.metadata = new MediaMetadata({ title: st.name, artist: "Web Radio" });
return;
@@ -185,7 +232,7 @@ const UI = {
$("#np-sub").textContent = t ? [t.artist, t.album].filter(Boolean).join(" · ") : "";
const art = artOf(t, 120);
if (art) $("#np-art").src = art; else $("#np-art").removeAttribute("src");
$("#b-art").hidden = !art; SideArt.fill();
$("#b-art").hidden = !art; SideArt.fill(); ArtTheme.set(artOf(t, 64));
document.title = t ? `${t.title} · Stemify` : "Stemify";
if ("mediaSession" in navigator) {
navigator.mediaSession.metadata = t ? new MediaMetadata({
@@ -1177,6 +1224,7 @@ function renderSettings() {
<div class="sg"><div class="sr col"><div class="sl"><span>Theme</span></div>
<div class="themes">${Object.entries(THEMES).map(([k, t]) => `<button class="swatch ${S.theme === k ? "on" : ""}" data-theme="${k}" style="background:${t.bg};color:${t.text};border-color:${t.line}"><i style="background:${t.accent}"></i>${k[0].toUpperCase() + k.slice(1)}</button>`).join("")}</div></div>
${srow("Accent", `${S.accent ? `<button class="btn small" id="accentreset">Reset</button>` : ""}<input type="color" id="accent" value="${S.accent || theme.accent}">`)}
${stog("Match album art", sw(`id="arttheme"`, S.artTheme))}
${stog("Call the vocals-only preset “Acapella”", sw(`id="acapella"`, S.acapella))}</div>
<h3 class="sgh">Player bar</h3>
<div class="sg">${BAR.map(([k, l]) => stog(l, sw(`data-bar="${k}"`, S.bar[k]))).join("")}</div>
@@ -1238,6 +1286,7 @@ function renderSettings() {
const ahead = v => { S.precache = Math.max(0, Math.min(50, Math.round(+v || 0))); $("#precache").value = $("#precachen").value = S.precache; save(); };
$("#precache").oninput = ev => ahead(ev.target.value);
$("#precachen").onchange = ev => ahead(ev.target.value);
$("#arttheme").onchange = ev => { S.artTheme = ev.target.checked; save(); ArtTheme.set(S.artTheme ? artOf(Q.cur(), 64) : ""); };
$("#acapella").onchange = ev => { S.acapella = ev.target.checked; save(); emit("presets"); emit("mix"); };
if ($("#forgetall")) $("#forgetall").onclick = () => { for (const k of Object.keys(songMixes)) forgetSongMix(k); again(); };
$("#kon").onchange = ev => setKaraoke(ev.target.checked);
+1 -1
View File
@@ -24,7 +24,7 @@ export const S = Object.assign({
acapella: false, // spell "A Cappella" as "Acapella"
bar: { speed: true, mixer: true, lyrics: true, queue: true }, // player bar buttons
stations: [], // web radio: [{id, name, url}]
theme: "graphite", accent: "", css: "", sideArt: false,
theme: "graphite", accent: "", css: "", sideArt: false, artTheme: false,
}, load(KEY) || {});
if (!S.clientId) S.clientId = uuid();
+4 -3
View File
@@ -8,7 +8,7 @@
--accent: #3a81ed;
--accent-ink: #ffffff;
--radius: 6px;
--player-h: 90px;
--player-h: 100px;
--nav-w: 240px;
--glass: #101010ee;
--hover: #e7e7e70d;
@@ -330,6 +330,7 @@ input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }
.q-item .x { color: var(--muted); font-size: 18px; padding: 0 4px; opacity: 0; }
.q-item:hover .x { opacity: 1; }
body, #nav, #player, .sg { transition: background-color .5s; }
#player { position: fixed; left: 0; right: 0; bottom: 0; height: var(--player-h); background: var(--bg);
border-top: 1px solid rgba(50, 50, 50, .7); display: grid; grid-template-columns: minmax(180px, 1fr) minmax(320px, 1.6fr) minmax(180px, 1fr); align-items: center; gap: 20px; padding: 0 20px; }
#player.empty .center, #player.empty .right, #player.empty #b-art { opacity: .35; pointer-events: none; }
@@ -347,7 +348,7 @@ input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }
.np-text { min-width: 0; }
#np-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#np-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.center { display: grid; gap: 4px; }
.center { display: grid; gap: 10px; }
.transport { display: flex; justify-content: center; align-items: center; gap: 20px; font-size: 18px; }
.transport button { color: #c5c5c5; }
.transport button:hover { color: #fff; }
@@ -374,7 +375,7 @@ input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }
input[type=range] { accent-color: var(--accent); }
@media (max-width: 860px) {
:root { --player-h: 150px; }
:root { --player-h: 162px; }
#app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
#nav { flex-direction: row; overflow-x: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); align-items: center; }
.brand { padding: 0 8px 0 4px; }