Open source CapCut alternative.
TypeScript
feat(cut): aspect picker with presets and custom ratio
David Leaac9ca259ae5
diff --git a/site/src/cut/components/TopBar.tsx b/site/src/cut/components/TopBar.tsxindex 6d406b2c..0e2baf83 100644--- a/site/src/cut/components/TopBar.tsx+++ b/site/src/cut/components/TopBar.tsx@@ -2,7 +2,7 @@import { useState } from "react";import Link from "next/link";-import { Check, ChevronDown, ChevronLeft, Cloud, Loader2, Mic, Monitor, Share2, Smartphone, Sparkles, Square, Upload, Video } from "lucide-react";+import { Check, ChevronDown, ChevronLeft, Cloud, Loader2, Mic, Monitor, Ratio, Share2, Smartphone, Sparkles, Square, Upload, Video } from "lucide-react";import { Button } from "@/components/ui/button";import {Dialog,@@ -17,6 +17,8 @@ import {DropdownMenuItem,DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";+import { Input } from "@/components/ui/input";+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { cloudBackend } from "@/cut/lib/backend/cloud";import { useCutMode } from "@/cut/lib/backend/hooks";import { localBackend } from "@/cut/lib/backend/local";@@ -24,7 +26,7 @@ import { useWebMode } from "@/cut/lib/flags";import { backTarget, projectHref, useCutBase } from "@/cut/lib/nav";import { copyProjectAcross } from "@/cut/lib/projectCopy";import { useEditor } from "@/cut/lib/store";-import { ASPECT_PRESETS, aspectLabel, aspectOrientation, type Aspect } from "@/cut/lib/types";+import { ASPECT_PRESETS, aspectLabel, aspectOrientation, frameOf, parseRatio, type Aspect } from "@/cut/lib/types";import { cn } from "@/lib/utils";import { RecordDialog, type RecordMode } from "./RecordDialog";import { ShareDialog } from "./ShareDialog";@@ -59,6 +61,16 @@ export function TopBar({const [editing, setEditing] = useState(false);const [draft, setDraft] = useState("");const [recordMode, setRecordMode] = useState<RecordMode | null>(null);+ const isPreset = ASPECT_PRESETS.some((p) => p.value === aspect);+ const [customOpen, setCustomOpen] = useState(false);+ const [customW, setCustomW] = useState("16");+ const [customH, setCustomH] = useState("9");+ const customRatio = parseRatio(`${customW}:${customH}`);+ const applyCustom = () => {+ if (!customRatio) return;+ useEditor.getState().setAspect(`${customRatio.w}:${customRatio.h}`);+ setCustomOpen(false);+ };// "Move to Cloud" (cut-web-mode flag): copies this local project — doc and// every media file — to the cloud, deletes the local original, and reopens@@ -110,25 +122,81 @@ export function TopBar({return (<header className="relative flex items-center justify-between border-b border-border bg-card pr-3 pl-2"><div className="absolute left-1/2 flex -translate-x-1/2 items-center gap-2">- <DropdownMenu>- <DropdownMenuTrigger className="aspect-switch flex items-center gap-1.5 rounded-full border border-border bg-card px-3 py-1.5 text-xs font-medium text-muted-foreground shadow-xs transition-colors hover:text-foreground">- <AspectIcon aspect={aspect} className="size-3.5" />- {aspectLabel(aspect)}- <ChevronDown className="size-3" />- </DropdownMenuTrigger>- <DropdownMenuContent align="start" className="w-56">- {ASPECT_PRESETS.map((p) => (- <DropdownMenuItem key={p.value} onClick={() => useEditor.getState().setAspect(p.value)}>- <AspectIcon aspect={p.value} />- <span className="flex-1">- {p.name} · {p.value}- <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>- ))}- </DropdownMenuContent>- </DropdownMenu>+ <Popover open={customOpen} onOpenChange={setCustomOpen}>+ <div className="relative">+ <DropdownMenu>+ <DropdownMenuTrigger className="aspect-switch flex items-center gap-1.5 rounded-full border border-border bg-card px-3 py-1.5 text-xs font-medium text-muted-foreground shadow-xs transition-colors hover:text-foreground">+ <AspectIcon aspect={aspect} className="size-3.5" />+ {aspectLabel(aspect)}+ <ChevronDown className="size-3" />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start" className="w-56">+ {ASPECT_PRESETS.map((p) => (+ <DropdownMenuItem key={p.value} onClick={() => useEditor.getState().setAspect(p.value)}>+ <AspectIcon aspect={p.value} />+ <span className="flex-1">+ {p.name} · {p.value}+ <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={() => {+ const r = parseRatio(aspect);+ if (r) {+ setCustomW(String(r.w));+ setCustomH(String(r.h));+ }+ setCustomOpen(true);+ }}+ >+ <Ratio />+ <span className="flex-1">+ Custom…+ <span className="block text-[10.5px] text-muted-foreground">+ {isPreset ? "Any width : height" : `Current · ${aspect}`}+ </span>+ </span>+ {!isPreset && <Check className="size-3.5 text-muted-foreground" />}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ {/* Invisible anchor spanning the pill, so the custom-ratio popover+ opens where the menu just was. */}+ <PopoverTrigger className="pointer-events-none absolute inset-0 -z-10" aria-hidden tabIndex={-1} />+ </div>+ <PopoverContent align="start" className="w-56">+ <div className="text-xs font-medium">Custom ratio</div>+ <div className="mt-2 flex items-center gap-1.5">+ <Input+ aria-label="Width"+ inputMode="numeric"+ className="h-8 text-center"+ value={customW}+ onChange={(e) => setCustomW(e.target.value.replace(/\D/g, "").slice(0, 3))}+ onKeyDown={(e) => e.key === "Enter" && applyCustom()}+ />+ <span className="text-xs text-muted-foreground">:</span>+ <Input+ aria-label="Height"+ inputMode="numeric"+ className="h-8 text-center"+ value={customH}+ onChange={(e) => setCustomH(e.target.value.replace(/\D/g, "").slice(0, 3))}+ onKeyDown={(e) => e.key === "Enter" && applyCustom()}+ />+ </div>+ <div className="mt-1.5 text-[10.5px] text-muted-foreground">+ {customRatio+ ? `Frame ${frameOf(`${customRatio.w}:${customRatio.h}`).w} × ${frameOf(`${customRatio.w}:${customRatio.h}`).h}`+ : "Whole numbers, up to a 4:1 shape."}+ </div>+ <Button size="sm" className="mt-2 w-full" disabled={!customRatio} onClick={applyCustom}>+ Apply+ </Button>+ </PopoverContent>+ </Popover><DropdownMenu><DropdownMenuTrigger className="record-switch flex items-center gap-1.5 rounded-full border border-border bg-card px-3 py-1.5 text-xs font-medium text-muted-foreground shadow-xs transition-colors hover:text-foreground"><span className="size-2 rounded-full bg-red-500" aria-hidden />