@ngbracket/a11y-devtools 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/README.md +146 -16
- package/bin/ngbr-a11y-report.mjs +89 -18
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inpage.global.js +331 -231
- package/dist/inpage.js +4 -0
- package/dist/keyboard/focus-walk.d.ts +55 -0
- package/dist/keyboard/focus-walk.js +147 -0
- package/dist/keyboard/keyboard-scan.d.ts +4 -0
- package/dist/keyboard/keyboard-scan.js +3 -2
- package/dist/report/baseline.d.ts +61 -0
- package/dist/report/baseline.js +96 -0
- package/dist/report/format.d.ts +27 -4
- package/dist/report/format.js +56 -12
- package/dist/report/headless.d.ts +51 -4
- package/dist/report/headless.js +128 -19
- package/dist/report/html.d.ts +4 -0
- package/dist/report/html.js +168 -0
- package/dist/report/index.d.ts +4 -2
- package/dist/report/index.js +4 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,75 @@
|
|
|
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.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **Baseline mode: fail CI only on new issues.** `--baseline <file>` compares a run
|
|
11
|
+
with a previous run's JSON report (from `--out`) and reports what's **new**,
|
|
12
|
+
**fixed** and **unchanged**. With a baseline, `--fail-on` counts only new findings,
|
|
13
|
+
so an app with known issues can turn the gate on today and stop the count going up.
|
|
14
|
+
- A finding's identity is route + rule + owning component + element selector.
|
|
15
|
+
Angular `_ngcontent`/`_nghost` hashes are ignored (they change between builds),
|
|
16
|
+
and so are impact and help text (an axe upgrade rewording a message isn't "new").
|
|
17
|
+
- Matching counts duplicates. A route missing from the baseline is all new. A route
|
|
18
|
+
that fails to scan isn't reported as "fixed".
|
|
19
|
+
- A bad baseline path or a non-report file fails fast (exit 2), before the scan.
|
|
20
|
+
- Markdown gets a "Compared with baseline" section, and new findings are marked. JSON
|
|
21
|
+
gets a `baseline` block (counts + `newFindings`) and remains a valid baseline.
|
|
22
|
+
- New API from `./report`: `diffAgainstBaseline`, `parseBaseline`, `findingKey`, and
|
|
23
|
+
the `BaselineDiff` / `BaselineReport` / `NewFinding` types. `toMarkdown` / `toJson`
|
|
24
|
+
take the diff as an optional second argument.
|
|
25
|
+
- **HTML report.** `--format html` (or `all`) writes one self-contained `.html` file:
|
|
26
|
+
inline CSS, no scripts, no external requests. It's accessible itself (landmarks,
|
|
27
|
+
sequential headings, a real data table, severity as text, AA contrast in light and
|
|
28
|
+
dark), and its own report-mode scan comes back clean. New `toHtml(report, diff?)`
|
|
29
|
+
export.
|
|
30
|
+
- **Dark-mode scanning.** Report mode used to run with the browser's default *light*
|
|
31
|
+
colour scheme, so a dark theme was never switched on or contrast-checked.
|
|
32
|
+
- `--color-scheme light|dark|both` (`colorScheme` in `scanPages`): the browser
|
|
33
|
+
emulates that `prefers-color-scheme`. `both` scans every route twice. Dark pages
|
|
34
|
+
are labelled `/route (dark)` and list only the issues that **don't also** appear
|
|
35
|
+
in light, so findings aren't doubled (`PageReport.darkOnly`). The keyboard-trap walk
|
|
36
|
+
runs once, in the light pass.
|
|
37
|
+
- Class/attribute-toggled themes: `--dark-class <name>` / `--dark-attribute
|
|
38
|
+
<name=value>` (`darkClass` / `darkAttribute`) set that on `<html>` before each
|
|
39
|
+
dark-pass scan. Either implies `both`.
|
|
40
|
+
- Hooks for anything else: `setup(page, { colorScheme })` now runs once per pass
|
|
41
|
+
in a fresh browser context, and the new `beforeScan(page, { colorScheme, route })`
|
|
42
|
+
runs after every route loads.
|
|
43
|
+
- New exports: `findingsNotIn`, `DARK_ONLY_NOTE`, and the `ColorScheme` /
|
|
44
|
+
`ThemeContext` types.
|
|
45
|
+
- `--format` now takes a comma-separated list (`md,json,html`), plus `both` (md + json,
|
|
46
|
+
still the default) and `all`.
|
|
47
|
+
- The real-browser E2E spec now runs the CLI itself: output formats and the baseline
|
|
48
|
+
gate (passes with no new issues, fails on a new serious one, rejects a bad baseline).
|
|
49
|
+
|
|
50
|
+
## 0.9.0
|
|
51
|
+
|
|
52
|
+
### Added
|
|
53
|
+
|
|
54
|
+
- **Keyboard & Focus Mode, M3 (part 2): keyboard-trap detection with real Tab
|
|
55
|
+
presses.** New opt-in report-mode flag `--focus-traps` (`focusTraps: true` in
|
|
56
|
+
`scanPages`). It walks each route with real Tab key presses and reports
|
|
57
|
+
**`ngbr/focus-trap`** when focus cycles inside part of the page and never moves on
|
|
58
|
+
([WCAG 2.1.2 No Keyboard Trap](https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html)).
|
|
59
|
+
The finding goes on the element holding the cycle and counts the controls that
|
|
60
|
+
were never reached. It's **serious** when Shift+Tab is trapped too, and
|
|
61
|
+
**moderate** when Shift+Tab escapes.
|
|
62
|
+
- Focus cycling inside an open `aria-modal` / `<dialog>` is containment, not a
|
|
63
|
+
trap, so it isn't reported. Repeated focus on an `<iframe>` (tabbing inside the
|
|
64
|
+
frame) isn't read as a trap.
|
|
65
|
+
- The walk runs after the scan, since pressing Tab can change page state.
|
|
66
|
+
- New public API: `detectTabTrap` (pure walk classifier), `createFocusWalkProbe`,
|
|
67
|
+
and the `FocusObservation` / `TabWalkVerdict` / `FocusWalkProbe` types.
|
|
68
|
+
- **Honesty guardrail:** a candidate, labelled "verify manually". A widget that
|
|
69
|
+
keeps Tab on purpose (a code editor) is fine if it documents another exit.
|
|
70
|
+
- **Real-browser E2E test.** `src/testing/e2e-report.spec.ts` drives the built
|
|
71
|
+
report-mode through Chromium over local fixture pages: axe, layout-dependent
|
|
72
|
+
tab order, and the trap walk. CI now installs Chromium so it runs there. It
|
|
73
|
+
skips itself when `dist/` or a Playwright Chromium is missing.
|
|
74
|
+
|
|
6
75
|
## 0.8.0
|
|
7
76
|
|
|
8
77
|
### Added
|
package/README.md
CHANGED
|
@@ -18,10 +18,11 @@ Part of the `@ngbracket` Angular tooling family.
|
|
|
18
18
|
|
|
19
19
|
Ships attribution — component **and** directive-level — + axe scan + grouped
|
|
20
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
overlay (severity-coloured highlights, click-to-scroll) + headless report mode
|
|
22
|
+
(Markdown / JSON / HTML, with a baseline so CI fails only on new issues) +
|
|
23
|
+
**Keyboard & Focus Mode** — tab-order visualisation, keyboard-reachability
|
|
24
|
+
findings, a focus-follow accessibility-tree preview, and focus-trap detection (the
|
|
25
|
+
part of accessibility axe can't test).
|
|
25
26
|
|
|
26
27
|
## How the attribution works
|
|
27
28
|
|
|
@@ -128,10 +129,93 @@ Start your app (`ng serve`), then point the CLI at it:
|
|
|
128
129
|
# writes a11y.md and a11y.json
|
|
129
130
|
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard --out a11y
|
|
130
131
|
|
|
132
|
+
# …or pick formats: md, json, html (comma-separated), both (= md,json) or all
|
|
133
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --out a11y --format all
|
|
134
|
+
|
|
131
135
|
# CI gate: exit non-zero on any serious/critical finding
|
|
132
136
|
npx ngbr-a11y-report --base http://localhost:4200 --route / --fail-on serious
|
|
133
137
|
```
|
|
134
138
|
|
|
139
|
+
### HTML report
|
|
140
|
+
|
|
141
|
+
`--format html` (or `all`) writes one self-contained `.html` file. It has no
|
|
142
|
+
scripts and makes no external requests, so you can attach it to a CI run, email it,
|
|
143
|
+
or open it offline. It has the same content as the Markdown report, and it's
|
|
144
|
+
accessible itself: landmarks, a sequential heading outline, a real data table,
|
|
145
|
+
severity written as text (not colour alone), and AA contrast in light and dark
|
|
146
|
+
mode. Its own report-mode scan comes back clean.
|
|
147
|
+
|
|
148
|
+
### Dark mode (and other colour schemes)
|
|
149
|
+
|
|
150
|
+
By default the headless browser reports a **light** colour-scheme preference, so a
|
|
151
|
+
dark theme is never switched on and its contrast is never checked. Pick the
|
|
152
|
+
scheme(s) to scan with `--color-scheme`:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# dark theme driven by prefers-color-scheme (the OS setting)
|
|
156
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --color-scheme both
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
- `light` (default) or `dark` scans once in that scheme. Dark pages are labelled
|
|
160
|
+
`/route (dark)`.
|
|
161
|
+
- `both` scans each route twice. To avoid listing everything twice, the dark page
|
|
162
|
+
shows only the issues that **don't also** appear in light mode (typically contrast
|
|
163
|
+
problems specific to the dark palette).
|
|
164
|
+
|
|
165
|
+
Many apps switch themes with a class or attribute instead of the OS setting. For
|
|
166
|
+
those, tell report mode what to set on `<html>` for the dark pass (either flag
|
|
167
|
+
implies `--color-scheme both`):
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --dark-class dark # Tailwind-style
|
|
171
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --dark-attribute data-bs-theme=dark # Bootstrap
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
For anything else (a theme picker, a setting in localStorage, a class on `<body>`),
|
|
175
|
+
use the programmatic hooks. Both receive the pass's `colorScheme`:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
await scanPages({
|
|
179
|
+
baseUrl: 'http://localhost:4200',
|
|
180
|
+
routes: ['/', '/settings'],
|
|
181
|
+
colorScheme: 'both',
|
|
182
|
+
// once per pass, e.g. pick the theme in a persisted setting
|
|
183
|
+
setup: async (page, { colorScheme }) => {
|
|
184
|
+
await page.evaluate((s) => localStorage.setItem('theme', s), colorScheme);
|
|
185
|
+
},
|
|
186
|
+
// after every route loads, for a theme that doesn't persist between pages
|
|
187
|
+
beforeScan: async (page, { colorScheme }) => {
|
|
188
|
+
if (colorScheme === 'dark') await page.click('button[aria-label="Dark theme"]');
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Baseline: fail CI only on new issues
|
|
194
|
+
|
|
195
|
+
An app with a backlog of known issues can't turn on `--fail-on` without every build
|
|
196
|
+
failing. A **baseline** fixes that. Save one run's JSON report, commit it, and
|
|
197
|
+
compare later runs against it:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# once: record today's state (commit a11y-baseline.json)
|
|
201
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard \
|
|
202
|
+
--out a11y-baseline --format json
|
|
203
|
+
|
|
204
|
+
# in CI: fail only on findings that aren't in the baseline
|
|
205
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard \
|
|
206
|
+
--baseline a11y-baseline.json --fail-on serious --out a11y --format all
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
- With `--baseline`, `--fail-on` counts only **new** findings. Known ones don't fail
|
|
210
|
+
the build, and the report shows what's **new**, **fixed** and **unchanged**.
|
|
211
|
+
- A finding's identity is its route, rule, owning component and element selector.
|
|
212
|
+
Angular's per-build `_ngcontent-…` style hashes are ignored, and so is reworded help
|
|
213
|
+
text after an axe upgrade.
|
|
214
|
+
- A route the baseline never scanned counts as entirely new, so re-record the
|
|
215
|
+
baseline when you add routes. A route that fails to scan isn't reported as "fixed".
|
|
216
|
+
- To ratchet down, re-record the baseline after fixing issues. The JSON from any run
|
|
217
|
+
(including a `--baseline` run) is itself a valid baseline.
|
|
218
|
+
|
|
135
219
|
For apps gated behind a login or theme picker, use the programmatic API with a
|
|
136
220
|
`setup` hook (run once before the routes are scanned):
|
|
137
221
|
|
|
@@ -150,6 +234,10 @@ const report = await scanPages({
|
|
|
150
234
|
console.log(toMarkdown(report));
|
|
151
235
|
```
|
|
152
236
|
|
|
237
|
+
The same pieces are exported for your own pipeline: `toJson`, `toHtml`,
|
|
238
|
+
`parseBaseline` and `diffAgainstBaseline` (pass the diff as the second argument to
|
|
239
|
+
`toMarkdown` / `toJson` / `toHtml`).
|
|
240
|
+
|
|
153
241
|
The report leads with a summary of **distinct rules vs. raw node-instances** (a
|
|
154
242
|
"54" is usually one rule firing dozens of times), then lists findings under each
|
|
155
243
|
owning component. When a flagged control is itself a third-party UI primitive
|
|
@@ -194,8 +282,37 @@ It adds:
|
|
|
194
282
|
npx ngbr-a11y-report --base http://localhost:4200 --route / --keyboard
|
|
195
283
|
```
|
|
196
284
|
|
|
197
|
-
**Honesty guardrail:** `click-without-key
|
|
198
|
-
|
|
285
|
+
**Honesty guardrail:** `click-without-key`, `tab-order-mismatch`,
|
|
286
|
+
`modal-focus-not-contained` and `focus-trap` are *heuristics*. They're labelled
|
|
287
|
+
"verify manually" and never reported as confirmed failures.
|
|
288
|
+
|
|
289
|
+
### Keyboard traps (report-mode, M3)
|
|
290
|
+
|
|
291
|
+
A keyboard trap is focus you can Tab *into* but never Tab *out of*
|
|
292
|
+
([WCAG 2.1.2](https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html)).
|
|
293
|
+
You can't find one by reading the DOM. Script makes the trap, by intercepting Tab or
|
|
294
|
+
re-focusing on blur, and synthetic key events don't move focus in a browser. So
|
|
295
|
+
report-mode presses the **real** Tab key through each route:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --focus-traps
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
- If focus laps the page (passes `<body>` and comes back round), there's no trap.
|
|
302
|
+
- If focus cycles inside part of the page without ever leaving, that's reported as
|
|
303
|
+
**`ngbr/focus-trap`**. The finding goes on the element that holds the cycle and
|
|
304
|
+
counts the tabbable controls that were never reached. The walk then tries
|
|
305
|
+
Shift+Tab: the finding is **serious** if that's stuck too, and **moderate** if
|
|
306
|
+
Shift+Tab gets out.
|
|
307
|
+
- Focus cycling inside an open `aria-modal` / `<dialog>` is containment working,
|
|
308
|
+
so it isn't reported. Consecutive focus on an `<iframe>` (Tab moving inside the
|
|
309
|
+
frame) isn't read as a trap either.
|
|
310
|
+
|
|
311
|
+
It's a separate flag (`focusTraps: true` in `scanPages`) because it's the one check
|
|
312
|
+
that *changes the page*. Pressing Tab can fire focus handlers and open menus, so
|
|
313
|
+
it runs after the scan. A widget that deliberately keeps Tab, like a code editor,
|
|
314
|
+
is fine if it tells users how to leave (Escape, for example). That's why the finding
|
|
315
|
+
says "verify manually".
|
|
199
316
|
|
|
200
317
|
### Accessibility-tree preview (M2)
|
|
201
318
|
|
|
@@ -248,22 +365,35 @@ static import (or adding a top-level side effect) fails the build.
|
|
|
248
365
|
|
|
249
366
|
```bash
|
|
250
367
|
npm install --legacy-peer-deps
|
|
251
|
-
npm test # vitest + jsdom + Angular TestBed (real axe)
|
|
368
|
+
npm test # vitest + jsdom + Angular TestBed (real axe); the real-browser
|
|
369
|
+
# E2E spec runs after a build, once `npx playwright install chromium`
|
|
252
370
|
npm run build # tsc -> dist/ (ESM + .d.ts)
|
|
253
371
|
```
|
|
254
372
|
|
|
255
373
|
## Roadmap
|
|
256
374
|
|
|
257
|
-
|
|
258
|
-
|
|
375
|
+
### Planned
|
|
376
|
+
|
|
259
377
|
- Headless "linear walkthrough" — the tab sequence as an SR-ish reading list per
|
|
260
378
|
route in report-mode (M2's preview is currently overlay-only).
|
|
261
|
-
- HTML report + baseline/diff mode for CI.
|
|
262
379
|
- Per-component filtering and a violation-count badge.
|
|
263
380
|
|
|
264
|
-
Done
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
381
|
+
### Done
|
|
382
|
+
|
|
383
|
+
- Component attribution — the nearest app-owned component, walking past UI primitives.
|
|
384
|
+
- Directive and `hostDirectives` attribution.
|
|
385
|
+
- Configurable framework prefixes.
|
|
386
|
+
- axe scan.
|
|
387
|
+
- Grouped console reporter.
|
|
388
|
+
- Dev-only provider.
|
|
389
|
+
- In-app overlay.
|
|
390
|
+
- Headless report mode (CLI + `./report`).
|
|
391
|
+
- HTML report output.
|
|
392
|
+
- Baseline/diff mode: CI fails only on new issues.
|
|
393
|
+
- Dark-mode scanning: `--color-scheme`, `--dark-class` / `--dark-attribute`, and theme-aware hooks.
|
|
394
|
+
- **Keyboard & Focus Mode M1** — tab-order visualisation + keyboard-reachability findings.
|
|
395
|
+
- **Keyboard & Focus Mode M2** — focus-follow accessibility-tree preview.
|
|
396
|
+
- **Keyboard & Focus Mode M3** — missing focus-trap detection (uncontained
|
|
397
|
+
`aria-modal`) and the keyboard-trap walk with real Tab presses.
|
|
398
|
+
- CI production-weight guard.
|
|
399
|
+
- Real-browser E2E test.
|
package/bin/ngbr-a11y-report.mjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { writeFileSync } from 'node:fs';
|
|
3
|
-
import {
|
|
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 /
|
|
15
|
-
--format <
|
|
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
|
|
@@ -26,6 +38,18 @@ Options:
|
|
|
26
38
|
--keyboard Also run the keyboard layer: heuristic ngbr/* findings for
|
|
27
39
|
keyboard-unreachable controls, click-without-keyboard
|
|
28
40
|
handlers, and visual-vs-tab-order mismatches
|
|
41
|
+
--focus-traps Also walk each route with real Tab presses to find keyboard
|
|
42
|
+
traps — focus that cycles inside part of the page and
|
|
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
|
|
29
53
|
--headed Launch a visible browser (debugging)
|
|
30
54
|
-h, --help Show this help
|
|
31
55
|
`;
|
|
@@ -45,11 +69,16 @@ function parseArgs(argv) {
|
|
|
45
69
|
case '--format': opts.format = next(); break;
|
|
46
70
|
case '--wait': opts.wait = Number(next()); break;
|
|
47
71
|
case '--fail-on': opts.failOn = next(); break;
|
|
72
|
+
case '--baseline': opts.baseline = next(); break;
|
|
48
73
|
case '--framework-prefixes':
|
|
49
74
|
opts.frameworkPrefixes = next().split(',').map((s) => s.trim()).filter(Boolean);
|
|
50
75
|
break;
|
|
51
76
|
case '--no-skip-primitives': opts.frameworkPrefixes = []; break;
|
|
52
77
|
case '--keyboard': opts.keyboard = true; break;
|
|
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;
|
|
53
82
|
case '--headed': opts.headed = true; break;
|
|
54
83
|
case '-h': case '--help': opts.help = true; break;
|
|
55
84
|
default: console.error(`Unknown argument: ${arg}\n`); opts.help = true;
|
|
@@ -65,6 +94,41 @@ if (opts.help || !opts.base || opts.routes.length === 0) {
|
|
|
65
94
|
process.exit(opts.help ? 0 : 1);
|
|
66
95
|
}
|
|
67
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
|
+
|
|
68
132
|
const report = await scanPages({
|
|
69
133
|
baseUrl: opts.base,
|
|
70
134
|
routes: opts.routes,
|
|
@@ -73,12 +137,22 @@ const report = await scanPages({
|
|
|
73
137
|
headed: opts.headed,
|
|
74
138
|
frameworkPrefixes: opts.frameworkPrefixes,
|
|
75
139
|
keyboard: opts.keyboard,
|
|
140
|
+
focusTraps: opts.focusTraps,
|
|
141
|
+
colorScheme: opts.colorScheme,
|
|
142
|
+
darkClass: opts.darkClass,
|
|
143
|
+
darkAttribute,
|
|
76
144
|
});
|
|
77
145
|
|
|
78
146
|
const allFindings = report.pages.flatMap((p) => p.findings);
|
|
79
147
|
process.stderr.write(
|
|
80
148
|
`Scanned ${report.pages.length} route(s) · ${allFindings.length} node-instance(s).\n`,
|
|
81
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
|
+
}
|
|
82
156
|
if (allFindings.length > 0 && allFindings.every((f) => f.component === null)) {
|
|
83
157
|
process.stderr.write(
|
|
84
158
|
'Note: no component attribution (window.ng absent) — is this a production build? Report mode names components only against a dev build.\n',
|
|
@@ -86,16 +160,12 @@ if (allFindings.length > 0 && allFindings.every((f) => f.component === null)) {
|
|
|
86
160
|
}
|
|
87
161
|
|
|
88
162
|
if (!opts.out) {
|
|
89
|
-
process.stdout.write(toMarkdown(report) + '\n');
|
|
163
|
+
process.stdout.write(toMarkdown(report, diff) + '\n');
|
|
90
164
|
} else {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
writeFileSync(`${opts.out}
|
|
94
|
-
process.stderr.write(`Wrote ${opts.out}
|
|
95
|
-
}
|
|
96
|
-
if (format === 'json' || format === 'both') {
|
|
97
|
-
writeFileSync(`${opts.out}.json`, toJson(report));
|
|
98
|
-
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`);
|
|
99
169
|
}
|
|
100
170
|
}
|
|
101
171
|
|
|
@@ -105,11 +175,12 @@ if (opts.failOn) {
|
|
|
105
175
|
process.stderr.write(`Invalid --fail-on "${opts.failOn}" (use minor|moderate|serious|critical)\n`);
|
|
106
176
|
process.exit(2);
|
|
107
177
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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);
|
|
111
181
|
if (worst >= threshold) {
|
|
112
|
-
|
|
182
|
+
const which = diff ? 'new violation(s)' : 'violation(s)';
|
|
183
|
+
process.stderr.write(`Failing: found ${which} at or above "${opts.failOn}".\n`);
|
|
113
184
|
process.exit(1);
|
|
114
185
|
}
|
|
115
186
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath,
|
|
|
6
6
|
export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, } 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
|
+
export { createFocusWalkProbe, detectTabTrap, type FocusObservation, type FocusWalkProbe, type TabWalkVerdict, } from './keyboard/focus-walk.js';
|
|
9
10
|
export { describeElement, accessibleDescription, ariaStates, type AxDescription, } from './keyboard/accname.js';
|
|
10
11
|
export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, type AxPanelData, } from './overlay.js';
|
package/dist/index.js
CHANGED
|
@@ -6,5 +6,6 @@ export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath,
|
|
|
6
6
|
export { tabSequence, 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
|
+
export { createFocusWalkProbe, detectTabTrap, } from './keyboard/focus-walk.js';
|
|
9
10
|
export { describeElement, accessibleDescription, ariaStates, } from './keyboard/accname.js';
|
|
10
11
|
export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, } from './overlay.js';
|