@ngbracket/a11y-devtools 0.7.1 → 0.8.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/CHANGELOG.md +27 -0
- package/README.md +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inpage.global.js +60 -0
- package/dist/keyboard/focus-trap.d.ts +30 -0
- package/dist/keyboard/focus-trap.js +39 -0
- package/dist/keyboard/keyboard-scan.js +11 -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,33 @@
|
|
|
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.8.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **Keyboard & Focus Mode — M3 (part 1): missing focus-trap detection.** A new
|
|
11
|
+
`ngbr/modal-focus-not-contained` finding (part of the `keyboard` layer) flags an
|
|
12
|
+
open `aria-modal="true"` whose focus isn't contained — i.e. tabbable elements
|
|
13
|
+
outside the modal are still reachable, so a keyboard user can Tab out to the page
|
|
14
|
+
behind it. Reuses the M1 tab-order machinery (which already drops `inert`/hidden
|
|
15
|
+
subtrees), so a modal that correctly inerts the background is **not** flagged.
|
|
16
|
+
- New public API: `findUncontainedModals` and the `UncontainedModal` type.
|
|
17
|
+
- **Honesty guardrail:** a candidate, labelled "verify manually", never a verdict.
|
|
18
|
+
- The *bad-trap* half of M3 ("you can Tab in but never Tab out") needs real Tab
|
|
19
|
+
key presses to observe and is a headless report-mode (Playwright) follow-up.
|
|
20
|
+
|
|
21
|
+
## 0.7.2
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **Findings labels no longer cover each other.** Where several flagged nodes
|
|
26
|
+
cluster (or share a column), each finding's label was drawn at its box's
|
|
27
|
+
top-left corner, so the labels piled on the same spot and the later one hid the
|
|
28
|
+
earlier — e.g. a `color-contrast` label sitting behind a `region` label. The
|
|
29
|
+
overlay now runs a de-collision pass (`resolveLabelStack`) that walks labels
|
|
30
|
+
top-to-bottom and lifts each one until it clears the labels already placed, so
|
|
31
|
+
every finding stays readable. Runs on render and on scroll/resize.
|
|
32
|
+
|
|
6
33
|
## 0.7.1
|
|
7
34
|
|
|
8
35
|
### Fixed
|
package/README.md
CHANGED
|
@@ -184,6 +184,10 @@ It adds:
|
|
|
184
184
|
(e.g. a handler added via `hostDirectives`).
|
|
185
185
|
- `ngbr/tab-order-mismatch` — the tab path jumps against the visual reading order
|
|
186
186
|
(needs real layout, so it fires in report-mode / a real browser).
|
|
187
|
+
- `ngbr/modal-focus-not-contained` — an open `aria-modal="true"` whose focus isn't
|
|
188
|
+
contained: tabbable elements outside it are still reachable, so a keyboard user
|
|
189
|
+
can Tab out to the page behind. (A modal that correctly marks the background
|
|
190
|
+
`inert` is not flagged, since those elements are no longer tabbable.)
|
|
187
191
|
|
|
188
192
|
```bash
|
|
189
193
|
# include the keyboard layer in a report-mode run
|
|
@@ -250,7 +254,8 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
|
|
|
250
254
|
|
|
251
255
|
## Roadmap
|
|
252
256
|
|
|
253
|
-
- Keyboard & Focus Mode **M3** —
|
|
257
|
+
- Keyboard & Focus Mode **M3 (part 2)** — *bad-trap* detection ("you can Tab in but
|
|
258
|
+
never Tab out") via real Tab presses in headless report-mode.
|
|
254
259
|
- Headless "linear walkthrough" — the tab sequence as an SR-ish reading list per
|
|
255
260
|
route in report-mode (M2's preview is currently overlay-only).
|
|
256
261
|
- HTML report + baseline/diff mode for CI.
|
|
@@ -261,4 +266,4 @@ directive / `hostDirectives` attribution · configurable framework prefixes · a
|
|
|
261
266
|
scan · grouped console reporter · dev-only provider · in-app overlay · headless
|
|
262
267
|
report mode (CLI + `./report`) · **Keyboard & Focus Mode M1** (tab-order viz +
|
|
263
268
|
keyboard-reachability findings) · **M2** (focus-follow accessibility-tree preview) ·
|
|
264
|
-
CI prod-weight guard.
|
|
269
|
+
**M3 part 1** (missing focus-trap: uncontained `aria-modal`) · CI prod-weight guard.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ 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 { findUncontainedModals, type UncontainedModal } from './keyboard/focus-trap.js';
|
|
8
9
|
export { describeElement, accessibleDescription, ariaStates, type AxDescription, } from './keyboard/accname.js';
|
|
9
10
|
export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, type AxPanelData, } from './overlay.js';
|
package/dist/index.js
CHANGED
|
@@ -5,5 +5,6 @@ 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 { findUncontainedModals } from './keyboard/focus-trap.js';
|
|
8
9
|
export { describeElement, accessibleDescription, ariaStates, } from './keyboard/accname.js';
|
|
9
10
|
export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, } from './overlay.js';
|
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, {
|
|
@@ -34625,6 +34660,27 @@
|
|
|
34625
34660
|
return jumps;
|
|
34626
34661
|
}
|
|
34627
34662
|
|
|
34663
|
+
// dist/keyboard/focus-trap.js
|
|
34664
|
+
function findUncontainedModals(root = document, options = {}) {
|
|
34665
|
+
const stops = tabSequence(root, options);
|
|
34666
|
+
if (stops.length === 0)
|
|
34667
|
+
return [];
|
|
34668
|
+
const results = [];
|
|
34669
|
+
for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
|
|
34670
|
+
let insideCount = 0;
|
|
34671
|
+
let outsideCount = 0;
|
|
34672
|
+
for (const stop of stops) {
|
|
34673
|
+
if (modal.contains(stop.element))
|
|
34674
|
+
insideCount++;
|
|
34675
|
+
else
|
|
34676
|
+
outsideCount++;
|
|
34677
|
+
}
|
|
34678
|
+
if (insideCount > 0 && outsideCount > 0)
|
|
34679
|
+
results.push({ element: modal, insideCount, outsideCount });
|
|
34680
|
+
}
|
|
34681
|
+
return results;
|
|
34682
|
+
}
|
|
34683
|
+
|
|
34628
34684
|
// dist/keyboard/keyboard-scan.js
|
|
34629
34685
|
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
34630
34686
|
"button",
|
|
@@ -34648,6 +34704,7 @@
|
|
|
34648
34704
|
var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
|
|
34649
34705
|
var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
|
|
34650
34706
|
var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
|
|
34707
|
+
var DIALOG_MODAL_URL = "https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/";
|
|
34651
34708
|
function shortSelector(element) {
|
|
34652
34709
|
const tag = element.tagName.toLowerCase();
|
|
34653
34710
|
if (element.id)
|
|
@@ -34697,6 +34754,9 @@
|
|
|
34697
34754
|
findings.push(make(element, "ngbr/click-without-key", "moderate", `Possible keyboard trap: this element has a (click) handler but no keyboard handler (keydown/keyup) and isn't a native button/link, so Enter/Space may not activate it. Verify by hand, then add a key handler or use a <button>.`, KEYBOARD_URL));
|
|
34698
34755
|
}
|
|
34699
34756
|
}
|
|
34757
|
+
for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
34758
|
+
findings.push(make(modal.element, "ngbr/modal-focus-not-contained", "moderate", `Possible missing focus trap: this element has aria-modal="true", but ${modal.outsideCount} tabbable element(s) outside it are still reachable, so a keyboard user can Tab out of the modal to the page behind. Mark the background inert or trap focus within the dialog. Heuristic \u2014 verify manually.`, DIALOG_MODAL_URL));
|
|
34759
|
+
}
|
|
34700
34760
|
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
34701
34761
|
for (const jump of visualOrderJumps(stops)) {
|
|
34702
34762
|
const stop = stops[jump];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard layer, part D (M3): focus-trap detection. This first landing does
|
|
3
|
+
* the *missing-trap* half — an open modal that fails to contain focus — because
|
|
4
|
+
* it's deterministic and reuses the M1 tab-order machinery directly. The
|
|
5
|
+
* *bad-trap* half ("you can Tab in but never Tab out") needs real Tab key presses
|
|
6
|
+
* to observe, so it belongs in headless report-mode (Playwright) and is a
|
|
7
|
+
* separate follow-up.
|
|
8
|
+
*
|
|
9
|
+
* HONESTY GUARDRAIL: these are *candidates*, not verdicts — a modal may be
|
|
10
|
+
* intentionally non-modal, so findings say "verify manually".
|
|
11
|
+
*/
|
|
12
|
+
import { type TabSequenceOptions } from './tab-sequence.js';
|
|
13
|
+
/** An open `aria-modal` whose focus isn't contained, with the leak counts. */
|
|
14
|
+
export interface UncontainedModal {
|
|
15
|
+
/** The `aria-modal="true"` element. */
|
|
16
|
+
element: Element;
|
|
17
|
+
/** Tabbable stops inside the modal. */
|
|
18
|
+
insideCount: number;
|
|
19
|
+
/** Tabbable stops outside the modal that are still reachable (the leak). */
|
|
20
|
+
outsideCount: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Open modals (`aria-modal="true"`) whose focus is **not** contained: while the
|
|
24
|
+
* modal is open, tabbable elements outside it are still reachable, so a keyboard
|
|
25
|
+
* user can Tab out to the page behind. Reuses {@link tabSequence} — which already
|
|
26
|
+
* drops `inert`/hidden/disabled subtrees — so a modal that correctly marks the
|
|
27
|
+
* background `inert` produces no outside stops and is *not* flagged. A modal with
|
|
28
|
+
* no tabbable content of its own is skipped (nothing to trap).
|
|
29
|
+
*/
|
|
30
|
+
export declare function findUncontainedModals(root?: ParentNode, options?: TabSequenceOptions): UncontainedModal[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard layer, part D (M3): focus-trap detection. This first landing does
|
|
3
|
+
* the *missing-trap* half — an open modal that fails to contain focus — because
|
|
4
|
+
* it's deterministic and reuses the M1 tab-order machinery directly. The
|
|
5
|
+
* *bad-trap* half ("you can Tab in but never Tab out") needs real Tab key presses
|
|
6
|
+
* to observe, so it belongs in headless report-mode (Playwright) and is a
|
|
7
|
+
* separate follow-up.
|
|
8
|
+
*
|
|
9
|
+
* HONESTY GUARDRAIL: these are *candidates*, not verdicts — a modal may be
|
|
10
|
+
* intentionally non-modal, so findings say "verify manually".
|
|
11
|
+
*/
|
|
12
|
+
import { tabSequence } from './tab-sequence.js';
|
|
13
|
+
/**
|
|
14
|
+
* Open modals (`aria-modal="true"`) whose focus is **not** contained: while the
|
|
15
|
+
* modal is open, tabbable elements outside it are still reachable, so a keyboard
|
|
16
|
+
* user can Tab out to the page behind. Reuses {@link tabSequence} — which already
|
|
17
|
+
* drops `inert`/hidden/disabled subtrees — so a modal that correctly marks the
|
|
18
|
+
* background `inert` produces no outside stops and is *not* flagged. A modal with
|
|
19
|
+
* no tabbable content of its own is skipped (nothing to trap).
|
|
20
|
+
*/
|
|
21
|
+
export function findUncontainedModals(root = document, options = {}) {
|
|
22
|
+
const stops = tabSequence(root, options);
|
|
23
|
+
if (stops.length === 0)
|
|
24
|
+
return [];
|
|
25
|
+
const results = [];
|
|
26
|
+
for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
|
|
27
|
+
let insideCount = 0;
|
|
28
|
+
let outsideCount = 0;
|
|
29
|
+
for (const stop of stops) {
|
|
30
|
+
if (modal.contains(stop.element))
|
|
31
|
+
insideCount++;
|
|
32
|
+
else
|
|
33
|
+
outsideCount++;
|
|
34
|
+
}
|
|
35
|
+
if (insideCount > 0 && outsideCount > 0)
|
|
36
|
+
results.push({ element: modal, insideCount, outsideCount });
|
|
37
|
+
}
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, } from '../attribution.js';
|
|
15
15
|
import { isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
|
|
16
|
+
import { findUncontainedModals } from './focus-trap.js';
|
|
16
17
|
/** WAI-ARIA roles that make a non-native element behave as an interactive control. */
|
|
17
18
|
const INTERACTIVE_ROLES = new Set([
|
|
18
19
|
'button',
|
|
@@ -36,6 +37,7 @@ const KEY_EVENTS = ['keydown', 'keyup', 'keypress'];
|
|
|
36
37
|
const UNDERSTANDING = 'https://www.w3.org/WAI/WCAG22/Understanding';
|
|
37
38
|
const KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
|
|
38
39
|
const FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
|
|
40
|
+
const DIALOG_MODAL_URL = 'https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/';
|
|
39
41
|
/** A short, human CSS-ish selector for our own findings (not an axe target). */
|
|
40
42
|
function shortSelector(element) {
|
|
41
43
|
const tag = element.tagName.toLowerCase();
|
|
@@ -104,6 +106,15 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
104
106
|
`activate it. Verify by hand, then add a key handler or use a <button>.`, KEYBOARD_URL));
|
|
105
107
|
}
|
|
106
108
|
}
|
|
109
|
+
// Missing focus trap (M3): an open aria-modal whose focus isn't contained.
|
|
110
|
+
// Reuses the tab-order machinery (inert/hidden already excluded), so a modal
|
|
111
|
+
// that correctly inerts the background is not flagged.
|
|
112
|
+
for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
113
|
+
findings.push(make(modal.element, 'ngbr/modal-focus-not-contained', 'moderate', `Possible missing focus trap: this element has aria-modal="true", but ` +
|
|
114
|
+
`${modal.outsideCount} tabbable element(s) outside it are still reachable, so a keyboard ` +
|
|
115
|
+
`user can Tab out of the modal to the page behind. Mark the background inert or trap ` +
|
|
116
|
+
`focus within the dialog. Heuristic — verify manually.`, DIALOG_MODAL_URL));
|
|
117
|
+
}
|
|
107
118
|
// Visual-vs-tab-order mismatch: a heuristic over the resolved sequence. Needs
|
|
108
119
|
// real layout, so it no-ops where getBoundingClientRect returns zeros (jsdom).
|
|
109
120
|
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
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.
|
|
3
|
+
"version": "0.8.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",
|