@gnawbit/tabretake 0.4.2 → 0.5.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/CHANGELOG.md +14 -0
- package/README.md +32 -20
- package/SKILL.md +21 -17
- package/bin/tabretake.mjs +6 -1
- package/package.json +2 -3
- package/references/rendering.md +9 -6
- package/references/story.md +18 -23
- package/schemas/story.schema.json +30 -4
- package/scripts/capture.mjs +598 -0
- package/scripts/cli.mjs +23 -6
- package/scripts/init.mjs +74 -37
- package/scripts/lib/browser.mjs +146 -16
- package/scripts/lib/config.mjs +1 -1
- package/scripts/lib/ffmpeg.mjs +9 -12
- package/scripts/lib/options.mjs +148 -74
- package/scripts/lib/report.mjs +1 -0
- package/scripts/lib/themes.mjs +11 -0
- package/scripts/mark.mjs +516 -0
- package/scripts/plan.mjs +32 -33
- package/scripts/record.mjs +67 -101
- package/scripts/render.mjs +91 -56
- package/scripts/run.mjs +55 -0
- package/README.zh-CN.md +0 -511
- package/bin/demo-reel.mjs +0 -2
package/scripts/record.mjs
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { parseCommand } from "./lib/options.mjs";
|
|
3
|
+
import { parseCommand, parseScale, parseViewport } from "./lib/options.mjs";
|
|
4
4
|
import {
|
|
5
5
|
clickAndType,
|
|
6
6
|
dragBy,
|
|
7
7
|
hover,
|
|
8
8
|
installCursor,
|
|
9
9
|
launchBrowser,
|
|
10
|
+
loginAndSave,
|
|
10
11
|
moveAndClick,
|
|
11
|
-
newContext,
|
|
12
12
|
openRecordedPage,
|
|
13
13
|
resolveLocator,
|
|
14
|
+
selectOption,
|
|
14
15
|
} from "./lib/browser.mjs";
|
|
15
|
-
import { waitForEnter } from "./lib/tty.mjs";
|
|
16
16
|
import { assertConfig, readConfig } from "./lib/config.mjs";
|
|
17
17
|
import { commandError, createReporter, requireInteractiveLogin } from "./lib/report.mjs";
|
|
18
18
|
import { navigate } from "./lib/navigation.mjs";
|
|
19
|
+
import { resolveTheme } from "./lib/themes.mjs";
|
|
19
20
|
|
|
20
|
-
function
|
|
21
|
-
if (value === undefined) return fallback;
|
|
22
|
-
if (!/^[1-9]\d*x[1-9]\d*$/.test(value)) throw new Error("--viewport must be WIDTHxHEIGHT with positive integers");
|
|
23
|
-
const [width, height] = value.split("x").map(Number);
|
|
24
|
-
return { width, height };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function record(argv, command = "record") {
|
|
21
|
+
export async function executeRecord(values, { command = "record", reporter = createReporter(command, Boolean(values?.json)) } = {}) {
|
|
28
22
|
const preview = command === "preview";
|
|
29
|
-
const { values } = parseCommand(command, argv);
|
|
30
|
-
requireInteractiveLogin(values);
|
|
31
|
-
const reporter = createReporter(command, values.json);
|
|
32
23
|
const screenshots = [];
|
|
33
24
|
|
|
34
25
|
if (!values.config && !values.url) {
|
|
@@ -48,11 +39,13 @@ export async function record(argv, command = "record") {
|
|
|
48
39
|
width: 1440,
|
|
49
40
|
height: 810,
|
|
50
41
|
});
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
const scale = parseScale(values.scale, config.scale ?? 1);
|
|
43
|
+
assertConfig({ ...config, url, viewport, scale }, { kind: "story" });
|
|
53
44
|
const steps = config.steps || [];
|
|
54
45
|
if (steps.length === 0) throw new Error("Config has no steps");
|
|
55
46
|
|
|
47
|
+
const theme = resolveTheme(config.brand, values.preset);
|
|
48
|
+
|
|
56
49
|
const outDir = path.resolve(values.out || config.out || "demo");
|
|
57
50
|
const rawDir = path.join(outDir, "raw");
|
|
58
51
|
if (!preview) {
|
|
@@ -75,6 +68,7 @@ export async function record(argv, command = "record") {
|
|
|
75
68
|
headless: preview ? values.headless : !values.headed,
|
|
76
69
|
proxy: values.proxy,
|
|
77
70
|
browser: values.browser,
|
|
71
|
+
scale,
|
|
78
72
|
});
|
|
79
73
|
|
|
80
74
|
let videoPath = null;
|
|
@@ -86,11 +80,12 @@ export async function record(argv, command = "record") {
|
|
|
86
80
|
const videoStartedAt = Date.now();
|
|
87
81
|
const { context, page } = await openRecordedPage(browser, {
|
|
88
82
|
viewport,
|
|
83
|
+
scale,
|
|
89
84
|
videoDir: preview ? undefined : rawDir,
|
|
90
85
|
storageState,
|
|
91
86
|
});
|
|
92
87
|
|
|
93
|
-
await installCursor(page);
|
|
88
|
+
await installCursor(page, { accent: theme.accent });
|
|
94
89
|
|
|
95
90
|
events = [];
|
|
96
91
|
|
|
@@ -104,6 +99,18 @@ export async function record(argv, command = "record") {
|
|
|
104
99
|
for (const [index, step] of steps.entries()) {
|
|
105
100
|
if (preview) reporter.log(`Step ${index + 1}/${steps.length}: ${step.action}`);
|
|
106
101
|
const t = Date.now() - startedAt;
|
|
102
|
+
const pushEvent = (action, point, extra = {}, timeEnd = Date.now() - startedAt) => {
|
|
103
|
+
events.push({
|
|
104
|
+
t,
|
|
105
|
+
tEnd: timeEnd,
|
|
106
|
+
zoom: step.zoom !== false,
|
|
107
|
+
action,
|
|
108
|
+
x: point.x,
|
|
109
|
+
y: point.y,
|
|
110
|
+
caption: step.caption || "",
|
|
111
|
+
...extra,
|
|
112
|
+
});
|
|
113
|
+
};
|
|
107
114
|
|
|
108
115
|
try {
|
|
109
116
|
switch (step.action) {
|
|
@@ -122,16 +129,7 @@ export async function record(argv, command = "record") {
|
|
|
122
129
|
case "click": {
|
|
123
130
|
const locator = await resolveLocator(page, step);
|
|
124
131
|
const point = await moveAndClick(page, locator, 0, Number(step.timeout ?? 20000));
|
|
125
|
-
|
|
126
|
-
t,
|
|
127
|
-
tEnd: Date.now() - startedAt,
|
|
128
|
-
zoom: step.zoom !== false,
|
|
129
|
-
action: "click",
|
|
130
|
-
x: point.x,
|
|
131
|
-
y: point.y,
|
|
132
|
-
caption: step.caption || "",
|
|
133
|
-
label: step.text || step.name || step.selector || "",
|
|
134
|
-
});
|
|
132
|
+
pushEvent("click", point, { label: step.text || step.name || step.selector || "" });
|
|
135
133
|
await page.waitForTimeout(Number(step.pause ?? 700));
|
|
136
134
|
break;
|
|
137
135
|
}
|
|
@@ -140,33 +138,24 @@ export async function record(argv, command = "record") {
|
|
|
140
138
|
const locator = await resolveLocator(page, step);
|
|
141
139
|
const value = String(step.value ?? step.text ?? "");
|
|
142
140
|
const point = await clickAndType(page, locator, value, 0);
|
|
143
|
-
|
|
144
|
-
t,
|
|
145
|
-
tEnd: Date.now() - startedAt,
|
|
146
|
-
zoom: step.zoom !== false,
|
|
147
|
-
action: "type",
|
|
148
|
-
x: point.x,
|
|
149
|
-
y: point.y,
|
|
150
|
-
caption: step.caption || "",
|
|
151
|
-
label: value,
|
|
152
|
-
});
|
|
141
|
+
pushEvent("type", point, { label: value });
|
|
153
142
|
await page.waitForTimeout(Number(step.pause ?? 400));
|
|
154
143
|
break;
|
|
155
144
|
}
|
|
156
145
|
|
|
146
|
+
case "select": {
|
|
147
|
+
const locator = await resolveLocator(page, step);
|
|
148
|
+
const value = String(step.value ?? step.text ?? "");
|
|
149
|
+
const point = await selectOption(page, locator, value, 0, Number(step.timeout ?? 20000));
|
|
150
|
+
pushEvent("select", point, { label: value });
|
|
151
|
+
await page.waitForTimeout(Number(step.pause ?? 500));
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
|
|
157
155
|
case "hover": {
|
|
158
156
|
const locator = await resolveLocator(page, step);
|
|
159
157
|
const point = await hover(page, locator, 0);
|
|
160
|
-
|
|
161
|
-
t,
|
|
162
|
-
tEnd: Date.now() - startedAt,
|
|
163
|
-
zoom: step.zoom !== false,
|
|
164
|
-
action: "hover",
|
|
165
|
-
x: point.x,
|
|
166
|
-
y: point.y,
|
|
167
|
-
caption: step.caption || "",
|
|
168
|
-
label: step.text || step.selector || "",
|
|
169
|
-
});
|
|
158
|
+
pushEvent("hover", point, { label: step.text || step.selector || "" });
|
|
170
159
|
await page.waitForTimeout(Number(step.pause ?? 500));
|
|
171
160
|
break;
|
|
172
161
|
}
|
|
@@ -179,12 +168,10 @@ export async function record(argv, command = "record") {
|
|
|
179
168
|
throw commandError("TARGET_NOT_FOUND", "The focus target has no visible area.");
|
|
180
169
|
}
|
|
181
170
|
const focusedAt = Date.now() - startedAt;
|
|
182
|
-
|
|
183
|
-
t: focusedAt,
|
|
184
|
-
x: box.x + box.width / 2, y: box.y + box.height / 2,
|
|
185
|
-
zoom: step.zoom !== false, caption: step.caption || "",
|
|
171
|
+
pushEvent("focus", { x: box.x + box.width / 2, y: box.y + box.height / 2 }, {
|
|
172
|
+
t: focusedAt,
|
|
186
173
|
label: step.text || step.name || step.selector || "",
|
|
187
|
-
});
|
|
174
|
+
}, focusedAt);
|
|
188
175
|
await page.waitForTimeout(Number(step.pause ?? 700));
|
|
189
176
|
break;
|
|
190
177
|
}
|
|
@@ -199,16 +186,7 @@ export async function record(argv, command = "record") {
|
|
|
199
186
|
Number(step.steps || 24),
|
|
200
187
|
0,
|
|
201
188
|
);
|
|
202
|
-
|
|
203
|
-
t,
|
|
204
|
-
tEnd: Date.now() - startedAt,
|
|
205
|
-
zoom: step.zoom !== false,
|
|
206
|
-
action: "drag",
|
|
207
|
-
x: point.x,
|
|
208
|
-
y: point.y,
|
|
209
|
-
caption: step.caption || "",
|
|
210
|
-
label: step.selector || "",
|
|
211
|
-
});
|
|
189
|
+
pushEvent("drag", point, { label: step.selector || "" });
|
|
212
190
|
await page.waitForTimeout(Number(step.pause ?? 600));
|
|
213
191
|
break;
|
|
214
192
|
}
|
|
@@ -218,30 +196,14 @@ export async function record(argv, command = "record") {
|
|
|
218
196
|
await page.evaluate((dy) => {
|
|
219
197
|
window.scrollBy({ top: dy, behavior: "smooth" });
|
|
220
198
|
}, y);
|
|
221
|
-
|
|
222
|
-
t,
|
|
223
|
-
tEnd: Date.now() - startedAt,
|
|
224
|
-
zoom: step.zoom !== false,
|
|
225
|
-
action: "scroll",
|
|
226
|
-
x: viewport.width / 2,
|
|
227
|
-
y: viewport.height / 2,
|
|
228
|
-
caption: step.caption || "",
|
|
229
|
-
});
|
|
199
|
+
pushEvent("scroll", { x: viewport.width / 2, y: viewport.height / 2 });
|
|
230
200
|
await page.waitForTimeout(Number(step.pause ?? 700));
|
|
231
201
|
break;
|
|
232
202
|
}
|
|
233
203
|
|
|
234
204
|
case "press": {
|
|
235
205
|
await page.keyboard.press(step.key || "Enter");
|
|
236
|
-
|
|
237
|
-
t,
|
|
238
|
-
tEnd: Date.now() - startedAt,
|
|
239
|
-
zoom: step.zoom !== false,
|
|
240
|
-
action: "press",
|
|
241
|
-
x: viewport.width / 2,
|
|
242
|
-
y: viewport.height / 2,
|
|
243
|
-
caption: step.caption || "",
|
|
244
|
-
});
|
|
206
|
+
pushEvent("press", { x: viewport.width / 2, y: viewport.height / 2 });
|
|
245
207
|
await page.waitForTimeout(Number(step.pause ?? 500));
|
|
246
208
|
break;
|
|
247
209
|
}
|
|
@@ -303,8 +265,11 @@ export async function record(argv, command = "record") {
|
|
|
303
265
|
|
|
304
266
|
if (preview) {
|
|
305
267
|
reporter.log(`Preview completed ${steps.length} step(s).`);
|
|
306
|
-
|
|
307
|
-
|
|
268
|
+
return {
|
|
269
|
+
summary: { duration: timelineDuration, stepCount: steps.length, artifacts: screenshots },
|
|
270
|
+
record: null,
|
|
271
|
+
recordPath: null,
|
|
272
|
+
};
|
|
308
273
|
}
|
|
309
274
|
|
|
310
275
|
const recordingPath = path.join(outDir, "recording.webm");
|
|
@@ -329,26 +294,27 @@ export async function record(argv, command = "record") {
|
|
|
329
294
|
reporter.log(`Record: ${recordPath}`);
|
|
330
295
|
reporter.log(`\nNext: tabretake render --config ${path.relative(process.cwd(), recordPath)}`);
|
|
331
296
|
reporter.log(` (or pass the original --config path)\n`);
|
|
332
|
-
await reporter.success({ duration: timelineDuration, eventCount: events.length, artifacts: [
|
|
333
|
-
{ kind: "video", path: recordingPath }, { kind: "timeline", path: recordPath }, ...screenshots,
|
|
334
|
-
] });
|
|
335
297
|
|
|
336
|
-
return
|
|
298
|
+
return {
|
|
299
|
+
summary: {
|
|
300
|
+
duration: timelineDuration,
|
|
301
|
+
eventCount: events.length,
|
|
302
|
+
artifacts: [
|
|
303
|
+
{ kind: "video", path: recordingPath },
|
|
304
|
+
{ kind: "timeline", path: recordPath },
|
|
305
|
+
...screenshots,
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
record,
|
|
309
|
+
recordPath,
|
|
310
|
+
};
|
|
337
311
|
}
|
|
338
312
|
|
|
339
|
-
async function
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
await waitForEnter("Press Enter when you are logged in... ");
|
|
347
|
-
await context.storageState({ path: statePath });
|
|
348
|
-
console.log(`Saved login state to ${statePath}\n`);
|
|
349
|
-
await context.close();
|
|
350
|
-
return statePath;
|
|
351
|
-
} finally {
|
|
352
|
-
await browser.close();
|
|
353
|
-
}
|
|
313
|
+
export async function record(argv, command = "record") {
|
|
314
|
+
const { values } = parseCommand(command, argv);
|
|
315
|
+
requireInteractiveLogin(values);
|
|
316
|
+
const reporter = createReporter(command, values.json);
|
|
317
|
+
const result = await executeRecord(values, { command, reporter });
|
|
318
|
+
await reporter.success(result.summary);
|
|
319
|
+
return result.record;
|
|
354
320
|
}
|
package/scripts/render.mjs
CHANGED
|
@@ -2,13 +2,13 @@ import { mkdir } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parseCommand } from "./lib/options.mjs";
|
|
4
4
|
import sharp from "sharp";
|
|
5
|
-
import { ffmpeg,
|
|
5
|
+
import { ffmpeg, probeVideoMeta } from "./lib/ffmpeg.mjs";
|
|
6
6
|
import { findCjkFont, findFont, hasCjk } from "./lib/fonts.mjs";
|
|
7
7
|
import { buildCameraFilter } from "./lib/camera.mjs";
|
|
8
8
|
import { createCaptionLayers } from "./lib/captions.mjs";
|
|
9
9
|
import { assertConfig, readConfig } from "./lib/config.mjs";
|
|
10
10
|
import { createReporter } from "./lib/report.mjs";
|
|
11
|
-
import { resolveTheme } from "./lib/themes.mjs";
|
|
11
|
+
import { hexToRgb, resolveTheme } from "./lib/themes.mjs";
|
|
12
12
|
|
|
13
13
|
const LAYOUTS = {
|
|
14
14
|
landscape: {
|
|
@@ -58,15 +58,17 @@ function landscapeLayout(videoW, videoH) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function verticalLayout(videoW, videoH) {
|
|
61
|
+
function verticalLayout(videoW, videoH, frameMode = "auto") {
|
|
62
62
|
const layout = LAYOUTS.vertical;
|
|
63
63
|
// Fit the source between branding and captions instead of cropping a phone
|
|
64
64
|
// recording into the landscape card. Keep the existing 16:9 card geometry.
|
|
65
|
-
const
|
|
65
|
+
const maxHeight = frameMode === "phone" ? 800 : 900;
|
|
66
|
+
const centerY = frameMode === "phone" ? 920 : layout.content.y + layout.content.h / 2;
|
|
67
|
+
const fit = Math.min(layout.content.w / videoW, maxHeight / videoH);
|
|
66
68
|
const w = Math.max(2, Math.floor(videoW * fit / 2) * 2);
|
|
67
69
|
const h = Math.max(2, Math.floor(videoH * fit / 2) * 2);
|
|
68
70
|
const x = (layout.width - w) / 2;
|
|
69
|
-
const y =
|
|
71
|
+
const y = centerY - h / 2;
|
|
70
72
|
return {
|
|
71
73
|
...layout,
|
|
72
74
|
content: { x, y, w, h },
|
|
@@ -74,14 +76,6 @@ function verticalLayout(videoW, videoH) {
|
|
|
74
76
|
};
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
function hexToRgb(hex) {
|
|
78
|
-
const clean = String(hex || "#070A12").replace("#", "");
|
|
79
|
-
const full =
|
|
80
|
-
clean.length === 3 ? clean.split("").map((c) => c + c).join("") : clean;
|
|
81
|
-
const n = parseInt(full, 16);
|
|
82
|
-
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
79
|
function mix(hex, target, amount) {
|
|
86
80
|
const a = hexToRgb(hex);
|
|
87
81
|
const b = hexToRgb(target);
|
|
@@ -163,8 +157,10 @@ async function makeBackground(file, theme, layout) {
|
|
|
163
157
|
async function makeBrowserFrame(file, hostname, layout, theme) {
|
|
164
158
|
const url = escapeXml(hostname || "your-app.com");
|
|
165
159
|
const { x, y, w, h } = layout.frame;
|
|
166
|
-
const
|
|
160
|
+
const { x: cx, y: cy, w: cw, h: ch } = layout.content;
|
|
161
|
+
const bar = cy - y;
|
|
167
162
|
const f = theme.frame;
|
|
163
|
+
const r = 8;
|
|
168
164
|
const addressWidth = Math.max(0, Math.min(560, w - 128));
|
|
169
165
|
const address = addressWidth >= 120 ? `
|
|
170
166
|
<clipPath id="address-clip"><rect x="${x + 114}" y="${y + 13}" width="${addressWidth - 20}" height="26"/></clipPath>
|
|
@@ -179,11 +175,12 @@ async function makeBrowserFrame(file, hostname, layout, theme) {
|
|
|
179
175
|
</filter>
|
|
180
176
|
<mask id="content-cutout">
|
|
181
177
|
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
182
|
-
<
|
|
178
|
+
<path d="M${cx} ${cy}H${cx + cw}V${cy + ch - r}a${r} ${r} 0 0 1 -${r} ${r}H${cx + r}a${r} ${r} 0 0 1 -${r} -${r}Z" fill="black"/>
|
|
183
179
|
</mask>
|
|
184
180
|
</defs>
|
|
185
181
|
<g mask="url(#content-cutout)">
|
|
186
182
|
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.85 : 0.25}"/>
|
|
183
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="${f.bar}"/>
|
|
187
184
|
<path d="M${x} ${y + 18}a18 18 0 0 1 18-18h${w - 36}a18 18 0 0 1 18 18v${bar - 18}H${x}z" fill="${f.bar}"/>
|
|
188
185
|
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="none" stroke="${f.border}" stroke-width="1.5"/>
|
|
189
186
|
<path d="M${x} ${y + bar}H${x + w}" stroke="${f.divider}" stroke-width="1"/>
|
|
@@ -200,6 +197,7 @@ async function makeBrowserFrame(file, hostname, layout, theme) {
|
|
|
200
197
|
|
|
201
198
|
async function makeCardFrame(file, layout, theme) {
|
|
202
199
|
const { x, y, w, h } = layout.frame;
|
|
200
|
+
const { x: cx, y: cy, w: cw, h: ch } = layout.content;
|
|
203
201
|
const f = theme.frame;
|
|
204
202
|
|
|
205
203
|
const svg = `
|
|
@@ -214,11 +212,12 @@ async function makeCardFrame(file, layout, theme) {
|
|
|
214
212
|
</linearGradient>
|
|
215
213
|
<mask id="content-cutout">
|
|
216
214
|
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
217
|
-
<rect x="${
|
|
215
|
+
<rect x="${cx}" y="${cy}" width="${cw}" height="${ch}" rx="12" fill="black"/>
|
|
218
216
|
</mask>
|
|
219
217
|
</defs>
|
|
220
218
|
<g mask="url(#content-cutout)">
|
|
221
219
|
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.75 : 0.3}"/>
|
|
220
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="${f.bar}"/>
|
|
222
221
|
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="none" stroke="${f.border}" stroke-width="1.5"/>
|
|
223
222
|
<rect x="${x + 1.5}" y="${y + 1.5}" width="${w - 3}" height="${h - 3}" rx="20.5" fill="none" stroke="url(#edge)" stroke-width="1"/>
|
|
224
223
|
<path d="M${x + 24} ${y + 1.5}H${x + w - 24}" stroke="#ffffff" stroke-opacity="0.10" stroke-width="1"/>
|
|
@@ -228,6 +227,43 @@ async function makeCardFrame(file, layout, theme) {
|
|
|
228
227
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
229
228
|
}
|
|
230
229
|
|
|
230
|
+
async function makePhoneFrame(file, layout, theme) {
|
|
231
|
+
const { x: cx, y: cy, w: cw, h: ch } = layout.content;
|
|
232
|
+
const f = theme.frame;
|
|
233
|
+
const padX = 16;
|
|
234
|
+
const padTop = Math.min(34, Math.max(16, cy - 16));
|
|
235
|
+
const maxBottom = layout.caption ? Math.max(16, layout.caption.y - 12 - (cy + ch)) : 34;
|
|
236
|
+
const padBottom = Math.min(34, maxBottom);
|
|
237
|
+
const x = cx - padX;
|
|
238
|
+
const y = cy - padTop;
|
|
239
|
+
const w = cw + padX * 2;
|
|
240
|
+
const h = ch + padTop + padBottom;
|
|
241
|
+
const speakerW = Math.min(72, Math.max(36, Math.round(cw * 0.14)));
|
|
242
|
+
|
|
243
|
+
const svg = `
|
|
244
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
245
|
+
<defs>
|
|
246
|
+
<filter id="shadow" x="-30%" y="-30%" width="160%" height="160%">
|
|
247
|
+
<feDropShadow dx="0" dy="28" stdDeviation="36" flood-color="#000000" flood-opacity="${f.shadowAlpha}"/>
|
|
248
|
+
</filter>
|
|
249
|
+
<mask id="content-cutout">
|
|
250
|
+
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
251
|
+
<rect x="${cx}" y="${cy}" width="${cw}" height="${ch}" rx="20" fill="black"/>
|
|
252
|
+
</mask>
|
|
253
|
+
</defs>
|
|
254
|
+
<g mask="url(#content-cutout)">
|
|
255
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="38" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.85 : 0.4}"/>
|
|
256
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="38" fill="${f.bar}"/>
|
|
257
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="38" fill="none" stroke="${f.border}" stroke-width="2"/>
|
|
258
|
+
<rect x="${cx - 1}" y="${cy - 1}" width="${cw + 2}" height="${ch + 2}" rx="20" fill="none" stroke="${f.divider}" stroke-width="1"/>
|
|
259
|
+
<rect x="${cx + (cw - speakerW) / 2}" y="${y + padTop / 2 - 2.5}" width="${speakerW}" height="5" rx="2.5" fill="${f.addressBorder}"/>
|
|
260
|
+
<circle cx="${cx + cw / 2 + speakerW / 2 + 12}" cy="${y + padTop / 2}" r="3" fill="${f.addressBorder}"/>
|
|
261
|
+
</g>
|
|
262
|
+
</svg>`;
|
|
263
|
+
|
|
264
|
+
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
265
|
+
}
|
|
266
|
+
|
|
231
267
|
function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, theme) {
|
|
232
268
|
if (!font || !layout.title) return "";
|
|
233
269
|
|
|
@@ -321,12 +357,18 @@ async function renderLayout({
|
|
|
321
357
|
|
|
322
358
|
const bgPath = path.join(assetsDir, `background-${layout.key}.png`);
|
|
323
359
|
const framePath = path.join(assetsDir, `frame-${layout.key}.png`);
|
|
360
|
+
const frameMode = record.config?.brand?.frame || "auto";
|
|
361
|
+
const hasFrame = frameMode !== "none";
|
|
324
362
|
|
|
325
363
|
await makeBackground(bgPath, theme, layout);
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
364
|
+
if (hasFrame) {
|
|
365
|
+
if (frameMode === "phone" && (layout.key === "vertical" || videoW <= videoH)) {
|
|
366
|
+
await makePhoneFrame(framePath, layout, theme);
|
|
367
|
+
} else if (frameMode === "browser" || (frameMode === "auto" && layout.frame.type === "browser")) {
|
|
368
|
+
await makeBrowserFrame(framePath, hostname, layout, theme);
|
|
369
|
+
} else {
|
|
370
|
+
await makeCardFrame(framePath, layout, theme);
|
|
371
|
+
}
|
|
330
372
|
}
|
|
331
373
|
|
|
332
374
|
const camera = buildCameraFilter({
|
|
@@ -356,12 +398,13 @@ async function renderLayout({
|
|
|
356
398
|
const graph = [
|
|
357
399
|
`[0:v]scale=${layout.width}:${layout.height}[bg]`,
|
|
358
400
|
`[1:v]${camera.filter}[base]`,
|
|
359
|
-
`[bg][base]overlay=${layout.content.x}:${layout.content.y}:format=auto[comp]`,
|
|
360
|
-
`[comp][2:v]overlay=0:0[out]`,
|
|
401
|
+
`[bg][base]overlay=${layout.content.x}:${layout.content.y}:format=auto[${hasFrame ? "comp" : "out"}]`,
|
|
361
402
|
];
|
|
403
|
+
if (hasFrame) graph.push(`[comp][2:v]overlay=0:0[out]`);
|
|
404
|
+
const captionInputOffset = hasFrame ? 3 : 2;
|
|
362
405
|
let lastLayer = "out";
|
|
363
406
|
captions.forEach((caption, i) => {
|
|
364
|
-
graph.push(`[${lastLayer}][${i +
|
|
407
|
+
graph.push(`[${lastLayer}][${i + captionInputOffset}:v]overlay=${caption.x}:${caption.y}:` +
|
|
365
408
|
`enable='gte(t,${caption.start})*lt(t,${caption.end})'[caption${i}]`);
|
|
366
409
|
lastLayer = `caption${i}`;
|
|
367
410
|
});
|
|
@@ -371,7 +414,7 @@ async function renderLayout({
|
|
|
371
414
|
await ffmpeg([
|
|
372
415
|
"-loop", "1", "-framerate", "30", "-i", bgPath,
|
|
373
416
|
"-i", videoPath,
|
|
374
|
-
"-i", framePath,
|
|
417
|
+
...(hasFrame ? ["-i", framePath] : []),
|
|
375
418
|
...captions.flatMap((caption) => ["-i", caption.file]),
|
|
376
419
|
"-filter_complex", graph.join(";"),
|
|
377
420
|
"-map", "[v]",
|
|
@@ -439,10 +482,7 @@ function marksToEvents(marks, videoW, videoH) {
|
|
|
439
482
|
.sort((a, b) => a.t - b.t);
|
|
440
483
|
}
|
|
441
484
|
|
|
442
|
-
export async function render(
|
|
443
|
-
const { values } = parseCommand("render", argv);
|
|
444
|
-
const reporter = createReporter("render", values.json);
|
|
445
|
-
|
|
485
|
+
export async function executeRender(values, { reporter = createReporter("render", Boolean(values?.json)) } = {}) {
|
|
446
486
|
if (!values.config) throw new Error("Missing --config");
|
|
447
487
|
|
|
448
488
|
const configPath = path.resolve(values.config);
|
|
@@ -453,31 +493,22 @@ export async function render(argv) {
|
|
|
453
493
|
let record;
|
|
454
494
|
let outDir;
|
|
455
495
|
let videoPath;
|
|
456
|
-
let
|
|
496
|
+
let videoMeta = null;
|
|
457
497
|
|
|
458
498
|
if (isMarkConfig) {
|
|
459
499
|
videoPath = videoOverride || path.resolve(path.dirname(configPath), raw.video);
|
|
460
500
|
outDir = values.out ? path.resolve(values.out) : path.resolve(raw.out || "demo");
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const stream = (probed.streams || []).find((s) => s.codec_type === "video");
|
|
464
|
-
const videoW = Number(stream?.width || 0);
|
|
465
|
-
const videoH = Number(stream?.height || 0);
|
|
466
|
-
const videoDurationSec = Number(probed.format?.duration || 0);
|
|
467
|
-
|
|
468
|
-
if (!videoW || !videoH || !videoDurationSec) {
|
|
469
|
-
throw new Error(`Could not read video metadata: ${videoPath}`);
|
|
470
|
-
}
|
|
501
|
+
videoMeta = await probeVideoMeta(videoPath);
|
|
471
502
|
|
|
472
503
|
record = {
|
|
473
504
|
config: raw,
|
|
474
505
|
url: raw.url || raw.displayUrl || "screen-recording",
|
|
475
|
-
viewport: raw.viewport || { width:
|
|
506
|
+
viewport: raw.viewport || { width: videoMeta.width, height: videoMeta.height },
|
|
476
507
|
scale: 1,
|
|
477
508
|
video: videoPath,
|
|
478
509
|
videoOffset: 0,
|
|
479
|
-
duration: Number(raw.duration ||
|
|
480
|
-
events: marksToEvents(raw.marks,
|
|
510
|
+
duration: Number(raw.duration || videoMeta.duration),
|
|
511
|
+
events: marksToEvents(raw.marks, videoMeta.width, videoMeta.height),
|
|
481
512
|
};
|
|
482
513
|
} else {
|
|
483
514
|
record = raw;
|
|
@@ -506,15 +537,8 @@ export async function render(argv) {
|
|
|
506
537
|
}
|
|
507
538
|
})();
|
|
508
539
|
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
const videoW = Number(videoStream?.width || 0);
|
|
512
|
-
const videoH = Number(videoStream?.height || 0);
|
|
513
|
-
const videoDurationSec = Number(info.format?.duration || 0);
|
|
514
|
-
|
|
515
|
-
if (!videoW || !videoH || !videoDurationSec) {
|
|
516
|
-
throw new Error(`Could not read video metadata: ${videoPath}`);
|
|
517
|
-
}
|
|
540
|
+
const { width: videoW, height: videoH, duration: videoDurationSec } =
|
|
541
|
+
videoMeta || (await probeVideoMeta(videoPath));
|
|
518
542
|
|
|
519
543
|
const videoOffset = Math.max(0, Number(record.videoOffset || 0));
|
|
520
544
|
const timelineDuration = Number(record.duration || videoDurationSec - videoOffset);
|
|
@@ -556,16 +580,17 @@ export async function render(argv) {
|
|
|
556
580
|
const font = values["no-captions"] ? null : findFont();
|
|
557
581
|
const cjkFont = values["no-captions"] ? null : findCjkFont();
|
|
558
582
|
if (!values["no-captions"] && !font) {
|
|
559
|
-
|
|
583
|
+
reporter.warn("No system font found; captions will be skipped.");
|
|
560
584
|
}
|
|
561
585
|
if (!values["no-captions"] && !cjkFont) {
|
|
562
|
-
|
|
586
|
+
reporter.warn("No CJK font found; Chinese captions may render as boxes.");
|
|
563
587
|
}
|
|
564
588
|
|
|
565
589
|
const theme = resolveTheme(record.config?.brand, values.preset);
|
|
590
|
+
const frameMode = record.config?.brand?.frame || "auto";
|
|
566
591
|
|
|
567
592
|
const layouts = [landscapeLayout(videoW, videoH)];
|
|
568
|
-
if (values.vertical) layouts.push(verticalLayout(videoW, videoH));
|
|
593
|
+
if (values.vertical) layouts.push(verticalLayout(videoW, videoH, frameMode));
|
|
569
594
|
|
|
570
595
|
let last = null;
|
|
571
596
|
const artifacts = [];
|
|
@@ -597,6 +622,16 @@ export async function render(argv) {
|
|
|
597
622
|
(values.vertical ? ", 16:9 + 9:16" : "") +
|
|
598
623
|
".\n",
|
|
599
624
|
);
|
|
600
|
-
|
|
601
|
-
|
|
625
|
+
return {
|
|
626
|
+
summary: { duration: durationSec, posterAt, artifacts },
|
|
627
|
+
outputPath: last?.outputPath,
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export async function render(argv) {
|
|
632
|
+
const { values } = parseCommand("render", argv);
|
|
633
|
+
const reporter = createReporter("render", values.json);
|
|
634
|
+
const result = await executeRender(values, { reporter });
|
|
635
|
+
await reporter.success(result.summary);
|
|
636
|
+
return result.outputPath;
|
|
602
637
|
}
|
package/scripts/run.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parseCommand } from "./lib/options.mjs";
|
|
3
|
+
import { assertConfig, inspectConfig, readConfig } from "./lib/config.mjs";
|
|
4
|
+
import { createReporter, requireInteractiveLogin } from "./lib/report.mjs";
|
|
5
|
+
import { executeRecord } from "./record.mjs";
|
|
6
|
+
import { executeRender } from "./render.mjs";
|
|
7
|
+
|
|
8
|
+
export async function runPipeline(values, { reporter = createReporter("run", Boolean(values?.json)) } = {}) {
|
|
9
|
+
if (!values.config) {
|
|
10
|
+
throw new Error("Provide --config demo.json");
|
|
11
|
+
}
|
|
12
|
+
const configPath = path.resolve(values.config);
|
|
13
|
+
const raw = await readConfig(configPath);
|
|
14
|
+
const inspected = inspectConfig(raw);
|
|
15
|
+
if (!inspected.ok) {
|
|
16
|
+
assertConfig(raw);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const artifacts = [];
|
|
20
|
+
let eventCount;
|
|
21
|
+
let renderConfigPath = configPath;
|
|
22
|
+
|
|
23
|
+
if (inspected.kind === "story") {
|
|
24
|
+
const recordRes = await executeRecord(values, { command: "record", reporter });
|
|
25
|
+
artifacts.push(...recordRes.summary.artifacts);
|
|
26
|
+
eventCount = recordRes.summary.eventCount;
|
|
27
|
+
renderConfigPath = recordRes.recordPath;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const renderValues = {
|
|
31
|
+
...values,
|
|
32
|
+
config: renderConfigPath,
|
|
33
|
+
out: values.out || (inspected.kind === "story" ? path.dirname(renderConfigPath) : undefined),
|
|
34
|
+
};
|
|
35
|
+
const renderRes = await executeRender(renderValues, { reporter });
|
|
36
|
+
artifacts.push(...renderRes.summary.artifacts);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
duration: renderRes.summary.duration,
|
|
40
|
+
posterAt: renderRes.summary.posterAt,
|
|
41
|
+
...(eventCount !== undefined ? { eventCount } : {}),
|
|
42
|
+
artifacts,
|
|
43
|
+
outputPath: renderRes.outputPath,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function run(argv) {
|
|
48
|
+
const { values } = parseCommand("run", argv);
|
|
49
|
+
requireInteractiveLogin(values);
|
|
50
|
+
const reporter = createReporter("run", values.json);
|
|
51
|
+
const result = await runPipeline(values, { reporter });
|
|
52
|
+
const { outputPath, ...summary } = result;
|
|
53
|
+
await reporter.success(summary);
|
|
54
|
+
return outputPath;
|
|
55
|
+
}
|