@techsio/storybook-better-a11y 0.0.5 → 0.0.6
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/AccessibilityRuleMaps.js +532 -0
- package/dist/a11yRunner.js +105 -0
- package/dist/a11yRunner.test.js +21 -0
- package/dist/a11yRunnerUtils.js +30 -0
- package/dist/a11yRunnerUtils.test.js +61 -0
- package/dist/apcaChecker.js +288 -0
- package/dist/apcaChecker.test.js +124 -0
- package/dist/axeRuleMappingHelper.js +4 -0
- package/dist/components/A11YPanel.js +140 -0
- package/dist/components/A11YPanel.stories.js +198 -0
- package/dist/components/A11YPanel.test.js +110 -0
- package/dist/components/A11yContext.js +438 -0
- package/dist/components/A11yContext.test.js +277 -0
- package/dist/components/Report/Details.js +169 -0
- package/dist/components/Report/Report.js +106 -0
- package/dist/components/Report/Report.stories.js +86 -0
- package/dist/components/Tabs.js +54 -0
- package/dist/components/TestDiscrepancyMessage.js +55 -0
- package/dist/components/TestDiscrepancyMessage.stories.js +40 -0
- package/dist/components/VisionSimulator.js +83 -0
- package/dist/components/VisionSimulator.stories.js +56 -0
- package/dist/constants.js +25 -0
- package/dist/manager.test.js +86 -0
- package/dist/params.js +0 -0
- package/dist/preview.test.js +215 -0
- package/dist/results.mock.js +874 -0
- package/dist/types.js +6 -0
- package/dist/utils.js +21 -0
- package/dist/visionSimulatorFilters.js +100 -0
- package/dist/withVisionSimulator.js +41 -0
- package/package.json +1 -1
package/dist/types.js
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function getIsVitestStandaloneRun() {
|
|
2
|
+
try {
|
|
3
|
+
return 'false' === ({
|
|
4
|
+
MODE: "production",
|
|
5
|
+
DEV: false,
|
|
6
|
+
PROD: true,
|
|
7
|
+
BASE_URL: "/",
|
|
8
|
+
ASSET_PREFIX: "auto"
|
|
9
|
+
}).VITEST_STORYBOOK;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getIsVitestRunning() {
|
|
15
|
+
try {
|
|
16
|
+
return false;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export { getIsVitestRunning, getIsVitestStandaloneRun };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const filters = {
|
|
2
|
+
blurred: {
|
|
3
|
+
label: 'Blurred vision',
|
|
4
|
+
filter: 'blur(2px)',
|
|
5
|
+
percentage: 22.9
|
|
6
|
+
},
|
|
7
|
+
deuteranomaly: {
|
|
8
|
+
label: 'Deuteranomaly',
|
|
9
|
+
filter: 'url("#storybook-a11y-vision-deuteranomaly")',
|
|
10
|
+
percentage: 2.7
|
|
11
|
+
},
|
|
12
|
+
deuteranopia: {
|
|
13
|
+
label: 'Deuteranopia',
|
|
14
|
+
filter: 'url("#storybook-a11y-vision-deuteranopia")',
|
|
15
|
+
percentage: 0.56
|
|
16
|
+
},
|
|
17
|
+
protanomaly: {
|
|
18
|
+
label: 'Protanomaly',
|
|
19
|
+
filter: 'url("#storybook-a11y-vision-protanomaly")',
|
|
20
|
+
percentage: 0.66
|
|
21
|
+
},
|
|
22
|
+
protanopia: {
|
|
23
|
+
label: 'Protanopia',
|
|
24
|
+
filter: 'url("#storybook-a11y-vision-protanopia")',
|
|
25
|
+
percentage: 0.59
|
|
26
|
+
},
|
|
27
|
+
tritanomaly: {
|
|
28
|
+
label: 'Tritanomaly',
|
|
29
|
+
filter: 'url("#storybook-a11y-vision-tritanomaly")',
|
|
30
|
+
percentage: 0.01
|
|
31
|
+
},
|
|
32
|
+
tritanopia: {
|
|
33
|
+
label: 'Tritanopia',
|
|
34
|
+
filter: 'url("#storybook-a11y-vision-tritanopia")',
|
|
35
|
+
percentage: 0.016
|
|
36
|
+
},
|
|
37
|
+
achromatopsia: {
|
|
38
|
+
label: 'Achromatopsia',
|
|
39
|
+
filter: 'url("#storybook-a11y-vision-achromatopsia")',
|
|
40
|
+
percentage: 0.0001
|
|
41
|
+
},
|
|
42
|
+
grayscale: {
|
|
43
|
+
label: 'Grayscale',
|
|
44
|
+
filter: 'grayscale(100%)'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const filterDefs = `<svg id="storybook-a11y-vision-filters" style="display: none !important;">
|
|
48
|
+
<defs>
|
|
49
|
+
<filter id="storybook-a11y-vision-protanopia">
|
|
50
|
+
<feColorMatrix
|
|
51
|
+
in="SourceGraphic"
|
|
52
|
+
type="matrix"
|
|
53
|
+
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"
|
|
54
|
+
/>
|
|
55
|
+
</filter>
|
|
56
|
+
<filter id="storybook-a11y-vision-protanomaly">
|
|
57
|
+
<feColorMatrix
|
|
58
|
+
in="SourceGraphic"
|
|
59
|
+
type="matrix"
|
|
60
|
+
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"
|
|
61
|
+
/>
|
|
62
|
+
</filter>
|
|
63
|
+
<filter id="storybook-a11y-vision-deuteranopia">
|
|
64
|
+
<feColorMatrix
|
|
65
|
+
in="SourceGraphic"
|
|
66
|
+
type="matrix"
|
|
67
|
+
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"
|
|
68
|
+
/>
|
|
69
|
+
</filter>
|
|
70
|
+
<filter id="storybook-a11y-vision-deuteranomaly">
|
|
71
|
+
<feColorMatrix
|
|
72
|
+
in="SourceGraphic"
|
|
73
|
+
type="matrix"
|
|
74
|
+
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"
|
|
75
|
+
/>
|
|
76
|
+
</filter>
|
|
77
|
+
<filter id="storybook-a11y-vision-tritanopia">
|
|
78
|
+
<feColorMatrix
|
|
79
|
+
in="SourceGraphic"
|
|
80
|
+
type="matrix"
|
|
81
|
+
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"
|
|
82
|
+
/>
|
|
83
|
+
</filter>
|
|
84
|
+
<filter id="storybook-a11y-vision-tritanomaly">
|
|
85
|
+
<feColorMatrix
|
|
86
|
+
in="SourceGraphic"
|
|
87
|
+
type="matrix"
|
|
88
|
+
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"
|
|
89
|
+
/>
|
|
90
|
+
</filter>
|
|
91
|
+
<filter id="storybook-a11y-vision-achromatopsia">
|
|
92
|
+
<feColorMatrix
|
|
93
|
+
in="SourceGraphic"
|
|
94
|
+
type="matrix"
|
|
95
|
+
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"
|
|
96
|
+
/>
|
|
97
|
+
</filter>
|
|
98
|
+
</defs>
|
|
99
|
+
</svg>`;
|
|
100
|
+
export { filterDefs, filters };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useCallback, useEffect } from "storybook/preview-api";
|
|
2
|
+
import { filterDefs, filters } from "./visionSimulatorFilters.js";
|
|
3
|
+
const knownFilters = Object.values(filters).map((f)=>f.filter);
|
|
4
|
+
const knownFiltersRegExp = new RegExp(`\\b(${knownFilters.join('|')})\\b`, 'g');
|
|
5
|
+
const withVisionSimulator = (StoryFn, { globals })=>{
|
|
6
|
+
const { vision } = globals;
|
|
7
|
+
const applyVisionFilter = useCallback(()=>{
|
|
8
|
+
const existingFilters = document.body.style.filter.replaceAll(knownFiltersRegExp, '').trim();
|
|
9
|
+
const visionFilter = filters[vision]?.filter;
|
|
10
|
+
if (visionFilter && document.body.classList.contains('sb-show-main')) if (existingFilters && 'none' !== existingFilters) document.body.style.filter = `${existingFilters} ${visionFilter}`;
|
|
11
|
+
else document.body.style.filter = visionFilter;
|
|
12
|
+
else document.body.style.filter = existingFilters || 'none';
|
|
13
|
+
return ()=>document.body.style.filter = existingFilters || 'none';
|
|
14
|
+
}, [
|
|
15
|
+
vision
|
|
16
|
+
]);
|
|
17
|
+
useEffect(()=>{
|
|
18
|
+
const cleanup = applyVisionFilter();
|
|
19
|
+
const observer = new MutationObserver(()=>applyVisionFilter());
|
|
20
|
+
observer.observe(document.body, {
|
|
21
|
+
attributeFilter: [
|
|
22
|
+
'class'
|
|
23
|
+
]
|
|
24
|
+
});
|
|
25
|
+
return ()=>{
|
|
26
|
+
cleanup();
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
};
|
|
29
|
+
}, [
|
|
30
|
+
applyVisionFilter
|
|
31
|
+
]);
|
|
32
|
+
useEffect(()=>{
|
|
33
|
+
document.body.insertAdjacentHTML('beforeend', filterDefs);
|
|
34
|
+
return ()=>{
|
|
35
|
+
const filterDefsElement = document.getElementById('storybook-a11y-vision-filters');
|
|
36
|
+
filterDefsElement?.parentElement?.removeChild(filterDefsElement);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
return StoryFn();
|
|
40
|
+
};
|
|
41
|
+
export { withVisionSimulator };
|