storybook-onbook-plugin 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/cli/index.d.ts +1 -0
  2. package/dist/cli/index.js +395 -0
  3. package/dist/index.d.ts +11 -2
  4. package/dist/index.js +453 -1
  5. package/dist/screenshot-service/index.d.ts +46 -4
  6. package/dist/screenshot-service/index.js +213 -5
  7. package/dist/screenshot-service/utils/browser/index.d.ts +12 -2
  8. package/dist/screenshot-service/utils/browser/index.js +25 -1
  9. package/package.json +28 -9
  10. package/dist/cli/generate-screenshots.d.ts +0 -3
  11. package/dist/cli/generate-screenshots.d.ts.map +0 -1
  12. package/dist/cli/generate-screenshots.js +0 -169
  13. package/dist/component-loc/component-loc.d.ts +0 -7
  14. package/dist/component-loc/component-loc.d.ts.map +0 -1
  15. package/dist/component-loc/component-loc.js +0 -58
  16. package/dist/component-loc/index.d.ts +0 -2
  17. package/dist/component-loc/index.d.ts.map +0 -1
  18. package/dist/component-loc/index.js +0 -1
  19. package/dist/handlers/handleStoryFileChange/handleStoryFileChange.d.ts +0 -3
  20. package/dist/handlers/handleStoryFileChange/handleStoryFileChange.d.ts.map +0 -1
  21. package/dist/handlers/handleStoryFileChange/handleStoryFileChange.js +0 -100
  22. package/dist/handlers/handleStoryFileChange/index.d.ts +0 -2
  23. package/dist/handlers/handleStoryFileChange/index.d.ts.map +0 -1
  24. package/dist/handlers/handleStoryFileChange/index.js +0 -1
  25. package/dist/index.d.ts.map +0 -1
  26. package/dist/screenshot-service/constants.d.ts +0 -8
  27. package/dist/screenshot-service/constants.d.ts.map +0 -1
  28. package/dist/screenshot-service/constants.js +0 -11
  29. package/dist/screenshot-service/index.d.ts.map +0 -1
  30. package/dist/screenshot-service/screenshot-service.d.ts +0 -8
  31. package/dist/screenshot-service/screenshot-service.d.ts.map +0 -1
  32. package/dist/screenshot-service/screenshot-service.js +0 -36
  33. package/dist/screenshot-service/types.d.ts +0 -18
  34. package/dist/screenshot-service/types.d.ts.map +0 -1
  35. package/dist/screenshot-service/types.js +0 -1
  36. package/dist/screenshot-service/utils/browser/browser.d.ts +0 -10
  37. package/dist/screenshot-service/utils/browser/browser.d.ts.map +0 -1
  38. package/dist/screenshot-service/utils/browser/browser.js +0 -29
  39. package/dist/screenshot-service/utils/browser/index.d.ts.map +0 -1
  40. package/dist/screenshot-service/utils/screenshot/index.d.ts +0 -2
  41. package/dist/screenshot-service/utils/screenshot/index.d.ts.map +0 -1
  42. package/dist/screenshot-service/utils/screenshot/index.js +0 -1
  43. package/dist/screenshot-service/utils/screenshot/screenshot.d.ts +0 -26
  44. package/dist/screenshot-service/utils/screenshot/screenshot.d.ts.map +0 -1
  45. package/dist/screenshot-service/utils/screenshot/screenshot.js +0 -128
  46. package/dist/storybook-onlook-plugin.d.ts +0 -9
  47. package/dist/storybook-onlook-plugin.d.ts.map +0 -1
  48. package/dist/storybook-onlook-plugin.js +0 -148
  49. package/dist/utils/fileSystem/fileSystem.d.ts +0 -9
  50. package/dist/utils/fileSystem/fileSystem.d.ts.map +0 -1
  51. package/dist/utils/fileSystem/fileSystem.js +0 -24
  52. package/dist/utils/fileSystem/index.d.ts +0 -2
  53. package/dist/utils/fileSystem/index.d.ts.map +0 -1
  54. package/dist/utils/fileSystem/index.js +0 -1
  55. package/dist/utils/findGitRoot/findGitRoot.d.ts +0 -5
  56. package/dist/utils/findGitRoot/findGitRoot.d.ts.map +0 -1
  57. package/dist/utils/findGitRoot/findGitRoot.js +0 -15
  58. package/dist/utils/findGitRoot/index.d.ts +0 -2
  59. package/dist/utils/findGitRoot/index.d.ts.map +0 -1
  60. package/dist/utils/findGitRoot/index.js +0 -1
  61. package/dist/utils/manifest/index.d.ts +0 -2
  62. package/dist/utils/manifest/index.d.ts.map +0 -1
  63. package/dist/utils/manifest/index.js +0 -1
  64. package/dist/utils/manifest/manifest.d.ts +0 -21
  65. package/dist/utils/manifest/manifest.d.ts.map +0 -1
  66. package/dist/utils/manifest/manifest.js +0 -44
package/dist/index.js CHANGED
@@ -1 +1,453 @@
1
- export { storybookOnlookPlugin, } from './storybook-onlook-plugin.js';
1
+ import fs, { existsSync } from 'fs';
2
+ import path2, { dirname, join, relative } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import generateModule from '@babel/generator';
5
+ import { parse } from '@babel/parser';
6
+ import traverseModule from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import crypto from 'crypto';
9
+ import { chromium } from 'playwright';
10
+
11
+ // src/storybook-onlook-plugin.ts
12
+ function componentLocPlugin(options = {}) {
13
+ const include = options.include ?? /\.(jsx|tsx)$/;
14
+ const traverse = traverseModule.default ?? traverseModule;
15
+ const generate = generateModule.default ?? generateModule;
16
+ let root;
17
+ return {
18
+ name: "onbook-component-loc",
19
+ enforce: "pre",
20
+ apply: "serve",
21
+ configResolved(config) {
22
+ root = config.root;
23
+ },
24
+ transform(code, id) {
25
+ const filepath = id.split("?", 1)[0];
26
+ if (!filepath || filepath.includes("node_modules")) return null;
27
+ if (!include.test(filepath)) return null;
28
+ const ast = parse(code, {
29
+ sourceType: "module",
30
+ plugins: ["jsx", "typescript"],
31
+ sourceFilename: filepath
32
+ });
33
+ let mutated = false;
34
+ const relativePath = path2.relative(root, filepath);
35
+ traverse(ast, {
36
+ JSXElement(nodePath) {
37
+ const opening = nodePath.node.openingElement;
38
+ const element = nodePath.node;
39
+ if (!opening.loc || !element.loc) return;
40
+ const alreadyTagged = opening.attributes.some(
41
+ (attribute) => t.isJSXAttribute(attribute) && attribute.name.name === "data-component-file"
42
+ );
43
+ if (alreadyTagged) return;
44
+ opening.attributes.push(
45
+ t.jsxAttribute(
46
+ t.jsxIdentifier("data-component-file"),
47
+ t.stringLiteral(relativePath)
48
+ ),
49
+ t.jsxAttribute(
50
+ t.jsxIdentifier("data-component-start"),
51
+ t.stringLiteral(`${element.loc.start.line}:${element.loc.start.column}`)
52
+ ),
53
+ t.jsxAttribute(
54
+ t.jsxIdentifier("data-component-end"),
55
+ t.stringLiteral(`${element.loc.end.line}:${element.loc.end.column}`)
56
+ )
57
+ );
58
+ mutated = true;
59
+ }
60
+ });
61
+ if (!mutated) return null;
62
+ const output = generate(
63
+ ast,
64
+ { retainLines: true, sourceMaps: true, sourceFileName: id },
65
+ code
66
+ );
67
+ return { code: output.code, map: output.map };
68
+ }
69
+ };
70
+ }
71
+ var CACHE_DIR = path2.join(process.cwd(), ".storybook-cache");
72
+ var SCREENSHOTS_DIR = path2.join(CACHE_DIR, "screenshots");
73
+ var MANIFEST_PATH = path2.join(CACHE_DIR, "manifest.json");
74
+ var VIEWPORT_WIDTH = 1920;
75
+ var VIEWPORT_HEIGHT = 1080;
76
+ var MIN_COMPONENT_WIDTH = 420;
77
+ var MIN_COMPONENT_HEIGHT = 280;
78
+
79
+ // src/utils/fileSystem/fileSystem.ts
80
+ function ensureCacheDirectories() {
81
+ if (!fs.existsSync(CACHE_DIR)) {
82
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
83
+ }
84
+ if (!fs.existsSync(SCREENSHOTS_DIR)) {
85
+ fs.mkdirSync(SCREENSHOTS_DIR, { recursive: true });
86
+ }
87
+ }
88
+ function computeFileHash(filePath) {
89
+ if (!fs.existsSync(filePath)) {
90
+ return "";
91
+ }
92
+ const content = fs.readFileSync(filePath, "utf-8");
93
+ return crypto.createHash("sha256").update(content).digest("hex");
94
+ }
95
+ function loadManifest() {
96
+ if (fs.existsSync(MANIFEST_PATH)) {
97
+ const content = fs.readFileSync(MANIFEST_PATH, "utf-8");
98
+ return JSON.parse(content);
99
+ }
100
+ return { stories: {} };
101
+ }
102
+ function saveManifest(manifest) {
103
+ ensureCacheDirectories();
104
+ fs.writeFileSync(MANIFEST_PATH, JSON.stringify(manifest, null, 2));
105
+ }
106
+ function updateManifest(storyId, sourcePath, fileHash, boundingBox) {
107
+ const manifest = loadManifest();
108
+ manifest.stories[storyId] = {
109
+ fileHash,
110
+ lastGenerated: (/* @__PURE__ */ new Date()).toISOString(),
111
+ sourcePath,
112
+ screenshots: {
113
+ light: `screenshots/${storyId}/light.png`,
114
+ dark: `screenshots/${storyId}/dark.png`
115
+ },
116
+ boundingBox: boundingBox ?? void 0
117
+ };
118
+ saveManifest(manifest);
119
+ }
120
+ var browser = null;
121
+ async function getBrowser() {
122
+ if (!browser) {
123
+ browser = await chromium.launch({
124
+ headless: true
125
+ });
126
+ }
127
+ return browser;
128
+ }
129
+ function getScreenshotPath(storyId, theme) {
130
+ const storyDir = path2.join(SCREENSHOTS_DIR, storyId);
131
+ return path2.join(storyDir, `${theme}.png`);
132
+ }
133
+ async function captureScreenshotBuffer(storyId, theme, width = VIEWPORT_WIDTH, height = VIEWPORT_HEIGHT, storybookUrl = "http://localhost:6006") {
134
+ const browser2 = await getBrowser();
135
+ const context = await browser2.newContext({
136
+ viewport: { width, height },
137
+ deviceScaleFactor: 2
138
+ });
139
+ const page = await context.newPage();
140
+ try {
141
+ const url = `${storybookUrl}/iframe.html?id=${storyId}&viewMode=story&globals=theme:${theme}`;
142
+ await page.goto(url, { timeout: 15e3 });
143
+ await page.waitForLoadState("domcontentloaded");
144
+ await page.waitForLoadState("load");
145
+ await page.waitForLoadState("networkidle");
146
+ await page.evaluate(() => document.fonts.ready);
147
+ await page.evaluate(async () => {
148
+ const images = document.querySelectorAll("img");
149
+ await Promise.all(
150
+ Array.from(images).map((img) => {
151
+ if (img.complete) return Promise.resolve();
152
+ return new Promise((resolve) => {
153
+ img.addEventListener("load", resolve);
154
+ img.addEventListener("error", resolve);
155
+ });
156
+ })
157
+ );
158
+ });
159
+ const contentBounds = await page.evaluate(() => {
160
+ const root = document.querySelector("#storybook-root");
161
+ if (!root) return null;
162
+ const children = root.querySelectorAll("*");
163
+ if (children.length === 0) return null;
164
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
165
+ children.forEach((child) => {
166
+ const rect = child.getBoundingClientRect();
167
+ if (rect.width === 0 || rect.height === 0) return;
168
+ minX = Math.min(minX, rect.left);
169
+ minY = Math.min(minY, rect.top);
170
+ maxX = Math.max(maxX, rect.right);
171
+ maxY = Math.max(maxY, rect.bottom);
172
+ });
173
+ if (minX === Infinity) return null;
174
+ return {
175
+ x: minX,
176
+ y: minY,
177
+ width: maxX - minX,
178
+ height: maxY - minY
179
+ };
180
+ });
181
+ let screenshotBuffer;
182
+ let resultBoundingBox = null;
183
+ if (contentBounds && contentBounds.width > 0 && contentBounds.height > 0) {
184
+ const PADDING = 20;
185
+ const clippedWidth = Math.min(width, contentBounds.width + PADDING);
186
+ const clippedHeight = Math.min(height, contentBounds.height + PADDING);
187
+ resultBoundingBox = {
188
+ width: Math.max(MIN_COMPONENT_WIDTH, Math.round(clippedWidth)),
189
+ height: Math.max(MIN_COMPONENT_HEIGHT, Math.round(clippedHeight))
190
+ };
191
+ screenshotBuffer = await page.screenshot({
192
+ type: "png",
193
+ clip: {
194
+ x: Math.max(0, contentBounds.x - 10),
195
+ y: Math.max(0, contentBounds.y - 10),
196
+ width: clippedWidth,
197
+ height: clippedHeight
198
+ }
199
+ });
200
+ } else {
201
+ screenshotBuffer = await page.screenshot({ type: "png" });
202
+ }
203
+ return { buffer: screenshotBuffer, boundingBox: resultBoundingBox };
204
+ } finally {
205
+ await context.close();
206
+ }
207
+ }
208
+ async function generateScreenshot(storyId, theme, storybookUrl = "http://localhost:6006") {
209
+ try {
210
+ ensureCacheDirectories();
211
+ const storyDir = path2.join(SCREENSHOTS_DIR, storyId);
212
+ if (!fs.existsSync(storyDir)) {
213
+ fs.mkdirSync(storyDir, { recursive: true });
214
+ }
215
+ const screenshotPath = getScreenshotPath(storyId, theme);
216
+ const { buffer, boundingBox } = await captureScreenshotBuffer(
217
+ storyId,
218
+ theme,
219
+ VIEWPORT_WIDTH,
220
+ VIEWPORT_HEIGHT,
221
+ storybookUrl
222
+ );
223
+ fs.writeFileSync(screenshotPath, buffer);
224
+ return { path: screenshotPath, boundingBox };
225
+ } catch (error) {
226
+ console.error(`Error generating screenshot for ${storyId} (${theme}):`, error);
227
+ return null;
228
+ }
229
+ }
230
+
231
+ // src/handlers/handleStoryFileChange/handleStoryFileChange.ts
232
+ var cachedIndex = null;
233
+ var indexFetchPromise = null;
234
+ var pendingFiles = /* @__PURE__ */ new Set();
235
+ var debounceTimer = null;
236
+ var DEBOUNCE_MS = 500;
237
+ async function fetchStorybookIndex() {
238
+ try {
239
+ const response = await fetch("http://localhost:6006/index.json");
240
+ if (response.ok) {
241
+ cachedIndex = await response.json();
242
+ console.log("[Screenshots] Cached Storybook index");
243
+ }
244
+ } catch (error) {
245
+ console.error("[Screenshots] Failed to fetch Storybook index:", error);
246
+ }
247
+ }
248
+ function getStoriesForFile(filePath) {
249
+ if (!cachedIndex) return [];
250
+ const fileName = path2.basename(filePath);
251
+ return Object.values(cachedIndex.entries).filter((entry) => entry.type === "story" && entry.importPath.endsWith(fileName)).map((entry) => entry.id);
252
+ }
253
+ async function regenerateScreenshotsForFiles(files) {
254
+ await fetchStorybookIndex();
255
+ const allStoryIds = /* @__PURE__ */ new Set();
256
+ const fileToStories = /* @__PURE__ */ new Map();
257
+ for (const file of files) {
258
+ const storyIds = getStoriesForFile(file);
259
+ fileToStories.set(file, storyIds);
260
+ for (const id of storyIds) {
261
+ allStoryIds.add(id);
262
+ }
263
+ }
264
+ if (allStoryIds.size === 0) {
265
+ console.log("[Screenshots] No stories found for changed files");
266
+ return;
267
+ }
268
+ console.log(
269
+ `[Screenshots] Regenerating ${allStoryIds.size} stories from ${files.length} files`
270
+ );
271
+ const storybookUrl = "http://localhost:6006";
272
+ const storyBoundingBoxes = /* @__PURE__ */ new Map();
273
+ await Promise.all(
274
+ Array.from(allStoryIds).map(async (storyId) => {
275
+ const [lightResult, _darkResult] = await Promise.all([
276
+ generateScreenshot(storyId, "light", storybookUrl),
277
+ generateScreenshot(storyId, "dark", storybookUrl)
278
+ ]);
279
+ if (lightResult) {
280
+ storyBoundingBoxes.set(storyId, lightResult.boundingBox);
281
+ }
282
+ })
283
+ );
284
+ for (const [file, storyIds] of fileToStories) {
285
+ const fileHash = computeFileHash(file);
286
+ storyIds.forEach((storyId) => {
287
+ updateManifest(storyId, file, fileHash, storyBoundingBoxes.get(storyId));
288
+ });
289
+ }
290
+ console.log(`[Screenshots] \u2713 Regenerated ${allStoryIds.size} stories`);
291
+ }
292
+ function handleStoryFileChange({ file, modules }) {
293
+ if (file.endsWith(".stories.tsx") || file.endsWith(".stories.ts")) {
294
+ console.log(`[Screenshots] Story file changed: ${file}`);
295
+ if (!cachedIndex && !indexFetchPromise) {
296
+ indexFetchPromise = fetchStorybookIndex();
297
+ }
298
+ pendingFiles.add(file);
299
+ if (debounceTimer) {
300
+ clearTimeout(debounceTimer);
301
+ }
302
+ debounceTimer = setTimeout(async () => {
303
+ const files = Array.from(pendingFiles);
304
+ pendingFiles.clear();
305
+ debounceTimer = null;
306
+ try {
307
+ await regenerateScreenshotsForFiles(files);
308
+ } catch (error) {
309
+ console.error("[Screenshots] Error regenerating screenshots:", error);
310
+ }
311
+ }, DEBOUNCE_MS);
312
+ return modules;
313
+ }
314
+ }
315
+ function findGitRoot(startPath) {
316
+ let currentPath = startPath;
317
+ while (currentPath !== dirname(currentPath)) {
318
+ if (existsSync(join(currentPath, ".git"))) {
319
+ return currentPath;
320
+ }
321
+ currentPath = dirname(currentPath);
322
+ }
323
+ return null;
324
+ }
325
+
326
+ // src/storybook-onlook-plugin.ts
327
+ var __dirname$1 = dirname(fileURLToPath(import.meta.url));
328
+ var storybookDir = join(__dirname$1, "..");
329
+ var gitRoot = findGitRoot(storybookDir);
330
+ var storybookLocation = gitRoot ? relative(gitRoot, storybookDir) : "";
331
+ var repoRoot = gitRoot || process.cwd();
332
+ var DEFAULT_ALLOWED_ORIGINS = [
333
+ "https://app.onlook.ai",
334
+ "http://localhost:3000",
335
+ "http://localhost:6006"
336
+ ];
337
+ var serveMetadataAndScreenshots = (req, res, next) => {
338
+ if (req.url === "/onbook-index.json") {
339
+ const manifestPath = path2.join(process.cwd(), ".storybook-cache", "manifest.json");
340
+ fetch("http://localhost:6006/index.json").then((response) => response.json()).then((indexData) => {
341
+ const manifest = fs.existsSync(manifestPath) ? JSON.parse(fs.readFileSync(manifestPath, "utf-8")) : { stories: {} };
342
+ const defaultBoundingBox = { width: 1920, height: 1080 };
343
+ for (const [storyId, entry] of Object.entries(indexData.entries || {})) {
344
+ const manifestEntry = manifest.stories?.[storyId];
345
+ entry.boundingBox = manifestEntry?.boundingBox || defaultBoundingBox;
346
+ }
347
+ indexData.meta = { storybookLocation, repoRoot };
348
+ res.setHeader("Content-Type", "application/json");
349
+ res.setHeader("Access-Control-Allow-Origin", "*");
350
+ res.end(JSON.stringify(indexData));
351
+ }).catch((error) => {
352
+ console.error("Failed to fetch/extend index.json:", error);
353
+ res.statusCode = 500;
354
+ res.setHeader("Content-Type", "application/json");
355
+ res.end(
356
+ JSON.stringify({ error: "Failed to fetch index", details: String(error) })
357
+ );
358
+ });
359
+ return;
360
+ }
361
+ if (req.url?.startsWith("/api/capture-screenshot")) {
362
+ const url = new URL(req.url, "http://localhost");
363
+ const storyId = url.searchParams.get("storyId");
364
+ const theme = url.searchParams.get("theme") || "light";
365
+ const width = parseInt(url.searchParams.get("width") || "800", 10);
366
+ const height = parseInt(url.searchParams.get("height") || "600", 10);
367
+ if (!storyId) {
368
+ res.statusCode = 400;
369
+ res.setHeader("Content-Type", "application/json");
370
+ res.end(JSON.stringify({ error: "storyId is required" }));
371
+ return;
372
+ }
373
+ if (theme !== "light" && theme !== "dark") {
374
+ res.statusCode = 400;
375
+ res.setHeader("Content-Type", "application/json");
376
+ res.end(JSON.stringify({ error: 'theme must be "light" or "dark"' }));
377
+ return;
378
+ }
379
+ captureScreenshotBuffer(storyId, theme, width, height).then(({ buffer }) => {
380
+ res.setHeader("Content-Type", "image/png");
381
+ res.setHeader("Access-Control-Allow-Origin", "*");
382
+ res.setHeader("Cache-Control", "no-cache");
383
+ res.end(buffer);
384
+ }).catch((error) => {
385
+ console.error("Screenshot capture error:", error);
386
+ res.statusCode = 500;
387
+ res.setHeader("Content-Type", "application/json");
388
+ res.end(
389
+ JSON.stringify({
390
+ error: "Failed to capture screenshot",
391
+ details: String(error)
392
+ })
393
+ );
394
+ });
395
+ return;
396
+ }
397
+ if (req.url?.startsWith("/screenshots/")) {
398
+ const screenshotPath = path2.join(
399
+ process.cwd(),
400
+ ".storybook-cache",
401
+ req.url.replace("/screenshots/", "screenshots/")
402
+ );
403
+ if (fs.existsSync(screenshotPath)) {
404
+ res.setHeader("Content-Type", "image/png");
405
+ res.setHeader("Access-Control-Allow-Origin", "*");
406
+ res.setHeader("Cache-Control", "public, max-age=3600");
407
+ fs.createReadStream(screenshotPath).pipe(res);
408
+ } else {
409
+ res.statusCode = 404;
410
+ res.end("Screenshot not found");
411
+ }
412
+ return;
413
+ }
414
+ next();
415
+ };
416
+ function storybookOnlookPlugin(options = {}) {
417
+ if (process.env.CHROMATIC || process.env.CI) {
418
+ return [];
419
+ }
420
+ const port = options.port ?? 6006;
421
+ const allowedOrigins = [...DEFAULT_ALLOWED_ORIGINS, ...options.allowedOrigins ?? []];
422
+ const mainPlugin = {
423
+ name: "storybook-onlook-plugin",
424
+ config() {
425
+ return {
426
+ server: {
427
+ // E2B sandbox HMR configuration
428
+ hmr: {
429
+ // E2B sandboxes use HTTPS, so we need secure WebSocket
430
+ protocol: "wss",
431
+ // E2B routes through standard HTTPS port 443
432
+ clientPort: 443,
433
+ // The actual Storybook server port inside the sandbox
434
+ port
435
+ },
436
+ cors: {
437
+ origin: allowedOrigins
438
+ }
439
+ }
440
+ };
441
+ },
442
+ configureServer(server) {
443
+ server.middlewares.use(serveMetadataAndScreenshots);
444
+ },
445
+ configurePreviewServer(server) {
446
+ server.middlewares.use(serveMetadataAndScreenshots);
447
+ },
448
+ handleHotUpdate: handleStoryFileChange
449
+ };
450
+ return [componentLocPlugin(), mainPlugin];
451
+ }
452
+
453
+ export { storybookOnlookPlugin };
@@ -1,5 +1,47 @@
1
- export { generateAllScreenshots } from './screenshot-service.js';
2
- export type { Manifest, ScreenshotMetadata } from './types.js';
3
1
  export { closeBrowser } from './utils/browser/index.js';
4
- export { generateScreenshot, getScreenshotPath, screenshotExists, } from './utils/screenshot/index.js';
5
- //# sourceMappingURL=index.d.ts.map
2
+ import 'playwright';
3
+
4
+ /**
5
+ * Generate screenshots for all stories (parallelized for speed)
6
+ */
7
+ declare function generateAllScreenshots(stories: Array<{
8
+ id: string;
9
+ importPath: string;
10
+ }>, storybookUrl?: string): Promise<void>;
11
+
12
+ interface BoundingBox {
13
+ width: number;
14
+ height: number;
15
+ }
16
+ interface ScreenshotMetadata {
17
+ fileHash: string;
18
+ lastGenerated: string;
19
+ sourcePath: string;
20
+ screenshots: {
21
+ light: string;
22
+ dark: string;
23
+ };
24
+ boundingBox?: BoundingBox;
25
+ }
26
+ interface Manifest {
27
+ stories: Record<string, ScreenshotMetadata>;
28
+ }
29
+
30
+ interface GenerateScreenshotResult {
31
+ path: string;
32
+ boundingBox: BoundingBox | null;
33
+ }
34
+ /**
35
+ * Get screenshot file path
36
+ */
37
+ declare function getScreenshotPath(storyId: string, theme: 'light' | 'dark'): string;
38
+ /**
39
+ * Check if screenshot exists
40
+ */
41
+ declare function screenshotExists(storyId: string, theme: 'light' | 'dark'): boolean;
42
+ /**
43
+ * Generate a screenshot for a story and save to disk
44
+ */
45
+ declare function generateScreenshot(storyId: string, theme: 'light' | 'dark', storybookUrl?: string): Promise<GenerateScreenshotResult | null>;
46
+
47
+ export { type Manifest, type ScreenshotMetadata, generateAllScreenshots, generateScreenshot, getScreenshotPath, screenshotExists };