@phil65/demoreel 0.0.0-stage → 0.1.0

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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +163 -2
  3. package/THIRD_PARTY_NOTICES.md +31 -0
  4. package/dist/args.d.ts +41 -0
  5. package/dist/args.js +230 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +279 -0
  8. package/dist/compose.d.ts +73 -0
  9. package/dist/compose.js +144 -0
  10. package/dist/env.d.ts +38 -0
  11. package/dist/env.js +182 -0
  12. package/dist/idle.d.ts +42 -0
  13. package/dist/idle.js +97 -0
  14. package/dist/index.d.ts +14 -0
  15. package/dist/index.js +13 -0
  16. package/dist/init.d.ts +19 -0
  17. package/dist/init.js +92 -0
  18. package/dist/layout.d.ts +52 -0
  19. package/dist/layout.js +55 -0
  20. package/dist/load.d.ts +2 -0
  21. package/dist/load.js +76 -0
  22. package/dist/marks.d.ts +69 -0
  23. package/dist/marks.js +152 -0
  24. package/dist/motion.d.ts +15 -0
  25. package/dist/motion.js +49 -0
  26. package/dist/openscreen/project.js +793 -0
  27. package/dist/openscreen.d.ts +14 -0
  28. package/dist/openscreen.js +41 -0
  29. package/dist/project.d.ts +143 -0
  30. package/dist/project.js +144 -0
  31. package/dist/record.d.ts +53 -0
  32. package/dist/record.js +111 -0
  33. package/dist/recorder.d.ts +40 -0
  34. package/dist/recorder.js +141 -0
  35. package/dist/render.d.ts +58 -0
  36. package/dist/render.js +139 -0
  37. package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +23 -0
  38. package/dist/renderer/assets/Cursor_App-Starting-zEGhqPJj.svg +8 -0
  39. package/dist/renderer/assets/Cursor_Cross-BuZZnB_U.svg +5 -0
  40. package/dist/renderer/assets/Cursor_Default-DkmrqhKh.svg +5 -0
  41. package/dist/renderer/assets/Cursor_Hand-(Grabbing)-B-Qy-RsV.svg +5 -0
  42. package/dist/renderer/assets/Cursor_Hand-(Open)-DGrW1tFF.svg +5 -0
  43. package/dist/renderer/assets/Cursor_Hand-(Pointing)-Byy2KbtA.svg +5 -0
  44. package/dist/renderer/assets/Cursor_Help-D5NcyFpT.svg +8 -0
  45. package/dist/renderer/assets/Cursor_Move-CerM5f-0.svg +5 -0
  46. package/dist/renderer/assets/Cursor_Not-Allowed-3rttFVa5.svg +7 -0
  47. package/dist/renderer/assets/Cursor_Resize-North-East-South-West-CBd4tbCA.svg +5 -0
  48. package/dist/renderer/assets/Cursor_Resize-North-South-DOxgUIwF.svg +5 -0
  49. package/dist/renderer/assets/Cursor_Resize-North-West-South-East-hzXJFJ2_.svg +5 -0
  50. package/dist/renderer/assets/Cursor_Resize-West-East-rDJgc6AZ.svg +5 -0
  51. package/dist/renderer/assets/Cursor_Text-Cursor-Cn9rFLjY.svg +5 -0
  52. package/dist/renderer/assets/Cursor_Up-Arrow-CYyEN-dA.svg +4 -0
  53. package/dist/renderer/assets/Cursor_Wait-CK8tq-9y.svg +6 -0
  54. package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +404 -0
  55. package/dist/renderer/assets/browserAll-aHn2isHo.js +14 -0
  56. package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +1 -0
  57. package/dist/renderer/assets/getTexelRangeRects-yD6MQ0xy.js +195 -0
  58. package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +1 -0
  59. package/dist/renderer/assets/gif.worker-CjkyQP34.js +3 -0
  60. package/dist/renderer/assets/index-BwP6rH7I.js +556 -0
  61. package/dist/renderer/assets/init-C2Za5NQh.js +83 -0
  62. package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +1 -0
  63. package/dist/renderer/index.html +13 -0
  64. package/dist/renderer/wallpapers/wallpaper1.jpg +0 -0
  65. package/dist/renderer/wallpapers/wallpaper12.jpg +0 -0
  66. package/dist/renderer/wallpapers/wallpaper5.jpg +0 -0
  67. package/dist/renderer/wasm/web-demuxer.wasm +0 -0
  68. package/dist/scene.d.ts +147 -0
  69. package/dist/scene.js +441 -0
  70. package/dist/server.d.ts +12 -0
  71. package/dist/server.js +116 -0
  72. package/dist/sheet.d.ts +37 -0
  73. package/dist/sheet.js +98 -0
  74. package/dist/types.d.ts +102 -0
  75. package/dist/types.js +2 -0
  76. package/dist/zoom.d.ts +55 -0
  77. package/dist/zoom.js +172 -0
  78. package/examples/demo-app/index.html +99 -0
  79. package/examples/local-demo.ts +21 -0
  80. package/licenses/colord.txt +21 -0
  81. package/licenses/earcut.txt +15 -0
  82. package/licenses/eventemitter3.txt +21 -0
  83. package/licenses/gif.js.txt +1 -0
  84. package/licenses/ismobilejs.txt +21 -0
  85. package/licenses/mediabunny.txt +373 -0
  86. package/licenses/motion-dom.txt +21 -0
  87. package/licenses/motion-utils.txt +21 -0
  88. package/licenses/openscreen.txt +21 -0
  89. package/licenses/parse-svg-path.txt +23 -0
  90. package/licenses/pixi-filters.txt +21 -0
  91. package/licenses/pixi.js.txt +21 -0
  92. package/licenses/web-demuxer.txt +21 -0
  93. package/package.json +74 -4
package/dist/cli.js ADDED
@@ -0,0 +1,279 @@
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 { recordScenario } 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
+ async function cmdRun({ positionals, flags }) {
49
+ const file = path.resolve(positionals[0]);
50
+ if (!fs.existsSync(file))
51
+ throw new DemoreelError(`scenario not found: ${file}`, "demoreel init (scaffolds one)");
52
+ const scenario = await loadScenario(file);
53
+ const out = path.resolve(String(flags.out ?? path.join("out", scenario.name)));
54
+ const overrides = {};
55
+ if (flags.viewport)
56
+ overrides.viewport = parseSize(String(flags.viewport));
57
+ if (flags.speed !== undefined)
58
+ overrides.pacing = { ...scenario.pacing, speed: Number(flags.speed) };
59
+ if (flags["trim-idle"] !== undefined)
60
+ overrides.trimIdle = Boolean(flags["trim-idle"]) && (scenario.trimIdle || true);
61
+ log(`recording "${scenario.name}" -> ${out}`);
62
+ const rec = await recordScenario(scenario, { outDir: out, scenarioFile: file, overrides, headed: Boolean(flags.headed), log });
63
+ const { result, timeline } = rec;
64
+ log(` recorded ${fmt(result.durationMs)}, ${result.frameCount} frames @ ${result.frameSize.width}x${result.frameSize.height}, ` +
65
+ `${result.samples.length} cursor samples, ${result.actions.length} actions, ${timeline.zoomRegions.length} zoom regions` +
66
+ (timeline.trimRegions.length ? `, ${timeline.trimRegions.length} idle cuts (-> ${fmt(timeline.outputDurationMs)})` : ""));
67
+ const v = await validateProject(rec.projectPath);
68
+ log(` OpenScreen validateProjectData: ${v.valid}${v.changedByNormalize.length ? `; normalised: ${v.changedByNormalize.join(", ")}` : ""}`);
69
+ log(` project: ${rec.projectPath}`);
70
+ log(` timeline: ${rec.timelinePath}`);
71
+ log(` marks: ${rec.marksPath}`);
72
+ if (flags.render === false)
73
+ return;
74
+ const mp4 = path.join(out, `${scenario.name}.mp4`);
75
+ const r = await renderProject({
76
+ projectPath: rec.projectPath,
77
+ outputPath: mp4,
78
+ ...renderFlags(flags),
79
+ log,
80
+ onProgress: progressPrinter(true),
81
+ });
82
+ printRender(r);
83
+ if (flags.sheet === false)
84
+ return;
85
+ const sheet = await reviewSheet(mp4, {
86
+ outDir: out,
87
+ marks: rec.marksPath,
88
+ frames: flags.frames,
89
+ framesheet: flags.framesheet === "off" ? "off" : "auto",
90
+ log,
91
+ });
92
+ log(` contact sheet (${sheet.tool}): ${sheet.sheet}`);
93
+ if (sheet.summary)
94
+ console.log(sheet.summary);
95
+ }
96
+ async function cmdRender({ positionals, flags }) {
97
+ const projectPath = path.resolve(positionals[0]);
98
+ const r = await renderProject({
99
+ projectPath,
100
+ outputPath: flags.out ? path.resolve(String(flags.out)) : undefined,
101
+ ...renderFlags(flags),
102
+ log,
103
+ onProgress: progressPrinter(true),
104
+ });
105
+ printRender(r);
106
+ console.log(r.outputPath);
107
+ }
108
+ async function cmdRezoom({ positionals, flags }) {
109
+ const dir = path.resolve(positionals[0]);
110
+ const zoom = parseJsonFlag("options", flags.options);
111
+ if (flags["max-depth"] !== undefined)
112
+ zoom.maxDepth = Number(flags["max-depth"]);
113
+ if (flags.lead !== undefined)
114
+ zoom.leadMs = Number(flags.lead);
115
+ if (flags.hold !== undefined)
116
+ zoom.holdMs = Number(flags.hold);
117
+ if (flags["auto-zoom"] !== undefined)
118
+ zoom.auto = Boolean(flags["auto-zoom"]);
119
+ const idle = parseJsonFlag("idle-options", flags["idle-options"]);
120
+ const trimIdle = flags["trim-idle"] === false ? false : flags["trim-idle"] || Object.keys(idle).length ? { ...idle } : undefined;
121
+ const res = rezoom(dir, { zoom, trimIdle });
122
+ const t = res.timeline;
123
+ log(`rezoomed ${t.scenario}: ${t.zoomRegions.length} zoom regions, ${t.trimRegions.length} trims, ${t.speedRegions.length} speed regions; output ${fmt(t.outputDurationMs)}`);
124
+ console.log(JSON.stringify({ zoomRegions: t.zoomRegions, trimRegions: t.trimRegions, speedRegions: t.speedRegions }, null, 1));
125
+ if (flags.render) {
126
+ const r = await renderProject({ projectPath: res.projectPath, ...renderFlags(flags), log, onProgress: progressPrinter(true) });
127
+ printRender(r);
128
+ }
129
+ }
130
+ async function cmdValidate({ positionals, flags }) {
131
+ const v = await validateProject(path.resolve(positionals[0]));
132
+ if (flags.json)
133
+ console.log(JSON.stringify(v, null, 2));
134
+ else {
135
+ console.log(`valid: ${v.valid}`);
136
+ if (v.valid)
137
+ console.log(`changed by normalizeProjectEditor: ${v.changedByNormalize.length ? v.changedByNormalize.join(", ") : "(nothing)"}`);
138
+ if (v.valid)
139
+ console.log(`media: ${JSON.stringify(v.media)}`);
140
+ }
141
+ if (!v.valid)
142
+ process.exitCode = 1;
143
+ }
144
+ async function cmdSheet({ positionals, flags }) {
145
+ let target = path.resolve(positionals[0]);
146
+ let marks = flags.marks ? path.resolve(String(flags.marks)) : undefined;
147
+ if (fs.existsSync(target) && fs.statSync(target).isDirectory()) {
148
+ const tl = readTimeline(target);
149
+ marks ??= path.join(target, tl.files?.marks ?? "marks.json");
150
+ target = path.join(target, tl.files?.video ?? `${tl.scenario}.mp4`);
151
+ }
152
+ if (!fs.existsSync(target))
153
+ throw new DemoreelError(`video not found: ${target}`, "render it first: demoreel render <project>");
154
+ marks ??= path.join(path.dirname(target), "marks.json");
155
+ const sheet = await reviewSheet(target, {
156
+ outDir: flags.out ? path.resolve(String(flags.out)) : path.dirname(target),
157
+ marks,
158
+ frames: flags.frames,
159
+ framesheet: flags.framesheet === "off" ? "off" : "auto",
160
+ log,
161
+ });
162
+ if (sheet.summary)
163
+ console.log(sheet.summary);
164
+ log(`contact sheet (${sheet.tool}): ${sheet.sheet}`);
165
+ console.log(sheet.sheet);
166
+ if (sheet.report)
167
+ console.log(sheet.report);
168
+ }
169
+ function cmdInit({ positionals, flags }) {
170
+ const written = initProject({
171
+ dir: positionals[0] ?? ".",
172
+ name: flags.name,
173
+ url: flags.url,
174
+ js: Boolean(flags.js),
175
+ force: Boolean(flags.force),
176
+ });
177
+ for (const f of written)
178
+ log(`wrote ${path.relative(process.cwd(), f) || f}`);
179
+ const scenario = path.relative(process.cwd(), written[0]);
180
+ log(`\nnext:\n npm install -D @phil65/demoreel playwright # if not installed yet\n npx demoreel run ${scenario}`);
181
+ }
182
+ async function cmdDoctor() {
183
+ let ok = true;
184
+ const check = async (name, fn) => {
185
+ try {
186
+ log(` ok ${name}: ${await fn()}`);
187
+ }
188
+ catch (e) {
189
+ ok = false;
190
+ log(` FAIL ${name}: ${e.message}`);
191
+ }
192
+ };
193
+ log(`demoreel ${version()} on ${process.versions.bun ? `bun ${process.versions.bun}` : `node ${process.version}`} (${process.platform})`);
194
+ await check("chromium", async () => {
195
+ const b = await launchChromium();
196
+ const v = b.version();
197
+ await b.close();
198
+ return v;
199
+ });
200
+ await check("ffmpeg", () => {
201
+ checkFfmpeg();
202
+ return "found, with libx264";
203
+ });
204
+ await check("gpu", async () => {
205
+ const g = await detectGpu();
206
+ if (!g.h264)
207
+ throw new DemoreelError("WebCodecs H.264 encoding unavailable", "npx playwright install chromium");
208
+ return `${g.gpu ? "hardware" : "software only (renders will be slow)"}: ${g.renderer}`;
209
+ });
210
+ const fsCmd = findFramesheet();
211
+ 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`)"}`);
212
+ if (!ok)
213
+ process.exitCode = 1;
214
+ }
215
+ function version() {
216
+ try {
217
+ return JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8")).version;
218
+ }
219
+ catch {
220
+ return "unknown";
221
+ }
222
+ }
223
+ export async function main(argv = process.argv.slice(2)) {
224
+ let args;
225
+ try {
226
+ args = parseArgs(argv);
227
+ }
228
+ catch (e) {
229
+ if (e instanceof UsageError) {
230
+ log(`error: ${e.message}`);
231
+ process.exitCode = 2;
232
+ return;
233
+ }
234
+ throw e;
235
+ }
236
+ if (args.version)
237
+ return void console.log(version());
238
+ if (args.help || !args.command) {
239
+ console.log(helpText(args.command));
240
+ return;
241
+ }
242
+ const handlers = {
243
+ run: cmdRun,
244
+ render: cmdRender,
245
+ rezoom: cmdRezoom,
246
+ validate: cmdValidate,
247
+ sheet: cmdSheet,
248
+ init: cmdInit,
249
+ doctor: cmdDoctor,
250
+ };
251
+ try {
252
+ await handlers[args.command](args);
253
+ }
254
+ catch (e) {
255
+ if (e instanceof DemoreelError || e instanceof UsageError) {
256
+ log(`error: ${e.message}`);
257
+ process.exitCode = e instanceof UsageError ? 2 : 1;
258
+ return;
259
+ }
260
+ throw e;
261
+ }
262
+ }
263
+ const isMain = (() => {
264
+ const entry = process.argv[1];
265
+ if (!entry)
266
+ return false;
267
+ try {
268
+ return fs.realpathSync(entry) === fs.realpathSync(fileURLToPath(import.meta.url));
269
+ }
270
+ catch {
271
+ return false;
272
+ }
273
+ })();
274
+ if (isMain) {
275
+ main().catch((e) => {
276
+ console.error(e);
277
+ process.exit(1);
278
+ });
279
+ }
@@ -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;
@@ -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
+ }
package/dist/env.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { Browser, BrowserType, LaunchOptions } from "playwright";
2
+ export declare class DemoreelError extends Error {
3
+ readonly fix?: string;
4
+ constructor(message: string, fix?: string);
5
+ }
6
+ export declare const INSTALL_CHROMIUM: string;
7
+ /** Playwright's `chromium`, from the `playwright` peer dependency (or `playwright-core`). */
8
+ export declare function loadChromium(): Promise<BrowserType>;
9
+ /** Launches headless Chromium, turning Playwright's install errors into actionable ones. */
10
+ export declare function launchChromium(opts?: LaunchOptions): Promise<Browser>;
11
+ /** The ffmpeg binary: $DEMOREEL_FFMPEG, $FFMPEG_PATH or `ffmpeg` on PATH. */
12
+ export declare function ffmpegBin(): string;
13
+ export declare function ffprobeBin(): string;
14
+ /** Throws a DemoreelError unless ffmpeg (with libx264) is available. */
15
+ export declare function checkFfmpeg(bin?: string): void;
16
+ /** Runs a command, resolving with stdout; rejects with the tail of stderr. */
17
+ export declare function run(cmd: string, args: string[], opts?: {
18
+ cwd?: string;
19
+ }): Promise<string>;
20
+ export declare const SOFTWARE_GL_ARGS: string[];
21
+ /** Candidate GPU flag sets per platform, best first. */
22
+ export declare function gpuArgCandidates(platform?: NodeJS.Platform): string[][];
23
+ export interface GpuProbe {
24
+ gpu: boolean;
25
+ args: string[];
26
+ renderer: string;
27
+ /** VideoEncoder supports H.264 (avc1.640033) at 1080p. */
28
+ h264: boolean;
29
+ }
30
+ /** Finds a working hardware GL flag set, else returns the SwiftShader (software) one. */
31
+ export declare function detectGpu(): Promise<GpuProbe>;
32
+ export type GpuMode = boolean | "auto";
33
+ /** Chromium args for rendering: GPU when asked/available, SwiftShader otherwise. */
34
+ export declare function renderArgs(mode: GpuMode, log?: (msg: string) => void): Promise<{
35
+ args: string[];
36
+ gpu: boolean;
37
+ renderer?: string;
38
+ }>;