@cappa/plugin-storybook 0.0.22 → 0.0.23
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 +7 -7
- package/CHANGELOG.md +8 -0
- package/README.md +2 -0
- package/dist/index.js +32 -17
- package/dist/index.mjs +32 -17
- package/package.json +2 -2
- package/src/cappa/plugin.ts +3 -16
- package/src/cappa/util.ts +31 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @cappa/plugin-storybook@0.0.
|
|
3
|
+
> @cappa/plugin-storybook@0.0.22 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
[34mESM[39m Build start
|
|
26
26
|
[34mCLI[39m Cleaning output folder
|
|
27
27
|
[34mESM[39m Build start
|
|
28
|
-
[32mESM[39m [1mdist/preview.mjs [22m[32m1.34 KB[39m
|
|
29
|
-
[32mESM[39m ⚡️ Build success in 7ms
|
|
30
28
|
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
31
29
|
[32mESM[39m ⚡️ Build success in 7ms
|
|
32
|
-
[32mESM[39m [1mdist/
|
|
33
|
-
[32mESM[39m ⚡️ Build success in
|
|
34
|
-
[
|
|
30
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.34 KB[39m
|
|
31
|
+
[32mESM[39m ⚡️ Build success in 7ms
|
|
32
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m7.07 KB[39m
|
|
33
|
+
[32mESM[39m ⚡️ Build success in 9ms
|
|
34
|
+
[32mCJS[39m [1mdist/index.js [22m[32m8.43 KB[39m
|
|
35
35
|
[32mCJS[39m ⚡️ Build success in 10ms
|
|
36
36
|
DTS Build start
|
|
37
|
-
DTS ⚡️ Build success in
|
|
37
|
+
DTS ⚡️ Build success in 864ms
|
|
38
38
|
DTS dist/index.d.ts 593.00 B
|
|
39
39
|
DTS dist/index.d.mts 593.00 B
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ Cappa uses a storybook addon that allows you to pass options from storybook into
|
|
|
50
50
|
| skip | Whether to skip the screenshot | false |
|
|
51
51
|
| delay | The delay to wait before taking the screenshot | null (no delay) |
|
|
52
52
|
| fullPage | Whether to take a full page screenshot | true |
|
|
53
|
+
| mask | An array of selectors to mask in the screenshot | [] |
|
|
53
54
|
|
|
54
55
|
#### Example
|
|
55
56
|
|
|
@@ -60,6 +61,7 @@ export const Primary: Story = {
|
|
|
60
61
|
skip: true,
|
|
61
62
|
delay: 1000,
|
|
62
63
|
fullPage: false,
|
|
64
|
+
mask: ["#my-element", ".my-class"],
|
|
63
65
|
},
|
|
64
66
|
},
|
|
65
67
|
};
|
package/dist/index.js
CHANGED
|
@@ -42,17 +42,41 @@ var freezeUI = async (page) => {
|
|
|
42
42
|
* { transition: none !important; animation: none !important }
|
|
43
43
|
* { caret-color: transparent !important }
|
|
44
44
|
::-webkit-scrollbar { display: none }
|
|
45
|
+
html { scroll-behavior: auto !important }
|
|
45
46
|
`
|
|
46
47
|
});
|
|
47
48
|
};
|
|
48
49
|
var waitForVisualIdle = async (page) => {
|
|
49
50
|
await page.waitForLoadState("networkidle");
|
|
50
51
|
await page.evaluate(async () => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)
|
|
52
|
+
await document.fonts?.ready?.catch(() => {
|
|
53
|
+
});
|
|
54
|
+
const imgs = Array.from(document.images).filter((i) => !i.complete);
|
|
55
|
+
await Promise.all(imgs.map((i) => new Promise((res) => {
|
|
56
|
+
i.onload = i.onerror = () => res(null);
|
|
57
|
+
})));
|
|
55
58
|
});
|
|
59
|
+
await page.evaluate(({ minIdleMs }) => new Promise((resolve) => {
|
|
60
|
+
let timer = null;
|
|
61
|
+
let last = performance.now();
|
|
62
|
+
const done = () => {
|
|
63
|
+
if (timer) cancelAnimationFrame(timer);
|
|
64
|
+
resolve();
|
|
65
|
+
};
|
|
66
|
+
const mo = new MutationObserver(() => {
|
|
67
|
+
last = performance.now();
|
|
68
|
+
});
|
|
69
|
+
mo.observe(document, { attributes: true, childList: true, subtree: true, characterData: true });
|
|
70
|
+
const tick = () => {
|
|
71
|
+
if (performance.now() - last >= minIdleMs) {
|
|
72
|
+
mo.disconnect();
|
|
73
|
+
done();
|
|
74
|
+
} else {
|
|
75
|
+
timer = requestAnimationFrame(tick);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
requestAnimationFrame(() => requestAnimationFrame(tick));
|
|
79
|
+
}), { minIdleMs: 100 });
|
|
56
80
|
};
|
|
57
81
|
var buildFilename = (story) => {
|
|
58
82
|
return `${story.title.replace(/[^a-zA-Z0-9/]/g, "")}/${story.name.replace(/[^a-zA-Z0-9]/g, "")}.png`;
|
|
@@ -80,10 +104,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
80
104
|
const {
|
|
81
105
|
storybookUrl,
|
|
82
106
|
includeStories = [],
|
|
83
|
-
excludeStories = []
|
|
84
|
-
defaultViewport = { width: 1920, height: 1080 },
|
|
85
|
-
waitForSelector,
|
|
86
|
-
waitForTimeout
|
|
107
|
+
excludeStories = []
|
|
87
108
|
} = options;
|
|
88
109
|
const storiesUrl = `${storybookUrl}/index.json`;
|
|
89
110
|
console.log(`Fetching stories from: ${storiesUrl}`);
|
|
@@ -127,12 +148,6 @@ var cappaPluginStorybook = (options) => {
|
|
|
127
148
|
for (const story of filteredStories) {
|
|
128
149
|
try {
|
|
129
150
|
const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
|
|
130
|
-
const screenshotOptions = {
|
|
131
|
-
viewport: defaultViewport,
|
|
132
|
-
waitForSelector,
|
|
133
|
-
waitForTimeout,
|
|
134
|
-
fullPage: true
|
|
135
|
-
};
|
|
136
151
|
const page = screenshotTool.page;
|
|
137
152
|
if (!page) {
|
|
138
153
|
throw new Error("Page not initialized");
|
|
@@ -166,9 +181,9 @@ var cappaPluginStorybook = (options) => {
|
|
|
166
181
|
page,
|
|
167
182
|
filename,
|
|
168
183
|
{
|
|
169
|
-
fullPage: options2.fullPage
|
|
170
|
-
|
|
171
|
-
|
|
184
|
+
fullPage: options2.fullPage,
|
|
185
|
+
mask: options2.mask?.map((selector) => page.locator(selector)),
|
|
186
|
+
omitBackground: options2.omitBackground
|
|
172
187
|
}
|
|
173
188
|
);
|
|
174
189
|
results.push({
|
package/dist/index.mjs
CHANGED
|
@@ -12,17 +12,41 @@ var freezeUI = async (page) => {
|
|
|
12
12
|
* { transition: none !important; animation: none !important }
|
|
13
13
|
* { caret-color: transparent !important }
|
|
14
14
|
::-webkit-scrollbar { display: none }
|
|
15
|
+
html { scroll-behavior: auto !important }
|
|
15
16
|
`
|
|
16
17
|
});
|
|
17
18
|
};
|
|
18
19
|
var waitForVisualIdle = async (page) => {
|
|
19
20
|
await page.waitForLoadState("networkidle");
|
|
20
21
|
await page.evaluate(async () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
22
|
+
await document.fonts?.ready?.catch(() => {
|
|
23
|
+
});
|
|
24
|
+
const imgs = Array.from(document.images).filter((i) => !i.complete);
|
|
25
|
+
await Promise.all(imgs.map((i) => new Promise((res) => {
|
|
26
|
+
i.onload = i.onerror = () => res(null);
|
|
27
|
+
})));
|
|
25
28
|
});
|
|
29
|
+
await page.evaluate(({ minIdleMs }) => new Promise((resolve) => {
|
|
30
|
+
let timer = null;
|
|
31
|
+
let last = performance.now();
|
|
32
|
+
const done = () => {
|
|
33
|
+
if (timer) cancelAnimationFrame(timer);
|
|
34
|
+
resolve();
|
|
35
|
+
};
|
|
36
|
+
const mo = new MutationObserver(() => {
|
|
37
|
+
last = performance.now();
|
|
38
|
+
});
|
|
39
|
+
mo.observe(document, { attributes: true, childList: true, subtree: true, characterData: true });
|
|
40
|
+
const tick = () => {
|
|
41
|
+
if (performance.now() - last >= minIdleMs) {
|
|
42
|
+
mo.disconnect();
|
|
43
|
+
done();
|
|
44
|
+
} else {
|
|
45
|
+
timer = requestAnimationFrame(tick);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
requestAnimationFrame(() => requestAnimationFrame(tick));
|
|
49
|
+
}), { minIdleMs: 100 });
|
|
26
50
|
};
|
|
27
51
|
var buildFilename = (story) => {
|
|
28
52
|
return `${story.title.replace(/[^a-zA-Z0-9/]/g, "")}/${story.name.replace(/[^a-zA-Z0-9]/g, "")}.png`;
|
|
@@ -50,10 +74,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
50
74
|
const {
|
|
51
75
|
storybookUrl,
|
|
52
76
|
includeStories = [],
|
|
53
|
-
excludeStories = []
|
|
54
|
-
defaultViewport = { width: 1920, height: 1080 },
|
|
55
|
-
waitForSelector,
|
|
56
|
-
waitForTimeout
|
|
77
|
+
excludeStories = []
|
|
57
78
|
} = options;
|
|
58
79
|
const storiesUrl = `${storybookUrl}/index.json`;
|
|
59
80
|
console.log(`Fetching stories from: ${storiesUrl}`);
|
|
@@ -97,12 +118,6 @@ var cappaPluginStorybook = (options) => {
|
|
|
97
118
|
for (const story of filteredStories) {
|
|
98
119
|
try {
|
|
99
120
|
const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
|
|
100
|
-
const screenshotOptions = {
|
|
101
|
-
viewport: defaultViewport,
|
|
102
|
-
waitForSelector,
|
|
103
|
-
waitForTimeout,
|
|
104
|
-
fullPage: true
|
|
105
|
-
};
|
|
106
121
|
const page = screenshotTool.page;
|
|
107
122
|
if (!page) {
|
|
108
123
|
throw new Error("Page not initialized");
|
|
@@ -136,9 +151,9 @@ var cappaPluginStorybook = (options) => {
|
|
|
136
151
|
page,
|
|
137
152
|
filename,
|
|
138
153
|
{
|
|
139
|
-
fullPage: options2.fullPage
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
fullPage: options2.fullPage,
|
|
155
|
+
mask: options2.mask?.map((selector) => page.locator(selector)),
|
|
156
|
+
omitBackground: options2.omitBackground
|
|
142
157
|
}
|
|
143
158
|
);
|
|
144
159
|
results.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@swc/core": "^1.13.5",
|
|
32
32
|
"chalk": "^5.6.2",
|
|
33
33
|
"storybook": "^9.1.5",
|
|
34
|
-
"@cappa/core": "0.0.
|
|
34
|
+
"@cappa/core": "0.0.23"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@vitest/coverage-v8": "3.2.4",
|
package/src/cappa/plugin.ts
CHANGED
|
@@ -60,9 +60,6 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
60
60
|
storybookUrl,
|
|
61
61
|
includeStories = [],
|
|
62
62
|
excludeStories = [],
|
|
63
|
-
defaultViewport = { width: 1920, height: 1080 },
|
|
64
|
-
waitForSelector,
|
|
65
|
-
waitForTimeout,
|
|
66
63
|
} = options;
|
|
67
64
|
|
|
68
65
|
const storiesUrl = `${storybookUrl}/index.json`;
|
|
@@ -134,14 +131,6 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
134
131
|
try {
|
|
135
132
|
const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
|
|
136
133
|
|
|
137
|
-
// Merge with default options
|
|
138
|
-
const screenshotOptions = {
|
|
139
|
-
viewport: defaultViewport,
|
|
140
|
-
waitForSelector: waitForSelector,
|
|
141
|
-
waitForTimeout: waitForTimeout,
|
|
142
|
-
fullPage: true,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
134
|
const page = screenshotTool.page;
|
|
146
135
|
if (!page) {
|
|
147
136
|
throw new Error("Page not initialized");
|
|
@@ -186,11 +175,9 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
186
175
|
page,
|
|
187
176
|
filename,
|
|
188
177
|
{
|
|
189
|
-
fullPage: options.fullPage
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
waitForTimeout:
|
|
193
|
-
options.waitForTimeout ?? screenshotOptions.waitForTimeout,
|
|
178
|
+
fullPage: options.fullPage,
|
|
179
|
+
mask: options.mask?.map((selector) => page.locator(selector)),
|
|
180
|
+
omitBackground: options.omitBackground,
|
|
194
181
|
},
|
|
195
182
|
);
|
|
196
183
|
|
package/src/cappa/util.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const freezeUI = async (page: Page) => {
|
|
|
11
11
|
* { transition: none !important; animation: none !important }
|
|
12
12
|
* { caret-color: transparent !important }
|
|
13
13
|
::-webkit-scrollbar { display: none }
|
|
14
|
+
html { scroll-behavior: auto !important }
|
|
14
15
|
`,
|
|
15
16
|
});
|
|
16
17
|
};
|
|
@@ -23,15 +24,37 @@ export const waitForVisualIdle = async (page: Page) => {
|
|
|
23
24
|
// Wait for the page to be fully loaded
|
|
24
25
|
await page.waitForLoadState("networkidle");
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// fonts + images
|
|
28
|
+
await page.evaluate(async () => {
|
|
29
|
+
await (document as any).fonts?.ready?.catch(() => {})
|
|
30
|
+
const imgs = Array.from(document.images).filter(i => !i.complete)
|
|
31
|
+
await Promise.all(imgs.map(i => new Promise(res => { i.onload = i.onerror = () => res(null) })))
|
|
32
|
+
})
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
// 2 animation frames + idle period with no DOM mutations
|
|
35
|
+
await page.evaluate(({ minIdleMs }) => new Promise<void>(resolve => {
|
|
36
|
+
let timer: number | null = null
|
|
37
|
+
let last = performance.now()
|
|
38
|
+
|
|
39
|
+
const done = () => {
|
|
40
|
+
if (timer) cancelAnimationFrame(timer)
|
|
41
|
+
resolve()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const mo = new MutationObserver(() => { last = performance.now() })
|
|
45
|
+
mo.observe(document, { attributes: true, childList: true, subtree: true, characterData: true })
|
|
46
|
+
|
|
47
|
+
const tick = () => {
|
|
48
|
+
if (performance.now() - last >= minIdleMs) {
|
|
49
|
+
mo.disconnect()
|
|
50
|
+
done()
|
|
51
|
+
} else {
|
|
52
|
+
timer = requestAnimationFrame(tick)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
requestAnimationFrame(() => requestAnimationFrame(tick))
|
|
57
|
+
}), { minIdleMs: 100 })
|
|
35
58
|
};
|
|
36
59
|
|
|
37
60
|
/**
|