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
|
@@ -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
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { basename, extname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The files an Edit or Look draws with (ADR 0005). A ref with an extension is a file, relative to the
|
|
7
|
+
* Take, Look or Scenario that names it; a ref without one is a built-in from src/styles, with the
|
|
8
|
+
* parameters it starts from. Built-ins are ordinary files agents can read and copy.
|
|
9
|
+
*/
|
|
10
|
+
export const BUILTIN_DIR = fileURLToPath(new URL('./styles/', import.meta.url));
|
|
11
|
+
export const BUILTINS = {
|
|
12
|
+
fluted: { file: 'fluted.glsl', params: { count: 36, strength: 0.09, angle: 0 } },
|
|
13
|
+
shadow: { file: 'shadow.glsl', params: { blur: 60, offset: 24, opacity: 0.5, rim: 0.12 } },
|
|
14
|
+
browser: { file: 'browser.js', params: { dark: false } },
|
|
15
|
+
'browser-dark': { file: 'browser.js', params: { dark: true } },
|
|
16
|
+
macos: { file: 'macos.js', params: { dark: false } },
|
|
17
|
+
'macos-dark': { file: 'macos.js', params: { dark: true } },
|
|
18
|
+
arrow: { file: 'arrow.js', params: { thin: false } },
|
|
19
|
+
'arrow-thin': { file: 'arrow.js', params: { thin: true } },
|
|
20
|
+
dot: { file: 'dot.js', params: {} },
|
|
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
|
+
};
|
|
25
|
+
export const KINDS = ['shader', 'draw', 'image'];
|
|
26
|
+
export const isFile = ref => typeof ref === 'string' && extname(ref) !== '';
|
|
27
|
+
|
|
28
|
+
/** Every drawn item an Edit or (partial) Look holds. */
|
|
29
|
+
function items(style) {
|
|
30
|
+
const { frame, cursor, clickEffect, keycaps, subtitles } = style ?? {};
|
|
31
|
+
return [...(Array.isArray(frame?.background) ? frame.background : []), ...(Array.isArray(frame?.effects) ? frame.effects : []), frame?.chrome, cursor, clickEffect, keycaps, subtitles]
|
|
32
|
+
.filter(item => item && typeof item === 'object');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A copy of `style` with every file ref (an item's drawing and its `files`) replaced by `map(ref)`. */
|
|
36
|
+
export function mapFiles(style, map) {
|
|
37
|
+
const copy = structuredClone(style);
|
|
38
|
+
for (const item of items(copy)) {
|
|
39
|
+
for (const key of KINDS) if (isFile(item[key])) item[key] = map(item[key]);
|
|
40
|
+
if (item.files) item.files = Object.fromEntries(Object.entries(item.files).map(([name, ref]) => [name, isFile(ref) ? map(ref) : ref]));
|
|
41
|
+
}
|
|
42
|
+
return copy;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The file refs `style` names, in order, without repeats. */
|
|
46
|
+
export function fileRefs(style) {
|
|
47
|
+
const refs = new Set();
|
|
48
|
+
mapFiles(style, ref => refs.add(ref));
|
|
49
|
+
return [...refs];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The shader and drawing-code files `style` runs, for an agent to review before using a Look. */
|
|
53
|
+
export function codeRefs(style) {
|
|
54
|
+
return [...new Set(items(style).flatMap(item => ['shader', 'draw'].map(key => item[key]).filter(isFile)))];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Refs made absolute against `dir`, so styling from several places can be merged. */
|
|
58
|
+
export const absolute = (style, dir) => mapFiles(style, ref => resolve(dir, ref));
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Copies every file `style` names (resolved against `fromDir`) into `toDir` and points the refs at the
|
|
62
|
+
* copies as `prefix + name`. Files already inside `toDir` stay; a different file with a taken name gets a suffix.
|
|
63
|
+
*/
|
|
64
|
+
export async function bundle(style, fromDir, toDir, prefix = '') {
|
|
65
|
+
const copies = new Map();
|
|
66
|
+
for (const ref of fileRefs(style)) {
|
|
67
|
+
const source = resolve(fromDir, ref);
|
|
68
|
+
if (!relative(toDir, source).startsWith('..') && !isAbsolute(relative(toDir, source))) { copies.set(ref, prefix + relative(toDir, source)); continue; }
|
|
69
|
+
const bytes = await fs.readFile(source);
|
|
70
|
+
await fs.mkdir(toDir, { recursive: true });
|
|
71
|
+
const ext = extname(source), stem = basename(source, ext);
|
|
72
|
+
for (let n = 1; ; n++) {
|
|
73
|
+
const name = n === 1 ? stem + ext : `${stem}-${n}${ext}`, target = join(toDir, name);
|
|
74
|
+
const existing = await fs.readFile(target).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
75
|
+
if (existing && !existing.equals(bytes)) continue;
|
|
76
|
+
if (!existing) await fs.writeFile(target, bytes);
|
|
77
|
+
copies.set(ref, prefix + name);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return mapFiles(style, ref => copies.get(ref));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const PAGE_TYPES = { '.js': 'text/javascript', '.mjs': 'text/javascript', '.glsl': 'text/plain', '.frag': 'text/plain', '.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.woff2': 'font/woff2', '.woff': 'font/woff', '.ttf': 'font/ttf', '.otf': 'font/otf' };
|
|
85
|
+
export const contentType = path => PAGE_TYPES[extname(path).toLowerCase()] ?? 'application/octet-stream';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The Edit as the render page reads it: each drawing becomes a URL under `/files/` (with its built-in
|
|
89
|
+
* parameters underneath the item's own). Refs resolve against `dir`; `files` collects the served
|
|
90
|
+
* names and paths, and may be shared by several Edits.
|
|
91
|
+
*/
|
|
92
|
+
export function forRender(edit, dir, files = {}) {
|
|
93
|
+
const serve = path => {
|
|
94
|
+
let name = Object.keys(files).find(key => files[key] === path);
|
|
95
|
+
if (!name) { name = `style-${Object.keys(files).length}${extname(path)}`; files[name] = path; }
|
|
96
|
+
return `/files/${name}`;
|
|
97
|
+
};
|
|
98
|
+
const copy = structuredClone(edit);
|
|
99
|
+
for (const item of items(copy)) {
|
|
100
|
+
const kind = KINDS.find(key => item[key] !== undefined);
|
|
101
|
+
if (!kind) continue;
|
|
102
|
+
const ref = item[kind], builtin = !isFile(ref) && BUILTINS[ref];
|
|
103
|
+
if (!isFile(ref) && !builtin) throw new Error(`No built-in named '${ref}'; built-ins are ${Object.keys(BUILTINS).join(', ')}, or name a file with its extension`);
|
|
104
|
+
Object.assign(item, { ...(builtin ? builtin.params : {}), ...item, ref, kind, url: serve(builtin ? join(BUILTIN_DIR, builtin.file) : resolve(dir, ref)) });
|
|
105
|
+
if (item.files) item.files = Object.fromEntries(Object.entries(item.files).map(([name, file]) => [name, serve(resolve(dir, file))]));
|
|
106
|
+
}
|
|
107
|
+
return { edit: copy, files };
|
|
108
|
+
}
|
package/src/uninstall.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { authProfileFiles } from './auth.js';
|
|
6
|
+
import { globalLookFiles } from './look.js';
|
|
7
|
+
import { uninstallBrowser } from './environment.js';
|
|
8
|
+
|
|
9
|
+
const PACKAGE_DIR = fileURLToPath(new URL('..', import.meta.url)).replace(/[\\/]$/, '');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The npx folders made for CueTake alone, in any version. The one this CLI runs from is
|
|
13
|
+
* `<cache>/_npx/<hash>/node_modules/cuetake`; npx folders that also hold other packages are not CueTake's.
|
|
14
|
+
*/
|
|
15
|
+
export async function npxFolders({ cache = process.env.npm_config_cache || join(homedir(), '.npm'), packageDir = PACKAGE_DIR } = {}) {
|
|
16
|
+
const own = dirname(dirname(packageDir)), roots = new Set([join(cache, '_npx')]);
|
|
17
|
+
if (basename(dirname(own)) === '_npx' && basename(packageDir) === 'cuetake') roots.add(dirname(own));
|
|
18
|
+
const found = [];
|
|
19
|
+
for (const root of roots) {
|
|
20
|
+
const names = await fs.readdir(root).catch(error => { if (['ENOENT', 'ENOTDIR'].includes(error.code)) return []; throw error; });
|
|
21
|
+
for (const name of names) {
|
|
22
|
+
const manifest = await fs.readFile(join(root, name, 'package.json'), 'utf8').then(JSON.parse, () => null);
|
|
23
|
+
if (manifest && Object.keys(manifest.dependencies ?? {}).join() === 'cuetake') found.push(join(root, name));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return found.sort();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Removes what CueTake put on this machine outside the user's projects: its npx folders and, through
|
|
31
|
+
* Playwright, the browser unless another Playwright installation still uses it. Auth profiles and global
|
|
32
|
+
* Looks are the user's and go only when asked. Take folders and local Looks are never touched.
|
|
33
|
+
*/
|
|
34
|
+
export async function uninstall({ auth = false, looks = false, dryRun = false, removeBrowser = uninstallBrowser } = {}) {
|
|
35
|
+
const npx = await npxFolders(), profiles = await authProfileFiles(), globalLooks = await globalLookFiles();
|
|
36
|
+
const removed = [], kept = [];
|
|
37
|
+
const remove = async (item, paths) => {
|
|
38
|
+
for (const path of paths) {
|
|
39
|
+
if (!dryRun) await fs.rm(path, { recursive: true, force: true });
|
|
40
|
+
removed.push({ item, path });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const own = dirname(dirname(PACKAGE_DIR));
|
|
44
|
+
// Old CueTake versions go first so Playwright no longer counts their claim on the browser.
|
|
45
|
+
await remove('npx cache', npx.filter(path => path !== own));
|
|
46
|
+
const browser = await removeBrowser({ dryRun });
|
|
47
|
+
if (browser.existed && dryRun) removed.push({ item: 'browser', path: browser.path, note: 'kept if another Playwright installation still uses it' });
|
|
48
|
+
else if (browser.removed) removed.push({ item: 'browser', path: browser.path });
|
|
49
|
+
else if (browser.existed) kept.push({ item: 'browser', path: browser.path, reason: 'another Playwright installation still uses it' });
|
|
50
|
+
for (const [item, flag, wanted, { dir, paths }] of [['Auth profile', '--auth', auth, profiles], ['global Look', '--looks', looks, globalLooks]]) {
|
|
51
|
+
if (wanted) await remove(item, paths);
|
|
52
|
+
else if (paths.length) kept.push({ item, path: dir, count: paths.length, reason: `pass ${flag} to remove` });
|
|
53
|
+
if (wanted && !dryRun) await fs.rmdir(dir).catch(() => {});
|
|
54
|
+
}
|
|
55
|
+
// This CLI's own npx folder goes last, once nothing else needs its files.
|
|
56
|
+
await remove('npx cache', npx.filter(path => path === own));
|
|
57
|
+
if (!dryRun) await fs.rmdir(join(homedir(), '.local/share/cuetake')).catch(() => {});
|
|
58
|
+
return {
|
|
59
|
+
dryRun, [dryRun ? 'wouldRemove' : 'removed']: removed, kept,
|
|
60
|
+
note: 'Take folders and local Looks (.cuetake/looks) stay in your projects. The skill is removed by the tool that installed it.',
|
|
61
|
+
};
|
|
62
|
+
}
|