storybook 9.0.0-alpha.0 → 9.0.0-alpha.2

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 (211) hide show
  1. package/README.md +31 -29
  2. package/assets/browser/favicon.svg +1 -0
  3. package/assets/browser/nunito-sans-bold-italic.woff2 +0 -0
  4. package/assets/browser/nunito-sans-bold.woff2 +0 -0
  5. package/assets/browser/nunito-sans-italic.woff2 +0 -0
  6. package/assets/browser/nunito-sans-regular.woff2 +0 -0
  7. package/assets/docs/message-reference.png +0 -0
  8. package/assets/server/addon.tsconfig.json +6 -0
  9. package/assets/server/base-preview-body.html +119 -0
  10. package/assets/server/base-preview-head.html +451 -0
  11. package/assets/server/template.ejs +87 -0
  12. package/bin/index.cjs +1 -1
  13. package/dist/babel/index.cjs +54034 -0
  14. package/dist/babel/index.d.ts +7488 -0
  15. package/dist/babel/index.js +54044 -0
  16. package/dist/bin/index.cjs +124 -0
  17. package/dist/bin/index.js +118 -0
  18. package/dist/builder-manager/index.cjs +2167 -0
  19. package/dist/builder-manager/index.d.ts +19 -0
  20. package/dist/builder-manager/index.js +2189 -0
  21. package/dist/channels/index.cjs +1938 -0
  22. package/dist/channels/index.d.ts +108 -0
  23. package/dist/channels/index.js +1885 -0
  24. package/dist/cli/bin/index.cjs +2687 -0
  25. package/dist/cli/bin/index.d.ts +2 -0
  26. package/dist/cli/bin/index.js +2707 -0
  27. package/dist/cli/index.cjs +17327 -0
  28. package/dist/cli/index.d.ts +209 -0
  29. package/dist/cli/index.js +17349 -0
  30. package/dist/client-logger/index.cjs +112 -0
  31. package/dist/client-logger/index.d.ts +29 -0
  32. package/dist/client-logger/index.js +70 -0
  33. package/dist/common/index.cjs +20558 -0
  34. package/dist/common/index.d.ts +955 -0
  35. package/dist/common/index.js +20643 -0
  36. package/dist/components/index.cjs +30056 -0
  37. package/dist/components/index.d.ts +1423 -0
  38. package/dist/components/index.js +25416 -0
  39. package/dist/core-events/index.cjs +167 -0
  40. package/dist/core-events/index.d.ts +313 -0
  41. package/dist/core-events/index.js +149 -0
  42. package/dist/core-server/index.cjs +37872 -0
  43. package/dist/core-server/index.d.ts +462 -0
  44. package/dist/core-server/index.js +37966 -0
  45. package/dist/core-server/presets/common-manager.js +28 -0
  46. package/dist/core-server/presets/common-override-preset.cjs +4824 -0
  47. package/dist/core-server/presets/common-override-preset.js +4829 -0
  48. package/dist/core-server/presets/common-preset.cjs +10228 -0
  49. package/dist/core-server/presets/common-preset.js +10306 -0
  50. package/dist/csf/index.cjs +223 -0
  51. package/dist/csf/index.d.ts +752 -0
  52. package/dist/csf/index.js +216 -0
  53. package/dist/csf-tools/index.cjs +1422 -0
  54. package/dist/csf-tools/index.d.ts +250 -0
  55. package/dist/csf-tools/index.js +1439 -0
  56. package/dist/docs-tools/index.cjs +923 -0
  57. package/dist/docs-tools/index.d.ts +162 -0
  58. package/dist/docs-tools/index.js +909 -0
  59. package/dist/index.cjs +17 -1
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.js +2 -7
  62. package/dist/instrumenter/index.cjs +3273 -0
  63. package/dist/instrumenter/index.d.ts +104 -0
  64. package/dist/instrumenter/index.js +4800 -0
  65. package/dist/manager/globals-module-info.cjs +666 -0
  66. package/dist/manager/globals-module-info.d.ts +36 -0
  67. package/dist/manager/globals-module-info.js +653 -0
  68. package/dist/manager/globals-runtime.js +41567 -0
  69. package/dist/manager/globals.cjs +43 -0
  70. package/dist/manager/globals.d.ts +21 -0
  71. package/dist/manager/globals.js +30 -0
  72. package/dist/manager/runtime.js +12043 -0
  73. package/dist/manager-api/index.cjs +10772 -0
  74. package/dist/manager-api/index.d.ts +1211 -0
  75. package/dist/manager-api/index.js +4547 -0
  76. package/dist/manager-errors.d.ts +65 -0
  77. package/dist/manager-errors.js +83 -0
  78. package/dist/node-logger/index.cjs +1642 -0
  79. package/dist/node-logger/index.d.ts +117 -0
  80. package/dist/node-logger/index.js +1652 -0
  81. package/dist/preview/globals.cjs +34 -0
  82. package/dist/preview/globals.d.ts +12 -0
  83. package/dist/preview/globals.js +21 -0
  84. package/dist/preview/runtime.js +7723 -0
  85. package/dist/preview-api/index.cjs +5658 -0
  86. package/dist/preview-api/index.d.ts +1356 -0
  87. package/dist/preview-api/index.js +5665 -0
  88. package/dist/preview-errors.cjs +486 -0
  89. package/dist/preview-errors.d.ts +188 -0
  90. package/dist/preview-errors.js +433 -0
  91. package/dist/router/index.cjs +3320 -0
  92. package/dist/router/index.d.ts +385 -0
  93. package/dist/router/index.js +1849 -0
  94. package/dist/server-errors.cjs +710 -0
  95. package/dist/server-errors.d.ts +272 -0
  96. package/dist/server-errors.js +711 -0
  97. package/dist/telemetry/index.cjs +3683 -0
  98. package/dist/telemetry/index.d.ts +112 -0
  99. package/dist/telemetry/index.js +3720 -0
  100. package/dist/theming/create.cjs +2422 -0
  101. package/dist/theming/create.d.ts +50 -0
  102. package/dist/theming/create.js +990 -0
  103. package/dist/theming/index.cjs +4832 -0
  104. package/dist/theming/index.d.ts +11939 -0
  105. package/dist/theming/index.js +3253 -0
  106. package/dist/types/index.cjs +27 -0
  107. package/dist/types/index.d.ts +2541 -0
  108. package/dist/types/index.js +7 -0
  109. package/package.json +308 -212
  110. package/.eslintrc.cjs +0 -31
  111. package/__mocks__/@aw-web-design/x-default-browser.js +0 -2
  112. package/core/babel/index.cjs +0 -1
  113. package/core/babel/index.d.ts +0 -2
  114. package/core/babel/index.js +0 -1
  115. package/core/builder-manager/index.cjs +0 -1
  116. package/core/builder-manager/index.d.ts +0 -2
  117. package/core/builder-manager/index.js +0 -1
  118. package/core/channels/index.cjs +0 -1
  119. package/core/channels/index.d.ts +0 -2
  120. package/core/channels/index.js +0 -1
  121. package/core/cli/bin/index.cjs +0 -1
  122. package/core/cli/bin/index.d.ts +0 -2
  123. package/core/cli/bin/index.js +0 -1
  124. package/core/cli/index.cjs +0 -1
  125. package/core/cli/index.d.ts +0 -2
  126. package/core/cli/index.js +0 -1
  127. package/core/client-logger/index.cjs +0 -1
  128. package/core/client-logger/index.d.ts +0 -2
  129. package/core/client-logger/index.js +0 -1
  130. package/core/common/index.cjs +0 -1
  131. package/core/common/index.d.ts +0 -2
  132. package/core/common/index.js +0 -1
  133. package/core/components/index.cjs +0 -1
  134. package/core/components/index.d.ts +0 -2
  135. package/core/components/index.js +0 -1
  136. package/core/core-events/index.cjs +0 -1
  137. package/core/core-events/index.d.ts +0 -2
  138. package/core/core-events/index.js +0 -1
  139. package/core/core-server/index.cjs +0 -1
  140. package/core/core-server/index.d.ts +0 -2
  141. package/core/core-server/index.js +0 -1
  142. package/core/core-server/presets/common-manager.js +0 -1
  143. package/core/core-server/presets/common-override-preset.cjs +0 -1
  144. package/core/core-server/presets/common-override-preset.js +0 -1
  145. package/core/core-server/presets/common-preset.cjs +0 -1
  146. package/core/core-server/presets/common-preset.js +0 -1
  147. package/core/csf/index.cjs +0 -1
  148. package/core/csf/index.d.ts +0 -2
  149. package/core/csf/index.js +0 -1
  150. package/core/csf-tools/index.cjs +0 -1
  151. package/core/csf-tools/index.d.ts +0 -2
  152. package/core/csf-tools/index.js +0 -1
  153. package/core/docs-tools/index.cjs +0 -1
  154. package/core/docs-tools/index.d.ts +0 -2
  155. package/core/docs-tools/index.js +0 -1
  156. package/core/index.cjs +0 -1
  157. package/core/index.d.ts +0 -2
  158. package/core/index.js +0 -1
  159. package/core/manager/globals-module-info.cjs +0 -1
  160. package/core/manager/globals-module-info.d.ts +0 -2
  161. package/core/manager/globals-module-info.js +0 -1
  162. package/core/manager/globals-runtime.js +0 -1
  163. package/core/manager/globals.cjs +0 -1
  164. package/core/manager/globals.d.ts +0 -2
  165. package/core/manager/globals.js +0 -1
  166. package/core/manager-api/index.cjs +0 -1
  167. package/core/manager-api/index.d.ts +0 -2
  168. package/core/manager-api/index.js +0 -1
  169. package/core/manager-errors.d.ts +0 -2
  170. package/core/manager-errors.js +0 -1
  171. package/core/node-logger/index.cjs +0 -1
  172. package/core/node-logger/index.d.ts +0 -2
  173. package/core/node-logger/index.js +0 -1
  174. package/core/preview/globals.cjs +0 -1
  175. package/core/preview/globals.d.ts +0 -2
  176. package/core/preview/globals.js +0 -1
  177. package/core/preview/runtime.js +0 -1
  178. package/core/preview-api/index.cjs +0 -1
  179. package/core/preview-api/index.d.ts +0 -2
  180. package/core/preview-api/index.js +0 -1
  181. package/core/preview-errors.cjs +0 -1
  182. package/core/preview-errors.d.ts +0 -2
  183. package/core/preview-errors.js +0 -1
  184. package/core/router/index.cjs +0 -1
  185. package/core/router/index.d.ts +0 -2
  186. package/core/router/index.js +0 -1
  187. package/core/server-errors.cjs +0 -1
  188. package/core/server-errors.d.ts +0 -2
  189. package/core/server-errors.js +0 -1
  190. package/core/telemetry/index.cjs +0 -1
  191. package/core/telemetry/index.d.ts +0 -2
  192. package/core/telemetry/index.js +0 -1
  193. package/core/theming/create.cjs +0 -1
  194. package/core/theming/create.d.ts +0 -2
  195. package/core/theming/create.js +0 -1
  196. package/core/theming/index.cjs +0 -1
  197. package/core/theming/index.d.ts +0 -2
  198. package/core/theming/index.js +0 -1
  199. package/core/types/index.cjs +0 -1
  200. package/core/types/index.d.ts +0 -2
  201. package/core/types/index.js +0 -1
  202. package/core.cjs +0 -0
  203. package/core.d.ts +0 -0
  204. package/core.js +0 -1
  205. package/dist/chunk-OWLSIX54.js +0 -8
  206. package/dist/core-path.cjs +0 -1
  207. package/dist/core-path.d.ts +0 -3
  208. package/dist/core-path.js +0 -9
  209. package/dist/proxy.cjs +0 -1
  210. package/dist/proxy.d.ts +0 -2
  211. package/dist/proxy.js +0 -9
@@ -0,0 +1,1439 @@
1
+ import ESM_COMPAT_Module from "node:module";
2
+ import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url';
3
+ import { dirname as ESM_COMPAT_dirname } from 'node:path';
4
+ const __filename = ESM_COMPAT_fileURLToPath(import.meta.url);
5
+ const __dirname = ESM_COMPAT_dirname(__filename);
6
+ const require = ESM_COMPAT_Module.createRequire(import.meta.url);
7
+ var ke = Object.create;
8
+ var G = Object.defineProperty;
9
+ var Ve = Object.getOwnPropertyDescriptor;
10
+ var Ae = Object.getOwnPropertyNames;
11
+ var $e = Object.getPrototypeOf, Re = Object.prototype.hasOwnProperty;
12
+ var p = (s, e) => G(s, "name", { value: e, configurable: !0 });
13
+ var Le = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports);
14
+ var Me = (s, e, i, t) => {
15
+ if (e && typeof e == "object" || typeof e == "function")
16
+ for (let r of Ae(e))
17
+ !Re.call(s, r) && r !== i && G(s, r, { get: () => e[r], enumerable: !(t = Ve(e, r)) || t.enumerable });
18
+ return s;
19
+ };
20
+ var M = (s, e, i) => (i = s != null ? ke($e(s)) : {}, Me(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ e || !s || !s.__esModule ? G(i, "default", { value: s, enumerable: !0 }) : i,
26
+ s
27
+ ));
28
+
29
+ // ../node_modules/ts-dedent/dist/index.js
30
+ var k = Le((T) => {
31
+ "use strict";
32
+ Object.defineProperty(T, "__esModule", { value: !0 });
33
+ T.dedent = void 0;
34
+ function ie(s) {
35
+ for (var e = [], i = 1; i < arguments.length; i++)
36
+ e[i - 1] = arguments[i];
37
+ var t = Array.from(typeof s == "string" ? [s] : s);
38
+ t[t.length - 1] = t[t.length - 1].replace(/\r?\n([\t ]*)$/, "");
39
+ var r = t.reduce(function(l, f) {
40
+ var m = f.match(/\n([\t ]+|(?!\s).)/g);
41
+ return m ? l.concat(m.map(function(g) {
42
+ var x, b;
43
+ return (b = (x = g.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && b !== void 0 ? b : 0;
44
+ })) : l;
45
+ }, []);
46
+ if (r.length) {
47
+ var o = new RegExp(`
48
+ [ ]{` + Math.min.apply(Math, r) + "}", "g");
49
+ t = t.map(function(l) {
50
+ return l.replace(o, `
51
+ `);
52
+ });
53
+ }
54
+ t[0] = t[0].replace(/^\r?\n/, "");
55
+ var a = t[0];
56
+ return e.forEach(function(l, f) {
57
+ var m = a.match(/(?:^|\n)( *)$/), g = m ? m[1] : "", x = l;
58
+ typeof l == "string" && l.includes(`
59
+ `) && (x = String(l).split(`
60
+ `).map(function(b, y) {
61
+ return y === 0 ? b : "" + g + b;
62
+ }).join(`
63
+ `)), a += x + t[f + 1];
64
+ }), a;
65
+ }
66
+ p(ie, "dedent");
67
+ T.dedent = ie;
68
+ T.default = ie;
69
+ });
70
+
71
+ // src/csf-tools/CsfFile.ts
72
+ var O = M(k(), 1);
73
+ import { readFile as Ue, writeFile as qe } from "node:fs/promises";
74
+ import {
75
+ BabelFileClass as Be,
76
+ babelParse as pe,
77
+ generate as We,
78
+ recast as fe,
79
+ types as c,
80
+ traverse as Ge
81
+ } from "storybook/internal/babel";
82
+ import { isExportStory as se, storyNameFromExport as ne, toId as ze } from "storybook/internal/csf";
83
+
84
+ // src/csf-tools/findVarInitialization.ts
85
+ import { types as V } from "storybook/internal/babel";
86
+ var P = /* @__PURE__ */ p((s, e) => {
87
+ let i = null, t = null;
88
+ return e.body.find((r) => (V.isVariableDeclaration(r) ? t = r.declarations : V.isExportNamedDeclaration(r) && V.isVariableDeclaration(r.declaration) &&
89
+ (t = r.declaration.declarations), t && t.find((o) => V.isVariableDeclarator(o) && V.isIdentifier(o.id) && o.id.name === s ? (i = o.init, !0) :
90
+ !1))), i;
91
+ }, "findVarInitialization");
92
+
93
+ // src/csf-tools/CsfFile.ts
94
+ var oe = console, Xe = /\/preview(.(js|jsx|mjs|ts|tsx))?$/, Ke = /* @__PURE__ */ p((s) => Xe.test(s), "isValidPreviewPath");
95
+ function Je(s) {
96
+ if (c.isArrayExpression(s))
97
+ return s.elements.map((e) => {
98
+ if (c.isStringLiteral(e))
99
+ return e.value;
100
+ throw new Error(`Expected string literal: ${e}`);
101
+ });
102
+ if (c.isStringLiteral(s))
103
+ return new RegExp(s.value);
104
+ if (c.isRegExpLiteral(s))
105
+ return new RegExp(s.pattern, s.flags);
106
+ throw new Error(`Unknown include/exclude: ${s}`);
107
+ }
108
+ p(Je, "parseIncludeExclude");
109
+ function ae(s) {
110
+ if (!c.isArrayExpression(s))
111
+ throw new Error("CSF: Expected tags array");
112
+ return s.elements.map((e) => {
113
+ if (c.isStringLiteral(e))
114
+ return e.value;
115
+ throw new Error("CSF: Expected tag to be string literal");
116
+ });
117
+ }
118
+ p(ae, "parseTags");
119
+ var I = /* @__PURE__ */ p((s, e) => {
120
+ let i = "";
121
+ if (s.loc) {
122
+ let { line: t, column: r } = s.loc?.start || {};
123
+ i = `(line ${t}, col ${r})`;
124
+ }
125
+ return `${e || ""} ${i}`.trim();
126
+ }, "formatLocation"), Qe = /* @__PURE__ */ p((s) => Ze.test(s), "isModuleMock"), le = /* @__PURE__ */ p((s, e, i) => {
127
+ let t = s;
128
+ if (c.isCallExpression(s)) {
129
+ let { callee: r, arguments: o } = s;
130
+ if (c.isProgram(e) && c.isMemberExpression(r) && c.isIdentifier(r.object) && c.isIdentifier(r.property) && r.property.name === "bind" &&
131
+ (o.length === 0 || o.length === 1 && c.isObjectExpression(o[0]) && o[0].properties.length === 0)) {
132
+ let a = r.object.name, l = P(a, e);
133
+ l && (i._templates[a] = l, t = l);
134
+ }
135
+ }
136
+ return c.isArrowFunctionExpression(t) || c.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
137
+ }, "isArgsStory"), He = /* @__PURE__ */ p((s) => {
138
+ if (c.isArrayExpression(s))
139
+ return s.elements.map((e) => {
140
+ if (c.isStringLiteral(e))
141
+ return e.value;
142
+ throw new Error(`Expected string literal named export: ${e}`);
143
+ });
144
+ throw new Error(`Expected array of string literals: ${s}`);
145
+ }, "parseExportsOrder"), ce = /* @__PURE__ */ p((s, e) => e.reduce(
146
+ (i, t) => {
147
+ let r = s[t];
148
+ return r && (i[t] = r), i;
149
+ },
150
+ {}
151
+ ), "sortExports"), Ye = /* @__PURE__ */ p((s) => {
152
+ if (c.isArrowFunctionExpression(s) || c.isFunctionDeclaration(s)) {
153
+ let e = s.params;
154
+ if (e.length >= 1) {
155
+ let [i] = e;
156
+ if (c.isObjectPattern(i))
157
+ return !!i.properties.find((t) => {
158
+ if (c.isObjectProperty(t) && c.isIdentifier(t.key))
159
+ return t.key.name === "mount";
160
+ });
161
+ }
162
+ }
163
+ return !1;
164
+ }, "hasMount"), Ze = /^[.\/#].*\.mock($|\.[^.]*$)/i, U = class extends Error {
165
+ static {
166
+ p(this, "NoMetaError");
167
+ }
168
+ constructor(e, i, t) {
169
+ let r = "".trim();
170
+ super(O.dedent`
171
+ CSF: ${e} ${I(i, t)}
172
+
173
+ More info: https://storybook.js.org/docs/writing-stories#default-export
174
+ `), this.name = this.constructor.name;
175
+ }
176
+ }, z = class extends Error {
177
+ static {
178
+ p(this, "MultipleMetaError");
179
+ }
180
+ constructor(e, i, t) {
181
+ let r = `${e} ${I(i, t)}`.trim();
182
+ super(O.dedent`
183
+ CSF: ${e} ${I(i, t)}
184
+
185
+ More info: https://storybook.js.org/docs/writing-stories#default-export
186
+ `), this.name = this.constructor.name;
187
+ }
188
+ }, q = class extends Error {
189
+ static {
190
+ p(this, "MixedFactoryError");
191
+ }
192
+ constructor(e, i, t) {
193
+ let r = `${e} ${I(i, t)}`.trim();
194
+ super(O.dedent`
195
+ CSF: ${e} ${I(i, t)}
196
+
197
+ More info: https://storybook.js.org/docs/writing-stories#default-export
198
+ `), this.name = this.constructor.name;
199
+ }
200
+ }, B = class extends Error {
201
+ static {
202
+ p(this, "BadMetaError");
203
+ }
204
+ constructor(e, i, t) {
205
+ let r = "".trim();
206
+ super(O.dedent`
207
+ CSF: ${e} ${I(i, t)}
208
+
209
+ More info: https://storybook.js.org/docs/writing-stories#default-export
210
+ `), this.name = this.constructor.name;
211
+ }
212
+ }, X = class {
213
+ constructor(e, i, t) {
214
+ this._stories = {};
215
+ this._metaAnnotations = {};
216
+ this._storyExports = {};
217
+ this._storyPaths = {};
218
+ this._storyStatements = {};
219
+ this._storyAnnotations = {};
220
+ this._templates = {};
221
+ this._ast = e, this._file = t, this._options = i, this.imports = [];
222
+ }
223
+ static {
224
+ p(this, "CsfFile");
225
+ }
226
+ /** @deprecated Use `_options.fileName` instead */
227
+ get _fileName() {
228
+ return this._options.fileName;
229
+ }
230
+ /** @deprecated Use `_options.makeTitle` instead */
231
+ get _makeTitle() {
232
+ return this._options.makeTitle;
233
+ }
234
+ _parseTitle(e) {
235
+ let i = c.isIdentifier(e) ? P(e.name, this._ast.program) : e;
236
+ if (c.isStringLiteral(i))
237
+ return i.value;
238
+ if (c.isTSSatisfiesExpression(i) && c.isStringLiteral(i.expression))
239
+ return i.expression.value;
240
+ throw new Error(O.dedent`
241
+ CSF: unexpected dynamic title ${I(i, this._options.fileName)}
242
+
243
+ More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
244
+ `);
245
+ }
246
+ _parseMeta(e, i) {
247
+ if (this._metaNode)
248
+ throw new z("multiple meta objects", e, this._options.fileName);
249
+ this._metaNode = e;
250
+ let t = {};
251
+ e.properties.forEach((r) => {
252
+ if (c.isIdentifier(r.key)) {
253
+ if (this._metaAnnotations[r.key.name] = r.value, r.key.name === "title")
254
+ t.title = this._parseTitle(r.value);
255
+ else if (["includeStories", "excludeStories"].includes(r.key.name))
256
+ t[r.key.name] = Je(r.value);
257
+ else if (r.key.name === "component") {
258
+ let o = r.value;
259
+ if (c.isIdentifier(o)) {
260
+ let l = o.name, f = i.body.find(
261
+ (m) => c.isImportDeclaration(m) && m.specifiers.find((g) => g.local.name === l)
262
+ );
263
+ if (f) {
264
+ let { source: m } = f;
265
+ c.isStringLiteral(m) && (this._rawComponentPath = m.value);
266
+ }
267
+ }
268
+ let { code: a } = fe.print(r.value, {});
269
+ t.component = a;
270
+ } else if (r.key.name === "tags") {
271
+ let o = r.value;
272
+ c.isIdentifier(o) && (o = P(o.name, this._ast.program)), t.tags = ae(o);
273
+ } else if (r.key.name === "id")
274
+ if (c.isStringLiteral(r.value))
275
+ t.id = r.value.value;
276
+ else
277
+ throw new Error(`Unexpected component id: ${r.value}`);
278
+ }
279
+ }), this._meta = t;
280
+ }
281
+ getStoryExport(e) {
282
+ let i = this._storyExports[e];
283
+ if (i = c.isVariableDeclarator(i) ? i.init : i, c.isCallExpression(i)) {
284
+ let { callee: t, arguments: r } = i;
285
+ if (c.isMemberExpression(t) && c.isIdentifier(t.object) && c.isIdentifier(t.property) && t.property.name === "bind" && (r.length === 0 ||
286
+ r.length === 1 && c.isObjectExpression(r[0]) && r[0].properties.length === 0)) {
287
+ let { name: o } = t.object;
288
+ i = this._templates[o];
289
+ }
290
+ }
291
+ return i;
292
+ }
293
+ parse() {
294
+ let e = this;
295
+ if (Ge(this._ast, {
296
+ ExportDefaultDeclaration: {
297
+ enter(t) {
298
+ let { node: r, parent: o } = t, a = c.isIdentifier(r.declaration) && c.isProgram(o);
299
+ if (e._options.transformInlineMeta && !a && c.isExpression(r.declaration)) {
300
+ let m = t.scope.generateUidIdentifier("meta");
301
+ e._metaVariableName = m.name;
302
+ let g = [
303
+ c.variableDeclaration("const", [c.variableDeclarator(m, r.declaration)]),
304
+ c.exportDefaultDeclaration(m)
305
+ ];
306
+ g.forEach((x) => x.loc = t.node.loc), t.replaceWithMultiple(g);
307
+ return;
308
+ }
309
+ let l, f;
310
+ if (a) {
311
+ let m = r.declaration.name;
312
+ e._metaVariableName = m;
313
+ let g = /* @__PURE__ */ p((x) => c.isIdentifier(x.id) && x.id.name === m, "isVariableDeclarator");
314
+ e._metaStatement = e._ast.program.body.find(
315
+ (x) => c.isVariableDeclaration(x) && x.declarations.find(g)
316
+ ), f = (e?._metaStatement?.declarations || []).find(
317
+ g
318
+ )?.init;
319
+ } else
320
+ e._metaStatement = r, f = r.declaration;
321
+ if (c.isObjectExpression(f) ? l = f : (
322
+ // export default { ... } as Meta<...>
323
+ (c.isTSAsExpression(f) || c.isTSSatisfiesExpression(f)) && c.isObjectExpression(f.expression) && (l = f.expression)
324
+ ), l && c.isProgram(o) && e._parseMeta(l, o), e._metaStatement && !e._metaNode)
325
+ throw new U(
326
+ "default export must be an object",
327
+ e._metaStatement,
328
+ e._options.fileName
329
+ );
330
+ e._metaPath = t;
331
+ }
332
+ },
333
+ ExportNamedDeclaration: {
334
+ enter(t) {
335
+ let { node: r, parent: o } = t, a;
336
+ c.isVariableDeclaration(r.declaration) ? a = r.declaration.declarations.filter((l) => c.isVariableDeclarator(l)) : c.isFunctionDeclaration(
337
+ r.declaration) && (a = [r.declaration]), a ? a.forEach((l) => {
338
+ if (c.isIdentifier(l.id)) {
339
+ let f = !1, { name: m } = l.id;
340
+ if (m === "__namedExportsOrder" && c.isVariableDeclarator(l)) {
341
+ e._namedExportsOrder = He(l.init);
342
+ return;
343
+ }
344
+ e._storyExports[m] = l, e._storyPaths[m] = t, e._storyStatements[m] = r;
345
+ let g = ne(m);
346
+ e._storyAnnotations[m] ? oe.warn(
347
+ `Unexpected annotations for "${m}" before story declaration`
348
+ ) : e._storyAnnotations[m] = {};
349
+ let x;
350
+ if (c.isVariableDeclarator(l) ? x = c.isTSAsExpression(l.init) || c.isTSSatisfiesExpression(l.init) ? l.init.expression : l.init :
351
+ x = l, c.isCallExpression(x) && c.isMemberExpression(x.callee) && c.isIdentifier(x.callee.property) && x.callee.property.name ===
352
+ "story" && (f = !0, x = x.arguments[0]), e._metaIsFactory && !f)
353
+ throw new q(
354
+ "expected factory story",
355
+ x,
356
+ e._options.fileName
357
+ );
358
+ if (!e._metaIsFactory && f)
359
+ throw e._metaNode ? new q(
360
+ "expected non-factory story",
361
+ x,
362
+ e._options.fileName
363
+ ) : new B(
364
+ "meta() factory must be imported from .storybook/preview configuration",
365
+ x,
366
+ e._options.fileName
367
+ );
368
+ let b = {};
369
+ c.isObjectExpression(x) ? (b.__isArgsStory = !0, x.properties.forEach((y) => {
370
+ if (c.isIdentifier(y.key)) {
371
+ if (y.key.name === "render")
372
+ b.__isArgsStory = le(
373
+ y.value,
374
+ o,
375
+ e
376
+ );
377
+ else if (y.key.name === "name" && c.isStringLiteral(y.value))
378
+ g = y.value.value;
379
+ else if (y.key.name === "storyName" && c.isStringLiteral(y.value))
380
+ oe.warn(
381
+ `Unexpected usage of "storyName" in "${m}". Please use "name" instead.`
382
+ );
383
+ else if (y.key.name === "parameters" && c.isObjectExpression(y.value)) {
384
+ let h = y.value.properties.find(
385
+ (D) => c.isObjectProperty(D) && c.isIdentifier(D.key) && D.key.name === "__id"
386
+ );
387
+ h && (b.__id = h.value.value);
388
+ }
389
+ e._storyAnnotations[m][y.key.name] = y.value;
390
+ }
391
+ })) : b.__isArgsStory = le(x, o, e), e._stories[m] = {
392
+ id: "FIXME",
393
+ name: g,
394
+ parameters: b,
395
+ __stats: {
396
+ factory: f
397
+ }
398
+ };
399
+ }
400
+ }) : r.specifiers.length > 0 && r.specifiers.forEach((l) => {
401
+ if (c.isExportSpecifier(l) && c.isIdentifier(l.exported)) {
402
+ let { name: f } = l.exported, { name: m } = l.local, g = c.isProgram(o) ? P(l.local.name, o) : l.local;
403
+ if (f === "default") {
404
+ let x;
405
+ c.isObjectExpression(g) ? x = g : (
406
+ // export default { ... } as Meta<...>
407
+ c.isTSAsExpression(g) && c.isObjectExpression(g.expression) && (x = g.expression)
408
+ ), x && c.isProgram(o) && e._parseMeta(x, o);
409
+ } else
410
+ e._storyAnnotations[f] = {}, e._storyStatements[f] = g, e._storyPaths[f] = t, e._stories[f] = {
411
+ id: "FIXME",
412
+ name: f,
413
+ localName: m,
414
+ parameters: {},
415
+ __stats: {}
416
+ };
417
+ }
418
+ });
419
+ }
420
+ },
421
+ ExpressionStatement: {
422
+ enter({ node: t, parent: r }) {
423
+ let { expression: o } = t;
424
+ if (c.isProgram(r) && c.isAssignmentExpression(o) && c.isMemberExpression(o.left) && c.isIdentifier(o.left.object) && c.isIdentifier(
425
+ o.left.property)) {
426
+ let a = o.left.object.name, l = o.left.property.name, f = o.right;
427
+ if (e._storyAnnotations[a] && (l === "story" && c.isObjectExpression(f) ? f.properties.forEach((m) => {
428
+ c.isIdentifier(m.key) && (e._storyAnnotations[a][m.key.name] = m.value);
429
+ }) : e._storyAnnotations[a][l] = f), l === "storyName" && c.isStringLiteral(f)) {
430
+ let m = f.value, g = e._stories[a];
431
+ if (!g)
432
+ return;
433
+ g.name = m;
434
+ }
435
+ }
436
+ }
437
+ },
438
+ CallExpression: {
439
+ enter(t) {
440
+ let { node: r } = t, { callee: o } = r;
441
+ if (c.isIdentifier(o) && o.name === "storiesOf")
442
+ throw new Error(O.dedent`
443
+ Unexpected \`storiesOf\` usage: ${I(r, e._options.fileName)}.
444
+
445
+ SB8 does not support \`storiesOf\`.
446
+ `);
447
+ if (c.isMemberExpression(o) && c.isIdentifier(o.property) && o.property.name === "meta" && c.isIdentifier(o.object) && r.arguments.
448
+ length > 0) {
449
+ let l = t.scope.getBinding(o.object.name)?.path?.parentPath?.node;
450
+ if (c.isImportDeclaration(l))
451
+ if (Ke(l.source.value)) {
452
+ let f = r.arguments[0];
453
+ e._metaVariableName = o.property.name, e._metaIsFactory = !0, e._parseMeta(f, e._ast.program);
454
+ } else
455
+ throw new B(
456
+ "meta() factory must be imported from .storybook/preview configuration",
457
+ l,
458
+ e._options.fileName
459
+ );
460
+ }
461
+ }
462
+ },
463
+ ImportDeclaration: {
464
+ enter({ node: t }) {
465
+ let { source: r } = t;
466
+ if (c.isStringLiteral(r))
467
+ e.imports.push(r.value);
468
+ else
469
+ throw new Error("CSF: unexpected import source");
470
+ }
471
+ }
472
+ }), !e._meta)
473
+ throw new U("missing default export", e._ast, e._options.fileName);
474
+ let i = Object.entries(e._stories);
475
+ if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
476
+ e._stories = i.reduce(
477
+ (t, [r, o]) => {
478
+ if (!se(r, e._meta))
479
+ return t;
480
+ let a = o.parameters?.__id ?? ze(e._meta?.id || e._meta?.title, ne(r)), l = { ...o.parameters, __id: a }, { includeStories: f } = e.
481
+ _meta || {};
482
+ r === "__page" && (i.length === 1 || Array.isArray(f) && f.length === 1) && (l.docsOnly = !0), t[r] = { ...o, id: a, parameters: l };
483
+ let m = e._storyAnnotations[r], { tags: g, play: x } = m;
484
+ if (g) {
485
+ let h = c.isIdentifier(g) ? P(g.name, this._ast.program) : g;
486
+ t[r].tags = ae(h);
487
+ }
488
+ x && (t[r].tags = [...t[r].tags || [], "play-fn"]);
489
+ let b = t[r].__stats;
490
+ ["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((h) => {
491
+ b[h] = !!m[h] || !!e._metaAnnotations[h];
492
+ });
493
+ let y = e.getStoryExport(r);
494
+ return b.storyFn = !!(c.isArrowFunctionExpression(y) || c.isFunctionDeclaration(y)), b.mount = Ye(m.play ?? e._metaAnnotations.play),
495
+ b.moduleMock = !!e.imports.find((h) => Qe(h)), t;
496
+ },
497
+ {}
498
+ ), Object.keys(e._storyExports).forEach((t) => {
499
+ se(t, e._meta) || (delete e._storyExports[t], delete e._storyAnnotations[t], delete e._storyStatements[t]);
500
+ }), e._namedExportsOrder) {
501
+ let t = Object.keys(e._storyExports);
502
+ e._storyExports = ce(e._storyExports, e._namedExportsOrder), e._stories = ce(e._stories, e._namedExportsOrder);
503
+ let r = Object.keys(e._storyExports);
504
+ if (t.length !== r.length)
505
+ throw new Error(
506
+ `Missing exports after sort: ${t.filter(
507
+ (o) => !r.includes(o)
508
+ )}`
509
+ );
510
+ }
511
+ return e;
512
+ }
513
+ get meta() {
514
+ return this._meta;
515
+ }
516
+ get stories() {
517
+ return Object.values(this._stories);
518
+ }
519
+ get indexInputs() {
520
+ let { fileName: e } = this._options;
521
+ if (!e)
522
+ throw new Error(
523
+ O.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
524
+ Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
525
+ );
526
+ return Object.entries(this._stories).map(([i, t]) => {
527
+ let r = [...this._meta?.tags ?? [], ...t.tags ?? []];
528
+ return {
529
+ type: "story",
530
+ importPath: e,
531
+ rawComponentPath: this._rawComponentPath,
532
+ exportName: i,
533
+ name: t.name,
534
+ title: this.meta?.title,
535
+ metaId: this.meta?.id,
536
+ tags: r,
537
+ __id: t.id,
538
+ __stats: t.__stats
539
+ };
540
+ });
541
+ }
542
+ }, et = /* @__PURE__ */ p(({
543
+ code: s,
544
+ filename: e = "",
545
+ ast: i
546
+ }) => new Be({ filename: e }, { code: s, ast: i ?? pe(s) }), "babelParseFile"), K = /* @__PURE__ */ p((s, e) => {
547
+ let i = pe(s), t = et({ code: s, filename: e.fileName, ast: i });
548
+ return new X(i, e, t);
549
+ }, "loadCsf"), de = /* @__PURE__ */ p((s, e = { sourceMaps: !1 }, i) => {
550
+ let t = We(s._ast, e, i);
551
+ return e.sourceMaps ? t : t.code;
552
+ }, "formatCsf"), tt = /* @__PURE__ */ p((s, e = {}) => fe.print(s._ast, e), "printCsf"), Ft = /* @__PURE__ */ p(async (s, e) => {
553
+ let i = (await Ue(s, "utf-8")).toString();
554
+ return K(i, { ...e, fileName: s });
555
+ }, "readCsf"), Ct = /* @__PURE__ */ p(async (s, e) => {
556
+ if (!(e || s._options.fileName))
557
+ throw new Error("Please specify a fileName for writeCsf");
558
+ await qe(e, tt(s).code);
559
+ }, "writeCsf");
560
+
561
+ // src/csf-tools/ConfigFile.ts
562
+ var xe = M(k(), 1);
563
+ import { readFile as rt, writeFile as it } from "node:fs/promises";
564
+ import {
565
+ babelParse as ge,
566
+ generate as me,
567
+ recast as st,
568
+ types as n,
569
+ traverse as ue
570
+ } from "storybook/internal/babel";
571
+ var J = console, Q = /* @__PURE__ */ p(({
572
+ expectedType: s,
573
+ foundType: e,
574
+ node: i
575
+ }) => xe.dedent`
576
+ CSF Parsing error: Expected '${s}' but found '${e}' instead in '${i?.type}'.
577
+ `, "getCsfParsingErrorMessage"), A = /* @__PURE__ */ p((s) => n.isIdentifier(s.key) ? s.key.name : n.isStringLiteral(s.key) ? s.key.value :
578
+ null, "propKey"), W = /* @__PURE__ */ p((s) => n.isTSAsExpression(s) || n.isTSSatisfiesExpression(s) ? W(s.expression) : s, "unwrap"), ye = /* @__PURE__ */ p(
579
+ (s, e) => {
580
+ if (s.length === 0)
581
+ return e;
582
+ if (n.isObjectExpression(e)) {
583
+ let [i, ...t] = s, r = e.properties.find((o) => A(o) === i);
584
+ if (r)
585
+ return ye(t, r.value);
586
+ }
587
+ }, "_getPath"), be = /* @__PURE__ */ p((s, e) => {
588
+ if (s.length === 0) {
589
+ if (n.isObjectExpression(e))
590
+ return e.properties;
591
+ throw new Error("Expected object expression");
592
+ }
593
+ if (n.isObjectExpression(e)) {
594
+ let [i, ...t] = s, r = e.properties.find((o) => A(o) === i);
595
+ if (r)
596
+ return t.length === 0 ? e.properties : be(t, r.value);
597
+ }
598
+ }, "_getPathProperties"), Ee = /* @__PURE__ */ p((s, e) => {
599
+ let i = null, t = null;
600
+ return e.body.find((r) => (n.isVariableDeclaration(r) ? t = r.declarations : n.isExportNamedDeclaration(r) && n.isVariableDeclaration(r.declaration) &&
601
+ (t = r.declaration.declarations), t && t.find((o) => n.isVariableDeclarator(o) && n.isIdentifier(o.id) && o.id.name === s ? (i = o, !0) : !1))),
602
+ i;
603
+ }, "_findVarDeclarator"), v = /* @__PURE__ */ p((s, e) => Ee(s, e)?.init, "_findVarInitialization"), $ = /* @__PURE__ */ p((s, e) => {
604
+ if (s.length === 0)
605
+ return e;
606
+ let [i, ...t] = s, r = $(t, e);
607
+ return n.objectExpression([n.objectProperty(n.identifier(i), r)]);
608
+ }, "_makeObjectExpression"), H = /* @__PURE__ */ p((s, e, i) => {
609
+ let [t, ...r] = s, o = i.properties.find(
610
+ (a) => A(a) === t
611
+ );
612
+ o ? n.isObjectExpression(o.value) && r.length > 0 ? H(r, e, o.value) : o.value = $(r, e) : i.properties.push(
613
+ n.objectProperty(n.identifier(t), $(r, e))
614
+ );
615
+ }, "_updateExportNode"), Y = class {
616
+ constructor(e, i, t) {
617
+ this._exports = {};
618
+ // FIXME: this is a hack. this is only used in the case where the user is
619
+ // modifying a named export that's a scalar. The _exports map is not suitable
620
+ // for that. But rather than refactor the whole thing, we just use this as a stopgap.
621
+ this._exportDecls = {};
622
+ this.hasDefaultExport = !1;
623
+ this._ast = e, this._code = i, this.fileName = t;
624
+ }
625
+ static {
626
+ p(this, "ConfigFile");
627
+ }
628
+ _parseExportsObject(e) {
629
+ this._exportsObject = e, e.properties.forEach((i) => {
630
+ let t = A(i);
631
+ if (t) {
632
+ let r = i.value;
633
+ n.isIdentifier(r) && (r = v(r.name, this._ast.program)), this._exports[t] = r;
634
+ }
635
+ });
636
+ }
637
+ parse() {
638
+ let e = this;
639
+ return ue(this._ast, {
640
+ ExportDefaultDeclaration: {
641
+ enter({ node: i, parent: t }) {
642
+ e.hasDefaultExport = !0;
643
+ let r = n.isIdentifier(i.declaration) && n.isProgram(t) ? v(i.declaration.name, t) : i.declaration;
644
+ r = W(r), n.isCallExpression(r) && n.isObjectExpression(r.arguments[0]) && (r = r.arguments[0]), n.isObjectExpression(r) ? e._parseExportsObject(
645
+ r) : J.warn(
646
+ Q({
647
+ expectedType: "ObjectExpression",
648
+ foundType: r?.type,
649
+ node: r || i.declaration
650
+ })
651
+ );
652
+ }
653
+ },
654
+ ExportNamedDeclaration: {
655
+ enter({ node: i, parent: t }) {
656
+ if (n.isVariableDeclaration(i.declaration))
657
+ i.declaration.declarations.forEach((r) => {
658
+ if (n.isVariableDeclarator(r) && n.isIdentifier(r.id)) {
659
+ let { name: o } = r.id, a = r.init;
660
+ n.isIdentifier(a) && (a = v(a.name, t)), e._exports[o] = a, e._exportDecls[o] = r;
661
+ }
662
+ });
663
+ else if (n.isFunctionDeclaration(i.declaration)) {
664
+ let r = i.declaration;
665
+ if (n.isIdentifier(r.id)) {
666
+ let { name: o } = r.id;
667
+ e._exportDecls[o] = r;
668
+ }
669
+ } else i.specifiers ? i.specifiers.forEach((r) => {
670
+ if (n.isExportSpecifier(r) && n.isIdentifier(r.local) && n.isIdentifier(r.exported)) {
671
+ let { name: o } = r.local, { name: a } = r.exported, l = Ee(o, t);
672
+ l && (e._exports[a] = l.init, e._exportDecls[a] = l);
673
+ }
674
+ }) : J.warn(
675
+ Q({
676
+ expectedType: "VariableDeclaration",
677
+ foundType: i.declaration?.type,
678
+ node: i.declaration
679
+ })
680
+ );
681
+ }
682
+ },
683
+ ExpressionStatement: {
684
+ enter({ node: i, parent: t }) {
685
+ if (n.isAssignmentExpression(i.expression) && i.expression.operator === "=") {
686
+ let { left: r, right: o } = i.expression;
687
+ if (n.isMemberExpression(r) && n.isIdentifier(r.object) && r.object.name === "module" && n.isIdentifier(r.property) && r.property.
688
+ name === "exports") {
689
+ let a = o;
690
+ n.isIdentifier(o) && (a = v(o.name, t)), a = W(a), n.isObjectExpression(a) ? (e._exportsObject = a, a.properties.forEach((l) => {
691
+ let f = A(l);
692
+ if (f) {
693
+ let m = l.value;
694
+ n.isIdentifier(m) && (m = v(
695
+ m.name,
696
+ t
697
+ )), e._exports[f] = m;
698
+ }
699
+ })) : J.warn(
700
+ Q({
701
+ expectedType: "ObjectExpression",
702
+ foundType: a?.type,
703
+ node: a
704
+ })
705
+ );
706
+ }
707
+ }
708
+ }
709
+ },
710
+ CallExpression: {
711
+ enter: /* @__PURE__ */ p(({ node: i }) => {
712
+ n.isIdentifier(i.callee) && i.callee.name === "definePreview" && i.arguments.length === 1 && n.isObjectExpression(i.arguments[0]) &&
713
+ e._parseExportsObject(i.arguments[0]);
714
+ }, "enter")
715
+ }
716
+ }), e;
717
+ }
718
+ getFieldNode(e) {
719
+ let [i, ...t] = e, r = this._exports[i];
720
+ if (r)
721
+ return ye(t, r);
722
+ }
723
+ getFieldProperties(e) {
724
+ let [i, ...t] = e, r = this._exports[i];
725
+ if (r)
726
+ return be(t, r);
727
+ }
728
+ getFieldValue(e) {
729
+ let i = this.getFieldNode(e);
730
+ if (i) {
731
+ let { code: t } = me(i, {});
732
+ return (0, eval)(`(() => (${t}))()`);
733
+ }
734
+ }
735
+ getSafeFieldValue(e) {
736
+ try {
737
+ return this.getFieldValue(e);
738
+ } catch {
739
+ }
740
+ }
741
+ setFieldNode(e, i) {
742
+ let [t, ...r] = e, o = this._exports[t];
743
+ if (this._exportsObject)
744
+ H(e, i, this._exportsObject), this._exports[e[0]] = i;
745
+ else if (o && n.isObjectExpression(o) && r.length > 0)
746
+ H(r, i, o);
747
+ else if (o && r.length === 0 && this._exportDecls[e[0]]) {
748
+ let a = this._exportDecls[e[0]];
749
+ n.isVariableDeclarator(a) && (a.init = $([], i));
750
+ } else {
751
+ if (this.hasDefaultExport)
752
+ throw new Error(
753
+ `Could not set the "${e.join(
754
+ "."
755
+ )}" field as the default export is not an object in this file.`
756
+ );
757
+ {
758
+ let a = $(r, i), l = n.exportNamedDeclaration(
759
+ n.variableDeclaration("const", [n.variableDeclarator(n.identifier(t), a)])
760
+ );
761
+ this._exports[t] = a, this._ast.program.body.push(l);
762
+ }
763
+ }
764
+ }
765
+ /**
766
+ * @example
767
+ *
768
+ * ```ts
769
+ * // 1. { framework: 'framework-name' }
770
+ * // 2. { framework: { name: 'framework-name', options: {} }
771
+ * getNameFromPath(['framework']); // => 'framework-name'
772
+ * ```
773
+ *
774
+ * @returns The name of a node in a given path, supporting the following formats:
775
+ */
776
+ getNameFromPath(e) {
777
+ let i = this.getFieldNode(e);
778
+ if (i)
779
+ return this._getPresetValue(i, "name");
780
+ }
781
+ /**
782
+ * Returns an array of names of a node in a given path, supporting the following formats:
783
+ *
784
+ * @example
785
+ *
786
+ * ```ts
787
+ * const config = {
788
+ * addons: ['first-addon', { name: 'second-addon', options: {} }],
789
+ * };
790
+ * // => ['first-addon', 'second-addon']
791
+ * getNamesFromPath(['addons']);
792
+ * ```
793
+ */
794
+ getNamesFromPath(e) {
795
+ let i = this.getFieldNode(e);
796
+ if (!i)
797
+ return;
798
+ let t = [];
799
+ return n.isArrayExpression(i) && i.elements.forEach((r) => {
800
+ t.push(this._getPresetValue(r, "name"));
801
+ }), t;
802
+ }
803
+ _getPnpWrappedValue(e) {
804
+ if (n.isCallExpression(e)) {
805
+ let i = e.arguments[0];
806
+ if (n.isStringLiteral(i))
807
+ return i.value;
808
+ }
809
+ }
810
+ /**
811
+ * Given a node and a fallback property, returns a **non-evaluated** string value of the node.
812
+ *
813
+ * 1. `{ node: 'value' }`
814
+ * 2. `{ node: { fallbackProperty: 'value' } }`
815
+ */
816
+ _getPresetValue(e, i) {
817
+ let t;
818
+ if (n.isStringLiteral(e) ? t = e.value : n.isObjectExpression(e) ? e.properties.forEach((r) => {
819
+ n.isObjectProperty(r) && n.isIdentifier(r.key) && r.key.name === i && (n.isStringLiteral(r.value) ? t = r.value.value : t = this._getPnpWrappedValue(
820
+ r.value)), n.isObjectProperty(r) && n.isStringLiteral(r.key) && r.key.value === "name" && n.isStringLiteral(r.value) && (t = r.value.value);
821
+ }) : n.isCallExpression(e) && (t = this._getPnpWrappedValue(e)), !t)
822
+ throw new Error(
823
+ `The given node must be a string literal or an object expression with a "${i}" property that is a string literal.`
824
+ );
825
+ return t;
826
+ }
827
+ removeField(e) {
828
+ let i = /* @__PURE__ */ p((r, o) => {
829
+ let a = r.findIndex(
830
+ (l) => n.isIdentifier(l.key) && l.key.name === o || n.isStringLiteral(l.key) && l.key.value === o
831
+ );
832
+ a >= 0 && r.splice(a, 1);
833
+ }, "removeProperty");
834
+ if (e.length === 1) {
835
+ let r = !1;
836
+ if (this._ast.program.body.forEach((o) => {
837
+ if (n.isExportNamedDeclaration(o) && n.isVariableDeclaration(o.declaration)) {
838
+ let a = o.declaration.declarations[0];
839
+ n.isIdentifier(a.id) && a.id.name === e[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(o), 1), r = !0);
840
+ }
841
+ if (n.isExportDefaultDeclaration(o)) {
842
+ let a = o.declaration;
843
+ if (n.isIdentifier(a) && (a = v(a.name, this._ast.program)), a = W(a), n.isObjectExpression(a)) {
844
+ let l = a.properties;
845
+ i(l, e[0]), r = !0;
846
+ }
847
+ }
848
+ if (n.isExpressionStatement(o) && n.isAssignmentExpression(o.expression) && n.isMemberExpression(o.expression.left) && n.isIdentifier(
849
+ o.expression.left.object) && o.expression.left.object.name === "module" && n.isIdentifier(o.expression.left.property) && o.expression.
850
+ left.property.name === "exports" && n.isObjectExpression(o.expression.right)) {
851
+ let a = o.expression.right.properties;
852
+ i(a, e[0]), r = !0;
853
+ }
854
+ }), r)
855
+ return;
856
+ }
857
+ let t = this.getFieldProperties(e);
858
+ if (t) {
859
+ let r = e.at(-1);
860
+ i(t, r);
861
+ }
862
+ }
863
+ appendValueToArray(e, i) {
864
+ let t = this.valueToNode(i);
865
+ t && this.appendNodeToArray(e, t);
866
+ }
867
+ appendNodeToArray(e, i) {
868
+ let t = this.getFieldNode(e);
869
+ if (!t)
870
+ this.setFieldNode(e, n.arrayExpression([i]));
871
+ else if (n.isArrayExpression(t))
872
+ t.elements.push(i);
873
+ else
874
+ throw new Error(`Expected array at '${e.join(".")}', got '${t.type}'`);
875
+ }
876
+ /**
877
+ * Specialized helper to remove addons or other array entries that can either be strings or
878
+ * objects with a name property.
879
+ */
880
+ removeEntryFromArray(e, i) {
881
+ let t = this.getFieldNode(e);
882
+ if (t)
883
+ if (n.isArrayExpression(t)) {
884
+ let r = t.elements.findIndex((o) => n.isStringLiteral(o) ? o.value === i : n.isObjectExpression(o) ? this._getPresetValue(o, "name") ===
885
+ i : this._getPnpWrappedValue(o) === i);
886
+ if (r >= 0)
887
+ t.elements.splice(r, 1);
888
+ else
889
+ throw new Error(`Could not find '${i}' in array at '${e.join(".")}'`);
890
+ } else
891
+ throw new Error(`Expected array at '${e.join(".")}', got '${t.type}'`);
892
+ }
893
+ _inferQuotes() {
894
+ if (!this._quotes) {
895
+ let e = (this._ast.tokens || []).slice(0, 500).reduce(
896
+ (i, t) => (t.type.label === "string" && (i[this._code[t.start]] += 1), i),
897
+ { "'": 0, '"': 0 }
898
+ );
899
+ this._quotes = e["'"] > e['"'] ? "single" : "double";
900
+ }
901
+ return this._quotes;
902
+ }
903
+ valueToNode(e) {
904
+ let i = this._inferQuotes(), t;
905
+ if (i === "single") {
906
+ let { code: r } = me(n.valueToNode(e), { jsescOption: { quotes: i } }), o = ge(`const __x = ${r}`);
907
+ ue(o, {
908
+ VariableDeclaration: {
909
+ enter({ node: a }) {
910
+ a.declarations.length === 1 && n.isVariableDeclarator(a.declarations[0]) && n.isIdentifier(a.declarations[0].id) && a.declarations[0].
911
+ id.name === "__x" && (t = a.declarations[0].init);
912
+ }
913
+ }
914
+ });
915
+ } else
916
+ t = n.valueToNode(e);
917
+ return t;
918
+ }
919
+ setFieldValue(e, i) {
920
+ let t = this.valueToNode(i);
921
+ if (!t)
922
+ throw new Error(`Unexpected value ${JSON.stringify(i)}`);
923
+ this.setFieldNode(e, t);
924
+ }
925
+ getBodyDeclarations() {
926
+ return this._ast.program.body;
927
+ }
928
+ setBodyDeclaration(e) {
929
+ this._ast.program.body.push(e);
930
+ }
931
+ /**
932
+ * Import specifiers for a specific require import
933
+ *
934
+ * @example
935
+ *
936
+ * ```ts
937
+ * // const { foo } = require('bar');
938
+ * setRequireImport(['foo'], 'bar');
939
+ *
940
+ * // const foo = require('bar');
941
+ * setRequireImport('foo', 'bar');
942
+ * ```
943
+ *
944
+ * @param importSpecifiers - The import specifiers to set. If a string is passed in, a default
945
+ * import will be set. Otherwise, an array of named imports will be set
946
+ * @param fromImport - The module to import from
947
+ */
948
+ setRequireImport(e, i) {
949
+ let t = this._ast.program.body.find(
950
+ (a) => n.isVariableDeclaration(a) && a.declarations.length === 1 && n.isVariableDeclarator(a.declarations[0]) && n.isCallExpression(a.
951
+ declarations[0].init) && n.isIdentifier(a.declarations[0].init.callee) && a.declarations[0].init.callee.name === "require" && n.isStringLiteral(
952
+ a.declarations[0].init.arguments[0]) && a.declarations[0].init.arguments[0].value === i
953
+ ), r = /* @__PURE__ */ p((a) => n.isObjectPattern(t?.declarations[0].id) && t?.declarations[0].id.properties.find(
954
+ (l) => n.isObjectProperty(l) && n.isIdentifier(l.key) && l.key.name === a
955
+ ), "hasRequireSpecifier"), o = /* @__PURE__ */ p((a, l) => a.declarations.length === 1 && n.isVariableDeclarator(a.declarations[0]) && n.
956
+ isIdentifier(a.declarations[0].id) && a.declarations[0].id.name === l, "hasDefaultRequireSpecifier");
957
+ if (typeof e == "string") {
958
+ let a = /* @__PURE__ */ p(() => {
959
+ this._ast.program.body.unshift(
960
+ n.variableDeclaration("const", [
961
+ n.variableDeclarator(
962
+ n.identifier(e),
963
+ n.callExpression(n.identifier("require"), [n.stringLiteral(i)])
964
+ )
965
+ ])
966
+ );
967
+ }, "addDefaultRequireSpecifier");
968
+ t && o(t, e) || a();
969
+ } else t ? e.forEach((a) => {
970
+ r(a) || t.declarations[0].id.properties.push(
971
+ n.objectProperty(n.identifier(a), n.identifier(a), void 0, !0)
972
+ );
973
+ }) : this._ast.program.body.unshift(
974
+ n.variableDeclaration("const", [
975
+ n.variableDeclarator(
976
+ n.objectPattern(
977
+ e.map(
978
+ (a) => n.objectProperty(n.identifier(a), n.identifier(a), void 0, !0)
979
+ )
980
+ ),
981
+ n.callExpression(n.identifier("require"), [n.stringLiteral(i)])
982
+ )
983
+ ])
984
+ );
985
+ }
986
+ /**
987
+ * Set import specifiers for a given import statement.
988
+ *
989
+ * Does not support setting type imports (yet)
990
+ *
991
+ * @example
992
+ *
993
+ * ```ts
994
+ * // import { foo } from 'bar';
995
+ * setImport(['foo'], 'bar');
996
+ *
997
+ * // import foo from 'bar';
998
+ * setImport('foo', 'bar');
999
+ *
1000
+ * // import * as foo from 'bar';
1001
+ * setImport({ namespace: 'foo' }, 'bar');
1002
+ *
1003
+ * // import 'bar';
1004
+ * setImport(null, 'bar');
1005
+ * ```
1006
+ *
1007
+ * @param importSpecifiers - The import specifiers to set. If a string is passed in, a default
1008
+ * import will be set. Otherwise, an array of named imports will be set
1009
+ * @param fromImport - The module to import from
1010
+ */
1011
+ setImport(e, i) {
1012
+ let t = /* @__PURE__ */ p((f) => n.importSpecifier(n.identifier(f), n.identifier(f)), "getNewImportSpecifier"), r = /* @__PURE__ */ p((f, m) => f.
1013
+ specifiers.find(
1014
+ (g) => n.isImportSpecifier(g) && n.isIdentifier(g.imported) && g.imported.name === m
1015
+ ), "hasImportSpecifier"), o = /* @__PURE__ */ p((f, m) => f.specifiers.find(
1016
+ (g) => n.isImportNamespaceSpecifier(g) && n.isIdentifier(g.local) && g.local.name === m
1017
+ ), "hasNamespaceImportSpecifier"), a = /* @__PURE__ */ p((f, m) => f.specifiers.find(
1018
+ (g) => n.isImportDefaultSpecifier(g) && n.isIdentifier(g.local) && g.local.name === m
1019
+ ), "hasDefaultImportSpecifier"), l = this._ast.program.body.find(
1020
+ (f) => n.isImportDeclaration(f) && f.source.value === i
1021
+ );
1022
+ e === null ? l || this._ast.program.body.unshift(n.importDeclaration([], n.stringLiteral(i))) : typeof e == "string" ? l ? a(l, e) || l.
1023
+ specifiers.push(
1024
+ n.importDefaultSpecifier(n.identifier(e))
1025
+ ) : this._ast.program.body.unshift(
1026
+ n.importDeclaration(
1027
+ [n.importDefaultSpecifier(n.identifier(e))],
1028
+ n.stringLiteral(i)
1029
+ )
1030
+ ) : Array.isArray(e) ? l ? e.forEach((f) => {
1031
+ r(l, f) || l.specifiers.push(t(f));
1032
+ }) : this._ast.program.body.unshift(
1033
+ n.importDeclaration(
1034
+ e.map(t),
1035
+ n.stringLiteral(i)
1036
+ )
1037
+ ) : e.namespace && (l ? o(l, e.namespace) || l.specifiers.push(
1038
+ n.importNamespaceSpecifier(n.identifier(e.namespace))
1039
+ ) : this._ast.program.body.unshift(
1040
+ n.importDeclaration(
1041
+ [n.importNamespaceSpecifier(n.identifier(e.namespace))],
1042
+ n.stringLiteral(i)
1043
+ )
1044
+ ));
1045
+ }
1046
+ }, nt = /* @__PURE__ */ p((s, e) => {
1047
+ let i = ge(s);
1048
+ return new Y(i, s, e);
1049
+ }, "loadConfig"), ot = /* @__PURE__ */ p((s) => at(s).code, "formatConfig"), at = /* @__PURE__ */ p((s, e = {}) => st.print(s._ast, e), "pri\
1050
+ ntConfig"), $t = /* @__PURE__ */ p(async (s) => {
1051
+ let e = (await rt(s, "utf-8")).toString();
1052
+ return nt(e, s).parse();
1053
+ }, "readConfig"), Rt = /* @__PURE__ */ p(async (s, e) => {
1054
+ let i = e || s.fileName;
1055
+ if (!i)
1056
+ throw new Error("Please specify a fileName for writeConfig");
1057
+ await it(i, ot(s));
1058
+ }, "writeConfig"), Lt = /* @__PURE__ */ p((s) => !!s._ast.program.body.find((i) => n.isImportDeclaration(i) && i.source.value.includes("@sto\
1059
+ rybook") && i.specifiers.some((t) => n.isImportSpecifier(t) && n.isIdentifier(t.imported) && t.imported.name === "definePreview")), "isCsfFa\
1060
+ ctoryPreview");
1061
+
1062
+ // src/csf-tools/getStorySortParameter.ts
1063
+ var je = M(k(), 1);
1064
+ import { babelParse as lt, generate as he, types as E, traverse as ct } from "storybook/internal/babel";
1065
+ var pt = console, Z = /* @__PURE__ */ p((s, e) => {
1066
+ let i;
1067
+ return s.properties.forEach((t) => {
1068
+ E.isIdentifier(t.key) && t.key.name === e && (i = t.value);
1069
+ }), i;
1070
+ }, "getValue"), ee = /* @__PURE__ */ p((s) => {
1071
+ let e = R(s);
1072
+ if (E.isArrayExpression(e))
1073
+ return e.elements.map((i) => ee(i));
1074
+ if (E.isObjectExpression(e))
1075
+ return e.properties.reduce((i, t) => (E.isIdentifier(t.key) && (i[t.key.name] = ee(t.value)), i), {});
1076
+ if (E.isLiteral(e))
1077
+ return e.value;
1078
+ if (E.isIdentifier(e))
1079
+ return w(e.name, !0);
1080
+ throw new Error(`Unknown node type ${e.type}`);
1081
+ }, "parseValue"), w = /* @__PURE__ */ p((s, e) => {
1082
+ let i = je.dedent`
1083
+ Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
1084
+
1085
+ export default {
1086
+ parameters: {
1087
+ options: {
1088
+ storySort: <array | object | function>
1089
+ },
1090
+ },
1091
+ };
1092
+ `;
1093
+ if (e)
1094
+ throw new Error(i);
1095
+ pt.info(i);
1096
+ }, "unsupported"), R = /* @__PURE__ */ p((s) => E.isTSAsExpression(s) || E.isTSSatisfiesExpression(s) ? s.expression : s, "stripTSModifiers"),
1097
+ Se = /* @__PURE__ */ p((s) => {
1098
+ let e = R(s);
1099
+ if (E.isObjectExpression(e)) {
1100
+ let i = Z(e, "options");
1101
+ if (i) {
1102
+ if (E.isObjectExpression(i))
1103
+ return Z(i, "storySort");
1104
+ w("options", !0);
1105
+ }
1106
+ }
1107
+ }, "parseParameters"), _e = /* @__PURE__ */ p((s, e) => {
1108
+ let i = R(s);
1109
+ if (E.isObjectExpression(i)) {
1110
+ let t = Z(i, "parameters");
1111
+ if (E.isIdentifier(t) && (t = P(t.name, e)), t)
1112
+ return Se(t);
1113
+ } else
1114
+ w("default", !0);
1115
+ }, "parseDefault"), Wt = /* @__PURE__ */ p((s) => {
1116
+ if (!s.includes("storySort"))
1117
+ return;
1118
+ let e, i = lt(s);
1119
+ if (ct(i, {
1120
+ ExportNamedDeclaration: {
1121
+ enter({ node: t }) {
1122
+ E.isVariableDeclaration(t.declaration) ? t.declaration.declarations.forEach((r) => {
1123
+ if (E.isVariableDeclarator(r) && E.isIdentifier(r.id)) {
1124
+ let { name: o } = r.id;
1125
+ if (o === "parameters" && r.init) {
1126
+ let a = R(r.init);
1127
+ e = Se(a);
1128
+ }
1129
+ }
1130
+ }) : t.specifiers.forEach((r) => {
1131
+ E.isIdentifier(r.exported) && r.exported.name === "parameters" && w("parameters", !1);
1132
+ });
1133
+ }
1134
+ },
1135
+ ExportDefaultDeclaration: {
1136
+ enter({ node: t }) {
1137
+ let r = t.declaration;
1138
+ E.isIdentifier(r) && (r = P(r.name, i.program)), r = R(r), E.isCallExpression(r) && E.isObjectExpression(r.arguments?.[0]) ? e = _e(
1139
+ r.arguments[0], i.program) : E.isObjectExpression(r) ? e = _e(r, i.program) : w("default", !1);
1140
+ }
1141
+ }
1142
+ }), !!e) {
1143
+ if (E.isArrowFunctionExpression(e)) {
1144
+ let { code: t } = he(e, {});
1145
+ return (0, eval)(t);
1146
+ }
1147
+ if (E.isFunctionExpression(e)) {
1148
+ let { code: t } = he(e, {}), r = e.id?.name, o = `(a, b) => {
1149
+ ${t};
1150
+ return ${r}(a, b)
1151
+ }`;
1152
+ return (0, eval)(o);
1153
+ }
1154
+ return E.isLiteral(e) || E.isArrayExpression(e) || E.isObjectExpression(e) ? ee(e) : w("storySort", !0);
1155
+ }
1156
+ }, "getStorySortParameter");
1157
+
1158
+ // src/csf-tools/enrichCsf.ts
1159
+ import { generate as ft, types as u } from "storybook/internal/babel";
1160
+ var dt = /* @__PURE__ */ p((s, e, i, t) => {
1161
+ let r = e.getStoryExport(i), o = u.isCallExpression(r) && u.isMemberExpression(r.callee) && u.isIdentifier(r.callee.object) && r.callee.object.
1162
+ name === "meta", a = !t?.disableSource && ut(r), l = !t?.disableDescription && Oe(e._storyStatements[i]), f = [], m = o ? u.memberExpression(
1163
+ u.identifier(i), u.identifier("input")) : u.identifier(i), g = u.memberExpression(m, u.identifier("parameters"));
1164
+ f.push(u.spreadElement(g));
1165
+ let x = u.optionalMemberExpression(
1166
+ g,
1167
+ u.identifier("docs"),
1168
+ !1,
1169
+ !0
1170
+ ), b = [];
1171
+ if (a) {
1172
+ let y = u.optionalMemberExpression(
1173
+ x,
1174
+ u.identifier("source"),
1175
+ !1,
1176
+ !0
1177
+ );
1178
+ b.push(
1179
+ u.objectProperty(
1180
+ u.identifier("source"),
1181
+ u.objectExpression([
1182
+ u.objectProperty(u.identifier("originalSource"), u.stringLiteral(a)),
1183
+ u.spreadElement(y)
1184
+ ])
1185
+ )
1186
+ );
1187
+ }
1188
+ if (l) {
1189
+ let y = u.optionalMemberExpression(
1190
+ x,
1191
+ u.identifier("description"),
1192
+ !1,
1193
+ !0
1194
+ );
1195
+ b.push(
1196
+ u.objectProperty(
1197
+ u.identifier("description"),
1198
+ u.objectExpression([
1199
+ u.objectProperty(u.identifier("story"), u.stringLiteral(l)),
1200
+ u.spreadElement(y)
1201
+ ])
1202
+ )
1203
+ );
1204
+ }
1205
+ if (b.length > 0) {
1206
+ f.push(
1207
+ u.objectProperty(
1208
+ u.identifier("docs"),
1209
+ u.objectExpression([u.spreadElement(x), ...b])
1210
+ )
1211
+ );
1212
+ let y = u.expressionStatement(
1213
+ u.assignmentExpression("=", g, u.objectExpression(f))
1214
+ );
1215
+ s._ast.program.body.push(y);
1216
+ }
1217
+ }, "enrichCsfStory"), Pe = /* @__PURE__ */ p((s, e, i) => {
1218
+ if (!e.length) {
1219
+ s.properties.find(
1220
+ (f) => u.isObjectProperty(f) && u.isIdentifier(f.key) && f.key.name === "component"
1221
+ ) || s.properties.unshift(i);
1222
+ return;
1223
+ }
1224
+ let [t, ...r] = e, o = s.properties.find(
1225
+ (l) => u.isObjectProperty(l) && u.isIdentifier(l.key) && l.key.name === t && u.isObjectExpression(l.value)
1226
+ ), a;
1227
+ o ? a = o.value : (a = u.objectExpression([]), s.properties.push(u.objectProperty(u.identifier(t), a))), Pe(a, r, i);
1228
+ }, "addComponentDescription"), mt = /* @__PURE__ */ p((s, e, i) => {
1229
+ let t = !i?.disableDescription && Oe(e._metaStatement);
1230
+ if (t) {
1231
+ let r = s._metaNode;
1232
+ r && u.isObjectExpression(r) && Pe(
1233
+ r,
1234
+ ["parameters", "docs", "description"],
1235
+ u.objectProperty(u.identifier("component"), u.stringLiteral(t))
1236
+ );
1237
+ }
1238
+ }, "enrichCsfMeta"), Kt = /* @__PURE__ */ p((s, e, i) => {
1239
+ mt(s, e, i), Object.keys(s._storyExports).forEach((t) => {
1240
+ dt(s, e, t, i);
1241
+ });
1242
+ }, "enrichCsf"), ut = /* @__PURE__ */ p((s) => {
1243
+ let e = u.isVariableDeclarator(s) ? s.init : s, { code: i } = ft(e, {});
1244
+ return i;
1245
+ }, "extractSource"), Oe = /* @__PURE__ */ p((s) => s?.leadingComments ? s.leadingComments.map((i) => i.type === "CommentLine" || !i.value.startsWith(
1246
+ "*") ? null : i.value.split(`
1247
+ `).map((t) => t.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
1248
+ `).trim()).filter(Boolean).join(`
1249
+ `) : "", "extractDescription");
1250
+
1251
+ // src/csf-tools/index.ts
1252
+ import { babelParse as cr } from "storybook/internal/babel";
1253
+
1254
+ // src/csf-tools/vitest-plugin/transformer.ts
1255
+ var te = M(k(), 1);
1256
+ import { types as d } from "storybook/internal/babel";
1257
+ import { getStoryTitle as gt } from "storybook/internal/common";
1258
+ import { combineTags as xt } from "storybook/internal/csf";
1259
+ var Ie = console, yt = /* @__PURE__ */ p((s, e) => !(e.include.length && !e.include.some((i) => s?.includes(i)) || e.exclude.some((i) => s?.
1260
+ includes(i))), "isValidTest");
1261
+ async function bt({
1262
+ code: s,
1263
+ fileName: e,
1264
+ configDir: i,
1265
+ stories: t,
1266
+ tagsFilter: r,
1267
+ previewLevelTags: o = []
1268
+ }) {
1269
+ if (!/\.stor(y|ies)\./.test(e))
1270
+ return s;
1271
+ let l = K(s, {
1272
+ fileName: e,
1273
+ transformInlineMeta: !0,
1274
+ makeTitle: /* @__PURE__ */ p((_) => {
1275
+ let S = gt({
1276
+ storyFilePath: e,
1277
+ configDir: i,
1278
+ stories: t,
1279
+ userTitle: _
1280
+ }) || "unknown";
1281
+ return S === "unknown" && Ie.warn(
1282
+ te.dedent`
1283
+ [Storybook]: Could not calculate story title for "${e}".
1284
+ Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${i}".
1285
+ `
1286
+ ), S;
1287
+ }, "makeTitle")
1288
+ }).parse(), f = l._ast, m = l._metaVariableName, g = l._metaNode, x = g.properties.find(
1289
+ (_) => d.isObjectProperty(_) && d.isIdentifier(_.key) && _.key.name === "title"
1290
+ ), b = d.stringLiteral(l._meta?.title || "unknown");
1291
+ if (x ? d.isObjectProperty(x) && (x.value = b) : g.properties.push(d.objectProperty(d.identifier("title"), b)), !g || !l._meta)
1292
+ throw new Error(
1293
+ `The Storybook vitest plugin could not detect the meta (default export) object in the story file.
1294
+
1295
+ Please make sure you have a default export with the meta object. If you are using a different export format that is not supported, please fi\
1296
+ le an issue with details about your use case.`
1297
+ );
1298
+ let y = {};
1299
+ Object.keys(l._stories).map((_) => {
1300
+ let S = xt(
1301
+ "test",
1302
+ "dev",
1303
+ ...o,
1304
+ ...l.meta?.tags || [],
1305
+ ...l._stories[_].tags || []
1306
+ );
1307
+ yt(S, r) && (y[_] = l._storyStatements[_]);
1308
+ });
1309
+ let h = l._file.path.scope.generateUidIdentifier("test"), D = l._file.path.scope.generateUidIdentifier("describe");
1310
+ if (Object.keys(y).length === 0) {
1311
+ let _ = d.expressionStatement(
1312
+ d.callExpression(d.memberExpression(D, d.identifier("skip")), [
1313
+ d.stringLiteral("No valid tests found")
1314
+ ])
1315
+ );
1316
+ f.program.body.push(_);
1317
+ let S = [
1318
+ d.importDeclaration(
1319
+ [
1320
+ d.importSpecifier(h, d.identifier("test")),
1321
+ d.importSpecifier(D, d.identifier("describe"))
1322
+ ],
1323
+ d.stringLiteral("vitest")
1324
+ )
1325
+ ];
1326
+ f.program.body.unshift(...S);
1327
+ } else {
1328
+ let re = function() {
1329
+ let j = l._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), N = d.memberExpression(
1330
+ d.callExpression(d.memberExpression(_, d.identifier("getState")), []),
1331
+ d.identifier("testPath")
1332
+ ), F = d.memberExpression(
1333
+ d.memberExpression(d.identifier("globalThis"), d.identifier("__vitest_worker__")),
1334
+ d.identifier("filepath")
1335
+ ), C = d.logicalExpression(
1336
+ "??",
1337
+ // TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
1338
+ // https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
1339
+ F,
1340
+ N
1341
+ ), L = d.callExpression(
1342
+ d.memberExpression(
1343
+ d.memberExpression(
1344
+ d.memberExpression(d.identifier("import"), d.identifier("meta")),
1345
+ d.identifier("url")
1346
+ ),
1347
+ d.identifier("includes")
1348
+ ),
1349
+ [C]
1350
+ );
1351
+ return { isRunningFromThisFileDeclaration: d.variableDeclaration("const", [
1352
+ d.variableDeclarator(j, L)
1353
+ ]), isRunningFromThisFileId: j };
1354
+ };
1355
+ var Et = re;
1356
+ p(re, "getTestGuardDeclaration");
1357
+ let _ = l._file.path.scope.generateUidIdentifier("expect"), S = l._file.path.scope.generateUidIdentifier("testStory"), De = d.identifier(
1358
+ JSON.stringify(r.skip)), { isRunningFromThisFileDeclaration: Ne, isRunningFromThisFileId: ve } = re();
1359
+ f.program.body.push(Ne);
1360
+ let we = /* @__PURE__ */ p(({
1361
+ localName: j,
1362
+ exportName: N,
1363
+ testTitle: F,
1364
+ node: C
1365
+ }) => {
1366
+ let L = d.expressionStatement(
1367
+ d.callExpression(h, [
1368
+ d.stringLiteral(F),
1369
+ d.callExpression(S, [
1370
+ d.stringLiteral(N),
1371
+ d.identifier(j),
1372
+ d.identifier(m),
1373
+ De
1374
+ ])
1375
+ ])
1376
+ );
1377
+ return L.loc = C.loc, L;
1378
+ }, "getTestStatementForStory"), Fe = Object.entries(y).map(([j, N]) => {
1379
+ if (N === null) {
1380
+ Ie.warn(
1381
+ te.dedent`
1382
+ [Storybook]: Could not transform "${j}" story into test at "${e}".
1383
+ Please make sure to define stories in the same file and not re-export stories coming from other files".
1384
+ `
1385
+ );
1386
+ return;
1387
+ }
1388
+ let F = l._stories[j].localName ?? j, C = l._stories[j].name ?? j;
1389
+ return we({ testTitle: C, localName: F, exportName: j, node: N });
1390
+ }).filter((j) => !!j), Ce = d.ifStatement(ve, d.blockStatement(Fe));
1391
+ f.program.body.push(Ce);
1392
+ let Te = [
1393
+ d.importDeclaration(
1394
+ [
1395
+ d.importSpecifier(h, d.identifier("test")),
1396
+ d.importSpecifier(_, d.identifier("expect"))
1397
+ ],
1398
+ d.stringLiteral("vitest")
1399
+ ),
1400
+ d.importDeclaration(
1401
+ [d.importSpecifier(S, d.identifier("testStory"))],
1402
+ d.stringLiteral("@storybook/addon-test/internal/test-utils")
1403
+ )
1404
+ ];
1405
+ f.program.body.unshift(...Te);
1406
+ }
1407
+ return de(l, { sourceMaps: !0, sourceFileName: e }, s);
1408
+ }
1409
+ p(bt, "vitestTransform");
1410
+ export {
1411
+ B as BadMetaError,
1412
+ Y as ConfigFile,
1413
+ X as CsfFile,
1414
+ q as MixedFactoryError,
1415
+ z as MultipleMetaError,
1416
+ U as NoMetaError,
1417
+ cr as babelParse,
1418
+ et as babelParseFile,
1419
+ Kt as enrichCsf,
1420
+ mt as enrichCsfMeta,
1421
+ dt as enrichCsfStory,
1422
+ Oe as extractDescription,
1423
+ ut as extractSource,
1424
+ ot as formatConfig,
1425
+ de as formatCsf,
1426
+ Wt as getStorySortParameter,
1427
+ Lt as isCsfFactoryPreview,
1428
+ Qe as isModuleMock,
1429
+ Ke as isValidPreviewPath,
1430
+ nt as loadConfig,
1431
+ K as loadCsf,
1432
+ at as printConfig,
1433
+ tt as printCsf,
1434
+ $t as readConfig,
1435
+ Ft as readCsf,
1436
+ bt as vitestTransform,
1437
+ Rt as writeConfig,
1438
+ Ct as writeCsf
1439
+ };