Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: enhance MockupMenu and related components with improved state management and scrolling functionality

CristianOlivera113959e37b14b
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index 0538e3e..6c35ff9 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -75,6 +75,7 @@ export default function Editor() {
imagePhoneOpening, setImagePhoneOpening,
imagePhoneShadow, setImagePhoneShadow,
imagePhoneShadowColor, setImagePhoneShadowColor,
+ imagePhoneRefWidth, setImagePhoneRefWidth,
} = useMockup3dContext();
// Undo/Redo system - centralized state management
@@ -322,6 +323,7 @@ export default function Editor() {
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth,
});
} catch (error) {
console.error("Auto-save failed:", error);
@@ -363,6 +365,7 @@ export default function Editor() {
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth
]);
useEffect(() => {
@@ -409,7 +412,6 @@ export default function Editor() {
// Restore current project when project ID changes (not on every currentProject update)
useEffect(() => {
if (!isPhotoMode || !currentProject) return;
-
if (lastRestoredProjectIdRef.current === currentProject.id) return;
isRestoringProjectRef.current = true;
@@ -423,7 +425,6 @@ export default function Editor() {
return;
}
- // Directly restore all states using the data URL
setImageUrl(imageDataUrl);
setBackgroundTab(currentProject.backgroundTab);
setSelectedWallpaper(currentProject.selectedWallpaper);
@@ -448,9 +449,7 @@ export default function Editor() {
height: currentProject.imageHeight,
});
- if (currentProject.imagePhoneActive !== undefined) {
- setImagePhoneActive(currentProject.imagePhoneActive);
- }
+ if (currentProject.imagePhoneActive !== undefined) setImagePhoneActive(currentProject.imagePhoneActive);
if (currentProject.imagePhoneX !== undefined) setImagePhoneX(currentProject.imagePhoneX);
if (currentProject.imagePhoneY !== undefined) setImagePhoneY(currentProject.imagePhoneY);
if (currentProject.imagePhoneScale !== undefined) setImagePhoneScale(currentProject.imagePhoneScale);
@@ -463,11 +462,12 @@ export default function Editor() {
if (currentProject.imagePhoneOpening !== undefined) setImagePhoneOpening(currentProject.imagePhoneOpening);
if (currentProject.imagePhoneShadow !== undefined) setImagePhoneShadow(currentProject.imagePhoneShadow);
if (currentProject.imagePhoneShadowColor !== undefined) setImagePhoneShadowColor(currentProject.imagePhoneShadowColor);
+ setImagePhoneRefWidth(currentProject.imagePhoneRefWidth ?? 0);
setTimeout(() => {
isRestoringProjectRef.current = false;
- }, 500); //
- }, [currentProject, isPhotoMode, setImagePhoneActive, setImagePhoneX, setImagePhoneY, setImagePhoneScale, setImagePhoneRotX, setImagePhoneRotY, setImagePhoneRotZ, setImagePhonePerspective, setImagePhoneDevice, setImagePhonePresetId, setImagePhoneOpening, setImagePhoneShadow, setImagePhoneShadowColor]);
+ }, 500);
+ }, [currentProject, isPhotoMode, setImagePhoneActive, setImagePhoneX, setImagePhoneY, setImagePhoneScale, setImagePhoneRotX, setImagePhoneRotY, setImagePhoneRotZ, setImagePhonePerspective, setImagePhoneDevice, setImagePhonePresetId, setImagePhoneOpening, setImagePhoneShadow, setImagePhoneShadowColor, setImagePhoneRefWidth]);
// Image project handlers
const handleSelectImageProject = useCallback(async (projectId: string) => {
@@ -567,9 +567,11 @@ export default function Editor() {
imagePhoneRotZ,
imagePhonePerspective,
imagePhoneDevice,
+ imagePhonePresetId,
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth
}
);
@@ -609,9 +611,11 @@ export default function Editor() {
imagePhoneRotZ,
imagePhonePerspective,
imagePhoneDevice,
+ imagePhonePresetId,
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth
]);
// Screen capture handler - now creates a project
@@ -626,7 +630,45 @@ export default function Editor() {
file,
file.name,
img.width,
- img.height
+ img.height,
+ {
+ backgroundTab,
+ selectedWallpaper,
+ backgroundBlur,
+ selectedImageUrl,
+ backgroundColorConfig,
+ padding,
+ roundedCorners,
+ shadows,
+ aspectRatio,
+ customDimensions,
+ cropArea,
+ mockupId,
+ mockupConfig,
+ canvasElements,
+ imageTransform: {
+ rotation: videoTransform.rotation,
+ translateX: videoTransform.translateX,
+ translateY: videoTransform.translateY,
+ },
+ imagePreview3D: imageTransform,
+ apply3DToBackground,
+ imageMaskConfig,
+ imagePhoneActive,
+ imagePhoneX,
+ imagePhoneY,
+ imagePhoneScale,
+ imagePhoneRotX,
+ imagePhoneRotY,
+ imagePhoneRotZ,
+ imagePhonePerspective,
+ imagePhoneDevice,
+ imagePhonePresetId,
+ imagePhoneOpening,
+ imagePhoneShadow,
+ imagePhoneShadowColor,
+ imagePhoneRefWidth
+ }
);
if (project) {
@@ -637,7 +679,42 @@ export default function Editor() {
console.error("Failed to create project from screenshot:", error);
}
}
- }, [captureScreen, createProject]);
+ }, [
+ captureScreen,
+ createProject,
+ backgroundTab,
+ selectedWallpaper,
+ backgroundBlur,
+ selectedImageUrl,
+ backgroundColorConfig,
+ padding,
+ roundedCorners,
+ shadows,
+ aspectRatio,
+ customDimensions,
+ cropArea,
+ mockupId,
+ mockupConfig,
+ canvasElements,
+ videoTransform,
+ imageTransform,
+ apply3DToBackground,
+ imageMaskConfig,
+ imagePhoneActive,
+ imagePhoneX,
+ imagePhoneY,
+ imagePhoneScale,
+ imagePhoneRotX,
+ imagePhoneRotY,
+ imagePhoneRotZ,
+ imagePhonePerspective,
+ imagePhoneDevice,
+ imagePhonePresetId,
+ imagePhoneOpening,
+ imagePhoneShadow,
+ imagePhoneShadowColor,
+ imagePhoneRefWidth
+ ]);
// Unified image upload handler - always creates a new history entry to preserve existing projects
const handleImageUploadToCanvas = useCallback(async (file: File) => {
@@ -685,6 +762,7 @@ export default function Editor() {
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth
}
);
@@ -727,6 +805,7 @@ export default function Editor() {
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth
]);
// Handler for drag & drop images on canvas (photo mode only)
@@ -1070,6 +1149,7 @@ export default function Editor() {
imagePhoneOpening,
imagePhoneShadow,
imagePhoneShadowColor,
+ imagePhoneRefWidth
});
}, 300);
return () => {
@@ -1086,16 +1166,17 @@ export default function Editor() {
videoTransform, imageTransform, apply3DToBackground, imageMaskConfig, videoMaskConfig,
imagePhoneActive, imagePhoneX, imagePhoneY, imagePhoneScale, imagePhoneRotX,
imagePhoneRotY, imagePhoneRotZ, imagePhonePerspective, imagePhoneDevice,
- imagePhonePresetId, imagePhoneOpening, imagePhoneShadow, imagePhoneShadowColor,
+ imagePhonePresetId, imagePhoneOpening, imagePhoneShadow, imagePhoneShadowColor, imagePhoneRefWidth,
setEditorState
]);
const prevUndoRedoVersionRef = useRef(undoRedoVersion);
useEffect(() => {
- // Only run when undoRedoVersion actually changed (undo/redo happened)
if (prevUndoRedoVersionRef.current === undoRedoVersion) return;
prevUndoRedoVersionRef.current = undoRedoVersion;
+ isRestoringProjectRef.current = true;
+
setBackgroundTab(editorState.backgroundTab);
setSelectedWallpaper(editorState.selectedWallpaper);
setBackgroundBlur(editorState.backgroundBlur);
@@ -1134,6 +1215,11 @@ export default function Editor() {
setImagePhoneOpening(editorState.imagePhoneOpening);
setImagePhoneShadow(editorState.imagePhoneShadow);
setImagePhoneShadowColor(editorState.imagePhoneShadowColor);
+ setImagePhoneRefWidth(editorState.imagePhoneRefWidth ?? 0);
+
+ setTimeout(() => {
+ isRestoringProjectRef.current = false;
+ }, 500);
}, [undoRedoVersion]);
// Handler para cambiar el mockup
@@ -3154,6 +3240,7 @@ export default function Editor() {
activeTool={activeTool}
isPlaying={isPlaying}
onMockupClick={handleMockupClick}
+ isRestoringProjectRef={isRestoringProjectRef}
layersPanelToolbar={
<EditorTopBar
onExport={handleExport}
diff --git a/app/components/ui/editor/HistoryMenu.tsx b/app/components/ui/editor/HistoryMenu.tsx
index 7c55fe6..5756d96 100644
--- a/app/components/ui/editor/HistoryMenu.tsx
+++ b/app/components/ui/editor/HistoryMenu.tsx
@@ -11,7 +11,6 @@ interface HistoryMenuProps {
currentProjectId?: string | null;
isLoading?: boolean;
onSelectProject: (projectId: string) => void;
- onAddToCanvas: (projectId: string) => void;
onDeleteProject: (projectId: string) => void;
onUploadToHistory: (file: File) => void;
}
@@ -21,7 +20,6 @@ export function HistoryMenu({
currentProjectId,
isLoading = false,
onSelectProject,
- onAddToCanvas,
onDeleteProject,
onUploadToHistory,
}: HistoryMenuProps) {
diff --git a/app/components/ui/editor/MobileToolsMenu.tsx b/app/components/ui/editor/MobileToolsMenu.tsx
index f5142ee..b842dfe 100644
--- a/app/components/ui/editor/MobileToolsMenu.tsx
+++ b/app/components/ui/editor/MobileToolsMenu.tsx
@@ -43,10 +43,10 @@ export function MobileToolsMenu({
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
<Dialog.Trigger asChild>
<button
- className="fixed bottom-4 left-4 z-50 size-10 rounded-full shadow-lg shadow-blue-500/50 bg-gradient-primary flex items-center justify-center hover:scale-105 transition-transform active:scale-95 lg:hidden"
+ className="fixed bottom-4 left-4 z-50 size-7 rounded-full shadow-lg shadow-blue-500/50 bg-gradient-primary flex items-center justify-center hover:scale-105 transition-transform active:scale-95 lg:hidden"
aria-label="Abrir menú de herramientas"
>
- <Icon icon="solar:widget-2-bold-duotone" width="20" className="text-white" aria-hidden="true" />
+ <Icon icon="solar:widget-2-bold-duotone" width="14" className="text-white" aria-hidden="true" />
</button>
</Dialog.Trigger>
diff --git a/app/components/ui/editor/Mockup3dMenu.tsx b/app/components/ui/editor/Mockup3dMenu.tsx
index 9f7a006..72f726c 100644
--- a/app/components/ui/editor/Mockup3dMenu.tsx
+++ b/app/components/ui/editor/Mockup3dMenu.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useRef, useState } from "react";
+import { useEffect, useRef, useState, useCallback } from "react";
import { useTranslations } from "next-intl";
import { Icon } from "@iconify/react";
import { SliderControl } from "../../../../components/ui/SliderControl";
@@ -9,390 +9,387 @@ import { Button } from "@/components/ui/button";
import { DetailPageHeader } from "@/components/ui/DetailHeaderMenu";
function PositionPad({
- x,
- y,
- onChangeX,
- onChangeY,
- onDragStart,
- backgroundUrl,
- backgroundColorCss,
+ x,
+ y,
+ onChangeX,
+ onChangeY,
+ onDragStart,
+ backgroundUrl,
+ backgroundColorCss,
}: {
- x: number;
- y: number;
- onChangeX: (v: number) => void;
- onChangeY: (v: number) => void;
- onDragStart?: () => void;
- backgroundUrl?: string | null;
- backgroundColorCss?: string | null;
+ x: number;
+ y: number;
+ onChangeX: (v: number) => void;
+ onChangeY: (v: number) => void;
+ onDragStart?: () => void;
+ backgroundUrl?: string | null;
+ backgroundColorCss?: string | null;
}) {
- const padRef = useRef<HTMLDivElement>(null);
- const dragging = useRef(false);
- const [isDraggingState, setIsDraggingState] = useState(false);
-
- const cx = Math.max(-X_HALF, Math.min(X_HALF, x));
- const cy = Math.max(-Y_HALF, Math.min(Y_HALF, y));
- const pctX = (cx + X_HALF) / (X_HALF * 2);
- const hy = ((cy + Y_HALF) / (Y_HALF * 2)) * PAD_H;
-
- const fromEvent = (e: React.PointerEvent) => {
- if (!padRef.current) return;
- const rect = padRef.current.getBoundingClientRect();
- const currentWidth = rect.width;
- const rx = Math.max(0, Math.min(currentWidth, e.clientX - rect.left));
- const ry = Math.max(0, Math.min(PAD_H, e.clientY - rect.top));
- onChangeX(Math.round((rx / currentWidth) * X_HALF * 2 - X_HALF));
- onChangeY(Math.round((ry / PAD_H) * Y_HALF * 2 - Y_HALF));
- };
-
- const bgLayerStyle: React.CSSProperties = backgroundUrl
- ? {
- backgroundImage: `url('${backgroundUrl}')`,
- backgroundSize: "cover",
- backgroundPosition: "center",
- backgroundRepeat: "no-repeat",
- }
- : backgroundColorCss
- ? backgroundColorCss.startsWith("#") || backgroundColorCss.startsWith("rgb")
- ? { backgroundColor: backgroundColorCss }
- : {
- backgroundImage: backgroundColorCss,
- backgroundSize: "cover",
- backgroundPosition: "center",
- }
- : {};
-
- return (
- <div className="relative group w-full cursor-default">
- <div
- ref={padRef}
- className={`relative w-full rounded-[14px] overflow-hidden select-none border shadow-[inset_0_2px_8px_rgba(0,0,0,0.8)] transition-all duration-200 ${isDraggingState
- ? "border-cyan-500/40 ring-1 ring-cyan-500/20"
- : "border-zinc-800/50"
- }`}
- style={{ height: PAD_H }}
- onPointerDown={(e) => {
- dragging.current = true;
- setIsDraggingState(true);
- (e.currentTarget as HTMLDivElement).setPointerCapture(e.pointerId);
- onDragStart?.();
- fromEvent(e);
- }}
- onPointerMove={(e) => {
- if (dragging.current) fromEvent(e);
- }}
- onPointerUp={() => {
- dragging.current = false;
- setIsDraggingState(false);
- }}
- >
- <div className="absolute inset-0 pointer-events-none" style={bgLayerStyle} />
- <div className="absolute inset-0 pointer-events-none bg-black/40" />
- {isDraggingState && (
- <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-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 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: `${pctX * 100}%`,
- top: hy,
- transform: `translate(-50%, -50%) ${isDraggingState ? "scale(1.25)" : "scale(1)"}`,
- cursor: isDraggingState ? "grabbing" : "grab",
- }}
- />
- </div>
- </div>
- );
+ const padRef = useRef<HTMLDivElement>(null);
+ const dragging = useRef(false);
+ const rectCache = useRef<DOMRect | null>(null);
+ const [isDraggingState, setIsDraggingState] = useState(false);
+
+ const cx = Math.max(-X_HALF, Math.min(X_HALF, x));
+ const cy = Math.max(-Y_HALF, Math.min(Y_HALF, y));
+ const pctX = (cx + X_HALF) / (X_HALF * 2);
+ const hy = ((cy + Y_HALF) / (Y_HALF * 2)) * PAD_H;
+
+ const fromEvent = useCallback((e: React.PointerEvent) => {
+ if (!rectCache.current) return;
+
+ const rect = rectCache.current;
+ const currentWidth = rect.width;
+ const rx = Math.max(0, Math.min(currentWidth, e.clientX - rect.left));
+ const ry = Math.max(0, Math.min(PAD_H, e.clientY - rect.top));
+
+ onChangeX(Math.round((rx / currentWidth) * X_HALF * 2 - X_HALF));
+ onChangeY(Math.round((ry / PAD_H) * Y_HALF * 2 - Y_HALF));
+ }, [onChangeX, onChangeY]);
+
+ const bgLayerStyle: React.CSSProperties = backgroundUrl
+ ? {
+ backgroundImage: `url('${backgroundUrl}')`,
+ backgroundSize: "cover",
+ backgroundPosition: "center",
+ backgroundRepeat: "no-repeat",
+ }
+ : backgroundColorCss
+ ? backgroundColorCss.startsWith("#") || backgroundColorCss.startsWith("rgb")
+ ? { backgroundColor: backgroundColorCss }
+ : {
+ backgroundImage: backgroundColorCss,
+ backgroundSize: "cover",
+ backgroundPosition: "center",
+ }
+ : {};
+
+ return (
+ <div className="relative group w-full cursor-default">
+ <div
+ ref={padRef}
+ className={`relative w-full rounded-[14px] overflow-hidden select-none border shadow-[inset_0_2px_8px_rgba(0,0,0,0.8)] transition-all duration-200 ${
+ isDraggingState ? "border-cyan-500/40 ring-1 ring-cyan-500/20" : "border-zinc-800/50"
+ }`}
+ style={{ height: PAD_H }}
+ onPointerDown={(e) => {
+ dragging.current = true;
+ setIsDraggingState(true);
+ (e.currentTarget as HTMLDivElement).setPointerCapture(e.pointerId);
+ if (padRef.current) {
+ rectCache.current = padRef.current.getBoundingClientRect();
+ }
+ onDragStart?.();
+ fromEvent(e);
+ }}
+ onPointerMove={(e) => {
+ if (dragging.current) {
+ fromEvent(e);
+ }
+ }}
+ onPointerUp={() => {
+ dragging.current = false;
+ setIsDraggingState(false);
+ rectCache.current = null;
+ }}
+ >
+ <div className="absolute inset-0 pointer-events-none" style={bgLayerStyle} />
+ <div className="absolute inset-0 pointer-events-none bg-black/40" />
+ {isDraggingState && (
+ <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-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 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: `${pctX * 100}%`,
+ top: hy,
+ transform: `translate(-50%, -50%) ${isDraggingState ? "scale(1.25)" : "scale(1)"}`,
+ cursor: isDraggingState ? "grabbing" : "grab",
+ }}
+ />
+ </div>
+ </div>
+ );
}
-function ActiveDevicePreview({
- tpl,
-}: {
- tpl: ActiveDeviceTpl;
-}) {
- const videoRef = useRef<HTMLVideoElement | null>(null);
- const [isHovering, setIsHovering] = useState(false);
- const [videoReady, setVideoReady] = useState(false);
-
- useEffect(() => {
- const video = videoRef.current;
- if (!video) return;
-
- if (isHovering) {
- const play = async () => {
- try {
- await video.play();
- } catch {
+function ActiveDevicePreview({ tpl }: { tpl: ActiveDeviceTpl }) {
+ const videoRef = useRef<HTMLVideoElement | null>(null);
+ const [isHovering, setIsHovering] = useState(false);
+ const [videoReady, setVideoReady] = useState(false);
+
+ useEffect(() => {
+ const video = videoRef.current;
+ if (!video) return;
+
+ let isMounted = true;
+
+ if (isHovering) {
+ const playVideo = async () => {
+ try {
+ await video.play();
+ } catch {
+ }
+ };
+ if (isMounted) playVideo();
+ } else {
+ video.pause();
+ video.currentTime = 0;
}
- };
- play();
- } else {
- video.pause();
- video.currentTime = 0;
- }
- }, [isHovering]);
-
- return (
- <div
- className="relative w-full h-86 overflow-hidden squircle-element-camera border"
- style={{ borderColor: `${tpl.accentColor}44` }}
- onMouseEnter={() => setIsHovering(true)}
- onMouseLeave={() => setIsHovering(false)}
- >
- <div className="absolute inset-0 bg-[#0d0d10]" />
- <div
- className="absolute inset-0 z-10 pointer-events-none"
- style={{
- background: `linear-gradient(135deg, ${tpl.accentColor}22 0%, transparent 70%)`,
- }}
- />
+ return () => {
+ isMounted = false;
+ };
+ }, [isHovering]);
- {tpl.posterUrl ? (
- <img
- src={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"
- }`}
- />
- ) : (
- <div className="absolute inset-0 flex items-center justify-center">
- <Icon
- icon={tpl.icon}
- width="48"
- style={{ color: `${tpl.accentColor}cc` }}
- />
+ return (
+ <div
+ className="relative w-full h-86 overflow-hidden squircle-element-camera border"
+ style={{ borderColor: `${tpl.accentColor}44` }}
+ onMouseEnter={() => setIsHovering(true)}
+ onMouseLeave={() => setIsHovering(false)}
+ >
+ <div className="absolute inset-0 bg-[#0d0d10]" />
+ <div
+ className="absolute inset-0 z-10 pointer-events-none"
+ style={{
+ background: `linear-gradient(135deg, ${tpl.accentColor}22 0%, transparent 70%)`,
+ }}
+ />
+ {tpl.posterUrl ? (
+ <img
+ src={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"
+ }`}
+ />
+ ) : (
+ <div className="absolute inset-0 flex items-center justify-center">
+ <Icon icon={tpl.icon} width="48" style={{ color: `${tpl.accentColor}cc` }} />
+ </div>
+ )}
+ {tpl.videoUrl && (
+ <video
+ ref={videoRef}
+ src={tpl.videoUrl}
+ poster={tpl.posterUrl}
+ muted
+ loop
+ playsInline
+ preload="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"
+ }`}
+ />
+ )}
+ <div
+ className={`absolute inset-0 z-20 bg-black/20 transition-opacity duration-300 ${
+ isHovering ? "opacity-100" : "opacity-0"
+ }`}
+ />
+ <div className=" flex items-center gap-2 absolute bottom-0 left-0 right-0 px-3 py-2 bg-gradient-to-t from-black/80 to-transparent z-30">
+ <Icon icon={tpl.icon} width={14} />
+ <span className="text-[11px] font-bold text-white/90 tracking-wide">{tpl.title}</span>
+ </div>
+ <div
+ className="absolute top-2 right-2 size-5 rounded-full flex items-center justify-center z-30"
+ style={{ background: tpl.accentColor }}
+ >
+ <Icon icon="mdi:check-bold" width={11} className="text-white" />
+ </div>
</div>
- )}
-
- {tpl.videoUrl && (
- <video
- ref={videoRef}
- src={tpl.videoUrl}
- poster={tpl.posterUrl}
- muted
- loop
- playsInline
- preload="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"
- }`}
- />
- )}
-
- <div
- className={`absolute inset-0 z-20 bg-black/20 transition-opacity duration-300 ${isHovering ? "opacity-100" : "opacity-0"
- }`}
- />
-
- <div className=" flex items-center gap-2 absolute bottom-0 left-0 right-0 px-3 py-2 bg-gradient-to-t from-black/80 to-transparent z-30">
- <Icon
- icon={tpl.icon}
- width={14}
- />
- <span className="text-[11px] font-bold text-white/90 tracking-wide">
- {tpl.title}
- </span>
- </div>
-
- <div
- className="absolute top-2 right-2 size-5 rounded-full flex items-center justify-center z-30"
- style={{ background: tpl.accentColor }}
- >
- <Icon icon="mdi:check-bold" width={11} className="text-white" />
- </div>
- </div>
- );
+ );
}
export interface ActiveDeviceTpl {
- id: ImageDeviceId;
- title: string;
- accentColor: string;
- icon: string;
- modelUrl: string;
- posterUrl?: string;
- videoUrl?: string;
+ id: ImageDeviceId;
+ title: string;
+ accentColor: string;
+ icon: string;
+ modelUrl: string;
+ posterUrl?: string;
+ videoUrl?: string;
}
export interface Mockup3dMenuProps {
- activeDeviceTpl: ActiveDeviceTpl | null;
- imagePhoneDevice: string;
- isLaptop: boolean;
- imagePhoneScale: number;
- setImagePhoneScale: (v: number) => void;
- imagePhoneOpening: number;
- setImagePhoneOpening: (v: number) => void;
- imagePhoneShadow: number;
- setImagePhoneShadow: (v: number) => void;
- setImagePhoneShadowColor: (v: string) => void;
- imagePhoneX: number;
- setImagePhoneX: (v: number) => void;
- imagePhoneY: number;
- setImagePhoneY: (v: number) => void;
- setImagePhoneRotX: (v: number) => void;
- setImagePhoneRotY: (v: number) => void;
-
- backgroundUrl?: string | null;
- backgroundColorCss?: string | null;
-
- onBack: () => void;
- onRemove: () => void;
+ activeDeviceTpl: ActiveDeviceTpl | null;
+ imagePhoneDevice: string;
+ isLaptop: boolean;
+ imagePhoneScale: number;
+ setImagePhoneScale: (v: number) => void;
+ imagePhoneOpening: number;
+ setImagePhoneOpening: (v: number) => void;
+ imagePhoneShadow: number;
+ setImagePhoneShadow: (v: number) => void;
+ setImagePhoneShadowColor: (v: string) => void;
+ imagePhoneX: number;
+ setImagePhoneX: (v: number) => void;
+ imagePhoneY: number;
+ setImagePhoneY: (v: number) => void;
+ setImagePhoneRotX: (v: number) => void;
+ setImagePhoneRotY: (v: number) => void;
+ backgroundUrl?: string | null;
+ backgroundColorCss?: string | null;
+ onBack: () => void;
+ onRemove: () => void;
}
export function Mockup3dMenu({
- activeDeviceTpl,
- imagePhoneDevice,
- isLaptop,
- imagePhoneScale,
- setImagePhoneScale,
- imagePhoneOpening,
- setImagePhoneOpening,
- imagePhoneShadow,
- setImagePhoneShadow,
- setImagePhoneShadowColor,
- imagePhoneX,
- setImagePhoneX,
- imagePhoneY,
- setImagePhoneY,
- setImagePhoneRotX,
- setImagePhoneRotY,
-
- backgroundUrl,
- backgroundColorCss,
-
- onBack,
- onRemove,
+ activeDeviceTpl,
+ imagePhoneDevice,
+ isLaptop,
+ imagePhoneScale,
+ setImagePhoneScale,
+ imagePhoneOpening,
+ setImagePhoneOpening,
+ imagePhoneShadow,
+ setImagePhoneShadow,
+ setImagePhoneShadowColor,
+ imagePhoneX,
+ setImagePhoneX,
+ imagePhoneY,
+ setImagePhoneY,
+ setImagePhoneRotX,
+ setImagePhoneRotY,
+ backgroundUrl,
+ backgroundColorCss,
+ onBack,
+ onRemove,
}: Mockup3dMenuProps) {
- const t = useTranslations("mockupMenu");
-
- const handleReset = () => {
- setImagePhoneX(0);
- setImagePhoneY(0);
- setImagePhoneScale(0.9);
- const defaultRotX = imagePhoneDevice === "laptop" ? 43.23 : -58.23;
- const defaultRotY = imagePhoneDevice === "laptop" ? -37.82 : -29.82;
- setImagePhoneRotX(defaultRotX);
- setImagePhoneRotY(defaultRotY);
- if (imagePhoneDevice === "laptop") {
- setImagePhoneOpening(1);
- setImagePhoneShadow(0.7);
- } else if (imagePhoneDevice === "double_iphone_13_pro") {
- setImagePhoneRotX(-30.23);
- setImagePhoneRotY(-60.82);
- } else {
- setImagePhoneShadow(0.4);
- }
- setImagePhoneShadowColor("#000000");
- };
-
- return (
- <>
- <div className="flex items-center gap-2 p-3 border-b border-white/6 shrink-0">
- <DetailPageHeader
- label={t("device3DTitle")}
- icon="mage:box-3d"
- onBack={onBack}
- />
- </div>
-
- <div className="flex-1 overflow-y-auto custom-scrollbar px-4 py-4 space-y-5">
- {activeDeviceTpl && <ActiveDevicePreview tpl={activeDeviceTpl} />}
-
- <div className="flex flex-col gap-4">
- <div className="flex items-center justify-between">
- <span className="text-[10px] font-semibold text-white/50 uppercase tracking-wider">
- {t("configuration")}
- </span>
- <button
- type="button"
- onClick={handleReset}
- className="flex items-center gap-1 text-[11px] text-white/40 hover:text-white/80 transition-colors"
- >
- <Icon icon="lucide:rotate-ccw" width="11" />
- {t("reset")}
- </button>
- </div>
-
- <SliderControl
- label={t("scale")}
- value={Math.round(imagePhoneScale * 100)}
- min={30}
- max={300}
- step={1}
- onChange={(v) => { setImagePhoneScale(v / 100); }}
- suffix="%"
- />
-
- {isLaptop && (
- <SliderControl
- icon="material-symbols:laptop-chromebook-outline"
- label={t("laptopOpening")}
- value={Math.round(imagePhoneOpening * 100)}
- min={0}
- max={100}
- step={1}
- onChange={(v) => { setImagePhoneOpening(v / 100); }}
- suffix="%"
- />
- )}
-
- <SliderControl
- icon="mdi:blur"
- label={t("shadow")}
- value={Math.round(imagePhoneShadow * 100)}
- min={0}
- max={100}
- step={1}
- onChange={(v) => { setImagePhoneShadow(v / 100); }}
- suffix="%"
- />
-
- <div className="flex flex-col gap-2">
- <span className="text-xs text-white/60 font-medium">{t("position")}</span>
- <PositionPad
- x={imagePhoneX}
- y={imagePhoneY}
- onChangeX={setImagePhoneX}
- onChangeY={setImagePhoneY}
- backgroundUrl={backgroundUrl}
- backgroundColorCss={backgroundColorCss}
- />
- </div>
- </div>
-
- <Button
- onClick={onRemove}
- variant="outline"
- className="w-full text-xs mt-2"
- >
- <Icon icon="ph:trash-bold" width="13" aria-hidden="true" />
- {t("removeFrame")}
- </Button>
- </div>
- </>
- );
+ const t = useTranslations("mockupMenu");
+
+ const handleReset = useCallback(() => {
+ setImagePhoneX(0);
+ setImagePhoneY(0);
+ setImagePhoneScale(0.9);
+
+ const defaultRotX = imagePhoneDevice === "laptop" ? 43.23 : -58.23;
+ const defaultRotY = imagePhoneDevice === "laptop" ? -37.82 : -29.82;
+ setImagePhoneRotX(defaultRotX);
+ setImagePhoneRotY(defaultRotY);
+
+ if (imagePhoneDevice === "laptop") {
+ setImagePhoneOpening(1);
+ setImagePhoneShadow(0.7);
+ } else if (imagePhoneDevice === "double_iphone_13_pro") {
+ setImagePhoneRotX(-30.23);
+ setImagePhoneRotY(-60.82);
+ } else {
+ setImagePhoneShadow(0.4);
+ }
+ setImagePhoneShadowColor("#000000");
+ }, [
+ imagePhoneDevice,
+ setImagePhoneX,
+ setImagePhoneY,
+ setImagePhoneScale,
+ setImagePhoneRotX,
+ setImagePhoneRotY,
+ setImagePhoneOpening,
+ setImagePhoneShadow,
+ setImagePhoneShadowColor,
+ ]);
+
+ return (
+ <>
+ <div className="flex items-center gap-2 p-3 border-b border-white/6 shrink-0">
+ <DetailPageHeader label={t("device3DTitle")} icon="mage:box-3d" onBack={onBack} />
+ </div>
+ <div className="flex-1 overflow-y-auto custom-scrollbar px-4 py-4 space-y-5">
+ {activeDeviceTpl && <ActiveDevicePreview tpl={activeDeviceTpl} />}
+
+ <div className="flex flex-col gap-4">
+ <div className="flex items-center justify-between">
+ <span className="text-[10px] font-semibold text-white/50 uppercase tracking-wider">
+ {t("configuration")}
+ </span>
+ <button
+ type="button"
+ onClick={handleReset}
+ className="flex items-center gap-1 text-[11px] text-white/40 hover:text-white/80 transition-colors"
+ >
+ <Icon icon="lucide:rotate-ccw" width="11" />
+ {t("reset")}
+ </button>
+ </div>
+
+ <SliderControl
+ label={t("scale")}
+ value={Math.round(imagePhoneScale * 100)}
+ min={30}
+ max={300}
+ step={1}
+ onChange={(v) => {
+ setImagePhoneScale(v / 100);
+ }}
+ suffix="%"
+ />
+ {isLaptop && (
+ <SliderControl
+ icon="material-symbols:laptop-chromebook-outline"
+ label={t("laptopOpening")}
+ value={Math.round(imagePhoneOpening * 100)}
+ min={0}
+ max={100}
+ step={1}
+ onChange={(v) => {
+ setImagePhoneOpening(v / 100);
+ }}
+ suffix="%"
+ />
+ )}
+ <SliderControl
+ icon="mdi:blur"
+ label={t("shadow")}
+ value={Math.round(imagePhoneShadow * 100)}
+ min={0}
+ max={100}
+ step={1}
+ onChange={(v) => {
+ setImagePhoneShadow(v / 100);
+ }}
+ suffix="%"
+ />
+
+ <div className="flex flex-col gap-2">
+ <span className="text-xs text-white/60 font-medium">{t("position")}</span>
+ <PositionPad
+ x={imagePhoneX}
+ y={imagePhoneY}
+ onChangeX={setImagePhoneX}
+ onChangeY={setImagePhoneY}
+ backgroundUrl={backgroundUrl}
+ backgroundColorCss={backgroundColorCss}
+ />
+ </div>
+ </div>
+
+ <Button onClick={onRemove} variant="outline" className="w-full text-xs mt-2">
+ <Icon icon="ph:trash-bold" width="13" aria-hidden="true" />
+ {t("removeFrame")}
+ </Button>
+ </div>
+ </>
+ );
}
\ No newline at end of file
diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsx
index e41b9b5..02283ca 100644
--- a/app/components/ui/editor/MockupMenu.tsx
+++ b/app/components/ui/editor/MockupMenu.tsx
@@ -1,10 +1,18 @@
"use client";
-import { useState, useRef, useCallback, useEffect } from "react";
+
+import { useState, useRef, useCallback, useEffect, useMemo } from "react";
import { useTranslations } from "next-intl";
import { Icon } from "@iconify/react";
+
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { MOCKUPS, MOCKUP_CATEGORIES } from "@/lib/mockup-data";
-import { IMAGE_DEVICE_TEMPLATES, ImageDeviceId, MenuPage, MockupConfig, MockupCategory } from "@/types/mockup.types";
+import {
+ IMAGE_DEVICE_TEMPLATES,
+ ImageDeviceId,
+ MenuPage,
+ MockupConfig,
+ MockupCategory,
+} from "@/types/mockup.types";
import { MockupGridSkeleton } from "../Skeleton";
import { Button } from "@/components/ui/button";
import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
@@ -17,7 +25,8 @@ export interface MockupMenuProps {
mockupId?: string;
mockupConfig?: MockupConfig;
onMockupChange?: (mockupId: string) => void;
- onMockupConfigChange?: (config: Partial<MockupConfig>) => void; backgroundUrl?: string | null;
+ onMockupConfigChange?: (config: Partial<MockupConfig>) => void;
+ backgroundUrl?: string | null;
backgroundColorCss?: string | null;
backgroundTab?: "wallpaper" | "image" | "color" | "unsplash";
selectedWallpaper?: number;
@@ -42,89 +51,18 @@ export function MockupMenu({
const t = useTranslations("mockupMenu");
const [page, setPage] = useState<MenuPage>(initialPage);
+ const [prevInitialPage, setPrevInitialPage] = useState<MenuPage>(initialPage);
- useEffect(() => {
+ if (initialPage !== prevInitialPage) {
+ setPrevInitialPage(initialPage);
if (initialPage !== "home") {
setPage(initialPage);
}
- }, [initialPage]);
+ }
+
const [selectedCategory, setSelectedCategory] = useState<MockupCategory>("all");
const [gridLoaded, setGridLoaded] = useState(false);
- const devicesScrollRef = useRef<HTMLDivElement>(null);
- const [canScrollLeft, setCanScrollLeft] = useState(false);
- const [canScrollRight, setCanScrollRight] = useState(false);
-
- const updateDevicesScrollState = useCallback(() => {
- const el = devicesScrollRef.current;
- if (!el) return;
-
- const maxScrollLeft = el.scrollWidth - el.clientWidth;
- setCanScrollLeft(el.scrollLeft > 8);
- setCanScrollRight(el.scrollLeft < maxScrollLeft - 8);
- }, []);
-
- const devicesScrollLeftRef = useRef(0);
-
- const handleDevicesScroll = useCallback(() => {
- const el = devicesScrollRef.current;
- if (!el) return;
-
- devicesScrollLeftRef.current = el.scrollLeft;
- updateDevicesScrollState();
- }, [updateDevicesScrollState]);
-
- const restoreDevicesScroll = useCallback(() => {
- const el = devicesScrollRef.current;
- if (!el) return;
-
- el.scrollLeft = devicesScrollLeftRef.current;
- updateDevicesScrollState();
- }, [updateDevicesScrollState]);
-
- const scrollDevices = useCallback((direction: "left" | "right") => {
- const el = devicesScrollRef.current;
- if (!el) return;
- const amount = Math.max(220, Math.round(el.clientWidth * 0.78));
- el.scrollBy({
- left: direction === "left" ? -amount : amount,
- behavior: "smooth",
- });
- }, []);
-
- useEffect(() => {
- if (page !== "home") return;
-
- const id = requestAnimationFrame(() => {
- restoreDevicesScroll();
- });
-
- const el = devicesScrollRef.current;
- if (!el) return;
-
- const onWheel = (e: WheelEvent) => {
- if (el.scrollWidth <= el.clientWidth) return;
- if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) return;
-
- e.preventDefault();
- el.scrollLeft += e.deltaY;
- };
-
- const onScroll = () => updateDevicesScrollState();
-
- el.addEventListener("wheel", onWheel, { passive: false });
- el.addEventListener("scroll", onScroll, { passive: true });
- window.addEventListener("resize", updateDevicesScrollState);
- updateDevicesScrollState();
-
- return () => {
- el.removeEventListener("wheel", onWheel);
- el.removeEventListener("scroll", onScroll);
- window.removeEventListener("resize", updateDevicesScrollState);
- };
-
- return () => cancelAnimationFrame(id);
- }, [page, restoreDevicesScroll, updateDevicesScrollState]);
const {
imagePhoneActive,
setImagePhoneActive,
@@ -147,18 +85,21 @@ export function MockupMenu({
setImagePhoneShadowColor,
} = useMockup3dContext();
- const filteredMockups =
- selectedCategory === "all"
+ const filteredMockups = useMemo(() => {
+ return selectedCategory === "all"
? MOCKUPS
: MOCKUPS.filter((m) => m.category === selectedCategory);
+ }, [selectedCategory]);
- const currentMockup = MOCKUPS.find((m) => m.id === mockupId);
+ const currentMockup = useMemo(() => {
+ return MOCKUPS.find((m) => m.id === mockupId);
+ }, [mockupId]);
const activeDeviceId: ImageDeviceId | null = imagePhoneActive
? (imagePhoneDevice as ImageDeviceId)
: null;
- const activeDeviceTpl: ActiveDeviceTpl | null = (() => {
+ const activeDeviceTpl: ActiveDeviceTpl | null = useMemo(() => {
if (!imagePhoneActive) return null;
const tpl = IMAGE_DEVICE_TEMPLATES.find((t) => t.id === activeDeviceId);
if (!tpl) return null;
@@ -171,46 +112,44 @@ export function MockupMenu({
posterUrl: tpl.posterUrl,
videoUrl: tpl.videoUrl,
};
- })();
+ }, [imagePhoneActive, activeDeviceId]);
const isLaptop = imagePhoneActive && imagePhoneDevice === "laptop";
- const resolvedBackgroundUrl = (() => {
+ const resolvedBackgroundUrl = useMemo(() => {
if (backgroundUrl) return backgroundUrl;
if (backgroundTab === "image" && selectedImageUrl) return selectedImageUrl;
- if (
- backgroundTab === "wallpaper" &&
- typeof selectedWallpaper === "number" &&
- selectedWallpaper >= 0
- ) {
+ if (backgroundTab === "wallpaper" && typeof selectedWallpaper === "number" && selectedWallpaper >= 0) {
return getWallpaperUrl(selectedWallpaper);
}
return null;
- })();
+ }, [backgroundUrl, backgroundTab, selectedImageUrl, selectedWallpaper]);
const hasActiveFrame = mockupId !== "none" || (mediaType === "image" && imagePhoneActive);
- const handleMockupSelect = (id: string) => {
+ const handleMockupSelect = useCallback((id: string) => {
onMockupChange?.(id);
if (imagePhoneActive) setImagePhoneActive(false);
if (id !== "none") setPage("detail-2d");
- };
+ }, [onMockupChange, imagePhoneActive, setImagePhoneActive]);
- const handleCategoryChange = (cat: MockupCategory) => {
+ const handleCategoryChange = useCallback((cat: MockupCategory) => {
setSelectedCategory(cat);
setGridLoaded(false);
setTimeout(() => setGridLoaded(true), 250);
- };
+ }, []);
- const handleDeviceClick = (id: ImageDeviceId) => {
+ const handleDeviceClick = useCallback((id: ImageDeviceId) => {
const isSameDevice = imagePhoneDevice === id;
const isUnposed = imagePhoneRotX === 0 && imagePhoneRotY === 0;
setImagePhoneDevice(id);
+
if (!isSameDevice || isUnposed) {
setImagePhoneX(0);
setImagePhoneY(0);
setImagePhoneScale(0.9);
+
if (id === "iphone-13-pro-max") {
setImagePhoneRotX(-58.23);
setImagePhoneRotY(-29.82);
@@ -227,16 +166,91 @@ export function MockupMenu({
setImagePhoneRotY(-29.82);
}
}
+
setImagePhoneActive(true);
if (mockupId !== "none") onMockupChange?.("none");
setPage("detail-3d");
- };
+ }, [
+ imagePhoneDevice, imagePhoneRotX, imagePhoneRotY, setImagePhoneDevice,
+ setImagePhoneX, setImagePhoneY, setImagePhoneScale, setImagePhoneRotX,
+ setImagePhoneRotY, setImagePhoneOpening, setImagePhoneActive, mockupId, onMockupChange
+ ]);
- const handleRemoveAll = () => {
+ const handleRemoveAll = useCallback(() => {
onMockupChange?.("none");
setImagePhoneActive(false);
setPage("home");
- };
+ }, [onMockupChange, setImagePhoneActive]);
+
+ const devicesScrollRef = useRef<HTMLDivElement>(null);
+ const [canScrollLeft, setCanScrollLeft] = useState(false);
+ const [canScrollRight, setCanScrollRight] = useState(false);
+ const devicesScrollLeftRef = useRef(0);
+
+ const updateDevicesScrollState = useCallback(() => {
+ const el = devicesScrollRef.current;
+ if (!el) return;
+ const maxScrollLeft = el.scrollWidth - el.clientWidth;
+ setCanScrollLeft(el.scrollLeft > 8);
+ setCanScrollRight(el.scrollLeft < maxScrollLeft - 8);
+ }, []);
+
+ const handleDevicesScroll = useCallback(() => {
+ const el = devicesScrollRef.current;
+ if (!el) return;
+ devicesScrollLeftRef.current = el.scrollLeft;
+
+ requestAnimationFrame(() => {
+ updateDevicesScrollState();
+ });
+ }, [updateDevicesScrollState]);
+
+ const restoreDevicesScroll = useCallback(() => {
+ const el = devicesScrollRef.current;
+ if (!el) return;
+ el.scrollLeft = devicesScrollLeftRef.current;
+ updateDevicesScrollState();
+ }, [updateDevicesScrollState]);
+
+ const scrollDevices = useCallback((direction: "left" | "right") => {
+ const el = devicesScrollRef.current;
+ if (!el) return;
+ const amount = Math.max(220, Math.round(el.clientWidth * 0.78));
+ el.scrollBy({
+ left: direction === "left" ? -amount : amount,
+ behavior: "smooth",
+ });
+ }, []);
+
+ useEffect(() => {
+ if (page !== "home") return;
+
+ const id = requestAnimationFrame(() => {
+ restoreDevicesScroll();
+ });
+
+ const el = devicesScrollRef.current;
+ if (!el) return;
+
+ const onWheel = (e: WheelEvent) => {
+ if (el.scrollWidth <= el.clientWidth) return;
+ if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) return;
+ e.preventDefault();
+ el.scrollLeft += e.deltaY;
+ };
+
+ el.addEventListener("wheel", onWheel, { passive: false });
+ window.addEventListener("resize", updateDevicesScrollState);
+
+ updateDevicesScrollState();
+
+ return () => {
+ el.removeEventListener("wheel", onWheel);
+ window.removeEventListener("resize", updateDevicesScrollState);
+ cancelAnimationFrame(id);
+ };
+ }, [page, restoreDevicesScroll, updateDevicesScrollState]);
+
if (page === "detail-2d") {
return (
@@ -300,8 +314,8 @@ export function MockupMenu({
<button
type="button"
className={`group relative flex items-center gap-3 p-2 squircle-element border transition-all w-full h-35 ${mockupId !== "none"
- ? "bg-blue-500/10 border-blue-500/40 text-blue-300"
- : "bg-white/3 border-white/[0.07] text-white/40 hover:border-white/20"
+ ? "bg-blue-500/10 border-blue-500/40 text-blue-300"
+ : "bg-white/3 border-white/[0.07] text-white/40 hover:border-white/20"
}`}
aria-label={t("windowType")}
aria-haspopup="dialog"
@@ -312,9 +326,7 @@ export function MockupMenu({
const categoryConfig = MOCKUP_CATEGORIES.find(
(c) => c.id === currentMockup?.category
);
- const bgUrl =
- categoryConfig?.bgUrl ||
- "https://i.ibb.co/r2JQ3Gcy/minimal-02.jpg";
+ const bgUrl = categoryConfig?.bgUrl || "https://i.ibb.co/r2JQ3Gcy/minimal-02.jpg";
return (
<div
className="absolute inset-0 bg-cover bg-center bg-no-repeat transition-transform duration-500 group-hover:scale-110"
@@ -337,12 +349,8 @@ export function MockupMenu({
</div>
</button>
</PopoverTrigger>
- <PopoverContent
- side="right"
- align="start"
- sideOffset={12}
- className="w-125 p-0 border-0 shadow-2xl"
- >
+
+ <PopoverContent side="right" align="start" sideOffset={12} className="w-125 p-0 border-0 shadow-2xl">
<div className="flex flex-col bg-[#111113] border border-white/10 rounded-xl overflow-hidden shadow-2xl max-h-150">
<div className="flex items-center gap-2 px-4 py-3 border-b border-white/10 bg-white/2 flex-wrap">
{MOCKUP_CATEGORIES.map((cat) => (
@@ -350,8 +358,8 @@ export function MockupMenu({
key={cat.id}
onClick={() => handleCategoryChange(cat.id)}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-medium uppercase tracking-wider transition-all ${selectedCategory === cat.id
- ? "bg-blue-500/20 text-blue-400 border border-blue-500/40"
- : "bg-white/5 text-white/50 hover:text-white/70 border border-transparent hover:border-white/10"
+ ? "bg-blue-500/20 text-blue-400 border border-blue-500/40"
+ : "bg-white/5 text-white/50 hover:text-white/70 border border-transparent hover:border-white/10"
}`}
>
<Icon icon={cat.icon} width="12" />
@@ -362,40 +370,33 @@ export function MockupMenu({
{t("count", { count: filteredMockups.length })}
</span>
</div>
+
<div className="relative overflow-y-auto custom-scrollbar overflow-x-hidden min-h-62.5">
<div
- className={`absolute inset-0 w-full transition-all duration-300 ease-out z-10 ${gridLoaded
- ? "opacity-0 blur-md pointer-events-none scale-105"
- : "opacity-100 blur-0 scale-100"
+ className={`absolute inset-0 w-full transition-all duration-300 ease-out z-10 ${gridLoaded ? "opacity-0 blur-md pointer-events-none scale-105" : "opacity-100 blur-0 scale-100"
}`}
>
<MockupGridSkeleton />
</div>
<div
- className={`p-3 grid grid-cols-3 gap-2 transition-all duration-300 ease-out ${!gridLoaded
- ? "opacity-0 scale-95 pointer-events-none"
- : "opacity-100 scale-100"
+ className={`p-3 grid grid-cols-3 gap-2 transition-all duration-300 ease-out ${!gridLoaded ? "opacity-0 scale-95 pointer-events-none" : "opacity-100 scale-100"
}`}
>
{filteredMockups.map((mockup) => {
- const categoryConfig = MOCKUP_CATEGORIES.find(
- (c) => c.id === mockup.category
- );
+ const categoryConfig = MOCKUP_CATEGORIES.find((c) => c.id === mockup.category);
const isActive = mockupId === mockup.id;
+
return (
<button
key={mockup.id}
onClick={() => handleMockupSelect(mockup.id)}
- className={`group relative w-full h-28 squircle-element border-2 overflow-hidden shadow-lg transition-all active:scale-95 ${isActive
- ? "border-blue-500 ring-2 ring-blue-500/50"
- : "border-neutral-800 hover:border-white/20"
+ className={`group relative w-full h-28 squircle-element border-2 overflow-hidden shadow-lg transition-all active:scale-95 ${isActive ? "border-blue-500 ring-2 ring-blue-500/50" : "border-neutral-800 hover:border-white/20"
}`}
>
<div
className="absolute inset-0 bg-cover bg-center bg-no-repeat transition-transform duration-500 group-hover:scale-105"
style={{
- backgroundImage: `url('${categoryConfig?.bgUrl ||
- "https://i.ibb.co/r2JQ3Gcy/minimal-02.jpg"
+ backgroundImage: `url('${categoryConfig?.bgUrl || "https://i.ibb.co/r2JQ3Gcy/minimal-02.jpg"
}')`,
}}
>
@@ -409,11 +410,7 @@ export function MockupMenu({
</div>
{isActive && (
<div className="absolute top-2 right-2 rounded-full shadow-[0_0_10px_rgba(96,165,250,0.8)] z-30">
- <Icon
- icon="icon-park-solid:check-one"
- width="20"
- className="text-blue-500"
- />
+ <Icon icon="icon-park-solid:check-one" width="20" className="text-blue-500" />
</div>
)}
</button>
@@ -427,27 +424,18 @@ export function MockupMenu({
<div className="space-y-2">
<div className="grid grid-cols-3 gap-2">
- {[
- "none",
- "macos",
- "macos-glass",
- "brave",
- "macos-dark-ide",
- "glass-curve",
- ].map((id) => {
+ {["none", "macos", "macos-glass", "brave", "macos-dark-ide", "glass-curve"].map((id) => {
const mockup = MOCKUPS.find((m) => m.id === id);
if (!mockup) return null;
- const categoryConfig = MOCKUP_CATEGORIES.find(
- (c) => c.id === mockup.category
- );
+
+ const categoryConfig = MOCKUP_CATEGORIES.find((c) => c.id === mockup.category);
const isActive = mockupId === mockup.id;
+
return (
<button
key={id}
onClick={() => handleMockupSelect(id)}
- className={`group relative w-full h-20 squircle-element border overflow-hidden transition-all active:scale-95 ${isActive
- ? "border-blue-500/60 ring-1 ring-blue-500/30"
- : "border-white/[0.07] hover:border-white/20"
+ className={`group relative w-full h-20 squircle-element border overflow-hidden transition-all active:scale-95 ${isActive ? "border-blue-500/60 ring-1 ring-blue-500/30" : "border-white/[0.07] hover:border-white/20"
}`}
>
<div
@@ -464,12 +452,7 @@ export function MockupMenu({
{isActive && (
<div className="absolute top-1.5 right-1.5 rounded-full shadow-[0_0_8px_rgba(96,165,250,0.7)] z-30 flex items-center justify-center size-4">
<div className="absolute size-2 bg-white rounded-full z-0" />
- <Icon
- icon="icon-park-solid:check-one"
- width="24"
- height="24"
- className="text-blue-500 relative z-10"
- />
+ <Icon icon="icon-park-solid:check-one" width="24" height="24" className="text-blue-500 relative z-10" />
</div>
)}
</button>
@@ -517,10 +500,7 @@ export function MockupMenu({
<div
ref={devicesScrollRef}
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",
- }}
+ style={{ scrollbarWidth: "none", msOverflowStyle: "none" }}
onScroll={handleDevicesScroll}
>
{IMAGE_DEVICE_TEMPLATES.map((tpl) => (
@@ -538,12 +518,7 @@ export function MockupMenu({
)}
{hasActiveFrame && (
- <Button
- onClick={handleRemoveAll}
- variant="outline"
- className="w-full text-xs"
- aria-label={t("remove")}
- >
+ <Button onClick={handleRemoveAll} variant="outline" className="w-full text-xs" aria-label={t("remove")}>
<Icon icon="ph:trash-bold" width="13" aria-hidden="true" />
{t("remove")}
</Button>
diff --git a/app/components/ui/editor/PhotoEditorPlaceholder.tsx b/app/components/ui/editor/PhotoEditorPlaceholder.tsx
index 157bc88..5f58b31 100644
--- a/app/components/ui/editor/PhotoEditorPlaceholder.tsx
+++ b/app/components/ui/editor/PhotoEditorPlaceholder.tsx
@@ -505,10 +505,13 @@ export function PhotoEditorPlaceholder({
return (
<div className={`flex flex-col bg-black border-t border-white/10 ${className}`}>
- <div className="h-13 shrink-0 border-t border-white/10 flex items-center justify-between px-5 bg-[#0D0D11]">
- <div className="flex items-center gap-2 text-white/60 whitespace-nowrap">
+ {/* 👇 Contenedor principal de ajustes: Scroll activado y barra oculta */}
+ <div className="h-13 shrink-0 border-t border-white/10 flex items-center justify-between px-5 bg-[#0D0D11] overflow-x-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
+
+ {/* GRUPO IZQUIERDO (Añadido shrink-0 para que no se apachurre) */}
+ <div className="flex items-center gap-2 text-white/60 whitespace-nowrap shrink-0">
<Icon icon="mdi:tune-vertical" width={16} aria-hidden="true" />
- <span className="text-xs font-semibold tracking-wide uppercase">
+ <span className="hidden sm:flex text-xs font-semibold tracking-wide uppercase">
{t("photoPreview.settings")}
</span>
@@ -527,8 +530,8 @@ export function PhotoEditorPlaceholder({
size="sm"
onClick={() => onToggle3DBackground(!apply3DToBackground)}
className={`px-2.5 py-2 text-xs font-medium squircle-element transition-all ${apply3DToBackground
- ? "bg-gradient-radial-primary text-cyan-500 border border-cyan-500/50!"
- : "bg-white/5 text-white/50 border border-white/10 hover:bg-white/10"
+ ? "bg-gradient-radial-primary text-cyan-500 border border-cyan-500/50!"
+ : "bg-white/5 text-white/50 border border-white/10 hover:bg-white/10"
}`}
aria-label={t("photoPreview.apply3D")}
aria-pressed={apply3DToBackground}
@@ -556,6 +559,7 @@ export function PhotoEditorPlaceholder({
perspective: 600
};
setCustomConfig(defaultCustom);
+
if (imagePhoneActive) {
const defaults = getDefaultRotation(imagePhoneDevice);
setImagePhoneRotX(defaults.rx);
@@ -574,7 +578,8 @@ export function PhotoEditorPlaceholder({
</TooltipAction>
</div>
- <div className="flex flex-wrap items-center justify-end gap-2">
+ {/* GRUPO DERECHO (Quité flex-wrap, puse whitespace-nowrap, ml-4 y shrink-0) */}
+ <div className="flex items-center justify-end gap-2 whitespace-nowrap shrink-0 ml-4">
{onOpenCropper && (
<TooltipAction label={t("cropper.tooltip")}>
<Button
@@ -601,7 +606,7 @@ export function PhotoEditorPlaceholder({
</div>
</div>
- <div className="flex gap-3 px-5 overflow-x-auto custom-scrollbar mask-r-from-90% ">
+ <div className="flex gap-1 sm:gap-3 px-5 overflow-x-auto custom-scrollbar mask-r-from-90%">
{allPreviews.map(renderPreviewCard)}
</div>
</div>
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index c28d5dc..f3420d8 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -107,6 +107,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio
onTextToolDeactivate,
onAddElement,
onMockupClick,
+ isRestoringProjectRef,
}, ref) {
const wallpaperUrl = getWallpaperUrl(selectedWallpaper);
@@ -121,10 +122,11 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio
imagePhoneRotZ,
imagePhoneDevice,
imagePhoneOpening,
- imagePhoneShadow, imagePhoneShadowColor
+ imagePhoneShadow, imagePhoneShadowColor,
+ imagePhoneRefWidth, setImagePhoneRefWidth
} = useMockup3dContext();
+
// 3D phone overlay is active in both video and image mode
- // Añadir FUERA del JSX de VideoCanvas, junto a los otros useCallback:
const handlePhoneMount = useCallback((canvas: HTMLCanvasElement) => {
imagePhoneCanvasRef.current = canvas;
}, []);
@@ -314,7 +316,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio
ctrlScrollWheelRef.current = (e: WheelEvent) => {
if (!e.ctrlKey || !imagePhoneActive) return;
e.preventDefault();
- e.stopImmediatePropagation(); // ← evita que otros listeners "wheel" del mismo nodo reaccionen a este evento
+ e.stopImmediatePropagation();
const next = Math.max(0.3, Math.min(3, imagePhoneScale * (e.deltaY < 0 ? 1.05 : 0.95)));
setImagePhoneScale(next);
setImagePhoneZoomVisible(true);
@@ -333,12 +335,16 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio
const [canvasDimensions, setCanvasDimensions] = useState<{ width: number; height: number } | null>(null);
- const canvasWidthRef = useRef<number | null>(null);
-
useEffect(() => {
const wrapper = canvasWrapperRef.current;
if (!wrapper) return;
+ const arReady = aspectRatio !== "auto" || !!customAspectRatio;
+ if (!arReady) {
+ setCanvasDimensions(null);
+ return;
+ }
+
const arNumber = getAspectRatioNumber(aspectRatio, customAspectRatio ?? undefined);
const computeDims = (containerWidth: number, containerHeight: number) => {
@@ -348,36 +354,34 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio
return { width: containerWidth, height: containerWidth / arNumber };
};
- const applyDims = (containerWidth: number, containerHeight: number) => {
- const dims = computeDims(containerWidth, containerHeight);
- if (!dims) return;
-
- const prevWidth = canvasWidthRef.current;
- setCanvasDimensions(dims);
- canvasWidthRef.current = dims.width;
-
- if (prevWidth) {
- const ratio = dims.width / prevWidth;
- if (Math.abs(ratio - 1) >= 0.005) {
- setImagePhoneX(prev => prev * ratio);
- setImagePhoneY(prev => prev * ratio);
- setImagePhoneScale(prev => prev * ratio);
- }
- }
- };
-
const observer = new ResizeObserver(([entry]) => {
const { width, height } = entry.contentRect;
- applyDims(width, height);
+ const dims = computeDims(width, height);
+ if (dims) setCanvasDimensions(dims);
});
observer.observe(wrapper);
const rect = wrapper.getBoundingClientRect();
- applyDims(rect.width, rect.height);
+ const initialDims = computeDims(rect.width, rect.height);
+ if (initialDims) setCanvasDimensions(initialDims);
return () => observer.disconnect();
}, [aspectRatio, customAspectRatio]);
+ useEffect(() => {
+ if (!canvasDimensions) return;
+
+ if (imagePhoneRefWidth > 0 && Math.abs(canvasDimensions.width - imagePhoneRefWidth) > 0.5) {
+ const ratio = canvasDimensions.width / imagePhoneRefWidth;
+ setImagePhoneX(prev => prev * ratio);
+ setImagePhoneY(prev => prev * ratio);
+ setImagePhoneScale(prev => prev * ratio);
+ setImagePhoneRefWidth(canvasDimensions.width);
+ } else if (imagePhoneRefWidth === 0) {
+ setImagePhoneRefWidth(canvasDimensions.width);
+ }
+ }, [canvasDimensions, imagePhoneRefWidth, setImagePhoneX, setImagePhoneY, setImagePhoneScale, setImagePhoneRefWidth]);
+
const cameraDragRef = useRef<{
pointerId: number;
startX: number;
@@ -2263,62 +2267,62 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio
shadowIntensity={imagePhoneShadow}
shadowColor={imagePhoneShadowColor}
/>
- ): activePhoneDevice === "iphone-17-pro-max" ? (
- <IPhone17ProMax3DViewer
- key="iphone-17-pro-max"
- imageUrl={imageUrl}
- videoElement={mediaType === "video" ? videoRef.current : undefined}
- imageMaskConfig={imageMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- />
- ) : activePhoneDevice === "double_iphone_13_pro" ? (
- <DoubleIPhone3DViewer
- key="double_iphone_13_pro"
- imageUrl={imageUrl}
- videoElement={mediaType === "video" ? videoRef.current : undefined}
- imageMaskConfig={imageMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- />
- ) : (
- <Phone3DViewer
- key={imagePhoneDevice}
- imageUrl={imageUrl}
- videoElement={mediaType === "video" ? videoRef.current : undefined}
- imageMaskConfig={imageMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- modelUrl={imagePhoneModelUrl}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- />
- )}
+ ) : activePhoneDevice === "iphone-17-pro-max" ? (
+ <IPhone17ProMax3DViewer
+ key="iphone-17-pro-max"
+ imageUrl={imageUrl}
+ videoElement={mediaType === "video" ? videoRef.current : undefined}
+ imageMaskConfig={imageMaskConfig}
+ cropArea={cropArea}
+ initialRotationX={imagePhoneRotX}
+ initialRotationY={imagePhoneRotY}
+ initialRotationZ={imagePhoneRotZ}
+ onRotationChange={handlePhoneRotationChange}
+ onMount={handlePhoneMount}
+ onApi={handlePhoneApi}
+ scale={1}
+ zoom={1}
+ shadowIntensity={imagePhoneShadow}
+ shadowColor={imagePhoneShadowColor}
+ />
+ ) : activePhoneDevice === "double_iphone_13_pro" ? (
+ <DoubleIPhone3DViewer
+ key="double_iphone_13_pro"
+ imageUrl={imageUrl}
+ videoElement={mediaType === "video" ? videoRef.current : undefined}
+ imageMaskConfig={imageMaskConfig}
+ cropArea={cropArea}
+ initialRotationX={imagePhoneRotX}
+ initialRotationY={imagePhoneRotY}
+ initialRotationZ={imagePhoneRotZ}
+ onRotationChange={handlePhoneRotationChange}
+ onMount={handlePhoneMount}
+ onApi={handlePhoneApi}
+ scale={1}
+ zoom={1}
+ shadowIntensity={imagePhoneShadow}
+ shadowColor={imagePhoneShadowColor}
+ />
+ ) : (
+ <Phone3DViewer
+ key={imagePhoneDevice}
+ imageUrl={imageUrl}
+ videoElement={mediaType === "video" ? videoRef.current : undefined}
+ imageMaskConfig={imageMaskConfig}
+ cropArea={cropArea}
+ initialRotationX={imagePhoneRotX}
+ initialRotationY={imagePhoneRotY}
+ initialRotationZ={imagePhoneRotZ}
+ modelUrl={imagePhoneModelUrl}
+ scale={1}
+ zoom={1}
+ shadowIntensity={imagePhoneShadow}
+ shadowColor={imagePhoneShadowColor}
+ onRotationChange={handlePhoneRotationChange}
+ onMount={handlePhoneMount}
+ onApi={handlePhoneApi}
+ />
+ )}
</div>
</div>
)}
diff --git a/app/contexts/Mockup3dContext.tsx b/app/contexts/Mockup3dContext.tsx
index 12f9561..09119c9 100644
--- a/app/contexts/Mockup3dContext.tsx
+++ b/app/contexts/Mockup3dContext.tsx
@@ -49,6 +49,8 @@ interface Mockup3dState {
/** Drop-shadow color (CSS color string) */
imagePhoneShadowColor: string;
setImagePhoneShadowColor: (v: string) => void;
+ imagePhoneRefWidth: number;
+ setImagePhoneRefWidth: (v: number) => void;
}
const Mockup3dContext = createContext<Mockup3dState | null>(null);
@@ -71,6 +73,7 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
const [imagePhoneOpening, setImagePhoneOpening] = useState(1);
const [imagePhoneShadow, setImagePhoneShadow] = useState(0.6);
const [imagePhoneShadowColor, setImagePhoneShadowColor] = useState("#000000");
+ const [imagePhoneRefWidth, setImagePhoneRefWidth] = useState(0);
return (
<Mockup3dContext.Provider value={{
@@ -90,6 +93,7 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
imagePhoneOpening, setImagePhoneOpening,
imagePhoneShadow, setImagePhoneShadow,
imagePhoneShadowColor, setImagePhoneShadowColor,
+ imagePhoneRefWidth, setImagePhoneRefWidth,
}}>
{children}
</Mockup3dContext.Provider>
diff --git a/components/ui/DeviceCard.tsx b/components/ui/DeviceCard.tsx
index 96f77b7..456172a 100644
--- a/components/ui/DeviceCard.tsx
+++ b/components/ui/DeviceCard.tsx
@@ -3,116 +3,111 @@ import { Icon } from "@iconify/react";
import { IMAGE_DEVICE_TEMPLATES } from "@/types";
export function DeviceCard({
- tpl,
- isActive,
- onClick,
+ tpl,
+ isActive,
+ onClick,
}: {
- tpl: (typeof IMAGE_DEVICE_TEMPLATES)[number];
- isActive: boolean;
- onClick: () => void;
+ tpl: (typeof IMAGE_DEVICE_TEMPLATES)[number];
+ isActive: boolean;
+ onClick: () => void;
}) {
- const videoRef = useRef<HTMLVideoElement | null>(null);
- const [isHovering, setIsHovering] = useState(false);
- const [videoReady, setVideoReady] = useState(false);
+ const videoRef = useRef<HTMLVideoElement | null>(null);
+ const [isHovering, setIsHovering] = useState(false);
+ const [videoReady, setVideoReady] = useState(false);
- useEffect(() => {
- const video = videoRef.current;
- if (!video) return;
- if (isHovering) {
- const play = async () => {
- try {
- await video.play();
- } catch {}
- };
- play();
- } else {
- video.pause();
- video.currentTime = 0;
- }
- }, [isHovering]);
+ useEffect(() => {
+ const video = videoRef.current;
+ if (!video) return;
- return (
- <div className="relative w-40 shrink-0 snap-start">
- <button
- type="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"
- }`}
- >
- <div className="relative aspect-3/4 w-full overflow-hidden bg-[#0d0d10]">
- <div
- className="absolute inset-0 z-10"
- style={{
- background: isActive
- ? `linear-gradient(135deg, ${tpl.accentColor}22 0%, transparent 70%)`
- : `linear-gradient(135deg, ${tpl.accentColor}10 0%, transparent 70%)`,
- }}
- />
- <img
- src={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"
- }`}
- />
- <video
- ref={videoRef}
- src={tpl.videoUrl}
- poster={tpl.posterUrl}
- muted
- loop
- playsInline
- preload="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"
- }`}
- />
- <div
- 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"
- }`}
- >
- <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] text-white">
- {tpl.title}
- </span>
- </div>
- </div>
- {isActive && (
- <div
- className="absolute top-2 right-2 z-40 flex size-4 items-center justify-center rounded-full"
- style={{
- background: tpl.accentColor,
- }}
+ let isMounted = true;
+
+ if (isHovering) {
+ const play = async () => {
+ try {
+ await video.play();
+ } catch {
+ }
+ };
+ if (isMounted) play();
+ } else {
+ video.pause();
+ video.currentTime = 0;
+ }
+
+ return () => {
+ isMounted = false;
+ };
+ }, [isHovering]);
+
+ return (
+ <div className="relative w-40 shrink-0 snap-start">
+ <button
+ type="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"
+ }`}
>
- <Icon icon="mdi:check-bold" width={8} className="text-white" />
- </div>
- )}
+ <div className="relative aspect-3/4 w-full overflow-hidden bg-[#0d0d10]">
+ <div
+ className="absolute inset-0 z-10"
+ style={{
+ background: isActive
+ ? `linear-gradient(135deg, ${tpl.accentColor}22 0%, transparent 70%)`
+ : `linear-gradient(135deg, ${tpl.accentColor}10 0%, transparent 70%)`,
+ }}
+ />
+ <img
+ src={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"
+ }`}
+ />
+ <video
+ ref={videoRef}
+ src={tpl.videoUrl}
+ poster={tpl.posterUrl}
+ muted
+ loop
+ playsInline
+ preload="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"
+ }`}
+ />
+ <div
+ 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">
+ <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] text-white">{tpl.title}</span>
+ </div>
+ </div>
+ {isActive && (
+ <div
+ className="absolute top-2 right-2 z-40 flex size-4 items-center justify-center rounded-full"
+ style={{ background: tpl.accentColor }}
+ >
+ <Icon icon="mdi:check-bold" width={8} className="text-white" />
+ </div>
+ )}
+ </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>
- </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 file
diff --git a/hooks/useImageProjects.ts b/hooks/useImageProjects.ts
index fe1898e..26e8648 100644
--- a/hooks/useImageProjects.ts
+++ b/hooks/useImageProjects.ts
@@ -50,11 +50,12 @@ interface ImageProjectState {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
- imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' ;
+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop';
imagePhonePresetId: string;
imagePhoneOpening: number;
imagePhoneShadow: number;
imagePhoneShadowColor: string;
+ imagePhoneRefWidth: number;
}
const DEFAULT_PROJECT_STATE: ImageProjectState = {
@@ -94,6 +95,7 @@ const DEFAULT_PROJECT_STATE: ImageProjectState = {
imagePhoneOpening: 1,
imagePhoneShadow: 0.6,
imagePhoneShadowColor: "#000000",
+ imagePhoneRefWidth: 0,
};
export function useImageProjects() {
@@ -163,7 +165,7 @@ export function useImageProjects() {
imageHeight,
...fullState,
});
-
+
setCurrentProject(project);
setCurrentProjectId(project.id);
await loadProjects(false);
@@ -192,7 +194,7 @@ export function useImageProjects() {
setCurrentProject(null);
return null;
}
-
+
const updated = await updateImageProject(currentProject.id, updates);
setCurrentProject(updated);
await loadProjects(false);
@@ -206,7 +208,7 @@ export function useImageProjects() {
}, [currentProject, loadProjects]);
const switchToProject = useCallback(async (id: string): Promise<ImageProject | null> => {
-
+
const project = await loadProject(id);
return project;
}, [loadProject]);
@@ -214,12 +216,12 @@ export function useImageProjects() {
const removeProject = useCallback(async (id: string): Promise<void> => {
try {
await deleteImageProject(id);
-
+
if (currentProject?.id === id) {
setCurrentProject(null);
setCurrentProjectId(null);
}
-
+
await loadProjects(false);
} catch (error) {
console.error("Error deleting project:", error);
@@ -236,7 +238,7 @@ export function useImageProjects() {
currentProject,
isLoading,
isSaving,
-
+
loadProjects,
loadProject,
createProject,
diff --git a/types/editor-state.types.ts b/types/editor-state.types.ts
index de8b41a..f796856 100644
--- a/types/editor-state.types.ts
+++ b/types/editor-state.types.ts
@@ -50,6 +50,7 @@ export interface EditorState {
imagePhoneOpening: number;
imagePhoneShadow: number;
imagePhoneShadowColor: string;
+ imagePhoneRefWidth: number;
}
export function createInitialEditorState(overrides?: Partial<EditorState>): EditorState {
@@ -116,6 +117,7 @@ export function createInitialEditorState(overrides?: Partial<EditorState>): Edit
imagePhoneOpening: 1,
imagePhoneShadow: 0.6,
imagePhoneShadowColor: '#000000',
+ imagePhoneRefWidth: 0,
...overrides,
};
}
diff --git a/types/editor.types.ts b/types/editor.types.ts
index 7c38770..eb35c66 100644
--- a/types/editor.types.ts
+++ b/types/editor.types.ts
@@ -123,4 +123,5 @@ export interface VideoCanvasProps {
onAddElement?: (element: CanvasElement) => void;
isPlaying?: boolean;
onMockupClick?: (kind: "2d" | "3d") => void;
+ isRestoringProjectRef?: React.MutableRefObject<boolean>;
}
\ No newline at end of file
diff --git a/types/image-project.types.ts b/types/image-project.types.ts
index 1daa971..14dd664 100644
--- a/types/image-project.types.ts
+++ b/types/image-project.types.ts
@@ -50,12 +50,12 @@ export interface ImageProject {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
- imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'iphone-17-pro-max';
+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'iphone-17-pro-max';
imagePhonePresetId: string;
imagePhoneOpening: number;
imagePhoneShadow: number;
imagePhoneShadowColor: string;
-
+ imagePhoneRefWidth: number;
createdAt: number;
}