gui: a logo solid to its edges is drawn at the size of a line logo beside it
The owner saw the Agents list's logos at two sizes. They were: every logo is drawn to its 16-22px box, and a tile or disc logo (Codex, WorkBuddy, ZCode, Qoder) inks ~96% of that box edge to edge, while a line logo (Pi, OpenCode, Hermes, Grok) inks ~40% and Alma's and Cindy's tiles bring their own margin (82% of the box). Measured on every file in icons/ at 256px. The 25 logos solid to their edges (inked to within 7% of each edge, 70% or more of the box) are now drawn at 82%, Alma's and Cindy's size. The list is a data-icon rule in app.css, so app.js and its budget are unchanged. icon-tile.test.cjs measures every file in icons/ and fails when a tile logo is missing from the rule or a line logo is in it, and checks in the Agents list that Codex and ZCode draw at 82%, centred, and Pi whole. Run: - icon-tile, mono-icon-redraw, models-add-and-icons, plugin-own-icon and i18n-keys GUI tests, chromium and webkit: 38 of 38. - go test -run Budget ./internal/gui: ok. - Broken by hand: codex-color taken out of the rule, the test goes red on both the list and the drawn size (22/22). - Before/after screenshot of the screenshot's 11 agents, dark, zh: the tiles now match Alma's and Cindy's. Not run: the whole GUI suite. A plugin's own icon or a user's file: icon that is a tile is not measured and stays full size.
This commit is contained in:
@@ -167,6 +167,11 @@ code { font: var(--code-style, normal) var(--code-weight, 400) 11.5px var(--code
|
||||
.ic { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 16px; height: 16px; }
|
||||
.ic img { width: 100%; height: 100%; object-fit: contain; display: block; }
|
||||
.ic .mask { width: 100%; height: 100%; background: currentColor; -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; }
|
||||
/* logos solid to their edges, a tile or a disc: drawn to the box's edges
|
||||
they read a size bigger than a line logo beside them, so they are drawn at
|
||||
the size Alma's and Cindy's tiles have of their own. icon-tile.test.cjs
|
||||
measures every file in icons/ and keeps this list whole. */
|
||||
.ic:is([data-icon="aihubmix-color"], [data-icon="atomcode"], [data-icon="cherryin-color"], [data-icon="codebuddy-color"], [data-icon="codex-color"], [data-icon="crush"], [data-icon="geminicli-color"], [data-icon="hanako"], [data-icon="hunyuan-color"], [data-icon="kilo"], [data-icon="kiro-color"], [data-icon="lody"], [data-icon="mistermorph-color"], [data-icon="mlx-serve"], [data-icon="monica-color"], [data-icon="phala-color"], [data-icon="pipellm-color"], [data-icon="qoder"], [data-icon="snow"], [data-icon="targon-color"], [data-icon="typesafe"], [data-icon="workbuddy-color"], [data-icon="yuanbao-color"], [data-icon="zcode"], [data-icon="zoo-code"]) > * { width: 82%; height: 82%; }
|
||||
.ic.generic { color: var(--muted); }
|
||||
/* maskSpan's shelf: a hidden user of every mask picture loaded, so a logo drawn again paints at once (#1847) */
|
||||
.mask-shelf { position: fixed; top: 0; left: 0; width: 0; height: 0; overflow: hidden; visibility: hidden; pointer-events: none; }
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A logo that is a solid tile or disc to its edges (Codex, WorkBuddy,
|
||||
// ZCode) read a size bigger than a line logo (Pi, OpenCode, Hermes) in the
|
||||
// row beside it: both filled the same box, the tile with ~96% of it inked
|
||||
// and the line logo with ~40%. A tile is now drawn at 82% of the box, the
|
||||
// size Alma's and Cindy's tiles have of their own. Every file in icons/ is
|
||||
// measured, so a new tile logo left out of app.css's list, or a line logo
|
||||
// put in it, fails here. In the Agents list the tile is drawn at 82% and the
|
||||
// line logo at full size, in Chromium and WebKit.
|
||||
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");
|
||||
|
||||
// inked to within 7% of every edge, and most of the box inked
|
||||
const isTile = (r) => Math.min(r.w, r.h) >= 0.93 && r.ink >= 0.7;
|
||||
|
||||
async function tileList() {
|
||||
const src = await fs.readFile(path.join(assets, "app.css"), "utf8");
|
||||
const m = src.match(/\.ic:is\(([^)]*)\) > \* \{ width: 82%; height: 82%; \}/);
|
||||
assert.ok(m, "app.css has the tile logos' rule");
|
||||
return new Set([...m[1].matchAll(/\[data-icon="([^"]+)"\]/g)].map((x) => x[1]));
|
||||
}
|
||||
|
||||
test("the tile logos' rule names every logo solid to its edges, and no other", async () => {
|
||||
const listed = await tileList();
|
||||
const files = (await fs.readdir(path.join(assets, "icons"))).filter((f) => /\.(svg|png)$/.test(f));
|
||||
const browser = await chromium.launch();
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
await page.setContent("<html></html>");
|
||||
const found = new Set(), all = new Set();
|
||||
for (const f of files) {
|
||||
const name = f.replace(/\.(svg|png)$/, "");
|
||||
all.add(name);
|
||||
const mime = f.endsWith(".png") ? "image/png" : "image/svg+xml";
|
||||
const url = `data:${mime};base64,` + (await fs.readFile(path.join(assets, "icons", f))).toString("base64");
|
||||
const r = await page.evaluate(async (url) => {
|
||||
const img = new Image();
|
||||
img.src = url;
|
||||
await img.decode();
|
||||
const S = 256, c = document.createElement("canvas");
|
||||
c.width = c.height = S;
|
||||
const x = c.getContext("2d");
|
||||
const nw = img.naturalWidth || S, nh = img.naturalHeight || S, k = Math.min(S / nw, S / nh);
|
||||
x.drawImage(img, (S - nw * k) / 2, (S - nh * k) / 2, nw * k, nh * k);
|
||||
const d = x.getImageData(0, 0, S, S).data;
|
||||
let l = S, t = S, rt = -1, b = -1, ink = 0;
|
||||
for (let y = 0; y < S; y++) for (let i = 0; i < S; i++) {
|
||||
if (d[(y * S + i) * 4 + 3] <= 24) continue;
|
||||
ink++; l = Math.min(l, i); rt = Math.max(rt, i); t = Math.min(t, y); b = Math.max(b, y);
|
||||
}
|
||||
return { w: (rt - l + 1) / S, h: (b - t + 1) / S, ink: ink / S / S };
|
||||
}, url);
|
||||
if (isTile(r)) found.add(name);
|
||||
}
|
||||
for (const n of found) assert.ok(listed.has(n), `${n} is solid to its edges but not in app.css's tile rule`);
|
||||
for (const n of listed) {
|
||||
assert.ok(all.has(n), `the tile rule names ${n}, which icons/ doesn't have`);
|
||||
assert.ok(found.has(n), `the tile rule names ${n}, which is not solid to its edges`);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
});
|
||||
|
||||
function serve() {
|
||||
const agents = [
|
||||
{ id: "pi", name: "Pi", icon: "pi", path: "/test/pi", fields: [] },
|
||||
{ id: "codex", name: "Codex", icon: "codex-color", path: "/test/codex", fields: [] },
|
||||
{ id: "zcode", name: "ZCode", icon: "zcode", path: "/test/zcode", fields: [] },
|
||||
];
|
||||
const state = { agents, profiles: [], settings: { lang: "en", theme: "dark" } };
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
const json = (data) => r.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"dark",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) return new Promise(() => {});
|
||||
return json({ mine: true, now: new Date().toISOString(), seq: 0, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||||
}
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
let body;
|
||||
try { body = await fs.readFile(file); } catch { return r.fulfill({ status: 404, body: "" }); }
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await r.fulfill({ body, contentType, headers: { "Cache-Control": "no-cache" } });
|
||||
};
|
||||
}
|
||||
|
||||
for (const [engine, type] of [["chromium", chromium], ["webkit", webkit]]) {
|
||||
test(`a tile logo is drawn at 82% of its box, a line logo whole (${engine})`, async () => {
|
||||
const browser = await type.launch();
|
||||
try {
|
||||
const page = await browser.newPage({ viewport: { width: 900, height: 700 } });
|
||||
await page.route("http://magpie.test/**", serve());
|
||||
await page.goto("http://magpie.test/");
|
||||
const size = (icon) => page.evaluate((icon) => {
|
||||
const e = document.querySelector(`.ic[data-icon="${icon}"]`);
|
||||
if (!e || !e.firstElementChild) return null;
|
||||
const b = e.getBoundingClientRect(), p = e.firstElementChild.getBoundingClientRect();
|
||||
return { box: b.width, pic: p.width, dx: p.left - b.left - (b.right - p.right), dy: p.top - b.top - (b.bottom - p.bottom) };
|
||||
}, icon);
|
||||
await page.waitForFunction(() => ["pi", "codex-color", "zcode"].every((i) => document.querySelector(`.ic[data-icon="${i}"] > *`)));
|
||||
// a row's logo opens from nothing as it comes in: measured once it holds still
|
||||
let last = "";
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const now = JSON.stringify(await Promise.all(["pi", "codex-color", "zcode"].map(size)));
|
||||
if (now === last) break;
|
||||
last = now;
|
||||
await page.waitForTimeout(100);
|
||||
}
|
||||
for (const icon of ["codex-color", "zcode"]) {
|
||||
const s = await size(icon);
|
||||
assert.ok(s.box > 0, `${icon} has a box`);
|
||||
assert.ok(Math.abs(s.pic / s.box - 0.82) < 0.02, `${icon} is drawn at ${s.pic}/${s.box}`);
|
||||
assert.ok(Math.abs(s.dx) < 0.6 && Math.abs(s.dy) < 0.6, `${icon} is centred in its box`);
|
||||
}
|
||||
const pi = await size("pi");
|
||||
assert.equal(pi.pic, pi.box, "a line logo fills its box");
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user