cuetake 0.3.0 → 0.5.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 +9 -7
- package/examples/tabs.mjs +88 -0
- package/helper/bin/cuetake-capture +0 -0
- package/package.json +6 -4
- package/src/app-capture.js +128 -0
- package/src/app-director.js +208 -0
- package/src/app-locators.js +223 -0
- package/src/auth.js +8 -1
- package/src/camera.js +80 -33
- package/src/cli.js +28 -7
- package/src/cursor.js +59 -3
- package/src/desktop.js +108 -0
- package/src/director.js +392 -32
- package/src/edit.js +87 -14
- package/src/environment.js +55 -7
- package/src/follow-tabs.js +64 -0
- package/src/frames.js +41 -0
- package/src/look.js +26 -8
- package/src/mac-keys.js +47 -0
- package/src/masks.js +140 -0
- package/src/motion.js +75 -0
- package/src/narration.js +146 -0
- package/src/pipeline.js +401 -46
- package/src/probe.js +338 -38
- package/src/recorder.js +45 -12
- package/src/render-page.js +702 -150
- package/src/render.js +70 -15
- package/src/shortcuts.js +73 -0
- package/src/shutter.js +42 -0
- package/src/styles/arrow.js +130 -10
- package/src/styles/browser.js +2 -1
- package/src/styles/dot.js +2 -1
- package/src/styles/fast-forward.js +22 -0
- package/src/styles/keycaps.js +38 -0
- package/src/styles/subtitles.js +17 -0
- package/src/styles.js +7 -3
- package/src/tab-capture.js +225 -77
- package/src/tabs.js +126 -0
- package/src/time-map.js +106 -0
- package/src/uninstall.js +62 -0
package/src/motion.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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, uneven typing and scrolls that
|
|
4
|
+
* flick quickly and settle long. Pure and
|
|
5
|
+
* seeded, so a Scenario moves the same way on every recording. CSS pixels and milliseconds throughout.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const REACH_MS = 250, REACH_MS_PER_BIT = 150; // Fitts's law: REACH_MS + REACH_MS_PER_BIT * log2(distance / size + 1)
|
|
9
|
+
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
|
|
10
|
+
const DRAG_SLOWDOWN = 1.5; // a held button makes people slower
|
|
11
|
+
const POINT_SIZE = 24; // target size for moves to a bare point
|
|
12
|
+
const BEND = 0.1, MAX_BEND = 80; // the arc's sideways offset, as a share of the distance and in CSS px
|
|
13
|
+
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
|
|
14
|
+
const SCROLL_MS = 300, SCROLL_MS_PER_BIT = 300, SCROLL_UNIT = 300; // a scroll takes SCROLL_MS + SCROLL_MS_PER_BIT * log2(distance / SCROLL_UNIT + 1)
|
|
15
|
+
const MAX_SCROLL_SPEED = 3000; // CSS px/s on average: a quick flick of a wheel or trackpad
|
|
16
|
+
const PAUSES = { beforePress: 120, press: 100, afterRelease: 150, afterGrab: 100, beforeDrop: 100, beforeKey: 150, afterKey: 250, afterScroll: 200 }; // press: how long a click or key is held
|
|
17
|
+
const PAUSE_JITTER = 0.25, TYPING_JITTER = 0.4, WORD_BREAK = 1.5;
|
|
18
|
+
|
|
19
|
+
/** A deterministic source of numbers in [0, 1) (mulberry32). */
|
|
20
|
+
export function random(seed) {
|
|
21
|
+
let a = seed >>> 0;
|
|
22
|
+
return () => {
|
|
23
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
24
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
25
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
26
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** How long a person takes to move `distance` onto a target `size` across. */
|
|
31
|
+
export function reachMs(distance, size = POINT_SIZE, { speed = 1, drag = false } = {}) {
|
|
32
|
+
if (distance < 1) return 0;
|
|
33
|
+
const fitts = REACH_MS + REACH_MS_PER_BIT * Math.log2(distance / Math.max(1, size) + 1);
|
|
34
|
+
return Math.max(fitts, distance / MAX_AVERAGE_SPEED * 1000) * (drag ? DRAG_SLOWDOWN : 1) / speed;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** How long a person takes to scroll `distance` CSS px: longer the farther, but a long scroll flicks fast. */
|
|
38
|
+
export function scrollMs(distance, { speed = 1 } = {}) {
|
|
39
|
+
if (distance < 1) return 0;
|
|
40
|
+
return Math.max(SCROLL_MS + SCROLL_MS_PER_BIT * Math.log2(distance / SCROLL_UNIT + 1), distance / MAX_SCROLL_SPEED * 1000) / speed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Progress along a move or scroll at time share `t`: minimum-jerk, warped so it peaks early and settles long. */
|
|
44
|
+
export const ease = t => { const u = t ** 0.75; return u * u * u * (10 - 15 * u + 6 * u * u); };
|
|
45
|
+
|
|
46
|
+
/** A move from `from` to `to`: its duration and its point at time share `t`, along a slight arc. */
|
|
47
|
+
export function reach(from, to, { size, duration, speed, drag, rand }) {
|
|
48
|
+
const dx = to.x - from.x, dy = to.y - from.y, distance = Math.hypot(dx, dy);
|
|
49
|
+
const bend = Math.min(distance * BEND, MAX_BEND) * (0.5 + rand() / 2) * (rand() < 0.5 ? -1 : 1);
|
|
50
|
+
const control = { x: from.x + dx / 2 - dy / (distance || 1) * bend, y: from.y + dy / 2 + dx / (distance || 1) * bend };
|
|
51
|
+
return {
|
|
52
|
+
duration: duration ?? reachMs(distance, size, { speed, drag }),
|
|
53
|
+
at(t) {
|
|
54
|
+
const k = ease(t), j = 1 - k;
|
|
55
|
+
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 };
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Where a click lands: a little off the center of its box, never more than a few pixels. */
|
|
61
|
+
export function landing(box, rand) {
|
|
62
|
+
const off = size => (rand() * 2 - 1) * Math.min(LANDING * size, MAX_LANDING);
|
|
63
|
+
return { x: box.x + box.width / 2 + off(box.width), y: box.y + box.height / 2 + off(box.height) };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A named pause, a little uneven. */
|
|
67
|
+
export const pauseMs = (name, speed, rand) => PAUSES[name] * (1 + (rand() * 2 - 1) * PAUSE_JITTER) / speed;
|
|
68
|
+
|
|
69
|
+
/** The delay after each typed character: uneven, longer after a word, averaging `msPerChar`. */
|
|
70
|
+
export function typingDelays(text, msPerChar, rand) {
|
|
71
|
+
const chars = [...text];
|
|
72
|
+
const raw = chars.map(c => (1 + (rand() * 2 - 1) * TYPING_JITTER) * (/[\s.,;:!?,。;:!?]/.test(c) ? WORD_BREAK : 1));
|
|
73
|
+
const total = raw.reduce((sum, d) => sum + d, 0);
|
|
74
|
+
return raw.map(d => d / total * msPerChar * chars.length);
|
|
75
|
+
}
|
package/src/narration.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narration timing and Subtitles, shared by Node and the render page. Pure functions, no imports.
|
|
3
|
+
*
|
|
4
|
+
* A placed Line is `{ id, text, start, duration, words? }`: `start` is seconds of Source time,
|
|
5
|
+
* `duration` is measured from its audio, and each word is `{ text, start, end }` in seconds from the
|
|
6
|
+
* start of the Line's audio. Subtitle cues are `{ id, start, end, rows }`, `id` naming their Line.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const CJK = /[⺀-鿿豈--]/u;
|
|
10
|
+
const SENTENCE_END = /[.!?。!?…]["'”’))]*$/u;
|
|
11
|
+
const CLAUSE_END = /[,;:,、;:—–]["'”’))]*$/u;
|
|
12
|
+
// Closing punctuation never starts a row; it joins what it follows.
|
|
13
|
+
const CLOSING = /^[.,;:!?)\]}'"”’。,、;:!?)》」』…]/u;
|
|
14
|
+
/** The characters that are spoken, which word timings count: no spaces or punctuation. */
|
|
15
|
+
const spoken = text => Array.from(text.replace(/[\s\p{P}\p{S}]/gu, '')).length;
|
|
16
|
+
const length = text => Array.from(text).length;
|
|
17
|
+
|
|
18
|
+
/** Whether `text` (or a language tag such as zh-CN) is written without spaces between words. */
|
|
19
|
+
export const isCjk = (text, language) => /^(zh|ja|ko)\b/i.test(language ?? '') || CJK.test(text);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The text broken into atoms that rows never split: a CJK character or a run of other non-space
|
|
23
|
+
* characters, with any closing punctuation after it. `space` marks a space before the atom.
|
|
24
|
+
*/
|
|
25
|
+
function atoms(text) {
|
|
26
|
+
const list = [];
|
|
27
|
+
for (const [piece] of text.trim().matchAll(/\s+|[⺀-鿿豈--]|[^\s⺀-鿿豈--]+/gu)) {
|
|
28
|
+
if (/^\s+$/u.test(piece)) { if (list.length) list.at(-1).spaceAfter = true; continue; }
|
|
29
|
+
const last = list.at(-1);
|
|
30
|
+
if (last && !last.spaceAfter && CLOSING.test(piece)) last.text += piece;
|
|
31
|
+
else list.push({ text: piece, space: Boolean(last?.spaceAfter) });
|
|
32
|
+
}
|
|
33
|
+
return list;
|
|
34
|
+
}
|
|
35
|
+
/** How good a break after `atom` is: sentence end, clause end, between words, inside CJK text. */
|
|
36
|
+
const breakScore = (atom, next) => SENTENCE_END.test(atom.text) ? 3 : CLAUSE_END.test(atom.text) ? 2 : next?.space ? 1 : 0.5;
|
|
37
|
+
const join = list => list.map((atom, i) => (i && atom.space ? ' ' : '') + atom.text).join('');
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The text as subtitle rows of at most `maxChars` characters, broken at the best place: a sentence
|
|
41
|
+
* end after the first third of an even row, then a clause end after its first half, then the word
|
|
42
|
+
* boundary nearest an even width, so a Line one word too long does not leave that word alone on a
|
|
43
|
+
* row. A single word longer than a row gets a row of its own.
|
|
44
|
+
*/
|
|
45
|
+
export function subtitleRows(text, maxChars) {
|
|
46
|
+
const total = length(text.trim()), even = Math.min(maxChars, Math.ceil(total / Math.ceil(total / maxChars)));
|
|
47
|
+
const least = { 3: even * 0.3, 2: even * 0.5 };
|
|
48
|
+
const rows = [];
|
|
49
|
+
let row = [];
|
|
50
|
+
for (const atom of atoms(text)) {
|
|
51
|
+
row.push(atom);
|
|
52
|
+
if (row.length < 2 || length(join(row)) <= maxChars) continue;
|
|
53
|
+
let cut = row.length - 1, best = -1, distance = Infinity;
|
|
54
|
+
for (let i = 0; i < row.length - 1; i++) {
|
|
55
|
+
const score = breakScore(row[i], row[i + 1]), prefix = length(join(row.slice(0, i + 1)));
|
|
56
|
+
if (prefix < (least[score] ?? 0)) continue;
|
|
57
|
+
if (score > best || (score === best && Math.abs(prefix - even) < distance)) { best = score; distance = Math.abs(prefix - even); cut = i + 1; }
|
|
58
|
+
}
|
|
59
|
+
rows.push(join(row.slice(0, cut)));
|
|
60
|
+
row = row.slice(cut);
|
|
61
|
+
}
|
|
62
|
+
if (row.length) rows.push(join(row));
|
|
63
|
+
return rows;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* When a Line's spoken characters are said, in seconds from the start of its audio: `start(k)` when
|
|
68
|
+
* the `k`th begins and `end(k)` when the one before it ends. With word timings each character takes
|
|
69
|
+
* an equal share of its word, so a pause between words shows as a gap; without, of the whole Line.
|
|
70
|
+
*/
|
|
71
|
+
function clock(line) {
|
|
72
|
+
const total = spoken(line.text);
|
|
73
|
+
if (!line.words?.length) { const at = k => line.duration * (total ? k / total : 0); return { start: at, end: at }; }
|
|
74
|
+
const spans = [];
|
|
75
|
+
let count = 0;
|
|
76
|
+
for (const word of line.words) { const n = Math.max(1, spoken(word.text)); spans.push({ from: count, n, ...word }); count += n; }
|
|
77
|
+
const at = (k, closing) => {
|
|
78
|
+
const position = total ? k * count / total : 0;
|
|
79
|
+
const span = spans.find(s => closing ? position <= s.from + s.n : position < s.from + s.n) ?? spans.at(-1);
|
|
80
|
+
return span.start + (span.end - span.start) * Math.min(1, Math.max(0, (position - span.from) / span.n));
|
|
81
|
+
};
|
|
82
|
+
return { start: k => at(k, false), end: k => at(k, true) };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Subtitle cues for placed Lines: each Line's rows, `maxRows` to a cue (a cue also ends after a
|
|
87
|
+
* sentence), shown while they are spoken. A cue shorter than `minDuration` takes time from the next
|
|
88
|
+
* cue of its Line, or from the silence after its Line, up to `end`, the end of the Final.
|
|
89
|
+
*/
|
|
90
|
+
export function subtitleCues(lines, { language, maxChars, maxRows = 2, minDuration = 1, end = Infinity } = {}) {
|
|
91
|
+
const cues = [];
|
|
92
|
+
for (const line of [...lines].sort((a, b) => a.start - b.start)) {
|
|
93
|
+
const width = maxChars ?? (isCjk(line.text, language) ? 16 : 42), said = clock(line);
|
|
94
|
+
const groups = [];
|
|
95
|
+
for (const row of subtitleRows(line.text, width)) {
|
|
96
|
+
const last = groups.at(-1);
|
|
97
|
+
if (last && last.length < maxRows && !SENTENCE_END.test(last.at(-1))) last.push(row); else groups.push([row]);
|
|
98
|
+
}
|
|
99
|
+
let k = 0;
|
|
100
|
+
const own = groups.map(rows => {
|
|
101
|
+
const n = rows.reduce((sum, row) => sum + spoken(row), 0);
|
|
102
|
+
const cue = { id: line.id, start: line.start + said.start(k), end: line.start + (k + n >= spoken(line.text) ? line.duration : said.end(k + n)), rows };
|
|
103
|
+
k += n;
|
|
104
|
+
return cue;
|
|
105
|
+
});
|
|
106
|
+
cues.push(...own);
|
|
107
|
+
}
|
|
108
|
+
for (const [i, cue] of cues.entries()) {
|
|
109
|
+
if (cue.end - cue.start >= minDuration) continue;
|
|
110
|
+
const next = cues[i + 1], want = cue.start + minDuration;
|
|
111
|
+
if (next?.id === cue.id) cue.end = next.start = Math.min(want, Math.max(cue.end, (cue.start + next.end) / 2));
|
|
112
|
+
else cue.end = Math.min(want, next ? Math.max(cue.end, next.start) : Math.max(cue.end, end));
|
|
113
|
+
}
|
|
114
|
+
return cues;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Whether the Edit's `subtitles` item draws them into the Final; otherwise they go only to the subtitle files. */
|
|
118
|
+
export const burnsIn = subtitles => Boolean(subtitles) && subtitles.burn !== false;
|
|
119
|
+
|
|
120
|
+
/** The cues of placed Lines as the Edit's `subtitles` item lays them out, ending by `end`. */
|
|
121
|
+
export const cuesFor = (lines, language, subtitles, end) => subtitleCues(lines, { language, maxChars: subtitles?.maxChars, maxRows: subtitles?.maxRows, minDuration: subtitles?.minDuration, end });
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* What stops Lines from playing as placed: a Line overlapping the next one, starting before the
|
|
125
|
+
* Take, or running past the end of the Final (`end` seconds). Each problem names its Line.
|
|
126
|
+
*/
|
|
127
|
+
export function lineProblems(lines, end) {
|
|
128
|
+
const sorted = [...lines].sort((a, b) => a.start - b.start), problems = [];
|
|
129
|
+
const seconds = s => `${s.toFixed(2)} s`;
|
|
130
|
+
for (const [i, line] of sorted.entries()) {
|
|
131
|
+
const next = sorted[i + 1], stops = line.start + line.duration;
|
|
132
|
+
if (line.start < 0) problems.push(`Line '${line.id}' starts ${seconds(-line.start)} before the Take`);
|
|
133
|
+
if (next && stops > next.start + 0.005) problems.push(`Line '${line.id}' overlaps '${next.id}' by ${seconds(stops - next.start)}`);
|
|
134
|
+
if (stops > end + 0.005) problems.push(`Line '${line.id}' runs ${seconds(stops - end)} past the end of the Final`);
|
|
135
|
+
}
|
|
136
|
+
return problems;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const stamp = (seconds, separator) => {
|
|
140
|
+
const ms = Math.max(0, Math.round(seconds * 1000)), pad = (n, w = 2) => String(n).padStart(w, '0');
|
|
141
|
+
return `${pad(Math.floor(ms / 3600000))}:${pad(Math.floor(ms / 60000) % 60)}:${pad(Math.floor(ms / 1000) % 60)}${separator}${pad(ms % 1000, 3)}`;
|
|
142
|
+
};
|
|
143
|
+
/** Cues as a SubRip (.srt) file. */
|
|
144
|
+
export const toSrt = cues => cues.map((cue, i) => `${i + 1}\n${stamp(cue.start, ',')} --> ${stamp(cue.end, ',')}\n${cue.rows.join('\n')}\n`).join('\n');
|
|
145
|
+
/** Cues as a WebVTT (.vtt) file. */
|
|
146
|
+
export const toVtt = cues => `WEBVTT\n\n${cues.map(cue => `${stamp(cue.start, '.')} --> ${stamp(cue.end, '.')}\n${cue.rows.join('\n')}\n`).join('\n')}`;
|