Skip to content

Open source CapCut alternative.

TypeScript

feat(site): group settings panel for multi-selections

David Lec1bae39d03da
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.md
index cc713380..efd96357 100644
--- a/docs/guides/cut/README.md
+++ b/docs/guides/cut/README.md
@@ -46,7 +46,7 @@ Browser previews use the browser compositor and replace one cached proxy in OPFS
Cloud source media, generated media, and retained exports count toward storage. Derived previews, share cards, and HLS ladders are quota-exempt; staging inputs are temporary. Garbage collection also corrects accounting for older preview and card objects in bounded batches. Transports expose structured storage, credit, and authentication failures. Each host chooses their presentation; the website mounts its storage dialog separately.
-Timeline and preview share selection: ⌘/Ctrl-click or Shift-click toggles items, and dragging moves them together with one undo step. Items move independently until grouped, and groups save with the project.
+Timeline and preview share selection: ⌘/Ctrl-click or Shift-click toggles items, and dragging moves them together with one undo step. Items move independently until grouped, and groups save with the project. On the preview the selection wears one frame whose grips scale the set and whose button turns it, while a drag on any member moves them all. Selecting two or more items opens the group panel: it shows the fields every selected item has, reads a field as Mixed where they differ, and writes each edit to all of them in one undo step.
Guides draw over the preview from the button beside the timeline zoom: thirds, center, safe margins, the short-form keep-out zone where TikTok, Reels and Shorts draw their own UI or crop the sides of a 9:16 frame, and custom lines dragged into place on the preview. They save with the project, snap a dragged element to their edges, never export, and the assistant reads the safe area they leave when it places graphics.
diff --git a/site/src/cut/components/ColorField.tsx b/site/src/cut/components/ColorField.tsx
index 0e57221a..7e90d9f3 100644
--- a/site/src/cut/components/ColorField.tsx
+++ b/site/src/cut/components/ColorField.tsx
@@ -109,6 +109,7 @@ export function ColorField({
opacity,
label = "Color",
className,
+ mixed,
}: {
value: string;
onBegin: () => void;
@@ -120,9 +121,13 @@ export function ColorField({
label: string;
onDraft: (v: number) => void;
onCommit: (v: number) => void;
+ mixed?: boolean;
};
label?: string;
className?: string;
+ /** The items behind the field wear different colors: the swatch shows a
+ * wheel and the readout "Mixed"; a pick lands one color on all of them. */
+ mixed?: boolean;
}) {
const [pickerOpen, setPickerOpen] = useState(false);
const [listOpen, setListOpen] = useState(false);
@@ -147,7 +152,7 @@ export function ColorField({
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 }}
+ style={{ background: mixed ? "conic-gradient(#f43f5e, #f59e0b, #22c55e, #3b82f6, #a855f7, #f43f5e)" : hex }}
/>
<PopoverContent side="bottom" align="end" sideOffset={6} className="w-56 p-2.5">
<ColorPicker value={hex} onBegin={onBegin} onLive={onLive} onCommit={commit} />
@@ -158,7 +163,7 @@ export function ColorField({
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)}
+ {mixed ? <span className="font-sans italic normal-case">Mixed</span> : hex.slice(1)}
</PopoverTrigger>
<PopoverContent side="bottom" align="end" sideOffset={6} className="w-56 p-1">
<ColorList
@@ -180,6 +185,7 @@ export function ColorField({
step={0.01}
format={(v) => `${Math.round(v * 100)}%`}
parse={parsePercentInput}
+ mixed={opacity.mixed}
onScrub={opacity.onDraft}
onCommit={opacity.onCommit}
/>
diff --git a/site/src/cut/components/Editor.tsx b/site/src/cut/components/Editor.tsx
index a4a27da1..f3ee59c4 100644
--- a/site/src/cut/components/Editor.tsx
+++ b/site/src/cut/components/Editor.tsx
@@ -171,18 +171,10 @@ export function Editor({
// and let the preview take the space.
const hasInspector = useEditor((s) => {
if (s.readOnly || s.selection == null) return false;
- if (s.selection.kind === "cue" || s.selection.kind === "transition") return false;
- if (s.multiSelection.length <= 1) return true;
- // A multi-selection (marquee, ⌘-click) has no single item to edit, so the
- // panel stays closed. The exception is a grouped element: selecting it
- // selects its whole group, and the panel edits the clicked member.
- const first = s.multiSelection[0];
- if (first?.kind !== "overlay") return false;
- const gid = s.overlays.find((o) => o.id === first.id)?.groupId;
- if (!gid) return false;
- return s.multiSelection.every(
- (m) => m?.kind === "overlay" && s.overlays.find((o) => o.id === m.id)?.groupId === gid
- );
+ // Two or more items open the group panel over what they share, whatever
+ // was clicked last; one item opens its own panel.
+ if (s.multiSelection.filter((m) => m && m.kind !== "cue" && m.kind !== "transition").length >= 2) return true;
+ return s.selection.kind !== "cue" && s.selection.kind !== "transition";
});
const [importing, setImporting] = useState(0);
// Files being probed and named, plus the ones already placed whose bytes are
diff --git a/site/src/cut/components/FontPicker.tsx b/site/src/cut/components/FontPicker.tsx
index 11081bf5..d6df7103 100644
--- a/site/src/cut/components/FontPicker.tsx
+++ b/site/src/cut/components/FontPicker.tsx
@@ -91,10 +91,14 @@ export function FontPicker({
value,
onChange,
className,
+ mixed,
}: {
value: string;
onChange: (id: string) => void;
className?: string;
+ /** The titles behind the field set in different faces: the field reads
+ * "Mixed" and a pick lands one face on all of them. */
+ mixed?: boolean;
}) {
// The menu re-reads the registry when the bundled families finish registering
// or a shelf font lands (the bump re-renders, and the render re-reads).
@@ -152,7 +156,7 @@ export function FontPicker({
return (
<>
<Select
- value={value}
+ value={mixed ? null : value}
items={Object.fromEntries(fonts.map((f) => [f.id, f.label]))}
onOpenChange={(open) => {
if (open) measure();
@@ -174,7 +178,7 @@ export function FontPicker({
fontSize: rowSize(fontStack(value)),
}}
>
- <SelectValue />
+ <SelectValue placeholder="Mixed" />
</SelectTrigger>
{/* The menu is the field's own width: a face's name sets in a face
that runs wide, and the panel it drops out of is narrow. */}
diff --git a/site/src/cut/components/GroupPanel.tsx b/site/src/cut/components/GroupPanel.tsx
new file mode 100644
index 00000000..972525cf
--- /dev/null
+++ b/site/src/cut/components/GroupPanel.tsx
@@ -0,0 +1,438 @@
+"use client";
+
+import { useMemo } from "react";
+import { Bold, Italic, Type } from "lucide-react";
+import { hasOverlayKeys, lineLikeShape, poseAt } from "@donkeycut/effects-kit";
+import { ColorField } from "@/cut/components/ColorField";
+import { FontPicker } from "@/cut/components/FontPicker";
+import { NumberField } from "@/cut/components/NumberField";
+import { Field, Row, Section, SegGroup, SegToggle, useSliderCheckpoint, Value } from "@/cut/components/panelBits";
+import { parseNumberInput, parsePercentInput, parseSecondsInput, ScrubValue } from "@/cut/components/ScrubValue";
+import { ValueSlider } from "@/cut/components/ValueSlider";
+import { Switch } from "@/components/ui/switch";
+import { selectionCenter, selectionSummary, selectionTranslation, sharedNumber, sharedValue } from "@/cut/lib/groupEdit";
+import { usePreviewTime } from "@/cut/lib/playhead";
+import { clipWindow, maxClipFade, useEditor } from "@/cut/lib/store";
+import { TEXT_SIZES } from "@/cut/lib/textStyle";
+import {
+ clampOverlayPos,
+ clipKeyed,
+ clipPoseAt,
+ isShapeOverlay,
+ isTextOverlay,
+ type AudioClip,
+ type Overlay,
+ type OverlayPatch,
+ type Selection,
+ type ShapeOverlay,
+ type TextOverlay,
+ type VideoClip,
+} from "@/cut/lib/types";
+
+/**
+ * The panel for several items at once: a group, or any multi-selection. It
+ * shows the fields every selected item has, reads a field as one value when
+ * they agree and as Mixed when they differ, and writes every edit to all of
+ * them in one undo step. Fields one kind has and another lacks stay off the
+ * panel, so a selection of shapes and titles edits its transform and nothing
+ * a shape cannot carry.
+ */
+export function GroupPanel({ selection }: { selection: readonly NonNullable<Selection>[] }) {
+ const overlays = useEditor((s) => s.overlays);
+ const clips = useEditor((s) => s.clips);
+ const audios = useEditor((s) => s.audioClips);
+ const items = useMemo(() => {
+ const ids = { overlay: new Set<string>(), clip: new Set<string>(), audio: new Set<string>() };
+ for (const sel of selection) if (sel.kind in ids) ids[sel.kind as keyof typeof ids].add(sel.id);
+ return {
+ overlays: overlays.filter((o) => ids.overlay.has(o.id)),
+ clips: clips.filter((c) => ids.clip.has(c.id)),
+ audios: audios.filter((a) => ids.audio.has(a.id)),
+ };
+ }, [selection, overlays, clips, audios]);
+ const all = [...items.overlays, ...items.clips, ...items.audios];
+ const group = sharedValue(all.map((it) => it.groupId));
+ const title = !group.mixed && group.value ? "Group" : `${all.length} items`;
+ const texts = items.overlays.filter(isTextOverlay);
+ const shapes = items.overlays.filter(isShapeOverlay);
+ const onlyOverlays = !items.clips.length && !items.audios.length;
+ return (
+ <>
+ <div className="flex h-10 shrink-0 items-center px-3.5">
+ <span className="truncate text-sm font-semibold tracking-tight">{title}</span>
+ </div>
+ <div className="flex flex-col gap-1 px-3.5 pb-4">
+ <div className="mb-1 text-[11px] text-muted-foreground">{selectionSummary(items)}</div>
+ {onlyOverlays && texts.length === items.overlays.length && <TextRows texts={texts} />}
+ {onlyOverlays && shapes.length === items.overlays.length && <ShapeRows shapes={shapes} />}
+ {!items.clips.length && !items.overlays.length && <AudioRows audios={items.audios} />}
+ <TransformRows items={items} />
+ </div>
+ </>
+ );
+}
+
+const st = () => useEditor.getState();
+
+/** One write per gesture across every item, in a single undo step. */
+function useGroupWrite() {
+ const ck = useSliderCheckpoint();
+ return {
+ draft(run: () => void) {
+ ck.begin();
+ run();
+ },
+ commit(run: () => void) {
+ ck.begin();
+ run();
+ ck.end();
+ },
+ once(run: () => void) {
+ st().pushHistory();
+ run();
+ },
+ };
+}
+
+const patchOverlays = (overlays: readonly Overlay[], patch: (o: Overlay) => OverlayPatch) =>
+ st().updateOverlaysTransient(overlays.map((o) => ({ id: o.id, patch: patch(o) })));
+const patchClips = (clips: readonly VideoClip[], patch: (c: VideoClip) => Partial<VideoClip>) =>
+ st().updateClipsTransient(clips.map((c) => ({ id: c.id, patch: patch(c) })));
+const patchAudios = (audios: readonly AudioClip[], patch: (a: AudioClip) => Partial<AudioClip>) =>
+ st().updateAudiosTransient(audios.map((a) => ({ id: a.id, patch: patch(a) })));
+
+const SLIDER = { sliderClassName: "data-horizontal:w-24", valueClassName: "w-9 text-muted-foreground" };
+
+function MixedSwitch({ label, values, onChange }: { label: string; values: boolean[]; onChange: (v: boolean) => void }) {
+ const shared = sharedValue(values);
+ return (
+ <Row label={label}>
+ {shared.mixed && <Value className="text-muted-foreground italic">Mixed</Value>}
+ <Switch checked={!shared.mixed && shared.value} onCheckedChange={onChange} aria-label={label} />
+ </Row>
+ );
+}
+
+/**
+ * Position, rotation, opacity and hidden, over whichever of the selection
+ * carries them. Position is the selection's center and moves the whole set
+ * with its offsets kept; rotation and opacity land the same value on each
+ * item. A keyed item takes the edit at the playhead, as its own panel does.
+ */
+function TransformRows({ items }: { items: { overlays: Overlay[]; clips: VideoClip[]; audios: AudioClip[] } }) {
+ const write = useGroupWrite();
+ const now = usePreviewTime();
+ const { overlays, clips, audios } = items;
+ const visual = !audios.length;
+ const local = (o: { start: number; end: number }) => Math.max(0, Math.min(now - o.start, Math.max(0.1, o.end - o.start)));
+ const overlayPose = (o: Overlay) => (hasOverlayKeys(o) ? poseAt(o, local(o)) : { x: o.x, y: o.y, rotation: o.rotation ?? 0, opacity: o.opacity ?? 1 });
+ const clipPose = (c: VideoClip) => {
+ const win = clipWindow(st().clips, st().assets, c.id);
+ const keyed = clipKeyed(c) && win;
+ const pose = keyed ? clipPoseAt(c, local({ start: win.start, end: win.start + win.len })) : { rotation: c.rotation ?? 0, opacity: c.opacity ?? 1 };
+ return { keyed: !!keyed, tLocal: win ? local({ start: win.start, end: win.start + win.len }) : 0, ...pose };
+ };
+ const setOverlay = (o: Overlay, patch: { x?: number; y?: number; rotation?: number; opacity?: number }) => {
+ if (hasOverlayKeys(o)) return st().setOverlayKey(o.id, local(o), patch, { transient: true });
+ const p: OverlayPatch = {};
+ if (patch.x !== undefined) p.x = patch.x;
+ if (patch.y !== undefined) p.y = patch.y;
+ if (patch.rotation !== undefined) p.rotation = patch.rotation === 0 ? undefined : patch.rotation;
+ if (patch.opacity !== undefined) p.opacity = patch.opacity >= 0.995 ? undefined : patch.opacity;
+ st().updateOverlayTransient(o.id, p);
+ };
+ const setClip = (c: VideoClip, patch: { rotation?: number; opacity?: number }) => {
+ const pose = clipPose(c);
+ if (pose.keyed) return st().setClipKey(c.id, pose.tLocal, patch, { transient: true });
+ st().updateClipTransient(c.id, {
+ ...(patch.rotation !== undefined ? { rotation: patch.rotation === 0 ? undefined : patch.rotation } : {}),
+ ...(patch.opacity !== undefined ? { opacity: patch.opacity >= 0.995 ? undefined : patch.opacity } : {}),
+ });
+ };
+ const poses = overlays.map(overlayPose);
+ const center = selectionCenter(poses);
+ const rotation = sharedNumber([...poses.map((p) => p.rotation), ...clips.map((c) => clipPose(c).rotation)]);
+ const opacity = sharedNumber([...poses.map((p) => p.opacity), ...clips.map((c) => clipPose(c).opacity)]);
+ const move = (axis: "x" | "y", pct: number) => {
+ const target = { ...center, [axis]: clampOverlayPos(pct / 100) };
+ const { dx, dy } = selectionTranslation(poses, target);
+ overlays.forEach((o, i) => setOverlay(o, { x: poses[i].x + dx, y: poses[i].y + dy }));
+ };
+ const rotate = (v: number) => {
+ const deg = Math.round(v);
+ overlays.forEach((o) => setOverlay(o, { rotation: deg }));
+ clips.forEach((c) => setClip(c, { rotation: deg }));
+ };
+ const fade = (v: number) => {
+ const a = Math.max(0, Math.min(1, v));
+ overlays.forEach((o) => setOverlay(o, { opacity: a }));
+ clips.forEach((c) => setClip(c, { opacity: a }));
+ };
+ const hidden = [...overlays.map((o) => !!o.hidden), ...clips.map((c) => !!c.hidden), ...audios.map((a) => !!a.hidden)];
+ const hiddenRow = (
+ <MixedSwitch
+ label="Hidden"
+ values={hidden}
+ onChange={(v) =>
+ write.once(() => {
+ patchOverlays(overlays, () => ({ hidden: v || undefined }));
+ patchClips(clips, () => ({ hidden: v }));
+ patchAudios(audios, () => ({ hidden: v }));
+ })
+ }
+ />
+ );
+ // Sound has no transform: a selection with audio in it shares only Hidden.
+ if (!visual) return hiddenRow;
+ return (
+ <Section title="Transform">
+ {overlays.length > 0 && !clips.length && (
+ <Row label="Position">
+ {(["x", "y"] as const).map((axis) => (
+ <span key={axis} className="flex items-center gap-1">
+ <span className="text-[11px] text-muted-foreground/70 uppercase">{axis}</span>
+ <ScrubValue
+ label={`${axis.toUpperCase()} position`}
+ className="w-9 text-muted-foreground"
+ value={center[axis] * 100}
+ min={2}
+ max={98}
+ step={0.5}
+ keyStep={1}
+ snap={[50]}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => write.draft(() => move(axis, v))}
+ onCommit={(v) => write.commit(() => move(axis, v))}
+ />
+ </span>
+ ))}
+ </Row>
+ )}
+ <Row label="Rotation">
+ <ValueSlider
+ label="Rotation"
+ {...SLIDER}
+ value={rotation.value}
+ mixed={rotation.mixed}
+ min={-180}
+ max={180}
+ step={1}
+ snap={[-90, 0, 90]}
+ format={(v) => `${Math.round(v)}°`}
+ parse={parseNumberInput}
+ onDraft={(v) => write.draft(() => rotate(v))}
+ onCommit={(v) => write.commit(() => rotate(v))}
+ />
+ </Row>
+ <Row label="Opacity">
+ <ValueSlider
+ label="Opacity"
+ {...SLIDER}
+ value={opacity.value}
+ mixed={opacity.mixed}
+ min={0}
+ max={1}
+ step={0.01}
+ format={(v) => String(Math.round(v * 100))}
+ parse={parsePercentInput}
+ onDraft={(v) => write.draft(() => fade(v))}
+ onCommit={(v) => write.commit(() => fade(v))}
+ />
+ </Row>
+ {hiddenRow}
+ </Section>
+ );
+}
+
+/** Face, size, weight, slant and color, over a selection of titles only. */
+function TextRows({ texts }: { texts: TextOverlay[] }) {
+ const write = useGroupWrite();
+ const font = sharedValue(texts.map((t) => t.font));
+ const size = sharedNumber(texts.map((t) => t.size));
+ const bold = sharedValue(texts.map((t) => t.weight === 700));
+ const italic = sharedValue(texts.map((t) => !!t.italic));
+ const color = sharedValue(texts.map((t) => t.color.toLowerCase()));
+ const set = (patch: OverlayPatch) => patchOverlays(texts, () => patch);
+ return (
+ <>
+ <Field label="Font">
+ <FontPicker value={font.value} mixed={font.mixed} onChange={(id) => write.once(() => set({ font: id as TextOverlay["font"] }))} />
+ </Field>
+ <div className="mt-1 flex items-center gap-2">
+ <SegGroup>
+ <SegToggle label="Bold" active={!bold.mixed && bold.value} onClick={() => write.once(() => set({ weight: bold.mixed || !bold.value ? 700 : 400 }))}>
+ <Bold />
+ </SegToggle>
+ <SegToggle label="Italic" active={!italic.mixed && italic.value} onClick={() => write.once(() => set({ italic: italic.mixed || !italic.value ? true : undefined }))}>
+ <Italic />
+ </SegToggle>
+ </SegGroup>
+ <NumberField
+ label="Text size"
+ className="ml-auto w-[74px]"
+ icon={<Type />}
+ value={size.value}
+ mixed={size.mixed}
+ min={24}
+ max={240}
+ step={1}
+ presets={TEXT_SIZES}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onDraft={(v) => write.draft(() => set({ size: v }))}
+ onCommit={(v) => write.commit(() => set({ size: v }))}
+ />
+ </div>
+ <Row label="Color">
+ <ColorField
+ value={color.value}
+ mixed={color.mixed}
+ label="Text color"
+ onBegin={() => st().pushHistory()}
+ onLive={(c) => set({ color: c })}
+ onCommit={(c) => write.once(() => set({ color: c }))}
+ />
+ </Row>
+ </>
+ );
+}
+
+/** Fill, corner radius and outline, over a selection of shapes only. */
+function ShapeRows({ shapes }: { shapes: ShapeOverlay[] }) {
+ const write = useGroupWrite();
+ const boxes = shapes.every((s) => !lineLikeShape(s.shape));
+ const rects = shapes.every((s) => s.shape === "rect");
+ const fill = sharedValue(shapes.map((s) => s.fill.toLowerCase()));
+ const fillOpacity = sharedNumber(shapes.map((s) => s.fillOpacity ?? 1));
+ const radius = sharedNumber(shapes.map((s) => s.radius ?? 0));
+ const outlined = shapes.every((s) => !!s.stroke);
+ const strokeColor = sharedValue(shapes.map((s) => s.stroke?.color.toLowerCase() ?? ""));
+ const strokeWidth = sharedNumber(shapes.map((s) => s.stroke?.width ?? 0));
+ const set = (patch: (s: ShapeOverlay) => OverlayPatch) => patchOverlays(shapes, (o) => patch(o as ShapeOverlay));
+ return (
+ <>
+ <Row label={boxes ? "Fill" : "Color"}>
+ <ColorField
+ value={fill.value}
+ mixed={fill.mixed}
+ label={boxes ? "Fill color" : "Shape color"}
+ onBegin={() => st().pushHistory()}
+ onLive={(c) => set(() => ({ fill: c }))}
+ onCommit={(c) => write.once(() => set(() => ({ fill: c })))}
+ opacity={
+ boxes
+ ? {
+ label: "Fill opacity",
+ value: fillOpacity.value,
+ mixed: fillOpacity.mixed,
+ onDraft: (v) => write.draft(() => set(() => ({ fillOpacity: v >= 0.995 ? undefined : v }))),
+ onCommit: (v) => write.commit(() => set(() => ({ fillOpacity: v >= 0.995 ? undefined : v }))),
+ }
+ : undefined
+ }
+ />
+ </Row>
+ {rects && (
+ <Row label="Corner radius">
+ <ValueSlider
+ label="Corner radius"
+ {...SLIDER}
+ value={radius.value}
+ mixed={radius.mixed}
+ min={0}
+ max={120}
+ step={1}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onDraft={(v) => write.draft(() => set(() => ({ radius: Math.round(v) || undefined })))}
+ onCommit={(v) => write.commit(() => set(() => ({ radius: Math.round(v) || undefined })))}
+ />
+ </Row>
+ )}
+ {boxes && (
+ <Section
+ title="Outline"
+ enabled={outlined}
+ onEnabledChange={(v) => write.once(() => set((s) => ({ stroke: v ? (s.stroke ?? { color: "#111114", width: 6 }) : undefined })))}
+ >
+ <Row label="Color">
+ <ColorField
+ value={strokeColor.value}
+ mixed={strokeColor.mixed}
+ label="Outline color"
+ onBegin={() => st().pushHistory()}
+ onLive={(c) => set((s) => ({ stroke: { ...s.stroke!, color: c } }))}
+ onCommit={(c) => write.once(() => set((s) => ({ stroke: { ...s.stroke!, color: c } })))}
+ />
+ </Row>
+ <Row label="Width">
+ <ValueSlider
+ label="Outline width"
+ {...SLIDER}
+ value={strokeWidth.value}
+ mixed={strokeWidth.mixed}
+ min={1}
+ max={40}
+ step={1}
+ snap={[6]}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onDraft={(v) => write.draft(() => set((s) => ({ stroke: { ...s.stroke!, width: Math.round(v) } })))}
+ onCommit={(v) => write.commit(() => set((s) => ({ stroke: { ...s.stroke!, width: Math.round(v) } })))}
+ />
+ </Row>
+ </Section>
+ )}
+ </>
+ );
+}
+
+/** Volume and fades, over a selection of audio clips only. */
+function AudioRows({ audios }: { audios: AudioClip[] }) {
+ const write = useGroupWrite();
+ const volume = sharedNumber(audios.map((a) => a.volume));
+ const fadeIn = sharedNumber(audios.map((a) => a.fadeIn ?? 0));
+ const fadeOut = sharedNumber(audios.map((a) => a.fadeOut ?? 0));
+ const maxFade = Math.min(...audios.map(maxClipFade));
+ const set = (patch: Partial<AudioClip>) => patchAudios(audios, () => patch);
+ const fadeRow = (label: string, key: "fadeIn" | "fadeOut", shared: { value: number; mixed: boolean }) => (
+ <Row label={label}>
+ <ValueSlider
+ label={label}
+ {...SLIDER}
+ value={shared.value}
+ mixed={shared.mixed}
+ min={0}
+ max={maxFade}
+ step={0.1}
+ format={(v) => `${v.toFixed(1)}s`}
+ parse={parseSecondsInput}
+ onDraft={(v) => write.draft(() => set({ [key]: v }))}
+ onCommit={(v) => write.commit(() => set({ [key]: v }))}
+ />
+ </Row>
+ );
+ return (
+ <>
+ <Row label="Volume">
+ <ValueSlider
+ label="Volume"
+ {...SLIDER}
+ value={volume.value}
+ mixed={volume.mixed}
+ min={0}
+ max={3}
+ step={0.05}
+ snap={[1]}
+ format={(v) => `${Math.round(v * 100)}%`}
+ parse={parsePercentInput}
+ onDraft={(v) => write.draft(() => set({ volume: v }))}
+ onCommit={(v) => write.commit(() => set({ volume: v }))}
+ />
+ </Row>
+ {fadeRow("Fade in", "fadeIn", fadeIn)}
+ {fadeRow("Fade out", "fadeOut", fadeOut)}
+ </>
+ );
+}
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsx
index f3d7017b..342234c1 100644
--- a/site/src/cut/components/Inspector.tsx
+++ b/site/src/cut/components/Inspector.tsx
@@ -110,7 +110,7 @@ import {
type SoundPreset,
} from "@/cut/lib/soundPresets";
import { patchLibrary, refetchLibrary, useLibrary } from "@/cut/lib/queries";
-import { writeTextStyle } from "@/cut/lib/textStyle";
+import { TEXT_SIZES, writeTextStyle } from "@/cut/lib/textStyle";
import { formatTime } from "@/cut/lib/time";
import {
fontStack,
@@ -136,6 +136,7 @@ import {
type MediaAsset,
overlayName,
type Overlay,
+ type Selection,
type ShapeOverlay,
type StickerOverlay,
type TextOverlay,
@@ -151,13 +152,21 @@ import {
import { getPreviewCanvas } from "@/cut/lib/previewCanvas";
import { cn } from "@/lib/utils";
import { ScrollArea } from "@/components/ui/scroll-area";
-import { ResetButton, Row, Section, useSliderCheckpoint, Value } from "@/cut/components/panelBits";
+import { Field, ResetButton, Row, Section, SegGroup, SegToggle, useSliderCheckpoint, Value } from "@/cut/components/panelBits";
import { ColorPanel } from "@/cut/components/ColorPanel";
+import { GroupPanel } from "@/cut/components/GroupPanel";
import { RemovalPanel } from "@/cut/components/RemovalPanel";
import { useMatteBakes } from "@/cut/lib/removal/bakeJobs";
export function Inspector() {
const selection = useEditor((s) => s.selection);
+ const multi = useEditor((s) => s.multiSelection);
+ // Two or more items open the group panel over what they share; one item
+ // opens its own panel.
+ const group = useMemo(() => {
+ const items = multi.filter((m): m is NonNullable<Selection> => !!m && m.kind !== "cue" && m.kind !== "transition");
+ return items.length >= 2 ? items : null;
+ }, [multi]);
const clip = useEditor((s) =>
selection?.kind === "clip" ? s.clips.find((c) => c.id === selection.id) : undefined
);
@@ -173,10 +182,11 @@ export function Inspector() {
{/* Keyed on what is selected: picking something else builds a fresh
column, so it opens on that thing's own fields. */}
<InspectorColumn
- key={selection?.id ?? "none"}
- clip={clip}
- audio={audio}
- overlay={overlay}
+ key={group ? group.map((g) => `${g.kind}:${g.id}`).join() : selection?.id ?? "none"}
+ clip={group ? undefined : clip}
+ audio={group ? undefined : audio}
+ overlay={group ? undefined : overlay}
+ group={group ?? undefined}
/>
</aside>
);
@@ -207,16 +217,18 @@ function InspectorColumn({
clip,
audio,
overlay,
+ group,
}: {
clip?: VideoClip;
audio?: AudioClip;
overlay?: Overlay;
+ group?: NonNullable<Selection>[];
}) {
const open = useEditor((s) => s.inspectorOpen);
const setOpen = useEditor((s) => s.setInspectorOpen);
// The open tab and the Home scroller's place hold per item for the
// session, so coming back to an item lands on its panel as it was left.
- const itemId = clip?.id ?? audio?.id ?? overlay?.id ?? PANEL_GLOBAL;
+ const itemId = clip?.id ?? audio?.id ?? overlay?.id ?? (group ? `group:${group.map((g) => g.id).join()}` : PANEL_GLOBAL);
const [view, setView] = usePanelState<string>(itemId, "tab", "main");
const homeScroll = useRememberedScroll(itemId, "main");
const pick = useCallback(
@@ -246,7 +258,9 @@ function InspectorColumn({
<AnimationPanel overlay={overlay} />
) : (
<ScrollArea className="min-h-0 flex-1" {...homeScroll}>
- {audio ? (
+ {group ? (
+ <GroupPanel selection={group} />
+ ) : audio ? (
<AudioPanel clip={audio} />
) : overlay ? (
isTextOverlay(overlay) ? (
@@ -451,55 +465,6 @@ function ClipHead({
);
}
-/** A control that carries its own caption, for the two-up rows where the
- * settings sit side by side instead of behind a label on the left. */
-function Field({ label, children }: { label: string; children: React.ReactNode }) {
- return (
- <div className="flex min-w-0 flex-col gap-1">
- <span className="truncate text-[11px] text-muted-foreground">{label}</span>
- {children}
- </div>
- );
-}
-
-/** Icon toggles that belong together, sat in one trough. */
-function SegGroup({ children }: { children: React.ReactNode }) {
- return (
- <div className="flex shrink-0 items-center gap-0.5 rounded-md bg-secondary/60 p-0.5">
- {children}
- </div>
- );
-}
-
-function SegToggle({
- label,
- active,
- onClick,
- children,
-}: {
- label: string;
- active: boolean;
- onClick: () => void;
- children: React.ReactNode;
-}) {
- return (
- <button
- type="button"
- aria-label={label}
- title={label}
- aria-pressed={active}
- className={cn(
- "grid size-6 place-items-center rounded-[5px] text-muted-foreground transition-colors [&_svg]:size-3.5",
- active ? "bg-foreground text-background" : "hover:bg-foreground/10 hover:text-foreground"
- )}
- onClick={onClick}
- >
- {children}
- </button>
- );
-}
-
-
/** Matches the store's MIN_LEN: the shortest a trim can leave a clip. */
const MIN_TRIM = 0.1;
@@ -1827,7 +1792,6 @@ function AudioPanel({ clip }: { clip: AudioClip }) {
/** The sizes and spacings a title usually wants, offered under each field's
* chevron; any value in range can still be typed or dragged. */
-const TEXT_SIZES = [32, 48, 64, 80, 96, 120, 160, 200, 240];
const LINE_HEIGHTS = [0.9, 1, 1.15, 1.25, 1.5, 1.75, 2];
const LETTER_SPACINGS = [-2, 0, 2, 5, 10, 20];
diff --git a/site/src/cut/components/NumberField.tsx b/site/src/cut/components/NumberField.tsx
index 0b64c6d7..679f0d7e 100644
--- a/site/src/cut/components/NumberField.tsx
+++ b/site/src/cut/components/NumberField.tsx
@@ -29,6 +29,7 @@ export function NumberField({
presets,
icon,
className,
+ mixed,
}: {
label: string;
value: number;
@@ -46,20 +47,24 @@ export function NumberField({
/** Drag handle. Omit for a field that only takes typed and picked values. */
icon?: React.ReactNode;
className?: string;
+ /** The items behind the field disagree: the box reads "Mixed" until a
+ * value is typed, dragged or picked, which lands on all of them. */
+ mixed?: boolean;
}) {
- const [entry, setEntry] = useState({ value, draft: format(value) });
+ const show = (v: number) => (mixed ? "" : format(v));
+ const [entry, setEntry] = useState({ value, mixed: !!mixed, draft: show(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) });
+ if (entry.value !== value || entry.mixed !== !!mixed) setEntry({ value, mixed: !!mixed, draft: show(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) });
+ else setEntry({ value, mixed: !!mixed, draft: show(value) });
};
const stepBy = (dir: number, coarse: boolean) => {
@@ -112,10 +117,11 @@ export function NumberField({
<input
aria-label={label}
value={entry.draft}
+ placeholder={mixed ? "Mixed" : undefined}
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 })}
+ onChange={(e) => setEntry({ value, mixed: !!mixed, draft: e.target.value })}
onFocus={(e) => e.currentTarget.select()}
onBlur={commitDraft}
onKeyDown={(e) => {
@@ -124,7 +130,7 @@ export function NumberField({
commitDraft();
e.currentTarget.blur();
} else if (e.key === "Escape") {
- setEntry({ value, draft: format(value) });
+ setEntry({ value, mixed: !!mixed, draft: show(value) });
} else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
e.preventDefault();
stepBy(e.key === "ArrowUp" ? 1 : -1, e.shiftKey);
diff --git a/site/src/cut/components/ScrubValue.tsx b/site/src/cut/components/ScrubValue.tsx
index 9e466c37..74c2058e 100644
--- a/site/src/cut/components/ScrubValue.tsx
+++ b/site/src/cut/components/ScrubValue.tsx
@@ -29,6 +29,7 @@ export function ScrubValue({
disabled,
className,
label,
+ mixed,
}: {
value: number;
min: number;
@@ -47,6 +48,10 @@ export function ScrubValue({
disabled?: boolean;
className?: string;
label: string;
+ /** The items behind this readout disagree: it reads "Mixed", and any
+ * scrub, keystroke or typed entry writes one value to all of them. `value`
+ * is where a scrub starts from. */
+ mixed?: boolean;
}) {
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState("");
@@ -77,7 +82,7 @@ export function ScrubValue({
liveArrowed.current = false;
setEditWidth(buttonRef.current?.offsetWidth ?? 0);
editStart.current = value;
- setDraft(format(value));
+ setDraft(mixed ? "" : format(value));
setEditing(true);
};
@@ -211,7 +216,7 @@ export function ScrubValue({
}
}}
>
- {format(preview ?? value)}
+ {preview != null ? format(preview) : mixed ? <span className="font-sans italic">Mixed</span> : format(value)}
</button>
);
}
diff --git a/site/src/cut/components/ValueSlider.tsx b/site/src/cut/components/ValueSlider.tsx
index 2a1c2dbd..e5c0c2a0 100644
--- a/site/src/cut/components/ValueSlider.tsx
+++ b/site/src/cut/components/ValueSlider.tsx
@@ -35,6 +35,7 @@ export function ValueSlider({
disabled,
sliderClassName,
valueClassName,
+ mixed,
}: {
label: string;
value: number;
@@ -55,6 +56,8 @@ export function ValueSlider({
disabled?: boolean;
sliderClassName?: string;
valueClassName?: string;
+ /** The readout reads "Mixed"; the thumb sits at `value`. */
+ mixed?: boolean;
}) {
// The slider commits what was last drafted: the draft passed through the
// snap wrapper, so committing it (over Base UI's own committed argument)
@@ -92,6 +95,7 @@ export function ValueSlider({
format={format}
parse={parse}
disabled={disabled}
+ mixed={mixed}
onScrub={onDraft}
onCommit={onCommit}
/>
diff --git a/site/src/cut/components/panelBits.tsx b/site/src/cut/components/panelBits.tsx
index 569c37c6..5cbb61b9 100644
--- a/site/src/cut/components/panelBits.tsx
+++ b/site/src/cut/components/panelBits.tsx
@@ -148,3 +148,51 @@ export function Section({
</section>
);
}
+
+/** A control that carries its own caption, for the two-up rows where the
+ * settings sit side by side instead of behind a label on the left. */
+export function Field({ label, children }: { label: string; children: React.ReactNode }) {
+ return (
+ <div className="flex min-w-0 flex-col gap-1">
+ <span className="truncate text-[11px] text-muted-foreground">{label}</span>
+ {children}
+ </div>
+ );
+}
+
+/** Icon toggles that belong together, sat in one trough. */
+export function SegGroup({ children }: { children: React.ReactNode }) {
+ return (
+ <div className="flex shrink-0 items-center gap-0.5 rounded-md bg-secondary/60 p-0.5">
+ {children}
+ </div>
+ );
+}
+
+export function SegToggle({
+ label,
+ active,
+ onClick,
+ children,
+}: {
+ label: string;
+ active: boolean;
+ onClick: () => void;
+ children: React.ReactNode;
+}) {
+ return (
+ <button
+ type="button"
+ aria-label={label}
+ title={label}
+ aria-pressed={active}
+ className={cn(
+ "grid size-6 place-items-center rounded-[5px] text-muted-foreground transition-colors [&_svg]:size-3.5",
+ active ? "bg-foreground text-background" : "hover:bg-foreground/10 hover:text-foreground"
+ )}
+ onClick={onClick}
+ >
+ {children}
+ </button>
+ );
+}
diff --git a/site/src/cut/lib/groupEdit.test.ts b/site/src/cut/lib/groupEdit.test.ts
new file mode 100644
index 00000000..bec05036
--- /dev/null
+++ b/site/src/cut/lib/groupEdit.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, test } from "bun:test";
+import { selectionCenter, selectionSummary, selectionTranslation, sharedNumber, sharedValue } from "./groupEdit";
+import type { Overlay } from "./types";
+
+describe("groupEdit", () => {
+ test("a field agrees or reads as mixed", () => {
+ expect(sharedValue(["a", "a"])).toEqual({ value: "a", mixed: false });
+ expect(sharedValue(["a", "b"])).toEqual({ value: "a", mixed: true });
+ expect(sharedNumber([1, 1])).toEqual({ value: 1, mixed: false });
+ expect(sharedNumber([0, 1])).toEqual({ value: 0.5, mixed: true });
+ expect(sharedNumber([])).toEqual({ value: 0, mixed: false });
+ });
+
+ test("the selection center is the middle of its span", () => {
+ const c = selectionCenter([{ x: 0.2, y: 0.4 }, { x: 0.6, y: 0.8 }]);
+ expect(c.x).toBeCloseTo(0.4);
+ expect(c.y).toBeCloseTo(0.6);
+ });
+
+ test("a move keeps offsets and stops at the frame edge", () => {
+ const items = [{ x: 0.2, y: 0.4 }, { x: 0.6, y: 0.8 }];
+ const mid = selectionTranslation(items, { x: 0.5, y: 0.5 });
+ expect(mid.dx).toBeCloseTo(0.1);
+ expect(mid.dy).toBeCloseTo(-0.1);
+ const edge = selectionTranslation(items, { x: 0.95, y: 0.95 });
+ expect(0.6 + edge.dx).toBeCloseTo(0.98);
+ expect(0.8 + edge.dy).toBeCloseTo(0.98);
+ });
+
+ test("the summary counts by kind", () => {
+ const overlays = [
+ { kind: "shape" } as Overlay, { kind: "shape" } as Overlay, { text: "hi" } as Overlay,
+ ];
+ expect(selectionSummary({ overlays, clips: [], audios: [] })).toBe("2 shapes · 1 title");
+ });
+});
diff --git a/site/src/cut/lib/groupEdit.ts b/site/src/cut/lib/groupEdit.ts
new file mode 100644
index 00000000..dd399cdf
--- /dev/null
+++ b/site/src/cut/lib/groupEdit.ts
@@ -0,0 +1,58 @@
+import { clampOverlayPos, isEffectOverlay, isShapeOverlay, isTextOverlay, type AudioClip, type Overlay, type VideoClip } from "./types";
+
+/**
+ * A multi-selection edits one field across every item it holds. A field reads
+ * as one value when every item agrees and as mixed when they differ; a write
+ * lands the same value on all of them.
+ */
+export type Shared<T> = { value: T; mixed: boolean };
+
+export function sharedValue<T>(values: readonly T[], same: (a: T, b: T) => boolean = Object.is): Shared<T> {
+ const first = values[0];
+ return { value: first, mixed: values.some((v) => !same(v, first)) };
+}
+
+/** A mixed number shows its mean, so a slider thumb sits where the set sits. */
+export function sharedNumber(values: readonly number[]): Shared<number> {
+ if (!values.length) return { value: 0, mixed: false };
+ const shared = sharedValue(values, (a, b) => Math.abs(a - b) < 1e-6);
+ if (!shared.mixed) return shared;
+ return { value: values.reduce((sum, v) => sum + v, 0) / values.length, mixed: true };
+}
+
+/** The selection's center: the middle of the box its item centers span. */
+export function selectionCenter(items: readonly { x: number; y: number }[]): { x: number; y: number } {
+ let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
+ for (const it of items) {
+ minX = Math.min(minX, it.x); maxX = Math.max(maxX, it.x);
+ minY = Math.min(minY, it.y); maxY = Math.max(maxY, it.y);
+ }
+ return items.length ? { x: (minX + maxX) / 2, y: (minY + maxY) / 2 } : { x: 0.5, y: 0.5 };
+}
+
+/**
+ * Move the whole selection so its center lands at the target, every item
+ * keeping its offset. The move stops where the first item reaches the edge
+ * an element can sit at, so the set never folds in on itself.
+ */
+export function selectionTranslation(
+ items: readonly { x: number; y: number }[], target: { x: number; y: number },
+): { dx: number; dy: number } {
+ if (!items.length) return { dx: 0, dy: 0 };
+ const center = selectionCenter(items);
+ const lo = clampOverlayPos(0), hi = clampOverlayPos(1);
+ const xs = items.map((it) => it.x), ys = items.map((it) => it.y);
+ const dx = Math.max(lo - Math.min(...xs), Math.min(hi - Math.max(...xs), target.x - center.x));
+ const dy = Math.max(lo - Math.min(...ys), Math.min(hi - Math.max(...ys), target.y - center.y));
+ return { dx, dy };
+}
+
+/** "5 shapes · 4 titles": what a selection holds, by kind, in selection order. */
+export function selectionSummary(items: { overlays: readonly Overlay[]; clips: readonly VideoClip[]; audios: readonly AudioClip[] }): string {
+ const counts = new Map<string, number>();
+ const bump = (name: string) => counts.set(name, (counts.get(name) ?? 0) + 1);
+ for (let i = 0; i < items.clips.length; i++) bump("clip");
+ for (const o of items.overlays) bump(isTextOverlay(o) ? "title" : isShapeOverlay(o) ? "shape" : isEffectOverlay(o) ? "effect" : "sticker");
+ for (let i = 0; i < items.audios.length; i++) bump("audio clip");
+ return [...counts].map(([name, n]) => `${n} ${name}${n === 1 ? "" : "s"}`).join(" · ");
+}
diff --git a/site/src/cut/lib/textStyle.ts b/site/src/cut/lib/textStyle.ts
index dddf2e32..48b401b6 100644
--- a/site/src/cut/lib/textStyle.ts
+++ b/site/src/cut/lib/textStyle.ts
@@ -23,3 +23,6 @@ export function writeTextStyle(style: Partial<TextStyle>) {
// Storage full/blocked — the style just won't persist.
}
}
+
+/** The sizes the text size menu offers, px at the 1080 design frame. */
+export const TEXT_SIZES = [32, 48, 64, 80, 96, 120, 160, 200, 240];