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/edit.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { isPopup } from './tabs.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* An Edit holds every choice Render makes; a Scenario's config only seeds the first one. Styling is
|
|
@@ -13,16 +14,34 @@ export const evenSize = z.number().int().min(240).max(7680).refine(n => n % 2 ==
|
|
|
13
14
|
|
|
14
15
|
/** Times are seconds except clickEffect.duration, which is milliseconds; geometry is CSS pixels. */
|
|
15
16
|
export const DEFAULT_STYLE = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// The Cursor shrinks to `press` while a button is held; `false` turns that off. A click shows on the
|
|
18
|
+
// Cursor, so no click effect is drawn unless named.
|
|
19
|
+
cursor: { draw: 'arrow', size: 24, color: '#ffffff', press: 0.8 },
|
|
20
|
+
clickEffect: false,
|
|
21
|
+
// quality is the H.264 quantizer (lower is sharper and larger). shutter is the fraction of each
|
|
22
|
+
// frame over which the camera and the Cursor blur as they move (shutter.js); 0 turns blur off.
|
|
23
|
+
output: { width: 3840, height: 2160, quality: 22, shutter: 0.5 },
|
|
20
24
|
// padding is a fraction of the short side, one number or [top, right, bottom, left]; radius is in 1080p pixels.
|
|
21
25
|
frame: { padding: 0.08, radius: 12, chrome: { draw: 'browser' }, background: [{ shader: 'fluted' }], effects: [{ shader: 'shadow' }] },
|
|
22
26
|
// See camera.js. Each target is framed with `padding` CSS px around it, zooming at most `maxZoom`;
|
|
23
27
|
// fits below `minZoom` stay wide. The camera arrives `lead` before an action, holds `hold` after the
|
|
24
28
|
// last one in a segment, settles in about `response`, and returns wide `endWide` before the end.
|
|
25
29
|
camera: { maxZoom: 2, minZoom: 1.2, padding: 48, lead: 0.6, hold: 1.5, chainGap: 2, response: 0.6, follow: true, endWide: 1.5 },
|
|
30
|
+
// Shortcuts show as keycaps over the Final, outside the camera, for `duration` seconds after each
|
|
31
|
+
// press; presses of the same keys meanwhile count up. A key pressed without Control, Alt, Shift or
|
|
32
|
+
// Meta shows only with `singleKeys`. `false` shows none.
|
|
33
|
+
keycaps: { draw: 'keycaps', duration: 1.5, singleKeys: false },
|
|
34
|
+
// Drawn over the Final, outside the camera, while a Line is spoken; `burn: false` keeps them to the
|
|
35
|
+
// subtitle files. Rows hold up to `maxChars` (about 16 in Chinese, 42 otherwise), `maxRows` to a cue,
|
|
36
|
+
// each shown at least `minDuration`.
|
|
37
|
+
subtitles: { draw: 'subtitles', burn: true },
|
|
38
|
+
// Drawn over the Final, outside the camera, while it fast-forwards, such as { draw: 'fast-forward' };
|
|
39
|
+
// `false` shows none.
|
|
40
|
+
fastForwardBadge: false,
|
|
41
|
+
// How the Final shows the Tabs (tabs.js): the window cuts to a tab of its own size, or fades over
|
|
42
|
+
// `{ fade }` seconds; a popup window scales and fades in and out over `duration`, from `scale`, unless
|
|
43
|
+
// `popupAnimation` is false. Times are Final seconds.
|
|
44
|
+
tabs: { transition: 'cut', popupAnimation: { duration: 0.2, scale: 0.9 } },
|
|
26
45
|
};
|
|
27
46
|
|
|
28
47
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -40,35 +59,89 @@ export function merge(base, over) {
|
|
|
40
59
|
|
|
41
60
|
/** A complete Edit: the defaults under whatever `edit` names. */
|
|
42
61
|
export function withDefaults(edit) {
|
|
43
|
-
return merge({ schemaVersion: EDIT_VERSION, ...DEFAULT_STYLE, output: { ...DEFAULT_STYLE.output, fps: 60 }, camera: { ...DEFAULT_STYLE.camera, targets: [] } }, edit);
|
|
62
|
+
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);
|
|
44
63
|
}
|
|
45
64
|
|
|
65
|
+
// Seconds after a click within which the App's focus moving to what holds its target counts as the click's.
|
|
66
|
+
const FOCUS_AFTER_CLICK = 1;
|
|
67
|
+
|
|
46
68
|
/**
|
|
47
|
-
* Camera targets: observed clicks, typing and drags,
|
|
48
|
-
*
|
|
69
|
+
* Camera targets: observed clicks, typing and drags, and each element an App focused, each in the CSS
|
|
70
|
+
* pixels of its Tab, and each popup window's whole page as it first comes in front, except those
|
|
71
|
+
* inside a `wide` window ({ start, end } seconds) from an action with `focus: false`, and focus a click
|
|
72
|
+
* gave to what holds its target. Like a manual zoom in Screen Studio, an explicit focus
|
|
49
73
|
* target replaces only the automatic targets inside its own span (from `lead` before it to `hold` after).
|
|
50
74
|
*/
|
|
51
75
|
export function cameraTargets(timeline, focus, wide = [], camera = {}) {
|
|
52
76
|
const { lead, hold } = { ...DEFAULT_STYLE.camera, ...camera };
|
|
53
77
|
const spans = focus.map(f => ({ start: f.t - lead, end: (f.until ?? f.t) + hold }));
|
|
54
78
|
const inside = (t, windows) => windows.some(w => t >= w.start && t <= w.end);
|
|
79
|
+
const tabs = new Map((timeline.tabs ?? []).map(tab => [tab.id, tab])), framed = new Set();
|
|
80
|
+
// Focus a click gave to what holds its target, such as the text area around a link, adds only a larger box.
|
|
81
|
+
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;
|
|
82
|
+
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));
|
|
55
83
|
const automatic = timeline.events.filter(event => !inside(event.t, wide) && !inside(event.t, spans)).flatMap(event => {
|
|
56
|
-
|
|
57
|
-
if (event.type === '
|
|
84
|
+
const tab = event.tab === undefined ? {} : { tab: event.tab };
|
|
85
|
+
if (event.type === 'focused' && byClick(event)) return [];
|
|
86
|
+
if ((event.type === 'click' || event.type === 'focused') && event.box) return [{ t: event.t, box: event.box, ...tab }];
|
|
87
|
+
if (event.type === 'type' && event.box) return [{ t: event.t, box: event.box, until: event.end, ...tab }];
|
|
58
88
|
if (event.type === 'drag') {
|
|
59
89
|
const x = Math.min(event.from.x, event.to.x), y = Math.min(event.from.y, event.to.y);
|
|
60
|
-
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 }];
|
|
90
|
+
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 }];
|
|
91
|
+
}
|
|
92
|
+
const opened = tabs.get(event.tab);
|
|
93
|
+
if (event.type === 'front' && opened && isPopup(opened, timeline.viewport) && !framed.has(event.tab)) {
|
|
94
|
+
framed.add(event.tab);
|
|
95
|
+
return [{ t: event.t, box: { x: 0, y: 0, ...opened.viewport }, tab: event.tab }];
|
|
61
96
|
}
|
|
62
97
|
return [];
|
|
63
98
|
});
|
|
64
99
|
return [...automatic, ...focus].sort((a, b) => a.t - b.t);
|
|
65
100
|
}
|
|
66
101
|
|
|
102
|
+
/** What the address bar shows for a page address: its host, or the whole address when it has none. */
|
|
103
|
+
export function addressOf(url) {
|
|
104
|
+
try { const parsed = new URL(url); return /^https?:$/.test(parsed.protocol) ? parsed.host : url; } catch { return url; }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The address bar's text when Capture started (`url`), and each change after it (`urls`, as
|
|
109
|
+
* { t, url, tab } in Source time): a full navigation to another host shows the new one from the moment
|
|
110
|
+
* the page took its address. A Tab the demo opens shows the host it opened on, or nothing until its
|
|
111
|
+
* first document commits when it opened on about:blank. The Scenario's `frame.url`, when set, names
|
|
112
|
+
* the host Capture started on, also when a navigation comes back to it.
|
|
113
|
+
*/
|
|
114
|
+
export function addressBar(config, timeline) {
|
|
115
|
+
const first = addressOf(timeline.url ?? config.url), shown = host => host === first ? config.frame?.url ?? first : host;
|
|
116
|
+
const urls = [], current = new Map([[0, first]]);
|
|
117
|
+
const change = (t, url, tab) => {
|
|
118
|
+
const host = !url || url === 'about:blank' ? '' : addressOf(url);
|
|
119
|
+
if (host !== (current.get(tab) ?? '')) urls.push({ t, url: shown(host), tab });
|
|
120
|
+
current.set(tab, host);
|
|
121
|
+
};
|
|
122
|
+
const opened = (timeline.tabs ?? []).slice(1).map(tab => ({ t: tab.opened, url: tab.url, tab: tab.id }));
|
|
123
|
+
const committed = (timeline.events ?? []).filter(event => event.type === 'navigate' && event.commit !== undefined).map(event => ({ t: event.commit, url: event.url, tab: event.tab ?? 0 }));
|
|
124
|
+
for (const { t, url, tab } of [...opened, ...committed].sort((a, b) => a.t - b.t)) change(t, url, tab);
|
|
125
|
+
return { url: shown(first), urls };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The first Edit of a Take. Each Line starts where the Scenario said it (`d.say`); its text, audio and
|
|
130
|
+
* word timings stay in the Take's Narration, since they change only with new audio. The Shortcuts the
|
|
131
|
+
* Timeline recorded are the ones shown, so one can be relabeled or removed without recording again, and
|
|
132
|
+
* so are the waits the Scenario fast-forwarded (`d.fastForward`), so one can be retimed (time-map.js),
|
|
133
|
+
* and the elements it masked (`d.mask`), so a mask can be retimed, restyled or removed (masks.js).
|
|
134
|
+
*/
|
|
67
135
|
export function createEdit(config, timeline, focus, wide = []) {
|
|
68
136
|
return withDefaults({
|
|
69
|
-
cursor: config.cursor, clickEffect: config.clickEffect, output: { ...config.output, fps: config.capture.fps },
|
|
70
|
-
// The browser chrome shows the
|
|
71
|
-
|
|
72
|
-
|
|
137
|
+
cursor: config.cursor, clickEffect: config.clickEffect, keycaps: config.keycaps, subtitles: config.subtitles, fastForwardBadge: config.fastForwardBadge, output: { ...config.output, fps: config.capture.fps },
|
|
138
|
+
// The browser chrome shows the host the page is on, unless the config names something else. A Take
|
|
139
|
+
// of Apps shows the App's own windows, without chrome, unless the config names one (ADR 0009).
|
|
140
|
+
frame: config.app ? { chrome: false, ...config.frame } : { ...config.frame, ...addressBar(config, timeline) },
|
|
141
|
+
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,
|
|
142
|
+
shortcuts: timeline.events.filter(event => event.type === 'shortcut').map(({ t, keys }) => ({ t, keys })),
|
|
143
|
+
fastForward: timeline.events.filter(event => event.type === 'fastForward').map(({ t, end, rate }) => ({ start: t, end, rate })),
|
|
144
|
+
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 })),
|
|
145
|
+
narration: { lines: timeline.events.filter(event => event.type === 'say').map(event => ({ id: event.id, start: event.t })) },
|
|
73
146
|
});
|
|
74
147
|
}
|
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,23 +19,66 @@ 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 };
|
|
22
29
|
}
|
|
23
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
|
+
|
|
24
34
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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.
|
|
27
38
|
*/
|
|
28
|
-
|
|
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.' }) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function playwright(args) {
|
|
29
57
|
const cli = join(dirname(createRequire(import.meta.url).resolve('playwright/package.json')), 'cli.js');
|
|
30
58
|
return new Promise((resolve, reject) => {
|
|
31
59
|
// Progress goes to stderr so stdout stays the JSON result.
|
|
32
|
-
const child = spawn(process.execPath, [cli,
|
|
60
|
+
const child = spawn(process.execPath, [cli, ...args], { stdio: ['ignore', 2, 2] });
|
|
33
61
|
child.on('error', reject);
|
|
34
|
-
child.on('close', code => code === 0 ? resolve(
|
|
62
|
+
child.on('close', code => code === 0 ? resolve() : reject(new Error(`playwright ${args[0]} exited with ${code}`)));
|
|
35
63
|
});
|
|
36
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Downloads the Chromium build that CueTake's own Playwright version drives. Running
|
|
68
|
+
* `npx playwright install` instead may resolve a newer Playwright and fetch a build CueTake never uses.
|
|
69
|
+
*/
|
|
70
|
+
export async function installBrowser() {
|
|
71
|
+
await playwright(['install', 'chromium', '--no-shell']);
|
|
72
|
+
return { installed: true, path: chromium.executablePath() };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Unregisters CueTake's Playwright from the shared browser cache, which deletes each browser no other
|
|
77
|
+
* Playwright installation still uses. Browsers other tools need stay.
|
|
78
|
+
*/
|
|
79
|
+
export async function uninstallBrowser({ dryRun = false } = {}) {
|
|
80
|
+
const path = chromium.executablePath(), exists = () => fs.access(path).then(() => true, () => false);
|
|
81
|
+
const existed = await exists();
|
|
82
|
+
if (existed && !dryRun) await playwright(['uninstall']);
|
|
83
|
+
return { path, existed, removed: existed && !dryRun && !await exists() };
|
|
84
|
+
}
|
|
@@ -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/look.js
CHANGED
|
@@ -5,22 +5,27 @@ import { merge } from './edit.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 and the frame rate
|
|
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.
|
|
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 { url, ...styling } = frame ?? {};
|
|
17
|
-
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 };
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
/**
|
|
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
|
+
*/
|
|
21
25
|
export function applyLook(edit, look, host) {
|
|
22
26
|
const next = merge(edit, look);
|
|
23
|
-
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 };
|
|
24
29
|
return next;
|
|
25
30
|
}
|
|
26
31
|
|
|
@@ -37,8 +42,9 @@ const scopes = (cwd = process.cwd()) => ({
|
|
|
37
42
|
local: join(cwd, '.cuetake', 'looks'),
|
|
38
43
|
global: process.env.CUETAKE_LOOK_DIR || join(homedir(), '.local/share/cuetake/looks'),
|
|
39
44
|
});
|
|
45
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
40
46
|
function checkName(name) {
|
|
41
|
-
if (
|
|
47
|
+
if (!NAME.test(name)) throw new Error('Use a short lowercase Look name, such as brand');
|
|
42
48
|
}
|
|
43
49
|
const readIfPresent = path => fs.readFile(path, 'utf8').catch(error => { if (['ENOENT', 'ENOTDIR'].includes(error.code)) return null; throw error; });
|
|
44
50
|
const parse = (text, path) => { try { return JSON.parse(text); } catch (error) { throw new Error(`${path} is not JSON: ${error.message}`); } };
|
|
@@ -110,6 +116,18 @@ export async function saveLook(name, look, { global = false, replace = false, cw
|
|
|
110
116
|
return { name, scope, path, summary: summarize(saved), code: codeRefs(absolute(saved, dir)) };
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
/** The file or folder of every global Look; other files in the folder are not CueTake's. */
|
|
120
|
+
export async function globalLookFiles() {
|
|
121
|
+
const dir = scopes().global, paths = [];
|
|
122
|
+
const entries = await fs.readdir(dir, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
const path = join(dir, entry.name);
|
|
125
|
+
if (entry.isFile() && entry.name.endsWith('.json') && NAME.test(basename(entry.name, '.json'))) paths.push(path);
|
|
126
|
+
else if (entry.isDirectory() && NAME.test(entry.name) && await readIfPresent(join(path, 'look.json')) !== null) paths.push(path);
|
|
127
|
+
}
|
|
128
|
+
return { dir, paths: paths.sort() };
|
|
129
|
+
}
|
|
130
|
+
|
|
113
131
|
export async function removeLook(name, { global = false, cwd } = {}) {
|
|
114
132
|
checkName(name);
|
|
115
133
|
const scope = global ? 'global' : 'local', root = scopes(cwd)[scope];
|
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
|
+
}
|
package/src/masks.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masks, shared by Node and the render page. Pure functions, no imports.
|
|
3
|
+
*
|
|
4
|
+
* A Mask hides or points at a region of a Tab's page for a span of the Take: `blur` blurs it past
|
|
5
|
+
* reading, `cover` fills it with a solid color, and `spotlight` dims everything outside it. A mask
|
|
6
|
+
* names either a fixed `box` in its Tab's CSS pixels, or an `element`: one of the Timeline's
|
|
7
|
+
* `elements`, whose boxes Capture recorded over time. Its `start` and `end` are Source seconds; without
|
|
8
|
+
* them it runs from the start or to the end of the Take. Masks sit on the page under the camera.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Each effect's parameters: `padding`, `radius` (corner), `blur` and `feather` (how far the light
|
|
13
|
+
* falls off across the region's edge) in CSS px; `color` as '#rrggbb'; `dim`, the share of light taken
|
|
14
|
+
* from the rest of the frame; `ease` in Final seconds.
|
|
15
|
+
*/
|
|
16
|
+
export const MASK_EFFECTS = {
|
|
17
|
+
blur: { blur: 16, padding: 4, radius: 6 },
|
|
18
|
+
cover: { color: '#000000', padding: 4, radius: 6 },
|
|
19
|
+
spotlight: { dim: 0.6, padding: 8, radius: 10, feather: 16, ease: 0.3 },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** The effects, as messages list them: "blur, cover or spotlight". */
|
|
23
|
+
export const EFFECT_NAMES = Object.keys(MASK_EFFECTS).join(', ').replace(/, (\w+)$/, ' or $1');
|
|
24
|
+
|
|
25
|
+
// Seconds before and after a moment whose boxes a blur or cover also hides. Tab capture shows a
|
|
26
|
+
// change tens of milliseconds after the page made it, more on a busy machine, so the Source can still
|
|
27
|
+
// show an element where it was after its box has moved. Capture sees an element the page replaced
|
|
28
|
+
// elsewhere, or one in a new document, only when the Director next watches it (director.js).
|
|
29
|
+
const SLACK = { before: 0.2, after: 0.25 };
|
|
30
|
+
|
|
31
|
+
/** Below this many CSS px, a blur leaves body text readable. */
|
|
32
|
+
const LEAST_BLUR = 8;
|
|
33
|
+
|
|
34
|
+
const isColor = value => typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value);
|
|
35
|
+
const isBox = box => box && ['x', 'y', 'width', 'height'].every(key => typeof box[key] === 'number' && Number.isFinite(box[key])) && box.width > 0 && box.height > 0;
|
|
36
|
+
|
|
37
|
+
/** A mask as messages name it, such as "Mask 2 (blur from 1.20 s)". */
|
|
38
|
+
const nameOf = (mask, i) => `Mask ${i} (${mask.effect}${typeof mask.start === 'number' ? ` from ${mask.start.toFixed(2)} s` : ''})`;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* What stops Render from masking as the Edit asks, each naming its mask: an unknown effect, a mask
|
|
42
|
+
* with neither or both of a box and an element the Timeline recorded (`elements`), a box on a Tab the
|
|
43
|
+
* Take does not show (`tabs`, their ids, when given), an empty span, a color that is not '#rrggbb', or
|
|
44
|
+
* a blur too weak to hide text. A mask Render cannot draw would show what it hides, so any of these stops it.
|
|
45
|
+
*/
|
|
46
|
+
export function maskProblems(masks = [], elements = [], tabs = null) {
|
|
47
|
+
if (!Array.isArray(masks)) return ['masks must be a list of masks'];
|
|
48
|
+
const ids = new Set(elements.map(element => element.id));
|
|
49
|
+
return masks.flatMap((mask, i) => {
|
|
50
|
+
if (!(mask?.effect in MASK_EFFECTS)) return [`Mask ${i} has effect '${mask?.effect}'; use ${EFFECT_NAMES}`];
|
|
51
|
+
const name = nameOf(mask, i), problems = [];
|
|
52
|
+
if (mask.element !== undefined && mask.box !== undefined) problems.push(`${name} names both a box and an element; keep one`);
|
|
53
|
+
else if (mask.element !== undefined) { if (!ids.has(mask.element)) problems.push(`${name} follows element ${mask.element}, which the Timeline does not record`); }
|
|
54
|
+
else if (!isBox(mask.box)) problems.push(`${name} needs a box { x, y, width, height } in CSS pixels, or the element a Scenario masked`);
|
|
55
|
+
else if (tabs && !tabs.includes(mask.tab ?? 0)) problems.push(`${name} is on Tab ${mask.tab}, which the Take does not show; its Tabs are ${tabs.join(', ')}`);
|
|
56
|
+
if (mask.color !== undefined && !isColor(mask.color)) problems.push(`${name} has color '${mask.color}'; use '#rrggbb'`);
|
|
57
|
+
const { start = 0, end = Infinity } = mask;
|
|
58
|
+
if (!(typeof start === 'number' && typeof end === 'number' && end > start)) problems.push(`${name} needs a start before its end, in seconds`);
|
|
59
|
+
const blur = mask.blur ?? MASK_EFFECTS.blur.blur;
|
|
60
|
+
if (mask.effect === 'blur' && !(blur >= LEAST_BLUR)) problems.push(`${name} blurs ${blur} CSS px, too little to hide text; use at least ${LEAST_BLUR}`);
|
|
61
|
+
return problems;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const padded = ({ x, y, width, height }, p) => ({ x: x - p, y: y - p, width: width + 2 * p, height: height + 2 * p });
|
|
66
|
+
const rectOf = ([x, y, width, height]) => ({ x, y, width, height });
|
|
67
|
+
|
|
68
|
+
/** The index of the last sample at or before Source time `s`, or the first: a box holds until the next one, and back to the start. */
|
|
69
|
+
function heldAt(boxes, s) {
|
|
70
|
+
let low = 0, high = boxes.length - 1, found = 0;
|
|
71
|
+
while (low <= high) { const mid = (low + high) >> 1; if (boxes[mid][0] <= s) { found = mid; low = mid + 1; } else high = mid - 1; }
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* An element's boxes at Source time `s`, as rects: those it held then, or with `slack`, every box it
|
|
77
|
+
* held from `slack.before` seconds before to `slack.after` after. A sample `[t, ...boxes]` lists each
|
|
78
|
+
* element the locator matched, as [x, y, width, height]; one without boxes means none showed.
|
|
79
|
+
*/
|
|
80
|
+
export function elementBoxesAt(boxes, s, slack = { before: 0, after: 0 }) {
|
|
81
|
+
if (!boxes?.length) return [];
|
|
82
|
+
const from = heldAt(boxes, s - slack.before), to = heldAt(boxes, s + slack.after), seen = new Set(), rects = [];
|
|
83
|
+
for (const sample of boxes.slice(from, to + 1)) for (const box of sample.slice(1)) {
|
|
84
|
+
const key = box.join();
|
|
85
|
+
if (!seen.has(key)) { seen.add(key); rects.push(rectOf(box)); }
|
|
86
|
+
}
|
|
87
|
+
return rects;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The masks through the Final: `at(t)` lists those showing at Final time `t`, each with its index in
|
|
92
|
+
* `masks`, its Tab, its effect and parameters, its `opacity` and its `rects`, padded, in its Tab's CSS
|
|
93
|
+
* pixels. `map` is the Take's time map (time-map.js).
|
|
94
|
+
*/
|
|
95
|
+
export function maskTrack(masks = [], elements = [], map) {
|
|
96
|
+
const byId = new Map(elements.map(element => [element.id, element]));
|
|
97
|
+
const placed = masks.map((mask, index) => {
|
|
98
|
+
const { effect, box, element: id, start = 0, end = Infinity, tab = 0, ...rest } = mask;
|
|
99
|
+
const params = { ...MASK_EFFECTS[effect], ...rest }, element = byId.get(id), slack = effect === 'spotlight' ? undefined : SLACK;
|
|
100
|
+
const rects = element ? s => elementBoxesAt(element.boxes, s, slack) : () => [box];
|
|
101
|
+
return { index, tab: element ? element.tab : tab, effect, params, from: map.outputAt(start), until: end === Infinity ? map.duration : map.outputAt(end), rects };
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
at(t) {
|
|
105
|
+
const s = map.sourceAt(t);
|
|
106
|
+
// A spotlight eases in after its start and out before its end, in Final time; a blur or cover is whole at once.
|
|
107
|
+
const opacity = ({ effect, params: { ease }, from, until }) => effect !== 'spotlight' || !(ease > 0) ? 1 : Math.max(0, Math.min(1, (t - from) / ease, (until - t) / ease));
|
|
108
|
+
return placed.filter(mask => t >= mask.from && t < mask.until).map(({ index, tab, effect, params, rects, ...mask }) => ({
|
|
109
|
+
index, tab, effect, opacity: opacity({ effect, params, ...mask }), rects: rects(s).map(r => padded(r, params.padding)), ...params,
|
|
110
|
+
})).filter(mask => mask.rects.length);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* At most `n` of `items` (each `{ rect, ... }`), the rest merged: past `n`, they become one item, the
|
|
117
|
+
* first of them with a rect around them all, so a box that does not fit one pass is hidden more widely, never shown.
|
|
118
|
+
*/
|
|
119
|
+
export function mergedPast(items, n) {
|
|
120
|
+
if (items.length <= n) return items;
|
|
121
|
+
const rest = items.slice(n - 1);
|
|
122
|
+
const left = Math.min(...rest.map(({ rect }) => rect.x)), top = Math.min(...rest.map(({ rect }) => rect.y));
|
|
123
|
+
const right = Math.max(...rest.map(({ rect }) => rect.x + rect.width)), bottom = Math.max(...rest.map(({ rect }) => rect.y + rect.height));
|
|
124
|
+
return [...items.slice(0, n - 1), { ...rest[0], rect: { x: left, y: top, width: right - left, height: bottom - top } }];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Warnings for masks that drew nothing: each that follows an element its locator never matched on the
|
|
129
|
+
* page during its span, which usually means a locator that misses or a span before the element shows.
|
|
130
|
+
*/
|
|
131
|
+
export function maskWarnings(masks = [], elements = []) {
|
|
132
|
+
const byId = new Map(elements.map(element => [element.id, element]));
|
|
133
|
+
return masks.flatMap((mask, i) => {
|
|
134
|
+
const element = byId.get(mask.element);
|
|
135
|
+
if (!element) return [];
|
|
136
|
+
const { start = 0, end = Infinity } = mask, { boxes } = element;
|
|
137
|
+
const seen = boxes.length && (boxes[heldAt(boxes, start)].length > 1 || boxes.some(([t, ...shown]) => t > start && t < end && shown.length));
|
|
138
|
+
return seen ? [] : [`${nameOf(mask, i)} found no ${element.name} on the page during its span, so it drew nothing; check the locator, or when the element shows`];
|
|
139
|
+
});
|
|
140
|
+
}
|