@storybook/addon-a11y 10.0.0-beta.0 → 10.0.0-beta.10

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/manager.js CHANGED
@@ -791,10 +791,11 @@ var A11yContextProvider = /* @__PURE__ */ __name((props) => {
791
791
  useEffect(() => {
792
792
  setStatus(getInitialStatus(manual));
793
793
  }, [getInitialStatus, manual]);
794
+ const isInitial = status === "initial";
794
795
  useEffect(() => {
795
796
  emit(REMOVE_HIGHLIGHT, `${ADDON_ID}/selected`);
796
797
  emit(REMOVE_HIGHLIGHT, `${ADDON_ID}/others`);
797
- if (!highlighted) {
798
+ if (!highlighted || isInitial) {
798
799
  return;
799
800
  }
800
801
  const selected = Array.from(selectedItems.values()).flatMap((key) => {
@@ -806,75 +807,79 @@ var A11yContextProvider = /* @__PURE__ */ __name((props) => {
806
807
  const target = result?.nodes[Number(number) - 1]?.target;
807
808
  return target ? [String(target)] : [];
808
809
  });
809
- emit(HIGHLIGHT, {
810
- id: `${ADDON_ID}/selected`,
811
- priority: 1,
812
- selectors: selected,
813
- styles: {
814
- outline: `1px solid color-mix(in srgb, ${colorsByType[tab]}, transparent 30%)`,
815
- backgroundColor: "transparent"
816
- },
817
- hoverStyles: {
818
- outlineWidth: "2px"
819
- },
820
- focusStyles: {
821
- backgroundColor: "transparent"
822
- },
823
- menu: results?.[tab].map((result) => {
824
- const selectors = result.nodes.flatMap((n) => n.target).map(String).filter((e) => selected.includes(e));
825
- return [
826
- {
827
- id: `${tab}.${result.id}:info`,
828
- title: getTitleForAxeResult(result),
829
- description: getFriendlySummaryForAxeResult(result),
830
- selectors
831
- },
832
- {
833
- id: `${tab}.${result.id}`,
834
- iconLeft: "info",
835
- iconRight: "shareAlt",
836
- title: "Learn how to resolve this violation",
837
- clickEvent: EVENTS.SELECT,
838
- selectors
839
- }
840
- ];
841
- })
842
- });
810
+ if (selected.length) {
811
+ emit(HIGHLIGHT, {
812
+ id: `${ADDON_ID}/selected`,
813
+ priority: 1,
814
+ selectors: selected,
815
+ styles: {
816
+ outline: `1px solid color-mix(in srgb, ${colorsByType[tab]}, transparent 30%)`,
817
+ backgroundColor: "transparent"
818
+ },
819
+ hoverStyles: {
820
+ outlineWidth: "2px"
821
+ },
822
+ focusStyles: {
823
+ backgroundColor: "transparent"
824
+ },
825
+ menu: results?.[tab].map((result) => {
826
+ const selectors = result.nodes.flatMap((n) => n.target).map(String).filter((e) => selected.includes(e));
827
+ return [
828
+ {
829
+ id: `${tab}.${result.id}:info`,
830
+ title: getTitleForAxeResult(result),
831
+ description: getFriendlySummaryForAxeResult(result),
832
+ selectors
833
+ },
834
+ {
835
+ id: `${tab}.${result.id}`,
836
+ iconLeft: "info",
837
+ iconRight: "shareAlt",
838
+ title: "Learn how to resolve this violation",
839
+ clickEvent: EVENTS.SELECT,
840
+ selectors
841
+ }
842
+ ];
843
+ })
844
+ });
845
+ }
843
846
  const others = results?.[tab].flatMap((r) => r.nodes.flatMap((n) => n.target).map(String)).filter((e) => ![...unhighlightedSelectors, ...selected].includes(e));
844
- emit(HIGHLIGHT, {
845
- id: `${ADDON_ID}/others`,
846
- selectors: others,
847
- styles: {
848
- outline: `1px solid color-mix(in srgb, ${colorsByType[tab]}, transparent 30%)`,
849
- backgroundColor: `color-mix(in srgb, ${colorsByType[tab]}, transparent 60%)`
850
- },
851
- hoverStyles: {
852
- outlineWidth: "2px"
853
- },
854
- focusStyles: {
855
- backgroundColor: "transparent"
856
- },
857
- menu: results?.[tab].map((result) => {
858
- const selectors = result.nodes.flatMap((n) => n.target).map(String).filter((e) => !selected.includes(e));
859
- return [
860
- {
861
- id: `${tab}.${result.id}:info`,
862
- title: getTitleForAxeResult(result),
863
- description: getFriendlySummaryForAxeResult(result),
864
- selectors
865
- },
866
- {
867
- id: `${tab}.${result.id}`,
868
- iconLeft: "info",
869
- iconRight: "shareAlt",
870
- title: "Learn how to resolve this violation",
871
- clickEvent: EVENTS.SELECT,
872
- selectors
873
- }
874
- ];
875
- })
876
- });
877
- }, [emit, highlighted, results, tab, selectedItems]);
847
+ if (others?.length) {
848
+ emit(HIGHLIGHT, {
849
+ id: `${ADDON_ID}/others`,
850
+ selectors: others,
851
+ styles: {
852
+ outline: `1px solid color-mix(in srgb, ${colorsByType[tab]}, transparent 30%)`,
853
+ backgroundColor: `color-mix(in srgb, ${colorsByType[tab]}, transparent 60%)`
854
+ },
855
+ hoverStyles: {
856
+ outlineWidth: "2px"
857
+ },
858
+ focusStyles: {
859
+ backgroundColor: "transparent"
860
+ },
861
+ menu: results?.[tab].map((result) => {
862
+ const selectors = result.nodes.flatMap((n) => n.target).map(String).filter((e) => !selected.includes(e));
863
+ return [
864
+ {
865
+ id: `${tab}.${result.id}:info`,
866
+ title: getTitleForAxeResult(result),
867
+ description: getFriendlySummaryForAxeResult(result),
868
+ selectors
869
+ },
870
+ {
871
+ id: `${tab}.${result.id}`,
872
+ iconLeft: "info",
873
+ iconRight: "shareAlt",
874
+ title: "Learn how to resolve this violation",
875
+ clickEvent: EVENTS.SELECT,
876
+ selectors
877
+ }
878
+ ];
879
+ })
880
+ });
881
+ }
882
+ }, [isInitial, emit, highlighted, results, tab, selectedItems]);
878
883
  const discrepancy = useMemo(() => {
879
884
  if (!currentStoryA11yStatusValue) {
880
885
  return null;
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_aps9sp9p4g8 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_aps9sp9p4g8 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_aps9sp9p4g8 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_g26mmftj3oj from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_g26mmftj3oj from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_g26mmftj3oj from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_aps9sp9p4g8.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_aps9sp9p4g8.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_aps9sp9p4g8.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_g26mmftj3oj.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_g26mmftj3oj.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_g26mmftj3oj.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -1205,8 +1205,10 @@ var format = /* @__PURE__ */ __name((open, close) => {
1205
1205
  }
1206
1206
  let result = openCode;
1207
1207
  let lastIndex = 0;
1208
+ const reopenOnNestedClose = close === 22;
1209
+ const replaceCode = (reopenOnNestedClose ? closeCode : "") + openCode;
1208
1210
  while (index !== -1) {
1209
- result += string.slice(lastIndex, index) + openCode;
1211
+ result += string.slice(lastIndex, index) + replaceCode;
1210
1212
  lastIndex = index + closeCode.length;
1211
1213
  index = string.indexOf(closeCode, lastIndex);
1212
1214
  }
@@ -3731,7 +3733,7 @@ function prettyMilliseconds(milliseconds, options) {
3731
3733
  }
3732
3734
  add(Number(parsed.minutes), "minute", "m");
3733
3735
  if (!options.hideSeconds) {
3734
- if (options.separateMilliseconds || options.formatSubMilliseconds || !options.colonNotation && milliseconds < 1e3) {
3736
+ if (options.separateMilliseconds || options.formatSubMilliseconds || !options.colonNotation && milliseconds < 1e3 && !options.subSecondsAsDecimals) {
3735
3737
  const seconds = Number(parsed.seconds);
3736
3738
  const milliseconds2 = Number(parsed.milliseconds);
3737
3739
  const microseconds = Number(parsed.microseconds);
package/dist/preview.d.ts CHANGED
@@ -1,3 +1,50 @@
1
- // auto generated file from file:///home/runner/work/storybook/storybook/scripts/build/utils/generate-type-mappers.ts, do not edit
2
- export * from '../src/preview.tsx';
3
- export type * from '../src/preview.tsx';
1
+ import { AfterEach } from 'storybook/internal/types';
2
+ import { Selector, SelectorList, RunOptions, Spec } from 'axe-core';
3
+
4
+ type SelectorWithoutNode = Omit<Selector, 'Node'> | Omit<SelectorList, 'NodeList'>;
5
+ type ContextObjectWithoutNode = {
6
+ include: SelectorWithoutNode;
7
+ exclude?: SelectorWithoutNode;
8
+ } | {
9
+ exclude: SelectorWithoutNode;
10
+ include?: SelectorWithoutNode;
11
+ };
12
+ type ContextSpecWithoutNode = SelectorWithoutNode | ContextObjectWithoutNode;
13
+ type A11yTest = 'off' | 'todo' | 'error';
14
+ interface A11yParameters {
15
+ /**
16
+ * Context parameter for axe-core's run function, except without support for passing Nodes and
17
+ * NodeLists directly.
18
+ *
19
+ * @see https://github.com/dequelabs/axe-core/blob/develop/doc/context.md
20
+ */
21
+ context?: ContextSpecWithoutNode;
22
+ /**
23
+ * Options for running axe-core.
24
+ *
25
+ * @see https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter
26
+ */
27
+ options?: RunOptions;
28
+ /**
29
+ * Configuration object for axe-core.
30
+ *
31
+ * @see https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axeconfigure
32
+ */
33
+ config?: Spec;
34
+ /** Whether to disable accessibility tests. */
35
+ disable?: boolean;
36
+ /** Defines how accessibility violations should be handled: 'off', 'todo', or 'error'. */
37
+ test?: A11yTest;
38
+ }
39
+
40
+ declare const afterEach: AfterEach<any>;
41
+ declare const initialGlobals: {
42
+ a11y: {
43
+ manual: boolean;
44
+ };
45
+ };
46
+ declare const parameters: {
47
+ a11y: A11yParameters;
48
+ };
49
+
50
+ export { afterEach, initialGlobals, parameters };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-a11y",
3
- "version": "10.0.0-beta.0",
3
+ "version": "10.0.0-beta.10",
4
4
  "description": "Storybook Addon A11y: Test UI component compliance with WCAG web accessibility standards",
5
5
  "keywords": [
6
6
  "a11y",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@radix-ui/react-tabs": "1.0.4",
67
- "@storybook/icons": "^1.4.0",
67
+ "@storybook/icons": "^1.6.0",
68
68
  "@testing-library/react": "^14.0.0",
69
69
  "execa": "^9.5.2",
70
70
  "react": "^18.2.0",
@@ -74,7 +74,7 @@
74
74
  "vitest-axe": "^0.1.0"
75
75
  },
76
76
  "peerDependencies": {
77
- "storybook": "^10.0.0-beta.0"
77
+ "storybook": "^10.0.0-beta.10"
78
78
  },
79
79
  "publishConfig": {
80
80
  "access": "public"
@@ -1,50 +0,0 @@
1
- import { AfterEach } from 'storybook/internal/types';
2
- import { Selector, SelectorList, RunOptions, Spec } from 'axe-core';
3
-
4
- type SelectorWithoutNode = Omit<Selector, 'Node'> | Omit<SelectorList, 'NodeList'>;
5
- type ContextObjectWithoutNode = {
6
- include: SelectorWithoutNode;
7
- exclude?: SelectorWithoutNode;
8
- } | {
9
- exclude: SelectorWithoutNode;
10
- include?: SelectorWithoutNode;
11
- };
12
- type ContextSpecWithoutNode = SelectorWithoutNode | ContextObjectWithoutNode;
13
- type A11yTest = 'off' | 'todo' | 'error';
14
- interface A11yParameters {
15
- /**
16
- * Context parameter for axe-core's run function, except without support for passing Nodes and
17
- * NodeLists directly.
18
- *
19
- * @see https://github.com/dequelabs/axe-core/blob/develop/doc/context.md
20
- */
21
- context?: ContextSpecWithoutNode;
22
- /**
23
- * Options for running axe-core.
24
- *
25
- * @see https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter
26
- */
27
- options?: RunOptions;
28
- /**
29
- * Configuration object for axe-core.
30
- *
31
- * @see https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axeconfigure
32
- */
33
- config?: Spec;
34
- /** Whether to disable accessibility tests. */
35
- disable?: boolean;
36
- /** Defines how accessibility violations should be handled: 'off', 'todo', or 'error'. */
37
- test?: A11yTest;
38
- }
39
-
40
- declare const afterEach: AfterEach<any>;
41
- declare const initialGlobals: {
42
- a11y: {
43
- manual: boolean;
44
- };
45
- };
46
- declare const parameters: {
47
- a11y: A11yParameters;
48
- };
49
-
50
- export { afterEach, initialGlobals, parameters };