@ngbracket/a11y-devtools 0.6.0 → 0.7.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,35 @@
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.7.1
7
+
8
+ ### Fixed
9
+
10
+ - **Tab-order badges no longer collide with the findings labels.** A numbered
11
+ tab-order badge was anchored on each control's top-left corner — exactly where
12
+ the severity-coloured finding labels sit — so on a flagged control the two
13
+ overlapped and obscured each other. Badges now sit just outside the control's
14
+ left edge, vertically centred (clamped into the viewport for controls flush to
15
+ the left), and the connector path threads those points.
16
+
17
+ ## 0.7.0
18
+
19
+ ### Added
20
+
21
+ - **Keyboard & Focus Mode — M2: the accessibility-tree preview.** With
22
+ `keyboard: true` **and** `overlay: true`, a panel now follows focus: as you Tab,
23
+ it shows the focused control's computed **role, accessible name, description, and
24
+ ARIA states**, attributed to the owning component.
25
+ - Name and role are computed by **axe-core's own accname commons** (one accname
26
+ source, not a second home-grown one). axe stays behind a dynamic import, so the
27
+ prod-weight guarantee is unchanged.
28
+ - **Honesty guardrail:** the panel is headed *"Accessibility-tree preview —
29
+ computed approximation"* and never branded as any specific screen reader's
30
+ output. A missing accessible name is flagged in warning colour.
31
+ - New public API: `describeElement` (async, axe-backed), `accessibleDescription`,
32
+ `ariaStates`, and the `AxDescription` / `AxPanelData` types; the overlay gains
33
+ `renderAxPanel`.
34
+
6
35
  ## 0.6.0
7
36
 
8
37
  ### Added
package/README.md CHANGED
@@ -19,8 +19,9 @@ Part of the `@ngbracket` Angular tooling family.
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
21
  overlay (severity-coloured highlights, click-to-scroll) + headless report mode +
22
- **Keyboard & Focus Mode M1** (tab-order visualisation + keyboard-reachability
23
- findings — the part of accessibility axe can't test).
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).
24
25
 
25
26
  ## How the attribution works
26
27
 
@@ -160,7 +161,15 @@ component that placed it and notes the primitive as `(via …)`.
160
161
  axe covers the machine-testable third of WCAG. **Keyboard & Focus Mode** starts on
161
162
  the rest — keyboard operability — still naming the component that owns each issue.
162
163
  Turn it on with `keyboard: true` (provider / `runA11yScan` / `scan` / `scanPages`)
163
- or `--keyboard` on the CLI. It adds:
164
+ or `--keyboard` on the CLI.
165
+
166
+ ![Keyboard & Focus Mode over the demo page: numbered tab-order badges (badge 1 in
167
+ orange flags a positive tabindex) joined by a connector path, severity-coloured
168
+ finding highlights labelled with their owning component (including the ngbr/*
169
+ keyboard findings), and the focus-follow accessibility-tree panel showing the
170
+ focused button's computed role, name and states.](./demo/keyboard-layer-2026-09.png)
171
+
172
+ It adds:
164
173
 
165
174
  - **Tab-order visualisation** (overlay): numbered badges at each tab stop and a
166
175
  connector path showing the order focus actually moves. A positive-`tabindex` stop
@@ -183,8 +192,24 @@ npx ngbr-a11y-report --base http://localhost:4200 --route / --keyboard
183
192
 
184
193
  **Honesty guardrail:** `click-without-key` and `tab-order-mismatch` are
185
194
  *heuristics* — labelled "verify manually", never reported as confirmed failures.
186
- (Next: M2 — an accessibility-tree preview, framed as a *computed approximation*,
187
- never "what a screen reader says".)
195
+
196
+ ### Accessibility-tree preview (M2)
197
+
198
+ With `keyboard: true` **and** `overlay: true`, a panel follows focus: as you Tab, it
199
+ shows the focused control's computed **role, accessible name, description, and ARIA
200
+ states** — attributed to its owning component. The name and role come from
201
+ axe-core's own accessible-name commons (one accname source, shared with the scan),
202
+ and a missing accessible name is flagged in warning colour.
203
+
204
+ > **Accessibility-tree preview — computed approximation.** This is a *computed*
205
+ > name/role/state, an approximation of what assistive tech announces — **not** what
206
+ > any one screen reader says. Real output varies by screen reader (NVDA / JAWS /
207
+ > VoiceOver), browse vs. focus mode, verbosity, and browser. Use it to catch
208
+ > missing names and wrong roles fast; confirm the announcement with a real SR.
209
+
210
+ The same computation is available programmatically via `describeElement(el)`
211
+ (async — it loads axe on demand), plus the pure `ariaStates(el)` and
212
+ `accessibleDescription(el)` helpers.
188
213
 
189
214
  ## What it checks (and what it can't)
190
215
 
@@ -225,9 +250,9 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
225
250
 
226
251
  ## Roadmap
227
252
 
228
- - Keyboard & Focus Mode **M2** — accessibility-tree preview (role + accessible
229
- name + state as you Tab), framed as a *computed approximation*.
230
253
  - Keyboard & Focus Mode **M3** — focus-trap *candidate* detection.
254
+ - Headless "linear walkthrough" — the tab sequence as an SR-ish reading list per
255
+ route in report-mode (M2's preview is currently overlay-only).
231
256
  - HTML report + baseline/diff mode for CI.
232
257
  - Per-component filtering and a violation-count badge.
233
258
 
@@ -235,4 +260,5 @@ Done: component attribution (nearest app-owned, walking past UI primitives) ·
235
260
  directive / `hostDirectives` attribution · configurable framework prefixes · axe
236
261
  scan · grouped console reporter · dev-only provider · in-app overlay · headless
237
262
  report mode (CLI + `./report`) · **Keyboard & Focus Mode M1** (tab-order viz +
238
- keyboard-reachability findings) · CI prod-weight guard.
263
+ keyboard-reachability findings) · **M2** (focus-follow accessibility-tree preview) ·
264
+ CI prod-weight guard.
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ 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
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
- export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, } from './overlay.js';
8
+ export { describeElement, accessibleDescription, ariaStates, type AxDescription, } from './keyboard/accname.js';
9
+ export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, type AxPanelData, } from './overlay.js';
package/dist/index.js CHANGED
@@ -5,4 +5,5 @@ export { logFindings } from './report.js';
5
5
  export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, } from './attribution.js';
6
6
  export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
7
7
  export { scanKeyboard } from './keyboard/keyboard-scan.js';
8
+ export { describeElement, accessibleDescription, ariaStates, } from './keyboard/accname.js';
8
9
  export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, } from './overlay.js';
@@ -34226,6 +34226,8 @@
34226
34226
  var SVG_NS = "http://www.w3.org/2000/svg";
34227
34227
  var TAB_ORDER_COLOR = "#0b8f8f";
34228
34228
  var TAB_ORDER_WARN_COLOR = "#e8710a";
34229
+ var TAB_BADGE_GUTTER = 10;
34230
+ var TAB_BADGE_MIN_X = 9;
34229
34231
  var OVERLAY_ATTR = "data-ngb-a11y-overlay";
34230
34232
  var OVERLAY_EXCLUDE_SELECTOR = `[${OVERLAY_ATTR}]`;
34231
34233
  var IMPACT_COLOR = {
@@ -34268,6 +34270,24 @@
34268
34270
  connector.setAttribute("opacity", "0.7");
34269
34271
  svg.appendChild(connector);
34270
34272
  container.appendChild(svg);
34273
+ const axPanel = doc.createElement("div");
34274
+ axPanel.setAttribute(OVERLAY_ATTR, "");
34275
+ Object.assign(axPanel.style, {
34276
+ position: "fixed",
34277
+ right: "12px",
34278
+ bottom: "12px",
34279
+ maxWidth: "320px",
34280
+ padding: "8px 10px",
34281
+ borderRadius: "6px",
34282
+ background: "rgba(20,22,28,0.94)",
34283
+ color: "#f4f4f5",
34284
+ font: "12px/1.5 ui-sans-serif, system-ui, sans-serif",
34285
+ boxShadow: "0 2px 12px rgba(0,0,0,0.4)",
34286
+ pointerEvents: "none",
34287
+ zIndex: "2147483647",
34288
+ display: "none"
34289
+ });
34290
+ container.appendChild(axPanel);
34271
34291
  let highlights = [];
34272
34292
  let tabBadges = [];
34273
34293
  const reposition = () => {
@@ -34280,9 +34300,11 @@
34280
34300
  const points = [];
34281
34301
  for (const { target, badge } of tabBadges) {
34282
34302
  const rect = target.getBoundingClientRect();
34283
- badge.style.top = `${rect.top}px`;
34284
- badge.style.left = `${rect.left}px`;
34285
- points.push(`${rect.left + rect.width / 2},${rect.top + rect.height / 2}`);
34303
+ const y = rect.top + rect.height / 2;
34304
+ const x = Math.max(TAB_BADGE_MIN_X, rect.left - TAB_BADGE_GUTTER);
34305
+ badge.style.top = `${y}px`;
34306
+ badge.style.left = `${x}px`;
34307
+ points.push(`${x},${y}`);
34286
34308
  }
34287
34309
  connector.setAttribute("points", points.join(" "));
34288
34310
  }
@@ -34340,14 +34362,60 @@
34340
34362
  }
34341
34363
  repositionTabOrder();
34342
34364
  }
34365
+ function renderAxPanel(data) {
34366
+ if (!data) {
34367
+ axPanel.style.display = "none";
34368
+ axPanel.replaceChildren();
34369
+ return;
34370
+ }
34371
+ axPanel.replaceChildren(...buildAxPanelContent(doc, data));
34372
+ axPanel.style.display = "block";
34373
+ }
34343
34374
  function destroy() {
34344
34375
  clear();
34345
34376
  clearTabOrder();
34377
+ renderAxPanel(null);
34346
34378
  win?.removeEventListener("scroll", onViewportChange, { capture: true });
34347
34379
  win?.removeEventListener("resize", onViewportChange);
34348
34380
  container.remove();
34349
34381
  }
34350
- return { render, renderTabOrder, clear, clearTabOrder, destroy };
34382
+ return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
34383
+ }
34384
+ function buildAxPanelContent(doc, data) {
34385
+ const nodes = [];
34386
+ const header = doc.createElement("div");
34387
+ header.textContent = "Accessibility-tree preview \u2014 computed approximation";
34388
+ Object.assign(header.style, {
34389
+ fontWeight: "700",
34390
+ fontSize: "10px",
34391
+ letterSpacing: "0.02em",
34392
+ textTransform: "uppercase",
34393
+ color: "#a9b0bd",
34394
+ marginBottom: "4px"
34395
+ });
34396
+ header.title = "A computed name/role/state \u2014 an approximation of what assistive tech announces, not any one screen reader.";
34397
+ nodes.push(header);
34398
+ const row = (label, value, muted = false) => {
34399
+ const div = doc.createElement("div");
34400
+ const key = doc.createElement("span");
34401
+ key.textContent = `${label}: `;
34402
+ key.style.color = "#a9b0bd";
34403
+ const val = doc.createElement("span");
34404
+ val.textContent = value;
34405
+ if (muted)
34406
+ val.style.color = "#e8710a";
34407
+ div.append(key, val);
34408
+ return div;
34409
+ };
34410
+ nodes.push(row("role", data.role ?? `(none \u2014 <${data.tag}>)`));
34411
+ nodes.push(data.name ? row("name", `"${data.name}"`) : row("name", "(no accessible name)", true));
34412
+ if (data.description)
34413
+ nodes.push(row("description", `"${data.description}"`));
34414
+ if (data.states.length)
34415
+ nodes.push(row("states", data.states.join(", ")));
34416
+ if (data.component)
34417
+ nodes.push(row("component", data.component));
34418
+ return nodes;
34351
34419
  }
34352
34420
  function buildBadge(doc, stop) {
34353
34421
  const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The keyboard layer, part C: a *computed approximation* of what assistive tech
3
+ * would announce for an element — its role, accessible name, description, and
4
+ * ARIA states.
5
+ *
6
+ * HONESTY GUARDRAIL (non-negotiable): this is a computed approximation, NEVER
7
+ * "what a screen reader says". Real output varies by screen reader
8
+ * (NVDA/JAWS/VoiceOver), browse vs. focus mode, verbosity, and browser. Callers
9
+ * must label it as such and must not brand it as any specific SR's output.
10
+ *
11
+ * The name and role come from **axe-core's own accessible-name commons** — the
12
+ * same well-tested implementation the scan already relies on — so there's one
13
+ * accname source, not a second home-grown one. axe is loaded via dynamic import
14
+ * (and only when this runs), so it never enters a consumer's static bundle; the
15
+ * prod-weight guard still holds.
16
+ */
17
+ /** A computed approximation of an element's accessibility-tree node. */
18
+ export interface AxDescription {
19
+ /** Computed ARIA role, or null when axe can't resolve one. */
20
+ role: string | null;
21
+ /** Computed accessible name (may be empty — itself a finding worth noticing). */
22
+ name: string;
23
+ /** Computed accessible description (aria-describedby / title), or ''. */
24
+ description: string;
25
+ /** Compact human labels for the element's states, e.g. `['expanded', 'level 2']`. */
26
+ states: string[];
27
+ }
28
+ /**
29
+ * Compute the accessibility-tree approximation for `element`. Resolves to sane
30
+ * defaults (no role, empty name) rather than throwing if axe's tree can't be
31
+ * built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
32
+ */
33
+ export declare function describeElement(element: Element): Promise<AxDescription>;
34
+ /** The accessible description: `aria-describedby` targets' text, else the `title`. */
35
+ export declare function accessibleDescription(element: Element): string;
36
+ /**
37
+ * Compact, human-readable state labels — the states a screen reader would voice
38
+ * alongside role and name (expanded, checked, disabled, current, level, position
39
+ * in set). ARIA attributes take precedence, with native fallbacks (a real
40
+ * checkbox's `checked`, a disabled control, a heading's level).
41
+ */
42
+ export declare function ariaStates(element: Element): string[];
@@ -0,0 +1,131 @@
1
+ /**
2
+ * The keyboard layer, part C: a *computed approximation* of what assistive tech
3
+ * would announce for an element — its role, accessible name, description, and
4
+ * ARIA states.
5
+ *
6
+ * HONESTY GUARDRAIL (non-negotiable): this is a computed approximation, NEVER
7
+ * "what a screen reader says". Real output varies by screen reader
8
+ * (NVDA/JAWS/VoiceOver), browse vs. focus mode, verbosity, and browser. Callers
9
+ * must label it as such and must not brand it as any specific SR's output.
10
+ *
11
+ * The name and role come from **axe-core's own accessible-name commons** — the
12
+ * same well-tested implementation the scan already relies on — so there's one
13
+ * accname source, not a second home-grown one. axe is loaded via dynamic import
14
+ * (and only when this runs), so it never enters a consumer's static bundle; the
15
+ * prod-weight guard still holds.
16
+ */
17
+ // axe is a heavy dynamic import; load it once and reuse. Typed loosely because
18
+ // the accname commons used here aren't part of axe's published type surface.
19
+ let axePromise;
20
+ function loadAxe() {
21
+ return (axePromise ??= import('axe-core').then((m) => (m.default ?? m)));
22
+ }
23
+ /**
24
+ * Compute the accessibility-tree approximation for `element`. Resolves to sane
25
+ * defaults (no role, empty name) rather than throwing if axe's tree can't be
26
+ * built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
27
+ */
28
+ export async function describeElement(element) {
29
+ const axe = await loadAxe();
30
+ const doc = element.ownerDocument ?? document;
31
+ let role = null;
32
+ let name = '';
33
+ try {
34
+ axe.setup(doc);
35
+ const vnode = axe.utils.getNodeFromTree(element);
36
+ role = axe.commons.aria.getRole(element) ?? null;
37
+ name = vnode ? (axe.commons.text.accessibleTextVirtual(vnode) ?? '') : '';
38
+ }
39
+ catch {
40
+ // Leave role=null / name='' — axe couldn't build a tree (e.g. run in flight).
41
+ }
42
+ finally {
43
+ try {
44
+ axe.teardown();
45
+ }
46
+ catch {
47
+ /* nothing set up */
48
+ }
49
+ }
50
+ return { role, name, description: accessibleDescription(element), states: ariaStates(element) };
51
+ }
52
+ /** The accessible description: `aria-describedby` targets' text, else the `title`. */
53
+ export function accessibleDescription(element) {
54
+ const ids = element.getAttribute('aria-describedby');
55
+ if (ids) {
56
+ const doc = element.ownerDocument ?? document;
57
+ const text = ids
58
+ .split(/\s+/)
59
+ .filter(Boolean)
60
+ .map((id) => doc.getElementById(id)?.textContent?.trim() ?? '')
61
+ .filter(Boolean)
62
+ .join(' ');
63
+ if (text)
64
+ return text;
65
+ }
66
+ return element.getAttribute('title')?.trim() ?? '';
67
+ }
68
+ /** True for an ARIA attribute value that expresses "on" rather than "off"/absent. */
69
+ function isOn(value) {
70
+ return value !== null && value !== 'false' && value !== 'undefined';
71
+ }
72
+ /**
73
+ * Compact, human-readable state labels — the states a screen reader would voice
74
+ * alongside role and name (expanded, checked, disabled, current, level, position
75
+ * in set). ARIA attributes take precedence, with native fallbacks (a real
76
+ * checkbox's `checked`, a disabled control, a heading's level).
77
+ */
78
+ export function ariaStates(element) {
79
+ const states = [];
80
+ const attr = (name) => element.getAttribute(name);
81
+ const expanded = attr('aria-expanded');
82
+ if (expanded === 'true')
83
+ states.push('expanded');
84
+ else if (expanded === 'false')
85
+ states.push('collapsed');
86
+ const checked = attr('aria-checked');
87
+ if (checked === 'true')
88
+ states.push('checked');
89
+ else if (checked === 'false')
90
+ states.push('not checked');
91
+ else if (checked === 'mixed')
92
+ states.push('mixed');
93
+ else if ('checked' in element && element.checked)
94
+ states.push('checked');
95
+ const pressed = attr('aria-pressed');
96
+ if (pressed === 'true')
97
+ states.push('pressed');
98
+ else if (pressed === 'false')
99
+ states.push('not pressed');
100
+ if (attr('aria-selected') === 'true')
101
+ states.push('selected');
102
+ if (isOn(attr('aria-disabled')) || ('disabled' in element && element.disabled)) {
103
+ states.push('disabled');
104
+ }
105
+ if (isOn(attr('aria-required')) || ('required' in element && element.required)) {
106
+ states.push('required');
107
+ }
108
+ if (attr('aria-invalid') === 'true')
109
+ states.push('invalid');
110
+ if (attr('aria-readonly') === 'true')
111
+ states.push('read only');
112
+ const current = attr('aria-current');
113
+ if (isOn(current))
114
+ states.push(current === 'true' ? 'current' : `current ${current}`);
115
+ const haspopup = attr('aria-haspopup');
116
+ if (isOn(haspopup))
117
+ states.push(haspopup === 'true' ? 'has popup' : `has ${haspopup} popup`);
118
+ const level = attr('aria-level') ?? headingLevel(element);
119
+ if (level)
120
+ states.push(`level ${level}`);
121
+ const posinset = attr('aria-posinset');
122
+ const setsize = attr('aria-setsize');
123
+ if (posinset && setsize)
124
+ states.push(`${posinset} of ${setsize}`);
125
+ return states;
126
+ }
127
+ /** The heading level for a native `h1`–`h6`, else null. */
128
+ function headingLevel(element) {
129
+ const match = /^h([1-6])$/.exec(element.tagName.toLowerCase());
130
+ return match ? match[1] : null;
131
+ }
package/dist/overlay.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { A11yFinding } from './scan.js';
2
2
  import type { TabStop } from './keyboard/tab-sequence.js';
3
+ import type { AxDescription } from './keyboard/accname.js';
3
4
  /**
4
5
  * Attribute marking the overlay's own DOM. `scan()` excludes anything under it
5
6
  * so the tool never reports violations against its own highlights.
@@ -7,6 +8,13 @@ import type { TabStop } from './keyboard/tab-sequence.js';
7
8
  export declare const OVERLAY_ATTR = "data-ngb-a11y-overlay";
8
9
  /** Selector form of {@link OVERLAY_ATTR}, passed to axe as an exclude. */
9
10
  export declare const OVERLAY_EXCLUDE_SELECTOR = "[data-ngb-a11y-overlay]";
11
+ /** The computed accessibility-tree info shown in the focus-follow panel. */
12
+ export interface AxPanelData extends AxDescription {
13
+ /** Owning component of the focused element, or null. */
14
+ component: string | null;
15
+ /** Tag name of the focused element, for context (e.g. `div`, `button`). */
16
+ tag: string;
17
+ }
10
18
  export interface A11yOverlay {
11
19
  /** Draw a highlight over each finding's node, replacing the previous set. */
12
20
  render(findings: A11yFinding[]): void;
@@ -15,6 +23,12 @@ export interface A11yOverlay {
15
23
  * independent of the findings highlights. Replaces the previous tab-order set.
16
24
  */
17
25
  renderTabOrder(stops: TabStop[]): void;
26
+ /**
27
+ * Show the accessibility-tree preview panel for the focused element, or hide it
28
+ * when passed `null`. Deliberately framed as a *computed approximation* — see
29
+ * the panel header — never as verbatim screen-reader output.
30
+ */
31
+ renderAxPanel(data: AxPanelData | null): void;
18
32
  /** Remove all highlights but keep the overlay live. */
19
33
  clear(): void;
20
34
  /** Remove the tab-order layer but keep the overlay live. */
package/dist/overlay.js CHANGED
@@ -2,6 +2,9 @@ const SVG_NS = 'http://www.w3.org/2000/svg';
2
2
  /** Tab-order path + badge colours: normal teal, warning orange for positive tabindex. */
3
3
  const TAB_ORDER_COLOR = '#0b8f8f';
4
4
  const TAB_ORDER_WARN_COLOR = '#e8710a';
5
+ /** How far outside a control's left edge the tab-order badge sits, and its min viewport x. */
6
+ const TAB_BADGE_GUTTER = 10;
7
+ const TAB_BADGE_MIN_X = 9;
5
8
  /**
6
9
  * Attribute marking the overlay's own DOM. `scan()` excludes anything under it
7
10
  * so the tool never reports violations against its own highlights.
@@ -59,6 +62,27 @@ export function createOverlay(options = {}) {
59
62
  connector.setAttribute('opacity', '0.7');
60
63
  svg.appendChild(connector);
61
64
  container.appendChild(svg); // under the badges, which are appended later
65
+ // The accessibility-tree preview panel: a fixed card that follows focus. Hidden
66
+ // until renderAxPanel is called with data. Marked with OVERLAY_ATTR so scans
67
+ // never flag the tool's own UI.
68
+ const axPanel = doc.createElement('div');
69
+ axPanel.setAttribute(OVERLAY_ATTR, '');
70
+ Object.assign(axPanel.style, {
71
+ position: 'fixed',
72
+ right: '12px',
73
+ bottom: '12px',
74
+ maxWidth: '320px',
75
+ padding: '8px 10px',
76
+ borderRadius: '6px',
77
+ background: 'rgba(20,22,28,0.94)',
78
+ color: '#f4f4f5',
79
+ font: '12px/1.5 ui-sans-serif, system-ui, sans-serif',
80
+ boxShadow: '0 2px 12px rgba(0,0,0,0.4)',
81
+ pointerEvents: 'none',
82
+ zIndex: '2147483647',
83
+ display: 'none',
84
+ });
85
+ container.appendChild(axPanel);
62
86
  let highlights = [];
63
87
  let tabBadges = [];
64
88
  const reposition = () => {
@@ -71,9 +95,16 @@ export function createOverlay(options = {}) {
71
95
  const points = [];
72
96
  for (const { target, badge } of tabBadges) {
73
97
  const rect = target.getBoundingClientRect();
74
- badge.style.top = `${rect.top}px`;
75
- badge.style.left = `${rect.left}px`;
76
- points.push(`${rect.left + rect.width / 2},${rect.top + rect.height / 2}`);
98
+ // Anchor the badge just OUTSIDE the left edge, vertically centred, so it
99
+ // clears the findings labels that sit along the top-left corner (a
100
+ // corner-anchored badge collided with them). Clamp x into the viewport so a
101
+ // control flush to the left edge still shows its badge. The connector
102
+ // threads these same points.
103
+ const y = rect.top + rect.height / 2;
104
+ const x = Math.max(TAB_BADGE_MIN_X, rect.left - TAB_BADGE_GUTTER);
105
+ badge.style.top = `${y}px`;
106
+ badge.style.left = `${x}px`;
107
+ points.push(`${x},${y}`);
77
108
  }
78
109
  connector.setAttribute('points', points.join(' '));
79
110
  }
@@ -132,14 +163,63 @@ export function createOverlay(options = {}) {
132
163
  }
133
164
  repositionTabOrder();
134
165
  }
166
+ function renderAxPanel(data) {
167
+ if (!data) {
168
+ axPanel.style.display = 'none';
169
+ axPanel.replaceChildren();
170
+ return;
171
+ }
172
+ axPanel.replaceChildren(...buildAxPanelContent(doc, data));
173
+ axPanel.style.display = 'block';
174
+ }
135
175
  function destroy() {
136
176
  clear();
137
177
  clearTabOrder();
178
+ renderAxPanel(null);
138
179
  win?.removeEventListener('scroll', onViewportChange, { capture: true });
139
180
  win?.removeEventListener('resize', onViewportChange);
140
181
  container.remove();
141
182
  }
142
- return { render, renderTabOrder, clear, clearTabOrder, destroy };
183
+ return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
184
+ }
185
+ /** The rows of the accessibility-tree preview panel, honesty header first. */
186
+ function buildAxPanelContent(doc, data) {
187
+ const nodes = [];
188
+ const header = doc.createElement('div');
189
+ header.textContent = 'Accessibility-tree preview — computed approximation';
190
+ Object.assign(header.style, {
191
+ fontWeight: '700',
192
+ fontSize: '10px',
193
+ letterSpacing: '0.02em',
194
+ textTransform: 'uppercase',
195
+ color: '#a9b0bd',
196
+ marginBottom: '4px',
197
+ });
198
+ header.title = 'A computed name/role/state — an approximation of what assistive tech announces, not any one screen reader.';
199
+ nodes.push(header);
200
+ const row = (label, value, muted = false) => {
201
+ const div = doc.createElement('div');
202
+ const key = doc.createElement('span');
203
+ key.textContent = `${label}: `;
204
+ key.style.color = '#a9b0bd';
205
+ const val = doc.createElement('span');
206
+ val.textContent = value;
207
+ if (muted)
208
+ val.style.color = '#e8710a'; // draw the eye to a missing name
209
+ div.append(key, val);
210
+ return div;
211
+ };
212
+ nodes.push(row('role', data.role ?? `(none — <${data.tag}>)`));
213
+ nodes.push(data.name
214
+ ? row('name', `"${data.name}"`)
215
+ : row('name', '(no accessible name)', true));
216
+ if (data.description)
217
+ nodes.push(row('description', `"${data.description}"`));
218
+ if (data.states.length)
219
+ nodes.push(row('states', data.states.join(', ')));
220
+ if (data.component)
221
+ nodes.push(row('component', data.component));
222
+ return nodes;
143
223
  }
144
224
  /**
145
225
  * A numbered badge marking one tab stop, anchored at the target's top-left
package/dist/provider.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { ApplicationRef, DestroyRef, inject, isDevMode, makeEnvironmentProviders, provideEnvironmentInitializer, } from '@angular/core';
2
2
  import { debounceTime, filter } from 'rxjs';
3
3
  import { runA11yScan } from './runner.js';
4
- import { createOverlay } from './overlay.js';
4
+ import { createOverlay, OVERLAY_ATTR } from './overlay.js';
5
5
  import { tabSequence } from './keyboard/tab-sequence.js';
6
+ import { describeElement } from './keyboard/accname.js';
7
+ import { resolveOwningComponentName } from './attribution.js';
6
8
  /**
7
9
  * Dev-only in-app accessibility auditing. Rescans whenever the application
8
10
  * settles (zoneless-aware, via `ApplicationRef.isStable`) and reports each
@@ -25,6 +27,26 @@ export function provideA11yDevtools(options = {}) {
25
27
  const appRef = inject(ApplicationRef);
26
28
  const destroyRef = inject(DestroyRef);
27
29
  const overlayView = overlay ? createOverlay() : undefined;
30
+ // Keyboard & Focus Mode, part C: a focus-follow accessibility-tree preview.
31
+ // As the user Tabs, show the focused control's computed role/name/state —
32
+ // the ~2/3 axe can't test — attributed to its component. Only meaningful
33
+ // with the visual overlay on.
34
+ let onFocusIn;
35
+ if (overlayView && keyboard) {
36
+ onFocusIn = (event) => {
37
+ const el = event.target;
38
+ if (!(el instanceof Element) || el.closest(`[${OVERLAY_ATTR}]`))
39
+ return; // skip our own UI
40
+ describeElement(el)
41
+ .then((desc) => overlayView.renderAxPanel({
42
+ ...desc,
43
+ component: resolveOwningComponentName(el, frameworkPrefixes),
44
+ tag: el.tagName.toLowerCase(),
45
+ }))
46
+ .catch(() => undefined);
47
+ };
48
+ document.addEventListener('focusin', onFocusIn, true);
49
+ }
28
50
  let scanning = false;
29
51
  const subscription = appRef.isStable
30
52
  .pipe(filter((stable) => stable), debounceTime(debounceMs))
@@ -48,6 +70,8 @@ export function provideA11yDevtools(options = {}) {
48
70
  });
49
71
  destroyRef.onDestroy(() => {
50
72
  subscription.unsubscribe();
73
+ if (onFocusIn)
74
+ document.removeEventListener('focusin', onFocusIn, true);
51
75
  overlayView?.destroy();
52
76
  });
53
77
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",