Open source CapCut alternative.
TypeScript
feat(site): scrubbable inspector values, safe preview rates
David Lea5251c2ff434
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex cd54e8a8..df3f2010 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -20,6 +20,14 @@ import { Switch } from "@/components/ui/switch";import { Textarea } from "@/components/ui/textarea";import { baseClips, getClipSpans, useEditor, type EditorState } from "@/cut/lib/store";import { GenerateSubtitlesAudio } from "@/cut/components/VoicePicker";+import {+ parseNumberInput,+ parsePercentInput,+ parseSecondsInput,+ parseSpeedInput,+ parseTimeInput,+ ScrubValue,+} from "@/cut/components/ScrubValue";import { PLATE_COLOR, PLATE_OPACITY, PLATE_RADIUS } from "@/cut/lib/textRender";import { writeTextStyle } from "@/cut/lib/textStyle";import { formatTime } from "@/cut/lib/time";@@ -28,6 +36,7 @@ import {LAYOUTS,rectOf,regionLabel,+ SPEED_FLOOR,SPEED_MAX,SPEED_MIN,TRANSITION_MAX,@@ -199,6 +208,13 @@ const Value = ({ children, className }: { children: React.ReactNode; className?:<span className={cn("font-mono text-[11.5px] tabular-nums", className)}>{children}</span>);+/** Matches the store's MIN_LEN: the shortest a trim can leave a clip. */+const MIN_TRIM = 0.1;++const formatSpeed = (v: number) => `${v.toFixed(2)}×`;+const formatFade = (v: number) => (v < 0.05 ? "Off" : `${v.toFixed(1)}s`);+const formatPercent = (v: number) => `${Math.round(v * 100)}%`;+/** One-click frame layouts (Full / Top / Bottom / Left / Right / PiP) shared by* the video-clip and overlay-clip panels. Picking one regions the clip so two* videos can share the frame; "Full" clears the region. */@@ -313,6 +329,9 @@ function ClipPanel({ clip }: { clip: VideoClip }) {const speed = speedDraft ?? clip.speed ?? 1;const xfade = xfadeDraft ?? clip.transition ?? 0;const speedLen = (clip.out - clip.in) / (speed > 0 ? speed : 1);+ // Typing can trim out to the source's end but no further; an image has no+ // intrinsic duration, so its clip can be any length.+ const maxOut = asset && asset.type !== "image" ? asset.duration : Infinity;return (<><PanelTitle>Video clip</PanelTitle>@@ -320,9 +339,42 @@ function ClipPanel({ clip }: { clip: VideoClip }) {<div className="mb-1.5 truncate border-b border-border pb-2.5 text-xs font-medium" title={asset?.name}>{asset?.name}</div>- <Row label="Length"><Value>{formatTime(speedLen)}</Value></Row>+ <Row label="Length">+ <ScrubValue+ label="Clip length"+ value={speedLen}+ min={MIN_TRIM}+ max={(maxOut - clip.in) / (speed > 0 ? speed : 1)}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) =>+ useEditor.getState().setClipTrim(clip.id, clip.in, clip.in + v * speed)+ }+ />+ </Row><Row label="Trim">- <Value>{formatTime(clip.in)} – {formatTime(clip.out)}</Value>+ <ScrubValue+ label="Trim start"+ value={clip.in}+ min={0}+ max={clip.out - MIN_TRIM}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) => useEditor.getState().setClipTrim(clip.id, v, clip.out)}+ />+ <Value className="text-muted-foreground">–</Value>+ <ScrubValue+ label="Trim end"+ value={clip.out}+ min={clip.in + MIN_TRIM}+ max={maxOut}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) => useEditor.getState().setClipTrim(clip.id, clip.in, v)}+ /></Row><Row label="Speed"><Slider@@ -337,7 +389,21 @@ function ClipPanel({ clip }: { clip: VideoClip }) {setSpeedDraft(null);}}/>- <Value className="w-9 text-right text-muted-foreground">{speed.toFixed(2)}×</Value>+ <ScrubValue+ label="Speed"+ className="w-9 text-muted-foreground"+ value={speed}+ min={SPEED_FLOOR}+ max={Infinity}+ step={0.05}+ format={formatSpeed}+ parse={parseSpeedInput}+ onScrub={setSpeedDraft}+ onCommit={(v) => {+ useEditor.getState().setClipSpeed(clip.id, v);+ setSpeedDraft(null);+ }}+ /></Row>{isFirst && (<Row label="Fade in">@@ -349,9 +415,18 @@ function ClipPanel({ clip }: { clip: VideoClip }) {value={fadeIn}onValueChange={(v) => useEditor.getState().setProjectFade({ fadeIn: Number(v) })}/>- <Value className="w-9 text-right text-muted-foreground">- {fadeIn < 0.05 ? "Off" : `${fadeIn.toFixed(1)}s`}- </Value>+ <ScrubValue+ label="Fade in"+ className="w-9 text-muted-foreground"+ value={fadeIn}+ min={0}+ max={TRANSITION_MAX}+ step={0.1}+ format={formatFade}+ parse={parseSecondsInput}+ onScrub={(v) => useEditor.getState().setProjectFade({ fadeIn: v })}+ onCommit={(v) => useEditor.getState().setProjectFade({ fadeIn: v })}+ /></Row>)}{isLast && (@@ -364,9 +439,18 @@ function ClipPanel({ clip }: { clip: VideoClip }) {value={fadeOut}onValueChange={(v) => useEditor.getState().setProjectFade({ fadeOut: Number(v) })}/>- <Value className="w-9 text-right text-muted-foreground">- {fadeOut < 0.05 ? "Off" : `${fadeOut.toFixed(1)}s`}- </Value>+ <ScrubValue+ label="Fade out"+ className="w-9 text-muted-foreground"+ value={fadeOut}+ min={0}+ max={TRANSITION_MAX}+ step={0.1}+ format={formatFade}+ parse={parseSecondsInput}+ onScrub={(v) => useEditor.getState().setProjectFade({ fadeOut: v })}+ onCommit={(v) => useEditor.getState().setProjectFade({ fadeOut: v })}+ /></Row>)}{hasNext && (@@ -408,9 +492,21 @@ function ClipPanel({ clip }: { clip: VideoClip }) {setXfadeDraft(null);}}/>- <Value className="w-9 text-right text-muted-foreground">- {xfade < 0.05 ? "Off" : `${xfade.toFixed(1)}s`}- </Value>+ <ScrubValue+ label="Transition length"+ className="w-9 text-muted-foreground"+ value={xfade}+ min={0}+ max={TRANSITION_MAX}+ step={0.1}+ format={formatFade}+ parse={parseSecondsInput}+ onScrub={setXfadeDraft}+ onCommit={(v) => {+ useEditor.getState().setClipTransition(clip.id, v);+ setXfadeDraft(null);+ }}+ /></Row></>)}@@ -432,9 +528,21 @@ function ClipPanel({ clip }: { clip: VideoClip }) {setVolumeDraft(null);}}/>- <Value className="w-9 text-right text-muted-foreground">- {Math.round(volume * 100)}%- </Value>+ <ScrubValue+ label="Clip volume"+ className="w-9 text-muted-foreground"+ value={volume}+ min={0}+ max={1.5}+ step={0.05}+ format={formatPercent}+ parse={parsePercentInput}+ onScrub={setVolumeDraft}+ onCommit={(v) => {+ updateClip(clip.id, { volume: v === 1 ? undefined : v });+ setVolumeDraft(null);+ }}+ /></Row><Row label="Mute audio"><Switch@@ -509,9 +617,29 @@ function ClipPanel({ clip }: { clip: VideoClip }) {setGenVolDraft(null);}}/>- <Value className="w-9 text-right text-muted-foreground">- {Math.round(genVol * 100)}%- </Value>+ <ScrubValue+ label="Generated audio volume"+ className="w-9 text-muted-foreground"+ value={genVol}+ min={0}+ max={1.5}+ step={0.05}+ format={formatPercent}+ parse={parsePercentInput}+ onScrub={(v) => {+ genCk.begin();+ setGenVolDraft(v);+ const s = useEditor.getState();+ genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: v }));+ }}+ onCommit={(v) => {+ genCk.begin();+ const s = useEditor.getState();+ genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: v }));+ genCk.end();+ setGenVolDraft(null);+ }}+ /></Row>)}</div>@@ -533,6 +661,12 @@ function AudioPanel({ clip }: { clip: AudioClip }) {const len = (clip.out - clip.in) / speed;// A fade can take at most half the clip so in+out never overlap.const maxFade = Math.max(0.1, Math.round((len / 2) * 10) / 10);+ // Commit closes the checkpoint setAudio opened (or opens+closes one for a+ // typed entry), so any adjustment lands as a single undo step.+ const commitAudio = (patch: Partial<AudioClip>) => {+ setAudio(patch);+ ck.end();+ };return (<><PanelTitle>Soundtrack</PanelTitle>@@ -540,8 +674,30 @@ function AudioPanel({ clip }: { clip: AudioClip }) {<div className="mb-1.5 truncate border-b border-border pb-2.5 text-xs font-medium" title={asset?.name}>{asset?.name}</div>- <Row label="Length"><Value>{formatTime(len)}</Value></Row>- <Row label="Starts at"><Value>{formatTime(clip.start)}</Value></Row>+ <Row label="Length">+ <ScrubValue+ label="Clip length"+ value={len}+ min={MIN_TRIM}+ max={((asset?.duration ?? clip.out) - clip.in) / speed}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) => commitAudio({ out: clip.in + v * speed })}+ />+ </Row>+ <Row label="Starts at">+ <ScrubValue+ label="Starts at"+ value={clip.start}+ min={0}+ max={Infinity}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) => commitAudio({ start: v })}+ />+ </Row><Row label="Speed"><SliderclassName="audio-speed data-horizontal:w-24"@@ -555,7 +711,18 @@ function AudioPanel({ clip }: { clip: AudioClip }) {}}onValueCommitted={ck.end}/>- <Value className="w-9 text-right text-muted-foreground">{speed.toFixed(2)}×</Value>+ <ScrubValue+ label="Speed"+ className="w-9 text-muted-foreground"+ value={speed}+ min={SPEED_FLOOR}+ max={Infinity}+ step={0.05}+ format={formatSpeed}+ parse={parseSpeedInput}+ onScrub={(v) => setAudio({ speed: Math.abs(v - 1) < 1e-4 ? undefined : v })}+ onCommit={(v) => commitAudio({ speed: Math.abs(v - 1) < 1e-4 ? undefined : v })}+ /></Row><Row label="Volume"><Slider@@ -567,9 +734,18 @@ function AudioPanel({ clip }: { clip: AudioClip }) {onValueChange={(v) => setAudio({ volume: Number(v) })}onValueCommitted={ck.end}/>- <Value className="w-9 text-right text-muted-foreground">- {Math.round(clip.volume * 100)}%- </Value>+ <ScrubValue+ label="Volume"+ className="w-9 text-muted-foreground"+ value={clip.volume}+ min={0}+ max={1.5}+ step={0.05}+ format={formatPercent}+ parse={parsePercentInput}+ onScrub={(v) => setAudio({ volume: v })}+ onCommit={(v) => commitAudio({ volume: v })}+ /></Row><Row label="Fade in"><Slider@@ -581,9 +757,18 @@ function AudioPanel({ clip }: { clip: AudioClip }) {onValueChange={(v) => setAudio({ fadeIn: Number(v) })}onValueCommitted={ck.end}/>- <Value className="w-9 text-right text-muted-foreground">- {(clip.fadeIn ?? 0).toFixed(1)}s- </Value>+ <ScrubValue+ label="Fade in"+ className="w-9 text-muted-foreground"+ value={clip.fadeIn ?? 0}+ min={0}+ max={maxFade}+ step={0.1}+ format={(v) => `${v.toFixed(1)}s`}+ parse={parseSecondsInput}+ onScrub={(v) => setAudio({ fadeIn: v })}+ onCommit={(v) => commitAudio({ fadeIn: v })}+ /></Row><Row label="Fade out"><Slider@@ -595,9 +780,18 @@ function AudioPanel({ clip }: { clip: AudioClip }) {onValueChange={(v) => setAudio({ fadeOut: Number(v) })}onValueCommitted={ck.end}/>- <Value className="w-9 text-right text-muted-foreground">- {(clip.fadeOut ?? 0).toFixed(1)}s- </Value>+ <ScrubValue+ label="Fade out"+ className="w-9 text-muted-foreground"+ value={clip.fadeOut ?? 0}+ min={0}+ max={maxFade}+ step={0.1}+ format={(v) => `${v.toFixed(1)}s`}+ parse={parseSecondsInput}+ onScrub={(v) => setAudio({ fadeOut: v })}+ onCommit={(v) => commitAudio({ fadeOut: v })}+ /></Row><Row label="Duck others"><Slider@@ -612,9 +806,18 @@ function AudioPanel({ clip }: { clip: AudioClip }) {}}onValueCommitted={ck.end}/>- <Value className="w-9 text-right text-muted-foreground">- {clip.duck === undefined ? "Off" : `${Math.round(clip.duck * 100)}%`}- </Value>+ <ScrubValue+ label="Duck others"+ className="w-9 text-muted-foreground"+ value={clip.duck ?? 1}+ min={0}+ max={1}+ step={0.05}+ format={(v) => (v >= 0.999 ? "Off" : formatPercent(v))}+ parse={(raw) => (raw.trim().toLowerCase() === "off" ? 1 : parsePercentInput(raw))}+ onScrub={(v) => setAudio({ duck: v < 0.999 ? v : undefined })}+ onCommit={(v) => commitAudio({ duck: v < 0.999 ? v : undefined })}+ /></Row>{clip.duck !== undefined && (<p className="text-[11px] leading-relaxed text-muted-foreground">@@ -639,6 +842,15 @@ function LayerClipPanel({ clip }: { clip: VideoClip }) {const ck = useSliderCheckpoint();const speed = clip.speed && clip.speed > 0 ? clip.speed : 1;const len = (clip.out - clip.in) / speed;+ const maxOut = asset && asset.type !== "image" ? asset.duration : Infinity;+ const setLayer = (patch: Partial<VideoClip>) => {+ ck.begin();+ updateTransient(clip.id, patch);+ };+ const commitLayer = (patch: Partial<VideoClip>) => {+ setLayer(patch);+ ck.end();+ };return (<><PanelTitle>Video clip</PanelTitle>@@ -646,8 +858,30 @@ function LayerClipPanel({ clip }: { clip: VideoClip }) {<div className="mb-1.5 truncate border-b border-border pb-2.5 text-xs font-medium" title={asset?.name}>{asset?.name}</div>- <Row label="Length"><Value>{formatTime(len)}</Value></Row>- <Row label="Starts at"><Value>{formatTime(clip.start)}</Value></Row>+ <Row label="Length">+ <ScrubValue+ label="Clip length"+ value={len}+ min={MIN_TRIM}+ max={(maxOut - clip.in) / speed}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) => commitLayer({ out: clip.in + v * speed })}+ />+ </Row>+ <Row label="Starts at">+ <ScrubValue+ label="Starts at"+ value={clip.start}+ min={0}+ max={Infinity}+ step={0.1}+ format={formatTime}+ parse={parseTimeInput}+ onCommit={(v) => commitLayer({ start: v })}+ />+ </Row><Row label="Speed"><SliderclassName="layer-speed data-horizontal:w-24"@@ -662,7 +896,18 @@ function LayerClipPanel({ clip }: { clip: VideoClip }) {}}onValueCommitted={ck.end}/>- <Value className="w-9 text-right text-muted-foreground">{speed.toFixed(2)}×</Value>+ <ScrubValue+ label="Speed"+ className="w-9 text-muted-foreground"+ value={speed}+ min={SPEED_FLOOR}+ max={Infinity}+ step={0.05}+ format={formatSpeed}+ parse={parseSpeedInput}+ onScrub={(v) => setLayer({ speed: Math.abs(v - 1) < 1e-4 ? undefined : v })}+ onCommit={(v) => commitLayer({ speed: Math.abs(v - 1) < 1e-4 ? undefined : v })}+ /></Row><LayoutButtonsrect={rectOf(clip)}@@ -818,7 +1063,25 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {}}onValueCommitted={sizeCk.end}/>- <Value className="w-9 text-right text-muted-foreground">{o.size}</Value>+ <ScrubValue+ label="Text size"+ className="w-9 text-muted-foreground"+ value={o.size}+ min={24}+ max={240}+ step={1}+ format={(v) => String(Math.round(v))}+ parse={parseNumberInput}+ onScrub={(v) => {+ sizeCk.begin();+ useEditor.getState().updateOverlayTransient(o.id, { size: v });+ }}+ onCommit={(v) => {+ sizeCk.begin();+ useEditor.getState().updateOverlayTransient(o.id, { size: v });+ sizeCk.end();+ }}+ /></Row><Row label="Color"><ColorSwatches@@ -857,9 +1120,25 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {}}onValueCommitted={opacityCk.end}/>- <Value className="w-9 text-right text-muted-foreground">- {Math.round((o.plateOpacity ?? PLATE_OPACITY) * 100)}- </Value>+ <ScrubValue+ label="Backdrop opacity"+ className="w-9 text-muted-foreground"+ value={o.plateOpacity ?? PLATE_OPACITY}+ min={0}+ max={1}+ step={0.01}+ format={(v) => String(Math.round(v * 100))}+ parse={parsePercentInput}+ onScrub={(v) => {+ opacityCk.begin();+ useEditor.getState().updateOverlayTransient(o.id, { plateOpacity: v });+ }}+ onCommit={(v) => {+ opacityCk.begin();+ useEditor.getState().updateOverlayTransient(o.id, { plateOpacity: v });+ opacityCk.end();+ }}+ /></Row><Row label="Radius"><Slider@@ -874,9 +1153,25 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {}}onValueCommitted={radiusCk.end}/>- <Value className="w-9 text-right text-muted-foreground">- {Math.round((o.plateRadius ?? PLATE_RADIUS) * 100)}- </Value>+ <ScrubValue+ label="Backdrop radius"+ className="w-9 text-muted-foreground"+ value={o.plateRadius ?? PLATE_RADIUS}+ min={0}+ max={1}+ step={0.01}+ format={(v) => String(Math.round(v * 100))}+ parse={parsePercentInput}+ onScrub={(v) => {+ radiusCk.begin();+ useEditor.getState().updateOverlayTransient(o.id, { plateRadius: v });+ }}+ onCommit={(v) => {+ radiusCk.begin();+ useEditor.getState().updateOverlayTransient(o.id, { plateRadius: v });+ radiusCk.end();+ }}+ /></Row></>)}diff --git a/site/src/cut/components/ScrubValue.tsx b/site/src/cut/components/ScrubValue.tsxnew file mode 100644index 00000000..3ffbe1bb--- /dev/null+++ b/site/src/cut/components/ScrubValue.tsx@@ -0,0 +1,231 @@+"use client";++import { useEffect, useRef, useState } from "react";+import { cn } from "@/lib/utils";++/**+ * Hot-text numeric value: reads as the plain mono readout it replaces, drag+ * horizontally to scrub (Shift = ×10 steps), click to type an exact value.+ * Enter/blur commits, Escape cancels, arrow keys nudge by one step.+ *+ * With `onScrub` the drag streams live values (pair it with a draft/transient+ * updater like the sliders use); without it the drag previews in place and+ * `onCommit` fires once on release, so actions that checkpoint history+ * internally stay one undo step.+ */+export function ScrubValue({+ value,+ min,+ max,+ step,+ format,+ parse,+ onScrub,+ onCommit,+ className,+ label,+}: {+ value: number;+ min: number;+ max: number;+ step: number;+ format: (v: number) => string;+ parse: (raw: string) => number | null;+ onScrub?: (v: number) => void;+ onCommit: (v: number) => void;+ className?: string;+ label: string;+}) {+ const [editing, setEditing] = useState(false);+ const [draft, setDraft] = useState("");+ const [preview, setPreview] = useState<number | null>(null);+ const inputRef = useRef<HTMLInputElement>(null);+ 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.+ const editStart = useRef(0);+ const liveArrowed = useRef(false);+ const drag = useRef<{ startX: number; startValue: number; moved: boolean; last: number } | null>(+ null+ );++ const clamp = (v: number) => Math.min(max, Math.max(min, quantize(v, step)));++ useEffect(() => {+ if (editing) inputRef.current?.select();+ }, [editing]);++ const openEditor = () => {+ skipBlur.current = false;+ liveArrowed.current = false;+ editStart.current = value;+ setDraft(format(value));+ setEditing(true);+ };++ const commitDraft = () => {+ setEditing(false);+ const parsed = parse(draft.trim());+ if (parsed != null && Number.isFinite(parsed)) {+ // Unconditional (even when unchanged): commit is also what clears the+ // caller's scrub draft after live arrow steps.+ onCommit(clamp(parsed));+ } else if (liveArrowed.current) {+ // Arrow steps applied live, then the text turned unparseable: restore.+ onCommit(clamp(editStart.current));+ }+ liveArrowed.current = false;+ };++ if (editing) {+ return (+ <input+ ref={inputRef}+ 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` }}+ className={cn(+ "border-b border-primary/60 bg-transparent text-right font-mono text-[11.5px] tabular-nums text-foreground outline-none",+ className+ )}+ onChange={(e) => setDraft(e.target.value)}+ onBlur={() => {+ if (skipBlur.current) {+ skipBlur.current = false;+ return;+ }+ commitDraft();+ }}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ skipBlur.current = true;+ commitDraft();+ } else if (e.key === "Escape") {+ skipBlur.current = true;+ setEditing(false);+ if (liveArrowed.current) {+ liveArrowed.current = false;+ onCommit(clamp(editStart.current));+ }+ } else if (e.key === "ArrowUp" || e.key === "ArrowDown") {+ e.preventDefault();+ const cur = parse(draft.trim());+ const base = cur != null && Number.isFinite(cur) ? cur : value;+ const dir = e.key === "ArrowUp" ? 1 : -1;+ const next = clamp(base + dir * step * (e.shiftKey ? 10 : 1));+ setDraft(format(next));+ if (onScrub) {+ onScrub(next);+ liveArrowed.current = true;+ }+ }+ }}+ />+ );+ }++ return (+ <button+ type="button"+ aria-label={label}+ title="Drag to adjust · click to type"+ className={cn(+ "cursor-ew-resize touch-none select-none text-right font-mono text-[11.5px] tabular-nums underline decoration-transparent decoration-dotted underline-offset-3 transition-colors hover:text-foreground hover:decoration-current",+ className+ )}+ onPointerDown={(e) => {+ if (e.button !== 0) return;+ drag.current = { startX: e.clientX, startValue: value, moved: false, last: value };+ e.currentTarget.setPointerCapture(e.pointerId);+ }}+ onPointerMove={(e) => {+ const d = drag.current;+ if (!d) return;+ const dx = e.clientX - d.startX;+ 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));+ if (onScrub) onScrub(d.last);+ else setPreview(d.last);+ }}+ onPointerUp={(e) => {+ const d = drag.current;+ drag.current = null;+ e.currentTarget.releasePointerCapture(e.pointerId);+ if (!d) return;+ if (d.moved) {+ setPreview(null);+ // Unconditional: with onScrub the value prop already tracks the+ // drag, so an equality guard would swallow the closing commit.+ onCommit(d.last);+ } else {+ openEditor();+ }+ }}+ onPointerCancel={() => {+ const d = drag.current;+ drag.current = null;+ setPreview(null);+ if (d?.moved) onCommit(d.last);+ }}+ onKeyDown={(e) => {+ // Keyboard path: Enter/Space opens the editor; arrows step the value+ // directly, each press one commit.+ if (e.key === "Enter" || e.key === " ") {+ e.preventDefault();+ openEditor();+ } else if (e.key === "ArrowUp" || e.key === "ArrowDown") {+ e.preventDefault();+ const dir = e.key === "ArrowUp" ? 1 : -1;+ onCommit(clamp(value + dir * step * (e.shiftKey ? 10 : 1)));+ }+ }}+ >+ {format(preview ?? value)}+ </button>+ );+}++/** Snap to the step grid so scrubbed values stay clean (step 0.1 → one decimal). */+function quantize(v: number, step: number) {+ return Number((Math.round(v / step) * step).toFixed(4));+}++/** "1:30", "1:30.5", "90", "0:06.5" → seconds. */+export function parseTimeInput(raw: string): number | null {+ const m = raw.match(/^(?:(\d+):)?(\d+(?:\.\d+)?)$/);+ if (!m) return null;+ return (m[1] ? Number(m[1]) : 0) * 60 + Number(m[2]);+}++/** "1.25", "1.25x", "1.25×", "125%" → playback rate. */+export function parseSpeedInput(raw: string): number | null {+ const s = raw.toLowerCase().replace(/\s+/g, "");+ const pct = s.match(/^(\d+(?:\.\d+)?)%$/);+ if (pct) return Number(pct[1]) / 100;+ const m = s.match(/^(\d*\.?\d+)[x×]?$/);+ return m ? Number(m[1]) : null;+}++/** "0.5", "0.5s", "off" → seconds. */+export function parseSecondsInput(raw: string): number | null {+ const s = raw.toLowerCase().replace(/\s+/g, "");+ if (s === "off") return 0;+ const m = s.match(/^(\d*\.?\d+)s?$/);+ return m ? Number(m[1]) : null;+}++/** "80", "80%" → fraction 0.8. */+export function parsePercentInput(raw: string): number | null {+ const m = raw.trim().match(/^(\d*\.?\d+)%?$/);+ return m ? Number(m[1]) / 100 : null;+}++/** Plain number, for unitless fields like text size. */+export function parseNumberInput(raw: string): number | null {+ const m = raw.trim().match(/^\d*\.?\d+$/);+ return m ? Number(m[0]) : null;+}diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsxindex 3d39e7f7..1c8994ef 100644--- a/site/src/cut/components/Timeline.tsx+++ b/site/src/cut/components/Timeline.tsx@@ -297,6 +297,7 @@ export function Timeline() {// Scrub with auto-scroll when the pointer nears the viewport edges.const scrub = (e: React.PointerEvent) => {const s = useEditor.getState();+ if (s.playing) s.setPlaying(false);s.seek(timeAt(e.clientX));const el = scrollRef.current;startDrag(e, {diff --git a/site/src/cut/hooks/usePlayback.ts b/site/src/cut/hooks/usePlayback.tsindex 89f67d56..2da464b9 100644--- a/site/src/cut/hooks/usePlayback.ts+++ b/site/src/cut/hooks/usePlayback.ts@@ -35,6 +35,11 @@ const elH = (el: MediaEl) => (isImageEl(el) ? el.naturalHeight : el.videoHeight)// The compositor paints through these instead of wedging on them.const elErrored = (el: MediaEl) =>isImageEl(el) ? el.complete && el.naturalWidth === 0 : !!el.error;+/** Browsers reject playbackRate outside roughly 0.0625–16, so the element+ * rate is clamped; beyond it the periodic seek correction carries the true+ * speed, at the cost of a choppier preview. Export renders the real rate. */+const safeRate = (speed: number) => Math.min(16, Math.max(0.0625, speed));+const pauseEl = (el: MediaEl) => {if (!isImageEl(el) && !el.paused) el.pause();};@@ -128,7 +133,8 @@ class Engine {// <img> decodes. Skip every video-clock operation.if (isImageEl(el)) return el;const speed = clipSpeed(span.clip);- if (el.playbackRate !== speed) el.playbackRate = speed;+ const rate = safeRate(speed);+ if (el.playbackRate !== rate) el.playbackRate = rate;const target = span.clip.in + Math.max(0, t - span.start) * speed;// While playing, the element is its own clock and advances on its own, so// only re-seek on a real jump (a clip switch or a scrub) — never for the@@ -413,7 +419,8 @@ class Engine {const el = this.overlayVideoFor(clip, asset);if (isImageEl(el)) return el;const speed = clip.speed && clip.speed > 0 ? clip.speed : 1;- if (el.playbackRate !== speed) el.playbackRate = speed;+ const rate = safeRate(speed);+ if (el.playbackRate !== rate) el.playbackRate = rate;const target = clip.in + Math.max(0, t - clip.start) * speed;const tol = play ? 0.34 : 0.05;if (Math.abs(el.currentTime - target) > tol && !el.seeking) el.currentTime = target;@@ -499,7 +506,8 @@ class Engine {// ducking clips never duck each other.const dg = a.duck !== undefined && a.duck < 1 ? 1 : duckGainAt(s.audioClips, t);el.volume = Math.max(0, Math.min(1, a.volume * gain * dg * fadeGain));- if (el.playbackRate !== speed) el.playbackRate = speed;+ const rate = safeRate(speed);+ if (el.playbackRate !== rate) el.playbackRate = rate;const expected = a.in + rel * speed;if (Math.abs(el.currentTime - expected) > 0.25) el.currentTime = expected;if (el.paused) void el.play().catch(() => {});