@storybook/svelte 11.0.0-beta.3 → 11.0.0-beta.5

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 (36) hide show
  1. package/dist/_browser-chunks/{chunk-D3HHTIN7.js → chunk-BMWD75KG.js} +5 -8
  2. package/dist/_browser-chunks/{chunk-QPNLWHUT.js → chunk-JSFXTARB.js} +3 -2
  3. package/dist/_browser-chunks/chunk-QOQZ54LJ.js +31 -0
  4. package/dist/_browser-chunks/{chunk-FPEMDWKX.js → chunk-SPDFOPD5.js} +4 -4
  5. package/dist/_node-chunks/{build-docgen-TQ6645JH.js → build-docgen-4CLD5RKH.js} +79 -177
  6. package/dist/_node-chunks/{chunk-QN3DI6BM.js → chunk-2Z47YIHP.js} +2 -13
  7. package/dist/_node-chunks/{chunk-5XOL5BKO.js → chunk-3JLJMGBT.js} +0 -12
  8. package/dist/_node-chunks/chunk-4AFBO5RP.js +9 -0
  9. package/dist/_node-chunks/{chunk-RUGG3JY2.js → chunk-4QUF46RV.js} +0 -12
  10. package/dist/_node-chunks/{chunk-BQ2RIMP3.js → chunk-EZI5LVNW.js} +35 -16
  11. package/dist/_node-chunks/{chunk-JCULIFGX.js → chunk-FZFWZSUN.js} +0 -12
  12. package/dist/_node-chunks/{chunk-BUMY5Y7X.js → chunk-XLMS4YUB.js} +2 -45
  13. package/dist/_node-chunks/{parsers-KP7MPNO3.js → parsers-ENYE653E.js} +0 -12
  14. package/dist/_node-chunks/{svelte-project-manager-OOWETREX.js → svelte-project-manager-Q35NEAHT.js} +1 -12
  15. package/dist/_node-chunks/walk-TKX2QFK2.js +6 -0
  16. package/dist/{chunk-Cepksr9x.d.ts → chunk-CoCY0Re5.d.ts} +6 -1
  17. package/dist/docgen/component-docgen/svelte2tsx/generate-docgen.js +1 -12
  18. package/dist/docgen/docgen-worker.js +3 -14
  19. package/dist/entry-preview-docs.js +2 -2
  20. package/dist/entry-preview.js +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +3 -3
  23. package/dist/preset.js +7 -18
  24. package/dist/svelte-csf/addon-check.js +0 -12
  25. package/dist/svelte-csf/compiler/transform.js +11 -22
  26. package/dist/svelte-csf/indexer/index.js +2 -13
  27. package/dist/svelte-csf/runtime/component-helpers.d.ts +18 -4
  28. package/dist/svelte-csf/runtime/component-helpers.js +6 -2
  29. package/dist/svelte-csf/runtime/create-runtime-stories.d.ts +1 -1
  30. package/dist/svelte-csf/runtime/create-runtime-stories.js +9 -1
  31. package/package.json +3 -3
  32. package/static/svelte-csf/Story.svelte +17 -1
  33. package/static/svelte-csf/StoryRenderer.svelte +8 -1
  34. package/static/svelte-csf/contexts/renderer.svelte.js +6 -0
  35. package/dist/_node-chunks/chunk-J4TCM6ZP.js +0 -21
  36. package/dist/_node-chunks/walk-FGYTHLP6.js +0 -17
@@ -5,11 +5,8 @@ var skipSourceRender = (context) => {
5
5
  let sourceParams = context.parameters.docs?.source, isArgsStory = context.parameters.__isArgsStory;
6
6
  return sourceParams?.type === SourceType.DYNAMIC ? !1 : !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
7
7
  };
8
- function toSvelteProperty(key, value, argTypes) {
9
- if (value == null)
10
- return null;
11
- let argType = argTypes[key];
12
- return argType && argType.action ? null : value === !0 ? key : typeof value == "string" ? `${key}=${JSON.stringify(value)}` : typeof value == "function" ? `${key}={<handler>}` : `${key}={${JSON.stringify(value)}}`;
8
+ function toSvelteProperty(key, value) {
9
+ return value == null || value.isAction ? null : value === !0 ? key : typeof value == "string" ? `${key}=${JSON.stringify(value)}` : typeof value == "function" ? `${key}={<handler>}` : `${key}={${JSON.stringify(value)}}`;
13
10
  }
14
11
  function getComponentName(component) {
15
12
  if (component == null)
@@ -17,11 +14,11 @@ function getComponentName(component) {
17
14
  let { __docgen = {} } = component, { name } = __docgen;
18
15
  return name ? (name.endsWith(".svelte") && (name = name.substring(0, name.length - 7)), name) : component.name;
19
16
  }
20
- function generateSvelteSource(component, args, argTypes, slotProperty) {
17
+ function generateSvelteSource(component, args, slotProperty) {
21
18
  let name = getComponentName(component);
22
19
  if (!name)
23
20
  return null;
24
- let propsArray = Object.entries(args).filter(([k]) => k !== slotProperty).map(([k, v]) => toSvelteProperty(k, v, argTypes)).filter((p) => p), props = propsArray.join(" "), multiline = props.length > 50, slotValue = slotProperty ? args[slotProperty] : null, srcStart = multiline ? `<${name}
21
+ let propsArray = Object.entries(args).filter(([k]) => k !== slotProperty).map(([k, v]) => toSvelteProperty(k, v)).filter((p) => p), props = propsArray.join(" "), multiline = props.length > 50, slotValue = slotProperty ? args[slotProperty] : null, srcStart = multiline ? `<${name}
25
22
  ${propsArray.join(`
26
23
  `)}` : `<${name} ${props}`;
27
24
  return slotValue ? `${srcStart}>
@@ -44,7 +41,7 @@ var sourceDecorator = (storyFn, context) => {
44
41
  context
45
42
  ), { wrapper, slotProperty } = getWrapperProperties(component);
46
43
  wrapper && (component = ctxComponent);
47
- let generated = generateSvelteSource(component, args, context?.argTypes, slotProperty);
44
+ let generated = generateSvelteSource(component, args, slotProperty);
48
45
  generated && source.current !== generated && (emitTransformCode(generated, context), source.current = generated);
49
46
  }), story;
50
47
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  sourceDecorator
3
- } from "./chunk-D3HHTIN7.js";
3
+ } from "./chunk-BMWD75KG.js";
4
4
  import {
5
5
  __export
6
6
  } from "./chunk-4BE7D4DS.js";
@@ -11,6 +11,7 @@ __export(entry_preview_docs_exports, {
11
11
  decorators: () => decorators,
12
12
  parameters: () => parameters
13
13
  });
14
+ import { getSourceSnippetRuntime } from "storybook/internal/docs-tools";
14
15
 
15
16
  // src/docs/print-hole.ts
16
17
  import { printValue, unknownHoleKind } from "storybook/internal/docs-tools";
@@ -75,7 +76,7 @@ function propValue(value, name) {
75
76
  }
76
77
 
77
78
  // src/entry-preview-docs.ts
78
- var decorators = globalThis.FEATURES?.docgenServer ? [] : [sourceDecorator], parameters = globalThis.FEATURES?.docgenServer ? { docs: { source: { printHole } } } : {};
79
+ var snippetRuntime = getSourceSnippetRuntime(), decorators = snippetRuntime === "preview" ? [sourceDecorator] : [], parameters = snippetRuntime === "server" ? { docs: { source: { printHole } } } : {};
79
80
 
80
81
  export {
81
82
  decorators,
@@ -0,0 +1,31 @@
1
+ // src/svelte-csf/runtime/sync-story-args.ts
2
+ import { UPDATE_STORY_ARGS } from "storybook/internal/core-events";
3
+ import { addons } from "storybook/internal/preview-api";
4
+ import { isEqual, isPlainObject } from "es-toolkit/predicate";
5
+ var snapshotArg = (value, copies = /* @__PURE__ */ new Map()) => {
6
+ if (!Array.isArray(value) && !isPlainObject(value))
7
+ return value;
8
+ if (copies.has(value))
9
+ return copies.get(value);
10
+ let copy = Array.isArray(value) ? [] : {};
11
+ copies.set(value, copy);
12
+ for (let [key, item] of Object.entries(value))
13
+ copy[key] = snapshotArg(item, copies);
14
+ return copy;
15
+ }, sentArgsByStory = /* @__PURE__ */ new Map(), syncStoryArgs = ({ exportName, storyArgs, argSources, storyId }) => {
16
+ let sent = sentArgsByStory.get(storyId);
17
+ sent || (sent = {}, sentArgsByStory.set(storyId, sent));
18
+ let updatedArgs = {};
19
+ for (let [key, value] of Object.entries(storyArgs ?? {})) {
20
+ if (argSources[key]?.exportName !== exportName)
21
+ continue;
22
+ let snapshot = snapshotArg(value), last = key in sent ? sent[key] : argSources[key].value;
23
+ isEqual(last, snapshot) || (sent[key] = snapshot, updatedArgs[key] = value);
24
+ }
25
+ Object.keys(updatedArgs).length > 0 && addons.getChannel().emit(UPDATE_STORY_ARGS, { storyId, updatedArgs });
26
+ };
27
+
28
+ export {
29
+ snapshotArg,
30
+ syncStoryArgs
31
+ };
@@ -130,7 +130,7 @@ async function renderToCanvas({
130
130
  mountedComponent && (svelte.unmount(mountedComponent), componentsByDomElement.delete(canvasElementToUnmount));
131
131
  }
132
132
  let existingComponent = componentsByDomElement.get(canvasElement), remount = forceRemount;
133
- if (storyIdsToRemountFromResetArgsEvent.has(storyContext.id) && (remount = !0, storyIdsToRemountFromResetArgsEvent.delete(storyContext.id)), remount && unmount2(canvasElement), !existingComponent || remount) {
133
+ if (storyIdsToRemountFromResetArgsEvent.has(storyContext.id) && (remount = !0, storyIdsToRemountFromResetArgsEvent.delete(storyContext.id)), remount && unmount2(canvasElement), showMain(), !existingComponent || remount) {
134
134
  let props = createReactiveProps({
135
135
  storyFn,
136
136
  storyContext,
@@ -149,8 +149,8 @@ async function renderToCanvas({
149
149
  name,
150
150
  title,
151
151
  showError
152
- }), await svelte.tick();
153
- return showMain(), () => {
152
+ }), svelte.flushSync(), await svelte.tick();
153
+ return () => {
154
154
  unmount2(canvasElement);
155
155
  };
156
156
  }
@@ -182,7 +182,7 @@ function prepareStory(context, rawStory, rawInnerStory) {
182
182
  ...innerStory,
183
183
  decorator: preparedStory
184
184
  }
185
- } : { ...preparedStory, argTypes: context.argTypes };
185
+ } : preparedStory;
186
186
  }
187
187
  function decorateStory(storyFn, decorators) {
188
188
  return decorators.reduce(
@@ -1,33 +1,24 @@
1
- import CJS_COMPAT_NODE_URL_ozn9e8tgwi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ozn9e8tgwi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ozn9e8tgwi from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_ozn9e8tgwi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ozn9e8tgwi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ozn9e8tgwi.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
1
  import {
13
2
  UNPRINTABLE_DEFAULT
14
- } from "./chunk-5XOL5BKO.js";
3
+ } from "./chunk-3JLJMGBT.js";
15
4
  import {
16
5
  parseSvelteSource
17
- } from "./chunk-QN3DI6BM.js";
6
+ } from "./chunk-2Z47YIHP.js";
18
7
  import {
19
8
  extractSvelteASTNodes,
20
- getDefineMetaComponentValue,
21
9
  getDefineMetaFirstArgumentObjectExpression
22
- } from "./chunk-BUMY5Y7X.js";
23
- import "./chunk-JCULIFGX.js";
10
+ } from "./chunk-XLMS4YUB.js";
11
+ import "./chunk-FZFWZSUN.js";
24
12
 
25
13
  // src/docgen/component-docgen/build-docgen.ts
26
- import { realpathSync } from "node:fs";
27
14
  import { readFile as readFile2 } from "node:fs/promises";
28
- import { dirname, isAbsolute, join, relative, resolve as resolve2 } from "node:path";
15
+ import { resolve as resolve2 } from "node:path";
29
16
  import { preprocess } from "svelte/compiler";
30
- import { getComponentIdFromEntry, getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
17
+ import {
18
+ componentPathFromStory,
19
+ getComponentIdFromEntry,
20
+ getStoryImportPathFromEntry as getStoryImportPathFromEntry2
21
+ } from "storybook/internal/common";
31
22
  import { extractComponentDescription } from "storybook/internal/csf-tools";
32
23
 
33
24
  // src/docgen/component-docgen/api-description/api-description.ts
@@ -223,79 +214,30 @@ import { readFileSync } from "node:fs";
223
214
  import { readFile } from "node:fs/promises";
224
215
  import { resolve } from "node:path";
225
216
  import {
226
- createMetaComponentResolver,
217
+ createComponentNodeResolver,
227
218
  createModuleResolver,
219
+ defaultResolveConditionNames,
220
+ extractDeclaredSubcomponents,
221
+ extractSubcomponents,
228
222
  getStoryImportPathFromEntry,
229
- jsTsSourceExtensions
223
+ jsTsSourceExtensions,
224
+ typescriptExtensionAlias
230
225
  } from "storybook/internal/common";
231
226
  import {
232
227
  SourceEditor,
233
- collectImportBindings,
234
228
  loadCsf,
235
- metaObject,
236
229
  parseExpression,
237
- parseModule,
238
- propertyValue,
239
- resolveReferencedValue,
240
- staticKey,
241
- unwrapExpression
230
+ propertyValue
242
231
  } from "storybook/internal/csf-tools";
243
- var resolveMetaComponent = createMetaComponentResolver({ extensions: [".svelte"] }), moduleResolver = createModuleResolver({
232
+ var moduleResolver = createModuleResolver({
244
233
  extensions: [".svelte", ...jsTsSourceExtensions],
245
234
  // TypeScript projects import `./index.ts` as `./index.js`, as SvelteKit's packaging requires.
246
- extensionAlias: { ".js": [".ts", ".js"] },
235
+ extensionAlias: typescriptExtensionAlias,
247
236
  mainFields: ["svelte", "module", "main"],
248
- conditionNames: ["svelte", "import", "module", "default"],
237
+ // Core's conditions plus `svelte`, so a `storybook` entry resolves as it does in the preview.
238
+ conditionNames: ["svelte", ...defaultResolveConditionNames],
249
239
  tsconfig: "auto"
250
240
  });
251
- function resolveImport(fromFile, specifier) {
252
- try {
253
- return moduleResolver.resolveFileSync(fromFile, specifier);
254
- } catch {
255
- return;
256
- }
257
- }
258
- function importedName(specifier) {
259
- return specifier.type === "ImportDefaultSpecifier" ? "default" : specifier.type === "ImportNamespaceSpecifier" ? "*" : specifier.imported?.type === "Identifier" ? String(specifier.imported.name) : String(specifier.imported?.value);
260
- }
261
- function exportedName(node) {
262
- return node.type === "Identifier" ? node.name : String(node.value);
263
- }
264
- function followExport(filePath, exportName, seen = /* @__PURE__ */ new Set()) {
265
- if (filePath.endsWith(".svelte") && exportName === "default") return filePath;
266
- let key = `${filePath}#${exportName}`;
267
- if (seen.has(key)) return;
268
- seen.add(key);
269
- let program = moduleProgram(filePath);
270
- if (!program) return;
271
- let follow = (specifier, name) => {
272
- let target = resolveImport(filePath, specifier);
273
- return target ? followExport(target, name, seen) : void 0;
274
- }, followLocal = (localName) => {
275
- for (let declaration of program.body) {
276
- if (declaration.type !== "ImportDeclaration" || declaration.importKind === "type") continue;
277
- let imported = declaration.specifiers.find(
278
- (candidate) => candidate.local.name === localName
279
- );
280
- if (imported) return follow(declaration.source.value, importedName(imported));
281
- }
282
- };
283
- for (let statement of program.body) {
284
- if (statement.type === "ExportDefaultDeclaration" && exportName === "default" && statement.declaration.type === "Identifier")
285
- return followLocal(statement.declaration.name);
286
- if (statement.type === "ExportAllDeclaration" && !statement.exported) {
287
- let found = exportName !== "default" && statement.exportKind !== "type" && follow(statement.source.value, exportName);
288
- if (found) return found;
289
- }
290
- if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue;
291
- let specifier = statement.specifiers.find(
292
- (candidate) => exportedName(candidate.exported) === exportName
293
- );
294
- if (!specifier || specifier.exportKind === "type") continue;
295
- let localName = exportedName(specifier.local);
296
- return statement.source ? follow(statement.source.value, localName) : followLocal(localName);
297
- }
298
- }
299
241
  function moduleEditor(filePath) {
300
242
  try {
301
243
  let file = readFileSync(filePath, "utf8");
@@ -306,123 +248,83 @@ function moduleEditor(filePath) {
306
248
  return;
307
249
  }
308
250
  }
309
- function moduleProgram(filePath) {
310
- return moduleEditor(filePath)?.program;
311
- }
312
- function locate(storyPath, specifier, exportName, name) {
313
- let filePath = resolveImport(storyPath, specifier), componentPath = filePath && followExport(filePath, exportName);
314
- if (!componentPath)
315
- throw new Error(`Could not resolve \`${specifier}\` export \`${exportName}\``);
316
- return { componentPath, exportName, name };
251
+ function readModule(filePath) {
252
+ let editor = moduleEditor(filePath);
253
+ return editor && { editor, filePath };
317
254
  }
318
- async function resolveStoryComponent(entry) {
255
+ var isComponent = (filePath, exportName) => filePath.endsWith(".svelte") && exportName === "default", exportReader = {
256
+ resolver: moduleResolver,
257
+ readModule,
258
+ ownsExport: isComponent
259
+ }, resolveComponentExpression = createComponentNodeResolver({ reader: exportReader }), unresolved = (specifier, exportName) => new Error(`Could not resolve \`${specifier}\` export \`${exportName}\``);
260
+ async function readStoryFile(entry) {
319
261
  let importPath = getStoryImportPathFromEntry(entry);
320
262
  if (!importPath) return;
321
263
  let storyPath = resolve(importPath), file = await readFile(storyPath, "utf8");
322
- if (storyPath.endsWith(".svelte")) {
323
- let { source, ast } = parseSvelteSource(file), nodes = await extractSvelteASTNodes({ ast, filename: storyPath }), component = getDefineMetaComponentValue({ nodes, filename: storyPath });
324
- if (!component) return;
325
- for (let statement of ast.module?.content.body ?? []) {
326
- if (statement.type !== "ImportDeclaration") continue;
327
- let localName2 = component.type === "MemberExpression" ? component.object.name : component.name, specifier = statement.specifiers.find(
328
- (candidate) => candidate.local.name === localName2
329
- );
330
- if (!specifier) continue;
331
- if (component.type !== "MemberExpression")
332
- return locate(
333
- storyPath,
334
- String(statement.source.value),
335
- importedName(specifier),
336
- component.name
337
- );
338
- if (specifier.type === "ImportNamespaceSpecifier")
339
- return locate(
340
- storyPath,
341
- String(statement.source.value),
342
- component.property.name,
343
- component.property.name
344
- );
345
- let module = ast.module?.content;
346
- if (!module) return;
347
- let parsed = /* @__PURE__ */ new Map(), referenced = resolveReferencedValue(
348
- {
349
- editor: new SourceEditor(source.slice(module.start, module.end), `${storyPath}.ts`),
350
- filePath: storyPath,
351
- resolveModule: (fromFile, specifier2) => {
352
- let target = resolveImport(fromFile, specifier2);
353
- if (target) {
354
- if (!parsed.has(target)) {
355
- let editor = moduleEditor(target);
356
- parsed.set(target, editor && { editor, filePath: target });
357
- }
358
- return parsed.get(target);
359
- }
360
- }
361
- },
362
- component
363
- );
364
- if (!referenced) return;
365
- let value = unwrapExpression(referenced.node);
366
- if (value.type !== "Identifier") return;
367
- let binding = collectImportBindings(referenced.ctx.editor.program).get(value.name);
368
- return binding ? locate(
369
- referenced.ctx.filePath,
370
- binding.importId,
371
- binding.importName,
372
- component.property.name
373
- ) : void 0;
264
+ return storyPath.endsWith(".svelte") ? { storyPath, ...await readSvelteMeta(file, storyPath) } : { storyPath, csf: loadCsf(file, { makeTitle: () => entry.title }).parse() };
265
+ }
266
+ function resolveComponentNode(story, node) {
267
+ let { module, meta } = "csf" in story ? {
268
+ module: { editor: story.csf.editor, filePath: story.storyPath },
269
+ meta: story.csf._metaAnnotations.component
270
+ } : { module: story.module, meta: propertyValue(story.meta, "component") }, expression = node ?? meta;
271
+ if (!expression) return;
272
+ let resolved = resolveComponentExpression(module, expression);
273
+ if ("reason" in resolved)
274
+ switch (resolved.reason) {
275
+ case "unreadable-component-expression":
276
+ throw new Error(`Cannot resolve the component \`${resolved.expression}\``);
277
+ case "missing-export":
278
+ throw unresolved(resolved.importId, resolved.exportName);
279
+ case "no-meta-component":
280
+ case "no-component-import":
281
+ return;
282
+ default: {
283
+ let unhandled = resolved;
284
+ throw new Error(`Unhandled resolution ${JSON.stringify(unhandled)}`);
285
+ }
374
286
  }
375
- return;
287
+ let { importId, path, exportName, localName } = resolved.component;
288
+ if (importId) {
289
+ if (!path || !isComponent(path, exportName)) throw unresolved(importId, exportName);
290
+ return { componentPath: path, exportName, name: localName };
376
291
  }
377
- let resolved = resolveMetaComponent(
378
- loadCsf(file, { makeTitle: () => entry.title }).parse(),
379
- storyPath
380
- );
381
- if ("reason" in resolved) {
382
- if (resolved.reason === "unreadable-component-expression")
383
- throw new Error(`Cannot resolve the component \`${resolved.expression}\``);
384
- return;
385
- }
386
- let { importId, exportName, localName } = resolved.component;
387
- return importId ? locate(storyPath, importId, exportName, localName) : void 0;
292
+ }
293
+ async function resolveStoryComponent(entry) {
294
+ let story = await readStoryFile(entry);
295
+ return story && resolveComponentNode(story);
388
296
  }
389
297
  async function resolveStorySubcomponents(entry) {
390
- let importPath = getStoryImportPathFromEntry(entry);
391
- if (!importPath) return {};
392
- let storyPath = resolve(importPath), file = await readFile(storyPath, "utf8"), { meta, program } = storyPath.endsWith(".svelte") ? await readSvelteMeta(file, storyPath) : readCsfMeta(file, entry), subcomponents = propertyValue(meta, "subcomponents");
393
- if (subcomponents?.type !== "ObjectExpression") return {};
394
- let bindings = collectImportBindings(program), resolved = {};
395
- for (let property of subcomponents.properties) {
396
- let name = property.type === "Property" ? staticKey(property) : void 0, value = property.type === "Property" ? property.value : void 0, binding = value?.type === "Identifier" ? bindings.get(value.name) : void 0;
397
- if (!(!name || !binding))
398
- try {
399
- resolved[name] = locate(storyPath, binding.importId, binding.importName, name);
400
- } catch {
401
- continue;
402
- }
403
- }
298
+ let story = await readStoryFile(entry);
299
+ if (!story) return {};
300
+ let declared = "csf" in story ? extractDeclaredSubcomponents(story.csf) : extractSubcomponents(
301
+ propertyValue(story.meta, "subcomponents"),
302
+ story.module.editor.program
303
+ ), resolved = {};
304
+ for (let { name, node } of declared)
305
+ try {
306
+ let component = resolveComponentNode(story, node);
307
+ component && (resolved[name] = { ...component, name });
308
+ } catch {
309
+ continue;
310
+ }
404
311
  return resolved;
405
312
  }
406
- function readCsfMeta(source, entry) {
407
- let csf = loadCsf(source, { makeTitle: () => entry.title }).parse();
408
- return { meta: metaObject(csf), program: csf.program };
409
- }
410
313
  async function readSvelteMeta(file, storyPath) {
411
314
  let { source, ast } = parseSvelteSource(file), nodes = await extractSvelteASTNodes({ ast, filename: storyPath }), { start, end } = getDefineMetaFirstArgumentObjectExpression({
412
315
  nodes,
413
316
  filename: storyPath
414
- }), module = ast.module.content, meta = parseExpression(source.slice(start, end));
317
+ }), script = ast.module.content, meta = parseExpression(source.slice(start, end));
415
318
  return {
416
319
  meta: meta.type === "ObjectExpression" ? meta : void 0,
417
- program: parseModule(source.slice(module.start, module.end), `${storyPath}.ts`).program
320
+ module: {
321
+ editor: new SourceEditor(source.slice(script.start, script.end), `${storyPath}.ts`),
322
+ filePath: storyPath
323
+ }
418
324
  };
419
325
  }
420
326
 
421
327
  // src/docgen/component-docgen/build-docgen.ts
422
- function pathFromStory(storyPath, componentPath) {
423
- let fromStory = relative(dirname(realpathSync(resolve2(storyPath))), componentPath), path = join(dirname(storyPath), fromStory).replaceAll("\\", "/");
424
- return isAbsolute(path) || path.startsWith("../") ? path : `./${path}`;
425
- }
426
328
  async function buildDocgenPayload(input, context) {
427
329
  let path = getStoryImportPathFromEntry2(input.entry);
428
330
  if (!path) return;
@@ -443,7 +345,7 @@ async function buildDocgenPayload(input, context) {
443
345
  try {
444
346
  subcomponents[name] = {
445
347
  name,
446
- path: pathFromStory(path, subcomponent.componentPath),
348
+ path: componentPathFromStory(path, resolve2(path), subcomponent.componentPath),
447
349
  ...await componentDocs(subcomponent.componentPath, name, context)
448
350
  };
449
351
  } catch {
@@ -1,14 +1,3 @@
1
- import CJS_COMPAT_NODE_URL_ozn9e8tgwi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ozn9e8tgwi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ozn9e8tgwi from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_ozn9e8tgwi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ozn9e8tgwi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ozn9e8tgwi.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
1
  import {
13
2
  ArrayElementNotStringError,
14
3
  DefaultOrNamespaceImportUsedError,
@@ -32,7 +21,7 @@ import {
32
21
  getStoryIdentifiers,
33
22
  getStoryParents,
34
23
  hasMetaImport
35
- } from "./chunk-JCULIFGX.js";
24
+ } from "./chunk-FZFWZSUN.js";
36
25
 
37
26
  // src/svelte-csf/indexer/parser.ts
38
27
  import fs from "node:fs/promises";
@@ -94,7 +83,7 @@ function getIndexableAST(code) {
94
83
  async function parseForIndexer(filename) {
95
84
  let [file, { walk }] = await Promise.all([
96
85
  fs.readFile(filename, { encoding: "utf8" }),
97
- import("./walk-FGYTHLP6.js")
86
+ import("./walk-TKX2QFK2.js")
98
87
  ]), { ast: svelteAST } = parseSvelteSource(file), results = {
99
88
  meta: {},
100
89
  stories: [],
@@ -1,15 +1,3 @@
1
- import CJS_COMPAT_NODE_URL_ozn9e8tgwi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ozn9e8tgwi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ozn9e8tgwi from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_ozn9e8tgwi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ozn9e8tgwi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ozn9e8tgwi.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
1
  // src/docgen/component-docgen/svelte2tsx/generate-docgen.ts
14
2
  import path from "node:path";
15
3
  import { fileURLToPath } from "node:url";
@@ -0,0 +1,9 @@
1
+ // src/docgen/story-file.ts
2
+ import { STORY_FILE_TEST_REGEXP } from "storybook/internal/common";
3
+ var SVELTE_STORY_FILE_TEST_REGEXP = /\.stories\.svelte$/, SVELTE_DOCGEN_STORY_FILE_TEST_REGEXP = new RegExp(
4
+ `${SVELTE_STORY_FILE_TEST_REGEXP.source}|${STORY_FILE_TEST_REGEXP.source}`
5
+ );
6
+
7
+ export {
8
+ SVELTE_DOCGEN_STORY_FILE_TEST_REGEXP
9
+ };
@@ -1,15 +1,3 @@
1
- import CJS_COMPAT_NODE_URL_ozn9e8tgwi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ozn9e8tgwi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ozn9e8tgwi from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_ozn9e8tgwi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ozn9e8tgwi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ozn9e8tgwi.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
1
  // ../../../node_modules/zimmerframe/src/walk.js
14
2
  function walk(node, state, visitors) {
15
3
  let universal = visitors._, stopped = !1;
@@ -1,25 +1,13 @@
1
- import CJS_COMPAT_NODE_URL_ozn9e8tgwi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ozn9e8tgwi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ozn9e8tgwi from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_ozn9e8tgwi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ozn9e8tgwi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ozn9e8tgwi.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
1
  import {
13
- extractDefineMetaPropertiesNodes,
14
- getDefineMetaComponentName,
15
- getDefineMetaComponentValue
16
- } from "./chunk-BUMY5Y7X.js";
2
+ extractDefineMetaPropertiesNodes
3
+ } from "./chunk-XLMS4YUB.js";
17
4
  import {
5
+ InvalidComponentValueError,
18
6
  InvalidRenderValueError,
19
7
  InvalidStoryTemplateAttributeError,
20
8
  extractStoryAttributesNodes,
21
9
  extractStoryTemplateSnippetBlock
22
- } from "./chunk-JCULIFGX.js";
10
+ } from "./chunk-FZFWZSUN.js";
23
11
 
24
12
  // src/svelte-csf/parser/ast.ts
25
13
  import { compile } from "svelte/compiler";
@@ -139,6 +127,37 @@ function findSnippetBlockByName(options) {
139
127
 
140
128
  // src/svelte-csf/parser/analyse/story/content.ts
141
129
  import { dedent } from "ts-dedent";
130
+
131
+ // src/svelte-csf/parser/analyse/define-meta/component-identifier.ts
132
+ import { unwrapExpression as unwrapExpression3 } from "storybook/internal/csf-tools";
133
+ function getDefineMetaComponentValue(params) {
134
+ let { nodes, filename } = params, { component } = extractDefineMetaPropertiesNodes({
135
+ nodes,
136
+ properties: ["component"],
137
+ filename
138
+ });
139
+ if (!component)
140
+ return;
141
+ let value = withoutTypeArguments(unwrapExpression3(component.value));
142
+ if (!isValidComponentValue(value))
143
+ throw new InvalidComponentValueError({
144
+ filename,
145
+ componentProperty: component
146
+ });
147
+ return value;
148
+ }
149
+ function withoutTypeArguments(value) {
150
+ let node = value;
151
+ return node.type === "TSInstantiationExpression" ? unwrapExpression3(node.expression) : value;
152
+ }
153
+ function isValidComponentValue(value) {
154
+ return value.type === "Identifier" ? !0 : value.type === "MemberExpression" && !value.computed && value.object.type === "Identifier" && value.property.type === "Identifier";
155
+ }
156
+ function getDefineMetaComponentName(value) {
157
+ return value ? value.type === "MemberExpression" ? `${value.object.name}.${value.property.name}` : value.name : "undefined";
158
+ }
159
+
160
+ // src/svelte-csf/parser/analyse/story/content.ts
142
161
  function getStoryContentRawCode(params) {
143
162
  let { nodes, originalCode, filename } = params, { component, svelte } = nodes;
144
163
  if (component.fragment.nodes.length === 0) {
@@ -1,15 +1,3 @@
1
- import CJS_COMPAT_NODE_URL_ozn9e8tgwi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ozn9e8tgwi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ozn9e8tgwi from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_ozn9e8tgwi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ozn9e8tgwi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ozn9e8tgwi.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
1
  // src/svelte-csf/constants.ts
14
2
  var SVELTE_CSF_TAG_PREFIX = "svelte-csf", SVELTE_CSF_V5_TAG = `${SVELTE_CSF_TAG_PREFIX}-v5`, STORYBOOK_INTERNAL_PREFIX = "$__", STORYBOOK_META_IDENTIFIER = `${STORYBOOK_INTERNAL_PREFIX}meta`, RUNTIME_STORIES_IDENTIFIER = `${STORYBOOK_INTERNAL_PREFIX}stories`, SVELTE_CSF_FRAMEWORK_IMPORT_SOURCES = [
15
3
  "@storybook/svelte-vite",