@ngbracket/a11y-devtools 0.1.1 → 0.2.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/LICENSE +21 -0
- package/README.md +35 -15
- package/dist/attribution.d.ts +7 -0
- package/dist/attribution.js +34 -1
- package/dist/report.js +3 -1
- package/dist/scan.d.ts +2 -0
- package/dist/scan.js +2 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Duncan Faulkner and Lara Sanz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,26 +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** —
|
|
5
|
-
(
|
|
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
|
-
|
|
7
|
+
The React axe tools in this space — [`@axe-core/react`](https://www.npmjs.com/package/@axe-core/react),
|
|
8
|
+
[`axe-mode`](https://github.com/raunofreiberg/axe-mode), the
|
|
9
|
+
[TanStack Devtools a11y plugin](https://tanstack.com/devtools/latest/docs/plugins/a11y)
|
|
10
|
+
— report the DOM node (selector, HTML, rule id) and highlight it, but stop there:
|
|
11
|
+
none tie a violation to the component that rendered it. This does, through
|
|
12
|
+
Angular's **documented** dev debug API (`window.ng`) rather than private framework
|
|
13
|
+
internals.
|
|
8
14
|
|
|
9
|
-
Part of the `@ngbracket` Angular tooling family.
|
|
10
|
-
[`docs/findings.md`](docs/findings.md) for the research and scope.
|
|
15
|
+
Part of the `@ngbracket` Angular tooling family.
|
|
11
16
|
|
|
12
17
|
## Status
|
|
13
18
|
|
|
14
|
-
Ships attribution + axe scan + grouped
|
|
15
|
-
+ the
|
|
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).
|
|
16
22
|
|
|
17
23
|
## How the attribution works
|
|
18
24
|
|
|
19
25
|
Angular publishes debug helpers on the `window.ng` global in dev mode.
|
|
20
26
|
`getOwningComponent(node)` returns the component whose view contains a DOM node,
|
|
21
|
-
so any axe-flagged element resolves to its owning component
|
|
22
|
-
|
|
23
|
-
|
|
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.
|
|
24
32
|
|
|
25
33
|
## Install
|
|
26
34
|
|
|
@@ -56,6 +64,20 @@ provideA11yDevtools({
|
|
|
56
64
|
});
|
|
57
65
|
```
|
|
58
66
|
|
|
67
|
+
Findings are grouped by owning component, led by a summary line, and each node's
|
|
68
|
+
directives are shown inline:
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
♿ a11y-devtools: 2 issue(s) across 1 component(s)
|
|
72
|
+
♿ UserCardComponent — 2 issue(s)
|
|
73
|
+
critical · image-alt: Images must have alternative text [via TooltipDirective]
|
|
74
|
+
img
|
|
75
|
+
https://dequeuniversity.com/rules/axe/4.13/image-alt
|
|
76
|
+
serious · color-contrast: Elements must meet minimum contrast
|
|
77
|
+
button.save
|
|
78
|
+
https://dequeuniversity.com/rules/axe/4.13/color-contrast
|
|
79
|
+
```
|
|
80
|
+
|
|
59
81
|
You can also scan on demand:
|
|
60
82
|
|
|
61
83
|
```ts
|
|
@@ -88,9 +110,7 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
|
|
|
88
110
|
|
|
89
111
|
## Roadmap
|
|
90
112
|
|
|
91
|
-
-
|
|
92
|
-
the item-2 lint plugin can't see statically.
|
|
93
|
-
- Per-component filtering and a violation count badge.
|
|
113
|
+
- Per-component filtering and a violation-count badge.
|
|
94
114
|
|
|
95
|
-
Done: attribution ·
|
|
96
|
-
in-app overlay · CI prod-weight guard.
|
|
115
|
+
Done: component attribution · directive / `hostDirectives` attribution · axe scan ·
|
|
116
|
+
grouped console reporter · dev-only provider · in-app overlay · CI prod-weight guard.
|
package/dist/attribution.d.ts
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
export interface NgDebugGlobal {
|
|
13
13
|
getComponent(element: Element): unknown;
|
|
14
14
|
getOwningComponent(element: Element | object): unknown;
|
|
15
|
+
getDirectives(element: Element | object): unknown[];
|
|
15
16
|
}
|
|
16
17
|
export declare function ngDebug(): NgDebugGlobal | undefined;
|
|
17
18
|
export declare function resolveOwningComponentName(node: Element): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Names of the directives applied directly to `node`, including those attached
|
|
21
|
+
* via `hostDirectives` — the runtime-only a11y cases the static lint plugin
|
|
22
|
+
* can't see. Empty when the debug global is absent or the node has none.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveDirectiveNames(node: Element): string[];
|
package/dist/attribution.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
export function ngDebug() {
|
|
2
2
|
return globalThis.ng;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Angular's dev output can emit class names with a leading underscore
|
|
6
|
+
* (e.g. `_Login` for `Login`); strip it so attribution shows the authored name.
|
|
7
|
+
*/
|
|
8
|
+
function cleanName(name) {
|
|
9
|
+
if (!name)
|
|
10
|
+
return null;
|
|
11
|
+
return name.replace(/^_+/, '') || null;
|
|
12
|
+
}
|
|
4
13
|
function nameOf(instance) {
|
|
5
14
|
if (!instance || typeof instance !== 'object')
|
|
6
15
|
return null;
|
|
7
|
-
return instance.constructor.name ?? null;
|
|
16
|
+
return cleanName(instance.constructor.name ?? null);
|
|
8
17
|
}
|
|
9
18
|
export function resolveOwningComponentName(node) {
|
|
10
19
|
const ng = ngDebug();
|
|
@@ -13,3 +22,27 @@ export function resolveOwningComponentName(node) {
|
|
|
13
22
|
const component = ng.getComponent(node) ?? ng.getOwningComponent(node);
|
|
14
23
|
return nameOf(component);
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Names of the directives applied directly to `node`, including those attached
|
|
27
|
+
* via `hostDirectives` — the runtime-only a11y cases the static lint plugin
|
|
28
|
+
* can't see. Empty when the debug global is absent or the node has none.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveDirectiveNames(node) {
|
|
31
|
+
const ng = ngDebug();
|
|
32
|
+
if (!ng?.getDirectives)
|
|
33
|
+
return [];
|
|
34
|
+
let directives;
|
|
35
|
+
try {
|
|
36
|
+
directives = ng.getDirectives(node) ?? [];
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return []; // node isn't part of a live view
|
|
40
|
+
}
|
|
41
|
+
const names = [];
|
|
42
|
+
for (const directive of directives) {
|
|
43
|
+
const name = nameOf(directive);
|
|
44
|
+
if (name)
|
|
45
|
+
names.push(name);
|
|
46
|
+
}
|
|
47
|
+
return names;
|
|
48
|
+
}
|
package/dist/report.js
CHANGED
|
@@ -17,10 +17,12 @@ export function logFindings(findings, logger = console) {
|
|
|
17
17
|
else
|
|
18
18
|
byComponent.set(key, [finding]);
|
|
19
19
|
}
|
|
20
|
+
logger.info(`♿ a11y-devtools: ${findings.length} issue(s) across ${byComponent.size} component(s)`);
|
|
20
21
|
for (const [component, items] of byComponent) {
|
|
21
22
|
logger.groupCollapsed(`♿ ${component} — ${items.length} issue(s)`);
|
|
22
23
|
for (const finding of items) {
|
|
23
|
-
|
|
24
|
+
const via = finding.directives.length ? ` [via ${finding.directives.join(', ')}]` : '';
|
|
25
|
+
logger.warn(`${finding.impact ?? 'n/a'} · ${finding.id}: ${finding.help}${via}`, `\n ${finding.target}\n ${finding.helpUrl}`);
|
|
24
26
|
}
|
|
25
27
|
logger.groupEnd();
|
|
26
28
|
}
|
package/dist/scan.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface A11yFinding {
|
|
|
9
9
|
helpUrl: string;
|
|
10
10
|
/** Owning component name, or null when attribution isn't available (prod). */
|
|
11
11
|
component: string | null;
|
|
12
|
+
/** Directives on the flagged node (incl. hostDirectives); [] when none/unavailable. */
|
|
13
|
+
directives: string[];
|
|
12
14
|
/** CSS selector axe reported for the node. */
|
|
13
15
|
target: string;
|
|
14
16
|
html: string;
|
package/dist/scan.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveOwningComponentName } from './attribution.js';
|
|
1
|
+
import { resolveDirectiveNames, resolveOwningComponentName } from './attribution.js';
|
|
2
2
|
import { OVERLAY_EXCLUDE_SELECTOR } from './overlay.js';
|
|
3
3
|
// axe-core is a singleton and throws if a run starts while another is in flight.
|
|
4
4
|
// Chain runs so overlapping callers (e.g. rapid rescans) serialize safely.
|
|
@@ -37,6 +37,7 @@ async function runAxeOnce(root, options) {
|
|
|
37
37
|
help: violation.help,
|
|
38
38
|
helpUrl: violation.helpUrl,
|
|
39
39
|
component: element ? resolveOwningComponentName(element) : null,
|
|
40
|
+
directives: element ? resolveDirectiveNames(element) : [],
|
|
40
41
|
target,
|
|
41
42
|
html: node.html,
|
|
42
43
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|