@cappa/plugin-storybook 0.1.3 → 0.2.1
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/.turbo/turbo-build.log +13 -13
- package/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +1 -91
- package/dist/index.d.mts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +243 -145
- package/dist/index.mjs +243 -145
- package/dist/preview.mjs +5 -3
- package/package.json +8 -8
- package/src/cappa/plugin.ts +287 -183
- package/src/cappa/storybook-url.test.ts +43 -0
- package/src/cappa/storybook-url.ts +55 -0
- package/src/index.ts +2 -0
- package/src/storybook/addon/decorator.ts +6 -4
- package/src/storybook/addon/preview.ts +1 -0
- package/src/storybook/util.ts +1 -1
- package/src/types.ts +29 -4
- package/tsconfig.json +13 -0
- package/src/tsconfig.json +0 -7
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @cappa/plugin-storybook@0.
|
|
3
|
+
> @cappa/plugin-storybook@0.2.0 build /home/tim/cappa/packages/plugins/plugin-storybook
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
-
[34mCLI[39m Using tsconfig:
|
|
7
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
8
|
[34mCLI[39m tsup v8.5.0
|
|
9
9
|
[34mCLI[39m Using tsup config: /home/tim/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
10
10
|
[34mCLI[39m Building entry: src/storybook/addon/preview.ts
|
|
11
|
-
[34mCLI[39m Using tsconfig:
|
|
11
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
12
12
|
[34mCLI[39m tsup v8.5.0
|
|
13
13
|
[34mCLI[39m Using tsup config: /home/tim/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
14
14
|
[34mCLI[39m Building entry: src/storybook/addon/browser.ts
|
|
15
|
-
[34mCLI[39m Using tsconfig:
|
|
15
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
16
16
|
[34mCLI[39m tsup v8.5.0
|
|
17
17
|
[34mCLI[39m Using tsup config: /home/tim/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
18
18
|
[34mCLI[39m Target: esnext
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
[34mCLI[39m Cleaning output folder
|
|
27
27
|
[34mESM[39m Build start
|
|
28
28
|
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
29
|
+
[32mESM[39m ⚡️ Build success in 10ms
|
|
30
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.35 KB[39m
|
|
29
31
|
[32mESM[39m ⚡️ Build success in 11ms
|
|
30
|
-
[32mESM[39m [1mdist/
|
|
31
|
-
[32mESM[39m ⚡️ Build success in
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[32mCJS[39m [1mdist/index.js [22m[32m10.79 KB[39m
|
|
35
|
-
[32mCJS[39m ⚡️ Build success in 20ms
|
|
32
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m11.00 KB[39m
|
|
33
|
+
[32mESM[39m ⚡️ Build success in 16ms
|
|
34
|
+
[32mCJS[39m [1mdist/index.js [22m[32m12.33 KB[39m
|
|
35
|
+
[32mCJS[39m ⚡️ Build success in 16ms
|
|
36
36
|
DTS Build start
|
|
37
|
-
DTS ⚡️ Build success in
|
|
38
|
-
DTS dist/index.d.ts
|
|
39
|
-
DTS dist/index.d.mts
|
|
37
|
+
DTS ⚡️ Build success in 1283ms
|
|
38
|
+
DTS dist/index.d.ts 905.00 B
|
|
39
|
+
DTS dist/index.d.mts 905.00 B
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @cappa/plugin-storybook
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 526857a: feat: add variant and play function support
|
|
8
|
+
- Updated dependencies [526857a]
|
|
9
|
+
- @cappa/core@0.2.1
|
|
10
|
+
- @cappa/logger@0.0.4
|
|
11
|
+
|
|
12
|
+
## 0.2.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 5b1f66f: Add support for capturing screenshot variants and configure Storybook stories to request multiple viewport screenshots.
|
|
17
|
+
- 4cd0ee2: Allow configuring Storybook args and globals for captured screenshots.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- a1d91c6: feat: add viewport options
|
|
22
|
+
- Updated dependencies [5b1f66f]
|
|
23
|
+
- Updated dependencies [87c8ab9]
|
|
24
|
+
- Updated dependencies [a1d91c6]
|
|
25
|
+
- Updated dependencies [88b3648]
|
|
26
|
+
- @cappa/core@0.2.0
|
|
27
|
+
|
|
3
28
|
## 0.1.3
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tim Richter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,94 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
This plugin allows to take screenshots of Storybook stories with Cappa.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
| fullPage | Whether to take a full page screenshot | true |
|
|
53
|
-
| mask | An array of selectors to mask in the screenshot | [] |
|
|
54
|
-
| omitBackground | Whether to omit the background in the screenshot | false |
|
|
55
|
-
|
|
56
|
-
#### Example
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
export const Primary: Story = {
|
|
60
|
-
parameters: {
|
|
61
|
-
cappa: {
|
|
62
|
-
skip: true,
|
|
63
|
-
delay: 1000,
|
|
64
|
-
fullPage: false,
|
|
65
|
-
mask: ["#my-element", ".my-class"],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Flakiness
|
|
72
|
-
|
|
73
|
-
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`):
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
import { isCappa } from '@cappa/plugin-storybook/browser';
|
|
77
|
-
|
|
78
|
-
if (isCappa()) {
|
|
79
|
-
import("disable-animations.css");
|
|
80
|
-
MotionGlobalConfig.disableAnimations = true;
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### DOM Mutations
|
|
85
|
-
|
|
86
|
-
Cappa waits for DOM mutations to be idle before taking the screenshot. It does so by querying the DOM for mutations and waiting for a certain amount of time to pass, until the page is considered idle.
|
|
87
|
-
|
|
88
|
-
### Fonts & Images
|
|
89
|
-
|
|
90
|
-
Cappa waits for fonts and images to be loaded before taking the screenshot.
|
|
91
|
-
|
|
92
|
-
### SVG's
|
|
93
|
-
|
|
94
|
-
Cappa sets global css styles to render svg images more consistently. You might experience
|
|
95
|
-
differences between actual browsers and cappa screenshots, but that is expected and wanted behavior, since browsers tend to render svg images differently.
|
|
5
|
+
For documentation, see the [Storybook Plugin documentation](https://tim-richter.github.io/cappa/storybook).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { Plugin } from '@cappa/core';
|
|
2
2
|
|
|
3
|
+
interface StorybookRenderOptions {
|
|
4
|
+
viewMode?: "story" | "docs";
|
|
5
|
+
args?: Record<string, unknown>;
|
|
6
|
+
globals?: Record<string, string | number | boolean>;
|
|
7
|
+
query?: Record<string, string | number | boolean>;
|
|
8
|
+
fullscreen?: boolean;
|
|
9
|
+
singleStory?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface ScreenshotVariantOverrideStorybook {
|
|
12
|
+
fullPage?: boolean;
|
|
13
|
+
delay?: number;
|
|
14
|
+
skip?: boolean;
|
|
15
|
+
mask?: string[];
|
|
16
|
+
omitBackground?: boolean;
|
|
17
|
+
viewport?: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
args?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
interface ScreenshotVariantOptionsStorybook {
|
|
24
|
+
id: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
filename?: string;
|
|
27
|
+
options?: ScreenshotVariantOverrideStorybook;
|
|
28
|
+
}
|
|
29
|
+
interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook {
|
|
30
|
+
variants?: ScreenshotVariantOptionsStorybook[];
|
|
31
|
+
}
|
|
32
|
+
|
|
3
33
|
interface StorybookPluginOptions {
|
|
4
34
|
storybookUrl: string;
|
|
5
35
|
includeStories?: string[];
|
|
@@ -10,6 +40,7 @@ interface StorybookPluginOptions {
|
|
|
10
40
|
};
|
|
11
41
|
waitForSelector?: string;
|
|
12
42
|
waitForTimeout?: number;
|
|
43
|
+
storybook?: StorybookRenderOptions;
|
|
13
44
|
}
|
|
14
45
|
/**
|
|
15
46
|
* Storybook Plugin for Cappa
|
|
@@ -19,4 +50,4 @@ declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
|
19
50
|
|
|
20
51
|
declare const previewAnnotations: string[];
|
|
21
52
|
|
|
22
|
-
export { cappaPluginStorybook, previewAnnotations };
|
|
53
|
+
export { type ScreenshotOptionsStorybook as CappaStorybookOptions, cappaPluginStorybook, previewAnnotations };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { Plugin } from '@cappa/core';
|
|
2
2
|
|
|
3
|
+
interface StorybookRenderOptions {
|
|
4
|
+
viewMode?: "story" | "docs";
|
|
5
|
+
args?: Record<string, unknown>;
|
|
6
|
+
globals?: Record<string, string | number | boolean>;
|
|
7
|
+
query?: Record<string, string | number | boolean>;
|
|
8
|
+
fullscreen?: boolean;
|
|
9
|
+
singleStory?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface ScreenshotVariantOverrideStorybook {
|
|
12
|
+
fullPage?: boolean;
|
|
13
|
+
delay?: number;
|
|
14
|
+
skip?: boolean;
|
|
15
|
+
mask?: string[];
|
|
16
|
+
omitBackground?: boolean;
|
|
17
|
+
viewport?: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
args?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
interface ScreenshotVariantOptionsStorybook {
|
|
24
|
+
id: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
filename?: string;
|
|
27
|
+
options?: ScreenshotVariantOverrideStorybook;
|
|
28
|
+
}
|
|
29
|
+
interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook {
|
|
30
|
+
variants?: ScreenshotVariantOptionsStorybook[];
|
|
31
|
+
}
|
|
32
|
+
|
|
3
33
|
interface StorybookPluginOptions {
|
|
4
34
|
storybookUrl: string;
|
|
5
35
|
includeStories?: string[];
|
|
@@ -10,6 +40,7 @@ interface StorybookPluginOptions {
|
|
|
10
40
|
};
|
|
11
41
|
waitForSelector?: string;
|
|
12
42
|
waitForTimeout?: number;
|
|
43
|
+
storybook?: StorybookRenderOptions;
|
|
13
44
|
}
|
|
14
45
|
/**
|
|
15
46
|
* Storybook Plugin for Cappa
|
|
@@ -19,4 +50,4 @@ declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
|
19
50
|
|
|
20
51
|
declare const previewAnnotations: string[];
|
|
21
52
|
|
|
22
|
-
export { cappaPluginStorybook, previewAnnotations };
|
|
53
|
+
export { type ScreenshotOptionsStorybook as CappaStorybookOptions, cappaPluginStorybook, previewAnnotations };
|