Create professional demos and 3D mockups in seconds, directly in your browser
feat: mockup 3d for videos
CristianOlivera19d054fa2b289
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsxindex 1450040..90f7c0d 100644--- a/app/[locale]/(editor)/editor/page.tsx+++ b/app/[locale]/(editor)/editor/page.tsx@@ -88,6 +88,18 @@ export default function Editor() {clearHistory,} = useUndoRedo<EditorState>(createInitialEditorState());+ const handleUndo = useCallback(() => {+ undo();+ setUndoRedoVersion(v => v + 1);+ }, [undo]);++ const handleRedo = useCallback(() => {+ redo();+ setUndoRedoVersion(v => v + 1);+ }, [redo]);++ const [undoRedoVersion, setUndoRedoVersion] = useState(-1);+// Image state for photo modeconst [imageUrl, setImageUrl] = useState<string | null>(null);const imageRef = useRef<HTMLImageElement>(null);@@ -1086,8 +1098,17 @@ export default function Editor() {setEditorState]);- // Sync editorState → individual states (from undo/redo)+ // Sync editorState → individual states (only on actual undo/redo, not every state change)+ // This effect restores all UI state when the user presses Ctrl+Z / Ctrl+Y.+ // Without the version guard, it would also fire on every debounced state save,+ // overwriting interactive values (like 3D rotation from OrbitControls drag)+ // with stale snapshot data.+ const prevUndoRedoVersionRef = useRef(undoRedoVersion);useEffect(() => {+ // Only run when undoRedoVersion actually changed (undo/redo happened)+ if (prevUndoRedoVersionRef.current === undoRedoVersion) return;+ prevUndoRedoVersionRef.current = undoRedoVersion;+setBackgroundTab(editorState.backgroundTab);setSelectedWallpaper(editorState.selectedWallpaper);setBackgroundBlur(editorState.backgroundBlur);@@ -1126,7 +1147,7 @@ export default function Editor() {setImagePhoneOpening(editorState.imagePhoneOpening);setImagePhoneShadow(editorState.imagePhoneShadow);setImagePhoneShadowColor(editorState.imagePhoneShadowColor);- }, [editorState]);+ }, [undoRedoVersion]);// Handler para cambiar el mockupconst handleMockupChange = useCallback((newMockupId: string) => {@@ -2163,7 +2184,7 @@ export default function Editor() {if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {e.preventDefault();if (canUndo) {- undo();+ handleUndo();}}@@ -2171,14 +2192,14 @@ export default function Editor() {((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'z')) {e.preventDefault();if (canRedo) {- redo();+ handleRedo();}}};window.addEventListener('keydown', handleKeyDown);return () => window.removeEventListener('keydown', handleKeyDown);- }, [undo, redo, canUndo, canRedo]);+ }, [handleUndo, handleRedo, canUndo, canRedo]);// Keyboard listener for Ctrl+V image paste (photo mode only)useEffect(() => {@@ -2588,6 +2609,12 @@ export default function Editor() {setTrimRange(prev => prev.end === 0 ? { start: 0, end: duration } : prev);}}++ const vw = videoRef.current.videoWidth;+ const vh = videoRef.current.videoHeight;+ if (vw > 0 && vh > 0) {+ setVideoDimensions({ width: vw, height: vh });+ }}}, []);@@ -3012,7 +3039,7 @@ export default function Editor() {videoThumbnail={selectedZoomFragment ? getThumbnailForTime(selectedZoomFragment.startTime)?.dataUrl ?? null : null}currentTime={currentTime}getThumbnailForTime={getThumbnailForTime}- videoDimensions={customAspectRatio}+ videoDimensions={videoDimensions}mockupId={mockupId}mockupConfig={mockupConfig}onMockupChange={handleMockupChange}@@ -3097,8 +3124,8 @@ export default function Editor() {onExport={handleExport}exportProgress={exportProgress}hasTransparentBackground={selectedWallpaper === -1}- onUndo={undo}- onRedo={redo}+ onUndo={handleUndo}+ onRedo={handleRedo}canUndo={canUndo}canRedo={canRedo}editorMode={editorMode}diff --git a/app/components/ui/ExportDropdown.tsx b/app/components/ui/ExportDropdown.tsxindex 7306a99..47401f1 100644--- a/app/components/ui/ExportDropdown.tsx+++ b/app/components/ui/ExportDropdown.tsx@@ -94,7 +94,7 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro<Icon icon="mdi:chevron-down" width="16" className="opacity-50" aria-hidden="true" /></Button></PopoverTrigger>- <PopoverContent align="end" className="w-72 bg-[#1C1C1F] border-white/10 text-white shadow-2xl p-0 overflow-hidden">+ <PopoverContent align="end" className="w-72 bg-[#1C1C1F] border-white/10 text-white shadow-2xl p-0 overflow-hidden z-999999"><div className="flex flex-col bg-black border border-white/10 rounded-xl overflow-hidden shadow-2xl"><div className="px-4 py-3 border-b border-white/10 bg-white/5"><span className="text-[10px] font-medium uppercase tracking-[0.15em] text-white/50">diff --git a/app/components/ui/ExportOverlay.tsx b/app/components/ui/ExportOverlay.tsxindex d9783f9..ecef8f9 100644--- a/app/components/ui/ExportOverlay.tsx+++ b/app/components/ui/ExportOverlay.tsx@@ -43,7 +43,7 @@ export function ExportOverlay({ exportProgress, onCancel, isTransparentExport }:};return (- <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/20 backdrop-blur-md transition-all duration-500">+ <div className="fixed inset-0 z-999999 flex items-center justify-center bg-black/20 backdrop-blur-md transition-all duration-500"><div className="p-10 bg-black border border-white/10 rounded-2xl shadow-[0_0_80px_-15px_rgba(0,0,0,1)] w-full max-w-lg mx-4"><div className="flex justify-center mb-8">diff --git a/app/components/ui/editor/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/IPhone13ProMax3DViewer.tsxindex 5d0d741..6cece6f 100644--- a/app/components/ui/editor/IPhone13ProMax3DViewer.tsx+++ b/app/components/ui/editor/IPhone13ProMax3DViewer.tsx@@ -1,6 +1,6 @@"use client";-import { Canvas, useThree } from "@react-three/fiber";+import { Canvas, useThree, useFrame } from "@react-three/fiber";import { PerspectiveCamera, useGLTF, Environment, OrbitControls } from "@react-three/drei";import { useEffect, useRef, useState, Suspense } from "react";import * as THREE from "three";@@ -33,6 +33,7 @@ interface Props {zoom?: number;shadowIntensity?: number;shadowColor?: string;+ videoElement?: HTMLVideoElement | null;}const TEX_W = 1284 * 2;@@ -108,6 +109,7 @@ function ModelScene({zoom,onApi,onLoaded,+ videoElement,}: {imageUrl: string | null;imageMaskConfig: ImageMaskConfigLike | null;@@ -121,6 +123,7 @@ function ModelScene({zoom: number;onApi?: (api: IPhone13ProMax3DApi | null) => void;onLoaded?: () => void;+ videoElement?: HTMLVideoElement | null;}) {const { gl } = useThree();const gltf = useGLTF("/models/apple_iphone_13_pro_max.glb") as unknown as {@@ -134,9 +137,16 @@ function ModelScene({const lastLoadedMaskKeyRef = useRef<string | null>(null);const lastLoadedCropKeyRef = useRef<string | null>(null);const wallpaperMatRef = useRef<THREE.MeshStandardMaterial | null>(null);+ const videoTextureRef = useRef<THREE.VideoTexture | null>(null);const { autoRotate, rotationSpeed, glow, environment } = ViewerControls3D();+ useFrame(() => {+ if (videoElement && videoTextureRef.current) {+ videoTextureRef.current.needsUpdate = true;+ }+ });+useEffect(() => {const api: IPhone13ProMax3DApi = {renderAt: (w, h) => {@@ -158,10 +168,53 @@ function ModelScene({}}, [materials.Wallpaper]);+ useEffect(() => {+ if (!videoElement) {+ if (videoTextureRef.current) {+ videoTextureRef.current.dispose();+ videoTextureRef.current = null;+ }+ return;+ }+ const tex = new THREE.VideoTexture(videoElement);+ tex.flipY = true;+ tex.colorSpace = THREE.SRGBColorSpace;+ tex.generateMipmaps = true;+ tex.minFilter = THREE.LinearMipmapLinearFilter;+ tex.magFilter = THREE.LinearFilter;+ tex.wrapS = THREE.ClampToEdgeWrapping;+ tex.wrapT = THREE.ClampToEdgeWrapping;+ if (videoTextureRef.current) {+ videoTextureRef.current.dispose();+ }+ videoTextureRef.current = tex;++ const applyVideoTex = () => {+ const mat = wallpaperMatRef.current;+ if (!mat) return;+ if (mat.map && mat.map !== tex) {+ mat.map.dispose();+ }+ mat.map = tex;+ mat.color.set(0xffffff);+ mat.needsUpdate = true;+ };+ applyVideoTex();++ return () => {+ if (videoTextureRef.current === tex) {+ videoTextureRef.current = null;+ }+ tex.dispose();+ };+ }, [videoElement]);+useEffect(() => {const mat = wallpaperMatRef.current;if (!mat) return;+ if (videoElement) return;+const maskKey = imageMaskConfig ? JSON.stringify(imageMaskConfig) : null;const cropKey = cropArea ? JSON.stringify(cropArea) : null;@@ -212,7 +265,7 @@ function ModelScene({lastLoadedCropKeyRef.current = cropKey;};img.src = imageUrl;- }, [imageUrl, imageMaskConfig, cropArea, gl]);+ }, [imageUrl, imageMaskConfig, cropArea, gl, videoElement]);useEffect(() => {const id = setTimeout(() => {@@ -316,6 +369,7 @@ function CanvasWithLoader({zoom,onApi,onMount,+ videoElement,}: {imageUrl: string | null;imageMaskConfig: ImageMaskConfigLike | null;@@ -329,6 +383,7 @@ function CanvasWithLoader({zoom: number;onApi?: (api: IPhone13ProMax3DApi | null) => void;onMount?: (canvas: HTMLCanvasElement) => void;+ videoElement?: HTMLVideoElement | null;}) {const [loaded, setLoaded] = useState(false);return (@@ -365,6 +420,7 @@ function CanvasWithLoader({zoom={zoom}onApi={onApi}onLoaded={() => setLoaded(true)}+ videoElement={videoElement}/></Suspense></Canvas>@@ -394,6 +450,7 @@ export function IPhone13ProMax3DViewer({zoom = 1,shadowIntensity = 0,shadowColor = "#000000",+ videoElement = null,}: Props) {const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);@@ -474,6 +531,7 @@ export function IPhone13ProMax3DViewer({zoom={zoom}onApi={onApi}onMount={onMount}+ videoElement={videoElement}/></div></div>diff --git a/app/components/ui/editor/Laptop3DViewer.tsx b/app/components/ui/editor/Laptop3DViewer.tsxindex dc2ecfe..2c03218 100644--- a/app/components/ui/editor/Laptop3DViewer.tsx+++ b/app/components/ui/editor/Laptop3DViewer.tsx@@ -1,6 +1,6 @@"use client";-import { Canvas, useThree } from "@react-three/fiber";+import { Canvas, useThree, useFrame } from "@react-three/fiber";import { PerspectiveCamera, Environment, OrbitControls } from "@react-three/drei";import { useEffect, useRef, useState, Suspense, useCallback } from "react";import * as THREE from "three";@@ -52,6 +52,7 @@ interface Props {zoom?: number;shadowIntensity?: number;shadowColor?: string;+ videoElement?: HTMLVideoElement | null;}let gltfCachePromise: Promise<THREE.Group> | null = null;@@ -83,6 +84,7 @@ function ModelScene({zoom = 1,onApi,onLoaded,+ videoElement,}: Props & {rootRef: React.MutableRefObject<THREE.Group | null>;cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;@@ -94,6 +96,7 @@ function ModelScene({const [modelGroup, setModelGroup] = useState<THREE.Group | null>(null);const lidGroupRef = useRef<THREE.Group | null>(null);const screenMatRef = useRef<THREE.MeshBasicMaterial | null>(null);+ const videoTextureRef = useRef<THREE.VideoTexture | null>(null);const lastLoadedUrlRef = useRef<string | null>(null);const lastLoadedCropKeyRef = useRef<string | null>(null);@@ -101,6 +104,12 @@ function ModelScene({defaultEnvironment: "forest"});+ useFrame(() => {+ if (videoElement && videoTextureRef.current) {+ videoTextureRef.current.needsUpdate = true;+ }+ });+useEffect(() => {const api: Laptop3DApi = {renderAt: (w, h) => {@@ -123,6 +132,7 @@ function ModelScene({}, [onApi, gl, scene, cameraRef]);const applyTexture = useCallback(() => {+ if (videoElement) return;const mat = screenMatRef.current;if (!mat) return;@@ -191,7 +201,46 @@ function ModelScene({};img.src = imageUrl;- }, [imageUrl, imageMaskConfig, cropArea, gl]);+ }, [imageUrl, imageMaskConfig, cropArea, gl, videoElement]);++ useEffect(() => {+ if (!videoElement) {+ if (videoTextureRef.current) {+ videoTextureRef.current.dispose();+ videoTextureRef.current = null;+ }+ return;+ }+ const tex = new THREE.VideoTexture(videoElement);+ tex.flipY = false;+ tex.colorSpace = THREE.SRGBColorSpace;+ tex.generateMipmaps = true;+ tex.minFilter = THREE.LinearMipmapLinearFilter;+ tex.magFilter = THREE.LinearFilter;+ tex.wrapS = THREE.ClampToEdgeWrapping;+ tex.wrapT = THREE.ClampToEdgeWrapping;+ if (videoTextureRef.current) {+ videoTextureRef.current.dispose();+ }+ videoTextureRef.current = tex;++ const mat = screenMatRef.current;+ if (mat) {+ if (mat.map && mat.map !== tex) {+ mat.map.dispose();+ }+ mat.map = tex;+ mat.color.set(0xffffff);+ mat.needsUpdate = true;+ }++ return () => {+ if (videoTextureRef.current === tex) {+ videoTextureRef.current = null;+ }+ tex.dispose();+ };+ }, [videoElement]);const applyTextureRef = useRef(applyTexture);useEffect(() => {diff --git a/app/components/ui/editor/Mockup3dMenu.tsx b/app/components/ui/editor/Mockup3dMenu.tsxindex e6cf4b4..2fc12c4 100644--- a/app/components/ui/editor/Mockup3dMenu.tsx+++ b/app/components/ui/editor/Mockup3dMenu.tsx@@ -89,22 +89,34 @@ function PositionPad({<div className="absolute inset-0 pointer-events-none rounded-[14px] ring-2 ring-cyan-400/30 animate-pulse" />)}<div className="absolute inset-0 pointer-events-none opacity-10 bg-[radial-gradient(#a1a1aa_1px,transparent_1px)] bg-size-[14px_14px]" />- <div className="absolute top-0 bottom-0 w-px bg-gradient-to-b from-transparent via-white/10 to-transparent" style={{ left: "50%" }} />- <div className="absolute left-0 right-0 h-px bg-gradient-to-r from-transparent via-white/10 to-transparent" style={{ top: "50%" }} />- <div className="absolute pointer-events-none bg-white/5 transition-opacity" style={{ left: `calc(${pctX * 100}%)`, top: 0, bottom: 0, width: 1 }} />- <div className="absolute pointer-events-none bg-white/5 transition-opacity" style={{ top: hy, left: 0, right: 0, height: 1 }} />++ <div className="absolute top-0 bottom-0 w-px bg-linear-to-b from-transparent via-white/10 to-transparent -translate-x-1/2" style={{ left: "50%" }} />+ <div className="absolute left-0 right-0 h-px bg-linear-to-r from-transparent via-white/10 to-transparent -translate-y-1/2" style={{ top: "50%" }} />++ <div+ className="absolute pointer-events-none bg-white/10 transition-opacity -translate-x-1/2"+ style={{ left: `${pctX * 100}%`, top: 0, bottom: 0, width: '1px' }}+ />+<div- className={`absolute bg-white border border-white/40 rounded-full shadow-[0_0_20px_4px_rgba(255,255,255,0.12),0_4px_12px_rgba(0,0,0,0.6)] mix-blend-screen flex items-center justify-center transition-all duration-75 pointer-events-auto ${isDraggingState ? "cursor-grabbing scale-125" : "cursor-grab"- }`}+ className="absolute pointer-events-none bg-white/10 transition-opacity -translate-y-1/2"+ style={{ top: hy, left: 0, right: 0, height: '1px' }}+ />++ <div+ className={`absolute bg-white border border-white/40 rounded-full shadow-[0_0_20px_4px_rgba(255,255,255,0.12),0_4px_12px_rgba(0,0,0,0.6)] mix-blend-screen flex items-center justify-center pointer-events-auto transition-transform duration-75`}style={{width: HANDLE_R * 3,height: HANDLE_R * 3,- left: `calc(${pctX * 100}% - ${HANDLE_R}px)`,- top: hy - HANDLE_R,+ left: `${pctX * 100}%`,+ top: hy,+ transform: `translate(-50%, -50%) ${isDraggingState ? "scale(1.25)" : "scale(1)"}`,+ cursor: isDraggingState ? "grabbing" : "grab",}}/></div></div>+);}diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsxindex 903e542..93e547a 100644--- a/app/components/ui/editor/MockupMenu.tsx+++ b/app/components/ui/editor/MockupMenu.tsx@@ -11,76 +11,7 @@ import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";import { getWallpaperUrl } from "@/lib/wallpaper.utils";import { Mockup2dMenu } from "./Mockup2dMenu";import { Mockup3dMenu, type ActiveDeviceTpl } from "./Mockup3dMenu";--function DeviceCard({- tpl,- isActive,- onClick,-}: {- tpl: (typeof IMAGE_DEVICE_TEMPLATES)[number];- isActive: boolean;- onClick: () => void;-}) {- return (- <div className="relative w-40 shrink-0 snap-start mt-0.5">- <button- type="button"- onClick={onClick}- className={`group flex h-full w-full flex-col overflow-hidden rounded-2xl border text-left transition-all duration-300 active:scale-[0.98] ${isActive- ? "border-white/20 bg-[#1a1a1e]"- : "border-white/6 bg-[#17171a] hover:border-white/20"- }`}- >- <div className="relative aspect-3/4 w-full shrink-0 bg-[#0d0d10]">- <div- className="absolute inset-0"- style={{- background: isActive- ? `linear-gradient(135deg, ${tpl.accentColor}22 0%, transparent 70%)`- : `linear-gradient(135deg, ${tpl.accentColor}10 0%, transparent 70%)`,- }}- />- <div className="absolute inset-0 flex items-center justify-center">- <Icon- icon={tpl.icon}- width="22"- style={{- color: isActive ? `${tpl.accentColor}cc` : `${tpl.accentColor}55`,- }}- />- </div>-- {isActive && (- <div- className="absolute top-1.5 right-1.5 size-4 rounded-full flex items-center justify-center"- style={{ background: tpl.accentColor }}- >- <Icon icon="mdi:check-bold" width={9} className="text-white" />- </div>- )}- </div>-- <div className="border-t border-white/5 bg-[#111113] px-3 py-2.5">- <h3- className={`truncate text-xs font-semibold ${isActive ? "text-white" : "text-white/60"- }`}- >- {tpl.title}- </h3>- </div>- </button>-- {isActive && (- <div- className="pointer-events-none absolute inset-0 rounded-2xl"- style={{ boxShadow: `inset 0 0 0 1.5px ${tpl.accentColor}88` }}- />- )}- </div>- );-}--// ─── Props ────────────────────────────────────────────────────────────────────+import { DeviceCard } from "@/components/ui/DeviceCard";export interface MockupMenuProps {mockupId?: string;@@ -93,16 +24,9 @@ export interface MockupMenuProps {backgroundTab?: "wallpaper" | "image" | "color" | "unsplash";selectedWallpaper?: number;selectedImageUrl?: string;- /**- * Initial page when the menu first mounts. When the canvas is clicked- * while a mockup is already applied, the parent passes "detail-2d" or- * "detail-3d" so the user lands directly on the config of the active frame.- */initialPage?: MenuPage;}-// ─── MockupMenu ───────────────────────────────────────────────────────────────-export function MockupMenu({mockupId = "none",mockupConfig,@@ -117,14 +41,8 @@ export function MockupMenu({}: MockupMenuProps) {const t = useTranslations("mockupMenu");- // ── Navigation state ──const [page, setPage] = useState<MenuPage>(initialPage);- // Sync page when the parent (VideoCanvas click) sets initialPage to a- // detail view while the menu is already mounted. Without this, the- // `useState(initialPage)` only reads the prop on first mount, so a click- // on a mockup already applied on the canvas wouldn't navigate the menu- // to the matching detail page.useEffect(() => {if (initialPage !== "home") {setPage(initialPage);@@ -225,6 +143,8 @@ export function MockupMenu({setImagePhoneY,imagePhoneScale,setImagePhoneScale,+ imagePhoneRotX,+ imagePhoneRotY,setImagePhoneRotX,setImagePhoneRotY,imagePhoneDevice,@@ -293,26 +213,31 @@ export function MockupMenu({// ── Handlers: 3D ──const handleDeviceClick = (id: ImageDeviceId) => {- // Always apply the per-device defaults on every click — even if the- // user picks the same device twice, we want to reset to the canonical- // pose. Without this, a device that starts at the context's default- // (imagePhoneRotX=0, imagePhoneRotY=0) would never snap to its pose- // because the "device changed" guard would be false.+ // Only reset the pose when switching to a *different* device.+ // If the user clicks the already-active device card, keep the current+ // position/rotation/scale so they don't lose their edits.+ // (Special case: if the device's rotation is still at the context default+ // of 0/0 — i.e. has never been posed — apply the canonical pose once.)+ const isSameDevice = imagePhoneDevice === id;+ const isUnposed = imagePhoneRotX === 0 && imagePhoneRotY === 0;+setImagePhoneDevice(id);- setImagePhoneX(0);- setImagePhoneY(0);- setImagePhoneScale(0.8);- if (id === "iphone-13-pro-max") {- setImagePhoneRotX(-58.23);- setImagePhoneRotY(-29.82);- } else if (id === "laptop") {- setImagePhoneRotX(43.23);- setImagePhoneRotY(-37.82);- setImagePhoneOpening(1);- setImagePhoneScale(1);- } else {- setImagePhoneRotX(-58.23);- setImagePhoneRotY(-29.82);+ if (!isSameDevice || isUnposed) {+ setImagePhoneX(0);+ setImagePhoneY(0);+ setImagePhoneScale(0.8);+ if (id === "iphone-13-pro-max") {+ setImagePhoneRotX(-58.23);+ setImagePhoneRotY(-29.82);+ } else if (id === "laptop") {+ setImagePhoneRotX(43.23);+ setImagePhoneRotY(-37.82);+ setImagePhoneOpening(1);+ setImagePhoneScale(1);+ } else {+ setImagePhoneRotX(-58.23);+ setImagePhoneRotY(-29.82);+ }}setImagePhoneActive(true);if (mockupId !== "none") onMockupChange?.("none");diff --git a/app/components/ui/editor/Phone3DViewer.tsx b/app/components/ui/editor/Phone3DViewer.tsxindex daca9b9..c421303 100644--- a/app/components/ui/editor/Phone3DViewer.tsx+++ b/app/components/ui/editor/Phone3DViewer.tsx@@ -1,6 +1,6 @@"use client";-import { Canvas, useThree } from "@react-three/fiber";+import { Canvas, useThree, useFrame } from "@react-three/fiber";import { PerspectiveCamera, Environment, OrbitControls } from "@react-three/drei";import { useEffect, useRef, useState, Suspense, useCallback } from "react";import * as THREE from "three";@@ -42,6 +42,7 @@ interface Props {zoom?: number;shadowIntensity?: number;shadowColor?: string;+ videoElement?: HTMLVideoElement | null;}const DEG = Math.PI / 180;@@ -88,6 +89,7 @@ function ModelScene({modelUrl,onApi,onLoaded,+ videoElement,}: Props & {rootRef: React.MutableRefObject<THREE.Group | null>;cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;@@ -97,6 +99,7 @@ function ModelScene({const orbitRef = useRef<OrbitControlsType | null>(null);const screenMatRef = useRef<THREE.MeshBasicMaterial | null>(null);+ const videoTextureRef = useRef<THREE.VideoTexture | null>(null);const [modelGroup, setModelGroup] = useState<THREE.Group | null>(null);const lastLoadedUrlRef = useRef<string | null>(null);const lastLoadedCropKeyRef = useRef<string | null>(null);@@ -105,6 +108,12 @@ function ModelScene({const { autoRotate, rotationSpeed, glow, environment } = ViewerControls3D();+ useFrame(() => {+ if (videoElement && videoTextureRef.current) {+ videoTextureRef.current.needsUpdate = true;+ }+ });+useEffect(() => {const api: Phone3DApi = {renderAt: (w, h) => {@@ -124,6 +133,7 @@ function ModelScene({}, [onApi, gl, scene, cameraRef]);const applyTexture = useCallback(() => {+ if (videoElement) return;const mat = screenMatRef.current;if (!mat) return;const cropKey = cropArea ? JSON.stringify(cropArea) : null;@@ -202,7 +212,46 @@ function ModelScene({lastLoadedCropKeyRef.current = cropKey;};img.src = imageUrl;- }, [imageUrl, imageMaskConfig, cropArea, modelUrl, gl]);+ }, [imageUrl, imageMaskConfig, cropArea, modelUrl, gl, videoElement]);++ useEffect(() => {+ if (!videoElement) {+ if (videoTextureRef.current) {+ videoTextureRef.current.dispose();+ videoTextureRef.current = null;+ }+ return;+ }+ const tex = new THREE.VideoTexture(videoElement);+ tex.flipY = flipYRef.current;+ tex.colorSpace = THREE.SRGBColorSpace;+ tex.generateMipmaps = true;+ tex.minFilter = THREE.LinearMipmapLinearFilter;+ tex.magFilter = THREE.LinearFilter;+ tex.wrapS = THREE.ClampToEdgeWrapping;+ tex.wrapT = THREE.ClampToEdgeWrapping;+ if (videoTextureRef.current) {+ videoTextureRef.current.dispose();+ }+ videoTextureRef.current = tex;++ const mat = screenMatRef.current;+ if (mat) {+ if (mat.map && mat.map !== tex) {+ mat.map.dispose();+ }+ mat.map = tex;+ mat.color.set(0xffffff);+ mat.needsUpdate = true;+ }++ return () => {+ if (videoTextureRef.current === tex) {+ videoTextureRef.current = null;+ }+ tex.dispose();+ };+ }, [videoElement]);const applyTextureRef = useRef(applyTexture);useEffect(() => {diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex 36f0886..234dd7e 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -104,7 +104,6 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct// Motion 3D phone overlay state (reads from shared MotionContext)const {- selectedTemplateId, motionImageUrl,imagePhoneActive, imagePhoneX, imagePhoneY,imagePhoneScale, setImagePhoneScale,imagePhoneRotX, setImagePhoneRotX, imagePhoneRotY, setImagePhoneRotY,@@ -113,8 +112,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functimagePhoneOpening,imagePhoneShadow, imagePhoneShadowColor} = useMockup3dContext();- // Phone shows whenever a real template is selected AND we are in video mode- const motionActive = selectedTemplateId !== null && selectedTemplateId !== "none" && mediaType === "video";+ // 3D phone overlay is active in both video and image mode// Ctrl+scroll zoom badge state for image phone overlayconst [imagePhoneZoomVisible, setImagePhoneZoomVisible] = useState(false);@@ -223,11 +221,6 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct// Image zoom state (for photo mode)const [imageZoomScale, setImageZoomScale] = useState(1);- // Motion phone zoom state (Ctrl + scroll, mirrors image mode behaviour)- const [motionZoomScale, setMotionZoomScale] = useState(1);- const [motionZoomVisible, setMotionZoomVisible] = useState(false);- const motionZoomTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);-const lastSetVideoUrlRef = useRef<string | null>(null);const preservedVideoStateRef = useRef<{ time: number; playing: boolean } | null>(null);@@ -307,7 +300,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct// Fix: update a ref each render (captures fresh state, no re-render cost)// and attach a stable non-passive listener once via useEffect.ctrlScrollWheelRef.current = (e: WheelEvent) => {- if (!e.ctrlKey || mediaType !== "image" || !imagePhoneActive) return;+ if (!e.ctrlKey || !imagePhoneActive) return;e.preventDefault();const next = Math.max(0.3, Math.min(3, imagePhoneScale * (e.deltaY < 0 ? 1.05 : 0.95)));setImagePhoneScale(next);@@ -820,35 +813,6 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct};}, [mediaType, imageUrl]);- // Motion phone zoom with mouse wheel (Ctrl + scroll) — mirrors image mode behaviour- useEffect(() => {- if (!motionActive) return;-- const handleWheel = (e: WheelEvent) => {- if (!e.ctrlKey && !e.metaKey) return;- e.preventDefault();- const zoomFactor = e.deltaY < 0 ? 1.1 : 0.9;- setMotionZoomScale(prev => Math.max(0.3, Math.min(3, prev * zoomFactor)));- setMotionZoomVisible(true);- if (motionZoomTimerRef.current) clearTimeout(motionZoomTimerRef.current);- motionZoomTimerRef.current = setTimeout(() => setMotionZoomVisible(false), 1500);- };-- const container = previewContainerRef.current;- if (!container) return;-- container.addEventListener("wheel", handleWheel, { passive: false });- return () => {- container.removeEventListener("wheel", handleWheel);- };- }, [motionActive]);-- // Reset motion zoom when template selection changes- useEffect(() => {- setMotionZoomScale(1);- setMotionZoomVisible(false);- }, [selectedTemplateId]);-// Drag & drop handlers for imagesconst handleDragOver = (e: React.DragEvent) => {if (mediaType !== "image" || !onImageDrop) return;@@ -1512,79 +1476,18 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct}ctx.restore();- // ── Phone frame overlay for motion export ──- // CSS 3D phone cannot be captured natively; draw a canvas phone bezel so the- // export frame shows the phone outline with the video visible through the screen.- if (motionActive) {- const phoneH = canvasHeight * 0.65;- const phoneW = phoneH * (272 / 552);- const phoneX = (canvasWidth - phoneW) / 2;- const phoneY = (canvasHeight - phoneH) / 2;- const scale = phoneW / 272;- const outerR = Math.round(44 * scale);- const inset = Math.round(5 * scale);- const screenR = Math.round(36 * scale);-- ctx.save();-- // Phone bezel — filled with dark color, screen area punched out (even-odd)- ctx.beginPath();- ctx.roundRect(phoneX, phoneY, phoneW, phoneH, outerR);- ctx.roundRect(phoneX + inset, phoneY + inset, phoneW - inset * 2, phoneH - inset * 2, screenR);- ctx.fillStyle = "rgba(14, 14, 26, 0.93)";- ctx.fill("evenodd");-- // Outer phone border- ctx.strokeStyle = "rgba(255,255,255,0.14)";- ctx.lineWidth = Math.max(1, 1.5 * scale);- ctx.beginPath();- ctx.roundRect(phoneX, phoneY, phoneW, phoneH, outerR);- ctx.stroke();-- // Screen inner border (subtle)- ctx.strokeStyle = "rgba(255,255,255,0.05)";- ctx.lineWidth = 1;- ctx.beginPath();- ctx.roundRect(phoneX + inset, phoneY + inset, phoneW - inset * 2, phoneH - inset * 2, screenR);- ctx.stroke();-- // Dynamic island- const diW = phoneW * 0.22;- const diH = Math.max(4, phoneH * 0.024);- ctx.fillStyle = "#000";- ctx.beginPath();- ctx.roundRect(phoneX + (phoneW - diW) / 2, phoneY + phoneH * 0.018, diW, diH, diH / 2);- ctx.fill();-- // Home indicator- const homeW = phoneW * 0.28;- const homeH = Math.max(3, 4 * scale);- ctx.fillStyle = "rgba(255,255,255,0.28)";- ctx.beginPath();- ctx.roundRect(phoneX + (phoneW - homeW) / 2, phoneY + phoneH - homeH - inset * 1.5, homeW, homeH, homeH / 2);- ctx.fill();-- // Side buttons (left: 2 volume, right: 1 power)- const btnW = Math.max(2, 3 * scale);- const btnH1 = phoneH * 0.08;- const btnH2 = phoneH * 0.11;- ctx.fillStyle = "rgba(14,14,26,0.93)";- ctx.strokeStyle = "rgba(255,255,255,0.10)";- ctx.lineWidth = 1;- // volume up- ctx.beginPath();- ctx.roundRect(phoneX - btnW, phoneY + phoneH * 0.21, btnW, btnH1, btnW / 2);- ctx.fill(); ctx.stroke();- // volume down- ctx.beginPath();- ctx.roundRect(phoneX - btnW, phoneY + phoneH * 0.32, btnW, btnH2, btnW / 2);- ctx.fill(); ctx.stroke();- // power- ctx.beginPath();- ctx.roundRect(phoneX + phoneW, phoneY + phoneH * 0.27, btnW, btnH2, btnW / 2);- ctx.fill(); ctx.stroke();-- ctx.restore();+ // ── 3D phone mockup overlay for video export ──+ // Composite the WebGL canvas snapshot just like image mode does.+ if (imagePhoneActive && imagePhoneCanvasRef.current) {+ const phoneGL = imagePhoneCanvasRef.current;+ const domW = canvasDimensions?.width ?? canvasWidth;+ const pxScale = canvasWidth / domW;+ const phoneCx = canvasWidth / 2 + imagePhoneX * pxScale;+ const phoneCy = canvasHeight / 2 + imagePhoneY * pxScale;+ const drawW = PHONE_W * imagePhoneScale * pxScale;+ const drawH = PHONE_H * imagePhoneScale * pxScale;+ imagePhoneApiRef.current?.renderAt(drawW, drawH);+ ctx.drawImage(phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH);}};@@ -1843,7 +1746,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct// Hide the video layer while a motion template is active;// the video element stays in the DOM so playback/timing continues.// In image mode, also hide when the phone overlay is active.- opacity: (mediaType === "video" ? motionActive : imagePhoneActive) ? 0 : 1,+ opacity: imagePhoneActive ? 0 : 1,transition: 'opacity 0.25s ease, padding 0.2s',...(mediaType === "image" && imageTransform && !apply3DToBackground ? {perspective: `${imageTransform.perspective || 600}px`,@@ -1873,7 +1776,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functtransition: (mediaType === "image" && imageTransform && !apply3DToBackground)? 'transform 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94)': isDraggingVideo || isDraggingRotation ? 'none' : 'transform 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94)',- pointerEvents: motionActive ? 'none' : 'auto',+ pointerEvents: imagePhoneActive ? 'none' : 'auto',transformStyle: mediaType === "image" && !apply3DToBackground ? 'preserve-3d' : undefined,}}onMouseEnter={() => hasMedia && setIsVideoHovered(true)}@@ -1945,7 +1848,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct</div></div>)}- {(isVideoSelected || isVideoHovered) && hasMedia && !isDraggingRotation && !(mediaType === "image" && imagePhoneActive) && (+ {(isVideoSelected || isVideoHovered) && hasMedia && !isDraggingRotation && !imagePhoneActive && (<divclassName={`absolute -inset-px border pointer-events-none z-10 opacity-80 ${isVideoSelected ? 'border-blue-500' : 'border-white'}`}style={{ borderRadius: `${roundedCorners + 1}px` }}@@ -2042,7 +1945,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functtransformStyle: mediaType === "image" && !apply3DToBackground ? 'preserve-3d' : undefined,}}>- <EditorHoverTooltip show={isVideoHovered && mediaType === "image"} />+ <EditorHoverTooltip show={isVideoHovered && imagePhoneActive} /></div></div></div>@@ -2114,45 +2017,8 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct}}/>- {motionActive && (- <div- ref={phoneOverlayRef}- data-phone-overlay- className="absolute inset-0 flex items-center justify-center overflow-hidden"- style={{ zIndex: 150, isolation: "isolate" }}- >- {/* Scale wrapper — controlled by Ctrl+scroll */}- <div- style={{- transform: `scale(${motionZoomScale})`,- transformOrigin: "center center",- transition: "transform 0.08s ease-out",- willChange: "transform",- }}- >- <Phone3DViewer- imageUrl={motionImageUrl}- initialRotationX={0}- initialRotationY={0}- initialRotationZ={0}- shadowIntensity={0}- shadowColor="#000000"- />- </div>-- {/* Ctrl+scroll hint — shown when zoom is at 100% */}- {motionZoomScale === 1 && !motionZoomVisible && (- <div className="absolute bottom-3 left-1/2 -translate-x-1/2 pointer-events-none select-none opacity-0 group-hover:opacity-100 transition-opacity">- <div className="text-white/30 text-[10px] font-normal whitespace-nowrap">- Ctrl + scroll para zoom- </div>- </div>- )}- </div>- )}-- {/* ── Image-mode phone overlay ── */}- {mediaType === "image" && imagePhoneActive && (+ {/* ── 3D phone overlay (video & image mode) ── */}+ {imagePhoneActive && (<divclassName="absolute inset-0 pointer-events-none"style={{ zIndex: 155, overflow: "visible" }}@@ -2177,7 +2043,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functpointerEvents: "none",}}>- <EditorHoverTooltip show={isVideoHovered && mediaType === "image"} />+ <EditorHoverTooltip show={isVideoHovered && imagePhoneActive} /></div></div>@@ -2189,14 +2055,12 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functonMouseLeave={() => setIsVideoHovered(false)}onPointerDown={(e) => {if (!onMockupClick) return;- if (mediaType !== "image" || !imagePhoneActive) return;- // Track click vs drag so the viewers' OrbitControls / drag- // system don't get mistaken for a click intent.+ if (!imagePhoneActive) return;clickStartPosRef.current = { x: e.clientX, y: e.clientY };}}onClick={(e) => {if (!onMockupClick) return;- if (mediaType !== "image" || !imagePhoneActive) return;+ if (!imagePhoneActive) return;const start = clickStartPosRef.current;clickStartPosRef.current = null;if (!start) return;@@ -2230,6 +2094,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct<Laptop3DViewerkey="laptop"imageUrl={imageUrl}+ videoElement={mediaType === "video" ? videoRef.current : undefined}openingProgress={imagePhoneOpening}imageMaskConfig={imageMaskConfig}cropArea={cropArea}@@ -2255,6 +2120,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct<IPhone13ProMax3DViewerkey="iphone-13-pro-max"imageUrl={imageUrl}+ videoElement={mediaType === "video" ? videoRef.current : undefined}imageMaskConfig={imageMaskConfig}cropArea={cropArea}initialRotationX={imagePhoneRotX}@@ -2279,6 +2145,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct<Phone3DViewerkey={imagePhoneDevice}imageUrl={imageUrl}+ videoElement={mediaType === "video" ? videoRef.current : undefined}imageMaskConfig={imageMaskConfig}cropArea={cropArea}initialRotationX={imagePhoneRotX}diff --git a/app/components/ui/editor/ZoomFragmentEditor.tsx b/app/components/ui/editor/ZoomFragmentEditor.tsxindex 568327e..6b8be32 100644--- a/app/components/ui/editor/ZoomFragmentEditor.tsx+++ b/app/components/ui/editor/ZoomFragmentEditor.tsx@@ -114,11 +114,6 @@ export function ZoomFragmentEditor({</button></div>)}- {!movementEnabled && (- <span className="ml-auto font-mono text-[10px] text-white/30">- {Math.round(fragment.focusX)}% · {Math.round(fragment.focusY)}%- </span>- )}</div><divref={focusPreviewRef}diff --git a/app/contexts/Mockup3dContext.tsx b/app/contexts/Mockup3dContext.tsxindex 9147d2b..0c164dd 100644--- a/app/contexts/Mockup3dContext.tsx+++ b/app/contexts/Mockup3dContext.tsx@@ -57,7 +57,6 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {const [motionImageUrl, setMotionImageUrl] = useState<string | null>(null);const [motionIntensity, setMotionIntensity] = useState(70);- // Image mode phone mockupconst [imagePhoneActive, setImagePhoneActive] = useState(false);const [imagePhoneX, setImagePhoneX] = useState(0);const [imagePhoneY, setImagePhoneY] = useState(0);diff --git a/components/ui/DeviceCard.tsx b/components/ui/DeviceCard.tsxnew file mode 100644index 0000000..3f13b7d--- /dev/null+++ b/components/ui/DeviceCard.tsx@@ -0,0 +1,70 @@+import { IMAGE_DEVICE_TEMPLATES } from "@/types";+import { Icon } from "@iconify/react";++export function DeviceCard({+ tpl,+ isActive,+ onClick,+}: {+ tpl: (typeof IMAGE_DEVICE_TEMPLATES)[number];+ isActive: boolean;+ onClick: () => void;+}) {+ return (+ <div className="relative w-40 shrink-0 snap-start mt-0.5">+ <button+ type="button"+ onClick={onClick}+ className={`group flex h-full w-full flex-col overflow-hidden rounded-2xl border text-left transition-all duration-300 active:scale-[0.98] ${isActive+ ? "border-white/20 bg-[#1a1a1e]"+ : "border-white/6 bg-[#17171a] hover:border-white/20"+ }`}+ >+ <div className="relative aspect-3/4 w-full shrink-0 bg-[#0d0d10]">+ <div+ className="absolute inset-0"+ style={{+ background: isActive+ ? `linear-gradient(135deg, ${tpl.accentColor}22 0%, transparent 70%)`+ : `linear-gradient(135deg, ${tpl.accentColor}10 0%, transparent 70%)`,+ }}+ />+ <div className="absolute inset-0 flex items-center justify-center">+ <Icon+ icon={tpl.icon}+ width="22"+ style={{+ color: isActive ? `${tpl.accentColor}cc` : `${tpl.accentColor}55`,+ }}+ />+ </div>++ {isActive && (+ <div+ className="absolute top-1.5 right-1.5 size-4 rounded-full flex items-center justify-center"+ style={{ background: tpl.accentColor }}+ >+ <Icon icon="mdi:check-bold" width={9} className="text-white" />+ </div>+ )}+ </div>++ <div className="border-t border-white/5 bg-[#111113] px-3 py-2.5">+ <h3+ className={`truncate text-xs font-semibold ${isActive ? "text-white" : "text-white/60"+ }`}+ >+ {tpl.title}+ </h3>+ </div>+ </button>++ {isActive && (+ <div+ className="pointer-events-none absolute inset-0 rounded-2xl"+ style={{ boxShadow: `inset 0 0 0 1.5px ${tpl.accentColor}88` }}+ />+ )}+ </div>+ );+}\ No newline at end of filediff --git a/lib/viewer-controls3d.ts b/lib/viewer-controls3d.tsindex 3e53b81..6fdc2b8 100644--- a/lib/viewer-controls3d.ts+++ b/lib/viewer-controls3d.ts@@ -10,9 +10,8 @@ interface ViewerControlsOptions {export function ViewerControls3D({ defaultEnvironment = "studio" }: ViewerControlsOptions = {}) {const [controls, set] = useControls("Configuration 3D", () => ({autoRotate: false,- glow: { value: 1.0, min: 0.0, max: 5.0, step: 0.1 },-rotationSpeed: { value: 3.5, min: 0.1, max: 10, step: 0.1 },+ glow: { value: 1.0, min: 0.0, max: 5.0, step: 0.1 },environment: {options: ['sunset', 'dawn', 'night', 'warehouse', 'forest', 'apartment', 'studio', 'city', 'park', 'lobby'],value: defaultEnvironment