@reelscript/cli 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trevin Lee
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 ADDED
@@ -0,0 +1,179 @@
1
+ # reelscript
2
+
3
+ ![A demo rendered by reelscript: the cursor glides to a button, a modal opens, the view zooms in, a name is typed, and the zoom releases](docs/demo.gif)
4
+
5
+ <sup>Made with reelscript, by reelscript: CI renders [examples/basic.ts](examples/basic.ts) inside the published container on every push to `main` and commits the result.</sup>
6
+
7
+ **Product demos as code.** Write a script, render a demo, re-run it in CI when your UI changes.
8
+
9
+
10
+ Screen-recording tools (Screen Studio, Arcade, Tango) all rot the same way: your product UI changes and your beautiful demo is now a lie, so you re-record it by hand. reelscript makes a demo a *build artifact*. The video is generated from a script, so when your UI updates you just re-run it.
11
+
12
+ ```ts
13
+ import { createDemo } from "@reelscript/cli";
14
+
15
+ const demo = createDemo({ theme: "macos", viewport: [1280, 800], fps: 60 });
16
+
17
+ await demo.browser.goto("https://app.local");
18
+ await demo.cursor.moveTo("#new-project", { ease: "smooth" });
19
+ await demo.cursor.click();
20
+
21
+ demo.zoom.to("#modal", { scale: 1.6 });
22
+ demo.say("Give it a name, and hit Create.");
23
+ await demo.type("#project-name", "Acme Q3 Launch", { wpm: 400 });
24
+ await demo.cursor.moveTo("#create");
25
+ await demo.cursor.click();
26
+ demo.zoom.out();
27
+ await demo.waitForNarration();
28
+
29
+ await demo.render("out/demo.mp4");
30
+ ```
31
+
32
+ ## How it works
33
+
34
+ - **Code-first, not a UI timeline.** The demo is a script you version, diff, and review.
35
+ - **Deterministic offline rendering.** Every step is scripted, so frames are produced one at a time: drive a headless Chromium to the state for frame *n*, capture it, composite the animated cursor and zoom, and pipe it to ffmpeg. Perfect 60fps with no dropped frames, and it runs headless in CI.
36
+ - **The page's clock is virtual.** reelscript replaces timers, `requestAnimationFrame`, `Date`, and `performance.now` inside the page and steps CSS transitions through the Web Animations API, advancing exactly one frame per rendered frame. A 200ms fade is 12 frames at 60fps no matter how slow capture is.
37
+ - **Cinematic layer.** Eased cursor motion, click ripples, zoom-to-element, accelerated typing. The polish that makes a demo feel produced, done as math over frames rather than captured motion.
38
+ - **Own the DOM.** Targets are CSS selectors, and `browser.mockAPI()` returns canned JSON so demos never depend on a live backend, real credentials, or flaky auth.
39
+ - **Clean stage.** The `macos` theme composites the page into a browser window on a mocked macOS desktop, so there is nothing to tidy up before recording.
40
+ - **A real desktop.** Windows have positions, sizes, focus, and z-order. Open a browser and a terminal side by side, click between them, and the one you click comes to the front. Selectors resolve in the focused window (or the one you name), typing goes to the focused window, and zoom targets can be in any window.
41
+ - **Terminal windows.** `terminal.open()` puts a Terminal-style window on the desktop and `terminal.run()` types a command and streams its output. Declare the output in the script, or run the real command once with `reelscript record` and replay the recording frame-exact on every render.
42
+ - **Narration as code.** `say()` speaks a line while the actions continue, sentences never overlap, and `waitForNarration()` paces the timeline to the voice. The default voice is Kokoro, an open-weights model that runs on CPU with no account, so it works offline and in CI. Plug in any engine through the `tts` option.
43
+
44
+ ## Install
45
+
46
+ ```sh
47
+ npm install -D @reelscript/cli
48
+ npx playwright install chromium
49
+ ```
50
+
51
+ The package installs a `reelscript` command. Scripts are ES modules that use top-level `await`; set `"type": "module"` in your package.json, or the CLI will run them as modules for you. (The unscoped name is blocked by npm's similarity rule against `rescript`, hence the scope.)
52
+
53
+ ## Try it
54
+
55
+ ```sh
56
+ git clone https://github.com/trevin-lee/reelscript && cd reelscript
57
+ npm install
58
+ npx playwright install chromium
59
+ npm run example # renders examples/basic.ts -> out/basic.mp4
60
+ ```
61
+
62
+ The example drives a small dashboard app that ships with the repo, so it is fully self-contained. A 6.5s demo at 1424x992 / 60fps renders in about 15s on an M-series laptop.
63
+
64
+ ## Run in CI
65
+
66
+ The container is the canonical render environment: Chromium, ffmpeg, the theme font, and the narration model are all baked in, so a script renders the same pixels on every machine and never downloads anything at run time.
67
+
68
+ ```sh
69
+ docker run --rm -v "$PWD:/work" ghcr.io/trevin-lee/reelscript:main render demo.ts --out demo.mp4
70
+ ```
71
+
72
+ Tags: `main` tracks the main branch, `sha-<commit>` pins a build, and each release adds `<version>` and `latest`. While the repository is private the image is too, so `docker login ghcr.io` with a GitHub token that has `read:packages` first.
73
+
74
+ In GitHub Actions:
75
+
76
+ ```yaml
77
+ jobs:
78
+ demo:
79
+ runs-on: ubuntu-latest
80
+ container: ghcr.io/trevin-lee/reelscript:main
81
+ steps:
82
+ - uses: actions/checkout@v5
83
+ - run: reelscript render demo.ts --out demo.mp4
84
+ ```
85
+
86
+ Scripts may `import { createDemo } from "@reelscript/cli"` without installing the package locally; the CLI resolves it to its own copy.
87
+
88
+ ## CLI
89
+
90
+ ```sh
91
+ reelscript render <script.ts> [--out demo.mp4] # render a script to video
92
+ reelscript preview <script.ts> --at 2.5 [--out f.png] # render the single frame at 2.5s
93
+ ```
94
+
95
+ `preview` is the fast way to iterate on a moment of a demo without waiting for the whole video.
96
+
97
+ ## API
98
+
99
+ | Call | What it does |
100
+ | --- | --- |
101
+ | `createDemo({ theme, viewport, desktop, fps, deterministic, gif, voice, tts, pronunciations })` | `theme`: `"macos"` or `"bare"`. `viewport` is the first window's content size, `desktop` the output size (default: the first window plus margins). Defaults: macos, 1280x800, 60fps, deterministic clock on, Kokoro voice `af_heart`. |
102
+ | `demo.browser.goto(url, { settle })` | Navigate, then hold for `settle` ms (default 400). |
103
+ | `demo.browser.mockAPI(pattern, json, { status })` | Fulfil matching requests with canned JSON. |
104
+ | `demo.cursor.moveTo(target, { ease, duration, window })` | Glide to a selector or `{x, y}` in the focused window, or in `window`. Duration defaults from distance. Eases: `smooth`, `snappy`, `overshoot`, `linear`. |
105
+ | `demo.cursor.click({ button })` | Click at the cursor, with a ripple. Focuses and raises the window under the cursor. |
106
+ | `demo.zoom.to(target, { scale, duration, ease, window })` | Animate a zoom centred on a target. Runs alongside the actions that follow. |
107
+ | `demo.zoom.out({ duration, ease })` | Return to 1x. |
108
+ | `demo.type(selector, text, { wpm })` | Focus the field and type at `wpm` (default 300). |
109
+ | `demo.press(key)` | Press a key or chord, e.g. `"Enter"`, `"Meta+K"`. |
110
+ | `demo.wait(ms)` | Hold. |
111
+ | `demo.browser.focus()`, `demo.terminal.focus()` | Bring a window to the front and direct typing to it. |
112
+ | `demo.browser.place({ x, y, width, height })`, `demo.terminal.place(...)` | Move or resize a window. `x, y` is the frame origin in desktop pixels; `width, height` is the content size. |
113
+ | `demo.terminal.open({ title, prompt, fontSize, x, y, width, height })` | Open a terminal window and focus it. The first window opened takes the main position; later ones cascade to the lower right unless placed. |
114
+ | `demo.terminal.run(cmd, { output, duration, wpm, speed, maxGapMs })` | Type `cmd`. With `output`, stream that text. Without it, replay the recording for `cmd` from `recordings/`. |
115
+ | `demo.say(text, { voice, speed })` | Queue narration. Starts immediately or after the previous sentence, while following actions run. |
116
+ | `demo.waitForNarration()` | Hold until everything queued with `say()` has been spoken. |
117
+ | `demo.render(path)` | Render to `.mp4` (H.264) or `.gif` (palette-optimized, 960px / 20fps by default, see `gif` option). Honours `REELSCRIPT_OUT` and `REELSCRIPT_SNAPSHOT_AT`, which the CLI uses. |
118
+
119
+ ## Status
120
+
121
+ Early but working end to end. Roadmap, roughly in order:
122
+
123
+ - An editor window built on VS Code's web workbench
124
+ - Window open/close animations and drag-to-move
125
+ - Pseudo-terminal recording for TTY-only tools
126
+ - Captions generated from narration (SRT and burned-in)
127
+ - Auto-zoom that follows the cursor, and zoom transitions with a bit of drift
128
+ - `watch` mode with live preview while editing a script
129
+ - Retina (2x) output
130
+ - Transitions between scenes and callouts
131
+ - Python bindings over the same timeline
132
+ - A Linux desktop backend (Xvfb in a container) for demos of native apps, targeted by coordinates or accessibility names
133
+
134
+ ## Several windows
135
+
136
+ ```ts
137
+ const demo = createDemo({ viewport: [1180, 720], desktop: [1600, 1000] });
138
+ await demo.browser.goto("https://app.local");
139
+ await demo.terminal.open({ title: "acme", x: 700, y: 560, width: 840, height: 360 });
140
+ await demo.terminal.run("npm run deploy", { output: "Live at https://acme.app\n" });
141
+ await demo.cursor.moveTo("#new-project", { window: "browser" }); // the browser is behind the terminal
142
+ await demo.cursor.click(); // click raises it
143
+ ```
144
+
145
+ Each window is its own Chromium page; the desktop composites them in z-order with the theme's frames and shadows. See [examples/desktop.ts](examples/desktop.ts).
146
+
147
+ ## Terminal demos
148
+
149
+ ```ts
150
+ await demo.terminal.open({ title: "acme", prompt: "acme % " });
151
+ await demo.terminal.run("npm install -D @reelscript/cli", { output: "\nadded 38 packages in 2s\n" });
152
+ await demo.terminal.run("node --version"); // replayed from recordings/node-version-<hash>.json
153
+ ```
154
+
155
+ Declared output never executes anything, so it renders identically everywhere. For real commands, run
156
+
157
+ ```sh
158
+ reelscript record examples/terminal.ts
159
+ ```
160
+
161
+ once (or in CI whenever your CLI changes): it executes every `terminal.run` that has no `output`, captures stdout and stderr with timestamps, and saves `recordings/<command-slug>.json` next to the script. Rendering replays the recording with long silences capped (`maxGapMs`) and optional `speed`, and never needs the tool installed. Commit the recordings; they're small JSON. Commands run through a shell with `FORCE_COLOR=1` and a 256-color `TERM`, without a pseudo-terminal, so tools that insist on a TTY for progress bars may print their non-interactive output.
162
+
163
+ See [examples/terminal.ts](examples/terminal.ts).
164
+
165
+ ## Narration
166
+
167
+ `say()` uses [Kokoro-82M](https://huggingface.co/onnx-community/Kokoro-82M-v1.0-ONNX) through the optional `kokoro-js` dependency. The model (about 90 MB) downloads on first use into `~/.cache/reelscript` (override with `REELSCRIPT_CACHE`); `reelscript warmup` fetches it ahead of time, and the container image ships with it baked in. Synthesized clips are cached by text and voice, so re-renders don't re-synthesize unchanged lines. Voices include `af_heart`, `af_bella`, `am_michael`, `bf_emma`, `bm_george` and more.
168
+
169
+ GIF output has no audio track; narration still paces the timeline. Render to `.mp4` for sound.
170
+
171
+ To skip the model entirely, install with `npm install --omit=optional` and pass your own `tts` engine, or don't call `say()`.
172
+
173
+ ## Requirements
174
+
175
+ Node 20+. ffmpeg is bundled via `ffmpeg-static`; set `REELSCRIPT_FFMPEG` to use your own.
176
+
177
+ ## License
178
+
179
+ MIT
Binary file
@@ -0,0 +1,92 @@
1
+ Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+ -----------------------------------------------------------
8
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
+ -----------------------------------------------------------
10
+
11
+ PREAMBLE
12
+ The goals of the Open Font License (OFL) are to stimulate worldwide
13
+ development of collaborative font projects, to support the font creation
14
+ efforts of academic and linguistic communities, and to provide a free and
15
+ open framework in which fonts may be shared and improved in partnership
16
+ with others.
17
+
18
+ The OFL allows the licensed fonts to be used, studied, modified and
19
+ redistributed freely as long as they are not sold by themselves. The
20
+ fonts, including any derivative works, can be bundled, embedded,
21
+ redistributed and/or sold with any software provided that any reserved
22
+ names are not used by derivative works. The fonts and derivatives,
23
+ however, cannot be released under any other type of license. The
24
+ requirement for fonts to remain under this license does not apply
25
+ to any document created using the fonts or their derivatives.
26
+
27
+ DEFINITIONS
28
+ "Font Software" refers to the set of files released by the Copyright
29
+ Holder(s) under this license and clearly marked as such. This may
30
+ include source files, build scripts and documentation.
31
+
32
+ "Reserved Font Name" refers to any names specified as such after the
33
+ copyright statement(s).
34
+
35
+ "Original Version" refers to the collection of Font Software components as
36
+ distributed by the Copyright Holder(s).
37
+
38
+ "Modified Version" refers to any derivative made by adding to, deleting,
39
+ or substituting -- in part or in whole -- any of the components of the
40
+ Original Version, by changing formats or by porting the Font Software to a
41
+ new environment.
42
+
43
+ "Author" refers to any designer, engineer, programmer, technical
44
+ writer or other person who contributed to the Font Software.
45
+
46
+ PERMISSION AND CONDITIONS
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
49
+ redistribute, and sell modified and unmodified copies of the Font
50
+ Software, subject to the following conditions:
51
+
52
+ 1) Neither the Font Software nor any of its individual components,
53
+ in Original or Modified Versions, may be sold by itself.
54
+
55
+ 2) Original or Modified Versions of the Font Software may be bundled,
56
+ redistributed and/or sold with any software, provided that each copy
57
+ contains the above copyright notice and this license. These can be
58
+ included either as stand-alone text files, human-readable headers or
59
+ in the appropriate machine-readable metadata fields within text or
60
+ binary files as long as those fields can be easily viewed by the user.
61
+
62
+ 3) No Modified Version of the Font Software may use the Reserved Font
63
+ Name(s) unless explicit written permission is granted by the corresponding
64
+ Copyright Holder. This restriction only applies to the primary font name as
65
+ presented to the users.
66
+
67
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
+ Software shall not be used to promote, endorse or advertise any
69
+ Modified Version, except to acknowledge the contribution(s) of the
70
+ Copyright Holder(s) and the Author(s) or with their explicit written
71
+ permission.
72
+
73
+ 5) The Font Software, modified or unmodified, in part or in whole,
74
+ must be distributed entirely under this license, and must not be
75
+ distributed under any other license. The requirement for fonts to
76
+ remain under this license does not apply to any document created
77
+ using the Font Software.
78
+
79
+ TERMINATION
80
+ This license becomes null and void if any of the above conditions are
81
+ not met.
82
+
83
+ DISCLAIMER
84
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * reelscript CLI
4
+ *
5
+ * reelscript render <script.ts> [--out demo.mp4]
6
+ * reelscript preview <script.ts> --at 2.5 [--out frame.png]
7
+ *
8
+ * Scripts are ordinary TS/JS modules that build a Demo and call
9
+ * `demo.render(...)`. The CLI runs them with tsx, overriding the output via
10
+ * environment variables (see Demo.render).
11
+ */
12
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * reelscript CLI
4
+ *
5
+ * reelscript render <script.ts> [--out demo.mp4]
6
+ * reelscript preview <script.ts> --at 2.5 [--out frame.png]
7
+ *
8
+ * Scripts are ordinary TS/JS modules that build a Demo and call
9
+ * `demo.render(...)`. The CLI runs them with tsx, overriding the output via
10
+ * environment variables (see Demo.render).
11
+ */
12
+ import { resolve } from "node:path";
13
+ import { pathToFileURL } from "node:url";
14
+ import { createRequire, register } from "node:module";
15
+ // Let scripts import "@reelscript/cli" without a local install (see resolve-self.ts).
16
+ register(new URL("./resolve-self.js", import.meta.url));
17
+ const require = createRequire(import.meta.url);
18
+ const version = require("../package.json").version;
19
+ function usage() {
20
+ console.log(`reelscript ${version} — product demos as code
21
+
22
+ usage:
23
+ reelscript render <script> [--out demo.mp4]
24
+ reelscript preview <script> --at <seconds> [--out frame.png]
25
+ reelscript record <script> run terminal commands for real and save recordings
26
+ reelscript warmup download the narration model into the cache
27
+
28
+ env:
29
+ REELSCRIPT_FFMPEG path to ffmpeg (defaults to bundled ffmpeg-static)`);
30
+ process.exit(1);
31
+ }
32
+ function parse(argv) {
33
+ const [command, ...rest] = argv;
34
+ const flags = {};
35
+ const positional = [];
36
+ for (let i = 0; i < rest.length; i++) {
37
+ const a = rest[i];
38
+ if (a.startsWith("--")) {
39
+ const [k, v] = a.slice(2).split("=", 2);
40
+ flags[k] = v ?? rest[++i] ?? "";
41
+ }
42
+ else
43
+ positional.push(a);
44
+ }
45
+ return { command, flags, positional };
46
+ }
47
+ async function runScript(path) {
48
+ const script = resolve(path);
49
+ process.env.REELSCRIPT_SCRIPT = script;
50
+ const { tsImport } = await import("tsx/esm/api");
51
+ try {
52
+ await tsImport(pathToFileURL(script).href, import.meta.url);
53
+ }
54
+ catch (err) {
55
+ // A .ts/.js script in a project without "type": "module" is compiled as
56
+ // CommonJS, which forbids top-level await. Re-run it as an ES module via
57
+ // a temporary .mts copy beside the original so relative paths still work.
58
+ if (!(err instanceof Error) || !/Top-level await/.test(err.message))
59
+ throw err;
60
+ const { copyFileSync, unlinkSync } = await import("node:fs");
61
+ const { dirname, basename, join } = await import("node:path");
62
+ const tmp = join(dirname(script), `.${basename(script).replace(/\.[cm]?[jt]sx?$/, "")}.reelscript.mts`);
63
+ copyFileSync(script, tmp);
64
+ try {
65
+ await tsImport(pathToFileURL(tmp).href, import.meta.url);
66
+ }
67
+ finally {
68
+ unlinkSync(tmp);
69
+ }
70
+ }
71
+ }
72
+ async function main() {
73
+ const { command, flags, positional } = parse(process.argv.slice(2));
74
+ switch (command) {
75
+ case "render": {
76
+ const script = positional[0] ?? usage();
77
+ if (flags.out)
78
+ process.env.REELSCRIPT_OUT = resolve(flags.out);
79
+ await runScript(script);
80
+ break;
81
+ }
82
+ case "preview": {
83
+ const script = positional[0] ?? usage();
84
+ const at = Number(flags.at ?? "0");
85
+ process.env.REELSCRIPT_SNAPSHOT_AT = String(Math.round(at * 1000));
86
+ process.env.REELSCRIPT_OUT = resolve(flags.out ?? `preview-${at}s.png`);
87
+ await runScript(script);
88
+ break;
89
+ }
90
+ case "record": {
91
+ const script = positional[0] ?? usage();
92
+ process.env.REELSCRIPT_RECORD = "1";
93
+ await runScript(script);
94
+ break;
95
+ }
96
+ case "warmup": {
97
+ const { kokoro } = await import("./tts.js");
98
+ const t = Date.now();
99
+ await kokoro().synthesize("Ready.", {});
100
+ console.log(`narration model ready (${((Date.now() - t) / 1000).toFixed(1)}s)`);
101
+ break;
102
+ }
103
+ case "--version":
104
+ case "-v":
105
+ console.log(version);
106
+ break;
107
+ default:
108
+ usage();
109
+ }
110
+ }
111
+ main().catch((err) => {
112
+ console.error(err instanceof Error ? err.message : err);
113
+ process.exit(1);
114
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Page clock shim, injected before any page script runs.
3
+ *
4
+ * Replaces the page's notion of time (timers, requestAnimationFrame, Date,
5
+ * performance.now) with a virtual clock that only moves when the renderer
6
+ * calls `window.__reelscript_advance(ms)`, and steps CSS transitions /
7
+ * animations by the same amount through the Web Animations API. Chromium's
8
+ * own compositor keeps running on real time, so screenshots and input
9
+ * dispatch never stall — only the *content's* clock is deterministic.
10
+ */
11
+ export declare const CLOCK_SHIM: string;
package/dist/clock.js ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Page clock shim, injected before any page script runs.
3
+ *
4
+ * Replaces the page's notion of time (timers, requestAnimationFrame, Date,
5
+ * performance.now) with a virtual clock that only moves when the renderer
6
+ * calls `window.__reelscript_advance(ms)`, and steps CSS transitions /
7
+ * animations by the same amount through the Web Animations API. Chromium's
8
+ * own compositor keeps running on real time, so screenshots and input
9
+ * dispatch never stall — only the *content's* clock is deterministic.
10
+ */
11
+ export const CLOCK_SHIM = String.raw `
12
+ (() => {
13
+ if (window.__reelscript_advance) return;
14
+ let now = 0;
15
+ let nextId = 1;
16
+ const timers = new Map();
17
+ const rafs = new Map();
18
+ const tracked = new WeakMap(); // Animation -> virtual currentTime
19
+ const epoch = Date.now();
20
+ const RealDate = Date;
21
+
22
+ const g = window;
23
+ g.setTimeout = (fn, delay = 0, ...args) => {
24
+ const id = nextId++;
25
+ timers.set(id, { at: now + Math.max(0, Number(delay) || 0), fn, args, every: 0 });
26
+ return id;
27
+ };
28
+ g.setInterval = (fn, delay = 0, ...args) => {
29
+ const id = nextId++;
30
+ const every = Math.max(1, Number(delay) || 0);
31
+ timers.set(id, { at: now + every, fn, args, every });
32
+ return id;
33
+ };
34
+ g.clearTimeout = g.clearInterval = (id) => { timers.delete(id); };
35
+ g.requestAnimationFrame = (fn) => { const id = nextId++; rafs.set(id, fn); return id; };
36
+ g.cancelAnimationFrame = (id) => { rafs.delete(id); };
37
+ g.requestIdleCallback = (fn) => g.setTimeout(() => fn({ didTimeout: false, timeRemaining: () => 8 }), 1);
38
+ g.cancelIdleCallback = g.clearTimeout;
39
+ Performance.prototype.now = () => now;
40
+ class VDate extends RealDate {
41
+ constructor(...a) { a.length === 0 ? super(epoch + now) : super(...a); }
42
+ static now() { return epoch + now; }
43
+ }
44
+ g.Date = VDate;
45
+
46
+ const call = (fn, args) => { try { typeof fn === "function" ? fn(...args) : new Function(String(fn))(); } catch (e) { console.error(e); } };
47
+
48
+ g.__reelscript_advance = (ms) => {
49
+ const target = now + ms;
50
+ // Fire timers in chronological order, including ones scheduled while firing.
51
+ for (let guard = 0; guard < 10000; guard++) {
52
+ let pick = null;
53
+ for (const [id, t] of timers) if (t.at <= target && (!pick || t.at < pick[1].at)) pick = [id, t];
54
+ if (!pick) break;
55
+ const [id, t] = pick;
56
+ now = t.at;
57
+ if (t.every) t.at += t.every; else timers.delete(id);
58
+ call(t.fn, t.args);
59
+ }
60
+ now = target;
61
+ // One animation frame per rendered frame.
62
+ const cbs = Array.from(rafs.values());
63
+ rafs.clear();
64
+ for (const cb of cbs) call(cb, [now]);
65
+ // Step every running CSS transition / animation by exactly ms.
66
+ for (const a of document.getAnimations()) {
67
+ let ct = tracked.get(a);
68
+ if (ct === undefined) {
69
+ // New since last frame: restart it on this frame boundary.
70
+ a.pause();
71
+ ct = 0;
72
+ } else {
73
+ ct += ms;
74
+ }
75
+ const timing = a.effect && a.effect.getComputedTiming();
76
+ const end = timing ? timing.endTime : Infinity;
77
+ if (ct >= end) {
78
+ tracked.delete(a);
79
+ a.playbackRate = 1;
80
+ a.finish();
81
+ } else {
82
+ a.currentTime = ct;
83
+ tracked.set(a, ct);
84
+ }
85
+ }
86
+ };
87
+ })();
88
+ `;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Cursor + click-feedback sprites, rasterized from SVG and cached by size.
3
+ * Coordinates: the sprite's hotspot (arrow tip) is at (hx, hy).
4
+ */
5
+ export interface Sprite {
6
+ data: Buffer;
7
+ width: number;
8
+ height: number;
9
+ hx: number;
10
+ hy: number;
11
+ }
12
+ export declare function cursorSprite(heightPx: number): Promise<Sprite>;
13
+ /** Translucent ring that expands from the click point. */
14
+ export declare function rippleSprite(radius: number, opacity: number): Promise<Sprite>;