agentcut 0.2.4 → 0.2.6

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 (31) hide show
  1. package/dist/studio/workspace.js +4 -0
  2. package/dist/studio/workspace.js.map +1 -1
  3. package/package.json +1 -1
  4. package/template/components/CATALOG.md +52 -0
  5. package/template/components/README.md +70 -61
  6. package/template/components/STYLES.md +2 -0
  7. package/template/components/catalog.json +477 -0
  8. package/template/components/catalog.ts +4 -0
  9. package/template/components/cinematic/Cinematic.tsx +1093 -0
  10. package/template/components/cinematic/Device3D.tsx +324 -0
  11. package/template/components/cinematic/devices3d/display-model.ts +184 -0
  12. package/template/components/cinematic/devices3d/iphone-model.ts +643 -0
  13. package/template/components/cinematic/devices3d/macbook-model.ts +604 -0
  14. package/template/components/cinematic/devices3d/models.ts +657 -0
  15. package/template/components/cinematic/devices3d/runtime.ts +267 -0
  16. package/template/components/cinematic/math.ts +100 -0
  17. package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -0
  18. package/template/components/dot-trace-title/meta.json +51 -0
  19. package/template/components/generate/GenerateReveal.tsx +381 -0
  20. package/template/components/index.ts +36 -0
  21. package/template/components/lib.ts +18 -6
  22. package/template/components/loops/LoopCanvas.tsx +132 -0
  23. package/template/components/loops/engine.ts +184 -0
  24. package/template/components/loops/library.ts +667 -0
  25. package/template/components/loops/library2.ts +777 -0
  26. package/template/components/motion-loop/MotionLoop.tsx +37 -0
  27. package/template/components/motion-loop/meta.json +312 -0
  28. package/template/skill/SKILL.md +16 -1
  29. package/template/skill/references/browser-export.md +61 -61
  30. package/template/skill/references/cinematic.md +184 -0
  31. package/template/skill/references/loops.md +151 -0
@@ -0,0 +1,324 @@
1
+ // Real 3D devices (iPhone 16 Pro Max model, MacBook, Studio Display) inside a cinematic <Stage>.
2
+ // three.js draws them on a full-frame canvas through exactly the Stage's camera, so they move, turn and
3
+ // blur with the CSS planes around them. Models come from ScreenSlick's device stage.
4
+ import { useLayoutEffect, useRef, useState } from "react";
5
+ import { Img, useDelayRender, useRemotionEnvironment, useVideoConfig } from "remotion";
6
+ import { blurFor, Group, Plane, useStageContext } from "./Cinematic";
7
+ import { mul, placementMatrix, type M4, type Placement } from "./math";
8
+ import type { DeviceRenderer, VideoDeviceModelId } from "./devices3d/runtime";
9
+
10
+ export type Device3DModel = "iphone" | "iphone-color" | "iphone-classic" | "macbook" | "macbook-pro" | "display";
11
+
12
+ const MODEL_IDS: Record<Device3DModel, VideoDeviceModelId> = {
13
+ iphone: "iphone-16-pro-max",
14
+ "iphone-color": "procedural-iphone",
15
+ "iphone-classic": "procedural-iphone",
16
+ macbook: "procedural-macbook",
17
+ "macbook-pro": "macbook-pro-14",
18
+ display: "procedural-display",
19
+ };
20
+
21
+ /** Default size: the device's largest dimension in world px. */
22
+ const DEFAULT_SIZE: Record<Device3DModel, number> = { iphone: 760, "iphone-color": 760, "iphone-classic": 760, macbook: 1250, "macbook-pro": 1250, display: 1150 };
23
+
24
+ /** Rough footprint (width, height as fractions of size) for the soft shadow behind the device. */
25
+ const FOOTPRINT: Record<Device3DModel, [number, number]> = {
26
+ iphone: [0.47, 1],
27
+ "iphone-color": [0.47, 1],
28
+ "iphone-classic": [0.47, 1],
29
+ macbook: [1, 0.62],
30
+ "macbook-pro": [1, 0.62],
31
+ display: [1, 0.86],
32
+ };
33
+
34
+ export const DEVICE_FINISHES: Record<string, string> = {
35
+ silver: "#cfd1d3",
36
+ starlight: "#d9cdb6",
37
+ "space-gray": "#6f7174",
38
+ // The deep anodised black of the current MacBook Pro (matched to a reference model).
39
+ "space-black": "#565457",
40
+ // Colour iPhone finishes (iphone-color), most with calibrated logo tints in iphone-model.ts.
41
+ lavender: "#c5a4df",
42
+ "mist-blue": "#829dce",
43
+ white: "#d9dad6",
44
+ "cosmic-orange": "#c9643a",
45
+ graphite: "#6a6a6a",
46
+ midnight: "#2f3541",
47
+ black: "#3c3d40",
48
+ };
49
+
50
+ export interface Device3DProps extends Placement {
51
+ model: Device3DModel;
52
+ /**
53
+ * Your own GLB for this device (asset("library:models/…")). Required for "macbook-pro", whose model
54
+ * can't ship with Agentcut; optional for the others.
55
+ */
56
+ modelSrc?: string;
57
+ /** Screenshot on the screen (asset("assets/…")). It covers the screen; a taller one shows its top. */
58
+ src?: string;
59
+ /** Largest dimension of the device in world px (iPhone ≈ its height, MacBook ≈ its width). */
60
+ size?: number;
61
+ /**
62
+ * Hardware colour, or any hex. MacBook / display: space-black (MacBook default), space-gray, silver,
63
+ * starlight, midnight, black. iphone-color: graphite (default), lavender, mist-blue, white,
64
+ * cosmic-orange, or a brand hex. The iPhone 16 Pro Max model has its own fixed finish.
65
+ */
66
+ finish?: string;
67
+ /** MacBook lid angle in degrees: 110 open, 0 closed. Animate it for an opening shot. */
68
+ lidAngle?: number;
69
+ /** Scrolls a tall screenshot: 0 top … 1 bottom. */
70
+ scroll?: number;
71
+ /** Light: 1 normal, 0.8 moody, 1.3 bright. */
72
+ exposure?: number;
73
+ /** Soft shadow behind the device: 0 none, 1 strong. */
74
+ shadow?: number;
75
+ /** Lens blur from the Stage's focus and aperture (whole device). */
76
+ dof?: boolean;
77
+ opacity?: number;
78
+ /**
79
+ * Pieces of the screenshot that rise off the device's screen toward the camera (cards, buttons,
80
+ * charts). `box` is [x, y, w, h] in fractions of the SCREENSHOT; `z` how far it rises (world px).
81
+ */
82
+ lifts?: Device3DLift[];
83
+ }
84
+
85
+ export interface Device3DLift {
86
+ box: [number, number, number, number];
87
+ /** Rise toward the viewer, world px (animate 0 → 40–140). */
88
+ z: number;
89
+ /** Extra scale while lifted (1.0–1.15). */
90
+ scale?: number;
91
+ /** Extra offset in world px while lifted (x right, y down). */
92
+ x?: number;
93
+ y?: number;
94
+ radius?: number;
95
+ shadow?: number;
96
+ rim?: number;
97
+ opacity?: number;
98
+ }
99
+
100
+ type V3 = [number, number, number];
101
+ const sub = (a: V3, b: V3): V3 => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
102
+ const len = (a: V3) => Math.hypot(a[0], a[1], a[2]);
103
+ const norm = (a: V3): V3 => {
104
+ const l = len(a) || 1;
105
+ return [a[0] / l, a[1] / l, a[2] / l];
106
+ };
107
+ const cross = (a: V3, b: V3): V3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
108
+
109
+ function loadImage(src: string) {
110
+ return new Promise<HTMLImageElement>((resolve, reject) => {
111
+ const image = new Image();
112
+ image.crossOrigin = "anonymous";
113
+ image.decoding = "async";
114
+ image.onload = () => resolve(image);
115
+ image.onerror = () => reject(new Error(`Couldn't load the screen image ${src}.`));
116
+ image.src = src;
117
+ });
118
+ }
119
+
120
+ /** A real 3D device in the Stage, with a screenshot on its screen. */
121
+ export function Device3D({
122
+ model,
123
+ modelSrc,
124
+ src,
125
+ size,
126
+ finish,
127
+ lidAngle = 110,
128
+ scroll = 0,
129
+ exposure = 1,
130
+ shadow = 0.6,
131
+ dof = true,
132
+ opacity = 1,
133
+ lifts,
134
+ ...placement
135
+ }: Device3DProps) {
136
+ const ctx = useStageContext("Device3D");
137
+ const { width, height } = useVideoConfig();
138
+ const env = useRemotionEnvironment();
139
+ const { delayRender, continueRender, cancelRender } = useDelayRender();
140
+ const holder = useRef<HTMLDivElement>(null);
141
+ const pending = useRef<number | null>(null);
142
+ const [device, setDevice] = useState<DeviceRenderer | null>(null);
143
+ // The built-in MacBook defaults to space black; other devices keep their own default.
144
+ const finishName = finish ?? (model === "macbook" ? "space-black" : model === "iphone-color" ? "graphite" : undefined);
145
+ const finishColor = finishName ? (DEVICE_FINISHES[finishName] ?? finishName) : undefined;
146
+ const deviceSize = size ?? DEFAULT_SIZE[model];
147
+
148
+ // Load three, the model and the screenshot; hold the render until the first frame is drawn. A layout
149
+ // effect, so the hold exists before the commit ends (an export or capture can look for holds right
150
+ // after it) and is never created by a render React throws away.
151
+ useLayoutEffect(() => {
152
+ const box = holder.current;
153
+ if (!box) return;
154
+ // A reload (new model, finish or screenshot) holds the render again until it's drawn.
155
+ pending.current ??= delayRender(`Loading the 3D ${model}`, { timeoutInMilliseconds: 60000 });
156
+ const handle = pending.current;
157
+ let alive = true;
158
+ let created: DeviceRenderer | null = null;
159
+ const canvas = document.createElement("canvas");
160
+ canvas.style.cssText = "position:absolute;left:0;top:0;width:100%;height:100%";
161
+ box.appendChild(canvas);
162
+ const image = src ? loadImage(src) : Promise.resolve(null);
163
+ // Handled below; this keeps a failure while the model loads from being reported as unhandled.
164
+ image.catch(() => {});
165
+ (async () => {
166
+ const { createDeviceRenderer } = await import("./devices3d/runtime");
167
+ const renderer = await createDeviceRenderer(canvas, MODEL_IDS[model], finishColor, modelSrc);
168
+ if (!alive) {
169
+ renderer.dispose();
170
+ return;
171
+ }
172
+ created = renderer;
173
+ const loaded = await image;
174
+ if (!alive) return;
175
+ renderer.setImage(loaded);
176
+ setDevice(renderer);
177
+ })().catch((error) => {
178
+ if (alive) cancelRender(error);
179
+ });
180
+ return () => {
181
+ alive = false;
182
+ created?.dispose();
183
+ canvas.remove();
184
+ setDevice(null);
185
+ if (pending.current === handle) {
186
+ continueRender(handle);
187
+ pending.current = null;
188
+ }
189
+ };
190
+ }, [model, modelSrc, finishColor, src, delayRender, continueRender, cancelRender]);
191
+
192
+ const matrix = mul(ctx.view, ctx.model, placementMatrix(placement));
193
+ const centerDist = ctx.D - matrix[11];
194
+ const blur = dof ? blurFor(ctx, centerDist) : 0;
195
+ const preview = env.isPlayer && !env.isRendering;
196
+
197
+ useLayoutEffect(() => {
198
+ if (!device) return;
199
+ device.render({
200
+ width,
201
+ height,
202
+ D: ctx.D,
203
+ fov: ctx.fov,
204
+ shiftX: ctx.shiftX,
205
+ shiftY: ctx.shiftY,
206
+ matrix,
207
+ size: deviceSize,
208
+ exposure,
209
+ lidAngle,
210
+ scroll,
211
+ // The live preview draws the 3D device at half resolution; captures and exports at full.
212
+ pixelRatio: preview ? 0.5 : 1,
213
+ });
214
+ if (pending.current !== null) {
215
+ continueRender(pending.current);
216
+ pending.current = null;
217
+ }
218
+ });
219
+
220
+ const [fw, fh] = FOOTPRINT[model];
221
+ const shadowFill = `rgba(0,0,0,${Math.min(0.8, 0.45 * shadow) * opacity})`;
222
+ // World px: the Plane turns it into its own local px.
223
+ const shadowBlur = Math.max(8, deviceSize * 0.04);
224
+ // Phones float: their shadow falls on a wall behind them. Laptops and displays stand: it pools on
225
+ // the floor under them.
226
+ const laptop = model === "macbook" || model === "macbook-pro";
227
+ const standing = laptop || model === "display";
228
+ return (
229
+ <>
230
+ {shadow > 0 ? (
231
+ <Group {...placement}>
232
+ {standing ? (
233
+ <Plane
234
+ y={deviceSize * fh * 0.5}
235
+ z={laptop ? deviceSize * 0.12 : 0}
236
+ tilt={90}
237
+ width={deviceSize * (laptop ? 1.02 : 0.5)}
238
+ height={deviceSize * (laptop ? 0.72 : 0.3)}
239
+ radius={deviceSize * 0.08}
240
+ background={shadowFill}
241
+ dof={false}
242
+ blur={shadowBlur}
243
+ />
244
+ ) : (
245
+ <Plane
246
+ z={-deviceSize * 0.06}
247
+ y={deviceSize * fh * 0.04}
248
+ width={deviceSize * fw * 0.92}
249
+ height={deviceSize * fh * 0.92}
250
+ radius={deviceSize * fw * 0.12}
251
+ background={shadowFill}
252
+ dof={false}
253
+ blur={shadowBlur}
254
+ />
255
+ )}
256
+ </Group>
257
+ ) : null}
258
+ <div
259
+ ref={holder}
260
+ style={{
261
+ position: "absolute",
262
+ left: 0,
263
+ top: 0,
264
+ width,
265
+ height,
266
+ opacity,
267
+ filter: blur > 0.5 ? `blur(${blur.toFixed(2)}px)` : undefined,
268
+ }}
269
+ />
270
+ {device && src && lifts?.length ? (
271
+ <Group {...placement}>
272
+ {lifts.map((lift, i) => {
273
+ // Lay the piece exactly over its spot on the screen, then raise it along the screen's normal.
274
+ const k = deviceSize / device.targetSize;
275
+ const toWorld = (x: number, y: number): V3 => {
276
+ const p = device.imagePoint(x, y, scroll, lidAngle);
277
+ return [p[0] * k, -p[1] * k, p[2] * k];
278
+ };
279
+ const [bx, by, bw, bh] = lift.box;
280
+ const p0 = toWorld(bx, by);
281
+ const ax = sub(toWorld(bx + bw, by), p0);
282
+ const ay = sub(toWorld(bx, by + bh), p0);
283
+ const w = len(ax);
284
+ const h = len(ay);
285
+ const ex = norm(ax);
286
+ const ey = norm(ay);
287
+ const n = norm(cross(ex, ey));
288
+ // The normal must face the viewer (z+) side of the screen.
289
+ const out: V3 = n[2] < 0 ? [-n[0], -n[1], -n[2]] : n;
290
+ const s = lift.scale ?? 1;
291
+ const c: V3 = [
292
+ p0[0] + ax[0] / 2 + ay[0] / 2 + out[0] * (lift.z + 0.6) + (lift.x ?? 0),
293
+ p0[1] + ax[1] / 2 + ay[1] / 2 + out[1] * (lift.z + 0.6) + (lift.y ?? 0),
294
+ p0[2] + ax[2] / 2 + ay[2] / 2 + out[2] * (lift.z + 0.6),
295
+ ];
296
+ const basis: M4 = [
297
+ ex[0] * s, ey[0] * s, out[0] * s, c[0],
298
+ ex[1] * s, ey[1] * s, out[1] * s, c[1],
299
+ ex[2] * s, ey[2] * s, out[2] * s, c[2],
300
+ 0, 0, 0, 1,
301
+ ];
302
+ const fullW = w / bw;
303
+ const fullH = h / bh;
304
+ return (
305
+ <Plane
306
+ key={i}
307
+ basis={basis}
308
+ width={w}
309
+ height={h}
310
+ radius={lift.radius ?? Math.min(w, h) * 0.08}
311
+ shadow={(lift.shadow ?? 0.8) * Math.min(1, lift.z / 40)}
312
+ shadowDepth={Math.max(10, lift.z)}
313
+ rim={lift.rim ?? 0.4}
314
+ opacity={(lift.opacity ?? 1) * opacity}
315
+ >
316
+ <Img src={src} style={{ position: "absolute", left: -bx * fullW, top: -by * fullH, width: fullW, height: fullH }} />
317
+ </Plane>
318
+ );
319
+ })}
320
+ </Group>
321
+ ) : null}
322
+ </>
323
+ );
324
+ }
@@ -0,0 +1,184 @@
1
+ import * as THREE from "three";
2
+ import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";
3
+ import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
4
+ import {
5
+ APPLE_MARK_SVG,
6
+ createRoundedExtrudedGeometry,
7
+ createRoundedPlaneGeometry,
8
+ } from "./iphone-model";
9
+
10
+ /**
11
+ * Procedural 27-inch desktop display on an aluminium stand, in the spirit of
12
+ * a Studio Display. Same millimetre scale as the laptop so the two read as
13
+ * the same family. The foot rests on y = 0; the screen faces +z.
14
+ */
15
+ const MM = 2 / 312.6;
16
+ const mm = (value: number) => value * MM;
17
+
18
+ const BODY = { w: 623, h: 361.4, t: 21, corner: 13, bezel: 12.6, glassInset: 1.1 };
19
+ const STAND = {
20
+ width: 152,
21
+ thickness: 9.5,
22
+ lift: 100,
23
+ attach: 40,
24
+ lean: 15,
25
+ foot: 150,
26
+ corner: 3.2,
27
+ };
28
+
29
+ export const DISPLAY_SCREEN_ASPECT =
30
+ (BODY.w - BODY.bezel * 2) / (BODY.h - BODY.bezel * 2);
31
+
32
+ function createLogoGeometry(width: number) {
33
+ const svg = new SVGLoader().parse(APPLE_MARK_SVG);
34
+ const shapes = svg.paths.flatMap((path) => SVGLoader.createShapes(path));
35
+ const geometry = new THREE.ShapeGeometry(shapes, 32);
36
+ geometry.center();
37
+ const scale = width / 814;
38
+ geometry.scale(scale, -scale, 1);
39
+ return geometry;
40
+ }
41
+
42
+ export interface DisplayModelOptions {
43
+ screenMaterial?: THREE.Material;
44
+ finishColor?: THREE.ColorRepresentation;
45
+ }
46
+
47
+ export function createDisplayModel(options: DisplayModelOptions = {}) {
48
+ const root = new THREE.Group();
49
+ root.name = "procedural-display";
50
+ const finish = new THREE.Color(options.finishColor ?? 0xcfd1d3);
51
+ const isDark = finish.getHSL({ h: 0, s: 0, l: 0 }).l < 0.35;
52
+ const aluminum = new THREE.MeshPhysicalMaterial({
53
+ color: finish,
54
+ metalness: 0.92,
55
+ roughness: 0.38,
56
+ clearcoat: 0.1,
57
+ clearcoatRoughness: 0.5,
58
+ });
59
+ const glass = new THREE.MeshBasicMaterial({ color: 0x030405 });
60
+ const lens = new THREE.MeshPhysicalMaterial({
61
+ color: 0x10162a,
62
+ roughness: 0.05,
63
+ metalness: 0.3,
64
+ clearcoat: 1,
65
+ });
66
+ const logoMaterial = new THREE.MeshPhysicalMaterial({
67
+ color: finish
68
+ .clone()
69
+ .lerp(new THREE.Color(isDark ? 0xffffff : 0x000000), isDark ? 0.2 : 0.45),
70
+ metalness: 1,
71
+ roughness: 0.05,
72
+ side: THREE.DoubleSide,
73
+ });
74
+ const screenOff = new THREE.MeshBasicMaterial({ color: 0x050608 });
75
+
76
+ const add = (name: string, mesh: THREE.Mesh, parent: THREE.Object3D = root) => {
77
+ mesh.name = name;
78
+ mesh.castShadow = true;
79
+ mesh.receiveShadow = true;
80
+ parent.add(mesh);
81
+ return mesh;
82
+ };
83
+
84
+ // ── Stand: a leaning neck that folds into a flat foot ──────────────
85
+ const lean = THREE.MathUtils.degToRad(STAND.lean);
86
+ const centerY = STAND.lift + BODY.h / 2;
87
+ const attachY = centerY - STAND.attach;
88
+ const neckLength = attachY / Math.cos(lean);
89
+ const attachZ = -BODY.t + 2;
90
+ const bottomZ = attachZ - attachY * Math.tan(lean);
91
+
92
+ const neck = add(
93
+ "display-neck",
94
+ new THREE.Mesh(
95
+ new RoundedBoxGeometry(
96
+ mm(STAND.width),
97
+ mm(neckLength),
98
+ mm(STAND.thickness),
99
+ 3,
100
+ mm(STAND.corner),
101
+ ),
102
+ aluminum,
103
+ ),
104
+ );
105
+ neck.position.set(0, mm(attachY / 2), mm((attachZ + bottomZ) / 2 - STAND.thickness / 2));
106
+ neck.rotation.x = lean;
107
+
108
+ const foot = add(
109
+ "display-foot",
110
+ new THREE.Mesh(
111
+ new RoundedBoxGeometry(
112
+ mm(STAND.width),
113
+ mm(STAND.thickness * 0.8),
114
+ mm(STAND.foot),
115
+ 3,
116
+ mm(STAND.corner),
117
+ ),
118
+ aluminum,
119
+ ),
120
+ );
121
+ foot.position.set(
122
+ 0,
123
+ mm((STAND.thickness * 0.8) / 2),
124
+ mm(bottomZ - STAND.thickness + STAND.foot / 2 - 18),
125
+ );
126
+
127
+ // ── Body ───────────────────────────────────────────────────────────
128
+ const bevel = mm(0.8);
129
+ const body = add(
130
+ "display-body",
131
+ new THREE.Mesh(
132
+ createRoundedExtrudedGeometry(
133
+ mm(BODY.w),
134
+ mm(BODY.h),
135
+ mm(BODY.corner),
136
+ mm(BODY.t) - bevel * 2,
137
+ bevel,
138
+ bevel,
139
+ ),
140
+ aluminum,
141
+ ),
142
+ );
143
+ body.position.set(0, mm(centerY), -mm(BODY.t / 2));
144
+
145
+ const front = add(
146
+ "display-glass",
147
+ new THREE.Mesh(
148
+ createRoundedPlaneGeometry(
149
+ mm(BODY.w - BODY.glassInset * 2),
150
+ mm(BODY.h - BODY.glassInset * 2),
151
+ mm(BODY.corner - BODY.glassInset),
152
+ ),
153
+ glass,
154
+ ),
155
+ );
156
+ front.position.set(0, mm(centerY), mm(0.3));
157
+
158
+ const screenWidth = BODY.w - BODY.bezel * 2;
159
+ const screenHeight = BODY.h - BODY.bezel * 2;
160
+ const screen = add(
161
+ "display-surface",
162
+ new THREE.Mesh(
163
+ createRoundedPlaneGeometry(mm(screenWidth), mm(screenHeight), mm(3.2)),
164
+ options.screenMaterial ?? screenOff,
165
+ ),
166
+ );
167
+ screen.position.set(0, mm(centerY), mm(0.6));
168
+ screen.castShadow = false;
169
+
170
+ const camera = add(
171
+ "display-camera",
172
+ new THREE.Mesh(new THREE.CircleGeometry(mm(1.6), 24), lens),
173
+ );
174
+ camera.position.set(0, mm(centerY + BODY.h / 2 - BODY.bezel / 2), mm(0.7));
175
+
176
+ const logo = add(
177
+ "display-logo",
178
+ new THREE.Mesh(createLogoGeometry(mm(34)), logoMaterial),
179
+ );
180
+ logo.rotation.y = Math.PI;
181
+ logo.position.set(0, mm(centerY + 30), -mm(BODY.t) - mm(0.4));
182
+
183
+ return root;
184
+ }