agentcut 0.2.4 → 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/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/skill/SKILL.md +16 -1
- 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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Seamless motion loops: each loop is a pure function of time drawn on a 2D canvas. Every motion in a
|
|
2
|
+
// loop repeats with a period that divides LOOP (12 s), so the frame at 12 s is the frame at 0 s and a
|
|
3
|
+
// loop can run under a clip of any length, or repeat, without a seam. No React here.
|
|
4
|
+
|
|
5
|
+
/** The loop length in seconds. Periods must divide it: 1, 1.5, 2, 3, 4, 6, 12. */
|
|
6
|
+
export const LOOP = 12;
|
|
7
|
+
export const TAU = Math.PI * 2;
|
|
8
|
+
|
|
9
|
+
export const clamp = (v: number, a = 0, b = 1) => Math.min(b, Math.max(a, v));
|
|
10
|
+
/** Fractional part in [0, 1): a tiny negative (float error) gives 0, never 1, so it is safe to index with. */
|
|
11
|
+
export const fract = (v: number) => {
|
|
12
|
+
const f = v - Math.floor(v);
|
|
13
|
+
return f < 1 ? f : 0;
|
|
14
|
+
};
|
|
15
|
+
/** Modulo that stays positive. */
|
|
16
|
+
export const mod = (a: number, n: number) => ((a % n) + n) % n;
|
|
17
|
+
export const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
|
|
18
|
+
|
|
19
|
+
/** 0…1 position inside a cycle of `period` seconds (offset in cycles). */
|
|
20
|
+
export const phase = (t: number, period: number, offset = 0) => fract(t / period + offset);
|
|
21
|
+
|
|
22
|
+
/** A fixed pseudo-random number in [0, 1) per element index and salt (never Math.random). */
|
|
23
|
+
export function rand(i: number, salt = 0) {
|
|
24
|
+
return fract(Math.sin(i * 127.1 + salt * 311.7 + 74.7) * 43758.5453123);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 0 before a, eases 0→1 between a and b (as a linear 0…1), 1 after b. */
|
|
28
|
+
export const win = (p: number, a: number, b: number) => clamp((p - a) / Math.max(1e-6, b - a));
|
|
29
|
+
|
|
30
|
+
export const smoothstep = (a: number, b: number, v: number) => {
|
|
31
|
+
const x = clamp((v - a) / (b - a));
|
|
32
|
+
return x * x * (3 - 2 * x);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const ease = {
|
|
36
|
+
linear: (k: number) => k,
|
|
37
|
+
inSine: (k: number) => 1 - Math.cos((k * Math.PI) / 2),
|
|
38
|
+
outSine: (k: number) => Math.sin((k * Math.PI) / 2),
|
|
39
|
+
inOutSine: (k: number) => -(Math.cos(Math.PI * k) - 1) / 2,
|
|
40
|
+
inCubic: (k: number) => k * k * k,
|
|
41
|
+
outCubic: (k: number) => 1 - Math.pow(1 - k, 3),
|
|
42
|
+
inOutCubic: (k: number) => (k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2),
|
|
43
|
+
outExpo: (k: number) => (k >= 1 ? 1 : 1 - Math.pow(2, -10 * k)),
|
|
44
|
+
inOutExpo: (k: number) =>
|
|
45
|
+
k <= 0 ? 0 : k >= 1 ? 1 : k < 0.5 ? Math.pow(2, 20 * k - 10) / 2 : (2 - Math.pow(2, -20 * k + 10)) / 2,
|
|
46
|
+
outBack: (k: number, s = 1.70158) => 1 + (s + 1) * Math.pow(k - 1, 3) + s * Math.pow(k - 1, 2),
|
|
47
|
+
inBack: (k: number, s = 1.70158) => (s + 1) * k * k * k - s * k * k,
|
|
48
|
+
/** Settles from 0 to 1 with a wobble; exactly 1 at k = 1. */
|
|
49
|
+
spring: (k: number, zeta = 0.35, freq = 3) => {
|
|
50
|
+
if (k >= 1) return 1;
|
|
51
|
+
const w = TAU * freq;
|
|
52
|
+
const v = 1 - Math.exp(-zeta * w * k) * Math.cos(w * Math.sqrt(1 - zeta * zeta) * k);
|
|
53
|
+
return lerp(v, 1, smoothstep(0.75, 1, k));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Smooth noise that repeats every `period` seconds (sines on a circle): drift, sway, breathing. */
|
|
58
|
+
export function loopNoise(t: number, seed = 0, period = LOOP) {
|
|
59
|
+
const a = TAU * phase(t, period);
|
|
60
|
+
return (
|
|
61
|
+
Math.sin(a + rand(seed, 1) * TAU) * 0.5 +
|
|
62
|
+
Math.sin(2 * a + rand(seed, 2) * TAU) * 0.3 +
|
|
63
|
+
Math.sin(3 * a + rand(seed, 3) * TAU) * 0.2
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Perspective projection, divided by depth once. */
|
|
68
|
+
export function proj(x: number, y: number, z: number, f: number, cx: number, cy: number) {
|
|
69
|
+
const s = f / Math.max(1e-3, z);
|
|
70
|
+
return { x: cx + x * s, y: cy + y * s, s };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ─── Colour ──────────────────────────────────────────────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
function parse(c: string): [number, number, number] {
|
|
76
|
+
const hex = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(c.trim());
|
|
77
|
+
if (hex) {
|
|
78
|
+
const h = hex[1].length === 3 ? hex[1].replace(/./g, (x) => x + x) : hex[1];
|
|
79
|
+
const n = parseInt(h, 16);
|
|
80
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
81
|
+
}
|
|
82
|
+
const rgb = /rgba?\(([^)]+)\)/i.exec(c);
|
|
83
|
+
if (rgb) {
|
|
84
|
+
const [r, g, b] = rgb[1].split(",").map((v) => parseFloat(v));
|
|
85
|
+
return [r || 0, g || 0, b || 0];
|
|
86
|
+
}
|
|
87
|
+
return [0, 0, 0];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A colour (hex or rgb()) at an alpha. */
|
|
91
|
+
export function rgba(c: string, a: number) {
|
|
92
|
+
const [r, g, b] = parse(c);
|
|
93
|
+
return `rgba(${r},${g},${b},${clamp(a)})`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Mix two colours (hex or rgb()). */
|
|
97
|
+
export function mixColor(a: string, b: string, k: number) {
|
|
98
|
+
const x = parse(a);
|
|
99
|
+
const y = parse(b);
|
|
100
|
+
return `rgb(${Math.round(lerp(x[0], y[0], k))},${Math.round(lerp(x[1], y[1], k))},${Math.round(lerp(x[2], y[2], k))})`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const luma = (c: string) => {
|
|
104
|
+
const [r, g, b] = parse(c);
|
|
105
|
+
return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type LoopTone = "dark" | "accent" | "light";
|
|
109
|
+
|
|
110
|
+
/** The palette a loop draws with. Never use other colours inside a loop. */
|
|
111
|
+
export interface LoopPalette {
|
|
112
|
+
/** Filled before draw() unless the loop is transparent. */
|
|
113
|
+
bg: string;
|
|
114
|
+
/** Main motif. */
|
|
115
|
+
fg: string;
|
|
116
|
+
/** Second colour, sparingly. */
|
|
117
|
+
fg2: string;
|
|
118
|
+
/** Between bg and fg: grids, quiet details. */
|
|
119
|
+
mid: string;
|
|
120
|
+
accent: string;
|
|
121
|
+
accent2: string;
|
|
122
|
+
paper: string;
|
|
123
|
+
ink: string;
|
|
124
|
+
tone: LoopTone;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Three tones from the brand colours: dark (deep brand-tinted background, accent motif), accent
|
|
129
|
+
* (accent background, ink motif), light (paper background, ink motif, accent as the second colour).
|
|
130
|
+
*/
|
|
131
|
+
export function loopPalette(accent: string, accent2: string, tone: LoopTone, paper = "#f5f3ee", ink = "#111216"): LoopPalette {
|
|
132
|
+
if (tone === "accent") {
|
|
133
|
+
const onAccent = luma(accent) > 0.6 ? ink : paper;
|
|
134
|
+
return { bg: accent, fg: onAccent, fg2: accent2, mid: mixColor(accent, onAccent, 0.3), accent, accent2, paper, ink, tone };
|
|
135
|
+
}
|
|
136
|
+
if (tone === "light") {
|
|
137
|
+
return { bg: paper, fg: ink, fg2: accent, mid: mixColor(paper, ink, 0.18), accent, accent2, paper, ink, tone };
|
|
138
|
+
}
|
|
139
|
+
const bg = mixColor(accent, "#07070b", 0.9);
|
|
140
|
+
return { bg, fg: accent, fg2: accent2, mid: mixColor(bg, accent, 0.28), accent, accent2, paper, ink, tone };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** What a loop's draw() receives besides the context. */
|
|
144
|
+
export interface LoopHelpers {
|
|
145
|
+
phase: typeof phase;
|
|
146
|
+
rand: typeof rand;
|
|
147
|
+
win: typeof win;
|
|
148
|
+
ease: typeof ease;
|
|
149
|
+
loopNoise: typeof loopNoise;
|
|
150
|
+
proj: typeof proj;
|
|
151
|
+
rgba: typeof rgba;
|
|
152
|
+
mixColor: typeof mixColor;
|
|
153
|
+
smoothstep: typeof smoothstep;
|
|
154
|
+
clamp: typeof clamp;
|
|
155
|
+
fract: typeof fract;
|
|
156
|
+
mod: typeof mod;
|
|
157
|
+
lerp: typeof lerp;
|
|
158
|
+
TAU: number;
|
|
159
|
+
LOOP: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const M: LoopHelpers = { phase, rand, win, ease, loopNoise, proj, rgba, mixColor, smoothstep, clamp, fract, mod, lerp, TAU, LOOP };
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* draw(ctx, w, h, t, P, M): paint the frame at t seconds (0 ≤ t < 12). The background is already
|
|
166
|
+
* filled (unless transparent). Sizes from u = h / 100 (min(w, h) for shapes); counts from w.
|
|
167
|
+
* `seed` varies element layouts so the same loop can look different per video.
|
|
168
|
+
*/
|
|
169
|
+
export type LoopDraw = (ctx: CanvasRenderingContext2D, w: number, h: number, t: number, P: LoopPalette, M: LoopHelpers, seed: number) => void;
|
|
170
|
+
|
|
171
|
+
export const LOOP_CATEGORIES = ["Backgrounds", "Shapes", "Symmetry", "Morphing", "Games", "Physics", "Generative"] as const;
|
|
172
|
+
export type LoopCategory = (typeof LOOP_CATEGORIES)[number];
|
|
173
|
+
|
|
174
|
+
export interface LoopDef {
|
|
175
|
+
id: string;
|
|
176
|
+
name: string;
|
|
177
|
+
kind: "background" | "shape";
|
|
178
|
+
/** Gallery group (defaults from kind). */
|
|
179
|
+
category?: LoopCategory;
|
|
180
|
+
/** What it looks like and when it works (Claude reads this). */
|
|
181
|
+
description: string;
|
|
182
|
+
tags: string[];
|
|
183
|
+
draw: LoopDraw;
|
|
184
|
+
}
|