autokast 0.0.0 → 0.1.1

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.
Files changed (79) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +165 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +300 -0
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.js +4 -0
  7. package/dist/inspect.d.ts +26 -0
  8. package/dist/inspect.js +193 -0
  9. package/dist/record/animations.d.ts +7 -0
  10. package/dist/record/animations.js +34 -0
  11. package/dist/record/capture.d.ts +85 -0
  12. package/dist/record/capture.js +202 -0
  13. package/dist/record/cast.d.ts +142 -0
  14. package/dist/record/cast.js +680 -0
  15. package/dist/record/cursor-style.d.ts +33 -0
  16. package/dist/record/cursor-style.js +252 -0
  17. package/dist/record/defaults.d.ts +96 -0
  18. package/dist/record/defaults.js +125 -0
  19. package/dist/record/editor.d.ts +11 -0
  20. package/dist/record/editor.js +48 -0
  21. package/dist/record/frame-pump.d.ts +91 -0
  22. package/dist/record/frame-pump.js +306 -0
  23. package/dist/record/index.d.ts +11 -0
  24. package/dist/record/index.js +287 -0
  25. package/dist/record/motion.d.ts +48 -0
  26. package/dist/record/motion.js +112 -0
  27. package/dist/record/pace.d.ts +69 -0
  28. package/dist/record/pace.js +133 -0
  29. package/dist/record/random.d.ts +12 -0
  30. package/dist/record/random.js +24 -0
  31. package/dist/record/scroll.d.ts +71 -0
  32. package/dist/record/scroll.js +249 -0
  33. package/dist/record/timeline.d.ts +34 -0
  34. package/dist/record/timeline.js +44 -0
  35. package/dist/render/background.d.ts +12 -0
  36. package/dist/render/background.js +209 -0
  37. package/dist/render/browser.d.ts +46 -0
  38. package/dist/render/browser.js +223 -0
  39. package/dist/render/camera.d.ts +119 -0
  40. package/dist/render/camera.js +372 -0
  41. package/dist/render/captions.d.ts +114 -0
  42. package/dist/render/captions.js +254 -0
  43. package/dist/render/color.d.ts +23 -0
  44. package/dist/render/color.js +78 -0
  45. package/dist/render/compositor.d.ts +185 -0
  46. package/dist/render/compositor.js +656 -0
  47. package/dist/render/cursor.d.ts +85 -0
  48. package/dist/render/cursor.js +314 -0
  49. package/dist/render/cursors/shapes.d.ts +34 -0
  50. package/dist/render/cursors/shapes.js +268 -0
  51. package/dist/render/defaults.d.ts +91 -0
  52. package/dist/render/defaults.js +139 -0
  53. package/dist/render/easing.d.ts +13 -0
  54. package/dist/render/easing.js +40 -0
  55. package/dist/render/effects.d.ts +39 -0
  56. package/dist/render/effects.js +91 -0
  57. package/dist/render/encoder.d.ts +52 -0
  58. package/dist/render/encoder.js +226 -0
  59. package/dist/render/index.d.ts +19 -0
  60. package/dist/render/index.js +138 -0
  61. package/dist/render/keycaps.d.ts +67 -0
  62. package/dist/render/keycaps.js +270 -0
  63. package/dist/render/scene.d.ts +59 -0
  64. package/dist/render/scene.js +230 -0
  65. package/dist/render/source.d.ts +21 -0
  66. package/dist/render/source.js +57 -0
  67. package/dist/render/spring.d.ts +11 -0
  68. package/dist/render/spring.js +47 -0
  69. package/dist/render/stage.d.ts +59 -0
  70. package/dist/render/stage.js +91 -0
  71. package/dist/render/timeline.d.ts +70 -0
  72. package/dist/render/timeline.js +157 -0
  73. package/dist/session.d.ts +14 -0
  74. package/dist/session.js +33 -0
  75. package/dist/types.d.ts +708 -0
  76. package/dist/types.js +1 -0
  77. package/package.json +61 -3
  78. package/skills/autokast/SKILL.md +300 -0
  79. package/skills/autokast/reference/jupyterlab.md +100 -0
@@ -0,0 +1,19 @@
1
+ import type { RenderOptions, RenderResult, Session } from '../types.ts';
2
+ import { BACKGROUND_PRESETS } from './background.ts';
3
+ export { BACKGROUND_PRESETS };
4
+ /**
5
+ * Output duration of a session in milliseconds, after cuts and speed changes.
6
+ */
7
+ export declare function outputDuration(session: Session): number;
8
+ /**
9
+ * Output time (ms) of a record time. A time inside a cut maps to the cut point.
10
+ */
11
+ export declare function toOutputTime(session: Session, recordTime: number): number;
12
+ /**
13
+ * Renders a recorded session to a video file.
14
+ */
15
+ export declare function render(sessionDir: string, options?: RenderOptions): Promise<RenderResult>;
16
+ /**
17
+ * Renders one still frame at an output time (milliseconds) and returns a PNG.
18
+ */
19
+ export declare function renderFrame(sessionDir: string, time: number, options?: RenderOptions): Promise<Buffer>;
@@ -0,0 +1,138 @@
1
+ import { mkdir, mkdtemp, rm } from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { loadSession } from "../session.js";
5
+ import { BACKGROUND_PRESETS, createBackground } from "./background.js";
6
+ import { Compositor } from "./compositor.js";
7
+ import { checkFfmpeg, encoderArgs, FfmpegProcess, ffmpegPath, gifArgs, gifSettings, runFfmpeg, } from "./encoder.js";
8
+ import { buildScene, frameInput, frameInputs } from "./scene.js";
9
+ import { FrameSource, upcomingFrames } from "./source.js";
10
+ import { frameIndexAt, sessionTimeMap } from "./timeline.js";
11
+ export { BACKGROUND_PRESETS };
12
+ /**
13
+ * Output duration of a session in milliseconds, after cuts and speed changes.
14
+ */
15
+ export function outputDuration(session) {
16
+ return sessionTimeMap(session).duration;
17
+ }
18
+ /**
19
+ * Output time (ms) of a record time. A time inside a cut maps to the cut point.
20
+ */
21
+ export function toOutputTime(session, recordTime) {
22
+ return sessionTimeMap(session).toOutput(recordTime);
23
+ }
24
+ async function setup(sessionDir, scene) {
25
+ const { options, layout } = scene;
26
+ const background = await createBackground(options.background, options.size, options.unit);
27
+ return {
28
+ compositor: new Compositor(options, layout, background, scene.band),
29
+ source: new FrameSource(sessionDir, scene.session.frames),
30
+ };
31
+ }
32
+ function nearestFrame(times, t) {
33
+ let lo = 0;
34
+ let hi = times.length - 1;
35
+ while (lo < hi) {
36
+ const mid = (lo + hi) >> 1;
37
+ if (times[mid] < t)
38
+ lo = mid + 1;
39
+ else
40
+ hi = mid;
41
+ }
42
+ return lo;
43
+ }
44
+ async function drawFrame(scene, compositor, source, i) {
45
+ const index = scene.frameIndex[i];
46
+ const image = await source.get(index);
47
+ source.retain(index, upcomingFrames(scene.frameIndex, i, 4));
48
+ const inputs = frameInputs(scene, i).map((input) => ({ ...input, image }));
49
+ for (const { mark } of inputs[0].clicks) {
50
+ if (!compositor.needsClickColor(mark))
51
+ continue;
52
+ const frame = frameIndexAt(scene.session.frames, mark.t);
53
+ compositor.prepareClick(mark, frame === index ? image : await source.get(frame));
54
+ }
55
+ for (const cue of inputs[0].keys) {
56
+ if (!compositor.needsKeyTheme(cue))
57
+ continue;
58
+ const j = nearestFrame(scene.times, cue.appear);
59
+ const frame = scene.frameIndex[j];
60
+ const behind = frame === index ? image : await source.get(frame);
61
+ compositor.prepareKeys(cue, { ...frameInput(scene, j), image: behind });
62
+ }
63
+ if (inputs.length > 1)
64
+ compositor.drawBlurred(inputs);
65
+ else
66
+ compositor.draw(inputs[0]);
67
+ }
68
+ /**
69
+ * Renders a recorded session to a video file.
70
+ */
71
+ export async function render(sessionDir, options) {
72
+ const session = await loadSession(sessionDir);
73
+ let scene = buildScene(session, options);
74
+ const format = scene.options.format;
75
+ if (format === 'gif') {
76
+ const gif = gifSettings(scene.options.size, scene.options.fps);
77
+ if (gif.fps !== scene.options.fps)
78
+ scene = buildScene(session, { ...options, fps: gif.fps });
79
+ }
80
+ const { options: opts, times } = scene;
81
+ const binary = ffmpegPath(opts);
82
+ await checkFfmpeg(binary);
83
+ await mkdir(path.dirname(opts.output), { recursive: true });
84
+ let first = 0;
85
+ while (first < times.length && times[first] < opts.range.start)
86
+ first++;
87
+ let last = first;
88
+ while (last < times.length && times[last] < opts.range.end)
89
+ last++;
90
+ const total = last - first;
91
+ const { compositor, source } = await setup(sessionDir, scene);
92
+ const temp = format === 'gif' ? await mkdtemp(path.join(os.tmpdir(), 'autokast-')) : null;
93
+ const target = temp ? path.join(temp, 'frames.mkv') : opts.output;
94
+ const encoder = new FfmpegProcess(binary, encoderArgs(temp ? 'mkv' : format === 'webm' ? 'webm' : 'mp4', opts.size, opts.fps, opts.encode, target));
95
+ try {
96
+ for (let i = first; i < last; i++) {
97
+ await drawFrame(scene, compositor, source, i);
98
+ await encoder.write(compositor.canvas.data());
99
+ opts.onProgress?.(i - first + 1, total);
100
+ }
101
+ await encoder.finish();
102
+ if (temp) {
103
+ const gif = gifSettings(opts.size, opts.fps);
104
+ await runFfmpeg(binary, gifArgs(target, opts.output, gif.fps, gif.width));
105
+ }
106
+ }
107
+ catch (error) {
108
+ encoder.kill();
109
+ throw error;
110
+ }
111
+ finally {
112
+ if (temp)
113
+ await rm(temp, { recursive: true, force: true });
114
+ }
115
+ let size = opts.size;
116
+ if (format === 'gif') {
117
+ const width = gifSettings(opts.size, opts.fps).width;
118
+ size = { width, height: Math.round((opts.size.height * width) / opts.size.width) };
119
+ }
120
+ return {
121
+ output: opts.output,
122
+ duration: (total * 1000) / opts.fps,
123
+ frames: total,
124
+ size,
125
+ fps: opts.fps,
126
+ };
127
+ }
128
+ /**
129
+ * Renders one still frame at an output time (milliseconds) and returns a PNG.
130
+ */
131
+ export async function renderFrame(sessionDir, time, options) {
132
+ const session = await loadSession(sessionDir);
133
+ const scene = buildScene(session, options, Math.max(0, time));
134
+ const i = scene.times.indexOf(Math.max(0, time));
135
+ const { compositor, source } = await setup(sessionDir, scene);
136
+ await drawFrame(scene, compositor, source, i);
137
+ return compositor.canvas.encode('png');
138
+ }
@@ -0,0 +1,67 @@
1
+ import { type SKRSContext2D } from '@napi-rs/canvas';
2
+ import type { KeyEvent } from '../types.ts';
3
+ import type { TimedEvent } from './timeline.ts';
4
+ /**
5
+ * One shortcut on screen: caps appear, are pressed one or more times, then leave.
6
+ */
7
+ export interface KeyCue {
8
+ keys: string[];
9
+ appear: number;
10
+ presses: number[];
11
+ fadeOut: number;
12
+ fadeDuration: number;
13
+ }
14
+ /**
15
+ * Key names on the caps: macOS (⌘ Cmd, ⌥ Opt) or Windows and Linux (Ctrl, Alt).
16
+ */
17
+ export type KeyLabels = 'mac' | 'pc';
18
+ /**
19
+ * Splits a combination such as `Control+Shift+C` into keys; `Control++` ends with `+`.
20
+ */
21
+ export declare function parseShortcut(combo: string, labels?: KeyLabels): string[];
22
+ /**
23
+ * What a cap shows: a glyph, a name, or both. Single characters show in upper case.
24
+ */
25
+ export declare function keyLabel(key: string, labels?: KeyLabels): {
26
+ glyph?: string;
27
+ name?: string;
28
+ };
29
+ /**
30
+ * Plans keycap cues for shortcut events. The same combination pressed again while shown
31
+ * presses the same caps; a new combination replaces the old one with a quick fade.
32
+ */
33
+ export declare function planKeys(events: TimedEvent<KeyEvent>[], labels?: KeyLabels): KeyCue[];
34
+ export declare function keyCueVisible(cue: KeyCue, t: number): boolean;
35
+ /**
36
+ * Press depth at time `t`, 0 to 1: a quick press and a slower release.
37
+ */
38
+ export declare function pressDepth(cue: KeyCue, t: number): number;
39
+ export interface CapTheme {
40
+ face: [string, string];
41
+ pressed: [string, string];
42
+ lip: string;
43
+ border: string;
44
+ highlight: string;
45
+ ink: string;
46
+ shadow: string;
47
+ contact: string;
48
+ }
49
+ export declare const LIGHT_CAPS: CapTheme;
50
+ export declare const DARK_CAPS: CapTheme;
51
+ export interface CapLayout {
52
+ key: string;
53
+ width: number;
54
+ glyph?: string;
55
+ name?: string;
56
+ }
57
+ /**
58
+ * Widths of the caps of a cue at a resolution unit.
59
+ */
60
+ export declare function capLayouts(keys: string[], unit: number, labels?: KeyLabels): CapLayout[];
61
+ export declare function capsWidth(caps: CapLayout[], unit: number): number;
62
+ /**
63
+ * Draws the caps of a cue with their top-left corner at (x, y), in output pixels. Each
64
+ * cap is a small physical key: a face with a top highlight on a darker lip, a contact
65
+ * shadow and a soft drop shadow. Pressed, the face sinks 2 units and darkens.
66
+ */
67
+ export declare function drawKeycaps(ctx: SKRSContext2D, cue: KeyCue, caps: CapLayout[], theme: CapTheme, x: number, y: number, unit: number, t: number): void;
@@ -0,0 +1,270 @@
1
+ import { createCanvas } from '@napi-rs/canvas';
2
+ import { clamp, smoothstep } from "./easing.js";
3
+ /**
4
+ * Timing of the keycaps, in output milliseconds.
5
+ */
6
+ const APPEAR = 180;
7
+ const PRESS_DOWN = 50;
8
+ const PRESS_UP = 120;
9
+ const HOLD = 1100;
10
+ const FADE = 250;
11
+ const REPLACE_FADE = 110;
12
+ const ALIASES = {
13
+ Command: 'Meta',
14
+ Cmd: 'Meta',
15
+ Ctrl: 'Control',
16
+ Option: 'Alt',
17
+ Return: 'Enter',
18
+ Esc: 'Escape',
19
+ ' ': 'Space',
20
+ };
21
+ /**
22
+ * Splits a combination such as `Control+Shift+C` into keys; `Control++` ends with `+`.
23
+ */
24
+ export function parseShortcut(combo, labels = 'mac') {
25
+ const keys = [];
26
+ let rest = combo;
27
+ while (rest.length) {
28
+ const i = rest.indexOf('+', 1);
29
+ if (i < 0) {
30
+ keys.push(rest);
31
+ break;
32
+ }
33
+ keys.push(rest.slice(0, i));
34
+ rest = rest.slice(i + 1);
35
+ }
36
+ const controlOrMeta = labels === 'mac' ? 'Meta' : 'Control';
37
+ return keys
38
+ .filter(Boolean)
39
+ .map((k) => (k === 'ControlOrMeta' ? controlOrMeta : (ALIASES[k] ?? k)));
40
+ }
41
+ const LABELS = {
42
+ Meta: { glyph: '⌘', name: 'Cmd' },
43
+ Control: { glyph: '⌃', name: 'Ctrl' },
44
+ Alt: { glyph: '⌥', name: 'Opt' },
45
+ Shift: { glyph: '⇧', name: 'Shift' },
46
+ Enter: { glyph: '↵', name: 'Enter' },
47
+ Tab: { glyph: '⇥', name: 'Tab' },
48
+ Escape: { glyph: '⎋', name: 'Esc' },
49
+ Backspace: { glyph: '⌫', name: 'Backspace' },
50
+ Delete: { glyph: '⌦', name: 'Del' },
51
+ ArrowUp: { glyph: '↑' },
52
+ ArrowDown: { glyph: '↓' },
53
+ ArrowLeft: { glyph: '←' },
54
+ ArrowRight: { glyph: '→' },
55
+ Space: { name: 'Space' },
56
+ PageUp: { name: 'Page Up' },
57
+ PageDown: { name: 'Page Down' },
58
+ Home: { name: 'Home' },
59
+ End: { name: 'End' },
60
+ };
61
+ const PC_LABELS = {
62
+ Meta: { name: 'Win' },
63
+ Control: { name: 'Ctrl' },
64
+ Alt: { name: 'Alt' },
65
+ Escape: { name: 'Esc' },
66
+ };
67
+ /**
68
+ * What a cap shows: a glyph, a name, or both. Single characters show in upper case.
69
+ */
70
+ export function keyLabel(key, labels = 'mac') {
71
+ const known = (labels === 'pc' ? PC_LABELS[key] : undefined) ?? LABELS[key];
72
+ if (known)
73
+ return known;
74
+ if (key.length === 1)
75
+ return { glyph: key.toUpperCase() };
76
+ if (/^Key[A-Z]$/.test(key))
77
+ return { glyph: key.slice(3) };
78
+ if (/^Digit[0-9]$/.test(key))
79
+ return { glyph: key.slice(5) };
80
+ return { name: key };
81
+ }
82
+ /**
83
+ * Plans keycap cues for shortcut events. The same combination pressed again while shown
84
+ * presses the same caps; a new combination replaces the old one with a quick fade.
85
+ */
86
+ export function planKeys(events, labels = 'mac') {
87
+ const cues = [];
88
+ const sorted = events.filter((e) => e.kind === 'shortcut').sort((a, b) => a.out - b.out);
89
+ for (const e of sorted) {
90
+ const keys = parseShortcut(e.key, labels);
91
+ if (!keys.length)
92
+ continue;
93
+ const last = cues[cues.length - 1];
94
+ if (last && last.keys.join('+') === keys.join('+') && e.out <= last.fadeOut) {
95
+ last.presses.push(e.out);
96
+ last.fadeOut = e.out + HOLD;
97
+ continue;
98
+ }
99
+ const appear = e.out - APPEAR;
100
+ if (last && appear < last.fadeOut + last.fadeDuration) {
101
+ last.fadeOut = Math.max(last.presses[last.presses.length - 1] + PRESS_UP, appear - REPLACE_FADE);
102
+ last.fadeDuration = REPLACE_FADE;
103
+ }
104
+ cues.push({ keys, appear, presses: [e.out], fadeOut: e.out + HOLD, fadeDuration: FADE });
105
+ }
106
+ return cues;
107
+ }
108
+ export function keyCueVisible(cue, t) {
109
+ return t >= cue.appear && t <= cue.fadeOut + cue.fadeDuration;
110
+ }
111
+ /**
112
+ * Press depth at time `t`, 0 to 1: a quick press and a slower release.
113
+ */
114
+ export function pressDepth(cue, t) {
115
+ let depth = 0;
116
+ for (const p of cue.presses) {
117
+ const down = smoothstep(p, p + PRESS_DOWN, t);
118
+ const up = smoothstep(p + PRESS_DOWN, p + PRESS_DOWN + PRESS_UP, t);
119
+ depth = Math.max(depth, down * (1 - up));
120
+ }
121
+ return depth;
122
+ }
123
+ export const LIGHT_CAPS = {
124
+ face: ['#fbfaf8', '#eeece8'],
125
+ pressed: ['#efedea', '#e2dfda'],
126
+ lip: '#c7c3bc',
127
+ border: 'rgba(0, 0, 0, 0.10)',
128
+ highlight: 'rgba(255, 255, 255, 0.95)',
129
+ ink: '#2a2b30',
130
+ shadow: 'rgba(0, 0, 0, 0.32)',
131
+ contact: 'rgba(0, 0, 0, 0.30)',
132
+ };
133
+ export const DARK_CAPS = {
134
+ face: ['#3a3b41', '#2d2e33'],
135
+ pressed: ['#313237', '#26272b'],
136
+ lip: '#141518',
137
+ border: 'rgba(255, 255, 255, 0.07)',
138
+ highlight: 'rgba(255, 255, 255, 0.16)',
139
+ ink: '#f2f0ec',
140
+ shadow: 'rgba(0, 0, 0, 0.26)',
141
+ contact: 'rgba(0, 0, 0, 0.35)',
142
+ };
143
+ const measurer = createCanvas(4, 4).getContext('2d');
144
+ /**
145
+ * Widths of the caps of a cue at a resolution unit.
146
+ */
147
+ export function capLayouts(keys, unit, labels = 'mac') {
148
+ const h = 40 * unit;
149
+ return keys.map((key) => {
150
+ const label = keyLabel(key, labels);
151
+ let content = 0;
152
+ if (label.glyph) {
153
+ measurer.font = glyphFont(label, unit);
154
+ content += measurer.measureText(label.glyph).width;
155
+ }
156
+ if (label.name) {
157
+ measurer.font = `500 ${14 * unit}px Inter`;
158
+ measurer.letterSpacing = '0px';
159
+ content += measurer.measureText(label.name).width + (label.glyph ? 7 * unit : 0);
160
+ }
161
+ const min = key === 'Space' ? 4 * h : h;
162
+ return { key, width: Math.max(min, content + 2 * 13 * unit), ...label };
163
+ });
164
+ }
165
+ function glyphFont(label, unit) {
166
+ return label.name ? `500 ${16 * unit}px Inter` : `600 ${17 * unit}px Inter`;
167
+ }
168
+ const CAP_GAP = 8;
169
+ export function capsWidth(caps, unit) {
170
+ return caps.reduce((w, c) => w + c.width, 0) + CAP_GAP * unit * (caps.length - 1);
171
+ }
172
+ /**
173
+ * Draws the caps of a cue with their top-left corner at (x, y), in output pixels. Each
174
+ * cap is a small physical key: a face with a top highlight on a darker lip, a contact
175
+ * shadow and a soft drop shadow. Pressed, the face sinks 2 units and darkens.
176
+ */
177
+ export function drawKeycaps(ctx, cue, caps, theme, x, y, unit, t) {
178
+ if (!keyCueVisible(cue, t))
179
+ return;
180
+ const u = unit;
181
+ const appear = clamp((t - cue.appear) / APPEAR, 0, 1);
182
+ const enter = 1 - (1 - appear) ** 3;
183
+ const leave = smoothstep(cue.fadeOut, cue.fadeOut + cue.fadeDuration, t);
184
+ const alpha = enter * (1 - leave);
185
+ if (alpha <= 0.002)
186
+ return;
187
+ const lift = (1 - enter) * 8 * u + leave * 3 * u;
188
+ const depth = pressDepth(cue, t);
189
+ const h = 40 * u;
190
+ const lip = 3.5 * u;
191
+ const radius = 8 * u;
192
+ const sink = 2 * u * depth;
193
+ ctx.save();
194
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
195
+ ctx.globalAlpha = alpha;
196
+ let cx = x;
197
+ const top = y + lift;
198
+ for (const cap of caps) {
199
+ const w = cap.width;
200
+ ctx.save();
201
+ ctx.beginPath();
202
+ ctx.roundRect(cx, top, w, h, radius);
203
+ ctx.fillStyle = theme.lip;
204
+ ctx.shadowColor = theme.shadow;
205
+ ctx.shadowBlur = (16 - 6 * depth) * u;
206
+ ctx.shadowOffsetY = (6 - 2 * depth) * u;
207
+ ctx.fill();
208
+ ctx.shadowColor = theme.contact;
209
+ ctx.shadowBlur = 2 * u;
210
+ ctx.shadowOffsetY = 1 * u;
211
+ ctx.fill();
212
+ ctx.restore();
213
+ const faceTop = top + sink;
214
+ const faceH = h - lip;
215
+ const colors = theme.face.map((c, i) => mix(c, theme.pressed[i], depth));
216
+ const g = ctx.createLinearGradient(0, faceTop, 0, faceTop + faceH);
217
+ g.addColorStop(0, colors[0]);
218
+ g.addColorStop(1, colors[1]);
219
+ ctx.beginPath();
220
+ ctx.roundRect(cx, faceTop, w, faceH, radius);
221
+ ctx.fillStyle = g;
222
+ ctx.fill();
223
+ ctx.lineWidth = u;
224
+ ctx.strokeStyle = theme.border;
225
+ ctx.beginPath();
226
+ ctx.roundRect(cx + u / 2, top + u / 2, w - u, h - u, radius - u / 2);
227
+ ctx.stroke();
228
+ ctx.save();
229
+ ctx.beginPath();
230
+ ctx.roundRect(cx, faceTop, w, faceH, radius);
231
+ ctx.clip();
232
+ ctx.beginPath();
233
+ ctx.roundRect(cx + u * 0.75, faceTop + u * 0.75, w - 1.5 * u, faceH + 4 * u, radius - u);
234
+ ctx.strokeStyle = theme.highlight;
235
+ ctx.lineWidth = 1.2 * u;
236
+ ctx.stroke();
237
+ ctx.restore();
238
+ ctx.fillStyle = theme.ink;
239
+ ctx.textBaseline = 'middle';
240
+ ctx.letterSpacing = '0px';
241
+ const mid = faceTop + faceH / 2 + 0.5 * u;
242
+ if (cap.glyph && cap.name) {
243
+ ctx.font = glyphFont(cap, u);
244
+ const gw = ctx.measureText(cap.glyph).width;
245
+ ctx.font = `500 ${14 * u}px Inter`;
246
+ const nw = ctx.measureText(cap.name).width;
247
+ let tx = cx + (w - gw - 7 * u - nw) / 2;
248
+ ctx.textAlign = 'left';
249
+ ctx.font = glyphFont(cap, u);
250
+ ctx.fillText(cap.glyph, tx, mid);
251
+ tx += gw + 7 * u;
252
+ ctx.font = `500 ${14 * u}px Inter`;
253
+ ctx.fillText(cap.name, tx, mid);
254
+ }
255
+ else {
256
+ ctx.textAlign = 'center';
257
+ ctx.font = glyphFont(cap, u);
258
+ ctx.fillText(cap.glyph ?? cap.name ?? '', cx + w / 2, mid);
259
+ }
260
+ cx += w + CAP_GAP * u;
261
+ }
262
+ ctx.restore();
263
+ }
264
+ function mix(a, b, t) {
265
+ const pa = parseInt(a.slice(1), 16);
266
+ const pb = parseInt(b.slice(1), 16);
267
+ const ch = (p, s) => (p >> s) & 255;
268
+ const v = (s) => Math.round(ch(pa, s) + (ch(pb, s) - ch(pa, s)) * t);
269
+ return `rgb(${v(16)}, ${v(8)}, ${v(0)})`;
270
+ }
@@ -0,0 +1,59 @@
1
+ import type { RenderOptions, Session, SpotlightEvent, UrlEvent } from '../types.ts';
2
+ import { type CameraTrack } from './camera.ts';
3
+ import { type CaptionCue } from './captions.ts';
4
+ import { type FrameInput, type Layout } from './compositor.ts';
5
+ import { type ClickMark, type CursorTrack } from './cursor.ts';
6
+ import { type ResolvedOptions } from './defaults.ts';
7
+ import { type KeyCue } from './keycaps.ts';
8
+ import { type BandLayout } from './stage.ts';
9
+ import { type TimedEvent, type TimeMap } from './timeline.ts';
10
+ /**
11
+ * Everything precomputed for a render: options, layout, and per-frame camera, cursor and
12
+ * source frame. Stateful motion (springs, interrupted transitions) is solved here in one
13
+ * pass over all output frames.
14
+ */
15
+ export interface Scene {
16
+ session: Session;
17
+ options: ResolvedOptions;
18
+ map: TimeMap;
19
+ layout: Layout;
20
+ times: Float64Array;
21
+ camera: CameraTrack;
22
+ cursor: CursorTrack;
23
+ clicks: ClickMark[];
24
+ spotlights: TimedEvent<SpotlightEvent>[];
25
+ captions: CaptionCue[];
26
+ keys: KeyCue[];
27
+ /**
28
+ * Addresses of the page, in output time order, for the browser frame.
29
+ */
30
+ urls: TimedEvent<UrlEvent>[];
31
+ /**
32
+ * Caption band geometry when open, or null without captions.
33
+ */
34
+ band: BandLayout | null;
35
+ /**
36
+ * How far the caption band is open at each output frame, 0 to 1.
37
+ */
38
+ bandOpen: Float64Array;
39
+ /**
40
+ * Index into `session.frames` for each output frame.
41
+ */
42
+ frameIndex: Int32Array;
43
+ }
44
+ /**
45
+ * Builds the scene. `extraTime` adds one output time to the frame grid (for a still
46
+ * between two frames).
47
+ */
48
+ export declare function buildScene(session: Session, options?: RenderOptions, extraTime?: number): Scene;
49
+ type Input = Omit<FrameInput, 'image'>;
50
+ /**
51
+ * Compositor inputs for output frame `i`, without the source image. More than one input
52
+ * means camera motion blur: the compositor averages them.
53
+ */
54
+ export declare function frameInputs(scene: Scene, i: number): Input[];
55
+ /**
56
+ * Compositor input for output frame `i`, without the source image or motion blur.
57
+ */
58
+ export declare function frameInput(scene: Scene, i: number): Input;
59
+ export {};