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

small: Increased-contrast mode: the palette answers prefers-contrast: more with stronger borders and text #13898

Merged opened this

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

Merged

scout/forge:scout/13875-small-increased-contrast-mode-the-palett → main 2 commits fork

  • Merged. scout/13875-small-increased-contrast-mode-the-palett was merged into main as 467d7bd.

Review

Sign in to review this change.
3 files changed +70 −1
src/design/themes.ts +42
@@ -423,6 +423,48 @@ export const themeCss = [
423423 ),
424424 ].join("\n");
425425
426 /**
427 * Increased contrast (#13875): under `prefers-contrast: more` the default
428 * light and dark themes swap the text, border and focus-ring (--accent)
429 * tokens for ones that reach 7:1 on bg, card and muted. One block of token
430 * overrides, so no component carries its own. Other themes keep their own
431 * palette: a person who asked for more contrast can pick Porcelain or Ink.
432 */
433 export const CONTRAST_MORE: Record<"light" | "dark", Partial<Palette>> = {
434 light: {
435 fg: "#000000",
436 "muted-fg": "#3f3f46",
437 border: "#52525b",
438 "border-strong": "#3f3f46",
439 accent: "#1e40af",
440 },
441 dark: {
442 fg: "#ffffff",
443 "muted-fg": "#d4d4d8",
444 border: "#b4b4bc",
445 "border-strong": "#d4d4d8",
446 accent: "#8ec5ff",
447 },
448 };
449
450 function moreVars(kind: "light" | "dark"): string {
451 return Object.entries(CONTRAST_MORE[kind]).map(([k, v]) => ` --${k}: ${v};`).join("\n");
452 }
453
454 export const contrastMoreCss = `@media (prefers-contrast: more) {
455 :root:not([data-theme]), :root[data-theme="light"] {
456 ${moreVars("light")}
457 }
458 @media (prefers-color-scheme: dark) {
459 :root:not([data-theme]) {
460 ${moreVars("dark")}
461 }
462 }
463 :root[data-theme="dark"] {
464 ${moreVars("dark")}
465 }
466 }`;
467
426468 /** The browser-chrome color for a page: the theme's page background. */
427469 export function metaThemeColor(name: ThemeName): string {
428470 return THEMES[name].tokens.bg;
src/web/style.ts +2 −1
@@ -22,7 +22,7 @@
2222 * this file reads those two, so neither may ever read `css` back.
2323 */
2424
25 import { themeCss } from "../design/themes.ts";
25 import { contrastMoreCss, themeCss } from "../design/themes.ts";
2626 import { boardCss } from "./pages/board_style.ts";
2727 import { homeFlowCss } from "./pages/home_flow_style.ts";
2828 import { base, layers, reset, utilities } from "./style/base.ts";
@@ -36,6 +36,7 @@ import { studioCss } from "./studio/style.ts";
3636 export const css = [
3737 layers,
3838 themeCss,
39 contrastMoreCss,
3940 reset,
4041 base,
4142 components,
test/contrast-more.test.ts added +26
@@ -0,0 +1,26 @@
1 import { describe, expect, test } from "bun:test";
2 import { contrast } from "../src/design/contrast.ts";
3 import { CONTRAST_MORE, THEMES } from "../src/design/themes.ts";
4 import { css } from "../src/web/style.ts";
5
6 const blockStart = css.indexOf("@media (prefers-contrast: more)");
7
8 describe("increased contrast (#13875)", () => {
9 test("the stylesheet carries one prefers-contrast: more block, after the themes", () => {
10 expect(blockStart).toBeGreaterThan(css.indexOf('[data-theme="aurora"]'));
11 expect(css.split("prefers-contrast").length - 1).toBe(1);
12 });
13 test("the block sets every override token as a custom property", () => {
14 const block = css.slice(blockStart, blockStart + 1200);
15 for (const kind of ["light", "dark"] as const)
16 for (const [k, v] of Object.entries(CONTRAST_MORE[kind])) expect(block).toContain(`--${k}: ${v};`);
17 });
18 for (const [kind, theme] of [["light", THEMES.light], ["dark", THEMES.dark]] as const) {
19 test(`${kind}: text, borders and focus ring reach 7:1 on every surface`, () => {
20 const t = { ...theme.tokens, ...CONTRAST_MORE[kind] };
21 for (const fg of ["fg", "muted-fg", "accent", "border", "border-strong"] as const)
22 for (const bg of ["bg", "card", "muted"] as const)
23 expect(contrast(t[fg], t[bg])).toBeGreaterThanOrEqual(7);
24 });
25 }
26 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs