Open source CapCut alternative.
TypeScript
feat(site): eight-grip resize on every box
David Le96a51d677ff4
diff --git a/site/src/cut/components/ColorField.tsx b/site/src/cut/components/ColorField.tsxnew file mode 100644index 00000000..0e57221a--- /dev/null+++ b/site/src/cut/components/ColorField.tsx@@ -0,0 +1,435 @@+"use client";++import { useRef, useState } from "react";+import { Check, Pipette } from "lucide-react";+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { parsePercentInput, ScrubValue } from "@/cut/components/ScrubValue";+import { cn } from "@/lib/utils";++/** The named colors every color field offers. */+export const COLOR_PRESETS: { hex: string; name: string }[] = [+ { hex: "#FFFFFF", name: "White" },+ { hex: "#111114", name: "Black" },+ { hex: "#8E8E93", name: "Grey" },+ { hex: "#FF375F", name: "Red" },+ { hex: "#FF9F0A", name: "Orange" },+ { hex: "#FFD60A", name: "Yellow" },+ { hex: "#30D158", name: "Green" },+ { hex: "#0A84FF", name: "Blue" },+ { hex: "#BF5AF2", name: "Purple" },+];++/** Colors the user picked by hand, newest first. */+const RECENT_COLORS_KEY = "cut-recent-colors";+const RECENT_LIMIT = 8;++export function readRecentColors(): string[] {+ if (typeof window === "undefined") return [];+ try {+ const v = JSON.parse(localStorage.getItem(RECENT_COLORS_KEY) ?? "[]") as unknown;+ return Array.isArray(v)+ ? v.filter((x): x is string => typeof x === "string").slice(0, RECENT_LIMIT)+ : [];+ } catch {+ return [];+ }+}++function writeRecentColors(list: string[]) {+ try {+ localStorage.setItem(RECENT_COLORS_KEY, JSON.stringify(list));+ } catch {+ // Storage full or blocked — recents just won't persist.+ }+}++/** "#abc", "abc", "AABBCC" → "#AABBCC". Anything else is null. */+export function parseHex(raw: string): string | null {+ const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(raw.trim());+ if (!m) return null;+ const h = m[1];+ return `#${(h.length === 3 ? [...h].map((c) => c + c).join("") : h).toUpperCase()}`;+}++const safeHex = (raw: string) => parseHex(raw) ?? "#FFFFFF";++type Hsv = { h: number; s: number; v: number };++function hexToHsv(hex: string): Hsv {+ const n = parseInt(hex.slice(1), 16);+ const r = ((n >> 16) & 255) / 255;+ const g = ((n >> 8) & 255) / 255;+ const b = (n & 255) / 255;+ const max = Math.max(r, g, b);+ const min = Math.min(r, g, b);+ const d = max - min;+ let h = 0;+ if (d) {+ if (max === r) h = ((g - b) / d) % 6;+ else if (max === g) h = (b - r) / d + 2;+ else h = (r - g) / d + 4;+ h = (h * 60 + 360) % 360;+ }+ return { h, s: max ? d / max : 0, v: max };+}++function hsvToHex({ h, s, v }: Hsv): string {+ const hue = ((h % 360) + 360) % 360;+ const c = v * s;+ const x = c * (1 - Math.abs(((hue / 60) % 2) - 1));+ const m = v - c;+ const [r, g, b] = [+ [c, x, 0],+ [x, c, 0],+ [0, c, x],+ [0, x, c],+ [x, 0, c],+ [c, 0, x],+ ][Math.floor(hue / 60) % 6];+ const ch = (t: number) =>+ Math.round((t + m) * 255)+ .toString(16)+ .padStart(2, "0");+ return `#${ch(r)}${ch(g)}${ch(b)}`.toUpperCase();+}++const clamp01 = (n: number) => Math.min(1, Math.max(0, n));++/**+ * The compact color control: a swatch that opens the picker, the hex readout+ * that opens the presets and recents list, and an optional opacity readout —+ * one row where a strip of swatches used to sit. `onBegin` marks an undo+ * checkpoint, `onLive` streams a drag, `onCommit` sets a final pick.+ */+export function ColorField({+ value,+ onBegin,+ onLive,+ onCommit,+ opacity,+ label = "Color",+ className,+}: {+ value: string;+ onBegin: () => void;+ onLive: (hex: string) => void;+ onCommit: (hex: string) => void;+ /** Folds the paired opacity into the same row. Omit for opaque colors. */+ opacity?: {+ value: number;+ label: string;+ onDraft: (v: number) => void;+ onCommit: (v: number) => void;+ };+ label?: string;+ className?: string;+}) {+ const [pickerOpen, setPickerOpen] = useState(false);+ const [listOpen, setListOpen] = useState(false);+ const hex = safeHex(value);++ const commit = (next: string) => {+ if (!COLOR_PRESETS.some((p) => p.hex === next)) {+ writeRecentColors([next, ...readRecentColors().filter((r) => r !== next)].slice(0, RECENT_LIMIT));+ }+ onCommit(next);+ };++ return (+ <div+ className={cn(+ "color-field flex h-7 shrink-0 items-center gap-1.5 rounded-md bg-secondary/60 pr-1.5 pl-1",+ className+ )}+ >+ <Popover open={pickerOpen} onOpenChange={setPickerOpen}>+ <PopoverTrigger+ aria-label={`${label} — open the picker`}+ title="Pick a color"+ className="color-field-swatch size-5 shrink-0 rounded-[5px] shadow-xs ring-1 ring-border transition-transform outline-none hover:scale-105 focus-visible:ring-2 focus-visible:ring-primary/60"+ style={{ background: hex }}+ />+ <PopoverContent side="bottom" align="end" sideOffset={6} className="w-56 p-2.5">+ <ColorPicker value={hex} onBegin={onBegin} onLive={onLive} onCommit={commit} />+ </PopoverContent>+ </Popover>+ <Popover open={listOpen} onOpenChange={setListOpen}>+ <PopoverTrigger+ aria-label={`${label} — open the list`}+ className="color-field-value w-[7ch] shrink-0 rounded-sm text-left font-mono text-[11.5px] tabular-nums text-foreground uppercase outline-none focus-visible:ring-2 focus-visible:ring-primary/60"+ >+ {hex.slice(1)}+ </PopoverTrigger>+ <PopoverContent side="bottom" align="end" sideOffset={6} className="w-56 p-1">+ <ColorList+ value={hex}+ onPick={(c) => {+ commit(c);+ setListOpen(false);+ }}+ />+ </PopoverContent>+ </Popover>+ {opacity && (+ <ScrubValue+ label={opacity.label}+ className="w-[4.5ch] text-muted-foreground"+ value={opacity.value}+ min={0}+ max={1}+ step={0.01}+ format={(v) => `${Math.round(v * 100)}%`}+ parse={parsePercentInput}+ onScrub={opacity.onDraft}+ onCommit={opacity.onCommit}+ />+ )}+ </div>+ );+}++/** Saturation/value pad, hue rail, hex entry, and the eyedropper. */+function ColorPicker({+ value,+ onBegin,+ onLive,+ onCommit,+}: {+ value: string;+ onBegin: () => void;+ onLive: (hex: string) => void;+ onCommit: (hex: string) => void;+}) {+ // The pad keeps its own hue and saturation: at pure black or white hex can+ // no longer carry them, so a drag through the corner would lose the color.+ // A value the pad did not author (a list pick, an undo) resets it.+ const [pad, setPad] = useState(() => ({ hex: value, hsv: hexToHsv(value) }));+ if (pad.hex !== value) setPad({ hex: value, hsv: hexToHsv(value) });+ const hsv = pad.hsv;++ const push = (next: Hsv) => {+ const hex = hsvToHex(next);+ setPad({ hex, hsv: next });+ onLive(hex);+ };++ const hueCss = `hsl(${Math.round(hsv.h)} 100% 50%)`;++ return (+ <div className="flex flex-col gap-2.5">+ <DragArea+ label="Saturation and brightness"+ className="relative h-28 w-full cursor-crosshair rounded-md ring-1 ring-border"+ style={{+ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, ${hueCss})`,+ }}+ onStart={onBegin}+ onDrag={(x, y) => push({ ...hsv, s: x, v: 1 - y })}+ onEnd={() => onCommit(hsvToHex(hsv))}+ >+ <Handle color={value} left={hsv.s} top={1 - hsv.v} />+ </DragArea>+ <DragArea+ label="Hue"+ className="relative h-3 w-full cursor-ew-resize rounded-full ring-1 ring-border"+ style={{+ background:+ "linear-gradient(to right, #FF0000, #FFFF00, #00FF00, #00FFFF, #0000FF, #FF00FF, #FF0000)",+ }}+ onStart={onBegin}+ onDrag={(x) => push({ ...hsv, h: x * 360 })}+ onEnd={() => onCommit(hsvToHex(hsv))}+ >+ <Handle color={hueCss} left={hsv.h / 360} top={0.5} />+ </DragArea>+ <div className="flex items-center gap-1.5">+ <HexInput value={value} onCommit={onCommit} className="h-7 flex-1" />+ <Eyedropper+ onPick={(hex) => {+ onBegin();+ onCommit(hex);+ }}+ />+ </div>+ </div>+ );+}++function Handle({ color, left, top }: { color: string; left: number; top: number }) {+ return (+ <span+ className="pointer-events-none absolute size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_rgba(0,0,0,0.35)]"+ style={{ left: `${left * 100}%`, top: `${top * 100}%`, background: color }}+ />+ );+}++/** Pointer-captured 2D track: reports the grab as fractions of its own box. */+function DragArea({+ label,+ className,+ style,+ onStart,+ onDrag,+ onEnd,+ children,+}: {+ label: string;+ className?: string;+ style?: React.CSSProperties;+ onStart: () => void;+ onDrag: (x: number, y: number) => void;+ onEnd: () => void;+ children: React.ReactNode;+}) {+ const active = useRef(false);+ const emit = (el: HTMLElement, clientX: number, clientY: number) => {+ const r = el.getBoundingClientRect();+ onDrag(clamp01((clientX - r.left) / r.width), clamp01((clientY - r.top) / r.height));+ };+ return (+ <div+ aria-label={label}+ className={cn("touch-none select-none", className)}+ style={style}+ onPointerDown={(e) => {+ if (e.button !== 0) return;+ active.current = true;+ e.currentTarget.setPointerCapture(e.pointerId);+ onStart();+ emit(e.currentTarget, e.clientX, e.clientY);+ }}+ onPointerMove={(e) => {+ if (active.current) emit(e.currentTarget, e.clientX, e.clientY);+ }}+ onPointerUp={(e) => {+ if (!active.current) return;+ active.current = false;+ e.currentTarget.releasePointerCapture(e.pointerId);+ onEnd();+ }}+ onPointerCancel={() => {+ if (!active.current) return;+ active.current = false;+ onEnd();+ }}+ >+ {children}+ </div>+ );+}++/** The presets and the user's recent picks, current value checked. */+function ColorList({ value, onPick }: { value: string; onPick: (hex: string) => void }) {+ const [recents] = useState(readRecentColors);+ const items = [+ ...COLOR_PRESETS,+ ...recents.filter((r) => !COLOR_PRESETS.some((p) => p.hex === r)).map((hex) => ({ hex, name: hex.slice(1) })),+ ];++ return (+ <div className="flex flex-col gap-1">+ <HexInput value={value} onCommit={onPick} autoFocus className="h-8" />+ <div className="max-h-64 overflow-y-auto">+ {items.map((c) => (+ <button+ key={c.hex}+ type="button"+ className="flex h-8 w-full items-center gap-2.5 rounded-md px-2 text-[12.5px] transition-colors hover:bg-secondary"+ onClick={() => onPick(c.hex)}+ >+ <span+ className="size-4 shrink-0 rounded-[4px] ring-1 ring-border"+ style={{ background: c.hex }}+ />+ <span className="min-w-0 truncate">{c.name}</span>+ {value === c.hex && <Check className="ml-auto size-3.5 shrink-0 text-muted-foreground" />}+ </button>+ ))}+ </div>+ </div>+ );+}++/** Hex entry that only reports what parses; garbage snaps back on blur. */+function HexInput({+ value,+ onCommit,+ autoFocus,+ className,+}: {+ value: string;+ onCommit: (hex: string) => void;+ autoFocus?: boolean;+ className?: string;+}) {+ const [entry, setEntry] = useState({ hex: value, draft: value.slice(1) });+ if (entry.hex !== value) setEntry({ hex: value, draft: value.slice(1) });+ const setDraft = (draft: string) => setEntry({ hex: value, draft });++ const commit = () => {+ const hex = parseHex(entry.draft);+ if (hex && hex !== value) onCommit(hex);+ else setDraft(value.slice(1));+ };++ return (+ <div+ className={cn(+ "flex items-center gap-2 rounded-md bg-secondary/60 px-2 focus-within:ring-1 focus-within:ring-primary/60",+ className+ )}+ >+ <span+ className="size-4 shrink-0 rounded-[4px] ring-1 ring-border"+ style={{ background: value }}+ />+ <input+ aria-label="Hex color"+ autoFocus={autoFocus}+ value={entry.draft}+ spellCheck={false}+ className="w-full min-w-0 bg-transparent font-mono text-[11.5px] tabular-nums uppercase outline-none"+ onChange={(e) => setDraft(e.target.value)}+ onFocus={(e) => e.currentTarget.select()}+ onBlur={commit}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ commit();+ } else if (e.key === "Escape") {+ setDraft(value.slice(1));+ }+ }}+ />+ </div>+ );+}++type EyeDropperCtor = new () => { open(): Promise<{ sRGBHex: string }> };++/** Screen sampling, on the browsers that carry the EyeDropper API. */+function Eyedropper({ onPick }: { onPick: (hex: string) => void }) {+ const [supported] = useState(() => typeof window !== "undefined" && "EyeDropper" in window);+ if (!supported) return null;+ return (+ <button+ type="button"+ aria-label="Sample a color from the screen"+ title="Sample a color from the screen"+ className="grid size-7 shrink-0 place-items-center rounded-md bg-secondary/60 text-muted-foreground transition-colors hover:text-foreground"+ onClick={async () => {+ const Ctor = (window as unknown as { EyeDropper: EyeDropperCtor }).EyeDropper;+ try {+ const { sRGBHex } = await new Ctor().open();+ const hex = parseHex(sRGBHex);+ if (hex) onPick(hex);+ } catch {+ // Dismissed.+ }+ }}+ >+ <Pipette className="size-3.5" />+ </button>+ );+}diff --git a/site/src/cut/components/NumberField.tsx b/site/src/cut/components/NumberField.tsxnew file mode 100644index 00000000..0b64c6d7--- /dev/null+++ b/site/src/cut/components/NumberField.tsx@@ -0,0 +1,166 @@+"use client";++import { useRef, useState } from "react";+import { Check, ChevronDown } from "lucide-react";+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { cn } from "@/lib/utils";+import { snapNear } from "@/lib/snap";++/**+ * A numeric setting as one compact box: a glyph that scrubs on drag, a field+ * that takes a typed value, and an optional chevron holding the common values+ * for the setting. It carries what a label + slider + readout used to, in a+ * third of the width, so several settings fit one row.+ *+ * `onDraft` streams a drag (pair it with a transient updater that checkpoints+ * history on the first call); `onCommit` closes it.+ */+export function NumberField({+ label,+ value,+ min,+ max,+ step,+ snap,+ format,+ parse,+ onDraft,+ onCommit,+ presets,+ icon,+ className,+}: {+ label: string;+ value: number;+ min: number;+ max: number;+ step: number;+ /** Detent values a drag lands on exactly. Typed and picked values stay exact. */+ snap?: number[];+ format: (v: number) => string;+ parse: (raw: string) => number | null;+ onDraft: (v: number) => void;+ onCommit: (v: number) => void;+ /** Offered under the chevron. Omit for a field with no menu. */+ presets?: number[];+ /** Drag handle. Omit for a field that only takes typed and picked values. */+ icon?: React.ReactNode;+ className?: string;+}) {+ const [entry, setEntry] = useState({ value, draft: format(value) });+ const [open, setOpen] = useState(false);+ const drag = useRef<{ startX: number; startValue: number; last: number } | null>(null);+ // A drag rewrites the value under the field; the box follows it, and any+ // value it did not author (a preset pick, an undo) resets the draft.+ if (entry.value !== value) setEntry({ value, draft: format(value) });++ const clamp = (v: number) => Math.min(max, Math.max(min, v));++ const commitDraft = () => {+ const parsed = parse(entry.draft);+ if (parsed != null && Number.isFinite(parsed)) onCommit(clamp(parsed));+ else setEntry({ value, draft: format(value) });+ };++ const stepBy = (dir: number, coarse: boolean) => {+ const parsed = parse(entry.draft);+ const base = parsed != null && Number.isFinite(parsed) ? parsed : value;+ onCommit(clamp(base + dir * step * (coarse ? 10 : 1)));+ };++ return (+ <div+ className={cn(+ "number-field flex h-7 min-w-0 items-center gap-1 rounded-md bg-secondary/60 pr-0.5 pl-1.5 focus-within:ring-1 focus-within:ring-primary/60",+ className+ )}+ >+ {icon && (+ <span+ aria-hidden+ title="Drag to adjust"+ className="grid shrink-0 cursor-ew-resize touch-none place-items-center text-muted-foreground [&_svg]:size-3.5"+ onPointerDown={(e) => {+ if (e.button !== 0) return;+ drag.current = { startX: e.clientX, startValue: value, last: value };+ e.currentTarget.setPointerCapture(e.pointerId);+ }}+ onPointerMove={(e) => {+ const d = drag.current;+ if (!d) return;+ // 2px per step; Shift coarsens to ×10.+ let next = clamp(d.startValue + ((e.clientX - d.startX) / 2) * step * (e.shiftKey ? 10 : 1));+ if (snap) next = clamp(snapNear(next, snap, min, max));+ d.last = next;+ onDraft(next);+ }}+ onPointerUp={(e) => {+ const d = drag.current;+ drag.current = null;+ e.currentTarget.releasePointerCapture(e.pointerId);+ if (d) onCommit(d.last);+ }}+ onPointerCancel={() => {+ const d = drag.current;+ drag.current = null;+ if (d) onCommit(d.last);+ }}+ >+ {icon}+ </span>+ )}+ <input+ aria-label={label}+ value={entry.draft}+ inputMode="decimal"+ spellCheck={false}+ className="w-full min-w-0 bg-transparent font-mono text-[11.5px] tabular-nums outline-none"+ onChange={(e) => setEntry({ value, draft: e.target.value })}+ onFocus={(e) => e.currentTarget.select()}+ onBlur={commitDraft}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ commitDraft();+ e.currentTarget.blur();+ } else if (e.key === "Escape") {+ setEntry({ value, draft: format(value) });+ } else if (e.key === "ArrowUp" || e.key === "ArrowDown") {+ e.preventDefault();+ stepBy(e.key === "ArrowUp" ? 1 : -1, e.shiftKey);+ }+ }}+ />+ {presets && presets.length > 0 && (+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger+ aria-label={`${label} presets`}+ className="grid size-6 shrink-0 place-items-center rounded-[5px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary/60"+ >+ <ChevronDown className="size-3.5" />+ </PopoverTrigger>+ <PopoverContent side="bottom" align="end" sideOffset={6} className="w-28 p-1">+ <div className="max-h-64 overflow-y-auto">+ {presets.map((p) => (+ <button+ key={p}+ type="button"+ className="flex h-7 w-full items-center rounded-md px-2 font-mono text-[11.5px] tabular-nums transition-colors hover:bg-secondary"+ onClick={() => {+ onCommit(clamp(p));+ setOpen(false);+ }}+ >+ {format(p)}+ {Math.abs(p - value) < step / 2 && (+ <Check className="ml-auto size-3.5 text-muted-foreground" />+ )}+ </button>+ ))}+ </div>+ </PopoverContent>+ </Popover>+ )}+ </div>+ );+}diff --git a/site/src/cut/components/PanelTile.tsx b/site/src/cut/components/PanelTile.tsxindex 26277acd..9f92d795 100644--- a/site/src/cut/components/PanelTile.tsx+++ b/site/src/cut/components/PanelTile.tsx@@ -29,7 +29,8 @@ export function Tile({onClick: () => void;/** Pointer entering or leaving — a tile whose preview only plays on hover. */onHover?: (inside: boolean) => void;- label: string;+ /** Caption under the preview; a tile whose preview is the name skips it. */+ label?: string;className?: string;/** A tile that places something by being dragged onto the timeline. */draggable?: boolean;@@ -60,7 +61,7 @@ export function Tile({onClick={onClick}>{children}- <span className="leading-none">{label}</span>+ {label && <span className="leading-none">{label}</span>}</button>);}diff --git a/site/src/cut/components/Preview.tsx b/site/src/cut/components/Preview.tsxindex d49695d2..db126a66 100644--- a/site/src/cut/components/Preview.tsx+++ b/site/src/cut/components/Preview.tsx@@ -22,7 +22,8 @@ import { setPreviewCanvas } from "@/cut/lib/previewCanvas";import { clipKeyed, clipPoseAt, frameOf, isFullRect, rectOf, REGION_MAX_SCALE, type Aspect, type ClipSpan, type FrameRect, type MediaAsset, type VideoClip } from "@/cut/lib/types";import { hasMaskKeys, type MaskKey } from "@donkeycut/effects-kit";import { cn } from "@/lib/utils";-import { Grip, MaskGizmoCore, OverlayLayer } from "./OverlayLayer";+import { MaskGizmoCore, OverlayLayer } from "./OverlayLayer";+import { HANDLE_AXIS, TransformHandles, type ResizeHandle } from "./TransformHandles";import {StageEffectPaint,StagePictureFx,@@ -441,19 +442,43 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {});};- const onResize = (e: React.PointerEvent) => {+ // A grip drags its own edges and leaves the opposite ones where they are:+ // the box keeps its far corner planted while the grabbed side travels, and+ // a moving edge snaps to the frame the same way a move does.+ const onResize = (handle: ResizeHandle, e: React.PointerEvent) => {e.stopPropagation();useEditor.getState().pushHistory();+ const a = HANDLE_AXIS[handle];startDrag(e, {onMove: (dx, dy) => {- let w = Math.max(0.1, Math.min(REGION_MAX_SCALE, r.w + dx / stage.w));- let h = Math.max(0.1, Math.min(REGION_MAX_SCALE, r.h + dy / stage.h));- const gx = snapEdge(r.x + w, SNAP_PX / stage.w);- const gy = snapEdge(r.y + h, SNAP_PX / stage.h);- if (gx !== null && gx - r.x >= 0.1) w = gx - r.x;- if (gy !== null && gy - r.y >= 0.1) h = gy - r.y;- setGuides({ x: gx !== null && gx - r.x >= 0.1 ? gx : null, y: gy !== null && gy - r.y >= 0.1 ? gy : null });- patch({ ...r, w, h });+ // One axis at a time: where the grabbed edge lands, snapped to the+ // frame, then the span it leaves against the planted edge.+ const pull = (+ dir: -1 | 0 | 1,+ pos: number,+ size: number,+ d: number,+ stageSize: number+ ) => {+ if (!dir) return { pos, size, guide: null as number | null };+ const far = dir > 0 ? pos : pos + size;+ const edge = (dir > 0 ? pos + size : pos) + d / stageSize;+ const snapped = snapEdge(edge, SNAP_PX / stageSize);+ const at = snapped ?? edge;+ // Signed: a grip dragged past the planted edge stops at the floor and+ // the box keeps its side.+ const span = dir > 0 ? at - far : far - at;+ const next = Math.max(0.1, Math.min(REGION_MAX_SCALE, span));+ return {+ pos: dir > 0 ? far : far - next,+ size: next,+ guide: snapped !== null && next === span ? snapped : null,+ };+ };+ const hx = pull(a.x, r.x, r.w, dx, stage.w);+ const hy = pull(a.y, r.y, r.h, dy, stage.h);+ setGuides({ x: hx.guide, y: hy.guide });+ patch({ ...r, x: hx.pos, w: hx.size, y: hy.pos, h: hy.size });},onUp: () => setGuides({ x: null, y: null }),});@@ -505,11 +530,7 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {onPointerDown={onPanContent}/>)}- <Grip- color="#0a84ff"- className="absolute -right-2 -bottom-2 z-20 cursor-nwse-resize"- onPointerDown={onResize}- />+ <TransformHandles color="#0a84ff" className="z-20" onResize={onResize} /></div><div className="pointer-events-none absolute inset-0 z-10 overflow-hidden rounded-xl"><divdiff --git a/site/src/cut/components/SubtitlesPanel.tsx b/site/src/cut/components/SubtitlesPanel.tsxindex e6a6ebd1..6d940c4c 100644--- a/site/src/cut/components/SubtitlesPanel.tsx+++ b/site/src/cut/components/SubtitlesPanel.tsx@@ -11,6 +11,7 @@ import {SelectValue,} from "@/components/ui/select";import { Switch } from "@/components/ui/switch";+import { ColorField } from "@/cut/components/ColorField";import { parseNumberInput } from "@/cut/components/ScrubValue";import { ValueSlider } from "@/cut/components/ValueSlider";import { GenerateSubtitlesAudio } from "@/cut/components/VoicePicker";@@ -189,9 +190,6 @@ export function SubtitlesPanel() {);}-/** Accent colors offered for the spoken word. */-const ACCENTS = ["#FFE94A", "#FFFFFF", "#FF375F", "#0A84FF", "#30D158"];-const ACCENT_MODES: { id: WordAccentMode; label: string }[] = [{ id: "color", label: "Color" },{ id: "underline", label: "Underline" },@@ -303,37 +301,14 @@ function OptionsTab() {</div><div className="flex min-h-8 items-center justify-between text-xs font-medium">Word color- <div className="sub-accent-color flex items-center gap-1.5">- {ACCENTS.map((c) => (- <button- key={c}- title={c}- aria-label={`Word color ${c}`}- className={cn(- "size-5 rounded-full border border-black/15 transition-transform hover:scale-110",- look.color.toUpperCase() === c.toUpperCase() &&- "ring-2 ring-primary ring-offset-2 ring-offset-card"- )}- style={{ background: c }}- onClick={() => useEditor.getState().setSubtitlesView({ accentColor: c })}- />- ))}- <label- title="Custom color"- className="relative size-5 cursor-pointer rounded-full border border-black/15 bg-[conic-gradient(from_0deg,#f43f5e,#f59e0b,#84cc16,#06b6d4,#6366f1,#d946ef,#f43f5e)] transition-transform hover:scale-110"- >- <span className="absolute inset-1 rounded-full bg-card" />- <span className="absolute inset-[5px] rounded-full" style={{ background: look.color }} />- <input- type="color"- aria-label="Pick a custom word color"- className="absolute inset-0 size-full cursor-pointer opacity-0"- value={/^#[0-9a-fA-F]{6}$/.test(look.color) ? look.color : "#ffffff"}- onChange={(e) =>- useEditor.getState().setSubtitlesView({ accentColor: e.target.value })- }- />- </label>+ <div className="sub-accent-color flex items-center">+ <ColorField+ value={look.color}+ label="Word color"+ onBegin={() => useEditor.getState().pushHistory()}+ onLive={(c) => useEditor.getState().setSubtitlesView({ accentColor: c })}+ onCommit={(c) => useEditor.getState().setSubtitlesView({ accentColor: c })}+ /></div></div></>diff --git a/site/src/cut/components/TransformHandles.tsx b/site/src/cut/components/TransformHandles.tsxnew file mode 100644index 00000000..379646f5--- /dev/null+++ b/site/src/cut/components/TransformHandles.tsx@@ -0,0 +1,135 @@+"use client";++import type { CSSProperties } from "react";+import { RefreshCw } from "lucide-react";+import { cn } from "@/lib/utils";++/**+ * The selection frame every resizable thing on the stage wears: a grip at each+ * corner, one on each side, and a rotate button above the top edge that reads+ * out the angle while it turns. The frame draws and routes gestures; what a+ * drag means belongs to the caller, which gets the grabbed handle and decides+ * what it resizes.+ */++/** Which grip a gesture grabbed. Corners pull both axes, the side pair pulls+ * width, the top/bottom pair pulls height. */+export type ResizeHandle = "nw" | "n" | "ne" | "e" | "se" | "s" | "sw" | "w";++/** The default set: four corners and the two side grips. */+export const BOX_HANDLES: ResizeHandle[] = ["nw", "ne", "se", "sw", "w", "e"];+/** Corners alone, for a box whose axes are locked together. */+export const CORNER_HANDLES: ResizeHandle[] = ["nw", "ne", "se", "sw"];++/** Which way a grip pulls, in the box's own space: -1/0/1 per axis, which is+ * also its position on the frame (0 = the middle of that axis). */+export const HANDLE_AXIS: Record<ResizeHandle, { x: -1 | 0 | 1; y: -1 | 0 | 1 }> = {+ nw: { x: -1, y: -1 },+ n: { x: 0, y: -1 },+ ne: { x: 1, y: -1 },+ e: { x: 1, y: 0 },+ se: { x: 1, y: 1 },+ s: { x: 0, y: 1 },+ sw: { x: -1, y: 1 },+ w: { x: -1, y: 0 },+};++const CURSORS = ["ew-resize", "nwse-resize", "ns-resize", "nesw-resize"];++/** The cursor for a grip on a box turned by `rotation`: the direction it pulls+ * on screen, rounded to the nearest of the four resize cursors. */+export function resizeCursor(handle: ResizeHandle, rotation = 0): string {+ const a = HANDLE_AXIS[handle];+ const deg = (Math.atan2(a.y, a.x) * 180) / Math.PI + rotation;+ return CURSORS[((Math.round(deg / 45) % 4) + 4) % 4];+}++export function TransformHandles({+ color = "#0a84ff",+ handles = BOX_HANDLES,+ rotation = 0,+ angle = null,+ onResize,+ onRotate,+ frame,+ className,+ rotateGap = 32,+ rotateCursor,+ resizeTitle = "Drag to resize",+ rotateTitle = "Drag to rotate",+}: {+ /** Ring color on every grip; the chrome it belongs to picks it. */+ color?: string;+ /** Which grips to draw. */+ handles?: ResizeHandle[];+ /** The box's on-screen angle: cursors point the way a drag pulls, and the+ * rotate button counter-turns so its readout stays upright. */+ rotation?: number;+ /** Degrees to show in the readout; null while nothing is turning. */+ angle?: number | null;+ onResize?: (handle: ResizeHandle, e: React.PointerEvent) => void;+ onRotate?: (e: React.PointerEvent) => void;+ /** Absolute placement for the frame; absent means the parent's own box. */+ frame?: CSSProperties;+ className?: string;+ /** Screen px between the top edge and the rotate button. */+ rotateGap?: number;+ /** Cursor CSS for the rotate button. */+ rotateCursor?: string;+ resizeTitle?: string;+ rotateTitle?: string;+}) {+ return (+ <div+ className={cn("pointer-events-none absolute", !frame && "inset-0", className)}+ style={frame}+ >+ {onRotate && (+ <div className="absolute left-1/2 top-0">+ <div+ className="relative"+ style={{ transform: `translate(-50%, -50%) rotate(${-rotation}deg)`, top: -rotateGap }}+ >+ {angle !== null && (+ <span className="absolute bottom-full left-1/2 mb-1.5 -translate-x-1/2 rounded-full bg-black/55 px-2 py-0.5 text-[11px] font-medium tabular-nums text-white">+ {Math.round(angle)}°+ </span>+ )}+ <span+ title={rotateTitle}+ onPointerDown={onRotate}+ style={{ cursor: rotateCursor ?? "grab" }}+ className="pointer-events-auto grid size-[22px] place-items-center rounded-full bg-white text-neutral-700 shadow-[0_1px_4px_rgba(0,0,0,0.4)]"+ >+ <RefreshCw className="size-3" strokeWidth={2.25} />+ </span>+ </div>+ </div>+ )}+ {onResize &&+ handles.map((h) => {+ const a = HANDLE_AXIS[h];+ const side = a.x === 0 || a.y === 0;+ return (+ <span+ key={h}+ title={resizeTitle}+ onPointerDown={(e) => onResize(h, e)}+ className={cn(+ "pointer-events-auto absolute rounded-full border-[2.5px] bg-white shadow-[0_1px_4px_rgba(0,0,0,0.4)]",+ !side && "size-[13px]",+ side && (a.x === 0 ? "h-[9px] w-[20px]" : "h-[20px] w-[9px]")+ )}+ style={{+ left: `${(a.x + 1) * 50}%`,+ top: `${(a.y + 1) * 50}%`,+ transform: "translate(-50%, -50%)",+ borderColor: color,+ cursor: resizeCursor(h, rotation),+ }}+ />+ );+ })}+ </div>+ );+}