@accesslint/storybook-addon 0.6.3
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/README.md +65 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/manager.js +278 -0
- package/dist/preview.cjs +58 -0
- package/dist/preview.d.cts +3 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +56 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AccessLint
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@accesslint/storybook-addon)
|
|
2
|
+
[](https://www.npmjs.com/package/@accesslint/storybook-addon)
|
|
3
|
+
[](https://github.com/AccessLint/storybook-addon/blob/main/LICENSE)
|
|
4
|
+
|
|
5
|
+
# @accesslint/storybook-addon
|
|
6
|
+
|
|
7
|
+
Catch accessibility violations in your Storybook stories as you develop. Powered by [@accesslint/core](https://core.accesslint.com).
|
|
8
|
+
|
|
9
|
+
<!-- TODO: Add screenshot or GIF of the panel -->
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @accesslint/storybook-addon
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then add it to your `.storybook/main.ts` (or `.storybook/main.js`):
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const config = {
|
|
21
|
+
addons: ["@accesslint/storybook-addon"],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default config;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
That's it. Restart Storybook and an **AccessLint** panel will appear in the addon bar.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
The addon automatically audits each story on render and displays violations sorted by severity. Expand any violation to see:
|
|
32
|
+
|
|
33
|
+
- **Impact level** — critical, serious, moderate, or minor
|
|
34
|
+
- **WCAG criteria** and conformance level (A, AA, AAA)
|
|
35
|
+
- **How to fix** guidance for each rule
|
|
36
|
+
- **Element HTML** snippet of the failing element
|
|
37
|
+
|
|
38
|
+
Selecting a violation highlights the affected element in the story preview.
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
Disable specific rules in your preview file:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// .storybook/preview.ts
|
|
46
|
+
import { configureRules } from "@accesslint/core";
|
|
47
|
+
|
|
48
|
+
configureRules({
|
|
49
|
+
disabledRules: ["accesslint-045"], // e.g. disable landmark region rule
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Compatibility
|
|
54
|
+
|
|
55
|
+
| Addon version | Storybook version |
|
|
56
|
+
| ------------- | ----------------- |
|
|
57
|
+
| 0.6.x | 8.6.x |
|
|
58
|
+
|
|
59
|
+
## Issues
|
|
60
|
+
|
|
61
|
+
Please report issues in the [AccessLint core repository](https://github.com/AccessLint/core/issues).
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/manager.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { addons, types, useAddonState, useChannel } from 'storybook/internal/manager-api';
|
|
2
|
+
import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
import { useTheme } from 'storybook/internal/theming';
|
|
4
|
+
import { AddonPanel } from 'storybook/internal/components';
|
|
5
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/manager.tsx
|
|
8
|
+
|
|
9
|
+
// src/constants.ts
|
|
10
|
+
var ADDON_ID = "accesslint/a11y";
|
|
11
|
+
var PANEL_ID = `${ADDON_ID}/panel`;
|
|
12
|
+
var IMPACT_COLOR = {
|
|
13
|
+
critical: "#d32f2f",
|
|
14
|
+
serious: "#d32f2f",
|
|
15
|
+
moderate: "#c43e00",
|
|
16
|
+
minor: "#999999"
|
|
17
|
+
};
|
|
18
|
+
var IMPACT_ICON = {
|
|
19
|
+
critical: "\u2716",
|
|
20
|
+
serious: "\u2716",
|
|
21
|
+
moderate: "\u26A0",
|
|
22
|
+
minor: "\xB7"
|
|
23
|
+
};
|
|
24
|
+
var IMPACT_ORDER = {
|
|
25
|
+
critical: 0,
|
|
26
|
+
serious: 1,
|
|
27
|
+
moderate: 2,
|
|
28
|
+
minor: 3
|
|
29
|
+
};
|
|
30
|
+
var LEVEL_COLOR = {
|
|
31
|
+
A: "#2e7d32",
|
|
32
|
+
AA: "#1565c0",
|
|
33
|
+
AAA: "#6a1b9a"
|
|
34
|
+
};
|
|
35
|
+
var HIGHLIGHT_ID = `${ADDON_ID}/highlight`;
|
|
36
|
+
var Panel = ({ active, ...rest }) => {
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
const isDark = theme.base === "dark";
|
|
39
|
+
const colors = useMemo(() => ({
|
|
40
|
+
text: theme.textColor || (isDark ? "#e0e0e0" : "#424242"),
|
|
41
|
+
textMuted: theme.textMutedColor || (isDark ? "#999" : "#616161"),
|
|
42
|
+
bg: theme.appContentBg || (isDark ? "#1a1a1a" : "#fff"),
|
|
43
|
+
bgDetails: isDark ? "#2a2a2a" : "#f5f5f5",
|
|
44
|
+
bgSelected: isDark ? "#1a3a5c" : "#e3f2fd",
|
|
45
|
+
border: theme.appBorderColor || (isDark ? "#444" : "#f0f0f0"),
|
|
46
|
+
codeBg: isDark ? "#333" : "#fff",
|
|
47
|
+
codeBorder: isDark ? "#555" : "#e0e0e0",
|
|
48
|
+
tagBg: isDark ? "#444" : "#e0e0e0",
|
|
49
|
+
tagText: isDark ? "#ccc" : "#616161",
|
|
50
|
+
ruleId: isDark ? "#64b5f6" : "#1565c0"
|
|
51
|
+
}), [isDark, theme]);
|
|
52
|
+
const [violations, setViolations] = useAddonState(
|
|
53
|
+
ADDON_ID,
|
|
54
|
+
[]
|
|
55
|
+
);
|
|
56
|
+
const [meta, setMeta] = useState(null);
|
|
57
|
+
const [expandedIndex, setExpandedIndex] = useState(null);
|
|
58
|
+
const buttonRefs = useRef([]);
|
|
59
|
+
const emit = useChannel({
|
|
60
|
+
[`${ADDON_ID}/results`]: (results) => {
|
|
61
|
+
setViolations(results);
|
|
62
|
+
setExpandedIndex(null);
|
|
63
|
+
},
|
|
64
|
+
[`${ADDON_ID}/meta`]: (data) => {
|
|
65
|
+
setMeta(data);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const sorted = [...violations].sort(
|
|
69
|
+
(a, b) => (IMPACT_ORDER[a.impact] ?? 4) - (IMPACT_ORDER[b.impact] ?? 4)
|
|
70
|
+
);
|
|
71
|
+
const expanded = expandedIndex !== null ? sorted[expandedIndex] : null;
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (expanded?.selector) {
|
|
74
|
+
const local = expanded.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
75
|
+
emit("storybook/highlight/add", {
|
|
76
|
+
id: HIGHLIGHT_ID,
|
|
77
|
+
selectors: [local],
|
|
78
|
+
styles: {
|
|
79
|
+
outline: `2px solid ${IMPACT_COLOR[expanded.impact] || "#1565c0"}`,
|
|
80
|
+
outlineOffset: "2px"
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
emit("storybook/highlight/remove", { id: HIGHLIGHT_ID });
|
|
85
|
+
}
|
|
86
|
+
}, [expandedIndex]);
|
|
87
|
+
const handleKeyDown = useCallback((e, index) => {
|
|
88
|
+
let next = null;
|
|
89
|
+
switch (e.key) {
|
|
90
|
+
case "ArrowDown":
|
|
91
|
+
next = Math.min(index + 1, sorted.length - 1);
|
|
92
|
+
break;
|
|
93
|
+
case "ArrowUp":
|
|
94
|
+
next = Math.max(index - 1, 0);
|
|
95
|
+
break;
|
|
96
|
+
case "Home":
|
|
97
|
+
next = 0;
|
|
98
|
+
break;
|
|
99
|
+
case "End":
|
|
100
|
+
next = sorted.length - 1;
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
buttonRefs.current[next]?.focus();
|
|
107
|
+
}, [sorted.length]);
|
|
108
|
+
if (!active) return null;
|
|
109
|
+
return /* @__PURE__ */ jsx(AddonPanel, { active, ...rest, children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", height: "100%", fontFamily: "system-ui, sans-serif" }, children: [
|
|
110
|
+
meta && /* @__PURE__ */ jsxs("div", { style: {
|
|
111
|
+
display: "flex",
|
|
112
|
+
gap: "12px",
|
|
113
|
+
padding: "8px 12px",
|
|
114
|
+
fontSize: "11px",
|
|
115
|
+
color: colors.textMuted,
|
|
116
|
+
borderBottom: `1px solid ${colors.border}`,
|
|
117
|
+
flexShrink: 0
|
|
118
|
+
}, children: [
|
|
119
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
120
|
+
meta.ruleCount,
|
|
121
|
+
" rules"
|
|
122
|
+
] }),
|
|
123
|
+
/* @__PURE__ */ jsxs("span", { style: { color: "#2e7d32" }, children: [
|
|
124
|
+
meta.passed,
|
|
125
|
+
" passed"
|
|
126
|
+
] }),
|
|
127
|
+
/* @__PURE__ */ jsxs("span", { style: { color: meta.failed > 0 ? "#d32f2f" : colors.textMuted }, children: [
|
|
128
|
+
meta.failed,
|
|
129
|
+
" failed"
|
|
130
|
+
] }),
|
|
131
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
132
|
+
meta.duration,
|
|
133
|
+
"ms"
|
|
134
|
+
] })
|
|
135
|
+
] }),
|
|
136
|
+
violations.length === 0 ? /* @__PURE__ */ jsx("p", { style: { padding: "12px", margin: 0, fontSize: "13px", color: colors.textMuted }, children: "No accessibility violations found." }) : /* @__PURE__ */ jsx("div", { style: { flex: 1, overflow: "auto", minHeight: 0 }, children: /* @__PURE__ */ jsx(
|
|
137
|
+
"ul",
|
|
138
|
+
{
|
|
139
|
+
style: { listStyle: "none", padding: 0, margin: 0 },
|
|
140
|
+
"aria-label": "Accessibility violations",
|
|
141
|
+
children: sorted.map((v, i) => {
|
|
142
|
+
const isOpen = expandedIndex === i;
|
|
143
|
+
return /* @__PURE__ */ jsxs("li", { style: { borderBottom: `1px solid ${colors.border}` }, children: [
|
|
144
|
+
/* @__PURE__ */ jsxs(
|
|
145
|
+
"button",
|
|
146
|
+
{
|
|
147
|
+
ref: (el) => {
|
|
148
|
+
buttonRefs.current[i] = el;
|
|
149
|
+
},
|
|
150
|
+
type: "button",
|
|
151
|
+
onClick: () => setExpandedIndex(isOpen ? null : i),
|
|
152
|
+
onKeyDown: (e) => handleKeyDown(e, i),
|
|
153
|
+
"aria-expanded": isOpen,
|
|
154
|
+
style: {
|
|
155
|
+
width: "100%",
|
|
156
|
+
padding: "8px 12px",
|
|
157
|
+
background: isOpen ? colors.bgSelected : "transparent",
|
|
158
|
+
border: "none",
|
|
159
|
+
font: "inherit",
|
|
160
|
+
fontSize: "12px",
|
|
161
|
+
textAlign: "left",
|
|
162
|
+
cursor: "pointer",
|
|
163
|
+
color: colors.text
|
|
164
|
+
},
|
|
165
|
+
children: [
|
|
166
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "6px" }, children: [
|
|
167
|
+
/* @__PURE__ */ jsx(
|
|
168
|
+
"span",
|
|
169
|
+
{
|
|
170
|
+
"aria-hidden": "true",
|
|
171
|
+
style: {
|
|
172
|
+
color: IMPACT_COLOR[v.impact],
|
|
173
|
+
fontWeight: "bold",
|
|
174
|
+
fontSize: "12px"
|
|
175
|
+
},
|
|
176
|
+
children: IMPACT_ICON[v.impact]
|
|
177
|
+
}
|
|
178
|
+
),
|
|
179
|
+
/* @__PURE__ */ jsx("span", { style: { color: IMPACT_COLOR[v.impact], fontSize: "11px" }, children: v.impact }),
|
|
180
|
+
/* @__PURE__ */ jsx("code", { style: { fontSize: "11px", color: colors.ruleId }, children: v.ruleId })
|
|
181
|
+
] }),
|
|
182
|
+
/* @__PURE__ */ jsx("div", { style: { marginTop: "2px", color: colors.text, fontSize: "12px" }, children: v.message })
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
),
|
|
186
|
+
isOpen && /* @__PURE__ */ jsxs("div", { style: { padding: "4px 12px 12px", background: colors.bgDetails }, children: [
|
|
187
|
+
v.description && /* @__PURE__ */ jsx("p", { style: { margin: "4px 0 8px", fontSize: "12px", color: colors.text }, children: v.description }),
|
|
188
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap", marginBottom: "8px" }, children: [
|
|
189
|
+
v.level && /* @__PURE__ */ jsxs("span", { style: {
|
|
190
|
+
display: "inline-block",
|
|
191
|
+
padding: "0 5px",
|
|
192
|
+
fontSize: "10px",
|
|
193
|
+
fontWeight: 600,
|
|
194
|
+
borderRadius: "3px",
|
|
195
|
+
color: "#fff",
|
|
196
|
+
background: LEVEL_COLOR[v.level] || "#666",
|
|
197
|
+
lineHeight: "18px"
|
|
198
|
+
}, children: [
|
|
199
|
+
"WCAG ",
|
|
200
|
+
v.level
|
|
201
|
+
] }),
|
|
202
|
+
v.wcag?.map((ref) => /* @__PURE__ */ jsx(
|
|
203
|
+
"span",
|
|
204
|
+
{
|
|
205
|
+
style: {
|
|
206
|
+
display: "inline-block",
|
|
207
|
+
padding: "0 5px",
|
|
208
|
+
fontSize: "10px",
|
|
209
|
+
fontWeight: 500,
|
|
210
|
+
borderRadius: "3px",
|
|
211
|
+
color: colors.tagText,
|
|
212
|
+
background: colors.tagBg,
|
|
213
|
+
lineHeight: "18px"
|
|
214
|
+
},
|
|
215
|
+
children: ref
|
|
216
|
+
},
|
|
217
|
+
ref
|
|
218
|
+
))
|
|
219
|
+
] }),
|
|
220
|
+
v.guidance && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
221
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: "11px", fontWeight: 500, color: colors.textMuted, marginBottom: "4px" }, children: "How to fix" }),
|
|
222
|
+
/* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "12px", color: colors.text, whiteSpace: "pre-wrap" }, children: v.guidance })
|
|
223
|
+
] }),
|
|
224
|
+
v.html && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
225
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: "11px", fontWeight: 500, color: colors.textMuted, marginBottom: "4px" }, children: "Element" }),
|
|
226
|
+
/* @__PURE__ */ jsx(
|
|
227
|
+
"pre",
|
|
228
|
+
{
|
|
229
|
+
style: {
|
|
230
|
+
margin: 0,
|
|
231
|
+
padding: "6px 8px",
|
|
232
|
+
fontSize: "11px",
|
|
233
|
+
color: colors.text,
|
|
234
|
+
background: colors.codeBg,
|
|
235
|
+
border: `1px solid ${colors.codeBorder}`,
|
|
236
|
+
borderRadius: "4px",
|
|
237
|
+
overflow: "auto",
|
|
238
|
+
whiteSpace: "pre-wrap",
|
|
239
|
+
wordBreak: "break-all"
|
|
240
|
+
},
|
|
241
|
+
children: v.html
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
] })
|
|
245
|
+
] })
|
|
246
|
+
] }, i);
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
) })
|
|
250
|
+
] }) });
|
|
251
|
+
};
|
|
252
|
+
var Title = () => {
|
|
253
|
+
const [violations] = useAddonState(ADDON_ID, []);
|
|
254
|
+
const count = violations.length;
|
|
255
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
256
|
+
"AccessLint",
|
|
257
|
+
count > 0 && /* @__PURE__ */ jsx("span", { style: {
|
|
258
|
+
display: "inline-block",
|
|
259
|
+
marginLeft: "8px",
|
|
260
|
+
minWidth: "18px",
|
|
261
|
+
padding: "0 5px",
|
|
262
|
+
lineHeight: "18px",
|
|
263
|
+
borderRadius: "9px",
|
|
264
|
+
fontSize: "11px",
|
|
265
|
+
fontWeight: "bold",
|
|
266
|
+
textAlign: "center",
|
|
267
|
+
background: "currentColor",
|
|
268
|
+
color: "inherit"
|
|
269
|
+
}, children: /* @__PURE__ */ jsx("span", { style: { color: "#fff" }, children: count }) })
|
|
270
|
+
] });
|
|
271
|
+
};
|
|
272
|
+
addons.register(ADDON_ID, () => {
|
|
273
|
+
addons.add(PANEL_ID, {
|
|
274
|
+
type: types.PANEL,
|
|
275
|
+
title: Title,
|
|
276
|
+
render: Panel
|
|
277
|
+
});
|
|
278
|
+
});
|
package/dist/preview.cjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var previewApi = require('storybook/internal/preview-api');
|
|
4
|
+
var core = require('@accesslint/core');
|
|
5
|
+
|
|
6
|
+
// src/preview.ts
|
|
7
|
+
|
|
8
|
+
// src/constants.ts
|
|
9
|
+
var ADDON_ID = "accesslint/a11y";
|
|
10
|
+
|
|
11
|
+
// src/preview.ts
|
|
12
|
+
core.configureRules({
|
|
13
|
+
disabledRules: ["accesslint-045"]
|
|
14
|
+
});
|
|
15
|
+
var decorator = (storyFn) => {
|
|
16
|
+
const story = storyFn();
|
|
17
|
+
setTimeout(async () => {
|
|
18
|
+
const start = performance.now();
|
|
19
|
+
const results = core.runAudit(document);
|
|
20
|
+
const duration = Math.round(performance.now() - start);
|
|
21
|
+
const root = document.getElementById("storybook-root");
|
|
22
|
+
const scoped = root ? results.violations.filter((v) => {
|
|
23
|
+
const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
24
|
+
try {
|
|
25
|
+
const el = document.querySelector(local);
|
|
26
|
+
return el && root.contains(el);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}) : results.violations;
|
|
31
|
+
const enriched = scoped.map((v) => {
|
|
32
|
+
const rule = core.getRuleById(v.ruleId);
|
|
33
|
+
return {
|
|
34
|
+
...v,
|
|
35
|
+
element: void 0,
|
|
36
|
+
// not serializable
|
|
37
|
+
description: rule?.description,
|
|
38
|
+
wcag: rule?.wcag,
|
|
39
|
+
level: rule?.level,
|
|
40
|
+
guidance: rule?.guidance
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const failedRuleIds = new Set(scoped.map((v) => v.ruleId));
|
|
44
|
+
const channel = previewApi.addons.getChannel();
|
|
45
|
+
channel.emit(`${ADDON_ID}/results`, enriched);
|
|
46
|
+
channel.emit(`${ADDON_ID}/meta`, {
|
|
47
|
+
duration,
|
|
48
|
+
ruleCount: results.ruleCount,
|
|
49
|
+
failed: failedRuleIds.size,
|
|
50
|
+
passed: results.ruleCount - failedRuleIds.size,
|
|
51
|
+
violations: scoped.length
|
|
52
|
+
});
|
|
53
|
+
}, 0);
|
|
54
|
+
return story;
|
|
55
|
+
};
|
|
56
|
+
var decorators = [decorator];
|
|
57
|
+
|
|
58
|
+
exports.decorators = decorators;
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { addons } from 'storybook/internal/preview-api';
|
|
2
|
+
import { configureRules, runAudit, getRuleById } from '@accesslint/core';
|
|
3
|
+
|
|
4
|
+
// src/preview.ts
|
|
5
|
+
|
|
6
|
+
// src/constants.ts
|
|
7
|
+
var ADDON_ID = "accesslint/a11y";
|
|
8
|
+
|
|
9
|
+
// src/preview.ts
|
|
10
|
+
configureRules({
|
|
11
|
+
disabledRules: ["accesslint-045"]
|
|
12
|
+
});
|
|
13
|
+
var decorator = (storyFn) => {
|
|
14
|
+
const story = storyFn();
|
|
15
|
+
setTimeout(async () => {
|
|
16
|
+
const start = performance.now();
|
|
17
|
+
const results = runAudit(document);
|
|
18
|
+
const duration = Math.round(performance.now() - start);
|
|
19
|
+
const root = document.getElementById("storybook-root");
|
|
20
|
+
const scoped = root ? results.violations.filter((v) => {
|
|
21
|
+
const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
|
|
22
|
+
try {
|
|
23
|
+
const el = document.querySelector(local);
|
|
24
|
+
return el && root.contains(el);
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}) : results.violations;
|
|
29
|
+
const enriched = scoped.map((v) => {
|
|
30
|
+
const rule = getRuleById(v.ruleId);
|
|
31
|
+
return {
|
|
32
|
+
...v,
|
|
33
|
+
element: void 0,
|
|
34
|
+
// not serializable
|
|
35
|
+
description: rule?.description,
|
|
36
|
+
wcag: rule?.wcag,
|
|
37
|
+
level: rule?.level,
|
|
38
|
+
guidance: rule?.guidance
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const failedRuleIds = new Set(scoped.map((v) => v.ruleId));
|
|
42
|
+
const channel = addons.getChannel();
|
|
43
|
+
channel.emit(`${ADDON_ID}/results`, enriched);
|
|
44
|
+
channel.emit(`${ADDON_ID}/meta`, {
|
|
45
|
+
duration,
|
|
46
|
+
ruleCount: results.ruleCount,
|
|
47
|
+
failed: failedRuleIds.size,
|
|
48
|
+
passed: results.ruleCount - failedRuleIds.size,
|
|
49
|
+
violations: scoped.length
|
|
50
|
+
});
|
|
51
|
+
}, 0);
|
|
52
|
+
return story;
|
|
53
|
+
};
|
|
54
|
+
var decorators = [decorator];
|
|
55
|
+
|
|
56
|
+
export { decorators };
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@accesslint/storybook-addon",
|
|
3
|
+
"version": "0.6.3",
|
|
4
|
+
"description": "Catch accessibility violations in your Storybook stories as you develop",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/AccessLint/core/issues"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./manager": "./dist/manager.js",
|
|
16
|
+
"./preview": {
|
|
17
|
+
"import": "./dist/preview.js",
|
|
18
|
+
"require": "./dist/preview.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"main": "dist/index.cjs",
|
|
22
|
+
"module": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/**/*",
|
|
26
|
+
"README.md",
|
|
27
|
+
"*.js",
|
|
28
|
+
"*.d.ts"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup",
|
|
32
|
+
"prepublishOnly": "node -e \"const fs = require('fs'); const v = JSON.parse(fs.readFileSync('node_modules/@accesslint/core/package.json','utf8')).version; const pkg = JSON.parse(fs.readFileSync('package.json','utf8')); pkg.version = v; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\\n');\"",
|
|
33
|
+
"build:watch": "tsup --watch",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@accesslint/core": "^0.6.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"react": "^18.2.0",
|
|
41
|
+
"react-dom": "^18.2.0",
|
|
42
|
+
"storybook": "^8.6.0",
|
|
43
|
+
"tsup": "^8.4.0",
|
|
44
|
+
"typescript": "^5.7.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"storybook": "^8.0.0"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"storybook-addon",
|
|
51
|
+
"accessibility",
|
|
52
|
+
"a11y",
|
|
53
|
+
"wcag",
|
|
54
|
+
"aria",
|
|
55
|
+
"accesslint",
|
|
56
|
+
"test",
|
|
57
|
+
"component",
|
|
58
|
+
"react",
|
|
59
|
+
"vue",
|
|
60
|
+
"angular",
|
|
61
|
+
"svelte",
|
|
62
|
+
"web-components"
|
|
63
|
+
],
|
|
64
|
+
"storybook": {
|
|
65
|
+
"displayName": "AccessLint",
|
|
66
|
+
"icon": "https://accesslint.com/icon.png"
|
|
67
|
+
},
|
|
68
|
+
"bundler": {
|
|
69
|
+
"nodeEntries": [
|
|
70
|
+
"./src/index.ts"
|
|
71
|
+
],
|
|
72
|
+
"managerEntries": [
|
|
73
|
+
"./src/manager.tsx"
|
|
74
|
+
],
|
|
75
|
+
"previewEntries": [
|
|
76
|
+
"./src/preview.ts"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|