@ngbracket/a11y-devtools 0.2.0 → 0.3.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/README.md CHANGED
@@ -1,25 +1,34 @@
1
1
  # @ngbracket/a11y-devtools
2
2
 
3
3
  Dev-only, in-app accessibility auditing for Angular that maps each axe violation
4
- back to **the component that rendered it** — the attribution React overlay tools
5
- (`@axe-core/react`, `axe-mode`, TanStack a11y) structurally can't do.
4
+ back to **the component that rendered it** — so you get
5
+ `♿ UserCardComponent — 2 issue(s)`, not a wall of CSS selectors.
6
6
 
7
- Report `♿ UserCardComponent 2 issue(s)` instead of a wall of CSS selectors.
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.
8
14
 
9
15
  Part of the `@ngbracket` Angular tooling family.
10
16
 
11
17
  ## Status
12
18
 
13
- Ships attribution + axe scan + grouped console reporter + the dev-only provider
14
- + the visual in-app overlay (severity-coloured highlights, click-to-scroll).
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).
15
22
 
16
23
  ## How the attribution works
17
24
 
18
25
  Angular publishes debug helpers on the `window.ng` global in dev mode.
19
26
  `getOwningComponent(node)` returns the component whose view contains a DOM node,
20
- so any axe-flagged element resolves to its owning component. These helpers exist
21
- **only in dev builds** which is exactly right: the tool is dev-only, and the
22
- global's absence in prod is the signal to no-op.
27
+ so any axe-flagged element resolves to its owning component; `getDirectives(node)`
28
+ adds the directives applied to that node including those pulled in via
29
+ `hostDirectives` which are the runtime cases a static ESLint pass can't see.
30
+ These helpers exist **only in dev builds** — which is exactly right: the tool is
31
+ dev-only, and the global's absence in prod is the signal to no-op.
23
32
 
24
33
  ## Install
25
34
 
@@ -52,9 +61,24 @@ provideA11yDevtools({
52
61
  log: true, // grouped console output; default true
53
62
  overlay: true, // in-app visual highlights over flagged nodes; default false
54
63
  debounceMs: 500, // quiet window after stabilization before scanning
64
+ tags: ['wcag22aa'], // scope the ruleset; default = axe-core's full ruleset
55
65
  });
56
66
  ```
57
67
 
68
+ Findings are grouped by owning component, led by a summary line, and each node's
69
+ directives are shown inline:
70
+
71
+ ```text
72
+ ♿ a11y-devtools: 2 issue(s) across 1 component(s)
73
+ ♿ UserCardComponent — 2 issue(s)
74
+ critical · image-alt: Images must have alternative text [via TooltipDirective]
75
+ img
76
+ https://dequeuniversity.com/rules/axe/4.13/image-alt
77
+ serious · color-contrast: Elements must meet minimum contrast
78
+ button.save
79
+ https://dequeuniversity.com/rules/axe/4.13/color-contrast
80
+ ```
81
+
58
82
  You can also scan on demand:
59
83
 
60
84
  ```ts
@@ -64,6 +88,26 @@ const findings = await runA11yScan(); // scan + grouped log
64
88
  const raw = await scan(document.body); // findings only
65
89
  ```
66
90
 
91
+ `scan()` and `runA11yScan()` also take full axe-core run options as a second
92
+ argument (`scan(root, { runOnly: … })`) for finer control than the provider's
93
+ `tags`.
94
+
95
+ ## What it checks (and what it can't)
96
+
97
+ Under the hood this is [axe-core](https://github.com/dequelabs/axe-core) — the
98
+ scan runs axe's rules and enriches each violation with the owning component. By
99
+ default it runs axe-core's full ruleset: the **machine-testable** rules across
100
+ **WCAG 2.0, 2.1 and 2.2, Levels A & AA**, plus axe's *best-practice* rules. Scope
101
+ it to a single conformance target with `tags` (e.g. `['wcag22aa']`) or
102
+ `['wcag21aa', 'best-practice']`.
103
+
104
+ Automated checks only cover the part of WCAG a machine can test — on the order of
105
+ a third of the success criteria. Many WCAG 2.2 additions have **no automated rule
106
+ at all** (target size 2.5.8, dragging 2.5.7, consistent help, redundant entry,
107
+ accessible authentication), so a clean run is necessary, not sufficient — the rest
108
+ needs keyboard, screen-reader and human testing. (WCAG 3.0 is still an early W3C
109
+ draft with a different, non-final model; there's nothing to test against yet.)
110
+
67
111
  ## Production weight
68
112
 
69
113
  In production `provideA11yDevtools()` is a **no-op** and axe-core is never loaded.
@@ -87,9 +131,7 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
87
131
 
88
132
  ## Roadmap
89
133
 
90
- - **`host` / `hostDirectives` a11y** via `getDirectives(el)` — the runtime cases
91
- a static ESLint pass can't see.
92
- - Per-component filtering and a violation count badge.
134
+ - Per-component filtering and a violation-count badge.
93
135
 
94
- Done: attribution · axe scan · grouped console reporter · dev-only provider ·
95
- in-app overlay · CI prod-weight guard.
136
+ Done: component attribution · directive / `hostDirectives` attribution · axe scan ·
137
+ grouped console reporter · dev-only provider · in-app overlay · CI prod-weight guard.
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Attribution core: given a DOM node that axe flagged, return the name of the
3
- * component responsible for it — the differentiator React overlay tools can't do.
3
+ * component responsible for it — the differentiator we haven't seen other axe
4
+ * overlay devtools do (they report the DOM node, not the owning component by name).
4
5
  *
5
6
  * Angular's debug helpers are NOT public named exports of `@angular/core`; they
6
7
  * are methods on the `window.ng` global published in dev mode
@@ -11,6 +11,14 @@ export interface A11yDevtoolsOptions {
11
11
  overlay?: boolean;
12
12
  /** Quiet window after stabilization before scanning. Default 500ms. */
13
13
  debounceMs?: number;
14
+ /**
15
+ * Restrict the scan to specific axe tags, e.g. `['wcag22aa']` or
16
+ * `['wcag21aa', 'best-practice']`. Omit to run axe-core's default ruleset —
17
+ * the machine-testable rules across WCAG 2.0/2.1/2.2 (Levels A & AA) plus axe's
18
+ * best-practice rules. (For finer control, call `runA11yScan`/`scan` with full
19
+ * axe run options.)
20
+ */
21
+ tags?: string[];
14
22
  }
15
23
  /**
16
24
  * Dev-only in-app accessibility auditing. Rescans whenever the application
package/dist/provider.js CHANGED
@@ -15,7 +15,10 @@ export function provideA11yDevtools(options = {}) {
15
15
  if (!isDevMode()) {
16
16
  return makeEnvironmentProviders([]);
17
17
  }
18
- const { root, log = true, logger, overlay = false, debounceMs = 500 } = options;
18
+ const { root, log = true, logger, overlay = false, debounceMs = 500, tags } = options;
19
+ const axe = tags
20
+ ? { runOnly: { type: 'tag', values: tags } }
21
+ : undefined;
19
22
  return makeEnvironmentProviders([
20
23
  provideEnvironmentInitializer(() => {
21
24
  const appRef = inject(ApplicationRef);
@@ -28,7 +31,7 @@ export function provideA11yDevtools(options = {}) {
28
31
  if (scanning)
29
32
  return; // don't stack rescans while one is in flight
30
33
  scanning = true;
31
- runA11yScan(root?.(), { log, logger })
34
+ runA11yScan(root?.(), { log, logger, axe })
32
35
  .then((findings) => overlayView?.render(findings))
33
36
  .catch(() => undefined)
34
37
  .finally(() => {
package/dist/runner.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { RunOptions as AxeRunOptions } from 'axe-core';
1
2
  import { type A11yFinding } from './scan.js';
2
3
  import { type Logger } from './report.js';
3
4
  export interface RunOptions {
@@ -5,6 +6,14 @@ export interface RunOptions {
5
6
  log?: boolean;
6
7
  /** Sink for reporting; defaults to `console`. */
7
8
  logger?: Logger;
9
+ /**
10
+ * axe-core run options — use this to scope the ruleset, e.g.
11
+ * `{ runOnly: { type: 'tag', values: ['wcag22aa'] } }`. Omit to run axe-core's
12
+ * default ruleset: the machine-testable rules across WCAG 2.0/2.1/2.2 (Levels
13
+ * A & AA) plus axe's best-practice rules. (The provider exposes the common case
14
+ * as a friendlier `tags: string[]`.)
15
+ */
16
+ axe?: AxeRunOptions;
8
17
  }
9
18
  /** Scan `root`, optionally report, and return the findings. */
10
19
  export declare function runA11yScan(root?: Element | Document, options?: RunOptions): Promise<A11yFinding[]>;
package/dist/runner.js CHANGED
@@ -2,7 +2,7 @@ import { scan } from './scan.js';
2
2
  import { logFindings } from './report.js';
3
3
  /** Scan `root`, optionally report, and return the findings. */
4
4
  export async function runA11yScan(root, options = {}) {
5
- const findings = await scan(root ?? document);
5
+ const findings = await scan(root ?? document, options.axe);
6
6
  if (options.log !== false) {
7
7
  logFindings(findings, options.logger);
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Dev-only in-app accessibility auditing for Angular that maps each axe violation back to the component that rendered it — the attribution React overlay tools can't do.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",
@@ -42,6 +42,7 @@
42
42
  "build": "tsc -p tsconfig.json",
43
43
  "test": "vitest run",
44
44
  "test:watch": "vitest",
45
+ "demo:console": "vitest run --config vitest.demo.config.ts --disableConsoleIntercept",
45
46
  "prepublishOnly": "npm run build"
46
47
  },
47
48
  "dependencies": {