Skip to content

Open source CapCut alternative.

TypeScript

feat(site): effects, drawn stickers and title tools [rebuild]

David Lefb51cf1070f7
diff --git a/site/packages/effects-kit/src/effects.ts b/site/packages/effects-kit/src/effects.ts
index 88f431d1..fdf85b64 100644
--- a/site/packages/effects-kit/src/effects.ts
+++ b/site/packages/effects-kit/src/effects.ts
@@ -22,6 +22,7 @@ export type VisualEffectId =
| "blur"
| "vignette"
| "lightleak"
+ | "lightbars"
| "flash"
| "shake"
| "negative"
@@ -67,6 +68,9 @@ export interface EffectOverlay extends OverlayBase {
rate?: number;
/** How a strobe's pulses land; absent = strobe. */
rhythm?: FlashRhythm;
+ /** A flash that ramps across the whole element instead of popping:
+ * absent = the pop (or the strobe). */
+ fade?: FlashFade;
}
/** A flash's color: `white` pops the picture bright, `black` dips it dark. */
@@ -85,8 +89,22 @@ export const FLASH_RATE_MAX = 15;
export const FLASH_RHYTHMS = ["strobe", "flicker"] as const;
export type FlashRhythm = (typeof FLASH_RHYTHMS)[number];
-/** What a flash plays beyond its amount: its tone, strobe rate and rhythm. */
-export type FlashPulse = Pick<EffectOverlay, "tone" | "rate" | "rhythm">;
+/** A flash that ramps instead of popping, evenly across its element and up
+ * to the full tone at amount 1: `to` fades the picture into the tone (a fade
+ * to black over the end of a scene), `from` starts on the tone and clears (a
+ * fade up from black). It covers everything on the rows behind its own, so
+ * on the front row it fades a whole stacked page as one. */
+export const FLASH_FADES = ["to", "from"] as const;
+export type FlashFade = (typeof FLASH_FADES)[number];
+
+/** The fade a person or the assistant picks: `none` is the pop (or the
+ * strobe) and stores as absence. */
+export const FLASH_FADE_NONE = "none";
+export const FLASH_FADE_CHOICES = [FLASH_FADE_NONE, ...FLASH_FADES] as const;
+export type FlashFadeChoice = (typeof FLASH_FADE_CHOICES)[number];
+
+/** What a flash plays beyond its amount: its tone, strobe rate, rhythm and fade. */
+export type FlashPulse = Pick<EffectOverlay, "tone" | "rate" | "rhythm" | "fade">;
/** How far past a frame's time a pulse is read, in pulses: at the top rate
* every 30 fps frame lands on a pulse's edge, and the nudge keeps rounding
@@ -169,6 +187,7 @@ export const EFFECT_IDS: VisualEffectId[] = [
"blur",
"vignette",
"lightleak",
+ "lightbars",
"flash",
"shake",
"negative",
@@ -252,6 +271,7 @@ export const EFFECT_LABELS: Record<EffectId, string> = {
blur: "Blur",
vignette: "Vignette",
lightleak: "Light leak",
+ lightbars: "Light bars",
flash: "Flash",
shake: "Shake",
negative: "Negative",
@@ -489,6 +509,254 @@ export const burnStreakGradient = (s: BurnStreak) =>
`${rgba(s.rgb ?? BURN_FLAME, 1)} ${(s.p * 100).toFixed(1)}%, ` +
`${rgba(s.rgb ?? BURN_FLAME, 0)} ${((s.p + 2 * s.w) * 100).toFixed(1)}%)`;
+/**
+ * Light bars, the streaming-service sting: the camera flies down a ribbon of
+ * glowing vertical lines — warm reds, oranges and pinks on the left, blues on
+ * the right — across the element's length. Every line hangs at its own
+ * depth, so the ribbon opens as one narrow warm column with every line packed
+ * inside it, bursts out to fill the frame as its nearest lines rush past,
+ * keeps flowing outward as the deeper lines spread after them, flares red
+ * and pink as the last broad lines pass close, and ends on the one red line
+ * the camera was flying at, widening until it sweeps off the right edge.
+ * Bars are added onto the picture (over black, they are the picture);
+ * amount is their brightness.
+ */
+
+/** Length the bars play over when nothing gives them one. */
+export const LIGHTBARS_SECONDS = 1.65;
+
+/** One line of the ribbon. It starts `th` frame widths off the camera's
+ * axis with half-width `w`; both grow as T / (T - u), `u` the share of the
+ * element played and `T` the share at which the camera reaches the line's
+ * depth (past 1, it never does). It lights over `LB_ON_SPAN` from `on` and
+ * goes out over `LB_OFF_SPAN` up to `off`; `a` is its peak opacity. */
+interface RibbonLine {
+ T: number;
+ th: number;
+ w: number;
+ rgb: [number, number, number];
+ a: number;
+ on?: number;
+ off?: number;
+}
+
+const LB_RED: [number, number, number] = [248, 18, 6];
+const LB_DEEP: [number, number, number] = [165, 6, 2];
+const LB_ORANGE: [number, number, number] = [255, 104, 32];
+const LB_AMBER: [number, number, number] = [255, 168, 64];
+const LB_PINK: [number, number, number] = [255, 72, 128];
+const LB_ROSE: [number, number, number] = [255, 214, 222];
+const LB_VIOLET: [number, number, number] = [168, 76, 210];
+const LB_BLUE: [number, number, number] = [26, 76, 255];
+const LB_NAVY: [number, number, number] = [16, 36, 196];
+const LB_CYAN: [number, number, number] = [44, 186, 255];
+const LB_ICE: [number, number, number] = [130, 206, 255];
+
+/** The camera's axis across the frame: the column opens on it, and every
+ * line flows outward from it. */
+const LB_AXIS = 0.46;
+/** Lines dim over the last `LB_NEAR` of their approach, so a line rushing
+ * past sweeps through rather than blanking the frame. */
+const LB_NEAR = 0.03;
+/** Shares of the element the ribbon takes to appear, a late line to light
+ * and a line with an `off` to go out. */
+const LB_APPEAR = 0.05;
+const LB_ON_SPAN = 0.04;
+const LB_OFF_SPAN = 0.03;
+/** Lines one ffmpeg expression draws; the ribbon is drawn in runs of them. */
+const LB_FFMPEG_RUN = 30;
+
+/** The line the camera flies at: inside the column at the start, the one
+ * left once the rest have passed, and reached as the element ends. */
+const LB_ANCHOR: RibbonLine = { T: 1, th: 0.0088, w: 0.0026, rgb: [255, 36, 8], a: 1 };
+
+/** The ribbon, dealt once from a fixed hash so every renderer draws the same
+ * lines: the warm column the camera bursts through, then warm lines left of
+ * the axis and cool ones right of it, the outer ones leaving first, then the
+ * broad lines of the closing flare and the anchor. */
+const RIBBON: RibbonLine[] = (() => {
+ const deal = (n: number) => {
+ const v = Math.sin(n * 91.345 + 47.853) * 24634.6345;
+ return v - Math.floor(v);
+ };
+ type Palette = [[number, number, number], number][];
+ const pick = (r: number, pal: Palette) => {
+ let acc = 0;
+ for (const [rgb, p] of pal) {
+ acc += p;
+ if (r < acc) return rgb;
+ }
+ return pal[pal.length - 1][0];
+ };
+ const column: Palette = [
+ [LB_RED, 0.42],
+ [LB_DEEP, 0.34],
+ [LB_ORANGE, 0.1],
+ [LB_AMBER, 0.09],
+ [LB_VIOLET, 0.05],
+ ];
+ const flare: Palette = [
+ [LB_ROSE, 0.25],
+ [LB_PINK, 0.25],
+ [LB_VIOLET, 0.2],
+ [LB_ORANGE, 0.15],
+ [LB_RED, 0.15],
+ ];
+ const warm: Palette = [
+ [LB_RED, 0.34],
+ [LB_DEEP, 0.24],
+ [LB_ORANGE, 0.14],
+ [LB_PINK, 0.12],
+ [LB_ROSE, 0.06],
+ [LB_AMBER, 0.05],
+ [LB_VIOLET, 0.05],
+ ];
+ const cool: Palette = [
+ [LB_BLUE, 0.44],
+ [LB_NAVY, 0.26],
+ [LB_CYAN, 0.16],
+ [LB_ICE, 0.08],
+ [LB_VIOLET, 0.06],
+ ];
+ // The depth at which a line `th` off the axis leaves the frame's edge
+ // `exit` of the way through.
+ const reach = (th: number, exit: number) => exit / (1 - Math.abs(th) / (th < 0 ? LB_AXIS : 1 - LB_AXIS));
+ const lines: RibbonLine[] = [];
+ for (let i = 0; i < 48; i++) {
+ lines.push({
+ T: 0.278 + 0.04 * deal(i + 500),
+ th: -0.04 + (0.08 * (i + deal(i))) / 48,
+ w: 0.0004 + 0.002 * deal(i + 100) ** 2,
+ rgb: pick(deal(i + 200), column),
+ a: 0.25 + 0.5 * deal(i + 300) ** 0.7,
+ });
+ }
+ for (let i = 0; i < 26; i++) {
+ const f = (i + deal(i + 800)) / 26; // outer to inner
+ const th = -0.2 + 0.18 * f;
+ lines.push({
+ T: reach(th, 0.4 + 0.3 * f ** 1.5 + 0.04 * (deal(i + 700) - 0.5)),
+ th,
+ w: 0.0006 + 0.0026 * deal(i + 1000) ** 2,
+ rgb: pick(deal(i + 1100), warm),
+ a: (0.3 + 0.5 * deal(i + 1200) ** 0.7) * (f < 0.45 ? 1.5 : 0.55),
+ on: 0.25 + 0.04 * deal(i + 900),
+ });
+ }
+ // The burst's bright middle, gone as the field settles.
+ for (let i = 0; i < 12; i++) {
+ const th = -0.035 + (0.07 * (i + deal(i + 4800))) / 12;
+ lines.push({
+ T: reach(th, 0.38 + 0.07 * deal(i + 4700)),
+ th,
+ w: 0.0006 + 0.0024 * deal(i + 5000) ** 2,
+ rgb: pick(deal(i + 5100), flare),
+ a: 0.5 + 0.4 * deal(i + 5200),
+ on: 0.24,
+ });
+ }
+ for (let i = 0; i < 16; i++) {
+ const th = -0.02 + (0.045 * (i + deal(i + 1800))) / 16;
+ lines.push({
+ T: reach(th, 0.72 + 0.06 * deal(i + 1700)),
+ th,
+ w: 0.0006 + 0.0022 * deal(i + 2000) ** 2,
+ rgb: pick(deal(i + 2100), warm),
+ a: 0.3 + 0.5 * deal(i + 2200) ** 0.7,
+ on: 0.25 + 0.04 * deal(i + 1900),
+ });
+ }
+ for (let i = 0; i < 30; i++) {
+ const f = (i + deal(i + 2800)) / 30; // inner to outer
+ const th = 0.03 + 0.2 * f;
+ lines.push({
+ T: reach(th, 0.63 - 0.15 * f + 0.04 * (deal(i + 2700) - 0.5)),
+ th,
+ w: 0.0008 + 0.0032 * deal(i + 3000) ** 2,
+ rgb: pick(deal(i + 3100), cool),
+ a: 0.65 * (0.45 + 0.55 * deal(i + 3200) ** 0.7),
+ on: 0.25 + 0.04 * deal(i + 2900),
+ });
+ }
+ // The closing flare: broad red and pink lines passing close to the axis,
+ // and a far red band that glows on the left while they do.
+ lines.push(
+ { T: 0.792, th: -0.012, w: 0.0024, rgb: LB_RED, a: 0.8, on: 0.5 },
+ { T: 0.778, th: 0.01, w: 0.0018, rgb: LB_ROSE, a: 0.8, on: 0.5 },
+ { T: 0.788, th: 0.016, w: 0.0012, rgb: LB_PINK, a: 0.8, on: 0.5 },
+ { T: 0.8, th: -0.02, w: 0.0014, rgb: LB_RED, a: 0.8, on: 0.5 },
+ { T: 0.805, th: 0.022, w: 0.001, rgb: LB_PINK, a: 0.6, on: 0.5 },
+ { T: 6, th: -0.27, w: 0.022, rgb: LB_RED, a: 0.9, on: 0.72, off: 0.84 }
+ );
+ return [...lines, LB_ANCHOR];
+})();
+
+/** A bar's profile across its half-width: a solid core out to `LB_CORE`,
+ * fading to nothing at `LB_EDGE`, inside a faint glow reaching `LB_HALO`.
+ * Piecewise linear, so a gradient's color stops draw it exactly. */
+const LB_CORE = 0.6;
+const LB_EDGE = 1.5;
+const LB_HALO = 4;
+const LB_HALO_SHARE = 0.2;
+const lbProfile = (d: number) => {
+ const a = Math.abs(d);
+ const core = Math.max(0, Math.min(1, (LB_EDGE - a) / (LB_EDGE - LB_CORE)));
+ return (1 - LB_HALO_SHARE) * core + LB_HALO_SHARE * Math.max(0, 1 - a / LB_HALO);
+};
+/** The profile's breakpoints, in half-widths from the center. */
+export const LIGHTBAR_STOPS = [-LB_HALO, -LB_EDGE, -LB_CORE, 0, LB_CORE, LB_EDGE, LB_HALO].map((d) => ({
+ d,
+ f: lbProfile(d),
+}));
+
+/** One bar on screen: center `x` and half-width `w` as frame-width
+ * fractions, color, and opacity. */
+export interface LightBar {
+ x: number;
+ w: number;
+ rgb: [number, number, number];
+ alpha: number;
+}
+
+const clip01 = (v: number) => Math.max(0, Math.min(1, v));
+
+/** The bars on screen `tLocal` seconds into an element `dur` long, at
+ * amount `k`. Lines the camera has passed and bars wholly off the frame are
+ * left out. */
+export function lightbarsAt(tLocal: number, dur: number, k: number): LightBar[] {
+ const u = clip01(tLocal / Math.max(dur, 1e-3));
+ const appear = Math.min(1, u / LB_APPEAR);
+ const gain = 0.4 + 0.6 * k;
+ return RIBBON.flatMap((l) => {
+ const left = l.T - u;
+ if (left <= 1e-3) return [];
+ const s = l.T / left;
+ const x = LB_AXIS + l.th * s;
+ const w = l.w * s;
+ const on = l.on ? clip01((u - l.on) / LB_ON_SPAN) : 1;
+ const off = l.off ? clip01((l.off - u) / LB_OFF_SPAN) : 1;
+ const alpha = l.a * gain * appear * on * off * Math.min(1, left / LB_NEAR);
+ if (alpha <= 0.002 || x + LB_HALO * w < 0 || x - LB_HALO * w > 1) return [];
+ return [{ x, w, rgb: l.rgb, alpha }];
+ });
+}
+
+/** One bar as a CSS box — the DOM twin of the canvas pass's horizontal
+ * gradient: a full-height layer only as wide as the bar's glow (cut to the
+ * frame), its gradient in the box's own coordinates. Add it onto the picture
+ * (plus-lighter); compositing scales with the bars' width, not their count. */
+export function lightbarBox(b: LightBar): { left: string; width: string; background: string } {
+ const lo = Math.max(0, b.x + LIGHTBAR_STOPS[0].d * b.w);
+ const hi = Math.min(1, b.x + LIGHTBAR_STOPS[LIGHTBAR_STOPS.length - 1].d * b.w);
+ const span = Math.max(hi - lo, 1e-6);
+ const at = (s: { d: number }) => fmt(((b.x + s.d * b.w - lo) / span) * 100);
+ return {
+ left: `${fmt(lo * 100)}%`,
+ width: `${fmt(span * 100)}%`,
+ background: `linear-gradient(to right, ${LIGHTBAR_STOPS.map((s) => `${rgba(b.rgb, b.alpha * s.f)} ${at(s)}%`).join(", ")})`,
+ };
+}
+
/** The ellipse a wash covers, in frame fractions: center (x, y), radii (rx,
* ry). The wash holds its full strength out to `inner` of the way to the rim
* and fades to nothing at it. */
@@ -560,6 +828,8 @@ export interface EffectPreviewState {
glow?: { blurFrac: number; alpha: number; mode: "screen" | "lighten"; bright?: boolean };
/** A film burn climbing over the picture (see `burnAt`). */
burn?: BurnPaint;
+ /** Light bars added onto the picture (see `lightbarsAt`). */
+ bars?: LightBar[];
}
/** A host-registered effect recipe: the same dual-renderer shape the
@@ -716,6 +986,8 @@ function glitchRunAt(step: number, k: number): { kind: GlitchKind; len: number }
/** The amount a pinned glitch pulls its full travel at; the travel scales
* with amount from there, so 0.15 is a faint fringe and 1 twice the pull. */
const PINNED_GLITCH_AMOUNT = 0.5;
+/** The furthest rgbashift moves a channel, px. */
+const RGBASHIFT_MAX = 255;
/** What the glitch does on step `step` at amount `k`; null = a clean step.
* The latest run to start plays until it ends, then the picture is clean
@@ -867,8 +1139,13 @@ export function effectPreviewState(
};
case "flash": {
// One pop at the element start, decaying over ~0.4s; on a strobe, the
- // tone held hard for the first half of every pulse.
+ // tone held hard for the first half of every pulse; on a fade, the
+ // tone ramped evenly across the element, to full at amount 1.
const tone = pulse?.tone === "black" ? "black" : undefined;
+ if (pulse?.fade && dur) {
+ const u = Math.max(0, Math.min(1, tLocal / dur));
+ return { cssFilter: "", flash: k * (pulse.fade === "to" ? u : 1 - u), ...(tone ? { flashTone: tone } : {}) };
+ }
const rate = flashRate(pulse);
const gain = rate ? flashOn(tLocal, rate, pulse?.rhythm) : Math.exp(-9 * Math.max(0, tLocal));
return { cssFilter: "", flash: Math.min(1, 0.85 * k * gain), ...(tone ? { flashTone: tone } : {}) };
@@ -877,6 +1154,8 @@ export function effectPreviewState(
return { cssFilter: "", burn: burnAt(tLocal, dur ?? BURN_SECONDS, k) };
case "char":
return { cssFilter: "", burn: burnAt(tLocal, dur ?? BURN_SECONDS, k, CHAR_PALETTE) };
+ case "lightbars":
+ return { cssFilter: "", bars: lightbarsAt(tLocal, dur ?? LIGHTBARS_SECONDS, k) };
case "scorch":
return scorchState(tLocal, k);
case "film":
@@ -1221,6 +1500,25 @@ export function applyEffectToCanvas(
});
}
}
+
+ if (state.bars) {
+ // Each bar a horizontal gradient through the profile's stops, all summed
+ // in one pass ("lighter" inside it too) and added onto the picture the
+ // way the DOM twin's plus-lighter does: one mask and composite a frame
+ // however many bars are up.
+ const bars = state.bars;
+ const lo = LIGHTBAR_STOPS[0].d;
+ const hi = LIGHTBAR_STOPS[LIGHTBAR_STOPS.length - 1].d;
+ over("lighter", 1, (c) => {
+ c.globalCompositeOperation = "lighter";
+ for (const b of bars) {
+ const g = c.createLinearGradient((b.x + lo * b.w) * W, 0, (b.x + hi * b.w) * W, 0);
+ for (const st of LIGHTBAR_STOPS) g.addColorStop((st.d - lo) / (hi - lo), rgba(b.rgb, b.alpha * st.f));
+ c.fillStyle = g;
+ c.fillRect(Math.floor((b.x + lo * b.w) * W), 0, Math.ceil((hi - lo) * b.w * W) + 2, H);
+ }
+ });
+ }
}
/**
@@ -1400,14 +1698,17 @@ function glitchFilterLines(
return lines;
}
+ const clampShift = (n: number) => Math.max(-RGBASHIFT_MAX, Math.min(RGBASHIFT_MAX, n));
// Rgb, pinned only: one channel shift per step, gated to it, since
// rgbashift takes whole px and no expressions. A 2-frame burst is 1–2.
const shifts = hits
.filter((x) => x.hit.kind === "rgb")
.map((x) => {
const o = glitchRgb(x.hit);
- const rh = Math.round((o.dx * px) / 1080);
- const rv = Math.round((o.dy * px) / 1080);
+ // rgbashift refuses a shift past 255 px, which a full-amount pull
+ // reaches on an 8K frame.
+ const rh = clampShift(Math.round((o.dx * px) / 1080));
+ const rv = clampShift(Math.round((o.dy * px) / 1080));
return `rgbashift=rh=${rh}:rv=${rv}:bh=${-rh}:bv=${-rv}:enable='${win(x)}'`;
});
lines.push(`[gbo${tag}]${shifts.join(",")}[${outLabel}]`);
@@ -1546,6 +1847,18 @@ export function effectFilterLines(
// per frame by geq — `T` is the frame's time, so the gain rides every
// frame of the window. White adds to luma; black pulls every plane
// toward black at the canvas pass's alpha.
+ if (pulse?.fade) {
+ // The fade's even ramp: every plane pulled toward the tone at the
+ // canvas pass's alpha, white as well as black.
+ const u = `clip((T-${fmt(start)})/${fmt(Math.max(1e-3, end - start))},0,1)`;
+ const keep = `(1-${fmt(k)}*${pulse.fade === "to" ? u : `(1-${u})`})`;
+ const mid = code(128, chroma.depth);
+ const toward = code(pulse.tone === "black" ? 16 : 235, chroma.depth);
+ return [
+ `[${inLabel}]geq=lum='${toward}+(lum(X,Y)-${toward})*${keep}':` +
+ `cb='${mid}+(cb(X,Y)-${mid})*${keep}':cr='${mid}+(cr(X,Y)-${mid})*${keep}':${en}[${outLabel}]`,
+ ];
+ }
const rate = flashRate(pulse);
const p = `((T-${fmt(start)})*${fmt(rate)}+${PULSE_NUDGE})`;
// A flicker deals each pulse its strength with the same sine hash as
@@ -1573,6 +1886,8 @@ export function effectFilterLines(
return burnFilterLines(inLabel, outLabel, k, start, end, chroma);
case "char":
return burnFilterLines(inLabel, outLabel, k, start, end, chroma, CHAR_PALETTE);
+ case "lightbars":
+ return lightbarsFilterLines(inLabel, outLabel, k, start, end, width, height, tag, chroma);
case "scorch":
return scorchFilterLines(inLabel, outLabel, k, start, end, tag, chroma);
case "film":
@@ -1612,6 +1927,91 @@ export function effectFilterLines(
}
}
+/**
+ * The light bars in ffmpeg. The bars run the frame's full height, so one geq
+ * draws them into a single row — every bar's profile at the frame's time,
+ * summed per channel in RGB the way the canvas adds them — and the row is
+ * stretched to the frame and added onto the picture by `blend`, on a branch
+ * laid back over the frame only inside the window.
+ */
+function lightbarsFilterLines(
+ inLabel: string,
+ outLabel: string,
+ k: number,
+ start: number,
+ end: number,
+ width: number,
+ height: number,
+ tag: string,
+ chroma: ChainChroma
+): string[] {
+ if (end <= start) {
+ return [`[${inLabel}]null[${outLabel}]`];
+ }
+ const dur = end - start;
+ const max = chroma.depth === 10 ? 1023 : 255;
+ const gain = 0.4 + 0.6 * k;
+ // Registers: 0 the progress u, 2 the ribbon's appearance, 4 the pixel's
+ // offset from the camera's axis as a frame fraction, 7 the channel's
+ // running sum.
+ const setup =
+ `st(0,clip((T-${fmt(start)})/${fmt(dur)},0,1));st(2,min(1,ld(0)/${LB_APPEAR}));` +
+ `st(4,(X+0.5)/W-${LB_AXIS});st(7,0)`;
+ // A bar's profile at its distance `d` in half-widths, the canvas
+ // gradient's ramp.
+ const profile = (d: string) =>
+ `(${fmt(1 - LB_HALO_SHARE)}*clip((${LB_EDGE}-${d})/${fmt(LB_EDGE - LB_CORE)},0,1)+` +
+ `${fmt(LB_HALO_SHARE)}*max(0,1-${d}/${LB_HALO}))`;
+ // One statement a bar: ffmpeg's expression parser runs out of room on a
+ // ribbon's worth of two-statement bars. A line's offset and half-width
+ // both grow as T / (T - u), so its distance in half-widths is the pixel's
+ // offset scaled back by (T - u) / T against the line's starting place.
+ // Lines are thousandths of the frame wide, so their numbers keep six
+ // significant figures.
+ const n = (v: number) => Number(v.toPrecision(6)).toString();
+ const plane = (lines: RibbonLine[], c: 0 | 1 | 2) => {
+ const terms = lines.filter((l) => l.rgb[c] > 0).map((l) => {
+ const near = l.T - 1 < LB_NEAR ? `*clip((${n(l.T)}-ld(0))/${LB_NEAR},0,1)` : "";
+ const on = l.on ? `*clip((ld(0)-${n(l.on)})/${LB_ON_SPAN},0,1)` : "";
+ const off = l.off ? `*clip((${n(l.off)}-ld(0))/${LB_OFF_SPAN},0,1)` : "";
+ const weight = `${n((l.rgb[c] / 255) * l.a * gain)}*ld(2)${near}${on}${off}`;
+ const d = `abs(ld(4)*(1-ld(0)/${n(l.T)})-${n(l.th)})/${n(l.w)}`;
+ return `st(7,ld(7)+${weight}*${profile(d)})`;
+ });
+ return `${setup};${terms.join(";")};${max}*min(1,ld(7))`;
+ };
+ const rgb = chroma.depth === 10 ? "gbrp10le" : "gbrp";
+ const win = gate(start, end);
+ // ffmpeg can't hold the whole ribbon in one expression, so each run of
+ // lines draws its own row and the rows are added up: the light is never
+ // negative, so clipping each sum at full and then the total is the
+ // canvas's one clip of the total.
+ const runs: RibbonLine[][] = [];
+ for (let i = 0; i < RIBBON.length; i += LB_FFMPEG_RUN) runs.push(RIBBON.slice(i, i + LB_FFMPEG_RUN));
+ const row = (i: number) => `lbr${i}${tag}`;
+ const rows = runs.map(
+ (lines, i) =>
+ `[lbs${i}${tag}]format=${rgb},geq=r='${plane(lines, 0)}':g='${plane(lines, 1)}':b='${plane(lines, 2)}'[${row(i)}]`
+ );
+ let sum = row(0);
+ const adds = runs.slice(1).map((_, j) => {
+ const next = `lbsum${j + 1}${tag}`;
+ const line = `[${sum}][${row(j + 1)}]blend=all_mode=addition[${next}]`;
+ sum = next;
+ return line;
+ });
+ return [
+ `[${inLabel}]split=3[lbo${tag}][lbg${tag}][lbs${tag}]`,
+ `[lbs${tag}]crop=iw:1:0:0,split=${runs.length}${runs.map((_, i) => `[lbs${i}${tag}]`).join("")}`,
+ ...rows,
+ ...adds,
+ `[${sum}]scale=${width}:${height}:flags=neighbor[lbl${tag}]`,
+ `[lbg${tag}]format=${rgb}[lbp${tag}]`,
+ `[lbp${tag}][lbl${tag}]blend=all_mode=addition:${win},format=${chroma.pixFmt}[lbc${tag}]`,
+ `[lbo${tag}][lbc${tag}]overlay=0:0:${win}:eof_action=pass${chroma.overlay}[${outLabel}]`,
+ ];
+}
+
/** Steps a second the export's burn is drawn at: one per frame at 60 fps. */
const BURN_RATE = 60;
diff --git a/site/packages/effects-kit/src/flashFade.test.ts b/site/packages/effects-kit/src/flashFade.test.ts
new file mode 100644
index 00000000..b7b7db3b
--- /dev/null
+++ b/site/packages/effects-kit/src/flashFade.test.ts
@@ -0,0 +1,74 @@
+import { spawnSync } from "node:child_process";
+import { describe, expect, test } from "bun:test";
+import { Canvas } from "skia-canvas";
+import { applyEffectToCanvas, effectFilterLines, effectPreviewState, type FlashPulse } from "./effects";
+import { TEST_FFMPEG } from "./testing/ffmpeg";
+
+type Surface = HTMLCanvasElement;
+const W = 64;
+const H = 16;
+const FPS = 30;
+const DUR = 1;
+const GREY = 120;
+const noGrain = () => null;
+
+function grey(): Surface {
+ const c = new Canvas(W, H) as unknown as Surface;
+ const ctx = c.getContext("2d")!;
+ ctx.fillStyle = `rgb(${GREY},${GREY},${GREY})`;
+ ctx.fillRect(0, 0, W, H);
+ return c;
+}
+
+/** The middle pixel of a grey frame after the canvas pass at `tLocal`. */
+function canvasAt(tLocal: number, pulse: FlashPulse): number[] {
+ const c = grey();
+ applyEffectToCanvas(c, grey(), "flash", 1, tLocal, noGrain, undefined, undefined, DUR, "opaque", pulse);
+ return Array.from(c.getContext("2d")!.getImageData(W / 2, H / 2, 1, 1).data.slice(0, 3));
+}
+
+describe("a flash that fades", () => {
+ test("fading to its tone ramps from clear to the full tone across the element", () => {
+ const at = (t: number) => effectPreviewState("flash", 1, t, undefined, undefined, DUR, { tone: "black", fade: "to" });
+ expect(at(0).flash ?? 0).toBeCloseTo(0, 5);
+ expect(at(0.5).flash).toBeCloseTo(0.5, 5);
+ expect(at(DUR).flash).toBeCloseTo(1, 5);
+ expect(at(0.5).flashTone).toBe("black");
+ });
+
+ test("fading from its tone starts full and clears by the element's end", () => {
+ const at = (t: number) => effectPreviewState("flash", 1, t, undefined, undefined, DUR, { tone: "black", fade: "from" });
+ expect(at(0).flash).toBeCloseTo(1, 5);
+ expect(at(0.25).flash).toBeCloseTo(0.75, 5);
+ expect(at(DUR).flash ?? 0).toBeCloseTo(0, 5);
+ });
+
+ test("the amount caps how far it fades", () => {
+ expect(effectPreviewState("flash", 0.5, DUR, undefined, undefined, DUR, { fade: "to" }).flash).toBeCloseTo(0.5, 5);
+ });
+
+ test("a full fade to black ends on black in the canvas pass", () => {
+ expect(Math.max(...canvasAt(DUR - 1e-6, { tone: "black", fade: "to" }))).toBeLessThan(2);
+ });
+
+ for (const tone of ["black", "white"] as const) {
+ test(`ffmpeg fades to and from ${tone} the way the canvas does`, () => {
+ for (const fade of ["to", "from"] as const) {
+ const pulse: FlashPulse = { tone: tone === "black" ? "black" : undefined, fade };
+ const chroma = { pixFmt: "yuv444p", overlay: ":format=yuv444" };
+ const lines = effectFilterLines("in", "out", "flash", 1, 0, DUR, W, H, "t", undefined, undefined, chroma, pulse)!;
+ const graph = `color=c=0x787878:s=${W}x${H}:r=${FPS}:d=${DUR},format=yuv444p[in];${lines.join(";")}`;
+ const run = spawnSync(TEST_FFMPEG, ["-v", "error", "-filter_complex", graph, "-map", "[out]", "-pix_fmt", "rgb24", "-f", "rawvideo", "-"], {
+ maxBuffer: 16 << 20,
+ });
+ expect(run.status).toBe(0);
+ const out = run.stdout as Buffer;
+ for (const f of [0, 8, 15, 22, 29]) {
+ const base = f * W * H * 3 + ((H / 2) * W + W / 2) * 3;
+ const ours = canvasAt(f / FPS, pulse);
+ for (let c = 0; c < 3; c++) expect(Math.abs(out[base + c] - ours[c])).toBeLessThan(6);
+ }
+ }
+ });
+ }
+});
diff --git a/site/packages/effects-kit/src/fontCycle.test.ts b/site/packages/effects-kit/src/fontCycle.test.ts
index 2a01cc43..c2565e73 100644
--- a/site/packages/effects-kit/src/fontCycle.test.ts
+++ b/site/packages/effects-kit/src/fontCycle.test.ts
@@ -1,5 +1,7 @@
import { describe, expect, test } from "bun:test";
+import { Canvas } from "skia-canvas";
import { cutAtFaces, cycleFaceAt, cycleFaceTag, fontCycleCuts, fontCycleVariants, withFontCycle } from "./fontCycle";
+import { planAnimatedLayers, renderOverlayFrames, type RenderEnv } from "./render";
import type { TextOverlay } from "./types";
const title = (fonts?: NonNullable<TextOverlay["anim"]>["fonts"]): TextOverlay => ({
@@ -67,4 +69,41 @@ describe("the font cycle", () => {
expect(cycleFaceTag(title(CYCLE), 0.1)).toBe("");
expect(fontCycleCuts(title(), 2)).toEqual([]);
});
+
+ test("a face's hold sets its own step, so the changes land on the beat", () => {
+ const held = {
+ faces: [{ font: "caveat", hold: 0.25 }, { font: "anton", italic: true }, { font: "bebas", hold: 0.05 }],
+ at: 0.5,
+ seconds: 1,
+ rate: 10,
+ };
+ expect(cycleFaceAt(held, 0.5)?.font).toBe("caveat");
+ expect(cycleFaceAt(held, 0.74)?.font).toBe("caveat");
+ expect(cycleFaceAt(held, 0.75)?.font).toBe("anton");
+ expect(cycleFaceAt(held, 0.85)?.font).toBe("bebas");
+ expect(cycleFaceAt(held, 0.9)?.font).toBe("caveat");
+ expect(withFontCycle(title(held), 0.8).italic).toBe(true);
+ expect(withFontCycle(title(held), 0.6).italic).toBeUndefined();
+ expect(fontCycleCuts(title(held), 2)).toEqual([0.5, 0.75, 0.85, 0.9, 1.15, 1.25, 1.3, 1.5]);
+ expect(fontCycleVariants(title(held)).map((v) => v.font)).toEqual(["caveat", "anton", "bebas"]);
+ });
+
+ test("the canvas and ffmpeg exports change face at the held steps", async () => {
+ const held = { faces: [{ font: "caveat", hold: 0.25 }, { font: "anton" }, { font: "bebas", hold: 0.05 }], at: 0.5, seconds: 1, rate: 10 };
+ const o = title(held);
+ const cuts = [0.5, 0.75, 0.85, 0.9, 1.15, 1.25, 1.3, 1.5].map((t) => +(o.start + t).toFixed(3));
+ const layers = planAnimatedLayers(o, 10);
+ const starts = layers.map((l) => +l.start.toFixed(3));
+ for (const c of cuts) expect(starts.includes(c)).toBe(true);
+ expect((layers.find((l) => Math.abs(l.start - 2.75) < 1e-6)?.overlay as TextOverlay | undefined)?.font).toBe("anton");
+ const env: RenderEnv = {
+ fontStack: () => "Arial",
+ createCanvas: (w, h) => new Canvas(w, h) as unknown as HTMLCanvasElement,
+ canvasToPngBlob: async (c) => new Blob([new Uint8Array(await (c as unknown as Canvas).toBuffer("png"))]),
+ };
+ const set = await renderOverlayFrames(o, 270, 480, 30, env);
+ let t = o.start;
+ const edges = set.entries.map((e) => +(t += e.duration).toFixed(3));
+ for (const c of cuts) expect(edges.includes(c)).toBe(true);
+ });
});
diff --git a/site/packages/effects-kit/src/fontCycle.ts b/site/packages/effects-kit/src/fontCycle.ts
index 7530be8d..82dc2cc4 100644
--- a/site/packages/effects-kit/src/fontCycle.ts
+++ b/site/packages/effects-kit/src/fontCycle.ts
@@ -19,6 +19,11 @@ export interface CycleFace {
scale?: number;
/** Letter spacing, em; absent = the title's own. */
tracking?: number;
+ /** Italic for this face; absent = the title's own. */
+ italic?: boolean;
+ /** Seconds this face shows before the next; absent = one step at the
+ * cycle's rate. Holds put each change on the music's beat. */
+ hold?: number;
}
/** The cycle: `faces` in order, `rate` changes a second, running from `at`
@@ -36,7 +41,10 @@ export const FONT_CYCLE_RATE = 15;
export const FONT_CYCLE_RATE_MIN = 2;
export const FONT_CYCLE_RATE_MAX = 30;
/** The most faces one cycle walks. */
-export const FONT_CYCLE_FACES_MAX = 12;
+export const FONT_CYCLE_FACES_MAX = 48;
+/** A face's hold bounds, seconds: a frame at 60 fps up to a long hold. */
+export const CYCLE_HOLD_MIN = 1 / 60;
+export const CYCLE_HOLD_MAX = 10;
/** Face scale bounds. */
export const CYCLE_SCALE_MIN = 0.5;
export const CYCLE_SCALE_MAX = 4;
@@ -48,6 +56,13 @@ const STEP_SLACK = 1e-4;
const rateOf = (c: OverlayFontCycle) =>
Math.max(FONT_CYCLE_RATE_MIN, Math.min(FONT_CYCLE_RATE_MAX, c.rate > 0 ? c.rate : FONT_CYCLE_RATE));
+/** How long a face shows: its own hold, or one step at the cycle's rate. */
+const stepOf = (c: OverlayFontCycle, f: CycleFace) =>
+ f.hold && f.hold > 0 ? Math.max(CYCLE_HOLD_MIN, Math.min(CYCLE_HOLD_MAX, f.hold)) : 1 / rateOf(c);
+
+/** Seconds one walk through every face takes. */
+const periodOf = (c: OverlayFontCycle) => c.faces.reduce((sum, f) => sum + stepOf(c, f), 0);
+
/** The cycle a text element carries, or nothing — other kinds have no face. */
export function overlayFontCycle(o: Overlay): OverlayFontCycle | undefined {
if ((o.kind ?? "text") !== "text") return undefined;
@@ -60,8 +75,16 @@ export function overlayFontCycle(o: Overlay): OverlayFontCycle | undefined {
export function cycleFaceAt(c: OverlayFontCycle, tLocal: number): CycleFace | null {
const u = tLocal - c.at;
if (u < -STEP_SLACK || u >= c.seconds - STEP_SLACK) return null;
- const step = Math.max(0, Math.floor((u + STEP_SLACK) * rateOf(c)));
- return c.faces[step % c.faces.length];
+
+ // Walk one period's steps to the face whose span holds this moment.
+ // Example: holds 0.25, 0.1, 0.05 put u = 0.3 in the second face.
+ const w = Math.max(0, u + STEP_SLACK) % periodOf(c);
+ let edge = 0;
+ for (const f of c.faces) {
+ edge += stepOf(c, f);
+ if (w < edge) return f;
+ }
+ return c.faces[c.faces.length - 1];
}
/** The element as it is set `tLocal` seconds in: the cycle's face while it
@@ -81,6 +104,7 @@ export function withFontCycle<T extends Overlay>(o: T, tLocal: number): T {
weight: face.weight ?? t.weight,
size: t.size * scale,
letterSpacing: face.tracking ?? t.letterSpacing,
+ italic: face.italic ?? t.italic,
anim: { ...o.anim, fonts: undefined },
} as T;
}
@@ -91,13 +115,12 @@ export function withFontCycle<T extends Overlay>(o: T, tLocal: number): T {
export function fontCycleCuts(o: Overlay, dur: number): number[] {
const c = overlayFontCycle(o);
if (!c) return [];
- const rate = rateOf(c);
const end = Math.min(dur, c.at + c.seconds);
const cuts: number[] = [];
- for (let i = 0; ; i++) {
- const t = c.at + i / rate;
- if (t >= end - 1e-3) break;
+ let t = c.at;
+ for (let i = 0; t < end - 1e-3; i++) {
if (t > 1e-3) cuts.push(Math.round(t * 1e4) / 1e4);
+ t += stepOf(c, c.faces[i % c.faces.length]);
}
if (end > 1e-3 && end < dur - 1e-3) cuts.push(Math.round(end * 1e4) / 1e4);
return cuts;
@@ -125,7 +148,12 @@ export function cutAtFaces<S extends { start: number; end: number }>(spans: S[],
export function fontCycleVariants<T extends Overlay>(o: T): T[] {
const c = overlayFontCycle(o);
if (!c) return [];
- return c.faces.map((_, i) => withFontCycle(o, c.at + (i + 0.5) / rateOf(c)));
+ let edge = c.at;
+ return c.faces.map((f) => {
+ const mid = edge + stepOf(c, f) / 2;
+ edge += stepOf(c, f);
+ return withFontCycle(o, mid);
+ });
}
/** A tag naming the face showing at `tLocal`, for a sampler that caches
diff --git a/site/packages/effects-kit/src/glitchRgb.test.ts b/site/packages/effects-kit/src/glitchRgb.test.ts
index 1fc982a1..e10ed781 100644
--- a/site/packages/effects-kit/src/glitchRgb.test.ts
+++ b/site/packages/effects-kit/src/glitchRgb.test.ts
@@ -124,4 +124,13 @@ describe("a pinned glitch", () => {
expect(under[down]).toBeGreaterThan(200);
expect(under[up]).toBeLessThan(40);
});
+
+ test("its ffmpeg shift stays inside rgbashift's ±255 px on an 8K export at full amount", () => {
+ // At amount 1 the pull is twice the default's, and on an 8K frame that
+ // ran to 335 px: ffmpeg refuses the value and the whole export fails.
+ const lines = effectFilterLines("in", "out", "glitch:rgb", 1, 0, 1, 7680, 4320, "t")!.join(";");
+ const values = [...lines.matchAll(/r[hv]=(-?\d+)/g)].map((m) => Math.abs(Number(m[1])));
+ expect(values.length).toBeGreaterThan(0);
+ expect(Math.max(...values)).toBeLessThanOrEqual(255);
+ });
});
diff --git a/site/packages/effects-kit/src/keys.test.ts b/site/packages/effects-kit/src/keys.test.ts
index 89462f60..15ba8d0c 100644
--- a/site/packages/effects-kit/src/keys.test.ts
+++ b/site/packages/effects-kit/src/keys.test.ts
@@ -72,6 +72,14 @@ describe("keyframe poses", () => {
expect(keyIndexAt(kf, 1)).toBe(0);
expect(removeKeyAt(kf, 1).length).toBe(0);
});
+
+ test("keys one 60fps frame apart stay two keys", () => {
+ // A squash that snaps in on the next frame: 10.883 then 10.9 on a 60fps cut.
+ const a = 5.816667;
+ const kf = upsertKey([key(a, { x: 0.2 })], key(a + 1 / 60, { x: 0.9 }));
+ expect(kf.map((k) => k.x)).toEqual([0.2, 0.9]);
+ expect(keyIndexAt(kf, a + 1 / 60)).toBe(1);
+ });
});
describe("presets composing over a pose", () => {
diff --git a/site/packages/effects-kit/src/keys.ts b/site/packages/effects-kit/src/keys.ts
index cf1b1d51..19d3d61a 100644
--- a/site/packages/effects-kit/src/keys.ts
+++ b/site/packages/effects-kit/src/keys.ts
@@ -115,9 +115,10 @@ interface Posable {
camera?: GroupCamera;
}
-/** Two keys closer than this are the same key. Half a frame at 30fps, so a
- * key can be dropped on any frame and still replace the one already there. */
-export const KEY_EPSILON = 1 / 60;
+/** Two keys closer than this are the same key. Half a frame at 60fps, so a
+ * key can be dropped on any frame and still replace the one already there,
+ * while keys on neighbouring 60fps frames stay apart. */
+export const KEY_EPSILON = 1 / 120;
/** The element's pose with no keys in play. */
export function restingPose(o: Posable): OverlayPose {
diff --git a/site/packages/effects-kit/src/lightbars.test.ts b/site/packages/effects-kit/src/lightbars.test.ts
new file mode 100644
index 00000000..c03048ca
--- /dev/null
+++ b/site/packages/effects-kit/src/lightbars.test.ts
@@ -0,0 +1,140 @@
+import { spawnSync } from "node:child_process";
+import { describe, expect, test } from "bun:test";
+import { Canvas } from "skia-canvas";
+import { applyEffectToCanvas, EFFECT_IDS, effectFilterLines, effectPreviewState, lightbarBox, lightbarsAt } from "./effects";
+import { TEST_FFMPEG } from "./testing/ffmpeg";
+
+type Surface = HTMLCanvasElement;
+const W = 192;
+const H = 32;
+const FPS = 30;
+const DUR = 1;
+const noGrain = () => null;
+
+function black(): Surface {
+ const c = new Canvas(W, H) as unknown as Surface;
+ const ctx = c.getContext("2d")!;
+ ctx.fillStyle = "#000000";
+ ctx.fillRect(0, 0, W, H);
+ return c;
+}
+
+/** The bars drawn by the canvas pass over black, as one row of RGB. */
+function canvasRow(tLocal: number): number[][] {
+ const c = black();
+ applyEffectToCanvas(c, black(), "lightbars", 1, tLocal, noGrain, undefined, undefined, DUR);
+ const d = c.getContext("2d")!.getImageData(0, H / 2, W, 1).data;
+ return Array.from({ length: W }, (_, x) => [d[x * 4], d[x * 4 + 1], d[x * 4 + 2]]);
+}
+
+const mean = (row: number[][], from: number, to: number, c: number) =>
+ row.slice(from, to).reduce((s, p) => s + p[c], 0) / (to - from);
+
+describe("the light bars' course", () => {
+ test("they are a picture effect of their own", () => {
+ expect(EFFECT_IDS as string[]).toContain("lightbars");
+ expect(effectPreviewState("lightbars", 1, 0.9, undefined, undefined, 2).bars).toEqual(lightbarsAt(0.9, 2, 1));
+ });
+
+ test("they open as one narrow warm column just left of the middle", () => {
+ const bars = lightbarsAt(0.02, DUR, 1);
+ expect(bars.length).toBeGreaterThan(20);
+ for (const b of bars) expect(Math.abs(b.x - 0.46)).toBeLessThan(0.05);
+ const light = (c: number) => bars.reduce((s, b) => s + b.rgb[c] * b.alpha * b.w, 0);
+ expect(light(0)).toBeGreaterThan(3 * light(2));
+ });
+
+ test("they burst out to fill the frame, warm on the left and cool on the right", () => {
+ const bars = lightbarsAt(0.3, DUR, 1);
+ expect(Math.min(...bars.map((b) => b.x))).toBeLessThan(0.1);
+ expect(Math.max(...bars.map((b) => b.x))).toBeGreaterThan(0.9);
+ const row = canvasRow(0.45);
+ expect(mean(row, 0, W / 4, 0)).toBeGreaterThan(mean(row, 0, W / 4, 2));
+ expect(mean(row, (3 * W) / 4, W, 2)).toBeGreaterThan(mean(row, (3 * W) / 4, W, 0));
+ });
+
+ test("deeper lines keep flowing out after the burst, the outer ones leaving first", () => {
+ const xs = (u: number) => lightbarsAt(u, DUR, 1).map((b) => b.x);
+ expect(Math.min(...xs(0.45))).toBeLessThan(0.15);
+ expect(Math.max(...xs(0.45))).toBeGreaterThan(0.85);
+ expect(lightbarsAt(0.45, DUR, 1).length).toBeGreaterThan(lightbarsAt(0.7, DUR, 1).length);
+ });
+
+ test("they close on the one red line, widening as it sweeps off the right edge", () => {
+ const at = (u: number) => lightbarsAt(u, DUR, 1);
+ expect(at(0.88).length).toBe(1);
+ const [mid, late] = [at(0.88)[0], at(0.97)[0]];
+ expect(mid.x).toBeGreaterThan(0.5);
+ expect(mid.x).toBeLessThan(0.56);
+ expect(late.x).toBeGreaterThan(mid.x + 0.1);
+ expect(late.w).toBeGreaterThan(mid.w * 3);
+ const row = canvasRow(0.88);
+ const peak = row.reduce((best, p) => (p[0] > best[0] ? p : best));
+ expect(peak[0]).toBeGreaterThan(200);
+ expect(peak[1]).toBeLessThan(80);
+ expect(peak[2]).toBeLessThan(80);
+ expect(at(DUR)).toEqual([]);
+ });
+
+ test("the CSS twin places every bar where the canvas draws it, in a box of its own width", () => {
+ for (const b of lightbarsAt(0.5, DUR, 1)) {
+ const box = lightbarBox(b);
+ const left = parseFloat(box.left) / 100;
+ const width = parseFloat(box.width) / 100;
+ expect(left).toBeGreaterThanOrEqual(0);
+ expect(left + width).toBeLessThanOrEqual(1 + 1e-9);
+ expect(width).toBeLessThan(0.5);
+ // The profile's peak stop lands on the bar's center.
+ const stops = [...box.background.matchAll(/ (-?[\d.]+)%/g)].map((m) => Number(m[1]) / 100);
+ expect(Math.abs(left + stops[3] * width - b.x)).toBeLessThan(1e-4);
+ }
+ });
+
+ test("the canvas pass adds every bar in one composite, however many there are", () => {
+ // Over a clear-edged layer each pass is a full-frame mask and draw; one
+ // per bar was well over a hundred a frame at the burst.
+ const c = black();
+ const bars = lightbarsAt(0.3, DUR, 1).length;
+ expect(bars).toBeGreaterThan(20);
+ const ctx = c.getContext("2d")!;
+ let draws = 0;
+ const draw = ctx.drawImage.bind(ctx);
+ ctx.drawImage = ((...args: Parameters<typeof draw>) => {
+ draws++;
+ return draw(...args);
+ }) as typeof ctx.drawImage;
+ applyEffectToCanvas(c, black(), "lightbars", 1, 0.3, noGrain, undefined, undefined, DUR, "keep");
+ expect(draws).toBe(1);
+ });
+});
+
+describe("the light bars in ffmpeg", () => {
+ test("a few geqs drawing a single row between them, gated to the element", () => {
+ const graph = effectFilterLines("in", "out", "lightbars", 1, 2, 3.6, 1920, 1080, "t")!.join(";");
+ expect(graph.match(/geq=/g)!.length).toBeGreaterThan(1);
+ expect(graph.match(/geq=/g)!.length).toBeLessThan(6);
+ expect(graph.match(/crop=iw:1:0:0/g)!.length).toBe(1);
+ expect(graph).toContain("enable='gte(t,2.000000)*lt(t,3.600000)'");
+ expect(graph.startsWith("[in]")).toBe(true);
+ expect(graph.endsWith("[out]")).toBe(true);
+ });
+
+ test("ffmpeg draws the bars the canvas draws", () => {
+ const frames = [3, 9, 15, 22, 28];
+ const chroma = { pixFmt: "yuv444p", overlay: ":format=yuv444" };
+ const lines = effectFilterLines("in", "out", "lightbars", 1, 0, DUR, W, H, "t", undefined, undefined, chroma)!;
+ const graph = `color=c=black:s=${W}x${H}:r=${FPS}:d=${DUR},format=yuv444p[in];${lines.join(";")}`;
+ const run = spawnSync(TEST_FFMPEG, ["-v", "error", "-filter_complex", graph, "-map", "[out]", "-pix_fmt", "rgb24", "-f", "rawvideo", "-"], {
+ maxBuffer: 64 << 20,
+ });
+ expect(run.status).toBe(0);
+ const out = run.stdout as Buffer;
+ for (const f of frames) {
+ const base = f * W * H * 3 + (H / 2) * W * 3;
+ const ours = canvasRow(f / FPS);
+ let diff = 0;
+ for (let x = 0; x < W; x++) for (let c = 0; c < 3; c++) diff += Math.abs(out[base + x * 3 + c] - ours[x][c]);
+ expect(diff / (W * 3)).toBeLessThan(6);
+ }
+ });
+});
diff --git a/site/packages/effects-kit/src/mask.ts b/site/packages/effects-kit/src/mask.ts
index 3f45e11f..18d09a53 100644
--- a/site/packages/effects-kit/src/mask.ts
+++ b/site/packages/effects-kit/src/mask.ts
@@ -494,6 +494,12 @@ export function maskComposite(
target.save();
target.setTransform(1, 0, 0, 1, 0, 0);
target.globalAlpha = 1;
+ // A shadowed element leaves its shadow set, and browsers shadow this draw
+ // too: the cut would keep the layer at the shadow's opacity.
+ target.shadowColor = "transparent";
+ target.shadowBlur = 0;
+ target.shadowOffsetX = 0;
+ target.shadowOffsetY = 0;
target.globalCompositeOperation = invert ? "destination-out" : "destination-in";
target.drawImage(coverage, 0, 0);
target.restore();
diff --git a/site/packages/effects-kit/src/maskShadow.test.ts b/site/packages/effects-kit/src/maskShadow.test.ts
new file mode 100644
index 00000000..3eafb69e
--- /dev/null
+++ b/site/packages/effects-kit/src/maskShadow.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, test } from "bun:test";
+import { maskComposite } from "./mask";
+
+describe("a mask over a shadowed element", () => {
+ test("the cut is drawn with no shadow, whatever the canvas was left carrying", () => {
+ // A text element with a drop shadow leaves the shadow set on the canvas.
+ // Browsers shadow a destination-in draw too, so a cut that inherits it
+ // fades the letters to the shadow's opacity wherever the mask keeps them
+ // (skia-canvas doesn't, so the state at the draw is what's checked).
+ const state = { shadowColor: "rgba(0,0,0,0.55)", shadowBlur: 30, shadowOffsetX: 0, shadowOffsetY: 8 };
+ const stack: (typeof state)[] = [];
+ let atDraw: typeof state | null = null;
+ const ctx = {
+ ...state,
+ globalAlpha: 1,
+ globalCompositeOperation: "source-over",
+ save() {
+ stack.push({ shadowColor: this.shadowColor, shadowBlur: this.shadowBlur, shadowOffsetX: this.shadowOffsetX, shadowOffsetY: this.shadowOffsetY });
+ },
+ restore() {
+ Object.assign(this, stack.pop());
+ },
+ setTransform() {},
+ drawImage() {
+ atDraw = { shadowColor: this.shadowColor, shadowBlur: this.shadowBlur, shadowOffsetX: this.shadowOffsetX, shadowOffsetY: this.shadowOffsetY };
+ },
+ };
+ maskComposite(ctx as unknown as CanvasRenderingContext2D, {} as CanvasImageSource);
+ expect(atDraw).not.toBeNull();
+ const s = atDraw!;
+ expect(s.shadowColor === "transparent" || (s.shadowBlur === 0 && s.shadowOffsetX === 0 && s.shadowOffsetY === 0)).toBe(true);
+ // The element's own shadow comes back for whatever paints next.
+ expect(ctx.shadowColor).toBe("rgba(0,0,0,0.55)");
+ });
+});
diff --git a/site/src/clients/chatgpt/server/guidance.ts b/site/src/clients/chatgpt/server/guidance.ts
index 30a3f985..bdc96d01 100644
--- a/site/src/clients/chatgpt/server/guidance.ts
+++ b/site/src/clients/chatgpt/server/guidance.ts
@@ -61,7 +61,7 @@ Build composite effects as layers: add_overlay_video for copies of footage, mask
Listen to the relevant source with listen_audio. Use detect_silence for pauses, detect_beats for music timing, and measure_level for level matching. Its volumeToMatch result can drive set_clip_volume or update_audio; use a fraction for a music bed beneath speech. Read watching-and-cutting for coverage and source-time rules.
update_audio edits soundtrack timing, source trim, volume, fades and ducking. A clip's duck lowers other audio while it plays. set_clip_sound applies EQ, compression and limiting to one clip; add_effect treats a time range of the mix. sync_audio lines a separately recorded audio file up with a video's own sound and binds it, so every clip of the video plays the recording; it refuses when no alignment is clear. set_split_edit starts a clip's sound before its picture or carries it past the cut, for J- and L-cuts. describe_commands supplies the supported presets and settings.
When captions are requested, subtitles_generate transcribes the cut; sync_lyrics aligns supplied words with the audio. subtitles_from_visuals writes descriptions of silent footage when the user wants them. captions_generate rewrites existing captions. These model-backed operations use the account's applicable allowance or credits.
-Use update_cue, delete_cue and merge_cue for corrections. subtitles_add_track, subtitles_remove_track and subtitles_translate_track manage languages. set_caption_look controls appearance and words per cue; subtitles_set_view controls visibility. set_caption_emphasis sets one or two key words apart in a caption every few lines, and update_cue x/y gives one caption its own spot. Current choices come from describe_commands, and text-videos covers timed text layouts. align_to_audio measures timing against the mix.
+Use update_cue, delete_cue and merge_cue for corrections. subtitles_add_track, subtitles_remove_track and subtitles_translate_track manage languages. set_caption_look controls appearance and words per cue; subtitles_set_view controls visibility. set_caption_emphasis sets one or two key words apart in a caption every few lines when the user asks for emphasis, and update_cue x/y gives one caption its own spot. Current choices come from describe_commands, and text-videos covers timed text layouts. align_to_audio measures timing against the mix.
For requested audio generation, list_voices supplies voice ids, voiceover_generate speaks a script, read_subtitles_aloud voices timed cues, and generate_music makes music. Generation spends credits. Read the result for asset ids and placement, then inspect and listen to verify it. These commands are available through edit_project while the editor card is open.`,
"ai-generation": `# Finding and creating media
diff --git a/site/src/cut/components/AnimationTiles.tools.ts b/site/src/cut/components/AnimationTiles.tools.ts
index b51e269e..7ccca62e 100644
--- a/site/src/cut/components/AnimationTiles.tools.ts
+++ b/site/src/cut/components/AnimationTiles.tools.ts
@@ -10,6 +10,7 @@
import { CAMERA_WORLD_MAX, CAMERA_WORLD_MIN, EASE_IDS, EDGE_STAGGER_MAX, ELEMENT_BLUR_MAX, TILT_MAX } from "@donkeycut/effects-kit";
import {
+ CYCLE_HOLD_MAX,
CYCLE_SCALE_MAX,
CYCLE_SCALE_MIN,
FONT_CYCLE_FACES_MAX,
@@ -30,6 +31,7 @@ import {
OVERLAY_ANIM_MIN_SECONDS,
GLYPH_ANIM_STYLE_IDS,
GLYPH_LOOP_STYLE_IDS,
+ LOOP_PERIODS,
DIVE_ANIM_STYLE_IDS,
edgeNotes,
OVERLAY_ANIM_STYLE_IDS,
@@ -55,11 +57,24 @@ const LONG_RAMPS = OVERLAY_ANIM_STYLE_IDS.filter((id) => edgeMaxSeconds(id) !==
.join("");
const RAMP_SECONDS = `${OVERLAY_ANIM_MIN_SECONDS}..${OVERLAY_ANIM_MAX_SECONDS} (default ${OVERLAY_ANIM_DEFAULT_SECONDS}${LONG_RAMPS})`;
+/** The loop rate multiplier's range: at the top a spin turns twice a second,
+ * fast enough for a loading spinner. */
+export const LOOP_SPEED_MIN = 0.25;
+export const LOOP_SPEED_MAX = 8;
+
+/** How far beyond the frame a keyed position may sit, so an element can enter
+ * or leave across an edge; its resting position stays on the frame. */
+export const OVERLAY_KEY_POS_MIN = -0.5;
+export const OVERLAY_KEY_POS_MAX = 1.5;
+
+// Each loop's cycle at speed 1, e.g. "spin 4s", so a rate can be set from a measured one.
+const LOOP_CYCLES = OVERLAY_LOOP_STYLE_IDS.map((id) => `${id} ${LOOP_PERIODS[id]}s`).join(", ");
+
export const OVERLAY_ANIMATION_TOOLS = [
{
name: "set_overlay_animation",
description:
- `Animate an overlay element (title, shape, or sticker): preset In/Out ramps, a Loop that runs its whole duration, and a Move that says what the element does WHILE it holds. Omitted slots keep their setting; pass "none" to clear one. In/Out styles: ${OVERLAY_ANIM_STYLE_IDS.join(", ")} — slide names are the motion direction; ${TEXT_ONLY_ANIM_STYLE_IDS.join(", ")} animate titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece; in_stagger/out_stagger set how much of their ramp the hand-off from the first letter to the last takes, so a 1.6s drop at stagger 0.8 lands a letter every ~0.27s, each moving for ~0.3s. ${edgeNotes()} ${DIVE_ANIM_STYLE_IDS.join(", ")} as the exit is the zoom-through-a-letter transition: the shot after the element shows once the ink has filled the frame, so it needs no freeze frames, image stills or per-letter keyframes. Loop styles: ${OVERLAY_LOOP_STYLE_IDS.join(", ")} — ${GLYPH_LOOP_STYLE_IDS.join(", ")} carry a title's letters on their own delays, and carry any other kind as one piece. A move is a slot like the others and never touches the element's keyframe track; set_overlay_keyframes is the precise way to move an element and the default reach, so name a move when it is exactly what you mean — the two compose together. Word effects — words_style, titles only — play the line word by word, timed against the cut's transcript when there is one and spread across the element's own span when there is not: an emphasis travels along a line that is fully up, and a build assembles the line as it is spoken. It is the slot for "make each word pop as I say it" and for "have the words appear one by one". A typewriter entrance on a title can carry a caret: a thin bar at the end of the typed text, solid while it types, then blinking every ${CARET_BLINK_SECONDS}s — the typed comment or search box of a call-to-action card. A hit plays one motion once at a moment inside the element (hit_at seconds from its start), between its entrance and exit: ${hitNotes()}. Use press for a button being pressed, a tap on a UI element, a like or post button; pair it with a click from stock_search kind "sound" placed at the same moment when the tap should be heard. A font cycle flickers a title through typefaces — a new face font_cycle_rate times a second, from font_cycle_at for font_cycle_seconds — and then the title settles back into its own face: the typeface-shuffle beat of a teaser title. Give each face a scale (and tracking) so it fills about the room the title's own face does; a wide tracked title cycling through condensed or hand-drawn faces wants tracking 0 and a scale above 1 on them.`,
+ `Animate an overlay element (title, shape, or sticker): preset In/Out ramps, a Loop that runs its whole duration, and a Move that says what the element does WHILE it holds. Omitted slots keep their setting; pass "none" to clear one. In/Out styles: ${OVERLAY_ANIM_STYLE_IDS.join(", ")} — slide names are the motion direction; ${TEXT_ONLY_ANIM_STYLE_IDS.join(", ")} animate titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece; in_stagger/out_stagger set how much of their ramp the hand-off from the first letter to the last takes, so a 1.6s drop at stagger 0.8 lands a letter every ~0.27s, each moving for ~0.3s. ${edgeNotes()} ${DIVE_ANIM_STYLE_IDS.join(", ")} as the exit is the zoom-through-a-letter transition: the shot after the element shows once the ink has filled the frame, so it needs no freeze frames, image stills or per-letter keyframes. Loop styles: ${OVERLAY_LOOP_STYLE_IDS.join(", ")} — ${GLYPH_LOOP_STYLE_IDS.join(", ")} carry a title's letters on their own delays, and carry any other kind as one piece. A move is a slot like the others and never touches the element's keyframe track; set_overlay_keyframes is the precise way to move an element and the default reach, so name a move when it is exactly what you mean — the two compose together. Word effects — words_style, titles only — play the line word by word, timed against the cut's transcript when there is one and spread across the element's own span when there is not: an emphasis travels along a line that is fully up, and a build assembles the line as it is spoken. It is the slot for "make each word pop as I say it" and for "have the words appear one by one". A typewriter entrance on a title can carry a caret: a thin bar at the end of the typed text, solid while it types, then blinking every ${CARET_BLINK_SECONDS}s — the typed comment or search box of a call-to-action card. A hit plays one motion once at a moment inside the element (hit_at seconds from its start), between its entrance and exit: ${hitNotes()}. Use press for a button being pressed, a tap on a UI element, a like or post button; pair it with a click from stock_search kind "sound" placed at the same moment when the tap should be heard. A font cycle flickers a title through typefaces — a new face font_cycle_rate times a second, from font_cycle_at for font_cycle_seconds — and then the title settles back into its own face: the typeface-shuffle beat of a teaser title. Give each face a scale (and tracking) so it fills about the room the title's own face does; a wide tracked title cycling through condensed or hand-drawn faces wants tracking 0 and a scale above 1 on them. A face's hold sets how long it shows, so changes that land on the music's beats are one face per beat with its measured hold; faces repeat in the list to revisit a typeface.`,
inputSchema: obj({
id: str("Overlay element id"),
move: {
@@ -89,7 +104,7 @@ export const OVERLAY_ANIMATION_TOOLS = [
enum: [...OVERLAY_LOOP_STYLE_IDS, "none"],
description: 'Loop style, or "none" to clear',
},
- loop_speed: num("Loop rate multiplier 0.25..4 (default 1)"),
+ loop_speed: num(`Loop rate multiplier ${LOOP_SPEED_MIN}..${LOOP_SPEED_MAX} (default 1); one cycle takes its base time over the speed — ${LOOP_CYCLES} — so a loading spinner that turns once every 0.8s is spin at speed 5`),
words_style: {
type: "string",
enum: [...WORD_EFFECT_IDS, "none"],
@@ -128,6 +143,8 @@ export const OVERLAY_ANIMATION_TOOLS = [
weight: { type: "number", enum: [...TEXT_WEIGHTS], description: "Weight of this face; default the title's own" },
scale: num(`Size multiplier on the title's own size, ${CYCLE_SCALE_MIN}..${CYCLE_SCALE_MAX} (default 1)`),
tracking: num("Letter spacing in em for this face; default the title's own"),
+ italic: bool("Italic for this face; default the title's own"),
+ hold: num(`Seconds this face shows, up to ${CYCLE_HOLD_MAX}; default one step at font_cycle_rate`),
},
["font"]
),
@@ -142,18 +159,19 @@ export const OVERLAY_ANIMATION_TOOLS = [
{
name: "set_overlay_keyframes",
description:
- `Give an overlay element a keyframed pose track — the default way to animate one, because a key names the exact pose at the exact second where a preset ramp approximates it. Each key is a whole pose at a time measured in seconds from the element's own start; the pose moves between keys along the key's ease (${EASE_IDS.join(", ")}; default linear) and holds outside them. Omitted fields on a key take the element's current value. scale_x/scale_y stretch one side over scale (a screen switching off: scale_y to 0.02, then scale_x to 0.02); tilt_x/tilt_y turn the element in 3D perspective about its horizontal/vertical axis (tilt_x positive tips the top edge away, tilt_y the right edge; ±${TILT_MAX}°): a bar falling back, a card swinging open. blur softens the element (px at the 1080 short side, 0..${ELEMENT_BLUR_MAX}): keyed with opacity it is depth of field — the card being read sharp, its neighbours blurred and dimmed while a group camera (set_group_camera) pushes in. Pass an empty list to clear the track and return the element to its resting pose. Preset In/Out/Loop animation still composes on top, so a keyframed title can also fade in.`,
+ `Give an overlay element a keyframed pose track — the default way to animate one, because a key names the exact pose at the exact second where a preset ramp approximates it. Each key is a whole pose at a time measured in seconds from the element's own start; the pose moves between keys along the key's ease (${EASE_IDS.join(", ")}; default linear) and holds outside them. Omitted fields on a key take the element's current value. scale_x/scale_y stretch one side over scale (a screen switching off: scale_y to 0.02, then scale_x to 0.02); tilt_x/tilt_y turn the element in 3D perspective about its horizontal/vertical axis (tilt_x positive tips the top edge away, tilt_y the right edge; ±${TILT_MAX}°): a bar falling back, a card swinging open. blur softens the element (px at the 1080 short side, 0..${ELEMENT_BLUR_MAX}): keyed with opacity it is depth of field — the card being read sharp, its neighbours blurred and dimmed while a group camera (set_group_camera) pushes in. Keys merge into the track the element already has — one at an existing time replaces that key, the rest stay — so pass replace true to lay a new track over an old one in one call. Pass an empty list to clear the track and return the element to its resting pose. Preset In/Out/Loop animation still composes on top, so a keyframed title can also fade in.`,
inputSchema: obj(
{
id: str("Overlay element id"),
+ replace: bool("true drops the element's existing keys first; default false merges these into them"),
keys: {
type: "array",
description: "Keys in any order; two at the same time collapse to one",
items: obj(
{
t: num("Seconds from the element's start"),
- x: num(`Center x, fraction of frame width 0..1 (${CAMERA_WORLD_MIN}..${CAMERA_WORLD_MAX} for a grouped element)`),
- y: num(`Center y, fraction of frame height 0..1 (${CAMERA_WORLD_MIN}..${CAMERA_WORLD_MAX} for a grouped element)`),
+ x: num(`Center x, fraction of frame width, ${OVERLAY_KEY_POS_MIN}..${OVERLAY_KEY_POS_MAX}: past 0..1 the element sits beyond the edge, for one that enters or leaves across it, like a pointer sliding in from below (${CAMERA_WORLD_MIN}..${CAMERA_WORLD_MAX} for a grouped element)`),
+ y: num(`Center y, fraction of frame height, ${OVERLAY_KEY_POS_MIN}..${OVERLAY_KEY_POS_MAX} (${CAMERA_WORLD_MIN}..${CAMERA_WORLD_MAX} for a grouped element)`),
scale: num("Size multiplier, 1 = the element's own size (0.1..4)"),
scale_x: num("Width over scale, 0..4 (default 1)"),
scale_y: num("Height over scale, 0..4 (default 1)"),
diff --git a/site/src/cut/components/EffectsPanel.tools.ts b/site/src/cut/components/EffectsPanel.tools.ts
index ae6d0318..4f520e7b 100644
--- a/site/src/cut/components/EffectsPanel.tools.ts
+++ b/site/src/cut/components/EffectsPanel.tools.ts
@@ -6,7 +6,7 @@
* removed or renamed tool breaks the build until every side catches up.
*/
-import { ALL_EFFECT_IDS, AUDIO_EFFECT_IDS, EFFECT_IDS, FLASH_RHYTHMS, FLASH_RATE_MAX, FLASH_RATE_MIN, FLASH_TONES, GLITCH_KINDS, LEAK_COURSES, LOOK_EFFECTS } from "@donkeycut/effects-kit";
+import { ALL_EFFECT_IDS, AUDIO_EFFECT_IDS, EFFECT_IDS, FLASH_FADE_CHOICES, FLASH_FADE_NONE, FLASH_RHYTHMS, FLASH_RATE_MAX, FLASH_RATE_MIN, FLASH_TONES, GLITCH_KINDS, LEAK_COURSES, LOOK_EFFECTS } from "@donkeycut/effects-kit";
import { num, obj, type AiToolDef } from "@/cut/lib/aiToolDef";
/** The effects with a treatment recipe of their own; the rest of the list is
@@ -16,7 +16,7 @@ export const EFFECT_TREATMENTS = EFFECT_IDS.filter(
);
/** An effect's own settings, each for one kind of effect: a light leak's
- * course, a glitch's pinned kind, a flash's tone and strobe. add_effect
+ * course, a glitch's pinned kind, a flash's tone, strobe and fade. add_effect
* places an effect with them and update_overlay changes them in place. */
export const EFFECT_SETTING_ARGS = {
leak: {
@@ -40,13 +40,18 @@ export const EFFECT_SETTING_ARGS = {
enum: [...FLASH_RHYTHMS],
description: 'flash with a rate only: "strobe" fires every pulse at full strength (default), "flicker" deals each pulse its own strength and skips some',
},
+ fade: {
+ type: "string",
+ enum: [...FLASH_FADE_CHOICES],
+ description: `flash only: ramp evenly across the whole element instead of popping, to the full tone at amount 1 — "to" fades the picture into the tone, "from" starts on it and clears, "${FLASH_FADE_NONE}" takes the fade off again. On the front row (lane 0, rows moved down with move_row if it is taken) it fades everything behind it as one, so a fade to black over the end of a stacked page (video, scrims, text, buttons, a pointer) goes black together instead of each layer fading on its own and showing the layers through each other`,
+ },
};
export const EFFECTS_TOOLS = [
{
name: "add_effect",
description:
- `Add a time-ranged effect element over the cut: a zoom into part of the frame, a picture treatment (${EFFECT_TREATMENTS.join(", ")}), a graded look (${LOOK_EFFECTS.join(", ")}), or an audio treatment (${AUDIO_EFFECT_IDS.join(", ")}) over the sound. A picture effect filters everything visible under its window (start..end); an audio effect treats everything audible under it — clip sound, upper tracks and soundtrack together. They stack. glitch is clean footage broken by runs of corrupted frames — dark pixel-stretch smears, the picture doubled sideways over an orange burn, teal close-ups, blown-out flashes — the glitch ending of a teaser, where amount is how often it hits. A glitch pinned to one kind (glitch "smear", "split", "tint", "blowout" or "rgb") hits with it on every frame; "rgb" pulls the color channels apart, red down and blue up — a 2–3 frame rgb glitch is the RGB-split hit of a collapsing title or HUD. lightleak drifts a warm bloom and light streaks over the picture for as long as it is up; with leak "burn" it is a film burn played once across the element's own length: it climbs from the bottom edge behind a hot orange front, flares near white, settles orange and hands the picture back in its last tenth — the burn-out of a teaser, a 0.4–0.6s element over the end of the last shot, amount 1 for a fully opaque burn. With leak "scorch" it flashes film burn through the picture: every frame maps the picture onto a saturated hot tone by brightness — yellow, orange, or red over pink — across the whole frame or a soft-edged patch of it, a new tone and patch each frame; short 2–12 frame scorches over the last shots, amount 1, are the burn-through flicker of a teaser's ending. With leak "film" it is the film-strip flash over a cut, played once across the element: the picture washes warm orange, a brighter band glows across the lower middle and the strip's sprocket holes blaze cream along the top edge, full through the middle of the element and gone by its ends — a 3–5 frame element centered on a cut, amount 1, is the film-strip light-leak transition of a recap montage (one per section change). With leak "char" it is the burn's climb in dark stock: a hot orange front rises from the bottom edge, the frame cools through ember to black behind it, a thin bright light line crosses, and the picture comes back in the last tenth — never a pale flare; an 8–10 frame element, amount 1, over a black card's end and the next shot's first frames is the dark film-burn handover of a recap opener. flash pops the picture white at the element's start and decays in about 0.4s; tone "black" dips it dark instead, and a strobe rate holds the tone on and off that many times a second for the whole element — a black strobe at 5–6 with amount 0.9–1 is the dark beat-flicker over a teaser's last shot. rhythm "flicker" deals each pulse its own strength and leaves some dark: an uneven exposure flicker, a white flicker at rate 12–15 and amount 0.15–0.25. To flicker one shot inside its mask, give the clip the flash through set_clip_effects. Tasteful default: one effect at a time, amount under ~0.5.`,
+ `Add a time-ranged effect element over the cut: a zoom into part of the frame, a picture treatment (${EFFECT_TREATMENTS.join(", ")}), a graded look (${LOOK_EFFECTS.join(", ")}), or an audio treatment (${AUDIO_EFFECT_IDS.join(", ")}) over the sound. A picture effect filters everything visible under its window (start..end); an audio effect treats everything audible under it — clip sound, upper tracks and soundtrack together. They stack. glitch is clean footage broken by runs of corrupted frames — dark pixel-stretch smears, the picture doubled sideways over an orange burn, teal close-ups, blown-out flashes — the glitch ending of a teaser, where amount is how often it hits. A glitch pinned to one kind (glitch "smear", "split", "tint", "blowout" or "rgb") hits with it on every frame; "rgb" pulls the color channels apart, red down and blue up — a 2–3 frame rgb glitch is the RGB-split hit of a collapsing title or HUD. lightleak drifts a warm bloom and light streaks over the picture for as long as it is up; with leak "burn" it is a film burn played once across the element's own length: it climbs from the bottom edge behind a hot orange front, flares near white, settles orange and hands the picture back in its last tenth — the burn-out of a teaser, a 0.4–0.6s element over the end of the last shot, amount 1 for a fully opaque burn. With leak "scorch" it flashes film burn through the picture: every frame maps the picture onto a saturated hot tone by brightness — yellow, orange, or red over pink — across the whole frame or a soft-edged patch of it, a new tone and patch each frame; short 2–12 frame scorches over the last shots, amount 1, are the burn-through flicker of a teaser's ending. With leak "film" it is the film-strip flash over a cut, played once across the element: the picture washes warm orange, a brighter band glows across the lower middle and the strip's sprocket holes blaze cream along the top edge, full through the middle of the element and gone by its ends — a 3–5 frame element centered on a cut, amount 1, is the film-strip light-leak transition of a recap montage (one per section change). With leak "char" it is the burn's climb in dark stock: a hot orange front rises from the bottom edge, the frame cools through ember to black behind it, a thin bright light line crosses, and the picture comes back in the last tenth — never a pale flare; an 8–10 frame element, amount 1, over a black card's end and the next shot's first frames is the dark film-burn handover of a recap opener. lightbars is the streaming-service sting: the camera flies down a ribbon of glowing vertical lines (reds, oranges and pinks on the left, blues on the right) across the element's own length — it opens as one narrow warm column just left of the frame's middle (x about 0.46, a twelfth of the frame wide), bursts out to fill the frame about a quarter of the way in, keeps flowing outward as deeper lines spread after the near ones, flares red and pink about three quarters in, then leaves one red line just right of the middle that widens and sweeps off the right edge as the element ends, on black. Bars add light onto the picture, so over black (no clip under it) they are the whole picture; a 1.6–1.7s element, amount 1, right after a logo reveal whose last red vertical stroke stands where the column opens. flash pops the picture white at the element's start and decays in about 0.4s; tone "black" dips it dark instead, and a strobe rate holds the tone on and off that many times a second for the whole element — a black strobe at 5–6 with amount 0.9–1 is the dark beat-flicker over a teaser's last shot. rhythm "flicker" deals each pulse its own strength and leaves some dark: an uneven exposure flicker, a white flicker at rate 12–15 and amount 0.15–0.25. To flicker one shot inside its mask, give the clip the flash through set_clip_effects. Tasteful default: one effect at a time, amount under ~0.5.`,
inputSchema: obj({
effect: { type: "string", enum: [...ALL_EFFECT_IDS], description: "Effect id" },
start: num("Start time s (default: playhead)"),
diff --git a/site/src/cut/components/EffectsPanel.tsx b/site/src/cut/components/EffectsPanel.tsx
index 141b10e7..f0734910 100644
--- a/site/src/cut/components/EffectsPanel.tsx
+++ b/site/src/cut/components/EffectsPanel.tsx
@@ -11,6 +11,7 @@ import {
isAudioEffect,
LEAK_TINT,
leakGradient,
+ lightbarBox,
streakGradient,
type EffectId,
} from "@donkeycut/effects-kit";
@@ -80,7 +81,7 @@ const GROUPS = [
{ id: "audio", label: "Sound" },
] as const;
-const MOVING: EffectId[] = ["zoom", "grain", "vhs", "glitch", "lightleak", "flash", "shake", "huecycle"];
+const MOVING: EffectId[] = ["zoom", "grain", "vhs", "glitch", "lightleak", "lightbars", "flash", "shake", "huecycle"];
const groupOf = (id: EffectId): EffectGroup =>
isAudioEffect(id) ? "audio" : MOVING.includes(id) ? "moving" : "filters";
@@ -1009,6 +1010,13 @@ export function EffectSwatch({
{!!st.flash && (
<span className="absolute inset-0 bg-white" style={{ opacity: Math.min(0.75, st.flash) }} />
)}
+ {st.bars?.map((b, j) => (
+ <span
+ key={`bar-${j}`}
+ className="absolute inset-y-0"
+ style={{ ...lightbarBox(b), mixBlendMode: "plus-lighter" }}
+ />
+ ))}
</span>
);
}
diff --git a/site/src/cut/components/ElementsPanel.tools.ts b/site/src/cut/components/ElementsPanel.tools.ts
index 38c2565a..dfe7fc7f 100644
--- a/site/src/cut/components/ElementsPanel.tools.ts
+++ b/site/src/cut/components/ElementsPanel.tools.ts
@@ -11,6 +11,9 @@ import { DOODLE_FPS, DOODLE_INKS_MAX, PATTERN_KINDS, SHADOW_BLUR_MAX, SHADOW_OFF
import { bool, num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";
import { SHAPE_LABELS, type ShapeKind } from "@/cut/lib/types";
+/** The longest SVG markup add_sticker draws a sticker from. */
+export const SVG_STICKER_MAX_CHARS = 20000;
+
/** Every shape the panel's grid shows, in `SHAPE_LABELS` order. */
export const SHAPE_KINDS = Object.keys(SHAPE_LABELS) as ShapeKind[];
@@ -55,9 +58,11 @@ export const ELEMENTS_TOOLS = [
{
name: "add_sticker",
description:
- "Add a sticker overlay from a project image asset (asset ids come from `media`; sticker uploads carry origin \"sticker\"). Width is a frame-width fraction; height follows the source's own aspect unless h sets it.",
+ "Add a sticker overlay from a project image asset (asset ids come from `media`; sticker uploads carry origin \"sticker\"), or draw one from SVG markup you write: pass svg instead of asset_id for a vector graphic no shape covers — a UI icon (download arrow, stacked episodes, speech-bubble subtitles, skip-next), a mouse pointer, a loading-spinner arc, a badge with lettering, a logo mark, line-art doodles around a title (sparkles, starbursts, fireworks, swirls, hearts drawn as thin white strokes). The markup is drawn to a transparent PNG (1024 px on its long side, keeping the viewBox's aspect), saved as an origin-\"sticker\" asset and placed; the result carries its assetId to place it again without redrawing. Width is a frame-width fraction; height follows the source's own aspect unless h sets it.",
inputSchema: obj({
- asset_id: str("Project image asset id"),
+ asset_id: str("Project image asset id (or pass svg)"),
+ svg: str(`SVG markup for a drawn sticker, instead of asset_id: one <svg viewBox=\"…\"> element with inline shapes, paths and text, no scripts or outside files, at most ${SVG_STICKER_MAX_CHARS} characters. Fill the viewBox with the graphic — empty margin becomes clear padding in the sticker`),
+ name: str("Drawn sticker only: the asset's name in Media (default \"Drawn sticker\")"),
start: num("Start time s (default: playhead)"),
end: num("End time s (default: start+3)"),
x: num("Center x 0..1 (default 0.5)"),
diff --git a/site/src/cut/components/FlashPulseRows.tsx b/site/src/cut/components/FlashPulseRows.tsx
index 32cd8bdf..1db162df 100644
--- a/site/src/cut/components/FlashPulseRows.tsx
+++ b/site/src/cut/components/FlashPulseRows.tsx
@@ -1,6 +1,6 @@
"use client";
-import { FLASH_RHYTHMS, FLASH_RATE_MAX, FLASH_TONES, type FlashRhythm, type FlashPulse, type FlashTone } from "@donkeycut/effects-kit";
+import { FLASH_FADE_CHOICES, FLASH_FADE_NONE, FLASH_RHYTHMS, FLASH_RATE_MAX, FLASH_TONES, type FlashFadeChoice, type FlashRhythm, type FlashPulse, type FlashTone } from "@donkeycut/effects-kit";
import { Row, useSliderCheckpoint } from "@/cut/components/panelBits";
import { parseNumberInput } from "@/cut/components/ScrubValue";
import { ValueSlider } from "@/cut/components/ValueSlider";
@@ -8,12 +8,13 @@ import { cn } from "@/lib/utils";
const FLASH_TONE_LABELS: Record<FlashTone, string> = { white: "White", black: "Black" };
const FLASH_RHYTHM_LABELS: Record<FlashRhythm, string> = { strobe: "Strobe", flicker: "Flicker" };
+const FLASH_FADE_LABELS: Record<FlashFadeChoice, string> = { none: "Off", to: "To", from: "From" };
/** How a write lands: `draft` while a slider drags (one undo step, closed by
* the checkpoint), `commit` for a single click. */
export type PulseWrite = "draft" | "commit";
-/** A two-way segmented choice in the flash rows. */
+/** A segmented choice in the flash rows. */
function Segmented<T extends string>({ items, value, labels, onPick }: { items: readonly T[]; value: T; labels: Record<T, string>; onPick: (v: T) => void }) {
return (
<div className="flex w-36 rounded-lg border border-input p-0.5 text-[11.5px] font-medium">
@@ -86,3 +87,18 @@ export function FlashPulseRows({ pulse, write }: { pulse: FlashPulse; write: (pa
</>
);
}
+
+/** A flash element's fade: off (the pop), into the tone, or out of it,
+ * evenly across the element. Off writes as absence. */
+export function FlashFadeRow({ pulse, write }: { pulse: FlashPulse; write: (patch: FlashPulse, how: PulseWrite) => void }) {
+ return (
+ <Row label="Fade">
+ <Segmented
+ items={FLASH_FADE_CHOICES}
+ value={pulse.fade ?? FLASH_FADE_NONE}
+ labels={FLASH_FADE_LABELS}
+ onPick={(c) => write({ fade: c === FLASH_FADE_NONE ? undefined : c }, "commit")}
+ />
+ </Row>
+ );
+}
diff --git a/site/src/cut/components/GroupPanel.tsx b/site/src/cut/components/GroupPanel.tsx
index b5c02c32..a065d6e4 100644
--- a/site/src/cut/components/GroupPanel.tsx
+++ b/site/src/cut/components/GroupPanel.tsx
@@ -19,6 +19,7 @@ import { usePreviewTime } from "@/cut/lib/playhead";
import { clipWindow, maxClipFade, useEditor } from "@/cut/lib/store";
import { PLATE_COLOR, PLATE_OPACITY, PLATE_RADIUS } from "@/cut/lib/textRender";
import { TEXT_SIZES } from "@/cut/lib/textStyle";
+import { TEXT_SIZE_MAX, TEXT_SIZE_MIN } from "@/cut/components/Timeline.tools";
import {
clampOverlayPos,
CLIP_MAX_ZOOM,
@@ -431,8 +432,8 @@ function TextRows({ texts }: { texts: TextOverlay[] }) {
icon={<Type />}
value={size.value}
mixed={size.mixed}
- min={24}
- max={240}
+ min={TEXT_SIZE_MIN}
+ max={TEXT_SIZE_MAX}
step={1}
presets={TEXT_SIZES}
format={(v) => String(Math.round(v))}
diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.ts
index b276ccfd..bdb05619 100644
--- a/site/src/cut/components/Inspector.tools.ts
+++ b/site/src/cut/components/Inspector.tools.ts
@@ -53,6 +53,11 @@ import {
STRIPE_LINE_MIN,
} from "@donkeycut/effects-kit";
import { EFFECT_SETTING_ARGS } from "@/cut/components/EffectsPanel.tools";
+import { TEXT_SIZE_MAX, TEXT_SIZE_MIN } from "@/cut/components/Timeline.tools";
+
+/** The narrowest a sticker draws, as a frame-width fraction: about 10 px on
+ * a 1920 frame, room for a mouse pointer or a small UI icon. */
+export const STICKER_W_MIN = 0.005;
import { bool, ids, num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";
import { builtinLutCatalogText } from "@/cut/lib/builtinLuts";
import { SPLIT_EDIT_MAX_S } from "@/cut/lib/soundSource";
@@ -123,17 +128,17 @@ export const INSPECTOR_TOOLS = [
{
name: "update_overlay",
description:
- "Update any overlay element — title, shape, or sticker — by id (from the selection or state). Titles take text/size/font/weight/color/shadow/plate; shapes take w/h/fill/inks/fill_opacity/radius/stroke/pattern/shadow; stickers take w/h. A shadow on a title or shape takes color, blur, opacity and offset; a colored shadow at shadow_y 0 is a glow. Every kind takes name, timing, position, rotation, opacity, blur, motion blur, hidden. This is the tool for 'make this text better' requests too. Pass ids to land one change on several elements at once (a group, every title in a run): fields a kind lacks are skipped on that element, and the whole write is one undo step.",
+ "Update any overlay element — title, shape, or sticker — by id (from the selection or state). Titles take text/size/font/weight/color/shadow/plate; shapes take w/h/fill/inks/fill_opacity/radius/stroke/pattern/shadow; stickers take w/h. Effects take amount and their own settings (leak, glitch, tone, rate, rhythm, fade — see add_effect), changed in place so the element keeps its id, lane and timing. A shadow on a title or shape takes color, blur, opacity and offset; a colored shadow at shadow_y 0 is a glow. Every kind takes name, timing, position, rotation, opacity, blur, motion blur, hidden. This is the tool for 'make this text better' requests too. Pass ids to land one change on several elements at once (a group, every title in a run): fields a kind lacks are skipped on that element, and the whole write is one undo step.",
inputSchema: obj({
id: str("Overlay element id"),
ids: { type: "array", items: { type: "string" }, description: "Several element ids to change together (instead of id)" },
name: str("What the person calls this element — shown on its timeline chip and inspector title (empty string clears it, back to what it is)"),
text: str("New text (titles)"),
- start: num("Start s"),
- end: num("End s"),
+ start: num("Start s. Alone it moves the element, its length riding along; with end it sets both edges. A start that lands on another element on the same row slides this one on to the next free spot, so shrink the neighbour first"),
+ end: num("End s. Alone it trims or extends in place, pushing the later elements on the row along"),
x: num(`Center x 0..1; a grouped element reaches ${CAMERA_WORLD_MIN}..${CAMERA_WORLD_MAX}, off the frame, for its group camera`),
y: num(`Center y 0..1; a grouped element reaches ${CAMERA_WORLD_MIN}..${CAMERA_WORLD_MAX}`),
- size: num("Font size px at 1080w (titles)"),
+ size: num(`Font size px at 1080w (titles), ${TEXT_SIZE_MIN}..${TEXT_SIZE_MAX}`),
color: str("CSS text color (titles)"),
font: str("Font id (titles; see the graphics skill)"),
weight: { type: "number", enum: [...TEXT_WEIGHTS], description: "Font weight (titles): 400 regular, 500 medium, 600 semibold, 700 bold, 800 extra bold, 900 black" },
@@ -153,8 +158,8 @@ export const INSPECTOR_TOOLS = [
enum: [...TEXT_TEXTURES, "none"],
description: 'Titles: grain inside the letters: "stipple" breaks each letter into spray-paint specks along its left edge, solid by its middle (the gritty teaser title); "none" makes the type solid again',
},
- w: num("Width, fraction of frame width (shapes/stickers)"),
- h: num("Height, fraction of frame height (shapes/stickers; a sticker's 0 returns it to the source's aspect)"),
+ w: num(`Width, fraction of frame width (shapes 0.01..2, stickers ${STICKER_W_MIN}..1.5: a 36 px mouse pointer is about 0.012)`),
+ h: num(`Height, fraction of frame height (shapes; stickers ${STICKER_W_MIN}..1.5, and 0 returns a sticker to its source's aspect)`),
fill: str("Fill color (shapes)"),
inks: {
type: "array",
@@ -460,7 +465,7 @@ export const INSPECTOR_TOOLS = [
{
name: "set_color_grade",
description:
- `Color-grade a video clip's basic sliders (any track; stills too): the Light group (${GRADE_BASIC_FIELDS.filter((f) => f.group === "light").map((f) => f.key).join(", ")}), the Color group (${GRADE_BASIC_FIELDS.filter((f) => f.group === "color").map((f) => f.key).join(", ")}) and the Detail pair (${GRADE_DETAIL_FIELDS.map((f) => f.key).join(", ")}). Fields patch the clip's current grade: only the ones you pass change, and every value 0 is neutral. The light sliders work in linear light on the picture after its source conversion and LUT; manual adjustments layer OVER the clip's color preset (set_color_preset), never replacing it. reset:true clears the manual grade first (the preset and LUT stay); auto:true fits a starting grade from the clip's base rendering (auto-tone: exposure to middle gray, contrast stretch, gray-world white balance — needs the clip's frame decoded, so seek into it first if this errors), and explicit fields then override it. Preview, timeline thumbnails, and export all render the same result. Read read_color_stats before grading so the numbers ground the move. Pass ids or all_clips to land the same patch on several clips as one undo step.`,
+ `Color-grade a video clip's basic sliders (any track; stills too): the Light group (${GRADE_BASIC_FIELDS.filter((f) => f.group === "light").map((f) => f.key).join(", ")}), the Color group (${GRADE_BASIC_FIELDS.filter((f) => f.group === "color").map((f) => f.key).join(", ")}) and the Detail pair (${GRADE_DETAIL_FIELDS.map((f) => f.key).join(", ")}). Fields patch the clip's current grade: only the ones you pass change, and every value 0 is neutral. The light sliders work in linear light on the picture after its source conversion and LUT; manual adjustments layer OVER the clip's color preset (set_color_preset), never replacing it. reset:true clears the manual grade first (the preset and LUT stay); auto:true fits a starting grade from the clip's base rendering (auto-tone: exposure to middle gray, contrast stretch, gray-world white balance), and explicit fields then override it. Preview, timeline thumbnails, and export all render the same result. Read read_color_stats before grading so the numbers ground the move. Pass ids or all_clips to land the same patch on several clips as one undo step.`,
inputSchema: obj({
clipId: str("Video clip id"),
...manyClips,
@@ -585,7 +590,7 @@ export const INSPECTOR_TOOLS = [
{
name: "read_color_stats",
description:
- "Read color statistics off a frame — per-channel and luma quantiles (0..255), channel means, mean saturation, and warmth (red/blue midtone ratio; >1 warm, <1 cool). Pass clipId for a video clip's current frame (seek into the clip first if it errors) or assetId for an image (a chat attachment or Media import). A clip reads as its base rendering — through the source conversion, before any LUT or grade, so the numbers describe the footage itself; graded:true reads it through the clip's LUT, preset and adjustments, which is how a move is verified. Read the base before grading — never grade blind — and the graded frame after.",
+ "Read color statistics off a frame — per-channel and luma quantiles (0..255), channel means, mean saturation, and warmth (red/blue midtone ratio; >1 warm, <1 cool). Pass clipId for a video clip's frame (the one on screen when the playhead is in the clip, otherwise one decoded from its file at the middle of its trim) or assetId for an image (a chat attachment or Media import). A clip reads as its base rendering — through the source conversion, before any LUT or grade, so the numbers describe the footage itself; graded:true reads it through the clip's LUT, preset and adjustments, which is how a move is verified. Read the base before grading — never grade blind — and the graded frame after.",
inputSchema: obj({
clipId: str("Video clip id (its current frame)"),
assetId: str("Image asset id (chat attachment or import)"),
@@ -595,7 +600,7 @@ export const INSPECTOR_TOOLS = [
{
name: "match_color_grade",
description:
- "Match a video clip's color to a reference, computed from the pixels: per-channel quantile mapping compiled into tone curves plus a saturation delta. The computed curves carry the whole look, so the match replaces the clip's entire grade, preset and LUT included. The reference is ref_asset_id (an attached or imported image) or ref_clip_id (another clip's current frame). Use when the user shares a look to copy or asks to match two shots; refine afterward with the other grading tools, checking read_color_stats.",
+ "Match a video clip's color to a reference, computed from the pixels: per-channel quantile mapping compiled into tone curves (each segment's slope bounded, so a reference of other content shifts the look without tearing gradients into bands) plus a saturation delta. The computed curves carry the whole look, so the match replaces the clip's entire grade, preset and LUT included. The reference is ref_asset_id (an attached or imported image) or ref_clip_id (another clip's frame). Use when the user shares a look to copy or asks to match two shots; refine afterward with the other grading tools, checking read_color_stats.",
inputSchema: obj({
clipId: str("Video clip to grade"),
ref_asset_id: str("Reference image asset id"),
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsx
index ee156635..24d3d570 100644
--- a/site/src/cut/components/Inspector.tsx
+++ b/site/src/cut/components/Inspector.tsx
@@ -98,6 +98,7 @@ import {
restingMaskFrame,
AMOUNTLESS_EFFECTS,
displayWords,
+ CYCLE_HOLD_MAX,
CYCLE_SCALE_MAX,
CYCLE_SCALE_MIN,
FONT_CYCLE_FACES_MAX,
@@ -115,7 +116,7 @@ import {
type OverlayFontCycle,
type TextWeight,
} from "@donkeycut/effects-kit";
-import { SHADOW, SHADOW_BLUR_MAX, SHADOW_OFFSET_MAX, STRIPE_GAP_MAX, STRIPE_LINE_MAX, STRIPE_LINE_MIN, STRIPES_DEFAULT, type ShadowSpec, type StripesPattern } from "@donkeycut/effects-kit";
+import { SHADOW, SHADOW_BLUR_MAX, SHADOW_OFFSET_MAX, STRIPE_GAP_MAX, STRIPE_LINE_MAX, STRIPE_LINE_MIN, STRIPES_DEFAULT, type FlashPulse, type ShadowSpec, type StripesPattern } from "@donkeycut/effects-kit";
import { BLOCK_COLOR } from "@/cut/lib/blockSource";
import { bindRecording, unbindRecording } from "@/cut/lib/soundBind";
import { SPLIT_EDIT_MAX_S } from "@/cut/lib/soundSource";
@@ -124,7 +125,10 @@ import { PANEL_GLOBAL, usePanelState, useRememberedScroll } from "@/cut/lib/pane
import { playheadAt, usePreviewTime } from "@/cut/lib/playhead";
import { allFonts, CLIP_MAX_ZOOM, clipCovers, clipKeyed, clipPoseAt, clipZoom, contentRect } from "@/cut/lib/types";
import { AnimationTiles } from "@/cut/components/AnimationTiles";
-import { FlashPulseRows } from "@/cut/components/FlashPulseRows";
+import { LOOP_SPEED_MAX, LOOP_SPEED_MIN } from "@/cut/components/AnimationTiles.tools";
+import { STICKER_W_MIN } from "@/cut/components/Inspector.tools";
+import { TEXT_SIZE_MAX, TEXT_SIZE_MIN } from "@/cut/components/Timeline.tools";
+import { FlashFadeRow, FlashPulseRows, type PulseWrite } from "@/cut/components/FlashPulseRows";
import { ColorField } from "@/cut/components/ColorField";
import { wordTimesFor } from "@/cut/lib/textWords";
import { NumberField } from "@/cut/components/NumberField";
@@ -144,8 +148,12 @@ import {
deleteStylePreset,
listStylePresets,
saveStylePreset,
+ styleMatches,
+ updateStylePreset,
type StylePreset,
} from "@/cut/lib/stylePresets";
+import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
+import { PICKED_RING } from "@/cut/lib/assetPick";
import {
deleteSoundPreset,
saveSoundPreset,
@@ -2230,8 +2238,8 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
className="ml-auto w-[74px]"
icon={<Type />}
value={o.size}
- min={24}
- max={240}
+ min={TEXT_SIZE_MIN}
+ max={TEXT_SIZE_MAX}
step={1}
presets={TEXT_SIZES}
format={(v) => String(Math.round(v))}
@@ -2470,19 +2478,57 @@ export function StylePresetsRow({ overlay: o, peers }: { overlay: TextOverlay; p
}
};
+ // Overwrite a saved style with this title's look, in place in the chip row.
+ const update = async (p: StylePreset) => {
+ const projectId = useEditor.getState().projectId;
+ if (!projectId || busy) return;
+ setBusy(true);
+ try {
+ const next = await updateStylePreset(projectId, p, o);
+ setPresets((prev) => (prev ?? []).flatMap((x) => (x !== p ? [x] : next ? [next] : [])));
+ } catch {
+ // Signed out or offline shelf — the saved style keeps its old look.
+ } finally {
+ setBusy(false);
+ }
+ };
+
if (presets === null) return null;
+
+ // A title that wears no saved style as-is has a look to push into one.
+ const worn = presets.find((p) => styleMatches(p.style, o));
+ const canUpdate = presets.length > 0 && !worn;
return (
<div className="mb-1.5">
<div className="mb-1 flex items-center justify-between">
<span className="text-[13px] text-muted-foreground">Styles</span>
{!naming && (
- <button
- type="button"
- className="text-[11.5px] text-muted-foreground transition-colors hover:text-foreground"
- onClick={() => setNaming(true)}
- >
- Save style
- </button>
+ <div className="flex items-center gap-3">
+ {canUpdate && (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ disabled={busy}
+ className="text-[11.5px] text-muted-foreground transition-colors hover:text-foreground"
+ >
+ Update style
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {presets.map((p) => (
+ <DropdownMenuItem key={`${p.residency}:${p.id}`} onClick={() => void update(p)}>
+ {p.name}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
+ <button
+ type="button"
+ className="text-[11.5px] text-muted-foreground transition-colors hover:text-foreground"
+ onClick={() => setNaming(true)}
+ >
+ Save style
+ </button>
+ </div>
)}
</div>
{naming && (
@@ -2510,7 +2556,10 @@ export function StylePresetsRow({ overlay: o, peers }: { overlay: TextOverlay; p
<button
type="button"
title={`Apply ${p.name}`}
- className="flex items-center gap-1.5 rounded-md border border-input px-2 py-1 text-[11.5px] transition-colors hover:border-ring"
+ className={cn(
+ "flex items-center gap-1.5 rounded-md border border-input px-2 py-1 text-[11.5px] transition-colors hover:border-ring",
+ p === worn && PICKED_RING
+ )}
onClick={() => {
const st = useEditor.getState();
st.pushHistory();
@@ -2967,7 +3016,18 @@ function FontCycleFaces({ overlay: o, peers }: { overlay: TextOverlay; peers?: r
</Button>
</div>
<Row label="Weight">
- <WeightSelect value={face.weight ?? o.weight} onChange={(weight) => commit(setFace(i, { weight }))} />
+ <div className="flex items-center gap-1.5">
+ <WeightSelect value={face.weight ?? o.weight} onChange={(weight) => commit(setFace(i, { weight }))} />
+ <SegGroup>
+ <SegToggle
+ label="Italic"
+ active={face.italic ?? !!o.italic}
+ onClick={() => commit(setFace(i, { italic: !(face.italic ?? !!o.italic) }))}
+ >
+ <Italic />
+ </SegToggle>
+ </SegGroup>
+ </div>
</Row>
<Row label="Size">
<ValueSlider
@@ -3012,6 +3072,29 @@ function FontCycleFaces({ overlay: o, peers }: { overlay: TextOverlay; peers?: r
}}
/>
</Row>
+ {/* Hold: how long this face shows; 0 follows the cycle's rate. */}
+ <Row label="Hold">
+ <ValueSlider
+ label="Hold"
+ sliderClassName="data-horizontal:w-24"
+ valueClassName="w-9 text-muted-foreground"
+ value={face.hold ?? 0}
+ min={0}
+ max={CYCLE_HOLD_MAX}
+ step={1 / 60}
+ snap={[0]}
+ format={(v) => (v > 0 ? `${v.toFixed(2)}s` : "Rate")}
+ parse={parseNumberInput}
+ onDraft={(v) => {
+ ck.begin();
+ write(setFace(i, { hold: v > 0 ? v : undefined }));
+ }}
+ onCommit={(v) => {
+ write(setFace(i, { hold: v > 0 ? v : undefined }));
+ ck.end();
+ }}
+ />
+ </Row>
</div>
))}
<Button
@@ -3408,8 +3491,8 @@ function AnimationToolbar({ overlay: o, slot, peers }: { overlay: Overlay; slot:
sliderClassName="data-horizontal:w-24"
valueClassName="w-9 text-muted-foreground"
value={anim.loop?.speed ?? 1}
- min={0.25}
- max={4}
+ min={LOOP_SPEED_MIN}
+ max={LOOP_SPEED_MAX}
step={0.25}
snap={[1]}
format={(v) => `${v.toFixed(2)}×`}
@@ -4944,6 +5027,15 @@ function PatternSection({ overlay: o }: { overlay: ShapeOverlay }) {
);
}
+/** A flash element's setting, drafted while a slider drags. */
+function writeFlash(id: string, patch: FlashPulse, how: PulseWrite) {
+ if (how === "draft") {
+ useEditor.getState().updateOverlayTransient(id, patch);
+ return;
+ }
+ useEditor.getState().updateOverlay(id, patch);
+}
+
function EffectPanel({ overlay: o }: { overlay: EffectOverlay }) {
const amountCk = useSliderCheckpoint();
return (
@@ -4959,12 +5051,10 @@ function EffectPanel({ overlay: o }: { overlay: EffectOverlay }) {
{o.effect === "lightleak" && <LeakCourseRow overlay={o} />}
{o.effect === "glitch" && <GlitchKindRow overlay={o} />}
{o.effect === "flash" && (
- <FlashPulseRows
- pulse={o}
- write={(patch, how) =>
- how === "draft" ? useEditor.getState().updateOverlayTransient(o.id, patch) : useEditor.getState().updateOverlay(o.id, patch)
- }
- />
+ <>
+ <FlashPulseRows pulse={o} write={(patch, how) => writeFlash(o.id, patch, how)} />
+ <FlashFadeRow pulse={o} write={(patch, how) => writeFlash(o.id, patch, how)} />
+ </>
)}
<Row label="Amount">
<ValueSlider
@@ -5246,10 +5336,10 @@ function StickerPanel({ overlay: o }: { overlay: StickerOverlay }) {
sliderClassName="data-horizontal:w-24"
valueClassName="w-9 text-muted-foreground"
value={o.w}
- min={0.02}
+ min={STICKER_W_MIN}
max={1}
- step={0.01}
- format={(v) => String(Math.round(v * 100))}
+ step={0.005}
+ format={(v) => (v < 0.1 ? (v * 100).toFixed(1) : String(Math.round(v * 100)))}
parse={parsePercentInput}
onDraft={(v) => {
widthCk.begin();
diff --git a/site/src/cut/components/StageEffects.tsx b/site/src/cut/components/StageEffects.tsx
index 9b61bfc3..085f696c 100644
--- a/site/src/cut/components/StageEffects.tsx
+++ b/site/src/cut/components/StageEffects.tsx
@@ -8,6 +8,7 @@ import {
isAudioEffect,
LEAK_TINT,
leakGradient,
+ lightbarBox,
streakGradient,
washBackground,
} from "@donkeycut/effects-kit";
@@ -159,7 +160,18 @@ export function StageEffectPaint({ lane }: { lane: number }) {
const washes = states.flatMap((s) => s.washes ?? []);
const leaks = states.flatMap((s) => (s.leak ? [s.leak] : []));
const burns = states.flatMap((s) => (s.burn ? [s.burn] : []));
- if (!grain && !vignette && !flash && !dark && washes.length === 0 && leaks.length === 0 && burns.length === 0) return null;
+ const bars = states.flatMap((s) => s.bars ?? []);
+ if (
+ !grain &&
+ !vignette &&
+ !flash &&
+ !dark &&
+ washes.length === 0 &&
+ leaks.length === 0 &&
+ burns.length === 0 &&
+ bars.length === 0
+ )
+ return null;
return (
<div className="pointer-events-none absolute inset-0">
{grain > 0 && grainUrl && (
@@ -226,6 +238,15 @@ export function StageEffectPaint({ lane }: { lane: number }) {
)}
</div>
))}
+ {bars.map((b, i) => (
+ // Each light bar added onto the picture, as the canvas pass's
+ // "lighter" composite does.
+ <div
+ key={`bar-${i}`}
+ className="absolute inset-y-0"
+ style={{ ...lightbarBox(b), mixBlendMode: "plus-lighter" }}
+ />
+ ))}
</div>
);
}
diff --git a/site/src/cut/components/SubtitlesPanel.tools.ts b/site/src/cut/components/SubtitlesPanel.tools.ts
index 7cca6473..581c74c7 100644
--- a/site/src/cut/components/SubtitlesPanel.tools.ts
+++ b/site/src/cut/components/SubtitlesPanel.tools.ts
@@ -139,7 +139,7 @@ export const SUBTITLES_TOOLS = [
{
name: "set_caption_emphasis",
description:
- `Set chosen caption words apart in the track's emphasis style (set_caption_look emphasis_* fields; default a bold italic ${CAPTION_EMPHASIS_DEFAULT.font} serif in ${CAPTION_EMPHASIS_DEFAULT.color} at the caption's size) while the rest of the line stays as it is — the social-caption highlight on a product name, a number, the keyword of the call to action. Any word effect still plays on top. Each mark names a cue id and its words, either by 0-based index into the cue's text split on spaces or by the exact word as it appears in that cue (a word that appears twice marks both). Emphasis stays with its word through a words_per_cue re-cut, align_to_audio, retiming and edits that keep the word. editor_state lists each cue's emphasized words. Cadence: one or two meaningful words in a caption, then two or three plain captions before the next; never two emphasized captions in a row, and never a function word (the, and, to, of, is). One call marks the whole track; \`clear_all\` first wipes what is there.`,
+ `Set chosen caption words apart in the track's emphasis style (set_caption_look emphasis_* fields; default a bold italic ${CAPTION_EMPHASIS_DEFAULT.font} serif in ${CAPTION_EMPHASIS_DEFAULT.color} at the caption's size) while the rest of the line stays as it is — the social-caption highlight on a product name, a number, the keyword of the call to action. Any word effect still plays on top. Each mark names a cue id and its words, either by 0-based index into the cue's text split on spaces or by the exact word as it appears in that cue (a word that appears twice marks both). Emphasis stays with its word through a words_per_cue re-cut, align_to_audio, retiming and edits that keep the word. editor_state lists each cue's emphasized words. Call it only when the user asks for words set apart; captions carry no emphasis otherwise. Cadence: one or two meaningful words in a caption, then two or three plain captions before the next; never two emphasized captions in a row, and never a function word (the, and, to, of, is). One call marks the whole track; \`clear_all\` first wipes what is there.`,
inputSchema: obj({
marks: {
type: "array",
diff --git a/site/src/cut/components/Timeline.tools.ts b/site/src/cut/components/Timeline.tools.ts
index 7b2cf249..4e933c6a 100644
--- a/site/src/cut/components/Timeline.tools.ts
+++ b/site/src/cut/components/Timeline.tools.ts
@@ -19,6 +19,11 @@ import { TEXT_MOVE_IDS, TEXT_MOVE_NOTES } from "@/cut/lib/textMotion";
import { LETTER_SPACING_MAX, LETTER_SPACING_MIN, OVERLAY_ANIM_STYLE_IDS, TEXT_TEXTURES, TEXT_WEIGHTS } from "@donkeycut/effects-kit";
import { REGION_MAX_SCALE, TIMELINE_IDS, TIMELINE_LABELS } from "@/cut/lib/types";
+/** The title sizes the assistant and the inspector set, px at a 1080 short
+ * side. */
+export const TEXT_SIZE_MIN = 16;
+export const TEXT_SIZE_MAX = 1600;
+
export const TIMELINE_TOOLS = [
{
name: "select",
@@ -251,7 +256,7 @@ export const TIMELINE_TOOLS = [
end: num("End time s (default: start+3)"),
x: num("Center x 0..1 (default 0.5)"),
y: num("Center y 0..1 (default 0.42)"),
- size: num("Font size px at 1080w (default 88)"),
+ size: num(`Font size px at 1080w, ${TEXT_SIZE_MIN}..${TEXT_SIZE_MAX} (default 88); a capital is about 0.7 of the size tall, so one letter filling a third of a 1080 frame is about 500`),
color: str("CSS color (default #FFFFFF)"),
font: str("Font id (see the graphics skill; default sf)"),
weight: { type: "number", enum: [...TEXT_WEIGHTS], description: "Font weight: 400 regular, 500 medium, 600 semibold, 700 bold, 800 extra bold, 900 black" },
@@ -306,7 +311,7 @@ export const TIMELINE_TOOLS = [
},
section: str('Passage label ("verse", "chorus", "bridge") — a new label restarts the type and color rotas'),
color: str("Override the run's color for this line"),
- size: num("Override the composed size for this line"),
+ size: num(`Override the composed size for this line, ${TEXT_SIZE_MIN}..${TEXT_SIZE_MAX}`),
font: str("Override the face carrying this line"),
x: num("Frame-width fraction 0..1, overriding the layout"),
y: num("Frame-height fraction 0..1, overriding the layout"),
diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.ts
index 71de6ace..e8ce0bee 100644
--- a/site/src/cut/lib/aiContext.ts
+++ b/site/src/cut/lib/aiContext.ts
@@ -41,6 +41,9 @@ import {
} from "./types";
const r = (n: number) => Math.round(n * 100) / 100;
+/** Element times to the millisecond: a 60 fps frame is 0.0167 s, which two
+ * decimals blur. editor_state and the tool results both read times through it. */
+export const roundT = (n: number) => Math.round(n * 1000) / 1000;
/** The transition this clip applies into the next one, clamped to the live
* overlap the same way the preview and export are. Null when there's no
@@ -641,7 +644,7 @@ function describeState(
...(sp.clip.grade ? { colorGrade: sp.clip.grade } : {}),
...(sp.clip.mask ? { mask: sp.clip.mask } : {}),
...(sp.clip.kf?.length
- ? { keyframes: sp.clip.kf.map((k) => ({ ...k, t: r(k.t), x: r(k.x), y: r(k.y) })) }
+ ? { keyframes: sp.clip.kf.map((k) => ({ ...k, t: roundT(k.t), x: r(k.x), y: r(k.y) })) }
: {}),
...(sp.clip.motionBlur ? { motionBlur: r(sp.clip.motionBlur) } : {}),
...clipEffects(sp.clip, live, { aspect: s.aspect, assetById }),
@@ -702,7 +705,7 @@ function describeState(
groupCameras: cams.map((c) => ({
groupId: c.groupId,
start: r(c.start),
- keys: c.keys.map((k) => ({ ...k, t: r(k.t), x: r(k.x), y: r(k.y), scale: r(k.scale), rotation: r(k.rotation) })),
+ keys: c.keys.map((k) => ({ ...k, t: roundT(k.t), x: r(k.x), y: r(k.y), scale: r(k.scale), rotation: r(k.rotation) })),
...(c.motionBlur ? { motionBlur: r(c.motionBlur) } : {}),
})),
}
@@ -852,7 +855,7 @@ function describeOverlayClip(c: VideoClip, assets: Map<string, { name: string }>
...(c.mask ? { mask: c.mask } : {}),
...(c.boxStyle ? { boxStyle: c.boxStyle } : {}),
...(c.kf?.length
- ? { keyframes: c.kf.map((k) => ({ ...k, t: r(k.t), x: r(k.x), y: r(k.y) })) }
+ ? { keyframes: c.kf.map((k) => ({ ...k, t: roundT(k.t), x: r(k.x), y: r(k.y) })) }
: {}),
...(c.motionBlur ? { motionBlur: r(c.motionBlur) } : {}),
};
@@ -863,8 +866,8 @@ function describeOverlay(o: Overlay) {
kind: o.kind ?? "text",
...(o.groupId ? { groupId: o.groupId } : {}),
name: overlayName(o),
- start: r(o.start),
- end: r(o.end),
+ start: roundT(o.start),
+ end: roundT(o.end),
x: r(o.x),
y: r(o.y),
...(o.rotation ? { rotation: o.rotation } : {}),
@@ -873,7 +876,7 @@ function describeOverlay(o: Overlay) {
...(o.motionBlur ? { motionBlur: r(o.motionBlur) } : {}),
...(hasOverlayAnim(o.anim) ? { anim: o.anim } : {}),
...(o.kf?.length
- ? { keyframes: o.kf.map((k) => ({ ...k, t: r(k.t), x: r(k.x), y: r(k.y) })) }
+ ? { keyframes: o.kf.map((k) => ({ ...k, t: roundT(k.t), x: r(k.x), y: r(k.y) })) }
: {}),
...(o.mask ? { mask: o.mask } : {}),
...(o.lane ? { lane: o.lane } : {}),
@@ -908,6 +911,7 @@ function describeOverlay(o: Overlay) {
...(o.effect === "glitch" && o.glitch ? { glitch: o.glitch } : {}),
...(o.effect === "flash" && o.tone ? { tone: o.tone } : {}),
...(o.effect === "flash" && o.rate ? { rate: r(o.rate), rhythm: o.rhythm ?? "strobe" } : {}),
+ ...(o.effect === "flash" && o.fade ? { fade: o.fade } : {}),
};
}
return {
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index b8c9f777..a61efba2 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -4,6 +4,7 @@ import { readFolder, sharedFolderPage } from "@/cut/lib/folderBrowse";
import { parseFolderLink } from "@/cut/lib/folderReference";
import { cloudRequest } from "@/cut/lib/backend/cloud";
import { assetTypeOf, importFileToProject } from "@/cut/lib/media";
+import { saveSvgSticker } from "@/cut/lib/svgSticker";
import { linkIdForAsset, uploadLinkedFile, syncLinkedLibrary, isLinkedType } from "@/cut/lib/linkedLibrary/registry";
import { formatBytes } from "@/lib/bytes";
@@ -96,6 +97,8 @@ import {
penClosed,
type RemovalStroke,
type StrokeStyleId,
+ CYCLE_HOLD_MAX,
+ CYCLE_HOLD_MIN,
CYCLE_SCALE_MAX,
CYCLE_SCALE_MIN,
FONT_CYCLE_FACES_MAX,
@@ -109,23 +112,27 @@ import {
type GlitchKind,
FLASH_RATE_MAX,
FLASH_RATE_MIN,
+ FLASH_FADE_CHOICES,
+ FLASH_FADE_NONE,
FLASH_RHYTHMS,
+ loopPeriod,
FLASH_TONES,
TEXT_TEXTURES,
type CycleFace,
+ type FlashFade,
type FlashRhythm,
type TextWeight,
} from "@donkeycut/effects-kit";
import type { AiPanelToolName } from "@/cut/components/AiPanel.tools";
-import type { OverlayAnimationToolName } from "@/cut/components/AnimationTiles.tools";
+import { LOOP_SPEED_MAX, LOOP_SPEED_MIN, OVERLAY_KEY_POS_MAX, OVERLAY_KEY_POS_MIN, type OverlayAnimationToolName } from "@/cut/components/AnimationTiles.tools";
import type { AudioToolName } from "@/cut/components/AudioPanel.tools";
import type { CameraCardToolName } from "@/cut/components/CameraCardSection.tools";
import type { EditorToolName } from "@/cut/components/Editor.tools";
import type { EffectsToolName } from "@/cut/components/EffectsPanel.tools";
-import { SHAPE_KINDS, type ElementsToolName } from "@/cut/components/ElementsPanel.tools";
+import { SHAPE_KINDS, SVG_STICKER_MAX_CHARS, type ElementsToolName } from "@/cut/components/ElementsPanel.tools";
import type { VideoGenToolName } from "@/cut/components/GeneratePanel.tools";
import type { ImageGenToolName } from "@/cut/components/ImageGenPanel.tools";
-import type { InspectorToolName } from "@/cut/components/Inspector.tools";
+import { STICKER_W_MIN, type InspectorToolName } from "@/cut/components/Inspector.tools";
import type { GroupPanelToolName } from "@/cut/components/GroupPanel.tools";
import { CAMERA_SCALE_MAX, CAMERA_SCALE_MIN, CAMERA_WORLD_MAX, CAMERA_WORLD_MIN, ELEMENT_BLUR_MAX, SHUTTER_MAX, SHUTTER_MIN, TILT_MAX, isEaseId, upsertKey as upsertCameraKey, type CameraKey } from "@donkeycut/effects-kit";
import { cleanInks, LETTER_SPACING_MAX, LETTER_SPACING_MIN, PATTERN_KINDS, SHADOW_BLUR_MAX, SHADOW_OFFSET_MAX, STRIPE_GAP_MAX, STRIPE_LINE_MAX, STRIPE_LINE_MIN, STRIPES_DEFAULT, type PatternSpec, type ShadowSpec } from "@donkeycut/effects-kit";
@@ -138,7 +145,7 @@ import type { SceneToolName } from "@/cut/components/SceneCard.tools";
import type { SidePanelToolName } from "@/cut/components/SidePanel.tools";
import type { StockToolName } from "@/cut/components/StockPanels.tools";
import type { SubtitlesToolName } from "@/cut/components/SubtitlesPanel.tools";
-import type { TimelineToolName } from "@/cut/components/Timeline.tools";
+import { TEXT_SIZE_MAX, TEXT_SIZE_MIN, type TimelineToolName } from "@/cut/components/Timeline.tools";
import type { TopBarToolName } from "@/cut/components/TopBar.tools";
import type { TransitionsToolName } from "@/cut/components/TransitionsPanel.tools";
import { apiFetch, apiJson, getBackend } from "./backend";
@@ -232,7 +239,7 @@ import { measureLoudnessSliced, roundedLoudness, type LoudnessMeasure } from "./
import { framesAt, readMediaFileSize } from "./mediaRead";
import { renderStageFrame, storeStageStill } from "./stageFrame";
import { createRasterCanvas, decodeRasterImageUrl, rasterCanvasToDataUrl } from "./raster";
-import { buildAiContext, describeCameraCard, describeDoc, hiddenFromChat, placedAssetIds } from "./aiContext";
+import { buildAiContext, describeCameraCard, describeDoc, hiddenFromChat, placedAssetIds, roundT } from "./aiContext";
import { CARD_SIDES, newCard, normalizeCard, type CardSide } from "./cameraCard";
import { CAPTION_STYLES, captionEmphasis, cueSpot, EMPHASIS_SCALE_MAX, EMPHASIS_SCALE_MIN, laneCues, subtitleLaneCount } from "./subtitles";
import { cueEmphasis, emphasisIndicesOf, emphasizedWords } from "./captionEmphasis";
@@ -342,6 +349,15 @@ import { soundSourceOf, SPLIT_EDIT_MAX_S } from "./soundSource";
import { bindRecording, unbindRecording } from "./soundBind";
const round2 = (n: number) => Math.round(n * 100) / 100;
+/** A time written out to the microsecond — 1.016667 for 61/60 — sits a hair
+ * past its frame, so that frame still shows what came before. One within 10 µs
+ * of a frame at a common rate (the 1/600 s grid holds 24, 25, 30, 50 and 60
+ * fps) lands on it exactly. */
+const FRAME_GRID = 600;
+const onFrame = (t: number) => {
+ const n = Math.round(t * FRAME_GRID);
+ return Math.abs(t * FRAME_GRID - n) < FRAME_GRID * 1e-5 ? n / FRAME_GRID : t;
+};
/** A rotation input in degrees, kept to tenths: a screen in the shot can lean
* a fraction of a degree, and whatever is fitted onto it has to match. */
const degInput = (n: number) => Math.round(clamp(n, -180, 180) * 10) / 10;
@@ -451,6 +467,16 @@ async function offscreenClipFrameData(
): Promise<Uint8ClampedArray | null> {
const asset = s.assets.find((a) => a.id === clip.assetId);
if (!asset?.url) return null;
+ // A still on the track has no frames to seek: draw the image itself.
+ if (asset.type === "image") {
+ const img = await decodeRasterImageUrl(asset.url);
+ if (!img || !img.width) return null;
+ const c = createRasterCanvas(w, h);
+ const ctx = c.getContext("2d") as CanvasRenderingContext2D | null;
+ if (!ctx) return null;
+ ctx.drawImage(img.source, 0, 0, w, h);
+ return toBaseRendering(ctx.getImageData(0, 0, w, h).data, sourceProfileOf(asset));
+ }
const frame = await baseFrameAt(asset.url, (clip.in + clip.out) / 2, { width: w, height: h, fit: "fill" });
const ctx = frame?.canvas.getContext("2d") as CanvasRenderingContext2D | null | undefined;
return ctx ? ctx.getImageData(0, 0, w, h).data : null;
@@ -600,21 +626,32 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
if (sel?.kind !== "overlay") throw new ToolError("Could not create the shape.");
applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "shape"));
const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;
- return { id: o.id, shape, start: round2(o.start), end: round2(o.end) };
+ return { id: o.id, shape, start: roundT(o.start), end: roundT(o.end) };
},
- add_sticker: (s, input) => {
- const assetId = typeof input.asset_id === "string" && input.asset_id ? input.asset_id : undefined;
- if (!assetId) throw new ToolError("Pass asset_id.");
+ add_sticker: async (s, input) => {
+ const svg = typeof input.svg === "string" && input.svg.trim() ? input.svg : undefined;
+ let assetId = typeof input.asset_id === "string" && input.asset_id ? input.asset_id : undefined;
+ if (!assetId && !svg) throw new ToolError("Pass asset_id, or svg markup to draw the sticker from.");
+ if (svg && !assetId) {
+ if (!s.projectId) throw new ToolError("No project open.");
+ if (svg.length > SVG_STICKER_MAX_CHARS) throw new ToolError(`svg is over ${SVG_STICKER_MAX_CHARS} characters.`);
+ const name = typeof input.name === "string" && input.name.trim() ? input.name.trim() : "Drawn sticker";
+ const drawn = await saveSvgSticker(s.projectId, svg, name).catch((e: unknown) => {
+ throw new ToolError(e instanceof Error ? e.message : String(e));
+ });
+ assetId = drawn.id;
+ s = useEditor.getState();
+ }
const stickerAsset = s.assets.find((a) => a.id === assetId);
if (stickerAsset?.type !== "image") throw new ToolError(`No image asset with id ${assetId}.`);
if (isNum(input.start)) s.seek(input.start);
- s.addSticker({ assetId, ...(isLottieAsset(stickerAsset) ? { lottie: true } : {}), ...aimedLane(input) });
+ s.addSticker({ assetId: assetId!, ...(isLottieAsset(stickerAsset) ? { lottie: true } : {}), ...aimedLane(input) });
const sel = useEditor.getState().selection;
if (sel?.kind !== "overlay") throw new ToolError("Could not create the sticker.");
applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "sticker"));
const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;
- return { id: o.id, assetId, start: round2(o.start), end: round2(o.end) };
+ return { id: o.id, assetId, start: roundT(o.start), end: roundT(o.end) };
},
create_sticker: async (s, input) => {
@@ -629,7 +666,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
if (sel?.kind !== "overlay") throw new ToolError("Could not place the sticker.");
applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "sticker"));
const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;
- return { id: o.id, assetId: asset.id, start: round2(o.start), end: round2(o.end) };
+ return { id: o.id, assetId: asset.id, start: roundT(o.start), end: roundT(o.end) };
},
add_effect: (s, input) => {
@@ -654,7 +691,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
const settings = effectSettings(effect as EffectId, input);
if (Object.keys(settings).length) useEditor.getState().updateOverlay(sel.id, settings);
const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;
- return { id: o.id, effect, start: round2(o.start), end: round2(o.end) };
+ return { id: o.id, effect, start: roundT(o.start), end: roundT(o.end) };
},
set_overlay_animation: (s, input) => {
@@ -714,7 +751,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
};
}
const rawLoop = input.loop_style;
- const speed = isNum(input.loop_speed) ? clamp(input.loop_speed, 0.25, 4) : undefined;
+ const speed = isNum(input.loop_speed) ? clamp(input.loop_speed, LOOP_SPEED_MIN, LOOP_SPEED_MAX) : undefined;
if (typeof rawLoop === "string") {
if (rawLoop === "none") delete anim.loop;
else if (!(OVERLAY_LOOP_STYLE_IDS as string[]).includes(rawLoop))
@@ -764,7 +801,10 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
applyFontCycleInput(o, anim, input);
s.updateOverlay(o.id, { anim: hasOverlayAnim(anim) ? anim : undefined });
const next = useEditor.getState().overlays.find((x) => x.id === o.id)!;
- return { id: next.id, anim: next.anim ?? null };
+ // The loop's real cycle, so a rate set to match a measured one can be
+ // checked without reading it off frames.
+ const cycle = loopPeriod(next.anim);
+ return { id: next.id, anim: next.anim ?? null, ...(cycle ? { loop_cycle_seconds: Math.round(cycle * 1000) / 1000 } : {}) };
},
set_overlay_keyframes: (s, input) => {
@@ -781,15 +821,17 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
// Each key builds on the pose already at its time, so a key that only
// names `x` keeps whatever the element was doing otherwise.
s.pushHistory();
+ // replace starts the track over, in the same undo step as its keys.
+ if (input.replace === true) s.updateOverlaysTransient([{ id: o.id, patch: { kf: undefined } }]);
for (const k of raw as Record<string, unknown>[]) {
if (!isNum(k.t)) throw new ToolError("Every key needs a time `t`.");
- sent.add(round2(clamp(k.t, 0, dur)));
+ sent.add(roundT(onFrame(clamp(k.t, 0, dur))));
s.setOverlayKey(
o.id,
- clamp(k.t, 0, dur),
+ onFrame(clamp(k.t, 0, dur)),
{
- ...(isNum(k.x) ? { x: clampOverlayPos(k.x, o) } : {}),
- ...(isNum(k.y) ? { y: clampOverlayPos(k.y, o) } : {}),
+ ...(isNum(k.x) ? { x: o.groupId ? clampOverlayPos(k.x, o) : clamp(k.x, OVERLAY_KEY_POS_MIN, OVERLAY_KEY_POS_MAX) } : {}),
+ ...(isNum(k.y) ? { y: o.groupId ? clampOverlayPos(k.y, o) : clamp(k.y, OVERLAY_KEY_POS_MIN, OVERLAY_KEY_POS_MAX) } : {}),
...(isNum(k.scale) ? { scale: clamp(k.scale, 0.1, 4) } : {}),
...(isNum(k.scale_x) ? { scaleX: clamp(k.scale_x, 0, 4) } : {}),
...(isNum(k.scale_y) ? { scaleY: clamp(k.scale_y, 0, 4) } : {}),
@@ -807,12 +849,12 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
}
// A merge keeps keys this call never named; say which, so a key meant to
// go is not sent around again and again.
- const kept = raw.length ? (kf ?? []).map((k) => round2(k.t)).filter((t) => !sent.has(t)) : [];
+ const kept = raw.length && input.replace !== true ? (kf ?? []).map((k) => roundT(k.t)).filter((t) => !sent.has(t)) : [];
return {
id: o.id,
- keys: (kf ?? []).map((k) => ({ ...k, t: round2(k.t) })),
+ keys: (kf ?? []).map((k) => ({ ...k, t: roundT(k.t) })),
...(kept.length
- ? { kept, note: `Keys at ${kept.join(", ")}s were already on the track and stay; to drop them, clear the track with an empty keys list, then send the full list.` }
+ ? { kept, note: `Keys at ${kept.join(", ")}s were already on the track and stay; pass replace true with the full list to drop them.` }
: {}),
};
},
@@ -853,7 +895,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
return {
groupId,
start: round2(next.start),
- keys: next.keys.map((k) => ({ ...k, t: round2(k.t), x: round2(k.x), y: round2(k.y), scale: round2(k.scale) })),
+ keys: next.keys.map((k) => ({ ...k, t: roundT(k.t), x: round2(k.x), y: round2(k.y), scale: round2(k.scale) })),
motionBlur: next.motionBlur ?? null,
};
},
@@ -873,7 +915,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
s.pushHistory();
s.updateClipTransient(clip.id, { motionBlur });
}
- return { id: clip.id, keys: (kf ?? []).map((k) => ({ ...k, t: round2(k.t) })), motionBlur: motionBlur ?? null };
+ return { id: clip.id, keys: (kf ?? []).map((k) => ({ ...k, t: roundT(k.t) })), motionBlur: motionBlur ?? null };
}
if (!Array.isArray(raw)) throw new ToolError("keys must be a list.");
if (raw.length === 0) {
@@ -904,7 +946,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
if (motionBlur !== clip.motionBlur) {
useEditor.getState().updateClipTransient(clip.id, { motionBlur });
}
- return { id: clip.id, keys: (kf ?? []).map((k) => ({ ...k, t: round2(k.t) })), motionBlur: motionBlur ?? null };
+ return { id: clip.id, keys: (kf ?? []).map((k) => ({ ...k, t: roundT(k.t) })), motionBlur: motionBlur ?? null };
},
set_mask: (s, input) => {
@@ -1041,6 +1083,9 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
style = TRANSITION_STYLE_IDS.find((x) => x === requested);
if (!style) throw new ToolError(`Unknown style. Use one of: ${TRANSITION_STYLE_IDS.join(", ")}.`);
}
+ // Refused before anything lands, so a failed call changes nothing.
+ if (isNum(input.band) && input.seconds > 0 && !takesBand(style ?? clip.transitionStyle ?? "crossfade"))
+ throw new ToolError(`band is for the wipes only (${BAND_STYLES.join(", ")}).`);
s.setClipTransition(clip.id, input.seconds, style);
let after = useEditor.getState();
// The bar's own id rides the result so remove_transition can round-trip it.
@@ -1054,8 +1099,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
after.updateTransitionTransient(bar.id, { feather: feather > 0 ? feather : undefined });
after = useEditor.getState();
}
- if (bar && isNum(input.band)) {
- if (!takesBand(bar.style)) throw new ToolError(`band is for the wipes only (${BAND_STYLES.join(", ")}).`);
+ if (bar && isNum(input.band) && takesBand(bar.style)) {
const band = clampBand(input.band);
after.updateTransitionTransient(bar.id, { band: band > 0 ? band : undefined });
after = useEditor.getState();
@@ -1161,8 +1205,9 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
// Composited through the render path, so the frame carries what the
// finished file would carry — clips, transitions, effects, elements,
// captions — the preview's video layer alone leaves its DOM elements
- // floating above it.
- const total = totalDuration(s.clips);
+ // floating above it. The cut runs as long as anything on it does, so a
+ // cut of shapes and titles alone is reachable past 0.
+ const total = projectDuration(s);
const at = clamp(isNum(input.t) ? input.t : playheadAt(), 0, Math.max(0, total - 0.001));
const frame = frameOf(s.aspect);
const k = CAPTURE_LONG_SIDE / Math.max(frame.w, frame.h);
@@ -1210,7 +1255,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
throw new ToolError("Pass times: [seconds] — the moments of the cut to check, or [{at, source}] when the cut sits at a different second than the source does.");
if (moments.length > MAX_COMPARE)
throw new ToolError(`That is ${moments.length} moments — ${MAX_COMPARE} is the most one call reads. Check these, fix what is off, then call again for the rest.`);
- const total = totalDuration(s.clips);
+ const total = projectDuration(s);
const frame = frameOf(s.aspect);
const k = CAPTURE_LONG_SIDE / Math.max(frame.w, frame.h);
const size = { width: Math.round(frame.w * k), height: Math.round(frame.h * k) };
@@ -2613,7 +2658,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
knownFont(input.font);
}
if (isNum(input.start)) s.seek(input.start);
- s.addOverlay(aimedLane(input));
+ s.addOverlay({ ...aimedLane(input), seed: "defaults" });
const sel = useEditor.getState().selection;
if (sel?.kind !== "overlay") throw new ToolError("Could not create the title.");
applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "text"));
@@ -2669,7 +2714,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
});
}
useEditor.getState().seek(line.start);
- useEditor.getState().addOverlay({ lane });
+ useEditor.getState().addOverlay({ lane, seed: "defaults" });
const sel = useEditor.getState().selection;
if (sel?.kind !== "overlay") return;
applyOverlayPatchSettled(sel.id, {
@@ -2695,7 +2740,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
});
useEditor.getState().updateOverlay(sel.id, { anim: line.anim });
const o = useEditor.getState().overlays.find((x) => x.id === sel.id);
- if (o) made.push({ id: o.id, start: round2(o.start), end: round2(o.end), text: line.text });
+ if (o) made.push({ id: o.id, start: roundT(o.start), end: roundT(o.end), text: line.text });
});
const faces = [...new Set(composed.map((l) => l.font))];
const moves = [...new Set(composed.map((l) => l.move))].filter((m) => m !== "none");
@@ -3028,16 +3073,16 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
const ids = Array.isArray(input.ids) && input.ids.length ? input.ids.map(String) : null;
if (!ids && typeof input.id !== "string") throw new ToolError("Pass id or ids.");
const targets = (ids ?? [String(input.id)]).map((id) => requireItem(s.overlays, id, "overlay element"));
+ // An effect's own settings — its course, kind, tone, strobe — change
+ // in place, so the element keeps its id, lane and timing. Read them all
+ // first: a bad value refuses the call before anything is written.
+ const settings = new Map(targets.flatMap((o) => (isEffectOverlay(o) ? [[o.id, effectSettings(o.effect, input)] as const] : [])));
// One undo step for the whole write, however many elements it lands on.
s.pushHistory();
for (const o of targets) {
applyOverlayPatchSettled(o.id, overlayPatch(input, o.kind ?? "text", o));
- // An effect's own settings — its course, kind, tone, strobe — change
- // in place, so the element keeps its id, lane and timing.
- if (isEffectOverlay(o)) {
- const settings = effectSettings(o.effect, input);
- if (Object.keys(settings).length) useEditor.getState().updateOverlay(o.id, settings);
- }
+ const own = settings.get(o.id);
+ if (own && Object.keys(own).length) useEditor.getState().updateOverlaysTransient([{ id: o.id, patch: own }]);
}
const report = (id: string) => {
const next = useEditor.getState().overlays.find((x) => x.id === id)!;
@@ -3045,8 +3090,8 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
id: next.id,
kind: next.kind ?? "text",
...(isTextOverlay(next) ? { text: next.text, color: next.color, size: next.size } : {}),
- start: round2(next.start),
- end: round2(next.end),
+ start: roundT(next.start),
+ end: roundT(next.end),
};
};
return ids ? { overlayIds: targets.map((o) => o.id), updated: targets.map((o) => report(o.id)) } : report(targets[0].id);
@@ -4679,14 +4724,20 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
},
delete_asset: (s, input) => {
- // The sweep: every asset no timeline uses, open or parked.
- if (input.unused === true || Array.isArray(input.asset_ids)) {
+ // The sweep: every asset no timeline uses, open or parked — of the
+ // ones this chat can see: another thread's unplaced media and the
+ // project's fonts and LUTs stay.
+ const listed = Array.isArray(input.asset_ids) && input.asset_ids.length > 0;
+ if (input.unused === true || listed) {
let gone: MediaAsset[];
if (input.unused === true) {
const used = assetIdsOnAnyTimeline(s);
- gone = s.assets.filter((a) => !used.has(a.id));
+ const placed = placedAssetIds(s);
+ const chatId = chatOwner();
+ const spare = s.assets.filter((a) => !used.has(a.id) && !isLinkedAssetType(a.type));
+ gone = spare.filter((a) => !hiddenFromChat(a, chatId, placed));
} else {
- const want = (input.asset_ids as unknown[]).filter((v): v is string => typeof v === "string");
+ const want = [...new Set((input.asset_ids as unknown[]).filter((v): v is string => typeof v === "string"))];
gone = want.map((id) => requireItem(s.assets, id, "project asset"));
}
const uses = assetClipUses(s, new Set(gone.map((a) => a.id)));
@@ -5051,7 +5102,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
let links = input.links !== undefined ? strings(input.links, "links") : undefined;
if (input.add_links !== undefined) {
const base = links ?? s.notes.links.filter(Boolean);
- links = [...base, ...strings(input.add_links, "add_links").filter((l) => !base.includes(l))];
+ links = [...new Set([...base, ...strings(input.add_links, "add_links")])];
}
if (links) patch.links = links;
if (typeof input.text === "string") patch.text = input.text;
@@ -5083,7 +5134,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
const out: Record<string, number> = {};
if (input.fit) {
const el = document.querySelector<HTMLElement>(".tl-scroll");
- const dur = totalDuration(s.clips);
+ const dur = projectDuration(s);
if (el && dur > 0) {
s.setPxPerSec((el.clientWidth - 60) / dur);
el.scrollLeft = 0;
@@ -5410,14 +5461,15 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
clipId: typeof input.ref_clip_id === "string" ? input.ref_clip_id : undefined,
assetId: typeof input.ref_asset_id === "string" ? input.ref_asset_id : undefined,
});
- const grade = matchGrade(source, reference, isNum(input.strength) ? input.strength : 1);
- // The frames already agree: the clip's own grade stays as it is rather
- // than being wiped by a match that has nothing to say.
+ const strength = isNum(input.strength) ? input.strength : 1;
+ const grade = matchGrade(source, reference, strength);
+ // The frames already agree, or strength 0 asked for none of the match:
+ // the clip's own grade stays as it is.
if (!grade)
return {
id: clip.id,
grade: clip.grade ?? "neutral",
- note: "The footage already matches the reference — nothing changed.",
+ note: strength <= 0 ? "strength 0 takes none of the match — nothing changed." : "The footage already matches the reference — nothing changed.",
};
// The computed curves carry the whole look, so the match replaces the
// clip's grade — a preset left underneath would double the move.
@@ -5580,6 +5632,8 @@ export const MEDIA_RUNTIME_TOOLS: ReadonlySet<string> = new Set([
"sync_lyrics",
"align_to_audio",
"stock_add",
+ "read_color_stats",
+ "match_color_grade",
]);
/** Tools that need the editor page itself: motion tracking runs MediaPipe's
@@ -5837,7 +5891,7 @@ function textSequenceLines(
start: isNum(l.start) ? Math.max(0, l.start) : NaN,
end: isNum(l.end) ? l.end : NaN,
...(typeof l.color === "string" ? { color: l.color } : {}),
- ...(isNum(l.size) ? { size: clamp(Math.round(l.size), 16, 320) } : {}),
+ ...(isNum(l.size) ? { size: clamp(Math.round(l.size), TEXT_SIZE_MIN, TEXT_SIZE_MAX) } : {}),
...(l.emphasis === "whisper" || l.emphasis === "hero" || l.emphasis === "normal"
? { emphasis: l.emphasis }
: {}),
@@ -6495,16 +6549,15 @@ function applyFontCycleInput(
// Timing: held inside the element, with the rate in its supported range.
const dur = Math.max(0.1, o.end - o.start);
- const at = clamp(isNum(input.font_cycle_at) ? input.font_cycle_at : (anim.fonts?.at ?? 0), 0, dur - 0.05);
- const seconds = clamp(
- isNum(input.font_cycle_seconds) ? input.font_cycle_seconds : (anim.fonts?.seconds ?? dur - at),
- 0.05,
- dur - at
+ const at = onFrame(clamp(isNum(input.font_cycle_at) ? input.font_cycle_at : (anim.fonts?.at ?? 0), 0, dur - 0.05));
+ const seconds = onFrame(
+ clamp(isNum(input.font_cycle_seconds) ? input.font_cycle_seconds : (anim.fonts?.seconds ?? dur - at), 0.05, dur - at)
);
const rate = isNum(input.font_cycle_rate)
? clamp(input.font_cycle_rate, FONT_CYCLE_RATE_MIN, FONT_CYCLE_RATE_MAX)
: (anim.fonts?.rate ?? FONT_CYCLE_RATE);
- const round = (v: number) => Math.round(v * 1000) / 1000;
+ // To the microsecond, so a run that starts on a frame stays on it.
+ const round = (v: number) => onFrame(Math.round(v * 1e6) / 1e6);
anim.fonts = { faces, at: round(at), seconds: round(seconds), rate };
}
@@ -6528,6 +6581,8 @@ function cycleFaceOf(raw: unknown): CycleFace {
...(isTextWeight(f.weight) ? { weight: f.weight } : {}),
...(isNum(f.scale) && f.scale !== 1 ? { scale: clamp(f.scale, CYCLE_SCALE_MIN, CYCLE_SCALE_MAX) } : {}),
...(isNum(f.tracking) ? { tracking: clamp(f.tracking, -0.05, 0.5) } : {}),
+ ...(typeof f.italic === "boolean" ? { italic: f.italic } : {}),
+ ...(isNum(f.hold) && f.hold > 0 ? { hold: onFrame(clamp(f.hold, CYCLE_HOLD_MIN, CYCLE_HOLD_MAX)) } : {}),
};
}
@@ -6952,8 +7007,8 @@ function patternInput(
/**
* The settings an effect of this kind takes from a tool call: a light leak's
- * course, a glitch's pinned kind, a flash's tone, strobe rate and rhythm.
- * Only the keys the call names come back, each as the value to store
+ * course, a glitch's pinned kind, a flash's tone, strobe rate, rhythm and
+ * fade. Only the keys the call names come back, each as the value to store
* (undefined clears it back to the default); a setting the effect doesn't
* take is skipped. Shared by add_effect and update_overlay.
*/
@@ -6982,6 +7037,13 @@ function effectSettings(effect: EffectId, input: Record<string, unknown>): Parti
}
if (isNum(input.rate)) patch.rate = input.rate > 0 ? clamp(input.rate, FLASH_RATE_MIN, FLASH_RATE_MAX) : undefined;
if (input.rhythm !== undefined) patch.rhythm = flashRhythm(input.rhythm);
+ // A fade of none is the pop again, and stores as absence.
+ if (input.fade !== undefined) {
+ if (!(FLASH_FADE_CHOICES as readonly unknown[]).includes(input.fade)) {
+ throw new ToolError(`fade is one of ${FLASH_FADE_CHOICES.join(", ")}.`);
+ }
+ patch.fade = input.fade === FLASH_FADE_NONE ? undefined : (input.fade as FlashFade);
+ }
return patch;
}
@@ -6991,8 +7053,8 @@ function overlayPatch(
place?: { groupId?: string; shadow?: boolean | ShadowSpec; pattern?: PatternSpec }
) {
const patch: Record<string, unknown> = {};
- if (isNum(input.start)) patch.start = Math.max(0, input.start);
- if (isNum(input.end)) patch.end = input.end;
+ if (isNum(input.start)) patch.start = onFrame(Math.max(0, input.start));
+ if (isNum(input.end)) patch.end = onFrame(input.end);
if (isNum(input.lane)) patch.lane = Math.max(0, Math.round(input.lane));
if (isNum(input.x)) patch.x = clampOverlayPos(input.x, place);
if (isNum(input.y)) patch.y = clampOverlayPos(input.y, place);
@@ -7012,7 +7074,7 @@ function overlayPatch(
// double-escape multi-line titles.
if (typeof input.text === "string" && input.text.trim())
patch.text = input.text.replace(/\\n/g, "\n");
- if (isNum(input.size)) patch.size = clamp(Math.round(input.size), 16, 320);
+ if (isNum(input.size)) patch.size = clamp(Math.round(input.size), TEXT_SIZE_MIN, TEXT_SIZE_MAX);
if (typeof input.color === "string") patch.color = input.color;
// Only ids the registry knows: an unknown one is refused, since it would
// render the default face and leave the Inspector's font menu blank.
@@ -7090,9 +7152,9 @@ function overlayPatch(
return patch;
}
- if (isNum(input.w)) patch.w = clamp(input.w, 0.02, 1.5);
+ if (isNum(input.w)) patch.w = clamp(input.w, STICKER_W_MIN, 1.5);
// A sticker's height is its own once set; 0 hands it back to the source's
// aspect.
- if (isNum(input.h)) patch.h = input.h > 0 ? clamp(input.h, 0.02, 1.5) : undefined;
+ if (isNum(input.h)) patch.h = input.h > 0 ? clamp(input.h, STICKER_W_MIN, 1.5) : undefined;
return patch;
}
diff --git a/site/src/cut/lib/chatToolEdges.test.ts b/site/src/cut/lib/chatToolEdges.test.ts
new file mode 100644
index 00000000..56f30c35
--- /dev/null
+++ b/site/src/cut/lib/chatToolEdges.test.ts
@@ -0,0 +1,86 @@
+import { beforeEach, describe, expect, test } from "bun:test";
+import { runAiTool } from "./aiTools";
+import { useEditor } from "./store";
+import { emptySubtitles, type EffectOverlay, type MediaAsset } from "./types";
+
+/** Edges a review of the template run's chat tools turned up: a write that
+ * fails must leave nothing half done, one call is one undo step, and a sweep
+ * takes only what this chat can see. */
+
+const fx = (id: string): EffectOverlay =>
+ ({ id, kind: "effect", effect: "lightleak", amount: 0.5, start: 0, end: 1, x: 0.5, y: 0.5, lane: 0 }) as unknown as EffectOverlay;
+const asset = (id: string, extra: Partial<MediaAsset> = {}): MediaAsset =>
+ ({ id, fileName: `${id}.mp4`, name: id, type: "video", duration: 5, url: "", ...extra }) as MediaAsset;
+
+beforeEach(() => {
+ useEditor.setState({
+ projectId: null,
+ aspect: "16:9",
+ assets: [],
+ clips: [],
+ audioClips: [],
+ overlays: [fx("a"), fx("b")],
+ transitions: [],
+ subtitles: emptySubtitles(),
+ timelines: {},
+ notes: { text: "", publishedAt: "", links: [] },
+ });
+});
+
+const overlay = (id: string) => useEditor.getState().overlays.find((o) => o.id === id) as EffectOverlay;
+
+describe("update_overlay on effects", () => {
+ test("a write across several effects undoes in one step", async () => {
+ await runAiTool("update_overlay", { ids: ["a", "b"], amount: 1, leak: "char" });
+ expect(overlay("a").leak).toBe("char");
+ useEditor.getState().undo();
+ expect(overlay("a")).toMatchObject({ amount: 0.5 });
+ expect(overlay("b")).toMatchObject({ amount: 0.5 });
+ expect(overlay("a").leak).toBeUndefined();
+ expect(overlay("b").leak).toBeUndefined();
+ });
+
+ test("a bad setting is refused before anything is written", async () => {
+ await expect(runAiTool("update_overlay", { ids: ["a", "b"], amount: 1, leak: "flare" })).rejects.toThrow();
+ expect(overlay("a").amount).toBe(0.5);
+ expect(overlay("b").amount).toBe(0.5);
+ });
+});
+
+describe("delete_asset", () => {
+ test("the unused sweep leaves another chat's unplaced media and the project's fonts alone", async () => {
+ useEditor.setState({
+ overlays: [],
+ assets: [
+ asset("spare"),
+ asset("theirs", { origin: "chat", chatId: "other-thread" } as Partial<MediaAsset>),
+ asset("font", { type: "font" } as unknown as Partial<MediaAsset>),
+ ],
+ });
+ const out = (await runAiTool("delete_asset", { unused: true })) as { removed: number; names: string[] };
+ expect(out).toMatchObject({ removed: 1, names: ["spare"] });
+ expect(useEditor.getState().assets.map((a) => a.id)).toEqual(["theirs", "font"]);
+ });
+
+ test("an empty asset_ids list falls back to asset_id, and repeated ids count once", async () => {
+ useEditor.setState({ overlays: [], assets: [asset("c"), asset("d")] });
+ await runAiTool("delete_asset", { asset_id: "c", asset_ids: [] });
+ expect(useEditor.getState().assets.map((a) => a.id)).toEqual(["d"]);
+ const out = (await runAiTool("delete_asset", { asset_ids: ["d", "d"] })) as { removed: number };
+ expect(out.removed).toBe(1);
+ });
+});
+
+test("set_project_notes skips a link repeated within the same call", async () => {
+ const out = (await runAiTool("set_project_notes", { add_links: ["https://x.test", "https://x.test"] })) as { links: string[] };
+ expect(out.links).toEqual(["https://x.test"]);
+});
+
+test("set_transition refuses a band on a crossfade before it writes the crossfade", async () => {
+ useEditor.setState({ overlays: [], assets: [asset("v")] });
+ await runAiTool("add_clip", { asset_id: "v" });
+ await runAiTool("add_clip", { asset_id: "v" });
+ const first = useEditor.getState().clips[0];
+ await expect(runAiTool("set_transition", { clipId: first.id, seconds: 0.4, style: "crossfade", band: 0.3 })).rejects.toThrow();
+ expect(useEditor.getState().clips[0].transition ?? 0).toBe(0);
+});
diff --git a/site/src/cut/lib/colorOffscreen.test.ts b/site/src/cut/lib/colorOffscreen.test.ts
index a4993d7b..512d5657 100644
--- a/site/src/cut/lib/colorOffscreen.test.ts
+++ b/site/src/cut/lib/colorOffscreen.test.ts
@@ -84,3 +84,9 @@ test("match_color_grade strength takes the match part of the way", async () => {
await runAiTool("match_color_grade", { clipId: dark.id, ref_clip_id: mid.id, strength: 0.5 });
expect(curveAt20()).toBe(60);
});
+
+test("strength 0 says it took none of the match, not that the footage already matches", async () => {
+ const clip = useEditor.getState().clips[0];
+ const out = (await runAiTool("match_color_grade", { clipId: clip.id, ref_clip_id: clip.id, strength: 0 })) as { note?: string };
+ expect(out.note).toContain("strength 0");
+});
diff --git a/site/src/cut/lib/compareToSource.test.ts b/site/src/cut/lib/compareToSource.test.ts
index 76efd5b2..441712d8 100644
--- a/site/src/cut/lib/compareToSource.test.ts
+++ b/site/src/cut/lib/compareToSource.test.ts
@@ -125,3 +125,23 @@ test("the source is read in one pass, in play order, at a height that keeps its
// frame — and mediabunny's sink refuses the pair outright.
expect(Object.keys(reads[0].size as object)).toEqual(["height"]);
});
+
+test("a cut built only from elements is checked at the moments asked for", async () => {
+ // No track-0 clip: the cut's length is its elements' and its soundtrack's.
+ useEditor.setState({ clips: [] });
+ // A still element is drawn once and reused as a bitmap; the stub surface
+ // has no pixels to hand over. Another file's stub may be installed already.
+ const was = globalThis.createImageBitmap;
+ globalThis.createImageBitmap = (async () => ({ width: 1, height: 1, close() {} })) as never;
+ try {
+ await runAiTool("add_shape", { shape: "rect", start: 0, end: 3, w: 1, h: 1, fill: "#C53CD4" });
+ const frame = (await runAiTool("capture_frame", { t: 1.9 })) as { at: number };
+ expect(frame.at).toBeCloseTo(1.9, 3);
+ const out = (await runAiTool("compare_to_source", { asset_id: "ref", times: [2.5] })) as {
+ checked: { at: number }[];
+ };
+ expect(out.checked[0].at).toBeCloseTo(2.5, 3);
+ } finally {
+ globalThis.createImageBitmap = was;
+ }
+});
diff --git a/site/src/cut/lib/effectUpdateTool.test.ts b/site/src/cut/lib/effectUpdateTool.test.ts
index 2120ef80..3c8002a5 100644
--- a/site/src/cut/lib/effectUpdateTool.test.ts
+++ b/site/src/cut/lib/effectUpdateTool.test.ts
@@ -50,6 +50,15 @@ describe("update_overlay on an effect", () => {
expect(overlay(glitch)).toMatchObject({ glitch: "rgb" });
});
+ test("a flash's fade comes off again with none, back to the pop", async () => {
+ const { id } = (await runAiTool("add_effect", { effect: "flash", start: 2, end: 3, fade: "to" })) as { id: string };
+ expect(overlay(id)).toMatchObject({ fade: "to" });
+ await runAiTool("update_overlay", { id, fade: "none" });
+ expect((overlay(id) as { fade?: string }).fade).toBeUndefined();
+ const props = INSPECTOR_TOOLS.find((t) => t.name === "update_overlay")!.inputSchema.properties as Record<string, { enum?: string[] }>;
+ expect(props.fade.enum).toContain("none");
+ });
+
test("a setting the effect doesn't take is skipped, like any field a kind lacks", async () => {
const { id } = (await runAiTool("add_effect", { effect: "flash", start: 2, end: 3 })) as { id: string };
await runAiTool("update_overlay", { id, leak: "burn" });
@@ -58,6 +67,6 @@ describe("update_overlay on an effect", () => {
test("the tool's schema offers the effect settings", () => {
const props = INSPECTOR_TOOLS.find((t) => t.name === "update_overlay")!.inputSchema.properties as Record<string, unknown>;
- for (const k of ["amount", "leak", "glitch", "tone", "rate", "rhythm"]) expect(Object.keys(props)).toContain(k);
+ for (const k of ["amount", "leak", "glitch", "tone", "rate", "rhythm", "fade"]) expect(Object.keys(props)).toContain(k);
});
});
diff --git a/site/src/cut/lib/elementTimes.test.ts b/site/src/cut/lib/elementTimes.test.ts
new file mode 100644
index 00000000..471fb17c
--- /dev/null
+++ b/site/src/cut/lib/elementTimes.test.ts
@@ -0,0 +1,88 @@
+import { beforeEach, expect, test } from "bun:test";
+import { buildAiContext } from "./aiContext";
+import { runAiTool } from "./aiTools";
+import { useEditor } from "./store";
+import { emptySubtitles } from "./types";
+
+// A 60 fps cut changes every 0.0167 s, so the chat reads an element's times to
+// the millisecond: at two decimals 0.317 reads 0.32 and it can't confirm the
+// frame it placed.
+
+beforeEach(() =>
+ useEditor.setState({
+ projectId: "p1",
+ aspect: "16:9",
+ assets: [],
+ clips: [],
+ audioClips: [],
+ overlays: [],
+ subtitles: emptySubtitles(),
+ background: "#000000",
+ })
+);
+
+test("a shape's times come back and read to the millisecond", async () => {
+ const out = (await runAiTool("add_shape", { shape: "rect", start: 0.317, end: 0.4, lane: 1 })) as { start: number; end: number };
+ expect([out.start, out.end]).toEqual([0.317, 0.4]);
+ const ctx = buildAiContext() as unknown as { overlays: { start: number; end: number }[] };
+ expect([ctx.overlays[0].start, ctx.overlays[0].end]).toEqual([0.317, 0.4]);
+});
+
+test("a retime reads back to the millisecond", async () => {
+ const { id } = (await runAiTool("add_shape", { shape: "rect", start: 1, end: 2, lane: 1 })) as { id: string };
+ const out = (await runAiTool("update_overlay", { id, start: 1.016667, end: 1.233333 })) as { start: number; end: number };
+ expect([out.start, out.end]).toEqual([1.017, 1.233]);
+});
+
+test("a card shorter than 0.2 s retimes against its neighbour without sliding", async () => {
+ const a = (await runAiTool("add_shape", { shape: "rect", start: 0.317, end: 0.4, lane: 1 })) as { id: string };
+ const b = (await runAiTool("add_shape", { shape: "rect", start: 0.4, end: 0.567, lane: 1 })) as { id: string };
+ const out = (await runAiTool("update_overlay", { id: a.id, start: 0.316667, end: 0.4 })) as { start: number; end: number };
+ expect([out.start, out.end]).toEqual([0.317, 0.4]);
+ const after = useEditor.getState().overlays.find((o) => o.id === b.id)!;
+ expect([after.start, after.end]).toEqual([0.4, 0.567]);
+});
+
+test("key times read back to the millisecond", async () => {
+ const { id } = (await runAiTool("add_shape", { shape: "rect", start: 0, end: 2, lane: 1 })) as { id: string };
+ const out = (await runAiTool("set_overlay_keyframes", { id, keys: [{ t: 0.516667, scale: 1 }, { t: 0.666667, scale: 2 }] })) as { keys: { t: number }[] };
+ expect(out.keys.map((k) => k.t)).toEqual([0.517, 0.667]);
+ const ctx = buildAiContext() as unknown as { overlays: { keyframes?: { t: number }[] }[] };
+ expect(ctx.overlays[0].keyframes?.map((k) => k.t)).toEqual([0.517, 0.667]);
+});
+
+test("an undo inside a chat turn steps back one edit at a time, never into the turn before", async () => {
+ const s = () => useEditor.getState();
+ const { id } = (await runAiTool("add_shape", { shape: "rect", start: 0, end: 1, lane: 1, fill: "#111111" })) as { id: string };
+ // The turn before: one committed step.
+ s().beginHistoryBatch();
+ await runAiTool("update_overlay", { id, fill: "#222222" });
+ s().endHistoryBatch();
+ // This turn tries two edits and takes each back.
+ s().beginHistoryBatch();
+ await runAiTool("update_overlay", { id, fill: "#333333" });
+ await runAiTool("undo", {});
+ const fill = () => (s().overlays.find((o) => o.id === id) as { fill?: string }).fill;
+ expect(fill()).toBe("#222222");
+ await runAiTool("update_overlay", { id, fill: "#444444" });
+ await runAiTool("undo", {});
+ expect(fill()).toBe("#222222");
+ s().endHistoryBatch();
+});
+
+test("a time written to the microsecond lands on its frame", async () => {
+ // 1.016667 is 61/60 to six places, but sits a hair past frame 61, so that
+ // frame would still show what came before.
+ const { id } = (await runAiTool("add_shape", { shape: "rect", start: 1.016667, end: 1.233333, lane: 1 })) as { id: string };
+ const o = () => useEditor.getState().overlays.find((x) => x.id === id)!;
+ expect(o().start).toBe(61 / 60);
+ expect(o().end).toBe(74 / 60);
+ // A time meant to the millisecond stays as written.
+ await runAiTool("update_overlay", { id, start: 1.017, end: 1.234 });
+ expect([o().start, o().end]).toEqual([1.017, 1.234]);
+ const { id: title } = (await runAiTool("add_title", { text: "GO", start: 2, end: 3, lane: 2 })) as { id: string };
+ await runAiTool("set_overlay_animation", { id: title, font_cycle: [{ font: "impact", hold: 0.216667 }, { font: "serif" }], font_cycle_at: 0.083333, font_cycle_seconds: 0.5 });
+ const fonts = (useEditor.getState().overlays.find((x) => x.id === title) as { anim?: { fonts?: { at: number; faces: { hold?: number }[] } } }).anim?.fonts;
+ expect(fonts?.at).toBe(5 / 60);
+ expect(fonts?.faces[0].hold).toBe(13 / 60);
+});
diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.ts
index a7aabec1..eef0677a 100644
--- a/site/src/cut/lib/exportClient.ts
+++ b/site/src/cut/lib/exportClient.ts
@@ -31,7 +31,7 @@ import { drawBlock } from "./blockSource";
import { createRasterCanvas, rasterCanvasToPng } from "./raster";
import { clipLen, clipSpeed, getClipSpans, MICRO_GAP_S, openedTimeline, overlayLayers, projectDuration, spanSequence, useEditor } from "./store";
import { captionStyle, cueOverlay, cueWordFrames, laneCues, laneHidden, subtitleLaneCount, trackPos } from "./subtitles";
-import { drawStreak, elementLook, isMaskAnimated, isOverlayAnimated, matteLumaToAlpha, normalizeGrade, paintMaskLuma, paintStrokeInk, retimeOf, type FlashRhythm, type FlashTone, type GlitchKind, type LeakCourse, type Mask, type SpeedNode } from "@donkeycut/effects-kit";
+import { drawStreak, elementLook, isMaskAnimated, isOverlayAnimated, matteLumaToAlpha, normalizeGrade, paintMaskLuma, paintStrokeInk, retimeOf, type FlashFade, type FlashRhythm, type FlashTone, type GlitchKind, type LeakCourse, type Mask, type SpeedNode } from "@donkeycut/effects-kit";
import { renderElementFrames, renderElementPng, renderStillPng } from "./textRender";
import { CLIP_MIN_SECONDS, clipCovers, clipFrameAt, clipKeyed, clipPosed, clipPoseAt, clipZoom, contentRect, frameOf, isStickerOverlay, isTextOverlay, laneOf, overlayAnimStyle, projectBackground, rectOf, regionPx, removalActive, shadowInk, subjectMasked, parkedTimeline } from "./types";
import { liveReader } from "./liveReader";
@@ -1395,6 +1395,7 @@ export async function buildExportPayload(
tone: (o as { tone?: FlashTone }).tone,
rate: (o as { rate?: number }).rate,
rhythm: (o as { rhythm?: FlashRhythm }).rhythm,
+ fade: (o as { fade?: FlashFade }).fade,
lane: laneOf(o),
start: o.start,
end: Math.min(o.end, duration),
diff --git a/site/src/cut/lib/fontCycleTool.test.ts b/site/src/cut/lib/fontCycleTool.test.ts
index 29759425..3fd8146c 100644
--- a/site/src/cut/lib/fontCycleTool.test.ts
+++ b/site/src/cut/lib/fontCycleTool.test.ts
@@ -36,6 +36,19 @@ const failure = async (args: Record<string, unknown>) => {
describe("set_overlay_animation font cycle", () => {
beforeEach(reset);
+ test("each face can hold its own time and set italic", async () => {
+ const o = await aTitle();
+ await runAiTool("set_overlay_animation", {
+ id: o.id,
+ font_cycle: [{ font: "impact", hold: 0.25 }, { font: "serif", italic: true, hold: 99 }, { font: "mono", hold: 0 }],
+ });
+ expect(titles()[0].anim?.fonts?.faces).toEqual([
+ { font: "impact", hold: 0.25 },
+ { font: "serif", italic: true, hold: 10 },
+ { font: "mono" },
+ ]);
+ });
+
test("a new cycle runs the title's length at the default rate", async () => {
const o = await aTitle();
await runAiTool("set_overlay_animation", {
diff --git a/site/src/cut/lib/keyframeKept.test.ts b/site/src/cut/lib/keyframeKept.test.ts
index ec34ecce..2899863b 100644
--- a/site/src/cut/lib/keyframeKept.test.ts
+++ b/site/src/cut/lib/keyframeKept.test.ts
@@ -20,13 +20,13 @@ test("keys the call left in place come back named, with the way to drop them", a
note?: string;
};
expect(out.kept).toEqual([1]);
- expect(out.note).toContain("empty keys list");
+ expect(out.note).toContain("replace");
});
-test("a call that names every key, or clears the track, reports nothing kept", async () => {
+test("a call that names every key, or replaces the track, reports nothing kept", async () => {
const all = (await runAiTool("set_overlay_keyframes", { id: "t1", keys: [{ t: 0, y: 0.56 }, { t: 1, y: 0.56 }, { t: 1.5, y: 0.56 }] })) as { kept?: number[] };
expect(all.kept).toBeUndefined();
- const cleared = (await runAiTool("set_overlay_keyframes", { id: "t1", keys: [] })) as { kept?: number[]; keys: unknown[] };
- expect(cleared.kept).toBeUndefined();
- expect(cleared.keys).toHaveLength(0);
+ const rep = (await runAiTool("set_overlay_keyframes", { id: "t1", replace: true, keys: [{ t: 0, y: 0.56 }] })) as { kept?: number[]; keys: unknown[] };
+ expect(rep.kept).toBeUndefined();
+ expect(rep.keys).toHaveLength(1);
});
diff --git a/site/src/cut/lib/store.test.ts b/site/src/cut/lib/store.test.ts
index b91ae159..d5852dcb 100644
--- a/site/src/cut/lib/store.test.ts
+++ b/site/src/cut/lib/store.test.ts
@@ -838,6 +838,42 @@ describe("title lanes", () => {
});
describe("keyframes", () => {
+ test("the chat keys an element in from beyond the frame while its rest stays on it", async () => {
+ const t1 = title({ start: 0, end: 4 });
+ useEditor.setState({ overlays: [t1] });
+ await runAiTool("set_overlay_keyframes", { id: t1.id, keys: [{ t: 0, x: -0.2, y: 1.1 }, { t: 1, x: 0.5, y: 0.5 }, { t: 2, y: 9 }] });
+ expect(overlayById(t1.id).kf!.map((k) => [k.x, k.y])).toEqual([[-0.2, 1.1], [0.5, 0.5], [0.5, 1.5]]);
+ await runAiTool("update_overlay", { id: t1.id, y: 1.1 });
+ expect(overlayById(t1.id).y).toBeCloseTo(0.98);
+ });
+
+ test("the chat's keys merge into the track unless it asks to replace it", async () => {
+ const t1 = title({ start: 0, end: 4 });
+ useEditor.setState({ overlays: [t1] });
+ await runAiTool("set_overlay_keyframes", { id: t1.id, keys: [{ t: 0, x: 0.2 }, { t: 3, x: 0.8 }] });
+ await runAiTool("set_overlay_keyframes", { id: t1.id, keys: [{ t: 1, x: 0.4 }] });
+ expect(overlayById(t1.id).kf!.map((k) => k.t)).toEqual([0, 1, 3]);
+ const out = await runAiTool("set_overlay_keyframes", { id: t1.id, replace: true, keys: [{ t: 0.5, x: 0.3 }, { t: 2, x: 0.6 }] });
+ expect(overlayById(t1.id).kf!.map((k) => [k.t, k.x])).toEqual([[0.5, 0.3], [2, 0.6]]);
+ expect((out as { keys: { t: number }[] }).keys.map((k) => k.t)).toEqual([0.5, 2]);
+ });
+
+ test("a loop's rate comes back as the seconds one cycle takes", async () => {
+ const t1 = title({ start: 0, end: 4 });
+ useEditor.setState({ overlays: [t1] });
+ const out = (await runAiTool("set_overlay_animation", { id: t1.id, loop_style: "spin", loop_speed: 5 })) as { loop_cycle_seconds?: number };
+ expect(out.loop_cycle_seconds).toBeCloseTo(0.8, 5);
+ });
+
+ test("a sticker can be drawn as small as a mouse pointer", async () => {
+ const st = title({ kind: "sticker", assetId: "img", w: 0.2 } as unknown as Partial<TextOverlay>);
+ useEditor.setState({ overlays: [st] });
+ await runAiTool("update_overlay", { id: st.id, w: 0.012 });
+ expect((overlayById(st.id) as unknown as { w: number }).w).toBeCloseTo(0.012, 4);
+ await runAiTool("update_overlay", { id: st.id, w: 0.001 });
+ expect((overlayById(st.id) as unknown as { w: number }).w).toBeCloseTo(0.005, 4);
+ });
+
test("a key captures the pose and the track drops when the last one goes", () => {
const t1 = title({ start: 2, end: 6, x: 0.4, rotation: 30, opacity: 0.5 });
useEditor.setState({ overlays: [t1] });
diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.ts
index 2da98220..0f0e5fa7 100644
--- a/site/src/cut/lib/store.ts
+++ b/site/src/cut/lib/store.ts
@@ -419,6 +419,10 @@ export type SubtitleStatus = "idle" | "running" | "ready" | "empty" | "error";
export type SaveState = "saved" | "dirty" | "saving" | "error";
+/** Where a new title's look starts: the last title the person styled, or the
+ * built-in defaults. */
+export type TitleSeed = "remembered" | "defaults";
+
export interface EditorState {
projectId: string | null;
projectName: string;
@@ -677,7 +681,7 @@ export interface EditorState {
* undo like any other edit. */
releaseGenClips: () => void;
/** Place a title element; a drop (or the assistant) passes where it landed. */
- addOverlay: (aim?: { at?: number; lane?: number }) => void;
+ addOverlay: (aim?: { at?: number; lane?: number; seed?: TitleSeed }) => void;
/** Add a vector shape element on the title lanes at the playhead. */
/** Place a shape element; a drop passes where it landed. */
addShape: (shape: ShapeKind, aim?: { at?: number; lane?: number }) => void;
@@ -1217,7 +1221,9 @@ function settleOverlayFootprint(id: string, patch: OverlayPatch) {
const others = st.overlays
.filter((o) => o.id !== id && (o.lane ?? 0) === (self.lane ?? 0))
.sort((a, b) => a.start - b.start);
- const len = Math.max(0.2, self.end - self.start);
+ // Its own length: a card cut on the beat can run a few frames, and a floor
+ // here would read it as overlapping the next card and slide it away.
+ const len = Math.max(1e-3, self.end - self.start);
if (moved) {
const at = nextFreeStart(
others.map((o) => ({ start: o.start, end: o.end })),
@@ -1797,6 +1803,13 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
}
};
+ /** An undo inside a batch spends its checkpoint, so the rest of the batch
+ * takes a fresh one from where the undo left the doc — else the next undo in
+ * the same chat turn would step back into the turn before. */
+ const rearmBatch = () => {
+ if (batchDepth > 0) pending = { snap: snapshot(), seq: docSeq };
+ };
+
const push = () => {
// Inside a batch a single checkpoint (taken at beginHistoryBatch) already
// covers every edit, so individual pushes are no-ops.
@@ -3052,8 +3065,10 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
addOverlay: (aim) => {
// Seed the visual style from the last-used title so repeated titles in a
- // project share one look; fall back to the built-in defaults.
- const remembered = readTextStyle();
+ // project share one look; fall back to the built-in defaults. The
+ // assistant asks for the defaults: its tools state them, and a look
+ // remembered from another title would ride along unseen.
+ const remembered = aim?.seed === "defaults" ? {} : readTextStyle();
addElement("text", (start, end, lane) => ({
id: uid(),
kind: "text",
@@ -5276,6 +5291,7 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
if (!prev) return false;
future.push(snapshot());
restoreDoc(prev);
+ rearmBatch();
return true;
},
@@ -5286,6 +5302,7 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
history.push(snapshot());
if (history.length > HISTORY_CAP) history.shift();
restoreDoc(next);
+ rearmBatch();
return true;
},
};
diff --git a/site/src/cut/lib/stylePresets.test.ts b/site/src/cut/lib/stylePresets.test.ts
new file mode 100644
index 00000000..548c9ce8
--- /dev/null
+++ b/site/src/cut/lib/stylePresets.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, test } from "bun:test";
+import { pickTextStyle } from "@donkeycut/effects-kit";
+import { styleMatches } from "./stylePresets";
+import type { TextOverlay } from "./types";
+
+// The inspector rings the saved style a title wears and offers to update one
+// once the title's look moves off every saved style.
+
+const title = (extra: Partial<Pick<TextOverlay, "text" | "x" | "y" | "size" | "italic">>): TextOverlay => ({
+ id: "a",
+ kind: "text",
+ text: "I QUIT MY JOB",
+ start: 0,
+ end: 3,
+ x: 0.5,
+ y: 0.25,
+ size: 110,
+ font: "Anton",
+ weight: 900,
+ shadow: false,
+ plate: false,
+ color: "#FFFDE8",
+ ...extra,
+});
+
+describe("styleMatches", () => {
+ test("a title wears the style it was given, whatever its words and place", () => {
+ const style = pickTextStyle(title({}));
+ expect(styleMatches(style, title({ text: "Other", x: 0.1, y: 0.9 }))).toBe(true);
+ });
+
+ test("a style read back from storage drops unset fields and still matches", () => {
+ const stored = JSON.parse(JSON.stringify(pickTextStyle(title({}))));
+ expect(styleMatches(stored, title({}))).toBe(true);
+ });
+
+ test("a changed style field moves the title off the style", () => {
+ const style = pickTextStyle(title({}));
+ expect(styleMatches(style, title({ size: 96 }))).toBe(false);
+ expect(styleMatches(style, title({ italic: true }))).toBe(false);
+ });
+
+ test("a style read back with its nested keys reordered still matches", () => {
+ // A cloud shelf stores the carrier in jsonb, which hands objects back
+ // in its own key order.
+ const worn = title({});
+ const own = { ...worn, shadow: { color: "#000000", blur: 12, x: 0, y: 4 } } as unknown as TextOverlay;
+ const stored = { ...pickTextStyle(own), shadow: { y: 4, x: 0, blur: 12, color: "#000000" } };
+ expect(styleMatches(stored as never, own)).toBe(true);
+ expect(styleMatches({ ...stored, shadow: { y: 5, x: 0, blur: 12, color: "#000000" } } as never, own)).toBe(false);
+ });
+});
diff --git a/site/src/cut/lib/stylePresets.ts b/site/src/cut/lib/stylePresets.ts
index a24b341b..3b698072 100644
--- a/site/src/cut/lib/stylePresets.ts
+++ b/site/src/cut/lib/stylePresets.ts
@@ -8,7 +8,7 @@
* textStyle.ts stays what it was: the implicit "last used" style.
*/
-import { pickTextStyle } from "@donkeycut/effects-kit";
+import { pickTextStyle, TEXT_STYLE_FIELDS } from "@donkeycut/effects-kit";
import { deleteTemplate, fetchLibrary, saveTemplate } from "./library";
import type { Residency } from "./residency";
import type { TextStyle } from "./textStyle";
@@ -55,6 +55,32 @@ export async function listStylePresets(): Promise<StylePreset[]> {
.filter((p): p is StylePreset => p !== null);
}
+/** Whether a title already wears a preset's look, field for field. A field
+ * the preset leaves unset matches a title that leaves it unset too. */
+export function styleMatches(style: TextStyle, overlay: TextOverlay): boolean {
+ const own = pickTextStyle(overlay);
+ return TEXT_STYLE_FIELDS.every((f) => sameValue(style[f], own[f]));
+}
+
+/** Two stored values are equal whatever order their keys come back in (a
+ * cloud shelf's jsonb reorders them); a key set to undefined is absent, as it
+ * is once stored. Arrays keep their order. */
+function sameValue(a: unknown, b: unknown): boolean {
+ if (a === b) {
+ return true;
+ }
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
+ return false;
+ }
+ if (Array.isArray(a) || Array.isArray(b)) {
+ return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => sameValue(v, b[i]));
+ }
+ const left = a as Record<string, unknown>;
+ const right = b as Record<string, unknown>;
+ const keys = new Set([...Object.keys(left), ...Object.keys(right)]);
+ return [...keys].every((k) => sameValue(left[k], right[k]));
+}
+
/** Save the given title's look as a named preset on the active shelf. */
export async function saveStylePreset(
projectId: string,
@@ -83,6 +109,19 @@ export async function saveStylePreset(
return presetOf(saved);
}
+/** Overwrite a preset with the given title's look, keeping its name. Every
+ * shelf already saves and deletes templates, so the new look lands on the
+ * active shelf and the old preset comes off once it has. */
+export async function updateStylePreset(
+ projectId: string,
+ preset: StylePreset,
+ overlay: TextOverlay
+): Promise<StylePreset | null> {
+ const next = await saveStylePreset(projectId, preset.name, overlay);
+ await deleteStylePreset(preset);
+ return next;
+}
+
export function deleteStylePreset(preset: StylePreset): Promise<void> {
return deleteTemplate(preset.residency, preset.id);
}
diff --git a/site/src/cut/lib/svgSticker.test.ts b/site/src/cut/lib/svgSticker.test.ts
new file mode 100644
index 00000000..e709524e
--- /dev/null
+++ b/site/src/cut/lib/svgSticker.test.ts
@@ -0,0 +1,70 @@
+import { describe, expect, test } from "bun:test";
+import { setRasterFactory, type RasterFactory, type RasterSurface } from "./raster";
+import { rasterizeSvg, sizedSvg, svgAspect } from "./svgSticker";
+
+describe("drawn stickers", () => {
+ test("the aspect comes from the viewBox, else width and height", () => {
+ expect(svgAspect('<svg viewBox="0 0 200 100"><rect/></svg>')).toBe(2);
+ expect(svgAspect("<svg viewBox='-10 -10 50,100'></svg>")).toBe(0.5);
+ expect(svgAspect('<svg width="30" height="60"></svg>')).toBe(0.5);
+ expect(svgAspect("<svg><rect/></svg>")).toBeNull();
+ });
+
+ test("the root is sized to the raster and carries the SVG namespace once", () => {
+ const out = sizedSvg('<svg width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M1 1"/></svg>', 512, 512);
+ expect(out.startsWith('<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 24 24" fill="none">')).toBe(true);
+ expect(out.match(/xmlns=/g)!.length).toBe(1);
+ });
+
+ test("markup that could run code or load files is refused", () => {
+ expect(() => sizedSvg('<svg viewBox="0 0 1 1"><script>x</script></svg>', 8, 8)).toThrow();
+ expect(() => sizedSvg('<svg viewBox="0 0 1 1" onload="x()"></svg>', 8, 8)).toThrow();
+ expect(() => sizedSvg('<svg viewBox="0 0 1 1"><image href="https://x/y.png"/></svg>', 8, 8)).toThrow();
+ expect(() => sizedSvg("<div>not svg</div>", 8, 8)).toThrow();
+ expect(() => sizedSvg("<svg><rect/></svg>", 8, 8)).toThrow();
+ expect(sizedSvg('<svg viewBox="0 0 1 1"><use href="#a"/></svg>', 8, 8)).toContain('href="#a"');
+ });
+});
+
+describe("drawing a sticker", () => {
+ test("rasterizes through the raster seam, so a headless runner draws it too", async () => {
+ const drawn: { w: number; h: number; blobType: string }[] = [];
+ const fake: RasterFactory = {
+ createCanvas: (w, h) => {
+ const ctx = { drawImage: () => {} };
+ return { width: w, height: h, getContext: () => ctx } as unknown as RasterSurface;
+ },
+ decodeImage: async (blob) => {
+ drawn.push({ w: 0, h: 0, blobType: blob.type });
+ return { source: {} as CanvasImageSource, width: 1024, height: 512 };
+ },
+ canvasToBlob: async (canvas, type) => {
+ drawn[drawn.length - 1] = { ...drawn[drawn.length - 1], w: canvas.width, h: canvas.height };
+ return new Blob(["png"], { type });
+ },
+ snapshot: async () => ({}) as ImageBitmap,
+ };
+ const replaced = setRasterFactory(fake);
+ try {
+ const png = await rasterizeSvg('<svg viewBox="0 0 200 100"><rect width="200" height="100"/></svg>');
+ expect(png.type).toBe("image/png");
+ expect(drawn).toEqual([{ w: 1024, h: 512, blobType: "image/svg+xml" }]);
+ } finally {
+ setRasterFactory(replaced);
+ }
+ });
+
+ test("markup the decoder cannot read is a clear error", async () => {
+ const replaced = setRasterFactory({
+ createCanvas: () => ({}) as RasterSurface,
+ decodeImage: async () => null,
+ canvasToBlob: async () => new Blob(),
+ snapshot: async () => ({}) as ImageBitmap,
+ });
+ try {
+ await expect(rasterizeSvg('<svg viewBox="0 0 1 1"><bogus</svg>')).rejects.toThrow("did not draw");
+ } finally {
+ setRasterFactory(replaced);
+ }
+ });
+});
diff --git a/site/src/cut/lib/svgSticker.ts b/site/src/cut/lib/svgSticker.ts
new file mode 100644
index 00000000..0af32957
--- /dev/null
+++ b/site/src/cut/lib/svgSticker.ts
@@ -0,0 +1,86 @@
+"use client";
+
+/**
+ * Stickers drawn from SVG markup: the assistant writes a small vector — a UI
+ * icon, a mouse pointer, a spinner arc, a badge — and it lands as an
+ * origin-"sticker" PNG like any other. The markup is rasterized here, in the
+ * browser, so the sticker is an ordinary image to every renderer (the live
+ * preview, the in-tab export and the server's headless render alike).
+ */
+
+import { enrichAsset, uploadProjectImage } from "./media";
+import { createRasterCanvas, decodeRasterImage, rasterCanvasToPng } from "./raster";
+import { useEditor } from "./store";
+import { mediaSlug, type MediaAsset } from "./types";
+
+/** The long side a drawn sticker is rasterized at, px: crisp at full-frame
+ * size on a 4K export's short side. */
+export const SVG_STICKER_PX = 1024;
+
+/** The markup's own aspect, from its viewBox or width/height; null when it
+ * names neither. */
+export function svgAspect(svg: string): number | null {
+ const root = /<svg\b[^>]*>/i.exec(svg)?.[0] ?? "";
+ const box = /viewBox\s*=\s*["']\s*([-\d.eE]+)[\s,]+([-\d.eE]+)[\s,]+([\d.eE]+)[\s,]+([\d.eE]+)\s*["']/i.exec(root);
+ if (box) {
+ const w = Number(box[3]);
+ const h = Number(box[4]);
+ return w > 0 && h > 0 ? w / h : null;
+ }
+ const w = Number(/\swidth\s*=\s*["']([\d.]+)/i.exec(root)?.[1]);
+ const h = Number(/\sheight\s*=\s*["']([\d.]+)/i.exec(root)?.[1]);
+ return w > 0 && h > 0 ? w / h : null;
+}
+
+/**
+ * The markup made ready to draw at `w`×`h`: one root <svg> with the SVG
+ * namespace and the raster's size, so the browser scales the viewBox to fill
+ * it. Throws on markup that is not a single sized SVG.
+ */
+export function sizedSvg(svg: string, w: number, h: number): string {
+ const text = svg.trim();
+ if (!/^(<\?xml[^>]*>\s*)?<svg\b/i.test(text) || !/<\/svg>\s*$/i.test(text)) {
+ throw new Error("svg must be one <svg …>…</svg> element.");
+ }
+ if (/<(script|foreignObject)\b/i.test(text) || /\bon[a-z]+\s*=/i.test(text)) {
+ throw new Error("svg can't carry scripts, event handlers or foreignObject.");
+ }
+ if (/\b(href|src)\s*=\s*["'](?!#)/i.test(text)) {
+ throw new Error("svg can't load outside files; draw everything inline.");
+ }
+ if (!svgAspect(text)) throw new Error("svg needs a viewBox (or width and height).");
+ return text.replace(/<svg\b([^>]*)>/i, (_, attrs: string) => {
+ const kept = attrs.replace(/\s(width|height|xmlns)\s*=\s*["'][^"']*["']/gi, "");
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}"${kept}>`;
+ });
+}
+
+/** Draw SVG markup to a transparent PNG, `SVG_STICKER_PX` on its long side. */
+export async function rasterizeSvg(svg: string): Promise<Blob> {
+ const aspect = svgAspect(svg) ?? 1;
+ const w = Math.max(1, Math.round(aspect >= 1 ? SVG_STICKER_PX : SVG_STICKER_PX * aspect));
+ const h = Math.max(1, Math.round(aspect >= 1 ? SVG_STICKER_PX / aspect : SVG_STICKER_PX));
+ // Decoded and drawn through the raster seam: the page's DOM image and
+ // canvas, or the skia surface a headless runner installs.
+ const img = await decodeRasterImage(new Blob([sizedSvg(svg, w, h)], { type: "image/svg+xml" }));
+ if (!img) {
+ throw new Error("The svg did not draw; check that it is valid SVG markup.");
+ }
+ const canvas = createRasterCanvas(w, h);
+ const ctx = canvas.getContext("2d") as CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
+ ctx.drawImage(img.source, 0, 0, w, h);
+ return rasterCanvasToPng(canvas);
+}
+
+/** Rasterize `svg` and save it as an origin-"sticker" asset of the open
+ * project, named `name`. */
+export async function saveSvgSticker(projectId: string, svg: string, name: string): Promise<MediaAsset> {
+ const png = await rasterizeSvg(svg);
+ const asset = await uploadProjectImage(projectId, png, `${mediaSlug(name, "sticker")}.png`, {
+ name,
+ origin: "sticker",
+ });
+ useEditor.getState().addAsset(asset);
+ void enrichAsset(asset);
+ return asset;
+}
diff --git a/site/src/cut/lib/titleDefaults.test.ts b/site/src/cut/lib/titleDefaults.test.ts
new file mode 100644
index 00000000..eb3c1c16
--- /dev/null
+++ b/site/src/cut/lib/titleDefaults.test.ts
@@ -0,0 +1,45 @@
+import { beforeEach, expect, test } from "bun:test";
+import { useEditor } from "./store";
+import { emptySubtitles, isTextOverlay } from "./types";
+
+// The editor remembers the last title's look for the next one a person adds.
+// The assistant's add_title states its own defaults, so a remembered look from
+// another title must not ride along on what it leaves out.
+const remembered = { font: "bangers", size: 140, letterSpacing: 0.55, color: "#FF0000", shadow: false };
+globalThis.localStorage ??= {
+ getItem: () => JSON.stringify(remembered),
+ setItem: () => {},
+ removeItem: () => {},
+} as unknown as Storage;
+
+const { runAiTool } = await import("./aiTools");
+
+beforeEach(() =>
+ useEditor.setState({
+ projectId: "p1",
+ aspect: "16:9",
+ assets: [],
+ clips: [],
+ audioClips: [],
+ overlays: [],
+ subtitles: emptySubtitles(),
+ background: "#000000",
+ })
+);
+
+test("add_title starts from the defaults its schema states", async () => {
+ await runAiTool("add_title", { text: "CLIP 1", font: "impact", start: 0, end: 1 });
+ const t = useEditor.getState().overlays.filter(isTextOverlay)[0];
+ expect(t.font).toBe("impact");
+ expect(t.size).toBe(88);
+ expect(t.letterSpacing).toBeUndefined();
+ expect(t.color).toBe("#FFFFFF");
+ expect(t.shadow).toBe(true);
+});
+
+test("a title the person adds still takes the remembered look", () => {
+ useEditor.getState().addOverlay();
+ const t = useEditor.getState().overlays.filter(isTextOverlay)[0];
+ expect(t.letterSpacing).toBe(0.55);
+ expect(t.font).toBe("bangers");
+});
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index fdb5de60..3facd5af 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -536,7 +536,7 @@ Generating: subtitles_generate transcribes the cut's audio on-device (Apple spee
captions_generate rewrites a track's cues into punchy social captions (emoji, curiosity-hook opener) in a style (clean/hook/punchy), keeping timings — use it when the ask is social/TikTok captions rather than a plain transcript.
Editing: update_cue (text, retime, or the caption's own x/y), delete_cue, merge_cue (joins into the previous cue on the same track). In the panel, Return splits a caption at the cursor onto real word timings; hand-edited text drops its word timings.
Placement per caption: a track has one spot, and update_cue x/y gives a single caption its own (editor_state shows it on the cue) — a talking-head video moves its captions with the layout: centered in the gap of a split layout, a lower third over the full-frame face, the top when the visual under it is busy low. follow_track hands it back. In the preview, Option-drag moves only the caption on screen.
-Emphasis: set_caption_emphasis sets chosen words apart in the track's emphasis style (default a bold italic ${CAPTION_EMPHASIS_DEFAULT.font} in ${CAPTION_EMPHASIS_DEFAULT.color}; set_caption_look emphasis_font/emphasis_color/emphasis_italic/emphasis_weight/emphasis_scale restyle it), the rest of the line unchanged and any word effect still playing over it. Pick one or two words that carry the line — a product name, a number, the call-to-action keyword — in roughly every third caption; never two emphasized captions in a row, never a function word. editor_state cues list their emphasized words as [index, word].
+Emphasis: set_caption_emphasis sets chosen words apart in the track's emphasis style (default a bold italic ${CAPTION_EMPHASIS_DEFAULT.font} in ${CAPTION_EMPHASIS_DEFAULT.color}; set_caption_look emphasis_font/emphasis_color/emphasis_italic/emphasis_weight/emphasis_scale restyle it), the rest of the line unchanged and any word effect still playing over it. Captions carry no emphasis until the user asks for it; then pick one or two words that carry the line — a product name, a number, the call-to-action keyword — in roughly every third caption, never two emphasized captions in a row, never a function word. editor_state cues list their emphasized words as [index, word].
subtitles_set_view: showOnVideo (preview + export burn-in), showOnTimeline (amber cue rows).
Caption look: set_caption_look carries the whole look — the visual presets (${Object.keys(CAPTION_STYLES).join(", ")}), size, font, and the word effect with its color, swell and fade settings; the Subtitles panel offers the same, and each track's caption drags to a new spot in the preview. The word effects play the caption as it is said:\n${wordEffectCatalog()}\ncaptions_generate's clean/hook/punchy choice shapes the caption text it writes; the visual preset is separate.`,
@@ -593,7 +593,7 @@ The opening line (the hook) is a split. The call to action and everything after
**7. Cover, captions, call to action.**
- Cover: a short opens on its title — add_title on the first frame only (start 0, end 0.04), bold and large, dark on a light rounded add_shape box in the upper part of the frame — written from the hook when the person gave none. A longer video skips it unless asked.
-- Captions: when the cut is final, subtitles_generate again so the captions come from the finished speech. set_caption_look style punchy, a few words per caption (words_per_cue 2 in a short, more in a longer piece), white with a dark outline. set_caption_emphasis marks one or two meaningful words — a product name, a number, a benefit, the call-to-action keyword — after every 2–3 plain captions, never two emphasized captions in a row and never a function word; the look's emphasis style carries them. Position follows the layout, each caption placed with update_cue x/y inside project.safeZones: on a split, in the free band between the graphic's content and the card; on camera, the lower band under the face; on a visual, the band its content leaves free; on the outro, clear of the call to action. A caption never covers the face, the card edge or a visual's content.
+- Captions: when the cut is final, subtitles_generate again so the captions come from the finished speech. set_caption_look style punchy, a few words per caption (words_per_cue 2 in a short, more in a longer piece), white with a dark outline. Position follows the layout, each caption placed with update_cue x/y inside project.safeZones: on a split, in the free band between the graphic's content and the card; on camera, the lower band under the face; on a visual, the band its content leaves free; on the outro, clear of the call to action. A caption never covers the face, the card edge or a visual's content.
- Call to action: on the outro, a comment box in the lower part of the frame — a white rounded add_shape, the keyword from the call-to-action line as an add_title typed in with a typewriter entrance and a blinking caret (set_overlay_animation caret), then a small Post button (shape and title, grouped) pressed with hit_style press once the keyword is typed. Nothing else on it.
**8. Sound.** set_clip_sound preset studio on the voice. Sound effects come from stock_search kind sound, one per meaningful visible event: a soft click on a button press or tap (the Post press included), a light keyboard tick on typing, a soft pop when a card or device lands, a chime on an answer or confirmation, and a low whoosh only on a camera whip, its loudest moment on the whip's midpoint (at most one per run, varied). Layout cuts, glides, steps and pushes get no sound. A riser of ~2–3s ends exactly on the join where the hook hands to the first point. Music is generate_music instrumental — modern, minimal, warm, 100–120 BPM, no lead melody, length "song" for a video over a minute — trimmed to the cut with a 0.8s fade-out at the end and one flat level throughout (no duck). measure_level sets every level from numbers: the music's integratedLufs 10 LU under the voice's; clicks, pops and chimes peaking ~10 dB under the voice's truePeakDbtp, whooshes ~9, ticks ~16, the riser ~14.
diff --git a/site/src/cut/server/ai/headlessTools.ts b/site/src/cut/server/ai/headlessTools.ts
index af66fd13..09bd4b96 100644
--- a/site/src/cut/server/ai/headlessTools.ts
+++ b/site/src/cut/server/ai/headlessTools.ts
@@ -45,6 +45,8 @@ const PAGE_MEDIA_TOOLS: ReadonlySet<string> = new Set([
"captions_generate",
"subtitles_from_visuals",
"stock_add",
+ "read_color_stats",
+ "match_color_grade",
...PAGE_ONLY_TOOLS,
]);
@@ -156,6 +158,12 @@ async function flush(doc: OpenDoc): Promise<void> {
doc.stored = merged;
}
+/** True when a tool input carries svg markup to draw. */
+function hasSvgMarkup(input: unknown): boolean {
+ const svg = (input as { svg?: unknown } | null)?.svg;
+ return typeof svg === "string" && svg.trim() !== "";
+}
+
/** Run one tool call against the engine-held store for `projectId`,
* persisting the doc after it. The bridge calls this when no editor tab is
* attached to the chat session. */
@@ -169,6 +177,12 @@ async function executeHeadlessTool(
output: { noEditor: true, note: DETACHED_UI_NOTE },
};
if (PAGE_MEDIA_TOOLS.has(toolName)) return { errorText: DETACHED_MEDIA_ERROR };
+
+ // A sticker drawn from svg markup rasterizes it, and the engine has no
+ // canvas; placing an existing sticker asset is a doc edit and runs here.
+ if (toolName === "add_sticker" && hasSvgMarkup(input)) {
+ return { errorText: DETACHED_MEDIA_ERROR };
+ }
if (toolName === "read_folder") {
const args = (input ?? {}) as { reference?: { scope?: string }; link?: string };
const ref = args.reference ?? (args.link ? parseFolderLink(args.link) : null);
diff --git a/site/src/cut/server/exportPipeline.ts b/site/src/cut/server/exportPipeline.ts
index 021bcba6..be8c9276 100644
--- a/site/src/cut/server/exportPipeline.ts
+++ b/site/src/cut/server/exportPipeline.ts
@@ -18,7 +18,7 @@ import { shiftSpan, type SpecSound } from "../lib/soundSource";
import { masterRawMix, packStems } from "./exportAudio";
import { STEM_CHANNELS, STEM_RATE, type StemDef } from "../lib/stems";
import { CLIP_MAX_ZOOM, CLIP_MIN_SECONDS, clipFrameAt, regionPx, TRANSITION_ZOOM, type ColorGrade } from "../lib/types";
-import { audioFxFilters, buildClipLut, elementLook, buildTransferLut, CLARITY_EPS, compositeSpaceFor, detailActive, detailGain, detailRadius, effectFilterLines, effectRecipe, type FlashRhythm, type FlashTone, type GlitchKind, type LeakCourse, graphicsToHlg, hexToHlgHex, hlgToPq, isAudioEffect, lookFilterLines, lutToCube, mirrorRetimable, parseLutFile, recipeKey, retimeOf, shortestTurn, slowRuns, srcSpan, sortedKeys, soundFilters, type ChainChroma, type ClipColorRecipe, type ClipEffect, type ClipSound, type CodeFormat, type EaseId, type OutputSpace, type OverlayKey, type ParsedLut, type Retime, type SpeedNode } from "@donkeycut/effects-kit";
+import { audioFxFilters, buildClipLut, elementLook, buildTransferLut, CLARITY_EPS, compositeSpaceFor, detailActive, detailGain, detailRadius, effectFilterLines, effectRecipe, type FlashFade, type FlashRhythm, type FlashTone, type GlitchKind, type LeakCourse, graphicsToHlg, hexToHlgHex, hlgToPq, isAudioEffect, lookFilterLines, lutToCube, mirrorRetimable, parseLutFile, recipeKey, retimeOf, shortestTurn, slowRuns, srcSpan, sortedKeys, soundFilters, type ChainChroma, type ClipColorRecipe, type ClipEffect, type ClipSound, type CodeFormat, type EaseId, type OutputSpace, type OverlayKey, type ParsedLut, type Retime, type SpeedNode } from "@donkeycut/effects-kit";
// The render pipeline itself: spec in, finished mp4 out. Shared by the local
// engine's job registry (jobs.ts) and the cloud render worker, which stage
@@ -404,10 +404,11 @@ export interface ExportSpec {
leak?: LeakCourse;
/** The kind a glitch is pinned to. */
glitch?: GlitchKind;
- /** A flash's tone, strobe rate and rhythm. */
+ /** A flash's tone, strobe rate, rhythm and fade. */
tone?: FlashTone;
rate?: number;
rhythm?: FlashRhythm;
+ fade?: FlashFade;
/** Its row in the element stack; lane 0 is the top. */
lane?: number;
start: number;