@phil65/demoreel 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +207 -2
- package/THIRD_PARTY_NOTICES.md +31 -0
- package/dist/args.d.ts +41 -0
- package/dist/args.js +252 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +468 -0
- package/dist/compose.d.ts +73 -0
- package/dist/compose.js +144 -0
- package/dist/env.d.ts +38 -0
- package/dist/env.js +182 -0
- package/dist/idle.d.ts +48 -0
- package/dist/idle.js +99 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/init.d.ts +19 -0
- package/dist/init.js +92 -0
- package/dist/layout.d.ts +52 -0
- package/dist/layout.js +55 -0
- package/dist/load.d.ts +2 -0
- package/dist/load.js +76 -0
- package/dist/marks.d.ts +69 -0
- package/dist/marks.js +153 -0
- package/dist/motion.d.ts +15 -0
- package/dist/motion.js +49 -0
- package/dist/openscreen/project.js +793 -0
- package/dist/openscreen.d.ts +14 -0
- package/dist/openscreen.js +41 -0
- package/dist/project.d.ts +143 -0
- package/dist/project.js +144 -0
- package/dist/record.d.ts +90 -0
- package/dist/record.js +189 -0
- package/dist/recorder.d.ts +41 -0
- package/dist/recorder.js +149 -0
- package/dist/render.d.ts +58 -0
- package/dist/render.js +139 -0
- package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +23 -0
- package/dist/renderer/assets/Cursor_App-Starting-zEGhqPJj.svg +8 -0
- package/dist/renderer/assets/Cursor_Cross-BuZZnB_U.svg +5 -0
- package/dist/renderer/assets/Cursor_Default-DkmrqhKh.svg +5 -0
- package/dist/renderer/assets/Cursor_Hand-(Grabbing)-B-Qy-RsV.svg +5 -0
- package/dist/renderer/assets/Cursor_Hand-(Open)-DGrW1tFF.svg +5 -0
- package/dist/renderer/assets/Cursor_Hand-(Pointing)-Byy2KbtA.svg +5 -0
- package/dist/renderer/assets/Cursor_Help-D5NcyFpT.svg +8 -0
- package/dist/renderer/assets/Cursor_Move-CerM5f-0.svg +5 -0
- package/dist/renderer/assets/Cursor_Not-Allowed-3rttFVa5.svg +7 -0
- package/dist/renderer/assets/Cursor_Resize-North-East-South-West-CBd4tbCA.svg +5 -0
- package/dist/renderer/assets/Cursor_Resize-North-South-DOxgUIwF.svg +5 -0
- package/dist/renderer/assets/Cursor_Resize-North-West-South-East-hzXJFJ2_.svg +5 -0
- package/dist/renderer/assets/Cursor_Resize-West-East-rDJgc6AZ.svg +5 -0
- package/dist/renderer/assets/Cursor_Text-Cursor-Cn9rFLjY.svg +5 -0
- package/dist/renderer/assets/Cursor_Up-Arrow-CYyEN-dA.svg +4 -0
- package/dist/renderer/assets/Cursor_Wait-CK8tq-9y.svg +6 -0
- package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +404 -0
- package/dist/renderer/assets/browserAll-aHn2isHo.js +14 -0
- package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +1 -0
- package/dist/renderer/assets/getTexelRangeRects-yD6MQ0xy.js +195 -0
- package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +1 -0
- package/dist/renderer/assets/gif.worker-CjkyQP34.js +3 -0
- package/dist/renderer/assets/index-BwP6rH7I.js +556 -0
- package/dist/renderer/assets/init-C2Za5NQh.js +83 -0
- package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +1 -0
- package/dist/renderer/index.html +13 -0
- package/dist/renderer/wallpapers/wallpaper1.jpg +0 -0
- package/dist/renderer/wallpapers/wallpaper12.jpg +0 -0
- package/dist/renderer/wallpapers/wallpaper5.jpg +0 -0
- package/dist/renderer/wasm/web-demuxer.wasm +0 -0
- package/dist/scene.d.ts +203 -0
- package/dist/scene.js +634 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +116 -0
- package/dist/sheet.d.ts +37 -0
- package/dist/sheet.js +98 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.js +2 -0
- package/dist/zoom.d.ts +57 -0
- package/dist/zoom.js +178 -0
- package/examples/demo-app/index.html +99 -0
- package/examples/local-demo.ts +21 -0
- package/licenses/colord.txt +21 -0
- package/licenses/earcut.txt +15 -0
- package/licenses/eventemitter3.txt +21 -0
- package/licenses/gif.js.txt +1 -0
- package/licenses/ismobilejs.txt +21 -0
- package/licenses/mediabunny.txt +373 -0
- package/licenses/motion-dom.txt +21 -0
- package/licenses/motion-utils.txt +21 -0
- package/licenses/openscreen.txt +21 -0
- package/licenses/parse-svg-path.txt +23 -0
- package/licenses/pixi-filters.txt +21 -0
- package/licenses/pixi.js.txt +21 -0
- package/licenses/web-demuxer.txt +21 -0
- package/package.json +74 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** demoreel CLI. See `demoreel --help`. */
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { COMMANDS, gpuMode, helpText, parseArgs, parseJsonFlag, parseSize, UsageError } from "./args.js";
|
|
7
|
+
import { readTimeline, rezoom } from "./compose.js";
|
|
8
|
+
import { checkFfmpeg, DemoreelError, detectGpu, launchChromium } from "./env.js";
|
|
9
|
+
import { initProject } from "./init.js";
|
|
10
|
+
import { loadScenario } from "./load.js";
|
|
11
|
+
import { PACKAGE_ROOT } from "./openscreen.js";
|
|
12
|
+
import { dryRunScenario, recordScenario, resolveStorageState } from "./record.js";
|
|
13
|
+
import { renderProject, validateProject } from "./render.js";
|
|
14
|
+
import { findFramesheet, reviewSheet } from "./sheet.js";
|
|
15
|
+
const fmt = (ms) => `${(ms / 1000).toFixed(1)}s`;
|
|
16
|
+
const log = (msg) => console.error(msg);
|
|
17
|
+
function progressPrinter(enabled) {
|
|
18
|
+
let last = -1;
|
|
19
|
+
return (p) => {
|
|
20
|
+
if (!enabled)
|
|
21
|
+
return;
|
|
22
|
+
const step = Math.floor(p / 10) * 10;
|
|
23
|
+
if (step !== last) {
|
|
24
|
+
last = step;
|
|
25
|
+
if (process.stderr.isTTY)
|
|
26
|
+
process.stderr.write(`\r rendering ${step}%${step >= 100 ? "\n" : ""}`);
|
|
27
|
+
else if (step % 25 === 0 || step >= 100)
|
|
28
|
+
log(` rendering ${step}%`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function printRender(r) {
|
|
33
|
+
log(` rendered ${r.width}x${r.height} ${(r.bytes / 1e6).toFixed(1)} MB in ${fmt(r.renderMs)} (${r.gpu ? "GPU" : "software"}, setup ${fmt(r.setupMs)}) -> ${r.outputPath}`);
|
|
34
|
+
if (r.warnings.length)
|
|
35
|
+
log(` warnings: ${r.warnings.join("; ")}`);
|
|
36
|
+
}
|
|
37
|
+
function renderFlags(flags) {
|
|
38
|
+
const q = flags.quality;
|
|
39
|
+
if (q && !["medium", "good", "source"].includes(q))
|
|
40
|
+
throw new UsageError("--quality must be medium, good or source");
|
|
41
|
+
return {
|
|
42
|
+
gpu: gpuMode(flags),
|
|
43
|
+
frameRate: flags.fps === undefined ? 30 : Number(flags.fps),
|
|
44
|
+
quality: q,
|
|
45
|
+
verbose: Boolean(flags.verbose),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function formatActionLine(a) {
|
|
49
|
+
const detail = a.label ? ` ${a.label}` : "";
|
|
50
|
+
return `ok ${a.kind}${detail} ${fmt(Math.max(0, a.endMs - a.startMs))}`;
|
|
51
|
+
}
|
|
52
|
+
async function cmdRun({ positionals, flags }) {
|
|
53
|
+
const file = path.resolve(positionals[0]);
|
|
54
|
+
if (!fs.existsSync(file))
|
|
55
|
+
throw new DemoreelError(`scenario not found: ${file}`, "demoreel init (scaffolds one)");
|
|
56
|
+
const scenario = await loadScenario(file);
|
|
57
|
+
const overrides = {};
|
|
58
|
+
if (flags.viewport)
|
|
59
|
+
overrides.viewport = parseSize(String(flags.viewport));
|
|
60
|
+
if (flags.speed !== undefined)
|
|
61
|
+
overrides.pacing = { ...scenario.pacing, speed: Number(flags.speed) };
|
|
62
|
+
if (flags["trim-idle"] !== undefined)
|
|
63
|
+
overrides.trimIdle = Boolean(flags["trim-idle"]) && (scenario.trimIdle || true);
|
|
64
|
+
const storageState = flags.state ? String(flags.state) : undefined;
|
|
65
|
+
if (flags["dry-run"]) {
|
|
66
|
+
const res = await dryRunScenario(scenario, {
|
|
67
|
+
scenarioFile: file,
|
|
68
|
+
overrides,
|
|
69
|
+
storageState,
|
|
70
|
+
headed: Boolean(flags.headed),
|
|
71
|
+
});
|
|
72
|
+
for (const a of res.actions)
|
|
73
|
+
console.log(formatActionLine(a));
|
|
74
|
+
if (!res.ok && res.error) {
|
|
75
|
+
log(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
log(`dry-run "${scenario.name}": ${res.actions.length} actions ok (${fmt(res.durationMs)})`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const out = path.resolve(String(flags.out ?? path.join("out", scenario.name)));
|
|
83
|
+
log(`recording "${scenario.name}" -> ${out}`);
|
|
84
|
+
const rec = await recordScenario(scenario, {
|
|
85
|
+
outDir: out,
|
|
86
|
+
scenarioFile: file,
|
|
87
|
+
overrides,
|
|
88
|
+
storageState,
|
|
89
|
+
headed: Boolean(flags.headed),
|
|
90
|
+
log,
|
|
91
|
+
});
|
|
92
|
+
const { result, timeline } = rec;
|
|
93
|
+
log(` recorded ${fmt(result.durationMs)}, ${result.frameCount} frames @ ${result.frameSize.width}x${result.frameSize.height}, ` +
|
|
94
|
+
`${result.samples.length} cursor samples, ${result.actions.length} actions, ${timeline.zoomRegions.length} zoom regions` +
|
|
95
|
+
(timeline.trimRegions.length ? `, ${timeline.trimRegions.length} idle cuts (-> ${fmt(timeline.outputDurationMs)})` : ""));
|
|
96
|
+
const v = await validateProject(rec.projectPath);
|
|
97
|
+
log(` OpenScreen validateProjectData: ${v.valid}${v.changedByNormalize.length ? `; normalised: ${v.changedByNormalize.join(", ")}` : ""}`);
|
|
98
|
+
log(` project: ${rec.projectPath}`);
|
|
99
|
+
log(` timeline: ${rec.timelinePath}`);
|
|
100
|
+
log(` marks: ${rec.marksPath}`);
|
|
101
|
+
if (flags.render === false)
|
|
102
|
+
return;
|
|
103
|
+
const mp4 = path.join(out, `${scenario.name}.mp4`);
|
|
104
|
+
const r = await renderProject({
|
|
105
|
+
projectPath: rec.projectPath,
|
|
106
|
+
outputPath: mp4,
|
|
107
|
+
...renderFlags(flags),
|
|
108
|
+
log,
|
|
109
|
+
onProgress: progressPrinter(true),
|
|
110
|
+
});
|
|
111
|
+
printRender(r);
|
|
112
|
+
if (flags.sheet === false)
|
|
113
|
+
return;
|
|
114
|
+
const sheet = await reviewSheet(mp4, {
|
|
115
|
+
outDir: out,
|
|
116
|
+
marks: rec.marksPath,
|
|
117
|
+
frames: flags.frames,
|
|
118
|
+
framesheet: flags.framesheet === "off" ? "off" : "auto",
|
|
119
|
+
log,
|
|
120
|
+
});
|
|
121
|
+
log(` contact sheet (${sheet.tool}): ${sheet.sheet}`);
|
|
122
|
+
if (sheet.summary)
|
|
123
|
+
console.log(sheet.summary);
|
|
124
|
+
}
|
|
125
|
+
async function cmdRender({ positionals, flags }) {
|
|
126
|
+
const projectPath = path.resolve(positionals[0]);
|
|
127
|
+
const r = await renderProject({
|
|
128
|
+
projectPath,
|
|
129
|
+
outputPath: flags.out ? path.resolve(String(flags.out)) : undefined,
|
|
130
|
+
...renderFlags(flags),
|
|
131
|
+
log,
|
|
132
|
+
onProgress: progressPrinter(true),
|
|
133
|
+
});
|
|
134
|
+
printRender(r);
|
|
135
|
+
console.log(r.outputPath);
|
|
136
|
+
}
|
|
137
|
+
async function cmdRezoom({ positionals, flags }) {
|
|
138
|
+
const dir = path.resolve(positionals[0]);
|
|
139
|
+
const zoom = parseJsonFlag("options", flags.options);
|
|
140
|
+
if (flags["max-depth"] !== undefined)
|
|
141
|
+
zoom.maxDepth = Number(flags["max-depth"]);
|
|
142
|
+
if (flags.lead !== undefined)
|
|
143
|
+
zoom.leadMs = Number(flags.lead);
|
|
144
|
+
if (flags.hold !== undefined)
|
|
145
|
+
zoom.holdMs = Number(flags.hold);
|
|
146
|
+
if (flags["auto-zoom"] !== undefined)
|
|
147
|
+
zoom.auto = Boolean(flags["auto-zoom"]);
|
|
148
|
+
const idle = parseJsonFlag("idle-options", flags["idle-options"]);
|
|
149
|
+
const trimIdle = flags["trim-idle"] === false ? false : flags["trim-idle"] || Object.keys(idle).length ? { ...idle } : undefined;
|
|
150
|
+
const res = rezoom(dir, { zoom, trimIdle });
|
|
151
|
+
const t = res.timeline;
|
|
152
|
+
log(`rezoomed ${t.scenario}: ${t.zoomRegions.length} zoom regions, ${t.trimRegions.length} trims, ${t.speedRegions.length} speed regions; output ${fmt(t.outputDurationMs)}`);
|
|
153
|
+
console.log(JSON.stringify({ zoomRegions: t.zoomRegions, trimRegions: t.trimRegions, speedRegions: t.speedRegions }, null, 1));
|
|
154
|
+
if (flags.render) {
|
|
155
|
+
const r = await renderProject({ projectPath: res.projectPath, ...renderFlags(flags), log, onProgress: progressPrinter(true) });
|
|
156
|
+
printRender(r);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function cmdValidate({ positionals, flags }) {
|
|
160
|
+
const v = await validateProject(path.resolve(positionals[0]));
|
|
161
|
+
if (flags.json)
|
|
162
|
+
console.log(JSON.stringify(v, null, 2));
|
|
163
|
+
else {
|
|
164
|
+
console.log(`valid: ${v.valid}`);
|
|
165
|
+
if (v.valid)
|
|
166
|
+
console.log(`changed by normalizeProjectEditor: ${v.changedByNormalize.length ? v.changedByNormalize.join(", ") : "(nothing)"}`);
|
|
167
|
+
if (v.valid)
|
|
168
|
+
console.log(`media: ${JSON.stringify(v.media)}`);
|
|
169
|
+
}
|
|
170
|
+
if (!v.valid)
|
|
171
|
+
process.exitCode = 1;
|
|
172
|
+
}
|
|
173
|
+
async function cmdSheet({ positionals, flags }) {
|
|
174
|
+
let target = path.resolve(positionals[0]);
|
|
175
|
+
let marks = flags.marks ? path.resolve(String(flags.marks)) : undefined;
|
|
176
|
+
if (fs.existsSync(target) && fs.statSync(target).isDirectory()) {
|
|
177
|
+
const tl = readTimeline(target);
|
|
178
|
+
marks ??= path.join(target, tl.files?.marks ?? "marks.json");
|
|
179
|
+
target = path.join(target, tl.files?.video ?? `${tl.scenario}.mp4`);
|
|
180
|
+
}
|
|
181
|
+
if (!fs.existsSync(target))
|
|
182
|
+
throw new DemoreelError(`video not found: ${target}`, "render it first: demoreel render <project>");
|
|
183
|
+
marks ??= path.join(path.dirname(target), "marks.json");
|
|
184
|
+
const sheet = await reviewSheet(target, {
|
|
185
|
+
outDir: flags.out ? path.resolve(String(flags.out)) : path.dirname(target),
|
|
186
|
+
marks,
|
|
187
|
+
frames: flags.frames,
|
|
188
|
+
framesheet: flags.framesheet === "off" ? "off" : "auto",
|
|
189
|
+
log,
|
|
190
|
+
});
|
|
191
|
+
if (sheet.summary)
|
|
192
|
+
console.log(sheet.summary);
|
|
193
|
+
log(`contact sheet (${sheet.tool}): ${sheet.sheet}`);
|
|
194
|
+
console.log(sheet.sheet);
|
|
195
|
+
if (sheet.report)
|
|
196
|
+
console.log(sheet.report);
|
|
197
|
+
}
|
|
198
|
+
async function cmdLogin({ positionals, flags }) {
|
|
199
|
+
const url = positionals[0];
|
|
200
|
+
const statePath = path.resolve(String(flags.state ?? path.join(".demoreel", "auth.json")));
|
|
201
|
+
const viewport = flags.viewport ? parseSize(String(flags.viewport)) : { width: 1280, height: 800 };
|
|
202
|
+
const browser = await launchChromium({ headless: false });
|
|
203
|
+
let context = null;
|
|
204
|
+
let timer = null;
|
|
205
|
+
try {
|
|
206
|
+
context = await browser.newContext({ viewport });
|
|
207
|
+
const page = await context.newPage();
|
|
208
|
+
await page.goto(url);
|
|
209
|
+
log("sign in, then close the window");
|
|
210
|
+
let lastState = null;
|
|
211
|
+
let inFlight = false;
|
|
212
|
+
const capture = () => {
|
|
213
|
+
if (!context || inFlight)
|
|
214
|
+
return;
|
|
215
|
+
inFlight = true;
|
|
216
|
+
context
|
|
217
|
+
.storageState()
|
|
218
|
+
.then((s) => {
|
|
219
|
+
lastState = s;
|
|
220
|
+
})
|
|
221
|
+
.catch(() => { })
|
|
222
|
+
.finally(() => {
|
|
223
|
+
inFlight = false;
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
const closed = new Promise((resolve) => {
|
|
227
|
+
const finish = () => resolve();
|
|
228
|
+
const watchPage = (p) => {
|
|
229
|
+
p.on("load", capture);
|
|
230
|
+
p.on("framenavigated", capture);
|
|
231
|
+
p.on("close", () => {
|
|
232
|
+
if (context && context.pages().every((other) => other.isClosed()))
|
|
233
|
+
finish();
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
watchPage(page);
|
|
237
|
+
context.on("page", watchPage);
|
|
238
|
+
context.on("close", finish);
|
|
239
|
+
browser.on("disconnected", finish);
|
|
240
|
+
});
|
|
241
|
+
capture();
|
|
242
|
+
timer = setInterval(capture, 1500);
|
|
243
|
+
timer.unref?.();
|
|
244
|
+
await closed;
|
|
245
|
+
clearInterval(timer);
|
|
246
|
+
timer = null;
|
|
247
|
+
fs.mkdirSync(path.dirname(statePath), { recursive: true });
|
|
248
|
+
try {
|
|
249
|
+
await context.storageState({ path: statePath });
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
if (lastState) {
|
|
253
|
+
fs.writeFileSync(statePath, JSON.stringify(lastState, null, 2));
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
throw new DemoreelError(`could not save login state before browser closed: ${e.message}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
log(`saved login state: ${statePath}`);
|
|
260
|
+
log("add .demoreel/ to .gitignore (it holds session cookies)");
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
if (timer)
|
|
264
|
+
clearInterval(timer);
|
|
265
|
+
await context?.close().catch(() => { });
|
|
266
|
+
await browser.close().catch(() => { });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function capturePageInspect(page, screenshotPath) {
|
|
270
|
+
let snapshot;
|
|
271
|
+
let screenshotSaved = false;
|
|
272
|
+
const errors = [];
|
|
273
|
+
try {
|
|
274
|
+
snapshot = await page.locator("body").ariaSnapshot();
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
errors.push(`aria snapshot failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
278
|
+
}
|
|
279
|
+
if (screenshotPath) {
|
|
280
|
+
try {
|
|
281
|
+
fs.mkdirSync(path.dirname(screenshotPath), { recursive: true });
|
|
282
|
+
await page.screenshot({ path: screenshotPath });
|
|
283
|
+
screenshotSaved = true;
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
errors.push(`screenshot failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return { snapshot, screenshotSaved, error: errors.length ? errors.join("; ") : undefined };
|
|
290
|
+
}
|
|
291
|
+
async function cmdInspect({ positionals, flags }) {
|
|
292
|
+
const target = positionals[0];
|
|
293
|
+
const screenshotPath = flags.screenshot ? path.resolve(String(flags.screenshot)) : undefined;
|
|
294
|
+
const stateFlag = flags.state ? String(flags.state) : undefined;
|
|
295
|
+
const headed = Boolean(flags.headed);
|
|
296
|
+
if (/^(https?|file):\/\//i.test(target)) {
|
|
297
|
+
const storageState = resolveStorageState(stateFlag);
|
|
298
|
+
const viewport = flags.viewport ? parseSize(String(flags.viewport)) : { width: 1280, height: 800 };
|
|
299
|
+
const browser = await launchChromium({ headless: !headed });
|
|
300
|
+
try {
|
|
301
|
+
const context = await browser.newContext({
|
|
302
|
+
viewport,
|
|
303
|
+
deviceScaleFactor: 1,
|
|
304
|
+
...(storageState ? { storageState } : {}),
|
|
305
|
+
});
|
|
306
|
+
const page = await context.newPage();
|
|
307
|
+
await page.goto(target, { waitUntil: "load" });
|
|
308
|
+
const cap = await capturePageInspect(page, screenshotPath);
|
|
309
|
+
if (cap.snapshot !== undefined)
|
|
310
|
+
console.log(cap.snapshot);
|
|
311
|
+
if (cap.screenshotSaved && screenshotPath)
|
|
312
|
+
log(`screenshot: ${screenshotPath}`);
|
|
313
|
+
if (cap.error) {
|
|
314
|
+
log(`warning: ${cap.error}`);
|
|
315
|
+
if (cap.snapshot === undefined)
|
|
316
|
+
process.exitCode = 1;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
await browser.close().catch(() => { });
|
|
321
|
+
}
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const file = path.resolve(target);
|
|
325
|
+
if (!fs.existsSync(file))
|
|
326
|
+
throw new DemoreelError(`scenario not found: ${file}`, "demoreel init (scaffolds one)");
|
|
327
|
+
const scenario = await loadScenario(file);
|
|
328
|
+
const overrides = {};
|
|
329
|
+
if (flags.viewport)
|
|
330
|
+
overrides.viewport = parseSize(String(flags.viewport));
|
|
331
|
+
let cap = { screenshotSaved: false };
|
|
332
|
+
const res = await dryRunScenario(scenario, {
|
|
333
|
+
scenarioFile: file,
|
|
334
|
+
overrides,
|
|
335
|
+
storageState: stateFlag,
|
|
336
|
+
headed,
|
|
337
|
+
atEnd: async (page) => {
|
|
338
|
+
cap = await capturePageInspect(page, screenshotPath);
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
if (!res.ok && res.error) {
|
|
342
|
+
log(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
log(`dry-run "${scenario.name}": ${res.actions.length} actions ok (${fmt(res.durationMs)})`);
|
|
346
|
+
}
|
|
347
|
+
if (cap.screenshotSaved && screenshotPath)
|
|
348
|
+
log(`screenshot: ${screenshotPath}`);
|
|
349
|
+
if (cap.error)
|
|
350
|
+
log(`warning: ${cap.error}`);
|
|
351
|
+
if (cap.snapshot !== undefined)
|
|
352
|
+
console.log(cap.snapshot);
|
|
353
|
+
if (!res.ok)
|
|
354
|
+
process.exitCode = 1;
|
|
355
|
+
}
|
|
356
|
+
function cmdInit({ positionals, flags }) {
|
|
357
|
+
const written = initProject({
|
|
358
|
+
dir: positionals[0] ?? ".",
|
|
359
|
+
name: flags.name,
|
|
360
|
+
url: flags.url,
|
|
361
|
+
js: Boolean(flags.js),
|
|
362
|
+
force: Boolean(flags.force),
|
|
363
|
+
});
|
|
364
|
+
for (const f of written)
|
|
365
|
+
log(`wrote ${path.relative(process.cwd(), f) || f}`);
|
|
366
|
+
const scenario = path.relative(process.cwd(), written[0]);
|
|
367
|
+
log(`\nnext:\n npm install -D @phil65/demoreel playwright # if not installed yet\n npx demoreel run ${scenario}`);
|
|
368
|
+
}
|
|
369
|
+
async function cmdDoctor() {
|
|
370
|
+
let ok = true;
|
|
371
|
+
const check = async (name, fn) => {
|
|
372
|
+
try {
|
|
373
|
+
log(` ok ${name}: ${await fn()}`);
|
|
374
|
+
}
|
|
375
|
+
catch (e) {
|
|
376
|
+
ok = false;
|
|
377
|
+
log(` FAIL ${name}: ${e.message}`);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
log(`demoreel ${version()} on ${process.versions.bun ? `bun ${process.versions.bun}` : `node ${process.version}`} (${process.platform})`);
|
|
381
|
+
await check("chromium", async () => {
|
|
382
|
+
const b = await launchChromium();
|
|
383
|
+
const v = b.version();
|
|
384
|
+
await b.close();
|
|
385
|
+
return v;
|
|
386
|
+
});
|
|
387
|
+
await check("ffmpeg", () => {
|
|
388
|
+
checkFfmpeg();
|
|
389
|
+
return "found, with libx264";
|
|
390
|
+
});
|
|
391
|
+
await check("gpu", async () => {
|
|
392
|
+
const g = await detectGpu();
|
|
393
|
+
if (!g.h264)
|
|
394
|
+
throw new DemoreelError("WebCodecs H.264 encoding unavailable", "npx playwright install chromium");
|
|
395
|
+
return `${g.gpu ? "hardware" : "software only (renders will be slow)"}: ${g.renderer}`;
|
|
396
|
+
});
|
|
397
|
+
const fsCmd = findFramesheet();
|
|
398
|
+
log(` ${fsCmd ? "ok " : "info"} framesheet: ${fsCmd ? `${fsCmd.cmd} ${fsCmd.args.join(" ")}`.trim() : "not found (sheets fall back to ffmpeg; `uv tool install framesheet` or `npm i -D framesheet`)"}`);
|
|
399
|
+
if (!ok)
|
|
400
|
+
process.exitCode = 1;
|
|
401
|
+
}
|
|
402
|
+
function version() {
|
|
403
|
+
try {
|
|
404
|
+
return JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8")).version;
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
return "unknown";
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
411
|
+
let args;
|
|
412
|
+
try {
|
|
413
|
+
args = parseArgs(argv);
|
|
414
|
+
}
|
|
415
|
+
catch (e) {
|
|
416
|
+
if (e instanceof UsageError) {
|
|
417
|
+
log(`error: ${e.message}`);
|
|
418
|
+
process.exitCode = 2;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
throw e;
|
|
422
|
+
}
|
|
423
|
+
if (args.version)
|
|
424
|
+
return void console.log(version());
|
|
425
|
+
if (args.help || !args.command) {
|
|
426
|
+
console.log(helpText(args.command));
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const handlers = {
|
|
430
|
+
run: cmdRun,
|
|
431
|
+
render: cmdRender,
|
|
432
|
+
rezoom: cmdRezoom,
|
|
433
|
+
validate: cmdValidate,
|
|
434
|
+
sheet: cmdSheet,
|
|
435
|
+
inspect: cmdInspect,
|
|
436
|
+
login: cmdLogin,
|
|
437
|
+
init: cmdInit,
|
|
438
|
+
doctor: cmdDoctor,
|
|
439
|
+
};
|
|
440
|
+
try {
|
|
441
|
+
await handlers[args.command](args);
|
|
442
|
+
}
|
|
443
|
+
catch (e) {
|
|
444
|
+
if (e instanceof DemoreelError || e instanceof UsageError) {
|
|
445
|
+
log(`error: ${e.message}`);
|
|
446
|
+
process.exitCode = e instanceof UsageError ? 2 : 1;
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
throw e;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const isMain = (() => {
|
|
453
|
+
const entry = process.argv[1];
|
|
454
|
+
if (!entry)
|
|
455
|
+
return false;
|
|
456
|
+
try {
|
|
457
|
+
return fs.realpathSync(entry) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
458
|
+
}
|
|
459
|
+
catch {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
})();
|
|
463
|
+
if (isMain) {
|
|
464
|
+
main().catch((e) => {
|
|
465
|
+
console.error(e);
|
|
466
|
+
process.exit(1);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type IdleOptions } from "./idle.ts";
|
|
2
|
+
import { type Marks } from "./marks.ts";
|
|
3
|
+
import { buildProject, type LookOptions } from "./project.ts";
|
|
4
|
+
import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, Viewport, ZoomRegion } from "./types.ts";
|
|
5
|
+
import { type ZoomOptions } from "./zoom.ts";
|
|
6
|
+
export declare const TIMELINE_VERSION = 1;
|
|
7
|
+
/** `timeline.json`: the agent-facing record of a run. Times in ms of the recording. */
|
|
8
|
+
export interface Timeline {
|
|
9
|
+
version: number;
|
|
10
|
+
scenario: string;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
durationMs: number;
|
|
13
|
+
/** Duration of the rendered video (after trim / speed regions). */
|
|
14
|
+
outputDurationMs: number;
|
|
15
|
+
frameCount: number;
|
|
16
|
+
viewport: Viewport;
|
|
17
|
+
frameSize: Viewport;
|
|
18
|
+
options: {
|
|
19
|
+
zoom: Partial<ZoomOptions>;
|
|
20
|
+
look: Partial<LookOptions>;
|
|
21
|
+
trimIdle: Partial<IdleOptions> | false;
|
|
22
|
+
};
|
|
23
|
+
actions: ActionRecord[];
|
|
24
|
+
zoomRegions: ZoomRegion[];
|
|
25
|
+
trimRegions: TrimRegion[];
|
|
26
|
+
speedRegions: SpeedRegion[];
|
|
27
|
+
captions: Caption[];
|
|
28
|
+
timings: Record<string, number>;
|
|
29
|
+
files: {
|
|
30
|
+
recording: string;
|
|
31
|
+
cursor: string;
|
|
32
|
+
project: string;
|
|
33
|
+
marks: string;
|
|
34
|
+
video: string;
|
|
35
|
+
};
|
|
36
|
+
/** Recording-clock times of captured frames (visual changes). */
|
|
37
|
+
frameTimes: number[];
|
|
38
|
+
}
|
|
39
|
+
export interface ComposeInput {
|
|
40
|
+
name: string;
|
|
41
|
+
outDir: string;
|
|
42
|
+
videoPath: string;
|
|
43
|
+
durationMs: number;
|
|
44
|
+
frameCount: number;
|
|
45
|
+
viewport: Viewport;
|
|
46
|
+
frameSize: Viewport;
|
|
47
|
+
actions: ActionRecord[];
|
|
48
|
+
captions: Caption[];
|
|
49
|
+
samples: CursorSample[];
|
|
50
|
+
frameTimes: number[];
|
|
51
|
+
timings: Record<string, number>;
|
|
52
|
+
zoom?: Partial<ZoomOptions>;
|
|
53
|
+
look?: Partial<LookOptions>;
|
|
54
|
+
trimIdle?: Partial<IdleOptions> | boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ComposeResult {
|
|
57
|
+
timeline: Timeline;
|
|
58
|
+
timelinePath: string;
|
|
59
|
+
projectPath: string;
|
|
60
|
+
marksPath: string;
|
|
61
|
+
marks: Marks;
|
|
62
|
+
project: ReturnType<typeof buildProject>;
|
|
63
|
+
}
|
|
64
|
+
export declare function compose(input: ComposeInput, opts?: {
|
|
65
|
+
keepProjectFrom?: string;
|
|
66
|
+
}): ComposeResult;
|
|
67
|
+
export declare function readTimeline(dir: string): Timeline;
|
|
68
|
+
/** Re-derives zoom / idle regions, project and marks from an output dir's timeline.json. */
|
|
69
|
+
export declare function rezoom(dir: string, overrides?: {
|
|
70
|
+
zoom?: Partial<ZoomOptions>;
|
|
71
|
+
trimIdle?: Partial<IdleOptions> | boolean;
|
|
72
|
+
look?: Partial<LookOptions>;
|
|
73
|
+
}): ComposeResult;
|
package/dist/compose.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a recording's timeline into the derived outputs: zoom regions, idle trims, the
|
|
3
|
+
* OpenScreen project and framesheet marks. Used by `recordScenario` and `demoreel rezoom`
|
|
4
|
+
* (which re-runs it from timeline.json without recording again).
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { deriveIdleRegions, sourceToOutputMs } from "./idle.js";
|
|
9
|
+
import { stageLayout } from "./layout.js";
|
|
10
|
+
import { buildMarks, placeCaptions, targetRects } from "./marks.js";
|
|
11
|
+
import { buildCursorData, buildProject, DEFAULT_LOOK } from "./project.js";
|
|
12
|
+
import { deriveZoomRegions } from "./zoom.js";
|
|
13
|
+
export const TIMELINE_VERSION = 1;
|
|
14
|
+
export function compose(input, opts = {}) {
|
|
15
|
+
const look = { ...DEFAULT_LOOK, ...input.look };
|
|
16
|
+
const layout = stageLayout(input.viewport, look);
|
|
17
|
+
const zoomRegions = deriveZoomRegions(input.actions, input.viewport, input.durationMs, input.zoom, layout);
|
|
18
|
+
const captions = placeCaptions(input.captions.map(({ position: _p, ...c }) => c), targetRects({ actions: input.actions, viewport: input.viewport, layout, zoomRegions }), look.captionPosition);
|
|
19
|
+
const idleOpts = input.trimIdle === true ? {} : input.trimIdle || null;
|
|
20
|
+
const { trimRegions, speedRegions } = idleOpts
|
|
21
|
+
? deriveIdleRegions({
|
|
22
|
+
durationMs: input.durationMs,
|
|
23
|
+
actions: input.actions,
|
|
24
|
+
captions: input.captions,
|
|
25
|
+
samples: input.samples,
|
|
26
|
+
zoomRegions,
|
|
27
|
+
frameTimes: input.frameTimes,
|
|
28
|
+
}, idleOpts)
|
|
29
|
+
: { trimRegions: [], speedRegions: [] };
|
|
30
|
+
const projectPath = path.join(input.outDir, `${input.name}.openscreen`);
|
|
31
|
+
let project = buildProject({
|
|
32
|
+
videoPath: input.videoPath,
|
|
33
|
+
zoomRegions,
|
|
34
|
+
captions,
|
|
35
|
+
trimRegions,
|
|
36
|
+
speedRegions,
|
|
37
|
+
look,
|
|
38
|
+
});
|
|
39
|
+
if (opts.keepProjectFrom && fs.existsSync(opts.keepProjectFrom)) {
|
|
40
|
+
// rezoom: keep edits made in OpenScreen, replace only the derived regions.
|
|
41
|
+
const prev = JSON.parse(fs.readFileSync(opts.keepProjectFrom, "utf8"));
|
|
42
|
+
project = {
|
|
43
|
+
...prev,
|
|
44
|
+
editor: { ...prev.editor, zoomRegions, trimRegions, speedRegions, annotationRegions: project.editor.annotationRegions },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
fs.writeFileSync(projectPath, JSON.stringify(project, null, 2));
|
|
48
|
+
const cursorPath = `${input.videoPath}.cursor.json`;
|
|
49
|
+
fs.writeFileSync(cursorPath, JSON.stringify(buildCursorData(input.samples)));
|
|
50
|
+
const marks = buildMarks({
|
|
51
|
+
viewport: input.viewport,
|
|
52
|
+
durationMs: input.durationMs,
|
|
53
|
+
actions: input.actions,
|
|
54
|
+
captions,
|
|
55
|
+
zoomRegions,
|
|
56
|
+
trimRegions,
|
|
57
|
+
speedRegions,
|
|
58
|
+
layout,
|
|
59
|
+
look,
|
|
60
|
+
});
|
|
61
|
+
const marksPath = path.join(input.outDir, "marks.json");
|
|
62
|
+
fs.writeFileSync(marksPath, JSON.stringify(marks, null, 1));
|
|
63
|
+
const timeline = {
|
|
64
|
+
version: TIMELINE_VERSION,
|
|
65
|
+
scenario: input.name,
|
|
66
|
+
createdAt: new Date().toISOString(),
|
|
67
|
+
durationMs: Math.round(input.durationMs),
|
|
68
|
+
outputDurationMs: Math.round(sourceToOutputMs(input.durationMs, trimRegions, speedRegions)),
|
|
69
|
+
frameCount: input.frameCount,
|
|
70
|
+
viewport: input.viewport,
|
|
71
|
+
frameSize: input.frameSize,
|
|
72
|
+
options: {
|
|
73
|
+
zoom: input.zoom ?? {},
|
|
74
|
+
look: input.look ?? {},
|
|
75
|
+
trimIdle: idleOpts ?? false,
|
|
76
|
+
},
|
|
77
|
+
actions: input.actions.map(roundAction),
|
|
78
|
+
zoomRegions,
|
|
79
|
+
trimRegions,
|
|
80
|
+
speedRegions,
|
|
81
|
+
captions: captions.map((c) => ({ ...c, startMs: Math.round(c.startMs), endMs: Math.round(c.endMs) })),
|
|
82
|
+
timings: input.timings,
|
|
83
|
+
files: {
|
|
84
|
+
recording: path.basename(input.videoPath),
|
|
85
|
+
cursor: path.basename(cursorPath),
|
|
86
|
+
project: path.basename(projectPath),
|
|
87
|
+
marks: path.basename(marksPath),
|
|
88
|
+
video: `${input.name}.mp4`,
|
|
89
|
+
},
|
|
90
|
+
frameTimes: input.frameTimes,
|
|
91
|
+
};
|
|
92
|
+
const timelinePath = path.join(input.outDir, "timeline.json");
|
|
93
|
+
fs.writeFileSync(timelinePath, JSON.stringify(timeline, null, 1));
|
|
94
|
+
return { timeline, timelinePath, projectPath, marksPath, marks, project };
|
|
95
|
+
}
|
|
96
|
+
const r1 = (v) => Math.round(v * 10) / 10;
|
|
97
|
+
function roundAction(a) {
|
|
98
|
+
const box = (b) => b && { x: r1(b.x), y: r1(b.y), width: r1(b.width), height: r1(b.height) };
|
|
99
|
+
return {
|
|
100
|
+
...a,
|
|
101
|
+
startMs: Math.round(a.startMs),
|
|
102
|
+
arriveMs: Math.round(a.arriveMs),
|
|
103
|
+
endMs: Math.round(a.endMs),
|
|
104
|
+
...(a.box ? { box: box(a.box) } : {}),
|
|
105
|
+
...(a.zoomBox ? { zoomBox: box(a.zoomBox) } : {}),
|
|
106
|
+
...(a.point ? { point: { x: r1(a.point.x), y: r1(a.point.y) } } : {}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function readTimeline(dir) {
|
|
110
|
+
const p = path.join(dir, "timeline.json");
|
|
111
|
+
if (!fs.existsSync(p))
|
|
112
|
+
throw new Error(`${p} not found (run \`demoreel run\` first)`);
|
|
113
|
+
return JSON.parse(fs.readFileSync(p, "utf8"));
|
|
114
|
+
}
|
|
115
|
+
/** Re-derives zoom / idle regions, project and marks from an output dir's timeline.json. */
|
|
116
|
+
export function rezoom(dir, overrides = {}) {
|
|
117
|
+
const tl = readTimeline(dir);
|
|
118
|
+
const recording = path.join(dir, tl.files?.recording ?? "recording.mp4");
|
|
119
|
+
const cursorFile = `${recording}.cursor.json`;
|
|
120
|
+
const samples = fs.existsSync(cursorFile) ? JSON.parse(fs.readFileSync(cursorFile, "utf8")).samples : [];
|
|
121
|
+
const trimIdle = overrides.trimIdle === undefined
|
|
122
|
+
? tl.options?.trimIdle
|
|
123
|
+
: overrides.trimIdle === true
|
|
124
|
+
? { ...(tl.options?.trimIdle || {}) }
|
|
125
|
+
: overrides.trimIdle;
|
|
126
|
+
const projectPath = path.join(dir, `${tl.scenario}.openscreen`);
|
|
127
|
+
return compose({
|
|
128
|
+
name: tl.scenario,
|
|
129
|
+
outDir: dir,
|
|
130
|
+
videoPath: recording,
|
|
131
|
+
durationMs: tl.durationMs,
|
|
132
|
+
frameCount: tl.frameCount,
|
|
133
|
+
viewport: tl.viewport,
|
|
134
|
+
frameSize: tl.frameSize,
|
|
135
|
+
actions: tl.actions,
|
|
136
|
+
captions: tl.captions,
|
|
137
|
+
samples,
|
|
138
|
+
frameTimes: tl.frameTimes ?? [],
|
|
139
|
+
timings: tl.timings,
|
|
140
|
+
zoom: { ...tl.options?.zoom, ...overrides.zoom },
|
|
141
|
+
look: { ...tl.options?.look, ...overrides.look },
|
|
142
|
+
trimIdle: trimIdle ?? false,
|
|
143
|
+
}, { keepProjectFrom: overrides.look ? undefined : projectPath });
|
|
144
|
+
}
|