From 4c48cf5dd39481f6338e50bb8daeb895fa64f6a4 Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Mon, 23 Nov 2026 13:32:25 +0100 Subject: [PATCH 1/6] Pin the slice E contracts --- docs/specs/PHASE-32-SPEC.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/specs/PHASE-32-SPEC.md b/docs/specs/PHASE-32-SPEC.md index 51fdfc1..e3dadfe 100644 --- a/docs/specs/PHASE-32-SPEC.md +++ b/docs/specs/PHASE-32-SPEC.md @@ -200,6 +200,17 @@ These fixes were proved red on 2cff888 and green after; no agent re-verified the - `evaluate.ts:2155-2165`: `link` and `text-input` (through `desktopTargets`) and `overlayTargets` in the touch loop; `TAPPABLE_PRIMITIVES` unchanged. - `src/types.ts`: the `text-input` `size` comment (`:354`), `controlSize` on `modal` and `toast`. +**Slice E — contracts pinned before build (2026-11-23; frozen at the commit that adds this block).** Today the phone census (`checkUsability`'s touch branch) measures the four controls and `TAPPABLE_PRIMITIVES` only, and on a mobile canvas `pointerTargets` never runs, so a `link`, a `text-input`, a modal's buttons and a toast's action are measured at no floor at all on a phone. +- **R1: `text-input` `lg`.** `TEXT_INPUT_HEIGHT` gains `lg: 44`; `textInputHeight` reads `sm` → 32, `lg` → 44, anything else → 40. A multi-line input stays `max(base, rows × 20 + 12)`. The renderer draws the field at that height; its font stays 14px (13 at `sm`) and its padding unchanged. `xs` is not a text-input size and renders `md`, as today. Every type, not only mobile. +- **R2: `link` and `text-input` in the phone census.** On a canvas with `mobile-touch-target` on, each `link` and `text-input` is measured at the floor by the box `desktopTargets` returns (the same box the 24px census uses): height always; width only when known (a numeric or px width, or an unlabelled link that hugs its glyphs). A target with a dimension below 44 is one `mobile-touch-target` error, −25, with `nodeId` the node, a message in the existing form (`link has a 14×24px touch target …`) and a suggestion: link — `height: 44` (and `width: 44` with no label), or a `button`; text-input — `size: "lg"` (44px). `TAPPABLE_PRIMITIVES` and `CLICKABLE_PRIMITIVES` do not change, so web and desktop-app keep their 24px census and `pointerTargets` stays off on mobile. +- **R3: disabled targets.** The phone census measures disabled `link`s, `text-input`s, modal actions and toast actions, as it measures disabled buttons and tab-bar items today (it never exempted disabled targets). The 24px census keeps skipping them. +- **R4: the row rule on a phone.** A control's row extends its target only when the row holds no other tappable (`countControls` on the touch path); `link` and `text-input` now count there, as the phone tappables they become. A checkbox in a horizontal row beside a text-input or link is measured at its own box. Overlays never count (they are lifted out of the row). +- **R5: `controlSize`.** `modal` and `toast` take `controlSize: "xs" | "sm" | "md" | "lg"`, the button size names and `BUTTON_HEIGHT` heights (24 / 32 / 44 / 52). Any other value (missing, unknown string, number) is the default: `sm` on a modal, `xs` on a toast. On a modal it sets the size of the close button (an icon-only button, so square: 44×44 at `md`) and every action; on a toast, the action. Header, body and footer padding, gaps, `maxWidth` (240 action, 160 toast action) and the toast's 40px `min-height` do not change; a taller control grows the row it sits in. `modal.size` keeps meaning width. `controlSize` joins `COPY_PROPS`' enums (never resolved as a token). Render never depends on type. +- **R6: byte-identity.** `renderToHtml` of a canvas holding a modal (title, two actions, one primary), a toast with an action, and each with `controlSize` absent, `"sm"`/`"xs"` respectively, or an invalid value, is the same string as on 09ec388, on web, mobile and desktop-app. +- **R7: overlays in the phone census.** `overlayTargets` reads `controlSize`: the modal close button `{ w: h, h }`, each action `{ h }` (width unknown; a labelled button is never narrower than tall), the toast action `{ h }`, `h` = `BUTTON_HEIGHT[controlSize]`. The phone census measures them at the floor, each a `mobile-touch-target` error on the overlay's own node id (one per target: a default modal with two actions is three errors), with the suggestion `controlSize: "md"` (44px) on the modal or toast — or a `sheet` for a bottom panel. The 24px census on web and desktop-app reads the same function; every `controlSize` is 24px or more, so none fails there. +- **R8: docs.** `sheet` stays the recommendation for a bottom panel; a centred `modal` with `controlSize: "md"` is a valid phone dialog; a toast on a phone takes `controlSize: "md"` when it has an action. The touch lists in INSTRUCTIONS (`index.ts:87`, `:118`, `:151`), the `canvas_evaluate` docstring, GUIDELINES' mobile-touch-target entry and overlay notes, the `text-input`, `modal` and `toast` docstrings and README rows, and VISION's two Phase 30 follow-up lines and slice E box. +- **R9: tests.** Unit: `test/unit/test-mobile-primitives.ts` or a new `test/unit/test-phone-targets.ts` (FR-E1 and FR-E3 acceptance on a mobile canvas, each passing case with a failing twin: a default link errors, `height: 44` clears it, a glyph-only link with `height: 44` still errors on width; a `text-input` errors at `md` and `sm`, clears at `lg` and at `rows: 2`; disabled ones still error; a default modal with two actions + a toast with an action = four errors, `controlSize: "md"` on both = none, `"lg"` none, `"sm"` on the toast = one; a checkbox in a 56px row beside a text-input errors, alone it passes; on web and desktop-app none of this raises `mobile-touch-target`). `test/unit/test-overlays.ts` (`overlayTargets` heights per `controlSize`, the invalid value, and R6 byte-identity against strings pinned from 09ec388). `test/unit/test-desktop-primitives.ts` (`lg` = 44 in `desktopTargets` and the rendered field). Browser: `test/browser/test-overlays-render.ts` measures the rendered close button and actions at 44 with `controlSize: "md"` and 32 by default, and a toast action at 44. The mobile gates (`test/browser/test-patterns-mobile.ts`, `test/e2e/test-ridgeline.ts`, `test/e2e/test-mobile-rules*.ts`) stay green unchanged. + **Agent surfaces, per slice (the #77 rule).** B: everything FR-B3 lists, plus GUIDELINES' element-states section. C: the `canvas_evaluate` and `canvas_autofix` docstrings, GUIDELINES' autofix list and fix workflow, `apply_structure`'s seeding note (`index.ts:1569`), the tint-layer notes (`index.ts:595-599`, `:1177`, GUIDELINES `:258`, `:379`), and `test-discoverability.ts` for the new rule id. D: the `tabs` and `tree-row` docstrings, the `canvas_evaluate` docstring (`index.ts:2158`, which says `select` is not measured and tree rows draw no mark) and INSTRUCTIONS (`index.ts:89`), GUIDELINES' rule lists (`:105-106`, `:133-134`) and stress list (`:489`), the `canvas_stress` docstring. E: the `text-input`, `modal` and `toast` docstrings, the touch list (GUIDELINES `:57`), the phone-dialog advice (`index.ts:614`, GUIDELINES `:161`), INSTRUCTIONS and the `canvas_evaluate` docstring where they list touch targets. Each slice's PR runs the `docs-steward`. --- From 9b1d956a76fc40f700dfc7e0932628dd225e43a3 Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Mon, 23 Nov 2026 13:37:35 +0100 Subject: [PATCH 2/6] Re-freeze the slice E contracts after the pre-freeze verifier --- docs/specs/PHASE-32-SPEC.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/specs/PHASE-32-SPEC.md b/docs/specs/PHASE-32-SPEC.md index e3dadfe..28af541 100644 --- a/docs/specs/PHASE-32-SPEC.md +++ b/docs/specs/PHASE-32-SPEC.md @@ -200,16 +200,16 @@ These fixes were proved red on 2cff888 and green after; no agent re-verified the - `evaluate.ts:2155-2165`: `link` and `text-input` (through `desktopTargets`) and `overlayTargets` in the touch loop; `TAPPABLE_PRIMITIVES` unchanged. - `src/types.ts`: the `text-input` `size` comment (`:354`), `controlSize` on `modal` and `toast`. -**Slice E — contracts pinned before build (2026-11-23; frozen at the commit that adds this block).** Today the phone census (`checkUsability`'s touch branch) measures the four controls and `TAPPABLE_PRIMITIVES` only, and on a mobile canvas `pointerTargets` never runs, so a `link`, a `text-input`, a modal's buttons and a toast's action are measured at no floor at all on a phone. +**Slice E — contracts pinned before build (2026-11-23; frozen at the commit that adds this block).** Drafted at 4c48cf5, then broken on paper by one pre-freeze verifier (7 findings, 7 confirmed); this is the re-frozen version. Departures from the draft are marked *(changed)*. Code is cited by function name: the line numbers in the slice E plan above predate slice A's move (`actionButton`, `renderModal`, `renderToast` in `renderer.ts`; `checkUsability`'s touch branch in `evaluate.ts`; `overlayTargets`, `textInputHeight`, `TEXT_INPUT_HEIGHT` in `primitives.ts`; the phone-dialog advice under the overlay list in `index.ts`). Today the phone census (`checkUsability`'s touch branch) measures the four controls and `TAPPABLE_PRIMITIVES` only, and on a mobile canvas `pointerTargets` never runs, so a `link`, a `text-input`, a modal's buttons and a toast's action are measured at no floor at all on a phone. - **R1: `text-input` `lg`.** `TEXT_INPUT_HEIGHT` gains `lg: 44`; `textInputHeight` reads `sm` → 32, `lg` → 44, anything else → 40. A multi-line input stays `max(base, rows × 20 + 12)`. The renderer draws the field at that height; its font stays 14px (13 at `sm`) and its padding unchanged. `xs` is not a text-input size and renders `md`, as today. Every type, not only mobile. -- **R2: `link` and `text-input` in the phone census.** On a canvas with `mobile-touch-target` on, each `link` and `text-input` is measured at the floor by the box `desktopTargets` returns (the same box the 24px census uses): height always; width only when known (a numeric or px width, or an unlabelled link that hugs its glyphs). A target with a dimension below 44 is one `mobile-touch-target` error, −25, with `nodeId` the node, a message in the existing form (`link has a 14×24px touch target …`) and a suggestion: link — `height: 44` (and `width: 44` with no label), or a `button`; text-input — `size: "lg"` (44px). `TAPPABLE_PRIMITIVES` and `CLICKABLE_PRIMITIVES` do not change, so web and desktop-app keep their 24px census and `pointerTargets` stays off on mobile. -- **R3: disabled targets.** The phone census measures disabled `link`s, `text-input`s, modal actions and toast actions, as it measures disabled buttons and tab-bar items today (it never exempted disabled targets). The 24px census keeps skipping them. -- **R4: the row rule on a phone.** A control's row extends its target only when the row holds no other tappable (`countControls` on the touch path); `link` and `text-input` now count there, as the phone tappables they become. A checkbox in a horizontal row beside a text-input or link is measured at its own box. Overlays never count (they are lifted out of the row). -- **R5: `controlSize`.** `modal` and `toast` take `controlSize: "xs" | "sm" | "md" | "lg"`, the button size names and `BUTTON_HEIGHT` heights (24 / 32 / 44 / 52). Any other value (missing, unknown string, number) is the default: `sm` on a modal, `xs` on a toast. On a modal it sets the size of the close button (an icon-only button, so square: 44×44 at `md`) and every action; on a toast, the action. Header, body and footer padding, gaps, `maxWidth` (240 action, 160 toast action) and the toast's 40px `min-height` do not change; a taller control grows the row it sits in. `modal.size` keeps meaning width. `controlSize` joins `COPY_PROPS`' enums (never resolved as a token). Render never depends on type. +- **R2: `link` and `text-input` in the phone census.** On a canvas with `mobile-touch-target` on, each `link` and `text-input` is measured at the floor by the box `desktopTargets` returns (the same box the 24px census uses): height always; width only when known (a numeric or px width, or an unlabelled link that hugs its glyphs). A target with a dimension below 44 is one `mobile-touch-target` error, −25, with `nodeId` the node, a message in the existing form (`link has a 14×24px touch target …`) and a suggestion naming the failing dimension *(changed)*: height — a link takes `height: 44` (or becomes a `button`), a text-input `size: "lg"` (44px); width — widen it to 44 or drop the width. A text-input's width is judged only when numeric (a `"200px"` string is not read, as in the 24px census); a link's when numeric, a px string, or an unlabelled link hugging its glyphs (a link with no label and no glyph measures 0 wide and errors, as it warns in the 24px census). `TAPPABLE_PRIMITIVES` and `CLICKABLE_PRIMITIVES` do not change, so web and desktop-app keep their 24px census and `pointerTargets` stays off on mobile. +- **R3: disabled targets.** The phone census measures disabled `link`s, `text-input`s, modal actions and toast actions, as it measures disabled buttons and tab-bar items today (it never exempted disabled targets). The 24px census keeps skipping them. WCAG 2.5.8 exempts inactive targets; the phone floor is a HIG floor, and the docs say disabled targets count there *(changed)*. +- **R4: the row rule on a phone.** A control's row extends its target only when the row holds no other tappable (`countControls` on the touch path); `link` and `text-input` now count there, as the phone tappables they become. A checkbox in a horizontal row beside a text-input or link is measured at its own box. *(changed)* An overlay's own targets (its close button and actions, a toast's action) never count toward a row; `countControls` still recurses into an overlay's children, as today (a modal placed inside a row is lifted out at render, but its body's controls count for that row; pre-existing, unchanged). +- **R5: `controlSize`.** `modal` and `toast` take `controlSize: "xs" | "sm" | "md" | "lg"`, the button size names and `BUTTON_HEIGHT` heights (24 / 32 / 44 / 52). Any other value (missing, an unknown string including inherited keys such as `constructor` or `toString`, a number, an object) is the default, read with an own-key test, never `BUTTON_HEIGHT[v] ?? default` *(changed)*: `sm` on a modal, `xs` on a toast. On a modal it sets the size of the close button (an icon-only button, so square: 44×44 at `md`) and every action; on a toast, the action. The buttons' own label size and side padding follow their size, as on `button` (`BUTTON_FONT`, `BUTTON_PADDING`: 14 and 12 at `sm`, 16 and 16 at `md`) *(changed)*. Header, body and footer padding, gaps, `maxWidth` (240 action, 160 toast action) and the toast's 40px `min-height` do not change; a taller control grows the row it sits in. `modal.size` keeps meaning width. `controlSize` joins `COPY_PROPS`' enums (never resolved as a token). Render never depends on type. - **R6: byte-identity.** `renderToHtml` of a canvas holding a modal (title, two actions, one primary), a toast with an action, and each with `controlSize` absent, `"sm"`/`"xs"` respectively, or an invalid value, is the same string as on 09ec388, on web, mobile and desktop-app. - **R7: overlays in the phone census.** `overlayTargets` reads `controlSize`: the modal close button `{ w: h, h }`, each action `{ h }` (width unknown; a labelled button is never narrower than tall), the toast action `{ h }`, `h` = `BUTTON_HEIGHT[controlSize]`. The phone census measures them at the floor, each a `mobile-touch-target` error on the overlay's own node id (one per target: a default modal with two actions is three errors), with the suggestion `controlSize: "md"` (44px) on the modal or toast — or a `sheet` for a bottom panel. The 24px census on web and desktop-app reads the same function; every `controlSize` is 24px or more, so none fails there. -- **R8: docs.** `sheet` stays the recommendation for a bottom panel; a centred `modal` with `controlSize: "md"` is a valid phone dialog; a toast on a phone takes `controlSize: "md"` when it has an action. The touch lists in INSTRUCTIONS (`index.ts:87`, `:118`, `:151`), the `canvas_evaluate` docstring, GUIDELINES' mobile-touch-target entry and overlay notes, the `text-input`, `modal` and `toast` docstrings and README rows, and VISION's two Phase 30 follow-up lines and slice E box. -- **R9: tests.** Unit: `test/unit/test-mobile-primitives.ts` or a new `test/unit/test-phone-targets.ts` (FR-E1 and FR-E3 acceptance on a mobile canvas, each passing case with a failing twin: a default link errors, `height: 44` clears it, a glyph-only link with `height: 44` still errors on width; a `text-input` errors at `md` and `sm`, clears at `lg` and at `rows: 2`; disabled ones still error; a default modal with two actions + a toast with an action = four errors, `controlSize: "md"` on both = none, `"lg"` none, `"sm"` on the toast = one; a checkbox in a 56px row beside a text-input errors, alone it passes; on web and desktop-app none of this raises `mobile-touch-target`). `test/unit/test-overlays.ts` (`overlayTargets` heights per `controlSize`, the invalid value, and R6 byte-identity against strings pinned from 09ec388). `test/unit/test-desktop-primitives.ts` (`lg` = 44 in `desktopTargets` and the rendered field). Browser: `test/browser/test-overlays-render.ts` measures the rendered close button and actions at 44 with `controlSize: "md"` and 32 by default, and a toast action at 44. The mobile gates (`test/browser/test-patterns-mobile.ts`, `test/e2e/test-ridgeline.ts`, `test/e2e/test-mobile-rules*.ts`) stay green unchanged. +- **R8: docs.** `sheet` stays the recommendation for a bottom panel; a centred `modal` with `controlSize: "md"` is a valid phone dialog; a toast on a phone takes `controlSize: "md"` when it has an action; a link inside a sentence is a `text` node's `links` range (exempt), a `link` node is a standalone link and is measured *(changed)*. The touch lists in INSTRUCTIONS (`index.ts:87`, `:118`, `:151`), the `canvas_evaluate` docstring, GUIDELINES' mobile-touch-target entry and overlay notes, the `text-input`, `modal` and `toast` docstrings and README rows, README's `mobile-touch-target` rule row and `usability` category row, GUIDELINES' usability line, and VISION's two Phase 30 follow-up lines and slice E box. +- **R9: tests.** Unit: `test/unit/test-mobile-primitives.ts` or a new `test/unit/test-phone-targets.ts` (FR-E1 and FR-E3 acceptance on a mobile canvas, each passing case with a failing twin: a default link errors, `height: 44` clears it, a glyph-only link with `height: 44` still errors on width; a `text-input` errors at `md` and `sm`, clears at `lg` and at `rows: 2`; disabled ones still error; a default modal with two actions + a toast with an action = four errors, `controlSize: "md"` on both = none, `"lg"` none, `"sm"` on the toast = one, `"constructor"` and `44` = the defaults' four; a checkbox in a 56px row beside a text-input errors, alone it passes; on web and desktop-app none of this raises `mobile-touch-target`). `test/unit/test-overlays.ts` (`overlayTargets` heights per `controlSize`, the invalid value, and R6 byte-identity against strings pinned from 09ec388). `test/unit/test-desktop-primitives.ts` (`lg` = 44 in `desktopTargets` and the rendered field; the check "mobile: desktop primitives are not phone tappables" flips for `link` and `text-input`). Browser: `test/browser/test-overlays-render.ts` measures the rendered close button and actions at 44 with `controlSize: "md"` and 32 by default, and a toast action at 44. The mobile gates (`test/browser/test-patterns-mobile.ts`, `test/e2e/test-ridgeline.ts`, `test/e2e/test-mobile-rules*.ts`) stay green unchanged. **Agent surfaces, per slice (the #77 rule).** B: everything FR-B3 lists, plus GUIDELINES' element-states section. C: the `canvas_evaluate` and `canvas_autofix` docstrings, GUIDELINES' autofix list and fix workflow, `apply_structure`'s seeding note (`index.ts:1569`), the tint-layer notes (`index.ts:595-599`, `:1177`, GUIDELINES `:258`, `:379`), and `test-discoverability.ts` for the new rule id. D: the `tabs` and `tree-row` docstrings, the `canvas_evaluate` docstring (`index.ts:2158`, which says `select` is not measured and tree rows draw no mark) and INSTRUCTIONS (`index.ts:89`), GUIDELINES' rule lists (`:105-106`, `:133-134`) and stress list (`:489`), the `canvas_stress` docstring. E: the `text-input`, `modal` and `toast` docstrings, the touch list (GUIDELINES `:57`), the phone-dialog advice (`index.ts:614`, GUIDELINES `:161`), INSTRUCTIONS and the `canvas_evaluate` docstring where they list touch targets. Each slice's PR runs the `docs-steward`. From f32a8c0c4a60bd8e0598acce874670a99f61a295 Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Mon, 23 Nov 2026 13:43:16 +0100 Subject: [PATCH 3/6] Measure links, text inputs and overlay controls at 44px on a phone A phone canvas never measured a link, a text-input, a modal's buttons or a toast's action, so a 32px field passed silently. text-input gains size lg (44) and modal and toast gain controlSize (the button size names); the mobile-touch-target census measures all four. --- README.md | 12 +-- VISION.md | 6 +- docs/GUIDELINES.md | 15 +-- src/evaluate.ts | 44 +++++++- src/index.ts | 18 ++-- src/primitives.ts | 29 ++++-- src/renderer.ts | 8 +- src/types.ts | 8 +- test/browser/test-overlays-render.ts | 27 +++++ test/unit/test-desktop-primitives.ts | 13 ++- test/unit/test-overlays.ts | 35 +++++++ test/unit/test-phone-targets.ts | 149 +++++++++++++++++++++++++++ 12 files changed, 317 insertions(+), 47 deletions(-) create mode 100644 test/unit/test-phone-targets.ts diff --git a/README.md b/README.md index 2bbea0b..70b127d 100644 --- a/README.md +++ b/README.md @@ -386,8 +386,8 @@ Application screens (`type: "desktop-app"`) are built from eight primitives on t | Type | Key props | What it is | |---|---|---| -| `link` | `label`, `icon`, `iconPosition`, `external`, `ariaLabel`, `state` | A standalone text action, at least 24 tall. With no `label` it hugs its glyphs (14px wide, 30 with `external`) and needs an `ariaLabel` (rendered as `aria-label` and `title`). A `text` node can hold inline links instead: `links: [{ start, end }]` character ranges of its content, drawn underlined and exempt from the 24px floor | -| `text-input` | `value`, `placeholder`, `icon`, `size` (`sm` 32 / `md` 40), `rows`, `error` (a message), `disabled`, `state` | A field whose border (`$border-strong` when the design system has it) is its only boundary; `error` draws an icon and the message below and turns the border `$danger` | +| `link` | `label`, `icon`, `iconPosition`, `external`, `ariaLabel`, `state` | A standalone text action, at least 24 tall (on a phone the census wants 44: `height: 44`). With no `label` it hugs its glyphs (14px wide, 30 with `external`) and needs an `ariaLabel` (rendered as `aria-label` and `title`). A `text` node can hold inline links instead: `links: [{ start, end }]` character ranges of its content, drawn underlined and exempt from the 24px floor | +| `text-input` | `value`, `placeholder`, `icon`, `size` (`sm` 32 / `md` 40 / `lg` 44, the phone size), `rows`, `error` (a message), `disabled`, `state` | A field whose border (`$border-strong` when the design system has it) is its only boundary; `error` draws an icon and the message below and turns the border `$danger` | | `nav-item` | `label`, `icon`, `count`, `dotColor`, `active`, `depth` (0 / 1), `collapsed`, `state` | A 32px sidebar row. `active` draws an `$accent-tint` fill, a 2px `$accent` bar and a heavier label; `collapsed` is the 32×32 rail form, with the label as its accessible name; `dotColor` is an identity dot, never counted as an accent | | `tabs` | `items: [{ label, count?, active?, disabled?, state? }]`, `variant` (`line` / `contained`), `size` (`sm` 32 / `md` 40) | One tablist; each tab is its own target. The active tab gets an indicator (`line`) or an `$accent-tint` fill (`contained`); only the line underline is measured by `desktop-app-state-contrast` | | `tree-row` | `label`, `depth`, `expanded` (absent for a leaf), `icon`, `active`, `state` | A 32px row indented 16px per level, with a chevron when `expanded` is set; `active` draws an `$accent-tint` fill, a 2px bar in `iconColor` (`$accent` by default) at the row's left edge at every depth, and a heavier label | @@ -408,8 +408,8 @@ Six overlays draw screen states: an open menu, a comment popover, a confirm dial | `tooltip` | `text`, `x`, `y` | A short hint, inverted, wrapping at 240px; never renders children | | `popover` | `x`, `y`, `size` (`xs` 192 / `sm` 320 / `md` 480 / `lg` 640), children | A panel (vertical, 12px padding by default) for a comment box or a filter form | | `menu` | `x`, `y`, children (`menu-row`s, `divider`s) | A menu at least 192 wide, hugging its rows | -| `modal` | `title`, `size` (`sm` 480 / `md` 640 / `lg` 960), `actions: [{ label, variant?, state? }]`, `closeLabel`, children | Centred over its own full scrim, with a close button named "Close"; actions right-aligned, the filled one (`primary` or `destructive`) rightmost, an action with no variant `secondary` | -| `toast` | `text`, `tone` (`neutral` / `success` / `warning` / `danger`), `action: { label, state? }` | Bottom-centre, 24px above the artboard's edge; the tone colours a leading glyph | +| `modal` | `title`, `size` (`sm` 480 / `md` 640 / `lg` 960), `actions: [{ label, variant?, state? }]`, `closeLabel`, `controlSize` (`xs` / `sm` / `md` / `lg`: 24 / 32 / 44 / 52, default `sm`), children | Centred over its own full scrim, with a close button named "Close"; `controlSize` sizes the close button and actions (`md` meets the 44px phone floor); actions right-aligned, the filled one (`primary` or `destructive`) rightmost, an action with no variant `secondary` | +| `toast` | `text`, `tone` (`neutral` / `success` / `warning` / `danger`), `action: { label, state? }`, `controlSize` (the action's button size, default `xs` 24) | Bottom-centre, 24px above the artboard's edge; the tone colours a leading glyph; `controlSize: "md"` gives the action the 44px phone size | | `drawer` | `size` (`sm` 320 / `md` 480), `scrim`, children | A panel pinned to the right edge at full height | ``` @@ -915,7 +915,7 @@ Every result also carries a **`surface`** field: `{ type, device, source, rulesO | Rule | Category | Severity | Fires on | |---|---|---|---| -| `mobile-touch-target` | usability | error | A tap target below 44px: a control (its target extends to its row only when the row is a horizontal frame holding that one tappable), a `button` (`size: "sm"` is 32, `"xs"` 24), a `list-row`, each `tab-bar` tab and FAB, or each `nav-bar` action. Primitives are measured by their own box; nodes inside an instance are judged as rendered and reported on the instance. | +| `mobile-touch-target` | usability | error | A tap target below 44px: a control (its target extends to its row only when the row is a horizontal frame holding that one tappable), a `button` (`size: "sm"` is 32, `"xs"` 24), a `list-row`, each `tab-bar` tab and FAB, each `nav-bar` action, a `link` (`height: 44`), a `text-input` (`size: "lg"`), or a `modal`'s close button and actions or a `toast`'s action (`controlSize: "md"`). Primitives are measured by their own box, disabled ones too; nodes inside an instance are judged as rendered and reported on the instance. | | `mobile-tab-bar` | usability | warning | A `tab-bar` with fewer than 2 or more than 5 tabs (the FAB is not a tab), a tab with no label, or a bar not pinned to the bottom (a `position` override or any `y`). | | `mobile-handbuilt-target` | usability | info | A frame shaped like a tap target (one icon, or an icon plus a label of up to three words) whose box is below 44px; rebuild it as a `button` if it is tappable. | | `mobile-safe-area` | usability | warning | Content under the 47px status-bar or 34px home-indicator inset, or left under a pinned bar. With the root's `safeArea` or pinned chrome the renderer reserves the insets, so fast mode checks positioned content (`absolute`, `fixed`, `sticky` at its stuck `y`) and pinned bars: the scroll's end (or start) must clear a bar you pinned, and the finding names the spacer height to add to your content frame. Without `safeArea`, the first and last content must clear the insets. Padding of 32px or more scales down on a phone, so clear an inset with a spacer frame. A `sheet`'s content is never judged. Detailed mode checks rendered positions and is authoritative. | @@ -963,7 +963,7 @@ Whenever the `coverage` category runs on a **base** canvas, the result also carr | `consistency` | 20 | Frames missing `layout`, sibling overlap (detailed mode; positioned siblings that content scrolls under — absolute, sticky, pinned chrome, a sheet, a bar pinned to the bottom — are exempt, while a bar pinned to the top still counts) — plus score-neutral advisories: **token detachment** (a literal `fill`/`stroke`/`color`/`cornerRadius` that exactly equals a token's value flags with a mechanical `$ref` autofix; ambiguous matches list candidates and never guess) and **ad-hoc motion** (3+ distinct duration/easing combos with no motion tokens declared) | | `cliche` | 15 | Machine-made tells: default purple/indigo accent, gradient/glow overuse, fake browser/OS chrome (traffic-light dots), the hanging eyebrow-beside-heading header, fabricated metrics/testimonials/logos, eyebrow rhythm (an eyebrow above nearly every section), slop copy (stock AI phrasing — filler verbs, scroll cues, placeholder names, hype labels), radius consistency (too many distinct corner radii), pure black/white (`#000000` ink / `#ffffff` page vs off-black/off-white), accent consistency (multiple competing accent hues — the `$success`/`$warning`/`$danger` status vocabulary is exempt when referenced as tokens, since those are semantics rather than a second accent; the same hues as literals still count). Each issue carries a `tell` discriminator. Tells are warning or info severity, but **every tell blocks the directive**, whatever its severity (see the `directive` above). Relaxable per `genre`. The tells know dashboard vocabulary: a violet reached only through a `$chart-*` or `$*-tint` token doesn't count as the default-purple tell (a literal violet, or one through any other token, still does), a gradient reached through a `$token` doesn't count toward gradient overuse, thin rounded sparkline bars aren't mistaken for traffic-light dots (fake-chrome now requires a near-square shape), and an uppercase label sitting beside a large tabular figure reads as a KPI-card metric, not an eyebrow. It also knows retail copy: a numeral bound to a unit noun by a tight hyphen (`"30-day returns"`, `"2-year warranty"`, `"24/7 support"`) is a compound modifier, not a numbered section eyebrow. | | `coverage` | 10 | State coverage on **base** canvases with data-bearing content: a detected table demands designed `empty` + `loading` variants, a form (3+ input controls, `text-input` included) demands `error` — each missing state is a directive-blocking warning whose suggestion names the `canvas_add_variant` + scaffold path. Variant canvases and non-data screens get no findings. Table detection needs three matching horizontal rows to read as data (two stacked rows are treated as a layout, e.g. a topbar over a greeting); an import-named `Table` frame keeps the looser two-row shape. A list whose every row leads with an icon, a dot or a small image (a sidebar of projects) is navigation and never reads as a table, on every type. On a **`loading`** variant itself, a warning fires per data surface (a detected table, or a frame with 2+ large tabular/numeric texts) that still shows live values while a sibling region is skeletoned — "Loading state is half-designed" — naming the region and suggesting the matching skeleton scaffold. The result's `coverage` field reports `{ dataBearing, states, missing }`. | -| `usability` | 20 | The mechanical UX floors beyond contrast. On web and desktop-app canvases every pointer target (the four controls and the clickable primitives: `button`, `list-row`, `tab-bar` tabs, `nav-bar` actions, `link`, `text-input`, `nav-item`, each tab of a `tabs`, `tree-row`, `menu-row`; see [Desktop-app primitives](#desktop-app-primitives)) meets the **24px floor** (WCAG 2.5.8) or its **spacing exception**, a smaller target with nothing else inside a 24px circle around it: detailed mode runs that test and makes a failure an **error**, fast mode **warns** on any target below 24 and names detailed mode — the effective target counts a lone control's padded row, so a well-padded settings row passes while two small controls sharing a row are measured bare; phone-width web artboards additionally get a 44px touch-first info, and a canvas declared `mobile` makes 44px an error instead (`mobile-touch-target`, see the mobile ruleset above). A control with **no text label** in its row or group is a warning (selects carry their own value text). **Vague action copy** — "Click here", "Learn more", "Read more", or "Submit" as the exact label — is an info: name the action. Controls also render with accent-derived `:focus-visible` rings in the live viewer; screenshots stay byte-identical (nothing is focused in a static capture). | +| `usability` | 20 | The mechanical UX floors beyond contrast. On web and desktop-app canvases every pointer target (the four controls and the clickable primitives: `button`, `list-row`, `tab-bar` tabs, `nav-bar` actions, `link`, `text-input`, `nav-item`, each tab of a `tabs`, `tree-row`, `menu-row`; see [Desktop-app primitives](#desktop-app-primitives)) meets the **24px floor** (WCAG 2.5.8) or its **spacing exception**, a smaller target with nothing else inside a 24px circle around it: detailed mode runs that test and makes a failure an **error**, fast mode **warns** on any target below 24 and names detailed mode — the effective target counts a lone control's padded row, so a well-padded settings row passes while two small controls sharing a row are measured bare; phone-width web artboards additionally get a 44px touch-first info, and a canvas declared `mobile` makes 44px an error instead (`mobile-touch-target`, see the mobile ruleset above), which also measures `link`, `text-input` and the overlay controls. A control with **no text label** in its row or group is a warning (selects carry their own value text). **Vague action copy** — "Click here", "Learn more", "Read more", or "Submit" as the exact label — is an info: name the action. Controls also render with accent-derived `:focus-visible` rings in the live viewer; screenshots stay byte-identical (nothing is focused in a static capture). | The weights are relative, not points out of 100. Each category scores 0–100, and `overallScore` is their weighted mean: the sum of score × weight over the categories that ran, divided by the sum of their weights. diff --git a/VISION.md b/VISION.md index ea3b116..b3b5809 100644 --- a/VISION.md +++ b/VISION.md @@ -555,8 +555,8 @@ The mobile attempt (2026-09-07) built one iOS screen end to end on v2.2.0 and go All seven slices are merged and the acceptance re-run passed. The phase is closed. -- [ ] Follow-up — `link` and `text-input` join the mobile 44px touch census. Phase 31 slice B added both primitives for app screens; on a phone canvas they are not measured today, so a 32px text-input passes silently. -- [ ] Follow-up — overlay controls on a phone. Phase 31 slice E's `modal` close button and actions (32px) and `toast` action (24px) are drawn at fixed pointer sizes and are not in the mobile 44px touch census, so a modal on a phone canvas passes silently; meeting 44px needs a size option on the overlay (render never depends on type), and the census then measures it. Until then the docs send phone dialogs to `sheet`. +- [x] Follow-up — `link` and `text-input` join the mobile 44px touch census. Phase 31 slice B added both primitives for app screens; on a phone canvas they are not measured today, so a 32px text-input passes silently (done in Phase 32 slice E: both are measured, and `text-input` gained `size: "lg"`, 44) +- [ ] Follow-up — overlay controls on a phone. Phase 31 slice E's `modal` close button and actions (32px) and `toast` action (24px) are drawn at fixed pointer sizes and are not in the mobile 44px touch census, so a modal on a phone canvas passes silently; meeting 44px needs a size option on the overlay (render never depends on type), and the census then measures it. Until then the docs send phone dialogs to `sheet` (done in Phase 32 slice E: `controlSize` on `modal` and `toast`, measured at 44 on a phone) _Full spec-driven breakdown in [`docs/specs/PHASE-30-SPEC.md`](docs/specs/PHASE-30-SPEC.md). Deliberately out of scope: an Android profile, tablet and other types, a tappable flag on frames, a thumb-reach rule, interaction and flows, mobile import, and mobile commerce archetypes (those come next, on the anatomy/realisation split this phase creates)._ @@ -591,7 +591,7 @@ Phases 30 and 31 closed with seven follow-ups open, and five of them are quiet f - [x] Slice B — one tree: instances expanded and resolved once, so the renderer and every rule (contrast, spacing and cliché included) see the same thing inside a component, and findings there name the instance - [x] Slice C — tokens: an `unknown-token` warning for any `$ref` the merged tokens do not define or that is the wrong kind, with a rename autofix when only one name is close; copy props never resolve; tints and `danger` derive from the applied palette, on new stamps and on canvases holding the old seeds - [x] Slice D — desktop-app checks: `select` gets a `$border-strong` boundary and joins the boundary check, an active `tree-row` draws a bar the indicator check measures, and stress widens `nav-item` and `tabs` counts -- [ ] Slice E — phone targets: `link` and `text-input` (with a new 44px `size: "lg"`) join the 44px census, and `modal` and `toast` take a `controlSize` the census measures +- [x] Slice E — phone targets: `link` and `text-input` (with a new 44px `size: "lg"`) join the 44px census, and `modal` and `toast` take a `controlSize` the census measures _Full spec-driven breakdown in [`docs/specs/PHASE-32-SPEC.md`](docs/specs/PHASE-32-SPEC.md). Deliberately out of scope: a test framework, splitting `src/index.ts` and `src/evaluate.ts`, rewriting "Phase N" comments in `src/`, cross-instance autofix, and an indicator bar on contained tabs._ diff --git a/docs/GUIDELINES.md b/docs/GUIDELINES.md index 797037c..d75a6b8 100644 --- a/docs/GUIDELINES.md +++ b/docs/GUIDELINES.md @@ -54,8 +54,9 @@ A canvas declares what medium it is on, separately from its genre (what it is fo On a `mobile` canvas these rules run. Each finding names its rule in a `rule` field, and the `surface` report lists the rules in `rulesOn`. Errors and warnings from these rules block the directive like any other finding, on every type; infos never do. Fast mode (`canvas_evaluate` with the default `mode: "fast"`) is what you run in the loop; before presenting a phone screen, also run `canvas_evaluate({ canvasId, mode: "detailed" })`, which checks rendered positions. - **`mobile-touch-target`** (usability, **error**, −25 per target). A tap target below 44px in either dimension. - - A control (toggle, checkbox, radio, select): the target extends to the control's row only when that row is a horizontal frame holding this one tappable (no other control or tappable primitive). A toggle in a 56px settings row passes; a lone checkbox inside a padded card is measured at its own size. To fix one, grow the control or put it alone in a horizontal row at least 44px tall. - - The tappable primitives, each by its own box (an ancestor's padding never counts): a `button` (24 / 32 / 44 / 52 by `size`, or a larger `height` / `minHeight`; never narrower than tall), so `size: "xs"` and `"sm"` are errors on a phone by design; a `list-row` (44, or 56 with a subtitle; a trailing toggle or chevron is part of the row, so the row is the target); each `tab-bar` tab (bar width ÷ slots × 49, where the bar width is its `width` or the artboard's, less 32 for `floating`, and the slots are the tabs plus one for a FAB) and the FAB (56); each `nav-bar` action (44×44). The defaults all pass. + - A control (toggle, checkbox, radio, select): the target extends to the control's row only when that row is a horizontal frame holding this one tappable (no other control or tappable primitive; a `link` or `text-input` beside it counts as one). A toggle in a 56px settings row passes; a lone checkbox inside a padded card is measured at its own size. To fix one, grow the control or put it alone in a horizontal row at least 44px tall. + - The tappable primitives, each by its own box (an ancestor's padding never counts): a `button` (24 / 32 / 44 / 52 by `size`, or a larger `height` / `minHeight`; never narrower than tall), so `size: "xs"` and `"sm"` are errors on a phone by design; a `link` (at least 24 tall, its `height` when larger; width judged when it is a number, a px string, or a label-less link hugging its glyphs: give it `height: 44`, or use a `button`); a `text-input` (40 by default, so `size: "lg"`, 44, is the phone size; `sm` is 32; a multi-line one grows by its `rows`); a `modal`'s close button and each action, and a `toast`'s action (32, 32 and 24 by default: give the overlay `controlSize: "md"`, 44); a `list-row` (44, or 56 with a subtitle; a trailing toggle or chevron is part of the row, so the row is the target); each `tab-bar` tab (bar width ÷ slots × 49, where the bar width is its `width` or the artboard's, less 32 for `floating`, and the slots are the tabs plus one for a FAB) and the FAB (56); each `nav-bar` action (44×44). The defaults of `button`, `list-row`, `tab-bar` and `nav-bar` pass; a default `link`, `text-input`, `modal` or `toast` action does not. A link inside a sentence stays a `text` node's `links` range, which is exempt; a `link` node is a standalone link and is measured. + - A disabled target still counts on a phone (the 44px floor is a touch-comfort floor, not WCAG's 24px rule, which exempts inactive targets). - Nodes inside a component instance are judged as they render, and the finding names the instance. - On web and desktop-app canvases the 24px floor applies instead, with WCAG's spacing exception (see [the 24px floor](#the-24px-floor-web-and-desktop-app)). - **`mobile-handbuilt-target`** (usability, info). A frame shaped like a tap target (one icon, or one icon and a label of three words or fewer) whose box is below 44px. It never blocks, because a frame can't say it is decorative. If it is tappable, rebuild it as a `button` (or a `list-row` / `tab-bar` item when that is what it is). @@ -120,7 +121,7 @@ On web and desktop-app canvases every pointer target is measured against WCAG 2. - **Detailed mode** (`canvas_evaluate({ canvasId, mode: "detailed" })`) runs the circle test and is the authority: a failure is an **error** that names the neighbour it reaches. It lays the canvas out in the design system's own fonts, as `screenshot` and `canvas_stress` render it, so its boxes are the ones on screen (a face that cannot load falls back, and the result carries a `Font warnings` item). - **Fast mode** cannot see spacing, so a target below 24px is a **warning** that names the exception and detailed mode. It blocks presenting until you grow the target or a detailed run clears it. -Mobile keeps its own 44px rule (`mobile-touch-target`), which has no spacing exception. +Mobile keeps its own 44px rule (`mobile-touch-target`), which has no spacing exception and also measures a `link`, a `text-input`, and a modal's and toast's controls. ### Desktop-app vocabulary @@ -128,7 +129,7 @@ Build application screens from these primitives, never from hand-built frames: a - **`button` at `size: "xs"`** is the 24px icon button of a dense toolbar. An icon-only button (no `label`) takes `ariaLabel` as its accessible name: it renders `aria-label` and `title` and is never drawn. `xs`, like `sm`, is an error on a phone. - **`link`** `{ label, icon?, iconPosition?, external?, ariaLabel?, state? }` is a standalone text action, at least 24 tall, and a measured target. Without a `label` it hugs its glyphs (14px wide, 30 with `external`) and takes `ariaLabel` as its name (rendered as `aria-label` and `title`). For a link inside a sentence, keep it in the `text` node: `links: [{ start, end }]` marks character ranges of its `content`, drawn underlined. Inline links are exempt from the 24px floor, as WCAG exempts them. A `text` node also takes `title`, rendered as a tooltip. -- **`text-input`** `{ value?, placeholder?, icon?, size?: "sm" | "md", rows?, error?, disabled?, state? }` is a field (32 or 40 tall; `rows` makes it multi-line). Its border is its only boundary, so it uses `$border-strong` when the design system has one. `error` turns the border `$danger` and draws an icon and the message below the field, so the error is never colour alone. +- **`text-input`** `{ value?, placeholder?, icon?, size?: "sm" | "md" | "lg", rows?, error?, disabled?, state? }` is a field (32, 40 or 44 tall; `rows` makes it multi-line). `lg` is the phone size: on a `mobile` canvas a field below 44 is a `mobile-touch-target` error. Its border is its only boundary, so it uses `$border-strong` when the design system has one. `error` turns the border `$danger` and draws an icon and the message below the field, so the error is never colour alone. - **`nav-item`** `{ label, icon?, count?, dotColor?, active?, depth?: 0 | 1, collapsed?, state? }` is a 32px sidebar row that spans its sidebar. `active` draws three cues: an `$accent-tint` fill, a 2px `$accent` bar, and a heavier label (and `aria-current`). `collapsed` is the 32×32 rail form, with its label as the accessible name. `dotColor` is an identity dot for a project or label: it is never counted as a competing accent, though the same colour used anywhere else still is. - **`tabs`** `{ items: [{ label, count?, active?, disabled?, state? }], variant?: "line" | "contained", size?: "sm" | "md" }` is one tablist (32 or 40 tall). Each tab is its own target. The active tab gets an underline indicator (`line`) or an `$accent-tint` fill (`contained`, from the node's `fill`) and a heavier label. Only the line underline is measured by `desktop-app-state-contrast`; a contained tab's fill and weight are not. - **`tree-row`** `{ label, depth, expanded?, icon?, active?, state? }` is a 32px row indented 16px per level. `expanded: true` / `false` draws an open / closed chevron; a leaf leaves it out and keeps the slot, so labels align. `active` draws a `nav-item`'s cues: an `$accent-tint` fill, a 2px bar in `iconColor` (`$accent` by default) at the row's left edge (the same x at every depth, outside the indent), and a heavier label. @@ -154,11 +155,11 @@ The six overlays take their colours from `$bg-surface`, `$border`, `$text-primar - **`tooltip`** `{ text, x, y }` is a short hint, inverted (`$text-primary` fill, `$bg-surface` text, so light on a dark theme), wrapping at 240px. Text only: it never renders children. - **`popover`** `{ x, y, size?: "xs" | "sm" | "md" | "lg", children }` is a panel 192 / 320 / 480 / 640 wide (320 by default; a numeric `width` wins), vertical with 12px padding by default; `layout`, `gap` and `padding` apply as on a frame. A comment box or a filter form. Give it a numeric `height` so fast mode can box it, and `overflow: "auto"` so long content scrolls inside it instead of being cut (stress reads it as scrolling, as it does a `drawer`). - **`menu`** `{ x, y, children }` holds `menu-row`s and `divider`s: 4px padding, at least 192 wide, hugging its rows. With a numeric `height`, add `overflow: "auto"` so long rows scroll inside it. -- **`modal`** `{ title, size?: "sm" | "md" | "lg", actions?: [{ label, variant?, state? }], closeLabel?, children }` is 480 / 640 / 960 wide (640 by default), centred over its own scrim, which always covers the artboard (`x` / `y` place the modal's top-left instead). It is never taller than the artboard less 64px (less the insets on a phone). Its header holds the title and a close button named "Close" (`closeLabel` renames it). The body holds the children (vertical, 12px gap) and scrolls when tall, between the header and the actions. `actions` render right-aligned as 32px buttons; an action with no variant renders `secondary`, and the filled ones (`primary`, `destructive`) render rightmost. For a delete confirmation: `actions: [{ label: "Cancel" }, { label: "Delete", variant: "destructive" }]`. -- **`toast`** `{ text, tone?: "neutral" | "success" | "warning" | "danger", action?: { label, state? } }` sits bottom-centre, 24px above the artboard's bottom edge (`x` / `y` place its top-left instead); it hugs its text up to 480px. The tone colours a leading glyph (`$success`, `$warning`, `$danger`, neutral `$text-secondary`; `iconColor` overrides); the text stays `$text-primary`. `danger` renders `role="alert"`. +- **`modal`** `{ title, size?: "sm" | "md" | "lg", actions?: [{ label, variant?, state? }], closeLabel?, controlSize?: "xs" | "sm" | "md" | "lg", children }` is 480 / 640 / 960 wide (640 by default), centred over its own scrim, which always covers the artboard (`x` / `y` place the modal's top-left instead). It is never taller than the artboard less 64px (less the insets on a phone). Its header holds the title and a close button named "Close" (`closeLabel` renames it). The body holds the children (vertical, 12px gap) and scrolls when tall, between the header and the actions. `actions` render right-aligned as 32px buttons, and the close button is a 32px square; `controlSize` sizes both with the `button` size names (24 / 32 / 44 / 52; `size` stays the modal's width). An action with no variant renders `secondary`, and the filled ones (`primary`, `destructive`) render rightmost. For a delete confirmation: `actions: [{ label: "Cancel" }, { label: "Delete", variant: "destructive" }]`. +- **`toast`** `{ text, tone?: "neutral" | "success" | "warning" | "danger", action?: { label, state? }, controlSize? }` sits bottom-centre, 24px above the artboard's bottom edge (`x` / `y` place its top-left instead); it hugs its text up to 480px. The tone colours a leading glyph (`$success`, `$warning`, `$danger`, neutral `$text-secondary`; `iconColor` overrides); the text stays `$text-primary`. `danger` renders `role="alert"`. Its action is a 24px button; `controlSize` (the `button` size names) makes it 44 at `"md"`. - **`drawer`** `{ size?: "sm" | "md", scrim?, children }` is a 320 / 480 panel pinned to the right edge at full height, 16px padding; `scrim: true` dims what is behind it. -A modal's close button and actions (32 tall) and a toast's action (24 tall) are pointer targets. They are sized for a pointer, so on a phone use a `sheet` for a dialog. A modal and a drawer are panes: navigation and primary buttons inside them are judged apart from the page behind. +A modal's close button and actions (32 tall) and a toast's action (24 tall) are pointer targets, sized for a pointer by default. On a phone they are measured at 44: a centred `modal` with `controlSize: "md"` is a valid phone dialog, and a toast with an action takes `controlSize: "md"` too. A `sheet` stays the choice for a panel that rises from the bottom. A modal and a drawer are panes: navigation and primary buttons inside them are judged apart from the page behind. On a canvas whose root declares a `safeArea` or pins a `tab-bar` (a phone), a centred modal, a default toast and a drawer keep clear of them: the modal stays 16px past the insets and pinned chrome, the toast sits 16px above the tab bar or home indicator, and the drawer's padding grows past them, so the safe-area rules skip those three when that clearance covers the insets they judge by (on a phone root without a `safeArea` or pinned chrome they are still checked). A popover, a menu, a tooltip, and a modal or toast you place with `x` / `y` are checked like any positioned content. A `fullPage` capture grows the page, but the overlay layer stays the artboard: a scrim dims the first screen only. diff --git a/src/evaluate.ts b/src/evaluate.ts index 3454f3b..5abd286 100644 --- a/src/evaluate.ts +++ b/src/evaluate.ts @@ -2204,6 +2204,41 @@ function primitiveTargets( return []; } +/** Phase 32 R2 — a link and a text-input are phone tappables, measured by + * the box the 24px census uses (desktopTargets), without joining + * TAPPABLE_PRIMITIVES (that would drop them from the 24px census). */ +const PHONE_FIELDS = new Set(['link', 'text-input']); + +/** Phase 32 R2/R7 — every touch target a node carries on a phone: the + * tappable primitives, a link or text-input, and an overlay's own controls + * (a modal's close button and actions, a toast's action, at its controlSize). + * Disabled targets count (the phone census never exempted them). The fix + * names the dimension that fails. */ +function phoneTargets( + node: SceneNode, parentOf: Map, rootWidth: number, floor: number, +): Array<{ what: string; w?: number; h: number; fix: string }> { + if (TAPPABLE_PRIMITIVES.has(node.type)) return primitiveTargets(node, parentOf, rootWidth); + const fixFor = (t: { w?: number; h: number }, tall: string, wide: string) => + [t.h < floor ? tall : '', t.w !== undefined && t.w < floor ? wide : ''].filter(Boolean).join(' '); + if (node.type === 'link') { + const labelled = typeof node.label === 'string' ? node.label.trim() !== '' : typeof node.label === 'number'; + return desktopTargets(node).map((t) => ({ + ...t, + fix: fixFor(t, `Give the link height: ${floor}, or make it a button (size "md").`, + labelled || node.width !== undefined ? `Widen it to ${floor} or drop its width.` : `Give it width: ${floor} (it hugs its glyphs).`), + })); + } + if (node.type === 'text-input') { + return desktopTargets(node).map((t) => ({ ...t, fix: fixFor(t, 'Use size "lg" (44px).', `Widen it to ${floor} or drop its width (a field spans its container).`) })); + } + return overlayTargets(node).map((t) => ({ + ...t, + fix: node.type === 'modal' + ? 'Set controlSize: "md" (44px) on the modal — or use a sheet for a bottom panel.' + : 'Set controlSize: "md" (44px) on the toast.', + })); +} + /** One pointer target for the 24px census: its id, what to call it, the * effective size after the padded-row step, and whether it is disabled. */ interface PointerTarget { node: SceneNode; what: string; w: number; h: number; disabled: boolean } @@ -2389,9 +2424,10 @@ function checkUsability(entries: NodeEntry[], rootWidth: number, touch?: { floor const parentOf = new Map(); for (const en of entries) parentOf.set(en.node.id, en.parent); // On a phone a row holds "one control" only when no tappable primitive - // shares it either — a checkbox beside a button doesn't own the row. + // shares it either — a checkbox beside a button doesn't own the row. A link + // and a text-input are phone tappables too (Phase 32 R4). const countControls = (n: SceneNode): number => { - let c = CONTROL_TYPES.has(n.type) || (touch !== undefined && TAPPABLE_PRIMITIVES.has(n.type)) ? 1 : 0; + let c = CONTROL_TYPES.has(n.type) || (touch !== undefined && (TAPPABLE_PRIMITIVES.has(n.type) || PHONE_FIELDS.has(n.type))) ? 1 : 0; for (const ch of n.children ?? []) c += countControls(ch); return c; }; @@ -2400,8 +2436,8 @@ function checkUsability(entries: NodeEntry[], rootWidth: number, touch?: { floor || (n.children ?? []).some(hasText); for (const { node } of entries) { - if (touch && TAPPABLE_PRIMITIVES.has(node.type)) { - for (const t of primitiveTargets(node, parentOf, rootWidth)) { + if (touch) { + for (const t of phoneTargets(node, parentOf, rootWidth, touch.floor)) { if ((t.w !== undefined && t.w < touch.floor) || t.h < touch.floor) { score -= 25; issues.push({ diff --git a/src/index.ts b/src/index.ts index a1ddf0b..f04389e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -84,7 +84,7 @@ Bulk edits & queries: replace_matching_properties applies one property change to Point-and-tell feedback: the user toggles Comment mode in the viewer and clicks any element to leave a note anchored to that node (or to the whole page). Comments are stored on the canvas, git-diffable in bound repos, and reach the running server automatically. Check get_feedback when picking up a canvas — each entry carries the anchor nodeId plus a node snapshot, enough to act on immediately. Open feedback blocks presenting, same as open inspector comments: address every item, then close each via resolve_feedback with a one-line note saying what changed (your note shows up as a reply in the viewer's Feedback tab). -Phone app screens: declare the medium. canvas_create({ type: "mobile" }) makes a phone screen — the device artboard (390×844 for the default device "iphone-390") with the root reserving the safe-area insets as safeArea: { top: 47, bottom: 34 } (the renderer adds them to the root's own top/bottom padding, and the root grows with long content keeping that padding past it, so in-flow content never sits under the status bar or home indicator). type: "web" (the default) is a web page; canvas_set_type changes or clears the declaration on an existing canvas (it never resizes or writes safeArea — its result's hint names the op that does). The type selects a ruleset and defaults, never the render: generate_design_system on a mobile canvas pivots the type scale on the device body size (17px; 16px for data-dense), and every evaluate result carries a "surface" report ({ type, device, source "declared" | "default", rulesOn, rulesOff, conflicts }) naming the rule ids the type + genre + preset rulesets turned on and off — a rule both enabled and disabled stays on (in rulesOn) and is listed in conflicts. Start a phone screen from a mobile realisation: apply_structure on a mobile canvas resolves the anatomy name to it — dashboard → dashboard-mobile, settings → settings-mobile, auth → auth-mobile, onboarding → onboarding-mobile, and the mobile-first feed → feed-mobile (a list of rows, pinned tab bar) and detail → detail-mobile (an item with a primary action pinned over the home indicator) — each built from the primitives and gated to pass the mobile ruleset in fast and detailed mode and canvas_stress CLEAN (unthemed and under every personality); stamp it after generate_design_system (the dark, light and material presets carry a 14–15px body that mobile-type-floor flags on a phone). Resolution reads the DECLARED type: an undeclared 390px canvas stamps the web structure, so declare type "mobile" first. Its placeholders include every copy field of its primitives, with prop the field's path (title, subtitle, label, trailing.text, leading.initials, leading.label, items[0].label — a path, not an op key: set a nested one by writing its whole object or array, siblings included). An anatomy with no mobile realisation (the other web pages such as pricing, catalogue or bento-grid; web-only components such as data-table) is refused with the list of those that have one; realisation: "web" stamps the web one anyway. Of the components, form-field, stat-card, empty-state, skeleton-card, skeleton-stat-card, kpi-card, status-chip and initials-avatar stamp on every type. Build phone screens from the mobile primitives (batch_design lists them): status-bar and home-indicator (device chrome), nav-bar, tab-bar, button, list-row, sheet — never hand-built frames — and pin bars with position "fixed" (the renderer reserves room for pinned chrome, so content never starts or ends under it). A mobile canvas runs the mobile ruleset; every finding names its rule in a "rule" field: mobile-touch-target (ERROR: a tap target below 44px — a control (its row counts only when the row is a horizontal frame holding that one tappable), a button (size "sm" is 32, "xs" 24), a list-row, each tab-bar tab and FAB, each nav-bar action; primitives are measured by their own box, inside instances too), mobile-safe-area (WARNING: content under the 47px status-bar or 34px home-indicator inset, or left under a pinned bar at the start or end of the scroll; with root safeArea or pinned chrome the renderer reserves the insets and only positioned content (absolute / fixed / sticky) and pinned bars are checked — padding ≥32px scales down on a phone, so clear a pinned bar with a spacer frame inside your content frame; detailed mode is authoritative), mobile-tab-bar (WARNING: a tab bar with fewer than 2 or more than 5 tabs, an unlabeled tab, or one not pinned to the bottom), mobile-type-floor (WARNING: text below 11px, $body below 16px, prose of 5+ words below 13px), mobile-handbuilt-target (info: an icon-shaped frame below 44px — rebuild it as a button), mobile-one-column (info: two or more side-by-side children each holding 8+ words), and on every type mobile-artboard (a mobile canvas 500px+ wide WARNS; an undeclared canvas narrower than 500px WARNS until canvas_set_type declares it either way). +Phone app screens: declare the medium. canvas_create({ type: "mobile" }) makes a phone screen — the device artboard (390×844 for the default device "iphone-390") with the root reserving the safe-area insets as safeArea: { top: 47, bottom: 34 } (the renderer adds them to the root's own top/bottom padding, and the root grows with long content keeping that padding past it, so in-flow content never sits under the status bar or home indicator). type: "web" (the default) is a web page; canvas_set_type changes or clears the declaration on an existing canvas (it never resizes or writes safeArea — its result's hint names the op that does). The type selects a ruleset and defaults, never the render: generate_design_system on a mobile canvas pivots the type scale on the device body size (17px; 16px for data-dense), and every evaluate result carries a "surface" report ({ type, device, source "declared" | "default", rulesOn, rulesOff, conflicts }) naming the rule ids the type + genre + preset rulesets turned on and off — a rule both enabled and disabled stays on (in rulesOn) and is listed in conflicts. Start a phone screen from a mobile realisation: apply_structure on a mobile canvas resolves the anatomy name to it — dashboard → dashboard-mobile, settings → settings-mobile, auth → auth-mobile, onboarding → onboarding-mobile, and the mobile-first feed → feed-mobile (a list of rows, pinned tab bar) and detail → detail-mobile (an item with a primary action pinned over the home indicator) — each built from the primitives and gated to pass the mobile ruleset in fast and detailed mode and canvas_stress CLEAN (unthemed and under every personality); stamp it after generate_design_system (the dark, light and material presets carry a 14–15px body that mobile-type-floor flags on a phone). Resolution reads the DECLARED type: an undeclared 390px canvas stamps the web structure, so declare type "mobile" first. Its placeholders include every copy field of its primitives, with prop the field's path (title, subtitle, label, trailing.text, leading.initials, leading.label, items[0].label — a path, not an op key: set a nested one by writing its whole object or array, siblings included). An anatomy with no mobile realisation (the other web pages such as pricing, catalogue or bento-grid; web-only components such as data-table) is refused with the list of those that have one; realisation: "web" stamps the web one anyway. Of the components, form-field, stat-card, empty-state, skeleton-card, skeleton-stat-card, kpi-card, status-chip and initials-avatar stamp on every type. Build phone screens from the mobile primitives (batch_design lists them): status-bar and home-indicator (device chrome), nav-bar, tab-bar, button, list-row, sheet — never hand-built frames — and pin bars with position "fixed" (the renderer reserves room for pinned chrome, so content never starts or ends under it). A mobile canvas runs the mobile ruleset; every finding names its rule in a "rule" field: mobile-touch-target (ERROR: a tap target below 44px — a control (its row counts only when the row is a horizontal frame holding that one tappable), a button (size "sm" is 32, "xs" 24), a list-row, each tab-bar tab and FAB, each nav-bar action, a link (24 by default: height 44), a text-input (40 by default: size "lg" is 44), a modal's close button and actions and a toast's action (32/32/24 by default: controlSize "md" is 44); primitives are measured by their own box, inside instances too, disabled ones included), mobile-safe-area (WARNING: content under the 47px status-bar or 34px home-indicator inset, or left under a pinned bar at the start or end of the scroll; with root safeArea or pinned chrome the renderer reserves the insets and only positioned content (absolute / fixed / sticky) and pinned bars are checked — padding ≥32px scales down on a phone, so clear a pinned bar with a spacer frame inside your content frame; detailed mode is authoritative), mobile-tab-bar (WARNING: a tab bar with fewer than 2 or more than 5 tabs, an unlabeled tab, or one not pinned to the bottom), mobile-type-floor (WARNING: text below 11px, $body below 16px, prose of 5+ words below 13px), mobile-handbuilt-target (info: an icon-shaped frame below 44px — rebuild it as a button), mobile-one-column (info: two or more side-by-side children each holding 8+ words), and on every type mobile-artboard (a mobile canvas 500px+ wide WARNS; an undeclared canvas narrower than 500px WARNS until canvas_set_type declares it either way). Application screens: canvas_create({ type: "desktop-app" }) for a tool you work in — an editor, an admin console, a file browser, a viewer: persistent chrome, panes, dense controls, a current selection, in a browser tab or a native window. The test is what the user does: a page you read and scroll is "web", a tool you work in is "desktop-app". It gets the window artboard (1440×900 for the default device "window-1440", no insets); generate_design_system pivots its type on 14px (13 for data-dense); its ruleset turns OFF type-scale-ratio (the adjacent font-size ratio check — dense apps step 12/13/14 on purpose), and desktop-app-artboard (on every type) WARNS when a desktop-app canvas is narrower than 1024px, and when a canvas holding a desktop-app primitive (nav-item, tabs, tree-row, menu-row, property-row) never declared its type or is declared mobile (declared web gets an info); an undeclared canvas holding an overlay (tooltip, popover, menu, modal, toast, drawer) warns too, while web and mobile canvases may hold overlays freely. Build app screens from the desktop-app primitives (batch_design lists them): link, text-input, nav-item, tabs, tree-row, menu-row, property-row, divider, plus button size "xs" (24px) with ariaLabel for icon-only buttons and links — never hand-built frames, which no target rule can measure. A nav-item's dotColor is an identity dot and never counts as a competing accent. Start an app screen from a desktop-app realisation: apply_structure on a desktop-app canvas resolves the anatomy name to it — split-workbench → split-workbench-app, dashboard → dashboard-app, settings → settings-app, and three app-only anatomies: list-detail → list-detail-app (navigation, a searchable list, a detail pane with a "nothing selected" placeholder), editor-inspector → editor-inspector-app (a work area beside a 70/30 inspector of tabs and property-rows), browser → browser-app (a filter bar over an adaptive card grid); data-table → data-table-app (32px toolbar, header, rows and pager; stamp it into a pane at least 480px wide, not a 300px side panel) and skeleton-table → skeleton-table-app (its loading state). Each is built from the primitives and gated: > 95 with no warning, error, tell or desktop-app finding in fast and detailed mode under the presets, every personality and an inherited system, canvas_stress CLEAN at 1440, 1280 and 1024 wide, data-table stamped into a pane at least 480px wide clean too — so a fresh stamp is READY TO PRESENT unless coverage asks for a state. They fill the window: the stamp sets root overflow "hidden" (the root keeps the artboard height) and every pane is overflow "auto", so long content scrolls inside its pane — keep new content inside a pane, and never give a pane's direct child a fixed height or an overflow (the pane squashes it instead of scrolling). Coverage still asks for states: dashboard-app and data-table-app need "empty" + "loading", editor-inspector-app and settings-app (forms) need "error". toolbar, toggle-row, segmented-control and breadcrumb stay web-only (realisation: "web" forces one). On web and desktop-app every pointer target — the four controls and the clickable primitives (button, list-row, tab-bar tabs, nav-bar actions, link, text-input, nav-item, each tab of a tabs, tree-row, menu-row; inline text links are exempt) — meets the 24px WCAG 2.5.8 floor or its spacing exception (nothing else within a 24px circle around it): detailed mode runs that circle test (ERROR on failure), fast mode WARNS on anything under 24 and names detailed mode. The desktop-app ruleset (each finding carries its "rule"; canvas_evaluate lists them) adds: name every icon-only button and link (ariaLabel); mark exactly one current place — one active nav-item per pane — a frame with overflow "auto", so give a rail and a sidebar each their own (a parent may stay active over its active child), one active tab per tabs, one active row per tree; a dense type ladder (desktop-app-type-ladder, replacing type-scale-ratio: 12/13/14 steps are fine, nothing below 11px, prose ≥12px, $body ≥13px); table header rows as tall as their body rows; column headers never truncated; one primary button per pane (info); and frames shaped like small buttons are named as hand-built targets (info) — rebuild them as button or link; overlays that cannot work as drawn warn (desktop-app-overlay: a second modal, a tooltip with children, a table of more than 10 body rows or a sideways scroller inside a modal, an overlay leaving the viewport, a popover or menu under the scrim of a modal or a scrim: true drawer) and a second toast, a danger toast and an anchor naming nothing clickable are infos. Before presenting a desktop-app screen run mode "detailed" too: it measures rendered rows, column edges and truncation (a tablist whose every label is cut warns). Overlays (tooltip, popover, menu, modal, toast, drawer) are screen states: add a variant ("menu-open", "comment-open", "confirm-delete", "toast") with canvas_add_variant and insert the overlay there; wherever it sits in the tree it renders in one layer above all content, stacked by kind (no z-index exists), at x / y in ROOT coordinates; a modal and a drawer are panes of their own (one active nav-item, one primary — a modal's "primary" action counts). A menu or popover on a screen with a modal (or a drawer with scrim: true) renders under the scrim: put its content in the dialog, or design it open on a variant without one. Element states are a property, not a variant: state: "hover" | "focus" | "pressed" | "disabled" on a button, link, text-input, nav-item, tree-row, menu-row, list-row or control (on the item for tabs, tab-bar, nav-bar actions, modal actions and a toast action) draws that state from the design system's state tokens — for a states sheet or a screenshot; the evaluator never needs it drawn: on a desktop-app canvas it computes every target's states itself, in both themes — desktop-app-focus-visible (ERROR: a focus ring below 3:1 against the pixels it covers unfocused; one error per ring and backdrop, its nodeIds every target that shares them — fix $focus-ring), desktop-app-state-contrast (WARNING: an active nav-item's or tree-row's bar or line tab's underline below 3:1 against its active fill, at rest or in hover; contained tabs are not measured), desktop-app-boundary (WARNING: a text-input or select border, an unchecked checkbox or radio outline, or an unchecked toggle track below 3:1 against what is behind it — a border that draws nothing (transparent, a misspelt $token) counts as invisible, a field whose own fill clears 3:1 passes; use $border-strong) and desktop-app-disabled (info: state tokens that make a disabled target look like its enabled self, within 1.1:1). Text inside a disabled clickable primitive is exempt from text contrast on every type. @@ -115,7 +115,7 @@ const WORKFLOW_CHEATSHEET = [ 'Final polish when an LLM API key is present: canvas_evaluate mode "llm" (the five-axis vision rubric) → canvas_revise on failing axes → re-judge until it passes or canvas_revise stops. The heuristic gate is the floor; the critique loop is the ceiling — make it the standard last step before presenting, not an exception. It never blocks: still-failing axes after canvas_revise stops get named to the user, not looped on. Keyless sessions skip it (a note says so), nothing else changes.', 'One canvas per screen / state; let the per-project build log nudge you to vary structure.', 'Data screens: design every state — canvas_add_variant for "empty" / "loading" ("error" for forms) + the empty-state / skeleton-table / skeleton-stat-card scaffolds (coverage warns until they exist) — and run canvas_stress before presenting (fix clips/overflows with fluid widths, then re-run until CLEAN — a FRAGILE run keeps canvas_evaluate NOT READY until a full CLEAN run).', - 'Usability gates like contrast does: on web and desktop-app a pointer target (a control or a clickable primitive) under the 24px floor fails — WCAG 2.5.8, with its spacing exception (a smaller target passes when nothing else sits within a 24px circle around it): detailed mode runs that test and ERRORS, fast mode WARNS until you grow it or run mode "detailed" (a lone control inherits its padded row\'s box; on a canvas declared mobile the floor is 44px for controls AND the tappable primitives — button (xs is 24 and sm is 32: errors there), list-row, tab-bar tabs, nav-bar actions — mobile-touch-target), an unlabeled control is a warning, "Click here"-style copy is an info; on desktop-app an icon-only button or link without ariaLabel warns, and a nav group, tabs or tree with no single active item warns (desktop-app-current). The stock scaffolds already pass — hand-built controls are where these bite.', + 'Usability gates like contrast does: on web and desktop-app a pointer target (a control or a clickable primitive) under the 24px floor fails — WCAG 2.5.8, with its spacing exception (a smaller target passes when nothing else sits within a 24px circle around it): detailed mode runs that test and ERRORS, fast mode WARNS until you grow it or run mode "detailed" (a lone control inherits its padded row\'s box; on a canvas declared mobile the floor is 44px for controls AND the tappable primitives — button (xs is 24 and sm is 32: errors there), list-row, tab-bar tabs, nav-bar actions, link (height 44), text-input (size "lg"), a modal\'s and a toast\'s controls (controlSize "md") — mobile-touch-target), an unlabeled control is a warning, "Click here"-style copy is an info; on desktop-app an icon-only button or link without ariaLabel warns, and a nav group, tabs or tree with no single active item warns (desktop-app-current). The stock scaffolds already pass — hand-built controls are where these bite.', 'Derive the system before drawing: generate_design_system (seed + personality → the full design language: colors, font pairing, type roles, radii, $elevation depth, $motion) is the headline call; generate_scale / generate_color_system regenerate just the scale or just the palette — then reference $tokens everywhere and let the lint re-attach any literal that drifts.', 'Multi-screen module? Finish as a SET: project_evaluate rolls up per-screen scores + cross-screen drift (radius / accent / token adoption / copied chrome / states) — advisory, the per-canvas directives still gate; mode "llm" adds the flow critique. Compose bento/editorial layouts with real grid (layout "grid" + spans), never nested flex.', 'Picking up an existing canvas? get_feedback first — point-and-tell comments may be waiting (node-anchored or canvas-level). Address every open item, then resolve_feedback with a note saying what changed.', @@ -148,7 +148,7 @@ const GOTCHAS = [ 'Beyond one canvas: bento/editorial compositions are REAL grid — layout: "grid" + gridColumns (count / fr-weight array / template string) + gridColumn/gridRow spans (a number means span N); responsive: "stack" collapses to one column on mobile. Never approximate tiles with nested flex. When a multi-screen module feels done, project_evaluate reviews the SET — radius-drift / accent-drift / token-adoption / copied-chrome / state-coverage findings, each naming its canvases — and mode "llm" judges up to 8 screens together for flow consistency (flowSkipped lists anything past the cap; keyless → full roll-up + a note). ADVISORY: only the per-canvas directives gate presenting.', 'Start a phone screen from its mobile realisation: generate_design_system, then apply_structure with the anatomy name on the mobile canvas — dashboard, settings, auth, onboarding, feed or detail stamp dashboard-mobile etc. (status bar, nav bar, list rows, buttons, pinned tab bar or home indicator; every tap target a primitive). Resolution reads the DECLARED type: canvas_create({ width: 390 }) with no type stamps the web dashboard. pricing and the web-only components (data-table, toolbar, …) are refused on a phone with the list of what has a mobile realisation; realisation: "web" forces the web one. list_structures({ canvasId }) lists what stamps on that canvas. Read the result\'s placeholders for node ids and fields (prop) instead of guessing them.', 'Start an application screen from its desktop-app realisation: canvas_create({ type: "desktop-app" }), generate_design_system, then apply_structure with the anatomy name — split-workbench, list-detail, editor-inspector, browser, dashboard or settings stamp split-workbench-app etc. (nav-items, panes that scroll on their own, every click target a primitive). Adapt inside the panes: a pane\'s direct child with a fixed height or an overflow gets squashed instead of scrolled. data-table stamps data-table-app (its loading state is skeleton-table-app). list_structures({ canvasId }) lists what stamps on the canvas; realisation: "web" forces a web-only one such as toolbar.', - 'Declare the medium: a phone app screen is canvas_create({ type: "mobile" }) (device "iphone-390": 390×844, root safeArea: { top: 47, bottom: 34 } added to the root padding by the renderer) — not a 390px-wide web canvas. canvas_set_type re-declares an existing canvas (type: "web" | "mobile" | null) WITHOUT resizing it or writing safeArea; follow its hint. The type changes the ruleset and defaults only (generate_design_system pivots on a 17px body, 16 for data-dense), never pixels; evaluate\'s "surface" report shows the type, its source ("declared" | "default"; canvas_create reports the same as typeSource) and the rulesOn / rulesOff / conflicts the rulesets composed. Build a phone screen from the mobile primitives — status-bar, nav-bar, list-row, button, tab-bar, home-indicator, sheet — not hand-built frames: they carry 44px targets and pin themselves. On mobile a tap target below 44px is an ERROR (mobile-touch-target), content in the status-bar / home-indicator insets or left under a pinned bar is a WARNING (mobile-safe-area), and a tab bar outside 2–5 labeled tabs or not pinned to the bottom WARNS (mobile-tab-bar). Keep root safeArea; the root grows with long content and keeps its end padding. A pinned CTA bar: position "fixed", bottom: 0, padding under 32 (larger padding scales down on a phone) and a 34px spacer frame as its last child, plus a spacer at the end of your content frame tall enough that it and the root\'s 34px bottom inset reach the bar\'s height (the rule names it: 68 for a 102px bar; re-evaluate after changing the bar). An undeclared canvas under 500px wide WARNS (mobile-artboard) until you declare it either way. canvas_set_type does not reach existing state variants — its variantsOutOfSync lists them.', + 'Declare the medium: a phone app screen is canvas_create({ type: "mobile" }) (device "iphone-390": 390×844, root safeArea: { top: 47, bottom: 34 } added to the root padding by the renderer) — not a 390px-wide web canvas. canvas_set_type re-declares an existing canvas (type: "web" | "mobile" | null) WITHOUT resizing it or writing safeArea; follow its hint. The type changes the ruleset and defaults only (generate_design_system pivots on a 17px body, 16 for data-dense), never pixels; evaluate\'s "surface" report shows the type, its source ("declared" | "default"; canvas_create reports the same as typeSource) and the rulesOn / rulesOff / conflicts the rulesets composed. Build a phone screen from the mobile primitives — status-bar, nav-bar, list-row, button, tab-bar, home-indicator, sheet — not hand-built frames: they carry 44px targets and pin themselves. A text-input on a phone takes size "lg" (44), a standalone link height 44, and a modal or toast controlSize "md": their defaults are pointer sizes and error there. On mobile a tap target below 44px is an ERROR (mobile-touch-target), content in the status-bar / home-indicator insets or left under a pinned bar is a WARNING (mobile-safe-area), and a tab bar outside 2–5 labeled tabs or not pinned to the bottom WARNS (mobile-tab-bar). Keep root safeArea; the root grows with long content and keeps its end padding. A pinned CTA bar: position "fixed", bottom: 0, padding under 32 (larger padding scales down on a phone) and a 34px spacer frame as its last child, plus a spacer at the end of your content frame tall enough that it and the root\'s 34px bottom inset reach the bar\'s height (the rule names it: 68 for a 102px bar; re-evaluate after changing the bar). An undeclared canvas under 500px wide WARNS (mobile-artboard) until you declare it either way. canvas_set_type does not reach existing state variants — its variantsOutOfSync lists them.', 'Gate integrity: a canvas describing a SHIPPED view is a contract — run canvas_check_drift against the live route BEFORE designing on it (findings: missing-in-page / missing-in-canvas / control-mismatch / table-mismatch), and reconcile deliberately: update the canvas, flag the implementation, or ask — never silently annotate a difference. canvas_sync_from_url answers "how much does it LOOK different" (pixel %); canvas_version makes approvals falsifiable — record { canvasId, versionHash } at approval time and check with expectedHash later (metadata/feedback never moves the hash; ANY inherited workspace/project token edit DOES, even to a token the canvas does not use). A legacy sha256: hash still checks but carries a warning — re-record it as the current sha256r: versionHash. CI can demand both: npx framesmith check-drift / verify exit 1 on failure.', ]; @@ -595,8 +595,8 @@ Mobile primitives (phone screens — they carry their own sizes, hit areas, and The renderer reserves room for pinned chrome: the root's top/bottom padding is raised to at least the pinned status-bar / tab-bar / home-indicator height, so content never starts or ends under it. Labels truncate to one line with an ellipsis (canvas_stress reports that as designed truncation). Desktop-app primitives (application screens — canvas_create type "desktop-app"; on the 24/32/40/48 density ladder, colours from $accent / $accent-tint / $border / $border-strong / $text-primary / $text-secondary / $danger, neutral fallbacks unthemed; NEVER hand-build them from frames — a hand-built frame is not a measured target): - - link { label, icon?, iconPosition?, external?, ariaLabel?, state? } — a standalone text action, at least 24 tall, measured as a pointer target. With no label it hugs its glyphs (14px wide, 30 with external) and takes ariaLabel as its name (aria-label + title). A text node can hold INLINE links instead: links: [{ start, end }] character ranges of its content, drawn underlined (inline links are exempt from the 24px floor, as WCAG exempts them). - - text-input { value?, placeholder?, icon?, size?: "sm"|"md" (32/40), rows? (a multi-line field), error? (a message), disabled?, state? } — its border ($border-strong when the design system has it) is its only boundary; error draws an icon and the message below and colours the border $danger. + - link { label, icon?, iconPosition?, external?, ariaLabel?, state? } — a standalone text action, at least 24 tall, measured as a pointer target (on a phone at 44: give it height 44, or use a button). With no label it hugs its glyphs (14px wide, 30 with external) and takes ariaLabel as its name (aria-label + title). A text node can hold INLINE links instead: links: [{ start, end }] character ranges of its content, drawn underlined (inline links are exempt from the 24px floor, as WCAG exempts them). + - text-input { value?, placeholder?, icon?, size?: "sm"|"md"|"lg" (32/40/44; lg is the phone size, below 44 is a mobile-touch-target error on a phone), rows? (a multi-line field), error? (a message), disabled?, state? } — its border ($border-strong when the design system has it) is its only boundary; error draws an icon and the message below and colours the border $danger. - nav-item { label, icon?, count?, dotColor? (an identity dot — never counted as an accent), active?, depth?: 0|1, collapsed?, state? } — 32 tall, spans its sidebar; active draws an $accent-tint fill, a 2px $accent bar and a heavier label (aria-current); collapsed is the 32×32 rail form, its label the accessible name. - tabs { items: [{ label, count?, active?, disabled?, state? }], variant?: "line"|"contained", size?: "sm"|"md" (32/40) } — one tablist; each tab is its own pointer target; the active tab gets an indicator (line) or an $accent-tint fill (contained) and a heavier label; desktop-app-state-contrast measures the line underline only, never a contained tab's fill. - tree-row { label, depth, expanded? (absent for a leaf), icon?, active?, state? } — 32 tall, indents 16 per level, a chevron when expanded is set; active draws an $accent-tint fill, a 2px bar in iconColor ($accent by default) at the row's left edge (same x at every depth, measured by desktop-app-state-contrast) and a heavier label. @@ -610,10 +610,10 @@ Overlays (screen states — put one in a state variant made with canvas_add_vari - tooltip { text, x, y } — inverted ($text-primary fill), wraps at 240px; text only, never children. - popover { x, y, size?: "xs"|"sm"|"md"|"lg" (192/320/480/640, default 320) or width, children } — a panel (vertical, padding 12 by default; layout / gap / padding apply as on a frame): a comment box, a filter form. With a numeric height, add overflow: "auto" so long content scrolls inside it (canvas_stress reads it as scrolling, as it does a drawer). - menu { x, y, children: menu-row and divider nodes } — padding 4, at least 192 wide, hugs its rows. With a numeric height, add overflow: "auto" so long rows scroll inside it (canvas_stress reads it as scrolling). - - modal { title, size?: "sm"|"md"|"lg" (480/640/960, default md), actions?: [{ label, variant?, state? }], closeLabel?, children } — centred over its own full scrim (x / y place its top-left instead); a header with the title and a close button named "Close" (closeLabel renames it); the body holds the children (vertical, gap 12) and scrolls when tall; actions render right-aligned as 32px buttons, an action with no variant as "secondary", the filled ones ("primary", "destructive") rightmost. A modal is a region of its own for the primary-count and wayfinding rules. - - toast { text, tone?: "neutral"|"success"|"warning"|"danger", action?: { label, state? } } — bottom-centre, 24px above the artboard's bottom edge (x / y place it); the tone colours a leading glyph, the text stays $text-primary. + - modal { title, size?: "sm"|"md"|"lg" (480/640/960, default md), actions?: [{ label, variant?, state? }], closeLabel?, controlSize?: "xs"|"sm"|"md"|"lg" (the close button's and actions' button size, 24/32/44/52, default sm), children } — centred over its own full scrim (x / y place its top-left instead); a header with the title and a close button named "Close" (closeLabel renames it); the body holds the children (vertical, gap 12) and scrolls when tall; actions render right-aligned as 32px buttons (controlSize "md" makes them and the square close button 44), an action with no variant as "secondary", the filled ones ("primary", "destructive") rightmost. A modal is a region of its own for the primary-count and wayfinding rules. + - toast { text, tone?: "neutral"|"success"|"warning"|"danger", action?: { label, state? }, controlSize? (the action's button size, default xs 24; "md" is 44) } — bottom-centre, 24px above the artboard's bottom edge (x / y place it); the tone colours a leading glyph, the text stays $text-primary. - drawer { size?: "sm"|"md" (320/480) or width, scrim?: false, children } — pinned to the right edge, full height, padding 16; scrim: true dims what is behind it. -A modal's close button and actions and a toast's action are pointer targets (32 / 32 / 24 tall), sized for a pointer: on a phone use a sheet for a dialog. On a root with a safeArea or a pinned tab-bar, a centred modal, a default toast and a drawer keep clear of the insets and the tab bar. snapshot_layout lists every overlay under the root, and a modal (or a drawer with a scrim) carries its scrim's rect. +A modal's close button and actions and a toast's action are pointer targets (32 / 32 / 24 tall by default), sized for a pointer; on a phone they must reach 44 (mobile-touch-target): a centred modal with controlSize "md" is a valid phone dialog, a toast with an action takes controlSize "md" too, and a sheet stays the choice for a panel that rises from the bottom. On a root with a safeArea or a pinned tab-bar, a centred modal, a default toast and a drawer keep clear of the insets and the tab bar. snapshot_layout lists every overlay under the root, and a modal (or a drawer with a scrim) carries its scrim's rect. Element states (state?: "rest"|"hover"|"focus"|"pressed"|"disabled", default rest): on button, link, text-input, nav-item, tree-row, menu-row, list-row, toggle, checkbox, radio, select, and on the items of tabs, tab-bar, nav-bar (leading / trailing), modal (actions[]) and toast (action). Hover, focus and pressed layer the target's label colour over its fill (the state tokens' hover / focus / pressed, Material's 8 / 10 / 10% without them); focus adds a 2px $focus-ring outline at a 2px gap (inside the tab for a tab or tab-bar item); a link also underlines in hover and pressed; active, checked and expanded keep their fill under the layer. disabled (or disabled: true, which wins over any state) renders the whole target in $text-primary at the state tokens' disabledContent (38%), a drawn fill or border at disabledContainer (12%), and a check mark, knob or badge numeral in $bg-surface, when the tokens set either disabled opacity (a lone one takes the other's Material value), else at 0.5 opacity in its own colours; an authored opacity wins. A disabled target leaves the tab order, the 24px census and the primary count (the phone's 44px census still measures it). A tabs node's own state "disabled" disables every tab. Inside a component instance, a state or disabled on the component's node, or set through an override (overrides: { "": { disabled: true } }), draws exactly as it does outside one, in the design system's colours. Other node types ignore state. @@ -2158,7 +2158,7 @@ THE HEURISTIC DIRECTIVE IS THE PRESENTATION GATE. mode: "llm" adds optional dept The result's "genre" field (present whenever cliche ran) makes the genre decision auditable: { active, source ("explicit" param | "provenance" stamp | null), relaxed (tells skipped, by the genre and by the applied preset), notRelaxed ([{ tell, relaxedBy }] — tells still flagging that a DIFFERENT genre would relax), byPreset ({ preset, relaxed } — present when the applied preset relaxed tells on its own, e.g. the material preset) }. active is the canonical genre: an alias reports as its canonical name ("dashboard" → "data", "checkout" → "commerce"). If the score is pinned by tells listed in notRelaxed, the genre is probably wrong — genre follows what the screen is FOR (read screens with the user's own figures → "data"; a screen you complete a purchase on → "commerce"; the Material style → "material" (an editor or admin console is a type, not a genre: declare it with canvas_create / canvas_set_type type "desktop-app")), not what it contains. -The result's "surface" field (always present) reports the canvas TYPE and the rules it selected: { type ("web" | "mobile" | "desktop-app"), device (the profile: a phone such as "iphone-390" on mobile, a window such as "window-1440" on desktop-app, null on web), source ("declared" by canvas_create type / canvas_set_type, or "default" — never declared, judged as web), rulesOn (rule ids the composed type + genre + preset rulesets turned on), rulesOff (rule ids they turned off), conflicts (ids both enabled and disabled — those stay ON) }. On a web canvas rulesOn is ["desktop-app-artboard", "mobile-artboard"] (the base rules, on for every type). On a desktop-app canvas rulesOff lists "type-scale-ratio" (the adjacent font-size ratio check, which tags its warnings with that rule id on web and mobile; dense apps step 12/13/14 on purpose), and desktop-app-artboard (structure, every type) WARNS when a desktop-app canvas is narrower than its window's 1024px minimum, and when a canvas holding a desktop-app primitive (nav-item, tabs, tree-row, menu-row, property-row) never declared its type or is declared mobile — a canvas declared web gets an info instead; an undeclared canvas holding an overlay (tooltip, popover, menu, modal, toast, drawer) warns too, while declared web or mobile canvases may hold overlays. On a desktop-app canvas rulesOn also lists the desktop-app ruleset, each finding tagged with its "rule": desktop-app-target (usability: the 24px floor above, named — fast WARNING, detailed ERROR when the 24px circle reaches a neighbour; an unlabelled link with no width (or "auto") measures its glyphs, 14px wide or 30 with external, on web too), desktop-app-handbuilt-target (usability info, never blocks: a frame below 32px holding one icon, an icon plus a label of ≤3 words, or a bordered padded frame holding one such label — the shape an imported text button takes; never inside a clickable primitive; rebuild it as a button or link if clickable), desktop-app-icon-label (usability WARNING: an icon-only button or link with no ariaLabel, a collapsed nav-item with a blank label), desktop-app-current (usability WARNING: in one pane — a frame with overflow "auto", a modal, a drawer, or the root; each node belongs to its nearest, so give each navigation region its own pane — two active nav-items at one depth, or two or more nav-items with none active; a tabs node with no active tab or more than one; two active tree-rows under one parent; info: a tree with a current row nesting past two levels), desktop-app-type-ladder (typography WARNING, replaces type-scale-ratio: adjacent sizes a { + const h = BUTTON_HEIGHT[overlayControlSize(n)]; if (n.type === 'modal') { + // The close button is icon-only, so square. return [ - { what: 'modal close button', w: MODAL_CONTROL, h: MODAL_CONTROL, disabled: false }, - ...modalActions(n).map((a) => ({ what: `modal action "${String(a.label).trim()}"`, h: MODAL_CONTROL, disabled: isDisabled(a) })), + { what: 'modal close button', w: h, h, disabled: false }, + ...modalActions(n).map((a) => ({ what: `modal action "${String(a.label).trim()}"`, h, disabled: isDisabled(a) })), ]; } if (n.type === 'toast' && n.action && typeof n.action === 'object' && hasText(n.action.label)) { - return [{ what: `toast action "${String(n.action.label).trim()}"`, h: TOAST_ACTION, disabled: isDisabled(n.action) }]; + return [{ what: `toast action "${String(n.action.label).trim()}"`, h, disabled: isDisabled(n.action) }]; } return []; } @@ -211,7 +218,7 @@ export function textInputRows(n: SceneNode): number { } export function textInputHeight(n: SceneNode): number { - const base = TEXT_INPUT_HEIGHT[n.size === 'sm' ? 'sm' : 'md']; + const base = TEXT_INPUT_HEIGHT[n.size === 'sm' || n.size === 'lg' ? n.size : 'md']; const rows = textInputRows(n); return rows > 1 ? Math.max(base, rows * TEXT_INPUT_LINE + 12) : base; } diff --git a/src/renderer.ts b/src/renderer.ts index 5b60c5d..c0135bf 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -8,7 +8,7 @@ import { BUTTON_FONT, BUTTON_PADDING, CHROME_EDGE, FAB_RAISE, FAB_SIZE, FLOATING_INSET, NAV_ACTION, NAV_BAR_HEIGHT, NAV_BAR_LARGE_HEIGHT, TAB_BAND, buttonHeight, chromeHeight, chromeReservation, effectivePosition, listRowMinHeight, navBarHeight, rootInsets, LINK_MIN_HEIGHT, LINK_ICON, LINK_EXTERNAL, NAV_ITEM_HEIGHT, TABS_HEIGHT, TREE_ROW_HEIGHT, TREE_INDENT, MENU_ROW_HEIGHT, PROPERTY_ROW_HEIGHT, PROPERTY_LABEL_WIDTH, - tabsItems, textInputHeight, textInputRows, + tabsItems, textInputHeight, textInputRows, overlayControlSize, OVERLAY_TYPES, OVERLAY_Z, TOOLTIP_MAX_WIDTH, MENU_MIN_WIDTH, drawerWidth, modalActions, modalWidth, popoverWidth, STATE_LAYERS, elementState, } from './primitives.js'; @@ -1766,7 +1766,7 @@ function actionButton(node: SceneNode, a: NonNullable[numb const fill = a.fill ?? (filled ? (variant === 'destructive' ? FALLBACK.danger : FALLBACK.accent) : 'transparent'); const stroke = a.stroke ?? (variant === 'secondary' ? node.stroke ?? FALLBACK.border : undefined); return { - id: node.id, type: 'button', size: 'sm', label: String(a.label).trim(), variant, maxWidth: 240, fill, + id: node.id, type: 'button', size: overlayControlSize(node), label: String(a.label).trim(), variant, maxWidth: 240, fill, color: a.color ?? (filled ? '#FFFFFF' : variant === 'ghost' ? FALLBACK.accent : node.color ?? FALLBACK.text), ...(stroke ? { stroke } : {}), state: a.state, disabled: a.disabled, stateStyle: node.stateStyle, @@ -1790,7 +1790,7 @@ function renderModal(node: SceneNode, rc: RenderCtx, attrs: string): string { node.opacity !== undefined ? `opacity: ${node.opacity}` : undefined, ]); const close = renderButton({ - id: node.id, type: 'button', size: 'sm', icon: 'x', variant: 'ghost', fill: 'transparent', + id: node.id, type: 'button', size: overlayControlSize(node), icon: 'x', variant: 'ghost', fill: 'transparent', color: node.secondaryColor ?? FALLBACK.secondary, ariaLabel: text(node.closeLabel) || 'Close', stateStyle: node.stateStyle, }, rc, ' tabindex="0" data-focusable data-fs-modal-close', true); const header = `
${title ? titledLabel(title, 'font-size: 16px; font-weight: 600; line-height: 24px') : ''}
${close}
`; @@ -1827,7 +1827,7 @@ function renderToast(node: SceneNode, rc: RenderCtx, attrs: string): string { const message = `${escapeHtml(text(node.text))}`; const action = label ? renderButton({ - id: node.id, type: 'button', size: 'xs', label, variant: 'ghost', fill: 'transparent', color: node.action?.color ?? FALLBACK.accent, maxWidth: 160, + id: node.id, type: 'button', size: overlayControlSize(node), label, variant: 'ghost', fill: 'transparent', color: node.action?.color ?? FALLBACK.accent, maxWidth: 160, state: node.action?.state, disabled: node.action?.disabled, stateStyle: node.stateStyle, }, rc, ' tabindex="0" data-focusable', true) : ''; diff --git a/src/types.ts b/src/types.ts index a18ede5..64116f7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -353,7 +353,8 @@ export interface SceneNode { /** button label. */ label?: string; iconPosition?: 'leading' | 'trailing'; - /** button: xs 24 / sm 32 / md 44 / lg 52; tabs and text-input: sm 32 / md 40; + /** button: xs 24 / sm 32 / md 44 / lg 52; tabs: sm 32 / md 40; text-input: + * sm 32 / md 40 / lg 44; * modal: sm 480 / md 640 / lg 960; popover: xs 192 / sm 320 / md 480 / lg 640; * drawer: sm 320 / md 480. */ size?: 'xs' | 'sm' | 'md' | 'lg'; @@ -421,6 +422,11 @@ export interface SceneNode { tone?: 'neutral' | 'success' | 'warning' | 'danger'; /** toast: one action, a ghost text button. */ action?: ToastAction; + /** Phase 32 FR-E2 — modal: the close button's and actions' button size + * (default sm, 32); toast: the action's (default xs, 24). xs 24 / sm 32 / + * md 44 / lg 52; "md" meets the 44px phone floor. Any other value is the + * default. */ + controlSize?: 'xs' | 'sm' | 'md' | 'lg'; /** drawer: a scrim behind it (default false; a modal always has one). */ scrim?: boolean; diff --git a/test/browser/test-overlays-render.ts b/test/browser/test-overlays-render.ts index 029130d..ffb7ecf 100644 --- a/test/browser/test-overlays-render.ts +++ b/test/browser/test-overlays-render.ts @@ -300,6 +300,33 @@ const tech = generateDesignSystem('#2563EB', 'technical').variables; check('fast mode reads a nested overlay\'s y as root coordinates (warns at y 10, not 310)', (await safe(nested, 'fast')).some((i) => i.nodeId === 'pt2')); } +// ── Phase 32 R5: controlSize, as rendered on a phone ──────────────────────── +{ + const dialog = (size?: string): Canvas => ({ + id: 'c', name: 'c', projectId: 'p', components: {}, variables: {}, createdAt: '', lastModified: '', + root: { id: 'document', type: 'document', name: 'D', width: 390, height: 844, fill: '#FFFFFF', layout: 'vertical', safeArea: { top: 47, bottom: 34 }, children: [ + { id: 'm', name: 'm', type: 'modal', title: 'Delete file?', actions: [{ label: 'Cancel' }, { label: 'Delete', variant: 'destructive' }], children: [{ id: 'mt', name: 'mt', type: 'text', content: 'This cannot be undone.' }], ...(size ? { controlSize: size } : {}) }, + { id: 't', name: 't', type: 'toast', text: 'Saved', action: { label: 'Undo' }, ...(size ? { controlSize: size } : {}) }, + ] }, + metadata: { surface: { type: 'mobile', device: 'iphone-390' } }, + } as Canvas); + /** Each rendered overlay control's box: [overlay id, width, height]. */ + const boxes = (c: Canvas) => withPage(async (page) => { + await page.setViewport({ width: 390, height: 844 }); + await page.setContent(renderToHtml(c.root, 390, 844, c), { waitUntil: 'load' }); + return page.evaluate(() => [...document.querySelectorAll('[data-node-id="m"] [data-focusable], [data-node-id="t"] [data-focusable]')].map((el) => { + const r = el.getBoundingClientRect(); + return [el.closest('[data-node-id="m"],[data-node-id="t"]')?.getAttribute('data-node-id'), Math.round(r.width), Math.round(r.height)] as [string, number, number]; + })); + }); + const def = await boxes(dialog()); + check('R5: by default the modal\'s close and actions render 32 tall (close 32 square), the toast action 24', def.length === 4 + && def.filter(([o]) => o === 'm').every(([, , h]) => h === 32) && def.some(([o, w, h]) => o === 'm' && w === 32 && h === 32) + && def.filter(([o]) => o === 't').every(([, , h]) => h === 24), JSON.stringify(def)); + const md = await boxes(dialog('md')); + check('R5: controlSize "md" renders every control 44 tall, the close button 44 square', md.length === 4 && md.every(([, , h]) => h === 44) && md.some(([o, w]) => o === 'm' && w === 44), JSON.stringify(md)); +} + // ── Round 1 mutation gaps (rendered) ──────────────────────────────────────── { const long = 'A tooltip with enough words in it to wrap well past its maximum width of two hundred and forty pixels'; diff --git a/test/unit/test-desktop-primitives.ts b/test/unit/test-desktop-primitives.ts index 166ca69..5bc2b2e 100644 --- a/test/unit/test-desktop-primitives.ts +++ b/test/unit/test-desktop-primitives.ts @@ -179,8 +179,17 @@ const html = (n: SceneNode, colors?: Record) => { check('a sole checkbox inside a property-row is measured by the row (passes)', owned.length === 0, JSON.stringify(owned.map((i) => i.message))); const two = await usab({ id: 'pr2', name: 'pr2', type: 'property-row', label: 'Flags', children: [{ id: 'f1', name: 'f1', type: 'frame', layout: 'horizontal', children: [{ id: 'c1', name: 'c1', type: 'checkbox' }, { id: 'c2', name: 'c2', type: 'checkbox' }] }] }); check('two checkboxes in one property-row are measured bare (fast warnings)', two.length === 2); - const phone = (await evaluateCanvas(canvasWith([{ id: 'l', name: 'l', type: 'link', label: 'Go' }], { type: 'mobile', device: 'iphone-390' }), { mode: 'fast', categories: ['usability'] })).issues; - check('mobile: desktop primitives are not phone tappables (no touch-target finding)', !phone.some((i) => i.rule === 'mobile-touch-target')); + // Phase 32 R2: a link is a phone tappable now (44px census); nav-item and + // the other desktop-app rows are not. + const onPhone = async (n: SceneNode) => (await evaluateCanvas(canvasWith([n], { type: 'mobile', device: 'iphone-390' }), { mode: 'fast', categories: ['usability'] })).issues; + const phoneLink = await onPhone({ id: 'l', name: 'l', type: 'link', label: 'Go' }); + check('mobile: a 24px link is a mobile-touch-target error (Phase 32 R2)', phoneLink.some((i) => i.rule === 'mobile-touch-target' && i.nodeId === 'l')); + const phoneNav = await onPhone({ id: 'n', name: 'n', type: 'nav-item', label: 'Go' }); + check('mobile twin: a nav-item is still not a phone tappable', !phoneNav.some((i) => i.rule === 'mobile-touch-target')); + // Phase 32 R1: text-input size "lg" is 44, in the census and the render. + check('R1: desktopTargets measures a lg text-input at 44', desktopTargets({ id: 'i', name: 'i', type: 'text-input', size: 'lg' } as SceneNode)[0].h === 44); + const lgHtml = (() => { const c = canvasWith([{ id: 'i', name: 'i', type: 'text-input', size: 'lg', value: 'x' }], app); return renderToHtml(c.root, 1440, 900, c); })(); + check('R1: a lg text-input renders a 44px field at 14px type', /height: 44px; min-height: 44px;[^"]*font-size: 14px/.test(lgHtml)); } // ── Verify round 1 fixes ─────────────────────────────────────────────────── diff --git a/test/unit/test-overlays.ts b/test/unit/test-overlays.ts index 1e4b30e..96ea1dd 100644 --- a/test/unit/test-overlays.ts +++ b/test/unit/test-overlays.ts @@ -11,6 +11,7 @@ // Usage: npx tsx test/unit/test-overlays.ts import '../env.js'; +import { createHash } from 'node:crypto'; import { evaluateCanvas } from '../../src/evaluate.js'; import { renderToHtml } from '../../src/renderer.js'; import { resolveVariables } from '../../src/variables.js'; @@ -361,5 +362,39 @@ const modal = (extra: Partial = {}): SceneNode => ({ check('twin: without the variant coverage still raises nothing (no demand)', !none.issues.some((i) => i.category === 'coverage') && none.coverage?.missing.length === 0); } +// ── Phase 32 R5/R6: controlSize ──────────────────────────────────────────── +{ + // R6: without controlSize (or at the defaults, or with an invalid value) a + // modal and a toast render byte-identical to 09ec388, on every type. + const BASE = 'e4793bebbbedcc2e3ed925e57f15ddbf754273abc96a159e68ab4f01f1ceb842'; + const pairHash = (surface: Surface, m: object, t: object) => { + const c = canvasWith([ + { id: 'm', name: 'm', type: 'modal', title: 'Delete file?', actions: [{ label: 'Cancel' }, { label: 'Delete', variant: 'primary' }], children: [{ id: 'mt', name: 'mt', type: 'text', content: 'Gone for good.' }], ...m } as SceneNode, + { id: 't', name: 't', type: 'toast', text: 'Saved', action: { label: 'Undo' }, ...t } as SceneNode, + ], surface); + return createHash('sha256').update(renderToHtml(resolveVariables(c.root, c.variables), 1440, 900, c)).digest('hex'); + }; + const surfaces: Surface[] = [{ type: 'web' }, { type: 'mobile', device: 'iphone-390' }, app]; + const variants: Array<[string, object, object]> = [ + ['absent', {}, {}], ['at the defaults', { controlSize: 'sm' }, { controlSize: 'xs' }], + ['invalid', { controlSize: 'xl' }, { controlSize: 44 }], ['an inherited key', { controlSize: 'constructor' }, { controlSize: 'toString' }], + ]; + for (const surface of surfaces) { + for (const [what, m, t] of variants) { + const h = pairHash(surface, m, t); + check(`R6: ${surface.type}, controlSize ${what}: byte-identical to 09ec388`, h === BASE, h); + } + } + const toastNode = (extra: object = {}): SceneNode => ({ id: 't', name: 't', type: 'toast', text: 'Saved', action: { label: 'Undo' }, ...extra } as SceneNode); + const mdHtml = htmlOf(canvasWith([modal({ controlSize: 'md' }), toastNode({ controlSize: 'md' })], app)); + const close = /<[^>]*data-fs-modal-close[^>]*>/.exec(mdHtml)?.[0] ?? ''; + check('R5: controlSize md draws a 44px square close button', /height: 44px/.test(close) && /min-width: 44px/.test(close), close.slice(0, 400)); + const tall = (html: string) => html.match(/<[^>]*data-focusable[^>]*>/g)?.filter((b) => /height: 44px/.test(b)) ?? []; + check('R5: md modal actions, close button and the toast action all render 44px', tall(mdHtml).length === 4, String(tall(mdHtml).length)); + check('R5: their labels follow the size (16px at md)', tall(mdHtml).filter((b) => !/data-fs-modal-close/.test(b)).every((b) => /font-size: 16px/.test(b))); + const defHtml = htmlOf(canvasWith([modal(), toastNode()], app)); + check('R5 twin: by default no overlay control is 44px', tall(defHtml).length === 0); +} + console.log(allPass ? '\nAll checks passed.' : '\nSome checks FAILED.'); process.exit(allPass ? 0 : 1); diff --git a/test/unit/test-phone-targets.ts b/test/unit/test-phone-targets.ts new file mode 100644 index 0000000..e1fb5b8 --- /dev/null +++ b/test/unit/test-phone-targets.ts @@ -0,0 +1,149 @@ +// Phase 32 slice E (FR-E1 to FR-E3, contracts R1 to R7): on a phone the 44px +// census measures a link, a text-input, a modal's close button and actions and +// a toast's action; `size: "lg"` (text-input) and `controlSize: "md"` +// (modal, toast) clear them. Web and desktop-app keep their 24px census. +// +// Usage: npx tsx test/unit/test-phone-targets.ts + +import '../env.js'; +import { evaluateCanvas } from '../../src/evaluate.js'; +import { overlayTargets, desktopTargets, textInputHeight } from '../../src/primitives.js'; +import type { Canvas, SceneNode } from '../../src/types.js'; + +let allPass = true; +function check(name: string, cond: boolean, extra?: string) { + if (!cond) allPass = false; + console.log(`${cond ? 'PASS' : 'FAIL'} ${name}${extra ? ` — ${extra}` : ''}`); +} + +type Surface = { type: 'web' | 'mobile' | 'desktop-app'; device?: string }; +const phone: Surface = { type: 'mobile', device: 'iphone-390' }; +const app: Surface = { type: 'desktop-app', device: 'window-1440' }; +const web: Surface = { type: 'web' }; + +function canvasWith(children: SceneNode[], surface: Surface): Canvas { + const width = surface.type === 'mobile' ? 390 : 1440; + return { + id: 'c', name: 'c', projectId: 'p', components: {}, createdAt: '', lastModified: '', variables: {}, + root: { id: 'document', type: 'document', name: 'Document', width, height: 844, fill: '#FFFFFF', layout: 'vertical', padding: 24, gap: 8, children }, + metadata: { surface }, + } as Canvas; +} + +const touch = async (children: SceneNode[], surface: Surface = phone) => + (await evaluateCanvas(canvasWith(children, surface), { mode: 'fast', categories: ['usability'] })).issues.filter((i) => i.rule === 'mobile-touch-target'); + +const label = (id: string): SceneNode => ({ id, name: id, type: 'text', content: 'Email address' }); +const modal = (extra: Partial = {}): SceneNode => ({ + id: 'm', name: 'm', type: 'modal', title: 'Delete file?', + actions: [{ label: 'Cancel' }, { label: 'Delete', variant: 'destructive' }], + children: [{ id: 'mt', name: 'mt', type: 'text', content: 'This cannot be undone.' }], ...extra, +} as SceneNode); +const toast = (extra: Partial = {}): SceneNode => ({ id: 't', name: 't', type: 'toast', text: 'Saved', action: { label: 'Undo' }, ...extra } as SceneNode); + +// ── R1: text-input lg = 44 ───────────────────────────────────────────────── +{ + const h = (extra: Partial) => textInputHeight({ id: 'i', type: 'text-input', ...extra } as SceneNode); + check('R1: text-input sm 32 / md 40 / lg 44', h({ size: 'sm' }) === 32 && h({}) === 40 && h({ size: 'md' }) === 40 && h({ size: 'lg' }) === 44); + check('R1 twin: xs is not a text-input size (40)', h({ size: 'xs' }) === 40); + check('R1: a multi-line lg input grows past 44 by its rows', h({ size: 'lg', rows: 3 }) === 72 && h({ size: 'lg', rows: 2 }) === 52); + check('R1: desktopTargets measures lg at 44', desktopTargets({ id: 'i', type: 'text-input', size: 'lg' } as SceneNode)[0].h === 44); +} + +// ── R2: link and text-input on a phone ───────────────────────────────────── +{ + const link = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Forgot password?' }]); + check('R2: a default link is a mobile-touch-target error', link.length === 1 && link[0].severity === 'error' && link[0].nodeId === 'l' && /^link has a \?×24px touch target/.test(link[0].message), link.map((i) => i.message).join(' | ')); + check('R2: the link suggestion names height', /height: 44/.test(link[0]?.suggestion ?? ''), link[0]?.suggestion); + const tall = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Forgot password?', height: 44 }]); + check('R2 twin: height: 44 clears the link', tall.length === 0, tall.map((i) => i.message).join(' | ')); + const glyph = await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings', height: 44 }]); + check('R2: a glyph-only link at height 44 still errors on width (14 wide)', glyph.length === 1 && /14×44px/.test(glyph[0].message) && /width: 44/.test(glyph[0].suggestion ?? '') && !/height: 44/.test(glyph[0].suggestion ?? ''), glyph.map((i) => `${i.message} / ${i.suggestion}`).join(' | ')); + const glyphOk = await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings', height: 44, width: 44 }]); + check('R2 twin: a glyph-only link at 44×44 passes', glyphOk.length === 0); + const narrow = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 44, width: 30 }]); + check('R2: a labelled link 30 wide errors on width, suggestion says widen or drop', narrow.length === 1 && /Widen it to 44 or drop its width/.test(narrow[0].suggestion ?? ''), narrow.map((i) => i.suggestion).join(' | ')); + const px = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 44, width: '30px' }]); + check('R2: a link\'s px-string width is read', px.length === 1 && /30×44px/.test(px[0].message)); + + const md = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', placeholder: 'you@example.com' }]); + check('R2: a default (40px) text-input errors on a phone, suggesting size "lg"', md.length === 1 && md[0].nodeId === 'i' && /40px touch target/.test(md[0].message) && /size "lg"/.test(md[0].suggestion ?? ''), md.map((i) => `${i.message} / ${i.suggestion}`).join(' | ')); + const sm = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', size: 'sm' }]); + check('R2: an sm text-input errors', sm.length === 1 && /32px/.test(sm[0].message)); + const lg = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', size: 'lg' }]); + check('R2 twin: size "lg" clears the text-input', lg.length === 0, lg.map((i) => i.message).join(' | ')); + const rows = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', rows: 2 }]); + check('R2 twin: a 2-row text-input (52) passes', rows.length === 0); + const thin = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', size: 'lg', width: 40 }]); + check('R2: a numeric width below 44 errors with the width suggestion', thin.length === 1 && /Widen it to 44/.test(thin[0].suggestion ?? '') && !/size "lg"/.test(thin[0].suggestion ?? '')); + const pxIn = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', size: 'lg', width: '40px' }]); + check('R2: a text-input\'s px-string width is not read (as in the 24px census)', pxIn.length === 0); + + for (const surface of [web, app]) { + const off = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go' }, label('lb'), { id: 'i', name: 'i', type: 'text-input' }, modal(), toast()], surface); + check(`R2 twin: on ${surface.type} none of this raises mobile-touch-target`, off.length === 0); + } + const appIssues = (await evaluateCanvas(canvasWith([{ id: 'i', name: 'i', type: 'text-input', size: 'sm', width: 20 }, label('lb')], app), { mode: 'fast', categories: ['usability'] })).issues; + check('R2 twin: desktop-app keeps the 24px census on a text-input', appIssues.some((i) => i.nodeId === 'i' && /24px floor/.test(i.message))); +} + +// ── R3: disabled targets count on a phone ────────────────────────────────── +{ + const off = await touch([ + { id: 'l', name: 'l', type: 'link', label: 'Go', disabled: true }, + label('lb'), { id: 'i', name: 'i', type: 'text-input', state: 'disabled' }, + modal({ actions: [{ label: 'Delete', variant: 'destructive', disabled: true }] }), + ]); + check('R3: disabled link, text-input and modal action are still measured', ['l', 'i'].every((id) => off.some((i) => i.nodeId === id)) && off.filter((i) => i.nodeId === 'm').length === 2, off.map((i) => i.nodeId).join(',')); +} + +// ── R4: the row rule counts a link or text-input ─────────────────────────── +{ + const row = (extra: SceneNode[]): SceneNode => ({ + id: 'row', name: 'row', type: 'frame', layout: 'horizontal', height: 56, alignItems: 'center', gap: 8, + children: [{ id: 'cb', name: 'cb', type: 'checkbox' }, { id: 'rt', name: 'rt', type: 'text', content: 'Remember me' }, ...extra], + } as SceneNode); + const alone = await touch([row([])]); + check('R4 twin: a lone checkbox in a 56px row passes', alone.length === 0, alone.map((i) => i.message).join(' | ')); + const withInput = await touch([row([{ id: 'i', name: 'i', type: 'text-input', size: 'lg', width: 200 }])]); + check('R4: a checkbox beside a text-input is measured bare', withInput.some((i) => i.nodeId === 'cb') && !withInput.some((i) => i.nodeId === 'i'), withInput.map((i) => i.nodeId).join(',')); + const withLink = await touch([row([{ id: 'l', name: 'l', type: 'link', label: 'Terms', height: 44 }])]); + check('R4: a checkbox beside a link is measured bare', withLink.some((i) => i.nodeId === 'cb') && !withLink.some((i) => i.nodeId === 'l')); + const webRow = (await evaluateCanvas(canvasWith([row([{ id: 'l', name: 'l', type: 'link', label: 'Terms' }])], web), { mode: 'fast', categories: ['usability'] })).issues; + check('R4 twin: on web the row rule is unchanged (no finding on the checkbox)', !webRow.some((i) => i.nodeId === 'cb'), webRow.map((i) => i.message).join(' | ')); +} + +// ── R5/R7: controlSize on modal and toast ────────────────────────────────── +{ + const hs = (n: SceneNode) => JSON.stringify(overlayTargets(n).map((t) => [t.w ?? null, t.h])); + check('R7: default modal targets are 32 (close square)', hs(modal()) === '[[32,32],[null,32],[null,32]]', hs(modal())); + check('R7: controlSize md → 44 (close 44×44)', hs(modal({ controlSize: 'md' })) === '[[44,44],[null,44],[null,44]]'); + check('R7: controlSize xs → 24, lg → 52', hs(modal({ controlSize: 'xs' })) === '[[24,24],[null,24],[null,24]]' && hs(modal({ controlSize: 'lg' })) === '[[52,52],[null,52],[null,52]]'); + check('R7: a toast action defaults to 24, md → 44', overlayTargets(toast())[0].h === 24 && overlayTargets(toast({ controlSize: 'md' }))[0].h === 44); + for (const bad of ['constructor', 'toString', 'xl', 44, { md: true }] as unknown[]) { + const m = modal({ controlSize: bad as SceneNode['controlSize'] }); + const t = toast({ controlSize: bad as SceneNode['controlSize'] }); + check(`R5: controlSize ${JSON.stringify(bad)} falls back to the defaults`, hs(m) === hs(modal()) && overlayTargets(t)[0].h === 24, `${hs(m)} ${overlayTargets(t)[0]?.h}`); + } + + const both = await touch([modal(), toast()]); + check('FR-E3: a default modal (two actions) and a toast with an action are four errors', both.length === 4 && both.filter((i) => i.nodeId === 'm').length === 3 && both.filter((i) => i.nodeId === 't').length === 1, both.map((i) => i.message).join(' | ')); + check('FR-E3: the modal suggestion names controlSize "md" and sheet', both.filter((i) => i.nodeId === 'm').length === 3 && both.filter((i) => i.nodeId === 'm').every((i) => /controlSize: "md"/.test(i.suggestion ?? '') && /sheet/.test(i.suggestion ?? ''))); + check('FR-E3: the close button is reported 32×32', both.some((i) => /^modal close button has a 32×32px/.test(i.message))); + const md = await touch([modal({ controlSize: 'md' }), toast({ controlSize: 'md' })]); + check('FR-E3 twin: controlSize "md" on both clears all four', md.length === 0, md.map((i) => i.message).join(' | ')); + const lg = await touch([modal({ controlSize: 'lg' }), toast({ controlSize: 'lg' })]); + check('FR-E3 twin: "lg" clears too', lg.length === 0); + const toastSm = await touch([modal({ controlSize: 'md' }), toast({ controlSize: 'sm' })]); + check('FR-E3: "sm" on the toast is one error', toastSm.length === 1 && toastSm[0].nodeId === 't' && /32px/.test(toastSm[0].message)); + const ctor = await touch([modal({ controlSize: 'constructor' as SceneNode['controlSize'] }), toast({ controlSize: 44 as unknown as SceneNode['controlSize'] })]); + check('R5: "constructor" and 44 measure as the defaults (four errors)', ctor.length === 4); + const noAction = await touch([toast({ action: undefined })]); + check('twin: a toast without an action has no target', noAction.length === 0); +} + +if (!allPass) { + console.log('\nSome checks FAILED'); + process.exit(1); +} +console.log('\nAll checks passed'); From 735a52ae400e965d37905f85aeece33693cdc75c Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Mon, 23 Nov 2026 14:00:47 +0100 Subject: [PATCH 4/6] Keep a link with a numeric height at least as wide as tall A short labelled link at height 44 rendered 26px wide and the phone census passed it, since its width was unknown. Verify round 1 fixes and docs. --- README.md | 4 +-- VISION.md | 2 +- docs/GUIDELINES.md | 5 +-- docs/specs/PHASE-32-SPEC.md | 7 ++++ src/evaluate.ts | 17 +++++----- src/index.ts | 4 +-- src/primitives.ts | 9 +++-- src/renderer.ts | 6 ++++ .../browser/test-desktop-primitives-render.ts | 26 ++++++++++++++ test/unit/test-desktop-primitives.ts | 12 +++++++ test/unit/test-phone-targets.ts | 34 +++++++++++++++---- 11 files changed, 103 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 70b127d..d3dcc95 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,7 @@ Application screens (`type: "desktop-app"`) are built from eight primitives on t | Type | Key props | What it is | |---|---|---| -| `link` | `label`, `icon`, `iconPosition`, `external`, `ariaLabel`, `state` | A standalone text action, at least 24 tall (on a phone the census wants 44: `height: 44`). With no `label` it hugs its glyphs (14px wide, 30 with `external`) and needs an `ariaLabel` (rendered as `aria-label` and `title`). A `text` node can hold inline links instead: `links: [{ start, end }]` character ranges of its content, drawn underlined and exempt from the 24px floor | +| `link` | `label`, `icon`, `iconPosition`, `external`, `ariaLabel`, `state` | A standalone text action, at least 24 tall; with a numeric `height` never narrower than tall (on a phone the census wants 44: `height: 44`). With no `label` it hugs its glyphs (14px wide, 30 with `external`) and needs an `ariaLabel` (rendered as `aria-label` and `title`). A `text` node can hold inline links instead: `links: [{ start, end }]` character ranges of its content, drawn underlined and exempt from the 24px floor | | `text-input` | `value`, `placeholder`, `icon`, `size` (`sm` 32 / `md` 40 / `lg` 44, the phone size), `rows`, `error` (a message), `disabled`, `state` | A field whose border (`$border-strong` when the design system has it) is its only boundary; `error` draws an icon and the message below and turns the border `$danger` | | `nav-item` | `label`, `icon`, `count`, `dotColor`, `active`, `depth` (0 / 1), `collapsed`, `state` | A 32px sidebar row. `active` draws an `$accent-tint` fill, a 2px `$accent` bar and a heavier label; `collapsed` is the 32×32 rail form, with the label as its accessible name; `dotColor` is an identity dot, never counted as an accent | | `tabs` | `items: [{ label, count?, active?, disabled?, state? }]`, `variant` (`line` / `contained`), `size` (`sm` 32 / `md` 40) | One tablist; each tab is its own target. The active tab gets an indicator (`line`) or an `$accent-tint` fill (`contained`); only the line underline is measured by `desktop-app-state-contrast` | @@ -915,7 +915,7 @@ Every result also carries a **`surface`** field: `{ type, device, source, rulesO | Rule | Category | Severity | Fires on | |---|---|---|---| -| `mobile-touch-target` | usability | error | A tap target below 44px: a control (its target extends to its row only when the row is a horizontal frame holding that one tappable), a `button` (`size: "sm"` is 32, `"xs"` 24), a `list-row`, each `tab-bar` tab and FAB, each `nav-bar` action, a `link` (`height: 44`), a `text-input` (`size: "lg"`), or a `modal`'s close button and actions or a `toast`'s action (`controlSize: "md"`). Primitives are measured by their own box, disabled ones too; nodes inside an instance are judged as rendered and reported on the instance. | +| `mobile-touch-target` | usability | error | A tap target below 44px: a control (its target extends to its row only when the row is a horizontal frame holding that one tappable), a `button` (`size: "sm"` is 32, `"xs"` 24), a `list-row`, each `tab-bar` tab and FAB, each `nav-bar` action, a `link` (`height: 44`), a `text-input` (`size: "lg"`), or a `modal`'s close button and actions or a `toast`'s action (`controlSize: "md"`; the defaults of 32 and 24 fail). A `link` or `text-input` beside a control means the control's row is not its own. Primitives are measured by their own box, disabled ones too; nodes inside an instance are judged as rendered and reported on the instance. | | `mobile-tab-bar` | usability | warning | A `tab-bar` with fewer than 2 or more than 5 tabs (the FAB is not a tab), a tab with no label, or a bar not pinned to the bottom (a `position` override or any `y`). | | `mobile-handbuilt-target` | usability | info | A frame shaped like a tap target (one icon, or an icon plus a label of up to three words) whose box is below 44px; rebuild it as a `button` if it is tappable. | | `mobile-safe-area` | usability | warning | Content under the 47px status-bar or 34px home-indicator inset, or left under a pinned bar. With the root's `safeArea` or pinned chrome the renderer reserves the insets, so fast mode checks positioned content (`absolute`, `fixed`, `sticky` at its stuck `y`) and pinned bars: the scroll's end (or start) must clear a bar you pinned, and the finding names the spacer height to add to your content frame. Without `safeArea`, the first and last content must clear the insets. Padding of 32px or more scales down on a phone, so clear an inset with a spacer frame. A `sheet`'s content is never judged. Detailed mode checks rendered positions and is authoritative. | diff --git a/VISION.md b/VISION.md index b3b5809..9428b9a 100644 --- a/VISION.md +++ b/VISION.md @@ -556,7 +556,7 @@ The mobile attempt (2026-09-07) built one iOS screen end to end on v2.2.0 and go All seven slices are merged and the acceptance re-run passed. The phase is closed. - [x] Follow-up — `link` and `text-input` join the mobile 44px touch census. Phase 31 slice B added both primitives for app screens; on a phone canvas they are not measured today, so a 32px text-input passes silently (done in Phase 32 slice E: both are measured, and `text-input` gained `size: "lg"`, 44) -- [ ] Follow-up — overlay controls on a phone. Phase 31 slice E's `modal` close button and actions (32px) and `toast` action (24px) are drawn at fixed pointer sizes and are not in the mobile 44px touch census, so a modal on a phone canvas passes silently; meeting 44px needs a size option on the overlay (render never depends on type), and the census then measures it. Until then the docs send phone dialogs to `sheet` (done in Phase 32 slice E: `controlSize` on `modal` and `toast`, measured at 44 on a phone) +- [x] Follow-up — overlay controls on a phone. Phase 31 slice E's `modal` close button and actions (32px) and `toast` action (24px) are drawn at fixed pointer sizes and are not in the mobile 44px touch census, so a modal on a phone canvas passes silently; meeting 44px needs a size option on the overlay (render never depends on type), and the census then measures it. Until then the docs send phone dialogs to `sheet` (done in Phase 32 slice E: `controlSize` on `modal` and `toast`, measured at 44 on a phone) _Full spec-driven breakdown in [`docs/specs/PHASE-30-SPEC.md`](docs/specs/PHASE-30-SPEC.md). Deliberately out of scope: an Android profile, tablet and other types, a tappable flag on frames, a thumb-reach rule, interaction and flows, mobile import, and mobile commerce archetypes (those come next, on the anatomy/realisation split this phase creates)._ diff --git a/docs/GUIDELINES.md b/docs/GUIDELINES.md index d75a6b8..65d8471 100644 --- a/docs/GUIDELINES.md +++ b/docs/GUIDELINES.md @@ -55,7 +55,8 @@ On a `mobile` canvas these rules run. Each finding names its rule in a `rule` fi - **`mobile-touch-target`** (usability, **error**, −25 per target). A tap target below 44px in either dimension. - A control (toggle, checkbox, radio, select): the target extends to the control's row only when that row is a horizontal frame holding this one tappable (no other control or tappable primitive; a `link` or `text-input` beside it counts as one). A toggle in a 56px settings row passes; a lone checkbox inside a padded card is measured at its own size. To fix one, grow the control or put it alone in a horizontal row at least 44px tall. - - The tappable primitives, each by its own box (an ancestor's padding never counts): a `button` (24 / 32 / 44 / 52 by `size`, or a larger `height` / `minHeight`; never narrower than tall), so `size: "xs"` and `"sm"` are errors on a phone by design; a `link` (at least 24 tall, its `height` when larger; width judged when it is a number, a px string, or a label-less link hugging its glyphs: give it `height: 44`, or use a `button`); a `text-input` (40 by default, so `size: "lg"`, 44, is the phone size; `sm` is 32; a multi-line one grows by its `rows`); a `modal`'s close button and each action, and a `toast`'s action (32, 32 and 24 by default: give the overlay `controlSize: "md"`, 44); a `list-row` (44, or 56 with a subtitle; a trailing toggle or chevron is part of the row, so the row is the target); each `tab-bar` tab (bar width ÷ slots × 49, where the bar width is its `width` or the artboard's, less 32 for `floating`, and the slots are the tabs plus one for a FAB) and the FAB (56); each `nav-bar` action (44×44). The defaults of `button`, `list-row`, `tab-bar` and `nav-bar` pass; a default `link`, `text-input`, `modal` or `toast` action does not. A link inside a sentence stays a `text` node's `links` range, which is exempt; a `link` node is a standalone link and is measured. + - The tappable primitives, each by its own box (an ancestor's padding never counts): a `button` (24 / 32 / 44 / 52 by `size`, or a larger `height` / `minHeight`; never narrower than tall), so `size: "xs"` and `"sm"` are errors on a phone by design; a `link` (at least 24 tall, its `height` when larger, and with a numeric `height` never narrower than tall, like a button: give it `height: 44`, or use a `button`); a `text-input` (40 by default, so `size: "lg"`, 44, is the phone size; `sm` is 32; a multi-line one is `rows` × 20 + 12 tall, so `rows: 2` is 52 and passes; its width is judged only when it is a number); a `modal`'s close button and each action, and a `toast`'s action (32, 32 and 24 by default: give the overlay `controlSize: "md"`, 44); a `list-row` (44, or 56 with a subtitle; a trailing toggle or chevron is part of the row, so the row is the target); each `tab-bar` tab (bar width ÷ slots × 49, where the bar width is its `width` or the artboard's, less 32 for `floating`, and the slots are the tabs plus one for a FAB) and the FAB (56); each `nav-bar` action (44×44). The defaults of `button`, `list-row`, `tab-bar` and `nav-bar` pass; a default `link`, `text-input`, `modal` or `toast` action does not. A link inside a sentence stays a `text` node's `links` range, which is exempt; a `link` node is a standalone link and is measured. + - Each primitive is judged by its props, never its stretched or text-driven box: a link that a row stretches taller, or whose large `fontSize` makes it taller, still measures its `height` (24 by default), and a text-input's `"10%"` width is not judged. Set the size props. - A disabled target still counts on a phone (the 44px floor is a touch-comfort floor, not WCAG's 24px rule, which exempts inactive targets). - Nodes inside a component instance are judged as they render, and the finding names the instance. - On web and desktop-app canvases the 24px floor applies instead, with WCAG's spacing exception (see [the 24px floor](#the-24px-floor-web-and-desktop-app)). @@ -128,7 +129,7 @@ Mobile keeps its own 44px rule (`mobile-touch-target`), which has no spacing exc Build application screens from these primitives, never from hand-built frames: a frame is not a measured target, and none of the app rules can see it. They sit on the 24 / 32 / 40 / 48 density ladder and take their colours from `$accent`, `$accent-tint`, `$border`, `$border-strong`, `$text-primary`, `$text-secondary` and `$danger` (neutral fallbacks unthemed; `fill`, `stroke`, `color`, `iconColor`, `secondaryColor` override). Labels truncate to one line with an ellipsis and keep their full text as a `title`, so `canvas_stress` reports a designed truncation, not a clip. - **`button` at `size: "xs"`** is the 24px icon button of a dense toolbar. An icon-only button (no `label`) takes `ariaLabel` as its accessible name: it renders `aria-label` and `title` and is never drawn. `xs`, like `sm`, is an error on a phone. -- **`link`** `{ label, icon?, iconPosition?, external?, ariaLabel?, state? }` is a standalone text action, at least 24 tall, and a measured target. Without a `label` it hugs its glyphs (14px wide, 30 with `external`) and takes `ariaLabel` as its name (rendered as `aria-label` and `title`). For a link inside a sentence, keep it in the `text` node: `links: [{ start, end }]` marks character ranges of its `content`, drawn underlined. Inline links are exempt from the 24px floor, as WCAG exempts them. A `text` node also takes `title`, rendered as a tooltip. +- **`link`** `{ label, icon?, iconPosition?, external?, ariaLabel?, state? }` is a standalone text action, at least 24 tall, and a measured target. With a numeric `height` it is never narrower than tall (`min-width`, the label centred when the link has no `width`), so `height: 44` makes even "OK" a 44px phone target. Without a `label` it hugs its glyphs (14px wide, 30 with `external`) and takes `ariaLabel` as its name (rendered as `aria-label` and `title`). For a link inside a sentence, keep it in the `text` node: `links: [{ start, end }]` marks character ranges of its `content`, drawn underlined. Inline links are exempt from the 24px floor, as WCAG exempts them. A `text` node also takes `title`, rendered as a tooltip. - **`text-input`** `{ value?, placeholder?, icon?, size?: "sm" | "md" | "lg", rows?, error?, disabled?, state? }` is a field (32, 40 or 44 tall; `rows` makes it multi-line). `lg` is the phone size: on a `mobile` canvas a field below 44 is a `mobile-touch-target` error. Its border is its only boundary, so it uses `$border-strong` when the design system has one. `error` turns the border `$danger` and draws an icon and the message below the field, so the error is never colour alone. - **`nav-item`** `{ label, icon?, count?, dotColor?, active?, depth?: 0 | 1, collapsed?, state? }` is a 32px sidebar row that spans its sidebar. `active` draws three cues: an `$accent-tint` fill, a 2px `$accent` bar, and a heavier label (and `aria-current`). `collapsed` is the 32×32 rail form, with its label as the accessible name. `dotColor` is an identity dot for a project or label: it is never counted as a competing accent, though the same colour used anywhere else still is. - **`tabs`** `{ items: [{ label, count?, active?, disabled?, state? }], variant?: "line" | "contained", size?: "sm" | "md" }` is one tablist (32 or 40 tall). Each tab is its own target. The active tab gets an underline indicator (`line`) or an `$accent-tint` fill (`contained`, from the node's `fill`) and a heavier label. Only the line underline is measured by `desktop-app-state-contrast`; a contained tab's fill and weight are not. diff --git a/docs/specs/PHASE-32-SPEC.md b/docs/specs/PHASE-32-SPEC.md index 28af541..cab79e8 100644 --- a/docs/specs/PHASE-32-SPEC.md +++ b/docs/specs/PHASE-32-SPEC.md @@ -211,6 +211,13 @@ These fixes were proved red on 2cff888 and green after; no agent re-verified the - **R8: docs.** `sheet` stays the recommendation for a bottom panel; a centred `modal` with `controlSize: "md"` is a valid phone dialog; a toast on a phone takes `controlSize: "md"` when it has an action; a link inside a sentence is a `text` node's `links` range (exempt), a `link` node is a standalone link and is measured *(changed)*. The touch lists in INSTRUCTIONS (`index.ts:87`, `:118`, `:151`), the `canvas_evaluate` docstring, GUIDELINES' mobile-touch-target entry and overlay notes, the `text-input`, `modal` and `toast` docstrings and README rows, README's `mobile-touch-target` rule row and `usability` category row, GUIDELINES' usability line, and VISION's two Phase 30 follow-up lines and slice E box. - **R9: tests.** Unit: `test/unit/test-mobile-primitives.ts` or a new `test/unit/test-phone-targets.ts` (FR-E1 and FR-E3 acceptance on a mobile canvas, each passing case with a failing twin: a default link errors, `height: 44` clears it, a glyph-only link with `height: 44` still errors on width; a `text-input` errors at `md` and `sm`, clears at `lg` and at `rows: 2`; disabled ones still error; a default modal with two actions + a toast with an action = four errors, `controlSize: "md"` on both = none, `"lg"` none, `"sm"` on the toast = one, `"constructor"` and `44` = the defaults' four; a checkbox in a 56px row beside a text-input errors, alone it passes; on web and desktop-app none of this raises `mobile-touch-target`). `test/unit/test-overlays.ts` (`overlayTargets` heights per `controlSize`, the invalid value, and R6 byte-identity against strings pinned from 09ec388). `test/unit/test-desktop-primitives.ts` (`lg` = 44 in `desktopTargets` and the rendered field; the check "mobile: desktop primitives are not phone tappables" flips for `link` and `text-input`). Browser: `test/browser/test-overlays-render.ts` measures the rendered close button and actions at 44 with `controlSize: "md"` and 32 by default, and a toast action at 44. The mobile gates (`test/browser/test-patterns-mobile.ts`, `test/e2e/test-ridgeline.ts`, `test/e2e/test-mobile-rules*.ts`) stay green unchanged. +**Slice E — as built and verify round 1 (recorded 2026-11-23).** Build snapshot f32a8c0; full tier 150/150. Five verifiers (spec conformance, mutation, review and gate attack, docs-steward, cold-reader). Conformance found no violation: 492 renders without `controlSize` or `lg` byte-identical to 09ec388, and 164 web and desktop-app evaluations unchanged. Fixes, each with a test red on f32a8c0: +- **A link with a numeric `height` is never narrower than tall** *(spec change to R2)*. The gate attack rendered a labelled link at `height: 44` 26px wide ("Edit") with no finding: R2 left an unknown width unjudged, and `renderLink` had no min-width. A link with a numeric `height` now renders `min-width: max(24, height)`, as a button does, and centres its content when it sets no `width` (a set width keeps its left-aligned label); the census measures `max(width, height)` when the width is known. A link without a numeric `height` renders byte-identical. On web and desktop-app a glyph-only link with `height: 24` now measures 24 wide, as it renders. The phone suggestion for a link is height alone, since a link below the floor is always too short. +- **Sizes print to one decimal** when rounding would hide a shortfall: a 43.5px target read "44×44px … below the 44px floor". +- **Twins the snapshot lacked:** `controlSize` never read as a token, an array `controlSize` falling back, the exact text-input and toast suggestions and their join. Of 48 mutants, 35 were killed, 4 are equivalent, and the 9 real survivors are killed or were in the link width-suggestion branch the first fix removed. +- **Docs:** the second VISION follow-up line was left unticked; README's rule row gained the row clause and the failing defaults; the multi-line height (`rows` × 20 + 12) and the new link rule are stated wherever the census is. +- **Not fixed, named:** each primitive is judged by its props, not its rendered box. A link a row stretches taller, or whose `fontSize` makes it taller, still measures its `height` (a false error, cleared by setting `height: 44`). A text-input's fluid width (`"10%"`, `calc()`) is not judged (a false pass on a field under 44 wide, which no real layout draws). A modal holding a control, placed inside a row, still makes the row hold two controls (pre-existing, R4). + **Agent surfaces, per slice (the #77 rule).** B: everything FR-B3 lists, plus GUIDELINES' element-states section. C: the `canvas_evaluate` and `canvas_autofix` docstrings, GUIDELINES' autofix list and fix workflow, `apply_structure`'s seeding note (`index.ts:1569`), the tint-layer notes (`index.ts:595-599`, `:1177`, GUIDELINES `:258`, `:379`), and `test-discoverability.ts` for the new rule id. D: the `tabs` and `tree-row` docstrings, the `canvas_evaluate` docstring (`index.ts:2158`, which says `select` is not measured and tree rows draw no mark) and INSTRUCTIONS (`index.ts:89`), GUIDELINES' rule lists (`:105-106`, `:133-134`) and stress list (`:489`), the `canvas_stress` docstring. E: the `text-input`, `modal` and `toast` docstrings, the touch list (GUIDELINES `:57`), the phone-dialog advice (`index.ts:614`, GUIDELINES `:161`), INSTRUCTIONS and the `canvas_evaluate` docstring where they list touch targets. Each slice's PR runs the `docs-steward`. --- diff --git a/src/evaluate.ts b/src/evaluate.ts index 5abd286..17251e8 100644 --- a/src/evaluate.ts +++ b/src/evaluate.ts @@ -2209,6 +2209,10 @@ function primitiveTargets( * TAPPABLE_PRIMITIVES (that would drop them from the 24px census). */ const PHONE_FIELDS = new Set(['link', 'text-input']); +/** A size for a finding: whole pixels, or one decimal when rounding would + * hide a shortfall (43.5 never prints as 44). */ +const pxText = (v: number): number => (Number.isInteger(v) ? v : Math.round(v * 10) / 10); + /** Phase 32 R2/R7 — every touch target a node carries on a phone: the * tappable primitives, a link or text-input, and an overlay's own controls * (a modal's close button and actions, a toast's action, at its controlSize). @@ -2220,13 +2224,10 @@ function phoneTargets( if (TAPPABLE_PRIMITIVES.has(node.type)) return primitiveTargets(node, parentOf, rootWidth); const fixFor = (t: { w?: number; h: number }, tall: string, wide: string) => [t.h < floor ? tall : '', t.w !== undefined && t.w < floor ? wide : ''].filter(Boolean).join(' '); + // A link below the floor is always too short: with a numeric height it is + // never narrower than tall, so height alone clears both dimensions. if (node.type === 'link') { - const labelled = typeof node.label === 'string' ? node.label.trim() !== '' : typeof node.label === 'number'; - return desktopTargets(node).map((t) => ({ - ...t, - fix: fixFor(t, `Give the link height: ${floor}, or make it a button (size "md").`, - labelled || node.width !== undefined ? `Widen it to ${floor} or drop its width.` : `Give it width: ${floor} (it hugs its glyphs).`), - })); + return desktopTargets(node).map((t) => ({ ...t, fix: `Give the link height: ${floor} (it is never narrower than its height), or make it a button (size "md").` })); } if (node.type === 'text-input') { return desktopTargets(node).map((t) => ({ ...t, fix: fixFor(t, 'Use size "lg" (44px).', `Widen it to ${floor} or drop its width (a field spans its container).`) })); @@ -2446,7 +2447,7 @@ function checkUsability(entries: NodeEntry[], rootWidth: number, touch?: { floor severity: 'error', nodeId: node.id, nodeName: node.name, - message: `${t.what} has a ${t.w === undefined ? '?' : Math.round(t.w)}×${Math.round(t.h)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, + message: `${t.what} has a ${t.w === undefined ? '?' : pxText(t.w)}×${pxText(t.h)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, ...(t.fix ? { suggestion: t.fix } : {}), }); } @@ -2468,7 +2469,7 @@ function checkUsability(entries: NodeEntry[], rootWidth: number, touch?: { floor severity: 'error', nodeId: node.id, nodeName: node.name, - message: `${node.type} has a ${Math.round(t.w)}×${Math.round(t.h)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, + message: `${node.type} has a ${pxText(t.w)}×${pxText(t.h)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, suggestion: `Grow the control, or put it alone in a row (a horizontal frame) at least ${touch.floor}px tall — a lone control's row is its target.`, }); } diff --git a/src/index.ts b/src/index.ts index f04389e..a5620bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -595,7 +595,7 @@ Mobile primitives (phone screens — they carry their own sizes, hit areas, and The renderer reserves room for pinned chrome: the root's top/bottom padding is raised to at least the pinned status-bar / tab-bar / home-indicator height, so content never starts or ends under it. Labels truncate to one line with an ellipsis (canvas_stress reports that as designed truncation). Desktop-app primitives (application screens — canvas_create type "desktop-app"; on the 24/32/40/48 density ladder, colours from $accent / $accent-tint / $border / $border-strong / $text-primary / $text-secondary / $danger, neutral fallbacks unthemed; NEVER hand-build them from frames — a hand-built frame is not a measured target): - - link { label, icon?, iconPosition?, external?, ariaLabel?, state? } — a standalone text action, at least 24 tall, measured as a pointer target (on a phone at 44: give it height 44, or use a button). With no label it hugs its glyphs (14px wide, 30 with external) and takes ariaLabel as its name (aria-label + title). A text node can hold INLINE links instead: links: [{ start, end }] character ranges of its content, drawn underlined (inline links are exempt from the 24px floor, as WCAG exempts them). + - link { label, icon?, iconPosition?, external?, ariaLabel?, state? } — a standalone text action, at least 24 tall, measured as a pointer target (on a phone at 44: give it height 44 — with a numeric height a link is never narrower than tall — or use a button). With no label it hugs its glyphs (14px wide, 30 with external) and takes ariaLabel as its name (aria-label + title). A text node can hold INLINE links instead: links: [{ start, end }] character ranges of its content, drawn underlined (inline links are exempt from the 24px floor, as WCAG exempts them). - text-input { value?, placeholder?, icon?, size?: "sm"|"md"|"lg" (32/40/44; lg is the phone size, below 44 is a mobile-touch-target error on a phone), rows? (a multi-line field), error? (a message), disabled?, state? } — its border ($border-strong when the design system has it) is its only boundary; error draws an icon and the message below and colours the border $danger. - nav-item { label, icon?, count?, dotColor? (an identity dot — never counted as an accent), active?, depth?: 0|1, collapsed?, state? } — 32 tall, spans its sidebar; active draws an $accent-tint fill, a 2px $accent bar and a heavier label (aria-current); collapsed is the 32×32 rail form, its label the accessible name. - tabs { items: [{ label, count?, active?, disabled?, state? }], variant?: "line"|"contained", size?: "sm"|"md" (32/40) } — one tablist; each tab is its own pointer target; the active tab gets an indicator (line) or an $accent-tint fill (contained) and a heavier label; desktop-app-state-contrast measures the line underline only, never a contained tab's fill. @@ -2158,7 +2158,7 @@ THE HEURISTIC DIRECTIVE IS THE PRESENTATION GATE. mode: "llm" adds optional dept The result's "genre" field (present whenever cliche ran) makes the genre decision auditable: { active, source ("explicit" param | "provenance" stamp | null), relaxed (tells skipped, by the genre and by the applied preset), notRelaxed ([{ tell, relaxedBy }] — tells still flagging that a DIFFERENT genre would relax), byPreset ({ preset, relaxed } — present when the applied preset relaxed tells on its own, e.g. the material preset) }. active is the canonical genre: an alias reports as its canonical name ("dashboard" → "data", "checkout" → "commerce"). If the score is pinned by tells listed in notRelaxed, the genre is probably wrong — genre follows what the screen is FOR (read screens with the user's own figures → "data"; a screen you complete a purchase on → "commerce"; the Material style → "material" (an editor or admin console is a type, not a genre: declare it with canvas_create / canvas_set_type type "desktop-app")), not what it contains. -The result's "surface" field (always present) reports the canvas TYPE and the rules it selected: { type ("web" | "mobile" | "desktop-app"), device (the profile: a phone such as "iphone-390" on mobile, a window such as "window-1440" on desktop-app, null on web), source ("declared" by canvas_create type / canvas_set_type, or "default" — never declared, judged as web), rulesOn (rule ids the composed type + genre + preset rulesets turned on), rulesOff (rule ids they turned off), conflicts (ids both enabled and disabled — those stay ON) }. On a web canvas rulesOn is ["desktop-app-artboard", "mobile-artboard"] (the base rules, on for every type). On a desktop-app canvas rulesOff lists "type-scale-ratio" (the adjacent font-size ratio check, which tags its warnings with that rule id on web and mobile; dense apps step 12/13/14 on purpose), and desktop-app-artboard (structure, every type) WARNS when a desktop-app canvas is narrower than its window's 1024px minimum, and when a canvas holding a desktop-app primitive (nav-item, tabs, tree-row, menu-row, property-row) never declared its type or is declared mobile — a canvas declared web gets an info instead; an undeclared canvas holding an overlay (tooltip, popover, menu, modal, toast, drawer) warns too, while declared web or mobile canvases may hold overlays. On a desktop-app canvas rulesOn also lists the desktop-app ruleset, each finding tagged with its "rule": desktop-app-target (usability: the 24px floor above, named — fast WARNING, detailed ERROR when the 24px circle reaches a neighbour; an unlabelled link with no width (or "auto") measures its glyphs, 14px wide or 30 with external, on web too), desktop-app-handbuilt-target (usability info, never blocks: a frame below 32px holding one icon, an icon plus a label of ≤3 words, or a bordered padded frame holding one such label — the shape an imported text button takes; never inside a clickable primitive; rebuild it as a button or link if clickable), desktop-app-icon-label (usability WARNING: an icon-only button or link with no ariaLabel, a collapsed nav-item with a blank label), desktop-app-current (usability WARNING: in one pane — a frame with overflow "auto", a modal, a drawer, or the root; each node belongs to its nearest, so give each navigation region its own pane — two active nav-items at one depth, or two or more nav-items with none active; a tabs node with no active tab or more than one; two active tree-rows under one parent; info: a tree with a current row nesting past two levels), desktop-app-type-ladder (typography WARNING, replaces type-scale-ratio: adjacent sizes a 40, JSON.stringify(bars.tpos)); } +// ── Phase 32 round 1: a link with a numeric height is never narrower than tall +{ + const row = (links: SceneNode[]): Canvas => ({ + id: 'c', name: 'c', projectId: 'p', components: {}, variables: {}, createdAt: '', lastModified: '', + root: { id: 'document', type: 'document', name: 'D', width: 390, height: 300, fill: '#FFFFFF', layout: 'vertical', children: [ + { id: 'r', name: 'r', type: 'frame', layout: 'horizontal', gap: 8, alignItems: 'center', children: links }, + { id: 'col', name: 'col', type: 'frame', layout: 'vertical', alignItems: 'center', children: [{ id: 'skip', name: 'skip', type: 'link', label: 'Skip', height: 44 }] }, + ] }, + metadata: { surface: { type: 'mobile', device: 'iphone-390' } }, + } as Canvas); + const c = row([ + { id: 'ok', name: 'ok', type: 'link', label: 'OK', height: 44 }, + { id: 'edit', name: 'edit', type: 'link', label: 'Edit', height: 44 }, + { id: 'gl', name: 'gl', type: 'link', icon: 'settings', ariaLabel: 'Settings', height: 44 }, + { id: 'w30', name: 'w30', type: 'link', label: 'Go', height: 44, width: 30 }, + { id: 'bare', name: 'bare', type: 'link', label: 'OK' }, + ]); + const rects = new Map(); + const index = (r: LayoutRect) => { rects.set(r.nodeId, r); r.children?.forEach(index); }; + (await computeLayout(renderToHtml(c.root, 390, 300, c), undefined, 25, { width: 390, height: 300 })).forEach(index); + const size = (id: string) => `${Math.round(rects.get(id)?.width ?? -1)}×${Math.round(rects.get(id)?.height ?? -1)}`; + check('a short labelled link at height 44 renders at least 44 wide (OK, Edit, Skip in a centred column)', ['ok', 'edit', 'skip'].every((id) => (rects.get(id)?.width ?? 0) >= 44 && rects.get(id)?.height === 44), ['ok', 'edit', 'skip'].map(size).join(' ')); + check('a glyph-only link and a width-30 link at height 44 render 44 wide', size('gl') === '44×44' && size('w30') === '44×44', `${size('gl')} ${size('w30')}`); + check('twin: a link without a height still hugs its label (narrower than 44)', (rects.get('bare')?.width ?? 99) < 44 && rects.get('bare')?.height === 24, size('bare')); +} + await shutdown(); console.log(allPass ? '\nALL PASS' : '\nSOME FAILED'); process.exit(allPass ? 0 : 1); diff --git a/test/unit/test-desktop-primitives.ts b/test/unit/test-desktop-primitives.ts index 5bc2b2e..7498167 100644 --- a/test/unit/test-desktop-primitives.ts +++ b/test/unit/test-desktop-primitives.ts @@ -54,6 +54,18 @@ const html = (n: SceneNode, colors?: Record) => { { const h = html({ id: 'l', name: 'l', type: 'link', label: 'View all', external: true }); check('a link renders at least 24 tall with role=link and its label as a title', /min-height: 24px/.test(h) && /role="link"/.test(h) && /title="View all"/.test(h)); + // Phase 32 round 1: a link with a numeric height is never narrower than + // tall (as a button); one without a height keeps its markup. + const linkStyle = (extra: Partial) => { + const c = canvasWith([{ id: 'lk', name: 'lk', type: 'link', label: 'OK', ...extra } as SceneNode], app); + return /data-node-id="lk"[^>]*style="([^"]*)"/.exec(renderToHtml(c.root, 1440, 900, c))?.[1] ?? ''; + }; + check('a link with height 44 gets min-width 44, centred', /height: 44px; min-width: 44px; justify-content: center/.test(linkStyle({ height: 44 })), linkStyle({ height: 44 })); + check('a link with height 10 renders 24 tall, so min-width 24', /min-width: 24px/.test(linkStyle({ height: 10 })), linkStyle({ height: 10 })); + check('twin: a link without a height has no min-width', !/min-width/.test(linkStyle({})) && !/justify-content/.test(linkStyle({}))); + check('twin: a link with a height and a set width keeps its label left-aligned', /min-width: 44px/.test(linkStyle({ height: 44, width: 200 })) && !/justify-content/.test(linkStyle({ height: 44, width: 200 }))); + check('census: a glyph-only link with height 24 measures 24 wide; without a height, its 14px glyph', desktopTargets({ id: 'g', type: 'link', icon: 'x', height: 24 } as SceneNode)[0].w === 24 && desktopTargets({ id: 'g', type: 'link', icon: 'x' } as SceneNode)[0].w === 14); + check('census: a numeric width below a numeric height measures the height', desktopTargets({ id: 'g', type: 'link', label: 'x', width: 10, height: 30 } as SceneNode)[0].w === 30); const t = html({ id: 't', name: 't', type: 'text', content: 'Read the guide or ask us.', links: [{ start: 9, end: 14 }, { start: 10, end: 12 }, { start: 30, end: 40 }], title: 'Help copy' }); check('inline links underline their ranges; overlapping and out-of-range ones are dropped', (t.match(/data-fs-inline-link/g) ?? []).length === 1 && />guide') + 4)); check('a text node renders its title attribute', /]*title="Help copy"/.test(t)); diff --git a/test/unit/test-phone-targets.ts b/test/unit/test-phone-targets.ts index e1fb5b8..95a8250 100644 --- a/test/unit/test-phone-targets.ts +++ b/test/unit/test-phone-targets.ts @@ -8,6 +8,7 @@ import '../env.js'; import { evaluateCanvas } from '../../src/evaluate.js'; import { overlayTargets, desktopTargets, textInputHeight } from '../../src/primitives.js'; +import { tokenRefs } from '../../src/variables.js'; import type { Canvas, SceneNode } from '../../src/types.js'; let allPass = true; @@ -57,14 +58,20 @@ const toast = (extra: Partial = {}): SceneNode => ({ id: 't', name: ' check('R2: the link suggestion names height', /height: 44/.test(link[0]?.suggestion ?? ''), link[0]?.suggestion); const tall = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Forgot password?', height: 44 }]); check('R2 twin: height: 44 clears the link', tall.length === 0, tall.map((i) => i.message).join(' | ')); + // Round 1 (spec change to R2): a link with a numeric height is never + // narrower than tall, so height 44 clears width too, whatever its width. const glyph = await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings', height: 44 }]); - check('R2: a glyph-only link at height 44 still errors on width (14 wide)', glyph.length === 1 && /14×44px/.test(glyph[0].message) && /width: 44/.test(glyph[0].suggestion ?? '') && !/height: 44/.test(glyph[0].suggestion ?? ''), glyph.map((i) => `${i.message} / ${i.suggestion}`).join(' | ')); - const glyphOk = await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings', height: 44, width: 44 }]); - check('R2 twin: a glyph-only link at 44×44 passes', glyphOk.length === 0); + check('R2: a glyph-only link at height 44 is 44 wide (min-width) and passes', glyph.length === 0, glyph.map((i) => i.message).join(' | ')); + const glyph32 = await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings', height: 32 }]); + check('R2 twin: a glyph-only link at height 32 is 32×32 and errors, suggesting height 44', glyph32.length === 1 && /32×32px/.test(glyph32[0].message) && /height: 44/.test(glyph32[0].suggestion ?? ''), glyph32.map((i) => `${i.message} / ${i.suggestion}`).join(' | ')); + const glyphBare = await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings' }]); + check('R2 twin: a glyph-only link with no height hugs its glyph (14×24) and errors', glyphBare.length === 1 && /14×24px/.test(glyphBare[0].message)); const narrow = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 44, width: 30 }]); - check('R2: a labelled link 30 wide errors on width, suggestion says widen or drop', narrow.length === 1 && /Widen it to 44 or drop its width/.test(narrow[0].suggestion ?? ''), narrow.map((i) => i.suggestion).join(' | ')); - const px = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 44, width: '30px' }]); - check('R2: a link\'s px-string width is read', px.length === 1 && /30×44px/.test(px[0].message)); + check('R2: a labelled link with width 30 and height 44 renders 44 wide and passes', narrow.length === 0, narrow.map((i) => i.message).join(' | ')); + const px = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 32, width: '30px' }]); + check('R2: a link\'s px-string width is read (30px at height 32 measures 32×32)', px.length === 1 && /32×32px/.test(px[0].message), px.map((i) => i.message).join(' | ')); + const half = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 43.5, width: 43.5 }]); + check('R2: a fractional size is printed to one decimal, not rounded up to the floor', half.length === 1 && /43\.5×43\.5px/.test(half[0].message), half.map((i) => i.message).join(' | ')); const md = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', placeholder: 'you@example.com' }]); check('R2: a default (40px) text-input errors on a phone, suggesting size "lg"', md.length === 1 && md[0].nodeId === 'i' && /40px touch target/.test(md[0].message) && /size "lg"/.test(md[0].suggestion ?? ''), md.map((i) => `${i.message} / ${i.suggestion}`).join(' | ')); @@ -142,6 +149,21 @@ const toast = (extra: Partial = {}): SceneNode => ({ id: 't', name: ' check('twin: a toast without an action has no target', noAction.length === 0); } +// ── Verify round 1: mutation survivors ───────────────────────────────────── +{ + check('controlSize is never read as a token ref', tokenRefs({ id: 'm', type: 'modal', controlSize: '$md' } as unknown as SceneNode).length === 0); + const arr = ['md'] as unknown as SceneNode['controlSize']; + check('an array controlSize is the default (not coerced to "md")', overlayTargets(modal({ controlSize: arr }))[0].h === 32 && overlayTargets(toast({ controlSize: arr }))[0].h === 24); + const tall = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', width: 44 }]); + check('a 44-wide md text-input fails on height only (exact suggestion)', tall.length === 1 && tall[0].suggestion === 'Use size "lg" (44px).', tall[0]?.suggestion); + const both = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', size: 'sm', width: 20 }]); + check('a text-input failing both ways gets both fixes, one space apart', both.length === 1 && both[0].suggestion === 'Use size "lg" (44px). Widen it to 44 or drop its width (a field spans its container).', both[0]?.suggestion); + const toastFix = (await touch([toast()]))[0]?.suggestion; + check('the toast suggestion names the toast', toastFix === 'Set controlSize: "md" (44px) on the toast.', toastFix); + const linkFix = (await touch([{ id: 'l', name: 'l', type: 'link', icon: 'settings', ariaLabel: 'Settings', width: 'auto' }]))[0]?.suggestion; + check('a link\'s suggestion is height alone, whatever its width', linkFix === 'Give the link height: 44 (it is never narrower than its height), or make it a button (size "md").', linkFix); +} + if (!allPass) { console.log('\nSome checks FAILED'); process.exit(1); From 551f8e1c7aaf558f34ea5e1c7b49596bbb1e0a4f Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Mon, 23 Nov 2026 14:10:53 +0100 Subject: [PATCH 5/6] Print a decimal only where rounding hides a touch shortfall --- docs/specs/PHASE-32-SPEC.md | 2 +- src/evaluate.ts | 10 +++++----- test/unit/test-phone-targets.ts | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/specs/PHASE-32-SPEC.md b/docs/specs/PHASE-32-SPEC.md index cab79e8..8fddc4b 100644 --- a/docs/specs/PHASE-32-SPEC.md +++ b/docs/specs/PHASE-32-SPEC.md @@ -213,7 +213,7 @@ These fixes were proved red on 2cff888 and green after; no agent re-verified the **Slice E — as built and verify round 1 (recorded 2026-11-23).** Build snapshot f32a8c0; full tier 150/150. Five verifiers (spec conformance, mutation, review and gate attack, docs-steward, cold-reader). Conformance found no violation: 492 renders without `controlSize` or `lg` byte-identical to 09ec388, and 164 web and desktop-app evaluations unchanged. Fixes, each with a test red on f32a8c0: - **A link with a numeric `height` is never narrower than tall** *(spec change to R2)*. The gate attack rendered a labelled link at `height: 44` 26px wide ("Edit") with no finding: R2 left an unknown width unjudged, and `renderLink` had no min-width. A link with a numeric `height` now renders `min-width: max(24, height)`, as a button does, and centres its content when it sets no `width` (a set width keeps its left-aligned label); the census measures `max(width, height)` when the width is known. A link without a numeric `height` renders byte-identical. On web and desktop-app a glyph-only link with `height: 24` now measures 24 wide, as it renders. The phone suggestion for a link is height alone, since a link below the floor is always too short. -- **Sizes print to one decimal** when rounding would hide a shortfall: a 43.5px target read "44×44px … below the 44px floor". +- **Sizes print to one decimal** (rounded down) only when rounding would hide a shortfall: a 43.5px target read "44×44px … below the 44px floor". The first version printed every fraction and moved an existing pin (`test/e2e/test-mobile-rules.ts`, a 41.7px tab read 42); now every other message is unchanged. - **Twins the snapshot lacked:** `controlSize` never read as a token, an array `controlSize` falling back, the exact text-input and toast suggestions and their join. Of 48 mutants, 35 were killed, 4 are equivalent, and the 9 real survivors are killed or were in the link width-suggestion branch the first fix removed. - **Docs:** the second VISION follow-up line was left unticked; README's rule row gained the row clause and the failing defaults; the multi-line height (`rows` × 20 + 12) and the new link rule are stated wherever the census is. - **Not fixed, named:** each primitive is judged by its props, not its rendered box. A link a row stretches taller, or whose `fontSize` makes it taller, still measures its `height` (a false error, cleared by setting `height: 44`). A text-input's fluid width (`"10%"`, `calc()`) is not judged (a false pass on a field under 44 wide, which no real layout draws). A modal holding a control, placed inside a row, still makes the row hold two controls (pre-existing, R4). diff --git a/src/evaluate.ts b/src/evaluate.ts index 17251e8..4850eb8 100644 --- a/src/evaluate.ts +++ b/src/evaluate.ts @@ -2209,9 +2209,9 @@ function primitiveTargets( * TAPPABLE_PRIMITIVES (that would drop them from the 24px census). */ const PHONE_FIELDS = new Set(['link', 'text-input']); -/** A size for a finding: whole pixels, or one decimal when rounding would - * hide a shortfall (43.5 never prints as 44). */ -const pxText = (v: number): number => (Number.isInteger(v) ? v : Math.round(v * 10) / 10); +/** A size for a finding: whole pixels, or one decimal (rounded down) when + * rounding would hide a shortfall (43.5 never prints as 44 below 44). */ +const pxText = (v: number, floor: number): number => (v < floor && Math.round(v) >= floor ? Math.floor(v * 10) / 10 : Math.round(v)); /** Phase 32 R2/R7 — every touch target a node carries on a phone: the * tappable primitives, a link or text-input, and an overlay's own controls @@ -2447,7 +2447,7 @@ function checkUsability(entries: NodeEntry[], rootWidth: number, touch?: { floor severity: 'error', nodeId: node.id, nodeName: node.name, - message: `${t.what} has a ${t.w === undefined ? '?' : pxText(t.w)}×${pxText(t.h)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, + message: `${t.what} has a ${t.w === undefined ? '?' : pxText(t.w, touch.floor)}×${pxText(t.h, touch.floor)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, ...(t.fix ? { suggestion: t.fix } : {}), }); } @@ -2469,7 +2469,7 @@ function checkUsability(entries: NodeEntry[], rootWidth: number, touch?: { floor severity: 'error', nodeId: node.id, nodeName: node.name, - message: `${node.type} has a ${pxText(t.w)}×${pxText(t.h)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, + message: `${node.type} has a ${pxText(t.w, touch.floor)}×${pxText(t.h, touch.floor)}px touch target — below the ${touch.floor}px floor on a phone (Apple HIG; WCAG 2.5.5).`, suggestion: `Grow the control, or put it alone in a row (a horizontal frame) at least ${touch.floor}px tall — a lone control's row is its target.`, }); } diff --git a/test/unit/test-phone-targets.ts b/test/unit/test-phone-targets.ts index 95a8250..c91d240 100644 --- a/test/unit/test-phone-targets.ts +++ b/test/unit/test-phone-targets.ts @@ -72,6 +72,10 @@ const toast = (extra: Partial = {}): SceneNode => ({ id: 't', name: ' check('R2: a link\'s px-string width is read (30px at height 32 measures 32×32)', px.length === 1 && /32×32px/.test(px[0].message), px.map((i) => i.message).join(' | ')); const half = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 43.5, width: 43.5 }]); check('R2: a fractional size is printed to one decimal, not rounded up to the floor', half.length === 1 && /43\.5×43\.5px/.test(half[0].message), half.map((i) => i.message).join(' | ')); + const frac = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 41.7 }]); + check('twin: a fraction that rounds below the floor prints whole (42, as before)', frac.length === 1 && /\?×42px/.test(frac[0].message), frac.map((i) => i.message).join(' | ')); + const near = await touch([{ id: 'l', name: 'l', type: 'link', label: 'Go', height: 43.96 }]); + check('a fraction just under the floor never prints as the floor (43.9)', near.length === 1 && /\?×43\.9px/.test(near[0].message), near.map((i) => i.message).join(' | ')); const md = await touch([label('lb'), { id: 'i', name: 'i', type: 'text-input', placeholder: 'you@example.com' }]); check('R2: a default (40px) text-input errors on a phone, suggesting size "lg"', md.length === 1 && md[0].nodeId === 'i' && /40px touch target/.test(md[0].message) && /size "lg"/.test(md[0].suggestion ?? ''), md.map((i) => `${i.message} / ${i.suggestion}`).join(' | ')); From 27bd08440a50f5fa0ecb3050471ab023600894a0 Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Mon, 23 Nov 2026 14:24:49 +0100 Subject: [PATCH 6/6] Record the slice E verify rounds --- docs/specs/PHASE-32-SPEC.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/specs/PHASE-32-SPEC.md b/docs/specs/PHASE-32-SPEC.md index 8fddc4b..3ba87d1 100644 --- a/docs/specs/PHASE-32-SPEC.md +++ b/docs/specs/PHASE-32-SPEC.md @@ -218,6 +218,8 @@ These fixes were proved red on 2cff888 and green after; no agent re-verified the - **Docs:** the second VISION follow-up line was left unticked; README's rule row gained the row clause and the failing defaults; the multi-line height (`rows` × 20 + 12) and the new link rule are stated wherever the census is. - **Not fixed, named:** each primitive is judged by its props, not its rendered box. A link a row stretches taller, or whose `fontSize` makes it taller, still measures its `height` (a false error, cleared by setting `height: 44`). A text-input's fluid width (`"10%"`, `calc()`) is not judged (a false pass on a field under 44 wide, which no real layout draws). A modal holding a control, placed inside a row, still makes the row hold two controls (pre-existing, R4). +**Slice E — verify round 2 (recorded 2026-11-23).** One verifier on the round-1 fix diff (f32a8c0 → 551f8e1), with every reader of `renderLink`, the `desktopTargets` link case, the `phoneTargets` link branch and `pxText`. No defect: 1,296 links without a numeric height render byte-identical to f32a8c0; over 972 Chrome rects a link with a numeric height is never narrower than tall and the census never measures wider than the render; of 56 phone inputs that went from error to clean, all 56 render at least 44×44, and none newly errors; `pxText` changes only values in [43.5, 44). Named, not fixed (low): a link with `height: 44` in a parent narrower than 44 overflows it, and neither evaluate nor `canvas_stress` reports that (stress compares against a baseline that already overflows); an explicit link `width` below its `height` is now overridden, so such layouts move; on web and desktop-app a link with a numeric height and a width under 24 now passes the 24px floor, as it renders 24 wide. Full tier on 551f8e1: 150/150. + **Agent surfaces, per slice (the #77 rule).** B: everything FR-B3 lists, plus GUIDELINES' element-states section. C: the `canvas_evaluate` and `canvas_autofix` docstrings, GUIDELINES' autofix list and fix workflow, `apply_structure`'s seeding note (`index.ts:1569`), the tint-layer notes (`index.ts:595-599`, `:1177`, GUIDELINES `:258`, `:379`), and `test-discoverability.ts` for the new rule id. D: the `tabs` and `tree-row` docstrings, the `canvas_evaluate` docstring (`index.ts:2158`, which says `select` is not measured and tree rows draw no mark) and INSTRUCTIONS (`index.ts:89`), GUIDELINES' rule lists (`:105-106`, `:133-134`) and stress list (`:489`), the `canvas_stress` docstring. E: the `text-input`, `modal` and `toast` docstrings, the touch list (GUIDELINES `:57`), the phone-dialog advice (`index.ts:614`, GUIDELINES `:161`), INSTRUCTIONS and the `canvas_evaluate` docstring where they list touch targets. Each slice's PR runs the `docs-steward`. ---