@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.
@@ -1,116 +1,140 @@
1
- import { expect } from 'storybook/test';
2
- import { expect as expect$1 } from 'vitest';
3
- import { composeConfigs, addons } from 'storybook/preview-api';
4
- import { configureRules, createChunkedAudit, getActiveRules, getRuleById } from '@accesslint/core';
5
- import { accesslintMatchers } from '@accesslint/vitest/matchers';
6
-
1
+ import { expect } from "storybook/test";
2
+ import { expect as expect$1 } from "vitest";
3
+ import { addons, composeConfigs } from "storybook/preview-api";
4
+ import { createChunkedAudit, getActiveRules, getRuleById } from "@accesslint/core";
5
+ import { accesslintMatchers } from "@accesslint/vitest/matchers";
6
+ //#region \0rolldown/runtime.js
7
7
  var __defProp = Object.defineProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
8
+ var __exportAll = (all, no_symbols) => {
9
+ let target = {};
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ return target;
11
16
  };
12
-
13
- // src/preview.ts
14
- var preview_exports = {};
15
- __export(preview_exports, {
16
- afterEach: () => afterEach,
17
- initialGlobals: () => initialGlobals,
18
- parameters: () => parameters
17
+ const RESULT_EVENT = `accesslint/a11y/result`;
18
+ const HIGHLIGHT_ADDON_ID = "storybook/highlight";
19
+ `${HIGHLIGHT_ADDON_ID}`;
20
+ `${HIGHLIGHT_ADDON_ID}`;
21
+ //#endregion
22
+ //#region src/preview.ts
23
+ var preview_exports = /* @__PURE__ */ __exportAll({
24
+ afterEach: () => afterEach,
25
+ initialGlobals: () => initialGlobals,
26
+ parameters: () => parameters,
27
+ setAuditOptions: () => setAuditOptions
19
28
  });
20
-
21
- // src/constants.ts
22
- var ADDON_ID = "accesslint/a11y";
23
- var RESULT_EVENT = `${ADDON_ID}/result`;
24
-
25
- // src/preview.ts
26
- var initialGlobals = {
27
- accesslint: {}
28
- };
29
- var parameters = {
30
- accesslint: {}
31
- };
32
- configureRules({
33
- disabledRules: ["accesslint-045"]
34
- });
35
- var BUDGET_MS = 12;
29
+ const initialGlobals = { accesslint: {} };
30
+ const parameters = { accesslint: {} };
31
+ let AUDIT_OPTIONS = { disabledRules: ["accesslint-045"] };
32
+ /**
33
+ * Merge additional audit options (disabledRules, additionalRules, includeAAA,
34
+ * componentMode, locale) into the options used for every Storybook audit.
35
+ * Call from your `.storybook/preview.ts` after importing the addon.
36
+ */
37
+ function setAuditOptions(options) {
38
+ AUDIT_OPTIONS = {
39
+ ...AUDIT_OPTIONS,
40
+ ...options,
41
+ disabledRules: [...AUDIT_OPTIONS.disabledRules ?? [], ...options.disabledRules ?? []],
42
+ additionalRules: [...AUDIT_OPTIONS.additionalRules ?? [], ...options.additionalRules ?? []]
43
+ };
44
+ }
45
+ const BUDGET_MS = 12;
36
46
  function yieldToMain() {
37
- return new Promise((resolve) => setTimeout(resolve, 0));
47
+ return new Promise((resolve) => setTimeout(resolve, 0));
38
48
  }
39
49
  function scopeViolations(violations) {
40
- const root = document.getElementById("storybook-root");
41
- if (!root) return violations;
42
- return violations.filter((v) => {
43
- const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
44
- try {
45
- const el = document.querySelector(local);
46
- return el && root.contains(el);
47
- } catch {
48
- return false;
49
- }
50
- });
50
+ const root = document.getElementById("storybook-root");
51
+ if (!root) return violations;
52
+ return violations.filter((v) => {
53
+ const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
54
+ try {
55
+ const el = document.querySelector(local);
56
+ return el && root.contains(el);
57
+ } catch {
58
+ return false;
59
+ }
60
+ });
51
61
  }
52
62
  function enrichViolations(violations) {
53
- return violations.map((v) => {
54
- const rule = getRuleById(v.ruleId);
55
- return {
56
- ...v,
57
- element: void 0,
58
- // not serializable
59
- description: rule?.description,
60
- wcag: rule?.wcag,
61
- level: rule?.level,
62
- guidance: rule?.guidance
63
- };
64
- });
63
+ return violations.map((v) => {
64
+ const rule = getRuleById(v.ruleId);
65
+ return {
66
+ ...v,
67
+ element: void 0,
68
+ description: rule?.description,
69
+ wcag: rule?.wcag,
70
+ level: rule?.level,
71
+ guidance: rule?.guidance
72
+ };
73
+ });
65
74
  }
66
- var afterEach = async ({
67
- reporting,
68
- parameters: parameters2,
69
- viewMode,
70
- tags,
71
- id
72
- }) => {
73
- const accesslintParam = parameters2?.accesslint;
74
- if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
75
- if (viewMode !== "story") return;
76
- const skipTags = typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : [];
77
- const allSkipTags = ["skip-accesslint", ...skipTags];
78
- const matchedTag = tags?.find((t) => allSkipTags.includes(t));
79
- if (matchedTag) {
80
- const result2 = { skipped: true, reason: matchedTag };
81
- addons.getChannel().emit(RESULT_EVENT, { storyId: id, result: result2 });
82
- reporting.addReport({
83
- type: "accesslint",
84
- version: 1,
85
- result: result2,
86
- status: "passed"
87
- });
88
- return;
89
- }
90
- const audit = createChunkedAudit(document);
91
- while (audit.processChunk(BUDGET_MS)) {
92
- await yieldToMain();
93
- }
94
- const violations = audit.getViolations();
95
- const scoped = scopeViolations(violations);
96
- const enriched = enrichViolations(scoped);
97
- const hasViolations = enriched.length > 0;
98
- const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
99
- const status = hasViolations ? mode : "passed";
100
- const result = {
101
- violations: enriched,
102
- ruleCount: getActiveRules().length
103
- };
104
- addons.getChannel().emit(RESULT_EVENT, { storyId: id, result, status });
105
- reporting.addReport({
106
- type: "accesslint",
107
- version: 1,
108
- result,
109
- status
110
- });
75
+ const afterEach = async ({ reporting, parameters, viewMode, tags, id }) => {
76
+ const accesslintParam = parameters?.accesslint;
77
+ if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
78
+ if (viewMode !== "story") return;
79
+ const allSkipTags = ["skip-accesslint", ...typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : []];
80
+ const matchedTag = tags?.find((t) => allSkipTags.includes(t));
81
+ if (matchedTag) {
82
+ const result = {
83
+ skipped: true,
84
+ reason: matchedTag
85
+ };
86
+ addons.getChannel().emit(RESULT_EVENT, {
87
+ storyId: id,
88
+ result
89
+ });
90
+ reporting.addReport({
91
+ type: "accesslint",
92
+ version: 1,
93
+ result,
94
+ status: "passed"
95
+ });
96
+ return;
97
+ }
98
+ const audit = createChunkedAudit(document, AUDIT_OPTIONS);
99
+ while (audit.processChunk(BUDGET_MS)) await yieldToMain();
100
+ const enriched = enrichViolations(scopeViolations(audit.getViolations()));
101
+ const hasViolations = enriched.length > 0;
102
+ const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
103
+ const status = hasViolations ? mode : "passed";
104
+ const result = {
105
+ violations: enriched,
106
+ ruleCount: getActiveRules(AUDIT_OPTIONS).length
107
+ };
108
+ addons.getChannel().emit(RESULT_EVENT, {
109
+ storyId: id,
110
+ result,
111
+ status
112
+ });
113
+ reporting.addReport({
114
+ type: "accesslint",
115
+ version: 1,
116
+ result,
117
+ status
118
+ });
111
119
  };
120
+ //#endregion
121
+ //#region src/vitest-setup.ts
122
+ /**
123
+ * Vitest setup file added by the accesslintTest() plugin.
124
+ *
125
+ * Merges the AccessLint preview annotations (afterEach, decorators) into
126
+ * globalProjectAnnotations so that AccessLint runs during vitest story tests
127
+ * and reports results as sidebar badges.
128
+ *
129
+ * Also registers the toBeAccessible() custom matcher with Storybook's expect
130
+ * and Vitest's expect for generic tests.
131
+ *
132
+ * This file runs AFTER the user's vitest.setup.js (which calls
133
+ * setProjectAnnotations), so globalProjectAnnotations is already set.
134
+ */
112
135
  expect.extend(accesslintMatchers);
113
136
  expect$1.extend(accesslintMatchers);
114
- var g = globalThis;
115
- var existing = g.globalProjectAnnotations;
137
+ const g = globalThis;
138
+ const existing = g.globalProjectAnnotations;
116
139
  g.globalProjectAnnotations = existing ? composeConfigs([existing, preview_exports]) : composeConfigs([preview_exports]);
140
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@accesslint/storybook-addon",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
4
4
  "description": "Catch accessibility violations in your Storybook stories as you develop",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -9,43 +9,104 @@
9
9
  "homepage": "https://www.accesslint.com/storybook?ref=npm_storybook",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/AccessLint/storybook-addon.git"
12
+ "url": "git+https://github.com/AccessLint/accesslint.git",
13
+ "directory": "storybook-addon"
13
14
  },
14
15
  "bugs": {
15
- "url": "https://github.com/AccessLint/core/issues"
16
+ "url": "https://github.com/AccessLint/accesslint/issues"
16
17
  },
17
18
  "type": "module",
18
19
  "exports": {
19
20
  ".": {
20
- "import": "./dist/index.js",
21
- "require": "./dist/index.cjs"
21
+ "import": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
29
+ },
30
+ "./manager": {
31
+ "types": "./dist/manager.d.ts",
32
+ "default": "./dist/manager.js"
22
33
  },
23
- "./manager": "./dist/manager.js",
24
34
  "./preview": {
25
- "import": "./dist/preview.js",
26
- "require": "./dist/preview.cjs"
35
+ "import": {
36
+ "types": "./dist/preview.d.ts",
37
+ "default": "./dist/preview.js"
38
+ },
39
+ "require": {
40
+ "types": "./dist/preview.d.cts",
41
+ "default": "./dist/preview.cjs"
42
+ }
27
43
  },
28
44
  "./vitest-plugin": {
29
- "import": "./dist/vitest-plugin.js",
30
- "require": "./dist/vitest-plugin.cjs"
45
+ "import": {
46
+ "types": "./dist/vitest-plugin.d.ts",
47
+ "default": "./dist/vitest-plugin.js"
48
+ },
49
+ "require": {
50
+ "types": "./dist/vitest-plugin.d.cts",
51
+ "default": "./dist/vitest-plugin.cjs"
52
+ }
31
53
  },
32
54
  "./vitest-setup": {
33
- "types": "./dist/vitest-setup.d.ts",
34
- "import": "./dist/vitest-setup.js",
35
- "require": "./dist/vitest-setup.cjs"
55
+ "import": {
56
+ "types": "./dist/vitest-setup.d.ts",
57
+ "default": "./dist/vitest-setup.js"
58
+ },
59
+ "require": {
60
+ "types": "./dist/vitest-setup.d.cts",
61
+ "default": "./dist/vitest-setup.cjs"
62
+ }
36
63
  },
37
64
  "./matchers": {
38
- "import": "./dist/matchers.js",
39
- "require": "./dist/matchers.cjs"
65
+ "import": {
66
+ "types": "./dist/matchers.d.ts",
67
+ "default": "./dist/matchers.js"
68
+ },
69
+ "require": {
70
+ "types": "./dist/matchers.d.cts",
71
+ "default": "./dist/matchers.cjs"
72
+ }
40
73
  },
41
74
  "./portable": {
42
- "import": "./dist/portable.js",
43
- "require": "./dist/portable.cjs"
75
+ "import": {
76
+ "types": "./dist/portable.d.ts",
77
+ "default": "./dist/portable.js"
78
+ },
79
+ "require": {
80
+ "types": "./dist/portable.d.cts",
81
+ "default": "./dist/portable.cjs"
82
+ }
44
83
  }
45
84
  },
46
85
  "main": "dist/index.cjs",
47
86
  "module": "dist/index.js",
48
- "types": "dist/index.d.ts",
87
+ "types": "dist/index.d.cts",
88
+ "typesVersions": {
89
+ "*": {
90
+ "manager": [
91
+ "./dist/manager.d.ts"
92
+ ],
93
+ "preview": [
94
+ "./dist/preview.d.ts"
95
+ ],
96
+ "vitest-plugin": [
97
+ "./dist/vitest-plugin.d.ts"
98
+ ],
99
+ "vitest-setup": [
100
+ "./dist/vitest-setup.d.ts"
101
+ ],
102
+ "matchers": [
103
+ "./dist/matchers.d.ts"
104
+ ],
105
+ "portable": [
106
+ "./dist/portable.d.ts"
107
+ ]
108
+ }
109
+ },
49
110
  "files": [
50
111
  "dist/**/*",
51
112
  "README.md",
@@ -53,13 +114,14 @@
53
114
  "*.d.ts"
54
115
  ],
55
116
  "scripts": {
56
- "build": "tsup",
57
- "build:watch": "tsup --watch",
58
- "typecheck": "tsc --noEmit"
117
+ "build": "tsdown",
118
+ "build:watch": "tsdown --watch",
119
+ "typecheck": "tsc --noEmit",
120
+ "prepublishOnly": "bun run build"
59
121
  },
60
122
  "dependencies": {
61
- "@accesslint/core": "^0.8.7",
62
- "@accesslint/vitest": "^0.1.7"
123
+ "@accesslint/core": "0.9.0",
124
+ "@accesslint/vitest": "0.3.0"
63
125
  },
64
126
  "devDependencies": {
65
127
  "@types/react": "^19.2.14",
@@ -67,7 +129,7 @@
67
129
  "react": "^18.2.0",
68
130
  "react-dom": "^18.2.0",
69
131
  "storybook": "^10.2.0",
70
- "tsup": "^8.4.0",
132
+ "tsdown": "^0.21.9",
71
133
  "typescript": "^5.7.0",
72
134
  "vitest": "^4.0.18"
73
135
  },
@@ -1,110 +0,0 @@
1
- import { configureRules, createChunkedAudit, getActiveRules, getRuleById } from '@accesslint/core';
2
- import { addons } from 'storybook/preview-api';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
-
10
- // src/preview.ts
11
- var preview_exports = {};
12
- __export(preview_exports, {
13
- afterEach: () => afterEach,
14
- initialGlobals: () => initialGlobals,
15
- parameters: () => parameters
16
- });
17
-
18
- // src/constants.ts
19
- var ADDON_ID = "accesslint/a11y";
20
- var RESULT_EVENT = `${ADDON_ID}/result`;
21
-
22
- // src/preview.ts
23
- var initialGlobals = {
24
- accesslint: {}
25
- };
26
- var parameters = {
27
- accesslint: {}
28
- };
29
- configureRules({
30
- disabledRules: ["accesslint-045"]
31
- });
32
- var BUDGET_MS = 12;
33
- function yieldToMain() {
34
- return new Promise((resolve) => setTimeout(resolve, 0));
35
- }
36
- function scopeViolations(violations) {
37
- const root = document.getElementById("storybook-root");
38
- if (!root) return violations;
39
- return violations.filter((v) => {
40
- const local = v.selector.replace(/^.*>>>\s*iframe>\s*/, "");
41
- try {
42
- const el = document.querySelector(local);
43
- return el && root.contains(el);
44
- } catch {
45
- return false;
46
- }
47
- });
48
- }
49
- function enrichViolations(violations) {
50
- return violations.map((v) => {
51
- const rule = getRuleById(v.ruleId);
52
- return {
53
- ...v,
54
- element: void 0,
55
- // not serializable
56
- description: rule?.description,
57
- wcag: rule?.wcag,
58
- level: rule?.level,
59
- guidance: rule?.guidance
60
- };
61
- });
62
- }
63
- var afterEach = async ({
64
- reporting,
65
- parameters: parameters2,
66
- viewMode,
67
- tags,
68
- id
69
- }) => {
70
- const accesslintParam = parameters2?.accesslint;
71
- if (accesslintParam?.disable === true || accesslintParam?.test === "off") return;
72
- if (viewMode !== "story") return;
73
- const skipTags = typeof __ACCESSLINT_SKIP_TAGS__ !== "undefined" ? __ACCESSLINT_SKIP_TAGS__ : [];
74
- const allSkipTags = ["skip-accesslint", ...skipTags];
75
- const matchedTag = tags?.find((t) => allSkipTags.includes(t));
76
- if (matchedTag) {
77
- const result2 = { skipped: true, reason: matchedTag };
78
- addons.getChannel().emit(RESULT_EVENT, { storyId: id, result: result2 });
79
- reporting.addReport({
80
- type: "accesslint",
81
- version: 1,
82
- result: result2,
83
- status: "passed"
84
- });
85
- return;
86
- }
87
- const audit = createChunkedAudit(document);
88
- while (audit.processChunk(BUDGET_MS)) {
89
- await yieldToMain();
90
- }
91
- const violations = audit.getViolations();
92
- const scoped = scopeViolations(violations);
93
- const enriched = enrichViolations(scoped);
94
- const hasViolations = enriched.length > 0;
95
- const mode = accesslintParam?.test === "todo" ? "warning" : "failed";
96
- const status = hasViolations ? mode : "passed";
97
- const result = {
98
- violations: enriched,
99
- ruleCount: getActiveRules().length
100
- };
101
- addons.getChannel().emit(RESULT_EVENT, { storyId: id, result, status });
102
- reporting.addReport({
103
- type: "accesslint",
104
- version: 1,
105
- result,
106
- status
107
- });
108
- };
109
-
110
- export { afterEach, initialGlobals, parameters, preview_exports };