@ngbracket/a11y-devtools 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,71 @@
3
3
  All notable changes to `@ngbracket/a11y-devtools` are documented here.
4
4
  This project adheres to [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## 0.10.1
7
+
8
+ ### Fixed
9
+
10
+ - **The JSON report now keeps a failed route's `error`.** Before, a route that
11
+ failed to scan appeared in the JSON as a page with 0 findings, which looks clean.
12
+ Pages now also carry `colorScheme` and `darkOnly` when set.
13
+ - **Baseline: a route that failed in the baseline is skipped** instead of counting
14
+ everything on it as new. Re-record the baseline to cover it.
15
+ - **`ngbr/tab-order-mismatch` no longer flags moving into the next column.** Tab
16
+ going up *and to the right* (from a sidebar into the main content, or across a
17
+ multi-column footer) is normal reading order. Up-and-left, and leftwards on the
18
+ same row, are still flagged. It also now compares where the previous stop *ends*
19
+ with where the next *starts*, using line boxes, so links in wrapped paragraph text
20
+ aren't misread. Found by running the tool on its own docs site. New export type:
21
+ `StopRect`.
22
+ - **`ngbr/unreachable-control` / `ngbr/click-without-key` skip event delegation.** A
23
+ click listener on a container of links or controls (with no interactive role of
24
+ its own) handles clicks on those controls; it isn't a fake button. New export:
25
+ `hasFocusableDescendant`.
26
+
27
+ ## 0.10.0
28
+
29
+ ### Added
30
+
31
+ - **Baseline mode: fail CI only on new issues.** `--baseline <file>` compares a run
32
+ with a previous run's JSON report (from `--out`) and reports what's **new**,
33
+ **fixed** and **unchanged**. With a baseline, `--fail-on` counts only new findings,
34
+ so an app with known issues can turn the gate on today and stop the count going up.
35
+ - A finding's identity is route + rule + owning component + element selector.
36
+ Angular `_ngcontent`/`_nghost` hashes are ignored (they change between builds),
37
+ and so are impact and help text (an axe upgrade rewording a message isn't "new").
38
+ - Matching counts duplicates. A route missing from the baseline is all new. A route
39
+ that fails to scan isn't reported as "fixed".
40
+ - A bad baseline path or a non-report file fails fast (exit 2), before the scan.
41
+ - Markdown gets a "Compared with baseline" section, and new findings are marked. JSON
42
+ gets a `baseline` block (counts + `newFindings`) and remains a valid baseline.
43
+ - New API from `./report`: `diffAgainstBaseline`, `parseBaseline`, `findingKey`, and
44
+ the `BaselineDiff` / `BaselineReport` / `NewFinding` types. `toMarkdown` / `toJson`
45
+ take the diff as an optional second argument.
46
+ - **HTML report.** `--format html` (or `all`) writes one self-contained `.html` file:
47
+ inline CSS, no scripts, no external requests. It's accessible itself (landmarks,
48
+ sequential headings, a real data table, severity as text, AA contrast in light and
49
+ dark), and its own report-mode scan comes back clean. New `toHtml(report, diff?)`
50
+ export.
51
+ - **Dark-mode scanning.** Report mode used to run with the browser's default *light*
52
+ colour scheme, so a dark theme was never switched on or contrast-checked.
53
+ - `--color-scheme light|dark|both` (`colorScheme` in `scanPages`): the browser
54
+ emulates that `prefers-color-scheme`. `both` scans every route twice. Dark pages
55
+ are labelled `/route (dark)` and list only the issues that **don't also** appear
56
+ in light, so findings aren't doubled (`PageReport.darkOnly`). The keyboard-trap walk
57
+ runs once, in the light pass.
58
+ - Class/attribute-toggled themes: `--dark-class <name>` / `--dark-attribute
59
+ <name=value>` (`darkClass` / `darkAttribute`) set that on `<html>` before each
60
+ dark-pass scan. Either implies `both`.
61
+ - Hooks for anything else: `setup(page, { colorScheme })` now runs once per pass
62
+ in a fresh browser context, and the new `beforeScan(page, { colorScheme, route })`
63
+ runs after every route loads.
64
+ - New exports: `findingsNotIn`, `DARK_ONLY_NOTE`, and the `ColorScheme` /
65
+ `ThemeContext` types.
66
+ - `--format` now takes a comma-separated list (`md,json,html`), plus `both` (md + json,
67
+ still the default) and `all`.
68
+ - The real-browser E2E spec now runs the CLI itself: output formats and the baseline
69
+ gate (passes with no new issues, fails on a new serious one, rejects a bad baseline).
70
+
6
71
  ## 0.9.0
7
72
 
8
73
  ### Added
package/README.md CHANGED
@@ -1,294 +1,101 @@
1
1
  # @ngbracket/a11y-devtools
2
2
 
3
- Dev-only, in-app accessibility auditing for Angular that maps each axe violation
4
- back to **the component that rendered it** — so you get
5
- `♿ UserCardComponent — 2 issue(s)`, not a wall of CSS selectors.
3
+ Accessibility auditing for Angular that maps each axe violation back to **the
4
+ component that rendered it**, so you get `♿ UserCardComponent — 2 issue(s)`, not a
5
+ wall of CSS selectors. Run it as a dev overlay while you build, or headless in CI.
6
6
 
7
- The axe-based devtools in this space — [`@axe-core/react`](https://www.npmjs.com/package/@axe-core/react),
8
- [`axe-mode`](https://github.com/raunofreiberg/axe-mode), and
9
- [TanStack's a11y plugin](https://tanstack.com/devtools/latest/docs/plugins/a11y)
10
- (now cross-framework, with an Angular adapter too) — report the DOM node (selector,
11
- HTML, rule id) and highlight it, but we haven't seen one tie a violation back to the
12
- component that rendered it, by name. This does, through Angular's **documented** dev
13
- debug API (`window.ng`) rather than private framework internals.
7
+ **📖 Documentation: [ngbracket.com/tools/a11y-devtools/docs](https://ngbracket.com/tools/a11y-devtools/docs/introduction)**
8
+ (guides, every option and CLI flag, and the rule catalogue).
14
9
 
15
10
  Part of the `@ngbracket` Angular tooling family.
16
11
 
17
- ## Status
18
-
19
- Ships attribution — component **and** directive-level — + axe scan + grouped
20
- console reporter (with a summary line) + the dev-only provider + the visual in-app
21
- overlay (severity-coloured highlights, click-to-scroll) + headless report mode +
22
- **Keyboard & Focus Mode M1 + M2** — tab-order visualisation, keyboard-reachability
23
- findings, and a focus-follow accessibility-tree preview (the part of accessibility
24
- axe can't test).
25
-
26
- ## How the attribution works
27
-
28
- Angular publishes debug helpers on the `window.ng` global in dev mode.
29
- `getOwningComponent(node)` returns the component whose view contains a DOM node,
30
- so any axe-flagged element resolves to its owning component; `getDirectives(node)`
31
- adds the directives applied to that node — including those pulled in via
32
- `hostDirectives` — which are the runtime cases a static ESLint pass can't see.
33
- These helpers exist **only in dev builds** — which is exactly right: the tool is
34
- dev-only, and the global's absence in prod is the signal to no-op.
12
+ ## Features
13
+
14
+ - **Component attribution**: every finding names the Angular component to fix,
15
+ walking past UI-library components (Material, CDK, Nebular, …) to yours. Uses
16
+ Angular's documented dev debug API (`window.ng`).
17
+ - **In-app provider**: rescans as the app settles; grouped console output and an
18
+ optional on-page overlay.
19
+ - **Report mode**: scan many routes headless from the CLI; Markdown, JSON and a
20
+ self-contained HTML report.
21
+ - **CI gating with a baseline**: fail only on *new* issues, so an app with known
22
+ issues can adopt the gate today.
23
+ - **Dark mode**: scan your dark theme too, whether it follows the OS setting, a
24
+ class, an attribute, or custom logic.
25
+ - **Keyboard & Focus Mode**: tab-order visualisation, keyboard findings,
26
+ accessibility-tree preview, and keyboard-trap detection with real Tab presses.
27
+ - **Zero production weight**: a no-op in production; axe-core is never loaded.
35
28
 
36
29
  ## Install
37
30
 
38
31
  ```bash
39
32
  npm i -D @ngbracket/a11y-devtools
40
- ```
41
-
42
- Peer deps: `@angular/core >=18`, `rxjs >=7`.
43
-
44
- ## Usage
45
-
46
- ```ts
47
- // app.config.ts (dev configuration)
48
- import { provideA11yDevtools } from '@ngbracket/a11y-devtools';
49
33
 
50
- export const appConfig = {
51
- providers: [
52
- // ...your providers
53
- provideA11yDevtools(),
54
- ],
55
- };
56
- ```
57
-
58
- It rescans whenever the app settles (zoneless-aware, via `ApplicationRef.isStable`)
59
- and logs violations grouped by owning component. Options:
60
-
61
- ```ts
62
- provideA11yDevtools({
63
- root: () => document.querySelector('main')!, // scan scope; default document
64
- log: true, // grouped console output; default true
65
- overlay: true, // in-app visual highlights over flagged nodes; default false
66
- debounceMs: 500, // quiet window after stabilization before scanning
67
- tags: ['wcag22aa'], // scope the ruleset; default = axe-core's full ruleset
68
- frameworkPrefixes: ['Nb', 'Mat', 'Cdk', 'Mdc'], // UI primitives to attribute past (default)
69
- keyboard: true, // also run the keyboard layer (see below); default false
70
- });
34
+ # for report mode only
35
+ npm i -D playwright && npx playwright install chromium
71
36
  ```
72
37
 
73
- **Framework prefixes.** Attribution walks *past* third-party UI primitives to the app
74
- component that placed them — a `<button nbButton>` with no name is blamed on your
75
- `HeaderComponent`, not `NbButtonComponent`. The default list is `Nb`/`Mat`/`Cdk`/`Mdc`;
76
- override `frameworkPrefixes` to add others (e.g. `['Nb','Mat','Nz','Clr','Ion']` — spread
77
- `DEFAULT_FRAMEWORK_PREFIXES` to extend), or pass `[]` to attribute to the **immediate**
78
- owner (useful when auditing a component library's *own* code). The same option is available
79
- on `scan`, `runA11yScan`, `scanPages`, and the CLI (`--framework-prefixes` / `--no-skip-primitives`).
38
+ Needs Angular 18+.
80
39
 
81
- Findings are grouped by owning component, led by a summary line, and each node's
82
- directives are shown inline:
40
+ ## Quick start
83
41
 
84
- ```text
85
- ♿ a11y-devtools: 2 issue(s) across 1 component(s)
86
- ♿ UserCardComponent — 2 issue(s)
87
- critical · image-alt: Images must have alternative text [via TooltipDirective]
88
- img
89
- https://dequeuniversity.com/rules/axe/4.13/image-alt
90
- serious · color-contrast: Elements must meet minimum contrast
91
- button.save
92
- https://dequeuniversity.com/rules/axe/4.13/color-contrast
93
- ```
94
-
95
- You can also scan on demand:
42
+ While you build:
96
43
 
97
44
  ```ts
98
- import { runA11yScan, scan } from '@ngbracket/a11y-devtools';
99
-
100
- const findings = await runA11yScan(); // scan + grouped log
101
- const raw = await scan(document.body); // findings only
102
- ```
103
-
104
- `scan()` and `runA11yScan()` also take full axe-core run options as a second
105
- argument (`scan(root, { runOnly: … })`) for finer control than the provider's
106
- `tags`.
107
-
108
- ## Report mode (headless, CI-friendly)
109
-
110
- The provider is for while you're developing a page. **Report mode** turns the same
111
- engine on a whole running app from the outside: it drives a headless browser over
112
- your **dev** server, injects the same component-attributed scan, and writes a
113
- report grouped by owning component — with no change to the app under test. It needs
114
- a dev build, because that's what publishes `window.ng` for attribution; against a
115
- production build, attribution falls back to `(unknown component)`.
116
-
117
- Report mode is opt-in and needs Playwright, an **optional peer** you install
118
- yourself (so the base package stays weightless):
119
-
120
- ```bash
121
- npm i -D playwright
122
- npx playwright install chromium
123
- ```
124
-
125
- Start your app (`ng serve`), then point the CLI at it:
126
-
127
- ```bash
128
- # writes a11y.md and a11y.json
129
- npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard --out a11y
130
-
131
- # CI gate: exit non-zero on any serious/critical finding
132
- npx ngbr-a11y-report --base http://localhost:4200 --route / --fail-on serious
133
- ```
134
-
135
- For apps gated behind a login or theme picker, use the programmatic API with a
136
- `setup` hook (run once before the routes are scanned):
137
-
138
- ```ts
139
- import { scanPages, toMarkdown } from '@ngbracket/a11y-devtools/report';
45
+ // app.config.ts
46
+ import { provideA11yDevtools } from '@ngbracket/a11y-devtools';
140
47
 
141
- const report = await scanPages({
142
- baseUrl: 'http://localhost:4200',
143
- routes: ['/pages/dashboard'],
144
- setup: async (page) => {
145
- await page.goto('http://localhost:4200/login');
146
- await page.fill('#email', 'demo@example.com');
147
- await page.click('button[type=submit]');
148
- },
149
- });
150
- console.log(toMarkdown(report));
48
+ export const appConfig: ApplicationConfig = {
49
+ providers: [provideA11yDevtools({ overlay: true, keyboard: true })],
50
+ };
151
51
  ```
152
52
 
153
- The report leads with a summary of **distinct rules vs. raw node-instances** (a
154
- "54" is usually one rule firing dozens of times), then lists findings under each
155
- owning component. When a flagged control is itself a third-party UI primitive
156
- (e.g. `<button nbButton>`), attribution walks past the primitive to the app
157
- component that placed it and notes the primitive as `(via …)`.
158
-
159
- ## Keyboard & Focus Mode (the ~2/3 axe can't test)
160
-
161
- axe covers the machine-testable third of WCAG. **Keyboard & Focus Mode** starts on
162
- the rest — keyboard operability — still naming the component that owns each issue.
163
- Turn it on with `keyboard: true` (provider / `runA11yScan` / `scan` / `scanPages`)
164
- or `--keyboard` on the CLI.
165
-
166
53
  ![Keyboard & Focus Mode over the demo page: numbered tab-order badges (badge 1 in
167
54
  orange flags a positive tabindex) joined by a connector path, severity-coloured
168
55
  finding highlights labelled with their owning component (including the ngbr/*
169
56
  keyboard findings), and the focus-follow accessibility-tree panel showing the
170
57
  focused button's computed role, name and states.](./demo/keyboard-layer-2026-09.png)
171
58
 
172
- It adds:
173
-
174
- - **Tab-order visualisation** (overlay): numbered badges at each tab stop and a
175
- connector path showing the order focus actually moves. A positive-`tabindex` stop
176
- is coloured as a warning, because it hijacks the natural order.
177
- - **Keyboard findings**, grouped and reported exactly like the axe violations:
178
- - `ngbr/unreachable-control` — an interactive element (an ARIA role, or a runtime
179
- `click` listener) that isn't a native control and has no `tabindex >= 0`, so the
180
- keyboard can't reach it.
181
- - `ngbr/click-without-key` — a focusable element with a `(click)` handler but no
182
- keyboard handler, so Enter/Space may not activate it. This is read from
183
- `window.ng.getListeners` — a **runtime** signal a static template lint can't see
184
- (e.g. a handler added via `hostDirectives`).
185
- - `ngbr/tab-order-mismatch` — the tab path jumps against the visual reading order
186
- (needs real layout, so it fires in report-mode / a real browser).
187
- - `ngbr/modal-focus-not-contained` — an open `aria-modal="true"` whose focus isn't
188
- contained: tabbable elements outside it are still reachable, so a keyboard user
189
- can Tab out to the page behind. (A modal that correctly marks the background
190
- `inert` is not flagged, since those elements are no longer tabbable.)
59
+ In CI, against a running `ng serve`:
191
60
 
192
61
  ```bash
193
- # include the keyboard layer in a report-mode run
194
- npx ngbr-a11y-report --base http://localhost:4200 --route / --keyboard
62
+ npx ngbr-a11y-report --base http://localhost:4200 --route / --route /settings \
63
+ --keyboard --baseline a11y-baseline.json --fail-on serious --out a11y --format all
195
64
  ```
196
65
 
197
- **Honesty guardrail:** `click-without-key`, `tab-order-mismatch`,
198
- `modal-focus-not-contained` and `focus-trap` are *heuristics*. They're labelled
199
- "verify manually" and never reported as confirmed failures.
66
+ Next steps, in the docs:
67
+ [Your first scan](https://ngbracket.com/tools/a11y-devtools/docs/first-scan) ·
68
+ [Report mode](https://ngbracket.com/tools/a11y-devtools/docs/report-mode) ·
69
+ [CI gating with a baseline](https://ngbracket.com/tools/a11y-devtools/docs/ci-baseline) ·
70
+ [CLI reference](https://ngbracket.com/tools/a11y-devtools/docs/cli) ·
71
+ [Findings & rules](https://ngbracket.com/tools/a11y-devtools/docs/findings)
200
72
 
201
- ### Keyboard traps (report-mode, M3)
73
+ ## What it can't do
202
74
 
203
- A keyboard trap is focus you can Tab *into* but never Tab *out of*
204
- ([WCAG 2.1.2](https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html)).
205
- You can't find one by reading the DOM. Script makes the trap, by intercepting Tab or
206
- re-focusing on blur, and synthetic key events don't move focus in a browser. So
207
- report-mode presses the **real** Tab key through each route:
208
-
209
- ```bash
210
- npx ngbr-a11y-report --base http://localhost:4200 --route / --focus-traps
211
- ```
212
-
213
- - If focus laps the page (passes `<body>` and comes back round), there's no trap.
214
- - If focus cycles inside part of the page without ever leaving, that's reported as
215
- **`ngbr/focus-trap`**. The finding goes on the element that holds the cycle and
216
- counts the tabbable controls that were never reached. The walk then tries
217
- Shift+Tab: the finding is **serious** if that's stuck too, and **moderate** if
218
- Shift+Tab gets out.
219
- - Focus cycling inside an open `aria-modal` / `<dialog>` is containment working,
220
- so it isn't reported. Consecutive focus on an `<iframe>` (Tab moving inside the
221
- frame) isn't read as a trap either.
222
-
223
- It's a separate flag (`focusTraps: true` in `scanPages`) because it's the one check
224
- that *changes the page*. Pressing Tab can fire focus handlers and open menus, so
225
- it runs after the scan. A widget that deliberately keeps Tab, like a code editor,
226
- is fine if it tells users how to leave (Escape, for example). That's why the finding
227
- says "verify manually".
228
-
229
- ### Accessibility-tree preview (M2)
230
-
231
- With `keyboard: true` **and** `overlay: true`, a panel follows focus: as you Tab, it
232
- shows the focused control's computed **role, accessible name, description, and ARIA
233
- states** — attributed to its owning component. The name and role come from
234
- axe-core's own accessible-name commons (one accname source, shared with the scan),
235
- and a missing accessible name is flagged in warning colour.
236
-
237
- > **Accessibility-tree preview — computed approximation.** This is a *computed*
238
- > name/role/state, an approximation of what assistive tech announces — **not** what
239
- > any one screen reader says. Real output varies by screen reader (NVDA / JAWS /
240
- > VoiceOver), browse vs. focus mode, verbosity, and browser. Use it to catch
241
- > missing names and wrong roles fast; confirm the announcement with a real SR.
242
-
243
- The same computation is available programmatically via `describeElement(el)`
244
- (async — it loads axe on demand), plus the pure `ariaStates(el)` and
245
- `accessibleDescription(el)` helpers.
246
-
247
- ## What it checks (and what it can't)
248
-
249
- Under the hood this is [axe-core](https://github.com/dequelabs/axe-core) — the
250
- scan runs axe's rules and enriches each violation with the owning component. By
251
- default it runs axe-core's full ruleset: the **machine-testable** rules across
252
- **WCAG 2.0, 2.1 and 2.2, Levels A & AA**, plus axe's *best-practice* rules. Scope
253
- it to a single conformance target with `tags` (e.g. `['wcag22aa']`) or
254
- `['wcag21aa', 'best-practice']`.
255
-
256
- Automated checks only cover the part of WCAG a machine can test — on the order of
257
- a third of the success criteria. Many WCAG 2.2 additions have **no automated rule
258
- at all** (target size 2.5.8, dragging 2.5.7, consistent help, redundant entry,
259
- accessible authentication), so a clean run is necessary, not sufficient — the rest
260
- needs keyboard, screen-reader and human testing. (WCAG 3.0 is still an early W3C
261
- draft with a different, non-final model; there's nothing to test against yet.)
262
-
263
- ## Production weight
264
-
265
- In production `provideA11yDevtools()` is a **no-op** and axe-core is never loaded.
266
- axe-core is a **dynamic import**, so it lands in a lazy chunk that prod never
267
- fetches, and the package is `sideEffects: false` so an unused import tree-shakes
268
- away entirely. For a hard guarantee, include the provider only in your dev
269
- bootstrap config (e.g. behind `isDevMode()`).
270
-
271
- This is **enforced in CI**: `src/testing/prod-weight.spec.ts` bundles the entry
272
- with esbuild and walks the module graph — axe-core must be reachable *only*
273
- through a dynamic import, never a static one. Turning `import('axe-core')` into a
274
- static import (or adding a top-level side effect) fails the build.
75
+ Automated checks cover part of WCAG, so a clean run is necessary, not sufficient:
76
+ keyboard, screen-reader and human testing cover the rest. The keyboard findings are
77
+ heuristics, labelled "verify manually". It helps you build toward supporting WCAG
78
+ 2.2 AA; it doesn't certify conformance. See
79
+ [What it checks (and what it can't)](https://ngbracket.com/tools/a11y-devtools/docs/coverage).
275
80
 
276
81
  ## Develop
277
82
 
278
83
  ```bash
279
84
  npm install --legacy-peer-deps
85
+ npm run build # tsc -> dist/ (ESM + .d.ts) + the in-page bundle
280
86
  npm test # vitest + jsdom + Angular TestBed (real axe); the real-browser
281
87
  # E2E spec runs after a build, once `npx playwright install chromium`
282
- npm run build # tsc -> dist/ (ESM + .d.ts)
283
88
  ```
284
89
 
90
+ CI also runs a production-weight guard: a bundle-graph test that fails if axe-core
91
+ ever becomes reachable through a static import.
92
+
285
93
  ## Roadmap
286
94
 
287
95
  ### Planned
288
96
 
289
97
  - Headless "linear walkthrough" — the tab sequence as an SR-ish reading list per
290
98
  route in report-mode (M2's preview is currently overlay-only).
291
- - HTML report + baseline/diff mode for CI.
292
99
  - Per-component filtering and a violation-count badge.
293
100
 
294
101
  ### Done
@@ -301,6 +108,9 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
301
108
  - Dev-only provider.
302
109
  - In-app overlay.
303
110
  - Headless report mode (CLI + `./report`).
111
+ - HTML report output.
112
+ - Baseline/diff mode: CI fails only on new issues.
113
+ - Dark-mode scanning: `--color-scheme`, `--dark-class` / `--dark-attribute`, and theme-aware hooks.
304
114
  - **Keyboard & Focus Mode M1** — tab-order visualisation + keyboard-reachability findings.
305
115
  - **Keyboard & Focus Mode M2** — focus-follow accessibility-tree preview.
306
116
  - **Keyboard & Focus Mode M3** — missing focus-trap detection (uncontained
@@ -1,6 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import { writeFileSync } from 'node:fs';
3
- import { scanPages, toJson, toMarkdown } from '../dist/report/index.js';
2
+ import { readFileSync, writeFileSync } from 'node:fs';
3
+ import {
4
+ diffAgainstBaseline,
5
+ parseBaseline,
6
+ scanPages,
7
+ toHtml,
8
+ toJson,
9
+ toMarkdown,
10
+ } from '../dist/report/index.js';
4
11
 
5
12
  const USAGE = `ngbr-a11y-report — component-attributed a11y scan of a running Angular dev build
6
13
 
@@ -11,11 +18,16 @@ Options:
11
18
  --base <url> Origin of the running dev server (e.g. http://localhost:4200)
12
19
  --route <path> Route to scan; repeat for multiple routes
13
20
  --tags <list> Comma-separated axe tags to scope the ruleset (e.g. wcag22aa,best-practice)
14
- --out <prefix> Write <prefix>.md / <prefix>.json (default: print Markdown to stdout)
15
- --format <fmt> md | json | both (default: both when --out is set)
21
+ --out <prefix> Write <prefix>.md / .json / .html (default: print Markdown to stdout)
22
+ --format <list> Comma-separated: md, json, html — or both (= md,json) or all
23
+ (default: both when --out is set)
16
24
  --wait <ms> Settle time after load before scanning (default 1500)
17
25
  --fail-on <impact> Exit non-zero if any finding is at/above impact
18
- (minor | moderate | serious | critical) — for CI gating
26
+ (minor | moderate | serious | critical) — for CI gating.
27
+ With --baseline, only NEW findings count
28
+ --baseline <file> Compare with a previous run's JSON report (from --out) and
29
+ mark what's new, fixed and unchanged — so CI can fail only
30
+ on regressions while known issues are worked down
19
31
  --framework-prefixes <list>
20
32
  Comma-separated component-name prefixes to treat as
21
33
  third-party UI primitives to walk past during attribution
@@ -29,6 +41,15 @@ Options:
29
41
  --focus-traps Also walk each route with real Tab presses to find keyboard
30
42
  traps — focus that cycles inside part of the page and
31
43
  never moves on (ngbr/focus-trap). Runs after the scan
44
+ --color-scheme <s> light | dark | both — scan with the browser emulating that
45
+ prefers-color-scheme (default light). "both" scans each
46
+ route twice; dark pages list only issues light doesn't have
47
+ --dark-class <name>
48
+ Dark theme toggled by a class: add it to <html> for the
49
+ dark pass (e.g. dark, dark-theme). Implies --color-scheme both
50
+ --dark-attribute <name=value>
51
+ Dark theme toggled by an attribute on <html>, e.g.
52
+ data-bs-theme=dark. Implies --color-scheme both
32
53
  --headed Launch a visible browser (debugging)
33
54
  -h, --help Show this help
34
55
  `;
@@ -48,12 +69,16 @@ function parseArgs(argv) {
48
69
  case '--format': opts.format = next(); break;
49
70
  case '--wait': opts.wait = Number(next()); break;
50
71
  case '--fail-on': opts.failOn = next(); break;
72
+ case '--baseline': opts.baseline = next(); break;
51
73
  case '--framework-prefixes':
52
74
  opts.frameworkPrefixes = next().split(',').map((s) => s.trim()).filter(Boolean);
53
75
  break;
54
76
  case '--no-skip-primitives': opts.frameworkPrefixes = []; break;
55
77
  case '--keyboard': opts.keyboard = true; break;
56
78
  case '--focus-traps': opts.focusTraps = true; break;
79
+ case '--color-scheme': opts.colorScheme = next(); break;
80
+ case '--dark-class': opts.darkClass = next(); break;
81
+ case '--dark-attribute': opts.darkAttribute = next(); break;
57
82
  case '--headed': opts.headed = true; break;
58
83
  case '-h': case '--help': opts.help = true; break;
59
84
  default: console.error(`Unknown argument: ${arg}\n`); opts.help = true;
@@ -69,6 +94,41 @@ if (opts.help || !opts.base || opts.routes.length === 0) {
69
94
  process.exit(opts.help ? 0 : 1);
70
95
  }
71
96
 
97
+ const FORMATS = { md: ['md'], json: ['json'], html: ['html'], both: ['md', 'json'], all: ['md', 'json', 'html'] };
98
+ const formats = new Set();
99
+ for (const name of String(opts.format).split(',').map((s) => s.trim()).filter(Boolean)) {
100
+ if (!FORMATS[name]) {
101
+ process.stderr.write(`Invalid --format "${name}" (use md, json, html, both or all)\n`);
102
+ process.exit(2);
103
+ }
104
+ FORMATS[name].forEach((f) => formats.add(f));
105
+ }
106
+
107
+ if (opts.colorScheme && !['light', 'dark', 'both'].includes(opts.colorScheme)) {
108
+ process.stderr.write(`Invalid --color-scheme "${opts.colorScheme}" (use light, dark or both)\n`);
109
+ process.exit(2);
110
+ }
111
+ let darkAttribute;
112
+ if (opts.darkAttribute) {
113
+ const eq = opts.darkAttribute.indexOf('=');
114
+ if (eq <= 0) {
115
+ process.stderr.write(`Invalid --dark-attribute "${opts.darkAttribute}" (use name=value, e.g. data-bs-theme=dark)\n`);
116
+ process.exit(2);
117
+ }
118
+ darkAttribute = { name: opts.darkAttribute.slice(0, eq), value: opts.darkAttribute.slice(eq + 1) };
119
+ }
120
+
121
+ // Read the baseline before the (slow) scan, so a bad path fails fast.
122
+ let baseline;
123
+ if (opts.baseline) {
124
+ try {
125
+ baseline = parseBaseline(readFileSync(opts.baseline, 'utf8'));
126
+ } catch (err) {
127
+ process.stderr.write(`Can't use --baseline ${opts.baseline}: ${err.message}\n`);
128
+ process.exit(2);
129
+ }
130
+ }
131
+
72
132
  const report = await scanPages({
73
133
  baseUrl: opts.base,
74
134
  routes: opts.routes,
@@ -78,12 +138,21 @@ const report = await scanPages({
78
138
  frameworkPrefixes: opts.frameworkPrefixes,
79
139
  keyboard: opts.keyboard,
80
140
  focusTraps: opts.focusTraps,
141
+ colorScheme: opts.colorScheme,
142
+ darkClass: opts.darkClass,
143
+ darkAttribute,
81
144
  });
82
145
 
83
146
  const allFindings = report.pages.flatMap((p) => p.findings);
84
147
  process.stderr.write(
85
148
  `Scanned ${report.pages.length} route(s) · ${allFindings.length} node-instance(s).\n`,
86
149
  );
150
+ const diff = baseline ? diffAgainstBaseline(report, baseline) : undefined;
151
+ if (diff) {
152
+ process.stderr.write(
153
+ `Compared with baseline: ${diff.added.length} new · ${diff.fixed.length} fixed · ${diff.unchanged} unchanged.\n`,
154
+ );
155
+ }
87
156
  if (allFindings.length > 0 && allFindings.every((f) => f.component === null)) {
88
157
  process.stderr.write(
89
158
  'Note: no component attribution (window.ng absent) — is this a production build? Report mode names components only against a dev build.\n',
@@ -91,16 +160,12 @@ if (allFindings.length > 0 && allFindings.every((f) => f.component === null)) {
91
160
  }
92
161
 
93
162
  if (!opts.out) {
94
- process.stdout.write(toMarkdown(report) + '\n');
163
+ process.stdout.write(toMarkdown(report, diff) + '\n');
95
164
  } else {
96
- const format = opts.format ?? 'both';
97
- if (format === 'md' || format === 'both') {
98
- writeFileSync(`${opts.out}.md`, toMarkdown(report));
99
- process.stderr.write(`Wrote ${opts.out}.md\n`);
100
- }
101
- if (format === 'json' || format === 'both') {
102
- writeFileSync(`${opts.out}.json`, toJson(report));
103
- process.stderr.write(`Wrote ${opts.out}.json\n`);
165
+ const render = { md: toMarkdown, json: toJson, html: toHtml };
166
+ for (const format of formats) {
167
+ writeFileSync(`${opts.out}.${format}`, render[format](report, diff));
168
+ process.stderr.write(`Wrote ${opts.out}.${format}\n`);
104
169
  }
105
170
  }
106
171
 
@@ -110,11 +175,12 @@ if (opts.failOn) {
110
175
  process.stderr.write(`Invalid --fail-on "${opts.failOn}" (use minor|moderate|serious|critical)\n`);
111
176
  process.exit(2);
112
177
  }
113
- const worst = report.pages
114
- .flatMap((p) => p.findings)
115
- .reduce((max, f) => Math.max(max, IMPACT_RANK[f.impact] ?? 0), 0);
178
+ // With a baseline, only regressions fail the gate; known issues don't.
179
+ const gated = diff ? diff.added.map((a) => a.finding) : allFindings;
180
+ const worst = gated.reduce((max, f) => Math.max(max, IMPACT_RANK[f.impact] ?? 0), 0);
116
181
  if (worst >= threshold) {
117
- process.stderr.write(`Failing: found violation(s) at or above "${opts.failOn}".\n`);
182
+ const which = diff ? 'new violation(s)' : 'violation(s)';
183
+ process.stderr.write(`Failing: found ${which} at or above "${opts.failOn}".\n`);
118
184
  process.exit(1);
119
185
  }
120
186
  }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { runA11yScan, type RunOptions } from './runner.js';
3
3
  export { scan, type A11yFinding, type Impact, type ScanOptions } from './scan.js';
4
4
  export { logFindings, type Logger } from './report.js';
5
5
  export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, type NgDebugGlobal, type NgListener, } from './attribution.js';
6
- export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, } from './keyboard/tab-sequence.js';
6
+ export { tabSequence, hasFocusableDescendant, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, type StopRect, } from './keyboard/tab-sequence.js';
7
7
  export { scanKeyboard, type KeyboardScanOptions } from './keyboard/keyboard-scan.js';
8
8
  export { findUncontainedModals, type UncontainedModal } from './keyboard/focus-trap.js';
9
9
  export { createFocusWalkProbe, detectTabTrap, type FocusObservation, type FocusWalkProbe, type TabWalkVerdict, } from './keyboard/focus-walk.js';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { runA11yScan } from './runner.js';
3
3
  export { scan } from './scan.js';
4
4
  export { logFindings } from './report.js';
5
5
  export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, } from './attribution.js';
6
- export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
6
+ export { tabSequence, hasFocusableDescendant, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
7
7
  export { scanKeyboard } from './keyboard/keyboard-scan.js';
8
8
  export { findUncontainedModals } from './keyboard/focus-trap.js';
9
9
  export { createFocusWalkProbe, detectTabTrap, } from './keyboard/focus-walk.js';