@ngbracket/a11y-devtools 0.18.6 → 0.20.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 +55 -0
- package/README.md +4 -0
- package/bin/ngbr-a11y-report.mjs +13 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inpage.global.js +307 -0
- package/dist/inpage.js +4 -0
- package/dist/keyboard/focus-walk.d.ts +2 -0
- package/dist/keyboard/focus-walk.js +3 -1
- package/dist/keyboard/keyboard-scan.js +2 -0
- package/dist/navigation/focus-loss.d.ts +39 -0
- package/dist/navigation/focus-loss.js +270 -0
- package/dist/navigation/record.d.ts +34 -0
- package/dist/navigation/record.js +15 -0
- package/dist/pill-menu.d.ts +2 -0
- package/dist/pill-menu.js +21 -2
- package/dist/provider.d.ts +14 -0
- package/dist/provider.js +72 -5
- package/dist/report/acr.js +16 -9
- package/dist/report/format.d.ts +9 -0
- package/dist/report/format.js +37 -0
- package/dist/report/headless.d.ts +10 -0
- package/dist/report/headless.js +162 -3
- package/dist/report/html.js +19 -1
- package/dist/report/wcag.d.ts +21 -0
- package/dist/report/wcag.js +35 -0
- package/dist/report.js +5 -1
- package/dist/scan.d.ts +7 -0
- package/dist/scan.js +2 -0
- package/package.json +2 -1
package/dist/report/format.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { findingCriteria, referenceUrl } from './wcag.js';
|
|
2
|
+
import { describeNavigation } from '../navigation/record.js';
|
|
1
3
|
/** One-line explanation for a dark-only page, shared by the Markdown and HTML reports. */
|
|
2
4
|
export const DARK_ONLY_NOTE = 'Dark mode: lists only issues that don’t also appear in light mode on this route.';
|
|
3
5
|
/**
|
|
@@ -6,6 +8,18 @@ export const DARK_ONLY_NOTE = 'Dark mode: lists only issues that don’t also ap
|
|
|
6
8
|
*/
|
|
7
9
|
export const WALKTHROUGH_NOTE = 'Each tab stop in order, with its computed role, name and states. A computed approximation, ' +
|
|
8
10
|
'not what any one screen reader announces.';
|
|
11
|
+
/** Heading note for the route change, shared by the Markdown and HTML reports. */
|
|
12
|
+
export const NAVIGATION_NOTE = 'The run moved here from the previous route inside the app, the way a keyboard user would. ' +
|
|
13
|
+
'Where focus went, whether the page title changed, and what live regions announced.';
|
|
14
|
+
/** The route change as one line, saying how the run made it. */
|
|
15
|
+
export function formatNavigation(record) {
|
|
16
|
+
const how = record.via === 'link'
|
|
17
|
+
? ' (pressed Enter on a link)'
|
|
18
|
+
: record.via === 'history'
|
|
19
|
+
? ' (no link to this route, so the run changed the URL with history.pushState)'
|
|
20
|
+
: '';
|
|
21
|
+
return `${describeNavigation(record)}${how}`;
|
|
22
|
+
}
|
|
9
23
|
/** One walkthrough step as a single line, e.g. `button "Save" (disabled) — SaveBarComponent`. */
|
|
10
24
|
export function formatStep(step) {
|
|
11
25
|
const role = step.role ?? `<${step.tag}>`;
|
|
@@ -105,6 +119,7 @@ export function toJson(report, diff) {
|
|
|
105
119
|
nodeInstances: p.findings.length,
|
|
106
120
|
findings: p.findings,
|
|
107
121
|
...(p.walkthrough && { walkthrough: p.walkthrough }),
|
|
122
|
+
...(p.navigation && { navigation: p.navigation }),
|
|
108
123
|
})),
|
|
109
124
|
}, null, 2);
|
|
110
125
|
}
|
|
@@ -140,9 +155,17 @@ export function parseReport(json) {
|
|
|
140
155
|
...(p.colorScheme && { colorScheme: p.colorScheme }),
|
|
141
156
|
...(p.darkOnly && { darkOnly: true }),
|
|
142
157
|
...(isWalkthrough(p.walkthrough) && { walkthrough: p.walkthrough }),
|
|
158
|
+
...(isNavigationRecord(p.navigation) && { navigation: p.navigation }),
|
|
143
159
|
})),
|
|
144
160
|
};
|
|
145
161
|
}
|
|
162
|
+
function isNavigationRecord(n) {
|
|
163
|
+
const r = n;
|
|
164
|
+
return (typeof r?.from === 'string' &&
|
|
165
|
+
typeof r.to === 'string' &&
|
|
166
|
+
typeof r.focus === 'string' &&
|
|
167
|
+
Array.isArray(r.announcements));
|
|
168
|
+
}
|
|
146
169
|
function isWalkthrough(w) {
|
|
147
170
|
return Array.isArray(w?.steps) && typeof w.total === 'number';
|
|
148
171
|
}
|
|
@@ -212,6 +235,7 @@ export function toMarkdown(report, diff) {
|
|
|
212
235
|
if (page.findings.length === 0) {
|
|
213
236
|
lines.push('No automated violations found. ✅');
|
|
214
237
|
lines.push('');
|
|
238
|
+
lines.push(...markdownNavigation(page));
|
|
215
239
|
lines.push(...markdownWalkthrough(page));
|
|
216
240
|
continue;
|
|
217
241
|
}
|
|
@@ -228,13 +252,26 @@ export function toMarkdown(report, diff) {
|
|
|
228
252
|
lines.push(`- ${isNew}**${finding.impact ?? 'n/a'} · ${finding.id}**: ${finding.help}${suffix}`);
|
|
229
253
|
lines.push(` - \`${finding.target}\``);
|
|
230
254
|
lines.push(` - ${finding.helpUrl}`);
|
|
255
|
+
const criteria = findingCriteria(finding);
|
|
256
|
+
if (criteria.length) {
|
|
257
|
+
lines.push(` - WCAG ${criteria.map((c) => `[${c.id} ${c.name}](${referenceUrl(c)})`).join(', ')}`);
|
|
258
|
+
}
|
|
231
259
|
}
|
|
232
260
|
lines.push('');
|
|
233
261
|
}
|
|
262
|
+
lines.push(...markdownNavigation(page));
|
|
234
263
|
lines.push(...markdownWalkthrough(page));
|
|
235
264
|
}
|
|
236
265
|
return lines.join('\n');
|
|
237
266
|
}
|
|
267
|
+
/** The route change into a page under its own heading, or nothing. */
|
|
268
|
+
function markdownNavigation(page) {
|
|
269
|
+
if (!page.navigation)
|
|
270
|
+
return [];
|
|
271
|
+
// Titles and announcements are page text: escape anything Markdown would read as markup.
|
|
272
|
+
const line = formatNavigation(page.navigation).replace(/([<>*_`[\]\\|&])/g, '\\$1');
|
|
273
|
+
return ['### Route change', '', `_${NAVIGATION_NOTE}_`, '', line, ''];
|
|
274
|
+
}
|
|
238
275
|
/** A page's walkthrough as a numbered Markdown list under its own heading, or nothing. */
|
|
239
276
|
function markdownWalkthrough(page) {
|
|
240
277
|
const walkthrough = page.walkthrough;
|
|
@@ -89,6 +89,16 @@ export interface ScanPagesOptions {
|
|
|
89
89
|
* light pass only. Default false.
|
|
90
90
|
*/
|
|
91
91
|
walkthrough?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Also move between the routes inside the app, in the order given, the way a
|
|
94
|
+
* keyboard user would: focus a link to the next route and press Enter, or
|
|
95
|
+
* when the page has no such link, change the URL with `history.pushState`.
|
|
96
|
+
* Each route then records where focus went, whether the title changed and
|
|
97
|
+
* what live regions announced, and focus left on the page body is reported
|
|
98
|
+
* as `ngbr/focus-lost-on-navigation`. Runs in its own browser session after
|
|
99
|
+
* the scan, once (in the light scheme with `colorScheme: 'both'`). Default false.
|
|
100
|
+
*/
|
|
101
|
+
navigation?: boolean;
|
|
92
102
|
}
|
|
93
103
|
/**
|
|
94
104
|
* Drive a real headless browser over a running Angular **dev** build and return
|
package/dist/report/headless.js
CHANGED
|
@@ -58,6 +58,147 @@ async function walkForFocusTrap(page, frameworkPrefixes) {
|
|
|
58
58
|
}
|
|
59
59
|
return null;
|
|
60
60
|
}
|
|
61
|
+
/** A route as the focus-loss probe keys it: path and query, plus a `#/` hash. */
|
|
62
|
+
function routeKey(url) {
|
|
63
|
+
return url.pathname + url.search + (url.hash.startsWith('#/') ? url.hash : '');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Load the first route, then move to each next route inside the app and ask the
|
|
67
|
+
* in-page probe what happened to focus. Results are keyed by the route's index
|
|
68
|
+
* in `routes`. A full page load (a link outside the app's router) is not a
|
|
69
|
+
* route change inside the app, so it's skipped with a warning.
|
|
70
|
+
*/
|
|
71
|
+
async function navigationPass(browser, colorScheme, config) {
|
|
72
|
+
const { baseUrl, routes, waitMs, inPageScript, frameworkPrefixes } = config;
|
|
73
|
+
const results = new Map();
|
|
74
|
+
if (routes.length < 2)
|
|
75
|
+
return results;
|
|
76
|
+
const context = await browser.newContext({
|
|
77
|
+
viewport: { width: 1280, height: 900 },
|
|
78
|
+
colorScheme,
|
|
79
|
+
bypassCSP: true,
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const page = await context.newPage();
|
|
83
|
+
if (config.setup) {
|
|
84
|
+
await page.goto(baseUrl, { waitUntil: 'domcontentloaded' });
|
|
85
|
+
await config.setup(page, { colorScheme });
|
|
86
|
+
}
|
|
87
|
+
const settle = async () => {
|
|
88
|
+
await page.waitForLoadState('networkidle').catch(() => undefined);
|
|
89
|
+
await page.waitForTimeout(waitMs);
|
|
90
|
+
};
|
|
91
|
+
// What the probe has reported so far, so each route takes only its own.
|
|
92
|
+
let recordCount = 0;
|
|
93
|
+
let findingCount = 0;
|
|
94
|
+
const startProbe = async () => {
|
|
95
|
+
recordCount = 0;
|
|
96
|
+
findingCount = 0;
|
|
97
|
+
await page.addStyleTag({ content: HIDE_OVERLAY_CSS });
|
|
98
|
+
await page.addScriptTag({ content: inPageScript });
|
|
99
|
+
await page.evaluate((prefixes) => {
|
|
100
|
+
const w = window;
|
|
101
|
+
w.__ngbA11yFocusLossProbe = w.__ngbA11yCreateFocusLossProbe(prefixes);
|
|
102
|
+
}, frameworkPrefixes);
|
|
103
|
+
};
|
|
104
|
+
const probeRunning = () => page.evaluate(() => window.__ngbA11yFocusLossProbe !== undefined);
|
|
105
|
+
const first = new URL(routes[0], baseUrl).toString();
|
|
106
|
+
await page.goto(first, { waitUntil: 'networkidle' }).catch(() => page.goto(first));
|
|
107
|
+
await page.waitForTimeout(waitMs);
|
|
108
|
+
await startProbe();
|
|
109
|
+
for (let i = 1; i < routes.length; i++) {
|
|
110
|
+
const route = routes[i];
|
|
111
|
+
const target = new URL(route, baseUrl);
|
|
112
|
+
try {
|
|
113
|
+
// Focus a visible link in the page that goes to this route, in the same
|
|
114
|
+
// tab. Without one, change the URL: the Angular Router (like most SPA
|
|
115
|
+
// routers) follows popstate.
|
|
116
|
+
const via = await page.evaluate((href) => {
|
|
117
|
+
const key = (u) => u.pathname + u.search + (u.hash.startsWith('#/') ? u.hash : '');
|
|
118
|
+
const wanted = key(new URL(href));
|
|
119
|
+
for (const link of document.querySelectorAll('a[href]')) {
|
|
120
|
+
if (!(link instanceof HTMLAnchorElement))
|
|
121
|
+
continue; // an SVG <a>
|
|
122
|
+
if (link.target && link.target !== '_self')
|
|
123
|
+
continue;
|
|
124
|
+
if (link.closest('[data-ngb-a11y-overlay], [inert], [aria-hidden="true"]'))
|
|
125
|
+
continue;
|
|
126
|
+
if (typeof link.checkVisibility === 'function' && !link.checkVisibility())
|
|
127
|
+
continue;
|
|
128
|
+
let url;
|
|
129
|
+
try {
|
|
130
|
+
url = new URL(link.href);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (url.origin !== location.origin || key(url) !== wanted)
|
|
136
|
+
continue;
|
|
137
|
+
link.focus();
|
|
138
|
+
if (document.activeElement === link)
|
|
139
|
+
return 'link';
|
|
140
|
+
}
|
|
141
|
+
history.pushState(null, '', href);
|
|
142
|
+
dispatchEvent(new PopStateEvent('popstate', { state: null }));
|
|
143
|
+
return 'history';
|
|
144
|
+
}, target.toString());
|
|
145
|
+
if (via === 'link')
|
|
146
|
+
await page.keyboard.press('Enter');
|
|
147
|
+
await settle();
|
|
148
|
+
if (!(await probeRunning())) {
|
|
149
|
+
console.warn(`ngbr-a11y-report: moving to ${route} loaded a new page, so it wasn't a route change ` +
|
|
150
|
+
`inside the app; skipped the focus check.`);
|
|
151
|
+
await startProbe();
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const seen = await page.evaluate(async () => {
|
|
155
|
+
const probe = window.__ngbA11yFocusLossProbe;
|
|
156
|
+
probe.notifyStable();
|
|
157
|
+
await probe.settled();
|
|
158
|
+
return { records: probe.records(), findings: probe.findings() };
|
|
159
|
+
});
|
|
160
|
+
const record = seen.records.length > recordCount ? seen.records.at(-1) : undefined;
|
|
161
|
+
recordCount = seen.records.length;
|
|
162
|
+
const findings = seen.findings.slice(findingCount);
|
|
163
|
+
findingCount = seen.findings.length;
|
|
164
|
+
if (!record) {
|
|
165
|
+
console.warn(`ngbr-a11y-report: moving to ${route} didn't change the route; skipped the focus check.`);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (record.to !== routeKey(target)) {
|
|
169
|
+
console.warn(`ngbr-a11y-report: moving to ${route} ended on ${record.to} (a redirect?).`);
|
|
170
|
+
}
|
|
171
|
+
results.set(i, { record: { ...record, via }, findings });
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
175
|
+
console.warn(`ngbr-a11y-report: route change to ${route} failed: ${message}`);
|
|
176
|
+
// Start again from what's on the page now, so the next route takes only its own results.
|
|
177
|
+
try {
|
|
178
|
+
await settle();
|
|
179
|
+
if (!(await probeRunning())) {
|
|
180
|
+
await startProbe();
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const counts = await page.evaluate(() => {
|
|
184
|
+
const probe = window.__ngbA11yFocusLossProbe;
|
|
185
|
+
return { records: probe.records().length, findings: probe.findings().length };
|
|
186
|
+
});
|
|
187
|
+
recordCount = counts.records;
|
|
188
|
+
findingCount = counts.findings;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// The page is gone; the next route's own error says so.
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
await context.close();
|
|
199
|
+
}
|
|
200
|
+
return results;
|
|
201
|
+
}
|
|
61
202
|
/** Settle time after switching a class/attribute theme, so colour transitions finish before axe reads them. */
|
|
62
203
|
const THEME_SETTLE_MS = 300;
|
|
63
204
|
/**
|
|
@@ -161,7 +302,7 @@ async function scanPass(browser, colorScheme, config) {
|
|
|
161
302
|
* to the component that rendered it — with no change to the target app.
|
|
162
303
|
*/
|
|
163
304
|
export async function scanPages(options) {
|
|
164
|
-
const { baseUrl, routes, tags, waitMs = 1500, labels = {}, setup, beforeScan, headed = false, frameworkPrefixes, keyboard, focusTraps = false, walkthrough = false, darkClass, darkAttribute, } = options;
|
|
305
|
+
const { baseUrl, routes, tags, waitMs = 1500, labels = {}, setup, beforeScan, headed = false, frameworkPrefixes, keyboard, focusTraps = false, walkthrough = false, navigation = false, darkClass, darkAttribute, } = options;
|
|
165
306
|
const colorScheme = options.colorScheme ?? (darkClass || darkAttribute ? 'both' : 'light');
|
|
166
307
|
const config = {
|
|
167
308
|
baseUrl,
|
|
@@ -174,6 +315,7 @@ export async function scanPages(options) {
|
|
|
174
315
|
keyboard,
|
|
175
316
|
focusTraps,
|
|
176
317
|
walkthrough,
|
|
318
|
+
navigation,
|
|
177
319
|
setup,
|
|
178
320
|
beforeScan,
|
|
179
321
|
darkClass,
|
|
@@ -182,12 +324,27 @@ export async function scanPages(options) {
|
|
|
182
324
|
const { chromium } = await loadPlaywright();
|
|
183
325
|
const browser = await chromium.launch({ headless: !headed });
|
|
184
326
|
let pages;
|
|
327
|
+
let moves = new Map();
|
|
185
328
|
try {
|
|
329
|
+
// Route changes don't depend on the theme: check them once.
|
|
330
|
+
if (navigation && routes.length < 2) {
|
|
331
|
+
console.warn('ngbr-a11y-report: --navigation needs 2 or more routes; skipped the route-change check.');
|
|
332
|
+
}
|
|
333
|
+
moves = navigation
|
|
334
|
+
? await navigationPass(browser, colorScheme === 'both' ? 'light' : colorScheme, config)
|
|
335
|
+
: new Map();
|
|
336
|
+
// A route that failed to scan keeps only its error.
|
|
337
|
+
const withMoves = (scanned) => scanned.map((page, i) => {
|
|
338
|
+
const move = moves.get(i);
|
|
339
|
+
return move && !page.error
|
|
340
|
+
? { ...page, findings: [...page.findings, ...move.findings], navigation: move.record }
|
|
341
|
+
: page;
|
|
342
|
+
});
|
|
186
343
|
if (colorScheme !== 'both') {
|
|
187
|
-
pages = await scanPass(browser, colorScheme, config);
|
|
344
|
+
pages = withMoves(await scanPass(browser, colorScheme, config));
|
|
188
345
|
}
|
|
189
346
|
else {
|
|
190
|
-
const light = await scanPass(browser, 'light', config);
|
|
347
|
+
const light = withMoves(await scanPass(browser, 'light', config));
|
|
191
348
|
// Keyboard traps and the tab order don't depend on the theme; doing them twice only costs time.
|
|
192
349
|
const dark = await scanPass(browser, 'dark', { ...config, focusTraps: false, walkthrough: false });
|
|
193
350
|
// Interleave per route (light, then its dark) and keep only what dark adds.
|
|
@@ -209,6 +366,8 @@ export async function scanPages(options) {
|
|
|
209
366
|
keyboard: keyboard ?? false,
|
|
210
367
|
focusTraps,
|
|
211
368
|
...(walkthrough && { walkthrough }),
|
|
369
|
+
// Only when at least one route change was checked, so the ACR doesn't count a check that didn't happen.
|
|
370
|
+
...(moves.size > 0 && { navigation: true }),
|
|
212
371
|
};
|
|
213
372
|
return { generatedAt: new Date().toISOString(), checks, pages };
|
|
214
373
|
}
|
package/dist/report/html.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { addedBySeverity, COVERAGE_URL, DARK_ONLY_NOTE, formatStep, REPORT_SCOPE_NOTE, REPORT_TITLE, bySeverity, distinctRuleCount, groupByComponent, viaNames, walkthroughCapNote, WALKTHROUGH_NOTE, } from './format.js';
|
|
1
|
+
import { addedBySeverity, COVERAGE_URL, DARK_ONLY_NOTE, formatNavigation, formatStep, NAVIGATION_NOTE, 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.
|
|
@@ -138,6 +139,7 @@ export function toHtml(report, diff) {
|
|
|
138
139
|
}
|
|
139
140
|
if (page.findings.length === 0) {
|
|
140
141
|
out.push('<p class="ok">No automated violations found.</p>');
|
|
142
|
+
out.push(...htmlNavigation(page));
|
|
141
143
|
out.push(...htmlWalkthrough(page));
|
|
142
144
|
out.push('</section>');
|
|
143
145
|
return;
|
|
@@ -160,12 +162,16 @@ export function toHtml(report, diff) {
|
|
|
160
162
|
if (href) {
|
|
161
163
|
out.push(` · <a href="${href}">Rule reference<span class="visually-hidden"> for ${escapeHtml(finding.id)}</span></a>`);
|
|
162
164
|
}
|
|
165
|
+
for (const c of findingCriteria(finding)) {
|
|
166
|
+
out.push(` · <a href="${referenceUrl(c)}">WCAG ${escapeHtml(c.id)} ${escapeHtml(c.name)}</a>`);
|
|
167
|
+
}
|
|
163
168
|
out.push('</p>');
|
|
164
169
|
out.push('</li>');
|
|
165
170
|
}
|
|
166
171
|
out.push('</ul>');
|
|
167
172
|
out.push('</div>');
|
|
168
173
|
}
|
|
174
|
+
out.push(...htmlNavigation(page));
|
|
169
175
|
out.push(...htmlWalkthrough(page));
|
|
170
176
|
out.push('</section>');
|
|
171
177
|
});
|
|
@@ -174,6 +180,18 @@ export function toHtml(report, diff) {
|
|
|
174
180
|
out.push('</html>');
|
|
175
181
|
return out.join('\n');
|
|
176
182
|
}
|
|
183
|
+
/** The route change into a page under its own heading, or nothing. */
|
|
184
|
+
function htmlNavigation(page) {
|
|
185
|
+
if (!page.navigation)
|
|
186
|
+
return [];
|
|
187
|
+
return [
|
|
188
|
+
'<div class="walkthrough">',
|
|
189
|
+
'<h3>Route change</h3>',
|
|
190
|
+
`<p class="meta">${escapeHtml(NAVIGATION_NOTE)}</p>`,
|
|
191
|
+
`<p>${escapeHtml(formatNavigation(page.navigation))}</p>`,
|
|
192
|
+
'</div>',
|
|
193
|
+
];
|
|
194
|
+
}
|
|
177
195
|
/** A page's walkthrough as an ordered list under its own heading, or nothing. */
|
|
178
196
|
function htmlWalkthrough(page) {
|
|
179
197
|
const walkthrough = page.walkthrough;
|
package/dist/report/wcag.d.ts
CHANGED
|
@@ -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[];
|
package/dist/report/wcag.js
CHANGED
|
@@ -74,3 +74,38 @@ 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
|
+
'ngbr/focus-lost-on-navigation': ['2.4.3'],
|
|
96
|
+
'ngbr/focus-lost-on-rerender': ['2.4.3'],
|
|
97
|
+
};
|
|
98
|
+
/** The `wcag` list for an `ngbr/*` finding; [] for an unknown id. */
|
|
99
|
+
export function ngbrRuleCriteria(id) {
|
|
100
|
+
return [...(NGBR_RULE_CRITERIA[id] ?? [])];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The WCAG 2.2 A and AA criteria a finding relates to, in document order:
|
|
104
|
+
* its `wcag` list, or for an `ngbr/*` finding saved before 0.19.0 (no `wcag`),
|
|
105
|
+
* the rule's fixed list. Empty for axe's best-practice rules, which have no
|
|
106
|
+
* criterion.
|
|
107
|
+
*/
|
|
108
|
+
export function findingCriteria(finding) {
|
|
109
|
+
const ids = new Set(finding.wcag ?? NGBR_RULE_CRITERIA[finding.id] ?? []);
|
|
110
|
+
return WCAG22_A_AA.filter((c) => ids.has(c.id));
|
|
111
|
+
}
|
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.
|
|
3
|
+
"version": "0.20.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",
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"@angular/forms": "^22.2.1",
|
|
83
83
|
"@angular/platform-browser": "^22.2.1",
|
|
84
84
|
"@angular/platform-browser-dynamic": "^22.2.1",
|
|
85
|
+
"@angular/router": "^22.2.1",
|
|
85
86
|
"@emnapi/core": "^1.11.3",
|
|
86
87
|
"@emnapi/runtime": "^1.11.3",
|
|
87
88
|
"@oxc-project/runtime": "^0.149.0",
|