sidebar: a page's row under the pointer is lit as by a torch, as a sub-list's is

The owner asked why the sidebar's page rows (Providers, Routing, Gateway…)
had no torch light when the sub-lists under them do (876d477d7). They now
light the same way: brightest where the pointer is, falling off along the
word, the rest of the row a step up, one row at a time; Settings at the
foot too. The open page's row is never lit, a touch lights nothing.

- navlamp.js: the row is a sub-list's row or, in the sidebar, a page's row
  (#nav > button[data-view], #prefs); the word is the row's own span; the
  open page (.on) is skipped as the sub-list's .cur is.
- app.css: the lit word's ground ink is the row's own (--lo): the page rows
  rest at --fg-2, the sub-rows at --ctl-fg as before; the page rows' plain
  hover ink stands down while the lamp is on, as the sub-rows' does. Their
  hover ground is unchanged.
- app.js: the lamp is loaded when the pointer first comes over the sidebar,
  not when a sub-list is drawn. Loaded when the sidebar was laid out, its
  fetch held up the open page's arrival past navTopGo's two frames, and
  the selection shape glided from Agents (sidebar-glide red 2 of 5 on
  Windows chromium, 0 of 6 at the base 5d955a4d4). A comment's
  cross-reference was cut so app.js is 39 bytes under main, no raise.

Rebased on a511b11d8; at that head (8fcefff51 before this message):
- nav-lamp, old-webkit, sidebar-glide, sidebar on Windows, both engines:
  56 pass, 0 fail; the Budget test on mote: ok.

Tests: nav-lamp.test.cjs gets a page-row test (both engines, dark/light,
en/zh): brightest at the pointer's end of 供应商/Providers by pixels, one
row lit, Gateway then Settings taking it, all out off the sidebar, the open
page's row never lit.

Run before the last rebase (on 5d955a4d4, then 47173f593):
- nav-lamp + old-webkit + sidebar + side-toggle + rail-tip on xiaomi-gpu
  (Windows), both engines: 74 pass, 0 fail. sidebar-glide chromium 6 of 6.
  mote ran chromium only (webkit timed out at launch, load 37).
- go test -tags nogui -run Budget ./internal/gui on mote: ok.
- The sidebar's look files (18 files) on Windows at the first version:
  header-centre webkit, mobile-web, omarchy and i18n-keys' "a plugin's
  words are its own" red, the same at the base 5d955a4d4 run beside it
  (plugins/routing "Unmarked" shared with a Go test; not mine, not filed
  here).
- A screenshot (zh dark) shows 供 lit, 应商 falling off.

Broken by hand: the page rows taken out of navlamp.js's selector, the new
test red in every case, the sub-list's still green; put back.

Not tried: the real app on Linux (WebKitGTK) and Windows (WebView2), the
whole GUI suite.
This commit is contained in:
yetone
2026-10-31 18:07:01 +08:00
parent 6b8261029b
commit 8410258364
5 changed files with 95 additions and 21 deletions
+12 -9
View File
@@ -433,22 +433,25 @@ body.side-nav #nav button.has-dot::after { top: 50%; right: 10px; margin-top: -3
before the selection slides there */
.nav-s:hover:not(.cur) { color: var(--fg); }
.nav-s.cur { color: var(--fg); font-weight: 500; }
/* the row under the pointer is lit as by a torch (navlamp.js): --lx is the
pointer's place in the word, --si how lit the row is. Its heart is a step
past the text's ink (--fg taken to white in dark, black in light), the
rest of the row 15% of the way to it, and the plain hover above stands
down. Where color-mix is missing (Safari 15) the plain hover stays. */
/* the row under the pointer is lit as by a torch (navlamp.js), a page's
row and a sub-list's alike: --lx is the pointer's place in the word, --si
how lit the row is, --lo the row's own ink. Its heart is a step past the
text's ink (--fg taken to white in dark, black in light), the rest of the
row 15% of the way to it, and the plain hover above stands down. Where
color-mix is missing (Safari 15) the plain hover stays. */
@supports (color: color-mix(in oklab, red, blue)) {
.navlamp .nav-s:hover:not(.cur) { color: var(--ctl-fg); }
.nav-s > span.lit {
.navlamp body.side-nav :is(#nav button[data-view], #prefs):hover:not(.on) { color: var(--fg-2); }
.navlamp body.side-nav :is(#nav button[data-view], #prefs) > span { --lo: var(--fg-2); }
:is(.nav-s, #nav button, #prefs) > span.lit {
--hi: var(--fg);
--hot: color-mix(in oklab, var(--hi) calc(var(--si) * 100%), var(--ctl-fg));
--far: color-mix(in oklab, var(--fg) calc(var(--si) * 15%), var(--ctl-fg));
--hot: color-mix(in oklab, var(--hi) calc(var(--si) * 100%), var(--lo, var(--ctl-fg)));
--far: color-mix(in oklab, var(--fg) calc(var(--si) * 15%), var(--lo, var(--ctl-fg)));
background: radial-gradient(36px 400px at var(--lx) 50%, var(--hot) 0%, var(--hot) 12%, color-mix(in oklab, var(--hot) 45%, var(--far)) 45%, var(--far) 100%);
-webkit-background-clip: text; background-clip: text; color: transparent;
}
}
@supports (color: oklch(from red round(l) c h)) { .nav-s > span.lit { --hi: oklch(from var(--fg) round(l) 0 h); } }
@supports (color: oklch(from red round(l) c h)) { :is(.nav-s, #nav button, #prefs) > span.lit { --hi: oklch(from var(--fg) round(l) 0 h); } }
/* a row pressed darkens, as a Mac sidebar's does: it never shrinks the way a
button does (.seg button:active, .icon:active below) */
body.side-nav #side button:active { transform: none; }
+2 -3
View File
@@ -23471,8 +23471,7 @@ document.fonts?.addEventListener("loadingdone", fitTop);
// ("Work / Library / MCP servers"). Narrower, and magpie web on a phone,
// the pages go back into the header as tabs and each page shows its own
// tabs again, as iPadOS's sidebar turns into a tab bar when it has no room.
// It is the same #nav, moved between the two. (app.css's side-nav rules
// hold at the same width: narrower than Usage's requests, 768 points)
// It is the same #nav, moved between the two.
var SIDE_AT = 1024;
var sideQuery = matchMedia(`(min-width: ${SIDE_AT}px)`);
function sideNav() { return document.body.classList.contains("side-nav"); }
@@ -23500,6 +23499,7 @@ function layoutNav() {
side.hidden = !on;
$("#crumb").hidden = !on;
if (on) {
side.addEventListener("pointerover", () => import("./navlamp.js").catch(() => {}), { once: true });
side.querySelector(".side-top").append(btn, brand);
side.querySelector(".side-scroll").append(nav);
side.querySelector(".side-foot").prepend(prefs);
@@ -23717,7 +23717,6 @@ function navSubs() {
const fresh = !box;
if (fresh) {
box = el("div", "nav-sub");
import("./navlamp.js").catch(() => {});
box.setAttribute("role", "tablist");
box.dataset.view = view;
box.append(el("i", "nav-hl"));
+8 -6
View File
@@ -1,16 +1,18 @@
// The sidebar's sub-lists light the row under the pointer as a torch would:
// The sidebar lights the row under the pointer as a torch would, in its
// pages (Providers, Routing…, Settings) and their sub-lists alike:
// brightest where it points, the rest of that row a step up from the
// others, which keep their own ink (app.css, .nav-s > span.lit). The light
// others, which keep their own ink (app.css, span.lit). The light
// follows the pointer with a little lag and fades out as it moves on; with
// reduced motion it is where the pointer is at once. Imported by app.js
// when a sub-list is first drawn; a touch never lights a row.
// when the pointer first comes over the sidebar (layoutNav), not at start,
// where it held up the open page's row; a touch never lights a row.
document.documentElement.classList.add("navlamp");
const lit = new Map(); // a row's word -> how lit it is, 0 to 1
let at = null, tx = 0, x = 0, raf = 0;
function frame() {
raf = 0;
const still = calm(), row = at && at.isConnected && !at.parentElement.classList.contains("cur") ? at : null;
const still = calm(), row = at && at.isConnected && !at.parentElement.matches(".cur, .on") ? at : null;
if (row && !lit.has(row)) lit.set(row, 0);
x = still ? tx : x + (tx - x) * 0.22;
let busy = Math.abs(tx - x) > 0.3;
@@ -34,8 +36,8 @@ function frame() {
const go = () => { if (!raf) raf = requestAnimationFrame(frame); };
document.addEventListener("pointermove", (e) => {
const row = e.pointerType === "touch" || !e.target.closest ? null : e.target.closest(".nav-sub > .nav-s");
const word = row && row.querySelector("span");
const row = e.pointerType === "touch" || !e.target.closest ? null : e.target.closest(".nav-sub > .nav-s, body.side-nav :is(#nav > button[data-view], #prefs)");
const word = row && row.querySelector(":scope > span");
if (word && !at) x = e.clientX;
tx = e.clientX;
if (word !== at) at = word;
+71 -1
View File
@@ -8,7 +8,8 @@
// motion the light is there at once. Read from the pixels: the ink near
// the pointer stands further off the ground than the word's far end, and
// both ends turn when the pointer goes to the other end. Both engines,
// light and dark, English and Chinese.
// light and dark, English and Chinese. The sidebar's page rows (Providers,
// Routing, Gateway…) and Settings are lit the same way.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -76,7 +77,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", serve(lang, theme));
await page.goto("http://magpie.test/?view=settings");
await page.waitForSelector(".nav-sub > .nav-s + .nav-s");
await page.mouse.move(40, 300); // over the sidebar, which loads the lamp
await page.waitForFunction(() => document.documentElement.classList.contains("navlamp"));
await page.mouse.move(700, 500);
await page.waitForTimeout(600); // the list's own unrolling
let all = await words(page);
assert(all.every((w) => !w.lit), "nothing lit before the pointer comes");
@@ -133,3 +136,70 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
});
}
// a page row's word (Providers, Routing…, Settings): its box, whether lit,
// whether its page is open
const tops = (page) => page.$$eval("#side :is(#nav > button[data-view], #prefs) > span", (all) => all.filter((s) => s.offsetWidth).map((s) => {
const b = s.getBoundingClientRect();
return { x: b.left, y: b.top, w: b.width, h: b.height, lit: s.classList.contains("lit"), on: s.parentElement.classList.contains("on"), id: s.parentElement.dataset.view || s.parentElement.id };
}));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: a page row in the sidebar is lit as by a torch`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const theme of ["dark", "light"]) for (const lang of ["en", "zh"]) await t.test(`${theme} ${lang}`, async () => {
const context = await browser.newContext({ viewport: { width: 1024, height: 800 }, colorScheme: theme });
t.after(() => context.close());
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, theme));
await page.goto("http://magpie.test/?view=agents");
await page.waitForSelector("body.side-nav #side #nav > button[data-view]");
await page.mouse.move(40, 300); // over the sidebar, which loads the lamp
await page.waitForFunction(() => document.documentElement.classList.contains("navlamp"));
await page.mouse.move(700, 500);
await page.waitForTimeout(400);
let all = await tops(page);
assert(all.length >= 4 && all.some((w) => w.id === "prefs"), `the page rows and Settings: ${JSON.stringify(all.map((w) => w.id))}`);
assert(all.every((w) => !w.lit), "nothing lit before the pointer comes");
const at = (id) => all.findIndex((w) => w.id === id);
const lit = (i) => page.waitForFunction((i) => { const s = [...document.querySelectorAll("#side :is(#nav > button[data-view], #prefs) > span")].filter((s) => s.offsetWidth)[i]; return s.classList.contains("lit") && +s.style.getPropertyValue("--si") > 0.99; }, i);
const out = (i) => page.waitForFunction((i) => ![...document.querySelectorAll("#side :is(#nav > button[data-view], #prefs) > span")].filter((s) => s.offsetWidth)[i].classList.contains("lit"), i);
const pv = at("providers"), gw = at("gateway"), prefs = at("prefs"), word = all[pv];
// at the word's start, the start stands off the ground more than its end
await page.mouse.move(word.x + 2, word.y + word.h / 2);
await lit(pv);
await page.waitForTimeout(400);
const atStart = await ink(page, word);
assert(atStart.start > atStart.end + 12, `brightest where the pointer is: ${JSON.stringify(atStart)}`);
assert.equal((await tops(page)).filter((w) => w.lit).length, 1, "only the row under the pointer is lit");
await page.mouse.move(word.x + word.w - 2, word.y + word.h / 2, { steps: 8 });
await page.waitForTimeout(600);
const atEnd = await ink(page, word);
assert(atEnd.end > atEnd.start + 12, `the light follows the pointer: ${JSON.stringify(atEnd)}`);
// to Gateway, then Settings: each takes the light from the one before
await page.mouse.move(all[gw].x + 4, all[gw].y + all[gw].h / 2, { steps: 4 });
await lit(gw);
await out(pv);
await page.mouse.move(all[prefs].x + 4, all[prefs].y + all[prefs].h / 2, { steps: 4 });
await lit(prefs);
await out(gw);
await page.mouse.move(700, 500);
await out(prefs);
// the open page's row keeps its own ink
const cur = all.find((w) => w.on);
assert(cur, "a page is open");
await page.mouse.move(cur.x + 4, cur.y + cur.h / 2);
await page.waitForTimeout(200);
assert((await tops(page)).every((w) => !w.lit), "the open page's row is never lit");
assert.deepEqual(errors, []);
});
});
}
+2 -2
View File
@@ -147,8 +147,8 @@ test("compat.js is the first of the page's own scripts", async () => {
// a provider editor draws its rate windows, traywindows.js when the menu
// bar shows a card, autoresetown.js when Settings draws Codex's auto-use
// rows, registry.js when Plugins draws its npm registry, navlamp.js when
// the sidebar draws a sub-list, whatsnew.js when release notes open; the
// checks above still read them
// the pointer comes over the sidebar, whatsnew.js when release notes
// open; the checks above still read them
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
});