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/render.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
3
|
+
import { basename, dirname, extname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { chromium } from 'playwright';
|
|
6
6
|
import { contentType } from './styles.js';
|
|
@@ -20,6 +20,13 @@ const pageFiles = {
|
|
|
20
20
|
'/camera.js': { path: fileURLToPath(new URL('./camera.js', import.meta.url)), type: 'text/javascript' },
|
|
21
21
|
'/cursor.js': { path: fileURLToPath(new URL('./cursor.js', import.meta.url)), type: 'text/javascript' },
|
|
22
22
|
'/stage.js': { path: fileURLToPath(new URL('./stage.js', import.meta.url)), type: 'text/javascript' },
|
|
23
|
+
'/narration.js': { path: fileURLToPath(new URL('./narration.js', import.meta.url)), type: 'text/javascript' },
|
|
24
|
+
'/shortcuts.js': { path: fileURLToPath(new URL('./shortcuts.js', import.meta.url)), type: 'text/javascript' },
|
|
25
|
+
'/time-map.js': { path: fileURLToPath(new URL('./time-map.js', import.meta.url)), type: 'text/javascript' },
|
|
26
|
+
'/tabs.js': { path: fileURLToPath(new URL('./tabs.js', import.meta.url)), type: 'text/javascript' },
|
|
27
|
+
'/shutter.js': { path: fileURLToPath(new URL('./shutter.js', import.meta.url)), type: 'text/javascript' },
|
|
28
|
+
'/masks.js': { path: fileURLToPath(new URL('./masks.js', import.meta.url)), type: 'text/javascript' },
|
|
29
|
+
'/desktop.js': { path: fileURLToPath(new URL('./desktop.js', import.meta.url)), type: 'text/javascript' },
|
|
23
30
|
'/mediabunny.js': { path: mediabunnyBundle, type: 'text/javascript' },
|
|
24
31
|
};
|
|
25
32
|
|
|
@@ -62,12 +69,18 @@ async function withRenderPage({ files = {}, writable = {} }, task) {
|
|
|
62
69
|
});
|
|
63
70
|
await page.goto(`${ORIGIN}/render.html`);
|
|
64
71
|
await page.waitForFunction(() => window.cuetakeRender, null, { timeout: 15_000 }).catch(() => { throw new Error(`Render page failed to load: ${errors.join('; ')}`); });
|
|
65
|
-
const result = await task(page).catch(error => { throw offline(error, blocked); });
|
|
72
|
+
const result = await task(page).catch(error => { throw offline(fromPage(error), blocked); });
|
|
66
73
|
if (blocked.length) throw offline(null, blocked);
|
|
67
74
|
return result;
|
|
68
75
|
} finally { await browser.close(); }
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
/** An error thrown in the render page, without Playwright's prefix and the page's stack. */
|
|
79
|
+
function fromPage(error) {
|
|
80
|
+
const message = error.message.replace(/^page\.evaluate: (Error: )?/, '').split(/\n\s+at /)[0];
|
|
81
|
+
return message === error.message ? error : new Error(message);
|
|
82
|
+
}
|
|
83
|
+
|
|
71
84
|
/** Names what styling code tried to fetch, which the render page cannot. */
|
|
72
85
|
function offline(error, blocked) {
|
|
73
86
|
if (!blocked.length) return error;
|
|
@@ -75,29 +88,71 @@ function offline(error, blocked) {
|
|
|
75
88
|
return new Error(error ? `${error.message}\n${note}` : note);
|
|
76
89
|
}
|
|
77
90
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Lines as the render page reads them, `{ id, audio, url, ... }`, with their audio served from `files`.
|
|
93
|
+
* Each Line is `{ id, path, ... }`, `path` being its audio file.
|
|
94
|
+
*/
|
|
95
|
+
function servedLines(lines, files) {
|
|
96
|
+
return lines.map(({ path, ...line }, i) => {
|
|
97
|
+
const name = `line-${i}${extname(path)}`;
|
|
98
|
+
files[name] = path;
|
|
99
|
+
return { ...line, audio: basename(path), url: `${ORIGIN}/files/${name}` };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The Timeline as the render page reads it, with each Tab's Source (`sources`, paths by Tab id) served
|
|
105
|
+
* from `files`. A Timeline without Tabs has one, the first, the viewport's size. A Take of Apps has
|
|
106
|
+
* `windows`, which show over its Desktop (desktop.js).
|
|
107
|
+
*/
|
|
108
|
+
function forPage(timeline, sources, files) {
|
|
109
|
+
const tabs = timeline.tabs ?? [{ id: 0, opener: null, opened: 0, closed: null, viewport: timeline.viewport, start: 0 }];
|
|
110
|
+
for (const tab of tabs) files[`source-${tab.id}`] = sources[tab.id];
|
|
111
|
+
return {
|
|
112
|
+
duration: timeline.duration, viewport: timeline.viewport, tabs,
|
|
113
|
+
pointer: timeline.pointer ?? [], shapes: timeline.shapes ?? [], events: timeline.events ?? [], elements: timeline.elements ?? [], windows: timeline.windows ?? null,
|
|
114
|
+
sources: tabs.map(tab => ({ tab: tab.id, url: `${ORIGIN}/files/source-${tab.id}` })),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Composes the Final from each Tab's Source (`sources`, paths by Tab id), the Timeline and the Edit;
|
|
120
|
+
* `files` serves the Edit's styling files (styles.js forRender). `narration` ({ language, volume, lines })
|
|
121
|
+
* adds its Lines' audio and Subtitles.
|
|
122
|
+
*/
|
|
123
|
+
export async function renderFinal({ sources, finalPath, timeline, edit, files = {}, narration = null }) {
|
|
80
124
|
const handle = await fs.open(finalPath, 'w');
|
|
125
|
+
const served = { ...files };
|
|
126
|
+
const spoken = narration && { ...narration, lines: servedLines(narration.lines, served) };
|
|
127
|
+
const take = forPage(timeline, sources, served);
|
|
81
128
|
try {
|
|
82
|
-
return await withRenderPage({ files:
|
|
83
|
-
|
|
84
|
-
viewport: timeline.viewport, pointer: timeline.pointer ?? [], events: timeline.events ?? [], edit,
|
|
129
|
+
return await withRenderPage({ files: served, writable: { final: handle } }, page => page.evaluate(options => window.cuetakeRender(options), {
|
|
130
|
+
...take, finalUrl: `${ORIGIN}/files/final`, edit, narration: spoken,
|
|
85
131
|
}));
|
|
86
132
|
} finally { await handle.close(); }
|
|
87
133
|
}
|
|
88
134
|
|
|
89
135
|
/** A Preview PNG of `tiles` ([{ name, edit }]) at `at` seconds, or at the end with the camera wide. No Final is touched. */
|
|
90
|
-
export async function composePreview({
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}));
|
|
136
|
+
export async function composePreview({ sources, timeline, tiles, at, files = {}, narration = null }) {
|
|
137
|
+
const served = { ...files };
|
|
138
|
+
const spoken = narration && { ...narration, lines: servedLines(narration.lines, served) };
|
|
139
|
+
const take = forPage(timeline, sources, served);
|
|
140
|
+
const png = await withRenderPage({ files: served }, page => page.evaluate(options => window.cuetakePreview(options), { ...take, tiles, at: at ?? null, narration: spoken }));
|
|
95
141
|
return Buffer.from(png, 'base64');
|
|
96
142
|
}
|
|
97
143
|
|
|
98
|
-
/** Container metadata of a Final plus a full decode. */
|
|
99
|
-
export function inspectFinal(path) {
|
|
100
|
-
|
|
144
|
+
/** Container metadata of a Final plus a full decode of its video and audio, and of each Line's audio (`lines`: [{ id, path }]). */
|
|
145
|
+
export function inspectFinal(path, lines = []) {
|
|
146
|
+
const files = { final: path };
|
|
147
|
+
const served = servedLines(lines, files);
|
|
148
|
+
return withRenderPage({ files }, page => page.evaluate(([url, lines]) => window.cuetakeInspect(url, lines), [`${ORIGIN}/files/final`, served]));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Each Line's audio duration in seconds (`lines`: [{ id, path }]); the error names a Line whose audio cannot be decoded. */
|
|
152
|
+
export function measureLines(lines) {
|
|
153
|
+
const files = {};
|
|
154
|
+
const served = servedLines(lines, files);
|
|
155
|
+
return withRenderPage({ files }, page => page.evaluate(lines => window.cuetakeMeasure(lines), served));
|
|
101
156
|
}
|
|
102
157
|
|
|
103
158
|
/** A PNG of the Final at `seconds`, for agents to look at without FFmpeg. */
|
package/src/shortcuts.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shortcuts and their keycaps, shared by Node and the render page. Pure functions, no imports; seconds throughout.
|
|
3
|
+
*
|
|
4
|
+
* A Shortcut is a key pressed outside a text field, or with Control, Alt or Meta held inside one: typing
|
|
5
|
+
* into a field already shows on the page, a shortcut does not. Its `keys` are the held modifiers in
|
|
6
|
+
* macOS order (Control, Alt, Shift, Meta), then the key, named as the DOM names it (`K`, `Enter`,
|
|
7
|
+
* `ArrowUp`, `Space`), so the same press reads the same on every keyboard layout Playwright plays.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const MODIFIERS = [['ctrlKey', 'Control'], ['altKey', 'Alt'], ['shiftKey', 'Shift'], ['metaKey', 'Meta']];
|
|
11
|
+
// Keys that only change another key, or carry no key of their own.
|
|
12
|
+
const NOT_SHOWN = new Set(['Control', 'Alt', 'Shift', 'Meta', 'AltGraph', 'CapsLock', 'Fn', 'FnLock', 'Hyper', 'Super', 'Symbol', 'SymbolLock', 'OS', 'Process', 'Dead', 'Unidentified', '']);
|
|
13
|
+
const FADE_IN = 0.12, FADE_OUT = 0.25; // seconds keycaps take to appear and to go
|
|
14
|
+
const RISE = 12; // 1080p pixels keycaps rise as they appear
|
|
15
|
+
|
|
16
|
+
/** The key a keydown names: a letter or digit by its place on the keyboard, so held modifiers do not change it. */
|
|
17
|
+
function keyName({ key, code = '' }) {
|
|
18
|
+
if (/^Key[A-Z]$/.test(code)) return code.slice(3);
|
|
19
|
+
if (/^Digit\d$/.test(code)) return code.slice(5);
|
|
20
|
+
if (key === ' ') return 'Space';
|
|
21
|
+
return key?.length === 1 ? key.toUpperCase() : key;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The keys a keydown shows, or null for one that is typing, a modifier on its own or the key repeating.
|
|
26
|
+
* `down` holds the event's `key`, `code`, modifier flags and `repeat`, and `field`: whether a text field had focus.
|
|
27
|
+
*/
|
|
28
|
+
export function shortcutKeys(down) {
|
|
29
|
+
const key = keyName(down);
|
|
30
|
+
if (down.repeat || NOT_SHOWN.has(key ?? '')) return null;
|
|
31
|
+
if (down.field && !down.ctrlKey && !down.altKey && !down.metaKey) return null;
|
|
32
|
+
return [...MODIFIERS.filter(([flag]) => down[flag]).map(([, name]) => name), key];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sameKeys = (a, b) => a.length === b.length && a.every((key, i) => key === b[i]);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* When each Shortcut's keycaps show: from its press until `duration` after, joined by later presses of
|
|
39
|
+
* the same keys while it shows, which count up. A new Shortcut replaces the one showing at once, without fading.
|
|
40
|
+
*/
|
|
41
|
+
export function keycapShows(shortcuts, duration) {
|
|
42
|
+
const shows = [];
|
|
43
|
+
for (const { t, keys } of shortcuts.toSorted((a, b) => a.t - b.t)) {
|
|
44
|
+
const last = shows.at(-1);
|
|
45
|
+
if (last && t < last.end && sameKeys(last.keys, keys)) { last.presses.push(t); last.end = t + duration; continue; }
|
|
46
|
+
const replacing = Boolean(last && t < last.end);
|
|
47
|
+
if (replacing) { last.end = t; last.replaced = true; }
|
|
48
|
+
shows.push({ t, end: t + duration, keys, presses: [t], replacing, replaced: false });
|
|
49
|
+
}
|
|
50
|
+
return shows;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const easeOut = u => 1 - (1 - u) ** 3;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The keycaps through a Take: `at(t)` gives the index of the show on screen, its keys, how many times
|
|
57
|
+
* they have been pressed, its opacity and how far below its place it is (1080p pixels), or null.
|
|
58
|
+
* `keycaps` is the Edit's keycaps item; `false` shows none, and a key pressed alone shows only with `singleKeys`.
|
|
59
|
+
*/
|
|
60
|
+
export function keycapTrack(shortcuts, keycaps) {
|
|
61
|
+
const shown = (shortcuts ?? []).filter(shortcut => keycaps?.singleKeys || shortcut.keys.length > 1);
|
|
62
|
+
const shows = keycaps ? keycapShows(shown, keycaps.duration ?? 1.5) : [];
|
|
63
|
+
return {
|
|
64
|
+
shows,
|
|
65
|
+
at(t) {
|
|
66
|
+
const index = shows.findIndex(show => t >= show.t && t < show.end);
|
|
67
|
+
if (index < 0) return null;
|
|
68
|
+
const show = shows[index], appear = show.replacing ? 1 : Math.min(1, (t - show.t) / FADE_IN);
|
|
69
|
+
const leave = show.replaced ? 1 : Math.min(1, (show.end - t) / FADE_OUT);
|
|
70
|
+
return { index, keys: show.keys, count: show.presses.filter(p => p <= t).length, opacity: Math.max(0, Math.min(appear, leave)), rise: RISE * (1 - easeOut(appear)) };
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
package/src/shutter.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion blur, shared by Node and the render page. Pure functions, no imports.
|
|
3
|
+
*
|
|
4
|
+
* Each output frame of the Final is exposed over the last `shutter` of its time, a fraction of a frame
|
|
5
|
+
* like a film camera's shutter: Render composes the moving parts of the frame at several moments of
|
|
6
|
+
* that exposure and averages them. Times are Final seconds.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The shutter Render uses for the Edit's `output.shutter`: between 0 and 1, and 0 for anything that is not a number. */
|
|
10
|
+
export const shutterOf = shutter => typeof shutter === 'number' && shutter > 0 ? Math.min(1, shutter) : 0;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The exposure of the frame at Final time `t`, as { start, end }, or null where the frame shows one
|
|
14
|
+
* sharp instant: with no shutter, on the first frame, and on a frame the camera cuts on, since `cuts`
|
|
15
|
+
* jump the camera and the Tab shown.
|
|
16
|
+
*/
|
|
17
|
+
export function exposure(t, fps, shutter, cuts = []) {
|
|
18
|
+
const frame = 1 / fps;
|
|
19
|
+
if (!shutterOf(shutter) || t < frame - 1e-9 || cuts.some(cut => cut > t - frame + 1e-9 && cut <= t + 1e-9)) return null;
|
|
20
|
+
return { start: t - shutterOf(shutter) * frame, end: t };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The camera's crop at Final time `t`, part way between the crops of the frames on either side (`crops` has one per frame). */
|
|
24
|
+
export function cropAt(crops, fps, t) {
|
|
25
|
+
const at = Math.max(0, Math.min(crops.length - 1, t * fps)), nearest = Math.round(at);
|
|
26
|
+
if (Math.abs(at - nearest) < 1e-6) return crops[nearest];
|
|
27
|
+
const low = Math.floor(at), a = crops[low], b = crops[low + 1], u = at - low;
|
|
28
|
+
return { x: a.x + (b.x - a.x) * u, y: a.y + (b.y - a.y) * u, w: a.w + (b.w - a.w) * u, h: a.h + (b.h - a.h) * u };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const MAX_MOMENTS = 16;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The moments a frame at `t` averages for content that moves `distance` output pixels on screen over
|
|
35
|
+
* its exposure `span`: evenly spaced, at most `step` pixels of movement apart, ending on `t` itself. A
|
|
36
|
+
* frame without an exposure, or whose content moves less than a step, shows the one moment `t`.
|
|
37
|
+
*/
|
|
38
|
+
export function moments(t, span, distance, step) {
|
|
39
|
+
if (!span || !(distance >= step)) return [t];
|
|
40
|
+
const count = Math.min(MAX_MOMENTS, Math.ceil(distance / step) + 1);
|
|
41
|
+
return Array.from({ length: count }, (_, i) => i === count - 1 ? t : span.start + (span.end - span.start) * i / (count - 1));
|
|
42
|
+
}
|
package/src/styles/arrow.js
CHANGED
|
@@ -1,13 +1,133 @@
|
|
|
1
|
-
// The arrow cursor: filled with `color`, outlined in dark gray, with a soft shadow.
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// The arrow cursor and its family of shapes: filled with `color`, outlined in dark gray, with a soft shadow.
|
|
2
|
+
// The pictures are Phosphor icons (https://phosphoricons.com), drawn in their 256-unit grid; each shape's box
|
|
3
|
+
// is the part of the grid it covers. CueTake scales the arrow's box to the cursor's size and the others with it.
|
|
4
|
+
//
|
|
5
|
+
// Phosphor Icons: Copyright (c) 2023 Phosphor Icons. Permission is hereby granted, free of charge, to any person
|
|
6
|
+
// obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software
|
|
7
|
+
// without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
8
|
+
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
// subject to the following conditions: The above copyright notice and this permission notice shall be included in
|
|
10
|
+
// all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
11
|
+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
|
12
|
+
// AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
13
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
14
|
+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
15
|
+
|
|
16
|
+
// Where each shape sits in the grid, as [x, y, width, height], its hotspot in grid units, and the frames of a shape that turns.
|
|
17
|
+
const GRID = {
|
|
18
|
+
default: [[28, 28, 200, 200], [37, 37]],
|
|
19
|
+
pointer: [[24, 10, 206, 236], [116, 18]],
|
|
20
|
+
text: [[56, 24, 144, 208], [128, 128]],
|
|
21
|
+
crosshair: [[22, 22, 212, 212], [128, 128]],
|
|
22
|
+
grab: [[16, 10, 206, 236], [128, 140]],
|
|
23
|
+
grabbing: [[36, 58, 186, 188], [128, 150]],
|
|
24
|
+
move: [[6, 6, 244, 244], [128, 128]],
|
|
25
|
+
'not-allowed': [[18, 18, 220, 220], [128, 128]],
|
|
26
|
+
'ew-resize': [[6, 84, 244, 88], [128, 128]],
|
|
27
|
+
'ns-resize': [[84, 6, 88, 244], [128, 128]],
|
|
28
|
+
'nwse-resize': [[30, 30, 196, 196], [128, 128]],
|
|
29
|
+
'nesw-resize': [[30, 30, 196, 196], [128, 128]],
|
|
30
|
+
wait: [[34, 34, 188, 188], [128, 128], 24],
|
|
31
|
+
progress: [[28, 28, 236, 200], [37, 37], 24],
|
|
32
|
+
};
|
|
33
|
+
export const shapes = Object.fromEntries(Object.entries(GRID).map(([name, [[x, y, width, height], [hx, hy], frames]]) =>
|
|
34
|
+
[name, { width, height, hotspot: [hx - x, hy - y], ...frames && { frames } }]));
|
|
35
|
+
|
|
36
|
+
const OUTLINE = '#171717';
|
|
37
|
+
const path = d => new Path2D(d);
|
|
38
|
+
// Outlined pictures: the duotone weight's area, filled, under the regular weight's lines, or the light weight's when thin.
|
|
39
|
+
const FRAMED = {
|
|
40
|
+
default: [
|
|
41
|
+
path('M213.66,201,201,213.66a8,8,0,0,1-11.31,0l-51.31-51.31a8,8,0,0,0-13,2.46l-17.82,46.41a8,8,0,0,1-14.85-.71L40.41,50.44a8,8,0,0,1,10-10L210.51,92.68a8,8,0,0,1,.71,14.85l-46.41,17.82a8,8,0,0,0-2.46,13l51.31,51.31A8,8,0,0,1,213.66,201Z'),
|
|
42
|
+
path('M168,132.69,214.08,115l.33-.13A16,16,0,0,0,213,85.07L52.92,32.8A15.95,15.95,0,0,0,32.8,52.92L85.07,213a15.82,15.82,0,0,0,14.41,11l.78,0a15.84,15.84,0,0,0,14.61-9.59l.13-.33L132.69,168,184,219.31a16,16,0,0,0,22.63,0l12.68-12.68a16,16,0,0,0,0-22.63ZM195.31,208,144,156.69a16,16,0,0,0-26,4.93c0,.11-.09.22-.13.32l-17.65,46L48,48l159.85,52.2-45.95,17.64-.32.13a16,16,0,0,0-4.93,26h0L208,195.31Z'),
|
|
43
|
+
path('M166.59,134.1a1.91,1.91,0,0,1-.55-1.79,2,2,0,0,1,1.08-1.42l46.25-17.76.24-.1A14,14,0,0,0,212.38,87L52.29,34.7A13.95,13.95,0,0,0,34.7,52.29L87,212.38a13.82,13.82,0,0,0,12.6,9.6c.23,0,.46,0,.69,0A13.84,13.84,0,0,0,113,213.61a2.44,2.44,0,0,0,.1-.24l17.76-46.25a2,2,0,0,1,3.21-.53l51.31,51.31a14,14,0,0,0,19.8,0l12.69-12.69a14,14,0,0,0,0-19.8Zm42.82,62.63-12.68,12.68a2,2,0,0,1-2.83,0L142.59,158.1a14,14,0,0,0-22.74,4.32,2.44,2.44,0,0,0-.1.24L102,208.91a2,2,0,0,1-3.61-.26L46.11,48.57a1.87,1.87,0,0,1,.47-2A1.92,1.92,0,0,1,47.93,46a2.22,2.22,0,0,1,.64.1L208.65,98.38a2,2,0,0,1,.26,3.61l-46.25,17.76-.24.1a14,14,0,0,0-4.32,22.74h0l51.31,51.31A2,2,0,0,1,209.41,196.73Z'),
|
|
44
|
+
],
|
|
45
|
+
pointer: [
|
|
46
|
+
path('M216,116v36a80,80,0,0,1-80,80c-44.18,0-55.81-24-93.32-90a20,20,0,0,1,34.64-20L96,152V44a20,20,0,0,1,40,0v56a20,20,0,0,1,40,0v16a20,20,0,0,1,40,0Z'),
|
|
47
|
+
path('M196,88a27.86,27.86,0,0,0-13.35,3.39A28,28,0,0,0,144,74.7V44a28,28,0,0,0-56,0v80l-3.82-6.13A28,28,0,0,0,35.73,146l4.67,8.23C74.81,214.89,89.05,240,136,240a88.1,88.1,0,0,0,88-88V116A28,28,0,0,0,196,88Zm12,64a72.08,72.08,0,0,1-72,72c-37.63,0-47.84-18-81.68-77.68l-4.69-8.27,0-.05A12,12,0,0,1,54,121.61a11.88,11.88,0,0,1,6-1.6,12,12,0,0,1,10.41,6,1.76,1.76,0,0,0,.14.23l18.67,30A8,8,0,0,0,104,152V44a12,12,0,0,1,24,0v68a8,8,0,0,0,16,0V100a12,12,0,0,1,24,0v20a8,8,0,0,0,16,0v-4a12,12,0,0,1,24,0Z'),
|
|
48
|
+
path('M196,90a25.87,25.87,0,0,0-14.59,4.49A26,26,0,0,0,142,78.1V44a26,26,0,0,0-52,0v87l-7.53-12.1a26,26,0,0,0-45,26.07l4.67,8.25c34,60,48.07,84.77,93.86,84.77a86.1,86.1,0,0,0,86-86V116A26,26,0,0,0,196,90Zm14,62a74.09,74.09,0,0,1-74,74c-38.8,0-50-19.83-83.42-78.69L47.89,139l0,0A14,14,0,0,1,53,119.88,13.87,13.87,0,0,1,60,118a14,14,0,0,1,12.15,7l.1.17,18.68,30A6,6,0,0,0,102,152V44a14,14,0,0,1,28,0v68a6,6,0,0,0,12,0V100a14,14,0,0,1,28,0v20a6,6,0,0,0,12,0v-4a14,14,0,0,1,28,0Z'),
|
|
49
|
+
],
|
|
50
|
+
grab: [
|
|
51
|
+
path('M208,76v76a80,80,0,0,1-80,80c-44.18,0-60.75-21.28-93.32-90a20,20,0,0,1,34.64-20L88,152V60a20,20,0,0,1,40,0V44a20,20,0,0,1,40,0V76a20,20,0,0,1,40,0Z'),
|
|
52
|
+
path('M188,48a27.75,27.75,0,0,0-12,2.71V44a28,28,0,0,0-54.65-8.6A28,28,0,0,0,80,60v64l-3.82-6.13a28,28,0,0,0-48.6,27.82c16,33.77,28.93,57.72,43.72,72.69C86.24,233.54,103.2,240,128,240a88.1,88.1,0,0,0,88-88V76A28,28,0,0,0,188,48Zm12,104a72.08,72.08,0,0,1-72,72c-20.38,0-33.51-4.88-45.33-16.85C69.44,193.74,57.26,171,41.9,138.58a6.36,6.36,0,0,0-.3-.58,12,12,0,0,1,20.79-12,1.76,1.76,0,0,0,.14.23l18.67,30A8,8,0,0,0,96,152V60a12,12,0,0,1,24,0v60a8,8,0,0,0,16,0V44a12,12,0,0,1,24,0v76a8,8,0,0,0,16,0V76a12,12,0,0,1,24,0Z'),
|
|
53
|
+
path('M188,50a25.8,25.8,0,0,0-14,4.11V44a26,26,0,0,0-51.41-5.51A26,26,0,0,0,82,60v71l-7.53-12.1a26,26,0,0,0-45.11,25.87C60.76,211,78.51,238,128,238a86.1,86.1,0,0,0,86-86V76A26,26,0,0,0,188,50Zm14,102a74.09,74.09,0,0,1-74,74c-21,0-34.51-5.05-46.75-17.45C67.81,195,55.54,172,40.1,139.43l-.23-.43a14,14,0,0,1,24.25-14l.1.17,18.68,30A6,6,0,0,0,94,152V60a14,14,0,0,1,28,0v60a6,6,0,0,0,12,0V44a14,14,0,0,1,28,0v76a6,6,0,0,0,12,0V76a14,14,0,0,1,28,0Z'),
|
|
54
|
+
],
|
|
55
|
+
grabbing: [
|
|
56
|
+
path('M208,108v44a80,80,0,0,1-160,0V140a20,20,0,0,1,20-20H88V92a20,20,0,0,1,40,0,20,20,0,0,1,40,0v16a20,20,0,0,1,40,0Z'),
|
|
57
|
+
path('M188,80a27.79,27.79,0,0,0-13.36,3.4,28,28,0,0,0-46.64-11A28,28,0,0,0,80,92v20H68a28,28,0,0,0-28,28v12a88,88,0,0,0,176,0V108A28,28,0,0,0,188,80Zm12,72a72,72,0,0,1-144,0V140a12,12,0,0,1,12-12H80v24a8,8,0,0,0,16,0V92a12,12,0,0,1,24,0v28a8,8,0,0,0,16,0V92a12,12,0,0,1,24,0v28a8,8,0,0,0,16,0V108a12,12,0,0,1,24,0Z'),
|
|
58
|
+
path('M188,82a25.85,25.85,0,0,0-14.59,4.49A26,26,0,0,0,128,75.41,26,26,0,0,0,82,92v22H68a26,26,0,0,0-26,26v12a86,86,0,0,0,172,0V108A26,26,0,0,0,188,82Zm14,70a74,74,0,0,1-148,0V140a14,14,0,0,1,14-14H82v26a6,6,0,0,0,12,0V92a14,14,0,0,1,28,0v28a6,6,0,0,0,12,0V92a14,14,0,0,1,28,0v28a6,6,0,0,0,12,0V108a14,14,0,0,1,28,0Z'),
|
|
59
|
+
],
|
|
60
|
+
'not-allowed': [
|
|
61
|
+
path('M224,128a96,96,0,1,1-96-96A96,96,0,0,1,224,128Z'),
|
|
62
|
+
path('M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm88,104a87.56,87.56,0,0,1-20.41,56.28L71.72,60.4A88,88,0,0,1,216,128ZM40,128A87.56,87.56,0,0,1,60.41,71.72L184.28,195.6A88,88,0,0,1,40,128Z'),
|
|
63
|
+
path('M128,26A102,102,0,1,0,230,128,102.12,102.12,0,0,0,128,26Zm90,102a89.6,89.6,0,0,1-22.29,59.22L68.78,60.29A89.95,89.95,0,0,1,218,128ZM38,128A89.6,89.6,0,0,1,60.29,68.78L187.22,195.71A89.95,89.95,0,0,1,38,128Z'),
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
// Line pictures, filled and ringed with the outline: the I-beam and cross from the regular weight, arrows from the fill
|
|
67
|
+
// weight, with the move arrows' shafts joined in the middle.
|
|
68
|
+
const RINGED = {
|
|
69
|
+
text: path('M184,208a8,8,0,0,1-8,8H160a40,40,0,0,1-32-16,40,40,0,0,1-32,16H80a8,8,0,0,1,0-16H96a24,24,0,0,0,24-24V136H104a8,8,0,0,1,0-16h16V80A24,24,0,0,0,96,56H80a8,8,0,0,1,0-16H96a40,40,0,0,1,32,16,40,40,0,0,1,32-16h16a8,8,0,0,1,0,16H160a24,24,0,0,0-24,24v40h16a8,8,0,0,1,0,16H136v40a24,24,0,0,0,24,24h16A8,8,0,0,1,184,208Z'),
|
|
70
|
+
crosshair: path('M224,128a8,8,0,0,1-8,8H136v80a8,8,0,0,1-16,0V136H40a8,8,0,0,1,0-16h80V40a8,8,0,0,1,16,0v80h80A8,8,0,0,1,224,128Z'),
|
|
71
|
+
move: [path('M96,136H64v24a8,8,0,0,1-13.66,5.66l-32-32a8,8,0,0,1,0-11.32l32-32A8,8,0,0,1,64,96v24H96a8,8,0,0,1,0,16Zm0-72h24V96a8,8,0,0,0,16,0V64h24a8,8,0,0,0,5.66-13.66l-32-32a8,8,0,0,0-11.32,0l-32,32A8,8,0,0,0,96,64Zm141.66,58.34-32-32A8,8,0,0,0,192,96v24H160a8,8,0,0,0,0,16h32v24a8,8,0,0,0,13.66,5.66l32-32A8,8,0,0,0,237.66,122.34ZM160,192H136V160a8,8,0,0,0-16,0v32H96a8,8,0,0,0-5.66,13.66l32,32a8,8,0,0,0,11.32,0l32-32A8,8,0,0,0,160,192Z'), path('M120,64h16v128h-16Z'), path('M64,120h128v16h-128Z')],
|
|
72
|
+
};
|
|
73
|
+
// The resize shapes are one double arrow, turned by degrees.
|
|
74
|
+
const DOUBLE_ARROW = path('M237.66,133.66l-32,32A8,8,0,0,1,192,160V136H64v24a8,8,0,0,1-13.66,5.66l-32-32a8,8,0,0,1,0-11.32l32-32A8,8,0,0,1,64,96v24H192V96a8,8,0,0,1,13.66-5.66l32,32A8,8,0,0,1,237.66,133.66Z');
|
|
75
|
+
const RESIZE = { 'ew-resize': 0, 'ns-resize': 90, 'nwse-resize': 45, 'nesw-resize': -45 };
|
|
76
|
+
// The busy shapes show a ball turning once a second, as macOS does, in its own colors whatever the cursor's `color`.
|
|
77
|
+
const BALL = ['#f5c400', '#f7862a', '#e8374f', '#a144c4', '#2f80ed', '#3dba4e'];
|
|
78
|
+
|
|
79
|
+
/** Paints `under` with a soft shadow, then `over` without; shadow sizes are device pixels, so they follow the box's scale on screen. */
|
|
80
|
+
function shadowed(ctx, under, over) {
|
|
81
|
+
const { a, b } = ctx.getTransform(), pixels = Math.hypot(a, b) * 8; // about one CSS pixel at the default size
|
|
82
|
+
ctx.save();
|
|
83
|
+
ctx.lineJoin = 'round'; ctx.strokeStyle = OUTLINE;
|
|
9
84
|
ctx.shadowColor = '#00000055'; ctx.shadowBlur = 2 * pixels; ctx.shadowOffsetY = pixels;
|
|
10
|
-
|
|
85
|
+
under();
|
|
11
86
|
ctx.shadowColor = 'transparent';
|
|
12
|
-
|
|
87
|
+
over();
|
|
88
|
+
ctx.restore();
|
|
89
|
+
}
|
|
90
|
+
const framed = (ctx, [area, regular, light], color, thin) => shadowed(ctx, () => { ctx.fillStyle = color; ctx.fill(area); }, () => { ctx.fillStyle = OUTLINE; ctx.fill(thin ? light : regular); });
|
|
91
|
+
/** The spinning ball at (x, y) with radius r, turned by `phase` of a turn: swirled wedges under a soft highlight. */
|
|
92
|
+
function ball(ctx, x, y, r, phase) {
|
|
93
|
+
const swirl = 0.9, step = 2 * Math.PI / BALL.length, disc = new Path2D();
|
|
94
|
+
disc.arc(x, y, r, 0, 2 * Math.PI);
|
|
95
|
+
shadowed(ctx, () => { ctx.fillStyle = BALL[0]; ctx.fill(disc); }, () => {
|
|
96
|
+
BALL.forEach((fill, i) => {
|
|
97
|
+
const a = (i + phase * BALL.length) * step, wedge = new Path2D(), bend = angle => [x + r * 0.6 * Math.cos(angle - swirl), y + r * 0.6 * Math.sin(angle - swirl)];
|
|
98
|
+
wedge.moveTo(x, y); wedge.quadraticCurveTo(...bend(a), x + r * Math.cos(a), y + r * Math.sin(a));
|
|
99
|
+
wedge.arc(x, y, r, a, a + step + 0.02);
|
|
100
|
+
wedge.quadraticCurveTo(...bend(a + step + 0.02), x, y);
|
|
101
|
+
ctx.fillStyle = fill; ctx.fill(wedge);
|
|
102
|
+
});
|
|
103
|
+
const shine = ctx.createRadialGradient(x - r * 0.35, y - r * 0.45, 0, x - r * 0.35, y - r * 0.45, r * 1.1);
|
|
104
|
+
shine.addColorStop(0, '#ffffff99'); shine.addColorStop(1, '#ffffff00');
|
|
105
|
+
ctx.fillStyle = shine; ctx.fill(disc);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** Line pictures (one path or overlapping parts) with a dark edge `edge` grid units wide outside them. */
|
|
109
|
+
function ringed(ctx, lines, color, edge) {
|
|
110
|
+
// One stroke for every part, so their shadows do not darken each other; each part fills on its own, whatever its winding.
|
|
111
|
+
const parts = [lines].flat(), whole = new Path2D();
|
|
112
|
+
parts.forEach(p => whole.addPath(p));
|
|
113
|
+
shadowed(ctx, () => { ctx.lineWidth = edge * 2; ctx.stroke(whole); }, () => { ctx.fillStyle = color; parts.forEach(p => ctx.fill(p)); });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* `thin` draws every dark edge 12 grid units wide, as the light weight's lines are, instead of 16 as the
|
|
118
|
+
* regular weight's are; either way the line pictures' edges match the outlined pictures'.
|
|
119
|
+
*/
|
|
120
|
+
export function draw(ctx, { shape, phase = 0, params }) {
|
|
121
|
+
const color = params.color ?? '#ffffff', thin = Boolean(params.thin), edge = thin ? 12 : 16, [[x, y]] = GRID[shape];
|
|
122
|
+
ctx.translate(-x, -y);
|
|
123
|
+
if (shape in FRAMED) return framed(ctx, FRAMED[shape], color, thin);
|
|
124
|
+
if (shape in RINGED) return ringed(ctx, RINGED[shape], color, edge);
|
|
125
|
+
if (shape in RESIZE) {
|
|
126
|
+
ctx.translate(128, 128); ctx.rotate(RESIZE[shape] * Math.PI / 180); ctx.translate(-128, -128);
|
|
127
|
+
return ringed(ctx, DOUBLE_ARROW, color, edge);
|
|
128
|
+
}
|
|
129
|
+
if (shape === 'wait') return ball(ctx, 128, 128, 88, phase);
|
|
130
|
+
// progress: the arrow with a small ball beside its tail, as macOS shows it.
|
|
131
|
+
framed(ctx, FRAMED.default, color, thin);
|
|
132
|
+
ball(ctx, 226, 178, 34, phase);
|
|
13
133
|
}
|
package/src/styles/browser.js
CHANGED
|
@@ -12,7 +12,8 @@ export function draw(ctx, { width, height, url, params }) {
|
|
|
12
12
|
ctx.beginPath(); ctx.arc(20 + i * 20, height / 2, 6, 0, 2 * Math.PI);
|
|
13
13
|
ctx.fillStyle = light; ctx.fill(); ctx.strokeStyle = '#0000001f'; ctx.lineWidth = 0.5; ctx.stroke();
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
// The field narrows in a narrow window, such as a popup's, to stay clear of the lights.
|
|
16
|
+
const w = Math.min(420, width - 160), h = 28, x = (width - w) / 2, y = (height - h) / 2;
|
|
16
17
|
ctx.beginPath(); ctx.roundRect(x, y, w, h, h / 2);
|
|
17
18
|
ctx.fillStyle = t.field; ctx.fill(); ctx.strokeStyle = t.fieldLine; ctx.lineWidth = 0.8; ctx.stroke();
|
|
18
19
|
ctx.font = '13px system-ui, -apple-system, sans-serif'; ctx.textBaseline = 'middle';
|
package/src/styles/dot.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// A round dot cursor filled with `color` and outlined in dark gray; its center is the hotspot.
|
|
2
|
-
|
|
2
|
+
// It draws only the default shape, so it stays a dot whatever the page asks for.
|
|
3
|
+
export const shapes = { default: { width: 24, height: 24, hotspot: [12, 12] } };
|
|
3
4
|
|
|
4
5
|
export function draw(ctx, { params }) {
|
|
5
6
|
const pixels = ctx.getTransform().a;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Fast-forward badge: two arrowheads and the span's rate on a rounded band, centered in the Final.
|
|
2
|
+
// Parameters: fontSize, color, band (#rrggbbaa, '' for none), x and y (where its center sits, as fractions of the Final).
|
|
3
|
+
// Drawn in 1080p pixels over the whole Final, outside the camera, while it fast-forwards; `rate` is the span's rate.
|
|
4
|
+
export function draw(ctx, { width, height, rate, params, files }) {
|
|
5
|
+
const { fontSize: size = 44, color = '#ffffff', band = '#000000a6', x: across = 0.5, y: down = 0.5 } = params;
|
|
6
|
+
const family = files.font ? `"${files.font}"` : '-apple-system, "SF Pro Text", "Helvetica Neue", "DejaVu Sans", system-ui, sans-serif';
|
|
7
|
+
const label = `${+rate.toFixed(2)}×`;
|
|
8
|
+
ctx.font = `600 ${size}px ${family}`;
|
|
9
|
+
ctx.textAlign = 'left'; ctx.textBaseline = 'middle';
|
|
10
|
+
const h = size * 1.8, padding = size * 0.6, arrow = size * 0.5, gap = size * 0.35;
|
|
11
|
+
const w = padding + 2 * arrow + gap + ctx.measureText(label).width + padding;
|
|
12
|
+
const x = width * across - w / 2, y = height * down - h / 2, middle = y + h / 2;
|
|
13
|
+
if (band) {
|
|
14
|
+
ctx.fillStyle = band;
|
|
15
|
+
ctx.beginPath(); ctx.roundRect(x, y, w, h, h / 2); ctx.fill();
|
|
16
|
+
}
|
|
17
|
+
ctx.fillStyle = color;
|
|
18
|
+
for (const left of [x + padding, x + padding + arrow]) {
|
|
19
|
+
ctx.beginPath(); ctx.moveTo(left, middle - arrow * 0.7); ctx.lineTo(left + arrow, middle); ctx.lineTo(left, middle + arrow * 0.7); ctx.closePath(); ctx.fill();
|
|
20
|
+
}
|
|
21
|
+
ctx.fillText(label, x + padding + 2 * arrow + gap, middle);
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Keycaps: one rounded cap per key of a Shortcut, in a row at the bottom right of the Final, level with the Subtitles.
|
|
2
|
+
// Parameters: symbols (macOS symbols such as ⌘ ⇧ ⌥ ⌃, or words such as Ctrl), fontSize, color, cap, edge, right, bottom.
|
|
3
|
+
// Drawn in 1080p pixels over the whole Final, outside the camera; `count` is how many times the keys were pressed.
|
|
4
|
+
const SYMBOLS = {
|
|
5
|
+
Meta: '⌘', Control: '⌃', Alt: '⌥', Shift: '⇧', Enter: '↩', Escape: 'esc', Backspace: '⌫', Delete: '⌦', Tab: '⇥', CapsLock: '⇪',
|
|
6
|
+
ArrowUp: '↑', ArrowDown: '↓', ArrowLeft: '←', ArrowRight: '→', PageUp: '⇞', PageDown: '⇟', Home: '↖', End: '↘', Space: 'space',
|
|
7
|
+
};
|
|
8
|
+
const WORDS = {
|
|
9
|
+
Meta: 'Cmd', Control: 'Ctrl', Alt: 'Alt', Shift: 'Shift', Enter: 'Enter', Escape: 'Esc', Backspace: 'Backspace', Delete: 'Del', Tab: 'Tab',
|
|
10
|
+
ArrowUp: '↑', ArrowDown: '↓', ArrowLeft: '←', ArrowRight: '→', PageUp: 'PgUp', PageDown: 'PgDn', Space: 'Space',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function draw(ctx, { width, height, keys, count, params, files }) {
|
|
14
|
+
const { symbols = true, fontSize: size = 34, color = '#ffffff', cap = '#1f1f23e6', edge = '#ffffff40', right = 80, bottom = 80 } = params;
|
|
15
|
+
const family = files.font ? `"${files.font}"` : '-apple-system, "SF Pro Text", "Helvetica Neue", "DejaVu Sans", system-ui, sans-serif';
|
|
16
|
+
const labels = keys.map(key => (symbols ? SYMBOLS : WORDS)[key] ?? key);
|
|
17
|
+
ctx.font = `600 ${size}px ${family}`;
|
|
18
|
+
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
19
|
+
const h = size * 1.9, gap = size * 0.3, padding = size * 0.55;
|
|
20
|
+
const widths = labels.map(label => Math.max(h, ctx.measureText(label).width + 2 * padding));
|
|
21
|
+
const times = count > 1 ? `×${count}` : '';
|
|
22
|
+
const total = widths.reduce((sum, w) => sum + w, 0) + gap * (labels.length - 1) + (times ? gap + ctx.measureText(times).width : 0);
|
|
23
|
+
let x = width - right - total;
|
|
24
|
+
const y = height - bottom - h;
|
|
25
|
+
labels.forEach((label, i) => {
|
|
26
|
+
ctx.beginPath(); ctx.roundRect(x, y, widths[i], h, size * 0.35);
|
|
27
|
+
ctx.shadowColor = '#00000059'; ctx.shadowBlur = size * 0.5; ctx.shadowOffsetY = size * 0.1;
|
|
28
|
+
ctx.fillStyle = cap; ctx.fill();
|
|
29
|
+
ctx.shadowColor = 'transparent';
|
|
30
|
+
ctx.lineWidth = 2; ctx.strokeStyle = edge; ctx.stroke();
|
|
31
|
+
ctx.fillStyle = color; ctx.fillText(label, x + widths[i] / 2, y + h / 2);
|
|
32
|
+
x += widths[i] + gap;
|
|
33
|
+
});
|
|
34
|
+
if (times) {
|
|
35
|
+
ctx.textAlign = 'left'; ctx.lineWidth = 6; ctx.strokeStyle = cap; ctx.lineJoin = 'round';
|
|
36
|
+
ctx.strokeText(times, x, y + h / 2); ctx.fillText(times, x, y + h / 2);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Subtitles: centered rows of text on a rounded band near the bottom of the Final.
|
|
2
|
+
// Parameters: fontSize, weight, color, band (#rrggbbaa, '' for none), bottom (gap below the band), padding.
|
|
3
|
+
// Drawn in 1080p pixels over the whole Final, outside the camera; a `font` in files replaces the system font.
|
|
4
|
+
export function draw(ctx, { width, height, rows, params, files }) {
|
|
5
|
+
const { fontSize: size = 40, weight = 600, color = '#ffffff', band = '#000000b3', bottom = 72, padding = 14 } = params;
|
|
6
|
+
const family = files.font ? `"${files.font}"` : '-apple-system, "PingFang SC", "Helvetica Neue", system-ui, sans-serif';
|
|
7
|
+
ctx.font = `${weight} ${size}px ${family}`;
|
|
8
|
+
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
9
|
+
const line = size * 1.3, w = Math.max(...rows.map(row => ctx.measureText(row).width)) + 2 * padding * 1.6;
|
|
10
|
+
const h = rows.length * line + 2 * padding, y = height - bottom - h;
|
|
11
|
+
if (band) {
|
|
12
|
+
ctx.fillStyle = band;
|
|
13
|
+
ctx.beginPath(); ctx.roundRect((width - w) / 2, y, w, h, Math.min(12, h / 2)); ctx.fill();
|
|
14
|
+
}
|
|
15
|
+
ctx.fillStyle = color;
|
|
16
|
+
rows.forEach((row, i) => ctx.fillText(row, width / 2, y + padding + line * (i + 0.5)));
|
|
17
|
+
}
|
package/src/styles.js
CHANGED
|
@@ -15,17 +15,21 @@ export const BUILTINS = {
|
|
|
15
15
|
'browser-dark': { file: 'browser.js', params: { dark: true } },
|
|
16
16
|
macos: { file: 'macos.js', params: { dark: false } },
|
|
17
17
|
'macos-dark': { file: 'macos.js', params: { dark: true } },
|
|
18
|
-
arrow: { file: 'arrow.js', params: {} },
|
|
18
|
+
arrow: { file: 'arrow.js', params: { thin: false } },
|
|
19
|
+
'arrow-thin': { file: 'arrow.js', params: { thin: true } },
|
|
19
20
|
dot: { file: 'dot.js', params: {} },
|
|
20
21
|
spark: { file: 'spark.js', params: { radius: 32, length: 16, count: 8 } },
|
|
22
|
+
keycaps: { file: 'keycaps.js', params: { symbols: true, fontSize: 34, color: '#ffffff', cap: '#1f1f23e6', edge: '#ffffff40', right: 80, bottom: 80 } },
|
|
23
|
+
subtitles: { file: 'subtitles.js', params: { fontSize: 40, weight: 600, color: '#ffffff', band: '#000000b3', bottom: 72, padding: 14 } },
|
|
24
|
+
'fast-forward': { file: 'fast-forward.js', params: { fontSize: 44, color: '#ffffff', band: '#000000a6', x: 0.5, y: 0.5 } },
|
|
21
25
|
};
|
|
22
26
|
export const KINDS = ['shader', 'draw', 'image'];
|
|
23
27
|
export const isFile = ref => typeof ref === 'string' && extname(ref) !== '';
|
|
24
28
|
|
|
25
29
|
/** Every drawn item an Edit or (partial) Look holds. */
|
|
26
30
|
function items(style) {
|
|
27
|
-
const { frame, cursor, clickEffect } = style ?? {};
|
|
28
|
-
return [...(Array.isArray(frame?.background) ? frame.background : []), ...(Array.isArray(frame?.effects) ? frame.effects : []), frame?.chrome, cursor, clickEffect]
|
|
31
|
+
const { frame, cursor, clickEffect, keycaps, subtitles, fastForwardBadge } = style ?? {};
|
|
32
|
+
return [...(Array.isArray(frame?.background) ? frame.background : []), ...(Array.isArray(frame?.effects) ? frame.effects : []), frame?.chrome, cursor, clickEffect, keycaps, subtitles, fastForwardBadge]
|
|
29
33
|
.filter(item => item && typeof item === 'object');
|
|
30
34
|
}
|
|
31
35
|
|