Create professional demos and 3D mockups in seconds, directly in your browser
feat: enhance camera overlay persistence and configuration management
CristianOlivera1f314a27d2edc
diff --git a/.gitignore b/.gitignoreindex 08deee2..0307f68 100644--- a/.gitignore+++ b/.gitignore@@ -47,4 +47,5 @@ BACKEND_SPEC.mdBACKEND_TESTING.md/openvid-back/openvid-autozoom-plan-integracion-openvid-autozoom.md\ No newline at end of file+plan-integracion-openvid-autozoom.md+VIDEO_PROJECT_PERSISTENCE_PLAN.md\ No newline at end of filediff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsxindex 3ae0a57..6f8ef67 100644--- a/app/[locale]/(editor)/editor/page.tsx+++ b/app/[locale]/(editor)/editor/page.tsx@@ -25,6 +25,7 @@ import type { EditorState } from "@/types/editor-state.types";import { createInitialEditorState } from "@/types/editor-state.types";import { DEFAULT_MOCKUP_CONFIG, getMockupDefaultConfig } from "@/types/mockup.types";import type { CameraConfig } from "@/types/camera.types";+import { DEFAULT_CAMERA_CONFIG } from "@/types/camera.types";import type { Preview3DConfig, ImageMaskConfig } from "@/types/photo.types";import { DEFAULT_MASK_CONFIG, PREVIEW_CONFIGS } from "@/types/photo.types";import { MOCKUPS } from "@/lib/mockup-data";@@ -1182,6 +1183,15 @@ export default function Editor() {probe.src = probeUrl;});+ // Restore the persisted camera overlay (if any) for this library video.+ // The camera blob is keyed by the clip's `libraryVideoId`, so a video+ // recorded with a camera can recover its overlay when re-added from+ // the library/history — not only on page reload via the saved project.+ const persistedCamera = await getCameraBlob(videoId).catch((err) => {+ console.error("Failed to restore camera blob from library:", err);+ return null;+ });+setVideoClips(prevClips => {const startTime = findNextClipPosition(prevClips);const newClip: VideoTrackClip = {@@ -1193,6 +1203,7 @@ export default function Editor() {trimStart: 0,trimEnd: duration,thumbnailUrl: libraryVideo.thumbnailUrl,+ hasCamera: !!persistedCamera,width: clipWidth || undefined,height: clipHeight || undefined,};@@ -1228,6 +1239,22 @@ export default function Editor() {setIsPlaying(false);}+ // Restore the camera overlay from the persisted blob. The+ // camera URL/config are project-level singletons, so we only+ // set them when no other clip already owns the camera —+ // otherwise the new clip's camera would clobber another+ // clip's. The `hasCamera` flag on the clip itself is what+ // gates visibility per-clip via `shouldShowCamera` at render+ // time.+ if (persistedCamera && !prevClips.some(c => c.hasCamera)) {+ const restoredCameraUrl = URL.createObjectURL(persistedCamera.blob);+ setCameraUrl(restoredCameraUrl);+ setCameraConfig(+ persistedCamera.cameraConfig+ ?? { ...DEFAULT_CAMERA_CONFIG, enabled: true }+ );+ }+showNewVideosBadge(0);clearHistory();}, 0);@@ -1753,7 +1780,12 @@ export default function Editor() {?? activeClipDataRef.current?.libraryVideoId?? null;if (owningClipId && 'cameraBlob' in videoToLoad && videoToLoad.cameraBlob) {- saveCameraBlob(owningClipId, videoToLoad.cameraBlob as Blob, "video/webm")+ saveCameraBlob(+ owningClipId,+ videoToLoad.cameraBlob as Blob,+ "video/webm",+ 'cameraConfig' in videoToLoad ? videoToLoad.cameraConfig : null,+ ).catch(err => console.error("Failed to persist camera blob:", err));}} else {diff --git a/lib/video-project-cache.ts b/lib/video-project-cache.tsindex 6ab4ad2..4a92dff 100644--- a/lib/video-project-cache.ts+++ b/lib/video-project-cache.ts@@ -92,6 +92,7 @@ export interface CachedCameraBlob {blob: Blob;mimeType: string;savedAt: number;+ cameraConfig?: CameraConfig | null;}let dbInstance: IDBDatabase | null = null;@@ -380,8 +381,17 @@ export async function clearAllAudioBlobs(): Promise<void> {/*** Persist (or replace) the camera-overlay blob for a given clip.+ *+ * `cameraConfig` is optional; when provided it is stored alongside the blob so+ * the camera settings (shape, size, position, etc.) can be restored when the+ * clip is re-added from the videos library, not only on a full project reload.*/-export async function saveCameraBlob(id: string, blob: Blob, mimeType: string): Promise<CachedCameraBlob> {+export async function saveCameraBlob(+ id: string,+ blob: Blob,+ mimeType: string,+ cameraConfig?: CameraConfig | null,+): Promise<CachedCameraBlob> {try {const db = await openDB();const data: CachedCameraBlob = {@@ -389,6 +399,7 @@ export async function saveCameraBlob(id: string, blob: Blob, mimeType: string):blob,mimeType,savedAt: Date.now(),+ cameraConfig: cameraConfig ?? null,};return new Promise((resolve, reject) => {diff --git a/types/editor.types.ts b/types/editor.types.tsindex 218c6ac..7b4ece6 100644--- a/types/editor.types.ts+++ b/types/editor.types.ts@@ -5,6 +5,7 @@ import type { ImageMaskConfig } from "@/types/photo.types";import type { MockupConfig } from "./mockup.types";import type { CameraConfig } from "./camera.types";import { MockupMotionFragment } from "@/lib/mockup-motion";+import type { VideoTrackClip } from "./video-track.types";export type Tool = "screenshot" | "elements" | "audio" | "zoom" | "mockup" | "cursor" | "video" | "camera" | "history" | "motion";export type BackgroundTab = "wallpaper" | "image" | "color";@@ -124,4 +125,6 @@ export interface VideoCanvasProps {onSelectZoomMovement?: (id: string | null) => void;onUpdateZoomMovement?: (id: string, updates: Partial<ZoomMovement>) => void;onSelectZoomFragment?: (id: string | null) => void;+ videoClips?: VideoTrackClip[];+ cameraClipUrls?: Map<string, string> | null;}