Skip to content

Commit 5b8b7cb

Browse files
committed
Separate width, height, and scale between screenshot and screencast
1 parent 78fb46b commit 5b8b7cb

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

lib/handler.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ export async function handleRender(source, options) {
1717
options.type = type;
1818
options.delay = readTime(options.delay, { max: 30 * 1000 }) || 0;
1919
options.time = readTime(options.time, { max: 60 * 1000 }) || 0;
20-
options.scale = Number(options.scale) || (options.time ? 1 : 2);
2120
options.selector ??= 'css-doodle';
2221

23-
options.windowWidth = 1600;
24-
options.windowHeight = 900;
2522
if (options.windowSize) {
2623
const [w, h = w] = options.windowSize.split(/[,x]/);
2724
options.windowWidth = Number(w);
2825
options.windowHeight = Number(h);
2926
}
3027

28+
if (options.scale) {
29+
options.scale = Number(options.scale);
30+
}
31+
3132
if (/\.(mp4|webm)$/.test(options.output) && !options.time) {
3233
options.time = 5 * 1000;
3334
}

lib/render/screencast.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import { randomUUID } from 'node:crypto';
44
import { tmpdir } from 'node:os';
55
import { join } from 'node:path';
66

7+
const defaultWindowWidth = 1200;
8+
const defaultWindowHeight = 900;
9+
const defaultScale = 1;
10+
711
export async function screencast(page, options) {
812
const { scale, output, selector, windowWidth, windowHeight } = options;
13+
const WIDTH = windowWidth || defaultWindowWidth;
14+
const HEIGHT = windowHeight || defaultWindowHeight;
15+
const SCALE = scale || defaultScale;
916

1017
await page.setViewport({
11-
width: windowWidth,
12-
height: windowHeight,
13-
defaultScaleFactor: scale
18+
width: WIDTH,
19+
height: HEIGHT,
20+
defaultScaleFactor: SCALE
1421
});
1522

1623
const crop = await page.evaluate(selector => {

lib/render/screenshot.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
const defaultWindowWidth = 1600;
2+
const defaultWindowHeight = 1200;
3+
const defaultScale = 2;
4+
15
export async function screenshot(page, options = {}) {
26
const { scale, output, selector, windowWidth, windowHeight } = options;
7+
const WIDTH = windowWidth || defaultWindowWidth;
8+
const HEIGHT = windowHeight || defaultWindowHeight;
9+
const SCALE = scale || defaultScale;
310

411
await page.setViewport({
5-
width: windowWidth,
6-
height: windowHeight,
7-
deviceScaleFactor: scale
12+
width: WIDTH,
13+
height: HEIGHT,
14+
deviceScaleFactor: SCALE
815
});
916

1017
const info = await page.evaluate(selector => {
@@ -27,9 +34,9 @@ export async function screenshot(page, options = {}) {
2734
}, selector);
2835

2936
await page.setViewport({
30-
width: Math.ceil(info.width) || windowWidth,
31-
height: Math.ceil(info.height) || windowHeight,
32-
deviceScaleFactor: scale
37+
width: Math.ceil(info.width) || WIDTH,
38+
height: Math.ceil(info.height) || HEIGHT,
39+
deviceScaleFactor: SCALE
3340
});
3441

3542
if (info.node) {

0 commit comments

Comments
 (0)