@phil65/demoreel 0.1.0 → 0.4.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 (47) hide show
  1. package/README.md +52 -8
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/dist/args.js +34 -0
  4. package/dist/cli.js +223 -5
  5. package/dist/compose.d.ts +4 -0
  6. package/dist/compose.js +4 -0
  7. package/dist/gif.d.ts +16 -0
  8. package/dist/gif.js +19 -0
  9. package/dist/idle.d.ts +8 -2
  10. package/dist/idle.js +12 -10
  11. package/dist/index.d.ts +5 -4
  12. package/dist/index.js +5 -4
  13. package/dist/marks.js +5 -4
  14. package/dist/motion.d.ts +1 -1
  15. package/dist/motion.js +3 -3
  16. package/dist/openscreen/project.js +3 -3
  17. package/dist/project.d.ts +51 -1
  18. package/dist/project.js +89 -1
  19. package/dist/record.d.ts +45 -3
  20. package/dist/record.js +110 -31
  21. package/dist/recorder.d.ts +1 -0
  22. package/dist/recorder.js +8 -0
  23. package/dist/renderer/assets/CanvasPool-PBu3bHFZ.js +1 -0
  24. package/dist/renderer/assets/CanvasRenderer-HmF-4gyW.js +1 -0
  25. package/dist/renderer/assets/RenderTargetSystem-Dk1U4wDJ.js +184 -0
  26. package/dist/renderer/assets/WebGLRenderer-C0v9HBel.js +149 -0
  27. package/dist/renderer/assets/WebGPURenderer-Ce0-U9Q1.js +95 -0
  28. package/dist/renderer/assets/{browserAll-aHn2isHo.js → browserAll-DhvWQ7nM.js} +2 -2
  29. package/dist/renderer/assets/canvasUtils-KRroregW.js +1 -0
  30. package/dist/renderer/assets/{getTexelRangeRects-yD6MQ0xy.js → getTexelRangeRects-D3pwCyRt.js} +3 -3
  31. package/dist/renderer/assets/index-CE-lli1m.js +556 -0
  32. package/dist/renderer/assets/init-DfmWKarH.js +83 -0
  33. package/dist/renderer/assets/webworkerAll-B41hok0-.js +1 -0
  34. package/dist/renderer/index.html +1 -6
  35. package/dist/scene.d.ts +85 -9
  36. package/dist/scene.js +310 -48
  37. package/dist/types.d.ts +6 -1
  38. package/dist/zoom.d.ts +2 -0
  39. package/dist/zoom.js +10 -4
  40. package/package.json +2 -2
  41. package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +0 -23
  42. package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +0 -404
  43. package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +0 -1
  44. package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +0 -1
  45. package/dist/renderer/assets/index-BwP6rH7I.js +0 -556
  46. package/dist/renderer/assets/init-C2Za5NQh.js +0 -83
  47. package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +0 -1
package/README.md CHANGED
@@ -61,8 +61,12 @@ npx demoreel doctor # checks Chromium, ffmpeg, GPU, framesheet
61
61
 
62
62
  ```
63
63
  demoreel run <scenario.ts|js> record, write project, render MP4, contact sheet
64
- --out DIR --no-render --fps 30 --quality medium|good|source --[no-]gpu
65
- --trim-idle --speed 1.5 --viewport 1280x720 --headed -n 12 --framesheet auto|off
64
+ --out DIR --no-render --dry-run --state FILE --fps 30 --quality medium|good|source
65
+ --[no-]gpu --trim-idle --speed 1.5 --viewport 1280x720 --headed -n 12 --framesheet auto|off
66
+ demoreel inspect <url|scenario> ARIA snapshot (+ optional --screenshot) of a page or scenario end state
67
+ --screenshot FILE --state FILE --viewport 1280x800 --headed
68
+ demoreel login <url> sign in in headed Chromium and save storageState (default .demoreel/auth.json)
69
+ --state FILE --viewport 1280x800
66
70
  demoreel render <project.openscreen> [--out FILE.mp4 --fps --quality --[no-]gpu]
67
71
  demoreel rezoom <outdir> re-derive zooms / idle cuts / marks from timeline.json
68
72
  --max-depth 4 --lead 350 --hold 800 --no-auto-zoom --options JSON
@@ -100,18 +104,58 @@ Each run writes into `out/<name>/`:
100
104
  | `zoom(target, { depth, duration, context, wait })` | explicit zoom that overrides automatic ones in its window |
101
105
  | `highlight(target, { duration, color, zoom })` | outline drawn into the page around an element |
102
106
 
103
- `target` is a CSS / Playwright selector or a `Locator`; the first visible match is used and
104
- scrolled into view if needed. `scene.page` is the raw Playwright page.
107
+ `target` is a structured accessibility-first spec (`{ role, name?, exact?, nth? }`,
108
+ `{ label, exact?, nth? }`, `{ placeholder, exact?, nth? }`, `{ text, exact?, nth? }`,
109
+ `{ testId, nth? }`, `{ css, nth? }`), a CSS / Playwright selector string, or a `Locator` — e.g.
110
+ `scene.click({ role: "button", name: "Save" })`. The first visible match (or `nth` visible match
111
+ when given) is used and scrolled into view if needed; structured targets also produce readable
112
+ default labels in `timeline.json` and `marks.json`. `scene.page` is the raw Playwright page.
105
113
 
106
114
  Scenario options: `viewport`, `cssZoom` (crisper text: lay out at a smaller size and scale
107
- up), `serve` (static dir served at `ctx.baseUrl`), `colorScheme`, `seed`, `pacing`
115
+ up), `serve` (static dir served at `ctx.baseUrl`), `storageState` (Playwright storageState
116
+ JSON, relative to the scenario file), `colorScheme`, `seed`, `pacing`
108
117
  (`speed`, `beforeAction`, `afterClick`, `typeDelay`, ...), `zoom` (see below), `look`
109
118
  (`wallpaper`, `padding`, `borderRadius`, `shadowIntensity`, `aspectRatio`,
110
119
  `captionPosition`), `trimIdle`.
111
120
 
112
- Library: `recordScenario`, `deriveZoomRegions`, `deriveIdleRegions`, `buildProject`,
113
- `buildCursorData`, `buildMarks`, `renderProject`, `validateProject`, `rezoom`,
114
- `reviewSheet`, all typed (`dist/index.d.ts`).
121
+ Library: `recordScenario`, `dryRunScenario`, `resolveStorageState`, `deriveZoomRegions`,
122
+ `deriveIdleRegions`, `buildProject`, `buildCursorData`, `buildMarks`, `renderProject`,
123
+ `validateProject`, `rezoom`, `reviewSheet`, all typed (`dist/index.d.ts`).
124
+
125
+ ### Inspect before you script
126
+
127
+ Before recording, inspect a URL to see its ARIA tree (and optionally save a PNG) so you can
128
+ pick exact role/name or text targets without guessing:
129
+
130
+ ```bash
131
+ npx demoreel inspect https://your.app --screenshot page.png
132
+ ```
133
+
134
+ Then validate a scenario with a fast dry run (no sleeps, no cursor animation, no ffmpeg, no
135
+ output files):
136
+
137
+ ```bash
138
+ npx demoreel inspect demo.scenario.ts --screenshot end.png # dry-run + end-state ARIA snapshot
139
+ npx demoreel run demo.scenario.ts --dry-run # dry-run with per-action summary
140
+ ```
141
+
142
+ If a step fails, `demoreel inspect` reports which action failed and still prints the ARIA
143
+ snapshot (and writes `--screenshot`) at the moment of failure.
144
+
145
+ ### Logged-in apps
146
+
147
+ Save a Playwright `storageState` once in a headed browser, then reuse it across inspections
148
+ and recordings:
149
+
150
+ ```bash
151
+ npx demoreel login https://your.app # saves .demoreel/auth.json
152
+ npx demoreel inspect https://your.app --state .demoreel/auth.json
153
+ npx demoreel run demo.scenario.ts --state .demoreel/auth.json
154
+ ```
155
+
156
+ Or set `storageState: ".demoreel/auth.json"` in `defineScenario({ ... })` (resolved relative
157
+ to the scenario file; `--state` overrides it relative to cwd). Add `.demoreel/` to
158
+ `.gitignore` — it holds session cookies.
115
159
 
116
160
  ## How cursor and zoom are derived
117
161
 
@@ -19,7 +19,7 @@ are listed in `vendor/openscreen/VENDORED.md` in the demoreel repository.
19
19
  | eventemitter3 | 5.0.4 | MIT | [licenses/eventemitter3.txt](licenses/eventemitter3.txt) | git://github.com/primus/eventemitter3 |
20
20
  | gif.js | 0.2.0 | MIT | [licenses/gif.js.txt](licenses/gif.js.txt) | https://github.com/jnordberg/gif.js |
21
21
  | ismobilejs | 1.1.1 | MIT | [licenses/ismobilejs.txt](licenses/ismobilejs.txt) | https://github.com/kaimallea/isMobile |
22
- | mediabunny | 1.66.2 | MPL-2.0 | [licenses/mediabunny.txt](licenses/mediabunny.txt) | https://github.com/Vanilagy/mediabunny |
22
+ | mediabunny | 1.66.5 | MPL-2.0 | [licenses/mediabunny.txt](licenses/mediabunny.txt) | https://github.com/Vanilagy/mediabunny |
23
23
  | motion-dom | 12.43.0 | MIT | [licenses/motion-dom.txt](licenses/motion-dom.txt) | https://github.com/motiondivision/motion |
24
24
  | motion-utils | 12.39.0 | MIT | [licenses/motion-utils.txt](licenses/motion-utils.txt) | https://github.com/motiondivision/motion |
25
25
  | parse-svg-path | 0.2.0 | MIT | [licenses/parse-svg-path.txt](licenses/parse-svg-path.txt) | git://github.com/jkroso/parse-svg-path |
package/dist/args.js CHANGED
@@ -14,6 +14,7 @@ export const COMMANDS = {
14
14
  flags: {
15
15
  out: { type: "string", alias: "o", value: "DIR", description: "output directory (default out/<name>)" },
16
16
  render: { type: "boolean", description: "render the MP4 (default; --no-render to only record)" },
17
+ gif: { type: "boolean", description: "also export a palette-optimised GIF next to the MP4" },
17
18
  sheet: { type: "boolean", description: "write a contact sheet after rendering (default)" },
18
19
  gpu,
19
20
  fps,
@@ -21,6 +22,8 @@ export const COMMANDS = {
21
22
  "trim-idle": trimIdle,
22
23
  speed: { type: "number", value: "X", description: "pacing speed multiplier (2 = twice as fast)" },
23
24
  viewport: { type: "string", value: "WxH", description: "override the scenario viewport, e.g. 1280x720" },
25
+ state: { type: "string", value: "FILE", description: "Playwright storageState JSON (overrides scenario.storageState)" },
26
+ "dry-run": { type: "boolean", description: "run the scenario fast without ffmpeg, recording, or writing files" },
24
27
  headed: { type: "boolean", description: "show the browser while recording" },
25
28
  frames,
26
29
  framesheet,
@@ -51,6 +54,7 @@ export const COMMANDS = {
51
54
  "auto-zoom": { type: "boolean", description: "automatic zooms (--no-auto-zoom: only scene.zoom())" },
52
55
  "trim-idle": trimIdle,
53
56
  "idle-options": { type: "string", value: "JSON", description: 'e.g. \'{"minMs":1500,"keepMs":800,"mode":"speed"}\'' },
57
+ "show-keys": { type: "boolean", description: "toggle keycap HUD overlays for scene.press() shortcuts" },
54
58
  render: { type: "boolean", description: "render the MP4 afterwards" },
55
59
  gpu,
56
60
  fps,
@@ -75,6 +79,36 @@ export const COMMANDS = {
75
79
  framesheet,
76
80
  },
77
81
  },
82
+ gif: {
83
+ usage: "gif <video.mp4|outdir>",
84
+ description: "export a palette-optimised GIF from a rendered MP4 (for READMEs and docs)",
85
+ positionals: { min: 1, max: 1 },
86
+ flags: {
87
+ out: { type: "string", alias: "o", value: "FILE", description: "output GIF path (default: next to the MP4)" },
88
+ fps: { type: "number", value: "N", description: "GIF frame rate (default 12)" },
89
+ width: { type: "number", value: "PX", description: "GIF width in px, height auto (default 960; 0 = source)" },
90
+ },
91
+ },
92
+ inspect: {
93
+ usage: "inspect <url|scenario.ts|js>",
94
+ description: "print a page's ARIA snapshot (or dry-run a scenario and inspect its end state)",
95
+ positionals: { min: 1, max: 1 },
96
+ flags: {
97
+ screenshot: { type: "string", value: "FILE", description: "also write a PNG screenshot of the page" },
98
+ state: { type: "string", value: "FILE", description: "Playwright storageState JSON (from `demoreel login`)" },
99
+ viewport: { type: "string", value: "WxH", description: "viewport (default 1280x800 for URLs, scenario viewport otherwise)" },
100
+ headed: { type: "boolean", description: "show the browser while inspecting" },
101
+ },
102
+ },
103
+ login: {
104
+ usage: "login <url>",
105
+ description: "open a headed browser to sign in and save cookies/storageState for scenarios",
106
+ positionals: { min: 1, max: 1 },
107
+ flags: {
108
+ state: { type: "string", value: "FILE", description: "output storageState path (default .demoreel/auth.json)" },
109
+ viewport: { type: "string", value: "WxH", description: "browser viewport (default 1280x800)" },
110
+ },
111
+ },
78
112
  init: {
79
113
  usage: "init [dir]",
80
114
  description: "scaffold an example scenario (and a copy of the demo app)",
package/dist/cli.js CHANGED
@@ -6,10 +6,11 @@ import { fileURLToPath } from "node:url";
6
6
  import { COMMANDS, gpuMode, helpText, parseArgs, parseJsonFlag, parseSize, UsageError } from "./args.js";
7
7
  import { readTimeline, rezoom } from "./compose.js";
8
8
  import { checkFfmpeg, DemoreelError, detectGpu, launchChromium } from "./env.js";
9
+ import { exportGif } from "./gif.js";
9
10
  import { initProject } from "./init.js";
10
11
  import { loadScenario } from "./load.js";
11
12
  import { PACKAGE_ROOT } from "./openscreen.js";
12
- import { recordScenario } from "./record.js";
13
+ import { dryRunScenario, recordScenario, resolveStorageState } from "./record.js";
13
14
  import { renderProject, validateProject } from "./render.js";
14
15
  import { findFramesheet, reviewSheet } from "./sheet.js";
15
16
  const fmt = (ms) => `${(ms / 1000).toFixed(1)}s`;
@@ -45,12 +46,15 @@ function renderFlags(flags) {
45
46
  verbose: Boolean(flags.verbose),
46
47
  };
47
48
  }
49
+ function formatActionLine(a) {
50
+ const detail = a.label ? ` ${a.label}` : "";
51
+ return `ok ${a.kind}${detail} ${fmt(Math.max(0, a.endMs - a.startMs))}`;
52
+ }
48
53
  async function cmdRun({ positionals, flags }) {
49
54
  const file = path.resolve(positionals[0]);
50
55
  if (!fs.existsSync(file))
51
56
  throw new DemoreelError(`scenario not found: ${file}`, "demoreel init (scaffolds one)");
52
57
  const scenario = await loadScenario(file);
53
- const out = path.resolve(String(flags.out ?? path.join("out", scenario.name)));
54
58
  const overrides = {};
55
59
  if (flags.viewport)
56
60
  overrides.viewport = parseSize(String(flags.viewport));
@@ -58,8 +62,34 @@ async function cmdRun({ positionals, flags }) {
58
62
  overrides.pacing = { ...scenario.pacing, speed: Number(flags.speed) };
59
63
  if (flags["trim-idle"] !== undefined)
60
64
  overrides.trimIdle = Boolean(flags["trim-idle"]) && (scenario.trimIdle || true);
65
+ const storageState = flags.state ? String(flags.state) : undefined;
66
+ if (flags["dry-run"]) {
67
+ const res = await dryRunScenario(scenario, {
68
+ scenarioFile: file,
69
+ overrides,
70
+ storageState,
71
+ headed: Boolean(flags.headed),
72
+ });
73
+ for (const a of res.actions)
74
+ console.log(formatActionLine(a));
75
+ if (!res.ok && res.error) {
76
+ log(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
77
+ process.exitCode = 1;
78
+ return;
79
+ }
80
+ log(`dry-run "${scenario.name}": ${res.actions.length} actions ok (${fmt(res.durationMs)})`);
81
+ return;
82
+ }
83
+ const out = path.resolve(String(flags.out ?? path.join("out", scenario.name)));
61
84
  log(`recording "${scenario.name}" -> ${out}`);
62
- const rec = await recordScenario(scenario, { outDir: out, scenarioFile: file, overrides, headed: Boolean(flags.headed), log });
85
+ const rec = await recordScenario(scenario, {
86
+ outDir: out,
87
+ scenarioFile: file,
88
+ overrides,
89
+ storageState,
90
+ headed: Boolean(flags.headed),
91
+ log,
92
+ });
63
93
  const { result, timeline } = rec;
64
94
  log(` recorded ${fmt(result.durationMs)}, ${result.frameCount} frames @ ${result.frameSize.width}x${result.frameSize.height}, ` +
65
95
  `${result.samples.length} cursor samples, ${result.actions.length} actions, ${timeline.zoomRegions.length} zoom regions` +
@@ -75,11 +105,16 @@ async function cmdRun({ positionals, flags }) {
75
105
  const r = await renderProject({
76
106
  projectPath: rec.projectPath,
77
107
  outputPath: mp4,
108
+ cursor: scenario.cursor,
78
109
  ...renderFlags(flags),
79
110
  log,
80
111
  onProgress: progressPrinter(true),
81
112
  });
82
113
  printRender(r);
114
+ if (flags.gif) {
115
+ const g = await exportGif(mp4);
116
+ log(` gif: ${g.outputPath} (${(g.bytes / 1e6).toFixed(1)} MB, ${g.width}px @ ${g.fps}fps)`);
117
+ }
83
118
  if (flags.sheet === false)
84
119
  return;
85
120
  const sheet = await reviewSheet(mp4, {
@@ -118,12 +153,19 @@ async function cmdRezoom({ positionals, flags }) {
118
153
  zoom.auto = Boolean(flags["auto-zoom"]);
119
154
  const idle = parseJsonFlag("idle-options", flags["idle-options"]);
120
155
  const trimIdle = flags["trim-idle"] === false ? false : flags["trim-idle"] || Object.keys(idle).length ? { ...idle } : undefined;
121
- const res = rezoom(dir, { zoom, trimIdle });
156
+ const look = flags["show-keys"] !== undefined ? { showKeys: Boolean(flags["show-keys"]) } : undefined;
157
+ const res = rezoom(dir, { zoom, trimIdle, look });
122
158
  const t = res.timeline;
123
159
  log(`rezoomed ${t.scenario}: ${t.zoomRegions.length} zoom regions, ${t.trimRegions.length} trims, ${t.speedRegions.length} speed regions; output ${fmt(t.outputDurationMs)}`);
124
160
  console.log(JSON.stringify({ zoomRegions: t.zoomRegions, trimRegions: t.trimRegions, speedRegions: t.speedRegions }, null, 1));
125
161
  if (flags.render) {
126
- const r = await renderProject({ projectPath: res.projectPath, ...renderFlags(flags), log, onProgress: progressPrinter(true) });
162
+ const r = await renderProject({
163
+ projectPath: res.projectPath,
164
+ cursor: t.options?.cursor,
165
+ ...renderFlags(flags),
166
+ log,
167
+ onProgress: progressPrinter(true),
168
+ });
127
169
  printRender(r);
128
170
  }
129
171
  }
@@ -166,6 +208,179 @@ async function cmdSheet({ positionals, flags }) {
166
208
  if (sheet.report)
167
209
  console.log(sheet.report);
168
210
  }
211
+ async function cmdGif({ positionals, flags }) {
212
+ let target = path.resolve(positionals[0]);
213
+ if (fs.existsSync(target) && fs.statSync(target).isDirectory()) {
214
+ const tl = readTimeline(target);
215
+ target = path.join(target, tl.files?.video ?? `${tl.scenario}.mp4`);
216
+ }
217
+ if (!fs.existsSync(target))
218
+ throw new DemoreelError(`video not found: ${target}`, "render it first: demoreel render <project>");
219
+ const g = await exportGif(target, flags.out ? path.resolve(String(flags.out)) : undefined, {
220
+ fps: flags.fps !== undefined ? Number(flags.fps) : undefined,
221
+ width: flags.width !== undefined ? Number(flags.width) : undefined,
222
+ });
223
+ log(`gif: ${g.outputPath} (${(g.bytes / 1e6).toFixed(1)} MB, ${g.width || "source"}px @ ${g.fps}fps)`);
224
+ console.log(g.outputPath);
225
+ }
226
+ async function cmdLogin({ positionals, flags }) {
227
+ const url = positionals[0];
228
+ const statePath = path.resolve(String(flags.state ?? path.join(".demoreel", "auth.json")));
229
+ const viewport = flags.viewport ? parseSize(String(flags.viewport)) : { width: 1280, height: 800 };
230
+ const browser = await launchChromium({ headless: false });
231
+ let context = null;
232
+ let timer = null;
233
+ try {
234
+ context = await browser.newContext({ viewport });
235
+ const page = await context.newPage();
236
+ await page.goto(url);
237
+ log("sign in, then close the window");
238
+ let lastState = null;
239
+ let inFlight = false;
240
+ const capture = () => {
241
+ if (!context || inFlight)
242
+ return;
243
+ inFlight = true;
244
+ context
245
+ .storageState()
246
+ .then((s) => {
247
+ lastState = s;
248
+ })
249
+ .catch(() => { })
250
+ .finally(() => {
251
+ inFlight = false;
252
+ });
253
+ };
254
+ const closed = new Promise((resolve) => {
255
+ const finish = () => resolve();
256
+ const watchPage = (p) => {
257
+ p.on("load", capture);
258
+ p.on("framenavigated", capture);
259
+ p.on("close", () => {
260
+ if (context && context.pages().every((other) => other.isClosed()))
261
+ finish();
262
+ });
263
+ };
264
+ watchPage(page);
265
+ context.on("page", watchPage);
266
+ context.on("close", finish);
267
+ browser.on("disconnected", finish);
268
+ });
269
+ capture();
270
+ timer = setInterval(capture, 1500);
271
+ timer.unref?.();
272
+ await closed;
273
+ clearInterval(timer);
274
+ timer = null;
275
+ fs.mkdirSync(path.dirname(statePath), { recursive: true });
276
+ try {
277
+ await context.storageState({ path: statePath });
278
+ }
279
+ catch (e) {
280
+ if (lastState) {
281
+ fs.writeFileSync(statePath, JSON.stringify(lastState, null, 2));
282
+ }
283
+ else {
284
+ throw new DemoreelError(`could not save login state before browser closed: ${e.message}`);
285
+ }
286
+ }
287
+ log(`saved login state: ${statePath}`);
288
+ log("add .demoreel/ to .gitignore (it holds session cookies)");
289
+ }
290
+ finally {
291
+ if (timer)
292
+ clearInterval(timer);
293
+ await context?.close().catch(() => { });
294
+ await browser.close().catch(() => { });
295
+ }
296
+ }
297
+ async function capturePageInspect(page, screenshotPath) {
298
+ let snapshot;
299
+ let screenshotSaved = false;
300
+ const errors = [];
301
+ try {
302
+ snapshot = await page.locator("body").ariaSnapshot();
303
+ }
304
+ catch (e) {
305
+ errors.push(`aria snapshot failed: ${e instanceof Error ? e.message : String(e)}`);
306
+ }
307
+ if (screenshotPath) {
308
+ try {
309
+ fs.mkdirSync(path.dirname(screenshotPath), { recursive: true });
310
+ await page.screenshot({ path: screenshotPath });
311
+ screenshotSaved = true;
312
+ }
313
+ catch (e) {
314
+ errors.push(`screenshot failed: ${e instanceof Error ? e.message : String(e)}`);
315
+ }
316
+ }
317
+ return { snapshot, screenshotSaved, error: errors.length ? errors.join("; ") : undefined };
318
+ }
319
+ async function cmdInspect({ positionals, flags }) {
320
+ const target = positionals[0];
321
+ const screenshotPath = flags.screenshot ? path.resolve(String(flags.screenshot)) : undefined;
322
+ const stateFlag = flags.state ? String(flags.state) : undefined;
323
+ const headed = Boolean(flags.headed);
324
+ if (/^(https?|file):\/\//i.test(target)) {
325
+ const storageState = resolveStorageState(stateFlag);
326
+ const viewport = flags.viewport ? parseSize(String(flags.viewport)) : { width: 1280, height: 800 };
327
+ const browser = await launchChromium({ headless: !headed });
328
+ try {
329
+ const context = await browser.newContext({
330
+ viewport,
331
+ deviceScaleFactor: 1,
332
+ ...(storageState ? { storageState } : {}),
333
+ });
334
+ const page = await context.newPage();
335
+ await page.goto(target, { waitUntil: "load" });
336
+ const cap = await capturePageInspect(page, screenshotPath);
337
+ if (cap.snapshot !== undefined)
338
+ console.log(cap.snapshot);
339
+ if (cap.screenshotSaved && screenshotPath)
340
+ log(`screenshot: ${screenshotPath}`);
341
+ if (cap.error) {
342
+ log(`warning: ${cap.error}`);
343
+ if (cap.snapshot === undefined)
344
+ process.exitCode = 1;
345
+ }
346
+ }
347
+ finally {
348
+ await browser.close().catch(() => { });
349
+ }
350
+ return;
351
+ }
352
+ const file = path.resolve(target);
353
+ if (!fs.existsSync(file))
354
+ throw new DemoreelError(`scenario not found: ${file}`, "demoreel init (scaffolds one)");
355
+ const scenario = await loadScenario(file);
356
+ const overrides = {};
357
+ if (flags.viewport)
358
+ overrides.viewport = parseSize(String(flags.viewport));
359
+ let cap = { screenshotSaved: false };
360
+ const res = await dryRunScenario(scenario, {
361
+ scenarioFile: file,
362
+ overrides,
363
+ storageState: stateFlag,
364
+ headed,
365
+ atEnd: async (page) => {
366
+ cap = await capturePageInspect(page, screenshotPath);
367
+ },
368
+ });
369
+ if (!res.ok && res.error) {
370
+ log(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
371
+ }
372
+ else {
373
+ log(`dry-run "${scenario.name}": ${res.actions.length} actions ok (${fmt(res.durationMs)})`);
374
+ }
375
+ if (cap.screenshotSaved && screenshotPath)
376
+ log(`screenshot: ${screenshotPath}`);
377
+ if (cap.error)
378
+ log(`warning: ${cap.error}`);
379
+ if (cap.snapshot !== undefined)
380
+ console.log(cap.snapshot);
381
+ if (!res.ok)
382
+ process.exitCode = 1;
383
+ }
169
384
  function cmdInit({ positionals, flags }) {
170
385
  const written = initProject({
171
386
  dir: positionals[0] ?? ".",
@@ -245,6 +460,9 @@ export async function main(argv = process.argv.slice(2)) {
245
460
  rezoom: cmdRezoom,
246
461
  validate: cmdValidate,
247
462
  sheet: cmdSheet,
463
+ gif: cmdGif,
464
+ inspect: cmdInspect,
465
+ login: cmdLogin,
248
466
  init: cmdInit,
249
467
  doctor: cmdDoctor,
250
468
  };
package/dist/compose.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type IdleOptions } from "./idle.ts";
2
2
  import { type Marks } from "./marks.ts";
3
3
  import { buildProject, type LookOptions } from "./project.ts";
4
+ import type { CursorStyle } from "./render.ts";
4
5
  import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, Viewport, ZoomRegion } from "./types.ts";
5
6
  import { type ZoomOptions } from "./zoom.ts";
6
7
  export declare const TIMELINE_VERSION = 1;
@@ -19,6 +20,7 @@ export interface Timeline {
19
20
  zoom: Partial<ZoomOptions>;
20
21
  look: Partial<LookOptions>;
21
22
  trimIdle: Partial<IdleOptions> | false;
23
+ cursor?: CursorStyle;
22
24
  };
23
25
  actions: ActionRecord[];
24
26
  zoomRegions: ZoomRegion[];
@@ -52,6 +54,7 @@ export interface ComposeInput {
52
54
  zoom?: Partial<ZoomOptions>;
53
55
  look?: Partial<LookOptions>;
54
56
  trimIdle?: Partial<IdleOptions> | boolean;
57
+ cursor?: CursorStyle;
55
58
  }
56
59
  export interface ComposeResult {
57
60
  timeline: Timeline;
@@ -70,4 +73,5 @@ export declare function rezoom(dir: string, overrides?: {
70
73
  zoom?: Partial<ZoomOptions>;
71
74
  trimIdle?: Partial<IdleOptions> | boolean;
72
75
  look?: Partial<LookOptions>;
76
+ cursor?: CursorStyle;
73
77
  }): ComposeResult;
package/dist/compose.js CHANGED
@@ -32,6 +32,7 @@ export function compose(input, opts = {}) {
32
32
  videoPath: input.videoPath,
33
33
  zoomRegions,
34
34
  captions,
35
+ actions: input.actions,
35
36
  trimRegions,
36
37
  speedRegions,
37
38
  look,
@@ -73,6 +74,7 @@ export function compose(input, opts = {}) {
73
74
  zoom: input.zoom ?? {},
74
75
  look: input.look ?? {},
75
76
  trimIdle: idleOpts ?? false,
77
+ ...(input.cursor ? { cursor: input.cursor } : {}),
76
78
  },
77
79
  actions: input.actions.map(roundAction),
78
80
  zoomRegions,
@@ -124,6 +126,7 @@ export function rezoom(dir, overrides = {}) {
124
126
  ? { ...(tl.options?.trimIdle || {}) }
125
127
  : overrides.trimIdle;
126
128
  const projectPath = path.join(dir, `${tl.scenario}.openscreen`);
129
+ const cursor = overrides.cursor ?? tl.options?.cursor;
127
130
  return compose({
128
131
  name: tl.scenario,
129
132
  outDir: dir,
@@ -140,5 +143,6 @@ export function rezoom(dir, overrides = {}) {
140
143
  zoom: { ...tl.options?.zoom, ...overrides.zoom },
141
144
  look: { ...tl.options?.look, ...overrides.look },
142
145
  trimIdle: trimIdle ?? false,
146
+ cursor,
143
147
  }, { keepProjectFrom: overrides.look ? undefined : projectPath });
144
148
  }
package/dist/gif.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export interface GifOptions {
2
+ /** Output frame rate (default 12). */
3
+ fps?: number;
4
+ /** Output width in px, height preserves aspect ratio (default 960; 0 keeps source width). */
5
+ width?: number;
6
+ /** Loop count: 0 = infinite (default), -1 = no loop, N = loop N times. */
7
+ loop?: number;
8
+ }
9
+ export interface GifResult {
10
+ outputPath: string;
11
+ bytes: number;
12
+ fps: number;
13
+ width: number;
14
+ }
15
+ /** Converts an MP4 video into a crisp palette-optimised GIF suitable for READMEs and docs. */
16
+ export declare function exportGif(videoPath: string, outPath?: string, opts?: GifOptions): Promise<GifResult>;
package/dist/gif.js ADDED
@@ -0,0 +1,19 @@
1
+ /** Two-pass palette-optimised GIF export from a rendered MP4 via ffmpeg. */
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { checkFfmpeg, ffmpegBin, run } from "./env.js";
5
+ /** Converts an MP4 video into a crisp palette-optimised GIF suitable for READMEs and docs. */
6
+ export async function exportGif(videoPath, outPath, opts = {}) {
7
+ checkFfmpeg();
8
+ const src = path.resolve(videoPath);
9
+ const dst = path.resolve(outPath ?? src.replace(/\.\w+$/, ".gif"));
10
+ const fps = Math.max(1, Math.min(30, Math.round(opts.fps ?? 12)));
11
+ const width = opts.width === 0 ? 0 : Math.max(120, Math.round(opts.width ?? 960));
12
+ const loop = opts.loop ?? 0;
13
+ fs.mkdirSync(path.dirname(dst), { recursive: true });
14
+ const scale = width > 0 ? `,scale=${width}:-2:flags=lanczos` : "";
15
+ const filter = `fps=${fps}${scale},split[s0][s1];[s0]palettegen=stats_mode=diff[p];[s1][p]paletteuse=dither=bayer:bayer_scale=3`;
16
+ await run(ffmpegBin(), ["-y", "-loglevel", "error", "-i", src, "-vf", filter, "-loop", String(loop), dst]);
17
+ const { size } = fs.statSync(dst);
18
+ return { outputPath: dst, bytes: size, fps, width };
19
+ }
package/dist/idle.d.ts CHANGED
@@ -14,6 +14,8 @@ export interface IdleOptions {
14
14
  mode: "trim" | "speed";
15
15
  /** Playback speed for `mode: "speed"` (OpenScreen allows 0.1-16). */
16
16
  speed: number;
17
+ /** Ignore raw screencast frame bursts (useful for apps with continuous rAF / WebGL / spinners). */
18
+ ignoreFrames?: boolean;
17
19
  }
18
20
  export declare const DEFAULT_IDLE_OPTIONS: IdleOptions;
19
21
  type Interval = [number, number];
@@ -27,9 +29,13 @@ export interface IdleInput {
27
29
  frameTimes?: number[];
28
30
  }
29
31
  /** Busy intervals of a recording (anything a viewer should see at normal speed). */
30
- export declare function busyIntervals(input: IdleInput): Interval[];
32
+ export declare function busyIntervals(input: IdleInput, opts?: {
33
+ ignoreFrames?: boolean;
34
+ }): Interval[];
31
35
  /** Idle stretches (complement of the busy intervals) longer than `minMs`. */
32
- export declare function idleIntervals(input: IdleInput, minMs?: number): Interval[];
36
+ export declare function idleIntervals(input: IdleInput, minMs?: number, opts?: {
37
+ ignoreFrames?: boolean;
38
+ }): Interval[];
33
39
  export declare function deriveIdleRegions(input: IdleInput, partial?: Partial<IdleOptions>): {
34
40
  trimRegions: TrimRegion[];
35
41
  speedRegions: SpeedRegion[];
package/dist/idle.js CHANGED
@@ -1,4 +1,4 @@
1
- export const DEFAULT_IDLE_OPTIONS = { minMs: 1200, keepMs: 600, mode: "trim", speed: 3 };
1
+ export const DEFAULT_IDLE_OPTIONS = { minMs: 1200, keepMs: 600, mode: "trim", speed: 3, ignoreFrames: false };
2
2
  /** OpenScreen zoom envelope (constants.ts TRANSITION_WINDOW_MS / ZOOM_IN_TRANSITION_WINDOW_MS). */
3
3
  const ZOOM_IN_BEFORE_MS = 1022;
4
4
  const ZOOM_IN_AFTER_MS = 500;
@@ -16,7 +16,7 @@ function mergeIntervals(list) {
16
16
  return out;
17
17
  }
18
18
  /** Busy intervals of a recording (anything a viewer should see at normal speed). */
19
- export function busyIntervals(input) {
19
+ export function busyIntervals(input, opts = {}) {
20
20
  const busy = [];
21
21
  for (const a of input.actions) {
22
22
  if (a.kind === "pause" || a.kind === "caption")
@@ -35,17 +35,19 @@ export function busyIntervals(input) {
35
35
  if (moved || s[i].interactionType !== "move")
36
36
  busy.push([s[i - 1].timeMs - 100, s[i].timeMs + 150]);
37
37
  }
38
- // >= 3 frames within 300 ms: something animates or paints.
39
- const f = input.frameTimes ?? [];
40
- for (let i = 2; i < f.length; i++) {
41
- if (f[i] - f[i - 2] <= 300)
42
- busy.push([f[i - 2] - 100, f[i] + 200]);
38
+ if (!opts.ignoreFrames) {
39
+ // >= 3 frames within 300 ms: something animates or paints.
40
+ const f = input.frameTimes ?? [];
41
+ for (let i = 2; i < f.length; i++) {
42
+ if (f[i] - f[i - 2] <= 300)
43
+ busy.push([f[i - 2] - 100, f[i] + 200]);
44
+ }
43
45
  }
44
46
  return mergeIntervals(busy);
45
47
  }
46
48
  /** Idle stretches (complement of the busy intervals) longer than `minMs`. */
47
- export function idleIntervals(input, minMs = DEFAULT_IDLE_OPTIONS.minMs) {
48
- const busy = busyIntervals(input);
49
+ export function idleIntervals(input, minMs = DEFAULT_IDLE_OPTIONS.minMs, opts = {}) {
50
+ const busy = busyIntervals(input, opts);
49
51
  const out = [];
50
52
  let cursor = 0;
51
53
  for (const [a, b] of busy) {
@@ -60,7 +62,7 @@ export function idleIntervals(input, minMs = DEFAULT_IDLE_OPTIONS.minMs) {
60
62
  export function deriveIdleRegions(input, partial = {}) {
61
63
  const opts = { ...DEFAULT_IDLE_OPTIONS, ...partial };
62
64
  const half = opts.keepMs / 2;
63
- const cuts = idleIntervals(input, Math.max(opts.minMs, opts.keepMs + 100))
65
+ const cuts = idleIntervals(input, Math.max(opts.minMs, opts.keepMs + 100), { ignoreFrames: opts.ignoreFrames })
64
66
  // keep the final hold (zoom-out, last frame) a bit longer than other stretches
65
67
  .map(([a, b]) => [Math.round(a + half), Math.round(b - (b >= input.durationMs ? Math.max(half, 900) : half))])
66
68
  .filter(([a, b]) => b - a >= 100);
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /** demoreel: scripted product demo videos (videos as code), rendered by OpenScreen's exporter. */
2
- export { type Scenario, type ScenarioContext, type RecordOptions, type RecordResult, defineScenario, recordScenario } from "./record.ts";
3
- export { type ActionOptions, applyZoomAnchor, DEFAULT_PACING, type HighlightOptions, type PacingOptions, Scene, type Target, ZOOM_ATTRIBUTE, type ZoomOptions as SceneZoomOptions, } from "./scene.ts";
4
- export { DEFAULT_ZOOM_OPTIONS, DEPTH_SCALES, deriveZoomRegions, depthForBox, type ZoomOptions } from "./zoom.ts";
2
+ export { type DryRunError, type DryRunOptions, type DryRunResult, type RecordOptions, type RecordResult, type Scenario, type ScenarioContext, defineScenario, dryRunScenario, recordScenario, resolveStorageState, } from "./record.ts";
3
+ export { type ActionOptions, applyZoomAnchor, type ClickRippleOptions, DEFAULT_PACING, describeTarget, type HighlightOptions, type PacingOptions, type PressOptions, resolveTarget, Scene, type SceneClock, type Target, type TargetSpec, ZOOM_ATTRIBUTE, type ZoomOptions as SceneZoomOptions, } from "./scene.ts";
4
+ export { DEFAULT_ZOOM_OPTIONS, DEPTH_SCALES, deriveZoomRegions, depthForBox, normalizeDepth, type ZoomOptions } from "./zoom.ts";
5
5
  export { DEFAULT_IDLE_OPTIONS, deriveIdleRegions, idleIntervals, type IdleOptions, sourceToOutputMs } from "./idle.ts";
6
- export { buildCursorData, buildProject, type BuildProjectOptions, captionAnnotations, DEFAULT_LOOK, type LookOptions, normalizeSamples, type OpenScreenProject, writeProject, } from "./project.ts";
6
+ export { buildCursorData, buildProject, type BuildProjectOptions, captionAnnotations, DEFAULT_LOOK, formatKeycap, keycapAnnotations, type KeyHudOptions, type KeyHudPosition, keycapRect, type LookOptions, normalizeSamples, type OpenScreenProject, writeProject, } from "./project.ts";
7
+ export { exportGif, type GifOptions, type GifResult } from "./gif.ts";
7
8
  export { buildMarks, type Marks, type MarkPoint, type MarkRegion, type MarkSpan, type MarksInput } from "./marks.ts";
8
9
  export { stageLayout, type StageLayout } from "./layout.ts";
9
10
  export { compose, rezoom, readTimeline, type Timeline, TIMELINE_VERSION } from "./compose.ts";
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  /** demoreel: scripted product demo videos (videos as code), rendered by OpenScreen's exporter. */
2
- export { defineScenario, recordScenario } from "./record.js";
3
- export { applyZoomAnchor, DEFAULT_PACING, Scene, ZOOM_ATTRIBUTE, } from "./scene.js";
4
- export { DEFAULT_ZOOM_OPTIONS, DEPTH_SCALES, deriveZoomRegions, depthForBox } from "./zoom.js";
2
+ export { defineScenario, dryRunScenario, recordScenario, resolveStorageState, } from "./record.js";
3
+ export { applyZoomAnchor, DEFAULT_PACING, describeTarget, resolveTarget, Scene, ZOOM_ATTRIBUTE, } from "./scene.js";
4
+ export { DEFAULT_ZOOM_OPTIONS, DEPTH_SCALES, deriveZoomRegions, depthForBox, normalizeDepth } from "./zoom.js";
5
5
  export { DEFAULT_IDLE_OPTIONS, deriveIdleRegions, idleIntervals, sourceToOutputMs } from "./idle.js";
6
- export { buildCursorData, buildProject, captionAnnotations, DEFAULT_LOOK, normalizeSamples, writeProject, } from "./project.js";
6
+ export { buildCursorData, buildProject, captionAnnotations, DEFAULT_LOOK, formatKeycap, keycapAnnotations, keycapRect, normalizeSamples, writeProject, } from "./project.js";
7
+ export { exportGif } from "./gif.js";
7
8
  export { buildMarks } from "./marks.js";
8
9
  export { stageLayout } from "./layout.js";
9
10
  export { compose, rezoom, readTimeline, TIMELINE_VERSION } from "./compose.js";