@accesslint/storybook-addon 0.8.9 → 0.8.11
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/README.md +26 -30
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/index.cjs +6 -116
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +6 -6
- package/dist/manager.d.ts +1 -0
- package/dist/manager.js +404 -395
- package/dist/matchers.cjs +10 -10
- package/dist/matchers.d.cts +2 -1
- package/dist/matchers.d.ts +2 -1
- package/dist/matchers.js +2 -1
- package/dist/portable.cjs +146 -105
- package/dist/portable.d.cts +37 -54
- package/dist/portable.d.ts +37 -54
- package/dist/portable.js +130 -104
- package/dist/preview-B3suakeJ.js +118 -0
- package/dist/preview-B8cvp9pY.cjs +148 -0
- package/dist/preview.cjs +6 -102
- package/dist/preview.d.cts +32 -17
- package/dist/preview.d.ts +32 -17
- package/dist/preview.js +2 -1
- package/dist/vitest-plugin.cjs +15 -27
- package/dist/vitest-plugin.d.cts +15 -14
- package/dist/vitest-plugin.d.ts +15 -14
- package/dist/vitest-plugin.js +14 -24
- package/dist/vitest-setup.cjs +131 -108
- package/dist/vitest-setup.d.cts +1 -2
- package/dist/vitest-setup.d.ts +1 -2
- package/dist/vitest-setup.js +127 -103
- package/package.json +86 -24
- package/dist/chunk-XTEGJNR3.js +0 -110
package/dist/portable.js
CHANGED
|
@@ -1,115 +1,141 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
parameters: () => parameters
|
|
1
|
+
import { t as __exportAll } from "./chunk-pbuEa-1d.js";
|
|
2
|
+
import { createChunkedAudit, getActiveRules, getRuleById } from "@accesslint/core";
|
|
3
|
+
import { addons } from "storybook/preview-api";
|
|
4
|
+
const RESULT_EVENT = `accesslint/a11y/result`;
|
|
5
|
+
const HIGHLIGHT_ADDON_ID = "storybook/highlight";
|
|
6
|
+
`${HIGHLIGHT_ADDON_ID}`;
|
|
7
|
+
`${HIGHLIGHT_ADDON_ID}`;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/preview.ts
|
|
10
|
+
var preview_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
afterEach: () => afterEach,
|
|
12
|
+
initialGlobals: () => initialGlobals,
|
|
13
|
+
parameters: () => parameters,
|
|
14
|
+
setAuditOptions: () => setAuditOptions
|
|
16
15
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
16
|
+
const initialGlobals = { accesslint: {} };
|
|
17
|
+
const parameters = { accesslint: {} };
|
|
18
|
+
let AUDIT_OPTIONS = { disabledRules: ["accesslint-045"] };
|
|
19
|
+
/**
|
|
20
|
+
* Merge additional audit options (disabledRules, additionalRules, includeAAA,
|
|
21
|
+
* componentMode, locale) into the options used for every Storybook audit.
|
|
22
|
+
* Call from your `.storybook/preview.ts` after importing the addon.
|
|
23
|
+
*/
|
|
24
|
+
function setAuditOptions(options) {
|
|
25
|
+
AUDIT_OPTIONS = {
|
|
26
|
+
...AUDIT_OPTIONS,
|
|
27
|
+
...options,
|
|
28
|
+
disabledRules: [...AUDIT_OPTIONS.disabledRules ?? [], ...options.disabledRules ?? []],
|
|
29
|
+
additionalRules: [...AUDIT_OPTIONS.additionalRules ?? [], ...options.additionalRules ?? []]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const BUDGET_MS = 12;
|
|
33
33
|
function yieldToMain() {
|
|
34
|
-
|
|
34
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
35
35
|
}
|
|
36
36
|
function scopeViolations(violations) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
const root = document.getElementById("storybook-root");
|
|
38
|
+
if (!root) return violations;
|
|
39
|
+
return violations.filter((v) => {
|
|
40
|
+
const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
41
|
+
try {
|
|
42
|
+
const el = document.querySelector(local);
|
|
43
|
+
return el && root.contains(el);
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
48
|
}
|
|
49
49
|
function enrichViolations(violations) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
50
|
+
return violations.map((v) => {
|
|
51
|
+
const rule = getRuleById(v.ruleId);
|
|
52
|
+
return {
|
|
53
|
+
...v,
|
|
54
|
+
element: void 0,
|
|
55
|
+
description: rule?.description,
|
|
56
|
+
wcag: rule?.wcag,
|
|
57
|
+
level: rule?.level,
|
|
58
|
+
guidance: rule?.guidance
|
|
59
|
+
};
|
|
60
|
+
});
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
62
|
+
const afterEach = async ({ reporting, parameters, viewMode, tags, id }) => {
|
|
63
|
+
const accesslintParam = parameters?.accesslint;
|
|
64
|
+
if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
|
|
65
|
+
if (viewMode !== "story") return;
|
|
66
|
+
const allSkipTags = ["skip-accesslint", ...typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : []];
|
|
67
|
+
const matchedTag = tags?.find((t) => allSkipTags.includes(t));
|
|
68
|
+
if (matchedTag) {
|
|
69
|
+
const result = {
|
|
70
|
+
skipped: true,
|
|
71
|
+
reason: matchedTag
|
|
72
|
+
};
|
|
73
|
+
addons.getChannel().emit(RESULT_EVENT, {
|
|
74
|
+
storyId: id,
|
|
75
|
+
result
|
|
76
|
+
});
|
|
77
|
+
reporting.addReport({
|
|
78
|
+
type: "accesslint",
|
|
79
|
+
version: 1,
|
|
80
|
+
result,
|
|
81
|
+
status: "passed"
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const audit = createChunkedAudit(document, AUDIT_OPTIONS);
|
|
86
|
+
while (audit.processChunk(BUDGET_MS)) await yieldToMain();
|
|
87
|
+
const enriched = enrichViolations(scopeViolations(audit.getViolations()));
|
|
88
|
+
const hasViolations = enriched.length > 0;
|
|
89
|
+
const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
|
|
90
|
+
const status = hasViolations ? mode : "passed";
|
|
91
|
+
const result = {
|
|
92
|
+
violations: enriched,
|
|
93
|
+
ruleCount: getActiveRules(AUDIT_OPTIONS).length
|
|
94
|
+
};
|
|
95
|
+
addons.getChannel().emit(RESULT_EVENT, {
|
|
96
|
+
storyId: id,
|
|
97
|
+
result,
|
|
98
|
+
status
|
|
99
|
+
});
|
|
100
|
+
reporting.addReport({
|
|
101
|
+
type: "accesslint",
|
|
102
|
+
version: 1,
|
|
103
|
+
result,
|
|
104
|
+
status
|
|
105
|
+
});
|
|
108
106
|
};
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/portable.ts
|
|
109
|
+
/**
|
|
110
|
+
* Portable stories helper for using AccessLint with composeStories
|
|
111
|
+
* outside of Storybook (plain Vitest, Jest, Playwright CT).
|
|
112
|
+
*
|
|
113
|
+
* Usage in your test setup file:
|
|
114
|
+
*
|
|
115
|
+
* import { enableAccessLint } from "@accesslint/storybook-addon/portable";
|
|
116
|
+
* import { setProjectAnnotations } from "@storybook/react";
|
|
117
|
+
* import * as previewAnnotations from "./.storybook/preview";
|
|
118
|
+
*
|
|
119
|
+
* const project = setProjectAnnotations([
|
|
120
|
+
* previewAnnotations,
|
|
121
|
+
* enableAccessLint(),
|
|
122
|
+
* ]);
|
|
123
|
+
* beforeAll(project.beforeAll);
|
|
124
|
+
*
|
|
125
|
+
* Then in tests:
|
|
126
|
+
*
|
|
127
|
+
* import { composeStories } from "@storybook/react";
|
|
128
|
+
* import * as stories from "./Button.stories";
|
|
129
|
+
*
|
|
130
|
+
* const { Primary } = composeStories(stories);
|
|
131
|
+
*
|
|
132
|
+
* test("is accessible", async () => {
|
|
133
|
+
* await Primary.run();
|
|
134
|
+
* // AccessLint afterEach runs automatically and reports violations
|
|
135
|
+
* });
|
|
136
|
+
*/
|
|
111
137
|
function enableAccessLint() {
|
|
112
|
-
|
|
138
|
+
return preview_exports;
|
|
113
139
|
}
|
|
114
|
-
|
|
140
|
+
//#endregion
|
|
115
141
|
export { preview_exports as accesslintAnnotations, enableAccessLint };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createChunkedAudit, getActiveRules, getRuleById } from "@accesslint/core";
|
|
2
|
+
import { addons } from "storybook/preview-api";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
const RESULT_EVENT = `accesslint/a11y/result`;
|
|
15
|
+
const HIGHLIGHT_ADDON_ID = "storybook/highlight";
|
|
16
|
+
`${HIGHLIGHT_ADDON_ID}`;
|
|
17
|
+
`${HIGHLIGHT_ADDON_ID}`;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/preview.ts
|
|
20
|
+
var preview_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
afterEach: () => afterEach,
|
|
22
|
+
initialGlobals: () => initialGlobals,
|
|
23
|
+
parameters: () => parameters,
|
|
24
|
+
setAuditOptions: () => setAuditOptions
|
|
25
|
+
});
|
|
26
|
+
const initialGlobals = { accesslint: {} };
|
|
27
|
+
const parameters = { accesslint: {} };
|
|
28
|
+
let AUDIT_OPTIONS = { disabledRules: ["accesslint-045"] };
|
|
29
|
+
/**
|
|
30
|
+
* Merge additional audit options (disabledRules, additionalRules, includeAAA,
|
|
31
|
+
* componentMode, locale) into the options used for every Storybook audit.
|
|
32
|
+
* Call from your `.storybook/preview.ts` after importing the addon.
|
|
33
|
+
*/
|
|
34
|
+
function setAuditOptions(options) {
|
|
35
|
+
AUDIT_OPTIONS = {
|
|
36
|
+
...AUDIT_OPTIONS,
|
|
37
|
+
...options,
|
|
38
|
+
disabledRules: [...AUDIT_OPTIONS.disabledRules ?? [], ...options.disabledRules ?? []],
|
|
39
|
+
additionalRules: [...AUDIT_OPTIONS.additionalRules ?? [], ...options.additionalRules ?? []]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const BUDGET_MS = 12;
|
|
43
|
+
function yieldToMain() {
|
|
44
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
45
|
+
}
|
|
46
|
+
function scopeViolations(violations) {
|
|
47
|
+
const root = document.getElementById("storybook-root");
|
|
48
|
+
if (!root) return violations;
|
|
49
|
+
return violations.filter((v) => {
|
|
50
|
+
const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
51
|
+
try {
|
|
52
|
+
const el = document.querySelector(local);
|
|
53
|
+
return el && root.contains(el);
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function enrichViolations(violations) {
|
|
60
|
+
return violations.map((v) => {
|
|
61
|
+
const rule = getRuleById(v.ruleId);
|
|
62
|
+
return {
|
|
63
|
+
...v,
|
|
64
|
+
element: void 0,
|
|
65
|
+
description: rule?.description,
|
|
66
|
+
wcag: rule?.wcag,
|
|
67
|
+
level: rule?.level,
|
|
68
|
+
guidance: rule?.guidance
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const afterEach = async ({ reporting, parameters, viewMode, tags, id }) => {
|
|
73
|
+
const accesslintParam = parameters?.accesslint;
|
|
74
|
+
if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
|
|
75
|
+
if (viewMode !== "story") return;
|
|
76
|
+
const allSkipTags = ["skip-accesslint", ...typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : []];
|
|
77
|
+
const matchedTag = tags?.find((t) => allSkipTags.includes(t));
|
|
78
|
+
if (matchedTag) {
|
|
79
|
+
const result = {
|
|
80
|
+
skipped: true,
|
|
81
|
+
reason: matchedTag
|
|
82
|
+
};
|
|
83
|
+
addons.getChannel().emit(RESULT_EVENT, {
|
|
84
|
+
storyId: id,
|
|
85
|
+
result
|
|
86
|
+
});
|
|
87
|
+
reporting.addReport({
|
|
88
|
+
type: "accesslint",
|
|
89
|
+
version: 1,
|
|
90
|
+
result,
|
|
91
|
+
status: "passed"
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const audit = createChunkedAudit(document, AUDIT_OPTIONS);
|
|
96
|
+
while (audit.processChunk(BUDGET_MS)) await yieldToMain();
|
|
97
|
+
const enriched = enrichViolations(scopeViolations(audit.getViolations()));
|
|
98
|
+
const hasViolations = enriched.length > 0;
|
|
99
|
+
const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
|
|
100
|
+
const status = hasViolations ? mode : "passed";
|
|
101
|
+
const result = {
|
|
102
|
+
violations: enriched,
|
|
103
|
+
ruleCount: getActiveRules(AUDIT_OPTIONS).length
|
|
104
|
+
};
|
|
105
|
+
addons.getChannel().emit(RESULT_EVENT, {
|
|
106
|
+
storyId: id,
|
|
107
|
+
result,
|
|
108
|
+
status
|
|
109
|
+
});
|
|
110
|
+
reporting.addReport({
|
|
111
|
+
type: "accesslint",
|
|
112
|
+
version: 1,
|
|
113
|
+
result,
|
|
114
|
+
status
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
export { setAuditOptions as a, preview_exports as i, initialGlobals as n, parameters as r, afterEach as t };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
let _accesslint_core = require("@accesslint/core");
|
|
14
|
+
let storybook_preview_api = require("storybook/preview-api");
|
|
15
|
+
const RESULT_EVENT = `accesslint/a11y/result`;
|
|
16
|
+
const HIGHLIGHT_ADDON_ID = "storybook/highlight";
|
|
17
|
+
`${HIGHLIGHT_ADDON_ID}`;
|
|
18
|
+
`${HIGHLIGHT_ADDON_ID}`;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/preview.ts
|
|
21
|
+
var preview_exports = /* @__PURE__ */ __exportAll({
|
|
22
|
+
afterEach: () => afterEach,
|
|
23
|
+
initialGlobals: () => initialGlobals,
|
|
24
|
+
parameters: () => parameters,
|
|
25
|
+
setAuditOptions: () => setAuditOptions
|
|
26
|
+
});
|
|
27
|
+
const initialGlobals = { accesslint: {} };
|
|
28
|
+
const parameters = { accesslint: {} };
|
|
29
|
+
let AUDIT_OPTIONS = { disabledRules: ["accesslint-045"] };
|
|
30
|
+
/**
|
|
31
|
+
* Merge additional audit options (disabledRules, additionalRules, includeAAA,
|
|
32
|
+
* componentMode, locale) into the options used for every Storybook audit.
|
|
33
|
+
* Call from your `.storybook/preview.ts` after importing the addon.
|
|
34
|
+
*/
|
|
35
|
+
function setAuditOptions(options) {
|
|
36
|
+
AUDIT_OPTIONS = {
|
|
37
|
+
...AUDIT_OPTIONS,
|
|
38
|
+
...options,
|
|
39
|
+
disabledRules: [...AUDIT_OPTIONS.disabledRules ?? [], ...options.disabledRules ?? []],
|
|
40
|
+
additionalRules: [...AUDIT_OPTIONS.additionalRules ?? [], ...options.additionalRules ?? []]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const BUDGET_MS = 12;
|
|
44
|
+
function yieldToMain() {
|
|
45
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
46
|
+
}
|
|
47
|
+
function scopeViolations(violations) {
|
|
48
|
+
const root = document.getElementById("storybook-root");
|
|
49
|
+
if (!root) return violations;
|
|
50
|
+
return violations.filter((v) => {
|
|
51
|
+
const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
52
|
+
try {
|
|
53
|
+
const el = document.querySelector(local);
|
|
54
|
+
return el && root.contains(el);
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function enrichViolations(violations) {
|
|
61
|
+
return violations.map((v) => {
|
|
62
|
+
const rule = (0, _accesslint_core.getRuleById)(v.ruleId);
|
|
63
|
+
return {
|
|
64
|
+
...v,
|
|
65
|
+
element: void 0,
|
|
66
|
+
description: rule?.description,
|
|
67
|
+
wcag: rule?.wcag,
|
|
68
|
+
level: rule?.level,
|
|
69
|
+
guidance: rule?.guidance
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const afterEach = async ({ reporting, parameters, viewMode, tags, id }) => {
|
|
74
|
+
const accesslintParam = parameters?.accesslint;
|
|
75
|
+
if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
|
|
76
|
+
if (viewMode !== "story") return;
|
|
77
|
+
const allSkipTags = ["skip-accesslint", ...typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : []];
|
|
78
|
+
const matchedTag = tags?.find((t) => allSkipTags.includes(t));
|
|
79
|
+
if (matchedTag) {
|
|
80
|
+
const result = {
|
|
81
|
+
skipped: true,
|
|
82
|
+
reason: matchedTag
|
|
83
|
+
};
|
|
84
|
+
storybook_preview_api.addons.getChannel().emit(RESULT_EVENT, {
|
|
85
|
+
storyId: id,
|
|
86
|
+
result
|
|
87
|
+
});
|
|
88
|
+
reporting.addReport({
|
|
89
|
+
type: "accesslint",
|
|
90
|
+
version: 1,
|
|
91
|
+
result,
|
|
92
|
+
status: "passed"
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const audit = (0, _accesslint_core.createChunkedAudit)(document, AUDIT_OPTIONS);
|
|
97
|
+
while (audit.processChunk(BUDGET_MS)) await yieldToMain();
|
|
98
|
+
const enriched = enrichViolations(scopeViolations(audit.getViolations()));
|
|
99
|
+
const hasViolations = enriched.length > 0;
|
|
100
|
+
const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
|
|
101
|
+
const status = hasViolations ? mode : "passed";
|
|
102
|
+
const result = {
|
|
103
|
+
violations: enriched,
|
|
104
|
+
ruleCount: (0, _accesslint_core.getActiveRules)(AUDIT_OPTIONS).length
|
|
105
|
+
};
|
|
106
|
+
storybook_preview_api.addons.getChannel().emit(RESULT_EVENT, {
|
|
107
|
+
storyId: id,
|
|
108
|
+
result,
|
|
109
|
+
status
|
|
110
|
+
});
|
|
111
|
+
reporting.addReport({
|
|
112
|
+
type: "accesslint",
|
|
113
|
+
version: 1,
|
|
114
|
+
result,
|
|
115
|
+
status
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
Object.defineProperty(exports, "afterEach", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function() {
|
|
122
|
+
return afterEach;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, "initialGlobals", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function() {
|
|
128
|
+
return initialGlobals;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(exports, "parameters", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function() {
|
|
134
|
+
return parameters;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, "preview_exports", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function() {
|
|
140
|
+
return preview_exports;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, "setAuditOptions", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function() {
|
|
146
|
+
return setAuditOptions;
|
|
147
|
+
}
|
|
148
|
+
});
|
package/dist/preview.cjs
CHANGED
|
@@ -1,102 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/constants.ts
|
|
9
|
-
var ADDON_ID = "accesslint/a11y";
|
|
10
|
-
var RESULT_EVENT = `${ADDON_ID}/result`;
|
|
11
|
-
|
|
12
|
-
// src/preview.ts
|
|
13
|
-
var initialGlobals = {
|
|
14
|
-
accesslint: {}
|
|
15
|
-
};
|
|
16
|
-
var parameters = {
|
|
17
|
-
accesslint: {}
|
|
18
|
-
};
|
|
19
|
-
core.configureRules({
|
|
20
|
-
disabledRules: ["accesslint-045"]
|
|
21
|
-
});
|
|
22
|
-
var BUDGET_MS = 12;
|
|
23
|
-
function yieldToMain() {
|
|
24
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
25
|
-
}
|
|
26
|
-
function scopeViolations(violations) {
|
|
27
|
-
const root = document.getElementById("storybook-root");
|
|
28
|
-
if (!root) return violations;
|
|
29
|
-
return violations.filter((v) => {
|
|
30
|
-
const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
31
|
-
try {
|
|
32
|
-
const el = document.querySelector(local);
|
|
33
|
-
return el && root.contains(el);
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function enrichViolations(violations) {
|
|
40
|
-
return violations.map((v) => {
|
|
41
|
-
const rule = core.getRuleById(v.ruleId);
|
|
42
|
-
return {
|
|
43
|
-
...v,
|
|
44
|
-
element: void 0,
|
|
45
|
-
// not serializable
|
|
46
|
-
description: rule?.description,
|
|
47
|
-
wcag: rule?.wcag,
|
|
48
|
-
level: rule?.level,
|
|
49
|
-
guidance: rule?.guidance
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
var afterEach = async ({
|
|
54
|
-
reporting,
|
|
55
|
-
parameters: parameters2,
|
|
56
|
-
viewMode,
|
|
57
|
-
tags,
|
|
58
|
-
id
|
|
59
|
-
}) => {
|
|
60
|
-
const accesslintParam = parameters2?.accesslint;
|
|
61
|
-
if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
|
|
62
|
-
if (viewMode !== "story") return;
|
|
63
|
-
const skipTags = typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : [];
|
|
64
|
-
const allSkipTags = ["skip-accesslint", ...skipTags];
|
|
65
|
-
const matchedTag = tags?.find((t) => allSkipTags.includes(t));
|
|
66
|
-
if (matchedTag) {
|
|
67
|
-
const result2 = { skipped: true, reason: matchedTag };
|
|
68
|
-
previewApi.addons.getChannel().emit(RESULT_EVENT, { storyId: id, result: result2 });
|
|
69
|
-
reporting.addReport({
|
|
70
|
-
type: "accesslint",
|
|
71
|
-
version: 1,
|
|
72
|
-
result: result2,
|
|
73
|
-
status: "passed"
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const audit = core.createChunkedAudit(document);
|
|
78
|
-
while (audit.processChunk(BUDGET_MS)) {
|
|
79
|
-
await yieldToMain();
|
|
80
|
-
}
|
|
81
|
-
const violations = audit.getViolations();
|
|
82
|
-
const scoped = scopeViolations(violations);
|
|
83
|
-
const enriched = enrichViolations(scoped);
|
|
84
|
-
const hasViolations = enriched.length > 0;
|
|
85
|
-
const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
|
|
86
|
-
const status = hasViolations ? mode : "passed";
|
|
87
|
-
const result = {
|
|
88
|
-
violations: enriched,
|
|
89
|
-
ruleCount: core.getActiveRules().length
|
|
90
|
-
};
|
|
91
|
-
previewApi.addons.getChannel().emit(RESULT_EVENT, { storyId: id, result, status });
|
|
92
|
-
reporting.addReport({
|
|
93
|
-
type: "accesslint",
|
|
94
|
-
version: 1,
|
|
95
|
-
result,
|
|
96
|
-
status
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
exports.afterEach = afterEach;
|
|
101
|
-
exports.initialGlobals = initialGlobals;
|
|
102
|
-
exports.parameters = parameters;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_preview = require("./preview-B8cvp9pY.cjs");
|
|
3
|
+
exports.afterEach = require_preview.afterEach;
|
|
4
|
+
exports.initialGlobals = require_preview.initialGlobals;
|
|
5
|
+
exports.parameters = require_preview.parameters;
|
|
6
|
+
exports.setAuditOptions = require_preview.setAuditOptions;
|
package/dist/preview.d.cts
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
+
import { AuditOptions } from "@accesslint/core";
|
|
2
|
+
|
|
3
|
+
//#region src/preview.d.ts
|
|
1
4
|
declare const initialGlobals: {
|
|
2
|
-
|
|
5
|
+
accesslint: {};
|
|
3
6
|
};
|
|
4
7
|
declare const parameters: {
|
|
5
|
-
|
|
8
|
+
accesslint: {};
|
|
6
9
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Merge additional audit options (disabledRules, additionalRules, includeAAA,
|
|
12
|
+
* componentMode, locale) into the options used for every Storybook audit.
|
|
13
|
+
* Call from your `.storybook/preview.ts` after importing the addon.
|
|
14
|
+
*/
|
|
15
|
+
declare function setAuditOptions(options: AuditOptions): void;
|
|
16
|
+
declare const afterEach: ({
|
|
17
|
+
reporting,
|
|
18
|
+
parameters,
|
|
19
|
+
viewMode,
|
|
20
|
+
tags,
|
|
21
|
+
id
|
|
22
|
+
}: {
|
|
23
|
+
reporting: {
|
|
24
|
+
addReport: (report: {
|
|
25
|
+
type: string;
|
|
26
|
+
version?: number;
|
|
27
|
+
result: unknown;
|
|
28
|
+
status: "failed" | "passed" | "warning";
|
|
29
|
+
}) => void;
|
|
30
|
+
};
|
|
31
|
+
parameters: Record<string, unknown>;
|
|
32
|
+
viewMode: string;
|
|
33
|
+
tags?: string[];
|
|
34
|
+
id?: string;
|
|
20
35
|
}) => Promise<void>;
|
|
21
|
-
|
|
22
|
-
export { afterEach, initialGlobals, parameters };
|
|
36
|
+
//#endregion
|
|
37
|
+
export { afterEach, initialGlobals, parameters, setAuditOptions };
|