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/edit.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { isPopup } from './tabs.js';
|
|
3
|
+
import { SETTLE } from './cursor.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* An Edit holds every choice Render makes; a Scenario's config only seeds the first one. Styling is
|
|
@@ -13,12 +15,14 @@ export const evenSize = z.number().int().min(240).max(7680).refine(n => n % 2 ==
|
|
|
13
15
|
|
|
14
16
|
/** Times are seconds except clickEffect.duration, which is milliseconds; geometry is CSS pixels. */
|
|
15
17
|
export const DEFAULT_STYLE = {
|
|
16
|
-
// The Cursor shrinks to `press` while a button is held; `false` turns that off.
|
|
17
|
-
//
|
|
18
|
-
|
|
18
|
+
// The Cursor shrinks to `press` while a button is held; `false` turns that off. It takes a shape only
|
|
19
|
+
// once the page has asked for it `settle` seconds or at a press; 0 shows every shape. A click shows on
|
|
20
|
+
// the Cursor, so no click effect is drawn unless named.
|
|
21
|
+
cursor: { draw: 'arrow', size: 24, color: '#ffffff', press: 0.8, settle: SETTLE },
|
|
19
22
|
clickEffect: false,
|
|
20
|
-
// quality is the H.264 quantizer (lower is sharper and larger).
|
|
21
|
-
|
|
23
|
+
// quality is the H.264 quantizer (lower is sharper and larger). shutter is the fraction of each
|
|
24
|
+
// frame over which the camera and the Cursor blur as they move (shutter.js); 0 turns blur off.
|
|
25
|
+
output: { width: 3840, height: 2160, quality: 22, shutter: 0.5 },
|
|
22
26
|
// padding is a fraction of the short side, one number or [top, right, bottom, left]; radius is in 1080p pixels.
|
|
23
27
|
frame: { padding: 0.08, radius: 12, chrome: { draw: 'browser' }, background: [{ shader: 'fluted' }], effects: [{ shader: 'shadow' }] },
|
|
24
28
|
// See camera.js. Each target is framed with `padding` CSS px around it, zooming at most `maxZoom`;
|
|
@@ -33,6 +37,13 @@ export const DEFAULT_STYLE = {
|
|
|
33
37
|
// subtitle files. Rows hold up to `maxChars` (about 16 in Chinese, 42 otherwise), `maxRows` to a cue,
|
|
34
38
|
// each shown at least `minDuration`.
|
|
35
39
|
subtitles: { draw: 'subtitles', burn: true },
|
|
40
|
+
// Drawn over the Final, outside the camera, while it fast-forwards, such as { draw: 'fast-forward' };
|
|
41
|
+
// `false` shows none.
|
|
42
|
+
fastForwardBadge: false,
|
|
43
|
+
// How the Final shows the Tabs (tabs.js): the window cuts to a tab of its own size, or fades over
|
|
44
|
+
// `{ fade }` seconds; a popup window scales and fades in and out over `duration`, from `scale`, unless
|
|
45
|
+
// `popupAnimation` is false. Times are Final seconds.
|
|
46
|
+
tabs: { transition: 'cut', popupAnimation: { duration: 0.2, scale: 0.9 } },
|
|
36
47
|
};
|
|
37
48
|
|
|
38
49
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -50,42 +61,89 @@ export function merge(base, over) {
|
|
|
50
61
|
|
|
51
62
|
/** A complete Edit: the defaults under whatever `edit` names. */
|
|
52
63
|
export function withDefaults(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);
|
|
64
|
+
return merge({ schemaVersion: EDIT_VERSION, ...DEFAULT_STYLE, output: { ...DEFAULT_STYLE.output, fps: 60 }, camera: { ...DEFAULT_STYLE.camera, targets: [], scrolls: [] }, tabs: { ...DEFAULT_STYLE.tabs, placement: [] }, shortcuts: [], fastForward: [], masks: [], narration: { volume: 1, lines: [] } }, edit);
|
|
54
65
|
}
|
|
55
66
|
|
|
67
|
+
// Seconds after a click within which the App's focus moving to what holds its target counts as the click's.
|
|
68
|
+
const FOCUS_AFTER_CLICK = 1;
|
|
69
|
+
|
|
56
70
|
/**
|
|
57
|
-
* Camera targets: observed clicks, typing and drags,
|
|
58
|
-
*
|
|
71
|
+
* Camera targets: observed clicks, typing and drags, and each element an App focused, each in the CSS
|
|
72
|
+
* pixels of its Tab, and each popup window's whole page as it first comes in front, except those
|
|
73
|
+
* inside a `wide` window ({ start, end } seconds) from an action with `focus: false`, and focus a click
|
|
74
|
+
* gave to what holds its target. Like a manual zoom in Screen Studio, an explicit focus
|
|
59
75
|
* target replaces only the automatic targets inside its own span (from `lead` before it to `hold` after).
|
|
60
76
|
*/
|
|
61
77
|
export function cameraTargets(timeline, focus, wide = [], camera = {}) {
|
|
62
78
|
const { lead, hold } = { ...DEFAULT_STYLE.camera, ...camera };
|
|
63
79
|
const spans = focus.map(f => ({ start: f.t - lead, end: (f.until ?? f.t) + hold }));
|
|
64
80
|
const inside = (t, windows) => windows.some(w => t >= w.start && t <= w.end);
|
|
81
|
+
const tabs = new Map((timeline.tabs ?? []).map(tab => [tab.id, tab])), framed = new Set();
|
|
82
|
+
// Focus a click gave to what holds its target, such as the text area around a link, adds only a larger box.
|
|
83
|
+
const holds = (outer, inner) => outer.x <= inner.x && outer.y <= inner.y && outer.x + outer.width >= inner.x + inner.width && outer.y + outer.height >= inner.y + inner.height;
|
|
84
|
+
const byClick = focused => timeline.events.some(event => event.type === 'click' && event.box && event.tab === focused.tab && event.t <= focused.t && focused.t - event.t <= FOCUS_AFTER_CLICK && holds(focused.box, event.box));
|
|
65
85
|
const automatic = timeline.events.filter(event => !inside(event.t, wide) && !inside(event.t, spans)).flatMap(event => {
|
|
66
|
-
|
|
67
|
-
if (event.type === '
|
|
86
|
+
const tab = event.tab === undefined ? {} : { tab: event.tab };
|
|
87
|
+
if (event.type === 'focused' && byClick(event)) return [];
|
|
88
|
+
if ((event.type === 'click' || event.type === 'focused') && event.box) return [{ t: event.t, box: event.box, ...tab }];
|
|
89
|
+
if (event.type === 'type' && event.box) return [{ t: event.t, box: event.box, until: event.end, ...tab }];
|
|
68
90
|
if (event.type === 'drag') {
|
|
69
91
|
const x = Math.min(event.from.x, event.to.x), y = Math.min(event.from.y, event.to.y);
|
|
70
|
-
return [{ t: event.t, box: { x, y, width: Math.abs(event.to.x - event.from.x), height: Math.abs(event.to.y - event.from.y) }, until: event.end }];
|
|
92
|
+
return [{ t: event.t, box: { x, y, width: Math.abs(event.to.x - event.from.x), height: Math.abs(event.to.y - event.from.y) }, until: event.end, ...tab }];
|
|
93
|
+
}
|
|
94
|
+
const opened = tabs.get(event.tab);
|
|
95
|
+
if (event.type === 'front' && opened && isPopup(opened, timeline.viewport) && !framed.has(event.tab)) {
|
|
96
|
+
framed.add(event.tab);
|
|
97
|
+
return [{ t: event.t, box: { x: 0, y: 0, ...opened.viewport }, tab: event.tab }];
|
|
71
98
|
}
|
|
72
99
|
return [];
|
|
73
100
|
});
|
|
74
101
|
return [...automatic, ...focus].sort((a, b) => a.t - b.t);
|
|
75
102
|
}
|
|
76
103
|
|
|
104
|
+
/** What the address bar shows for a page address: its host, or the whole address when it has none. */
|
|
105
|
+
export function addressOf(url) {
|
|
106
|
+
try { const parsed = new URL(url); return /^https?:$/.test(parsed.protocol) ? parsed.host : url; } catch { return url; }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The address bar's text when Capture started (`url`), and each change after it (`urls`, as
|
|
111
|
+
* { t, url, tab } in Source time): a full navigation to another host shows the new one from the moment
|
|
112
|
+
* the page took its address. A Tab the demo opens shows the host it opened on, or nothing until its
|
|
113
|
+
* first document commits when it opened on about:blank. The Scenario's `frame.url`, when set, names
|
|
114
|
+
* the host Capture started on, also when a navigation comes back to it.
|
|
115
|
+
*/
|
|
116
|
+
export function addressBar(config, timeline) {
|
|
117
|
+
const first = addressOf(timeline.url ?? config.url), shown = host => host === first ? config.frame?.url ?? first : host;
|
|
118
|
+
const urls = [], current = new Map([[0, first]]);
|
|
119
|
+
const change = (t, url, tab) => {
|
|
120
|
+
const host = !url || url === 'about:blank' ? '' : addressOf(url);
|
|
121
|
+
if (host !== (current.get(tab) ?? '')) urls.push({ t, url: shown(host), tab });
|
|
122
|
+
current.set(tab, host);
|
|
123
|
+
};
|
|
124
|
+
const opened = (timeline.tabs ?? []).slice(1).map(tab => ({ t: tab.opened, url: tab.url, tab: tab.id }));
|
|
125
|
+
const committed = (timeline.events ?? []).filter(event => event.type === 'navigate' && event.commit !== undefined).map(event => ({ t: event.commit, url: event.url, tab: event.tab ?? 0 }));
|
|
126
|
+
for (const { t, url, tab } of [...opened, ...committed].sort((a, b) => a.t - b.t)) change(t, url, tab);
|
|
127
|
+
return { url: shown(first), urls };
|
|
128
|
+
}
|
|
129
|
+
|
|
77
130
|
/**
|
|
78
131
|
* The first Edit of a Take. Each Line starts where the Scenario said it (`d.say`); its text, audio and
|
|
79
132
|
* 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
|
|
133
|
+
* Timeline recorded are the ones shown, so one can be relabeled or removed without recording again, and
|
|
134
|
+
* so are the waits the Scenario fast-forwarded (`d.fastForward`), so one can be retimed (time-map.js),
|
|
135
|
+
* and the elements it masked (`d.mask`), so a mask can be retimed, restyled or removed (masks.js).
|
|
81
136
|
*/
|
|
82
137
|
export function createEdit(config, timeline, focus, wide = []) {
|
|
83
138
|
return withDefaults({
|
|
84
|
-
cursor: config.cursor, clickEffect: config.clickEffect, keycaps: config.keycaps, subtitles: config.subtitles, output: { ...config.output, fps: config.capture.fps },
|
|
85
|
-
// The browser chrome shows the
|
|
86
|
-
|
|
87
|
-
|
|
139
|
+
cursor: config.cursor, clickEffect: config.clickEffect, keycaps: config.keycaps, subtitles: config.subtitles, fastForwardBadge: config.fastForwardBadge, output: { ...config.output, fps: config.capture.fps },
|
|
140
|
+
// The browser chrome shows the host the page is on, unless the config names something else. A Take
|
|
141
|
+
// of Apps shows the App's own windows, without chrome, unless the config names one (ADR 0009).
|
|
142
|
+
frame: config.app ? { chrome: false, ...config.frame } : { ...config.frame, ...addressBar(config, timeline) },
|
|
143
|
+
camera: { ...config.camera, targets: cameraTargets(timeline, focus, wide, config.camera), scrolls: timeline.events.filter(event => event.type === 'scroll').map(({ t, end }) => ({ start: t, end })) }, tabs: config.tabs,
|
|
88
144
|
shortcuts: timeline.events.filter(event => event.type === 'shortcut').map(({ t, keys }) => ({ t, keys })),
|
|
145
|
+
fastForward: timeline.events.filter(event => event.type === 'fastForward').map(({ t, end, rate }) => ({ start: t, end, rate })),
|
|
146
|
+
masks: timeline.events.filter(event => event.type === 'mask').map(({ type, t, end, effect, element, ...params }) => ({ effect, element, start: t, ...(end !== null && end !== undefined && { end }), ...params })),
|
|
89
147
|
narration: { lines: timeline.events.filter(event => event.type === 'say').map(event => ({ id: event.id, start: event.t })) },
|
|
90
148
|
});
|
|
91
149
|
}
|
package/src/environment.js
CHANGED
|
@@ -3,8 +3,13 @@ import { spawn } from 'node:child_process';
|
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { chromium } from 'playwright';
|
|
6
|
+
import { appChecks } from './app-capture.js';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Checks what CueTake needs; installs nothing and requests no permission. Each failed check names the
|
|
10
|
+
* exact fix. `ok` covers web pages; on macOS, `apps.ok` also covers the checks marked `for: 'Apps'`,
|
|
11
|
+
* which a Take of an App needs too.
|
|
12
|
+
*/
|
|
8
13
|
export async function doctor() {
|
|
9
14
|
const checks = [];
|
|
10
15
|
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
@@ -14,11 +19,38 @@ export async function doctor() {
|
|
|
14
19
|
const browserPath = chromium.executablePath();
|
|
15
20
|
try { await fs.access(browserPath); checks.push({ name: 'chromium', ok: true, path: browserPath }); }
|
|
16
21
|
catch { checks.push({ name: 'chromium', ok: false, fix: 'cuetake install-browser (downloads about 150 MB; ask the user first)' }); }
|
|
22
|
+
if (checks.at(-1).ok) checks.push(await gpu());
|
|
17
23
|
const platform = process.platform === 'darwin'
|
|
18
24
|
? { name: 'platform', ok: true, value: 'macOS' }
|
|
19
25
|
: { name: 'platform', ok: true, value: process.platform, note: 'Only macOS is verified; capture and Render may behave differently here.' };
|
|
20
26
|
checks.push(platform);
|
|
21
|
-
|
|
27
|
+
if (process.platform === 'darwin') checks.push(...await appChecks());
|
|
28
|
+
return { ok: checks.every(c => c.ok || c.for), ...(process.platform === 'darwin' && { apps: { ok: checks.every(c => c.ok) } }), checks };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Whether a WebGL renderer name is a GPU; null when Chromium reports none. */
|
|
32
|
+
export const drawsWithGpu = renderer => renderer ? !/swiftshader|llvmpipe|softpipe|software|basic render driver/i.test(renderer) : null;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Asks the headless Chromium Capture runs in what draws its pages. Without a GPU it rasterizes and encodes
|
|
36
|
+
* on the CPU, and at resolution scale 2 a busy page then gets far fewer frames than it draws. Informational:
|
|
37
|
+
* Capture still works, so the check never fails.
|
|
38
|
+
*/
|
|
39
|
+
async function gpu() {
|
|
40
|
+
let renderer = null;
|
|
41
|
+
try {
|
|
42
|
+
const browser = await chromium.launch({ headless: true, channel: 'chromium' });
|
|
43
|
+
try {
|
|
44
|
+
renderer = await (await browser.newPage()).evaluate(() => {
|
|
45
|
+
const gl = document.createElement('canvas').getContext('webgl'), info = gl?.getExtension('WEBGL_debug_renderer_info');
|
|
46
|
+
return info ? gl.getParameter(info.UNMASKED_RENDERER_WEBGL) : null;
|
|
47
|
+
});
|
|
48
|
+
} finally { await browser.close(); }
|
|
49
|
+
} catch {}
|
|
50
|
+
const accelerated = drawsWithGpu(renderer);
|
|
51
|
+
return { name: 'gpu', ok: true, accelerated, renderer,
|
|
52
|
+
...(accelerated === false && { note: 'Chromium draws without a GPU here, so record captures at resolutionScale 1 unless the Scenario sets one.' }),
|
|
53
|
+
...(accelerated === null && { note: 'Chromium did not report a renderer.' }) };
|
|
22
54
|
}
|
|
23
55
|
|
|
24
56
|
function playwright(args) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Follows the Tabs a Take shows (ADR 0008): the first page, and every page a Tab, or an iframe in it,
|
|
3
|
+
* opens as a new tab or a popup window. Pages the Scenario opens itself with `context.newPage()` are
|
|
4
|
+
* not followed. `watch(tab)` is called as each Tab opens; `start(tab)` then begins recording it, one Tab
|
|
5
|
+
* at a time. A Tab another came in front of while it started goes back behind.
|
|
6
|
+
*
|
|
7
|
+
* Which Tab is in front follows the browser: a new Tab comes in front when it opens, and when it closes
|
|
8
|
+
* the Tab that opened it comes back (or, if that one closed too, its nearest open opener). Any other
|
|
9
|
+
* Tab comes back only through `switchTo`. Times are epoch milliseconds.
|
|
10
|
+
*/
|
|
11
|
+
export function followTabs(first, { watch = () => {}, start = async () => {} } = {}) {
|
|
12
|
+
const tabs = [], fronts = [];
|
|
13
|
+
let front = null, starting = Promise.resolve();
|
|
14
|
+
const toFront = tab => {
|
|
15
|
+
if (front === tab) return;
|
|
16
|
+
front = tab;
|
|
17
|
+
fronts.push({ ms: Date.now(), tab: tab.id });
|
|
18
|
+
};
|
|
19
|
+
const add = (page, opener) => {
|
|
20
|
+
const tab = { id: tabs.length, page, opener: opener?.id ?? null, openedMs: Date.now(), closedMs: null, viewport: page.viewportSize(), url: page.url() };
|
|
21
|
+
tabs.push(tab);
|
|
22
|
+
watch(tab);
|
|
23
|
+
page.on('popup', popup => toFront(add(popup, tab)));
|
|
24
|
+
page.on('close', () => {
|
|
25
|
+
tab.closedMs = Date.now();
|
|
26
|
+
if (front !== tab) return;
|
|
27
|
+
let back = tabs[tab.opener];
|
|
28
|
+
while (back?.closedMs) back = tabs[back.opener];
|
|
29
|
+
back ??= tabs.findLast(other => !other.closedMs);
|
|
30
|
+
if (!back) return;
|
|
31
|
+
toFront(back);
|
|
32
|
+
back.page.bringToFront().catch(() => {});
|
|
33
|
+
});
|
|
34
|
+
// A Tab that closes before it could be recorded is left out; any other failure stops the Take.
|
|
35
|
+
tab.ready = starting = starting.catch(() => {}).then(() => start(tab)).then(async () => {
|
|
36
|
+
tab.recorded = true;
|
|
37
|
+
if (front !== tab) await front.page.bringToFront().catch(() => {});
|
|
38
|
+
}, error => {
|
|
39
|
+
if (!page.isClosed()) throw error;
|
|
40
|
+
tab.recorded = false;
|
|
41
|
+
});
|
|
42
|
+
tab.ready.catch(() => {});
|
|
43
|
+
return tab;
|
|
44
|
+
};
|
|
45
|
+
front = add(first, null);
|
|
46
|
+
const of = page => tabs.find(tab => tab.page === page);
|
|
47
|
+
return {
|
|
48
|
+
get front() { return front; },
|
|
49
|
+
fronts,
|
|
50
|
+
list: () => tabs,
|
|
51
|
+
of,
|
|
52
|
+
/** Resolves once the Tab showing `page` records. */
|
|
53
|
+
ready: page => of(page)?.ready ?? Promise.reject(new Error('This page is not a Tab of the Take')),
|
|
54
|
+
/** Resolves once every Tab opened so far records or has closed unrecorded; rejects if one failed to start. */
|
|
55
|
+
started: () => Promise.all(tabs.map(tab => tab.ready)),
|
|
56
|
+
async switchTo(page) {
|
|
57
|
+
const tab = of(page);
|
|
58
|
+
if (!tab) throw new Error('d.switchTo needs a Tab of the Take: the first page or one the demo opened. Capture does not follow pages opened with context.newPage()');
|
|
59
|
+
if (tab.closedMs) throw new Error(`Tab ${tab.id} has closed`);
|
|
60
|
+
await page.bringToFront();
|
|
61
|
+
toFront(tab);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
package/src/frames.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an iframe's content starts in its parent's viewport, in CSS pixels, and how much it is scaled:
|
|
3
|
+
* inside its border and padding, after scrolling, positioning and transforms. It runs in the page, in
|
|
4
|
+
* the iframe's parent document, so it works for a cross-origin iframe too. A rotated or skewed iframe
|
|
5
|
+
* gets the scale of its bounding box, which is only near.
|
|
6
|
+
*/
|
|
7
|
+
export function contentOf(element) {
|
|
8
|
+
const r = element.getBoundingClientRect(), style = getComputedStyle(element);
|
|
9
|
+
const sx = element.offsetWidth ? r.width / element.offsetWidth : 1, sy = element.offsetHeight ? r.height / element.offsetHeight : 1;
|
|
10
|
+
return { x: r.x + (element.clientLeft + parseFloat(style.paddingLeft)) * sx, y: r.y + (element.clientTop + parseFloat(style.paddingTop)) * sy, sx, sy };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A located element's border box in top-level CSS pixels, mapped up through every iframe it is in, or
|
|
15
|
+
* null when it shows no box. Playwright's own boundingBox places an element in a cross-origin iframe
|
|
16
|
+
* from the iframe's outer edge, unscaled, so it misses the iframe's border, padding and scale.
|
|
17
|
+
*/
|
|
18
|
+
export async function boxOnPage(locator) {
|
|
19
|
+
const handle = await locator.elementHandle();
|
|
20
|
+
try {
|
|
21
|
+
const box = await handle.evaluate(e => e.getClientRects().length ? e.getBoundingClientRect().toJSON() : null);
|
|
22
|
+
return box && onPage(await placeOf(await handle.ownerFrame()), box);
|
|
23
|
+
} finally { await handle.dispose(); }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Where a frame's viewport shows in top-level CSS pixels: the offset of its origin and its scale,
|
|
28
|
+
* through every iframe it is in. The top frame's is { x: 0, y: 0, sx: 1, sy: 1 }.
|
|
29
|
+
*/
|
|
30
|
+
export async function placeOf(frame) {
|
|
31
|
+
let map = { x: 0, y: 0, sx: 1, sy: 1 };
|
|
32
|
+
for (let f = frame; f?.parentFrame(); f = f.parentFrame()) {
|
|
33
|
+
const element = await f.frameElement();
|
|
34
|
+
const content = await element.evaluate(contentOf).finally(() => element.dispose());
|
|
35
|
+
map = { x: content.x + map.x * content.sx, y: content.y + map.y * content.sy, sx: map.sx * content.sx, sy: map.sy * content.sy };
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A box in a frame's CSS pixels placed in top-level CSS pixels by the frame's `map` (placeOf). */
|
|
41
|
+
export const onPage = (map, box) => ({ x: map.x + box.x * map.sx, y: map.y + box.y * map.sy, width: box.width * map.sx, height: box.height * map.sy });
|
package/src/home.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
/** The user Home, shared by every project; on macOS and Linux it follows $HOME. */
|
|
6
|
+
export const userHome = () => join(process.env.HOME || homedir(), '.local', 'share', 'cuetake');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The Home of the skill copy that ran: `CUETAKE_HOME`, which the skill's launcher sets for a skill installed
|
|
10
|
+
* in a project, else the user Home (ADR 0011).
|
|
11
|
+
*/
|
|
12
|
+
export const home = () => process.env.CUETAKE_HOME ? resolve(process.env.CUETAKE_HOME) : userHome();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The Home, created when missing. A project Home is created with a .gitignore that keeps its Takes out of
|
|
16
|
+
* git; CueTake never writes that file again, so the user may change it.
|
|
17
|
+
*/
|
|
18
|
+
export async function ensureHome() {
|
|
19
|
+
const dir = home();
|
|
20
|
+
const created = await fs.mkdir(dir, { recursive: true });
|
|
21
|
+
if (created && dir !== userHome()) await fs.writeFile(join(dir, '.gitignore'), 'takes/\n');
|
|
22
|
+
return dir;
|
|
23
|
+
}
|
package/src/look.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
2
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
3
|
import { merge } from './edit.js';
|
|
4
|
+
import { ensureHome, home, userHome } from './home.js';
|
|
5
5
|
import { absolute, bundle, codeRefs, fileRefs } from './styles.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
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, the frame rate, the Shortcuts and the Narration's Lines. A
|
|
10
|
-
* it names, and is not validated.
|
|
8
|
+
* A Look is the part of an Edit that does not depend on one Take: everything except camera targets and scrolls,
|
|
9
|
+
* the address bar's url and its changes, where popups sit, the frame rate, the Shortcuts, the fast-forwards, the masks and the Narration's Lines. A
|
|
10
|
+
* Look sets only what it names, and is not validated.
|
|
11
11
|
*/
|
|
12
12
|
export const mergeLook = merge;
|
|
13
13
|
|
|
14
14
|
/** The Look an Edit carries. */
|
|
15
15
|
export function lookFromEdit(edit) {
|
|
16
|
-
const { schemaVersion, narration, shortcuts, output: { fps, ...output } = {}, frame, camera: { targets, ...camera } = {}, ...rest } = edit;
|
|
17
|
-
const { url, ...styling } = frame ?? {};
|
|
18
|
-
return { ...rest, output, frame: styling, camera };
|
|
16
|
+
const { schemaVersion, narration, shortcuts, fastForward, masks, output: { fps, ...output } = {}, frame, camera: { targets, scrolls, ...camera } = {}, tabs: { placement, ...tabs } = {}, ...rest } = edit;
|
|
17
|
+
const { url, urls, ...styling } = frame ?? {};
|
|
18
|
+
return { ...rest, output, frame: styling, camera, tabs };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The Edit with a Look adopted. Camera targets, the frame rate, the Shortcuts, the fast-forwards, the
|
|
23
|
+
* masks, the Lines and where popups sit stay; the address bar keeps its url and changes, else shows `host`.
|
|
24
|
+
*/
|
|
22
25
|
export function applyLook(edit, look, host) {
|
|
23
26
|
const next = merge(edit, look);
|
|
24
|
-
next.frame = { ...next.frame, url: edit.frame?.url ?? host };
|
|
27
|
+
next.frame = { ...next.frame, url: edit.frame?.url ?? host, ...(edit.frame?.urls && { urls: edit.frame.urls }) };
|
|
28
|
+
if (edit.tabs?.placement) next.tabs = { ...next.tabs, placement: edit.tabs.placement };
|
|
25
29
|
return next;
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -33,11 +37,11 @@ export function summarize(look) {
|
|
|
33
37
|
return parts.filter(Boolean).join(' · ') || Object.keys(look).join(', ') || 'empty';
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
/**
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
/** Looks live in the Home; a project Home's Looks come before the user Home's, which serve every project. */
|
|
41
|
+
const inProject = () => home() !== userHome();
|
|
42
|
+
const scopes = () => ({ ...(inProject() && { project: join(home(), 'looks') }), user: join(userHome(), 'looks') });
|
|
43
|
+
/** Where `look save` and `look rm` act: the user Home with --global, else the Home. */
|
|
44
|
+
const scopeFor = global => !global && inProject() ? 'project' : 'user';
|
|
41
45
|
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
42
46
|
function checkName(name) {
|
|
43
47
|
if (!NAME.test(name)) throw new Error('Use a short lowercase Look name, such as brand');
|
|
@@ -55,7 +59,7 @@ async function readSaved(dir, name) {
|
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
/**
|
|
58
|
-
* A Look by name,
|
|
62
|
+
* A Look by name, the project's before the user's, or from a JSON file labeled by its `name` or file name. `dir` is
|
|
59
63
|
* where its file refs resolve.
|
|
60
64
|
*/
|
|
61
65
|
export async function loadLook(ref, cwd = process.cwd()) {
|
|
@@ -65,27 +69,26 @@ export async function loadLook(ref, cwd = process.cwd()) {
|
|
|
65
69
|
return { name: String(name), dir: dirname(path), look };
|
|
66
70
|
}
|
|
67
71
|
checkName(ref);
|
|
68
|
-
for (const [scope, root] of Object.entries(scopes(
|
|
72
|
+
for (const [scope, root] of Object.entries(scopes())) {
|
|
69
73
|
const saved = await readSaved(root, ref);
|
|
70
74
|
if (saved) return { name: ref, scope, dir: saved.dir, look: saved.look };
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
throw new Error(`No Look named '${ref}' in ${local} or ${global}`);
|
|
76
|
+
throw new Error(`No Look named '${ref}' in ${Object.values(scopes()).join(' or ')}`);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
/** A Look's styling with its file refs made absolute, ready to merge with styling from elsewhere. */
|
|
77
80
|
export const resolvedLook = ({ look, dir }) => absolute(look, dir);
|
|
78
81
|
|
|
79
|
-
/** Every saved Look, with the code files it runs; a
|
|
80
|
-
export async function listLooks(
|
|
82
|
+
/** Every saved Look, with the code files it runs; a user Look hidden by a project one with the same name is marked shadowed. */
|
|
83
|
+
export async function listLooks() {
|
|
81
84
|
const found = [];
|
|
82
|
-
for (const [scope, root] of Object.entries(scopes(
|
|
85
|
+
for (const [scope, root] of Object.entries(scopes())) {
|
|
83
86
|
const entries = await fs.readdir(root, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
84
87
|
const names = entries.flatMap(e => e.isDirectory() ? [e.name] : e.name.endsWith('.json') ? [basename(e.name, '.json')] : []).sort();
|
|
85
88
|
for (const name of new Set(names)) {
|
|
86
89
|
const saved = await readSaved(root, name).catch(error => ({ error }));
|
|
87
90
|
if (!saved) continue;
|
|
88
|
-
const entry = { name, scope, shadowed: scope === '
|
|
91
|
+
const entry = { name, scope, shadowed: scope === 'user' && found.some(l => l.scope === 'project' && l.name === name), path: saved.path ?? join(root, name) };
|
|
89
92
|
if (saved.error) found.push({ ...entry, summary: `invalid: ${saved.error.message}` });
|
|
90
93
|
else found.push({ ...entry, summary: summarize(saved.look), code: codeRefs(absolute(saved.look, saved.dir)) });
|
|
91
94
|
}
|
|
@@ -94,12 +97,14 @@ export async function listLooks(cwd = process.cwd()) {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
/**
|
|
97
|
-
* Saves a Look
|
|
98
|
-
* files becomes a folder holding copies of them. An existing Look with the name is kept
|
|
100
|
+
* Saves a Look in the Home, or the user Home when `global`, with its file refs resolved against `from`. A
|
|
101
|
+
* Look that names files becomes a folder holding copies of them. An existing Look with the name is kept
|
|
102
|
+
* unless `replace`.
|
|
99
103
|
*/
|
|
100
|
-
export async function saveLook(name, look, { global = false, replace = false,
|
|
104
|
+
export async function saveLook(name, look, { global = false, replace = false, from = process.cwd() } = {}) {
|
|
101
105
|
checkName(name);
|
|
102
|
-
const scope = global
|
|
106
|
+
const scope = scopeFor(global), root = scopes()[scope];
|
|
107
|
+
if (scope === 'project') await ensureHome();
|
|
103
108
|
const existing = await readSaved(root, name);
|
|
104
109
|
if (existing && !replace) throw new Error(`A ${scope} Look named '${name}' already exists at ${existing.path}; pass --replace to overwrite it`);
|
|
105
110
|
await fs.rm(join(root, `${name}.json`), { force: true });
|
|
@@ -112,9 +117,9 @@ export async function saveLook(name, look, { global = false, replace = false, cw
|
|
|
112
117
|
return { name, scope, path, summary: summarize(saved), code: codeRefs(absolute(saved, dir)) };
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
/** The file or folder of every
|
|
116
|
-
export async function
|
|
117
|
-
const dir = scopes().
|
|
120
|
+
/** The file or folder of every Look in the user Home; other files in the folder are not CueTake's. */
|
|
121
|
+
export async function userLookFiles() {
|
|
122
|
+
const dir = scopes().user, paths = [];
|
|
118
123
|
const entries = await fs.readdir(dir, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
119
124
|
for (const entry of entries) {
|
|
120
125
|
const path = join(dir, entry.name);
|
|
@@ -124,9 +129,9 @@ export async function globalLookFiles() {
|
|
|
124
129
|
return { dir, paths: paths.sort() };
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
export async function removeLook(name, { global = false
|
|
132
|
+
export async function removeLook(name, { global = false } = {}) {
|
|
128
133
|
checkName(name);
|
|
129
|
-
const scope = global
|
|
134
|
+
const scope = scopeFor(global), root = scopes()[scope];
|
|
130
135
|
const saved = await readSaved(root, name);
|
|
131
136
|
if (!saved) throw new Error(`No ${scope} Look named '${name}' in ${root}`);
|
|
132
137
|
const removed = saved.path === join(root, `${name}.json`) ? saved.path : saved.dir;
|
package/src/mac-keys.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys the App Director presses, as macOS posts them. Pure, no imports.
|
|
3
|
+
*
|
|
4
|
+
* A Scenario names keys as Playwright does ('Meta+K', 'Enter', 'Shift+ArrowUp', 'ControlOrMeta+Z').
|
|
5
|
+
* Each names the virtual key code to post, by its place on an ANSI keyboard, the modifiers to hold, and
|
|
6
|
+
* the keydown a page would see for it, so the Timeline records the same Shortcut a page would.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// [macOS virtual key code, DOM key, DOM code] for the keys that are not a letter or digit.
|
|
10
|
+
const NAMED = {
|
|
11
|
+
Enter: [36, 'Enter', 'Enter'], Tab: [48, 'Tab', 'Tab'], Space: [49, ' ', 'Space'], Backspace: [51, 'Backspace', 'Backspace'],
|
|
12
|
+
Escape: [53, 'Escape', 'Escape'], Delete: [117, 'Delete', 'Delete'], Home: [115, 'Home', 'Home'], End: [119, 'End', 'End'],
|
|
13
|
+
PageUp: [116, 'PageUp', 'PageUp'], PageDown: [121, 'PageDown', 'PageDown'],
|
|
14
|
+
ArrowLeft: [123, 'ArrowLeft', 'ArrowLeft'], ArrowRight: [124, 'ArrowRight', 'ArrowRight'], ArrowDown: [125, 'ArrowDown', 'ArrowDown'], ArrowUp: [126, 'ArrowUp', 'ArrowUp'],
|
|
15
|
+
F1: [122, 'F1', 'F1'], F2: [120, 'F2', 'F2'], F3: [99, 'F3', 'F3'], F4: [118, 'F4', 'F4'], F5: [96, 'F5', 'F5'], F6: [97, 'F6', 'F6'],
|
|
16
|
+
F7: [98, 'F7', 'F7'], F8: [100, 'F8', 'F8'], F9: [101, 'F9', 'F9'], F10: [109, 'F10', 'F10'], F11: [103, 'F11', 'F11'], F12: [111, 'F12', 'F12'],
|
|
17
|
+
'-': [27, '-', 'Minus'], '=': [24, '=', 'Equal'], '[': [33, '[', 'BracketLeft'], ']': [30, ']', 'BracketRight'], '\\': [42, '\\', 'Backslash'],
|
|
18
|
+
';': [41, ';', 'Semicolon'], "'": [39, "'", 'Quote'], ',': [43, ',', 'Comma'], '.': [47, '.', 'Period'], '/': [44, '/', 'Slash'], '`': [50, '`', 'Backquote'],
|
|
19
|
+
};
|
|
20
|
+
const LETTERS = { A: 0, S: 1, D: 2, F: 3, H: 4, G: 5, Z: 6, X: 7, C: 8, V: 9, B: 11, Q: 12, W: 13, E: 14, R: 15, Y: 16, T: 17, O: 31, U: 32, I: 34, P: 35, L: 37, J: 38, K: 40, N: 45, M: 46 };
|
|
21
|
+
const DIGITS = { 1: 18, 2: 19, 3: 20, 4: 21, 6: 22, 5: 23, 9: 25, 7: 26, 8: 28, 0: 29 };
|
|
22
|
+
// Modifiers in macOS order, each with the keydown flag a page sees.
|
|
23
|
+
const MODIFIERS = [['Control', 'control', 'ctrlKey'], ['Alt', 'option', 'altKey'], ['Shift', 'shift', 'shiftKey'], ['Meta', 'command', 'metaKey']];
|
|
24
|
+
|
|
25
|
+
/** The key code and DOM key and code for one key name, or null. */
|
|
26
|
+
function keyOf(name) {
|
|
27
|
+
const letter = name.length === 1 ? name.toUpperCase() : /^Key[A-Z]$/.test(name) ? name.slice(3) : null;
|
|
28
|
+
if (letter in LETTERS) return [LETTERS[letter], letter.toLowerCase(), `Key${letter}`];
|
|
29
|
+
const digit = /^\d$/.test(name) ? name : /^Digit\d$/.test(name) ? name.slice(5) : null;
|
|
30
|
+
if (digit !== null) return [DIGITS[digit], digit, `Digit${digit}`];
|
|
31
|
+
return NAMED[name] ?? null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** `keys`, such as 'Meta+K', as `{ keyCode, modifiers, down }`: what to post, what to hold, and the keydown a page would see. */
|
|
35
|
+
export function macKeys(keys) {
|
|
36
|
+
// Every part before the last '+' is a modifier; the rest is the key.
|
|
37
|
+
const [, prefix, name] = String(keys).match(/^((?:[^+]+\+)*)(.*)$/);
|
|
38
|
+
const held = new Set(prefix.split('+').filter(Boolean).map(part => part === 'ControlOrMeta' ? 'Meta' : part));
|
|
39
|
+
for (const part of held) if (!MODIFIERS.some(([modifier]) => modifier === part)) throw new Error(`d.press does not know the modifier '${part}'; use Control, Alt, Shift, Meta or ControlOrMeta`);
|
|
40
|
+
const key = keyOf(name);
|
|
41
|
+
if (!key) throw new Error(`d.press does not know the key '${name}'; use names such as Enter, Escape, Tab, Space, ArrowUp, a letter or a digit, as in 'Meta+K'`);
|
|
42
|
+
const [keyCode, domKey, code] = key, on = MODIFIERS.filter(([modifier]) => held.has(modifier));
|
|
43
|
+
return {
|
|
44
|
+
keyCode, modifiers: on.map(([, mac]) => mac),
|
|
45
|
+
down: { key: domKey, code, ...Object.fromEntries(MODIFIERS.map(([modifier, , flag]) => [flag, held.has(modifier)])) },
|
|
46
|
+
};
|
|
47
|
+
}
|