Web: sidebar playlists fixed for 1080p, side album art, vertical stem faders with live meters

- Nav scrolls, playlists section always gets room, boot race fixed (waits on connect)
- Album art expands into the left sidebar (Feishin style), collapses on hover button
- Mixer: tall vertical channel strips with per-stem peak meters (AnalyserNode, rAF, transform-only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-11-19 21:57:24 -08:00
1 parent 115eb28bdf
commit f624a9866a
5 files changed
+165 -100

No files matched your search

+81 -49
View File
@@ -148,19 +148,20 @@ let drawer = null; // "mixer" | "lyrics" | "queue"
const Lyr = { id: null, data: null, idx: -1 };
const artOf = (t, size) => t?.srv ? img(t.srv, t.thumb, size) : "";
// Full-size album art over the content area, opened from the art in the player bar.
const Big = {
el: null,
open() { if (!Q.cur() || Radio.station) return; this.el.hidden = false; this.fill(); },
close() { if (this.el) this.el.hidden = true; },
// Feishin-style big art at the foot of the sidebar, opened from the art in the player bar.
const wide = matchMedia("(min-width: 861px)");
const SideArt = {
src: "",
show(on) { S.sideArt = on; save(); this.fill(); },
fill() {
const o = this.el;
if (!o || o.hidden) return;
const t = Q.cur(), src = artOf(t, 1000);
if (!src) return this.close();
if (o.dataset.src !== src) { o.dataset.src = src; o.querySelector("img").src = src; o.querySelector(".bg").style.backgroundImage = `url("${src}")`; }
o.querySelector(".t").textContent = t.title;
o.querySelector(".s").textContent = [t.artist, t.album].filter(Boolean).join(" · ");
const t = Radio.station ? null : Q.cur(), src = artOf(t, 640), on = !!(S.sideArt && src && wide.matches);
$("#app").classList.toggle("sideart", on);
$("#player").classList.toggle("sideart", on);
if (!on || src === this.src) return;
// Swap only once the new art has decoded, so it never flashes empty between tracks.
this.src = src;
const im = new Image(); im.src = src;
im.decode().catch(() => {}).then(() => { if (this.src === src) $("#sideart img").src = src; });
},
};
const UI = {
@@ -173,7 +174,7 @@ const UI = {
$("#np-title").textContent = st.name;
$("#np-sub").textContent = "Web Radio";
$("#np-art").removeAttribute("src");
$("#b-art").hidden = true; Big.close();
$("#b-art").hidden = true; SideArt.fill();
document.title = `${st.name} · Stemify`;
if ("mediaSession" in navigator) navigator.mediaSession.metadata = new MediaMetadata({ title: st.name, artist: "Web Radio" });
return;
@@ -184,7 +185,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; Big.fill();
$("#b-art").hidden = !art; SideArt.fill();
document.title = t ? `${t.title} · Stemify` : "Stemify";
if ("mediaSession" in navigator) {
navigator.mediaSession.metadata = t ? new MediaMetadata({
@@ -206,6 +207,7 @@ const UI = {
for (const d of ["mixer", "lyrics", "queue"]) $(`#b-${d}`).classList.toggle("on", drawer === d);
$("#b-mixer").classList.toggle("dot", S.karaoke);
if ("mediaSession" in navigator) navigator.mediaSession.playbackState = playing ? "playing" : "paused";
if (drawer === "mixer") Meter.start();
},
progress() {
$("#t-pos").textContent = E.loading ? `${Math.round(E.loadFrac * 100)}%` : fmtTime(E.position());
@@ -225,6 +227,7 @@ const UI = {
d.innerHTML = tabs + `<div id="dbody">${drawer === "mixer" ? mixerHtml() : drawer === "queue" ? queueHtml() : lyricsShell()}</div>`;
if (drawer === "lyrics") loadLyrics();
if (drawer === "queue") $(".q-item.cur", d)?.scrollIntoView({ block: "center" });
d.classList.toggle("mixing", drawer === "mixer");
}
this.transport();
},
@@ -262,14 +265,15 @@ function mixerHtml() {
if (!names.length) return `<p class="note">${E.loading ? "Loading stems…" : Q.cur() ? "This track has no stems yet. Right-click it and pick Stem Now." : "Play something with stems to mix it."}</p>`;
return `<div id="mixer" data-names="${esc(names.join(","))}">
<div class="presets">${presetsHtml(names)}</div>
${names.map(n => {
<div class="strips">${names.map(n => {
const s = setting(n);
return `<div class="stem ${stemGain(n, names) ? "" : "silent"} ${s.muted ? "muted" : ""}" data-stem="${esc(n)}" style="--c:${STEM_COLORS[n] || "#8e8e93"}">
<div class="fader" data-fader="${esc(n)}" role="slider" tabindex="0" aria-label="${esc(n)} level" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${Math.round(s.level * 100)}" style="--v:${pct(s.level)}">
<span class="name">${esc(n)}</span><span class="pct">${pct(s.level)}</span></div>
<button class="ms mute ${s.muted ? "on" : ""}" data-mute="${esc(n)}" title="Mute">M</button>
<button class="ms solo ${s.solo ? "on" : ""}" data-solo="${esc(n)}" title="Solo">S</button></div>`;
}).join("")}
<div class="pct">${pct(s.level)}</div>
<div class="fader" data-fader="${esc(n)}" role="slider" aria-orientation="vertical" tabindex="0" aria-label="${esc(n)} level" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${Math.round(s.level * 100)}" style="--v:${s.level}">
<i class="lvl"></i><i class="mtr"></i><i class="cap"><b></b></i></div>
<div class="name" title="${esc(n)}">${esc(n)}</div>
<div class="msrow"><button class="ms mute ${s.muted ? "on" : ""}" data-mute="${esc(n)}" title="Mute">M</button><button class="ms solo ${s.solo ? "on" : ""}" data-solo="${esc(n)}" title="Solo">S</button></div></div>`;
}).join("")}</div>
<div id="mixfoot">${mixFoot(names)}</div></div>`;
}
// Updates the open mixer in place, so taps answer at once and the slider being dragged keeps
@@ -292,9 +296,30 @@ function syncMixer() {
}
const paintFader = (f, v) => {
const p = pct(v);
if (f.style.getPropertyValue("--v") === p) return;
f.style.setProperty("--v", p); f.setAttribute("aria-valuenow", Math.round(v * 100)); f.querySelector(".pct").textContent = p;
if (f.style.getPropertyValue("--v") === String(v)) return;
f.style.setProperty("--v", v); f.setAttribute("aria-valuenow", Math.round(v * 100)); f.parentNode.querySelector(".pct").textContent = pct(v);
};
// Live meters: each stem's bar rises and falls with its audio (pre-fader peak, shown under the
// fader's level like the iOS mixer). Runs on animation frames only while the mixer is open and
// playing or still falling, and writes nothing but transforms.
const Meter = {
raf: 0, rows: null, box: null, shown: new Map(),
start() { if (!this.raf) this.raf = requestAnimationFrame(this.tick); },
tick: () => {
const M = Meter, box = $("#mixer");
M.raf = 0;
if (!box || drawer !== "mixer" || document.hidden) return;
if (M.box !== box) { M.box = box; M.rows = [...box.querySelectorAll(".stem")].map(r => ({ n: r.dataset.stem, el: r.querySelector(".mtr") })); M.shown.clear(); }
const playing = E.playing && !E.buffering, names = mixNames();
let moving = false;
for (const r of M.rows) {
const st = setting(r.n), live = playing && stemGain(r.n, names) ? E.meter(r.n) * st.level : 0;
const prev = M.shown.get(r.n) || 0, v = live >= prev ? live : Math.max(live, prev - 0.025);
if (Math.abs(v - prev) > 0.002 || (v === 0 && prev !== 0)) { r.el.style.transform = `scaleY(${v.toFixed(3)})`; M.shown.set(r.n, v); }
if (v > 0) moving = true;
}
if (playing || moving) M.start();
},
};
// Sets a stem's level live; the save and mixer refresh wait until the gesture settles.
let levelSave = 0;
@@ -362,30 +387,27 @@ d$.addEventListener("click", ev => {
else if (ds.q) Q.jump(+ds.q);
else if (ds.li) E.seek(Lyr.data.lines[+ds.li].t);
});
// Faders: a mouse sets the level where it presses and drags from there. A finger has to move
// sideways first (or tap) so scrolling the drawer never changes a level.
// Faders: vertical. Grabbing the cap (or any touch) moves it from where it is; a mouse press
// elsewhere on the track jumps there first. Touches never scroll the drawer from a fader.
{
let drag = null;
const at = (f, x) => { const r = f.getBoundingClientRect(); setLevel(f.dataset.fader, (x - r.left) / r.width); };
const span = r => r.height - 8, val = (r, y) => (r.bottom - 4 - y) / span(r);
d$.addEventListener("pointerdown", ev => {
const f = ev.target.closest(".fader");
if (!f || ev.button) return;
drag = { f, id: ev.pointerId, x0: ev.clientX, y0: ev.clientY, on: ev.pointerType === "mouse" };
if (drag.on) { ev.preventDefault(); f.setPointerCapture(ev.pointerId); f.classList.add("drag"); at(f, ev.clientX); }
ev.preventDefault();
const n = f.dataset.fader, r = f.getBoundingClientRect(), v = setting(n).level;
const onCap = Math.abs(ev.clientY - (r.bottom - 4 - v * span(r))) < 14;
drag = { f, n, id: ev.pointerId, y0: ev.clientY, v0: v, r, rel: onCap || ev.pointerType !== "mouse" };
f.setPointerCapture(ev.pointerId); f.classList.add("drag");
if (!drag.rel) setLevel(n, val(r, ev.clientY));
});
d$.addEventListener("pointermove", ev => {
if (!drag || ev.pointerId !== drag.id) return;
if (!drag.on) {
const dx = Math.abs(ev.clientX - drag.x0), dy = Math.abs(ev.clientY - drag.y0);
if (dy > 8 && dy > dx) { drag = null; return; }
if (dx < 6) return;
drag.on = true; drag.f.setPointerCapture(ev.pointerId); drag.f.classList.add("drag");
}
at(drag.f, ev.clientX);
setLevel(drag.n, drag.rel ? drag.v0 + (drag.y0 - ev.clientY) / span(drag.r) : val(drag.r, ev.clientY));
});
const end = ev => {
if (!drag || ev.pointerId !== drag.id) return;
if (!drag.on && ev.type === "pointerup") at(drag.f, ev.clientX);
drag.f.classList.remove("drag"); drag = null;
};
d$.addEventListener("pointerup", end);
@@ -395,7 +417,7 @@ d$.addEventListener("click", ev => {
const f = ev.target.closest(".fader");
if (!f) return;
ev.preventDefault();
setLevel(f.dataset.fader, setting(f.dataset.fader).level - Math.sign(ev.deltaY || -ev.deltaX) * 0.02);
setLevel(f.dataset.fader, setting(f.dataset.fader).level - Math.sign(ev.deltaY || ev.deltaX) * 0.02);
}, { passive: false });
d$.addEventListener("keydown", ev => {
const f = ev.target.closest(".fader");
@@ -477,9 +499,10 @@ function applyBar() {
$("#speed").style.display = S.bar.speed ? "" : "none";
for (const k of ["mixer", "lyrics", "queue"]) $(`#b-${k}`).style.display = S.bar[k] ? "" : "none";
}
Big.el = $("#bigart");
Big.el.onclick = () => Big.close();
$("#b-art").onclick = ev => { ev.stopPropagation(); Big.open(); };
$("#b-art").onclick = ev => { if (wide.matches) { ev.stopPropagation(); SideArt.show(true); } };
$("#sideart .sa-col").onclick = () => SideArt.show(false);
$("#sideart .sa-img").onclick = () => { const t = Q.cur(); if (t?.albumKey) location.hash = `#/album/${t.srv}:${t.albumKey}`; };
wide.addEventListener("change", () => SideArt.fill());
$(".np").onclick = () => { const t = Q.cur(); if (t?.albumKey) location.hash = `#/album/${t.srv}:${t.albumKey}`; };
if ("mediaSession" in navigator) {
@@ -492,7 +515,7 @@ if ("mediaSession" in navigator) {
}
document.addEventListener("keydown", ev => {
if (ev.key === "Escape") { Big.close(); return Menu.close(); }
if (ev.key === "Escape") return Menu.close();
if (ev.target.closest("input, select, textarea") || ev.metaKey || ev.ctrlKey || ev.altKey) return;
const k = ev.key.toLowerCase();
if (k === " ") { ev.preventDefault(); togglePlay(); }
@@ -897,7 +920,7 @@ const routes = {
if (my !== seq) return;
pls = st.random ? pls.sort(() => Math.random() - 0.5) : pls.sort(comparator(st.param));
count(pls.length + playlists.length, "playlist");
navPls = [...pls].sort((a, b) => a.title.localeCompare(b.title)); navPlaylists();
navPls = [...pls].sort((a, b) => (a.title || "").localeCompare(b.title || "")); navState = "ok"; navPlaylists();
$("#plexpl").innerHTML = pls.length ? `<div class="grid">${pls.map(p => card({ href: `#/playlist/${p._srv}:${p.ratingKey}`, img: img(p._srv, p.thumb || p.composite), fb: p.composite && rawImg(p._srv, p.composite), t: p.title, s: plural(p.leafCount || 0, "track"), kind: "playlist", srv: p._srv, key: p.ratingKey })).join("")}</div>`
: `<p class="empty-msg">No music playlists.</p>`;
},
@@ -985,15 +1008,22 @@ const routes = {
// Sidebar playlist list: stem playlists, then Plex ones (fetched at start and on the Playlists page).
let navPls = [], navHtml = "";
let navState = "loading";
const STEMDOT = '<svg viewBox="0 0 24 24"><path d="M5 10h2v10H5zm4-6h2v16H9zm4 8h2v8h-2zm4-4h2v12h-2z"/></svg>';
function navPlaylists() {
const box = $("#nav-pl"), html = playlists.map(p => `<a href="#/stemplaylist/${p.id}">${esc(p.title)}</a>`).join("")
+ navPls.map(p => `<a href="#/playlist/${p._srv}:${p.ratingKey}">${esc(p.title)}</a>`).join("");
const box = $("#nav-pl"), html = playlists.map(p => `<a href="#/stemplaylist/${p.id}" title="${esc(p.title)} · stem playlist"><span>${esc(p.title)}</span>${STEMDOT}</a>`).join("")
+ navPls.map(p => `<a href="#/playlist/${p._srv}:${p.ratingKey}" title="${esc(p.title)}"><span>${esc(p.title)}</span></a>`).join("")
|| `<p class="nav-empty">${navState === "loading" ? "Loading…" : navState === "none" ? "No Plex server set up." : "No playlists yet."}</p>`;
if (html !== navHtml) { navHtml = html; box.innerHTML = html; }
for (const a of box.children) a.classList.toggle("on", a.getAttribute("href") === location.hash);
}
async function loadNavPlaylists() {
if (!liveServers().length) return;
try { navPls = (await everything(liveServers().map(srv => ({ srv })), "/playlists", { playlistType: "audio" })).sort((a, b) => a.title.localeCompare(b.title)); } catch {}
await connecting;
if (!liveServers().length) navState = "none";
else {
try { navPls = (await everything(liveServers().map(srv => ({ srv })), "/playlists", { playlistType: "audio" })).sort((a, b) => (a.title || "").localeCompare(b.title || "")); } catch {}
navState = "ok";
}
navPlaylists();
}
@@ -1207,7 +1237,7 @@ function renderSettings() {
navigator.storage?.estimate?.().then(e => { const el = $("#storage-info"); if (el && e?.quota) el.insertAdjacentText("afterbegin", `${fmtBytes(e.usage)} of ${fmtBytes(e.quota)} used. `); }).catch(() => {});
const again = () => { if (location.hash.startsWith("#/settings")) renderSettings(); };
const plexChanged = () => { genreCache = null; save(); };
const plexChanged = () => { genreCache = null; save(); loadNavPlaylists(); };
$("#signin").onclick = async () => {
const st = $("#sstatus");
try { const ok = await signIn(m => { st.textContent = m; }); plexChanged(); toast(`Added ${plural(ok.length, "server")}`); again(); }
@@ -1305,16 +1335,18 @@ async function connect() {
save();
}
let connecting = null;
(async () => {
applyTheme();
applyStemFilter();
applyBar();
await Offline.init();
await Promise.race([connect(), new Promise(r => setTimeout(r, 5000))]);
connecting = connect();
await Promise.race([connecting, new Promise(r => setTimeout(r, 5000))]);
Q.restore();
UI.all();
route();
loadNavPlaylists();
Live.poll();
setInterval(() => { if (!document.hidden) Stems.refresh(); }, 5 * 60 * 1000);
setInterval(() => { if (!document.hidden) { Stems.refresh(); loadNavPlaylists(); } }, 5 * 60 * 1000);
})();