storybook-astro 0.1.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.
- package/LICENSE +21 -0
- package/README.md +330 -0
- package/dist/index.cjs +397 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +390 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/index.cjs +50 -0
- package/dist/integration/index.cjs.map +1 -0
- package/dist/integration/index.d.cts +26 -0
- package/dist/integration/index.d.ts +26 -0
- package/dist/integration/index.js +44 -0
- package/dist/integration/index.js.map +1 -0
- package/dist/integration/toolbar-app.cjs +91 -0
- package/dist/integration/toolbar-app.cjs.map +1 -0
- package/dist/integration/toolbar-app.d.cts +10 -0
- package/dist/integration/toolbar-app.d.ts +10 -0
- package/dist/integration/toolbar-app.js +89 -0
- package/dist/integration/toolbar-app.js.map +1 -0
- package/dist/preset.cjs +294 -0
- package/dist/preset.cjs.map +1 -0
- package/dist/preset.d.cts +49 -0
- package/dist/preset.d.ts +49 -0
- package/dist/preset.js +285 -0
- package/dist/preset.js.map +1 -0
- package/dist/render-BR-BGSWL.d.cts +36 -0
- package/dist/render-BR-BGSWL.d.ts +36 -0
- package/dist/renderer/entry-preview.cjs +315 -0
- package/dist/renderer/entry-preview.cjs.map +1 -0
- package/dist/renderer/entry-preview.d.cts +26 -0
- package/dist/renderer/entry-preview.d.ts +26 -0
- package/dist/renderer/entry-preview.js +311 -0
- package/dist/renderer/entry-preview.js.map +1 -0
- package/dist/renderer/index.cjs +216 -0
- package/dist/renderer/index.cjs.map +1 -0
- package/dist/renderer/index.d.cts +21 -0
- package/dist/renderer/index.d.ts +21 -0
- package/dist/renderer/index.js +211 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/sourceTransformer-CsgaPbY9.d.cts +38 -0
- package/dist/sourceTransformer-CsgaPbY9.d.ts +38 -0
- package/package.json +100 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var toolbar = require('astro/toolbar');
|
|
4
|
+
|
|
5
|
+
// src/integration/toolbar-app.ts
|
|
6
|
+
var toolbar_app_default = toolbar.defineToolbarApp({
|
|
7
|
+
init(canvas) {
|
|
8
|
+
fetch("/__storybook-config").then((res) => res.json()).then((config) => {
|
|
9
|
+
const storybookUrl = `http://${config.host}:${config.port}`;
|
|
10
|
+
const container = document.createElement("astro-dev-toolbar-window");
|
|
11
|
+
const content = document.createElement("div");
|
|
12
|
+
content.style.padding = "1rem";
|
|
13
|
+
const title = document.createElement("h2");
|
|
14
|
+
title.textContent = "Storybook";
|
|
15
|
+
title.style.marginTop = "0";
|
|
16
|
+
title.style.marginBottom = "0.5rem";
|
|
17
|
+
title.style.fontSize = "1.1rem";
|
|
18
|
+
title.style.fontWeight = "600";
|
|
19
|
+
content.appendChild(title);
|
|
20
|
+
const description = document.createElement("p");
|
|
21
|
+
description.textContent = "View and develop your components in isolation.";
|
|
22
|
+
description.style.marginTop = "0";
|
|
23
|
+
description.style.marginBottom = "1rem";
|
|
24
|
+
description.style.fontSize = "0.85rem";
|
|
25
|
+
description.style.opacity = "0.8";
|
|
26
|
+
content.appendChild(description);
|
|
27
|
+
const openButton = document.createElement("astro-dev-toolbar-button");
|
|
28
|
+
openButton.setAttribute("button-style", "purple");
|
|
29
|
+
openButton.innerHTML = `
|
|
30
|
+
<span style="display: flex; align-items: center; gap: 0.5rem;">
|
|
31
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
32
|
+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
|
|
33
|
+
<polyline points="15,3 21,3 21,9"/>
|
|
34
|
+
<line x1="10" y1="14" x2="21" y2="3"/>
|
|
35
|
+
</svg>
|
|
36
|
+
Open Storybook
|
|
37
|
+
</span>
|
|
38
|
+
`;
|
|
39
|
+
openButton.addEventListener("click", () => {
|
|
40
|
+
window.open(storybookUrl, "_blank");
|
|
41
|
+
});
|
|
42
|
+
content.appendChild(openButton);
|
|
43
|
+
const statusContainer = document.createElement("div");
|
|
44
|
+
statusContainer.style.marginTop = "1rem";
|
|
45
|
+
statusContainer.style.fontSize = "0.75rem";
|
|
46
|
+
statusContainer.style.display = "flex";
|
|
47
|
+
statusContainer.style.alignItems = "center";
|
|
48
|
+
statusContainer.style.gap = "0.5rem";
|
|
49
|
+
const statusDot = document.createElement("span");
|
|
50
|
+
statusDot.style.width = "8px";
|
|
51
|
+
statusDot.style.height = "8px";
|
|
52
|
+
statusDot.style.borderRadius = "50%";
|
|
53
|
+
statusDot.style.backgroundColor = "#888";
|
|
54
|
+
const statusText = document.createElement("span");
|
|
55
|
+
statusText.textContent = "Checking...";
|
|
56
|
+
statusText.style.opacity = "0.7";
|
|
57
|
+
statusContainer.appendChild(statusDot);
|
|
58
|
+
statusContainer.appendChild(statusText);
|
|
59
|
+
content.appendChild(statusContainer);
|
|
60
|
+
container.appendChild(content);
|
|
61
|
+
canvas.appendChild(container);
|
|
62
|
+
checkStorybookStatus(storybookUrl, statusDot, statusText);
|
|
63
|
+
}).catch(() => {
|
|
64
|
+
const container = document.createElement("astro-dev-toolbar-window");
|
|
65
|
+
const content = document.createElement("div");
|
|
66
|
+
content.style.padding = "1rem";
|
|
67
|
+
content.innerHTML = `
|
|
68
|
+
<h2 style="margin: 0 0 0.5rem 0; font-size: 1.1rem;">Storybook</h2>
|
|
69
|
+
<p style="margin: 0; font-size: 0.85rem; opacity: 0.8;">
|
|
70
|
+
Run <code style="background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px;">npm run storybook</code> to start Storybook.
|
|
71
|
+
</p>
|
|
72
|
+
`;
|
|
73
|
+
container.appendChild(content);
|
|
74
|
+
canvas.appendChild(container);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
async function checkStorybookStatus(url, dot, text) {
|
|
79
|
+
try {
|
|
80
|
+
await fetch(url, { mode: "no-cors" });
|
|
81
|
+
dot.style.backgroundColor = "#4ade80";
|
|
82
|
+
text.textContent = `Running at ${url}`;
|
|
83
|
+
} catch {
|
|
84
|
+
dot.style.backgroundColor = "#f87171";
|
|
85
|
+
text.textContent = "Not running";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = toolbar_app_default;
|
|
90
|
+
//# sourceMappingURL=toolbar-app.cjs.map
|
|
91
|
+
//# sourceMappingURL=toolbar-app.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integration/toolbar-app.ts"],"names":["defineToolbarApp"],"mappings":";;;;;AAQA,IAAO,sBAAQA,wBAAA,CAAiB;AAAA,EAC9B,KAAK,MAAA,EAAQ;AAEX,IAAA,KAAA,CAAM,qBAAqB,EACxB,IAAA,CAAK,CAAA,GAAA,KAAO,IAAI,IAAA,EAAM,CAAA,CACtB,IAAA,CAAK,CAAA,MAAA,KAAU;AACd,MAAA,MAAM,eAAe,CAAA,OAAA,EAAU,MAAA,CAAO,IAAI,CAAA,CAAA,EAAI,OAAO,IAAI,CAAA,CAAA;AAGzD,MAAA,MAAM,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,0BAA0B,CAAA;AAEnE,MAAA,MAAM,OAAA,GAAU,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC5C,MAAA,OAAA,CAAQ,MAAM,OAAA,GAAU,MAAA;AAExB,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,aAAA,CAAc,IAAI,CAAA;AACzC,MAAA,KAAA,CAAM,WAAA,GAAc,WAAA;AACpB,MAAA,KAAA,CAAM,MAAM,SAAA,GAAY,GAAA;AACxB,MAAA,KAAA,CAAM,MAAM,YAAA,GAAe,QAAA;AAC3B,MAAA,KAAA,CAAM,MAAM,QAAA,GAAW,QAAA;AACvB,MAAA,KAAA,CAAM,MAAM,UAAA,GAAa,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,IAAA,IAAA,CAAK,WAAA,GAAc,cAAc,GAAG,CAAA,CAAA;AAAA,EACtC,CAAA,CAAA,MAAQ;AACN,IAAA,GAAA,CAAI,MAAM,eAAA,GAAkB,SAAA;AAC5B,IAAA,IAAA,CAAK,WAAA,GAAc,aAAA;AAAA,EACrB;AACF","file":"toolbar-app.cjs","sourcesContent":["/**\n * Storybook Dev Toolbar App\n * \n * Shows a Storybook icon in the Astro dev toolbar that opens Storybook when clicked.\n */\n\nimport { defineToolbarApp } from 'astro/toolbar';\n\nexport default defineToolbarApp({\n init(canvas) {\n // Fetch Storybook config\n fetch('/__storybook-config')\n .then(res => res.json())\n .then(config => {\n const storybookUrl = `http://${config.host}:${config.port}`;\n \n // Create the UI\n const container = document.createElement('astro-dev-toolbar-window');\n \n const content = document.createElement('div');\n content.style.padding = '1rem';\n \n const title = document.createElement('h2');\n title.textContent = 'Storybook';\n title.style.marginTop = '0';\n title.style.marginBottom = '0.5rem';\n title.style.fontSize = '1.1rem';\n title.style.fontWeight = '600';\n content.appendChild(title);\n \n const description = document.createElement('p');\n description.textContent = 'View and develop your components in isolation.';\n description.style.marginTop = '0';\n description.style.marginBottom = '1rem';\n description.style.fontSize = '0.85rem';\n description.style.opacity = '0.8';\n content.appendChild(description);\n \n // Open Storybook button using astro-dev-toolbar-button\n const openButton = document.createElement('astro-dev-toolbar-button');\n openButton.setAttribute('button-style', 'purple');\n openButton.innerHTML = `\n <span style=\"display: flex; align-items: center; gap: 0.5rem;\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6\"/>\n <polyline points=\"15,3 21,3 21,9\"/>\n <line x1=\"10\" y1=\"14\" x2=\"21\" y2=\"3\"/>\n </svg>\n Open Storybook\n </span>\n `;\n openButton.addEventListener('click', () => {\n window.open(storybookUrl, '_blank');\n });\n content.appendChild(openButton);\n \n // Status indicator\n const statusContainer = document.createElement('div');\n statusContainer.style.marginTop = '1rem';\n statusContainer.style.fontSize = '0.75rem';\n statusContainer.style.display = 'flex';\n statusContainer.style.alignItems = 'center';\n statusContainer.style.gap = '0.5rem';\n \n const statusDot = document.createElement('span');\n statusDot.style.width = '8px';\n statusDot.style.height = '8px';\n statusDot.style.borderRadius = '50%';\n statusDot.style.backgroundColor = '#888';\n \n const statusText = document.createElement('span');\n statusText.textContent = 'Checking...';\n statusText.style.opacity = '0.7';\n \n statusContainer.appendChild(statusDot);\n statusContainer.appendChild(statusText);\n content.appendChild(statusContainer);\n \n container.appendChild(content);\n canvas.appendChild(container);\n \n // Check if Storybook is running\n checkStorybookStatus(storybookUrl, statusDot, statusText);\n })\n .catch(() => {\n // Fallback if config fetch fails\n const container = document.createElement('astro-dev-toolbar-window');\n const content = document.createElement('div');\n content.style.padding = '1rem';\n content.innerHTML = `\n <h2 style=\"margin: 0 0 0.5rem 0; font-size: 1.1rem;\">Storybook</h2>\n <p style=\"margin: 0; font-size: 0.85rem; opacity: 0.8;\">\n Run <code style=\"background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px;\">npm run storybook</code> to start Storybook.\n </p>\n `;\n container.appendChild(content);\n canvas.appendChild(container);\n });\n },\n});\n\n/**\n * Check if Storybook is running and update the status indicator\n */\nasync function checkStorybookStatus(\n url: string, \n dot: HTMLElement, \n text: HTMLElement\n): Promise<void> {\n try {\n await fetch(url, { mode: 'no-cors' });\n // no-cors mode doesn't give us status, but if it doesn't throw, something is there\n dot.style.backgroundColor = '#4ade80';\n text.textContent = `Running at ${url}`;\n } catch {\n dot.style.backgroundColor = '#f87171';\n text.textContent = 'Not running';\n }\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { defineToolbarApp } from 'astro/toolbar';
|
|
2
|
+
|
|
3
|
+
// src/integration/toolbar-app.ts
|
|
4
|
+
var toolbar_app_default = defineToolbarApp({
|
|
5
|
+
init(canvas) {
|
|
6
|
+
fetch("/__storybook-config").then((res) => res.json()).then((config) => {
|
|
7
|
+
const storybookUrl = `http://${config.host}:${config.port}`;
|
|
8
|
+
const container = document.createElement("astro-dev-toolbar-window");
|
|
9
|
+
const content = document.createElement("div");
|
|
10
|
+
content.style.padding = "1rem";
|
|
11
|
+
const title = document.createElement("h2");
|
|
12
|
+
title.textContent = "Storybook";
|
|
13
|
+
title.style.marginTop = "0";
|
|
14
|
+
title.style.marginBottom = "0.5rem";
|
|
15
|
+
title.style.fontSize = "1.1rem";
|
|
16
|
+
title.style.fontWeight = "600";
|
|
17
|
+
content.appendChild(title);
|
|
18
|
+
const description = document.createElement("p");
|
|
19
|
+
description.textContent = "View and develop your components in isolation.";
|
|
20
|
+
description.style.marginTop = "0";
|
|
21
|
+
description.style.marginBottom = "1rem";
|
|
22
|
+
description.style.fontSize = "0.85rem";
|
|
23
|
+
description.style.opacity = "0.8";
|
|
24
|
+
content.appendChild(description);
|
|
25
|
+
const openButton = document.createElement("astro-dev-toolbar-button");
|
|
26
|
+
openButton.setAttribute("button-style", "purple");
|
|
27
|
+
openButton.innerHTML = `
|
|
28
|
+
<span style="display: flex; align-items: center; gap: 0.5rem;">
|
|
29
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
30
|
+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
|
|
31
|
+
<polyline points="15,3 21,3 21,9"/>
|
|
32
|
+
<line x1="10" y1="14" x2="21" y2="3"/>
|
|
33
|
+
</svg>
|
|
34
|
+
Open Storybook
|
|
35
|
+
</span>
|
|
36
|
+
`;
|
|
37
|
+
openButton.addEventListener("click", () => {
|
|
38
|
+
window.open(storybookUrl, "_blank");
|
|
39
|
+
});
|
|
40
|
+
content.appendChild(openButton);
|
|
41
|
+
const statusContainer = document.createElement("div");
|
|
42
|
+
statusContainer.style.marginTop = "1rem";
|
|
43
|
+
statusContainer.style.fontSize = "0.75rem";
|
|
44
|
+
statusContainer.style.display = "flex";
|
|
45
|
+
statusContainer.style.alignItems = "center";
|
|
46
|
+
statusContainer.style.gap = "0.5rem";
|
|
47
|
+
const statusDot = document.createElement("span");
|
|
48
|
+
statusDot.style.width = "8px";
|
|
49
|
+
statusDot.style.height = "8px";
|
|
50
|
+
statusDot.style.borderRadius = "50%";
|
|
51
|
+
statusDot.style.backgroundColor = "#888";
|
|
52
|
+
const statusText = document.createElement("span");
|
|
53
|
+
statusText.textContent = "Checking...";
|
|
54
|
+
statusText.style.opacity = "0.7";
|
|
55
|
+
statusContainer.appendChild(statusDot);
|
|
56
|
+
statusContainer.appendChild(statusText);
|
|
57
|
+
content.appendChild(statusContainer);
|
|
58
|
+
container.appendChild(content);
|
|
59
|
+
canvas.appendChild(container);
|
|
60
|
+
checkStorybookStatus(storybookUrl, statusDot, statusText);
|
|
61
|
+
}).catch(() => {
|
|
62
|
+
const container = document.createElement("astro-dev-toolbar-window");
|
|
63
|
+
const content = document.createElement("div");
|
|
64
|
+
content.style.padding = "1rem";
|
|
65
|
+
content.innerHTML = `
|
|
66
|
+
<h2 style="margin: 0 0 0.5rem 0; font-size: 1.1rem;">Storybook</h2>
|
|
67
|
+
<p style="margin: 0; font-size: 0.85rem; opacity: 0.8;">
|
|
68
|
+
Run <code style="background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px;">npm run storybook</code> to start Storybook.
|
|
69
|
+
</p>
|
|
70
|
+
`;
|
|
71
|
+
container.appendChild(content);
|
|
72
|
+
canvas.appendChild(container);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
async function checkStorybookStatus(url, dot, text) {
|
|
77
|
+
try {
|
|
78
|
+
await fetch(url, { mode: "no-cors" });
|
|
79
|
+
dot.style.backgroundColor = "#4ade80";
|
|
80
|
+
text.textContent = `Running at ${url}`;
|
|
81
|
+
} catch {
|
|
82
|
+
dot.style.backgroundColor = "#f87171";
|
|
83
|
+
text.textContent = "Not running";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { toolbar_app_default as default };
|
|
88
|
+
//# sourceMappingURL=toolbar-app.js.map
|
|
89
|
+
//# sourceMappingURL=toolbar-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integration/toolbar-app.ts"],"names":[],"mappings":";;;AAQA,IAAO,sBAAQ,gBAAA,CAAiB;AAAA,EAC9B,KAAK,MAAA,EAAQ;AAEX,IAAA,KAAA,CAAM,qBAAqB,EACxB,IAAA,CAAK,CAAA,GAAA,KAAO,IAAI,IAAA,EAAM,CAAA,CACtB,IAAA,CAAK,CAAA,MAAA,KAAU;AACd,MAAA,MAAM,eAAe,CAAA,OAAA,EAAU,MAAA,CAAO,IAAI,CAAA,CAAA,EAAI,OAAO,IAAI,CAAA,CAAA;AAGzD,MAAA,MAAM,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,0BAA0B,CAAA;AAEnE,MAAA,MAAM,OAAA,GAAU,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC5C,MAAA,OAAA,CAAQ,MAAM,OAAA,GAAU,MAAA;AAExB,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,aAAA,CAAc,IAAI,CAAA;AACzC,MAAA,KAAA,CAAM,WAAA,GAAc,WAAA;AACpB,MAAA,KAAA,CAAM,MAAM,SAAA,GAAY,GAAA;AACxB,MAAA,KAAA,CAAM,MAAM,YAAA,GAAe,QAAA;AAC3B,MAAA,KAAA,CAAM,MAAM,QAAA,GAAW,QAAA;AACvB,MAAA,KAAA,CAAM,MAAM,UAAA,GAAa,KAAA;AACzB,MAAA,OAAA,CAAQ,YAAY,KAAK,CAAA;AAEzB,MAAA,MAAM,WAAA,GAAc,QAAA,CAAS,aAAA,CAAc,GAAG,CAAA;AAC9C,MAAA,WAAA,CAAY,WAAA,GAAc,gDAAA;AAC1B,MAAA,WAAA,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AA,EACrB;AACF","file":"toolbar-app.js","sourcesContent":["/**\n * Storybook Dev Toolbar App\n * \n * Shows a Storybook icon in the Astro dev toolbar that opens Storybook when clicked.\n */\n\nimport { defineToolbarApp } from 'astro/toolbar';\n\nexport default defineToolbarApp({\n init(canvas) {\n // Fetch Storybook config\n fetch('/__storybook-config')\n .then(res => res.json())\n .then(config => {\n const storybookUrl = `http://${config.host}:${config.port}`;\n \n // Create the UI\n const container = document.createElement('astro-dev-toolbar-window');\n \n const content = document.createElement('div');\n content.style.padding = '1rem';\n \n const title = document.createElement('h2');\n title.textContent = 'Storybook';\n title.style.marginTop = '0';\n title.style.marginBottom = '0.5rem';\n title.style.fontSize = '1.1rem';\n title.style.fontWeight = '600';\n content.appendChild(title);\n \n const description = document.createElement('p');\n description.textContent = 'View and develop your components in isolation.';\n description.style.marginTop = '0';\n description.style.marginBottom = '1rem';\n description.style.fontSize = '0.85rem';\n description.style.opacity = '0.8';\n content.appendChild(description);\n \n // Open Storybook button using astro-dev-toolbar-button\n const openButton = document.createElement('astro-dev-toolbar-button');\n openButton.setAttribute('button-style', 'purple');\n openButton.innerHTML = `\n <span style=\"display: flex; align-items: center; gap: 0.5rem;\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6\"/>\n <polyline points=\"15,3 21,3 21,9\"/>\n <line x1=\"10\" y1=\"14\" x2=\"21\" y2=\"3\"/>\n </svg>\n Open Storybook\n </span>\n `;\n openButton.addEventListener('click', () => {\n window.open(storybookUrl, '_blank');\n });\n content.appendChild(openButton);\n \n // Status indicator\n const statusContainer = document.createElement('div');\n statusContainer.style.marginTop = '1rem';\n statusContainer.style.fontSize = '0.75rem';\n statusContainer.style.display = 'flex';\n statusContainer.style.alignItems = 'center';\n statusContainer.style.gap = '0.5rem';\n \n const statusDot = document.createElement('span');\n statusDot.style.width = '8px';\n statusDot.style.height = '8px';\n statusDot.style.borderRadius = '50%';\n statusDot.style.backgroundColor = '#888';\n \n const statusText = document.createElement('span');\n statusText.textContent = 'Checking...';\n statusText.style.opacity = '0.7';\n \n statusContainer.appendChild(statusDot);\n statusContainer.appendChild(statusText);\n content.appendChild(statusContainer);\n \n container.appendChild(content);\n canvas.appendChild(container);\n \n // Check if Storybook is running\n checkStorybookStatus(storybookUrl, statusDot, statusText);\n })\n .catch(() => {\n // Fallback if config fetch fails\n const container = document.createElement('astro-dev-toolbar-window');\n const content = document.createElement('div');\n content.style.padding = '1rem';\n content.innerHTML = `\n <h2 style=\"margin: 0 0 0.5rem 0; font-size: 1.1rem;\">Storybook</h2>\n <p style=\"margin: 0; font-size: 0.85rem; opacity: 0.8;\">\n Run <code style=\"background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px;\">npm run storybook</code> to start Storybook.\n </p>\n `;\n container.appendChild(content);\n canvas.appendChild(container);\n });\n },\n});\n\n/**\n * Check if Storybook is running and update the status indicator\n */\nasync function checkStorybookStatus(\n url: string, \n dot: HTMLElement, \n text: HTMLElement\n): Promise<void> {\n try {\n await fetch(url, { mode: 'no-cors' });\n // no-cors mode doesn't give us status, but if it doesn't throw, something is there\n dot.style.backgroundColor = '#4ade80';\n text.textContent = `Running at ${url}`;\n } catch {\n dot.style.backgroundColor = '#f87171';\n text.textContent = 'Not running';\n }\n}\n"]}
|
package/dist/preset.cjs
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var url = require('url');
|
|
7
|
+
var module$1 = require('module');
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __esm = (fn, res) => function __init() {
|
|
13
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/framework/vite-plugins.ts
|
|
21
|
+
var vite_plugins_exports = {};
|
|
22
|
+
__export(vite_plugins_exports, {
|
|
23
|
+
createAstroVitePlugins: () => createAstroVitePlugins
|
|
24
|
+
});
|
|
25
|
+
async function createAstroVitePlugins(options) {
|
|
26
|
+
process.env.VITEST = "true";
|
|
27
|
+
const astroViteConfig = await getAstroViteConfig();
|
|
28
|
+
const astroPlugins = extractAstroPlugins(astroViteConfig);
|
|
29
|
+
return [
|
|
30
|
+
...astroPlugins,
|
|
31
|
+
astroContainerPlugin(),
|
|
32
|
+
astroStylesPlugin(options.stylesheets || []),
|
|
33
|
+
astroScriptsPlugin(options.scripts || []),
|
|
34
|
+
astroComponentMarkerPlugin()
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
async function getAstroViteConfig() {
|
|
38
|
+
if (cachedAstroViteConfig) {
|
|
39
|
+
return cachedAstroViteConfig;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const { getViteConfig } = await import('astro/config');
|
|
43
|
+
const configFn = getViteConfig({}, {
|
|
44
|
+
// Minimal inline Astro config - will use astro.config.mjs from project
|
|
45
|
+
});
|
|
46
|
+
cachedAstroViteConfig = await configFn({
|
|
47
|
+
mode: "development",
|
|
48
|
+
command: "serve"
|
|
49
|
+
});
|
|
50
|
+
return cachedAstroViteConfig;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn("[storybook-astro] Could not load Astro Vite config:", error);
|
|
53
|
+
return { plugins: [] };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function extractAstroPlugins(config) {
|
|
57
|
+
if (!config.plugins) return [];
|
|
58
|
+
const flatPlugins = [];
|
|
59
|
+
const flatten = (arr) => {
|
|
60
|
+
for (const item of arr) {
|
|
61
|
+
if (Array.isArray(item)) {
|
|
62
|
+
flatten(item);
|
|
63
|
+
} else if (item) {
|
|
64
|
+
flatPlugins.push(item);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
flatten(config.plugins);
|
|
69
|
+
const essentialPlugins = [
|
|
70
|
+
"astro:build",
|
|
71
|
+
"astro:build:normal",
|
|
72
|
+
"astro:config-alias",
|
|
73
|
+
"astro:load-fallback",
|
|
74
|
+
"astro:postprocess",
|
|
75
|
+
"astro:markdown",
|
|
76
|
+
"astro:html",
|
|
77
|
+
"astro:scripts",
|
|
78
|
+
"astro:assets",
|
|
79
|
+
"astro:head",
|
|
80
|
+
"astro:container"
|
|
81
|
+
];
|
|
82
|
+
return flatPlugins.filter((p) => {
|
|
83
|
+
if (!p || typeof p !== "object") return false;
|
|
84
|
+
const name = "name" in p ? String(p.name) : "";
|
|
85
|
+
return essentialPlugins.some((essential) => name.startsWith(essential) || name === essential);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function astroContainerPlugin() {
|
|
89
|
+
let viteServer;
|
|
90
|
+
return {
|
|
91
|
+
name: "storybook-astro:container",
|
|
92
|
+
configureServer(server) {
|
|
93
|
+
viteServer = server;
|
|
94
|
+
server.ws.on("astro:render:request", async (data, client) => {
|
|
95
|
+
try {
|
|
96
|
+
const html = await renderAstroComponent(data, viteServer);
|
|
97
|
+
const response = {
|
|
98
|
+
id: data.id,
|
|
99
|
+
html
|
|
100
|
+
};
|
|
101
|
+
client.send("astro:render:response", response);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
104
|
+
console.error("[storybook-astro] Render error:", errorMessage);
|
|
105
|
+
const response = {
|
|
106
|
+
id: data.id,
|
|
107
|
+
html: `<div style="color: #dc2626; background: #fef2f2; padding: 16px; border-radius: 8px; font-family: system-ui;">
|
|
108
|
+
<strong>Render Error</strong>
|
|
109
|
+
<pre style="margin: 8px 0 0; white-space: pre-wrap;">${escapeHtml(errorMessage)}</pre>
|
|
110
|
+
</div>`,
|
|
111
|
+
error: errorMessage
|
|
112
|
+
};
|
|
113
|
+
client.send("astro:render:response", response);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function renderAstroComponent(data, server) {
|
|
120
|
+
const { experimental_AstroContainer: AstroContainer } = await import('astro/container');
|
|
121
|
+
const container = await AstroContainer.create({
|
|
122
|
+
// Resolve module paths for client-side scripts
|
|
123
|
+
resolve: async (specifier) => {
|
|
124
|
+
if (specifier.startsWith("astro:scripts")) {
|
|
125
|
+
return `/@id/${specifier}`;
|
|
126
|
+
}
|
|
127
|
+
return specifier;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const componentModule = await server.ssrLoadModule(data.component);
|
|
131
|
+
const Component = componentModule.default;
|
|
132
|
+
if (!Component) {
|
|
133
|
+
throw new Error(`Component not found: ${data.component}`);
|
|
134
|
+
}
|
|
135
|
+
const html = await container.renderToString(Component, {
|
|
136
|
+
props: data.args || {},
|
|
137
|
+
slots: data.slots || {}
|
|
138
|
+
});
|
|
139
|
+
return html;
|
|
140
|
+
}
|
|
141
|
+
function astroStylesPlugin(stylesheets) {
|
|
142
|
+
const virtualModuleId = "virtual:astro-storybook/styles";
|
|
143
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
144
|
+
return {
|
|
145
|
+
name: "storybook-astro:styles",
|
|
146
|
+
resolveId(id) {
|
|
147
|
+
if (id === virtualModuleId) {
|
|
148
|
+
return resolvedVirtualModuleId;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
load(id) {
|
|
152
|
+
if (id === resolvedVirtualModuleId) {
|
|
153
|
+
const normalized = stylesheets.map((s) => normalizeAssetPath(s));
|
|
154
|
+
return `export const stylesheets = ${JSON.stringify(normalized)};`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function astroScriptsPlugin(scripts) {
|
|
160
|
+
const virtualModuleId = "virtual:astro-storybook/scripts";
|
|
161
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
162
|
+
return {
|
|
163
|
+
name: "storybook-astro:scripts",
|
|
164
|
+
resolveId(id) {
|
|
165
|
+
if (id === virtualModuleId) {
|
|
166
|
+
return resolvedVirtualModuleId;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
load(id) {
|
|
170
|
+
if (id === resolvedVirtualModuleId) {
|
|
171
|
+
const normalized = scripts.map((s) => normalizeAssetPath(s));
|
|
172
|
+
return `export const scripts = ${JSON.stringify(normalized)};`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function astroComponentMarkerPlugin() {
|
|
178
|
+
return {
|
|
179
|
+
name: "storybook-astro:component-marker",
|
|
180
|
+
enforce: "post",
|
|
181
|
+
transform(code, id) {
|
|
182
|
+
if (!id.endsWith(".astro") && !id.includes(".astro?")) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
if (code.includes("export default") || code.includes("export { $$Component as default }")) {
|
|
186
|
+
const moduleIdLine = `
|
|
187
|
+
;(function() {
|
|
188
|
+
if (typeof $$Component !== 'undefined') {
|
|
189
|
+
$$Component.isAstroComponentFactory = true;
|
|
190
|
+
$$Component.moduleId = ${JSON.stringify(id.split("?")[0])};
|
|
191
|
+
}
|
|
192
|
+
})();
|
|
193
|
+
`;
|
|
194
|
+
return {
|
|
195
|
+
code: code + moduleIdLine,
|
|
196
|
+
map: null
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
},
|
|
201
|
+
// Handle HMR for Astro components
|
|
202
|
+
handleHotUpdate({ file, server }) {
|
|
203
|
+
if (file.endsWith(".astro")) {
|
|
204
|
+
server.ws.send({
|
|
205
|
+
type: "custom",
|
|
206
|
+
event: "astro:component:update",
|
|
207
|
+
data: { file }
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function normalizeAssetPath(path) {
|
|
214
|
+
if (/^https?:\/\//.test(path)) {
|
|
215
|
+
return path;
|
|
216
|
+
}
|
|
217
|
+
path = path.replace(/^\.\//, "");
|
|
218
|
+
if (!path.startsWith("/")) {
|
|
219
|
+
path = "/" + path;
|
|
220
|
+
}
|
|
221
|
+
return path;
|
|
222
|
+
}
|
|
223
|
+
function escapeHtml(text) {
|
|
224
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
225
|
+
}
|
|
226
|
+
var cachedAstroViteConfig;
|
|
227
|
+
var init_vite_plugins = __esm({
|
|
228
|
+
"src/framework/vite-plugins.ts"() {
|
|
229
|
+
cachedAstroViteConfig = null;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
var __dirname$1 = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('preset.cjs', document.baseURI).href))));
|
|
233
|
+
var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('preset.cjs', document.baseURI).href)));
|
|
234
|
+
function getAbsolutePath(input) {
|
|
235
|
+
return path.dirname(require2.resolve(path.join(input, "package.json")));
|
|
236
|
+
}
|
|
237
|
+
var core = {
|
|
238
|
+
builder: getAbsolutePath("@storybook/builder-vite"),
|
|
239
|
+
renderer: path.join(__dirname$1, "renderer")
|
|
240
|
+
};
|
|
241
|
+
var frameworkName = "storybook-astro";
|
|
242
|
+
var previewAnnotations = async (input = []) => {
|
|
243
|
+
return [
|
|
244
|
+
...input,
|
|
245
|
+
path.join(__dirname$1, "renderer", "entry-preview.js")
|
|
246
|
+
];
|
|
247
|
+
};
|
|
248
|
+
async function viteFinal(config, { presets }) {
|
|
249
|
+
const frameworkOptions = await presets.apply("frameworkOptions");
|
|
250
|
+
const { createAstroVitePlugins: createAstroVitePlugins2 } = await Promise.resolve().then(() => (init_vite_plugins(), vite_plugins_exports));
|
|
251
|
+
const astroPlugins = await createAstroVitePlugins2(frameworkOptions || {});
|
|
252
|
+
const existingPlugins = config.plugins || [];
|
|
253
|
+
const existingOptimizeDeps = config.optimizeDeps || {};
|
|
254
|
+
const existingSsr = config.ssr || {};
|
|
255
|
+
return {
|
|
256
|
+
...config,
|
|
257
|
+
plugins: [...existingPlugins, ...astroPlugins],
|
|
258
|
+
optimizeDeps: {
|
|
259
|
+
...existingOptimizeDeps,
|
|
260
|
+
include: [
|
|
261
|
+
...existingOptimizeDeps.include || [],
|
|
262
|
+
// Pre-bundle CJS modules that Astro depends on
|
|
263
|
+
"cssesc",
|
|
264
|
+
"string-width"
|
|
265
|
+
],
|
|
266
|
+
exclude: [
|
|
267
|
+
...existingOptimizeDeps.exclude || [],
|
|
268
|
+
"astro",
|
|
269
|
+
"astro/container"
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
ssr: {
|
|
273
|
+
...existingSsr,
|
|
274
|
+
noExternal: [
|
|
275
|
+
...Array.isArray(existingSsr.noExternal) ? existingSsr.noExternal : [],
|
|
276
|
+
"storybook-astro"
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
var preset_default = {
|
|
282
|
+
core,
|
|
283
|
+
viteFinal,
|
|
284
|
+
frameworkName,
|
|
285
|
+
previewAnnotations
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
exports.core = core;
|
|
289
|
+
exports.default = preset_default;
|
|
290
|
+
exports.frameworkName = frameworkName;
|
|
291
|
+
exports.previewAnnotations = previewAnnotations;
|
|
292
|
+
exports.viteFinal = viteFinal;
|
|
293
|
+
//# sourceMappingURL=preset.cjs.map
|
|
294
|
+
//# sourceMappingURL=preset.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/framework/vite-plugins.ts","../src/preset.ts"],"names":["__dirname","dirname","fileURLToPath","require","createRequire","join","createAstroVitePlugins"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAA,oBAAA,GAAA,EAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,sBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAkBA,eAAsB,uBAAuB,OAAA,EAA8C;AAIzF,EAAA,OAAA,CAAQ,IAAI,MAAA,GAAS,MAAA;AAGrB,EAAA,MAAM,eAAA,GAAkB,MAAM,kBAAA,EAAmB;AAGjD,EAAA,MAAM,YAAA,GAAe,oBAAoB,eAAe,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,GAAG,YAAA;AAAA,IACH,oBAAA,EAAqB;AAAA,IACrB,iBAAA,CAAkB,OAAA,CAAQ,WAAA,IAAe,EAAE,CAAA;AAAA,IAC3C,kBAAA,CAAmB,OAAA,CAAQ,OAAA,IAAW,EAAE,CAAA;AAAA,IACxC,0BAAA;AAA2B,GAC7B;AACF;AAKA,eAAe,kBAAA,GAA4C;AACzD,EAAA,IAAI,qBAAA,EAAuB;AACzB,IAAA,OAAO,qBAAA;AAAA,EACT;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,aAAA,EAAc,GAAI,MAAM,OAAO,cAAc,CAAA;AAGrD,IAAA,MAAM,QAAA,GAAW,aAAA,CAAc,EAAC,EAAG;AAAA;AAAA,KAElC,CAAA;AAED,IAAA,qBAAA,GAAwB,MAAM,QAAA,CAAS;AAAA,MACrC,IAAA,EAAM,aAAA;AAAA,MACN,OAAA,EAAS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A,MACZ,GAAG,oBAAA;AAAA,MACH,OAAA,EAAS;AAAA,QACP,GAAI,oBAAA,CAAqB,OAAA,IAAW,EAAC;AAAA;AAAA,QAErC,QAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,OAAA,EAAS;AAAA,QACP,GAAI,oBAAA,CAAqB,OAAA,IAAW,EAAC;AAAA,QACrC,OAAA;AAAA,QACA;AAAA;AACF,KACF;AAAA,IACA,GAAA,EAAK;AAAA,MACH,GAAG,WAAA;AAAA,MACH,UAAA,EAAY;AAAA,QACV,GAAI,MAAM,OAAA,CAAQ,WAAA,CAAY,UAAU,CAAA,GAAI,WAAA,CAAY,aAAa,EAAC;AAAA,QACtE;AAAA;AACF;AACF,GACF;AACF;AAKA,IAAO,cAAA,GAAQ;AAAA,EACb,IAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF","file":"preset.cjs","sourcesContent":["/**\n * Vite plugins for Astro Storybook integration\n * \n * Creates the necessary Vite plugins to:\n * 1. Handle Astro component imports via Astro's Vite plugin\n * 2. Set up WebSocket communication for rendering\n * 3. Inject global styles and scripts\n */\n\nimport type { Plugin, ViteDevServer, InlineConfig } from 'vite';\nimport type { FrameworkOptions, RenderRequestMessage, RenderResponseMessage } from '../types/index.js';\n\n// Cache the Astro Vite config to avoid recreating it\nlet cachedAstroViteConfig: InlineConfig | null = null;\n\n/**\n * Create all Vite plugins needed for Astro support in Storybook\n */\nexport async function createAstroVitePlugins(options: FrameworkOptions): Promise<Plugin[]> {\n // Set VITEST env to trick Astro into compiling components for client-side rendering\n // This works around the SSR check in astro:build plugin that would otherwise\n // stub out components with an error\n process.env.VITEST = 'true';\n \n // Get Astro's full Vite configuration including all plugins\n const astroViteConfig = await getAstroViteConfig();\n \n // Extract plugins from Astro's config\n const astroPlugins = extractAstroPlugins(astroViteConfig);\n \n return [\n ...astroPlugins,\n astroContainerPlugin(),\n astroStylesPlugin(options.stylesheets || []),\n astroScriptsPlugin(options.scripts || []),\n astroComponentMarkerPlugin(),\n ];\n}\n\n/**\n * Get the full Astro Vite configuration using getViteConfig\n */\nasync function getAstroViteConfig(): Promise<InlineConfig> {\n if (cachedAstroViteConfig) {\n return cachedAstroViteConfig;\n }\n \n try {\n const { getViteConfig } = await import('astro/config');\n \n // getViteConfig returns a function that takes { mode, command }\n const configFn = getViteConfig({}, {\n // Minimal inline Astro config - will use astro.config.mjs from project\n });\n \n cachedAstroViteConfig = await configFn({ \n mode: 'development', \n command: 'serve' \n });\n \n return cachedAstroViteConfig;\n } catch (error) {\n console.warn('[storybook-astro] Could not load Astro Vite config:', error);\n return { plugins: [] };\n }\n}\n\n/**\n * Extract relevant plugins from Astro's Vite configuration\n */\nfunction extractAstroPlugins(config: InlineConfig): Plugin[] {\n if (!config.plugins) return [];\n \n // Flatten nested plugin arrays - use explicit typing to avoid deep recursion\n const flatPlugins: unknown[] = [];\n const flatten = (arr: unknown[]): void => {\n for (const item of arr) {\n if (Array.isArray(item)) {\n flatten(item);\n } else if (item) {\n flatPlugins.push(item);\n }\n }\n };\n flatten(config.plugins as unknown[]);\n \n // Include plugins essential for .astro file compilation\n const essentialPlugins = [\n 'astro:build',\n 'astro:build:normal', \n 'astro:config-alias',\n 'astro:load-fallback',\n 'astro:postprocess',\n 'astro:markdown',\n 'astro:html',\n 'astro:scripts',\n 'astro:assets',\n 'astro:head',\n 'astro:container',\n ];\n \n return flatPlugins.filter((p): p is Plugin => {\n if (!p || typeof p !== 'object') return false;\n const name = 'name' in p ? String((p as { name: unknown }).name) : '';\n return essentialPlugins.some(essential => name.startsWith(essential) || name === essential);\n });\n}\n\n/**\n * Plugin that sets up the Astro Container API for server-side rendering\n * Handles WebSocket messages from the client to render components\n */\nfunction astroContainerPlugin(): Plugin {\n let viteServer: ViteDevServer;\n \n return {\n name: 'storybook-astro:container',\n \n configureServer(server) {\n viteServer = server;\n \n // Handle render requests from the client\n server.ws.on('astro:render:request', async (data: RenderRequestMessage['data'], client) => {\n try {\n const html = await renderAstroComponent(data, viteServer);\n \n const response: RenderResponseMessage['data'] = {\n id: data.id,\n html,\n };\n \n client.send('astro:render:response', response);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error';\n console.error('[storybook-astro] Render error:', errorMessage);\n \n const response: RenderResponseMessage['data'] = {\n id: data.id,\n html: `<div style=\"color: #dc2626; background: #fef2f2; padding: 16px; border-radius: 8px; font-family: system-ui;\">\n <strong>Render Error</strong>\n <pre style=\"margin: 8px 0 0; white-space: pre-wrap;\">${escapeHtml(errorMessage)}</pre>\n </div>`,\n error: errorMessage,\n };\n \n client.send('astro:render:response', response);\n }\n });\n },\n };\n}\n\n/**\n * Render an Astro component using the Container API\n */\nasync function renderAstroComponent(\n data: RenderRequestMessage['data'],\n server: ViteDevServer\n): Promise<string> {\n // Dynamic import to get fresh module on HMR\n const { experimental_AstroContainer: AstroContainer } = await import('astro/container');\n \n // Create container for rendering\n const container = await AstroContainer.create({\n // Resolve module paths for client-side scripts\n resolve: async (specifier: string) => {\n if (specifier.startsWith('astro:scripts')) {\n return `/@id/${specifier}`;\n }\n return specifier;\n },\n });\n \n // Import the component module\n const componentModule = await server.ssrLoadModule(data.component);\n const Component = componentModule.default;\n \n if (!Component) {\n throw new Error(`Component not found: ${data.component}`);\n }\n \n // Render to string\n const html = await container.renderToString(Component, {\n props: data.args || {},\n slots: data.slots || {},\n });\n \n return html;\n}\n\n/**\n * Virtual module plugin for injecting global stylesheets\n */\nfunction astroStylesPlugin(stylesheets: string[]): Plugin {\n const virtualModuleId = 'virtual:astro-storybook/styles';\n const resolvedVirtualModuleId = '\\0' + virtualModuleId;\n \n return {\n name: 'storybook-astro:styles',\n \n resolveId(id) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId;\n }\n },\n \n load(id) {\n if (id === resolvedVirtualModuleId) {\n const normalized = stylesheets.map(s => normalizeAssetPath(s));\n return `export const stylesheets = ${JSON.stringify(normalized)};`;\n }\n },\n };\n}\n\n/**\n * Virtual module plugin for injecting global scripts\n */\nfunction astroScriptsPlugin(scripts: string[]): Plugin {\n const virtualModuleId = 'virtual:astro-storybook/scripts';\n const resolvedVirtualModuleId = '\\0' + virtualModuleId;\n \n return {\n name: 'storybook-astro:scripts',\n \n resolveId(id) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId;\n }\n },\n \n load(id) {\n if (id === resolvedVirtualModuleId) {\n const normalized = scripts.map(s => normalizeAssetPath(s));\n return `export const scripts = ${JSON.stringify(normalized)};`;\n }\n },\n };\n}\n\n/**\n * Plugin to mark Astro components with their module ID for rendering\n */\nfunction astroComponentMarkerPlugin(): Plugin {\n return {\n name: 'storybook-astro:component-marker',\n enforce: 'post',\n \n transform(code, id) {\n // Only process compiled .astro files\n if (!id.endsWith('.astro') && !id.includes('.astro?')) {\n return null;\n }\n \n // Look for the default export and add moduleId\n // Astro compiles components to have a default export\n if (code.includes('export default') || code.includes('export { $$Component as default }')) {\n const moduleIdLine = `\\n;(function() { \n if (typeof $$Component !== 'undefined') { \n $$Component.isAstroComponentFactory = true;\n $$Component.moduleId = ${JSON.stringify(id.split('?')[0])}; \n }\n })();\\n`;\n \n return {\n code: code + moduleIdLine,\n map: null,\n };\n }\n \n return null;\n },\n \n // Handle HMR for Astro components\n handleHotUpdate({ file, server }) {\n if (file.endsWith('.astro')) {\n server.ws.send({\n type: 'custom',\n event: 'astro:component:update',\n data: { file },\n });\n }\n },\n };\n}\n\n/**\n * Normalize asset paths for injection\n */\nfunction normalizeAssetPath(path: string): string {\n // Keep absolute URLs as-is\n if (/^https?:\\/\\//.test(path)) {\n return path;\n }\n \n // Remove leading ./ and ensure leading /\n path = path.replace(/^\\.\\//, '');\n if (!path.startsWith('/')) {\n path = '/' + path;\n }\n \n return path;\n}\n\n/**\n * Escape HTML special characters\n */\nfunction escapeHtml(text: string): string {\n return text\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n","/**\n * Storybook Preset for Astro Framework\n * \n * This preset configures Storybook to work with Astro components by:\n * 1. Setting up the Vite builder with Astro-specific plugins\n * 2. Configuring the custom Astro renderer\n * 3. Adding middleware for server-side rendering via Container API\n */\n\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { createRequire } from 'node:module';\nimport type { FrameworkOptions } from './types/index.js';\nimport type { InlineConfig } from 'vite';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst require = createRequire(import.meta.url);\n\n/**\n * Get absolute path to a package\n */\nfunction getAbsolutePath<T extends string>(input: T): T {\n return dirname(require.resolve(join(input, 'package.json'))) as T;\n}\n\n/**\n * Core Storybook configuration\n */\nexport const core = {\n builder: getAbsolutePath('@storybook/builder-vite'),\n renderer: join(__dirname, 'renderer'),\n};\n\n/**\n * Framework name for Storybook\n */\nexport const frameworkName = 'storybook-astro' as const;\n\n/**\n * Preview annotations - tells Storybook where to find the render functions\n */\nexport const previewAnnotations = async (input: string[] = []) => {\n return [\n ...input,\n join(__dirname, 'renderer', 'entry-preview.js'),\n ];\n};\n\ninterface ViteFinalContext {\n presets: {\n apply<T>(preset: string): Promise<T>;\n };\n}\n\n/**\n * Vite configuration for Astro support\n */\nexport async function viteFinal(\n config: InlineConfig,\n { presets }: ViteFinalContext\n): Promise<InlineConfig> {\n const frameworkOptions = await presets.apply<FrameworkOptions>('frameworkOptions');\n \n // Dynamic import to avoid bundling issues\n const { createAstroVitePlugins } = await import('./framework/vite-plugins.js');\n \n const astroPlugins = await createAstroVitePlugins(frameworkOptions || {});\n \n const existingPlugins = config.plugins || [];\n const existingOptimizeDeps = config.optimizeDeps || {};\n const existingSsr = config.ssr || {};\n \n return {\n ...config,\n plugins: [...existingPlugins, ...astroPlugins],\n optimizeDeps: {\n ...existingOptimizeDeps,\n include: [\n ...(existingOptimizeDeps.include || []),\n // Pre-bundle CJS modules that Astro depends on\n 'cssesc',\n 'string-width',\n ],\n exclude: [\n ...(existingOptimizeDeps.exclude || []),\n 'astro',\n 'astro/container',\n ],\n },\n ssr: {\n ...existingSsr,\n noExternal: [\n ...(Array.isArray(existingSsr.noExternal) ? existingSsr.noExternal : []),\n 'storybook-astro',\n ],\n },\n };\n}\n\n/**\n * Default export for preset auto-detection\n */\nexport default {\n core,\n viteFinal,\n frameworkName,\n previewAnnotations,\n};\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { InlineConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Storybook Preset for Astro Framework
|
|
5
|
+
*
|
|
6
|
+
* This preset configures Storybook to work with Astro components by:
|
|
7
|
+
* 1. Setting up the Vite builder with Astro-specific plugins
|
|
8
|
+
* 2. Configuring the custom Astro renderer
|
|
9
|
+
* 3. Adding middleware for server-side rendering via Container API
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Core Storybook configuration
|
|
14
|
+
*/
|
|
15
|
+
declare const core: {
|
|
16
|
+
builder: "@storybook/builder-vite";
|
|
17
|
+
renderer: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Framework name for Storybook
|
|
21
|
+
*/
|
|
22
|
+
declare const frameworkName: "storybook-astro";
|
|
23
|
+
/**
|
|
24
|
+
* Preview annotations - tells Storybook where to find the render functions
|
|
25
|
+
*/
|
|
26
|
+
declare const previewAnnotations: (input?: string[]) => Promise<string[]>;
|
|
27
|
+
interface ViteFinalContext {
|
|
28
|
+
presets: {
|
|
29
|
+
apply<T>(preset: string): Promise<T>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Vite configuration for Astro support
|
|
34
|
+
*/
|
|
35
|
+
declare function viteFinal(config: InlineConfig, { presets }: ViteFinalContext): Promise<InlineConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* Default export for preset auto-detection
|
|
38
|
+
*/
|
|
39
|
+
declare const _default: {
|
|
40
|
+
core: {
|
|
41
|
+
builder: "@storybook/builder-vite";
|
|
42
|
+
renderer: string;
|
|
43
|
+
};
|
|
44
|
+
viteFinal: typeof viteFinal;
|
|
45
|
+
frameworkName: "storybook-astro";
|
|
46
|
+
previewAnnotations: (input?: string[]) => Promise<string[]>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { core, _default as default, frameworkName, previewAnnotations, viteFinal };
|