Public: anyone can read this; the crew can change it.

Theme menu row is a native select of Auto and ten themes; four new themes (Sand, High contrast, Dusk, Forest) #16348

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

ui/themes → main 0 commits

  • Merged. ui/themes was merged into main as 5068baf.

Review

Sign in to review this change.
13 files changed +168 −59
docs/design/size-budget.json +17 −17
@@ -1,31 +1,31 @@
11 {
22 "/": {
33 "js": 22016,
4 "css": 48384
4 "css": 48640
55 },
66 "/explore": {
77 "js": 21760,
8 "css": 48384
8 "css": 48640
99 },
1010 "/map": {
1111 "js": 28672,
12 "css": 50176
12 "css": 50304
1313 },
1414 "/:owner/:name": {
1515 "js": 38400,
16 "css": 48384
16 "css": 48640
1717 },
1818 "/changelog": {
1919 "js": 26880,
20 "css": 48384
20 "css": 48640
2121 },
2222 "/:owner/:name/next": {
2323 "js": 23296,
24 "css": 48896
24 "css": 49024
2525 },
2626 "/:owner/:name/space": {
2727 "js": 30208,
28 "css": 49664
28 "css": 49792
2929 },
3030 "/:owner/:name/space.json": {
3131 "js": 0,
@@ -33,39 +33,39 @@
3333 },
3434 "/maintenance": {
3535 "js": 21760,
36 "css": 48384
36 "css": 48640
3737 },
3838 "/pricing": {
3939 "js": 21760,
40 "css": 48384
40 "css": 48640
4141 },
4242 "/forges/new": {
4343 "js": 21760,
44 "css": 48384
44 "css": 48640
4545 },
4646 "/claim": {
4747 "js": 24320,
48 "css": 48384
48 "css": 48640
4949 },
5050 "/templates": {
5151 "js": 21760,
52 "css": 48384
52 "css": 48640
5353 },
5454 "/system": {
5555 "js": 23808,
56 "css": 48384
56 "css": 48640
5757 },
5858 "/feed": {
5959 "js": 36352,
60 "css": 48384
60 "css": 48640
6161 },
6262 "/board": {
6363 "js": 26880,
64 "css": 48384
64 "css": 48640
6565 },
6666 "/fleet": {
6767 "js": 21760,
68 "css": 48384
68 "css": 48640
6969 },
7070 "/talk": {
7171 "js": 39168,
@@ -73,6 +73,6 @@
7373 },
7474 "/:owner/:name/pulls/:number": {
7575 "js": 32000,
76 "css": 48384
76 "css": 48640
7777 }
7878 }
src/design/themes.ts +103
@@ -367,6 +367,105 @@ const aurora: Palette = {
367367 "tok-link": "#88c0d0",
368368 };
369369
370 /** Sand — warm linen and walnut; one terracotta accent. */
371 const sand: Palette = {
372 ...porcelain,
373 bg: "#f5eee2",
374 fg: "#2a2017",
375 card: "#fcf8ef",
376 muted: "#ebe2d2",
377 "muted-fg": "#6a5a49",
378 faint: "#9d8d7a",
379 border: "#e0d5c2",
380 "border-strong": "#cdbea6",
381 primary: "#2a2017",
382 "primary-fg": "#fcf8ef",
383 accent: "#a3421d",
384 "accent-fg": "#fffaf2",
385 "shadow-1": "0 1px 2px rgb(42 32 23 / 0.06)",
386 "shadow-2": "0 8px 24px rgb(42 32 23 / 0.12)",
387 danger: "#b3261e",
388 success: "#19702f",
389 "tok-comment": "#6b5e4e",
390 "tok-link": "#a3421d",
391 "tok-heading": "#a3421d",
392 "tok-emphasis": "#2a2017",
393 };
394
395 /** Contrast — pure black on white, strong rules, a deep blue accent: 7:1 and better everywhere. */
396 const contrastHigh: Palette = {
397 ...porcelain,
398 bg: "#ffffff",
399 fg: "#000000",
400 card: "#ffffff",
401 muted: "#f0f0f0",
402 "muted-fg": "#2b2b2b",
403 faint: "#595959",
404 border: "#6b6b6b",
405 "border-strong": "#000000",
406 primary: "#000000",
407 "primary-fg": "#ffffff",
408 accent: "#0030c0",
409 "accent-fg": "#ffffff",
410 danger: "#b00020",
411 success: "#006b2c",
412 attn: "#8a4b00",
413 merged: "#5b21b6",
414 "add-fg": "#005a24",
415 "del-fg": "#a8001c",
416 "tok-comment": "#4d4d4d",
417 "tok-punctuation": "#4d4d4d",
418 "tok-link": "#0030c0",
419 "tok-heading": "#0030c0",
420 "tok-emphasis": "#000000",
421 };
422
423 /** Dusk — soft violet-grey evening; low glare, one lilac accent. */
424 const dusk: Palette = {
425 ...ink,
426 bg: "#1e1b2e",
427 fg: "#ebe7f6",
428 card: "#27243a",
429 muted: "#2f2b45",
430 "muted-fg": "#b4adcc",
431 faint: "#8179a0",
432 border: "#38344f",
433 "border-strong": "#4a4566",
434 primary: "#ebe7f6",
435 "primary-fg": "#1e1b2e",
436 accent: "#b9a0ff",
437 "accent-fg": "#1a1628",
438 "shadow-1": "0 1px 2px rgb(8 6 20 / 0.4)",
439 "shadow-2": "0 8px 24px rgb(8 6 20 / 0.5)",
440 "tok-comment": "#8f88ad",
441 "tok-link": "#b9a0ff",
442 "tok-heading": "#b9a0ff",
443 "tok-emphasis": "#ebe7f6",
444 };
445
446 /** Forest — deep green-black, calm and dense; one mint accent. */
447 const forest: Palette = {
448 ...ink,
449 bg: "#0d1411",
450 fg: "#e6efe9",
451 card: "#131c18",
452 muted: "#1a2621",
453 "muted-fg": "#a3b6ac",
454 faint: "#73887d",
455 border: "#25332c",
456 "border-strong": "#36483f",
457 primary: "#e6efe9",
458 "primary-fg": "#0d1411",
459 accent: "#5fd39a",
460 "accent-fg": "#06120c",
461 "shadow-1": "0 1px 2px rgb(0 0 0 / 0.4)",
462 "shadow-2": "0 8px 24px rgb(0 0 0 / 0.5)",
463 "tok-comment": "#7f948a",
464 "tok-link": "#5fd39a",
465 "tok-heading": "#5fd39a",
466 "tok-emphasis": "#e6efe9",
467 };
468
370469 export const THEMES = {
371470 light: { label: "Porcelain", appearance: "light", tokens: porcelain },
372471 paper: { label: "Paper", appearance: "light", tokens: paper },
@@ -374,6 +473,10 @@ export const THEMES = {
374473 dark: { label: "Ink", appearance: "dark", tokens: ink },
375474 midnight: { label: "Midnight", appearance: "dark", tokens: midnight },
376475 aurora: { label: "Aurora", appearance: "dark", tokens: aurora },
476 sand: { label: "Sand", appearance: "light", tokens: sand },
477 contrast: { label: "High contrast", appearance: "light", tokens: contrastHigh },
478 dusk: { label: "Dusk", appearance: "dark", tokens: dusk },
479 forest: { label: "Forest", appearance: "dark", tokens: forest },
377480 } as const satisfies Record<string, Theme>;
378481
379482 export type ThemeName = keyof typeof THEMES;
src/web/client.ts +16 −12
@@ -1285,22 +1285,26 @@ const shellCore = /* js */ `
12851285 if (next) { next.focus(); e.preventDefault(); }
12861286 });
12871287
1288 // ---- theme: a press applies at once and is kept by the same POST the form makes ----
1288 // ---- theme: a choice applies at once and is kept by the same POST the form makes ----
1289 function setTheme(form, value) {
1290 var root = doc.documentElement;
1291 root.classList.add('theme-anim');
1292 if (value === 'system') root.removeAttribute('data-theme'); else root.setAttribute('data-theme', value);
1293 window.setTimeout(function () { root.classList.remove('theme-anim'); }, 260);
1294 // The menu's select and the settings gallery agree on what is worn.
1295 doc.querySelectorAll('.theme-form select[name=theme]').forEach(function (o) { o.value = value; });
1296 doc.querySelectorAll('.theme-form button[name=theme]').forEach(function (o) { o.setAttribute('aria-pressed', o.value === value ? 'true' : 'false'); });
1297 fetch(form.action, { method: 'POST', body: new URLSearchParams({ theme: value }) }).catch(function () {});
1298 }
12891299 doc.addEventListener('click', function (e) {
12901300 var b = e.target && e.target.closest ? e.target.closest('.theme-form button[name=theme]') : null;
12911301 if (!b) return;
12921302 e.preventDefault();
1293 var root = doc.documentElement, mode = b.getAttribute('data-a');
1294 root.classList.add('theme-anim');
1295 if (b.value === 'system') root.removeAttribute('data-theme'); else root.setAttribute('data-theme', b.value);
1296 window.setTimeout(function () { root.classList.remove('theme-anim'); }, 260);
1297 // The menu's row and the settings gallery agree: a mode button stands for the theme now worn.
1298 doc.querySelectorAll('.theme-form button[name=theme]').forEach(function (o) {
1299 var seg = o.closest('.seg'), on = seg ? o.getAttribute('data-a') === mode : o.value === b.value;
1300 if (seg && on) o.value = b.value;
1301 o.setAttribute('aria-pressed', on ? 'true' : 'false');
1302 });
1303 fetch(b.form.action, { method: 'POST', body: new URLSearchParams({ theme: b.value }) }).catch(function () {});
1303 setTheme(b.form, b.value);
1304 });
1305 doc.addEventListener('change', function (e) {
1306 var t = e.target;
1307 if (t && t.matches && t.matches('.theme-form select[name=theme]')) setTheme(t.form, t.value);
13041308 });
13051309
13061310 // ---- copy buttons ----
src/web/layout.ts +10 −16
@@ -46,6 +46,7 @@ import { runningLine } from "../kernel/version.ts";
4646 import {
4747 bootCss,
4848 metaThemeColor,
49 THEME_NAMES,
4950 THEMES,
5051 type ThemeName,
5152 } from "../design/themes.ts";
@@ -244,25 +245,18 @@ export interface PageOptions {
244245 // ---- topbar pieces ----
245246
246247 /**
247 * The theme a mode button sends: the viewer's own named theme while it is of that mode, else the
248 * default of the pair.
249 */
250 const modeTheme = (mode: "light" | "dark", active: ThemeName | undefined): ThemeName =>
251 active !== undefined && THEMES[active].appearance === mode ? active : mode;
252
253 /**
254 * Appearance, as one row of a menu: Auto, Light, Dark. Each is a submit button,
255 * so the row works with no script; the named themes are at /settings/appearance.
248 * Appearance, as one row of a menu: a native select of Auto and every theme. With no script
249 * the Apply button sends the form; with it, choosing applies at once (client.ts).
256250 */
257251 function themeRow(active: ThemeName | undefined): Html {
258 const mode = active === undefined ? "" : THEMES[active].appearance;
259 const choice = (label: string, value: string, of: string) =>
260 html`<button name="theme" value="${value}" data-a="${of}" aria-pressed="${mode === of ? "true" : "false"}">${label}</button>`;
252 const option = (value: string, label: string, on: boolean) =>
253 html`<option value="${value}" ${on ? "selected" : ""}>${label}</option>`;
254 const group = (label: string, appearance: "light" | "dark") =>
255 html`<optgroup label="${label}">${THEME_NAMES.filter((n) => THEMES[n].appearance === appearance).map((n) => option(n, THEMES[n].label, active === n))}</optgroup>`;
261256 return html`<form class="theme-form menu-row" method="post" action="/theme">
262 ${themeGlyph}<span class="grow" id="menu-theme">Theme</span>
263 <span class="seg" role="group" aria-labelledby="menu-theme"
264 >${choice("Auto", "system", "")}${choice("Light", modeTheme("light", active), "light")}${choice("Dark", modeTheme("dark", active), "dark")}</span
265 >
257 ${themeGlyph}<label for="menu-theme">Theme</label>
258 <select class="input" id="menu-theme" name="theme" data-size="sm">${option("system", "Auto", active === undefined)}${group("Light", "light")}${group("Dark", "dark")}</select>
259 <button class="btn" data-size="sm" data-nojs>Apply</button>
266260 </form>`;
267261 }
268262
src/web/style/components.ts +3
@@ -805,6 +805,9 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
805805 .menu-item:focus-visible { outline-offset: -2px; }
806806 .menu > summary .truncate { max-width: 18ch; }
807807 .menu-row { cursor: default; padding-block: 4px; padding-right: 4px; }
808 :root.js [data-nojs] { display: none; }
809 .menu-row > label { flex: none; margin: 0; font-weight: 400; }
810 .menu-row > select.input { flex: 0 1 11rem; width: auto; min-width: 0; margin-left: auto; }
808811 /* A phone: the bar's menus are a bottom sheet, measured from the bar down to 100dvh. */
809812 @media (max-width: 719px) {
810813 .topbar .menu[open] { position: static; }
test/account-menu.test.ts +5 −2
@@ -6,6 +6,7 @@ import { afterAll, beforeAll, expect, test } from "bun:test";
66 import { mkdtemp, rm } from "node:fs/promises";
77 import { tmpdir } from "node:os";
88 import { join } from "node:path";
9 import { THEME_NAMES, THEMES } from "../src/design/themes.ts";
910 import { createApp, type App } from "../src/app.ts";
1011 import { setSsh } from "../src/settings/ssh.ts";
1112 import { serve, type Servers } from "../src/http/server.ts";
@@ -73,11 +74,13 @@ test("a visitor's menu: no account rows, the same one row for appearance, and th
7374 expect(html).toContain('href="/settings/appearance"');
7475 });
7576
76 test("the theme control is one row of three buttons, whoever opens the menu", async () => {
77 test("the theme control is one select of Auto and every theme, whoever opens the menu", async () => {
7778 for (const [path, cookie] of [["/", admin], ["/", member], ["/explore", ""]] as const) {
7879 const { html } = await menuRows(path, cookie);
7980 const row = html.slice(html.indexOf('<form class="theme-form menu-row"'), html.indexOf("</form>", html.indexOf('<form class="theme-form menu-row"')));
80 expect([...row.matchAll(/<button name="theme"[^>]*>([^<]+)</g)].map((m) => m[1])).toEqual(["Auto", "Light", "Dark"]);
81 expect(row).toContain('<select class="input" id="menu-theme" name="theme"');
82 expect([...row.matchAll(/<option value="([^"]+)"/g)].map((m) => m[1])).toEqual(["system", ...THEME_NAMES.filter((n) => THEMES[n].appearance === "light"), ...THEME_NAMES.filter((n) => THEMES[n].appearance === "dark")]);
83 expect(row).toContain("Apply");
8184 expect(html.match(/action="\/theme"/g)?.length).toBe(1);
8285 expect(html).not.toContain('type="radio"');
8386 }
test/flow-pipeline.test.ts +1 −1
@@ -290,7 +290,7 @@ describe("/flow: the forge shows its own bottleneck", () => {
290290 });
291291
292292 test("the shell script wires the theme buttons by the form's class", () => {
293 expect(shellJs).toContain("closest('.theme-form button[name=theme]')");
293 expect(shellJs).toContain("matches('.theme-form select[name=theme]')");
294294 expect(shellJs).not.toContain(".theme-menu form");
295295 });
296296
test/pricing-size.test.ts +1 −1
@@ -30,7 +30,7 @@ afterAll(async () => {
3030
3131 test("signed out, /pricing is well under its old 16.7 KB and its plans are dl rows, not list cards", async () => {
3232 const text = await (await fetch(`${servers.url}/pricing`)).text();
33 expect(new TextEncoder().encode(text).length).toBeLessThan(13.6 * 1024); // +~50 B: the theme <link> on every page (#6297); was 16.7 KB, 12.5 before each card said its price, credit and forges (#13886); the issue asks < 10 KB, the shared shell is ~8 KB of the rest
33 expect(new TextEncoder().encode(text).length).toBeLessThan(14.3 * 1024); // +~0.65 KB: the theme select and four themes' boot rules (14,569 B measured); +~50 B: the theme <link> on every page (#6297); was 16.7 KB, 12.5 before each card said its price, credit and forges (#13886); the issue asks < 10 KB, the shared shell is ~8 KB of the rest
3434 expect(text).toContain('<dl class="status-rows">');
3535 expect(text.match(/class="status-row" data-plan="/g)?.length).toBeGreaterThanOrEqual(2);
3636 expect(text).not.toContain("setting-list");
test/studio-stranger.test.ts +2 −1
@@ -373,7 +373,8 @@ describe("a stranger sees the app, not the owner's books", () => {
373373 expect(stranger).not.toContain("keeper");
374374 expect(stranger).not.toMatch(/\$\d/);
375375 expect(stranger).not.toContain("Add to crew");
376 expect(stranger).not.toContain("<select");
376 // The page's own part: the bar's menu carries the theme select.
377 expect(stranger.slice(stranger.indexOf("<main"))).not.toContain("<select");
377378
378379 const anon = await get("/alice/beacon/settings");
379380 expect(anon.status).toBe(200);
test/terms-page.test.ts +1 −1
@@ -37,7 +37,7 @@ describe("/terms", () => {
3737 // under 10 KB with any body; the page's own part is held small, and the shell under 10.5 KB.
3838 const main = text.match(/<main[\s\S]*?<\/main>/)![0];
3939 expect(main.length).toBeLessThan(2_000);
40 expect(text.length - main.length).toBeLessThan(10_500);
40 expect(text.length - main.length).toBeLessThan(11_000); // 10,866 B measured: the theme select and four themes' boot rules
4141 expect(text).toContain("<title>Terms");
4242 expect(text).toContain("<h1>Terms of a paid forge</h1>");
4343 expect(text.match(/<dt>/g)!.length).toBe(6);
test/tui-icons.test.ts +4 −3
@@ -14,6 +14,7 @@
1414 */
1515
1616 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
17 import { THEME_NAMES } from "../src/design/themes.ts";
1718 import { mkdtemp, rm } from "node:fs/promises";
1819 import { tmpdir } from "node:os";
1920 import { join } from "node:path";
@@ -336,8 +337,8 @@ describe("the icon set a session actually draws", () => {
336337 expect(h.text()).toContain("Icons");
337338 expect(h.text()).toContain("plain glyphs");
338339
339 // "dark" is the fourth theme, so four presses reach the Icons row.
340 await h.press("j", "j", "j", "j");
340 // "dark" is the fourth theme; the Icons row follows the last theme and the Images row.
341 await h.press(...Array<string>(THEME_NAMES.length + 1 - THEME_NAMES.indexOf("dark")).fill("j"));
341342 await h.press("right");
342343 expect(h.app.ctx.icons).toBe("nerd");
343344 // The preview changes under the cursor: the whole point of the row.
@@ -366,7 +367,7 @@ describe("the icon set a session actually draws", () => {
366367 const h = boot("xterm-ghostty");
367368 try {
368369 await h.settle();
369 await h.press("ctrl+t", "j", "j", "j");
370 await h.press("ctrl+t", ...Array<string>(THEME_NAMES.length - THEME_NAMES.indexOf("dark")).fill("j"));
370371 expect(h.text()).toContain("auto (kitty)");
371372 await h.press("right");
372373 await h.press("esc");
test/web.test.ts +4 −4
@@ -678,11 +678,11 @@ describe("themes", () => {
678678 const text = await (await fetch(`${base}/explore`)).text();
679679 expect(text).not.toMatch(/<html[^>]*\sdata-theme=/);
680680 expect(text).toContain('action="/theme"');
681 // The menu holds one row: Auto, Light, Dark, each a submit button of a §5 seg. No radios, no Apply.
681 // The menu holds one row: a native select of Auto and every theme. No radios.
682682 const form = text.slice(text.indexOf('action="/theme"'));
683683 const panel = form.slice(0, form.indexOf("</form>"));
684 expect([...panel.matchAll(/<button name="theme" value="([^"]+)"[^>]*aria-pressed="([^"]+)"/g)].map((m) => `${m[1]}:${m[2]}`)).toEqual(["system:true", "light:false", "dark:false"]);
685 expect(panel).toContain('class="seg"');
684 expect([...panel.matchAll(/<option value="([^"]+)" (selected)?/g)].map((m) => `${m[1]}:${m[2] ?? ""}`).filter((x) => x.endsWith("selected"))).toEqual(["system:selected"]);
685 expect([...panel.matchAll(/<option value="([^"]+)"/g)].length).toBe(THEME_NAMES.length + 1);
686686 expect(panel).not.toContain('type="radio"');
687687 // Every theme is a card on the appearance page, a visitor's too.
688688 const gallery = await (await fetch(`${base}/settings/appearance`)).text();
@@ -722,7 +722,7 @@ describe("themes", () => {
722722 const text = await (await fetch(`${base}/explore`, { headers: { cookie } })).text();
723723 expect(text).toContain('data-theme="midnight"');
724724 // The switcher shows the active choice.
725 expect(text).toContain('<button name="theme" value="midnight" data-a="dark" aria-pressed="true">Dark</button>');
725 expect(text).toContain('<option value="midnight" selected>Midnight</option>');
726726 // Boot paint follows the attribute: midnight's ground for this page, and
727727 // the same rules as a system page, so switching away repaints at once.
728728 const boot = text.match(/<style>([^<]*)<\/style>/)?.[1];

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs