Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions src/components/video-editor/VideoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import { buildAutoZoomSuggestions } from "./timeline/zoomSuggestionUtils";
import {
type AnnotationRegion,
type BlurData,
type CameraFullscreenRegion,
clampFocusToDepth,
DEFAULT_ANNOTATION_POSITION,
DEFAULT_ANNOTATION_SIZE,
Expand Down Expand Up @@ -189,6 +190,7 @@ export default function VideoEditor() {

const {
zoomRegions,
cameraFullscreenRegions,
autoZoomEnabled,
autoFocusAll,
trimRegions,
Expand Down Expand Up @@ -227,6 +229,7 @@ export default function VideoEditor() {
const durationRef = useRef(duration);
durationRef.current = duration;
const [selectedZoomId, setSelectedZoomId] = useState<string | null>(null);
const [selectedCameraFullscreenId, setSelectedCameraFullscreenId] = useState<string | null>(null);
const [isPreviewingZoom, setIsPreviewingZoom] = useState(false);
const [selectedTrimId, setSelectedTrimId] = useState<string | null>(null);
const [selectedSpeedId, setSelectedSpeedId] = useState<string | null>(null);
Expand Down Expand Up @@ -297,6 +300,7 @@ export default function VideoEditor() {
const videoPlaybackRef = useRef<VideoPlaybackRef>(null);

const nextZoomIdRef = useRef(1);
const nextCameraFullscreenIdRef = useRef(1);
const nextTrimIdRef = useRef(1);
const nextSpeedIdRef = useRef(1);

Expand Down Expand Up @@ -372,6 +376,7 @@ export default function VideoEditor() {
const inferredDurationMs = Math.max(
0,
...normalizedEditor.zoomRegions.map((region) => region.endMs),
...normalizedEditor.cameraFullscreenRegions.map((region) => region.endMs),
...normalizedEditor.trimRegions.map((region) => region.endMs),
...normalizedEditor.speedRegions.map((region) => region.endMs),
...normalizedEditor.annotationRegions.map((region) => region.endMs),
Expand Down Expand Up @@ -408,6 +413,7 @@ export default function VideoEditor() {
padding: normalizedEditor.padding,
cropRegion: normalizedEditor.cropRegion,
zoomRegions: normalizedEditor.zoomRegions,
cameraFullscreenRegions: normalizedEditor.cameraFullscreenRegions,
autoZoomEnabled: normalizedEditor.autoZoomEnabled,
autoFocusAll: normalizedEditor.autoFocusAll,
trimRegions: normalizedEditor.trimRegions,
Expand All @@ -429,6 +435,7 @@ export default function VideoEditor() {
setCursorTheme(normalizedEditor.cursorTheme);

setSelectedZoomId(null);
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
Expand All @@ -438,6 +445,10 @@ export default function VideoEditor() {
"zoom",
normalizedEditor.zoomRegions.map((region) => region.id),
);
nextCameraFullscreenIdRef.current = deriveNextId(
"camera-fullscreen",
normalizedEditor.cameraFullscreenRegions.map((region) => region.id),
);
nextTrimIdRef.current = deriveNextId(
"trim",
normalizedEditor.trimRegions.map((region) => region.id),
Expand Down Expand Up @@ -485,6 +496,7 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
cameraFullscreenRegions,
autoZoomEnabled,
autoFocusAll,
trimRegions,
Expand Down Expand Up @@ -516,6 +528,7 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
cameraFullscreenRegions,
autoZoomEnabled,
autoFocusAll,
trimRegions,
Expand Down Expand Up @@ -644,6 +657,7 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
cameraFullscreenRegions,
autoZoomEnabled,
autoFocusAll,
trimRegions,
Expand Down Expand Up @@ -709,6 +723,7 @@ export default function VideoEditor() {
padding,
cropRegion,
zoomRegions,
cameraFullscreenRegions,
autoZoomEnabled,
autoFocusAll,
trimRegions,
Expand Down Expand Up @@ -846,6 +861,7 @@ export default function VideoEditor() {
resetState();
// Reset non-undoable selection state.
setSelectedZoomId(null);
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
Expand All @@ -863,6 +879,7 @@ export default function VideoEditor() {
setCursorTheme(DEFAULT_CURSOR_SETTINGS.theme);
// Reset region ID counters.
nextZoomIdRef.current = 1;
nextCameraFullscreenIdRef.current = 1;
nextTrimIdRef.current = 1;
nextSpeedIdRef.current = 1;
nextAnnotationIdRef.current = 1;
Expand Down Expand Up @@ -973,6 +990,18 @@ export default function VideoEditor() {
const handleSelectZoom = useCallback((id: string | null) => {
setSelectedZoomId(id);
if (id) {
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
setSelectedBlurId(null);
}
}, []);

const handleSelectCameraFullscreen = useCallback((id: string | null) => {
setSelectedCameraFullscreenId(id);
if (id) {
setSelectedZoomId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
Expand All @@ -984,6 +1013,7 @@ export default function VideoEditor() {
setSelectedTrimId(id);
if (id) {
setSelectedZoomId(null);
setSelectedCameraFullscreenId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
setSelectedBlurId(null);
Expand All @@ -994,6 +1024,7 @@ export default function VideoEditor() {
setSelectedAnnotationId(id);
if (id) {
setSelectedZoomId(null);
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedBlurId(null);
Expand All @@ -1004,6 +1035,7 @@ export default function VideoEditor() {
setSelectedBlurId(id);
if (id) {
setSelectedZoomId(null);
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedAnnotationId(null);
setSelectedSpeedId(null);
Expand All @@ -1026,6 +1058,7 @@ export default function VideoEditor() {
};
pushState((prev) => ({ zoomRegions: [...prev.zoomRegions, newRegion] }));
setSelectedZoomId(id);
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
Expand All @@ -1034,6 +1067,56 @@ export default function VideoEditor() {
[pushState, autoFocusAll],
);

const handleCameraFullscreenAdded = useCallback(
(span: Span) => {
const id = `camera-fullscreen-${nextCameraFullscreenIdRef.current++}`;
const newRegion: CameraFullscreenRegion = {
id,
startMs: Math.round(span.start),
endMs: Math.round(span.end),
};
pushState((prev) => ({
cameraFullscreenRegions: [...prev.cameraFullscreenRegions, newRegion],
}));
setSelectedCameraFullscreenId(id);
setSelectedZoomId(null);
setSelectedTrimId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
setSelectedBlurId(null);
},
[pushState],
);

const handleCameraFullscreenSpanChange = useCallback(
(id: string, span: Span) => {
pushState((prev) => ({
cameraFullscreenRegions: prev.cameraFullscreenRegions.map((region) =>
region.id === id
? {
...region,
startMs: Math.round(span.start),
endMs: Math.round(span.end),
}
: region,
),
}));
},
[pushState],
);

const handleCameraFullscreenDelete = useCallback(
(id: string) => {
pushState((prev) => ({
cameraFullscreenRegions: prev.cameraFullscreenRegions.filter((r) => r.id !== id),
}));
if (selectedCameraFullscreenId === id) {
setSelectedCameraFullscreenId(null);
}
},
[selectedCameraFullscreenId, pushState],
);

// Builds fresh "auto" zoom regions from cursor telemetry without overlapping
// existing ones. Used by both the on-load auto-suggest pass and the wand toggle.
const buildAutoZoomRegions = useCallback(
Expand Down Expand Up @@ -1284,6 +1367,7 @@ export default function VideoEditor() {
setSelectedSpeedId(id);
if (id) {
setSelectedZoomId(null);
setSelectedCameraFullscreenId(null);
setSelectedTrimId(null);
setSelectedAnnotationId(null);
setSelectedBlurId(null);
Expand Down Expand Up @@ -1722,6 +1806,15 @@ export default function VideoEditor() {
}
}, [selectedZoomId, zoomRegions]);

useEffect(() => {
if (
selectedCameraFullscreenId &&
!cameraFullscreenRegions.some((region) => region.id === selectedCameraFullscreenId)
) {
setSelectedCameraFullscreenId(null);
}
}, [selectedCameraFullscreenId, cameraFullscreenRegions]);

useEffect(() => {
if (selectedTrimId && !trimRegions.some((region) => region.id === selectedTrimId)) {
setSelectedTrimId(null);
Expand Down Expand Up @@ -1891,6 +1984,7 @@ export default function VideoEditor() {
sizePreset: settings.gifConfig.sizePreset,
wallpaper,
zoomRegions,
cameraFullscreenRegions,
trimRegions,
speedRegions,
showShadow: shadowIntensity > 0,
Expand Down Expand Up @@ -1986,6 +2080,7 @@ export default function VideoEditor() {
codec: "avc1.640033",
wallpaper,
zoomRegions,
cameraFullscreenRegions,
trimRegions,
speedRegions,
showShadow: shadowIntensity > 0,
Expand Down Expand Up @@ -2094,6 +2189,7 @@ export default function VideoEditor() {
webcamVideoPath,
wallpaper,
zoomRegions,
cameraFullscreenRegions,
trimRegions,
speedRegions,
shadowIntensity,
Expand Down Expand Up @@ -2607,6 +2703,7 @@ export default function VideoEditor() {
onError={setError}
wallpaper={wallpaper}
zoomRegions={zoomRegions}
cameraFullscreenRegions={cameraFullscreenRegions}
selectedZoomId={selectedZoomId}
onSelectZoom={handleSelectZoom}
onZoomFocusChange={handleZoomFocusChange}
Expand Down Expand Up @@ -2863,6 +2960,12 @@ export default function VideoEditor() {
onZoomDelete={handleZoomDelete}
selectedZoomId={selectedZoomId}
onSelectZoom={handleSelectZoom}
cameraFullscreenRegions={cameraFullscreenRegions}
onCameraFullscreenAdded={handleCameraFullscreenAdded}
onCameraFullscreenSpanChange={handleCameraFullscreenSpanChange}
onCameraFullscreenDelete={handleCameraFullscreenDelete}
selectedCameraFullscreenId={selectedCameraFullscreenId}
onSelectCameraFullscreen={handleSelectCameraFullscreen}
trimRegions={trimRegions}
onTrimAdded={handleTrimAdded}
onTrimSpanChange={handleTrimSpanChange}
Expand Down
Loading
Loading