@ngbracket/a11y-devtools 0.1.1 → 0.2.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/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
@@ -6,8 +6,7 @@ back to **the component that rendered it** — the attribution React overlay too
6
6
 
7
7
  Report `♿ UserCardComponent — 2 issue(s)` instead of a wall of CSS selectors.
8
8
 
9
- Part of the `@ngbracket` Angular tooling family. See
10
- [`docs/findings.md`](docs/findings.md) for the research and scope.
9
+ Part of the `@ngbracket` Angular tooling family.
11
10
 
12
11
  ## Status
13
12
 
@@ -89,7 +88,7 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
89
88
  ## Roadmap
90
89
 
91
90
  - **`host` / `hostDirectives` a11y** via `getDirectives(el)` — the runtime cases
92
- the item-2 lint plugin can't see statically.
91
+ a static ESLint pass can't see.
93
92
  - Per-component filtering and a violation count badge.
94
93
 
95
94
  Done: attribution · axe scan · grouped console reporter · dev-only provider ·
@@ -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[];
@@ -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
- logger.warn(`${finding.impact ?? 'n/a'} · ${finding.id}: ${finding.help}`, `\n ${finding.target}\n ${finding.helpUrl}`);
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.1.1",
3
+ "version": "0.2.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",