Skip to content

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

feat: enhance video menu UI and interactions, add 3D model support in zoom editor, and implement position presets editor

CristianOlivera1d02d0d20d204
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index fd544a2..c15d4c9 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -270,6 +270,14 @@ export default function Editor() {
const isLoadingFromCacheRef = useRef(false);
const lastRestoredProjectIdRef = useRef<string | null>(null);
+ useEffect(() => {
+ return () => {
+ if (autoSaveTimeoutRef.current) {
+ clearTimeout(autoSaveTimeoutRef.current);
+ }
+ };
+ }, []);
+
const autoSaveCurrentProject = useCallback(async () => {
if (!isPhotoMode || !imageUrl || !currentProject) return;
if (isRestoringProjectRef.current) return;
@@ -330,6 +338,7 @@ export default function Editor() {
currentProject, isPhotoMode, autoSaveCurrentProject,
]);
+
// Restore current project when project ID changes (not on every currentProject update)
useEffect(() => {
if (!isPhotoMode || !currentProject) return;
@@ -557,10 +566,10 @@ export default function Editor() {
}, [isPhotoMode, handleImageUploadToCanvas]);
const selectCanvasElement = useCallback((id: string | null) => {
setSelectedElementId(id);
+ setSelectedZoomFragmentId(null);
+ setSelectedVideoClipId(null);
+ setSelectedAudioTrackId(null);
if (id) {
- setSelectedZoomFragmentId(null);
- setSelectedVideoClipId(null);
- setSelectedAudioTrackId(null);
setActiveTool("elements");
}
}, []);
@@ -1169,10 +1178,10 @@ export default function Editor() {
const handleSelectAudioTrack = useCallback((trackId: string | null) => {
setSelectedAudioTrackId(trackId);
+ setSelectedZoomFragmentId(null);
+ setSelectedVideoClipId(null);
+ setSelectedElementId(null);
if (trackId) {
- setSelectedZoomFragmentId(null);
- setSelectedVideoClipId(null);
- setSelectedElementId(null);
setActiveTool("audio");
}
}, []);
@@ -1651,10 +1660,10 @@ export default function Editor() {
const handleSelectVideoClip = useCallback((clipId: string | null) => {
setSelectedVideoClipId(clipId);
// Clear other selections when selecting video clip (mutual exclusivity)
+ setSelectedZoomFragmentId(null);
+ setSelectedAudioTrackId(null);
+ setSelectedElementId(null);
if (clipId) {
- setSelectedZoomFragmentId(null);
- setSelectedAudioTrackId(null);
- setSelectedElementId(null);
setActiveTool("video");
}
}, []);
@@ -2646,11 +2655,9 @@ export default function Editor() {
// Zoom fragment handlers
const handleSelectZoomFragment = useCallback((fragmentId: string | null) => {
setSelectedZoomFragmentId(fragmentId);
- if (fragmentId) {
- setSelectedAudioTrackId(null);
- setSelectedVideoClipId(null);
- setSelectedElementId(null);
- }
+ setSelectedAudioTrackId(null);
+ setSelectedVideoClipId(null);
+ setSelectedElementId(null);
}, []);
const handleActivateZoomTool = useCallback(() => {
@@ -2819,6 +2826,7 @@ export default function Editor() {
}, [selectedElementId, selectedZoomFragmentId, selectedAudioTrackId, selectedVideoClipId, deleteCanvasElement, handleDeleteZoomFragment, handleDeleteAudioTrack, handleDeleteVideoClip, copySelectedElement, pasteElement, isPhotoMode, copiedElement, textToolActive]);
const wasMobileRef = useRef<boolean | null>(null);
+ const otherSelectionActive = !!(selectedZoomFragmentId || selectedAudioTrackId || selectedVideoClipId);
useEffect(() => {
const checkMobile = () => {
@@ -3113,6 +3121,7 @@ export default function Editor() {
onPaddingChange={setPadding}
imageZoomScale={imageZoomScale}
onImageZoomScaleChange={setImageZoomScale}
+ otherSelectionActive={otherSelectionActive}
/>
{/* Video mode: Show player controls and timeline */}
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index 82e9586..439a6cc 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -26,6 +26,7 @@ import {
import { ElementsMenu } from "./ElementsMenu";
import { TooltipAction } from "@/components/ui/tooltip-action";
import { CameraMenu } from "./CameraMenu";
+import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
const ImageRecentBackgroundGrid = lazy(() => import("../ImageRecentBackgroundGrid").then(mod => ({ default: mod.ImageRecentBackgroundGrid })));
const BackgroundColorEditor = lazy(() => import("../BackgroundColorEditor").then(mod => ({ default: mod.BackgroundColorEditor })));
@@ -132,6 +133,7 @@ export function ControlPanel({
}: ExtendedControlPanelProps) {
const t = useTranslations("controlPanel");
+ const { imagePhoneActive } = useMockup3dContext();
return (
<div className="relative w-full sm:w-[320px] h-screen bg-[#141417] border-r border-white/10 flex flex-col shrink-0" role="complementary" aria-label="Control panel">
@@ -365,6 +367,7 @@ export function ControlPanel({
onBack={() => onSelectZoomFragment?.(null)}
onDelete={() => onDeleteZoomFragment?.(selectedZoomFragment.id)}
onUpdate={(updates) => onUpdateZoomFragment?.(selectedZoomFragment.id, updates)}
+ is3DModelActive={imagePhoneActive}
/>
</Suspense>
) : (
diff --git a/app/components/ui/editor/Mockup3dMenu.tsx b/app/components/ui/editor/Mockup3dMenu.tsx
index ac21a77..4e961d0 100644
--- a/app/components/ui/editor/Mockup3dMenu.tsx
+++ b/app/components/ui/editor/Mockup3dMenu.tsx
@@ -7,6 +7,7 @@ import { SliderControl } from "../../../../components/ui/SliderControl";
import { HANDLE_R, ImageDeviceId, PAD_H, X_HALF, Y_HALF } from "@/types/mockup.types";
import { Button } from "@/components/ui/button";
import { DetailPageHeader } from "@/components/ui/DetailHeaderMenu";
+import { Position3DPresetsEditor } from "@/components/ui/Position3DPresetsEditor";
function PositionPad({
x,
@@ -249,6 +250,13 @@ export interface Mockup3dMenuProps {
backgroundColorCss?: string | null;
onBack: () => void;
onRemove: () => void;
+ imagePhoneRotX: number;
+ imagePhoneRotY: number;
+ imagePhoneRotZ: number;
+ setImagePhoneRotZ: (v: number) => void;
+ imagePhonePresetId: string;
+ setImagePhonePresetId: (id: string) => void;
+ mediaType: "video" | "image";
}
export function Mockup3dMenu({
@@ -272,6 +280,13 @@ export function Mockup3dMenu({
backgroundColorCss,
onBack,
onRemove,
+ imagePhoneRotX,
+ imagePhoneRotY,
+ imagePhoneRotZ,
+ setImagePhoneRotZ,
+ imagePhonePresetId,
+ setImagePhonePresetId,
+ mediaType,
}: Mockup3dMenuProps) {
const t = useTranslations("mockupMenu");
@@ -284,6 +299,7 @@ export function Mockup3dMenu({
const defaultRotY = imagePhoneDevice === "laptop" ? -37.82 : -29.82;
setImagePhoneRotX(defaultRotX);
setImagePhoneRotY(defaultRotY);
+ setImagePhoneRotZ(0);
if (imagePhoneDevice === "laptop") {
setImagePhoneOpening(1);
@@ -297,6 +313,7 @@ export function Mockup3dMenu({
setImagePhoneShadow(0.4);
}
setImagePhoneShadowColor("#000000");
+ setImagePhonePresetId("custom");
}, [
imagePhoneDevice,
setImagePhoneX,
@@ -304,9 +321,11 @@ export function Mockup3dMenu({
setImagePhoneScale,
setImagePhoneRotX,
setImagePhoneRotY,
+ setImagePhoneRotZ,
setImagePhoneOpening,
setImagePhoneShadow,
- setImagePhoneShadowColor
+ setImagePhoneShadowColor,
+ setImagePhonePresetId
]);
return (
@@ -331,6 +350,34 @@ export function Mockup3dMenu({
{t("reset")}
</button>
</div>
+ {mediaType === "video" && (
+ <Position3DPresetsEditor
+ device={imagePhoneDevice}
+ isLaptop={isLaptop}
+ selectedPresetId={imagePhonePresetId}
+ onSelectPreset={(preset) => {
+ setImagePhoneX(preset.x);
+ setImagePhoneY(preset.y);
+ setImagePhoneScale(preset.scale);
+ setImagePhoneRotX(preset.rotateX);
+ setImagePhoneRotY(preset.rotateY);
+ setImagePhoneRotZ(preset.rotateZ);
+ setImagePhonePresetId(preset.id);
+ if ("imagePhoneOpening" in preset) {
+ setImagePhoneOpening(preset.imagePhoneOpening);
+ }
+ }}
+ rotateX={imagePhoneRotX}
+ rotateY={imagePhoneRotY}
+ onRotationXYChange={(rX, rY) => {
+ setImagePhoneRotX(rX);
+ setImagePhoneRotY(rY);
+ }}
+ rotateZ={imagePhoneRotZ}
+ onRotateZChange={setImagePhoneRotZ}
+ onCustomReset={handleReset}
+ />
+ )}
<SliderControl
icon="solar:scale-linear"
diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsx
index 9f38bf1..2180160 100644
--- a/app/components/ui/editor/MockupMenu.tsx
+++ b/app/components/ui/editor/MockupMenu.tsx
@@ -64,27 +64,13 @@ export function MockupMenu({
const [gridLoaded, setGridLoaded] = useState(false);
const {
- imagePhoneActive,
- setImagePhoneActive,
- imagePhoneX,
- setImagePhoneX,
- imagePhoneY,
- setImagePhoneY,
- imagePhoneScale,
- setImagePhoneScale,
- imagePhoneRotX,
- imagePhoneRotY,
- setImagePhoneRotX,
- setImagePhoneRotY,
- imagePhoneDevice,
- setImagePhoneDevice,
- imagePhoneOpening,
- setImagePhoneOpening,
- imagePhoneShadow,
- setImagePhoneShadow,
- setImagePhoneShadowColor,
+ imagePhoneActive, setImagePhoneActive, imagePhoneX, setImagePhoneX, imagePhoneY, setImagePhoneY,
+ imagePhoneScale, setImagePhoneScale, imagePhoneRotX, imagePhoneRotY, setImagePhoneRotX, setImagePhoneRotY,
+ imagePhoneRotZ, setImagePhoneRotZ, imagePhoneDevice, setImagePhoneDevice, imagePhoneOpening, setImagePhoneOpening,
+ imagePhoneShadow, setImagePhoneShadow, imagePhoneShadowColor, imagePhonePresetId, setImagePhonePresetId, setImagePhoneShadowColor
} = useMockup3dContext();
+
const filteredMockups = useMemo(() => {
return selectedCategory === "all"
? MOCKUPS
@@ -271,6 +257,7 @@ export function MockupMenu({
activeDeviceTpl={activeDeviceTpl}
imagePhoneDevice={imagePhoneDevice}
isLaptop={isLaptop}
+ mediaType={mediaType}
imagePhoneScale={imagePhoneScale}
setImagePhoneScale={setImagePhoneScale}
imagePhoneOpening={imagePhoneOpening}
@@ -288,6 +275,12 @@ export function MockupMenu({
backgroundColorCss={backgroundColorCss}
onBack={() => setPage("home")}
onRemove={handleRemoveAll}
+ imagePhoneRotX={imagePhoneRotX}
+ imagePhoneRotY={imagePhoneRotY}
+ imagePhoneRotZ={imagePhoneRotZ}
+ setImagePhoneRotZ={setImagePhoneRotZ}
+ imagePhonePresetId={imagePhonePresetId}
+ setImagePhonePresetId={setImagePhonePresetId}
/>
);
}
@@ -462,7 +455,6 @@ export function MockupMenu({
</div>
</div>
</div>
- {mediaType === "image" && (
<>
<div className="h-px bg-white/6" />
@@ -516,7 +508,6 @@ export function MockupMenu({
</div>
</div>
</>
- )}
{hasActiveFrame && (
<Button onClick={handleRemoveAll} variant="outline" className="w-full text-xs" aria-label={t("remove")}>
<Icon icon="ph:trash-bold" width="13" aria-hidden="true" />
diff --git a/app/components/ui/editor/PhotoEditorPlaceholder.tsx b/app/components/ui/editor/PhotoEditorPlaceholder.tsx
index 35b32f7..7df7c29 100644
--- a/app/components/ui/editor/PhotoEditorPlaceholder.tsx
+++ b/app/components/ui/editor/PhotoEditorPlaceholder.tsx
@@ -25,6 +25,7 @@ import {
getPhoneImagePreviews,
} from "@/types/photo.types";
import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
+import { PositionCustomControls } from "@/components/ui/PositionCustomControls";
const DEFAULT_PHONE_ROTATION = { rx: -58.23, ry: -29.82 };
const DEFAULT_LAPTOP_ROTATION = { rx: 43.23, ry: -37.82 };
@@ -304,105 +305,36 @@ export function PhotoEditorPlaceholder({
</PopoverTitle>
</PopoverHeader>
- <div className="space-y-4">
- {!imagePhoneActive && (
- <SliderControl
- icon="mdi:cube-outline"
- label={t("photoPreview.custom.perspective")}
- value={customConfig.perspective || 600}
- min={200}
- max={1000}
- step={50}
- onChange={(value) => {
- updateCustomConfig({ perspective: value });
- }}
- suffix="px"
- />
- )}
-
- <SliderControl
- icon="mdi:resize"
- label={t("photoPreview.custom.scale")}
- value={Math.round(customConfig.scale * 100)}
- min={50}
- max={150}
- step={5}
- onChange={(value) => {
- updateCustomConfig({ scale: value / 100 });
- if (imagePhoneActive) setImagePhoneScale(value / 100);
- }}
- suffix="%"
- />
-
- <div className="space-y-2">
- <div className="flex items-center gap-1.5 text-[11px] text-white/60">
- <Icon icon="mdi:rotate-3d-variant" width={12} />
- <span>{t("photoPreview.custom.rotationXY")}</span>
- </div>
- <div
- className="relative w-full aspect-square bg-white/3 rounded-lg border border-white/10 cursor-crosshair overflow-hidden hover:bg-white/4 transition-colors"
- onClick={(e) => {
- const rect = e.currentTarget.getBoundingClientRect();
- const x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
- const y = ((e.clientY - rect.top) / rect.height) * 2 - 1;
- const rY = Math.round(-x * 45);
- const rX = Math.round(y * 45);
-
- updateCustomConfig({ rotateY: rY, rotateX: rX });
- if (imagePhoneActive) {
- setImagePhoneRotX(rX);
- setImagePhoneRotY(rY);
- }
- }}
- >
- <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
- <div className="w-full h-px bg-white/5" />
- <div className="h-full w-px bg-white/5 absolute" />
- </div>
- <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-all duration-75 cursor-grab"
- style={{
- width: "14px",
- height: "14px",
- left: `${50 + (-customConfig.rotateY / 45) * 50}%`,
- top: `${50 + (customConfig.rotateX / 45) * 50}%`,
- transform: "translate(-50%, -50%) scale(1)",
- }}
- />
- </div>
- </div>
-
- <SliderControl
- icon="mdi:axis-z-rotate-clockwise"
- label={t("photoPreview.custom.rotationZ")}
- value={customConfig.rotateZ}
- min={-45}
- max={45}
- step={5}
- onChange={(value) => {
- updateCustomConfig({ rotateZ: value });
- if (imagePhoneActive) setImagePhoneRotZ(value);
- }}
- suffix="°"
- />
-
- <SliderControl
- icon="mdi:arrow-up-down"
- label={t("photoPreview.custom.vertical")}
- value={customConfig.translateY}
- min={-10}
- max={100}
- step={1}
- onChange={(value) => {
- updateCustomConfig({ translateY: value });
- if (imagePhoneActive) setImagePhoneY(value);
- }}
- suffix="%"
- />
- </div>
-
- <button
- onClick={() => {
+ <PositionCustomControls
+ scale={customConfig.scale}
+ onScaleChange={(v) => {
+ updateCustomConfig({ scale: v });
+ if (imagePhoneActive) setImagePhoneScale(v);
+ }}
+ rotateX={customConfig.rotateX}
+ rotateY={customConfig.rotateY}
+ onRotationXYChange={(rX, rY) => {
+ updateCustomConfig({ rotateX: rX, rotateY: rY });
+ if (imagePhoneActive) {
+ setImagePhoneRotX(rX);
+ setImagePhoneRotY(rY);
+ }
+ }}
+ rotateZ={customConfig.rotateZ}
+ onRotateZChange={(v) => {
+ updateCustomConfig({ rotateZ: v });
+ if (imagePhoneActive) setImagePhoneRotZ(v);
+ }}
+ perspective={!imagePhoneActive ? (customConfig.perspective || 600) : undefined}
+ onPerspectiveChange={
+ !imagePhoneActive ? (v) => updateCustomConfig({ perspective: v }) : undefined
+ }
+ verticalValue={customConfig.translateY}
+ onVerticalChange={(v) => {
+ updateCustomConfig({ translateY: v });
+ if (imagePhoneActive) setImagePhoneY(v);
+ }}
+ onReset={() => {
const resetConfig: Preview3DConfig = {
id: "custom",
label: t("photoPreview.custom.label"),
@@ -415,7 +347,6 @@ export function PhotoEditorPlaceholder({
};
setCustomConfig(resetConfig);
if (selectedPreviewId === "custom") onSelectPreview?.(resetConfig);
-
if (imagePhoneActive) {
const defaults = getDefaultRotation(imagePhoneDevice);
setImagePhoneRotX(defaults.rx);
@@ -426,11 +357,15 @@ export function PhotoEditorPlaceholder({
setImagePhoneY(0);
}
}}
- className="w-full mt-4 px-3 py-2 rounded-lg bg-white/5 hover:bg-white/10 text-[11px] text-white/70 hover:text-white transition-all flex items-center justify-center gap-2 border border-white/5"
- >
- <Icon icon="mdi:restore" width={14} />
- {t("photoPreview.custom.reset")}
- </button>
+ labels={{
+ perspective: t("photoPreview.custom.perspective"),
+ scale: t("photoPreview.custom.scale"),
+ rotationXY: t("photoPreview.custom.rotationXY"),
+ rotationZ: t("photoPreview.custom.rotationZ"),
+ vertical: t("photoPreview.custom.vertical"),
+ reset: t("photoPreview.custom.reset"),
+ }}
+ />
</PopoverContent>
</Popover>
);
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 063635e..2561393 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -23,7 +23,7 @@ import { EditorHoverTooltip } from "./EditorHoverTooltip";
import DropImage from "@/components/ui/DropImage";
import { LayersPanel } from "./LayersPanel";
import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
-import { PHONE_H, PHONE_W, DEVICE_3D_DIMENSIONS, DEVICE_VIEWER_DEFAULTS, PHONE_DEVICE_URLS } from "@/lib/phone3d.utils";
+import { PHONE_H, PHONE_W, DEVICE_3D_DIMENSIONS, DEVICE_VIEWER_DEFAULTS, PHONE_DEVICE_URLS, type ImageMaskConfigLike } from "@/lib/phone3d.utils";
import { Viewer3DControls } from "@/lib/viewer-controls3d";
import { ControlsPopup } from "@/components/ui/ControlsPopup";
import { CanvasContextMenu } from "@/components/ui/CanvasContextMenu";
@@ -125,6 +125,7 @@ function VideoCanvasInner({
onPaddingChange,
imageZoomScale = 1,
onImageZoomScaleChange,
+ otherSelectionActive = false,
}: VideoCanvasProps & { ref?: React.Ref<VideoCanvasHandle> }) {
const wallpaperUrl = getWallpaperUrl(selectedWallpaper);
@@ -183,7 +184,7 @@ function VideoCanvasInner({
renderAt: (w: number, h: number) => void;
restorePreview: () => void;
hasBuiltInShadow?: boolean;
- getVisualSize?: () => { width: number; height: number } | null;
+ getVisualSize?: () => { width: number; height: number; offsetY?: number } | null; // ← offsetY
} | null>(null);
const [activePhoneDevice, setActivePhoneDevice] = useState<string | null>(null);
const [phoneTransitioning, setPhoneTransitioning] = useState(false);
@@ -254,6 +255,7 @@ function VideoCanvasInner({
// Foreground canvas — used to render the mockup in isolation so that the
// WebGL 3D perspective is applied only to the mockup, not to the background.
const foregroundCanvasRef = useRef<HTMLCanvasElement | null>(null);
+ const maskCompositeCanvasRef = useRef<HTMLCanvasElement | null>(null);
const wallpaperImageRef = useRef<HTMLImageElement | null>(null);
const customImageRef = useRef<HTMLImageElement | null>(null);
@@ -284,6 +286,13 @@ function VideoCanvasInner({
lastSetVideoUrlRef.current = null;
}, [mockupId]);
+ useEffect(() => {
+ if (otherSelectionActive) {
+ setIsVideoSelected(false);
+ setCanvasSelectedIds([]);
+ }
+ }, [otherSelectionActive]);
+
useEffect(() => {
const targetUrl = activeClipUrl ?? videoUrl;
if (videoRef.current && targetUrl) {
@@ -376,7 +385,7 @@ function VideoCanvasInner({
const rotationStartAngleRef = useRef<number>(0);
const videoContainerRef = useRef<HTMLDivElement>(null);
const clickStartPosRef = useRef<{ x: number; y: number } | null>(null);
- const CLICK_THRESHOLD = 5; // px
+ const CLICK_THRESHOLD = 5;
const [elementCorners, setElementCorners] = useState<Record<string, Corner | null>>({});
const cameraVideoRef = useRef<HTMLVideoElement | null>(null);
@@ -602,8 +611,8 @@ function VideoCanvasInner({
const handleLayersMultiSelect = useCallback((ids: string[]) => {
setCanvasSelectedIds(ids);
- if (ids.length === 1) handleElementSelect(ids[0]);
- else if (ids.length === 0) handleElementSelect(null);
+ if (ids.length >= 1) handleElementSelect(ids[0]);
+ else handleElementSelect(null);
}, [handleElementSelect]);
const handleLayersDelete = useCallback((idOrIds: string | string[]) => {
@@ -1230,6 +1239,42 @@ function VideoCanvasInner({
}
};
+ const drawMaskedImage = (
+ destCtx: CanvasRenderingContext2D,
+ img: CanvasImageSource,
+ x: number,
+ y: number,
+ w: number,
+ h: number,
+ maskConfig?: ImageMaskConfigLike | null
+ ) => {
+ if (!maskConfig?.enabled) {
+ destCtx.drawImage(img, x, y, w, h);
+ return;
+ }
+ const safeW = Math.max(1, Math.round(w));
+ const safeH = Math.max(1, Math.round(h));
+ let off = maskCompositeCanvasRef.current;
+ if (!off) {
+ off = document.createElement('canvas');
+ maskCompositeCanvasRef.current = off;
+ }
+ if (off.width !== safeW || off.height !== safeH) {
+ off.width = safeW;
+ off.height = safeH;
+ }
+ const offCtx = off.getContext('2d');
+ if (!offCtx) {
+ destCtx.drawImage(img, x, y, w, h);
+ return;
+ }
+ offCtx.setTransform(1, 0, 0, 1, 0, 0);
+ offCtx.clearRect(0, 0, safeW, safeH);
+ offCtx.drawImage(img, 0, 0, safeW, safeH);
+ applyGradientMaskToRegion(offCtx, 0, 0, safeW, safeH, maskConfig);
+ destCtx.drawImage(off, x, y, w, h);
+ };
+
// Helper function to render canvas elements (SVG, images, text)
const renderCanvasElements = async (
ctx: CanvasRenderingContext2D,
@@ -1440,7 +1485,7 @@ function VideoCanvasInner({
const drawMockupAndMedia = (
c: CanvasRenderingContext2D,
containerX: number, containerY: number, containerWidth: number, containerHeight: number,
- source: HTMLVideoElement | HTMLImageElement, applyImageXform: boolean
+ source: HTMLVideoElement | HTMLImageElement, applyImageXform: boolean, is3DActive: boolean = false
) => {
const vCX = containerX + containerWidth / 2;
const vCY = containerY + containerHeight / 2;
@@ -1513,9 +1558,12 @@ function VideoCanvasInner({
c.rect(vX, vY, vW, vH);
c.clip();
}
-
if (mediaType === "video") {
- c.filter = 'saturate(130%) contrast(104%) brightness(103%)';
+ if (is3DActive) {
+ c.filter = 'saturate(125%) contrast(110%) brightness(105%)';
+ } else {
+ c.filter = 'saturate(130%) contrast(104%) brightness(103%)';
+ }
}
if (cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)) {
@@ -1564,11 +1612,11 @@ function VideoCanvasInner({
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;
- // Use device-specific dimensions instead of generic PHONE_W/H
const measuredDims = imagePhoneApiRef.current?.getVisualSize?.();
const deviceDims = measuredDims ?? DEVICE_3D_DIMENSIONS[imagePhoneDevice] ?? { width: PHONE_W, height: PHONE_H };
+ const visualOffsetY = (measuredDims?.offsetY ?? 0) * imagePhoneScale * pxScale;
+ const phoneCx = canvasWidth / 2 + imagePhoneX * pxScale;
+ const phoneCy = canvasHeight / 2 + imagePhoneY * pxScale + visualOffsetY; // ← offset incluido
const drawW = deviceDims.width * imagePhoneScale * pxScale;
const drawH = deviceDims.height * imagePhoneScale * pxScale;
// Paint CSS-shadow replica as a 2D radial gradient underneath the model,
@@ -1592,14 +1640,12 @@ function VideoCanvasInner({
}
if (highQuality) {
imagePhoneApiRef.current?.renderAt(drawW, drawH);
- ctx.drawImage(phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH);
+ drawMaskedImage(ctx, phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH, effectivePhoneMaskConfig);
imagePhoneApiRef.current?.restorePreview();
} else {
- ctx.drawImage(phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH);
- }
- if (effectivePhoneMaskConfig?.enabled) {
- applyGradientMaskToRegion(ctx, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH, effectivePhoneMaskConfig);
+ drawMaskedImage(ctx, phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH, effectivePhoneMaskConfig);
}
+
}
ctx.restore();
return;
@@ -1684,11 +1730,7 @@ function VideoCanvasInner({
fgCtx.save();
fgCtx.translate(fgOffsetX, fgOffsetY);
if (!imagePhoneActive) {
- drawMockupAndMedia(fgCtx, containerX, containerY, containerWidth, containerHeight, video!, false);
- }
- if (imagePhoneActive && imagePhoneCanvasRef.current) {
- drawPhone3DCompositeWithZoom(ctx, canvasWidth, canvasHeight, frameTime, zoomState, highQuality, pivotX, pivotY);
-
+ drawMockupAndMedia(fgCtx, containerX, containerY, containerWidth, containerHeight, video!, false, true);
}
fgCtx.restore();
applyPerspective3D(fgCanvas, zoomState.rotateX, zoomState.rotateY, zoomState.perspective / BLEED_FACTOR);
@@ -1696,6 +1738,9 @@ function VideoCanvasInner({
applyVideoZoom(ctx);
ctx.drawImage(fgCanvas, -fgOffsetX, -fgOffsetY, fgWidth, fgHeight);
ctx.restore();
+ if (imagePhoneActive && imagePhoneCanvasRef.current) {
+ drawPhone3DCompositeWithZoom(ctx, canvasWidth, canvasHeight, frameTime, zoomState, highQuality, pivotX, pivotY);
+ }
} else {
const hasVideoMask = !!(videoMaskConfig?.enabled && (
videoMaskConfig.top || videoMaskConfig.bottom ||
@@ -1712,7 +1757,7 @@ function VideoCanvasInner({
vlCtx.imageSmoothingEnabled = true;
vlCtx.imageSmoothingQuality = 'high';
if (!imagePhoneActive) {
- drawMockupAndMedia(vlCtx, containerX, containerY, containerWidth, containerHeight, video!, false);
+ drawMockupAndMedia(vlCtx, containerX, containerY, containerWidth, containerHeight, video!, false, false);
}
vlCtx.globalCompositeOperation = 'destination-in';
@@ -1782,7 +1827,7 @@ function VideoCanvasInner({
ctx.save();
applyVideoZoom(ctx);
if (!imagePhoneActive) {
- drawMockupAndMedia(ctx, containerX, containerY, containerWidth, containerHeight, video!, false);
+ drawMockupAndMedia(ctx, containerX, containerY, containerWidth, containerHeight, video!, false, false);
}
ctx.restore();
@@ -1815,21 +1860,39 @@ function VideoCanvasInner({
const domW = canvasDimensions?.width ?? canvasWidth;
const pxScale = canvasWidth / domW;
const zScale = zs.scale;
+
const centerX = canvasWidth / 2;
const centerY = canvasHeight / 2;
- const baseCx = centerX + imagePhoneX * pxScale;
- const baseCy = centerY + imagePhoneY * pxScale;
-
- const phoneCx = pivotX + zScale * (baseCx - pivotX);
- const phoneCy = pivotY + zScale * (baseCy - pivotY);
const measuredDims = imagePhoneApiRef.current?.getVisualSize?.();
const deviceDims = measuredDims ?? DEVICE_3D_DIMENSIONS[imagePhoneDevice] ?? { width: PHONE_W, height: PHONE_H };
- const drawW = deviceDims.width * imagePhoneScale * pxScale * zScale;
- const drawH = deviceDims.height * imagePhoneScale * pxScale * zScale;
+ const visualOffsetY = (measuredDims?.offsetY ?? 0) * imagePhoneScale * pxScale;
+
+ const baseCx = centerX + imagePhoneX * pxScale;
+ const baseCy = centerY + imagePhoneY * pxScale + visualOffsetY;
+
+ const baseW = deviceDims.width * imagePhoneScale * pxScale;
+ const baseH = deviceDims.height * imagePhoneScale * pxScale;
+
+ // LA SOLUCIÓN CORREGIDA:
+ // Usamos exactamente baseW y baseH. Como baseW ya multiplica por pxScale,
+ // ya tiene la resolución alta necesaria para la exportación.
+ // Si multiplicamos aquí, rompemos la cámara 3D o excedemos la memoria WebGL.
+ if (highQuality) {
+ imagePhoneApiRef.current?.renderAt(baseW, baseH);
+ }
+
+ c.save();
+
+ if (zScale !== 1) {
+ c.translate(pivotX, pivotY);
+ c.scale(zScale, zScale);
+ c.translate(-pivotX, -pivotY);
+ }
const hasBuiltInShadow = imagePhoneApiRef.current?.hasBuiltInShadow ?? false;
+
if (imagePhoneShadow > 0.01 && !hasBuiltInShadow) {
const sT = imagePhoneShadow * imagePhoneShadow;
const sBlur = sT * 60;
@@ -1839,9 +1902,9 @@ function VideoCanvasInner({
c.filter = `blur(${Math.max(2, sBlur * 0.6) * pxScale}px)`;
c.beginPath();
c.ellipse(
- phoneCx,
- phoneCy + drawH / 2 + sBlur * 0.2 * pxScale,
- drawW * (0.6 - sT * 0.1) / 2,
+ baseCx,
+ baseCy + baseH / 2 + sBlur * 0.2 * pxScale,
+ baseW * (0.6 - sT * 0.1) / 2,
Math.max(4, sBlur * 0.55) * pxScale / 2,
0, 0, Math.PI * 2
);
@@ -1850,16 +1913,25 @@ function VideoCanvasInner({
c.restore();
}
- if (highQuality) {
- imagePhoneApiRef.current?.renderAt(drawW, drawH);
- c.drawImage(phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH);
- imagePhoneApiRef.current?.restorePreview();
- } else {
- c.drawImage(phoneGL, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH);
+ if (imagePhoneShadow > 0.01) {
+ c.shadowColor = imagePhoneShadowColor;
+ c.shadowBlur = 28 * imagePhoneShadow * pxScale;
+ c.shadowOffsetX = 0;
+ c.shadowOffsetY = 18 * imagePhoneShadow * pxScale;
+ }
+
+ drawMaskedImage(c, phoneGL, baseCx - baseW / 2, baseCy - baseH / 2, baseW, baseH, effectivePhoneMaskConfig);
+
+ if (imagePhoneShadow > 0.01) {
+ c.shadowColor = "transparent";
+ c.shadowBlur = 0;
+ c.shadowOffsetY = 0;
}
- if (effectivePhoneMaskConfig?.enabled) {
- applyGradientMaskToRegion(c, phoneCx - drawW / 2, phoneCy - drawH / 2, drawW, drawH, effectivePhoneMaskConfig);
+ c.restore();
+
+ if (highQuality) {
+ imagePhoneApiRef.current?.restorePreview();
}
};
@@ -2499,10 +2571,9 @@ function VideoCanvasInner({
transformOrigin: "center center",
pointerEvents: "auto",
userSelect: "none",
- filter:
- imagePhoneShadow > 0 && imagePhoneDevice !== "laptop"
- ? `drop-shadow(0px ${18 * imagePhoneShadow}px ${28 * imagePhoneShadow}px ${imagePhoneShadowColor})`
- : "none",
+ filter: imagePhoneShadow > 0
+ ? `drop-shadow(0px ${18 * imagePhoneShadow}px ${28 * imagePhoneShadow}px ${imagePhoneShadowColor})`
+ : "none",
}}
>
{phoneTransitioning || !activePhoneDevice ? (
diff --git a/app/components/ui/editor/VideosMenu.tsx b/app/components/ui/editor/VideosMenu.tsx
index da883bb..73e6455 100644
--- a/app/components/ui/editor/VideosMenu.tsx
+++ b/app/components/ui/editor/VideosMenu.tsx
@@ -262,92 +262,102 @@ export function VideosMenu({
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, x: -20, scale: 0.95 }}
- className={`group bg-[#09090B] border squircle-element overflow-hidden transition-colors ${videosInTrackIds.includes(video.id)
- ? "border-blue-500/50 bg-blue-500/5"
- : "border-white/5 hover:border-white/10"
+ className={`group relative rounded-lg border overflow-hidden transition-all duration-200 aspect-[16/10] w-full bg-[#000] ${videosInTrackIds.includes(video.id)
+ ? "border-blue-500 shadow-[0_0_15px_rgba(59,130,246,0.15)]"
+ : "border-neutral-800 hover:border-neutral-700"
}`}
>
- <div className="flex gap-3 p-2.5 items-center">
- <div
- className="relative w-20 h-12 rounded-md overflow-hidden bg-black/50 shrink-0 cursor-pointer"
- onClick={() => {
- if (!addingId) {
- videosInTrackIds.includes(video.id) ? onRemoveFromTrack?.(video.id) : handleAddToTrack(video.id);
- }
- }}
- >
- {video.thumbnailUrl ? (
- <img src={video.thumbnailUrl} alt={video.fileName} className="w-full h-full object-cover" />
- ) : (
- <div className="w-full h-full flex items-center justify-center">
- <Icon icon="solar:play-bold" width="20" className="text-white/30" />
- </div>
- )}
- <div className="absolute bottom-0.5 right-0.5 px-1 py-0.5 bg-black/70 rounded text-[9px] font-mono text-white/80">
- {formatVideoDuration(video.duration)}
+ <div
+ className="absolute inset-0 w-full h-full cursor-pointer"
+ onClick={() => {
+ if (!addingId) {
+ videosInTrackIds.includes(video.id)
+ ? onRemoveFromTrack?.(video.id)
+ : handleAddToTrack(video.id);
+ }
+ }}
+ >
+ {video.thumbnailUrl ? (
+ <img
+ src={video.thumbnailUrl}
+ alt={video.fileName}
+ className="w-full h-full object-cover transition-transform duration-300 group-hover:scale-105"
+ />
+ ) : (
+ <div className="w-full h-full flex items-center justify-center bg-neutral-950">
+ <Icon icon="solar:play-bold" width="32" className="text-neutral-800" />
</div>
- <div
- className={`absolute inset-0 flex items-center justify-center transition-all ${videosInTrackIds.includes(video.id) ? "bg-blue-500/10 opacity-100" : "bg-black/60 opacity-0 group-hover:opacity-100"
- }`}
- >
- {addingId === video.id ? (
- <Icon icon="svg-spinners:ring-resize" width="20" className="text-white" />
- ) : videosInTrackIds.includes(video.id) ? (
- <Icon icon="solar:check-circle-bold" width="20" className="text-blue-400" />
- ) : (
- <div className="absolute inset-0 flex items-center justify-center">
- <div
- className={` flex items-center gap-0.5 px-2 py-1 bg-white/10 backdrop-blur-md border border-white/20 rounded-full shadow-2xl transition-all duration-300 group-hover:bg-white/20 group-hover:scale-105 `}
- >
- <Icon icon="material-symbols:add-rounded" width="16" className="text-white drop-shadow-md" />
- <span className="text-[9px] font-bold text-white tracking-wider">{t("actions.add")}</span>
- </div>
- </div>
- )}
+ )}
+ </div>
+
+ <div className="absolute top-2 right-2 px-1.5 py-0.5 bg-black/80 border border-neutral-800 rounded text-[10px] font-mono text-neutral-400 z-10">
+ {formatVideoDuration(video.duration)}
+ </div>
+
+ <div
+ className={`absolute inset-0 flex items-center justify-center transition-opacity z-10 pointer-events-none ${videosInTrackIds.includes(video.id) || addingId === video.id
+ ? "opacity-100"
+ : "opacity-0 group-hover:opacity-100"
+ }`}
+ >
+ {addingId === video.id ? (
+ <div className="p-3 rounded-full bg-black/60 backdrop-blur-sm border border-neutral-800">
+ <Icon icon="svg-spinners:ring-resize" width="24" className="text-white" />
</div>
- </div>
+ ) : videosInTrackIds.includes(video.id) ? (
+ <div className="p-2.5 rounded-full bg-blue-500/10 backdrop-blur-sm border border-blue-500/50">
+ <Icon icon="solar:check-circle-bold" width="28" className="text-blue-500" />
+ </div>
+ ) : (
+ <div className="absolute inset-0 flex items-center justify-center bg-black/30 backdrop-blur-[1px]">
+ <div className="flex items-center gap-1 px-3 py-1 bg-white text-black rounded-full shadow-xl">
+ <Icon icon="material-symbols:add-rounded" width="16" />
+ <span className="text-[11px] font-bold">{t("actions.add")}</span>
+ </div>
+ </div>
+ )}
+ </div>
+
+ <div className="absolute bottom-0 left-0 right-0 h-1/2 bg-gradient-to-t from-black via-black/80 to-transparent z-10 pointer-events-none" />
- <div className="flex-1 min-w-0 flex flex-col justify-center">
- <p className="text-xs text-white/80 truncate" title={video.fileName}>
+ <div className="absolute bottom-0 left-0 right-0 p-3 flex items-end justify-between gap-3 z-20">
+ <div className="flex-1 min-w-0 flex flex-col gap-0.5">
+ <p className="text-xs font-semibold text-white truncate drop-shadow-[0_1px_2px_rgba(0,0,0,0.5)]" title={video.fileName}>
{video.fileName}
</p>
- <div className="flex items-center gap-2 mt-0.5">
- <span className="text-[11px] text-white/40">{formatFileSize(video.fileSize)}</span>
- <span className="text-[11px] text-white/30">•</span>
- <span className="text-[11px] text-white/40">
- {video.width}×{video.height}
- </span>
+ <div className="flex items-center gap-1.5 text-[10px] text-neutral-300 drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)] font-medium">
+ <span>{formatFileSize(video.fileSize)}</span>
+ <span>•</span>
+ <span>{video.width}×{video.height}</span>
</div>
</div>
- <div className="flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity">
+ <div className="flex items-center gap-0.5 shrink-0 pointer-events-auto opacity-0 group-hover:opacity-100 transition-opacity duration-150">
<TooltipAction label={video.hasAudio === false ? t("actions.unmute") : t("actions.mute")}>
<button
onClick={() => handleToggleAudio(video.id, video.hasAudio)}
disabled={video.originalHasAudio === false}
- className={`p-1.5 rounded-md transition-colors ${video.originalHasAudio === false
- ? "text-white/10 cursor-not-allowed"
- : video.hasAudio === false
- ? "text-red-400 bg-red-500/10"
- : "text-white/40 hover:text-white hover:bg-white/5"
+ className={`p-1.5 rounded-md backdrop-blur-sm border transition-colors ${video.originalHasAudio === false
+ ? "text-neutral-500 border-transparent cursor-not-allowed"
+ : video.hasAudio === false
+ ? "text-red-400 bg-red-500/20 border-red-500/50"
+ : "text-neutral-300 bg-neutral-900/50 hover:text-white hover:bg-neutral-800 border-neutral-700/50"
}`}
>
- <Icon
- icon={video.hasAudio === false ? "solar:volume-cross-outline" : "solar:volume-loud-outline"}
- width="16"
- />
+ <Icon icon={video.hasAudio === false ? "solar:volume-cross-outline" : "solar:volume-loud-outline"} width="15" />
</button>
</TooltipAction>
+
<TooltipAction label={t("actions.delete")}>
<button
onClick={() => handleDelete(video.id)}
disabled={deletingId === video.id}
- className="p-1.5 rounded-md text-white/40 hover:text-red-400 hover:bg-red-500/10 transition-colors disabled:opacity-50"
+ className="p-1.5 rounded-md backdrop-blur-sm bg-neutral-900/50 hover:text-red-400 hover:bg-red-500/20 border border-neutral-700/50 hover:border-red-500/50 text-neutral-300 transition-colors disabled:opacity-50"
>
{deletingId === video.id ? (
- <Icon icon="svg-spinners:ring-resize" width="16" />
+ <Icon icon="svg-spinners:ring-resize" width="15" />
) : (
- <Icon icon="solar:trash-bin-trash-outline" width="16" />
+ <Icon icon="solar:trash-bin-trash-outline" width="15" />
)}
</button>
</TooltipAction>
diff --git a/app/components/ui/editor/ZoomFragmentEditor.tsx b/app/components/ui/editor/ZoomFragmentEditor.tsx
index 787fc88..4bf992a 100644
--- a/app/components/ui/editor/ZoomFragmentEditor.tsx
+++ b/app/components/ui/editor/ZoomFragmentEditor.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useRef, useMemo, useState } from "react";
+import { useRef, useMemo, useState, useEffect } from "react";
import { Icon } from "@iconify/react";
import { useTranslations } from "next-intl";
import { SliderControl } from "../../../../components/ui/SliderControl";
@@ -11,13 +11,20 @@ import { DetailPageHeader } from "@/components/ui/DetailHeaderMenu";
export function ZoomFragmentEditor({
fragment, videoUrl, videoThumbnail, currentTime = 0,
- getThumbnailForTime, videoDimensions, onBack, onDelete, onUpdate,
+ getThumbnailForTime, videoDimensions, onBack, onDelete, onUpdate, is3DModelActive = false,
}: ZoomFragmentEditorProps) {
const t = useTranslations("zoomFragmentEditor");
const tCommon = useTranslations("editor");
const focusPreviewRef = useRef<HTMLDivElement>(null);
const [editingPoint, setEditingPoint] = useState<'start' | 'end'>('start');
+ useEffect(() => {
+ if (is3DModelActive && fragment.enable3D) {
+ onUpdate({ enable3D: false });
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [is3DModelActive]);
+
const dynamicThumbnail = useMemo(() => {
if (!getThumbnailForTime) return videoThumbnail || null;
const thumb = getThumbnailForTime(currentTime);
@@ -301,63 +308,65 @@ export function ZoomFragmentEditor({
</div>
{/* 3D effect */}
- <div className="space-y-3 p-3 bg-white/3 border border-white/8 squircle-element">
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-2">
- <Icon icon="mdi:cube-outline" width="16" className="text-white/60" />
- <div>
- <p className="text-xs font-medium text-white/80">{tCommon("effect3d.title")}</p>
- <p className="text-[11px] text-white/40">{tCommon("effect3d.subtitle")}</p>
+ {!is3DModelActive && (
+ <div className="space-y-3 p-3 bg-white/3 border border-white/8 squircle-element">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <Icon icon="mdi:cube-outline" width="16" className="text-white/60" />
+ <div>
+ <p className="text-xs font-medium text-white/80">{tCommon("effect3d.title")}</p>
+ <p className="text-[11px] text-white/40">{tCommon("effect3d.subtitle")}</p>
+ </div>
</div>
+ <button onClick={handleToggle3D} className={`relative w-11 h-6 rounded-full transition-colors ${fragment.enable3D ? 'bg-gray-400' : 'bg-white/15'}`}>
+ <div className={`absolute top-1 w-4 h-4 rounded-full bg-white shadow transition-transform ${fragment.enable3D ? 'translate-x-6' : 'translate-x-1'}`} />
+ </button>
</div>
- <button onClick={handleToggle3D} className={`relative w-11 h-6 rounded-full transition-colors ${fragment.enable3D ? 'bg-gray-400' : 'bg-white/15'}`}>
- <div className={`absolute top-1 w-4 h-4 rounded-full bg-white shadow transition-transform ${fragment.enable3D ? 'translate-x-6' : 'translate-x-1'}`} />
- </button>
- </div>
- {fragment.enable3D && (
- <div className="space-y-3 pt-3 border-t border-gray-500/20">
- <SliderControl icon="mdi:brightness-6" label={tCommon("effect3d.intensity")} value={fragment.perspective3DIntensity ?? 50} min={0} max={100} step={5} onChange={(value) => onUpdate({ perspective3DIntensity: value })} suffix="%" />
- <div className="space-y-2">
- <div className="flex items-center gap-2 text-xs text-white/60">
- <span>{tCommon("effect3d.direction")}</span>
- </div>
- <div
- className="relative w-full aspect-square mx-auto bg-[#0A0A0A] squircle-element border border-[#262626] hover:border-[#404040] transition-colors cursor-crosshair overflow-hidden group"
- onClick={(e) => {
- const rect = e.currentTarget.getBoundingClientRect();
- const x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
- const y = ((e.clientY - rect.top) / rect.height) * 2 - 1;
- onUpdate({ perspective3DAngleX: Math.round(y * 45), perspective3DAngleY: Math.round(-x * 45) });
- }}
- >
- <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
- <div className="w-full h-px bg-[#1F1F1F]" />
- <div className="h-full w-px bg-[#1F1F1F] absolute" />
+ {fragment.enable3D && (
+ <div className="space-y-3 pt-3 border-t border-gray-500/20">
+ <SliderControl icon="mdi:brightness-6" label={tCommon("effect3d.intensity")} value={fragment.perspective3DIntensity ?? 50} min={0} max={100} step={5} onChange={(value) => onUpdate({ perspective3DIntensity: value })} suffix="%" />
+ <div className="space-y-2">
+ <div className="flex items-center gap-2 text-xs text-white/60">
+ <span>{tCommon("effect3d.direction")}</span>
</div>
+ <div
+ className="relative w-full aspect-square mx-auto bg-[#0A0A0A] squircle-element border border-[#262626] hover:border-[#404040] transition-colors cursor-crosshair overflow-hidden group"
+ onClick={(e) => {
+ const rect = e.currentTarget.getBoundingClientRect();
+ const x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
+ const y = ((e.clientY - rect.top) / rect.height) * 2 - 1;
+ onUpdate({ perspective3DAngleX: Math.round(y * 45), perspective3DAngleY: Math.round(-x * 45) });
+ }}
+ >
+ <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
+ <div className="w-full h-px bg-[#1F1F1F]" />
+ <div className="h-full w-px bg-[#1F1F1F] absolute" />
+ </div>
+
+ <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
+ <div
+ className="w-40 h-28 border border-gray-500/40 bg-gray-500/10 rounded-md transition-transform duration-300 ease-out shadow-[0_4px_20px_rgba(0,0,0,0.4)]"
+ style={{ transform: `perspective(120px) rotateX(${fragment.perspective3DAngleX ?? 0}deg) rotateY(${fragment.perspective3DAngleY ?? 0}deg)` }}
+ />
+ </div>
- <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
<div
- className="w-40 h-28 border border-gray-500/40 bg-gray-500/10 rounded-md transition-transform duration-300 ease-out shadow-[0_4px_20px_rgba(0,0,0,0.4)]"
- style={{ transform: `perspective(120px) rotateX(${fragment.perspective3DAngleX ?? 0}deg) rotateY(${fragment.perspective3DAngleY ?? 0}deg)` }}
+ className="absolute w-2.5 h-2.5 bg-gray-300 rounded-full shadow-[0_0_8px_rgba(255,255,255,0.4)] transition-all duration-300 ease-out z-10"
+ style={{
+ left: `${50 + (-(fragment.perspective3DAngleY ?? (-(fragment.focusX - 50) / 50 * 15)) / 45) * 50}%`,
+ top: `${50 + ((fragment.perspective3DAngleX ?? ((fragment.focusY - 50) / 50 * 15)) / 45) * 50}%`,
+ transform: 'translate(-50%, -50%)'
+ }}
/>
</div>
- <div
- className="absolute w-2.5 h-2.5 bg-gray-300 rounded-full shadow-[0_0_8px_rgba(255,255,255,0.4)] transition-all duration-300 ease-out z-10"
- style={{
- left: `${50 + (-(fragment.perspective3DAngleY ?? (-(fragment.focusX - 50) / 50 * 15)) / 45) * 50}%`,
- top: `${50 + ((fragment.perspective3DAngleX ?? ((fragment.focusY - 50) / 50 * 15)) / 45) * 50}%`,
- transform: 'translate(-50%, -50%)'
- }}
- />
+ <p className="text-[11px] text-white/30 text-center">{tCommon("effect3d.directionHint")}</p>
</div>
-
- <p className="text-[11px] text-white/30 text-center">{tCommon("effect3d.directionHint")}</p>
</div>
- </div>
- )}
- </div>
+ )}
+ </div>
+ )}
<SliderControl icon="mdi:magnify-plus-outline" label={t("sliders.zoomLevel")} value={fragment.zoomLevel} min={1} max={10} step={0.1} onChange={(value) => onUpdate({ zoomLevel: value })} />
<SliderControl icon="mdi:speedometer" label={t("sliders.transitionSpeed")} value={fragment.speed} min={1} max={10} step={0.1} onChange={(value) => onUpdate({ speed: value })} />
diff --git a/app/contexts/Mockup3dContext.tsx b/app/contexts/Mockup3dContext.tsx
index 0994cb7..7ffefb9 100644
--- a/app/contexts/Mockup3dContext.tsx
+++ b/app/contexts/Mockup3dContext.tsx
@@ -69,7 +69,7 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
const [imagePhoneRotZ, setImagePhoneRotZ] = useState(0);
const [imagePhonePerspective, setImagePhonePerspective] = useState(600);
const [imagePhoneDevice, setImagePhoneDevice] = useState<'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'ipad_mini_6_2021'>('phone');
- const [imagePhonePresetId, setImagePhonePresetId] = useState('front');
+ const [imagePhonePresetId, setImagePhonePresetId] = useState('custom');
const [imagePhoneOpening, setImagePhoneOpening] = useState(1);
const [imagePhoneShadow, setImagePhoneShadow] = useState(0.6);
const [imagePhoneShadowColor, setImagePhoneShadowColor] = useState("#000000");
diff --git a/components/ui/Position3DPresetsEditor.tsx b/components/ui/Position3DPresetsEditor.tsx
new file mode 100644
index 0000000..451a006
--- /dev/null
+++ b/components/ui/Position3DPresetsEditor.tsx
@@ -0,0 +1,192 @@
+"use client";
+
+import { Icon } from "@iconify/react";
+import { useState } from "react";
+import { Button } from "@/components/ui/button";
+import {
+ Popover,
+ PopoverTrigger,
+ PopoverContent,
+ PopoverHeader,
+ PopoverTitle,
+} from "@/components/ui/popover";
+import { TooltipAction } from "@/components/ui/tooltip-action";
+import { useTranslations } from "next-intl";
+import {
+ PhoneImagePreviewConfig,
+ LaptopImagePreviewConfig,
+ LAPTOP_IMAGE_PREVIEWS,
+ getPhoneImagePreviews,
+} from "@/types/photo.types";
+import { PositionCustomControls } from "./PositionCustomControls";
+
+type DevicePreset = PhoneImagePreviewConfig | LaptopImagePreviewConfig;
+
+export interface Position3DPresetsEditorProps {
+ device: string;
+ isLaptop: boolean;
+ selectedPresetId: string;
+ onSelectPreset: (preset: DevicePreset) => void;
+
+ rotateX: number;
+ rotateY: number;
+ onRotationXYChange: (rotateX: number, rotateY: number) => void;
+ rotateZ: number;
+ onRotateZChange: (v: number) => void;
+ onCustomReset?: () => void;
+}
+
+export function Position3DPresetsEditor({
+ device,
+ isLaptop,
+ selectedPresetId,
+ onSelectPreset,
+ rotateX,
+ rotateY,
+ onRotationXYChange,
+ rotateZ,
+ onRotateZChange,
+ onCustomReset,
+}: Position3DPresetsEditorProps) {
+ const [isOpen, setIsOpen] = useState(false);
+ const [activeTab, setActiveTab] = useState<"presets" | "custom">("presets");
+ const t = useTranslations("mockupMenu.positionPresets");
+
+ const presets: DevicePreset[] = isLaptop
+ ? LAPTOP_IMAGE_PREVIEWS
+ : getPhoneImagePreviews(device);
+
+ return (
+ <Popover open={isOpen} onOpenChange={setIsOpen}>
+ <TooltipAction label={t("tooltip")}>
+ <PopoverTrigger asChild>
+ <Button
+ variant="outline"
+ className={`gap-2 text-xs transition-all duration-200 w-full justify-start
+ }`}
+ size="sm"
+ >
+ <Icon icon="mdi:image-multiple-outline" width="16" />
+ {t("trigger")}
+ <Icon icon="lucide:chevron-down" width="14" className="ml-auto opacity-50 shrink-0" />
+ </Button>
+ </PopoverTrigger>
+ </TooltipAction>
+ <PopoverContent
+ align="start"
+ className="w-80 h-130 bg-[#0A0A0A] border-white/10 shadow-2xl p-0 rounded-xl overflow-hidden"
+ >
+ <div className="flex flex-col">
+ <PopoverHeader className="px-4 py-3 border-b border-white/10 bg-white/5">
+ <div className="flex items-center justify-between">
+ <PopoverTitle className="text-xs font-semibold text-white/80 tracking-wide uppercase flex items-center gap-2">
+ <Icon icon="mdi:image-multiple-outline" width="14" className="text-blue-400" aria-hidden="true" />
+ {t("title")}
+ </PopoverTitle>
+ </div>
+ </PopoverHeader>
+
+ <div className="flex border-b border-white/10 bg-black/20">
+ <button
+ onClick={() => setActiveTab("presets")}
+ className={`flex-1 px-4 py-2.5 text-xs font-medium transition-all ${activeTab === "presets"
+ ? "text-blue-400 border-b-2 border-blue-400 bg-blue-500/5"
+ : "text-white/60 hover:text-white/80 hover:bg-white/5"
+ }`}
+ >
+ <Icon icon="mdi:palette-outline" width="14" className="inline mr-1.5" />
+ {t("tabs.presets")}
+ </button>
+ <button
+ onClick={() => setActiveTab("custom")}
+ className={`flex-1 px-4 py-2.5 text-xs font-medium transition-all ${activeTab === "custom"
+ ? "text-blue-400 border-b-2 border-blue-400 bg-blue-500/5"
+ : "text-white/60 hover:text-white/80 hover:bg-white/5"
+ }`}
+ >
+ <Icon icon="mdi:tune" width="14" className="inline mr-1.5" />
+ {t("tabs.custom")}
+ </button>
+ </div>
+
+ <div className="p-4 max-h-120 overflow-y-auto custom-scrollbar">
+ {activeTab === "presets" ? (
+ <div className="grid grid-cols-2 gap-3 w-full">
+ {onCustomReset && (
+ <button
+ onClick={onCustomReset}
+ className="group relative flex flex-col squircle-element border border-dashed border-white/20 hover:border-white/40 bg-white/5 hover:bg-white/10 transition-all overflow-hidden"
+ >
+ <div className="relative w-full aspect-video bg-zinc-900 flex flex-col items-center justify-center gap-1.5">
+ <div className="size-8 rounded-full bg-white/5 border border-white/5 flex items-center justify-center">
+ <Icon
+ icon="mdi:restore"
+ width="16"
+ className="text-white/70 group-hover:text-blue-400 transition-colors"
+ />
+ </div>
+ <span className="text-[11px] font-semibold text-white/60 group-hover:text-white/80 transition-colors">
+ {t("resetDefault")}
+ </span>
+ </div>
+ </button>
+ )}
+ {presets.map((preset) => {
+ const active = preset.id === selectedPresetId;
+ return (
+ <button
+ key={preset.id}
+ onClick={() => onSelectPreset(preset)}
+ className={`group relative flex flex-col squircle-element border transition-all overflow-hidden ${active ? "border-blue-500 bg-blue-500/10" : "border-white/10 hover:border-white/30 bg-white/5 hover:bg-white/10"}`}
+ >
+ <div className="relative w-full aspect-video bg-zinc-900">
+ {preset.imageUrl ? (
+ <img src={preset.imageUrl} alt={preset.label} className="w-full h-full object-cover" draggable={false} />
+ ) : (
+ <div className="absolute inset-0 flex items-center justify-center">
+ <Icon icon="mdi:image-off-outline" width="20" className="text-white/30" />
+ </div>
+ )}
+
+ {/* Tu nuevo diseño de badge para el texto del preset */}
+ <div className="absolute bottom-0 left-0 bg-black/60 border-t border-r border-white/10 px-1.5 py-0.5 text-[9px] font-semibold tracking-tight rounded-tr-md rounded-bl-lg z-30 max-w-[85%] truncate">
+ <span className={`transition-colors ${active ? "text-blue-400" : "text-white/80"}`}>
+ {preset.label}
+ </span>
+ </div>
+
+ {active && (
+ <div className="absolute top-2 right-2 z-30 size-4 rounded-full bg-blue-500 flex items-center justify-center shadow-xl">
+ <Icon icon="mdi:check" width="10" className="text-white" />
+ </div>
+ )}
+ </div>
+ </button>
+
+ );
+ })}
+ </div>
+ ) : (
+ <PositionCustomControls
+ rotateX={rotateX}
+ rotateY={rotateY}
+ onRotationXYChange={onRotationXYChange}
+ rotateZ={rotateZ}
+ onRotateZChange={onRotateZChange}
+ onReset={onCustomReset}
+ labels={{
+ perspective: t("custom.perspective"),
+ scale: t("custom.scale"),
+ rotationXY: t("custom.rotationXY"),
+ rotationZ: t("custom.rotationZ"),
+ vertical: t("custom.vertical"),
+ reset: t("custom.reset"),
+ }}
+ />
+ )}
+ </div>
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+}
\ No newline at end of file
diff --git a/components/ui/PositionCustomControls.tsx b/components/ui/PositionCustomControls.tsx
new file mode 100644
index 0000000..66c87d4
--- /dev/null
+++ b/components/ui/PositionCustomControls.tsx
@@ -0,0 +1,150 @@
+"use client";
+
+import { Icon } from "@iconify/react";
+import { SliderControl } from "./SliderControl";
+
+export interface PositionCustomControlsLabels {
+ perspective: string;
+ scale: string;
+ rotationXY: string;
+ rotationZ: string;
+ vertical: string;
+ reset: string;
+}
+
+export interface PositionCustomControlsProps {
+ scale?: number;
+ onScaleChange?: (v: number) => void;
+ scaleMin?: number;
+ scaleMax?: number;
+ rotateX: number;
+ rotateY: number;
+ onRotationXYChange: (rotateX: number, rotateY: number) => void;
+ rotateZ: number;
+ onRotateZChange: (v: number) => void;
+ perspective?: number;
+ onPerspectiveChange?: (v: number) => void;
+ verticalValue?: number;
+ verticalMin?: number;
+ verticalMax?: number;
+ onVerticalChange?: (v: number) => void;
+ onReset?: () => void;
+ labels: PositionCustomControlsLabels;
+}
+
+export function PositionCustomControls({
+ scale,
+ onScaleChange,
+ scaleMin = 50,
+ scaleMax = 150,
+ rotateX,
+ rotateY,
+ onRotationXYChange,
+ rotateZ,
+ onRotateZChange,
+ perspective,
+ onPerspectiveChange,
+ verticalValue,
+ verticalMin = -10,
+ verticalMax = 100,
+ onVerticalChange,
+ onReset,
+ labels,
+}: PositionCustomControlsProps) {
+ return (
+ <div className="space-y-4">
+ {onPerspectiveChange && (
+ <SliderControl
+ icon="mdi:cube-outline"
+ label={labels.perspective}
+ value={perspective ?? 600}
+ min={200}
+ max={1000}
+ step={50}
+ onChange={onPerspectiveChange}
+ suffix="px"
+ />
+ )}
+
+ {onScaleChange && (
+ <SliderControl
+ icon="mdi:resize"
+ label={labels.scale}
+ value={Math.round((scale ?? 1) * 100)}
+ min={scaleMin}
+ max={scaleMax}
+ step={5}
+ onChange={(value) => onScaleChange(value / 100)}
+ suffix="%"
+ />
+ )}
+
+ <div className="space-y-2">
+ <div className="flex items-center gap-1.5 text-[11px] text-white/60">
+ <Icon icon="mdi:rotate-3d-variant" width={12} />
+ <span>{labels.rotationXY}</span>
+ </div>
+ <div
+ className="relative w-full aspect-square bg-white/3 rounded-lg border border-white/10 cursor-crosshair overflow-hidden hover:bg-white/4 transition-colors"
+ onClick={(e) => {
+ const rect = e.currentTarget.getBoundingClientRect();
+ const x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
+ const y = ((e.clientY - rect.top) / rect.height) * 2 - 1;
+ const rY = Math.round(-x * 45);
+ const rX = Math.round(y * 45);
+ onRotationXYChange(rX, rY);
+ }}
+ >
+ <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
+ <div className="w-full h-px bg-white/5" />
+ <div className="h-full w-px bg-white/5 absolute" />
+ </div>
+ <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-all duration-75 cursor-grab"
+ style={{
+ width: "14px",
+ height: "14px",
+ left: `${50 + (-rotateY / 45) * 50}%`,
+ top: `${50 + (rotateX / 45) * 50}%`,
+ transform: "translate(-50%, -50%) scale(1)",
+ }}
+ />
+ </div>
+ </div>
+
+ <SliderControl
+ icon="mdi:axis-z-rotate-clockwise"
+ label={labels.rotationZ}
+ value={rotateZ}
+ min={-45}
+ max={45}
+ step={5}
+ onChange={onRotateZChange}
+ suffix="°"
+ />
+
+ {onVerticalChange && (
+ <SliderControl
+ icon="mdi:arrow-up-down"
+ label={labels.vertical}
+ value={verticalValue ?? 0}
+ min={verticalMin}
+ max={verticalMax}
+ step={1}
+ onChange={onVerticalChange}
+ suffix="%"
+ />
+ )}
+
+ {onReset && (
+ <button
+ onClick={onReset}
+ className="w-full mt-4 px-3 py-2 rounded-lg bg-white/5 hover:bg-white/10 text-[11px] text-white/70 hover:text-white transition-all flex items-center justify-center gap-2 border border-white/5"
+ >
+ <Icon icon="mdi:restore" width={14} />
+ {labels.reset}
+ </button>
+ )}
+ </div>
+ );
+}
\ No newline at end of file