@ngbracket/a11y-devtools 0.18.5 → 0.19.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 CHANGED
@@ -3,6 +3,44 @@
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.19.0
7
+
8
+ ### Added
9
+
10
+ - Each finding now links to the WCAG criteria it relates to, in the
11
+ [NgBracket accessibility reference](https://ngbracket.com/reference). The
12
+ console, the Markdown report and the HTML report show a link such as
13
+ "WCAG 1.4.3 Contrast (Minimum)" after the axe rule link, which stays as it
14
+ was. The reference page says what the criterion asks, where Angular apps
15
+ usually fail it and how to check it.
16
+ - Every finding has a new `wcag` field listing the WCAG 2.2 A and AA
17
+ criteria its rule checks, such as `['1.4.3']`, in the JSON report too.
18
+ axe findings take theirs from the rule's tags. axe's best-practice rules
19
+ have none, so they get no link. The tool's own `ngbr/*` rules use the
20
+ criteria on their docs pages, such as `['2.1.2']` for `ngbr/focus-trap`.
21
+
22
+ ## 0.18.6
23
+
24
+ ### Fixed
25
+
26
+ - A baseline no longer reports a known finding as new when the markup around
27
+ it was reordered. axe's selectors can contain positional parts such as
28
+ `li:nth-child(3)` and generated ids such as `#mat-input-3`. Adding an item
29
+ above the element, or another field earlier in the form, changed them, so
30
+ the finding failed to match its baseline entry and failed the CI gate.
31
+ Findings still unmatched after the exact comparison are now compared again
32
+ with those parts left out, for the same route, rule and owning component.
33
+ Only ids with at least two words before the number count as generated
34
+ (`#mat-input-3`, `#cdk-overlay-12`); `#h2`, `#col-12` and `#item-2024` are
35
+ compared as written, and so are ids with a number in the middle such as
36
+ `#mat-mdc-checkbox-2-input`. A positional part inside `:not()`, `:is()`,
37
+ `:where()` or `:has()` is kept. Duplicates
38
+ are still counted, so a component that gains a real extra instance of a
39
+ rule reports it as new. One case can't be told apart: if one instance is
40
+ fixed and another appears in the same component and rule in the same run,
41
+ and their selectors differ only in position or id counter, the count is
42
+ unchanged and neither is reported.
43
+
6
44
  ## 0.18.5
7
45
 
8
46
  ### Fixed
@@ -35003,6 +35003,93 @@
35003
35003
  return false;
35004
35004
  }
35005
35005
 
35006
+ // dist/report/wcag.js
35007
+ var WCAG22_A_AA = [
35008
+ { id: "1.1.1", name: "Non-text Content", level: "A", slug: "non-text-content" },
35009
+ { id: "1.2.1", name: "Audio-only and Video-only (Prerecorded)", level: "A", slug: "audio-only-and-video-only-prerecorded" },
35010
+ { id: "1.2.2", name: "Captions (Prerecorded)", level: "A", slug: "captions-prerecorded" },
35011
+ { id: "1.2.3", name: "Audio Description or Media Alternative (Prerecorded)", level: "A", slug: "audio-description-or-media-alternative-prerecorded" },
35012
+ { id: "1.2.4", name: "Captions (Live)", level: "AA", slug: "captions-live" },
35013
+ { id: "1.2.5", name: "Audio Description (Prerecorded)", level: "AA", slug: "audio-description-prerecorded" },
35014
+ { id: "1.3.1", name: "Info and Relationships", level: "A", slug: "info-and-relationships" },
35015
+ { id: "1.3.2", name: "Meaningful Sequence", level: "A", slug: "meaningful-sequence" },
35016
+ { id: "1.3.3", name: "Sensory Characteristics", level: "A", slug: "sensory-characteristics" },
35017
+ { id: "1.3.4", name: "Orientation", level: "AA", slug: "orientation" },
35018
+ { id: "1.3.5", name: "Identify Input Purpose", level: "AA", slug: "identify-input-purpose" },
35019
+ { id: "1.4.1", name: "Use of Color", level: "A", slug: "use-of-color" },
35020
+ { id: "1.4.2", name: "Audio Control", level: "A", slug: "audio-control" },
35021
+ { id: "1.4.3", name: "Contrast (Minimum)", level: "AA", slug: "contrast-minimum" },
35022
+ { id: "1.4.4", name: "Resize Text", level: "AA", slug: "resize-text" },
35023
+ { id: "1.4.5", name: "Images of Text", level: "AA", slug: "images-of-text" },
35024
+ { id: "1.4.10", name: "Reflow", level: "AA", slug: "reflow" },
35025
+ { id: "1.4.11", name: "Non-text Contrast", level: "AA", slug: "non-text-contrast" },
35026
+ { id: "1.4.12", name: "Text Spacing", level: "AA", slug: "text-spacing" },
35027
+ { id: "1.4.13", name: "Content on Hover or Focus", level: "AA", slug: "content-on-hover-or-focus" },
35028
+ { id: "2.1.1", name: "Keyboard", level: "A", slug: "keyboard" },
35029
+ { id: "2.1.2", name: "No Keyboard Trap", level: "A", slug: "no-keyboard-trap" },
35030
+ { id: "2.1.4", name: "Character Key Shortcuts", level: "A", slug: "character-key-shortcuts" },
35031
+ { id: "2.2.1", name: "Timing Adjustable", level: "A", slug: "timing-adjustable" },
35032
+ { id: "2.2.2", name: "Pause, Stop, Hide", level: "A", slug: "pause-stop-hide" },
35033
+ { id: "2.3.1", name: "Three Flashes or Below Threshold", level: "A", slug: "three-flashes-or-below-threshold" },
35034
+ { id: "2.4.1", name: "Bypass Blocks", level: "A", slug: "bypass-blocks" },
35035
+ { id: "2.4.2", name: "Page Titled", level: "A", slug: "page-titled" },
35036
+ { id: "2.4.3", name: "Focus Order", level: "A", slug: "focus-order" },
35037
+ { id: "2.4.4", name: "Link Purpose (In Context)", level: "A", slug: "link-purpose-in-context" },
35038
+ { id: "2.4.5", name: "Multiple Ways", level: "AA", slug: "multiple-ways" },
35039
+ { id: "2.4.6", name: "Headings and Labels", level: "AA", slug: "headings-and-labels" },
35040
+ { id: "2.4.7", name: "Focus Visible", level: "AA", slug: "focus-visible" },
35041
+ { id: "2.4.11", name: "Focus Not Obscured (Minimum)", level: "AA", slug: "focus-not-obscured-minimum" },
35042
+ { id: "2.5.1", name: "Pointer Gestures", level: "A", slug: "pointer-gestures" },
35043
+ { id: "2.5.2", name: "Pointer Cancellation", level: "A", slug: "pointer-cancellation" },
35044
+ { id: "2.5.3", name: "Label in Name", level: "A", slug: "label-in-name" },
35045
+ { id: "2.5.4", name: "Motion Actuation", level: "A", slug: "motion-actuation" },
35046
+ { id: "2.5.7", name: "Dragging Movements", level: "AA", slug: "dragging-movements" },
35047
+ { id: "2.5.8", name: "Target Size (Minimum)", level: "AA", slug: "target-size-minimum" },
35048
+ { id: "3.1.1", name: "Language of Page", level: "A", slug: "language-of-page" },
35049
+ { id: "3.1.2", name: "Language of Parts", level: "AA", slug: "language-of-parts" },
35050
+ { id: "3.2.1", name: "On Focus", level: "A", slug: "on-focus" },
35051
+ { id: "3.2.2", name: "On Input", level: "A", slug: "on-input" },
35052
+ { id: "3.2.3", name: "Consistent Navigation", level: "AA", slug: "consistent-navigation" },
35053
+ { id: "3.2.4", name: "Consistent Identification", level: "AA", slug: "consistent-identification" },
35054
+ { id: "3.2.6", name: "Consistent Help", level: "A", slug: "consistent-help" },
35055
+ { id: "3.3.1", name: "Error Identification", level: "A", slug: "error-identification" },
35056
+ { id: "3.3.2", name: "Labels or Instructions", level: "A", slug: "labels-or-instructions" },
35057
+ { id: "3.3.3", name: "Error Suggestion", level: "AA", slug: "error-suggestion" },
35058
+ { id: "3.3.4", name: "Error Prevention (Legal, Financial, Data)", level: "AA", slug: "error-prevention-legal-financial-data" },
35059
+ { id: "3.3.7", name: "Redundant Entry", level: "A", slug: "redundant-entry" },
35060
+ { id: "3.3.8", name: "Accessible Authentication (Minimum)", level: "AA", slug: "accessible-authentication-minimum" },
35061
+ { id: "4.1.2", name: "Name, Role, Value", level: "A", slug: "name-role-value" },
35062
+ { id: "4.1.3", name: "Status Messages", level: "AA", slug: "status-messages" }
35063
+ ];
35064
+ function understandingUrl(criterion) {
35065
+ return `https://www.w3.org/WAI/WCAG22/Understanding/${criterion.slug}.html`;
35066
+ }
35067
+ function criterionForTag(tag) {
35068
+ const digits = /^wcag(\d{3,4})$/.exec(tag)?.[1];
35069
+ return digits ? BY_DIGITS.get(digits) : void 0;
35070
+ }
35071
+ var BY_DIGITS = new Map(WCAG22_A_AA.map((c) => [c.id.replace(/\./g, ""), c]));
35072
+ var REFERENCE_WCAG_URL = "https://ngbracket.com/reference/wcag";
35073
+ function referenceUrl(criterion) {
35074
+ return `${REFERENCE_WCAG_URL}/${criterion.slug}`;
35075
+ }
35076
+ var NGBR_RULE_CRITERIA = {
35077
+ "ngbr/unreachable-control": ["2.1.1"],
35078
+ "ngbr/click-without-key": ["2.1.1"],
35079
+ "ngbr/hover-only-content": ["2.1.1"],
35080
+ "ngbr/drag-without-keyboard": ["2.1.1", "2.5.7"],
35081
+ "ngbr/tab-order-mismatch": ["2.4.3"],
35082
+ "ngbr/modal-focus-not-contained": ["2.4.3"],
35083
+ "ngbr/focus-trap": ["2.1.2"]
35084
+ };
35085
+ function ngbrRuleCriteria(id) {
35086
+ return [...NGBR_RULE_CRITERIA[id] ?? []];
35087
+ }
35088
+ function findingCriteria(finding) {
35089
+ const ids = new Set(finding.wcag ?? NGBR_RULE_CRITERIA[finding.id] ?? []);
35090
+ return WCAG22_A_AA.filter((c) => ids.has(c.id));
35091
+ }
35092
+
35006
35093
  // dist/keyboard/keyboard-scan.js
35007
35094
  var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
35008
35095
  "button",
@@ -35240,6 +35327,7 @@
35240
35327
  impact,
35241
35328
  help,
35242
35329
  helpUrl,
35330
+ wcag: ngbrRuleCriteria(id),
35243
35331
  component: appComponentFromPath(componentPath, prefixes),
35244
35332
  componentPath,
35245
35333
  directives: resolveDirectiveNames(element),
@@ -35456,6 +35544,7 @@
35456
35544
  impact: shiftTabEscapes ? "moderate" : "serious",
35457
35545
  help: `Keyboard trap: ${where}${reach}.${shift} If this widget deliberately keeps Tab (e.g. a code editor), it must tell users how to leave (such as Escape); otherwise let Tab move focus on. Found by real Tab presses \u2014 verify manually.`,
35458
35546
  helpUrl: FOCUS_TRAP_DOCS,
35547
+ wcag: ngbrRuleCriteria("ngbr/focus-trap"),
35459
35548
  component: appComponentFromPath(componentPath, frameworkPrefixes),
35460
35549
  componentPath,
35461
35550
  directives: resolveDirectiveNames(owner),
@@ -35624,6 +35713,7 @@
35624
35713
  impact: violation.impact ?? null,
35625
35714
  help: violation.help,
35626
35715
  helpUrl: violation.helpUrl,
35716
+ wcag: violation.tags.flatMap((tag) => criterionForTag(tag)?.id ?? []),
35627
35717
  component: appComponentFromPath(componentPath, frameworkPrefixes),
35628
35718
  componentPath,
35629
35719
  directives: element ? resolveDirectiveNames(element) : [],
@@ -21,6 +21,7 @@
21
21
  import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, } from '../attribution.js';
22
22
  import { shortHtml, shortSelector } from './keyboard-scan.js';
23
23
  import { tabSequence } from './tab-sequence.js';
24
+ import { ngbrRuleCriteria } from '../report/wcag.js';
24
25
  /**
25
26
  * Classify a Tab walk. Browsers pass focus through `<body>` (null here) when Tab
26
27
  * wraps off the end of the page, so an element seen again *after* a null means
@@ -140,6 +141,7 @@ export function createFocusWalkProbe(doc = document, frameworkPrefixes = DEFAULT
140
141
  `Tab (e.g. a code editor), it must tell users how to leave (such as Escape); otherwise ` +
141
142
  `let Tab move focus on. Found by real Tab presses — verify manually.`,
142
143
  helpUrl: FOCUS_TRAP_DOCS,
144
+ wcag: ngbrRuleCriteria('ngbr/focus-trap'),
143
145
  component: appComponentFromPath(componentPath, frameworkPrefixes),
144
146
  componentPath,
145
147
  directives: resolveDirectiveNames(owner),
@@ -17,6 +17,7 @@ import { findUncontainedModals } from './focus-trap.js';
17
17
  import { hoverSignal } from './hover-content.js';
18
18
  import { dragGroups, dragHandles, hasMoveControl } from './drag-drop.js';
19
19
  import { blockingModalDialog } from '../top-layer.js';
20
+ import { ngbrRuleCriteria } from '../report/wcag.js';
20
21
  import { OVERLAY_EXCLUDE_SELECTOR } from '../overlay.js';
21
22
  /** WAI-ARIA roles that make a non-native element behave as an interactive control. */
22
23
  const INTERACTIVE_ROLES = new Set([
@@ -399,6 +400,7 @@ export function scanKeyboard(root = document, options = {}) {
399
400
  impact,
400
401
  help,
401
402
  helpUrl,
403
+ wcag: ngbrRuleCriteria(id),
402
404
  component: appComponentFromPath(componentPath, prefixes),
403
405
  componentPath,
404
406
  directives: resolveDirectiveNames(element),
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { impactRank } from './format.js';
3
3
  import { escapeHtml, safeHref, STYLES } from './html.js';
4
- import { criterionForTag, understandingUrl, WCAG22_A_AA } from './wcag.js';
4
+ import { criterionForTag, NGBR_RULE_CRITERIA, understandingUrl, WCAG22_A_AA } from './wcag.js';
5
5
  export const ACR_RESULT_LABELS = {
6
6
  failures: 'Automated failures found',
7
7
  'possible-failures': 'Possible failures found — verify manually',
@@ -15,13 +15,13 @@ export const ACR_TITLE = 'Evaluation worksheet — not a conformance report';
15
15
  * documented way out; an order mismatch can be deliberate).
16
16
  */
17
17
  const NGBR_RULES = {
18
- 'ngbr/unreachable-control': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
19
- 'ngbr/click-without-key': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
20
- 'ngbr/hover-only-content': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
21
- 'ngbr/drag-without-keyboard': { criteria: ['2.1.1', '2.5.7'], ranWhen: 'keyboard' },
22
- 'ngbr/tab-order-mismatch': { criteria: ['2.4.3'], ranWhen: 'keyboard' },
23
- 'ngbr/modal-focus-not-contained': { criteria: ['2.4.3'], ranWhen: 'keyboard' },
24
- 'ngbr/focus-trap': { criteria: ['2.1.2'], ranWhen: 'focusTraps' },
18
+ 'ngbr/unreachable-control': { criteria: NGBR_RULE_CRITERIA['ngbr/unreachable-control'], ranWhen: 'keyboard' },
19
+ 'ngbr/click-without-key': { criteria: NGBR_RULE_CRITERIA['ngbr/click-without-key'], ranWhen: 'keyboard' },
20
+ 'ngbr/hover-only-content': { criteria: NGBR_RULE_CRITERIA['ngbr/hover-only-content'], ranWhen: 'keyboard' },
21
+ 'ngbr/drag-without-keyboard': { criteria: NGBR_RULE_CRITERIA['ngbr/drag-without-keyboard'], ranWhen: 'keyboard' },
22
+ 'ngbr/tab-order-mismatch': { criteria: NGBR_RULE_CRITERIA['ngbr/tab-order-mismatch'], ranWhen: 'keyboard' },
23
+ 'ngbr/modal-focus-not-contained': { criteria: NGBR_RULE_CRITERIA['ngbr/modal-focus-not-contained'], ranWhen: 'keyboard' },
24
+ 'ngbr/focus-trap': { criteria: NGBR_RULE_CRITERIA['ngbr/focus-trap'], ranWhen: 'focusTraps' },
25
25
  };
26
26
  export function loadAxeRules() {
27
27
  const axe = createRequire(import.meta.url)('axe-core');
@@ -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
@@ -1,3 +1,4 @@
1
+ import { findingCriteria, referenceUrl } from './wcag.js';
1
2
  /** One-line explanation for a dark-only page, shared by the Markdown and HTML reports. */
2
3
  export const DARK_ONLY_NOTE = 'Dark mode: lists only issues that don’t also appear in light mode on this route.';
3
4
  /**
@@ -228,6 +229,10 @@ export function toMarkdown(report, diff) {
228
229
  lines.push(`- ${isNew}**${finding.impact ?? 'n/a'} · ${finding.id}**: ${finding.help}${suffix}`);
229
230
  lines.push(` - \`${finding.target}\``);
230
231
  lines.push(` - ${finding.helpUrl}`);
232
+ const criteria = findingCriteria(finding);
233
+ if (criteria.length) {
234
+ lines.push(` - WCAG ${criteria.map((c) => `[${c.id} ${c.name}](${referenceUrl(c)})`).join(', ')}`);
235
+ }
231
236
  }
232
237
  lines.push('');
233
238
  }
@@ -1,4 +1,5 @@
1
1
  import { addedBySeverity, COVERAGE_URL, DARK_ONLY_NOTE, formatStep, REPORT_SCOPE_NOTE, REPORT_TITLE, bySeverity, distinctRuleCount, groupByComponent, viaNames, walkthroughCapNote, WALKTHROUGH_NOTE, } from './format.js';
2
+ import { findingCriteria, referenceUrl } from './wcag.js';
2
3
  /**
3
4
  * A single self-contained HTML report: inline CSS, no scripts, no external
4
5
  * requests — so it can be attached to a CI run, emailed, or opened offline.
@@ -160,6 +161,9 @@ export function toHtml(report, diff) {
160
161
  if (href) {
161
162
  out.push(` · <a href="${href}">Rule reference<span class="visually-hidden"> for ${escapeHtml(finding.id)}</span></a>`);
162
163
  }
164
+ for (const c of findingCriteria(finding)) {
165
+ out.push(` · <a href="${referenceUrl(c)}">WCAG ${escapeHtml(c.id)} ${escapeHtml(c.name)}</a>`);
166
+ }
163
167
  out.push('</p>');
164
168
  out.push('</li>');
165
169
  }
@@ -22,3 +22,24 @@ export declare function understandingUrl(criterion: WcagCriterion): string;
22
22
  * {@link WCAG22_A_AA}. Dropping the dots is unambiguous within the A/AA set.
23
23
  */
24
24
  export declare function criterionForTag(tag: string): WcagCriterion | undefined;
25
+ /** Where the NgBracket accessibility reference explains each criterion. */
26
+ export declare const REFERENCE_WCAG_URL = "https://ngbracket.com/reference/wcag";
27
+ /** The criterion's page in the NgBracket accessibility reference. */
28
+ export declare function referenceUrl(criterion: WcagCriterion): string;
29
+ /**
30
+ * The criteria the tool's own `ngbr/*` rules check, from the "Standard" row of
31
+ * each rule's docs page. axe findings take theirs from axe's tags.
32
+ */
33
+ export declare const NGBR_RULE_CRITERIA: Readonly<Record<string, readonly string[]>>;
34
+ /** The `wcag` list for an `ngbr/*` finding; [] for an unknown id. */
35
+ export declare function ngbrRuleCriteria(id: string): string[];
36
+ /**
37
+ * The WCAG 2.2 A and AA criteria a finding relates to, in document order:
38
+ * its `wcag` list, or for an `ngbr/*` finding saved before 0.19.0 (no `wcag`),
39
+ * the rule's fixed list. Empty for axe's best-practice rules, which have no
40
+ * criterion.
41
+ */
42
+ export declare function findingCriteria(finding: {
43
+ id: string;
44
+ wcag?: readonly string[];
45
+ }): WcagCriterion[];
@@ -74,3 +74,36 @@ export function criterionForTag(tag) {
74
74
  return digits ? BY_DIGITS.get(digits) : undefined;
75
75
  }
76
76
  const BY_DIGITS = new Map(WCAG22_A_AA.map((c) => [c.id.replace(/\./g, ''), c]));
77
+ /** Where the NgBracket accessibility reference explains each criterion. */
78
+ export const REFERENCE_WCAG_URL = 'https://ngbracket.com/reference/wcag';
79
+ /** The criterion's page in the NgBracket accessibility reference. */
80
+ export function referenceUrl(criterion) {
81
+ return `${REFERENCE_WCAG_URL}/${criterion.slug}`;
82
+ }
83
+ /**
84
+ * The criteria the tool's own `ngbr/*` rules check, from the "Standard" row of
85
+ * each rule's docs page. axe findings take theirs from axe's tags.
86
+ */
87
+ export const NGBR_RULE_CRITERIA = {
88
+ 'ngbr/unreachable-control': ['2.1.1'],
89
+ 'ngbr/click-without-key': ['2.1.1'],
90
+ 'ngbr/hover-only-content': ['2.1.1'],
91
+ 'ngbr/drag-without-keyboard': ['2.1.1', '2.5.7'],
92
+ 'ngbr/tab-order-mismatch': ['2.4.3'],
93
+ 'ngbr/modal-focus-not-contained': ['2.4.3'],
94
+ 'ngbr/focus-trap': ['2.1.2'],
95
+ };
96
+ /** The `wcag` list for an `ngbr/*` finding; [] for an unknown id. */
97
+ export function ngbrRuleCriteria(id) {
98
+ return [...(NGBR_RULE_CRITERIA[id] ?? [])];
99
+ }
100
+ /**
101
+ * The WCAG 2.2 A and AA criteria a finding relates to, in document order:
102
+ * its `wcag` list, or for an `ngbr/*` finding saved before 0.19.0 (no `wcag`),
103
+ * the rule's fixed list. Empty for axe's best-practice rules, which have no
104
+ * criterion.
105
+ */
106
+ export function findingCriteria(finding) {
107
+ const ids = new Set(finding.wcag ?? NGBR_RULE_CRITERIA[finding.id] ?? []);
108
+ return WCAG22_A_AA.filter((c) => ids.has(c.id));
109
+ }
package/dist/report.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { groupByComponent } from './report/format.js';
2
+ import { findingCriteria, referenceUrl } from './report/wcag.js';
2
3
  /**
3
4
  * Log findings grouped by the component that owns them — the readable form the
4
5
  * attribution makes possible ("♿ UserCardComponent — 2 issues" beats a list of
@@ -15,7 +16,10 @@ export function logFindings(findings, logger = console) {
15
16
  logger.groupCollapsed(`♿ ${component} — ${items.length} issue(s)`);
16
17
  for (const finding of items) {
17
18
  const via = finding.directives.length ? ` [via ${finding.directives.join(', ')}]` : '';
18
- logger.warn(`${finding.impact ?? 'n/a'} · ${finding.id}: ${finding.help}${via}`, `\n ${finding.target}\n ${finding.helpUrl}`);
19
+ logger.warn(`${finding.impact ?? 'n/a'} · ${finding.id}: ${finding.help}${via}`, `\n ${finding.target}\n ${finding.helpUrl}` +
20
+ findingCriteria(finding)
21
+ .map((c) => `\n WCAG ${c.id} ${c.name}: ${referenceUrl(c)}`)
22
+ .join(''));
19
23
  }
20
24
  logger.groupEnd();
21
25
  }
package/dist/scan.d.ts CHANGED
@@ -24,6 +24,13 @@ export interface A11yFinding {
24
24
  impact: Impact;
25
25
  help: string;
26
26
  helpUrl: string;
27
+ /**
28
+ * WCAG 2.2 A and AA criteria the rule checks, e.g. `['1.4.3']`: from the
29
+ * axe rule's tags, or from the docs page of an `ngbr/*` rule. Empty for
30
+ * axe's best-practice rules. Optional because reports saved before 0.19.0
31
+ * don't have it.
32
+ */
33
+ wcag?: string[];
27
34
  /** Owning component name, or null when attribution isn't available (prod). */
28
35
  component: string | null;
29
36
  /** Owning components from the flagged node up to the root, nearest first, each once; [] in prod. */
package/dist/scan.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, } from './attribution.js';
2
2
  import { OVERLAY_EXCLUDE_SELECTOR } from './overlay.js';
3
3
  import { scanKeyboard } from './keyboard/keyboard-scan.js';
4
+ import { criterionForTag } from './report/wcag.js';
4
5
  // axe-core is a singleton and throws if a run starts while another is in flight.
5
6
  // Chain runs so overlapping callers (e.g. rapid rescans) serialize safely.
6
7
  let runChain = Promise.resolve();
@@ -39,6 +40,7 @@ async function runAxeOnce(root, options, scanOptions) {
39
40
  impact: (violation.impact ?? null),
40
41
  help: violation.help,
41
42
  helpUrl: violation.helpUrl,
43
+ wcag: violation.tags.flatMap((tag) => criterionForTag(tag)?.id ?? []),
42
44
  component: appComponentFromPath(componentPath, frameworkPrefixes),
43
45
  componentPath,
44
46
  directives: element ? resolveDirectiveNames(element) : [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.18.5",
3
+ "version": "0.19.0",
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",