cuetake 0.4.0 → 0.6.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 +5 -5
- package/examples/tabs.mjs +88 -0
- package/helper/bin/cuetake-capture +0 -0
- package/package.json +5 -3
- 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 +3 -2
- package/src/camera.js +80 -33
- package/src/cli.js +29 -13
- package/src/cursor.js +24 -4
- package/src/desktop.js +108 -0
- package/src/director.js +340 -35
- package/src/edit.js +74 -16
- package/src/environment.js +34 -2
- package/src/follow-tabs.js +64 -0
- package/src/frames.js +41 -0
- package/src/home.js +23 -0
- package/src/look.js +36 -31
- package/src/mac-keys.js +47 -0
- package/src/masks.js +140 -0
- package/src/motion.js +13 -4
- package/src/pipeline.js +253 -48
- package/src/probe.js +315 -73
- package/src/recorder.js +46 -13
- package/src/render-page.js +545 -151
- package/src/render.js +38 -14
- package/src/shutter.js +42 -0
- package/src/styles/browser.js +2 -1
- package/src/styles/fast-forward.js +22 -0
- package/src/styles.js +3 -2
- package/src/tab-capture.js +225 -77
- package/src/tabs.js +126 -0
- package/src/time-map.js +106 -0
- package/src/uninstall.js +22 -9
package/src/time-map.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time map between the Final and the Source, shared by Node and the render page. Pure functions,
|
|
3
|
+
* no imports.
|
|
4
|
+
*
|
|
5
|
+
* Every time in the Timeline and the Edit is Source time: seconds since Capture started. The Edit's
|
|
6
|
+
* `fastForward` spans (`{ start, end, rate }`, Source seconds) play `rate` times faster in the Final;
|
|
7
|
+
* the rest plays as recorded. A span eases to its rate and back inside itself, over about `EASE`
|
|
8
|
+
* seconds of the Final each way, so the page never jumps to speed and the moments around the span stay
|
|
9
|
+
* as recorded.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const EASE = 0.3; // seconds of the Final a span takes to reach its rate, and to leave it
|
|
13
|
+
const BADGE_IN = 0.15, BADGE_OUT = 0.2; // seconds of the Final a fast-forward badge takes to appear and to go
|
|
14
|
+
const EPSILON = 0.005;
|
|
15
|
+
|
|
16
|
+
// A ramp's speed rises from 1 to `rate` as smoothstep(u); `rise(u)` is that share integrated over u.
|
|
17
|
+
const rise = u => u * u * u - u * u * u * u / 2;
|
|
18
|
+
|
|
19
|
+
/** What stops the spans from playing: a rate below 1, an empty span, or spans that overlap. Each problem names its span. */
|
|
20
|
+
export function fastForwardProblems(spans = []) {
|
|
21
|
+
const problems = [], sorted = [...spans].sort((a, b) => a.start - b.start);
|
|
22
|
+
const name = span => `The fast-forward ${typeof span.start === 'number' ? `from ${span.start.toFixed(2)} s` : JSON.stringify(span)}`;
|
|
23
|
+
for (const [i, span] of sorted.entries()) {
|
|
24
|
+
if (!(typeof span.start === 'number' && typeof span.end === 'number' && span.end > span.start)) problems.push(`${name(span)} needs a start before its end, in seconds`);
|
|
25
|
+
if (!(typeof span.rate === 'number' && span.rate >= 1)) problems.push(`${name(span)} needs a rate of at least 1`);
|
|
26
|
+
const next = sorted[i + 1];
|
|
27
|
+
if (next && next.start < span.end - EPSILON) problems.push(`${name(span)} overlaps the one from ${next.start.toFixed(2)} s`);
|
|
28
|
+
}
|
|
29
|
+
return problems;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The map for a Source `duration` seconds long: the Final's `duration`, `sourceAt(t)` for a moment of
|
|
34
|
+
* the Final, `outputAt(s)` for a moment of the Source, and each span's place in the Final as
|
|
35
|
+
* `spans: [{ start, end, rate }]`. Spans are clipped to the Source; invalid ones stop it.
|
|
36
|
+
*/
|
|
37
|
+
export function timeMap(spans = [], duration) {
|
|
38
|
+
const problems = fastForwardProblems(spans);
|
|
39
|
+
if (problems.length) throw new Error(`The fast-forward spans do not fit: ${problems.join('; ')}`);
|
|
40
|
+
// Pieces of the Final in order, each `seconds` long from Final time `t` and Source time `s`.
|
|
41
|
+
const pieces = [];
|
|
42
|
+
let t = 0, s = 0;
|
|
43
|
+
const add = (seconds, source, at, rate = 1) => { if (seconds > 0) pieces.push({ t, s, seconds, at, rate }); t += seconds; s += source; };
|
|
44
|
+
const shown = [];
|
|
45
|
+
const clipped = spans.map(span => ({ ...span, start: Math.max(0, span.start), end: Math.min(duration, span.end) })).filter(span => span.end > span.start);
|
|
46
|
+
for (const { start, end, rate } of clipped.sort((a, b) => a.start - b.start)) {
|
|
47
|
+
add(start - s, start - s, u => u);
|
|
48
|
+
const from = t, length = end - start, ease = Math.min(EASE, length / (1 + rate)), steady = length - ease * (1 + rate);
|
|
49
|
+
add(ease, ease * (1 + rate) / 2, u => u + (rate - 1) * ease * rise(u / ease), null);
|
|
50
|
+
add(steady / rate, steady, u => u * rate, rate);
|
|
51
|
+
add(ease, ease * (1 + rate) / 2, u => rate * u - (rate - 1) * ease * rise(u / ease), null);
|
|
52
|
+
s = end; // no drift from the ramps' arithmetic
|
|
53
|
+
shown.push({ start: from, end: t, rate });
|
|
54
|
+
}
|
|
55
|
+
add(Math.max(0, duration - s), Math.max(0, duration - s), u => u);
|
|
56
|
+
if (!pieces.length) pieces.push({ t: 0, s: 0, seconds: 0, at: u => u, rate: 1 });
|
|
57
|
+
const last = (list, key, value) => list.findLast(piece => piece[key] <= value) ?? list[0];
|
|
58
|
+
return {
|
|
59
|
+
duration: t,
|
|
60
|
+
spans: shown,
|
|
61
|
+
sourceAt(time) {
|
|
62
|
+
const piece = last(pieces, 't', time), u = Math.min(Math.max(time - piece.t, 0), piece.seconds);
|
|
63
|
+
// Past the last piece, or before the first, the Final plays the Source as recorded.
|
|
64
|
+
return piece.s + piece.at(u) + (time - piece.t - u);
|
|
65
|
+
},
|
|
66
|
+
outputAt(source) {
|
|
67
|
+
const piece = last(pieces, 's', source), offset = source - piece.s;
|
|
68
|
+
if (piece.rate !== null || offset <= 0) return piece.t + offset / (piece.rate ?? 1);
|
|
69
|
+
// A ramp: its Source time rises monotonically, so halve the interval until it pins `offset`.
|
|
70
|
+
let low = 0, high = piece.seconds;
|
|
71
|
+
if (piece.at(high) <= offset) return piece.t + high + (offset - piece.at(high));
|
|
72
|
+
for (let i = 0; i < 48; i++) { const mid = (low + high) / 2; if (piece.at(mid) < offset) low = mid; else high = mid; }
|
|
73
|
+
return piece.t + (low + high) / 2;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The fast-forward badge at Final time `t`: the index of the span showing, its rate and the badge's opacity, or null. */
|
|
79
|
+
export function badgeAt(map, t) {
|
|
80
|
+
const index = map.spans.findIndex(span => t >= span.start && t < span.end);
|
|
81
|
+
if (index < 0) return null;
|
|
82
|
+
const { start, end, rate } = map.spans[index];
|
|
83
|
+
return { index, rate, opacity: Math.max(0, Math.min(1, (t - start) / BADGE_IN, (end - t) / BADGE_OUT)) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `items` with the times named by `keys` moved from the Source to the Final, as Shortcuts and camera targets are. */
|
|
87
|
+
export const retimed = (items, map, keys = ['t']) => items.map(item => {
|
|
88
|
+
const moved = { ...item };
|
|
89
|
+
for (const key of keys) if (typeof item[key] === 'number') moved[key] = map.outputAt(item[key]);
|
|
90
|
+
return moved;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Lines placed in the Final: each `start` moved to Final time. A Line still speaking while the Final
|
|
95
|
+
* fast-forwards is a problem naming it, since speech cannot play faster with the picture.
|
|
96
|
+
*/
|
|
97
|
+
export function linesInFinal(lines, map) {
|
|
98
|
+
const problems = [], seconds = s => `${s.toFixed(2)} s`;
|
|
99
|
+
const placed = lines.map(line => {
|
|
100
|
+
const start = map.outputAt(line.start), stops = start + (line.duration ?? 0);
|
|
101
|
+
const span = map.spans.find(span => start < span.end - EPSILON && stops > span.start + EPSILON);
|
|
102
|
+
if (span) problems.push(`Line '${line.id}' is spoken from ${seconds(start)} to ${seconds(stops)} of the Final, while it fast-forwards from ${seconds(span.start)} to ${seconds(span.end)}; move the Line out of it or shorten the fast-forward`);
|
|
103
|
+
return { ...line, start };
|
|
104
|
+
});
|
|
105
|
+
return { lines: placed, problems };
|
|
106
|
+
}
|
package/src/uninstall.js
CHANGED
|
@@ -3,7 +3,8 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { authProfileFiles } from './auth.js';
|
|
6
|
-
import {
|
|
6
|
+
import { userLookFiles } from './look.js';
|
|
7
|
+
import { userHome } from './home.js';
|
|
7
8
|
import { uninstallBrowser } from './environment.js';
|
|
8
9
|
|
|
9
10
|
const PACKAGE_DIR = fileURLToPath(new URL('..', import.meta.url)).replace(/[\\/]$/, '');
|
|
@@ -26,13 +27,24 @@ export async function npxFolders({ cache = process.env.npm_config_cache || join(
|
|
|
26
27
|
return found.sort();
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
const entries = async dir => (await fs.readdir(dir, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; }))
|
|
31
|
+
.sort((a, b) => a.name.localeCompare(b.name)).map(entry => ({ path: join(dir, entry.name), folder: entry.isDirectory() }));
|
|
32
|
+
|
|
33
|
+
/** Each Take folder in the user Home, at `takes/<scenario>/<time>`. */
|
|
34
|
+
async function userTakes() {
|
|
35
|
+
const dir = join(userHome(), 'takes'), folders = (await entries(dir)).filter(e => e.folder).map(e => e.path), paths = [];
|
|
36
|
+
for (const folder of folders) for (const take of await entries(folder)) if (take.folder) paths.push(take.path);
|
|
37
|
+
return { dir, paths, folders };
|
|
38
|
+
}
|
|
39
|
+
const userScenarios = async () => { const dir = join(userHome(), 'scenarios'); return { dir, paths: (await entries(dir)).map(e => e.path) }; };
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* Removes what CueTake put on this machine outside the user's projects: its npx folders and, through
|
|
31
|
-
* Playwright, the browser unless another Playwright installation still uses it. Auth profiles and
|
|
32
|
-
* Looks are the user's and go only when asked.
|
|
43
|
+
* Playwright, the browser unless another Playwright installation still uses it. Auth profiles and the user
|
|
44
|
+
* Home's Looks, Takes and Scenarios are the user's and go only when asked. A project Home is never touched.
|
|
33
45
|
*/
|
|
34
|
-
export async function uninstall({ auth = false, looks = false, dryRun = false, removeBrowser = uninstallBrowser } = {}) {
|
|
35
|
-
const npx = await npxFolders()
|
|
46
|
+
export async function uninstall({ auth = false, looks = false, takes = false, scenarios = false, dryRun = false, removeBrowser = uninstallBrowser } = {}) {
|
|
47
|
+
const npx = await npxFolders();
|
|
36
48
|
const removed = [], kept = [];
|
|
37
49
|
const remove = async (item, paths) => {
|
|
38
50
|
for (const path of paths) {
|
|
@@ -47,16 +59,17 @@ export async function uninstall({ auth = false, looks = false, dryRun = false, r
|
|
|
47
59
|
if (browser.existed && dryRun) removed.push({ item: 'browser', path: browser.path, note: 'kept if another Playwright installation still uses it' });
|
|
48
60
|
else if (browser.removed) removed.push({ item: 'browser', path: browser.path });
|
|
49
61
|
else if (browser.existed) kept.push({ item: 'browser', path: browser.path, reason: 'another Playwright installation still uses it' });
|
|
50
|
-
|
|
62
|
+
const kinds = [['Auth profile', '--auth', auth, await authProfileFiles()], ['Look', '--looks', looks, await userLookFiles()], ['Take', '--takes', takes, await userTakes()], ['Scenario', '--scenarios', scenarios, await userScenarios()]];
|
|
63
|
+
for (const [item, flag, wanted, { dir, paths, folders = [] }] of kinds) {
|
|
51
64
|
if (wanted) await remove(item, paths);
|
|
52
65
|
else if (paths.length) kept.push({ item, path: dir, count: paths.length, reason: `pass ${flag} to remove` });
|
|
53
|
-
if (wanted && !dryRun) await fs.rmdir(
|
|
66
|
+
if (wanted && !dryRun) for (const folder of [...folders, dir]) await fs.rmdir(folder).catch(() => {});
|
|
54
67
|
}
|
|
55
68
|
// This CLI's own npx folder goes last, once nothing else needs its files.
|
|
56
69
|
await remove('npx cache', npx.filter(path => path === own));
|
|
57
|
-
if (!dryRun) await fs.rmdir(
|
|
70
|
+
if (!dryRun) await fs.rmdir(userHome()).catch(() => {});
|
|
58
71
|
return {
|
|
59
72
|
dryRun, [dryRun ? 'wouldRemove' : 'removed']: removed, kept,
|
|
60
|
-
note: '
|
|
73
|
+
note: 'Every project Home (.cuetake in a project) stays. The skill is removed by the tool that installed it.',
|
|
61
74
|
};
|
|
62
75
|
}
|