@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,12 @@
|
|
|
1
|
+
// src/messages.ts
|
|
2
|
+
/** Post owned JSON DTO through bounded plugin transport. */
|
|
3
|
+
function send(channel, type, data) {
|
|
4
|
+
return channel.post(type, data);
|
|
5
|
+
}
|
|
6
|
+
/** Read command shape without trusting arbitrary host messages. */
|
|
7
|
+
function command(value) {
|
|
8
|
+
if (!value || typeof value !== "object") return;
|
|
9
|
+
const data = value;
|
|
10
|
+
return typeof data.visit === "string" && data.visit.length > 0 && data.visit.length < 128 ? data : void 0;
|
|
11
|
+
}
|
|
12
|
+
export { send as n, command as t };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/scanner/policy.ts
|
|
2
|
+
/** Severity weights shared by filtering and test policy. */
|
|
3
|
+
var IMPACTS = {
|
|
4
|
+
minor: 1,
|
|
5
|
+
moderate: 2,
|
|
6
|
+
serious: 3,
|
|
7
|
+
critical: 4
|
|
8
|
+
};
|
|
9
|
+
/** Evaluate complete axe output before bounding human-readable failure diagnostics. */
|
|
10
|
+
function evaluateResults(results, minimumImpact) {
|
|
11
|
+
if (minimumImpact !== void 0 && !Object.hasOwn(IMPACTS, minimumImpact)) throw new Error("[HstA11y] Invalid minimumImpact");
|
|
12
|
+
const failing = results.violations.filter((rule) => !minimumImpact || !rule.impact || (IMPACTS[rule.impact] ?? 4) >= IMPACTS[minimumImpact]);
|
|
13
|
+
const lines = [];
|
|
14
|
+
let remaining = 12e3;
|
|
15
|
+
let omitted = 0;
|
|
16
|
+
for (const rule of failing) {
|
|
17
|
+
const text = [`${rule.id} [${rule.impact ?? "unknown"}]: ${rule.help}\n${rule.helpUrl}`, ...rule.nodes.map((node) => `${JSON.stringify(node.target)}${node.failureSummary ? `\n${node.failureSummary}` : ""}`)].join("\n");
|
|
18
|
+
if (remaining < 300) {
|
|
19
|
+
omitted++;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const bounded = text.slice(0, Math.min(remaining, 2e3));
|
|
23
|
+
lines.push(bounded + (bounded.length < text.length ? "\nAdditional element details omitted" : ""));
|
|
24
|
+
remaining -= bounded.length;
|
|
25
|
+
}
|
|
26
|
+
if (omitted) lines.push(`${omitted} additional failing rules omitted`);
|
|
27
|
+
return {
|
|
28
|
+
failed: failing.length,
|
|
29
|
+
belowThreshold: results.violations.length - failing.length,
|
|
30
|
+
review: results.incomplete.length,
|
|
31
|
+
message: lines.join("\n\n")
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// src/results.ts
|
|
35
|
+
/** Name of the per-variant test registered by the `test` option. */
|
|
36
|
+
var A11Y_TEST_NAME = "Accessibility (axe-core)";
|
|
37
|
+
/** Plugin key of the report attached to test results (`HistoireTestCaseResult.data`). */
|
|
38
|
+
var A11Y_TEST_DATA_KEY = "a11y";
|
|
39
|
+
/** File emitted into static books by the `build` option. */
|
|
40
|
+
var A11Y_BUILD_REPORT_FILE = "a11y-report.json";
|
|
41
|
+
export { evaluateResults as a, IMPACTS as i, A11Y_TEST_DATA_KEY as n, A11Y_TEST_NAME as r, A11Y_BUILD_REPORT_FILE as t };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { normalizeAccessibility, scanAccessibilityRaw, waitForAccessibilityScan } from "@histoire/shared/accessibility";
|
|
2
|
+
import { measureWireValue } from "@histoire/protocol";
|
|
3
|
+
// src/options.ts
|
|
4
|
+
/** Validate public settings before generating browser configuration. */
|
|
5
|
+
function normalizeOptions(options = {}) {
|
|
6
|
+
for (const key of [
|
|
7
|
+
"enabled",
|
|
8
|
+
"devOnly",
|
|
9
|
+
"autoRun",
|
|
10
|
+
"build"
|
|
11
|
+
]) if (options[key] !== void 0 && typeof options[key] !== "boolean") throw new Error(`[HstA11y] ${key} must be a boolean`);
|
|
12
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
13
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 1 || timeoutMs > 3e4) throw new Error("[HstA11y] timeoutMs must be between 1 and 30000");
|
|
14
|
+
if (options.exclude !== void 0 && (!Array.isArray(options.exclude) || options.exclude.some((value) => typeof value !== "string" || !value.trim()))) throw new Error("[HstA11y] exclude must contain nonempty selectors");
|
|
15
|
+
const impact = typeof options.test === "object" ? options.test?.minimumImpact : void 0;
|
|
16
|
+
if (impact !== void 0 && ![
|
|
17
|
+
"minor",
|
|
18
|
+
"moderate",
|
|
19
|
+
"serious",
|
|
20
|
+
"critical"
|
|
21
|
+
].includes(impact)) throw new Error("[HstA11y] Invalid minimumImpact");
|
|
22
|
+
if (options.axe !== void 0 && (!options.axe || typeof options.axe !== "object" || Array.isArray(options.axe))) throw new Error("[HstA11y] axe must contain rule options");
|
|
23
|
+
if (options.axe) measureWireValue(options.axe, { mode: "json" });
|
|
24
|
+
return {
|
|
25
|
+
autoRun: options.autoRun ?? true,
|
|
26
|
+
exclude: options.exclude ?? [],
|
|
27
|
+
timeoutMs,
|
|
28
|
+
...options.axe ? { axe: options.axe } : {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// src/scanner/run.ts
|
|
32
|
+
/** Recovery guidance for shared scanner's finite error codes. */
|
|
33
|
+
var SCAN_ERRORS = {
|
|
34
|
+
TIMEOUT: "Accessibility check timed out. Run checks again or increase timeoutMs.",
|
|
35
|
+
CAPABILITY_UNAVAILABLE: "Another accessibility check is still running. Try again shortly.",
|
|
36
|
+
RUNTIME_CHANGED: "Variant changed during accessibility check. Run checks again.",
|
|
37
|
+
CANCELLED: "Accessibility check cancelled.",
|
|
38
|
+
INTERNAL_ERROR: "Accessibility check failed. Run checks again."
|
|
39
|
+
};
|
|
40
|
+
/** Stable key correlating bounded finding to private raw node reference. */
|
|
41
|
+
function nodeKey(kind, rule, selectors) {
|
|
42
|
+
return JSON.stringify([
|
|
43
|
+
kind,
|
|
44
|
+
rule,
|
|
45
|
+
selectors
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
/** Scan one owned root; retain raw results locally for complete CLI failure policy. */
|
|
49
|
+
async function runAudit(root, input = {}, signal) {
|
|
50
|
+
const options = normalizeOptions(input);
|
|
51
|
+
let raw;
|
|
52
|
+
const elements = /* @__PURE__ */ new Map();
|
|
53
|
+
let detail;
|
|
54
|
+
const capturedDocument = root.ownerDocument;
|
|
55
|
+
try {
|
|
56
|
+
const started = performance.now();
|
|
57
|
+
await waitForAccessibilityScan(capturedDocument, signal, options.timeoutMs);
|
|
58
|
+
const result = await scanAccessibilityRaw(root, void 0, {
|
|
59
|
+
signal,
|
|
60
|
+
timeoutMs: Math.max(1, options.timeoutMs - (performance.now() - started)),
|
|
61
|
+
isActive: () => root.isConnected && root.ownerDocument === capturedDocument,
|
|
62
|
+
loadAxe: async () => {
|
|
63
|
+
let axe;
|
|
64
|
+
try {
|
|
65
|
+
axe = (await import("./_histoire-a11y-axe-BL07tEuN.js")).default;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
detail = error;
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
const rules = new Set(axe.getRules().map((rule) => rule.ruleId));
|
|
71
|
+
for (const name of Object.keys(options.axe?.rules ?? {})) if (!rules.has(name)) {
|
|
72
|
+
detail = /* @__PURE__ */ new Error(`Unknown axe rule: ${name}`);
|
|
73
|
+
throw detail;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
version: axe.version,
|
|
77
|
+
async run() {
|
|
78
|
+
try {
|
|
79
|
+
const excluded = options.exclude.flatMap((selector) => [...root.matches(selector) ? [root] : [], ...root.querySelectorAll(selector)]);
|
|
80
|
+
const runOptions = {
|
|
81
|
+
...options.axe,
|
|
82
|
+
elementRef: true
|
|
83
|
+
};
|
|
84
|
+
const scanned = excluded.includes(root) ? {
|
|
85
|
+
violations: [],
|
|
86
|
+
incomplete: [],
|
|
87
|
+
passes: [],
|
|
88
|
+
inapplicable: [],
|
|
89
|
+
testEngine: {
|
|
90
|
+
name: "axe-core",
|
|
91
|
+
version: axe.version
|
|
92
|
+
}
|
|
93
|
+
} : await axe.run({
|
|
94
|
+
include: [root],
|
|
95
|
+
exclude: excluded
|
|
96
|
+
}, runOptions);
|
|
97
|
+
raw = scanned;
|
|
98
|
+
for (const kind of ["violations", "incomplete"]) for (const rule of scanned[kind]) for (const node of rule.nodes) {
|
|
99
|
+
const element = node.element;
|
|
100
|
+
if (element && root.contains(element)) elements.set(nodeKey(kind, rule.id, node.target), element);
|
|
101
|
+
}
|
|
102
|
+
return scanned;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
detail = error;
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const report = {
|
|
112
|
+
...normalizeAccessibility(result.engineVersion, result.matched, result.results),
|
|
113
|
+
violationsCount: raw.violations.length,
|
|
114
|
+
incompleteCount: raw.incomplete.length
|
|
115
|
+
};
|
|
116
|
+
const retained = /* @__PURE__ */ new Map();
|
|
117
|
+
for (const kind of ["violations", "incomplete"]) for (const rule of report[kind]) for (const node of rule.nodes) {
|
|
118
|
+
const key = nodeKey(kind, rule.id, node.selectors);
|
|
119
|
+
const element = elements.get(key);
|
|
120
|
+
if (element) retained.set(key, element);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
report,
|
|
124
|
+
raw,
|
|
125
|
+
elements: retained
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (detail) throw new Error(`Accessibility scan failed: ${detail instanceof Error ? detail.message : String(detail)}`, { cause: error });
|
|
129
|
+
const code = error?.code;
|
|
130
|
+
if (code && SCAN_ERRORS[code]) throw new Error(SCAN_ERRORS[code], { cause: error });
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export { runAudit as n, normalizeOptions as r, nodeKey as t };
|
package/dist/client.d.ts
ADDED