astro-better-generate-screenshots 0.4.2 → 0.4.4
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/package.json +1 -1
- package/scripts/check-screenshots.mjs +3 -2
- package/scripts/take-screenshots.mjs +2 -12
- package/src/chrome.mjs +20 -0
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ import { loadConfig } from 'astro-better-declarative-screenshots';
|
|
|
10
10
|
import { discoverScreenshots } from '../src/discover.mjs';
|
|
11
11
|
import { startDocker, stopDocker } from '../src/docker.mjs';
|
|
12
12
|
import { capturePage, createBrowserContext } from '../src/capture.mjs';
|
|
13
|
-
import {
|
|
13
|
+
import { applyChrome } from '../src/chrome.mjs';
|
|
14
14
|
import { diffScreenshot } from '../src/diff.mjs';
|
|
15
15
|
|
|
16
16
|
const projectRoot = process.cwd();
|
|
@@ -93,7 +93,7 @@ async function main() {
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
let newBuffer = rawBuffer;
|
|
96
|
-
if (config.chrome.style !== 'none') {
|
|
96
|
+
if (config.chrome.style !== 'none' && config.chrome.renderIn !== 'css') {
|
|
97
97
|
newBuffer = await addChrome(rawBuffer, {
|
|
98
98
|
url: fullUrl,
|
|
99
99
|
dark: config.chrome.dark,
|
|
@@ -177,6 +177,7 @@ function parseArgs(argv) {
|
|
|
177
177
|
if (argv[i].startsWith('--filter=')) args.filter = argv[i].slice(9);
|
|
178
178
|
if (argv[i].startsWith('--diff-dir=')) args.diffDir = argv[i].slice(11);
|
|
179
179
|
if (argv[i] === '--diff-dir' && argv[i + 1]) args.diffDir = argv[++i];
|
|
180
|
+
if (argv[i] === '--threshold' && argv[i + 1]) args.thresholdRatio = parseFloat(argv[++i]);
|
|
180
181
|
if (argv[i].startsWith('--threshold=')) args.thresholdRatio = parseFloat(argv[i].slice(12));
|
|
181
182
|
}
|
|
182
183
|
return args;
|
|
@@ -9,7 +9,7 @@ import { loadConfig } from 'astro-better-declarative-screenshots';
|
|
|
9
9
|
import { discoverScreenshots } from '../src/discover.mjs';
|
|
10
10
|
import { startDocker, stopDocker } from '../src/docker.mjs';
|
|
11
11
|
import { capturePage, createBrowserContext } from '../src/capture.mjs';
|
|
12
|
-
import {
|
|
12
|
+
import { applyChrome } from '../src/chrome.mjs';
|
|
13
13
|
import { generatePlaceholder } from '../src/placeholder.mjs';
|
|
14
14
|
|
|
15
15
|
const projectRoot = process.cwd();
|
|
@@ -91,17 +91,7 @@ async function main() {
|
|
|
91
91
|
context,
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (config.chrome.style !== 'none' && config.chrome.renderIn !== 'css') {
|
|
97
|
-
finalBuffer = await addChrome(rawBuffer, {
|
|
98
|
-
url: fullUrl,
|
|
99
|
-
dark: config.chrome.theme === 'dark',
|
|
100
|
-
showUrl: config.chrome.showUrl,
|
|
101
|
-
shadowBlur: config.chrome.shadowBlur,
|
|
102
|
-
shadowPadding: config.chrome.shadowPadding,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
94
|
+
const finalBuffer = await applyChrome(rawBuffer, config, fullUrl);
|
|
105
95
|
|
|
106
96
|
writeFileSync(outputPath, finalBuffer);
|
|
107
97
|
process.stdout.write('done\n');
|
package/src/chrome.mjs
CHANGED
|
@@ -15,6 +15,26 @@ const URL_BAR_X = 100;
|
|
|
15
15
|
const URL_BAR_X_MARGIN_R = 20;
|
|
16
16
|
const URL_BAR_RADIUS = 5;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Applies the window chrome the config asks for, or returns the buffer untouched.
|
|
20
|
+
*
|
|
21
|
+
* Both CLIs must decide this identically. With renderIn: 'css' the Screenshot
|
|
22
|
+
* component already draws the frame inside the page, so compositing here would add a
|
|
23
|
+
* second frame and change the image's dimensions. check-screenshots used to miss that
|
|
24
|
+
* condition and reported every image as 100% changed against a correct reference.
|
|
25
|
+
*/
|
|
26
|
+
export async function applyChrome(screenshotBuffer, config, url) {
|
|
27
|
+
const { chrome } = config;
|
|
28
|
+
if (chrome.style === 'none' || chrome.renderIn === 'css') return screenshotBuffer;
|
|
29
|
+
return addChrome(screenshotBuffer, {
|
|
30
|
+
url,
|
|
31
|
+
dark: chrome.theme === 'dark',
|
|
32
|
+
showUrl: chrome.showUrl,
|
|
33
|
+
shadowBlur: chrome.shadowBlur,
|
|
34
|
+
shadowPadding: chrome.shadowPadding,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
export async function addChrome(screenshotBuffer, opts = {}) {
|
|
19
39
|
const {
|
|
20
40
|
url = '',
|