@ngbracket/a11y-devtools 0.18.4 → 0.18.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,48 @@
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.18.6
7
+
8
+ ### Fixed
9
+
10
+ - A baseline no longer reports a known finding as new when the markup around
11
+ it was reordered. axe's selectors can contain positional parts such as
12
+ `li:nth-child(3)` and generated ids such as `#mat-input-3`. Adding an item
13
+ above the element, or another field earlier in the form, changed them, so
14
+ the finding failed to match its baseline entry and failed the CI gate.
15
+ Findings still unmatched after the exact comparison are now compared again
16
+ with those parts left out, for the same route, rule and owning component.
17
+ Only ids with at least two words before the number count as generated
18
+ (`#mat-input-3`, `#cdk-overlay-12`); `#h2`, `#col-12` and `#item-2024` are
19
+ compared as written, and so are ids with a number in the middle such as
20
+ `#mat-mdc-checkbox-2-input`. A positional part inside `:not()`, `:is()`,
21
+ `:where()` or `:has()` is kept. Duplicates
22
+ are still counted, so a component that gains a real extra instance of a
23
+ rule reports it as new. One case can't be told apart: if one instance is
24
+ fixed and another appears in the same component and rule in the same run,
25
+ and their selectors differ only in position or id counter, the count is
26
+ unchanged and neither is reported.
27
+
28
+ ## 0.18.5
29
+
30
+ ### Fixed
31
+
32
+ - The dashed line joining the tab-order badges is drawn opaque. At 70% opacity
33
+ the teal blended to about 2.5:1 on a white page, under the 3:1 that WCAG
34
+ 1.4.11 asks of non-text content. Opaque, it measures 3.93:1 on white, 3.61:1
35
+ on #f5f5f5, 3.5:1 on #2d2d2d and 5.34:1 on black. On a mid-tone page it can
36
+ still fall under 3:1.
37
+ - The tab-order layer is clipped to the viewport. When the path ran past the
38
+ bottom of the window, axe's color-contrast check treated it as covering the
39
+ text below the fold and returned "needs review" for that text. A
40
+ low-contrast paragraph under the path was not reported as a violation.
41
+ Report mode already hid the overlay before scanning and still does, because
42
+ the app it scans may run an older overlay.
43
+ - The on/off pill and its menu now sit in a region labelled "Accessibility
44
+ developer tools". A page scan that doesn't exclude the overlay, such as an
45
+ axe browser extension, reported the pill under the best-practice `region`
46
+ rule as content outside any landmark.
47
+
6
48
  ## 0.18.4
7
49
 
8
50
  ### Fixed
@@ -34350,14 +34350,13 @@
34350
34350
  width: "100%",
34351
34351
  height: "100%",
34352
34352
  pointerEvents: "none",
34353
- overflow: "visible"
34353
+ overflow: "hidden"
34354
34354
  });
34355
34355
  const connector = doc.createElementNS(SVG_NS, "polyline");
34356
34356
  connector.setAttribute("fill", "none");
34357
34357
  connector.setAttribute("stroke", TAB_ORDER_COLOR);
34358
34358
  connector.setAttribute("stroke-width", "2");
34359
34359
  connector.setAttribute("stroke-dasharray", "4 3");
34360
- connector.setAttribute("opacity", "0.7");
34361
34360
  svg.appendChild(connector);
34362
34361
  container.appendChild(svg);
34363
34362
  const axPanel = doc.createElement("div");
package/dist/overlay.js CHANGED
@@ -72,6 +72,8 @@ export function createOverlay(options = {}) {
72
72
  const releaseTopLayer = keepInTopLayer(container, { document: doc });
73
73
  // The tab-order connector lives on its own SVG layer under the badges, so the
74
74
  // findings highlights and the tab-order path render and clear independently.
75
+ // Clipped to the viewport: a path left to overflow it covers text below the
76
+ // fold, and axe's color-contrast then gives up on that text ("needs review").
75
77
  const svg = doc.createElementNS(SVG_NS, 'svg');
76
78
  svg.setAttribute(OVERLAY_ATTR, '');
77
79
  Object.assign(svg.style, {
@@ -80,14 +82,16 @@ export function createOverlay(options = {}) {
80
82
  width: '100%',
81
83
  height: '100%',
82
84
  pointerEvents: 'none',
83
- overflow: 'visible',
85
+ overflow: 'hidden',
84
86
  });
87
+ // Drawn opaque so the line passes 3:1 for non-text contrast: the teal is
88
+ // 3.93:1 on white, 3.61:1 on #f5f5f5, 3.5:1 on #2d2d2d and 5.34:1 on black.
89
+ // At 0.7 opacity it blended to about 2.5:1 on white.
85
90
  const connector = doc.createElementNS(SVG_NS, 'polyline');
86
91
  connector.setAttribute('fill', 'none');
87
92
  connector.setAttribute('stroke', TAB_ORDER_COLOR);
88
93
  connector.setAttribute('stroke-width', '2');
89
94
  connector.setAttribute('stroke-dasharray', '4 3');
90
- connector.setAttribute('opacity', '0.7');
91
95
  svg.appendChild(connector);
92
96
  container.appendChild(svg); // under the badges, which are appended later
93
97
  // The Focus preview panel: a fixed card that follows focus. Hidden
@@ -47,9 +47,11 @@ export declare function findingKey(page: string, finding: A11yFinding): string;
47
47
  export declare function findingsNotIn(findings: A11yFinding[], reference: A11yFinding[]): A11yFinding[];
48
48
  /**
49
49
  * Compare `current` with `baseline`. Matching is by {@link findingKey} with
50
- * counts, so two identical keys in the current run against one in the baseline
51
- * leaves one new. Pages are matched by label; a route the baseline never
52
- * scanned counts entirely as new (add it to the baseline when you add it to CI).
50
+ * counts, then by a looser key that ignores positional selector parts and id
51
+ * counters for whatever is still unpaired. Two identical keys in the current
52
+ * run against one in the baseline leaves one new. Pages are matched by label;
53
+ * a route the baseline never scanned counts entirely as new (add it to the
54
+ * baseline when you add it to CI).
53
55
  * Pages that failed to scan in the current run are skipped, so an outage
54
56
  * doesn't report everything on that page as fixed. Pages that failed in the
55
57
  * *baseline* are skipped too — there's nothing to compare against, so their
@@ -14,6 +14,57 @@ function normalizeTarget(target) {
14
14
  export function findingKey(page, finding) {
15
15
  return [page, finding.id, finding.component ?? '', normalizeTarget(finding.target)].join('\u0000');
16
16
  }
17
+ /**
18
+ * Positional parts of a selector: `:nth-child(3)`, `:nth-of-type(2)`,
19
+ * `:first-child`, `:last-of-type` and the like. They change when markup is
20
+ * reordered even though the element is the same.
21
+ */
22
+ const POSITIONAL = /:(?:nth-(?:last-)?(?:child|of-type)\([^)]*\)|(?:first|last|only)-(?:child|of-type))/g;
23
+ /** Selector functions whose argument is itself a selector. */
24
+ const SELECTOR_FUNCTION = /:(?:not|is|where|has)\(/g;
25
+ /**
26
+ * Remove {@link POSITIONAL} parts, except inside `:not()`, `:is()`, `:where()`
27
+ * and `:has()`: there a positional part is what tells `li:not(.x:first-child)`
28
+ * from `li:not(.x:last-child)`, so it stays.
29
+ */
30
+ function stripPositional(selector) {
31
+ let out = '';
32
+ let from = 0;
33
+ for (const match of selector.matchAll(SELECTOR_FUNCTION)) {
34
+ const open = match.index + match[0].length;
35
+ if (match.index < from)
36
+ continue; // nested inside a function already kept
37
+ let depth = 1;
38
+ let end = open;
39
+ while (end < selector.length && depth > 0) {
40
+ if (selector[end] === '(')
41
+ depth++;
42
+ else if (selector[end] === ')')
43
+ depth--;
44
+ end++;
45
+ }
46
+ out += selector.slice(from, match.index).replace(POSITIONAL, '') + selector.slice(match.index, end);
47
+ from = end;
48
+ }
49
+ return out + selector.slice(from).replace(POSITIONAL, '');
50
+ }
51
+ /**
52
+ * The counter at the end of a generated id: `#mat-input-3`, `#cdk-overlay-12`,
53
+ * `#pn_id_3`. Only ids with at least two words before the number count, so
54
+ * `#h2`, `#col-12` and `#item-2024`, where the number is part of the name,
55
+ * stay distinct.
56
+ */
57
+ const ID_COUNTER = /(#[A-Za-z][A-Za-z0-9]*[-_][\w-]*?[-_])\d+(?=[\s>+~.:#[]|$)/g;
58
+ /**
59
+ * A looser identity for the second matching pass: {@link findingKey} with the
60
+ * positional parts and id counters taken out of the selector. A markup
61
+ * reorder changes those, so without this pass a known finding came back as
62
+ * "new" and failed the CI gate.
63
+ */
64
+ function looseKey(page, finding) {
65
+ const target = stripPositional(normalizeTarget(finding.target)).replace(ID_COUNTER, '$1#');
66
+ return [page, finding.id, finding.component ?? '', target].join('\u0000');
67
+ }
17
68
  /**
18
69
  * The findings in `findings` that aren't also in `reference`, matched by
19
70
  * {@link findingKey} with counts. Used for a dark-mode pass, so it reports only
@@ -36,9 +87,11 @@ export function findingsNotIn(findings, reference) {
36
87
  }
37
88
  /**
38
89
  * Compare `current` with `baseline`. Matching is by {@link findingKey} with
39
- * counts, so two identical keys in the current run against one in the baseline
40
- * leaves one new. Pages are matched by label; a route the baseline never
41
- * scanned counts entirely as new (add it to the baseline when you add it to CI).
90
+ * counts, then by a looser key that ignores positional selector parts and id
91
+ * counters for whatever is still unpaired. Two identical keys in the current
92
+ * run against one in the baseline leaves one new. Pages are matched by label;
93
+ * a route the baseline never scanned counts entirely as new (add it to the
94
+ * baseline when you add it to CI).
42
95
  * Pages that failed to scan in the current run are skipped, so an outage
43
96
  * doesn't report everything on that page as fixed. Pages that failed in the
44
97
  * *baseline* are skipped too — there's nothing to compare against, so their
@@ -47,37 +100,53 @@ export function findingsNotIn(findings, reference) {
47
100
  export function diffAgainstBaseline(current, baseline) {
48
101
  const failed = new Set(current.pages.filter((p) => p.error).map((p) => p.label));
49
102
  const baselineFailed = new Set(baseline.pages.filter((p) => p.error).map((p) => p.label));
103
+ let before = baseline.pages
104
+ .filter((page) => !failed.has(page.label))
105
+ .flatMap((page) => page.findings.map((finding) => ({ page: page.label, finding })));
106
+ let after = current.pages
107
+ .filter((page) => !baselineFailed.has(page.label))
108
+ .flatMap((page) => page.findings.map((finding) => ({ page: page.label, finding })));
109
+ // Exact keys first, then the loose key for what's left, so a finding whose
110
+ // selector only moved (a reordered list, a shifted id counter) still pairs
111
+ // with its baseline entry. Both passes match with counts: a component that
112
+ // gains a real extra instance of a rule still reports it as added.
113
+ let unchanged = 0;
114
+ for (const key of [findingKey, looseKey]) {
115
+ const result = pair(after, before, key);
116
+ unchanged += result.matched;
117
+ after = result.unmatched;
118
+ before = result.leftover;
119
+ }
120
+ return { added: after, fixed: before, unchanged };
121
+ }
122
+ /**
123
+ * Pair each item of `current` with one of `baseline` that has the same key.
124
+ * Returns how many paired, the current items with no partner, and the baseline
125
+ * items nobody claimed.
126
+ */
127
+ function pair(current, baseline, key) {
50
128
  const remaining = new Map();
51
- for (const page of baseline.pages) {
52
- if (failed.has(page.label))
53
- continue;
54
- for (const finding of page.findings) {
55
- const key = findingKey(page.label, finding);
56
- const bucket = remaining.get(key);
57
- if (bucket)
58
- bucket.push({ page: page.label, finding });
59
- else
60
- remaining.set(key, [{ page: page.label, finding }]);
61
- }
129
+ for (const item of baseline) {
130
+ const k = key(item.page, item.finding);
131
+ const bucket = remaining.get(k);
132
+ if (bucket)
133
+ bucket.push(item);
134
+ else
135
+ remaining.set(k, [item]);
62
136
  }
63
- const added = [];
64
- let unchanged = 0;
65
- for (const page of current.pages) {
66
- if (baselineFailed.has(page.label))
67
- continue;
68
- for (const finding of page.findings) {
69
- const bucket = remaining.get(findingKey(page.label, finding));
70
- if (bucket && bucket.length > 0) {
71
- bucket.pop();
72
- unchanged++;
73
- }
74
- else {
75
- added.push({ page: page.label, finding });
76
- }
137
+ let matched = 0;
138
+ const unmatched = [];
139
+ for (const item of current) {
140
+ const bucket = remaining.get(key(item.page, item.finding));
141
+ if (bucket && bucket.length > 0) {
142
+ bucket.pop();
143
+ matched++;
144
+ }
145
+ else {
146
+ unmatched.push(item);
77
147
  }
78
148
  }
79
- const fixed = [...remaining.values()].flat();
80
- return { added, fixed, unchanged };
149
+ return { matched, unmatched, leftover: [...remaining.values()].flat() };
81
150
  }
82
151
  /**
83
152
  * Read a baseline from its JSON text (a previous `toJson` report). Throws a
@@ -61,12 +61,14 @@ async function walkForFocusTrap(page, frameworkPrefixes) {
61
61
  /** Settle time after switching a class/attribute theme, so colour transitions finish before axe reads them. */
62
62
  const THEME_SETTLE_MS = 300;
63
63
  /**
64
- * Hides the in-app overlay (if the app runs it) for the headless scan. Its
65
- * tab-order path is a fixed SVG that overflows the viewport, and axe's
66
- * color-contrast counts it as covering text below the fold: that text came
67
- * back "needs review" instead of pass/fail, so its contrast was never
68
- * reported. Excluding the overlay from axe's context isn't enough; the exclude
69
- * stops axe checking the overlay, not seeing it.
64
+ * Hides the in-app overlay (if the app runs it) for the headless scan. Up to
65
+ * 0.18.4 its tab-order path was a fixed SVG that overflowed the viewport, and
66
+ * axe's color-contrast counted it as covering text below the fold: that text
67
+ * came back "needs review" instead of pass/fail, so its contrast was never
68
+ * reported. The SVG is clipped to the viewport since 0.18.5, but the app being
69
+ * scanned may run an older overlay than this report, so the hide stays.
70
+ * Excluding the overlay from axe's context isn't enough; the exclude stops axe
71
+ * checking the overlay, not seeing it.
70
72
  */
71
73
  const HIDE_OVERLAY_CSS = `${OVERLAY_EXCLUDE_SELECTOR} { display: none !important; }`;
72
74
  /** Scan every route in one colour scheme, in its own browser context. */
package/dist/toggle.js CHANGED
@@ -214,8 +214,13 @@ export function createTogglePill(options) {
214
214
  pointerEvents: 'none',
215
215
  zIndex: '2147483647',
216
216
  });
217
- // The switch, the optional menu button and its panel sit together in a corner.
217
+ // The switch, the optional menu button and its panel sit together in a corner,
218
+ // in a labelled region so a page scan doesn't report the pill as content
219
+ // outside any landmark (axe's `region` rule). The region's name differs from
220
+ // the switch's, so tabbing in doesn't announce "a11y devtools" twice.
218
221
  const group = doc.createElement('div');
222
+ group.setAttribute('role', 'region');
223
+ group.setAttribute('aria-label', 'Accessibility developer tools');
219
224
  Object.assign(group.style, {
220
225
  position: 'fixed',
221
226
  [vertical]: '12px',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.18.4",
3
+ "version": "0.18.6",
4
4
  "description": "Finds accessibility problems in Angular apps and names the component behind each one. A dev overlay, or headless reports for CI.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",
@@ -90,6 +90,9 @@
90
90
  "rxjs": "^7.8.2",
91
91
  "tslib": "^2.8.1",
92
92
  "typescript": "^6.0.3",
93
- "vitest": "^4.1.11"
93
+ "vitest": "^4.1.12"
94
+ },
95
+ "overrides": {
96
+ "vite": "^8.3.5"
94
97
  }
95
98
  }