@accesslint/storybook-addon 0.8.9 → 0.8.11

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/matchers.cjs CHANGED
@@ -1,14 +1,14 @@
1
- 'use strict';
2
-
3
- var matchers = require('@accesslint/vitest/matchers');
4
-
5
-
6
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _accesslint_vitest_matchers = require("@accesslint/vitest/matchers");
7
3
  Object.defineProperty(exports, "accesslintMatchers", {
8
- enumerable: true,
9
- get: function () { return matchers.accesslintMatchers; }
4
+ enumerable: true,
5
+ get: function() {
6
+ return _accesslint_vitest_matchers.accesslintMatchers;
7
+ }
10
8
  });
11
9
  Object.defineProperty(exports, "toBeAccessible", {
12
- enumerable: true,
13
- get: function () { return matchers.toBeAccessible; }
10
+ enumerable: true,
11
+ get: function() {
12
+ return _accesslint_vitest_matchers.toBeAccessible;
13
+ }
14
14
  });
@@ -1 +1,2 @@
1
- export { AccessibleMatcherOptions, accesslintMatchers, toBeAccessible } from '@accesslint/vitest/matchers';
1
+ import { AccessibleMatcherOptions, accesslintMatchers, toBeAccessible } from "@accesslint/vitest/matchers";
2
+ export { type AccessibleMatcherOptions, accesslintMatchers, toBeAccessible };
@@ -1 +1,2 @@
1
- export { AccessibleMatcherOptions, accesslintMatchers, toBeAccessible } from '@accesslint/vitest/matchers';
1
+ import { AccessibleMatcherOptions, accesslintMatchers, toBeAccessible } from "@accesslint/vitest/matchers";
2
+ export { type AccessibleMatcherOptions, accesslintMatchers, toBeAccessible };
package/dist/matchers.js CHANGED
@@ -1 +1,2 @@
1
- export { accesslintMatchers, toBeAccessible } from '@accesslint/vitest/matchers';
1
+ import { accesslintMatchers, toBeAccessible } from "@accesslint/vitest/matchers";
2
+ export { accesslintMatchers, toBeAccessible };
package/dist/portable.cjs CHANGED
@@ -1,118 +1,159 @@
1
- 'use strict';
2
-
3
- var core = require('@accesslint/core');
4
- var previewApi = require('storybook/preview-api');
5
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
6
3
  var __defProp = Object.defineProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
4
+ var __exportAll = (all, no_symbols) => {
5
+ let target = {};
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
+ return target;
10
12
  };
11
-
12
- // src/preview.ts
13
- var preview_exports = {};
14
- __export(preview_exports, {
15
- afterEach: () => afterEach,
16
- initialGlobals: () => initialGlobals,
17
- parameters: () => parameters
13
+ //#endregion
14
+ let _accesslint_core = require("@accesslint/core");
15
+ let storybook_preview_api = require("storybook/preview-api");
16
+ const RESULT_EVENT = `accesslint/a11y/result`;
17
+ const HIGHLIGHT_ADDON_ID = "storybook/highlight";
18
+ `${HIGHLIGHT_ADDON_ID}`;
19
+ `${HIGHLIGHT_ADDON_ID}`;
20
+ //#endregion
21
+ //#region src/preview.ts
22
+ var preview_exports = /* @__PURE__ */ __exportAll({
23
+ afterEach: () => afterEach,
24
+ initialGlobals: () => initialGlobals,
25
+ parameters: () => parameters,
26
+ setAuditOptions: () => setAuditOptions
18
27
  });
19
-
20
- // src/constants.ts
21
- var ADDON_ID = "accesslint/a11y";
22
- var RESULT_EVENT = `${ADDON_ID}/result`;
23
-
24
- // src/preview.ts
25
- var initialGlobals = {
26
- accesslint: {}
27
- };
28
- var parameters = {
29
- accesslint: {}
30
- };
31
- core.configureRules({
32
- disabledRules: ["accesslint-045"]
33
- });
34
- var BUDGET_MS = 12;
28
+ const initialGlobals = { accesslint: {} };
29
+ const parameters = { accesslint: {} };
30
+ let AUDIT_OPTIONS = { disabledRules: ["accesslint-045"] };
31
+ /**
32
+ * Merge additional audit options (disabledRules, additionalRules, includeAAA,
33
+ * componentMode, locale) into the options used for every Storybook audit.
34
+ * Call from your `.storybook/preview.ts` after importing the addon.
35
+ */
36
+ function setAuditOptions(options) {
37
+ AUDIT_OPTIONS = {
38
+ ...AUDIT_OPTIONS,
39
+ ...options,
40
+ disabledRules: [...AUDIT_OPTIONS.disabledRules ?? [], ...options.disabledRules ?? []],
41
+ additionalRules: [...AUDIT_OPTIONS.additionalRules ?? [], ...options.additionalRules ?? []]
42
+ };
43
+ }
44
+ const BUDGET_MS = 12;
35
45
  function yieldToMain() {
36
- return new Promise((resolve) => setTimeout(resolve, 0));
46
+ return new Promise((resolve) => setTimeout(resolve, 0));
37
47
  }
38
48
  function scopeViolations(violations) {
39
- const root = document.getElementById("storybook-root");
40
- if (!root) return violations;
41
- return violations.filter((v) => {
42
- const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
43
- try {
44
- const el = document.querySelector(local);
45
- return el && root.contains(el);
46
- } catch {
47
- return false;
48
- }
49
- });
49
+ const root = document.getElementById("storybook-root");
50
+ if (!root) return violations;
51
+ return violations.filter((v) => {
52
+ const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
53
+ try {
54
+ const el = document.querySelector(local);
55
+ return el && root.contains(el);
56
+ } catch {
57
+ return false;
58
+ }
59
+ });
50
60
  }
51
61
  function enrichViolations(violations) {
52
- return violations.map((v) => {
53
- const rule = core.getRuleById(v.ruleId);
54
- return {
55
- ...v,
56
- element: void 0,
57
- // not serializable
58
- description: rule?.description,
59
- wcag: rule?.wcag,
60
- level: rule?.level,
61
- guidance: rule?.guidance
62
- };
63
- });
62
+ return violations.map((v) => {
63
+ const rule = (0, _accesslint_core.getRuleById)(v.ruleId);
64
+ return {
65
+ ...v,
66
+ element: void 0,
67
+ description: rule?.description,
68
+ wcag: rule?.wcag,
69
+ level: rule?.level,
70
+ guidance: rule?.guidance
71
+ };
72
+ });
64
73
  }
65
- var afterEach = async ({
66
- reporting,
67
- parameters: parameters2,
68
- viewMode,
69
- tags,
70
- id
71
- }) => {
72
- const accesslintParam = parameters2?.accesslint;
73
- if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
74
- if (viewMode !== "story") return;
75
- const skipTags = typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : [];
76
- const allSkipTags = ["skip-accesslint", ...skipTags];
77
- const matchedTag = tags?.find((t) => allSkipTags.includes(t));
78
- if (matchedTag) {
79
- const result2 = { skipped: true, reason: matchedTag };
80
- previewApi.addons.getChannel().emit(RESULT_EVENT, { storyId: id, result: result2 });
81
- reporting.addReport({
82
- type: "accesslint",
83
- version: 1,
84
- result: result2,
85
- status: "passed"
86
- });
87
- return;
88
- }
89
- const audit = core.createChunkedAudit(document);
90
- while (audit.processChunk(BUDGET_MS)) {
91
- await yieldToMain();
92
- }
93
- const violations = audit.getViolations();
94
- const scoped = scopeViolations(violations);
95
- const enriched = enrichViolations(scoped);
96
- const hasViolations = enriched.length > 0;
97
- const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
98
- const status = hasViolations ? mode : "passed";
99
- const result = {
100
- violations: enriched,
101
- ruleCount: core.getActiveRules().length
102
- };
103
- previewApi.addons.getChannel().emit(RESULT_EVENT, { storyId: id, result, status });
104
- reporting.addReport({
105
- type: "accesslint",
106
- version: 1,
107
- result,
108
- status
109
- });
74
+ const afterEach = async ({ reporting, parameters, viewMode, tags, id }) => {
75
+ const accesslintParam = parameters?.accesslint;
76
+ if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
77
+ if (viewMode !== "story") return;
78
+ const allSkipTags = ["skip-accesslint", ...typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : []];
79
+ const matchedTag = tags?.find((t) => allSkipTags.includes(t));
80
+ if (matchedTag) {
81
+ const result = {
82
+ skipped: true,
83
+ reason: matchedTag
84
+ };
85
+ storybook_preview_api.addons.getChannel().emit(RESULT_EVENT, {
86
+ storyId: id,
87
+ result
88
+ });
89
+ reporting.addReport({
90
+ type: "accesslint",
91
+ version: 1,
92
+ result,
93
+ status: "passed"
94
+ });
95
+ return;
96
+ }
97
+ const audit = (0, _accesslint_core.createChunkedAudit)(document, AUDIT_OPTIONS);
98
+ while (audit.processChunk(BUDGET_MS)) await yieldToMain();
99
+ const enriched = enrichViolations(scopeViolations(audit.getViolations()));
100
+ const hasViolations = enriched.length > 0;
101
+ const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
102
+ const status = hasViolations ? mode : "passed";
103
+ const result = {
104
+ violations: enriched,
105
+ ruleCount: (0, _accesslint_core.getActiveRules)(AUDIT_OPTIONS).length
106
+ };
107
+ storybook_preview_api.addons.getChannel().emit(RESULT_EVENT, {
108
+ storyId: id,
109
+ result,
110
+ status
111
+ });
112
+ reporting.addReport({
113
+ type: "accesslint",
114
+ version: 1,
115
+ result,
116
+ status
117
+ });
110
118
  };
111
-
112
- // src/portable.ts
119
+ //#endregion
120
+ //#region src/portable.ts
121
+ /**
122
+ * Portable stories helper for using AccessLint with composeStories
123
+ * outside of Storybook (plain Vitest, Jest, Playwright CT).
124
+ *
125
+ * Usage in your test setup file:
126
+ *
127
+ * import { enableAccessLint } from "@accesslint/storybook-addon/portable";
128
+ * import { setProjectAnnotations } from "@storybook/react";
129
+ * import * as previewAnnotations from "./.storybook/preview";
130
+ *
131
+ * const project = setProjectAnnotations([
132
+ * previewAnnotations,
133
+ * enableAccessLint(),
134
+ * ]);
135
+ * beforeAll(project.beforeAll);
136
+ *
137
+ * Then in tests:
138
+ *
139
+ * import { composeStories } from "@storybook/react";
140
+ * import * as stories from "./Button.stories";
141
+ *
142
+ * const { Primary } = composeStories(stories);
143
+ *
144
+ * test("is accessible", async () => {
145
+ * await Primary.run();
146
+ * // AccessLint afterEach runs automatically and reports violations
147
+ * });
148
+ */
113
149
  function enableAccessLint() {
114
- return preview_exports;
150
+ return preview_exports;
115
151
  }
116
-
117
- exports.accesslintAnnotations = preview_exports;
152
+ //#endregion
153
+ Object.defineProperty(exports, "accesslintAnnotations", {
154
+ enumerable: true,
155
+ get: function() {
156
+ return preview_exports;
157
+ }
158
+ });
118
159
  exports.enableAccessLint = enableAccessLint;
@@ -1,60 +1,43 @@
1
+ import { AuditOptions } from "@accesslint/core";
2
+
3
+ //#region \0rolldown/runtime.js
4
+ declare namespace preview_d_exports {
5
+ export { afterEach, initialGlobals, parameters, setAuditOptions };
6
+ }
1
7
  declare const initialGlobals: {
2
- accesslint: {};
8
+ accesslint: {};
3
9
  };
4
10
  declare const parameters: {
5
- accesslint: {};
11
+ accesslint: {};
6
12
  };
7
- declare const afterEach: ({ reporting, parameters, viewMode, tags, id, }: {
8
- reporting: {
9
- addReport: (report: {
10
- type: string;
11
- version?: number;
12
- result: unknown;
13
- status: "failed" | "passed" | "warning";
14
- }) => void;
15
- };
16
- parameters: Record<string, unknown>;
17
- viewMode: string;
18
- tags?: string[];
19
- id?: string;
20
- }) => Promise<void>;
21
-
22
- declare const accesslintAnnotations_afterEach: typeof afterEach;
23
- declare const accesslintAnnotations_initialGlobals: typeof initialGlobals;
24
- declare const accesslintAnnotations_parameters: typeof parameters;
25
- declare namespace accesslintAnnotations {
26
- export { accesslintAnnotations_afterEach as afterEach, accesslintAnnotations_initialGlobals as initialGlobals, accesslintAnnotations_parameters as parameters };
27
- }
28
-
29
13
  /**
30
- * Portable stories helper for using AccessLint with composeStories
31
- * outside of Storybook (plain Vitest, Jest, Playwright CT).
32
- *
33
- * Usage in your test setup file:
34
- *
35
- * import { enableAccessLint } from "@accesslint/storybook-addon/portable";
36
- * import { setProjectAnnotations } from "@storybook/react";
37
- * import * as previewAnnotations from "./.storybook/preview";
38
- *
39
- * const project = setProjectAnnotations([
40
- * previewAnnotations,
41
- * enableAccessLint(),
42
- * ]);
43
- * beforeAll(project.beforeAll);
44
- *
45
- * Then in tests:
46
- *
47
- * import { composeStories } from "@storybook/react";
48
- * import * as stories from "./Button.stories";
49
- *
50
- * const { Primary } = composeStories(stories);
51
- *
52
- * test("is accessible", async () => {
53
- * await Primary.run();
54
- * // AccessLint afterEach runs automatically and reports violations
55
- * });
14
+ * Merge additional audit options (disabledRules, additionalRules, includeAAA,
15
+ * componentMode, locale) into the options used for every Storybook audit.
16
+ * Call from your `.storybook/preview.ts` after importing the addon.
56
17
  */
57
-
58
- declare function enableAccessLint(): typeof accesslintAnnotations;
59
-
60
- export { accesslintAnnotations, enableAccessLint };
18
+ declare function setAuditOptions(options: AuditOptions): void;
19
+ declare const afterEach: ({
20
+ reporting,
21
+ parameters,
22
+ viewMode,
23
+ tags,
24
+ id
25
+ }: {
26
+ reporting: {
27
+ addReport: (report: {
28
+ type: string;
29
+ version?: number;
30
+ result: unknown;
31
+ status: "failed" | "passed" | "warning";
32
+ }) => void;
33
+ };
34
+ parameters: Record<string, unknown>;
35
+ viewMode: string;
36
+ tags?: string[];
37
+ id?: string;
38
+ }) => Promise<void>;
39
+ //#endregion
40
+ //#region src/portable.d.ts
41
+ declare function enableAccessLint(): typeof preview_d_exports;
42
+ //#endregion
43
+ export { preview_d_exports as accesslintAnnotations, enableAccessLint };
@@ -1,60 +1,43 @@
1
+ import { AuditOptions } from "@accesslint/core";
2
+
3
+ //#region src/preview.d.ts
4
+ declare namespace preview_d_exports {
5
+ export { afterEach, initialGlobals, parameters, setAuditOptions };
6
+ }
1
7
  declare const initialGlobals: {
2
- accesslint: {};
8
+ accesslint: {};
3
9
  };
4
10
  declare const parameters: {
5
- accesslint: {};
11
+ accesslint: {};
6
12
  };
7
- declare const afterEach: ({ reporting, parameters, viewMode, tags, id, }: {
8
- reporting: {
9
- addReport: (report: {
10
- type: string;
11
- version?: number;
12
- result: unknown;
13
- status: "failed" | "passed" | "warning";
14
- }) => void;
15
- };
16
- parameters: Record<string, unknown>;
17
- viewMode: string;
18
- tags?: string[];
19
- id?: string;
20
- }) => Promise<void>;
21
-
22
- declare const accesslintAnnotations_afterEach: typeof afterEach;
23
- declare const accesslintAnnotations_initialGlobals: typeof initialGlobals;
24
- declare const accesslintAnnotations_parameters: typeof parameters;
25
- declare namespace accesslintAnnotations {
26
- export { accesslintAnnotations_afterEach as afterEach, accesslintAnnotations_initialGlobals as initialGlobals, accesslintAnnotations_parameters as parameters };
27
- }
28
-
29
13
  /**
30
- * Portable stories helper for using AccessLint with composeStories
31
- * outside of Storybook (plain Vitest, Jest, Playwright CT).
32
- *
33
- * Usage in your test setup file:
34
- *
35
- * import { enableAccessLint } from "@accesslint/storybook-addon/portable";
36
- * import { setProjectAnnotations } from "@storybook/react";
37
- * import * as previewAnnotations from "./.storybook/preview";
38
- *
39
- * const project = setProjectAnnotations([
40
- * previewAnnotations,
41
- * enableAccessLint(),
42
- * ]);
43
- * beforeAll(project.beforeAll);
44
- *
45
- * Then in tests:
46
- *
47
- * import { composeStories } from "@storybook/react";
48
- * import * as stories from "./Button.stories";
49
- *
50
- * const { Primary } = composeStories(stories);
51
- *
52
- * test("is accessible", async () => {
53
- * await Primary.run();
54
- * // AccessLint afterEach runs automatically and reports violations
55
- * });
14
+ * Merge additional audit options (disabledRules, additionalRules, includeAAA,
15
+ * componentMode, locale) into the options used for every Storybook audit.
16
+ * Call from your `.storybook/preview.ts` after importing the addon.
56
17
  */
57
-
58
- declare function enableAccessLint(): typeof accesslintAnnotations;
59
-
60
- export { accesslintAnnotations, enableAccessLint };
18
+ declare function setAuditOptions(options: AuditOptions): void;
19
+ declare const afterEach: ({
20
+ reporting,
21
+ parameters,
22
+ viewMode,
23
+ tags,
24
+ id
25
+ }: {
26
+ reporting: {
27
+ addReport: (report: {
28
+ type: string;
29
+ version?: number;
30
+ result: unknown;
31
+ status: "failed" | "passed" | "warning";
32
+ }) => void;
33
+ };
34
+ parameters: Record<string, unknown>;
35
+ viewMode: string;
36
+ tags?: string[];
37
+ id?: string;
38
+ }) => Promise<void>;
39
+ //#endregion
40
+ //#region src/portable.d.ts
41
+ declare function enableAccessLint(): typeof preview_d_exports;
42
+ //#endregion
43
+ export { preview_d_exports as accesslintAnnotations, enableAccessLint };