@domandigital/create-site 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @domandigital/create-site
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 63dfae5: `measure.mjs` uses craft's every-viewport measure (DOM-787, part of DOM-772): one measure that the portal gates use too. It measures every page at 320, 375, 390, 430, landscape 844 x 390, 768, 1024, 1280, 1440 and 1920, phone first, with a width sweep from 320 to 1920, and keeps its earlier failures (a page that does not answer, sideways scroll, no viewport meta, text under `measure.minFontPx`, targets under 44 x 44, fields under 16px, labels, noindex on a preview). New failures: text over text and a cut-off title at any width; on a short phone, the main action (`measure.mainAction`) off the first screen, fixed layers over a quarter of the screen, oversized or stretched images, wrong keyboards and missing autocomplete, phone numbers that are not `tel:` links; in landscape, fixed layers over half the height; at 1440 and 1920, body lines over 80 characters. `site.programme.json` `measure` gains `mainAction`, `thresholds`, `sweep` and `baseline` (known failures in craft's baseline format, written by `--update-baseline`); a failure names the widths it happens at. New sites install `@domandigital/craft` ^0.20.0, which carries the measure.
8
+
9
+ ## 0.7.1
10
+
11
+ ### Patch Changes
12
+
13
+ - c88e737: The site measure gate now sees sideways scroll at phone widths (DOM-774). It compared `scrollWidth` with `window.innerWidth`, which grows with the page under mobile emulation, so a 500px-wide page at 375 passed. It now measures against the layout viewport (`clientWidth`), reports a page with no `width=device-width` viewport meta, and treats a target parked past the right edge as off the page, as `@domandigital/craft/phone` does.
14
+
3
15
  ## 0.7.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -70,10 +70,19 @@ the build:
70
70
  | `null-check.mjs` | 06 | the deck carries a phrase the null builds kept writing, without a reason |
71
71
  | `mobile-first.mjs` | 06 | the source has a `max-width` media query or a Tailwind `max-*:` variant with no recorded exception: the phone is the base layout |
72
72
 
73
- `pnpm measure` serves the last build and measures it phone first, at 375, 390
74
- and 1440: it fails on sideways scroll, on text under 12px, and on a label
75
- outside its container, and at the two phone widths on a target under 44px and
76
- a form field set under 16px.
73
+ `pnpm measure` serves the last build and measures it at every viewport, phone
74
+ first, with craft's measure (`@domandigital/craft/phone`, the one the portal
75
+ gates use): the ladder 320, 375, 390, 430, landscape 844 x 390, 768, 1024,
76
+ 1280, 1440 and 1920, and a sweep from 320 to 1920 in 16 to 32px steps. At any
77
+ width it fails on sideways scroll, on text over other text, on a cut-off page
78
+ title, on text under 12px and on a label outside its container; on a phone, on
79
+ a target under 44px and a form field set under 16px; on a short phone (375 x
80
+ 667), on a main action below the first screen (`measure.mainAction`), fixed
81
+ layers over a quarter of the screen, images far larger than they are shown or
82
+ stretched, a phone, email or number field with the wrong keyboard or no
83
+ autocomplete, and a phone number that is not a `tel:` link; in landscape, on
84
+ fixed layers over half the height; at 1440 and 1920, on body lines over 80
85
+ characters. `measure.baseline` lists known failures so they stay visible.
77
86
  `pnpm deploy:preview` is the only deploy: it sets `PUBLIC_PREVIEW` itself,
78
87
  builds, measures with noindex required, and deploys a preview to Cloudflare
79
88
  or Vercel; it refuses a route, a custom domain or `--prod`. So a site made
package/dist/cli.js CHANGED
@@ -788,11 +788,11 @@ var HOUSE_DEPENDENCIES = {
788
788
  "@domandigital/seo": "^0.3.0"
789
789
  };
790
790
  var HOUSE_DEV_DEPENDENCIES = {
791
- "@domandigital/craft": "^0.19.0",
791
+ "@domandigital/craft": "^0.20.0",
792
792
  "@types/node": "^22.0.0",
793
793
  vitest: "^4.1.11",
794
- // scripts/gates/measure.mjs renders the pages at 375, 390 and 1440 before every
795
- // preview deploy; tsx loads the copy deck on Node older than 22.18.
794
+ // scripts/gates/measure.mjs renders the pages at every viewport, phone first,
795
+ // before every preview deploy, with craft's measure; tsx loads the copy deck on Node older than 22.18.
796
796
  playwright: "^1.62.0",
797
797
  tsx: "^4.20.0"
798
798
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domandigital/create-site",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "private": false,
5
5
  "description": "The first thing that runs on a new Doman Digital client site: installs the house packages and writes the per-site files they read (the facts file, route policy, backlink register, redirects, JSON-LD, the designer credit, house docs and the SEO checks), so every build starts on the same foundation and stays upgradeable by bumping packages.",
6
6
  "license": "Apache-2.0",
@@ -41,7 +41,7 @@
41
41
  "tsup": "^8.3.5",
42
42
  "typescript": "^5.6.3",
43
43
  "vitest": "^4.0.0",
44
- "@domandigital/craft": "^0.19.1",
44
+ "@domandigital/craft": "^0.20.0",
45
45
  "@domandigital/graph": "^0.7.0",
46
46
  "@domandigital/seo": "^0.3.1"
47
47
  },
@@ -48,7 +48,7 @@ a file is not acceptance.
48
48
  | 03 Low-fidelity wireframes, phone first | A versioned wireframe set covering every page family at 375px first, then the desktop derived from it, annotated with evidence, destination and holds | Hierarchy and journey coverage accepted on the phone set first; missing proof is an obvious placeholder | None: wireframes are reviewed, not built |
49
49
  | 04 Validate the prototype and iterate the journeys | Test tasks, the synthetic buyer panel's run, then human sessions; findings and a revised wireframe version | Critical task failures fixed and rechecked; the approved wireframe version is named | The buyer panel (`packages/buyer-panel` in dd-packages) run on the prototype; its report linked on the issue |
50
50
  | 05 Visual direction, argued from evidence and measured | `art-direction.json`: the job, a hierarchy per page type and the seven choices with their reasons; the night side in `art-direction.sheets.json`; the accent test | The human choice and its reason recorded on the issue; no value adopted because an earlier pack showed it | `check-direction.mjs`, `tokens.mjs`, `night-contrast.mjs` |
51
- | 06 Detailed pages, content and the component system | The real app on a preview, every page family, the copy deck through the gates, built phone first and measured at 375, then 390, then 1440 | Design and content accepted at an exact version, from the phone captures first; no invented price or claim in the deck | `facts.mjs`, `copy-deck.mjs`, `null-check.mjs`, `mobile-first.mjs`, `measure.mjs`, `deploy-preview.mjs` |
51
+ | 06 Detailed pages, content and the component system | The real app on a preview, every page family, the copy deck through the gates, built phone first and measured at every viewport, from 375 up, with the width sweep | Design and content accepted at an exact version, from the phone captures first; no invented price or claim in the deck | `facts.mjs`, `copy-deck.mjs`, `null-check.mjs`, `mobile-first.mjs`, `measure.mjs`, `deploy-preview.mjs` |
52
52
  | 07 Implementation and content migration plan | Slices, the file and CMS ownership manifest, the route, SEO and redirect plan, tests per slice, release and rollback outline | A named reviewer accepts the plan and the first slice | `redirects.json` and `tests/seo/redirects.test.ts` |
53
53
  | 08 Build the approved slices and verify rendered drafts | Reviewed PRs, protected CMS drafts, rendered previews, slice-level checks | Every slice matches the accepted design or has a recorded deviation | Every gate above, on every build and every preview |
54
54
  | 09 QA across every journey, and the release decision | The acceptance report across every page family and journey; a named go or no-go | No release-critical defect open; residual risks accepted by the right person | `launch:check`, `craft direction validate --snapshot <preview> --strict`; the live domain is attached here and nowhere earlier |
@@ -73,7 +73,7 @@ Run around a running build:
73
73
 
74
74
  | Gate | Stage | Fails when |
75
75
  | --- | --- | --- |
76
- | `measure.mjs` | 06 | measured phone first, at 375, then 390, then 1440: a page in `measure.pages` does not answer, scrolls sideways, or shows text under `measure.minFontPx`; at 375 and 390, a link, button, field or summary is under 44 x 44 CSS px (a link inside a sentence is exempt) or a text field is set under 16px; a label in `measure.labels` leaves its container or covers a label or copy; with `--preview`, a page has no noindex |
76
+ | `measure.mjs` | 06 | measured with craft's measure (`@domandigital/craft/phone`) at every viewport, phone first: the ladder 320, 375, 390, 430, landscape 844 x 390, 768, 1024, 1280, 1440, 1920, and a width sweep from 320 to 1920 in 16 to 32px steps. A page in `measure.pages` does not answer; at any width it scrolls sideways, has visible text over other text, has a cut-off page title or text under `measure.minFontPx`; on a phone, a link, button, field or summary is under 44 x 44 CSS px (a link inside a sentence is exempt) or a text field is set under 16px; on a short phone (375 x 667), the main action in `measure.mainAction` is below the first screen and not pinned, fixed and sticky layers cover more than a quarter of the screen, an image is more than about 2.5 times wider than it is shown or is stretched past its file, a phone, email or number field has the wrong keyboard, a name, email or address field has no autocomplete, or a UK phone number in the text is not a `tel:` link; on a landscape phone, header and fixed layers cover more than half the height; at 1440 and 1920, body lines run past 80 characters or an image is stretched; a label in `measure.labels` leaves its container or covers a label or copy; with `--preview`, a page has no noindex. A failure names the widths it happens at |
77
77
  | `deploy-preview.mjs` | 06 to 08 | the build, the measurement or the host's config refuses it (a route, a custom domain or `--prod`). Sets `PUBLIC_PREVIEW=1` and `NEXT_PUBLIC_PREVIEW=1` itself |
78
78
 
79
79
  The site reads `PUBLIC_PREVIEW` (Astro, `import.meta.env.PUBLIC_PREVIEW`) or
@@ -100,7 +100,7 @@ pricing modules and writes the facts the redesign renders.
100
100
  | `issue` | The programme issue in Linear (`DOM-123`) |
101
101
  | `registeredDirection` | The direction's registered copy in the craft estate, usually `~/dd-ops/<site>/art-direction.json`; null until registered |
102
102
  | `paths` | Where the token stylesheet, the deck, the rendered deck and the null-check report live, and the source folders `facts.mjs` reads |
103
- | `measure` | `pages`, `minFontPx` (12), `labels` (`{ "selector": ".label", "within": ".screen" }` or null), `port` |
103
+ | `measure` | `pages`, `minFontPx` (12), `labels` (`{ "selector": ".label", "within": ".screen" }` or null), `port`, `mainAction` (a CSS selector for the page's main action, or `{ "/": ".hero a", "*": "a.book" }` per page; not checked when absent), `thresholds` (override a house default: `maxLayerShare` 0.25, `landscapeMaxLayerShare` 0.5, `oversizeRatio` 2.5, `upscaleRatio` 1, `maxLineCh` 80, `overlapShare` 0.4, `minImagePx` 32), `sweep` (`{ "step": 16, "wideStep": 32 }`, or `false` to measure the ladder only), `baseline` (a file of known failures, craft's phone-first baseline format; `node scripts/gates/measure.mjs --serve --update-baseline` writes it, and it only shrinks) |
104
104
  | `nullCheck` | `harvest` (a path, `~/` allowed) and `justified` (phrase to reason) |
105
105
  | `facts` | `importer`: the site's importer script, or null |
106
106
  | `mobileFirst` | `exceptions`: the files allowed a `max-width` query or `max-*:` variant, each `{ "file": "src/styles/print.css", "reason": "..." }` |
@@ -1,19 +1,40 @@
1
1
  // Stage 06 gate: measures the rendered pages rather than trusting the
2
- // stylesheet, phone first (STANDARD.md section 10 in @domandigital/craft):
3
- // 375 x 812, the floor every surface is designed at, then 390 x 844, the
4
- // width the design is accepted at, then 1440 x 900. On every page named in
5
- // site.programme.json measure.pages, at every width: the page answers,
6
- // nothing scrolls sideways, no visible text is smaller than
7
- // measure.minFontPx, and, when measure.labels names them, every label sits
8
- // inside its container, over no other label and no copy. At the two phone
9
- // widths, also: every link, button, field and summary a thumb has to hit is
10
- // at least 44 x 44 CSS px (a link inside a sentence is exempt, as in WCAG
11
- // 2.5.5; a field's label counts as its target), and every text field is set
12
- // at 16px or more, so Safari on iOS does not zoom on focus. With --preview,
13
- // every page must also carry a noindex robots meta, so a preview cannot be
14
- // indexed. Writes measure/measure.json, with the hash of the direction it
15
- // measured, and a full-page capture per page and width under measure/out,
16
- // phone captures first. Exits 1 on any failure.
2
+ // stylesheet, at every viewport, phone first (STANDARD.md section 10 in
3
+ // @domandigital/craft, DOM-787). The measure itself is craft's
4
+ // (@domandigital/craft/phone), the same one the portal gates use: this file
5
+ // serves the build, names the pages, adds what only a site has (labels,
6
+ // noindex on a preview) and fails the build on what it finds.
7
+ //
8
+ // On every page named in site.programme.json measure.pages, in order:
9
+ // - the viewport ladder, phone first: 320, 375, 390, 430, landscape 844 x 390,
10
+ // 768, 1024, 1280, 1440, 1920, and a width sweep from 320 to 1920 in
11
+ // 16 to 32px steps, so what breaks between the breakpoints shows;
12
+ // - at any width: the page answers, nothing scrolls sideways, no visible
13
+ // text sits on other text, no page title is cut off, no visible text is
14
+ // smaller than measure.minFontPx, and, when measure.labels names them,
15
+ // every label sits inside its container, over no other label and no copy;
16
+ // - on a phone (320 to 430, and landscape): every link, button, field and
17
+ // summary a thumb has to hit is at least 44 x 44 CSS px (a link inside a
18
+ // sentence is exempt, as in WCAG 2.5.5; a field's label counts as its
19
+ // target), and every text field is set at 16px or more, so Safari on iOS
20
+ // does not zoom on focus;
21
+ // - on a short phone, 375 x 667: the main action (measure.mainAction, a
22
+ // selector, or one per page) is on the first screen or pinned; fixed and
23
+ // sticky layers cover at most a quarter of the screen; images are neither
24
+ // far larger than they are shown nor stretched; phone, email and number
25
+ // fields use the keyboard that fits and carry autocomplete; phone numbers
26
+ // in the text are tel: links;
27
+ // - on a landscape phone, header and fixed layers leave half the height;
28
+ // - at 1440 and 1920: body text lines stay under 80 characters and no image
29
+ // is stretched past its file.
30
+ // With --preview, every page must also carry a noindex robots meta, so a
31
+ // preview cannot be indexed. Thresholds are craft's house defaults;
32
+ // measure.thresholds overrides one. measure.baseline names a file of known
33
+ // failures (craft's phone-first baseline format, written by --update-baseline):
34
+ // those stay listed and visible, and anything new fails. Writes
35
+ // measure/measure.json, with the hash of the direction it measured, and a
36
+ // full-page capture per page and ladder viewport under measure/out, phone
37
+ // captures first. Exits 1 on any failure.
17
38
  //
18
39
  // --serve serves the last build itself and measures that: static output in
19
40
  // dist/ is served from here the way the host serves it (no trailing slash,
@@ -22,7 +43,9 @@
22
43
  // --base <url> measures a server that is already running instead.
23
44
  //
24
45
  // Lifted from apps/site/scripts/measure.mjs in Doman-Digital (DOM-647), with
25
- // the redesign's own label component generalised to a selector.
46
+ // the redesign's own label component generalised to a selector; the
47
+ // measuring moved into craft so a site and a portal are measured the same way
48
+ // (DOM-787).
26
49
 
27
50
  import { spawn } from "node:child_process";
28
51
  import { createHash } from "node:crypto";
@@ -33,15 +56,12 @@ import { parseArgs } from "node:util";
33
56
  import { programme, root, sitePath, stop } from "./programme.mjs";
34
57
 
35
58
  const GATE = "measure";
36
- const { values } = parseArgs({ options: { base: { type: "string" }, serve: { type: "boolean", default: false }, preview: { type: "boolean", default: false } } });
59
+ const { values } = parseArgs({ options: { base: { type: "string" }, serve: { type: "boolean", default: false }, preview: { type: "boolean", default: false }, "update-baseline": { type: "boolean", default: false } } });
37
60
  const { measure = {}, paths } = programme();
38
61
  const port = measure.port ?? 4410;
39
62
  const base = (values.base ?? `http://127.0.0.1:${port}`).replace(/\/$/, "");
40
63
  const pages = measure.pages?.length ? measure.pages : ["/"];
41
64
  const minFontPx = measure.minFontPx ?? 12;
42
- // The house floors at phone width: STANDARD.md section 10. Not per-site settings.
43
- const MIN_TARGET_PX = 44;
44
- const MIN_FIELD_FONT_PX = 16;
45
65
  const labels = measure.labels ?? null;
46
66
  const outDir = join(root, "measure", "out");
47
67
  mkdirSync(outDir, { recursive: true });
@@ -52,134 +72,123 @@ try {
52
72
  } catch {
53
73
  stop(GATE, "06", "playwright is not installed. Add it as a dev dependency and run `npx playwright install chromium`.");
54
74
  }
75
+ let craft;
76
+ try {
77
+ craft = await import("@domandigital/craft/phone");
78
+ } catch {
79
+ stop(GATE, "06", "@domandigital/craft is not installed, or is older than the every-viewport measure (0.20). Install the site's dependencies.");
80
+ }
81
+ const { measureSite, judgeMeasured, writeBaseline, EMPTY_BASELINE, LADDER, PHONE_FLOORS, DEFAULT_THRESHOLDS } = craft;
55
82
 
56
83
  const close = values.serve ? await serveBuild() : () => {};
57
84
 
58
85
  const hash = (p) => (existsSync(p) ? createHash("sha256").update(readFileSync(p)).digest("hex").slice(0, 16) : null);
59
86
  const slug = (route) => (route === "/" ? "home" : route.replace(/^\//, "").replace(/\//g, "-"));
60
- const VIEWPORTS = [
61
- { name: "375x812", phone: true, viewport: { width: 375, height: 812 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true },
62
- { name: "390x844", phone: true, viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true },
63
- { name: "1440x900", phone: false, viewport: { width: 1440, height: 900 } },
64
- ];
87
+
88
+ // What only a site has, read at each ladder viewport as craft hands over the page.
89
+ const extras = Object.fromEntries(pages.map((route) => [route, { noindex: false, labels: {} }]));
90
+ async function atViewport(page, viewport, route) {
91
+ const found = await page.evaluate(
92
+ ({ labels }) => {
93
+ const R = (e) => {
94
+ const r = e.getBoundingClientRect();
95
+ return { l: r.left, t: r.top, r: r.right, b: r.bottom };
96
+ };
97
+ const ov = (a, b) => !(a.r <= b.l || b.r <= a.l || a.b <= b.t || b.b <= a.t);
98
+ const shown = (e) => {
99
+ const s = getComputedStyle(e);
100
+ return s.display !== "none" && s.visibility !== "hidden" && e.getClientRects().length > 0;
101
+ };
102
+ const out = { noindex: /noindex/i.test(document.querySelector('meta[name="robots"]')?.getAttribute("content") ?? ""), labels: [] };
103
+ if (labels?.selector) {
104
+ const all = [...document.querySelectorAll(labels.selector)].filter(shown);
105
+ const copy = [...document.querySelectorAll("main h1, main h2, main h3, main p, main li")].filter(shown);
106
+ for (const l of all) {
107
+ const r = R(l);
108
+ const box = labels.within ? l.parentElement?.closest(labels.within) : null;
109
+ const b = box ? R(box) : null;
110
+ out.labels.push({
111
+ text: l.textContent.trim().slice(0, 40),
112
+ inside: b ? r.l >= b.l - 0.5 && r.t >= b.t - 0.5 && r.r <= b.r + 0.5 && r.b <= b.b + 0.5 : null,
113
+ overLabels: all.filter((o) => o !== l && ov(r, R(o))).length,
114
+ overCopy: copy.filter((t) => !l.contains(t) && !t.contains(l) && ov(r, R(t))).length,
115
+ fontPx: parseFloat(getComputedStyle(l).fontSize),
116
+ });
117
+ }
118
+ }
119
+ return out;
120
+ },
121
+ { labels },
122
+ );
123
+ extras[route].noindex = found.noindex;
124
+ extras[route].labels[viewport.name] = found.labels;
125
+ await page.screenshot({ path: join(outDir, `${slug(route)}-${viewport.name}.png`), fullPage: true });
126
+ }
65
127
 
66
128
  const browser = await chromium.launch();
67
- const failures = [];
68
- const res = { base, measuredAt: new Date().toISOString(), preview: values.preview, direction: hash(join(root, "art-direction.json")), tokens: hash(sitePath(paths.tokens)), minFontPx, minTargetPx: MIN_TARGET_PX, minFieldFontPx: MIN_FIELD_FONT_PX, pages: {} };
129
+ let site;
130
+ try {
131
+ site = await measureSite(browser, {
132
+ base,
133
+ routes: pages,
134
+ out: false,
135
+ floors: { textPx: minFontPx },
136
+ ...(measure.mainAction ? { mainAction: measure.mainAction } : {}),
137
+ ...(measure.thresholds ? { thresholds: measure.thresholds } : {}),
138
+ ...(measure.sweep !== undefined ? { sweep: measure.sweep } : {}),
139
+ onViewport: atViewport,
140
+ });
141
+ } finally {
142
+ await browser.close();
143
+ close();
144
+ }
69
145
 
70
- for (const route of pages) {
71
- res.pages[route] = {};
72
- for (const { name, phone, ...options } of VIEWPORTS) {
73
- const context = await browser.newContext(options);
74
- const page = await context.newPage();
75
- const resp = await page.goto(base + route).catch((error) => ({ ok: () => false, status: () => error.message }));
76
- if (!resp || !resp.ok()) {
77
- res.pages[route][name] = { error: `HTTP ${resp?.status()}` };
78
- failures.push(`${route} at ${name}: HTTP ${resp?.status()}`);
79
- await context.close();
80
- continue;
81
- }
82
- await page.evaluate(() => document.fonts.ready);
83
- await settle(page);
84
- const m = await page.evaluate(
85
- ({ labels, minFontPx, phone, minTargetPx, minFieldFontPx }) => {
86
- const R = (e) => {
87
- const r = e.getBoundingClientRect();
88
- return { l: r.left, t: r.top, r: r.right, b: r.bottom };
89
- };
90
- const ov = (a, b) => !(a.r <= b.l || b.r <= a.l || a.b <= b.t || b.b <= a.t);
91
- const shown = (e) => {
92
- const s = getComputedStyle(e);
93
- return s.display !== "none" && s.visibility !== "hidden" && e.getClientRects().length > 0;
94
- };
95
- // Text an element shows itself, not text it inherits from a child.
96
- const texty = [...document.querySelectorAll("body *")].filter(
97
- (e) => shown(e) && [...e.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim()) && !e.closest("[aria-hidden='true'], .sr-only, .visually-hidden"),
98
- );
99
- const small = texty
100
- .map((e) => ({ tag: e.tagName.toLowerCase(), cls: String(e.className || ""), px: parseFloat(getComputedStyle(e).fontSize), text: e.textContent.trim().slice(0, 40) }))
101
- .filter((t) => t.px < minFontPx);
102
- const out = {
103
- horizontalScroll: document.documentElement.scrollWidth > window.innerWidth,
104
- fontSizesUsed: [...new Set(texty.map((e) => getComputedStyle(e).fontSize))].sort((a, b) => parseFloat(a) - parseFloat(b)),
105
- smallText: small.slice(0, 10),
106
- noindex: /noindex/i.test(document.querySelector('meta[name="robots"]')?.getAttribute("content") ?? ""),
107
- labels: [],
108
- smallTargets: [],
109
- smallFields: [],
110
- };
111
- if (phone) {
112
- const name = (e) => ({ tag: e.tagName.toLowerCase(), cls: String(e.className || ""), text: (e.textContent.trim() || e.getAttribute("aria-label") || e.getAttribute("name") || "").slice(0, 40) });
113
- // Visually hidden (an sr-only skip link) or parked off the page: not a target until it is shown.
114
- const hidden = (e, r) => e.closest("[aria-hidden='true'], .sr-only, .visually-hidden") || r.width <= 1 || r.height <= 1 || r.right <= 0 || r.bottom <= -window.scrollY;
115
- // WCAG 2.5.5's inline exception: a link in a sentence is sized by the line it sits in.
116
- const inline = (e) => {
117
- if (e.tagName !== "A" || getComputedStyle(e).display !== "inline") return false;
118
- const block = e.parentElement?.closest("p, li, dd, td, th, blockquote, figcaption, address");
119
- return !!block && block.textContent.trim().length > e.textContent.trim().length;
120
- };
121
- const targets = [...document.querySelectorAll("a[href], button, input:not([type='hidden']), select, textarea, [role='button'], summary")].filter(shown);
122
- for (const e of targets) {
123
- const r = e.getBoundingClientRect();
124
- if (hidden(e, r) || inline(e)) continue;
125
- // A field's label is a hit target too: a 20px checkbox in a 44px label passes.
126
- const boxes = [r, ...[...(e.labels ?? [])].filter(shown).map((l) => l.getBoundingClientRect())];
127
- const w = Math.max(...boxes.map((b) => b.width));
128
- const h = Math.max(...boxes.map((b) => b.height));
129
- if (Math.round(w) < minTargetPx || Math.round(h) < minTargetPx) out.smallTargets.push({ ...name(e), w: Math.round(w), h: Math.round(h) });
130
- }
131
- const NOT_TEXT = new Set(["checkbox", "radio", "range", "color", "file", "submit", "reset", "button", "image"]);
132
- for (const e of document.querySelectorAll("input:not([type='hidden']), select, textarea")) {
133
- if (!shown(e) || (e.tagName === "INPUT" && NOT_TEXT.has(e.type))) continue;
134
- const px = parseFloat(getComputedStyle(e).fontSize);
135
- if (px < minFieldFontPx) out.smallFields.push({ ...name(e), px: Math.round(px * 10) / 10 });
136
- }
137
- }
138
- if (labels?.selector) {
139
- const all = [...document.querySelectorAll(labels.selector)].filter(shown);
140
- const copy = [...document.querySelectorAll("main h1, main h2, main h3, main p, main li")].filter(shown);
141
- for (const l of all) {
142
- const r = R(l);
143
- const box = labels.within ? l.parentElement?.closest(labels.within) : null;
144
- const b = box ? R(box) : null;
145
- out.labels.push({
146
- text: l.textContent.trim().slice(0, 40),
147
- inside: b ? r.l >= b.l - 0.5 && r.t >= b.t - 0.5 && r.r <= b.r + 0.5 && r.b <= b.b + 0.5 : null,
148
- overLabels: all.filter((o) => o !== l && ov(r, R(o))).length,
149
- overCopy: copy.filter((t) => !l.contains(t) && !t.contains(l) && ov(r, R(t))).length,
150
- fontPx: parseFloat(getComputedStyle(l).fontSize),
151
- });
152
- }
153
- }
154
- return out;
155
- },
156
- { labels, minFontPx, phone, minTargetPx: MIN_TARGET_PX, minFieldFontPx: MIN_FIELD_FONT_PX },
157
- );
146
+ const baselineFile = measure.baseline ? sitePath(measure.baseline) : null;
147
+ const updating = values["update-baseline"];
148
+ if (updating) {
149
+ if (!baselineFile) stop(GATE, "06", "--update-baseline needs measure.baseline in site.programme.json: the file the known failures go in.");
150
+ const note = existsSync(baselineFile) ? JSON.parse(readFileSync(baselineFile, "utf8")).note : undefined;
151
+ writeFileSync(baselineFile, `${JSON.stringify(writeBaseline([], site.routes, note), null, 2)}\n`);
152
+ console.log(`${GATE}: wrote ${measure.baseline}. Each line in it is a failure to fix; the count only goes down.`);
153
+ }
154
+ const baseline = baselineFile && existsSync(baselineFile) ? { static: [], measured: [], ...JSON.parse(readFileSync(baselineFile, "utf8")) } : EMPTY_BASELINE;
155
+ const judged = judgeMeasured(site.routes, baseline);
156
+
157
+ const failures = [...site.errors.map((e) => `${e.route}: ${e.error}`), ...judged.fresh, ...judged.stale];
158
+ for (const [route, { noindex, labels: byViewport }] of Object.entries(extras)) {
159
+ if (site.errors.some((e) => e.route === route)) continue;
160
+ for (const [name, list] of Object.entries(byViewport)) {
158
161
  const at = `${route} at ${name}`;
159
- if (m.horizontalScroll) failures.push(`${at}: the page scrolls sideways`);
160
- for (const t of m.smallText) failures.push(`${at}: ${t.px}px text under ${minFontPx}px (<${t.tag}${t.cls ? ` class="${t.cls}"` : ""}> "${t.text}")`);
161
- const tag = (t) => `<${t.tag}${t.cls ? ` class="${t.cls}"` : ""}>${t.text ? ` "${t.text}"` : ""}`;
162
- for (const t of m.smallTargets.slice(0, 10)) failures.push(`${at}: a ${t.w}x${t.h}px target under ${MIN_TARGET_PX}x${MIN_TARGET_PX} (${tag(t)})`);
163
- if (m.smallTargets.length > 10) failures.push(`${at}: ${m.smallTargets.length - 10} more targets under ${MIN_TARGET_PX}x${MIN_TARGET_PX}; measure/measure.json lists them`);
164
- for (const t of m.smallFields) failures.push(`${at}: a field set at ${t.px}px, under ${MIN_FIELD_FONT_PX}px, so Safari on iOS zooms on focus (${tag(t)})`);
165
- for (const l of m.labels) {
162
+ for (const l of list) {
166
163
  if (l.inside === false) failures.push(`${at}: label "${l.text}" leaves its ${labels.within}`);
167
164
  if (l.overLabels) failures.push(`${at}: label "${l.text}" sits over another label`);
168
165
  if (l.overCopy) failures.push(`${at}: label "${l.text}" sits over copy`);
169
166
  }
170
- if (values.preview && !m.noindex) failures.push(`${at}: no noindex robots meta on a preview build (read PUBLIC_PREVIEW)`);
171
- res.pages[route][name] = m;
172
- await page.screenshot({ path: join(outDir, `${slug(route)}-${name}.png`), fullPage: true });
173
- await context.close();
174
167
  }
168
+ if (values.preview && !noindex) failures.push(`${route}: no noindex robots meta on a preview build (read PUBLIC_PREVIEW)`);
175
169
  }
176
- await browser.close();
177
- close();
178
170
 
179
- res.failures = failures;
171
+ const res = {
172
+ base,
173
+ measuredAt: new Date().toISOString(),
174
+ preview: values.preview,
175
+ direction: hash(join(root, "art-direction.json")),
176
+ tokens: hash(sitePath(paths.tokens)),
177
+ minFontPx,
178
+ minTargetPx: PHONE_FLOORS.targetPx,
179
+ minFieldFontPx: PHONE_FLOORS.fieldFontPx,
180
+ thresholds: { ...DEFAULT_THRESHOLDS, ...(measure.thresholds ?? {}) },
181
+ mainAction: measure.mainAction ?? null,
182
+ baseline: measure.baseline ?? null,
183
+ knownBreaches: judged.known,
184
+ pages: Object.fromEntries(site.routes.map((r) => [r.route, { viewports: r.viewports, findings: r.findings, noindex: extras[r.route].noindex, labels: extras[r.route].labels }])),
185
+ errors: site.errors,
186
+ failures,
187
+ };
180
188
  writeFileSync(join(root, "measure", "measure.json"), `${JSON.stringify(res, null, 1)}\n`);
181
- console.log(`${GATE}: ${pages.length} page(s) at 375, 390 and 1440, phone first, against ${base}; captures in measure/out, report in measure/measure.json`);
182
- if (failures.length) stop(GATE, "06", `${failures.length} failure(s):\n${failures.map((f) => ` ${f}`).join("\n")}`);
189
+ const ladder = LADDER.map((v) => v.name).join(", ");
190
+ console.log(`${GATE}: ${pages.length} page(s) at ${ladder} and the width sweep, phone first, against ${base}${judged.known ? `; ${judged.known} known breach${judged.known === 1 ? "" : "es"} in ${measure.baseline}` : ""}; captures in measure/out, report in measure/measure.json`);
191
+ if (!updating && failures.length) stop(GATE, "06", `${failures.length} failure(s):\n${failures.map((f) => ` ${f}`).join("\n")}`);
183
192
 
184
193
  /** Serves the last build on measure.port and returns how to stop it. */
185
194
  async function serveBuild() {
@@ -214,16 +223,3 @@ async function serveBuild() {
214
223
  stopServer();
215
224
  stop(GATE, "06", `the build did not answer on ${base} within a minute.`);
216
225
  }
217
-
218
- // Scroll through the page so lazy images load before the capture, then back to the top.
219
- async function settle(p) {
220
- await p.evaluate(async () => {
221
- const h = document.documentElement.scrollHeight;
222
- for (let y = 0; y < h; y += 600) {
223
- window.scrollTo(0, y);
224
- await new Promise((r) => setTimeout(r, 40));
225
- }
226
- window.scrollTo(0, 0);
227
- });
228
- await p.waitForTimeout(600);
229
- }
@@ -3,7 +3,7 @@
3
3
  // first one to fail stops the build and names its stage. The order matters:
4
4
  // the direction is decided before tokens are written from it, the tokens are
5
5
  // written before they are measured, and the deck is current before the null
6
- // set reads it. The measurement at 375, 390 and 1440 (phone first) needs a
6
+ // set reads it. The measurement at every viewport (phone first) needs a
7
7
  // running build, so deploy-preview.mjs runs it before every preview deploy
8
8
  // instead.
9
9