@ngbracket/a11y-devtools 0.15.4 → 0.15.6

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,43 @@
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.15.6
7
+
8
+ ### Fixed
9
+
10
+ - **The Focus preview card is now headed "Focus preview".** It used to say
11
+ "Accessibility-tree preview", which didn't match the "Focus preview" setting
12
+ in the pill menu, so the card and its switch were hard to connect. It is
13
+ still labelled a computed approximation.
14
+ - **Turning Focus preview on shows the card without waiting for focus to
15
+ move.** Before, nothing appeared until focus next moved. Now, switching the
16
+ setting on describes the control that already has focus; switching the whole
17
+ tool on does the same once its first scan finishes. When you toggle it
18
+ from the pill menu, it describes the page control you were on before.
19
+ - **The Focus preview no longer shows an empty name while a scan is running.**
20
+ axe can't compute an accessible name during its own run, so a control
21
+ focused mid-scan showed "(no accessible name)". The preview now waits for the
22
+ scan to finish and describes only the latest focus. A `describeElement` call
23
+ made during a scan also no longer tears down the scan's axe tree, which had
24
+ silently dropped that scan's findings.
25
+
26
+ ## 0.15.5
27
+
28
+ ### Fixed
29
+
30
+ - **`ngbr/unreachable-control` accepts one roving tab stop shared by several
31
+ widgets.** A kanban board with a `role="listbox"` per column and a single tab
32
+ stop for the whole board had every card in the other columns reported as
33
+ serious, although Tab reaches the board and the arrow keys cross columns. An
34
+ item is now also reachable when another widget of the same role, inside the
35
+ same component and repeated alongside it (the same element with the same
36
+ classes, as a `@for` over columns renders; Angular's `ng-*` classes and BEM
37
+ `--modifiers` are ignored), has a tabbable item of the same role. So a
38
+ working listbox can't vouch for an unrelated broken one elsewhere in the
39
+ template, and key handling is still required. Development builds only: it
40
+ needs Angular's debug API to find the component, so a production-build scan
41
+ still reports these items. Found on our own docs: 13 false positives → 0.
42
+
6
43
  ## 0.15.4
7
44
 
8
45
  ### Fixed
package/README.md CHANGED
@@ -26,7 +26,7 @@ Part of the `@ngbracket` Angular tooling family.
26
26
  - **Dark mode**: scan your dark theme too, whether it follows the OS setting, a
27
27
  class, an attribute, or custom logic.
28
28
  - **Keyboard & Focus Mode**: tab-order visualisation, keyboard findings,
29
- accessibility-tree preview, and keyboard-trap detection with real Tab presses.
29
+ Focus preview (computed role, name and state), and keyboard-trap detection with real Tab presses.
30
30
  - **Zero production weight**: a no-op in production; axe-core is never loaded.
31
31
 
32
32
  ## Install
@@ -34483,7 +34483,7 @@
34483
34483
  function buildAxPanelContent(doc, data) {
34484
34484
  const nodes = [];
34485
34485
  const header = doc.createElement("div");
34486
- header.textContent = "Accessibility-tree preview \u2014 computed approximation";
34486
+ header.textContent = "Focus preview \u2014 computed approximation";
34487
34487
  Object.assign(header.style, {
34488
34488
  fontWeight: "700",
34489
34489
  fontSize: "10px",
@@ -34838,7 +34838,7 @@
34838
34838
  return events.some((e) => KEY_EVENTS.includes(e.split(".")[0]));
34839
34839
  }
34840
34840
  var COMPOSITE_SELECTOR = ["tablist", "toolbar", "menu", "menubar", "radiogroup", "listbox", "tree", "treegrid", "grid"].map((role) => `[role="${role}"]`).join(",");
34841
- function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map()) {
34841
+ function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map(), sharedCache = /* @__PURE__ */ new Map()) {
34842
34842
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
34843
34843
  if (!widget)
34844
34844
  return false;
@@ -34848,7 +34848,7 @@
34848
34848
  const tabindex = element.getAttribute("tabindex");
34849
34849
  if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
34850
34850
  return false;
34851
- const enterable = isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible);
34851
+ const enterable = isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible) || sharesRovingStop(widget, element, isVisible, sharedCache);
34852
34852
  if (!enterable)
34853
34853
  return false;
34854
34854
  if (!listenersVisible())
@@ -34873,6 +34873,63 @@
34873
34873
  const keyed = (el) => hasKeyEvent(resolveListenerEvents(el));
34874
34874
  return [widget, ...controllers, ...ancestors].some(keyed) || [...widget.querySelectorAll("*")].some(keyed);
34875
34875
  }
34876
+ function sharesRovingStop(widget, item, isVisible, cache) {
34877
+ const role = item.getAttribute("role") ?? "";
34878
+ let byRole = cache.get(widget);
34879
+ if (!byRole)
34880
+ cache.set(widget, byRole = /* @__PURE__ */ new Map());
34881
+ let result = byRole.get(role);
34882
+ if (result === void 0)
34883
+ byRole.set(role, result = findsRepeatedSiblingStop(widget, item, isVisible));
34884
+ return result;
34885
+ }
34886
+ function findsRepeatedSiblingStop(widget, item, isVisible) {
34887
+ const ng = ngDebug();
34888
+ const widgetRole = widget.getAttribute("role");
34889
+ const itemRole = item.getAttribute("role");
34890
+ if (!ng || !widgetRole || !itemRole)
34891
+ return false;
34892
+ let host = null;
34893
+ for (let el = widget.parentElement; el; el = el.parentElement) {
34894
+ if (isComponentHost(el, ng)) {
34895
+ host = el;
34896
+ break;
34897
+ }
34898
+ }
34899
+ if (!host)
34900
+ return false;
34901
+ for (const other of host.querySelectorAll(`[role="${widgetRole}"] [role="${itemRole}"]`)) {
34902
+ const otherWidget = other.parentElement?.closest(COMPOSITE_SELECTOR);
34903
+ if (!otherWidget || otherWidget === widget || otherWidget.getAttribute("role") !== widgetRole)
34904
+ continue;
34905
+ if (!isTabbable(other, isVisible))
34906
+ continue;
34907
+ if (repeatedSiblings(widget, otherWidget, host))
34908
+ return true;
34909
+ }
34910
+ return false;
34911
+ }
34912
+ function repeatedSiblings(a, b, bound) {
34913
+ if (a.contains(b) || b.contains(a))
34914
+ return false;
34915
+ for (let branchA = a; branchA && branchA !== bound; branchA = branchA.parentElement) {
34916
+ const parent = branchA.parentElement;
34917
+ if (!parent || !parent.contains(b))
34918
+ continue;
34919
+ let branchB = b;
34920
+ while (branchB && branchB.parentElement !== parent)
34921
+ branchB = branchB.parentElement;
34922
+ if (!branchB || branchB === branchA || branchB.tagName !== branchA.tagName)
34923
+ return false;
34924
+ const setA = structuralClasses(branchA);
34925
+ const setB = structuralClasses(branchB);
34926
+ return setA.length > 0 && setA.length === setB.length && setA.every((c) => setB.includes(c));
34927
+ }
34928
+ return false;
34929
+ }
34930
+ function structuralClasses(el) {
34931
+ return [...el.classList].filter((c) => !c.startsWith("ng-") && !c.includes("--")).sort();
34932
+ }
34876
34933
  function isComponentHost(el, ng) {
34877
34934
  try {
34878
34935
  return ng?.getComponent(el) != null;
@@ -34881,10 +34938,10 @@
34881
34938
  }
34882
34939
  }
34883
34940
  var ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).join(",");
34884
- function partOfKeyboardOperatedWidget(element, isVisible, keyCache) {
34941
+ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache) {
34885
34942
  const item = element.parentElement?.closest(ITEM_SELECTOR);
34886
34943
  if (item?.parentElement?.closest(COMPOSITE_SELECTOR)) {
34887
- if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache))
34944
+ if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache, sharedCache))
34888
34945
  return true;
34889
34946
  }
34890
34947
  for (let el = element.parentElement; el; el = el.parentElement) {
@@ -34911,6 +34968,7 @@
34911
34968
  const isVisible = options.isVisible;
34912
34969
  const findings = [];
34913
34970
  const keyCache = /* @__PURE__ */ new Map();
34971
+ const sharedCache = /* @__PURE__ */ new Map();
34914
34972
  const make = (element, id, impact, help, helpUrl) => {
34915
34973
  const componentPath = resolveComponentPath(element);
34916
34974
  return {
@@ -34944,9 +35002,9 @@
34944
35002
  continue;
34945
35003
  const focusable = isTabbable(element, isVisible);
34946
35004
  if (!focusable) {
34947
- if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache))
35005
+ if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
34948
35006
  continue;
34949
- const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache) : false;
35007
+ const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
34950
35008
  if (within === "reached")
34951
35009
  continue;
34952
35010
  if (within === "no-keys") {
@@ -30,8 +30,10 @@ export async function describeElement(element) {
30
30
  const doc = element.ownerDocument ?? document;
31
31
  let role = null;
32
32
  let name = '';
33
+ let didSetup = false;
33
34
  try {
34
35
  axe.setup(doc);
36
+ didSetup = true;
35
37
  const vnode = axe.utils.getNodeFromTree(element);
36
38
  role = axe.commons.aria.getRole(element) ?? null;
37
39
  name = vnode ? (axe.commons.text.accessibleTextVirtual(vnode) ?? '') : '';
@@ -40,11 +42,15 @@ export async function describeElement(element) {
40
42
  // Leave role=null / name='' — axe couldn't build a tree (e.g. run in flight).
41
43
  }
42
44
  finally {
43
- try {
44
- axe.teardown();
45
- }
46
- catch {
47
- /* nothing set up */
45
+ // Only tear down our own setup: a failed setup means a scan owns axe's tree,
46
+ // and tearing that down would silently drop the scan's findings.
47
+ if (didSetup) {
48
+ try {
49
+ axe.teardown();
50
+ }
51
+ catch {
52
+ /* nothing set up */
53
+ }
48
54
  }
49
55
  }
50
56
  return { role, name, description: accessibleDescription(element), states: ariaStates(element) };
@@ -66,7 +66,7 @@ const COMPOSITE_SELECTOR = ['tablist', 'toolbar', 'menu', 'menubar', 'radiogroup
66
66
  * Key listeners are read through Angular's dev-mode debug API. Without it (a
67
67
  * production build) nothing can be seen, so roving tabindex counts as reached.
68
68
  */
69
- function reachedWithinWidget(element, isVisible, keyCache = new Map()) {
69
+ function reachedWithinWidget(element, isVisible, keyCache = new Map(), sharedCache = new Map()) {
70
70
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
71
71
  if (!widget)
72
72
  return false;
@@ -80,7 +80,10 @@ function reachedWithinWidget(element, isVisible, keyCache = new Map()) {
80
80
  const tabindex = element.getAttribute('tabindex');
81
81
  if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
82
82
  return false;
83
- const enterable = isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible);
83
+ const enterable = isTabbable(widget, isVisible) ||
84
+ controllers.length > 0 ||
85
+ hasTabbableDescendant(widget, isVisible) ||
86
+ sharesRovingStop(widget, element, isVisible, sharedCache);
84
87
  if (!enterable)
85
88
  return false;
86
89
  if (!listenersVisible())
@@ -116,6 +119,87 @@ function handlesKeys(widget, controllers) {
116
119
  // Cheapest first; the widget's contents (every cell of a grid) last.
117
120
  return [widget, ...controllers, ...ancestors].some(keyed) || [...widget.querySelectorAll('*')].some(keyed);
118
121
  }
122
+ /**
123
+ * True when `widget` is one of several same-role widgets that share a single
124
+ * roving tab stop: a kanban board with a `role="listbox"` per column and one tab
125
+ * stop for the whole board, where arrow keys cross columns. A column without the
126
+ * current card has no tabbable item of its own, but Tab still reaches the board.
127
+ *
128
+ * Accepted when another widget of the same role holds a tabbable item of the
129
+ * same role, both inside the nearest component host, AND the two are repeated
130
+ * siblings: where their branches meet, each branch is the same element with the
131
+ * same classes (what a `@for` over columns renders), ignoring Angular's own
132
+ * `ng-*` classes and BEM modifiers (`--full`), which vary by state. So a working
133
+ * listbox can't vouch for an unrelated broken one in another part of the same
134
+ * template. Needs Angular's debug API to find the host; without it (a
135
+ * production build) it never applies.
136
+ */
137
+ function sharesRovingStop(widget, item, isVisible, cache) {
138
+ // Per widget AND item role: a menu can mix menuitem and menuitemradio.
139
+ const role = item.getAttribute('role') ?? '';
140
+ let byRole = cache.get(widget);
141
+ if (!byRole)
142
+ cache.set(widget, (byRole = new Map()));
143
+ let result = byRole.get(role);
144
+ if (result === undefined)
145
+ byRole.set(role, (result = findsRepeatedSiblingStop(widget, item, isVisible)));
146
+ return result;
147
+ }
148
+ function findsRepeatedSiblingStop(widget, item, isVisible) {
149
+ const ng = ngDebug();
150
+ const widgetRole = widget.getAttribute('role');
151
+ const itemRole = item.getAttribute('role');
152
+ if (!ng || !widgetRole || !itemRole)
153
+ return false;
154
+ let host = null;
155
+ for (let el = widget.parentElement; el; el = el.parentElement) {
156
+ if (isComponentHost(el, ng)) {
157
+ host = el;
158
+ break;
159
+ }
160
+ }
161
+ if (!host)
162
+ return false;
163
+ for (const other of host.querySelectorAll(`[role="${widgetRole}"] [role="${itemRole}"]`)) {
164
+ const otherWidget = other.parentElement?.closest(COMPOSITE_SELECTOR);
165
+ if (!otherWidget || otherWidget === widget || otherWidget.getAttribute('role') !== widgetRole)
166
+ continue;
167
+ if (!isTabbable(other, isVisible))
168
+ continue;
169
+ if (repeatedSiblings(widget, otherWidget, host))
170
+ return true;
171
+ }
172
+ return false;
173
+ }
174
+ /**
175
+ * True when `a` and `b` sit in sibling branches of the same kind: below their
176
+ * lowest common ancestor (inside `bound`), the branch holding each is the same
177
+ * tag with the same (non-empty) set of classes, once Angular's `ng-*` classes
178
+ * (e.g. `ng-star-inserted` from the animations module) and BEM modifiers are
179
+ * set aside. Unclassed wrappers never match: the safe direction.
180
+ */
181
+ function repeatedSiblings(a, b, bound) {
182
+ if (a.contains(b) || b.contains(a))
183
+ return false;
184
+ for (let branchA = a; branchA && branchA !== bound; branchA = branchA.parentElement) {
185
+ const parent = branchA.parentElement;
186
+ if (!parent || !parent.contains(b))
187
+ continue;
188
+ let branchB = b;
189
+ while (branchB && branchB.parentElement !== parent)
190
+ branchB = branchB.parentElement;
191
+ if (!branchB || branchB === branchA || branchB.tagName !== branchA.tagName)
192
+ return false;
193
+ const setA = structuralClasses(branchA);
194
+ const setB = structuralClasses(branchB);
195
+ return setA.length > 0 && setA.length === setB.length && setA.every((c) => setB.includes(c));
196
+ }
197
+ return false;
198
+ }
199
+ /** Classes that say what an element is, not its state: no `ng-*`, no BEM `--modifier`. */
200
+ function structuralClasses(el) {
201
+ return [...el.classList].filter((c) => !c.startsWith('ng-') && !c.includes('--')).sort();
202
+ }
119
203
  function isComponentHost(el, ng) {
120
204
  try {
121
205
  return ng?.getComponent(el) != null;
@@ -135,11 +219,11 @@ const ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).j
135
219
  * keys. `<body>` is never tabbable, so a page-wide shortcut listener doesn't
136
220
  * count.
137
221
  */
138
- function partOfKeyboardOperatedWidget(element, isVisible, keyCache) {
222
+ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache) {
139
223
  const item = element.parentElement?.closest(ITEM_SELECTOR);
140
224
  if (item?.parentElement?.closest(COMPOSITE_SELECTOR)) {
141
225
  // 'no-keys' too: the item itself is reported, so its parts needn't be.
142
- if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache))
226
+ if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache, sharedCache))
143
227
  return true;
144
228
  }
145
229
  for (let el = element.parentElement; el; el = el.parentElement) {
@@ -182,6 +266,7 @@ export function scanKeyboard(root = document, options = {}) {
182
266
  const isVisible = options.isVisible;
183
267
  const findings = [];
184
268
  const keyCache = new Map();
269
+ const sharedCache = new Map();
185
270
  const make = (element, id, impact, help, helpUrl) => {
186
271
  const componentPath = resolveComponentPath(element);
187
272
  return {
@@ -226,9 +311,9 @@ export function scanKeyboard(root = document, options = {}) {
226
311
  if (!focusable) {
227
312
  // A click-only part of something the keyboard operates is a mouse shortcut.
228
313
  // Only for unreachable elements: one Tab reaches is still checked below.
229
- if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache))
314
+ if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
230
315
  continue;
231
- const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache) : false;
316
+ const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
232
317
  if (within === 'reached')
233
318
  continue;
234
319
  if (within === 'no-keys') {
package/dist/overlay.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface A11yOverlay {
24
24
  */
25
25
  renderTabOrder(stops: TabStop[]): void;
26
26
  /**
27
- * Show the accessibility-tree preview panel for the focused element, or hide it
27
+ * Show the Focus preview panel (an accessibility-tree approximation) for the focused element, or hide it
28
28
  * when passed `null`. Deliberately framed as a *computed approximation* — see
29
29
  * the panel header — never as verbatim screen-reader output.
30
30
  */
package/dist/overlay.js CHANGED
@@ -74,7 +74,7 @@ export function createOverlay(options = {}) {
74
74
  connector.setAttribute('opacity', '0.7');
75
75
  svg.appendChild(connector);
76
76
  container.appendChild(svg); // under the badges, which are appended later
77
- // The accessibility-tree preview panel: a fixed card that follows focus. Hidden
77
+ // The Focus preview panel: a fixed card that follows focus. Hidden
78
78
  // until renderAxPanel is called with data. Marked with OVERLAY_ATTR so scans
79
79
  // never flag the tool's own UI.
80
80
  const axPanel = doc.createElement('div');
@@ -223,11 +223,11 @@ export function createOverlay(options = {}) {
223
223
  }
224
224
  return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
225
225
  }
226
- /** The rows of the accessibility-tree preview panel, honesty header first. */
226
+ /** The rows of the Focus preview panel, honesty header first. */
227
227
  function buildAxPanelContent(doc, data) {
228
228
  const nodes = [];
229
229
  const header = doc.createElement('div');
230
- header.textContent = 'Accessibility-tree preview — computed approximation';
230
+ header.textContent = 'Focus preview — computed approximation';
231
231
  Object.assign(header.style, {
232
232
  fontWeight: '700',
233
233
  fontSize: '10px',
package/dist/provider.js CHANGED
@@ -82,21 +82,37 @@ function devtoolsProviders(options) {
82
82
  if (!settings.focusPreview)
83
83
  overlayView.renderAxPanel(null);
84
84
  }
85
+ /**
86
+ * On turning the preview (or the tool) on, describe what's already focused —
87
+ * or, when focus is in our own pill menu (the toggle was just clicked), the
88
+ * page control that had focus before it.
89
+ */
90
+ function previewCurrentFocus() {
91
+ const active = document.activeElement;
92
+ const ours = active instanceof Element && active.closest(`[${OVERLAY_ATTR}]`);
93
+ previewFocus(ours ? (lastPageFocus?.isConnected ? lastPageFocus : null) : active);
94
+ }
85
95
  const setEnabled = (next) => {
86
96
  if (next === enabled)
87
97
  return;
88
98
  enabled = next;
89
99
  writeStoredEnabled(storage, enabled);
90
100
  pillView?.setEnabled(enabled);
91
- if (enabled)
101
+ if (enabled) {
92
102
  scanNow(); // don't wait for the app's next stable moment
93
- else
103
+ previewCurrentFocus();
104
+ }
105
+ else {
94
106
  draw();
107
+ }
95
108
  };
96
109
  const setSettings = (next) => {
110
+ const previewTurnedOn = next.focusPreview && !settings.focusPreview;
97
111
  settings = next;
98
112
  writeStoredSettings(storage, settings, defaultSettings);
99
113
  draw();
114
+ if (previewTurnedOn)
115
+ previewCurrentFocus();
100
116
  };
101
117
  const downloadReport = () => {
102
118
  import('./report/html.js')
@@ -139,38 +155,63 @@ function devtoolsProviders(options) {
139
155
  // the ~2/3 axe can't test — attributed to its component. Needs the visual
140
156
  // overlay; shown while the Focus preview setting is on.
141
157
  let onFocusIn;
158
+ // The last page control (not our own UI) that had focus, for previewCurrentFocus.
159
+ let lastPageFocus;
142
160
  if (overlayView) {
143
161
  onFocusIn = (event) => {
144
- if (!enabled || !settings.focusPreview)
145
- return;
146
162
  const el = event.target;
147
- if (!(el instanceof Element) || el.closest(`[${OVERLAY_ATTR}]`))
148
- return; // skip our own UI
149
- describeElement(el)
150
- .then((desc) => {
151
- if (!enabled || !settings.focusPreview)
152
- return; // switched off while describing
153
- overlayView.renderAxPanel({
154
- ...desc,
155
- component: resolveOwningComponentName(el, frameworkPrefixes),
156
- tag: el.tagName.toLowerCase(),
157
- });
158
- })
159
- .catch(() => undefined);
163
+ if (el instanceof Element && !el.closest(`[${OVERLAY_ATTR}]`))
164
+ lastPageFocus = el;
165
+ previewFocus(el);
160
166
  };
161
167
  document.addEventListener('focusin', onFocusIn, true);
162
168
  }
163
- let scanning = false;
169
+ // Bumped on every preview request, so only the latest focus is described.
170
+ let previewGen = 0;
171
+ /** Show the Focus preview card for `el`, unless it's our own UI or the page body. */
172
+ function previewFocus(el) {
173
+ if (!overlayView || !enabled || !settings.focusPreview)
174
+ return;
175
+ if (!(el instanceof Element) || el === document.body || el === document.documentElement)
176
+ return;
177
+ if (el.closest(`[${OVERLAY_ATTR}]`))
178
+ return; // skip our own UI
179
+ const gen = ++previewGen;
180
+ const stale = () => gen !== previewGen || !enabled || !settings.focusPreview;
181
+ // axe can't build an accname tree while a scan has it set up, so wait
182
+ // until no scan is running rather than show an empty name.
183
+ scansIdle()
184
+ .then(() => (stale() || !el.isConnected ? null : describeElement(el)))
185
+ .then((desc) => {
186
+ if (!desc || stale())
187
+ return; // focus moved on, or switched off while waiting
188
+ overlayView.renderAxPanel({
189
+ ...desc,
190
+ component: resolveOwningComponentName(el, frameworkPrefixes),
191
+ tag: el.tagName.toLowerCase(),
192
+ });
193
+ })
194
+ .catch(() => undefined);
195
+ }
196
+ let currentScan;
164
197
  let rescanQueued = false;
198
+ /**
199
+ * Resolves once no scan is running (a queued rescan starts as one ends).
200
+ * Gives up after a few back-to-back scans, so an app that keeps re-settling
201
+ * can't hold the preview back for ever.
202
+ */
203
+ async function scansIdle() {
204
+ for (let waits = 0; currentScan && waits < 3; waits++)
205
+ await currentScan;
206
+ }
165
207
  function scanNow() {
166
208
  if (!enabled)
167
209
  return;
168
- if (scanning) {
210
+ if (currentScan) {
169
211
  rescanQueued = true; // don't stack scans; run one more when this finishes
170
212
  return;
171
213
  }
172
- scanning = true;
173
- runA11yScan(root?.(), { log, logger, axe, frameworkPrefixes, keyboard })
214
+ currentScan = runA11yScan(root?.(), { log, logger, axe, frameworkPrefixes, keyboard })
174
215
  .then((findings) => {
175
216
  if (!enabled)
176
217
  return; // switched off mid-scan: draw nothing
@@ -182,7 +223,7 @@ function devtoolsProviders(options) {
182
223
  })
183
224
  .catch(() => undefined)
184
225
  .finally(() => {
185
- scanning = false;
226
+ currentScan = undefined;
186
227
  if (rescanQueued) {
187
228
  rescanQueued = false;
188
229
  scanNow();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.15.4",
3
+ "version": "0.15.6",
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",