cuetake 0.2.0 → 0.4.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 +8 -6
- package/package.json +2 -2
- package/src/auth.js +8 -1
- package/src/cli.js +26 -8
- package/src/cursor.js +57 -30
- package/src/director.js +80 -25
- package/src/edit.js +55 -45
- package/src/environment.js +23 -7
- package/src/look.js +88 -60
- package/src/motion.js +66 -0
- package/src/narration.js +146 -0
- package/src/pipeline.js +188 -33
- package/src/probe.js +78 -20
- package/src/render-page.js +498 -207
- package/src/render.js +68 -17
- package/src/shortcuts.js +73 -0
- package/src/stage.js +28 -44
- package/src/styles/arrow.js +133 -0
- package/src/styles/browser.js +24 -0
- package/src/styles/dot.js +12 -0
- package/src/styles/fluted.glsl +35 -0
- package/src/styles/keycaps.js +38 -0
- package/src/styles/macos.js +12 -0
- package/src/styles/shadow.glsl +10 -0
- package/src/styles/spark.js +19 -0
- package/src/styles/subtitles.js +17 -0
- package/src/styles.js +108 -0
- package/src/uninstall.js +62 -0
package/src/render.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
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
|
+
import { contentType } from './styles.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Render runs in a headless Chromium page (ADR 0001). Files reach the page through intercepted
|
|
9
10
|
* requests on a private origin, so no port is opened: the Source is served with byte ranges and
|
|
10
|
-
* the Final arrives as positioned chunks written straight to disk.
|
|
11
|
+
* the Final arrives as positioned chunks written straight to disk. The page has no network: it runs
|
|
12
|
+
* agent-written code (ADR 0005), and anything that code tries to fetch from elsewhere is refused.
|
|
11
13
|
*/
|
|
12
14
|
const ORIGIN = 'https://render.cuetake.invalid';
|
|
13
15
|
// The bundled build is a single file the page can import; the package's own entry is many modules.
|
|
@@ -18,6 +20,8 @@ const pageFiles = {
|
|
|
18
20
|
'/camera.js': { path: fileURLToPath(new URL('./camera.js', import.meta.url)), type: 'text/javascript' },
|
|
19
21
|
'/cursor.js': { path: fileURLToPath(new URL('./cursor.js', import.meta.url)), type: 'text/javascript' },
|
|
20
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' },
|
|
21
25
|
'/mediabunny.js': { path: mediabunnyBundle, type: 'text/javascript' },
|
|
22
26
|
};
|
|
23
27
|
|
|
@@ -30,19 +34,23 @@ async function serveRange(route, path) {
|
|
|
30
34
|
try {
|
|
31
35
|
const body = Buffer.alloc(end - start + 1);
|
|
32
36
|
await handle.read(body, 0, body.length, start);
|
|
33
|
-
await route.fulfill({ status: match ? 206 : 200, body, headers: { 'content-type':
|
|
37
|
+
await route.fulfill({ status: match ? 206 : 200, body, headers: { 'content-type': contentType(path), 'accept-ranges': 'bytes', 'content-range': `bytes ${start}-${end}/${size}` } });
|
|
34
38
|
} finally { await handle.close(); }
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/** Opens the render page with `files` ({ name: path }) readable and `writable` ({ name: handle }) writable. */
|
|
38
42
|
async function withRenderPage({ files = {}, writable = {} }, task) {
|
|
39
|
-
|
|
43
|
+
// An unreachable proxy stops what request interception does not see, such as WebSockets.
|
|
44
|
+
const browser = await chromium.launch({ headless: true, channel: 'chromium', proxy: { server: 'http://127.0.0.1:9' }, args: ['--force-webrtc-ip-handling-policy=disable_non_proxied_udp'] });
|
|
45
|
+
const blocked = [];
|
|
40
46
|
try {
|
|
41
47
|
const page = await browser.newPage();
|
|
42
48
|
const errors = [];
|
|
43
49
|
page.on('pageerror', error => errors.push(error.message));
|
|
44
|
-
await page.route(
|
|
45
|
-
const
|
|
50
|
+
await page.route('**/*', async route => {
|
|
51
|
+
const url = new URL(route.request().url());
|
|
52
|
+
if (url.origin !== ORIGIN) { blocked.push(url.href); return route.abort('blockedbyclient'); }
|
|
53
|
+
const { pathname, searchParams } = url;
|
|
46
54
|
const name = pathname.slice('/files/'.length);
|
|
47
55
|
if (route.request().method() === 'POST' && writable[name]) {
|
|
48
56
|
const body = route.request().postDataBuffer();
|
|
@@ -56,33 +64,76 @@ async function withRenderPage({ files = {}, writable = {} }, task) {
|
|
|
56
64
|
});
|
|
57
65
|
await page.goto(`${ORIGIN}/render.html`);
|
|
58
66
|
await page.waitForFunction(() => window.cuetakeRender, null, { timeout: 15_000 }).catch(() => { throw new Error(`Render page failed to load: ${errors.join('; ')}`); });
|
|
59
|
-
|
|
67
|
+
const result = await task(page).catch(error => { throw offline(fromPage(error), blocked); });
|
|
68
|
+
if (blocked.length) throw offline(null, blocked);
|
|
69
|
+
return result;
|
|
60
70
|
} finally { await browser.close(); }
|
|
61
71
|
}
|
|
62
72
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
73
|
+
/** An error thrown in the render page, without Playwright's prefix and the page's stack. */
|
|
74
|
+
function fromPage(error) {
|
|
75
|
+
const message = error.message.replace(/^page\.evaluate: (Error: )?/, '').split(/\n\s+at /)[0];
|
|
76
|
+
return message === error.message ? error : new Error(message);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Names what styling code tried to fetch, which the render page cannot. */
|
|
80
|
+
function offline(error, blocked) {
|
|
81
|
+
if (!blocked.length) return error;
|
|
82
|
+
const note = `The render page has no network and refused ${[...new Set(blocked)].join(', ')}; download it next to the Look or Take and name it by its relative path in \`files\``;
|
|
83
|
+
return new Error(error ? `${error.message}\n${note}` : note);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Lines as the render page reads them, `{ id, audio, url, ... }`, with their audio served from `files`.
|
|
88
|
+
* Each Line is `{ id, path, ... }`, `path` being its audio file.
|
|
89
|
+
*/
|
|
90
|
+
function servedLines(lines, files) {
|
|
91
|
+
return lines.map(({ path, ...line }, i) => {
|
|
92
|
+
const name = `line-${i}${extname(path)}`;
|
|
93
|
+
files[name] = path;
|
|
94
|
+
return { ...line, audio: basename(path), url: `${ORIGIN}/files/${name}` };
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Composes the Final from a Source, Timeline and Edit; `files` serves the Edit's styling files (styles.js
|
|
100
|
+
* forRender). `narration` ({ language, volume, lines }) adds its Lines' audio and Subtitles.
|
|
101
|
+
*/
|
|
102
|
+
export async function renderFinal({ sourcePath, finalPath, timeline, edit, files = {}, narration = null }) {
|
|
65
103
|
const handle = await fs.open(finalPath, 'w');
|
|
104
|
+
const served = { ...files, source: sourcePath };
|
|
105
|
+
const spoken = narration && { ...narration, lines: servedLines(narration.lines, served) };
|
|
66
106
|
try {
|
|
67
|
-
return await withRenderPage({ files:
|
|
107
|
+
return await withRenderPage({ files: served, writable: { final: handle } }, page => page.evaluate(options => window.cuetakeRender(options), {
|
|
68
108
|
sourceUrl: `${ORIGIN}/files/source`, finalUrl: `${ORIGIN}/files/final`, duration: timeline.duration,
|
|
69
|
-
viewport: timeline.viewport, pointer: timeline.pointer ?? [], events: timeline.events ?? [], edit,
|
|
109
|
+
viewport: timeline.viewport, pointer: timeline.pointer ?? [], shapes: timeline.shapes ?? [], events: timeline.events ?? [], edit, narration: spoken,
|
|
70
110
|
}));
|
|
71
111
|
} finally { await handle.close(); }
|
|
72
112
|
}
|
|
73
113
|
|
|
74
114
|
/** A Preview PNG of `tiles` ([{ name, edit }]) at `at` seconds, or at the end with the camera wide. No Final is touched. */
|
|
75
|
-
export async function composePreview({ sourcePath, timeline, tiles, at }) {
|
|
76
|
-
const
|
|
115
|
+
export async function composePreview({ sourcePath, timeline, tiles, at, files = {}, narration = null }) {
|
|
116
|
+
const served = { ...files, source: sourcePath };
|
|
117
|
+
const spoken = narration && { ...narration, lines: servedLines(narration.lines, served) };
|
|
118
|
+
const png = await withRenderPage({ files: served }, page => page.evaluate(options => window.cuetakePreview(options), {
|
|
77
119
|
sourceUrl: `${ORIGIN}/files/source`, duration: timeline.duration, viewport: timeline.viewport,
|
|
78
|
-
pointer: timeline.pointer ?? [], events: timeline.events ?? [], tiles, at: at ?? null,
|
|
120
|
+
pointer: timeline.pointer ?? [], shapes: timeline.shapes ?? [], events: timeline.events ?? [], tiles, at: at ?? null, narration: spoken,
|
|
79
121
|
}));
|
|
80
122
|
return Buffer.from(png, 'base64');
|
|
81
123
|
}
|
|
82
124
|
|
|
83
|
-
/** Container metadata of a Final plus a full decode. */
|
|
84
|
-
export function inspectFinal(path) {
|
|
85
|
-
|
|
125
|
+
/** Container metadata of a Final plus a full decode of its video and audio, and of each Line's audio (`lines`: [{ id, path }]). */
|
|
126
|
+
export function inspectFinal(path, lines = []) {
|
|
127
|
+
const files = { final: path };
|
|
128
|
+
const served = servedLines(lines, files);
|
|
129
|
+
return withRenderPage({ files }, page => page.evaluate(([url, lines]) => window.cuetakeInspect(url, lines), [`${ORIGIN}/files/final`, served]));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Each Line's audio duration in seconds (`lines`: [{ id, path }]); the error names a Line whose audio cannot be decoded. */
|
|
133
|
+
export function measureLines(lines) {
|
|
134
|
+
const files = {};
|
|
135
|
+
const served = servedLines(lines, files);
|
|
136
|
+
return withRenderPage({ files }, page => page.evaluate(lines => window.cuetakeMeasure(lines), served));
|
|
86
137
|
}
|
|
87
138
|
|
|
88
139
|
/** 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/stage.js
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stage layout shared by Node and the render page. Pure functions, no imports.
|
|
3
3
|
*
|
|
4
|
-
* The stage is the Final's pixel grid
|
|
5
|
-
* bar above it)
|
|
4
|
+
* The stage is the Final's pixel grid at camera zoom 1: the page sits in a window (with an optional
|
|
5
|
+
* chrome bar above it) inset by padding. The Background stays in output pixels whatever the camera does.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
export const
|
|
10
|
-
/** Chrome bar heights in page CSS pixels. */
|
|
11
|
-
export const CHROME_HEIGHT = { none: 0, macos: 28, browser: 44 };
|
|
8
|
+
/** The Final's pixel size. */
|
|
9
|
+
export const outputSize = edit => ({ width: edit.output.width, height: edit.output.height });
|
|
12
10
|
|
|
13
|
-
/** The
|
|
14
|
-
export function
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
? { width: even(short * viewport.width / viewport.height), height: short }
|
|
18
|
-
: { width: short, height: even(short * viewport.height / viewport.width) };
|
|
19
|
-
const long = even(short * 16 / 9);
|
|
20
|
-
return { '16:9': { width: long, height: short }, '9:16': { width: short, height: long }, '1:1': { width: short, height: short } }[edit.output.aspect];
|
|
11
|
+
/** The Edit with its output scaled so the short side is `short` pixels; everything else scales with it. */
|
|
12
|
+
export function atShortSide(edit, short) {
|
|
13
|
+
const { width, height } = edit.output, k = short / Math.min(width, height), even = n => Math.round(n * k / 2) * 2;
|
|
14
|
+
return { ...edit, output: { ...edit.output, width: even(width), height: even(height) } };
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const scale = Math.min((width -
|
|
33
|
-
const w = viewport.width * scale, h = (viewport.height +
|
|
34
|
-
const window = { x: (width - w) / 2, y: (height - h) / 2, w, h };
|
|
35
|
-
const chrome = chromeCss * scale;
|
|
17
|
+
/**
|
|
18
|
+
* Where the window, its chrome and the page sit on the stage, in stage pixels. `chrome` is the chrome
|
|
19
|
+
* bar's height in CSS pixels; `scale` is stage px per CSS px. The window is as large as fits inside the
|
|
20
|
+
* padding and centered in it.
|
|
21
|
+
*/
|
|
22
|
+
export function layout(edit, viewport, chrome = 0) {
|
|
23
|
+
const { width, height } = outputSize(edit), short = Math.min(width, height);
|
|
24
|
+
const padding = [edit.frame.padding ?? 0].flat();
|
|
25
|
+
const [top, right, bottom, left] = (padding.length === 4 ? padding : [padding[0], padding[0], padding[0], padding[0]]).map(p => p * short);
|
|
26
|
+
const scale = Math.min((width - left - right) / viewport.width, (height - top - bottom) / (viewport.height + chrome));
|
|
27
|
+
const w = viewport.width * scale, h = (viewport.height + chrome) * scale;
|
|
28
|
+
const window = { x: left + (width - left - right - w) / 2, y: top + (height - top - bottom - h) / 2, w, h };
|
|
36
29
|
return {
|
|
37
|
-
width, height, scale, chrome, radius: edit.frame.radius *
|
|
38
|
-
window, page: { x: window.x, y: window.y + chrome, w, h: h - chrome },
|
|
30
|
+
width, height, scale, chrome: chrome * scale, radius: (edit.frame.radius ?? 0) * short / 1080,
|
|
31
|
+
window, page: { x: window.x, y: window.y + chrome * scale, w, h: h - chrome * scale },
|
|
39
32
|
};
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
/**
|
|
43
36
|
* The camera for a viewport crop: the stage point at the Final's center and the zoom. Zoom 1 shows
|
|
44
|
-
* the whole stage; zooming keeps the view inside the stage, so
|
|
37
|
+
* the whole stage; zooming keeps the view inside the stage, so the Background shows beside the page near its edges.
|
|
45
38
|
*/
|
|
46
39
|
export function cameraView(crop, stage, viewport) {
|
|
47
40
|
const zoom = viewport.width / crop.w;
|
|
@@ -54,24 +47,15 @@ export function cameraView(crop, stage, viewport) {
|
|
|
54
47
|
};
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
/** Mesh backgrounds: a base color under soft radial blobs [x, y, radius] as fractions of the stage. */
|
|
58
|
-
export const BACKGROUNDS = {
|
|
59
|
-
aurora: { base: '#1e1b4b', blobs: [[0.15, 0.2, 0.7, '#7c3aed'], [0.85, 0.15, 0.6, '#db2777'], [0.7, 0.9, 0.75, '#2563eb'], [0.2, 0.85, 0.55, '#0ea5e9']] },
|
|
60
|
-
sunset: { base: '#431407', blobs: [[0.1, 0.15, 0.7, '#f97316'], [0.9, 0.25, 0.65, '#e11d48'], [0.6, 0.95, 0.7, '#a21caf'], [0.25, 0.8, 0.45, '#facc15']] },
|
|
61
|
-
ocean: { base: '#082f49', blobs: [[0.2, 0.1, 0.65, '#14b8a6'], [0.85, 0.3, 0.7, '#0284c7'], [0.4, 0.95, 0.75, '#1e3a8a'], [0.95, 0.9, 0.4, '#22d3ee']] },
|
|
62
|
-
graphite: { base: '#0a0a0a', blobs: [[0.3, 0.2, 0.7, '#3f3f46'], [0.8, 0.8, 0.7, '#27272a']] },
|
|
63
|
-
paper: { base: '#f4f4f5', blobs: [[0.5, 0, 0.8, '#ffffff'], [0.5, 1.1, 0.7, '#e4e4e7']] },
|
|
64
|
-
};
|
|
65
|
-
|
|
66
50
|
const hsl = (h, s, l) => {
|
|
67
51
|
const k = n => (n + h / 30) % 12, a = s * Math.min(l, 1 - l);
|
|
68
|
-
|
|
69
|
-
return '#' + [f(0), f(8), f(4)].map(v => Math.round(v * 255).toString(16).padStart(2, '0')).join('');
|
|
52
|
+
return [0, 8, 4].map(n => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1)));
|
|
70
53
|
};
|
|
71
54
|
|
|
72
|
-
/**
|
|
73
|
-
export function
|
|
74
|
-
|
|
55
|
+
/** The brand color shaders receive, as RGB from 0 to 1: the page's brand hue, or a neutral gray for a colorless page. */
|
|
56
|
+
export function brandColor(rgba) {
|
|
57
|
+
const hue = brandHue(rgba);
|
|
58
|
+
return hue === null ? [0.55, 0.56, 0.6] : hsl(hue, 0.75, 0.55);
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
/** The hue of the most frequent saturated color in RGBA pixels, or null for a colorless page. */
|
|
@@ -0,0 +1,133 @@
|
|
|
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;
|
|
84
|
+
ctx.shadowColor = '#00000055'; ctx.shadowBlur = 2 * pixels; ctx.shadowOffsetY = pixels;
|
|
85
|
+
under();
|
|
86
|
+
ctx.shadowColor = 'transparent';
|
|
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);
|
|
133
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// A browser window's top bar: traffic lights and a centered address field showing the url.
|
|
2
|
+
// Parameters: dark (a dark bar). Drawn in CSS pixels; CueTake clips it to the window's rounded top.
|
|
3
|
+
export const height = 44;
|
|
4
|
+
|
|
5
|
+
export function draw(ctx, { width, height, url, params }) {
|
|
6
|
+
const t = params.dark
|
|
7
|
+
? { bar: '#2a2a2e', line: '#111113', field: '#3a3a40', fieldLine: '#4a4a52', text: '#d4d4d8', lock: '#a1a1aa' }
|
|
8
|
+
: { bar: '#f3f3f5', line: '#d4d4d8', field: '#ffffff', fieldLine: '#e4e4e7', text: '#52525b', lock: '#71717a' };
|
|
9
|
+
ctx.fillStyle = t.bar; ctx.fillRect(0, 0, width, height);
|
|
10
|
+
ctx.fillStyle = t.line; ctx.fillRect(0, height - 1, width, 1);
|
|
11
|
+
['#ff5f57', '#febc2e', '#28c840'].forEach((light, i) => {
|
|
12
|
+
ctx.beginPath(); ctx.arc(20 + i * 20, height / 2, 6, 0, 2 * Math.PI);
|
|
13
|
+
ctx.fillStyle = light; ctx.fill(); ctx.strokeStyle = '#0000001f'; ctx.lineWidth = 0.5; ctx.stroke();
|
|
14
|
+
});
|
|
15
|
+
const w = 420, h = 28, x = (width - w) / 2, y = (height - h) / 2;
|
|
16
|
+
ctx.beginPath(); ctx.roundRect(x, y, w, h, h / 2);
|
|
17
|
+
ctx.fillStyle = t.field; ctx.fill(); ctx.strokeStyle = t.fieldLine; ctx.lineWidth = 0.8; ctx.stroke();
|
|
18
|
+
ctx.font = '13px system-ui, -apple-system, sans-serif'; ctx.textBaseline = 'middle';
|
|
19
|
+
const left = width / 2 - (ctx.measureText(url).width + 16) / 2;
|
|
20
|
+
ctx.fillStyle = t.lock; // padlock
|
|
21
|
+
ctx.beginPath(); ctx.roundRect(left, y + 13, 9, 7, 1.5); ctx.fill();
|
|
22
|
+
ctx.strokeStyle = t.lock; ctx.lineWidth = 1.3; ctx.beginPath(); ctx.arc(left + 4.5, y + 13, 2.8, Math.PI, 0); ctx.stroke();
|
|
23
|
+
ctx.fillStyle = t.text; ctx.fillText(url, left + 16, height / 2 + 0.5);
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A round dot cursor filled with `color` and outlined in dark gray; its center is the hotspot.
|
|
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] } };
|
|
4
|
+
|
|
5
|
+
export function draw(ctx, { params }) {
|
|
6
|
+
const pixels = ctx.getTransform().a;
|
|
7
|
+
ctx.shadowColor = '#00000055'; ctx.shadowBlur = 2 * pixels; ctx.shadowOffsetY = pixels;
|
|
8
|
+
ctx.beginPath(); ctx.arc(12, 12, 12, 0, 2 * Math.PI);
|
|
9
|
+
ctx.fillStyle = params.color ?? '#ffffff'; ctx.fill();
|
|
10
|
+
ctx.shadowColor = 'transparent';
|
|
11
|
+
ctx.lineWidth = 1.5; ctx.strokeStyle = '#171717'; ctx.beginPath(); ctx.arc(12, 12, 11.25, 0, 2 * Math.PI); ctx.stroke();
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Fluted glass: soft light in the page's brand color seen through glass ribs, over near black.
|
|
2
|
+
// Parameters: count (ribs across the short side), strength (how far a rib bends the light, as a
|
|
3
|
+
// fraction of the short side), angle (rib tilt in degrees). Set uBrand to light it in another color.
|
|
4
|
+
|
|
5
|
+
vec3 hueShift(vec3 c, float turn) {
|
|
6
|
+
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
7
|
+
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
|
8
|
+
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
|
9
|
+
float d = q.x - min(q.w, q.y);
|
|
10
|
+
vec3 hsv = vec3(fract(abs(q.z + (q.w - q.y) / (6.0 * d + 1e-10)) + turn), d / (q.x + 1e-10), q.x);
|
|
11
|
+
return hsv.z * mix(vec3(1.0), clamp(abs(mod(hsv.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0), hsv.y);
|
|
12
|
+
}
|
|
13
|
+
float blob(vec2 uv, vec2 c, float r) { return exp(-dot(uv - c, uv - c) / (r * r)); }
|
|
14
|
+
// Light placed where the margins around the window show; uv is 0–1 across the short side, centered.
|
|
15
|
+
vec3 light(vec2 uv) {
|
|
16
|
+
return uBrand * 0.06
|
|
17
|
+
+ uBrand * blob(uv, vec2(0.15, 0.95), 0.42)
|
|
18
|
+
+ hueShift(uBrand, 0.1) * blob(uv, vec2(0.92, 0.08), 0.38) * 0.9
|
|
19
|
+
+ hueShift(uBrand, -0.11) * blob(uv, vec2(0.85, 0.9), 0.3) * 0.7
|
|
20
|
+
+ hueShift(uBrand, 0.04) * blob(uv, vec2(0.05, 0.15), 0.25) * 0.5;
|
|
21
|
+
}
|
|
22
|
+
float hash(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }
|
|
23
|
+
|
|
24
|
+
void main() {
|
|
25
|
+
vec2 px = pixel(), center = uResolution * 0.5;
|
|
26
|
+
float side = min(uResolution.x, uResolution.y), a = radians(angle);
|
|
27
|
+
vec2 across = vec2(cos(a), sin(a));
|
|
28
|
+
float w = side / count, u = fract(dot(px - center, across) / w);
|
|
29
|
+
vec2 bent = px + across * (u - 0.5) * strength * side;
|
|
30
|
+
vec3 c = light((bent - center) / side + 0.5);
|
|
31
|
+
c *= 0.78 + 0.34 * pow(u, 1.6); // each rib darkens toward one edge
|
|
32
|
+
c += 0.05 * smoothstep(0.9, 1.0, u); // and catches a highlight on the other
|
|
33
|
+
c += (hash(px) - 0.5) * 0.05; // grain keeps H.264 from banding the light
|
|
34
|
+
color = vec4(c, 1.0);
|
|
35
|
+
}
|
|
@@ -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,12 @@
|
|
|
1
|
+
// A macOS app window's title bar: traffic lights only. Parameters: dark (a dark bar).
|
|
2
|
+
// Drawn in CSS pixels; CueTake clips it to the window's rounded top.
|
|
3
|
+
export const height = 28;
|
|
4
|
+
|
|
5
|
+
export function draw(ctx, { width, height, params }) {
|
|
6
|
+
ctx.fillStyle = params.dark ? '#2a2a2e' : '#ececef'; ctx.fillRect(0, 0, width, height);
|
|
7
|
+
ctx.fillStyle = params.dark ? '#111113' : '#d4d4d8'; ctx.fillRect(0, height - 1, width, 1);
|
|
8
|
+
['#ff5f57', '#febc2e', '#28c840'].forEach((light, i) => {
|
|
9
|
+
ctx.beginPath(); ctx.arc(16 + i * 20, height / 2, 6, 0, 2 * Math.PI);
|
|
10
|
+
ctx.fillStyle = light; ctx.fill(); ctx.strokeStyle = '#0000001f'; ctx.lineWidth = 0.5; ctx.stroke();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// A soft drop shadow under the window and a faint light rim around it. It follows the window as the
|
|
2
|
+
// camera zooms and moves it. Parameters: blur and offset (1080p pixels at zoom 1), opacity and rim (0–1).
|
|
3
|
+
|
|
4
|
+
void main() {
|
|
5
|
+
vec2 px = pixel();
|
|
6
|
+
float k = uUnit * uZoom;
|
|
7
|
+
float shadow = opacity * (1.0 - smoothstep(-blur * k, blur * k, windowDistance(px - vec2(0.0, offset * k))));
|
|
8
|
+
float edge = rim * (1.0 - smoothstep(0.0, 1.5, abs(windowDistance(px))));
|
|
9
|
+
color = vec4(vec3(edge), edge + shadow * (1.0 - edge));
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// A spark: `count` rays burst out from the click to `radius` CSS px, shrinking from `length` and fading.
|
|
2
|
+
// Rays are the cursor's color unless `color` is set, with a dark edge so they read on any page.
|
|
3
|
+
export const reach = ({ radius, length }) => radius + length + 8;
|
|
4
|
+
|
|
5
|
+
export function draw(ctx, { progress, params, cursor }) {
|
|
6
|
+
const { radius, length: rayLength, count } = params, color = params.color ?? cursor.color ?? '#ffffff';
|
|
7
|
+
const eased = 1 - (1 - progress) ** 3;
|
|
8
|
+
const distance = 5 + eased * radius, length = rayLength * (1 - eased);
|
|
9
|
+
ctx.globalAlpha = 1 - progress;
|
|
10
|
+
ctx.lineCap = 'round';
|
|
11
|
+
for (let i = 0; i < count; i++) {
|
|
12
|
+
const angle = 2 * Math.PI * i / count + Math.PI / 8;
|
|
13
|
+
ctx.beginPath();
|
|
14
|
+
ctx.moveTo(distance * Math.cos(angle), distance * Math.sin(angle));
|
|
15
|
+
ctx.lineTo((distance + length) * Math.cos(angle), (distance + length) * Math.sin(angle));
|
|
16
|
+
ctx.strokeStyle = '#171717'; ctx.lineWidth = 4.5; ctx.stroke();
|
|
17
|
+
ctx.strokeStyle = color; ctx.lineWidth = 2.5; ctx.stroke();
|
|
18
|
+
}
|
|
19
|
+
}
|