@ngbracket/a11y-devtools 0.7.1 → 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 +12 -0
- package/dist/inpage.global.js +35 -0
- package/dist/overlay.d.ts +20 -0
- package/dist/overlay.js +53 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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
|
+
|
|
6
18
|
## 0.7.1
|
|
7
19
|
|
|
8
20
|
### Fixed
|
package/dist/inpage.global.js
CHANGED
|
@@ -34228,6 +34228,7 @@
|
|
|
34228
34228
|
var TAB_ORDER_WARN_COLOR = "#e8710a";
|
|
34229
34229
|
var TAB_BADGE_GUTTER = 10;
|
|
34230
34230
|
var TAB_BADGE_MIN_X = 9;
|
|
34231
|
+
var LABEL_MIN_TOP = 2;
|
|
34231
34232
|
var OVERLAY_ATTR = "data-ngb-a11y-overlay";
|
|
34232
34233
|
var OVERLAY_EXCLUDE_SELECTOR = `[${OVERLAY_ATTR}]`;
|
|
34233
34234
|
var IMPACT_COLOR = {
|
|
@@ -34294,8 +34295,26 @@
|
|
|
34294
34295
|
for (const { target, box } of highlights) {
|
|
34295
34296
|
positionBox(box, target);
|
|
34296
34297
|
}
|
|
34298
|
+
decollideLabels();
|
|
34297
34299
|
repositionTabOrder();
|
|
34298
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
|
+
}
|
|
34299
34318
|
function repositionTabOrder() {
|
|
34300
34319
|
const points = [];
|
|
34301
34320
|
for (const { target, badge } of tabBadges) {
|
|
@@ -34343,6 +34362,7 @@
|
|
|
34343
34362
|
positionBox(box, target);
|
|
34344
34363
|
highlights.push({ finding, target, box });
|
|
34345
34364
|
}
|
|
34365
|
+
decollideLabels();
|
|
34346
34366
|
}
|
|
34347
34367
|
function clearTabOrder() {
|
|
34348
34368
|
for (const { badge } of tabBadges)
|
|
@@ -34481,6 +34501,21 @@
|
|
|
34481
34501
|
box.appendChild(label);
|
|
34482
34502
|
return box;
|
|
34483
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
|
+
}
|
|
34484
34519
|
function positionBox(box, target) {
|
|
34485
34520
|
const rect = target.getBoundingClientRect();
|
|
34486
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
|
@@ -5,6 +5,8 @@ const TAB_ORDER_WARN_COLOR = '#e8710a';
|
|
|
5
5
|
/** How far outside a control's left edge the tab-order badge sits, and its min viewport x. */
|
|
6
6
|
const TAB_BADGE_GUTTER = 10;
|
|
7
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;
|
|
8
10
|
/**
|
|
9
11
|
* Attribute marking the overlay's own DOM. `scan()` excludes anything under it
|
|
10
12
|
* so the tool never reports violations against its own highlights.
|
|
@@ -89,8 +91,35 @@ export function createOverlay(options = {}) {
|
|
|
89
91
|
for (const { target, box } of highlights) {
|
|
90
92
|
positionBox(box, target);
|
|
91
93
|
}
|
|
94
|
+
decollideLabels();
|
|
92
95
|
repositionTabOrder();
|
|
93
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
|
+
}
|
|
94
123
|
function repositionTabOrder() {
|
|
95
124
|
const points = [];
|
|
96
125
|
for (const { target, badge } of tabBadges) {
|
|
@@ -144,6 +173,7 @@ export function createOverlay(options = {}) {
|
|
|
144
173
|
positionBox(box, target);
|
|
145
174
|
highlights.push({ finding, target, box });
|
|
146
175
|
}
|
|
176
|
+
decollideLabels();
|
|
147
177
|
}
|
|
148
178
|
function clearTabOrder() {
|
|
149
179
|
for (const { badge } of tabBadges)
|
|
@@ -293,6 +323,29 @@ function buildBox(doc, finding) {
|
|
|
293
323
|
box.appendChild(label);
|
|
294
324
|
return box;
|
|
295
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
|
+
}
|
|
296
349
|
/** Anchor `box` (position:fixed) over `target` using viewport coordinates. */
|
|
297
350
|
function positionBox(box, target) {
|
|
298
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.
|
|
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",
|