agentcut 0.2.3 → 0.2.5
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/dist/studio/tools.js +17 -2
- package/dist/studio/tools.js.map +1 -1
- package/dist/studio/workspace.js +4 -0
- package/dist/studio/workspace.js.map +1 -1
- package/package.json +1 -1
- package/template/components/CATALOG.md +52 -0
- package/template/components/README.md +70 -61
- package/template/components/STYLES.md +2 -0
- package/template/components/catalog.json +477 -0
- package/template/components/catalog.ts +4 -0
- package/template/components/cinematic/Cinematic.tsx +1139 -0
- package/template/components/cinematic/Device3D.tsx +299 -0
- package/template/components/cinematic/devices3d/display-model.ts +184 -0
- package/template/components/cinematic/devices3d/iphone-model.ts +643 -0
- package/template/components/cinematic/devices3d/macbook-model.ts +553 -0
- package/template/components/cinematic/devices3d/models.ts +612 -0
- package/template/components/cinematic/devices3d/runtime.ts +258 -0
- package/template/components/cinematic/math.ts +100 -0
- package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -0
- package/template/components/dot-trace-title/meta.json +51 -0
- package/template/components/generate/GenerateReveal.tsx +381 -0
- package/template/components/index.ts +36 -0
- package/template/components/lib.ts +18 -6
- package/template/components/loops/LoopCanvas.tsx +132 -0
- package/template/components/loops/engine.ts +184 -0
- package/template/components/loops/library.ts +667 -0
- package/template/components/loops/library2.ts +777 -0
- package/template/components/motion-loop/MotionLoop.tsx +37 -0
- package/template/components/motion-loop/meta.json +312 -0
- package/template/runtime/composition.tsx +927 -920
- package/template/skill/SKILL.md +20 -3
- package/template/skill/references/browser-export.md +61 -61
- package/template/skill/references/cinematic.md +171 -0
- package/template/skill/references/loops.md +151 -0
- package/template/skill/references/performance.md +81 -0
|
@@ -0,0 +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
|
+
}
|
|
@@ -25,6 +25,8 @@ import { Highlighter } from "./highlighter/Highlighter";
|
|
|
25
25
|
import { LogoSting } from "./logo-sting/LogoSting";
|
|
26
26
|
import { Marquee } from "./marquee/Marquee";
|
|
27
27
|
import { Aurora } from "./aurora/Aurora";
|
|
28
|
+
import { MotionLoop } from "./motion-loop/MotionLoop";
|
|
29
|
+
import { DotTraceTitle } from "./dot-trace-title/DotTraceTitle";
|
|
28
30
|
import { LavaLamp } from "./lava-lamp/LavaLamp";
|
|
29
31
|
import { SpotlightGrid } from "./spotlight-grid/SpotlightGrid";
|
|
30
32
|
import { IrisWipe } from "./iris-wipe/IrisWipe";
|
|
@@ -77,6 +79,8 @@ const COMPONENTS: Record<string, unknown> = {
|
|
|
77
79
|
"logo-sting": LogoSting,
|
|
78
80
|
"marquee": Marquee,
|
|
79
81
|
"aurora": Aurora,
|
|
82
|
+
"motion-loop": MotionLoop,
|
|
83
|
+
"dot-trace-title": DotTraceTitle,
|
|
80
84
|
"lava-lamp": LavaLamp,
|
|
81
85
|
"spotlight-grid": SpotlightGrid,
|
|
82
86
|
"iris-wipe": IrisWipe,
|
|
@@ -144,6 +148,38 @@ export { loadMotionFonts, useMotionFonts } from "./lib";
|
|
|
144
148
|
// Called by the studio runtime for a project with a style: camera on footage, texture, captions.
|
|
145
149
|
export { StyleOverlay, StyledCaptions, styleCamera, styleLookProps } from "./style-layer";
|
|
146
150
|
export { hookSpeakerBox, type SpeakerBox } from "./hook-card/HookCard";
|
|
151
|
+
// Cinematic toolkit for scenes: a 3D camera with lens blur, devices, lifts, glare (see skills/agentcut/references/cinematic.md).
|
|
152
|
+
export {
|
|
153
|
+
Backdrop,
|
|
154
|
+
cameraAt,
|
|
155
|
+
Device,
|
|
156
|
+
DEVICE_ASPECT,
|
|
157
|
+
deviceGeometry,
|
|
158
|
+
Floor,
|
|
159
|
+
Glare,
|
|
160
|
+
Group,
|
|
161
|
+
Lift,
|
|
162
|
+
Plane,
|
|
163
|
+
PlaneVideo,
|
|
164
|
+
progress,
|
|
165
|
+
Screen,
|
|
166
|
+
screenRect,
|
|
167
|
+
Stage,
|
|
168
|
+
usePlaneLayer,
|
|
169
|
+
useStage,
|
|
170
|
+
} from "./cinematic/Cinematic";
|
|
171
|
+
export { Device3D, DEVICE_FINISHES } from "./cinematic/Device3D";
|
|
172
|
+
// Seamless motion loops for scenes: <LoopCanvas loop="dot-wave" accent=… /> or your own draw(ctx, w, h, t, P, M).
|
|
173
|
+
export { LoopCanvas } from "./loops/LoopCanvas";
|
|
174
|
+
// The "generated by an agent" reveal for screenshots and photos in scenes.
|
|
175
|
+
export { GenerateReveal } from "./generate/GenerateReveal";
|
|
176
|
+
export type { GenerateRevealProps } from "./generate/GenerateReveal";
|
|
177
|
+
export type { LoopCanvasProps } from "./loops/LoopCanvas";
|
|
178
|
+
export { LOOP, LOOP_CATEGORIES, loopPalette, M as loopHelpers } from "./loops/engine";
|
|
179
|
+
export type { LoopCategory, LoopDef, LoopDraw, LoopHelpers, LoopPalette, LoopTone } from "./loops/engine";
|
|
180
|
+
export { getLoop, LOOP_IDS, LOOPS } from "./loops/library";
|
|
181
|
+
export type { Device3DModel, Device3DProps } from "./cinematic/Device3D";
|
|
182
|
+
export type { BackdropLook, CameraKey, CameraPose, DeviceKind, EaseName, LiftProps, Placement, PlaneProps, ScreenProps, StageProps } from "./cinematic/Cinematic";
|
|
147
183
|
|
|
148
184
|
export { COMPONENT_METAS } from "./catalog";
|
|
149
185
|
export type { ComponentMeta, MotionBaseProps, MotionComponent, PropSpec, PropValues } from "./types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Small helpers shared by the components. Components import only react, remotion and this file,
|
|
2
2
|
// so they bundle the same way in the gallery, the studio preview, the browser export and a local render.
|
|
3
|
-
import {
|
|
3
|
+
import { useLayoutEffect } from "react";
|
|
4
4
|
import { Easing, interpolate, spring, useDelayRender } from "remotion";
|
|
5
5
|
|
|
6
6
|
/** Scale for the frame size: 1 at 1080 px on the short side. */
|
|
@@ -118,11 +118,23 @@ export function loadMotionFonts() {
|
|
|
118
118
|
/** Holds the render (export, still, local render) until the fonts are in, so frame 0 has the right type. */
|
|
119
119
|
export function useMotionFonts() {
|
|
120
120
|
const { delayRender, continueRender } = useDelayRender();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
// A layout effect: the hold exists before the commit ends, is never taken by a render React throws
|
|
122
|
+
// away, and is released on unmount (StrictMode mounts twice) and when a font fails to load.
|
|
123
|
+
useLayoutEffect(() => {
|
|
124
|
+
if (fontsLoaded) return;
|
|
125
|
+
const handle = delayRender("Loading motion component fonts");
|
|
126
|
+
let released = false;
|
|
127
|
+
const release = () => {
|
|
128
|
+
if (released) return;
|
|
129
|
+
released = true;
|
|
130
|
+
continueRender(handle);
|
|
131
|
+
};
|
|
132
|
+
loadMotionFonts().then(release, (error: unknown) => {
|
|
133
|
+
console.warn("[agentcut] motion component fonts didn't load", error);
|
|
134
|
+
release();
|
|
135
|
+
});
|
|
136
|
+
return release;
|
|
137
|
+
}, [delayRender, continueRender]);
|
|
126
138
|
}
|
|
127
139
|
|
|
128
140
|
/** The `background` prop as a CSS value ("transparent" keeps an overlay see-through). */
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Draws a seamless loop (or your own draw function) on a canvas for the current frame.
|
|
2
|
+
import { useLayoutEffect, useRef, type CSSProperties } from "react";
|
|
3
|
+
import { useCurrentFrame, useRemotionEnvironment, useVideoConfig } from "remotion";
|
|
4
|
+
import { LOOP, loopPalette, M, type LoopDraw, type LoopPalette, type LoopTone } from "./engine";
|
|
5
|
+
import { getLoop } from "./library";
|
|
6
|
+
|
|
7
|
+
export interface LoopCanvasProps {
|
|
8
|
+
/** A library loop id (see LOOPS) or your own draw function with the same contract. */
|
|
9
|
+
loop: string | LoopDraw;
|
|
10
|
+
/** Brand colours; the palette's three tones derive from them. */
|
|
11
|
+
accent?: string;
|
|
12
|
+
accent2?: string;
|
|
13
|
+
tone?: LoopTone;
|
|
14
|
+
/** Or a full palette (overrides accent, accent2 and tone). */
|
|
15
|
+
palette?: LoopPalette;
|
|
16
|
+
/** Playback speed (1 = the loop's 12 s cycle). Seamless at any speed; to repeat a clip, make duration × speed a multiple of 12 s. */
|
|
17
|
+
speed?: number;
|
|
18
|
+
/** Shifts where in the cycle it starts (seconds). */
|
|
19
|
+
offset?: number;
|
|
20
|
+
/** Varies the layout of the loop's elements. */
|
|
21
|
+
seed?: number;
|
|
22
|
+
/** Don't fill the background (shapes over footage or a Stage). */
|
|
23
|
+
transparent?: boolean;
|
|
24
|
+
/** Motion blur sub-frames in captures and exports (1 = none, 4 default, 8 for fast loops); the live preview draws 1. */
|
|
25
|
+
blur?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Size in world px. Without them the loop is frame-sized and stretches to fill its parent (a
|
|
28
|
+
* full-frame parent, or one with the frame's aspect). With them it is drawn at exactly that size
|
|
29
|
+
* (CSS too), so it never distorts: pass the size of the box it sits in (a card, a Plane).
|
|
30
|
+
*/
|
|
31
|
+
width?: number;
|
|
32
|
+
height?: number;
|
|
33
|
+
style?: CSSProperties;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A seamless motion loop drawn from the brand palette, frame-accurate in preview and export. */
|
|
37
|
+
export function LoopCanvas({
|
|
38
|
+
loop,
|
|
39
|
+
accent = "#7c5cff",
|
|
40
|
+
accent2 = "#ff5ca8",
|
|
41
|
+
tone = "dark",
|
|
42
|
+
palette,
|
|
43
|
+
speed = 1,
|
|
44
|
+
offset = 0,
|
|
45
|
+
seed = 0,
|
|
46
|
+
transparent = false,
|
|
47
|
+
blur = 4,
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
style,
|
|
51
|
+
}: LoopCanvasProps) {
|
|
52
|
+
const frame = useCurrentFrame();
|
|
53
|
+
const config = useVideoConfig();
|
|
54
|
+
const env = useRemotionEnvironment();
|
|
55
|
+
const ref = useRef<HTMLCanvasElement>(null);
|
|
56
|
+
const scratch = useRef<HTMLCanvasElement | null>(null);
|
|
57
|
+
const acc = useRef<Float32Array | null>(null);
|
|
58
|
+
const w = Math.round(width ?? config.width);
|
|
59
|
+
const h = Math.round(height ?? config.height);
|
|
60
|
+
const draw = typeof loop === "function" ? loop : getLoop(loop).draw;
|
|
61
|
+
const P = palette ?? loopPalette(accent, accent2, tone);
|
|
62
|
+
// The live preview skips motion blur; captures and exports draw every sub-frame.
|
|
63
|
+
const samples = env.isPlayer && !env.isRendering ? 1 : Math.max(1, Math.min(12, Math.round(blur)));
|
|
64
|
+
|
|
65
|
+
useLayoutEffect(() => {
|
|
66
|
+
const canvas = ref.current;
|
|
67
|
+
const ctx = canvas?.getContext("2d");
|
|
68
|
+
if (!canvas || !ctx) return;
|
|
69
|
+
const paint = (target: CanvasRenderingContext2D, t: number) => {
|
|
70
|
+
target.save();
|
|
71
|
+
target.clearRect(0, 0, w, h);
|
|
72
|
+
if (!transparent) {
|
|
73
|
+
target.fillStyle = P.bg;
|
|
74
|
+
target.fillRect(0, 0, w, h);
|
|
75
|
+
}
|
|
76
|
+
draw(target, w, h, ((t % LOOP) + LOOP) % LOOP, P, M, seed);
|
|
77
|
+
target.restore();
|
|
78
|
+
};
|
|
79
|
+
const t0 = (frame / config.fps) * speed + offset;
|
|
80
|
+
if (samples === 1) {
|
|
81
|
+
paint(ctx, t0);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Average sub-frames across a 180° shutter (half a frame), in premultiplied float so transparent
|
|
85
|
+
// pixels average correctly and 8-bit rounding happens once.
|
|
86
|
+
scratch.current ??= document.createElement("canvas");
|
|
87
|
+
const sc = scratch.current;
|
|
88
|
+
if (sc.width !== w || sc.height !== h) {
|
|
89
|
+
sc.width = w;
|
|
90
|
+
sc.height = h;
|
|
91
|
+
}
|
|
92
|
+
const sctx = sc.getContext("2d", { willReadFrequently: true });
|
|
93
|
+
if (!sctx) return;
|
|
94
|
+
if (acc.current?.length !== w * h * 4) acc.current = new Float32Array(w * h * 4);
|
|
95
|
+
const sum = acc.current;
|
|
96
|
+
sum.fill(0);
|
|
97
|
+
for (let i = 0; i < samples; i++) {
|
|
98
|
+
const dt = ((i + 0.5) / samples - 0.5) * 0.5 * (speed / config.fps);
|
|
99
|
+
paint(sctx, t0 + dt);
|
|
100
|
+
const d = sctx.getImageData(0, 0, w, h).data;
|
|
101
|
+
for (let p = 0; p < d.length; p += 4) {
|
|
102
|
+
const a = d[p + 3];
|
|
103
|
+
if (!a) continue;
|
|
104
|
+
sum[p] += d[p] * a;
|
|
105
|
+
sum[p + 1] += d[p + 1] * a;
|
|
106
|
+
sum[p + 2] += d[p + 2] * a;
|
|
107
|
+
sum[p + 3] += a;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const out = ctx.createImageData(w, h);
|
|
111
|
+
const o = out.data;
|
|
112
|
+
for (let p = 0; p < o.length; p += 4) {
|
|
113
|
+
const a = sum[p + 3];
|
|
114
|
+
if (!a) continue;
|
|
115
|
+
o[p] = sum[p] / a;
|
|
116
|
+
o[p + 1] = sum[p + 1] / a;
|
|
117
|
+
o[p + 2] = sum[p + 2] / a;
|
|
118
|
+
o[p + 3] = a / samples;
|
|
119
|
+
}
|
|
120
|
+
ctx.putImageData(out, 0, 0);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const sized = width !== undefined || height !== undefined;
|
|
124
|
+
return (
|
|
125
|
+
<canvas
|
|
126
|
+
ref={ref}
|
|
127
|
+
width={w}
|
|
128
|
+
height={h}
|
|
129
|
+
style={{ position: "absolute", left: 0, top: 0, width: sized ? w : "100%", height: sized ? h : "100%", ...style }}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|