Skip to content

Open source CapCut alternative.

TypeScript

feat(site): slider detents, scrub readouts, and rotate snap guides

David Leea5b58e3421c
diff --git a/site/src/components/ui/slider.tsx b/site/src/components/ui/slider.tsx
index ad12da6b..b5c15997 100644
--- a/site/src/components/ui/slider.tsx
+++ b/site/src/components/ui/slider.tsx
@@ -2,14 +2,37 @@ import { Slider as SliderPrimitive } from "@base-ui/react/slider"
import { cn } from "@/lib/utils"
+/** Fraction of the range around a snap point that lands exactly on it. */
+const SNAP_REACH = 0.025
+
function Slider({
className,
defaultValue,
value,
min = 0,
max = 100,
+ snap,
+ onValueChange,
...props
-}: SliderPrimitive.Root.Props) {
+}: SliderPrimitive.Root.Props & {
+ /**
+ * Detent values: a pointer drag that comes within reach lands exactly on
+ * one, which is how a nudged setting finds its way back to 100% or 0°.
+ * Keyboard steps stay exact, so arrow keys can walk out of a detent.
+ */
+ snap?: number[]
+}) {
+ const handleValueChange: typeof onValueChange =
+ snap && onValueChange
+ ? (v, details) => {
+ if (typeof v === "number" && details.reason !== "keyboard") {
+ const reach = (max - min) * SNAP_REACH
+ const n = v
+ v = snap.find((s) => Math.abs(n - s) <= reach) ?? n
+ }
+ onValueChange(v, details)
+ }
+ : onValueChange
// One thumb per actual value. A scalar renders exactly one thumb — a phantom
// second thumb has no backing value, so Base UI ignores any rail click that
// lands closest to it (the click resolves to a thumb index out of range).
@@ -31,6 +54,7 @@ function Slider({
value={value}
min={min}
max={max}
+ onValueChange={handleValueChange}
thumbAlignment="edge"
{...props}
>
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsx
index 2d7a4ee2..3d30aaf1 100644
--- a/site/src/cut/components/Inspector.tsx
+++ b/site/src/cut/components/Inspector.tsx
@@ -482,6 +482,7 @@ function ClipPanel({ clip }: { clip: VideoClip }) {
min={SPEED_MIN}
max={SPEED_MAX}
step={0.05}
+ snap={[1]}
value={speed}
onValueChange={(v) => setSpeedDraft(Number(v))}
onValueCommitted={() => {
@@ -538,6 +539,7 @@ function ClipPanel({ clip }: { clip: VideoClip }) {
min={0}
max={1.5}
step={0.05}
+ snap={[1]}
value={volume}
onValueChange={(v) => setVolumeDraft(Number(v))}
onValueCommitted={() => {
@@ -684,6 +686,7 @@ function ColorPanel({ clip, onBack }: { clip: VideoClip; onBack: () => void }) {
min={-f.max}
max={f.max}
step={1}
+ snap={[0]}
value={value}
onValueChange={(v) => setField(f.key, Number(v))}
onValueCommitted={() => ck.end()}
@@ -856,6 +859,7 @@ function ClipGeneratedAudio({ clip }: { clip: VideoClip }) {
min={0}
max={1.5}
step={0.05}
+ snap={[1]}
value={genVol}
onValueChange={(v) => {
genCk.begin();
@@ -969,6 +973,7 @@ function AudioPanel({ clip }: { clip: AudioClip }) {
min={SPEED_MIN}
max={SPEED_MAX}
step={0.05}
+ snap={[1]}
value={speed}
onValueChange={(v) => {
const n = Number(v);
@@ -1000,6 +1005,7 @@ function AudioPanel({ clip }: { clip: AudioClip }) {
min={0}
max={1.5}
step={0.05}
+ snap={[1]}
value={clip.volume}
onValueChange={(v) => setAudio({ volume: Number(v) })}
onValueCommitted={ck.end}
@@ -1298,6 +1304,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={-0.05}
max={0.3}
step={0.005}
+ snap={[0]}
value={o.letterSpacing ?? 0}
onValueChange={(v) => {
spacingCk.begin();
@@ -1307,9 +1314,29 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
}}
onValueCommitted={spacingCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {Math.round((o.letterSpacing ?? 0) * 100)}
- </Value>
+ <ScrubValue
+ label="Letter spacing"
+ className="w-9 text-muted-foreground"
+ value={(o.letterSpacing ?? 0) * 100}
+ min={-5}
+ max={30}
+ step={0.5}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ spacingCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ letterSpacing: Math.abs(v) < 0.25 ? undefined : v / 100,
+ });
+ }}
+ onCommit={(v) => {
+ spacingCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ letterSpacing: Math.abs(v) < 0.25 ? undefined : v / 100,
+ });
+ spacingCk.end();
+ }}
+ />
</Row>
<Row label="Line height">
<Slider
@@ -1317,6 +1344,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={0.8}
max={2}
step={0.05}
+ snap={[1.25]}
value={o.lineHeight ?? 1.25}
onValueChange={(v) => {
lineHeightCk.begin();
@@ -1326,7 +1354,29 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
}}
onValueCommitted={lineHeightCk.end}
/>
- <Value className="w-9 text-muted-foreground">{(o.lineHeight ?? 1.25).toFixed(2)}</Value>
+ <ScrubValue
+ label="Line height"
+ className="w-9 text-muted-foreground"
+ value={o.lineHeight ?? 1.25}
+ min={0.8}
+ max={2}
+ step={0.05}
+ format={(v) => v.toFixed(2)}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ lineHeightCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ lineHeight: Math.abs(v - 1.25) < 0.025 ? undefined : v,
+ });
+ }}
+ onCommit={(v) => {
+ lineHeightCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ lineHeight: Math.abs(v - 1.25) < 0.025 ? undefined : v,
+ });
+ lineHeightCk.end();
+ }}
+ />
</Row>
<Section
title="Outline"
@@ -1355,6 +1405,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={0.01}
max={0.15}
step={0.005}
+ snap={[0.04]}
value={o.stroke.width}
onValueChange={(v) => {
strokeCk.begin();
@@ -1364,9 +1415,29 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
}}
onValueCommitted={strokeCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {Math.round(o.stroke.width * 100)}
- </Value>
+ <ScrubValue
+ label="Outline width"
+ className="w-9 text-muted-foreground"
+ value={o.stroke.width * 100}
+ min={1}
+ max={15}
+ step={0.5}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ strokeCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ stroke: { ...o.stroke!, width: v / 100 },
+ });
+ }}
+ onCommit={(v) => {
+ strokeCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ stroke: { ...o.stroke!, width: v / 100 },
+ });
+ strokeCk.end();
+ }}
+ />
</Row>
</>
)}
@@ -1399,6 +1470,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={0}
max={60}
step={1}
+ snap={[14]}
value={(typeof o.shadow === "object" ? o.shadow.blur : undefined) ?? 14}
onValueChange={(v) => {
shadowCk.begin();
@@ -1408,9 +1480,29 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
}}
onValueCommitted={shadowCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {(typeof o.shadow === "object" ? o.shadow.blur : undefined) ?? 14}
- </Value>
+ <ScrubValue
+ label="Shadow blur"
+ className="w-9 text-muted-foreground"
+ value={(typeof o.shadow === "object" ? o.shadow.blur : undefined) ?? 14}
+ min={0}
+ max={60}
+ step={1}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ shadowCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ shadow: { ...(typeof o.shadow === "object" ? o.shadow : {}), blur: v },
+ });
+ }}
+ onCommit={(v) => {
+ shadowCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ shadow: { ...(typeof o.shadow === "object" ? o.shadow : {}), blur: v },
+ });
+ shadowCk.end();
+ }}
+ />
</Row>
<Row label="Opacity">
<Slider
@@ -1418,6 +1510,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={0}
max={1}
step={0.01}
+ snap={[0.65]}
value={(typeof o.shadow === "object" ? o.shadow.opacity : undefined) ?? 0.65}
onValueChange={(v) => {
shadowCk.begin();
@@ -1430,9 +1523,29 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
}}
onValueCommitted={shadowCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {Math.round(((typeof o.shadow === "object" ? o.shadow.opacity : undefined) ?? 0.65) * 100)}
- </Value>
+ <ScrubValue
+ label="Shadow opacity"
+ className="w-9 text-muted-foreground"
+ value={(typeof o.shadow === "object" ? o.shadow.opacity : undefined) ?? 0.65}
+ min={0}
+ max={1}
+ step={0.01}
+ format={(v) => String(Math.round(v * 100))}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ shadowCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ shadow: { ...(typeof o.shadow === "object" ? o.shadow : {}), opacity: v },
+ });
+ }}
+ onCommit={(v) => {
+ shadowCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ shadow: { ...(typeof o.shadow === "object" ? o.shadow : {}), opacity: v },
+ });
+ shadowCk.end();
+ }}
+ />
</Row>
</>
</Section>
@@ -1456,6 +1569,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={0}
max={1}
step={0.01}
+ snap={[PLATE_OPACITY]}
value={o.plateOpacity ?? PLATE_OPACITY}
onValueChange={(v) => {
opacityCk.begin();
@@ -1489,6 +1603,7 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
min={0}
max={1}
step={0.01}
+ snap={[PLATE_RADIUS]}
value={o.plateRadius ?? PLATE_RADIUS}
onValueChange={(v) => {
radiusCk.begin();
@@ -1727,6 +1842,7 @@ function AnimationRows({ overlay: o }: { overlay: Overlay }) {
min={OVERLAY_ANIM_MIN_SECONDS}
max={Math.min(OVERLAY_ANIM_MAX_SECONDS, dur)}
step={0.05}
+ snap={[OVERLAY_ANIM_DEFAULT_SECONDS]}
value={seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS}
onValueChange={(v) =>
dragAnim(lengthCk, {
@@ -1735,9 +1851,27 @@ function AnimationRows({ overlay: o }: { overlay: Overlay }) {
}
onValueCommitted={lengthCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {(seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS).toFixed(2)}s
- </Value>
+ <ScrubValue
+ label="Animation length"
+ className="w-9 text-muted-foreground"
+ value={seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS}
+ min={OVERLAY_ANIM_MIN_SECONDS}
+ max={Math.min(OVERLAY_ANIM_MAX_SECONDS, dur)}
+ step={0.05}
+ format={(v) => `${v.toFixed(2)}s`}
+ parse={parseSecondsInput}
+ onScrub={(v) =>
+ dragAnim(lengthCk, {
+ [slot]: { style: active.style as OverlayAnimStyle, seconds: v },
+ })
+ }
+ onCommit={(v) => {
+ dragAnim(lengthCk, {
+ [slot]: { style: active.style as OverlayAnimStyle, seconds: v },
+ });
+ lengthCk.end();
+ }}
+ />
</Row>
)}
{slot === "loop" && anim.loop && (
@@ -1753,7 +1887,21 @@ function AnimationRows({ overlay: o }: { overlay: Overlay }) {
}
onValueCommitted={speedCk.end}
/>
- <Value className="w-9 text-muted-foreground">{anim.loop.speed.toFixed(2)}×</Value>
+ <ScrubValue
+ label="Loop speed"
+ className="w-9 text-muted-foreground"
+ value={anim.loop.speed}
+ min={0.25}
+ max={4}
+ step={0.25}
+ format={(v) => `${v.toFixed(2)}×`}
+ parse={parseSpeedInput}
+ onScrub={(v) => dragAnim(speedCk, { loop: { ...anim.loop!, speed: v } })}
+ onCommit={(v) => {
+ dragAnim(speedCk, { loop: { ...anim.loop!, speed: v } });
+ speedCk.end();
+ }}
+ />
</Row>
)}
</Section>
@@ -1854,6 +2002,7 @@ function TransformRows({ overlay: o }: { overlay: Overlay }) {
max={98}
step={0.5}
keyStep={1}
+ snap={[50]}
format={(v) => String(Math.round(v))}
parse={parseNumberInput}
onScrub={(v) => {
@@ -1876,6 +2025,7 @@ function TransformRows({ overlay: o }: { overlay: Overlay }) {
min={0.1}
max={4}
step={0.01}
+ snap={[1]}
value={pose.scale}
onValueChange={(v) => {
scaleCk.begin();
@@ -1883,7 +2033,26 @@ function TransformRows({ overlay: o }: { overlay: Overlay }) {
}}
onValueCommitted={scaleCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(pose.scale * 100)}%</Value>
+ <ScrubValue
+ label="Scale"
+ className="w-9 text-muted-foreground"
+ value={pose.scale}
+ min={0.1}
+ max={4}
+ step={0.01}
+ keyStep={0.05}
+ format={(v) => `${Math.round(v * 100)}%`}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ scaleCk.begin();
+ setKey({ scale: v });
+ }}
+ onCommit={(v) => {
+ scaleCk.begin();
+ setKey({ scale: v });
+ scaleCk.end();
+ }}
+ />
</Row>
)}
<Row label="Rotation">
@@ -1892,6 +2061,7 @@ function TransformRows({ overlay: o }: { overlay: Overlay }) {
min={-180}
max={180}
step={1}
+ snap={[-90, 0, 90]}
value={keyed ? pose.rotation : (o.rotation ?? 0)}
onValueChange={(v) => {
rotationCk.begin();
@@ -2148,6 +2318,7 @@ function ClipTransformSection({ clip }: { clip: VideoClip }) {
max={150}
step={0.5}
keyStep={1}
+ snap={[50]}
format={(v) => String(Math.round(v))}
parse={parseNumberInput}
onScrub={(v) => {
@@ -2169,6 +2340,7 @@ function ClipTransformSection({ clip }: { clip: VideoClip }) {
min={0.1}
max={4}
step={0.01}
+ snap={[1]}
value={pose.scale}
onValueChange={(v) => {
scaleCk.begin();
@@ -2176,7 +2348,26 @@ function ClipTransformSection({ clip }: { clip: VideoClip }) {
}}
onValueCommitted={scaleCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(pose.scale * 100)}%</Value>
+ <ScrubValue
+ label="Scale"
+ className="w-9 text-muted-foreground"
+ value={pose.scale}
+ min={0.1}
+ max={4}
+ step={0.01}
+ keyStep={0.05}
+ format={(v) => `${Math.round(v * 100)}%`}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ scaleCk.begin();
+ setKey({ scale: v });
+ }}
+ onCommit={(v) => {
+ scaleCk.begin();
+ setKey({ scale: v });
+ scaleCk.end();
+ }}
+ />
</Row>
<Row label="Rotation">
<Slider
@@ -2184,6 +2375,7 @@ function ClipTransformSection({ clip }: { clip: VideoClip }) {
min={-180}
max={180}
step={1}
+ snap={[-90, 0, 90]}
value={pose.rotation}
onValueChange={(v) => {
rotationCk.begin();
@@ -2191,7 +2383,25 @@ function ClipTransformSection({ clip }: { clip: VideoClip }) {
}}
onValueCommitted={rotationCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(pose.rotation)}°</Value>
+ <ScrubValue
+ label="Rotation"
+ className="w-9 text-muted-foreground"
+ value={pose.rotation}
+ min={-180}
+ max={180}
+ step={1}
+ format={(v) => `${Math.round(v)}°`}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ rotationCk.begin();
+ setKey({ rotation: Math.round(v) });
+ }}
+ onCommit={(v) => {
+ rotationCk.begin();
+ setKey({ rotation: Math.round(v) });
+ rotationCk.end();
+ }}
+ />
</Row>
<Row label="Opacity">
<Slider
@@ -2206,7 +2416,25 @@ function ClipTransformSection({ clip }: { clip: VideoClip }) {
}}
onValueCommitted={opacityCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(pose.opacity * 100)}</Value>
+ <ScrubValue
+ label="Opacity"
+ className="w-9 text-muted-foreground"
+ value={pose.opacity}
+ min={0}
+ max={1}
+ step={0.01}
+ format={(v) => String(Math.round(v * 100))}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ opacityCk.begin();
+ setKey({ opacity: v });
+ }}
+ onCommit={(v) => {
+ opacityCk.begin();
+ setKey({ opacity: v });
+ opacityCk.end();
+ }}
+ />
</Row>
</>
)}
@@ -2415,6 +2643,7 @@ function MaskSection({ target }: { target: MaskTarget }) {
max={100}
step={0.5}
keyStep={1}
+ snap={[0]}
format={(v) => String(Math.round(v))}
parse={parseNumberInput}
onScrub={(v) => {
@@ -2443,6 +2672,7 @@ function MaskSection({ target }: { target: MaskTarget }) {
min={1}
max={200}
step={1}
+ snap={[100]}
format={(v) => String(Math.round(v))}
parse={parseNumberInput}
onScrub={(v) => {
@@ -2466,6 +2696,7 @@ function MaskSection({ target }: { target: MaskTarget }) {
min={-180}
max={180}
step={1}
+ snap={[-90, 0, 90]}
value={geom.rotation}
onValueChange={(v) => {
rotationCk.begin();
@@ -2473,7 +2704,25 @@ function MaskSection({ target }: { target: MaskTarget }) {
}}
onValueCommitted={rotationCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(geom.rotation)}°</Value>
+ <ScrubValue
+ label="Mask rotation"
+ className="w-9 text-muted-foreground"
+ value={geom.rotation}
+ min={-180}
+ max={180}
+ step={1}
+ format={(v) => `${Math.round(v)}°`}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ rotationCk.begin();
+ writeGeom({ rotation: Math.round(v) });
+ }}
+ onCommit={(v) => {
+ rotationCk.begin();
+ writeGeom({ rotation: Math.round(v) });
+ rotationCk.end();
+ }}
+ />
</Row>
)}
<Row label="Feather">
@@ -2489,7 +2738,25 @@ function MaskSection({ target }: { target: MaskTarget }) {
}}
onValueCommitted={featherCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(geom.feather)}</Value>
+ <ScrubValue
+ label="Feather"
+ className="w-9 text-muted-foreground"
+ value={geom.feather}
+ min={0}
+ max={120}
+ step={1}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ featherCk.begin();
+ writeGeom({ feather: Math.round(v) });
+ }}
+ onCommit={(v) => {
+ featherCk.begin();
+ writeGeom({ feather: Math.round(v) });
+ featherCk.end();
+ }}
+ />
</Row>
{(m.kind === "rect" || m.kind === "square") && (
<Row label="Radius">
@@ -2506,7 +2773,27 @@ function MaskSection({ target }: { target: MaskTarget }) {
}}
onValueCommitted={radiusCk.end}
/>
- <Value className="w-9 text-muted-foreground">{m.radius ?? 0}</Value>
+ <ScrubValue
+ label="Mask corner radius"
+ className="w-9 text-muted-foreground"
+ value={m.radius ?? 0}
+ min={0}
+ max={200}
+ step={1}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ radiusCk.begin();
+ const radius = Math.round(v);
+ target.setTransient({ ...m, radius: radius === 0 ? undefined : radius });
+ }}
+ onCommit={(v) => {
+ radiusCk.begin();
+ const radius = Math.round(v);
+ target.setTransient({ ...m, radius: radius === 0 ? undefined : radius });
+ radiusCk.end();
+ }}
+ />
</Row>
)}
<Row label="Invert">
@@ -2556,9 +2843,29 @@ function ShapePanel({ overlay: o }: { overlay: ShapeOverlay }) {
}}
onValueCommitted={fillCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {Math.round((o.fillOpacity ?? 1) * 100)}
- </Value>
+ <ScrubValue
+ label="Fill opacity"
+ className="w-9 text-muted-foreground"
+ value={o.fillOpacity ?? 1}
+ min={0}
+ max={1}
+ step={0.01}
+ format={(v) => String(Math.round(v * 100))}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ fillCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ fillOpacity: v >= 0.995 ? undefined : v,
+ });
+ }}
+ onCommit={(v) => {
+ fillCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ fillOpacity: v >= 0.995 ? undefined : v,
+ });
+ fillCk.end();
+ }}
+ />
</Row>
)}
{o.shape === "rect" && (
@@ -2577,7 +2884,31 @@ function ShapePanel({ overlay: o }: { overlay: ShapeOverlay }) {
}}
onValueCommitted={radiusCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(o.radius ?? 0)}</Value>
+ <ScrubValue
+ label="Corner radius"
+ className="w-9 text-muted-foreground"
+ value={o.radius ?? 0}
+ min={0}
+ max={120}
+ step={1}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ radiusCk.begin();
+ const radius = Math.round(v);
+ useEditor.getState().updateOverlayTransient(o.id, {
+ radius: radius === 0 ? undefined : radius,
+ });
+ }}
+ onCommit={(v) => {
+ radiusCk.begin();
+ const radius = Math.round(v);
+ useEditor.getState().updateOverlayTransient(o.id, {
+ radius: radius === 0 ? undefined : radius,
+ });
+ radiusCk.end();
+ }}
+ />
</Row>
)}
{boxShape && (
@@ -2608,6 +2939,7 @@ function ShapePanel({ overlay: o }: { overlay: ShapeOverlay }) {
min={1}
max={40}
step={1}
+ snap={[6]}
value={o.stroke.width}
onValueChange={(v) => {
strokeCk.begin();
@@ -2617,7 +2949,29 @@ function ShapePanel({ overlay: o }: { overlay: ShapeOverlay }) {
}}
onValueCommitted={strokeCk.end}
/>
- <Value className="w-9 text-muted-foreground">{o.stroke.width}</Value>
+ <ScrubValue
+ label="Outline width"
+ className="w-9 text-muted-foreground"
+ value={o.stroke.width}
+ min={1}
+ max={40}
+ step={1}
+ format={(v) => String(Math.round(v))}
+ parse={parseNumberInput}
+ onScrub={(v) => {
+ strokeCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ stroke: { ...o.stroke!, width: Math.round(v) },
+ });
+ }}
+ onCommit={(v) => {
+ strokeCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, {
+ stroke: { ...o.stroke!, width: Math.round(v) },
+ });
+ strokeCk.end();
+ }}
+ />
</Row>
</>
)}
@@ -2649,6 +3003,7 @@ function EffectPanel({ overlay: o }: { overlay: EffectOverlay }) {
min={0.05}
max={1}
step={0.01}
+ snap={[0.5]}
value={o.amount ?? 0.5}
onValueChange={(v) => {
amountCk.begin();
@@ -2656,9 +3011,25 @@ function EffectPanel({ overlay: o }: { overlay: EffectOverlay }) {
}}
onValueCommitted={amountCk.end}
/>
- <Value className="w-9 text-muted-foreground">
- {Math.round((o.amount ?? 0.5) * 100)}
- </Value>
+ <ScrubValue
+ label="Effect amount"
+ className="w-9 text-muted-foreground"
+ value={o.amount ?? 0.5}
+ min={0.05}
+ max={1}
+ step={0.01}
+ format={(v) => String(Math.round(v * 100))}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ amountCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, { amount: v });
+ }}
+ onCommit={(v) => {
+ amountCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, { amount: v });
+ amountCk.end();
+ }}
+ />
</Row>
)}
<HiddenRow overlay={o} />
@@ -2839,7 +3210,25 @@ function StickerPanel({ overlay: o }: { overlay: StickerOverlay }) {
}}
onValueCommitted={widthCk.end}
/>
- <Value className="w-9 text-muted-foreground">{Math.round(o.w * 100)}</Value>
+ <ScrubValue
+ label="Sticker size"
+ className="w-9 text-muted-foreground"
+ value={o.w}
+ min={0.02}
+ max={1}
+ step={0.01}
+ format={(v) => String(Math.round(v * 100))}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ widthCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, { w: v });
+ }}
+ onCommit={(v) => {
+ widthCk.begin();
+ useEditor.getState().updateOverlayTransient(o.id, { w: v });
+ widthCk.end();
+ }}
+ />
</Row>
<OverlayMaskSection overlay={o} />
<TransformRows overlay={o} />
diff --git a/site/src/cut/components/OverlayLayer.tsx b/site/src/cut/components/OverlayLayer.tsx
index 1244b976..832e59c3 100644
--- a/site/src/cut/components/OverlayLayer.tsx
+++ b/site/src/cut/components/OverlayLayer.tsx
@@ -61,6 +61,10 @@ const ROTATE_BOX = Math.ceil(Math.hypot(ROTATE_GLYPH_W, ROTATE_GLYPH_H));
/** The glyph's own arrows run top-to-bottom, so a quarter turn puts them
* left-to-right — the way an unrotated element's top handle drags. */
const ROTATE_BASE_DEG = -90;
+/** Degrees around a quarter turn where a rotate drag locks on. Wide enough to
+ * feel as a detent at drag speed — a rotate drag covers several degrees per
+ * pointer event, so a narrow window slips by between frames. */
+const ROTATE_SNAP_DEG = 6;
const rotateCursorCache = new Map<number, string>();
@@ -212,6 +216,23 @@ export function OverlayLayer({
const clearGuides = useCallback(() => setGuides({ v: [], h: [] }), []);
+ // A rotate drag that locks onto a quarter turn paints a guide through the
+ // element's center: the horizontal line at 0°/±180°, the vertical one at
+ // ±90°, matching the axis the element's baseline runs along.
+ const rotationGuide = useCallback(
+ (p: { clientX: number; clientY: number; quarter: number } | null) => {
+ const root = rootRef.current;
+ if (!p || !root) {
+ setGuides({ v: [], h: [] });
+ return;
+ }
+ const r = root.getBoundingClientRect();
+ if (Math.abs(p.quarter) === 90) setGuides({ v: [p.clientX - r.left], h: [] });
+ else setGuides({ v: [], h: [p.clientY - r.top] });
+ },
+ []
+ );
+
// The selected title and whether the playhead sits inside it. Selecting a
// title off the playhead (e.g. focusing its text in the panel) edits it in
// isolation: it shows alone so it never stacks over whatever title is live.
@@ -262,6 +283,7 @@ export function OverlayLayer({
registerBox={registerBox}
snap={snap}
onSnapEnd={clearGuides}
+ rotationGuide={rotationGuide}
/>
);
})}
@@ -438,6 +460,7 @@ function OverlayItem({
registerBox,
snap,
onSnapEnd,
+ rotationGuide,
}: {
overlay: Overlay;
selected: boolean;
@@ -448,6 +471,9 @@ function OverlayItem({
registerBox: (id: string, el: HTMLElement | null) => void;
snap: (id: string, x: number, y: number, ev: PointerEvent) => { x: number; y: number };
onSnapEnd: () => void;
+ /** Paint (or clear) the guide line while a rotate drag sits on a quarter
+ * turn; the point is the rotating element's center in client coords. */
+ rotationGuide: (p: { clientX: number; clientY: number; quarter: number } | null) => void;
}) {
const [editing, setEditing] = useState(false);
const editRef = useRef<HTMLDivElement>(null);
@@ -661,10 +687,10 @@ function OverlayItem({
});
};
- // The lollipop above the box rotates around the center; plain angles within
- // 3° of a quarter turn snap to it, and 0 stores as absence. A group orbits
- // its shared center: positions revolve and each member's rotation shifts by
- // the same delta.
+ // The lollipop above the box rotates around the center; angles within reach
+ // of a quarter turn snap to it, and 0 stores as absence. A group orbits
+ // its shared center: positions revolve, each member's rotation shifts by
+ // the same delta, and the grabbed element's angle snaps the same way.
const rotateFrom = (e: React.PointerEvent) => {
const s = useEditor.getState();
s.pushHistory();
@@ -677,6 +703,9 @@ function OverlayItem({
const angleAt = (ev: { clientX: number; clientY: number }) =>
(Math.atan2(ev.clientY - cy, ev.clientX - cx) * 180) / Math.PI + 90;
const start0 = angleAt(e);
+ // The grabbed member's start position, for placing the guide while the
+ // group orbit carries its center away from the box rect measured above.
+ const grabbed = members.find((m) => m.id === o.id) ?? o;
const norm = (deg: number) => ((((deg + 180) % 360) + 360) % 360) - 180;
// The cursor turns with the element for the whole drag, so its heads keep
// pointing the way the next bit of travel will take it.
@@ -686,15 +715,30 @@ function OverlayItem({
onMove: (_dx, _dy, ev) => {
if (members.length === 1) {
let deg = norm(angleAt(ev));
+ let locked: number | null = null;
for (const q of [-180, -90, 0, 90, 180]) {
- if (Math.abs(deg - q) < 3) deg = q;
+ if (Math.abs(deg - q) < ROTATE_SNAP_DEG) {
+ deg = q;
+ locked = q;
+ break;
+ }
}
const rotation = Math.round(deg);
liveRotation = rotation;
+ rotationGuide(locked === null ? null : { clientX: cx, clientY: cy, quarter: locked });
writeTransform([{ id: o.id, patch: { rotation: rotation === 0 ? undefined : rotation } }]);
return;
}
- const delta = norm(angleAt(ev) - start0);
+ let delta = norm(angleAt(ev) - start0);
+ const lead = norm((o.rotation ?? 0) + delta);
+ let locked: number | null = null;
+ for (const q of [-180, -90, 0, 90, 180]) {
+ if (Math.abs(lead - q) < ROTATE_SNAP_DEG) {
+ delta = norm(delta + q - lead);
+ locked = q;
+ break;
+ }
+ }
liveRotation = norm((o.rotation ?? 0) + delta);
const rad = (delta * Math.PI) / 180;
// Positions are frame fractions with unequal axes; orbit in a square
@@ -716,7 +760,21 @@ function OverlayItem({
};
})
);
+ const ox0 = (grabbed.x - gx) * ax;
+ const oy0 = (grabbed.y - gy) * ay;
+ rotationGuide(
+ locked === null
+ ? null
+ : {
+ clientX:
+ cx + (gx + (ox0 * Math.cos(rad) - oy0 * Math.sin(rad)) / ax - grabbed.x) * stageWidth,
+ clientY:
+ cy + (gy + (ox0 * Math.sin(rad) + oy0 * Math.cos(rad)) / ay - grabbed.y) * stageHeight,
+ quarter: locked,
+ }
+ );
},
+ onUp: () => rotationGuide(null),
});
};
@@ -967,8 +1025,10 @@ const MASK_GRIP =
/**
* On-canvas mask editing, shared by elements and video clips: an amber
- * outline tracing the mask's edge, a center grip that moves it and a corner
- * grip that resizes it (the band height, for mirror). Coordinates are local
+ * outline tracing the mask's edge — its interior moves the mask, a lollipop
+ * above rotates it and a corner grip resizes it (the band height, for
+ * mirror), with the same detents and red guide lines as the element's own
+ * handles. Coordinates are local
* px around the layer's anchor — the mount point carries the layer's own
* transform — and screen deltas are folded back through that transform via
* `rotation`/`poseScale`, then through the mask's own angle for the resize.
@@ -995,6 +1055,11 @@ export function MaskGizmoCore({
begin: () => void;
}) {
const f = maskFrameAt(m, tLocal);
+ // Guide lines while a drag sits on a detent: `rot` is the locked quarter
+ // turn, `x`/`y` mark the mask centered on an axis. Local space, so on an
+ // element they ride its transform the way the mask itself does.
+ const [guide, setGuide] = useState<{ rot?: number; x?: boolean; y?: boolean } | null>(null);
+ const interiorRef = useRef<HTMLDivElement>(null);
// Screen deltas → the box's local space (undo the element transform).
const toLocal = (dx: number, dy: number) => {
const r = (-rotation * Math.PI) / 180;
@@ -1022,6 +1087,9 @@ export function MaskGizmoCore({
const rx = gx * Math.cos(theta) - gy * Math.sin(theta);
const ry = gx * Math.sin(theta) + gy * Math.cos(theta);
const clampSize = (v: number) => Math.min(2, Math.max(0.01, v));
+ // Detents matching the inspector's: size locks onto exactly full frame,
+ // the center onto dead center, within a couple percent of the frame.
+ const snapTo = (v: number, target: number) => (Math.abs(v - target) < 0.02 ? target : v);
const designScale = Math.min(stageWidth, stageHeight) / 1080;
const edge = {
className: "pointer-events-none",
@@ -1038,8 +1106,48 @@ export function MaskGizmoCore({
startDrag(e, {
onMove: (dx, dy) => {
const l = toLocal(dx, dy);
- writeGeom({ x: g0.x + l.x / stageWidth, y: g0.y + l.y / stageHeight });
+ const x = snapTo(g0.x + l.x / stageWidth, 0);
+ const y = snapTo(g0.y + l.y / stageHeight, 0);
+ setGuide(x === 0 || y === 0 ? { x: x === 0, y: y === 0 } : null);
+ writeGeom({ x, y });
+ },
+ onUp: () => setGuide(null),
+ });
+ };
+ // The lollipop turns the mask about its center; quarter turns detent the
+ // same way the element's own handle does. Angles are mask-local — the
+ // mount's transform carries the element's rotation, and a screen-angle
+ // delta equals a local delta under rotate + uniform scale.
+ const rotateMask = (e: React.PointerEvent) => {
+ e.stopPropagation();
+ begin();
+ const box = interiorRef.current?.getBoundingClientRect();
+ const mcx = box ? box.left + box.width / 2 : e.clientX;
+ const mcy = box ? box.top + box.height / 2 : e.clientY;
+ const angleAt = (ev: { clientX: number; clientY: number }) =>
+ (Math.atan2(ev.clientY - mcy, ev.clientX - mcx) * 180) / Math.PI;
+ const a0 = angleAt(e);
+ const g0 = f;
+ const norm = (deg: number) => ((((deg + 180) % 360) + 360) % 360) - 180;
+ let liveRot = rotation + g0.rotation;
+ startDrag(e, {
+ cursor: () => rotateCursor(liveRot),
+ onMove: (_dx, _dy, ev) => {
+ let deg = norm(g0.rotation + (angleAt(ev) - a0));
+ let locked: number | null = null;
+ for (const q of [-180, -90, 0, 90, 180]) {
+ if (Math.abs(deg - q) < ROTATE_SNAP_DEG) {
+ deg = q;
+ locked = q;
+ break;
+ }
+ }
+ const rot = Math.round(deg);
+ liveRot = rotation + rot;
+ setGuide(locked === null ? null : { rot: locked });
+ writeGeom({ rotation: rot });
},
+ onUp: () => setGuide(null),
});
};
// The whole interior moves the mask, so a drag can start anywhere inside
@@ -1121,12 +1229,12 @@ export function MaskGizmoCore({
const my = -l.x * Math.sin(theta) + l.y * Math.cos(theta);
writeGeom(
m.kind === "square"
- ? { w: clampSize(g0.w + (2 * mx) / stageWidth) }
+ ? { w: clampSize(snapTo(g0.w + (2 * mx) / stageWidth, 1)) }
: m.kind === "mirror"
- ? { h: clampSize(g0.h + (2 * my) / stageHeight) }
+ ? { h: clampSize(snapTo(g0.h + (2 * my) / stageHeight, 1)) }
: {
- w: clampSize(g0.w + (2 * mx) / stageWidth),
- h: clampSize(g0.h + (2 * my) / stageHeight),
+ w: clampSize(snapTo(g0.w + (2 * mx) / stageWidth, 1)),
+ h: clampSize(snapTo(g0.h + (2 * my) / stageHeight, 1)),
}
);
},
diff --git a/site/src/cut/components/ScrubValue.tsx b/site/src/cut/components/ScrubValue.tsx
index 86070ef4..68b28f7e 100644
--- a/site/src/cut/components/ScrubValue.tsx
+++ b/site/src/cut/components/ScrubValue.tsx
@@ -20,6 +20,7 @@ export function ScrubValue({
max,
step,
keyStep,
+ snap,
format,
parse,
onScrub,
@@ -32,6 +33,9 @@ export function ScrubValue({
max: number;
step: number;
keyStep?: number;
+ /** Detent values: a drag passing within a few steps lands exactly on one.
+ * Arrow keys and typed entries stay exact. */
+ snap?: number[];
format: (v: number) => string;
parse: (raw: string) => number | null;
onScrub?: (v: number) => void;
@@ -43,6 +47,10 @@ export function ScrubValue({
const [draft, setDraft] = useState("");
const [preview, setPreview] = useState<number | null>(null);
const inputRef = useRef<HTMLInputElement>(null);
+ const buttonRef = useRef<HTMLButtonElement>(null);
+ // The readout's rendered width, held while the editor is open so swapping
+ // the button for an input never reflows the row around it.
+ const [editWidth, setEditWidth] = useState(0);
const skipBlur = useRef(false);
// Arrow keys inside the editor apply live through onScrub; these carry the
// pre-edit value so Escape (or garbage text) can put it back.
@@ -62,6 +70,7 @@ export function ScrubValue({
const openEditor = () => {
skipBlur.current = false;
liveArrowed.current = false;
+ setEditWidth(buttonRef.current?.offsetWidth ?? 0);
editStart.current = value;
setDraft(format(value));
setEditing(true);
@@ -88,10 +97,12 @@ export function ScrubValue({
autoFocus
value={draft}
aria-label={label}
- // Mono font, so ch tracks the content width as the user types.
- style={{ width: `${Math.max(draft.length, 3) + 1}ch` }}
+ // At least as wide as the readout it replaced (so the row holds
+ // still); mono font, so ch grows it with what the user types. The
+ // underline is a shadow — a border would add a pixel of height.
+ style={{ width: `${Math.max(draft.length, 3) + 1}ch`, minWidth: editWidth }}
className={cn(
- "border-b border-primary/60 bg-transparent text-right font-mono text-[11.5px] tabular-nums text-foreground outline-none",
+ "bg-transparent text-right font-mono text-[11.5px] tabular-nums text-foreground shadow-[0_1px_0_0] shadow-primary/60 outline-none",
className
)}
onChange={(e) => setDraft(e.target.value)}
@@ -132,6 +143,7 @@ export function ScrubValue({
return (
<button
+ ref={buttonRef}
type="button"
aria-label={label}
title="Drag to adjust · click to type"
@@ -151,7 +163,10 @@ export function ScrubValue({
if (!d.moved && Math.abs(dx) < 3) return;
d.moved = true;
// 2px per step; Shift coarsens to ×10.
- d.last = clamp(d.startValue + (dx / 2) * step * (e.shiftKey ? 10 : 1));
+ let next = clamp(d.startValue + (dx / 2) * step * (e.shiftKey ? 10 : 1));
+ const near = snap?.find((s) => Math.abs(next - s) <= 3 * step);
+ if (near !== undefined) next = clamp(near);
+ d.last = next;
if (onScrub) onScrub(d.last);
else setPreview(d.last);
}}
@@ -228,8 +243,8 @@ export function parsePercentInput(raw: string): number | null {
return m ? Number(m[1]) / 100 : null;
}
-/** Plain number, for unitless fields like text size. */
+/** Plain or signed number, degree sign allowed: "64", "-12", "12°". */
export function parseNumberInput(raw: string): number | null {
- const m = raw.trim().match(/^\d*\.?\d+$/);
+ const m = raw.trim().replace(/°$/, "").match(/^-?\d*\.?\d+$/);
return m ? Number(m[0]) : null;
}
diff --git a/site/src/cut/components/SubtitlesPanel.tsx b/site/src/cut/components/SubtitlesPanel.tsx
index 7196cca5..48df2635 100644
--- a/site/src/cut/components/SubtitlesPanel.tsx
+++ b/site/src/cut/components/SubtitlesPanel.tsx
@@ -258,6 +258,7 @@ function OptionsTab() {
min={24}
max={120}
step={1}
+ snap={[captionStyle(subtitles.style).size]}
value={subtitles.size ?? captionStyle(subtitles.style).size}
onValueChange={(v) => useEditor.getState().setSubtitlesView({ size: Number(v) })}
/>
diff --git a/site/src/cut/lib/drag.ts b/site/src/cut/lib/drag.ts
index cebd62bb..33a07d4a 100644
--- a/site/src/cut/lib/drag.ts
+++ b/site/src/cut/lib/drag.ts
@@ -86,10 +86,27 @@ export function startDrag(e: React.PointerEvent, opts: DragOpts) {
latest = ev;
if (!frame) frame = requestAnimationFrame(flush);
};
+ // The gesture owns this pointer through release: the browser may still
+ // synthesize a click on the common ancestor of the press and the release
+ // (canceling pointerdown leaves click alone in some engines), and that stray
+ // click lands on whatever sits under the pointer — the stage would take a
+ // handle drag's release as play/pause. Armed at release, disarmed by the
+ // click it eats or by the next press.
+ const swallowClick = (ce: MouseEvent) => {
+ ce.stopPropagation();
+ ce.preventDefault();
+ disarm();
+ };
+ const disarm = () => {
+ window.removeEventListener("click", swallowClick, true);
+ window.removeEventListener("pointerdown", disarm, true);
+ };
const up = (ev: PointerEvent) => {
window.removeEventListener("pointermove", move);
window.removeEventListener("pointerup", up);
window.removeEventListener("pointercancel", up);
+ window.addEventListener("click", swallowClick, true);
+ window.addEventListener("pointerdown", disarm, true);
// Land the last position before the gesture ends, so a fast release
// finishes where the pointer was rather than one frame behind it.
if (frame) cancelAnimationFrame(frame);