@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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Philipp Temminghoff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,164 @@
1
- # Temporary Holding Version
1
+ # demoreel
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scripted product demo videos ("videos as code"). Write a short Playwright scenario, and
4
+ demoreel records it in headless Chromium, adds a smooth cursor and automatic zoom onto
5
+ whatever you click or type into, and renders an MP4 with
6
+ [OpenScreen](https://github.com/siddharthvaddem/openscreen)'s own exporter. No screen
7
+ recorder, no editing timeline: change the script, run it again.
8
+
9
+ ![demo: recorded, zoomed and rendered by demoreel](docs/assets/local-demo.gif)
10
+
11
+ [MP4 (960px)](docs/assets/local-demo.mp4) · contact sheet with marks (made by
12
+ [framesheet](https://github.com/phil65/framesheet) from `marks.json`):
13
+
14
+ ![contact sheet of the demo video with click, target, zoom and caption marks](docs/assets/local-demo-sheet.png)
15
+
16
+ ```ts
17
+ import { defineScenario } from "@phil65/demoreel";
18
+
19
+ export default defineScenario({
20
+ name: "add-task",
21
+ serve: "./demo-app", // or skip this and scene.goto("https://your.app")
22
+ viewport: { width: 1920, height: 1080 },
23
+ cssZoom: 1.5,
24
+ async run(scene, { baseUrl }) {
25
+ await scene.goto(`${baseUrl}/`);
26
+ await scene.caption("Add a task in seconds", { duration: 3000 });
27
+ await scene.type("#title", "Ship the demo video");
28
+ await scene.click("#add", { label: "add task" });
29
+ await scene.highlight("#count");
30
+ },
31
+ });
32
+ ```
33
+
34
+ ```bash
35
+ npx demoreel run add-task.scenario.ts
36
+ # out/add-task/add-task.mp4, .openscreen project, timeline.json, marks.json, contact sheet
37
+ ```
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ npm install -D @phil65/demoreel playwright
43
+ npx playwright install chromium # Linux CI: npx playwright install --with-deps chromium
44
+ # ffmpeg with libx264 on PATH (or DEMOREEL_FFMPEG=/path/to/ffmpeg):
45
+ sudo apt install ffmpeg # macOS: brew install ffmpeg
46
+ npx demoreel doctor # checks Chromium, ffmpeg, GPU, framesheet
47
+ ```
48
+
49
+ - Node >= 20.11 or Bun. TypeScript scenarios run natively on Bun and Node >= 22.18
50
+ (type stripping; erasable syntax only). On older Node install `tsx` or `jiti` next to
51
+ the scenario (demoreel picks them up) or write the scenario as `.mjs`. In a package
52
+ without `"type": "module"`, name TypeScript scenarios `*.mts`.
53
+ - `playwright` (or `playwright-core`) is a peer dependency; demoreel uses its Chromium.
54
+ - **GPU recommended.** Rendering runs OpenScreen's WebGL (Pixi) + WebCodecs pipeline in
55
+ headless Chromium. demoreel probes for a hardware GL backend (Vulkan / GL on Linux, Metal
56
+ on macOS, D3D11 on Windows) and falls back to SwiftShader with a warning. Rough numbers
57
+ for a 17 s demo: 1080p30 (default) about 77 s on an integrated AMD GPU, 1080p60 about 130 s, 720p30 about 35 s; software
58
+ rendering is 10-20x slower (fine for 640x360 drafts and CI, slow for 1080p).
59
+
60
+ ## CLI
61
+
62
+ ```
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
66
+ demoreel render <project.openscreen> [--out FILE.mp4 --fps --quality --[no-]gpu]
67
+ demoreel rezoom <outdir> re-derive zooms / idle cuts / marks from timeline.json
68
+ --max-depth 4 --lead 350 --hold 800 --no-auto-zoom --options JSON
69
+ --trim-idle --idle-options '{"minMs":1500,"keepMs":600,"mode":"speed"}' --render
70
+ demoreel validate <project> OpenScreen's validateProjectData / normalizeProjectEditor
71
+ demoreel sheet <video|outdir> framesheet inspect --marks marks.json, else ffmpeg tiles
72
+ demoreel init [dir] [--url URL] [--js] scaffold a scenario (+ a demo app to record)
73
+ demoreel doctor environment check
74
+ ```
75
+
76
+ Each run writes into `out/<name>/`:
77
+
78
+ | file | what |
79
+ | --- | --- |
80
+ | `<name>.mp4` | the rendered video |
81
+ | `<name>.openscreen` | OpenScreen v2 project: open it in the OpenScreen app to tweak by hand, then `demoreel render` |
82
+ | `recording.mp4` + `.cursor.json` | raw CFR recording and cursor telemetry (OpenScreen's sidecar format) |
83
+ | `timeline.json` | what happened when: actions with target boxes, zoom / trim regions, captions, timings |
84
+ | `marks.json` | the same in [framesheet's marks format](https://github.com/phil65/framesheet/blob/main/schema/marks.schema.json), in rendered-video coordinates |
85
+ | `framesheet/` or `<name>.sheet.png` | contact sheet for review |
86
+
87
+ ## Scene API
88
+
89
+ | method | does |
90
+ | --- | --- |
91
+ | `goto(url)` | navigate (the first call starts the recording) |
92
+ | `click(target, { zoom, label, navigates })` | eased cursor travel, aim, click; zooms by default |
93
+ | `type(target, text, { clear, zoom })` | click into a field and type with human-ish timing |
94
+ | `hover(target, { dwell, zoom })` | move there and rest (no zoom unless asked) |
95
+ | `moveTo(target \| {x, y})` | move the cursor, nothing else |
96
+ | `scroll(target \| { by: px })` | smooth scroll (the page's or the target's scroll container) |
97
+ | `press(key)` | keyboard shortcut, Playwright syntax |
98
+ | `pause(ms)` | wait |
99
+ | `caption(text, { duration, wait })` | caption overlay (an OpenScreen text annotation, sharp at any zoom) |
100
+ | `zoom(target, { depth, duration, context, wait })` | explicit zoom that overrides automatic ones in its window |
101
+ | `highlight(target, { duration, color, zoom })` | outline drawn into the page around an element |
102
+
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.
105
+
106
+ 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`
108
+ (`speed`, `beforeAction`, `afterClick`, `typeDelay`, ...), `zoom` (see below), `look`
109
+ (`wallpaper`, `padding`, `borderRadius`, `shadowIntensity`, `aspectRatio`,
110
+ `captionPosition`), `trimIdle`.
111
+
112
+ Library: `recordScenario`, `deriveZoomRegions`, `deriveIdleRegions`, `buildProject`,
113
+ `buildCursorData`, `buildMarks`, `renderProject`, `validateProject`, `rezoom`,
114
+ `reviewSheet`, all typed (`dist/index.d.ts`).
115
+
116
+ ## How cursor and zoom are derived
117
+
118
+ - **Cursor**: every Scene action moves the real mouse along an eased, slightly arced Bezier
119
+ path (duration from Fitts' law, seeded jitter, so re-runs look the same). Positions are
120
+ sampled at ~60 Hz on the recording clock (CDP screencast frame timestamps) with cursor type
121
+ (arrow / pointer / text from the element's CSS) and click events, and written as OpenScreen
122
+ cursor telemetry. OpenScreen draws the cursor in the export (smoothing, click bounce,
123
+ motion blur), so it stays sharp under zoom.
124
+ - **Zoom**: each click / type (and hover with `zoom: true`) records the target's bounding box.
125
+ The depth is the deepest of OpenScreen's six levels (1.25x to 5x) at which the box still
126
+ fits 80% of the view width and 50% of its height (capped by `zoom.maxDepth`, default 3).
127
+ Regions start `leadMs` before the cursor arrives (OpenScreen eases in over ~1.5 s), hold
128
+ `holdMs` after the action, merge with the next action when the union still zooms, and
129
+ otherwise chain so OpenScreen pans instead of zooming out and in. Scrolls and navigation end
130
+ a zoom. The focus is converted to OpenScreen's stage coordinates (padding included) and
131
+ clamped so a zoomed view never shows wallpaper.
132
+ - **Anchors**: put `data-demoreel-zoom` on a container to zoom onto the container whenever an
133
+ action targets something inside it (`="2"` forces depth 2, `="off"` disables zoom there).
134
+ - **Trim idle** (`trimIdle: true` or `--trim-idle`): stretches with no action, cursor motion,
135
+ caption, zoom transition or visual change are cut to `keepMs` with OpenScreen trim regions
136
+ (or sped up with `mode: "speed"`). `timeline.json` keeps recording times; `marks.json`
137
+ uses output times.
138
+ - **Captions** sit at the bottom unless that would cover a target active at the time; then
139
+ they move to the top (`look.captionPosition: "auto"`, or force `"top"` / `"bottom"`).
140
+
141
+ ## Agent loop
142
+
143
+ `timeline.json` + `marks.json` make the output checkable without watching the video:
144
+ `demoreel sheet out/<name>` runs `framesheet inspect <video> --marks marks.json` (framesheet
145
+ on PATH, in `node_modules`, or via `uvx framesheet`) which draws clicks, targets, zooms and
146
+ captions onto the tiles and flags e.g. captions covering a target. Iterate with
147
+ `demoreel rezoom` (no re-recording) and `demoreel render`. A Claude Code skill for this loop
148
+ is in [docs/skill.md](docs/skill.md).
149
+
150
+ ## Limitations
151
+
152
+ - **No HiDPI capture**: Chromium's screencast delivers frames in CSS pixels and ignores
153
+ `deviceScaleFactor`. Use `cssZoom` (pages you control) or a larger viewport for crisp text.
154
+ - **Real-time recording**: a scenario takes as long as the video (plus encode and render).
155
+ - **GPU recommended** for rendering (see above).
156
+ - On Linux the OpenScreen GUI's preview does not show the cursor overlay for imported projects;
157
+ the export (and demoreel's render) does.
158
+ - Audio, webcam overlays and multi-tab recordings are not supported.
159
+
160
+ ## License
161
+
162
+ MIT. The prebuilt renderer bundles unmodified [OpenScreen](https://github.com/siddharthvaddem/openscreen)
163
+ code (MIT) and npm packages listed in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)
164
+ (licence texts in `licenses/`).
@@ -0,0 +1,31 @@
1
+ # Third-party notices
2
+
3
+ demoreel's prebuilt renderer (`dist/renderer/`) and `dist/openscreen/project.js` are bundled
4
+ from third-party code. Generated by `scripts/build-renderer.ts`.
5
+
6
+ ## OpenScreen
7
+
8
+ Unmodified source files from [OpenScreen](https://github.com/siddharthvaddem/openscreen)
9
+ (commit `ca8104c279da0d4b4481ec992ff103949e22c772`, MIT License, Copyright (c) 2025 Siddharth Vaddem), including its
10
+ cursor and wallpaper assets: [licenses/openscreen.txt](licenses/openscreen.txt). The exact files
11
+ are listed in `vendor/openscreen/VENDORED.md` in the demoreel repository.
12
+
13
+ ## npm packages bundled into dist/
14
+
15
+ | package | version | license | text | source |
16
+ | --- | --- | --- | --- | --- |
17
+ | colord | 2.14.0 | MIT | [licenses/colord.txt](licenses/colord.txt) | https://github.com/omgovich/colord |
18
+ | earcut | 3.2.4 | ISC | [licenses/earcut.txt](licenses/earcut.txt) | git://github.com/mapbox/earcut |
19
+ | eventemitter3 | 5.0.4 | MIT | [licenses/eventemitter3.txt](licenses/eventemitter3.txt) | git://github.com/primus/eventemitter3 |
20
+ | gif.js | 0.2.0 | MIT | [licenses/gif.js.txt](licenses/gif.js.txt) | https://github.com/jnordberg/gif.js |
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 |
23
+ | motion-dom | 12.43.0 | MIT | [licenses/motion-dom.txt](licenses/motion-dom.txt) | https://github.com/motiondivision/motion |
24
+ | motion-utils | 12.39.0 | MIT | [licenses/motion-utils.txt](licenses/motion-utils.txt) | https://github.com/motiondivision/motion |
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 |
26
+ | pixi-filters | 6.1.5 | MIT | [licenses/pixi-filters.txt](licenses/pixi-filters.txt) | https://github.com/pixijs/filters |
27
+ | pixi.js | 8.23.0 | MIT | [licenses/pixi.js.txt](licenses/pixi.js.txt) | https://github.com/pixijs/pixijs |
28
+ | web-demuxer | 4.0.0 | MIT | [licenses/web-demuxer.txt](licenses/web-demuxer.txt) | https://github.com/ForeverSc/web-demuxer |
29
+
30
+ MPL-2.0 code (mediabunny) is included unmodified; its source is available from the
31
+ repository linked above and from the npm package of the listed version.
package/dist/args.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ /** CLI argument parsing (no dependencies; Node 20 compatible). */
2
+ export type FlagType = "boolean" | "string" | "number";
3
+ export interface FlagSpec {
4
+ type: FlagType;
5
+ alias?: string;
6
+ description: string;
7
+ /** Shown in help, e.g. "DIR". */
8
+ value?: string;
9
+ }
10
+ export interface CommandSpec {
11
+ usage: string;
12
+ description: string;
13
+ /** Required positional count. */
14
+ positionals: {
15
+ min: number;
16
+ max: number;
17
+ };
18
+ flags: Record<string, FlagSpec>;
19
+ }
20
+ export declare const COMMANDS: Record<string, CommandSpec>;
21
+ export type FlagValue = string | number | boolean;
22
+ export interface ParsedArgs {
23
+ command: string | null;
24
+ positionals: string[];
25
+ flags: Record<string, FlagValue>;
26
+ help: boolean;
27
+ version: boolean;
28
+ }
29
+ export declare class UsageError extends Error {
30
+ constructor(message: string);
31
+ }
32
+ export declare function parseArgs(argv: string[]): ParsedArgs;
33
+ /** "1280x720" -> { width, height }. */
34
+ export declare function parseSize(s: string): {
35
+ width: number;
36
+ height: number;
37
+ };
38
+ /** Tri-state GPU flag: true / false / "auto" when absent. */
39
+ export declare function gpuMode(flags: Record<string, FlagValue>): boolean | "auto";
40
+ export declare function parseJsonFlag(name: string, raw: FlagValue | undefined): Record<string, unknown>;
41
+ export declare function helpText(command?: string | null): string;
package/dist/args.js ADDED
@@ -0,0 +1,230 @@
1
+ /** CLI argument parsing (no dependencies; Node 20 compatible). */
2
+ const gpu = { type: "boolean", description: "force GPU on/off (default: auto-detect, fall back to software)" };
3
+ const fps = { type: "number", value: "N", description: "output frame rate (default 30)" };
4
+ const quality = { type: "string", value: "Q", description: "medium (720p) | good (1080p, default) | source" };
5
+ const verbose = { type: "boolean", alias: "v", description: "print browser console output" };
6
+ const frames = { type: "number", alias: "n", value: "N", description: "contact sheet tiles (default 12)" };
7
+ const framesheet = { type: "string", value: "MODE", description: "auto (default: use framesheet if found) | off" };
8
+ const trimIdle = { type: "boolean", description: "cut idle stretches (OpenScreen trim regions)" };
9
+ export const COMMANDS = {
10
+ run: {
11
+ usage: "run <scenario.ts|js>",
12
+ description: "record a scenario, write the OpenScreen project, render the MP4 and a contact sheet",
13
+ positionals: { min: 1, max: 1 },
14
+ flags: {
15
+ out: { type: "string", alias: "o", value: "DIR", description: "output directory (default out/<name>)" },
16
+ render: { type: "boolean", description: "render the MP4 (default; --no-render to only record)" },
17
+ sheet: { type: "boolean", description: "write a contact sheet after rendering (default)" },
18
+ gpu,
19
+ fps,
20
+ quality,
21
+ "trim-idle": trimIdle,
22
+ speed: { type: "number", value: "X", description: "pacing speed multiplier (2 = twice as fast)" },
23
+ viewport: { type: "string", value: "WxH", description: "override the scenario viewport, e.g. 1280x720" },
24
+ headed: { type: "boolean", description: "show the browser while recording" },
25
+ frames,
26
+ framesheet,
27
+ verbose,
28
+ },
29
+ },
30
+ render: {
31
+ usage: "render <project.openscreen>",
32
+ description: "render an OpenScreen project to MP4 with OpenScreen's exporter (headless)",
33
+ positionals: { min: 1, max: 1 },
34
+ flags: {
35
+ out: { type: "string", alias: "o", value: "FILE", description: "output MP4 (default: next to the project)" },
36
+ gpu,
37
+ fps,
38
+ quality,
39
+ verbose,
40
+ },
41
+ },
42
+ rezoom: {
43
+ usage: "rezoom <outdir>",
44
+ description: "re-derive zoom / idle regions, project and marks from timeline.json (no re-recording)",
45
+ positionals: { min: 1, max: 1 },
46
+ flags: {
47
+ options: { type: "string", value: "JSON", description: 'zoom options, e.g. \'{"maxDepth":4,"holdMs":1200}\'' },
48
+ "max-depth": { type: "number", value: "D", description: "deepest automatic zoom (1-6)" },
49
+ lead: { type: "number", value: "MS", description: "zoom-in lead before the cursor arrives" },
50
+ hold: { type: "number", value: "MS", description: "stay zoomed after an action" },
51
+ "auto-zoom": { type: "boolean", description: "automatic zooms (--no-auto-zoom: only scene.zoom())" },
52
+ "trim-idle": trimIdle,
53
+ "idle-options": { type: "string", value: "JSON", description: 'e.g. \'{"minMs":1500,"keepMs":800,"mode":"speed"}\'' },
54
+ render: { type: "boolean", description: "render the MP4 afterwards" },
55
+ gpu,
56
+ fps,
57
+ quality,
58
+ verbose,
59
+ },
60
+ },
61
+ validate: {
62
+ usage: "validate <project.openscreen>",
63
+ description: "run OpenScreen's validateProjectData / normalizeProjectEditor on a project",
64
+ positionals: { min: 1, max: 1 },
65
+ flags: { json: { type: "boolean", description: "print the full result as JSON" } },
66
+ },
67
+ sheet: {
68
+ usage: "sheet <video.mp4|outdir>",
69
+ description: "contact sheet via framesheet (with marks.json) or ffmpeg",
70
+ positionals: { min: 1, max: 1 },
71
+ flags: {
72
+ out: { type: "string", alias: "o", value: "DIR", description: "output directory (default: next to the video)" },
73
+ marks: { type: "string", value: "FILE", description: "framesheet marks (default: marks.json next to the video)" },
74
+ frames,
75
+ framesheet,
76
+ },
77
+ },
78
+ init: {
79
+ usage: "init [dir]",
80
+ description: "scaffold an example scenario (and a copy of the demo app)",
81
+ positionals: { min: 0, max: 1 },
82
+ flags: {
83
+ name: { type: "string", value: "NAME", description: 'scenario name (default "demo")' },
84
+ url: { type: "string", value: "URL", description: "record this URL instead of the bundled demo app" },
85
+ js: { type: "boolean", description: "write a .mjs scenario instead of .ts" },
86
+ force: { type: "boolean", description: "overwrite existing files" },
87
+ },
88
+ },
89
+ doctor: {
90
+ usage: "doctor",
91
+ description: "check Chromium, ffmpeg, GPU and framesheet",
92
+ positionals: { min: 0, max: 0 },
93
+ flags: {},
94
+ },
95
+ };
96
+ export class UsageError extends Error {
97
+ constructor(message) {
98
+ super(message);
99
+ this.name = "UsageError";
100
+ }
101
+ }
102
+ export function parseArgs(argv) {
103
+ const res = { command: null, positionals: [], flags: {}, help: false, version: false };
104
+ let i = 0;
105
+ while (i < argv.length && argv[i].startsWith("-")) {
106
+ const a = argv[i++];
107
+ if (a === "--help" || a === "-h")
108
+ res.help = true;
109
+ else if (a === "--version" || a === "-V")
110
+ res.version = true;
111
+ else
112
+ throw new UsageError(`unknown option ${a}`);
113
+ }
114
+ if (i >= argv.length)
115
+ return res;
116
+ const command = argv[i++];
117
+ const spec = COMMANDS[command];
118
+ if (!spec)
119
+ throw new UsageError(`unknown command "${command}" (try --help)`);
120
+ res.command = command;
121
+ const aliases = new Map(Object.entries(spec.flags).flatMap(([k, f]) => (f.alias ? [[f.alias, k]] : [])));
122
+ let onlyPositionals = false;
123
+ for (; i < argv.length; i++) {
124
+ const a = argv[i];
125
+ if (onlyPositionals || !a.startsWith("-") || a === "-") {
126
+ res.positionals.push(a);
127
+ continue;
128
+ }
129
+ if (a === "--") {
130
+ onlyPositionals = true;
131
+ continue;
132
+ }
133
+ if (a === "--help" || a === "-h") {
134
+ res.help = true;
135
+ continue;
136
+ }
137
+ let name;
138
+ let inline;
139
+ if (a.startsWith("--")) {
140
+ const eq = a.indexOf("=");
141
+ name = eq > 0 ? a.slice(2, eq) : a.slice(2);
142
+ inline = eq > 0 ? a.slice(eq + 1) : undefined;
143
+ }
144
+ else {
145
+ const alias = aliases.get(a.slice(1));
146
+ if (!alias)
147
+ throw new UsageError(`unknown option ${a} for "${command}"`);
148
+ name = alias;
149
+ }
150
+ let negated = false;
151
+ if (!spec.flags[name] && name.startsWith("no-") && spec.flags[name.slice(3)]?.type === "boolean") {
152
+ name = name.slice(3);
153
+ negated = true;
154
+ }
155
+ const f = spec.flags[name];
156
+ if (!f)
157
+ throw new UsageError(`unknown option --${name} for "${command}"`);
158
+ if (f.type === "boolean") {
159
+ if (inline !== undefined) {
160
+ if (!/^(true|false|1|0)$/.test(inline))
161
+ throw new UsageError(`--${name} expects true/false`);
162
+ res.flags[name] = /^(true|1)$/.test(inline) !== negated;
163
+ }
164
+ else
165
+ res.flags[name] = !negated;
166
+ continue;
167
+ }
168
+ if (negated)
169
+ throw new UsageError(`--no-${name} is not valid`);
170
+ const raw = inline ?? argv[++i];
171
+ if (raw === undefined)
172
+ throw new UsageError(`--${name} needs a value`);
173
+ if (f.type === "number") {
174
+ const n = Number(raw);
175
+ if (!Number.isFinite(n))
176
+ throw new UsageError(`--${name} expects a number, got "${raw}"`);
177
+ res.flags[name] = n;
178
+ }
179
+ else
180
+ res.flags[name] = raw;
181
+ }
182
+ if (!res.help) {
183
+ const { min, max } = spec.positionals;
184
+ if (res.positionals.length < min)
185
+ throw new UsageError(`usage: demoreel ${spec.usage}`);
186
+ if (res.positionals.length > max)
187
+ throw new UsageError(`too many arguments; usage: demoreel ${spec.usage}`);
188
+ }
189
+ return res;
190
+ }
191
+ /** "1280x720" -> { width, height }. */
192
+ export function parseSize(s) {
193
+ const m = /^(\d+)\s*[x:*]\s*(\d+)$/i.exec(s.trim());
194
+ if (!m)
195
+ throw new UsageError(`expected WxH like 1280x720, got "${s}"`);
196
+ return { width: Number(m[1]), height: Number(m[2]) };
197
+ }
198
+ /** Tri-state GPU flag: true / false / "auto" when absent. */
199
+ export function gpuMode(flags) {
200
+ return flags.gpu === undefined ? "auto" : Boolean(flags.gpu);
201
+ }
202
+ export function parseJsonFlag(name, raw) {
203
+ if (raw === undefined)
204
+ return {};
205
+ try {
206
+ const v = JSON.parse(String(raw));
207
+ if (!v || typeof v !== "object" || Array.isArray(v))
208
+ throw new Error("not an object");
209
+ return v;
210
+ }
211
+ catch (e) {
212
+ throw new UsageError(`--${name} expects a JSON object: ${e.message}`);
213
+ }
214
+ }
215
+ export function helpText(command) {
216
+ const fmtFlags = (flags) => Object.entries(flags)
217
+ .map(([k, f]) => {
218
+ const left = `${f.alias ? `-${f.alias}, ` : " "}--${f.type === "boolean" ? `[no-]${k}` : k}${f.value ? ` ${f.value}` : ""}`;
219
+ return ` ${left.padEnd(30)} ${f.description}`;
220
+ })
221
+ .join("\n");
222
+ if (command && COMMANDS[command]) {
223
+ const c = COMMANDS[command];
224
+ return `demoreel ${c.usage}\n\n${c.description}\n${Object.keys(c.flags).length ? `\noptions:\n${fmtFlags(c.flags)}\n` : ""}`;
225
+ }
226
+ const list = Object.values(COMMANDS)
227
+ .map((c) => ` ${c.usage.padEnd(32)} ${c.description}`)
228
+ .join("\n");
229
+ return `demoreel: scripted product demo videos (auto cursor + auto zoom, rendered by OpenScreen)\n\nusage: demoreel <command> [options]\n\ncommands:\n${list}\n\nrun \`demoreel <command> --help\` for options.\n`;
230
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(argv?: string[]): Promise<void>;