@ngbracket/a11y-devtools 0.7.0 → 0.7.2

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,29 @@
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.2
7
+
8
+ ### Fixed
9
+
10
+ - **Findings labels no longer cover each other.** Where several flagged nodes
11
+ cluster (or share a column), each finding's label was drawn at its box's
12
+ top-left corner, so the labels piled on the same spot and the later one hid the
13
+ earlier — e.g. a `color-contrast` label sitting behind a `region` label. The
14
+ overlay now runs a de-collision pass (`resolveLabelStack`) that walks labels
15
+ top-to-bottom and lifts each one until it clears the labels already placed, so
16
+ every finding stays readable. Runs on render and on scroll/resize.
17
+
18
+ ## 0.7.1
19
+
20
+ ### Fixed
21
+
22
+ - **Tab-order badges no longer collide with the findings labels.** A numbered
23
+ tab-order badge was anchored on each control's top-left corner — exactly where
24
+ the severity-coloured finding labels sit — so on a flagged control the two
25
+ overlapped and obscured each other. Badges now sit just outside the control's
26
+ left edge, vertically centred (clamped into the viewport for controls flush to
27
+ the left), and the connector path threads those points.
28
+
6
29
  ## 0.7.0
7
30
 
8
31
  ### Added
package/README.md CHANGED
@@ -161,7 +161,15 @@ component that placed it and notes the primitive as `(via …)`.
161
161
  axe covers the machine-testable third of WCAG. **Keyboard & Focus Mode** starts on
162
162
  the rest — keyboard operability — still naming the component that owns each issue.
163
163
  Turn it on with `keyboard: true` (provider / `runA11yScan` / `scan` / `scanPages`)
164
- 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:
165
173
 
166
174
  - **Tab-order visualisation** (overlay): numbered badges at each tab stop and a
167
175
  connector path showing the order focus actually moves. A positive-`tabindex` stop
@@ -34226,6 +34226,9 @@
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;
34231
+ var LABEL_MIN_TOP = 2;
34229
34232
  var OVERLAY_ATTR = "data-ngb-a11y-overlay";
34230
34233
  var OVERLAY_EXCLUDE_SELECTOR = `[${OVERLAY_ATTR}]`;
34231
34234
  var IMPACT_COLOR = {
@@ -34292,15 +34295,35 @@
34292
34295
  for (const { target, box } of highlights) {
34293
34296
  positionBox(box, target);
34294
34297
  }
34298
+ decollideLabels();
34295
34299
  repositionTabOrder();
34296
34300
  };
34301
+ function decollideLabels() {
34302
+ const labels = [];
34303
+ const boxes = [];
34304
+ for (const { target, box } of highlights) {
34305
+ const label = box.firstElementChild;
34306
+ if (!label)
34307
+ continue;
34308
+ const rect = target.getBoundingClientRect();
34309
+ labels.push(label);
34310
+ boxes.push({ left: rect.left, width: label.offsetWidth, baseTop: rect.top - label.offsetHeight, height: label.offsetHeight });
34311
+ }
34312
+ const tops = resolveLabelStack(boxes);
34313
+ for (let i = 0; i < labels.length; i++) {
34314
+ const extraUp = boxes[i].baseTop - tops[i];
34315
+ labels[i].style.transform = extraUp > 0 ? `translateY(calc(-100% - ${extraUp}px))` : "translateY(-100%)";
34316
+ }
34317
+ }
34297
34318
  function repositionTabOrder() {
34298
34319
  const points = [];
34299
34320
  for (const { target, badge } of tabBadges) {
34300
34321
  const rect = target.getBoundingClientRect();
34301
- badge.style.top = `${rect.top}px`;
34302
- badge.style.left = `${rect.left}px`;
34303
- points.push(`${rect.left + rect.width / 2},${rect.top + rect.height / 2}`);
34322
+ const y = rect.top + rect.height / 2;
34323
+ const x = Math.max(TAB_BADGE_MIN_X, rect.left - TAB_BADGE_GUTTER);
34324
+ badge.style.top = `${y}px`;
34325
+ badge.style.left = `${x}px`;
34326
+ points.push(`${x},${y}`);
34304
34327
  }
34305
34328
  connector.setAttribute("points", points.join(" "));
34306
34329
  }
@@ -34339,6 +34362,7 @@
34339
34362
  positionBox(box, target);
34340
34363
  highlights.push({ finding, target, box });
34341
34364
  }
34365
+ decollideLabels();
34342
34366
  }
34343
34367
  function clearTabOrder() {
34344
34368
  for (const { badge } of tabBadges)
@@ -34477,6 +34501,21 @@
34477
34501
  box.appendChild(label);
34478
34502
  return box;
34479
34503
  }
34504
+ function resolveLabelStack(items, minTop = LABEL_MIN_TOP) {
34505
+ const order = items.map((it, i) => ({ it, i })).sort((a, b) => a.it.baseTop - b.it.baseTop || a.it.left - b.it.left);
34506
+ const placed = [];
34507
+ const tops = new Array(items.length);
34508
+ for (const { it, i } of order) {
34509
+ let top = it.baseTop;
34510
+ const hits = (t) => placed.some((p) => it.left < p.right && it.left + it.width > p.left && t < p.bottom && t + it.height > p.top);
34511
+ let guard = 0;
34512
+ while (hits(top) && top > minTop && guard++ < 60)
34513
+ top -= it.height + 2;
34514
+ tops[i] = top;
34515
+ placed.push({ left: it.left, right: it.left + it.width, top, bottom: top + it.height });
34516
+ }
34517
+ return tops;
34518
+ }
34480
34519
  function positionBox(box, target) {
34481
34520
  const rect = target.getBoundingClientRect();
34482
34521
  Object.assign(box.style, {
package/dist/overlay.d.ts CHANGED
@@ -49,3 +49,23 @@ export interface OverlayOptions {
49
49
  * targets as the page moves.
50
50
  */
51
51
  export declare function createOverlay(options?: OverlayOptions): A11yOverlay;
52
+ /** One finding label's box for stacking: its natural top-left and measured size. */
53
+ export interface LabelBox {
54
+ /** Viewport left of the label (its box's left edge). */
55
+ left: number;
56
+ /** Measured label width. */
57
+ width: number;
58
+ /** The label's natural top (just above its box) with no de-collision shift. */
59
+ baseTop: number;
60
+ /** Measured label height. */
61
+ height: number;
62
+ }
63
+ /**
64
+ * Resolve overlapping finding labels to non-overlapping vertical positions,
65
+ * returning the adjusted top for each input (in input order). Labels are walked
66
+ * top-to-bottom and each is pushed *up* until it clears the ones already placed,
67
+ * so a cluster of flagged nodes stacks its labels instead of hiding them behind
68
+ * one another. Pure geometry — no DOM — so it's unit-testable. Pushing stops at
69
+ * `minTop` to keep labels on-screen (a dense cluster may then still overlap).
70
+ */
71
+ export declare function resolveLabelStack(items: LabelBox[], minTop?: number): number[];
package/dist/overlay.js CHANGED
@@ -2,6 +2,11 @@ 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;
8
+ /** Highest a de-collided finding label may be pushed (viewport y), so labels stay on-screen. */
9
+ const LABEL_MIN_TOP = 2;
5
10
  /**
6
11
  * Attribute marking the overlay's own DOM. `scan()` excludes anything under it
7
12
  * so the tool never reports violations against its own highlights.
@@ -86,15 +91,49 @@ export function createOverlay(options = {}) {
86
91
  for (const { target, box } of highlights) {
87
92
  positionBox(box, target);
88
93
  }
94
+ decollideLabels();
89
95
  repositionTabOrder();
90
96
  };
97
+ /**
98
+ * Push overlapping finding labels apart so none is hidden behind another —
99
+ * the demo (and any dense page) stacks several findings at the same top-left
100
+ * spot, and previously the later label simply covered the earlier one. Measures
101
+ * each label, resolves non-overlapping tops via {@link resolveLabelStack}, and
102
+ * applies the extra upward shift as a transform (the label's default is
103
+ * `translateY(-100%)`, sitting just above its box).
104
+ */
105
+ function decollideLabels() {
106
+ const labels = [];
107
+ const boxes = [];
108
+ for (const { target, box } of highlights) {
109
+ const label = box.firstElementChild;
110
+ if (!label)
111
+ continue;
112
+ const rect = target.getBoundingClientRect();
113
+ labels.push(label);
114
+ boxes.push({ left: rect.left, width: label.offsetWidth, baseTop: rect.top - label.offsetHeight, height: label.offsetHeight });
115
+ }
116
+ const tops = resolveLabelStack(boxes);
117
+ for (let i = 0; i < labels.length; i++) {
118
+ const extraUp = boxes[i].baseTop - tops[i]; // >= 0
119
+ labels[i].style.transform =
120
+ extraUp > 0 ? `translateY(calc(-100% - ${extraUp}px))` : 'translateY(-100%)';
121
+ }
122
+ }
91
123
  function repositionTabOrder() {
92
124
  const points = [];
93
125
  for (const { target, badge } of tabBadges) {
94
126
  const rect = target.getBoundingClientRect();
95
- badge.style.top = `${rect.top}px`;
96
- badge.style.left = `${rect.left}px`;
97
- points.push(`${rect.left + rect.width / 2},${rect.top + rect.height / 2}`);
127
+ // Anchor the badge just OUTSIDE the left edge, vertically centred, so it
128
+ // clears the findings labels that sit along the top-left corner (a
129
+ // corner-anchored badge collided with them). Clamp x into the viewport so a
130
+ // control flush to the left edge still shows its badge. The connector
131
+ // threads these same points.
132
+ const y = rect.top + rect.height / 2;
133
+ const x = Math.max(TAB_BADGE_MIN_X, rect.left - TAB_BADGE_GUTTER);
134
+ badge.style.top = `${y}px`;
135
+ badge.style.left = `${x}px`;
136
+ points.push(`${x},${y}`);
98
137
  }
99
138
  connector.setAttribute('points', points.join(' '));
100
139
  }
@@ -134,6 +173,7 @@ export function createOverlay(options = {}) {
134
173
  positionBox(box, target);
135
174
  highlights.push({ finding, target, box });
136
175
  }
176
+ decollideLabels();
137
177
  }
138
178
  function clearTabOrder() {
139
179
  for (const { badge } of tabBadges)
@@ -283,6 +323,29 @@ function buildBox(doc, finding) {
283
323
  box.appendChild(label);
284
324
  return box;
285
325
  }
326
+ /**
327
+ * Resolve overlapping finding labels to non-overlapping vertical positions,
328
+ * returning the adjusted top for each input (in input order). Labels are walked
329
+ * top-to-bottom and each is pushed *up* until it clears the ones already placed,
330
+ * so a cluster of flagged nodes stacks its labels instead of hiding them behind
331
+ * one another. Pure geometry — no DOM — so it's unit-testable. Pushing stops at
332
+ * `minTop` to keep labels on-screen (a dense cluster may then still overlap).
333
+ */
334
+ export function resolveLabelStack(items, minTop = LABEL_MIN_TOP) {
335
+ const order = items.map((it, i) => ({ it, i })).sort((a, b) => a.it.baseTop - b.it.baseTop || a.it.left - b.it.left);
336
+ const placed = [];
337
+ const tops = new Array(items.length);
338
+ for (const { it, i } of order) {
339
+ let top = it.baseTop;
340
+ const hits = (t) => placed.some((p) => it.left < p.right && it.left + it.width > p.left && t < p.bottom && t + it.height > p.top);
341
+ let guard = 0;
342
+ while (hits(top) && top > minTop && guard++ < 60)
343
+ top -= it.height + 2;
344
+ tops[i] = top;
345
+ placed.push({ left: it.left, right: it.left + it.width, top, bottom: top + it.height });
346
+ }
347
+ return tops;
348
+ }
286
349
  /** Anchor `box` (position:fixed) over `target` using viewport coordinates. */
287
350
  function positionBox(box, target) {
288
351
  const rect = target.getBoundingClientRect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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",