agentcut 0.2.25 → 0.2.27
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 +177 -148
- package/dist/config.d.ts +0 -1
- package/dist/config.js +0 -5
- package/dist/config.js.map +1 -1
- package/dist/studio/agents/claude.js +3 -2
- package/dist/studio/agents/claude.js.map +1 -1
- package/dist/studio/chat.js +1 -1
- package/dist/studio/chat.js.map +1 -1
- package/dist/studio/cli.js +40 -21
- package/dist/studio/cli.js.map +1 -1
- package/dist/studio/download.d.ts +24 -0
- package/dist/studio/download.js +234 -0
- package/dist/studio/download.js.map +1 -0
- package/dist/studio/host.d.ts +1 -2
- package/dist/studio/host.js +36 -8
- package/dist/studio/host.js.map +1 -1
- package/dist/studio/housekeeping.d.ts +2 -2
- package/dist/studio/housekeeping.js +18 -17
- package/dist/studio/housekeeping.js.map +1 -1
- package/dist/studio/mcp-guides.js +1 -18
- package/dist/studio/mcp-guides.js.map +1 -1
- package/dist/studio/proc.js +16 -6
- package/dist/studio/proc.js.map +1 -1
- package/dist/studio/proxies.d.ts +4 -0
- package/dist/studio/proxies.js +15 -6
- package/dist/studio/proxies.js.map +1 -1
- package/dist/studio/release-cursor.js +21 -21
- package/dist/studio/release-video.js +10 -10
- package/dist/studio/schema.d.ts +0 -1
- package/dist/studio/schema.js +0 -1
- package/dist/studio/schema.js.map +1 -1
- package/dist/studio/tools.d.ts +0 -4
- package/dist/studio/tools.js +32 -31
- package/dist/studio/tools.js.map +1 -1
- package/dist/studio/voice/kokoro-catalog.d.ts +56 -28
- package/dist/studio/voice/kokoro-catalog.js +56 -28
- package/dist/studio/voice/kokoro-catalog.js.map +1 -1
- package/dist/studio/voice/ming-catalog.d.ts +19 -0
- package/dist/studio/voice/ming-catalog.js +40 -0
- package/dist/studio/voice/ming-catalog.js.map +1 -0
- package/dist/studio/voice/ming.d.ts +12 -0
- package/dist/studio/voice/ming.js +397 -0
- package/dist/studio/voice/ming.js.map +1 -0
- package/dist/studio/voice/previews.d.ts +5 -0
- package/dist/studio/voice/previews.js +50 -0
- package/dist/studio/voice/previews.js.map +1 -0
- package/dist/studio/voice/registry.js +2 -0
- package/dist/studio/voice/registry.js.map +1 -1
- package/dist/studio/voice.d.ts +1 -1
- package/dist/studio/voice.js +5 -6
- package/dist/studio/voice.js.map +1 -1
- package/package.json +56 -56
- package/template/AGENTS.md +14 -14
- package/template/components/README.md +70 -70
- package/template/components/before-after/BeforeAfter.tsx +89 -89
- package/template/components/catalog.ts +107 -107
- package/template/components/cinematic/Device3D.tsx +324 -324
- package/template/components/cinematic/devices3d/display-model.ts +184 -184
- package/template/components/cinematic/devices3d/iphone-model.ts +643 -643
- package/template/components/cinematic/devices3d/macbook-model.ts +608 -608
- package/template/components/cinematic/devices3d/models.ts +657 -657
- package/template/components/cinematic/devices3d/runtime.ts +267 -267
- package/template/components/cinematic/math.ts +100 -100
- package/template/components/color/grade-effect.ts +650 -650
- package/template/components/color/grade.ts +512 -512
- package/template/components/color/looks.ts +154 -154
- package/template/components/countdown/Countdown.tsx +166 -166
- package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -181
- package/template/components/dot-trace-title/meta.json +51 -51
- package/template/components/generate/GenerateReveal.tsx +381 -381
- package/template/components/hook-card/HookCard.tsx +554 -554
- package/template/components/index.ts +199 -199
- package/template/components/lib.ts +191 -191
- package/template/components/line-diagram/LineDiagram.tsx +205 -205
- package/template/components/line-diagram/meta.json +215 -215
- package/template/components/list-card/ListCard.tsx +104 -104
- package/template/components/live-clip.ts +75 -75
- package/template/components/looks.tsx +1447 -1447
- package/template/components/loops/LoopCanvas.tsx +132 -132
- package/template/components/loops/engine.ts +184 -184
- package/template/components/loops/library.ts +667 -667
- package/template/components/loops/library2.ts +777 -777
- package/template/components/motion-loop/MotionLoop.tsx +37 -37
- package/template/components/motion-loop/meta.json +311 -311
- package/template/components/props.ts +73 -73
- package/template/components/quote-card/QuoteCard.tsx +71 -71
- package/template/components/style-layer.tsx +233 -233
- package/template/components/styles.ts +113 -113
- package/template/components/types.ts +66 -66
- package/template/components/word-pop/WordPop.tsx +59 -59
- package/template/components/word-stack/WordStack.tsx +122 -122
- package/template/presets/charcoal-sketch/PROMPT.md +48 -48
- package/template/presets/charcoal-sketch/scripts/duck_music.py +34 -34
- package/template/presets/punk-cut-paper/scenes/Motif.tsx +376 -376
- package/template/presets/punk-cut-paper/scenes/Photo.tsx +73 -73
- package/template/presets/punk-cut-paper/scenes/Ransom.tsx +119 -119
- package/template/runtime/composition.tsx +1189 -1185
- package/template/runtime/helpers.tsx +230 -230
- package/template/runtime/index.tsx +22 -22
- package/template/runtime/types.ts +315 -315
- package/template/skill/SKILL.md +186 -351
- package/template/skill/references/broll.md +44 -44
- package/template/skill/references/browser-export.md +61 -61
- package/template/skill/references/cinematic.md +206 -206
- package/template/skill/references/color.md +79 -79
- package/template/skill/references/craft.md +54 -10
- package/template/skill/references/editing-styles.md +57 -57
- package/template/skill/references/feature-launch.md +5 -1
- package/template/skill/references/footage.md +72 -72
- package/template/skill/references/format.md +142 -142
- package/template/skill/references/how-to.md +0 -15
- package/template/skill/references/launch-direction.md +89 -0
- package/template/skill/references/loops.md +151 -151
- package/template/skill/references/mcp-external.md +19 -0
- package/template/skill/references/performance.md +93 -93
- package/template/skill/references/person-cutout.md +19 -19
- package/template/skill/references/presets.md +60 -60
- package/template/skill/references/product-launch.md +4 -1
- package/template/skill/references/release-capture.md +53 -0
- package/template/skill/references/sound.md +167 -155
- package/template/skill/references/style-spy.md +160 -160
- package/template/skill/references/website-howto.md +45 -45
- package/template/starter/.studio/chat.json +1 -1
- package/template/starter/layers.json +46 -46
- package/template/starter/notes.md +4 -4
- package/template/starter/project.json +13 -13
- package/template/starter/scenes/Title.tsx +38 -38
|
@@ -1,381 +1,381 @@
|
|
|
1
|
-
// "Generated by an agent" reveals: a screenshot or photo appears the way an AI would build it. Dotted
|
|
2
|
-
// wireframes draw each UI block, a halftone of the image's own pixels fills in, then the real pixels
|
|
3
|
-
// resolve block by block (with an optional agent log typing alongside). Original Agentcut effect.
|
|
4
|
-
import { useLayoutEffect, useRef, useState } from "react";
|
|
5
|
-
import { Img, interpolate, useCurrentFrame, useDelayRender, useRemotionEnvironment } from "remotion";
|
|
6
|
-
import { usePlaneLayer } from "../cinematic/Cinematic";
|
|
7
|
-
import { alpha, FONTS, loadMotionFonts } from "../lib";
|
|
8
|
-
|
|
9
|
-
export interface GenerateRevealProps {
|
|
10
|
-
/** Image URL (in scenes: asset("assets/…")). */
|
|
11
|
-
src: string;
|
|
12
|
-
/**
|
|
13
|
-
* Size of the box in px (the image covers it). Inside a cinematic Screen use the Screen's own
|
|
14
|
-
* `width` and `width / aspect`, so the build fills the screen exactly.
|
|
15
|
-
*/
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
/**
|
|
19
|
-
* The UI's blocks, [x, y, w, h] in fractions of the image, in build order (header, sidebar, cards…).
|
|
20
|
-
* Leave out for photos: the whole image builds as one block. Values are clamped to the image.
|
|
21
|
-
*/
|
|
22
|
-
boxes?: [number, number, number, number][];
|
|
23
|
-
/** First frame of the build (local to the scene) and how long it takes. */
|
|
24
|
-
from?: number;
|
|
25
|
-
duration?: number;
|
|
26
|
-
/** "ui": wireframe → halftone → pixels. "image": tone sketch → colour dots → photo. */
|
|
27
|
-
mode?: "ui" | "image";
|
|
28
|
-
/** Wireframe and cursor colour. */
|
|
29
|
-
accent?: string;
|
|
30
|
-
/** Dot pitch in px of the box (smaller = finer halftone). */
|
|
31
|
-
dot?: number;
|
|
32
|
-
/** Agent log lines typed while it builds (empty for none); one line per block reads best. */
|
|
33
|
-
log?: string[];
|
|
34
|
-
/** Where the log sits. */
|
|
35
|
-
logPosition?: "top-left" | "bottom-left" | "top-right" | "bottom-right";
|
|
36
|
-
radius?: number;
|
|
37
|
-
/** Background behind the image while it builds. */
|
|
38
|
-
background?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Pixel ratio of the dots-and-wireframe canvas. Defaults to 2 in renders and exports (sharp under a
|
|
41
|
-
* camera push-in) and 1 in the live preview. Lower it for very large boxes. The blurred and mirrored
|
|
42
|
-
* copies a cinematic Plane draws always use 0.5 (and square dots): they're only seen soft.
|
|
43
|
-
*/
|
|
44
|
-
resolution?: number;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface Sampled {
|
|
48
|
-
/** The sampling inputs these cells belong to. */
|
|
49
|
-
key: string;
|
|
50
|
-
cols: number;
|
|
51
|
-
rows: number;
|
|
52
|
-
/** r, g, b, luma per cell; null when the pixels can't be read (no CORS): no dotted fill then. */
|
|
53
|
-
cells: Float32Array | null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const ease = (k: number) => 1 - Math.pow(1 - Math.min(1, Math.max(0, k)), 3);
|
|
57
|
-
const win = (p: number, a: number, b: number) => Math.min(1, Math.max(0, (p - a) / Math.max(1e-6, b - a)));
|
|
58
|
-
const clamp01 = (v: number) => Math.min(1, Math.max(0, Number.isFinite(v) ? v : 0));
|
|
59
|
-
/** Frames the full image takes to cross-fade in over the per-block pixels once the build is done. */
|
|
60
|
-
const SETTLE_FRAMES = 10;
|
|
61
|
-
/** Largest canvas side, so a high `resolution` on a big box stays quick to draw and capture. */
|
|
62
|
-
const MAX_CANVAS = 4096;
|
|
63
|
-
|
|
64
|
-
/** Boxes clamped to the image; empty ones dropped (the whole image when none are left). */
|
|
65
|
-
function clampBoxes(boxes: GenerateRevealProps["boxes"]): [number, number, number, number][] {
|
|
66
|
-
const out: [number, number, number, number][] = [];
|
|
67
|
-
for (const [x, y, w, h] of boxes ?? []) {
|
|
68
|
-
const x0 = clamp01(x);
|
|
69
|
-
const y0 = clamp01(y);
|
|
70
|
-
const x1 = clamp01(x + w);
|
|
71
|
-
const y1 = clamp01(y + h);
|
|
72
|
-
if (x1 - x0 > 1e-4 && y1 - y0 > 1e-4) out.push([x0, y0, x1 - x0, y1 - y0]);
|
|
73
|
-
}
|
|
74
|
-
return out.length ? out : [[0, 0, 1, 1]];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** A screenshot or photo that builds itself on screen like an agent is generating it. */
|
|
78
|
-
export function GenerateReveal({
|
|
79
|
-
src,
|
|
80
|
-
width,
|
|
81
|
-
height,
|
|
82
|
-
boxes,
|
|
83
|
-
from = 0,
|
|
84
|
-
duration = 90,
|
|
85
|
-
mode = "ui",
|
|
86
|
-
accent = "#7c5cff",
|
|
87
|
-
dot = 9,
|
|
88
|
-
log = [],
|
|
89
|
-
logPosition = "top-left",
|
|
90
|
-
radius = 0,
|
|
91
|
-
background = "transparent",
|
|
92
|
-
resolution,
|
|
93
|
-
}: GenerateRevealProps) {
|
|
94
|
-
const frame = useCurrentFrame();
|
|
95
|
-
const env = useRemotionEnvironment();
|
|
96
|
-
// Inside a Plane's lens-blur or reflection copy: the cheap drawing reads the same once blurred.
|
|
97
|
-
const { copy } = usePlaneLayer();
|
|
98
|
-
const canvas = useRef<HTMLCanvasElement>(null);
|
|
99
|
-
const { delayRender, continueRender } = useDelayRender();
|
|
100
|
-
const [sampled, setSampled] = useState<Sampled | null>(null);
|
|
101
|
-
/** Releases the current sampling hold (idempotent); set by the sampling effect. */
|
|
102
|
-
const releaseSample = useRef<(() => void) | null>(null);
|
|
103
|
-
const blocks = clampBoxes(boxes);
|
|
104
|
-
const p = interpolate(frame, [from, from + duration], [0, 1], { extrapolateLeft: "clamp", extrapolateRight: "clamp" });
|
|
105
|
-
// Once the build is done the full image fades in on top, so areas no box covers show too.
|
|
106
|
-
const settle = interpolate(frame, [from + duration, from + duration + SETTLE_FRAMES], [0, 1], {
|
|
107
|
-
extrapolateLeft: "clamp",
|
|
108
|
-
extrapolateRight: "clamp",
|
|
109
|
-
});
|
|
110
|
-
const cols = Math.max(8, Math.round(width / dot));
|
|
111
|
-
const rows = Math.max(6, Math.round(height / dot));
|
|
112
|
-
const key = `${src}|${cols}|${rows}`;
|
|
113
|
-
// Preview-only shortcut: the live player draws the canvas at 1x; captures and exports stay sharp.
|
|
114
|
-
const preview = env.isPlayer && !env.isRendering;
|
|
115
|
-
const ratio = copy ? 0.5 : Math.max(0.5, Math.min(resolution ?? (preview ? 1 : 2), MAX_CANVAS / Math.max(1, width, height)));
|
|
116
|
-
const canvasW = Math.max(1, Math.round(width * ratio));
|
|
117
|
-
const canvasH = Math.max(1, Math.round(height * ratio));
|
|
118
|
-
|
|
119
|
-
// Sample the image once on a coarse grid: the halftone is made of its own pixels. The hold is taken
|
|
120
|
-
// in a layout effect (on the first commit, before a capture looks for holds, and never in a render
|
|
121
|
-
// React may discard) and released by the first draw with these samples, or by cleanup (unmount,
|
|
122
|
-
// StrictMode's second mount, new inputs).
|
|
123
|
-
useLayoutEffect(() => {
|
|
124
|
-
let alive = true;
|
|
125
|
-
let released = false;
|
|
126
|
-
const handle = delayRender(`Sampling ${src} for GenerateReveal`);
|
|
127
|
-
const release = () => {
|
|
128
|
-
if (released) return;
|
|
129
|
-
released = true;
|
|
130
|
-
continueRender(handle);
|
|
131
|
-
};
|
|
132
|
-
releaseSample.current = release;
|
|
133
|
-
const done = (cells: Float32Array | null) => {
|
|
134
|
-
if (alive) setSampled({ key, cols, rows, cells });
|
|
135
|
-
};
|
|
136
|
-
// A decorative layer never aborts the render: without readable pixels it skips the dotted fill
|
|
137
|
-
// (wireframes, log and the real <Img> reveal still play; a missing image fails in that <Img>).
|
|
138
|
-
const degrade = (reason: string) => {
|
|
139
|
-
console.warn(`GenerateReveal: ${reason} for ${src}; drawing it without the dotted fill.`);
|
|
140
|
-
done(null);
|
|
141
|
-
};
|
|
142
|
-
const image = new Image();
|
|
143
|
-
image.crossOrigin = "anonymous";
|
|
144
|
-
image.onload = () => {
|
|
145
|
-
if (!alive) return;
|
|
146
|
-
const c = document.createElement("canvas");
|
|
147
|
-
c.width = cols;
|
|
148
|
-
c.height = rows;
|
|
149
|
-
const ctx = c.getContext("2d");
|
|
150
|
-
if (!ctx) return degrade("no 2D canvas");
|
|
151
|
-
try {
|
|
152
|
-
// Cover the box like the <Img> below.
|
|
153
|
-
const s = Math.max(cols / image.naturalWidth, rows / image.naturalHeight);
|
|
154
|
-
const w = image.naturalWidth * s;
|
|
155
|
-
const h = image.naturalHeight * s;
|
|
156
|
-
ctx.drawImage(image, (cols - w) / 2, (rows - h) / 2, w, h);
|
|
157
|
-
// A SecurityError here means the server sent no CORS headers (the canvas is tainted).
|
|
158
|
-
const data = ctx.getImageData(0, 0, cols, rows).data;
|
|
159
|
-
const cells = new Float32Array(cols * rows * 4);
|
|
160
|
-
for (let i = 0; i < cols * rows; i++) {
|
|
161
|
-
const r = data[i * 4];
|
|
162
|
-
const g = data[i * 4 + 1];
|
|
163
|
-
const b = data[i * 4 + 2];
|
|
164
|
-
cells.set([r, g, b, (0.299 * r + 0.587 * g + 0.114 * b) / 255], i * 4);
|
|
165
|
-
}
|
|
166
|
-
done(cells);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
degrade(`couldn't read the pixels (${error instanceof Error ? error.message : String(error)})`);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
image.onerror = () => {
|
|
172
|
-
if (alive) degrade("couldn't load the image with CORS");
|
|
173
|
-
};
|
|
174
|
-
image.src = src;
|
|
175
|
-
return () => {
|
|
176
|
-
alive = false;
|
|
177
|
-
image.onload = null;
|
|
178
|
-
image.onerror = null;
|
|
179
|
-
if (releaseSample.current === release) releaseSample.current = null;
|
|
180
|
-
release();
|
|
181
|
-
};
|
|
182
|
-
}, [key, src, cols, rows, delayRender, continueRender]);
|
|
183
|
-
|
|
184
|
-
// The log's font (Geist Mono) is a library font that scenes don't load: hold until it's in.
|
|
185
|
-
const hasLog = log.length > 0;
|
|
186
|
-
useLayoutEffect(() => {
|
|
187
|
-
if (!hasLog) return;
|
|
188
|
-
let alive = true;
|
|
189
|
-
let released = false;
|
|
190
|
-
const handle = delayRender("Loading the GenerateReveal log font");
|
|
191
|
-
const release = () => {
|
|
192
|
-
if (released) return;
|
|
193
|
-
released = true;
|
|
194
|
-
continueRender(handle);
|
|
195
|
-
};
|
|
196
|
-
// loadMotionFonts resolves even when the network fails (the text falls back), so this always ends.
|
|
197
|
-
loadMotionFonts()
|
|
198
|
-
.then(() => document.fonts.load(`500 16px ${FONTS.mono}`))
|
|
199
|
-
.catch(() => undefined)
|
|
200
|
-
.then(() => {
|
|
201
|
-
if (alive) release();
|
|
202
|
-
});
|
|
203
|
-
return () => {
|
|
204
|
-
alive = false;
|
|
205
|
-
release();
|
|
206
|
-
};
|
|
207
|
-
}, [hasLog, delayRender, continueRender]);
|
|
208
|
-
|
|
209
|
-
// Timing per block: each block runs wire → dots → pixels, staggered in build order.
|
|
210
|
-
const n = blocks.length;
|
|
211
|
-
const stagger = n > 1 ? 0.55 / (n - 1) : 0;
|
|
212
|
-
const span = 0.45;
|
|
213
|
-
const stage = (i: number) => {
|
|
214
|
-
const q = win(p, i * stagger, i * stagger + span);
|
|
215
|
-
return { wire: ease(win(q, 0, 0.35)), dots: ease(win(q, 0.2, 0.6)), pixels: ease(win(q, 0.55, 1)), q };
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
useLayoutEffect(() => {
|
|
219
|
-
const ready = sampled?.key === key;
|
|
220
|
-
const c = canvas.current;
|
|
221
|
-
const ctx = c?.getContext("2d");
|
|
222
|
-
if (c && ctx) {
|
|
223
|
-
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
224
|
-
ctx.clearRect(0, 0, width, height);
|
|
225
|
-
const cells = ready && sampled ? sampled.cells : null;
|
|
226
|
-
const cw = width / cols;
|
|
227
|
-
const ch = height / rows;
|
|
228
|
-
blocks.forEach(([bx, by, bw, bh], i) => {
|
|
229
|
-
const st = stage(i);
|
|
230
|
-
const x0 = bx * width;
|
|
231
|
-
const y0 = by * height;
|
|
232
|
-
const w = bw * width;
|
|
233
|
-
const h = bh * height;
|
|
234
|
-
// Halftone of the block's own pixels, sweeping top to bottom, then fading as the pixels arrive.
|
|
235
|
-
const dotsAlpha = st.dots * (1 - st.pixels);
|
|
236
|
-
if (cells && dotsAlpha > 0.01) {
|
|
237
|
-
const c0 = Math.max(0, Math.floor(bx * cols));
|
|
238
|
-
const c1 = Math.min(cols, Math.ceil((bx + bw) * cols));
|
|
239
|
-
const r0 = Math.max(0, Math.floor(by * rows));
|
|
240
|
-
const r1 = Math.min(rows, Math.ceil((by + bh) * rows));
|
|
241
|
-
for (let r = r0; r < r1; r++) {
|
|
242
|
-
const sweep = Math.min(1, Math.max(0, st.dots * 1.3 - ((r - r0) / Math.max(1, r1 - r0)) * 0.3));
|
|
243
|
-
if (sweep <= 0) continue;
|
|
244
|
-
for (let col = c0; col < c1; col++) {
|
|
245
|
-
const k = (r * cols + col) * 4;
|
|
246
|
-
const [R, G, B, L] = [cells[k], cells[k + 1], cells[k + 2], cells[k + 3]];
|
|
247
|
-
// Light UIs: ink where it's dark; dark UIs: ink where it's light.
|
|
248
|
-
// Every cell gets a dot (a readable dotted fill); contrast against the page makes it bigger.
|
|
249
|
-
const ink = 0.22 + 0.78 * Math.abs(L - (L > 0.5 ? 1 : 0));
|
|
250
|
-
const colour = mode === "image" ? st.dots : Math.max(0, st.dots - 0.4) / 0.6;
|
|
251
|
-
const mono = mode === "image" ? 1 - st.dots : 1;
|
|
252
|
-
const tone = Math.round(255 * (L > 0.5 ? 0.15 : 0.9));
|
|
253
|
-
const cr = Math.round(R * colour + tone * (1 - colour));
|
|
254
|
-
const cg = Math.round(G * colour + tone * (1 - colour));
|
|
255
|
-
const cb = Math.round(B * colour + tone * (1 - colour));
|
|
256
|
-
const radius = Math.max(0.4, Math.min(cw, ch) * 0.5 * Math.sqrt(Math.max(0.08, ink)) * sweep);
|
|
257
|
-
// Empty page reads as the agent's dotted fill (accent); content keeps its own colours.
|
|
258
|
-
ctx.fillStyle =
|
|
259
|
-
mode === "ui" && Math.abs(L - (cells[3] ?? L)) < 0.06
|
|
260
|
-
? alpha(accent, dotsAlpha * 0.45)
|
|
261
|
-
: `rgba(${cr},${cg},${cb},${dotsAlpha * (0.55 + 0.45 * mono)})`;
|
|
262
|
-
if (copy) {
|
|
263
|
-
// A square of the same area: far cheaper than an arc, identical once blurred.
|
|
264
|
-
const side = radius * Math.sqrt(Math.PI);
|
|
265
|
-
ctx.fillRect((col + 0.5) * cw - side / 2, (r + 0.5) * ch - side / 2, side, side);
|
|
266
|
-
} else {
|
|
267
|
-
ctx.beginPath();
|
|
268
|
-
ctx.arc((col + 0.5) * cw, (r + 0.5) * ch, radius, 0, Math.PI * 2);
|
|
269
|
-
ctx.fill();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
// Dotted wireframe drawn around the block, then fading once the pixels land.
|
|
275
|
-
if (mode === "ui" && st.wire > 0 && st.pixels < 1) {
|
|
276
|
-
const per = 2 * (w + h);
|
|
277
|
-
ctx.save();
|
|
278
|
-
ctx.strokeStyle = alpha(accent, 0.95 * (1 - st.pixels));
|
|
279
|
-
ctx.lineWidth = Math.max(2, dot * 0.32);
|
|
280
|
-
ctx.lineCap = "round";
|
|
281
|
-
// Reveal the dotted outline along its perimeter.
|
|
282
|
-
ctx.setLineDash([0.1, dot * 0.8]);
|
|
283
|
-
const length = per * st.wire;
|
|
284
|
-
ctx.beginPath();
|
|
285
|
-
let left = length;
|
|
286
|
-
const pts: [number, number][] = [
|
|
287
|
-
[x0 + 2, y0 + 2],
|
|
288
|
-
[x0 + w - 2, y0 + 2],
|
|
289
|
-
[x0 + w - 2, y0 + h - 2],
|
|
290
|
-
[x0 + 2, y0 + h - 2],
|
|
291
|
-
[x0 + 2, y0 + 2],
|
|
292
|
-
];
|
|
293
|
-
ctx.moveTo(pts[0][0], pts[0][1]);
|
|
294
|
-
let cursor = pts[0];
|
|
295
|
-
for (let s = 1; s < pts.length && left > 0; s++) {
|
|
296
|
-
const [ax, ay] = pts[s - 1];
|
|
297
|
-
const [bx2, by2] = pts[s];
|
|
298
|
-
const seg = Math.hypot(bx2 - ax, by2 - ay);
|
|
299
|
-
const k = Math.min(1, left / seg);
|
|
300
|
-
cursor = [ax + (bx2 - ax) * k, ay + (by2 - ay) * k];
|
|
301
|
-
ctx.lineTo(cursor[0], cursor[1]);
|
|
302
|
-
left -= seg;
|
|
303
|
-
}
|
|
304
|
-
ctx.stroke();
|
|
305
|
-
ctx.restore();
|
|
306
|
-
// The "agent's cursor" at the drawing tip.
|
|
307
|
-
if (st.wire < 1) {
|
|
308
|
-
ctx.fillStyle = accent;
|
|
309
|
-
ctx.beginPath();
|
|
310
|
-
ctx.arc(cursor[0], cursor[1], Math.max(3, dot * 0.45), 0, Math.PI * 2);
|
|
311
|
-
ctx.fill();
|
|
312
|
-
ctx.fillStyle = alpha(accent, 0.25);
|
|
313
|
-
ctx.beginPath();
|
|
314
|
-
ctx.arc(cursor[0], cursor[1], Math.max(8, dot * 1.3), 0, Math.PI * 2);
|
|
315
|
-
ctx.fill();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
// The first frame drawn with these samples (or knowing there are none) releases the render hold.
|
|
321
|
-
if (ready) releaseSample.current?.();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
const logLines = log.slice(0, Math.max(0, n === 1 ? log.length : n));
|
|
325
|
-
const [vertical, horizontal] = logPosition.split("-") as ["top" | "bottom", "left" | "right"];
|
|
326
|
-
const imgStyle = { width: "100%", height: "100%", objectFit: "cover", display: "block" } as const;
|
|
327
|
-
|
|
328
|
-
return (
|
|
329
|
-
<div style={{ position: "relative", width, height, borderRadius: radius, overflow: "hidden", background }}>
|
|
330
|
-
{settle < 1
|
|
331
|
-
? blocks.map(([bx, by, bw, bh], i) => {
|
|
332
|
-
const st = stage(i);
|
|
333
|
-
if (st.pixels <= 0) return null;
|
|
334
|
-
// The real pixels of this block resolve from soft to sharp.
|
|
335
|
-
const clip = `inset(${(by * 100).toFixed(3)}% ${((1 - bx - bw) * 100).toFixed(3)}% ${((1 - by - bh) * 100).toFixed(3)}% ${(bx * 100).toFixed(3)}%)`;
|
|
336
|
-
const blur = (1 - st.pixels) * 10;
|
|
337
|
-
return (
|
|
338
|
-
<div key={i} style={{ position: "absolute", inset: 0, clipPath: clip, opacity: st.pixels }}>
|
|
339
|
-
<Img src={src} style={{ ...imgStyle, filter: blur > 0.3 ? `blur(${blur.toFixed(2)}px)` : undefined }} />
|
|
340
|
-
</div>
|
|
341
|
-
);
|
|
342
|
-
})
|
|
343
|
-
: null}
|
|
344
|
-
{/* The end state is exactly the screenshot: one unclipped image, the per-block copies dropped. */}
|
|
345
|
-
{settle > 0 ? <Img src={src} style={{ ...imgStyle, position: "absolute", inset: 0, opacity: settle }} /> : null}
|
|
346
|
-
<canvas ref={canvas} width={canvasW} height={canvasH} style={{ position: "absolute", left: 0, top: 0, width, height }} />
|
|
347
|
-
{logLines.length ? (
|
|
348
|
-
<div
|
|
349
|
-
style={{
|
|
350
|
-
position: "absolute",
|
|
351
|
-
[vertical]: Math.round(height * 0.04),
|
|
352
|
-
[horizontal]: Math.round(width * 0.03),
|
|
353
|
-
maxWidth: width * 0.5,
|
|
354
|
-
padding: `${dot * 1.2}px ${dot * 1.6}px`,
|
|
355
|
-
borderRadius: dot * 1.2,
|
|
356
|
-
background: "rgba(12,12,16,0.82)",
|
|
357
|
-
border: `1px solid ${alpha(accent, 0.5)}`,
|
|
358
|
-
color: "#e7e7ee",
|
|
359
|
-
font: `500 ${Math.max(11, Math.round(height * 0.022))}px ${FONTS.mono}`,
|
|
360
|
-
lineHeight: 1.5,
|
|
361
|
-
opacity: ease(win(p, 0, 0.06)) * (1 - ease(win(p, 0.94, 1))),
|
|
362
|
-
}}
|
|
363
|
-
>
|
|
364
|
-
{logLines.map((line, i) => {
|
|
365
|
-
const st = n === 1 ? { q: win(p, (i / logLines.length) * 0.8, ((i + 1) / logLines.length) * 0.8) } : stage(i);
|
|
366
|
-
const typed = Math.round(line.length * win(st.q, 0, 0.4));
|
|
367
|
-
if (st.q <= 0) return null;
|
|
368
|
-
const done = st.q >= 1;
|
|
369
|
-
return (
|
|
370
|
-
<div key={i} style={{ whiteSpace: "nowrap", overflow: "hidden" }}>
|
|
371
|
-
<span style={{ color: done ? accent : alpha("#e7e7ee", 0.5) }}>{done ? "✓ " : "› "}</span>
|
|
372
|
-
{line.slice(0, typed)}
|
|
373
|
-
{!done && typed < line.length ? <span style={{ color: accent }}>▍</span> : null}
|
|
374
|
-
</div>
|
|
375
|
-
);
|
|
376
|
-
})}
|
|
377
|
-
</div>
|
|
378
|
-
) : null}
|
|
379
|
-
</div>
|
|
380
|
-
);
|
|
381
|
-
}
|
|
1
|
+
// "Generated by an agent" reveals: a screenshot or photo appears the way an AI would build it. Dotted
|
|
2
|
+
// wireframes draw each UI block, a halftone of the image's own pixels fills in, then the real pixels
|
|
3
|
+
// resolve block by block (with an optional agent log typing alongside). Original Agentcut effect.
|
|
4
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { Img, interpolate, useCurrentFrame, useDelayRender, useRemotionEnvironment } from "remotion";
|
|
6
|
+
import { usePlaneLayer } from "../cinematic/Cinematic";
|
|
7
|
+
import { alpha, FONTS, loadMotionFonts } from "../lib";
|
|
8
|
+
|
|
9
|
+
export interface GenerateRevealProps {
|
|
10
|
+
/** Image URL (in scenes: asset("assets/…")). */
|
|
11
|
+
src: string;
|
|
12
|
+
/**
|
|
13
|
+
* Size of the box in px (the image covers it). Inside a cinematic Screen use the Screen's own
|
|
14
|
+
* `width` and `width / aspect`, so the build fills the screen exactly.
|
|
15
|
+
*/
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
/**
|
|
19
|
+
* The UI's blocks, [x, y, w, h] in fractions of the image, in build order (header, sidebar, cards…).
|
|
20
|
+
* Leave out for photos: the whole image builds as one block. Values are clamped to the image.
|
|
21
|
+
*/
|
|
22
|
+
boxes?: [number, number, number, number][];
|
|
23
|
+
/** First frame of the build (local to the scene) and how long it takes. */
|
|
24
|
+
from?: number;
|
|
25
|
+
duration?: number;
|
|
26
|
+
/** "ui": wireframe → halftone → pixels. "image": tone sketch → colour dots → photo. */
|
|
27
|
+
mode?: "ui" | "image";
|
|
28
|
+
/** Wireframe and cursor colour. */
|
|
29
|
+
accent?: string;
|
|
30
|
+
/** Dot pitch in px of the box (smaller = finer halftone). */
|
|
31
|
+
dot?: number;
|
|
32
|
+
/** Agent log lines typed while it builds (empty for none); one line per block reads best. */
|
|
33
|
+
log?: string[];
|
|
34
|
+
/** Where the log sits. */
|
|
35
|
+
logPosition?: "top-left" | "bottom-left" | "top-right" | "bottom-right";
|
|
36
|
+
radius?: number;
|
|
37
|
+
/** Background behind the image while it builds. */
|
|
38
|
+
background?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Pixel ratio of the dots-and-wireframe canvas. Defaults to 2 in renders and exports (sharp under a
|
|
41
|
+
* camera push-in) and 1 in the live preview. Lower it for very large boxes. The blurred and mirrored
|
|
42
|
+
* copies a cinematic Plane draws always use 0.5 (and square dots): they're only seen soft.
|
|
43
|
+
*/
|
|
44
|
+
resolution?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Sampled {
|
|
48
|
+
/** The sampling inputs these cells belong to. */
|
|
49
|
+
key: string;
|
|
50
|
+
cols: number;
|
|
51
|
+
rows: number;
|
|
52
|
+
/** r, g, b, luma per cell; null when the pixels can't be read (no CORS): no dotted fill then. */
|
|
53
|
+
cells: Float32Array | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ease = (k: number) => 1 - Math.pow(1 - Math.min(1, Math.max(0, k)), 3);
|
|
57
|
+
const win = (p: number, a: number, b: number) => Math.min(1, Math.max(0, (p - a) / Math.max(1e-6, b - a)));
|
|
58
|
+
const clamp01 = (v: number) => Math.min(1, Math.max(0, Number.isFinite(v) ? v : 0));
|
|
59
|
+
/** Frames the full image takes to cross-fade in over the per-block pixels once the build is done. */
|
|
60
|
+
const SETTLE_FRAMES = 10;
|
|
61
|
+
/** Largest canvas side, so a high `resolution` on a big box stays quick to draw and capture. */
|
|
62
|
+
const MAX_CANVAS = 4096;
|
|
63
|
+
|
|
64
|
+
/** Boxes clamped to the image; empty ones dropped (the whole image when none are left). */
|
|
65
|
+
function clampBoxes(boxes: GenerateRevealProps["boxes"]): [number, number, number, number][] {
|
|
66
|
+
const out: [number, number, number, number][] = [];
|
|
67
|
+
for (const [x, y, w, h] of boxes ?? []) {
|
|
68
|
+
const x0 = clamp01(x);
|
|
69
|
+
const y0 = clamp01(y);
|
|
70
|
+
const x1 = clamp01(x + w);
|
|
71
|
+
const y1 = clamp01(y + h);
|
|
72
|
+
if (x1 - x0 > 1e-4 && y1 - y0 > 1e-4) out.push([x0, y0, x1 - x0, y1 - y0]);
|
|
73
|
+
}
|
|
74
|
+
return out.length ? out : [[0, 0, 1, 1]];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A screenshot or photo that builds itself on screen like an agent is generating it. */
|
|
78
|
+
export function GenerateReveal({
|
|
79
|
+
src,
|
|
80
|
+
width,
|
|
81
|
+
height,
|
|
82
|
+
boxes,
|
|
83
|
+
from = 0,
|
|
84
|
+
duration = 90,
|
|
85
|
+
mode = "ui",
|
|
86
|
+
accent = "#7c5cff",
|
|
87
|
+
dot = 9,
|
|
88
|
+
log = [],
|
|
89
|
+
logPosition = "top-left",
|
|
90
|
+
radius = 0,
|
|
91
|
+
background = "transparent",
|
|
92
|
+
resolution,
|
|
93
|
+
}: GenerateRevealProps) {
|
|
94
|
+
const frame = useCurrentFrame();
|
|
95
|
+
const env = useRemotionEnvironment();
|
|
96
|
+
// Inside a Plane's lens-blur or reflection copy: the cheap drawing reads the same once blurred.
|
|
97
|
+
const { copy } = usePlaneLayer();
|
|
98
|
+
const canvas = useRef<HTMLCanvasElement>(null);
|
|
99
|
+
const { delayRender, continueRender } = useDelayRender();
|
|
100
|
+
const [sampled, setSampled] = useState<Sampled | null>(null);
|
|
101
|
+
/** Releases the current sampling hold (idempotent); set by the sampling effect. */
|
|
102
|
+
const releaseSample = useRef<(() => void) | null>(null);
|
|
103
|
+
const blocks = clampBoxes(boxes);
|
|
104
|
+
const p = interpolate(frame, [from, from + duration], [0, 1], { extrapolateLeft: "clamp", extrapolateRight: "clamp" });
|
|
105
|
+
// Once the build is done the full image fades in on top, so areas no box covers show too.
|
|
106
|
+
const settle = interpolate(frame, [from + duration, from + duration + SETTLE_FRAMES], [0, 1], {
|
|
107
|
+
extrapolateLeft: "clamp",
|
|
108
|
+
extrapolateRight: "clamp",
|
|
109
|
+
});
|
|
110
|
+
const cols = Math.max(8, Math.round(width / dot));
|
|
111
|
+
const rows = Math.max(6, Math.round(height / dot));
|
|
112
|
+
const key = `${src}|${cols}|${rows}`;
|
|
113
|
+
// Preview-only shortcut: the live player draws the canvas at 1x; captures and exports stay sharp.
|
|
114
|
+
const preview = env.isPlayer && !env.isRendering;
|
|
115
|
+
const ratio = copy ? 0.5 : Math.max(0.5, Math.min(resolution ?? (preview ? 1 : 2), MAX_CANVAS / Math.max(1, width, height)));
|
|
116
|
+
const canvasW = Math.max(1, Math.round(width * ratio));
|
|
117
|
+
const canvasH = Math.max(1, Math.round(height * ratio));
|
|
118
|
+
|
|
119
|
+
// Sample the image once on a coarse grid: the halftone is made of its own pixels. The hold is taken
|
|
120
|
+
// in a layout effect (on the first commit, before a capture looks for holds, and never in a render
|
|
121
|
+
// React may discard) and released by the first draw with these samples, or by cleanup (unmount,
|
|
122
|
+
// StrictMode's second mount, new inputs).
|
|
123
|
+
useLayoutEffect(() => {
|
|
124
|
+
let alive = true;
|
|
125
|
+
let released = false;
|
|
126
|
+
const handle = delayRender(`Sampling ${src} for GenerateReveal`);
|
|
127
|
+
const release = () => {
|
|
128
|
+
if (released) return;
|
|
129
|
+
released = true;
|
|
130
|
+
continueRender(handle);
|
|
131
|
+
};
|
|
132
|
+
releaseSample.current = release;
|
|
133
|
+
const done = (cells: Float32Array | null) => {
|
|
134
|
+
if (alive) setSampled({ key, cols, rows, cells });
|
|
135
|
+
};
|
|
136
|
+
// A decorative layer never aborts the render: without readable pixels it skips the dotted fill
|
|
137
|
+
// (wireframes, log and the real <Img> reveal still play; a missing image fails in that <Img>).
|
|
138
|
+
const degrade = (reason: string) => {
|
|
139
|
+
console.warn(`GenerateReveal: ${reason} for ${src}; drawing it without the dotted fill.`);
|
|
140
|
+
done(null);
|
|
141
|
+
};
|
|
142
|
+
const image = new Image();
|
|
143
|
+
image.crossOrigin = "anonymous";
|
|
144
|
+
image.onload = () => {
|
|
145
|
+
if (!alive) return;
|
|
146
|
+
const c = document.createElement("canvas");
|
|
147
|
+
c.width = cols;
|
|
148
|
+
c.height = rows;
|
|
149
|
+
const ctx = c.getContext("2d");
|
|
150
|
+
if (!ctx) return degrade("no 2D canvas");
|
|
151
|
+
try {
|
|
152
|
+
// Cover the box like the <Img> below.
|
|
153
|
+
const s = Math.max(cols / image.naturalWidth, rows / image.naturalHeight);
|
|
154
|
+
const w = image.naturalWidth * s;
|
|
155
|
+
const h = image.naturalHeight * s;
|
|
156
|
+
ctx.drawImage(image, (cols - w) / 2, (rows - h) / 2, w, h);
|
|
157
|
+
// A SecurityError here means the server sent no CORS headers (the canvas is tainted).
|
|
158
|
+
const data = ctx.getImageData(0, 0, cols, rows).data;
|
|
159
|
+
const cells = new Float32Array(cols * rows * 4);
|
|
160
|
+
for (let i = 0; i < cols * rows; i++) {
|
|
161
|
+
const r = data[i * 4];
|
|
162
|
+
const g = data[i * 4 + 1];
|
|
163
|
+
const b = data[i * 4 + 2];
|
|
164
|
+
cells.set([r, g, b, (0.299 * r + 0.587 * g + 0.114 * b) / 255], i * 4);
|
|
165
|
+
}
|
|
166
|
+
done(cells);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
degrade(`couldn't read the pixels (${error instanceof Error ? error.message : String(error)})`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
image.onerror = () => {
|
|
172
|
+
if (alive) degrade("couldn't load the image with CORS");
|
|
173
|
+
};
|
|
174
|
+
image.src = src;
|
|
175
|
+
return () => {
|
|
176
|
+
alive = false;
|
|
177
|
+
image.onload = null;
|
|
178
|
+
image.onerror = null;
|
|
179
|
+
if (releaseSample.current === release) releaseSample.current = null;
|
|
180
|
+
release();
|
|
181
|
+
};
|
|
182
|
+
}, [key, src, cols, rows, delayRender, continueRender]);
|
|
183
|
+
|
|
184
|
+
// The log's font (Geist Mono) is a library font that scenes don't load: hold until it's in.
|
|
185
|
+
const hasLog = log.length > 0;
|
|
186
|
+
useLayoutEffect(() => {
|
|
187
|
+
if (!hasLog) return;
|
|
188
|
+
let alive = true;
|
|
189
|
+
let released = false;
|
|
190
|
+
const handle = delayRender("Loading the GenerateReveal log font");
|
|
191
|
+
const release = () => {
|
|
192
|
+
if (released) return;
|
|
193
|
+
released = true;
|
|
194
|
+
continueRender(handle);
|
|
195
|
+
};
|
|
196
|
+
// loadMotionFonts resolves even when the network fails (the text falls back), so this always ends.
|
|
197
|
+
loadMotionFonts()
|
|
198
|
+
.then(() => document.fonts.load(`500 16px ${FONTS.mono}`))
|
|
199
|
+
.catch(() => undefined)
|
|
200
|
+
.then(() => {
|
|
201
|
+
if (alive) release();
|
|
202
|
+
});
|
|
203
|
+
return () => {
|
|
204
|
+
alive = false;
|
|
205
|
+
release();
|
|
206
|
+
};
|
|
207
|
+
}, [hasLog, delayRender, continueRender]);
|
|
208
|
+
|
|
209
|
+
// Timing per block: each block runs wire → dots → pixels, staggered in build order.
|
|
210
|
+
const n = blocks.length;
|
|
211
|
+
const stagger = n > 1 ? 0.55 / (n - 1) : 0;
|
|
212
|
+
const span = 0.45;
|
|
213
|
+
const stage = (i: number) => {
|
|
214
|
+
const q = win(p, i * stagger, i * stagger + span);
|
|
215
|
+
return { wire: ease(win(q, 0, 0.35)), dots: ease(win(q, 0.2, 0.6)), pixels: ease(win(q, 0.55, 1)), q };
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
useLayoutEffect(() => {
|
|
219
|
+
const ready = sampled?.key === key;
|
|
220
|
+
const c = canvas.current;
|
|
221
|
+
const ctx = c?.getContext("2d");
|
|
222
|
+
if (c && ctx) {
|
|
223
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
224
|
+
ctx.clearRect(0, 0, width, height);
|
|
225
|
+
const cells = ready && sampled ? sampled.cells : null;
|
|
226
|
+
const cw = width / cols;
|
|
227
|
+
const ch = height / rows;
|
|
228
|
+
blocks.forEach(([bx, by, bw, bh], i) => {
|
|
229
|
+
const st = stage(i);
|
|
230
|
+
const x0 = bx * width;
|
|
231
|
+
const y0 = by * height;
|
|
232
|
+
const w = bw * width;
|
|
233
|
+
const h = bh * height;
|
|
234
|
+
// Halftone of the block's own pixels, sweeping top to bottom, then fading as the pixels arrive.
|
|
235
|
+
const dotsAlpha = st.dots * (1 - st.pixels);
|
|
236
|
+
if (cells && dotsAlpha > 0.01) {
|
|
237
|
+
const c0 = Math.max(0, Math.floor(bx * cols));
|
|
238
|
+
const c1 = Math.min(cols, Math.ceil((bx + bw) * cols));
|
|
239
|
+
const r0 = Math.max(0, Math.floor(by * rows));
|
|
240
|
+
const r1 = Math.min(rows, Math.ceil((by + bh) * rows));
|
|
241
|
+
for (let r = r0; r < r1; r++) {
|
|
242
|
+
const sweep = Math.min(1, Math.max(0, st.dots * 1.3 - ((r - r0) / Math.max(1, r1 - r0)) * 0.3));
|
|
243
|
+
if (sweep <= 0) continue;
|
|
244
|
+
for (let col = c0; col < c1; col++) {
|
|
245
|
+
const k = (r * cols + col) * 4;
|
|
246
|
+
const [R, G, B, L] = [cells[k], cells[k + 1], cells[k + 2], cells[k + 3]];
|
|
247
|
+
// Light UIs: ink where it's dark; dark UIs: ink where it's light.
|
|
248
|
+
// Every cell gets a dot (a readable dotted fill); contrast against the page makes it bigger.
|
|
249
|
+
const ink = 0.22 + 0.78 * Math.abs(L - (L > 0.5 ? 1 : 0));
|
|
250
|
+
const colour = mode === "image" ? st.dots : Math.max(0, st.dots - 0.4) / 0.6;
|
|
251
|
+
const mono = mode === "image" ? 1 - st.dots : 1;
|
|
252
|
+
const tone = Math.round(255 * (L > 0.5 ? 0.15 : 0.9));
|
|
253
|
+
const cr = Math.round(R * colour + tone * (1 - colour));
|
|
254
|
+
const cg = Math.round(G * colour + tone * (1 - colour));
|
|
255
|
+
const cb = Math.round(B * colour + tone * (1 - colour));
|
|
256
|
+
const radius = Math.max(0.4, Math.min(cw, ch) * 0.5 * Math.sqrt(Math.max(0.08, ink)) * sweep);
|
|
257
|
+
// Empty page reads as the agent's dotted fill (accent); content keeps its own colours.
|
|
258
|
+
ctx.fillStyle =
|
|
259
|
+
mode === "ui" && Math.abs(L - (cells[3] ?? L)) < 0.06
|
|
260
|
+
? alpha(accent, dotsAlpha * 0.45)
|
|
261
|
+
: `rgba(${cr},${cg},${cb},${dotsAlpha * (0.55 + 0.45 * mono)})`;
|
|
262
|
+
if (copy) {
|
|
263
|
+
// A square of the same area: far cheaper than an arc, identical once blurred.
|
|
264
|
+
const side = radius * Math.sqrt(Math.PI);
|
|
265
|
+
ctx.fillRect((col + 0.5) * cw - side / 2, (r + 0.5) * ch - side / 2, side, side);
|
|
266
|
+
} else {
|
|
267
|
+
ctx.beginPath();
|
|
268
|
+
ctx.arc((col + 0.5) * cw, (r + 0.5) * ch, radius, 0, Math.PI * 2);
|
|
269
|
+
ctx.fill();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// Dotted wireframe drawn around the block, then fading once the pixels land.
|
|
275
|
+
if (mode === "ui" && st.wire > 0 && st.pixels < 1) {
|
|
276
|
+
const per = 2 * (w + h);
|
|
277
|
+
ctx.save();
|
|
278
|
+
ctx.strokeStyle = alpha(accent, 0.95 * (1 - st.pixels));
|
|
279
|
+
ctx.lineWidth = Math.max(2, dot * 0.32);
|
|
280
|
+
ctx.lineCap = "round";
|
|
281
|
+
// Reveal the dotted outline along its perimeter.
|
|
282
|
+
ctx.setLineDash([0.1, dot * 0.8]);
|
|
283
|
+
const length = per * st.wire;
|
|
284
|
+
ctx.beginPath();
|
|
285
|
+
let left = length;
|
|
286
|
+
const pts: [number, number][] = [
|
|
287
|
+
[x0 + 2, y0 + 2],
|
|
288
|
+
[x0 + w - 2, y0 + 2],
|
|
289
|
+
[x0 + w - 2, y0 + h - 2],
|
|
290
|
+
[x0 + 2, y0 + h - 2],
|
|
291
|
+
[x0 + 2, y0 + 2],
|
|
292
|
+
];
|
|
293
|
+
ctx.moveTo(pts[0][0], pts[0][1]);
|
|
294
|
+
let cursor = pts[0];
|
|
295
|
+
for (let s = 1; s < pts.length && left > 0; s++) {
|
|
296
|
+
const [ax, ay] = pts[s - 1];
|
|
297
|
+
const [bx2, by2] = pts[s];
|
|
298
|
+
const seg = Math.hypot(bx2 - ax, by2 - ay);
|
|
299
|
+
const k = Math.min(1, left / seg);
|
|
300
|
+
cursor = [ax + (bx2 - ax) * k, ay + (by2 - ay) * k];
|
|
301
|
+
ctx.lineTo(cursor[0], cursor[1]);
|
|
302
|
+
left -= seg;
|
|
303
|
+
}
|
|
304
|
+
ctx.stroke();
|
|
305
|
+
ctx.restore();
|
|
306
|
+
// The "agent's cursor" at the drawing tip.
|
|
307
|
+
if (st.wire < 1) {
|
|
308
|
+
ctx.fillStyle = accent;
|
|
309
|
+
ctx.beginPath();
|
|
310
|
+
ctx.arc(cursor[0], cursor[1], Math.max(3, dot * 0.45), 0, Math.PI * 2);
|
|
311
|
+
ctx.fill();
|
|
312
|
+
ctx.fillStyle = alpha(accent, 0.25);
|
|
313
|
+
ctx.beginPath();
|
|
314
|
+
ctx.arc(cursor[0], cursor[1], Math.max(8, dot * 1.3), 0, Math.PI * 2);
|
|
315
|
+
ctx.fill();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
// The first frame drawn with these samples (or knowing there are none) releases the render hold.
|
|
321
|
+
if (ready) releaseSample.current?.();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const logLines = log.slice(0, Math.max(0, n === 1 ? log.length : n));
|
|
325
|
+
const [vertical, horizontal] = logPosition.split("-") as ["top" | "bottom", "left" | "right"];
|
|
326
|
+
const imgStyle = { width: "100%", height: "100%", objectFit: "cover", display: "block" } as const;
|
|
327
|
+
|
|
328
|
+
return (
|
|
329
|
+
<div style={{ position: "relative", width, height, borderRadius: radius, overflow: "hidden", background }}>
|
|
330
|
+
{settle < 1
|
|
331
|
+
? blocks.map(([bx, by, bw, bh], i) => {
|
|
332
|
+
const st = stage(i);
|
|
333
|
+
if (st.pixels <= 0) return null;
|
|
334
|
+
// The real pixels of this block resolve from soft to sharp.
|
|
335
|
+
const clip = `inset(${(by * 100).toFixed(3)}% ${((1 - bx - bw) * 100).toFixed(3)}% ${((1 - by - bh) * 100).toFixed(3)}% ${(bx * 100).toFixed(3)}%)`;
|
|
336
|
+
const blur = (1 - st.pixels) * 10;
|
|
337
|
+
return (
|
|
338
|
+
<div key={i} style={{ position: "absolute", inset: 0, clipPath: clip, opacity: st.pixels }}>
|
|
339
|
+
<Img src={src} style={{ ...imgStyle, filter: blur > 0.3 ? `blur(${blur.toFixed(2)}px)` : undefined }} />
|
|
340
|
+
</div>
|
|
341
|
+
);
|
|
342
|
+
})
|
|
343
|
+
: null}
|
|
344
|
+
{/* The end state is exactly the screenshot: one unclipped image, the per-block copies dropped. */}
|
|
345
|
+
{settle > 0 ? <Img src={src} style={{ ...imgStyle, position: "absolute", inset: 0, opacity: settle }} /> : null}
|
|
346
|
+
<canvas ref={canvas} width={canvasW} height={canvasH} style={{ position: "absolute", left: 0, top: 0, width, height }} />
|
|
347
|
+
{logLines.length ? (
|
|
348
|
+
<div
|
|
349
|
+
style={{
|
|
350
|
+
position: "absolute",
|
|
351
|
+
[vertical]: Math.round(height * 0.04),
|
|
352
|
+
[horizontal]: Math.round(width * 0.03),
|
|
353
|
+
maxWidth: width * 0.5,
|
|
354
|
+
padding: `${dot * 1.2}px ${dot * 1.6}px`,
|
|
355
|
+
borderRadius: dot * 1.2,
|
|
356
|
+
background: "rgba(12,12,16,0.82)",
|
|
357
|
+
border: `1px solid ${alpha(accent, 0.5)}`,
|
|
358
|
+
color: "#e7e7ee",
|
|
359
|
+
font: `500 ${Math.max(11, Math.round(height * 0.022))}px ${FONTS.mono}`,
|
|
360
|
+
lineHeight: 1.5,
|
|
361
|
+
opacity: ease(win(p, 0, 0.06)) * (1 - ease(win(p, 0.94, 1))),
|
|
362
|
+
}}
|
|
363
|
+
>
|
|
364
|
+
{logLines.map((line, i) => {
|
|
365
|
+
const st = n === 1 ? { q: win(p, (i / logLines.length) * 0.8, ((i + 1) / logLines.length) * 0.8) } : stage(i);
|
|
366
|
+
const typed = Math.round(line.length * win(st.q, 0, 0.4));
|
|
367
|
+
if (st.q <= 0) return null;
|
|
368
|
+
const done = st.q >= 1;
|
|
369
|
+
return (
|
|
370
|
+
<div key={i} style={{ whiteSpace: "nowrap", overflow: "hidden" }}>
|
|
371
|
+
<span style={{ color: done ? accent : alpha("#e7e7ee", 0.5) }}>{done ? "✓ " : "› "}</span>
|
|
372
|
+
{line.slice(0, typed)}
|
|
373
|
+
{!done && typed < line.length ? <span style={{ color: accent }}>▍</span> : null}
|
|
374
|
+
</div>
|
|
375
|
+
);
|
|
376
|
+
})}
|
|
377
|
+
</div>
|
|
378
|
+
) : null}
|
|
379
|
+
</div>
|
|
380
|
+
);
|
|
381
|
+
}
|