@storybook/svelte 10.4.0-alpha.9 → 10.4.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.
@@ -0,0 +1,90 @@
1
+ import CJS_COMPAT_NODE_URL_yx1i39d6a5l from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_yx1i39d6a5l from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_yx1i39d6a5l from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_yx1i39d6a5l.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_yx1i39d6a5l.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_yx1i39d6a5l.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+
13
+ // src/parsers/svelteImportParser.ts
14
+ import {
15
+ ChangeDetectionFailureError
16
+ } from "storybook/internal/core-server";
17
+ var svelteCompilerPromise;
18
+ async function getSvelteCompiler() {
19
+ return svelteCompilerPromise || (svelteCompilerPromise = import("svelte/compiler").catch((error) => {
20
+ throw svelteCompilerPromise = void 0, new ChangeDetectionFailureError(
21
+ `Failed to load 'svelte/compiler'; is 'svelte' installed? Original error: ${error instanceof Error ? error.message : String(error)}`,
22
+ error instanceof Error ? { cause: error } : void 0
23
+ );
24
+ })), svelteCompilerPromise;
25
+ }
26
+ function readLangFromAttributes(attributes) {
27
+ if (Array.isArray(attributes)) {
28
+ for (let attr of attributes)
29
+ if (attr.name === "lang") {
30
+ if (attr.value === !0)
31
+ return;
32
+ if (Array.isArray(attr.value) && attr.value.length > 0) {
33
+ let first = attr.value[0];
34
+ if (typeof first?.data == "string")
35
+ return first.data;
36
+ }
37
+ return;
38
+ }
39
+ }
40
+ }
41
+ function extractScriptSource(source, script) {
42
+ let range = script?.content;
43
+ if (!range || typeof range.start != "number" || typeof range.end != "number" || range.start < 0 || range.end > source.length || range.end <= range.start)
44
+ return;
45
+ let lang = readLangFromAttributes(script?.attributes);
46
+ return { scriptSource: source.slice(range.start, range.end), lang };
47
+ }
48
+ function virtualExtensionForLang(lang) {
49
+ switch (lang) {
50
+ case "ts":
51
+ return "ts";
52
+ case "tsx":
53
+ return "tsx";
54
+ case "jsx":
55
+ return "jsx";
56
+ default:
57
+ return "js";
58
+ }
59
+ }
60
+ var svelteImportParser = {
61
+ extensions: [".svelte"],
62
+ async parse({ filePath, source }, ctx) {
63
+ let compiler = await getSvelteCompiler(), ast;
64
+ try {
65
+ ast = compiler.parse(source, { filename: filePath, modern: !0 });
66
+ } catch (error) {
67
+ throw new ChangeDetectionFailureError(
68
+ `svelte/compiler failed to parse ${filePath}: ${error instanceof Error ? error.message : String(error)}`,
69
+ error instanceof Error ? { cause: error } : void 0
70
+ );
71
+ }
72
+ let root = ast ?? {}, scripts = [], moduleResult = extractScriptSource(source, root.module);
73
+ moduleResult !== void 0 && scripts.push(moduleResult);
74
+ let instanceResult = extractScriptSource(source, root.instance);
75
+ if (instanceResult !== void 0 && scripts.push(instanceResult), scripts.length === 0)
76
+ return [];
77
+ let edges = [], seen = /* @__PURE__ */ new Set();
78
+ for (let { scriptSource, lang } of scripts) {
79
+ let ext = virtualExtensionForLang(lang), virtualFilePath = `${filePath}.script.${ext}`, scriptEdges = await ctx.parseScriptWithOxc(scriptSource, virtualFilePath);
80
+ for (let edge of scriptEdges) {
81
+ let key = `${edge.kind}:${edge.specifier}`;
82
+ seen.has(key) || (seen.add(key), edges.push(edge));
83
+ }
84
+ }
85
+ return edges;
86
+ }
87
+ };
88
+ export {
89
+ svelteImportParser
90
+ };
package/dist/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_e4ehjq3le1n from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_e4ehjq3le1n from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_e4ehjq3le1n from "node:module";
1
+ import CJS_COMPAT_NODE_URL_yx1i39d6a5l from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_yx1i39d6a5l from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_yx1i39d6a5l from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_e4ehjq3le1n.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_e4ehjq3le1n.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_e4ehjq3le1n.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_yx1i39d6a5l.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_yx1i39d6a5l.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_yx1i39d6a5l.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -17,7 +17,11 @@ var previewAnnotations = async (input = [], options) => {
17
17
  return [].concat(input).concat([fileURLToPath(import.meta.resolve("@storybook/svelte/entry-preview"))]).concat(
18
18
  docsEnabled ? [fileURLToPath(import.meta.resolve("@storybook/svelte/entry-preview-docs"))] : []
19
19
  );
20
+ }, experimental_importParsers = async (input = []) => {
21
+ let { svelteImportParser } = await import("./_node-chunks/parsers-NO7WF3GP.js");
22
+ return [...input, svelteImportParser];
20
23
  };
21
24
  export {
25
+ experimental_importParsers,
22
26
  previewAnnotations
23
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/svelte",
3
- "version": "10.4.0-alpha.9",
3
+ "version": "10.4.0",
4
4
  "description": "Storybook Svelte renderer: Develop, document, and test UI components in isolation.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -66,7 +66,7 @@
66
66
  "vite": "^7.0.4"
67
67
  },
68
68
  "peerDependencies": {
69
- "storybook": "^10.4.0-alpha.9",
69
+ "storybook": "^10.4.0",
70
70
  "svelte": "^5.0.0"
71
71
  },
72
72
  "publishConfig": {
@@ -1,5 +1,9 @@
1
1
  <script>
2
- import DecoratorHandler from './DecoratorHandler.svelte';
2
+ /*
3
+ ! DO NOT change this DecoratorHandler import to a relative path, it will break it.
4
+ ! See https://github.com/storybookjs/storybook/issues/34304
5
+ */
6
+ import DecoratorHandler from '@storybook/svelte/internal/DecoratorHandler.svelte';
3
7
  import { dedent } from 'ts-dedent';
4
8
 
5
9
  const { name, title, storyFn, showError } = $props();