@techsio/storybook-better-a11y 0.0.5 → 0.0.7

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/dist/100.js ADDED
@@ -0,0 +1,122 @@
1
+ const ADDON_ID = 'storybook/a11y';
2
+ const PANEL_ID = `${ADDON_ID}/panel`;
3
+ "a11y";
4
+ "vision";
5
+ const RESULT = `${ADDON_ID}/result`;
6
+ const REQUEST = `${ADDON_ID}/request`;
7
+ const RUNNING = `${ADDON_ID}/running`;
8
+ const ERROR = `${ADDON_ID}/error`;
9
+ const MANUAL = `${ADDON_ID}/manual`;
10
+ const SELECT = `${ADDON_ID}/select`;
11
+ const DOCUMENTATION_LINK = 'writing-tests/accessibility-testing';
12
+ const DOCUMENTATION_DISCREPANCY_LINK = `${DOCUMENTATION_LINK}#why-are-my-tests-failing-in-different-environments`;
13
+ const EVENTS = {
14
+ RESULT: RESULT,
15
+ REQUEST: REQUEST,
16
+ RUNNING: RUNNING,
17
+ ERROR: ERROR,
18
+ MANUAL: MANUAL,
19
+ SELECT: SELECT
20
+ };
21
+ const STATUS_TYPE_ID_COMPONENT_TEST = 'storybook/component-test';
22
+ const STATUS_TYPE_ID_A11Y = 'storybook/a11y';
23
+ const filters = {
24
+ blurred: {
25
+ label: 'Blurred vision',
26
+ filter: 'blur(2px)',
27
+ percentage: 22.9
28
+ },
29
+ deuteranomaly: {
30
+ label: 'Deuteranomaly',
31
+ filter: 'url("#storybook-a11y-vision-deuteranomaly")',
32
+ percentage: 2.7
33
+ },
34
+ deuteranopia: {
35
+ label: 'Deuteranopia',
36
+ filter: 'url("#storybook-a11y-vision-deuteranopia")',
37
+ percentage: 0.56
38
+ },
39
+ protanomaly: {
40
+ label: 'Protanomaly',
41
+ filter: 'url("#storybook-a11y-vision-protanomaly")',
42
+ percentage: 0.66
43
+ },
44
+ protanopia: {
45
+ label: 'Protanopia',
46
+ filter: 'url("#storybook-a11y-vision-protanopia")',
47
+ percentage: 0.59
48
+ },
49
+ tritanomaly: {
50
+ label: 'Tritanomaly',
51
+ filter: 'url("#storybook-a11y-vision-tritanomaly")',
52
+ percentage: 0.01
53
+ },
54
+ tritanopia: {
55
+ label: 'Tritanopia',
56
+ filter: 'url("#storybook-a11y-vision-tritanopia")',
57
+ percentage: 0.016
58
+ },
59
+ achromatopsia: {
60
+ label: 'Achromatopsia',
61
+ filter: 'url("#storybook-a11y-vision-achromatopsia")',
62
+ percentage: 0.0001
63
+ },
64
+ grayscale: {
65
+ label: 'Grayscale',
66
+ filter: 'grayscale(100%)'
67
+ }
68
+ };
69
+ const filterDefs = `<svg id="storybook-a11y-vision-filters" style="display: none !important;">
70
+ <defs>
71
+ <filter id="storybook-a11y-vision-protanopia">
72
+ <feColorMatrix
73
+ in="SourceGraphic"
74
+ type="matrix"
75
+ values="0.567, 0.433, 0, 0, 0 0.558, 0.442, 0, 0, 0 0, 0.242, 0.758, 0, 0 0, 0, 0, 1, 0"
76
+ />
77
+ </filter>
78
+ <filter id="storybook-a11y-vision-protanomaly">
79
+ <feColorMatrix
80
+ in="SourceGraphic"
81
+ type="matrix"
82
+ values="0.817, 0.183, 0, 0, 0 0.333, 0.667, 0, 0, 0 0, 0.125, 0.875, 0, 0 0, 0, 0, 1, 0"
83
+ />
84
+ </filter>
85
+ <filter id="storybook-a11y-vision-deuteranopia">
86
+ <feColorMatrix
87
+ in="SourceGraphic"
88
+ type="matrix"
89
+ values="0.625, 0.375, 0, 0, 0 0.7, 0.3, 0, 0, 0 0, 0.3, 0.7, 0, 0 0, 0, 0, 1, 0"
90
+ />
91
+ </filter>
92
+ <filter id="storybook-a11y-vision-deuteranomaly">
93
+ <feColorMatrix
94
+ in="SourceGraphic"
95
+ type="matrix"
96
+ values="0.8, 0.2, 0, 0, 0 0.258, 0.742, 0, 0, 0 0, 0.142, 0.858, 0, 0 0, 0, 0, 1, 0"
97
+ />
98
+ </filter>
99
+ <filter id="storybook-a11y-vision-tritanopia">
100
+ <feColorMatrix
101
+ in="SourceGraphic"
102
+ type="matrix"
103
+ values="0.95, 0.05, 0, 0, 0 0, 0.433, 0.567, 0, 0 0, 0.475, 0.525, 0, 0 0, 0, 0, 1, 0"
104
+ />
105
+ </filter>
106
+ <filter id="storybook-a11y-vision-tritanomaly">
107
+ <feColorMatrix
108
+ in="SourceGraphic"
109
+ type="matrix"
110
+ values="0.967, 0.033, 0, 0, 0 0, 0.733, 0.267, 0, 0 0, 0.183, 0.817, 0, 0 0, 0, 0, 1, 0"
111
+ />
112
+ </filter>
113
+ <filter id="storybook-a11y-vision-achromatopsia">
114
+ <feColorMatrix
115
+ in="SourceGraphic"
116
+ type="matrix"
117
+ values="0.299, 0.587, 0.114, 0, 0 0.299, 0.587, 0.114, 0, 0 0.299, 0.587, 0.114, 0, 0 0, 0, 0, 1, 0"
118
+ />
119
+ </filter>
120
+ </defs>
121
+ </svg>`;
122
+ export { ADDON_ID, DOCUMENTATION_DISCREPANCY_LINK, EVENTS, PANEL_ID, STATUS_TYPE_ID_A11Y, STATUS_TYPE_ID_COMPONENT_TEST, filterDefs, filters };
package/dist/699.js ADDED
@@ -0,0 +1,540 @@
1
+ import { __webpack_require__ } from "./rslib-runtime.js";
2
+ import { expect } from "storybook/test";
3
+ import { ElementA11yParameterError } from "storybook/internal/preview-errors";
4
+ import { global } from "@storybook/global";
5
+ import { addons, useCallback, useEffect, waitForAnimations } from "storybook/preview-api";
6
+ import { EVENTS, filters, filterDefs, PANEL_ID } from "./100.js";
7
+ var preview_namespaceObject = {};
8
+ __webpack_require__.r(preview_namespaceObject);
9
+ __webpack_require__.d(preview_namespaceObject, {
10
+ afterEach: ()=>afterEach,
11
+ decorators: ()=>decorators,
12
+ initialGlobals: ()=>initialGlobals,
13
+ parameters: ()=>preview_parameters
14
+ });
15
+ const { document: a11yRunnerUtils_document } = global;
16
+ const withLinkPaths = (results, storyId)=>{
17
+ const pathname = a11yRunnerUtils_document.location.pathname.replace(/iframe\.html$/, '');
18
+ const enhancedResults = {
19
+ ...results
20
+ };
21
+ const propertiesToAugment = [
22
+ 'incomplete',
23
+ 'passes',
24
+ 'violations'
25
+ ];
26
+ propertiesToAugment.forEach((key)=>{
27
+ if (Array.isArray(results[key])) enhancedResults[key] = results[key].map((result)=>({
28
+ ...result,
29
+ nodes: result.nodes.map((node, index)=>{
30
+ const id = `${key}.${result.id}.${index + 1}`;
31
+ const linkPath = `${pathname}?path=/story/${storyId}&addonPanel=${PANEL_ID}&a11ySelection=${id}`;
32
+ return {
33
+ id,
34
+ ...node,
35
+ linkPath
36
+ };
37
+ })
38
+ }));
39
+ });
40
+ return enhancedResults;
41
+ };
42
+ const { document: apcaChecker_document } = global;
43
+ const DEFAULT_APCA_OPTIONS = {
44
+ level: 'bronze',
45
+ useCase: 'body'
46
+ };
47
+ const APCA_LC_STEPS = [
48
+ 15,
49
+ 20,
50
+ 25,
51
+ 30,
52
+ 35,
53
+ 40,
54
+ 45,
55
+ 50,
56
+ 55,
57
+ 60,
58
+ 65,
59
+ 70,
60
+ 75,
61
+ 80,
62
+ 85,
63
+ 90,
64
+ 95,
65
+ 100,
66
+ 105,
67
+ 110,
68
+ 115,
69
+ 120,
70
+ 125
71
+ ];
72
+ const APCA_MAX_CONTRAST_LC = 90;
73
+ function getComputedColor(element, property) {
74
+ const computed = global.getComputedStyle(element);
75
+ return computed[property] || '';
76
+ }
77
+ function getEffectiveBackgroundColor(element) {
78
+ let current = element;
79
+ while(current && current !== apcaChecker_document.body){
80
+ const bgColor = getComputedColor(current, 'backgroundColor');
81
+ if (bgColor && 'rgba(0, 0, 0, 0)' !== bgColor && 'transparent' !== bgColor) return bgColor;
82
+ current = current.parentElement;
83
+ }
84
+ return 'rgb(255, 255, 255)';
85
+ }
86
+ function parseColor(color) {
87
+ const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
88
+ if (!match) return null;
89
+ return [
90
+ parseInt(match[1], 10),
91
+ parseInt(match[2], 10),
92
+ parseInt(match[3], 10)
93
+ ];
94
+ }
95
+ function normalizeUseCase(value, fallback) {
96
+ if (!value) return fallback;
97
+ const normalized = value.toLowerCase().replace(/\s+/g, '-');
98
+ if (normalized.includes('body')) return 'body';
99
+ if (normalized.includes('sub') || normalized.includes('logo')) return 'sub-fluent';
100
+ if (normalized.includes('non') || normalized.includes('incidental') || normalized.includes('spot')) return 'non-fluent';
101
+ if (normalized.includes('fluent')) return 'fluent';
102
+ return fallback;
103
+ }
104
+ function getUseCaseForElement(element, fallback) {
105
+ const attr = element.getAttribute('data-apca-usecase') ?? element.getAttribute('data-apca-use-case') ?? element.getAttribute('data-apca-usage');
106
+ return normalizeUseCase(attr, fallback);
107
+ }
108
+ function normalizeWeightBucket(fontWeight) {
109
+ const weight = Number.isFinite(fontWeight) ? fontWeight : 400;
110
+ const clamped = Math.max(100, Math.min(900, weight));
111
+ return 100 * Math.round(clamped / 100);
112
+ }
113
+ function getBronzeThreshold(useCase, fontSize) {
114
+ if ('body' === useCase) return {
115
+ threshold: 75,
116
+ preferred: 90
117
+ };
118
+ if ('fluent' === useCase) {
119
+ if (fontSize > 32) return {
120
+ threshold: 45
121
+ };
122
+ if (fontSize >= 16) return {
123
+ threshold: 60
124
+ };
125
+ return {
126
+ threshold: 75
127
+ };
128
+ }
129
+ return null;
130
+ }
131
+ function getMinFontSize(level, useCase) {
132
+ if ('bronze' === level) return;
133
+ if ('sub-fluent' === useCase) return 'gold' === level ? 12 : 10;
134
+ if ('fluent' === useCase || 'body' === useCase) return 'gold' === level ? 16 : 14;
135
+ }
136
+ function getMaxContrast(level, useCase, fontSize, fontWeight) {
137
+ if ('bronze' === level) {
138
+ if ('fluent' === useCase && fontSize > 32 && fontWeight >= 700) return APCA_MAX_CONTRAST_LC;
139
+ return;
140
+ }
141
+ if (('body' === useCase || 'fluent' === useCase) && fontSize > 36) return APCA_MAX_CONTRAST_LC;
142
+ }
143
+ function getBaseThresholdFromLookup(fontSize, fontWeight, allowNonContent, fontLookupAPCA) {
144
+ const weightBucket = normalizeWeightBucket(fontWeight);
145
+ const weightIndex = Math.round(weightBucket / 100);
146
+ for (const lc of APCA_LC_STEPS){
147
+ const row = fontLookupAPCA(lc, 2);
148
+ const requiredSize = Number(row[weightIndex]);
149
+ if (!Number.isFinite(requiredSize)) continue;
150
+ if (999 === requiredSize) continue;
151
+ if (777 === requiredSize && !allowNonContent) continue;
152
+ const minSize = 777 === requiredSize ? 0 : requiredSize;
153
+ if (fontSize >= minSize) return lc;
154
+ }
155
+ return null;
156
+ }
157
+ function getApcaThreshold(level, useCase, fontSize, fontWeight, fontLookupAPCA) {
158
+ if ('bronze' === level) {
159
+ const bronzeThreshold = getBronzeThreshold(useCase, fontSize);
160
+ if (!bronzeThreshold) return {
161
+ threshold: null,
162
+ skip: true
163
+ };
164
+ return {
165
+ threshold: bronzeThreshold.threshold,
166
+ maxContrast: getMaxContrast(level, useCase, fontSize, fontWeight)
167
+ };
168
+ }
169
+ const minFontSize = getMinFontSize(level, useCase);
170
+ const baseThreshold = getBaseThresholdFromLookup(fontSize, fontWeight, 'non-fluent' === useCase, fontLookupAPCA);
171
+ if (null === baseThreshold) return {
172
+ threshold: null,
173
+ minFontSize,
174
+ note: 'Font size/weight is below the minimums in the APCA lookup table for this use case.'
175
+ };
176
+ let threshold = baseThreshold;
177
+ if ('sub-fluent' === useCase) threshold = Math.max(threshold - 15, 'silver' === level ? 40 : 45);
178
+ else if ('non-fluent' === useCase) threshold = Math.max(threshold - ('silver' === level ? 30 : 20), 30);
179
+ if ('body' === useCase && 'gold' === level && threshold < 75) threshold += 15;
180
+ return {
181
+ threshold,
182
+ minFontSize,
183
+ maxContrast: getMaxContrast(level, useCase, fontSize, fontWeight)
184
+ };
185
+ }
186
+ function hasReadableText(element) {
187
+ const text = element.textContent?.trim() || '';
188
+ return text.length > 0 && !element.hasAttribute('aria-hidden');
189
+ }
190
+ function isVisible(element) {
191
+ const computed = global.getComputedStyle(element);
192
+ return 'none' !== computed.display && 'hidden' !== computed.visibility && '0' !== computed.opacity;
193
+ }
194
+ async function runAPCACheck(context = apcaChecker_document, options = DEFAULT_APCA_OPTIONS, excludeSelectors = []) {
195
+ const { APCAcontrast, sRGBtoY, fontLookupAPCA } = await import("apca-w3");
196
+ const apcaOptions = {
197
+ ...DEFAULT_APCA_OPTIONS,
198
+ ...options
199
+ };
200
+ const violations = [];
201
+ const root = context instanceof Document ? context.body : context;
202
+ const textElements = root.querySelectorAll('p, span, div, h1, h2, h3, h4, h5, h6, a, button, label, td, th, li, input, textarea');
203
+ textElements.forEach((element)=>{
204
+ if (excludeSelectors.length > 0) {
205
+ const isExcluded = excludeSelectors.some((selector)=>{
206
+ try {
207
+ return null !== element.closest(selector);
208
+ } catch {
209
+ return false;
210
+ }
211
+ });
212
+ if (isExcluded) return;
213
+ }
214
+ if (!isVisible(element) || !hasReadableText(element)) return;
215
+ const foreground = getComputedColor(element, 'color');
216
+ const background = getEffectiveBackgroundColor(element);
217
+ const fgColor = parseColor(foreground);
218
+ const bgColor = parseColor(background);
219
+ if (!fgColor || !bgColor) return;
220
+ const computed = global.getComputedStyle(element);
221
+ const fontSize = parseFloat(computed.fontSize);
222
+ const fontWeight = parseInt(computed.fontWeight, 10);
223
+ try {
224
+ const fgLuminance = sRGBtoY(fgColor);
225
+ const bgLuminance = sRGBtoY(bgColor);
226
+ const contrastValue = Math.abs(APCAcontrast(fgLuminance, bgLuminance));
227
+ const useCase = getUseCaseForElement(element, apcaOptions.useCase);
228
+ const level = apcaOptions.level;
229
+ const { threshold, minFontSize, maxContrast, note, skip } = getApcaThreshold(level, useCase, fontSize, fontWeight, fontLookupAPCA);
230
+ if (skip) return;
231
+ const messages = [];
232
+ if (null === threshold) {
233
+ if (note) messages.push(note);
234
+ } else {
235
+ if (contrastValue < threshold) messages.push(`APCA contrast of ${contrastValue.toFixed(1)} Lc is below the minimum of ${threshold} Lc for ${level} ${useCase} text.`);
236
+ if (void 0 !== maxContrast && contrastValue > maxContrast) messages.push(`APCA contrast of ${contrastValue.toFixed(1)} Lc exceeds the maximum of ${maxContrast} Lc for ${level} ${useCase} text at ${fontSize.toFixed(1)}px.`);
237
+ }
238
+ if (minFontSize && fontSize < minFontSize) messages.push(`Font size ${fontSize.toFixed(1)}px is below the minimum ${minFontSize}px for ${level} ${useCase} text.`);
239
+ if (messages.length > 0) violations.push({
240
+ element,
241
+ foreground,
242
+ background,
243
+ contrastValue,
244
+ fontSize,
245
+ fontWeight,
246
+ threshold,
247
+ maxContrast,
248
+ useCase,
249
+ level,
250
+ minFontSize,
251
+ note
252
+ });
253
+ } catch (error) {
254
+ console.warn('APCA calculation error:', error);
255
+ }
256
+ });
257
+ const nodes = violations.map((violation)=>{
258
+ const impact = getImpact(violation.contrastValue, violation.threshold, violation.maxContrast);
259
+ const messages = [];
260
+ if (violation.note) messages.push(violation.note);
261
+ else if (null !== violation.threshold && violation.contrastValue < violation.threshold) messages.push(`APCA contrast of ${violation.contrastValue.toFixed(1)} Lc is below the minimum of ${violation.threshold} Lc for ${violation.level} ${violation.useCase} text.`);
262
+ if (void 0 !== violation.maxContrast && violation.contrastValue > violation.maxContrast) messages.push(`APCA contrast of ${violation.contrastValue.toFixed(1)} Lc exceeds the maximum of ${violation.maxContrast} Lc for ${violation.level} ${violation.useCase} text at ${violation.fontSize.toFixed(1)}px.`);
263
+ if (violation.minFontSize && violation.fontSize < violation.minFontSize) messages.push(`Font size ${violation.fontSize.toFixed(1)}px is below the minimum ${violation.minFontSize}px for ${violation.level} ${violation.useCase} text.`);
264
+ const rules = messages.map((message)=>({
265
+ id: 'apca-contrast',
266
+ impact,
267
+ message,
268
+ data: null,
269
+ relatedNodes: []
270
+ }));
271
+ const failureSummary = `Fix any of the following:\n ${messages.join('\n ')}`;
272
+ return {
273
+ html: violation.element.outerHTML,
274
+ target: [
275
+ getSelector(violation.element)
276
+ ],
277
+ any: rules,
278
+ all: [],
279
+ none: [],
280
+ impact,
281
+ failureSummary
282
+ };
283
+ });
284
+ return {
285
+ id: 'apca-contrast',
286
+ impact: nodes.length > 0 ? 'serious' : null,
287
+ tags: [
288
+ 'wcag3',
289
+ 'wcag30',
290
+ 'apca',
291
+ 'contrast'
292
+ ],
293
+ description: 'Ensures text has sufficient contrast using APCA (WCAG 3.0 method)',
294
+ help: 'Elements must have sufficient color contrast using APCA',
295
+ helpUrl: 'https://git.apcacontrast.com/',
296
+ nodes
297
+ };
298
+ }
299
+ function getSelector(element) {
300
+ if (element.id) return `#${element.id}`;
301
+ const path = [];
302
+ let current = element;
303
+ while(current && current !== apcaChecker_document.body){
304
+ let selector = current.tagName.toLowerCase();
305
+ if (current.className) {
306
+ const classes = current.className.split(' ').filter(Boolean);
307
+ if (classes.length > 0) selector += `.${classes[0]}`;
308
+ }
309
+ const parent = current.parentElement;
310
+ if (parent) {
311
+ const siblings = Array.from(parent.children);
312
+ const index = siblings.indexOf(current) + 1;
313
+ selector += `:nth-child(${index})`;
314
+ }
315
+ path.unshift(selector);
316
+ current = parent;
317
+ }
318
+ return path.join(' > ');
319
+ }
320
+ function getImpact(contrastValue, threshold, maxContrast) {
321
+ if (null === threshold && void 0 === maxContrast) return 'serious';
322
+ const difference = void 0 !== maxContrast && contrastValue > maxContrast ? contrastValue - maxContrast : (threshold ?? 0) - contrastValue;
323
+ if (difference > 30) return 'critical';
324
+ if (difference > 20) return 'serious';
325
+ if (difference > 10) return 'moderate';
326
+ return 'minor';
327
+ }
328
+ const { document: a11yRunner_document } = global;
329
+ const channel = addons.getChannel();
330
+ const DEFAULT_PARAMETERS = {
331
+ config: {},
332
+ options: {}
333
+ };
334
+ const DISABLED_RULES = [
335
+ 'region'
336
+ ];
337
+ const queue = [];
338
+ let isRunning = false;
339
+ const runNext = async ()=>{
340
+ if (0 === queue.length) {
341
+ isRunning = false;
342
+ return;
343
+ }
344
+ isRunning = true;
345
+ const next = queue.shift();
346
+ if (next) await next();
347
+ runNext();
348
+ };
349
+ const run = async (input = DEFAULT_PARAMETERS, storyId)=>{
350
+ const axeCore = await import("axe-core");
351
+ const axe = axeCore?.default || globalThis.axe;
352
+ const { config = {}, options = {} } = input;
353
+ if (input.element) throw new ElementA11yParameterError();
354
+ const context = {
355
+ include: a11yRunner_document?.body,
356
+ exclude: [
357
+ '.sb-wrapper',
358
+ '#storybook-docs',
359
+ '#storybook-highlights-root'
360
+ ]
361
+ };
362
+ if (input.context) {
363
+ const hasInclude = 'object' == typeof input.context && 'include' in input.context && void 0 !== input.context.include;
364
+ const hasExclude = 'object' == typeof input.context && 'exclude' in input.context && void 0 !== input.context.exclude;
365
+ if (hasInclude) context.include = input.context.include;
366
+ else if (!hasInclude && !hasExclude) context.include = input.context;
367
+ if (hasExclude) context.exclude = context.exclude.concat(input.context.exclude);
368
+ }
369
+ axe.reset();
370
+ const configWithDefault = {
371
+ ...config,
372
+ rules: [
373
+ ...DISABLED_RULES.map((id)=>({
374
+ id,
375
+ enabled: false
376
+ })),
377
+ ...config?.rules ?? []
378
+ ]
379
+ };
380
+ axe.configure(configWithDefault);
381
+ return new Promise((resolve, reject)=>{
382
+ const highlightsRoot = a11yRunner_document?.getElementById('storybook-highlights-root');
383
+ if (highlightsRoot) highlightsRoot.style.display = 'none';
384
+ const task = async ()=>{
385
+ try {
386
+ const result = await axe.run(context, options);
387
+ let contextElement = a11yRunner_document;
388
+ if (context.include instanceof Element) contextElement = context.include;
389
+ else if (Array.isArray(context.include)) {
390
+ const first = context.include[0];
391
+ if (first instanceof Element) contextElement = first;
392
+ else if ('string' == typeof first) contextElement = a11yRunner_document.querySelector(first) || a11yRunner_document;
393
+ } else if ('string' == typeof context.include) contextElement = a11yRunner_document.querySelector(context.include) || a11yRunner_document;
394
+ const excludeSelectors = Array.isArray(context.exclude) ? context.exclude.filter((value)=>'string' == typeof value) : 'string' == typeof context.exclude ? [
395
+ context.exclude
396
+ ] : [];
397
+ const apcaResult = await runAPCACheck(contextElement, input.apca, excludeSelectors);
398
+ if (apcaResult.nodes.length > 0) result.violations.push(apcaResult);
399
+ else result.passes.push(apcaResult);
400
+ const resultWithLinks = withLinkPaths(result, storyId);
401
+ globalThis.__TECHSIO_A11Y_RESULTS__ = {
402
+ storyId,
403
+ results: resultWithLinks,
404
+ timestamp: Date.now()
405
+ };
406
+ resolve(resultWithLinks);
407
+ } catch (error) {
408
+ reject(error);
409
+ }
410
+ };
411
+ queue.push(task);
412
+ if (!isRunning) runNext();
413
+ if (highlightsRoot) highlightsRoot.style.display = '';
414
+ });
415
+ };
416
+ channel.on(EVENTS.MANUAL, async (storyId, input = DEFAULT_PARAMETERS)=>{
417
+ try {
418
+ await waitForAnimations();
419
+ const result = await run(input, storyId);
420
+ const resultJson = JSON.parse(JSON.stringify(result));
421
+ channel.emit(EVENTS.RESULT, resultJson, storyId);
422
+ } catch (error) {
423
+ channel.emit(EVENTS.ERROR, error);
424
+ }
425
+ });
426
+ function getIsVitestStandaloneRun() {
427
+ try {
428
+ return 'false' === ({
429
+ MODE: "production",
430
+ DEV: false,
431
+ PROD: true,
432
+ BASE_URL: "/",
433
+ ASSET_PREFIX: "auto"
434
+ }).VITEST_STORYBOOK;
435
+ } catch (e) {
436
+ return false;
437
+ }
438
+ }
439
+ const knownFilters = Object.values(filters).map((f)=>f.filter);
440
+ const knownFiltersRegExp = new RegExp(`\\b(${knownFilters.join('|')})\\b`, 'g');
441
+ const withVisionSimulator = (StoryFn, { globals })=>{
442
+ const { vision } = globals;
443
+ const applyVisionFilter = useCallback(()=>{
444
+ const existingFilters = document.body.style.filter.replaceAll(knownFiltersRegExp, '').trim();
445
+ const visionFilter = filters[vision]?.filter;
446
+ if (visionFilter && document.body.classList.contains('sb-show-main')) if (existingFilters && 'none' !== existingFilters) document.body.style.filter = `${existingFilters} ${visionFilter}`;
447
+ else document.body.style.filter = visionFilter;
448
+ else document.body.style.filter = existingFilters || 'none';
449
+ return ()=>document.body.style.filter = existingFilters || 'none';
450
+ }, [
451
+ vision
452
+ ]);
453
+ useEffect(()=>{
454
+ const cleanup = applyVisionFilter();
455
+ const observer = new MutationObserver(()=>applyVisionFilter());
456
+ observer.observe(document.body, {
457
+ attributeFilter: [
458
+ 'class'
459
+ ]
460
+ });
461
+ return ()=>{
462
+ cleanup();
463
+ observer.disconnect();
464
+ };
465
+ }, [
466
+ applyVisionFilter
467
+ ]);
468
+ useEffect(()=>{
469
+ document.body.insertAdjacentHTML('beforeend', filterDefs);
470
+ return ()=>{
471
+ const filterDefsElement = document.getElementById('storybook-a11y-vision-filters');
472
+ filterDefsElement?.parentElement?.removeChild(filterDefsElement);
473
+ };
474
+ }, []);
475
+ return StoryFn();
476
+ };
477
+ let vitestMatchersExtended = false;
478
+ const decorators = [
479
+ withVisionSimulator
480
+ ];
481
+ const afterEach = async ({ id: storyId, reporting, parameters, globals, viewMode })=>{
482
+ const a11yParameter = parameters.a11y;
483
+ const a11yGlobals = globals.a11y;
484
+ const shouldRunEnvironmentIndependent = a11yParameter?.disable !== true && a11yParameter?.test !== 'off' && a11yGlobals?.manual !== true;
485
+ const getMode = ()=>{
486
+ switch(a11yParameter?.test){
487
+ case 'todo':
488
+ return 'warning';
489
+ case 'error':
490
+ default:
491
+ return 'failed';
492
+ }
493
+ };
494
+ if (shouldRunEnvironmentIndependent && 'story' === viewMode) try {
495
+ const result = await run(a11yParameter, storyId);
496
+ if (result) {
497
+ const hasViolations = (result?.violations.length ?? 0) > 0;
498
+ reporting.addReport({
499
+ type: 'a11y',
500
+ version: 1,
501
+ result,
502
+ status: hasViolations ? getMode() : 'passed'
503
+ });
504
+ if (getIsVitestStandaloneRun()) {
505
+ if (hasViolations && 'failed' === getMode()) {
506
+ if (!vitestMatchersExtended) {
507
+ const { toHaveNoViolations } = await import("vitest-axe/matchers");
508
+ expect.extend({
509
+ toHaveNoViolations
510
+ });
511
+ vitestMatchersExtended = true;
512
+ }
513
+ expect(result).toHaveNoViolations();
514
+ }
515
+ }
516
+ }
517
+ } catch (e) {
518
+ reporting.addReport({
519
+ type: 'a11y',
520
+ version: 1,
521
+ result: {
522
+ error: e
523
+ },
524
+ status: 'failed'
525
+ });
526
+ if (getIsVitestStandaloneRun()) throw e;
527
+ }
528
+ };
529
+ const initialGlobals = {
530
+ a11y: {
531
+ manual: false
532
+ },
533
+ vision: void 0
534
+ };
535
+ const preview_parameters = {
536
+ a11y: {
537
+ test: 'todo'
538
+ }
539
+ };
540
+ export { afterEach, decorators, initialGlobals, preview_namespaceObject, preview_parameters as parameters };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { definePreviewAddon } from "storybook/internal/csf";
2
- import { PARAM_KEY } from "./constants.js";
3
- export * from "./params.js";
4
- import * as __rspack_external__preview_js_3b21eac2 from "./preview.js";
5
- const src = ()=>definePreviewAddon(__rspack_external__preview_js_3b21eac2);
6
- export { PARAM_KEY, src as default };
2
+ import { preview_namespaceObject } from "./699.js";
3
+ import "./100.js";
4
+ const src = ()=>definePreviewAddon(preview_namespaceObject);
5
+ var src_PARAM_KEY = "a11y";
6
+ export default src;
7
+ export { src_PARAM_KEY as PARAM_KEY };