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

small: design-lint proves the Dictate button is named and at least 44 px tall #14199

Merged opened this

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

Merged

scout/forge:scout/14198-small-design-lint-proves-the-dictate-but → main 2 commits fork 4 threads · 4 unresolved

  • Merged. scout/14198-small-design-lint-proves-the-dictate-but was merged into main as 5ecdc0f.

Review

Sign in to review this change.
3 files changed +95 −1
scripts/design-lint.ts +10 −1
@@ -67,6 +67,7 @@
6767
6868 import { readdirSync, readFileSync, writeFileSync } from "node:fs";
outdated

Import placed before node: imports and duplicated by the re-export below; keep one of each in order.

6969 import { join, relative } from "node:path";
70 import { dictateFindings } from "../src/design/dictate.ts";
7071 import { STRANGER_NEVER_SEES } from "../src/design/first_five_minutes.ts";
7172 import { contrastFindings } from "../src/design/contrast.ts";
7273 import { compareLayout, layoutCounts, scanLayout } from "../src/design/layout.ts";
@@ -76,6 +77,7 @@ import { cssBlocksAt, scanOverlay, sourceFiles } from "../src/design/overlay.ts"
7677
7778 // The covered-page rule lives in src/design/ so the release preflight runs it too (#11916).
7879 export { motionFindings, type MotionFinding } from "../src/design/motion.ts";
80 export { dictateFindings } from "../src/design/dictate.ts";
7981 export { widthFindings, type WidthFinding } from "../src/design/width.ts";
8082 export { compareLayout, layoutCounts, layoutIn, scanLayout } from "../src/design/layout.ts";
8183 export { matchesClosedOverlay, overlay, overlayClassesIn, type OverlayFinding, scanOverlay, sourceFiles } from "../src/design/overlay.ts";
@@ -622,6 +624,13 @@ export function scanWidth(root: string): string[] {
622624 return out;
623625 }
624626
627 /** The /talk Dictate button keeps a name and a 44px target (#14198). */
628 export function scanDictate(root: string): string[] {
629 const read = (f: string): string => readFileSync(join(root, f), "utf8");
630 const css = read("src/web/style/components.ts") + read("src/web/pages/talk_client.ts");
631 return dictateFindings(read("src/web/pages/talk.ts"), css).map((p) => `src/web/pages/talk.ts: ${p}`);
632 }
633
625634 const BASELINE = "docs/design/baseline.json";
626635 const DESIGN = "docs/DESIGN.md";
627636 const SECTIONS = "docs/design/sections";
@@ -638,7 +647,7 @@ if (import.meta.main) {
638647 } else {
639648 const base: Baseline = JSON.parse(readFileSync(join(root, BASELINE), "utf8"));
640649 const debt: QuietDebt = JSON.parse(readFileSync(join(root, QUIET_DEBT), "utf8"));
641 const problems = [...compare(base, now, designText(root), areaFiles(root)), ...compareQuiet(debt, scanQuiet(root)), ...scanBanner(root), ...compareLayout(base.layout ?? {}, scanLayout(root)), ...scanOverlay(root), ...scanCards(root), ...scanStranger(root), ...scanMotion(root), ...scanWidth(root), ...contrastFindings()];
650 const problems = [...compare(base, now, designText(root), areaFiles(root)), ...compareQuiet(debt, scanQuiet(root)), ...scanBanner(root), ...compareLayout(base.layout ?? {}, scanLayout(root)), ...scanOverlay(root), ...scanCards(root), ...scanStranger(root), ...scanMotion(root), ...scanWidth(root), ...scanDictate(root), ...contrastFindings()];
642651 for (const p of problems) console.error(p);
643652 if (problems.length) process.exit(1);
644653 console.log("design: no colour, size or component added outside the system");
src/design/dictate.ts added +55
@@ -0,0 +1,55 @@
1 /**
2 * The Dictate button (#14198): the /talk `[data-dictate]` button keeps a name and a 44px target.
3 * It is named by its text or an aria-label, and sized by `.btn`, whose coarse-pointer rule is
4 * 44px; a height of its own that is smaller would undo that. Plain data in (the page's source and
5 * the stylesheet's), plain problems out.
6 */
7
8 const strip = (css: string): string => css.replace(/\/\*[\s\S]*?\*\//g, "");
9
10 type Rule = { selectors: string[]; body: string; coarse: boolean };
11
12 /**
13 * Every style rule of a sheet, flattened, with whether a `@media (pointer: coarse)` encloses it.
14 */
15 function rules(text: string, coarse = false, out: Rule[] = []): Rule[] {
16 let i = 0;
17 while (i < text.length) {
18 const open = text.indexOf("{", i);
19 if (open < 0) break;
outdated

Does not require the coarse-pointer media block; any .btn{min-height:44px} passes. Parse the @media (pointer: coarse) block and look inside it.

20 let depth = 1, j = open + 1;
21 while (j < text.length && depth) depth += text[j] === "{" ? 1 : text[j] === "}" ? -1 : 0, j++;
outdated

Only px, and [^{,]* skips selector lists. Convert rem/em and match every rule whose selector list contains .talk-dictate.

22 const head = text.slice(i, open).split(/[;}`]/).pop()!.trim();
23 const inner = text.slice(open + 1, j - 1);
24 if (head.startsWith("@")) rules(inner, coarse || (/^@media\b/i.test(head) && /\(\s*pointer\s*:\s*coarse\s*\)/i.test(head) && !/\bnot\b/i.test(head)), out);
25 else out.push({ selectors: head.split(",").map((x) => x.trim()), body: inner, coarse });
26 i = j;
27 }
28 return out;
29 }
30
31 const px = (n: string, unit: string): number => Number(n) * (unit === "px" ? 1 : 16);
32
33 /**
34 * Only `.talk-dictate` rules (any selector list or state, px, rem or em at 16px) and the plain
35 * `.btn` rule are read; an override through another selector such as `.talk-compose .btn` is not.
36 */
37 export function dictateFindings(page: string, css: string): string[] {
38 const out: string[] = [];
39 const m = /<button\b([^>]*\bdata-dictate\b[^>]*)>([\s\S]*?)<\/button>/.exec(page);
40 if (!m) return ["the [data-dictate] button is gone from src/web/pages/talk.ts"];
41 const [, attrs = "", inner = ""] = m;
42 const named = inner.replace(/<[^>]*>/g, "").trim() !== "" || /\baria-label="[^"]+"/.test(attrs);
43 if (!named) out.push("the [data-dictate] button has no text and no aria-label: give it a name");
44 if (!/\bclass="[^"]*\bbtn\b[^"]*"/.test(attrs)) out.push("the [data-dictate] button lost class `btn`, which gives it the 44px target");
45 const all = rules(strip(css));
46 const btn44 = all.some((r) => r.coarse && r.selectors.includes(".btn") && [...r.body.matchAll(/(?:^|[;\s])min-height\s*:\s*(\d+(?:\.\d+)?)px/g)].some((x) => Number(x[1]) >= 44));
47 if (!btn44) out.push("`.btn` has no min-height of 44px inside @media (pointer: coarse) in the stylesheet");
48 for (const r of all) {
49 if (!r.selectors.some((x) => /\.talk-dictate(?![\w-])/.test(x))) continue;
50 for (const h of r.body.matchAll(/(?:^|[;\s])(?:min-height|height|max-height)\s*:\s*(\d+(?:\.\d+)?)(px|rem|em)\b/g)) {
51 if (px(h[1] ?? "0", h[2] ?? "px") < 44) out.push(`.talk-dictate sets a height of ${h[1]}${h[2]}, under the 44px target`);
52 }
53 }
54 return out;
55 }
test/talk-voice.test.ts +30
@@ -4,7 +4,9 @@
44 * what went wrong in words, and is never mistaken for the Send button.
55 */
66 import { describe, expect, test } from "bun:test";
7 import { readFileSync } from "node:fs";
78 import { Window } from "happy-dom";
9 import { dictateFindings, scanDictate } from "../scripts/design-lint.ts";
810 import { dictateJs, sendSelector, talkCss, talkJs } from "../src/web/pages/talk_client.ts";
911
1012 class Stub {
@@ -86,3 +88,31 @@ describe("talk dictation", () => {
8688 expect(dictateJs.length).toBeLessThan(1400);
8789 });
8890 });
outdated

Imports belong at the top of the file.

91
92 describe("design lint: the Dictate button is named and 44px (#14198)", () => {
93 const page = readFileSync("src/web/pages/talk.ts", "utf8");
94 const css = readFileSync("src/web/style/components.ts", "utf8");
95 test("the shipped page and sheet pass", () => {
96 expect(dictateFindings(page, css)).toEqual([]);
97 expect(scanDictate(process.cwd())).toEqual([]);
98 });
99 test("losing the name, the btn class, the 44px rule or adding a short height each fails", () => {
100 expect(dictateFindings(page.replace(">Dictate</button>", "></button>"), css).join()).toContain("no text");
101 expect(dictateFindings(page.replace('class="btn talk-dictate"', 'class="talk-dictate"'), css).join()).toContain("btn");
102 expect(dictateFindings(page, css.replace(".btn { min-height: 44px; }", ".btn { min-height: 40px; }")).join()).toContain("44px");
103 expect(dictateFindings(page, css + ".talk-dictate { height: 30px; }").join()).toContain("30px");
104 expect(dictateFindings(page.replace(">Dictate</button>", ' aria-label="Dictate"></button>'), css)).toEqual([]);
105 });
106 test("the 44px rule must sit in a coarse-pointer block", () => {
107 const fine = css.replace("@media (pointer: coarse) {\n .btn { min-height: 44px; }", "@media (pointer: fine) {\n .btn { min-height: 44px; }");
108 expect(fine).not.toBe(css);
109 expect(dictateFindings(page, fine).join()).toContain("pointer: coarse");
110 });
111 test("rem, em, selector lists and states of .talk-dictate are read", () => {
112 expect(dictateFindings(page, css + ".talk-dictate { height: 2rem; }").join()).toContain("2rem");
113 expect(dictateFindings(page, css + ".talk-dictate { min-height: 2em; }").join()).toContain("2em");
114 expect(dictateFindings(page, css + ".talk-dictate, .x { height: 30px; }").join()).toContain("30px");
115 expect(dictateFindings(page, css + '.x, .talk-dictate[aria-pressed="true"] { height: 30px; }').join()).toContain("30px");
116 expect(dictateFindings(page, css + ".talk-dictate { min-height: 3rem; }")).toEqual([]);
117 });
118 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs