cuetake 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/package.json +2 -2
- package/src/auth.js +8 -1
- package/src/cli.js +17 -5
- package/src/cursor.js +59 -3
- package/src/director.js +80 -25
- package/src/edit.js +21 -4
- package/src/environment.js +23 -7
- package/src/look.js +18 -4
- package/src/motion.js +66 -0
- package/src/narration.js +146 -0
- package/src/pipeline.js +166 -15
- package/src/probe.js +78 -20
- package/src/render-page.js +206 -48
- package/src/render.js +48 -12
- package/src/shortcuts.js +73 -0
- package/src/styles/arrow.js +130 -10
- package/src/styles/dot.js +2 -1
- package/src/styles/keycaps.js +38 -0
- package/src/styles/subtitles.js +17 -0
- package/src/styles.js +6 -3
- package/src/uninstall.js +62 -0
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ Built entirely for AI agents, CueTake turns browser interactions into sharp prod
|
|
|
11
11
|
- Retina tab capture at 30 or 60 fps and a 2× pixel scale, headless by default.
|
|
12
12
|
- An automatic camera in the style of Screen Studio: it arrives just before each click, field and drag, follows the cursor on a spring, and ends on the wide shot.
|
|
13
13
|
- The page framed in a browser or macOS window over fluted glass lit in the product's brand color, at any output size; backgrounds, chrome, cursors and click effects are shaders or drawing code the agent can write.
|
|
14
|
-
- Cursor
|
|
14
|
+
- A Cursor drawn at Render time in the shape the page asks for, pressing on each click, so a Take can be restyled without recording again.
|
|
15
|
+
- Keyboard shortcuts shown as keycaps, so a demo of a command palette or an editor teaches the keys it presses.
|
|
15
16
|
- Styling chosen in conversation: the agent shows Previews of candidate Looks side by side in about a second, and the Look you pick is saved for later Takes.
|
|
16
17
|
- Rendering in Chromium with WebGL and WebCodecs: no FFmpeg, 4K60 by default.
|
|
17
18
|
- A separate folder for every Take: Source, Timeline, Edit, Final MP4, and verification.
|
|
@@ -47,6 +48,7 @@ Playwright is a local package dependency. Browser binaries use Playwright's norm
|
|
|
47
48
|
```sh
|
|
48
49
|
bun src/cli.js doctor
|
|
49
50
|
bun src/cli.js install-browser
|
|
51
|
+
bun src/cli.js uninstall --dry-run
|
|
50
52
|
bun src/cli.js record ./my-scenario.mjs --out ./recordings/my-take [--headed]
|
|
51
53
|
bun src/cli.js render ./recordings/my-take
|
|
52
54
|
bun src/cli.js verify ./recordings/my-take
|
|
@@ -60,13 +62,13 @@ A successful command is a technical check, not an editorial approval. Watch the
|
|
|
60
62
|
|
|
61
63
|
## How it works
|
|
62
64
|
|
|
63
|
-
Playwright drives an isolated Chromium tab. Chromium captures the tab at device-pixel resolution using `getDisplayMedia`; a VP9 `MediaRecorder` saves the source. An in-page probe records the pointer path, clicks, drags and
|
|
65
|
+
Playwright drives an isolated Chromium tab. Chromium captures the tab at device-pixel resolution using `getDisplayMedia`; a VP9 `MediaRecorder` saves the source. An in-page probe records the pointer path, clicks, drags, typing and shortcuts into the Timeline. Render then composes the camera path in a headless Chromium page with WebGL and encodes H.264 with WebCodecs; see [ADR 0001](docs/adr/0001-render-in-browser-with-webgl-and-webcodecs.md).
|
|
64
66
|
|
|
65
67
|
Source capture is variable frame rate. Static scenes may drop to approximately one captured frame per second, and busy scenes can drop frames. A 60 fps output does not imply 60 unique source frames every second. Capture callback statistics and output metadata are retained in each take. No motion interpolation is used.
|
|
66
68
|
|
|
67
69
|
## Current scope
|
|
68
70
|
|
|
69
|
-
The supported workflow is a short, same-document browser demo, including SPA interactions. A full page navigation or reload destroys the in-page recorder; record those as separate takes.
|
|
71
|
+
The supported workflow is a short, same-document browser demo, including SPA interactions. A full page navigation or reload destroys the in-page recorder; record those as separate takes. Page audio and desktop/window capture are outside this workflow; a Narration voiced by a separate speech tool is mixed in at Render, with Subtitles ([narration](skills/cuetake/narration.md)). Input inside cross-origin iframes is not seen by the Timeline probe, so the cursor and camera do not follow it there. Headless Chromium renders the generic `monospace` family as Courier rather than Menlo; record with `--headed` when a page relies on it. Browser automation and captured data stay local; the visited website still receives normal browser requests.
|
|
70
72
|
|
|
71
73
|
The bundled [agent skill](skills/cuetake/SKILL.md) teaches planning and operation; site-specific scenarios stay in your application project. See [distribution](docs/distribution.md) and [login](skills/cuetake/authentication.md).
|
|
72
74
|
|
|
@@ -78,4 +80,4 @@ bun test tests/pipeline.test.js
|
|
|
78
80
|
bun test tests/browser.test.js
|
|
79
81
|
```
|
|
80
82
|
|
|
81
|
-
`pipeline.test.js` covers configuration and camera math; `browser.test.js` covers the probe, Auth profiles, and Render geometry,
|
|
83
|
+
`pipeline.test.js` covers configuration and camera math; `browser.test.js` covers the probe, Auth profiles, and Render geometry, the Cursor's shape, press and fade, and sparks at a 2× capture scale. No build step is required. Do not commit recordings, browser profiles, credentials, or product-specific scenarios into this generic tool repository.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cuetake",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Local recording runtime for AI agents: plan a browser demo, capture it, and render a finished take.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=20.10.0"
|
|
41
41
|
},
|
|
42
|
-
"packageManager": "bun@1.
|
|
42
|
+
"packageManager": "bun@1.4.4"
|
|
43
43
|
}
|
package/src/auth.js
CHANGED
|
@@ -5,8 +5,9 @@ import { join } from 'node:path';
|
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
6
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
7
7
|
const root = () => process.env.CUETAKE_AUTH_DIR || join(homedir(), '.local/share/cuetake/auth');
|
|
8
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
8
9
|
function profilePath(profile) {
|
|
9
|
-
if (
|
|
10
|
+
if (!NAME.test(profile)) throw new Error('Use a short lowercase profile name, such as product-demo');
|
|
10
11
|
return join(root(), `${profile}.json`);
|
|
11
12
|
}
|
|
12
13
|
export async function resolveAuthProfile(profile) {
|
|
@@ -14,6 +15,12 @@ export async function resolveAuthProfile(profile) {
|
|
|
14
15
|
await fs.access(path).catch(() => { throw new Error(`Auth profile '${profile}' is missing. Run: cuetake login ${profile} <login-url>`); });
|
|
15
16
|
return path;
|
|
16
17
|
}
|
|
18
|
+
/** The saved Auth profile files, with any left over from an interrupted save; other files in the folder are not CueTake's. */
|
|
19
|
+
export async function authProfileFiles() {
|
|
20
|
+
const dir = root(), names = await fs.readdir(dir).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
21
|
+
const paths = names.filter(name => { const [profile, ext, ...rest] = name.split('.'); return NAME.test(profile) && ext === 'json' && (rest.length === 0 || (rest.length === 2 && rest[1] === 'tmp')); });
|
|
22
|
+
return { dir, paths: paths.sort().map(name => join(dir, name)) };
|
|
23
|
+
}
|
|
17
24
|
/** Accepts a browser context or an already-read storage state. */
|
|
18
25
|
export async function saveAuthState(source, profile) {
|
|
19
26
|
const path = profilePath(profile);
|
package/src/cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import pkg from '../package.json' with { type: 'json' };
|
|
4
|
-
import { recordScenario, renderTake, verifyTake, previewTake, applyLookToTake, saveLookFromTake } from './pipeline.js';
|
|
4
|
+
import { recordScenario, renderTake, verifyTake, previewTake, applyLookToTake, saveLookFromTake, importNarration } from './pipeline.js';
|
|
5
5
|
import { listLooks, removeLook } from './look.js';
|
|
6
6
|
import { BUILTINS, BUILTIN_DIR } from './styles.js';
|
|
7
7
|
import { doctor, installBrowser } from './environment.js';
|
|
8
|
+
import { uninstall } from './uninstall.js';
|
|
8
9
|
import { login } from './auth.js';
|
|
9
10
|
import { extractFrame } from './render.js';
|
|
10
11
|
import { writeFile } from 'node:fs/promises';
|
|
@@ -14,7 +15,9 @@ const help = `CueTake ${pkg.version} — browser demos directed by code
|
|
|
14
15
|
|
|
15
16
|
cuetake doctor
|
|
16
17
|
cuetake install-browser
|
|
17
|
-
cuetake
|
|
18
|
+
cuetake uninstall [--auth] [--looks] [--dry-run]
|
|
19
|
+
cuetake record <scenario.mjs> [--out <new-directory>] [--auth-profile <name>] [--look <name|file.json>] [--narration <narration.json>] [--headed]
|
|
20
|
+
cuetake narrate import <take-directory> <narration.json>
|
|
18
21
|
cuetake preview <take-directory> [--look <name|file.json>]... [--at <seconds>]
|
|
19
22
|
cuetake render <take-directory>
|
|
20
23
|
cuetake verify <take-directory>
|
|
@@ -27,9 +30,15 @@ const help = `CueTake ${pkg.version} — browser demos directed by code
|
|
|
27
30
|
cuetake styles
|
|
28
31
|
|
|
29
32
|
install-browser downloads the Chromium build this CueTake version drives (about 150 MB).
|
|
33
|
+
uninstall removes CueTake's npx cache and its browser, unless another Playwright installation uses it.
|
|
34
|
+
It keeps Auth profiles unless --auth and global Looks unless --looks; Take folders and local Looks
|
|
35
|
+
are never touched. --dry-run lists what would go and removes nothing.
|
|
30
36
|
record captures, renders and verifies a new take; an existing directory is never overwritten.
|
|
31
37
|
Capture runs headless; --headed shows the browser window while recording.
|
|
32
38
|
--look seeds the first Edit from a Look; fields the Scenario config names win.
|
|
39
|
+
--narration copies a Narration and its audio into the Take first: d.say(id) holds each Line for its audio.
|
|
40
|
+
narrate import copies a Narration and its audio into a recorded Take, replacing its earlier one. Lines keep
|
|
41
|
+
their start in edit.json; a new Line takes the start the file gives it. Render plays and subtitles them.
|
|
33
42
|
preview writes preview.png in the take: the current Edit beside each Look, at --at seconds
|
|
34
43
|
or at the end with the camera wide. It never changes edit.json or final.mp4.
|
|
35
44
|
render reuses source.webm, timeline.json and edit.json, replacing final.mp4 only on success.
|
|
@@ -40,16 +49,19 @@ A Look is a take's reusable styling, with the files it draws with. Looks are sav
|
|
|
40
49
|
name. list names the code each Look runs. apply rewrites edit.json and copies files into styles/.
|
|
41
50
|
styles lists the built-in shaders and drawing code, with their files and starting parameters.
|
|
42
51
|
Styling is agent-written code and is not validated; the render page has no network.
|
|
43
|
-
Scenario files are trusted JavaScript. Recording runs locally
|
|
52
|
+
Scenario files are trusted JavaScript. Recording runs locally and captures no page audio; Narration is
|
|
53
|
+
voiced beforehand by a speech tool of your choice.
|
|
44
54
|
`;
|
|
45
55
|
try {
|
|
46
|
-
const { values, positionals } = parseArgs({ args: process.argv.slice(2), allowPositionals: true, options: { out: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'auth-profile': { type: 'string' }, headed: { type: 'boolean' }, look: { type: 'string', multiple: true }, at: { type: 'string' }, global: { type: 'boolean' }, replace: { type: 'boolean' } } });
|
|
56
|
+
const { values, positionals } = parseArgs({ args: process.argv.slice(2), allowPositionals: true, options: { out: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'auth-profile': { type: 'string' }, headed: { type: 'boolean' }, look: { type: 'string', multiple: true }, narration: { type: 'string' }, at: { type: 'string' }, global: { type: 'boolean' }, replace: { type: 'boolean' }, auth: { type: 'boolean' }, looks: { type: 'boolean' }, 'dry-run': { type: 'boolean' } } });
|
|
47
57
|
const [command, target] = positionals, looks = values.look ?? [];
|
|
48
58
|
const print = data => console.log(JSON.stringify(data, null, 2));
|
|
49
59
|
if (values.help || !command) console.log(help);
|
|
50
60
|
else if (command === 'doctor') { const result = await doctor(); console.log(JSON.stringify(result, null, 2)); if (!result.ok) process.exitCode = 1; }
|
|
51
61
|
else if (command === 'install-browser') console.log(JSON.stringify(await installBrowser(), null, 2));
|
|
52
|
-
else if (command === '
|
|
62
|
+
else if (command === 'uninstall' && !target) print(await uninstall({ auth: values.auth, looks: values.looks, dryRun: values['dry-run'] }));
|
|
63
|
+
else if (command === 'record' && target && looks.length <= 1) print(await recordScenario(target, values.out, { authProfile: values['auth-profile'], look: looks[0], narration: values.narration, headed: values.headed }));
|
|
64
|
+
else if (command === 'narrate' && target === 'import' && positionals[3]) print(await importNarration(positionals[2], positionals[3]));
|
|
53
65
|
else if (command === 'preview' && target) print(await previewTake(target, looks, { at: values.at === undefined ? undefined : Number(values.at) }));
|
|
54
66
|
else if (command === 'render' && target) { await renderTake(target); console.log(JSON.stringify(await verifyTake(target), null, 2)); }
|
|
55
67
|
else if (command === 'verify' && target) console.log(JSON.stringify(await verifyTake(target), null, 2));
|
package/src/cursor.js
CHANGED
|
@@ -3,11 +3,19 @@
|
|
|
3
3
|
* Pure functions shared by Node and the render page; CSS pixels and seconds throughout.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const PRESS_IN = 0.08, PRESS_OUT = 0.3; // seconds to shrink when a button goes down and to spring back after it is released
|
|
7
|
+
|
|
8
|
+
/** The index of the last entry of `list` (sorted by `time(entry)`) at or before `t`, or -1. */
|
|
9
|
+
function lastAt(list, t, time) {
|
|
10
|
+
let low = 0, high = list.length - 1, found = -1;
|
|
11
|
+
while (low <= high) { const mid = (low + high) >> 1; if (time(list[mid]) <= t) { found = mid; low = mid + 1; } else high = mid - 1; }
|
|
12
|
+
return found;
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
/** The pointer position at `t`, interpolated between samples; null before the first sample. */
|
|
7
16
|
export function pointerAt(pointer, t) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
while (low < high) { const mid = (low + high + 1) >> 1; if (pointer[mid][0] <= t) low = mid; else high = mid - 1; }
|
|
17
|
+
const low = lastAt(pointer, t, sample => sample[0]);
|
|
18
|
+
if (low < 0) return null;
|
|
11
19
|
const [t0, x0, y0] = pointer[low], next = pointer[low + 1];
|
|
12
20
|
if (!next || next[0] === t0) return { x: x0, y: y0 };
|
|
13
21
|
const k = (t - t0) / (next[0] - t0);
|
|
@@ -26,3 +34,51 @@ export function sparksAt(pressList, clickEffect, t) {
|
|
|
26
34
|
const life = (clickEffect.duration ?? 400) / 1000;
|
|
27
35
|
return pressList.filter(p => t >= p.t && t < p.t + life).map(p => ({ x: p.x, y: p.y, progress: (t - p.t) / life }));
|
|
28
36
|
}
|
|
37
|
+
|
|
38
|
+
/** When a button is held: each click and drag from press to release. */
|
|
39
|
+
export const heldSpans = events => events.filter(event => event.type === 'click' || event.type === 'drag').map(event => ({ t: event.t, end: event.end ?? event.t }));
|
|
40
|
+
|
|
41
|
+
const easeOut = u => 1 - (1 - u) ** 3;
|
|
42
|
+
const springBack = u => { const c = 1.70158; return 1 + (c + 1) * (u - 1) ** 3 + c * (u - 1) ** 2; };
|
|
43
|
+
|
|
44
|
+
/** The Cursor's scale at `t`: down to `press` while a button is held, springing back after; `press: false` keeps 1. */
|
|
45
|
+
export function pressScale(spans, press, t) {
|
|
46
|
+
if (typeof press !== 'number') return 1;
|
|
47
|
+
const span = spans[lastAt(spans, t, s => s.t)];
|
|
48
|
+
if (!span) return 1;
|
|
49
|
+
const down = held => 1 - (1 - press) * easeOut(Math.min(1, held / PRESS_IN));
|
|
50
|
+
if (t <= span.end) return down(t - span.t);
|
|
51
|
+
const u = (t - span.end) / PRESS_OUT, from = down(span.end - span.t);
|
|
52
|
+
return u >= 1 ? 1 : from + (1 - from) * springBack(u);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The cursor shape the page asked for at `t`, as a CSS keyword; `default` before the first. */
|
|
56
|
+
export function shapeAt(shapes, t) {
|
|
57
|
+
return shapes[lastAt(shapes, t, entry => entry[0])]?.[1] ?? 'default';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Keywords that name the same picture as one a cursor is more likely to draw.
|
|
61
|
+
const ALIASES = {
|
|
62
|
+
progress: 'wait', 'all-scroll': 'move', 'no-drop': 'not-allowed',
|
|
63
|
+
'col-resize': 'ew-resize', 'e-resize': 'ew-resize', 'w-resize': 'ew-resize',
|
|
64
|
+
'row-resize': 'ns-resize', 'n-resize': 'ns-resize', 's-resize': 'ns-resize',
|
|
65
|
+
'ne-resize': 'nesw-resize', 'sw-resize': 'nesw-resize', 'nw-resize': 'nwse-resize', 'se-resize': 'nwse-resize',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** The shape a cursor drawing `drawn` (a Set of names) shows for `keyword`: itself, its alias, or `default`. */
|
|
69
|
+
export const drawnShape = (keyword, drawn) => drawn.has(keyword) ? keyword : drawn.has(ALIASES[keyword]) ? ALIASES[keyword] : 'default';
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The Cursor through a Take: `at(t)` gives its point, scale and the shape the page asked for,
|
|
73
|
+
* or null before the first pointer sample. `cursor` is the Edit's cursor item.
|
|
74
|
+
*/
|
|
75
|
+
export function cursorTrack({ pointer, shapes = [], events }, cursor) {
|
|
76
|
+
const spans = heldSpans(events);
|
|
77
|
+
return {
|
|
78
|
+
at(t) {
|
|
79
|
+
const point = pointerAt(pointer, t);
|
|
80
|
+
if (!point) return null;
|
|
81
|
+
return { ...point, scale: pressScale(spans, cursor.press, t), shape: shapeAt(shapes, t) };
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
package/src/director.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { landing, pauseMs, random, reach, typingDelays } from './motion.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Timed, viewport-aligned interactions shared by all scenarios, moving like a person (see motion.js).
|
|
5
|
+
* `said` collects where each Line starts; `voiced` maps the Narration's Line ids to their audio's
|
|
6
|
+
* seconds, or is null without one. `speed` scales every move, pause and typing delay it chooses;
|
|
7
|
+
* `seed` picks one of many equally human ways to move.
|
|
8
|
+
*/
|
|
9
|
+
export function createDirector(page, startedAt, fps, focusTargets, wideWindows, said = [], voiced = null, { speed = 1, seed = 1 } = {}) {
|
|
3
10
|
let cursor = { x: 0, y: 0 };
|
|
11
|
+
const rand = random(seed);
|
|
4
12
|
const wait = ms => page.waitForTimeout(Math.max(0, ms));
|
|
5
13
|
const time = () => (Date.now() - startedAt) / 1000;
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
const pause = name => wait(pauseMs(name, speed, rand));
|
|
15
|
+
async function glide(to, { size, duration, drag } = {}) {
|
|
16
|
+
const path = reach(cursor, to, { size, duration, speed, drag, rand });
|
|
17
|
+
// Progress follows the clock, so a page slow to take each move cannot stretch the move.
|
|
8
18
|
const start = Date.now();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
await page.mouse.move(
|
|
14
|
-
await wait(start + i * duration / frames - Date.now());
|
|
19
|
+
for (let i = 1, t = 0; t < 1; i++) {
|
|
20
|
+
await wait(start + i * 1000 / fps - Date.now());
|
|
21
|
+
t = path.duration ? Math.min(1, (Date.now() - start) / path.duration) : 1;
|
|
22
|
+
const { x, y } = path.at(t);
|
|
23
|
+
await page.mouse.move(x, y);
|
|
15
24
|
}
|
|
16
|
-
cursor = {
|
|
25
|
+
cursor = { ...to };
|
|
17
26
|
}
|
|
18
|
-
|
|
27
|
+
const move = (x, y, duration) => glide({ x, y }, { duration });
|
|
28
|
+
// Clicks, typing, drags and cursor shapes are recorded by the in-page probe; only deliberate camera choices live here.
|
|
19
29
|
const focus = (box, t = time()) => focusTargets.push({ t, box });
|
|
20
30
|
/** Options may be a bare number for the action's main timing; `focus: false` keeps the camera wide. */
|
|
21
31
|
const options = (value, key) => typeof value === 'number' ? { [key]: value } : value ?? {};
|
|
@@ -24,31 +34,76 @@ export function createDirector(page, startedAt, fps, focusTargets, wideWindows)
|
|
|
24
34
|
try { return await action(); }
|
|
25
35
|
finally { if (follow === false) wideWindows.push({ start, end: time() }); }
|
|
26
36
|
}
|
|
37
|
+
/** Moves onto a target, landing a little off its center; returns the target and where it landed inside its box. */
|
|
38
|
+
async function approach(locator, duration, action) {
|
|
39
|
+
const target = typeof locator === 'string' ? page.locator(locator) : locator;
|
|
40
|
+
const box = await target.boundingBox();
|
|
41
|
+
if (!box) throw new Error(`${action} target has no visible bounding box`);
|
|
42
|
+
const point = landing(box, rand);
|
|
43
|
+
await glide(point, { size: Math.min(box.width, box.height), duration });
|
|
44
|
+
return { target, position: { x: point.x - box.x, y: point.y - box.y } };
|
|
45
|
+
}
|
|
46
|
+
/** `button: 'right'` opens the page's context menu instead. */
|
|
27
47
|
function click(locator, opts) {
|
|
28
|
-
const { duration =
|
|
48
|
+
const { duration, button = 'left', ...rest } = options(opts, 'duration');
|
|
29
49
|
return act(rest, async () => {
|
|
30
|
-
const target =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await
|
|
34
|
-
await
|
|
50
|
+
const { target, position } = await approach(locator, duration, 'Click');
|
|
51
|
+
await pause('beforePress');
|
|
52
|
+
// A person holds the button for a moment, so the Cursor's press shows.
|
|
53
|
+
await target.click({ position, button, delay: pauseMs('press', speed, rand) });
|
|
54
|
+
await pause('afterRelease');
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Presses a key or combination, such as 'Meta+K', on whatever has focus; the Final shows it as keycaps. */
|
|
58
|
+
function press(keys, opts) {
|
|
59
|
+
return act(options(opts), async () => {
|
|
60
|
+
await pause('beforeKey');
|
|
61
|
+
await page.keyboard.press(keys, { delay: pauseMs('press', speed, rand) });
|
|
62
|
+
await pause('afterKey');
|
|
35
63
|
});
|
|
36
64
|
}
|
|
65
|
+
/** Rests the cursor on a target without pressing, so the page shows its hover state. */
|
|
66
|
+
async function hover(locator, opts) {
|
|
67
|
+
const { duration } = options(opts, 'duration');
|
|
68
|
+
await approach(locator, duration, 'Hover');
|
|
69
|
+
}
|
|
37
70
|
function type(locator, text, opts) {
|
|
38
|
-
const { msPerChar = 70, ...rest } = options(opts, 'msPerChar');
|
|
71
|
+
const { msPerChar = 70 / speed, ...rest } = options(opts, 'msPerChar');
|
|
39
72
|
return act(rest, async () => {
|
|
40
73
|
await click(locator, rest);
|
|
41
|
-
|
|
74
|
+
const chars = [...text], delays = typingDelays(text, msPerChar, rand);
|
|
75
|
+
for (let i = 0; i < chars.length; i++) {
|
|
76
|
+
if (i) await wait(delays[i - 1]);
|
|
77
|
+
await page.keyboard.type(chars[i]);
|
|
78
|
+
}
|
|
42
79
|
});
|
|
43
80
|
}
|
|
44
81
|
function drag(from, to, opts) {
|
|
45
|
-
const { duration
|
|
82
|
+
const { duration, ...rest } = options(opts, 'duration');
|
|
46
83
|
return act(rest, async () => {
|
|
47
|
-
await
|
|
84
|
+
await glide(from);
|
|
85
|
+
await pause('beforePress');
|
|
48
86
|
await page.mouse.down();
|
|
49
|
-
try {
|
|
50
|
-
|
|
87
|
+
try {
|
|
88
|
+
await pause('afterGrab');
|
|
89
|
+
await glide(to, { duration, drag: true });
|
|
90
|
+
await pause('beforeDrop');
|
|
91
|
+
} finally { await page.mouse.up(); }
|
|
92
|
+
await pause('afterRelease');
|
|
51
93
|
});
|
|
52
94
|
}
|
|
53
|
-
|
|
95
|
+
/** Starts a Line. With a Narration it holds for the Line's audio, so the picture follows the voice. */
|
|
96
|
+
async function say(id, text) {
|
|
97
|
+
const t = time(), earlier = said.find(line => line.id === id);
|
|
98
|
+
if (earlier) throw new Error(`Line '${id}' was already said at ${earlier.t.toFixed(2)} s`);
|
|
99
|
+
if (voiced) {
|
|
100
|
+
if (!voiced.has(id)) throw new Error(`The Narration has no Line '${id}'; its Lines are ${[...voiced.keys()].join(', ')}`);
|
|
101
|
+
said.push({ t, id });
|
|
102
|
+
await wait((t + voiced.get(id)) * 1000 - (Date.now() - startedAt));
|
|
103
|
+
} else {
|
|
104
|
+
if (typeof text !== 'string' || !text) throw new Error(`d.say('${id}') needs the Line's text when recording without --narration`);
|
|
105
|
+
said.push({ t, id, text });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { page, wait, time, at: seconds => wait(seconds * 1000 - (Date.now() - startedAt)), move, hover, click, press, type, drag, focus, say };
|
|
54
109
|
}
|
package/src/edit.js
CHANGED
|
@@ -13,8 +13,10 @@ export const evenSize = z.number().int().min(240).max(7680).refine(n => n % 2 ==
|
|
|
13
13
|
|
|
14
14
|
/** Times are seconds except clickEffect.duration, which is milliseconds; geometry is CSS pixels. */
|
|
15
15
|
export const DEFAULT_STYLE = {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// The Cursor shrinks to `press` while a button is held; `false` turns that off. A click shows on the
|
|
17
|
+
// Cursor, so no click effect is drawn unless named.
|
|
18
|
+
cursor: { draw: 'arrow', size: 24, color: '#ffffff', press: 0.8 },
|
|
19
|
+
clickEffect: false,
|
|
18
20
|
// quality is the H.264 quantizer (lower is sharper and larger).
|
|
19
21
|
output: { width: 3840, height: 2160, quality: 22 },
|
|
20
22
|
// padding is a fraction of the short side, one number or [top, right, bottom, left]; radius is in 1080p pixels.
|
|
@@ -23,6 +25,14 @@ export const DEFAULT_STYLE = {
|
|
|
23
25
|
// fits below `minZoom` stay wide. The camera arrives `lead` before an action, holds `hold` after the
|
|
24
26
|
// last one in a segment, settles in about `response`, and returns wide `endWide` before the end.
|
|
25
27
|
camera: { maxZoom: 2, minZoom: 1.2, padding: 48, lead: 0.6, hold: 1.5, chainGap: 2, response: 0.6, follow: true, endWide: 1.5 },
|
|
28
|
+
// Shortcuts show as keycaps over the Final, outside the camera, for `duration` seconds after each
|
|
29
|
+
// press; presses of the same keys meanwhile count up. A key pressed without Control, Alt, Shift or
|
|
30
|
+
// Meta shows only with `singleKeys`. `false` shows none.
|
|
31
|
+
keycaps: { draw: 'keycaps', duration: 1.5, singleKeys: false },
|
|
32
|
+
// Drawn over the Final, outside the camera, while a Line is spoken; `burn: false` keeps them to the
|
|
33
|
+
// subtitle files. Rows hold up to `maxChars` (about 16 in Chinese, 42 otherwise), `maxRows` to a cue,
|
|
34
|
+
// each shown at least `minDuration`.
|
|
35
|
+
subtitles: { draw: 'subtitles', burn: true },
|
|
26
36
|
};
|
|
27
37
|
|
|
28
38
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -40,7 +50,7 @@ export function merge(base, over) {
|
|
|
40
50
|
|
|
41
51
|
/** A complete Edit: the defaults under whatever `edit` names. */
|
|
42
52
|
export function withDefaults(edit) {
|
|
43
|
-
return merge({ schemaVersion: EDIT_VERSION, ...DEFAULT_STYLE, output: { ...DEFAULT_STYLE.output, fps: 60 }, camera: { ...DEFAULT_STYLE.camera, targets: [] } }, edit);
|
|
53
|
+
return merge({ schemaVersion: EDIT_VERSION, ...DEFAULT_STYLE, output: { ...DEFAULT_STYLE.output, fps: 60 }, camera: { ...DEFAULT_STYLE.camera, targets: [] }, shortcuts: [], narration: { volume: 1, lines: [] } }, edit);
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
/**
|
|
@@ -64,11 +74,18 @@ export function cameraTargets(timeline, focus, wide = [], camera = {}) {
|
|
|
64
74
|
return [...automatic, ...focus].sort((a, b) => a.t - b.t);
|
|
65
75
|
}
|
|
66
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The first Edit of a Take. Each Line starts where the Scenario said it (`d.say`); its text, audio and
|
|
79
|
+
* word timings stay in the Take's Narration, since they change only with new audio. The Shortcuts the
|
|
80
|
+
* Timeline recorded are the ones shown, so one can be relabeled or removed without recording again.
|
|
81
|
+
*/
|
|
67
82
|
export function createEdit(config, timeline, focus, wide = []) {
|
|
68
83
|
return withDefaults({
|
|
69
|
-
cursor: config.cursor, clickEffect: config.clickEffect, output: { ...config.output, fps: config.capture.fps },
|
|
84
|
+
cursor: config.cursor, clickEffect: config.clickEffect, keycaps: config.keycaps, subtitles: config.subtitles, output: { ...config.output, fps: config.capture.fps },
|
|
70
85
|
// The browser chrome shows the Scenario's host unless the config names something else.
|
|
71
86
|
frame: { url: new URL(config.url).host, ...config.frame },
|
|
72
87
|
camera: { ...config.camera, targets: cameraTargets(timeline, focus, wide, config.camera) },
|
|
88
|
+
shortcuts: timeline.events.filter(event => event.type === 'shortcut').map(({ t, keys }) => ({ t, keys })),
|
|
89
|
+
narration: { lines: timeline.events.filter(event => event.type === 'say').map(event => ({ id: event.id, start: event.t })) },
|
|
73
90
|
});
|
|
74
91
|
}
|
package/src/environment.js
CHANGED
|
@@ -21,16 +21,32 @@ export async function doctor() {
|
|
|
21
21
|
return { ok: checks.every(c => c.ok), checks };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
* Downloads the Chromium build that CueTake's own Playwright version drives. Running
|
|
26
|
-
* `npx playwright install` instead may resolve a newer Playwright and fetch a build CueTake never uses.
|
|
27
|
-
*/
|
|
28
|
-
export function installBrowser() {
|
|
24
|
+
function playwright(args) {
|
|
29
25
|
const cli = join(dirname(createRequire(import.meta.url).resolve('playwright/package.json')), 'cli.js');
|
|
30
26
|
return new Promise((resolve, reject) => {
|
|
31
27
|
// Progress goes to stderr so stdout stays the JSON result.
|
|
32
|
-
const child = spawn(process.execPath, [cli,
|
|
28
|
+
const child = spawn(process.execPath, [cli, ...args], { stdio: ['ignore', 2, 2] });
|
|
33
29
|
child.on('error', reject);
|
|
34
|
-
child.on('close', code => code === 0 ? resolve(
|
|
30
|
+
child.on('close', code => code === 0 ? resolve() : reject(new Error(`playwright ${args[0]} exited with ${code}`)));
|
|
35
31
|
});
|
|
36
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Downloads the Chromium build that CueTake's own Playwright version drives. Running
|
|
36
|
+
* `npx playwright install` instead may resolve a newer Playwright and fetch a build CueTake never uses.
|
|
37
|
+
*/
|
|
38
|
+
export async function installBrowser() {
|
|
39
|
+
await playwright(['install', 'chromium', '--no-shell']);
|
|
40
|
+
return { installed: true, path: chromium.executablePath() };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Unregisters CueTake's Playwright from the shared browser cache, which deletes each browser no other
|
|
45
|
+
* Playwright installation still uses. Browsers other tools need stay.
|
|
46
|
+
*/
|
|
47
|
+
export async function uninstallBrowser({ dryRun = false } = {}) {
|
|
48
|
+
const path = chromium.executablePath(), exists = () => fs.access(path).then(() => true, () => false);
|
|
49
|
+
const existed = await exists();
|
|
50
|
+
if (existed && !dryRun) await playwright(['uninstall']);
|
|
51
|
+
return { path, existed, removed: existed && !dryRun && !await exists() };
|
|
52
|
+
}
|
package/src/look.js
CHANGED
|
@@ -6,18 +6,19 @@ import { absolute, bundle, codeRefs, fileRefs } from './styles.js';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A Look is the part of an Edit that does not depend on one Take: everything except camera targets,
|
|
9
|
-
* the address bar's url and the
|
|
9
|
+
* the address bar's url, the frame rate, the Shortcuts and the Narration's Lines. A Look sets only what
|
|
10
|
+
* it names, and is not validated.
|
|
10
11
|
*/
|
|
11
12
|
export const mergeLook = merge;
|
|
12
13
|
|
|
13
14
|
/** The Look an Edit carries. */
|
|
14
15
|
export function lookFromEdit(edit) {
|
|
15
|
-
const { schemaVersion, output: { fps, ...output } = {}, frame, camera: { targets, ...camera } = {}, ...rest } = edit;
|
|
16
|
+
const { schemaVersion, narration, shortcuts, output: { fps, ...output } = {}, frame, camera: { targets, ...camera } = {}, ...rest } = edit;
|
|
16
17
|
const { url, ...styling } = frame ?? {};
|
|
17
18
|
return { ...rest, output, frame: styling, camera };
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
/** The Edit with a Look adopted. Camera targets
|
|
21
|
+
/** The Edit with a Look adopted. Camera targets, the frame rate, the Shortcuts and the Lines stay; the address bar keeps its url, else shows `host`. */
|
|
21
22
|
export function applyLook(edit, look, host) {
|
|
22
23
|
const next = merge(edit, look);
|
|
23
24
|
next.frame = { ...next.frame, url: edit.frame?.url ?? host };
|
|
@@ -37,8 +38,9 @@ const scopes = (cwd = process.cwd()) => ({
|
|
|
37
38
|
local: join(cwd, '.cuetake', 'looks'),
|
|
38
39
|
global: process.env.CUETAKE_LOOK_DIR || join(homedir(), '.local/share/cuetake/looks'),
|
|
39
40
|
});
|
|
41
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
40
42
|
function checkName(name) {
|
|
41
|
-
if (
|
|
43
|
+
if (!NAME.test(name)) throw new Error('Use a short lowercase Look name, such as brand');
|
|
42
44
|
}
|
|
43
45
|
const readIfPresent = path => fs.readFile(path, 'utf8').catch(error => { if (['ENOENT', 'ENOTDIR'].includes(error.code)) return null; throw error; });
|
|
44
46
|
const parse = (text, path) => { try { return JSON.parse(text); } catch (error) { throw new Error(`${path} is not JSON: ${error.message}`); } };
|
|
@@ -110,6 +112,18 @@ export async function saveLook(name, look, { global = false, replace = false, cw
|
|
|
110
112
|
return { name, scope, path, summary: summarize(saved), code: codeRefs(absolute(saved, dir)) };
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
/** The file or folder of every global Look; other files in the folder are not CueTake's. */
|
|
116
|
+
export async function globalLookFiles() {
|
|
117
|
+
const dir = scopes().global, paths = [];
|
|
118
|
+
const entries = await fs.readdir(dir, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
const path = join(dir, entry.name);
|
|
121
|
+
if (entry.isFile() && entry.name.endsWith('.json') && NAME.test(basename(entry.name, '.json'))) paths.push(path);
|
|
122
|
+
else if (entry.isDirectory() && NAME.test(entry.name) && await readIfPresent(join(path, 'look.json')) !== null) paths.push(path);
|
|
123
|
+
}
|
|
124
|
+
return { dir, paths: paths.sort() };
|
|
125
|
+
}
|
|
126
|
+
|
|
113
127
|
export async function removeLook(name, { global = false, cwd } = {}) {
|
|
114
128
|
checkName(name);
|
|
115
129
|
const scope = global ? 'global' : 'local', root = scopes(cwd)[scope];
|
package/src/motion.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the Director's hand moves: durations from Fitts's law, a quick start and a long settle, a
|
|
3
|
+
* slight arc, pauses around presses and Shortcuts, a held click or key and uneven typing. Pure and
|
|
4
|
+
* seeded, so a Scenario moves the same way on every recording. CSS pixels and milliseconds throughout.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const REACH_MS = 250, REACH_MS_PER_BIT = 150; // Fitts's law: REACH_MS + REACH_MS_PER_BIT * log2(distance / size + 1)
|
|
8
|
+
const MAX_AVERAGE_SPEED = 1100; // CSS px/s; with the ease's 1.8× peak, a move at speed 1 stays under about 2000 px/s
|
|
9
|
+
const DRAG_SLOWDOWN = 1.5; // a held button makes people slower
|
|
10
|
+
const POINT_SIZE = 24; // target size for moves to a bare point
|
|
11
|
+
const BEND = 0.1, MAX_BEND = 80; // the arc's sideways offset, as a share of the distance and in CSS px
|
|
12
|
+
const LANDING = 0.15, MAX_LANDING = 8; // a click lands at most this share of its box's size, and CSS px, from the center
|
|
13
|
+
const PAUSES = { beforePress: 120, press: 100, afterRelease: 150, afterGrab: 100, beforeDrop: 100, beforeKey: 150, afterKey: 250 }; // press: how long a click or key is held
|
|
14
|
+
const PAUSE_JITTER = 0.25, TYPING_JITTER = 0.4, WORD_BREAK = 1.5;
|
|
15
|
+
|
|
16
|
+
/** A deterministic source of numbers in [0, 1) (mulberry32). */
|
|
17
|
+
export function random(seed) {
|
|
18
|
+
let a = seed >>> 0;
|
|
19
|
+
return () => {
|
|
20
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
21
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
22
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
23
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** How long a person takes to move `distance` onto a target `size` across. */
|
|
28
|
+
export function reachMs(distance, size = POINT_SIZE, { speed = 1, drag = false } = {}) {
|
|
29
|
+
if (distance < 1) return 0;
|
|
30
|
+
const fitts = REACH_MS + REACH_MS_PER_BIT * Math.log2(distance / Math.max(1, size) + 1);
|
|
31
|
+
return Math.max(fitts, distance / MAX_AVERAGE_SPEED * 1000) * (drag ? DRAG_SLOWDOWN : 1) / speed;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Progress along a move at time share `t`: minimum-jerk, warped so it peaks early and settles long. */
|
|
35
|
+
const ease = t => { const u = t ** 0.75; return u * u * u * (10 - 15 * u + 6 * u * u); };
|
|
36
|
+
|
|
37
|
+
/** A move from `from` to `to`: its duration and its point at time share `t`, along a slight arc. */
|
|
38
|
+
export function reach(from, to, { size, duration, speed, drag, rand }) {
|
|
39
|
+
const dx = to.x - from.x, dy = to.y - from.y, distance = Math.hypot(dx, dy);
|
|
40
|
+
const bend = Math.min(distance * BEND, MAX_BEND) * (0.5 + rand() / 2) * (rand() < 0.5 ? -1 : 1);
|
|
41
|
+
const control = { x: from.x + dx / 2 - dy / (distance || 1) * bend, y: from.y + dy / 2 + dx / (distance || 1) * bend };
|
|
42
|
+
return {
|
|
43
|
+
duration: duration ?? reachMs(distance, size, { speed, drag }),
|
|
44
|
+
at(t) {
|
|
45
|
+
const k = ease(t), j = 1 - k;
|
|
46
|
+
return { x: j * j * from.x + 2 * j * k * control.x + k * k * to.x, y: j * j * from.y + 2 * j * k * control.y + k * k * to.y };
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Where a click lands: a little off the center of its box, never more than a few pixels. */
|
|
52
|
+
export function landing(box, rand) {
|
|
53
|
+
const off = size => (rand() * 2 - 1) * Math.min(LANDING * size, MAX_LANDING);
|
|
54
|
+
return { x: box.x + box.width / 2 + off(box.width), y: box.y + box.height / 2 + off(box.height) };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A named pause, a little uneven. */
|
|
58
|
+
export const pauseMs = (name, speed, rand) => PAUSES[name] * (1 + (rand() * 2 - 1) * PAUSE_JITTER) / speed;
|
|
59
|
+
|
|
60
|
+
/** The delay after each typed character: uneven, longer after a word, averaging `msPerChar`. */
|
|
61
|
+
export function typingDelays(text, msPerChar, rand) {
|
|
62
|
+
const chars = [...text];
|
|
63
|
+
const raw = chars.map(c => (1 + (rand() * 2 - 1) * TYPING_JITTER) * (/[\s.,;:!?,。;:!?]/.test(c) ? WORD_BREAK : 1));
|
|
64
|
+
const total = raw.reduce((sum, d) => sum + d, 0);
|
|
65
|
+
return raw.map(d => d / total * msPerChar * chars.length);
|
|
66
|
+
}
|