@techsio/storybook-better-a11y 0.0.4 → 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.
Files changed (38) hide show
  1. package/dist/AccessibilityRuleMaps.js +532 -0
  2. package/dist/a11yRunner.js +105 -0
  3. package/dist/a11yRunner.test.js +21 -0
  4. package/dist/a11yRunnerUtils.js +30 -0
  5. package/dist/a11yRunnerUtils.test.js +61 -0
  6. package/dist/{699.js → apcaChecker.js} +1 -255
  7. package/dist/apcaChecker.test.js +124 -0
  8. package/dist/axeRuleMappingHelper.js +4 -0
  9. package/dist/components/A11YPanel.js +140 -0
  10. package/dist/components/A11YPanel.stories.js +198 -0
  11. package/dist/components/A11YPanel.test.js +110 -0
  12. package/dist/components/A11yContext.js +438 -0
  13. package/dist/components/A11yContext.test.js +277 -0
  14. package/dist/components/Report/Details.js +169 -0
  15. package/dist/components/Report/Report.js +106 -0
  16. package/dist/components/Report/Report.stories.js +86 -0
  17. package/dist/components/Tabs.js +54 -0
  18. package/dist/components/TestDiscrepancyMessage.js +55 -0
  19. package/dist/components/TestDiscrepancyMessage.stories.js +40 -0
  20. package/dist/components/VisionSimulator.js +83 -0
  21. package/dist/components/VisionSimulator.stories.js +56 -0
  22. package/dist/constants.js +25 -0
  23. package/dist/index.js +5 -6
  24. package/dist/manager.js +11 -1540
  25. package/dist/manager.test.js +86 -0
  26. package/dist/params.js +0 -0
  27. package/dist/postinstall.js +1 -1
  28. package/dist/preview.js +68 -1
  29. package/dist/preview.test.js +215 -0
  30. package/dist/results.mock.js +874 -0
  31. package/dist/types.js +6 -0
  32. package/dist/utils.js +21 -0
  33. package/dist/{100.js → visionSimulatorFilters.js} +1 -23
  34. package/dist/withVisionSimulator.js +41 -0
  35. package/package.json +1 -1
  36. package/dist/212.js +0 -1965
  37. package/dist/212.js.LICENSE.txt +0 -19
  38. package/dist/rslib-runtime.js +0 -37
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ const RuleType = {
2
+ VIOLATION: 'violations',
3
+ PASS: 'passes',
4
+ INCOMPLETION: 'incomplete'
5
+ };
6
+ export { RuleType };
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 };
@@ -1,25 +1,3 @@
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
1
  const filters = {
24
2
  blurred: {
25
3
  label: 'Blurred vision',
@@ -119,4 +97,4 @@ const filterDefs = `<svg id="storybook-a11y-vision-filters" style="display: none
119
97
  </filter>
120
98
  </defs>
121
99
  </svg>`;
122
- export { ADDON_ID, DOCUMENTATION_DISCREPANCY_LINK, EVENTS, PANEL_ID, STATUS_TYPE_ID_A11Y, STATUS_TYPE_ID_COMPONENT_TEST, filterDefs, filters };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techsio/storybook-better-a11y",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Storybook Accessibility addon with APCA (WCAG 3) support",
5
5
  "keywords": [
6
6
  "storybook",