Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

global auto toggle

Siddhartha3716581b0b6
diff --git a/src/components/video-editor/SettingsPanel.tsx b/src/components/video-editor/SettingsPanel.tsx
index cffeadcc2..b9bfeca0f 100644
--- a/src/components/video-editor/SettingsPanel.tsx
+++ b/src/components/video-editor/SettingsPanel.tsx
@@ -247,6 +247,8 @@ interface SettingsPanelProps {
onZoomPreviewEnd?: () => void;
selectedZoomFocusMode?: ZoomFocusMode | null;
onZoomFocusModeChange?: (mode: ZoomFocusMode) => void;
+ /** When the global Auto-Focus toggle is on, the per-zoom selector is locked. */
+ focusModeLocked?: boolean;
selectedZoomFocus?: ZoomFocus | null;
onZoomFocusCoordinateChange?: (focus: ZoomFocus) => void;
onZoomFocusCoordinateCommit?: () => void;
@@ -383,6 +385,7 @@ export function SettingsPanel({
onZoomPreviewEnd,
selectedZoomFocusMode,
onZoomFocusModeChange,
+ focusModeLocked = false,
selectedZoomFocus,
onZoomFocusCoordinateChange,
onZoomFocusCoordinateCommit,
@@ -944,32 +947,42 @@ export function SettingsPanel({
</div>
)}
{zoomEnabled && hasCursorTelemetry && (
- <div className="flex items-center justify-between gap-3">
- <span className="text-[11px] font-medium text-slate-400">
- {t("zoom.focusMode.title")}
- </span>
- <div className="grid w-32 grid-cols-2 gap-0.5 rounded-lg border border-white/[0.06] bg-white/[0.035] p-0.5">
- {(["manual", "auto"] as const).map((mode) => {
- const isActive = selectedZoomFocusMode === mode;
- return (
- <Button
- key={mode}
- type="button"
- onClick={() => onZoomFocusModeChange?.(mode)}
- className={cn(
- "h-6 w-full rounded-md border px-1 text-center transition-all duration-150 ease-out cursor-pointer",
- isActive
- ? "border-[#34B27B]/50 bg-[#34B27B] text-white"
- : "border-transparent bg-transparent text-slate-400 hover:bg-white/[0.06] hover:text-slate-200",
- )}
- >
- <span className="text-[10px] font-semibold capitalize">
- {t(`zoom.focusMode.${mode}`)}
- </span>
- </Button>
- );
- })}
+ <div className="space-y-1.5">
+ <div className="flex items-center justify-between gap-3">
+ <span className="text-[11px] font-medium text-slate-400">
+ {t("zoom.focusMode.title")}
+ </span>
+ <div className="grid w-32 grid-cols-2 gap-0.5 rounded-lg border border-white/[0.06] bg-white/[0.035] p-0.5">
+ {(["manual", "auto"] as const).map((mode) => {
+ const isActive = selectedZoomFocusMode === mode;
+ return (
+ <Button
+ key={mode}
+ type="button"
+ disabled={focusModeLocked}
+ onClick={() => !focusModeLocked && onZoomFocusModeChange?.(mode)}
+ className={cn(
+ "h-6 w-full rounded-md border px-1 text-center transition-all duration-150 ease-out",
+ isActive
+ ? "border-[#34B27B]/50 bg-[#34B27B] text-white"
+ : "border-transparent bg-transparent text-slate-400 hover:bg-white/[0.06] hover:text-slate-200",
+ focusModeLocked ? "cursor-not-allowed opacity-50" : "cursor-pointer",
+ )}
+ >
+ <span className="text-[10px] font-semibold capitalize">
+ {t(`zoom.focusMode.${mode}`)}
+ </span>
+ </Button>
+ );
+ })}
+ </div>
</div>
+ {focusModeLocked && (
+ <div className="flex items-start gap-1 text-[10px] leading-snug text-slate-500">
+ <Info size={11} className="mt-px shrink-0" />
+ <span>{t("zoom.focusMode.lockedDisclaimer")}</span>
+ </div>
+ )}
</div>
)}
{zoomEnabled && onZoomPreviewStart && onZoomPreviewEnd && (
diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx
index 9ce39614b..e36b07692 100644
--- a/src/components/video-editor/VideoEditor.tsx
+++ b/src/components/video-editor/VideoEditor.tsx
@@ -89,6 +89,7 @@ import {
} from "./projectPersistence";
import { SettingsPanel } from "./SettingsPanel";
import TimelineEditor from "./timeline/TimelineEditor";
+import { buildAutoZoomSuggestions } from "./timeline/zoomSuggestionUtils";
import {
type AnnotationRegion,
type BlurData,
@@ -188,6 +189,8 @@ export default function VideoEditor() {
const {
zoomRegions,
+ autoZoomEnabled,
+ autoFocusAll,
trimRegions,
speedRegions,
annotationRegions,
@@ -389,6 +392,10 @@ export default function VideoEditor() {
setRecordingCursorCaptureMode(projectCursorCaptureMode);
setCurrentProjectPath(path ?? null);
+ // A loaded project keeps its zooms exactly as saved — never auto-suggest
+ // over it (even if it has zero zooms because the user deleted them all).
+ autoProcessedSourceRef.current = sourcePath;
+
pushState({
wallpaper: normalizedEditor.wallpaper,
shadowIntensity: normalizedEditor.shadowIntensity,
@@ -399,6 +406,8 @@ export default function VideoEditor() {
padding: normalizedEditor.padding,
cropRegion: normalizedEditor.cropRegion,
zoomRegions: normalizedEditor.zoomRegions,
+ autoZoomEnabled: normalizedEditor.autoZoomEnabled,
+ autoFocusAll: normalizedEditor.autoFocusAll,
trimRegions: normalizedEditor.trimRegions,
speedRegions: normalizedEditor.speedRegions,
annotationRegions: normalizedEditor.annotationRegions,
@@ -472,6 +481,8 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
+ autoZoomEnabled,
+ autoFocusAll,
trimRegions,
speedRegions,
annotationRegions,
@@ -498,6 +509,8 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
+ autoZoomEnabled,
+ autoFocusAll,
trimRegions,
speedRegions,
annotationRegions,
@@ -624,6 +637,8 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
+ autoZoomEnabled,
+ autoFocusAll,
trimRegions,
speedRegions,
annotationRegions,
@@ -685,6 +700,8 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
+ autoZoomEnabled,
+ autoFocusAll,
trimRegions,
speedRegions,
annotationRegions,
@@ -991,6 +1008,9 @@ export default function VideoEditor() {
depth: DEFAULT_ZOOM_DEPTH,
customScale: ZOOM_DEPTH_SCALES[DEFAULT_ZOOM_DEPTH],
focus: { cx: 0.5, cy: 0.5 },
+ // Auto-Focus toggle on → new zooms follow the cursor too.
+ focusMode: autoFocusAll ? "auto" : undefined,
+ source: "manual",
};
pushState((prev) => ({ zoomRegions: [...prev.zoomRegions, newRegion] }));
setSelectedZoomId(id);
@@ -999,24 +1019,94 @@ export default function VideoEditor() {
setSelectedAnnotationId(null);
setSelectedBlurId(null);
},
- [pushState],
+ [pushState, autoFocusAll],
);
- const handleZoomSuggested = useCallback(
- (span: Span, focus: ZoomFocus) => {
- const id = `zoom-${nextZoomIdRef.current++}`;
- const newRegion: ZoomRegion = {
- id,
- startMs: Math.round(span.start),
- endMs: Math.round(span.end),
+ // Builds fresh "auto" zoom regions from cursor telemetry, avoiding overlap with
+ // the regions already present. Used by both the on-load auto-suggest pass and
+ // the magic-wand toggle.
+ const buildAutoZoomRegions = useCallback(
+ (existingRegions: ZoomRegion[]): ZoomRegion[] => {
+ const totalMs = Math.round(duration * 1000);
+ const suggestions = buildAutoZoomSuggestions({
+ cursorTelemetry,
+ totalMs,
+ existingRegions,
+ defaultDurationMs: Math.max(1000, Math.round(totalMs * 0.05)),
+ });
+ return suggestions.map((suggestion) => ({
+ id: `zoom-${nextZoomIdRef.current++}`,
+ startMs: Math.round(suggestion.span.start),
+ endMs: Math.round(suggestion.span.end),
depth: DEFAULT_ZOOM_DEPTH,
customScale: ZOOM_DEPTH_SCALES[DEFAULT_ZOOM_DEPTH],
- focus: clampFocusToDepth(focus, DEFAULT_ZOOM_DEPTH),
- };
- // Bulk suggest must not steal selection — keeping a zoom selected hides
- // the export panel (SettingsPanel gates it on !hasTimelineSelection),
- // trapping users who just want to export after auto-zoom.
- pushState((prev) => ({ zoomRegions: [...prev.zoomRegions, newRegion] }));
+ focus: clampFocusToDepth(suggestion.focus, DEFAULT_ZOOM_DEPTH),
+ focusMode: autoFocusAll ? ("auto" as const) : undefined,
+ source: "auto" as const,
+ }));
+ },
+ [cursorTelemetry, duration, autoFocusAll],
+ );
+
+ // Auto-suggest zooms once per fresh recording (no existing zooms, telemetry
+ // available, wand enabled). Loaded projects are marked processed elsewhere so
+ // they're never touched. The ref guard makes this run exactly once per source
+ // and survive undo.
+ const autoProcessedSourceRef = useRef<string | null>(null);
+ useEffect(() => {
+ if (!autoZoomEnabled || !cursorTelemetrySourcePath) return;
+ if (autoProcessedSourceRef.current === cursorTelemetrySourcePath) return;
+ if (cursorTelemetry.length < 2 || duration <= 0) return;
+ // Only auto-suggest for a fresh recording; don't disturb existing zooms.
+ if (zoomRegions.length > 0) {
+ autoProcessedSourceRef.current = cursorTelemetrySourcePath;
+ return;
+ }
+ const newRegions = buildAutoZoomRegions([]);
+ autoProcessedSourceRef.current = cursorTelemetrySourcePath;
+ if (newRegions.length === 0) return;
+ pushState((prev) => ({ zoomRegions: [...prev.zoomRegions, ...newRegions] }));
+ }, [
+ autoZoomEnabled,
+ cursorTelemetrySourcePath,
+ cursorTelemetry,
+ duration,
+ zoomRegions,
+ buildAutoZoomRegions,
+ pushState,
+ ]);
+
+ // Magic-wand toggle: ON regenerates suggestions around existing zooms; OFF
+ // removes only untouched auto zooms (manual + edited-to-manual survive).
+ const handleToggleAutoZoom = useCallback(
+ (enabled: boolean) => {
+ if (enabled) {
+ autoProcessedSourceRef.current = cursorTelemetrySourcePath;
+ pushState((prev) => ({
+ autoZoomEnabled: true,
+ zoomRegions: [...prev.zoomRegions, ...buildAutoZoomRegions(prev.zoomRegions)],
+ }));
+ } else {
+ pushState((prev) => ({
+ autoZoomEnabled: false,
+ zoomRegions: prev.zoomRegions.filter((region) => region.source !== "auto"),
+ }));
+ }
+ },
+ [pushState, buildAutoZoomRegions, cursorTelemetrySourcePath],
+ );
+
+ // Global Auto-Focus toggle: flip every zoom between auto (cursor-follow) and
+ // manual at once.
+ const handleToggleAutoFocusAll = useCallback(
+ (on: boolean) => {
+ pushState((prev) => ({
+ autoFocusAll: on,
+ zoomRegions: prev.zoomRegions.map((region) => ({
+ ...region,
+ focusMode: on ? "auto" : "manual",
+ })),
+ }));
},
[pushState],
);
@@ -1048,6 +1138,7 @@ export default function VideoEditor() {
...region,
startMs: Math.round(span.start),
endMs: Math.round(span.end),
+ source: "manual",
}
: region,
),
@@ -1078,7 +1169,9 @@ export default function VideoEditor() {
(id: string, focus: ZoomFocus) => {
updateState((prev) => ({
zoomRegions: prev.zoomRegions.map((region) =>
- region.id === id ? { ...region, focus: clampFocusToDepth(focus, region.depth) } : region,
+ region.id === id
+ ? { ...region, focus: clampFocusToDepth(focus, region.depth), source: "manual" }
+ : region,
),
}));
},
@@ -1096,6 +1189,7 @@ export default function VideoEditor() {
depth,
customScale: ZOOM_DEPTH_SCALES[depth],
focus: clampFocusToDepth(region.focus, depth),
+ source: "manual",
}
: region,
),
@@ -1111,7 +1205,9 @@ export default function VideoEditor() {
if (!Number.isFinite(rounded)) return;
updateState((prev) => ({
zoomRegions: prev.zoomRegions.map((region) =>
- region.id === selectedZoomId ? { ...region, customScale: rounded } : region,
+ region.id === selectedZoomId
+ ? { ...region, customScale: rounded, source: "manual" }
+ : region,
),
}));
},
@@ -1127,7 +1223,7 @@ export default function VideoEditor() {
if (!selectedZoomId) return;
pushState((prev) => ({
zoomRegions: prev.zoomRegions.map((region) =>
- region.id === selectedZoomId ? { ...region, focusMode } : region,
+ region.id === selectedZoomId ? { ...region, focusMode, source: "manual" } : region,
),
}));
},
@@ -1154,9 +1250,9 @@ export default function VideoEditor() {
if (region.id !== selectedZoomId) return region;
if (preset === null) {
const { rotationPreset: _p, ...rest } = region;
- return rest;
+ return { ...rest, source: "manual" };
}
- return { ...region, rotationPreset: preset };
+ return { ...region, rotationPreset: preset, source: "manual" };
}),
}));
},
@@ -2580,6 +2676,7 @@ export default function VideoEditor() {
onZoomFocusModeChange={(mode) =>
selectedZoomId && handleZoomFocusModeChange(mode)
}
+ focusModeLocked={autoFocusAll}
selectedZoomFocus={
selectedZoomId
? (zoomRegions.find((z) => z.id === selectedZoomId)?.focus ?? null)
@@ -2735,10 +2832,12 @@ export default function VideoEditor() {
videoDuration={duration}
currentTime={currentTime}
onSeek={handleSeek}
- cursorTelemetry={cursorTelemetry}
zoomRegions={zoomRegions}
onZoomAdded={handleZoomAdded}
- onZoomSuggested={handleZoomSuggested}
+ autoZoomEnabled={autoZoomEnabled}
+ onToggleAutoZoom={handleToggleAutoZoom}
+ autoFocusAll={autoFocusAll}
+ onToggleAutoFocusAll={handleToggleAutoFocusAll}
onZoomSpanChange={handleZoomSpanChange}
onZoomDelete={handleZoomDelete}
selectedZoomId={selectedZoomId}
diff --git a/src/components/video-editor/projectPersistence.ts b/src/components/video-editor/projectPersistence.ts
index 35a631469..de03adf2b 100644
--- a/src/components/video-editor/projectPersistence.ts
+++ b/src/components/video-editor/projectPersistence.ts
@@ -73,6 +73,8 @@ export interface ProjectEditorState {
padding: number;
cropRegion: CropRegion;
zoomRegions: ZoomRegion[];
+ autoZoomEnabled: boolean;
+ autoFocusAll: boolean;
trimRegions: TrimRegion[];
speedRegions: SpeedRegion[];
annotationRegions: AnnotationRegion[];
@@ -260,6 +262,7 @@ export function normalizeProjectEditor(editor: Partial<ProjectEditorState>): Pro
cy: clamp(isFiniteNumber(region.focus?.cy) ? region.focus.cy : 0.5, 0, 1),
},
focusMode: region.focusMode === "auto" ? "auto" : "manual",
+ source: region.source === "auto" ? "auto" : "manual",
...(validPreset ? { rotationPreset: validPreset } : {}),
};
})
@@ -477,6 +480,10 @@ export function normalizeProjectEditor(editor: Partial<ProjectEditorState>): Pro
height: cropHeight,
},
zoomRegions: normalizedZoomRegions,
+ // Default on for legacy projects so re-opens behave like the new default;
+ // the on-load auto-suggest pass is gated separately so it won't add zooms.
+ autoZoomEnabled: typeof editor.autoZoomEnabled === "boolean" ? editor.autoZoomEnabled : true,
+ autoFocusAll: typeof editor.autoFocusAll === "boolean" ? editor.autoFocusAll : false,
trimRegions: normalizedTrimRegions,
speedRegions: normalizedSpeedRegions,
annotationRegions: normalizedAnnotationRegions,
diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsx
index 65ebd8bdb..12ac0b0a5 100644
--- a/src/components/video-editor/timeline/TimelineEditor.tsx
+++ b/src/components/video-editor/timeline/TimelineEditor.tsx
@@ -7,6 +7,7 @@ import {
Gauge,
MessageSquare,
Plus,
+ ScanEye,
Scissors,
WandSparkles,
ZoomIn,
@@ -28,20 +29,12 @@ import { matchesShortcut } from "@/lib/shortcuts";
import { cn } from "@/lib/utils";
import { ASPECT_RATIOS, type AspectRatio, getAspectRatioLabel } from "@/utils/aspectRatioUtils";
import { formatShortcut } from "@/utils/platformUtils";
-import type {
- AnnotationRegion,
- CursorTelemetryPoint,
- SpeedRegion,
- TrimRegion,
- ZoomFocus,
- ZoomRegion,
-} from "../types";
+import type { AnnotationRegion, SpeedRegion, TrimRegion, ZoomRegion } from "../types";
import BackgroundWaveform from "./BackgroundWaveform";
import Item from "./Item";
import KeyframeMarkers from "./KeyframeMarkers";
import Row from "./Row";
import TimelineWrapper from "./TimelineWrapper";
-import { detectZoomDwellCandidates, normalizeCursorTelemetry } from "./zoomSuggestionUtils";
const ZOOM_ROW_ID = "row-zoom";
const TRIM_ROW_ID = "row-trim";
@@ -50,17 +43,20 @@ const BLUR_ROW_ID = "row-blur";
const SPEED_ROW_ID = "row-speed";
const FALLBACK_RANGE_MS = 1000;
const TARGET_MARKER_COUNT = 12;
-const SUGGESTION_SPACING_MS = 1800;
interface TimelineEditorProps {
videoDuration: number;
hasVideoSource?: boolean;
currentTime: number;
onSeek?: (time: number) => void;
- cursorTelemetry?: CursorTelemetryPoint[];
zoomRegions: ZoomRegion[];
onZoomAdded: (span: Span) => void;
- onZoomSuggested?: (span: Span, focus: ZoomFocus) => void;
+ /** Magic-wand auto-zoom toggle state + handler. */
+ autoZoomEnabled?: boolean;
+ onToggleAutoZoom?: (enabled: boolean) => void;
+ /** Global Auto-Focus toggle state + handler. */
+ autoFocusAll?: boolean;
+ onToggleAutoFocusAll?: (on: boolean) => void;
onZoomSpanChange: (id: string, span: Span) => void;
onZoomDelete: (id: string) => void;
selectedZoomId: string | null;
@@ -894,10 +890,12 @@ export default function TimelineEditor({
hasVideoSource = false,
currentTime,
onSeek,
- cursorTelemetry = [],
zoomRegions,
onZoomAdded,
- onZoomSuggested,
+ autoZoomEnabled = true,
+ onToggleAutoZoom,
+ autoFocusAll = false,
+ onToggleAutoFocusAll,
onZoomSpanChange,
onZoomDelete,
selectedZoomId,
@@ -1156,103 +1154,6 @@ export default function TimelineEditor({
onZoomAdded({ start: startPos, end: startPos + actualDuration });
}, [videoDuration, totalMs, currentTimeMs, zoomRegions, onZoomAdded, defaultRegionDurationMs, t]);
- const handleSuggestZooms = useCallback(() => {
- if (!videoDuration || videoDuration === 0 || totalMs === 0) {
- return;
- }
-
- if (!onZoomSuggested) {
- toast.error(t("errors.zoomSuggestionUnavailable"));
- return;
- }
-
- if (cursorTelemetry.length < 2) {
- toast.info(t("errors.noCursorTelemetry"), {
- description: t("errors.noCursorTelemetryDescription"),
- });
- return;
- }
-
- const defaultDuration = Math.min(defaultRegionDurationMs, totalMs);
- if (defaultDuration <= 0) {
- return;
- }
-
- const reservedSpans = [...zoomRegions]
- .map((region) => ({ start: region.startMs, end: region.endMs }))
- .sort((a, b) => a.start - b.start);
-
- const normalizedSamples = normalizeCursorTelemetry(cursorTelemetry, totalMs);
-
- if (normalizedSamples.length < 2) {
- toast.info(t("errors.noUsableTelemetry"), {
- description: t("errors.noUsableTelemetryDescription"),
- });
- return;
- }
-
- const dwellCandidates = detectZoomDwellCandidates(normalizedSamples);
-
- if (dwellCandidates.length === 0) {
- toast.info(t("errors.noDwellMoments"), {
- description: t("errors.noDwellMomentsDescription"),
- });
- return;
- }
-
- const sortedCandidates = [...dwellCandidates].sort((a, b) => b.strength - a.strength);
- const acceptedCenters: number[] = [];
-
- let addedCount = 0;
-
- sortedCandidates.forEach((candidate) => {
- const tooCloseToAccepted = acceptedCenters.some(
- (center) => Math.abs(center - candidate.centerTimeMs) < SUGGESTION_SPACING_MS,
- );
-
- if (tooCloseToAccepted) {
- return;
- }
-
- const centeredStart = Math.round(candidate.centerTimeMs - defaultDuration / 2);
- const candidateStart = Math.max(0, Math.min(centeredStart, totalMs - defaultDuration));
- const candidateEnd = candidateStart + defaultDuration;
- const hasOverlap = reservedSpans.some(
- (span) => candidateEnd > span.start && candidateStart < span.end,
- );
-
- if (hasOverlap) {
- return;
- }
-
- reservedSpans.push({ start: candidateStart, end: candidateEnd });
- acceptedCenters.push(candidate.centerTimeMs);
- onZoomSuggested({ start: candidateStart, end: candidateEnd }, candidate.focus);
- addedCount += 1;
- });
-
- if (addedCount === 0) {
- toast.info(t("errors.noAutoZoomSlots"), {
- description: t("errors.noAutoZoomSlotsDescription"),
- });
- return;
- }
-
- toast.success(
- addedCount === 1
- ? t("success.addedZoomSuggestions", { count: String(addedCount) })
- : t("success.addedZoomSuggestionsPlural", { count: String(addedCount) }),
- );
- }, [
- videoDuration,
- totalMs,
- defaultRegionDurationMs,
- zoomRegions,
- onZoomSuggested,
- cursorTelemetry,
- t,
- ]);
-
const handleAddTrim = useCallback(() => {
if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onTrimAdded) {
return;
@@ -1614,14 +1515,31 @@ export default function TimelineEditor({
<ZoomIn className="w-4 h-4" />
</Button>
<Button
- onClick={handleSuggestZooms}
+ onClick={() => onToggleAutoZoom?.(!autoZoomEnabled)}
variant="ghost"
size="icon"
- className="h-7 w-7 rounded-lg text-slate-400 hover:text-[#34B27B] hover:bg-[#34B27B]/10 transition-all"
- title={t("buttons.suggestZooms")}
+ aria-pressed={autoZoomEnabled}
+ className={cn(
+ "h-7 w-7 rounded-lg transition-all hover:bg-[#34B27B]/10 hover:text-[#34B27B]",
+ autoZoomEnabled ? "bg-[#34B27B]/15 text-[#34B27B]" : "text-slate-400",
+ )}
+ title={autoZoomEnabled ? t("buttons.autoZoomOn") : t("buttons.autoZoomOff")}
>
<WandSparkles className="w-4 h-4" />
</Button>
+ <Button
+ onClick={() => onToggleAutoFocusAll?.(!autoFocusAll)}
+ variant="ghost"
+ size="icon"
+ aria-pressed={autoFocusAll}
+ className={cn(
+ "h-7 w-7 rounded-lg transition-all hover:bg-[#34B27B]/10 hover:text-[#34B27B]",
+ autoFocusAll ? "bg-[#34B27B]/15 text-[#34B27B]" : "text-slate-400",
+ )}
+ title={autoFocusAll ? t("buttons.autoFocusAllOn") : t("buttons.autoFocusAllOff")}
+ >
+ <ScanEye className="w-4 h-4" />
+ </Button>
<Button
onClick={handleAddTrim}
variant="ghost"
diff --git a/src/components/video-editor/timeline/zoomSuggestionUtils.ts b/src/components/video-editor/timeline/zoomSuggestionUtils.ts
index 9f807d32c..6068557b3 100644
--- a/src/components/video-editor/timeline/zoomSuggestionUtils.ts
+++ b/src/components/video-editor/timeline/zoomSuggestionUtils.ts
@@ -3,6 +3,8 @@ import type { CursorTelemetryPoint, ZoomFocus } from "../types";
export const MIN_DWELL_DURATION_MS = 450;
export const MAX_DWELL_DURATION_MS = 2600;
export const DWELL_MOVE_THRESHOLD = 0.02;
+/** Minimum spacing between two accepted suggestion centres. */
+export const SUGGESTION_SPACING_MS = 1800;
export interface ZoomDwellCandidate {
centerTimeMs: number;
@@ -79,3 +81,77 @@ export function detectZoomDwellCandidates(samples: CursorTelemetryPoint[]): Zoom
return dwellCandidates;
}
+
+export interface AutoZoomSuggestion {
+ span: { start: number; end: number };
+ focus: ZoomFocus;
+}
+
+/**
+ * Builds non-overlapping zoom suggestions from cursor telemetry: detects dwell
+ * moments, ranks them by dwell duration, spaces them out by SUGGESTION_SPACING_MS,
+ * and drops any that overlap an existing region. Pure — shared by the magic-wand
+ * toggle and the on-load auto-suggest pass.
+ */
+export function buildAutoZoomSuggestions(options: {
+ cursorTelemetry: CursorTelemetryPoint[];
+ totalMs: number;
+ existingRegions: { startMs: number; endMs: number }[];
+ defaultDurationMs: number;
+}): AutoZoomSuggestion[] {
+ const { cursorTelemetry, totalMs, existingRegions, defaultDurationMs } = options;
+ if (totalMs <= 0 || cursorTelemetry.length < 2) {
+ return [];
+ }
+
+ const defaultDuration = Math.min(defaultDurationMs, totalMs);
+ if (defaultDuration <= 0) {
+ return [];
+ }
+
+ const normalizedSamples = normalizeCursorTelemetry(cursorTelemetry, totalMs);
+ if (normalizedSamples.length < 2) {
+ return [];
+ }
+
+ const dwellCandidates = detectZoomDwellCandidates(normalizedSamples);
+ if (dwellCandidates.length === 0) {
+ return [];
+ }
+
+ const reservedSpans = existingRegions
+ .map((region) => ({ start: region.startMs, end: region.endMs }))
+ .sort((a, b) => a.start - b.start);
+
+ const sortedCandidates = [...dwellCandidates].sort((a, b) => b.strength - a.strength);
+ const acceptedCenters: number[] = [];
+ const suggestions: AutoZoomSuggestion[] = [];
+
+ for (const candidate of sortedCandidates) {
+ const tooCloseToAccepted = acceptedCenters.some(
+ (center) => Math.abs(center - candidate.centerTimeMs) < SUGGESTION_SPACING_MS,
+ );
+ if (tooCloseToAccepted) {
+ continue;
+ }
+
+ const centeredStart = Math.round(candidate.centerTimeMs - defaultDuration / 2);
+ const candidateStart = Math.max(0, Math.min(centeredStart, totalMs - defaultDuration));
+ const candidateEnd = candidateStart + defaultDuration;
+ const hasOverlap = reservedSpans.some(
+ (span) => candidateEnd > span.start && candidateStart < span.end,
+ );
+ if (hasOverlap) {
+ continue;
+ }
+
+ reservedSpans.push({ start: candidateStart, end: candidateEnd });
+ acceptedCenters.push(candidate.centerTimeMs);
+ suggestions.push({
+ span: { start: candidateStart, end: candidateEnd },
+ focus: candidate.focus,
+ });
+ }
+
+ return suggestions;
+}
diff --git a/src/components/video-editor/types.ts b/src/components/video-editor/types.ts
index de1b80d24..364ff1937 100644
--- a/src/components/video-editor/types.ts
+++ b/src/components/video-editor/types.ts
@@ -59,6 +59,13 @@ export function rotation3DPerspective(width: number, height: number): number {
return Math.min(width, height) * ROTATION_3D_PERSPECTIVE_FACTOR;
}
+/**
+ * Origin of a zoom region. "auto" marks zooms added by the magic-wand auto-suggest
+ * pass; toggling the wand off removes only these. Editing an auto zoom promotes it
+ * to "manual" so it survives. Undefined is treated as "manual" for back-compat.
+ */
+export type ZoomRegionSource = "auto" | "manual";
+
export interface ZoomRegion {
id: string;
startMs: number;
@@ -69,6 +76,7 @@ export interface ZoomRegion {
rotationPreset?: Rotation3DPreset;
/** Custom scale overriding the preset depth (1.0–5.0, two decimal precision). */
customScale?: number;
+ source?: ZoomRegionSource;
}
export function getRotation3D(region: Pick<ZoomRegion, "rotationPreset">): Rotation3D {
diff --git a/src/hooks/useEditorHistory.ts b/src/hooks/useEditorHistory.ts
index ca9fa3eb5..1435cc2ae 100644
--- a/src/hooks/useEditorHistory.ts
+++ b/src/hooks/useEditorHistory.ts
@@ -22,6 +22,11 @@ import type { AspectRatio } from "@/utils/aspectRatioUtils";
// selection change would feel surprising to the user).
export interface EditorState {
zoomRegions: ZoomRegion[];
+ /** Magic-wand auto-zoom toggle. When on, fresh recordings get suggested zooms. */
+ autoZoomEnabled: boolean;
+ /** Global Auto-Focus toggle: when on, all zooms follow the cursor and the
+ * per-zoom Focus Mode selector is locked. */
+ autoFocusAll: boolean;
trimRegions: TrimRegion[];
speedRegions: SpeedRegion[];
annotationRegions: AnnotationRegion[];
@@ -43,6 +48,8 @@ export interface EditorState {
export const INITIAL_EDITOR_STATE: EditorState = {
zoomRegions: [],
+ autoZoomEnabled: true,
+ autoFocusAll: false,
trimRegions: [],
speedRegions: [],
annotationRegions: [],
diff --git a/src/i18n/locales/en/settings.json b/src/i18n/locales/en/settings.json
index 020814386..d4d6665a0 100644
--- a/src/i18n/locales/en/settings.json
+++ b/src/i18n/locales/en/settings.json
@@ -9,7 +9,8 @@
"title": "Focus Mode",
"manual": "Manual",
"auto": "Auto",
- "autoDescription": "Camera follows the recorded cursor position"
+ "autoDescription": "Camera follows the recorded cursor position",
+ "lockedDisclaimer": "Controlled by the global Auto-Focus toggle in the timeline. Turn it off to set focus mode per zoom."
},
"threeD": {
"title": "3D Rotation",
diff --git a/src/i18n/locales/en/timeline.json b/src/i18n/locales/en/timeline.json
index 389184b2b..4fc250828 100644
--- a/src/i18n/locales/en/timeline.json
+++ b/src/i18n/locales/en/timeline.json
@@ -2,6 +2,10 @@
"buttons": {
"addZoom": "Add Zoom (Z)",
"suggestZooms": "Suggest Zooms from Cursor",
+ "autoZoomOn": "Auto zoom suggestions on — click to remove suggested zooms",
+ "autoZoomOff": "Auto zoom suggestions off — click to suggest zooms from cursor",
+ "autoFocusAllOn": "Auto-Focus on for all zooms — click to switch all to manual",
+ "autoFocusAllOff": "Auto-Focus all zooms (camera follows the cursor)",
"addTrim": "Add Trim (T)",
"addAnnotation": "Add Annotation (A)",
"addBlur": "Add Blur (B)",