agentcut 0.2.26 → 0.2.28
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 -177
- 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 +24 -24
- 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.js +8 -0
- 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/release-cursor.js +21 -21
- package/dist/studio/release-video.js +10 -10
- package/dist/studio/schema.d.ts +102 -0
- package/dist/studio/schema.js +5 -0
- package/dist/studio/schema.js.map +1 -1
- package/dist/studio/tools.js +7 -0
- package/dist/studio/tools.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 +1207 -1189
- package/template/runtime/helpers.tsx +230 -230
- package/template/runtime/index.tsx +26 -22
- package/template/runtime/types.ts +324 -315
- package/template/skill/SKILL.md +188 -187
- 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 +97 -97
- package/template/skill/references/editing-styles.md +57 -57
- package/template/skill/references/feature-launch.md +34 -34
- package/template/skill/references/footage.md +72 -72
- package/template/skill/references/format.md +145 -142
- package/template/skill/references/how-to.md +146 -146
- package/template/skill/references/launch-direction.md +89 -89
- package/template/skill/references/loops.md +151 -151
- package/template/skill/references/mcp-external.md +19 -19
- 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 +134 -134
- package/template/skill/references/release-capture.md +53 -53
- package/template/skill/references/sound.md +167 -166
- 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,191 +1,191 @@
|
|
|
1
|
-
// Small helpers shared by the components. Components import only react, remotion and this file,
|
|
2
|
-
// so they bundle the same way in the gallery, the studio preview, the browser export and a local render.
|
|
3
|
-
import { useLayoutEffect } from "react";
|
|
4
|
-
import { Easing, interpolate, spring, useDelayRender } from "remotion";
|
|
5
|
-
|
|
6
|
-
/** Scale for the frame size: 1 at 1080 px on the short side. */
|
|
7
|
-
export const unit = (width: number, height: number) => Math.min(width, height) / 1080;
|
|
8
|
-
|
|
9
|
-
export const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
|
|
10
|
-
|
|
11
|
-
/** 0→1 over `frames` starting at `start`, eased. */
|
|
12
|
-
export function ramp(frame: number, start: number, frames: number, easing = Easing.bezier(0.22, 1, 0.36, 1)) {
|
|
13
|
-
return interpolate(frame, [start, start + Math.max(1, frames)], [0, 1], {
|
|
14
|
-
extrapolateLeft: "clamp",
|
|
15
|
-
extrapolateRight: "clamp",
|
|
16
|
-
easing,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** A soft spring for entrances (no overshoot past ~4%). */
|
|
21
|
-
export function pop(frame: number, fps: number, delay = 0, stiffness = 170) {
|
|
22
|
-
return spring({ frame: frame - delay, fps, config: { damping: 18, stiffness, mass: 0.9 } });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** 1 while on screen, easing to 0 over the last `frames` of the clip (the shared exit). */
|
|
26
|
-
export function exitOut(frame: number, durationInFrames: number, frames = 12) {
|
|
27
|
-
return 1 - ramp(frame, durationInFrames - frames, frames, Easing.bezier(0.55, 0, 0.75, 0.25));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const mix = (a: number, b: number, t: number) => a + (b - a) * t;
|
|
31
|
-
|
|
32
|
-
/** Split "Make videos with *Claude*" into words, marking *starred* ones as highlighted. */
|
|
33
|
-
export function splitHighlights(line: string) {
|
|
34
|
-
return line
|
|
35
|
-
.split(/\s+/)
|
|
36
|
-
.filter(Boolean)
|
|
37
|
-
.map((word) => {
|
|
38
|
-
const highlighted = /^\*.*\*[.,!?:;]*$/.test(word);
|
|
39
|
-
return { text: highlighted ? word.replace(/\*/g, "") : word, highlighted };
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const FONTS: Record<string, string> = {
|
|
44
|
-
sans: 'Inter, "Geist", "Segoe UI", system-ui, -apple-system, sans-serif',
|
|
45
|
-
display: '"Bricolage Grotesque", "Geist", Inter, system-ui, sans-serif',
|
|
46
|
-
serif: '"Instrument Serif", Georgia, "Times New Roman", serif',
|
|
47
|
-
mono: '"Geist Mono", "JetBrains Mono", ui-monospace, Menlo, monospace',
|
|
48
|
-
grotesk: '"Space Grotesk", Inter, system-ui, sans-serif',
|
|
49
|
-
syne: 'Syne, "Bricolage Grotesque", Inter, system-ui, sans-serif',
|
|
50
|
-
fraunces: 'Fraunces, "Instrument Serif", Georgia, serif',
|
|
51
|
-
wide: 'Unbounded, "Bricolage Grotesque", Inter, system-ui, sans-serif',
|
|
52
|
-
condensed: 'Anton, "Bebas Neue", Impact, "Arial Narrow", sans-serif',
|
|
53
|
-
archivo: '"Archivo Black", "Arial Black", Inter, system-ui, sans-serif',
|
|
54
|
-
caveat: 'Caveat, "Segoe Print", "Comic Sans MS", cursive',
|
|
55
|
-
pixel: 'VT323, "Geist Mono", ui-monospace, monospace',
|
|
56
|
-
tech: 'Orbitron, Unbounded, "Space Grotesk", system-ui, sans-serif',
|
|
57
|
-
heavy: 'Montserrat, "Arial Black", Inter, system-ui, sans-serif',
|
|
58
|
-
retro: 'Bungee, "Arial Black", Impact, system-ui, sans-serif',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Every family in FONTS, from Google Fonts (variable axes where the family has them).
|
|
62
|
-
const FONTS_CSS =
|
|
63
|
-
"https://fonts.googleapis.com/css2?family=Inter:wght@400..900&family=Bricolage+Grotesque:opsz,wght@12..96,400..800" +
|
|
64
|
-
"&family=Instrument+Serif:ital@0;1&family=Geist+Mono:wght@400..700&family=Space+Grotesk:wght@400..700" +
|
|
65
|
-
"&family=Syne:wght@400..800&family=Fraunces:ital,opsz,wght@0,9..144,300..900;1,9..144,300..900" +
|
|
66
|
-
"&family=Unbounded:wght@400..900&family=Anton&family=Archivo+Black&family=Caveat:wght@400..700&family=VT323&family=Orbitron:wght@400..900&family=Montserrat:wght@500..900&family=Bungee" +
|
|
67
|
-
"&display=block";
|
|
68
|
-
const FONT_FACES = [
|
|
69
|
-
"700 40px Inter",
|
|
70
|
-
'700 40px "Bricolage Grotesque"',
|
|
71
|
-
'400 40px "Instrument Serif"',
|
|
72
|
-
'italic 400 40px "Instrument Serif"',
|
|
73
|
-
'500 40px "Geist Mono"',
|
|
74
|
-
'700 40px "Space Grotesk"',
|
|
75
|
-
"700 40px Syne",
|
|
76
|
-
"500 40px Fraunces",
|
|
77
|
-
"italic 500 40px Fraunces",
|
|
78
|
-
"700 40px Unbounded",
|
|
79
|
-
"400 40px Anton",
|
|
80
|
-
'400 40px "Archivo Black"',
|
|
81
|
-
"700 40px Caveat",
|
|
82
|
-
"400 40px VT323",
|
|
83
|
-
"800 40px Orbitron",
|
|
84
|
-
"900 40px Montserrat",
|
|
85
|
-
"400 40px Bungee",
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
let fontsLoaded = false;
|
|
89
|
-
let fontsLoading: Promise<void> | undefined;
|
|
90
|
-
|
|
91
|
-
/** Loads the library's fonts once per page (resolves even if the network fails: text falls back). */
|
|
92
|
-
export function loadMotionFonts() {
|
|
93
|
-
if (typeof document === "undefined") return Promise.resolve();
|
|
94
|
-
fontsLoading ??= new Promise<void>((resolve) => {
|
|
95
|
-
const done = () => {
|
|
96
|
-
fontsLoaded = true;
|
|
97
|
-
resolve();
|
|
98
|
-
};
|
|
99
|
-
const timeout = setTimeout(done, 10000);
|
|
100
|
-
const link = document.createElement("link");
|
|
101
|
-
link.rel = "stylesheet";
|
|
102
|
-
link.href = FONTS_CSS;
|
|
103
|
-
link.onload = () => {
|
|
104
|
-
Promise.allSettled(FONT_FACES.map((face) => document.fonts.load(face))).then(() => {
|
|
105
|
-
clearTimeout(timeout);
|
|
106
|
-
done();
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
link.onerror = () => {
|
|
110
|
-
clearTimeout(timeout);
|
|
111
|
-
done();
|
|
112
|
-
};
|
|
113
|
-
document.head.appendChild(link);
|
|
114
|
-
});
|
|
115
|
-
return fontsLoading;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Holds the render (export, still, local render) until the fonts are in, so frame 0 has the right type. */
|
|
119
|
-
export function useMotionFonts() {
|
|
120
|
-
const { delayRender, continueRender } = useDelayRender();
|
|
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]);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** The `background` prop as a CSS value ("transparent" keeps an overlay see-through). */
|
|
141
|
-
export const fill = (background: string) => (background === "transparent" ? undefined : background);
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Blur that the browser export draws cleanly: it clips a filtered element to its own box, so the
|
|
145
|
-
* box gets padding for the blur's spread (and a matching negative margin, so layout doesn't move).
|
|
146
|
-
*/
|
|
147
|
-
export function blurStyle(px: number) {
|
|
148
|
-
if (px < 0.3) return {};
|
|
149
|
-
const pad = Math.ceil(px * 2.5);
|
|
150
|
-
return { filter: `blur(${px.toFixed(2)}px)`, padding: pad, margin: -pad };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* A hex color at an alpha, as rgba(). Fade gradients to the color at alpha 0 rather than to
|
|
155
|
-
* "transparent" (transparent black), which greys the falloff in the browser export.
|
|
156
|
-
*/
|
|
157
|
-
export function alpha(hex: string, a: number) {
|
|
158
|
-
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
159
|
-
if (!m) return a <= 0 ? "transparent" : hex;
|
|
160
|
-
const n = parseInt(m[1], 16);
|
|
161
|
-
return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${a})`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* A soft radial glow centered at (x, y) px. The browser export only draws centered, unsized radial
|
|
166
|
-
* gradients, so the glow is a box of the glow's size with a plain radial-gradient inside.
|
|
167
|
-
*/
|
|
168
|
-
export function glowStyle(x: number, y: number, w: number, h: number, color: string, opacity = 1, reach = 0.7) {
|
|
169
|
-
return {
|
|
170
|
-
position: "absolute",
|
|
171
|
-
left: x - w / 2,
|
|
172
|
-
top: y - h / 2,
|
|
173
|
-
width: w,
|
|
174
|
-
height: h,
|
|
175
|
-
background: `radial-gradient(${color} 0%, ${alpha(color, 0)} ${Math.round(reach * 100)}%)`,
|
|
176
|
-
opacity,
|
|
177
|
-
} as const;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** Out-expo: fast start, long soft landing (the "premium" ease). */
|
|
181
|
-
export const easeOutExpo = Easing.bezier(0.16, 1, 0.3, 1);
|
|
182
|
-
export const easeInOut = Easing.bezier(0.65, 0, 0.35, 1);
|
|
183
|
-
|
|
184
|
-
/** Readable text on a color: near-black or white. */
|
|
185
|
-
export function onColor(hex: string) {
|
|
186
|
-
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
187
|
-
if (!m) return "#ffffff";
|
|
188
|
-
const n = parseInt(m[1], 16);
|
|
189
|
-
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
190
|
-
return 0.299 * r + 0.587 * g + 0.114 * b > 160 ? "#0b0d10" : "#ffffff";
|
|
191
|
-
}
|
|
1
|
+
// Small helpers shared by the components. Components import only react, remotion and this file,
|
|
2
|
+
// so they bundle the same way in the gallery, the studio preview, the browser export and a local render.
|
|
3
|
+
import { useLayoutEffect } from "react";
|
|
4
|
+
import { Easing, interpolate, spring, useDelayRender } from "remotion";
|
|
5
|
+
|
|
6
|
+
/** Scale for the frame size: 1 at 1080 px on the short side. */
|
|
7
|
+
export const unit = (width: number, height: number) => Math.min(width, height) / 1080;
|
|
8
|
+
|
|
9
|
+
export const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
|
|
10
|
+
|
|
11
|
+
/** 0→1 over `frames` starting at `start`, eased. */
|
|
12
|
+
export function ramp(frame: number, start: number, frames: number, easing = Easing.bezier(0.22, 1, 0.36, 1)) {
|
|
13
|
+
return interpolate(frame, [start, start + Math.max(1, frames)], [0, 1], {
|
|
14
|
+
extrapolateLeft: "clamp",
|
|
15
|
+
extrapolateRight: "clamp",
|
|
16
|
+
easing,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A soft spring for entrances (no overshoot past ~4%). */
|
|
21
|
+
export function pop(frame: number, fps: number, delay = 0, stiffness = 170) {
|
|
22
|
+
return spring({ frame: frame - delay, fps, config: { damping: 18, stiffness, mass: 0.9 } });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 1 while on screen, easing to 0 over the last `frames` of the clip (the shared exit). */
|
|
26
|
+
export function exitOut(frame: number, durationInFrames: number, frames = 12) {
|
|
27
|
+
return 1 - ramp(frame, durationInFrames - frames, frames, Easing.bezier(0.55, 0, 0.75, 0.25));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const mix = (a: number, b: number, t: number) => a + (b - a) * t;
|
|
31
|
+
|
|
32
|
+
/** Split "Make videos with *Claude*" into words, marking *starred* ones as highlighted. */
|
|
33
|
+
export function splitHighlights(line: string) {
|
|
34
|
+
return line
|
|
35
|
+
.split(/\s+/)
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.map((word) => {
|
|
38
|
+
const highlighted = /^\*.*\*[.,!?:;]*$/.test(word);
|
|
39
|
+
return { text: highlighted ? word.replace(/\*/g, "") : word, highlighted };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const FONTS: Record<string, string> = {
|
|
44
|
+
sans: 'Inter, "Geist", "Segoe UI", system-ui, -apple-system, sans-serif',
|
|
45
|
+
display: '"Bricolage Grotesque", "Geist", Inter, system-ui, sans-serif',
|
|
46
|
+
serif: '"Instrument Serif", Georgia, "Times New Roman", serif',
|
|
47
|
+
mono: '"Geist Mono", "JetBrains Mono", ui-monospace, Menlo, monospace',
|
|
48
|
+
grotesk: '"Space Grotesk", Inter, system-ui, sans-serif',
|
|
49
|
+
syne: 'Syne, "Bricolage Grotesque", Inter, system-ui, sans-serif',
|
|
50
|
+
fraunces: 'Fraunces, "Instrument Serif", Georgia, serif',
|
|
51
|
+
wide: 'Unbounded, "Bricolage Grotesque", Inter, system-ui, sans-serif',
|
|
52
|
+
condensed: 'Anton, "Bebas Neue", Impact, "Arial Narrow", sans-serif',
|
|
53
|
+
archivo: '"Archivo Black", "Arial Black", Inter, system-ui, sans-serif',
|
|
54
|
+
caveat: 'Caveat, "Segoe Print", "Comic Sans MS", cursive',
|
|
55
|
+
pixel: 'VT323, "Geist Mono", ui-monospace, monospace',
|
|
56
|
+
tech: 'Orbitron, Unbounded, "Space Grotesk", system-ui, sans-serif',
|
|
57
|
+
heavy: 'Montserrat, "Arial Black", Inter, system-ui, sans-serif',
|
|
58
|
+
retro: 'Bungee, "Arial Black", Impact, system-ui, sans-serif',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Every family in FONTS, from Google Fonts (variable axes where the family has them).
|
|
62
|
+
const FONTS_CSS =
|
|
63
|
+
"https://fonts.googleapis.com/css2?family=Inter:wght@400..900&family=Bricolage+Grotesque:opsz,wght@12..96,400..800" +
|
|
64
|
+
"&family=Instrument+Serif:ital@0;1&family=Geist+Mono:wght@400..700&family=Space+Grotesk:wght@400..700" +
|
|
65
|
+
"&family=Syne:wght@400..800&family=Fraunces:ital,opsz,wght@0,9..144,300..900;1,9..144,300..900" +
|
|
66
|
+
"&family=Unbounded:wght@400..900&family=Anton&family=Archivo+Black&family=Caveat:wght@400..700&family=VT323&family=Orbitron:wght@400..900&family=Montserrat:wght@500..900&family=Bungee" +
|
|
67
|
+
"&display=block";
|
|
68
|
+
const FONT_FACES = [
|
|
69
|
+
"700 40px Inter",
|
|
70
|
+
'700 40px "Bricolage Grotesque"',
|
|
71
|
+
'400 40px "Instrument Serif"',
|
|
72
|
+
'italic 400 40px "Instrument Serif"',
|
|
73
|
+
'500 40px "Geist Mono"',
|
|
74
|
+
'700 40px "Space Grotesk"',
|
|
75
|
+
"700 40px Syne",
|
|
76
|
+
"500 40px Fraunces",
|
|
77
|
+
"italic 500 40px Fraunces",
|
|
78
|
+
"700 40px Unbounded",
|
|
79
|
+
"400 40px Anton",
|
|
80
|
+
'400 40px "Archivo Black"',
|
|
81
|
+
"700 40px Caveat",
|
|
82
|
+
"400 40px VT323",
|
|
83
|
+
"800 40px Orbitron",
|
|
84
|
+
"900 40px Montserrat",
|
|
85
|
+
"400 40px Bungee",
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
let fontsLoaded = false;
|
|
89
|
+
let fontsLoading: Promise<void> | undefined;
|
|
90
|
+
|
|
91
|
+
/** Loads the library's fonts once per page (resolves even if the network fails: text falls back). */
|
|
92
|
+
export function loadMotionFonts() {
|
|
93
|
+
if (typeof document === "undefined") return Promise.resolve();
|
|
94
|
+
fontsLoading ??= new Promise<void>((resolve) => {
|
|
95
|
+
const done = () => {
|
|
96
|
+
fontsLoaded = true;
|
|
97
|
+
resolve();
|
|
98
|
+
};
|
|
99
|
+
const timeout = setTimeout(done, 10000);
|
|
100
|
+
const link = document.createElement("link");
|
|
101
|
+
link.rel = "stylesheet";
|
|
102
|
+
link.href = FONTS_CSS;
|
|
103
|
+
link.onload = () => {
|
|
104
|
+
Promise.allSettled(FONT_FACES.map((face) => document.fonts.load(face))).then(() => {
|
|
105
|
+
clearTimeout(timeout);
|
|
106
|
+
done();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
link.onerror = () => {
|
|
110
|
+
clearTimeout(timeout);
|
|
111
|
+
done();
|
|
112
|
+
};
|
|
113
|
+
document.head.appendChild(link);
|
|
114
|
+
});
|
|
115
|
+
return fontsLoading;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Holds the render (export, still, local render) until the fonts are in, so frame 0 has the right type. */
|
|
119
|
+
export function useMotionFonts() {
|
|
120
|
+
const { delayRender, continueRender } = useDelayRender();
|
|
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]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The `background` prop as a CSS value ("transparent" keeps an overlay see-through). */
|
|
141
|
+
export const fill = (background: string) => (background === "transparent" ? undefined : background);
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Blur that the browser export draws cleanly: it clips a filtered element to its own box, so the
|
|
145
|
+
* box gets padding for the blur's spread (and a matching negative margin, so layout doesn't move).
|
|
146
|
+
*/
|
|
147
|
+
export function blurStyle(px: number) {
|
|
148
|
+
if (px < 0.3) return {};
|
|
149
|
+
const pad = Math.ceil(px * 2.5);
|
|
150
|
+
return { filter: `blur(${px.toFixed(2)}px)`, padding: pad, margin: -pad };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A hex color at an alpha, as rgba(). Fade gradients to the color at alpha 0 rather than to
|
|
155
|
+
* "transparent" (transparent black), which greys the falloff in the browser export.
|
|
156
|
+
*/
|
|
157
|
+
export function alpha(hex: string, a: number) {
|
|
158
|
+
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
159
|
+
if (!m) return a <= 0 ? "transparent" : hex;
|
|
160
|
+
const n = parseInt(m[1], 16);
|
|
161
|
+
return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${a})`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A soft radial glow centered at (x, y) px. The browser export only draws centered, unsized radial
|
|
166
|
+
* gradients, so the glow is a box of the glow's size with a plain radial-gradient inside.
|
|
167
|
+
*/
|
|
168
|
+
export function glowStyle(x: number, y: number, w: number, h: number, color: string, opacity = 1, reach = 0.7) {
|
|
169
|
+
return {
|
|
170
|
+
position: "absolute",
|
|
171
|
+
left: x - w / 2,
|
|
172
|
+
top: y - h / 2,
|
|
173
|
+
width: w,
|
|
174
|
+
height: h,
|
|
175
|
+
background: `radial-gradient(${color} 0%, ${alpha(color, 0)} ${Math.round(reach * 100)}%)`,
|
|
176
|
+
opacity,
|
|
177
|
+
} as const;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Out-expo: fast start, long soft landing (the "premium" ease). */
|
|
181
|
+
export const easeOutExpo = Easing.bezier(0.16, 1, 0.3, 1);
|
|
182
|
+
export const easeInOut = Easing.bezier(0.65, 0, 0.35, 1);
|
|
183
|
+
|
|
184
|
+
/** Readable text on a color: near-black or white. */
|
|
185
|
+
export function onColor(hex: string) {
|
|
186
|
+
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
187
|
+
if (!m) return "#ffffff";
|
|
188
|
+
const n = parseInt(m[1], 16);
|
|
189
|
+
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
190
|
+
return 0.299 * r + 0.587 * g + 0.114 * b > 160 ? "#0b0d10" : "#ffffff";
|
|
191
|
+
}
|