@storybook/svelte 11.0.0-alpha.1 → 11.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 (33) hide show
  1. package/dist/_node-chunks/chunk-QVOOVEY3.js +902 -0
  2. package/dist/_node-chunks/chunk-XG6FO5LG.js +18 -0
  3. package/dist/_node-chunks/{parsers-H2LWDUQQ.js → parsers-XK3HYEM3.js} +6 -6
  4. package/dist/_node-chunks/walk-UCLUTCVD.js +100 -0
  5. package/dist/chunk-C5ZpXlin.d.ts +138 -0
  6. package/dist/docgen/docgen-worker.js +26 -0
  7. package/dist/entry-preview-docs.js +1 -1
  8. package/dist/index.d.ts +13 -46
  9. package/dist/index.js +9 -0
  10. package/dist/preset.js +66 -9
  11. package/dist/svelte-csf/addon-check.d.ts +14 -0
  12. package/dist/svelte-csf/addon-check.js +56 -0
  13. package/dist/svelte-csf/compiler/transform.d.ts +1117 -0
  14. package/dist/svelte-csf/compiler/transform.js +2201 -0
  15. package/dist/svelte-csf/indexer/index.d.ts +6 -0
  16. package/dist/svelte-csf/indexer/index.js +214 -0
  17. package/dist/svelte-csf/runtime/component-helpers.d.ts +24 -0
  18. package/dist/svelte-csf/runtime/component-helpers.js +59 -0
  19. package/dist/svelte-csf/runtime/create-runtime-stories.d.ts +19 -0
  20. package/dist/svelte-csf/runtime/create-runtime-stories.js +47 -0
  21. package/package.json +55 -4
  22. package/static/createReactiveProps.svelte.js +1 -0
  23. package/static/svelte-csf/StoriesExtractor.svelte +18 -0
  24. package/static/svelte-csf/Story.svelte +85 -0
  25. package/static/svelte-csf/StoryRenderer.svelte +36 -0
  26. package/static/svelte-csf/contexts/extractor.svelte.js +68 -0
  27. package/static/svelte-csf/contexts/renderer.svelte.js +71 -0
  28. package/template/cli/js/Button.stories.svelte +1 -1
  29. package/template/cli/js/Header.stories.svelte +1 -1
  30. package/template/cli/js/Page.stories.svelte +1 -1
  31. package/template/cli/ts/Button.stories.svelte +1 -1
  32. package/template/cli/ts/Header.stories.svelte +1 -1
  33. package/template/cli/ts/Page.stories.svelte +1 -1
@@ -0,0 +1,902 @@
1
+ import CJS_COMPAT_NODE_URL_a1hnnkx33fo from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_a1hnnkx33fo from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_a1hnnkx33fo from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_a1hnnkx33fo.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_a1hnnkx33fo.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_a1hnnkx33fo.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+
13
+ // src/svelte-csf/constants.ts
14
+ 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
+ "@storybook/svelte-vite",
16
+ "@storybook/sveltekit"
17
+ ], SVELTE_CSF_RENDERER_IMPORT_SOURCE = "@storybook/svelte", SVELTE_CSF_IMPORT_SOURCES = [
18
+ ...SVELTE_CSF_FRAMEWORK_IMPORT_SOURCES,
19
+ SVELTE_CSF_RENDERER_IMPORT_SOURCE
20
+ ], SVELTE_CSF_RUNTIME_STORIES_IMPORT_SOURCE = "@storybook/svelte/internal/svelte-csf/create-runtime-stories";
21
+
22
+ // src/svelte-csf/parser/ast.ts
23
+ import { compile } from "svelte/compiler";
24
+ function getSvelteAST(options) {
25
+ let { filename, code } = options, { ast } = compile(code, {
26
+ filename,
27
+ modernAst: !0
28
+ });
29
+ return ast;
30
+ }
31
+ function createASTProperty(name, value) {
32
+ return {
33
+ type: "Property",
34
+ kind: "init",
35
+ computed: !1,
36
+ method: !1,
37
+ shorthand: !1,
38
+ key: {
39
+ type: "Identifier",
40
+ name
41
+ },
42
+ value
43
+ };
44
+ }
45
+ function createASTArrayExpression(elements = []) {
46
+ return {
47
+ type: "ArrayExpression",
48
+ elements
49
+ };
50
+ }
51
+ function createASTObjectExpression(properties = []) {
52
+ return {
53
+ type: "ObjectExpression",
54
+ properties
55
+ };
56
+ }
57
+ function appendASTProperty(node, property) {
58
+ node.properties = [...node.properties, property];
59
+ }
60
+ function createASTIdentifier(name) {
61
+ return {
62
+ type: "Identifier",
63
+ name
64
+ };
65
+ }
66
+ function createASTExportSpecifier({
67
+ local,
68
+ exported
69
+ }) {
70
+ return {
71
+ type: "ExportSpecifier",
72
+ local: createASTIdentifier(local),
73
+ exported: createASTIdentifier(exported ?? local)
74
+ };
75
+ }
76
+
77
+ // src/svelte-csf/utils/error.ts
78
+ import url from "node:url";
79
+ import rendererPkg from "@storybook/svelte/package.json" with { type: "json" };
80
+ var [SVELTE_VITE_IMPORT_SOURCE, SVELTEKIT_IMPORT_SOURCE] = SVELTE_CSF_FRAMEWORK_IMPORT_SOURCES, StorybookSvelteCSFError = class _StorybookSvelteCSFError extends Error {
81
+ constructor({
82
+ filename,
83
+ component
84
+ }, options) {
85
+ super();
86
+ /**
87
+ * Data associated with the error. Used to provide additional information in the error message or to be passed to telemetry.
88
+ */
89
+ this.data = {};
90
+ /**
91
+ * Specifies the documentation for the error.
92
+ * - If `true`, links to a documentation page on the Storybook website (make sure it exists before enabling).
93
+ * - If a string, uses the provided URL for documentation (external or FAQ links).
94
+ * - If `false` (default), no documentation link is added.
95
+ */
96
+ this.documentation = !1;
97
+ /**
98
+ * Flag used to easily determine if the error originates from Storybook.
99
+ */
100
+ this.fromStorybook = !0;
101
+ this.cause = options?.cause, this.filename = filename, this.component = component;
102
+ }
103
+ static {
104
+ this.isStorybookCSFSvelteError = !0;
105
+ }
106
+ static {
107
+ // Users import `defineMeta` from their framework. The messages name both frameworks.
108
+ this.importSource = SVELTE_VITE_IMPORT_SOURCE;
109
+ }
110
+ static {
111
+ this.sveltekitImportSource = SVELTEKIT_IMPORT_SOURCE;
112
+ }
113
+ static {
114
+ this.importSourcesText = SVELTE_CSF_FRAMEWORK_IMPORT_SOURCES.map(
115
+ (source) => `"${source}"`
116
+ ).join(" or ");
117
+ }
118
+ static {
119
+ this.packageVersion = rendererPkg.version;
120
+ }
121
+ static {
122
+ this.CATEGORY = {
123
+ parserExtractSvelte: "PARSER_EXTRACT_SVELTE",
124
+ parserExtractCompiled: "PARSER_EXTRACT_COMPILED",
125
+ parserAnalyseDefineMeta: "PARSER_ANALYSE_DEFINE_META",
126
+ parserAnalyseStory: "PARSER_ANALYSE_STORY",
127
+ compiler: "COMPILER"
128
+ };
129
+ }
130
+ get fullErrorCode() {
131
+ let paddedCode = String(this.code).padStart(4, "0");
132
+ return `SB_SVELTE_CSF_${this.category}_${paddedCode}`;
133
+ }
134
+ /**
135
+ * Overrides the default `Error.name` property in the format: SB_<CATEGORY>_<CODE>.
136
+ */
137
+ get name() {
138
+ let errorName = this.constructor.name;
139
+ return `${this.fullErrorCode} (${errorName})`;
140
+ }
141
+ /**
142
+ * Generates the error message along with additional documentation link (if applicable).
143
+ */
144
+ get message() {
145
+ if (this.customMessage)
146
+ return this.customMessage;
147
+ let page;
148
+ return this.documentation === !0 ? page = `https://github.com/storybookjs/storybook/blob/v${_StorybookSvelteCSFError.packageVersion}/code/renderers/svelte/src/svelte-csf/ERRORS.md#${this.fullErrorCode}` : typeof this.documentation == "string" ? page = this.documentation : Array.isArray(this.documentation) && (page = `
149
+ ${this.documentation.map((doc) => ` - ${doc}`).join(`
150
+ `)}`), `${this.template()}${page != null ? `
151
+
152
+ More info: ${page}
153
+ ` : ""}`;
154
+ }
155
+ /**
156
+ * Allows anyone to set Error.message after creation, mimicking the native Error behavior.
157
+ * Vite does this sometimes.
158
+ */
159
+ set message(message) {
160
+ this.customMessage = message;
161
+ }
162
+ // WARN: I had to duplicate logic. We already have functions for it.
163
+ // But we can't import it, because it would create a cyclic-dependency.
164
+ get storyNameFromAttribute() {
165
+ if (!this.component)
166
+ return "<UnnamedComponent>";
167
+ let { attributes } = this.component;
168
+ for (let attribute of attributes)
169
+ if (attribute.type === "Attribute" && attribute.value !== !0) {
170
+ if (!Array.isArray(attribute.value))
171
+ return "value" in attribute.value.expression ? attribute.value.expression.value : void 0;
172
+ if (attribute.value[0].type === "Text")
173
+ return attribute.value[0].data;
174
+ if (attribute.value[0].expression.type === "Literal" && typeof attribute.value[0].expression.value == "string")
175
+ return attribute.value[0].expression.value;
176
+ }
177
+ }
178
+ get filepathURL() {
179
+ return this.filename ? url.pathToFileURL(this.filename) : "<path not specified>";
180
+ }
181
+ get quickStoryRawCodeIdentifier() {
182
+ return `<Story name="${this.storyNameFromAttribute}" />`;
183
+ }
184
+ };
185
+ function isStorybookSvelteCSFError(error) {
186
+ return !!Object.getPrototypeOf(error)?.constructor?.isStorybookCSFSvelteError;
187
+ }
188
+
189
+ // src/svelte-csf/utils/error/parser/extract/svelte.ts
190
+ import { inspect } from "node:util";
191
+ import { logger } from "storybook/internal/node-logger";
192
+ import { dedent } from "ts-dedent";
193
+ var BASE_INITIAL_SNIPPET = dedent`
194
+ <script module>
195
+ import { defineMeta } from "${StorybookSvelteCSFError.importSource}";
196
+
197
+ const { Story } = defineMeta({});
198
+ </script>
199
+
200
+ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.sveltekitImportSource}".
201
+ `, MissingModuleTagError = class extends StorybookSvelteCSFError {
202
+ constructor(filename) {
203
+ super({ filename });
204
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
205
+ this.code = 1;
206
+ this.documentation = !0;
207
+ }
208
+ template() {
209
+ return dedent`
210
+ The file '${this.filepathURL}'
211
+ does not have a module context (<script module> ... </script>).
212
+
213
+ defineMeta(...) should be called inside a module script tag, like so:
214
+
215
+ ${BASE_INITIAL_SNIPPET}
216
+ `;
217
+ }
218
+ }, DefaultOrNamespaceImportUsedError = class extends StorybookSvelteCSFError {
219
+ constructor(filename) {
220
+ super({ filename });
221
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
222
+ this.code = 2;
223
+ this.documentation = !0;
224
+ }
225
+ template() {
226
+ return dedent`
227
+ The file '${this.filepathURL}'
228
+ is using a default or namespace import of ${StorybookSvelteCSFError.importSourcesText},
229
+ and doesn't import defineMeta by name. Import it with a named import, like so:
230
+
231
+ import { defineMeta } from "${StorybookSvelteCSFError.importSource}";
232
+
233
+ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.sveltekitImportSource}".
234
+ `;
235
+ }
236
+ }, MissingDefineMetaImportError = class extends StorybookSvelteCSFError {
237
+ constructor(filename) {
238
+ super({ filename });
239
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
240
+ this.code = 3;
241
+ this.documentation = !0;
242
+ }
243
+ template() {
244
+ return dedent`
245
+ The file '${this.filepathURL}'
246
+ does not import defineMeta from ${StorybookSvelteCSFError.importSourcesText} inside the module context.
247
+
248
+ Make sure to import defineMeta from the package and use it inside the module context like so:
249
+
250
+ ${BASE_INITIAL_SNIPPET}
251
+ `;
252
+ }
253
+ }, MissingDefineMetaVariableDeclarationError = class extends StorybookSvelteCSFError {
254
+ constructor(filename) {
255
+ super({ filename });
256
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
257
+ this.code = 4;
258
+ this.documentation = !0;
259
+ }
260
+ template() {
261
+ return dedent`
262
+ The file '${this.filepathURL}'
263
+ does not store the result of calling defineMeta(). While defineMeta() might have been called,
264
+ it's return value needs to be stored and destructured for the parsing to succeed, eg.:
265
+
266
+ ${BASE_INITIAL_SNIPPET}
267
+ `;
268
+ }
269
+ }, NoStoryComponentDestructuredError = class extends StorybookSvelteCSFError {
270
+ constructor({
271
+ filename,
272
+ defineMetaImport
273
+ }) {
274
+ super({ filename });
275
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
276
+ this.code = 5;
277
+ this.documentation = !0;
278
+ this.defineMetaImport = defineMetaImport;
279
+ }
280
+ template() {
281
+ return dedent`
282
+ The file '${this.filepathURL}'
283
+ does not destructure the Story component from the '${this.defineMetaImport.local.name}({ ... })' function call.
284
+ eg.:
285
+
286
+ ${BASE_INITIAL_SNIPPET}
287
+ `;
288
+ }
289
+ }, GetDefineMetaFirstArgumentError = class extends StorybookSvelteCSFError {
290
+ constructor({
291
+ filename,
292
+ defineMetaVariableDeclaration
293
+ }) {
294
+ super({ filename });
295
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
296
+ this.code = 6;
297
+ this.documentation = !0;
298
+ this.defineMetaVariableDeclaration = defineMetaVariableDeclaration;
299
+ }
300
+ template() {
301
+ return dedent`
302
+ The file '${this.filepathURL}'
303
+ passes an invalid first argument to the 'defineMeta' call.
304
+
305
+ The first argument must be an object expression with the meta properties set.
306
+ `;
307
+ }
308
+ }, InvalidStoryTemplateAttributeError = class extends StorybookSvelteCSFError {
309
+ constructor({
310
+ filename,
311
+ component,
312
+ templateAttribute
313
+ }) {
314
+ super({ filename, component });
315
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
316
+ this.code = 7;
317
+ this.documentation = !0;
318
+ this.templateAttribute = templateAttribute;
319
+ }
320
+ template() {
321
+ return dedent`
322
+ Component '${this.quickStoryRawCodeIdentifier}' in the stories file '${this.filepathURL}'
323
+ has an invalid 'template'-prop.
324
+
325
+ When set, the 'template'-prop must be an expression with reference to a root-level snippet.
326
+
327
+ Eg.:
328
+
329
+ {#snippet template()}
330
+ ...
331
+ {/snippet}
332
+
333
+ <Story name="${this.storyNameFromAttribute}" template={template} />
334
+ `;
335
+ }
336
+ }, describeCause = (cause) => {
337
+ if (cause instanceof Error)
338
+ return logger.shouldLog("debug") && cause.stack ? cause.stack : `${cause.name}: ${cause.message}`;
339
+ if (typeof cause == "string")
340
+ return cause;
341
+ try {
342
+ return inspect(cause);
343
+ } catch {
344
+ return "<the original error could not be printed>";
345
+ }
346
+ }, IndexerParseError = class extends StorybookSvelteCSFError {
347
+ constructor(filename, options) {
348
+ super({ filename }, options);
349
+ this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
350
+ this.code = 9;
351
+ this.documentation = !0;
352
+ }
353
+ template() {
354
+ return dedent`
355
+ Storybook stories indexer parser threw an unrecognized error while indexing the file '${this.filepathURL}':
356
+
357
+ ${describeCause(this.cause)}
358
+
359
+ If the original error doesn't point to a problem in the stories file or in the Svelte config, please report it on the issue tracker on GitHub at https://github.com/storybookjs/storybook/issues/new?template=bug_report.yml.
360
+ `;
361
+ }
362
+ };
363
+
364
+ // src/svelte-csf/utils/is-one-of.ts
365
+ function isOneOf(values, value) {
366
+ return values.some((candidate) => candidate === value);
367
+ }
368
+
369
+ // src/svelte-csf/utils/import-source.ts
370
+ function isSvelteCsfImportSource(source) {
371
+ return typeof source == "string" && isOneOf(SVELTE_CSF_IMPORT_SOURCES, source);
372
+ }
373
+ function findDefineMetaImport(body) {
374
+ let result = { hasDefaultOrNamespaceImport: !1 };
375
+ for (let statement of body)
376
+ if (!(statement.type !== "ImportDeclaration" || !isSvelteCsfImportSource(statement.source.value)))
377
+ for (let specifier of statement.specifiers)
378
+ specifier.type !== "ImportSpecifier" ? result.hasDefaultOrNamespaceImport = !0 : "name" in specifier.imported && specifier.imported.name === "defineMeta" && (result.defineMetaImport = specifier);
379
+ return result;
380
+ }
381
+
382
+ // src/svelte-csf/parser/extract/svelte/story/attributes.ts
383
+ function extractStoryAttributesNodes(options) {
384
+ let { attributes, component } = options, results = {};
385
+ for (let attributeNode of component.attributes)
386
+ attributeNode.type === "Attribute" && isOneOf(attributes, attributeNode.name) && (results[attributeNode.name] = attributeNode);
387
+ return results;
388
+ }
389
+
390
+ // src/svelte-csf/utils/error/parser/analyse/story.ts
391
+ import { dedent as dedent2 } from "ts-dedent";
392
+ var AttributeNotStringError = class extends StorybookSvelteCSFError {
393
+ constructor({
394
+ filename,
395
+ attribute,
396
+ component
397
+ }) {
398
+ super({ component, filename });
399
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
400
+ this.code = 1;
401
+ this.documentation = !0;
402
+ this.attribute = attribute;
403
+ }
404
+ template() {
405
+ return dedent2`
406
+ In the stories file: ${this.filepathURL}
407
+
408
+ A '${this.quickStoryRawCodeIdentifier}' has a prop '${this.attribute.name}' whose value must be a static literal string.
409
+ `;
410
+ }
411
+ }, AttributeNotArrayError = class extends StorybookSvelteCSFError {
412
+ constructor({
413
+ filename,
414
+ attribute,
415
+ component
416
+ }) {
417
+ super({ component, filename });
418
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
419
+ this.code = 2;
420
+ this.documentation = !0;
421
+ this.attribute = attribute;
422
+ }
423
+ get valueType() {
424
+ let { attribute } = this, { value } = attribute;
425
+ return value === !0 ? !0 : Array.isArray(value) ? value[0].type === "Text" ? value[0].data : value[0].expression.value : value.expression.value;
426
+ }
427
+ template() {
428
+ return dedent2`
429
+ In the stories file: ${this.filepathURL}
430
+
431
+ A '${this.quickStoryRawCodeIdentifier}' has a prop'${this.attribute.name}' whose value was expected to be a static array.
432
+ Instead the value type is '${this.valueType}'.
433
+ `;
434
+ }
435
+ }, AttributeNotArrayOfStringsError = class extends StorybookSvelteCSFError {
436
+ constructor({
437
+ filename,
438
+ attribute,
439
+ component,
440
+ element
441
+ }) {
442
+ super({ component, filename });
443
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
444
+ this.code = 3;
445
+ this.documentation = !0;
446
+ this.attribute = attribute, this.element = element;
447
+ }
448
+ get valueType() {
449
+ let { attribute } = this, { value } = attribute;
450
+ return value === !0 ? !0 : Array.isArray(value) ? value[0].type === "Text" ? value[0].data : value[0].expression.value : value.expression.value;
451
+ }
452
+ template() {
453
+ return dedent2`
454
+ In the stories file: ${this.filepathURL}
455
+
456
+ A '${this.quickStoryRawCodeIdentifier}' has attribute '${this.attribute.name}' whose value was expected to be an array expression.
457
+ All elements in the array must be static literal strings only, but one of the elements is of type '${this.valueType}'.
458
+ `;
459
+ }
460
+ }, NoStoryIdentifierError = class extends StorybookSvelteCSFError {
461
+ constructor({
462
+ filename,
463
+ component
464
+ }) {
465
+ super({ component, filename });
466
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
467
+ this.code = 4;
468
+ this.documentation = !0;
469
+ }
470
+ template() {
471
+ return dedent2`
472
+ Missing 'name' or 'exportName' attribute (prop) in a '<Story />' definition in the stories file: '${this.filepathURL}'.
473
+ All stories must either have a 'name' or an 'exportName' prop, or both.
474
+ `;
475
+ }
476
+ }, InvalidStoryExportNameError = class extends StorybookSvelteCSFError {
477
+ constructor({
478
+ filename,
479
+ component,
480
+ value
481
+ }) {
482
+ super({ component, filename });
483
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
484
+ this.code = 5;
485
+ this.documentation = !0;
486
+ this.value = value;
487
+ }
488
+ template() {
489
+ return dedent2`
490
+ Invalid attribute 'exportName' value '${this.value}' found in '<Story />' component inside stories file: ${this.filepathURL}
491
+
492
+ 'exportName' value must be a valid JavaScript variable name.
493
+ It must start with a letter, $ or _, followed by letters, numbers, $ or _.
494
+ Reserved words like 'default' are also not allowed (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words)
495
+ `;
496
+ }
497
+ }, DuplicateStoryIdentifiersError = class extends StorybookSvelteCSFError {
498
+ constructor({
499
+ filename,
500
+ identifiers,
501
+ duplicateIdentifiers
502
+ }) {
503
+ super({ filename });
504
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
505
+ this.code = 6;
506
+ this.documentation = !0;
507
+ this.identifiers = identifiers, this.duplicateIdentifiers = duplicateIdentifiers;
508
+ }
509
+ template() {
510
+ return dedent2`
511
+ Duplicate exportNames found between two '<Story />' definitions in stories file: ${this.filepathURL}
512
+
513
+ First instance: <Story name=${this.duplicateIdentifiers.name ? `"${this.duplicateIdentifiers.name}"` : "{undefined}"} exportName="${this.duplicateIdentifiers.exportName}" ... />
514
+ Second instance: <Story name=${this.identifiers.name ? `"${this.identifiers.name}"` : "{undefined}"} exportName="${this.identifiers.exportName}" ... />
515
+
516
+ This can happen when 'exportName' is implicitly derived by 'name'.
517
+ Complex names will be simplified to a PascalCased, valid JavaScript variable name,
518
+ eg. 'Some story name!!' will be converted to 'SomeStoryName'.
519
+ You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.
520
+ `;
521
+ }
522
+ }, StoryTemplateAndChildrenError = class extends StorybookSvelteCSFError {
523
+ constructor({
524
+ filename,
525
+ component
526
+ }) {
527
+ super({ component, filename });
528
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
529
+ this.code = 7;
530
+ this.documentation = !0;
531
+ }
532
+ template() {
533
+ return dedent2`
534
+ A '${this.quickStoryRawCodeIdentifier}' has both a 'template' prop and children elements defined, which is not allowed.
535
+ Use the 'template' snippet to define the story's content structure.
536
+ Found in file: ${this.filepathURL}
537
+ `;
538
+ }
539
+ }, StoryTemplateAndAsChildError = class extends StorybookSvelteCSFError {
540
+ constructor({
541
+ filename,
542
+ component
543
+ }) {
544
+ super({ component, filename });
545
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
546
+ this.code = 8;
547
+ this.documentation = !0;
548
+ }
549
+ template() {
550
+ return dedent2`
551
+ A '${this.quickStoryRawCodeIdentifier}' has both a 'template' prop and the 'asChild' prop set.
552
+ Use the 'template' snippet to define the story's content structure.
553
+ Found in file: ${this.filepathURL}
554
+ `;
555
+ }
556
+ }, StoryAsChildWithoutChildrenError = class extends StorybookSvelteCSFError {
557
+ constructor({
558
+ filename,
559
+ component
560
+ }) {
561
+ super({ component, filename });
562
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseStory;
563
+ this.code = 9;
564
+ this.documentation = !0;
565
+ }
566
+ template() {
567
+ return dedent2`
568
+ A '${this.quickStoryRawCodeIdentifier}' has the 'asChild' prop set, but no children were provided. The 'asChild' prop requires children to render the story content.
569
+ Found in file: ${this.filepathURL}
570
+ `;
571
+ }
572
+ };
573
+
574
+ // src/svelte-csf/parser/analyse/story/attributes.ts
575
+ function getLiteralValueFromAttribute(params) {
576
+ let { node, filename, component } = params;
577
+ if (!node)
578
+ return;
579
+ let { value } = node;
580
+ if (value === !0)
581
+ throw new AttributeNotStringError({ filename, component, attribute: node });
582
+ if (!Array.isArray(value)) {
583
+ if (value.expression.type === "Literal")
584
+ return value.expression.value;
585
+ throw new AttributeNotStringError({ filename, component, attribute: node });
586
+ }
587
+ let [first] = value;
588
+ if (first.type === "Text")
589
+ return first.data;
590
+ if (first.type === "ExpressionTag" && first.expression.type === "Literal" && typeof first.expression.value == "string")
591
+ return first.expression.value;
592
+ throw new AttributeNotStringError({ filename, component, attribute: node });
593
+ }
594
+ function getStringValueFromAttribute(params) {
595
+ let { node, filename, component } = params;
596
+ if (!node)
597
+ return;
598
+ let value = getLiteralValueFromAttribute(params);
599
+ if (typeof value != "string")
600
+ throw new AttributeNotStringError({ filename, component, attribute: node });
601
+ return value;
602
+ }
603
+ function getArrayOfStringsValueFromAttribute(params) {
604
+ let { node, filename, component } = params;
605
+ if (!node)
606
+ return [];
607
+ let { value } = node;
608
+ if (value === !0)
609
+ throw new AttributeNotArrayError({
610
+ component,
611
+ filename,
612
+ attribute: node
613
+ });
614
+ if (!Array.isArray(value)) {
615
+ if (value.expression.type !== "ArrayExpression")
616
+ throw new AttributeNotArrayError({
617
+ component,
618
+ filename,
619
+ attribute: node
620
+ });
621
+ let arrayOfStrings2 = [];
622
+ for (let element of value.expression.elements) {
623
+ if (element?.type !== "Literal" || typeof element.value != "string")
624
+ throw new AttributeNotArrayOfStringsError({
625
+ filename,
626
+ component,
627
+ attribute: node,
628
+ element
629
+ });
630
+ arrayOfStrings2.push(element.value);
631
+ }
632
+ return arrayOfStrings2;
633
+ }
634
+ if (value[0].type !== "ExpressionTag" || value[0].expression.type !== "ArrayExpression")
635
+ throw new AttributeNotArrayError({
636
+ component,
637
+ filename,
638
+ attribute: node
639
+ });
640
+ let arrayOfStrings = [];
641
+ for (let element of value[0].expression.elements) {
642
+ if (element?.type !== "Literal" || typeof element.value != "string")
643
+ throw new AttributeNotArrayOfStringsError({
644
+ filename,
645
+ component,
646
+ attribute: node,
647
+ element
648
+ });
649
+ arrayOfStrings.push(element.value);
650
+ }
651
+ return arrayOfStrings;
652
+ }
653
+
654
+ // src/svelte-csf/utils/identifier-utils.ts
655
+ import { sanitize } from "storybook/internal/csf";
656
+ var storyIdToExportName = (storyId) => storyId.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
657
+ var storyNameToId = (name) => (
658
+ // add a space before all caps and use utility from @storybook/csf to sanitize the resulting string
659
+ sanitize(name.replace(/([A-Z])/g, " $1").trim())
660
+ ), storyNameToExportName = (name) => storyIdToExportName(storyNameToId(name)), isValidVariableName = (str) => {
661
+ if (typeof str != "string" || str.trim() !== str)
662
+ return !1;
663
+ try {
664
+ new Function(str, "var " + str);
665
+ } catch {
666
+ return !1;
667
+ }
668
+ return !0;
669
+ };
670
+
671
+ // src/svelte-csf/parser/analyse/story/attributes/identifiers.ts
672
+ function getStoryIdentifiers(options) {
673
+ let { nameNode, exportNameNode, filename, component } = options, exportNameValue = getLiteralValueFromAttribute({
674
+ node: exportNameNode,
675
+ filename,
676
+ component
677
+ }), name = getStringValueFromAttribute({
678
+ node: nameNode,
679
+ filename,
680
+ component
681
+ }), exportName;
682
+ if (exportNameValue)
683
+ if (typeof exportNameValue == "string")
684
+ exportName = exportNameValue;
685
+ else
686
+ throw new InvalidStoryExportNameError({
687
+ filename,
688
+ component,
689
+ value: String(exportNameValue)
690
+ });
691
+ else {
692
+ if (!name)
693
+ throw new NoStoryIdentifierError({
694
+ component,
695
+ filename
696
+ });
697
+ exportName = storyNameToExportName(name);
698
+ }
699
+ if (!isValidVariableName(exportName))
700
+ throw new InvalidStoryExportNameError({
701
+ filename,
702
+ component,
703
+ value: exportName
704
+ });
705
+ return {
706
+ name,
707
+ exportName
708
+ };
709
+ }
710
+ function getStoriesIdentifiers(params) {
711
+ let { nodes, filename } = params, { storyComponents } = nodes, allIdentifiers = [];
712
+ for (let story of storyComponents) {
713
+ let { exportName, name } = extractStoryAttributesNodes({
714
+ component: story.component,
715
+ filename,
716
+ attributes: ["exportName", "name"]
717
+ }), identifiers = getStoryIdentifiers({
718
+ exportNameNode: exportName,
719
+ nameNode: name,
720
+ filename,
721
+ component: story.component
722
+ }), duplicateIdentifiers = allIdentifiers.find(
723
+ (existingIdentifiers) => existingIdentifiers.exportName === identifiers.exportName
724
+ );
725
+ if (duplicateIdentifiers)
726
+ throw new DuplicateStoryIdentifiersError({
727
+ filename,
728
+ identifiers,
729
+ duplicateIdentifiers
730
+ });
731
+ allIdentifiers.push(identifiers);
732
+ }
733
+ return allIdentifiers;
734
+ }
735
+
736
+ // src/svelte-csf/utils/error/parser/analyse/define-meta.ts
737
+ import { dedent as dedent3 } from "ts-dedent";
738
+ var InvalidComponentValueError = class extends StorybookSvelteCSFError {
739
+ constructor({
740
+ filename,
741
+ componentProperty
742
+ }) {
743
+ super({ filename });
744
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseDefineMeta;
745
+ this.code = 1;
746
+ this.documentation = !0;
747
+ this.componentProperty = componentProperty;
748
+ }
749
+ template() {
750
+ return dedent3`
751
+ The 'component' property of 'defineMeta' must reference an imported Svelte component.
752
+ The current type of the property is '${this.componentProperty.value.type}'.
753
+
754
+ The issue occurred in Stories file: ${this.filepathURL}
755
+ `;
756
+ }
757
+ }, NoDestructuredDefineMetaCallError = class extends StorybookSvelteCSFError {
758
+ constructor({
759
+ filename,
760
+ defineMetaVariableDeclarator
761
+ }) {
762
+ super({ filename });
763
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseDefineMeta;
764
+ this.code = 2;
765
+ this.documentation = !0;
766
+ this.node = defineMetaVariableDeclarator;
767
+ }
768
+ template() {
769
+ return dedent3`
770
+ The return value of the 'defineMeta' call was not destructured to { Story }.
771
+ The issue occurred in Stories file: ${this.filepathURL}
772
+
773
+ The current pattern type is: "${this.node.id.type}", and expected is "ObjectPattern".
774
+ `;
775
+ }
776
+ }, NoStringLiteralError = class extends StorybookSvelteCSFError {
777
+ constructor({
778
+ filename,
779
+ property
780
+ }) {
781
+ super({ filename });
782
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseDefineMeta;
783
+ this.code = 3;
784
+ this.documentation = !0;
785
+ this.property = property;
786
+ }
787
+ template() {
788
+ return dedent3`
789
+ The '${this.property.key.name}' passed to 'defineMeta()' must be a static string literal.
790
+ But it is of type '${this.property.value.type}'.
791
+
792
+ This issue occurred in stories file: ${this.filepathURL}
793
+ `;
794
+ }
795
+ }, NoArrayExpressionError = class extends StorybookSvelteCSFError {
796
+ constructor({
797
+ filename,
798
+ property
799
+ }) {
800
+ super({ filename });
801
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseDefineMeta;
802
+ this.code = 4;
803
+ this.documentation = !0;
804
+ this.property = property;
805
+ }
806
+ template() {
807
+ return dedent3`
808
+ The '${this.property.key.name}' passed to 'defineMeta()' must be a static array.
809
+ But it is of type '${this.property.value.type}'.
810
+
811
+ This issue occurred in stories file: ${this.filepathURL}
812
+ `;
813
+ }
814
+ }, ArrayElementNotStringError = class extends StorybookSvelteCSFError {
815
+ constructor({
816
+ filename,
817
+ property,
818
+ element
819
+ }) {
820
+ super({ filename });
821
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseDefineMeta;
822
+ this.code = 5;
823
+ this.documentation = !0;
824
+ this.element = element, this.property = property;
825
+ }
826
+ template() {
827
+ return dedent3`
828
+ All entries in the '${this.property.key.name}' property passed to 'defineMeta()' must be static strings.
829
+ One of the elements is not a string but is instead of type '${this.element?.type}'.
830
+
831
+ This issue occurred in stories file: ${this.filepathURL}
832
+ `;
833
+ }
834
+ }, InvalidRenderValueError = class extends StorybookSvelteCSFError {
835
+ constructor({
836
+ filename,
837
+ renderProperty
838
+ }) {
839
+ super({ filename });
840
+ this.category = StorybookSvelteCSFError.CATEGORY.parserAnalyseDefineMeta;
841
+ this.code = 6;
842
+ this.documentation = !0;
843
+ this.renderProperty = renderProperty;
844
+ }
845
+ template() {
846
+ return dedent3`
847
+ The 'render' property of 'defineMeta' must reference a root-level Svelte snippet.
848
+ The current type of the property is '${this.renderProperty.value.type}'.
849
+
850
+ The issue occurred in Stories file: ${this.filepathURL}
851
+ `;
852
+ }
853
+ };
854
+
855
+ // src/svelte-csf/parser/extract/svelte/story/template.ts
856
+ function extractStoryTemplateSnippetBlock(component) {
857
+ let { fragment } = component, { nodes } = fragment;
858
+ return nodes.find(
859
+ (node) => node.type === "SnippetBlock" && node.expression.name === "template"
860
+ );
861
+ }
862
+
863
+ export {
864
+ SVELTE_CSF_V5_TAG,
865
+ STORYBOOK_INTERNAL_PREFIX,
866
+ STORYBOOK_META_IDENTIFIER,
867
+ RUNTIME_STORIES_IDENTIFIER,
868
+ SVELTE_CSF_RUNTIME_STORIES_IMPORT_SOURCE,
869
+ isOneOf,
870
+ findDefineMetaImport,
871
+ getSvelteAST,
872
+ createASTProperty,
873
+ createASTArrayExpression,
874
+ createASTObjectExpression,
875
+ appendASTProperty,
876
+ createASTIdentifier,
877
+ createASTExportSpecifier,
878
+ extractStoryAttributesNodes,
879
+ StorybookSvelteCSFError,
880
+ isStorybookSvelteCSFError,
881
+ StoryTemplateAndChildrenError,
882
+ StoryTemplateAndAsChildError,
883
+ StoryAsChildWithoutChildrenError,
884
+ getArrayOfStringsValueFromAttribute,
885
+ getStoryIdentifiers,
886
+ getStoriesIdentifiers,
887
+ InvalidComponentValueError,
888
+ NoDestructuredDefineMetaCallError,
889
+ NoStringLiteralError,
890
+ NoArrayExpressionError,
891
+ ArrayElementNotStringError,
892
+ InvalidRenderValueError,
893
+ MissingModuleTagError,
894
+ DefaultOrNamespaceImportUsedError,
895
+ MissingDefineMetaImportError,
896
+ MissingDefineMetaVariableDeclarationError,
897
+ NoStoryComponentDestructuredError,
898
+ GetDefineMetaFirstArgumentError,
899
+ InvalidStoryTemplateAttributeError,
900
+ IndexerParseError,
901
+ extractStoryTemplateSnippetBlock
902
+ };