@storybook/svelte-vite 10.1.0-alpha.8 → 10.1.0-beta.0

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,23 +1,19 @@
1
- import CJS_COMPAT_NODE_URL_r10jp1894sr from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_r10jp1894sr from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_r10jp1894sr from "node:module";
1
+ import CJS_COMPAT_NODE_URL_gu2mg2oirnj from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_gu2mg2oirnj from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_gu2mg2oirnj from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_r10jp1894sr.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_r10jp1894sr.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_r10jp1894sr.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_gu2mg2oirnj.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_gu2mg2oirnj.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_gu2mg2oirnj.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "../_node-chunks/chunk-WKFO5K6J.js";
15
12
 
16
13
  // src/node/index.ts
17
14
  function defineMain(config) {
18
15
  return config;
19
16
  }
20
- __name(defineMain, "defineMain");
21
17
  export {
22
18
  defineMain
23
19
  };
package/dist/preset.js CHANGED
@@ -1,17 +1,14 @@
1
- import CJS_COMPAT_NODE_URL_r10jp1894sr from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_r10jp1894sr from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_r10jp1894sr from "node:module";
1
+ import CJS_COMPAT_NODE_URL_gu2mg2oirnj from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_gu2mg2oirnj from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_gu2mg2oirnj from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_r10jp1894sr.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_r10jp1894sr.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_r10jp1894sr.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_gu2mg2oirnj.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_gu2mg2oirnj.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_gu2mg2oirnj.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "./_node-chunks/chunk-WKFO5K6J.js";
15
12
 
16
13
  // src/plugins/svelte-docgen.ts
17
14
  import { basename, relative } from "node:path";
@@ -23,96 +20,68 @@ import svelte2tsx, { internalHelpers } from "svelte2tsx";
23
20
  import { VERSION } from "svelte/compiler";
24
21
  import ts from "typescript";
25
22
  function convertType(type, checker) {
26
- if (type.flags & ts.TypeFlags.Any) {
23
+ if (type.flags & ts.TypeFlags.Any)
27
24
  return { type: "any" };
28
- }
29
- if (type.flags & ts.TypeFlags.Number) {
25
+ if (type.flags & ts.TypeFlags.Number)
30
26
  return { type: "number" };
31
- }
32
- if (type.flags & ts.TypeFlags.String) {
27
+ if (type.flags & ts.TypeFlags.String)
33
28
  return { type: "string" };
34
- }
35
- if (type.flags & ts.TypeFlags.Boolean) {
29
+ if (type.flags & ts.TypeFlags.Boolean)
36
30
  return { type: "boolean" };
37
- }
38
- if (type.flags & ts.TypeFlags.ESSymbol) {
31
+ if (type.flags & ts.TypeFlags.ESSymbol)
39
32
  return { type: "symbol" };
40
- }
41
- if (type.flags & ts.TypeFlags.Null) {
33
+ if (type.flags & ts.TypeFlags.Null)
42
34
  return { type: "null" };
43
- }
44
- if (type.flags & ts.TypeFlags.Undefined) {
35
+ if (type.flags & ts.TypeFlags.Undefined)
45
36
  return { type: "undefined" };
46
- }
47
- if (type.flags & ts.TypeFlags.Void) {
37
+ if (type.flags & ts.TypeFlags.Void)
48
38
  return { type: "void" };
49
- }
50
- if (type.getCallSignatures().length > 0) {
39
+ if (type.getCallSignatures().length > 0)
51
40
  return { type: "function", text: checker.typeToString(type) };
52
- }
53
- if (type.flags & ts.TypeFlags.Object) {
54
- const indexType = checker.getIndexTypeOfType(type, ts.IndexKind.Number);
55
- if (indexType) {
56
- return { type: "array", text: checker.typeToString(type) };
57
- }
58
- return { type: "object", text: checker.typeToString(type) };
59
- }
60
- if (type.isNumberLiteral() || type.isStringLiteral()) {
41
+ if (type.flags & ts.TypeFlags.Object)
42
+ return checker.getIndexTypeOfType(type, ts.IndexKind.Number) ? { type: "array", text: checker.typeToString(type) } : { type: "object", text: checker.typeToString(type) };
43
+ if (type.isNumberLiteral() || type.isStringLiteral())
61
44
  return {
62
45
  type: "literal",
63
46
  value: type.value,
64
47
  text: type.flags & ts.TypeFlags.EnumLiteral ? checker.typeToString(type) : JSON.stringify(type.value)
65
48
  };
66
- }
67
49
  if (type.flags & ts.TypeFlags.BooleanLiteral) {
68
- const text = checker.typeToString(type);
50
+ let text = checker.typeToString(type);
69
51
  return { type: "literal", value: text === "true", text };
70
52
  }
71
53
  if (type.isUnion()) {
72
- const types = type.types.map((t) => convertType(t, checker)).filter((t) => {
73
- return t !== void 0 && t.type !== "undefined";
74
- });
75
- const idxTrue = types.findIndex((t) => t.type === "literal" && t.value === true);
76
- const idxFalse = types.findIndex((t) => t.type === "literal" && t.value === false);
77
- if (idxTrue !== -1 && idxFalse !== -1) {
78
- types.splice(Math.max(idxTrue, idxFalse), 1);
79
- types.splice(Math.min(idxTrue, idxFalse), 1, { type: "boolean" });
80
- }
81
- return types.length > 1 ? { type: "union", types } : types[0];
82
- }
83
- if (type.isIntersection()) {
84
- const types = type.types.map((t) => convertType(t, checker)).filter((t) => t !== void 0);
85
- return { type: "intersection", types };
54
+ let types = type.types.map((t) => convertType(t, checker)).filter((t) => t !== void 0 && t.type !== "undefined"), idxTrue = types.findIndex((t) => t.type === "literal" && t.value === !0), idxFalse = types.findIndex((t) => t.type === "literal" && t.value === !1);
55
+ return idxTrue !== -1 && idxFalse !== -1 && (types.splice(Math.max(idxTrue, idxFalse), 1), types.splice(Math.min(idxTrue, idxFalse), 1, { type: "boolean" })), types.length > 1 ? { type: "union", types } : types[0];
86
56
  }
87
- return void 0;
57
+ if (type.isIntersection())
58
+ return { type: "intersection", types: type.types.map((t) => convertType(t, checker)).filter((t) => t !== void 0) };
88
59
  }
89
- __name(convertType, "convertType");
90
60
  function initializerToDefaultValue(expr, checker) {
91
- if (ts.isNumericLiteral(expr)) {
61
+ if (ts.isNumericLiteral(expr))
92
62
  return { text: expr.text };
93
- } else if (ts.isStringLiteral(expr)) {
63
+ if (ts.isStringLiteral(expr))
94
64
  return { text: JSON.stringify(expr.text) };
95
- } else if (ts.isIdentifier(expr) || ts.isPropertyAccessExpression(expr)) {
96
- const symbol = checker.getSymbolAtLocation(expr);
97
- if (symbol && checker.isUndefinedSymbol(symbol)) {
98
- return void 0;
99
- }
100
- const type = checker.getTypeAtLocation(expr);
101
- if (type.flags & ts.TypeFlags.EnumLiteral) {
65
+ if (ts.isIdentifier(expr) || ts.isPropertyAccessExpression(expr)) {
66
+ let symbol = checker.getSymbolAtLocation(expr);
67
+ if (symbol && checker.isUndefinedSymbol(symbol))
68
+ return;
69
+ let type = checker.getTypeAtLocation(expr);
70
+ if (type.flags & ts.TypeFlags.EnumLiteral)
102
71
  return { text: checker.typeToString(type) };
103
- } else if (type.isLiteral()) {
72
+ if (type.isLiteral())
104
73
  return { text: JSON.stringify(type.value) };
105
- } else if (type.flags & ts.TypeFlags.Null) {
74
+ if (type.flags & ts.TypeFlags.Null)
106
75
  return { text: "null" };
107
- } else if (type.flags & ts.TypeFlags.BooleanLiteral) {
76
+ if (type.flags & ts.TypeFlags.BooleanLiteral)
108
77
  return { text: checker.typeToString(type) };
109
- } else if (type.getCallSignatures().length > 0) {
78
+ if (type.getCallSignatures().length > 0)
79
+ return { text: "function" };
80
+ } else {
81
+ if (ts.isArrayLiteralExpression(expr) || ts.isObjectLiteralExpression(expr) || ts.isNewExpression(expr))
82
+ return { text: expr.getText() };
83
+ if (ts.isArrowFunction(expr))
110
84
  return { text: "function" };
111
- }
112
- } else if (ts.isArrayLiteralExpression(expr) || ts.isObjectLiteralExpression(expr) || ts.isNewExpression(expr)) {
113
- return { text: expr.getText() };
114
- } else if (ts.isArrowFunction(expr)) {
115
- return { text: "function" };
116
85
  }
117
86
  switch (expr.kind) {
118
87
  case ts.SyntaxKind.TrueKeyword:
@@ -124,23 +93,19 @@ function initializerToDefaultValue(expr, checker) {
124
93
  }
125
94
  return { text: "..." };
126
95
  }
127
- __name(initializerToDefaultValue, "initializerToDefaultValue");
128
96
  function loadConfig(basepath) {
129
- const configPath = ts.findConfigFile(basepath, ts.sys.fileExists) || ts.findConfigFile(basepath, ts.sys.fileExists, "jsconfig.json");
130
- const forcedOptions = {
131
- sourceMap: false,
132
- noEmit: true,
133
- strict: true,
134
- allowJs: true,
135
- checkJs: true,
136
- skipLibCheck: true,
137
- skipDefaultLibCheck: true
97
+ let configPath = ts.findConfigFile(basepath, ts.sys.fileExists) || ts.findConfigFile(basepath, ts.sys.fileExists, "jsconfig.json"), forcedOptions = {
98
+ sourceMap: !1,
99
+ noEmit: !0,
100
+ strict: !0,
101
+ allowJs: !0,
102
+ checkJs: !0,
103
+ skipLibCheck: !0,
104
+ skipDefaultLibCheck: !0
138
105
  };
139
- if (!configPath) {
106
+ if (!configPath)
140
107
  return [forcedOptions, /* @__PURE__ */ new Set()];
141
- }
142
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
143
- const config = ts.parseJsonConfigFileContent(
108
+ let configFile = ts.readConfigFile(configPath, ts.sys.readFile), config = ts.parseJsonConfigFileContent(
144
109
  configFile.config,
145
110
  ts.sys,
146
111
  path.dirname(configPath),
@@ -150,12 +115,11 @@ function loadConfig(basepath) {
150
115
  [
151
116
  {
152
117
  extension: "svelte",
153
- isMixedContent: true,
118
+ isMixedContent: !0,
154
119
  scriptKind: ts.ScriptKind.Deferred
155
120
  }
156
121
  ]
157
- );
158
- const fileNames = new Set(
122
+ ), fileNames = new Set(
159
123
  config.fileNames.filter((fileName) => fileName.endsWith(".svelte")).map((fileName) => fileName + ".tsx")
160
124
  );
161
125
  return [
@@ -166,7 +130,6 @@ function loadConfig(basepath) {
166
130
  fileNames
167
131
  ];
168
132
  }
169
- __name(loadConfig, "loadConfig");
170
133
  function createDocgenCache() {
171
134
  return {
172
135
  filenameToModifiedTime: {},
@@ -174,216 +137,144 @@ function createDocgenCache() {
174
137
  fileCache: {}
175
138
  };
176
139
  }
177
- __name(createDocgenCache, "createDocgenCache");
178
140
  function generateDocgen(targetFileName, cache) {
179
- if (targetFileName.endsWith(".svelte")) {
180
- targetFileName = targetFileName + ".tsx";
181
- }
182
- if (cache.options === void 0 || !cache.rootNames?.has(targetFileName)) {
141
+ if (targetFileName.endsWith(".svelte") && (targetFileName = targetFileName + ".tsx"), cache.options === void 0 || !cache.rootNames?.has(targetFileName)) {
183
142
  [cache.options, cache.rootNames] = loadConfig(targetFileName);
184
- const shimFilename = import.meta.resolve("svelte2tsx/svelte-shims-v4.d.ts");
185
- cache.rootNames.add(shimFilename);
186
- cache.rootNames.add(targetFileName);
143
+ let shimFilename = import.meta.resolve("svelte2tsx/svelte-shims-v4.d.ts");
144
+ cache.rootNames.add(shimFilename), cache.rootNames.add(targetFileName);
187
145
  }
188
- const originalHost = ts.createCompilerHost(cache.options);
189
- const host = {
146
+ let originalHost = ts.createCompilerHost(cache.options), host = {
190
147
  ...originalHost,
191
148
  readFile(fileName) {
192
- const isCacheTarget = fileName.endsWith(path.sep + "package.json");
193
- if (isCacheTarget && cache.fileCache[fileName]) {
149
+ let isCacheTarget = fileName.endsWith(path.sep + "package.json");
150
+ if (isCacheTarget && cache.fileCache[fileName])
194
151
  return cache.fileCache[fileName];
195
- }
196
- const content = originalHost.readFile(fileName);
197
- if (content && isCacheTarget) {
198
- cache.fileCache[fileName] = content;
199
- }
200
- return content;
152
+ let content = originalHost.readFile(fileName);
153
+ return content && isCacheTarget && (cache.fileCache[fileName] = content), content;
201
154
  },
202
155
  fileExists(fileName) {
203
- const isCacheTarget = fileName.endsWith(path.sep + "package.json");
204
- if (isCacheTarget && cache.fileCache[fileName]) {
205
- return true;
206
- }
156
+ if (fileName.endsWith(path.sep + "package.json") && cache.fileCache[fileName])
157
+ return !0;
207
158
  let exists = originalHost.fileExists(fileName);
208
- if (exists) {
209
- return exists;
210
- }
211
- if (fileName.endsWith(".svelte.tsx") || fileName.endsWith(".svelte.jsx")) {
212
- fileName = fileName.slice(0, -4);
213
- exists = originalHost.fileExists(fileName);
214
- return exists;
215
- }
216
- return false;
159
+ return exists || (fileName.endsWith(".svelte.tsx") || fileName.endsWith(".svelte.jsx") ? (fileName = fileName.slice(0, -4), exists = originalHost.fileExists(fileName), exists) : !1);
217
160
  },
218
161
  getSourceFile(fileName, languageVersion, onError) {
219
162
  if (fileName.endsWith(".svelte.tsx") || fileName.endsWith(".svelte.jsx")) {
220
- const realFileName = fileName.slice(0, -4);
221
- const modifiedTime = ts.sys.getModifiedTime ? ts.sys.getModifiedTime(realFileName) : void 0;
222
- if (modifiedTime) {
223
- const cachedModifiedTime = cache.filenameToModifiedTime[fileName];
224
- if (cachedModifiedTime?.getTime() === modifiedTime.getTime()) {
225
- return cache.filenameToSourceFile[fileName];
226
- }
227
- }
228
- const content = originalHost.readFile(realFileName);
229
- if (content === void 0) {
163
+ let realFileName = fileName.slice(0, -4), modifiedTime = ts.sys.getModifiedTime ? ts.sys.getModifiedTime(realFileName) : void 0;
164
+ if (modifiedTime && cache.filenameToModifiedTime[fileName]?.getTime() === modifiedTime.getTime())
165
+ return cache.filenameToSourceFile[fileName];
166
+ let content = originalHost.readFile(realFileName);
167
+ if (content === void 0)
230
168
  return;
231
- }
232
- const isTsFile = /<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(content);
233
- const tsx = svelte2tsx.svelte2tsx(content, {
169
+ let isTsFile = /<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(content), tsx = svelte2tsx.svelte2tsx(content, {
234
170
  version: VERSION,
235
171
  isTsFile,
236
172
  mode: "dts"
237
- });
238
- const sourceFile2 = ts.createSourceFile(
173
+ }), sourceFile2 = ts.createSourceFile(
239
174
  fileName,
240
175
  tsx.code,
241
176
  languageVersion,
242
- true,
177
+ !0,
243
178
  isTsFile ? ts.ScriptKind.TS : ts.ScriptKind.JS
244
179
  // Set to 'JS' to enable TypeScript to parse JSDoc.
245
180
  );
246
- cache.filenameToSourceFile[fileName] = sourceFile2;
247
- cache.filenameToModifiedTime[fileName] = modifiedTime;
248
- return sourceFile2;
181
+ return cache.filenameToSourceFile[fileName] = sourceFile2, cache.filenameToModifiedTime[fileName] = modifiedTime, sourceFile2;
249
182
  } else {
250
- let staticCaching = false;
183
+ let staticCaching = !1;
251
184
  staticCaching ||= fileName.split(path.sep).some((part) => part.toLowerCase() === "node_modules");
252
- const cachedSourceFile = cache.filenameToSourceFile[fileName];
253
- if (cachedSourceFile && staticCaching) {
185
+ let cachedSourceFile = cache.filenameToSourceFile[fileName];
186
+ if (cachedSourceFile && staticCaching)
254
187
  return cachedSourceFile;
255
- }
256
- const modifiedTime = ts.sys.getModifiedTime ? ts.sys.getModifiedTime(fileName) : void 0;
257
- if (modifiedTime) {
258
- const cachedModifiedTime = cache.filenameToModifiedTime[fileName];
259
- if (cachedModifiedTime?.getTime() === modifiedTime.getTime()) {
260
- return cache.filenameToSourceFile[fileName];
261
- }
262
- }
263
- const content = originalHost.readFile(fileName);
264
- if (content === void 0) {
188
+ let modifiedTime = ts.sys.getModifiedTime ? ts.sys.getModifiedTime(fileName) : void 0;
189
+ if (modifiedTime && cache.filenameToModifiedTime[fileName]?.getTime() === modifiedTime.getTime())
190
+ return cache.filenameToSourceFile[fileName];
191
+ let content = originalHost.readFile(fileName);
192
+ if (content === void 0)
265
193
  return;
266
- }
267
- const sourceFile2 = ts.createSourceFile(fileName, content, languageVersion, true);
268
- cache.filenameToSourceFile[fileName] = sourceFile2;
269
- cache.filenameToModifiedTime[fileName] = modifiedTime;
270
- return sourceFile2;
194
+ let sourceFile2 = ts.createSourceFile(fileName, content, languageVersion, !0);
195
+ return cache.filenameToSourceFile[fileName] = sourceFile2, cache.filenameToModifiedTime[fileName] = modifiedTime, sourceFile2;
271
196
  }
272
197
  },
273
198
  writeFile() {
274
199
  }
275
- };
276
- const program = ts.createProgram({
200
+ }, program = ts.createProgram({
277
201
  rootNames: Array.from(cache.rootNames),
278
202
  options: cache.options,
279
203
  host,
280
204
  oldProgram: cache.oldProgram
281
205
  });
282
206
  cache.oldProgram = program;
283
- const checker = program.getTypeChecker();
284
- const sourceFile = program.getSourceFile(targetFileName);
285
- if (sourceFile === void 0) {
207
+ let checker = program.getTypeChecker(), sourceFile = program.getSourceFile(targetFileName);
208
+ if (sourceFile === void 0)
286
209
  return {
287
210
  props: []
288
211
  };
289
- }
290
- const propMap = /* @__PURE__ */ new Map();
291
- const renderFunction = sourceFile.statements.find((statement) => {
292
- return ts.isFunctionDeclaration(statement) && statement.name?.text === internalHelpers.renderName;
293
- });
294
- if (renderFunction === void 0) {
212
+ let propMap = /* @__PURE__ */ new Map(), renderFunction = sourceFile.statements.find((statement) => ts.isFunctionDeclaration(statement) && statement.name?.text === internalHelpers.renderName);
213
+ if (renderFunction === void 0)
295
214
  return {
296
215
  props: []
297
216
  };
298
- }
299
- let propsType;
300
- const signature = checker.getSignatureFromDeclaration(renderFunction);
301
- if (signature && signature.declaration) {
302
- const type = checker.getReturnTypeOfSignature(signature);
303
- type.getProperties().forEach((retObjProp) => {
304
- if (retObjProp.name === "props") {
305
- const decl = signature.getDeclaration();
306
- propsType = checker.getTypeOfSymbolAtLocation(retObjProp, decl);
307
- propsType.getProperties().forEach((prop) => {
308
- const name = prop.getName();
309
- let description = ts.displayPartsToString(prop.getDocumentationComment(checker)) || void 0;
310
- const propType = checker.getTypeOfSymbolAtLocation(prop, decl);
311
- if (prop.valueDeclaration) {
312
- const typeTag = ts.getJSDocTypeTag(prop.valueDeclaration);
313
- if (typeTag?.comment) {
314
- description = ((description || "") + "\n" + typeTag.comment).trim();
315
- }
316
- }
317
- if ((prop.valueDeclaration ?? prop?.links?.syntheticOrigin?.valueDeclaration)?.getSourceFile().fileName.includes("node_modules/svelte/elements.d.ts")) {
318
- return;
217
+ let propsType, signature = checker.getSignatureFromDeclaration(renderFunction);
218
+ return signature && signature.declaration && checker.getReturnTypeOfSignature(signature).getProperties().forEach((retObjProp) => {
219
+ if (retObjProp.name === "props") {
220
+ let decl = signature.getDeclaration();
221
+ propsType = checker.getTypeOfSymbolAtLocation(retObjProp, decl), propsType.getProperties().forEach((prop) => {
222
+ let name = prop.getName(), description = ts.displayPartsToString(prop.getDocumentationComment(checker)) || void 0, propType = checker.getTypeOfSymbolAtLocation(prop, decl);
223
+ if (prop.valueDeclaration) {
224
+ let typeTag = ts.getJSDocTypeTag(prop.valueDeclaration);
225
+ typeTag?.comment && (description = ((description || "") + `
226
+ ` + typeTag.comment).trim());
227
+ }
228
+ if ((prop.valueDeclaration ?? prop?.links?.syntheticOrigin?.valueDeclaration)?.getSourceFile().fileName.includes("node_modules/svelte/elements.d.ts"))
229
+ return;
230
+ let optional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
231
+ propMap.set(name, {
232
+ name,
233
+ optional,
234
+ description,
235
+ type: convertType(propType, checker)
236
+ });
237
+ });
238
+ }
239
+ }), renderFunction.body?.forEachChild((node) => {
240
+ ts.isVariableStatement(node) && node.declarationList.declarations.forEach((declaration) => {
241
+ if (ts.isObjectBindingPattern(declaration.name)) {
242
+ let isPropsRune = declaration.initializer && ts.isCallExpression(declaration.initializer) && ts.isIdentifier(declaration.initializer.expression) && declaration.initializer.expression.text === "$props", isPropsType = declaration.type && propsType === checker.getTypeFromTypeNode(declaration.type);
243
+ (isPropsRune || isPropsType) && declaration.name.elements.forEach((element) => {
244
+ let name = element.name.getText(), prop = propMap.get(name);
245
+ if (prop && element.initializer) {
246
+ let defaultValue = initializerToDefaultValue(element.initializer, checker);
247
+ defaultValue && (prop.defaultValue = defaultValue);
319
248
  }
320
- const optional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
321
- propMap.set(name, {
322
- name,
323
- optional,
324
- description,
325
- type: convertType(propType, checker)
326
- });
327
249
  });
328
250
  }
329
- });
330
- }
331
- renderFunction.body?.forEachChild((node) => {
332
- if (ts.isVariableStatement(node)) {
333
- node.declarationList.declarations.forEach((declaration) => {
334
- if (ts.isObjectBindingPattern(declaration.name)) {
335
- const isPropsRune = declaration.initializer && ts.isCallExpression(declaration.initializer) && ts.isIdentifier(declaration.initializer.expression) && declaration.initializer.expression.text === "$props";
336
- const isPropsType = declaration.type && propsType === checker.getTypeFromTypeNode(declaration.type);
337
- if (isPropsRune || isPropsType) {
338
- declaration.name.elements.forEach((element) => {
339
- const name = element.name.getText();
340
- const prop = propMap.get(name);
341
- if (prop && element.initializer) {
342
- const defaultValue = initializerToDefaultValue(element.initializer, checker);
343
- if (defaultValue) {
344
- prop.defaultValue = defaultValue;
345
- }
346
- }
347
- });
348
- }
349
- }
350
- if (ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) && propMap.has(declaration.name.text)) {
351
- const prop = propMap.get(declaration.name.text);
352
- if (prop && declaration.initializer) {
353
- prop.optional = true;
354
- const defaultValue = initializerToDefaultValue(declaration.initializer, checker);
355
- if (defaultValue) {
356
- prop.defaultValue = defaultValue;
357
- }
358
- }
251
+ if (ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) && propMap.has(declaration.name.text)) {
252
+ let prop = propMap.get(declaration.name.text);
253
+ if (prop && declaration.initializer) {
254
+ prop.optional = !0;
255
+ let defaultValue = initializerToDefaultValue(declaration.initializer, checker);
256
+ defaultValue && (prop.defaultValue = defaultValue);
359
257
  }
360
- });
361
- }
362
- });
363
- return {
258
+ }
259
+ });
260
+ }), {
364
261
  props: Array.from(propMap.values())
365
262
  };
366
263
  }
367
- __name(generateDocgen, "generateDocgen");
368
264
 
369
265
  // src/plugins/svelte-docgen.ts
370
266
  function getComponentName(ast) {
371
- const exportDefaultDeclaration = ast.body.find((n) => n.type === "ExportDefaultDeclaration");
372
- if (!exportDefaultDeclaration) {
267
+ let exportDefaultDeclaration = ast.body.find((n) => n.type === "ExportDefaultDeclaration");
268
+ if (!exportDefaultDeclaration)
373
269
  throw new Error("Unreachable - no default export found");
374
- }
375
- if (exportDefaultDeclaration.declaration.type === "Identifier") {
270
+ if (exportDefaultDeclaration.declaration.type === "Identifier")
376
271
  return exportDefaultDeclaration.declaration.name;
377
- }
378
- if (exportDefaultDeclaration.declaration.type !== "ClassDeclaration" && exportDefaultDeclaration.declaration.type !== "FunctionDeclaration") {
272
+ if (exportDefaultDeclaration.declaration.type !== "ClassDeclaration" && exportDefaultDeclaration.declaration.type !== "FunctionDeclaration")
379
273
  throw new Error("Unreachable - not a class or a function");
380
- }
381
- if (!exportDefaultDeclaration.declaration.id) {
274
+ if (!exportDefaultDeclaration.declaration.id)
382
275
  throw new Error("Unreachable - unnamed class/function");
383
- }
384
276
  return exportDefaultDeclaration.declaration.id.name;
385
277
  }
386
- __name(getComponentName, "getComponentName");
387
278
  function transformToSvelteDocParserType(type) {
388
279
  switch (type.type) {
389
280
  case "string":
@@ -411,21 +302,16 @@ function transformToSvelteDocParserType(type) {
411
302
  case "literal":
412
303
  return { kind: "const", type: typeof type.value, value: type.value, text: type.text };
413
304
  case "union": {
414
- const nonNull = type.types.filter((t) => t.type !== "null");
415
- const text = nonNull.map((t) => transformToSvelteDocParserType(t).text).join(" | ");
416
- const types = nonNull.map((t) => transformToSvelteDocParserType(t));
305
+ let nonNull = type.types.filter((t) => t.type !== "null"), text = nonNull.map((t) => transformToSvelteDocParserType(t).text).join(" | "), types = nonNull.map((t) => transformToSvelteDocParserType(t));
417
306
  return types.length === 1 ? types[0] : { kind: "union", type: types, text };
418
307
  }
419
- case "intersection": {
420
- const text = type.types.map((t) => transformToSvelteDocParserType(t).text).join(" & ");
421
- return { kind: "type", type: "intersection", text };
422
- }
308
+ case "intersection":
309
+ return { kind: "type", type: "intersection", text: type.types.map((t) => transformToSvelteDocParserType(t).text).join(" & ") };
423
310
  }
424
311
  }
425
- __name(transformToSvelteDocParserType, "transformToSvelteDocParserType");
426
312
  function transformToSvelteDocParserDataItems(docgen) {
427
313
  return docgen.props.map((p) => {
428
- const required = p.optional === false && p.defaultValue === void 0;
314
+ let required = p.optional === !1 && p.defaultValue === void 0;
429
315
  return {
430
316
  name: p.name,
431
317
  visibility: "public",
@@ -433,8 +319,8 @@ function transformToSvelteDocParserDataItems(docgen) {
433
319
  keywords: required ? [{ name: "required", description: "" }] : [],
434
320
  kind: "let",
435
321
  type: p.type ? transformToSvelteDocParserType(p.type) : void 0,
436
- static: false,
437
- readonly: false,
322
+ static: !1,
323
+ readonly: !1,
438
324
  importPath: void 0,
439
325
  originalName: void 0,
440
326
  localName: void 0,
@@ -442,76 +328,50 @@ function transformToSvelteDocParserDataItems(docgen) {
442
328
  };
443
329
  });
444
330
  }
445
- __name(transformToSvelteDocParserDataItems, "transformToSvelteDocParserDataItems");
446
331
  async function svelteDocgen() {
447
- const cwd = process.cwd();
448
- const include = /\.svelte$/;
449
- const exclude = /node_modules\/.*/;
450
- const { createFilter } = await import("vite");
451
- const filter = createFilter(include, exclude);
452
- const sourceFileCache = createDocgenCache();
332
+ let cwd = process.cwd(), include = /\.svelte$/, exclude = /node_modules\/.*/, { createFilter } = await import("vite"), filter = createFilter(include, exclude), sourceFileCache = createDocgenCache();
453
333
  return {
454
334
  name: "storybook:svelte-docgen-plugin",
455
335
  async transform(src, id) {
456
- if (id.startsWith("\0") || !filter(id)) {
457
- return void 0;
458
- }
459
- const resource = relative(cwd, id);
460
- const docgen = generateDocgen(resource, sourceFileCache);
461
- const data = transformToSvelteDocParserDataItems(docgen);
462
- const componentDoc = {
463
- data,
336
+ if (id.startsWith("\0") || !filter(id))
337
+ return;
338
+ let resource = relative(cwd, id), docgen = generateDocgen(resource, sourceFileCache), componentDoc = {
339
+ data: transformToSvelteDocParserDataItems(docgen),
464
340
  name: basename(resource)
465
- };
466
- const s = new MagicString(src);
467
- const outputAst = this.parse(src);
468
- const componentName = getComponentName(outputAst);
469
- s.append(`
470
- ;${componentName}.__docgen = ${JSON.stringify(componentDoc)}`);
471
- return {
341
+ }, s = new MagicString(src), outputAst = this.parse(src), componentName = getComponentName(outputAst);
342
+ return s.append(`
343
+ ;${componentName}.__docgen = ${JSON.stringify(componentDoc)}`), {
472
344
  code: s.toString(),
473
- map: s.generateMap({ hires: true, source: id })
345
+ map: s.generateMap({ hires: !0, source: id })
474
346
  };
475
347
  }
476
348
  };
477
349
  }
478
- __name(svelteDocgen, "svelteDocgen");
479
350
 
480
351
  // src/utils.ts
481
352
  import { SvelteViteWithSvelteKitError } from "storybook/internal/server-errors";
482
353
  import { hasVitePlugins } from "@storybook/builder-vite";
483
354
  async function handleSvelteKit(plugins, options) {
484
- const frameworkPreset = await options.presets.apply("framework", {}, options);
485
- const framework = typeof frameworkPreset === "string" ? frameworkPreset : frameworkPreset.name;
486
- const hasSvelteKitPlugins = await hasVitePlugins(plugins, [
355
+ let frameworkPreset = await options.presets.apply("framework", {}, options), framework = typeof frameworkPreset == "string" ? frameworkPreset : frameworkPreset.name;
356
+ if (await hasVitePlugins(plugins, [
487
357
  "vite-plugin-svelte-kit",
488
358
  "vite-plugin-sveltekit-setup",
489
359
  "vite-plugin-sveltekit-compile"
490
- ]);
491
- if (hasSvelteKitPlugins && !framework.includes("@storybook/sveltekit")) {
360
+ ]) && !framework.includes("@storybook/sveltekit"))
492
361
  throw new SvelteViteWithSvelteKitError();
493
- }
494
362
  }
495
- __name(handleSvelteKit, "handleSvelteKit");
496
363
 
497
364
  // src/preset.ts
498
365
  var core = {
499
366
  builder: import.meta.resolve("@storybook/builder-vite"),
500
367
  renderer: import.meta.resolve("@storybook/svelte/preset")
501
- };
502
- var viteFinal = /* @__PURE__ */ __name(async (config, options) => {
503
- const { plugins = [] } = config;
504
- const framework = await options.presets.apply("framework");
505
- const frameworkOptions = typeof framework === "string" ? {} : framework.options ?? {};
506
- if (frameworkOptions.docgen !== false) {
507
- plugins.push(await svelteDocgen());
508
- }
509
- await handleSvelteKit(plugins, options);
510
- return {
368
+ }, viteFinal = async (config, options) => {
369
+ let { plugins = [] } = config, framework = await options.presets.apply("framework");
370
+ return (typeof framework == "string" ? {} : framework.options ?? {}).docgen !== !1 && plugins.push(await svelteDocgen()), await handleSvelteKit(plugins, options), {
511
371
  ...config,
512
372
  plugins
513
373
  };
514
- }, "viteFinal");
374
+ };
515
375
  export {
516
376
  core,
517
377
  viteFinal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/svelte-vite",
3
- "version": "10.1.0-alpha.8",
3
+ "version": "10.1.0-beta.0",
4
4
  "description": "Storybook for Svelte and Vite: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -53,8 +53,8 @@
53
53
  "prep": "jiti ../../../scripts/build/build-package.ts"
54
54
  },
55
55
  "dependencies": {
56
- "@storybook/builder-vite": "10.1.0-alpha.8",
57
- "@storybook/svelte": "10.1.0-alpha.8",
56
+ "@storybook/builder-vite": "10.1.0-beta.0",
57
+ "@storybook/svelte": "10.1.0-beta.0",
58
58
  "magic-string": "^0.30.0",
59
59
  "svelte2tsx": "^0.7.44",
60
60
  "typescript": "^4.9.4 || ^5.0.0"
@@ -69,12 +69,12 @@
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@sveltejs/vite-plugin-svelte": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
72
- "storybook": "^10.1.0-alpha.8",
72
+ "storybook": "^10.1.0-beta.0",
73
73
  "svelte": "^5.0.0",
74
74
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
75
75
  },
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  },
79
- "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae16"
79
+ "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae1l"
80
80
  }
@@ -1,17 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_r10jp1894sr from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_r10jp1894sr from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_r10jp1894sr from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_r10jp1894sr.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_r10jp1894sr.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_r10jp1894sr.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
-
15
- export {
16
- __name
17
- };