@storybook-astro/framework 0.1.0-beta.1 → 0.1.0-beta.10
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.
- package/dist/{chunk-LLYYQI75.js → chunk-KTGNRGDJ.js} +20 -14
- package/dist/chunk-KTGNRGDJ.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/middleware.js +84 -0
- package/dist/middleware.js.map +1 -0
- package/dist/preset.js +1 -1
- package/package.json +29 -24
- package/src/middleware.ts +2 -1
- package/src/preset.ts +5 -3
- package/src/viteAstroContainerRenderersPlugin.ts +3 -2
- package/src/vitePluginAstro.ts +3 -2
- package/src/vitePluginAstroBuildPrerender.ts +3 -2
- package/src/viteStorybookAstroMiddlewarePlugin.ts +4 -3
- package/src/viteStorybookRendererFallbackPlugin.ts +2 -1
- package/dist/chunk-LLYYQI75.js.map +0 -1
|
@@ -4,6 +4,7 @@ import { createServer } from "vite";
|
|
|
4
4
|
|
|
5
5
|
// src/viteAstroContainerRenderersPlugin.ts
|
|
6
6
|
function viteAstroContainerRenderersPlugin(integrations) {
|
|
7
|
+
const safeIntegrations = integrations ?? [];
|
|
7
8
|
const name = "astro-container-renderers";
|
|
8
9
|
const virtualModuleId = `virtual:${name}`;
|
|
9
10
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
@@ -16,11 +17,11 @@ function viteAstroContainerRenderersPlugin(integrations) {
|
|
|
16
17
|
},
|
|
17
18
|
load(id) {
|
|
18
19
|
if (id === resolvedVirtualModuleId) {
|
|
19
|
-
const importStatements = buildImportStatements(
|
|
20
|
+
const importStatements = buildImportStatements(safeIntegrations);
|
|
20
21
|
const code = `
|
|
21
22
|
${importStatements}
|
|
22
23
|
export function addRenderers(container) {
|
|
23
|
-
${
|
|
24
|
+
${safeIntegrations.map((integration) => buildServerRenderer(integration) + "\n" + buildClientRenderer(integration)).join("\n")}
|
|
24
25
|
}
|
|
25
26
|
`;
|
|
26
27
|
return code;
|
|
@@ -124,7 +125,7 @@ async function vitePluginStorybookAstroMiddleware(options) {
|
|
|
124
125
|
const middleware = await viteServer.ssrLoadModule(filePath, {
|
|
125
126
|
fixStacktrace: true
|
|
126
127
|
});
|
|
127
|
-
const handler = await middleware.handlerFactory(options.integrations);
|
|
128
|
+
const handler = await middleware.handlerFactory(options.integrations ?? []);
|
|
128
129
|
server.ws.on("astro:render:request", async (data) => {
|
|
129
130
|
try {
|
|
130
131
|
const html = await handler(data);
|
|
@@ -175,12 +176,13 @@ async function vitePluginStorybookAstroMiddleware(options) {
|
|
|
175
176
|
}
|
|
176
177
|
async function createViteServer(integrations) {
|
|
177
178
|
const { getViteConfig } = await import("astro/config");
|
|
179
|
+
const safeIntegrations = integrations ?? [];
|
|
178
180
|
const config = await getViteConfig(
|
|
179
181
|
{},
|
|
180
182
|
{
|
|
181
183
|
configFile: false,
|
|
182
184
|
integrations: await Promise.all(
|
|
183
|
-
|
|
185
|
+
safeIntegrations.map((integration) => integration.loadIntegration())
|
|
184
186
|
)
|
|
185
187
|
}
|
|
186
188
|
)({ mode: "development", command: "serve" });
|
|
@@ -189,7 +191,7 @@ async function createViteServer(integrations) {
|
|
|
189
191
|
...config,
|
|
190
192
|
plugins: [
|
|
191
193
|
...config.plugins?.filter(Boolean) ?? [],
|
|
192
|
-
viteAstroContainerRenderersPlugin(
|
|
194
|
+
viteAstroContainerRenderersPlugin(safeIntegrations),
|
|
193
195
|
vitePluginAstroFontsFallback()
|
|
194
196
|
]
|
|
195
197
|
});
|
|
@@ -199,6 +201,7 @@ async function createViteServer(integrations) {
|
|
|
199
201
|
|
|
200
202
|
// src/viteStorybookRendererFallbackPlugin.ts
|
|
201
203
|
function viteStorybookRendererFallbackPlugin(integrations) {
|
|
204
|
+
const safeIntegrations = integrations ?? [];
|
|
202
205
|
const name = "storybook-renderer-fallback";
|
|
203
206
|
const virtualModuleId = `virtual:${name}`;
|
|
204
207
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
@@ -211,7 +214,7 @@ function viteStorybookRendererFallbackPlugin(integrations) {
|
|
|
211
214
|
},
|
|
212
215
|
load(id) {
|
|
213
216
|
if (id === resolvedVirtualModuleId) {
|
|
214
|
-
return
|
|
217
|
+
return safeIntegrations.filter((integration) => integration.storybookEntryPreview).map(
|
|
215
218
|
(integration) => `export * as ${integration.name} from '${integration.storybookEntryPreview}';`
|
|
216
219
|
).join("\n");
|
|
217
220
|
}
|
|
@@ -309,6 +312,7 @@ import { readFileSync as readFileSync2 } from "fs";
|
|
|
309
312
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
310
313
|
import { basename } from "path";
|
|
311
314
|
function vitePluginAstroBuildPrerender(integrations) {
|
|
315
|
+
const safeIntegrations = integrations ?? [];
|
|
312
316
|
let viteServer = null;
|
|
313
317
|
let handler = null;
|
|
314
318
|
const assetRefIds = /* @__PURE__ */ new Map();
|
|
@@ -318,12 +322,12 @@ function vitePluginAstroBuildPrerender(integrations) {
|
|
|
318
322
|
enforce: "post",
|
|
319
323
|
async buildStart() {
|
|
320
324
|
try {
|
|
321
|
-
viteServer = await createViteServer(
|
|
325
|
+
viteServer = await createViteServer(safeIntegrations);
|
|
322
326
|
const filePath = fileURLToPath2(new URL("./middleware", import.meta.url));
|
|
323
327
|
const middleware = await viteServer.ssrLoadModule(filePath, {
|
|
324
328
|
fixStacktrace: true
|
|
325
329
|
});
|
|
326
|
-
handler = await middleware.handlerFactory(
|
|
330
|
+
handler = await middleware.handlerFactory(safeIntegrations);
|
|
327
331
|
} catch (err) {
|
|
328
332
|
console.warn(
|
|
329
333
|
"[storybook-astro] Failed to create pre-render server:",
|
|
@@ -488,14 +492,15 @@ var ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK = [
|
|
|
488
492
|
"astro:vite-plugin-env",
|
|
489
493
|
"astro:vite-plugin-file-url"
|
|
490
494
|
];
|
|
491
|
-
async function mergeWithAstroConfig(config, integrations) {
|
|
495
|
+
async function mergeWithAstroConfig(config, integrations = []) {
|
|
492
496
|
const { getViteConfig } = await import("astro/config");
|
|
497
|
+
const safeIntegrations = integrations ?? [];
|
|
493
498
|
const astroConfig = await getViteConfig(
|
|
494
499
|
{},
|
|
495
500
|
{
|
|
496
501
|
configFile: false,
|
|
497
502
|
integrations: await Promise.all(
|
|
498
|
-
|
|
503
|
+
safeIntegrations.map((integration) => integration.loadIntegration())
|
|
499
504
|
)
|
|
500
505
|
}
|
|
501
506
|
)({
|
|
@@ -522,13 +527,14 @@ var viteFinal = async (config, { presets }) => {
|
|
|
522
527
|
if (!config.plugins) {
|
|
523
528
|
config.plugins = [];
|
|
524
529
|
}
|
|
530
|
+
const integrations = options.integrations ?? [];
|
|
525
531
|
config.plugins.push(
|
|
526
532
|
storybookAstroMiddlewarePlugin,
|
|
527
|
-
viteStorybookRendererFallbackPlugin(
|
|
533
|
+
viteStorybookRendererFallbackPlugin(integrations),
|
|
528
534
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
529
535
|
vitePluginAstroComponentMarker(),
|
|
530
536
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
531
|
-
vitePluginAstroBuildPrerender(
|
|
537
|
+
vitePluginAstroBuildPrerender(integrations),
|
|
532
538
|
...viteConfig.plugins
|
|
533
539
|
);
|
|
534
540
|
if (!config.resolve) {
|
|
@@ -544,7 +550,7 @@ var viteFinal = async (config, { presets }) => {
|
|
|
544
550
|
if (!aliases["react-dom"]) {
|
|
545
551
|
aliases["react-dom"] = "react-dom";
|
|
546
552
|
}
|
|
547
|
-
const finalConfig = await mergeWithAstroConfig(config,
|
|
553
|
+
const finalConfig = await mergeWithAstroConfig(config, integrations);
|
|
548
554
|
return finalConfig;
|
|
549
555
|
};
|
|
550
556
|
|
|
@@ -552,4 +558,4 @@ export {
|
|
|
552
558
|
core,
|
|
553
559
|
viteFinal
|
|
554
560
|
};
|
|
555
|
-
//# sourceMappingURL=chunk-
|
|
561
|
+
//# sourceMappingURL=chunk-KTGNRGDJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/viteStorybookAstroMiddlewarePlugin.ts","../src/viteAstroContainerRenderersPlugin.ts","../src/vitePluginAstroFontsFallback.ts","../src/viteStorybookRendererFallbackPlugin.ts","../src/vitePluginAstroComponentMarker.ts","../src/vitePluginAstroBuildPrerender.ts","../src/vitePluginAstro.ts","../src/preset.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport { createServer, type PluginOption, type ViteDevServer } from 'vite';\nimport type { RenderRequestMessage, RenderResponseMessage } from '@storybook-astro/renderer/types';\nimport type { FrameworkOptions } from './types.ts';\nimport type { Integration } from './integrations/index.ts';\nimport { viteAstroContainerRenderersPlugin } from './viteAstroContainerRenderersPlugin.ts';\nimport { vitePluginAstroFontsFallback } from './vitePluginAstroFontsFallback.ts';\n\nexport async function vitePluginStorybookAstroMiddleware(options: FrameworkOptions) {\n // The internal Vite server is created lazily inside configureServer (dev-only).\n // During builds, configureServer never fires, so no server is created.\n let viteServer: ViteDevServer | null = null;\n\n const vitePlugin = {\n name: 'storybook-astro-middleware-plugin',\n async configureServer(server) {\n viteServer = await createViteServer(options.integrations);\n\n const filePath = fileURLToPath(new URL('./middleware', import.meta.url));\n const middleware = await viteServer.ssrLoadModule(filePath, {\n fixStacktrace: true\n });\n const handler = await middleware.handlerFactory(options.integrations ?? []);\n\n server.ws.on('astro:render:request', async (data: RenderRequestMessage['data']) => {\n try {\n const html = await handler(data);\n\n server.ws.send('astro:render:response', {\n html,\n id: data.id\n } satisfies RenderResponseMessage['data']);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n const errorStack = err instanceof Error ? err.stack : '';\n\n console.error('[storybook-astro] Render error:', errorMessage);\n if (errorStack) {console.error(errorStack);}\n server.ws.send('astro:render:response', {\n id: data.id,\n html:\n '<div style=\"background: #d73838; padding: 12px; color: #f0f0f0; font-family: monospace; border-radius: 4px\">' +\n '<strong>Error rendering Astro component</strong><br/>' +\n '<pre style=\"white-space: pre-wrap; margin-top: 8px; font-size: 12px\">' +\n errorMessage.replace(/</g, '<').replace(/>/g, '>') +\n '</pre></div>'\n } satisfies RenderResponseMessage['data']);\n }\n });\n }\n } satisfies PluginOption;\n\n // Create asset serving plugin (only active in dev when viteServer exists)\n const assetServingPlugin = {\n name: 'storybook-astro-assets',\n configureServer(server) {\n server.middlewares.use('/_image', (req, res, next) => {\n if (!viteServer) {\n next();\n \nreturn;\n }\n // Forward the request to the Astro vite server\n viteServer.middlewares.handle(req, res, (err) => {\n if (err) {\n console.error('Asset serving error:', err);\n next();\n }\n });\n });\n }\n };\n\n // The extracted CSS plugins from Astro's internal Vite server cause Vue SFC\n // <style> blocks to be double-processed (once by these plugins, once by\n // Storybook's built-in CSS plugins), resulting in PostCSS errors.\n // \n // Solution: Don't extract Astro's CSS plugins. Storybook's built-in CSS\n // plugins handle both Vue styles AND Astro style sub-modules (which are\n // standard CSS imports like `Component.astro?astro&type=style&index=0&lang.css`).\n // \n // The Astro internal server's CSS plugins are only needed for SSR rendering\n // within that server - they don't need to be shared with Storybook's server.\n return {\n vitePlugin,\n viteConfig: {\n plugins: [\n assetServingPlugin\n ].filter(Boolean)\n }\n };\n}\n\nexport async function createViteServer(integrations: Integration[]) {\n const { getViteConfig } = await import('astro/config');\n const safeIntegrations = integrations ?? [];\n\n const config = await getViteConfig(\n {},\n {\n configFile: false,\n integrations: await Promise.all(\n safeIntegrations.map((integration) => integration.loadIntegration())\n )\n }\n )({ mode: 'development', command: 'serve' });\n\n const viteServer = await createServer({\n configFile: false,\n ...config,\n plugins: [\n ...(config.plugins?.filter(Boolean) ?? []),\n viteAstroContainerRenderersPlugin(safeIntegrations),\n vitePluginAstroFontsFallback()\n ]\n });\n\n // Initialize the server's plugin container to ensure all plugins are ready.\n // Without this, some plugins (like vite:css) may have uninitialized state\n // when ssrLoadModule is called.\n await viteServer.pluginContainer.buildStart({});\n\n return viteServer;\n}\n","import type { Integration } from './integrations/index.ts';\n\nexport function viteAstroContainerRenderersPlugin(integrations: Integration[]) {\n const safeIntegrations = integrations ?? [];\n const name = 'astro-container-renderers';\n const virtualModuleId = `virtual:${name}`;\n const resolvedVirtualModuleId = `\\0${virtualModuleId}`;\n\n return {\n name,\n\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId;\n }\n },\n\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n const importStatements = buildImportStatements(safeIntegrations);\n\n const code = `\n ${importStatements}\n export function addRenderers(container) {\n ${safeIntegrations.map((integration) => buildServerRenderer(integration) + '\\n' + buildClientRenderer(integration)).join('\\n')}\n }\n `;\n\n return code;\n }\n }\n };\n}\n\nfunction buildImportStatements(integrations: Integration[]) {\n return integrations\n .filter((integration) => integration.renderer.server)\n .map(\n (integration) =>\n `import ${integration.name}Renderer from '${integration.renderer.server?.entrypoint}';`\n )\n .join('\\n');\n}\n\nfunction buildServerRenderer(integration: Integration) {\n const serverRenderer = integration.renderer.server;\n\n if (!serverRenderer) {\n return '';\n }\n\n if (integration.name === 'solid') {\n return `\n container.addServerRenderer({\n name: '${serverRenderer.name}',\n renderer: {\n ...${integration.name}Renderer,\n name: '${serverRenderer.name}'\n }\n });\n `;\n }\n\n return `\n container.addServerRenderer({\n name: '${serverRenderer.name}',\n renderer: ${integration.name}Renderer\n });\n `;\n}\n\nfunction buildClientRenderer(integration: Integration) {\n const clientRenderer = integration.renderer.client;\n\n if (clientRenderer) {\n return `\n container.addClientRenderer({\n name: '${clientRenderer.name}',\n entrypoint: '${clientRenderer.entrypoint}'\n });\n `;\n }\n\n return '';\n}\n","import type { Plugin } from 'vite';\n\nconst FONTS_RUNTIME_STUB = `\nexport const fontData = {};\nexport function createGetFontData(fontsMod) {\n return fontsMod?.fontDataByCssVariable ?? {};\n}\n`;\n\nconst FONTS_INTERNAL_STUB = `\nexport const componentDataByCssVariable = new Map();\nexport const fontDataByCssVariable = {};\n`;\n\n/**\n * Provides fallback resolution for Astro's font-related virtual modules\n * and package import paths in Storybook's SSR Vite server.\n *\n * In Astro 6, the `astro:assets` virtual module depends on font-related\n * modules through virtual modules and a bare `astro/assets/fonts/runtime`\n * import. In the Storybook SSR context:\n *\n * 1. The fonts plugin's filter-based `resolveId` may not trigger for\n * the virtual module IDs.\n * 2. A Vite transform rewrites the `astro:assets` module to import\n * `createGetFontData` from `astro/assets/fonts/runtime` (without\n * `.js`), which fails against Astro's package.json exports map.\n * 3. The `createGetFontData` function is injected by a runtime Vite\n * transform that doesn't run in our SSR context.\n *\n * This plugin stubs all three font module paths with no-op exports,\n * since Storybook doesn't need Astro's font system.\n */\nexport function vitePluginAstroFontsFallback(): Plugin {\n const VIRTUAL_ID = 'virtual:astro:assets/fonts/internal';\n const RUNTIME_VIRTUAL_ID = 'virtual:astro:assets/fonts/runtime';\n const RESOLVED_VIRTUAL_ID = '\\0' + VIRTUAL_ID;\n const RESOLVED_RUNTIME_VIRTUAL_ID = '\\0' + RUNTIME_VIRTUAL_ID;\n const RESOLVED_FONTS_RUNTIME_ID = '\\0storybook:astro-fonts-runtime';\n\n return {\n name: 'storybook-astro-fonts-fallback',\n // Must run before vite:resolve to intercept virtual modules\n // before Vite tries to resolve them as Node package imports\n enforce: 'pre',\n\n resolveId(id) {\n if (id === VIRTUAL_ID) {\n return RESOLVED_VIRTUAL_ID;\n }\n if (id === RUNTIME_VIRTUAL_ID) {\n return RESOLVED_RUNTIME_VIRTUAL_ID;\n }\n // Intercept the bare package import (without .js) and the .js variant\n if (id === 'astro/assets/fonts/runtime' || id === 'astro/assets/fonts/runtime.js') {\n return RESOLVED_FONTS_RUNTIME_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return { code: FONTS_INTERNAL_STUB };\n }\n if (id === RESOLVED_RUNTIME_VIRTUAL_ID || id === RESOLVED_FONTS_RUNTIME_ID) {\n return { code: FONTS_RUNTIME_STUB };\n }\n }\n };\n}\n","import type { Integration } from './integrations/index.ts';\n\nexport function viteStorybookRendererFallbackPlugin(integrations: Integration[]) {\n const safeIntegrations = integrations ?? [];\n const name = 'storybook-renderer-fallback';\n const virtualModuleId = `virtual:${name}`;\n const resolvedVirtualModuleId = `\\0${virtualModuleId}`;\n\n return {\n name,\n\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId;\n }\n },\n\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n return safeIntegrations\n .filter((integration) => integration.storybookEntryPreview)\n .map(\n (integration) =>\n `export * as ${integration.name} from '${integration.storybookEntryPreview}';`\n )\n .join('\\n');\n }\n }\n };\n}\n","import { readFileSync } from 'node:fs';\nimport type { PluginOption } from 'vite';\n\n/**\n * Vite plugin that patches Astro 6's client-side .astro file transforms for Storybook.\n *\n * In Astro 6, the client-side transform of .astro files produces a stub function that\n * throws \"Astro components cannot be used in the browser\" without setting the\n * `isAstroComponentFactory` marker. Storybook's renderer relies on this marker to detect\n * Astro components and route them to server-side rendering via the Container API.\n *\n * This plugin also preserves the component's scoped CSS by importing the style sub-modules\n * that the Astro Vite plugin exposes. Without this, the client-side stub would strip all\n * CSS since Astro 6 no longer includes style imports in client-side .astro transforms.\n *\n * During builds, Astro's compile metadata cache is not populated for client-side transforms,\n * so style sub-module imports would fail. Instead, raw CSS is extracted directly from the\n * .astro source and inlined.\n */\nexport function vitePluginAstroComponentMarker(): PluginOption {\n let isBuild = false;\n\n return {\n name: 'storybook-astro-component-marker',\n enforce: 'post',\n\n configResolved(config) {\n isBuild = config.command === 'build';\n },\n\n transform(code: string, id: string) {\n // Only process main .astro modules (not sub-modules like ?astro&type=style)\n if (!id.endsWith('.astro')) {return null;}\n\n // Detect the Astro 6 client-side stub pattern\n if (!code.includes('Astro components cannot be used in the browser')) {return null;}\n\n const moduleId = id;\n\n // In dev mode, import style sub-modules via Astro's Vite plugin (which has\n // compile metadata cached from the SSR transform).\n // In build mode, Astro's compile metadata cache is not populated for client-side\n // transforms, so sub-module imports would fail. Extract raw CSS instead.\n const styleCode = isBuild\n ? generateInlineStyles(moduleId)\n : generateStyleImports(moduleId);\n\n return {\n code: `\n${styleCode}\nconst __astro_component = () => {\n throw new Error('Astro components are rendered server-side by Storybook.');\n};\n__astro_component.isAstroComponentFactory = true;\n__astro_component.moduleId = ${JSON.stringify(moduleId)};\nexport default __astro_component;\n`,\n map: null,\n };\n },\n };\n}\n\n/**\n * Reads the original .astro source file and generates import statements\n * for each <style> block, using the Astro Vite plugin's sub-module convention.\n */\nfunction generateStyleImports(filePath: string): string {\n try {\n const source = readFileSync(filePath, 'utf-8');\n const styleCount = countStyleBlocks(source);\n\n return Array.from({ length: styleCount }, (_, i) =>\n `import ${JSON.stringify(`${filePath}?astro&type=style&index=${i}&lang.css`)};`\n ).join('\\n');\n } catch {\n return '';\n }\n}\n\n/**\n * Reads the original .astro source file and generates a JS snippet that injects\n * the raw CSS from each <style> block into the document. Used during builds where\n * Astro's compile metadata cache is unavailable.\n *\n * The CSS is unscoped (no Astro scoping transforms), which is acceptable because\n * Astro components show a fallback message in static builds.\n */\nfunction generateInlineStyles(filePath: string): string {\n try {\n const source = readFileSync(filePath, 'utf-8');\n const cssBlocks = extractStyleBlocks(source);\n\n if (cssBlocks.length === 0) {return '';}\n\n // Create a side-effect that injects styles into the document\n return cssBlocks.map((css, i) => {\n const escaped = JSON.stringify(css);\n\n \nreturn `\n(function() {\n if (typeof document !== 'undefined') {\n const style = document.createElement('style');\n style.setAttribute('data-astro-build', ${JSON.stringify(filePath + ':' + i)});\n style.textContent = ${escaped};\n document.head.appendChild(style);\n }\n})();`;\n }).join('\\n');\n } catch {\n return '';\n }\n}\n\n/**\n * Extracts the content of all top-level <style> blocks from an Astro component's source.\n * Strips frontmatter before parsing.\n */\nfunction extractStyleBlocks(source: string): string[] {\n const withoutFrontmatter = source.replace(/^---[\\s\\S]*?---/m, '');\n const blocks: string[] = [];\n const regex = /<style(?:\\s[^>]*)?>([\\s\\S]*?)<\\/style>/g;\n let match;\n\n while ((match = regex.exec(withoutFrontmatter)) !== null) {\n blocks.push(match[1].trim());\n }\n\n return blocks;\n}\n\n/**\n * Counts the number of top-level <style> blocks in an Astro component's source.\n * Only counts opening tags that are NOT inside the frontmatter fence (---).\n */\nfunction countStyleBlocks(source: string): number {\n // Strip frontmatter\n const withoutFrontmatter = source.replace(/^---[\\s\\S]*?---/m, '');\n // Match <style> opening tags (with optional attributes)\n const matches = withoutFrontmatter.match(/<style(\\s|>)/g);\n\n \nreturn matches ? matches.length : 0;\n}\n","import { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { basename } from 'node:path';\nimport type { Plugin, ViteDevServer } from 'vite';\nimport type { Integration } from './integrations/index.ts';\nimport type { HandlerProps } from './middleware.ts';\nimport { createViteServer } from './viteStorybookAstroMiddlewarePlugin.ts';\n\n/**\n * Vite plugin that pre-renders Astro component stories at build time.\n *\n * During `storybook build`, this plugin:\n * 1. Creates an internal Vite SSR server with AstroContainer\n * 2. Detects story files that import Astro components\n * 3. Loads each story module via ssrLoadModule to get fully evaluated args\n * (including imported assets, computed values, etc.)\n * 4. Renders each story variant using AstroContainer\n * 5. Injects the pre-rendered HTML as a story parameter (`__astroPrerendered`)\n *\n * The renderer checks for this parameter in static builds and uses the\n * pre-rendered HTML directly instead of showing a fallback message.\n *\n * Limitations:\n * - Controls panel changes won't update Astro components (HTML is static)\n * - Build time increases with the number of Astro stories\n * - Stories that override the meta component are skipped\n */\nexport function vitePluginAstroBuildPrerender(integrations: Integration[]): Plugin {\n const safeIntegrations = integrations ?? [];\n let viteServer: ViteDevServer | null = null;\n let handler: ((data: HandlerProps) => Promise<string>) | null = null;\n\n // Maps placeholder strings to Rollup emitted-file reference IDs.\n // Placeholders are injected into pre-rendered HTML during transform,\n // then resolved to final asset paths in renderChunk.\n const assetRefIds = new Map<string, string>();\n\n return {\n name: 'storybook-astro-build-prerender',\n apply: 'build',\n enforce: 'post',\n\n async buildStart() {\n try {\n viteServer = await createViteServer(safeIntegrations);\n\n const filePath = fileURLToPath(new URL('./middleware', import.meta.url));\n const middleware = await viteServer.ssrLoadModule(filePath, {\n fixStacktrace: true\n });\n\n handler = await middleware.handlerFactory(safeIntegrations);\n } catch (err) {\n console.warn(\n '[storybook-astro] Failed to create pre-render server:',\n err instanceof Error ? err.message : err\n );\n }\n },\n\n async transform(code, id) {\n if (!handler || !viteServer) {return null;}\n\n // Only process story files\n if (!/\\.stories\\.(jsx?|tsx?|mjs)$/.test(id)) {return null;}\n\n // Parse AST to find .astro imports\n const ast = this.parse(code);\n const astroImport = findFirstAstroImport(ast);\n\n if (!astroImport) {return null;}\n\n // Resolve the .astro import to an absolute path\n const resolved = await this.resolve(astroImport.source, id);\n\n if (!resolved) {return null;}\n const componentPath = resolved.id;\n\n // Load the story module via SSR to get fully evaluated args\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let storyModule: Record<string, any>;\n\n try {\n storyModule = await viteServer.ssrLoadModule(id);\n } catch (err) {\n console.warn(\n `[storybook-astro] Failed to load story for pre-render: ${id}`,\n err instanceof Error ? err.message : err\n );\n \nreturn null;\n }\n\n const meta = storyModule.default || {};\n\n // Confirm the meta component is an Astro component\n if (!meta.component?.isAstroComponentFactory) {return null;}\n\n // Find all named exports that are story objects\n const storyNames = Object.keys(storyModule).filter(\n (k) =>\n k !== 'default' &&\n k !== '__esModule' &&\n typeof storyModule[k] === 'object' &&\n storyModule[k] !== null\n );\n\n if (storyNames.length === 0) {return null;}\n\n // Pre-render each story\n const prerendered: Record<string, string> = {};\n\n for (const name of storyNames) {\n const story = storyModule[name];\n\n // Skip stories that override the component — the resolved path\n // corresponds to the meta component and may not match\n if (story.component && story.component !== meta.component) {continue;}\n\n // Merge meta args with story args (story args take precedence)\n const mergedArgs = { ...meta.args, ...story.args };\n const { slots = {}, ...componentArgs } = mergedArgs;\n\n try {\n const html = await handler({\n component: componentPath,\n args: componentArgs,\n slots: (slots ?? {}) as Record<string, unknown>\n });\n // Rewrite /@fs dev-server URLs to Rollup asset placeholders.\n // The actual files are emitted via this.emitFile and the\n // placeholders are resolved to final paths in renderChunk.\n\n prerendered[name] = emitAndRewriteAssetUrls(html, this, assetRefIds);\n } catch (err) {\n console.warn(\n `[storybook-astro] Pre-render failed for \"${name}\" in ${id}:`,\n err instanceof Error ? err.message : err\n );\n }\n }\n\n if (Object.keys(prerendered).length === 0) {return null;}\n\n // Append code that injects pre-rendered HTML as story parameters.\n // This runs as module-level side effects during import, before\n // Storybook reads the story exports.\n const injections = Object.entries(prerendered).map(\n ([name, html]) =>\n `if (typeof ${name} !== 'undefined' && ${name} && typeof ${name} === 'object') {\\n` +\n ` ${name}.parameters = Object.assign({}, ${name}.parameters, ` +\n `{ __astroPrerendered: ${JSON.stringify(html)} });\\n` +\n `}`\n );\n\n return {\n code:\n code +\n '\\n// Pre-rendered by storybook-astro-build-prerender\\n' +\n injections.join('\\n'),\n map: null\n };\n },\n\n renderChunk(code) {\n if (assetRefIds.size === 0) {return null;}\n\n let result = code;\n let modified = false;\n\n for (const [placeholder, refId] of assetRefIds) {\n if (!result.includes(placeholder)) {continue;}\n const fileName = this.getFileName(refId);\n\n result = result.replaceAll(placeholder, fileName);\n modified = true;\n }\n\n return modified ? { code: result, map: null } : null;\n },\n\n async buildEnd() {\n if (viteServer) {\n await viteServer.close();\n viteServer = null;\n handler = null;\n }\n }\n };\n}\n\n/**\n * Finds the first import declaration with a .astro source in the ESTree AST.\n */\nfunction findFirstAstroImport(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ast: any\n): { local: string; source: string } | null {\n for (const node of ast.body) {\n if (\n node.type === 'ImportDeclaration' &&\n typeof node.source.value === 'string' &&\n node.source.value.endsWith('.astro')\n ) {\n const defaultSpecifier = node.specifiers?.find(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (s: any) => s.type === 'ImportDefaultSpecifier'\n );\n\n if (defaultSpecifier) {\n return {\n local: defaultSpecifier.local.name,\n source: node.source.value\n };\n }\n }\n }\n \nreturn null;\n}\n\n/**\n * Finds /@fs dev-server URLs in pre-rendered HTML, emits the referenced\n * files as Rollup assets, and replaces the URLs with placeholders that\n * are resolved to final paths in renderChunk.\n */\nfunction emitAndRewriteAssetUrls(\n html: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ctx: any,\n refIds: Map<string, string>\n): string {\n // Match /@fs URLs in HTML attribute values.\n // The URL may have a query string with HTML-encoded & (&).\n // Note: file paths may contain spaces, so we match until the closing quote.\n return html.replace(/\\/@fs([^\"'>]+)/g, (fullMatch, rawPath: string) => {\n // Strip query string (may contain & or &)\n const pathOnly = rawPath.split('?')[0];\n\n try {\n const source = readFileSync(pathOnly);\n const name = basename(pathOnly);\n const refId = ctx.emitFile({ type: 'asset', name, source });\n const placeholder = `__ASTRO_PRERENDER_ASSET_${refId}__`;\n\n refIds.set(placeholder, refId);\n \nreturn placeholder;\n } catch {\n return fullMatch;\n }\n });\n}\n","import { mergeConfig, type InlineConfig } from 'vite';\nimport type { Integration } from './integrations/index.ts';\n\nconst ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK = [\n '@astro/plugin-actions',\n '@astrojs/vite-plugin-astro-ssr-manifest',\n 'astro-content-virtual-mod-plugin',\n 'astro:actions',\n 'astro:build:normal',\n 'astro:container',\n 'astro:content-asset-propagation',\n 'astro:content-imports',\n 'astro:content-listen',\n 'astro:dev-toolbar',\n 'astro:head-metadata',\n 'astro:html',\n 'astro:i18n',\n 'astro:integration-container',\n 'astro:jsx',\n 'astro:markdown',\n 'astro:postprocess',\n 'astro:prefetch',\n 'astro:scanner',\n 'astro:scripts:page-ssr',\n 'astro:server',\n 'astro:vite-plugin-env',\n 'astro:vite-plugin-file-url'\n];\n\nexport async function mergeWithAstroConfig(config: InlineConfig, integrations: Integration[] = []) {\n const { getViteConfig } = await import('astro/config');\n const safeIntegrations = integrations ?? [];\n\n const astroConfig = await getViteConfig(\n {},\n {\n configFile: false,\n integrations: await Promise.all(\n safeIntegrations.map((integration) => integration.loadIntegration())\n )\n }\n )({\n mode: 'development',\n command: 'serve'\n });\n\n const filteredPlugins = astroConfig\n .plugins!.flat()\n .filter(\n (plugin) =>\n plugin &&\n 'name' in plugin &&\n !ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK.includes(plugin.name)\n );\n\n return mergeConfig(config, {\n ...astroConfig,\n plugins: filteredPlugins\n });\n}\n","import type { StorybookConfigVite, FrameworkOptions } from './types.ts';\nimport { vitePluginStorybookAstroMiddleware } from './viteStorybookAstroMiddlewarePlugin.ts';\nimport { viteStorybookRendererFallbackPlugin } from './viteStorybookRendererFallbackPlugin.ts';\nimport { vitePluginAstroComponentMarker } from './vitePluginAstroComponentMarker.ts';\nimport { vitePluginAstroBuildPrerender } from './vitePluginAstroBuildPrerender.ts';\nimport { mergeWithAstroConfig } from './vitePluginAstro.ts';\n\nexport const core = {\n builder: '@storybook/builder-vite',\n renderer: '@storybook-astro/renderer'\n};\n\nexport const viteFinal: StorybookConfigVite['viteFinal'] = async (config, { presets }) => {\n const options = await presets.apply<FrameworkOptions>('frameworkOptions');\n const { vitePlugin: storybookAstroMiddlewarePlugin, viteConfig } =\n await vitePluginStorybookAstroMiddleware(options);\n\n if (!config.plugins) {\n config.plugins = [];\n }\n\n const integrations = options.integrations ?? [];\n\n config.plugins.push(\n storybookAstroMiddlewarePlugin,\n viteStorybookRendererFallbackPlugin(integrations),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n vitePluginAstroComponentMarker() as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n vitePluginAstroBuildPrerender(integrations) as any,\n ...viteConfig.plugins\n );\n\n // Add React/ReactDOM aliases for storybook-solidjs compatibility\n if (!config.resolve) {\n config.resolve = {};\n }\n if (!config.resolve.alias) {\n config.resolve.alias = {};\n }\n \n // Ensure React is available for storybook-solidjs\n const aliases = config.resolve.alias as Record<string, string>;\n\n if (!aliases['react']) {\n aliases['react'] = 'react';\n }\n if (!aliases['react-dom']) {\n aliases['react-dom'] = 'react-dom';\n }\n\n const finalConfig = await mergeWithAstroConfig(config, integrations);\n\n return finalConfig;\n};\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,oBAA2D;;;ACC7D,SAAS,kCAAkC,cAA6B;AAC7E,QAAM,mBAAmB,gBAAgB,CAAC;AAC1C,QAAM,OAAO;AACb,QAAM,kBAAkB,WAAW,IAAI;AACvC,QAAM,0BAA0B,KAAK,eAAe;AAEpD,SAAO;AAAA,IACL;AAAA,IAEA,UAAU,IAAY;AACpB,UAAI,OAAO,iBAAiB;AAC1B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAY;AACf,UAAI,OAAO,yBAAyB;AAClC,cAAM,mBAAmB,sBAAsB,gBAAgB;AAE/D,cAAM,OAAO;AAAA,YACT,gBAAgB;AAAA;AAAA,cAEd,iBAAiB,IAAI,CAAC,gBAAgB,oBAAoB,WAAW,IAAI,OAAO,oBAAoB,WAAW,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA;AAAA;AAIlI,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,sBAAsB,cAA6B;AAC1D,SAAO,aACJ,OAAO,CAAC,gBAAgB,YAAY,SAAS,MAAM,EACnD;AAAA,IACC,CAAC,gBACC,UAAU,YAAY,IAAI,kBAAkB,YAAY,SAAS,QAAQ,UAAU;AAAA,EACvF,EACC,KAAK,IAAI;AACd;AAEA,SAAS,oBAAoB,aAA0B;AACrD,QAAM,iBAAiB,YAAY,SAAS;AAE5C,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,SAAS,SAAS;AAChC,WAAO;AAAA;AAAA,iBAEM,eAAe,IAAI;AAAA;AAAA,eAErB,YAAY,IAAI;AAAA,mBACZ,eAAe,IAAI;AAAA;AAAA;AAAA;AAAA,EAIpC;AAEA,SAAO;AAAA;AAAA,eAEM,eAAe,IAAI;AAAA,kBAChB,YAAY,IA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
+
|
|
3
|
+
// src/middleware.ts
|
|
4
|
+
import { experimental_AstroContainer as AstroContainer } from "astro/container";
|
|
5
|
+
import { addRenderers } from "virtual:astro-container-renderers";
|
|
6
|
+
async function handlerFactory(integrations) {
|
|
7
|
+
const safeIntegrations = integrations ?? [];
|
|
8
|
+
const container = await AstroContainer.create({
|
|
9
|
+
// Somewhat hacky way to force client-side Storybook's Vite to resolve modules properly
|
|
10
|
+
resolve: async (s) => {
|
|
11
|
+
if (s.startsWith("astro:scripts")) {
|
|
12
|
+
return `/@id/${s}`;
|
|
13
|
+
}
|
|
14
|
+
for (const integration of safeIntegrations) {
|
|
15
|
+
const resolution = integration.resolveClient(s);
|
|
16
|
+
if (resolution) {
|
|
17
|
+
return resolution;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return s;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
addRenderers(container);
|
|
24
|
+
return async function handler(data) {
|
|
25
|
+
const { default: Component } = await import(
|
|
26
|
+
/* @vite-ignore */
|
|
27
|
+
data.component
|
|
28
|
+
);
|
|
29
|
+
const processedArgs = await processImageMetadata(data.args || {});
|
|
30
|
+
const patchedComponent = patchCreateAstroCompat(Component);
|
|
31
|
+
const result = await container.renderToString(patchedComponent, {
|
|
32
|
+
props: processedArgs,
|
|
33
|
+
slots: data.slots ?? {}
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function patchCreateAstroCompat(Component) {
|
|
39
|
+
const wrapped = (result, props, slots) => {
|
|
40
|
+
if (result && result.createAstro) {
|
|
41
|
+
const origCreateAstro = result.createAstro;
|
|
42
|
+
result.createAstro = (...args) => {
|
|
43
|
+
if (args.length === 3) {
|
|
44
|
+
return origCreateAstro(args[1], args[2]);
|
|
45
|
+
}
|
|
46
|
+
return origCreateAstro(...args);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return Component(result, props, slots);
|
|
50
|
+
};
|
|
51
|
+
wrapped.isAstroComponentFactory = Component.isAstroComponentFactory;
|
|
52
|
+
wrapped.moduleId = Component.moduleId;
|
|
53
|
+
wrapped.propagation = Component.propagation;
|
|
54
|
+
return wrapped;
|
|
55
|
+
}
|
|
56
|
+
async function processImageMetadata(args) {
|
|
57
|
+
const processed = {};
|
|
58
|
+
for (const [key, value] of Object.entries(args)) {
|
|
59
|
+
if (isImageMetadata(value)) {
|
|
60
|
+
processed[key] = convertImageMetadataToUrl(value);
|
|
61
|
+
} else if (Array.isArray(value)) {
|
|
62
|
+
processed[key] = await Promise.all(
|
|
63
|
+
value.map(
|
|
64
|
+
async (item) => typeof item === "object" && item !== null ? await processImageMetadata(item) : item
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
} else if (typeof value === "object" && value !== null) {
|
|
68
|
+
processed[key] = await processImageMetadata(value);
|
|
69
|
+
} else {
|
|
70
|
+
processed[key] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return processed;
|
|
74
|
+
}
|
|
75
|
+
function isImageMetadata(value) {
|
|
76
|
+
return typeof value === "object" && value !== null && "src" in value && typeof value.src === "string" && ("width" in value || "height" in value || "format" in value);
|
|
77
|
+
}
|
|
78
|
+
function convertImageMetadataToUrl(imageMetadata) {
|
|
79
|
+
return imageMetadata.src || imageMetadata.fsPath || String(imageMetadata);
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
handlerFactory
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["import { experimental_AstroContainer as AstroContainer } from 'astro/container';\nimport type { Integration } from './integrations/index.ts';\nimport { addRenderers } from 'virtual:astro-container-renderers';\n\nexport type HandlerProps = {\n component: string;\n args?: Record<string, unknown>;\n slots?: Record<string, unknown>;\n};\n\nexport async function handlerFactory(integrations: Integration[]) {\n const safeIntegrations = integrations ?? [];\n const container = await AstroContainer.create({\n // Somewhat hacky way to force client-side Storybook's Vite to resolve modules properly\n resolve: async (s) => {\n if (s.startsWith('astro:scripts')) {\n return `/@id/${s}`;\n }\n\n for (const integration of safeIntegrations) {\n const resolution = integration.resolveClient(s);\n\n if (resolution) {\n return resolution;\n }\n }\n\n return s;\n }\n });\n\n addRenderers(container);\n\n return async function handler(data: HandlerProps) {\n const { default: Component } = await import(/* @vite-ignore */ data.component);\n\n // Process args to convert ImageMetadata objects to usable URLs\n const processedArgs = await processImageMetadata(data.args || {});\n\n // Wrap the component factory to fix the createAstro calling convention mismatch.\n // Astro compiler v2 produces: result.createAstro($$Astro, $$props, $$slots) [3 args]\n // Astro 6 runtime expects: result.createAstro($$props, $$slots) [2 args]\n // When v2-compiled components run against the v6 runtime, $$Astro gets captured as\n // \"props\" and actual props end up as \"slots\". This wrapper detects the 3-arg call\n // and strips the leading $$Astro argument.\n const patchedComponent = patchCreateAstroCompat(Component);\n\n const result = await container.renderToString(patchedComponent, {\n props: processedArgs,\n slots: data.slots ?? {}\n });\n\n return result;\n };\n}\n\n/**\n * Wraps an Astro component factory to fix the createAstro calling convention mismatch\n * between Astro compiler v2 and the Astro 6 runtime.\n *\n * The compiled component calls result.createAstro($$Astro, $$props, $$slots) [3 args],\n * but the Astro 6 runtime's createResult defines createAstro(props, slots) [2 params].\n * This causes $$Astro to be captured as \"props\" and actual props to be lost.\n *\n * The wrapper intercepts the result object and patches its createAstro method to\n * handle both calling conventions.\n */\nfunction patchCreateAstroCompat(Component: any): any {\n const wrapped = (result: any, props: any, slots: any) => {\n if (result && result.createAstro) {\n const origCreateAstro = result.createAstro;\n\n result.createAstro = (...args: any[]) => {\n if (args.length === 3) {\n // Compiler v2 convention: ($$Astro, $$props, $$slots) → skip $$Astro\n return origCreateAstro(args[1], args[2]);\n }\n\n // Compiler v3 convention: ($$props, $$slots) → pass through\n return origCreateAstro(...args);\n };\n }\n\n return Component(result, props, slots);\n };\n\n // Copy component factory metadata so the Container treats it as a valid Astro component\n wrapped.isAstroComponentFactory = Component.isAstroComponentFactory;\n wrapped.moduleId = Component.moduleId;\n wrapped.propagation = Component.propagation;\n\n return wrapped;\n}\n\n/**\n * Recursively processes arguments to convert ImageMetadata objects to usable image URLs.\n * This allows Astro's Image component to work properly in Storybook by converting\n * optimized asset references to direct file paths.\n */\nasync function processImageMetadata(args: Record<string, unknown>): Promise<Record<string, unknown>> {\n const processed: Record<string, unknown> = {};\n \n for (const [key, value] of Object.entries(args)) {\n if (isImageMetadata(value)) {\n // Convert ImageMetadata to a usable URL\n processed[key] = convertImageMetadataToUrl(value);\n } else if (Array.isArray(value)) {\n // Process arrays recursively\n processed[key] = await Promise.all(\n value.map(async (item) => \n typeof item === 'object' && item !== null \n ? await processImageMetadata(item as Record<string, unknown>)\n : item\n )\n );\n } else if (typeof value === 'object' && value !== null) {\n // Process nested objects recursively\n processed[key] = await processImageMetadata(value as Record<string, unknown>);\n } else {\n processed[key] = value;\n }\n }\n \n return processed;\n}\n\n/**\n * Type guard to check if a value is an ImageMetadata object.\n * ImageMetadata objects typically have properties like src, width, height, format.\n */\nfunction isImageMetadata(value: unknown): value is Record<string, any> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'src' in value &&\n typeof (value as any).src === 'string' &&\n ('width' in value || 'height' in value || 'format' in value)\n );\n}\n\n/**\n * Converts an ImageMetadata object to a usable URL for Storybook.\n * In a Storybook environment, we use the raw file path instead of optimized URLs.\n */\nfunction convertImageMetadataToUrl(imageMetadata: Record<string, any>): string {\n // For Storybook, use the raw src path which should be the file path\n // This bypasses Astro's image optimization which doesn't work in Storybook\n return imageMetadata.src || imageMetadata.fsPath || String(imageMetadata);\n}\n"],"mappings":";;;AAAA,SAAS,+BAA+B,sBAAsB;AAE9D,SAAS,oBAAoB;AAQ7B,eAAsB,eAAe,cAA6B;AAChE,QAAM,mBAAmB,gBAAgB,CAAC;AAC1C,QAAM,YAAY,MAAM,eAAe,OAAO;AAAA;AAAA,IAE5C,SAAS,OAAO,MAAM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AI,0BAA0B,KAAK;AAAA,IAClD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAE/B,gBAAU,GAAG,IAAI,MAAM,QAAQ;AAAA,QAC7B,MAAM;AAAA,UAAI,OAAO,SACf,OAAO,SAAS,YAAY,SAAS,OACjC,MAAM,qBAAqB,IAA+B,IAC1D;AAAA,QACN;AAAA,MACF;AAAA,IACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AAEtD,gBAAU,GAAG,IAAI,MAAM,qBAAqB,KAAgC;AAAA,IAC9E,OAAO;AACL,gBAAU,GAAG,IAAI;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAMA,SAAS,gBAAgB,OAA8C;AACrE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,SAAS,SACT,OAAQ,MAAc,QAAQ,aAC7B,WAAW,SAAS,YAAY,SAAS,YAAY;AAE1D;AAMA,SAAS,0BAA0B,eAA4C;AAG7E,SAAO,cAAc,OAAO,cAAc,UAAU,OAAO,aAAa;AAC1E;","names":[]}
|
package/dist/preset.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook-astro/framework",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.10",
|
|
4
4
|
"description": "Community-supported Storybook framework for Astro 6 components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/lukemcd/storybook-astro",
|
|
9
|
+
"url": "git+https://github.com/lukemcd/storybook-astro.git",
|
|
10
10
|
"directory": "packages/@storybook-astro/framework"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://storybook-astro.org",
|
|
@@ -24,10 +24,22 @@
|
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
26
|
"exports": {
|
|
27
|
-
".":
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./src/index.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./integrations": {
|
|
32
|
+
"types": "./src/integrations/index.ts",
|
|
33
|
+
"import": "./dist/integrations/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./testing": {
|
|
36
|
+
"types": "./src/testing.ts",
|
|
37
|
+
"import": "./dist/testing.js"
|
|
38
|
+
},
|
|
39
|
+
"./preset": {
|
|
40
|
+
"types": "./preset.ts",
|
|
41
|
+
"import": "./dist/preset.js"
|
|
42
|
+
},
|
|
31
43
|
"./package.json": "./package.json",
|
|
32
44
|
"./*": "./src/*"
|
|
33
45
|
},
|
|
@@ -66,17 +78,17 @@
|
|
|
66
78
|
"@types/node": "^20.19.0",
|
|
67
79
|
"@vitejs/plugin-react": "^5.0.0",
|
|
68
80
|
"alpinejs": "^3.14.9",
|
|
69
|
-
"astro": "^5.6.1",
|
|
81
|
+
"astro": "^5.6.1 || ^6.0.0-beta.0",
|
|
70
82
|
"storybook-solidjs": "^1.0.0-beta.7",
|
|
71
83
|
"vite-plugin-solid": "^2.11.10"
|
|
72
84
|
},
|
|
73
85
|
"peerDependencies": {
|
|
74
|
-
"@astrojs/alpinejs": "^0.4.5",
|
|
75
|
-
"@astrojs/preact": "^4.0.8",
|
|
76
|
-
"@astrojs/react": "^4.2.3",
|
|
77
|
-
"@astrojs/solid-js": "^5.0.7",
|
|
78
|
-
"@astrojs/svelte": "^7.0.9",
|
|
79
|
-
"@astrojs/vue": "^5.0.9",
|
|
86
|
+
"@astrojs/alpinejs": "^0.4.5 || ^0.5.0-beta.0",
|
|
87
|
+
"@astrojs/preact": "^4.0.8 || ^5.0.0-beta.0",
|
|
88
|
+
"@astrojs/react": "^4.2.3 || ^5.0.0-beta.0",
|
|
89
|
+
"@astrojs/solid-js": "^5.0.7 || ^6.0.0-beta.0",
|
|
90
|
+
"@astrojs/svelte": "^7.0.9 || ^8.0.0-beta.0",
|
|
91
|
+
"@astrojs/vue": "^5.0.9 || ^6.0.0-beta.0",
|
|
80
92
|
"@preact/preset-vite": "^2.10.1",
|
|
81
93
|
"@storybook/preact": "^10.0.0",
|
|
82
94
|
"@storybook/react": "^10.0.0",
|
|
@@ -85,7 +97,7 @@
|
|
|
85
97
|
"@vitejs/plugin-react": "^5.0.0",
|
|
86
98
|
"@vitejs/plugin-vue": "^5.2.3",
|
|
87
99
|
"@vitejs/plugin-vue-jsx": "^4.1.2",
|
|
88
|
-
"astro": "^5.5.3",
|
|
100
|
+
"astro": "^5.5.3 || ^6.0.0-beta.0",
|
|
89
101
|
"storybook": "^10.0.0",
|
|
90
102
|
"storybook-solidjs": "^1.0.0-beta.7",
|
|
91
103
|
"vite": "^6.2.5 || ^7.0.0"
|
|
@@ -135,14 +147,7 @@
|
|
|
135
147
|
}
|
|
136
148
|
},
|
|
137
149
|
"dependencies": {
|
|
138
|
-
"@storybook-astro/renderer": "
|
|
139
|
-
"
|
|
140
|
-
"react": "*",
|
|
141
|
-
"react-dom": "*",
|
|
142
|
-
"solid-js": "*",
|
|
143
|
-
"storybook": "*",
|
|
144
|
-
"svelte": "*",
|
|
145
|
-
"vite": "^6.2.5 || ^7.0.0",
|
|
146
|
-
"vue": "*"
|
|
150
|
+
"@storybook-astro/renderer": "0.1.0-beta.10",
|
|
151
|
+
"vite": "^6.2.5 || ^7.0.0"
|
|
147
152
|
}
|
|
148
|
-
}
|
|
153
|
+
}
|
package/src/middleware.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type HandlerProps = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export async function handlerFactory(integrations: Integration[]) {
|
|
12
|
+
const safeIntegrations = integrations ?? [];
|
|
12
13
|
const container = await AstroContainer.create({
|
|
13
14
|
// Somewhat hacky way to force client-side Storybook's Vite to resolve modules properly
|
|
14
15
|
resolve: async (s) => {
|
|
@@ -16,7 +17,7 @@ export async function handlerFactory(integrations: Integration[]) {
|
|
|
16
17
|
return `/@id/${s}`;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
for (const integration of
|
|
20
|
+
for (const integration of safeIntegrations) {
|
|
20
21
|
const resolution = integration.resolveClient(s);
|
|
21
22
|
|
|
22
23
|
if (resolution) {
|
package/src/preset.ts
CHANGED
|
@@ -19,13 +19,15 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, { pres
|
|
|
19
19
|
config.plugins = [];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const integrations = options.integrations ?? [];
|
|
23
|
+
|
|
22
24
|
config.plugins.push(
|
|
23
25
|
storybookAstroMiddlewarePlugin,
|
|
24
|
-
viteStorybookRendererFallbackPlugin(
|
|
26
|
+
viteStorybookRendererFallbackPlugin(integrations),
|
|
25
27
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
28
|
vitePluginAstroComponentMarker() as any,
|
|
27
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
vitePluginAstroBuildPrerender(
|
|
30
|
+
vitePluginAstroBuildPrerender(integrations) as any,
|
|
29
31
|
...viteConfig.plugins
|
|
30
32
|
);
|
|
31
33
|
|
|
@@ -47,7 +49,7 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, { pres
|
|
|
47
49
|
aliases['react-dom'] = 'react-dom';
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
const finalConfig = await mergeWithAstroConfig(config,
|
|
52
|
+
const finalConfig = await mergeWithAstroConfig(config, integrations);
|
|
51
53
|
|
|
52
54
|
return finalConfig;
|
|
53
55
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Integration } from './integrations/index.ts';
|
|
2
2
|
|
|
3
3
|
export function viteAstroContainerRenderersPlugin(integrations: Integration[]) {
|
|
4
|
+
const safeIntegrations = integrations ?? [];
|
|
4
5
|
const name = 'astro-container-renderers';
|
|
5
6
|
const virtualModuleId = `virtual:${name}`;
|
|
6
7
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
@@ -16,12 +17,12 @@ export function viteAstroContainerRenderersPlugin(integrations: Integration[]) {
|
|
|
16
17
|
|
|
17
18
|
load(id: string) {
|
|
18
19
|
if (id === resolvedVirtualModuleId) {
|
|
19
|
-
const importStatements = buildImportStatements(
|
|
20
|
+
const importStatements = buildImportStatements(safeIntegrations);
|
|
20
21
|
|
|
21
22
|
const code = `
|
|
22
23
|
${importStatements}
|
|
23
24
|
export function addRenderers(container) {
|
|
24
|
-
${
|
|
25
|
+
${safeIntegrations.map((integration) => buildServerRenderer(integration) + '\n' + buildClientRenderer(integration)).join('\n')}
|
|
25
26
|
}
|
|
26
27
|
`;
|
|
27
28
|
|
package/src/vitePluginAstro.ts
CHANGED
|
@@ -27,15 +27,16 @@ const ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK = [
|
|
|
27
27
|
'astro:vite-plugin-file-url'
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
-
export async function mergeWithAstroConfig(config: InlineConfig, integrations: Integration[]) {
|
|
30
|
+
export async function mergeWithAstroConfig(config: InlineConfig, integrations: Integration[] = []) {
|
|
31
31
|
const { getViteConfig } = await import('astro/config');
|
|
32
|
+
const safeIntegrations = integrations ?? [];
|
|
32
33
|
|
|
33
34
|
const astroConfig = await getViteConfig(
|
|
34
35
|
{},
|
|
35
36
|
{
|
|
36
37
|
configFile: false,
|
|
37
38
|
integrations: await Promise.all(
|
|
38
|
-
|
|
39
|
+
safeIntegrations.map((integration) => integration.loadIntegration())
|
|
39
40
|
)
|
|
40
41
|
}
|
|
41
42
|
)({
|
|
@@ -26,6 +26,7 @@ import { createViteServer } from './viteStorybookAstroMiddlewarePlugin.ts';
|
|
|
26
26
|
* - Stories that override the meta component are skipped
|
|
27
27
|
*/
|
|
28
28
|
export function vitePluginAstroBuildPrerender(integrations: Integration[]): Plugin {
|
|
29
|
+
const safeIntegrations = integrations ?? [];
|
|
29
30
|
let viteServer: ViteDevServer | null = null;
|
|
30
31
|
let handler: ((data: HandlerProps) => Promise<string>) | null = null;
|
|
31
32
|
|
|
@@ -41,14 +42,14 @@ export function vitePluginAstroBuildPrerender(integrations: Integration[]): Plug
|
|
|
41
42
|
|
|
42
43
|
async buildStart() {
|
|
43
44
|
try {
|
|
44
|
-
viteServer = await createViteServer(
|
|
45
|
+
viteServer = await createViteServer(safeIntegrations);
|
|
45
46
|
|
|
46
47
|
const filePath = fileURLToPath(new URL('./middleware', import.meta.url));
|
|
47
48
|
const middleware = await viteServer.ssrLoadModule(filePath, {
|
|
48
49
|
fixStacktrace: true
|
|
49
50
|
});
|
|
50
51
|
|
|
51
|
-
handler = await middleware.handlerFactory(
|
|
52
|
+
handler = await middleware.handlerFactory(safeIntegrations);
|
|
52
53
|
} catch (err) {
|
|
53
54
|
console.warn(
|
|
54
55
|
'[storybook-astro] Failed to create pre-render server:',
|
|
@@ -20,7 +20,7 @@ export async function vitePluginStorybookAstroMiddleware(options: FrameworkOptio
|
|
|
20
20
|
const middleware = await viteServer.ssrLoadModule(filePath, {
|
|
21
21
|
fixStacktrace: true
|
|
22
22
|
});
|
|
23
|
-
const handler = await middleware.handlerFactory(options.integrations);
|
|
23
|
+
const handler = await middleware.handlerFactory(options.integrations ?? []);
|
|
24
24
|
|
|
25
25
|
server.ws.on('astro:render:request', async (data: RenderRequestMessage['data']) => {
|
|
26
26
|
try {
|
|
@@ -93,13 +93,14 @@ return;
|
|
|
93
93
|
|
|
94
94
|
export async function createViteServer(integrations: Integration[]) {
|
|
95
95
|
const { getViteConfig } = await import('astro/config');
|
|
96
|
+
const safeIntegrations = integrations ?? [];
|
|
96
97
|
|
|
97
98
|
const config = await getViteConfig(
|
|
98
99
|
{},
|
|
99
100
|
{
|
|
100
101
|
configFile: false,
|
|
101
102
|
integrations: await Promise.all(
|
|
102
|
-
|
|
103
|
+
safeIntegrations.map((integration) => integration.loadIntegration())
|
|
103
104
|
)
|
|
104
105
|
}
|
|
105
106
|
)({ mode: 'development', command: 'serve' });
|
|
@@ -109,7 +110,7 @@ export async function createViteServer(integrations: Integration[]) {
|
|
|
109
110
|
...config,
|
|
110
111
|
plugins: [
|
|
111
112
|
...(config.plugins?.filter(Boolean) ?? []),
|
|
112
|
-
viteAstroContainerRenderersPlugin(
|
|
113
|
+
viteAstroContainerRenderersPlugin(safeIntegrations),
|
|
113
114
|
vitePluginAstroFontsFallback()
|
|
114
115
|
]
|
|
115
116
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Integration } from './integrations/index.ts';
|
|
2
2
|
|
|
3
3
|
export function viteStorybookRendererFallbackPlugin(integrations: Integration[]) {
|
|
4
|
+
const safeIntegrations = integrations ?? [];
|
|
4
5
|
const name = 'storybook-renderer-fallback';
|
|
5
6
|
const virtualModuleId = `virtual:${name}`;
|
|
6
7
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
@@ -16,7 +17,7 @@ export function viteStorybookRendererFallbackPlugin(integrations: Integration[])
|
|
|
16
17
|
|
|
17
18
|
load(id: string) {
|
|
18
19
|
if (id === resolvedVirtualModuleId) {
|
|
19
|
-
return
|
|
20
|
+
return safeIntegrations
|
|
20
21
|
.filter((integration) => integration.storybookEntryPreview)
|
|
21
22
|
.map(
|
|
22
23
|
(integration) =>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viteStorybookAstroMiddlewarePlugin.ts","../src/viteAstroContainerRenderersPlugin.ts","../src/vitePluginAstroFontsFallback.ts","../src/viteStorybookRendererFallbackPlugin.ts","../src/vitePluginAstroComponentMarker.ts","../src/vitePluginAstroBuildPrerender.ts","../src/vitePluginAstro.ts","../src/preset.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport { createServer, type PluginOption, type ViteDevServer } from 'vite';\nimport type { RenderRequestMessage, RenderResponseMessage } from '@storybook-astro/renderer/types';\nimport type { FrameworkOptions } from './types.ts';\nimport type { Integration } from './integrations/index.ts';\nimport { viteAstroContainerRenderersPlugin } from './viteAstroContainerRenderersPlugin.ts';\nimport { vitePluginAstroFontsFallback } from './vitePluginAstroFontsFallback.ts';\n\nexport async function vitePluginStorybookAstroMiddleware(options: FrameworkOptions) {\n // The internal Vite server is created lazily inside configureServer (dev-only).\n // During builds, configureServer never fires, so no server is created.\n let viteServer: ViteDevServer | null = null;\n\n const vitePlugin = {\n name: 'storybook-astro-middleware-plugin',\n async configureServer(server) {\n viteServer = await createViteServer(options.integrations);\n\n const filePath = fileURLToPath(new URL('./middleware', import.meta.url));\n const middleware = await viteServer.ssrLoadModule(filePath, {\n fixStacktrace: true\n });\n const handler = await middleware.handlerFactory(options.integrations);\n\n server.ws.on('astro:render:request', async (data: RenderRequestMessage['data']) => {\n try {\n const html = await handler(data);\n\n server.ws.send('astro:render:response', {\n html,\n id: data.id\n } satisfies RenderResponseMessage['data']);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n const errorStack = err instanceof Error ? err.stack : '';\n\n console.error('[storybook-astro] Render error:', errorMessage);\n if (errorStack) {console.error(errorStack);}\n server.ws.send('astro:render:response', {\n id: data.id,\n html:\n '<div style=\"background: #d73838; padding: 12px; color: #f0f0f0; font-family: monospace; border-radius: 4px\">' +\n '<strong>Error rendering Astro component</strong><br/>' +\n '<pre style=\"white-space: pre-wrap; margin-top: 8px; font-size: 12px\">' +\n errorMessage.replace(/</g, '<').replace(/>/g, '>') +\n '</pre></div>'\n } satisfies RenderResponseMessage['data']);\n }\n });\n }\n } satisfies PluginOption;\n\n // Create asset serving plugin (only active in dev when viteServer exists)\n const assetServingPlugin = {\n name: 'storybook-astro-assets',\n configureServer(server) {\n server.middlewares.use('/_image', (req, res, next) => {\n if (!viteServer) {\n next();\n \nreturn;\n }\n // Forward the request to the Astro vite server\n viteServer.middlewares.handle(req, res, (err) => {\n if (err) {\n console.error('Asset serving error:', err);\n next();\n }\n });\n });\n }\n };\n\n // The extracted CSS plugins from Astro's internal Vite server cause Vue SFC\n // <style> blocks to be double-processed (once by these plugins, once by\n // Storybook's built-in CSS plugins), resulting in PostCSS errors.\n // \n // Solution: Don't extract Astro's CSS plugins. Storybook's built-in CSS\n // plugins handle both Vue styles AND Astro style sub-modules (which are\n // standard CSS imports like `Component.astro?astro&type=style&index=0&lang.css`).\n // \n // The Astro internal server's CSS plugins are only needed for SSR rendering\n // within that server - they don't need to be shared with Storybook's server.\n return {\n vitePlugin,\n viteConfig: {\n plugins: [\n assetServingPlugin\n ].filter(Boolean)\n }\n };\n}\n\nexport async function createViteServer(integrations: Integration[]) {\n const { getViteConfig } = await import('astro/config');\n\n const config = await getViteConfig(\n {},\n {\n configFile: false,\n integrations: await Promise.all(\n integrations.map((integration) => integration.loadIntegration())\n )\n }\n )({ mode: 'development', command: 'serve' });\n\n const viteServer = await createServer({\n configFile: false,\n ...config,\n plugins: [\n ...(config.plugins?.filter(Boolean) ?? []),\n viteAstroContainerRenderersPlugin(integrations),\n vitePluginAstroFontsFallback()\n ]\n });\n\n // Initialize the server's plugin container to ensure all plugins are ready.\n // Without this, some plugins (like vite:css) may have uninitialized state\n // when ssrLoadModule is called.\n await viteServer.pluginContainer.buildStart({});\n\n return viteServer;\n}\n","import type { Integration } from './integrations/index.ts';\n\nexport function viteAstroContainerRenderersPlugin(integrations: Integration[]) {\n const name = 'astro-container-renderers';\n const virtualModuleId = `virtual:${name}`;\n const resolvedVirtualModuleId = `\\0${virtualModuleId}`;\n\n return {\n name,\n\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId;\n }\n },\n\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n const importStatements = buildImportStatements(integrations);\n\n const code = `\n ${importStatements}\n export function addRenderers(container) {\n ${integrations.map((integration) => buildServerRenderer(integration) + '\\n' + buildClientRenderer(integration)).join('\\n')}\n }\n `;\n\n return code;\n }\n }\n };\n}\n\nfunction buildImportStatements(integrations: Integration[]) {\n return integrations\n .filter((integration) => integration.renderer.server)\n .map(\n (integration) =>\n `import ${integration.name}Renderer from '${integration.renderer.server?.entrypoint}';`\n )\n .join('\\n');\n}\n\nfunction buildServerRenderer(integration: Integration) {\n const serverRenderer = integration.renderer.server;\n\n if (!serverRenderer) {\n return '';\n }\n\n if (integration.name === 'solid') {\n return `\n container.addServerRenderer({\n name: '${serverRenderer.name}',\n renderer: {\n ...${integration.name}Renderer,\n name: '${serverRenderer.name}'\n }\n });\n `;\n }\n\n return `\n container.addServerRenderer({\n name: '${serverRenderer.name}',\n renderer: ${integration.name}Renderer\n });\n `;\n}\n\nfunction buildClientRenderer(integration: Integration) {\n const clientRenderer = integration.renderer.client;\n\n if (clientRenderer) {\n return `\n container.addClientRenderer({\n name: '${clientRenderer.name}',\n entrypoint: '${clientRenderer.entrypoint}'\n });\n `;\n }\n\n return '';\n}\n","import type { Plugin } from 'vite';\n\nconst FONTS_RUNTIME_STUB = `\nexport const fontData = {};\nexport function createGetFontData(fontsMod) {\n return fontsMod?.fontDataByCssVariable ?? {};\n}\n`;\n\nconst FONTS_INTERNAL_STUB = `\nexport const componentDataByCssVariable = new Map();\nexport const fontDataByCssVariable = {};\n`;\n\n/**\n * Provides fallback resolution for Astro's font-related virtual modules\n * and package import paths in Storybook's SSR Vite server.\n *\n * In Astro 6, the `astro:assets` virtual module depends on font-related\n * modules through virtual modules and a bare `astro/assets/fonts/runtime`\n * import. In the Storybook SSR context:\n *\n * 1. The fonts plugin's filter-based `resolveId` may not trigger for\n * the virtual module IDs.\n * 2. A Vite transform rewrites the `astro:assets` module to import\n * `createGetFontData` from `astro/assets/fonts/runtime` (without\n * `.js`), which fails against Astro's package.json exports map.\n * 3. The `createGetFontData` function is injected by a runtime Vite\n * transform that doesn't run in our SSR context.\n *\n * This plugin stubs all three font module paths with no-op exports,\n * since Storybook doesn't need Astro's font system.\n */\nexport function vitePluginAstroFontsFallback(): Plugin {\n const VIRTUAL_ID = 'virtual:astro:assets/fonts/internal';\n const RUNTIME_VIRTUAL_ID = 'virtual:astro:assets/fonts/runtime';\n const RESOLVED_VIRTUAL_ID = '\\0' + VIRTUAL_ID;\n const RESOLVED_RUNTIME_VIRTUAL_ID = '\\0' + RUNTIME_VIRTUAL_ID;\n const RESOLVED_FONTS_RUNTIME_ID = '\\0storybook:astro-fonts-runtime';\n\n return {\n name: 'storybook-astro-fonts-fallback',\n // Must run before vite:resolve to intercept virtual modules\n // before Vite tries to resolve them as Node package imports\n enforce: 'pre',\n\n resolveId(id) {\n if (id === VIRTUAL_ID) {\n return RESOLVED_VIRTUAL_ID;\n }\n if (id === RUNTIME_VIRTUAL_ID) {\n return RESOLVED_RUNTIME_VIRTUAL_ID;\n }\n // Intercept the bare package import (without .js) and the .js variant\n if (id === 'astro/assets/fonts/runtime' || id === 'astro/assets/fonts/runtime.js') {\n return RESOLVED_FONTS_RUNTIME_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return { code: FONTS_INTERNAL_STUB };\n }\n if (id === RESOLVED_RUNTIME_VIRTUAL_ID || id === RESOLVED_FONTS_RUNTIME_ID) {\n return { code: FONTS_RUNTIME_STUB };\n }\n }\n };\n}\n","import type { Integration } from './integrations/index.ts';\n\nexport function viteStorybookRendererFallbackPlugin(integrations: Integration[]) {\n const name = 'storybook-renderer-fallback';\n const virtualModuleId = `virtual:${name}`;\n const resolvedVirtualModuleId = `\\0${virtualModuleId}`;\n\n return {\n name,\n\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId;\n }\n },\n\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n return integrations\n .filter((integration) => integration.storybookEntryPreview)\n .map(\n (integration) =>\n `export * as ${integration.name} from '${integration.storybookEntryPreview}';`\n )\n .join('\\n');\n }\n }\n };\n}\n","import { readFileSync } from 'node:fs';\nimport type { PluginOption } from 'vite';\n\n/**\n * Vite plugin that patches Astro 6's client-side .astro file transforms for Storybook.\n *\n * In Astro 6, the client-side transform of .astro files produces a stub function that\n * throws \"Astro components cannot be used in the browser\" without setting the\n * `isAstroComponentFactory` marker. Storybook's renderer relies on this marker to detect\n * Astro components and route them to server-side rendering via the Container API.\n *\n * This plugin also preserves the component's scoped CSS by importing the style sub-modules\n * that the Astro Vite plugin exposes. Without this, the client-side stub would strip all\n * CSS since Astro 6 no longer includes style imports in client-side .astro transforms.\n *\n * During builds, Astro's compile metadata cache is not populated for client-side transforms,\n * so style sub-module imports would fail. Instead, raw CSS is extracted directly from the\n * .astro source and inlined.\n */\nexport function vitePluginAstroComponentMarker(): PluginOption {\n let isBuild = false;\n\n return {\n name: 'storybook-astro-component-marker',\n enforce: 'post',\n\n configResolved(config) {\n isBuild = config.command === 'build';\n },\n\n transform(code: string, id: string) {\n // Only process main .astro modules (not sub-modules like ?astro&type=style)\n if (!id.endsWith('.astro')) {return null;}\n\n // Detect the Astro 6 client-side stub pattern\n if (!code.includes('Astro components cannot be used in the browser')) {return null;}\n\n const moduleId = id;\n\n // In dev mode, import style sub-modules via Astro's Vite plugin (which has\n // compile metadata cached from the SSR transform).\n // In build mode, Astro's compile metadata cache is not populated for client-side\n // transforms, so sub-module imports would fail. Extract raw CSS instead.\n const styleCode = isBuild\n ? generateInlineStyles(moduleId)\n : generateStyleImports(moduleId);\n\n return {\n code: `\n${styleCode}\nconst __astro_component = () => {\n throw new Error('Astro components are rendered server-side by Storybook.');\n};\n__astro_component.isAstroComponentFactory = true;\n__astro_component.moduleId = ${JSON.stringify(moduleId)};\nexport default __astro_component;\n`,\n map: null,\n };\n },\n };\n}\n\n/**\n * Reads the original .astro source file and generates import statements\n * for each <style> block, using the Astro Vite plugin's sub-module convention.\n */\nfunction generateStyleImports(filePath: string): string {\n try {\n const source = readFileSync(filePath, 'utf-8');\n const styleCount = countStyleBlocks(source);\n\n return Array.from({ length: styleCount }, (_, i) =>\n `import ${JSON.stringify(`${filePath}?astro&type=style&index=${i}&lang.css`)};`\n ).join('\\n');\n } catch {\n return '';\n }\n}\n\n/**\n * Reads the original .astro source file and generates a JS snippet that injects\n * the raw CSS from each <style> block into the document. Used during builds where\n * Astro's compile metadata cache is unavailable.\n *\n * The CSS is unscoped (no Astro scoping transforms), which is acceptable because\n * Astro components show a fallback message in static builds.\n */\nfunction generateInlineStyles(filePath: string): string {\n try {\n const source = readFileSync(filePath, 'utf-8');\n const cssBlocks = extractStyleBlocks(source);\n\n if (cssBlocks.length === 0) {return '';}\n\n // Create a side-effect that injects styles into the document\n return cssBlocks.map((css, i) => {\n const escaped = JSON.stringify(css);\n\n \nreturn `\n(function() {\n if (typeof document !== 'undefined') {\n const style = document.createElement('style');\n style.setAttribute('data-astro-build', ${JSON.stringify(filePath + ':' + i)});\n style.textContent = ${escaped};\n document.head.appendChild(style);\n }\n})();`;\n }).join('\\n');\n } catch {\n return '';\n }\n}\n\n/**\n * Extracts the content of all top-level <style> blocks from an Astro component's source.\n * Strips frontmatter before parsing.\n */\nfunction extractStyleBlocks(source: string): string[] {\n const withoutFrontmatter = source.replace(/^---[\\s\\S]*?---/m, '');\n const blocks: string[] = [];\n const regex = /<style(?:\\s[^>]*)?>([\\s\\S]*?)<\\/style>/g;\n let match;\n\n while ((match = regex.exec(withoutFrontmatter)) !== null) {\n blocks.push(match[1].trim());\n }\n\n return blocks;\n}\n\n/**\n * Counts the number of top-level <style> blocks in an Astro component's source.\n * Only counts opening tags that are NOT inside the frontmatter fence (---).\n */\nfunction countStyleBlocks(source: string): number {\n // Strip frontmatter\n const withoutFrontmatter = source.replace(/^---[\\s\\S]*?---/m, '');\n // Match <style> opening tags (with optional attributes)\n const matches = withoutFrontmatter.match(/<style(\\s|>)/g);\n\n \nreturn matches ? matches.length : 0;\n}\n","import { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { basename } from 'node:path';\nimport type { Plugin, ViteDevServer } from 'vite';\nimport type { Integration } from './integrations/index.ts';\nimport type { HandlerProps } from './middleware.ts';\nimport { createViteServer } from './viteStorybookAstroMiddlewarePlugin.ts';\n\n/**\n * Vite plugin that pre-renders Astro component stories at build time.\n *\n * During `storybook build`, this plugin:\n * 1. Creates an internal Vite SSR server with AstroContainer\n * 2. Detects story files that import Astro components\n * 3. Loads each story module via ssrLoadModule to get fully evaluated args\n * (including imported assets, computed values, etc.)\n * 4. Renders each story variant using AstroContainer\n * 5. Injects the pre-rendered HTML as a story parameter (`__astroPrerendered`)\n *\n * The renderer checks for this parameter in static builds and uses the\n * pre-rendered HTML directly instead of showing a fallback message.\n *\n * Limitations:\n * - Controls panel changes won't update Astro components (HTML is static)\n * - Build time increases with the number of Astro stories\n * - Stories that override the meta component are skipped\n */\nexport function vitePluginAstroBuildPrerender(integrations: Integration[]): Plugin {\n let viteServer: ViteDevServer | null = null;\n let handler: ((data: HandlerProps) => Promise<string>) | null = null;\n\n // Maps placeholder strings to Rollup emitted-file reference IDs.\n // Placeholders are injected into pre-rendered HTML during transform,\n // then resolved to final asset paths in renderChunk.\n const assetRefIds = new Map<string, string>();\n\n return {\n name: 'storybook-astro-build-prerender',\n apply: 'build',\n enforce: 'post',\n\n async buildStart() {\n try {\n viteServer = await createViteServer(integrations);\n\n const filePath = fileURLToPath(new URL('./middleware', import.meta.url));\n const middleware = await viteServer.ssrLoadModule(filePath, {\n fixStacktrace: true\n });\n\n handler = await middleware.handlerFactory(integrations);\n } catch (err) {\n console.warn(\n '[storybook-astro] Failed to create pre-render server:',\n err instanceof Error ? err.message : err\n );\n }\n },\n\n async transform(code, id) {\n if (!handler || !viteServer) {return null;}\n\n // Only process story files\n if (!/\\.stories\\.(jsx?|tsx?|mjs)$/.test(id)) {return null;}\n\n // Parse AST to find .astro imports\n const ast = this.parse(code);\n const astroImport = findFirstAstroImport(ast);\n\n if (!astroImport) {return null;}\n\n // Resolve the .astro import to an absolute path\n const resolved = await this.resolve(astroImport.source, id);\n\n if (!resolved) {return null;}\n const componentPath = resolved.id;\n\n // Load the story module via SSR to get fully evaluated args\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let storyModule: Record<string, any>;\n\n try {\n storyModule = await viteServer.ssrLoadModule(id);\n } catch (err) {\n console.warn(\n `[storybook-astro] Failed to load story for pre-render: ${id}`,\n err instanceof Error ? err.message : err\n );\n \nreturn null;\n }\n\n const meta = storyModule.default || {};\n\n // Confirm the meta component is an Astro component\n if (!meta.component?.isAstroComponentFactory) {return null;}\n\n // Find all named exports that are story objects\n const storyNames = Object.keys(storyModule).filter(\n (k) =>\n k !== 'default' &&\n k !== '__esModule' &&\n typeof storyModule[k] === 'object' &&\n storyModule[k] !== null\n );\n\n if (storyNames.length === 0) {return null;}\n\n // Pre-render each story\n const prerendered: Record<string, string> = {};\n\n for (const name of storyNames) {\n const story = storyModule[name];\n\n // Skip stories that override the component — the resolved path\n // corresponds to the meta component and may not match\n if (story.component && story.component !== meta.component) {continue;}\n\n // Merge meta args with story args (story args take precedence)\n const mergedArgs = { ...meta.args, ...story.args };\n const { slots = {}, ...componentArgs } = mergedArgs;\n\n try {\n const html = await handler({\n component: componentPath,\n args: componentArgs,\n slots: (slots ?? {}) as Record<string, unknown>\n });\n // Rewrite /@fs dev-server URLs to Rollup asset placeholders.\n // The actual files are emitted via this.emitFile and the\n // placeholders are resolved to final paths in renderChunk.\n\n prerendered[name] = emitAndRewriteAssetUrls(html, this, assetRefIds);\n } catch (err) {\n console.warn(\n `[storybook-astro] Pre-render failed for \"${name}\" in ${id}:`,\n err instanceof Error ? err.message : err\n );\n }\n }\n\n if (Object.keys(prerendered).length === 0) {return null;}\n\n // Append code that injects pre-rendered HTML as story parameters.\n // This runs as module-level side effects during import, before\n // Storybook reads the story exports.\n const injections = Object.entries(prerendered).map(\n ([name, html]) =>\n `if (typeof ${name} !== 'undefined' && ${name} && typeof ${name} === 'object') {\\n` +\n ` ${name}.parameters = Object.assign({}, ${name}.parameters, ` +\n `{ __astroPrerendered: ${JSON.stringify(html)} });\\n` +\n `}`\n );\n\n return {\n code:\n code +\n '\\n// Pre-rendered by storybook-astro-build-prerender\\n' +\n injections.join('\\n'),\n map: null\n };\n },\n\n renderChunk(code) {\n if (assetRefIds.size === 0) {return null;}\n\n let result = code;\n let modified = false;\n\n for (const [placeholder, refId] of assetRefIds) {\n if (!result.includes(placeholder)) {continue;}\n const fileName = this.getFileName(refId);\n\n result = result.replaceAll(placeholder, fileName);\n modified = true;\n }\n\n return modified ? { code: result, map: null } : null;\n },\n\n async buildEnd() {\n if (viteServer) {\n await viteServer.close();\n viteServer = null;\n handler = null;\n }\n }\n };\n}\n\n/**\n * Finds the first import declaration with a .astro source in the ESTree AST.\n */\nfunction findFirstAstroImport(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ast: any\n): { local: string; source: string } | null {\n for (const node of ast.body) {\n if (\n node.type === 'ImportDeclaration' &&\n typeof node.source.value === 'string' &&\n node.source.value.endsWith('.astro')\n ) {\n const defaultSpecifier = node.specifiers?.find(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (s: any) => s.type === 'ImportDefaultSpecifier'\n );\n\n if (defaultSpecifier) {\n return {\n local: defaultSpecifier.local.name,\n source: node.source.value\n };\n }\n }\n }\n \nreturn null;\n}\n\n/**\n * Finds /@fs dev-server URLs in pre-rendered HTML, emits the referenced\n * files as Rollup assets, and replaces the URLs with placeholders that\n * are resolved to final paths in renderChunk.\n */\nfunction emitAndRewriteAssetUrls(\n html: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ctx: any,\n refIds: Map<string, string>\n): string {\n // Match /@fs URLs in HTML attribute values.\n // The URL may have a query string with HTML-encoded & (&).\n // Note: file paths may contain spaces, so we match until the closing quote.\n return html.replace(/\\/@fs([^\"'>]+)/g, (fullMatch, rawPath: string) => {\n // Strip query string (may contain & or &)\n const pathOnly = rawPath.split('?')[0];\n\n try {\n const source = readFileSync(pathOnly);\n const name = basename(pathOnly);\n const refId = ctx.emitFile({ type: 'asset', name, source });\n const placeholder = `__ASTRO_PRERENDER_ASSET_${refId}__`;\n\n refIds.set(placeholder, refId);\n \nreturn placeholder;\n } catch {\n return fullMatch;\n }\n });\n}\n","import { mergeConfig, type InlineConfig } from 'vite';\nimport type { Integration } from './integrations/index.ts';\n\nconst ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK = [\n '@astro/plugin-actions',\n '@astrojs/vite-plugin-astro-ssr-manifest',\n 'astro-content-virtual-mod-plugin',\n 'astro:actions',\n 'astro:build:normal',\n 'astro:container',\n 'astro:content-asset-propagation',\n 'astro:content-imports',\n 'astro:content-listen',\n 'astro:dev-toolbar',\n 'astro:head-metadata',\n 'astro:html',\n 'astro:i18n',\n 'astro:integration-container',\n 'astro:jsx',\n 'astro:markdown',\n 'astro:postprocess',\n 'astro:prefetch',\n 'astro:scanner',\n 'astro:scripts:page-ssr',\n 'astro:server',\n 'astro:vite-plugin-env',\n 'astro:vite-plugin-file-url'\n];\n\nexport async function mergeWithAstroConfig(config: InlineConfig, integrations: Integration[]) {\n const { getViteConfig } = await import('astro/config');\n\n const astroConfig = await getViteConfig(\n {},\n {\n configFile: false,\n integrations: await Promise.all(\n integrations.map((integration) => integration.loadIntegration())\n )\n }\n )({\n mode: 'development',\n command: 'serve'\n });\n\n const filteredPlugins = astroConfig\n .plugins!.flat()\n .filter(\n (plugin) =>\n plugin &&\n 'name' in plugin &&\n !ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK.includes(plugin.name)\n );\n\n return mergeConfig(config, {\n ...astroConfig,\n plugins: filteredPlugins\n });\n}\n","import type { StorybookConfigVite, FrameworkOptions } from './types.ts';\nimport { vitePluginStorybookAstroMiddleware } from './viteStorybookAstroMiddlewarePlugin.ts';\nimport { viteStorybookRendererFallbackPlugin } from './viteStorybookRendererFallbackPlugin.ts';\nimport { vitePluginAstroComponentMarker } from './vitePluginAstroComponentMarker.ts';\nimport { vitePluginAstroBuildPrerender } from './vitePluginAstroBuildPrerender.ts';\nimport { mergeWithAstroConfig } from './vitePluginAstro.ts';\n\nexport const core = {\n builder: '@storybook/builder-vite',\n renderer: '@storybook-astro/renderer'\n};\n\nexport const viteFinal: StorybookConfigVite['viteFinal'] = async (config, { presets }) => {\n const options = await presets.apply<FrameworkOptions>('frameworkOptions');\n const { vitePlugin: storybookAstroMiddlewarePlugin, viteConfig } =\n await vitePluginStorybookAstroMiddleware(options);\n\n if (!config.plugins) {\n config.plugins = [];\n }\n\n config.plugins.push(\n storybookAstroMiddlewarePlugin,\n viteStorybookRendererFallbackPlugin(options.integrations),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n vitePluginAstroComponentMarker() as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n vitePluginAstroBuildPrerender(options.integrations) as any,\n ...viteConfig.plugins\n );\n\n // Add React/ReactDOM aliases for storybook-solidjs compatibility\n if (!config.resolve) {\n config.resolve = {};\n }\n if (!config.resolve.alias) {\n config.resolve.alias = {};\n }\n \n // Ensure React is available for storybook-solidjs\n const aliases = config.resolve.alias as Record<string, string>;\n\n if (!aliases['react']) {\n aliases['react'] = 'react';\n }\n if (!aliases['react-dom']) {\n aliases['react-dom'] = 'react-dom';\n }\n\n const finalConfig = await mergeWithAstroConfig(config, options.integrations);\n\n return finalConfig;\n};\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,oBAA2D;;;ACC7D,SAAS,kCAAkC,cAA6B;AAC7E,QAAM,OAAO;AACb,QAAM,kBAAkB,WAAW,IAAI;AACvC,QAAM,0BAA0B,KAAK,eAAe;AAEpD,SAAO;AAAA,IACL;AAAA,IAEA,UAAU,IAAY;AACpB,UAAI,OAAO,iBAAiB;AAC1B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAY;AACf,UAAI,OAAO,yBAAyB;AAClC,cAAM,mBAAmB,sBAAsB,YAAY;AAE3D,cAAM,OAAO;AAAA,YACT,gBAAgB;AAAA;AAAA,cAEd,aAAa,IAAI,CAAC,gBAAgB,oBAAoB,WAAW,IAAI,OAAO,oBAAoB,WAAW,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA;AAAA;AAI9H,eAAO;AAA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