Create professional demos and 3D mockups in seconds, directly in your browser
feat: add Phone3DViewer component for 3D phone mockups
CristianOlivera1b3c006f84585
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsxindex 75f595d..422e918 100644--- a/app/[locale]/(editor)/editor/page.tsx+++ b/app/[locale]/(editor)/editor/page.tsx@@ -1083,12 +1083,7 @@ export default function Editor() {imagePhonePresetId, imagePhoneOpening, imagePhoneShadow, imagePhoneShadowColor,setEditorState]);-- // 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)@@ -1610,33 +1605,32 @@ export default function Editor() {}exportVideo({- quality,- videoBlob: videoBlob ?? undefined,- transparentBackground: selectedWallpaper === -1,- trim: trimRange.end > trimRange.start ? { start: trimRange.start, end: trimRange.end } : undefined,- muteOriginalAudio,- videoHasAudioTrack: videoHasAudioTrack,- audioTracks: audioTracks.map(track => {- const audio = uploadedAudios.find(a => a.id === track.audioId);- return {- audioUrl: audio?.url || '',- startTime: track.startTime,- duration: track.duration,- trimStart: track.trimStart ?? 0,- volume: track.volume,- loop: track.loop,- };- }),- masterVolume,- videoClips: videoClips.length > 0 ? videoClips : undefined,- videoClipBlobs: videoClips.length > 1 ? videoBlobsRef.current : undefined,- clipAudioStates: Object.fromEntries(clipAudioStateRef.current),-}).finally(() => {- isExportingRef.current = false; // ← antes quedaba en true para siempre-});+ quality,+ videoBlob: videoBlob ?? undefined,+ transparentBackground: selectedWallpaper === -1,+ trim: trimRange.end > trimRange.start ? { start: trimRange.start, end: trimRange.end } : undefined,+ muteOriginalAudio,+ videoHasAudioTrack: videoHasAudioTrack,+ audioTracks: audioTracks.map(track => {+ const audio = uploadedAudios.find(a => a.id === track.audioId);+ return {+ audioUrl: audio?.url || '',+ startTime: track.startTime,+ duration: track.duration,+ trimStart: track.trimStart ?? 0,+ volume: track.volume,+ loop: track.loop,+ };+ }),+ masterVolume,+ videoClips: videoClips.length > 0 ? videoClips : undefined,+ videoClipBlobs: videoClips.length > 1 ? videoBlobsRef.current : undefined,+ clipAudioStates: Object.fromEntries(clipAudioStateRef.current),+ }).finally(() => {+ isExportingRef.current = false;+ });};- // Handler para subir video (desde ToolsSidebar)const handleVideoUpload = useCallback(async (file: File) => {const hasExistingClips = videoClipsRef.current.length > 0;@@ -2618,41 +2612,28 @@ export default function Editor() {setTimelineZoom(zoom);}, []);- const handleLoadedMetadata = useCallback(() => {- if (videoRef.current) {- videoRef.current.playbackRate = 1.0;+ const handleLoadedMetadata = useCallback(() => {+ if (videoRef.current) {+ videoRef.current.playbackRate = 1.0;- // Durante la exportación, el pipeline reasigna video.src entre los- // blobs de cada clip para renderizar sus frames. Ese reasignado- // dispara este mismo evento nativo "loadedmetadata"; sin este guard- // redimensionaríamos el canvas de exportación cada vez que carga un- // clip con resolución nativa distinta — justo lo que provoca el- // error "Video sample size must remain constant" de mediabunny.- if (isExportingRef.current) return;+ if (isExportingRef.current) return;- const duration = videoRef.current.duration;- const currentClips = videoClipsRef.current;- const isMultiClip = currentClips.length > 1;-- if (isFinite(duration) && duration > 0 && !isMultiClip) {- setVideoDuration(duration);- setTrimRange(prev => prev.end === 0 ? { start: 0, end: duration } : prev);- }-- const vw = videoRef.current.videoWidth;- const vh = videoRef.current.videoHeight;- // Mismo razonamiento fuera de la exportación: en un track multi-clip- // el <video> compartido cambia de src entre clips a medida que la- // reproducción cruza límites de clip. Esos clips pueden tener- // resoluciones nativas distintas, así que el canvas/aspect-ratio- // debe quedar fijado con lo que se registró al construir el track- // (ver handleVideoUpload / handleAddVideoToTrack), no seguir al- // clip que esté cargado en ese instante.- if (vw > 0 && vh > 0 && !isMultiClip) {- setVideoDimensions({ width: vw, height: vh });- }- }-}, []);+ const duration = videoRef.current.duration;+ const currentClips = videoClipsRef.current;+ const isMultiClip = currentClips.length > 1;++ if (isFinite(duration) && duration > 0 && !isMultiClip) {+ setVideoDuration(duration);+ 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 && !isMultiClip) {+ setVideoDimensions({ width: vw, height: vh });+ }+ }+ }, []);const skipBackward = useCallback(() => {if (videoRef.current) {diff --git a/app/components/ui/PlaceholderEditor.tsx b/app/components/ui/PlaceholderEditor.tsxindex 7151bbe..18f8c6f 100644--- a/app/components/ui/PlaceholderEditor.tsx+++ b/app/components/ui/PlaceholderEditor.tsx@@ -125,7 +125,6 @@ export default function PlaceholderEditor({ onVideoUpload, isUploading = false,</div></div>- {/* Contenedor Principal con el color de fondo del diseño base */}<divclassName="flex-1 flex items-center justify-center bg-[#0a0a0a] p-12"onDragEnter={handleDragEnter}diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsxindex b4a426f..e41b9b5 100644--- a/app/components/ui/editor/MockupMenu.tsx+++ b/app/components/ui/editor/MockupMenu.tsx@@ -482,13 +482,11 @@ export function MockupMenu({{mediaType === "image" && (<><div className="h-px bg-white/6" />-<div className="flex flex-col gap-3"><div className="flex items-center justify-between"><p className="text-[10px] uppercase tracking-widest text-white/40 font-bold">{t("devices3D")}</p>-<div className="flex items-center gap-2"><div className="flex items-center squircle-element border border-white/8 bg-white/3 p-0.5"><button@@ -499,7 +497,6 @@ export function MockupMenu({><Icon icon="ph:caret-left-bold" width="12" /></button>-<buttontype="button"onClick={() => scrollDevices("right")}@@ -517,10 +514,9 @@ export function MockupMenu({className={`pointer-events-none absolute inset-y-0 right-0 z-20 w-12 bg-gradient-to-l from-[#141417] to-transparent transition-opacity duration-200 ${canScrollRight ? "opacity-100" : "opacity-0"}`}/>-<divref={devicesScrollRef}- className="flex gap-2 overflow-x-auto overflow-y-hidden snap-x snap-mandatory scroll-smooth pb-2 pl-1 pr-12 custom-scrollbar"+ className="grid grid-rows-2 grid-flow-col gap-2 overflow-x-auto overflow-y-hidden snap-x snap-mandatory scroll-smooth pb-2 pl-1 pr-12 custom-scrollbar"style={{scrollbarWidth: "none",msOverflowStyle: "none",diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex 50505cf..fa09314 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -30,22 +30,22 @@ import { PHONE_H, PHONE_W, DEVICE_3D_DIMENSIONS } from "@/lib/phone3d.utils";export type { VideoCanvasHandle, VideoCanvasProps };const Phone3DViewer = dynamic(- () => import("./Phone3DViewer").then((m) => ({ default: m.Phone3DViewer })),+ () => import("./mockups-3d/Phone3DViewer").then((m) => ({ default: m.Phone3DViewer })),{ ssr: false });const Laptop3DViewer = dynamic(- () => import("./Laptop3DViewer").then((m) => ({ default: m.Laptop3DViewer })),+ () => import("./mockups-3d/Laptop3DViewer").then((m) => ({ default: m.Laptop3DViewer })),{ ssr: false });const IPhone13ProMax3DViewer = dynamic(- () => import("./IPhone13ProMax3DViewer").then((m) => ({ default: m.IPhone13ProMax3DViewer })),+ () => import("./mockups-3d/IPhone13ProMax3DViewer").then((m) => ({ default: m.IPhone13ProMax3DViewer })),{ ssr: false });const DoubleIPhone3DViewer = dynamic(- () => import("./DoubleIPhone3DViewer").then((m) => ({ default: m.DoubleIPhone3DViewer })),+ () => import("./mockups-3d/DoubleIPhone3DViewer").then((m) => ({ default: m.DoubleIPhone3DViewer })),{ ssr: false });@@ -2176,7 +2176,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functiopointerEvents: "none",}}>- {/* <EditorHoverTooltip show={isVideoHovered && imagePhoneActive} /> */}+ <EditorHoverTooltip show={isVideoHovered && imagePhoneActive} /></div></div>diff --git a/app/components/ui/editor/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsxsimilarity index 100%rename from app/components/ui/editor/DoubleIPhone3DViewer.tsxrename to app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsxdiff --git a/app/components/ui/editor/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsxsimilarity index 100%rename from app/components/ui/editor/IPhone13ProMax3DViewer.tsxrename to app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsxdiff --git a/app/components/ui/editor/Laptop3DViewer.tsx b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsxsimilarity index 100%rename from app/components/ui/editor/Laptop3DViewer.tsxrename to app/components/ui/editor/mockups-3d/Laptop3DViewer.tsxdiff --git a/app/components/ui/editor/Phone3DViewer.tsx b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsxsimilarity index 100%rename from app/components/ui/editor/Phone3DViewer.tsxrename to app/components/ui/editor/mockups-3d/Phone3DViewer.tsxdiff --git a/claude.md b/claude.mdindex f47045e..d42ed3a 100644--- a/claude.md+++ b/claude.md@@ -262,7 +262,6 @@ openvidshot/│ │ # MockupFeatures, MockupCategory, DEFAULT_MOCKUP_CONFIG│ ├── motion.types.ts # ELIMINADO — la lógica de motion se consolidó en MockupMenu/Mockup3dContext│ ├── photo.types.ts # Preview3DConfig, ImageMaskConfig, PREVIEW_CONFIGS,-│ │ # PREVIEW_TO_PHONE_OFFSET (front/top-left-angle/...)│ ├── player-control.types.ts # PlayerControlsProps, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP│ ├── recording.types.ts # RecordingState, RecordingResult, RecordingContextType│ ├── timeline.types.ts # TrimRange, TimelinePropsdiff --git a/components/ui/ControlsPopup.tsx b/components/ui/ControlsPopup.tsxindex 9c812f8..12b0aca 100644--- a/components/ui/ControlsPopup.tsx+++ b/components/ui/ControlsPopup.tsx@@ -20,8 +20,8 @@ export function ControlsPopup() {<divstyle={{position: "fixed",- bottom: "240px",- right: "325px",+ bottom: "220px",+ right: "290px",width: "320px",zIndex: 10,}}diff --git a/components/ui/DeviceCard.tsx b/components/ui/DeviceCard.tsxindex 7faaf70..96f77b7 100644--- a/components/ui/DeviceCard.tsx+++ b/components/ui/DeviceCard.tsx@@ -18,13 +18,11 @@ export function DeviceCard({useEffect(() => {const video = videoRef.current;if (!video) return;-if (isHovering) {const play = async () => {try {await video.play();- } catch {- }+ } catch {}};play();} else {@@ -32,17 +30,19 @@ export function DeviceCard({video.currentTime = 0;}}, [isHovering]);+return (- <div className="relative w-40 shrink-0 snap-start mt-0.5">+ <div className="relative w-40 shrink-0 snap-start"><buttontype="button"onClick={onClick}onMouseEnter={() => setIsHovering(true)}onMouseLeave={() => setIsHovering(false)}- className={`group flex h-full w-full 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"- }`}+ className={`group flex h-full w-full 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 overflow-hidden bg-[#0d0d10]"><div@@ -53,15 +53,14 @@ export function DeviceCard({: `linear-gradient(135deg, ${tpl.accentColor}10 0%, transparent 70%)`,}}/>-<imgsrc={tpl.posterUrl}alt={tpl.title}draggable={false}- className={`absolute inset-0 h-full w-full object-cover transition-all duration-500 ${isHovering ? "scale-105 opacity-0" : "scale-100 opacity-100"- }`}+ className={`absolute inset-0 h-full w-full object-cover transition-all duration-500 ${+ isHovering ? "scale-105 opacity-0" : "scale-100 opacity-100"+ }`}/>-<videoref={videoRef}src={tpl.videoUrl}@@ -71,36 +70,29 @@ export function DeviceCard({playsInlinepreload="metadata"onLoadedData={() => setVideoReady(true)}- className={`absolute inset-0 h-full w-full object-cover transition-all duration-500 ${isHovering && videoReady- ? "scale-105 opacity-100"- : "scale-100 opacity-0"- }`}+ className={`absolute inset-0 h-full w-full object-cover transition-all duration-500 ${+ isHovering && videoReady+ ? "scale-105 opacity-100"+ : "scale-100 opacity-0"+ }`}/>-<div- className={`absolute inset-0 z-20 bg-black/20 transition-opacity duration-300 ${isHovering ? "opacity-100" : "opacity-0"- }`}+ className={`absolute inset-0 z-20 bg-black/20 transition-opacity duration-300 ${+ isHovering ? "opacity-100" : "opacity-0"+ }`}/>-<div- className={`absolute inset-x-0 bottom-0 z-30 transition-all duration-300 ${isHovering- ? "translate-y-0 opacity-100"- : "translate-y-3 opacity-0"- }`}+ className={`absolute inset-x-0 bottom-0 z-30 transition-all duration-300"+ }`}><div className="absolute inset-0 h-24 bg-gradient-to-t from-black via-black/70 to-transparent" />-<div className="relative flex items-center gap-2 p-3">- <Icon- icon={tpl.icon}- width={10}- />- <span className="truncate text-[10px] font-medium text-white">+ <Icon icon={tpl.icon} width={10} />+ <span className="truncate text-[10px] text-white">{tpl.title}</span></div></div>-{isActive && (<divclassName="absolute top-2 right-2 z-40 flex size-4 items-center justify-center rounded-full"@@ -108,16 +100,11 @@ export function DeviceCard({background: tpl.accentColor,}}>- <Icon- icon="mdi:check-bold"- width={8}- className="text-white"- />+ <Icon icon="mdi:check-bold" width={8} className="text-white" /></div>)}</div></button>-{isActive && (<divclassName="pointer-events-none absolute inset-0 rounded-2xl"diff --git a/lib/phone3d.utils.ts b/lib/phone3d.utils.tsindex 41c29c1..0a3f4e6 100644--- a/lib/phone3d.utils.ts+++ b/lib/phone3d.utils.ts@@ -54,8 +54,8 @@ export const deviceConfigs: Record<DeviceKey, DeviceConfig> = {cornerRadiusFactor: 0.04,},phone: {- modelUrl: "/models/phone-gltf.glb", // previously loaded from JSON, now a real GLB- aspectRatio: 0, // uses model's built-in screen mesh UV+ modelUrl: "/models/phone-gltf.glb",+ aspectRatio: 0,screenHeightFactor: 0,screenOffset: { x: 0, y: 0, z: 0 },cornerRadiusFactor: 0,diff --git a/public/images/mockups-3d/sansung-s25.avif b/public/images/mockups-3d/samsung-s25.avifsimilarity index 100%rename from public/images/mockups-3d/sansung-s25.avifrename to public/images/mockups-3d/samsung-s25.avifdiff --git a/public/videos/mockups-3d/sansung-s25.mp4 b/public/videos/mockups-3d/samsung-s25.mp4similarity index 100%rename from public/videos/mockups-3d/sansung-s25.mp4rename to public/videos/mockups-3d/samsung-s25.mp4diff --git a/types/mockup.types.ts b/types/mockup.types.tsindex 0889c11..4ac5aa8 100644--- a/types/mockup.types.ts+++ b/types/mockup.types.ts@@ -109,7 +109,7 @@ export const IMAGE_DEVICE_TEMPLATES = [{id: "iphone",title: "iPhone 15 Pro",- accentColor: "#A8A8B0",+ accentColor: "#00A3FF",icon: "simple-icons:apple",modelUrl: "/models/iphone-15-pro-max.glb",posterUrl: encodeURI("/images/mockups-3d/iphone-15pro.avif"),@@ -118,16 +118,16 @@ export const IMAGE_DEVICE_TEMPLATES = [{id: "samsung",title: "Samsung S25",- accentColor: "#1428A0",+ accentColor: "#2443ff",icon: "simple-icons:samsung",modelUrl: "/models/samsung-galaxy-s25-ultra.glb",- posterUrl: encodeURI("/images/mockups-3d/sansung-s25.avif"),- videoUrl: encodeURI("/videos/mockups-3d/sansung-s25.mp4"),+ posterUrl: encodeURI("/images/mockups-3d/samsung-s25.avif"),+ videoUrl: encodeURI("/videos/mockups-3d/samsung-s25.mp4"),},{id: "phone",title: "Phone",- accentColor: "#00A3FF",+ accentColor: "#ededed",icon: "lineicons:phone",modelUrl: "/models/phone-gltf.glb",posterUrl: encodeURI("/images/mockups-3d/phone.avif"),@@ -136,7 +136,7 @@ export const IMAGE_DEVICE_TEMPLATES = [{id: "laptop",title: "macOS Laptop",- accentColor: "#CECFD3",+ accentColor: "#E0A830",icon: "ph:laptop-bold",modelUrl: "/models/mac-book.glb",posterUrl: encodeURI("/images/mockups-3d/macos-laptop.avif"),diff --git a/types/photo.types.ts b/types/photo.types.tsindex c0fe7a0..94158e9 100644--- a/types/photo.types.ts+++ b/types/photo.types.ts@@ -16,17 +16,6 @@ export interface PhoneRotationOffset {ry: number;}-export const PREVIEW_TO_PHONE_OFFSET: Record<string, PhoneRotationOffset> = {- "front": { rx: 0, ry: 0 },- "top-left-angle": { rx: 15, ry: 25 },- "top-right-angle": { rx: 15, ry: -22 },- "bottom-left-angle": { rx: -15, ry: 25 },- "bottom-right-angle": { rx: -15, ry: -22 },- "isometric": { rx: 25, ry: -45 },- "tilt-up": { rx: 15, ry: 0 },- "tilt-down": { rx: -15, ry: 0 },-};-export const CSS_PHONE_PREVIEW_ROTATIONS: Record<string, PhoneRotationOffset> = {"front": { rx: -30, ry: 22 },"top-left-angle": { rx: -45, ry: 40 },@@ -35,7 +24,6 @@ export const CSS_PHONE_PREVIEW_ROTATIONS: Record<string, PhoneRotationOffset> ="bottom-right-angle": { rx: -10, ry: -15 },"isometric": { rx: -55, ry: -40 },"tilt-up": { rx: -40, ry: 22 },- "tilt-down": { rx: -8, ry: 22 },};export const CSS_LAPTOP_PREVIEW_ROTATIONS: Record<string, PhoneRotationOffset> = {@@ -46,7 +34,6 @@ export const CSS_LAPTOP_PREVIEW_ROTATIONS: Record<string, PhoneRotationOffset> ="bottom-right-angle": { rx: 15, ry: 10 },"isometric": { rx: 60, ry: -55 },"tilt-up": { rx: 50, ry: -30 },- "tilt-down": { rx: 15, ry: -30 },};export const THREEJS_PHONE_ROTATIONS: Record<string, PhoneRotationOffset> = {@@ -57,7 +44,6 @@ export const THREEJS_PHONE_ROTATIONS: Record<string, PhoneRotationOffset> = {"bottom-right-angle": { rx: -42, ry: -5 },"isometric": { rx: -80, ry: -70 },"tilt-up": { rx: -75, ry: -29.82 },- "tilt-down": { rx: -38, ry: -29.82 },};/** Three.js absolute rotation values for the laptop viewer. */@@ -69,7 +55,6 @@ export const THREEJS_LAPTOP_ROTATIONS: Record<string, PhoneRotationOffset> = {"bottom-right-angle": { rx: 30, ry: -15 },"isometric": { rx: 65, ry: -75 },"tilt-up": { rx: 60, ry: -37.82 },- "tilt-down": { rx: 25, ry: -37.82 },};export const PREVIEW_CONFIGS: readonly Preview3DConfig[] = Object.freeze([@@ -78,8 +63,7 @@ export const PREVIEW_CONFIGS: readonly Preview3DConfig[] = Object.freeze([Object.freeze({ id: "top-right-angle", label: "Top Right Angle", rotateX: 18, rotateY: -22, rotateZ: 15, translateY: 5, scale: 0.95, perspective: 500 }),Object.freeze({ id: "bottom-left-angle", label: "Bottom Left Angle", rotateX: -18, rotateY: 25, rotateZ: 15, translateY: -5, scale: 0.95, perspective: 500 }),Object.freeze({ id: "bottom-right-angle", label: "Bottom Right Angle", rotateX: -18, rotateY: -22, rotateZ: -15, translateY: -5, scale: 0.95, perspective: 500 }),- Object.freeze({ id: "isometric", label: "Isometric", rotateX: 35, rotateY: -45, rotateZ: 10, translateY: 0, scale: 0.85, perspective: 1000 }), Object.freeze({ id: "tilt-up", label: "Tilt Up", rotateX: 15, rotateY: 0, rotateZ: 0, translateY: -2, scale: 0.88, perspective: 500 }),- Object.freeze({ id: "tilt-down", label: "Tilt Down", rotateX: -15, rotateY: 0, rotateZ: 0, translateY: 2, scale: 0.88, perspective: 500 }),+ Object.freeze({ id: "isometric", label: "Isometric", rotateX: 35, rotateY: -45, rotateZ: 10, translateY: 0, scale: 0.85, perspective: 1000 }), Object.freeze({ id: "tilt-up", label: "Tilt Up", rotateX: 15, rotateY: 0, rotateZ: 0, translateY: -2, scale: 0.88, perspective: 500 })]);export interface ImageMaskConfig {