Open source CapCut alternative.
TypeScript
feat(cut): stretch stickers per axis from side grips [rebuild]
David Le5d0920be361d
diff --git a/site/packages/effects-kit/src/render.ts b/site/packages/effects-kit/src/render.tsindex e9838ec3..68837ffc 100644--- a/site/packages/effects-kit/src/render.ts+++ b/site/packages/effects-kit/src/render.ts@@ -226,7 +226,7 @@ async function paintSticker(const handle = await env.resolveLottie?.(o.assetId);if (!handle) return;const aspect = handle.width > 0 && handle.height > 0 ? handle.width / handle.height : 1;- const h = w / aspect;+ const h = stickerHeight(o, frame, w, aspect);ctx.drawImage(handle.seek(frame.t ?? 0), cx - w / 2, cy - h / 2, w, h);return;}@@ -234,10 +234,16 @@ async function paintSticker(const img = await env.resolveAsset(o.assetId);if (!img) return;const aspect = img.width > 0 && img.height > 0 ? img.width / img.height : 1;- const h = w / aspect;+ const h = stickerHeight(o, frame, w, aspect);ctx.drawImage(img.source, cx - w / 2, cy - h / 2, w, h);}+/** A sticker's painted height in px: its stored height when a side grip set+ * one, otherwise the width under the source's own aspect. */+function stickerHeight(o: StickerOverlay, frame: PaintFrame, w: number, aspect: number): number {+ return o.h ? Math.max(1, o.h * frame.height) : w / aspect;+}+/** The CSS font shorthand a text element paints (and loads faces) with. */export function textCssFont(overlay: TextOverlay, fpx: number, env: RenderEnv): string {return `${overlay.italic ? "italic " : ""}${overlay.weight} ${fpx}px ${env.fontStack(overlay.font)}`;@@ -764,11 +770,11 @@ export async function measureElementBounds(if (s.lottie) {const handle = s.assetId ? await env.resolveLottie?.(s.assetId) : null;const aspect = handle && handle.width > 0 ? handle.width / handle.height : 1;- return { cx, cy, w, h: w / aspect };+ return { cx, cy, w, h: stickerHeight(s, frame, w, aspect) };}const img = s.assetId && env.resolveAsset ? await env.resolveAsset(s.assetId) : null;const aspect = img && img.width > 0 && img.height > 0 ? img.width / img.height : 1;- return { cx, cy, w, h: w / aspect };+ return { cx, cy, w, h: stickerHeight(s, frame, w, aspect) };}const o = overlay as TextOverlay;const fpx = o.size * frame.scale;diff --git a/site/packages/effects-kit/src/types.ts b/site/packages/effects-kit/src/types.tsindex d875d11c..2db0f4e6 100644--- a/site/packages/effects-kit/src/types.ts+++ b/site/packages/effects-kit/src/types.ts@@ -124,14 +124,16 @@ export interface ShapeOverlay extends OverlayBase {stroke?: { color: string; width: number }; // outline, width px at 1080 short side}-/** An image sticker. Height follows the source's own aspect, so only the- * width is stored. */+/** An image sticker. Height follows the source's own aspect until a side+ * grip stretches it, which stores an explicit `h`. */export interface StickerOverlay extends OverlayBase {kind: "sticker";/** Host media asset holding the sticker image (PNG/JPG/SVG, or a Lottie* JSON document when `lottie` is set). */assetId?: string;w: number; // width, fraction of frame width+ /** Height, fraction of frame height; absent means the source's own aspect. */+ h?: number;/** The asset is a Lottie animation; it plays on a loop for the element's* whole duration, frame-seeked from timeline time. */lottie?: boolean;diff --git a/site/src/cut/components/ElementsPanel.tools.ts b/site/src/cut/components/ElementsPanel.tools.tsindex 208c89da..ea9f6b5a 100644--- a/site/src/cut/components/ElementsPanel.tools.ts+++ b/site/src/cut/components/ElementsPanel.tools.ts@@ -39,7 +39,7 @@ 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.",+ "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.",inputSchema: obj({asset_id: str("Project image asset id"),start: num("Start time s (default: playhead)"),@@ -47,6 +47,7 @@ export const ELEMENTS_TOOLS = [x: num("Center x 0..1 (default 0.5)"),y: num("Center y 0..1 (default 0.5)"),w: num("Width, fraction of frame width (default 0.25)"),+ h: num("Height, fraction of frame height; omit to keep the source's aspect"),rotation: num("Degrees clockwise, -180..180"),opacity: num("Whole-element opacity 0..1"),lane: num("Element row (0 = the front row, drawn over every higher row). Elements on one row never overlap — a title over a shape needs a lower row than the shape."),@@ -63,6 +64,7 @@ export const ELEMENTS_TOOLS = [x: num("Center x 0..1 (default 0.5)"),y: num("Center y 0..1 (default 0.5)"),w: num("Width, fraction of frame width (default 0.25)"),+ h: num("Height, fraction of frame height; omit to keep the source's aspect"),lane: num("Element row (0 = the front row, drawn over every higher row). Elements on one row never overlap — a title over a shape needs a lower row than the shape."),}, ["idea"]),},diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.tsindex 8b4914a9..4be9dc8f 100644--- a/site/src/cut/components/Inspector.tools.ts+++ b/site/src/cut/components/Inspector.tools.ts@@ -69,7 +69,7 @@ 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/fill_opacity/radius/stroke; stickers take w. Every kind takes timing, position, rotation, opacity, hidden. This is the tool for 'make this text better' requests too.",+ "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/fill_opacity/radius/stroke; stickers take w/h. Every kind takes timing, position, rotation, opacity, hidden. This is the tool for 'make this text better' requests too.",inputSchema: obj({id: str("Overlay element id"),text: str("New text (titles)"),@@ -93,7 +93,7 @@ export const INSPECTOR_TOOLS = [shadow: bool("Drop shadow (titles)"),plate: bool("Backdrop plate (titles)"),w: num("Width, fraction of frame width (shapes/stickers)"),- h: num("Height, fraction of frame height (shapes)"),+ h: num("Height, fraction of frame height (shapes/stickers; a sticker's 0 returns it to the source's aspect)"),fill: str("Fill color (shapes)"),fill_opacity: num("Fill opacity 0..1 (rect/ellipse)"),radius: num("Rect corner radius, px at 1080 short side"),diff --git a/site/src/cut/components/OverlayLayer.tsx b/site/src/cut/components/OverlayLayer.tsxindex 3a234183..d5a98ba1 100644--- a/site/src/cut/components/OverlayLayer.tsx+++ b/site/src/cut/components/OverlayLayer.tsx@@ -850,6 +850,16 @@ function OverlayItem({const c = Math.round(Math.min(4, Math.max(0.25, v)) * 1000) / 1000;return Math.abs(c - 1) < 0.005 ? undefined : c;};+ const stickerSize = (v: number) => Math.min(1.5, Math.max(0.02, v));+ // A sticker's resting height as a frame fraction: the one it stores, or+ // the grabbed box laid out under the source's own aspect. A side grip+ // pins it so the other axis holds while one stretches.+ const stickerH = (m: Overlay): number | undefined => {+ if (m.kind !== "sticker") return undefined;+ if (m.h) return m.h;+ const laid = m.id === o.id ? el.offsetHeight / stageHeight : 0;+ return laid > 0 ? laid : undefined;+ };const scaled = (m: Overlay, k: number): Partial<Overlay> => {if (isTextOverlay(m)) {// A side grip pulls one axis of the glyph stretch; a corner scales@@ -867,7 +877,14 @@ function OverlayItem({if (axis.x === 0) return h;return { ...w, ...h };}- if (m.kind === "sticker") return { w: Math.min(1.5, Math.max(0.02, m.w * k)) };+ if (m.kind === "sticker") {+ // A side grip stretches its own axis and pins the other; a corner+ // scales the whole picture, the stored height riding along.+ const h = stickerH(m);+ if (axis.y === 0) return { w: stickerSize(m.w * k), ...(h ? { h } : {}) };+ if (axis.x === 0) return h ? { h: stickerSize(h * k) } : { w: stickerSize(m.w * k) };+ return { w: stickerSize(m.w * k), ...(m.h ? { h: stickerSize(m.h * k) } : {}) };+ }return {};};// How much the grabbed element actually grew per axis once its size@@ -890,8 +907,11 @@ function OverlayItem({if (self.kind === "shape")return { kx: (p.w ?? self.w) / self.w, ky: (p.h ?? self.h) / self.h };if (self.kind === "sticker") {- const k = (p.w ?? self.w) / self.w;- return { kx: k, ky: k };+ const kx = (p.w ?? self.w) / self.w;+ const h0 = stickerH(self);+ // Height follows the width whenever it is not stored on its own.+ const ky = p.h !== undefined && h0 ? p.h / h0 : axis.x === 0 ? 1 : kx;+ return { kx, ky };}return { kx: 1, ky: 1 };};@@ -1112,7 +1132,7 @@ function OverlayItem({) : o.kind === "shape" ? (<ShapeView shape={o} stageWidth={stageWidth} stageHeight={stageHeight} scale={scale} />) : o.kind === "sticker" ? (- <StickerView sticker={o} stageWidth={stageWidth} t={t} />+ <StickerView sticker={o} stageWidth={stageWidth} stageHeight={stageHeight} t={t} />) : null}</div>{/* The twin can't mount until its size is read, so the in-box chrome@@ -2130,18 +2150,30 @@ function ShapeView({function StickerView({sticker: o,stageWidth,+ stageHeight,t,}: {sticker: StickerOverlay;stageWidth: number;+ stageHeight: number;t: number;}) {const asset = useEditor((s) =>o.assetId ? s.assets.find((a) => a.id === o.assetId) : undefined);if (!asset) return <span className="block size-8 rounded bg-white/20" />;+ // A stretched sticker draws at its stored height; otherwise the source's+ // own aspect sets it.+ const height = o.h ? o.h * stageHeight : undefined;if (o.lottie) {- return <LottieView asset={asset} width={o.w * stageWidth} tLocal={Math.max(0, t - o.start)} />;+ return (+ <LottieView+ asset={asset}+ width={o.w * stageWidth}+ height={height}+ tLocal={Math.max(0, t - o.start)}+ />+ );}return (// eslint-disable-next-line @next/next/no-img-element -- project media blob/engine URL@@ -2150,7 +2182,7 @@ function StickerView({alt={asset.name}draggable={false}className="block max-w-none select-none"- style={{ width: o.w * stageWidth, height: "auto" }}+ style={{ width: o.w * stageWidth, height: height ?? "auto" }}/>);}@@ -2161,10 +2193,13 @@ function StickerView({function LottieView({asset,width,+ height,tLocal,}: {asset: { id: string; url: string; fileName: string; name: string };width: number;+ /** An explicit height; absent draws under the animation's own aspect. */+ height?: number;tLocal: number;}) {const canvasRef = useRef<HTMLCanvasElement>(null);@@ -2211,7 +2246,7 @@ function LottieView({<canvasref={canvasRef}className="block max-w-none select-none"- style={{ width, height: width / aspect }}+ style={{ width, height: height ?? width / aspect }}/>);}diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.tsindex 812977e3..bb108897 100644--- a/site/src/cut/lib/aiContext.ts+++ b/site/src/cut/lib/aiContext.ts@@ -701,7 +701,7 @@ function describeOverlay(o: Overlay) {};}if (o.kind === "sticker") {- return { ...base, assetId: o.assetId, w: r(o.w) };+ return { ...base, assetId: o.assetId, w: r(o.w), ...(o.h ? { h: r(o.h) } : {}) };}if (o.kind === "effect") {return {diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 14f6e8fb..7da3f17d 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -4933,5 +4933,8 @@ function overlayPatch(input: Record<string, unknown>, kind: "text" | "shape" | "}if (isNum(input.w)) patch.w = clamp(input.w, 0.02, 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;return patch;}diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 20c2d172..0172d1ca 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -202,7 +202,7 @@ The frame's own color is set_background, not a full-frame rectangle: it fills thA whole run of text — lines timed to speech, a lyric video, a kinetic-typography passage, a quote sequence — is add_text_sequence, one call. Design is opt-in: called with no look it lays a plain run — one readable face, one place in the frame, a short fade, no cards, no moves, the frame color untouched — which is what a bare "add the text" asks for. Name a look when the user asked for a designed run, and then the look is the design of the whole run, not one line: the frame color, the cards, and the ensemble the run walks across its length — faces, entrances, where successive lines land, and what each holds. Read the text-videos skill for the looks and the flow, and text-creativity for the fifty devices that keep a long run from reading flat. A designed run is composed in the call, never laid identical and then repaired element by element. A video needs no footage. Titles, shapes and stickers over a background color are a complete cut on their own: it plays, exports, and shares like any other. Build one by setting the background, then placing elements on the rows the stack needs — reach for footage only when the user asks for it.Titles (add_title / update_overlay): text, size (frame px; the design short side is 1080), font (${FONTS.map((f) => `${f.id}=${f.label}`).join(", ")}), weight (400/700), color, shadow, plate (translucent dark backdrop). Type never leaves the picture: a line too wide for the room its anchor leaves is broken onto more lines as it draws, in the preview and in the export alike, so write the words at the size the design wants and leave the fitting to the renderer.Shapes (add_shape): rect, ellipse, line, arrow. w/h are frame fractions; rect/ellipse take fill + fill_opacity, corner radius (rect), and an outline (stroke_color/stroke_width); line/arrow draw in \`fill\` with h as their thickness, and rotation gives them their direction (0° points right, 90° points down).-Stickers (add_sticker): a project image asset (generated cutouts in the Elements panel carry origin "sticker"); w is a frame-width fraction and height follows the source's aspect. Lottie JSON uploads become animated stickers that loop for the element's duration.+Stickers (add_sticker): a project image asset (generated cutouts in the Elements panel carry origin "sticker"); w is a frame-width fraction and height follows the source's aspect unless h sets it. Lottie JSON uploads become animated stickers that loop for the element's duration.Custom stickers (create_sticker): one call generates the image, removes the background, adds the die-cut outline, and places it — use it when the user asks for a sticker of something they don't have (it spends credits like image generation).Effects (add_effect): time-ranged treatments over the finished cut. Three families, one list: the picture treatments (${EFFECT_TREATMENTS.join(", ")}), the graded looks (${LOOK_EFFECTS.join(", ")}), and the audio treatments (${AUDIO_EFFECT_IDS.join(", ")}). A picture effect treats the footage and everything laid over it; an audio effect treats everything audible under its window at once — clip sound, upper-track sound and the soundtrack — so "make this bit sound like a phone call", "put an echo on that line", or "muffle the music here" is an effect element over that stretch, and a per-clip volume, fade or duck is the audio tools instead. A handover on the sound at a cut belongs to the transition on that cut — the audiocross style — not here. Placed like any element and tuned with \`amount\` (update_overlay), and trims like anything else: a picture effect dropped over a clip opens covering that clip, while an audio effect opens at the standard length wherever it was placed — a treatment on the sound is aimed at a moment, so give it the window you mean. One effect at a time reads best, amounts under ~0.5. Effects are stylized post treatments on a stretch of timeline; pure color — exposure, warmth, a cinematic or film palette on one clip — is the per-clip grading tools instead (color-grading skill), whose preset catalog is separate from the look effects.Advanced text (update_overlay): italic, align (multi-line), letter_spacing (em), line_height, stretch_x/stretch_y (glyph stretch multipliers, the side grips' axis-only resize), stroke_color/stroke_width (em outline behind the fill), and richer shadows. Bundled Google families join the system set — ${GOOGLE_FONT_IDS.join(", ")} — and so do the user's own: a .ttf/.otf/.woff/.woff2 file dropped on the Library is offered in every project under a font id like "font:<id>". Editor_state lists the ones this account has under \`fonts\` — use an id from there instead of guessing at a family name, and when someone asks for a typeface that is not in the list, tell them the Library takes font files.@@ -218,7 +218,7 @@ Composite builds: these primitives compose. Stacked overlay video copies, masksAll of it is regular timeline editing: free, live, and undoable.Good TikTok titles: short punchy lines, high contrast (white/yellow + shadow or plate), size 72–110, keep inside the middle 80% of the frame (x 0.1..0.9, y 0.1..0.9), avoid the caption band (y≈0.8) when subtitles are on.Tasteful graphics: shapes read best as accents (a highlight box behind a stat, an arrow pointing at the subject, a color bar under a title) — semi-transparent fills (fill_opacity 0.2–0.5) sit better over footage than solid blocks. One or two stickers a scene; size 0.15–0.3 of the frame width.-In the UI: the timeline toolbar adds Text; the Elements side-panel tab browses stickers and shapes and creates sticker images, and the Effects tab holds the effects — a click in any panel picks a tile, and dragging one onto the timeline is what places it; dragging in the preview places an element, its corner handle resizes, the top handle rotates; the Inspector edits every field.`,+In the UI: the timeline toolbar adds Text; the Elements side-panel tab browses stickers and shapes and creates sticker images, and the Effects tab holds the effects — a click in any panel picks a tile, and dragging one onto the timeline is what places it; dragging in the preview places an element, a corner handle scales it, a side handle stretches one axis with the far side planted, the top handle rotates; the Inspector edits every field.`,"text-videos": `# Text-driven videos: lyrics, kinetic type, quote cardsA video whose picture is words. Three pieces: the frame behind them (set_background, or the user's footage), the words themselves, and the clock that says when each line lands. For the device list — fifty ways to make a run of text worth watching — read the text-creativity skill.