@cappa/plugin-storybook 0.0.11 → 0.0.13

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.
@@ -1,31 +1,39 @@
1
1
 
2
2
 
3
- > @cappa/plugin-storybook@0.0.10 build /home/tim/cappa/packages/plugins/plugin-storybook
4
- > tsdown
3
+ > @cappa/plugin-storybook@0.0.12 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
4
+ > tsup
5
5
 
6
- ℹ tsdown v0.14.1 powered by rolldown v1.0.0-beta.37
7
- ℹ Using tsdown config: /home/tim/cappa/packages/plugins/plugin-storybook/tsdown.config.ts
8
- (node:239692) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/tim/cappa/packages/plugins/plugin-storybook/tsdown.config.ts is not specified and it doesn't parse as CommonJS.
9
- Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
10
- To eliminate this warning, add "type": "module" to /home/tim/cappa/packages/plugins/plugin-storybook/package.json.
11
- (Use `node --trace-warnings ...` to show where the warning was created)
12
- ℹ entry: src/index.ts
13
- ℹ tsconfig: ../../../tsconfig.json
14
- ℹ Build start
15
- ℹ Cleaning 6 files
16
- Warning: Invalid input options (1 issue found)
17
- - For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. 
18
- Warning: Invalid input options (1 issue found)
19
- - For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. 
20
- ℹ [CJS] dist/index.js  7.48 kB │ gzip: 2.60 kB
21
- ℹ [CJS] dist/index.js.map 13.21 kB │ gzip: 4.15 kB
22
- ℹ [CJS] 2 files, total: 20.68 kB
23
- Warning: Invalid input options (1 issue found)
24
- - For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. 
25
- ℹ [ESM] dist/index.mjs  6.38 kB │ gzip: 2.19 kB
26
- ℹ [ESM] dist/index.mjs.map 13.19 kB │ gzip: 4.16 kB
27
- ℹ [ESM] dist/index.d.mts  0.71 kB │ gzip: 0.39 kB
28
- ℹ [ESM] 3 files, total: 20.28 kB
29
- ℹ [CJS] dist/index.d.ts 0.71 kB │ gzip: 0.38 kB
30
- ℹ [CJS] 1 files, total: 0.71 kB
31
- ✔ Build complete in 1416ms
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: ../../../tsconfig.json
8
+ CLI tsup v8.5.0
9
+ CLI Using tsup config: /home/tim/code/work/cappa/packages/plugins/plugin-storybook/tsup.config.ts
10
+ CLI Building entry: src/storybook/addon/preview.ts
11
+ CLI Using tsconfig: ../../../tsconfig.json
12
+ CLI tsup v8.5.0
13
+ CLI Using tsup config: /home/tim/code/work/cappa/packages/plugins/plugin-storybook/tsup.config.ts
14
+ CLI Building entry: src/storybook/addon/browser.ts
15
+ CLI Using tsconfig: ../../../tsconfig.json
16
+ CLI tsup v8.5.0
17
+ CLI Using tsup config: /home/tim/code/work/cappa/packages/plugins/plugin-storybook/tsup.config.ts
18
+ CLI Target: esnext
19
+ CLI Target: node16
20
+ CLI Target: es2015
21
+ CLI Cleaning output folder
22
+ CJS Build start
23
+ ESM Build start
24
+ CLI Cleaning output folder
25
+ ESM Build start
26
+ CLI Cleaning output folder
27
+ ESM Build start
28
+ ESM dist/preview.mjs 1.49 KB
29
+ ESM ⚡️ Build success in 7ms
30
+ ESM dist/index.mjs 5.70 KB
31
+ ESM ⚡️ Build success in 9ms
32
+ CJS dist/index.js 6.99 KB
33
+ CJS ⚡️ Build success in 9ms
34
+ ESM dist/browser.mjs 138.00 B
35
+ ESM ⚡️ Build success in 7ms
36
+ DTS Build start
37
+ DTS ⚡️ Build success in 843ms
38
+ DTS dist/index.d.ts 593.00 B
39
+ DTS dist/index.d.mts 593.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @cappa/plugin-storybook
2
2
 
3
+ ## 0.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - c538974: Replace playwright with playwright-core
8
+ - Updated dependencies [c538974]
9
+ - @cappa/core@0.0.13
10
+
11
+ ## 0.0.12
12
+
13
+ ### Patch Changes
14
+
15
+ - 4e529fd: New options
16
+ - Updated dependencies [4e529fd]
17
+ - @cappa/core@0.0.12
18
+
3
19
  ## 0.0.11
4
20
 
5
21
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Storybook Plugin for Cappa
2
+
3
+ This plugin allows to take screenshots of Storybook stories with Cappa.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add -D @cappa/plugin-storybook
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Add the plugin to your cappa config:
14
+
15
+ ```ts
16
+ import { defineConfig } from "@cappa/core";
17
+ import { cappaPluginStorybook } from "@cappa/plugin-storybook";
18
+
19
+ export default defineConfig({
20
+ plugins: [cappaPluginStorybook({ storybookUrl: "http://localhost:8080" })],
21
+ });
22
+ ```
23
+
24
+ > Make sure to have a running Storybook server on the given url.
25
+
26
+ Add the plugin to your storybook config:
27
+
28
+ ```ts
29
+ const config: StorybookConfig = {
30
+ addons: ["@cappa/plugin-storybook"],
31
+ };
32
+ ```
33
+
34
+ Run cappa cli in the directory of your cappa config:
35
+
36
+ ```bash
37
+ cappa
38
+ ```
39
+
40
+ ## Options
41
+
42
+ ## Storybook options
43
+
44
+ Cappa uses a storybook addon that allows you to pass options from storybook into cappa.
45
+
46
+ ### Parameters
47
+
48
+ | Option | Description | Default |
49
+ | ------ | ---------------------------------------------- | --------------- |
50
+ | skip | Whether to skip the screenshot | false |
51
+ | delay | The delay to wait before taking the screenshot | null (no delay) |
52
+
53
+ #### Example
54
+
55
+ ```ts
56
+ export const Primary: Story = {
57
+ parameters: {
58
+ cappa: {
59
+ skip: true,
60
+ delay: 1000,
61
+ },
62
+ },
63
+ };
64
+ ```
65
+
66
+ ### Play function
67
+
68
+ cappa automatically waits for the play function to finish, before taking screenshots. This allows you to define 'actions' that are executed before the screenshot is taken e.g. clicking on a button.
69
+
70
+ > `delay` is added "on top" of the play function execution.
71
+
72
+ #### Example
73
+
74
+ ```ts
75
+ export const Primary: Story = {
76
+ play: async ({ canvasElement }) => {
77
+ const canvas = within(canvasElement);
78
+ await userEvent.click(canvas.getByRole("button"));
79
+ },
80
+ };
81
+ ```
82
+
83
+ ## Flakiness
84
+
85
+ To avoid flakiness, cappa disables css animations and transitions by default. For additional use cases or animation libraries, you can use the `isCappa` function to check if the current window is a cappa window. You can use it inside of your storybook preview file (`.storybook/preview.ts`):
86
+
87
+ ```ts
88
+ if (isCappa()) {
89
+ import("disable-animations.css");
90
+ MotionGlobalConfig.disableAnimations = true;
91
+ }
92
+ ```
93
+
94
+ ## How it works
95
+
96
+ cappa uses a 'one way binding' to pass options from storybook into cappa. That means that the storybook addon is responsible for passing options into cappa and 'communicating' the correct timing to take the screenshot.
@@ -0,0 +1,7 @@
1
+ // src/storybook/addon/browser.ts
2
+ var isCappa = () => {
3
+ return navigator.userAgent.includes("CappaStorybook");
4
+ };
5
+ export {
6
+ isCappa
7
+ };
package/dist/index.d.mts CHANGED
@@ -1,25 +1,22 @@
1
- import { Plugin } from "@cappa/core";
1
+ import { Plugin } from '@cappa/core';
2
2
 
3
- //#region src/cappa/plugin.d.ts
4
3
  interface StorybookPluginOptions {
5
- storybookUrl: string;
6
- includeStories?: string[];
7
- excludeStories?: string[];
8
- defaultViewport?: {
9
- width: number;
10
- height: number;
11
- };
12
- waitForSelector?: string;
13
- waitForTimeout?: number;
4
+ storybookUrl: string;
5
+ includeStories?: string[];
6
+ excludeStories?: string[];
7
+ defaultViewport?: {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ waitForSelector?: string;
12
+ waitForTimeout?: number;
14
13
  }
15
14
  /**
16
15
  * Storybook Plugin for Cappa
17
16
  * Fetches stories from a running Storybook server and takes screenshots of each story
18
17
  */
19
18
  declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
20
- //#endregion
21
- //#region src/storybook/decorator.d.ts
22
- declare const withCappaDecorator: (...args: any) => any;
23
- //#endregion
24
- export { cappaPluginStorybook, withCappaDecorator };
25
- //# sourceMappingURL=index.d.mts.map
19
+
20
+ declare const previewAnnotations: string[];
21
+
22
+ export { cappaPluginStorybook, previewAnnotations };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,22 @@
1
- import { Plugin } from "@cappa/core";
1
+ import { Plugin } from '@cappa/core';
2
2
 
3
- //#region src/cappa/plugin.d.ts
4
3
  interface StorybookPluginOptions {
5
- storybookUrl: string;
6
- includeStories?: string[];
7
- excludeStories?: string[];
8
- defaultViewport?: {
9
- width: number;
10
- height: number;
11
- };
12
- waitForSelector?: string;
13
- waitForTimeout?: number;
4
+ storybookUrl: string;
5
+ includeStories?: string[];
6
+ excludeStories?: string[];
7
+ defaultViewport?: {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ waitForSelector?: string;
12
+ waitForTimeout?: number;
14
13
  }
15
14
  /**
16
15
  * Storybook Plugin for Cappa
17
16
  * Fetches stories from a running Storybook server and takes screenshots of each story
18
17
  */
19
18
  declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
20
- //#endregion
21
- //#region src/storybook/decorator.d.ts
22
- declare const withCappaDecorator: (...args: any) => any;
23
- //#endregion
24
- export { cappaPluginStorybook, withCappaDecorator };
25
- //# sourceMappingURL=index.d.ts.map
19
+
20
+ declare const previewAnnotations: string[];
21
+
22
+ export { cappaPluginStorybook, previewAnnotations };
package/dist/index.js CHANGED
@@ -1,203 +1,186 @@
1
- //#region rolldown:runtime
1
+ "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
8
12
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
17
19
  };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
29
 
23
- //#endregion
24
- require("@cappa/core");
25
- let storybook_preview_api = require("storybook/preview-api");
26
- storybook_preview_api = __toESM(storybook_preview_api);
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ cappaPluginStorybook: () => cappaPluginStorybook,
34
+ previewAnnotations: () => previewAnnotations
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
27
37
 
28
- //#region src/cappa/util.ts
29
- /**
30
- * Disable CSS transitions, animations, and scrollbars
31
- * @param page - The page to disable CSS transitions, animations, and scrollbars
32
- */
33
- const freezeUI = async (page) => {
34
- await page.addStyleTag({ content: `
38
+ // src/cappa/util.ts
39
+ var freezeUI = async (page) => {
40
+ await page.addStyleTag({
41
+ content: `
35
42
  * { transition: none !important; animation: none !important }
36
43
  * { caret-color: transparent !important }
37
44
  ::-webkit-scrollbar { display: none }
38
- ` });
45
+ `
46
+ });
39
47
  };
40
- /**
41
- * Wait for general visual stability on the page
42
- * @param page - The page to wait for
43
- */
44
- const waitForVisualIdle = async (page) => {
45
- await page.waitForLoadState("networkidle");
46
- await page.evaluate(async () => {
47
- if (document.fonts?.ready) await document.fonts.ready;
48
- await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
49
- });
48
+ var waitForVisualIdle = async (page) => {
49
+ await page.waitForLoadState("networkidle");
50
+ await page.evaluate(async () => {
51
+ if (document.fonts?.ready) await document.fonts.ready;
52
+ await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
53
+ });
50
54
  };
51
55
 
52
- //#endregion
53
- //#region src/cappa/plugin.ts
54
- /**
55
- * Create a latch for a Promise. A latch is a Promise that can be resolved from outside.
56
- * @param T - The type of the Promise
57
- * @returns A latch for a Promise
58
- */
56
+ // src/cappa/plugin.ts
59
57
  function createLatch() {
60
- let resolve;
61
- return {
62
- p: new Promise((r) => resolve = r),
63
- resolve
64
- };
58
+ let resolve;
59
+ const p = new Promise((r) => resolve = r);
60
+ return { p, resolve };
65
61
  }
66
- /**
67
- * Storybook Plugin for Cappa
68
- * Fetches stories from a running Storybook server and takes screenshots of each story
69
- */
70
- const cappaPluginStorybook = (options) => {
71
- return {
72
- name: "StorybookPlugin",
73
- description: "Takes screenshots of Storybook stories with configurable options",
74
- version: "1.0.0",
75
- execute: async (screenshotTool) => {
76
- if (!options) throw new Error("Storybook plugin options are required");
77
- if (!options.storybookUrl) throw new Error("storybookUrl is required");
78
- const { storybookUrl, includeStories = [], excludeStories = [], defaultViewport = {
79
- width: 1920,
80
- height: 1080
81
- }, waitForSelector, waitForTimeout } = options;
82
- const storiesUrl = `${storybookUrl}/index.json`;
83
- console.log(`Fetching stories from: ${storiesUrl}`);
84
- try {
85
- const response = await fetch(storiesUrl);
86
- if (!response.ok) throw new Error(`Failed to fetch stories: ${response.status} ${response.statusText}`);
87
- const data = await response.json();
88
- let filteredStories = Object.values(data.entries);
89
- if (includeStories.length > 0) filteredStories = filteredStories.filter((story) => includeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern)));
90
- if (excludeStories.length > 0) filteredStories = filteredStories.filter((story) => !excludeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern)));
91
- filteredStories = filteredStories.filter((story) => story.type === "story");
92
- console.log(`Found ${filteredStories.length} stories to screenshot`);
93
- const results = [];
94
- await screenshotTool.init();
95
- let currentLatch = createLatch();
96
- await screenshotTool.page?.exposeFunction("__cappa_parameters", async (payload) => {
97
- currentLatch.resolve(payload);
98
- });
99
- for (const story of filteredStories) try {
100
- const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
101
- const screenshotOptions = {
102
- viewport: defaultViewport,
103
- waitForSelector,
104
- waitForTimeout,
105
- fullPage: true,
106
- quality: 90,
107
- type: "jpeg"
108
- };
109
- const filename = `${story.title.replace(/[^a-zA-Z0-9]/g, "_")}_${story.name.replace(/[^a-zA-Z0-9]/g, "_")}.${screenshotOptions.type}`;
110
- const page = screenshotTool.page;
111
- if (!page) throw new Error("Page not initialized");
112
- page.on("console", (message) => {
113
- console.log("console", message.text());
114
- });
115
- page.on("pageerror", (error) => {
116
- console.log("pageerror", error);
117
- });
118
- await page.goto(storyUrl);
119
- const options$1 = await currentLatch.p;
120
- currentLatch = createLatch();
121
- if (options$1.skip) console.log(`Skipping story ${story.title} - ${story.name}`);
122
- await freezeUI(page);
123
- await waitForVisualIdle(page);
124
- if (options$1.delay) await page.waitForTimeout(options$1.delay);
125
- const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
126
- fullPage: options$1.fullPage ?? screenshotOptions.fullPage,
127
- type: options$1.type ?? screenshotOptions.type,
128
- waitForSelector: options$1.waitForSelector ?? screenshotOptions.waitForSelector,
129
- waitForTimeout: options$1.waitForTimeout ?? screenshotOptions.waitForTimeout
130
- });
131
- results.push({
132
- storyId: story.id,
133
- storyName: story.name,
134
- storyTitle: story.title,
135
- success: true,
136
- filepath: actualFilepath
137
- });
138
- } catch (error) {
139
- console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, error.message);
140
- results.push({
141
- storyId: story.id,
142
- storyName: story.name,
143
- storyTitle: story.title,
144
- success: false,
145
- error: error.message
146
- });
147
- }
148
- console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
149
- return results;
150
- } catch (error) {
151
- console.error("Error in Storybook plugin:", error.message);
152
- throw error;
153
- }
154
- }
155
- };
62
+ var cappaPluginStorybook = (options) => {
63
+ return {
64
+ name: "StorybookPlugin",
65
+ description: "Takes screenshots of Storybook stories with configurable options",
66
+ version: "1.0.0",
67
+ execute: async (screenshotTool) => {
68
+ if (!options) {
69
+ throw new Error("Storybook plugin options are required");
70
+ }
71
+ if (!options.storybookUrl) {
72
+ throw new Error("storybookUrl is required");
73
+ }
74
+ const {
75
+ storybookUrl,
76
+ includeStories = [],
77
+ excludeStories = [],
78
+ defaultViewport = { width: 1920, height: 1080 },
79
+ waitForSelector,
80
+ waitForTimeout
81
+ } = options;
82
+ const storiesUrl = `${storybookUrl}/index.json`;
83
+ console.log(`Fetching stories from: ${storiesUrl}`);
84
+ try {
85
+ const response = await fetch(storiesUrl);
86
+ if (!response.ok) {
87
+ throw new Error(`Failed to fetch stories: ${response.status} ${response.statusText}`);
88
+ }
89
+ const data = await response.json();
90
+ const stories = Object.values(data.entries);
91
+ let filteredStories = stories;
92
+ if (includeStories.length > 0) {
93
+ filteredStories = filteredStories.filter(
94
+ (story) => includeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern))
95
+ );
96
+ }
97
+ if (excludeStories.length > 0) {
98
+ filteredStories = filteredStories.filter(
99
+ (story) => !excludeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern))
100
+ );
101
+ }
102
+ filteredStories = filteredStories.filter((story) => story.type === "story");
103
+ console.log(`Found ${filteredStories.length} stories to screenshot`);
104
+ const results = [];
105
+ await screenshotTool.init();
106
+ let currentLatch = createLatch();
107
+ await screenshotTool.page?.exposeFunction("__cappa_parameters", async (payload) => {
108
+ currentLatch.resolve(payload);
109
+ });
110
+ for (const story of filteredStories) {
111
+ try {
112
+ const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
113
+ const screenshotOptions = {
114
+ viewport: defaultViewport,
115
+ waitForSelector,
116
+ waitForTimeout,
117
+ fullPage: true,
118
+ quality: 90,
119
+ type: "jpeg"
120
+ };
121
+ const filename = `${story.title.replace(
122
+ /[^a-zA-Z0-9]/g,
123
+ "_"
124
+ )}_${story.name.replace(/[^a-zA-Z0-9]/g, "_")}.${screenshotOptions.type}`;
125
+ const page = screenshotTool.page;
126
+ if (!page) {
127
+ throw new Error("Page not initialized");
128
+ }
129
+ page.on("console", (message) => {
130
+ console.log("console", message.text());
131
+ });
132
+ page.on("pageerror", (error) => {
133
+ console.log("pageerror", error);
134
+ });
135
+ await page.goto(storyUrl);
136
+ const options2 = await currentLatch.p;
137
+ currentLatch = createLatch();
138
+ if (options2.skip) {
139
+ console.log(`Skipping story ${story.title} - ${story.name}`);
140
+ }
141
+ await freezeUI(page);
142
+ await waitForVisualIdle(page);
143
+ if (options2.delay) {
144
+ await page.waitForTimeout(options2.delay);
145
+ }
146
+ const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
147
+ fullPage: options2.fullPage ?? screenshotOptions.fullPage,
148
+ type: options2.type ?? screenshotOptions.type,
149
+ waitForSelector: options2.waitForSelector ?? screenshotOptions.waitForSelector,
150
+ waitForTimeout: options2.waitForTimeout ?? screenshotOptions.waitForTimeout
151
+ });
152
+ results.push({
153
+ storyId: story.id,
154
+ storyName: story.name,
155
+ storyTitle: story.title,
156
+ success: true,
157
+ filepath: actualFilepath
158
+ });
159
+ } catch (error) {
160
+ console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, error.message);
161
+ results.push({
162
+ storyId: story.id,
163
+ storyName: story.name,
164
+ storyTitle: story.title,
165
+ success: false,
166
+ error: error.message
167
+ });
168
+ }
169
+ }
170
+ console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
171
+ return results;
172
+ } catch (error) {
173
+ console.error("Error in Storybook plugin:", error.message);
174
+ throw error;
175
+ }
176
+ }
177
+ };
156
178
  };
157
179
 
158
- //#endregion
159
- //#region src/storybook/util.ts
160
- /**
161
- * Wait for a function to be exposed on the window object
162
- * @param name - The name of the function to wait for
163
- * @param timeoutMs - The timeout in milliseconds
164
- * @returns The function or rejects if the function is not exposed within the timeout
165
- */
166
- const waitForExposed = (name, timeoutMs = 5e3) => {
167
- return new Promise((resolve, reject) => {
168
- const start = performance.now();
169
- const t = setInterval(() => {
170
- const fn = window[name];
171
- if (typeof fn === "function") {
172
- clearInterval(t);
173
- resolve(fn);
174
- } else if (performance.now() - start > timeoutMs) {
175
- clearInterval(t);
176
- reject(/* @__PURE__ */ new Error(`Timed out waiting for ${name}`));
177
- }
178
- }, 16);
179
- });
180
- };
181
-
182
- //#endregion
183
- //#region src/storybook/decorator.ts
184
- const withCappaDecorator = (0, storybook_preview_api.makeDecorator)({
185
- name: "withCappa",
186
- parameterName: "cappa",
187
- skipIfNoParametersOrOptions: false,
188
- wrapper: (getStory, context, { parameters }) => {
189
- queueMicrotask(async () => {
190
- try {
191
- (await waitForExposed("__cappa_parameters"))(parameters ?? {});
192
- } catch (error) {
193
- console.error(error);
194
- }
195
- });
196
- return getStory(context);
197
- }
180
+ // src/index.ts
181
+ var previewAnnotations = [require.resolve("./preview.mjs")];
182
+ // Annotate the CommonJS export names for ESM import in node:
183
+ 0 && (module.exports = {
184
+ cappaPluginStorybook,
185
+ previewAnnotations
198
186
  });
199
-
200
- //#endregion
201
- exports.cappaPluginStorybook = cappaPluginStorybook;
202
- exports.withCappaDecorator = withCappaDecorator;
203
- //# sourceMappingURL=index.js.map