Open source CapCut alternative.
TypeScript
feat(cut): decimal custom ratios, 8:1 shape cap, reordered presets [rebuild]
David Lea134de4d6dc9
diff --git a/site/src/cut/components/TopBar.tsx b/site/src/cut/components/TopBar.tsxindex ed91d86d..84957485 100644--- a/site/src/cut/components/TopBar.tsx+++ b/site/src/cut/components/TopBar.tsx@@ -138,13 +138,15 @@ export function TopBar({<AspectIcon aspect={p.value} /><span className="flex-1">{p.name} · {p.value}- <span className="block text-[10.5px] text-muted-foreground">{p.sublabel}</span>+ {p.sublabel && (+ <span className="block text-[10.5px] text-muted-foreground">{p.sublabel}</span>+ )}</span>{aspect === p.value && <Check className="size-3.5 text-muted-foreground" />}</DropdownMenuItem>))}<DropdownMenuItem- onSelect={() => {+ onClick={() => {const r = parseRatio(aspect);if (r) {setCustomW(String(r.w));@@ -154,12 +156,7 @@ export function TopBar({}}><Ratio />- <span className="flex-1">- Custom…- <span className="block text-[10.5px] text-muted-foreground">- {isPreset ? "Any width : height" : `Current · ${aspect}`}- </span>- </span>+ <span className="flex-1">Custom…</span>{!isPreset && <Check className="size-3.5 text-muted-foreground" />}</DropdownMenuItem></DropdownMenuContent>diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex d84ec892..5c438c14 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -1710,7 +1710,7 @@ export async function runAiTool(const a = typeof input.aspect === "string" ? normalizeAspect(input.aspect) : null;if (!a)throw new ToolError(- 'aspect must be "W:H" with whole numbers up to a 4:1 shape, e.g. "9:16", "16:9", "1:1", or "9:5".'+ 'aspect must be "W:H" up to an 8:1 shape — whole or decimal sides, e.g. "9:16", "1:1", "9:2", "2.39:1".');s.setAspect(a);const f = frameOf(a);diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex e4d65dee..6427c51a 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -12,26 +12,35 @@ export const IMAGE_CLIP_SECONDS = 8;export type Aspect = `${number}:${number}`;/** Parse a "W:H" ratio. Null unless both sides are positive integers up to- * three digits and the long/short ratio is at most 4 (keeps ffmpeg output+ * three digits and the long/short ratio is at most 8 (keeps ffmpeg output* dims and text layout sane). */export function parseRatio(a: string | undefined | null): { w: number; h: number } | null {const m = /^(\d{1,3}):(\d{1,3})$/.exec(a ?? "");if (!m) return null;const w = Number(m[1]);const h = Number(m[2]);- if (!w || !h || Math.max(w, h) / Math.min(w, h) > 4) return null;+ if (!w || !h || Math.max(w, h) / Math.min(w, h) > 8) return null;return { w, h };}-/** Reduce a valid ratio to lowest terms as the one canonical string —- * "18:32" and "09:16" both become "9:16", so preset checks and literal- * comparisons see a single spelling. Null when the ratio is invalid. */+/** Reduce a ratio to the one canonical string: lowest-terms whole numbers.+ * Sides may carry up to two decimals — "1.85:1" → "37:20", "18:32" and+ * "09:16" both → "9:16" — so preset checks and literal comparisons see a+ * single spelling. Null when invalid: non-positive, more extreme than 8:1,+ * or not expressible with whole sides up to 999. */export function normalizeAspect(a: string | undefined | null): Aspect | null {- const r = parseRatio(a);- if (!r) return null;+ const m = /^(\d{1,3}(?:\.\d{1,2})?):(\d{1,3}(?:\.\d{1,2})?)$/.exec(a ?? "");+ if (!m) return null;+ const scale = 10 ** Math.max(m[1].split(".")[1]?.length ?? 0, m[2].split(".")[1]?.length ?? 0);+ let w = Math.round(Number(m[1]) * scale);+ let h = Math.round(Number(m[2]) * scale);+ if (!w || !h || Math.max(w, h) / Math.min(w, h) > 8) return null;const gcd = (x: number, y: number): number => (y === 0 ? x : gcd(y, x % y));- const g = gcd(r.w, r.h);- return `${r.w / g}:${r.h / g}`;+ const g = gcd(w, h);+ w /= g;+ h /= g;+ if (w > 999 || h > 999) return null;+ return `${w}:${h}`;}/** Output frame in pixels. The short side is pinned to 1080 — the design@@ -43,13 +52,13 @@ export function frameOf(aspect: Aspect): { w: number; h: number } {return r.w >= r.h ? { w: long, h: 1080 } : { w: 1080, h: long };}-export const ASPECT_PRESETS: { value: Aspect; name: string; sublabel: string }[] = [+export const ASPECT_PRESETS: { value: Aspect; name: string; sublabel?: string }[] = [{ value: "16:9", name: "Widescreen", sublabel: "YouTube" },- { value: "4:3", name: "Classic", sublabel: "LinkedIn, Facebook ads" },- { value: "2:1", name: "Cinematic", sublabel: "Wide social banners" },{ value: "9:16", name: "Vertical", sublabel: "TikTok, Reels, Shorts" },- { value: "1:1", name: "Square", sublabel: "Instagram posts" },- { value: "3:4", name: "Portrait", sublabel: "Feed photos" },+ { value: "4:3", name: "Classic" },+ { value: "2:1", name: "Cinematic" },+ { value: "1:1", name: "Square" },+ { value: "3:4", name: "Portrait" },];export function aspectLabel(aspect: Aspect): string {diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 168236a8..42462400 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -709,8 +709,8 @@ export const AI_TOOLS: AiToolDef[] = [{name: "set_aspect",description:- "Set the project's output frame ratio as \"W:H\". Presets: 16:9 (YouTube), 9:16 (TikTok/Reels/Shorts), 1:1, 4:3, 3:4, 2:1 — but any whole-number ratio up to a 4:1 shape works (e.g. \"9:5\" for a custom screen). The frame renders with its short side at 1080px: 9:16 → 1080×1920, 16:9 → 1920×1080, 9:5 → 1944×1080.",- inputSchema: obj({ aspect: { type: "string", description: "Output ratio as \"W:H\", e.g. \"9:16\", \"16:9\", \"1:1\", \"9:5\"" } }, ["aspect"]),+ "Set the project's output frame ratio as \"W:H\". Presets: 16:9 (YouTube), 9:16 (TikTok/Reels/Shorts), 1:1, 4:3, 3:4, 2:1 — but any ratio up to an 8:1 shape works, with whole or decimal sides (\"9:5\", \"2.39:1\" — stored reduced, so 2.39:1 becomes 239:100). The frame renders with its short side at 1080px: 9:16 → 1080×1920, 16:9 → 1920×1080, 9:5 → 1944×1080.",+ inputSchema: obj({ aspect: { type: "string", description: "Output ratio as \"W:H\", e.g. \"9:16\", \"1:1\", \"9:5\", \"2.39:1\"" } }, ["aspect"]),},{name: "set_project_fade",