@histoire/plugin-a11y 0.0.0-stage → 1.0.0-beta.2
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/LICENSE +21 -0
- package/NOTICE +433 -0
- package/README.md +97 -2
- package/dist/build/scan.d.ts +11 -0
- package/dist/build/scan.js +85 -0
- package/dist/chunks/_histoire-a11y-axe-BL07tEuN.js +53627 -0
- package/dist/chunks/messages-KjPUArEa.js +12 -0
- package/dist/chunks/results-C0vYpcmy.js +41 -0
- package/dist/chunks/run-lct8FHuk.js +134 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +1368 -0
- package/dist/frame/highlight.d.ts +6 -0
- package/dist/frame.d.ts +2 -0
- package/dist/frame.js +211 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +44 -0
- package/dist/messages.d.ts +43 -0
- package/dist/messages.js +11 -0
- package/dist/options.d.ts +41 -0
- package/dist/options.js +22 -0
- package/dist/results.d.ts +6 -0
- package/dist/results.js +6 -0
- package/dist/scanner/policy.d.ts +11 -0
- package/dist/scanner/run.d.ts +24 -0
- package/dist/test.d.ts +13 -0
- package/dist/test.js +25 -0
- package/dist/workbench/AuditPanel.vue.d.ts +11 -0
- package/dist/workbench/FindingRow.vue.d.ts +15 -0
- package/dist/workbench/ProjectPanel.vue.d.ts +16 -0
- package/dist/workbench/VariantGroup.vue.d.ts +17 -0
- package/dist/workbench/filters.d.ts +26 -0
- package/dist/workbench/fix-summary.d.ts +33 -0
- package/dist/workbench/locate.d.ts +26 -0
- package/dist/workbench/model.d.ts +42 -0
- package/dist/workbench/project-model.d.ts +66 -0
- package/dist/workbench/project-source.d.ts +51 -0
- package/dist/workbench/sources.d.ts +40 -0
- package/dist/workbench/sources.js +62 -0
- package/package.json +170 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Temporary background overlay; story element styles and focus stay untouched. */
|
|
2
|
+
export declare function createHighlighter(root: HTMLElement, signal: AbortSignal): {
|
|
3
|
+
clear: () => void;
|
|
4
|
+
/** Show exact retained element; stale or foreign references are rejected. */
|
|
5
|
+
show(element: Element | undefined): boolean;
|
|
6
|
+
};
|
package/dist/frame.d.ts
ADDED
package/dist/frame.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { n as runAudit, r as normalizeOptions } from "./chunks/run-lct8FHuk.js";
|
|
2
|
+
import { n as send, t as command } from "./chunks/messages-KjPUArEa.js";
|
|
3
|
+
import { defineFramePlugin } from "@histoire/plugin-kit/frame";
|
|
4
|
+
// src/frame/highlight.ts
|
|
5
|
+
/** Temporary background overlay; story element styles and focus stay untouched. */
|
|
6
|
+
function createHighlighter(root, signal) {
|
|
7
|
+
let overlay;
|
|
8
|
+
let target;
|
|
9
|
+
let timer;
|
|
10
|
+
const document = root.ownerDocument;
|
|
11
|
+
const window = document.defaultView;
|
|
12
|
+
/** Drop previous target and every owned resource. */
|
|
13
|
+
function clear() {
|
|
14
|
+
clearTimeout(timer);
|
|
15
|
+
overlay?.remove();
|
|
16
|
+
overlay = void 0;
|
|
17
|
+
target = void 0;
|
|
18
|
+
window.removeEventListener("scroll", position, true);
|
|
19
|
+
window.removeEventListener("resize", position);
|
|
20
|
+
}
|
|
21
|
+
/** Follow current element without affecting document flow or hit testing. */
|
|
22
|
+
function position() {
|
|
23
|
+
if (!overlay || !target) return;
|
|
24
|
+
if (!target.isConnected || !root.contains(target)) return clear();
|
|
25
|
+
const rect = target.getBoundingClientRect();
|
|
26
|
+
Object.assign(overlay.style, {
|
|
27
|
+
left: `${rect.left}px`,
|
|
28
|
+
top: `${rect.top}px`,
|
|
29
|
+
width: `${rect.width}px`,
|
|
30
|
+
height: `${rect.height}px`
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
signal.addEventListener("abort", clear, { once: true });
|
|
34
|
+
return {
|
|
35
|
+
clear,
|
|
36
|
+
/** Show exact retained element; stale or foreign references are rejected. */
|
|
37
|
+
show(element) {
|
|
38
|
+
clear();
|
|
39
|
+
if (signal.aborted || !element?.isConnected || !root.contains(element)) return false;
|
|
40
|
+
target = element;
|
|
41
|
+
element.scrollIntoView({
|
|
42
|
+
block: "nearest",
|
|
43
|
+
inline: "nearest",
|
|
44
|
+
behavior: "instant"
|
|
45
|
+
});
|
|
46
|
+
overlay = document.createElement("div");
|
|
47
|
+
overlay.dataset.histoireA11yHighlight = "";
|
|
48
|
+
overlay.setAttribute("aria-hidden", "true");
|
|
49
|
+
Object.assign(overlay.style, {
|
|
50
|
+
position: "fixed",
|
|
51
|
+
pointerEvents: "none",
|
|
52
|
+
zIndex: "2147483647",
|
|
53
|
+
background: "rgba(99, 102, 241, 0.18)",
|
|
54
|
+
borderRadius: "4px"
|
|
55
|
+
});
|
|
56
|
+
document.body.append(overlay);
|
|
57
|
+
position();
|
|
58
|
+
window.addEventListener("scroll", position, true);
|
|
59
|
+
window.addEventListener("resize", position);
|
|
60
|
+
timer = setTimeout(clear, 1600);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// src/frame.ts
|
|
66
|
+
/** Own observation and serialized scans for exactly one rendered actor. */
|
|
67
|
+
function attach(frame) {
|
|
68
|
+
const options = normalizeOptions(frame.options);
|
|
69
|
+
const highlight = createHighlighter(frame.element, frame.signal);
|
|
70
|
+
let visit;
|
|
71
|
+
let autoRun = false;
|
|
72
|
+
let request = 0;
|
|
73
|
+
let reportId = 0;
|
|
74
|
+
let elements = /* @__PURE__ */ new Map();
|
|
75
|
+
let timer;
|
|
76
|
+
let controller;
|
|
77
|
+
let busy = false;
|
|
78
|
+
let pending = false;
|
|
79
|
+
let staleNotified = true;
|
|
80
|
+
let stopState;
|
|
81
|
+
/** Send only while current inspector visit owns actor. */
|
|
82
|
+
function update(data) {
|
|
83
|
+
if (visit && !frame.signal.aborted) send(frame.channel, "update", {
|
|
84
|
+
visit,
|
|
85
|
+
request,
|
|
86
|
+
...data
|
|
87
|
+
}).catch(() => {});
|
|
88
|
+
}
|
|
89
|
+
/** Run at most one scan, retaining admission after cancellation until raw axe settles. */
|
|
90
|
+
async function run() {
|
|
91
|
+
if (!visit || frame.signal.aborted) return;
|
|
92
|
+
if (busy) {
|
|
93
|
+
pending = true;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
pending = false;
|
|
98
|
+
busy = true;
|
|
99
|
+
const owner = visit;
|
|
100
|
+
const sequence = ++request;
|
|
101
|
+
controller = new AbortController();
|
|
102
|
+
const signal = controller.signal;
|
|
103
|
+
highlight.clear();
|
|
104
|
+
staleNotified = true;
|
|
105
|
+
update({
|
|
106
|
+
running: true,
|
|
107
|
+
stale: true
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
const result = await runAudit(frame.element, options, signal);
|
|
111
|
+
if (visit !== owner || signal.aborted || frame.signal.aborted || sequence !== request) return;
|
|
112
|
+
elements = pending ? /* @__PURE__ */ new Map() : result.elements;
|
|
113
|
+
staleNotified = pending;
|
|
114
|
+
reportId = sequence;
|
|
115
|
+
update({
|
|
116
|
+
running: false,
|
|
117
|
+
stale: pending,
|
|
118
|
+
reportId,
|
|
119
|
+
report: result.report
|
|
120
|
+
});
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (visit === owner && !signal.aborted && !frame.signal.aborted) update({
|
|
123
|
+
running: false,
|
|
124
|
+
stale: true,
|
|
125
|
+
error: error instanceof Error ? error.message : String(error)
|
|
126
|
+
});
|
|
127
|
+
} finally {
|
|
128
|
+
busy = false;
|
|
129
|
+
if (pending && visit) schedule();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Coalesce state/DOM changes and invalidate element handles immediately. */
|
|
133
|
+
function schedule() {
|
|
134
|
+
if (!visit) return;
|
|
135
|
+
elements.clear();
|
|
136
|
+
highlight.clear();
|
|
137
|
+
if (!staleNotified) update({ stale: true });
|
|
138
|
+
staleNotified = true;
|
|
139
|
+
if (!autoRun) return;
|
|
140
|
+
if (busy) pending = true;
|
|
141
|
+
clearTimeout(timer);
|
|
142
|
+
timer = setTimeout(() => void run(), 300);
|
|
143
|
+
}
|
|
144
|
+
const observer = new MutationObserver(schedule);
|
|
145
|
+
/** Stop automatic work; leave non-abortable engine owned by shared admission. */
|
|
146
|
+
function deactivate() {
|
|
147
|
+
visit = void 0;
|
|
148
|
+
autoRun = false;
|
|
149
|
+
pending = false;
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
controller?.abort();
|
|
152
|
+
observer.disconnect();
|
|
153
|
+
stopState?.();
|
|
154
|
+
stopState = void 0;
|
|
155
|
+
elements.clear();
|
|
156
|
+
highlight.clear();
|
|
157
|
+
}
|
|
158
|
+
/** Enable observation only while active tab requests live auditing. */
|
|
159
|
+
function observe() {
|
|
160
|
+
observer.disconnect();
|
|
161
|
+
stopState?.();
|
|
162
|
+
stopState = void 0;
|
|
163
|
+
if (visit) {
|
|
164
|
+
observer.observe(frame.element, {
|
|
165
|
+
subtree: true,
|
|
166
|
+
childList: true,
|
|
167
|
+
attributes: true,
|
|
168
|
+
characterData: true
|
|
169
|
+
});
|
|
170
|
+
stopState = frame.state.subscribe(schedule);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
frame.onCleanup(frame.channel.on("activate", (value) => {
|
|
174
|
+
const data = command(value);
|
|
175
|
+
if (!data) return;
|
|
176
|
+
deactivate();
|
|
177
|
+
visit = data.visit;
|
|
178
|
+
autoRun = data.autoRun === true;
|
|
179
|
+
observe();
|
|
180
|
+
if (autoRun) run();
|
|
181
|
+
}));
|
|
182
|
+
frame.onCleanup(frame.channel.on("stop", (value) => {
|
|
183
|
+
if (command(value)?.visit === visit) deactivate();
|
|
184
|
+
}));
|
|
185
|
+
frame.onCleanup(frame.channel.on("run", (value) => {
|
|
186
|
+
if (command(value)?.visit === visit) run();
|
|
187
|
+
}));
|
|
188
|
+
frame.onCleanup(frame.channel.on("configure", (value) => {
|
|
189
|
+
const data = command(value);
|
|
190
|
+
if (!data || data.visit !== visit) return;
|
|
191
|
+
autoRun = data.autoRun === true;
|
|
192
|
+
observe();
|
|
193
|
+
if (autoRun) run();
|
|
194
|
+
else {
|
|
195
|
+
clearTimeout(timer);
|
|
196
|
+
pending = false;
|
|
197
|
+
}
|
|
198
|
+
}));
|
|
199
|
+
frame.onCleanup(frame.channel.on("highlight", (value) => {
|
|
200
|
+
const data = command(value);
|
|
201
|
+
if (!data || data.visit !== visit) return;
|
|
202
|
+
update({ feedback: data.reportId === reportId && typeof data.node === "string" && highlight.show(elements.get(data.node)) ? "Element highlighted" : "Element changed; run checks again" });
|
|
203
|
+
}));
|
|
204
|
+
frame.onCleanup(deactivate);
|
|
205
|
+
}
|
|
206
|
+
var frame_default = defineFramePlugin({
|
|
207
|
+
id: "a11y",
|
|
208
|
+
apiVersion: 1,
|
|
209
|
+
attach
|
|
210
|
+
});
|
|
211
|
+
export { frame_default as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Plugin } from '@histoire/shared';
|
|
2
|
+
import type { A11yOptions } from './options.js';
|
|
3
|
+
export type { A11yImpact, A11yOptions, A11yScanOptions, A11yTestOptions } from './options.js';
|
|
4
|
+
/** Install axe-core audits in inspector and optional fresh-mount story tests. */
|
|
5
|
+
export declare function HstA11y(options?: A11yOptions): Plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { normalizeOptions } from './options.js';
|
|
3
|
+
/** Install axe-core audits in inspector and optional fresh-mount story tests. */
|
|
4
|
+
export function HstA11y(options = {}) {
|
|
5
|
+
const browser = normalizeOptions(options);
|
|
6
|
+
return {
|
|
7
|
+
name: '@histoire/plugin-a11y',
|
|
8
|
+
metadata: { displayName: 'Accessibility', description: 'Accessibility audits with axe-core', icon: 'list-checked', docsUrl: 'https://histoire.dev/guide/plugins/a11y.html', repoUrl: 'https://github.com/histoire-dev/histoire/tree/main/packages/histoire-plugin-a11y' },
|
|
9
|
+
workbench: options.enabled === false
|
|
10
|
+
? undefined
|
|
11
|
+
: {
|
|
12
|
+
id: 'a11y',
|
|
13
|
+
apiVersion: 1,
|
|
14
|
+
client: fileURLToPath(new URL('./client.js', import.meta.url)),
|
|
15
|
+
frame: fileURLToPath(new URL('./frame.js', import.meta.url)),
|
|
16
|
+
// `tests`/`report` tell the workbench which project-wide source exists.
|
|
17
|
+
options: { ...browser, tests: !!options.test, report: !!options.build },
|
|
18
|
+
devOnly: options.devOnly ?? false,
|
|
19
|
+
},
|
|
20
|
+
async onBuild(api) {
|
|
21
|
+
// Static books without the UI have no pane to read the report.
|
|
22
|
+
if (!options.build || options.enabled === false || options.devOnly)
|
|
23
|
+
return;
|
|
24
|
+
const { createBuildScanner } = await import('./build/scan.js');
|
|
25
|
+
const scanner = createBuildScanner(browser);
|
|
26
|
+
api.onPreviewStory(scanner.scan);
|
|
27
|
+
api.onBuildEnd(() => scanner.write(api.outputDir));
|
|
28
|
+
},
|
|
29
|
+
/** Serve the already-built ESM test hook directly when generated setup first imports it. */
|
|
30
|
+
viteConfig(_config, { browserRuntime }) {
|
|
31
|
+
if (browserRuntime && options.enabled !== false && options.test) {
|
|
32
|
+
return { optimizeDeps: { exclude: ['@histoire/plugin-a11y/test'] } };
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
config(config, mode) {
|
|
36
|
+
if (mode === 'build' || options.enabled === false || !options.test)
|
|
37
|
+
return;
|
|
38
|
+
const names = new Set(['setupVanilla', ...config.plugins.flatMap(plugin => plugin.supportPlugin?.setupFn ?? [])]);
|
|
39
|
+
const settings = { ...browser, ...(typeof options.test === 'object' ? options.test : {}) };
|
|
40
|
+
const code = `import { registerA11yTests } from '@histoire/plugin-a11y/test'\n${[...names].map(name => `export function ${name}() { registerA11yTests(${JSON.stringify(settings)}) }`).join('\n')}`;
|
|
41
|
+
config.setupCode = [...config.setupCode ?? [], code];
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PluginChannel } from '@histoire/plugin-kit';
|
|
2
|
+
import type { normalizeAccessibility } from '@histoire/shared/accessibility';
|
|
3
|
+
/** Bounded UI report; raw axe nodes never cross channel. */
|
|
4
|
+
export type AuditReport = ReturnType<typeof normalizeAccessibility> & {
|
|
5
|
+
/** Total violating rules before display bounds. */
|
|
6
|
+
violationsCount: number;
|
|
7
|
+
/** Total rules needing review before display bounds. */
|
|
8
|
+
incompleteCount: number;
|
|
9
|
+
};
|
|
10
|
+
/** Frame control message scoped to one mounted inspector visit. */
|
|
11
|
+
export interface AuditCommand {
|
|
12
|
+
/** Inspector visit identity. */
|
|
13
|
+
visit: string;
|
|
14
|
+
/** Whether live changes trigger scans. */
|
|
15
|
+
autoRun?: boolean;
|
|
16
|
+
/** Report owning highlight target. */
|
|
17
|
+
reportId?: number;
|
|
18
|
+
/** Opaque node key, resolved only from frame-owned references. */
|
|
19
|
+
node?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Correlated frame status. */
|
|
22
|
+
export interface AuditUpdate {
|
|
23
|
+
/** Inspector visit identity. */
|
|
24
|
+
visit: string;
|
|
25
|
+
/** Scan sequence within actor. */
|
|
26
|
+
request: number;
|
|
27
|
+
/** Successful report identity. */
|
|
28
|
+
reportId?: number;
|
|
29
|
+
/** Latest bounded result. */
|
|
30
|
+
report?: AuditReport;
|
|
31
|
+
/** Pending scan. */
|
|
32
|
+
running?: boolean;
|
|
33
|
+
/** Prior result no longer reflects current DOM. */
|
|
34
|
+
stale?: boolean;
|
|
35
|
+
/** Actionable failure. */
|
|
36
|
+
error?: string;
|
|
37
|
+
/** Compact highlight feedback. */
|
|
38
|
+
feedback?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Post owned JSON DTO through bounded plugin transport. */
|
|
41
|
+
export declare function send(channel: PluginChannel, type: string, data: AuditCommand | AuditUpdate): Promise<void>;
|
|
42
|
+
/** Read command shape without trusting arbitrary host messages. */
|
|
43
|
+
export declare function command(value: unknown): AuditCommand | undefined;
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Post owned JSON DTO through bounded plugin transport. */
|
|
2
|
+
export function send(channel, type, data) {
|
|
3
|
+
return channel.post(type, data);
|
|
4
|
+
}
|
|
5
|
+
/** Read command shape without trusting arbitrary host messages. */
|
|
6
|
+
export function command(value) {
|
|
7
|
+
if (!value || typeof value !== 'object')
|
|
8
|
+
return;
|
|
9
|
+
const data = value;
|
|
10
|
+
return typeof data.visit === 'string' && data.visit.length > 0 && data.visit.length < 128 ? data : undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RunOptions } from 'axe-core';
|
|
2
|
+
/** Axe severity ordered from lowest to highest. */
|
|
3
|
+
export type A11yImpact = 'minor' | 'moderate' | 'serious' | 'critical';
|
|
4
|
+
/** Configurable scan settings shared by UI and assertions. */
|
|
5
|
+
export interface A11yScanOptions {
|
|
6
|
+
/** Axe rule selection and enabled overrides; defaults to axe defaults. */
|
|
7
|
+
axe?: Pick<RunOptions, 'runOnly' | 'rules'>;
|
|
8
|
+
/** Selectors excluded within variant root; defaults to none. */
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
/** Scan deadline in milliseconds, 1–30000; defaults to 10000. */
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Options of automatic tests and explicit assertions. */
|
|
14
|
+
export interface A11yTestOptions extends A11yScanOptions {
|
|
15
|
+
/** Lowest failing impact; omitted means every violation fails. Unknown impact always fails. */
|
|
16
|
+
minimumImpact?: A11yImpact;
|
|
17
|
+
}
|
|
18
|
+
/** Configuration of HstA11y. */
|
|
19
|
+
export interface A11yOptions extends A11yScanOptions {
|
|
20
|
+
/** Enable UI and automatic tests; defaults to true. */
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
/** Exclude UI and scanner from static books; defaults to false. */
|
|
23
|
+
devOnly?: boolean;
|
|
24
|
+
/** Initial user preference for live checks while tab open; defaults to true. */
|
|
25
|
+
autoRun?: boolean;
|
|
26
|
+
/** Register fresh-mount tests per variant; defaults to false. Feeds the Accessibility pane on the dev server. */
|
|
27
|
+
test?: boolean | Pick<A11yTestOptions, 'minimumImpact'>;
|
|
28
|
+
/** Check every variant during `histoire build` and embed the report into the book's Accessibility pane; needs Playwright. Defaults to false. */
|
|
29
|
+
build?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Serializable settings shared with workbench and frame modules. */
|
|
32
|
+
export interface BrowserOptions extends A11yScanOptions {
|
|
33
|
+
/** Initial user preference. */
|
|
34
|
+
autoRun: boolean;
|
|
35
|
+
/** Scoped excluded selectors. */
|
|
36
|
+
exclude: string[];
|
|
37
|
+
/** Bounded scan deadline. */
|
|
38
|
+
timeoutMs: number;
|
|
39
|
+
}
|
|
40
|
+
/** Validate public settings before generating browser configuration. */
|
|
41
|
+
export declare function normalizeOptions(options?: A11yOptions): BrowserOptions;
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { measureWireValue } from '@histoire/protocol';
|
|
2
|
+
/** Validate public settings before generating browser configuration. */
|
|
3
|
+
export function normalizeOptions(options = {}) {
|
|
4
|
+
for (const key of ['enabled', 'devOnly', 'autoRun', 'build']) {
|
|
5
|
+
if (options[key] !== undefined && typeof options[key] !== 'boolean')
|
|
6
|
+
throw new Error(`[HstA11y] ${key} must be a boolean`);
|
|
7
|
+
}
|
|
8
|
+
const timeoutMs = options.timeoutMs ?? 10000;
|
|
9
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 1 || timeoutMs > 30000)
|
|
10
|
+
throw new Error('[HstA11y] timeoutMs must be between 1 and 30000');
|
|
11
|
+
if (options.exclude !== undefined && (!Array.isArray(options.exclude) || options.exclude.some(value => typeof value !== 'string' || !value.trim())))
|
|
12
|
+
throw new Error('[HstA11y] exclude must contain nonempty selectors');
|
|
13
|
+
const impact = typeof options.test === 'object' ? options.test?.minimumImpact : undefined;
|
|
14
|
+
if (impact !== undefined && !['minor', 'moderate', 'serious', 'critical'].includes(impact))
|
|
15
|
+
throw new Error('[HstA11y] Invalid minimumImpact');
|
|
16
|
+
// Browser settings travel as plain JSON, never callbacks or custom engine configuration.
|
|
17
|
+
if (options.axe !== undefined && (!options.axe || typeof options.axe !== 'object' || Array.isArray(options.axe)))
|
|
18
|
+
throw new Error('[HstA11y] axe must contain rule options');
|
|
19
|
+
if (options.axe)
|
|
20
|
+
measureWireValue(options.axe, { mode: 'json' });
|
|
21
|
+
return { autoRun: options.autoRun ?? true, exclude: options.exclude ?? [], timeoutMs, ...(options.axe ? { axe: options.axe } : {}) };
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Name of the per-variant test registered by the `test` option. */
|
|
2
|
+
export declare const A11Y_TEST_NAME = "Accessibility (axe-core)";
|
|
3
|
+
/** Plugin key of the report attached to test results (`HistoireTestCaseResult.data`). */
|
|
4
|
+
export declare const A11Y_TEST_DATA_KEY = "a11y";
|
|
5
|
+
/** File emitted into static books by the `build` option. */
|
|
6
|
+
export declare const A11Y_BUILD_REPORT_FILE = "a11y-report.json";
|
package/dist/results.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Name of the per-variant test registered by the `test` option. */
|
|
2
|
+
export const A11Y_TEST_NAME = 'Accessibility (axe-core)';
|
|
3
|
+
/** Plugin key of the report attached to test results (`HistoireTestCaseResult.data`). */
|
|
4
|
+
export const A11Y_TEST_DATA_KEY = 'a11y';
|
|
5
|
+
/** File emitted into static books by the `build` option. */
|
|
6
|
+
export const A11Y_BUILD_REPORT_FILE = 'a11y-report.json';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AxeResults } from 'axe-core';
|
|
2
|
+
import type { A11yImpact } from '../options.js';
|
|
3
|
+
/** Severity weights shared by filtering and test policy. */
|
|
4
|
+
export declare const IMPACTS: Readonly<Record<A11yImpact, number>>;
|
|
5
|
+
/** Evaluate complete axe output before bounding human-readable failure diagnostics. */
|
|
6
|
+
export declare function evaluateResults(results: Pick<AxeResults, 'violations' | 'incomplete'>, minimumImpact?: A11yImpact): {
|
|
7
|
+
failed: number;
|
|
8
|
+
belowThreshold: number;
|
|
9
|
+
review: number;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AxeResults } from 'axe-core';
|
|
2
|
+
import type { A11yScanOptions } from '../options.js';
|
|
3
|
+
/** Exact private element references retained for one completed report. */
|
|
4
|
+
export type AuditElements = Map<string, Element>;
|
|
5
|
+
/** Stable key correlating bounded finding to private raw node reference. */
|
|
6
|
+
export declare function nodeKey(kind: string, rule: string, selectors: readonly string[]): string;
|
|
7
|
+
/** Scan one owned root; retain raw results locally for complete CLI failure policy. */
|
|
8
|
+
export declare function runAudit(root: HTMLElement, input?: A11yScanOptions, signal?: AbortSignal): Promise<{
|
|
9
|
+
report: {
|
|
10
|
+
violationsCount: number;
|
|
11
|
+
incompleteCount: number;
|
|
12
|
+
matched: boolean;
|
|
13
|
+
engine: "axe-core";
|
|
14
|
+
engineVersion: string;
|
|
15
|
+
violations: import("@histoire/protocol").HistoireAccessibilityFinding[];
|
|
16
|
+
incomplete: import("@histoire/protocol").HistoireAccessibilityFinding[];
|
|
17
|
+
passesCount: number;
|
|
18
|
+
inapplicableCount: number;
|
|
19
|
+
droppedCount: number;
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
};
|
|
22
|
+
raw: AxeResults;
|
|
23
|
+
elements: AuditElements;
|
|
24
|
+
}>;
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HistoireTestRuntimeContext } from '@histoire/shared';
|
|
2
|
+
import type { A11yTestOptions } from './options.js';
|
|
3
|
+
export type { A11yTestOptions } from './options.js';
|
|
4
|
+
/**
|
|
5
|
+
* Assert accessibility of current story state, independent of workbench preferences.
|
|
6
|
+
* @param canvas Variant root to scan.
|
|
7
|
+
* @param options Scan settings and failure threshold.
|
|
8
|
+
* @param context Optional test runtime context; when given, the bounded report is attached to the
|
|
9
|
+
* test result (also on failure) so the workbench Accessibility pane can list findings.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertA11y(canvas: HTMLElement, options?: A11yTestOptions, context?: Pick<HistoireTestRuntimeContext, 'task'>): Promise<void>;
|
|
12
|
+
/** Register one isolated test; called by generated framework setup hooks. Never scans during discovery. */
|
|
13
|
+
export declare function registerA11yTests(options: A11yTestOptions): void;
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { a as evaluateResults, n as A11Y_TEST_DATA_KEY, r as A11Y_TEST_NAME } from "./chunks/results-C0vYpcmy.js";
|
|
2
|
+
import { n as runAudit } from "./chunks/run-lct8FHuk.js";
|
|
3
|
+
import { pushHistoireTestRegistration, registerCollectedTestCase, setHistoireTestData } from "@histoire/shared";
|
|
4
|
+
// src/test.ts
|
|
5
|
+
/**
|
|
6
|
+
* Assert accessibility of current story state, independent of workbench preferences.
|
|
7
|
+
* @param canvas Variant root to scan.
|
|
8
|
+
* @param options Scan settings and failure threshold.
|
|
9
|
+
* @param context Optional test runtime context; when given, the bounded report is attached to the
|
|
10
|
+
* test result (also on failure) so the workbench Accessibility pane can list findings.
|
|
11
|
+
*/
|
|
12
|
+
async function assertA11y(canvas, options = {}, context) {
|
|
13
|
+
const result = await runAudit(canvas, options);
|
|
14
|
+
setHistoireTestData(context, A11Y_TEST_DATA_KEY, { report: result.report });
|
|
15
|
+
const policy = evaluateResults(result.raw, options.minimumImpact);
|
|
16
|
+
if (policy.review || policy.belowThreshold) console.info(`[Accessibility] ${policy.review} rules need review; ${policy.belowThreshold} violations below failure threshold`);
|
|
17
|
+
if (policy.failed) throw new Error(`${policy.failed} accessibility ${policy.failed === 1 ? "violation" : "violations"}\n\n${policy.message}`);
|
|
18
|
+
}
|
|
19
|
+
/** Register one isolated test; called by generated framework setup hooks. Never scans during discovery. */
|
|
20
|
+
function registerA11yTests(options) {
|
|
21
|
+
pushHistoireTestRegistration(({ canvas }) => {
|
|
22
|
+
registerCollectedTestCase(A11Y_TEST_NAME, (context) => assertA11y(canvas, options, context), (options.timeoutMs ?? 1e4) + 1e3);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export { assertA11y, registerA11yTests };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FrameScopedContext } from '@histoire/plugin-kit';
|
|
2
|
+
import type { AuditModel } from './model.js';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** Current actor scope supplied by host. */
|
|
5
|
+
context: FrameScopedContext;
|
|
6
|
+
/** Host-isolated audit model. */
|
|
7
|
+
model: AuditModel;
|
|
8
|
+
};
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuditReport } from '../messages.js';
|
|
2
|
+
import type { NodeFinding } from './locate.js';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** Bounded finding from exact actor. */
|
|
5
|
+
rule: AuditReport['violations'][number];
|
|
6
|
+
/** Outcome category of the rule. */
|
|
7
|
+
outcome: NodeFinding['outcome'];
|
|
8
|
+
};
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
10
|
+
highlight: (finding: NodeFinding) => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
12
|
+
onHighlight?: ((finding: NodeFinding) => any) | undefined;
|
|
13
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
|
+
declare const _default: typeof __VLS_export;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PluginPreferences, WorkbenchContext } from '@histoire/plugin-kit';
|
|
2
|
+
import type { AuditModel } from './model.js';
|
|
3
|
+
import type { ProjectSource } from './project-source.js';
|
|
4
|
+
type __VLS_Props = {
|
|
5
|
+
/** Root workbench context (catalog and navigation). */
|
|
6
|
+
context: WorkbenchContext;
|
|
7
|
+
/** Project results source. */
|
|
8
|
+
source: ProjectSource;
|
|
9
|
+
/** Plugin preferences holding the shared filters. */
|
|
10
|
+
preferences: PluginPreferences;
|
|
11
|
+
/** Live audit model, highlighting through the inspector tab's frame visit. */
|
|
12
|
+
model: AuditModel;
|
|
13
|
+
};
|
|
14
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
|
+
declare const _default: typeof __VLS_export;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NodeFinding } from './locate.js';
|
|
2
|
+
import type { ProjectGroup } from './project-model.js';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** Variant row with its matching findings. */
|
|
5
|
+
group: ProjectGroup;
|
|
6
|
+
/** Outcome category the findings belong to. */
|
|
7
|
+
outcome: NodeFinding['outcome'];
|
|
8
|
+
};
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
10
|
+
highlight: (finding: NodeFinding) => any;
|
|
11
|
+
open: () => any;
|
|
12
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
13
|
+
onHighlight?: ((finding: NodeFinding) => any) | undefined;
|
|
14
|
+
onOpen?: (() => any) | undefined;
|
|
15
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
16
|
+
declare const _default: typeof __VLS_export;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PluginPreferences } from '@histoire/plugin-kit';
|
|
2
|
+
import type { WritableComputedRef } from 'vue';
|
|
3
|
+
import type { ProjectFilter } from './project-model.js';
|
|
4
|
+
/** Options of the outcome select. */
|
|
5
|
+
export declare const OUTCOME_OPTIONS: {
|
|
6
|
+
violations: string;
|
|
7
|
+
incomplete: string;
|
|
8
|
+
};
|
|
9
|
+
/** Options of the severity select. */
|
|
10
|
+
export declare const SEVERITY_OPTIONS: {
|
|
11
|
+
all: string;
|
|
12
|
+
critical: string;
|
|
13
|
+
serious: string;
|
|
14
|
+
moderate: string;
|
|
15
|
+
minor: string;
|
|
16
|
+
unknown: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Outcome and severity filters persisted in plugin preferences, shared by the inspector tab and
|
|
20
|
+
* the project pane. Invalid stored values read as defaults. Must run in a component scope.
|
|
21
|
+
* @param preferences Plugin preferences.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useFindingFilters(preferences: PluginPreferences): {
|
|
24
|
+
outcome: WritableComputedRef<ProjectFilter['outcome']>;
|
|
25
|
+
severity: WritableComputedRef<string>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** One requirement list of an axe failure summary. */
|
|
2
|
+
export interface FixSection {
|
|
3
|
+
/** `all`: every item must be fixed; `any`: fixing one item is enough. */
|
|
4
|
+
kind: 'all' | 'any';
|
|
5
|
+
/** Requirements, one per line of the summary. */
|
|
6
|
+
items: string[];
|
|
7
|
+
}
|
|
8
|
+
/** Affected element of a finding, as the bounded report carries it. */
|
|
9
|
+
export interface FixNode {
|
|
10
|
+
/** Selector chain (frames first). */
|
|
11
|
+
selectors: string[];
|
|
12
|
+
/** Raw axe failure summary. */
|
|
13
|
+
failureSummary?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Elements that share the same fix. */
|
|
16
|
+
export interface FixGroup<TNode extends FixNode = FixNode> {
|
|
17
|
+
/** Parsed fix of every element of the group. */
|
|
18
|
+
sections: FixSection[];
|
|
19
|
+
/** Elements in report order. */
|
|
20
|
+
nodes: TNode[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Splits an axe `failureSummary` into its "Fix all" / "Fix any" requirement lists.
|
|
24
|
+
* Lines before any heading form an `all` list.
|
|
25
|
+
* @param summary Raw summary; `undefined` reads as no requirement.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseFailureSummary(summary: string | undefined): FixSection[];
|
|
28
|
+
/**
|
|
29
|
+
* Groups elements with an identical failure summary, so a shared fix shows once.
|
|
30
|
+
* Groups keep the order in which their first element appears.
|
|
31
|
+
* @param nodes Affected elements of one finding.
|
|
32
|
+
*/
|
|
33
|
+
export declare function groupNodesByFix<TNode extends FixNode>(nodes: readonly TNode[]): FixGroup<TNode>[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuditReport } from '../messages.js';
|
|
2
|
+
/** One reported element to find again in a live report of the same variant. */
|
|
3
|
+
export interface NodeFinding {
|
|
4
|
+
/** Outcome category of the rule. */
|
|
5
|
+
outcome: 'violations' | 'incomplete';
|
|
6
|
+
/** Axe rule id. */
|
|
7
|
+
rule: string;
|
|
8
|
+
/** Selector chain of the element in the report it comes from. */
|
|
9
|
+
selectors: readonly string[];
|
|
10
|
+
/** Position of the element in its rule. */
|
|
11
|
+
index: number;
|
|
12
|
+
/** Elements of the rule in the report it comes from. */
|
|
13
|
+
count: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Element of a live report matching a finding from another report (a project run, the build
|
|
17
|
+
* report). Same selectors win; selectors computed in another document only match by position,
|
|
18
|
+
* and only when the rule reports as many elements, so a changed variant never highlights a guess.
|
|
19
|
+
* @param report Live report of the variant.
|
|
20
|
+
* @param finding Element to find.
|
|
21
|
+
*/
|
|
22
|
+
export declare function matchNode(report: Pick<AuditReport, 'violations' | 'incomplete'>, finding: NodeFinding): {
|
|
23
|
+
selectors: string[];
|
|
24
|
+
accessibleName?: string;
|
|
25
|
+
failureSummary?: string;
|
|
26
|
+
} | undefined;
|