@phil65/demoreel 0.1.0 → 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/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
 
package/dist/args.js CHANGED
@@ -21,6 +21,8 @@ export const COMMANDS = {
21
21
  "trim-idle": trimIdle,
22
22
  speed: { type: "number", value: "X", description: "pacing speed multiplier (2 = twice as fast)" },
23
23
  viewport: { type: "string", value: "WxH", description: "override the scenario viewport, e.g. 1280x720" },
24
+ state: { type: "string", value: "FILE", description: "Playwright storageState JSON (overrides scenario.storageState)" },
25
+ "dry-run": { type: "boolean", description: "run the scenario fast without ffmpeg, recording, or writing files" },
24
26
  headed: { type: "boolean", description: "show the browser while recording" },
25
27
  frames,
26
28
  framesheet,
@@ -75,6 +77,26 @@ export const COMMANDS = {
75
77
  framesheet,
76
78
  },
77
79
  },
80
+ inspect: {
81
+ usage: "inspect <url|scenario.ts|js>",
82
+ description: "print a page's ARIA snapshot (or dry-run a scenario and inspect its end state)",
83
+ positionals: { min: 1, max: 1 },
84
+ flags: {
85
+ screenshot: { type: "string", value: "FILE", description: "also write a PNG screenshot of the page" },
86
+ state: { type: "string", value: "FILE", description: "Playwright storageState JSON (from `demoreel login`)" },
87
+ viewport: { type: "string", value: "WxH", description: "viewport (default 1280x800 for URLs, scenario viewport otherwise)" },
88
+ headed: { type: "boolean", description: "show the browser while inspecting" },
89
+ },
90
+ },
91
+ login: {
92
+ usage: "login <url>",
93
+ description: "open a headed browser to sign in and save cookies/storageState for scenarios",
94
+ positionals: { min: 1, max: 1 },
95
+ flags: {
96
+ state: { type: "string", value: "FILE", description: "output storageState path (default .demoreel/auth.json)" },
97
+ viewport: { type: "string", value: "WxH", description: "browser viewport (default 1280x800)" },
98
+ },
99
+ },
78
100
  init: {
79
101
  usage: "init [dir]",
80
102
  description: "scaffold an example scenario (and a copy of the demo app)",
package/dist/cli.js CHANGED
@@ -9,7 +9,7 @@ import { checkFfmpeg, DemoreelError, detectGpu, launchChromium } from "./env.js"
9
9
  import { initProject } from "./init.js";
10
10
  import { loadScenario } from "./load.js";
11
11
  import { PACKAGE_ROOT } from "./openscreen.js";
12
- import { recordScenario } from "./record.js";
12
+ import { dryRunScenario, recordScenario, resolveStorageState } from "./record.js";
13
13
  import { renderProject, validateProject } from "./render.js";
14
14
  import { findFramesheet, reviewSheet } from "./sheet.js";
15
15
  const fmt = (ms) => `${(ms / 1000).toFixed(1)}s`;
@@ -45,12 +45,15 @@ function renderFlags(flags) {
45
45
  verbose: Boolean(flags.verbose),
46
46
  };
47
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
+ }
48
52
  async function cmdRun({ positionals, flags }) {
49
53
  const file = path.resolve(positionals[0]);
50
54
  if (!fs.existsSync(file))
51
55
  throw new DemoreelError(`scenario not found: ${file}`, "demoreel init (scaffolds one)");
52
56
  const scenario = await loadScenario(file);
53
- const out = path.resolve(String(flags.out ?? path.join("out", scenario.name)));
54
57
  const overrides = {};
55
58
  if (flags.viewport)
56
59
  overrides.viewport = parseSize(String(flags.viewport));
@@ -58,8 +61,34 @@ async function cmdRun({ positionals, flags }) {
58
61
  overrides.pacing = { ...scenario.pacing, speed: Number(flags.speed) };
59
62
  if (flags["trim-idle"] !== undefined)
60
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)));
61
83
  log(`recording "${scenario.name}" -> ${out}`);
62
- const rec = await recordScenario(scenario, { outDir: out, scenarioFile: file, overrides, headed: Boolean(flags.headed), log });
84
+ const rec = await recordScenario(scenario, {
85
+ outDir: out,
86
+ scenarioFile: file,
87
+ overrides,
88
+ storageState,
89
+ headed: Boolean(flags.headed),
90
+ log,
91
+ });
63
92
  const { result, timeline } = rec;
64
93
  log(` recorded ${fmt(result.durationMs)}, ${result.frameCount} frames @ ${result.frameSize.width}x${result.frameSize.height}, ` +
65
94
  `${result.samples.length} cursor samples, ${result.actions.length} actions, ${timeline.zoomRegions.length} zoom regions` +
@@ -166,6 +195,164 @@ async function cmdSheet({ positionals, flags }) {
166
195
  if (sheet.report)
167
196
  console.log(sheet.report);
168
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
+ }
169
356
  function cmdInit({ positionals, flags }) {
170
357
  const written = initProject({
171
358
  dir: positionals[0] ?? ".",
@@ -245,6 +432,8 @@ export async function main(argv = process.argv.slice(2)) {
245
432
  rezoom: cmdRezoom,
246
433
  validate: cmdValidate,
247
434
  sheet: cmdSheet,
435
+ inspect: cmdInspect,
436
+ login: cmdLogin,
248
437
  init: cmdInit,
249
438
  doctor: cmdDoctor,
250
439
  };
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,7 +1,7 @@
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, DEFAULT_PACING, describeTarget, type HighlightOptions, type PacingOptions, 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
6
  export { buildCursorData, buildProject, type BuildProjectOptions, captionAnnotations, DEFAULT_LOOK, type LookOptions, normalizeSamples, type OpenScreenProject, writeProject, } from "./project.ts";
7
7
  export { buildMarks, type Marks, type MarkPoint, type MarkRegion, type MarkSpan, type MarksInput } from "./marks.ts";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
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
6
  export { buildCursorData, buildProject, captionAnnotations, DEFAULT_LOOK, normalizeSamples, writeProject, } from "./project.js";
7
7
  export { buildMarks } from "./marks.js";
package/dist/marks.js CHANGED
@@ -8,6 +8,7 @@
8
8
  import { sourceToOutputMs } from "./idle.js";
9
9
  import { clipUnit, DEPTH_SCALES, boxToStage, clampFocus, toStage } from "./layout.js";
10
10
  import { captionRect } from "./project.js";
11
+ import { normalizeDepth } from "./zoom.js";
11
12
  /** Action target boxes in output-frame coordinates (padding + zoom camera applied). */
12
13
  export function targetRects(input) {
13
14
  const out = [];
@@ -74,7 +75,7 @@ export function applyCamera(rect, regions, t) {
74
75
  const cam = cameraAt(regions, t);
75
76
  if (!cam)
76
77
  return rect;
77
- const s = DEPTH_SCALES[cam.region.depth];
78
+ const s = DEPTH_SCALES[normalizeDepth(cam.region.depth)];
78
79
  const f = clampFocus(cam.region.focus, s);
79
80
  const scale = 1 + (s - 1) * cam.p;
80
81
  const ox = (0.5 - f.cx * s) * cam.p;
@@ -104,8 +105,8 @@ export function buildMarks(input) {
104
105
  });
105
106
  }
106
107
  for (const a of input.actions) {
107
- if (a.point && (a.kind === "click" || a.kind === "type")) {
108
- const t = a.kind === "click" ? a.endMs : a.arriveMs;
108
+ if (a.point && (a.kind === "click" || a.kind === "select" || a.kind === "type")) {
109
+ const t = a.kind === "type" ? a.arriveMs : a.endMs;
109
110
  const p = applyCamera({ ...toStage(layout, vp, a.point), w: 0, h: 0 }, zr, t);
110
111
  if (p.x >= 0 && p.x <= 1 && p.y >= 0 && p.y <= 1) {
111
112
  marks.points.push({
@@ -124,7 +125,7 @@ export function buildMarks(input) {
124
125
  marks.regions.push({
125
126
  start,
126
127
  end: Math.max(start, Math.min(endS, out(z.endMs))),
127
- label: `zoom ${DEPTH_SCALES[z.depth]}x (${z.source ?? "auto"})`,
128
+ label: `zoom ${DEPTH_SCALES[normalizeDepth(z.depth)]}x (${z.source ?? "auto"})`,
128
129
  kind: "zoom",
129
130
  });
130
131
  }
package/dist/motion.d.ts CHANGED
@@ -12,4 +12,4 @@ export declare function travelDuration(distance: number, targetSize?: number, sp
12
12
  /** Deterministic pseudo-random so re-renders of a scenario produce the same motion. */
13
13
  export declare function mulberry32(seed: number): () => number;
14
14
  export declare function makePath(from: Point, to: Point, rand: () => number): (t: number) => Point;
15
- export declare const sleep: (ms: number) => Promise<unknown>;
15
+ export declare const sleep: (ms: number) => Promise<void>;
package/dist/motion.js CHANGED
@@ -14,8 +14,8 @@ export function easeAimed(t) {
14
14
  export function travelDuration(distance, targetSize = 40, speed = 1) {
15
15
  if (distance < 2)
16
16
  return 0;
17
- const fitts = 260 + 170 * Math.log2(distance / Math.max(targetSize, 8) + 1);
18
- return Math.round(Math.min(1400, Math.max(320, fitts)) / speed);
17
+ const fitts = 190 + 120 * Math.log2(distance / Math.max(targetSize, 8) + 1);
18
+ return Math.round(Math.min(950, Math.max(240, fitts)) / speed);
19
19
  }
20
20
  /** Deterministic pseudo-random so re-renders of a scenario produce the same motion. */
21
21
  export function mulberry32(seed) {
@@ -46,4 +46,4 @@ export function makePath(from, to, rand) {
46
46
  };
47
47
  };
48
48
  }
49
- export const sleep = (ms) => new Promise((r) => setTimeout(r, Math.max(0, ms)));
49
+ export const sleep = (ms) => (ms <= 0 ? Promise.resolve() : new Promise((r) => setTimeout(r, ms)));
package/dist/record.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ import type { Page } from "playwright";
1
2
  import { type ComposeResult } from "./compose.ts";
2
3
  import type { IdleOptions } from "./idle.ts";
3
4
  import type { LookOptions } from "./project.ts";
4
5
  import { type PacingOptions, Scene } from "./scene.ts";
5
- import type { RecordingResult, Viewport } from "./types.ts";
6
+ import type { ActionRecord, RecordingResult, Viewport } from "./types.ts";
6
7
  import type { ZoomOptions } from "./zoom.ts";
7
8
  export interface ScenarioContext {
8
9
  /** URL of the scenario's `serve` directory ("" if none). */
@@ -22,6 +23,8 @@ export interface Scenario {
22
23
  cssZoom?: number;
23
24
  /** Static directory (relative to the scenario file) served at `ctx.baseUrl`. */
24
25
  serve?: string;
26
+ /** Saved Playwright storageState JSON file (relative to the scenario file, like `serve`). */
27
+ storageState?: string;
25
28
  colorScheme?: "light" | "dark";
26
29
  /** Seed for the cursor-path jitter (same seed => same motion). */
27
30
  seed?: number;
@@ -37,10 +40,12 @@ export declare function defineScenario(s: Scenario): Scenario;
37
40
  export interface RecordOptions {
38
41
  /** Output directory (default: out/<name>). */
39
42
  outDir?: string;
40
- /** Path of the scenario file; `serve` is resolved relative to it (default: cwd). */
43
+ /** Path of the scenario file; `serve` and `storageState` are resolved relative to it (default: cwd). */
41
44
  scenarioFile?: string;
42
45
  /** Override scenario fields (e.g. from CLI flags). */
43
46
  overrides?: Partial<Omit<Scenario, "run" | "name">>;
47
+ /** Override `scenario.storageState` (resolved relative to cwd). */
48
+ storageState?: string;
44
49
  /** Show the browser while recording (debugging; the recording then includes OS chrome timing). */
45
50
  headed?: boolean;
46
51
  log?: (msg: string) => void;
@@ -50,4 +55,36 @@ export interface RecordResult extends ComposeResult {
50
55
  outDir: string;
51
56
  zoomRegions: ComposeResult["timeline"]["zoomRegions"];
52
57
  }
58
+ export interface DryRunError {
59
+ message: string;
60
+ /** Index of the failing step: the number of actions that completed before it. */
61
+ actionIndex: number;
62
+ }
63
+ export interface DryRunOptions {
64
+ /** Path of the scenario file; `serve` and `storageState` are resolved relative to it (default: cwd). */
65
+ scenarioFile?: string;
66
+ /** Override scenario fields (e.g. from CLI flags). */
67
+ overrides?: Partial<Omit<Scenario, "run" | "name">>;
68
+ /** Override `scenario.storageState` (resolved relative to cwd). */
69
+ storageState?: string;
70
+ /** Show the browser while running. */
71
+ headed?: boolean;
72
+ /** Called with the Playwright page at the end of the run (both on success and failure), before closing the browser. */
73
+ atEnd?: (page: Page) => Promise<void> | void;
74
+ /** Called on failure with the error and page, before `atEnd` and before closing the browser. */
75
+ onFailure?: (err: DryRunError, page: Page) => Promise<void> | void;
76
+ }
77
+ export interface DryRunResult {
78
+ ok: boolean;
79
+ actions: ActionRecord[];
80
+ durationMs: number;
81
+ error?: DryRunError;
82
+ }
83
+ /** Resolves a Playwright storageState file path and throws a clear DemoreelError if missing. */
84
+ export declare function resolveStorageState(statePath: string | undefined, baseDir?: string): string | undefined;
53
85
  export declare function recordScenario(input: Scenario, opts?: RecordOptions): Promise<RecordResult>;
86
+ /**
87
+ * Runs a scenario quickly in fast mode (no ffmpeg, no CDP screencast, no output files).
88
+ * Invokes `atEnd(page)` on both success and failure before closing the browser and static server.
89
+ */
90
+ export declare function dryRunScenario(input: Scenario, opts?: DryRunOptions): Promise<DryRunResult>;