gui: the header's other views and the text buttons read at WCAG AA, and the view shown stands off the switch (#477: in light mode an unselected tab read at 3.25:1, a text button at 3.33:1 on the page; dark passed by 0.08) — both were drawn in --muted (#85858d light, #8b8b94 dark), meant for captions, not controls, and the thumb on the view shown was white on a pill-grey track (1.13:1) or a 10% white on a 4.5% one (1.36:1). A control's quiet text now has its own colour, --ctl-fg (#63636b light, #a1a1aa dark), for the switch's other views, the Accounts and Sessions switches on the same track, and every .text button: 4.79:1 on the light track, 5.4 to 6.0:1 on the page, a card and the inset editor, 6.1:1 and up in dark. The light track is a shade deeper (#e6e6eb) and its thumb's edge a little firmer, 1.24:1 against it; dark's track is 3.5% white and its thumb 15%, 1.61:1. Sizes and weights are unchanged, so the header fits as before (#442/#457). seg-contrast.test.cjs (Chromium, WebKit, en, zh; light, dark, system dark) reads the computed colours, each background laid over the ones under it, and fails without the change. header-centre, header-zoom-fit, text-size, sessions-toolbar, click-scroll, old-webkit pass.
This commit is contained in:
+16
-10
@@ -5,9 +5,14 @@
|
||||
--card-2: #f9f9fb; /* expanded editor */
|
||||
--pill: #f1f1f4;
|
||||
--pill-hover: #e9e9ee;
|
||||
--seg-track: var(--pill); /* the header's view switch: its track and the thumb on the view shown */
|
||||
/* the header's view switch: its track and the thumb on the view shown, the
|
||||
track a shade deeper than a pill so the white thumb stands off it (#477) */
|
||||
--seg-track: #e6e6eb;
|
||||
--seg-thumb: var(--card);
|
||||
--seg-edge: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06);
|
||||
--seg-edge: 0 1px 2px rgba(0, 0, 0, .14), 0 0 0 .5px rgba(0, 0, 0, .08);
|
||||
/* a control's quiet text (the switch's other views, a text button): darker
|
||||
than --muted, so it reads at 4.5:1 or better on every surface it sits on */
|
||||
--ctl-fg: #63636b;
|
||||
--line: #e3e3e8;
|
||||
--line-2: #ececf0;
|
||||
--fg: #1c1c21;
|
||||
@@ -43,8 +48,8 @@
|
||||
--card-2: #1f1f23;
|
||||
--pill: #2d2d33;
|
||||
--pill-hover: #36363d;
|
||||
--seg-track: rgba(255, 255, 255, .045);
|
||||
--seg-thumb: rgba(255, 255, 255, .1);
|
||||
--seg-track: rgba(255, 255, 255, .035);
|
||||
--seg-thumb: rgba(255, 255, 255, .15);
|
||||
--seg-edge: inset 0 .5px 0 rgba(255, 255, 255, .08), 0 1px 2px rgba(0, 0, 0, .3);
|
||||
--line: #333339;
|
||||
--line-2: #2c2c32;
|
||||
@@ -52,6 +57,7 @@
|
||||
--fg-2: #b9b9c1;
|
||||
--muted: #8b8b94;
|
||||
--faint: #56565f;
|
||||
--ctl-fg: #a1a1aa;
|
||||
--accent: #a5b4fc;
|
||||
--accent-soft: #2b2c47;
|
||||
--accent-fg: #14142a;
|
||||
@@ -73,8 +79,8 @@
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #1a1a1e; --card: #232327; --card-2: #1f1f23; --pill: #2d2d33; --pill-hover: #36363d;
|
||||
--seg-track: rgba(255, 255, 255, .045); --seg-thumb: rgba(255, 255, 255, .1); --seg-edge: inset 0 .5px 0 rgba(255, 255, 255, .08), 0 1px 2px rgba(0, 0, 0, .3);
|
||||
--line: #333339; --line-2: #2c2c32; --fg: #ededf1; --fg-2: #b9b9c1; --muted: #8b8b94; --faint: #56565f;
|
||||
--seg-track: rgba(255, 255, 255, .035); --seg-thumb: rgba(255, 255, 255, .15); --seg-edge: inset 0 .5px 0 rgba(255, 255, 255, .08), 0 1px 2px rgba(0, 0, 0, .3);
|
||||
--line: #333339; --line-2: #2c2c32; --fg: #ededf1; --fg-2: #b9b9c1; --muted: #8b8b94; --faint: #56565f; --ctl-fg: #a1a1aa;
|
||||
--accent: #a5b4fc; --accent-soft: #2b2c47; --accent-fg: #14142a; --sel: #33345a;
|
||||
--green: #6fd99b; --green-soft: #1e3a2b; --red: #f28b82; --red-soft: #45272a; --amber: #f2b544; --amber-soft: #3f3220;
|
||||
--drift: #ff9592; --drift-soft: #3b1219;
|
||||
@@ -199,7 +205,7 @@ body.window:not(.mac):not(.linux):not(.web) .brand { display: none; } /* Windows
|
||||
}
|
||||
.seg > .thumb { border-radius: 6px; background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
body.panel .seg { display: none; }
|
||||
.seg button { position: relative; z-index: 1; white-space: nowrap; height: 24px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; color: var(--muted); transition: color .18s var(--ease), transform .14s var(--ease); }
|
||||
.seg button { position: relative; z-index: 1; white-space: nowrap; height: 24px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; color: var(--ctl-fg); transition: color .18s var(--ease), transform .14s var(--ease); }
|
||||
.seg button.on { color: var(--fg); }
|
||||
/* a plugin update waiting for the reader: a dot on Plugins */
|
||||
.seg button.has-dot::after { content: ""; position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
|
||||
@@ -1130,7 +1136,7 @@ body.panel .foot { min-height: 0; padding: 5px 8px 7px 14px; border-top: 1px sol
|
||||
.profiles .chips .hint { line-height: 30px; }
|
||||
.row-head { display: flex; align-items: center; height: 26px; }
|
||||
.label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
|
||||
.text { font-size: 12px; color: var(--muted); padding: 3px 7px; border-radius: 6px; transition: background .12s, color .12s; white-space: nowrap; }
|
||||
.text { font-size: 12px; color: var(--ctl-fg); padding: 3px 7px; border-radius: 6px; transition: background .12s, color .12s; white-space: nowrap; }
|
||||
.text:hover { color: var(--fg); background: var(--pill); }
|
||||
.text.action { height: 27px; padding: 0 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg-2); box-shadow: 0 1px 1px rgba(0, 0, 0, .04); display: inline-flex; align-items: center; justify-content: center; }
|
||||
.text.action:hover { border-color: var(--muted); background: var(--card-2); color: var(--fg); }
|
||||
@@ -1516,7 +1522,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.acc .dot { width: 16px; height: 16px; flex: none; border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 0 0 1.5px var(--faint); color: var(--muted); }
|
||||
.acc.in-use .dot { background: var(--fg); box-shadow: none; color: var(--card); }
|
||||
.acc .using { font-size: 11px; color: var(--fg-2); padding: 2px 8px; border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line); }
|
||||
.acc .text.quiet { color: var(--muted); opacity: 0; transition: opacity .15s; }
|
||||
.acc .text.quiet { opacity: 0; transition: opacity .15s; }
|
||||
.acc:hover .text.quiet { opacity: 1; }
|
||||
.acc .text.quiet:focus-visible { opacity: 1; }
|
||||
.acc.new { animation: sub-in .5s cubic-bezier(.2, .8, .2, 1); }
|
||||
@@ -2234,7 +2240,7 @@ body.window .row.agent .who.with-models { flex-wrap: wrap; row-gap: 0; }
|
||||
.pop.am-pop .am-search input { flex: 1; min-width: 0; height: 28px; border: 0; outline: none; background: none; color: var(--fg); font: inherit; font-size: 12.5px; }
|
||||
.am-search:focus-within { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
|
||||
.am-seg { display: inline-flex; flex: none; padding: 2px; border-radius: 8px; background: var(--seg-track); }
|
||||
.am-seg button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; transition: background-color .15s, color .15s; }
|
||||
.am-seg button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: none; color: var(--ctl-fg); font: inherit; font-size: 12px; cursor: pointer; transition: background-color .15s, color .15s; }
|
||||
.am-seg button.on { background: var(--seg-thumb); color: var(--fg); box-shadow: var(--seg-edge); }
|
||||
.am-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 2px; }
|
||||
.am-gh { display: flex; align-items: center; margin: 6px 2px 0; }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
.sm-switch { min-width: 0; flex: 1; display: flex; align-items: center; }
|
||||
.sm-agents { min-width: 0; max-width: 100%; }
|
||||
.segs.sm-agents { background: var(--seg-track); }
|
||||
.sm-agents .opt:not(.on, :hover) { color: var(--ctl-fg); }
|
||||
.sm-agents .opt { display: inline-flex; align-items: center; gap: 5px; }
|
||||
.sm-agents .opt.on { background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
.sm-agents .opt.on em { color: var(--muted); }
|
||||
|
||||
@@ -1211,3 +1211,16 @@ Chinese:
|
||||
```sh
|
||||
node --test internal/gui/tests/routing-account-order.test.cjs
|
||||
```
|
||||
|
||||
`seg-contrast.test.cjs` checks the header's view switch and the text buttons
|
||||
against WCAG AA (#477): with the window light, dark, and dark by the system's
|
||||
choice, it reads the colours the browser computed, each background laid over
|
||||
the ones under it, and asserts that the switch's other views on its track, the
|
||||
view shown on its thumb, and a text button on the page, a card and the inset
|
||||
editor read at 4.5:1 with margin (4.7), and that the thumb stands off the
|
||||
track by more than it did (1.2:1 light, 1.5:1 dark). It runs in Chromium and
|
||||
WebKit, in English and Chinese:
|
||||
|
||||
```sh
|
||||
node --test internal/gui/tests/seg-contrast.test.cjs
|
||||
```
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// #477: in light mode the header's view switch's other views (#85858d on the
|
||||
// #f1f1f4 track) read at 3.25:1, and a text button at 3.33:1 on the page and
|
||||
// 3.66:1 on a card, under WCAG AA's 4.5:1 for small text; in dark mode the
|
||||
// other views passed by 0.08, and in both the thumb on the view shown stood
|
||||
// off the track at 1.13:1 (light) and 1.36:1 (dark). The window is drawn
|
||||
// light, dark, and dark by the system's choice, and the colours read as the
|
||||
// browser computed them, each background laid over the ones under it: the
|
||||
// other views and a text button on the page, a card and the inset editor
|
||||
// read at 4.5:1 with some margin to spare (4.7), the view shown on its thumb
|
||||
// too, and the thumb is told from the track by more than it was. Chromium
|
||||
// and WebKit, English and Chinese; no backend, the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
|
||||
function server(lang, theme) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"${theme}",web:false};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme } } });
|
||||
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], presets: [], excluded: [], gateway: { running: true, window: true } } });
|
||||
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
|
||||
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
||||
if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
// every ratio the page draws, worked out in the page from computed colours
|
||||
const ratios = (page) => page.evaluate(() => {
|
||||
const rgba = (s) => {
|
||||
const m = s.match(/rgba?\(([^)]+)\)/);
|
||||
if (!m) throw new Error("not a colour: " + s);
|
||||
const [r, g, b, a = 1] = m[1].split(/[ ,/]+/).filter(Boolean).map(Number);
|
||||
return [r, g, b, a];
|
||||
};
|
||||
const over = (top, under) => {
|
||||
const a = top[3];
|
||||
return [0, 1, 2].map((i) => top[i] * a + under[i] * (1 - a)).concat(1);
|
||||
};
|
||||
// what is under el: its ancestors' backgrounds, deepest last, laid down
|
||||
// from the first opaque one
|
||||
const behind = (el, own) => {
|
||||
const layers = [];
|
||||
for (let e = el; e; e = e.parentElement) layers.push(rgba(getComputedStyle(e).backgroundColor));
|
||||
if (own) layers.unshift(rgba(getComputedStyle(own).backgroundColor));
|
||||
let i = layers.findIndex((c) => c[3] >= 1);
|
||||
if (i < 0) { i = layers.length; layers.push([255, 255, 255, 1]); }
|
||||
let c = layers[i];
|
||||
for (let j = i - 1; j >= 0; j--) c = over(layers[j], c);
|
||||
return c;
|
||||
};
|
||||
const lum = (c) => {
|
||||
const [r, g, b] = c.slice(0, 3).map((v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; });
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
};
|
||||
const ratio = (x, y) => { const a = lum(x), b = lum(y); return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05); };
|
||||
const text = (el, bg) => ratio(over(rgba(getComputedStyle(el).color), bg), bg);
|
||||
|
||||
const seg = document.querySelector("#nav"), thumb = seg.querySelector(".thumb");
|
||||
const track = behind(seg), onThumb = behind(seg, thumb);
|
||||
const out = {
|
||||
"other view on the track": Math.min(...[...seg.querySelectorAll("button:not(.on)")].map((b) => text(b, track))),
|
||||
"view shown on its thumb": text(seg.querySelector("button.on"), onThumb),
|
||||
"thumb against the track": ratio(onThumb, track),
|
||||
};
|
||||
// a text button on each surface it is put on
|
||||
for (const [name, bg] of [["page", ""], ["card", "var(--card)"], ["editor", "var(--card-2)"]]) {
|
||||
const box = document.createElement("div");
|
||||
if (bg) box.style.background = bg;
|
||||
const b = document.createElement("button");
|
||||
b.className = "text";
|
||||
b.textContent = "Refresh";
|
||||
box.append(b);
|
||||
document.querySelector("main, #view-agents, body").append(box);
|
||||
out[`text button on the ${name}`] = text(b, behind(b));
|
||||
box.remove();
|
||||
}
|
||||
return out;
|
||||
});
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": the header's switch and text buttons read at WCAG AA", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(async () => {
|
||||
if (errors.length) console.log(errors);
|
||||
await browser.close();
|
||||
});
|
||||
for (const lang of ["en", "zh"]) for (const [theme, scheme] of [["light", "light"], ["dark", "light"], ["system", "dark"]]) {
|
||||
await t.test(`${lang}, ${theme}${theme === "system" ? " (" + scheme + ")" : ""}`, async () => {
|
||||
const ctx = await browser.newContext({ viewport: { width: 1000, height: 640 }, colorScheme: scheme });
|
||||
const page = await ctx.newPage();
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, theme));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.waitForSelector("#nav button.on");
|
||||
await page.waitForFunction(() => document.querySelector("#nav .thumb")?.getBoundingClientRect().width > 0);
|
||||
const r = await ratios(page), at = JSON.stringify(r);
|
||||
for (const [what, v] of Object.entries(r)) {
|
||||
if (what === "thumb against the track") continue;
|
||||
assert(v >= 4.7, `${what} reads at ${v.toFixed(2)}:1, under 4.5:1 with margin; ${at}`);
|
||||
}
|
||||
const dark = theme === "dark" || scheme === "dark";
|
||||
// before: 1.13 (light), 1.36 (dark, the thumb laid over the track)
|
||||
assert(r["thumb against the track"] >= (dark ? 1.5 : 1.2), `the thumb is hard to tell from the track (${r["thumb against the track"].toFixed(2)}:1); ${at}`);
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user