@ngbracket/a11y-devtools 0.4.0 → 0.6.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 +44 -0
- package/README.md +51 -5
- package/bin/ngbr-a11y-report.mjs +17 -0
- package/dist/attribution.d.ts +41 -3
- package/dist/attribution.js +59 -15
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/inpage.d.ts +2 -2
- package/dist/inpage.global.js +334 -20
- package/dist/inpage.js +1 -1
- package/dist/keyboard/keyboard-scan.d.ts +14 -0
- package/dist/keyboard/keyboard-scan.js +117 -0
- package/dist/keyboard/tab-sequence.d.ts +58 -0
- package/dist/keyboard/tab-sequence.js +178 -0
- package/dist/overlay.d.ts +8 -0
- package/dist/overlay.js +87 -1
- package/dist/provider.d.ts +15 -0
- package/dist/provider.js +11 -3
- package/dist/report/headless.d.ts +14 -0
- package/dist/report/headless.js +4 -4
- package/dist/runner.d.ts +12 -0
- package/dist/runner.js +4 -1
- package/dist/scan.d.ts +18 -1
- package/dist/scan.js +12 -5
- package/package.json +1 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard layer, part A: compute the order in which Tab moves through a
|
|
3
|
+
* page. This is the ~2/3 of accessibility axe can't test — keyboard operability
|
|
4
|
+
* — and, like the axe findings, every stop is attributed to the component that
|
|
5
|
+
* rendered it.
|
|
6
|
+
*
|
|
7
|
+
* The tabbable set and ordering mirror the browser's own algorithm (and the
|
|
8
|
+
* well-known `tabbable` element definition), implemented here with no runtime
|
|
9
|
+
* dependency: elements with a positive `tabindex` come first in ascending order
|
|
10
|
+
* (the anti-pattern that hijacks focus order), then everything with `tabindex=0`
|
|
11
|
+
* or a native default in DOM order.
|
|
12
|
+
*/
|
|
13
|
+
import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, } from '../attribution.js';
|
|
14
|
+
/** Elements that can hold focus and thus may appear in the tab order. */
|
|
15
|
+
const FOCUSABLE_SELECTOR = [
|
|
16
|
+
'a[href]',
|
|
17
|
+
'area[href]',
|
|
18
|
+
'button',
|
|
19
|
+
'input',
|
|
20
|
+
'select',
|
|
21
|
+
'textarea',
|
|
22
|
+
'audio[controls]',
|
|
23
|
+
'video[controls]',
|
|
24
|
+
'summary',
|
|
25
|
+
'iframe',
|
|
26
|
+
'object',
|
|
27
|
+
'embed',
|
|
28
|
+
'[contenteditable]',
|
|
29
|
+
'[tabindex]',
|
|
30
|
+
].join(',');
|
|
31
|
+
/** A native default of 0 (focusable without a tabindex attribute), else -1. */
|
|
32
|
+
function nativeTabIndex(element) {
|
|
33
|
+
return isNativelyFocusable(element) ? 0 : -1;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* True when the element takes focus without an explicit `tabindex` — a link with
|
|
37
|
+
* an href, a form control, a `<summary>`, an editing host, and the embedded
|
|
38
|
+
* document elements. Disabled/hidden state is handled separately.
|
|
39
|
+
*/
|
|
40
|
+
export function isNativelyFocusable(element) {
|
|
41
|
+
const tag = element.tagName.toLowerCase();
|
|
42
|
+
switch (tag) {
|
|
43
|
+
case 'a':
|
|
44
|
+
case 'area':
|
|
45
|
+
return element.hasAttribute('href');
|
|
46
|
+
case 'button':
|
|
47
|
+
case 'select':
|
|
48
|
+
case 'textarea':
|
|
49
|
+
return true;
|
|
50
|
+
case 'input':
|
|
51
|
+
return element.getAttribute('type')?.toLowerCase() !== 'hidden';
|
|
52
|
+
case 'summary':
|
|
53
|
+
return true;
|
|
54
|
+
case 'iframe':
|
|
55
|
+
case 'object':
|
|
56
|
+
case 'embed':
|
|
57
|
+
return true;
|
|
58
|
+
case 'audio':
|
|
59
|
+
case 'video':
|
|
60
|
+
return element.hasAttribute('controls');
|
|
61
|
+
}
|
|
62
|
+
const editable = element.getAttribute('contenteditable');
|
|
63
|
+
return editable !== null && editable !== 'false';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The tabindex the browser will use: the parsed attribute when present and
|
|
67
|
+
* numeric, otherwise the native default. A non-numeric `tabindex` (e.g.
|
|
68
|
+
* `tabindex="foo"`) is ignored by browsers, so it falls back to the native value.
|
|
69
|
+
*/
|
|
70
|
+
export function resolvedTabIndex(element) {
|
|
71
|
+
const attr = element.getAttribute('tabindex');
|
|
72
|
+
if (attr === null)
|
|
73
|
+
return nativeTabIndex(element);
|
|
74
|
+
const parsed = Number.parseInt(attr, 10);
|
|
75
|
+
return Number.isNaN(parsed) ? nativeTabIndex(element) : parsed;
|
|
76
|
+
}
|
|
77
|
+
/** True when `element` (or an ancestor) is disabled via a control or `<fieldset disabled>`. */
|
|
78
|
+
function isDisabled(element) {
|
|
79
|
+
if ('disabled' in element && element.disabled)
|
|
80
|
+
return true;
|
|
81
|
+
// A disabled fieldset disables its controls (except those inside its first legend).
|
|
82
|
+
return element.closest('fieldset[disabled]') !== null && element.closest('legend') === null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Structurally hidden — removed from the tab order by markup, independent of any
|
|
86
|
+
* layout: inside an `[inert]` or `[hidden]` subtree, or non-summary content of a
|
|
87
|
+
* closed `<details>`. Kept separate from the layout check so the injectable
|
|
88
|
+
* visibility predicate only ever overrides computed-style visibility.
|
|
89
|
+
*/
|
|
90
|
+
function isStructurallyHidden(element) {
|
|
91
|
+
if (element.closest('[inert]') || element.closest('[hidden]'))
|
|
92
|
+
return true;
|
|
93
|
+
const closedDetails = element.closest('details:not([open])');
|
|
94
|
+
return closedDetails !== null && element.closest('summary') === null && element !== closedDetails;
|
|
95
|
+
}
|
|
96
|
+
/** Layout-aware default visibility: computed `display`/`visibility` up the tree. */
|
|
97
|
+
function defaultIsVisible(element) {
|
|
98
|
+
const view = element.ownerDocument?.defaultView;
|
|
99
|
+
if (!view?.getComputedStyle)
|
|
100
|
+
return true; // no layout engine (e.g. jsdom) — assume visible
|
|
101
|
+
for (let node = element; node; node = node.parentElement) {
|
|
102
|
+
const style = view.getComputedStyle(node);
|
|
103
|
+
if (style.display === 'none')
|
|
104
|
+
return false;
|
|
105
|
+
if (style.visibility === 'hidden' || style.visibility === 'collapse')
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* True when `element` participates in sequential keyboard navigation: it's
|
|
112
|
+
* focusable, has a resolved `tabindex >= 0`, and is neither disabled nor hidden.
|
|
113
|
+
* `isVisible` overrides only the layout (computed-style) part of the check.
|
|
114
|
+
*/
|
|
115
|
+
export function isTabbable(element, isVisible = defaultIsVisible) {
|
|
116
|
+
if (resolvedTabIndex(element) < 0)
|
|
117
|
+
return false;
|
|
118
|
+
if (isDisabled(element))
|
|
119
|
+
return false;
|
|
120
|
+
if (isStructurallyHidden(element))
|
|
121
|
+
return false;
|
|
122
|
+
// An element matched only by `[contenteditable]` with the value "false" isn't focusable.
|
|
123
|
+
const editable = element.getAttribute('contenteditable');
|
|
124
|
+
if (editable === 'false' && !isNativelyFocusable(element) && !element.hasAttribute('tabindex')) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return isVisible(element);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The resolved tab order within `root`: positive-tabindex stops first (ascending,
|
|
131
|
+
* ties in DOM order), then `tabindex=0`/native stops in DOM order — the order a
|
|
132
|
+
* browser actually moves focus. Each stop carries its owning component.
|
|
133
|
+
*/
|
|
134
|
+
export function tabSequence(root = document, options = {}) {
|
|
135
|
+
const isVisible = options.isVisible ?? defaultIsVisible;
|
|
136
|
+
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
137
|
+
const candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => isTabbable(el, isVisible));
|
|
138
|
+
const withMeta = candidates.map((element, domIndex) => ({
|
|
139
|
+
element,
|
|
140
|
+
domIndex,
|
|
141
|
+
tabindex: resolvedTabIndex(element),
|
|
142
|
+
positive: /^\d+$/.test(element.getAttribute('tabindex') ?? '') && resolvedTabIndex(element) > 0,
|
|
143
|
+
}));
|
|
144
|
+
const positives = withMeta
|
|
145
|
+
.filter((m) => m.tabindex > 0)
|
|
146
|
+
.sort((a, b) => a.tabindex - b.tabindex || a.domIndex - b.domIndex);
|
|
147
|
+
const zeros = withMeta.filter((m) => m.tabindex === 0); // already in DOM order
|
|
148
|
+
return [...positives, ...zeros].map((m, i) => {
|
|
149
|
+
const componentPath = resolveComponentPath(m.element);
|
|
150
|
+
return {
|
|
151
|
+
element: m.element,
|
|
152
|
+
order: i + 1,
|
|
153
|
+
tabindex: m.tabindex,
|
|
154
|
+
positive: m.positive,
|
|
155
|
+
component: appComponentFromPath(componentPath, prefixes),
|
|
156
|
+
componentPath,
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Indices (0-based, into the sequence) where the tab path jumps *backward against
|
|
162
|
+
* reading order* — a stop that sits clearly above, or well to the left on the
|
|
163
|
+
* same row, of the stop before it. A heuristic signal that DOM/tabindex order
|
|
164
|
+
* has drifted from the visual order a sighted keyboard user expects; always
|
|
165
|
+
* "verify manually". `getRect` is injectable for tests.
|
|
166
|
+
*/
|
|
167
|
+
export function visualOrderJumps(stops, getRect = (el) => el.getBoundingClientRect(), rowThreshold = 8) {
|
|
168
|
+
const jumps = [];
|
|
169
|
+
for (let i = 1; i < stops.length; i++) {
|
|
170
|
+
const prev = getRect(stops[i - 1].element);
|
|
171
|
+
const curr = getRect(stops[i].element);
|
|
172
|
+
const movedUp = curr.top < prev.top - rowThreshold;
|
|
173
|
+
const sameRowMovedLeft = Math.abs(curr.top - prev.top) <= rowThreshold && curr.left < prev.left - rowThreshold;
|
|
174
|
+
if (movedUp || sameRowMovedLeft)
|
|
175
|
+
jumps.push(i);
|
|
176
|
+
}
|
|
177
|
+
return jumps;
|
|
178
|
+
}
|
package/dist/overlay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { A11yFinding } from './scan.js';
|
|
2
|
+
import type { TabStop } from './keyboard/tab-sequence.js';
|
|
2
3
|
/**
|
|
3
4
|
* Attribute marking the overlay's own DOM. `scan()` excludes anything under it
|
|
4
5
|
* so the tool never reports violations against its own highlights.
|
|
@@ -9,8 +10,15 @@ export declare const OVERLAY_EXCLUDE_SELECTOR = "[data-ngb-a11y-overlay]";
|
|
|
9
10
|
export interface A11yOverlay {
|
|
10
11
|
/** Draw a highlight over each finding's node, replacing the previous set. */
|
|
11
12
|
render(findings: A11yFinding[]): void;
|
|
13
|
+
/**
|
|
14
|
+
* Draw the tab order as numbered badges plus a connector path, on a layer
|
|
15
|
+
* independent of the findings highlights. Replaces the previous tab-order set.
|
|
16
|
+
*/
|
|
17
|
+
renderTabOrder(stops: TabStop[]): void;
|
|
12
18
|
/** Remove all highlights but keep the overlay live. */
|
|
13
19
|
clear(): void;
|
|
20
|
+
/** Remove the tab-order layer but keep the overlay live. */
|
|
21
|
+
clearTabOrder(): void;
|
|
14
22
|
/** Tear down: remove the container and detach scroll/resize listeners. */
|
|
15
23
|
destroy(): void;
|
|
16
24
|
}
|
package/dist/overlay.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
2
|
+
/** Tab-order path + badge colours: normal teal, warning orange for positive tabindex. */
|
|
3
|
+
const TAB_ORDER_COLOR = '#0b8f8f';
|
|
4
|
+
const TAB_ORDER_WARN_COLOR = '#e8710a';
|
|
1
5
|
/**
|
|
2
6
|
* Attribute marking the overlay's own DOM. `scan()` excludes anything under it
|
|
3
7
|
* so the tool never reports violations against its own highlights.
|
|
@@ -35,12 +39,44 @@ export function createOverlay(options = {}) {
|
|
|
35
39
|
zIndex: '2147483646',
|
|
36
40
|
});
|
|
37
41
|
doc.body.appendChild(container);
|
|
42
|
+
// The tab-order connector lives on its own SVG layer under the badges, so the
|
|
43
|
+
// findings highlights and the tab-order path render and clear independently.
|
|
44
|
+
const svg = doc.createElementNS(SVG_NS, 'svg');
|
|
45
|
+
svg.setAttribute(OVERLAY_ATTR, '');
|
|
46
|
+
Object.assign(svg.style, {
|
|
47
|
+
position: 'fixed',
|
|
48
|
+
inset: '0',
|
|
49
|
+
width: '100%',
|
|
50
|
+
height: '100%',
|
|
51
|
+
pointerEvents: 'none',
|
|
52
|
+
overflow: 'visible',
|
|
53
|
+
});
|
|
54
|
+
const connector = doc.createElementNS(SVG_NS, 'polyline');
|
|
55
|
+
connector.setAttribute('fill', 'none');
|
|
56
|
+
connector.setAttribute('stroke', TAB_ORDER_COLOR);
|
|
57
|
+
connector.setAttribute('stroke-width', '2');
|
|
58
|
+
connector.setAttribute('stroke-dasharray', '4 3');
|
|
59
|
+
connector.setAttribute('opacity', '0.7');
|
|
60
|
+
svg.appendChild(connector);
|
|
61
|
+
container.appendChild(svg); // under the badges, which are appended later
|
|
38
62
|
let highlights = [];
|
|
63
|
+
let tabBadges = [];
|
|
39
64
|
const reposition = () => {
|
|
40
65
|
for (const { target, box } of highlights) {
|
|
41
66
|
positionBox(box, target);
|
|
42
67
|
}
|
|
68
|
+
repositionTabOrder();
|
|
43
69
|
};
|
|
70
|
+
function repositionTabOrder() {
|
|
71
|
+
const points = [];
|
|
72
|
+
for (const { target, badge } of tabBadges) {
|
|
73
|
+
const rect = target.getBoundingClientRect();
|
|
74
|
+
badge.style.top = `${rect.top}px`;
|
|
75
|
+
badge.style.left = `${rect.left}px`;
|
|
76
|
+
points.push(`${rect.left + rect.width / 2},${rect.top + rect.height / 2}`);
|
|
77
|
+
}
|
|
78
|
+
connector.setAttribute('points', points.join(' '));
|
|
79
|
+
}
|
|
44
80
|
// rAF-throttle so a stream of scroll events collapses to one layout read.
|
|
45
81
|
const raf = doc.defaultView?.requestAnimationFrame?.bind(doc.defaultView);
|
|
46
82
|
let scheduled = false;
|
|
@@ -78,13 +114,63 @@ export function createOverlay(options = {}) {
|
|
|
78
114
|
highlights.push({ finding, target, box });
|
|
79
115
|
}
|
|
80
116
|
}
|
|
117
|
+
function clearTabOrder() {
|
|
118
|
+
for (const { badge } of tabBadges)
|
|
119
|
+
badge.remove();
|
|
120
|
+
tabBadges = [];
|
|
121
|
+
connector.setAttribute('points', '');
|
|
122
|
+
}
|
|
123
|
+
function renderTabOrder(stops) {
|
|
124
|
+
clearTabOrder();
|
|
125
|
+
for (const stop of stops) {
|
|
126
|
+
const target = stop.element;
|
|
127
|
+
if (!target.isConnected)
|
|
128
|
+
continue; // node gone since the sequence was computed
|
|
129
|
+
const badge = buildBadge(doc, stop);
|
|
130
|
+
container.appendChild(badge);
|
|
131
|
+
tabBadges.push({ stop, target, badge });
|
|
132
|
+
}
|
|
133
|
+
repositionTabOrder();
|
|
134
|
+
}
|
|
81
135
|
function destroy() {
|
|
82
136
|
clear();
|
|
137
|
+
clearTabOrder();
|
|
83
138
|
win?.removeEventListener('scroll', onViewportChange, { capture: true });
|
|
84
139
|
win?.removeEventListener('resize', onViewportChange);
|
|
85
140
|
container.remove();
|
|
86
141
|
}
|
|
87
|
-
return { render, clear, destroy };
|
|
142
|
+
return { render, renderTabOrder, clear, clearTabOrder, destroy };
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A numbered badge marking one tab stop, anchored at the target's top-left
|
|
146
|
+
* corner. A positive-tabindex stop is coloured as a warning, since an explicit
|
|
147
|
+
* positive tabindex hijacks the natural order.
|
|
148
|
+
*/
|
|
149
|
+
function buildBadge(doc, stop) {
|
|
150
|
+
const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
|
|
151
|
+
const badge = doc.createElement('div');
|
|
152
|
+
badge.setAttribute('data-ngb-tab-order', String(stop.order));
|
|
153
|
+
const owner = stop.component ? ` · ${stop.component}` : '';
|
|
154
|
+
const ti = stop.positive ? ` · tabindex=${stop.tabindex} (hijacks order)` : '';
|
|
155
|
+
badge.title = `Tab stop ${stop.order}${owner}${ti}`;
|
|
156
|
+
badge.textContent = String(stop.order);
|
|
157
|
+
Object.assign(badge.style, {
|
|
158
|
+
position: 'fixed',
|
|
159
|
+
transform: 'translate(-50%, -50%)',
|
|
160
|
+
minWidth: '16px',
|
|
161
|
+
height: '16px',
|
|
162
|
+
padding: '0 3px',
|
|
163
|
+
boxSizing: 'border-box',
|
|
164
|
+
borderRadius: '8px',
|
|
165
|
+
font: '10px/16px ui-monospace, monospace',
|
|
166
|
+
fontWeight: '700',
|
|
167
|
+
textAlign: 'center',
|
|
168
|
+
color: '#fff',
|
|
169
|
+
background: color,
|
|
170
|
+
border: '1px solid rgba(255,255,255,0.85)',
|
|
171
|
+
pointerEvents: 'none',
|
|
172
|
+
});
|
|
173
|
+
return badge;
|
|
88
174
|
}
|
|
89
175
|
/** Resolve a finding's target selector to a node, tolerating a bad selector. */
|
|
90
176
|
function resolveTarget(doc, target) {
|
package/dist/provider.d.ts
CHANGED
|
@@ -19,6 +19,21 @@ export interface A11yDevtoolsOptions {
|
|
|
19
19
|
* axe run options.)
|
|
20
20
|
*/
|
|
21
21
|
tags?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Component-name prefixes treated as third-party UI primitives to walk past
|
|
24
|
+
* during attribution. Defaults to `Nb`/`Mat`/`Cdk`/`Mdc`. Add others (e.g.
|
|
25
|
+
* `Nz`/`Clr`/`Ion`) or pass `[]` to attribute to the immediate owner — useful
|
|
26
|
+
* when auditing a component library's own code.
|
|
27
|
+
*/
|
|
28
|
+
frameworkPrefixes?: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Turn on the **keyboard layer** — the ~2/3 of accessibility axe can't test.
|
|
31
|
+
* Adds heuristic `ngbr/*` findings (keyboard-unreachable controls,
|
|
32
|
+
* click-without-keyboard handlers, tab-order mismatches) to the report, and,
|
|
33
|
+
* when `overlay` is on, draws the numbered tab-order path over the page.
|
|
34
|
+
* Default false.
|
|
35
|
+
*/
|
|
36
|
+
keyboard?: boolean;
|
|
22
37
|
}
|
|
23
38
|
/**
|
|
24
39
|
* Dev-only in-app accessibility auditing. Rescans whenever the application
|
package/dist/provider.js
CHANGED
|
@@ -2,6 +2,7 @@ import { ApplicationRef, DestroyRef, inject, isDevMode, makeEnvironmentProviders
|
|
|
2
2
|
import { debounceTime, filter } from 'rxjs';
|
|
3
3
|
import { runA11yScan } from './runner.js';
|
|
4
4
|
import { createOverlay } from './overlay.js';
|
|
5
|
+
import { tabSequence } from './keyboard/tab-sequence.js';
|
|
5
6
|
/**
|
|
6
7
|
* Dev-only in-app accessibility auditing. Rescans whenever the application
|
|
7
8
|
* settles (zoneless-aware, via `ApplicationRef.isStable`) and reports each
|
|
@@ -15,7 +16,7 @@ export function provideA11yDevtools(options = {}) {
|
|
|
15
16
|
if (!isDevMode()) {
|
|
16
17
|
return makeEnvironmentProviders([]);
|
|
17
18
|
}
|
|
18
|
-
const { root, log = true, logger, overlay = false, debounceMs = 500, tags } = options;
|
|
19
|
+
const { root, log = true, logger, overlay = false, debounceMs = 500, tags, frameworkPrefixes, keyboard = false, } = options;
|
|
19
20
|
const axe = tags
|
|
20
21
|
? { runOnly: { type: 'tag', values: tags } }
|
|
21
22
|
: undefined;
|
|
@@ -31,8 +32,15 @@ export function provideA11yDevtools(options = {}) {
|
|
|
31
32
|
if (scanning)
|
|
32
33
|
return; // don't stack rescans while one is in flight
|
|
33
34
|
scanning = true;
|
|
34
|
-
runA11yScan(root?.(), { log, logger, axe })
|
|
35
|
-
.then((findings) =>
|
|
35
|
+
runA11yScan(root?.(), { log, logger, axe, frameworkPrefixes, keyboard })
|
|
36
|
+
.then((findings) => {
|
|
37
|
+
overlayView?.render(findings);
|
|
38
|
+
// Draw the tab-order path as its own overlay layer (independent of
|
|
39
|
+
// the findings highlights) when the keyboard layer is on.
|
|
40
|
+
if (overlayView && keyboard) {
|
|
41
|
+
overlayView.renderTabOrder(tabSequence(root?.() ?? document, { frameworkPrefixes }));
|
|
42
|
+
}
|
|
43
|
+
})
|
|
36
44
|
.catch(() => undefined)
|
|
37
45
|
.finally(() => {
|
|
38
46
|
scanning = false;
|
|
@@ -19,6 +19,20 @@ export interface ScanPagesOptions {
|
|
|
19
19
|
setup?: (page: Page) => Promise<void>;
|
|
20
20
|
/** Launch a headed browser (for debugging). Default false (headless). */
|
|
21
21
|
headed?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Component-name prefixes treated as third-party UI primitives to walk past
|
|
24
|
+
* during attribution. Defaults to `Nb`/`Mat`/`Cdk`/`Mdc`; pass `[]` to
|
|
25
|
+
* attribute to the immediate owner — useful when scanning a component
|
|
26
|
+
* library's own code (so it blames the library component, not a demo wrapper).
|
|
27
|
+
*/
|
|
28
|
+
frameworkPrefixes?: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Also run the keyboard layer in-page — heuristic `ngbr/*` findings for
|
|
31
|
+
* keyboard-unreachable controls, click-without-keyboard handlers, and
|
|
32
|
+
* tab-order mismatches (the last needs real layout, which headless has).
|
|
33
|
+
* Default false.
|
|
34
|
+
*/
|
|
35
|
+
keyboard?: boolean;
|
|
22
36
|
}
|
|
23
37
|
/**
|
|
24
38
|
* Drive a real headless browser over a running Angular **dev** build and return
|
package/dist/report/headless.js
CHANGED
|
@@ -21,7 +21,7 @@ function inPageScriptPath() {
|
|
|
21
21
|
* to the component that rendered it — with no change to the target app.
|
|
22
22
|
*/
|
|
23
23
|
export async function scanPages(options) {
|
|
24
|
-
const { baseUrl, routes, tags, waitMs = 1500, labels = {}, setup, headed = false } = options;
|
|
24
|
+
const { baseUrl, routes, tags, waitMs = 1500, labels = {}, setup, headed = false, frameworkPrefixes, keyboard, } = options;
|
|
25
25
|
const axeOptions = tags
|
|
26
26
|
? { runOnly: { type: 'tag', values: tags } }
|
|
27
27
|
: undefined;
|
|
@@ -45,10 +45,10 @@ export async function scanPages(options) {
|
|
|
45
45
|
await page.goto(url, { waitUntil: 'networkidle' }).catch(() => page.goto(url));
|
|
46
46
|
await page.waitForTimeout(waitMs);
|
|
47
47
|
await page.addScriptTag({ content: inPageScript });
|
|
48
|
-
const findings = (await page.evaluate((
|
|
48
|
+
const findings = (await page.evaluate((args) => {
|
|
49
49
|
const w = window;
|
|
50
|
-
return w.__ngbA11yScan(
|
|
51
|
-
}, axeOptions));
|
|
50
|
+
return w.__ngbA11yScan(args.axe, args.scan);
|
|
51
|
+
}, { axe: axeOptions, scan: { frameworkPrefixes, keyboard } }));
|
|
52
52
|
pages.push({ label, url: page.url(), findings });
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
package/dist/runner.d.ts
CHANGED
|
@@ -14,6 +14,18 @@ export interface RunOptions {
|
|
|
14
14
|
* as a friendlier `tags: string[]`.)
|
|
15
15
|
*/
|
|
16
16
|
axe?: AxeRunOptions;
|
|
17
|
+
/**
|
|
18
|
+
* Component-name prefixes treated as third-party UI primitives to walk past
|
|
19
|
+
* during attribution. Defaults to `Nb`/`Mat`/`Cdk`/`Mdc`; pass `[]` to
|
|
20
|
+
* attribute to the immediate owner (e.g. when scanning a library's own code).
|
|
21
|
+
*/
|
|
22
|
+
frameworkPrefixes?: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Also run the keyboard layer — heuristic `ngbr/*` findings for
|
|
25
|
+
* keyboard-unreachable controls, click-without-keyboard handlers, and
|
|
26
|
+
* tab-order mismatches. Default false.
|
|
27
|
+
*/
|
|
28
|
+
keyboard?: boolean;
|
|
17
29
|
}
|
|
18
30
|
/** Scan `root`, optionally report, and return the findings. */
|
|
19
31
|
export declare function runA11yScan(root?: Element | Document, options?: RunOptions): Promise<A11yFinding[]>;
|
package/dist/runner.js
CHANGED
|
@@ -2,7 +2,10 @@ import { scan } from './scan.js';
|
|
|
2
2
|
import { logFindings } from './report.js';
|
|
3
3
|
/** Scan `root`, optionally report, and return the findings. */
|
|
4
4
|
export async function runA11yScan(root, options = {}) {
|
|
5
|
-
const findings = await scan(root ?? document, options.axe
|
|
5
|
+
const findings = await scan(root ?? document, options.axe, {
|
|
6
|
+
frameworkPrefixes: options.frameworkPrefixes,
|
|
7
|
+
keyboard: options.keyboard,
|
|
8
|
+
});
|
|
6
9
|
if (options.log !== false) {
|
|
7
10
|
logFindings(findings, options.logger);
|
|
8
11
|
}
|
package/dist/scan.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { RunOptions } from 'axe-core';
|
|
2
2
|
export type Impact = 'minor' | 'moderate' | 'serious' | 'critical' | null;
|
|
3
|
+
/** Attribution options for a scan (separate from axe's own run options). */
|
|
4
|
+
export interface ScanOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Component-name prefixes treated as third-party UI primitives to walk past
|
|
7
|
+
* during attribution. Defaults to {@link DEFAULT_FRAMEWORK_PREFIXES}
|
|
8
|
+
* (`Nb`/`Mat`/`Cdk`/`Mdc`). Pass `[]` to disable walking and attribute to the
|
|
9
|
+
* immediate owner — useful when scanning a component library's own code.
|
|
10
|
+
*/
|
|
11
|
+
frameworkPrefixes?: readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* Also run the keyboard layer (part B): heuristic, `window.ng`-driven checks
|
|
14
|
+
* axe can't do — keyboard-unreachable interactive controls, click handlers
|
|
15
|
+
* with no keyboard handler, and visual-vs-tab-order mismatches. Emitted as
|
|
16
|
+
* `ngbr/*` findings alongside the axe violations. Default false.
|
|
17
|
+
*/
|
|
18
|
+
keyboard?: boolean;
|
|
19
|
+
}
|
|
3
20
|
/** One axe violation node, enriched with the component that rendered it. */
|
|
4
21
|
export interface A11yFinding {
|
|
5
22
|
/** axe rule id, e.g. `image-alt`. */
|
|
@@ -23,4 +40,4 @@ export interface A11yFinding {
|
|
|
23
40
|
* main bundle (the provider also no-ops outside dev mode). Concurrent calls are
|
|
24
41
|
* serialized because axe cannot run more than once at a time.
|
|
25
42
|
*/
|
|
26
|
-
export declare function scan(root?: Element | Document, options?: RunOptions): Promise<A11yFinding[]>;
|
|
43
|
+
export declare function scan(root?: Element | Document, options?: RunOptions, scanOptions?: ScanOptions): Promise<A11yFinding[]>;
|
package/dist/scan.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { appComponentFromPath, resolveComponentPath, resolveDirectiveNames } from './attribution.js';
|
|
1
|
+
import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, } from './attribution.js';
|
|
2
2
|
import { OVERLAY_EXCLUDE_SELECTOR } from './overlay.js';
|
|
3
|
+
import { scanKeyboard } from './keyboard/keyboard-scan.js';
|
|
3
4
|
// axe-core is a singleton and throws if a run starts while another is in flight.
|
|
4
5
|
// Chain runs so overlapping callers (e.g. rapid rescans) serialize safely.
|
|
5
6
|
let runChain = Promise.resolve();
|
|
@@ -9,13 +10,14 @@ let runChain = Promise.resolve();
|
|
|
9
10
|
* main bundle (the provider also no-ops outside dev mode). Concurrent calls are
|
|
10
11
|
* serialized because axe cannot run more than once at a time.
|
|
11
12
|
*/
|
|
12
|
-
export function scan(root = document, options) {
|
|
13
|
-
const result = runChain.then(() => runAxeOnce(root, options));
|
|
13
|
+
export function scan(root = document, options, scanOptions) {
|
|
14
|
+
const result = runChain.then(() => runAxeOnce(root, options, scanOptions));
|
|
14
15
|
runChain = result.catch(() => undefined);
|
|
15
16
|
return result;
|
|
16
17
|
}
|
|
17
|
-
async function runAxeOnce(root, options) {
|
|
18
|
+
async function runAxeOnce(root, options, scanOptions) {
|
|
18
19
|
const axe = (await import('axe-core')).default;
|
|
20
|
+
const frameworkPrefixes = scanOptions?.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
19
21
|
// Scan within `root` but never flag the overlay's own highlights.
|
|
20
22
|
const context = { include: root, exclude: [OVERLAY_EXCLUDE_SELECTOR] };
|
|
21
23
|
const results = await axe.run(context, options ?? {});
|
|
@@ -37,7 +39,7 @@ async function runAxeOnce(root, options) {
|
|
|
37
39
|
impact: (violation.impact ?? null),
|
|
38
40
|
help: violation.help,
|
|
39
41
|
helpUrl: violation.helpUrl,
|
|
40
|
-
component: appComponentFromPath(componentPath),
|
|
42
|
+
component: appComponentFromPath(componentPath, frameworkPrefixes),
|
|
41
43
|
componentPath,
|
|
42
44
|
directives: element ? resolveDirectiveNames(element) : [],
|
|
43
45
|
target,
|
|
@@ -45,5 +47,10 @@ async function runAxeOnce(root, options) {
|
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
// The keyboard layer runs over the same root, in the page, and appends its own
|
|
51
|
+
// `ngbr/*` findings so they group and report exactly like the axe ones.
|
|
52
|
+
if (scanOptions?.keyboard) {
|
|
53
|
+
findings.push(...scanKeyboard(root, { frameworkPrefixes }));
|
|
54
|
+
}
|
|
48
55
|
return findings;
|
|
49
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|